summaryrefslogtreecommitdiff
path: root/recordmydesktop
diff options
context:
space:
mode:
Diffstat (limited to 'recordmydesktop')
-rw-r--r--recordmydesktop/include/rmdfunc.h24
-rw-r--r--recordmydesktop/include/rmdtypes.h1
-rw-r--r--recordmydesktop/src/Makefile.am4
-rw-r--r--recordmydesktop/src/register_callbacks.c41
-rw-r--r--recordmydesktop/src/rmd_timer.c60
-rw-r--r--recordmydesktop/src/rmdthreads.c12
6 files changed, 89 insertions, 53 deletions
diff --git a/recordmydesktop/include/rmdfunc.h b/recordmydesktop/include/rmdfunc.h
index dad87dd..f230287 100644
--- a/recordmydesktop/include/rmdfunc.h
+++ b/recordmydesktop/include/rmdfunc.h
@@ -44,6 +44,16 @@
void *PollEvents(ProgData *pdata);
/**
+* Loop ,signal timer cond var,sleep-\
+* ^ |
+* |________________________________/
+*
+*
+* \param pdata ProgData struct containing all program data
+*/
+void *rmdTimer(ProgData *pdata);
+
+/**
* Retrieve frame form xserver, and transform to a yuv buffer,
* either directly(full shots) or by calling UpdateImage.
* \param pdata ProgData struct containing all program data
@@ -113,13 +123,6 @@ int CollideRects(WGeometry *wgeom1,
WGeometry **wgeom_return,
int *ngeoms);
-/**
-* Broadcast time condition variable, increment frame count.
-*
-* \param signum Number of signal received(unused, always SIGALRM)
-*
-*/
-void SetExpired(int signum);
/**
* Set up all callbacks and signal handlers
@@ -445,10 +448,6 @@ void *LoadCache(ProgData *pdata);
*/
void SyncEncodeImageBuffer(ProgData *pdata);
-/**
-* Stop the timer
-*/
-void CancelTimer(void);
/**
* As EncodeSoundBuffer, only with the assumption that
@@ -791,6 +790,9 @@ void rmdDrawFrame(Display *dpy,
Window win,
int width,
int height);
+
+
+
#endif
diff --git a/recordmydesktop/include/rmdtypes.h b/recordmydesktop/include/rmdtypes.h
index 317e8c5..d7096ba 100644
--- a/recordmydesktop/include/rmdtypes.h
+++ b/recordmydesktop/include/rmdtypes.h
@@ -332,6 +332,7 @@ typedef struct _ProgData{
v_encoding_clean, // >> >>
v_enc_thread_waiting, //these indicate a wait
th_enc_thread_waiting, //condition on the cond vars.
+ timer_alive, //determines loop of timer thread
hard_pause, //if sound device doesn't support pause
//we have to close and reopen
avd; //syncronization among audio and video
diff --git a/recordmydesktop/src/Makefile.am b/recordmydesktop/src/Makefile.am
index 177cafe..a3a18ba 100644
--- a/recordmydesktop/src/Makefile.am
+++ b/recordmydesktop/src/Makefile.am
@@ -33,7 +33,9 @@ recordmydesktop_SOURCES= recordmydesktop.c\
specsfile.c\
shortcuts.c\
rmd_error.c\
- rmd_frame.c
+ rmd_frame.c\
+ rmd_timer.c
+
INCLUDES= $(all_includes) -I$(top_srcdir)/include
diff --git a/recordmydesktop/src/register_callbacks.c b/recordmydesktop/src/register_callbacks.c
index 8db5d5d..cd6efe4 100644
--- a/recordmydesktop/src/register_callbacks.c
+++ b/recordmydesktop/src/register_callbacks.c
@@ -26,25 +26,6 @@
#include <recordmydesktop.h>
-void SetExpired(int signum){
- if(!Paused){
- frames_total++;
- if(capture_busy){
- frames_lost++;
- }
-/*FIXME */
-//This is not safe.
-//cond_var signaling must move away from signal handlers
-//alltogether (JackCapture, SetExpired, SetPaused).
-//Better would be a set of pipes for each of these.
-//The callback should write on the pipe and the main thread
-//should perform a select over the fd's, signaling afterwards the
-//appropriate cond_var.
- pthread_mutex_lock(&time_mutex);
- pthread_cond_broadcast(time_cond);
- pthread_mutex_unlock(&time_mutex);
- }
-}
void SetPaused(int signum){
if(!Paused){
@@ -75,34 +56,16 @@ void SetRunning(int signum){
Aborted=1;
}
-void CancelTimer(void){
- struct itimerval value;
- value.it_interval.tv_sec=
- value.it_value.tv_sec=
- value.it_interval.tv_usec=
- value.it_value.tv_usec=0;
-
- setitimer(ITIMER_REAL,&value,NULL);
-}
void RegisterCallbacks(ProgArgs *args){
- struct itimerval value;
- struct sigaction time_act,pause_act,end_act;
-
+ struct sigaction pause_act,end_act;
- value.it_interval.tv_sec=value.it_value.tv_sec=1/args->fps;
- value.it_interval.tv_usec=value.it_value.tv_usec=(1000000)/args->fps-value.it_value.tv_sec*1000000;
-
- 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);
+ pause_act.sa_flags=end_act.sa_flags=0;
sigaction(SIGUSR1,&pause_act,NULL);
sigaction(SIGINT,&end_act,NULL);
sigaction(SIGTERM,&end_act,NULL);
diff --git a/recordmydesktop/src/rmd_timer.c b/recordmydesktop/src/rmd_timer.c
new file mode 100644
index 0000000..ff1fc9b
--- /dev/null
+++ b/recordmydesktop/src/rmd_timer.c
@@ -0,0 +1,60 @@
+/******************************************************************************
+* recordMyDesktop *
+*******************************************************************************
+* *
+* Copyright (C) 2006,2007 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 *
+******************************************************************************/
+
+
+#ifdef HAVE_CONFIG_H
+ #include <config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <recordmydesktop.h>
+
+
+void *rmdTimer(ProgData *pdata){
+
+
+ while(pdata->timer_alive){
+
+ if(!Paused){
+ frames_total++;
+ if(capture_busy){
+ frames_lost++;
+ }
+ pthread_mutex_lock(&time_mutex);
+ pthread_cond_broadcast(time_cond);
+ pthread_mutex_unlock(&time_mutex);
+ }
+ usleep(pdata->frametime);
+
+ }
+
+
+ pthread_exit(&errno);
+}
+
+
+
diff --git a/recordmydesktop/src/rmdthreads.c b/recordmydesktop/src/rmdthreads.c
index f8e9ef4..a1b8e53 100644
--- a/recordmydesktop/src/rmdthreads.c
+++ b/recordmydesktop/src/rmdthreads.c
@@ -46,7 +46,8 @@ void rmdThreads(ProgData *pdata){
sound_capture_t,
sound_encode_t,
sound_cache_t,
- flush_to_ogg_t;
+ flush_to_ogg_t,
+ timer_t;
Window dummy_w;
if(pdata->args.delay>0){
@@ -98,6 +99,11 @@ void rmdThreads(ProgData *pdata){
(void *)pdata);
RegisterCallbacks(&pdata->args);
+ pdata->timer_alive=1;
+ pthread_create(&timer_t,
+ NULL,
+ (void *)rmdTimer,
+ (void *)pdata);
fprintf(stderr,"Capturing!\n");
#ifdef HAVE_JACK_H
if(pdata->args.use_jack){
@@ -176,6 +182,8 @@ void rmdThreads(ProgData *pdata){
pthread_join(poll_events_t,NULL);
//Now that we are done with recording we cancel the timer
- CancelTimer();
+ pdata->timer_alive=0;
+ pthread_join(timer_t,NULL);
+
}
© All Rights Reserved