webrtc: move webrtc_kind_from_caps() to utils

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2220>
This commit is contained in:
Matthew Waters 2021-05-06 17:06:44 +10:00 committed by GStreamer Marge Bot
parent 90edef103c
commit 1470660976
3 changed files with 33 additions and 29 deletions

View file

@ -3235,35 +3235,11 @@ _media_add_rtx (GstSDPMedia * media, WebRTCTransceiver * trans,
}
}
static GstWebRTCKind
_kind_from_caps (const GstCaps * caps)
{
GstStructure *s;
const gchar *media;
if (gst_caps_get_size (caps) == 0)
return GST_WEBRTC_KIND_UNKNOWN;
s = gst_caps_get_structure (caps, 0);
media = gst_structure_get_string (s, "media");
if (media == NULL)
return GST_WEBRTC_KIND_UNKNOWN;
if (!g_strcmp0 (media, "audio"))
return GST_WEBRTC_KIND_AUDIO;
if (!g_strcmp0 (media, "video"))
return GST_WEBRTC_KIND_VIDEO;
return GST_WEBRTC_KIND_UNKNOWN;
}
static gboolean
_update_transceiver_kind_from_caps (GstWebRTCRTPTransceiver * trans,
const GstCaps * caps)
{
GstWebRTCKind kind = _kind_from_caps (caps);
GstWebRTCKind kind = webrtc_kind_from_caps (caps);
if (trans->kind == kind)
return TRUE;
@ -3583,7 +3559,8 @@ _create_answer_task (GstWebRTCBin * webrtc, const GstStructure * options,
if (!_update_transceiver_kind_from_caps (rtp_trans, answer_caps))
GST_WARNING_OBJECT (webrtc,
"Trying to change transceiver %d kind from %d to %d",
rtp_trans->mline, rtp_trans->kind, _kind_from_caps (answer_caps));
rtp_trans->mline, rtp_trans->kind,
webrtc_kind_from_caps (answer_caps));
if (!trans->do_nack) {
answer_caps = gst_caps_make_writable (answer_caps);
@ -6420,7 +6397,7 @@ gst_webrtc_bin_request_new_pad (GstElement * element, GstPadTemplate * templ,
}
if (trans->kind != GST_WEBRTC_KIND_UNKNOWN) {
GstWebRTCKind kind = _kind_from_caps (caps);
GstWebRTCKind kind = webrtc_kind_from_caps (caps);
if (trans->kind != kind) {
GST_ERROR_OBJECT (element, "Tried to request a new sink pad %s for"
@ -6440,7 +6417,7 @@ gst_webrtc_bin_request_new_pad (GstElement * element, GstPadTemplate * templ,
guint i;
if (caps)
kind = _kind_from_caps (caps);
kind = webrtc_kind_from_caps (caps);
for (i = 0; i < webrtc->priv->transceivers->len; i++) {
GstWebRTCRTPTransceiver *tmptrans =

View file

@ -205,3 +205,28 @@ _rtp_caps_from_media (const GstSDPMedia * media)
return ret;
}
GstWebRTCKind
webrtc_kind_from_caps (const GstCaps * caps)
{
GstStructure *s;
const gchar *media;
if (gst_caps_get_size (caps) == 0)
return GST_WEBRTC_KIND_UNKNOWN;
s = gst_caps_get_structure (caps, 0);
media = gst_structure_get_string (s, "media");
if (media == NULL)
return GST_WEBRTC_KIND_UNKNOWN;
if (!g_strcmp0 (media, "audio"))
return GST_WEBRTC_KIND_AUDIO;
if (!g_strcmp0 (media, "video"))
return GST_WEBRTC_KIND_VIDEO;
return GST_WEBRTC_KIND_UNKNOWN;
}

View file

@ -82,6 +82,8 @@ G_GNUC_INTERNAL
const gchar * _g_checksum_to_webrtc_string (GChecksumType type);
G_GNUC_INTERNAL
GstCaps * _rtp_caps_from_media (const GstSDPMedia * media);
G_GNUC_INTERNAL
GstWebRTCKind webrtc_kind_from_caps (const GstCaps * caps);
G_END_DECLS