sdp: Add API to remove media from a SDP message

Based on initial patch by Stefano Buora.
https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/merge_requests/579

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4670>
This commit is contained in:
Philippe Normand 2023-05-18 17:18:40 +01:00
parent 059965fe53
commit b2e121054d
4 changed files with 100 additions and 0 deletions

View file

@ -3374,6 +3374,25 @@ from a #GstSDPMessage.</doc>
</parameter> </parameter>
</parameters> </parameters>
</method> </method>
<method name="remove_media" c:identifier="gst_sdp_message_remove_media" version="1.24">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-base/gst-libs/gst/sdp/gstsdpmessage.c">Remove the media at @idx from the array of medias in @msg if found.</doc>
<source-position filename="../subprojects/gst-plugins-base/gst-libs/gst/sdp/gstsdpmessage.h"/>
<return-value transfer-ownership="none">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-base/gst-libs/gst/sdp/gstsdpmessage.c">#GST_SDP_OK when the specified media is found at @idx and removed,
#GST_SDP_EINVAL otherwise.</doc>
<type name="SDPResult" c:type="GstSDPResult"/>
</return-value>
<parameters>
<instance-parameter name="msg" transfer-ownership="none">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-base/gst-libs/gst/sdp/gstsdpmessage.c">a #GstSDPMessage</doc>
<type name="SDPMessage" c:type="GstSDPMessage*"/>
</instance-parameter>
<parameter name="idx" transfer-ownership="none">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-base/gst-libs/gst/sdp/gstsdpmessage.c">the media index</doc>
<type name="guint" c:type="guint"/>
</parameter>
</parameters>
</method>
<method name="remove_phone" c:identifier="gst_sdp_message_remove_phone" version="1.2"> <method name="remove_phone" c:identifier="gst_sdp_message_remove_phone" version="1.2">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-base/gst-libs/gst/sdp/gstsdpmessage.c">Remove the phone number in @msg at index @idx.</doc> <doc xml:space="preserve" filename="../subprojects/gst-plugins-base/gst-libs/gst/sdp/gstsdpmessage.c">Remove the phone number in @msg at index @idx.</doc>
<source-position filename="../subprojects/gst-plugins-base/gst-libs/gst/sdp/gstsdpmessage.h"/> <source-position filename="../subprojects/gst-plugins-base/gst-libs/gst/sdp/gstsdpmessage.h"/>

View file

@ -1790,6 +1790,33 @@ gst_sdp_message_add_media (GstSDPMessage * msg, GstSDPMedia * media)
return GST_SDP_OK; return GST_SDP_OK;
} }
/**
* gst_sdp_message_remove_media:
* @msg: a #GstSDPMessage
* @idx: the media index
*
* Remove the media at @idx from the array of medias in @msg if found.
*
* Returns: #GST_SDP_OK when the specified media is found at @idx and removed,
* #GST_SDP_EINVAL otherwise.
*
* Since: 1.24
*/
GstSDPResult
gst_sdp_message_remove_media (GstSDPMessage * msg, guint idx)
{
GstSDPMedia *media = NULL;
g_return_val_if_fail (msg != NULL, GST_SDP_EINVAL);
g_return_val_if_fail (idx <= gst_sdp_message_medias_len (msg),
GST_SDP_EINVAL);
media = &g_array_index (msg->medias, GstSDPMedia, idx);
gst_sdp_media_uninit (media);
g_array_remove_index (msg->medias, idx);
return GST_SDP_OK;
}
/* media access */ /* media access */
/** /**

View file

@ -572,6 +572,9 @@ const GstSDPMedia* gst_sdp_message_get_media (const GstSDPMessage
GST_SDP_API GST_SDP_API
GstSDPResult gst_sdp_message_add_media (GstSDPMessage *msg, GstSDPMedia *media); GstSDPResult gst_sdp_message_add_media (GstSDPMessage *msg, GstSDPMedia *media);
GST_SDP_API
GstSDPResult gst_sdp_message_remove_media (GstSDPMessage *msg, guint idx);
GST_SDP_API GST_SDP_API
GstSDPResult gst_sdp_message_dump (const GstSDPMessage *msg); GstSDPResult gst_sdp_message_dump (const GstSDPMessage *msg);

View file

@ -933,6 +933,56 @@ GST_START_TEST (media_from_caps_with_source_filters)
gst_sdp_message_free (message); gst_sdp_message_free (message);
} }
GST_END_TEST
GST_START_TEST (media_remove)
{
GstSDPResult ret = GST_SDP_OK;
GstSDPMessage *message;
const gchar *media;
GstSDPMedia *media_video, *media_audio;
const GstSDPMedia *result_audio;
GstCaps *caps_video, *caps_audio;
/* Add two medias, firts a video and then audio */
caps_video = gst_caps_from_string (caps_video_string1);
caps_audio = gst_caps_from_string (caps_audio_string);
gst_sdp_media_new (&media_video);
fail_unless (media_video != NULL);
gst_sdp_media_new (&media_audio);
fail_unless (media_audio != NULL);
ret = gst_sdp_media_set_media_from_caps (caps_video, media_video);
fail_unless (ret == GST_SDP_OK);
gst_caps_unref (caps_video);
ret = gst_sdp_media_set_media_from_caps (caps_audio, media_audio);
fail_unless (ret == GST_SDP_OK);
gst_caps_unref (caps_audio);
gst_sdp_message_new (&message);
gst_sdp_message_add_media (message, media_video);
gst_sdp_message_add_media (message, media_audio);
fail_unless_equals_int (gst_sdp_message_medias_len (message), 2);
/* Remove the first media (video) */
ret = gst_sdp_message_remove_media (message, 0);
fail_unless (ret == GST_SDP_OK);
/* Audio media is the only one left */
fail_unless_equals_int (gst_sdp_message_medias_len (message), 1);
result_audio = gst_sdp_message_get_media (message, 0);
fail_unless (result_audio != NULL);
media = gst_sdp_media_get_media (result_audio);
fail_unless_equals_string (media, "audio");
gst_sdp_media_free (media_audio);
gst_sdp_media_free (media_video);
gst_sdp_message_free (message);
}
GST_END_TEST GST_END_TEST
/* /*
* End of test cases * End of test cases
@ -963,6 +1013,7 @@ sdp_suite (void)
tcase_add_test (tc_chain, caps_multiple_rid_parse); tcase_add_test (tc_chain, caps_multiple_rid_parse);
tcase_add_test (tc_chain, caps_multiple_rid_parse_with_params); tcase_add_test (tc_chain, caps_multiple_rid_parse_with_params);
tcase_add_test (tc_chain, media_from_caps_with_source_filters); tcase_add_test (tc_chain, media_from_caps_with_source_filters);
tcase_add_test (tc_chain, media_remove);
return s; return s;
} }