diff --git a/girs/GstSdp-1.0.gir b/girs/GstSdp-1.0.gir
index 6a519fd06d..414877e3a9 100644
--- a/girs/GstSdp-1.0.gir
+++ b/girs/GstSdp-1.0.gir
@@ -3374,6 +3374,25 @@ from a #GstSDPMessage.
+
+ Remove the media at @idx from the array of medias in @msg if found.
+
+
+ #GST_SDP_OK when the specified media is found at @idx and removed,
+#GST_SDP_EINVAL otherwise.
+
+
+
+
+ a #GstSDPMessage
+
+
+
+ the media index
+
+
+
+
Remove the phone number in @msg at index @idx.
diff --git a/subprojects/gst-plugins-base/gst-libs/gst/sdp/gstsdpmessage.c b/subprojects/gst-plugins-base/gst-libs/gst/sdp/gstsdpmessage.c
index 6f5f7f8133..2e17e7c596 100644
--- a/subprojects/gst-plugins-base/gst-libs/gst/sdp/gstsdpmessage.c
+++ b/subprojects/gst-plugins-base/gst-libs/gst/sdp/gstsdpmessage.c
@@ -1790,6 +1790,33 @@ gst_sdp_message_add_media (GstSDPMessage * msg, GstSDPMedia * media)
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 */
/**
diff --git a/subprojects/gst-plugins-base/gst-libs/gst/sdp/gstsdpmessage.h b/subprojects/gst-plugins-base/gst-libs/gst/sdp/gstsdpmessage.h
index 378f14938b..3504205c66 100644
--- a/subprojects/gst-plugins-base/gst-libs/gst/sdp/gstsdpmessage.h
+++ b/subprojects/gst-plugins-base/gst-libs/gst/sdp/gstsdpmessage.h
@@ -572,6 +572,9 @@ const GstSDPMedia* gst_sdp_message_get_media (const GstSDPMessage
GST_SDP_API
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
GstSDPResult gst_sdp_message_dump (const GstSDPMessage *msg);
diff --git a/subprojects/gst-plugins-base/tests/check/libs/sdp.c b/subprojects/gst-plugins-base/tests/check/libs/sdp.c
index 11b671d3db..33be83936d 100644
--- a/subprojects/gst-plugins-base/tests/check/libs/sdp.c
+++ b/subprojects/gst-plugins-base/tests/check/libs/sdp.c
@@ -933,6 +933,56 @@ GST_START_TEST (media_from_caps_with_source_filters)
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
/*
* 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_with_params);
tcase_add_test (tc_chain, media_from_caps_with_source_filters);
+ tcase_add_test (tc_chain, media_remove);
return s;
}