4 * Copyright (C) 2013-2014 Intel Corporation
5 * Copyright (C) 2015 Intel Corporation
6 * Author: XuGuangxin<Guangxin.Xu@intel.com>
7 * Author: Sreerenj Balachandran<sreerenj.balachandran@intel.com>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
19 * You should have received a copy of the GNU Library General Public
20 * License along with this library; if not, write to the
21 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
22 * Boston, MA 02110-1301, USA.
25 #ifndef GST_VP9_PARSER_H
26 #define GST_VP9_PARSER_H
28 #ifndef GST_USE_UNSTABLE_API
29 #warning "The VP9 parsing library is unstable API and may change in future."
30 #warning "You can define GST_USE_UNSTABLE_API to avoid this warning."
34 #include <gst/codecparsers/codecparsers-prelude.h>
38 #define GST_VP9_FRAME_MARKER 0x02
39 #define GST_VP9_SYNC_CODE 0x498342
41 #define GST_VP9_MAX_LOOP_FILTER 63
42 #define GST_VP9_MAX_PROB 255
44 #define GST_VP9_REFS_PER_FRAME 3
45 #define GST_VP9_REF_FRAMES_LOG2 3
46 #define GST_VP9_REF_FRAMES (1 << GST_VP9_REF_FRAMES_LOG2)
48 #define GST_VP9_FRAME_CONTEXTS_LOG2 2
50 #define GST_VP9_MAX_LOOP_FILTER 63
51 #define GST_VP9_MAX_SHARPNESS 7
53 #define GST_VP9_MAX_REF_LF_DELTAS 4
54 #define GST_VP9_MAX_MODE_LF_DELTAS 2
56 #define GST_VP9_SEGMENT_DELTADATA 0
57 #define GST_VP9_SEGMENT_ABSDATA 1
59 #define GST_VP9_MAX_SEGMENTS 8
60 #define GST_VP9_SEG_TREE_PROBS (GST_VP9_MAX_SEGMENTS-1)
62 #define GST_VP9_PREDICTION_PROBS 3
64 typedef struct _GstVp9Parser GstVp9Parser;
65 typedef struct _GstVp9FrameHdr GstVp9FrameHdr;
66 typedef struct _GstVp9LoopFilter GstVp9LoopFilter;
67 typedef struct _GstVp9QuantIndices GstVp9QuantIndices;
68 typedef struct _GstVp9Segmentation GstVp9Segmentation;
69 typedef struct _GstVp9SegmentationInfo GstVp9SegmentationInfo;
70 typedef struct _GstVp9SegmentationInfoData GstVp9SegmentationInfoData;
74 * @GST_VP9_PARSER_OK: The parsing went well
75 * @GST_VP9_PARSER_BROKEN_DATA: The data to parse is broken
76 * @GST_VP9_PARSER_NO_PACKET_ERROR: An error occured during the parsing
78 * Result type of any parsing function.
85 GST_VP9_PARSER_BROKEN_DATA,
90 * GstVp9Profile: Bitstream profiles indicated by 2-3 bits in the uncompressed header
91 * @GST_VP9_PROFILE_0: Profile 0, 8-bit 4:2:0 only.
92 * @GST_VP9_PROFILE_1: Profile 1, 8-bit 4:4:4, 4:2:2, and 4:4:0.
93 * @GST_VP9_PROFILE_2: Profile 2, 10-bit and 12-bit color only, with 4:2:0 sampling.
94 * @GST_VP9_PROFILE_3: Profile 3, 10-bit and 12-bit color only, with 4:2:2/4:4:4/4:4:0 sampling.
95 * @GST_VP9_PROFILE_UNDEFINED: Undefined profile
106 GST_VP9_PROFILE_UNDEFINED
111 * @GST_VP9_KEY_FRAME: Key frame, only have intra blocks
112 * @GST_VP9_INTER_FRAME: Inter frame, both intra and inter blocks
119 GST_VP9_KEY_FRAME = 0,
120 GST_VP9_INTER_FRAME = 1
125 * @GST_VP9_BIT_DEPTH_8: Bit depth is 8
126 * @GST_VP9_BIT_DEPTH_10 Bit depth is 10
127 * @GST_VP9_BIT_DEPTH_12:Bit depth is 12
129 * Bit depths of encoded frames
134 GST_VP9_BIT_DEPTH_8 = 8,
135 GST_VP9_BIT_DEPTH_10 = 10,
136 GST_VP9_BIT_DEPTH_12 = 12
141 * @GST_VP9_CS_UNKNOWN: Unknown color space
142 * @GST_VP9_CS_BT_601: BT.601
143 * @GST_VP9_CS_BT_709: BT.709
144 * @GST_VP9_CS_SMPTE_170: SMPTE.170
145 * @GST_VP9_CS_SMPTE_240: SMPTE.240
146 * @GST_VP9_CS_BT_2020: BT.2020
147 * @GST_VP9_CS_RESERVED: Reserved
148 * @GST_VP9_CS_SRGB: sRGB
150 * Supported ColorSpace standards
155 GST_VP9_CS_UNKNOWN = 0,
156 GST_VP9_CS_BT_601 = 1,
157 GST_VP9_CS_BT_709 = 2,
158 GST_VP9_CS_SMPTE_170 = 3,
159 GST_VP9_CS_SMPTE_240 = 4,
160 GST_VP9_CS_BT_2020 = 5,
161 GST_VP9_CS_RESERVED_2 = 6,
167 * @GST_VP9_CR_LIMITED: Y range is [16-235], UV range is [16-240]
168 * @GST_VP9_CR_FULL: Full range for Y,U and V [0-255]
170 * Possible color value ranges
180 * GstVp9InterpolationFilter:
181 * @GST_VP9_INTERPOLATION_FILTER_EIGHTTAP: EightTap interpolation filter
182 * @GST_VP9_INTERPOLATION_FILTER_EIGHTTAP_SMOOTH: Smooth interpolation filter
183 * @GST_VP9_INTERPOLATION_FILTER_EIGHTTAP_SHARP: Shart interpolation filter
184 * @GST_VP9_INTERPOLATION_FILTER_BILINEAR: Bilinear interpolation filter
185 * @GST_VP9_INTERPOLATION_FILTER_SWITCHABLE: Selectable interpolation filter
187 * Interpolation Filters Types
192 GST_VP9_INTERPOLATION_FILTER_EIGHTTAP = 0,
193 GST_VP9_INTERPOLATION_FILTER_EIGHTTAP_SMOOTH = 1,
194 GST_VP9_INTERPOLATION_FILTER_EIGHTTAP_SHARP = 2,
195 GST_VP9_INTERPOLATION_FILTER_BILINEAR = 3,
196 GST_VP9_INTERPOLATION_FILTER_SWITCHABLE = 4
197 } GstVp9InterpolationFilter;
200 * GstVp9RefFrameType:
201 * @GST_VP9_REF_FRAME_INTRA: Intra reference frame
202 * @GST_VP9_REF_FRAME_LAST: Last Reference frame
203 * @GST_VP9_REF_FRAME_GOLDEN: Golden Reference frame
204 * @GST_VP9_REF_FRAME_ALTREF: Alternate Reference frame
205 * @GST_VP9_REF_FRAME_MAX:
207 * Reference Frame types
212 GST_VP9_REF_FRAME_INTRA = 0,
213 GST_VP9_REF_FRAME_LAST = 1,
214 GST_VP9_REF_FRAME_GOLDEN = 2,
215 GST_VP9_REF_FRAME_ALTREF = 3,
216 GST_VP9_REF_FRAME_MAX = 4
217 } GstVp9RefFrameType;
220 * GstVp9QuantIndices:
221 * @y_ac_qi: indicates the dequantization table index used for the
222 * luma AC coefficients
223 * @y_dc_delta: indicates the delta value that is added to the
224 * baseline index to obtain the luma DC coefficient dequantization
226 * @uv_dc_delta: indicates the delta value that is added to the
227 * baseline index to obtain the chroma DC coefficient dequantization
229 * @uv_ac_delta: indicates the delta value that is added to the
230 * baseline index to obtain the chroma AC coefficient dequantization
233 * Dequantization indices.
237 struct _GstVp9QuantIndices
247 * @filter_level: indicates loop filter level for the current frame
248 * @sharpness_level: indicates sharpness level for thecurrent frame
249 * @mode_ref_delta_enabled: indicate if filter adjust is on
250 * @mode_ref_delta_update: indicates if the delta values used in an
251 * adjustment are updated in the current frame
252 * @update_ref_deltas: indicate which ref deltas are updated
253 * @ref_deltas: Loop filter strength adjustments based on
254 * frame type (intra, inter)
255 * @update_mode_deltas: indicate with mode deltas are updated
256 * @mode_deltas: Loop filter strength adjustments based on
257 * mode (zero, new mv)
263 struct _GstVp9LoopFilter {
265 gint sharpness_level;
267 guint8 mode_ref_delta_enabled;
268 guint8 mode_ref_delta_update;
269 guint8 update_ref_deltas[GST_VP9_MAX_REF_LF_DELTAS];
270 gint8 ref_deltas[GST_VP9_MAX_REF_LF_DELTAS];
271 guint8 update_mode_deltas[GST_VP9_MAX_MODE_LF_DELTAS];
272 gint8 mode_deltas[GST_VP9_MAX_MODE_LF_DELTAS];
276 * GstVp9SegmentationInfoData:
277 * @alternate_quantizer_enabled: indicate alternate quantizer enabled at segment level
278 * @alternate_quantizer: alternate quantizer value
279 * @alternate_loop_filter_enabled: indicate alternate loop filter enabled at segment level
280 * @alternate_loop_filter: alternate loop filter
281 * @reference_frame_enabled: indicate alternate reference frame at segment level
282 * @reference_frame: alternate reference frame
283 * @reference_skip: a block skip mode that implies both the use of a (0,0)
284 * motion vector and that no residual will be coded.
286 * Segmentation info for each segment
290 struct _GstVp9SegmentationInfoData {
292 guint8 alternate_quantizer_enabled;
293 gint16 alternate_quantizer;
296 guint8 alternate_loop_filter_enabled;
297 gint8 alternate_loop_filter;
299 /* SEG_LVL_REF_FRAME */
300 guint8 reference_frame_enabled;
301 gint reference_frame;
303 guint8 reference_skip;
307 * GstVp9SegmentationInfo:
308 * @enabled: enables the segmentation feature for the current frame
309 * @update_map: determines if segmentation is updated in the current frame
310 * @update_tree_probs: determines if tree probabilities updated or not
311 * @tree_probs: segment tree probabilities
312 * @update_pred_probs:determines if prediction probabilities updated or not
313 * @pred_probs: prediction probabilities
314 * @abs_delta: interpretation of segment data values
315 * @temporal_update: type of map update
316 * @update_data: indicates if the segment feature data
317 * is updated in the current frame
318 * @data: segment feature data
324 struct _GstVp9SegmentationInfo {
325 /* enable in setup_segmentation*/
327 /* update_map in setup_segmentation*/
329 /* tree_probs exist or not*/
330 guint8 update_tree_probs[GST_VP9_SEG_TREE_PROBS];
331 guint8 tree_probs[GST_VP9_SEG_TREE_PROBS];
332 /* pred_probs exist or not*/
333 guint8 update_pred_probs[GST_VP9_PREDICTION_PROBS];
334 guint8 pred_probs[GST_VP9_PREDICTION_PROBS];
336 /* abs_delta in setup_segmentation */
338 /* temporal_update in setup_segmentation */
339 guint8 temporal_update;
341 /* update_data in setup_segmentation*/
343 GstVp9SegmentationInfoData data[GST_VP9_MAX_SEGMENTS];
348 * @profile: encoded profile
349 * @show_existing_frame: display already decoded frame instead of doing the decoding
350 * @frame_to_show: which frame to show if show_existing_frame is true
351 * @frame_type: frame type
352 * @show_frame: indicate whether it is a displayable frame or not
353 * @error_resilient_mode: error resilent mode
354 * @width: frame width
355 * @height: frame height
356 * @display_size_enabled: display size enabled (cropping)
357 * @display_width: display width
358 * @display_height: display height
359 * @frame_context_idx: frame context index
360 * @intra_only: intra only frame
361 * @reset_frame_context: reset frame context
362 * @refresh_frame_flags: refresh reference frame flags
363 * @ref_frame_indices: reference frame index
364 * @ref_frame_sign_bias: sign bias for selecting altref,last and golden frames
365 * @allow_high_precision_mv: allow hight precision motion vector
366 * @mcomp_filter_type: interpolation filter type
367 * @refresh_frame_context: refresh frame context indicator
368 * @frame_parallel_decoding_mode: enable or disable parallel decoding support.
369 * @loopfilter: loopfilter values
370 * @quant_indices: quantization indeces
371 * @segmentation: segmentation info
372 * @log2_tile_rows: tile row indicator
373 * @log2_tile_columns: tile column indicator
374 * @first_partition_size: first partition size (after the uncompressed header)
375 * @lossless_flag: lossless mode decode
376 * @frame_header_length_in_bytes: length of uncompressed header
382 struct _GstVp9FrameHdr
385 guint8 show_existing_frame;
389 guint8 error_resilient_mode;
392 guint8 display_size_enabled;
393 guint32 display_width;
394 guint32 display_height;
395 guint frame_context_idx;
398 gint reset_frame_context;
399 gint refresh_frame_flags;
401 gint ref_frame_indices[GST_VP9_REFS_PER_FRAME];
402 gint ref_frame_sign_bias[GST_VP9_REFS_PER_FRAME];
403 gint allow_high_precision_mv;
404 guint8 mcomp_filter_type;
406 gint refresh_frame_context;
407 /* frame_parallel_decoding_mode in vp9 code*/
408 gint frame_parallel_decoding_mode;
410 GstVp9LoopFilter loopfilter;
411 GstVp9QuantIndices quant_indices;
412 GstVp9SegmentationInfo segmentation;
415 gint log2_tile_columns;
417 guint32 first_partition_size;
419 /* calculated values */
421 guint32 frame_header_length_in_bytes;
425 * GstVp9Segmentation:
426 * @filter_level: loop filter level
427 * @luma_ac_quant_scale: AC quant scale for luma(Y) component
428 * @luma_dc_quant_scale: DC quant scale for luma(Y) component
429 * @chroma_ac_quant_scale AC quant scale for chroma(U/V) component
430 * @chroma_dc_quant_scale: DC quant scale for chroma (U/V) component
431 * @reference_frame_enabled: alternate reference frame enablement
432 * @reference_frame: alternate reference frame
433 * @reference_skip: a block skip mode that implies both the use of a (0,0)
434 * motion vector and that no residual will be coded
436 * Segmentation info kept across multipe frames
440 struct _GstVp9Segmentation
442 guint8 filter_level[4][2];
443 gint16 luma_ac_quant_scale;
444 gint16 luma_dc_quant_scale;
445 gint16 chroma_ac_quant_scale;
446 gint16 chroma_dc_quant_scale;
448 guint8 reference_frame_enabled;
449 gint reference_frame;
451 guint8 reference_skip;
456 * @priv: GstVp9ParserPrivate struct to keep track of state variables
457 * @subsampling_x: horizontal subsampling
458 * @subsampling_y: vertical subsampling
459 * @bit_depth: bit depth of the stream
460 * @color_space: color space standard
461 * @color_range: color range standard
462 * @mb_segment_tree_probs: decoding tree probabilities
463 * @segment_pred_probs: segment prediction probabiilties
464 * @segmentation: Segmentation info
466 * Parser context that needs to be live across frames
472 /* private stuct for tracking state variables across frames */
481 guint8 mb_segment_tree_probs[GST_VP9_SEG_TREE_PROBS];
482 guint8 segment_pred_probs[GST_VP9_PREDICTION_PROBS];
483 GstVp9Segmentation segmentation[GST_VP9_MAX_SEGMENTS];
486 GST_CODEC_PARSERS_API
487 GstVp9Parser * gst_vp9_parser_new (void);
489 GST_CODEC_PARSERS_API
490 GstVp9ParserResult gst_vp9_parser_parse_frame_header (GstVp9Parser* parser, GstVp9FrameHdr * frame_hdr, const guint8 * data, gsize size);
492 GST_CODEC_PARSERS_API
493 void gst_vp9_parser_free (GstVp9Parser * parser);
497 #endif /* GST_VP9_PARSER_H */