• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "../../../ext/avtp/gstavtpcrfbase.h"
22 #include "../../../ext/avtp/gstavtpcrfutil.h"
23 
24 #include <avtp.h>
25 #include <avtp_aaf.h>
26 #include <avtp_cvf.h>
27 #include <glib.h>
28 #include <gst/check/gstcheck.h>
29 #include <gst/check/gstharness.h>
30 
GST_START_TEST(test_buffer_tstamp_valid)31 GST_START_TEST (test_buffer_tstamp_valid)
32 {
33   struct avtp_stream_pdu pdu = { 0, };
34   GstMapInfo info = { 0, };
35   gboolean result;
36 
37   info.data = (guint8 *) & pdu;
38 
39   avtp_pdu_set ((struct avtp_common_pdu *) &pdu, AVTP_FIELD_SUBTYPE,
40       AVTP_SUBTYPE_AAF);
41   info.size = 50;
42   result = buffer_size_valid (&info);
43   fail_unless (result == TRUE);
44 
45   avtp_pdu_set ((struct avtp_common_pdu *) &pdu, AVTP_FIELD_SUBTYPE,
46       AVTP_SUBTYPE_CVF);
47   avtp_cvf_pdu_set (&pdu, AVTP_CVF_FIELD_FORMAT_SUBTYPE,
48       AVTP_CVF_FORMAT_SUBTYPE_H264);
49   info.size = 55;
50   result = buffer_size_valid (&info);
51   fail_unless (result == TRUE);
52 
53   avtp_pdu_set ((struct avtp_common_pdu *) &pdu, AVTP_FIELD_SUBTYPE,
54       AVTP_SUBTYPE_AAF);
55   info.size = 15;
56   result = buffer_size_valid (&info);
57   fail_unless (result == FALSE);
58 
59   avtp_pdu_set ((struct avtp_common_pdu *) &pdu, AVTP_FIELD_SUBTYPE,
60       AVTP_SUBTYPE_CVF);
61   avtp_cvf_pdu_set (&pdu, AVTP_CVF_FIELD_FORMAT_SUBTYPE,
62       AVTP_CVF_FORMAT_SUBTYPE_H264);
63   info.size = 24;
64   result = buffer_size_valid (&info);
65   fail_unless (result == FALSE);
66 }
67 
68 GST_END_TEST;
69 
GST_START_TEST(test_get_avtp_tstamp)70 GST_START_TEST (test_get_avtp_tstamp)
71 {
72   GstAvtpCrfBase *avtpcrfbase = g_object_new (GST_TYPE_AVTP_CRF_BASE, NULL);
73   struct avtp_stream_pdu pdu;
74   GstClockTime tstamp;
75 
76   avtp_aaf_pdu_init (&pdu);
77   avtp_aaf_pdu_set (&pdu, AVTP_AAF_FIELD_TV, 1);
78   avtp_aaf_pdu_set (&pdu, AVTP_AAF_FIELD_TIMESTAMP, 12345);
79   tstamp = get_avtp_tstamp (avtpcrfbase, &pdu);
80   fail_unless_equals_uint64 (tstamp, 12345);
81 
82   avtp_aaf_pdu_set (&pdu, AVTP_AAF_FIELD_TV, 0);
83   tstamp = get_avtp_tstamp (avtpcrfbase, &pdu);
84   fail_unless_equals_uint64 (tstamp, GST_CLOCK_TIME_NONE);
85 
86   avtp_cvf_pdu_init (&pdu, AVTP_CVF_FORMAT_SUBTYPE_H264);
87   avtp_cvf_pdu_set (&pdu, AVTP_CVF_FIELD_TV, 1);
88   avtp_cvf_pdu_set (&pdu, AVTP_CVF_FIELD_TIMESTAMP, 43567);
89   tstamp = get_avtp_tstamp (avtpcrfbase, &pdu);
90   fail_unless_equals_uint64 (tstamp, 43567);
91 
92   avtp_cvf_pdu_set (&pdu, AVTP_CVF_FIELD_TV, 0);
93   tstamp = get_avtp_tstamp (avtpcrfbase, &pdu);
94   fail_unless_equals_uint64 (tstamp, GST_CLOCK_TIME_NONE);
95 
96   avtp_pdu_set ((struct avtp_common_pdu *) &pdu, AVTP_FIELD_SUBTYPE,
97       AVTP_SUBTYPE_TSCF);
98   tstamp = get_avtp_tstamp (avtpcrfbase, &pdu);
99   fail_unless_equals_uint64 (tstamp, GST_CLOCK_TIME_NONE);
100 
101   g_object_unref (avtpcrfbase);
102 }
103 
104 GST_END_TEST;
105 
GST_START_TEST(test_get_h264_tstamp)106 GST_START_TEST (test_get_h264_tstamp)
107 {
108   struct avtp_stream_pdu *pdu =
109       g_malloc0 (sizeof (struct avtp_stream_pdu) + sizeof (guint32));
110   gboolean tstamp_valid;
111 
112   avtp_cvf_pdu_init (pdu, AVTP_CVF_FORMAT_SUBTYPE_H264);
113   avtp_cvf_pdu_set (pdu, AVTP_CVF_FIELD_H264_PTV, 1);
114   avtp_cvf_pdu_set (pdu, AVTP_CVF_FIELD_H264_TIMESTAMP, 43567);
115   tstamp_valid = h264_tstamp_valid (pdu);
116   fail_unless (tstamp_valid == TRUE);
117 
118   avtp_cvf_pdu_set (pdu, AVTP_CVF_FIELD_H264_PTV, 0);
119   tstamp_valid = h264_tstamp_valid (pdu);
120   fail_unless (tstamp_valid == FALSE);
121 
122   avtp_cvf_pdu_init (pdu, AVTP_CVF_FORMAT_SUBTYPE_MJPEG);
123   avtp_cvf_pdu_set (pdu, AVTP_CVF_FIELD_H264_PTV, 1);
124   avtp_cvf_pdu_set (pdu, AVTP_CVF_FIELD_H264_TIMESTAMP, 43567);
125   tstamp_valid = h264_tstamp_valid (pdu);
126   fail_unless (tstamp_valid == FALSE);
127 
128   avtp_aaf_pdu_init (pdu);
129   tstamp_valid = h264_tstamp_valid (pdu);
130   fail_unless (tstamp_valid == FALSE);
131 
132   g_free (pdu);
133 }
134 
135 GST_END_TEST;
136 
137 static Suite *
avtpcrfutil_suite(void)138 avtpcrfutil_suite (void)
139 {
140   Suite *s = suite_create ("avtpcrfutil");
141   TCase *tc_chain = tcase_create ("general");
142 
143   suite_add_tcase (s, tc_chain);
144   tcase_add_test (tc_chain, test_buffer_tstamp_valid);
145   tcase_add_test (tc_chain, test_get_avtp_tstamp);
146   tcase_add_test (tc_chain, test_get_h264_tstamp);
147 
148   return s;
149 }
150 
151 GST_CHECK_MAIN (avtpcrfutil);
152