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