1 /*
2 * GStreamer AVTP Plugin
3 * Copyright (C) 2019 Intel Corporation
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later
9 * version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301 USA
20 */
21
22 #include <avtp.h>
23 #include <avtp_aaf.h>
24 #include <gst/check/gstcheck.h>
25 #include <gst/check/gstharness.h>
26
27 static GstHarness *
setup_harness(void)28 setup_harness (void)
29 {
30 GstHarness *h;
31
32 h = gst_harness_new_parse
33 ("avtpaafpay streamid=0xDEADC0DEDEADC0DE mtt=1000000 tu=1000000 processing-deadline=1000000 timestamp-mode=normal");
34 gst_harness_set_src_caps_str (h,
35 "audio/x-raw,format=S16BE,rate=48000,channels=2,layout=interleaved");
36
37 return h;
38 }
39
GST_START_TEST(test_buffer)40 GST_START_TEST (test_buffer)
41 {
42 GstHarness *h;
43 GstBuffer *in, *out;
44 GstMapInfo info;
45 struct avtp_stream_pdu pdu = { 0 };
46 const int DATA_LEN = 4;
47
48 avtp_aaf_pdu_init (&pdu);
49 avtp_aaf_pdu_set (&pdu, AVTP_AAF_FIELD_TV, 1);
50 avtp_aaf_pdu_set (&pdu, AVTP_AAF_FIELD_STREAM_ID, 0xDEADC0DEDEADC0DE);
51 avtp_aaf_pdu_set (&pdu, AVTP_AAF_FIELD_FORMAT, AVTP_AAF_FORMAT_INT_16BIT);
52 avtp_aaf_pdu_set (&pdu, AVTP_AAF_FIELD_NSR, AVTP_AAF_PCM_NSR_48KHZ);
53 avtp_aaf_pdu_set (&pdu, AVTP_AAF_FIELD_CHAN_PER_FRAME, 2);
54 avtp_aaf_pdu_set (&pdu, AVTP_AAF_FIELD_BIT_DEPTH, 16);
55 avtp_aaf_pdu_set (&pdu, AVTP_AAF_FIELD_SP, AVTP_AAF_PCM_SP_NORMAL);
56 avtp_aaf_pdu_set (&pdu, AVTP_AAF_FIELD_TIMESTAMP, 4000000);
57 avtp_aaf_pdu_set (&pdu, AVTP_AAF_FIELD_STREAM_DATA_LEN, DATA_LEN);
58
59 h = setup_harness ();
60 in = gst_harness_create_buffer (h, DATA_LEN);
61 GST_BUFFER_PTS (in) = 1000000;
62 out = gst_harness_push_and_pull (h, in);
63
64 fail_unless (gst_buffer_get_size (out) ==
65 sizeof (struct avtp_stream_pdu) + DATA_LEN);
66 fail_unless (GST_BUFFER_PTS (in) == GST_BUFFER_PTS (out));
67 gst_buffer_map (out, &info, GST_MAP_READ);
68 fail_unless (memcmp (info.data, &pdu, sizeof (struct avtp_stream_pdu)) == 0);
69 gst_buffer_unmap (out, &info);
70
71 gst_buffer_unref (out);
72 gst_harness_teardown (h);
73 }
74
75 GST_END_TEST;
76
GST_START_TEST(test_properties)77 GST_START_TEST (test_properties)
78 {
79 GstHarness *h;
80 guint val_uint;
81 guint64 val_uint64;
82 GstElement *element;
83 const guint64 streamid = 0xAABBCCDDEEFF0001;
84 const guint64 processing_deadline = 20000000;
85 const guint tstamp_mode = 0;
86 const guint mtt = 11111111;
87 const guint tu = 22222222;
88
89 h = setup_harness ();
90 element = gst_harness_find_element (h, "avtpaafpay");
91
92 g_object_set (G_OBJECT (element), "streamid", streamid, NULL);
93 g_object_get (G_OBJECT (element), "streamid", &val_uint64, NULL);
94 fail_unless (val_uint64 == streamid);
95
96 g_object_set (G_OBJECT (element), "mtt", mtt, NULL);
97 g_object_get (G_OBJECT (element), "mtt", &val_uint, NULL);
98 fail_unless (val_uint == mtt);
99
100 g_object_set (G_OBJECT (element), "tu", tu, NULL);
101 g_object_get (G_OBJECT (element), "tu", &val_uint, NULL);
102 fail_unless (val_uint == tu);
103
104 g_object_set (G_OBJECT (element), "timestamp-mode", tstamp_mode, NULL);
105 g_object_get (G_OBJECT (element), "timestamp-mode", &val_uint, NULL);
106 fail_unless (val_uint == tstamp_mode);
107
108 g_object_set (G_OBJECT (element), "processing-deadline", processing_deadline,
109 NULL);
110 g_object_get (G_OBJECT (element), "processing-deadline", &val_uint64, NULL);
111 fail_unless (val_uint64 == processing_deadline);
112
113 gst_object_unref (element);
114 gst_harness_teardown (h);
115 }
116
117 GST_END_TEST;
118
119 static Suite *
avtpaafpay_suite(void)120 avtpaafpay_suite (void)
121 {
122 Suite *s = suite_create ("avtpaafpay");
123 TCase *tc_chain = tcase_create ("general");
124
125 suite_add_tcase (s, tc_chain);
126 tcase_add_test (tc_chain, test_buffer);
127 tcase_add_test (tc_chain, test_properties);
128
129 return s;
130 }
131
132 GST_CHECK_MAIN (avtpaafpay);
133