2 * Copyright (C) <2011> Intel
3 * Copyright (C) <2011> Collabora Ltd.
4 * Copyright (C) <2011> Thibault Saunier <thibault.saunier@collabora.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
22 #ifndef __GST_VC1_PARSER_H__
23 #define __GST_VC1_PARSER_H__
25 #ifndef GST_USE_UNSTABLE_API
26 #warning "The VC1 parsing library is unstable API and may change in future."
27 #warning "You can define GST_USE_UNSTABLE_API to avoid this warning."
34 #define MAX_HRD_NUM_LEAKY_BUCKETS 31
37 * @GST_VC1_BFRACTION_BASIS: The @bfraction variable should be divided
38 * by this constant to have the actual value.
40 #define GST_VC1_BFRACTION_BASIS 840
42 #define GST_VC1_BFRACTION_RESERVED (GST_VC1_BFRACTION_BASIS + 1)
43 #define GST_VC1_BFRACTION_PTYPE_BI (GST_VC1_BFRACTION_BASIS + 2)
46 GST_VC1_END_OF_SEQ = 0x0A,
50 GST_VC1_ENTRYPOINT = 0x0E,
51 GST_VC1_SEQUENCE = 0x0F,
52 GST_VC1_SLICE_USER = 0x1B,
53 GST_VC1_FIELD_USER = 0x1C,
54 GST_VC1_FRAME_USER = 0x1D,
55 GST_VC1_ENTRY_POINT_USER = 0x1E,
56 GST_VC1_SEQUENCE_USER = 0x1F
60 GST_VC1_PROFILE_SIMPLE,
62 GST_VC1_PROFILE_RESERVED,
63 GST_VC1_PROFILE_ADVANCED
68 GST_VC1_PARSER_BROKEN_DATA,
69 GST_VC1_PARSER_NO_BDU,
70 GST_VC1_PARSER_NO_BDU_END,
76 GST_VC1_PICTURE_TYPE_P,
77 GST_VC1_PICTURE_TYPE_B,
78 GST_VC1_PICTURE_TYPE_I,
79 GST_VC1_PICTURE_TYPE_BI,
80 GST_VC1_PICTURE_TYPE_SKIPPED
85 GST_VC1_LEVEL_LOW = 0, /* Simple/Main profile low level */
86 GST_VC1_LEVEL_MEDIUM = 1, /* Simple/Main profile medium level */
87 GST_VC1_LEVEL_HIGH = 2, /* Main profile high level */
89 GST_VC1_LEVEL_L0 = 0, /* Advanced profile level 0 */
90 GST_VC1_LEVEL_L1 = 1, /* Advanced profile level 1 */
91 GST_VC1_LEVEL_L2 = 2, /* Advanced profile level 2 */
92 GST_VC1_LEVEL_L3 = 3, /* Advanced profile level 3 */
93 GST_VC1_LEVEL_L4 = 4, /* Advanced profile level 4 */
96 GST_VC1_LEVEL_UNKNOWN = 255 /* Unknown profile */
101 GST_VC1_QUANTIZER_IMPLICITLY,
102 GST_VC1_QUANTIZER_EXPLICITLY,
103 GST_VC1_QUANTIZER_NON_UNIFORM,
104 GST_VC1_QUANTIZER_UNIFORM
105 } GstVC1QuantizerSpec;
108 GST_VC1_DQPROFILE_FOUR_EDGES,
109 GST_VC1_DQPROFILE_DOUBLE_EDGES,
110 GST_VC1_DQPROFILE_SINGLE_EDGE,
111 GST_VC1_DQPROFILE_ALL_MBS
115 GST_VC1_CONDOVER_NONE,
116 GST_VC1_CONDOVER_ALL,
117 GST_VC1_CONDOVER_SELECT
126 GST_VC1_MVMODE_1MV_HPEL_BILINEAR,
128 GST_VC1_MVMODE_1MV_HPEL,
129 GST_VC1_MVMODE_MIXED_MV,
130 GST_VC1_MVMODE_INTENSITY_COMP
135 GST_VC1_FRAME_PROGRESSIVE = 0x0,
136 GST_VC1_FRAME_INTERLACE = 0x10,
137 GST_VC1_FIELD_INTERLACE = 0x11
138 } GstVC1FrameCodingMode;
140 typedef struct _GstVC1SeqHdr GstVC1SeqHdr;
141 typedef struct _GstVC1AdvancedSeqHdr GstVC1AdvancedSeqHdr;
142 typedef struct _GstVC1HrdParam GstVC1HrdParam;
143 typedef struct _GstVC1EntryPointHdr GstVC1EntryPointHdr;
145 typedef struct _GstVC1SeqLayer GstVC1SeqLayer;
147 typedef struct _GstVC1SeqStructA GstVC1SeqStructA;
148 typedef struct _GstVC1SeqStructB GstVC1SeqStructB;
149 typedef struct _GstVC1SeqStructC GstVC1SeqStructC;
151 /* Pictures Structures */
152 typedef struct _GstVC1FrameLayer GstVC1FrameLayer;
153 typedef struct _GstVC1FrameHdr GstVC1FrameHdr;
154 typedef struct _GstVC1PicAdvanced GstVC1PicAdvanced;
155 typedef struct _GstVC1PicSimpleMain GstVC1PicSimpleMain;
156 typedef struct _GstVC1Picture GstVC1Picture;
158 typedef struct _GstVC1VopDquant GstVC1VopDquant;
160 typedef struct _GstVC1BitPlanes GstVC1BitPlanes;
162 typedef struct _GstVC1BDU GstVC1BDU;
164 struct _GstVC1HrdParam
166 guint8 hrd_num_leaky_buckets;
167 guint8 bit_rate_exponent;
168 guint8 buffer_size_exponent;
169 guint16 hrd_rate[MAX_HRD_NUM_LEAKY_BUCKETS];
170 guint16 hrd_buffer[MAX_HRD_NUM_LEAKY_BUCKETS];
174 * GstVC1EntryPointHdr:
176 * Structure for entrypoint header, this will be used only in advanced profiles
178 struct _GstVC1EntryPointHdr
191 guint8 coded_size_flag;
193 guint16 coded_height;
195 guint8 range_mapy_flag;
197 guint8 range_mapuv_flag;
200 guint8 hrd_full[MAX_HRD_NUM_LEAKY_BUCKETS];
204 * GstVC1AdvancedSeqHdr:
206 * Structure for the advanced profile sequence headers specific parameters.
208 struct _GstVC1AdvancedSeqHdr
212 guint8 frmrtq_postproc;
213 guint8 bitrtq_postproc;
215 guint16 max_coded_width;
216 guint16 max_coded_height;
223 guint16 disp_horiz_size;
224 guint16 disp_vert_size;
225 guint8 aspect_ratio_flag;
227 guint8 aspect_horiz_size;
228 guint8 aspect_vert_size;
229 guint8 framerate_flag;
233 guint16 framerateexp;
234 guint8 color_format_flag;
236 guint8 transfer_char;
238 guint8 hrd_param_flag;
239 guint8 colordiff_format;
241 GstVC1HrdParam hrd_param;
244 guint framerate; /* Around in fps, 0 if unknown*/
245 guint bitrate; /* Around in kpbs, 0 if unknown*/
251 /* The last parsed entry point */
252 GstVC1EntryPointHdr entrypoint;
255 struct _GstVC1SeqStructA
261 struct _GstVC1SeqStructB
268 /* In simple and main profiles only */
273 struct _GstVC1SeqStructC
275 GstVC1Profile profile;
277 /* Only in simple and main profiles */
278 guint8 frmrtq_postproc;
279 guint8 bitrtq_postproc;
295 guint framerate; /* Around in fps, 0 if unknown*/
296 guint bitrate; /* Around in kpbs, 0 if unknown*/
298 /* This should be filled by user if previously known */
300 /* This should be filled by user if previously known */
301 guint16 coded_height;
304 guint8 wmvp; /* Specify if the stream is wmp or not */
305 /* In the wmvp case, the framerate is not computed but in the bistream */
309 struct _GstVC1SeqLayer
313 GstVC1SeqStructA struct_a;
314 GstVC1SeqStructB struct_b;
315 GstVC1SeqStructC struct_c;
321 * Structure for sequence headers in any profile.
325 GstVC1Profile profile;
327 GstVC1SeqStructC struct_c;
334 GstVC1AdvancedSeqHdr advanced;
339 * GstVC1PicSimpleMain:
340 * @bfaction: Should be divided by #GST_VC1_BFRACTION_BASIS
341 * to get the real value.
343 struct _GstVC1PicSimpleMain
349 /* I and P pic simple and main profiles only */
352 /* I and BI pic simple and main profiles only */
356 /* B and P pic simple and main profiles only */
361 /* P pic simple and main profiles only */
369 /* B and BI picture only
370 * Should be divided by #GST_VC1_BFRACTION_BASIS
371 * to get the real value. */
374 /* Biplane value, those fields only mention the fact
375 * that the bitplane is in raw mode or not */
378 guint8 directmb; /* B pic main profile only */
383 * @bfaction: Should be divided by #GST_VC1_BFRACTION_BASIS
384 * to get the real value.
386 struct _GstVC1PicAdvanced
388 GstVC1FrameCodingMode fcm;
403 /* B and P picture specific */
411 /* B and BI picture only
412 * Should be divided by #GST_VC1_BFRACTION_BASIS
413 * to get the real value. */
426 /* Biplane value, those fields only mention the fact
427 * that the bitplane is in raw mode or not */
433 guint8 forwardmb; /* B pic interlace field only */
435 /* For interlaced pictures only */
438 /* P and B pictures */
445 guint8 mvbptab4; /* If 4mvswitch in ppic */
450 /* For interlaced fields only */
452 guint8 fptype; /* Raw value */
463 struct _GstVC1BitPlanes
473 guint size; /* Size of the arrays */
476 struct _GstVC1VopDquant
488 /* if dqprofile == GST_VC1_DQPROFILE_SINGLE_EDGE
489 * or GST_VC1_DQPROFILE_DOUBLE_EDGE:*/
492 /* if dqprofile == GST_VC1_DQPROFILE_SINGLE_EDGE
493 * or GST_VC1_DQPROFILE_DOUBLE_EDGE:*/
496 /* if dqprofile == GST_VC1_DQPROFILE_ALL_MBS */
501 struct _GstVC1FrameLayer
509 guint32 next_framelayer_offset;
510 guint8 skiped_p_frame;
516 * Structure that represent picture in any profile or mode.
517 * You should look at @ptype and @profile to know what is currently
520 struct _GstVC1FrameHdr
523 GstVC1PictureType ptype;
534 /* Convenience fields */
539 GstVC1VopDquant vopdquant;
542 GstVC1PicSimpleMain simple;
543 GstVC1PicAdvanced advanced;
546 /* Size of the picture layer in bits */
553 * Structure that represents a Bitstream Data Unit.
557 GstVC1StartCode type;
564 GstVC1ParserResult gst_vc1_identify_next_bdu (const guint8 *data,
569 GstVC1ParserResult gst_vc1_parse_sequence_header (const guint8 *data,
571 GstVC1SeqHdr * seqhdr);
573 GstVC1ParserResult gst_vc1_parse_entry_point_header (const guint8 *data,
575 GstVC1EntryPointHdr * entrypoint,
576 GstVC1SeqHdr *seqhdr);
578 GstVC1ParserResult gst_vc1_parse_sequence_layer (const guint8 *data,
580 GstVC1SeqLayer * seqlayer);
583 gst_vc1_parse_sequence_header_struct_a (const guint8 *data,
585 GstVC1SeqStructA *structa);
587 gst_vc1_parse_sequence_header_struct_b (const guint8 *data,
589 GstVC1SeqStructB *structb);
592 gst_vc1_parse_sequence_header_struct_c (const guint8 *data,
594 GstVC1SeqStructC *structc);
596 GstVC1ParserResult gst_vc1_parse_frame_layer (const guint8 *data,
598 GstVC1FrameLayer * framelayer);
600 GstVC1ParserResult gst_vc1_parse_frame_header (const guint8 *data,
602 GstVC1FrameHdr * framehdr,
603 GstVC1SeqHdr *seqhdr,
604 GstVC1BitPlanes *bitplanes);
606 GstVC1ParserResult gst_vc1_parse_field_header (const guint8 *data,
608 GstVC1FrameHdr * fieldhdr,
609 GstVC1SeqHdr *seqhdr,
610 GstVC1BitPlanes *bitplanes);
612 GstVC1BitPlanes * gst_vc1_bitplanes_new (void);
614 void gst_vc1_bitplanes_free (GstVC1BitPlanes *bitplanes);
616 void gst_vc1_bitplanes_free_1 (GstVC1BitPlanes *bitplanes);
618 gboolean gst_vc1_bitplanes_ensure_size (GstVC1BitPlanes *bitplanes,
619 GstVC1SeqHdr *seqhdr);