diff options
author | iovar <iovar@f606c939-3180-4ac9-a4b8-4b8779d57d0a> | 2006-11-11 00:00:24 +0000 |
---|---|---|
committer | iovar <iovar@f606c939-3180-4ac9-a4b8-4b8779d57d0a> | 2006-11-11 00:00:24 +0000 |
commit | 663f58eb03ce8bcaa21e751077144faaaf202b32 (patch) | |
tree | 3fe34d8e9a9390922015142891fd6b4e79b865c4 /recordmydesktop | |
parent | b89af75ae20823839a343b1d877fba7d9d76b640 (diff) |
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
Diffstat (limited to 'recordmydesktop')
-rw-r--r-- | recordmydesktop/include/recordmydesktop.h | 8 | ||||
-rw-r--r-- | recordmydesktop/src/cache_frame.c | 66 | ||||
-rw-r--r-- | recordmydesktop/src/load_cache.c | 26 | ||||
-rw-r--r-- | recordmydesktop/src/recordmydesktop.c | 3 | ||||
-rw-r--r-- | recordmydesktop/src/rmd_cache.c | 72 |
5 files changed, 143 insertions, 32 deletions
diff --git a/recordmydesktop/include/recordmydesktop.h b/recordmydesktop/include/recordmydesktop.h index 5f2a1f0..e9f27b1 100644 --- a/recordmydesktop/include/recordmydesktop.h +++ b/recordmydesktop/include/recordmydesktop.h @@ -89,6 +89,9 @@ #error Only little-endian and big-endian systems are supported #endif +//500 mb file size +#define CACHE_FILE_SIZE_LIMIT (500*1<<20) + //do not be confused //this is useless and obsolete. @@ -713,6 +716,7 @@ int capture_busy, /**Function prototypes*/ +/** TODO document all the functions*/ void *PollDamage(void *pdata); void *GetFrame(void *pdata); void *EncodeImageBuffer(void *pdata); @@ -743,5 +747,9 @@ void SyncEncodeImageBuffer(ProgData *pdata); void CancelTimer(void); void SyncEncodeSoundBuffer(ProgData *pdata,signed char *buff); char *rmdWMCheck(Display *dpy,Window root); +void CacheFileN(char *name,char **newname,int n); +int SwapCacheFilesWrite(char *name,int n,gzFile **fp,FILE **ucfp); +int SwapCacheFilesRead(char *name,int n,gzFile **fp,FILE **ucfp); +int PurgeCache(CacheData *cache_data_t,int sound); #endif 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;j<ynum;j++) - FlushBlock(yuv[current].y,yblocks[j],yuv[current].y_width,yuv[current].y_height,divisor,fp,ucfp); + nbytes+=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,ucfp); + nbytes+=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,ucfp); + nbytes+=FlushBlock( yuv[current].v,vblocks[j], + yuv[current].uv_width, + yuv[current].uv_height, + divisor/2, + fp, + ucfp); /**@________________@**/ ((ProgData *)pdata)->avd+=((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 diff --git a/recordmydesktop/src/load_cache.c b/recordmydesktop/src/load_cache.c index ffa3d67..2606900 100644 --- a/recordmydesktop/src/load_cache.c +++ b/recordmydesktop/src/load_cache.c @@ -51,6 +51,7 @@ void *LoadCache(void *pdata){ signed char *sound_data=(signed char *)malloc(((ProgData *)pdata)->periodsize); int j=0, + nth_cache=1, audio_end=0, extra_frames=0,//total number of duplicated frames missing_frames=0,//if this is found >0 current run will not load @@ -171,7 +172,13 @@ void *LoadCache(void *pdata){ } } else{ - raise(SIGINT); + if(SwapCacheFilesRead(((ProgData *)pdata)->cache_data->imgdata,nth_cache,&ifp,&ucfp)){ + raise(SIGINT); + } + else{ + fprintf(stderr,"\t[Cache File %d]",nth_cache); + nth_cache++; + } continue; } } @@ -190,25 +197,8 @@ void *LoadCache(void *pdata){ CLEAR_FRAME(&frame) free(sound_data); - 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); - 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); diff --git a/recordmydesktop/src/recordmydesktop.c b/recordmydesktop/src/recordmydesktop.c index 77c08ce..7af3038 100644 --- a/recordmydesktop/src/recordmydesktop.c +++ b/recordmydesktop/src/recordmydesktop.c @@ -313,6 +313,9 @@ int main(int argc,char **argv){ pthread_join(load_cache_t,NULL); fprintf(stderr,"Encoding finished!\nWait a moment please...\n"); pthread_join(flush_to_ogg_t,NULL); + fprintf(stderr,"Cleanning up cache...\n"); + if(PurgeCache(pdata.cache_data,!pdata.args.nosound)) + fprintf(stderr,"Some error occured while cleaning up cache!\n"); fprintf(stderr,"Done!!!\n"); } } diff --git a/recordmydesktop/src/rmd_cache.c b/recordmydesktop/src/rmd_cache.c index ca13095..2a49895 100644 --- a/recordmydesktop/src/rmd_cache.c +++ b/recordmydesktop/src/rmd_cache.c @@ -26,6 +26,78 @@ #include <recordmydesktop.h> + +void CacheFileN(char *name,char **newname,int n){//nth cache file + char numbuf[8]; + strcpy(*newname,name); + strcat(*newname,"."); + I16TOA((n),numbuf) + strcat(*newname,numbuf); +} + +int SwapCacheFilesWrite(char *name,int n,gzFile **fp,FILE **ucfp){ + char *newname=malloc(strlen(name)+10); + CacheFileN(name,&newname,n); + if(*fp==NULL){ + fflush(*ucfp); + fclose(*ucfp); + *ucfp=fopen(newname,"wb"); + } + else{ + gzflush(*fp,Z_FINISH); + gzclose(*fp); + *fp=gzopen(newname,"wb0f"); + } + free(newname); + return ((*fp==NULL)&&(*ucfp==NULL)); +} + +int SwapCacheFilesRead(char *name,int n,gzFile **fp,FILE **ucfp){ + char *newname=malloc(strlen(name)+10); + CacheFileN(name,&newname,n); + if(*fp==NULL){ + fclose(*ucfp); + *ucfp=fopen(newname,"rb"); + } + else{ + + gzclose(*fp); + *fp=gzopen(newname,"rb"); + } + free(newname); + return ((*fp==NULL)&&(*ucfp==NULL)); +} + +int PurgeCache(CacheData *cache_data_t,int sound){ + struct stat buff; + char *fname; + fname=malloc(strlen(cache_data_t->imgdata)+10); + strcpy(fname,cache_data_t->imgdata); + int exit_value=0; + int nth_cache=1; + + while (stat(fname,&buff)==0){ + if(remove(fname)){ + fprintf(stderr,"Couldn't remove temporary file %s",cache_data_t->imgdata); + exit_value=1; + } + CacheFileN(cache_data_t->imgdata,&fname,nth_cache); + nth_cache++; + } + free(fname); + if(sound){ + if(remove(cache_data_t->audiodata)){ + fprintf(stderr,"Couldn't remove temporary file %s",cache_data_t->audiodata); + exit_value=1; + } + } + if(remove(cache_data_t->projname)){ + fprintf(stderr,"Couldn't remove temporary directory %s",cache_data_t->projname); + exit_value=1; + } + return exit_value; +} + void InitCacheData(ProgData *pdata,EncData *enc_data_t,CacheData *cache_data_t){ int width,height,offset_x,offset_y,pid; char pidbuf[8]; |