📄 mp4file.h
字号:
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is MPEG4IP.
*
* The Initial Developer of the Original Code is Cisco Systems Inc.
* Portions created by Cisco Systems Inc. are
* Copyright (C) Cisco Systems Inc. 2001. All Rights Reserved.
*
* Contributor(s):
* Dave Mackie dmackie@cisco.com
* Alix Marchandise-Franquet alix@cisco.com
*/
#ifndef __MP4_FILE_INCLUDED__
#define __MP4_FILE_INCLUDED__
// forward declarations
class MP4Atom;
class MP4Property;
class MP4Float32Property;
class MP4StringProperty;
class MP4BytesProperty;
class MP4Descriptor;
class MP4DescriptorProperty;
#ifdef USE_FILE_CALLBACKS
typedef u_int32_t (*MP4OpenCallback)(const char *pName, const char *mode, void *userData);
typedef void (*MP4CloseCallback)(void *userData);
typedef u_int32_t (*MP4ReadCallback)(void *pBuffer, unsigned int nBytesToRead, void *userData);
typedef u_int32_t (*MP4WriteCallback)(void *pBuffer, unsigned int nBytesToWrite, void *userData);
typedef int32_t (*MP4SetposCallback)(u_int32_t pos, void *userData);
typedef int64_t (*MP4GetposCallback)(void *userData);
typedef int64_t (*MP4FilesizeCallback)(void *userData);
#endif
class MP4File {
public: /* equivalent to MP4 library API */
MP4File(u_int32_t verbosity = 0);
~MP4File();
/* file operations */
void Read(const char* fileName);
void Create(const char* fileName, bool use64bits);
void Modify(const char* fileName);
void Optimize(const char* orgFileName,
const char* newFileName = NULL);
void Dump(FILE* pDumpFile = NULL, bool dumpImplicits = false);
void Close();
/* library property per file */
u_int32_t GetVerbosity() {
return m_verbosity;
}
void SetVerbosity(u_int32_t verbosity) {
m_verbosity = verbosity;
}
bool Use64Bits() {
return m_use64bits;
}
/* file properties */
u_int64_t GetIntegerProperty(const char* name);
float GetFloatProperty(const char* name);
const char* GetStringProperty(const char* name);
void GetBytesProperty(const char* name,
u_int8_t** ppValue, u_int32_t* pValueSize);
void SetIntegerProperty(const char* name, u_int64_t value);
void SetFloatProperty(const char* name, float value);
void SetStringProperty(const char* name, const char* value);
void SetBytesProperty(const char* name,
const u_int8_t* pValue, u_int32_t valueSize);
// file level convenience functions
MP4Duration GetDuration();
void SetDuration(MP4Duration value);
u_int32_t GetTimeScale();
void SetTimeScale(u_int32_t value);
u_int8_t GetODProfileLevel();
void SetODProfileLevel(u_int8_t value);
u_int8_t GetSceneProfileLevel();
void SetSceneProfileLevel(u_int8_t value);
u_int8_t GetVideoProfileLevel();
void SetVideoProfileLevel(u_int8_t value);
u_int8_t GetAudioProfileLevel();
void SetAudioProfileLevel(u_int8_t value);
u_int8_t GetGraphicsProfileLevel();
void SetGraphicsProfileLevel(u_int8_t value);
const char* GetSessionSdp();
void SetSessionSdp(const char* sdpString);
void AppendSessionSdp(const char* sdpString);
/* track operations */
MP4TrackId AddTrack(const char* type, u_int32_t timeScale = 1000);
void DeleteTrack(MP4TrackId trackId);
u_int32_t GetNumberOfTracks(const char* type = NULL, u_int8_t subType = 0);
MP4TrackId AllocTrackId();
MP4TrackId FindTrackId(u_int16_t trackIndex,
const char* type = NULL, u_int8_t subType = 0);
u_int16_t FindTrackIndex(MP4TrackId trackId);
u_int16_t FindTrakAtomIndex(MP4TrackId trackId);
/* track properties */
u_int64_t GetTrackIntegerProperty(
MP4TrackId trackId, const char* name);
float GetTrackFloatProperty(
MP4TrackId trackId, const char* name);
const char* GetTrackStringProperty(
MP4TrackId trackId, const char* name);
void GetTrackBytesProperty(
MP4TrackId trackId, const char* name,
u_int8_t** ppValue, u_int32_t* pValueSize);
void SetTrackIntegerProperty(
MP4TrackId trackId, const char* name, int64_t value);
void SetTrackFloatProperty(
MP4TrackId trackId, const char* name, float value);
void SetTrackStringProperty(
MP4TrackId trackId, const char* name, const char* value);
void SetTrackBytesProperty(
MP4TrackId trackId, const char* name,
const u_int8_t* pValue, u_int32_t valueSize);
/* sample operations */
u_int32_t GetSampleSize(MP4TrackId trackId, MP4SampleId sampleId);
u_int32_t GetTrackMaxSampleSize(MP4TrackId trackId);
MP4SampleId GetSampleIdFromTime(MP4TrackId trackId,
MP4Timestamp when, bool wantSyncSample = false);
MP4Timestamp GetSampleTime(
MP4TrackId trackId, MP4SampleId sampleId);
MP4Duration GetSampleDuration(
MP4TrackId trackId, MP4SampleId sampleId);
MP4Duration GetSampleRenderingOffset(
MP4TrackId trackId, MP4SampleId sampleId);
bool GetSampleSync(
MP4TrackId trackId, MP4SampleId sampleId);
void ReadSample(
// input parameters
MP4TrackId trackId,
MP4SampleId sampleId,
// output parameters
u_int8_t** ppBytes,
u_int32_t* pNumBytes,
MP4Timestamp* pStartTime = NULL,
MP4Duration* pDuration = NULL,
MP4Duration* pRenderingOffset = NULL,
bool* pIsSyncSample = NULL);
void WriteSample(
MP4TrackId trackId,
const u_int8_t* pBytes,
u_int32_t numBytes,
MP4Duration duration = 0,
MP4Duration renderingOffset = 0,
bool isSyncSample = true);
void SetSampleRenderingOffset(
MP4TrackId trackId,
MP4SampleId sampleId,
MP4Duration renderingOffset);
/* track level convenience functions */
MP4TrackId AddSystemsTrack(const char* type);
MP4TrackId AddODTrack();
MP4TrackId AddSceneTrack();
MP4TrackId AddAudioTrack(
u_int32_t timeScale,
MP4Duration sampleDuration,
u_int8_t audioType);
MP4TrackId AddEncAudioTrack( // ismacrypt
u_int32_t timeScale,
MP4Duration sampleDuration,
u_int8_t audioType);
MP4TrackId AddVideoTrack(
u_int32_t timeScale,
MP4Duration sampleDuration,
u_int16_t width,
u_int16_t height,
u_int8_t videoType);
MP4TrackId AddEncVideoTrack( // ismacrypt
u_int32_t timeScale,
MP4Duration sampleDuration,
u_int16_t width,
u_int16_t height,
u_int8_t videoType);
MP4TrackId AddHintTrack(MP4TrackId refTrackId);
MP4SampleId GetTrackNumberOfSamples(MP4TrackId trackId);
const char* GetTrackType(MP4TrackId trackId);
MP4Duration GetTrackDuration(MP4TrackId trackId);
u_int32_t GetTrackTimeScale(MP4TrackId trackId);
void SetTrackTimeScale(MP4TrackId trackId, u_int32_t value);
// replacement to GetTrackAudioType and GetTrackVideoType
u_int8_t GetTrackEsdsObjectTypeId(MP4TrackId trackId);
u_int8_t GetTrackAudioType(MP4TrackId trackId);
u_int8_t GetTrackAudioMpeg4Type(MP4TrackId trackId);
u_int8_t GetTrackVideoType(MP4TrackId trackId);
MP4Duration GetTrackFixedSampleDuration(MP4TrackId trackId);
float GetTrackVideoFrameRate(MP4TrackId trackId);
void GetTrackESConfiguration(MP4TrackId trackId,
u_int8_t** ppConfig, u_int32_t* pConfigSize);
void SetTrackESConfiguration(MP4TrackId trackId,
const u_int8_t* pConfig, u_int32_t configSize);
const char* GetHintTrackSdp(MP4TrackId hintTrackId);
void SetHintTrackSdp(MP4TrackId hintTrackId, const char* sdpString);
void AppendHintTrackSdp(MP4TrackId hintTrackId, const char* sdpString);
// ISMA specific functions
void MakeIsmaCompliant(bool addIsmaComplianceSdp = true);
void CreateIsmaIodFromParams(
u_int8_t videoProfile,
u_int32_t videoBitrate,
u_int8_t* videoConfig,
u_int32_t videoConfigLength,
u_int8_t audioProfile,
u_int32_t audioBitrate,
u_int8_t* audioConfig,
u_int32_t audioConfigLength,
u_int8_t** ppBytes,
u_int64_t* pNumBytes);
// time convenience functions
u_int64_t ConvertFromMovieDuration(
MP4Duration duration,
u_int32_t timeScale);
u_int64_t ConvertFromTrackTimestamp(
MP4TrackId trackId,
MP4Timestamp timeStamp,
u_int32_t timeScale);
MP4Timestamp ConvertToTrackTimestamp(
MP4TrackId trackId,
u_int64_t timeStamp,
u_int32_t timeScale);
u_int64_t ConvertFromTrackDuration(
MP4TrackId trackId,
MP4Duration duration,
u_int32_t timeScale);
MP4Duration ConvertToTrackDuration(
MP4TrackId trackId,
u_int64_t duration,
u_int32_t timeScale);
// specialized operations
void GetHintTrackRtpPayload(
MP4TrackId hintTrackId,
char** ppPayloadName = NULL,
u_int8_t* pPayloadNumber = NULL,
u_int16_t* pMaxPayloadSize = NULL,
char **ppEncodingParams = NULL);
void SetHintTrackRtpPayload(
MP4TrackId hintTrackId,
const char* payloadName,
u_int8_t* pPayloadNumber,
u_int16_t maxPayloadSize,
const char *encoding_params,
bool include_rtp_map,
bool include_mpeg4_esid);
MP4TrackId GetHintTrackReferenceTrackId(
MP4TrackId hintTrackId);
void ReadRtpHint(
MP4TrackId hintTrackId,
MP4SampleId hintSampleId,
u_int16_t* pNumPackets = NULL);
u_int16_t GetRtpHintNumberOfPackets(
MP4TrackId hintTrackId);
int8_t GetRtpPacketBFrame(
MP4TrackId hintTrackId,
u_int16_t packetIndex);
int32_t GetRtpPacketTransmitOffset(
MP4TrackId hintTrackId,
u_int16_t packetIndex);
void ReadRtpPacket(
MP4TrackId hintTrackId,
u_int16_t packetIndex,
u_int8_t** ppBytes,
u_int32_t* pNumBytes,
u_int32_t ssrc = 0,
bool includeHeader = true,
bool includePayload = true);
MP4Timestamp GetRtpTimestampStart(
MP4TrackId hintTrackId);
void SetRtpTimestampStart(
MP4TrackId hintTrackId,
MP4Timestamp rtpStart);
void AddRtpHint(
MP4TrackId hintTrackId,
bool isBframe,
u_int32_t timestampOffset);
void AddRtpPacket(
MP4TrackId hintTrackId,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -