2007-08-22 21:50:59 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* BlueZ - Bluetooth protocol stack for Linux
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004-2007 Marcel Holtmann <marcel@holtmann.org>
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2007-08-26 14:14:34 +00:00
|
|
|
#include <unistd.h>
|
2007-10-18 21:50:00 +00:00
|
|
|
#include <pthread.h>
|
|
|
|
|
2007-11-01 19:45:00 +00:00
|
|
|
#include "gstsbcutil.h"
|
2007-08-22 21:50:59 +00:00
|
|
|
#include "gsta2dpsink.h"
|
|
|
|
|
2008-01-23 13:14:02 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (gst_a2dp_sink_debug);
|
|
|
|
#define GST_CAT_DEFAULT gst_a2dp_sink_debug
|
2007-10-18 21:50:00 +00:00
|
|
|
|
2008-01-23 13:14:02 +00:00
|
|
|
#define A2DP_SBC_RTP_PAYLOAD_TYPE 1
|
|
|
|
#define TEMPLATE_MAX_BITPOOL_STR "64"
|
2007-08-26 14:14:34 +00:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
2008-01-23 13:14:02 +00:00
|
|
|
PROP_DEVICE
|
2007-08-26 14:14:34 +00:00
|
|
|
};
|
|
|
|
|
2008-01-23 13:14:02 +00:00
|
|
|
GST_BOILERPLATE (GstA2dpSink, gst_a2dp_sink, GstBin, GST_TYPE_BIN);
|
2007-08-22 21:50:59 +00:00
|
|
|
|
2008-01-23 13:14:02 +00:00
|
|
|
static const GstElementDetails gst_a2dp_sink_details =
|
2007-08-22 21:50:59 +00:00
|
|
|
GST_ELEMENT_DETAILS ("Bluetooth A2DP sink",
|
|
|
|
"Sink/Audio",
|
|
|
|
"Plays audio to an A2DP device",
|
|
|
|
"Marcel Holtmann <marcel@holtmann.org>");
|
|
|
|
|
2008-01-23 13:14:02 +00:00
|
|
|
static GstStaticPadTemplate gst_a2dp_sink_factory =
|
2007-08-26 14:14:34 +00:00
|
|
|
GST_STATIC_PAD_TEMPLATE ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS ("audio/x-sbc, "
|
|
|
|
"rate = (int) { 16000, 32000, 44100, 48000 }, "
|
|
|
|
"channels = (int) [ 1, 2 ], "
|
|
|
|
"mode = (string) { mono, dual, stereo, joint }, "
|
|
|
|
"blocks = (int) { 4, 8, 12, 16 }, "
|
2008-01-23 13:14:02 +00:00
|
|
|
"subbands = (int) { 4, 8 }, "
|
|
|
|
"allocation = (string) { snr, loudness }, "
|
2008-01-23 13:19:32 +00:00
|
|
|
"bitpool = (int) [ 2, " TEMPLATE_MAX_BITPOOL_STR " ]; " "audio/mpeg;"));
|
|
|
|
|
|
|
|
static gboolean gst_a2dp_sink_handle_event (GstPad * pad, GstEvent * event);
|
|
|
|
static gboolean gst_a2dp_sink_set_caps (GstPad * pad, GstCaps * caps);
|
|
|
|
static GstCaps *gst_a2dp_sink_get_caps (GstPad * pad);
|
|
|
|
static gboolean gst_a2dp_sink_init_caps_filter (GstA2dpSink * self);
|
2007-11-21 20:24:11 +00:00
|
|
|
|
2008-01-23 13:23:01 +00:00
|
|
|
/*
|
|
|
|
* Helper function to create elements, add to the bin and link it
|
|
|
|
* to another element.
|
|
|
|
*/
|
|
|
|
static GstElement *
|
|
|
|
gst_a2dp_sink_init_element (GstA2dpSink * self,
|
|
|
|
const gchar * elementname, const gchar * name, GstElement * link_to)
|
|
|
|
{
|
|
|
|
GstElement *element;
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (self, "Initializing %s", elementname);
|
|
|
|
|
|
|
|
element = gst_element_factory_make (elementname, name);
|
|
|
|
if (element == NULL) {
|
|
|
|
GST_ERROR_OBJECT (self, "Couldn't create %s", elementname);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gst_bin_add (GST_BIN (self), element)) {
|
|
|
|
GST_ERROR_OBJECT (self, "failed to add %s to the bin", elementname);
|
|
|
|
goto cleanup_and_fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gst_element_set_state (element, GST_STATE_READY) ==
|
|
|
|
GST_STATE_CHANGE_FAILURE) {
|
|
|
|
GST_ERROR_OBJECT (self, "%s failed to go to ready", elementname);
|
|
|
|
goto remove_element_and_fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gst_element_link (link_to, element)) {
|
|
|
|
GST_ERROR_OBJECT (self, "couldn't link %s", elementname);
|
|
|
|
goto remove_element_and_fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
return element;
|
|
|
|
|
|
|
|
remove_element_and_fail:
|
|
|
|
gst_element_set_state (element, GST_STATE_NULL);
|
|
|
|
gst_bin_remove (GST_BIN (self), element);
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
cleanup_and_fail:
|
|
|
|
if (element != NULL)
|
|
|
|
g_object_unref (G_OBJECT (element));
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-08-22 21:50:59 +00:00
|
|
|
static void
|
2007-08-23 19:12:23 +00:00
|
|
|
gst_a2dp_sink_base_init (gpointer g_class)
|
2007-08-22 21:50:59 +00:00
|
|
|
{
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
|
|
|
|
2008-01-23 13:14:02 +00:00
|
|
|
gst_element_class_set_details (element_class, &gst_a2dp_sink_details);
|
2007-08-22 21:50:59 +00:00
|
|
|
gst_element_class_add_pad_template (element_class,
|
2008-01-23 13:14:02 +00:00
|
|
|
gst_static_pad_template_get (&gst_a2dp_sink_factory));
|
2007-08-22 21:50:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-08-26 14:14:34 +00:00
|
|
|
gst_a2dp_sink_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
2007-08-22 21:50:59 +00:00
|
|
|
{
|
2008-01-23 13:14:02 +00:00
|
|
|
GstA2dpSink *self = GST_A2DP_SINK (object);
|
2007-08-26 14:14:34 +00:00
|
|
|
|
2007-08-22 21:50:59 +00:00
|
|
|
switch (prop_id) {
|
2007-08-26 14:14:34 +00:00
|
|
|
case PROP_DEVICE:
|
2008-01-23 13:14:02 +00:00
|
|
|
if (self->sink != NULL)
|
2008-01-23 15:18:15 +00:00
|
|
|
gst_avdtp_sink_set_device (self->sink, g_value_get_string (value));
|
2008-01-23 13:14:02 +00:00
|
|
|
|
|
|
|
if (self->device != NULL)
|
|
|
|
g_free (self->device);
|
|
|
|
self->device = g_value_dup_string (value);
|
2007-08-26 14:14:34 +00:00
|
|
|
break;
|
|
|
|
|
2007-08-22 21:50:59 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-08-26 14:14:34 +00:00
|
|
|
gst_a2dp_sink_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec)
|
2007-08-22 21:50:59 +00:00
|
|
|
{
|
2008-01-23 13:14:02 +00:00
|
|
|
GstA2dpSink *self = GST_A2DP_SINK (object);
|
|
|
|
gchar *device;
|
2007-08-26 14:14:34 +00:00
|
|
|
|
2007-08-22 21:50:59 +00:00
|
|
|
switch (prop_id) {
|
2007-08-26 14:14:34 +00:00
|
|
|
case PROP_DEVICE:
|
2008-01-23 13:14:02 +00:00
|
|
|
if (self->sink != NULL) {
|
2008-01-23 15:18:15 +00:00
|
|
|
device = gst_avdtp_sink_get_device (self->sink);
|
2008-01-23 13:14:02 +00:00
|
|
|
if (device != NULL)
|
|
|
|
g_value_take_string (value, device);
|
|
|
|
}
|
2007-08-26 14:14:34 +00:00
|
|
|
break;
|
|
|
|
|
2007-08-22 21:50:59 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-23 13:19:32 +00:00
|
|
|
static gboolean
|
|
|
|
gst_a2dp_sink_init_ghost_pad (GstA2dpSink * self)
|
|
|
|
{
|
|
|
|
GstPad *capsfilter_pad;
|
|
|
|
|
|
|
|
/* we search for the capsfilter sinkpad */
|
|
|
|
capsfilter_pad = gst_element_get_static_pad (self->capsfilter, "sink");
|
|
|
|
|
|
|
|
/* now we add a ghostpad */
|
|
|
|
self->ghostpad = GST_GHOST_PAD (gst_ghost_pad_new ("sink", capsfilter_pad));
|
|
|
|
g_object_unref (capsfilter_pad);
|
|
|
|
|
|
|
|
/* the getcaps of our ghostpad must reflect the device caps */
|
|
|
|
gst_pad_set_getcaps_function (GST_PAD (self->ghostpad),
|
|
|
|
gst_a2dp_sink_get_caps);
|
|
|
|
self->ghostpad_setcapsfunc = GST_PAD_SETCAPSFUNC (self->ghostpad);
|
|
|
|
gst_pad_set_setcaps_function (GST_PAD (self->ghostpad),
|
|
|
|
GST_DEBUG_FUNCPTR (gst_a2dp_sink_set_caps));
|
|
|
|
|
|
|
|
/* we need to handle events on our own and we also need the eventfunc
|
|
|
|
* of the ghostpad for forwarding calls */
|
|
|
|
self->ghostpad_eventfunc = GST_PAD_EVENTFUNC (GST_PAD (self->ghostpad));
|
|
|
|
gst_pad_set_event_function (GST_PAD (self->ghostpad),
|
|
|
|
gst_a2dp_sink_handle_event);
|
|
|
|
|
|
|
|
if (!gst_element_add_pad (GST_ELEMENT (self), GST_PAD (self->ghostpad)))
|
|
|
|
GST_ERROR_OBJECT (self, "failed to add ghostpad");
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2008-01-23 13:23:01 +00:00
|
|
|
static void
|
|
|
|
gst_a2dp_sink_remove_dynamic_elements (GstA2dpSink * self)
|
|
|
|
{
|
|
|
|
if (self->rtp) {
|
|
|
|
GST_LOG_OBJECT (self, "removing rtp element from the bin");
|
|
|
|
if (!gst_bin_remove (GST_BIN (self), GST_ELEMENT (self->rtp)))
|
|
|
|
GST_WARNING_OBJECT (self, "failed to remove rtp " "element from bin");
|
|
|
|
else
|
|
|
|
self->rtp = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-23 13:14:02 +00:00
|
|
|
static GstStateChangeReturn
|
|
|
|
gst_a2dp_sink_change_state (GstElement * element, GstStateChange transition)
|
2007-10-18 21:50:00 +00:00
|
|
|
{
|
2008-01-23 13:19:32 +00:00
|
|
|
GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
|
2008-01-23 13:14:02 +00:00
|
|
|
GstA2dpSink *self = GST_A2DP_SINK (element);
|
2007-11-21 20:24:11 +00:00
|
|
|
|
2008-01-23 13:14:02 +00:00
|
|
|
switch (transition) {
|
2008-01-23 13:19:32 +00:00
|
|
|
case GST_STATE_CHANGE_READY_TO_PAUSED:
|
|
|
|
self->taglist = gst_tag_list_new ();
|
|
|
|
break;
|
|
|
|
|
2008-01-23 13:14:02 +00:00
|
|
|
case GST_STATE_CHANGE_NULL_TO_READY:
|
2008-01-23 13:23:01 +00:00
|
|
|
self->sink_is_in_bin = FALSE;
|
|
|
|
|
2008-01-23 13:19:32 +00:00
|
|
|
self->sink =
|
2008-01-23 15:18:15 +00:00
|
|
|
GST_AVDTP_SINK (gst_element_factory_make ("avdtpsink", "avdtpsink"));
|
2008-01-23 13:19:32 +00:00
|
|
|
if (self->sink == NULL) {
|
2008-01-23 15:18:15 +00:00
|
|
|
GST_WARNING_OBJECT (self, "failed to create avdtpsink");
|
2008-01-23 13:19:32 +00:00
|
|
|
return GST_STATE_CHANGE_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (self->device != NULL)
|
2008-01-23 15:18:15 +00:00
|
|
|
gst_avdtp_sink_set_device (self->sink, self->device);
|
2008-01-23 13:19:32 +00:00
|
|
|
|
|
|
|
ret = gst_element_set_state (GST_ELEMENT (self->sink), GST_STATE_READY);
|
|
|
|
break;
|
|
|
|
default:
|
2008-01-23 13:14:02 +00:00
|
|
|
break;
|
2008-01-23 13:19:32 +00:00
|
|
|
}
|
2007-11-21 20:24:11 +00:00
|
|
|
|
2008-01-23 13:19:32 +00:00
|
|
|
if (ret == GST_STATE_CHANGE_FAILURE)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
|
|
|
|
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
|
|
|
if (self->taglist) {
|
|
|
|
gst_tag_list_free (self->taglist);
|
|
|
|
self->taglist = NULL;
|
|
|
|
}
|
2008-01-23 13:14:02 +00:00
|
|
|
if (self->newseg_event != NULL) {
|
|
|
|
gst_event_unref (self->newseg_event);
|
|
|
|
self->newseg_event = NULL;
|
|
|
|
}
|
2008-01-23 13:19:32 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GST_STATE_CHANGE_READY_TO_NULL:
|
2008-01-23 13:23:01 +00:00
|
|
|
if (self->sink_is_in_bin) {
|
|
|
|
if (!gst_bin_remove (GST_BIN (self), GST_ELEMENT (self->sink)))
|
2008-01-23 15:18:15 +00:00
|
|
|
GST_WARNING_OBJECT (self, "Failed to remove " "avdtpsink from bin");
|
2008-01-23 13:23:01 +00:00
|
|
|
} else if (self->sink != NULL) {
|
|
|
|
gst_element_set_state (GST_ELEMENT (self->sink), GST_STATE_NULL);
|
|
|
|
g_object_unref (G_OBJECT (self->sink));
|
|
|
|
}
|
|
|
|
|
|
|
|
self->sink = NULL;
|
|
|
|
|
|
|
|
gst_a2dp_sink_remove_dynamic_elements (self);
|
|
|
|
|
2008-01-23 13:14:02 +00:00
|
|
|
break;
|
2007-10-18 21:50:00 +00:00
|
|
|
|
2008-01-23 13:14:02 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2007-10-18 21:50:00 +00:00
|
|
|
|
2008-01-23 13:19:32 +00:00
|
|
|
return ret;
|
2007-10-18 21:50:00 +00:00
|
|
|
}
|
|
|
|
|
2008-01-23 13:14:02 +00:00
|
|
|
static void
|
|
|
|
gst_a2dp_sink_class_init (GstA2dpSinkClass * klass)
|
2007-08-22 21:50:59 +00:00
|
|
|
{
|
2008-01-23 13:14:02 +00:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
2007-10-18 21:50:00 +00:00
|
|
|
|
2008-01-23 13:14:02 +00:00
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
2007-10-29 15:02:26 +00:00
|
|
|
|
2008-01-23 13:14:02 +00:00
|
|
|
object_class->set_property = GST_DEBUG_FUNCPTR (gst_a2dp_sink_set_property);
|
|
|
|
object_class->get_property = GST_DEBUG_FUNCPTR (gst_a2dp_sink_get_property);
|
2007-12-03 22:41:29 +00:00
|
|
|
|
2008-01-23 13:14:02 +00:00
|
|
|
element_class->change_state = GST_DEBUG_FUNCPTR (gst_a2dp_sink_change_state);
|
2007-10-18 21:50:00 +00:00
|
|
|
|
2008-01-23 13:14:02 +00:00
|
|
|
g_object_class_install_property (object_class, PROP_DEVICE,
|
|
|
|
g_param_spec_string ("device", "Device",
|
|
|
|
"Bluetooth remote device address", NULL, G_PARAM_READWRITE));
|
2007-10-24 21:40:35 +00:00
|
|
|
|
2008-01-23 13:14:02 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_a2dp_sink_debug, "a2dpsink", 0,
|
|
|
|
"A2DP sink element");
|
2007-08-22 21:50:59 +00:00
|
|
|
}
|
|
|
|
|
2008-01-23 13:14:02 +00:00
|
|
|
static GstCaps *
|
|
|
|
gst_a2dp_sink_get_device_caps (GstA2dpSink * self)
|
2007-08-22 21:50:59 +00:00
|
|
|
{
|
2008-01-23 15:18:15 +00:00
|
|
|
return gst_avdtp_sink_get_device_caps (self->sink);
|
2007-08-22 21:50:59 +00:00
|
|
|
}
|
|
|
|
|
2008-01-23 13:14:02 +00:00
|
|
|
static GstCaps *
|
|
|
|
gst_a2dp_sink_get_caps (GstPad * pad)
|
2007-08-22 21:50:59 +00:00
|
|
|
{
|
2008-01-23 13:14:02 +00:00
|
|
|
GstCaps *caps;
|
|
|
|
GstCaps *caps_aux;
|
|
|
|
GstA2dpSink *self = GST_A2DP_SINK (GST_PAD_PARENT (pad));
|
|
|
|
|
|
|
|
if (self->sink == NULL) {
|
|
|
|
GST_DEBUG_OBJECT (self, "a2dpsink isn't initialized "
|
|
|
|
"returning template caps");
|
|
|
|
caps = gst_static_pad_template_get_caps (&gst_a2dp_sink_factory);
|
|
|
|
} else {
|
|
|
|
GST_LOG_OBJECT (self, "Getting device caps");
|
|
|
|
caps = gst_a2dp_sink_get_device_caps (self);
|
|
|
|
if (caps == NULL)
|
|
|
|
caps = gst_static_pad_template_get_caps (&gst_a2dp_sink_factory);
|
|
|
|
}
|
|
|
|
caps_aux = gst_caps_copy (caps);
|
|
|
|
g_object_set (self->capsfilter, "caps", caps_aux, NULL);
|
|
|
|
gst_caps_unref (caps_aux);
|
|
|
|
return caps;
|
2007-11-21 20:24:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2008-01-23 13:14:02 +00:00
|
|
|
gst_a2dp_sink_init_sender_sink (GstA2dpSink * self)
|
2007-11-21 20:24:11 +00:00
|
|
|
{
|
2008-01-23 13:14:02 +00:00
|
|
|
GstElement *sink;
|
2007-11-21 20:24:11 +00:00
|
|
|
|
2008-01-23 13:14:02 +00:00
|
|
|
if (self->sink == NULL)
|
2008-01-23 15:18:15 +00:00
|
|
|
sink = gst_element_factory_make ("avdtpsink", "avdtosink");
|
2008-01-23 13:14:02 +00:00
|
|
|
else
|
|
|
|
sink = GST_ELEMENT (self->sink);
|
2007-11-21 20:24:11 +00:00
|
|
|
|
2008-01-23 13:14:02 +00:00
|
|
|
if (sink == NULL) {
|
2008-01-23 15:18:15 +00:00
|
|
|
GST_ERROR_OBJECT (self, "Couldn't create avdtpsink");
|
2008-01-23 13:14:02 +00:00
|
|
|
return FALSE;
|
2007-11-21 20:24:11 +00:00
|
|
|
}
|
|
|
|
|
2008-01-23 13:14:02 +00:00
|
|
|
if (!gst_bin_add (GST_BIN (self), sink)) {
|
2008-01-23 15:18:15 +00:00
|
|
|
GST_ERROR_OBJECT (self, "failed to add avdtpsink " "to the bin");
|
2008-01-23 13:14:02 +00:00
|
|
|
goto cleanup_and_fail;
|
2007-11-21 20:24:11 +00:00
|
|
|
}
|
|
|
|
|
2008-01-23 13:14:02 +00:00
|
|
|
if (gst_element_set_state (sink, GST_STATE_READY) == GST_STATE_CHANGE_FAILURE) {
|
2008-01-23 15:18:15 +00:00
|
|
|
GST_ERROR_OBJECT (self, "avdtpsink failed to go to ready");
|
2008-01-23 13:14:02 +00:00
|
|
|
goto remove_element_and_fail;
|
2007-11-21 20:24:11 +00:00
|
|
|
}
|
2008-01-23 13:14:02 +00:00
|
|
|
|
|
|
|
if (!gst_element_link (GST_ELEMENT (self->rtp), sink)) {
|
2008-01-23 15:18:15 +00:00
|
|
|
GST_ERROR_OBJECT (self, "couldn't link rtpsbcpay " "to avdtpsink");
|
2008-01-23 13:14:02 +00:00
|
|
|
goto remove_element_and_fail;
|
2007-11-21 20:24:11 +00:00
|
|
|
}
|
|
|
|
|
2008-01-23 15:18:15 +00:00
|
|
|
self->sink = GST_AVDTP_SINK (sink);
|
2008-01-23 13:23:01 +00:00
|
|
|
self->sink_is_in_bin = TRUE;
|
2008-01-23 13:14:02 +00:00
|
|
|
g_object_set (G_OBJECT (self->sink), "device", self->device, NULL);
|
2007-11-21 20:24:11 +00:00
|
|
|
|
2008-01-23 13:14:02 +00:00
|
|
|
gst_element_set_state (sink, GST_STATE_PAUSED);
|
2007-11-21 20:24:11 +00:00
|
|
|
|
2008-01-23 13:14:02 +00:00
|
|
|
return TRUE;
|
2007-11-21 20:24:11 +00:00
|
|
|
|
2008-01-23 13:14:02 +00:00
|
|
|
remove_element_and_fail:
|
|
|
|
gst_element_set_state (sink, GST_STATE_NULL);
|
|
|
|
gst_bin_remove (GST_BIN (self), sink);
|
|
|
|
return FALSE;
|
2007-11-21 20:24:11 +00:00
|
|
|
|
2008-01-23 13:14:02 +00:00
|
|
|
cleanup_and_fail:
|
|
|
|
if (sink != NULL)
|
|
|
|
g_object_unref (G_OBJECT (sink));
|
2007-11-21 20:24:11 +00:00
|
|
|
|
2008-01-23 13:14:02 +00:00
|
|
|
return FALSE;
|
2007-11-21 20:24:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2008-01-23 13:14:02 +00:00
|
|
|
gst_a2dp_sink_init_rtp_sbc_element (GstA2dpSink * self)
|
2007-11-21 20:24:11 +00:00
|
|
|
{
|
2008-01-23 13:14:02 +00:00
|
|
|
GstElement *rtppay;
|
2007-11-21 20:24:11 +00:00
|
|
|
|
2008-01-23 13:23:01 +00:00
|
|
|
rtppay = gst_a2dp_sink_init_element (self, "rtpsbcpay", "rtp",
|
|
|
|
self->capsfilter);
|
|
|
|
if (rtppay == NULL)
|
2007-11-21 20:24:11 +00:00
|
|
|
return FALSE;
|
2007-10-18 21:50:00 +00:00
|
|
|
|
2008-01-23 13:14:02 +00:00
|
|
|
self->rtp = GST_BASE_RTP_PAYLOAD (rtppay);
|
|
|
|
g_object_set (G_OBJECT (self->rtp), "min-frames", -1, NULL);
|
2007-10-18 21:50:00 +00:00
|
|
|
|
2008-01-23 13:14:02 +00:00
|
|
|
gst_element_set_state (rtppay, GST_STATE_PAUSED);
|
2007-10-24 21:13:12 +00:00
|
|
|
|
2008-01-23 13:14:02 +00:00
|
|
|
return TRUE;
|
2007-08-26 14:14:34 +00:00
|
|
|
}
|
|
|
|
|
2008-01-23 13:19:32 +00:00
|
|
|
static gboolean
|
|
|
|
gst_a2dp_sink_init_rtp_mpeg_element (GstA2dpSink * self)
|
|
|
|
{
|
|
|
|
GstElement *rtppay;
|
|
|
|
|
2008-01-23 13:23:01 +00:00
|
|
|
GST_LOG_OBJECT (self, "Initializing rtp mpeg element");
|
2008-01-23 13:19:32 +00:00
|
|
|
|
2008-01-23 13:23:01 +00:00
|
|
|
/* if capsfilter is not created then we can't have our rtp element */
|
|
|
|
if (self->capsfilter == NULL)
|
2008-01-23 13:19:32 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2008-01-23 13:23:01 +00:00
|
|
|
rtppay = gst_a2dp_sink_init_element (self, "rtpmpapay", "rtp",
|
|
|
|
self->capsfilter);
|
|
|
|
if (rtppay == NULL)
|
|
|
|
return FALSE;
|
2008-01-23 13:19:32 +00:00
|
|
|
|
|
|
|
self->rtp = GST_BASE_RTP_PAYLOAD (rtppay);
|
|
|
|
|
|
|
|
gst_element_set_state (rtppay, GST_STATE_PAUSED);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2007-08-26 14:14:34 +00:00
|
|
|
static gboolean
|
2008-01-23 13:23:01 +00:00
|
|
|
gst_a2dp_sink_init_dynamic_elements (GstA2dpSink * self, GstCaps * caps)
|
2007-08-26 14:14:34 +00:00
|
|
|
{
|
2008-01-23 13:14:02 +00:00
|
|
|
GstStructure *structure;
|
2008-01-23 13:19:32 +00:00
|
|
|
GstEvent *event;
|
|
|
|
GstPad *capsfilterpad;
|
|
|
|
gboolean crc;
|
|
|
|
gchar *mode = NULL;
|
2007-10-18 21:50:00 +00:00
|
|
|
|
2008-01-23 13:14:02 +00:00
|
|
|
structure = gst_caps_get_structure (caps, 0);
|
2007-11-21 20:24:11 +00:00
|
|
|
|
2008-01-23 13:14:02 +00:00
|
|
|
/* first, we need to create our rtp payloader */
|
2008-01-23 13:19:32 +00:00
|
|
|
if (gst_structure_has_name (structure, "audio/x-sbc")) {
|
2008-01-23 13:23:01 +00:00
|
|
|
GST_LOG_OBJECT (self, "sbc media received");
|
2008-01-23 13:19:32 +00:00
|
|
|
if (!gst_a2dp_sink_init_rtp_sbc_element (self))
|
|
|
|
return FALSE;
|
|
|
|
} else if (gst_structure_has_name (structure, "audio/mpeg")) {
|
2008-01-23 13:23:01 +00:00
|
|
|
GST_LOG_OBJECT (self, "mp3 media received");
|
2008-01-23 13:19:32 +00:00
|
|
|
if (!gst_a2dp_sink_init_rtp_mpeg_element (self))
|
|
|
|
return FALSE;
|
|
|
|
} else {
|
2008-01-23 13:14:02 +00:00
|
|
|
GST_ERROR_OBJECT (self, "Unexpected media type");
|
2007-10-18 21:50:00 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-01-23 13:14:02 +00:00
|
|
|
if (!gst_a2dp_sink_init_sender_sink (self))
|
2007-11-21 20:24:11 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2008-01-23 13:19:32 +00:00
|
|
|
/* check if we should push the taglist FIXME should we push this?
|
|
|
|
* we can send the tags directly if needed */
|
|
|
|
if (self->taglist != NULL && gst_structure_has_name (structure, "audio/mpeg")) {
|
|
|
|
|
|
|
|
event = gst_event_new_tag (self->taglist);
|
|
|
|
|
|
|
|
/* send directly the crc */
|
|
|
|
if (gst_tag_list_get_boolean (self->taglist, "has-crc", &crc))
|
2008-01-23 15:18:15 +00:00
|
|
|
gst_avdtp_sink_set_crc (self->sink, crc);
|
2008-01-23 13:19:32 +00:00
|
|
|
|
|
|
|
if (gst_tag_list_get_string (self->taglist, "channel-mode", &mode))
|
2008-01-23 15:18:15 +00:00
|
|
|
gst_avdtp_sink_set_channel_mode (self->sink, mode);
|
2008-01-23 13:19:32 +00:00
|
|
|
|
|
|
|
capsfilterpad = gst_ghost_pad_get_target (self->ghostpad);
|
|
|
|
gst_pad_send_event (capsfilterpad, event);
|
|
|
|
self->taglist = NULL;
|
|
|
|
g_free (mode);
|
|
|
|
}
|
|
|
|
|
2008-01-23 15:18:15 +00:00
|
|
|
if (!gst_avdtp_sink_set_device_caps (self->sink, caps))
|
2007-10-18 21:50:00 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2008-01-23 13:14:02 +00:00
|
|
|
g_object_set (G_OBJECT (self->rtp), "mtu",
|
2008-01-23 15:18:15 +00:00
|
|
|
gst_avdtp_sink_get_link_mtu (self->sink), NULL);
|
2007-11-21 20:24:11 +00:00
|
|
|
|
2008-01-23 13:14:02 +00:00
|
|
|
/* we forward our new segment here if we have one */
|
2008-01-23 13:23:01 +00:00
|
|
|
if (self->newseg_event) {
|
|
|
|
gst_pad_send_event (GST_BASE_RTP_PAYLOAD_SINKPAD (self->rtp),
|
|
|
|
self->newseg_event);
|
|
|
|
self->newseg_event = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_a2dp_sink_set_caps (GstPad * pad, GstCaps * caps)
|
|
|
|
{
|
|
|
|
GstA2dpSink *self;
|
|
|
|
|
|
|
|
self = GST_A2DP_SINK (GST_PAD_PARENT (pad));
|
|
|
|
GST_INFO_OBJECT (self, "setting caps");
|
|
|
|
|
|
|
|
/* now we know the caps */
|
|
|
|
gst_a2dp_sink_init_dynamic_elements (self, caps);
|
2007-08-26 14:14:34 +00:00
|
|
|
|
2008-01-23 13:14:02 +00:00
|
|
|
return self->ghostpad_setcapsfunc (GST_PAD (self->ghostpad), caps);
|
2007-08-22 21:50:59 +00:00
|
|
|
}
|
|
|
|
|
2008-01-23 13:14:02 +00:00
|
|
|
/* used for catching newsegment events while we don't have a sink, for
|
|
|
|
* later forwarding it to the sink */
|
2007-10-18 21:50:00 +00:00
|
|
|
static gboolean
|
2008-01-23 13:14:02 +00:00
|
|
|
gst_a2dp_sink_handle_event (GstPad * pad, GstEvent * event)
|
2007-10-18 21:50:00 +00:00
|
|
|
{
|
2008-01-23 13:14:02 +00:00
|
|
|
GstA2dpSink *self;
|
2008-01-23 13:19:32 +00:00
|
|
|
GstTagList *taglist = NULL;
|
2007-10-18 21:50:00 +00:00
|
|
|
|
2008-01-23 13:14:02 +00:00
|
|
|
self = GST_A2DP_SINK (GST_PAD_PARENT (pad));
|
2007-11-21 20:24:11 +00:00
|
|
|
|
2008-01-23 13:14:02 +00:00
|
|
|
if (GST_EVENT_TYPE (event) == GST_EVENT_NEWSEGMENT &&
|
|
|
|
gst_element_get_parent (GST_ELEMENT (self->sink)) !=
|
|
|
|
GST_OBJECT_CAST (self)) {
|
|
|
|
if (self->newseg_event != NULL)
|
|
|
|
gst_event_unref (self->newseg_event);
|
|
|
|
self->newseg_event = gst_event_ref (event);
|
2008-01-23 13:19:32 +00:00
|
|
|
} else if (GST_EVENT_TYPE (event) == GST_EVENT_TAG &&
|
|
|
|
gst_element_get_parent (GST_ELEMENT (self->sink)) !=
|
|
|
|
GST_OBJECT_CAST (self)) {
|
|
|
|
if (self->taglist == NULL) {
|
|
|
|
gst_event_parse_tag (event, &self->taglist);
|
|
|
|
} else {
|
|
|
|
gst_event_parse_tag (event, &taglist);
|
|
|
|
gst_tag_list_insert (self->taglist, taglist, GST_TAG_MERGE_REPLACE);
|
|
|
|
}
|
|
|
|
/* FIXME handle tag events */
|
2007-11-21 20:24:11 +00:00
|
|
|
}
|
|
|
|
|
2008-01-23 13:14:02 +00:00
|
|
|
return self->ghostpad_eventfunc (GST_PAD (self->ghostpad), event);
|
2007-11-21 20:24:11 +00:00
|
|
|
}
|
|
|
|
|
2007-10-18 21:50:00 +00:00
|
|
|
static gboolean
|
2008-01-23 13:14:02 +00:00
|
|
|
gst_a2dp_sink_init_caps_filter (GstA2dpSink * self)
|
2007-10-18 21:50:00 +00:00
|
|
|
{
|
2008-01-23 13:14:02 +00:00
|
|
|
GstElement *element;
|
2007-10-18 21:50:00 +00:00
|
|
|
|
2008-01-23 13:14:02 +00:00
|
|
|
element = gst_element_factory_make ("capsfilter", "filter");
|
|
|
|
if (element == NULL)
|
|
|
|
goto failed;
|
2007-10-24 21:13:12 +00:00
|
|
|
|
2008-01-23 13:14:02 +00:00
|
|
|
if (!gst_bin_add (GST_BIN (self), element))
|
|
|
|
goto failed;
|
2007-10-24 21:13:12 +00:00
|
|
|
|
2008-01-23 13:14:02 +00:00
|
|
|
self->capsfilter = element;
|
2007-10-18 21:50:00 +00:00
|
|
|
return TRUE;
|
|
|
|
|
2008-01-23 13:14:02 +00:00
|
|
|
failed:
|
|
|
|
GST_ERROR_OBJECT (self, "Failed to initialize caps filter");
|
|
|
|
return FALSE;
|
2007-08-22 21:50:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-08-26 14:14:34 +00:00
|
|
|
gst_a2dp_sink_init (GstA2dpSink * self, GstA2dpSinkClass * klass)
|
2007-08-22 21:50:59 +00:00
|
|
|
{
|
2008-01-23 13:14:02 +00:00
|
|
|
self->sink = NULL;
|
|
|
|
self->rtp = NULL;
|
|
|
|
self->device = NULL;
|
|
|
|
self->capsfilter = NULL;
|
|
|
|
self->newseg_event = NULL;
|
2008-01-23 13:19:32 +00:00
|
|
|
self->taglist = NULL;
|
|
|
|
self->ghostpad = NULL;
|
2008-01-23 13:23:01 +00:00
|
|
|
self->sink_is_in_bin = FALSE;
|
2008-01-23 13:14:02 +00:00
|
|
|
|
|
|
|
/* we initialize our capsfilter */
|
|
|
|
gst_a2dp_sink_init_caps_filter (self);
|
|
|
|
g_object_set (self->capsfilter, "caps",
|
|
|
|
gst_static_pad_template_get_caps (&gst_a2dp_sink_factory), NULL);
|
|
|
|
|
2008-01-23 13:19:32 +00:00
|
|
|
gst_a2dp_sink_init_ghost_pad (self);
|
2008-01-23 13:14:02 +00:00
|
|
|
|
2007-11-21 20:24:11 +00:00
|
|
|
}
|
|
|
|
|
2008-01-23 13:14:02 +00:00
|
|
|
gboolean
|
|
|
|
gst_a2dp_sink_plugin_init (GstPlugin * plugin)
|
2007-11-21 20:24:11 +00:00
|
|
|
{
|
2008-01-23 13:14:02 +00:00
|
|
|
return gst_element_register (plugin, "a2dpsink",
|
|
|
|
GST_RANK_PRIMARY, GST_TYPE_A2DP_SINK);
|
2007-11-21 20:24:11 +00:00
|
|
|
}
|