+GST_START_TEST (test_force_second_media)
+{
+ struct test_webrtc *t = test_webrtc_new ();
+ const gchar *media_types[] = { "audio" };
+ VAL_SDP_INIT (media_type, _verify_media_types, &media_types, NULL);
+ guint media_format_count[] = { 1, };
+ VAL_SDP_INIT (media_formats, on_sdp_media_count_formats,
+ media_format_count, &media_type);
+ const gchar *expected_offer_setup[] = { "actpass", };
+ VAL_SDP_INIT (offer_setup, on_sdp_media_setup, expected_offer_setup,
+ &media_formats);
+ const gchar *expected_answer_setup[] = { "active", };
+ VAL_SDP_INIT (answer_setup, on_sdp_media_setup, expected_answer_setup,
+ &media_formats);
+ const gchar *expected_offer_direction[] = { "sendrecv", };
+ VAL_SDP_INIT (offer_direction, on_sdp_media_direction,
+ expected_offer_direction, &offer_setup);
+ const gchar *expected_answer_direction[] = { "recvonly", };
+ VAL_SDP_INIT (answer_direction, on_sdp_media_direction,
+ expected_answer_direction, &answer_setup);
+ VAL_SDP_INIT (answer_count, _count_num_sdp_media, GUINT_TO_POINTER (1),
+ &answer_direction);
+ VAL_SDP_INIT (offer_count, _count_num_sdp_media, GUINT_TO_POINTER (1),
+ &offer_direction);
+
+ const gchar *second_media_types[] = { "audio", "video" };
+ VAL_SDP_INIT (second_media_type, _verify_media_types, &second_media_types,
+ NULL);
+ guint second_media_format_count[] = { 1, 1 };
+ VAL_SDP_INIT (second_media_formats, on_sdp_media_count_formats,
+ second_media_format_count, &second_media_type);
+ const gchar *second_expected_offer_setup[] = { "active", "actpass" };
+ VAL_SDP_INIT (second_offer_setup, on_sdp_media_setup,
+ second_expected_offer_setup, &second_media_formats);
+ const gchar *second_expected_answer_setup[] = { "passive", "active" };
+ VAL_SDP_INIT (second_answer_setup, on_sdp_media_setup,
+ second_expected_answer_setup, &second_media_formats);
+ const gchar *second_expected_answer_direction[] = { "sendonly", "recvonly" };
+ VAL_SDP_INIT (second_answer_direction, on_sdp_media_direction,
+ second_expected_answer_direction, &second_answer_setup);
+ const gchar *second_expected_offer_direction[] = { "recvonly", "sendrecv" };
+ VAL_SDP_INIT (second_offer_direction, on_sdp_media_direction,
+ second_expected_offer_direction, &second_offer_setup);
+ VAL_SDP_INIT (second_answer_count, _count_num_sdp_media, GUINT_TO_POINTER (2),
+ &second_answer_direction);
+ VAL_SDP_INIT (second_offer_count, _count_num_sdp_media, GUINT_TO_POINTER (2),
+ &second_offer_direction);
+
+ GstHarness *h;
+ guint negotiation_flag = 0;
+ GstPadTemplate *templ;
+ GstCaps *caps;
+ GstPad *pad;
+
+ /* add a transceiver that will only receive an opus stream and check that
+ * the created offer is marked as recvonly */
+ t->on_negotiation_needed = on_negotiation_needed_hit;
+ t->negotiation_data = &negotiation_flag;
+ t->on_ice_candidate = NULL;
+ t->on_pad_added = _pad_added_fakesink;
+
+ /* setup peer */
+ h = gst_harness_new_with_element (t->webrtc1, "sink_0", NULL);
+ add_fake_audio_src_harness (h, 96);
+ t->harnesses = g_list_prepend (t->harnesses, h);
+
+ /* Create a second side with specific video caps */
+ templ = gst_element_get_pad_template (t->webrtc2, "sink_%u");
+ fail_unless (templ != NULL);
+ caps = gst_caps_from_string (VP8_RTP_CAPS (97));
+ pad = gst_element_request_pad (t->webrtc2, templ, NULL, caps);
+ gst_caps_unref (caps);
+ fail_unless (pad != NULL);
+ h = gst_harness_new_with_element (t->webrtc2, GST_PAD_NAME (pad), NULL);
+ gst_object_unref (pad);
+ add_fake_video_src_harness (h, 97);
+ t->harnesses = g_list_prepend (t->harnesses, h);
+
+ test_validate_sdp (t, &offer_count, &answer_count);
+ fail_unless (negotiation_flag & 1 << 2);
+
+ test_webrtc_reset_negotiation (t);
+
+ t->offerror = 2;
+ test_validate_sdp (t, &second_offer_count, &second_answer_count);
+
+ test_webrtc_free (t);
+}
+
+GST_END_TEST;
+