2011-10-17 16:55:30 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) <2011> Sebastian Dröge <sebastian.droege@collabora.co.uk>
|
|
|
|
* Copyright (C) <2011> Vincent Penquerch <vincent.penquerch@collabora.co.uk>
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "gstplaysinkconvertbin.h"
|
|
|
|
|
|
|
|
#include <gst/pbutils/pbutils.h>
|
|
|
|
#include <gst/gst-i18n-plugin.h>
|
2011-12-04 16:43:38 +00:00
|
|
|
#include "gst/glib-compat-private.h"
|
2011-10-17 16:55:30 +00:00
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_STATIC (gst_play_sink_convert_bin_debug);
|
|
|
|
#define GST_CAT_DEFAULT gst_play_sink_convert_bin_debug
|
|
|
|
|
|
|
|
#define parent_class gst_play_sink_convert_bin_parent_class
|
|
|
|
|
2011-11-07 11:43:37 +00:00
|
|
|
static gboolean gst_play_sink_convert_bin_sink_setcaps (GstPlaySinkConvertBin *
|
|
|
|
self, GstCaps * caps);
|
|
|
|
|
2011-10-17 16:55:30 +00:00
|
|
|
G_DEFINE_TYPE (GstPlaySinkConvertBin, gst_play_sink_convert_bin, GST_TYPE_BIN);
|
|
|
|
|
|
|
|
static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS_ANY);
|
|
|
|
|
|
|
|
static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS_ANY);
|
|
|
|
|
|
|
|
static gboolean
|
2011-10-17 17:29:50 +00:00
|
|
|
is_raw_caps (GstCaps * caps, gboolean audio)
|
2011-10-17 16:55:30 +00:00
|
|
|
{
|
|
|
|
gint i, n;
|
|
|
|
GstStructure *s;
|
|
|
|
const gchar *name;
|
2012-02-20 14:17:29 +00:00
|
|
|
const gchar *prefix = audio ? "audio/x-raw" : "video/x-raw";
|
2011-10-17 16:55:30 +00:00
|
|
|
|
|
|
|
n = gst_caps_get_size (caps);
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
s = gst_caps_get_structure (caps, i);
|
|
|
|
name = gst_structure_get_name (s);
|
2012-02-20 14:17:29 +00:00
|
|
|
if (!g_str_equal (name, prefix))
|
2011-10-17 16:55:30 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_play_sink_convert_bin_post_missing_element_message (GstPlaySinkConvertBin *
|
|
|
|
self, const gchar * name)
|
|
|
|
{
|
|
|
|
GstMessage *msg;
|
|
|
|
|
|
|
|
msg = gst_missing_element_message_new (GST_ELEMENT_CAST (self), name);
|
|
|
|
gst_element_post_message (GST_ELEMENT_CAST (self), msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
distribute_running_time (GstElement * element, const GstSegment * segment)
|
|
|
|
{
|
|
|
|
GstEvent *event;
|
|
|
|
GstPad *pad;
|
|
|
|
|
|
|
|
pad = gst_element_get_static_pad (element, "sink");
|
|
|
|
|
2011-10-19 13:13:39 +00:00
|
|
|
gst_pad_send_event (pad, gst_event_new_flush_start ());
|
2011-11-07 11:43:37 +00:00
|
|
|
gst_pad_send_event (pad, gst_event_new_flush_stop (FALSE));
|
2011-10-17 16:55:30 +00:00
|
|
|
|
2011-11-30 13:25:11 +00:00
|
|
|
if (segment->format != GST_FORMAT_UNDEFINED) {
|
2011-12-02 00:07:39 +00:00
|
|
|
event = gst_event_new_segment (segment);
|
2011-11-30 13:25:11 +00:00
|
|
|
gst_pad_send_event (pad, event);
|
|
|
|
}
|
2011-10-17 16:55:30 +00:00
|
|
|
|
|
|
|
gst_object_unref (pad);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gst_play_sink_convert_bin_add_conversion_element (GstPlaySinkConvertBin * self,
|
|
|
|
GstElement * el)
|
|
|
|
{
|
|
|
|
self->conversion_elements = g_list_append (self->conversion_elements, el);
|
|
|
|
gst_bin_add (GST_BIN (self), gst_object_ref (el));
|
|
|
|
}
|
|
|
|
|
|
|
|
GstElement *
|
|
|
|
gst_play_sink_convert_bin_add_conversion_element_factory (GstPlaySinkConvertBin
|
|
|
|
* self, const char *factory, const char *name)
|
|
|
|
{
|
|
|
|
GstElement *el;
|
|
|
|
|
|
|
|
el = gst_element_factory_make (factory, name);
|
|
|
|
if (el == NULL) {
|
|
|
|
gst_play_sink_convert_bin_post_missing_element_message (self, factory);
|
|
|
|
GST_ELEMENT_WARNING (self, CORE, MISSING_PLUGIN,
|
|
|
|
(_("Missing element '%s' - check your GStreamer installation."),
|
|
|
|
factory),
|
|
|
|
(self->audio ? "audio rendering might fail" :
|
|
|
|
"video rendering might fail"));
|
|
|
|
} else {
|
|
|
|
gst_play_sink_convert_bin_add_conversion_element (self, el);
|
|
|
|
}
|
|
|
|
return el;
|
|
|
|
}
|
|
|
|
|
2011-10-19 13:13:30 +00:00
|
|
|
void
|
2011-10-17 16:55:30 +00:00
|
|
|
gst_play_sink_convert_bin_add_identity (GstPlaySinkConvertBin * self)
|
|
|
|
{
|
2011-11-03 09:07:27 +00:00
|
|
|
if (self->identity)
|
|
|
|
return;
|
|
|
|
|
2011-10-17 16:55:30 +00:00
|
|
|
self->identity = gst_element_factory_make ("identity", "identity");
|
|
|
|
if (self->identity == NULL) {
|
|
|
|
gst_play_sink_convert_bin_post_missing_element_message (self, "identity");
|
|
|
|
GST_ELEMENT_WARNING (self, CORE, MISSING_PLUGIN,
|
|
|
|
(_("Missing element '%s' - check your GStreamer installation."),
|
|
|
|
"identity"), (self->audio ?
|
|
|
|
"audio rendering might fail" : "video rendering might fail")
|
|
|
|
|
|
|
|
);
|
|
|
|
} else {
|
2011-11-25 14:35:39 +00:00
|
|
|
g_object_set (self->identity, "silent", TRUE, "signal-handoffs", FALSE,
|
|
|
|
NULL);
|
2011-10-17 16:55:30 +00:00
|
|
|
gst_bin_add (GST_BIN_CAST (self), self->identity);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-10-17 17:26:48 +00:00
|
|
|
gst_play_sink_convert_bin_set_targets (GstPlaySinkConvertBin * self,
|
|
|
|
gboolean passthrough)
|
2011-10-17 16:55:30 +00:00
|
|
|
{
|
|
|
|
GstPad *pad;
|
|
|
|
GstElement *head, *tail;
|
|
|
|
|
2011-10-17 21:05:30 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "Setting pad targets with passthrough %d",
|
|
|
|
passthrough);
|
2011-10-17 17:26:48 +00:00
|
|
|
if (self->conversion_elements == NULL || passthrough) {
|
2011-10-17 22:41:11 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "no conversion elements, using identity (%p) as "
|
|
|
|
"head/tail", self->identity);
|
2011-10-17 17:26:48 +00:00
|
|
|
if (!passthrough) {
|
|
|
|
GST_WARNING_OBJECT (self,
|
|
|
|
"Doing passthrough as no converter elements were added");
|
|
|
|
}
|
2011-10-17 16:55:30 +00:00
|
|
|
head = tail = self->identity;
|
|
|
|
} else {
|
|
|
|
head = GST_ELEMENT (g_list_first (self->conversion_elements)->data);
|
|
|
|
tail = GST_ELEMENT (g_list_last (self->conversion_elements)->data);
|
2011-10-17 22:41:11 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "conversion elements in use, picking "
|
|
|
|
"head:%s and tail:%s", GST_OBJECT_NAME (head), GST_OBJECT_NAME (tail));
|
2011-10-17 16:55:30 +00:00
|
|
|
}
|
|
|
|
|
2011-10-17 22:41:11 +00:00
|
|
|
g_return_if_fail (head != NULL);
|
|
|
|
g_return_if_fail (tail != NULL);
|
|
|
|
|
2011-10-17 16:55:30 +00:00
|
|
|
pad = gst_element_get_static_pad (head, "sink");
|
2011-10-17 21:05:30 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "Ghosting bin sink pad to %" GST_PTR_FORMAT, pad);
|
2011-10-17 16:55:30 +00:00
|
|
|
gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (self->sinkpad), pad);
|
|
|
|
gst_object_unref (pad);
|
|
|
|
|
|
|
|
pad = gst_element_get_static_pad (tail, "src");
|
2011-10-17 21:05:30 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "Ghosting bin src pad to %" GST_PTR_FORMAT, pad);
|
2011-10-17 16:55:30 +00:00
|
|
|
gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (self->srcpad), pad);
|
|
|
|
gst_object_unref (pad);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_play_sink_convert_bin_remove_element (GstElement * element,
|
|
|
|
GstPlaySinkConvertBin * self)
|
|
|
|
{
|
|
|
|
gst_element_set_state (element, GST_STATE_NULL);
|
2012-03-08 14:17:40 +00:00
|
|
|
gst_object_unref (element);
|
2011-10-17 16:55:30 +00:00
|
|
|
gst_bin_remove (GST_BIN_CAST (self), element);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_play_sink_convert_bin_on_element_added (GstElement * element,
|
|
|
|
GstPlaySinkConvertBin * self)
|
|
|
|
{
|
|
|
|
gst_element_sync_state_with_parent (element);
|
|
|
|
distribute_running_time (element, &self->segment);
|
|
|
|
}
|
|
|
|
|
2011-11-07 11:43:37 +00:00
|
|
|
static GstPadProbeReturn
|
2011-11-08 10:07:18 +00:00
|
|
|
pad_blocked_cb (GstPad * pad, GstPadProbeInfo * info, gpointer user_data)
|
2011-10-17 16:55:30 +00:00
|
|
|
{
|
2011-11-07 11:43:37 +00:00
|
|
|
GstPlaySinkConvertBin *self = user_data;
|
2011-10-17 16:55:30 +00:00
|
|
|
GstPad *peer;
|
|
|
|
GstCaps *caps;
|
|
|
|
gboolean raw;
|
|
|
|
|
|
|
|
GST_PLAY_SINK_CONVERT_BIN_LOCK (self);
|
2011-11-07 11:43:37 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "Pad blocked");
|
2011-10-17 16:55:30 +00:00
|
|
|
|
|
|
|
/* There must be a peer at this point */
|
|
|
|
peer = gst_pad_get_peer (self->sinkpad);
|
2011-11-07 11:43:37 +00:00
|
|
|
caps = gst_pad_get_current_caps (peer);
|
2011-10-17 16:55:30 +00:00
|
|
|
if (!caps)
|
2011-11-15 15:48:15 +00:00
|
|
|
caps = gst_pad_query_caps (peer, NULL);
|
2011-10-17 16:55:30 +00:00
|
|
|
gst_object_unref (peer);
|
|
|
|
|
2011-10-17 17:29:50 +00:00
|
|
|
raw = is_raw_caps (caps, self->audio);
|
2011-10-17 16:55:30 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "Caps %" GST_PTR_FORMAT " are raw: %d", caps, raw);
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
|
|
|
|
if (raw == self->raw)
|
|
|
|
goto unblock;
|
|
|
|
self->raw = raw;
|
|
|
|
|
2011-10-17 17:26:48 +00:00
|
|
|
gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (self->sinkpad), NULL);
|
|
|
|
gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (self->srcpad), NULL);
|
2011-10-17 16:55:30 +00:00
|
|
|
|
2011-10-17 17:26:48 +00:00
|
|
|
if (raw) {
|
|
|
|
GST_DEBUG_OBJECT (self, "Switching to raw conversion pipeline");
|
2011-10-17 16:55:30 +00:00
|
|
|
|
|
|
|
if (self->conversion_elements)
|
|
|
|
g_list_foreach (self->conversion_elements,
|
|
|
|
(GFunc) gst_play_sink_convert_bin_on_element_added, self);
|
|
|
|
} else {
|
|
|
|
|
2011-10-17 17:26:48 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "Switch to passthrough pipeline");
|
2011-10-17 16:55:30 +00:00
|
|
|
|
2011-10-17 17:26:48 +00:00
|
|
|
gst_play_sink_convert_bin_on_element_added (self->identity, self);
|
2011-10-17 16:55:30 +00:00
|
|
|
}
|
|
|
|
|
2011-10-17 17:26:48 +00:00
|
|
|
gst_play_sink_convert_bin_set_targets (self, !raw);
|
2011-10-17 16:55:30 +00:00
|
|
|
|
|
|
|
unblock:
|
2011-11-07 11:43:37 +00:00
|
|
|
self->sink_proxypad_block_id = 0;
|
2011-10-17 16:55:30 +00:00
|
|
|
GST_PLAY_SINK_CONVERT_BIN_UNLOCK (self);
|
2011-11-07 11:43:37 +00:00
|
|
|
|
|
|
|
return GST_PAD_PROBE_REMOVE;
|
2011-10-17 16:55:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-11-17 11:48:25 +00:00
|
|
|
gst_play_sink_convert_bin_sink_event (GstPad * pad, GstObject * parent,
|
|
|
|
GstEvent * event)
|
2011-10-17 16:55:30 +00:00
|
|
|
{
|
2011-11-17 11:48:25 +00:00
|
|
|
GstPlaySinkConvertBin *self = GST_PLAY_SINK_CONVERT_BIN (parent);
|
2011-10-17 16:55:30 +00:00
|
|
|
gboolean ret;
|
|
|
|
|
2011-11-07 11:43:37 +00:00
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
case GST_EVENT_CAPS:
|
|
|
|
{
|
|
|
|
GstCaps *caps;
|
|
|
|
|
|
|
|
gst_event_parse_caps (event, &caps);
|
|
|
|
ret = gst_play_sink_convert_bin_sink_setcaps (self, caps);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-11-17 11:48:25 +00:00
|
|
|
ret = gst_proxy_pad_event_default (pad, parent, gst_event_ref (event));
|
2011-10-17 16:55:30 +00:00
|
|
|
|
2011-11-07 11:43:37 +00:00
|
|
|
if (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT) {
|
|
|
|
GstSegment seg;
|
2011-10-17 16:55:30 +00:00
|
|
|
|
|
|
|
GST_PLAY_SINK_CONVERT_BIN_LOCK (self);
|
2011-11-07 11:43:37 +00:00
|
|
|
gst_event_copy_segment (event, &seg);
|
2011-10-17 16:55:30 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (self, "Segment before %" GST_SEGMENT_FORMAT,
|
|
|
|
&self->segment);
|
2011-11-07 11:43:37 +00:00
|
|
|
self->segment = seg;
|
2011-10-17 16:55:30 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "Segment after %" GST_SEGMENT_FORMAT,
|
|
|
|
&self->segment);
|
|
|
|
GST_PLAY_SINK_CONVERT_BIN_UNLOCK (self);
|
|
|
|
} else if (GST_EVENT_TYPE (event) == GST_EVENT_FLUSH_STOP) {
|
|
|
|
GST_PLAY_SINK_CONVERT_BIN_LOCK (self);
|
|
|
|
GST_DEBUG_OBJECT (self, "Resetting segment");
|
|
|
|
gst_segment_init (&self->segment, GST_FORMAT_UNDEFINED);
|
|
|
|
GST_PLAY_SINK_CONVERT_BIN_UNLOCK (self);
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_event_unref (event);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-11-07 11:43:37 +00:00
|
|
|
static void
|
|
|
|
block_proxypad (GstPlaySinkConvertBin * self)
|
|
|
|
{
|
|
|
|
if (self->sink_proxypad_block_id == 0) {
|
|
|
|
self->sink_proxypad_block_id =
|
2011-11-07 16:10:48 +00:00
|
|
|
gst_pad_add_probe (self->sink_proxypad,
|
2012-03-22 10:35:13 +00:00
|
|
|
GST_PAD_PROBE_TYPE_BLOCK_DOWNSTREAM, pad_blocked_cb, self, NULL);
|
2011-11-07 11:43:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
unblock_proxypad (GstPlaySinkConvertBin * self)
|
|
|
|
{
|
|
|
|
if (self->sink_proxypad_block_id != 0) {
|
|
|
|
gst_pad_remove_probe (self->sink_proxypad, self->sink_proxypad_block_id);
|
|
|
|
self->sink_proxypad_block_id = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-17 16:55:30 +00:00
|
|
|
static gboolean
|
2011-11-07 11:43:37 +00:00
|
|
|
gst_play_sink_convert_bin_sink_setcaps (GstPlaySinkConvertBin * self,
|
|
|
|
GstCaps * caps)
|
2011-10-17 16:55:30 +00:00
|
|
|
{
|
|
|
|
GstStructure *s;
|
|
|
|
const gchar *name;
|
|
|
|
gboolean reconfigure = FALSE;
|
|
|
|
gboolean raw;
|
|
|
|
|
2011-11-07 11:43:37 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "setcaps");
|
2011-10-17 16:55:30 +00:00
|
|
|
GST_PLAY_SINK_CONVERT_BIN_LOCK (self);
|
|
|
|
s = gst_caps_get_structure (caps, 0);
|
|
|
|
name = gst_structure_get_name (s);
|
|
|
|
|
|
|
|
if (self->audio) {
|
2012-02-20 14:17:29 +00:00
|
|
|
raw = g_str_equal (name, "audio/x-raw");
|
2011-10-17 16:55:30 +00:00
|
|
|
} else {
|
2012-02-20 14:17:29 +00:00
|
|
|
raw = g_str_equal (name, "video/x-raw");
|
2011-10-17 16:55:30 +00:00
|
|
|
}
|
|
|
|
|
2011-10-17 21:05:30 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "raw %d, self->raw %d, blocked %d",
|
|
|
|
raw, self->raw, gst_pad_is_blocked (self->sink_proxypad));
|
2011-11-24 11:38:54 +00:00
|
|
|
|
2011-10-17 16:55:30 +00:00
|
|
|
if (raw) {
|
2011-11-24 11:38:54 +00:00
|
|
|
if (!gst_pad_is_blocked (self->sink_proxypad)) {
|
|
|
|
GstPad *target = gst_ghost_pad_get_target (GST_GHOST_PAD (self->sinkpad));
|
|
|
|
|
2011-11-26 12:12:59 +00:00
|
|
|
if (!self->raw || (target && !gst_pad_query_accept_caps (target, caps))) {
|
2011-11-24 11:38:54 +00:00
|
|
|
if (!self->raw)
|
|
|
|
GST_DEBUG_OBJECT (self, "Changing caps from non-raw to raw");
|
|
|
|
else
|
|
|
|
GST_DEBUG_OBJECT (self, "Changing caps in an incompatible way");
|
|
|
|
|
|
|
|
reconfigure = TRUE;
|
2011-11-26 12:12:59 +00:00
|
|
|
block_proxypad (self);
|
2011-11-24 11:38:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (target)
|
|
|
|
gst_object_unref (target);
|
2011-10-17 16:55:30 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (self->raw && !gst_pad_is_blocked (self->sink_proxypad)) {
|
|
|
|
GST_DEBUG_OBJECT (self, "Changing caps from raw to non-raw");
|
|
|
|
reconfigure = TRUE;
|
2011-11-07 11:43:37 +00:00
|
|
|
block_proxypad (self);
|
2011-10-17 16:55:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Otherwise the setcaps below fails */
|
|
|
|
if (reconfigure) {
|
|
|
|
gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (self->sinkpad), NULL);
|
|
|
|
gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (self->srcpad), NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_PLAY_SINK_CONVERT_BIN_UNLOCK (self);
|
|
|
|
|
2011-11-07 11:43:37 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "Setting sink caps %" GST_PTR_FORMAT, caps);
|
2011-10-17 16:55:30 +00:00
|
|
|
|
2011-11-07 11:43:37 +00:00
|
|
|
return TRUE;
|
2011-10-17 16:55:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstCaps *
|
2011-11-07 11:43:37 +00:00
|
|
|
gst_play_sink_convert_bin_getcaps (GstPad * pad, GstCaps * filter)
|
2011-10-17 16:55:30 +00:00
|
|
|
{
|
|
|
|
GstPlaySinkConvertBin *self =
|
|
|
|
GST_PLAY_SINK_CONVERT_BIN (gst_pad_get_parent (pad));
|
|
|
|
GstCaps *ret;
|
|
|
|
GstPad *otherpad, *peer;
|
|
|
|
|
|
|
|
GST_PLAY_SINK_CONVERT_BIN_LOCK (self);
|
2011-10-17 18:06:00 +00:00
|
|
|
if (pad == self->srcpad) {
|
|
|
|
otherpad = self->sinkpad;
|
|
|
|
} else if (pad == self->sinkpad) {
|
|
|
|
otherpad = self->srcpad;
|
|
|
|
} else {
|
|
|
|
GST_ERROR_OBJECT (pad, "Not one of our pads");
|
|
|
|
otherpad = NULL;
|
2011-10-17 16:55:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (otherpad) {
|
|
|
|
peer = gst_pad_get_peer (otherpad);
|
|
|
|
if (peer) {
|
2011-11-15 15:48:15 +00:00
|
|
|
GstCaps *peer_caps = gst_pad_query_caps (peer, filter);
|
2011-10-17 16:55:30 +00:00
|
|
|
gst_object_unref (peer);
|
2011-11-28 18:06:57 +00:00
|
|
|
if (self->converter_caps && is_raw_caps (peer_caps, self->audio)) {
|
2012-03-11 18:04:41 +00:00
|
|
|
ret = gst_caps_merge (peer_caps, gst_caps_ref (self->converter_caps));
|
2011-10-17 18:43:06 +00:00
|
|
|
} else {
|
|
|
|
ret = peer_caps;
|
|
|
|
}
|
2011-10-17 16:55:30 +00:00
|
|
|
} else {
|
2011-10-17 18:06:00 +00:00
|
|
|
ret = gst_caps_ref (self->converter_caps);
|
2011-10-17 16:55:30 +00:00
|
|
|
}
|
2011-10-17 18:43:06 +00:00
|
|
|
} else {
|
|
|
|
ret = gst_caps_new_any ();
|
2011-10-17 16:55:30 +00:00
|
|
|
}
|
2011-10-17 18:06:00 +00:00
|
|
|
GST_PLAY_SINK_CONVERT_BIN_UNLOCK (self);
|
|
|
|
|
2011-10-17 16:55:30 +00:00
|
|
|
gst_object_unref (self);
|
|
|
|
|
2011-11-24 11:37:58 +00:00
|
|
|
GST_DEBUG_OBJECT (pad, "Returning caps %" GST_PTR_FORMAT, ret);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_play_sink_convert_bin_acceptcaps (GstPad * pad, GstCaps * caps)
|
|
|
|
{
|
|
|
|
GstCaps *allowed_caps;
|
|
|
|
gboolean ret;
|
|
|
|
|
2011-11-26 12:12:59 +00:00
|
|
|
allowed_caps = gst_pad_query_caps (pad, NULL);
|
2011-11-24 11:37:58 +00:00
|
|
|
/* FIXME 0.11: Should be a subset check now */
|
|
|
|
ret = gst_caps_can_intersect (caps, allowed_caps);
|
|
|
|
gst_caps_unref (allowed_caps);
|
|
|
|
|
2011-10-17 16:55:30 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-11-15 15:30:38 +00:00
|
|
|
static gboolean
|
2011-11-16 16:25:17 +00:00
|
|
|
gst_play_sink_convert_bin_query (GstPad * pad, GstObject * parent,
|
|
|
|
GstQuery * query)
|
2011-11-15 15:30:38 +00:00
|
|
|
{
|
|
|
|
gboolean res = FALSE;
|
|
|
|
|
|
|
|
switch (GST_QUERY_TYPE (query)) {
|
2011-11-26 12:12:59 +00:00
|
|
|
case GST_QUERY_ACCEPT_CAPS:
|
|
|
|
{
|
|
|
|
GstCaps *caps;
|
|
|
|
|
|
|
|
gst_query_parse_accept_caps (query, &caps);
|
|
|
|
gst_query_set_accept_caps_result (query,
|
|
|
|
gst_play_sink_convert_bin_acceptcaps (pad, caps));
|
|
|
|
res = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
2011-11-15 15:30:38 +00:00
|
|
|
case GST_QUERY_CAPS:
|
|
|
|
{
|
|
|
|
GstCaps *filter, *caps;
|
|
|
|
|
|
|
|
gst_query_parse_caps (query, &filter);
|
|
|
|
caps = gst_play_sink_convert_bin_getcaps (pad, filter);
|
|
|
|
gst_query_set_caps_result (query, caps);
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
res = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
2012-02-02 11:14:15 +00:00
|
|
|
res = gst_proxy_pad_query_default (pad, parent, query);
|
2011-11-15 15:30:38 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2011-10-17 21:05:30 +00:00
|
|
|
void
|
|
|
|
gst_play_sink_convert_bin_remove_elements (GstPlaySinkConvertBin * self)
|
|
|
|
{
|
|
|
|
if (self->conversion_elements) {
|
|
|
|
g_list_foreach (self->conversion_elements,
|
|
|
|
(GFunc) gst_play_sink_convert_bin_remove_element, self);
|
|
|
|
g_list_free (self->conversion_elements);
|
|
|
|
self->conversion_elements = NULL;
|
|
|
|
}
|
|
|
|
if (self->converter_caps) {
|
|
|
|
gst_caps_unref (self->converter_caps);
|
|
|
|
self->converter_caps = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-17 16:55:30 +00:00
|
|
|
static void
|
2011-11-22 09:04:12 +00:00
|
|
|
gst_play_sink_convert_bin_dispose (GObject * object)
|
2011-10-17 16:55:30 +00:00
|
|
|
{
|
|
|
|
GstPlaySinkConvertBin *self = GST_PLAY_SINK_CONVERT_BIN_CAST (object);
|
|
|
|
|
2011-10-17 21:05:30 +00:00
|
|
|
gst_play_sink_convert_bin_remove_elements (self);
|
|
|
|
|
2011-11-22 09:04:12 +00:00
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_play_sink_convert_bin_finalize (GObject * object)
|
|
|
|
{
|
|
|
|
GstPlaySinkConvertBin *self = GST_PLAY_SINK_CONVERT_BIN_CAST (object);
|
|
|
|
|
2011-10-17 16:55:30 +00:00
|
|
|
gst_object_unref (self->sink_proxypad);
|
|
|
|
g_mutex_free (self->lock);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2011-10-17 21:05:30 +00:00
|
|
|
void
|
2011-10-17 17:54:27 +00:00
|
|
|
gst_play_sink_convert_bin_cache_converter_caps (GstPlaySinkConvertBin * self)
|
|
|
|
{
|
|
|
|
GstElement *head;
|
|
|
|
GstPad *pad;
|
|
|
|
|
2011-10-17 21:05:30 +00:00
|
|
|
if (self->converter_caps) {
|
|
|
|
gst_caps_unref (self->converter_caps);
|
|
|
|
self->converter_caps = NULL;
|
|
|
|
}
|
2011-10-17 17:54:27 +00:00
|
|
|
|
2011-10-17 18:43:06 +00:00
|
|
|
if (!self->conversion_elements) {
|
|
|
|
GST_WARNING_OBJECT (self, "No conversion elements");
|
2011-10-17 17:54:27 +00:00
|
|
|
return;
|
2011-10-17 18:43:06 +00:00
|
|
|
}
|
2011-10-17 17:54:27 +00:00
|
|
|
|
|
|
|
head = GST_ELEMENT (g_list_first (self->conversion_elements)->data);
|
|
|
|
pad = gst_element_get_static_pad (head, "sink");
|
2011-10-17 18:43:06 +00:00
|
|
|
if (!pad) {
|
|
|
|
GST_WARNING_OBJECT (self, "No sink pad found");
|
2011-10-17 17:54:27 +00:00
|
|
|
return;
|
2011-10-17 18:43:06 +00:00
|
|
|
}
|
2011-10-17 17:54:27 +00:00
|
|
|
|
2011-11-15 15:48:15 +00:00
|
|
|
self->converter_caps = gst_pad_query_caps (pad, NULL);
|
2011-10-17 17:54:27 +00:00
|
|
|
GST_INFO_OBJECT (self, "Converter caps: %" GST_PTR_FORMAT,
|
|
|
|
self->converter_caps);
|
|
|
|
|
|
|
|
gst_object_unref (pad);
|
|
|
|
}
|
|
|
|
|
2011-10-17 16:55:30 +00:00
|
|
|
static GstStateChangeReturn
|
|
|
|
gst_play_sink_convert_bin_change_state (GstElement * element,
|
|
|
|
GstStateChange transition)
|
|
|
|
{
|
|
|
|
GstStateChangeReturn ret;
|
|
|
|
GstPlaySinkConvertBin *self = GST_PLAY_SINK_CONVERT_BIN_CAST (element);
|
|
|
|
|
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
|
|
|
GST_PLAY_SINK_CONVERT_BIN_LOCK (self);
|
2011-11-07 11:43:37 +00:00
|
|
|
unblock_proxypad (self);
|
2011-10-17 16:55:30 +00:00
|
|
|
GST_PLAY_SINK_CONVERT_BIN_UNLOCK (self);
|
|
|
|
break;
|
2011-10-17 23:14:54 +00:00
|
|
|
case GST_STATE_CHANGE_READY_TO_PAUSED:
|
|
|
|
GST_PLAY_SINK_CONVERT_BIN_LOCK (self);
|
|
|
|
gst_segment_init (&self->segment, GST_FORMAT_UNDEFINED);
|
|
|
|
gst_play_sink_convert_bin_set_targets (self, TRUE);
|
|
|
|
self->raw = FALSE;
|
|
|
|
GST_PLAY_SINK_CONVERT_BIN_UNLOCK (self);
|
|
|
|
break;
|
2011-10-17 16:55:30 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
|
|
|
if (ret == GST_STATE_CHANGE_FAILURE)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
|
|
|
GST_PLAY_SINK_CONVERT_BIN_LOCK (self);
|
|
|
|
gst_segment_init (&self->segment, GST_FORMAT_UNDEFINED);
|
2011-10-17 17:26:48 +00:00
|
|
|
gst_play_sink_convert_bin_set_targets (self, TRUE);
|
2011-10-17 16:55:30 +00:00
|
|
|
self->raw = FALSE;
|
|
|
|
GST_PLAY_SINK_CONVERT_BIN_UNLOCK (self);
|
|
|
|
break;
|
|
|
|
case GST_STATE_CHANGE_READY_TO_PAUSED:
|
|
|
|
GST_PLAY_SINK_CONVERT_BIN_LOCK (self);
|
2011-11-07 11:43:37 +00:00
|
|
|
unblock_proxypad (self);
|
2011-10-17 16:55:30 +00:00
|
|
|
GST_PLAY_SINK_CONVERT_BIN_UNLOCK (self);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_play_sink_convert_bin_class_init (GstPlaySinkConvertBinClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_play_sink_convert_bin_debug,
|
|
|
|
"playsinkconvertbin", 0, "play bin");
|
|
|
|
|
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
|
|
gstelement_class = (GstElementClass *) klass;
|
|
|
|
|
2011-11-22 09:04:12 +00:00
|
|
|
gobject_class->dispose = gst_play_sink_convert_bin_dispose;
|
2011-10-17 16:55:30 +00:00
|
|
|
gobject_class->finalize = gst_play_sink_convert_bin_finalize;
|
|
|
|
|
|
|
|
gst_element_class_add_pad_template (gstelement_class,
|
|
|
|
gst_static_pad_template_get (&srctemplate));
|
|
|
|
gst_element_class_add_pad_template (gstelement_class,
|
|
|
|
gst_static_pad_template_get (&sinktemplate));
|
2012-04-09 23:45:16 +00:00
|
|
|
gst_element_class_set_static_metadata (gstelement_class,
|
2011-10-17 16:55:30 +00:00
|
|
|
"Player Sink Converter Bin", "Bin/Converter",
|
|
|
|
"Convenience bin for audio/video conversion",
|
|
|
|
"Sebastian Dröge <sebastian.droege@collabora.co.uk>");
|
|
|
|
|
|
|
|
gstelement_class->change_state =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_play_sink_convert_bin_change_state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_play_sink_convert_bin_init (GstPlaySinkConvertBin * self)
|
|
|
|
{
|
|
|
|
GstPadTemplate *templ;
|
|
|
|
|
|
|
|
self->lock = g_mutex_new ();
|
|
|
|
gst_segment_init (&self->segment, GST_FORMAT_UNDEFINED);
|
|
|
|
|
|
|
|
templ = gst_static_pad_template_get (&sinktemplate);
|
|
|
|
self->sinkpad = gst_ghost_pad_new_no_target_from_template ("sink", templ);
|
|
|
|
gst_pad_set_event_function (self->sinkpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_play_sink_convert_bin_sink_event));
|
2011-11-15 15:30:38 +00:00
|
|
|
gst_pad_set_query_function (self->sinkpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_play_sink_convert_bin_query));
|
2011-10-17 16:55:30 +00:00
|
|
|
|
|
|
|
self->sink_proxypad =
|
|
|
|
GST_PAD_CAST (gst_proxy_pad_get_internal (GST_PROXY_PAD (self->sinkpad)));
|
|
|
|
|
|
|
|
gst_element_add_pad (GST_ELEMENT_CAST (self), self->sinkpad);
|
|
|
|
gst_object_unref (templ);
|
|
|
|
|
|
|
|
templ = gst_static_pad_template_get (&srctemplate);
|
|
|
|
self->srcpad = gst_ghost_pad_new_no_target_from_template ("src", templ);
|
2011-11-15 15:30:38 +00:00
|
|
|
gst_pad_set_query_function (self->srcpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_play_sink_convert_bin_query));
|
2011-10-17 16:55:30 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT_CAST (self), self->srcpad);
|
|
|
|
gst_object_unref (templ);
|
2011-10-17 21:05:30 +00:00
|
|
|
|
|
|
|
gst_play_sink_convert_bin_add_identity (self);
|
2011-10-17 16:55:30 +00:00
|
|
|
}
|