From b97fd0333d1faf11675c2ec522979ee1ba81a524 Mon Sep 17 00:00:00 2001 From: iovar Date: Wed, 5 Dec 2007 17:50:09 +0000 Subject: moved pause cond signaling to rmd_timer thread (was in signal handler) git-svn-id: https://recordmydesktop.svn.sourceforge.net/svnroot/recordmydesktop/trunk@458 f606c939-3180-4ac9-a4b8-4b8779d57d0a --- recordmydesktop/src/initialize_data.c | 1 + recordmydesktop/src/register_callbacks.c | 24 ++++-------------------- recordmydesktop/src/rmd_timer.c | 27 +++++++++++++++++++++++++-- 3 files changed, 30 insertions(+), 22 deletions(-) (limited to 'recordmydesktop/src') diff --git a/recordmydesktop/src/initialize_data.c b/recordmydesktop/src/initialize_data.c index 6e363f6..a3566ba 100644 --- a/recordmydesktop/src/initialize_data.c +++ b/recordmydesktop/src/initialize_data.c @@ -88,6 +88,7 @@ int InitializeData(ProgData *pdata, time_cond=&pdata->time_cond; pause_cond=&pdata->pause_cond; Running=&pdata->running; + PauseStateChanged=0; if(!pdata->args.nosound){ if(!pdata->args.use_jack){ diff --git a/recordmydesktop/src/register_callbacks.c b/recordmydesktop/src/register_callbacks.c index a0d2552..c5d22d1 100644 --- a/recordmydesktop/src/register_callbacks.c +++ b/recordmydesktop/src/register_callbacks.c @@ -28,25 +28,9 @@ #include void SetPaused(int signum){ - if(!Paused){ - Paused=1; - fprintf(stderr,"STATE:PAUSED\n"); - } - else{ - Paused=0; - fprintf(stderr,"STATE:RECORDING\n"); -/*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(&pause_mutex); - pthread_cond_broadcast(pause_cond); - pthread_mutex_unlock(&pause_mutex); - } + + PauseStateChanged=1; + } @@ -60,7 +44,7 @@ void SetRunning(int signum){ void RegisterCallbacks(ProgArgs *args){ struct sigaction pause_act,end_act; - + pause_act.sa_handler=SetPaused; end_act.sa_handler=SetRunning; sigfillset(&(pause_act.sa_mask)); diff --git a/recordmydesktop/src/rmd_timer.c b/recordmydesktop/src/rmd_timer.c index ff1fc9b..da26f18 100644 --- a/recordmydesktop/src/rmd_timer.c +++ b/recordmydesktop/src/rmd_timer.c @@ -35,10 +35,30 @@ void *rmdTimer(ProgData *pdata){ - + + long unsigned int secs_tw=1/pdata->args.fps; + long unsigned int usecs_tw=(1000000)/pdata->args.fps- + secs_tw*1000000; while(pdata->timer_alive){ + if(PauseStateChanged){ + PauseStateChanged=0; + + if(!Paused){ + Paused=1; + fprintf(stderr,"STATE:PAUSED\n"); + } + else{ + Paused=0; + fprintf(stderr,"STATE:RECORDING\n"); + pthread_mutex_lock(&pause_mutex); + pthread_cond_broadcast(pause_cond); + pthread_mutex_unlock(&pause_mutex); + } + + } + if(!Paused){ frames_total++; if(capture_busy){ @@ -48,7 +68,10 @@ void *rmdTimer(ProgData *pdata){ pthread_cond_broadcast(time_cond); pthread_mutex_unlock(&time_mutex); } - usleep(pdata->frametime); + + if(secs_tw) + sleep(secs_tw); + usleep(usecs_tw); } -- cgit v1.2.1