diff options
author | iovar <iovar@f606c939-3180-4ac9-a4b8-4b8779d57d0a> | 2006-11-09 15:17:43 +0000 |
---|---|---|
committer | iovar <iovar@f606c939-3180-4ac9-a4b8-4b8779d57d0a> | 2006-11-09 15:17:43 +0000 |
commit | b89af75ae20823839a343b1d877fba7d9d76b640 (patch) | |
tree | a58dbb06aacefba2d6da8cbfed7a8f15fa4897ca /recordmydesktop/src | |
parent | 7eaf09aa2eb9d4a4aba31a192d38476ea578b00d (diff) |
Writting and reading cache, is changed to happen through
normal fwrites-freads, when zero compression is selected as
an option
git-svn-id: https://recordmydesktop.svn.sourceforge.net/svnroot/recordmydesktop/trunk@159 f606c939-3180-4ac9-a4b8-4b8779d57d0a
Diffstat (limited to 'recordmydesktop/src')
-rw-r--r-- | recordmydesktop/src/cache_frame.c | 62 | ||||
-rw-r--r-- | recordmydesktop/src/load_cache.c | 51 | ||||
-rw-r--r-- | recordmydesktop/src/rmd_cache.c | 19 |
3 files changed, 99 insertions, 33 deletions
diff --git a/recordmydesktop/src/cache_frame.c b/recordmydesktop/src/cache_frame.c index c100505..01d83d6 100644 --- a/recordmydesktop/src/cache_frame.c +++ b/recordmydesktop/src/cache_frame.c @@ -46,14 +46,22 @@ int CompareBlocks(unsigned char *incoming,unsigned char *old,int blockno,int wid return 0; } -void FlushBlock(unsigned char *buf,int blockno,int width, int height,int divisor,gzFile *fp){ +void FlushBlock(unsigned char *buf,int blockno,int width, int height,int divisor,gzFile *fp,FILE *ucfp){ int j, block_i=blockno/divisor,//place on the grid block_k=blockno%divisor; register unsigned char *buf_reg=(&buf[block_i*(width*height/divisor)+block_k*width/divisor]); - for(j=0;j<height/divisor;j++){//we flush in rows - gzwrite(fp,(void *)buf_reg,width/divisor); - buf_reg+=width; + if(ucfp==NULL){ + for(j=0;j<height/divisor;j++){//we flush in rows + gzwrite(fp,(void *)buf_reg,width/divisor); + buf_reg+=width; + } + } + else{ + for(j=0;j<height/divisor;j++){//we flush in rows + fwrite((void *)buf_reg,width/divisor,1,ucfp); + buf_reg+=width; + } } } @@ -62,11 +70,19 @@ void *CacheImageBuffer(void *pdata){ pthread_mutex_init(&pmut,NULL); pthread_mutex_init(&imut,NULL); yuv_buffer yuv[2]; - gzFile *fp=((ProgData *)pdata)->cache_data->ifp; + gzFile *fp=NULL; + FILE *ucfp=NULL; + int i,current=0,divisor=16,firstrun=1,frameno=0; - if(fp==NULL)exit(13); + if(!((ProgData *)pdata)->args.zerocompression){ + fp=((ProgData *)pdata)->cache_data->ifp; + if(fp==NULL)exit(13); + } + else{ + ucfp=((ProgData *)pdata)->cache_data->uncifp; + if(ucfp==NULL)exit(13); + } - int i,current=0,divisor=16,firstrun=1,frameno=0; for(i=0;i<2;i++){ yuv[i].y_width=((ProgData *)pdata)->enc_data->yuv.y_width; @@ -157,23 +173,30 @@ void *CacheImageBuffer(void *pdata){ fheader.Unum=unum; fheader.Vnum=vnum; fheader.pad=0; - gzwrite(fp,(void*)&fheader,sizeof(FrameHeader)); - //flush indexes - if(ynum)gzwrite(fp,yblocks,ynum); - if(unum)gzwrite(fp,ublocks,unum); - if(vnum)gzwrite(fp,vblocks,vnum); - - + if(!((ProgData *)pdata)->args.zerocompression){ + gzwrite(fp,(void*)&fheader,sizeof(FrameHeader)); + //flush indexes + if(ynum)gzwrite(fp,yblocks,ynum); + if(unum)gzwrite(fp,ublocks,unum); + if(vnum)gzwrite(fp,vblocks,vnum); + } + else{ + fwrite((void*)&fheader,sizeof(FrameHeader),1,ucfp); + //flush indexes + if(ynum)fwrite(yblocks,ynum,1,ucfp); + if(unum)fwrite(ublocks,unum,1,ucfp); + if(vnum)fwrite(vblocks,vnum,1,ucfp); + } //flush the blocks for each buffer if(ynum) for(j=0;j<ynum;j++) - FlushBlock(yuv[current].y,yblocks[j],yuv[current].y_width,yuv[current].y_height,divisor,fp); + FlushBlock(yuv[current].y,yblocks[j],yuv[current].y_width,yuv[current].y_height,divisor,fp,ucfp); if(unum) for(j=0;j<unum;j++) - FlushBlock(yuv[current].u,ublocks[j],yuv[current].uv_width,yuv[current].uv_height,divisor/2,fp); + FlushBlock(yuv[current].u,ublocks[j],yuv[current].uv_width,yuv[current].uv_height,divisor/2,fp,ucfp); if(vnum) for(j=0;j<vnum;j++) - FlushBlock(yuv[current].v,vblocks[j],yuv[current].uv_width,yuv[current].uv_height,divisor/2,fp); + FlushBlock(yuv[current].v,vblocks[j],yuv[current].uv_width,yuv[current].uv_height,divisor/2,fp,ucfp); /**@________________@**/ @@ -188,6 +211,9 @@ void *CacheImageBuffer(void *pdata){ free(yuv[i].v); } fprintf(stderr,"Saved %d frames in a total of %d requests\n",frameno,frames_total); - gzclose(fp); + if(!((ProgData *)pdata)->args.zerocompression) + gzclose(fp); + else + fclose(ucfp); pthread_exit(&errno); } diff --git a/recordmydesktop/src/load_cache.c b/recordmydesktop/src/load_cache.c index cd09956..ffa3d67 100644 --- a/recordmydesktop/src/load_cache.c +++ b/recordmydesktop/src/load_cache.c @@ -43,7 +43,8 @@ void LoadBlock(unsigned char *dest,unsigned char *source,int blockno,int width, void *LoadCache(void *pdata){ yuv_buffer *yuv=&((ProgData *)pdata)->enc_data->yuv; - gzFile *ifp=((ProgData *)pdata)->cache_data->ifp; + gzFile *ifp=NULL; + FILE *ucfp=NULL; FILE *afp=((ProgData *)pdata)->cache_data->afp; FrameHeader fheader; CachedFrame frame; @@ -61,11 +62,21 @@ void *LoadCache(void *pdata){ //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.zerocompression){ + ifp=gzopen(((ProgData *)pdata)->cache_data->imgdata,"rb"); + if(ifp==NULL){ + thread_exit=-1; + pthread_exit(&thread_exit); + } } + else{ + ucfp=fopen(((ProgData *)pdata)->cache_data->imgdata,"rb"); + if(ucfp==NULL){ + thread_exit=-1; + pthread_exit(&thread_exit); + } + } + if(!((ProgData *)pdata)->args.nosound){ afp=fopen(((ProgData *)pdata)->cache_data->audiodata,"rb"); @@ -84,7 +95,6 @@ void *LoadCache(void *pdata){ ((ProgData *)pdata)->avd=0; //If sound finishes first,we go on with the video. //If video ends we will do one more run to flush audio in the ogg file - while(((ProgData *)pdata)->running){ //video load and encoding if(((ProgData *)pdata)->avd<=0 || ((ProgData *)pdata)->args.nosound || audio_end){ @@ -93,7 +103,10 @@ void *LoadCache(void *pdata){ missing_frames--; SyncEncodeImageBuffer((ProgData *)pdata); } - else if(gzread(ifp,frame.header,sizeof(FrameHeader))==sizeof(FrameHeader)){ + else if(((!((ProgData *)pdata)->args.zerocompression)&& + (gzread(ifp,frame.header,sizeof(FrameHeader))==sizeof(FrameHeader) ))|| + ((((ProgData *)pdata)->args.zerocompression)&& + (fread(frame.header,sizeof(FrameHeader),1,ucfp)==1))){ //sync missing_frames+=frame.header->current_total-(extra_frames+frame.header->frameno); fprintf(stdout,"\r[%d%%] ", @@ -103,12 +116,26 @@ void *LoadCache(void *pdata){ 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) && + + ( + ((!((ProgData *)pdata)->args.zerocompression)&& + ((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))){ + (gzread(ifp,frame.VData,(blockszuv*frame.header->Vnum))==(blockszuv*frame.header->Vnum)))) || + + ((((ProgData *)pdata)->args.zerocompression)&& + ((fread(frame.YBlocks,1,frame.header->Ynum,ucfp)==frame.header->Ynum) && + (fread(frame.UBlocks,1,frame.header->Unum,ucfp)==frame.header->Unum) && + (fread(frame.VBlocks,1,frame.header->Vnum,ucfp)==frame.header->Vnum) && + (frame.header->Ynum==0 ||fread(frame.YData,blockszy,frame.header->Ynum,ucfp)==frame.header->Ynum) && + (frame.header->Unum==0 ||fread(frame.UData,blockszuv,frame.header->Unum,ucfp)==frame.header->Unum) && + (frame.header->Vnum==0 ||fread(frame.VData,blockszuv,frame.header->Vnum,ucfp)==frame.header->Vnum))) + + ) + ){ //load the blocks for each buffer if(frame.header->Ynum) for(j=0;j<frame.header->Ynum;j++) @@ -162,7 +189,11 @@ void *LoadCache(void *pdata){ fprintf(stdout,"\n"); CLEAR_FRAME(&frame) free(sound_data); - gzclose(ifp); + + if(!((ProgData *)pdata)->args.zerocompression) + gzclose(ifp); + else + fclose(ucfp); if(remove(((ProgData *)pdata)->cache_data->imgdata)){ fprintf(stderr,"Couldn't remove temporary file %s",((ProgData *)pdata)->cache_data->imgdata); diff --git a/recordmydesktop/src/rmd_cache.c b/recordmydesktop/src/rmd_cache.c index 9cb76d5..ca13095 100644 --- a/recordmydesktop/src/rmd_cache.c +++ b/recordmydesktop/src/rmd_cache.c @@ -71,7 +71,7 @@ void InitCacheData(ProgData *pdata,EncData *enc_data_t,CacheData *cache_data_t){ //image data cache_data_t->imgdata=malloc(strlen(cache_data_t->projname)+11); strcpy(cache_data_t->imgdata,cache_data_t->projname); - strcat(cache_data_t->imgdata,"img.out.gz"); + strcat(cache_data_t->imgdata,"img.out"); //audio data cache_data_t->audiodata=malloc(strlen(cache_data_t->projname)+10); strcpy(cache_data_t->audiodata,cache_data_t->projname); @@ -84,10 +84,19 @@ void InitCacheData(ProgData *pdata,EncData *enc_data_t,CacheData *cache_data_t){ fprintf(stderr,"Could not create temporary directory %s !!!\n",cache_data_t->projname); exit(13); } - cache_data_t->ifp=gzopen(cache_data_t->imgdata,"wb0f"); - if(cache_data_t->ifp==NULL){ - fprintf(stderr,"Could not create temporary file %s !!!\n",cache_data_t->imgdata); - exit(13); + if(!pdata->args.zerocompression){ + cache_data_t->ifp=gzopen(cache_data_t->imgdata,"wb0f"); + if(cache_data_t->ifp==NULL){ + fprintf(stderr,"Could not create temporary file %s !!!\n",cache_data_t->imgdata); + exit(13); + } + } + else{ + cache_data_t->uncifp=fopen(cache_data_t->imgdata,"wb0f"); + if(cache_data_t->uncifp==NULL){ + fprintf(stderr,"Could not create temporary file %s !!!\n",cache_data_t->imgdata); + exit(13); + } } if(!pdata->args.nosound){ cache_data_t->afp=fopen(cache_data_t->audiodata,"wb"); |