From a03db32bbe45059df5dbb130a2b52cc5514e09ed Mon Sep 17 00:00:00 2001 From: Mathieu Duponchelle Date: Wed, 27 Apr 2022 02:08:00 +0200 Subject: [PATCH] rtpbasepayload: always store input buffer meta before negotiation The decision to store the input buffer depends on whether extensions are to be added to the output buffer, I assume as an optimization. This creates an issue for subclasses that call negotiate(), where header_exts is actually populated, from their handle_buffer() implementation: at chain time, no header extension has been negotiated yet, which means that we don't add extensions to the first batch of buffers that comes out. Keep track of whether negotiate has been called (this is different from the negotiated field) and always store the input buffer until then. This fixes the issue while largely preserving the optimization. Part-of: --- .../gst-libs/gst/rtp/gstrtpbasepayload.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/subprojects/gst-plugins-base/gst-libs/gst/rtp/gstrtpbasepayload.c b/subprojects/gst-plugins-base/gst-libs/gst/rtp/gstrtpbasepayload.c index 2c5728e711..f7cd559315 100644 --- a/subprojects/gst-plugins-base/gst-libs/gst/rtp/gstrtpbasepayload.c +++ b/subprojects/gst-plugins-base/gst-libs/gst/rtp/gstrtpbasepayload.c @@ -63,6 +63,13 @@ struct _GstRTPBasePayloadPrivate gboolean negotiated; + /* We need to know whether negotiate was called in order to decide + * whether we should store the input buffer as input meta in case + * negotiate() gets called from the subclass' handle_buffer() implementation, + * as negotiate() is where we instantiate header extensions. + */ + gboolean negotiate_called; + gboolean delay_segment; GstEvent *pending_segment; @@ -840,7 +847,8 @@ gst_rtp_base_payload_chain (GstPad * pad, GstObject * parent, goto not_negotiated; if (rtpbasepayload->priv->source_info - || rtpbasepayload->priv->header_exts->len > 0) { + || rtpbasepayload->priv->header_exts->len > 0 + || !rtpbasepayload->priv->negotiate_called) { /* Save a copy of meta (instead of taking an extra reference before * handle_buffer) to make the meta available when allocating a output * buffer. */ @@ -1508,6 +1516,7 @@ gst_rtp_base_payload_negotiate (GstRTPBasePayload * payload) gst_caps_unref (templ); out: + payload->priv->negotiate_called = TRUE; if (!res) gst_pad_mark_reconfigure (GST_RTP_BASE_PAYLOAD_SRCPAD (payload)); @@ -2285,6 +2294,7 @@ gst_rtp_base_payload_change_state (GstElement * element, g_atomic_int_set (&rtpbasepayload->priv->notified_first_timestamp, 1); priv->base_offset = GST_BUFFER_OFFSET_NONE; priv->negotiated = FALSE; + priv->negotiate_called = FALSE; gst_caps_replace (&rtpbasepayload->priv->subclass_srccaps, NULL); gst_caps_replace (&rtpbasepayload->priv->sinkcaps, NULL); break;