summaryrefslogtreecommitdiffstats
path: root/gst/selector/gstoutputselector.c
diff options
context:
space:
mode:
Diffstat (limited to 'gst/selector/gstoutputselector.c')
-rw-r--r--gst/selector/gstoutputselector.c51
1 files changed, 33 insertions, 18 deletions
diff --git a/gst/selector/gstoutputselector.c b/gst/selector/gstoutputselector.c
index bf354a74..15c0a726 100644
--- a/gst/selector/gstoutputselector.c
+++ b/gst/selector/gstoutputselector.c
@@ -196,7 +196,7 @@ gst_output_selector_set_property (GObject * object, guint prop_id,
next_pad = g_value_get_object (value);
- GST_LOG_OBJECT (sel, "Activating pad %s:%s",
+ GST_INFO_OBJECT (sel, "Activating pad %s:%s",
GST_DEBUG_PAD_NAME (next_pad));
GST_OBJECT_LOCK (object);
@@ -262,11 +262,11 @@ gst_output_selector_buffer_alloc (GstPad * pad, guint64 offset, guint size,
GstPad *allocpad;
sel = GST_OUTPUT_SELECTOR (GST_PAD_PARENT (pad));
-
res = GST_FLOW_NOT_LINKED;
GST_OBJECT_LOCK (sel);
- if ((allocpad = sel->active_srcpad)) {
+ allocpad = sel->pending_srcpad ? sel->pending_srcpad : sel->active_srcpad;
+ if (allocpad) {
/* if we had a previous pad we used for allocating a buffer, continue using
* it. */
GST_DEBUG_OBJECT (sel, "using pad %s:%s for alloc",
@@ -278,9 +278,16 @@ gst_output_selector_buffer_alloc (GstPad * pad, guint64 offset, guint size,
gst_object_unref (allocpad);
GST_OBJECT_LOCK (sel);
+ } else {
+ /* fallback case, allocate a buffer of our own, add pad caps. */
+ GST_DEBUG_OBJECT (pad, "fallback buffer alloc");
+ *buf = NULL;
+ res = GST_FLOW_OK;
}
GST_OBJECT_UNLOCK (sel);
+ GST_DEBUG_OBJECT (sel, "buffer alloc finished: %s", gst_flow_get_name (res));
+
return res;
}
@@ -330,14 +337,24 @@ gst_output_selector_release_pad (GstElement * element, GstPad * pad)
static gboolean
gst_output_selector_switch (GstOutputSelector * osel)
{
- gboolean res = TRUE;
+ gboolean res = FALSE;
GstEvent *ev = NULL;
GstSegment *seg = NULL;
gint64 start = 0, position = 0;
+ /* Switch */
+ GST_OBJECT_LOCK (GST_OBJECT (osel));
GST_INFO ("switching to pad %" GST_PTR_FORMAT, osel->pending_srcpad);
-
if (gst_pad_is_linked (osel->pending_srcpad)) {
+ osel->active_srcpad = osel->pending_srcpad;
+ res = TRUE;
+ }
+ gst_object_unref (osel->pending_srcpad);
+ osel->pending_srcpad = NULL;
+ GST_OBJECT_UNLOCK (GST_OBJECT (osel));
+
+ /* Send NEWSEGMENT event and latest buffer if switching succeeded */
+ if (res) {
/* Send NEWSEGMENT to the pad we are going to switch to */
seg = &osel->segment;
/* If resending then mark newsegment start and position accordingly */
@@ -349,29 +366,22 @@ gst_output_selector_switch (GstOutputSelector * osel)
}
ev = gst_event_new_new_segment (TRUE, seg->rate,
seg->format, start, seg->stop, position);
- if (!gst_pad_push_event (osel->pending_srcpad, ev)) {
+ if (!gst_pad_push_event (osel->active_srcpad, ev)) {
GST_WARNING_OBJECT (osel,
"newsegment handling failed in %" GST_PTR_FORMAT,
- osel->pending_srcpad);
+ osel->active_srcpad);
}
/* Resend latest buffer to newly switched pad */
if (osel->resend_latest && osel->latest_buffer) {
GST_INFO ("resending latest buffer");
- gst_pad_push (osel->pending_srcpad, osel->latest_buffer);
+ gst_pad_push (osel->active_srcpad, osel->latest_buffer);
osel->latest_buffer = NULL;
}
-
- /* Switch */
- osel->active_srcpad = osel->pending_srcpad;
} else {
GST_WARNING_OBJECT (osel, "switch failed, pad not linked");
- res = FALSE;
}
- gst_object_unref (osel->pending_srcpad);
- osel->pending_srcpad = NULL;
-
return res;
}
@@ -389,10 +399,15 @@ gst_output_selector_chain (GstPad * pad, GstBuffer * buf)
gst_output_selector_switch (osel);
}
- /* Keep reference to latest buffer to resend it after switch */
- if (osel->latest_buffer)
+ if (osel->latest_buffer) {
gst_buffer_unref (osel->latest_buffer);
- osel->latest_buffer = gst_buffer_ref (buf);
+ osel->latest_buffer = NULL;
+ }
+
+ if (osel->resend_latest) {
+ /* Keep reference to latest buffer to resend it after switch */
+ osel->latest_buffer = gst_buffer_ref (buf);
+ }
/* Keep track of last stop and use it in NEWSEGMENT start after
switching to a new src pad */