• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * gstvp9parser.h
3  *
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>
8  *
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.
13  *
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.
18  *
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.
23  */
24 
25 #ifndef GST_VP9_PARSER_H
26 #define GST_VP9_PARSER_H
27 
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."
31 #endif
32 
33 #include <gst/gst.h>
34 #include <gst/codecparsers/codecparsers-prelude.h>
35 
36 G_BEGIN_DECLS
37 
38 #define GST_VP9_FRAME_MARKER 0x02
39 #define GST_VP9_SYNC_CODE 0x498342
40 #define GST_VP9_SUPERFRAME_MARKER 0x06
41 
42 #define GST_VP9_MAX_LOOP_FILTER    63
43 #define GST_VP9_MAX_PROB           255
44 
45 #define GST_VP9_REFS_PER_FRAME     3
46 #define GST_VP9_REF_FRAMES_LOG2    3
47 #define GST_VP9_REF_FRAMES         (1 << GST_VP9_REF_FRAMES_LOG2)
48 
49 #define GST_VP9_FRAME_CONTEXTS_LOG2 2
50 
51 #define GST_VP9_MAX_SHARPNESS      7
52 
53 #define GST_VP9_MAX_REF_LF_DELTAS  4
54 #define GST_VP9_MAX_MODE_LF_DELTAS 2
55 
56 #define GST_VP9_SEGMENT_DELTADATA  0
57 #define GST_VP9_SEGMENT_ABSDATA    1
58 
59 #define GST_VP9_MAX_SEGMENTS       8
60 #define GST_VP9_SEG_TREE_PROBS     (GST_VP9_MAX_SEGMENTS-1)
61 
62 #define GST_VP9_PREDICTION_PROBS   3
63 
64 #define GST_VP9_MAX_FRAMES_IN_SUPERFRAME 8
65 
66 typedef struct _GstVp9Parser               GstVp9Parser;
67 typedef struct _GstVp9FrameHdr             GstVp9FrameHdr;
68 typedef struct _GstVp9LoopFilter           GstVp9LoopFilter;
69 typedef struct _GstVp9QuantIndices         GstVp9QuantIndices;
70 typedef struct _GstVp9Segmentation         GstVp9Segmentation;
71 typedef struct _GstVp9SegmentationInfo     GstVp9SegmentationInfo;
72 typedef struct _GstVp9SegmentationInfoData GstVp9SegmentationInfoData;
73 typedef struct _GstVp9SuperframeInfo       GstVp9SuperframeInfo;
74 
75 /**
76  * GstVp9ParseResult:
77  * @GST_VP9_PARSER_OK: The parsing went well
78  * @GST_VP9_PARSER_BROKEN_DATA: The data to parse is broken
79  * @GST_VP9_PARSER_NO_PACKET_ERROR: An error occurred during the parsing
80  *
81  * Result type of any parsing function.
82  *
83  * Since: 1.8
84  */
85 typedef enum
86 {
87   GST_VP9_PARSER_OK,
88   GST_VP9_PARSER_BROKEN_DATA,
89   GST_VP9_PARSER_ERROR,
90 } GstVp9ParserResult;
91 
92 /**
93  * GstVp9Profile: Bitstream profiles indicated by 2-3 bits in the uncompressed header
94  * @GST_VP9_PROFILE_0: Profile 0, 8-bit 4:2:0 only.
95  * @GST_VP9_PROFILE_1: Profile 1, 8-bit 4:4:4, 4:2:2, and 4:4:0.
96  * @GST_VP9_PROFILE_2: Profile 2, 10-bit and 12-bit color only, with 4:2:0 sampling.
97  * @GST_VP9_PROFILE_3: Profile 3, 10-bit and 12-bit color only, with 4:2:2/4:4:4/4:4:0 sampling.
98  * @GST_VP9_PROFILE_UNDEFINED: Undefined profile
99  *
100  * VP9 Profiles
101  *
102  * Since: 1.8
103  */
104 typedef enum {
105   GST_VP9_PROFILE_0,
106   GST_VP9_PROFILE_1,
107   GST_VP9_PROFILE_2,
108   GST_VP9_PROFILE_3,
109   GST_VP9_PROFILE_UNDEFINED
110 } GstVP9Profile;
111 
112 /**
113  * GstVp9FrameType:
114  * @GST_VP9_KEY_FRAME: Key frame, only have intra blocks
115  * @GST_VP9_INTER_FRAME: Inter frame, both intra and inter blocks
116  *
117  * VP9 frame types
118  *
119  * Since: 1.8
120  */
121 typedef enum {
122   GST_VP9_KEY_FRAME   = 0,
123   GST_VP9_INTER_FRAME = 1
124 } GstVp9FrameType;
125 
126 /**
127  * GstVp9BitDepth:
128  * @GST_VP9_BIT_DEPTH_8: Bit depth is 8
129  * @GST_VP9_BIT_DEPTH_10 Bit depth is 10
130  * @GST_VP9_BIT_DEPTH_12:Bit depth is 12
131  *
132  * Bit depths of encoded frames
133  *
134  * Since: 1.8
135  */
136 typedef enum {
137   GST_VP9_BIT_DEPTH_8  = 8,
138   GST_VP9_BIT_DEPTH_10 = 10,
139   GST_VP9_BIT_DEPTH_12 = 12
140 } GstVp9BitDepth;
141 
142 /**
143  * GstVp9ColorSpace:
144  * @GST_VP9_CS_UNKNOWN: Unknown color space
145  * @GST_VP9_CS_BT_601: BT.601
146  * @GST_VP9_CS_BT_709: BT.709
147  * @GST_VP9_CS_SMPTE_170: SMPTE.170
148  * @GST_VP9_CS_SMPTE_240: SMPTE.240
149  * @GST_VP9_CS_BT_2020: BT.2020
150  * @GST_VP9_CS_RESERVED: Reserved
151  * @GST_VP9_CS_SRGB: sRGB
152  *
153  * Supported ColorSpace standards
154  *
155  * Since: 1.8
156  */
157 typedef enum {
158   GST_VP9_CS_UNKNOWN               = 0,
159   GST_VP9_CS_BT_601                = 1,
160   GST_VP9_CS_BT_709                = 2,
161   GST_VP9_CS_SMPTE_170             = 3,
162   GST_VP9_CS_SMPTE_240             = 4,
163   GST_VP9_CS_BT_2020               = 5,
164   GST_VP9_CS_RESERVED_2            = 6,
165   GST_VP9_CS_SRGB                  = 7
166 } GstVp9ColorSpace;
167 
168 /**
169  * GstVp9ColorRange:
170  * @GST_VP9_CR_LIMITED: Y range is [16-235], UV range is [16-240]
171  * @GST_VP9_CR_FULL: Full range for Y,U and V [0-255]
172  *
173  * Possible color value ranges
174  *
175  * Since: 1.8
176  */
177 typedef enum {
178   GST_VP9_CR_LIMITED,
179   GST_VP9_CR_FULL
180 } GstVp9ColorRange;
181 
182 /**
183  * GstVp9InterpolationFilter:
184  * @GST_VP9_INTERPOLATION_FILTER_EIGHTTAP: EightTap interpolation filter
185  * @GST_VP9_INTERPOLATION_FILTER_EIGHTTAP_SMOOTH: Smooth interpolation filter
186  * @GST_VP9_INTERPOLATION_FILTER_EIGHTTAP_SHARP: Shart interpolation filter
187  * @GST_VP9_INTERPOLATION_FILTER_BILINEAR: Bilinear interpolation filter
188  * @GST_VP9_INTERPOLATION_FILTER_SWITCHABLE: Selectable interpolation filter
189  *
190  * Interpolation Filters Types
191  *
192  * Since: 1.8
193  */
194 typedef enum {
195   GST_VP9_INTERPOLATION_FILTER_EIGHTTAP        = 0,
196   GST_VP9_INTERPOLATION_FILTER_EIGHTTAP_SMOOTH = 1,
197   GST_VP9_INTERPOLATION_FILTER_EIGHTTAP_SHARP  = 2,
198   GST_VP9_INTERPOLATION_FILTER_BILINEAR        = 3,
199   GST_VP9_INTERPOLATION_FILTER_SWITCHABLE      = 4
200 } GstVp9InterpolationFilter;
201 
202 /**
203  * GstVp9RefFrameType:
204  * @GST_VP9_REF_FRAME_INTRA: Intra reference frame
205  * @GST_VP9_REF_FRAME_LAST: Last Reference frame
206  * @GST_VP9_REF_FRAME_GOLDEN: Golden Reference frame
207  * @GST_VP9_REF_FRAME_ALTREF: Alternate Reference frame
208  * @GST_VP9_REF_FRAME_MAX:
209  *
210  * Reference Frame types
211  *
212  * Since: 1.8
213  */
214 typedef enum {
215   GST_VP9_REF_FRAME_INTRA  = 0,
216   GST_VP9_REF_FRAME_LAST   = 1,
217   GST_VP9_REF_FRAME_GOLDEN = 2,
218   GST_VP9_REF_FRAME_ALTREF = 3,
219   GST_VP9_REF_FRAME_MAX    = 4
220 } GstVp9RefFrameType;
221 
222 /**
223  * GstVp9QuantIndices:
224  * @y_ac_qi: indicates the dequantization table index used for the
225  *   luma AC coefficients
226  * @y_dc_delta: indicates the delta value that is added to the
227  *   baseline index to obtain the luma DC coefficient dequantization
228  *   index
229  * @uv_dc_delta: indicates the delta value that is added to the
230  *   baseline index to obtain the chroma DC coefficient dequantization
231  *   index
232  * @uv_ac_delta: indicates the delta value that is added to the
233  *   baseline index to obtain the chroma AC coefficient dequantization
234  *   index
235  *
236  * Dequantization indices.
237  *
238  * Since: 1.8
239  */
240 struct _GstVp9QuantIndices
241 {
242   guint8 y_ac_qi;
243   gint8 y_dc_delta;
244   gint8 uv_dc_delta;
245   gint8 uv_ac_delta;
246 };
247 
248 /**
249  * GstVp9LoopFilter:
250  * @filter_level: indicates loop filter level for the current frame
251  * @sharpness_level: indicates sharpness level for thecurrent frame
252  * @mode_ref_delta_enabled: indicate if filter adjust is on
253  * @mode_ref_delta_update: indicates if the delta values used in an
254  *   adjustment are updated in the current frame
255  * @update_ref_deltas: indicate which ref deltas are updated
256  * @ref_deltas:  Loop filter strength adjustments based on
257  *  frame type (intra, inter)
258  * @update_mode_deltas: indicate with mode deltas are updated
259  * @mode_deltas: Loop filter strength adjustments based on
260  *   mode (zero, new mv)
261  *
262  * Loop filter values
263  *
264  * Since: 1.8
265  */
266 struct _GstVp9LoopFilter {
267   gint filter_level;
268   gint sharpness_level;
269 
270   guint8 mode_ref_delta_enabled;
271   guint8 mode_ref_delta_update;
272   guint8 update_ref_deltas[GST_VP9_MAX_REF_LF_DELTAS];
273   gint8 ref_deltas[GST_VP9_MAX_REF_LF_DELTAS];
274   guint8 update_mode_deltas[GST_VP9_MAX_MODE_LF_DELTAS];
275   gint8 mode_deltas[GST_VP9_MAX_MODE_LF_DELTAS];
276 };
277 
278 /**
279  * GstVp9SegmentationInfoData:
280  * @alternate_quantizer_enabled: indicate alternate quantizer enabled at segment level
281  * @alternate_quantizer: alternate quantizer value
282  * @alternate_loop_filter_enabled: indicate alternate loop filter enabled at segment level
283  * @alternate_loop_filter: alternate loop filter
284  * @reference_frame_enabled: indicate alternate reference frame at segment level
285  * @reference_frame: alternate reference frame
286  * @reference_skip: a block skip mode that implies both the use of a (0,0)
287  *   motion vector and that no residual will be coded.
288  *
289  * Segmentation info for each segment
290  *
291  * Since: 1.8
292  */
293 struct _GstVp9SegmentationInfoData {
294   /* SEG_LVL_ALT_Q */
295   guint8 alternate_quantizer_enabled;
296   gint16 alternate_quantizer;
297 
298   /* SEG_LVL_ALT_LF */
299   guint8 alternate_loop_filter_enabled;
300   gint8 alternate_loop_filter;
301 
302   /* SEG_LVL_REF_FRAME */
303   guint8 reference_frame_enabled;
304   gint reference_frame;
305 
306   guint8 reference_skip;
307 };
308 
309 /**
310  * GstVp9SegmentationInfo:
311  * @enabled: enables the segmentation feature for the current frame
312  * @update_map: determines if segmentation is updated in the current frame
313  * @update_tree_probs: determines if tree probabilities updated or not
314  * @tree_probs: segment tree probabilities
315  * @update_pred_probs:determines if prediction probabilities updated or not
316  * @pred_probs: prediction probabilities
317  * @abs_delta: interpretation of segment data values
318  * @temporal_update: type of map update
319  * @update_data: indicates if the segment feature data
320  *   is updated in the current frame
321  * @data: segment feature data
322  *
323  * Segmentation info
324  *
325  * Since: 1.8
326  */
327 struct _GstVp9SegmentationInfo {
328   /* enable in setup_segmentation*/
329   guint8  enabled;
330   /* update_map in setup_segmentation*/
331   guint8 update_map;
332   /* tree_probs exist or not*/
333   guint8 update_tree_probs[GST_VP9_SEG_TREE_PROBS];
334   guint8 tree_probs[GST_VP9_SEG_TREE_PROBS];
335   /* pred_probs exist or not*/
336   guint8 update_pred_probs[GST_VP9_PREDICTION_PROBS];
337   guint8 pred_probs[GST_VP9_PREDICTION_PROBS];
338 
339   /* abs_delta in setup_segmentation */
340   guint8 abs_delta;
341   /* temporal_update in setup_segmentation */
342   guint8 temporal_update;
343 
344   /* update_data in setup_segmentation*/
345   guint8 update_data;
346   GstVp9SegmentationInfoData data[GST_VP9_MAX_SEGMENTS];
347 };
348 
349 /**
350  * GstVp9FrameHdr:
351  * @profile: encoded profile
352  * @show_existing_frame: display already decoded frame instead of doing the decoding
353  * @frame_to_show: which frame to show if show_existing_frame is true
354  * @frame_type: frame type
355  * @show_frame: indicate whether it is a displayable frame or not
356  * @error_resilient_mode: error resilent mode
357  * @width: frame width
358  * @height: frame height
359  * @display_size_enabled: display size enabled (cropping)
360  * @display_width: display width
361  * @display_height: display height
362  * @frame_context_idx: frame context index
363  * @intra_only: intra only frame
364  * @reset_frame_context: reset frame context
365  * @refresh_frame_flags: refresh reference frame flags
366  * @ref_frame_indices: reference frame index
367  * @ref_frame_sign_bias: sign bias for selecting altref,last and golden frames
368  * @allow_high_precision_mv: allow hight precision motion vector
369  * @mcomp_filter_type: interpolation filter type
370  * @refresh_frame_context: refresh frame context indicator
371  * @frame_parallel_decoding_mode: enable or disable parallel decoding support.
372  * @loopfilter: loopfilter values
373  * @quant_indices: quantization indices
374  * @segmentation: segmentation info
375  * @log2_tile_rows: tile row indicator
376  * @log2_tile_columns:  tile column indicator
377  * @first_partition_size: first partition size (after the uncompressed header)
378  * @lossless_flag: lossless mode decode
379  * @frame_header_length_in_bytes: length of uncompressed header
380  *
381  * Frame header
382  *
383  * Since: 1.8
384  */
385 struct _GstVp9FrameHdr
386 {
387   guint profile;
388   guint8 show_existing_frame;
389   gint  frame_to_show;
390   guint frame_type;
391   guint8 show_frame;
392   guint8 error_resilient_mode;
393   guint32 width;
394   guint32 height;
395   guint8 display_size_enabled;
396   guint32 display_width;
397   guint32 display_height;
398   guint frame_context_idx;
399 
400   guint8 intra_only;
401   gint reset_frame_context;
402   gint refresh_frame_flags;
403 
404   gint ref_frame_indices[GST_VP9_REFS_PER_FRAME];
405   gint ref_frame_sign_bias[GST_VP9_REFS_PER_FRAME];
406   gint allow_high_precision_mv;
407   guint8 mcomp_filter_type;
408 
409   gint refresh_frame_context;
410   /* frame_parallel_decoding_mode in vp9 code*/
411   gint frame_parallel_decoding_mode;
412 
413   GstVp9LoopFilter loopfilter;
414   GstVp9QuantIndices quant_indices;
415   GstVp9SegmentationInfo segmentation;
416 
417   gint log2_tile_rows;
418   gint log2_tile_columns;
419 
420   guint32 first_partition_size;
421 
422   /* calculated values */
423   guint lossless_flag;
424   guint32 frame_header_length_in_bytes;
425 };
426 
427 /**
428  * GstVp9SuperframeInfo:
429  * @bytes_per_framesize: indicates the number of bytes needed to code each frame size
430  * @frames_in_superframe: indicates the number of frames within this superframe
431  * @frame_sizes: specifies the size in bytes of frame number i (zero indexed) within this superframe
432  * @superframe_index_size: indicates the total size of the superframe_index
433  *
434  * Superframe info
435  *
436  * Since: 1.18
437  */
438 struct _GstVp9SuperframeInfo {
439   guint32 bytes_per_framesize;
440   guint32 frames_in_superframe;
441   guint32 frame_sizes[GST_VP9_MAX_FRAMES_IN_SUPERFRAME];
442   guint32 superframe_index_size;
443 };
444 
445 /**
446  * GstVp9Segmentation:
447  * @filter_level: loop filter level
448  * @luma_ac_quant_scale: AC quant scale for luma(Y) component
449  * @luma_dc_quant_scale: DC quant scale for luma(Y) component
450  * @chroma_ac_quant_scale AC quant scale for chroma(U/V) component
451  * @chroma_dc_quant_scale: DC quant scale for chroma (U/V) component
452  * @reference_frame_enabled: alternate reference frame enablement
453  * @reference_frame: alternate reference frame
454  * @reference_skip:  a block skip mode that implies both the use of a (0,0)
455  *   motion vector and that no residual will be coded
456  *
457  * Segmentation info kept across multiple frames
458  *
459  * Since: 1.8
460  */
461 struct _GstVp9Segmentation
462 {
463   guint8 filter_level[GST_VP9_MAX_REF_LF_DELTAS][GST_VP9_MAX_MODE_LF_DELTAS];
464   gint16 luma_ac_quant_scale;
465   gint16 luma_dc_quant_scale;
466   gint16 chroma_ac_quant_scale;
467   gint16 chroma_dc_quant_scale;
468 
469   guint8 reference_frame_enabled;
470   gint reference_frame;
471 
472   guint8 reference_skip;
473 };
474 
475 /**
476  * GstVp9Parser:
477  * @priv: GstVp9ParserPrivate struct to keep track of state variables
478  * @subsampling_x: horizontal subsampling
479  * @subsampling_y: vertical subsampling
480  * @bit_depth: bit depth of the stream
481  * @color_space: color space standard
482  * @color_range: color range standard
483  * @mb_segment_tree_probs: decoding tree probabilities
484  * @segment_pred_probs: segment prediction probabiilties
485  * @segmentation: Segmentation info
486  *
487  * Parser context that needs to be live across frames
488  *
489  * Since: 1.8
490  */
491 struct _GstVp9Parser
492 {
493   /* private struct for tracking state variables across frames */
494   void *priv;
495 
496   gint subsampling_x;
497   gint subsampling_y;
498   guint bit_depth;
499   guint color_space;
500   guint color_range;
501 
502   guint8 mb_segment_tree_probs[GST_VP9_SEG_TREE_PROBS];
503   guint8 segment_pred_probs[GST_VP9_PREDICTION_PROBS];
504   GstVp9Segmentation segmentation[GST_VP9_MAX_SEGMENTS];
505 };
506 
507 GST_CODEC_PARSERS_API
508 GstVp9Parser *     gst_vp9_parser_new (void);
509 
510 GST_CODEC_PARSERS_API
511 GstVp9ParserResult gst_vp9_parser_parse_frame_header (GstVp9Parser* parser, GstVp9FrameHdr * frame_hdr, const guint8 * data, gsize size);
512 
513 GST_CODEC_PARSERS_API
514 GstVp9ParserResult gst_vp9_parser_parse_superframe_info (GstVp9Parser* parser, GstVp9SuperframeInfo * superframe_info, const guint8 * data, gsize size);
515 
516 GST_CODEC_PARSERS_API
517 void               gst_vp9_parser_free (GstVp9Parser * parser);
518 
519 G_END_DECLS
520 
521 #endif /* GST_VP9_PARSER_H */
522