3 * Copyright (C) 2009 Carl-Anton Ingmarsson <ca.ingmarsson@gmail.com>
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.
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.
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.
21 #ifndef __GST_MPEG4UTIL_H__
22 #define __GST_MPEG4UTIL_H__
25 #include <gst/base/gstbitreader.h>
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;
36 typedef struct _GstMpeg4SpriteTrajectory GstMpeg4SpriteTrajectory;
38 typedef struct _GstMpeg4Packet GstMpeg4Packet;
43 * Defines the different startcodes present in the bitstream as
44 * defined in: Table 6-3 — Start code values
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,
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
75 * GstMpeg4VisualObjectType:
77 * Defines the different visual object types as
78 * defined in: Table 6-5 -- Meaning of visual object type
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,
88 } GstMpeg4VisualObjectType;
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
99 * Defines the different pixel aspect ratios as
100 * defined in: Table 6-12 -- Meaning of pixel aspect ratio
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;
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
119 * Result type of any parsing function.
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;
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)
136 * The vop coding types as defined in:
137 * Table 6-20 -- Meaning of vop_coding_type
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;
147 * GstMpeg4ChromaFormat
149 * The chroma format in use as
150 * defined in: Table 6-13 -- Meaning of chroma_format
153 /* Other value are reserved */
154 GST_MPEG4_CHROMA_4_2_0 = 0x01
155 } GstMpeg4ChromaFormat;
158 * GstMpeg4VideoObjectLayerShape:
160 * The different video object layer shapes as defined in:
161 * Table 6-16 — Video Object Layer shape type
164 GST_MPEG4_RECTANGULAR,
166 GST_MPEG4_BINARY_ONLY,
168 } GstMpeg4VideoObjectLayerShape;
171 * GstMpeg4SpriteEnable:
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
178 GST_MPEG4_SPRITE_UNUSED,
179 GST_MPEG4_SPRITE_STATIC,
181 } GstMpeg4SpriteEnable;
186 * Different defined profiles as defined in:
187 * 9- Profiles and levels
189 * It is computed using:
190 * Table G.1 — FLC table for profile_and_level_indication
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
218 * Different levels as defined in:
219 * 9- Profiles and levels
221 * It is computed using:
222 * Table G.1 — FLC table for profile_and_level_indication
232 GST_MPEG4_LEVEL_RESERVED
236 * GstMpeg4VisualObjectSequence:
238 * The visual object sequence structure as defined in:
239 * 6.2.2 Visual Object Sequence and Visual Object
241 struct _GstMpeg4VisualObjectSequence {
242 guint8 profile_and_level_indication;
244 /* Computed according to:
245 * Table G.1 — FLC table for profile_and_level_indication */
247 GstMpeg4Profile profile;
251 * The visual object structure as defined in:
252 * 6.2.2 Visual Object Sequence and Visual Object
254 struct _GstMpeg4VisualObject {
255 guint8 is_identifier;
256 /* If is_identifier */
260 GstMpeg4VisualObjectType type;
264 * GstMpeg4VideoSignalType:
266 * The video signal type structure as defined in:
267 * 6.2.2 Visual Object Sequence and Visual Object.
269 struct _GstMpeg4VideoSignalType {
274 guint8 color_description;
275 guint8 color_primaries;
276 guint8 transfer_characteristics;
277 guint8 matrix_coefficients;
281 * GstMpeg4VideoPlaneShortHdr:
283 * The video plane short header structure as defined in:
284 * 6.2.5.2 Video Plane with Short Header
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;
297 /* Gob layer specific fields */
298 guint8 gob_header_empty;
304 * If all the values are set to 0, then it is reserved
305 * Table 6-25 -- Parameters Defined by source_format Field
309 guint16 num_macroblocks_in_gob;
310 guint8 num_gobs_in_vop;
312 /* The size in bits */
317 * GstMpeg4VideoObjectLayer:
319 * The video object layer structure as defined in:
320 * 6.2.3 Video Object Layer
322 struct _GstMpeg4VideoObjectLayer {
323 guint8 random_accessible_vol;
324 guint8 video_object_type_indication;
326 guint8 is_object_layer_identifier;
327 /* if is_object_layer_identifier */
331 GstMpeg4AspectRatioInfo aspect_ratio_info;
335 guint8 control_parameters;
336 /* if control_parameters */
337 GstMpeg4ChromaFormat chroma_format;
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;
348 /* Computed values */
350 guint32 vbv_buffer_size;
352 GstMpeg4VideoObjectLayerShape shape;
353 /* if shape == GST_MPEG4_GRAYSCALE && verid =! 1 */
354 guint8 shape_extension;
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;
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;
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;
381 /* if shape != GST_MPEG4_RECTANGULAR */
382 guint8 sadct_disable;
387 guint8 quant_precision;
388 guint8 bits_per_pixel;
390 /* if shape == GRAYSCALE */
391 guint8 no_gray_quant_update;
392 guint8 composition_method;
393 guint8 linear_composition;
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];
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;
410 guint8 enhancement_type;
412 GstMpeg4VideoPlaneShortHdr short_hdr;
416 * GstMpeg4SpriteTrajectory:
418 * The sprite trajectory structure as defined in:
419 * 7.8.4 Sprite reference point decoding and
420 * 6.2.5.4 Sprite coding
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 */
428 * GstMpeg4GroupOfVOP:
430 * The group of video object plane structure as defined in:
431 * 6.2.4 Group of Video Object Plane
433 struct _GstMpeg4GroupOfVOP {
443 * GstMpeg4VideoObjectPlane:
445 * The Video object plane structure as defined in:
446 * 6.2.5 Video Object Plane and Video Plane with Short Header
448 struct _GstMpeg4VideoObjectPlane {
449 GstMpeg4VideoObjectCodingType coding_type;
451 guint8 modulo_time_base;
452 guint16 time_increment;
455 /* if newpred_enable */
457 guint8 id_for_prediction_indication;
458 guint16 id_for_prediction;
462 guint16 horizontal_mc_spatial_ref;
463 guint16 vertical_mc_spatial_ref;
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;
473 guint8 intra_dc_vlc_thr;
476 guint8 top_field_first;
477 guint8 alternate_vertical_scan_flag;
481 guint8 fcode_forward;
482 guint8 fcode_backward;
484 guint8 shape_coding_type;
485 guint8 load_backward_shape;
486 guint8 ref_select_code;
488 /* Computed macroblock informations */
493 /* The size of the header */
498 * GstMpeg4VideoPacketHdr:
499 * @size: Size of the header in bit.
501 * The video packet header structure as defined in:
502 * 6.2.5.2 Video Plane with Short Header
504 struct _GstMpeg4VideoPacketHdr {
505 guint8 header_extension_code;
506 guint16 macroblock_number;
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.
520 * A structure that contains the type of a packet, its offset and its size
522 struct _GstMpeg4Packet
529 GstMpeg4StartCode type;
532 GstMpeg4ParseResult gst_h263_parse (GstMpeg4Packet * packet,
533 const guint8 * data, guint offset,
537 GstMpeg4ParseResult gst_mpeg4_parse (GstMpeg4Packet * packet,
538 gboolean skip_user_data,
539 GstMpeg4VideoObjectPlane *vop,
540 const guint8 * data, guint offset,
544 gst_mpeg4_parse_video_object_plane (GstMpeg4VideoObjectPlane *vop,
545 GstMpeg4SpriteTrajectory *sprite_trajectory,
546 GstMpeg4VideoObjectLayer *vol,
551 gst_mpeg4_parse_group_of_vop (GstMpeg4GroupOfVOP *gov,
552 const guint8 * data, gsize size);
555 gst_mpeg4_parse_video_object_layer (GstMpeg4VideoObjectLayer *vol,
556 GstMpeg4VisualObject *vo,
557 const guint8 * data, gsize size);
560 gst_mpeg4_parse_visual_object (GstMpeg4VisualObject *vo,
561 GstMpeg4VideoSignalType *signal_type,
562 const guint8 * data, gsize size);
565 gst_mpeg4_parse_visual_object_sequence (GstMpeg4VisualObjectSequence *vos,
566 const guint8 * data, gsize size);
568 gst_mpeg4_parse_video_plane_short_header (GstMpeg4VideoPlaneShortHdr * shorthdr,
569 const guint8 * data, gsize size);
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);
578 #endif /* __GST_MPEG4UTIL_H__ */