import ext/codecparsers instead of git submodule
[profile/ivi/gstreamer-vaapi.git] / ext / codecparsers / gst-libs / gst / codecparsers / gstmpeg4parser.h
1 /*
2  * GStreamer
3  * Copyright (C) 2009 Carl-Anton Ingmarsson <ca.ingmarsson@gmail.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20
21 #ifndef __GST_MPEG4UTIL_H__
22 #define __GST_MPEG4UTIL_H__
23
24 #include <gst/gst.h>
25 #include <gst/base/gstbitreader.h>
26
27 typedef struct _GstMpeg4VisualObjectSequence    GstMpeg4VisualObjectSequence;
28 typedef struct _GstMpeg4VisualObject            GstMpeg4VisualObject;
29 typedef struct _GstMpeg4VideoObjectLayer        GstMpeg4VideoObjectLayer;
30 typedef struct _GstMpeg4GroupOfVOP              GstMpeg4GroupOfVOP;
31 typedef struct _GstMpeg4VideoObjectPlane        GstMpeg4VideoObjectPlane;
32 typedef struct _GstMpeg4VideoSignalType         GstMpeg4VideoSignalType;
33 typedef struct _GstMpeg4VideoPlaneShortHdr      GstMpeg4VideoPlaneShortHdr;
34 typedef struct _GstMpeg4VideoPacketHdr          GstMpeg4VideoPacketHdr;
35
36 typedef struct _GstMpeg4SpriteTrajectory        GstMpeg4SpriteTrajectory;
37
38 typedef struct _GstMpeg4Packet                  GstMpeg4Packet;
39
40 /**
41  * GstMpeg4StartCode:
42  *
43  * Defines the different startcodes present in the bitstream as
44  * defined in: Table 6-3 — Start code values
45  */
46 typedef enum
47 {
48   GST_MPEG4_VIDEO_OBJ_FIRST      = 0x00,
49   GST_MPEG4_VIDEO_OBJ_LAST       = 0x1f,
50   GST_MPEG4_VIDEO_LAYER_FIRST    = 0x20,
51   GST_MPEG4_VIDEO_LAYER_LAST     = 0x2f,
52   GST_MPEG4_VISUAL_OBJ_SEQ_START = 0xb0,
53   GST_MPEG4_VISUAL_OBJ_SEQ_END   = 0xb1,
54   GST_MPEG4_USER_DATA            = 0xb2,
55   GST_MPEG4_GROUP_OF_VOP         = 0xb3,
56   GST_MPEG4_VIDEO_SESSION_ERR    = 0xb4,
57   GST_MPEG4_VISUAL_OBJ           = 0xb5,
58   GST_MPEG4_VIDEO_OBJ_PLANE      = 0xb6,
59   GST_MPEG4_FBA                  = 0xba,
60   GST_MPEG4_FBA_PLAN             = 0xbb,
61   GST_MPEG4_MESH                 = 0xbc,
62   GST_MPEG4_MESH_PLAN            = 0xbd,
63   GST_MPEG4_STILL_TEXTURE_OBJ    = 0xbe,
64   GST_MPEG4_TEXTURE_SPATIAL      = 0xbf,
65   GST_MPEG4_TEXTURE_SNR_LAYER    = 0xc0,
66   GST_MPEG4_TEXTURE_TILE         = 0xc1,
67   GST_MPEG4_SHAPE_LAYER          = 0xc2,
68   GST_MPEG4_STUFFING             = 0xc3,
69   GST_MPEG4_SYSTEM_FIRST         = 0xc6,
70   GST_MPEG4_SYSTEM_LAST          = 0xff,
71   GST_MPEG4_RESYNC               = 0xfff
72 } GstMpeg4StartCode;
73
74 /**
75  * GstMpeg4VisualObjectType:
76  *
77  * Defines the different visual object types as
78  * defined in: Table 6-5 -- Meaning of visual object type
79  */
80 typedef enum {
81   GST_MPEG4_VIDEO_ID         = 0x01,
82   GST_MPEG4_STILL_TEXTURE_ID = 0x02,
83   GST_MPEG4_STILL_MESH_ID    = 0x03,
84   GST_MPEG4_STILL_FBA_ID     = 0x04,
85   GST_MPEG4_STILL_3D_MESH_ID = 0x05,
86   /*... reserved */
87
88 } GstMpeg4VisualObjectType;
89
90 /**
91  * GstMpeg4AspectRatioInfo:
92  * @GST_MPEG4_SQUARE: 1:1 square
93  * @GST_MPEG4_625_TYPE_4_3: 12:11 (625-type for 4:3 picture)
94  * @GST_MPEG4_525_TYPE_4_3: 10:11 (525-type for 4:3 picture)
95  * @GST_MPEG4_625_TYPE_16_9: 16:11 (625-type stretched for 16:9 picture)
96  * @GST_MPEG4_525_TYPE_16_9: 40:33 (525-type stretched for 16:9 picture)
97  * @GST_MPEG4_EXTENDED_PAR: Extended par
98  *
99  * Defines the different pixel aspect ratios as
100  * defined in: Table 6-12 -- Meaning of pixel aspect ratio
101  */
102 typedef enum {
103   GST_MPEG4_SQUARE        = 0x01,
104   GST_MPEG4_625_TYPE_4_3  = 0x02,
105   GST_MPEG4_525_TYPE_4_3  = 0x03,
106   GST_MPEG4_625_TYPE_16_9 = 0x04,
107   GST_MPEG4_525_TYPE_16_9 = 0x05,
108   GST_MPEG4_EXTENDED_PAR  = 0x0f,
109 } GstMpeg4AspectRatioInfo;
110
111 /**
112  * GstMpeg4ParseResult:
113  * @GST_MPEG4_PARSER_OK: The parsing went well
114  * @GST_MPEG4_PARSER_BROKEN_DATA: The bitstream was broken
115  * @GST_MPEG4_PARSER_NO_PACKET: There was no packet in the buffer
116  * @GST_MPEG4_PARSER_NO_PACKET_END: There was no packet end in the buffer
117  * @GST_MPEG4_PARSER_NO_PACKET_ERROR: An error accured durint the parsing
118  *
119  * Result type of any parsing function.
120  */
121 typedef enum {
122   GST_MPEG4_PARSER_OK,
123   GST_MPEG4_PARSER_BROKEN_DATA,
124   GST_MPEG4_PARSER_NO_PACKET,
125   GST_MPEG4_PARSER_NO_PACKET_END,
126   GST_MPEG4_PARSER_ERROR,
127 } GstMpeg4ParseResult;
128
129 /**
130  * GstMpeg4VideoObjectCodingType:
131  * @GST_MPEG4_I_VOP: intra-coded (I)
132  * @GST_MPEG4_P_VOP: predictive-coded (P)
133  * @GST_MPEG4_B_VOP: bidirectionally-predictive-coded (B)
134  * @GST_MPEG4_S_VOP: sprite (S)
135  *
136  * The vop coding types as defined in:
137  * Table 6-20 -- Meaning of vop_coding_type
138  */
139 typedef enum {
140   GST_MPEG4_I_VOP = 0x0,
141   GST_MPEG4_P_VOP = 0x1,
142   GST_MPEG4_B_VOP = 0x2,
143   GST_MPEG4_S_VOP = 0x3
144 } GstMpeg4VideoObjectCodingType;
145
146 /**
147  * GstMpeg4ChromaFormat
148  *
149  * The chroma format in use as
150  * defined in: Table 6-13 -- Meaning of chroma_format
151  */
152 typedef enum {
153   /* Other value are reserved */
154   GST_MPEG4_CHROMA_4_2_0 = 0x01
155 } GstMpeg4ChromaFormat;
156
157 /**
158  * GstMpeg4VideoObjectLayerShape:
159  *
160  * The different video object layer shapes as defined in:
161  * Table 6-16 — Video Object Layer shape type
162  */
163 typedef enum {
164   GST_MPEG4_RECTANGULAR,
165   GST_MPEG4_BINARY,
166   GST_MPEG4_BINARY_ONLY,
167   GST_MPEG4_GRAYSCALE
168 } GstMpeg4VideoObjectLayerShape;
169
170 /**
171  * GstMpeg4SpriteEnable:
172  *
173  * Indicates the usage of static sprite coding
174  * or global motion compensation (GMC) as defined in:
175  * Table V2 - 2 -- Meaning of sprite_enable codewords
176  */
177 typedef enum {
178   GST_MPEG4_SPRITE_UNUSED,
179   GST_MPEG4_SPRITE_STATIC,
180   GST_MPEG4_SPRITE_GMG
181 } GstMpeg4SpriteEnable;
182
183 /**
184  * GstMpeg4Profile:
185  *
186  * Different defined profiles as defined in:
187  * 9- Profiles and levels
188  *
189  * It is computed using:
190  * Table G.1 — FLC table for profile_and_level_indication
191  */
192 typedef enum {
193   GST_MPEG4_PROFILE_CORE,
194   GST_MPEG4_PROFILE_MAIN,
195   GST_MPEG4_PROFILE_N_BIT,
196   GST_MPEG4_PROFILE_SIMPLE,
197   GST_MPEG4_PROFILE_HYBRID,
198   GST_MPEG4_PROFILE_RESERVED,
199   GST_MPEG4_PROFILE_SIMPLE_FBA,
200   GST_MPEG4_PROFILE_CORE_STUDIO,
201   GST_MPEG4_PROFILE_SIMPLE_STUDIO,
202   GST_MPEG4_PROFILE_CORE_SCALABLE,
203   GST_MPEG4_PROFILE_ADVANCED_CORE,
204   GST_MPEG4_PROFILE_ADVANCED_SIMPLE,
205   GST_MPEG4_PROFILE_SIMPLE_SCALABLE,
206   GST_MPEG4_PROFILE_SCALABLE_TEXTURE,
207   GST_MPEG4_PROFILE_SIMPLE_FACE_ANIMATION,
208   GST_MPEG4_PROFILE_BASIC_ANIMATED_TEXTURE,
209   GST_MPEG4_PROFILE_ADVANCED_REALTIME_SIMPLE,
210   GST_MPEG4_PROFILE_ADVANCED_SCALABLE_TEXTURE,
211   GST_MPEG4_PROFILE_FINE_GRANULARITY_SCALABLE,
212   GST_MPEG4_PROFILE_ADVANCED_CODING_EFFICIENCY
213 } GstMpeg4Profile;
214
215 /**
216  * GstMpeg4Level:
217  *
218  * Different levels as defined in:
219  * 9- Profiles and levels
220  *
221  * It is computed using:
222  * Table G.1 — FLC table for profile_and_level_indication
223  */
224 typedef enum {
225   GST_MPEG4_LEVEL0,
226   GST_MPEG4_LEVEL1,
227   GST_MPEG4_LEVEL2,
228   GST_MPEG4_LEVEL3,
229   GST_MPEG4_LEVEL3b,
230   GST_MPEG4_LEVEL4,
231   GST_MPEG4_LEVEL5,
232   GST_MPEG4_LEVEL_RESERVED
233 } GstMpeg4Level;
234
235 /**
236  * GstMpeg4VisualObjectSequence:
237  *
238  * The visual object sequence structure as defined in:
239  * 6.2.2 Visual Object Sequence and Visual Object
240  */
241 struct _GstMpeg4VisualObjectSequence {
242   guint8 profile_and_level_indication;
243
244   /* Computed according to:
245    * Table G.1 — FLC table for profile_and_level_indication */
246   GstMpeg4Level level;
247   GstMpeg4Profile profile;
248 };
249
250 /**
251  * The visual object structure as defined in:
252  * 6.2.2 Visual Object Sequence and Visual Object
253  */
254 struct _GstMpeg4VisualObject {
255   guint8 is_identifier;
256   /* If is_identifier */
257   guint8 verid;
258   guint8 priority;
259
260   GstMpeg4VisualObjectType type;
261 };
262
263 /**
264  * GstMpeg4VideoSignalType:
265  *
266  * The video signal type structure as defined in:
267  * 6.2.2 Visual Object Sequence and Visual Object.
268  */
269 struct _GstMpeg4VideoSignalType {
270   guint8 type;
271
272   guint8 format;
273   guint8 range;
274   guint8 color_description;
275   guint8 color_primaries;
276   guint8 transfer_characteristics;
277   guint8 matrix_coefficients;
278 };
279
280 /**
281  * GstMpeg4VideoPlaneShortHdr:
282  *
283  * The video plane short header structure as defined in:
284  * 6.2.5.2 Video Plane with Short Header
285  */
286 struct _GstMpeg4VideoPlaneShortHdr {
287   guint8 temporal_reference;
288   guint8 split_screen_indicator;
289   guint8 document_camera_indicator;
290   guint8 full_picture_freeze_release;
291   guint8 source_format;
292   guint8 picture_coding_type;
293   guint8 vop_quant;
294   guint8 pei;
295   guint8 psupp;
296
297   /*  Gob layer specific fields */
298   guint8 gob_header_empty;
299   guint8 gob_number;
300   guint8 gob_frame_id;
301   guint8 quant_scale;
302
303   /* Computed
304    * If all the values are set to 0, then it is reserved
305    * Table 6-25 -- Parameters Defined by source_format Field
306    */
307   guint16 vop_width;
308   guint16 vop_height;
309   guint16 num_macroblocks_in_gob;
310   guint8 num_gobs_in_vop;
311
312   /* The size in bits */
313   guint size;
314 };
315
316 /**
317  * GstMpeg4VideoObjectLayer:
318  *
319  * The video object layer structure as defined in:
320  * 6.2.3 Video Object Layer
321  */
322 struct _GstMpeg4VideoObjectLayer {
323   guint8 random_accessible_vol;
324   guint8 video_object_type_indication;
325
326   guint8 is_object_layer_identifier;
327   /* if is_object_layer_identifier */
328   guint8 verid;
329   guint8 priority;
330
331   GstMpeg4AspectRatioInfo aspect_ratio_info;
332   guint8 par_width;
333   guint8 par_height;
334
335   guint8 control_parameters;
336   /* if control_parameters */
337   GstMpeg4ChromaFormat chroma_format;
338   guint8 low_delay;
339   guint8 vbv_parameters;
340   /* if vbv_parameters */
341   guint16 first_half_bitrate;
342   guint16 latter_half_bitrate;
343   guint16 first_half_vbv_buffer_size;
344   guint16 latter_half_vbv_buffer_size;
345   guint16 first_half_vbv_occupancy;
346   guint16 latter_half_vbv_occupancy;
347
348   /* Computed values */
349   guint32 bit_rate;
350   guint32 vbv_buffer_size;
351
352   GstMpeg4VideoObjectLayerShape shape;
353   /* if shape == GST_MPEG4_GRAYSCALE && verid =! 1 */
354   guint8 shape_extension;
355
356   guint16 vop_time_increment_resolution;
357   guint8 vop_time_increment_bits;
358   guint8 fixed_vop_rate;
359   /* if fixed_vop_rate */
360   guint16 fixed_vop_time_increment;
361
362   guint16 width;
363   guint16 height;
364   guint8 interlaced;
365   guint8 obmc_disable;
366
367   GstMpeg4SpriteEnable sprite_enable;
368   /* if vol->sprite_enable == SPRITE_GMG or SPRITE_STATIC*/
369   /* if vol->sprite_enable != GST_MPEG4_SPRITE_GMG */
370   guint16 sprite_width;
371   guint16 sprite_height;
372   guint16 sprite_left_coordinate;
373   guint16 sprite_top_coordinate;
374
375   guint8 no_of_sprite_warping_points;
376   guint8 sprite_warping_accuracy;
377   guint8 sprite_brightness_change;
378   /* if vol->sprite_enable != GST_MPEG4_SPRITE_GMG */
379   guint8 low_latency_sprite_enable;
380
381   /* if shape != GST_MPEG4_RECTANGULAR */
382   guint8 sadct_disable;
383
384   guint8 not_8_bit;
385
386   /* if no_8_bit */
387   guint8 quant_precision;
388   guint8 bits_per_pixel;
389
390   /* if shape == GRAYSCALE */
391   guint8 no_gray_quant_update;
392   guint8 composition_method;
393   guint8 linear_composition;
394
395   guint8 quant_type;
396   /* if quant_type */
397   guint8 load_intra_quant_mat;
398   guint8 intra_quant_mat[64];
399   guint8 load_non_intra_quant_mat;
400   guint8 non_intra_quant_mat[64];
401
402   guint8 quarter_sample;
403   guint8 complexity_estimation_disable;
404   guint8 resync_marker_disable;
405   guint8 data_partitioned;
406   guint8 reversible_vlc;
407   guint8 newpred_enable;
408   guint8 reduced_resolution_vop_enable;
409   guint8 scalability;
410   guint8 enhancement_type;
411
412   GstMpeg4VideoPlaneShortHdr short_hdr;
413 };
414
415 /**
416  * GstMpeg4SpriteTrajectory:
417  *
418  * The sprite trajectory structure as defined in:
419  * 7.8.4 Sprite reference point decoding and
420  * 6.2.5.4 Sprite coding
421  */
422 struct _GstMpeg4SpriteTrajectory {
423   guint16 vop_ref_points[63]; /* Defined as "du" in 6.2.5.4 */
424   guint16 sprite_ref_points[63]; /* Defined as "dv" in 6.2.5.4 */
425 };
426
427 /**
428  * GstMpeg4GroupOfVOP:
429  *
430  * The group of video object plane structure as defined in:
431  * 6.2.4 Group of Video Object Plane
432  */
433 struct _GstMpeg4GroupOfVOP {
434   guint8 hours;
435   guint8 minutes;
436   guint8 seconds;
437
438   guint8 closed;
439   guint8 broken_link;
440 };
441
442 /**
443  * GstMpeg4VideoObjectPlane:
444  *
445  * The Video object plane structure as defined in:
446  * 6.2.5 Video Object Plane and Video Plane with Short Header
447  */
448 struct _GstMpeg4VideoObjectPlane {
449   GstMpeg4VideoObjectCodingType coding_type;
450
451   guint8  modulo_time_base;
452   guint16 time_increment;
453
454   guint8  coded;
455   /* if newpred_enable */
456   guint16 id;
457   guint8  id_for_prediction_indication;
458   guint16 id_for_prediction;
459
460   guint16 width;
461   guint16 height;
462   guint16 horizontal_mc_spatial_ref;
463   guint16 vertical_mc_spatial_ref;
464
465   guint8  rounding_type;
466   /*if vol->shape != GST_MPEG4_RECTANGULAR */
467   guint8  background_composition;
468   guint8  change_conv_ratio_disable;
469   guint8  constant_alpha;
470   guint8  constant_alpha_value;
471   guint8  reduced_resolution;
472
473   guint8  intra_dc_vlc_thr;
474
475
476   guint8  top_field_first;
477   guint8  alternate_vertical_scan_flag;
478
479   guint16 quant;
480
481   guint8  fcode_forward;
482   guint8  fcode_backward;
483
484   guint8  shape_coding_type;
485   guint8  load_backward_shape;
486   guint8  ref_select_code;
487
488   /* Computed macroblock informations */
489   guint16 mb_height;
490   guint16 mb_width;
491   guint mb_num;
492
493   /* The size of the header */
494   guint    size;
495 };
496
497 /**
498  * GstMpeg4VideoPacketHdr:
499  * @size: Size of the header in bit.
500  *
501  * The video packet header structure as defined in:
502  * 6.2.5.2 Video Plane with Short Header
503  */
504 struct _GstMpeg4VideoPacketHdr {
505   guint8  header_extension_code;
506   guint16 macroblock_number;
507   guint16 quant_scale;
508   guint   size;
509 };
510
511 /**
512  * GstMpeg4Packet:
513  * @type: the type of the packet that start at @offset
514  * @data: the data containing packet starting at @offset
515  * @offset: offset of the start of the packet (without the 3 bytes startcode), but
516  * including the #GstMpeg4StartCode byte.
517  * @size: The size in bytes of the packet or %G_MAXUINT if the end wasn't found.
518  * @marker_size: The size in bit of the resync marker.
519  *
520  * A structure that contains the type of a packet, its offset and its size
521  */
522 struct _GstMpeg4Packet
523 {
524   const guint8     *data;
525   guint             offset;
526   gsize             size;
527   guint             marker_size;
528
529   GstMpeg4StartCode type;
530 };
531
532 GstMpeg4ParseResult gst_h263_parse       (GstMpeg4Packet * packet,
533                                           const guint8 * data, guint offset,
534                                           gsize size);
535
536
537 GstMpeg4ParseResult gst_mpeg4_parse      (GstMpeg4Packet * packet,
538                                           gboolean skip_user_data,
539                                           GstMpeg4VideoObjectPlane *vop,
540                                           const guint8 * data, guint offset,
541                                           gsize size);
542
543 GstMpeg4ParseResult
544 gst_mpeg4_parse_video_object_plane       (GstMpeg4VideoObjectPlane *vop,
545                                           GstMpeg4SpriteTrajectory *sprite_trajectory,
546                                           GstMpeg4VideoObjectLayer *vol,
547                                           const guint8 * data,
548                                           gsize size);
549
550 GstMpeg4ParseResult
551 gst_mpeg4_parse_group_of_vop             (GstMpeg4GroupOfVOP *gov,
552                                           const guint8 * data, gsize size);
553
554 GstMpeg4ParseResult
555 gst_mpeg4_parse_video_object_layer       (GstMpeg4VideoObjectLayer *vol,
556                                           GstMpeg4VisualObject *vo,
557                                           const guint8 * data, gsize size);
558
559 GstMpeg4ParseResult
560 gst_mpeg4_parse_visual_object            (GstMpeg4VisualObject *vo,
561                                           GstMpeg4VideoSignalType *signal_type,
562                                           const guint8 * data, gsize size);
563
564 GstMpeg4ParseResult
565 gst_mpeg4_parse_visual_object_sequence   (GstMpeg4VisualObjectSequence *vos,
566                                           const guint8 * data, gsize size);
567 GstMpeg4ParseResult
568 gst_mpeg4_parse_video_plane_short_header (GstMpeg4VideoPlaneShortHdr * shorthdr,
569                                           const guint8 * data, gsize size);
570
571 GstMpeg4ParseResult
572 gst_mpeg4_parse_video_packet_header      (GstMpeg4VideoPacketHdr * videopackethdr,
573                                           GstMpeg4VideoObjectLayer * vol,
574                                           GstMpeg4VideoObjectPlane * vop,
575                                           GstMpeg4SpriteTrajectory * sprite_trajectory,
576                                           const guint8 * data, gsize size);
577
578 #endif /* __GST_MPEG4UTIL_H__ */