1 /* GStreamer
2 *
3 * unit test for rtpptdemux element
4 *
5 * Copyright 2017 Pexip
6 * @author: Mikhail Fludkov <misha@pexip.com>
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
17 *
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22 */
23
24 #include <gst/check/gstcheck.h>
25 #include <gst/check/gstharness.h>
26 #include <gst/rtp/gstrtpbuffer.h>
27 #include <gst/gst.h>
28
29 static void
new_payload_type(G_GNUC_UNUSED GstElement * element,G_GNUC_UNUSED guint pt,GstPad * pad,GstHarness ** h)30 new_payload_type (G_GNUC_UNUSED GstElement * element, G_GNUC_UNUSED guint pt,
31 GstPad * pad, GstHarness ** h)
32 {
33 gst_harness_add_element_src_pad (*h, pad);
34 }
35
36 static void
test_rtpptdemux_srccaps_from_sinkcaps_base(const gchar * srccaps,const gchar * sinkcaps)37 test_rtpptdemux_srccaps_from_sinkcaps_base (const gchar * srccaps,
38 const gchar * sinkcaps)
39 {
40 GstCaps *caps;
41 gchar *caps_str;
42 GstHarness *h = gst_harness_new_with_padnames ("rtpptdemux", "sink", NULL);
43
44 gst_harness_set_src_caps_str (h, srccaps);
45 g_signal_connect (h->element,
46 "new-payload-type", (GCallback) new_payload_type, &h);
47 gst_harness_play (h);
48
49 gst_buffer_unref (gst_harness_push_and_pull (h,
50 gst_rtp_buffer_new_allocate (0, 0, 0)));
51
52 caps = gst_pad_get_current_caps (h->sinkpad);
53 caps_str = gst_caps_to_string (caps);
54 fail_unless_equals_string (caps_str, sinkcaps);
55
56 g_free (caps_str);
57 gst_caps_unref (caps);
58 gst_harness_teardown (h);
59 }
60
GST_START_TEST(test_rtpptdemux_srccaps_from_sinkcaps)61 GST_START_TEST (test_rtpptdemux_srccaps_from_sinkcaps)
62 {
63 test_rtpptdemux_srccaps_from_sinkcaps_base
64 ("application/x-rtp, ssrc=(uint)1111",
65 "application/x-rtp, ssrc=(uint)1111, payload=(int)0");
66 }
67
68 GST_END_TEST;
69
GST_START_TEST(test_rtpptdemux_srccaps_from_sinkcaps_nossrc)70 GST_START_TEST (test_rtpptdemux_srccaps_from_sinkcaps_nossrc)
71 {
72 test_rtpptdemux_srccaps_from_sinkcaps_base ("application/x-rtp",
73 "application/x-rtp, payload=(int)0");
74 }
75
76 GST_END_TEST;
77
78 static GstCaps *
request_pt_map(G_GNUC_UNUSED GstElement * demux,G_GNUC_UNUSED guint pt,const gchar * caps)79 request_pt_map (G_GNUC_UNUSED GstElement * demux,
80 G_GNUC_UNUSED guint pt, const gchar * caps)
81 {
82 return gst_caps_from_string (caps);
83 }
84
85 static void
test_rtpptdemux_srccaps_from_signal_base(const gchar * srccaps,const gchar * sigcaps,const gchar * sinkcaps)86 test_rtpptdemux_srccaps_from_signal_base (const gchar * srccaps,
87 const gchar * sigcaps, const gchar * sinkcaps)
88 {
89 GstCaps *caps;
90 gchar *caps_str;
91 GstHarness *h = gst_harness_new_with_padnames ("rtpptdemux", "sink", NULL);
92
93 gst_harness_set_src_caps_str (h, srccaps);
94 g_signal_connect (h->element,
95 "new-payload-type", (GCallback) new_payload_type, &h);
96 g_signal_connect (h->element,
97 "request-pt-map", (GCallback) request_pt_map, (gpointer) sigcaps);
98 gst_harness_play (h);
99
100 gst_buffer_unref (gst_harness_push_and_pull (h,
101 gst_rtp_buffer_new_allocate (0, 0, 0)));
102
103 caps = gst_pad_get_current_caps (h->sinkpad);
104 caps_str = gst_caps_to_string (caps);
105 fail_unless_equals_string (caps_str, sinkcaps);
106
107 g_free (caps_str);
108 gst_caps_unref (caps);
109 gst_harness_teardown (h);
110 }
111
GST_START_TEST(test_rtpptdemux_srccaps_from_signal)112 GST_START_TEST (test_rtpptdemux_srccaps_from_signal)
113 {
114 test_rtpptdemux_srccaps_from_signal_base
115 ("application/x-rtp, ssrc=(uint)1111",
116 "application/x-rtp, encoding-name=(string)H264, media=(string)video, clock-rate=(int)90000",
117 "application/x-rtp, encoding-name=(string)H264, media=(string)video, clock-rate=(int)90000, payload=(int)0, ssrc=(uint)1111");
118 }
119
120 GST_END_TEST;
121
GST_START_TEST(test_rtpptdemux_srccaps_from_signal_nossrc)122 GST_START_TEST (test_rtpptdemux_srccaps_from_signal_nossrc)
123 {
124 test_rtpptdemux_srccaps_from_signal_base ("application/x-rtp",
125 "application/x-rtp, encoding-name=(string)H264, media=(string)video, clock-rate=(int)90000",
126 "application/x-rtp, encoding-name=(string)H264, media=(string)video, clock-rate=(int)90000, payload=(int)0");
127 }
128
129 GST_END_TEST;
130
131 static Suite *
rtpptdemux_suite(void)132 rtpptdemux_suite (void)
133 {
134 Suite *s = suite_create ("rtpptdemux");
135 TCase *tc_chain;
136
137 tc_chain = tcase_create ("general");
138 tcase_add_test (tc_chain, test_rtpptdemux_srccaps_from_sinkcaps);
139 tcase_add_test (tc_chain, test_rtpptdemux_srccaps_from_sinkcaps_nossrc);
140 tcase_add_test (tc_chain, test_rtpptdemux_srccaps_from_signal);
141 tcase_add_test (tc_chain, test_rtpptdemux_srccaps_from_signal_nossrc);
142 suite_add_tcase (s, tc_chain);
143
144 return s;
145 }
146
147 GST_CHECK_MAIN (rtpptdemux)
148