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