/*********************************************************** * * Copyright (C) 2012 PUX Corporation * All Rights Reserved. * ***********************************************************/ #ifndef __MP4DMX_H__ #define __MP4DMX_H__ #ifdef __cplusplus extern "C"{ #endif /* #ifdef __cplusplus */ /******************************************** Return Definition *********************************************/ #define MP4DMX_RET_NO_MORE_CHUNK 1000000 #define MP4DMX_RET_FOUND_MOOV_BOX 2000000 #define MP4DMX_RET_FOUND_MOOF_BOX 2000001 #define MP4DMX_RET_FOUND_MFRA_BOX 2000002 #define MP4DMX_RET_FOUND_MFRO_BOX 2000003 #define MP4DMX_RET_NOT_FOUND_BOX 2000004 #define MP4DMX_RET_FOUND_FTYP_BOX 2000005 #define MP4DMX_RET_FIND_HEADER 2000006 #define MP4DMX_RET_READ_HEADER 2000007 #define MP4DMX_RET_EXECUTE_NORMAL 2000008 #define MP4DMX_RET_EXECUTE_WARNING 2000009 #define MP4DMX_RET_INPUT_CONTINUE 2000010 #define MP4DMX_RET_ERROR_FILE_IO -9999997 #define MP4DMX_RET_ERROR_INVALID_POINTER -9999996 #define MP4DMX_RET_ERROR_FATAL -9999995 #define MP4DMX_RET_ERROR_SYSTEM_BUFFER_OVERFLOW -9999994 #define MP4DMX_RET_ERROR_BAD_USER_ID -9999993 #define MP4DMX_RET_ERROR_BAD_STREAM -9999992 #define MP4DMX_RET_ERROR_BAD_TIMESTAMP -9999991 #define MP4DMX_RET_INVALID_TRACK_ID -9999990 #define MP4DMX_RET_INVALID_TRACK_INDEX -9999989 #define MP4DMX_RET_NOT_FOUND -9999988 #define MP4DMX_SEEK_NORMAL 0 #define MP4DMX_SEEK_BACKWARD 1 #define MP4DMX_SEEK_FORWARD 2 #define MP4DMX_TIME_FORMAT_TIMESTAMP 1 #define MP4DMX_TIME_FORMAT_VIDEOFRAME 2 /******************************************** Parameter Definition *********************************************/ ///The starting value of the open parameters #define MP4DMX_MPO_PARAM_TOP 81004000 ///Open Parameter ID enum MP4DMXParamENUM { MP4DMX_OUT_VIDEO_FLAG = MP4DMX_MPO_PARAM_TOP, // Parameter ID to set the video output flag MP4DMX_OUT_AUDIO_FLAG, // Parameter ID to set the audio output flag MP4DMX_OUT_TEXT_FLAG, // Parameter ID to set the text output flag MP4DMX_OUT_ONLY_KEYFRAME, // Parameter ID to set the output flag is only the key frames MP4DMX_SIMPLE_PROCESS, // Parameter ID to set a simple fade speed processing flag MP4DMX_INPUT_VIDEO_BUFFER_NUM, // Parameter ID to set the number of elements of a video ring buffer MP4DMX_INPUT_AUDIO_BUFFER_NUM, // Parameter ID to set the number of elements of the audio ring buffer MP4DMX_INPUT_TEXT_BUFFER_NUM, // Parameter ID to set the number of ring buffer elements of the text MP4DMX_GET_BINARY_BOX_TYPE, // Parameter ID to set the Box type to keep binary data MP4DMX_STSZ_READ_BUFFER_SIZE, // Maximum memory size of sample entries maintained STSZ at one MP4DMX_STTS_READ_BUFFER_SIZE, // Maximum memory size of sample entries maintained STTS at one MP4DMX_MAX_ENTRY_NUM, // The maximum number of entries MP4DMX_MAX_SAMPLE_NUM, // Maximum number of samples MP4DMX_MAX_CHUNK_NUM, // Maximum number of chunks MP4DMX_CTTS_READ_BUFFER_SIZE // Maximum memory size of sample entries maintained CTTS at one }; /******************************************** Parameter Definition *********************************************/ #ifndef MP4DMX_RET_SUCCESS #define MP4DMX_RET_SUCCESS 0 // Return value(Successful completion) #endif /* #ifndef MP4DMX_RET_SUCCESS */ #ifndef MP4DMX_RET_ERROR #define MP4DMX_RET_ERROR -1 // Return value(Error) #endif /* #ifndef MP4DMX_RET_ERROR */ #define MP4DMX_RET_OK 0 // Return value(Successful completion) #define MP4DMX_RET_NG -1 // Return value(Failure) #define MP4DMX_RET_WAIT -16 // Return value(Wait for instructions from the callback function) #define MP4DMX_RET_ERROR_NOT_ENOUGH_MEMORY -9999999 // Return value(Out of memory error) #define MP4DMX_RET_ERROR_BADPARAM -9999998 // Return value(Incorrect parameter error) #ifndef MP4DMX_MPO_PARAMETER_END ///Open Parameters(End flag) #define MP4DMX_MPO_PARAMETER_END -1 #endif /* #ifndef MP4DMX_MPO_PARAMETER_END */ #ifndef MP4DMX_MPO_OUTPUT_FUNCTION #define MP4DMX_MPO_OUTPUT_FUNCTION 6000004 // Open Parameters(Output callback functions) #endif /* #ifndef MP4DMX_MPO_OUTPUT_FUNCTION */ /* 2007-05-15 */ /***** for 'Mpo_UNIT' *****/ /* for 'unit_code' member */ #define MP4DMX_VIDEO_KEYFRAME 1 // Mpo_UNIT Structure unit_code(Key Frame) /* for 'process_flag' member */ #define MP4DMX_FLUSHED_DATA 1 // Mpo_UNIT Structure process_flag(Flash data) /***** for 'Mpo_Mp4HeaderInf' *****/ /* for 'mvexbox_exist_flag' member */ #define MP4DMX_MVEX_BOX_EXIST 1 // Mpo_UNIT Structure mvexbox_exist_flag(MovieExtendsBox) /***** for 'Mpo_Mp4TrackInf' *****/ /* define for 'type' member */ #define MP4DMX_VIDEO_TRACK 1 // Mpo_Mp4TrackInf Structure type(Video Track) #define MP4DMX_AUDIO_TRACK 2 // Mpo_Mp4TrackInf Structure type(Audio Track) #define MP4DMX_TEXT_TRACK 3 // Mpo_Mp4TrackInf Structure type(Text Track) #define MP4DMX_OTHER_TRACK 4 // Mpo_Mp4TrackInf Structure type(Other Tracks) /* define for 'supported_flag' member */ #define MP4DMX_SUPPORTED_TRACK 1 // Mpo_Mp4TrackInf Structure supported_flag(Supported Track) #define MP4DMX_UNSUPPORTED_TRACK 0 // Mpo_Mp4TrackInf Structure supported_flag(No Supported Track) /* define for 'stts_exist_flag' member */ #define MP4DMX_STTS_BOX_EXIST 1 // Mpo_Mp4TrackInf Structure stts_exist_flag(sttsBox) /* define for 'tfra_exist_flag' member */ #define MP4DMX_TFRA_BOX_EXIST 1 // Mpo_Mp4TrackInf Structure tfra_exist_flag(tfraBox) /* for 'Mpo_Mp4VideoTrackInf', 'Mpo_Mp4AudioTrackInf', 'Mpo_Mp4TextTrackInf' */ /* define for 'mediatype' member */ #define MP4DMX_MEDIA_TYPE_MP4V 0x6D703476 // Mpo_Mp4VideoTrackInf Structure mediatype(mp4v) #define MP4DMX_MEDIA_TYPE_S263 0x73323633 // Mpo_Mp4VideoTrackInf Structure mediatype(s263) #define MP4DMX_MEDIA_TYPE_AVC1 0x61766331 // Mpo_Mp4VideoTrackInf Structure mediatype(avc1) #define MP4DMX_MEDIA_TYPE_JPEG 0x6A706567 // Mpo_JpegVideoTrackInf Structure mediatype(jpeg) #define MP4DMX_MEDIA_TYPE_MP4A 0x6D703461 // Mpo_Mp4AudioTrackInf Structure mediatype(mp4a) #define MP4DMX_MEDIA_TYPE_SAMR 0x73616D72 // Mpo_Mp4AudioTrackInf Structure mediatype(samr) #define MP4DMX_MEDIA_TYPE_ULAW 0x756C6177 // Mpo_Mp4AudioTrackInf Structure mediatype(ulaw) #define MP4DMX_MEDIA_TYPE_TX3G 0x74783367 // Mpo_Mp4TextTrackInf Structure mediatype(tx3g) /* define for 'channel_mode' member */ #define MP4DMX_CHANNEL_MODE_MONO 1 // Mpo_Mp4AudioTrackInf Structure channel_mode(Monaural) #define MP4DMX_CHANNEL_MODE_STEREO 2 // Mpo_Mp4AudioTrackInf Structure channel_mode(Stereo) #define MP4DMX_CHANNEL_MODE_PS_STEREO 3 // Mpo_Mp4AudioTrackInf Structure channel_mode(Parametric Stereo) /* define for 'sbr_enable_flag', 'ps_enable_flag' */ #define MP4DMX_SBR_ENABLED 1 // Mpo_Mp4AudioTrackInf Structure sbr_enable_flag(SBR) #define MP4DMX_PS_ENABLED 1 // Mpo_Mp4AudioTrackInf Structure sbr_enable_flag(Parametric Stereo) #define MP4DMX_UNKNOWN_INFO -1 // All Structure(Value is uncertain) /* define for 'track_id', 'end_time_stamp' */ #define MP4DMX_UNASSIGNED_TRACK_ID -1 // All Structure track_id(Value is uncertain) ///Execute Parameters EndTimeStamp Pending #if( defined( _MSC_VER ) ) #define MP4DMX_UNASSIGNED_END_TIME_STAMP 0xFFFFFFFFFFFFFFFFUI64 /* cpp50501 *//* 2007-06-05 No Problem */ #else #define MP4DMX_UNASSIGNED_END_TIME_STAMP 0xFFFFFFFFFFFFFFFFULL /* cpp50501 *//* 2007-06-05 No Problem */ #endif ///UserDataBox(Title, Author, Copyright, Description) Number of bytes that can be acquired #define MP4DMX_UDTA_DATA_LENGTH 1024 ///MovieBox(Compatible Brand Data) Number of bytes that can be acquired #define MP4DMX_COMPATIBLE_DATA_LENGTH 1024 /*--------------------------------------------- * Structure *----------------------------------------------*/ #ifndef MP4DMX_STRUCT_MPO_UNIT #define MP4DMX_STRUCT_MPO_UNIT ///MP4 Sample Data Structure typedef struct{ ///Sample data start pointer void *unit; ///Sample data Size s32 unit_size; ///Sample data offset s32 offset; ///Point synchronization flag s32 unit_code; ///Time Stamp u64 time_stamp; ///Duration s32 duration; ///DescriptionIndex s32 descript_index; ///EEnd processing output flag s32 process_flag; ///Starting offset of the chunk u64 chunk_offset; ///Chunk Size u64 chunk_size; s32 num_of_sample; ///Show Time offset(If there is a B picture is always zero) ///Show Time(PTS) = time_stamp + cmp_offset s32 cmp_offset; ///reserved s32 reserved[17]; } MP4DMXMpoUNIT; #endif /* #ifndef MP4DMX_STRUCT_MPO_UNIT */ #ifndef MP4DMX_STRUCT_MP4_AVC_PARAMSETS #define MP4DMX_STRUCT_MP4_AVC_PARAMSETS ///AVC Parameter Set Structure typedef struct { ///File offset of the beginning of the parameter set s32 offset; ///The number of bytes of parameter set data s32 length; } MP4DMXAvcParamSets; #endif /* #ifndef STRUCT_MP4_AVC_PARAMSETS */ #ifndef MP4DMX_STRUCT_MP4_AVC_CONFIG #define MP4DMX_STRUCT_MP4_AVC_CONFIG ///AVC Configuration Structure typedef struct { ///The number of bytes of data byte length s32 length_size; ///SPS s32 number_of_sps; ///SPS MP4DMXAvcParamSets SPS[32]; ///PPS s32 number_of_pps; ///PPS MP4DMXAvcParamSets PPS[256]; } MP4DMXAvcConfig; #endif /* #ifndef MP4DMX_STRUCT_MP4_AVC_CONFIG */ #ifndef MP4DMX_STRUCT_MPO_DATA #define MP4DMX_STRUCT_MPO_DATA ///Store the input and output sample Structure typedef struct{ /* input */ ///AV Data Structure void Pointer void **data; ///AV Data Structure s32 unit_num; ///Always Zero s32 data_cnt; /* output */ ///Amount of data processed in the callback function s32 used_unit_num; } MP4DMXMpoDATA; #endif /* #ifndef MP4DMX_STRUCT_MPO_DATA */ #ifndef MP4DMX_STRUCT_MPO_PARAMETER #define MP4DMX_STRUCT_MPO_PARAMETER ///Open Parameter Structure typedef struct{ union{ ///32-bit Value s32 int32; ///64-bit Value f64 real64; ///Pointer Value void *ptr; } ///Parameter Value value; ///Parameter ID s32 id; } MP4DMXMpoPARAMETER; #endif /* #ifndef MP4DMX_STRUCT_MPO_PARAMETER */ #ifndef MP4DMX_STRUCT_MPO_OUTPUT_FUNCTION #define MP4DMX_STRUCT_MPO_OUTPUT_FUNCTION ///Callback function Structure typedef struct{ ///Pointer to a callback function s32 (*output_fptr)(MP4DMXMpoDATA*, int, void*); ///Arguments to the callback function void *handle; } MP4DMXMpoOutputFunction; #endif /* #ifndef MP4DMX_STRUCT_MPO_OUTPUT_FUNCTION */ #ifndef MP4DMX_STRUCT_MPO_OUTPUT_LOG_FUNCTION #define MP4DMX_STRUCT_MPO_OUTPUT_LOG_FUNCTION ///Log output callback function Structure typedef struct{ ///Pointer to a callback function s32 (*output_fptr)(u8 *,int,void *); ///Arguments to the callback function void *handle; } MP4DMXMpoOutputLogFunction; #endif /* #ifndef MP4DMX_STRUCT_MPO_OUTPUT_LOG_FUNCTION */ #ifndef MP4DMX_STRUCT_MPO_MP4HEADERINF #define MP4DMX_STRUCT_MPO_MP4HEADERINF ///MP4Movie Header Information Structure typedef struct{ ///moov header size s32 size; ///time scale s32 timescale; ///moov Play Time(Conversion time scale) u64 duration; ///Total playing time, including the fragment(Conversion time scale) u64 fragment_duration; ///Flags whether there is the mvex Box s32 mvexbox_exist_flag; ///Playback Rate s32 rate; ///Playback volume s32 volume; ///The number of tracks contained in the moov header s32 track_num; ///Major Brand u8 major_brand[5]; ///Minor Version s32 minor_version; ///Number of Compatible Brands s32 compatible_brands_num; ///Compatible Brand u8 compatible_brands[MP4DMX_COMPATIBLE_DATA_LENGTH]; ///Creation Time u64 creation_time; ///Modification Time u64 modification_time; ///The number of bytes Title information s32 title_length; ///The number of bytes Author information s32 author_length; ///The number of bytes Copyright information s32 copyright_length; ///The number of bytes Description s32 description_length; ///language code of title u16 title_language; ///language code of author u16 author_language; ///language code of copyright u16 copyright_language; ///language code of description u16 description_language; ///Title u8 title[MP4DMX_UDTA_DATA_LENGTH]; ///Author u8 author[MP4DMX_UDTA_DATA_LENGTH]; ///Copyright u8 copyright[MP4DMX_UDTA_DATA_LENGTH]; ///Description u8 description[MP4DMX_UDTA_DATA_LENGTH]; } MP4DMXMpoMp4HeaderInf; #endif /* #ifndef MP4DMX_STRUCT_MPO_MP4HEADERINF */ #ifndef MP4DMX_STRUCT_MPO_MP4TRACKINF #define MP4DMX_STRUCT_MPO_MP4TRACKINF ///Track Information Structure typedef struct{ ///track ID s32 track_ID; ///time scale s32 timescale; ///Track playing time(Conversion time scale) u64 duration; ///Media type of the track s32 type; ///Flags whether to support the demultiplexer s32 supported_flag; ///Flags whether there is the stts Box s32 stts_exist_flag; ///Flags whether there is the tfra Box s32 tfra_exist_flag; ///Number of SampleEntry s32 num_of_entry; } MP4DMXMpoMp4TrackInf; #endif /* #ifndef MP4DMX_STRUCT_MPO_MP4TRACKINF */ #ifndef MP4DMX_STRUCT_MPO_MP4_VIDEOTRACKINF #define MP4DMX_STRUCT_MPO_MP4_VIDEOTRACKINF ///Video Track Information Structure typedef struct{ ///Video track size s32 size; ///Image Width[pixel] s32 width; ///Image Height[pixel] s32 height; ///Maximum bit rate, in bits per second s32 maxbitrate; ///Average bit rate, in bits per second s32 avgbitrate; ///Media type of video s32 mediatype; ///Maximum frame rate[frame / 1000s] s32 framerate; ///Video Profile u8 profile; ///Video Level s32 level; } MP4DMXMpoMp4VideoTrackInf; #endif /* #ifndef MP4DMX_STRUCT_MPO_MP4_VIDEOTRACKINF */ #ifndef MP4DMX_STRUCT_MPO_MP4_AUDIOTRACKINF #define MP4DMX_STRUCT_MPO_MP4_AUDIOTRACKINF ///Audio Track Information Structure typedef struct { ///Audio Track Size s32 size; ///The playback volume s32 volume; ///Number of Channels s32 channel_count; ///Size of sample s32 sample_size; ///Audio Time Scale s32 sample_rate; ///Maximum bit rate, in bits per second s32 maxbitrate; ///Average bit rate, in bits per second s32 avgbitrate; ///Media type of audio s32 mediatype; ///Number of Channels s32 channel_mode; ///Audio Object Type s32 audio_object_type; ///Object Type s32 object_type_indication; ///SBR flag s32 sbr_enable_flag; ///ParametricStereo flag s32 ps_enable_flag; ///The number of offset bytes from the beginning of the file of the first frame #ifndef _TYPE_CO64 s32 top_frame_offset; #else u64 top_frame_offset; #endif /*_TYPE_CO64*/ ///The number of bytes in the first frame s32 top_frame_size; } MP4DMXMpoMp4AudioTrackInf; #endif /* #ifndef MP4DMX_STRUCT_MPO_MP4_AUDIOTRACKINF */ /* -------------------------- open -------------------------- */ s32 MP4DMXOpen( MP4DMXMpoPARAMETER *parameter, void **handle_ret, void *allocator ); /* -------------------------- begin -------------------------- */ s32 MP4DMXBegin( void *handle ); /* -------------------------- execute -------------------------- */ s32 MP4DMXExecute( void *data, s32 control_flag, s32 track_id, s32 seek_direction, u64 end_time_stamp, u64 *time_stamp, u64 *next_offset, s32 *next_size, void *handle ); /* -------------------------- end -------------------------- */ s32 MP4DMXEnd( void *handle ); /* -------------------------- close -------------------------- */ s32 MP4DMXClose( void *handle, void *allocator ); ///Get Header position s32 MP4DMXFindHeader( void *data, s32 size, u64 *next_offset, s32 *next_size, void *handle ); ///Header analysis s32 MP4DMXReadHeader( void *data, u64 *time_stamp, u64 *next_offset, s32 *next_size, void *handle ); ///Get Movie Header information s32 MP4DMXGetHeaderInf( MP4DMXMpoMp4HeaderInf *mp4headerInf, void *handle ); ///Get Track information s32 MP4DMXGetTrackInf( s32 track_index, MP4DMXMpoMp4TrackInf *mp4TrackInf, void *handle ); ///Get Video Track information s32 MP4DMXGetVideoTrackInf( s32 trackID, MP4DMXMpoMp4VideoTrackInf *mp4VideoTrackInf, void *handle ); ///Get Audio Track information s32 MP4DMXGetAudioTrackInf( s32 trackID, MP4DMXMpoMp4AudioTrackInf *mp4AudioTrackInf, void *handle ); ///Get AVC information s32 MP4DMXGetAVCSpecificInf( s32 sample_index, MP4DMXAvcConfig *data, void *handle ); ///Get Decoder specific information s32 MP4DMXGetDecoderSpecificInf( s32 trackID, s32 sample_index, void *data, s32 *size, void *handle ); #ifdef __cplusplus } #endif /* #ifdef __cplusplus */ #endif // __MP4DMX_H__