Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | From 83bed90c306ed3185d48febf6441177d638f7341 Mon Sep 17 00:00:00 2001 |
| 2 | From: Song Bing <b06498@freescale.com> |
| 3 | Date: Wed, 24 Dec 2014 10:13:51 +0800 |
| 4 | Subject: [PATCH] inputselector: sticky events haven't send out when active |
| 5 | track reach EOS |
| 6 | |
| 7 | EOS event hasn't been send to down-element. The resolution is block EOS event |
| 8 | of inactive pad, send the event after the pad actived. |
| 9 | |
| 10 | https://bugzilla.gnome.org/show_bug.cgi?id=740949 |
| 11 | |
| 12 | Upstream-Status: Backport [1.5.1] |
| 13 | |
| 14 | Signed-off-by: Song Bing <b06498@freescale.com> |
| 15 | --- |
| 16 | plugins/elements/gstinputselector.c | 58 ++++++++++++++++++++++++++--------- |
| 17 | plugins/elements/gstinputselector.h | 1 + |
| 18 | 2 files changed, 45 insertions(+), 14 deletions(-) |
| 19 | |
| 20 | diff --git a/plugins/elements/gstinputselector.c b/plugins/elements/gstinputselector.c |
| 21 | index fb50802..4461f7c 100644 |
| 22 | --- a/plugins/elements/gstinputselector.c |
| 23 | +++ b/plugins/elements/gstinputselector.c |
| 24 | @@ -440,6 +440,17 @@ gst_selector_pad_iterate_linked_pads (GstPad * pad, GstObject * parent) |
| 25 | } |
| 26 | |
| 27 | static gboolean |
| 28 | +gst_input_selector_eos_wait (GstInputSelector * self, GstSelectorPad * pad) |
| 29 | +{ |
| 30 | + while (!self->eos && !self->flushing && !pad->flushing) { |
| 31 | + /* we can be unlocked here when we are shutting down (flushing) or when we |
| 32 | + * get unblocked */ |
| 33 | + GST_INPUT_SELECTOR_WAIT (self); |
| 34 | + } |
| 35 | + return self->flushing; |
| 36 | +} |
| 37 | + |
| 38 | +static gboolean |
| 39 | gst_selector_pad_event (GstPad * pad, GstObject * parent, GstEvent * event) |
| 40 | { |
| 41 | gboolean res = TRUE; |
| 42 | @@ -486,6 +497,7 @@ gst_selector_pad_event (GstPad * pad, GstObject * parent, GstEvent * event) |
| 43 | case GST_EVENT_FLUSH_START: |
| 44 | /* Unblock the pad if it's waiting */ |
| 45 | selpad->flushing = TRUE; |
| 46 | + sel->eos = FALSE; |
| 47 | GST_INPUT_SELECTOR_BROADCAST (sel); |
| 48 | break; |
| 49 | case GST_EVENT_FLUSH_STOP: |
| 50 | @@ -523,21 +535,12 @@ gst_selector_pad_event (GstPad * pad, GstObject * parent, GstEvent * event) |
| 51 | case GST_EVENT_EOS: |
| 52 | selpad->eos = TRUE; |
| 53 | |
| 54 | - if (forward) { |
| 55 | - selpad->eos_sent = TRUE; |
| 56 | - } else { |
| 57 | - GstSelectorPad *active_selpad; |
| 58 | - |
| 59 | - /* If the active sinkpad is in EOS state but EOS |
| 60 | - * was not sent downstream this means that the pad |
| 61 | - * got EOS before it was set as active pad and that |
| 62 | - * the previously active pad got EOS after it was |
| 63 | - * active |
| 64 | - */ |
| 65 | - active_selpad = GST_SELECTOR_PAD (active_sinkpad); |
| 66 | - forward = (active_selpad->eos && !active_selpad->eos_sent); |
| 67 | - active_selpad->eos_sent = TRUE; |
| 68 | + if (!forward) { |
| 69 | + /* blocked until active the sind pad or flush */ |
| 70 | + gst_input_selector_eos_wait (sel, selpad); |
| 71 | + forward = TRUE; |
| 72 | } |
| 73 | + selpad->eos_sent = TRUE; |
| 74 | GST_DEBUG_OBJECT (pad, "received EOS"); |
| 75 | break; |
| 76 | case GST_EVENT_GAP:{ |
| 77 | @@ -676,6 +679,12 @@ gst_input_selector_wait_running_time (GstInputSelector * sel, |
| 78 | gst_input_selector_activate_sinkpad (sel, GST_PAD_CAST (selpad)); |
| 79 | active_selpad = GST_SELECTOR_PAD_CAST (active_sinkpad); |
| 80 | |
| 81 | + if (sel->eos) { |
| 82 | + GST_DEBUG_OBJECT (sel, "Not waiting because inputselector reach EOS."); |
| 83 | + GST_INPUT_SELECTOR_UNLOCK (sel); |
| 84 | + return FALSE; |
| 85 | + } |
| 86 | + |
| 87 | if (seg->format != GST_FORMAT_TIME) { |
| 88 | GST_DEBUG_OBJECT (selpad, |
| 89 | "Not waiting because we don't have a TIME segment"); |
| 90 | @@ -971,6 +980,12 @@ gst_selector_pad_chain (GstPad * pad, GstObject * parent, GstBuffer * buf) |
| 91 | GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf))); |
| 92 | |
| 93 | GST_INPUT_SELECTOR_LOCK (sel); |
| 94 | + if (sel->eos) { |
| 95 | + GST_DEBUG_OBJECT (pad, "inputselector eos."); |
| 96 | + GST_INPUT_SELECTOR_UNLOCK (sel); |
| 97 | + goto eos; |
| 98 | + } |
| 99 | + |
| 100 | /* wait or check for flushing */ |
| 101 | if (gst_input_selector_wait (sel, selpad)) { |
| 102 | GST_INPUT_SELECTOR_UNLOCK (sel); |
| 103 | @@ -1151,6 +1166,13 @@ flushing: |
| 104 | res = GST_FLOW_FLUSHING; |
| 105 | goto done; |
| 106 | } |
| 107 | +eos: |
| 108 | + { |
| 109 | + GST_DEBUG_OBJECT (pad, "We are eos, discard buffer %p", buf); |
| 110 | + gst_buffer_unref (buf); |
| 111 | + res = GST_FLOW_EOS; |
| 112 | + goto done; |
| 113 | + } |
| 114 | } |
| 115 | |
| 116 | static void gst_input_selector_dispose (GObject * object); |
| 117 | @@ -1309,6 +1331,7 @@ gst_input_selector_init (GstInputSelector * sel) |
| 118 | g_mutex_init (&sel->lock); |
| 119 | g_cond_init (&sel->cond); |
| 120 | sel->blocked = FALSE; |
| 121 | + sel->eos = FALSE; |
| 122 | |
| 123 | /* lets give a change for downstream to do something on |
| 124 | * active-pad change before we start pushing new buffers */ |
| 125 | @@ -1377,6 +1400,11 @@ gst_input_selector_set_active_pad (GstInputSelector * self, GstPad * pad) |
| 126 | GST_DEBUG_OBJECT (self, "New active pad is %" GST_PTR_FORMAT, |
| 127 | self->active_sinkpad); |
| 128 | |
| 129 | + if (old != new && new->eos && !new->eos_sent) { |
| 130 | + self->eos = TRUE; |
| 131 | + GST_INPUT_SELECTOR_BROADCAST (self); |
| 132 | + } |
| 133 | + |
| 134 | return TRUE; |
| 135 | } |
| 136 | |
| 137 | @@ -1771,6 +1799,7 @@ gst_input_selector_change_state (GstElement * element, |
| 138 | switch (transition) { |
| 139 | case GST_STATE_CHANGE_READY_TO_PAUSED: |
| 140 | GST_INPUT_SELECTOR_LOCK (self); |
| 141 | + self->eos = FALSE; |
| 142 | self->blocked = FALSE; |
| 143 | self->flushing = FALSE; |
| 144 | GST_INPUT_SELECTOR_UNLOCK (self); |
| 145 | @@ -1779,6 +1808,7 @@ gst_input_selector_change_state (GstElement * element, |
| 146 | /* first unlock before we call the parent state change function, which |
| 147 | * tries to acquire the stream lock when going to ready. */ |
| 148 | GST_INPUT_SELECTOR_LOCK (self); |
| 149 | + self->eos = TRUE; |
| 150 | self->blocked = FALSE; |
| 151 | self->flushing = TRUE; |
| 152 | GST_INPUT_SELECTOR_BROADCAST (self); |
| 153 | diff --git a/plugins/elements/gstinputselector.h b/plugins/elements/gstinputselector.h |
| 154 | index 96c680f..9bf924f 100644 |
| 155 | --- a/plugins/elements/gstinputselector.h |
| 156 | +++ b/plugins/elements/gstinputselector.h |
| 157 | @@ -77,6 +77,7 @@ struct _GstInputSelector { |
| 158 | GMutex lock; |
| 159 | GCond cond; |
| 160 | gboolean blocked; |
| 161 | + gboolean eos; |
| 162 | gboolean flushing; |
| 163 | }; |
| 164 | |
| 165 | -- |
| 166 | 1.7.9.5 |
| 167 | |