rtphdrext: allow the extension to inspect payloader's sink caps

Some header extensions may need to read information from the payloader's
sink caps. Introduce gst_rtp_header_extension_update_from_sinkcaps ()
that passes the caps to the extension, which can then use it to update
its internal state.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/merge_requests/1011>
This commit is contained in:
Jakub Adam 2021-01-12 22:11:46 +01:00
parent 9759810d82
commit 899c69abad
3 changed files with 57 additions and 1 deletions

View file

@ -1475,6 +1475,25 @@ gst_rtp_base_payload_negotiate (GstRTPBasePayload * payload)
payload->priv->header_exts);
g_ptr_array_foreach (to_add, (GFunc) add_item_to,
payload->priv->header_exts);
/* let extensions update their internal state from sinkcaps */
if (payload->priv->sinkcaps) {
gint i;
for (i = 0; i < payload->priv->header_exts->len; i++) {
GstRTPHeaderExtension *ext;
ext = g_ptr_array_index (payload->priv->header_exts, i);
if (!gst_rtp_header_extension_set_non_rtp_sink_caps (ext,
payload->priv->sinkcaps)) {
GST_WARNING_OBJECT (payload,
"Failed to update rtp header extension (%s) from sink caps",
GST_OBJECT_NAME (ext));
res = FALSE;
GST_OBJECT_UNLOCK (payload);
goto ext_out;
}
}
}
/* add extension information to srccaps */
g_ptr_array_foreach (payload->priv->header_exts,
(GFunc) add_header_ext_to_caps, srccaps);

View file

@ -394,6 +394,36 @@ gst_rtp_header_extension_set_attributes_from_caps (GstRTPHeaderExtension * ext,
return klass->set_attributes_from_caps (ext, caps);
}
/**
* gst_rtp_header_extension_set_non_rtp_sink_caps:
* @ext: a #GstRTPHeaderExtension
* @caps: sink #GstCaps
*
* Passes RTP payloader's sink (i.e. not payloaded) @caps to the header
* extension.
*
* Returns: Whether @caps could be read successfully
*
* Since: 1.20
*/
gboolean
gst_rtp_header_extension_set_non_rtp_sink_caps (GstRTPHeaderExtension * ext,
const GstCaps * caps)
{
GstRTPHeaderExtensionClass *klass;
g_return_val_if_fail (GST_IS_CAPS (caps), FALSE);
g_return_val_if_fail (GST_IS_RTP_HEADER_EXTENSION (ext), FALSE);
g_return_val_if_fail (ext->ext_id <= MAX_RTP_EXT_ID, FALSE);
klass = GST_RTP_HEADER_EXTENSION_GET_CLASS (ext);
if (klass->set_non_rtp_sink_caps) {
return klass->set_non_rtp_sink_caps (ext, caps);
}
return TRUE;
}
/**
* gst_rtp_header_extension_set_caps_from_attributes:
* @ext: a #GstRTPHeaderExtension

View file

@ -138,7 +138,9 @@ struct _GstRTPHeaderExtension
* information is provided to help writing extensions in particular cases.
* @read: read from a rtp payloaded buffer and extract the extension
* information, optionally adding some meta onto the output buffer.
* @set_attributes_from_caps: read the caps information to set the necesary
* @set_non_rtp_sink_caps: read any information from sink caps that the header
* extension needs for its function.
* @set_attributes_from_caps: read the caps information to set the necessary
* attributes that may be signaled e.g. with an SDP.
* @set_caps_from_attributes: write the necessary caps field/s for the configured
* attributes e.g. as signalled with SDP.
@ -169,6 +171,8 @@ struct _GstRTPHeaderExtensionClass
const guint8 * data,
gsize size,
GstBuffer * buffer);
gboolean (*set_non_rtp_sink_caps) (GstRTPHeaderExtension * ext,
const GstCaps * caps);
gboolean (*set_attributes_from_caps) (GstRTPHeaderExtension * ext,
const GstCaps * caps);
gboolean (*set_caps_from_attributes) (GstRTPHeaderExtension * ext,
@ -217,6 +221,9 @@ gboolean gst_rtp_header_extension_read (GstRTPHeaderExt
gsize size,
GstBuffer * buffer);
GST_RTP_API
gboolean gst_rtp_header_extension_set_non_rtp_sink_caps (GstRTPHeaderExtension * ext,
const GstCaps * caps);
GST_RTP_API
gboolean gst_rtp_header_extension_set_caps_from_attributes (GstRTPHeaderExtension * ext,
GstCaps * caps);
GST_RTP_API