mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-22 08:17:01 +00:00
682b523652
<gstsdpmessage.h> GstCaps* gst_sdp_media_get_caps_from_media (const GstSDPMedia *media, gint pt); GstSDPResult gst_sdp_media_set_media_from_caps (const GstCaps* caps, GstSDPMedia *media); gchar * gst_sdp_make_keymgmt (const gchar *uri, const gchar *base64); GstSDPResult gst_sdp_message_attributes_to_caps (GstSDPMessage *msg, GstCaps *caps); GstSDPResult gst_sdp_media_attributes_to_caps (GstSDPMedia *media, GstCaps *caps); <gstmikey.h> GstMIKEYMessage * gst_mikey_message_new_from_caps (GstCaps *caps); gchar * gst_mikey_message_base64_encode (GstMIKEYMessage* msg); https://bugzilla.gnome.org/show_bug.cgi?id=745880
319 lines
9.8 KiB
C
319 lines
9.8 KiB
C
/* GStreamer unit tests for the SDP support library
|
|
*
|
|
* Copyright (C) 2013 Jose Antonio Santos Cadenas <santoscadenas@gmail.com>
|
|
*
|
|
* This library is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU Library General Public
|
|
* License as published by the Free Software Foundation; either
|
|
* version 2 of the License, or (at your option) any later version.
|
|
*
|
|
* This library is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* Library General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Library General Public
|
|
* License along with this library; if not, write to the
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
* Boston, MA 02111-1307, USA.
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
#include "config.h"
|
|
#endif
|
|
|
|
#include <gst/check/gstcheck.h>
|
|
|
|
/*
|
|
* test_sdp.c - gst-kurento-plugins
|
|
*
|
|
* Copyright (C) 2013 Kurento
|
|
* Contact: Miguel París Díaz <mparisdiaz@gmail.com>
|
|
* Contact: José Antonio Santos Cadenas <santoscadenas@kurento.com>
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License version 3
|
|
* as published by the Free Software Foundation.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include <gst/check/gstcheck.h>
|
|
#include <gst/sdp/gstsdpmessage.h>
|
|
|
|
static const gchar *sdp = "v=0\r\n"
|
|
"o=- 123456 0 IN IP4 127.0.0.1\r\n"
|
|
"s=TestSessionToCopy\r\n"
|
|
"c=IN IP4 127.0.0.1\r\n"
|
|
"t=0 0\r\n"
|
|
"m=video 3434 RTP/AVP 96 97 99\r\n"
|
|
"a=rtpmap:96 MP4V-ES/90000\r\n"
|
|
"a=rtpmap:97 H263-1998/90000\r\n"
|
|
"a=rtpmap:99 H263/90000\r\n"
|
|
"a=sendrecv\r\n"
|
|
"m=video 6565 RTP/AVP 98\r\n"
|
|
"a=rtpmap:98 VP8/90000\r\n"
|
|
"a=sendrecv\r\n" "m=audio 4545 RTP/AVP 14\r\n" "a=sendrecv\r\n"
|
|
"m=audio 1010 TCP 14\r\n";
|
|
|
|
static const gchar caps_video_string1[] =
|
|
"application/x-unknown, media=(string)video, payload=(int)96, "
|
|
"clock-rate=(int)90000, encoding-name=(string)MP4V-ES";
|
|
|
|
static const gchar caps_video_string2[] =
|
|
"application/x-unknown, media=(string)video, payload=(int)97, "
|
|
"clock-rate=(int)90000, encoding-name=(string)H263-1998";
|
|
|
|
static const gchar caps_audio_string[] =
|
|
"application/x-unknown, media=(string)audio, payload=(int)14, "
|
|
"clock-rate=(int)90000";
|
|
|
|
GST_START_TEST (boxed)
|
|
{
|
|
GValue value = G_VALUE_INIT;
|
|
GValue value_copy = G_VALUE_INIT;
|
|
GstSDPMessage *message, *copy;
|
|
gchar *message1_str, *message2_str, *copy_str;
|
|
const gchar *repeat1[] = { "789", "012", NULL };
|
|
|
|
gst_sdp_message_new (&message);
|
|
gst_sdp_message_parse_buffer ((guint8 *) sdp, -1, message);
|
|
|
|
gst_sdp_message_add_time (message, "123", "456", repeat1);
|
|
|
|
g_value_init (&value, GST_TYPE_SDP_MESSAGE);
|
|
g_value_init (&value_copy, GST_TYPE_SDP_MESSAGE);
|
|
|
|
g_value_set_boxed (&value, message);
|
|
message1_str = gst_sdp_message_as_text (message);
|
|
GST_DEBUG ("message1:\n%s", message1_str);
|
|
gst_sdp_message_free (message);
|
|
|
|
message = g_value_get_boxed (&value);
|
|
message2_str = gst_sdp_message_as_text (message);
|
|
GST_DEBUG ("message2:\n%s", message2_str);
|
|
|
|
fail_if (g_strcmp0 (message1_str, message2_str) != 0);
|
|
|
|
g_value_copy (&value, &value_copy);
|
|
g_value_reset (&value);
|
|
|
|
copy = g_value_dup_boxed (&value_copy);
|
|
g_value_reset (&value_copy);
|
|
|
|
copy_str = gst_sdp_message_as_text (copy);
|
|
gst_sdp_message_free (copy);
|
|
GST_DEBUG ("copy:\n%s", copy_str);
|
|
|
|
fail_if (g_strcmp0 (message1_str, copy_str));
|
|
|
|
g_free (message1_str);
|
|
g_free (message2_str);
|
|
g_free (copy_str);
|
|
}
|
|
|
|
GST_END_TEST
|
|
GST_START_TEST (copy)
|
|
{
|
|
GstSDPMessage *message, *copy;
|
|
glong length = -1;
|
|
gchar *message_str, *copy_str;
|
|
const gchar *repeat1[] = { "789", "012", NULL };
|
|
const gchar *repeat2[] = { "987", "210", NULL };
|
|
|
|
gst_sdp_message_new (&message);
|
|
gst_sdp_message_parse_buffer ((guint8 *) sdp, length, message);
|
|
|
|
gst_sdp_message_add_time (message, "123", "456", repeat1);
|
|
gst_sdp_message_add_time (message, "321", "654", repeat2);
|
|
|
|
gst_sdp_message_copy (message, ©);
|
|
|
|
message_str = gst_sdp_message_as_text (message);
|
|
GST_DEBUG ("Original:\n%s", message_str);
|
|
gst_sdp_message_free (message);
|
|
copy_str = gst_sdp_message_as_text (copy);
|
|
gst_sdp_message_free (copy);
|
|
GST_DEBUG ("Copy:\n%s", copy_str);
|
|
|
|
fail_if (g_strcmp0 (copy_str, message_str) != 0);
|
|
g_free (copy_str);
|
|
g_free (message_str);
|
|
}
|
|
|
|
GST_END_TEST
|
|
GST_START_TEST (modify)
|
|
{
|
|
GstSDPMessage *message;
|
|
glong length = -1;
|
|
const GstSDPMedia *media;
|
|
const gchar *old_val;
|
|
const gchar *result;
|
|
GstSDPAttribute attr;
|
|
|
|
gst_sdp_message_new (&message);
|
|
gst_sdp_message_parse_buffer ((guint8 *) sdp, length, message);
|
|
|
|
/* modify session attribute */
|
|
fail_unless (gst_sdp_message_add_attribute (message,
|
|
"test_attr_session", "param1=val1") == GST_SDP_OK);
|
|
|
|
old_val = gst_sdp_message_get_attribute_val (message, "test_attr_session");
|
|
|
|
fail_unless (old_val != NULL);
|
|
attr.key = g_strdup ("test_attr_session");
|
|
attr.value = g_strdup_printf ("%s;param2=val2", old_val);
|
|
|
|
fail_unless (gst_sdp_message_replace_attribute (message, 0,
|
|
&attr) == GST_SDP_OK);
|
|
|
|
result = gst_sdp_message_get_attribute_val (message, "test_attr_session");
|
|
fail_unless (result != NULL);
|
|
fail_unless (g_strcmp0 (result, "param1=val1;param2=val2") == 0);
|
|
|
|
|
|
/* modify media attribute */
|
|
media = gst_sdp_message_get_media (message, 0);
|
|
fail_unless (media != NULL);
|
|
|
|
fail_unless (gst_sdp_media_add_attribute ((GstSDPMedia *) media,
|
|
"test_attr_media", "param3=val3") == GST_SDP_OK);
|
|
|
|
old_val =
|
|
gst_sdp_media_get_attribute_val ((GstSDPMedia *) media,
|
|
"test_attr_media");
|
|
|
|
fail_unless (old_val != NULL);
|
|
attr.key = g_strdup ("test_attr_media");
|
|
attr.value = g_strdup ("myparam=myval");
|
|
|
|
fail_unless (gst_sdp_media_replace_attribute ((GstSDPMedia *) media,
|
|
0, &attr) == GST_SDP_OK);
|
|
|
|
result =
|
|
gst_sdp_media_get_attribute_val ((GstSDPMedia *) media,
|
|
"test_attr_media");
|
|
fail_unless (result != NULL);
|
|
fail_unless (g_strcmp0 (result, "myparam=myval") == 0);
|
|
|
|
gst_sdp_message_free (message);
|
|
}
|
|
|
|
GST_END_TEST
|
|
GST_START_TEST (caps_from_media)
|
|
{
|
|
GstSDPMessage *message;
|
|
glong length = -1;
|
|
const GstSDPMedia *media1, *media2, *media3;
|
|
GstCaps *caps_video1, *caps_video2, *caps_audio;
|
|
GstCaps *result_video1, *result_video2, *result_audio;
|
|
|
|
gst_sdp_message_new (&message);
|
|
gst_sdp_message_parse_buffer ((guint8 *) sdp, length, message);
|
|
|
|
media1 = gst_sdp_message_get_media (message, 0);
|
|
fail_unless (media1 != NULL);
|
|
|
|
media2 = gst_sdp_message_get_media (message, 1);
|
|
fail_unless (media2 != NULL);
|
|
|
|
media3 = gst_sdp_message_get_media (message, 2);
|
|
fail_unless (media2 != NULL);
|
|
|
|
caps_video1 = gst_sdp_media_get_caps_from_media (media1, 96);
|
|
caps_video2 = gst_sdp_media_get_caps_from_media (media1, 97);
|
|
caps_audio = gst_sdp_media_get_caps_from_media (media3, 14);
|
|
|
|
result_video1 = gst_caps_from_string (caps_video_string1);
|
|
fail_unless (gst_caps_is_strictly_equal (caps_video1, result_video1));
|
|
gst_caps_unref (result_video1);
|
|
gst_caps_unref (caps_video1);
|
|
|
|
result_video2 = gst_caps_from_string (caps_video_string2);
|
|
fail_unless (gst_caps_is_strictly_equal (caps_video2, result_video2));
|
|
gst_caps_unref (result_video2);
|
|
gst_caps_unref (caps_video2);
|
|
|
|
result_audio = gst_caps_from_string (caps_audio_string);
|
|
fail_unless (gst_caps_is_strictly_equal (caps_audio, result_audio));
|
|
gst_caps_unref (result_audio);
|
|
gst_caps_unref (caps_audio);
|
|
|
|
gst_sdp_message_free (message);
|
|
}
|
|
|
|
GST_END_TEST
|
|
GST_START_TEST (media_from_caps)
|
|
{
|
|
GstSDPResult ret = GST_SDP_OK;
|
|
GstSDPMessage *message;
|
|
glong length = -1;
|
|
GstSDPMedia *media_video, *media_audio;
|
|
const GstSDPMedia *result_video, *result_audio;
|
|
GstCaps *caps_video, *caps_audio;
|
|
const gchar *media1_text, *media2_text, *media3_text, *media4_text;
|
|
|
|
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_parse_buffer ((guint8 *) sdp, length, message);
|
|
|
|
result_video = gst_sdp_message_get_media (message, 0);
|
|
fail_unless (result_video != NULL);
|
|
|
|
result_audio = gst_sdp_message_get_media (message, 2);
|
|
fail_unless (result_audio != NULL);
|
|
|
|
media1_text = gst_sdp_media_get_attribute_val (media_video, "rtpmap");
|
|
media2_text = gst_sdp_media_get_attribute_val (result_video, "rtpmap");
|
|
media3_text = gst_sdp_media_get_format (media_audio, 0);
|
|
media4_text = gst_sdp_media_get_format (result_audio, 0);
|
|
|
|
fail_if (g_strcmp0 (media1_text, media2_text) != 0);
|
|
fail_if (g_strcmp0 (media3_text, media4_text) != 0);
|
|
|
|
gst_sdp_media_free (media_video);
|
|
gst_sdp_media_free (media_audio);
|
|
gst_sdp_message_free (message);
|
|
}
|
|
|
|
GST_END_TEST
|
|
/*
|
|
* End of test cases
|
|
*/
|
|
static Suite *
|
|
sdp_suite (void)
|
|
{
|
|
Suite *s = suite_create ("sdp");
|
|
TCase *tc_chain = tcase_create ("sdp");
|
|
|
|
suite_add_tcase (s, tc_chain);
|
|
tcase_add_test (tc_chain, copy);
|
|
tcase_add_test (tc_chain, boxed);
|
|
tcase_add_test (tc_chain, modify);
|
|
tcase_add_test (tc_chain, caps_from_media);
|
|
tcase_add_test (tc_chain, media_from_caps);
|
|
|
|
return s;
|
|
}
|
|
|
|
GST_CHECK_MAIN (sdp);
|