From f28ddbdc5bd6ebefad1e3baacf7a32689194d4c4 Mon Sep 17 00:00:00 2001 From: joq Date: Fri, 3 Dec 2004 20:52:59 +0000 Subject: [PATCH] [0.99.19] add new realtime-safe messagebuffer interface git-svn-id: svn+ssh://jackaudio.org/trunk/jack@815 0c269be4-1314-0410-8aa9-9f06e86f4224 --- configure.ac | 2 +- drivers/alsa/alsa_driver.c | 3 +- jack/Makefile.am | 1 + jack/engine.h | 3 -- jack/messagebuffer.h | 44 ++++++++++++++++++++ jackd/clientengine.c | 1 + jackd/engine.c | 5 ++- jackd/jackd.c | 4 ++ jackd/transengine.c | 2 +- libjack/Makefile.am | 1 + libjack/messagebuffer.c | 83 ++++++++++++++++++++++++++++++++++++++ 11 files changed, 142 insertions(+), 7 deletions(-) create mode 100644 jack/messagebuffer.h create mode 100644 libjack/messagebuffer.c diff --git a/configure.ac b/configure.ac index 8d2c46d..745c8a5 100644 --- a/configure.ac +++ b/configure.ac @@ -15,7 +15,7 @@ dnl changes are made dnl --- JACK_MAJOR_VERSION=0 JACK_MINOR_VERSION=99 -JACK_MICRO_VERSION=18 +JACK_MICRO_VERSION=19 dnl --- dnl HOWTO: updating the jack protocol version diff --git a/drivers/alsa/alsa_driver.c b/drivers/alsa/alsa_driver.c index fc9ba00..6cd7900 100644 --- a/drivers/alsa/alsa_driver.c +++ b/drivers/alsa/alsa_driver.c @@ -33,6 +33,7 @@ #include #include +#include #include @@ -1081,7 +1082,7 @@ alsa_driver_xrun_recovery (alsa_driver_t *driver, float *delayed_usecs) snd_pcm_status_get_trigger_tstamp(status, &tstamp); timersub(&now, &tstamp, &diff); *delayed_usecs = diff.tv_sec * 1000000.0 + diff.tv_usec; - fprintf(stderr, "\n\n**** alsa_pcm: xrun of at least %.3f " + MESSAGE("\n\n**** alsa_pcm: xrun of at least %.3f " "msecs\n\n", *delayed_usecs / 1000.0); } diff --git a/jack/Makefile.am b/jack/Makefile.am index f989faa..3f8dd37 100644 --- a/jack/Makefile.am +++ b/jack/Makefile.am @@ -21,6 +21,7 @@ noinst_HEADERS = \ internal.h \ jslist.h \ memops.h \ +f messagebuffer.h \ pool.h \ port.h \ ringbuffer.h \ diff --git a/jack/engine.h b/jack/engine.h index 4bf5403..0a26d13 100644 --- a/jack/engine.h +++ b/jack/engine.h @@ -26,9 +26,6 @@ #include #include -#define VERBOSE(engine,format,args...) \ - if ((engine)->verbose) fprintf (stderr, format, ## args) - struct _jack_driver; struct _jack_client_internal; struct _jack_port_internal; diff --git a/jack/messagebuffer.h b/jack/messagebuffer.h new file mode 100644 index 0000000..74effc5 --- /dev/null +++ b/jack/messagebuffer.h @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2004 Rui Nuno Capela, Steve Harris + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser 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. + * + * $Id$ + */ + +#ifndef __jack_messagebuffer_h__ +#define __jack_messagebuffer_h__ + +#define MB_BUFFERSIZE 256 + +#define MESSAGE(fmt,args...) { \ + char msg[MB_BUFFERSIZE]; \ + snprintf(msg, MB_BUFFERSIZE-1, fmt, ##args); \ + jack_messagebuffer_add(msg); \ + } + +#define VERBOSE(engine,fmt,args...) \ + if ((engine)->verbose) { \ + char msg[MB_BUFFERSIZE]; \ + snprintf(msg, MB_BUFFERSIZE-1, fmt, ##args); \ + jack_messagebuffer_add(msg); \ + } + +void jack_messagebuffer_init(const char *prefix); +void jack_messagebuffer_exit(); + +void jack_messagebuffer_add(const char *msg); + +#endif /* __jack_messagebuffer_h__ */ diff --git a/jackd/clientengine.c b/jackd/clientengine.c index 1766bde..ac113b2 100644 --- a/jackd/clientengine.c +++ b/jackd/clientengine.c @@ -30,6 +30,7 @@ #include #include +#include #include #include #include diff --git a/jackd/engine.c b/jackd/engine.c index fc258ff..b3e4e1b 100644 --- a/jackd/engine.c +++ b/jackd/engine.c @@ -42,6 +42,7 @@ #include #include +#include #include #include #include @@ -1951,7 +1952,7 @@ jack_run_one_cycle (jack_engine_t *engine, jack_nframes_t nframes, engine->spare_usecs && ((WORK_SCALE * engine->spare_usecs) <= delayed_usecs)) { - fprintf (stderr, "delay of %.3f usecs exceeds estimated spare" + MESSAGE("delay of %.3f usecs exceeds estimated spare" " time of %.3f; restart ...\n", delayed_usecs, WORK_SCALE * engine->spare_usecs); @@ -2134,6 +2135,8 @@ jack_engine_delete (jack_engine_t *engine) VERBOSE (engine, "engine deleted\n"); free (engine); + + jack_messagebuffer_exit(); } void diff --git a/jackd/jackd.c b/jackd/jackd.c index e7dbe35..0c8fcf6 100644 --- a/jackd/jackd.c +++ b/jackd/jackd.c @@ -38,6 +38,7 @@ #include #include #include +#include #ifdef USE_CAPABILITIES @@ -173,6 +174,9 @@ jack_main (jack_driver_desc_t * driver_desc, JSList * driver_params) } } + /* start a thread to display messages from realtime threads */ + jack_messagebuffer_init(""); + if (verbose) { fprintf (stderr, "%d waiting for signals\n", getpid()); } diff --git a/jackd/transengine.c b/jackd/transengine.c index be18b10..436f4de 100644 --- a/jackd/transengine.c +++ b/jackd/transengine.c @@ -26,9 +26,9 @@ #include #include #include +#include #include "transengine.h" - /********************** internal functions **********************/ /* initiate polling a new slow-sync client diff --git a/libjack/Makefile.am b/libjack/Makefile.am index c390d72..6371ed4 100644 --- a/libjack/Makefile.am +++ b/libjack/Makefile.am @@ -4,6 +4,7 @@ SOURCE_FILES = \ client.c \ driver.c \ intclient.c \ + messagebuffer.c \ pool.c \ port.c \ ringbuffer.c \ diff --git a/libjack/messagebuffer.c b/libjack/messagebuffer.c new file mode 100644 index 0000000..1751122 --- /dev/null +++ b/libjack/messagebuffer.c @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2004 Rui Nuno Capela, Steve Harris + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser 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. + * + * $Id$ + */ + +#include +#include +#include +#include +#include + +#include + +#define MB_BUFFERS 32 /* must be 2^n */ + +static char mb_buffers[MB_BUFFERS][MB_BUFFERSIZE]; +static const char *mb_prefix; +static unsigned int mb_initialized = 0; +static unsigned int mb_inbuffer = 0; +static unsigned int mb_outbuffer = 0; +static pthread_t mb_writer_thread; + +static void * +mb_thread_func(void *arg) +{ + while (mb_initialized) { + usleep(1000); + while (mb_outbuffer != mb_inbuffer) { + fprintf(stderr, "%s%s", mb_prefix, + mb_buffers[mb_outbuffer]); + mb_outbuffer = (mb_outbuffer + 1) & (MB_BUFFERS - 1); + } + } + + return NULL; +} + +void +jack_messagebuffer_init (const char *prefix) +{ + if (mb_initialized) + return; + + mb_initialized = 1; + + mb_prefix = prefix; + if (pthread_create(&mb_writer_thread, NULL, &mb_thread_func, NULL) != 0) + mb_initialized = 0; +} + +void +jack_messagebuffer_exit () +{ + if (!mb_initialized) + return; + + mb_initialized = 0; + + pthread_join(&mb_writer_thread, NULL); +} + + +void +jack_messagebuffer_add (const char *msg) +{ + strncpy(mb_buffers[mb_inbuffer], msg, MB_BUFFERSIZE - 1); + mb_inbuffer = (mb_inbuffer + 1) & (MB_BUFFERS - 1); +}