summaryrefslogtreecommitdiff
path: root/recordmydesktop/src/rmd_jack.c
diff options
context:
space:
mode:
Diffstat (limited to 'recordmydesktop/src/rmd_jack.c')
-rw-r--r--recordmydesktop/src/rmd_jack.c69
1 files changed, 33 insertions, 36 deletions
diff --git a/recordmydesktop/src/rmd_jack.c b/recordmydesktop/src/rmd_jack.c
index ada967e..ba37c8b 100644
--- a/recordmydesktop/src/rmd_jack.c
+++ b/recordmydesktop/src/rmd_jack.c
@@ -46,23 +46,22 @@
*
* \returns Zero always
*/
-static int rmdJackCapture(jack_nframes_t nframes,void *jdata_t) {
- int i=0;
- JackData *jdata=(JackData *)jdata_t;
+static int rmdJackCapture(jack_nframes_t nframes, void *jdata_t) {
+ JackData *jdata = (JackData *)jdata_t;
- if (!jdata->pdata->running || jdata->pdata->paused || !jdata->capture_started)
+ if (!jdata->pdata->running || jdata->pdata->paused || !jdata->capture_started)
return 0;
- for(i= 0;i<jdata->nports;i++)
- jdata->portbuf[i]=jack_port_get_buffer(jdata->ports[i],nframes);
+ for(int i = 0; i < jdata->nports; 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;i<jdata->nports;i++)
+ for(int i = 0; i < jdata->nports; i++)
(*jack_ringbuffer_write)( jdata->sound_buffer,
(void *)(jdata->portbuf[i]),
- nframes*
+ nframes *
sizeof(jack_default_audio_sample_t));
/*FIXME */
//This is not safe.
@@ -88,18 +87,16 @@ static int rmdJackCapture(jack_nframes_t nframes,void *jdata_t) {
* \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);
+ 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;i<jdata->nports;i++) {
+ for(int i = 0; i < jdata->nports; 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);
+ strcpy(name, "input_");
+ snprintf(num, 8, "%d", i + 1);
+ strcat(name, num);
jdata->ports[i] = jack_port_register( jdata->client,
name,
@@ -108,13 +105,13 @@ static int rmdSetupPorts(JackData *jdata) {
0);
if (!jdata->ports[i]) {
- fprintf(stderr,"Cannot register input port \"%s\"!\n",name);
+ 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",
+ fprintf(stderr, "Cannot connect input port %s to %s\n",
jack_port_name(jdata->ports[i]),
jdata->port_names[i]);
return 1;
@@ -136,7 +133,7 @@ static void rmdJackShutdown(void *jdata_t) {
}
int rmdStartJackClient(JackData *jdata) {
- float ring_buffer_size=0.0;
+ float ring_buffer_size = 0.0;
int pid;
char pidbuf[8];
char rmd_client_name[32];
@@ -146,12 +143,12 @@ int rmdStartJackClient(JackData *jdata) {
//in order to allow multiple
//instances of recordMyDesktop
//to connetc to a Jack Server
- strcpy(rmd_client_name,"recordMyDesktop-");
- pid=getpid();
+ strcpy(rmd_client_name, "recordMyDesktop-");
+ pid = getpid();
snprintf( pidbuf, 8, "%d", pid );
- strcat(rmd_client_name,pidbuf);
+ strcat(rmd_client_name, pidbuf);
- if ((jdata->client=(*jack_client_new)(rmd_client_name))==0) {
+ 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;
@@ -169,18 +166,18 @@ 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 = 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);
+ 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");
+ fprintf(stderr, "cannot activate client!\n");
return 16;
}
@@ -193,12 +190,12 @@ int rmdStartJackClient(JackData *jdata) {
}
int rmdStopJackClient(JackData *jdata) {
- int ret=0;
+ int ret = 0;
(*jack_ringbuffer_free)(jdata->sound_buffer);
if (jack_client_close(jdata->client)) {
- fprintf(stderr,"Cannot close Jack client!\n");
- ret=1;
+ fprintf(stderr, "Cannot close Jack client!\n");
+ ret = 1;
}
/*TODO*/
@@ -207,10 +204,10 @@ int rmdStopJackClient(JackData *jdata) {
//because here it causes a segfault.
// if (dlclose(jdata->jack_lib_handle)) {
-// fprintf(stderr,"Cannot unload Jack library!\n");
+// fprintf(stderr, "Cannot unload Jack library!\n");
// ret=1;
// }
-// else fprintf(stderr,"Unloaded Jack library.\n");
+// else fprintf(stderr, "Unloaded Jack library.\n");
return ret;
}
© All Rights Reserved