summaryrefslogtreecommitdiff
path: root/recordmydesktop/src
diff options
context:
space:
mode:
authoriovar <iovar@f606c939-3180-4ac9-a4b8-4b8779d57d0a>2006-11-08 16:26:44 +0000
committeriovar <iovar@f606c939-3180-4ac9-a4b8-4b8779d57d0a>2006-11-08 16:26:44 +0000
commitad5b05712d9ed8650fcc145373ac878f8e6b8829 (patch)
tree96284e14aec9e30f72e9d2fe3b486cf1c254b225 /recordmydesktop/src
parentfd4a7480e74008c0e654ad9bf790a8fa6625e661 (diff)
Replaced all files with the ones in the rMD-exp module.
(this should have been a branch not a module, but it's too late now. rMD-exp module will be purged but if anyone's interested on the not-so descriptive commit logs, they'll be on the attic. This is the start of the 0.3 branch. Files will will be tagged as v0_3_0 in a new branch before final release. Snapshot prior to this release has tagged as v0_2_7 in a new branch. All releases will be tagged and branched from now on. git-svn-id: https://recordmydesktop.svn.sourceforge.net/svnroot/recordmydesktop/trunk@153 f606c939-3180-4ac9-a4b8-4b8779d57d0a
Diffstat (limited to 'recordmydesktop/src')
-rw-r--r--recordmydesktop/src/Makefile.am14
-rw-r--r--recordmydesktop/src/cache_audio.c (renamed from recordmydesktop/src/zpixmaptobmp.c)81
-rw-r--r--recordmydesktop/src/cache_frame.c193
-rw-r--r--recordmydesktop/src/encode_image_buffer.c20
-rw-r--r--recordmydesktop/src/encode_sound_buffer.c30
-rw-r--r--recordmydesktop/src/init_encoder.c70
-rw-r--r--recordmydesktop/src/load_cache.c187
-rw-r--r--recordmydesktop/src/parseargs.c64
-rw-r--r--recordmydesktop/src/poll_damage.c47
-rw-r--r--recordmydesktop/src/recordmydesktop.c211
-rw-r--r--recordmydesktop/src/register_callbacks.c10
-rw-r--r--recordmydesktop/src/rmd_cache.c102
-rw-r--r--recordmydesktop/src/wm_check.c68
13 files changed, 925 insertions, 172 deletions
diff --git a/recordmydesktop/src/Makefile.am b/recordmydesktop/src/Makefile.am
index e56b856..d5fa847 100644
--- a/recordmydesktop/src/Makefile.am
+++ b/recordmydesktop/src/Makefile.am
@@ -3,7 +3,6 @@ bin_PROGRAMS = recordmydesktop
recordmydesktop_SOURCES= recordmydesktop.c\
- zpixmaptobmp.c\
getzpixmap.c\
parseargs.c\
rectinsert.c\
@@ -20,9 +19,14 @@ recordmydesktop_SOURCES= recordmydesktop.c\
opendev.c\
capture_sound.c\
encode_sound_buffer.c\
- init_encoder.c
+ init_encoder.c\
+ cache_frame.c\
+ cache_audio.c\
+ rmd_cache.c\
+ load_cache.c\
+ wm_check.c
-INCLUDES= $(all_includes) -I../include -I$x_includes
-
-recordmydesktop_LDFLAGS = -D_THREAD_SAFE -pthread -Wall
+INCLUDES= $(all_includes) -I../include
+recordmydesktop_LDFLAGS = @X_LIBS@ @X_EXTRA_LIBS@ @X_PRE_LIBS@
+recordmydesktop_CFLAGS = -D_THREAD_SAFE -pthread -Wall
diff --git a/recordmydesktop/src/zpixmaptobmp.c b/recordmydesktop/src/cache_audio.c
index 0aa9477..7b17d7b 100644
--- a/recordmydesktop/src/zpixmaptobmp.c
+++ b/recordmydesktop/src/cache_audio.c
@@ -24,55 +24,44 @@
* For further information contact me at johnvarouhakis@gmail.com *
**********************************************************************************/
-
#include <recordmydesktop.h>
+void *CacheSoundBuffer(void *pdata){
+//We are simply going to throw sound on the disk.
+//It's sound is tiny compared to that of image, so
+//compressing would reducethe overall size by only an
+//insignificant fraction.
+ pthread_mutex_t smut;
+ pthread_mutex_init(&smut,NULL);
+ while((((ProgData *)pdata)->running)){
+ SndBuffer *buff;
-int ZPixmapToBMP(XImage *imgz,BRWindow *brwin,char *fname,int nbytes,int scale){
- FILE *fpbmp;
- int i,k;
- int siz=52+nbytes/(pow(scale,2));
- int offs=54+1024;
- short int rsrvd=0;
- int hsiz=40;
- int width=brwin->rgeom.width/scale,height=brwin->rgeom.height/scale,nbts=nbytes/(pow(scale,2));
- unsigned short int planes=1;
- unsigned short int bpp=24;
- unsigned int cmpr=0;
- unsigned int ncols=0;
- char *dtap=imgz->data;
-
- /*Write header*/
- fpbmp=fopen(fname,"wb");
- fputc('B',fpbmp);
- fputc('M',fpbmp);
- fwrite(&siz,4,1,fpbmp);
- fwrite(&rsrvd,2,1,fpbmp);
- fwrite(&rsrvd,2,1,fpbmp);
- fwrite(&offs,4,1,fpbmp);
- fwrite(&hsiz,4,1,fpbmp);
- fwrite(&(width),4,1,fpbmp);
- fwrite(&(height),4,1,fpbmp);
- fwrite(&planes,2,1,fpbmp);
- fwrite(&bpp,2,1,fpbmp);
- fwrite(&cmpr,4,1,fpbmp);
- fwrite(&nbts,4,1,fpbmp);
- fwrite(&(width),4,1,fpbmp);
- fwrite(&(height),4,1,fpbmp);
- fwrite(&(ncols),4,1,fpbmp);
- fwrite(&(ncols),4,1,fpbmp);
- for(i=0;i<1024;i++)
- fputc(0,fpbmp);
- /*Data*/
- for(k=(nbytes/imgz->bytes_per_line)-1;k>=0;k-=scale){
- for(i=0;i<imgz->bytes_per_line/4;i+=scale){
- fwrite(&dtap[(i*4)+k*(imgz->bytes_per_line)],1,1,fpbmp);
- fwrite(&dtap[(i*4)+k*(imgz->bytes_per_line)+1],1,1,fpbmp);
- fwrite(&dtap[(i*4)+k*(imgz->bytes_per_line)+2],1,1,fpbmp);
- }
+ if(Paused){
+ pthread_mutex_t tmut;
+ pthread_mutex_init(&tmut,NULL);
+ pthread_cond_wait(&((ProgData *)pdata)->pause_cond,&tmut);
}
-
- fclose(fpbmp);
- return 0;
+
+ if(((ProgData *)pdata)->sound_buffer==NULL)
+ pthread_cond_wait(&((ProgData *)pdata)->sound_data_read,&smut);
+
+ pthread_mutex_lock(&((ProgData *)pdata)->sound_buffer_mutex);
+ buff=((ProgData *)pdata)->sound_buffer;
+ //advance the list
+ ((ProgData *)pdata)->sound_buffer=((ProgData *)pdata)->sound_buffer->next;
+ pthread_mutex_unlock(&((ProgData *)pdata)->sound_buffer_mutex);
+
+ fwrite(buff->data,((ProgData *)pdata)->periodsize,1,((ProgData *)pdata)->cache_data->afp);
+
+
+
+ ((ProgData *)pdata)->avd-=((ProgData *)pdata)->periodtime;
+
+ free(buff->data);
+ free(buff);
+ }
+
+ fclose(((ProgData *)pdata)->cache_data->afp);
+ pthread_exit(&errno);
}
diff --git a/recordmydesktop/src/cache_frame.c b/recordmydesktop/src/cache_frame.c
new file mode 100644
index 0000000..c100505
--- /dev/null
+++ b/recordmydesktop/src/cache_frame.c
@@ -0,0 +1,193 @@
+/*********************************************************************************
+* recordMyDesktop *
+**********************************************************************************
+* *
+* Copyright (C) 2006 John Varouhakis *
+* *
+* *
+* This program is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+* *
+* This program is distributed in the hope that it will be useful, *
+* but WITHOUT ANY WARRANTY; without even the implied warranty of *
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+* GNU General Public License for more details. *
+* *
+* You should have received a copy of the GNU General Public License *
+* along with this program; if not, write to the Free Software *
+* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
+* *
+* *
+* *
+* For further information contact me at johnvarouhakis@gmail.com *
+**********************************************************************************/
+
+#include <recordmydesktop.h>
+
+
+int CompareBlocks(unsigned char *incoming,unsigned char *old,int blockno,int width, int height,int divisor){
+ 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<height/divisor;j++){
+ for(i=0;i<width/divisor;i++){
+ if((*(incoming_reg++))!=(*(old_reg++)))
+ return 1;
+ }
+ incoming_reg+=(width-width/divisor);
+ old_reg+=(width-width/divisor);
+ }
+
+ return 0;
+}
+
+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;
+ register unsigned char *buf_reg=(&buf[block_i*(width*height/divisor)+block_k*width/divisor]);
+ for(j=0;j<height/divisor;j++){//we flush in rows
+ gzwrite(fp,(void *)buf_reg,width/divisor);
+ buf_reg+=width;
+ }
+}
+
+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=((ProgData *)pdata)->cache_data->ifp;
+
+ if(fp==NULL)exit(13);
+
+ int i,current=0,divisor=16,firstrun=1,frameno=0;
+
+ for(i=0;i<2;i++){
+ yuv[i].y_width=((ProgData *)pdata)->enc_data->yuv.y_width;
+ yuv[i].y_height=((ProgData *)pdata)->enc_data->yuv.y_height;
+ yuv[i].uv_width=((ProgData *)pdata)->enc_data->yuv.uv_width;
+ yuv[i].uv_height=((ProgData *)pdata)->enc_data->yuv.uv_height;
+
+ yuv[i].y=(unsigned char *)malloc(yuv[i].y_width*yuv[i].y_height);
+ yuv[i].u=(unsigned char *)malloc(yuv[i].uv_width*yuv[i].uv_height);
+ yuv[i].v=(unsigned char *)malloc(yuv[i].uv_width*yuv[i].uv_height);
+ }
+
+
+ while(((ProgData *)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;
+
+ pthread_cond_wait(&((ProgData *)pdata)->image_buffer_ready,&imut);
+ if(Paused)
+ pthread_cond_wait(&((ProgData *)pdata)->pause_cond,&pmut);
+ pthread_mutex_lock(&((ProgData *)pdata)->yuv_mutex);
+
+ //rotate buffers
+ prev=current;
+ current=(current)?0:1;
+ //copy incoming
+ memcpy(yuv[current].y,((ProgData *)pdata)->enc_data->yuv.y,yuv[current].y_width*yuv[current].y_height);
+ memcpy(yuv[current].u,((ProgData *)pdata)->enc_data->yuv.u,yuv[current].uv_width*yuv[current].uv_height);
+ memcpy(yuv[current].v,((ProgData *)pdata)->enc_data->yuv.v,yuv[current].uv_width*yuv[current].uv_height);
+ //release main buffer
+ pthread_mutex_unlock(&((ProgData *)pdata)->yuv_mutex);
+ //get checksums for new
+
+ //find and flush different blocks
+ if(firstrun){
+ firstrun=0;
+ for(j=0;j<pow(divisor,2);j++){
+ ynum++;
+ yblocks[ynum-1]=j;
+ }
+ for(j=0;j<pow(divisor/2,2);j++){
+ unum++;
+ ublocks[unum-1]=j;
+ }
+ for(j=0;j<pow(divisor/2,2);j++){
+ vnum++;
+ vblocks[vnum-1]=j;
+ }
+
+ }
+ else{
+ for(j=0;j<pow(divisor,2);j++){
+ if(CompareBlocks(yuv[current].y,yuv[prev].y,j,yuv[current].y_width,yuv[current].y_height,divisor)){
+ ynum++;
+ yblocks[ynum-1]=j;
+ }
+ }
+ for(j=0;j<pow(divisor/2,2);j++){
+ if(CompareBlocks(yuv[current].u,yuv[prev].u,j,yuv[current].uv_width,yuv[current].uv_height,divisor/2)){
+ unum++;
+ ublocks[unum-1]=j;
+ }
+ }
+ for(j=0;j<pow(divisor/2,2);j++){
+ if(CompareBlocks(yuv[current].v,yuv[prev].v,j,yuv[current].uv_width,yuv[current].uv_height,divisor/2)){
+ vnum++;
+ vblocks[vnum-1]=j;
+ }
+ }
+
+ }
+ /**WRITE FRAME TO DISK*/
+ if(!((ProgData *)pdata)->args.zerocompression){
+ if(ynum+unum+vnum>(pow(divisor,2)+pow(divisor/2,2)*2)/10)
+ gzsetparams (fp,1,Z_FILTERED);
+ else
+ gzsetparams (fp,0,Z_FILTERED);
+ }
+
+ 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;
+ 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);
+
+
+ //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;
+
+ }
+
+ //clean up since we're not finished
+ for(i=0;i<2;i++){
+ free(yuv[i].y);
+ free(yuv[i].u);
+ free(yuv[i].v);
+ }
+ fprintf(stderr,"Saved %d frames in a total of %d requests\n",frameno,frames_total);
+ gzclose(fp);
+ pthread_exit(&errno);
+}
diff --git a/recordmydesktop/src/encode_image_buffer.c b/recordmydesktop/src/encode_image_buffer.c
index 38a1d77..8ff9629 100644
--- a/recordmydesktop/src/encode_image_buffer.c
+++ b/recordmydesktop/src/encode_image_buffer.c
@@ -30,8 +30,8 @@ void *EncodeImageBuffer(void *pdata){
pthread_mutex_init(&pmut,NULL);
pthread_mutex_init(&imut,NULL);
while(((ProgData *)pdata)->running){
- encoder_busy=1;
pthread_cond_wait(&((ProgData *)pdata)->image_buffer_ready,&imut);
+ encoder_busy=1;
if(Paused)
pthread_cond_wait(&((ProgData *)pdata)->pause_cond,&pmut);//this may not be needed
pthread_mutex_lock(&((ProgData *)pdata)->yuv_mutex);
@@ -62,4 +62,22 @@ void *EncodeImageBuffer(void *pdata){
pthread_exit(&errno);
}
+//this function is meant to be called normally
+//not through a thread of it's own
+void SyncEncodeImageBuffer(ProgData *pdata){
+ if(theora_encode_YUVin(&pdata->enc_data->m_th_st,
+ &pdata->enc_data->yuv)){
+ fprintf(stderr,"Encoder not ready!\n");
+ }
+ else{
+ if(theora_encode_packetout(&pdata->enc_data->m_th_st,0,
+ &pdata->enc_data->m_ogg_pckt1)==1){
+ pthread_mutex_lock(&pdata->libogg_mutex);
+ ogg_stream_packetin(&pdata->enc_data->m_ogg_ts,
+ &pdata->enc_data->m_ogg_pckt1);
+ pthread_mutex_unlock(&pdata->libogg_mutex);
+ pdata->avd+=pdata->frametime*2*pdata->args.channels;
+ }
+ }
+}
diff --git a/recordmydesktop/src/encode_sound_buffer.c b/recordmydesktop/src/encode_sound_buffer.c
index 85e277d..73f6d48 100644
--- a/recordmydesktop/src/encode_sound_buffer.c
+++ b/recordmydesktop/src/encode_sound_buffer.c
@@ -90,4 +90,32 @@ void *EncodeSoundBuffer(void *pdata){
pthread_exit(&errno);
}
-
+void SyncEncodeSoundBuffer(ProgData *pdata,signed char *buff){
+ float **vorbis_buffer;
+ int count=0,i,j;
+ int sampread=pdata->periodsize/(2*pdata->args.channels);
+ vorbis_buffer=vorbis_analysis_buffer(&pdata->enc_data->m_vo_dsp,sampread);
+ for(i=0;i<sampread;i++){
+ for(j=0;j<pdata->args.channels;j++){
+ vorbis_buffer[j][i]=((buff[count+1]<<8)|
+ (0x00ff&(int)buff[count]))/32768.f;
+ count+=2;
+ }
+ }
+
+ vorbis_analysis_wrote(&pdata->enc_data->m_vo_dsp,sampread);
+
+ while(vorbis_analysis_blockout(&pdata->enc_data->m_vo_dsp,&pdata->enc_data->m_vo_block)==1){
+
+ vorbis_analysis(&pdata->enc_data->m_vo_block,NULL);
+ vorbis_bitrate_addblock(&pdata->enc_data->m_vo_block);
+
+ while(vorbis_bitrate_flushpacket(&pdata->enc_data->m_vo_dsp,&pdata->enc_data->m_ogg_pckt2)){
+ pthread_mutex_lock(&pdata->libogg_mutex);
+ ogg_stream_packetin(&pdata->enc_data->m_ogg_vs,&pdata->enc_data->m_ogg_pckt2);
+ pthread_mutex_unlock(&pdata->libogg_mutex);
+ }
+ }
+ pdata->avd-=pdata->periodtime;
+}
+
diff --git a/recordmydesktop/src/init_encoder.c b/recordmydesktop/src/init_encoder.c
index ed1ad53..84d36aa 100644
--- a/recordmydesktop/src/init_encoder.c
+++ b/recordmydesktop/src/init_encoder.c
@@ -27,7 +27,35 @@
#include <recordmydesktop.h>
-void InitEncoder(ProgData *pdata,EncData *enc_data_t){
+int IncrementalNaming(char **name){
+ struct stat buff;
+ char *base_name;
+ int i=0;
+ base_name=malloc(strlen(*name));
+ strcpy(base_name,*name);
+
+ //this will go on an endless loop if you have 65536? files with the same name
+ //or it will crash and die.anyone interested in trying ?
+ while (stat(*name,&buff)==0){
+ //create new name
+ char *tname=malloc(strlen(*name)+10);
+ char numbuf[8];
+
+ strcpy(tname,base_name);
+ strcat(tname,".");
+ I16TOA((++i),numbuf)
+ strcat(tname,numbuf);
+ //save new name
+ free(*name);
+ *name=malloc(strlen(tname)+1);
+ strcpy(*name,tname);
+ free(tname);
+ }
+ free(base_name);
+ return 0;
+}
+
+void InitEncoder(ProgData *pdata,EncData *enc_data_t,int buffer_ready){
int y1,y2;
(pdata)->enc_data=enc_data_t;
srand(time(NULL));
@@ -38,12 +66,13 @@ void InitEncoder(ProgData *pdata,EncData *enc_data_t){
ogg_stream_init(&(enc_data_t)->m_ogg_ts,y1);
if(!pdata->args.nosound)
ogg_stream_init(&(enc_data_t)->m_ogg_vs,y2);
-
+ if(!pdata->args.overwrite)
+ IncrementalNaming(&(pdata)->args.filename);
(enc_data_t)->fp=fopen((pdata)->args.filename,"w");
if((enc_data_t)->fp==NULL){
fprintf(stderr,"Cannot open file %s for writting!\n",(pdata)->args.filename);
exit(13);
- }
+ }
theora_info_init(&(enc_data_t)->m_th_inf);
(enc_data_t)->m_th_inf.frame_width=(pdata)->brwin.rgeom.width;
(enc_data_t)->m_th_inf.frame_height=(pdata)->brwin.rgeom.height;
@@ -87,7 +116,7 @@ void InitEncoder(ProgData *pdata,EncData *enc_data_t){
vorbis_block_init(&(enc_data_t)->m_vo_dsp,&(enc_data_t)->m_vo_block);
}
-
+
theora_encode_header(&(enc_data_t)->m_th_st,&(enc_data_t)->m_ogg_pckt1);
ogg_stream_packetin(&(enc_data_t)->m_ogg_ts,&(enc_data_t)->m_ogg_pckt1);
if(ogg_stream_pageout(&(enc_data_t)->m_ogg_ts,&(enc_data_t)->m_ogg_pg)!=1){
@@ -109,16 +138,16 @@ void InitEncoder(ProgData *pdata,EncData *enc_data_t){
ogg_packet header;
ogg_packet header_comm;
ogg_packet header_code;
-
+
vorbis_analysis_headerout(&(enc_data_t)->m_vo_dsp,&(enc_data_t)->m_vo_cmmnt,&header,&header_comm,&header_code);
- ogg_stream_packetin(&(enc_data_t)->m_ogg_vs,&header);
+ ogg_stream_packetin(&(enc_data_t)->m_ogg_vs,&header);
if(ogg_stream_pageout(&(enc_data_t)->m_ogg_vs,&(enc_data_t)->m_ogg_pg)!=1){
fprintf(stderr,"Internal Ogg library error.\n");
exit(2);
}
fwrite((enc_data_t)->m_ogg_pg.header,1,(enc_data_t)->m_ogg_pg.header_len,(enc_data_t)->fp);
fwrite((enc_data_t)->m_ogg_pg.body,1,(enc_data_t)->m_ogg_pg.body_len,(enc_data_t)->fp);
-
+
ogg_stream_packetin(&(enc_data_t)->m_ogg_vs,&header_comm);
ogg_stream_packetin(&(enc_data_t)->m_ogg_vs,&header_code);
}
@@ -150,23 +179,24 @@ void InitEncoder(ProgData *pdata,EncData *enc_data_t){
}
+ if(!buffer_ready){
+ (enc_data_t)->yuv.y=(unsigned char *)malloc((enc_data_t)->m_th_inf.height*(enc_data_t)->m_th_inf.width);
+ (enc_data_t)->yuv.u=(unsigned char *)malloc((enc_data_t)->m_th_inf.height*(enc_data_t)->m_th_inf.width/4);
+ (enc_data_t)->yuv.v=(unsigned char *)malloc((enc_data_t)->m_th_inf.height*(enc_data_t)->m_th_inf.width/4);
+ (enc_data_t)->yuv.y_width=(enc_data_t)->m_th_inf.width;
+ (enc_data_t)->yuv.y_height=(enc_data_t)->m_th_inf.height;
+ (enc_data_t)->yuv.y_stride=(enc_data_t)->m_th_inf.width;
- (enc_data_t)->yuv.y=(unsigned char *)malloc((enc_data_t)->m_th_inf.height*(enc_data_t)->m_th_inf.width);
- (enc_data_t)->yuv.u=(unsigned char *)malloc((enc_data_t)->m_th_inf.height*(enc_data_t)->m_th_inf.width/4);
- (enc_data_t)->yuv.v=(unsigned char *)malloc((enc_data_t)->m_th_inf.height*(enc_data_t)->m_th_inf.width/4);
- (enc_data_t)->yuv.y_width=(enc_data_t)->m_th_inf.width;
- (enc_data_t)->yuv.y_height=(enc_data_t)->m_th_inf.height;
- (enc_data_t)->yuv.y_stride=(enc_data_t)->m_th_inf.width;
-
- (enc_data_t)->yuv.uv_width=(enc_data_t)->m_th_inf.width/2;
- (enc_data_t)->yuv.uv_height=(enc_data_t)->m_th_inf.height/2;
- (enc_data_t)->yuv.uv_stride=(enc_data_t)->m_th_inf.width/2;
- (enc_data_t)->x_offset=(enc_data_t)->m_th_inf.offset_x;
- (enc_data_t)->y_offset=(enc_data_t)->m_th_inf.offset_y;
+ (enc_data_t)->yuv.uv_width=(enc_data_t)->m_th_inf.width/2;
+ (enc_data_t)->yuv.uv_height=(enc_data_t)->m_th_inf.height/2;
+ (enc_data_t)->yuv.uv_stride=(enc_data_t)->m_th_inf.width/2;
+ (enc_data_t)->x_offset=(enc_data_t)->m_th_inf.offset_x;
+ (enc_data_t)->y_offset=(enc_data_t)->m_th_inf.offset_y;
+ }
theora_info_clear(&(enc_data_t)->m_th_inf);
}
-
+
diff --git a/recordmydesktop/src/load_cache.c b/recordmydesktop/src/load_cache.c
new file mode 100644
index 0000000..cd09956
--- /dev/null
+++ b/recordmydesktop/src/load_cache.c
@@ -0,0 +1,187 @@
+/*********************************************************************************
+* recordMyDesktop *
+**********************************************************************************
+* *
+* Copyright (C) 2006 John Varouhakis *
+* *
+* *
+* This program is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+* *
+* This program is distributed in the hope that it will be useful, *
+* but WITHOUT ANY WARRANTY; without even the implied warranty of *
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+* GNU General Public License for more details. *
+* *
+* You should have received a copy of the GNU General Public License *
+* along with this program; if not, write to the Free Software *
+* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
+* *
+* *
+* *
+* For further information contact me at johnvarouhakis@gmail.com *
+**********************************************************************************/
+
+
+#include <recordmydesktop.h>
+
+void LoadBlock(unsigned char *dest,unsigned char *source,int blockno,int width, int height,int divisor){
+ int j,
+ block_i=blockno/divisor,//place on the grid
+ block_k=blockno%divisor;
+
+ for(j=0;j<height/divisor;j++)//we copy rows
+ memcpy( &dest[block_i*(width*height/divisor)+j*width+block_k*width/divisor],
+ &source[j*width/divisor],
+ width/divisor);
+}
+
+
+
+void *LoadCache(void *pdata){
+
+ yuv_buffer *yuv=&((ProgData *)pdata)->enc_data->yuv;
+ gzFile *ifp=((ProgData *)pdata)->cache_data->ifp;
+ FILE *afp=((ProgData *)pdata)->cache_data->afp;
+ FrameHeader fheader;
+ CachedFrame frame;
+ signed char *sound_data=(signed char *)malloc(((ProgData *)pdata)->periodsize);
+
+ int j=0,
+ audio_end=0,
+ extra_frames=0,//total number of duplicated frames
+ missing_frames=0,//if this is found >0 current run will not load
+ //a frame but it will proccess the previous
+ thread_exit=0,//0 success, -1 couldn't find files,1 couldn't remove
+ divisor=16,
+ blockszy=0,//size of y plane block in bytes
+ blockszuv=0;//size of u,v plane blocks in bytes
+ //we allocate the frame that we will use
+ INIT_FRAME(&frame,&fheader,yuv)
+ //and the we open our files
+ ifp=gzopen(((ProgData *)pdata)->cache_data->imgdata,"rb");
+ if(ifp==NULL){
+ thread_exit=-1;
+ pthread_exit(&thread_exit);
+ }
+
+ if(!((ProgData *)pdata)->args.nosound){
+ afp=fopen(((ProgData *)pdata)->cache_data->audiodata,"rb");
+ if(afp==NULL){
+ thread_exit=-1;
+ pthread_exit(&thread_exit);
+ }
+ }
+ //these two are likely to be the same, but not guaranteed, especially on
+ //low resolutions
+ blockszy=(yuv->y_width*yuv->y_height )/pow(divisor,2);
+ blockszuv=(yuv->uv_width*yuv->uv_height)/pow(divisor/2,2);
+
+ //this will be used now to define if we proccess audio or video
+ //on any given loop.
+ ((ProgData *)pdata)->avd=0;
+ //If sound finishes first,we go on with the video.
+ //If video ends we will do one more run to flush audio in the ogg file
+
+ while(((ProgData *)pdata)->running){
+ //video load and encoding
+ if(((ProgData *)pdata)->avd<=0 || ((ProgData *)pdata)->args.nosound || audio_end){
+ if(missing_frames>0){
+ extra_frames++;
+ missing_frames--;
+ SyncEncodeImageBuffer((ProgData *)pdata);
+ }
+ else if(gzread(ifp,frame.header,sizeof(FrameHeader))==sizeof(FrameHeader)){
+ //sync
+ missing_frames+=frame.header->current_total-(extra_frames+frame.header->frameno);
+ fprintf(stdout,"\r[%d%%] ",
+ ((frame.header->frameno+extra_frames)*100)/frames_total);
+
+ fflush(stdout);
+ if( (frame.header->Ynum<=pow(divisor,2)) &&
+ (frame.header->Unum<=pow(divisor/2,2)) &&
+ (frame.header->Vnum<=pow(divisor/2,2)) &&
+ (gzread(ifp,frame.YBlocks,frame.header->Ynum)==frame.header->Ynum) &&
+ (gzread(ifp,frame.UBlocks,frame.header->Unum)==frame.header->Unum) &&
+ (gzread(ifp,frame.VBlocks,frame.header->Vnum)==frame.header->Vnum) &&
+ (gzread(ifp,frame.YData,blockszy*frame.header->Ynum)==blockszy*frame.header->Ynum) &&
+ (gzread(ifp,frame.UData,(blockszuv*frame.header->Unum))==(blockszuv*frame.header->Unum)) &&
+ (gzread(ifp,frame.VData,(blockszuv*frame.header->Vnum))==(blockszuv*frame.header->Vnum))){
+ //load the blocks for each buffer
+ if(frame.header->Ynum)
+ for(j=0;j<frame.header->Ynum;j++)
+ LoadBlock( yuv->y,
+ &frame.YData[j*blockszy],
+ frame.YBlocks[j],
+ yuv->y_width,
+ yuv->y_height,
+ divisor);
+ if(frame.header->Unum)
+ for(j=0;j<frame.header->Unum;j++)
+ LoadBlock( yuv->u,
+ &frame.UData[j*blockszuv],
+ frame.UBlocks[j],
+ yuv->uv_width,
+ yuv->uv_height,
+ divisor/2);
+ if(frame.header->Vnum)
+ for(j=0;j<frame.header->Vnum;j++)
+ LoadBlock( yuv->v,
+ &frame.VData[j*blockszuv],
+ frame.VBlocks[j],
+ yuv->uv_width,
+ yuv->uv_height,
+ divisor/2);
+ //encode. This is not made in a thread since now blocking is not a problem
+ //and this way sync problems can be avoided more easily.
+ SyncEncodeImageBuffer((ProgData *)pdata);
+ }
+ else{
+ raise(SIGINT);
+ continue;
+ }
+ }
+ else{
+ raise(SIGINT);
+ continue;
+ }
+ }
+ //audio load and encoding
+ else{
+ if(!audio_end){
+ int nbytes=fread(sound_data,((ProgData *)pdata)->periodsize,1,afp);
+ if(nbytes<=0)
+ audio_end=1;
+ else
+ SyncEncodeSoundBuffer((ProgData *)pdata,sound_data);
+ }
+ }
+ }
+ fprintf(stdout,"\n");
+ CLEAR_FRAME(&frame)
+ free(sound_data);
+ gzclose(ifp);
+
+ 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/parseargs.c b/recordmydesktop/src/parseargs.c
index 5280cf2..c7d20fd 100644
--- a/recordmydesktop/src/parseargs.c
+++ b/recordmydesktop/src/parseargs.c
@@ -32,11 +32,11 @@ int ParseArgs(int argc,char **argv,ProgArgs *arg_return){
int i;
char *usage="\nUsage:\n"
"\trecordmydesktop [-h| --help| --version| -delay n[H|h|M|m]| -windowid id_of_window|\n"
- "\t-display DISPLAY| -x X| -y Y|-width N| -height N| -fps N(number>0)|\n"
+ "\t-display DISPLAY| -x X| -y Y|-width N| -height N| -fps N(number>0)| --on-the-fly-encoding|\n"
"\t -v_quality n| -s_quality n| -v_bitrate n| --no-framedrop| -dummy-cursor color|\n"
"\t --no-cursor| -freq N(number>0)| -channels N(number>0)| -device SOUND_DEVICE|\n"
- "\t --nosound| --with-shared| --no-cond-shared| -shared-threshold n| --full-shots|\n"
- "\t --quick-subsampling| --scshot| -scale-shot N| -o filename]^filename\n\n\n"
+ "\t --no-sound| --with-shared| --no-cond-shared| -shared-threshold n| --full-shots|\n"
+ "\t --quick-subsampling| -workdir DIR| --zero-compression| --no-wm-check| --overwite| -o filename]^filename\n\n\n"
"General Options:\n"
"\t-h or --help\t\tPrint this help and exit.\n"
@@ -51,7 +51,7 @@ int ParseArgs(int argc,char **argv,ProgArgs *arg_return){
"\t-height N\t\tHeight of recorded window.\n\n"
"\t-dummy-cursor color\tColor of the dummy cursor [black|white]\n"
- "\t--no-cursor\tDisable drawing of the cursor.\n"
+ "\t--no-cursor\t\tDisable drawing of the cursor.\n"
"\t--with-shared\t\tEnable usage of MIT-shared memory extension at all times.\n"
"\t--no-cond-shared\tDo not use the MIT-shared memory extension when aquiring large areas.\n"
"\t-shared-threshold n\tThreshold over which shared memory is used(default 75).\n"
@@ -63,18 +63,22 @@ int ParseArgs(int argc,char **argv,ProgArgs *arg_return){
"\t-channels N(number>0)\tA positive number denoting desired sound channels in recording.\n"
"\t-freq N(number>0)\tA positive number denoting desired sound frequency.\n"
"\t-device SOUND_DEVICE\tSound device(default hw0:0).\n"
- "\t--nosound\t\tDo not record sound.\n\n"
+ "\t--no-sound\t\tDo not record sound.\n\n"
"Encoding Options\n"
+ "\t--on-the-fly-encoding\tEncode the audio-video data, while recording.\n"
"\t-v_quality n\t\tA number from 0 to 63 for desired encoded video quality(default 63).\n"
"\t-v_bitrate n\t\tA number from 45000 to 2000000 for desired encoded video bitrate(default 45000).\n"
"\t--drop-frames\t\tAllow theora encoder to drop frames.\n"
"\t-s_quality n\t\tDesired audio quality(-1 to 10).\n\n"
"Misc Options:\n"
+ "\t--no-wm-check\tDo not try to detect the window manager(and set options according to it)\n"
+ "\t--zero-compression\tImage data are always cached uncompressed.\n"
+ "\t-workdir DIR\t\tLocation where a temporary directory will be created to hold project files(default $HOME).\n"
"\t-delay n[H|h|M|m]\tNumber of secs(default),minutes or hours before capture starts(number can be float)\n"
- "\t--scshot\t\tTake a bitmap screenshot(default rmdout.bmp) and exit.\n"
- "\t-scale-shot N\t\tFactor by which screenshot is scaled down(1<=number<=64,power of 2).\n"
+ "\t--overwrite\t\tIf there is already a file with the same name, delete it\n"
+ "\t\t\t\t(default is to add a number postfix to the new one).\n"
"\t-o filename\t\tName of recorded video(default out.ogg).\n"
"\n\tIf no other options are specified, filename can be given without the -o switch.\n\n\n";
@@ -279,7 +283,7 @@ int ParseArgs(int argc,char **argv,ProgArgs *arg_return){
return 1;
}
arg_return->have_dummy_cursor=1;
- arg_return->xfixes_cursor=0;
+ arg_return->xfixes_cursor=0;
}
else{
fprintf(stderr,"Argument Usage: -dummy-cursor [black|white]\n");
@@ -353,37 +357,31 @@ int ParseArgs(int argc,char **argv,ProgArgs *arg_return){
}
i++;
}
- else if(!strcmp(argv[i],"-scale-shot")){
+ else if(!strcmp(argv[i],"-device")){
if(i+1<argc){
- int num=atoi(argv[i+1]);
- if((num==1)||(num==2)||(num==4)||(num==8)
- ||(num==16)||(num==32)||(num==64)){
- arg_return->scale_shot=num;
- }
- else{
- fprintf(stderr,"Argument Usage: -scale-shot N(0<number<64,power of 2)\n");
- return 1;
- }
+ free(arg_return->device);
+ arg_return->device=malloc(strlen(argv[i+1])+1);
+ strcpy(arg_return->device,argv[i+1]);
}
else{
- fprintf(stderr,"Argument Usage: -scale-shot N(0<number<64,power of 2)\n");
+ fprintf(stderr,"Argument Usage: -device SOUND_DEVICE\n");
return 1;
}
i++;
}
- else if(!strcmp(argv[i],"-device")){
+ else if(!strcmp(argv[i],"-workdir")){
if(i+1<argc){
- free(arg_return->device);
- arg_return->device=malloc(strlen(argv[i+1])+1);
- strcpy(arg_return->device,argv[i+1]);
+ free(arg_return->workdir);
+ arg_return->workdir=malloc(strlen(argv[i+1])+1);
+ strcpy(arg_return->workdir,argv[i+1]);
}
else{
- fprintf(stderr,"Argument Usage: -device SOUND_DEVICE\n");
+ fprintf(stderr,"Argument Usage: -workdir DIR\n");
return 1;
}
i++;
}
- else if(!strcmp(argv[i],"--nosound"))
+ else if(!strcmp(argv[i],"--no-sound"))
arg_return->nosound=1;
else if(!strcmp(argv[i],"--drop-frames"))
arg_return->dropframes=1;
@@ -397,13 +395,19 @@ int ParseArgs(int argc,char **argv,ProgArgs *arg_return){
arg_return->full_shots=1;
arg_return->nocondshared=1;
}
- else if(!strcmp(argv[i],"--scshot")){
- arg_return->scshot=1;
- arg_return->nocondshared=1;
- }
else if(!strcmp(argv[i],"--quick-subsampling")){
arg_return->no_quick_subsample=0;
}
+ else if(!strcmp(argv[i],"--on-the-fly-encoding")){
+ arg_return->encOnTheFly=1;
+ }
+ else if(!strcmp(argv[i],"--overwrite"))
+ arg_return->overwrite=1;
+ else if(!strcmp(argv[i],"--no-wm-check"))
+ arg_return->nowmcheck=1;
+ else if(!strcmp(argv[i],"--zero-compression")){
+ arg_return->zerocompression=1;
+ }
else if(!strcmp(argv[i],"--help")||!strcmp(argv[i],"-h")){
fprintf(stderr,"%s",usage);
return 1;
@@ -415,7 +419,7 @@ int ParseArgs(int argc,char **argv,ProgArgs *arg_return){
else{
fprintf(stderr,"\n\tError parsing arguments.\n\tType --help or -h for usage.\n\n");
return 1;
- }
+ }
}
return 0;
}
diff --git a/recordmydesktop/src/poll_damage.c b/recordmydesktop/src/poll_damage.c
index 5433bbc..9bf7ee2 100644
--- a/recordmydesktop/src/poll_damage.c
+++ b/recordmydesktop/src/poll_damage.c
@@ -28,18 +28,48 @@
#include <recordmydesktop.h>
void *PollDamage(void *pdata){
-
- Damage damage;
+ Window root_return,
+ parent_return,
+ *children;
+ unsigned int i,
+ nchildren,
+ inserts=0;
XEvent event;
- int inserts=0;
-
-
- damage= XDamageCreate( ((ProgData *)pdata)->dpy, ((ProgData *)pdata)->brwin.windowid, XDamageReportRawRectangles);
+
+ XSelectInput (((ProgData *)pdata)->dpy,((ProgData *)pdata)->specs.root, SubstructureNotifyMask);
+
+ XQueryTree (((ProgData *)pdata)->dpy,
+ ((ProgData *)pdata)->specs.root,
+ &root_return,
+ &parent_return,
+ &children,
+ &nchildren);
+
+ for (i = 0; i < nchildren; i++){
+ XWindowAttributes attribs;
+ if (XGetWindowAttributes (((ProgData *)pdata)->dpy,children[i],&attribs)){
+ if (!attribs.override_redirect && attribs.depth==((ProgData *)pdata)->specs.depth)
+ XDamageCreate (((ProgData *)pdata)->dpy, children[i],XDamageReportRawRectangles);
+ }
+ }
+
+ XDamageCreate( ((ProgData *)pdata)->dpy, ((ProgData *)pdata)->brwin.windowid, XDamageReportRawRectangles);
+
+
while(((ProgData *)pdata)->running){
-// if(Paused)pthread_cond_wait(&((ProgData *)pdata)->pause_cond,&((ProgData *)pdata)->pause_cond_mutex);
//damage polling doesn't stop,eventually full image may be needed
+ //30/10/2006 : when and why did I write the above line? what did I mean?
XNextEvent(((ProgData *)pdata)->dpy,&event);
- if(event.type == ((ProgData *)pdata)->damage_event + XDamageNotify ){
+ if (event.type == MapNotify ){
+ XWindowAttributes attribs;
+ if (!((XMapEvent *)(&event))->override_redirect && XGetWindowAttributes (((ProgData *)pdata)->dpy,
+ event.xcreatewindow.window,
+ &attribs)){
+ if (!attribs.override_redirect && attribs.depth==((ProgData *)pdata)->specs.depth)
+ XDamageCreate (((ProgData *)pdata)->dpy,event.xcreatewindow.window,XDamageReportRawRectangles);
+ }
+ }
+ else if(event.type == ((ProgData *)pdata)->damage_event + XDamageNotify ){
XDamageNotifyEvent *e =(XDamageNotifyEvent *)( &event );
WGeometry wgeom;
CLIP_EVENT_AREA(e,&(((ProgData *)pdata)->brwin),&wgeom);
@@ -51,6 +81,7 @@ void *PollDamage(void *pdata){
pthread_mutex_unlock(&((ProgData *)pdata)->list_mutex[tlist_sel]);
}
}
+
}
pthread_exit(&errno);
}
diff --git a/recordmydesktop/src/recordmydesktop.c b/recordmydesktop/src/recordmydesktop.c
index 6b9e003..77c08ce 100644
--- a/recordmydesktop/src/recordmydesktop.c
+++ b/recordmydesktop/src/recordmydesktop.c
@@ -51,12 +51,16 @@ int main(int argc,char **argv){
}
else{
EncData enc_data;
+ CacheData cache_data;
pthread_t poll_damage_t,
image_capture_t,
image_encode_t,
+ image_cache_t,
sound_capture_t,
sound_encode_t,
- flush_to_ogg_t;
+ sound_cache_t,
+ flush_to_ogg_t,
+ load_cache_t;
XShmSegmentInfo shminfo;
int i;
@@ -67,47 +71,68 @@ int main(int argc,char **argv){
}
if(SetBRWindow(pdata.dpy,&pdata.brwin,&pdata.specs,&pdata.args))
exit(11);
-
+
+
+ //check if we are under compiz or beryl,in which case we must enable full-shots
+ //and with it use of shared memory.User can override this
+ pdata.window_manager=((pdata.args.nowmcheck)?NULL:rmdWMCheck(pdata.dpy,pdata.specs.root));
+ if(pdata.window_manager==NULL){
+ fprintf(stderr,"Not taking window manager into account.\n");
+ }
+ //Right now only wm's that I know of performing 3d compositing are beryl and compiz.
+ //No, the blue screen in metacity doesn't count :)
+ //names can be compiz for compiz and beryl/beryl-co/beryl-core for beryl(so it's strncmp )
+ else if(!strcmp(pdata.window_manager,"compiz") || !strncmp(pdata.window_manager,"beryl",5)){
+ fprintf(stderr,"\nDetected 3d compositing window manager.\n"
+ "Reverting to full screen capture at every frame.\n"
+ "To disable this check run with --no-wm-check\n"
+ "(though that is not advised, since it will probably produce faulty results).\n\n");
+ pdata.args.full_shots=1;
+ pdata.args.noshared=0;
+ pdata.args.nocondshared=1;
+ }
+
QueryExtensions(pdata.dpy,&pdata.args,&pdata.damage_event, &pdata.damage_error);
- //init data
+
+ //init data
+
//these are globals, look for them at the header
frames_total=frames_lost=encoder_busy=capture_busy=0;
- if(!pdata.args.scshot){
- fprintf(stderr,"Initializing...\n");
- MakeMatrices();
- if(pdata.args.have_dummy_cursor){
- pdata.dummy_pointer=MakeDummyPointer(&pdata.specs,16,pdata.args.cursor_color,0,&pdata.npxl);
- pdata.dummy_p_size=16;
- }
+ fprintf(stderr,"Initializing...\n");
+ MakeMatrices();
+ if(pdata.args.have_dummy_cursor){
+ pdata.dummy_pointer=MakeDummyPointer(&pdata.specs,16,pdata.args.cursor_color,0,&pdata.npxl);
+ pdata.dummy_p_size=16;
}
- if((pdata.args.noshared)||(pdata.args.scshot))
+
+ if((pdata.args.noshared))
pdata.datamain=(char *)malloc(pdata.brwin.nbytes);
- if(!pdata.args.scshot){
- if(pdata.args.noshared)
- pdata.datatemp=(char *)malloc(pdata.brwin.nbytes);
- pdata.rect_root[0]=pdata.rect_root[1]=NULL;
- pthread_mutex_init(&pdata.list_mutex[0],NULL);
- pthread_mutex_init(&pdata.list_mutex[1],NULL);
- pthread_mutex_init(&pdata.sound_buffer_mutex,NULL);
- pthread_mutex_init(&pdata.libogg_mutex,NULL);
- pthread_mutex_init(&pdata.yuv_mutex,NULL);
-
- pthread_cond_init(&pdata.time_cond,NULL);
- pthread_cond_init(&pdata.pause_cond,NULL);
- pthread_cond_init(&pdata.image_buffer_ready,NULL);
- pthread_cond_init(&pdata.sound_buffer_ready,NULL);
- pthread_cond_init(&pdata.sound_data_read,NULL);
- pdata.list_selector=Paused=Aborted=pdata.avd=0;
- pdata.running=1;
- time_cond=&pdata.time_cond;
- pause_cond=&pdata.pause_cond;
- Running=&pdata.running;
- }
- if((pdata.args.noshared)||(pdata.args.scshot)){
+
+ if(pdata.args.noshared)
+ pdata.datatemp=(char *)malloc(pdata.brwin.nbytes);
+ pdata.rect_root[0]=pdata.rect_root[1]=NULL;
+ pthread_mutex_init(&pdata.list_mutex[0],NULL);
+ pthread_mutex_init(&pdata.list_mutex[1],NULL);
+ pthread_mutex_init(&pdata.sound_buffer_mutex,NULL);
+ pthread_mutex_init(&pdata.libogg_mutex,NULL);
+ pthread_mutex_init(&pdata.yuv_mutex,NULL);
+
+ pthread_cond_init(&pdata.time_cond,NULL);
+ pthread_cond_init(&pdata.pause_cond,NULL);
+ pthread_cond_init(&pdata.image_buffer_ready,NULL);
+ pthread_cond_init(&pdata.sound_buffer_ready,NULL);
+ pthread_cond_init(&pdata.sound_data_read,NULL);
+ pdata.list_selector=Paused=Aborted=pdata.avd=0;
+ pdata.running=1;
+ time_cond=&pdata.time_cond;
+ pause_cond=&pdata.pause_cond;
+ Running=&pdata.running;
+
+ if((pdata.args.noshared)){
pdata.image=XCreateImage(pdata.dpy, pdata.specs.visual, pdata.specs.depth, ZPixmap, 0,pdata.datamain,pdata.brwin.rgeom.width,
pdata.brwin.rgeom.height, 8, 0);
XInitImage(pdata.image);
@@ -115,7 +140,7 @@ int main(int argc,char **argv){
pdata.brwin.rgeom.width,pdata.brwin.rgeom.height);
}
if((!pdata.args.noshared)||(!pdata.args.nocondshared)){
- pdata.shimage=XShmCreateImage (pdata.dpy,pdata.specs.visual,pdata.specs.depth,ZPixmap,pdata.datash,
+ pdata.shimage=XShmCreateImage (pdata.dpy,pdata.specs.visual,pdata.specs.depth,ZPixmap,pdata.datash,
&shminfo, pdata.brwin.rgeom.width,pdata.brwin.rgeom.height);
shminfo.shmid = shmget (IPC_PRIVATE,
pdata.shimage->bytes_per_line * pdata.shimage->height,
@@ -128,18 +153,6 @@ int main(int argc,char **argv){
}
XShmGetImage(pdata.dpy,pdata.specs.root,pdata.shimage,pdata.brwin.rgeom.x,pdata.brwin.rgeom.y,AllPlanes);
}
- if(pdata.args.scshot){
- if(pdata.args.delay>0){
- fprintf(stderr,"Will sleep for %d seconds now.\n",pdata.args.delay);
- sleep(pdata.args.delay);
- }
- //get a new screenshot
- GetZPixmap(pdata.dpy,pdata.specs.root,pdata.image->data,pdata.brwin.rgeom.x,pdata.brwin.rgeom.y,
- pdata.brwin.rgeom.width,pdata.brwin.rgeom.height);
- ZPixmapToBMP(pdata.image,&pdata.brwin,((!strcmp(pdata.args.filename,"out.ogg"))?"rmdout.bmp":pdata.args.filename),pdata.brwin.nbytes,pdata.args.scale_shot);
- fprintf(stderr,"done!\n");
- exit(0);
- }
if(!pdata.args.nosound){
pdata.sound_handle=OpenDev(pdata.args.device,&pdata.args.channels,&pdata.args.frequency,&pdata.periodsize, &pdata.periodtime,&pdata.hard_pause);
if(pdata.sound_handle==NULL){
@@ -147,12 +160,18 @@ int main(int argc,char **argv){
exit(3);
}
}
- InitEncoder(&pdata,&enc_data);
+
+ if(pdata.args.encOnTheFly)
+ InitEncoder(&pdata,&enc_data,0);
+ else
+ InitCacheData(&pdata,&enc_data,&cache_data);
+
for(i=0;i<(pdata.enc_data->yuv.y_width*pdata.enc_data->yuv.y_height);i++)
pdata.enc_data->yuv.y[i]=0;
for(i=0;i<(pdata.enc_data->yuv.uv_width*pdata.enc_data->yuv.uv_height);i++){
pdata.enc_data->yuv.v[i]=pdata.enc_data->yuv.u[i]=127;
}
+
if((pdata.args.nocondshared)&&(!pdata.args.noshared)){
if(pdata.args.no_quick_subsample){
UPDATE_YUV_BUFFER_IM_AVG((&pdata.enc_data->yuv),((unsigned char*)pdata.shimage->data),
@@ -189,50 +208,120 @@ int main(int argc,char **argv){
if(!pdata.args.full_shots)
pthread_create(&poll_damage_t,NULL,PollDamage,(void *)&pdata);
pthread_create(&image_capture_t,NULL,GetFrame,(void *)&pdata);
- pthread_create(&image_encode_t,NULL,EncodeImageBuffer,(void *)&pdata);
+ if(pdata.args.encOnTheFly)
+ pthread_create(&image_encode_t,NULL,EncodeImageBuffer,(void *)&pdata);
+ else
+ pthread_create(&image_cache_t,NULL,CacheImageBuffer,(void *)&pdata);
+
if(!pdata.args.nosound){
pthread_create(&sound_capture_t,NULL,CaptureSound,(void *)&pdata);
- pthread_create(&sound_encode_t,NULL,EncodeSoundBuffer,(void *)&pdata);
+ if(pdata.args.encOnTheFly)
+ pthread_create(&sound_encode_t,NULL,EncodeSoundBuffer,(void *)&pdata);
+ else
+ pthread_create(&sound_cache_t,NULL,CacheSoundBuffer,(void *)&pdata);
}
- pthread_create(&flush_to_ogg_t,NULL,FlushToOgg,(void *)&pdata);
-
+ if(pdata.args.encOnTheFly)
+ pthread_create(&flush_to_ogg_t,NULL,FlushToOgg,(void *)&pdata);
+
RegisterCallbacks(&pdata.args);
fprintf(stderr,"Capturing!\n");
//wait all threads to finish
-
+
pthread_join(image_capture_t,NULL);
fprintf(stderr,"Shutting down.");
- pthread_join(image_encode_t,NULL);
+ //if no damage events have been received the thread will get stuck
+ pthread_cond_broadcast(&pdata.image_buffer_ready);
+ if(pdata.args.encOnTheFly)
+ pthread_join(image_encode_t,NULL);
+ else
+ pthread_join(image_cache_t,NULL);
+
+
fprintf(stderr,".");
if(!pdata.args.nosound){
int *snd_exit;
- pthread_join(sound_capture_t,(&snd_exit));
+ pthread_join(sound_capture_t,(void *)(&snd_exit));
fprintf(stderr,".");
- if(!(*snd_exit))
- pthread_join(sound_encode_t,NULL);
+
+ if(pdata.args.encOnTheFly){
+ if(!(*snd_exit))
+ pthread_join(sound_encode_t,NULL);
+ else{
+ pthread_cancel(sound_encode_t);
+ exit_status=*snd_exit;
+ }
+ }
else{
- pthread_cancel(sound_encode_t);
- exit_status=*snd_exit;
+ if(!(*snd_exit))
+ pthread_join(sound_cache_t,NULL);
+ else{
+ pthread_cancel(sound_cache_t);
+ exit_status=*snd_exit;
+ }
}
- fprintf(stderr,".");
}
else
fprintf(stderr,"..");
- pthread_join(flush_to_ogg_t,NULL);
+
+ if(pdata.args.encOnTheFly)
+ pthread_join(flush_to_ogg_t,NULL);
fprintf(stderr,".");
+
if(!pdata.args.full_shots)
pthread_join(poll_damage_t,NULL);
+
+
fprintf(stderr,".");
if((!pdata.args.noshared)||(!pdata.args.nocondshared)){
XShmDetach (pdata.dpy, &shminfo);
-// XDestroyImage (pdata.image);
shmdt (&shminfo.shmaddr);
shmctl (shminfo.shmid, IPC_RMID, 0);
}
fprintf(stderr,"\n");
+
+
+ //Now that we are done with recording we cancel the timer
+ CancelTimer();
+
+/** Encoding */
+ if(!pdata.args.encOnTheFly){
+ if(!Aborted){
+ fprintf(stderr,"Encoding started!\nThis may take several minutes.\n"
+ "Pressing Ctrl-C will cancel the procedure (resuming will not be possible, but\n"
+ "any portion of the video, which is already encoded won't be deleted).\n"
+ "Please wait...\n");
+ pdata.running=1;
+ InitEncoder(&pdata,&enc_data,1);
+ //load encoding and flushing threads
+ if(!pdata.args.nosound){
+ //before we start loading again
+ //we need to free any left-overs
+ while(pdata.sound_buffer!=NULL){
+ free(pdata.sound_buffer->data);
+ pdata.sound_buffer=pdata.sound_buffer->next;
+ }
+ }
+ pthread_create(&flush_to_ogg_t,NULL,FlushToOgg,(void *)&pdata);
+
+
+ //start loading image and audio
+ pthread_create(&load_cache_t,NULL,LoadCache,(void *)&pdata);
+
+ //join and finish
+ pthread_join(load_cache_t,NULL);
+ fprintf(stderr,"Encoding finished!\nWait a moment please...\n");
+ pthread_join(flush_to_ogg_t,NULL);
+ fprintf(stderr,"Done!!!\n");
+ }
+ }
+/**@_______________________________________________@*/
+
+ //This can happen earlier, but in some cases it might get stuck.
+ //So we must make sure the recording is not wasted.
XCloseDisplay(pdata.dpy);
+
if(Aborted){
if(remove(pdata.args.filename)){
perror("Error while removing file:\n");
diff --git a/recordmydesktop/src/register_callbacks.c b/recordmydesktop/src/register_callbacks.c
index 677fc75..08c528f 100644
--- a/recordmydesktop/src/register_callbacks.c
+++ b/recordmydesktop/src/register_callbacks.c
@@ -56,6 +56,16 @@ void SetRunning(int signum){
Aborted=1;
}
+void CancelTimer(void){
+ struct itimerval value;
+ value.it_interval.tv_sec=
+ value.it_value.tv_sec=
+ value.it_interval.tv_usec=
+ value.it_value.tv_usec=0;
+
+ setitimer(ITIMER_REAL,&value,NULL);
+}
+
void RegisterCallbacks(ProgArgs *args){
struct itimerval value;
diff --git a/recordmydesktop/src/rmd_cache.c b/recordmydesktop/src/rmd_cache.c
new file mode 100644
index 0000000..9cb76d5
--- /dev/null
+++ b/recordmydesktop/src/rmd_cache.c
@@ -0,0 +1,102 @@
+/*********************************************************************************
+* recordMyDesktop *
+**********************************************************************************
+* *
+* Copyright (C) 2006 John Varouhakis *
+* *
+* *
+* This program is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+* *
+* This program is distributed in the hope that it will be useful, *
+* but WITHOUT ANY WARRANTY; without even the implied warranty of *
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+* GNU General Public License for more details. *
+* *
+* You should have received a copy of the GNU General Public License *
+* along with this program; if not, write to the Free Software *
+* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
+* *
+* *
+* *
+* For further information contact me at johnvarouhakis@gmail.com *
+**********************************************************************************/
+
+#include <recordmydesktop.h>
+
+void InitCacheData(ProgData *pdata,EncData *enc_data_t,CacheData *cache_data_t){
+ int width,height,offset_x,offset_y,pid;
+ char pidbuf[8];
+
+ //we set the buffer only since there's
+ //no need to initialize the encoder from now.
+ width=((pdata->brwin.rgeom.width + 15) >>4)<<4;
+ height=((pdata->brwin.rgeom.height + 15) >>4)<<4;
+ offset_x=((width-pdata->brwin.rgeom.width)/2)&~1;
+ offset_y=((height-pdata->brwin.rgeom.height)/2)&~1;
+
+ (pdata)->enc_data=enc_data_t;
+
+ enc_data_t->yuv.y=(unsigned char *)malloc(height*width);
+ enc_data_t->yuv.u=(unsigned char *)malloc(height*width/4);
+ enc_data_t->yuv.v=(unsigned char *)malloc(height*width/4);
+ enc_data_t->yuv.y_width=width;
+ enc_data_t->yuv.y_height=height;
+ enc_data_t->yuv.y_stride=width;
+
+ enc_data_t->yuv.uv_width=width/2;
+ enc_data_t->yuv.uv_height=height/2;
+ enc_data_t->yuv.uv_stride=width/2;
+ enc_data_t->x_offset=offset_x;
+ enc_data_t->y_offset=offset_y;
+
+
+ //now we set the cache files
+ (pdata)->cache_data=cache_data_t;
+
+ cache_data_t->workdir=(pdata->args).workdir;
+ pid=getpid();
+
+ I16TOA(pid,pidbuf)
+ //names are stored relatively to current dir(i.e. no chdir)
+ cache_data_t->projname=malloc(strlen(cache_data_t->workdir)+12+strlen(pidbuf)+3);
+ //projname
+ strcpy(cache_data_t->projname,cache_data_t->workdir);
+ strcat(cache_data_t->projname,"/");
+ strcat(cache_data_t->projname,"rMD-session-");
+ strcat(cache_data_t->projname,pidbuf);
+ strcat(cache_data_t->projname,"/");
+ //image data
+ cache_data_t->imgdata=malloc(strlen(cache_data_t->projname)+11);
+ strcpy(cache_data_t->imgdata,cache_data_t->projname);
+ strcat(cache_data_t->imgdata,"img.out.gz");
+ //audio data
+ cache_data_t->audiodata=malloc(strlen(cache_data_t->projname)+10);
+ strcpy(cache_data_t->audiodata,cache_data_t->projname);
+ strcat(cache_data_t->audiodata,"audio.pcm");
+
+ //now that've got out buffers and our filenames we start
+ //creating the needed files
+
+ if(mkdir(cache_data_t->projname,0777)){
+ fprintf(stderr,"Could not create temporary directory %s !!!\n",cache_data_t->projname);
+ exit(13);
+ }
+ cache_data_t->ifp=gzopen(cache_data_t->imgdata,"wb0f");
+ if(cache_data_t->ifp==NULL){
+ fprintf(stderr,"Could not create temporary file %s !!!\n",cache_data_t->imgdata);
+ exit(13);
+ }
+ if(!pdata->args.nosound){
+ cache_data_t->afp=fopen(cache_data_t->audiodata,"wb");
+ if(cache_data_t->afp==NULL){
+ fprintf(stderr,"Could not create temporary file %s !!!\n",cache_data_t->audiodata);
+ exit(13);
+ }
+ }
+
+}
+
+
diff --git a/recordmydesktop/src/wm_check.c b/recordmydesktop/src/wm_check.c
new file mode 100644
index 0000000..ee6b0ba
--- /dev/null
+++ b/recordmydesktop/src/wm_check.c
@@ -0,0 +1,68 @@
+/*********************************************************************************
+* recordMyDesktop *
+**********************************************************************************
+* *
+* Copyright (C) 2006 John Varouhakis *
+* *
+* *
+* This program is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+* *
+* This program is distributed in the hope that it will be useful, *
+* but WITHOUT ANY WARRANTY; without even the implied warranty of *
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+* GNU General Public License for more details. *
+* *
+* You should have received a copy of the GNU General Public License *
+* along with this program; if not, write to the Free Software *
+* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
+* *
+* *
+* *
+* For further information contact me at johnvarouhakis@gmail.com *
+**********************************************************************************/
+
+
+#include <recordmydesktop.h>
+
+char *rmdWMCheck(Display *dpy,Window root){
+
+ Window *wm_child;
+ Atom nwm_atom,
+ utf8_string,
+ wm_name_atom,
+ rt;
+ unsigned long nbytes,
+ nitems;
+
+ char *wm_name_str=NULL;
+ int fmt;
+
+ utf8_string = XInternAtom(dpy, "UTF8_STRING", False);
+
+ nwm_atom =XInternAtom(dpy,"_NET_SUPPORTING_WM_CHECK",True);
+ wm_name_atom =XInternAtom(dpy,"_NET_WM_NAME",True);
+
+ if(nwm_atom!=None && wm_name_atom!=None){
+ if(!((XGetWindowProperty( dpy,root,nwm_atom,0,100,
+ False,XA_WINDOW,
+ &rt,&fmt,&nitems, &nbytes,
+ (unsigned char **)((void*)&wm_child))
+ ==Success ) &&
+ (XGetWindowProperty( dpy,*wm_child,wm_name_atom,0,100,
+ False,utf8_string,&rt,
+ &fmt,&nitems, &nbytes,
+ (unsigned char **)((void*)&wm_name_str))
+ ==Success ))){
+ fprintf(stderr,"Warning!!!\nYour window manager appears to be non-compliant!\n");
+ }
+ }
+ fprintf(stderr,"Your window manager appears to be %s\n\n",
+ ((wm_name_str!=NULL)?wm_name_str:"Uknown"));
+
+
+ return wm_name_str;
+}
+
© All Rights Reserved