diff options
author | enselic <enselic@f606c939-3180-4ac9-a4b8-4b8779d57d0a> | 2008-09-13 11:39:35 +0000 |
---|---|---|
committer | enselic <enselic@f606c939-3180-4ac9-a4b8-4b8779d57d0a> | 2008-09-13 11:39:35 +0000 |
commit | 3f5d20573bd0aac953bd2db2d72997ff44365caf (patch) | |
tree | bc66789419ca93091b30ab16adefafe02661dc52 | |
parent | e2e84c980f5e6f3cdec3fe2c09fc33b8f4c03f39 (diff) |
The global int pointer 'Running' is just a hack for global access of
ProgData::running. We can get rid of this global.
include/rmdtypes.h: Put ProgData in JackData so that the libjack stuff
can access progam state.
src/recordmydesktop.c: Initialize ProgData member of JackData.
src/rmd_jack.c: Use ProgData instead of the global.
src/register_callbacks.[ch]: Pass ProgData to the registering of
signal handlers and put a local version of the Running-global hack in
this file.
src/rmd_rescue.c: Get rid of Running-logic and pass ProgData to
RegisterCallbacks()
src/rmdthreads.c: Pass ProgData to RegisterCallbacks()
src/initialize_data.c: Get rid of Running-logic.
include/recordmydesktop.h: Remove the Running-global.
git-svn-id: https://recordmydesktop.svn.sourceforge.net/svnroot/recordmydesktop/trunk@528 f606c939-3180-4ac9-a4b8-4b8779d57d0a
-rw-r--r-- | recordmydesktop/include/recordmydesktop.h | 2 | ||||
-rw-r--r-- | recordmydesktop/include/rmdtypes.h | 8 | ||||
-rw-r--r-- | recordmydesktop/src/initialize_data.c | 1 | ||||
-rw-r--r-- | recordmydesktop/src/recordmydesktop.c | 5 | ||||
-rw-r--r-- | recordmydesktop/src/register_callbacks.c | 14 | ||||
-rw-r--r-- | recordmydesktop/src/register_callbacks.h | 2 | ||||
-rw-r--r-- | recordmydesktop/src/rmd_jack.c | 9 | ||||
-rw-r--r-- | recordmydesktop/src/rmd_rescue.c | 3 | ||||
-rw-r--r-- | recordmydesktop/src/rmdthreads.c | 2 |
9 files changed, 33 insertions, 13 deletions
diff --git a/recordmydesktop/include/recordmydesktop.h b/recordmydesktop/include/recordmydesktop.h index adbc233..1a5c3fa 100644 --- a/recordmydesktop/include/recordmydesktop.h +++ b/recordmydesktop/include/recordmydesktop.h @@ -50,7 +50,7 @@ u_int32_t *yblocks, /**Globals*/ //I've read somewhere that I'll go to hell for using globals... -int Paused,*Running,Aborted,PauseStateChanged; +int Paused, Aborted, PauseStateChanged; pthread_cond_t *time_cond,*pause_cond; pthread_mutex_t pause_mutex,time_mutex; unsigned char Yr[256],Yg[256],Yb[256], diff --git a/recordmydesktop/include/rmdtypes.h b/recordmydesktop/include/rmdtypes.h index 7fdb59b..5d31fda 100644 --- a/recordmydesktop/include/rmdtypes.h +++ b/recordmydesktop/include/rmdtypes.h @@ -103,6 +103,9 @@ typedef int boolean; #define FALSE (0) #define TRUE (!FALSE) +// Forward declarations +typedef struct _ProgData ProgData; + typedef struct _DisplaySpecs{ //this struct holds some basic information int screen; //about the display,needed mostly for unsigned int width; //validity checks at startup @@ -243,6 +246,7 @@ typedef struct _SndBuffer{ #ifdef HAVE_JACK_H typedef struct _JackData{ + ProgData *pdata; //pointer to prog data void *jack_lib_handle; //handle for jack library (loaded with dlopen). jack_client_t *client; unsigned int buffersize, //buffer size for every port in frames. @@ -269,7 +273,7 @@ typedef struct _HotKey{ //Hold info about the shortcuts //It's usage is mostly to be given as an argument to the //threads,so they will have access to the program data, avoiding //at the same time usage of any globals. -typedef struct _ProgData{ +struct _ProgData { /**recordMyDesktop specific structs*/ ProgArgs args; //the program arguments DisplaySpecs specs; //Display specific information @@ -345,7 +349,7 @@ typedef struct _ProgData{ int sound_handle; u_int32_t periodsize; #endif -}ProgData; +}; //This is the header of every frame. diff --git a/recordmydesktop/src/initialize_data.c b/recordmydesktop/src/initialize_data.c index 30a0ab8..df30292 100644 --- a/recordmydesktop/src/initialize_data.c +++ b/recordmydesktop/src/initialize_data.c @@ -112,7 +112,6 @@ int InitializeData(ProgData *pdata, pdata->running=1; time_cond=&pdata->time_cond; pause_cond=&pdata->pause_cond; - Running=&pdata->running; PauseStateChanged=0; if(!pdata->args.nosound){ diff --git a/recordmydesktop/src/recordmydesktop.c b/recordmydesktop/src/recordmydesktop.c index 8c46ab7..e2b394e 100644 --- a/recordmydesktop/src/recordmydesktop.c +++ b/recordmydesktop/src/recordmydesktop.c @@ -58,7 +58,10 @@ int main(int argc,char **argv){ CacheData cache_data; #ifdef HAVE_JACK_H JackData jdata; - pdata.jdata=&jdata; + + // Give jack access to program data, mainly for program state + jdata.pdata = &pdata; + pdata.jdata = &jdata; #endif // Query display specs diff --git a/recordmydesktop/src/register_callbacks.c b/recordmydesktop/src/register_callbacks.c index 79ee3fe..c16f7b1 100644 --- a/recordmydesktop/src/register_callbacks.c +++ b/recordmydesktop/src/register_callbacks.c @@ -30,6 +30,11 @@ #include "register_callbacks.h" +// There seem to be no way of passing user data to the signal handler, +// so hack around not being able to pass ProgData to them +static int *pdata_running = NULL; + + static void SetPaused(int signum) { PauseStateChanged = 1; @@ -39,7 +44,9 @@ static void SetRunning(int signum) { if (!Paused){ - *Running = 0; + if (pdata_running != NULL) { + *pdata_running = 0; + } if (signum == SIGABRT) { Aborted = 1; @@ -47,11 +54,14 @@ static void SetRunning(int signum) { } } -void RegisterCallbacks(ProgArgs *prog_data) { +void RegisterCallbacks(ProgData *pata) { struct sigaction pause_act; struct sigaction end_act; + // Is there some way to pass pata to the signal handlers? + pdata_running = &pata->running; + // Setup pause_act sigfillset(&pause_act.sa_mask); pause_act.sa_flags = SA_RESTART; diff --git a/recordmydesktop/src/register_callbacks.h b/recordmydesktop/src/register_callbacks.h index a0a4522..1fb3b76 100644 --- a/recordmydesktop/src/register_callbacks.h +++ b/recordmydesktop/src/register_callbacks.h @@ -35,7 +35,7 @@ * Set up all callbacks and signal handlers * \param pdata ProgData struct containing all program data */ -void RegisterCallbacks(ProgArgs *args); +void RegisterCallbacks(ProgData *prog_data); #endif diff --git a/recordmydesktop/src/rmd_jack.c b/recordmydesktop/src/rmd_jack.c index ed03a8a..1718c09 100644 --- a/recordmydesktop/src/rmd_jack.c +++ b/recordmydesktop/src/rmd_jack.c @@ -91,8 +91,10 @@ static int JackCapture(jack_nframes_t nframes,void *jdata_t) { int i=0; JackData *jdata=(JackData *)jdata_t; - if((!*Running)||(Paused) || (!jdata->capture_started)) + if (!jdata->pdata->running || Paused || !jdata->capture_started) { return 0; + } + for(i= 0;i<jdata->nports;i++) jdata->portbuf[i]=jack_port_get_buffer_p(jdata->ports[i],nframes); //vorbis analysis buffer wants uninterleaved data @@ -206,8 +208,11 @@ static int LoadJackLib(void *jack_lib_handle) { //encode the result(if not on the fly) //an exit cleanly. static void JackShutdown(void *jdata_t) { + JackData *jdata = (JackData *)jdata_t; + + jdata->pdata->running = 0; + fprintf (stderr, "JACK shutdown\n"); - *Running=0; } int StartJackClient(JackData *jdata){ diff --git a/recordmydesktop/src/rmd_rescue.c b/recordmydesktop/src/rmd_rescue.c index 827a004..f49cd1b 100644 --- a/recordmydesktop/src/rmd_rescue.c +++ b/recordmydesktop/src/rmd_rescue.c @@ -111,9 +111,8 @@ int rmdRescue(const char *path){ Aborted=pdata.avd=0; pdata.sound_buffer=NULL; pdata.running=1; - Running=&pdata.running; - RegisterCallbacks(NULL); + RegisterCallbacks(&pdata); fprintf(stderr,"Restoring %s!!!\n",path); EncodeCache(&pdata); diff --git a/recordmydesktop/src/rmdthreads.c b/recordmydesktop/src/rmdthreads.c index bbdb166..705c383 100644 --- a/recordmydesktop/src/rmdthreads.c +++ b/recordmydesktop/src/rmdthreads.c @@ -92,7 +92,7 @@ void rmdThreads(ProgData *pdata){ (void *)FlushToOgg, (void *)pdata); - RegisterCallbacks(&pdata->args); + RegisterCallbacks(pdata); pdata->timer_alive=1; pthread_create(&timer_t, NULL, |