Commit 57a006d8 authored by Matthew Waters's avatar Matthew Waters 🐨
Browse files

tests/webrtc: use the existing functions in the plugin

Instead of redefining our own, use the function implementations in
webrtcsdp.c and utils.c
parent 14ee6f9d
......@@ -174,12 +174,6 @@ _have_dtls_elements (GstWebRTCBin * webrtc)
return TRUE;
}
GQuark
gst_webrtc_bin_error_quark (void)
{
return g_quark_from_static_string ("gst-webrtc-bin-error-quark");
}
G_DEFINE_TYPE (GstWebRTCBinPad, gst_webrtc_bin_pad, GST_TYPE_GHOST_PAD);
static void
......@@ -3484,7 +3478,7 @@ _set_description_task (GstWebRTCBin * webrtc, struct set_description *sd)
g_free (type_str);
}
if (!validate_sdp (webrtc, sd->source, sd->sdp, &error)) {
if (!validate_sdp (webrtc->signaling_state, sd->source, sd->sdp, &error)) {
GST_ERROR_OBJECT (webrtc, "%s", error->message);
g_clear_error (&error);
goto out;
......
......@@ -27,21 +27,6 @@
G_BEGIN_DECLS
#define GST_WEBRTC_BIN_ERROR gst_webrtc_bin_error_quark ()
GQuark gst_webrtc_bin_error_quark (void);
typedef enum
{
GST_WEBRTC_BIN_ERROR_FAILED,
GST_WEBRTC_BIN_ERROR_INVALID_SYNTAX,
GST_WEBRTC_BIN_ERROR_INVALID_MODIFICATION,
GST_WEBRTC_BIN_ERROR_INVALID_STATE,
GST_WEBRTC_BIN_ERROR_BAD_SDP,
GST_WEBRTC_BIN_ERROR_FINGERPRINT,
GST_WEBRTC_BIN_ERROR_SCTP_FAILURE,
GST_WEBRTC_BIN_ERROR_DATA_CHANNEL_FAILURE,
} GstWebRTCError;
GType gst_webrtc_bin_pad_get_type(void);
#define GST_TYPE_WEBRTC_BIN_PAD (gst_webrtc_bin_pad_get_type())
#define GST_WEBRTC_BIN_PAD(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_WEBRTC_BIN_PAD,GstWebRTCBinPad))
......
......@@ -24,6 +24,12 @@
#include "utils.h"
#include "gstwebrtcbin.h"
GQuark
gst_webrtc_bin_error_quark (void)
{
return g_quark_from_static_string ("gst-webrtc-bin-error-quark");
}
GstPadTemplate *
_find_pad_template (GstElement * element, GstPadDirection direction,
GstPadPresence presence, const gchar * name)
......
......@@ -26,6 +26,21 @@
G_BEGIN_DECLS
#define GST_WEBRTC_BIN_ERROR gst_webrtc_bin_error_quark ()
GQuark gst_webrtc_bin_error_quark (void);
typedef enum
{
GST_WEBRTC_BIN_ERROR_FAILED,
GST_WEBRTC_BIN_ERROR_INVALID_SYNTAX,
GST_WEBRTC_BIN_ERROR_INVALID_MODIFICATION,
GST_WEBRTC_BIN_ERROR_INVALID_STATE,
GST_WEBRTC_BIN_ERROR_BAD_SDP,
GST_WEBRTC_BIN_ERROR_FINGERPRINT,
GST_WEBRTC_BIN_ERROR_SCTP_FAILURE,
GST_WEBRTC_BIN_ERROR_DATA_CHANNEL_FAILURE,
} GstWebRTCError;
GstPadTemplate * _find_pad_template (GstElement * element,
GstPadDirection direction,
GstPadPresence presence,
......
......@@ -39,6 +39,7 @@
#include <gst/sctp/sctpsendmeta.h>
#include "gstwebrtcbin.h"
#include "utils.h"
#define GST_CAT_DEFAULT gst_webrtc_data_channel_debug
GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
......
......@@ -24,7 +24,6 @@
#include "webrtcsdp.h"
#include "utils.h"
#include "gstwebrtcbin.h"
#include <string.h>
......@@ -44,10 +43,9 @@ _sdp_source_to_string (SDPSource source)
}
static gboolean
_check_valid_state_for_sdp_change (GstWebRTCBin * webrtc, SDPSource source,
GstWebRTCSDPType type, GError ** error)
_check_valid_state_for_sdp_change (GstWebRTCSignalingState state,
SDPSource source, GstWebRTCSDPType type, GError ** error)
{
GstWebRTCSignalingState state = webrtc->signaling_state;
#define STATE(val) GST_WEBRTC_SIGNALING_STATE_ ## val
#define TYPE(val) GST_WEBRTC_SDP_TYPE_ ## val
......@@ -82,14 +80,14 @@ _check_valid_state_for_sdp_change (GstWebRTCBin * webrtc, SDPSource source,
return TRUE;
{
gchar *state = _enum_value_to_string (GST_TYPE_WEBRTC_SIGNALING_STATE,
webrtc->signaling_state);
gchar *state_str = _enum_value_to_string (GST_TYPE_WEBRTC_SIGNALING_STATE,
state);
gchar *type_str = _enum_value_to_string (GST_TYPE_WEBRTC_SDP_TYPE, type);
g_set_error (error, GST_WEBRTC_BIN_ERROR,
GST_WEBRTC_BIN_ERROR_INVALID_STATE,
"Not in the correct state (%s) for setting %s %s description", state,
_sdp_source_to_string (source), type_str);
g_free (state);
"Not in the correct state (%s) for setting %s %s description",
state_str, _sdp_source_to_string (source), type_str);
g_free (state_str);
g_free (type_str);
}
......@@ -100,8 +98,8 @@ _check_valid_state_for_sdp_change (GstWebRTCBin * webrtc, SDPSource source,
}
static gboolean
_check_sdp_crypto (GstWebRTCBin * webrtc, SDPSource source,
GstWebRTCSessionDescription * sdp, GError ** error)
_check_sdp_crypto (SDPSource source, GstWebRTCSessionDescription * sdp,
GError ** error)
{
const gchar *message_fingerprint, *fingerprint;
const GstSDPKey *key;
......@@ -278,7 +276,7 @@ _media_has_dtls_id (const GstSDPMedia * media, guint media_idx, GError ** error)
}
#endif
gboolean
validate_sdp (GstWebRTCBin * webrtc, SDPSource source,
validate_sdp (GstWebRTCSignalingState state, SDPSource source,
GstWebRTCSessionDescription * sdp, GError ** error)
{
const gchar *group, *bundle_ice_ufrag = NULL, *bundle_ice_pwd = NULL;
......@@ -286,9 +284,9 @@ validate_sdp (GstWebRTCBin * webrtc, SDPSource source,
gboolean is_bundle = FALSE;
int i;
if (!_check_valid_state_for_sdp_change (webrtc, source, sdp->type, error))
if (!_check_valid_state_for_sdp_change (state, source, sdp->type, error))
return FALSE;
if (!_check_sdp_crypto (webrtc, source, sdp, error))
if (!_check_sdp_crypto (source, sdp, error))
return FALSE;
/* not explicitly required
if (ICE && !_check_trickle_ice (sdp->sdp))
......
......@@ -38,7 +38,7 @@ const gchar * _sdp_source_to_string (SDP
G_GNUC_INTERNAL
gboolean validate_sdp (GstWebRTCBin * webrtc,
gboolean validate_sdp (GstWebRTCSignalingState state,
SDPSource source,
GstWebRTCSessionDescription * sdp,
GError ** error);
......
......@@ -29,6 +29,10 @@
#include <gst/check/gstcheck.h>
#include <gst/check/gstharness.h>
#include <gst/webrtc/webrtc.h>
#include "../../../ext/webrtc/webrtcsdp.h"
#include "../../../ext/webrtc/webrtcsdp.c"
#include "../../../ext/webrtc/utils.h"
#include "../../../ext/webrtc/utils.c"
#define OPUS_RTP_CAPS(pt) "application/x-rtp,payload=" G_STRINGIFY(pt) ",encoding-name=OPUS,media=audio,clock-rate=48000,ssrc=(uint)3384078950"
#define VP8_RTP_CAPS(pt) "application/x-rtp,payload=" G_STRINGIFY(pt) ",encoding-name=VP8,media=video,clock-rate=90000,ssrc=(uint)3484078950"
......@@ -785,7 +789,7 @@ struct validate_sdp
};
static GstWebRTCSessionDescription *
validate_sdp (struct test_webrtc *t, GstElement * element,
_check_validate_sdp (struct test_webrtc *t, GstElement * element,
GstPromise * promise, gpointer user_data)
{
struct validate_sdp *validate = user_data;
......@@ -862,9 +866,9 @@ GST_START_TEST (test_media_direction)
t->on_negotiation_needed = NULL;
t->offer_data = &offer;
t->on_offer_created = validate_sdp;
t->on_offer_created = _check_validate_sdp;
t->answer_data = &answer;
t->on_answer_created = validate_sdp;
t->on_answer_created = _check_validate_sdp;
t->on_ice_candidate = NULL;
fail_if (gst_element_set_state (t->webrtc1,
......@@ -922,7 +926,7 @@ GST_START_TEST (test_payload_types)
t->on_negotiation_needed = NULL;
t->offer_data = &offer;
t->on_offer_created = validate_sdp;
t->on_offer_created = _check_validate_sdp;
t->on_ice_candidate = NULL;
/* We don't really care about the answer here */
t->on_answer_created = NULL;
......@@ -986,9 +990,9 @@ GST_START_TEST (test_media_setup)
t->on_negotiation_needed = NULL;
t->offer_data = &offer;
t->on_offer_created = validate_sdp;
t->on_offer_created = _check_validate_sdp;
t->answer_data = &answer;
t->on_answer_created = validate_sdp;
t->on_answer_created = _check_validate_sdp;
t->on_ice_candidate = NULL;
fail_if (gst_element_set_state (t->webrtc1,
......@@ -1396,9 +1400,9 @@ GST_START_TEST (test_add_recvonly_transceiver)
t->on_pad_added = _pad_added_fakesink;
t->on_negotiation_needed = NULL;
t->offer_data = &offer;
t->on_offer_created = validate_sdp;
t->on_offer_created = _check_validate_sdp;
t->answer_data = &answer;
t->on_answer_created = validate_sdp;
t->on_answer_created = _check_validate_sdp;
t->on_ice_candidate = NULL;
/* setup recvonly transceiver */
......@@ -1449,9 +1453,9 @@ GST_START_TEST (test_recvonly_sendonly)
t->on_pad_added = _pad_added_fakesink;
t->on_negotiation_needed = NULL;
t->offer_data = &offer;
t->on_offer_created = validate_sdp;
t->on_offer_created = _check_validate_sdp;
t->answer_data = &answer;
t->on_answer_created = validate_sdp;
t->on_answer_created = _check_validate_sdp;
t->on_ice_candidate = NULL;
/* setup recvonly transceiver */
......@@ -1493,32 +1497,6 @@ GST_START_TEST (test_recvonly_sendonly)
GST_END_TEST;
static gboolean
_message_media_is_datachannel (const GstSDPMessage * msg, guint media_id)
{
const GstSDPMedia *media;
if (!msg)
return FALSE;
if (gst_sdp_message_medias_len (msg) <= media_id)
return FALSE;
media = gst_sdp_message_get_media (msg, media_id);
if (g_strcmp0 (gst_sdp_media_get_media (media), "application") != 0)
return FALSE;
if (gst_sdp_media_formats_len (media) != 1)
return FALSE;
if (g_strcmp0 (gst_sdp_media_get_format (media, 0),
"webrtc-datachannel") != 0)
return FALSE;
return TRUE;
}
static void
on_sdp_has_datachannel (struct test_webrtc *t, GstElement * element,
GstWebRTCSessionDescription * desc, gpointer user_data)
......@@ -1554,9 +1532,9 @@ GST_START_TEST (test_data_channel_create)
t->on_negotiation_needed = NULL;
t->offer_data = &offer;
t->on_offer_created = validate_sdp;
t->on_offer_created = _check_validate_sdp;
t->answer_data = &answer;
t->on_answer_created = validate_sdp;
t->on_answer_created = _check_validate_sdp;
t->on_ice_candidate = NULL;
fail_if (gst_element_set_state (t->webrtc1,
......@@ -1613,9 +1591,9 @@ GST_START_TEST (test_data_channel_remote_notify)
t->on_negotiation_needed = NULL;
t->offer_data = &offer;
t->on_offer_created = validate_sdp;
t->on_offer_created = _check_validate_sdp;
t->answer_data = &answer;
t->on_answer_created = validate_sdp;
t->on_answer_created = _check_validate_sdp;
t->on_ice_candidate = NULL;
t->on_data_channel = have_data_channel;
......@@ -1688,9 +1666,9 @@ GST_START_TEST (test_data_channel_transfer_string)
t->on_negotiation_needed = NULL;
t->offer_data = &offer;
t->on_offer_created = validate_sdp;
t->on_offer_created = _check_validate_sdp;
t->answer_data = &answer;
t->on_answer_created = validate_sdp;
t->on_answer_created = _check_validate_sdp;
t->on_ice_candidate = NULL;
t->on_data_channel = have_data_channel_transfer_string;
......@@ -1770,9 +1748,9 @@ GST_START_TEST (test_data_channel_transfer_data)
t->on_negotiation_needed = NULL;
t->offer_data = &offer;
t->on_offer_created = validate_sdp;
t->on_offer_created = _check_validate_sdp;
t->answer_data = &answer;
t->on_answer_created = validate_sdp;
t->on_answer_created = _check_validate_sdp;
t->on_ice_candidate = NULL;
t->on_data_channel = have_data_channel_transfer_data;
......@@ -1828,9 +1806,9 @@ GST_START_TEST (test_data_channel_create_after_negotiate)
t->on_negotiation_needed = NULL;
t->offer_data = &offer;
t->on_offer_created = validate_sdp;
t->on_offer_created = _check_validate_sdp;
t->answer_data = &answer;
t->on_answer_created = validate_sdp;
t->on_answer_created = _check_validate_sdp;
t->on_ice_candidate = NULL;
t->on_data_channel = have_data_channel_create_data_channel;
......@@ -1889,9 +1867,9 @@ GST_START_TEST (test_data_channel_low_threshold)
t->on_negotiation_needed = NULL;
t->offer_data = &offer;
t->on_offer_created = validate_sdp;
t->on_offer_created = _check_validate_sdp;
t->answer_data = &answer;
t->on_answer_created = validate_sdp;
t->on_answer_created = _check_validate_sdp;
t->on_ice_candidate = NULL;
t->on_data_channel = have_data_channel_check_low_threshold_emitted;
......@@ -1962,9 +1940,9 @@ GST_START_TEST (test_data_channel_max_message_size)
t->on_negotiation_needed = NULL;
t->offer_data = &offer;
t->on_offer_created = validate_sdp;
t->on_offer_created = _check_validate_sdp;
t->answer_data = &answer;
t->on_answer_created = validate_sdp;
t->on_answer_created = _check_validate_sdp;
t->on_ice_candidate = NULL;
t->on_data_channel = have_data_channel_transfer_large_data;
......@@ -2019,9 +1997,9 @@ GST_START_TEST (test_data_channel_pre_negotiated)
t->on_negotiation_needed = NULL;
t->offer_data = &offer;
t->on_offer_created = validate_sdp;
t->on_offer_created = _check_validate_sdp;
t->answer_data = &answer;
t->on_answer_created = validate_sdp;
t->on_answer_created = _check_validate_sdp;
t->on_ice_candidate = NULL;
fail_if (gst_element_set_state (t->webrtc1,
......@@ -2078,48 +2056,6 @@ typedef struct
const gchar **bundled_only;
} BundleCheckData;
static gboolean
_parse_bundle (GstSDPMessage * sdp, GStrv * bundled)
{
const gchar *group;
gboolean ret = FALSE;
group = gst_sdp_message_get_attribute_val (sdp, "group");
if (group && g_str_has_prefix (group, "BUNDLE ")) {
*bundled = g_strsplit (group + strlen ("BUNDLE "), " ", 0);
if (!(*bundled)[0]) {
GST_ERROR
("Invalid format for BUNDLE group, expected at least one mid (%s)",
group);
goto done;
}
} else {
ret = TRUE;
goto done;
}
ret = TRUE;
done:
return ret;
}
static gboolean
_media_has_attribute_key (const GstSDPMedia * media, const gchar * key)
{
int i;
for (i = 0; i < gst_sdp_media_attributes_len (media); i++) {
const GstSDPAttribute *attr = gst_sdp_media_get_attribute (media, i);
if (g_strcmp0 (attr->key, key) == 0)
return TRUE;
}
return FALSE;
}
static void
_check_bundled_sdp_media (struct test_webrtc *t, GstElement * element,
GstWebRTCSessionDescription * sd, gpointer user_data)
......@@ -2202,9 +2138,9 @@ GST_START_TEST (test_bundle_audio_video_max_bundle_max_bundle)
t->on_negotiation_needed = NULL;
t->offer_data = &offer;
t->on_offer_created = validate_sdp;
t->on_offer_created = _check_validate_sdp;
t->answer_data = &answer;
t->on_answer_created = validate_sdp;
t->on_answer_created = _check_validate_sdp;
t->on_ice_candidate = NULL;
fail_if (gst_element_set_state (t->webrtc1,
......@@ -2259,9 +2195,9 @@ GST_START_TEST (test_bundle_audio_video_max_compat_max_bundle)
t->on_negotiation_needed = NULL;
t->offer_data = &offer;
t->on_offer_created = validate_sdp;
t->on_offer_created = _check_validate_sdp;
t->answer_data = &answer;
t->on_answer_created = validate_sdp;
t->on_answer_created = _check_validate_sdp;
t->on_ice_candidate = NULL;
fail_if (gst_element_set_state (t->webrtc1,
......@@ -2317,9 +2253,9 @@ GST_START_TEST (test_bundle_audio_video_max_bundle_none)
t->on_negotiation_needed = NULL;
t->offer_data = &offer;
t->on_offer_created = validate_sdp;
t->on_offer_created = _check_validate_sdp;
t->answer_data = &answer;
t->on_answer_created = validate_sdp;
t->on_answer_created = _check_validate_sdp;
t->on_ice_candidate = NULL;
fail_if (gst_element_set_state (t->webrtc1,
......@@ -2376,9 +2312,9 @@ GST_START_TEST (test_bundle_audio_video_data)
t->on_negotiation_needed = NULL;
t->offer_data = &offer;
t->on_offer_created = validate_sdp;
t->on_offer_created = _check_validate_sdp;
t->answer_data = &answer;
t->on_answer_created = validate_sdp;
t->on_answer_created = _check_validate_sdp;
t->on_ice_candidate = NULL;
fail_if (gst_element_set_state (t->webrtc1,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment