1 /* GStreamer RTP meta unit tests
2 * Copyright (C) 2016 Stian Selnes <stian@pexip.com>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General
15 * Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */
20
21 #include <gst/gst.h>
22 #include <gst/check/gstcheck.h>
23 #include <gst/rtp/rtp.h>
24
GST_START_TEST(test_rtp_source_meta_set_get_sources)25 GST_START_TEST (test_rtp_source_meta_set_get_sources)
26 {
27 GstBuffer *buffer;
28 GstRTPSourceMeta *meta;
29 gint i;
30 guint32 ssrc = 1000, ssrc2 = 2000;
31 const guint32 csrc[] = {
32 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
33 };
34
35 buffer = gst_buffer_new ();
36 meta = gst_buffer_add_rtp_source_meta (buffer, &ssrc, csrc, 12);
37
38 fail_unless_equals_int (gst_rtp_source_meta_get_source_count (meta), 12 + 1);
39 fail_unless (meta->ssrc_valid);
40 fail_unless_equals_int (meta->ssrc, ssrc);
41 for (i = 0; i < 12; i++)
42 fail_unless_equals_int (meta->csrc[i], csrc[i]);
43
44 /* Unset the ssrc */
45 fail_unless (gst_rtp_source_meta_set_ssrc (meta, NULL));
46 fail_unless_equals_int (gst_rtp_source_meta_get_source_count (meta), 12);
47 fail_if (meta->ssrc_valid);
48
49 /* Set the ssrc again */
50 fail_unless (gst_rtp_source_meta_set_ssrc (meta, &ssrc2));
51 fail_unless_equals_int (gst_rtp_source_meta_get_source_count (meta), 12 + 1);
52 fail_unless (meta->ssrc_valid);
53 fail_unless_equals_int (meta->ssrc, ssrc2);
54
55 /* Append multiple csrcs */
56 fail_unless (gst_rtp_source_meta_append_csrc (meta, &csrc[12], 2));
57 fail_unless_equals_int (gst_rtp_source_meta_get_source_count (meta), 14 + 1);
58 for (i = 0; i < 14; i++)
59 fail_unless_equals_int (meta->csrc[i], csrc[i]);
60
61 gst_buffer_unref (buffer);
62 }
63
64 GST_END_TEST;
65
GST_START_TEST(test_rtp_source_meta_set_get_max_sources)66 GST_START_TEST (test_rtp_source_meta_set_get_max_sources)
67 {
68 GstBuffer *buffer;
69 GstRTPSourceMeta *meta;
70 guint32 ssrc = 1000;
71 const guint32 csrc[16] = { 0, };
72
73 buffer = gst_buffer_new ();
74 meta = gst_buffer_add_rtp_source_meta (buffer, &ssrc, csrc, 14);
75
76 fail_unless_equals_int (gst_rtp_source_meta_get_source_count (meta), 14 + 1);
77 fail_unless_equals_int (meta->csrc_count, 14);
78 fail_unless (meta->ssrc_valid);
79 fail_unless_equals_int (meta->ssrc, ssrc);
80
81 /* Append one more csrc */
82 /* The source count should cap at 15 for convenient use with
83 * gst_rtp_buffer-functions! */
84 fail_unless (gst_rtp_source_meta_append_csrc (meta, &csrc[14], 1));
85 fail_unless_equals_int (gst_rtp_source_meta_get_source_count (meta), 15);
86 fail_unless_equals_int (meta->csrc_count, 15);
87
88 /* Try to append one more csrc, but we've reached max */
89 fail_if (gst_rtp_source_meta_append_csrc (meta, &csrc[15], 1));
90 fail_unless_equals_int (gst_rtp_source_meta_get_source_count (meta), 15);
91 fail_unless_equals_int (meta->csrc_count, 15);
92
93 gst_buffer_unref (buffer);
94 }
95
96 GST_END_TEST;
97
98 static Suite *
rtp_meta_suite(void)99 rtp_meta_suite (void)
100 {
101 Suite *s = suite_create ("rtp_meta_tests");
102 TCase *tc_chain;
103
104 suite_add_tcase (s, (tc_chain = tcase_create ("GstRTPSourceMeta")));
105 tcase_add_test (tc_chain, test_rtp_source_meta_set_get_sources);
106 tcase_add_test (tc_chain, test_rtp_source_meta_set_get_max_sources);
107
108 return s;
109 }
110
111 GST_CHECK_MAIN (rtp_meta)
112