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