1 /* GStreamer
2 *
3 * Copyright (C) 2019 Mathieu Duponchelle <mathieu@centricular.com>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General 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 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24 #include <gst/gst.h>
25 #include <gst/check/gstcheck.h>
26 #include <gst/check/gstharness.h>
27 #include <gst/video/video.h>
28
GST_START_TEST(basic)29 GST_START_TEST (basic)
30 {
31 GstHarness *h;
32 GstBuffer *buf, *outbuf;
33 GstVideoInfo info;
34 GstVideoCaptionMeta *in_cc_meta, *out_cc_meta;
35 guint i;
36 guint8 empty_data[] = { 0x90, 0x80, 0x80, 0x0, 0x80, 0x80 };
37 guint8 full_data[] = { 0x90, 0x42, 0x43, 0x0, 0x44, 0x45 };
38 GstCaps *caps = gst_caps_new_simple ("video/x-raw",
39 "format", G_TYPE_STRING, "I420",
40 "width", G_TYPE_INT, 720,
41 "height", G_TYPE_INT, 625,
42 "interlace-mode", G_TYPE_STRING, "interleaved",
43 NULL);
44
45 h = gst_harness_new_parse ("line21encoder ! line21decoder");
46 gst_harness_set_caps (h, gst_caps_ref (caps), gst_caps_ref (caps));
47
48 gst_video_info_from_caps (&info, caps);
49
50 gst_caps_unref (caps);
51
52 buf = gst_buffer_new_and_alloc (info.size);
53 outbuf = gst_harness_push_and_pull (h, buf);
54
55 fail_unless (outbuf != NULL);
56 fail_unless_equals_int (gst_buffer_get_n_meta (outbuf,
57 GST_VIDEO_CAPTION_META_API_TYPE), 1);
58
59 out_cc_meta = gst_buffer_get_video_caption_meta (outbuf);
60
61 fail_unless (out_cc_meta != NULL);
62 fail_unless (out_cc_meta->size == 6);
63
64 for (i = 0; i < out_cc_meta->size; i++)
65 fail_unless (out_cc_meta->data[i] == empty_data[i]);
66
67 gst_buffer_unref (outbuf);
68
69 buf = gst_buffer_new_and_alloc (info.size);
70 gst_buffer_add_video_caption_meta (buf, GST_VIDEO_CAPTION_TYPE_CEA608_S334_1A,
71 full_data, 6);
72 in_cc_meta = gst_buffer_get_video_caption_meta (buf);
73 outbuf = gst_harness_push_and_pull (h, buf);
74
75 fail_unless (outbuf != NULL);
76 fail_unless_equals_int (gst_buffer_get_n_meta (outbuf,
77 GST_VIDEO_CAPTION_META_API_TYPE), 1);
78
79 out_cc_meta = gst_buffer_get_video_caption_meta (outbuf);
80 fail_unless (in_cc_meta != out_cc_meta);
81
82 for (i = 0; i < out_cc_meta->size; i++)
83 fail_unless (out_cc_meta->data[i] == full_data[i]);
84
85 gst_buffer_unref (outbuf);
86 gst_harness_teardown (h);
87 }
88
89 GST_END_TEST;
90
91 static Suite *
line21_suite(void)92 line21_suite (void)
93 {
94 Suite *s = suite_create ("line21");
95 TCase *tc = tcase_create ("general");
96
97 suite_add_tcase (s, tc);
98
99 tcase_add_test (tc, basic);
100
101 return s;
102 }
103
104 GST_CHECK_MAIN (line21);
105