GESTimelinePipeline: Also get static pads for static pads from encodebin.

This is for the cases where the provided GstStreamEncodingProfile has
a non-zero presence.
This commit is contained in:
Edward Hervey 2010-01-08 18:14:46 +01:00
parent e0dcea0bd5
commit b4e36fe853

View file

@ -165,6 +165,65 @@ done:
return ret;
}
/* Fetches a ocmpatible pad on the target element which isn't already
* linked */
static GstPad *
get_compatible_unlinked_pad (GstElement * element, GstPad * pad)
{
GstPad *res = NULL;
GstIterator *pads;
gboolean done = FALSE;
GstCaps *srccaps;
GST_DEBUG ("element : %s, pad %s:%s",
GST_ELEMENT_NAME (element), GST_DEBUG_PAD_NAME (pad));
if (GST_PAD_DIRECTION (pad) == GST_PAD_SRC)
pads = gst_element_iterate_sink_pads (element);
else
pads = gst_element_iterate_src_pads (element);
srccaps = gst_pad_get_caps (pad);
GST_DEBUG ("srccaps %" GST_PTR_FORMAT, srccaps);
while (!done) {
gpointer padptr;
switch (gst_iterator_next (pads, &padptr)) {
case GST_ITERATOR_OK:
{
GstPad *testpad = (GstPad *) padptr;
if (gst_pad_is_linked (testpad)) {
gst_object_unref (testpad);
} else {
GstCaps *sinkcaps = gst_pad_get_caps (testpad);
GST_DEBUG ("sinkccaps %" GST_PTR_FORMAT, sinkcaps);
if (gst_caps_can_intersect (srccaps, sinkcaps)) {
res = testpad;
done = TRUE;
} else
gst_object_unref (testpad);
gst_caps_unref (sinkcaps);
}
}
case GST_ITERATOR_DONE:
case GST_ITERATOR_ERROR:
done = TRUE;
break;
case GST_ITERATOR_RESYNC:
gst_iterator_resync (pads);
break;
}
}
gst_iterator_free (pads);
gst_caps_unref (srccaps);
return res;
}
static void
pad_added_cb (GstElement * timeline, GstPad * pad, GESTimelinePipeline * self)
{
@ -257,12 +316,17 @@ pad_added_cb (GstElement * timeline, GstPad * pad, GESTimelinePipeline * self)
if (self->mode & TIMELINE_MODE_RENDER) {
GST_DEBUG_OBJECT (self, "Connecting to encodebin");
sinkpad = NULL;
g_signal_emit_by_name (self->encodebin, "request-pad",
gst_pad_get_caps (pad), &sinkpad);
if (G_UNLIKELY (sinkpad == NULL)) {
GST_WARNING_OBJECT (self, "Couldn't get a pad from encodebin !");
goto error;
/* Check for unused static pads */
sinkpad = get_compatible_unlinked_pad (self->encodebin, pad);
if (sinkpad == NULL) {
/* If no compatible static pad is available, request a pad */
g_signal_emit_by_name (self->encodebin, "request-pad",
gst_pad_get_caps (pad), &sinkpad);
if (G_UNLIKELY (sinkpad == NULL)) {
GST_WARNING_OBJECT (self, "Couldn't get a pad from encodebin !");
goto error;
}
}
if (G_UNLIKELY (gst_pad_link (gst_element_get_request_pad (chain->tee,