2008-08-07 08:47:40 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2008 Tristan Matthews <tristan@sat.qc.ca>
|
2021-07-26 10:55:25 +00:00
|
|
|
*
|
2008-08-07 08:47:40 +00:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell 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 OTHER
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the
|
|
|
|
* GNU Lesser General Public License Version 2.1 (the "LGPL"), in
|
|
|
|
* which case the following provisions apply instead of the ones
|
|
|
|
* mentioned above:
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
2012-11-04 00:07:18 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2008-08-07 08:47:40 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2010-03-24 13:59:53 +00:00
|
|
|
* SECTION:element-jackaudiosrc
|
2018-10-22 09:39:24 +00:00
|
|
|
* @title: jackaudiosrc
|
2011-11-11 10:53:45 +00:00
|
|
|
* @see_also: #GstAudioBaseSrc, #GstAudioRingBuffer
|
2008-08-07 08:47:40 +00:00
|
|
|
*
|
|
|
|
* A Src that inputs data from Jack ports.
|
2018-10-22 09:39:24 +00:00
|
|
|
*
|
|
|
|
* It will create N Jack ports named in_<name>_<num> where
|
2008-08-07 08:47:40 +00:00
|
|
|
* <name> is the element name and <num> is starting from 1.
|
|
|
|
* Each port corresponds to a gstreamer channel.
|
2018-10-22 09:39:24 +00:00
|
|
|
*
|
2008-08-07 08:47:40 +00:00
|
|
|
* The samplerate as exposed on the caps is always the same as the samplerate of
|
|
|
|
* the jack server.
|
2018-10-22 09:39:24 +00:00
|
|
|
*
|
2008-08-07 08:47:40 +00:00
|
|
|
* When the #GstJackAudioSrc:connect property is set to auto, this element
|
2018-10-22 09:39:24 +00:00
|
|
|
* will try to connect each input port to a random physical jack output pin.
|
|
|
|
*
|
2008-08-07 08:47:40 +00:00
|
|
|
* When the #GstJackAudioSrc:connect property is set to none, the element will
|
|
|
|
* accept any number of output channels and will create (but not connect) an
|
|
|
|
* input port for each channel.
|
2018-10-22 09:39:24 +00:00
|
|
|
*
|
2008-08-07 08:47:40 +00:00
|
|
|
* The element will generate an error when the Jack server is shut down when it
|
|
|
|
* was PAUSED or PLAYING. This element does not support dynamic rate and buffer
|
|
|
|
* size changes at runtime.
|
2018-10-22 09:39:24 +00:00
|
|
|
*
|
|
|
|
* ## Example launch line
|
2008-08-07 08:47:40 +00:00
|
|
|
* |[
|
2012-08-26 21:39:55 +00:00
|
|
|
* gst-launch-1.0 jackaudiosrc connect=0 ! jackaudiosink connect=0
|
2008-08-07 08:47:40 +00:00
|
|
|
* ]| Get audio input into gstreamer from jack.
|
2018-10-22 09:39:24 +00:00
|
|
|
*
|
2008-08-07 08:47:40 +00:00
|
|
|
*/
|
|
|
|
|
2010-09-09 18:49:06 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2022-03-25 13:59:23 +00:00
|
|
|
#include <glib/gi18n-lib.h>
|
2008-08-07 08:47:40 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2012-12-12 17:35:04 +00:00
|
|
|
#include <gst/audio/audio.h>
|
|
|
|
|
2008-08-07 08:47:40 +00:00
|
|
|
#include "gstjackaudiosrc.h"
|
|
|
|
#include "gstjackringbuffer.h"
|
2010-04-27 14:48:32 +00:00
|
|
|
#include "gstjackutil.h"
|
2008-08-07 08:47:40 +00:00
|
|
|
|
2008-08-07 09:09:44 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (gst_jack_audio_src_debug);
|
2008-08-07 13:15:21 +00:00
|
|
|
#define GST_CAT_DEFAULT gst_jack_audio_src_debug
|
2008-08-07 08:47:40 +00:00
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_jack_audio_src_allocate_channels (GstJackAudioSrc * src, gint channels)
|
|
|
|
{
|
|
|
|
jack_client_t *client;
|
|
|
|
|
|
|
|
client = gst_jack_audio_client_get_client (src->client);
|
|
|
|
|
|
|
|
/* remove ports we don't need */
|
|
|
|
while (src->port_count > channels)
|
|
|
|
jack_port_unregister (client, src->ports[--src->port_count]);
|
|
|
|
|
|
|
|
/* alloc enough input ports */
|
|
|
|
src->ports = g_realloc (src->ports, sizeof (jack_port_t *) * channels);
|
2010-05-11 21:56:31 +00:00
|
|
|
src->buffers = g_realloc (src->buffers, sizeof (sample_t *) * channels);
|
2008-08-07 08:47:40 +00:00
|
|
|
|
|
|
|
/* create an input port for each channel */
|
|
|
|
while (src->port_count < channels) {
|
|
|
|
gchar *name;
|
|
|
|
|
|
|
|
/* port names start from 1 and are local to the element */
|
|
|
|
name =
|
|
|
|
g_strdup_printf ("in_%s_%d", GST_ELEMENT_NAME (src),
|
|
|
|
src->port_count + 1);
|
|
|
|
src->ports[src->port_count] =
|
|
|
|
jack_port_register (client, name, JACK_DEFAULT_AUDIO_TYPE,
|
|
|
|
JackPortIsInput, 0);
|
|
|
|
if (src->ports[src->port_count] == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
src->port_count++;
|
|
|
|
|
|
|
|
g_free (name);
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_jack_audio_src_free_channels (GstJackAudioSrc * src)
|
|
|
|
{
|
|
|
|
gint res, i = 0;
|
|
|
|
jack_client_t *client;
|
|
|
|
|
|
|
|
client = gst_jack_audio_client_get_client (src->client);
|
|
|
|
|
|
|
|
/* get rid of all ports */
|
|
|
|
while (src->port_count) {
|
|
|
|
GST_LOG_OBJECT (src, "unregister port %d", i);
|
|
|
|
if ((res = jack_port_unregister (client, src->ports[i++])))
|
|
|
|
GST_DEBUG_OBJECT (src, "unregister of port failed (%d)", res);
|
|
|
|
|
|
|
|
src->port_count--;
|
|
|
|
}
|
|
|
|
g_free (src->ports);
|
|
|
|
src->ports = NULL;
|
2010-05-11 21:56:31 +00:00
|
|
|
g_free (src->buffers);
|
|
|
|
src->buffers = NULL;
|
2008-08-07 08:47:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ringbuffer abstract base class */
|
|
|
|
static GType
|
2010-03-22 15:56:03 +00:00
|
|
|
gst_jack_ring_buffer_get_type (void)
|
2008-08-07 08:47:40 +00:00
|
|
|
{
|
2021-03-18 08:52:53 +00:00
|
|
|
static gsize ringbuffer_type = 0;
|
2008-08-07 08:47:40 +00:00
|
|
|
|
2011-01-02 17:07:19 +00:00
|
|
|
if (g_once_init_enter (&ringbuffer_type)) {
|
2008-08-07 08:47:40 +00:00
|
|
|
static const GTypeInfo ringbuffer_info = { sizeof (GstJackRingBufferClass),
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
(GClassInitFunc) gst_jack_ring_buffer_class_init,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
sizeof (GstJackRingBuffer),
|
|
|
|
0,
|
|
|
|
(GInstanceInitFunc) gst_jack_ring_buffer_init,
|
|
|
|
NULL
|
|
|
|
};
|
2011-11-11 10:24:00 +00:00
|
|
|
GType tmp = g_type_register_static (GST_TYPE_AUDIO_RING_BUFFER,
|
2008-08-07 08:47:40 +00:00
|
|
|
"GstJackAudioSrcRingBuffer", &ringbuffer_info, 0);
|
2011-01-02 17:07:19 +00:00
|
|
|
g_once_init_leave (&ringbuffer_type, tmp);
|
2008-08-07 08:47:40 +00:00
|
|
|
}
|
2011-01-02 17:07:19 +00:00
|
|
|
|
|
|
|
return (GType) ringbuffer_type;
|
2008-08-07 08:47:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_jack_ring_buffer_class_init (GstJackRingBufferClass * klass)
|
|
|
|
{
|
2011-11-11 10:24:00 +00:00
|
|
|
GstAudioRingBufferClass *gstringbuffer_class;
|
2008-08-07 08:47:40 +00:00
|
|
|
|
2011-11-11 10:24:00 +00:00
|
|
|
gstringbuffer_class = (GstAudioRingBufferClass *) klass;
|
2008-08-07 08:47:40 +00:00
|
|
|
|
|
|
|
ring_parent_class = g_type_class_peek_parent (klass);
|
|
|
|
|
|
|
|
gstringbuffer_class->open_device =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_jack_ring_buffer_open_device);
|
|
|
|
gstringbuffer_class->close_device =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_jack_ring_buffer_close_device);
|
|
|
|
gstringbuffer_class->acquire =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_jack_ring_buffer_acquire);
|
|
|
|
gstringbuffer_class->release =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_jack_ring_buffer_release);
|
|
|
|
gstringbuffer_class->start = GST_DEBUG_FUNCPTR (gst_jack_ring_buffer_start);
|
|
|
|
gstringbuffer_class->pause = GST_DEBUG_FUNCPTR (gst_jack_ring_buffer_pause);
|
|
|
|
gstringbuffer_class->resume = GST_DEBUG_FUNCPTR (gst_jack_ring_buffer_start);
|
|
|
|
gstringbuffer_class->stop = GST_DEBUG_FUNCPTR (gst_jack_ring_buffer_stop);
|
|
|
|
|
|
|
|
gstringbuffer_class->delay = GST_DEBUG_FUNCPTR (gst_jack_ring_buffer_delay);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* this is the callback of jack. This should be RT-safe.
|
|
|
|
* Writes samples from the jack input port's buffer to the gst ring buffer.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
jack_process_cb (jack_nframes_t nframes, void *arg)
|
|
|
|
{
|
|
|
|
GstJackAudioSrc *src;
|
2011-11-11 10:24:00 +00:00
|
|
|
GstAudioRingBuffer *buf;
|
2010-05-13 10:55:29 +00:00
|
|
|
gint len;
|
2010-05-11 21:56:31 +00:00
|
|
|
guint8 *writeptr;
|
2008-08-07 08:47:40 +00:00
|
|
|
gint writeseg;
|
2010-05-13 10:55:29 +00:00
|
|
|
gint channels, i, j, flen;
|
2010-05-11 21:56:31 +00:00
|
|
|
sample_t *data;
|
2008-08-07 08:47:40 +00:00
|
|
|
|
2011-11-11 10:24:00 +00:00
|
|
|
buf = GST_AUDIO_RING_BUFFER_CAST (arg);
|
2008-08-07 08:47:40 +00:00
|
|
|
src = GST_JACK_AUDIO_SRC (GST_OBJECT_PARENT (buf));
|
|
|
|
|
2011-08-18 17:21:07 +00:00
|
|
|
channels = GST_AUDIO_INFO_CHANNELS (&buf->spec.info);
|
2010-05-13 10:55:29 +00:00
|
|
|
|
2008-08-07 08:47:40 +00:00
|
|
|
/* get input buffers */
|
|
|
|
for (i = 0; i < channels; i++)
|
2010-05-11 21:56:31 +00:00
|
|
|
src->buffers[i] =
|
|
|
|
(sample_t *) jack_port_get_buffer (src->ports[i], nframes);
|
2008-08-07 08:47:40 +00:00
|
|
|
|
2011-11-11 10:24:00 +00:00
|
|
|
if (gst_audio_ring_buffer_prepare_read (buf, &writeseg, &writeptr, &len)) {
|
2010-05-13 10:55:29 +00:00
|
|
|
flen = len / channels;
|
|
|
|
|
|
|
|
/* the number of samples must be exactly the segment size */
|
|
|
|
if (nframes * sizeof (sample_t) != flen)
|
|
|
|
goto wrong_size;
|
|
|
|
|
|
|
|
/* the samples in the jack input buffers have to be interleaved into the
|
|
|
|
* ringbuffer */
|
2010-05-11 21:56:31 +00:00
|
|
|
data = (sample_t *) writeptr;
|
|
|
|
for (i = 0; i < nframes; ++i)
|
|
|
|
for (j = 0; j < channels; ++j)
|
|
|
|
*data++ = src->buffers[j][i];
|
|
|
|
|
2008-08-07 08:47:40 +00:00
|
|
|
GST_DEBUG ("copy %d frames: %p, %d bytes, %d channels", nframes, writeptr,
|
|
|
|
len / channels, channels);
|
|
|
|
|
|
|
|
/* we wrote one segment */
|
2011-11-11 10:24:00 +00:00
|
|
|
gst_audio_ring_buffer_advance (buf, 1);
|
2008-08-07 08:47:40 +00:00
|
|
|
}
|
|
|
|
return 0;
|
2010-05-13 10:55:29 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
wrong_size:
|
|
|
|
{
|
|
|
|
GST_ERROR_OBJECT (src, "nbytes (%d) != flen (%d)",
|
|
|
|
(gint) (nframes * sizeof (sample_t)), flen);
|
|
|
|
return 1;
|
|
|
|
}
|
2008-08-07 08:47:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* we error out */
|
|
|
|
static int
|
|
|
|
jack_sample_rate_cb (jack_nframes_t nframes, void *arg)
|
|
|
|
{
|
|
|
|
GstJackAudioSrc *src;
|
|
|
|
GstJackRingBuffer *abuf;
|
|
|
|
|
|
|
|
abuf = GST_JACK_RING_BUFFER_CAST (arg);
|
|
|
|
src = GST_JACK_AUDIO_SRC (GST_OBJECT_PARENT (arg));
|
|
|
|
|
|
|
|
if (abuf->sample_rate != -1 && abuf->sample_rate != nframes)
|
|
|
|
goto not_supported;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
not_supported:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS,
|
|
|
|
(NULL), ("Jack changed the sample rate, which is not supported"));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we error out */
|
|
|
|
static int
|
|
|
|
jack_buffer_size_cb (jack_nframes_t nframes, void *arg)
|
|
|
|
{
|
|
|
|
GstJackAudioSrc *src;
|
|
|
|
GstJackRingBuffer *abuf;
|
|
|
|
|
|
|
|
abuf = GST_JACK_RING_BUFFER_CAST (arg);
|
|
|
|
src = GST_JACK_AUDIO_SRC (GST_OBJECT_PARENT (arg));
|
|
|
|
|
|
|
|
if (abuf->buffer_size != -1 && abuf->buffer_size != nframes)
|
|
|
|
goto not_supported;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
not_supported:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS,
|
|
|
|
(NULL), ("Jack changed the buffer size, which is not supported"));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
jack_shutdown_cb (void *arg)
|
|
|
|
{
|
|
|
|
GstJackAudioSrc *src;
|
|
|
|
|
|
|
|
src = GST_JACK_AUDIO_SRC (GST_OBJECT_PARENT (arg));
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (src, "shutdown");
|
|
|
|
|
|
|
|
GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND,
|
|
|
|
(NULL), ("Jack server shutdown"));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_jack_ring_buffer_init (GstJackRingBuffer * buf,
|
|
|
|
GstJackRingBufferClass * g_class)
|
|
|
|
{
|
|
|
|
buf->channels = -1;
|
|
|
|
buf->buffer_size = -1;
|
|
|
|
buf->sample_rate = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* the _open_device method should make a connection with the server
|
|
|
|
*/
|
|
|
|
static gboolean
|
2011-11-11 10:24:00 +00:00
|
|
|
gst_jack_ring_buffer_open_device (GstAudioRingBuffer * buf)
|
2008-08-07 08:47:40 +00:00
|
|
|
{
|
|
|
|
GstJackAudioSrc *src;
|
|
|
|
jack_status_t status = 0;
|
|
|
|
const gchar *name;
|
|
|
|
|
|
|
|
src = GST_JACK_AUDIO_SRC (GST_OBJECT_PARENT (buf));
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (src, "open");
|
|
|
|
|
2011-12-09 15:45:03 +00:00
|
|
|
if (src->client_name) {
|
|
|
|
name = src->client_name;
|
|
|
|
} else {
|
|
|
|
name = g_get_application_name ();
|
|
|
|
}
|
2008-08-07 08:47:40 +00:00
|
|
|
if (!name)
|
|
|
|
name = "GStreamer";
|
|
|
|
|
|
|
|
src->client = gst_jack_audio_client_new (name, src->server,
|
2010-09-06 20:11:31 +00:00
|
|
|
src->jclient,
|
2008-08-07 08:47:40 +00:00
|
|
|
GST_JACK_CLIENT_SOURCE,
|
|
|
|
jack_shutdown_cb,
|
|
|
|
jack_process_cb, jack_buffer_size_cb, jack_sample_rate_cb, buf, &status);
|
|
|
|
if (src->client == NULL)
|
|
|
|
goto could_not_open;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (src, "opened");
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
could_not_open:
|
|
|
|
{
|
2011-08-13 15:51:22 +00:00
|
|
|
if (status & (JackServerFailed | JackFailure)) {
|
2008-08-07 08:47:40 +00:00
|
|
|
GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND,
|
2010-09-09 18:49:06 +00:00
|
|
|
(_("Jack server not found")),
|
|
|
|
("Cannot connect to the Jack server (status %d)", status));
|
2008-08-07 08:47:40 +00:00
|
|
|
} else {
|
2011-08-13 15:51:22 +00:00
|
|
|
GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ,
|
2008-08-07 08:47:40 +00:00
|
|
|
(NULL), ("Jack client open error (status %d)", status));
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* close the connection with the server
|
|
|
|
*/
|
|
|
|
static gboolean
|
2011-11-11 10:24:00 +00:00
|
|
|
gst_jack_ring_buffer_close_device (GstAudioRingBuffer * buf)
|
2008-08-07 08:47:40 +00:00
|
|
|
{
|
|
|
|
GstJackAudioSrc *src;
|
|
|
|
|
|
|
|
src = GST_JACK_AUDIO_SRC (GST_OBJECT_PARENT (buf));
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (src, "close");
|
|
|
|
|
|
|
|
gst_jack_audio_src_free_channels (src);
|
|
|
|
gst_jack_audio_client_free (src->client);
|
|
|
|
src->client = NULL;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* allocate a buffer and setup resources to process the audio samples of
|
|
|
|
* the format as specified in @spec.
|
|
|
|
*
|
|
|
|
* We allocate N jack ports, one for each channel. If we are asked to
|
|
|
|
* automatically make a connection with physical ports, we connect as many
|
|
|
|
* ports as there are physical ports, leaving leftover ports unconnected.
|
|
|
|
*
|
|
|
|
* It is assumed that samplerate and number of channels are acceptable since our
|
|
|
|
* getcaps method will always provide correct values. If unacceptable caps are
|
|
|
|
* received for some reason, we fail here.
|
|
|
|
*/
|
|
|
|
static gboolean
|
2011-11-11 10:24:00 +00:00
|
|
|
gst_jack_ring_buffer_acquire (GstAudioRingBuffer * buf,
|
|
|
|
GstAudioRingBufferSpec * spec)
|
2008-08-07 08:47:40 +00:00
|
|
|
{
|
|
|
|
GstJackAudioSrc *src;
|
|
|
|
GstJackRingBuffer *abuf;
|
|
|
|
gint sample_rate, buffer_size;
|
2011-08-18 17:21:07 +00:00
|
|
|
gint i, bpf, rate, channels, res;
|
2008-08-07 08:47:40 +00:00
|
|
|
jack_client_t *client;
|
|
|
|
|
|
|
|
src = GST_JACK_AUDIO_SRC (GST_OBJECT_PARENT (buf));
|
|
|
|
abuf = GST_JACK_RING_BUFFER_CAST (buf);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (src, "acquire");
|
|
|
|
|
|
|
|
client = gst_jack_audio_client_get_client (src->client);
|
|
|
|
|
2011-08-18 17:21:07 +00:00
|
|
|
rate = GST_AUDIO_INFO_RATE (&spec->info);
|
|
|
|
|
2008-08-07 08:47:40 +00:00
|
|
|
/* sample rate must be that of the server */
|
|
|
|
sample_rate = jack_get_sample_rate (client);
|
2011-08-18 17:21:07 +00:00
|
|
|
if (sample_rate != rate)
|
2008-08-07 08:47:40 +00:00
|
|
|
goto wrong_samplerate;
|
|
|
|
|
2011-08-18 17:21:07 +00:00
|
|
|
bpf = GST_AUDIO_INFO_BPF (&spec->info);
|
|
|
|
channels = GST_AUDIO_INFO_CHANNELS (&spec->info);
|
2008-08-07 08:47:40 +00:00
|
|
|
|
|
|
|
if (!gst_jack_audio_src_allocate_channels (src, channels))
|
|
|
|
goto out_of_ports;
|
|
|
|
|
2012-01-04 13:52:46 +00:00
|
|
|
gst_jack_set_layout (buf, spec);
|
2010-04-27 14:48:32 +00:00
|
|
|
|
2008-08-07 08:47:40 +00:00
|
|
|
buffer_size = jack_get_buffer_size (client);
|
|
|
|
|
|
|
|
/* the segment size in bytes, this is large enough to hold a buffer of 32bit floats
|
|
|
|
* for all channels */
|
|
|
|
spec->segsize = buffer_size * sizeof (gfloat) * channels;
|
|
|
|
spec->latency_time = gst_util_uint64_scale (spec->segsize,
|
2011-08-18 17:21:07 +00:00
|
|
|
(GST_SECOND / GST_USECOND), rate * bpf);
|
2008-08-07 08:47:40 +00:00
|
|
|
/* segtotal based on buffer-time latency */
|
|
|
|
spec->segtotal = spec->buffer_time / spec->latency_time;
|
2021-07-26 11:14:32 +00:00
|
|
|
|
|
|
|
/* Use small period when low-latency is enabled regardless of buffer-time */
|
|
|
|
if (spec->segtotal < 2 || src->low_latency) {
|
2009-10-12 06:06:37 +00:00
|
|
|
spec->segtotal = 2;
|
|
|
|
spec->buffer_time = spec->latency_time * spec->segtotal;
|
|
|
|
}
|
2008-08-07 08:47:40 +00:00
|
|
|
|
2009-10-12 06:06:37 +00:00
|
|
|
GST_DEBUG_OBJECT (src, "buffer time: %" G_GINT64_FORMAT " usec",
|
|
|
|
spec->buffer_time);
|
|
|
|
GST_DEBUG_OBJECT (src, "latency time: %" G_GINT64_FORMAT " usec",
|
|
|
|
spec->latency_time);
|
|
|
|
GST_DEBUG_OBJECT (src, "buffer_size %d, segsize %d, segtotal %d",
|
|
|
|
buffer_size, spec->segsize, spec->segtotal);
|
2008-08-07 08:47:40 +00:00
|
|
|
|
|
|
|
/* allocate the ringbuffer memory now */
|
2011-04-26 13:42:47 +00:00
|
|
|
buf->size = spec->segtotal * spec->segsize;
|
|
|
|
buf->memory = g_malloc0 (buf->size);
|
2008-08-07 08:47:40 +00:00
|
|
|
|
|
|
|
if ((res = gst_jack_audio_client_set_active (src->client, TRUE)))
|
|
|
|
goto could_not_activate;
|
|
|
|
|
|
|
|
/* if we need to automatically connect the ports, do so now. We must do this
|
|
|
|
* after activating the client. */
|
2009-03-16 10:21:02 +00:00
|
|
|
if (src->connect == GST_JACK_CONNECT_AUTO
|
2021-07-27 09:33:18 +00:00
|
|
|
|| src->connect == GST_JACK_CONNECT_AUTO_FORCED
|
|
|
|
|| src->connect == GST_JACK_CONNECT_EXPLICIT) {
|
|
|
|
const char **available_ports = NULL;
|
|
|
|
const char **jack_ports = NULL;
|
|
|
|
char **user_ports = NULL;
|
|
|
|
|
2008-08-07 08:47:40 +00:00
|
|
|
/* find all the physical output ports. A physical output port is a port
|
|
|
|
* associated with a hardware device. Someone needs connect to a physical
|
|
|
|
* port in order to capture something. */
|
2015-02-17 11:20:57 +00:00
|
|
|
|
2021-07-27 09:33:18 +00:00
|
|
|
if (src->port_names) {
|
|
|
|
user_ports = gst_jack_audio_client_get_port_names_from_string (client,
|
|
|
|
src->port_names, JackPortIsOutput);
|
|
|
|
|
|
|
|
if (user_ports)
|
|
|
|
available_ports = (const char **) user_ports;
|
2015-02-17 11:20:57 +00:00
|
|
|
}
|
|
|
|
|
2021-07-27 09:33:18 +00:00
|
|
|
if (!available_ports && src->connect == GST_JACK_CONNECT_EXPLICIT)
|
|
|
|
goto wrong_port_names;
|
|
|
|
|
|
|
|
if (!available_ports) {
|
|
|
|
if (!src->port_pattern) {
|
|
|
|
jack_ports = jack_get_ports (client, NULL, NULL,
|
|
|
|
JackPortIsPhysical | JackPortIsOutput);
|
|
|
|
} else {
|
|
|
|
jack_ports = jack_get_ports (client, src->port_pattern, NULL,
|
|
|
|
JackPortIsOutput);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!available_ports) {
|
2008-08-07 08:47:40 +00:00
|
|
|
/* no ports? fine then we don't do anything except for posting a warning
|
|
|
|
* message. */
|
|
|
|
GST_ELEMENT_WARNING (src, RESOURCE, NOT_FOUND, (NULL),
|
|
|
|
("No physical output ports found, leaving ports unconnected"));
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < channels; i++) {
|
|
|
|
/* stop when all output ports are exhausted */
|
2021-07-27 09:33:18 +00:00
|
|
|
if (!available_ports[i]) {
|
2008-08-07 08:47:40 +00:00
|
|
|
/* post a warning that we could not connect all ports */
|
|
|
|
GST_ELEMENT_WARNING (src, RESOURCE, NOT_FOUND, (NULL),
|
|
|
|
("No more physical ports, leaving some ports unconnected"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
GST_DEBUG_OBJECT (src, "try connecting to %s",
|
|
|
|
jack_port_name (src->ports[i]));
|
|
|
|
|
2009-03-16 10:21:02 +00:00
|
|
|
/* connect the physical port to a port */
|
2021-07-27 09:33:18 +00:00
|
|
|
res = jack_connect (client,
|
|
|
|
available_ports[i], jack_port_name (src->ports[i]));
|
|
|
|
if (res != 0 && res != EEXIST) {
|
|
|
|
jack_free (jack_ports);
|
|
|
|
g_strfreev (user_ports);
|
|
|
|
|
2008-08-07 08:47:40 +00:00
|
|
|
goto cannot_connect;
|
2021-07-27 09:33:18 +00:00
|
|
|
}
|
2008-08-07 08:47:40 +00:00
|
|
|
}
|
2021-07-27 09:33:18 +00:00
|
|
|
|
|
|
|
jack_free (jack_ports);
|
|
|
|
g_strfreev (user_ports);
|
2008-08-07 08:47:40 +00:00
|
|
|
}
|
|
|
|
done:
|
|
|
|
|
|
|
|
abuf->sample_rate = sample_rate;
|
|
|
|
abuf->buffer_size = buffer_size;
|
2011-08-18 17:21:07 +00:00
|
|
|
abuf->channels = channels;
|
2008-08-07 08:47:40 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
wrong_samplerate:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS, (NULL),
|
|
|
|
("Wrong samplerate, server is running at %d and we received %d",
|
2011-08-18 17:21:07 +00:00
|
|
|
sample_rate, rate));
|
2008-08-07 08:47:40 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
out_of_ports:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS, (NULL),
|
|
|
|
("Cannot allocate more Jack ports"));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
could_not_activate:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS, (NULL),
|
|
|
|
("Could not activate client (%d:%s)", res, g_strerror (res)));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
cannot_connect:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS, (NULL),
|
|
|
|
("Could not connect input ports to physical ports (%d:%s)",
|
|
|
|
res, g_strerror (res)));
|
2021-07-27 09:33:18 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
wrong_port_names:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS, (NULL),
|
|
|
|
("Invalid port-names was provided"));
|
2008-08-07 08:47:40 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* function is called with LOCK */
|
|
|
|
static gboolean
|
2011-11-11 10:24:00 +00:00
|
|
|
gst_jack_ring_buffer_release (GstAudioRingBuffer * buf)
|
2008-08-07 08:47:40 +00:00
|
|
|
{
|
|
|
|
GstJackAudioSrc *src;
|
|
|
|
GstJackRingBuffer *abuf;
|
|
|
|
gint res;
|
|
|
|
|
|
|
|
abuf = GST_JACK_RING_BUFFER_CAST (buf);
|
|
|
|
src = GST_JACK_AUDIO_SRC (GST_OBJECT_PARENT (buf));
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (src, "release");
|
|
|
|
|
|
|
|
if ((res = gst_jack_audio_client_set_active (src->client, FALSE))) {
|
|
|
|
/* we only warn, this means the server is probably shut down and the client
|
|
|
|
* is gone anyway. */
|
|
|
|
GST_ELEMENT_WARNING (src, RESOURCE, CLOSE, (NULL),
|
|
|
|
("Could not deactivate Jack client (%d)", res));
|
|
|
|
}
|
|
|
|
|
|
|
|
abuf->channels = -1;
|
|
|
|
abuf->buffer_size = -1;
|
|
|
|
abuf->sample_rate = -1;
|
|
|
|
|
|
|
|
/* free the buffer */
|
2011-04-26 13:42:47 +00:00
|
|
|
g_free (buf->memory);
|
|
|
|
buf->memory = NULL;
|
2008-08-07 08:47:40 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-11-11 10:24:00 +00:00
|
|
|
gst_jack_ring_buffer_start (GstAudioRingBuffer * buf)
|
2008-08-07 08:47:40 +00:00
|
|
|
{
|
|
|
|
GstJackAudioSrc *src;
|
|
|
|
|
|
|
|
src = GST_JACK_AUDIO_SRC (GST_OBJECT_PARENT (buf));
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (src, "start");
|
|
|
|
|
2012-03-04 18:55:26 +00:00
|
|
|
if (src->transport & GST_JACK_TRANSPORT_MASTER) {
|
2012-01-11 13:47:36 +00:00
|
|
|
jack_client_t *client;
|
|
|
|
|
|
|
|
client = gst_jack_audio_client_get_client (src->client);
|
|
|
|
jack_transport_start (client);
|
|
|
|
}
|
|
|
|
|
2008-08-07 08:47:40 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-11-11 10:24:00 +00:00
|
|
|
gst_jack_ring_buffer_pause (GstAudioRingBuffer * buf)
|
2008-08-07 08:47:40 +00:00
|
|
|
{
|
|
|
|
GstJackAudioSrc *src;
|
|
|
|
|
|
|
|
src = GST_JACK_AUDIO_SRC (GST_OBJECT_PARENT (buf));
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (src, "pause");
|
|
|
|
|
2012-03-04 18:55:26 +00:00
|
|
|
if (src->transport & GST_JACK_TRANSPORT_MASTER) {
|
2012-01-11 13:47:36 +00:00
|
|
|
jack_client_t *client;
|
|
|
|
|
|
|
|
client = gst_jack_audio_client_get_client (src->client);
|
|
|
|
jack_transport_stop (client);
|
|
|
|
}
|
|
|
|
|
2008-08-07 08:47:40 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-11-11 10:24:00 +00:00
|
|
|
gst_jack_ring_buffer_stop (GstAudioRingBuffer * buf)
|
2008-08-07 08:47:40 +00:00
|
|
|
{
|
|
|
|
GstJackAudioSrc *src;
|
|
|
|
|
|
|
|
src = GST_JACK_AUDIO_SRC (GST_OBJECT_PARENT (buf));
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (src, "stop");
|
|
|
|
|
2012-03-04 18:55:26 +00:00
|
|
|
if (src->transport & GST_JACK_TRANSPORT_MASTER) {
|
2012-01-11 13:47:36 +00:00
|
|
|
jack_client_t *client;
|
|
|
|
|
|
|
|
client = gst_jack_audio_client_get_client (src->client);
|
|
|
|
jack_transport_stop (client);
|
|
|
|
}
|
|
|
|
|
2008-08-07 08:47:40 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-04-16 12:33:45 +00:00
|
|
|
#if defined (HAVE_JACK_0_120_1) || defined(HAVE_JACK_1_9_7)
|
2008-08-07 08:47:40 +00:00
|
|
|
static guint
|
2011-11-11 10:24:00 +00:00
|
|
|
gst_jack_ring_buffer_delay (GstAudioRingBuffer * buf)
|
2008-08-07 08:47:40 +00:00
|
|
|
{
|
|
|
|
GstJackAudioSrc *src;
|
2011-03-11 09:29:08 +00:00
|
|
|
guint i, res = 0;
|
|
|
|
jack_latency_range_t range;
|
2008-08-07 08:47:40 +00:00
|
|
|
|
|
|
|
src = GST_JACK_AUDIO_SRC (GST_OBJECT_PARENT (buf));
|
2008-11-23 17:50:08 +00:00
|
|
|
|
|
|
|
for (i = 0; i < src->port_count; i++) {
|
2011-03-11 09:29:08 +00:00
|
|
|
jack_port_get_latency_range (src->ports[i], JackCaptureLatency, &range);
|
|
|
|
if (range.max > res)
|
|
|
|
res = range.max;
|
2011-04-16 12:33:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (src, "delay %u", res);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
#else /* !(defined (HAVE_JACK_0_120_1) || defined(HAVE_JACK_1_9_7)) */
|
|
|
|
static guint
|
2011-11-11 10:24:00 +00:00
|
|
|
gst_jack_ring_buffer_delay (GstAudioRingBuffer * buf)
|
2011-04-16 12:33:45 +00:00
|
|
|
{
|
|
|
|
GstJackAudioSrc *src;
|
|
|
|
guint i, res = 0;
|
|
|
|
guint latency;
|
|
|
|
jack_client_t *client;
|
|
|
|
|
|
|
|
src = GST_JACK_AUDIO_SRC (GST_OBJECT_PARENT (buf));
|
|
|
|
|
|
|
|
client = gst_jack_audio_client_get_client (src->client);
|
|
|
|
|
|
|
|
for (i = 0; i < src->port_count; i++) {
|
2008-11-23 17:50:08 +00:00
|
|
|
latency = jack_port_get_total_latency (client, src->ports[i]);
|
|
|
|
if (latency > res)
|
|
|
|
res = latency;
|
|
|
|
}
|
2008-08-07 08:47:40 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (src, "delay %u", res);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
2011-04-16 12:33:45 +00:00
|
|
|
#endif
|
2008-08-07 08:47:40 +00:00
|
|
|
|
|
|
|
/* Audiosrc signals and args */
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
/* FILL ME */
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2011-12-09 15:45:03 +00:00
|
|
|
#define DEFAULT_PROP_CONNECT GST_JACK_CONNECT_AUTO
|
|
|
|
#define DEFAULT_PROP_SERVER NULL
|
|
|
|
#define DEFAULT_PROP_CLIENT_NAME NULL
|
2012-01-11 13:47:36 +00:00
|
|
|
#define DEFAULT_PROP_TRANSPORT GST_JACK_TRANSPORT_AUTONOMOUS
|
2015-02-17 11:20:57 +00:00
|
|
|
#define DEFAULT_PROP_PORT_PATTERN NULL
|
2021-07-26 11:14:32 +00:00
|
|
|
#define DEFAULT_PROP_LOW_LATENCY FALSE
|
|
|
|
|
2008-08-07 08:47:40 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_CONNECT,
|
|
|
|
PROP_SERVER,
|
2010-09-06 20:11:31 +00:00
|
|
|
PROP_CLIENT,
|
2011-12-09 15:45:03 +00:00
|
|
|
PROP_CLIENT_NAME,
|
2015-02-17 11:20:57 +00:00
|
|
|
PROP_PORT_PATTERN,
|
2012-01-11 13:47:36 +00:00
|
|
|
PROP_TRANSPORT,
|
2021-07-26 11:14:32 +00:00
|
|
|
PROP_LOW_LATENCY,
|
2021-07-27 09:33:18 +00:00
|
|
|
PROP_PORT_NAMES,
|
2008-08-07 08:47:40 +00:00
|
|
|
PROP_LAST
|
|
|
|
};
|
|
|
|
|
|
|
|
/* the capabilities of the inputs and outputs.
|
|
|
|
*
|
|
|
|
* describe the real formats here.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
2011-08-18 17:21:07 +00:00
|
|
|
GST_STATIC_CAPS ("audio/x-raw, "
|
|
|
|
"format = (string) " GST_JACK_FORMAT_STR ", "
|
2012-01-04 13:54:10 +00:00
|
|
|
"layout = (string) interleaved, "
|
2008-08-07 08:47:40 +00:00
|
|
|
"rate = (int) [ 1, MAX ], " "channels = (int) [ 1, MAX ]")
|
|
|
|
);
|
|
|
|
|
2011-04-26 13:42:47 +00:00
|
|
|
#define gst_jack_audio_src_parent_class parent_class
|
2011-11-11 10:53:45 +00:00
|
|
|
G_DEFINE_TYPE (GstJackAudioSrc, gst_jack_audio_src, GST_TYPE_AUDIO_BASE_SRC);
|
2021-02-12 08:56:36 +00:00
|
|
|
GST_ELEMENT_REGISTER_DEFINE (jackaudiosrc, "jackaudiosrc",
|
|
|
|
GST_RANK_PRIMARY, GST_TYPE_JACK_AUDIO_SRC);
|
2008-08-07 08:47:40 +00:00
|
|
|
|
2010-04-27 07:59:00 +00:00
|
|
|
static void gst_jack_audio_src_dispose (GObject * object);
|
2008-08-07 13:15:21 +00:00
|
|
|
static void gst_jack_audio_src_set_property (GObject * object, guint prop_id,
|
2008-08-07 08:47:40 +00:00
|
|
|
const GValue * value, GParamSpec * pspec);
|
2008-08-07 13:15:21 +00:00
|
|
|
static void gst_jack_audio_src_get_property (GObject * object, guint prop_id,
|
2008-08-07 08:47:40 +00:00
|
|
|
GValue * value, GParamSpec * pspec);
|
|
|
|
|
2011-06-09 15:56:18 +00:00
|
|
|
static GstCaps *gst_jack_audio_src_getcaps (GstBaseSrc * bsrc,
|
|
|
|
GstCaps * filter);
|
2011-11-11 10:53:45 +00:00
|
|
|
static GstAudioRingBuffer *gst_jack_audio_src_create_ringbuffer (GstAudioBaseSrc
|
2011-11-11 10:24:00 +00:00
|
|
|
* src);
|
2008-08-07 08:47:40 +00:00
|
|
|
|
|
|
|
/* GObject vmethod implementations */
|
|
|
|
|
2008-08-07 13:15:21 +00:00
|
|
|
/* initialize the jack_audio_src's class */
|
2008-08-07 08:47:40 +00:00
|
|
|
static void
|
2008-08-07 13:15:21 +00:00
|
|
|
gst_jack_audio_src_class_init (GstJackAudioSrcClass * klass)
|
2008-08-07 08:47:40 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
2011-04-26 13:42:47 +00:00
|
|
|
GstElementClass *gstelement_class;
|
2008-08-07 08:47:40 +00:00
|
|
|
GstBaseSrcClass *gstbasesrc_class;
|
2011-11-11 11:01:17 +00:00
|
|
|
GstAudioBaseSrcClass *gstaudiobasesrc_class;
|
2008-08-07 08:47:40 +00:00
|
|
|
|
2011-04-26 13:42:47 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_jack_audio_src_debug, "jacksrc", 0,
|
|
|
|
"jacksrc element");
|
2008-08-07 08:47:40 +00:00
|
|
|
|
2011-04-26 13:42:47 +00:00
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
|
|
gstelement_class = (GstElementClass *) klass;
|
2008-08-07 08:47:40 +00:00
|
|
|
gstbasesrc_class = (GstBaseSrcClass *) klass;
|
2011-11-11 11:01:17 +00:00
|
|
|
gstaudiobasesrc_class = (GstAudioBaseSrcClass *) klass;
|
2008-08-07 08:47:40 +00:00
|
|
|
|
2010-04-27 07:59:00 +00:00
|
|
|
gobject_class->dispose = gst_jack_audio_src_dispose;
|
2010-04-27 07:34:24 +00:00
|
|
|
gobject_class->set_property = gst_jack_audio_src_set_property;
|
|
|
|
gobject_class->get_property = gst_jack_audio_src_get_property;
|
2008-08-07 08:47:40 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_CONNECT,
|
|
|
|
g_param_spec_enum ("connect", "Connect",
|
|
|
|
"Specify how the input ports will be connected",
|
2010-10-19 13:23:23 +00:00
|
|
|
GST_TYPE_JACK_CONNECT, DEFAULT_PROP_CONNECT,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2008-08-07 08:47:40 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_SERVER,
|
|
|
|
g_param_spec_string ("server", "Server",
|
|
|
|
"The Jack server to connect to (NULL = default)",
|
2010-10-19 13:23:23 +00:00
|
|
|
DEFAULT_PROP_SERVER, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2008-08-07 08:47:40 +00:00
|
|
|
|
2011-12-09 15:50:28 +00:00
|
|
|
/**
|
2013-11-18 14:44:36 +00:00
|
|
|
* GstJackAudioSrc:client-name:
|
2011-12-09 15:50:28 +00:00
|
|
|
*
|
|
|
|
* The client name to use.
|
|
|
|
*/
|
2011-12-09 15:45:03 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_CLIENT_NAME,
|
|
|
|
g_param_spec_string ("client-name", "Client name",
|
|
|
|
"The client name of the Jack instance (NULL = default)",
|
|
|
|
DEFAULT_PROP_CLIENT_NAME,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2010-09-06 20:11:31 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_CLIENT,
|
|
|
|
g_param_spec_boxed ("client", "JackClient", "Handle for jack client",
|
|
|
|
GST_TYPE_JACK_CLIENT,
|
|
|
|
GST_PARAM_MUTABLE_READY | G_PARAM_READWRITE |
|
|
|
|
G_PARAM_STATIC_STRINGS));
|
2015-02-17 11:20:57 +00:00
|
|
|
/**
|
|
|
|
* GstJackAudioSrc:port-pattern
|
|
|
|
*
|
|
|
|
* autoconnect to ports matching pattern, when NULL connect to physical ports
|
|
|
|
*
|
|
|
|
* Since: 1.6
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (gobject_class, PROP_PORT_PATTERN,
|
|
|
|
g_param_spec_string ("port-pattern", "port pattern",
|
|
|
|
"A pattern to select which ports to connect to (NULL = first physical ports)",
|
|
|
|
DEFAULT_PROP_PORT_PATTERN,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2010-09-06 20:11:31 +00:00
|
|
|
|
2012-01-11 13:47:36 +00:00
|
|
|
/**
|
2013-11-18 14:44:36 +00:00
|
|
|
* GstJackAudioSink:transport:
|
2012-01-11 13:47:36 +00:00
|
|
|
*
|
|
|
|
* The jack transport behaviour for the client.
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (gobject_class, PROP_TRANSPORT,
|
2012-03-04 18:55:26 +00:00
|
|
|
g_param_spec_flags ("transport", "Transport mode",
|
2012-01-11 13:47:36 +00:00
|
|
|
"Jack transport behaviour of the client",
|
|
|
|
GST_TYPE_JACK_TRANSPORT, DEFAULT_PROP_TRANSPORT,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2021-07-26 11:14:32 +00:00
|
|
|
/**
|
|
|
|
* GstJackAudioSrc:low-latency:
|
|
|
|
*
|
|
|
|
* Optimize all settings for lowest latency. When enabled,
|
|
|
|
* #GstAudioBaseSrc:buffer-time and #GstAudioBaseSrc:latency-time will be
|
|
|
|
* ignored.
|
|
|
|
*
|
|
|
|
* Since: 1.20
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (gobject_class, PROP_LOW_LATENCY,
|
|
|
|
g_param_spec_boolean ("low-latency", "Low latency",
|
|
|
|
"Optimize all settings for lowest latency. When enabled, "
|
|
|
|
"\"buffer-time\" and \"latency-time\" will be ignored",
|
|
|
|
DEFAULT_PROP_LOW_LATENCY,
|
|
|
|
GST_PARAM_MUTABLE_READY | G_PARAM_READWRITE |
|
|
|
|
G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2021-07-27 09:33:18 +00:00
|
|
|
/**
|
|
|
|
* GstJackAudioSrc:port-names:
|
|
|
|
*
|
|
|
|
* Comma-separated list of port name including "client_name:" prefix
|
|
|
|
*
|
|
|
|
* Since: 1.20
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (gobject_class, PROP_PORT_NAMES,
|
|
|
|
g_param_spec_string ("port-names", "Port Names",
|
|
|
|
"Comma-separated list of port name including \"client_name:\" prefix",
|
|
|
|
NULL, GST_PARAM_MUTABLE_READY | G_PARAM_READWRITE |
|
|
|
|
G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2016-03-04 01:30:12 +00:00
|
|
|
gst_element_class_add_static_pad_template (gstelement_class, &src_factory);
|
2011-04-26 13:42:47 +00:00
|
|
|
|
2012-04-09 23:51:41 +00:00
|
|
|
gst_element_class_set_static_metadata (gstelement_class,
|
|
|
|
"Audio Source (Jack)", "Source/Audio",
|
|
|
|
"Captures audio from a JACK server",
|
2011-04-26 13:42:47 +00:00
|
|
|
"Tristan Matthews <tristan@sat.qc.ca>");
|
|
|
|
|
2008-08-07 09:09:44 +00:00
|
|
|
gstbasesrc_class->get_caps = GST_DEBUG_FUNCPTR (gst_jack_audio_src_getcaps);
|
2011-11-11 11:01:17 +00:00
|
|
|
gstaudiobasesrc_class->create_ringbuffer =
|
2008-08-07 09:09:44 +00:00
|
|
|
GST_DEBUG_FUNCPTR (gst_jack_audio_src_create_ringbuffer);
|
2008-08-07 08:47:40 +00:00
|
|
|
|
|
|
|
/* ref class from a thread-safe context to work around missing bit of
|
|
|
|
* thread-safety in GObject */
|
|
|
|
g_type_class_ref (GST_TYPE_JACK_RING_BUFFER);
|
|
|
|
|
|
|
|
gst_jack_audio_client_init ();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-04-26 13:42:47 +00:00
|
|
|
gst_jack_audio_src_init (GstJackAudioSrc * src)
|
2008-08-07 08:47:40 +00:00
|
|
|
{
|
|
|
|
//gst_base_src_set_live(GST_BASE_SRC (src), TRUE);
|
|
|
|
src->connect = DEFAULT_PROP_CONNECT;
|
|
|
|
src->server = g_strdup (DEFAULT_PROP_SERVER);
|
2010-09-06 20:11:31 +00:00
|
|
|
src->jclient = NULL;
|
2008-08-07 08:47:40 +00:00
|
|
|
src->ports = NULL;
|
|
|
|
src->port_count = 0;
|
2010-05-11 21:56:31 +00:00
|
|
|
src->buffers = NULL;
|
2011-12-09 15:45:03 +00:00
|
|
|
src->client_name = g_strdup (DEFAULT_PROP_CLIENT_NAME);
|
2012-01-11 13:47:36 +00:00
|
|
|
src->transport = DEFAULT_PROP_TRANSPORT;
|
2021-07-26 11:14:32 +00:00
|
|
|
src->low_latency = DEFAULT_PROP_LOW_LATENCY;
|
2008-08-07 08:47:40 +00:00
|
|
|
}
|
|
|
|
|
2010-04-27 07:59:00 +00:00
|
|
|
static void
|
|
|
|
gst_jack_audio_src_dispose (GObject * object)
|
|
|
|
{
|
|
|
|
GstJackAudioSrc *src = GST_JACK_AUDIO_SRC (object);
|
|
|
|
|
|
|
|
gst_caps_replace (&src->caps, NULL);
|
2011-12-09 15:50:28 +00:00
|
|
|
|
|
|
|
if (src->client_name != NULL) {
|
|
|
|
g_free (src->client_name);
|
|
|
|
src->client_name = NULL;
|
|
|
|
}
|
|
|
|
|
2015-02-17 11:20:57 +00:00
|
|
|
if (src->port_pattern != NULL) {
|
|
|
|
g_free (src->port_pattern);
|
|
|
|
src->port_pattern = NULL;
|
|
|
|
}
|
|
|
|
|
2021-07-27 09:33:18 +00:00
|
|
|
g_clear_pointer (&src->port_names, g_free);
|
|
|
|
|
2010-04-27 07:59:00 +00:00
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
2008-08-07 08:47:40 +00:00
|
|
|
static void
|
2008-08-07 13:15:21 +00:00
|
|
|
gst_jack_audio_src_set_property (GObject * object, guint prop_id,
|
2008-08-07 08:47:40 +00:00
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstJackAudioSrc *src = GST_JACK_AUDIO_SRC (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
2011-12-09 15:45:03 +00:00
|
|
|
case PROP_CLIENT_NAME:
|
|
|
|
g_free (src->client_name);
|
|
|
|
src->client_name = g_value_dup_string (value);
|
|
|
|
break;
|
2015-02-17 11:20:57 +00:00
|
|
|
case PROP_PORT_PATTERN:
|
|
|
|
g_free (src->port_pattern);
|
|
|
|
src->port_pattern = g_value_dup_string (value);
|
|
|
|
break;
|
2008-08-07 08:47:40 +00:00
|
|
|
case PROP_CONNECT:
|
|
|
|
src->connect = g_value_get_enum (value);
|
|
|
|
break;
|
|
|
|
case PROP_SERVER:
|
|
|
|
g_free (src->server);
|
|
|
|
src->server = g_value_dup_string (value);
|
|
|
|
break;
|
2010-09-06 20:11:31 +00:00
|
|
|
case PROP_CLIENT:
|
|
|
|
if (GST_STATE (src) == GST_STATE_NULL ||
|
|
|
|
GST_STATE (src) == GST_STATE_READY) {
|
|
|
|
src->jclient = g_value_get_boxed (value);
|
|
|
|
}
|
|
|
|
break;
|
2012-01-11 13:47:36 +00:00
|
|
|
case PROP_TRANSPORT:
|
2012-03-04 18:55:26 +00:00
|
|
|
src->transport = g_value_get_flags (value);
|
2012-01-11 13:47:36 +00:00
|
|
|
break;
|
2021-07-26 11:14:32 +00:00
|
|
|
case PROP_LOW_LATENCY:
|
|
|
|
src->low_latency = g_value_get_boolean (value);
|
|
|
|
break;
|
2021-07-27 09:33:18 +00:00
|
|
|
case PROP_PORT_NAMES:
|
|
|
|
g_free (src->port_names);
|
|
|
|
src->port_names = g_value_dup_string (value);
|
|
|
|
break;
|
2008-08-07 08:47:40 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-08-07 13:15:21 +00:00
|
|
|
gst_jack_audio_src_get_property (GObject * object, guint prop_id,
|
2008-08-07 08:47:40 +00:00
|
|
|
GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstJackAudioSrc *src = GST_JACK_AUDIO_SRC (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
2011-12-09 15:45:03 +00:00
|
|
|
case PROP_CLIENT_NAME:
|
|
|
|
g_value_set_string (value, src->client_name);
|
|
|
|
break;
|
2015-02-17 11:20:57 +00:00
|
|
|
case PROP_PORT_PATTERN:
|
|
|
|
g_value_set_string (value, src->port_pattern);
|
2015-02-19 11:20:51 +00:00
|
|
|
break;
|
2008-08-07 08:47:40 +00:00
|
|
|
case PROP_CONNECT:
|
|
|
|
g_value_set_enum (value, src->connect);
|
|
|
|
break;
|
|
|
|
case PROP_SERVER:
|
|
|
|
g_value_set_string (value, src->server);
|
|
|
|
break;
|
2010-09-06 20:11:31 +00:00
|
|
|
case PROP_CLIENT:
|
|
|
|
g_value_set_boxed (value, src->jclient);
|
|
|
|
break;
|
2012-01-11 13:47:36 +00:00
|
|
|
case PROP_TRANSPORT:
|
2012-03-04 18:55:26 +00:00
|
|
|
g_value_set_flags (value, src->transport);
|
2012-01-11 13:47:36 +00:00
|
|
|
break;
|
2021-07-26 11:14:32 +00:00
|
|
|
case PROP_LOW_LATENCY:
|
|
|
|
g_value_set_boolean (value, src->low_latency);
|
|
|
|
break;
|
2021-07-27 09:33:18 +00:00
|
|
|
case PROP_PORT_NAMES:
|
|
|
|
g_value_set_string (value, src->port_names);
|
|
|
|
break;
|
2008-08-07 08:47:40 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstCaps *
|
2011-06-09 15:56:18 +00:00
|
|
|
gst_jack_audio_src_getcaps (GstBaseSrc * bsrc, GstCaps * filter)
|
2008-08-07 08:47:40 +00:00
|
|
|
{
|
|
|
|
GstJackAudioSrc *src = GST_JACK_AUDIO_SRC (bsrc);
|
|
|
|
const char **ports;
|
|
|
|
gint min, max;
|
|
|
|
gint rate;
|
|
|
|
jack_client_t *client;
|
|
|
|
|
|
|
|
if (src->client == NULL)
|
|
|
|
goto no_client;
|
|
|
|
|
2021-07-27 09:33:18 +00:00
|
|
|
if (src->connect == GST_JACK_CONNECT_EXPLICIT && !src->port_names)
|
|
|
|
goto no_port_names;
|
|
|
|
|
2008-08-07 08:47:40 +00:00
|
|
|
client = gst_jack_audio_client_get_client (src->client);
|
|
|
|
|
2021-07-27 09:33:18 +00:00
|
|
|
if (src->connect == GST_JACK_CONNECT_AUTO ||
|
|
|
|
src->connect == GST_JACK_CONNECT_EXPLICIT) {
|
|
|
|
max = 0;
|
|
|
|
|
|
|
|
if (src->port_names) {
|
|
|
|
gchar **user_ports =
|
|
|
|
gst_jack_audio_client_get_port_names_from_string (client,
|
|
|
|
src->port_names, JackPortIsOutput);
|
|
|
|
|
|
|
|
if (user_ports) {
|
|
|
|
max = g_strv_length (user_ports);
|
|
|
|
} else {
|
|
|
|
GST_ELEMENT_WARNING (src, RESOURCE, NOT_FOUND,
|
|
|
|
("Invalid \"port-names\" was requested"),
|
|
|
|
("Requested \"port-names\" %s contains invalid name",
|
|
|
|
src->port_names));
|
|
|
|
}
|
|
|
|
|
|
|
|
g_strfreev (user_ports);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (max > 0)
|
|
|
|
goto found;
|
|
|
|
|
|
|
|
if (src->connect == GST_JACK_CONNECT_EXPLICIT)
|
|
|
|
goto no_port_names;
|
|
|
|
|
2008-08-07 08:47:40 +00:00
|
|
|
/* get a port count, this is the number of channels we can automatically
|
|
|
|
* connect. */
|
|
|
|
ports = jack_get_ports (client, NULL, NULL,
|
|
|
|
JackPortIsPhysical | JackPortIsOutput);
|
|
|
|
if (ports != NULL) {
|
|
|
|
for (; ports[max]; max++);
|
|
|
|
|
2022-05-28 11:16:04 +00:00
|
|
|
jack_free (ports);
|
2008-08-07 08:47:40 +00:00
|
|
|
} else
|
|
|
|
max = 0;
|
|
|
|
} else {
|
|
|
|
/* we allow any number of pads, something else is going to connect the
|
|
|
|
* pads. */
|
|
|
|
max = G_MAXINT;
|
|
|
|
}
|
2021-07-27 09:33:18 +00:00
|
|
|
|
|
|
|
found:
|
|
|
|
if (src->connect == GST_JACK_CONNECT_EXPLICIT) {
|
|
|
|
min = max;
|
|
|
|
} else {
|
|
|
|
min = MIN (1, max);
|
|
|
|
}
|
2008-08-07 08:47:40 +00:00
|
|
|
|
|
|
|
rate = jack_get_sample_rate (client);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (src, "got %d-%d ports, samplerate: %d", min, max, rate);
|
|
|
|
|
|
|
|
if (!src->caps) {
|
2011-08-18 17:21:07 +00:00
|
|
|
src->caps = gst_caps_new_simple ("audio/x-raw",
|
|
|
|
"format", G_TYPE_STRING, GST_JACK_FORMAT_STR,
|
2021-07-26 09:43:04 +00:00
|
|
|
"layout", G_TYPE_STRING, "interleaved", "rate", G_TYPE_INT, rate, NULL);
|
|
|
|
if (min == max) {
|
|
|
|
gst_caps_set_simple (src->caps, "channels", G_TYPE_INT, min, NULL);
|
|
|
|
} else {
|
|
|
|
gst_caps_set_simple (src->caps,
|
|
|
|
"channels", GST_TYPE_INT_RANGE, min, max, NULL);
|
|
|
|
}
|
2008-08-07 08:47:40 +00:00
|
|
|
}
|
|
|
|
GST_INFO_OBJECT (src, "returning caps %" GST_PTR_FORMAT, src->caps);
|
|
|
|
|
|
|
|
return gst_caps_ref (src->caps);
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
no_client:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (src, "device not open, using template caps");
|
|
|
|
/* base class will get template caps for us when we return NULL */
|
|
|
|
return NULL;
|
|
|
|
}
|
2021-07-27 09:33:18 +00:00
|
|
|
no_port_names:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS,
|
|
|
|
("User must provide valid port names"),
|
|
|
|
("\"port-names\" contains invalid name or NULL string"));
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-08-07 08:47:40 +00:00
|
|
|
}
|
|
|
|
|
2011-11-11 10:24:00 +00:00
|
|
|
static GstAudioRingBuffer *
|
2011-11-11 10:53:45 +00:00
|
|
|
gst_jack_audio_src_create_ringbuffer (GstAudioBaseSrc * src)
|
2008-08-07 08:47:40 +00:00
|
|
|
{
|
2011-11-11 10:24:00 +00:00
|
|
|
GstAudioRingBuffer *buffer;
|
2008-08-07 08:47:40 +00:00
|
|
|
|
|
|
|
buffer = g_object_new (GST_TYPE_JACK_RING_BUFFER, NULL);
|
|
|
|
GST_DEBUG_OBJECT (src, "created ringbuffer @%p", buffer);
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
}
|