From nobody Sat May 18 13:36:42 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=hostfission.com ARC-Seal: i=1; a=rsa-sha256; t=1588140735; cv=none; d=zohomail.com; s=zohoarc; b=YNIhSkrX2+JHKmR4JTPxp/VwJQC9h85eNZnylLmq8YWZzP1wUq5YhoEEpxa7+krAaubeduLICHa8aSjK6LWfBJX19xKm7v8Elnt4apgR9MOK2j/GUqlNvyw5mk5CWJ9kizeYBdfOkVHH3Ny4PR4b/QDu8dnSG9vwfuWRvW7WDkQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588140735; h=Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:Sender:Subject:To; bh=ZUc5RoU62/OxMoZPZkvcz8pPIGeT7CN7OiGGNkW+IYs=; b=hvxmrvTT4/P0kCa7c9RZy52ub0UveukT8LaOPyNeq4eJ76enQFBo63ZD+FNPaC9M3o0RJxbIHcqxRbEduRz162AQTDcX9iw7/tI6kA5FgXHrMFqwhz4CTeXbrfIa8utklBvbW5BAYthR2IyF4evH+2Q1cyhzO7HKDdiTf0EV8Dc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1588140735893183.02165286821798; Tue, 28 Apr 2020 23:12:15 -0700 (PDT) Received: from localhost ([::1]:47702 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jTfx7-0006lm-OI for importer@patchew.org; Wed, 29 Apr 2020 02:12:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39274) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jTfvx-0005SP-G8 for qemu-devel@nongnu.org; Wed, 29 Apr 2020 02:11:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jTfvv-00023b-R4 for qemu-devel@nongnu.org; Wed, 29 Apr 2020 02:11:01 -0400 Received: from mail1.hostfission.com ([139.99.139.48]:48664) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jTfvv-00023D-0P for qemu-devel@nongnu.org; Wed, 29 Apr 2020 02:10:59 -0400 Received: from aeryn.lan.ktmba (office.hostfission.com [220.233.29.71]) by mail1.hostfission.com (Postfix) with ESMTP id 40B434EE52; Wed, 29 Apr 2020 16:10:54 +1000 (AEST) Received: by aeryn.lan.ktmba (Postfix, from userid 1000) id 348B23C0D11; Wed, 29 Apr 2020 16:10:54 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=hostfission.com; s=mail; t=1588140654; bh=31XEfPO3x+/EbtY/uk8i1oMFhqu54+pliIfH+j9KeSE=; h=From:Date:Subject:To:From; b=SvcEOpCquM6esJ90PquBnOYG6Xzu/x5UMvdROevoc9xLKMgfBZeaTevL/MZLuGX21 8k1hf6Pk/YJaHN8HsEZza/56enB1sztcWxmDPWQMbZ5Llnw92ZMZcclPf/2c7c6ZBV Q2vF8typKvtGmR5Q3UlfQdew9msWWinhOYF0YxtM= From: Geoffrey McRae Date: Wed, 29 Apr 2020 15:53:58 +1000 Subject: [PATCH] audio/jack: add JACK client audiodev To: X-Mailer: mail (GNU Mailutils 3.5) Message-Id: <20200429061054.348B23C0D11@aeryn.lan.ktmba> Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=139.99.139.48; envelope-from=geoff@hostfission.com; helo=mail1.hostfission.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/29 02:10:55 X-ACL-Warn: Detected OS = Linux 3.11 and newer X-Received-From: 139.99.139.48 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @hostfission.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This commit adds a new audiodev backend to allow QEMU to use JACK as both an audio sink and source. Signed-off-by: Geoffrey McRae --- audio/Makefile.objs | 5 + audio/audio.c | 1 + audio/audio_template.h | 2 + audio/jackaudio.c | 583 +++++++++++++++++++++++++++++++++++++++++ configure | 17 ++ qapi/audio.json | 50 +++- 6 files changed, 656 insertions(+), 2 deletions(-) create mode 100644 audio/jackaudio.c diff --git a/audio/Makefile.objs b/audio/Makefile.objs index d7490a379f..b4a4c11f31 100644 --- a/audio/Makefile.objs +++ b/audio/Makefile.objs @@ -28,3 +28,8 @@ common-obj-$(CONFIG_AUDIO_SDL) +=3D sdl.mo sdl.mo-objs =3D sdlaudio.o sdl.mo-cflags :=3D $(SDL_CFLAGS) sdl.mo-libs :=3D $(SDL_LIBS) + +# jack module +common-obj-$(CONFIG_AUDIO_JACK) +=3D jack.mo +jack.mo-objs =3D jackaudio.o +jack.mo-libs :=3D $(JACK_LIBS) diff --git a/audio/audio.c b/audio/audio.c index 7a9e680355..95d9fb16ca 100644 --- a/audio/audio.c +++ b/audio/audio.c @@ -1969,6 +1969,7 @@ void audio_create_pdos(Audiodev *dev) CASE(ALSA, alsa, Alsa); CASE(COREAUDIO, coreaudio, Coreaudio); CASE(DSOUND, dsound, ); + CASE(JACK, jack, Jack); CASE(OSS, oss, Oss); CASE(PA, pa, Pa); CASE(SDL, sdl, ); diff --git a/audio/audio_template.h b/audio/audio_template.h index 7013d3041f..8dd48ce14e 100644 --- a/audio/audio_template.h +++ b/audio/audio_template.h @@ -330,6 +330,8 @@ AudiodevPerDirectionOptions *glue(audio_get_pdo_, TYPE)= (Audiodev *dev) dev->u.coreaudio.TYPE); case AUDIODEV_DRIVER_DSOUND: return dev->u.dsound.TYPE; + case AUDIODEV_DRIVER_JACK: + return qapi_AudiodevJackPerDirectionOptions_base(dev->u.jack.TYPE); case AUDIODEV_DRIVER_OSS: return qapi_AudiodevOssPerDirectionOptions_base(dev->u.oss.TYPE); case AUDIODEV_DRIVER_PA: diff --git a/audio/jackaudio.c b/audio/jackaudio.c new file mode 100644 index 0000000000..0413731044 --- /dev/null +++ b/audio/jackaudio.c @@ -0,0 +1,583 @@ +/* + * QEMU JACK Audio Connection Kit Client + * + * Copyright (c) 2020 Geoffrey McRae (gnif) + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ + +#include "qemu/osdep.h" +#include "qemu/module.h" +#include "qemu/fifo8.h" +#include "qemu-common.h" +#include "audio.h" + +#define AUDIO_CAP "jack" +#include "audio_int.h" + +#include +#include +#include + +struct QJack; + +typedef enum QJackState +{ + QJACK_STATE_DISCONNECTED, + QJACK_STATE_CONNECTED, + QJACK_STATE_IDLE, + QJACK_STATE_RUNNING, + QJACK_STATE_STOPPING, + QJACK_STATE_STOPPED, +} +QJackState; + +typedef struct QJackBuffer +{ + int channels; + int frames; + _Atomic(int) used; + int rptr, wptr; + float ** data; +} +QJackBuffer; + +typedef struct QJackClient +{ + bool out; + QJackState state; + jack_client_t * client; + jack_nframes_t freq; + + struct QJack * j; + int nchannels; + int buffersize; + jack_port_t ** port; + QJackBuffer fifo; +} +QJackClient; + +typedef struct QJackOut +{ + HWVoiceOut hw; + QJackClient c; +} +QJackOut; + +typedef struct QJackIn +{ + HWVoiceIn hw; + QJackClient c; +} +QJackIn; + +static void qjack_buffer_create(QJackBuffer * buffer, int channels, int fr= ames) +{ + buffer->channels =3D channels; + buffer->frames =3D frames; + buffer->used =3D 0; + buffer->rptr =3D 0; + buffer->wptr =3D 0; + buffer->data =3D g_malloc(channels * sizeof(float *)); + for(int i =3D 0; i < channels; ++i) + buffer->data[i] =3D g_malloc(frames * sizeof(float)); +} + +static void qjack_buffer_clear(QJackBuffer * buffer) +{ + atomic_store_explicit(&buffer->used, 0, memory_order_relaxed); + buffer->rptr =3D 0; + buffer->wptr =3D 0; +} + +static void qjack_buffer_free(QJackBuffer * buffer) +{ + for(int i =3D 0; i < buffer->channels; ++i) + g_free(buffer->data[i]); + + g_free(buffer->data); + buffer->data =3D NULL; +} + +inline static int qjack_buffer_used(QJackBuffer * buffer) +{ + return atomic_load_explicit(&buffer->used, memory_order_relaxed); +} + +/* write PCM interleaved */ +static int qjack_buffer_write(QJackBuffer * buffer, float * data, int size) +{ + const int samples =3D size / sizeof(float); + int frames =3D samples / buffer->channels; + const int avail =3D buffer->frames - + atomic_load_explicit(&buffer->used, memory_order_acquire); + + if (frames > avail) + frames =3D avail; + + int copy =3D frames; + int wptr =3D buffer->wptr; + + while(copy) { + + for(int c =3D 0; c < buffer->channels; ++c) + buffer->data[c][wptr] =3D *data++; + + if (++wptr =3D=3D buffer->frames) + wptr =3D 0; + + --copy; + } + + buffer->wptr =3D wptr; + + atomic_fetch_add_explicit(&buffer->used, frames, memory_order_release); + return frames * buffer->channels * sizeof(float); +}; + +/* write PCM linear */ +static int qjack_buffer_write_l(QJackBuffer * buffer, float ** dest, int f= rames) +{ + const int avail =3D buffer->frames - + atomic_load_explicit(&buffer->used, memory_order_acquire); + int wptr =3D buffer->wptr; + + if (frames > avail) + frames =3D avail; + + int right =3D buffer->frames - wptr; + if (right > frames) + right =3D frames; + + const int left =3D frames - right; + for(int c =3D 0; c < buffer->channels; ++c) { + memcpy(buffer->data[c] + wptr, dest[c] , right * sizeof(flo= at)); + memcpy(buffer->data[c] , dest[c] + right, left * sizeof(flo= at)); + } + + wptr +=3D frames; + if (wptr >=3D buffer->frames) + wptr -=3D buffer->frames; + buffer->wptr =3D wptr; + + atomic_fetch_add_explicit(&buffer->used, frames, memory_order_release); + return frames; +} + +/* read PCM interleaved */ +static int qjack_buffer_read(QJackBuffer * buffer, float * dest, int size) +{ + const int samples =3D size / sizeof(float); + int frames =3D samples / buffer->channels; + const int avail =3D + atomic_load_explicit(&buffer->used, memory_order_acquire); + + if (frames > avail) + frames =3D avail; + + int copy =3D frames; + int rptr =3D buffer->rptr; + + while(copy) { + + for(int c =3D 0; c < buffer->channels; ++c) + *dest++ =3D buffer->data[c][rptr]; + + if (++rptr =3D=3D buffer->frames) + rptr =3D 0; + + --copy; + } + + buffer->rptr =3D rptr; + + atomic_fetch_sub_explicit(&buffer->used, frames, memory_order_release); + return frames * buffer->channels * sizeof(float); +} + +/* read PCM linear */ +static int qjack_buffer_read_l(QJackBuffer * buffer, float ** dest, int fr= ames) +{ + int copy =3D frames; + const int used =3D atomic_load_explicit(&buffer->used, memory_order_ac= quire); + int rptr =3D buffer->rptr; + + if (copy > used) + copy =3D used; + + int right =3D buffer->frames - rptr; + if (right > copy) + right =3D copy; + + const int left =3D copy - right; + for(int c =3D 0; c < buffer->channels; ++c) { + memcpy(dest[c] , buffer->data[c] + rptr, right * sizeof(flo= at)); + memcpy(dest[c] + right, buffer->data[c] , left * sizeof(flo= at)); + } + + rptr +=3D copy; + if (rptr >=3D buffer->frames) + rptr -=3D buffer->frames; + buffer->rptr =3D rptr; + + atomic_fetch_sub_explicit(&buffer->used, copy, memory_order_release); + return copy; +} + +static int qjack_process(jack_nframes_t nframes, void *arg) +{ + QJackClient *c =3D (QJackClient *)arg; + jack_transport_state_t ts =3D jack_transport_query(c->client, NULL); + + if (ts =3D=3D JackTransportRolling) { + + if (c->state !=3D QJACK_STATE_RUNNING) + return 0; + + /* get the buffers for the ports */ + float * buffers[c->nchannels]; + for(int i =3D 0; i < c->nchannels; ++i) + buffers[i] =3D jack_port_get_buffer(c->port[i], nframes); + + if (c->out) + qjack_buffer_read_l(&c->fifo, buffers, nframes); + else + qjack_buffer_write_l(&c->fifo, buffers, nframes); + + } else if (ts =3D=3D JackTransportStopped) { + + if (c->state =3D=3D QJACK_STATE_RUNNING) + c->state =3D QJACK_STATE_STOPPED; + + } + + return 0; +} + +static int qjack_xrun(void * arg) +{ + QJackClient *c =3D (QJackClient *)arg; + + if (c->state !=3D QJACK_STATE_RUNNING) + return 0; + + qjack_buffer_clear(&c->fifo); + return 0; +} + +static void qjack_shutdown(void *arg) +{ + QJackClient *c =3D (QJackClient *)arg; + + switch(c->state) + { + case QJACK_STATE_RUNNING: + jack_transport_stop(c->client); + /* fallthrough */ + + case QJACK_STATE_IDLE: + jack_deactivate(c->client); + /* fallthrough */ + + default: + jack_client_close(c->client); + c->state =3D QJACK_STATE_DISCONNECTED; + dolog("shutdown\n"); + break; + + case QJACK_STATE_DISCONNECTED: + break; + } +} + +static size_t qjack_write(HWVoiceOut *hw, void *buf, size_t len) +{ + QJackOut *jo =3D (QJackOut *)hw; + + if (jo->c.state !=3D QJACK_STATE_RUNNING) + return len; + + return qjack_buffer_write(&jo->c.fifo, buf, len); +} + +static size_t qjack_read(HWVoiceIn *hw, void *buf, size_t len) +{ + QJackIn *ji =3D (QJackIn *)hw; + + if (ji->c.state !=3D QJACK_STATE_RUNNING) + return len; + + return qjack_buffer_read(&ji->c.fifo, buf, len); +} + +static int qjack_client_init(QJackClient *c, + AudiodevJackPerDirectionOptions *opt, bool out, struct audsettings *as) +{ + jack_status_t status; + char client_name[jack_client_name_size()]; + jack_options_t options =3D JackNullOption; + + c->out =3D out; + + snprintf(client_name, sizeof(client_name), "%s-%s", + out ? "out" : "in", + opt->client_name ? opt->client_name : qemu_get_vm_name()); + + if (opt->exact_name) + options |=3D JackUseExactName; + + if (!opt->start_server) + options |=3D JackNoStartServer; + + if (opt->server_name) + options |=3D JackServerName; + + c->client =3D jack_client_open(client_name, options, &status, + opt->server_name); + + if (c->client =3D=3D NULL) { + dolog("jack_client_open failed: status =3D 0x%2.0x\n", status); + if (status & JackServerFailed) + dolog("unable to connect to JACK server\n"); + return -1; + } + + c->freq =3D jack_get_sample_rate(c->client); + + if (status & JackServerStarted) { + dolog("JACK server started\n"); + } + + if (status & JackNameNotUnique) { + dolog("JACK unique name assigned %s\n", + jack_get_client_name(c->client)); + } + + jack_set_process_callback(c->client, qjack_process , c); + jack_set_xrun_callback (c->client, qjack_xrun , c); + jack_on_shutdown (c->client, qjack_shutdown, c); + + c->state =3D QJACK_STATE_CONNECTED; + + /* activate the session */ + jack_activate(c->client); + + c->nchannels =3D as->nchannels; + c->buffersize =3D jack_get_buffer_size(c->client); + + /* ensure the buffersize is no smaller then 512 samples, some (all?) q= emu + * virtual devices do not work correctly otherwise */ + if (c->buffersize < 512) + c->buffersize =3D 512; + + /* create a 2 period buffer */ + qjack_buffer_create(&c->fifo, c->nchannels, c->buffersize * 2); + + /* allocate and register the ports */ + c->port =3D g_malloc(sizeof(jack_port_t *) * c->nchannels); + for(int i =3D 0; i < c->nchannels; ++i) { + + char port_name[16]; + snprintf( + port_name, + sizeof(port_name), + out ? "output %d" : "input %d", + i); + + c->port[i] =3D jack_port_register( + c->client, + port_name, + JACK_DEFAULT_AUDIO_TYPE, + out ? JackPortIsOutput : JackPortIsInput, + 0); + } + + c->state =3D QJACK_STATE_IDLE; + return 0; +} + +static int qjack_init_out(HWVoiceOut *hw, struct audsettings *as, + void *drv_opaque) +{ + QJackOut *jo =3D (QJackOut *)hw; + Audiodev *dev =3D (Audiodev *)drv_opaque; + + if (jo->c.state !=3D QJACK_STATE_DISCONNECTED) + return 0; + + int ret =3D qjack_client_init(&jo->c, dev->u.jack.out, true, as); + if (ret !=3D 0) + return ret; + + /* report the buffer size to qemu */ + hw->samples =3D jo->c.buffersize; + + /* report the audio format we support */ + struct audsettings os =3D { + .freq =3D jo->c.freq, + .nchannels =3D jo->c.nchannels, + .fmt =3D AUDIO_FORMAT_F32, + .endianness =3D 0 + }; + audio_pcm_init_info(&hw->info, &os); + + dolog("JACK output configured for %dHz (%d samples)\n", + jo->c.freq, jo->c.buffersize); + + return 0; +} + +static int qjack_init_in(HWVoiceIn *hw, struct audsettings *as, + void *drv_opaque) +{ + QJackIn *ji =3D (QJackIn *)hw; + Audiodev *dev =3D (Audiodev *)drv_opaque; + + if (ji->c.state !=3D QJACK_STATE_DISCONNECTED) + return 0; + + int ret =3D qjack_client_init(&ji->c, dev->u.jack.in, false, as); + if (ret !=3D 0) + return ret; + + /* report the buffer size to qemu */ + hw->samples =3D ji->c.buffersize; + + /* report the audio format we support */ + struct audsettings is =3D { + .freq =3D ji->c.freq, + .nchannels =3D ji->c.nchannels, + .fmt =3D AUDIO_FORMAT_F32, + .endianness =3D 0 + }; + audio_pcm_init_info(&hw->info, &is); + + dolog("JACK input configured for %dHz (%d samples)\n", + ji->c.freq, ji->c.buffersize); + + return 0; +} + + +static void qjack_client_fini(QJackClient *c) +{ + qjack_shutdown(c); + + qjack_buffer_free(&c->fifo); + for(int i =3D 0; i < c->nchannels; ++i) + jack_port_unregister(c->client, c->port[i]); + g_free(c->port); +} + +static void qjack_fini_out(HWVoiceOut *hw) +{ + QJackOut *jo =3D (QJackOut *)hw; + qjack_client_fini(&jo->c); +} + +static void qjack_fini_in(HWVoiceIn *hw) +{ + QJackIn *ji =3D (QJackIn *)hw; + qjack_client_fini(&ji->c); +} + +static void qjack_enable(QJackClient *c, bool enable) +{ + if (c->state !=3D QJACK_STATE_IDLE) + return; + + if (enable) { + jack_transport_start(c->client); + c->state =3D QJACK_STATE_RUNNING; + } else { + jack_transport_stop(c->client); + c->state =3D QJACK_STATE_IDLE; + } +} + +static void qjack_enable_out(HWVoiceOut *hw, bool enable) +{ + QJackOut *jo =3D (QJackOut *)hw; + qjack_enable(&jo->c, enable); +} + +static void qjack_enable_in(HWVoiceIn *hw, bool enable) +{ + QJackIn *ji =3D (QJackIn *)hw; + qjack_enable(&ji->c, enable); +} + +static int qjack_thread_creator(jack_native_thread_t * thread, + const pthread_attr_t * attr, void *(*function)(void *), void *arg) +{ + int ret =3D pthread_create(thread, attr, function, arg); + if (ret !=3D 0) + return ret; + + /* set the name of the thread */ + pthread_setname_np(*thread, "jack-client"); + + return ret; +} + +static void* qjack_init(Audiodev *dev) +{ + assert(dev->driver =3D=3D AUDIODEV_DRIVER_JACK); + + dev->u.jack.has_in =3D false; + + return dev; +} + +static void qjack_fini (void *opaque) +{ +} + +static struct audio_pcm_ops jack_pcm_ops =3D { + .init_out =3D qjack_init_out, + .fini_out =3D qjack_fini_out, + .write =3D qjack_write, + .run_buffer_out =3D audio_generic_run_buffer_out, + .enable_out =3D qjack_enable_out, + + .init_in =3D qjack_init_in, + .fini_in =3D qjack_fini_in, + .read =3D qjack_read, + .enable_in =3D qjack_enable_in +}; + +static struct audio_driver jack_driver =3D { + .name =3D "jack", + .descr =3D "JACK Audio Connection Kit Client", + .init =3D qjack_init, + .fini =3D qjack_fini, + .pcm_ops =3D &jack_pcm_ops, + .can_be_default =3D 1, + .max_voices_out =3D INT_MAX, + .max_voices_in =3D INT_MAX, + .voice_size_out =3D sizeof(QJackOut), + .voice_size_in =3D sizeof(QJackIn) +}; + +static void register_audio_jack(void) +{ + audio_driver_register(&jack_driver); + jack_set_thread_creator(qjack_thread_creator); +} +type_init(register_audio_jack); diff --git a/configure b/configure index 23b5e93752..004502c775 100755 --- a/configure +++ b/configure @@ -3629,6 +3629,22 @@ for drv in $audio_drv_list; do oss_libs=3D"$oss_lib" ;; =20 + jack | try-jack) + if $pkg_config jack --exists; then + jack_libs=3D$($pkg_config jack --libs) + if test "$drv" =3D "try-jack"; then + audio_drv_list=3D$(echo "$audio_drv_list" | sed -e 's/try-jack= /jack/') + fi + else + if test "$drv" =3D "try-jack"; then + audio_drv_list=3D$(echo "$audio_drv_list" | sed -e 's/try-jack= //') + else + error_exit "$drv check failed" \ + "Make sure to have the $drv libs and headers installed." + fi + fi + ;; + *) echo "$audio_possible_drivers" | grep -q "\<$drv\>" || { error_exit "Unknown driver '$drv' selected" \ @@ -6904,6 +6920,7 @@ echo "PULSE_LIBS=3D$pulse_libs" >> $config_host_mak echo "COREAUDIO_LIBS=3D$coreaudio_libs" >> $config_host_mak echo "DSOUND_LIBS=3D$dsound_libs" >> $config_host_mak echo "OSS_LIBS=3D$oss_libs" >> $config_host_mak +echo "JACK_LIBS=3D$jack_libs" >> $config_host_mak if test "$audio_win_int" =3D "yes" ; then echo "CONFIG_AUDIO_WIN_INT=3Dy" >> $config_host_mak fi diff --git a/qapi/audio.json b/qapi/audio.json index c31251f45b..c4bd1f65fc 100644 --- a/qapi/audio.json +++ b/qapi/audio.json @@ -152,6 +152,51 @@ '*out': 'AudiodevPerDirectionOptions', '*latency': 'uint32' } } =20 +## +# @AudiodevJackPerDirectionOptions: +# +# Options of the JACK backend that are used for both playback and +# recording. +# +# @server_name: select from among several possible concurrent server insta= nces. +# If unspecified, use "default" unless $JACK_DEFAULT_SERVER is defined in = the +# process environment. +# +# @client_name: the client name to use. The server will modify this name to +# create a unique variant, if needed unless @exact_name is true. +# +# @start_server: set to true to start a jack server instance if one is not +# present. +# +# @exact_name: use the exact name requested otherwise JACK automatically +# generates a unique one, if needed. +# +# Since: 4.0 +## +{ 'struct': 'AudiodevJackPerDirectionOptions', + 'base': 'AudiodevPerDirectionOptions', + 'data': { + '*server_name': 'str', + '*client_name': 'str', + '*start_server': 'bool', + '*exact_name': 'bool' } } + +## +# @AudiodevJackOptions: +# +# Options of the JACK audio backend. +# +# @in: options of the capture stream +# +# @out: options of the playback stream +# +# Since: 4.0 +## +{ 'struct': 'AudiodevJackOptions', + 'data': { + '*in': 'AudiodevJackPerDirectionOptions', + '*out': 'AudiodevJackPerDirectionOptions' } } + ## # @AudiodevOssPerDirectionOptions: # @@ -300,8 +345,8 @@ # Since: 4.0 ## { 'enum': 'AudiodevDriver', - 'data': [ 'none', 'alsa', 'coreaudio', 'dsound', 'oss', 'pa', 'sdl', - 'spice', 'wav' ] } + 'data': [ 'none', 'alsa', 'coreaudio', 'dsound', 'jack', 'oss', 'pa', + 'sdl', 'spice', 'wav' ] } =20 ## # @Audiodev: @@ -327,6 +372,7 @@ 'alsa': 'AudiodevAlsaOptions', 'coreaudio': 'AudiodevCoreaudioOptions', 'dsound': 'AudiodevDsoundOptions', + 'jack': 'AudiodevJackOptions', 'oss': 'AudiodevOssOptions', 'pa': 'AudiodevPaOptions', 'sdl': 'AudiodevGenericOptions', --=20 2.20.1