mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-06-07 16:08:51 +00:00
rtphdrext: Put simple caps generation as the base class default
Instead of having a helper function that gets called by almost every subclass, just let the base class set the caps fields automatically. Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/906>
This commit is contained in:
parent
ecf84cdd4e
commit
498740fe57
5 changed files with 42 additions and 80 deletions
|
@ -399,21 +399,55 @@ gst_rtp_header_extension_set_attributes_from_caps (GstRTPHeaderExtension * ext,
|
||||||
GstRTPHeaderExtensionClass *klass;
|
GstRTPHeaderExtensionClass *klass;
|
||||||
GstStructure *structure;
|
GstStructure *structure;
|
||||||
gchar *field_name;
|
gchar *field_name;
|
||||||
|
const GValue *val;
|
||||||
|
|
||||||
g_return_val_if_fail (GST_IS_CAPS (caps), FALSE);
|
g_return_val_if_fail (GST_IS_CAPS (caps), FALSE);
|
||||||
g_return_val_if_fail (gst_caps_is_fixed (caps), FALSE);
|
g_return_val_if_fail (gst_caps_is_fixed (caps), FALSE);
|
||||||
g_return_val_if_fail (GST_IS_RTP_HEADER_EXTENSION (ext), FALSE);
|
g_return_val_if_fail (GST_IS_RTP_HEADER_EXTENSION (ext), FALSE);
|
||||||
g_return_val_if_fail (priv->ext_id <= MAX_RTP_EXT_ID, FALSE);
|
g_return_val_if_fail (priv->ext_id <= MAX_RTP_EXT_ID, FALSE);
|
||||||
klass = GST_RTP_HEADER_EXTENSION_GET_CLASS (ext);
|
klass = GST_RTP_HEADER_EXTENSION_GET_CLASS (ext);
|
||||||
g_return_val_if_fail (klass->set_attributes_from_caps != NULL, FALSE);
|
|
||||||
|
|
||||||
structure = gst_caps_get_structure (caps, 0);
|
structure = gst_caps_get_structure (caps, 0);
|
||||||
g_return_val_if_fail (structure != NULL, FALSE);
|
g_return_val_if_fail (structure != NULL, FALSE);
|
||||||
field_name = g_strdup_printf ("extmap-%u", priv->ext_id);
|
field_name = g_strdup_printf ("extmap-%u", priv->ext_id);
|
||||||
g_return_val_if_fail (gst_structure_has_field (structure, field_name), FALSE);
|
g_return_val_if_fail (gst_structure_has_field (structure, field_name), FALSE);
|
||||||
|
|
||||||
|
val = gst_structure_get_value (structure, field_name);
|
||||||
g_free (field_name);
|
g_free (field_name);
|
||||||
|
|
||||||
return klass->set_attributes_from_caps (ext, caps);
|
if (G_VALUE_HOLDS_STRING (val)) {
|
||||||
|
const gchar *ext_uri = g_value_get_string (val);
|
||||||
|
|
||||||
|
if (g_strcmp0 (ext_uri, gst_rtp_header_extension_get_uri (ext)) != 0) {
|
||||||
|
/* incompatible extension uri for this instance */
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
} else if (GST_VALUE_HOLDS_ARRAY (val)
|
||||||
|
&& gst_value_array_get_size (val) == 3) {
|
||||||
|
const GValue *inner_val;
|
||||||
|
|
||||||
|
inner_val = gst_value_array_get_value (val, 1);
|
||||||
|
if (!G_VALUE_HOLDS_STRING (inner_val))
|
||||||
|
goto error;
|
||||||
|
if (g_strcmp0 (g_value_get_string (inner_val),
|
||||||
|
gst_rtp_header_extension_get_uri (ext)) != 0)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
inner_val = gst_value_array_get_value (val, 2);
|
||||||
|
if (!G_VALUE_HOLDS_STRING (inner_val))
|
||||||
|
goto error;
|
||||||
|
} else {
|
||||||
|
/* unknown caps format */
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (klass->set_attributes_from_caps)
|
||||||
|
return klass->set_attributes_from_caps (ext, caps);
|
||||||
|
else
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
error:
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -586,42 +620,6 @@ gst_rtp_header_extension_get_sdp_caps_field_name (GstRTPHeaderExtension * ext)
|
||||||
return g_strdup_printf ("extmap-%u", priv->ext_id);
|
return g_strdup_printf ("extmap-%u", priv->ext_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* gst_rtp_header_extension_set_attributes_from_caps_simple_sdp:
|
|
||||||
* @ext: the #GstRTPHeaderExtension
|
|
||||||
* @caps: #GstCaps to read attributes from
|
|
||||||
*
|
|
||||||
* Helper implementation for GstRTPExtensionClass::set_attributes_from_caps
|
|
||||||
* that retrieves the configured extension id and checks that the
|
|
||||||
* corresponding field in the sdp caps is configured for this extension uri.
|
|
||||||
* Requires that the extension does not have any attributes or direction
|
|
||||||
* advertised in the caps.
|
|
||||||
*
|
|
||||||
* Returns: whether the attributes in the @caps could be set on @ext successfully
|
|
||||||
*
|
|
||||||
* Since: 1.20
|
|
||||||
*/
|
|
||||||
gboolean
|
|
||||||
gst_rtp_header_extension_set_attributes_from_caps_simple_sdp
|
|
||||||
(GstRTPHeaderExtension * ext, const GstCaps * caps) {
|
|
||||||
gchar *field_name = gst_rtp_header_extension_get_sdp_caps_field_name (ext);
|
|
||||||
GstStructure *s = gst_caps_get_structure (caps, 0);
|
|
||||||
const gchar *ext_uri;
|
|
||||||
|
|
||||||
if (!(ext_uri = gst_structure_get_string (s, field_name)))
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
if (g_strcmp0 (ext_uri, gst_rtp_header_extension_get_uri (ext)) != 0)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
g_free (field_name);
|
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
error:
|
|
||||||
g_free (field_name);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gst_rtp_header_extension_set_caps_from_attributes_simple_sdp:
|
* gst_rtp_header_extension_set_caps_from_attributes_simple_sdp:
|
||||||
* @ext: the #GstRTPHeaderExtension
|
* @ext: the #GstRTPHeaderExtension
|
||||||
|
|
|
@ -248,8 +248,6 @@ GstRTPHeaderExtension * gst_rtp_header_extension_create_from_uri (const gchar *
|
||||||
GST_RTP_API
|
GST_RTP_API
|
||||||
gchar * gst_rtp_header_extension_get_sdp_caps_field_name (GstRTPHeaderExtension * ext);
|
gchar * gst_rtp_header_extension_get_sdp_caps_field_name (GstRTPHeaderExtension * ext);
|
||||||
GST_RTP_API
|
GST_RTP_API
|
||||||
gboolean gst_rtp_header_extension_set_attributes_from_caps_simple_sdp (GstRTPHeaderExtension * ext, const GstCaps *caps);
|
|
||||||
GST_RTP_API
|
|
||||||
gboolean gst_rtp_header_extension_set_caps_from_attributes_simple_sdp (GstRTPHeaderExtension * ext, GstCaps *caps);
|
gboolean gst_rtp_header_extension_set_caps_from_attributes_simple_sdp (GstRTPHeaderExtension * ext, GstCaps *caps);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
|
@ -451,8 +451,6 @@ static void
|
||||||
gst_rtp_header_extension_colorspace_set_non_rtp_sink_caps;
|
gst_rtp_header_extension_colorspace_set_non_rtp_sink_caps;
|
||||||
rtp_hdr_class->update_non_rtp_src_caps =
|
rtp_hdr_class->update_non_rtp_src_caps =
|
||||||
gst_rtp_header_extension_colorspace_update_non_rtp_src_caps;
|
gst_rtp_header_extension_colorspace_update_non_rtp_src_caps;
|
||||||
rtp_hdr_class->set_attributes_from_caps =
|
|
||||||
gst_rtp_header_extension_set_attributes_from_caps_simple_sdp;
|
|
||||||
rtp_hdr_class->set_caps_from_attributes =
|
rtp_hdr_class->set_caps_from_attributes =
|
||||||
gst_rtp_header_extension_set_caps_from_attributes_simple_sdp;
|
gst_rtp_header_extension_set_caps_from_attributes_simple_sdp;
|
||||||
|
|
||||||
|
|
|
@ -119,36 +119,14 @@ gst_rtp_header_extension_rfc6464_set_attributes_from_caps (GstRTPHeaderExtension
|
||||||
{
|
{
|
||||||
gchar *field_name = gst_rtp_header_extension_get_sdp_caps_field_name (ext);
|
gchar *field_name = gst_rtp_header_extension_get_sdp_caps_field_name (ext);
|
||||||
GstStructure *s = gst_caps_get_structure (caps, 0);
|
GstStructure *s = gst_caps_get_structure (caps, 0);
|
||||||
const gchar *ext_uri;
|
|
||||||
const GValue *arr;
|
const GValue *arr;
|
||||||
|
|
||||||
if (!field_name)
|
arr = gst_structure_get_value (s, field_name);
|
||||||
return FALSE;
|
g_free (field_name);
|
||||||
|
|
||||||
if ((ext_uri = gst_structure_get_string (s, field_name))) {
|
if (GST_VALUE_HOLDS_ARRAY (arr)) {
|
||||||
if (g_strcmp0 (ext_uri, gst_rtp_header_extension_get_uri (ext)) != 0) {
|
const GValue *val = gst_value_array_get_value (arr, 2);
|
||||||
/* incompatible extension uri for this instance */
|
const gchar *vad_attr = g_value_get_string (val);
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
set_vad (ext, DEFAULT_VAD);
|
|
||||||
} else if ((arr = gst_structure_get_value (s, field_name))
|
|
||||||
&& GST_VALUE_HOLDS_ARRAY (arr)
|
|
||||||
&& gst_value_array_get_size (arr) == 3) {
|
|
||||||
const GValue *val;
|
|
||||||
const gchar *vad_attr;
|
|
||||||
|
|
||||||
val = gst_value_array_get_value (arr, 1);
|
|
||||||
if (!G_VALUE_HOLDS_STRING (val))
|
|
||||||
goto error;
|
|
||||||
if (g_strcmp0 (g_value_get_string (val),
|
|
||||||
gst_rtp_header_extension_get_uri (ext)) != 0)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
val = gst_value_array_get_value (arr, 2);
|
|
||||||
if (!G_VALUE_HOLDS_STRING (val))
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
vad_attr = g_value_get_string (val);
|
|
||||||
|
|
||||||
if (g_str_equal (vad_attr, "vad=on"))
|
if (g_str_equal (vad_attr, "vad=on"))
|
||||||
set_vad (ext, TRUE);
|
set_vad (ext, TRUE);
|
||||||
|
@ -156,19 +134,11 @@ gst_rtp_header_extension_rfc6464_set_attributes_from_caps (GstRTPHeaderExtension
|
||||||
set_vad (ext, FALSE);
|
set_vad (ext, FALSE);
|
||||||
else {
|
else {
|
||||||
GST_WARNING_OBJECT (ext, "Invalid attribute: %s", vad_attr);
|
GST_WARNING_OBJECT (ext, "Invalid attribute: %s", vad_attr);
|
||||||
goto error;
|
return FALSE;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
/* unknown caps format */
|
|
||||||
goto error;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free (field_name);
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
error:
|
|
||||||
g_free (field_name);
|
|
||||||
return FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
|
|
|
@ -104,8 +104,6 @@ gst_rtp_header_extension_twcc_class_init (GstRTPHeaderExtensionTWCCClass *
|
||||||
rtp_hdr_class->get_max_size = gst_rtp_header_extension_twcc_get_max_size;
|
rtp_hdr_class->get_max_size = gst_rtp_header_extension_twcc_get_max_size;
|
||||||
rtp_hdr_class->write = gst_rtp_header_extension_twcc_write;
|
rtp_hdr_class->write = gst_rtp_header_extension_twcc_write;
|
||||||
rtp_hdr_class->read = gst_rtp_header_extension_twcc_read;
|
rtp_hdr_class->read = gst_rtp_header_extension_twcc_read;
|
||||||
rtp_hdr_class->set_attributes_from_caps =
|
|
||||||
gst_rtp_header_extension_set_attributes_from_caps_simple_sdp;
|
|
||||||
rtp_hdr_class->set_caps_from_attributes =
|
rtp_hdr_class->set_caps_from_attributes =
|
||||||
gst_rtp_header_extension_set_caps_from_attributes_simple_sdp;
|
gst_rtp_header_extension_set_caps_from_attributes_simple_sdp;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue