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 *out_cc_meta;
35 guint i;
36 guint8 empty_data[] = { 0x8c, 0x80, 0x80, 0x0, 0x80, 0x80 };
37 guint8 full_data[] = { 0x8c, 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, 525,
42 "interlace-mode", G_TYPE_STRING, "interleaved",
43 NULL);
44
45 h = gst_harness_new_parse
46 ("line21encoder remove-caption-meta=true ! line21decoder");
47 gst_harness_set_caps (h, gst_caps_ref (caps), gst_caps_ref (caps));
48
49 gst_video_info_from_caps (&info, caps);
50
51 gst_caps_unref (caps);
52
53 buf = gst_buffer_new_and_alloc (info.size);
54 outbuf = gst_harness_push_and_pull (h, buf);
55
56 fail_unless (outbuf != NULL);
57 fail_unless_equals_int (gst_buffer_get_n_meta (outbuf,
58 GST_VIDEO_CAPTION_META_API_TYPE), 1);
59
60 out_cc_meta = gst_buffer_get_video_caption_meta (outbuf);
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_equals_int (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
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 (out_cc_meta != NULL);
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
GST_START_TEST(remove_caption_meta)91 GST_START_TEST (remove_caption_meta)
92 {
93 GstHarness *h;
94 GstBuffer *buf, *outbuf;
95 GstVideoInfo info;
96 GstVideoCaptionMeta *out_cc_meta;
97 guint8 full_data[] = { 0x8c, 0x42, 0x43, 0x0, 0x44, 0x45 };
98 GstCaps *caps = gst_caps_new_simple ("video/x-raw",
99 "format", G_TYPE_STRING, "I420",
100 "width", G_TYPE_INT, 720,
101 "height", G_TYPE_INT, 525,
102 "interlace-mode", G_TYPE_STRING, "interleaved",
103 NULL);
104
105 h = gst_harness_new_parse ("line21encoder remove-caption-meta=true");
106 gst_harness_set_caps (h, gst_caps_ref (caps), gst_caps_ref (caps));
107
108 gst_video_info_from_caps (&info, caps);
109
110 gst_caps_unref (caps);
111
112 buf = gst_buffer_new_and_alloc (info.size);
113 gst_buffer_add_video_caption_meta (buf, GST_VIDEO_CAPTION_TYPE_CEA608_S334_1A,
114 full_data, 6);
115
116 outbuf = gst_harness_push_and_pull (h, buf);
117 fail_unless (outbuf != NULL);
118 fail_unless_equals_int (gst_buffer_get_n_meta (outbuf,
119 GST_VIDEO_CAPTION_META_API_TYPE), 0);
120
121 out_cc_meta = gst_buffer_get_video_caption_meta (outbuf);
122 fail_unless (out_cc_meta == NULL);
123
124 gst_buffer_unref (outbuf);
125 gst_harness_teardown (h);
126 }
127
128 GST_END_TEST;
129
130 static Suite *
line21_suite(void)131 line21_suite (void)
132 {
133 Suite *s = suite_create ("line21");
134 TCase *tc = tcase_create ("general");
135
136 suite_add_tcase (s, tc);
137
138 tcase_add_test (tc, basic);
139 tcase_add_test (tc, remove_caption_meta);
140
141 return s;
142 }
143
144 GST_CHECK_MAIN (line21);
145