1 /*********************************************************** 2 * 3 * Copyright (C) 2012 PUX Corporation 4 * All Rights Reserved. 5 * 6 ***********************************************************/ 7 8 #ifndef __MP4DMX_H__ 9 #define __MP4DMX_H__ 10 11 #ifdef __cplusplus 12 extern "C"{ 13 #endif /* #ifdef __cplusplus */ 14 15 /******************************************** 16 Return Definition 17 *********************************************/ 18 #define MP4DMX_RET_NO_MORE_CHUNK 1000000 19 #define MP4DMX_RET_FOUND_MOOV_BOX 2000000 20 #define MP4DMX_RET_FOUND_MOOF_BOX 2000001 21 #define MP4DMX_RET_FOUND_MFRA_BOX 2000002 22 #define MP4DMX_RET_FOUND_MFRO_BOX 2000003 23 #define MP4DMX_RET_NOT_FOUND_BOX 2000004 24 #define MP4DMX_RET_FOUND_FTYP_BOX 2000005 25 #define MP4DMX_RET_FIND_HEADER 2000006 26 #define MP4DMX_RET_READ_HEADER 2000007 27 #define MP4DMX_RET_EXECUTE_NORMAL 2000008 28 #define MP4DMX_RET_EXECUTE_WARNING 2000009 29 #define MP4DMX_RET_INPUT_CONTINUE 2000010 30 #define MP4DMX_RET_ERROR_FILE_IO -9999997 31 #define MP4DMX_RET_ERROR_INVALID_POINTER -9999996 32 #define MP4DMX_RET_ERROR_FATAL -9999995 33 #define MP4DMX_RET_ERROR_SYSTEM_BUFFER_OVERFLOW -9999994 34 #define MP4DMX_RET_ERROR_BAD_USER_ID -9999993 35 #define MP4DMX_RET_ERROR_BAD_STREAM -9999992 36 #define MP4DMX_RET_ERROR_BAD_TIMESTAMP -9999991 37 #define MP4DMX_RET_INVALID_TRACK_ID -9999990 38 #define MP4DMX_RET_INVALID_TRACK_INDEX -9999989 39 #define MP4DMX_RET_NOT_FOUND -9999988 40 41 #define MP4DMX_SEEK_NORMAL 0 42 #define MP4DMX_SEEK_BACKWARD 1 43 #define MP4DMX_SEEK_FORWARD 2 44 45 #define MP4DMX_TIME_FORMAT_TIMESTAMP 1 46 #define MP4DMX_TIME_FORMAT_VIDEOFRAME 2 47 48 /******************************************** 49 Parameter Definition 50 *********************************************/ 51 ///The starting value of the open parameters 52 #define MP4DMX_MPO_PARAM_TOP 81004000 53 ///Open Parameter ID 54 enum MP4DMXParamENUM { 55 MP4DMX_OUT_VIDEO_FLAG = MP4DMX_MPO_PARAM_TOP, // Parameter ID to set the video output flag 56 MP4DMX_OUT_AUDIO_FLAG, // Parameter ID to set the audio output flag 57 MP4DMX_OUT_TEXT_FLAG, // Parameter ID to set the text output flag 58 MP4DMX_OUT_ONLY_KEYFRAME, // Parameter ID to set the output flag is only the key frames 59 MP4DMX_SIMPLE_PROCESS, // Parameter ID to set a simple fade speed processing flag 60 MP4DMX_INPUT_VIDEO_BUFFER_NUM, // Parameter ID to set the number of elements of a video ring buffer 61 MP4DMX_INPUT_AUDIO_BUFFER_NUM, // Parameter ID to set the number of elements of the audio ring buffer 62 MP4DMX_INPUT_TEXT_BUFFER_NUM, // Parameter ID to set the number of ring buffer elements of the text 63 MP4DMX_GET_BINARY_BOX_TYPE, // Parameter ID to set the Box type to keep binary data 64 MP4DMX_STSZ_READ_BUFFER_SIZE, // Maximum memory size of sample entries maintained STSZ at one 65 MP4DMX_STTS_READ_BUFFER_SIZE, // Maximum memory size of sample entries maintained STTS at one 66 MP4DMX_MAX_ENTRY_NUM, // The maximum number of entries 67 MP4DMX_MAX_SAMPLE_NUM, // Maximum number of samples 68 MP4DMX_MAX_CHUNK_NUM, // Maximum number of chunks 69 MP4DMX_CTTS_READ_BUFFER_SIZE // Maximum memory size of sample entries maintained CTTS at one 70 }; 71 72 /******************************************** 73 Parameter Definition 74 *********************************************/ 75 #ifndef MP4DMX_RET_SUCCESS 76 #define MP4DMX_RET_SUCCESS 0 // Return value(Successful completion) 77 #endif /* #ifndef MP4DMX_RET_SUCCESS */ 78 79 #ifndef MP4DMX_RET_ERROR 80 #define MP4DMX_RET_ERROR -1 // Return value(Error) 81 #endif /* #ifndef MP4DMX_RET_ERROR */ 82 83 #define MP4DMX_RET_OK 0 // Return value(Successful completion) 84 #define MP4DMX_RET_NG -1 // Return value(Failure) 85 #define MP4DMX_RET_WAIT -16 // Return value(Wait for instructions from the callback function) 86 #define MP4DMX_RET_ERROR_NOT_ENOUGH_MEMORY -9999999 // Return value(Out of memory error) 87 #define MP4DMX_RET_ERROR_BADPARAM -9999998 // Return value(Incorrect parameter error) 88 89 #ifndef MP4DMX_MPO_PARAMETER_END 90 ///Open Parameters(End flag) 91 #define MP4DMX_MPO_PARAMETER_END -1 92 #endif /* #ifndef MP4DMX_MPO_PARAMETER_END */ 93 94 #ifndef MP4DMX_MPO_OUTPUT_FUNCTION 95 #define MP4DMX_MPO_OUTPUT_FUNCTION 6000004 // Open Parameters(Output callback functions) 96 #endif /* #ifndef MP4DMX_MPO_OUTPUT_FUNCTION */ 97 98 /* 2007-05-15 */ 99 /***** for 'Mpo_UNIT' *****/ 100 /* for 'unit_code' member */ 101 #define MP4DMX_VIDEO_KEYFRAME 1 // Mpo_UNIT Structure unit_code(Key Frame) 102 /* for 'process_flag' member */ 103 #define MP4DMX_FLUSHED_DATA 1 // Mpo_UNIT Structure process_flag(Flash data) 104 105 /***** for 'Mpo_Mp4HeaderInf' *****/ 106 /* for 'mvexbox_exist_flag' member */ 107 #define MP4DMX_MVEX_BOX_EXIST 1 // Mpo_UNIT Structure mvexbox_exist_flag(MovieExtendsBox) 108 109 /***** for 'Mpo_Mp4TrackInf' *****/ 110 /* define for 'type' member */ 111 #define MP4DMX_VIDEO_TRACK 1 // Mpo_Mp4TrackInf Structure type(Video Track) 112 #define MP4DMX_AUDIO_TRACK 2 // Mpo_Mp4TrackInf Structure type(Audio Track) 113 #define MP4DMX_TEXT_TRACK 3 // Mpo_Mp4TrackInf Structure type(Text Track) 114 #define MP4DMX_OTHER_TRACK 4 // Mpo_Mp4TrackInf Structure type(Other Tracks) 115 /* define for 'supported_flag' member */ 116 #define MP4DMX_SUPPORTED_TRACK 1 // Mpo_Mp4TrackInf Structure supported_flag(Supported Track) 117 #define MP4DMX_UNSUPPORTED_TRACK 0 // Mpo_Mp4TrackInf Structure supported_flag(No Supported Track) 118 /* define for 'stts_exist_flag' member */ 119 #define MP4DMX_STTS_BOX_EXIST 1 // Mpo_Mp4TrackInf Structure stts_exist_flag(sttsBox) 120 /* define for 'tfra_exist_flag' member */ 121 #define MP4DMX_TFRA_BOX_EXIST 1 // Mpo_Mp4TrackInf Structure tfra_exist_flag(tfraBox) 122 123 /* for 'Mpo_Mp4VideoTrackInf', 'Mpo_Mp4AudioTrackInf', 'Mpo_Mp4TextTrackInf' */ 124 /* define for 'mediatype' member */ 125 #define MP4DMX_MEDIA_TYPE_MP4V 0x6D703476 // Mpo_Mp4VideoTrackInf Structure mediatype(mp4v) 126 #define MP4DMX_MEDIA_TYPE_S263 0x73323633 // Mpo_Mp4VideoTrackInf Structure mediatype(s263) 127 #define MP4DMX_MEDIA_TYPE_AVC1 0x61766331 // Mpo_Mp4VideoTrackInf Structure mediatype(avc1) 128 #define MP4DMX_MEDIA_TYPE_JPEG 0x6A706567 // Mpo_JpegVideoTrackInf Structure mediatype(jpeg) 129 130 #define MP4DMX_MEDIA_TYPE_MP4A 0x6D703461 // Mpo_Mp4AudioTrackInf Structure mediatype(mp4a) 131 #define MP4DMX_MEDIA_TYPE_SAMR 0x73616D72 // Mpo_Mp4AudioTrackInf Structure mediatype(samr) 132 #define MP4DMX_MEDIA_TYPE_ULAW 0x756C6177 // Mpo_Mp4AudioTrackInf Structure mediatype(ulaw) 133 134 #define MP4DMX_MEDIA_TYPE_TX3G 0x74783367 // Mpo_Mp4TextTrackInf Structure mediatype(tx3g) 135 /* define for 'channel_mode' member */ 136 #define MP4DMX_CHANNEL_MODE_MONO 1 // Mpo_Mp4AudioTrackInf Structure channel_mode(Monaural) 137 #define MP4DMX_CHANNEL_MODE_STEREO 2 // Mpo_Mp4AudioTrackInf Structure channel_mode(Stereo) 138 #define MP4DMX_CHANNEL_MODE_PS_STEREO 3 // Mpo_Mp4AudioTrackInf Structure channel_mode(Parametric Stereo) 139 /* define for 'sbr_enable_flag', 'ps_enable_flag' */ 140 #define MP4DMX_SBR_ENABLED 1 // Mpo_Mp4AudioTrackInf Structure sbr_enable_flag(SBR) 141 #define MP4DMX_PS_ENABLED 1 // Mpo_Mp4AudioTrackInf Structure sbr_enable_flag(Parametric Stereo) 142 #define MP4DMX_UNKNOWN_INFO -1 // All Structure(Value is uncertain) 143 /* define for 'track_id', 'end_time_stamp' */ 144 #define MP4DMX_UNASSIGNED_TRACK_ID -1 // All Structure track_id(Value is uncertain) 145 146 ///Execute Parameters EndTimeStamp Pending 147 #if( defined( _MSC_VER ) ) 148 #define MP4DMX_UNASSIGNED_END_TIME_STAMP 0xFFFFFFFFFFFFFFFFUI64 /* cpp50501 *//* 2007-06-05 No Problem */ 149 #else 150 #define MP4DMX_UNASSIGNED_END_TIME_STAMP 0xFFFFFFFFFFFFFFFFULL /* cpp50501 *//* 2007-06-05 No Problem */ 151 #endif 152 153 ///UserDataBox(Title, Author, Copyright, Description) Number of bytes that can be acquired 154 #define MP4DMX_UDTA_DATA_LENGTH 1024 155 ///MovieBox(Compatible Brand Data) Number of bytes that can be acquired 156 #define MP4DMX_COMPATIBLE_DATA_LENGTH 1024 157 158 159 /*--------------------------------------------- 160 * Structure 161 *----------------------------------------------*/ 162 163 #ifndef MP4DMX_STRUCT_MPO_UNIT 164 #define MP4DMX_STRUCT_MPO_UNIT 165 ///MP4 Sample Data Structure 166 typedef struct{ 167 ///Sample data start pointer 168 void *unit; 169 ///Sample data Size 170 s32 unit_size; 171 ///Sample data offset 172 s32 offset; 173 ///Point synchronization flag 174 s32 unit_code; 175 ///Time Stamp 176 u64 time_stamp; 177 ///Duration 178 s32 duration; 179 ///DescriptionIndex 180 s32 descript_index; 181 ///EEnd processing output flag 182 s32 process_flag; 183 ///Starting offset of the chunk 184 u64 chunk_offset; 185 ///Chunk Size 186 u64 chunk_size; 187 s32 num_of_sample; 188 ///Show Time offset(If there is a B picture is always zero) 189 ///Show Time(PTS) = time_stamp + cmp_offset 190 s32 cmp_offset; 191 ///reserved 192 s32 reserved[17]; 193 } MP4DMXMpoUNIT; 194 #endif /* #ifndef MP4DMX_STRUCT_MPO_UNIT */ 195 196 197 #ifndef MP4DMX_STRUCT_MP4_AVC_PARAMSETS 198 #define MP4DMX_STRUCT_MP4_AVC_PARAMSETS 199 ///AVC Parameter Set Structure 200 typedef struct { 201 ///File offset of the beginning of the parameter set 202 s32 offset; 203 ///The number of bytes of parameter set data 204 s32 length; 205 } MP4DMXAvcParamSets; 206 #endif /* #ifndef STRUCT_MP4_AVC_PARAMSETS */ 207 208 209 #ifndef MP4DMX_STRUCT_MP4_AVC_CONFIG 210 #define MP4DMX_STRUCT_MP4_AVC_CONFIG 211 ///AVC Configuration Structure 212 typedef struct { 213 ///The number of bytes of data byte length 214 s32 length_size; 215 ///SPS 216 s32 number_of_sps; 217 ///SPS 218 MP4DMXAvcParamSets SPS[32]; 219 ///PPS 220 s32 number_of_pps; 221 ///PPS 222 MP4DMXAvcParamSets PPS[256]; 223 } MP4DMXAvcConfig; 224 #endif /* #ifndef MP4DMX_STRUCT_MP4_AVC_CONFIG */ 225 226 227 #ifndef MP4DMX_STRUCT_MPO_DATA 228 #define MP4DMX_STRUCT_MPO_DATA 229 ///Store the input and output sample Structure 230 typedef struct{ 231 /* input */ 232 ///AV Data Structure void Pointer 233 void **data; 234 ///AV Data Structure 235 s32 unit_num; 236 ///Always Zero 237 s32 data_cnt; 238 /* output */ 239 ///Amount of data processed in the callback function 240 s32 used_unit_num; 241 } MP4DMXMpoDATA; 242 #endif /* #ifndef MP4DMX_STRUCT_MPO_DATA */ 243 244 245 #ifndef MP4DMX_STRUCT_MPO_PARAMETER 246 #define MP4DMX_STRUCT_MPO_PARAMETER 247 ///Open Parameter Structure 248 typedef struct{ 249 union{ 250 ///32-bit Value 251 s32 int32; 252 ///64-bit Value 253 f64 real64; 254 ///Pointer Value 255 void *ptr; 256 } 257 ///Parameter Value 258 value; 259 ///Parameter ID 260 s32 id; 261 } MP4DMXMpoPARAMETER; 262 #endif /* #ifndef MP4DMX_STRUCT_MPO_PARAMETER */ 263 264 265 #ifndef MP4DMX_STRUCT_MPO_OUTPUT_FUNCTION 266 #define MP4DMX_STRUCT_MPO_OUTPUT_FUNCTION 267 ///Callback function Structure 268 typedef struct{ 269 ///Pointer to a callback function 270 s32 (*output_fptr)(MP4DMXMpoDATA*, int, void*); 271 ///Arguments to the callback function 272 void *handle; 273 } MP4DMXMpoOutputFunction; 274 #endif /* #ifndef MP4DMX_STRUCT_MPO_OUTPUT_FUNCTION */ 275 276 277 #ifndef MP4DMX_STRUCT_MPO_OUTPUT_LOG_FUNCTION 278 #define MP4DMX_STRUCT_MPO_OUTPUT_LOG_FUNCTION 279 ///Log output callback function Structure 280 typedef struct{ 281 ///Pointer to a callback function 282 s32 (*output_fptr)(u8 *,int,void *); 283 ///Arguments to the callback function 284 void *handle; 285 } MP4DMXMpoOutputLogFunction; 286 #endif /* #ifndef MP4DMX_STRUCT_MPO_OUTPUT_LOG_FUNCTION */ 287 288 289 #ifndef MP4DMX_STRUCT_MPO_MP4HEADERINF 290 #define MP4DMX_STRUCT_MPO_MP4HEADERINF 291 ///MP4Movie Header Information Structure 292 typedef struct{ 293 ///moov header size 294 s32 size; 295 ///time scale 296 s32 timescale; 297 ///moov Play Time(Conversion time scale) 298 u64 duration; 299 ///Total playing time, including the fragment(Conversion time scale) 300 u64 fragment_duration; 301 ///Flags whether there is the mvex Box 302 s32 mvexbox_exist_flag; 303 ///Playback Rate 304 s32 rate; 305 ///Playback volume 306 s32 volume; 307 ///The number of tracks contained in the moov header 308 s32 track_num; 309 ///Major Brand 310 u8 major_brand[5]; 311 ///Minor Version 312 s32 minor_version; 313 ///Number of Compatible Brands 314 s32 compatible_brands_num; 315 ///Compatible Brand 316 u8 compatible_brands[MP4DMX_COMPATIBLE_DATA_LENGTH]; 317 ///Creation Time 318 u64 creation_time; 319 ///Modification Time 320 u64 modification_time; 321 ///The number of bytes Title information 322 s32 title_length; 323 ///The number of bytes Author information 324 s32 author_length; 325 ///The number of bytes Copyright information 326 s32 copyright_length; 327 ///The number of bytes Description 328 s32 description_length; 329 ///language code of title 330 u16 title_language; 331 ///language code of author 332 u16 author_language; 333 ///language code of copyright 334 u16 copyright_language; 335 ///language code of description 336 u16 description_language; 337 ///Title 338 u8 title[MP4DMX_UDTA_DATA_LENGTH]; 339 ///Author 340 u8 author[MP4DMX_UDTA_DATA_LENGTH]; 341 ///Copyright 342 u8 copyright[MP4DMX_UDTA_DATA_LENGTH]; 343 ///Description 344 u8 description[MP4DMX_UDTA_DATA_LENGTH]; 345 } MP4DMXMpoMp4HeaderInf; 346 #endif /* #ifndef MP4DMX_STRUCT_MPO_MP4HEADERINF */ 347 348 349 #ifndef MP4DMX_STRUCT_MPO_MP4TRACKINF 350 #define MP4DMX_STRUCT_MPO_MP4TRACKINF 351 ///Track Information Structure 352 typedef struct{ 353 ///track ID 354 s32 track_ID; 355 ///time scale 356 s32 timescale; 357 ///Track playing time(Conversion time scale) 358 u64 duration; 359 ///Media type of the track 360 s32 type; 361 ///Flags whether to support the demultiplexer 362 s32 supported_flag; 363 ///Flags whether there is the stts Box 364 s32 stts_exist_flag; 365 ///Flags whether there is the tfra Box 366 s32 tfra_exist_flag; 367 ///Number of SampleEntry 368 s32 num_of_entry; 369 } MP4DMXMpoMp4TrackInf; 370 #endif /* #ifndef MP4DMX_STRUCT_MPO_MP4TRACKINF */ 371 372 373 #ifndef MP4DMX_STRUCT_MPO_MP4_VIDEOTRACKINF 374 #define MP4DMX_STRUCT_MPO_MP4_VIDEOTRACKINF 375 ///Video Track Information Structure 376 typedef struct{ 377 ///Video track size 378 s32 size; 379 ///Image Width[pixel] 380 s32 width; 381 ///Image Height[pixel] 382 s32 height; 383 ///Maximum bit rate, in bits per second 384 s32 maxbitrate; 385 ///Average bit rate, in bits per second 386 s32 avgbitrate; 387 ///Media type of video 388 s32 mediatype; 389 ///Maximum frame rate[frame / 1000s] 390 s32 framerate; 391 ///Video Profile 392 u8 profile; 393 ///Video Level 394 s32 level; 395 } MP4DMXMpoMp4VideoTrackInf; 396 #endif /* #ifndef MP4DMX_STRUCT_MPO_MP4_VIDEOTRACKINF */ 397 398 399 #ifndef MP4DMX_STRUCT_MPO_MP4_AUDIOTRACKINF 400 #define MP4DMX_STRUCT_MPO_MP4_AUDIOTRACKINF 401 ///Audio Track Information Structure 402 typedef struct 403 { 404 ///Audio Track Size 405 s32 size; 406 ///The playback volume 407 s32 volume; 408 ///Number of Channels 409 s32 channel_count; 410 ///Size of sample 411 s32 sample_size; 412 ///Audio Time Scale 413 s32 sample_rate; 414 ///Maximum bit rate, in bits per second 415 s32 maxbitrate; 416 ///Average bit rate, in bits per second 417 s32 avgbitrate; 418 ///Media type of audio 419 s32 mediatype; 420 ///Number of Channels 421 s32 channel_mode; 422 ///Audio Object Type 423 s32 audio_object_type; 424 ///Object Type 425 s32 object_type_indication; 426 ///SBR flag 427 s32 sbr_enable_flag; 428 ///ParametricStereo flag 429 s32 ps_enable_flag; 430 ///The number of offset bytes from the beginning of the file of the first frame 431 #ifndef _TYPE_CO64 432 s32 top_frame_offset; 433 #else 434 u64 top_frame_offset; 435 #endif /*_TYPE_CO64*/ 436 ///The number of bytes in the first frame 437 s32 top_frame_size; 438 } MP4DMXMpoMp4AudioTrackInf; 439 #endif /* #ifndef MP4DMX_STRUCT_MPO_MP4_AUDIOTRACKINF */ 440 441 /* -------------------------- 442 open 443 -------------------------- */ 444 s32 445 MP4DMXOpen( 446 MP4DMXMpoPARAMETER *parameter, 447 void **handle_ret, 448 void *allocator 449 ); 450 451 /* -------------------------- 452 begin 453 -------------------------- */ 454 s32 455 MP4DMXBegin( 456 void *handle 457 ); 458 459 /* -------------------------- 460 execute 461 -------------------------- */ 462 s32 463 MP4DMXExecute( 464 void *data, 465 s32 control_flag, 466 s32 track_id, 467 s32 seek_direction, 468 u64 end_time_stamp, 469 u64 *time_stamp, 470 u64 *next_offset, 471 s32 *next_size, 472 void *handle 473 ); 474 475 /* -------------------------- 476 end 477 -------------------------- */ 478 s32 479 MP4DMXEnd( 480 void *handle 481 ); 482 483 /* -------------------------- 484 close 485 -------------------------- */ 486 s32 487 MP4DMXClose( 488 void *handle, 489 void *allocator 490 ); 491 492 ///Get Header position 493 s32 494 MP4DMXFindHeader( 495 void *data, 496 s32 size, 497 u64 *next_offset, 498 s32 *next_size, 499 void *handle 500 ); 501 ///Header analysis 502 s32 503 MP4DMXReadHeader( 504 void *data, 505 u64 *time_stamp, 506 u64 *next_offset, 507 s32 *next_size, 508 void *handle 509 ); 510 511 ///Get Movie Header information 512 s32 513 MP4DMXGetHeaderInf( 514 MP4DMXMpoMp4HeaderInf *mp4headerInf, 515 void *handle 516 ); 517 518 ///Get Track information 519 s32 520 MP4DMXGetTrackInf( 521 s32 track_index, 522 MP4DMXMpoMp4TrackInf *mp4TrackInf, 523 void *handle 524 ); 525 526 ///Get Video Track information 527 s32 528 MP4DMXGetVideoTrackInf( 529 s32 trackID, 530 MP4DMXMpoMp4VideoTrackInf *mp4VideoTrackInf, 531 void *handle 532 ); 533 534 ///Get Audio Track information 535 s32 536 MP4DMXGetAudioTrackInf( 537 s32 trackID, 538 MP4DMXMpoMp4AudioTrackInf *mp4AudioTrackInf, 539 void *handle 540 ); 541 542 ///Get AVC information 543 s32 544 MP4DMXGetAVCSpecificInf( 545 s32 sample_index, 546 MP4DMXAvcConfig *data, 547 void *handle 548 ); 549 550 ///Get Decoder specific information 551 s32 552 MP4DMXGetDecoderSpecificInf( 553 s32 trackID, 554 s32 sample_index, 555 void *data, 556 s32 *size, 557 void *handle 558 ); 559 560 #ifdef __cplusplus 561 } 562 #endif /* #ifdef __cplusplus */ 563 564 #endif // __MP4DMX_H__ 565