2006-10-18 04:49:13 +02:00
|
|
|
/* jack plug in for the Music Player Daemon (MPD)
|
2007-04-09 22:18:11 +02:00
|
|
|
* (c)2006 by anarch(anarchsss@gmail.com)
|
2006-10-18 04:49:13 +02:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 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 General Public License for more details.
|
|
|
|
* You should have received a copy of the GNU 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "../audioOutput.h"
|
|
|
|
|
|
|
|
#ifdef HAVE_JACK
|
|
|
|
|
2008-01-03 08:29:49 +01:00
|
|
|
#include "../os_compat.h"
|
2006-10-18 04:49:13 +02:00
|
|
|
#include "../conf.h"
|
|
|
|
#include "../log.h"
|
|
|
|
|
|
|
|
#include <jack/jack.h>
|
|
|
|
#include <jack/types.h>
|
|
|
|
#include <jack/ringbuffer.h>
|
|
|
|
|
2007-04-09 22:18:11 +02:00
|
|
|
pthread_mutex_t play_audio_lock = PTHREAD_MUTEX_INITIALIZER;
|
|
|
|
pthread_cond_t play_audio = PTHREAD_COND_INITIALIZER;
|
|
|
|
|
2006-12-30 01:14:45 +01:00
|
|
|
/*#include "dmalloc.h"*/
|
|
|
|
|
2008-01-03 08:29:49 +01:00
|
|
|
#ifdef MIN
|
|
|
|
# undef MIN
|
|
|
|
# define MIN(a, b) ((a) < (b) ? (a) : (b))
|
|
|
|
#endif
|
|
|
|
|
2007-04-11 19:41:10 +02:00
|
|
|
/*#define SAMPLE_SIZE sizeof(jack_default_audio_sample_t);*/
|
|
|
|
|
2006-12-30 01:14:45 +01:00
|
|
|
|
2007-01-14 03:08:18 +01:00
|
|
|
static char *name = "mpd";
|
|
|
|
static char *output_ports[2];
|
2007-04-09 22:18:11 +02:00
|
|
|
static int ringbuf_sz = 32768;
|
2007-04-11 19:41:10 +02:00
|
|
|
size_t sample_size = sizeof(jack_default_audio_sample_t);
|
2006-10-18 04:49:13 +02:00
|
|
|
|
|
|
|
typedef struct _JackData {
|
|
|
|
jack_port_t *ports[2];
|
|
|
|
jack_client_t *client;
|
|
|
|
jack_ringbuffer_t *ringbuffer[2];
|
|
|
|
int bps;
|
|
|
|
int shutdown;
|
|
|
|
} JackData;
|
|
|
|
|
2006-12-30 01:14:45 +01:00
|
|
|
/*JackData *jd = NULL;*/
|
2006-10-18 04:49:13 +02:00
|
|
|
|
2006-12-30 01:14:45 +01:00
|
|
|
static JackData *newJackData(void)
|
2006-10-18 04:49:13 +02:00
|
|
|
{
|
|
|
|
JackData *ret;
|
2006-12-30 01:14:45 +01:00
|
|
|
ret = xcalloc(sizeof(JackData), 1);
|
2006-10-18 04:49:13 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-08-26 08:27:15 +02:00
|
|
|
static void freeJackClient(JackData *jd)
|
|
|
|
{
|
|
|
|
assert(jd != NULL);
|
|
|
|
|
|
|
|
if (jd->client != NULL) {
|
|
|
|
jack_deactivate(jd->client);
|
|
|
|
jack_client_close(jd->client);
|
|
|
|
jd->client = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (jd->ringbuffer[0] != NULL) {
|
|
|
|
jack_ringbuffer_free(jd->ringbuffer[0]);
|
|
|
|
jd->ringbuffer[0] = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (jd->ringbuffer[1] != NULL) {
|
|
|
|
jack_ringbuffer_free(jd->ringbuffer[1]);
|
|
|
|
jd->ringbuffer[1] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-20 22:04:32 +01:00
|
|
|
static void freeJackData(AudioOutput *audioOutput)
|
2006-10-18 04:49:13 +02:00
|
|
|
{
|
|
|
|
JackData *jd = audioOutput->data;
|
2007-01-14 03:08:24 +01:00
|
|
|
if (jd) {
|
2008-08-26 08:27:15 +02:00
|
|
|
freeJackClient(jd);
|
2007-01-14 03:08:24 +01:00
|
|
|
free(jd);
|
|
|
|
audioOutput->data = NULL;
|
|
|
|
}
|
2007-01-20 22:04:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void jack_finishDriver(AudioOutput *audioOutput)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2008-08-26 08:27:15 +02:00
|
|
|
freeJackData(audioOutput);
|
2007-05-23 14:24:12 +02:00
|
|
|
DEBUG("disconnect_jack (pid=%d)\n", getpid ());
|
2007-01-20 22:04:32 +01:00
|
|
|
|
|
|
|
if ( strcmp(name, "mpd") ) {
|
|
|
|
free(name);
|
|
|
|
name = "mpd";
|
|
|
|
}
|
|
|
|
|
|
|
|
for ( i = ARRAY_SIZE(output_ports); --i >= 0; ) {
|
|
|
|
if (!output_ports[i])
|
|
|
|
continue;
|
|
|
|
free(output_ports[i]);
|
|
|
|
output_ports[i] = NULL;
|
|
|
|
}
|
2006-10-18 04:49:13 +02:00
|
|
|
}
|
|
|
|
|
2008-08-26 08:27:02 +02:00
|
|
|
static int srate(mpd_unused jack_nframes_t rate, void *data)
|
2006-10-18 04:49:13 +02:00
|
|
|
{
|
|
|
|
JackData *jd = (JackData *) ((AudioOutput*) data)->data;
|
|
|
|
AudioFormat *audioFormat = &(((AudioOutput*) data)->outAudioFormat);
|
|
|
|
|
2006-12-30 01:14:45 +01:00
|
|
|
audioFormat->sampleRate = (int)jack_get_sample_rate(jd->client);
|
2006-10-18 04:49:13 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-12-30 01:14:45 +01:00
|
|
|
static int process(jack_nframes_t nframes, void *arg)
|
2006-10-18 04:49:13 +02:00
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
JackData *jd = (JackData *) arg;
|
|
|
|
jack_default_audio_sample_t *out[2];
|
|
|
|
size_t avail_data, avail_frames;
|
|
|
|
|
|
|
|
if ( nframes <= 0 )
|
|
|
|
return 0;
|
|
|
|
|
2006-12-30 01:14:45 +01:00
|
|
|
out[0] = jack_port_get_buffer(jd->ports[0], nframes);
|
|
|
|
out[1] = jack_port_get_buffer(jd->ports[1], nframes);
|
2006-10-18 04:49:13 +02:00
|
|
|
|
2007-03-23 12:07:04 +01:00
|
|
|
while ( nframes ) {
|
|
|
|
avail_data = jack_ringbuffer_read_space(jd->ringbuffer[1]);
|
2006-10-18 04:49:13 +02:00
|
|
|
|
2007-03-23 12:07:04 +01:00
|
|
|
if ( avail_data > 0 ) {
|
2007-04-11 19:41:10 +02:00
|
|
|
avail_frames = avail_data / sample_size;
|
2007-03-23 12:07:04 +01:00
|
|
|
|
|
|
|
if (avail_frames > nframes) {
|
|
|
|
avail_frames = nframes;
|
2007-04-11 19:41:10 +02:00
|
|
|
avail_data = nframes*sample_size;
|
2007-03-23 12:07:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
jack_ringbuffer_read(jd->ringbuffer[0], (char *)out[0],
|
|
|
|
avail_data);
|
|
|
|
jack_ringbuffer_read(jd->ringbuffer[1], (char *)out[1],
|
|
|
|
avail_data);
|
|
|
|
|
|
|
|
nframes -= avail_frames;
|
|
|
|
out[0] += avail_data;
|
|
|
|
out[1] += avail_data;
|
|
|
|
} else {
|
|
|
|
for (i = 0; i < nframes; i++)
|
|
|
|
out[0][i] = out[1][i] = 0.0;
|
|
|
|
nframes = 0;
|
|
|
|
}
|
|
|
|
|
2007-04-09 22:18:11 +02:00
|
|
|
if (pthread_mutex_trylock (&play_audio_lock) == 0) {
|
|
|
|
pthread_cond_signal (&play_audio);
|
|
|
|
pthread_mutex_unlock (&play_audio_lock);
|
2006-10-18 04:49:13 +02:00
|
|
|
}
|
2007-04-09 22:18:11 +02:00
|
|
|
}
|
|
|
|
|
2006-10-18 04:49:13 +02:00
|
|
|
|
2007-05-23 14:24:12 +02:00
|
|
|
/*DEBUG("process (pid=%d)\n", getpid());*/
|
2006-10-18 04:49:13 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-12-30 01:14:45 +01:00
|
|
|
static void shutdown_callback(void *arg)
|
2006-10-18 04:49:13 +02:00
|
|
|
{
|
|
|
|
JackData *jd = (JackData *) arg;
|
|
|
|
jd->shutdown = 1;
|
|
|
|
}
|
|
|
|
|
2006-12-30 01:14:45 +01:00
|
|
|
static void set_audioformat(AudioOutput *audioOutput)
|
2006-10-18 04:49:13 +02:00
|
|
|
{
|
|
|
|
JackData *jd = audioOutput->data;
|
|
|
|
AudioFormat *audioFormat = &audioOutput->outAudioFormat;
|
|
|
|
|
2006-12-30 01:14:45 +01:00
|
|
|
audioFormat->sampleRate = (int) jack_get_sample_rate(jd->client);
|
2007-05-23 14:24:12 +02:00
|
|
|
DEBUG("samplerate = %d\n", audioFormat->sampleRate);
|
2006-12-30 01:14:45 +01:00
|
|
|
audioFormat->channels = 2;
|
2006-10-18 04:49:13 +02:00
|
|
|
audioFormat->bits = 16;
|
2007-01-20 22:04:32 +01:00
|
|
|
jd->bps = audioFormat->channels
|
2007-03-23 22:23:41 +01:00
|
|
|
* sizeof(jack_default_audio_sample_t)
|
2007-01-20 22:04:32 +01:00
|
|
|
* audioFormat->sampleRate;
|
2006-10-18 04:49:13 +02:00
|
|
|
}
|
|
|
|
|
2006-12-30 01:14:45 +01:00
|
|
|
static void error_callback(const char *msg)
|
|
|
|
{
|
|
|
|
ERROR("jack: %s\n", msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int jack_initDriver(AudioOutput *audioOutput, ConfigParam *param)
|
|
|
|
{
|
|
|
|
BlockParam *bp;
|
|
|
|
char *endptr;
|
|
|
|
int val;
|
2008-06-13 09:39:11 +02:00
|
|
|
char *cp = NULL;
|
|
|
|
|
2008-08-26 08:27:15 +02:00
|
|
|
audioOutput->data = newJackData();
|
2006-12-30 01:14:45 +01:00
|
|
|
|
2007-05-23 14:24:12 +02:00
|
|
|
DEBUG("jack_initDriver (pid=%d)\n", getpid());
|
2006-12-30 01:14:45 +01:00
|
|
|
if ( ! param ) return 0;
|
|
|
|
|
|
|
|
if ( (bp = getBlockParam(param, "ports")) ) {
|
2007-01-14 03:08:27 +01:00
|
|
|
DEBUG("output_ports=%s\n", bp->value);
|
|
|
|
|
|
|
|
if (!(cp = strchr(bp->value, ',')))
|
|
|
|
FATAL("expected comma and a second value for '%s' "
|
|
|
|
"at line %d: %s\n",
|
|
|
|
bp->name, bp->line, bp->value);
|
|
|
|
|
|
|
|
*cp = '\0';
|
|
|
|
output_ports[0] = xstrdup(bp->value);
|
|
|
|
*cp++ = ',';
|
|
|
|
|
|
|
|
if (!*cp)
|
|
|
|
FATAL("expected a second value for '%s' at line %d: "
|
|
|
|
"%s\n", bp->name, bp->line, bp->value);
|
|
|
|
|
|
|
|
output_ports[1] = xstrdup(cp);
|
|
|
|
|
|
|
|
if (strchr(cp,','))
|
|
|
|
FATAL("Only %d values are supported for '%s' "
|
2007-01-14 05:25:22 +01:00
|
|
|
"at line %d\n", (int)ARRAY_SIZE(output_ports),
|
|
|
|
bp->name, bp->line);
|
2006-12-30 01:14:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( (bp = getBlockParam(param, "ringbuffer_size")) ) {
|
|
|
|
errno = 0;
|
|
|
|
val = strtol(bp->value, &endptr, 10);
|
|
|
|
|
|
|
|
if ( errno == 0 && endptr != bp->value) {
|
2007-04-09 22:18:11 +02:00
|
|
|
ringbuf_sz = val < 32768 ? 32768 : val;
|
2007-05-23 14:24:12 +02:00
|
|
|
DEBUG("ringbuffer_size=%d\n", ringbuf_sz);
|
2006-12-30 01:14:45 +01:00
|
|
|
} else {
|
2007-05-23 14:24:12 +02:00
|
|
|
FATAL("%s is not a number; ringbuf_size=%d\n",
|
2006-12-30 01:14:45 +01:00
|
|
|
bp->value, ringbuf_sz);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( (bp = getBlockParam(param, "name"))
|
|
|
|
&& (strcmp(bp->value, "mpd") != 0) ) {
|
2007-01-14 03:08:22 +01:00
|
|
|
name = xstrdup(bp->value);
|
2007-05-23 14:24:12 +02:00
|
|
|
DEBUG("name=%s\n", name);
|
2006-12-30 01:14:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int jack_testDefault(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int connect_jack(AudioOutput *audioOutput)
|
2006-10-18 04:49:13 +02:00
|
|
|
{
|
|
|
|
JackData *jd = audioOutput->data;
|
2006-12-30 01:41:05 +01:00
|
|
|
char **jports;
|
2006-12-30 01:14:45 +01:00
|
|
|
char *port_name;
|
2006-10-18 04:49:13 +02:00
|
|
|
|
2006-12-30 01:14:45 +01:00
|
|
|
if ( (jd->client = jack_client_new(name)) == NULL ) {
|
|
|
|
ERROR("jack server not running?\n");
|
2006-10-18 04:49:13 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2006-12-30 01:14:45 +01:00
|
|
|
jack_set_error_function(error_callback);
|
|
|
|
jack_set_process_callback(jd->client, process, (void *)jd);
|
|
|
|
jack_set_sample_rate_callback(jd->client, (JackProcessCallback)srate,
|
|
|
|
(void *)audioOutput);
|
|
|
|
jack_on_shutdown(jd->client, shutdown_callback, (void *)jd);
|
2006-10-18 04:49:13 +02:00
|
|
|
|
2006-12-30 01:14:45 +01:00
|
|
|
if ( jack_activate(jd->client) ) {
|
2007-08-27 23:03:22 +02:00
|
|
|
ERROR("cannot activate client\n");
|
2006-10-18 04:49:13 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2006-12-30 01:14:45 +01:00
|
|
|
jd->ports[0] = jack_port_register(jd->client, "left",
|
|
|
|
JACK_DEFAULT_AUDIO_TYPE,
|
|
|
|
JackPortIsOutput, 0);
|
2006-10-18 04:49:13 +02:00
|
|
|
if ( !jd->ports[0] ) {
|
2006-12-30 01:14:45 +01:00
|
|
|
ERROR("Cannot register left output port.\n");
|
2006-10-18 04:49:13 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2006-12-30 01:14:45 +01:00
|
|
|
jd->ports[1] = jack_port_register(jd->client, "right",
|
|
|
|
JACK_DEFAULT_AUDIO_TYPE,
|
|
|
|
JackPortIsOutput, 0);
|
2006-10-18 04:49:13 +02:00
|
|
|
if ( !jd->ports[1] ) {
|
2006-12-30 01:14:45 +01:00
|
|
|
ERROR("Cannot register right output port.\n");
|
2006-10-18 04:49:13 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* hay que buscar que hay */
|
2006-12-30 01:41:05 +01:00
|
|
|
if ( !output_ports[1]
|
|
|
|
&& (jports = (char **)jack_get_ports(jd->client, NULL, NULL,
|
|
|
|
JackPortIsPhysical|
|
|
|
|
JackPortIsInput)) ) {
|
2006-12-30 01:14:45 +01:00
|
|
|
output_ports[0] = jports[0];
|
|
|
|
output_ports[1] = jports[1] ? jports[1] : jports[0];
|
2007-05-23 14:24:12 +02:00
|
|
|
DEBUG("output_ports: %s %s\n", output_ports[0], output_ports[1]);
|
2006-12-30 01:14:45 +01:00
|
|
|
free(jports);
|
2006-10-18 04:49:13 +02:00
|
|
|
}
|
|
|
|
|
2006-12-30 01:14:45 +01:00
|
|
|
if ( output_ports[1] ) {
|
|
|
|
jd->ringbuffer[0] = jack_ringbuffer_create(ringbuf_sz);
|
|
|
|
jd->ringbuffer[1] = jack_ringbuffer_create(ringbuf_sz);
|
|
|
|
memset(jd->ringbuffer[0]->buf, 0, jd->ringbuffer[0]->size);
|
|
|
|
memset(jd->ringbuffer[1]->buf, 0, jd->ringbuffer[1]->size);
|
|
|
|
|
|
|
|
port_name = xmalloc(sizeof(char)*(7+strlen(name)));
|
|
|
|
|
|
|
|
sprintf(port_name, "%s:left", name);
|
2007-01-20 22:04:32 +01:00
|
|
|
if ( (jack_connect(jd->client, port_name,
|
|
|
|
output_ports[0])) != 0 ) {
|
2007-08-27 23:03:22 +02:00
|
|
|
ERROR("%s is not a valid Jack Client / Port\n",
|
2007-01-20 22:04:32 +01:00
|
|
|
output_ports[0]);
|
2006-12-30 01:14:45 +01:00
|
|
|
free(port_name);
|
2006-10-18 04:49:13 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2006-12-30 01:14:45 +01:00
|
|
|
sprintf(port_name, "%s:right", name);
|
2007-01-20 22:04:32 +01:00
|
|
|
if ( (jack_connect(jd->client, port_name,
|
|
|
|
output_ports[1])) != 0 ) {
|
2007-08-27 23:03:22 +02:00
|
|
|
ERROR("%s is not a valid Jack Client / Port\n",
|
2007-01-20 22:04:32 +01:00
|
|
|
output_ports[1]);
|
2006-12-30 01:14:45 +01:00
|
|
|
free(port_name);
|
2006-10-18 04:49:13 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2006-12-30 01:14:45 +01:00
|
|
|
free(port_name);
|
2006-10-18 04:49:13 +02:00
|
|
|
}
|
|
|
|
|
2007-05-23 14:24:12 +02:00
|
|
|
DEBUG("connect_jack (pid=%d)\n", getpid());
|
2006-10-18 04:49:13 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2006-12-30 01:14:45 +01:00
|
|
|
static int jack_openDevice(AudioOutput *audioOutput)
|
2006-10-18 04:49:13 +02:00
|
|
|
{
|
2006-12-30 01:14:45 +01:00
|
|
|
JackData *jd = audioOutput->data;
|
2006-10-18 04:49:13 +02:00
|
|
|
|
2008-08-26 08:27:15 +02:00
|
|
|
assert(jd != NULL);
|
2006-10-18 04:49:13 +02:00
|
|
|
|
2008-08-26 08:27:15 +02:00
|
|
|
if (jd->client == NULL && connect_jack(audioOutput) < 0) {
|
2008-08-26 08:27:15 +02:00
|
|
|
freeJackClient(jd);
|
2008-08-26 08:27:15 +02:00
|
|
|
audioOutput->open = 0;
|
|
|
|
return -1;
|
2006-10-18 04:49:13 +02:00
|
|
|
}
|
|
|
|
|
2006-12-30 01:14:45 +01:00
|
|
|
set_audioformat(audioOutput);
|
2006-10-18 04:49:13 +02:00
|
|
|
audioOutput->open = 1;
|
|
|
|
|
2007-05-23 14:24:12 +02:00
|
|
|
DEBUG("jack_openDevice (pid=%d)!\n", getpid ());
|
2006-10-18 04:49:13 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void jack_closeDevice(AudioOutput * audioOutput)
|
|
|
|
{
|
2007-01-20 22:04:32 +01:00
|
|
|
/*jack_finishDriver(audioOutput);*/
|
2006-10-18 04:49:13 +02:00
|
|
|
audioOutput->open = 0;
|
2007-05-23 14:24:12 +02:00
|
|
|
DEBUG("jack_closeDevice (pid=%d)\n", getpid());
|
2006-10-18 04:49:13 +02:00
|
|
|
}
|
|
|
|
|
2008-08-26 08:27:02 +02:00
|
|
|
static void jack_dropBufferedAudio (mpd_unused AudioOutput * audioOutput)
|
2006-10-18 04:49:13 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-04-12 06:15:52 +02:00
|
|
|
static int jack_playAudio(AudioOutput * audioOutput,
|
|
|
|
const char *buff, size_t size)
|
2006-10-18 04:49:13 +02:00
|
|
|
{
|
|
|
|
JackData *jd = audioOutput->data;
|
2006-12-30 01:14:45 +01:00
|
|
|
size_t space;
|
2008-04-12 06:15:52 +02:00
|
|
|
size_t i;
|
|
|
|
const short *buffer = (const short *) buff;
|
2007-03-23 22:23:41 +01:00
|
|
|
jack_default_audio_sample_t sample;
|
|
|
|
size_t samples = size/4;
|
2006-10-18 04:49:13 +02:00
|
|
|
|
2007-05-23 14:24:12 +02:00
|
|
|
/*DEBUG("jack_playAudio: (pid=%d)!\n", getpid());*/
|
2007-03-23 12:07:04 +01:00
|
|
|
|
2006-10-18 04:49:13 +02:00
|
|
|
if ( jd->shutdown ) {
|
2006-12-30 01:14:45 +01:00
|
|
|
ERROR("Refusing to play, because there is no client thread.\n");
|
2008-08-26 08:27:15 +02:00
|
|
|
freeJackClient(jd);
|
2007-01-20 22:04:32 +01:00
|
|
|
audioOutput->open = 0;
|
2006-10-18 04:49:13 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-03-23 22:23:41 +01:00
|
|
|
while ( samples && !jd->shutdown ) {
|
2007-04-09 22:18:11 +02:00
|
|
|
|
2007-03-23 22:23:41 +01:00
|
|
|
if ( (space = jack_ringbuffer_write_space(jd->ringbuffer[0]))
|
2007-04-11 19:41:10 +02:00
|
|
|
>= samples*sample_size ) {
|
2006-12-30 01:14:45 +01:00
|
|
|
|
2007-04-11 19:41:10 +02:00
|
|
|
/*space = MIN(space, samples*sample_size);*/
|
|
|
|
/*space = samples*sample_size;*/
|
2007-03-23 22:23:41 +01:00
|
|
|
|
2007-04-11 19:41:10 +02:00
|
|
|
/*for(i=0; i<space/sample_size; i++) {*/
|
|
|
|
for(i=0; i<samples; i++) {
|
2007-03-23 22:23:41 +01:00
|
|
|
sample = (jack_default_audio_sample_t) *(buffer++)/32768.0;
|
|
|
|
|
|
|
|
jack_ringbuffer_write(jd->ringbuffer[0], (void*)&sample,
|
2007-04-11 19:41:10 +02:00
|
|
|
sample_size);
|
2007-03-23 22:23:41 +01:00
|
|
|
|
|
|
|
sample = (jack_default_audio_sample_t) *(buffer++)/32768.0;
|
|
|
|
|
|
|
|
jack_ringbuffer_write(jd->ringbuffer[1], (void*)&sample,
|
2007-04-11 19:41:10 +02:00
|
|
|
sample_size);
|
2007-03-23 22:23:41 +01:00
|
|
|
|
2007-04-11 19:41:10 +02:00
|
|
|
/*samples--;*/
|
2007-03-23 22:23:41 +01:00
|
|
|
}
|
2007-04-11 19:41:10 +02:00
|
|
|
samples=0;
|
2006-12-30 01:14:45 +01:00
|
|
|
|
2007-04-11 19:41:10 +02:00
|
|
|
} else {
|
|
|
|
pthread_mutex_lock(&play_audio_lock);
|
|
|
|
pthread_cond_wait(&play_audio, &play_audio_lock);
|
|
|
|
pthread_mutex_unlock(&play_audio_lock);
|
|
|
|
}
|
2006-12-30 01:14:45 +01:00
|
|
|
|
2007-04-09 22:18:11 +02:00
|
|
|
}
|
2006-10-18 04:49:13 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
AudioOutputPlugin jackPlugin = {
|
|
|
|
"jack",
|
|
|
|
jack_testDefault,
|
|
|
|
jack_initDriver,
|
|
|
|
jack_finishDriver,
|
|
|
|
jack_openDevice,
|
|
|
|
jack_playAudio,
|
|
|
|
jack_dropBufferedAudio,
|
|
|
|
jack_closeDevice,
|
|
|
|
NULL, /* sendMetadataFunc */
|
|
|
|
};
|
|
|
|
|
|
|
|
#else /* HAVE JACK */
|
|
|
|
|
|
|
|
DISABLED_AUDIO_OUTPUT_PLUGIN(jackPlugin)
|
|
|
|
|
|
|
|
#endif /* HAVE_JACK */
|