1 /* GStreamer 2 * Copyright (C) <2019> Aaron Boxer <aaron.boxer@collabora.com> 3 * Copyright (C) <2019> Collabora Ltd. 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 #ifndef __VIDEO_PARSE_UTILS_H__ 22 #define __VIDEO_PARSE_UTILS_H__ 23 24 #include <gst/gst.h> 25 #include <gst/base/gstbaseparse.h> 26 #include <gst/base/gstbytereader.h> 27 #include <gst/video/video-anc.h> 28 29 #define GST_VIDEO_BAR_MAX_BYTES 9 30 31 /* A53-4 Table 6.7 */ 32 #define A53_USER_DATA_ID_GA94 0x47413934 33 #define A53_USER_DATA_ID_DTG1 0x44544731 34 35 /* custom id for SCTE 20 608 */ 36 #define USER_DATA_ID_SCTE_20_CC 0xFFFFFFFE 37 /* custom id for DirecTV */ 38 #define USER_DATA_ID_DIRECTV_CC 0xFFFFFFFF 39 40 /* A53-4 Table 6.9 */ 41 #define A53_USER_DATA_TYPE_CODE_CC_DATA 0x03 42 #define A53_USER_DATA_TYPE_CODE_BAR_DATA 0x06 43 /* ANSI/SCTE 21 Additional EIA 608 Data 44 * https://www.scte.org/documents/pdf/Standards/ANSISCTE212001R2006.pdf*/ 45 #define A53_USER_DATA_TYPE_CODE_SCTE_21_EIA_608_CC_DATA 0x04 46 47 /* CEA-708 Table 2 */ 48 #define CEA_708_PROCESS_CC_DATA_FLAG 0x40 49 #define CEA_708_PROCESS_EM_DATA_FLAG 0x80 50 51 /* country codes */ 52 #define ITU_T_T35_COUNTRY_CODE_US 0xB5 53 54 /* provider codes */ 55 #define ITU_T_T35_MANUFACTURER_US_ATSC 0x31 56 #define ITU_T_T35_MANUFACTURER_US_DIRECTV 0x2F 57 58 /* 59 * GstVideoAFDAspectRatio: 60 * @GST_VIDEO_AFD_ASPECT_RATIO_UNDEFINED: aspect ratio is undefined 61 * @GST_VIDEO_AFD_ASPECT_RATIO_4_3: 4:3 aspect ratio 62 * @GST_VIDEO_AFD_ASPECT_RATIO_16_9: 16:9 aspect ratio 63 * 64 * Enumeration of the different AFD aspect ratios (SMPTE ST2016-1 only) 65 */ 66 typedef enum { 67 GST_VIDEO_AFD_ASPECT_RATIO_UNDEFINED, 68 GST_VIDEO_AFD_ASPECT_RATIO_4_3, 69 GST_VIDEO_AFD_ASPECT_RATIO_16_9 70 } GstVideoAFDAspectRatio; 71 72 /* 73 * GstVideoParseUtilsField: 74 * @GST_VIDEO_PARSE_UTILS_FIELD_1 progressive or field 1 75 * @GST_VIDEO_PARSE_UTILS_FIELD_2 field 2 76 * 77 * Enumeration of fields 78 */ 79 typedef enum { 80 GST_VIDEO_PARSE_UTILS_FIELD_1, 81 GST_VIDEO_PARSE_UTILS_FIELD_2 82 } GstVideoParseUtilsField; 83 84 /* 85 * GstVideoAFD: 86 * @field: #GstVideoParseUtilsField for @afd 87 * @aspect_ratio: #GstVideoAFDAspectRatio for frame 88 * @spec: #GstVideoAFDSpec that applies to @afd 89 * @afd: #GstVideoAFDValue AFD value 90 * 91 * Active Format Description (AFD) 92 * 93 * For details, see Table 6.14 Active Format in: 94 * 95 * ATSC Digital Television Standard: 96 * Part 4 – MPEG-2 Video System Characteristics 97 * 98 * https://www.atsc.org/wp-content/uploads/2015/03/a_53-Part-4-2009.pdf 99 * 100 * and Active Format Description in Complete list of AFD codes 101 * 102 * https://en.wikipedia.org/wiki/Active_Format_Description#Complete_list_of_AFD_codes 103 * 104 * and SMPTE ST2016-1 105 */ 106 typedef struct { 107 GstVideoParseUtilsField field; 108 GstVideoAFDAspectRatio aspect_ratio; 109 GstVideoAFDSpec spec; 110 GstVideoAFDValue afd; 111 } GstVideoAFD; 112 113 /* 114 * GstVideoBarData: 115 * @field: GstVideoParseUtilsField for bar data 116 * @is_letterbox: if true then bar data specifies letterbox, otherwise pillarbox 117 * @bar_data: An array of size 2. if @is_letterbox is true, then two values specify 118 * last line of a horizontal letterbox bar area at top of reconstructed frame 119 * and first line of a horizontal letterbox bar area at bottom of reconstructed frame 120 * otherwise, two values specify 121 * last horizontal luminance sample of a vertical pillarbox bar area at the left side 122 * of the reconstructed frame, and first horizontal luminance sample of a vertical pillarbox 123 * bar area at the right side of the reconstructed frame 124 * 125 * Bar data should be included in video user data 126 * whenever the rectangular picture area containing useful information 127 * does not extend to the full height or width of the coded frame 128 * and AFD alone is insufficient to describe the extent of the image. 129 * 130 * Note: either vertical or horizontal bars are specified, but not both. 131 * 132 * For more details, see: 133 * 134 * https://www.atsc.org/wp-content/uploads/2015/03/a_53-Part-4-2009.pdf 135 * 136 * and SMPTE ST2016-1 137 */ 138 typedef struct { 139 GstVideoParseUtilsField field; 140 gboolean is_letterbox; 141 guint bar_data[2]; 142 } GstVideoBarData; 143 144 /* 145 * GstVideoParseUserData 146 * 147 * Holds unparsed and parsed user data for closed captions, AFD and Bar data. 148 */ 149 typedef struct 150 { 151 GstVideoParseUtilsField field; 152 153 /* pending closed captions */ 154 guint8 closedcaptions[96]; 155 guint closedcaptions_size; 156 GstVideoCaptionType closedcaptions_type; 157 158 /* pending bar data */ 159 guint8 bar_data[GST_VIDEO_BAR_MAX_BYTES]; 160 guint bar_data_size; 161 gboolean has_bar_data; 162 163 /* parsed bar data */ 164 GstVideoBarData bar_parsed; 165 166 /* pending AFD data */ 167 guint8 afd; 168 gboolean active_format_flag; 169 GstVideoAFDSpec afd_spec; 170 gboolean has_afd; 171 172 /* parsed afd data */ 173 GstVideoAFD afd_parsed; 174 175 } GstVideoParseUserData; 176 177 G_BEGIN_DECLS 178 179 void gst_video_parse_user_data(GstElement * elt, GstVideoParseUserData * user_data, 180 GstByteReader * br, guint8 field, guint16 provider_code); 181 182 void gst_video_push_user_data(GstElement * elt, GstVideoParseUserData * user_data, 183 GstBuffer * buf); 184 185 G_END_DECLS 186 #endif /* __VIDEO_PARSE_UTILS_H__ */ 187