Browse Source

[0.99.19] add new realtime-safe messagebuffer interface

git-svn-id: svn+ssh://jackaudio.org/trunk/jack@815 0c269be4-1314-0410-8aa9-9f06e86f4224
tags/0.109.0
joq 21 years ago
parent
commit
f28ddbdc5b
11 changed files with 142 additions and 7 deletions
  1. +1
    -1
      configure.ac
  2. +2
    -1
      drivers/alsa/alsa_driver.c
  3. +1
    -0
      jack/Makefile.am
  4. +0
    -3
      jack/engine.h
  5. +44
    -0
      jack/messagebuffer.h
  6. +1
    -0
      jackd/clientengine.c
  7. +4
    -1
      jackd/engine.c
  8. +4
    -0
      jackd/jackd.c
  9. +1
    -1
      jackd/transengine.c
  10. +1
    -0
      libjack/Makefile.am
  11. +83
    -0
      libjack/messagebuffer.c

+ 1
- 1
configure.ac View File

@@ -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


+ 2
- 1
drivers/alsa/alsa_driver.c View File

@@ -33,6 +33,7 @@
#include <jack/internal.h>
#include <jack/engine.h>
#include <jack/messagebuffer.h>

#include <sysdeps/time.h>

@@ -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);
}


+ 1
- 0
jack/Makefile.am View File

@@ -21,6 +21,7 @@ noinst_HEADERS = \
internal.h \
jslist.h \
memops.h \
f messagebuffer.h \
pool.h \
port.h \
ringbuffer.h \


+ 0
- 3
jack/engine.h View File

@@ -26,9 +26,6 @@
#include <jack/internal.h>
#include <jack/driver_interface.h>

#define VERBOSE(engine,format,args...) \
if ((engine)->verbose) fprintf (stderr, format, ## args)

struct _jack_driver;
struct _jack_client_internal;
struct _jack_port_internal;


+ 44
- 0
jack/messagebuffer.h View File

@@ -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__ */

+ 1
- 0
jackd/clientengine.c View File

@@ -30,6 +30,7 @@

#include <jack/internal.h>
#include <jack/engine.h>
#include <jack/messagebuffer.h>
#include <jack/version.h>
#include <sysdeps/poll.h>
#include <sysdeps/ipc.h>


+ 4
- 1
jackd/engine.c View File

@@ -42,6 +42,7 @@

#include <jack/internal.h>
#include <jack/engine.h>
#include <jack/messagebuffer.h>
#include <jack/driver.h>
#include <jack/shm.h>
#include <jack/thread.h>
@@ -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


+ 4
- 0
jackd/jackd.c View File

@@ -38,6 +38,7 @@
#include <jack/driver.h>
#include <jack/shm.h>
#include <jack/driver_parse.h>
#include <jack/messagebuffer.h>

#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());
}


+ 1
- 1
jackd/transengine.c View File

@@ -26,9 +26,9 @@
#include <stdio.h>
#include <jack/internal.h>
#include <jack/engine.h>
#include <jack/messagebuffer.h>
#include "transengine.h"


/********************** internal functions **********************/

/* initiate polling a new slow-sync client


+ 1
- 0
libjack/Makefile.am View File

@@ -4,6 +4,7 @@ SOURCE_FILES = \
client.c \
driver.c \
intclient.c \
messagebuffer.c \
pool.c \
port.c \
ringbuffer.c \


+ 83
- 0
libjack/messagebuffer.c View File

@@ -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 <unistd.h>
#include <string.h>
#include <pthread.h>
#include <stdarg.h>
#include <stdio.h>

#include <jack/messagebuffer.h>

#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);
}

Loading…
Cancel
Save