rtopuspay: Ignore the stereo parameter in multiopus caps

Also add unit tests for the various variants

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3674>
This commit is contained in:
Olivier Crête 2023-01-12 14:25:52 -05:00
parent f1cf457811
commit 46a6f72f03
2 changed files with 110 additions and 13 deletions

View file

@ -372,7 +372,7 @@ gst_rtp_opus_pay_getcaps (GstRTPBasePayload * payload,
GstPad * pad, GstCaps * filter)
{
GstStructure *s;
const gchar *stereo;
int channel_mapping_family = 0;
GstCaps *caps, *peercaps, *tcaps, *tempcaps;
if (pad == GST_RTP_BASE_PAYLOAD_SRCPAD (payload))
@ -428,21 +428,27 @@ gst_rtp_opus_pay_getcaps (GstRTPBasePayload * payload,
}
gst_caps_unref (tempcaps);
s = gst_caps_get_structure (peercaps, 0);
stereo = gst_structure_get_string (s, "stereo");
if (stereo != NULL) {
caps = gst_caps_make_writable (caps);
s = gst_caps_get_structure (caps, 0);
gst_structure_get_int (s, "channel-mapping-family", &channel_mapping_family);
if (channel_mapping_family == 0) {
GstStructure *sp = gst_caps_get_structure (peercaps, 0);
const gchar *stereo = gst_structure_get_string (sp, "stereo");
if (!strcmp (stereo, "1")) {
GstCaps *caps2 = gst_caps_copy (caps);
if (stereo != NULL) {
guint channels = 0;
gst_caps_set_simple (caps, "channels", G_TYPE_INT, 2, NULL);
caps = gst_caps_merge (caps, caps2);
} else if (!strcmp (stereo, "0")) {
GstCaps *caps2 = gst_caps_copy (caps);
if (!strcmp (stereo, "1"))
channels = 2;
else if (!strcmp (stereo, "0"))
channels = 1;
gst_caps_set_simple (caps, "channels", G_TYPE_INT, 1, NULL);
caps = gst_caps_merge (caps, caps2);
if (channels) {
GstCaps *caps2 = gst_caps_copy_nth (caps, 0);
gst_caps_set_simple (caps2, "channels", G_TYPE_INT, channels, NULL);
caps = gst_caps_make_writable (caps);
caps = gst_caps_merge (caps2, caps);
}
}
}
gst_caps_unref (peercaps);

View file

@ -126,6 +126,7 @@ GST_START_TEST (test_pay_to_depay_multichannel)
}
GST_END_TEST;
GST_START_TEST (test_depay_to_pay_multichannel)
{
GstHarness *h = gst_harness_new_parse ("rtpopusdepay ! rtpopuspay");
@ -165,6 +166,95 @@ GST_START_TEST (test_depay_to_pay_multichannel)
GST_END_TEST;
GST_START_TEST (test_pay_getcaps)
{
GstHarness *h = gst_harness_new ("rtpopuspay");
GstCaps *ref, *qcaps;
gst_harness_set_sink_caps_str (h, "application/x-rtp, "
"encoding-name=(string)OPUS, stereo=(string)0");
qcaps = gst_pad_peer_query_caps (h->srcpad, NULL);
/* Check that is also contains stereo */
ref = gst_caps_from_string ("audio/x-opus, channels=(int)2, "
"channel-mapping-family=(int)0");
fail_unless (gst_caps_can_intersect (ref, qcaps));
gst_caps_unref (ref);
fail_unless_equals_int (gst_caps_get_size (qcaps), 2);
qcaps = gst_caps_truncate (qcaps);
/* Check that the first structure is mono */
ref = gst_caps_from_string ("audio/x-opus, channels=(int)1, "
"channel-mapping-family=(int)0");
fail_unless (gst_caps_is_equal (ref, qcaps));
gst_caps_unref (ref);
gst_caps_unref (qcaps);
gst_harness_set_sink_caps_str (h, "application/x-rtp, "
"encoding-name=(string)OPUS, stereo=(string)1");
qcaps = gst_pad_peer_query_caps (h->srcpad, NULL);
/* Check that is also contains stereo */
ref = gst_caps_from_string ("audio/x-opus, channels=(int)2, "
"channel-mapping-family=(int)0");
fail_unless (gst_caps_can_intersect (ref, qcaps));
gst_caps_unref (ref);
fail_unless_equals_int (gst_caps_get_size (qcaps), 2);
qcaps = gst_caps_truncate (qcaps);
/* Check that the first structure is mono */
ref = gst_caps_from_string ("audio/x-opus, channels=(int)2, "
"channel-mapping-family=(int)0");
fail_unless (gst_caps_is_equal (ref, qcaps));
gst_caps_unref (ref);
gst_caps_unref (qcaps);
gst_harness_set_sink_caps_str (h, "application/x-rtp, "
"encoding-name=(string)MULTIOPUS");
qcaps = gst_pad_peer_query_caps (h->srcpad, NULL);
/* Check that is also contains stereo */
ref = gst_caps_from_string ("audio/x-opus, channels=(int)[3, 255], "
"channel-mapping-family=(int)1");
fail_unless (gst_caps_is_equal (ref, qcaps));
gst_caps_unref (ref);
fail_unless_equals_int (gst_caps_get_size (qcaps), 1);
gst_caps_unref (qcaps);
gst_harness_set_sink_caps_str (h, "application/x-rtp, "
"encoding-name=(string)MULTIOPUS, stereo=(string)1");
qcaps = gst_pad_peer_query_caps (h->srcpad, NULL);
/* Check that is also contains stereo */
ref = gst_caps_from_string ("audio/x-opus, channels=(int)[3, 255], "
"channel-mapping-family=(int)1");
fail_unless (gst_caps_is_equal (ref, qcaps));
gst_caps_unref (ref);
fail_unless_equals_int (gst_caps_get_size (qcaps), 1);
gst_caps_unref (qcaps);
gst_harness_set_sink_caps_str (h, "application/x-rtp, "
"encoding-name=(string)OPUS, stereo=(string)0;"
"application/x-rtp, encoding-name=(string)MULTIOPUS");
qcaps = gst_pad_peer_query_caps (h->srcpad, NULL);
/* Check that is also contains stereo */
ref = gst_caps_from_string ("audio/x-opus, channels=(int)2, "
"channel-mapping-family=(int)0");
fail_unless (gst_caps_can_intersect (ref, qcaps));
gst_caps_unref (ref);
/* Check that is also contains 3 channels */
ref = gst_caps_from_string ("audio/x-opus, channels=(int)3, "
"channel-mapping-family=(int)1");
fail_unless (gst_caps_can_intersect (ref, qcaps));
gst_caps_unref (ref);
fail_unless_equals_int (gst_caps_get_size (qcaps), 3);
qcaps = gst_caps_truncate (qcaps);
/* Check that the first structure is mono */
ref = gst_caps_from_string ("audio/x-opus, channels=(int)1, "
"channel-mapping-family=(int)0");
fail_unless (gst_caps_can_intersect (ref, qcaps));
gst_caps_unref (ref);
gst_caps_unref (qcaps);
gst_harness_teardown (h);
}
GST_END_TEST;
static Suite *
rtpopus_suite (void)
{
@ -176,6 +266,7 @@ rtpopus_suite (void)
tcase_add_test (tc_chain, test_depay_to_pay);
tcase_add_test (tc_chain, test_pay_to_depay_multichannel);
tcase_add_test (tc_chain, test_depay_to_pay_multichannel);
tcase_add_test (tc_chain, test_pay_getcaps);
return s;
}