From 29d2e46787bee6bc3a951734d40a215088d58692 Mon Sep 17 00:00:00 2001 From: iovar Date: Fri, 27 Oct 2006 15:19:15 +0000 Subject: image cache loading ,almost fuctional git-svn-id: https://recordmydesktop.svn.sourceforge.net/svnroot/recordmydesktop/trunk@123 f606c939-3180-4ac9-a4b8-4b8779d57d0a --- rMD-exp/src/load_cache.c | 160 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 159 insertions(+), 1 deletion(-) (limited to 'rMD-exp/src/load_cache.c') diff --git a/rMD-exp/src/load_cache.c b/rMD-exp/src/load_cache.c index dbe6057..246b14e 100644 --- a/rMD-exp/src/load_cache.c +++ b/rMD-exp/src/load_cache.c @@ -27,16 +27,174 @@ #include +void LoadBlock(unsigned char *dest,unsigned char *source,int blockno,int width, int height,int divisor){ + int j, + block_i=blockno/divisor,//place on the grid + block_k=blockno%divisor; + + for(j=0;jenc_data->yuv; + gzFile *ifp=((ProgData *)pdata)->cache_data->ifp; + FILE *afp=((ProgData *)pdata)->cache_data->afp; + FrameHeader fheader; + CachedFrame frame; + int j=0, + thread_exit=0,//0 success, -1 couldn't find files,1 couldn't remove + divisor=16, + blockszy=0,//size of y plane block in bytes + blockszuv=0;//size of u,v plane blocks in bytes + //we allocate the frame that we will use + INIT_FRAME(&frame,&fheader,yuv) + //and the we open our files + ifp=gzopen(((ProgData *)pdata)->cache_data->imgdata,"rb"); + if(ifp==NULL){ + thread_exit=-1; + pthread_exit(&thread_exit); + } + + if(!((ProgData *)pdata)->args.nosound){ + afp=fopen(((ProgData *)pdata)->cache_data->audiodata,"rb"); + if(afp==NULL){ + thread_exit=-1; + pthread_exit(&thread_exit); + } + } +// int first=10; + + //recalculate the divisor since it is not saved + while(((((ProgData *)pdata)->brwin.rgeom.width* + ((ProgData *)pdata)->brwin.rgeom.width ) + /pow(divisor,2)) + <=1024){ + divisor/=2; + if(divisor==2) + break; + } + //these two are likely to be the same, but not guaranteed, especially on + //low resolutions + blockszy=(yuv->y_width*yuv->y_height )/pow(divisor,2); + blockszuv=(yuv->uv_width*yuv->uv_height)/pow(divisor/2,2); + + + while(((ProgData *)pdata)->running){ + int framesize=0; +// if(first){ + if(gzread(ifp,frame.header,sizeof(FrameHeader))==sizeof(FrameHeader)){ +// fprintf(stderr,"1:%c%c%c%c \n1: %d \n1: %d \n1: %d \n1: %d \n1: %d \n1: %d\n", +// frame.header->frame_prefix[0],frame.header->frame_prefix[1],frame.header->frame_prefix[2],frame.header->frame_prefix[3], +// frame.header->frameno,frame.header->current_total +// ,frame.header->Ynum,frame.header->Unum,frame.header->Vnum,frame.header->pad);fflush(stderr); + fprintf(stderr,"\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b %d of %d",frame.header->frameno,frame.header->current_total); + if( (frame.header->Ynum<=pow(divisor,2)) && + (frame.header->Unum<=pow(divisor/2,2)) && + (frame.header->Vnum<=pow(divisor/2,2)) && + (gzread(ifp,frame.YBlocks,frame.header->Ynum)==frame.header->Ynum) && + (gzread(ifp,frame.UBlocks,frame.header->Unum)==frame.header->Unum) && + (gzread(ifp,frame.VBlocks,frame.header->Vnum)==frame.header->Vnum) && + (gzread(ifp,frame.YData,blockszy*frame.header->Ynum)==blockszy*frame.header->Ynum) && + (gzread(ifp,frame.UData,(blockszuv*frame.header->Unum))==(blockszuv*frame.header->Unum)) && + (gzread(ifp,frame.VData,(blockszuv*frame.header->Vnum))==(blockszuv*frame.header->Vnum))){ + framesize+=sizeof(FrameHeader) + +frame.header->Ynum+frame.header->Unum+frame.header->Vnum + +blockszy*frame.header->Ynum+(blockszuv*frame.header->Unum) + +(blockszuv*frame.header->Vnum); +// fprintf(stderr,"OK! %d \n%d %d %d\n",framesize,blockszy,blockszuv,sizeof(FrameHeader));fflush(stderr); + + pthread_mutex_lock(&((ProgData *)pdata)->yuv_mutex); + + //load the blocks for each buffer + if(frame.header->Ynum) + for(j=0;jYnum;j++) + LoadBlock( yuv->y, + &frame.YData[j*blockszy], + frame.YBlocks[j], + yuv->y_width, + yuv->y_height, + divisor); + if(frame.header->Unum) + for(j=0;jUnum;j++) + LoadBlock( yuv->u, + &frame.UData[j*blockszuv], + frame.UBlocks[j], + yuv->uv_width, + yuv->uv_height, + divisor/2); + if(frame.header->Vnum) + for(j=0;jVnum;j++) + LoadBlock( yuv->v, + &frame.VData[j*blockszuv], + frame.VBlocks[j], + yuv->uv_width, + yuv->uv_height, + divisor/2); + pthread_mutex_unlock(&((ProgData *)pdata)->yuv_mutex); + + while(encoder_busy){ + usleep(100); + } + pthread_cond_broadcast(&((ProgData *)pdata)->image_buffer_ready); + while(encoder_busy){ + usleep(100); + } + } + else{ +// first=0; + raise(SIGINT); + continue; + } + } + else{ +// first=0; + raise(SIGINT); + continue; + } + +// } + + //call loading func{ + //if avd>=0 + //load image from cache + //signal buffer + ////if avd<0 + //load sound from cache + //signal buffer + //} +// sleep(1); + } + CLEAR_FRAME(&frame) + gzclose(ifp); + if(remove(((ProgData *)pdata)->cache_data->imgdata)){ + fprintf(stderr,"Couldn't remove temporary file %s",((ProgData *)pdata)->cache_data->imgdata); + thread_exit=1; + } + if(!((ProgData *)pdata)->args.nosound){ + fclose(afp); + if(remove(((ProgData *)pdata)->cache_data->audiodata)){ + fprintf(stderr,"Couldn't remove temporary file %s",((ProgData *)pdata)->cache_data->audiodata); + thread_exit=1; + } + } + if(remove(((ProgData *)pdata)->cache_data->projname)){ + fprintf(stderr,"Couldn't remove temporary directory %s",((ProgData *)pdata)->cache_data->projname); + thread_exit=1; + } + pthread_exit(&thread_exit); - pthread_exit(&errno); } -- cgit v1.2.3