1 /* 2 * gstvp8parser.h - VP8 parser 3 * 4 * Copyright (C) 2013-2014 Intel Corporation 5 * Author: Halley Zhao <halley.zhao@intel.com> 6 * Author: Gwenole Beauchesne <gwenole.beauchesne@intel.com> 7 * 8 * This library is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU Library General Public 10 * License as published by the Free Software Foundation; either 11 * version 2 of the License, or (at your option) any later version. 12 * 13 * This library is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * Library General Public License for more details. 17 * 18 * You should have received a copy of the GNU Library General Public 19 * License along with this library; if not, write to the 20 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 21 * Boston, MA 02110-1301, USA. 22 */ 23 24 #ifndef GST_VP8_PARSER_H 25 #define GST_VP8_PARSER_H 26 27 #include <gst/gst.h> 28 #include <gst/codecparsers/codecparsers-prelude.h> 29 30 #ifndef GST_USE_UNSTABLE_API 31 #warning "The VP8 parsing library is unstable API and may change in future." 32 #warning "You can define GST_USE_UNSTABLE_API to avoid this warning." 33 #endif 34 35 G_BEGIN_DECLS 36 37 typedef struct _GstVp8FrameHdr GstVp8FrameHdr; 38 typedef struct _GstVp8QuantIndices GstVp8QuantIndices; 39 typedef struct _GstVp8Segmentation GstVp8Segmentation; 40 typedef struct _GstVp8MbLfAdjustments GstVp8MbLfAdjustments; 41 typedef struct _GstVp8TokenProbs GstVp8TokenProbs; 42 typedef struct _GstVp8MvProbs GstVp8MvProbs; 43 typedef struct _GstVp8ModeProbs GstVp8ModeProbs; 44 typedef struct _GstVp8Parser GstVp8Parser; 45 46 /** 47 * GstVp8ParserResult: 48 * @GST_VP8_PARSER_OK: The parsing succeeded 49 * @GST_VP8_PARSER_BROKEN_DATA: The data to parse is broken 50 * @GST_VP8_PARSER_ERROR: An error accured when parsing 51 * 52 * The result of parsing VP8 data. 53 */ 54 typedef enum { 55 GST_VP8_PARSER_OK, 56 GST_VP8_PARSER_BROKEN_DATA, 57 GST_VP8_PARSER_ERROR, 58 } GstVp8ParserResult; 59 60 /** 61 * GstVpQuantIndices: 62 * @y_ac_qi: indicates the dequantization table index used for the 63 * luma AC coefficients 64 * @y_dc_delta: indicates the delta value that is added to the 65 * baseline index to obtain the luma DC coefficient dequantization 66 * index 67 * @y2_dc_delta: indicates the delta value that is added to the 68 * baseline index to obtain the Y2 block DC coefficient dequantization 69 * index 70 * @y2_ac_delta: indicates the delta value that is added to the 71 * baseline index to obtain the Y2 block AC coefficient dequantization 72 * index 73 * @uv_dc_delta: indicates the delta value that is added to the 74 * baseline index to obtain the chroma DC coefficient dequantization 75 * index 76 * @uv_ac_delta: indicates the delta value that is added to the 77 * baseline index to obtain the chroma AC coefficient dequantization 78 * index 79 * 80 * Dequantization indices. 81 */ 82 struct _GstVp8QuantIndices 83 { 84 guint8 y_ac_qi; 85 gint8 y_dc_delta; 86 gint8 y2_dc_delta; 87 gint8 y2_ac_delta; 88 gint8 uv_dc_delta; 89 gint8 uv_ac_delta; 90 }; 91 92 /** 93 * GstVp8Segmentation: 94 * @segmentation_enabled: enables the segmentation feature for the 95 * current frame 96 * @update_mb_segmentation_map: determines if the MB segmentation map 97 * is updated in the current frame 98 * @update_segment_feature_data: indicates if the segment feature data 99 * is updated in the current frame 100 * @segment_feature_mode: indicates the feature data update mode (0: 101 * delta, 1: absolute value) 102 * @quantizer_update_value: indicates the update value for the segment 103 * quantizer 104 * @lf_update_value: indicates the update value for the loop filter level 105 * @segment_prob: indicates the branch probabilities of the segment_id 106 * decoding tree 107 * 108 * Segmentation feature data. 109 */ 110 struct _GstVp8Segmentation 111 { 112 guint8 segmentation_enabled; 113 guint8 update_mb_segmentation_map; 114 guint8 update_segment_feature_data; 115 116 /* if update_segment_feature_data == 1 */ 117 guint8 segment_feature_mode; 118 gint8 quantizer_update_value[4]; 119 gint8 lf_update_value[4]; 120 121 /* if update_mb_segmentation_map == 1 */ 122 guint8 segment_prob[3]; 123 }; 124 125 /** 126 * GstVp8MbLfAdjustments: 127 * @loop_filter_adj_enable: indicates if the MB-level loop filter 128 * adjustment is on for the current frame 129 * @mode_ref_lf_delta_update: indicates if the delta values used in an 130 * adjustment are updated in the current frame 131 * @ref_frame_delta: indicates the adjustment delta value 132 * corresponding to a certain used reference frame 133 * @mb_mode_delta: indicates the adjustment delta value corresponding 134 * to a certain MB prediction mode 135 * 136 * MB-level loop filter adjustments. 137 */ 138 struct _GstVp8MbLfAdjustments 139 { 140 guint8 loop_filter_adj_enable; 141 guint8 mode_ref_lf_delta_update; 142 143 /* if mode_ref_lf_delta_update == 1 */ 144 gint8 ref_frame_delta[4]; 145 gint8 mb_mode_delta[4]; 146 }; 147 148 /** 149 * GstVp8TokenProbs: 150 * @prob: token probability 151 * 152 * Token probabilities, with cumulative updates applied. 153 * 154 * Each probability value in this matrix is live across frames, until 155 * they are reset to their default values on key frame. 156 */ 157 struct _GstVp8TokenProbs 158 { 159 guint8 prob[4][8][3][11]; 160 }; 161 162 /** 163 * GstVp8MvProbs: 164 * @prob: MV probability 165 * 166 * Probabilities used for motion vector decoding, with cumulative 167 * updates applied. 168 * 169 * Each probability value in this matrix is live across frames, until 170 * they are reset to their default values on key frame. 171 */ 172 struct _GstVp8MvProbs 173 { 174 guint8 prob[2][19]; 175 }; 176 177 /** 178 * GstVp8ModeProbs: 179 * @y_prob: indicates the branch probabilities of the luma 180 * intra-prediction mode decoding tree 181 * @uv_prob: indicates the branch probabilities of the chroma 182 * intra-prediction mode decoding tree 183 * 184 * Probabilities used for intra-prediction mode decoding tree. 185 * 186 * Each probability value in thie structure is live across frames, 187 * until they are reset to their default values on key frame. 188 */ 189 struct _GstVp8ModeProbs 190 { 191 guint8 y_prob[4]; 192 guint8 uv_prob[3]; 193 }; 194 195 /** 196 * GstVp8FrameHdr: 197 * @key_frame: indicates whether the frame is a key frame (1), or an 198 * inter frame (0) 199 * @version: version number 200 * @show_frame: indicates whether the frame is meant to be displayed (1), 201 * or not (0) 202 * @data_chunk_size: the size in bytes of the Uncompressed Data Chunk 203 * @first_part_size: the size in bytes of the first partition (control 204 * partition), excluding the uncompressed data chunk 205 * @width: the frame width in pixels 206 * @height: the frame height in pixels 207 * @horiz_scale_code: horizontal scale code value 208 * @vert_scale_code: vertical scale code value 209 * @color_space: defines the YUV color space of the sequence 210 * @clamping_type: specifies if the decoder is required to clamp the 211 * reconstructed pixel values 212 * @filter_type: determines whether the normal or the simple loop 213 * filter is used 214 * @loop_filter_level: controls the deblocking filter 215 * @sharpness_level: controls the deblocking filter 216 * @log2_nbr_of_dct_partitions: determines the number of separate 217 * partitions containing the DCT coefficients of the macroblocks 218 * @partition_size: determines the size of each separate partition 219 * containing the DCT coefficients of the macroblocks, including the 220 * very last one (calculated size) 221 * @quant_indices: dequantization indices (see #GstVp8QuantIndices) 222 * @token_probs: token probabilities (see #GstVp8TokenProbs) 223 * @mv_probs: probabilities used for motion vector decoding 224 * (see #GstVp8MvProbs) 225 * @mode_probs: probabilities used for intra-prediction mode decoding 226 * tree (see #GstVp8ModeProbs) 227 * @refresh_entropy_probs: determines whether updated token 228 * probabilities are used only for this frame or until further update 229 * @refresh_golden_frame: determines if the current decoded frame 230 * refreshes the golden frame 231 * @refresh_alternate_frame: determines if the current decoded frame 232 * refreshes the alternate reference frame 233 * @copy_buffer_to_golden: determines if the golden reference is 234 * replaced by another reference 235 * @copy_buffer_to_alternate: determines if the alternate reference is 236 * replaced by another reference 237 * @sign_bias_golden: controls the sign of motion vectors when the 238 * golden frame is referenced 239 * @sign_bias_alternate: controls the sign of motion vectors when the 240 * alternate frame is referenced 241 * @refresh_last: determines if the current decoded frame refreshes 242 * the last frame reference buffer 243 * @mb_no_skip_coeff: enables (0) or disables (1) the skipping of 244 * macroblocks containing no non-zero coefficients 245 * @prob_skip_false: indicates the probability that the macroblock is 246 * not skipped 247 * @prob_intra: indicates the probability of an intra macroblock 248 * @prob_last: indicates the probability that the last reference frame 249 * is used for inter-prediction 250 * @prob_gf: indicates the probability that the golden reference frame 251 * is used for inter-prediction 252 * @rd_range: last range decoder value for "Range" 253 * @rd_value: last range decoder value for "Value" 254 * @rd_count: number of bits left in range decoder "Value" (@rd_value) 255 * @header_size: the size in bits of the Frame Header, thus excluding 256 * any Uncompressed Data Chunk bytes 257 * 258 * Frame header. 259 */ 260 struct _GstVp8FrameHdr 261 { 262 guint8 key_frame; 263 guint8 version; 264 guint8 show_frame; 265 guint8 data_chunk_size; 266 guint32 first_part_size; 267 268 /* if key_frame == 1 */ 269 guint16 width; 270 guint16 height; 271 guint8 horiz_scale_code; 272 guint8 vert_scale_code; 273 guint8 color_space; 274 guint8 clamping_type; 275 276 guint8 filter_type; 277 guint8 loop_filter_level; 278 guint8 sharpness_level; 279 guint8 log2_nbr_of_dct_partitions; 280 guint partition_size[8]; 281 282 GstVp8QuantIndices quant_indices; 283 GstVp8TokenProbs token_probs; 284 GstVp8MvProbs mv_probs; 285 GstVp8ModeProbs mode_probs; 286 287 guint8 refresh_entropy_probs; 288 guint8 refresh_last; 289 /* if key_frame != 1 */ 290 guint8 refresh_golden_frame; 291 guint8 refresh_alternate_frame; 292 guint8 copy_buffer_to_golden; 293 guint8 copy_buffer_to_alternate; 294 guint8 sign_bias_golden; 295 guint8 sign_bias_alternate; 296 297 guint8 mb_no_skip_coeff; 298 guint8 prob_skip_false; 299 300 /* if key_frame != 1 */ 301 guint8 prob_intra; 302 guint8 prob_last; 303 guint8 prob_gf; 304 305 /* Range decoder state */ 306 guint8 rd_range; 307 guint8 rd_value; 308 guint8 rd_count; 309 310 /* Size of the Frame Header in bits */ 311 guint header_size; 312 }; 313 314 /** 315 * GstVp8Parser: 316 * @segmentation: segmentation feature data 317 * @mb_lf_adjust: MB-level loop filter adjustments 318 * @token_probs: token probabilities 319 * @mv_probs: probabilities used for motion vector decoding 320 * @mode_probs: probabilities used for intra-prediction mode decoding tree. 321 * 322 * Parser context that needs to be live across frames. For instance 323 * the probabilities tables stored in #GstVp8FrameHdr may depend on 324 * the previous frames. 325 */ 326 struct _GstVp8Parser 327 { 328 GstVp8Segmentation segmentation; 329 GstVp8MbLfAdjustments mb_lf_adjust; 330 GstVp8TokenProbs token_probs; 331 GstVp8MvProbs mv_probs; 332 GstVp8ModeProbs mode_probs; 333 }; 334 335 GST_CODEC_PARSERS_API 336 void gst_vp8_parser_init (GstVp8Parser * parser); 337 338 GST_CODEC_PARSERS_API 339 GstVp8ParserResult gst_vp8_parser_parse_frame_header (GstVp8Parser * parser, 340 GstVp8FrameHdr * frame_hdr, 341 const guint8 * data, 342 gsize size); 343 344 G_END_DECLS 345 346 #endif /* GST_VP8_PARSER_H */ 347