From 2e5fdc7f842eacce7b41eab794c4bfe97761e381 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Fri, 19 Jun 2020 03:47:43 -0700 Subject: *: just some fast and nasty reformatting If I'm going to actually be modifying this program substantially and possibly maintaining some fork of it, it's gotta be formmatted how I prefer. This is by no means done or perfect, rmd_types.h in particular is quite the mess, I will be revisiting this issue... --- recordmydesktop/src/rmd_jack.c | 218 ++++++++++++++++++++--------------------- 1 file changed, 109 insertions(+), 109 deletions(-) (limited to 'recordmydesktop/src/rmd_jack.c') diff --git a/recordmydesktop/src/rmd_jack.c b/recordmydesktop/src/rmd_jack.c index fb7a55e..ada967e 100644 --- a/recordmydesktop/src/rmd_jack.c +++ b/recordmydesktop/src/rmd_jack.c @@ -42,28 +42,28 @@ * \param nframes Number of frames captured * * \param jdata_t Pointer to JackData struct containing port -* and client information +* and client information * * \returns Zero always */ static int rmdJackCapture(jack_nframes_t nframes,void *jdata_t) { - int i=0; - JackData *jdata=(JackData *)jdata_t; + int i=0; + JackData *jdata=(JackData *)jdata_t; - if (!jdata->pdata->running || jdata->pdata->paused || !jdata->capture_started) { - return 0; - } + if (!jdata->pdata->running || jdata->pdata->paused || !jdata->capture_started) + return 0; + + for(i= 0;inports;i++) + jdata->portbuf[i]=jack_port_get_buffer(jdata->ports[i],nframes); - for(i= 0;inports;i++) - jdata->portbuf[i]=jack_port_get_buffer(jdata->ports[i],nframes); //vorbis analysis buffer wants uninterleaved data //so we are simply placing the buffers for every channel //sequentially on the ringbuffer - for(i=0;inports;i++) - (*jack_ringbuffer_write)(jdata->sound_buffer, - (void *)(jdata->portbuf[i]), - nframes* - sizeof(jack_default_audio_sample_t)); + for(i=0;inports;i++) + (*jack_ringbuffer_write)( jdata->sound_buffer, + (void *)(jdata->portbuf[i]), + nframes* + sizeof(jack_default_audio_sample_t)); /*FIXME */ //This is not safe. //cond_var signaling must move away from signal handlers @@ -72,54 +72,55 @@ static int rmdJackCapture(jack_nframes_t nframes,void *jdata_t) { //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(jdata->snd_buff_ready_mutex); - pthread_cond_signal(jdata->sound_data_read); - pthread_mutex_unlock(jdata->snd_buff_ready_mutex); + pthread_mutex_lock(jdata->snd_buff_ready_mutex); + pthread_cond_signal(jdata->sound_data_read); + pthread_mutex_unlock(jdata->snd_buff_ready_mutex); - return 0; + return 0; } /** * Register and Activate specified ports * * \param jdata_t Pointer to JackData struct containing port -* and client information +* and client information * * \returns 0 on Success, 1 on failure */ static int rmdSetupPorts(JackData *jdata) { - int i=0; - jdata->ports=malloc(sizeof(jack_port_t *)* - jdata->nports); - jdata->portbuf=malloc(sizeof(jack_default_audio_sample_t*)* - jdata->nports); - memset(jdata->portbuf,0,sizeof(jack_default_audio_sample_t*)* - jdata->nports); - - for(i=0;inports;i++){ - char name[64];//recordMyDesktop:input_n<64 is enough for full name - char num[8]; - strcpy(name,"input_"); - snprintf( num, 8, "%d", i+1 ); - strcat(name,num); - if((jdata->ports[i]=jack_port_register(jdata->client, - name, - JACK_DEFAULT_AUDIO_TYPE, - JackPortIsInput, - 0))==0){ - fprintf(stderr,"Cannot register input port \"%s\"!\n",name); - return 1; - } - if(jack_connect(jdata->client, - jdata->port_names[i], - jack_port_name(jdata->ports[i]))){ - fprintf(stderr,"Cannot connect input port %s to %s\n", - jack_port_name(jdata->ports[i]), - jdata->port_names[i]); - return 1; - } - } - return 0; + int i=0; + + jdata->ports=malloc(sizeof(jack_port_t *)* jdata->nports); + jdata->portbuf=malloc(sizeof(jack_default_audio_sample_t*)* jdata->nports); + memset(jdata->portbuf,0,sizeof(jack_default_audio_sample_t*)* jdata->nports); + + for(i=0;inports;i++) { + char name[64];//recordMyDesktop:input_n<64 is enough for full name + char num[8]; + strcpy(name,"input_"); + snprintf( num, 8, "%d", i+1 ); + strcat(name,num); + + jdata->ports[i] = jack_port_register( jdata->client, + name, + JACK_DEFAULT_AUDIO_TYPE, + JackPortIsInput, + 0); + + if (!jdata->ports[i]) { + fprintf(stderr,"Cannot register input port \"%s\"!\n",name); + return 1; + } + + if (jack_connect(jdata->client, jdata->port_names[i], jack_port_name(jdata->ports[i]))) { + + fprintf(stderr,"Cannot connect input port %s to %s\n", + jack_port_name(jdata->ports[i]), + jdata->port_names[i]); + return 1; + } + } + return 0; } //in case the jack server shuts down @@ -127,34 +128,34 @@ static int rmdSetupPorts(JackData *jdata) { //encode the result(if not on the fly) //an exit cleanly. static void rmdJackShutdown(void *jdata_t) { - JackData *jdata = (JackData *)jdata_t; + JackData *jdata = (JackData *)jdata_t; - jdata->pdata->running = FALSE; + jdata->pdata->running = FALSE; - fprintf (stderr, "JACK shutdown\n"); + fprintf (stderr, "JACK shutdown\n"); } -int rmdStartJackClient(JackData *jdata){ - float ring_buffer_size=0.0; - int pid; - char pidbuf[8]; - char rmd_client_name[32]; - - //construct the jack client name - //which is recordMyDesktop-pid - //in order to allow multiple - //instances of recordMyDesktop - //to connetc to a Jack Server - strcpy(rmd_client_name,"recordMyDesktop-"); - pid=getpid(); - snprintf( pidbuf, 8, "%d", pid ); - strcat(rmd_client_name,pidbuf); - - if ((jdata->client=(*jack_client_new)(rmd_client_name))==0){ - fprintf(stderr,"Could not create new client!\n" - "Make sure that Jack server is running!\n"); - return 15; - } +int rmdStartJackClient(JackData *jdata) { + float ring_buffer_size=0.0; + int pid; + char pidbuf[8]; + char rmd_client_name[32]; + + //construct the jack client name + //which is recordMyDesktop-pid + //in order to allow multiple + //instances of recordMyDesktop + //to connetc to a Jack Server + strcpy(rmd_client_name,"recordMyDesktop-"); + pid=getpid(); + snprintf( pidbuf, 8, "%d", pid ); + strcat(rmd_client_name,pidbuf); + + if ((jdata->client=(*jack_client_new)(rmd_client_name))==0) { + fprintf(stderr, "Could not create new client!\n" + "Make sure that Jack server is running!\n"); + return 15; + } //in contrast to ALSA and OSS, Jack dictates frequency //and buffersize to the values it was launched with. //Supposedly jack_set_buffer_size can set the buffersize @@ -168,51 +169,50 @@ int rmdStartJackClient(JackData *jdata){ //(it might be in some cases, but it will certainly be the cause //of unpredicted problems). A clean exit is preferable //and any recording up to that point will be encoded and saved. - jdata->frequency=jack_get_sample_rate(jdata->client); - jdata->buffersize=jack_get_buffer_size(jdata->client); - ring_buffer_size=(jdata->ringbuffer_secs* - jdata->frequency* - sizeof(jack_default_audio_sample_t)* - jdata->nports); - jdata->sound_buffer= - (*jack_ringbuffer_create)((int)(ring_buffer_size+0.5));//round up - jack_set_process_callback(jdata->client,rmdJackCapture,jdata); - jack_on_shutdown(jdata->client,rmdJackShutdown,jdata); - - if (jack_activate(jdata->client)) { - fprintf(stderr,"cannot activate client!\n"); - return 16; - } - if(rmdSetupPorts(jdata)){ - jack_client_close(jdata->client); - return 17; - } - - return 0; + jdata->frequency=jack_get_sample_rate(jdata->client); + jdata->buffersize=jack_get_buffer_size(jdata->client); + ring_buffer_size=( jdata->ringbuffer_secs* + jdata->frequency* + sizeof(jack_default_audio_sample_t)* + jdata->nports); + jdata->sound_buffer= (*jack_ringbuffer_create)((int)(ring_buffer_size+0.5));//round up + jack_set_process_callback(jdata->client,rmdJackCapture,jdata); + jack_on_shutdown(jdata->client,rmdJackShutdown,jdata); + + if (jack_activate(jdata->client)) { + fprintf(stderr,"cannot activate client!\n"); + return 16; + } + + if (rmdSetupPorts(jdata)) { + jack_client_close(jdata->client); + return 17; + } + + return 0; } -int rmdStopJackClient(JackData *jdata){ - int ret=0; +int rmdStopJackClient(JackData *jdata) { + int ret=0; - (*jack_ringbuffer_free)(jdata->sound_buffer); - if(jack_client_close(jdata->client)){ - fprintf(stderr,"Cannot close Jack client!\n"); - ret=1; - } + (*jack_ringbuffer_free)(jdata->sound_buffer); + if (jack_client_close(jdata->client)) { + fprintf(stderr,"Cannot close Jack client!\n"); + ret=1; + } /*TODO*/ //I need to make some kind of program/thread //flow diagram to see where it's safe to dlclose //because here it causes a segfault. -// if(dlclose(jdata->jack_lib_handle)){ -// fprintf(stderr,"Cannot unload Jack library!\n"); -// ret=1; -// } -// else fprintf(stderr,"Unloaded Jack library.\n"); +// if (dlclose(jdata->jack_lib_handle)) { +// fprintf(stderr,"Cannot unload Jack library!\n"); +// ret=1; +// } +// else fprintf(stderr,"Unloaded Jack library.\n"); - return ret; + return ret; } #endif - -- cgit v1.2.3