From 663f58eb03ce8bcaa21e751077144faaaf202b32 Mon Sep 17 00:00:00 2001 From: iovar Date: Sat, 11 Nov 2006 00:00:24 +0000 Subject: Cache files are now broken on 500mb parts, measured always as uncomressed bytes as gzwrite returns them, in order to avoid gzlib 2 gb file size limit. CacheFileN,SwapCacheFilesWrite,SwapCacheFilesRead functions have been added to achieve this without messing with normal operation(i.e. the rest of the program keeps operating on the same file pointer). Also PurgeCache function has been added to separate the task from encoding itself. git-svn-id: https://recordmydesktop.svn.sourceforge.net/svnroot/recordmydesktop/trunk@160 f606c939-3180-4ac9-a4b8-4b8779d57d0a --- recordmydesktop/src/cache_frame.c | 66 ++++++++++++++++++++++++++++++--------- 1 file changed, 52 insertions(+), 14 deletions(-) (limited to 'recordmydesktop/src/cache_frame.c') diff --git a/recordmydesktop/src/cache_frame.c b/recordmydesktop/src/cache_frame.c index 01d83d6..a968b14 100644 --- a/recordmydesktop/src/cache_frame.c +++ b/recordmydesktop/src/cache_frame.c @@ -46,7 +46,7 @@ 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,FILE *ucfp){ +int 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; @@ -63,6 +63,7 @@ void FlushBlock(unsigned char *buf,int blockno,int width, int height,int divisor buf_reg+=width; } } + return ((height*width)/pow(divisor,2)); } void *CacheImageBuffer(void *pdata){ @@ -72,7 +73,13 @@ void *CacheImageBuffer(void *pdata){ yuv_buffer yuv[2]; gzFile *fp=NULL; FILE *ucfp=NULL; - int i,current=0,divisor=16,firstrun=1,frameno=0; + int i, + current=0, + divisor=16, + firstrun=1, + frameno=0, + nbytes=0, + nth_cache=1; if(!((ProgData *)pdata)->args.zerocompression){ fp=((ProgData *)pdata)->cache_data->ifp; @@ -174,34 +181,65 @@ void *CacheImageBuffer(void *pdata){ fheader.Vnum=vnum; fheader.pad=0; if(!((ProgData *)pdata)->args.zerocompression){ - gzwrite(fp,(void*)&fheader,sizeof(FrameHeader)); + nbytes+=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(ynum)nbytes+=gzwrite(fp,yblocks,ynum); + if(unum)nbytes+=gzwrite(fp,ublocks,unum); + if(vnum)nbytes+=gzwrite(fp,vblocks,vnum); } else{ - fwrite((void*)&fheader,sizeof(FrameHeader),1,ucfp); + nbytes+=sizeof(FrameHeader)*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); + if(ynum)nbytes+=ynum*fwrite(yblocks,ynum,1,ucfp); + if(unum)nbytes+=unum*fwrite(ublocks,unum,1,ucfp); + if(vnum)nbytes+=vnum*fwrite(vblocks,vnum,1,ucfp); } //flush the blocks for each buffer if(ynum) for(j=0;javd+=((ProgData *)pdata)->frametime*2*((ProgData *)pdata)->args.channels; - + if(nbytes>CACHE_FILE_SIZE_LIMIT){ + if(SwapCacheFilesWrite(((ProgData *)pdata)->cache_data->imgdata,nth_cache,&fp,&ucfp)){ + fprintf(stderr,"New cache file could not be created.\nEnding recording...\n"); + fflush(stderr); + raise(SIGINT); //if for some reason we cannot make a new file + //we have to stop. If we are out of space,which means + //that encoding cannot happen either, + //InitEncoder will cause an abrupt end with an + //error code and the cache will remain intact. + //If we've chosen separate two-stages, the program will make a + //clean exit. + //In either case data will be preserved so if + //space is freed the recording can be proccessed later. + } + nth_cache++; + nbytes=0; + } } //clean up since we're not finished -- cgit v1.2.1