summaryrefslogtreecommitdiff
path: root/rMD-exp
diff options
context:
space:
mode:
authoriovar <iovar@f606c939-3180-4ac9-a4b8-4b8779d57d0a>2006-10-24 12:58:54 +0000
committeriovar <iovar@f606c939-3180-4ac9-a4b8-4b8779d57d0a>2006-10-24 12:58:54 +0000
commitba11f851311f9f92f92fcd8148a8f621b736e979 (patch)
treedd062f9ff9f0fe8f2e26cb323300a121704e6c95 /rMD-exp
parentffe69a6240de9e6bb56b9b729b8133fb323cee80 (diff)
gzipped frame caching
git-svn-id: https://recordmydesktop.svn.sourceforge.net/svnroot/recordmydesktop/trunk@114 f606c939-3180-4ac9-a4b8-4b8779d57d0a
Diffstat (limited to 'rMD-exp')
-rw-r--r--rMD-exp/include/recordmydesktop.h38
-rw-r--r--rMD-exp/src/cache_frame.c58
2 files changed, 76 insertions, 20 deletions
diff --git a/rMD-exp/include/recordmydesktop.h b/rMD-exp/include/recordmydesktop.h
index 9255525..b06db1b 100644
--- a/rMD-exp/include/recordmydesktop.h
+++ b/rMD-exp/include/recordmydesktop.h
@@ -235,31 +235,39 @@ typedef struct _ProgData{
//the same platform.
//We need the total number of blocks
-//and the position number of each of them
-//(separately for y,u,v planes).
+//for each plane.
+
//The number of the frame compared to the
//number of time expirations at the time of
//caching, will enable us to make up for lost frames.
-
+//default 4+4+2+2+2=14!bad!
+//me add pad, make god of 2 happy!
typedef struct _FrameHeader{
-
- unsigned int frameno;//number of frame(cached frames)
- unsigned int current_total;//number of frames that should have been
+ u_int32_t frameno,//number of frame(cached frames)
+ current_total;//number of frames that should have been
//taken at time of caching this one
- unsigned short Ynum;//number of changed blocks in the Y plane
- unsigned short Unum;//number of changed blocks in the U plane
- unsigned short Vnum;//number of changed blocks in the V plane
- unsigned char *YBlocks;//identifying number on the grid, starting at top left
- unsigned char *UBlocks;// >> >>
- unsigned char *VBlocks;// >> >>
- unsigned char *YData;//data for the blocks that have changed,
- unsigned char *UData;//which have to be remapped on the buffer when reading
- unsigned char *VData;
+ u_int16_t Ynum,//number of changed blocks in the Y plane
+ Unum,//number of changed blocks in the U plane
+ Vnum;//number of changed blocks in the V plane
+ u_int16_t pad;//always zero
}FrameHeader;
+//The frame after retrieval.
+//Based on the Header information
+//we can read the correct amount of bytes.
+
+typedef struct _CachedFrame{
+ FrameHeader *header;
+ unsigned char *YBlocks;//identifying number on the grid, starting at top left
+ unsigned char *UBlocks;// >> >>
+ unsigned char *VBlocks;// >> >>
+ unsigned char *YData;//pointer to data for the blocks that have changed,
+ unsigned char *UData;//which have to be remapped on the buffer when reading
+ unsigned char *VData;
+}CachedFrame;
/**Globals*/
diff --git a/rMD-exp/src/cache_frame.c b/rMD-exp/src/cache_frame.c
index 894de3b..6b214e0 100644
--- a/rMD-exp/src/cache_frame.c
+++ b/rMD-exp/src/cache_frame.c
@@ -25,7 +25,7 @@
**********************************************************************************/
#include <recordmydesktop.h>
-
+#include <zlib.h>
void MakeChecksums(unsigned char *buf,int width,int height,int divisor,unsigned short int *checksums){
int i,k,j,m;
@@ -45,17 +45,29 @@ void MakeChecksums(unsigned char *buf,int width,int height,int divisor,unsigned
}
}
+void FlushBlock(unsigned char *buf,int blockno,int width, int height,int divisor,gzFile *fp){
+ int j,
+ block_i=blockno/divisor,//place on the grid
+ block_k=blockno%divisor;
+
+ for(j=0;j<height/divisor;j++)//we flush in rows
+ gzwrite(fp,(void *)&buf[block_i*(width*height/divisor)+j*width+block_k*width/divisor],width/divisor);
+
+}
+
void *CacheImageBuffer(void *pdata){
pthread_mutex_t pmut,imut;
pthread_mutex_init(&pmut,NULL);
pthread_mutex_init(&imut,NULL);
yuv_buffer yuv[2];
-
+ gzFile *fp;
+ fp=gzopen("temp.out","wb1f");
+ if(fp==NULL)exit(13);
unsigned short int checksums_y[2][256],
checksums_u[2][64],
checksums_v[2][64];
- int i,current=0,divisor=16,firstrun=1;
+ int i,current=0,divisor=16,firstrun=1,frameno=0;
//we want to make sure that each block has a sufficient
//number of bytes, so that the checksum will wrap
@@ -111,7 +123,9 @@ void *CacheImageBuffer(void *pdata){
int j;
unsigned short ynum,unum,vnum;
unsigned char yblocks[256],ublocks[64],vblocks[64];
+ FrameHeader fheader;
ynum=unum=vnum=0;
+
for(j=0;j<pow(divisor,2);j++){
if(checksums_y[current][j]!=checksums_y[prev][j]){
ynum++;
@@ -130,8 +144,41 @@ void *CacheImageBuffer(void *pdata){
vblocks[vnum-1]=j;
}
}
+ /**WRITE FRAME TO DISK*/
+ if(ynum+unum+vnum>(pow(divisor,2)+pow(divisor/2,2)*2)/10)
+ gzsetparams (fp,1,Z_FILTERED);
+ else
+ gzsetparams (fp,0,Z_FILTERED);
+ fheader.frameno=++frameno;
+ fheader.current_total=frames_total;
+ fheader.Ynum=ynum;
+ fheader.Unum=unum;
+ fheader.Vnum=vnum;
+ fheader.pad=0;
+ gzwrite(fp,(void*)&fheader,16);
+ //flush indexes
+ if(ynum)gzwrite(fp,yblocks,ynum);
+ if(unum)gzwrite(fp,ublocks,unum);
+ if(vnum)gzwrite(fp,vblocks,vnum);
+
+
+ //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);
+ 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);
+ 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);
+
+
+ /**@________________@**/
((ProgData *)pdata)->avd+=((ProgData *)pdata)->frametime*2*((ProgData *)pdata)->args.channels;
-// fprintf(stderr,"k %d uk %d vk %d\n ",k,uk,vk);
+
+
+
}
}
@@ -141,6 +188,7 @@ void *CacheImageBuffer(void *pdata){
free(yuv[i].u);
free(yuv[i].v);
}
-
+ fprintf(stderr,"Saved %d frames in a total of %d requests",frameno,frames_total);
+ gzclose(fp);
pthread_exit(&errno);
}
© All Rights Reserved