video-anc: Add DID16 value for SMPTE 2016-3 AFD/Bar data
[platform/upstream/gstreamer.git] / gst-libs / gst / video / video-anc.h
1 /* GStreamer
2  * Copyright (C) <2018> Edward Hervey <edward@centricular.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 Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19
20 #ifndef __GST_VIDEO_ANC_H__
21 #define __GST_VIDEO_ANC_H__
22
23 #include <gst/gst.h>
24 #include <gst/video/video-format.h>
25 #include <gst/video/video-info.h>
26
27 G_BEGIN_DECLS
28
29 typedef struct _GstVideoAncillary GstVideoAncillary;
30
31 /**
32  * GstVideoAncillary:
33  * @DID: The Data Identifier
34  * @SDID_block_number: The Secondary Data Identifier (if type 2) or the Data
35  *                     Block Number (if type 1)
36  * @data_count: The amount of data (in bytes) in @data (max 255 bytes)
37  * @data: (array length=data_count): The user data content of the Ancillary packet.
38  *    Does not contain the ADF, DID, SDID nor CS.
39  *
40  * Video Ancillary data, according to SMPTE-291M specification.
41  *
42  * Note that the contents of the data are always stored as 8bit data (i.e. do not contain
43  * the parity check bits).
44  *
45  * Since: 1.16
46  */
47 struct _GstVideoAncillary {
48   guint8 DID;
49   guint8 SDID_block_number;
50   guint8 data_count;
51   guint8 data[256];
52
53   /*< private >*/
54   /* Padding for future extension */
55   gpointer _gst_reserved[GST_PADDING];
56 };
57
58 typedef enum {
59   GST_VIDEO_ANCILLARY_DID_UNDEFINED = 0x00,
60   GST_VIDEO_ANCILLARY_DID_DELETION  = 0x80,
61   GST_VIDEO_ANCILLARY_DID_HANC_3G_AUDIO_DATA_FIRST = 0xa0,
62   GST_VIDEO_ANCILLARY_DID_HANC_3G_AUDIO_DATA_LAST = 0xa7,
63   GST_VIDEO_ANCILLARY_DID_HANC_HDTV_AUDIO_DATA_FIRST = 0xe0,
64   GST_VIDEO_ANCILLARY_DID_HANC_HDTV_AUDIO_DATA_LAST = 0xe7,
65   GST_VIDEO_ANCILLARY_DID_HANC_SDTV_AUDIO_DATA_1_FIRST = 0xec,
66   GST_VIDEO_ANCILLARY_DID_HANC_SDTV_AUDIO_DATA_1_LAST = 0xef,
67   GST_VIDEO_ANCILLARY_DID_CAMERA_POSITION = 0xf0,
68   GST_VIDEO_ANCILLARY_DID_HANC_ERROR_DETECTION = 0xf4,
69   GST_VIDEO_ANCILLARY_DID_HANC_SDTV_AUDIO_DATA_2_FIRST = 0xf8,
70   GST_VIDEO_ANCILLARY_DID_HANC_SDTV_AUDIO_DATA_2_LAST = 0xff,
71 } GstVideoAncillaryDID;
72
73 /**
74  * GST_VIDEO_ANCILLARY_DID16:
75  * @anc: a #GstVideoAncillary
76  *
77  * Returns the #GstVideoAncillaryDID16 of the ancillary data.
78  *
79  * Since: 1.16
80  *
81  * Returns: a #GstVideoAncillaryDID16 identifier
82  */
83 #define GST_VIDEO_ANCILLARY_DID16(anc) ((guint16)((anc)->DID) << 8 | (guint16)((anc)->SDID_block_number))
84
85 /**
86  * GstVideoAncillaryDID16:
87  * @GST_VIDEO_ANCILLARY_DID16_S334_EIA_708: CEA 708 Ancillary data according to SMPTE 334
88  * @GST_VIDEO_ANCILLARY_DID16_S334_EIA_608: CEA 608 Ancillary data according to SMPTE 334
89  * @GST_VIDEO_ANCILLARY_DID16_S2016_3_AFD_BAR: AFD/Bar Ancillary data according to SMPTE 2016-3 (Since: 1.18)
90  *
91  * Some know types of Ancillary Data identifiers.
92  *
93  * Since: 1.16
94  */
95 typedef enum {
96   GST_VIDEO_ANCILLARY_DID16_S334_EIA_708        = 0x6101,
97   GST_VIDEO_ANCILLARY_DID16_S334_EIA_608        = 0x6102,
98   GST_VIDEO_ANCILLARY_DID16_S2016_3_AFD_BAR     = 0x4105,
99 } GstVideoAncillaryDID16;
100
101 /* Closed Caption support */
102 /**
103  * GstVideoCaptionType:
104  * @GST_VIDEO_CAPTION_TYPE_UNKNOWN: Unknown type of CC
105  * @GST_VIDEO_CAPTION_TYPE_CEA608_RAW: CEA-608 as byte pairs. Note that
106  *      this format is not recommended since is does not specify to
107  *      which field the caption comes from and therefore assumes
108  *      it comes from the first field (and that there is no information
109  *      on the second field). Use @GST_VIDEO_CAPTION_TYPE_CEA708_RAW
110  *      if you wish to store CEA-608 from two fields and prefix each byte pair
111  *      with 0xFC for the first field and 0xFD for the second field.
112  * @GST_VIDEO_CAPTION_TYPE_CEA608_S334_1A: CEA-608 as byte triplets as defined
113  *      in SMPTE S334-1 Annex A. The second and third byte of the byte triplet
114  *      is the raw CEA608 data, the first byte is a bitfield: The top/7th bit is
115  *      0 for the second field, 1 for the first field, bit 6 and 5 are 0 and
116  *      bits 4 to 0 are a 5 bit unsigned integer that represents the line
117  *      offset relative to the base-line of the original image format (line 9
118  *      for 525-line field 1, line 272 for 525-line field 2, line 5 for
119  *      625-line field 1 and line 318 for 625-line field 2).
120  * @GST_VIDEO_CAPTION_TYPE_CEA708_RAW: CEA-708 as cc_data byte triplets. They
121  *      can also contain 608-in-708 and the first byte of each triplet has to
122  *      be inspected for detecting the type.
123  * @GST_VIDEO_CAPTION_TYPE_CEA708_CDP: CEA-708 (and optionally CEA-608) in
124  *      a CDP (Caption Distribution Packet) defined by SMPTE S-334-2.
125  *      Contains the whole CDP (starting with 0x9669).
126  *
127  * The various known types of Closed Caption (CC).
128  *
129  * Since: 1.16
130  */
131 typedef enum {
132   GST_VIDEO_CAPTION_TYPE_UNKNOWN                = 0,
133   GST_VIDEO_CAPTION_TYPE_CEA608_RAW             = 1,
134   GST_VIDEO_CAPTION_TYPE_CEA608_S334_1A         = 2,
135   GST_VIDEO_CAPTION_TYPE_CEA708_RAW             = 3,
136   GST_VIDEO_CAPTION_TYPE_CEA708_CDP             = 4
137 } GstVideoCaptionType;
138
139 GST_VIDEO_API
140 GstVideoCaptionType
141 gst_video_caption_type_from_caps (const GstCaps *caps);
142
143 GST_VIDEO_API
144 GstCaps *
145 gst_video_caption_type_to_caps (GstVideoCaptionType type);
146
147 /**
148  * GstVideoCaptionMeta:
149  * @meta: parent #GstMeta
150  * @caption_type: The type of Closed Caption contained in the meta.
151  * @data: (array length=size): The Closed Caption data.
152  * @size: The size in bytes of @data
153  *
154  * Extra buffer metadata providing Closed Caption.
155  *
156  * Since: 1.16
157  */
158 typedef struct {
159   GstMeta meta;
160
161   GstVideoCaptionType caption_type;
162   guint8 *data;
163   gsize size;
164 } GstVideoCaptionMeta;
165
166 GST_VIDEO_API
167 GType   gst_video_caption_meta_api_get_type (void);
168 #define GST_VIDEO_CAPTION_META_API_TYPE (gst_video_caption_meta_api_get_type())
169
170 GST_VIDEO_API
171 const GstMetaInfo *gst_video_caption_meta_get_info (void);
172 #define GST_VIDEO_CAPTION_META_INFO (gst_video_caption_meta_get_info())
173
174 /**
175  * gst_buffer_get_video_caption_meta:
176  * @b: A #GstBuffer
177  *
178  * Gets the #GstVideoCaptionMeta that might be present on @b.
179  *
180  * Since: 1.16
181  *
182  * Returns: The first #GstVideoCaptionMeta present on @b, or %NULL if
183  * no #GstVideoCaptionMeta are present
184  */
185 #define gst_buffer_get_video_caption_meta(b) \
186         ((GstVideoCaptionMeta*)gst_buffer_get_meta((b),GST_VIDEO_CAPTION_META_API_TYPE))
187
188 GST_VIDEO_API
189 GstVideoCaptionMeta *gst_buffer_add_video_caption_meta    (GstBuffer   * buffer,
190                                                            GstVideoCaptionType caption_type,
191                                                            const guint8 *data,
192                                                            gsize size);
193
194 /**
195  * GstVideoVBIParser:
196  *
197  * A parser for detecting and extracting @GstVideoAncillary data from
198  * Vertical Blanking Interval lines of component signals.
199  *
200  * Since: 1.16
201  */
202
203 typedef struct _GstVideoVBIParser GstVideoVBIParser;
204
205 GST_VIDEO_API
206 GType gst_video_vbi_parser_get_type (void);
207
208 /**
209  * GstVideoVBIParserResult:
210  * @GST_VIDEO_VBI_PARSER_RESULT_DONE: No line were provided, or no more Ancillary data was found.
211  * @GST_VIDEO_VBI_PARSER_RESULT_OK: A #GstVideoAncillary was found.
212  * @GST_VIDEO_VBI_PARSER_RESULT_ERROR: An error occured
213  *
214  * Return values for #GstVideoVBIParser
215  *
216  * Since: 1.16
217  */
218 typedef enum {
219   GST_VIDEO_VBI_PARSER_RESULT_DONE  = 0,
220   GST_VIDEO_VBI_PARSER_RESULT_OK    = 1,
221   GST_VIDEO_VBI_PARSER_RESULT_ERROR = 2
222 } GstVideoVBIParserResult;
223
224 GST_VIDEO_API
225 GstVideoVBIParserResult gst_video_vbi_parser_get_ancillary(GstVideoVBIParser *parser,
226                                                            GstVideoAncillary *anc);
227
228 GST_VIDEO_API
229 GstVideoVBIParser *gst_video_vbi_parser_new (GstVideoFormat format, guint32 pixel_width);
230
231 GST_VIDEO_API
232 GstVideoVBIParser *gst_video_vbi_parser_copy (const GstVideoVBIParser *parser);
233
234 GST_VIDEO_API
235 void               gst_video_vbi_parser_free (GstVideoVBIParser *parser);
236
237 GST_VIDEO_API
238 void               gst_video_vbi_parser_add_line (GstVideoVBIParser *parser, const guint8 *data);
239
240 /**
241  * GstVideoVBIEncoder:
242  *
243  * An encoder for writing ancillary data to the
244  * Vertical Blanking Interval lines of component signals.
245  *
246  * Since: 1.16
247  */
248
249 typedef struct _GstVideoVBIEncoder GstVideoVBIEncoder;
250
251 GST_VIDEO_API
252 GType gst_video_vbi_encoder_get_type (void);
253
254 GST_VIDEO_API
255 GstVideoVBIEncoder *gst_video_vbi_encoder_new  (GstVideoFormat format, guint32 pixel_width);
256
257 GST_VIDEO_API
258 GstVideoVBIEncoder *gst_video_vbi_encoder_copy (const GstVideoVBIEncoder *encoder);
259
260 GST_VIDEO_API
261 void               gst_video_vbi_encoder_free  (GstVideoVBIEncoder *encoder);
262
263 GST_VIDEO_API
264 gboolean gst_video_vbi_encoder_add_ancillary   (GstVideoVBIEncoder *encoder,
265                                                 gboolean            composite,
266                                                 guint8              DID,
267                                                 guint8              SDID_block_number,
268                                                 const guint8       *data,
269                                                 guint               data_count);
270
271 GST_VIDEO_API
272 void gst_video_vbi_encoder_write_line (GstVideoVBIEncoder *encoder, guint8 *data);
273
274 G_END_DECLS
275
276 #endif /* __GST_VIDEO_ANC_H__ */