From c1a890715d4791b75b9512c1d9b02cb691c5de39 Mon Sep 17 00:00:00 2001 From: iovar Date: Sat, 27 Jan 2007 17:18:58 +0000 Subject: Changed cache format to utilize better interframe encoding and thus require sufficiently less hard disk space. Instead of the old (plane_width/16)*(plane_height/16) blocksize, now we are using 16x16 for the y plane and 8x8 blocks for the u,v planes. Also this byte alignment allows comparing of blocks to happen by first casting into a larger datatype(u_int64_t if available, u_int32_t else). This way we do as little as 1/8 or 1/4 of comparisons. This essentially offsets the higher CPU required to check the now increased number of blocks, and even provides a slight performance boost from the previous way of caching. Also, the load cache loop has been debloated, by moving much of the functionality that previously resided in an if evaluation statement, into anew function(ReadFrame). For further abstraction, ReadFrame utilizes ReadZF to do the actual reading. ReadZF determines if a gzread or an fread has to be done. Another improvement in the program is that, now, write operations on the disk, happen in 4 kbytes pages, minimizing thus the overall cost of access. Last change in this set is that the indexes in the CachedFrame and FrameHeader datatypes, are now u_int32_t's, to accomodate the possibly large number of blocks(could have been 16 bit types but that would give 4096*4096 max resolution, which might have caused problems in the future) git-svn-id: https://recordmydesktop.svn.sourceforge.net/svnroot/recordmydesktop/trunk@266 f606c939-3180-4ac9-a4b8-4b8779d57d0a --- recordmydesktop/src/cache_frame.c | 166 ++++++++++++++++++++++---------------- 1 file changed, 95 insertions(+), 71 deletions(-) (limited to 'recordmydesktop/src/cache_frame.c') diff --git a/recordmydesktop/src/cache_frame.c b/recordmydesktop/src/cache_frame.c index 07c7c70..4258932 100644 --- a/recordmydesktop/src/cache_frame.c +++ b/recordmydesktop/src/cache_frame.c @@ -32,23 +32,24 @@ int CompareBlocks(unsigned char *incoming, int blockno, int width, int height, - int divisor){ + int blockwidth){ int j,i, - block_i=blockno/divisor,//place on the grid - block_k=blockno%divisor; - register unsigned char *incoming_reg=&(incoming[block_i* - (width*height/divisor)+ - block_k*width/divisor]), - *old_reg=&(old[block_i*(width*height/divisor)+ - block_k*width/divisor]); - - for(j=0;j=CACHE_OUT_BUFFER_SIZE || + (flush && out_buffer_bytes)){ + if(ucfp==NULL) + gzwrite(fp,(void *)out_buffer,out_buffer_bytes); + else + fwrite((void *)out_buffer,1,out_buffer_bytes,ucfp); + bytes_written=out_buffer_bytes; + out_buffer_bytes=0; } - else{ - for(j=0;jenc_data->yuv.y_width/Y_UNIT_WIDTH, + blocknum_y=pdata->enc_data->yuv.y_height/Y_UNIT_WIDTH, firstrun=1, frameno=0, nbytes=0, nth_cache=1; - + u_int32_t ynum,unum,vnum; + u_int32_t yblocks[blocknum_x*blocknum_y], + ublocks[blocknum_x*blocknum_y], + vblocks[blocknum_x*blocknum_y]; if(!pdata->args.zerocompression){ fp=pdata->cache_data->ifp; if(fp==NULL)exit(13); @@ -121,8 +140,6 @@ void *CacheImageBuffer(ProgData *pdata){ while(pdata->running){ int prev; int j; - unsigned short ynum,unum,vnum; - unsigned char yblocks[256],ublocks[64],vblocks[64]; FrameHeader fheader; ynum=unum=vnum=0; @@ -151,41 +168,41 @@ void *CacheImageBuffer(ProgData *pdata){ //find and flush different blocks if(firstrun){ firstrun=0; - for(j=0;jargs.zerocompression){ - if(ynum+unum+vnum>(pow(divisor,2)+pow(divisor/2,2)*2)/10) + if(ynum*4+unum+vnum>(blocknum_x*blocknum_y*6)/10) gzsetparams (fp,1,Z_FILTERED); else gzsetparams (fp,0,Z_FILTERED); @@ -203,52 +220,60 @@ void *CacheImageBuffer(ProgData *pdata){ strncpy(fheader.frame_prefix,"FRAM",4); fheader.frameno=++frameno; fheader.current_total=frames_total; + fheader.Ynum=ynum; fheader.Unum=unum; fheader.Vnum=vnum; - fheader.pad=0; if(!pdata->args.zerocompression){ nbytes+=gzwrite(fp,(void*)&fheader,sizeof(FrameHeader)); //flush indexes - if(ynum)nbytes+=gzwrite(fp,yblocks,ynum); - if(unum)nbytes+=gzwrite(fp,ublocks,unum); - if(vnum)nbytes+=gzwrite(fp,vblocks,vnum); + if(ynum)nbytes+=gzwrite(fp,(void*)yblocks,ynum*index_entry_size); + if(unum)nbytes+=gzwrite(fp,(void*)ublocks,unum*index_entry_size); + if(vnum)nbytes+=gzwrite(fp,(void*)vblocks,vnum*index_entry_size); } else{ nbytes+=sizeof(FrameHeader)* fwrite((void*)&fheader,sizeof(FrameHeader),1,ucfp); //flush indexes - 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); + if(ynum)nbytes+=index_entry_size* + fwrite(yblocks,index_entry_size,ynum,ucfp); + if(unum)nbytes+=index_entry_size* + fwrite(ublocks,index_entry_size,unum,ucfp); + if(vnum)nbytes+=index_entry_size* + fwrite(vblocks,index_entry_size,vnum,ucfp); } //flush the blocks for each buffer - if(ynum) + if(ynum){ for(j=0;javd+=pdata->frametime; if(nbytes>CACHE_FILE_SIZE_LIMIT){ @@ -274,7 +299,6 @@ void *CacheImageBuffer(ProgData *pdata){ nbytes=0; } } - //clean up since we're not finished for(i=0;i<2;i++){ free(yuv[i].y); -- cgit v1.2.1