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
|
|
|
|
*/
|
|
|
|
|
2008-09-07 22:41:17 +02:00
|
|
|
#include "../output_api.h"
|
2006-10-18 04:49:13 +02:00
|
|
|
|
|
|
|
#ifdef HAVE_JACK
|
|
|
|
|
2008-09-07 22:41:17 +02:00
|
|
|
#include "../utils.h"
|
2006-10-18 04:49:13 +02:00
|
|
|
#include "../log.h"
|
|
|
|
|
2008-10-08 10:49:29 +02:00
|
|
|
#include <assert.h>
|
|
|
|
|
2006-10-18 04:49:13 +02:00
|
|
|
#include <jack/jack.h>
|
|
|
|
#include <jack/types.h>
|
|
|
|
#include <jack/ringbuffer.h>
|
|
|
|
|
2008-08-26 08:27:16 +02:00
|
|
|
static const size_t sample_size = sizeof(jack_default_audio_sample_t);
|
2006-10-18 04:49:13 +02:00
|
|
|
|
|
|
|
typedef struct _JackData {
|
2008-09-24 07:20:55 +02:00
|
|
|
struct audio_output *ao;
|
|
|
|
|
2008-08-26 08:27:16 +02:00
|
|
|
/* configuration */
|
2008-09-07 19:14:39 +02:00
|
|
|
const char *name;
|
|
|
|
const char *output_ports[2];
|
2008-08-26 08:27:16 +02:00
|
|
|
int ringbuf_sz;
|
|
|
|
|
2008-09-24 07:20:36 +02:00
|
|
|
/* for srate() only */
|
|
|
|
struct audio_format *audio_format;
|
|
|
|
|
2008-08-26 08:27:16 +02:00
|
|
|
/* jack library stuff */
|
2006-10-18 04:49:13 +02:00
|
|
|
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;
|
2008-09-07 19:14:39 +02:00
|
|
|
|
2006-12-30 01:14:45 +01:00
|
|
|
ret = xcalloc(sizeof(JackData), 1);
|
2006-10-18 04:49:13 +02:00
|
|
|
|
2008-08-26 08:27:16 +02:00
|
|
|
ret->name = "mpd";
|
|
|
|
ret->ringbuf_sz = 32768;
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-24 07:20:55 +02:00
|
|
|
static void freeJackData(JackData *jd)
|
2006-10-18 04:49:13 +02:00
|
|
|
{
|
2008-08-26 08:27:16 +02:00
|
|
|
int i;
|
2008-08-26 08:27:15 +02:00
|
|
|
|
|
|
|
assert(jd != NULL);
|
|
|
|
|
|
|
|
freeJackClient(jd);
|
2008-08-26 08:27:16 +02:00
|
|
|
|
|
|
|
if (strcmp(jd->name, "mpd") != 0)
|
2008-09-07 19:14:39 +02:00
|
|
|
xfree(jd->name);
|
2008-08-26 08:27:16 +02:00
|
|
|
|
|
|
|
for ( i = ARRAY_SIZE(jd->output_ports); --i >= 0; ) {
|
|
|
|
if (!jd->output_ports[i])
|
|
|
|
continue;
|
2008-09-07 19:14:39 +02:00
|
|
|
xfree(jd->output_ports[i]);
|
2008-08-26 08:27:16 +02:00
|
|
|
}
|
|
|
|
|
2008-08-26 08:27:15 +02:00
|
|
|
free(jd);
|
2007-01-20 22:04:32 +01:00
|
|
|
}
|
|
|
|
|
2008-09-24 07:20:55 +02:00
|
|
|
static void jack_finishDriver(void *data)
|
2007-01-20 22:04:32 +01:00
|
|
|
{
|
2008-09-24 07:20:55 +02:00
|
|
|
JackData *jd = data;
|
|
|
|
freeJackData(jd);
|
2007-05-23 14:24:12 +02:00
|
|
|
DEBUG("disconnect_jack (pid=%d)\n", getpid ());
|
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
|
|
|
{
|
2008-09-24 07:20:55 +02:00
|
|
|
JackData *jd = (JackData *)data;
|
2008-09-24 07:20:36 +02:00
|
|
|
struct audio_format *audioFormat = jd->audio_format;
|
2006-10-18 04:49:13 +02:00
|
|
|
|
2008-10-10 14:40:54 +02:00
|
|
|
audioFormat->sample_rate = (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
|
|
|
{
|
|
|
|
JackData *jd = (JackData *) arg;
|
2008-10-24 16:55:51 +02:00
|
|
|
jack_default_audio_sample_t *out;
|
2008-10-24 16:56:08 +02:00
|
|
|
size_t available;
|
2006-10-18 04:49:13 +02:00
|
|
|
|
2008-10-24 08:44:40 +02:00
|
|
|
if (nframes <= 0)
|
2006-10-18 04:49:13 +02:00
|
|
|
return 0;
|
|
|
|
|
2008-10-24 16:55:51 +02:00
|
|
|
for (unsigned i = 0; i < 2; ++i) {
|
2008-10-24 16:56:08 +02:00
|
|
|
available = jack_ringbuffer_read_space(jd->ringbuffer[i]);
|
2008-10-24 16:56:10 +02:00
|
|
|
assert(available % sample_size == 0);
|
2008-10-24 16:56:08 +02:00
|
|
|
available /= sample_size;
|
|
|
|
if (available > nframes)
|
|
|
|
available = nframes;
|
2007-03-23 12:07:04 +01:00
|
|
|
|
2008-10-24 16:55:51 +02:00
|
|
|
out = jack_port_get_buffer(jd->ports[i], nframes);
|
|
|
|
jack_ringbuffer_read(jd->ringbuffer[i],
|
2008-10-24 16:56:08 +02:00
|
|
|
(char *)out, available * sample_size);
|
2007-03-23 12:07:04 +01:00
|
|
|
|
2008-10-24 16:56:08 +02:00
|
|
|
while (available < nframes)
|
2008-10-24 16:55:51 +02:00
|
|
|
/* ringbuffer underrun, fill with silence */
|
2008-10-24 16:56:08 +02:00
|
|
|
out[available++] = 0.0;
|
2007-04-09 22:18:11 +02:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2008-09-24 07:20:55 +02:00
|
|
|
static void set_audioformat(JackData *jd, struct audio_format *audioFormat)
|
2006-10-18 04:49:13 +02:00
|
|
|
{
|
2008-10-10 14:40:54 +02:00
|
|
|
audioFormat->sample_rate = jack_get_sample_rate(jd->client);
|
|
|
|
DEBUG("samplerate = %u\n", audioFormat->sample_rate);
|
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)
|
2008-10-10 14:40:54 +02:00
|
|
|
* audioFormat->sample_rate;
|
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);
|
|
|
|
}
|
|
|
|
|
2008-10-24 08:44:40 +02:00
|
|
|
static void *
|
|
|
|
jack_initDriver(struct audio_output *ao,
|
|
|
|
mpd_unused const struct audio_format *audio_format,
|
|
|
|
ConfigParam *param)
|
2006-12-30 01:14:45 +01:00
|
|
|
{
|
2008-08-26 08:27:16 +02:00
|
|
|
JackData *jd;
|
2006-12-30 01:14:45 +01:00
|
|
|
BlockParam *bp;
|
|
|
|
char *endptr;
|
|
|
|
int val;
|
2008-06-13 09:39:11 +02:00
|
|
|
char *cp = NULL;
|
|
|
|
|
2008-09-24 07:20:55 +02:00
|
|
|
jd = newJackData();
|
|
|
|
jd->ao = ao;
|
2006-12-30 01:14:45 +01:00
|
|
|
|
2007-05-23 14:24:12 +02:00
|
|
|
DEBUG("jack_initDriver (pid=%d)\n", getpid());
|
2008-09-24 07:20:55 +02:00
|
|
|
if (param == NULL)
|
|
|
|
return jd;
|
2006-12-30 01:14:45 +01:00
|
|
|
|
|
|
|
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';
|
2008-08-26 08:27:16 +02:00
|
|
|
jd->output_ports[0] = xstrdup(bp->value);
|
2007-01-14 03:08:27 +01:00
|
|
|
*cp++ = ',';
|
|
|
|
|
|
|
|
if (!*cp)
|
|
|
|
FATAL("expected a second value for '%s' at line %d: "
|
|
|
|
"%s\n", bp->name, bp->line, bp->value);
|
|
|
|
|
2008-08-26 08:27:16 +02:00
|
|
|
jd->output_ports[1] = xstrdup(cp);
|
2007-01-14 03:08:27 +01:00
|
|
|
|
|
|
|
if (strchr(cp,','))
|
|
|
|
FATAL("Only %d values are supported for '%s' "
|
2008-08-26 08:27:16 +02:00
|
|
|
"at line %d\n",
|
|
|
|
(int)ARRAY_SIZE(jd->output_ports),
|
2007-01-14 05:25:22 +01:00
|
|
|
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) {
|
2008-08-26 08:27:16 +02:00
|
|
|
jd->ringbuf_sz = val < 32768 ? 32768 : val;
|
|
|
|
DEBUG("ringbuffer_size=%d\n", jd->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",
|
2008-08-26 08:27:16 +02:00
|
|
|
bp->value, jd->ringbuf_sz);
|
2006-12-30 01:14:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( (bp = getBlockParam(param, "name"))
|
|
|
|
&& (strcmp(bp->value, "mpd") != 0) ) {
|
2008-08-26 08:27:16 +02:00
|
|
|
jd->name = xstrdup(bp->value);
|
|
|
|
DEBUG("name=%s\n", jd->name);
|
2006-12-30 01:14:45 +01:00
|
|
|
}
|
|
|
|
|
2008-09-24 07:20:55 +02:00
|
|
|
return jd;
|
2006-12-30 01:14:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static int jack_testDefault(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-09-24 07:20:55 +02:00
|
|
|
static int connect_jack(JackData *jd, struct audio_format *audio_format)
|
2006-10-18 04:49:13 +02:00
|
|
|
{
|
2008-09-07 19:14:39 +02:00
|
|
|
const char **jports;
|
2006-12-30 01:14:45 +01:00
|
|
|
char *port_name;
|
2006-10-18 04:49:13 +02:00
|
|
|
|
2008-09-24 07:20:36 +02:00
|
|
|
jd->audio_format = audio_format;
|
|
|
|
|
2008-08-26 08:27:16 +02:00
|
|
|
if ( (jd->client = jack_client_new(jd->name)) == NULL ) {
|
2006-12-30 01:14:45 +01:00
|
|
|
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,
|
2008-09-24 07:20:55 +02:00
|
|
|
(void *)jd);
|
2006-12-30 01:14:45 +01:00
|
|
|
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 */
|
2008-10-24 08:44:40 +02:00
|
|
|
if (!jd->output_ports[1] &&
|
|
|
|
(jports = jack_get_ports(jd->client, NULL, NULL,
|
|
|
|
JackPortIsPhysical | JackPortIsInput))) {
|
2008-08-26 08:27:16 +02:00
|
|
|
jd->output_ports[0] = jports[0];
|
|
|
|
jd->output_ports[1] = jports[1] ? jports[1] : jports[0];
|
|
|
|
DEBUG("output_ports: %s %s\n",
|
|
|
|
jd->output_ports[0], jd->output_ports[1]);
|
2006-12-30 01:14:45 +01:00
|
|
|
free(jports);
|
2006-10-18 04:49:13 +02:00
|
|
|
}
|
|
|
|
|
2008-08-26 08:27:16 +02:00
|
|
|
if ( jd->output_ports[1] ) {
|
|
|
|
jd->ringbuffer[0] = jack_ringbuffer_create(jd->ringbuf_sz);
|
|
|
|
jd->ringbuffer[1] = jack_ringbuffer_create(jd->ringbuf_sz);
|
2006-12-30 01:14:45 +01:00
|
|
|
memset(jd->ringbuffer[0]->buf, 0, jd->ringbuffer[0]->size);
|
|
|
|
memset(jd->ringbuffer[1]->buf, 0, jd->ringbuffer[1]->size);
|
|
|
|
|
2008-08-26 08:27:16 +02:00
|
|
|
port_name = xmalloc(sizeof(char)*(7+strlen(jd->name)));
|
2006-12-30 01:14:45 +01:00
|
|
|
|
2008-08-26 08:27:16 +02:00
|
|
|
sprintf(port_name, "%s:left", jd->name);
|
2007-01-20 22:04:32 +01:00
|
|
|
if ( (jack_connect(jd->client, port_name,
|
2008-08-26 08:27:16 +02:00
|
|
|
jd->output_ports[0])) != 0 ) {
|
2007-08-27 23:03:22 +02:00
|
|
|
ERROR("%s is not a valid Jack Client / Port\n",
|
2008-08-26 08:27:16 +02:00
|
|
|
jd->output_ports[0]);
|
2006-12-30 01:14:45 +01:00
|
|
|
free(port_name);
|
2006-10-18 04:49:13 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2008-08-26 08:27:16 +02:00
|
|
|
sprintf(port_name, "%s:right", jd->name);
|
2007-01-20 22:04:32 +01:00
|
|
|
if ( (jack_connect(jd->client, port_name,
|
2008-08-26 08:27:16 +02:00
|
|
|
jd->output_ports[1])) != 0 ) {
|
2007-08-27 23:03:22 +02:00
|
|
|
ERROR("%s is not a valid Jack Client / Port\n",
|
2008-08-26 08:27:16 +02:00
|
|
|
jd->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;
|
|
|
|
}
|
|
|
|
|
2008-09-24 07:20:55 +02:00
|
|
|
static int jack_openDevice(void *data,
|
2008-09-24 07:20:36 +02:00
|
|
|
struct audio_format *audio_format)
|
2006-10-18 04:49:13 +02:00
|
|
|
{
|
2008-09-24 07:20:55 +02:00
|
|
|
JackData *jd = 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-09-24 07:20:55 +02:00
|
|
|
if (jd->client == NULL && connect_jack(jd, audio_format) < 0) {
|
2008-08-26 08:27:15 +02:00
|
|
|
freeJackClient(jd);
|
2008-08-26 08:27:15 +02:00
|
|
|
return -1;
|
2006-10-18 04:49:13 +02:00
|
|
|
}
|
|
|
|
|
2008-09-24 07:20:55 +02:00
|
|
|
set_audioformat(jd, audio_format);
|
2006-10-18 04:49:13 +02:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-24 07:20:55 +02:00
|
|
|
static void jack_closeDevice(mpd_unused void *data)
|
2006-10-18 04:49:13 +02:00
|
|
|
{
|
2007-01-20 22:04:32 +01:00
|
|
|
/*jack_finishDriver(audioOutput);*/
|
2007-05-23 14:24:12 +02:00
|
|
|
DEBUG("jack_closeDevice (pid=%d)\n", getpid());
|
2006-10-18 04:49:13 +02:00
|
|
|
}
|
|
|
|
|
2008-09-24 07:20:55 +02:00
|
|
|
static void jack_dropBufferedAudio (mpd_unused void *data)
|
2006-10-18 04:49:13 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-09-24 07:20:55 +02:00
|
|
|
static int jack_playAudio(void *data,
|
2008-04-12 06:15:52 +02:00
|
|
|
const char *buff, size_t size)
|
2006-10-18 04:49:13 +02:00
|
|
|
{
|
2008-09-24 07:20:55 +02:00
|
|
|
JackData *jd = data;
|
2008-10-24 16:39:43 +02:00
|
|
|
size_t space, space1;
|
2008-04-12 06:15:52 +02:00
|
|
|
const short *buffer = (const short *) buff;
|
2008-10-24 15:47:52 +02:00
|
|
|
static const size_t frame_size = sizeof(*buffer) * 2;
|
2007-03-23 22:23:41 +01:00
|
|
|
jack_default_audio_sample_t sample;
|
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
|
|
|
|
2008-10-24 08:44:40 +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);
|
2008-09-24 07:20:55 +02:00
|
|
|
audio_output_closed(jd->ao);
|
2006-10-18 04:49:13 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-10-24 16:56:10 +02:00
|
|
|
assert(size % frame_size == 0);
|
2008-10-24 16:39:43 +02:00
|
|
|
size /= frame_size;
|
|
|
|
while (size > 0 && !jd->shutdown) {
|
2008-10-24 08:44:40 +02:00
|
|
|
space = jack_ringbuffer_write_space(jd->ringbuffer[0]);
|
2008-10-24 16:39:43 +02:00
|
|
|
space1 = jack_ringbuffer_write_space(jd->ringbuffer[1]);
|
|
|
|
if (space > space1)
|
|
|
|
/* send data symmetrically */
|
|
|
|
space = space1;
|
|
|
|
|
|
|
|
space /= sample_size;
|
|
|
|
if (space > 0) {
|
|
|
|
if (space > size)
|
|
|
|
space = size;
|
|
|
|
|
|
|
|
size -= space;
|
|
|
|
while (space-- > 0) {
|
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
|
|
|
}
|
2008-10-24 08:44:40 +02:00
|
|
|
} else {
|
2008-10-24 16:55:51 +02:00
|
|
|
/* XXX do something more intelligent to
|
|
|
|
synchronize */
|
|
|
|
my_usleep(10000);
|
2007-04-11 19:41:10 +02:00
|
|
|
}
|
2006-12-30 01:14:45 +01:00
|
|
|
|
2007-04-09 22:18:11 +02:00
|
|
|
}
|
2008-10-24 08:44:40 +02:00
|
|
|
|
2006-10-18 04:49:13 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-09-08 11:43:38 +02:00
|
|
|
const struct audio_output_plugin jackPlugin = {
|
2008-09-29 15:55:17 +02:00
|
|
|
.name = "jack",
|
|
|
|
.test_default_device = jack_testDefault,
|
|
|
|
.init = jack_initDriver,
|
|
|
|
.finish = jack_finishDriver,
|
|
|
|
.open = jack_openDevice,
|
|
|
|
.play = jack_playAudio,
|
|
|
|
.cancel = jack_dropBufferedAudio,
|
|
|
|
.close = jack_closeDevice,
|
2006-10-18 04:49:13 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#else /* HAVE JACK */
|
|
|
|
|
|
|
|
DISABLED_AUDIO_OUTPUT_PLUGIN(jackPlugin)
|
|
|
|
|
|
|
|
#endif /* HAVE_JACK */
|