2 * Copyright (C) 2008 Tristan Matthews <tristan@sat.qc.ca>
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
22 * Alternatively, the contents of this file may be used under the
23 * GNU Lesser General Public License Version 2.1 (the "LGPL"), in
24 * which case the following provisions apply instead of the ones
27 * This library is free software; you can redistribute it and/or
28 * modify it under the terms of the GNU Library General Public
29 * License as published by the Free Software Foundation; either
30 * version 2 of the License, or (at your option) any later version.
32 * This library is distributed in the hope that it will be useful,
33 * but WITHOUT ANY WARRANTY; without even the implied warranty of
34 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
35 * Library General Public License for more details.
37 * You should have received a copy of the GNU Library General Public
38 * License along with this library; if not, write to the
39 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
40 * Boston, MA 02110-1301, USA.
44 * SECTION:element-jackaudiosrc
45 * @see_also: #GstAudioBaseSrc, #GstAudioRingBuffer
47 * A Src that inputs data from Jack ports.
49 * It will create N Jack ports named in_<name>_<num> where
50 * <name> is the element name and <num> is starting from 1.
51 * Each port corresponds to a gstreamer channel.
53 * The samplerate as exposed on the caps is always the same as the samplerate of
56 * When the #GstJackAudioSrc:connect property is set to auto, this element
57 * will try to connect each input port to a random physical jack output pin.
59 * When the #GstJackAudioSrc:connect property is set to none, the element will
60 * accept any number of output channels and will create (but not connect) an
61 * input port for each channel.
63 * The element will generate an error when the Jack server is shut down when it
64 * was PAUSED or PLAYING. This element does not support dynamic rate and buffer
65 * size changes at runtime.
68 * <title>Example launch line</title>
70 * gst-launch-1.0 jackaudiosrc connect=0 ! jackaudiosink connect=0
71 * ]| Get audio input into gstreamer from jack.
79 #include <gst/gst-i18n-plugin.h>
83 #include <gst/audio/audio.h>
85 #include "gstjackaudiosrc.h"
86 #include "gstjackringbuffer.h"
87 #include "gstjackutil.h"
89 GST_DEBUG_CATEGORY_STATIC (gst_jack_audio_src_debug);
90 #define GST_CAT_DEFAULT gst_jack_audio_src_debug
93 gst_jack_audio_src_allocate_channels (GstJackAudioSrc * src, gint channels)
95 jack_client_t *client;
97 client = gst_jack_audio_client_get_client (src->client);
99 /* remove ports we don't need */
100 while (src->port_count > channels)
101 jack_port_unregister (client, src->ports[--src->port_count]);
103 /* alloc enough input ports */
104 src->ports = g_realloc (src->ports, sizeof (jack_port_t *) * channels);
105 src->buffers = g_realloc (src->buffers, sizeof (sample_t *) * channels);
107 /* create an input port for each channel */
108 while (src->port_count < channels) {
111 /* port names start from 1 and are local to the element */
113 g_strdup_printf ("in_%s_%d", GST_ELEMENT_NAME (src),
114 src->port_count + 1);
115 src->ports[src->port_count] =
116 jack_port_register (client, name, JACK_DEFAULT_AUDIO_TYPE,
118 if (src->ports[src->port_count] == NULL)
129 gst_jack_audio_src_free_channels (GstJackAudioSrc * src)
132 jack_client_t *client;
134 client = gst_jack_audio_client_get_client (src->client);
136 /* get rid of all ports */
137 while (src->port_count) {
138 GST_LOG_OBJECT (src, "unregister port %d", i);
139 if ((res = jack_port_unregister (client, src->ports[i++])))
140 GST_DEBUG_OBJECT (src, "unregister of port failed (%d)", res);
146 g_free (src->buffers);
150 /* ringbuffer abstract base class */
152 gst_jack_ring_buffer_get_type (void)
154 static volatile gsize ringbuffer_type = 0;
156 if (g_once_init_enter (&ringbuffer_type)) {
157 static const GTypeInfo ringbuffer_info = { sizeof (GstJackRingBufferClass),
160 (GClassInitFunc) gst_jack_ring_buffer_class_init,
163 sizeof (GstJackRingBuffer),
165 (GInstanceInitFunc) gst_jack_ring_buffer_init,
168 GType tmp = g_type_register_static (GST_TYPE_AUDIO_RING_BUFFER,
169 "GstJackAudioSrcRingBuffer", &ringbuffer_info, 0);
170 g_once_init_leave (&ringbuffer_type, tmp);
173 return (GType) ringbuffer_type;
177 gst_jack_ring_buffer_class_init (GstJackRingBufferClass * klass)
179 GstAudioRingBufferClass *gstringbuffer_class;
181 gstringbuffer_class = (GstAudioRingBufferClass *) klass;
183 ring_parent_class = g_type_class_peek_parent (klass);
185 gstringbuffer_class->open_device =
186 GST_DEBUG_FUNCPTR (gst_jack_ring_buffer_open_device);
187 gstringbuffer_class->close_device =
188 GST_DEBUG_FUNCPTR (gst_jack_ring_buffer_close_device);
189 gstringbuffer_class->acquire =
190 GST_DEBUG_FUNCPTR (gst_jack_ring_buffer_acquire);
191 gstringbuffer_class->release =
192 GST_DEBUG_FUNCPTR (gst_jack_ring_buffer_release);
193 gstringbuffer_class->start = GST_DEBUG_FUNCPTR (gst_jack_ring_buffer_start);
194 gstringbuffer_class->pause = GST_DEBUG_FUNCPTR (gst_jack_ring_buffer_pause);
195 gstringbuffer_class->resume = GST_DEBUG_FUNCPTR (gst_jack_ring_buffer_start);
196 gstringbuffer_class->stop = GST_DEBUG_FUNCPTR (gst_jack_ring_buffer_stop);
198 gstringbuffer_class->delay = GST_DEBUG_FUNCPTR (gst_jack_ring_buffer_delay);
201 /* this is the callback of jack. This should be RT-safe.
202 * Writes samples from the jack input port's buffer to the gst ring buffer.
205 jack_process_cb (jack_nframes_t nframes, void *arg)
207 GstJackAudioSrc *src;
208 GstAudioRingBuffer *buf;
212 gint channels, i, j, flen;
215 buf = GST_AUDIO_RING_BUFFER_CAST (arg);
216 src = GST_JACK_AUDIO_SRC (GST_OBJECT_PARENT (buf));
218 channels = GST_AUDIO_INFO_CHANNELS (&buf->spec.info);
220 /* get input buffers */
221 for (i = 0; i < channels; i++)
223 (sample_t *) jack_port_get_buffer (src->ports[i], nframes);
225 if (gst_audio_ring_buffer_prepare_read (buf, &writeseg, &writeptr, &len)) {
226 flen = len / channels;
228 /* the number of samples must be exactly the segment size */
229 if (nframes * sizeof (sample_t) != flen)
232 /* the samples in the jack input buffers have to be interleaved into the
234 data = (sample_t *) writeptr;
235 for (i = 0; i < nframes; ++i)
236 for (j = 0; j < channels; ++j)
237 *data++ = src->buffers[j][i];
239 GST_DEBUG ("copy %d frames: %p, %d bytes, %d channels", nframes, writeptr,
240 len / channels, channels);
242 /* we wrote one segment */
243 gst_audio_ring_buffer_advance (buf, 1);
250 GST_ERROR_OBJECT (src, "nbytes (%d) != flen (%d)",
251 (gint) (nframes * sizeof (sample_t)), flen);
258 jack_sample_rate_cb (jack_nframes_t nframes, void *arg)
260 GstJackAudioSrc *src;
261 GstJackRingBuffer *abuf;
263 abuf = GST_JACK_RING_BUFFER_CAST (arg);
264 src = GST_JACK_AUDIO_SRC (GST_OBJECT_PARENT (arg));
266 if (abuf->sample_rate != -1 && abuf->sample_rate != nframes)
274 GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS,
275 (NULL), ("Jack changed the sample rate, which is not supported"));
282 jack_buffer_size_cb (jack_nframes_t nframes, void *arg)
284 GstJackAudioSrc *src;
285 GstJackRingBuffer *abuf;
287 abuf = GST_JACK_RING_BUFFER_CAST (arg);
288 src = GST_JACK_AUDIO_SRC (GST_OBJECT_PARENT (arg));
290 if (abuf->buffer_size != -1 && abuf->buffer_size != nframes)
298 GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS,
299 (NULL), ("Jack changed the buffer size, which is not supported"));
305 jack_shutdown_cb (void *arg)
307 GstJackAudioSrc *src;
309 src = GST_JACK_AUDIO_SRC (GST_OBJECT_PARENT (arg));
311 GST_DEBUG_OBJECT (src, "shutdown");
313 GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND,
314 (NULL), ("Jack server shutdown"));
318 gst_jack_ring_buffer_init (GstJackRingBuffer * buf,
319 GstJackRingBufferClass * g_class)
322 buf->buffer_size = -1;
323 buf->sample_rate = -1;
326 /* the _open_device method should make a connection with the server
329 gst_jack_ring_buffer_open_device (GstAudioRingBuffer * buf)
331 GstJackAudioSrc *src;
332 jack_status_t status = 0;
335 src = GST_JACK_AUDIO_SRC (GST_OBJECT_PARENT (buf));
337 GST_DEBUG_OBJECT (src, "open");
339 if (src->client_name) {
340 name = src->client_name;
342 name = g_get_application_name ();
347 src->client = gst_jack_audio_client_new (name, src->server,
349 GST_JACK_CLIENT_SOURCE,
351 jack_process_cb, jack_buffer_size_cb, jack_sample_rate_cb, buf, &status);
352 if (src->client == NULL)
355 GST_DEBUG_OBJECT (src, "opened");
362 if (status & (JackServerFailed | JackFailure)) {
363 GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND,
364 (_("Jack server not found")),
365 ("Cannot connect to the Jack server (status %d)", status));
367 GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ,
368 (NULL), ("Jack client open error (status %d)", status));
374 /* close the connection with the server
377 gst_jack_ring_buffer_close_device (GstAudioRingBuffer * buf)
379 GstJackAudioSrc *src;
381 src = GST_JACK_AUDIO_SRC (GST_OBJECT_PARENT (buf));
383 GST_DEBUG_OBJECT (src, "close");
385 gst_jack_audio_src_free_channels (src);
386 gst_jack_audio_client_free (src->client);
393 /* allocate a buffer and setup resources to process the audio samples of
394 * the format as specified in @spec.
396 * We allocate N jack ports, one for each channel. If we are asked to
397 * automatically make a connection with physical ports, we connect as many
398 * ports as there are physical ports, leaving leftover ports unconnected.
400 * It is assumed that samplerate and number of channels are acceptable since our
401 * getcaps method will always provide correct values. If unacceptable caps are
402 * received for some reason, we fail here.
405 gst_jack_ring_buffer_acquire (GstAudioRingBuffer * buf,
406 GstAudioRingBufferSpec * spec)
408 GstJackAudioSrc *src;
409 GstJackRingBuffer *abuf;
411 gint sample_rate, buffer_size;
412 gint i, bpf, rate, channels, res;
413 jack_client_t *client;
415 src = GST_JACK_AUDIO_SRC (GST_OBJECT_PARENT (buf));
416 abuf = GST_JACK_RING_BUFFER_CAST (buf);
418 GST_DEBUG_OBJECT (src, "acquire");
420 client = gst_jack_audio_client_get_client (src->client);
422 rate = GST_AUDIO_INFO_RATE (&spec->info);
424 /* sample rate must be that of the server */
425 sample_rate = jack_get_sample_rate (client);
426 if (sample_rate != rate)
427 goto wrong_samplerate;
429 bpf = GST_AUDIO_INFO_BPF (&spec->info);
430 channels = GST_AUDIO_INFO_CHANNELS (&spec->info);
432 if (!gst_jack_audio_src_allocate_channels (src, channels))
435 gst_jack_set_layout (buf, spec);
437 buffer_size = jack_get_buffer_size (client);
439 /* the segment size in bytes, this is large enough to hold a buffer of 32bit floats
440 * for all channels */
441 spec->segsize = buffer_size * sizeof (gfloat) * channels;
442 spec->latency_time = gst_util_uint64_scale (spec->segsize,
443 (GST_SECOND / GST_USECOND), rate * bpf);
444 /* segtotal based on buffer-time latency */
445 spec->segtotal = spec->buffer_time / spec->latency_time;
446 if (spec->segtotal < 2) {
448 spec->buffer_time = spec->latency_time * spec->segtotal;
451 GST_DEBUG_OBJECT (src, "buffer time: %" G_GINT64_FORMAT " usec",
453 GST_DEBUG_OBJECT (src, "latency time: %" G_GINT64_FORMAT " usec",
455 GST_DEBUG_OBJECT (src, "buffer_size %d, segsize %d, segtotal %d",
456 buffer_size, spec->segsize, spec->segtotal);
458 /* allocate the ringbuffer memory now */
459 buf->size = spec->segtotal * spec->segsize;
460 buf->memory = g_malloc0 (buf->size);
462 if ((res = gst_jack_audio_client_set_active (src->client, TRUE)))
463 goto could_not_activate;
465 /* if we need to automatically connect the ports, do so now. We must do this
466 * after activating the client. */
467 if (src->connect == GST_JACK_CONNECT_AUTO
468 || src->connect == GST_JACK_CONNECT_AUTO_FORCED) {
469 /* find all the physical output ports. A physical output port is a port
470 * associated with a hardware device. Someone needs connect to a physical
471 * port in order to capture something. */
473 if (src->port_pattern == NULL) {
474 ports = jack_get_ports (client, NULL, NULL,
475 JackPortIsPhysical | JackPortIsOutput);
477 ports = jack_get_ports (client, src->port_pattern, NULL,
482 /* no ports? fine then we don't do anything except for posting a warning
484 GST_ELEMENT_WARNING (src, RESOURCE, NOT_FOUND, (NULL),
485 ("No physical output ports found, leaving ports unconnected"));
489 for (i = 0; i < channels; i++) {
490 /* stop when all output ports are exhausted */
491 if (ports[i] == NULL) {
492 /* post a warning that we could not connect all ports */
493 GST_ELEMENT_WARNING (src, RESOURCE, NOT_FOUND, (NULL),
494 ("No more physical ports, leaving some ports unconnected"));
497 GST_DEBUG_OBJECT (src, "try connecting to %s",
498 jack_port_name (src->ports[i]));
500 /* connect the physical port to a port */
501 res = jack_connect (client, ports[i], jack_port_name (src->ports[i]));
502 if (res != 0 && res != EEXIST)
509 abuf->sample_rate = sample_rate;
510 abuf->buffer_size = buffer_size;
511 abuf->channels = channels;
518 GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS, (NULL),
519 ("Wrong samplerate, server is running at %d and we received %d",
525 GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS, (NULL),
526 ("Cannot allocate more Jack ports"));
531 GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS, (NULL),
532 ("Could not activate client (%d:%s)", res, g_strerror (res)));
537 GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS, (NULL),
538 ("Could not connect input ports to physical ports (%d:%s)",
539 res, g_strerror (res)));
545 /* function is called with LOCK */
547 gst_jack_ring_buffer_release (GstAudioRingBuffer * buf)
549 GstJackAudioSrc *src;
550 GstJackRingBuffer *abuf;
553 abuf = GST_JACK_RING_BUFFER_CAST (buf);
554 src = GST_JACK_AUDIO_SRC (GST_OBJECT_PARENT (buf));
556 GST_DEBUG_OBJECT (src, "release");
558 if ((res = gst_jack_audio_client_set_active (src->client, FALSE))) {
559 /* we only warn, this means the server is probably shut down and the client
561 GST_ELEMENT_WARNING (src, RESOURCE, CLOSE, (NULL),
562 ("Could not deactivate Jack client (%d)", res));
566 abuf->buffer_size = -1;
567 abuf->sample_rate = -1;
569 /* free the buffer */
570 g_free (buf->memory);
577 gst_jack_ring_buffer_start (GstAudioRingBuffer * buf)
579 GstJackAudioSrc *src;
581 src = GST_JACK_AUDIO_SRC (GST_OBJECT_PARENT (buf));
583 GST_DEBUG_OBJECT (src, "start");
585 if (src->transport & GST_JACK_TRANSPORT_MASTER) {
586 jack_client_t *client;
588 client = gst_jack_audio_client_get_client (src->client);
589 jack_transport_start (client);
596 gst_jack_ring_buffer_pause (GstAudioRingBuffer * buf)
598 GstJackAudioSrc *src;
600 src = GST_JACK_AUDIO_SRC (GST_OBJECT_PARENT (buf));
602 GST_DEBUG_OBJECT (src, "pause");
604 if (src->transport & GST_JACK_TRANSPORT_MASTER) {
605 jack_client_t *client;
607 client = gst_jack_audio_client_get_client (src->client);
608 jack_transport_stop (client);
615 gst_jack_ring_buffer_stop (GstAudioRingBuffer * buf)
617 GstJackAudioSrc *src;
619 src = GST_JACK_AUDIO_SRC (GST_OBJECT_PARENT (buf));
621 GST_DEBUG_OBJECT (src, "stop");
623 if (src->transport & GST_JACK_TRANSPORT_MASTER) {
624 jack_client_t *client;
626 client = gst_jack_audio_client_get_client (src->client);
627 jack_transport_stop (client);
633 #if defined (HAVE_JACK_0_120_1) || defined(HAVE_JACK_1_9_7)
635 gst_jack_ring_buffer_delay (GstAudioRingBuffer * buf)
637 GstJackAudioSrc *src;
639 jack_latency_range_t range;
641 src = GST_JACK_AUDIO_SRC (GST_OBJECT_PARENT (buf));
643 for (i = 0; i < src->port_count; i++) {
644 jack_port_get_latency_range (src->ports[i], JackCaptureLatency, &range);
649 GST_DEBUG_OBJECT (src, "delay %u", res);
653 #else /* !(defined (HAVE_JACK_0_120_1) || defined(HAVE_JACK_1_9_7)) */
655 gst_jack_ring_buffer_delay (GstAudioRingBuffer * buf)
657 GstJackAudioSrc *src;
660 jack_client_t *client;
662 src = GST_JACK_AUDIO_SRC (GST_OBJECT_PARENT (buf));
664 client = gst_jack_audio_client_get_client (src->client);
666 for (i = 0; i < src->port_count; i++) {
667 latency = jack_port_get_total_latency (client, src->ports[i]);
672 GST_DEBUG_OBJECT (src, "delay %u", res);
678 /* Audiosrc signals and args */
685 #define DEFAULT_PROP_CONNECT GST_JACK_CONNECT_AUTO
686 #define DEFAULT_PROP_SERVER NULL
687 #define DEFAULT_PROP_CLIENT_NAME NULL
688 #define DEFAULT_PROP_TRANSPORT GST_JACK_TRANSPORT_AUTONOMOUS
689 #define DEFAULT_PROP_PORT_PATTERN NULL
702 /* the capabilities of the inputs and outputs.
704 * describe the real formats here.
707 static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
710 GST_STATIC_CAPS ("audio/x-raw, "
711 "format = (string) " GST_JACK_FORMAT_STR ", "
712 "layout = (string) interleaved, "
713 "rate = (int) [ 1, MAX ], " "channels = (int) [ 1, MAX ]")
716 #define gst_jack_audio_src_parent_class parent_class
717 G_DEFINE_TYPE (GstJackAudioSrc, gst_jack_audio_src, GST_TYPE_AUDIO_BASE_SRC);
719 static void gst_jack_audio_src_dispose (GObject * object);
720 static void gst_jack_audio_src_set_property (GObject * object, guint prop_id,
721 const GValue * value, GParamSpec * pspec);
722 static void gst_jack_audio_src_get_property (GObject * object, guint prop_id,
723 GValue * value, GParamSpec * pspec);
725 static GstCaps *gst_jack_audio_src_getcaps (GstBaseSrc * bsrc,
727 static GstAudioRingBuffer *gst_jack_audio_src_create_ringbuffer (GstAudioBaseSrc
730 /* GObject vmethod implementations */
732 /* initialize the jack_audio_src's class */
734 gst_jack_audio_src_class_init (GstJackAudioSrcClass * klass)
736 GObjectClass *gobject_class;
737 GstElementClass *gstelement_class;
738 GstBaseSrcClass *gstbasesrc_class;
739 GstAudioBaseSrcClass *gstaudiobasesrc_class;
741 GST_DEBUG_CATEGORY_INIT (gst_jack_audio_src_debug, "jacksrc", 0,
744 gobject_class = (GObjectClass *) klass;
745 gstelement_class = (GstElementClass *) klass;
746 gstbasesrc_class = (GstBaseSrcClass *) klass;
747 gstaudiobasesrc_class = (GstAudioBaseSrcClass *) klass;
749 gobject_class->dispose = gst_jack_audio_src_dispose;
750 gobject_class->set_property = gst_jack_audio_src_set_property;
751 gobject_class->get_property = gst_jack_audio_src_get_property;
753 g_object_class_install_property (gobject_class, PROP_CONNECT,
754 g_param_spec_enum ("connect", "Connect",
755 "Specify how the input ports will be connected",
756 GST_TYPE_JACK_CONNECT, DEFAULT_PROP_CONNECT,
757 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
759 g_object_class_install_property (gobject_class, PROP_SERVER,
760 g_param_spec_string ("server", "Server",
761 "The Jack server to connect to (NULL = default)",
762 DEFAULT_PROP_SERVER, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
765 * GstJackAudioSrc:client-name:
767 * The client name to use.
769 g_object_class_install_property (gobject_class, PROP_CLIENT_NAME,
770 g_param_spec_string ("client-name", "Client name",
771 "The client name of the Jack instance (NULL = default)",
772 DEFAULT_PROP_CLIENT_NAME,
773 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
775 g_object_class_install_property (gobject_class, PROP_CLIENT,
776 g_param_spec_boxed ("client", "JackClient", "Handle for jack client",
777 GST_TYPE_JACK_CLIENT,
778 GST_PARAM_MUTABLE_READY | G_PARAM_READWRITE |
779 G_PARAM_STATIC_STRINGS));
781 * GstJackAudioSrc:port-pattern
783 * autoconnect to ports matching pattern, when NULL connect to physical ports
787 g_object_class_install_property (gobject_class, PROP_PORT_PATTERN,
788 g_param_spec_string ("port-pattern", "port pattern",
789 "A pattern to select which ports to connect to (NULL = first physical ports)",
790 DEFAULT_PROP_PORT_PATTERN,
791 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
794 * GstJackAudioSink:transport:
796 * The jack transport behaviour for the client.
798 g_object_class_install_property (gobject_class, PROP_TRANSPORT,
799 g_param_spec_flags ("transport", "Transport mode",
800 "Jack transport behaviour of the client",
801 GST_TYPE_JACK_TRANSPORT, DEFAULT_PROP_TRANSPORT,
802 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
804 gst_element_class_add_static_pad_template (gstelement_class, &src_factory);
806 gst_element_class_set_static_metadata (gstelement_class,
807 "Audio Source (Jack)", "Source/Audio",
808 "Captures audio from a JACK server",
809 "Tristan Matthews <tristan@sat.qc.ca>");
811 gstbasesrc_class->get_caps = GST_DEBUG_FUNCPTR (gst_jack_audio_src_getcaps);
812 gstaudiobasesrc_class->create_ringbuffer =
813 GST_DEBUG_FUNCPTR (gst_jack_audio_src_create_ringbuffer);
815 /* ref class from a thread-safe context to work around missing bit of
816 * thread-safety in GObject */
817 g_type_class_ref (GST_TYPE_JACK_RING_BUFFER);
819 gst_jack_audio_client_init ();
823 gst_jack_audio_src_init (GstJackAudioSrc * src)
825 //gst_base_src_set_live(GST_BASE_SRC (src), TRUE);
826 src->connect = DEFAULT_PROP_CONNECT;
827 src->server = g_strdup (DEFAULT_PROP_SERVER);
832 src->client_name = g_strdup (DEFAULT_PROP_CLIENT_NAME);
833 src->transport = DEFAULT_PROP_TRANSPORT;
837 gst_jack_audio_src_dispose (GObject * object)
839 GstJackAudioSrc *src = GST_JACK_AUDIO_SRC (object);
841 gst_caps_replace (&src->caps, NULL);
843 if (src->client_name != NULL) {
844 g_free (src->client_name);
845 src->client_name = NULL;
848 if (src->port_pattern != NULL) {
849 g_free (src->port_pattern);
850 src->port_pattern = NULL;
853 G_OBJECT_CLASS (parent_class)->dispose (object);
857 gst_jack_audio_src_set_property (GObject * object, guint prop_id,
858 const GValue * value, GParamSpec * pspec)
860 GstJackAudioSrc *src = GST_JACK_AUDIO_SRC (object);
863 case PROP_CLIENT_NAME:
864 g_free (src->client_name);
865 src->client_name = g_value_dup_string (value);
867 case PROP_PORT_PATTERN:
868 g_free (src->port_pattern);
869 src->port_pattern = g_value_dup_string (value);
872 src->connect = g_value_get_enum (value);
875 g_free (src->server);
876 src->server = g_value_dup_string (value);
879 if (GST_STATE (src) == GST_STATE_NULL ||
880 GST_STATE (src) == GST_STATE_READY) {
881 src->jclient = g_value_get_boxed (value);
885 src->transport = g_value_get_flags (value);
888 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
894 gst_jack_audio_src_get_property (GObject * object, guint prop_id,
895 GValue * value, GParamSpec * pspec)
897 GstJackAudioSrc *src = GST_JACK_AUDIO_SRC (object);
900 case PROP_CLIENT_NAME:
901 g_value_set_string (value, src->client_name);
903 case PROP_PORT_PATTERN:
904 g_value_set_string (value, src->port_pattern);
907 g_value_set_enum (value, src->connect);
910 g_value_set_string (value, src->server);
913 g_value_set_boxed (value, src->jclient);
916 g_value_set_flags (value, src->transport);
919 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
925 gst_jack_audio_src_getcaps (GstBaseSrc * bsrc, GstCaps * filter)
927 GstJackAudioSrc *src = GST_JACK_AUDIO_SRC (bsrc);
931 jack_client_t *client;
933 if (src->client == NULL)
936 client = gst_jack_audio_client_get_client (src->client);
938 if (src->connect == GST_JACK_CONNECT_AUTO) {
939 /* get a port count, this is the number of channels we can automatically
941 ports = jack_get_ports (client, NULL, NULL,
942 JackPortIsPhysical | JackPortIsOutput);
945 for (; ports[max]; max++);
951 /* we allow any number of pads, something else is going to connect the
957 rate = jack_get_sample_rate (client);
959 GST_DEBUG_OBJECT (src, "got %d-%d ports, samplerate: %d", min, max, rate);
962 src->caps = gst_caps_new_simple ("audio/x-raw",
963 "format", G_TYPE_STRING, GST_JACK_FORMAT_STR,
964 "layout", G_TYPE_STRING, "interleaved",
965 "rate", G_TYPE_INT, rate,
966 "channels", GST_TYPE_INT_RANGE, min, max, NULL);
968 GST_INFO_OBJECT (src, "returning caps %" GST_PTR_FORMAT, src->caps);
970 return gst_caps_ref (src->caps);
975 GST_DEBUG_OBJECT (src, "device not open, using template caps");
976 /* base class will get template caps for us when we return NULL */
981 static GstAudioRingBuffer *
982 gst_jack_audio_src_create_ringbuffer (GstAudioBaseSrc * src)
984 GstAudioRingBuffer *buffer;
986 buffer = g_object_new (GST_TYPE_JACK_RING_BUFFER, NULL);
987 GST_DEBUG_OBJECT (src, "created ringbuffer @%p", buffer);