summaryrefslogtreecommitdiff
path: root/rMD-exp/src
diff options
context:
space:
mode:
authoriovar <iovar@f606c939-3180-4ac9-a4b8-4b8779d57d0a>2006-10-06 14:14:57 +0000
committeriovar <iovar@f606c939-3180-4ac9-a4b8-4b8779d57d0a>2006-10-06 14:14:57 +0000
commitf9563ee14b530fa38701b00d551891a6bdcd0352 (patch)
tree910062fa0beff896335d0bd8040713a3c5e140a5 /rMD-exp/src
parent59a690e87883e1da1256cbf72085b6830a2e99ff (diff)
This commit was generated by cvs2svn to compensate for changes in r85,
which included commits to RCS files with non-trunk default branches. git-svn-id: https://recordmydesktop.svn.sourceforge.net/svnroot/recordmydesktop/trunk@86 f606c939-3180-4ac9-a4b8-4b8779d57d0a
Diffstat (limited to 'rMD-exp/src')
-rw-r--r--rMD-exp/src/Makefile.am28
-rw-r--r--rMD-exp/src/bgr_to_yuv.c54
-rw-r--r--rMD-exp/src/capture_sound.c107
-rw-r--r--rMD-exp/src/encode_image_buffer.c65
-rw-r--r--rMD-exp/src/encode_sound_buffer.c93
-rw-r--r--rMD-exp/src/flush_to_ogg.c81
-rw-r--r--rMD-exp/src/get_frame.c209
-rw-r--r--rMD-exp/src/getzpixmap.c55
-rw-r--r--rMD-exp/src/init_encoder.c172
-rw-r--r--rMD-exp/src/make_dummy_pointer.c76
-rw-r--r--rMD-exp/src/opendev.c103
-rw-r--r--rMD-exp/src/parseargs.c421
-rw-r--r--rMD-exp/src/poll_damage.c57
-rw-r--r--rMD-exp/src/queryextensions.c48
-rw-r--r--rMD-exp/src/recordmydesktop.c259
-rw-r--r--rMD-exp/src/rectinsert.c499
-rw-r--r--rMD-exp/src/register_callbacks.c81
-rw-r--r--rMD-exp/src/setbrwindow.c176
-rw-r--r--rMD-exp/src/update_image.c86
-rw-r--r--rMD-exp/src/zpixmaptobmp.c78
20 files changed, 2748 insertions, 0 deletions
diff --git a/rMD-exp/src/Makefile.am b/rMD-exp/src/Makefile.am
new file mode 100644
index 0000000..e56b856
--- /dev/null
+++ b/rMD-exp/src/Makefile.am
@@ -0,0 +1,28 @@
+bin_PROGRAMS = recordmydesktop
+
+
+
+recordmydesktop_SOURCES= recordmydesktop.c\
+ zpixmaptobmp.c\
+ getzpixmap.c\
+ parseargs.c\
+ rectinsert.c\
+ setbrwindow.c\
+ queryextensions.c\
+ register_callbacks.c\
+ get_frame.c\
+ update_image.c\
+ poll_damage.c\
+ encode_image_buffer.c\
+ bgr_to_yuv.c\
+ flush_to_ogg.c\
+ make_dummy_pointer.c\
+ opendev.c\
+ capture_sound.c\
+ encode_sound_buffer.c\
+ init_encoder.c
+
+INCLUDES= $(all_includes) -I../include -I$x_includes
+
+recordmydesktop_LDFLAGS = -D_THREAD_SAFE -pthread -Wall
+
diff --git a/rMD-exp/src/bgr_to_yuv.c b/rMD-exp/src/bgr_to_yuv.c
new file mode 100644
index 0000000..0f775e2
--- /dev/null
+++ b/rMD-exp/src/bgr_to_yuv.c
@@ -0,0 +1,54 @@
+/*********************************************************************************
+* 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 MakeMatrices(){
+ int i;
+
+ for(i=0;i<256;i++)
+ Yr[i]=(2104.0*i)/8192.0+8.0;
+ for(i=0;i<256;i++)
+ Yg[i]=(4130.0*i)/8192.0+8.0;
+ for(i=0;i<256;i++)
+ Yb[i]=(802.0*i)/8192.0;
+
+ for(i=0;i<256;i++)
+ Ur[i]=37.8-(1204.0*i)/8192.0+8.0;
+ for(i=0;i<256;i++)
+ Ug[i]=74.2-(2384.0*i)/8192.0+8.0;
+ for(i=0;i<256;i++)
+ Ub[i]=(3598.0*i)/8192.0 ;
+
+ for(i=0;i<256;i++)
+ Vr[i]=(3598.0*i)/8192.0;
+ for(i=0;i<256;i++)
+ Vg[i]=93.8-(3013.0*i)/8192.0+8.0;
+ for(i=0;i<256;i++)
+ Vb[i]=18.2-(585.0*i)/8192.0+8.0;
+}
+
diff --git a/rMD-exp/src/capture_sound.c b/rMD-exp/src/capture_sound.c
new file mode 100644
index 0000000..f28ba26
--- /dev/null
+++ b/rMD-exp/src/capture_sound.c
@@ -0,0 +1,107 @@
+/*********************************************************************************
+* 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 *CaptureSound(void *pdata){
+
+ int frames=((ProgData *)pdata)->periodsize>>((ProgData *)pdata)->args.channels;
+// fprintf(stderr,"fr %d ps %d\n",frames,((ProgData *)pdata)->periodsize);fflush(stderr);
+ pthread_mutex_t pmut;
+ pthread_mutex_init(&pmut,NULL);
+ ((ProgData *)pdata)->sound_buffer=NULL;
+
+ while(((ProgData *)pdata)->running){
+ int sret=0;
+ SndBuffer *newbuf,*tmp;
+ if(Paused){
+ if(!((ProgData *)pdata)->hard_pause){
+ snd_pcm_pause(((ProgData *)pdata)->sound_handle,1);
+ pthread_cond_wait(&((ProgData *)pdata)->pause_cond,&pmut);
+ snd_pcm_pause(((ProgData *)pdata)->sound_handle,0);
+ }
+ else{//device doesn't support pause(is this the norm?mine doesn't)
+ snd_pcm_close(((ProgData *)pdata)->sound_handle);
+ pthread_cond_wait(&((ProgData *)pdata)->pause_cond,&pmut);
+
+ ((ProgData *)pdata)->sound_handle=
+ OpenDev(((ProgData *)pdata)->args.device,
+ &((ProgData *)pdata)->args.channels,
+ &((ProgData *)pdata)->args.frequency,
+ NULL,
+ NULL,
+ NULL//let's hope that the device capabilities didn't magically change
+ );
+ if(((ProgData *)pdata)->sound_handle==NULL){
+ fprintf(stderr,"Couldn't reopen sound device.\nThere will be no sound data from this point on.\n");
+ pthread_exit(&errno);
+ }
+ }
+ }
+
+ //create new buffer
+ newbuf=(SndBuffer *)malloc(sizeof(SndBuffer *));
+ newbuf->data=(signed char *)malloc(((ProgData *)pdata)->periodsize);
+ newbuf->next=NULL;
+
+ //read data into new buffer
+ while(sret<frames){
+ int temp_sret=snd_pcm_readi(((ProgData *)pdata)->sound_handle,
+ newbuf->data+2*((ProgData *)pdata)->args.channels*sret,
+ frames-sret);
+ if(temp_sret==-EPIPE)
+ snd_pcm_prepare(((ProgData *)pdata)->sound_handle);
+ else if (temp_sret<0){
+ fprintf(stderr,"An error occured while reading sound data:\n %s\n",snd_strerror(temp_sret));
+ snd_pcm_prepare(((ProgData *)pdata)->sound_handle);
+ }
+ else
+ sret+=temp_sret;
+ }
+
+ //queue the new buffer
+ pthread_mutex_lock(&((ProgData *)pdata)->sound_buffer_mutex);
+ tmp=((ProgData *)pdata)->sound_buffer;
+ if(((ProgData *)pdata)->sound_buffer==NULL)
+ ((ProgData *)pdata)->sound_buffer=newbuf;
+ else{
+ while(tmp->next!=NULL)
+ tmp=tmp->next;
+ tmp->next=newbuf;
+ }
+ pthread_mutex_unlock(&((ProgData *)pdata)->sound_buffer_mutex);
+
+
+ //signal that there are data to be proccessed
+ pthread_cond_signal(&((ProgData *)pdata)->sound_data_read);
+ }
+ snd_pcm_close(((ProgData *)pdata)->sound_handle);
+ pthread_exit(&errno);
+}
+
+
+
diff --git a/rMD-exp/src/encode_image_buffer.c b/rMD-exp/src/encode_image_buffer.c
new file mode 100644
index 0000000..38a1d77
--- /dev/null
+++ b/rMD-exp/src/encode_image_buffer.c
@@ -0,0 +1,65 @@
+/*********************************************************************************
+* 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 *EncodeImageBuffer(void *pdata){
+ pthread_mutex_t pmut,imut;
+ 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);
+ if(Paused)
+ pthread_cond_wait(&((ProgData *)pdata)->pause_cond,&pmut);//this may not be needed
+ pthread_mutex_lock(&((ProgData *)pdata)->yuv_mutex);
+ if(theora_encode_YUVin(&((ProgData *)pdata)->enc_data->m_th_st,&((ProgData *)pdata)->enc_data->yuv)){
+ fprintf(stderr,"Encoder not ready!\n");
+ pthread_mutex_unlock(&((ProgData *)pdata)->yuv_mutex);
+ }
+ else{
+ pthread_mutex_unlock(&((ProgData *)pdata)->yuv_mutex);
+ if(theora_encode_packetout(&((ProgData *)pdata)->enc_data->m_th_st,0,&((ProgData *)pdata)->enc_data->m_ogg_pckt1)==1){
+ pthread_mutex_lock(&((ProgData *)pdata)->libogg_mutex);
+ ogg_stream_packetin(&((ProgData *)pdata)->enc_data->m_ogg_ts,&((ProgData *)pdata)->enc_data->m_ogg_pckt1);
+ pthread_mutex_unlock(&((ProgData *)pdata)->libogg_mutex);
+ ((ProgData *)pdata)->avd+=((ProgData *)pdata)->frametime*2*((ProgData *)pdata)->args.channels;
+ }
+ }
+ encoder_busy=0;
+ }
+ //last packet
+ if(theora_encode_YUVin(&((ProgData *)pdata)->enc_data->m_th_st,&((ProgData *)pdata)->enc_data->yuv)){
+ fprintf(stderr,"Encoder not ready!\n");
+ }
+
+ theora_encode_packetout(&((ProgData *)pdata)->enc_data->m_th_st,1,&((ProgData *)pdata)->enc_data->m_ogg_pckt1);
+
+// ogg_stream_packetin(&((ProgData *)pdata)->enc_data->m_ogg_ts,&((ProgData *)pdata)->enc_data->m_ogg_pckt);
+
+ pthread_exit(&errno);
+}
+
+
diff --git a/rMD-exp/src/encode_sound_buffer.c b/rMD-exp/src/encode_sound_buffer.c
new file mode 100644
index 0000000..85e277d
--- /dev/null
+++ b/rMD-exp/src/encode_sound_buffer.c
@@ -0,0 +1,93 @@
+/*********************************************************************************
+* 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 *EncodeSoundBuffer(void *pdata){
+
+ int sampread=((ProgData *)pdata)->periodsize/(2*((ProgData *)pdata)->args.channels);
+ pthread_mutex_t smut;
+ pthread_mutex_init(&smut,NULL);
+ while((((ProgData *)pdata)->running)){
+ float **vorbis_buffer;
+ int count=0,i,j;
+ SndBuffer *buff;
+
+ if(Paused){
+ pthread_mutex_t tmut;
+ pthread_mutex_init(&tmut,NULL);
+ pthread_cond_wait(&((ProgData *)pdata)->pause_cond,&tmut);
+ }
+
+ 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);
+
+ vorbis_buffer=vorbis_analysis_buffer(&((ProgData *)pdata)->enc_data->m_vo_dsp,sampread);
+ for(i=0;i<sampread;i++){
+ for(j=0;j<((ProgData *)pdata)->args.channels;j++){
+ vorbis_buffer[j][i]=((buff->data[count+1]<<8)|
+ (0x00ff&(int)buff->data[count]))/32768.f;
+ count+=2;
+ }
+ }
+ vorbis_analysis_wrote(&((ProgData *)pdata)->enc_data->m_vo_dsp,sampread);
+
+ while(vorbis_analysis_blockout(&((ProgData *)pdata)->enc_data->m_vo_dsp,&((ProgData *)pdata)->enc_data->m_vo_block)==1){
+
+ vorbis_analysis(&((ProgData *)pdata)->enc_data->m_vo_block,NULL);
+ vorbis_bitrate_addblock(&((ProgData *)pdata)->enc_data->m_vo_block);
+
+ while(vorbis_bitrate_flushpacket(&((ProgData *)pdata)->enc_data->m_vo_dsp,&((ProgData *)pdata)->enc_data->m_ogg_pckt2)){
+ pthread_mutex_lock(&((ProgData *)pdata)->libogg_mutex);
+ ogg_stream_packetin(&((ProgData *)pdata)->enc_data->m_ogg_vs,&((ProgData *)pdata)->enc_data->m_ogg_pckt2);
+ pthread_mutex_unlock(&((ProgData *)pdata)->libogg_mutex);
+ }
+ }
+ ((ProgData *)pdata)->avd-=((ProgData *)pdata)->periodtime;
+
+ free(buff->data);
+ free(buff);
+ }
+
+ vorbis_analysis_wrote(&((ProgData *)pdata)->enc_data->m_vo_dsp,0);
+// while(vorbis_analysis_blockout(&((ProgData *)pdata)->enc_data->m_vo_dsp,&((ProgData *)pdata)->enc_data->m_vo_block)==1){
+// vorbis_analysis(&((ProgData *)pdata)->enc_data->m_vo_block,NULL);
+// vorbis_bitrate_addblock(&((ProgData *)pdata)->enc_data->m_vo_block);
+// while(vorbis_bitrate_flushpacket(&((ProgData *)pdata)->enc_data->m_vo_dsp,&((ProgData *)pdata)->enc_data->m_ogg_pckt2))
+// ogg_stream_packetin(&((ProgData *)pdata)->enc_data->m_ogg_vs,&((ProgData *)pdata)->enc_data->m_ogg_pckt2);
+// }
+
+ pthread_exit(&errno);
+}
+
+
diff --git a/rMD-exp/src/flush_to_ogg.c b/rMD-exp/src/flush_to_ogg.c
new file mode 100644
index 0000000..fed07c5
--- /dev/null
+++ b/rMD-exp/src/flush_to_ogg.c
@@ -0,0 +1,81 @@
+/*********************************************************************************
+* 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 *FlushToOgg(void *pdata){
+ int videoflag=0,audioflag=0;
+ double video_bytesout=0,audio_bytesout=0;
+ ogg_page videopage,audiopage;
+ while(((ProgData *)pdata)->running){
+ pthread_mutex_lock(&((ProgData *)pdata)->libogg_mutex);
+ videoflag=ogg_stream_pageout(&((ProgData *)pdata)->enc_data->m_ogg_ts,&videopage);
+ pthread_mutex_unlock(&((ProgData *)pdata)->libogg_mutex);
+ if(videoflag){
+ video_bytesout+=fwrite(videopage.header,1,videopage.header_len,((ProgData *)pdata)->enc_data->fp);
+ video_bytesout+=fwrite(videopage.body,1,videopage.body_len,((ProgData *)pdata)->enc_data->fp);
+ videoflag=0;
+ if(!((ProgData *)pdata)->args.nosound){
+ pthread_mutex_lock(&((ProgData *)pdata)->libogg_mutex);
+ audioflag=ogg_stream_pageout(&((ProgData *)pdata)->enc_data->m_ogg_vs,&audiopage);
+ pthread_mutex_unlock(&((ProgData *)pdata)->libogg_mutex);
+ if(audioflag){
+ audio_bytesout+=fwrite(audiopage.header,1,audiopage.header_len,((ProgData *)pdata)->enc_data->fp);
+ audio_bytesout+=fwrite(audiopage.body,1,audiopage.body_len,((ProgData *)pdata)->enc_data->fp);
+ audioflag=0;
+ }
+ }
+ }
+ else
+ usleep(10000);
+
+ }
+ //last packages
+ videoflag=ogg_stream_flush(&((ProgData *)pdata)->enc_data->m_ogg_ts,&videopage);
+ if(videoflag){
+ video_bytesout+=fwrite(videopage.header,1,videopage.header_len,((ProgData *)pdata)->enc_data->fp);
+ video_bytesout+=fwrite(videopage.body,1,videopage.body_len,((ProgData *)pdata)->enc_data->fp);
+ videoflag=0;
+ }
+ if(!((ProgData *)pdata)->args.nosound)
+ audioflag=ogg_stream_flush(&((ProgData *)pdata)->enc_data->m_ogg_vs,&audiopage);
+ if(audioflag){
+ audio_bytesout+=fwrite(audiopage.header,1,audiopage.header_len,((ProgData *)pdata)->enc_data->fp);
+ audio_bytesout+=fwrite(audiopage.body,1,audiopage.body_len,((ProgData *)pdata)->enc_data->fp);
+ audioflag=0;
+ }
+
+ ogg_stream_clear(&((ProgData *)pdata)->enc_data->m_ogg_ts);
+ if(!((ProgData *)pdata)->args.nosound)
+ ogg_stream_clear(&((ProgData *)pdata)->enc_data->m_ogg_vs);
+//this always gives me a segfault :(
+// theora_clear(&((ProgData *)pdata)->enc_data->m_th_st);
+
+ if(((ProgData *)pdata)->enc_data->fp)fclose(((ProgData *)pdata)->enc_data->fp);
+
+ fprintf(stderr,"\r \nDone.\nWritten %.0f bytes\n(%.0f of which were video data and %.0f audio data)\n\n",video_bytesout+audio_bytesout,video_bytesout,audio_bytesout);
+ pthread_exit(&errno);
+}
diff --git a/rMD-exp/src/get_frame.c b/rMD-exp/src/get_frame.c
new file mode 100644
index 0000000..b1da1fe
--- /dev/null
+++ b/rMD-exp/src/get_frame.c
@@ -0,0 +1,209 @@
+/*********************************************************************************
+* 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 *GetFrame(void *pdata){
+ int tlist_sel=0;
+ pthread_mutex_t pmut,tmut;
+ uint msk_ret;
+ WGeometry mouse_pos_abs,mouse_pos_rel,mouse_pos_temp;
+ Window root_ret,child_ret;
+ int pixel_total=((ProgData *)pdata)->brwin.rgeom.width*((ProgData *)pdata)->brwin.rgeom.height;
+ XFixesCursorImage *xcim=NULL;
+
+ mouse_pos_abs.x=mouse_pos_temp.x=0;
+ mouse_pos_abs.y=mouse_pos_temp.y=0;
+ mouse_pos_abs.width=mouse_pos_temp.width=((ProgData *)pdata)->dummy_p_size;
+ mouse_pos_abs.height=mouse_pos_temp.height=((ProgData *)pdata)->dummy_p_size;
+ pthread_mutex_init(&pmut,NULL);
+ pthread_mutex_init(&tmut,NULL);
+
+ while(((ProgData *)pdata)->running){
+
+ //if we are left behind we must not wait.
+ //also before actually pausing we must make sure the streams
+ //are synced. sound stops so this should only happen quickly.
+ if(((ProgData *)pdata)->avd>0){
+ pthread_cond_wait(&((ProgData *)pdata)->time_cond,&tmut);
+ if(Paused){
+ pthread_cond_wait(&((ProgData *)pdata)->pause_cond,&pmut);
+ }
+ }
+ capture_busy=1;
+
+ /*pthread_cond_wait(&((ProgData *)pdata)->pause_cond,&((ProgData *)pdata)->pause_cond_mutex);*/
+ //mutexes and lists with changes are useless when full_shots is enabled
+ if(!((ProgData *)pdata)->args.full_shots){
+ tlist_sel=((ProgData *)pdata)->list_selector;
+ ((ProgData *)pdata)->list_selector=((((ProgData *)pdata)->list_selector+1)%2);
+ pthread_mutex_lock(&((ProgData *)pdata)->list_mutex[tlist_sel]);
+ }
+ //here we measure the list and decide which way we will go
+ if(!((ProgData *)pdata)->args.nocondshared){
+ int level=0;
+ RectArea *temp=((ProgData *)pdata)->rect_root[tlist_sel];
+
+ if(temp!=NULL){
+ do{
+ level+=temp->geom.width*temp->geom.height;
+ temp=temp->next;
+ }while(temp!=NULL);
+ level*=100;
+ level/=pixel_total;
+ ((ProgData *)pdata)->args.noshared=(level<((ProgData *)pdata)->args.shared_thres);
+// if(!((ProgData *)pdata)->args.noshared){
+// fprintf(stderr,"shared screenshot with %d\n",level);
+// }
+ }
+ }
+ if(((ProgData *)pdata)->args.xfixes_cursor){
+ //xfixes pointer sequence
+ //update previous_position
+ //(if full_shots is enabled this is skipped since it's pointless)
+ if(!((ProgData *)pdata)->args.full_shots){
+ CLIP_DUMMY_POINTER_AREA(mouse_pos_abs,&((ProgData *)pdata)->brwin,&mouse_pos_temp);
+ if((mouse_pos_temp.x>=0)&&(mouse_pos_temp.y>=0)&&(mouse_pos_temp.width>0)&&(mouse_pos_temp.height>0))
+ RectInsert(&((ProgData *)pdata)->rect_root[tlist_sel],&mouse_pos_temp);
+ }
+ xcim=XFixesGetCursorImage(((ProgData *)pdata)->dpy);
+ mouse_pos_abs.x=xcim->x;
+ mouse_pos_abs.y=xcim->y;
+ mouse_pos_abs.width=xcim->width;
+ mouse_pos_abs.height=xcim->height;
+ }
+ if(((ProgData *)pdata)->args.have_dummy_cursor){
+ //dummy pointer sequence
+ //update previous_position
+ //(if full_shots is enabled this is skipped since it's pointless)
+ if(!((ProgData *)pdata)->args.full_shots){
+ CLIP_DUMMY_POINTER_AREA(mouse_pos_abs,&((ProgData *)pdata)->brwin,&mouse_pos_temp);
+ if((mouse_pos_temp.x>=0)&&(mouse_pos_temp.y>=0)&&(mouse_pos_temp.width>0)&&(mouse_pos_temp.height>0))
+ RectInsert(&((ProgData *)pdata)->rect_root[tlist_sel],&mouse_pos_temp);
+ }
+ //find new one
+ XQueryPointer(((ProgData *)pdata)->dpy,
+ ((ProgData *)pdata)->specs.root,
+ &root_ret,&child_ret,
+ &mouse_pos_abs.x,&mouse_pos_abs.y,
+ &mouse_pos_rel.x,&mouse_pos_rel.y,&msk_ret);
+ }
+ if(!((ProgData *)pdata)->args.noshared)
+ XShmGetImage(((ProgData *)pdata)->dpy,((ProgData *)pdata)->specs.root,((ProgData *)pdata)->shimage,(((ProgData *)pdata)->brwin.rgeom.x),(((ProgData *)pdata)->brwin.rgeom.y),AllPlanes);
+ if(!((ProgData *)pdata)->args.full_shots)
+ UpdateImage(((ProgData *)pdata)->dpy,
+ &((ProgData *)pdata)->enc_data->yuv,
+ &((ProgData *)pdata)->yuv_mutex,
+ &((ProgData *)pdata)->specs,
+ &((ProgData *)pdata)->rect_root[tlist_sel],
+ &((ProgData *)pdata)->brwin,
+ ((ProgData *)pdata)->enc_data,
+ ((((ProgData *)pdata)->args.noshared)?(((ProgData *)pdata)->datatemp):((ProgData *)pdata)->shimage->data),
+ ((ProgData *)pdata)->args.noshared,
+ ((ProgData *)pdata)->args.no_quick_subsample);
+ else{
+ if(((ProgData *)pdata)->args.noshared){
+ GetZPixmap( ((ProgData *)pdata)->dpy,
+ ((ProgData *)pdata)->specs.root,
+ ((ProgData *)pdata)->image->data,
+ ((ProgData *)pdata)->brwin.rgeom.x,
+ ((ProgData *)pdata)->brwin.rgeom.y,
+ ((ProgData *)pdata)->brwin.rgeom.width,
+ ((ProgData *)pdata)->brwin.rgeom.height);
+ pthread_mutex_lock(&((ProgData *)pdata)->yuv_mutex);
+ if(((ProgData *)pdata)->args.no_quick_subsample){
+ UPDATE_YUV_BUFFER_IM_AVG((&((ProgData *)pdata)->enc_data->yuv),((unsigned char*)((ProgData *)pdata)->image->data),
+ (((ProgData *)pdata)->enc_data->x_offset),(((ProgData *)pdata)->enc_data->y_offset),
+ (((ProgData *)pdata)->brwin.rgeom.width),(((ProgData *)pdata)->brwin.rgeom.height));
+ }
+ else{
+ UPDATE_YUV_BUFFER_IM((&((ProgData *)pdata)->enc_data->yuv),((unsigned char*)((ProgData *)pdata)->image->data),
+ (((ProgData *)pdata)->enc_data->x_offset),(((ProgData *)pdata)->enc_data->y_offset),
+ (((ProgData *)pdata)->brwin.rgeom.width),(((ProgData *)pdata)->brwin.rgeom.height));
+ }
+ pthread_mutex_unlock(&((ProgData *)pdata)->yuv_mutex);
+ }
+ else{
+ pthread_mutex_lock(&((ProgData *)pdata)->yuv_mutex);
+ if(((ProgData *)pdata)->args.no_quick_subsample){
+ UPDATE_YUV_BUFFER_IM_AVG((&((ProgData *)pdata)->enc_data->yuv),((unsigned char*)((ProgData *)pdata)->shimage->data),
+ (((ProgData *)pdata)->enc_data->x_offset),(((ProgData *)pdata)->enc_data->y_offset),
+ (((ProgData *)pdata)->brwin.rgeom.width),(((ProgData *)pdata)->brwin.rgeom.height));
+ }
+ else{
+ UPDATE_YUV_BUFFER_IM((&((ProgData *)pdata)->enc_data->yuv),((unsigned char*)((ProgData *)pdata)->shimage->data),
+ (((ProgData *)pdata)->enc_data->x_offset),(((ProgData *)pdata)->enc_data->y_offset),
+ (((ProgData *)pdata)->brwin.rgeom.width),(((ProgData *)pdata)->brwin.rgeom.height));
+ }
+
+ pthread_mutex_unlock(&((ProgData *)pdata)->yuv_mutex);
+ }
+ }
+ if(((ProgData *)pdata)->args.xfixes_cursor){
+ //avoid segfaults
+ CLIP_DUMMY_POINTER_AREA(mouse_pos_abs,&((ProgData *)pdata)->brwin,&mouse_pos_temp);
+ //draw the cursor
+ if((mouse_pos_temp.x>=0)&&(mouse_pos_temp.y>=0)&&(mouse_pos_temp.width>0)&&(mouse_pos_temp.height>0)){
+ XFIXES_POINTER_TO_YUV((&((ProgData *)pdata)->enc_data->yuv),((unsigned char*)xcim->pixels),
+ (mouse_pos_temp.x-((ProgData *)pdata)->brwin.rgeom.x+((ProgData *)pdata)->enc_data->x_offset),
+ (mouse_pos_temp.y-((ProgData *)pdata)->brwin.rgeom.y+((ProgData *)pdata)->enc_data->y_offset),
+ mouse_pos_temp.width,
+ mouse_pos_temp.height,
+ (xcim->width-mouse_pos_temp.width));
+ }
+ XFree(xcim);
+ xcim=NULL;
+ }
+
+ if(((ProgData *)pdata)->args.have_dummy_cursor){
+ //avoid segfaults
+ CLIP_DUMMY_POINTER_AREA(mouse_pos_abs,&((ProgData *)pdata)->brwin,&mouse_pos_temp);
+ //draw the cursor
+ if((mouse_pos_temp.x>=0)&&(mouse_pos_temp.y>=0)&&(mouse_pos_temp.width>0)&&(mouse_pos_temp.height>0)){
+ DUMMY_POINTER_TO_YUV((&((ProgData *)pdata)->enc_data->yuv),
+ ((ProgData *)pdata)->dummy_pointer,
+ (mouse_pos_temp.x-((ProgData *)pdata)->brwin.rgeom.x+((ProgData *)pdata)->enc_data->x_offset),
+ (mouse_pos_temp.y-((ProgData *)pdata)->brwin.rgeom.y+((ProgData *)pdata)->enc_data->y_offset),
+ mouse_pos_temp.width,
+ mouse_pos_temp.height,
+ ((ProgData *)pdata)->npxl);
+ }
+ }
+ if(!((ProgData *)pdata)->args.full_shots){
+ ClearList(&((ProgData *)pdata)->rect_root[tlist_sel]);
+ pthread_mutex_unlock(&((ProgData *)pdata)->list_mutex[tlist_sel]);
+ }
+ if(encoder_busy){
+ frames_lost++;
+ }
+ pthread_cond_broadcast(&((ProgData *)pdata)->image_buffer_ready);
+ capture_busy=0;
+ }
+ pthread_cond_broadcast(&((ProgData *)pdata)->image_buffer_ready);
+ pthread_exit(&errno);
+}
+
diff --git a/rMD-exp/src/getzpixmap.c b/rMD-exp/src/getzpixmap.c
new file mode 100644
index 0000000..4a7a7de
--- /dev/null
+++ b/rMD-exp/src/getzpixmap.c
@@ -0,0 +1,55 @@
+/*********************************************************************************
+* 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 GetZPixmap(Display *dpy,Window root,char *data,int x,int y,int width,int height) {
+ xGetImageReply reply;
+ xGetImageReq *request;
+ long nbytes;
+
+ LockDisplay(dpy);
+ GetReq(GetImage,request);
+ request->drawable=root;
+ request->x=x;
+ request->y=y;
+ request->width=width;
+ request->height=height;
+ request->planeMask=AllPlanes;
+ request->format=ZPixmap;
+ if((!_XReply(dpy,(xReply *)&reply,0,xFalse))||(!reply.length)){
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return 1;
+ }
+ nbytes=(long)reply.length<<2;
+ _XReadPad(dpy,data,nbytes);
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return 0;
+}
+
diff --git a/rMD-exp/src/init_encoder.c b/rMD-exp/src/init_encoder.c
new file mode 100644
index 0000000..ed1ad53
--- /dev/null
+++ b/rMD-exp/src/init_encoder.c
@@ -0,0 +1,172 @@
+/*********************************************************************************
+* 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 InitEncoder(ProgData *pdata,EncData *enc_data_t){
+ int y1,y2;
+ (pdata)->enc_data=enc_data_t;
+ srand(time(NULL));
+ y1=rand();
+ y2=rand();
+ y2+=(y1==y2);
+
+ ogg_stream_init(&(enc_data_t)->m_ogg_ts,y1);
+ if(!pdata->args.nosound)
+ ogg_stream_init(&(enc_data_t)->m_ogg_vs,y2);
+
+ (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;
+ (enc_data_t)->m_th_inf.width=(((enc_data_t)->m_th_inf.frame_width + 15) >>4)<<4;
+ (enc_data_t)->m_th_inf.height=(((enc_data_t)->m_th_inf.frame_height + 15) >>4)<<4;
+ (enc_data_t)->m_th_inf.offset_x=(((enc_data_t)->m_th_inf.width-(enc_data_t)->m_th_inf.frame_width)/2)&~1;
+ (enc_data_t)->m_th_inf.offset_y=(((enc_data_t)->m_th_inf.height-(enc_data_t)->m_th_inf.frame_height)/2)&~1;
+ (enc_data_t)->m_th_inf.fps_numerator=((pdata)->args.fps*100.0);
+ (enc_data_t)->m_th_inf.fps_denominator=100;
+ (enc_data_t)->m_th_inf.aspect_numerator=1;//(pdata)->brwin.rgeom.width;
+ (enc_data_t)->m_th_inf.aspect_denominator=1;//(pdata)->brwin.rgeom.height;
+ (enc_data_t)->m_th_inf.colorspace=OC_CS_UNSPECIFIED;
+ (enc_data_t)->m_th_inf.pixelformat=OC_PF_420;
+ (enc_data_t)->m_th_inf.target_bitrate=(pdata)->args.v_bitrate;
+ (enc_data_t)->m_th_inf.quality=(pdata)->args.v_quality;
+ (enc_data_t)->m_th_inf.dropframes_p=(pdata)->args.dropframes;
+ (enc_data_t)->m_th_inf.quick_p=1;
+ (enc_data_t)->m_th_inf.keyframe_auto_p=1;
+ (enc_data_t)->m_th_inf.keyframe_frequency=64;
+ (enc_data_t)->m_th_inf.keyframe_frequency_force=64;
+ (enc_data_t)->m_th_inf.keyframe_data_target_bitrate=(enc_data_t)->m_th_inf.quality*1.5;
+ (enc_data_t)->m_th_inf.keyframe_auto_threshold=80;
+ (enc_data_t)->m_th_inf.keyframe_mindistance=8;
+ (enc_data_t)->m_th_inf.noise_sensitivity=1;
+ (enc_data_t)->m_th_inf.sharpness=2;
+
+ theora_encode_init(&(enc_data_t)->m_th_st,&(enc_data_t)->m_th_inf);
+
+
+
+ if(!pdata->args.nosound){
+ int ret;
+ vorbis_info_init(&(enc_data_t)->m_vo_inf);
+ ret = vorbis_encode_init_vbr(&(enc_data_t)->m_vo_inf,pdata->args.channels,pdata->args.frequency,(float)pdata->args.s_quality*0.1);
+ if(ret){
+ fprintf(stderr,"Error while setting up vorbis stream quality!\n");
+ exit(2);
+ }
+ vorbis_comment_init(&(enc_data_t)->m_vo_cmmnt);
+ vorbis_analysis_init(&(enc_data_t)->m_vo_dsp,&(enc_data_t)->m_vo_inf);
+ 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){
+ 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);
+
+ theora_comment_init(&(enc_data_t)->m_th_cmmnt);
+ theora_comment_add_tag(&(enc_data_t)->m_th_cmmnt,"recordMyDesktop",VERSION);
+ theora_encode_comment(&(enc_data_t)->m_th_cmmnt,&(enc_data_t)->m_ogg_pckt1);
+ ogg_stream_packetin(&(enc_data_t)->m_ogg_ts,&(enc_data_t)->m_ogg_pckt1);
+ theora_encode_tables(&(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(!pdata->args.nosound){
+ 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);
+ 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);
+ }
+
+
+
+ while(1){
+ int result = ogg_stream_flush(&(enc_data_t)->m_ogg_ts,&(enc_data_t)->m_ogg_pg);
+ if(result<0){
+ fprintf(stderr,"Internal Ogg library error.\n");
+ exit(2);
+ }
+ if(result==0)break;
+ 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);
+ }
+
+ if(!pdata->args.nosound){
+ while(1){
+ int result=ogg_stream_flush(&(enc_data_t)->m_ogg_vs,&(enc_data_t)->m_ogg_pg);
+ if(result<0){
+ fprintf(stderr,"Internal Ogg library error.\n");
+ exit(2);
+ }
+ if(result==0)break;
+ 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);
+ }
+ }
+
+
+
+ (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;
+ theora_info_clear(&(enc_data_t)->m_th_inf);
+
+}
+
+
+
+
diff --git a/rMD-exp/src/make_dummy_pointer.c b/rMD-exp/src/make_dummy_pointer.c
new file mode 100644
index 0000000..00a346e
--- /dev/null
+++ b/rMD-exp/src/make_dummy_pointer.c
@@ -0,0 +1,76 @@
+/*********************************************************************************
+* 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>
+
+unsigned char *MakeDummyPointer(DisplaySpecs *specs,int size,int color,int type,unsigned char *npxl){
+ int i,k,o='.';
+ unsigned long b=(color)?'w':'b',
+ w=(color)?'b':'w';
+ char pmask[1][16][16]={{
+ {w,w,w,w,w,w,o,o,o,o,o,o,o,o,o,o},
+ {w,b,b,w,w,w,w,o,o,o,o,o,o,o,o,o},
+ {w,b,b,b,w,w,w,w,o,o,o,o,o,o,o,o},
+ {w,b,b,b,b,w,w,w,w,o,o,o,o,o,o,o},
+ {w,b,b,b,b,b,w,w,w,w,o,o,o,o,o,o},
+ {w,b,b,b,b,b,b,w,w,w,w,o,o,o,o,o},
+ {w,b,b,b,b,b,b,b,w,w,w,w,o,o,o,o},
+ {w,b,b,b,b,b,b,b,b,w,w,w,w,o,o,o},
+ {w,b,b,b,b,b,b,b,b,b,w,w,w,w,o,o},
+ {w,b,b,b,b,b,b,b,b,b,b,w,w,w,w,o},
+ {w,b,b,b,b,b,b,b,b,w,w,w,w,o,o,o},
+ {w,b,b,b,b,b,b,b,b,w,w,w,w,o,o,o},
+ {w,w,w,w,w,b,b,b,b,b,w,w,w,o,o,o},
+ {w,w,w,w,w,w,b,b,b,b,w,w,w,o,o,o},
+ {o,o,o,o,o,w,w,b,b,b,w,w,w,o,o,o},
+ {o,o,o,o,o,o,w,w,w,w,w,w,w,o,o,o}}
+ };
+ unsigned char *ret=malloc(size*sizeof(char[size*4]));
+ unsigned char wp[4]={
+ ((specs->wpixel^0xff000000)>>24),
+ ((specs->wpixel^0x00ff0000)>>16),
+ ((specs->wpixel^0x0000ff00)>>8),
+ ((specs->wpixel^0x000000ff))
+ };
+ unsigned char bp[4]={
+ ((specs->bpixel^0xff000000)>>24),
+ ((specs->bpixel^0x00ff0000)>>16),
+ ((specs->bpixel^0x0000ff00)>>8),
+ ((specs->bpixel^0x000000ff))
+ };
+ *npxl=((wp[0]-1)!=bp[0])?wp[0]-100:wp[0]-102;
+ for(i=0;i<size;i++){
+ for(k=0;k<size;k++){
+ ret[(i*size+k)*4+__ABYTE]=(pmask[type][i][k]=='w')?wp[0]:(pmask[type][i][k]=='b')?bp[0]:*npxl;
+ ret[(i*size+k)*4+__RBYTE]=(pmask[type][i][k]=='w')?wp[1]:(pmask[type][i][k]=='b')?bp[1]:*npxl;
+ ret[(i*size+k)*4+__GBYTE]=(pmask[type][i][k]=='w')?wp[2]:(pmask[type][i][k]=='b')?bp[2]:*npxl;
+ ret[(i*size+k)*4+__BBYTE]=(pmask[type][i][k]=='w')?wp[3]:(pmask[type][i][k]=='b')?bp[3]:*npxl;
+ }
+ }
+
+ return ret;
+}
diff --git a/rMD-exp/src/opendev.c b/rMD-exp/src/opendev.c
new file mode 100644
index 0000000..4b559ec
--- /dev/null
+++ b/rMD-exp/src/opendev.c
@@ -0,0 +1,103 @@
+/*********************************************************************************
+* 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>
+
+
+snd_pcm_t *OpenDev(const char *pcm_dev,unsigned int *channels,unsigned int *frequency,snd_pcm_uframes_t *periodsize,unsigned int *periodtime,int *hard_pause){
+
+ snd_pcm_t *mhandle;
+ snd_pcm_hw_params_t *hwparams;
+ unsigned int periods=2;
+ unsigned int exactrate = *frequency;
+
+ snd_pcm_hw_params_alloca(&hwparams);
+ snd_pcm_uframes_t buffsize=4096;
+
+ if (snd_pcm_open(&mhandle, pcm_dev, SND_PCM_STREAM_CAPTURE, 0)<0){
+ fprintf(stderr, "Couldn't open PCM device %s\n", pcm_dev);
+ return NULL;
+ }
+ if (snd_pcm_hw_params_any(mhandle, hwparams)<0){
+ fprintf(stderr, "Couldn't configure PCM device.\n");
+ return NULL;
+ }
+ if (snd_pcm_hw_params_set_access(mhandle, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED)<0) {
+ fprintf(stderr, "Couldn't set access.\n");
+ return NULL;
+ }
+ if (snd_pcm_hw_params_set_format(mhandle, hwparams, SND_PCM_FORMAT_S16_LE)<0){
+ fprintf(stderr, "Couldn't set format.\n");
+ return NULL;
+ }
+ if (snd_pcm_hw_params_set_rate_near(mhandle, hwparams, &exactrate, 0)<0){
+ fprintf(stderr, "Couldn't set frequency.\n");
+ return NULL;
+ }
+ if (*frequency != exactrate){
+ fprintf(stderr, "Playback frequency %dHz is not available...\nUsing %dHz instead.\n",*frequency,exactrate);
+ *frequency=exactrate;
+ }
+ if (snd_pcm_hw_params_set_channels_near(mhandle, hwparams, channels)<0){
+ fprintf(stderr, "Couldn't set channels number.\n");
+ return NULL;
+ }
+ if(*channels>2){
+ fprintf(stderr,"Channels number should be 1(mono) or 2(stereo).\n");
+ return NULL;
+ }
+ if (snd_pcm_hw_params_set_periods_near(mhandle, hwparams, &periods,0)<0) {
+ fprintf(stderr, "Couldn't set periods.\n");
+ return NULL;
+ }
+ buffsize=(exactrate*(*channels))/2;
+ if (snd_pcm_hw_params_set_buffer_size_near(mhandle, hwparams,&buffsize)<0){
+ fprintf(stderr, "Couldn't set buffer size.\n");
+ return NULL;
+ }
+ if (snd_pcm_hw_params(mhandle, hwparams)<0){
+ fprintf(stderr, "Couldn't set hardware parameters.\n");
+ return NULL;
+ }
+ if(hard_pause!=NULL)
+ if(!snd_pcm_hw_params_can_pause(hwparams)){
+// fprintf(stderr, "Current sound device doesn't seem to support pausing!\nI will attempt to close/reopen device in case you opt to pause during recording.\n");
+ *hard_pause=1;
+ }
+ if(periodsize!=NULL)
+ snd_pcm_hw_params_get_period_size(hwparams,periodsize,0);
+ if(periodtime!=NULL)
+ snd_pcm_hw_params_get_period_time(hwparams,periodtime,0);
+ fprintf(stderr,"Recording on device %s is set to:\n%d channels at %dHz\n",pcm_dev,*channels,*frequency);
+ snd_pcm_prepare(mhandle);
+
+ return mhandle;
+}
+
+
diff --git a/rMD-exp/src/parseargs.c b/rMD-exp/src/parseargs.c
new file mode 100644
index 0000000..5280cf2
--- /dev/null
+++ b/rMD-exp/src/parseargs.c
@@ -0,0 +1,421 @@
+/*********************************************************************************
+* 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 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 -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"
+
+ "General Options:\n"
+ "\t-h or --help\t\tPrint this help and exit.\n"
+ "\t--version\t\tPrint program version and exit.\n\n"
+
+ "Image Options:\n"
+ "\t-windowid id_of_window\tid of window to be recorded.\n"
+ "\t-display DISPLAY\tDisplay to connect to.\n"
+ "\t-x X\t\t\tOffset in x direction.\n"
+ "\t-y Y\t\t\tOffset in y direction.\n"
+ "\t-width N\t\tWidth of recorded window.\n"
+ "\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--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"
+ "\t--full-shots\t\tTake full screenshot at every frame(Not recomended!).\n"
+ "\t--quick-subsampling\tDo subsampling of the chroma planes by discarding,not averaging.\n"
+ "\t-fps N(number>0.0)\tA positive number denoting desired framerate.\n\n"
+
+ "Sound Options:\n"
+ "\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"
+
+ "Encoding Options\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-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-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";
+
+ if(argc==2){
+ if(argv[1][0]!='-'){
+ free(arg_return->filename);
+ arg_return->filename=malloc(strlen(argv[1])+1);
+ strcpy(arg_return->filename,argv[1]);
+ return 0;
+ }
+ }
+ for(i=1;i<argc;i++){
+ if(!strcmp(argv[i],"-delay")){
+ if(i+1<argc){
+ float num=atof(argv[i+1]);
+ if(num>0.0){
+ int k;
+ for(k=0;k<strlen(argv[i+1]);k++){
+ if((argv[i+1][k]=='M')||(argv[i+1][k]=='m')){
+ num*=60.0;
+ break;
+ }
+ else if((argv[i+1][k]=='H')||(argv[i+1][k]=='h')){
+ num*=3600.0;
+ break;
+ }
+ }
+ arg_return->delay=(int)num;
+ }
+ else{
+ fprintf(stderr,"Argument Usage: -delay n[H|h|M|m]\nwhere n is a float number\n");
+ return 1;
+ }
+ }
+ else{
+ fprintf(stderr,"Argument Usage: -delay n[H|h|M|m]\nwhere n is a float number\n");
+ return 1;
+ }
+ i++;
+ }
+ else if(!strcmp(argv[i],"-windowid")){
+ if(i+1<argc){
+ Window num=strtod(argv[i+1],NULL);
+ if(num>0)
+ arg_return->windowid=num;
+ else{
+ fprintf(stderr,"Argument Usage: -windowid id_of_window(number)\n");
+ return 1;
+ }
+ }
+ else{
+ fprintf(stderr,"Argument Usage: -windowid id_of_window(number)\n");
+ return 1;
+ }
+ i++;
+ }
+ else if(!strcmp(argv[i],"-display")){
+ if(i+1<argc){
+ if(arg_return->display!=NULL)
+ free(arg_return->display);
+ arg_return->display=malloc(strlen(argv[i+1])+1);
+ strcpy(arg_return->display,argv[i+1]);
+ }
+ else{
+ fprintf(stderr,"Argument Usage: -display DISPLAY\n");
+ return 1;
+ }
+ i++;
+ }
+ else if(!strcmp(argv[i],"-x")){
+ if(i+1<argc){
+ int num=atoi(argv[i+1]);
+ if(num>0)
+ arg_return->x=num;
+ else{
+ fprintf(stderr,"Argument Usage: -x X(number>0)\n");
+ return 1;
+ }
+ }
+ else{
+ fprintf(stderr,"Argument Usage: -x X(number>0)\n");
+ return 1;
+ }
+ i++;
+ }
+ else if(!strcmp(argv[i],"-y")){
+ if(i+1<argc){
+ int num=atoi(argv[i+1]);
+ if(num>0)
+ arg_return->y=num;
+ else{
+ fprintf(stderr,"Argument Usage: -y Y(number>0)\n");
+ return 1;
+ }
+ }
+ else{
+ fprintf(stderr,"Argument Usage: -y Y(number>0)\n");
+ return 1;
+ }
+ i++;
+ }
+ else if(!strcmp(argv[i],"-width")){
+ if(i+1<argc){
+ int num=atoi(argv[i+1]);
+ if(num>0)
+ arg_return->width=num;
+ else{
+ fprintf(stderr,"Argument Usage: -width N(number>0)\n");
+ return 1;
+ }
+ }
+ else{
+ fprintf(stderr,"Argument Usage: -width N(number>0)\n");
+ return 1;
+ }
+ i++;
+ }
+ else if(!strcmp(argv[i],"-height")){
+ if(i+1<argc){
+ int num=atoi(argv[i+1]);
+ if(num>0)
+ arg_return->height=num;
+ else{
+ fprintf(stderr,"Argument Usage: -height N(number>0)\n");
+ return 1;
+ }
+ }
+ else{
+ fprintf(stderr,"Argument Usage: -height N(number>0)\n");
+ return 1;
+ }
+ i++;
+ }
+ else if(!strcmp(argv[i],"-o")){
+ if(i+1<argc){
+ free(arg_return->filename);
+ arg_return->filename=malloc(strlen(argv[i+1])+1);
+ strcpy(arg_return->filename,argv[i+1]);
+ }
+ else{
+ fprintf(stderr,"Argument Usage: -o filename\n");
+ return 1;
+ }
+ i++;
+ }
+ else if(!strcmp(argv[i],"-fps")){
+ if(i+1<argc){
+ float num=atof(argv[i+1]);
+ if(num>0.0)
+ arg_return->fps=num;
+ else{
+ fprintf(stderr,"Argument Usage: -fps N(number>0)\n");
+ return 1;
+ }
+ }
+ else{
+ fprintf(stderr,"Argument Usage: -fps N(number>0)\n");
+ return 1;
+ }
+ i++;
+ }
+ else if(!strcmp(argv[i],"-v_quality")){
+ if(i+1<argc){
+ int num=atoi(argv[i+1]);
+ if((num>=0)&&(num<64))
+ arg_return->v_quality=num;
+ else{
+ fprintf(stderr,"Argument Usage: -v_quality n(number 0-63)\n");
+ return 1;
+ }
+ }
+ else{
+ fprintf(stderr,"Argument Usage: -v_quality n(number 0-63)\n");
+ return 1;
+ }
+ i++;
+ }
+ else if(!strcmp(argv[i],"-v_bitrate")){
+ if(i+1<argc){
+ int num=atoi(argv[i+1]);
+ if((num>=45000)&&(num<=2000000))
+ arg_return->v_bitrate=num;
+ else{
+ fprintf(stderr,"Argument Usage: -v_bitrate n(number 45000-2000000)\n");
+ return 1;
+ }
+ }
+ else{
+ fprintf(stderr,"Argument Usage: -v_bitrate n(number 45000-2000000)\n");
+ return 1;
+ }
+ i++;
+ }
+ else if(!strcmp(argv[i],"-dummy-cursor")){
+ if(i+1<argc){
+ if(!strcmp(argv[i+1],"white"))
+ arg_return->cursor_color=0;
+ else if(!strcmp(argv[i+1],"black"))
+ arg_return->cursor_color=1;
+ else{
+ fprintf(stderr,"Argument Usage: -dummy-cursor [black|white]\n");
+ return 1;
+ }
+ arg_return->have_dummy_cursor=1;
+ arg_return->xfixes_cursor=0;
+ }
+ else{
+ fprintf(stderr,"Argument Usage: -dummy-cursor [black|white]\n");
+ return 1;
+ }
+ i++;
+ }
+ else if(!strcmp(argv[i],"--no-cursor"))
+ arg_return->xfixes_cursor=0;
+ else if(!strcmp(argv[i],"-freq")){
+ if(i+1<argc){
+ int num=atoi(argv[i+1]);
+ if(num>0)
+ arg_return->frequency=num;
+ else{
+ fprintf(stderr,"Argument Usage: -freq N(number>0)\n");
+ return 1;
+ }
+ }
+ else{
+ fprintf(stderr,"Argument Usage: -freq N(number>0)\n");
+ return 1;
+ }
+ i++;
+ }
+ else if(!strcmp(argv[i],"-channels")){
+ if(i+1<argc){
+ int num=atoi(argv[i+1]);
+ if(num>0)
+ arg_return->channels=num;
+ else{
+ fprintf(stderr,"Argument Usage: -channels N(number>0)\n");
+ return 1;
+ }
+ }
+ else{
+ fprintf(stderr,"Argument Usage: -channels N(number>0)\n");
+ return 1;
+ }
+ i++;
+ }
+ else if(!strcmp(argv[i],"-s_quality")){
+ if(i+1<argc){
+ int num=atoi(argv[i+1]);
+ if((num>=-1)&&(num<=10))
+ arg_return->s_quality=num;
+ else{
+ fprintf(stderr,"Argument Usage: -s_quality n(number -1 to 10)\n");
+ return 1;
+ }
+ }
+ else{
+ fprintf(stderr,"Argument Usage: -s_quality n(number -1 to 10)\n");
+ return 1;
+ }
+ i++;
+ }
+ else if(!strcmp(argv[i],"-shared-threshold")){
+ if(i+1<argc){
+ int num=atoi(argv[i+1]);
+ if((num>0)&&(num<100))
+ arg_return->shared_thres=num;
+ else{
+ fprintf(stderr,"Argument Usage: -shared-threshold N(0<number<100)\n");
+ return 1;
+ }
+ }
+ else{
+ fprintf(stderr,"Argument Usage: -shared-threshold N(0<number<100)\n");
+ return 1;
+ }
+ i++;
+ }
+ else if(!strcmp(argv[i],"-scale-shot")){
+ 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;
+ }
+ }
+ else{
+ fprintf(stderr,"Argument Usage: -scale-shot N(0<number<64,power of 2)\n");
+ return 1;
+ }
+ i++;
+ }
+ else if(!strcmp(argv[i],"-device")){
+ if(i+1<argc){
+ 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: -device SOUND_DEVICE\n");
+ return 1;
+ }
+ i++;
+ }
+ else if(!strcmp(argv[i],"--nosound"))
+ arg_return->nosound=1;
+ else if(!strcmp(argv[i],"--drop-frames"))
+ arg_return->dropframes=1;
+ else if(!strcmp(argv[i],"--with-shared")){
+ arg_return->noshared=0;
+ arg_return->nocondshared=1;
+ }
+ else if(!strcmp(argv[i],"--no-cond-shared"))
+ arg_return->nocondshared=1;
+ else if(!strcmp(argv[i],"--full-shots")){
+ 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],"--help")||!strcmp(argv[i],"-h")){
+ fprintf(stderr,"%s",usage);
+ return 1;
+ }
+ else if(!strcmp(argv[i],"--version")){
+ fprintf(stderr,"recordMyDesktop v%s\n\n",VERSION);
+ return 1;
+ }
+ else{
+ fprintf(stderr,"\n\tError parsing arguments.\n\tType --help or -h for usage.\n\n");
+ return 1;
+ }
+ }
+ return 0;
+}
diff --git a/rMD-exp/src/poll_damage.c b/rMD-exp/src/poll_damage.c
new file mode 100644
index 0000000..5433bbc
--- /dev/null
+++ b/rMD-exp/src/poll_damage.c
@@ -0,0 +1,57 @@
+/*********************************************************************************
+* 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 *PollDamage(void *pdata){
+
+ Damage damage;
+ XEvent event;
+ int inserts=0;
+
+
+ damage= 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
+ XNextEvent(((ProgData *)pdata)->dpy,&event);
+ if(event.type == ((ProgData *)pdata)->damage_event + XDamageNotify ){
+ XDamageNotifyEvent *e =(XDamageNotifyEvent *)( &event );
+ WGeometry wgeom;
+ CLIP_EVENT_AREA(e,&(((ProgData *)pdata)->brwin),&wgeom);
+ if((wgeom.x>=0)&&(wgeom.y>=0)&&(wgeom.width>0)&&(wgeom.height>0))
+ {
+ int tlist_sel=((ProgData *)pdata)->list_selector;
+ pthread_mutex_lock(&((ProgData *)pdata)->list_mutex[tlist_sel]);
+ inserts+=RectInsert(&((ProgData *)pdata)->rect_root[tlist_sel],&wgeom);
+ pthread_mutex_unlock(&((ProgData *)pdata)->list_mutex[tlist_sel]);
+ }
+ }
+ }
+ pthread_exit(&errno);
+}
+
diff --git a/rMD-exp/src/queryextensions.c b/rMD-exp/src/queryextensions.c
new file mode 100644
index 0000000..0b311b9
--- /dev/null
+++ b/rMD-exp/src/queryextensions.c
@@ -0,0 +1,48 @@
+/*********************************************************************************
+* 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 QueryExtensions(Display *dpy,ProgArgs *args,int *damage_event,int *damage_error){
+ int xf_event_basep,
+ xf_error_basep;
+
+ if(!XDamageQueryExtension( dpy, damage_event, damage_error)){
+ fprintf(stderr,"XDamage extension not found!!!\n");
+ exit(4);
+ }
+ if((!args->noshared)&&(XShmQueryExtension(dpy)==False)){
+ args->noshared=1;
+ fprintf(stderr,"Shared Memory extension not present!\nTry again removing the --with-shared option(if you used it)\nand add the --no-cond-shared option.\n");
+ exit(5);
+ }
+ if((args->xfixes_cursor)&&(XFixesQueryExtension(dpy,&xf_event_basep,&xf_error_basep)==False)){
+ args->xfixes_cursor=0;
+ fprintf(stderr,"Xfixes extension not present!\nPlease run with the -dummy-cursor or --no-cursor option.\n");
+ exit(6);
+ }
+}
diff --git a/rMD-exp/src/recordmydesktop.c b/rMD-exp/src/recordmydesktop.c
new file mode 100644
index 0000000..5b7e32b
--- /dev/null
+++ b/rMD-exp/src/recordmydesktop.c
@@ -0,0 +1,259 @@
+/*********************************************************************************
+* 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 main(int argc,char **argv){
+ ProgData pdata;
+
+ if(XInitThreads ()==0){
+ fprintf(stderr,"Couldn't initialize thread support!\n");
+ exit(7);
+ }
+ DEFAULT_ARGS(&pdata.args);
+ if(ParseArgs(argc,argv,&pdata.args)){
+ exit(1);
+ }
+ if(pdata.args.display!=NULL)
+ pdata.dpy = XOpenDisplay(pdata.args.display);
+ else{
+ fprintf(stderr,"No display specified for connection!\n");
+ exit(8);
+ }
+ if (pdata.dpy == NULL) {
+ fprintf(stderr, "Cannot connect to X server %s\n",pdata.args.display);
+ exit(9);
+ }
+ else{
+ EncData enc_data;
+ pthread_t poll_damage_t,
+ image_capture_t,
+ image_encode_t,
+ sound_capture_t,
+ sound_encode_t,
+ flush_to_ogg_t;
+ XShmSegmentInfo shminfo;
+ int i;
+
+ QUERY_DISPLAY_SPECS(pdata.dpy,&pdata.specs);
+ if(pdata.specs.depth!=24){
+ fprintf(stderr,"Only 24bpp color depth mode is currently supported.\n");
+ exit(10);
+ }
+ if(SetBRWindow(pdata.dpy,&pdata.brwin,&pdata.specs,&pdata.args))
+ exit(11);
+
+ QueryExtensions(pdata.dpy,&pdata.args,&pdata.damage_event, &pdata.damage_error);
+
+ //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;
+ }
+ }
+ if((pdata.args.noshared)||(pdata.args.scshot))
+ 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)){
+ 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);
+ 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);
+ }
+ if((!pdata.args.noshared)||(!pdata.args.nocondshared)){
+ 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,
+ IPC_CREAT|0777);
+ shminfo.shmaddr = pdata.shimage->data = shmat (shminfo.shmid, 0, 0);
+ shminfo.readOnly = False;
+ if(!XShmAttach(pdata.dpy,&shminfo)){
+ fprintf(stderr,"Failed to attach shared memory to proccess.\n");
+ exit(12);
+ }
+ 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){
+ fprintf(stderr,"Error while opening/configuring soundcard %s\nTry running with the --no-sound or specify a correct device.\n",pdata.args.device);
+ exit(3);
+ }
+ }
+ InitEncoder(&pdata,&enc_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),
+ (pdata.enc_data->x_offset),(pdata.enc_data->y_offset),
+ (pdata.brwin.rgeom.width),(pdata.brwin.rgeom.height));
+ }
+ else{
+ UPDATE_YUV_BUFFER_IM((&pdata.enc_data->yuv),((unsigned char*)pdata.shimage->data),
+ (pdata.enc_data->x_offset),(pdata.enc_data->y_offset),
+ (pdata.brwin.rgeom.width),(pdata.brwin.rgeom.height));
+ }
+ }
+ else{
+ if(pdata.args.no_quick_subsample){
+ UPDATE_YUV_BUFFER_IM_AVG((&pdata.enc_data->yuv),((unsigned char*)pdata.image->data),
+ (pdata.enc_data->x_offset),(pdata.enc_data->y_offset),
+ (pdata.brwin.rgeom.width),(pdata.brwin.rgeom.height));
+ }
+ else{
+ UPDATE_YUV_BUFFER_IM((&pdata.enc_data->yuv),((unsigned char*)pdata.image->data),
+ (pdata.enc_data->x_offset),(pdata.enc_data->y_offset),
+ (pdata.brwin.rgeom.width),(pdata.brwin.rgeom.height));
+ }
+ }
+
+ pdata.frametime=(1000000)/pdata.args.fps;
+
+ if(pdata.args.delay>0){
+ fprintf(stderr,"Will sleep for %d seconds now.\n",pdata.args.delay);
+ sleep(pdata.args.delay);
+ }
+
+ /*start threads*/
+ 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.nosound){
+ pthread_create(&sound_capture_t,NULL,CaptureSound,(void *)&pdata);
+ pthread_create(&sound_encode_t,NULL,EncodeSoundBuffer,(void *)&pdata);
+ }
+ 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);
+ fprintf(stderr,".");
+ if(!pdata.args.nosound){
+ pthread_join(sound_capture_t,NULL);
+ fprintf(stderr,".");
+ pthread_join(sound_encode_t,NULL);
+ fprintf(stderr,".");
+ }
+ else
+ fprintf(stderr,"..");
+ 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");
+ XCloseDisplay(pdata.dpy);
+ if(Aborted){
+ if(remove(pdata.args.filename)){
+ perror("Error while removing file:\n");
+ return 1;
+ }
+ else{
+ fprintf(stderr,"SIGABRT received,file %s removed\n",pdata.args.filename);
+ return 0;
+ }
+ }
+ else
+ fprintf(stderr,"Goodbye!\n");
+ }
+ return 0;
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/rMD-exp/src/rectinsert.c b/rMD-exp/src/rectinsert.c
new file mode 100644
index 0000000..aefeb1e
--- /dev/null
+++ b/rMD-exp/src/rectinsert.c
@@ -0,0 +1,499 @@
+/*********************************************************************************
+* 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>
+//return 1 and null if geom1 in geom2 ,2 and null if geom2 in geom1,0 if they don't collide
+//-1 and two geoms if they collide and geom1 is broken.//-2 and one or two geoms if they collide and geom2 is broken.
+//-10 if group and replace is possible
+int CollideRects(WGeometry *wgeom1,WGeometry *wgeom2,WGeometry **wgeom_return,int *ngeoms){
+ //1 fits in 2
+ if((wgeom1->x>=wgeom2->x)&&
+ (wgeom1->x+wgeom1->width<=wgeom2->x+wgeom2->width)&&
+ (wgeom1->y>=wgeom2->y)&&
+ (wgeom1->y+wgeom1->height<=wgeom2->y+wgeom2->height)){
+ *ngeoms=0;
+ return 1;
+ }
+ //2 fits in 1
+ else if((wgeom2->x>=wgeom1->x)&&
+ (wgeom2->x+wgeom2->width<=wgeom1->x+wgeom1->width)&&
+ (wgeom2->y>=wgeom1->y)&&
+ (wgeom2->y+wgeom2->height<=wgeom1->y+wgeom1->height)){
+ *ngeoms=0;
+ return 2;
+ }
+ //no collision
+ else if((wgeom1->x+wgeom1->width<wgeom2->x)||
+ (wgeom2->x+wgeom2->width<wgeom1->x)||
+ (wgeom1->y+wgeom1->height<wgeom2->y)||
+ (wgeom2->y+wgeom2->height<wgeom1->y)){
+ *ngeoms=0;
+ return 0;
+ }
+ else{
+//overlapping points are considered enclosed
+//this happens because libxdamage may generate many events for one change
+//and some of them may be in the the exact same region
+//so identical rects would be considered not colliding
+//in order though to avoid endless recursion on the RectInsert
+//function should always start at the next element(which is logical since
+//if any rect makes it to a points none of it's part collides with previous
+//nodes on the list, too)
+ int x1[2]={wgeom1->x,wgeom1->x+wgeom1->width};
+ int y1[2]={wgeom1->y,wgeom1->y+wgeom1->height};
+ int x2[2]={wgeom2->x,wgeom2->x+wgeom2->width};
+ int y2[2]={wgeom2->y,wgeom2->y+wgeom2->height};
+ int enclosed[2][4],tot1,tot2;
+ enclosed[0][0]=(((x1[0]>=x2[0])&&(x1[0]<=x2[1])&&
+ (y1[0]>=y2[0])&&(y1[0]<=y2[1]))?1:0);
+ enclosed[0][1]=(((x1[1]>=x2[0])&&(x1[1]<=x2[1])&&
+ (y1[0]>=y2[0])&&(y1[0]<=y2[1]))?1:0);
+ enclosed[0][2]=(((x1[0]>=x2[0])&&(x1[0]<=x2[1])&&
+ (y1[1]>=y2[0])&&(y1[1]<=y2[1]))?1:0);
+ enclosed[0][3]=(((x1[1]>=x2[0])&&(x1[1]<=x2[1])&&
+ (y1[1]>=y2[0])&&(y1[1]<=y2[1]))?1:0);
+ enclosed[1][0]=(((x2[0]>=x1[0])&&(x2[0]<=x1[1])&&
+ (y2[0]>=y1[0])&&(y2[0]<=y1[1]))?1:0);
+ enclosed[1][1]=(((x2[1]>=x1[0])&&(x2[1]<=x1[1])&&
+ (y2[0]>=y1[0])&&(y2[0]<=y1[1]))?1:0);
+ enclosed[1][2]=(((x2[0]>=x1[0])&&(x2[0]<=x1[1])&&
+ (y2[1]>=y1[0])&&(y2[1]<=y1[1]))?1:0);
+ enclosed[1][3]=(((x2[1]>=x1[0])&&(x2[1]<=x1[1])&&
+ (y2[1]>=y1[0])&&(y2[1]<=y1[1]))?1:0);
+ tot1=enclosed[0][0]+enclosed[0][1]+enclosed[0][2]+enclosed[0][3];
+ tot2=enclosed[1][0]+enclosed[1][1]+enclosed[1][2]+enclosed[1][3];
+ if((tot1==2)&&(tot2==2)){//same width or height, which is the best case
+ //group
+ if((enclosed[1][0]&&enclosed[1][1])&&(wgeom1->width==wgeom2->width)){
+ wgeom_return[0]=(WGeometry *)malloc(sizeof(WGeometry));
+ *ngeoms=1;
+ wgeom_return[0]->x=wgeom1->x;
+ wgeom_return[0]->y=wgeom1->y;
+ wgeom_return[0]->width=wgeom1->width;
+ wgeom_return[0]->height=wgeom2->height+wgeom2->y-wgeom1->y;
+ return -10;
+ }
+ else if((enclosed[1][0]&&enclosed[1][2])&&(wgeom1->height==wgeom2->height)){
+// wgeom_return[0]=(WGeometry *)malloc(sizeof(WGeometry));
+ *ngeoms=1;
+ wgeom_return[0]->x=wgeom1->x;
+ wgeom_return[0]->y=wgeom1->y;
+ wgeom_return[0]->width=wgeom2->width+wgeom2->x-wgeom1->x;
+ wgeom_return[0]->height=wgeom1->height;
+ return -10;
+ }
+ else if((enclosed[1][3]&&enclosed[1][1])&&(wgeom1->height==wgeom2->height)){
+// wgeom_return[0]=(WGeometry *)malloc(sizeof(WGeometry));
+ *ngeoms=1;
+ wgeom_return[0]->x=wgeom2->x;
+ wgeom_return[0]->y=wgeom2->y;
+ wgeom_return[0]->width=wgeom1->width+wgeom1->x-wgeom2->x;
+ wgeom_return[0]->height=wgeom2->height;
+ return -10;
+ }
+ else if((enclosed[1][3]&&enclosed[1][2])&&(wgeom1->width==wgeom2->width)){
+// wgeom_return[0]=(WGeometry *)malloc(sizeof(WGeometry));
+ *ngeoms=1;
+ wgeom_return[0]->x=wgeom2->x;
+ wgeom_return[0]->y=wgeom2->y;
+ wgeom_return[0]->width=wgeom2->width;
+ wgeom_return[0]->height=wgeom1->height+wgeom1->y-wgeom2->y;
+ return -10;
+ }
+ //if control reaches here therewasn't a group and we go on
+ }
+ if(tot2==2){
+ //break geom2
+// wgeom_return[0]=(WGeometry *)malloc(sizeof(WGeometry));
+ wgeom_return[0]->x=wgeom2->x;
+ wgeom_return[0]->y=wgeom2->y;
+ wgeom_return[0]->width=wgeom2->width;
+ wgeom_return[0]->height=wgeom2->height;
+ *ngeoms=1;
+ if(enclosed[1][0]&&enclosed[1][1]){
+ wgeom_return[0]->y=y1[1];
+ wgeom_return[0]->height-=y1[1]-y2[0];
+ }
+ else if(enclosed[1][0]&&enclosed[1][2]){
+ wgeom_return[0]->x=x1[1];
+ wgeom_return[0]->width-=x1[1]-x2[0];
+ }
+ else if(enclosed[1][3]&&enclosed[1][1])
+ wgeom_return[0]->width-=x2[1]-x1[0];
+ else if(enclosed[1][3]&&enclosed[1][2])
+ wgeom_return[0]->height-=y2[1]-y1[0];
+ return -2;
+ }
+ else if(tot1==2){
+ //if the first one breaks(which is already inserted)
+ //then we reenter the part that was left and the one
+ //that was to be inserted
+// wgeom_return[1]=wgeom2;
+ wgeom_return[1]->x=wgeom2->x;
+ wgeom_return[1]->y=wgeom2->y;
+ wgeom_return[1]->width=wgeom2->width;
+ wgeom_return[1]->height=wgeom2->height;
+// wgeom_return[0]=(WGeometry *)malloc(sizeof(WGeometry));
+ wgeom_return[0]->x=wgeom1->x;
+ wgeom_return[0]->y=wgeom1->y;
+ wgeom_return[0]->width=wgeom1->width;
+ wgeom_return[0]->height=wgeom1->height;
+ *ngeoms=1;
+ if(enclosed[0][0]&&enclosed[0][1]){
+ wgeom_return[0]->y=y2[1];
+ wgeom_return[0]->height-=y2[1]-y1[0];
+ }
+ else if(enclosed[0][0]&&enclosed[0][2]){
+ wgeom_return[0]->x=x2[1];
+ wgeom_return[0]->width-=x2[1]-x1[0];
+ }
+ else if(enclosed[0][3]&&enclosed[0][1])
+ wgeom_return[0]->width-=x1[1]-x2[0];
+ else if(enclosed[0][3]&&enclosed[0][2])
+ wgeom_return[0]->height-=y1[1]-y2[0];
+ return -1;
+
+ }
+ else if(tot2==1){//in which case there is also tot1==1 but we rather not break that
+ //break geom2 in two
+// wgeom_return[0]=(WGeometry *)malloc(sizeof(WGeometry));
+// wgeom_return[1]=(WGeometry *)malloc(sizeof(WGeometry));
+ *ngeoms=2;
+ if(enclosed[1][0]){
+//first
+ wgeom_return[0]->x=x1[1];
+ wgeom_return[0]->y=y2[0];
+ wgeom_return[0]->width=wgeom2->width-x1[1]+x2[0];
+ wgeom_return[0]->height=wgeom2->height;
+//second
+ wgeom_return[1]->x=x2[0];
+ wgeom_return[1]->y=y1[1];
+ wgeom_return[1]->width=x1[1]-x2[0];
+ wgeom_return[1]->height=wgeom2->height-y1[1]+y2[0];
+ }
+ else if(enclosed[1][1]){
+//first
+ wgeom_return[0]->x=x2[0];
+ wgeom_return[0]->y=y2[0];
+ wgeom_return[0]->width=wgeom2->width-x2[1]+x1[0];
+ wgeom_return[0]->height=wgeom2->height;
+//second
+ wgeom_return[1]->x=x1[0];
+ wgeom_return[1]->y=y1[1];
+ wgeom_return[1]->width=x2[1]-x1[0];
+ wgeom_return[1]->height=wgeom2->height-y1[1]+y2[0];
+ }
+ else if(enclosed[1][2]){
+//first(same as [1][0])
+ wgeom_return[0]->x=x1[1];
+ wgeom_return[0]->y=y2[0];
+ wgeom_return[0]->width=wgeom2->width-x1[1]+x2[0];
+ wgeom_return[0]->height=wgeom2->height;
+//second
+ wgeom_return[1]->x=x2[0];
+ wgeom_return[1]->y=y2[0];
+ wgeom_return[1]->width=x1[1]-x2[0];
+ wgeom_return[1]->height=wgeom2->height-y2[1]+y1[0];
+ }
+ else if(enclosed[1][3]){
+//first(same as [1][1])
+ wgeom_return[0]->x=x2[0];
+ wgeom_return[0]->y=y2[0];
+ wgeom_return[0]->width=wgeom2->width-x2[1]+x1[0];
+ wgeom_return[0]->height=wgeom2->height;
+//second
+ wgeom_return[1]->x=x1[0];
+ wgeom_return[1]->y=y2[0];
+ wgeom_return[1]->width=x2[1]-x1[0];
+ wgeom_return[1]->height=wgeom2->height-y2[1]+y1[0];
+ }
+ return -2;
+ }
+ else{//polygons collide but no point of one is in the other
+ //so we just keep the two parts of geom2 that are outside geom1
+
+ //break geom2 in two
+ //two cases:
+ //geom2 crossing vertically geom1
+ //and geom2 crossing horizontally geom1
+ //The proper one can be found by simply checking x,y positions
+// wgeom_return[0]=(WGeometry *)malloc(sizeof(WGeometry));
+// wgeom_return[1]=(WGeometry *)malloc(sizeof(WGeometry));
+ *ngeoms=2;
+ if(wgeom2->y<wgeom1->y){
+ //common
+ wgeom_return[0]->x=wgeom_return[1]->x=x2[0];
+ wgeom_return[0]->width=wgeom_return[1]->width=wgeom2->width;
+
+ wgeom_return[0]->y=y2[0];
+ wgeom_return[0]->height=wgeom2->height-y2[1]+y1[0];
+ wgeom_return[1]->y=y1[1];
+ wgeom_return[1]->height=y2[1]-y1[1];
+ }
+ else{
+ //common
+ wgeom_return[0]->y=wgeom_return[1]->y=y2[0];
+ wgeom_return[0]->height=wgeom_return[1]->height=wgeom2->height;
+
+ wgeom_return[0]->x=x2[0];
+ wgeom_return[0]->width=wgeom2->width-x2[1]+x1[0];
+ wgeom_return[1]->x=x1[1];
+ wgeom_return[1]->width=x2[1]-x1[1];
+ }
+ return -2;
+ }
+ }
+}
+
+int RectInsert(RectArea **root,WGeometry *wgeom){
+
+ int total_insertions=0;
+ RectArea *temp=NULL,*newnode=(RectArea *)malloc(sizeof(RectArea));
+ //align
+ //we do need to know boundaries
+ wgeom->width+=(wgeom->width%2)|(wgeom->x%2);
+ wgeom->height+=(wgeom->height%2)|(wgeom->y%2);
+ wgeom->width+=(wgeom->width%2);
+ wgeom->height+=(wgeom->height%2);
+ wgeom->x-=wgeom->x%2;
+ wgeom->y-=wgeom->y%2;
+// fprintf(stderr," %d %d %d %d\n",wgeom->x,
+
+ newnode->geom.x=wgeom->x;
+ newnode->geom.y=wgeom->y;
+ newnode->geom.width=wgeom->width;
+ newnode->geom.height=wgeom->height;
+ newnode->prev=newnode->next=NULL;
+ if(*root==NULL){
+ *root=newnode;
+ total_insertions=1;
+ }
+ else{
+ WGeometry *wgeom_return[2];
+ wgeom_return[0]=(WGeometry *)malloc(sizeof(WGeometry));
+ wgeom_return[1]=(WGeometry *)malloc(sizeof(WGeometry));
+
+ int ngeoms=0,insert_ok=1,i=0;
+ temp=*root;
+ while(insert_ok){//if something is broken list does not procceed(except on -1 collres case)
+ int collres/*=0;//*/=CollideRects(&(temp->geom),wgeom,wgeom_return,&ngeoms);
+ if((!collres))
+ insert_ok=1;
+ else{
+ for(i=0;i<ngeoms;i++){
+ wgeom_return[i]->width+=(wgeom_return[i]->width%2)|(wgeom_return[i]->x%2);
+ wgeom_return[i]->height+=(wgeom_return[i]->height%2)|(wgeom_return[i]->y%2);
+ wgeom_return[i]->width+=(wgeom_return[i]->width%2);
+ wgeom_return[i]->height+=(wgeom_return[i]->height%2);
+ wgeom_return[i]->x-=wgeom_return[i]->x%2;
+ wgeom_return[i]->y-=wgeom_return[i]->y%2;
+ }
+ insert_ok=0;
+ switch(collres){
+ case 1://remove current node,reinsert new one
+ total_insertions--;
+ if(temp->prev!=NULL){//no root
+ if(temp->next!=NULL){//
+ RectArea *temp1=temp->next;
+ temp->prev->next=temp->next;
+ temp->next->prev=temp->prev;
+ free(temp);
+ if((wgeom->width>0)&&(wgeom->height>0))
+ total_insertions+=RectInsert(&temp1,wgeom);
+ }
+ else{
+ temp->prev->next=newnode;
+ newnode->prev=temp->prev;
+ total_insertions++;
+ free(temp);
+ }
+ }
+ else{//root
+ if((*root)->next!=NULL){
+ (*root)=(*root)->next;
+ (*root)->prev=NULL;
+ if((wgeom->width>0)&&(wgeom->height>0))
+ total_insertions+=RectInsert(root,wgeom);
+ }
+ else if((wgeom->width>0)&&(wgeom->height>0)){
+ *root=newnode;
+ total_insertions++;
+ }
+ else{
+ *root=NULL;
+ total_insertions++;
+ }
+ free(temp);
+ }
+ break;
+ case 2://done,area is already covered
+ free(newnode);
+ break;
+ case -1://current node is broken and reinserted(in same pos)
+ //newnode is also reinserted
+ if((wgeom_return[0]->width>0)&&(wgeom_return[0]->height>0)){
+ temp->geom.x=wgeom_return[0]->x;
+ temp->geom.y=wgeom_return[0]->y;
+ temp->geom.width=wgeom_return[0]->width;
+ temp->geom.height=wgeom_return[0]->height;
+ if(temp->next==NULL){
+ temp->next=newnode;
+ newnode->prev=temp;
+ total_insertions++;
+ }
+ else{
+ insert_ok=1;
+ }
+ }
+ else{//it might happen that the old and now broken node
+ //is of zero width or height(so it isn't reinserted)
+ /*TODO this may cause lines to be left not updated
+ so maybe it is needed to increase the size by one
+ pixel(zero width or height cause BadValue*/
+ if((temp->prev==NULL)&&(temp->next!=NULL)){
+ *root=(*root)->next;
+ (*root)->prev=NULL;
+ }
+ else if((temp->next==NULL)&&(temp->prev!=NULL)){
+ temp->prev->next=newnode;
+ newnode->prev=temp->prev;
+ }
+ else if((temp->next==NULL)&&(temp->prev==NULL))
+ (*root)=newnode;
+ else{
+ total_insertions--;
+ temp->next->prev=temp->prev;
+ temp->prev->next=temp->next;
+ total_insertions+=RectInsert(&temp->next,wgeom);
+ }
+ free(temp);
+ }
+ break;
+ case -2://new is broken and reinserted
+ if(temp->next==NULL){
+ total_insertions+=ngeoms;
+ newnode->geom.x=wgeom_return[0]->x;
+ newnode->geom.y=wgeom_return[0]->y;
+ newnode->geom.width=wgeom_return[0]->width;
+ newnode->geom.height=wgeom_return[0]->height;
+ temp->next=newnode;
+ newnode->prev=temp;
+ if(ngeoms>1){
+ RectArea *newnode1=(RectArea *)malloc(sizeof(RectArea));
+ newnode1->geom.x=wgeom_return[1]->x;
+ newnode1->geom.y=wgeom_return[1]->y;
+ newnode1->geom.width=wgeom_return[1]->width;
+ newnode1->geom.height=wgeom_return[1]->height;
+ newnode->next=newnode1;
+ newnode1->prev=newnode;
+ newnode1->next=NULL;
+ }
+ }
+ else{
+ for(i=0;i<ngeoms;i++){
+ if((wgeom_return[i]->width>0)&&(wgeom_return[i]->height>0))
+ total_insertions+=RectInsert(&temp->next,wgeom_return[i]);
+ }
+ }
+ break;
+ case -10://grouped
+ if(temp->prev==NULL){
+ if(temp->next==NULL){//empty list
+ newnode->geom.x=wgeom_return[0]->x;
+ newnode->geom.y=wgeom_return[0]->y;
+ newnode->geom.width=wgeom_return[0]->width;
+ newnode->geom.height=wgeom_return[0]->height;
+ *root=newnode;
+ free(temp);
+ }
+ else{
+ total_insertions--;
+ *root=temp->next;
+ (*root)->prev=NULL;
+ free(temp);
+ if((wgeom_return[0]->width>0)&&(wgeom_return[0]->height>0))
+ total_insertions+=RectInsert(root,wgeom_return[0]);
+ }
+ }
+ else if(temp->next==NULL){//last, enter anyway
+ newnode->geom.x=wgeom_return[0]->x;
+ newnode->geom.y=wgeom_return[0]->y;
+ newnode->geom.width=wgeom_return[0]->width;
+ newnode->geom.height=wgeom_return[0]->height;
+ temp->prev->next=newnode;
+ newnode->prev=temp->prev;
+ free(temp);
+ }
+ else{//remove node and reinsert, starting where we were
+ total_insertions--;
+ RectArea *temp1=temp->next;
+ temp->prev->next=temp->next;
+ temp->next->prev=temp->prev;
+ free(temp);
+ if((wgeom_return[0]->width>0)&&(wgeom_return[0]->height>0))
+ total_insertions+=RectInsert(&temp1,wgeom_return[0]);
+ }
+ break;
+ }
+ }
+ if(insert_ok){
+ if(temp->next==NULL){
+ temp->next=newnode;
+ newnode->prev=temp;
+ total_insertions++;
+ break;
+ }
+ else{
+ temp=temp->next;
+ }
+ }
+ else{
+ break;
+ }
+ };
+
+ free(wgeom_return[0]);
+ free(wgeom_return[1]);
+ }
+ return total_insertions;
+}
+
+void ClearList(RectArea **root){
+
+ RectArea *temp;
+ temp=*root;
+ if(temp!=NULL){
+ while(temp->next!=NULL){
+ temp=temp->next;
+ free(temp->prev);
+
+ }
+ free(temp);
+ *root=NULL;
+ }
+}
+
diff --git a/rMD-exp/src/register_callbacks.c b/rMD-exp/src/register_callbacks.c
new file mode 100644
index 0000000..677fc75
--- /dev/null
+++ b/rMD-exp/src/register_callbacks.c
@@ -0,0 +1,81 @@
+/*********************************************************************************
+* 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 SetExpired(int signum){
+ frames_total++;
+ if(capture_busy){
+ frames_lost++;
+ }
+ pthread_cond_broadcast(time_cond);//sig handlers should not call this func
+ //could be a set_expired and main thread
+ //doing a while(running) if set_expired broadcast else usleep(n)
+}
+
+void SetPaused(int signum){
+ if(!Paused)
+ Paused=1;
+ else{
+// pthread_cond_broadcast(pause_cond);//thsi should work, but it doesn't
+ int i;//this is a bug
+ Paused=0;//normally with the broadcast all the threads should restart, but sound capture thread
+ for(i=0;i<15;i++)//remains dead. If a bunch of signals, restarts all threads, why can't a broadcast do the same?
+ pthread_cond_signal(pause_cond);//if you have any idea please contact me.
+ //(misses the signal?)
+ }
+}
+
+
+void SetRunning(int signum){
+ *Running=0;
+ if(signum==SIGABRT)
+ Aborted=1;
+}
+
+void RegisterCallbacks(ProgArgs *args){
+
+ struct itimerval value;
+ struct sigaction time_act,pause_act,end_act;
+
+
+ value.it_interval.tv_sec=value.it_value.tv_sec=0;
+ value.it_interval.tv_usec=value.it_value.tv_usec=(1000000)/args->fps;
+ setitimer(ITIMER_REAL,&value,NULL);
+ time_act.sa_handler=SetExpired;
+ pause_act.sa_handler=SetPaused;
+ end_act.sa_handler=SetRunning;
+ sigfillset(&(time_act.sa_mask));
+ sigfillset(&(pause_act.sa_mask));
+ sigfillset(&(end_act.sa_mask));
+ time_act.sa_flags=pause_act.sa_flags=end_act.sa_flags=0;
+ sigaction(SIGALRM,&time_act,NULL);
+ sigaction(SIGUSR1,&pause_act,NULL);
+ sigaction(SIGINT,&end_act,NULL);
+ sigaction(SIGTERM,&end_act,NULL);
+ sigaction(SIGABRT,&end_act,NULL);
+}
+
diff --git a/rMD-exp/src/setbrwindow.c b/rMD-exp/src/setbrwindow.c
new file mode 100644
index 0000000..58dc34c
--- /dev/null
+++ b/rMD-exp/src/setbrwindow.c
@@ -0,0 +1,176 @@
+/*********************************************************************************
+* 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 SizePack2_8_16(int *start,int *size,int limit){
+ int octoffset,hexoffset;
+
+ //align in two
+ //an odd x can always go down and still be in recording area.
+ //Resolutions come in even numbers
+ //so if x is an odd numer, width max is an odd number, too
+ //thus since x will go down one then width can go up one too and still
+ //be inbounds
+ (*size)+=((*size)%2)|((*start)%2);
+ //but if x goes down 1 and width is already even,it becomes odd so:
+ (*size)+=((*size)%2);
+ (*start)-=(*start)%2;
+
+
+ //32 bit pack align
+ //we already have disible by two width,so
+ //it's 2, 4 or 6
+ octoffset=((*size)%8);
+ if(octoffset==2){
+ (*size)-=2;
+
+ }
+ else if(octoffset==6){
+ if((*size)+(*start)+2<=limit)
+ (*size)+=2;
+ else if((*start)>=2){
+ (*start)-=2;
+ (*size)+=2;
+ }
+ else{
+ (*start)+=2;
+ (*size)-=4;
+ }
+ }
+
+ else if(octoffset==4){
+ if(((*size)+(*start)+2<=limit)&&((*start)>=2)){
+ (*start)-=2;
+ (*size)+=4;
+ }
+ else if((*size)+(*start)+4<=limit){
+ (*size)+=4;
+ }
+ else if((*start)>=4){
+ (*start)-=4;
+ (*size)+=4;
+ }
+ else{
+ (*start)+=2;
+ (*size)-=4;
+ }
+ }
+
+ //16 divisble width(needed for shared memory only,but applied anyway since theora wants it, too)
+ //we already have divisibility by 8 so module
+ //by 16 is euther 8 or 0
+ hexoffset=((*size)%16);
+ if(hexoffset){
+ if(((*size)+(*start)+4<=limit)&&((*start)>=4)){
+ (*start)-=4;
+ (*size)+=8;
+ }
+ else if((*size)+(*start)+8<=limit){
+ (*size)+=8;
+ }
+ else if((*start)>=8){
+ (*start)-=8;
+ (*size)+=8;
+ }
+ else{
+ (*start)+=4;
+ (*size)-=8;
+ }
+ }
+
+}
+
+
+
+int SetBRWindow(Display *dpy,BRWindow *brwin,DisplaySpecs *specs,ProgArgs *args){
+ //before we start recording we have to make sure the ranges are valid
+ if(args->windowid==0){//root window
+ //first set it up
+ brwin->windowid=specs->root;
+ brwin->geom.x=brwin->geom.y=0;
+ brwin->geom.width=specs->width;
+ brwin->geom.height=specs->height;
+ brwin->rgeom.x=args->x;
+ brwin->rgeom.y=args->y;
+ brwin->rgeom.width=((args->width)?args->width:specs->width-brwin->rgeom.x);
+ brwin->rgeom.height=((args->height)?args->height:specs->height-brwin->rgeom.y);
+ //and then check validity
+ if((brwin->rgeom.x+brwin->rgeom.width>specs->width)||
+ (brwin->rgeom.y+brwin->rgeom.height>specs->height)){
+ fprintf(stderr,"Window size specification out of bounds!(current resolution:%dx%d)\n",specs->width,specs->height);
+ return 1;
+ }
+ }
+ else{
+ Window wchid;
+ int transl_x,transl_y;
+
+ XWindowAttributes attribs;
+ XGetWindowAttributes(dpy,args->windowid,&attribs);
+ if((attribs.map_state==IsUnviewable)||(attribs.map_state==IsUnmapped)){
+ fprintf(stderr,"Window must be mapped and visible!\n");
+ return 1;
+ }
+ XTranslateCoordinates(dpy,specs->root,args->windowid,attribs.x,attribs.y,&transl_x,&transl_y,&wchid);
+ brwin->windowid=specs->root;
+ brwin->geom.x=attribs.x-transl_x;
+ brwin->geom.y=attribs.y-transl_y;
+ brwin->geom.width=attribs.width;
+ brwin->geom.height=attribs.height;
+ if((brwin->geom.x+brwin->geom.width>specs->width)||
+ (brwin->geom.y+brwin->geom.height>specs->height)){
+ fprintf(stderr,"Window must be on visible screen area!\n");
+ return 1;
+ }
+
+ brwin->rgeom.x=brwin->geom.x+args->x;
+ brwin->rgeom.y=brwin->geom.y+args->y;
+ brwin->rgeom.width=((args->width)?args->width:brwin->geom.width-args->x);
+ brwin->rgeom.height=((args->height)?args->height:brwin->geom.height-args->y);
+ if((args->x+brwin->rgeom.width>brwin->geom.width)||
+ (args->y+brwin->rgeom.height>brwin->geom.height)){
+ fprintf(stderr,"Specified Area is larger than window!\n");
+ return 1;
+ }
+ }
+ fprintf(stderr, "Initial recording window is set to:\n"
+ "X:%d Y:%d Width:%d Height:%d\n"
+ ,brwin->rgeom.x,brwin->rgeom.y,brwin->rgeom.width,brwin->rgeom.height);
+ SizePack2_8_16(&brwin->rgeom.x,&brwin->rgeom.width,specs->width);
+ SizePack2_8_16(&brwin->rgeom.y,&brwin->rgeom.height,specs->height);
+
+ fprintf(stderr, "Adjusted recording window is set to:\n"
+ "X:%d Y:%d Width:%d Height:%d\n"
+ ,brwin->rgeom.x,brwin->rgeom.y,brwin->rgeom.width,brwin->rgeom.height);
+
+
+
+ brwin->nbytes=(((brwin->rgeom.width+15)>>4)<<4)*(((brwin->rgeom.height+15)>>4)<<4)*4;
+
+
+ return 0;
+}
diff --git a/rMD-exp/src/update_image.c b/rMD-exp/src/update_image.c
new file mode 100644
index 0000000..2725011
--- /dev/null
+++ b/rMD-exp/src/update_image.c
@@ -0,0 +1,86 @@
+/*********************************************************************************
+* 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 UpdateImage(Display * dpy,
+ yuv_buffer *yuv,
+ pthread_mutex_t *yuv_mutex,
+ DisplaySpecs *specs,
+ RectArea **root,
+ BRWindow *brwin,
+ EncData *enc,
+ char *datatemp,
+ int noshmem,
+ int no_quick_subsample){
+ RectArea *temp;
+ unsigned char *dtap=(unsigned char*)datatemp;
+ temp=*root;
+
+ if(temp!=NULL){
+ do{
+ if(noshmem){
+ GetZPixmap( dpy,
+ specs->root,
+ datatemp,
+ temp->geom.x,
+ temp->geom.y,
+ temp->geom.width,
+ temp->geom.height);
+
+ pthread_mutex_lock(yuv_mutex);
+ if(no_quick_subsample){
+ UPDATE_YUV_BUFFER_IM_AVG(yuv,dtap,
+ (temp->geom.x-brwin->rgeom.x+enc->x_offset),(temp->geom.y-brwin->rgeom.y+enc->y_offset),
+ (temp->geom.width),(temp->geom.height));
+ }
+ else{
+ UPDATE_YUV_BUFFER_IM(yuv,dtap,
+ (temp->geom.x-brwin->rgeom.x+enc->x_offset),(temp->geom.y-brwin->rgeom.y+enc->y_offset),
+ (temp->geom.width),(temp->geom.height));
+ }
+
+ pthread_mutex_unlock(yuv_mutex);
+ }
+ else{
+ if(no_quick_subsample){
+ UPDATE_YUV_BUFFER_SH_AVG(yuv,dtap,
+ (temp->geom.x-brwin->rgeom.x+enc->x_offset),(temp->geom.y-brwin->rgeom.y+enc->y_offset),
+ (temp->geom.width),(temp->geom.height));
+ }
+ else{
+ UPDATE_YUV_BUFFER_SH(yuv,dtap,
+ (temp->geom.x-brwin->rgeom.x+enc->x_offset),(temp->geom.y-brwin->rgeom.y+enc->y_offset),
+ (temp->geom.width),(temp->geom.height));
+ }
+
+ }
+ temp=temp->next;
+ }while(temp!=NULL);
+ }
+}
+
diff --git a/rMD-exp/src/zpixmaptobmp.c b/rMD-exp/src/zpixmaptobmp.c
new file mode 100644
index 0000000..0aa9477
--- /dev/null
+++ b/rMD-exp/src/zpixmaptobmp.c
@@ -0,0 +1,78 @@
+/*********************************************************************************
+* 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 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);
+ }
+ }
+
+ fclose(fpbmp);
+ return 0;
+}
+
+
© All Rights Reserved