2009-03-13 18:43:16 +01:00
|
|
|
/*
|
2013-04-17 00:24:44 +02:00
|
|
|
* Copyright (C) 2003-2013 The Music Player Daemon Project
|
2009-03-13 18:43:16 +01:00
|
|
|
* http://www.musicpd.org
|
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.
|
2009-03-13 18:43:16 +01:00
|
|
|
*
|
|
|
|
* 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.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2006-10-18 04:49:13 +02:00
|
|
|
*/
|
|
|
|
|
2009-02-16 18:41:30 +01:00
|
|
|
#include "config.h"
|
2013-04-17 00:24:44 +02:00
|
|
|
#include "JackOutputPlugin.hxx"
|
2013-07-30 08:34:10 +02:00
|
|
|
#include "OutputAPI.hxx"
|
2006-10-18 04:49:13 +02:00
|
|
|
|
2008-10-08 10:49:29 +02:00
|
|
|
#include <assert.h>
|
|
|
|
|
2008-11-01 14:04:14 +01:00
|
|
|
#include <glib.h>
|
2006-10-18 04:49:13 +02:00
|
|
|
#include <jack/jack.h>
|
|
|
|
#include <jack/types.h>
|
|
|
|
#include <jack/ringbuffer.h>
|
|
|
|
|
2009-01-02 17:23:10 +01:00
|
|
|
#include <stdlib.h>
|
2013-07-30 20:11:57 +02:00
|
|
|
#include <string.h>
|
2009-01-02 17:23:10 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2008-12-29 17:29:36 +01:00
|
|
|
#undef G_LOG_DOMAIN
|
|
|
|
#define G_LOG_DOMAIN "jack"
|
|
|
|
|
2009-11-06 18:55:26 +01:00
|
|
|
enum {
|
|
|
|
MAX_PORTS = 16,
|
|
|
|
};
|
|
|
|
|
2011-03-16 18:08:54 +01:00
|
|
|
static const size_t jack_sample_size = sizeof(jack_default_audio_sample_t);
|
2006-10-18 04:49:13 +02:00
|
|
|
|
2013-04-17 00:24:44 +02:00
|
|
|
struct JackOutput {
|
2011-09-16 23:31:48 +02:00
|
|
|
struct audio_output base;
|
|
|
|
|
2009-11-05 20:01:18 +01:00
|
|
|
/**
|
|
|
|
* libjack options passed to jack_client_open().
|
|
|
|
*/
|
|
|
|
jack_options_t options;
|
|
|
|
|
2009-02-25 17:32:58 +01:00
|
|
|
const char *name;
|
2008-09-24 07:20:55 +02:00
|
|
|
|
2009-11-07 17:26:21 +01:00
|
|
|
const char *server_name;
|
|
|
|
|
2008-08-26 08:27:16 +02:00
|
|
|
/* configuration */
|
2009-11-06 01:35:19 +01:00
|
|
|
|
2009-11-06 18:58:35 +01:00
|
|
|
char *source_ports[MAX_PORTS];
|
|
|
|
unsigned num_source_ports;
|
|
|
|
|
2009-11-06 18:55:26 +01:00
|
|
|
char *destination_ports[MAX_PORTS];
|
|
|
|
unsigned num_destination_ports;
|
2009-11-06 01:35:19 +01:00
|
|
|
|
2009-10-21 21:39:26 +02:00
|
|
|
size_t ringbuffer_size;
|
2008-08-26 08:27:16 +02:00
|
|
|
|
2009-01-30 19:43:31 +01:00
|
|
|
/* the current audio format */
|
2013-08-03 21:00:50 +02:00
|
|
|
AudioFormat audio_format;
|
2008-09-24 07:20:36 +02:00
|
|
|
|
2008-08-26 08:27:16 +02:00
|
|
|
/* jack library stuff */
|
2009-11-06 18:58:35 +01:00
|
|
|
jack_port_t *ports[MAX_PORTS];
|
2006-10-18 04:49:13 +02:00
|
|
|
jack_client_t *client;
|
2009-11-06 18:58:35 +01:00
|
|
|
jack_ringbuffer_t *ringbuffer[MAX_PORTS];
|
2009-01-29 23:15:55 +01:00
|
|
|
|
2009-01-29 23:15:27 +01:00
|
|
|
bool shutdown;
|
2009-10-21 18:33:05 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* While this flag is set, the "process" callback generates
|
|
|
|
* silence.
|
|
|
|
*/
|
|
|
|
bool pause;
|
2013-04-17 00:24:44 +02:00
|
|
|
|
2013-08-04 12:25:08 +02:00
|
|
|
bool Initialize(const config_param ¶m, GError **error_r) {
|
2013-04-17 00:24:44 +02:00
|
|
|
return ao_base_init(&base, &jack_output_plugin, param,
|
|
|
|
error_r);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Deinitialize() {
|
|
|
|
ao_base_finish(&base);
|
|
|
|
}
|
2008-10-24 17:29:37 +02:00
|
|
|
};
|
2006-10-18 04:49:13 +02:00
|
|
|
|
2009-02-26 22:04:59 +01:00
|
|
|
/**
|
|
|
|
* The quark used for GError.domain.
|
|
|
|
*/
|
|
|
|
static inline GQuark
|
|
|
|
jack_output_quark(void)
|
|
|
|
{
|
|
|
|
return g_quark_from_static_string("jack_output");
|
|
|
|
}
|
|
|
|
|
2010-03-10 19:18:51 +01:00
|
|
|
/**
|
|
|
|
* Determine the number of frames guaranteed to be available on all
|
|
|
|
* channels.
|
|
|
|
*/
|
|
|
|
static jack_nframes_t
|
2013-04-17 00:24:44 +02:00
|
|
|
mpd_jack_available(const JackOutput *jd)
|
2010-03-10 19:18:51 +01:00
|
|
|
{
|
|
|
|
size_t min = jack_ringbuffer_read_space(jd->ringbuffer[0]);
|
|
|
|
|
|
|
|
for (unsigned i = 1; i < jd->audio_format.channels; ++i) {
|
|
|
|
size_t current = jack_ringbuffer_read_space(jd->ringbuffer[i]);
|
|
|
|
if (current < min)
|
|
|
|
min = current;
|
|
|
|
}
|
|
|
|
|
2011-03-16 18:08:54 +01:00
|
|
|
assert(min % jack_sample_size == 0);
|
2010-03-10 19:18:51 +01:00
|
|
|
|
2011-03-16 18:08:54 +01:00
|
|
|
return min / jack_sample_size;
|
2010-03-10 19:18:51 +01:00
|
|
|
}
|
|
|
|
|
2008-10-24 17:29:37 +02:00
|
|
|
static int
|
|
|
|
mpd_jack_process(jack_nframes_t nframes, void *arg)
|
2006-10-18 04:49:13 +02:00
|
|
|
{
|
2013-04-17 00:24:44 +02:00
|
|
|
JackOutput *jd = (JackOutput *) arg;
|
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;
|
|
|
|
|
2009-10-21 18:33:05 +02:00
|
|
|
if (jd->pause) {
|
2010-03-10 19:48:27 +01:00
|
|
|
/* empty the ring buffers */
|
|
|
|
|
|
|
|
const jack_nframes_t available = mpd_jack_available(jd);
|
|
|
|
for (unsigned i = 0; i < jd->audio_format.channels; ++i)
|
|
|
|
jack_ringbuffer_read_advance(jd->ringbuffer[i],
|
2011-03-16 18:08:54 +01:00
|
|
|
available * jack_sample_size);
|
2010-03-10 19:48:27 +01:00
|
|
|
|
2009-10-21 18:33:05 +02:00
|
|
|
/* generate silence while MPD is paused */
|
|
|
|
|
2009-11-05 20:02:04 +01:00
|
|
|
for (unsigned i = 0; i < jd->audio_format.channels; ++i) {
|
2013-04-17 00:24:44 +02:00
|
|
|
jack_default_audio_sample_t *out =
|
|
|
|
(jack_default_audio_sample_t *)
|
|
|
|
jack_port_get_buffer(jd->ports[i], nframes);
|
2009-10-21 18:33:05 +02:00
|
|
|
|
|
|
|
for (jack_nframes_t f = 0; f < nframes; ++f)
|
|
|
|
out[f] = 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-03-10 19:18:51 +01:00
|
|
|
jack_nframes_t available = mpd_jack_available(jd);
|
|
|
|
if (available > nframes)
|
|
|
|
available = nframes;
|
2007-03-23 12:07:04 +01:00
|
|
|
|
2010-03-10 19:18:51 +01:00
|
|
|
for (unsigned i = 0; i < jd->audio_format.channels; ++i) {
|
2013-04-17 00:24:44 +02:00
|
|
|
jack_default_audio_sample_t *out =
|
|
|
|
(jack_default_audio_sample_t *)
|
|
|
|
jack_port_get_buffer(jd->ports[i], nframes);
|
|
|
|
if (out == nullptr)
|
2012-04-04 21:38:29 +02:00
|
|
|
/* workaround for libjack1 bug: if the server
|
|
|
|
connection fails, the process callback is
|
|
|
|
invoked anyway, but unable to get a
|
|
|
|
buffer */
|
|
|
|
continue;
|
|
|
|
|
2008-10-24 16:55:51 +02:00
|
|
|
jack_ringbuffer_read(jd->ringbuffer[i],
|
2011-03-16 18:08:54 +01:00
|
|
|
(char *)out, available * jack_sample_size);
|
2007-03-23 12:07:04 +01:00
|
|
|
|
2010-03-10 19:18:51 +01:00
|
|
|
for (jack_nframes_t f = available; f < nframes; ++f)
|
2008-10-24 16:55:51 +02:00
|
|
|
/* ringbuffer underrun, fill with silence */
|
2010-03-10 19:18:51 +01:00
|
|
|
out[f] = 0.0;
|
2007-04-09 22:18:11 +02:00
|
|
|
}
|
|
|
|
|
2009-11-06 18:58:35 +01:00
|
|
|
/* generate silence for the unused source ports */
|
|
|
|
|
|
|
|
for (unsigned i = jd->audio_format.channels;
|
|
|
|
i < jd->num_source_ports; ++i) {
|
2013-04-17 00:24:44 +02:00
|
|
|
jack_default_audio_sample_t *out =
|
|
|
|
(jack_default_audio_sample_t *)
|
|
|
|
jack_port_get_buffer(jd->ports[i], nframes);
|
|
|
|
if (out == nullptr)
|
2012-04-04 21:38:29 +02:00
|
|
|
/* workaround for libjack1 bug: if the server
|
|
|
|
connection fails, the process callback is
|
|
|
|
invoked anyway, but unable to get a
|
|
|
|
buffer */
|
|
|
|
continue;
|
2009-11-06 18:58:35 +01:00
|
|
|
|
|
|
|
for (jack_nframes_t f = 0; f < nframes; ++f)
|
|
|
|
out[f] = 0.0;
|
|
|
|
}
|
|
|
|
|
2006-10-18 04:49:13 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-10-24 17:29:37 +02:00
|
|
|
static void
|
|
|
|
mpd_jack_shutdown(void *arg)
|
2006-10-18 04:49:13 +02:00
|
|
|
{
|
2013-04-17 00:24:44 +02:00
|
|
|
JackOutput *jd = (JackOutput *) arg;
|
2009-01-29 23:15:27 +01:00
|
|
|
jd->shutdown = true;
|
2006-10-18 04:49:13 +02:00
|
|
|
}
|
|
|
|
|
2008-10-24 17:29:37 +02:00
|
|
|
static void
|
2013-08-03 21:00:50 +02:00
|
|
|
set_audioformat(JackOutput *jd, AudioFormat &audio_format)
|
2006-10-18 04:49:13 +02:00
|
|
|
{
|
2013-08-03 21:00:50 +02:00
|
|
|
audio_format.sample_rate = jack_get_sample_rate(jd->client);
|
2009-11-05 20:02:04 +01:00
|
|
|
|
2009-11-06 18:58:35 +01:00
|
|
|
if (jd->num_source_ports == 1)
|
2013-08-03 21:00:50 +02:00
|
|
|
audio_format.channels = 1;
|
|
|
|
else if (audio_format.channels > jd->num_source_ports)
|
|
|
|
audio_format.channels = 2;
|
2008-10-24 17:36:11 +02:00
|
|
|
|
2013-08-03 21:00:50 +02:00
|
|
|
if (audio_format.format != SampleFormat::S16 &&
|
|
|
|
audio_format.format != SampleFormat::S24_P32)
|
|
|
|
audio_format.format = SampleFormat::S24_P32;
|
2006-10-18 04:49:13 +02:00
|
|
|
}
|
|
|
|
|
2008-10-24 17:29:37 +02:00
|
|
|
static void
|
|
|
|
mpd_jack_error(const char *msg)
|
2006-12-30 01:14:45 +01:00
|
|
|
{
|
2008-12-29 17:29:36 +01:00
|
|
|
g_warning("%s", msg);
|
2006-12-30 01:14:45 +01:00
|
|
|
}
|
|
|
|
|
2009-01-30 19:43:25 +01:00
|
|
|
#ifdef HAVE_JACK_SET_INFO_FUNCTION
|
2009-01-30 15:57:43 +01:00
|
|
|
static void
|
|
|
|
mpd_jack_info(const char *msg)
|
|
|
|
{
|
|
|
|
g_message("%s", msg);
|
|
|
|
}
|
2009-01-30 19:43:25 +01:00
|
|
|
#endif
|
2009-01-30 15:57:43 +01:00
|
|
|
|
2009-10-21 21:37:11 +02:00
|
|
|
/**
|
|
|
|
* Disconnect the JACK client.
|
|
|
|
*/
|
|
|
|
static void
|
2013-04-17 00:24:44 +02:00
|
|
|
mpd_jack_disconnect(JackOutput *jd)
|
2009-10-21 21:37:11 +02:00
|
|
|
{
|
2013-04-17 00:24:44 +02:00
|
|
|
assert(jd != nullptr);
|
|
|
|
assert(jd->client != nullptr);
|
2009-10-21 21:37:11 +02:00
|
|
|
|
|
|
|
jack_deactivate(jd->client);
|
|
|
|
jack_client_close(jd->client);
|
2013-04-17 00:24:44 +02:00
|
|
|
jd->client = nullptr;
|
2009-10-21 21:37:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Connect the JACK client and performs some basic setup
|
|
|
|
* (e.g. register callbacks).
|
|
|
|
*/
|
|
|
|
static bool
|
2013-04-17 00:24:44 +02:00
|
|
|
mpd_jack_connect(JackOutput *jd, GError **error_r)
|
2009-10-21 21:37:11 +02:00
|
|
|
{
|
2009-11-05 20:01:18 +01:00
|
|
|
jack_status_t status;
|
|
|
|
|
2013-04-17 00:24:44 +02:00
|
|
|
assert(jd != nullptr);
|
2009-10-21 21:37:11 +02:00
|
|
|
|
|
|
|
jd->shutdown = false;
|
|
|
|
|
2009-11-07 17:26:21 +01:00
|
|
|
jd->client = jack_client_open(jd->name, jd->options, &status,
|
|
|
|
jd->server_name);
|
2013-04-17 00:24:44 +02:00
|
|
|
if (jd->client == nullptr) {
|
2009-10-21 21:37:11 +02:00
|
|
|
g_set_error(error_r, jack_output_quark(), 0,
|
2009-11-05 20:01:18 +01:00
|
|
|
"Failed to connect to JACK server, status=%d",
|
|
|
|
status);
|
2009-10-21 21:37:11 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
jack_set_process_callback(jd->client, mpd_jack_process, jd);
|
|
|
|
jack_on_shutdown(jd->client, mpd_jack_shutdown, jd);
|
|
|
|
|
2009-11-06 18:58:35 +01:00
|
|
|
for (unsigned i = 0; i < jd->num_source_ports; ++i) {
|
|
|
|
jd->ports[i] = jack_port_register(jd->client,
|
|
|
|
jd->source_ports[i],
|
2009-10-21 21:37:11 +02:00
|
|
|
JACK_DEFAULT_AUDIO_TYPE,
|
|
|
|
JackPortIsOutput, 0);
|
2013-04-17 00:24:44 +02:00
|
|
|
if (jd->ports[i] == nullptr) {
|
2009-10-21 21:37:11 +02:00
|
|
|
g_set_error(error_r, jack_output_quark(), 0,
|
|
|
|
"Cannot register output port \"%s\"",
|
2009-11-06 18:58:35 +01:00
|
|
|
jd->source_ports[i]);
|
2009-10-21 21:37:11 +02:00
|
|
|
mpd_jack_disconnect(jd);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
mpd_jack_test_default_device(void)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-11-06 18:55:26 +01:00
|
|
|
static unsigned
|
|
|
|
parse_port_list(int line, const char *source, char **dest, GError **error_r)
|
|
|
|
{
|
|
|
|
char **list = g_strsplit(source, ",", 0);
|
|
|
|
unsigned n = 0;
|
|
|
|
|
2013-04-17 00:24:44 +02:00
|
|
|
for (n = 0; list[n] != nullptr; ++n) {
|
2009-11-06 18:55:26 +01:00
|
|
|
if (n >= MAX_PORTS) {
|
|
|
|
g_set_error(error_r, jack_output_quark(), 0,
|
|
|
|
"too many port names in line %d",
|
|
|
|
line);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
dest[n] = list[n];
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free(list);
|
|
|
|
|
|
|
|
if (n == 0) {
|
|
|
|
g_set_error(error_r, jack_output_quark(), 0,
|
|
|
|
"at least one port name expected in line %d",
|
|
|
|
line);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2011-09-16 23:31:48 +02:00
|
|
|
static struct audio_output *
|
2013-08-04 12:25:08 +02:00
|
|
|
mpd_jack_init(const config_param ¶m, GError **error_r)
|
2006-12-30 01:14:45 +01:00
|
|
|
{
|
2013-04-17 00:24:44 +02:00
|
|
|
JackOutput *jd = new JackOutput();
|
2011-09-16 23:31:48 +02:00
|
|
|
|
2013-04-17 00:24:44 +02:00
|
|
|
if (!jd->Initialize(param, error_r)) {
|
|
|
|
delete jd;
|
|
|
|
return nullptr;
|
2011-09-16 23:31:48 +02:00
|
|
|
}
|
|
|
|
|
2009-01-18 19:37:27 +01:00
|
|
|
const char *value;
|
2008-06-13 09:39:11 +02:00
|
|
|
|
2009-11-05 20:01:18 +01:00
|
|
|
jd->options = JackNullOption;
|
|
|
|
|
2013-08-04 12:25:08 +02:00
|
|
|
jd->name = param.GetBlockValue("client_name", nullptr);
|
2013-04-17 00:24:44 +02:00
|
|
|
if (jd->name != nullptr)
|
|
|
|
jd->options = jack_options_t(jd->options | JackUseExactName);
|
2009-11-05 20:01:18 +01:00
|
|
|
else
|
|
|
|
/* if there's a no configured client name, we don't
|
|
|
|
care about the JackUseExactName option */
|
|
|
|
jd->name = "Music Player Daemon";
|
|
|
|
|
2013-08-04 12:25:08 +02:00
|
|
|
jd->server_name = param.GetBlockValue("server_name", nullptr);
|
2013-04-17 00:24:44 +02:00
|
|
|
if (jd->server_name != nullptr)
|
|
|
|
jd->options = jack_options_t(jd->options | JackServerName);
|
2009-11-07 17:26:21 +01:00
|
|
|
|
2013-08-04 12:25:08 +02:00
|
|
|
if (!param.GetBlockValue("autostart", false))
|
2013-04-17 00:24:44 +02:00
|
|
|
jd->options = jack_options_t(jd->options | JackNoStartServer);
|
2006-12-30 01:14:45 +01:00
|
|
|
|
2009-11-06 18:58:35 +01:00
|
|
|
/* configure the source ports */
|
|
|
|
|
2013-08-04 12:25:08 +02:00
|
|
|
value = param.GetBlockValue("source_ports", "left,right");
|
|
|
|
jd->num_source_ports = parse_port_list(param.line, value,
|
2009-11-06 18:58:35 +01:00
|
|
|
jd->source_ports, error_r);
|
|
|
|
if (jd->num_source_ports == 0)
|
2013-04-17 00:24:44 +02:00
|
|
|
return nullptr;
|
2009-11-06 18:58:35 +01:00
|
|
|
|
|
|
|
/* configure the destination ports */
|
|
|
|
|
2013-08-04 12:25:08 +02:00
|
|
|
value = param.GetBlockValue("destination_ports", nullptr);
|
2013-04-17 00:24:44 +02:00
|
|
|
if (value == nullptr) {
|
2009-11-06 01:54:58 +01:00
|
|
|
/* compatibility with MPD < 0.16 */
|
2013-08-04 12:25:08 +02:00
|
|
|
value = param.GetBlockValue("ports", nullptr);
|
2013-04-17 00:24:44 +02:00
|
|
|
if (value != nullptr)
|
2009-11-06 01:54:58 +01:00
|
|
|
g_warning("deprecated option 'ports' in line %d",
|
2013-08-04 12:25:08 +02:00
|
|
|
param.line);
|
2009-11-06 01:54:58 +01:00
|
|
|
}
|
|
|
|
|
2013-04-17 00:24:44 +02:00
|
|
|
if (value != nullptr) {
|
2009-11-06 18:55:26 +01:00
|
|
|
jd->num_destination_ports =
|
2013-08-04 12:25:08 +02:00
|
|
|
parse_port_list(param.line, value,
|
2009-11-06 18:55:26 +01:00
|
|
|
jd->destination_ports, error_r);
|
|
|
|
if (jd->num_destination_ports == 0)
|
2013-04-17 00:24:44 +02:00
|
|
|
return nullptr;
|
2009-01-29 23:16:30 +01:00
|
|
|
} else {
|
2009-11-06 18:55:26 +01:00
|
|
|
jd->num_destination_ports = 0;
|
2006-12-30 01:14:45 +01:00
|
|
|
}
|
|
|
|
|
2009-11-06 18:58:35 +01:00
|
|
|
if (jd->num_destination_ports > 0 &&
|
|
|
|
jd->num_destination_ports != jd->num_source_ports)
|
|
|
|
g_warning("number of source ports (%u) mismatches the "
|
|
|
|
"number of destination ports (%u) in line %d",
|
|
|
|
jd->num_source_ports, jd->num_destination_ports,
|
2013-08-04 12:25:08 +02:00
|
|
|
param.line);
|
2009-11-06 18:58:35 +01:00
|
|
|
|
2013-08-04 12:25:08 +02:00
|
|
|
jd->ringbuffer_size = param.GetBlockValue("ringbuffer_size", 32768u);
|
2006-12-30 01:14:45 +01:00
|
|
|
|
2009-01-29 23:12:08 +01:00
|
|
|
jack_set_error_function(mpd_jack_error);
|
2009-01-30 19:43:25 +01:00
|
|
|
|
|
|
|
#ifdef HAVE_JACK_SET_INFO_FUNCTION
|
2009-01-30 15:57:43 +01:00
|
|
|
jack_set_info_function(mpd_jack_info);
|
2009-01-30 19:43:25 +01:00
|
|
|
#endif
|
2009-01-29 23:12:08 +01:00
|
|
|
|
2011-09-16 23:31:48 +02:00
|
|
|
return &jd->base;
|
2006-12-30 01:14:45 +01:00
|
|
|
}
|
|
|
|
|
2009-10-21 21:37:11 +02:00
|
|
|
static void
|
2011-09-16 23:31:48 +02:00
|
|
|
mpd_jack_finish(struct audio_output *ao)
|
2006-12-30 01:14:45 +01:00
|
|
|
{
|
2013-04-17 00:24:44 +02:00
|
|
|
JackOutput *jd = (JackOutput *)ao;
|
2009-10-21 21:37:11 +02:00
|
|
|
|
2009-11-07 15:17:48 +01:00
|
|
|
for (unsigned i = 0; i < jd->num_source_ports; ++i)
|
|
|
|
g_free(jd->source_ports[i]);
|
|
|
|
|
2009-11-06 18:55:26 +01:00
|
|
|
for (unsigned i = 0; i < jd->num_destination_ports; ++i)
|
2009-11-06 01:35:19 +01:00
|
|
|
g_free(jd->destination_ports[i]);
|
2009-10-23 10:56:25 +02:00
|
|
|
|
2013-04-17 00:24:44 +02:00
|
|
|
jd->Deinitialize();
|
|
|
|
delete jd;
|
2009-10-23 10:56:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
2011-09-16 23:31:48 +02:00
|
|
|
mpd_jack_enable(struct audio_output *ao, GError **error_r)
|
2009-10-23 10:56:25 +02:00
|
|
|
{
|
2013-04-17 00:24:44 +02:00
|
|
|
JackOutput *jd = (JackOutput *)ao;
|
2009-10-23 10:56:25 +02:00
|
|
|
|
2009-11-06 18:58:35 +01:00
|
|
|
for (unsigned i = 0; i < jd->num_source_ports; ++i)
|
2013-04-17 00:24:44 +02:00
|
|
|
jd->ringbuffer[i] = nullptr;
|
2009-10-23 10:56:25 +02:00
|
|
|
|
|
|
|
return mpd_jack_connect(jd, error_r);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-09-16 23:31:48 +02:00
|
|
|
mpd_jack_disable(struct audio_output *ao)
|
2009-10-23 10:56:25 +02:00
|
|
|
{
|
2013-04-17 00:24:44 +02:00
|
|
|
JackOutput *jd = (JackOutput *)ao;
|
2009-10-23 10:56:25 +02:00
|
|
|
|
2013-04-17 00:24:44 +02:00
|
|
|
if (jd->client != nullptr)
|
2009-10-21 21:37:11 +02:00
|
|
|
mpd_jack_disconnect(jd);
|
|
|
|
|
2009-11-06 18:58:35 +01:00
|
|
|
for (unsigned i = 0; i < jd->num_source_ports; ++i) {
|
2013-04-17 00:24:44 +02:00
|
|
|
if (jd->ringbuffer[i] != nullptr) {
|
2009-10-21 21:37:11 +02:00
|
|
|
jack_ringbuffer_free(jd->ringbuffer[i]);
|
2013-04-17 00:24:44 +02:00
|
|
|
jd->ringbuffer[i] = nullptr;
|
2009-10-21 21:37:11 +02:00
|
|
|
}
|
|
|
|
}
|
2006-12-30 01:14:45 +01:00
|
|
|
}
|
|
|
|
|
2009-10-21 21:37:11 +02:00
|
|
|
/**
|
|
|
|
* Stops the playback on the JACK connection.
|
|
|
|
*/
|
|
|
|
static void
|
2013-04-17 00:24:44 +02:00
|
|
|
mpd_jack_stop(JackOutput *jd)
|
2006-10-18 04:49:13 +02:00
|
|
|
{
|
2013-04-17 00:24:44 +02:00
|
|
|
assert(jd != nullptr);
|
2009-01-30 19:44:58 +01:00
|
|
|
|
2013-04-17 00:24:44 +02:00
|
|
|
if (jd->client == nullptr)
|
2009-10-21 21:37:11 +02:00
|
|
|
return;
|
2009-01-29 18:11:30 +01:00
|
|
|
|
2009-10-21 21:37:11 +02:00
|
|
|
if (jd->shutdown)
|
|
|
|
/* the connection has failed; close it */
|
|
|
|
mpd_jack_disconnect(jd);
|
|
|
|
else
|
|
|
|
/* the connection is alive: just stop playback */
|
|
|
|
jack_deactivate(jd->client);
|
|
|
|
}
|
2009-01-29 17:08:44 +01:00
|
|
|
|
2009-10-21 21:37:11 +02:00
|
|
|
static bool
|
2013-04-17 00:24:44 +02:00
|
|
|
mpd_jack_start(JackOutput *jd, GError **error_r)
|
2009-10-21 21:37:11 +02:00
|
|
|
{
|
2009-11-06 18:55:26 +01:00
|
|
|
const char *destination_ports[MAX_PORTS], **jports;
|
2013-04-17 00:24:44 +02:00
|
|
|
const char *duplicate_port = nullptr;
|
2009-11-06 18:55:26 +01:00
|
|
|
unsigned num_destination_ports;
|
2006-10-18 04:49:13 +02:00
|
|
|
|
2013-04-17 00:24:44 +02:00
|
|
|
assert(jd->client != nullptr);
|
2009-11-06 18:58:35 +01:00
|
|
|
assert(jd->audio_format.channels <= jd->num_source_ports);
|
2006-10-18 04:49:13 +02:00
|
|
|
|
2009-10-21 21:37:11 +02:00
|
|
|
/* allocate the ring buffers on the first open(); these
|
|
|
|
persist until MPD exits. It's too unsafe to delete them
|
|
|
|
because we can never know when mpd_jack_process() gets
|
|
|
|
called */
|
2009-11-06 18:58:35 +01:00
|
|
|
for (unsigned i = 0; i < jd->num_source_ports; ++i) {
|
2013-04-17 00:24:44 +02:00
|
|
|
if (jd->ringbuffer[i] == nullptr)
|
2009-10-21 21:37:11 +02:00
|
|
|
jd->ringbuffer[i] =
|
|
|
|
jack_ringbuffer_create(jd->ringbuffer_size);
|
2006-10-18 04:49:13 +02:00
|
|
|
|
2009-11-05 20:01:50 +01:00
|
|
|
/* clear the ring buffer to be sure that data from
|
|
|
|
previous playbacks are gone */
|
|
|
|
jack_ringbuffer_reset(jd->ringbuffer[i]);
|
|
|
|
}
|
|
|
|
|
2009-01-29 18:11:23 +01:00
|
|
|
if ( jack_activate(jd->client) ) {
|
2009-10-21 20:13:39 +02:00
|
|
|
g_set_error(error_r, jack_output_quark(), 0,
|
2009-02-26 22:04:59 +01:00
|
|
|
"cannot activate client");
|
2009-10-21 21:37:11 +02:00
|
|
|
mpd_jack_stop(jd);
|
2009-01-29 23:15:27 +01:00
|
|
|
return false;
|
2009-01-29 18:11:23 +01:00
|
|
|
}
|
|
|
|
|
2009-11-06 18:55:26 +01:00
|
|
|
if (jd->num_destination_ports == 0) {
|
2009-01-29 23:12:16 +01:00
|
|
|
/* no output ports were configured - ask libjack for
|
|
|
|
defaults */
|
2013-04-17 00:24:44 +02:00
|
|
|
jports = jack_get_ports(jd->client, nullptr, nullptr,
|
2009-01-29 23:12:16 +01:00
|
|
|
JackPortIsPhysical | JackPortIsInput);
|
2013-04-17 00:24:44 +02:00
|
|
|
if (jports == nullptr) {
|
2009-10-21 20:13:39 +02:00
|
|
|
g_set_error(error_r, jack_output_quark(), 0,
|
2009-02-26 22:04:59 +01:00
|
|
|
"no ports found");
|
2009-10-21 21:37:11 +02:00
|
|
|
mpd_jack_stop(jd);
|
2009-01-29 23:15:27 +01:00
|
|
|
return false;
|
2009-01-29 23:12:16 +01:00
|
|
|
}
|
|
|
|
|
2013-04-17 00:24:44 +02:00
|
|
|
assert(*jports != nullptr);
|
2009-11-06 18:55:26 +01:00
|
|
|
|
|
|
|
for (num_destination_ports = 0;
|
|
|
|
num_destination_ports < MAX_PORTS &&
|
2013-04-17 00:24:44 +02:00
|
|
|
jports[num_destination_ports] != nullptr;
|
2009-11-06 18:55:26 +01:00
|
|
|
++num_destination_ports) {
|
|
|
|
g_debug("destination_port[%u] = '%s'\n",
|
|
|
|
num_destination_ports,
|
|
|
|
jports[num_destination_ports]);
|
|
|
|
destination_ports[num_destination_ports] =
|
|
|
|
jports[num_destination_ports];
|
|
|
|
}
|
2009-01-30 19:44:58 +01:00
|
|
|
} else {
|
|
|
|
/* use the configured output ports */
|
|
|
|
|
2009-11-06 18:55:26 +01:00
|
|
|
num_destination_ports = jd->num_destination_ports;
|
|
|
|
memcpy(destination_ports, jd->destination_ports,
|
|
|
|
num_destination_ports * sizeof(*destination_ports));
|
2009-01-30 19:44:58 +01:00
|
|
|
|
2013-04-17 00:24:44 +02:00
|
|
|
jports = nullptr;
|
2006-10-18 04:49:13 +02:00
|
|
|
}
|
|
|
|
|
2009-11-06 18:55:26 +01:00
|
|
|
assert(num_destination_ports > 0);
|
|
|
|
|
2009-11-06 18:58:35 +01:00
|
|
|
if (jd->audio_format.channels >= 2 && num_destination_ports == 1) {
|
2009-11-06 18:55:26 +01:00
|
|
|
/* mix stereo signal on one speaker */
|
|
|
|
|
2009-11-06 18:58:35 +01:00
|
|
|
while (num_destination_ports < jd->audio_format.channels)
|
|
|
|
destination_ports[num_destination_ports++] =
|
|
|
|
destination_ports[0];
|
|
|
|
} else if (num_destination_ports > jd->audio_format.channels) {
|
|
|
|
if (jd->audio_format.channels == 1 && num_destination_ports > 2) {
|
|
|
|
/* mono input file: connect the one source
|
|
|
|
channel to the both destination channels */
|
|
|
|
duplicate_port = destination_ports[1];
|
|
|
|
num_destination_ports = 1;
|
|
|
|
} else
|
|
|
|
/* connect only as many ports as we need */
|
|
|
|
num_destination_ports = jd->audio_format.channels;
|
2009-11-06 18:55:26 +01:00
|
|
|
}
|
|
|
|
|
2009-11-06 18:58:35 +01:00
|
|
|
assert(num_destination_ports <= jd->num_source_ports);
|
2009-11-06 18:55:26 +01:00
|
|
|
|
2009-11-06 18:58:35 +01:00
|
|
|
for (unsigned i = 0; i < num_destination_ports; ++i) {
|
2009-01-29 23:14:04 +01:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = jack_connect(jd->client, jack_port_name(jd->ports[i]),
|
2009-11-06 01:35:19 +01:00
|
|
|
destination_ports[i]);
|
2009-01-29 23:14:04 +01:00
|
|
|
if (ret != 0) {
|
2009-10-21 20:13:39 +02:00
|
|
|
g_set_error(error_r, jack_output_quark(), 0,
|
2009-02-26 22:04:59 +01:00
|
|
|
"Not a valid JACK port: %s",
|
2009-11-06 01:35:19 +01:00
|
|
|
destination_ports[i]);
|
2009-01-30 19:44:58 +01:00
|
|
|
|
2013-04-17 00:24:44 +02:00
|
|
|
if (jports != nullptr)
|
2009-01-30 19:44:58 +01:00
|
|
|
free(jports);
|
|
|
|
|
2009-10-21 21:37:11 +02:00
|
|
|
mpd_jack_stop(jd);
|
2009-01-29 23:15:27 +01:00
|
|
|
return false;
|
2009-01-29 23:14:04 +01:00
|
|
|
}
|
2006-10-18 04:49:13 +02:00
|
|
|
}
|
|
|
|
|
2013-04-17 00:24:44 +02:00
|
|
|
if (duplicate_port != nullptr) {
|
2009-11-05 20:02:04 +01:00
|
|
|
/* mono input file: connect the one source channel to
|
|
|
|
the both destination channels */
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = jack_connect(jd->client, jack_port_name(jd->ports[0]),
|
2009-11-06 18:58:35 +01:00
|
|
|
duplicate_port);
|
2009-11-05 20:02:04 +01:00
|
|
|
if (ret != 0) {
|
|
|
|
g_set_error(error_r, jack_output_quark(), 0,
|
|
|
|
"Not a valid JACK port: %s",
|
2009-11-06 18:58:35 +01:00
|
|
|
duplicate_port);
|
2009-11-05 20:02:04 +01:00
|
|
|
|
2013-04-17 00:24:44 +02:00
|
|
|
if (jports != nullptr)
|
2009-11-05 20:02:04 +01:00
|
|
|
free(jports);
|
|
|
|
|
|
|
|
mpd_jack_stop(jd);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-17 00:24:44 +02:00
|
|
|
if (jports != nullptr)
|
2009-01-30 19:44:58 +01:00
|
|
|
free(jports);
|
|
|
|
|
2009-01-29 23:15:27 +01:00
|
|
|
return true;
|
2006-10-18 04:49:13 +02:00
|
|
|
}
|
|
|
|
|
2008-10-29 20:40:27 +01:00
|
|
|
static bool
|
2013-08-03 21:00:50 +02:00
|
|
|
mpd_jack_open(struct audio_output *ao, AudioFormat &audio_format,
|
2011-09-16 23:31:48 +02:00
|
|
|
GError **error_r)
|
2006-10-18 04:49:13 +02:00
|
|
|
{
|
2013-04-17 00:24:44 +02:00
|
|
|
JackOutput *jd = (JackOutput *)ao;
|
2006-10-18 04:49:13 +02:00
|
|
|
|
2013-04-17 00:24:44 +02:00
|
|
|
assert(jd != nullptr);
|
2006-10-18 04:49:13 +02:00
|
|
|
|
2009-10-21 18:33:05 +02:00
|
|
|
jd->pause = false;
|
|
|
|
|
2013-04-17 00:24:44 +02:00
|
|
|
if (jd->client != nullptr && jd->shutdown)
|
2012-04-04 21:40:56 +02:00
|
|
|
mpd_jack_disconnect(jd);
|
|
|
|
|
2013-04-17 00:24:44 +02:00
|
|
|
if (jd->client == nullptr && !mpd_jack_connect(jd, error_r))
|
2008-10-29 20:40:27 +01:00
|
|
|
return false;
|
2006-10-18 04:49:13 +02:00
|
|
|
|
2008-09-24 07:20:55 +02:00
|
|
|
set_audioformat(jd, audio_format);
|
2013-08-03 21:00:50 +02:00
|
|
|
jd->audio_format = audio_format;
|
2006-10-18 04:49:13 +02:00
|
|
|
|
2009-11-05 20:02:04 +01:00
|
|
|
if (!mpd_jack_start(jd, error_r))
|
|
|
|
return false;
|
|
|
|
|
2008-10-29 20:40:27 +01:00
|
|
|
return true;
|
2006-10-18 04:49:13 +02:00
|
|
|
}
|
|
|
|
|
2008-10-24 17:29:37 +02:00
|
|
|
static void
|
2011-09-16 23:31:48 +02:00
|
|
|
mpd_jack_close(G_GNUC_UNUSED struct audio_output *ao)
|
2006-10-18 04:49:13 +02:00
|
|
|
{
|
2013-04-17 00:24:44 +02:00
|
|
|
JackOutput *jd = (JackOutput *)ao;
|
2009-01-29 23:16:21 +01:00
|
|
|
|
2009-10-21 21:37:11 +02:00
|
|
|
mpd_jack_stop(jd);
|
2006-10-18 04:49:13 +02:00
|
|
|
}
|
|
|
|
|
2012-08-14 22:47:25 +02:00
|
|
|
static unsigned
|
|
|
|
mpd_jack_delay(struct audio_output *ao)
|
|
|
|
{
|
2013-04-17 00:24:44 +02:00
|
|
|
JackOutput *jd = (JackOutput *)ao;
|
2012-08-14 22:47:25 +02:00
|
|
|
|
|
|
|
return jd->base.pause && jd->pause && !jd->shutdown
|
|
|
|
? 1000
|
|
|
|
: 0;
|
|
|
|
}
|
|
|
|
|
2008-10-24 17:34:47 +02:00
|
|
|
static inline jack_default_audio_sample_t
|
|
|
|
sample_16_to_jack(int16_t sample)
|
|
|
|
{
|
|
|
|
return sample / (jack_default_audio_sample_t)(1 << (16 - 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-04-17 00:24:44 +02:00
|
|
|
mpd_jack_write_samples_16(JackOutput *jd, const int16_t *src,
|
2008-10-24 17:34:47 +02:00
|
|
|
unsigned num_samples)
|
|
|
|
{
|
|
|
|
jack_default_audio_sample_t sample;
|
2009-11-06 18:58:35 +01:00
|
|
|
unsigned i;
|
2008-10-24 17:34:47 +02:00
|
|
|
|
|
|
|
while (num_samples-- > 0) {
|
2009-11-06 18:58:35 +01:00
|
|
|
for (i = 0; i < jd->audio_format.channels; ++i) {
|
2009-11-05 20:02:04 +01:00
|
|
|
sample = sample_16_to_jack(*src++);
|
2013-04-17 00:24:44 +02:00
|
|
|
jack_ringbuffer_write(jd->ringbuffer[i],
|
|
|
|
(const char *)&sample,
|
2009-11-05 20:02:04 +01:00
|
|
|
sizeof(sample));
|
|
|
|
}
|
2008-10-24 17:34:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-24 17:36:11 +02:00
|
|
|
static inline jack_default_audio_sample_t
|
|
|
|
sample_24_to_jack(int32_t sample)
|
|
|
|
{
|
|
|
|
return sample / (jack_default_audio_sample_t)(1 << (24 - 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-04-17 00:24:44 +02:00
|
|
|
mpd_jack_write_samples_24(JackOutput *jd, const int32_t *src,
|
2008-10-24 17:36:11 +02:00
|
|
|
unsigned num_samples)
|
|
|
|
{
|
|
|
|
jack_default_audio_sample_t sample;
|
2009-11-06 18:58:35 +01:00
|
|
|
unsigned i;
|
2008-10-24 17:36:11 +02:00
|
|
|
|
|
|
|
while (num_samples-- > 0) {
|
2009-11-06 18:58:35 +01:00
|
|
|
for (i = 0; i < jd->audio_format.channels; ++i) {
|
2009-11-05 20:02:04 +01:00
|
|
|
sample = sample_24_to_jack(*src++);
|
2013-04-17 00:24:44 +02:00
|
|
|
jack_ringbuffer_write(jd->ringbuffer[i],
|
|
|
|
(const char *)&sample,
|
2009-11-05 20:02:04 +01:00
|
|
|
sizeof(sample));
|
|
|
|
}
|
2008-10-24 17:36:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-24 17:34:47 +02:00
|
|
|
static void
|
2013-04-17 00:24:44 +02:00
|
|
|
mpd_jack_write_samples(JackOutput *jd, const void *src,
|
2008-10-24 17:34:47 +02:00
|
|
|
unsigned num_samples)
|
|
|
|
{
|
2009-11-10 17:11:34 +01:00
|
|
|
switch (jd->audio_format.format) {
|
2013-08-03 21:00:50 +02:00
|
|
|
case SampleFormat::S16:
|
2008-10-24 17:34:47 +02:00
|
|
|
mpd_jack_write_samples_16(jd, (const int16_t*)src,
|
|
|
|
num_samples);
|
|
|
|
break;
|
|
|
|
|
2013-08-03 21:00:50 +02:00
|
|
|
case SampleFormat::S24_P32:
|
2008-10-24 17:36:11 +02:00
|
|
|
mpd_jack_write_samples_24(jd, (const int32_t*)src,
|
|
|
|
num_samples);
|
|
|
|
break;
|
|
|
|
|
2008-10-24 17:34:47 +02:00
|
|
|
default:
|
|
|
|
assert(false);
|
2013-08-03 21:34:17 +02:00
|
|
|
gcc_unreachable();
|
2008-10-24 17:34:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-23 09:29:56 +01:00
|
|
|
static size_t
|
2011-09-16 23:31:48 +02:00
|
|
|
mpd_jack_play(struct audio_output *ao, const void *chunk, size_t size,
|
|
|
|
GError **error_r)
|
2006-10-18 04:49:13 +02:00
|
|
|
{
|
2013-04-17 00:24:44 +02:00
|
|
|
JackOutput *jd = (JackOutput *)ao;
|
2013-08-03 21:00:50 +02:00
|
|
|
const size_t frame_size = jd->audio_format.GetFrameSize();
|
2009-02-24 19:06:34 +01:00
|
|
|
size_t space = 0, space1;
|
2006-10-18 04:49:13 +02:00
|
|
|
|
2009-10-21 18:33:05 +02:00
|
|
|
jd->pause = false;
|
|
|
|
|
2008-10-24 16:56:10 +02:00
|
|
|
assert(size % frame_size == 0);
|
2008-10-24 16:39:43 +02:00
|
|
|
size /= frame_size;
|
2009-02-23 09:29:56 +01:00
|
|
|
|
2009-02-26 22:04:59 +01:00
|
|
|
while (true) {
|
|
|
|
if (jd->shutdown) {
|
2009-10-21 20:13:39 +02:00
|
|
|
g_set_error(error_r, jack_output_quark(), 0,
|
2009-02-26 22:04:59 +01:00
|
|
|
"Refusing to play, because "
|
|
|
|
"there is no client thread");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-10-24 08:44:40 +02:00
|
|
|
space = jack_ringbuffer_write_space(jd->ringbuffer[0]);
|
2009-11-06 18:58:35 +01:00
|
|
|
for (unsigned i = 1; i < jd->audio_format.channels; ++i) {
|
|
|
|
space1 = jack_ringbuffer_write_space(jd->ringbuffer[i]);
|
|
|
|
if (space > space1)
|
|
|
|
/* send data symmetrically */
|
|
|
|
space = space1;
|
|
|
|
}
|
2008-10-24 16:39:43 +02:00
|
|
|
|
2011-03-16 18:08:54 +01:00
|
|
|
if (space >= jack_sample_size)
|
2009-02-23 09:29:56 +01:00
|
|
|
break;
|
2006-12-30 01:14:45 +01:00
|
|
|
|
2009-02-23 09:29:56 +01:00
|
|
|
/* XXX do something more intelligent to
|
|
|
|
synchronize */
|
|
|
|
g_usleep(1000);
|
2007-04-09 22:18:11 +02:00
|
|
|
}
|
2008-10-24 08:44:40 +02:00
|
|
|
|
2011-03-16 18:08:54 +01:00
|
|
|
space /= jack_sample_size;
|
2009-02-23 09:29:56 +01:00
|
|
|
if (space < size)
|
|
|
|
size = space;
|
|
|
|
|
2009-02-23 09:34:26 +01:00
|
|
|
mpd_jack_write_samples(jd, chunk, size);
|
2009-02-23 09:29:56 +01:00
|
|
|
return size * frame_size;
|
2006-10-18 04:49:13 +02:00
|
|
|
}
|
|
|
|
|
2009-10-21 18:33:05 +02:00
|
|
|
static bool
|
2011-09-16 23:31:48 +02:00
|
|
|
mpd_jack_pause(struct audio_output *ao)
|
2009-10-21 18:33:05 +02:00
|
|
|
{
|
2013-04-17 00:24:44 +02:00
|
|
|
JackOutput *jd = (JackOutput *)ao;
|
2009-10-21 18:33:05 +02:00
|
|
|
|
|
|
|
if (jd->shutdown)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
jd->pause = true;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-10-21 18:33:01 +02:00
|
|
|
const struct audio_output_plugin jack_output_plugin = {
|
2013-04-17 00:24:44 +02:00
|
|
|
"jack",
|
|
|
|
mpd_jack_test_default_device,
|
|
|
|
mpd_jack_init,
|
|
|
|
mpd_jack_finish,
|
|
|
|
mpd_jack_enable,
|
|
|
|
mpd_jack_disable,
|
|
|
|
mpd_jack_open,
|
|
|
|
mpd_jack_close,
|
|
|
|
mpd_jack_delay,
|
|
|
|
nullptr,
|
|
|
|
mpd_jack_play,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
mpd_jack_pause,
|
|
|
|
nullptr,
|
2006-10-18 04:49:13 +02:00
|
|
|
};
|