summaryrefslogtreecommitdiff
path: root/recordmydesktop/src/cache_frame.c
diff options
context:
space:
mode:
authoriovar <iovar@f606c939-3180-4ac9-a4b8-4b8779d57d0a>2006-11-11 00:00:24 +0000
committeriovar <iovar@f606c939-3180-4ac9-a4b8-4b8779d57d0a>2006-11-11 00:00:24 +0000
commit663f58eb03ce8bcaa21e751077144faaaf202b32 (patch)
tree3fe34d8e9a9390922015142891fd6b4e79b865c4 /recordmydesktop/src/cache_frame.c
parentb89af75ae20823839a343b1d877fba7d9d76b640 (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/src/cache_frame.c')
-rw-r--r--recordmydesktop/src/cache_frame.c66
1 files changed, 52 insertions, 14 deletions
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
© All Rights Reserved