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."
31 #include <gst/codecparsers/codecparsers-prelude.h>
35 #define MAX_HRD_NUM_LEAKY_BUCKETS 31
38 * GST_VC1_BFRACTION_BASIS:
39 * The @bfraction variable should be divided
40 * by this constant to have the actual value.
42 #define GST_VC1_BFRACTION_BASIS 840
44 #define GST_VC1_BFRACTION_RESERVED (GST_VC1_BFRACTION_BASIS + 1)
45 #define GST_VC1_BFRACTION_PTYPE_BI (GST_VC1_BFRACTION_BASIS + 2)
48 GST_VC1_END_OF_SEQ = 0x0A,
52 GST_VC1_ENTRYPOINT = 0x0E,
53 GST_VC1_SEQUENCE = 0x0F,
54 GST_VC1_SLICE_USER = 0x1B,
55 GST_VC1_FIELD_USER = 0x1C,
56 GST_VC1_FRAME_USER = 0x1D,
57 GST_VC1_ENTRY_POINT_USER = 0x1E,
58 GST_VC1_SEQUENCE_USER = 0x1F
62 GST_VC1_PROFILE_SIMPLE,
64 GST_VC1_PROFILE_RESERVED,
65 GST_VC1_PROFILE_ADVANCED
70 GST_VC1_PARSER_BROKEN_DATA,
71 GST_VC1_PARSER_NO_BDU,
72 GST_VC1_PARSER_NO_BDU_END,
78 GST_VC1_PICTURE_TYPE_P,
79 GST_VC1_PICTURE_TYPE_B,
80 GST_VC1_PICTURE_TYPE_I,
81 GST_VC1_PICTURE_TYPE_BI,
82 GST_VC1_PICTURE_TYPE_SKIPPED
87 GST_VC1_LEVEL_LOW = 0, /* Simple/Main profile low level */
88 GST_VC1_LEVEL_MEDIUM = 2, /* Simple/Main profile medium level */
89 GST_VC1_LEVEL_HIGH = 4, /* Main profile high level */
91 GST_VC1_LEVEL_L0 = 0, /* Advanced profile level 0 */
92 GST_VC1_LEVEL_L1 = 1, /* Advanced profile level 1 */
93 GST_VC1_LEVEL_L2 = 2, /* Advanced profile level 2 */
94 GST_VC1_LEVEL_L3 = 3, /* Advanced profile level 3 */
95 GST_VC1_LEVEL_L4 = 4, /* Advanced profile level 4 */
98 GST_VC1_LEVEL_UNKNOWN = 255 /* Unknown profile */
103 GST_VC1_QUANTIZER_IMPLICITLY,
104 GST_VC1_QUANTIZER_EXPLICITLY,
105 GST_VC1_QUANTIZER_NON_UNIFORM,
106 GST_VC1_QUANTIZER_UNIFORM
107 } GstVC1QuantizerSpec;
110 GST_VC1_DQPROFILE_FOUR_EDGES,
111 GST_VC1_DQPROFILE_DOUBLE_EDGES,
112 GST_VC1_DQPROFILE_SINGLE_EDGE,
113 GST_VC1_DQPROFILE_ALL_MBS
117 GST_VC1_CONDOVER_NONE,
118 GST_VC1_CONDOVER_ALL,
119 GST_VC1_CONDOVER_SELECT
128 GST_VC1_MVMODE_1MV_HPEL_BILINEAR,
130 GST_VC1_MVMODE_1MV_HPEL,
131 GST_VC1_MVMODE_MIXED_MV,
132 GST_VC1_MVMODE_INTENSITY_COMP
137 GST_VC1_FRAME_PROGRESSIVE = 0x0,
138 GST_VC1_FRAME_INTERLACE = 0x10,
139 GST_VC1_FIELD_INTERLACE = 0x11
140 } GstVC1FrameCodingMode;
142 typedef struct _GstVC1SeqHdr GstVC1SeqHdr;
143 typedef struct _GstVC1AdvancedSeqHdr GstVC1AdvancedSeqHdr;
144 typedef struct _GstVC1HrdParam GstVC1HrdParam;
145 typedef struct _GstVC1EntryPointHdr GstVC1EntryPointHdr;
147 typedef struct _GstVC1SeqLayer GstVC1SeqLayer;
149 typedef struct _GstVC1SeqStructA GstVC1SeqStructA;
150 typedef struct _GstVC1SeqStructB GstVC1SeqStructB;
151 typedef struct _GstVC1SeqStructC GstVC1SeqStructC;
153 /* Pictures Structures */
154 typedef struct _GstVC1FrameLayer GstVC1FrameLayer;
155 typedef struct _GstVC1FrameHdr GstVC1FrameHdr;
156 typedef struct _GstVC1PicAdvanced GstVC1PicAdvanced;
157 typedef struct _GstVC1PicSimpleMain GstVC1PicSimpleMain;
158 typedef struct _GstVC1Picture GstVC1Picture;
159 typedef struct _GstVC1SliceHdr GstVC1SliceHdr;
161 typedef struct _GstVC1VopDquant GstVC1VopDquant;
163 typedef struct _GstVC1BitPlanes GstVC1BitPlanes;
165 typedef struct _GstVC1BDU GstVC1BDU;
167 struct _GstVC1HrdParam
169 guint8 hrd_num_leaky_buckets;
170 guint8 bit_rate_exponent;
171 guint8 buffer_size_exponent;
172 guint16 hrd_rate[MAX_HRD_NUM_LEAKY_BUCKETS];
173 guint16 hrd_buffer[MAX_HRD_NUM_LEAKY_BUCKETS];
177 * GstVC1EntryPointHdr:
179 * Structure for entrypoint header, this will be used only in advanced profiles
181 struct _GstVC1EntryPointHdr
194 guint8 coded_size_flag;
196 guint16 coded_height;
198 guint8 range_mapy_flag;
200 guint8 range_mapuv_flag;
203 guint8 hrd_full[MAX_HRD_NUM_LEAKY_BUCKETS];
207 * GstVC1AdvancedSeqHdr:
209 * Structure for the advanced profile sequence headers specific parameters.
211 struct _GstVC1AdvancedSeqHdr
215 guint8 frmrtq_postproc;
216 guint8 bitrtq_postproc;
218 guint16 max_coded_width;
219 guint16 max_coded_height;
226 guint16 disp_horiz_size;
227 guint16 disp_vert_size;
228 guint8 aspect_ratio_flag;
230 guint8 aspect_horiz_size;
231 guint8 aspect_vert_size;
232 guint8 framerate_flag;
236 guint16 framerateexp;
237 guint8 color_format_flag;
239 guint8 transfer_char;
241 guint8 hrd_param_flag;
242 guint8 colordiff_format;
244 GstVC1HrdParam hrd_param;
247 guint framerate; /* Around in fps, 0 if unknown*/
248 guint bitrate; /* Around in kpbs, 0 if unknown*/
254 /* The last parsed entry point */
255 GstVC1EntryPointHdr entrypoint;
258 struct _GstVC1SeqStructA
264 struct _GstVC1SeqStructB
271 /* In simple and main profiles only */
276 struct _GstVC1SeqStructC
278 GstVC1Profile profile;
280 /* Only in simple and main profiles */
281 guint8 frmrtq_postproc;
282 guint8 bitrtq_postproc;
298 guint framerate; /* Around in fps, 0 if unknown*/
299 guint bitrate; /* Around in kpbs, 0 if unknown*/
301 /* This should be filled by user if previously known */
303 /* This should be filled by user if previously known */
304 guint16 coded_height;
307 guint8 wmvp; /* Specify if the stream is wmp or not */
308 /* In the wmvp case, the framerate is not computed but in the bistream */
312 struct _GstVC1SeqLayer
316 GstVC1SeqStructA struct_a;
317 GstVC1SeqStructB struct_b;
318 GstVC1SeqStructC struct_c;
324 * Structure for sequence headers in any profile.
328 GstVC1Profile profile;
330 GstVC1SeqStructC struct_c;
337 GstVC1AdvancedSeqHdr advanced;
342 * GstVC1PicSimpleMain:
343 * @bfaction: Should be divided by #GST_VC1_BFRACTION_BASIS
344 * to get the real value.
346 struct _GstVC1PicSimpleMain
352 /* I and P pic simple and main profiles only */
355 /* I and BI pic simple and main profiles only */
359 /* B and P pic simple and main profiles only */
364 /* P pic simple and main profiles only */
372 /* B and BI picture only
373 * Should be divided by #GST_VC1_BFRACTION_BASIS
374 * to get the real value. */
377 /* Biplane value, those fields only mention the fact
378 * that the bitplane is in raw mode or not */
381 guint8 directmb; /* B pic main profile only */
386 * @bfaction: Should be divided by #GST_VC1_BFRACTION_BASIS
387 * to get the real value.
389 struct _GstVC1PicAdvanced
391 GstVC1FrameCodingMode fcm;
406 /* B and P picture specific */
414 /* B and BI picture only
415 * Should be divided by #GST_VC1_BFRACTION_BASIS
416 * to get the real value. */
429 /* Biplane value, those fields only mention the fact
430 * that the bitplane is in raw mode or not */
436 guint8 forwardmb; /* B pic interlace field only */
438 /* For interlaced pictures only */
441 /* P and B pictures */
448 guint8 mvbptab4; /* If 4mvswitch in ppic */
453 /* For interlaced fields only */
455 guint8 fptype; /* Raw value */
466 struct _GstVC1BitPlanes
476 guint size; /* Size of the arrays */
479 struct _GstVC1VopDquant
491 /* Boundary edge selection. This represents DQSBEDGE
492 * if dqprofile == GST_VC1_DQPROFILE_SINGLE_EDGE or
493 * DQDBEDGE if dqprofile == GST_VC1_DQPROFILE_DOUBLE_EDGE */
499 /* if dqprofile == GST_VC1_DQPROFILE_ALL_MBS */
504 struct _GstVC1FrameLayer
512 guint32 next_framelayer_offset;
513 guint8 skiped_p_frame;
519 * Structure that represent picture in any profile or mode.
520 * You should look at @ptype and @profile to know what is currently
523 struct _GstVC1FrameHdr
526 GstVC1PictureType ptype;
537 /* Convenience fields */
542 GstVC1VopDquant vopdquant;
545 GstVC1PicSimpleMain simple;
546 GstVC1PicAdvanced advanced;
549 /* Size of the picture layer in bits */
556 * Structure that represents slice layer in advanced profile.
558 struct _GstVC1SliceHdr
562 /* Size of the slice layer in bits */
569 * Structure that represents a Bitstream Data Unit.
573 GstVC1StartCode type;
580 GST_CODEC_PARSERS_API
581 GstVC1ParserResult gst_vc1_identify_next_bdu (const guint8 *data,
586 GST_CODEC_PARSERS_API
587 GstVC1ParserResult gst_vc1_parse_sequence_header (const guint8 *data,
589 GstVC1SeqHdr * seqhdr);
591 GST_CODEC_PARSERS_API
592 GstVC1ParserResult gst_vc1_parse_entry_point_header (const guint8 *data,
594 GstVC1EntryPointHdr * entrypoint,
595 GstVC1SeqHdr *seqhdr);
597 GST_CODEC_PARSERS_API
598 GstVC1ParserResult gst_vc1_parse_sequence_layer (const guint8 *data,
600 GstVC1SeqLayer * seqlayer);
601 GST_CODEC_PARSERS_API
603 gst_vc1_parse_sequence_header_struct_a (const guint8 *data,
605 GstVC1SeqStructA *structa);
606 GST_CODEC_PARSERS_API
608 gst_vc1_parse_sequence_header_struct_b (const guint8 *data,
610 GstVC1SeqStructB *structb);
611 GST_CODEC_PARSERS_API
613 gst_vc1_parse_sequence_header_struct_c (const guint8 *data,
615 GstVC1SeqStructC *structc);
617 GST_CODEC_PARSERS_API
618 GstVC1ParserResult gst_vc1_parse_frame_layer (const guint8 *data,
620 GstVC1FrameLayer * framelayer);
622 GST_CODEC_PARSERS_API
623 GstVC1ParserResult gst_vc1_parse_frame_header (const guint8 *data,
625 GstVC1FrameHdr * framehdr,
626 GstVC1SeqHdr *seqhdr,
627 GstVC1BitPlanes *bitplanes);
629 GST_CODEC_PARSERS_API
630 GstVC1ParserResult gst_vc1_parse_field_header (const guint8 *data,
632 GstVC1FrameHdr * fieldhdr,
633 GstVC1SeqHdr *seqhdr,
634 GstVC1BitPlanes *bitplanes);
636 GST_CODEC_PARSERS_API
637 GstVC1ParserResult gst_vc1_parse_slice_header (const guint8 *data,
639 GstVC1SliceHdr *slicehdr,
640 GstVC1SeqHdr *seqhdr);
642 GST_CODEC_PARSERS_API
643 GstVC1BitPlanes * gst_vc1_bitplanes_new (void);
645 GST_CODEC_PARSERS_API
646 void gst_vc1_bitplanes_free (GstVC1BitPlanes *bitplanes);
648 GST_CODEC_PARSERS_API
649 void gst_vc1_bitplanes_free_1 (GstVC1BitPlanes *bitplanes);
651 GST_CODEC_PARSERS_API
652 gboolean gst_vc1_bitplanes_ensure_size (GstVC1BitPlanes *bitplanes,
653 GstVC1SeqHdr *seqhdr);