rtpgstdepay: Only store the current caps and drop old caps immediately

Otherwise it can happen that we already collected 7 caps, miss the 8th
caps packet (packet loss) and then re-use the 1st caps for the following
buffers instead of the 8th caps which will likely cause errors further
downstream unless both caps are accidentally the same.

Keeping old caps around does not seem to have any value other than
potentially causing errors. We would always receive new caps whenever
they change (even if they were previous ones) and it's very unlikely
that they happen to be exactly the same as the previous ones.

Also after having received new caps or a buffer with a next caps
version, no buffers with old caps version will arrive anymore.
This commit is contained in:
Sebastian Dröge 2019-06-12 14:57:24 +03:00 committed by Sebastian Dröge
parent 53b3f2ddbb
commit 44a697deba
2 changed files with 12 additions and 34 deletions

View file

@ -116,31 +116,13 @@ gst_rtp_gst_depay_finalize (GObject * object)
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static gboolean
store_cache (GstRtpGSTDepay * rtpgstdepay, guint CV, GstCaps * caps)
{
gboolean changed = FALSE;
if (caps && rtpgstdepay->CV_cache[CV])
changed = !gst_caps_is_strictly_equal (caps, rtpgstdepay->CV_cache[CV]);
if (rtpgstdepay->CV_cache[CV])
gst_caps_unref (rtpgstdepay->CV_cache[CV]);
rtpgstdepay->CV_cache[CV] = caps;
return changed;
}
static void
gst_rtp_gst_depay_reset (GstRtpGSTDepay * rtpgstdepay, gboolean full)
{
guint i;
gst_adapter_clear (rtpgstdepay->adapter);
if (full) {
rtpgstdepay->current_CV = 0;
for (i = 0; i < 8; i++)
store_cache (rtpgstdepay, i, NULL);
gst_caps_replace (&rtpgstdepay->current_caps, NULL);
g_free (rtpgstdepay->stream_id);
rtpgstdepay->stream_id = NULL;
if (rtpgstdepay->tags)
@ -189,14 +171,14 @@ gst_rtp_gst_depay_setcaps (GstRTPBaseDepayload * depayload, GstCaps * caps)
}
/* store in cache */
rtpgstdepay->current_CV = CV;
gst_caps_ref (outcaps);
store_cache (rtpgstdepay, CV, outcaps);
gst_caps_replace (&rtpgstdepay->current_caps, outcaps);
res = gst_pad_set_caps (depayload->srcpad, outcaps);
gst_caps_unref (outcaps);
} else {
GST_WARNING_OBJECT (depayload, "no caps given");
rtpgstdepay->current_CV = -1;
gst_caps_replace (&rtpgstdepay->current_caps, NULL);
res = TRUE;
}
@ -471,8 +453,12 @@ gst_rtp_gst_depay_process (GstRTPBaseDepayload * depayload, GstRTPBuffer * rtp)
GST_DEBUG_OBJECT (rtpgstdepay,
"inline caps %u, length %u, %" GST_PTR_FORMAT, CV, size, outcaps);
if (store_cache (rtpgstdepay, CV, outcaps))
if (!rtpgstdepay->current_caps
|| !gst_caps_is_strictly_equal (rtpgstdepay->current_caps, outcaps))
gst_pad_set_caps (depayload->srcpad, outcaps);
gst_caps_replace (&rtpgstdepay->current_caps, outcaps);
gst_caps_unref (outcaps);
rtpgstdepay->current_CV = CV;
/* skip caps */
offset += size;
@ -512,17 +498,9 @@ gst_rtp_gst_depay_process (GstRTPBaseDepayload * depayload, GstRTPBuffer * rtp)
/* see what caps we need */
if (CV != rtpgstdepay->current_CV) {
/* we need to switch caps, check if we have the caps */
if ((outcaps = rtpgstdepay->CV_cache[CV]) == NULL)
goto missing_caps;
GST_DEBUG_OBJECT (rtpgstdepay,
"need caps switch from %u to %u, %" GST_PTR_FORMAT,
rtpgstdepay->current_CV, CV, outcaps);
/* and set caps */
if (gst_pad_set_caps (depayload->srcpad, outcaps))
rtpgstdepay->current_CV = CV;
/* we need to switch caps but didn't receive the new caps yet */
gst_caps_replace (&rtpgstdepay->current_caps, NULL);
goto missing_caps;
}
if (payload[0] & 0x8)

View file

@ -46,7 +46,7 @@ struct _GstRtpGSTDepay
GstAdapter *adapter;
guint current_CV;
GstCaps *CV_cache[8];
GstCaps *current_caps;
GstTagList *tags;
gchar *stream_id;