mp4file.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864
  1. /*
  2. * The contents of this file are subject to the Mozilla Public
  3. * License Version 1.1 (the "License"); you may not use this file
  4. * except in compliance with the License. You may obtain a copy of
  5. * the License at http://www.mozilla.org/MPL/
  6. *
  7. * Software distributed under the License is distributed on an "AS
  8. * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  9. * implied. See the License for the specific language governing
  10. * rights and limitations under the License.
  11. *
  12. * The Original Code is MPEG4IP.
  13. *
  14. * The Initial Developer of the Original Code is Cisco Systems Inc.
  15. * Portions created by Cisco Systems Inc. are
  16. * Copyright (C) Cisco Systems Inc. 2001 - 2005. All Rights Reserved.
  17. *
  18. * 3GPP features implementation is based on 3GPP's TS26.234-v5.60,
  19. * and was contributed by Ximpo Group Ltd.
  20. *
  21. * Portions created by Ximpo Group Ltd. are
  22. * Copyright (C) Ximpo Group Ltd. 2003, 2004. All Rights Reserved.
  23. *
  24. * Contributor(s):
  25. * Dave Mackie [email protected]
  26. * Alix Marchandise-Franquet [email protected]
  27. * Ximpo Group Ltd. [email protected]
  28. */
  29. #ifndef __MP4_FILE_INCLUDED__
  30. #define __MP4_FILE_INCLUDED__
  31. // forward declarations
  32. class MP4Atom;
  33. class MP4Property;
  34. class MP4Float32Property;
  35. class MP4StringProperty;
  36. class MP4BytesProperty;
  37. class MP4Descriptor;
  38. class MP4DescriptorProperty;
  39. struct Virtual_IO;
  40. class MP4File {
  41. public: /* equivalent to MP4 library API */
  42. MP4File(u_int32_t verbosity = 0);
  43. ~MP4File();
  44. /* file operations */
  45. void Read(const MP4_FILENAME_CHAR *fileName);
  46. void ReadEx(const MP4_FILENAME_CHAR *fileName, void *user, Virtual_IO *virtual_IO); //benski>
  47. void Create(const MP4_FILENAME_CHAR *fileName, u_int32_t flags,
  48. int add_ftyp = 1, int add_iods = 1,
  49. char* majorBrand = NULL,
  50. u_int32_t minorVersion = 0, char** supportedBrands = NULL,
  51. u_int32_t supportedBrandsCount = 0);
  52. void Modify(const MP4_FILENAME_CHAR *fileName);
  53. void Optimize(const MP4_FILENAME_CHAR *orgFileName,
  54. const MP4_FILENAME_CHAR *newFileName = NULL);
  55. void Close();
  56. /* library property per file */
  57. u_int32_t GetVerbosity() {
  58. return m_verbosity;
  59. }
  60. void SetVerbosity(u_int32_t verbosity) {
  61. m_verbosity = verbosity;
  62. }
  63. bool Use64Bits(const char *atomName);
  64. void Check64BitStatus(const char *atomName);
  65. /* file properties */
  66. u_int64_t GetIntegerProperty(const char* name);
  67. float GetFloatProperty(const char* name);
  68. const char* GetStringProperty(const char* name);
  69. void GetBytesProperty(const char* name,
  70. u_int8_t** ppValue, u_int32_t* pValueSize);
  71. void SetIntegerProperty(const char* name, u_int64_t value);
  72. void SetFloatProperty(const char* name, float value);
  73. void SetStringProperty(const char* name, const char* value);
  74. void SetBytesProperty(const char* name,
  75. const u_int8_t* pValue, u_int32_t valueSize);
  76. // file level convenience functions
  77. MP4Duration GetDuration();
  78. void SetDuration(MP4Duration value);
  79. u_int32_t GetTimeScale();
  80. void SetTimeScale(u_int32_t value);
  81. u_int8_t GetODProfileLevel();
  82. void SetODProfileLevel(u_int8_t value);
  83. u_int8_t GetSceneProfileLevel();
  84. void SetSceneProfileLevel(u_int8_t value);
  85. u_int8_t GetVideoProfileLevel();
  86. void SetVideoProfileLevel(u_int8_t value);
  87. u_int8_t GetAudioProfileLevel();
  88. void SetAudioProfileLevel(u_int8_t value);
  89. u_int8_t GetGraphicsProfileLevel();
  90. void SetGraphicsProfileLevel(u_int8_t value);
  91. const char* GetSessionSdp();
  92. void SetSessionSdp(const char* sdpString);
  93. void AppendSessionSdp(const char* sdpString);
  94. /* track operations */
  95. MP4TrackId AddTrack(const char* type, u_int32_t timeScale = 1000);
  96. void DeleteTrack(MP4TrackId trackId);
  97. u_int32_t GetNumberOfTracks(const char* type = NULL, u_int8_t subType = 0);
  98. MP4TrackId AllocTrackId();
  99. MP4TrackId FindTrackId(u_int16_t trackIndex,
  100. const char* type = NULL, u_int8_t subType = 0);
  101. u_int16_t FindTrackIndex(MP4TrackId trackId);
  102. u_int16_t FindTrakAtomIndex(MP4TrackId trackId);
  103. /* track properties */
  104. MP4Atom *FindTrackAtom(MP4TrackId trackId, const char *name);
  105. u_int64_t GetTrackIntegerProperty(
  106. MP4TrackId trackId, const char* name);
  107. float GetTrackFloatProperty(
  108. MP4TrackId trackId, const char* name);
  109. const char* GetTrackStringProperty(
  110. MP4TrackId trackId, const char* name);
  111. void GetTrackBytesProperty(
  112. MP4TrackId trackId, const char* name,
  113. u_int8_t** ppValue, u_int32_t* pValueSize);
  114. void SetTrackIntegerProperty(
  115. MP4TrackId trackId, const char* name, int64_t value);
  116. void SetTrackFloatProperty(
  117. MP4TrackId trackId, const char* name, float value);
  118. void SetTrackStringProperty(
  119. MP4TrackId trackId, const char* name, const char* value);
  120. void SetTrackBytesProperty(
  121. MP4TrackId trackId, const char* name,
  122. const u_int8_t* pValue, u_int32_t valueSize);
  123. /* sample operations */
  124. u_int32_t GetSampleSize(MP4TrackId trackId, MP4SampleId sampleId);
  125. u_int32_t GetTrackMaxSampleSize(MP4TrackId trackId);
  126. MP4SampleId GetSampleIdFromTime(MP4TrackId trackId,
  127. MP4Timestamp when, bool wantSyncSample = false, bool rewind = false);
  128. MP4ChunkId GetChunkIdFromTime(MP4TrackId trackId, MP4Timestamp when);
  129. MP4Timestamp GetSampleTime(
  130. MP4TrackId trackId, MP4SampleId sampleId);
  131. MP4Duration GetSampleDuration(
  132. MP4TrackId trackId, MP4SampleId sampleId);
  133. MP4Duration GetSampleRenderingOffset(
  134. MP4TrackId trackId, MP4SampleId sampleId);
  135. bool GetSampleSync(
  136. MP4TrackId trackId, MP4SampleId sampleId);
  137. void ReadSample(
  138. // input parameters
  139. MP4TrackId trackId,
  140. MP4SampleId sampleId,
  141. // output parameters
  142. u_int8_t** ppBytes,
  143. u_int32_t* pNumBytes,
  144. MP4Timestamp* pStartTime = NULL,
  145. MP4Duration* pDuration = NULL,
  146. MP4Duration* pRenderingOffset = NULL,
  147. bool* pIsSyncSample = NULL);
  148. void ReadChunk(
  149. // input parameters
  150. MP4TrackId trackId,
  151. MP4ChunkId sampleId,
  152. // output parameters
  153. u_int8_t** ppBytes,
  154. u_int32_t* pNumBytes,
  155. MP4Timestamp* pStartTime = NULL,
  156. MP4Duration* pDuration = NULL);
  157. void WriteSample(
  158. MP4TrackId trackId,
  159. const u_int8_t* pBytes,
  160. u_int32_t numBytes,
  161. MP4Duration duration = 0,
  162. MP4Duration renderingOffset = 0,
  163. bool isSyncSample = true);
  164. void SetSampleRenderingOffset(
  165. MP4TrackId trackId,
  166. MP4SampleId sampleId,
  167. MP4Duration renderingOffset);
  168. /* track level convenience functions */
  169. MP4TrackId AddSystemsTrack(const char* type);
  170. MP4TrackId AddODTrack();
  171. MP4TrackId AddSceneTrack();
  172. MP4TrackId AddAudioTrack(
  173. u_int32_t timeScale,
  174. MP4Duration sampleDuration,
  175. u_int8_t audioType);
  176. MP4TrackId AddEncAudioTrack( // ismacryp
  177. u_int32_t timeScale,
  178. MP4Duration sampleDuration,
  179. u_int8_t audioType,
  180. u_int32_t scheme_type,
  181. u_int16_t scheme_version,
  182. u_int8_t key_ind_len,
  183. u_int8_t iv_len,
  184. bool selective_enc,
  185. const char *kms_uri,
  186. bool use_ismacryp);
  187. void SetAmrVendor(
  188. MP4TrackId trackId,
  189. u_int32_t vendor);
  190. void SetAmrDecoderVersion(
  191. MP4TrackId trackId,
  192. u_int8_t decoderVersion);
  193. void SetAmrModeSet(
  194. MP4TrackId trackId,
  195. u_int16_t modeSet);
  196. uint16_t GetAmrModeSet(MP4TrackId trackId);
  197. MP4TrackId AddAmrAudioTrack(
  198. u_int32_t timeScale,
  199. u_int16_t modeSet,
  200. u_int8_t modeChangePeriod,
  201. u_int8_t framesPerSample,
  202. bool isAmrWB);
  203. MP4TrackId AddHrefTrack(uint32_t timeScale,
  204. MP4Duration sampleDuration,
  205. const char *base_url);
  206. MP4TrackId AddMP4VideoTrack(
  207. u_int32_t timeScale,
  208. MP4Duration sampleDuration,
  209. u_int16_t width,
  210. u_int16_t height,
  211. u_int8_t videoType);
  212. MP4TrackId AddEncVideoTrack( // ismacryp
  213. u_int32_t timeScale,
  214. MP4Duration sampleDuration,
  215. u_int16_t width,
  216. u_int16_t height,
  217. u_int8_t videoType,
  218. mp4v2_ismacrypParams *icPp,
  219. const char *oFormat);
  220. void SetH263Vendor(
  221. MP4TrackId trackId,
  222. u_int32_t vendor);
  223. void SetH263DecoderVersion(
  224. MP4TrackId trackId,
  225. u_int8_t decoderVersion);
  226. void SetH263Bitrates(
  227. MP4TrackId,
  228. u_int32_t avgBitrate,
  229. u_int32_t maxBitrate);
  230. MP4TrackId AddH263VideoTrack(
  231. u_int32_t timeScale,
  232. MP4Duration sampleDuration,
  233. u_int16_t width,
  234. u_int16_t height,
  235. u_int8_t h263Level,
  236. u_int8_t h263Profile,
  237. u_int32_t avgBitrate,
  238. u_int32_t maxBitrate);
  239. MP4TrackId AddH264VideoTrack(
  240. u_int32_t timeScale,
  241. MP4Duration sampleDuration,
  242. u_int16_t width,
  243. u_int16_t height,
  244. uint8_t AVCProfileIndication,
  245. uint8_t profile_compat,
  246. uint8_t AVCLevelIndication,
  247. uint8_t sampleLenFieldSizeMinusOne);
  248. MP4TrackId AddEncH264VideoTrack(
  249. u_int32_t timeScale,
  250. MP4Duration sampleDuration,
  251. u_int16_t width,
  252. u_int16_t height,
  253. MP4Atom *srcAtom,
  254. mp4v2_ismacrypParams *icPp);
  255. void AddH264SequenceParameterSet(MP4TrackId trackId,
  256. const uint8_t *pSequence,
  257. uint16_t sequenceLen);
  258. void AddH264PictureParameterSet(MP4TrackId trackId,
  259. const uint8_t *pPicture,
  260. uint16_t pictureLen);
  261. MP4TrackId AddHintTrack(MP4TrackId refTrackId);
  262. MP4TrackId AddTextTrack(MP4TrackId refTrackId);
  263. MP4TrackId AddChapterTextTrack(MP4TrackId refTrackId, u_int32_t timescale = 0);
  264. void AddChapter(MP4TrackId chapterTrackId,
  265. MP4Duration chapterDuration,
  266. u_int32_t chapterNr,
  267. const char * chapterTitle = 0);
  268. void AddChapter(MP4Timestamp chapterStart,
  269. const char * chapterTitle = 0);
  270. void ConvertChapters(boolean toQT = true);
  271. void DeleteChapters(MP4TrackId chapterTrackId = 0, boolean deleteQT = true);
  272. void GetChaptersList(MP4Chapters_t ** chapterList,
  273. u_int32_t * chapterCount,
  274. boolean getQT = true);
  275. MP4TrackId FindChapterTrack(char * trackName = 0, int trackNameSize = 0);
  276. MP4TrackId FindChapterReferenceTrack(MP4TrackId chapterTrackId, char * trackName = 0, size_t trackNameSize = 0);
  277. MP4SampleId GetTrackNumberOfSamples(MP4TrackId trackId);
  278. MP4ChunkId GetTrackNumberOfChunks(MP4TrackId trackId);
  279. const char* GetTrackType(MP4TrackId trackId);
  280. const char *GetTrackMediaDataName(MP4TrackId trackId);
  281. bool GetTrackMediaDataOriginalFormat(MP4TrackId trackId,
  282. char *originalFormat, u_int32_t buflen);
  283. MP4Duration GetTrackDuration(MP4TrackId trackId);
  284. u_int32_t GetTrackTimeScale(MP4TrackId trackId);
  285. void SetTrackTimeScale(MP4TrackId trackId, u_int32_t value);
  286. // replacement to GetTrackAudioType and GetTrackVideoType
  287. u_int8_t GetTrackEsdsObjectTypeId(MP4TrackId trackId);
  288. u_int8_t GetTrackAudioMpeg4Type(MP4TrackId trackId);
  289. MP4Duration GetTrackFixedSampleDuration(MP4TrackId trackId);
  290. double GetTrackVideoFrameRate(MP4TrackId trackId);
  291. int GetTrackAudioChannels(MP4TrackId trackId);
  292. void GetTrackESConfiguration(MP4TrackId trackId,
  293. u_int8_t** ppConfig, u_int32_t* pConfigSize);
  294. void SetTrackESConfiguration(MP4TrackId trackId,
  295. const u_int8_t* pConfig, u_int32_t configSize);
  296. void GetTrackVideoMetadata(MP4TrackId trackId,
  297. u_int8_t** ppConfig, u_int32_t* pConfigSize);
  298. void GetTrackH264SeqPictHeaders(MP4TrackId trackId,
  299. uint8_t ***pSeqHeader,
  300. uint32_t **pSeqHeaderSize,
  301. uint8_t ***pPictHeader,
  302. uint32_t **pPictHeaderSize);
  303. const char* GetHintTrackSdp(MP4TrackId hintTrackId);
  304. void SetHintTrackSdp(MP4TrackId hintTrackId, const char* sdpString);
  305. void AppendHintTrackSdp(MP4TrackId hintTrackId, const char* sdpString);
  306. // 3GPP specific functions
  307. void MakeFtypAtom(char* majorBrand,
  308. u_int32_t minorVersion,
  309. char** supportedBrands,
  310. u_int32_t supportedBrandsCount);
  311. void Make3GPCompliant(const MP4_FILENAME_CHAR* fileName,
  312. char* majorBrand,
  313. u_int32_t minorVersion,
  314. char** supportedBrands,
  315. u_int32_t supportedBrandsCount,
  316. bool deleteIodsAtom);
  317. // ISMA specific functions
  318. // true if media track encrypted according to ismacryp
  319. bool IsIsmaCrypMediaTrack(MP4TrackId trackId);
  320. void MakeIsmaCompliant(bool addIsmaComplianceSdp = true);
  321. void CreateIsmaIodFromParams(
  322. u_int8_t videoProfile,
  323. u_int32_t videoBitrate,
  324. u_int8_t* videoConfig,
  325. u_int32_t videoConfigLength,
  326. u_int8_t audioProfile,
  327. u_int32_t audioBitrate,
  328. u_int8_t* audioConfig,
  329. u_int32_t audioConfigLength,
  330. u_int8_t** ppBytes,
  331. u_int64_t* pNumBytes);
  332. // time convenience functions
  333. u_int64_t ConvertFromMovieDuration(
  334. MP4Duration duration,
  335. u_int32_t timeScale);
  336. u_int64_t ConvertFromTrackTimestamp(
  337. MP4TrackId trackId,
  338. MP4Timestamp timeStamp,
  339. u_int32_t timeScale);
  340. MP4Timestamp ConvertToTrackTimestamp(
  341. MP4TrackId trackId,
  342. u_int64_t timeStamp,
  343. u_int32_t timeScale);
  344. u_int64_t ConvertFromTrackDuration(
  345. MP4TrackId trackId,
  346. MP4Duration duration,
  347. u_int32_t timeScale);
  348. MP4Duration ConvertToTrackDuration(
  349. MP4TrackId trackId,
  350. u_int64_t duration,
  351. u_int32_t timeScale);
  352. // specialized operations
  353. void GetHintTrackRtpPayload(
  354. MP4TrackId hintTrackId,
  355. char** ppPayloadName = NULL,
  356. u_int8_t* pPayloadNumber = NULL,
  357. u_int16_t* pMaxPayloadSize = NULL,
  358. char **ppEncodingParams = NULL);
  359. void SetHintTrackRtpPayload(
  360. MP4TrackId hintTrackId,
  361. const char* payloadName,
  362. u_int8_t* pPayloadNumber,
  363. u_int16_t maxPayloadSize,
  364. const char *encoding_params,
  365. bool include_rtp_map,
  366. bool include_mpeg4_esid);
  367. MP4TrackId GetHintTrackReferenceTrackId(
  368. MP4TrackId hintTrackId);
  369. void ReadRtpHint(
  370. MP4TrackId hintTrackId,
  371. MP4SampleId hintSampleId,
  372. u_int16_t* pNumPackets = NULL);
  373. u_int16_t GetRtpHintNumberOfPackets(
  374. MP4TrackId hintTrackId);
  375. int8_t GetRtpPacketBFrame(
  376. MP4TrackId hintTrackId,
  377. u_int16_t packetIndex);
  378. int32_t GetRtpPacketTransmitOffset(
  379. MP4TrackId hintTrackId,
  380. u_int16_t packetIndex);
  381. void ReadRtpPacket(
  382. MP4TrackId hintTrackId,
  383. u_int16_t packetIndex,
  384. u_int8_t** ppBytes,
  385. u_int32_t* pNumBytes,
  386. u_int32_t ssrc = 0,
  387. bool includeHeader = true,
  388. bool includePayload = true);
  389. MP4Timestamp GetRtpTimestampStart(
  390. MP4TrackId hintTrackId);
  391. void SetRtpTimestampStart(
  392. MP4TrackId hintTrackId,
  393. MP4Timestamp rtpStart);
  394. void AddRtpHint(
  395. MP4TrackId hintTrackId,
  396. bool isBframe,
  397. u_int32_t timestampOffset);
  398. void AddRtpPacket(
  399. MP4TrackId hintTrackId,
  400. bool setMbit,
  401. int32_t transmitOffset);
  402. void AddRtpImmediateData(
  403. MP4TrackId hintTrackId,
  404. const u_int8_t* pBytes,
  405. u_int32_t numBytes);
  406. void AddRtpSampleData(
  407. MP4TrackId hintTrackId,
  408. MP4SampleId sampleId,
  409. u_int32_t dataOffset,
  410. u_int32_t dataLength);
  411. void AddRtpESConfigurationPacket(
  412. MP4TrackId hintTrackId);
  413. void WriteRtpHint(
  414. MP4TrackId hintTrackId,
  415. MP4Duration duration,
  416. bool isSyncSample);
  417. u_int8_t AllocRtpPayloadNumber();
  418. // edit list related
  419. char* MakeTrackEditName(
  420. MP4TrackId trackId,
  421. MP4EditId editId,
  422. const char* name);
  423. MP4EditId AddTrackEdit(
  424. MP4TrackId trackId,
  425. MP4EditId editId = MP4_INVALID_EDIT_ID);
  426. void DeleteTrackEdit(
  427. MP4TrackId trackId,
  428. MP4EditId editId);
  429. u_int32_t GetTrackNumberOfEdits(
  430. MP4TrackId trackId);
  431. MP4Timestamp GetTrackEditStart(
  432. MP4TrackId trackId,
  433. MP4EditId editId);
  434. MP4Duration GetTrackEditTotalDuration(
  435. MP4TrackId trackId,
  436. MP4EditId editId);
  437. MP4Timestamp GetTrackEditMediaStart(
  438. MP4TrackId trackId,
  439. MP4EditId editId);
  440. void SetTrackEditMediaStart(
  441. MP4TrackId trackId,
  442. MP4EditId editId,
  443. MP4Timestamp startTime);
  444. MP4Duration GetTrackEditDuration(
  445. MP4TrackId trackId,
  446. MP4EditId editId);
  447. void SetTrackEditDuration(
  448. MP4TrackId trackId,
  449. MP4EditId editId,
  450. MP4Duration duration);
  451. bool GetTrackEditDwell(
  452. MP4TrackId trackId,
  453. MP4EditId editId);
  454. void SetTrackEditDwell(
  455. MP4TrackId trackId,
  456. MP4EditId editId,
  457. bool dwell);
  458. MP4SampleId GetSampleIdFromEditTime(
  459. MP4TrackId trackId,
  460. MP4Timestamp when,
  461. MP4Timestamp* pStartTime = NULL,
  462. MP4Duration* pDuration = NULL);
  463. /* iTunes metadata handling */
  464. protected:
  465. bool CreateMetadataAtom(const char* name);
  466. public:
  467. // these are public to remove a lot of unnecessary routines
  468. bool DeleteMetadataAtom(const char* name, bool try_udta = false);
  469. bool GetMetadataString(const char *atom, char **value, bool try_udta = false);
  470. bool SetMetadataString(const char *atom, const char *value);
  471. bool MetadataDelete(void);
  472. bool SetMetadataUint8(const char *atom, u_int8_t compilation);
  473. bool GetMetadataUint8(const char *atom, u_int8_t* compilation);
  474. /* set metadata */
  475. bool SetMetadataTrack(u_int16_t track, u_int16_t totalTracks);
  476. bool SetMetadataDisk(u_int16_t disk, u_int16_t totalDisks);
  477. bool SetMetadataGenre(const char *value);
  478. bool SetMetadataTempo(u_int16_t tempo);
  479. bool SetMetadataCoverArt(u_int8_t *coverArt, u_int32_t size, int flags);
  480. bool SetMetadataFreeForm(const char *name,
  481. const u_int8_t* pValue,
  482. u_int32_t valueSize,
  483. const char *owner = NULL);
  484. /* get metadata */
  485. bool GetMetadataByIndex(u_int32_t index,
  486. char** ppName, // free memory when done
  487. u_int8_t** ppValue, // free memory when done
  488. u_int32_t* pValueSize);
  489. bool GetMetadataTrack(u_int16_t* track, u_int16_t* totalTracks);
  490. bool GetMetadataDisk(u_int16_t* disk, u_int16_t* totalDisks);
  491. bool GetMetadataGenre(char **value);
  492. bool GetMetadataTempo(u_int16_t* tempo);
  493. bool GetMetadataCoverArt(u_int8_t **coverArt, u_int32_t* size,
  494. uint32_t index = 0);
  495. u_int32_t GetMetadataCoverArtCount(void);
  496. bool GetMetadataFreeForm(const char *name,
  497. u_int8_t** pValue,
  498. u_int32_t* valueSize,
  499. const char *owner = NULL);
  500. /* delete metadata */
  501. bool DeleteMetadataGenre();
  502. bool DeleteMetadataFreeForm(const char *name, const char *owner = NULL);
  503. /* 3GP metadata */
  504. bool Get3GPMetadataString(const char *atom, uint16_t **value);
  505. bool Set3GPMetadataString(const char *atom, const uint16_t *value);
  506. bool Get3GPMetadataInteger(const char *atom, uint64_t *value);
  507. bool Set3GPMetadataInteger(const char *atom, uint64_t value);
  508. bool Delete3GPMetadataAtom(const char* name);
  509. /* end of MP4 API */
  510. /* "protected" interface to be used only by friends in library */
  511. u_int64_t GetPosition(FILE* pFile = NULL);
  512. void SetPosition(u_int64_t pos, FILE* pFile = NULL);
  513. u_int64_t GetSize();
  514. void ReadBytes(
  515. u_int8_t* pBytes, u_int32_t numBytes, FILE* pFile = NULL);
  516. u_int64_t ReadUInt(u_int8_t size);
  517. u_int8_t ReadUInt8();
  518. u_int16_t ReadUInt16();
  519. u_int32_t ReadUInt24();
  520. u_int32_t ReadUInt32();
  521. u_int64_t ReadUInt64();
  522. float ReadFixed16();
  523. float ReadFixed32();
  524. float ReadFloat();
  525. char* ReadString();
  526. uint16_t *ReadUnicodeString();
  527. char* ReadCountedString(
  528. u_int8_t charSize = 1, bool allowExpandedCount = false);
  529. u_int64_t ReadBits(u_int8_t numBits);
  530. void FlushReadBits();
  531. u_int32_t ReadMpegLength();
  532. void PeekBytes(
  533. u_int8_t* pBytes, u_int32_t numBytes, FILE* pFile = NULL);
  534. void WriteBytes(u_int8_t* pBytes, u_int32_t numBytes, FILE* pFile = NULL);
  535. void WriteUInt(u_int64_t value, u_int8_t bytes);
  536. void WriteUInt8(u_int8_t value);
  537. void WriteUInt16(u_int16_t value);
  538. void WriteUInt24(u_int32_t value);
  539. void WriteUInt32(u_int32_t value);
  540. void WriteUInt64(u_int64_t value);
  541. void WriteFixed16(float value);
  542. void WriteFixed32(float value);
  543. void WriteFloat(float value);
  544. void WriteString(char* string);
  545. void WriteUnicodeString(const uint16_t *string);
  546. void WriteCountedString(char* string,
  547. u_int8_t charSize = 1, bool allowExpandedCount = false);
  548. void WriteBits(u_int64_t bits, u_int8_t numBits);
  549. void PadWriteBits(u_int8_t pad = 0);
  550. void FlushWriteBits();
  551. void WriteMpegLength(u_int32_t value, bool compact = false);
  552. void EnableMemoryBuffer(
  553. u_int8_t* pBytes = NULL, u_int64_t numBytes = 0);
  554. void DisableMemoryBuffer(
  555. u_int8_t** ppBytes = NULL, u_int64_t* pNumBytes = NULL);
  556. char GetMode() {
  557. return m_mode;
  558. }
  559. MP4Track* GetTrack(MP4TrackId trackId);
  560. void UpdateDuration(MP4Duration duration);
  561. MP4Atom* FindAtomMP4File(const char* name);
  562. MP4Atom* AddChildAtom(
  563. const char* parentName,
  564. const char* childName);
  565. MP4Atom* AddChildAtom(
  566. MP4Atom* pParentAtom,
  567. const char* childName);
  568. MP4Atom* InsertChildAtom(
  569. const char* parentName,
  570. const char* childName,
  571. u_int32_t index);
  572. MP4Atom* InsertChildAtom(
  573. MP4Atom* pParentAtom,
  574. const char* childName,
  575. u_int32_t index);
  576. MP4Atom* AddDescendantAtoms(
  577. const char* ancestorName,
  578. const char* childName);
  579. MP4Atom* AddDescendantAtoms(
  580. MP4Atom* pAncestorAtom,
  581. const char* childName);
  582. protected:
  583. void Open(const MP4_FILENAME_CHAR* fmode);
  584. void ReadFromFile();
  585. void GenerateTracks();
  586. void BeginWrite();
  587. void FinishWrite();
  588. void CacheProperties();
  589. void RewriteMdat(void* pReadFile, void* pWriteFile,
  590. Virtual_IO *readIO, Virtual_IO *writeIO);
  591. bool ShallHaveIods();
  592. const wchar_t *TempFileName();
  593. void Rename(const MP4_FILENAME_CHAR* existingFileName, const MP4_FILENAME_CHAR* newFileName);
  594. void ProtectWriteOperation(char* where);
  595. void FindIntegerProperty(const char* name,
  596. MP4Property** ppProperty, u_int32_t* pIndex = NULL);
  597. void FindFloatProperty(const char* name,
  598. MP4Property** ppProperty, u_int32_t* pIndex = NULL);
  599. void FindStringProperty(const char* name,
  600. MP4Property** ppProperty, u_int32_t* pIndex = NULL);
  601. void FindBytesProperty(const char* name,
  602. MP4Property** ppProperty, u_int32_t* pIndex = NULL);
  603. bool FindProperty(const char* name,
  604. MP4Property** ppProperty, u_int32_t* pIndex = NULL);
  605. MP4TrackId AddVideoTrackDefault(
  606. u_int32_t timeScale,
  607. MP4Duration sampleDuration,
  608. u_int16_t width,
  609. u_int16_t height,
  610. const char *videoType);
  611. MP4TrackId AddCntlTrackDefault(
  612. u_int32_t timeScale,
  613. MP4Duration sampleDuration,
  614. const char *videoType);
  615. void AddTrackToIod(MP4TrackId trackId);
  616. void RemoveTrackFromIod(MP4TrackId trackId, bool shallHaveIods = true);
  617. void AddTrackToOd(MP4TrackId trackId);
  618. void RemoveTrackFromOd(MP4TrackId trackId);
  619. void GetTrackReferenceProperties(const char* trefName,
  620. MP4Property** ppCountProperty, MP4Property** ppTrackIdProperty);
  621. void AddTrackReference(const char* trefName, MP4TrackId refTrackId);
  622. u_int32_t FindTrackReference(const char* trefName, MP4TrackId refTrackId);
  623. void RemoveTrackReference(const char* trefName, MP4TrackId refTrackId);
  624. void AddDataReference(MP4TrackId trackId, const char* url);
  625. char* MakeTrackName(MP4TrackId trackId, const char* name);
  626. u_int8_t ConvertTrackTypeToStreamType(const char* trackType);
  627. void CreateIsmaIodFromFile(
  628. MP4TrackId odTrackId,
  629. MP4TrackId sceneTrackId,
  630. MP4TrackId audioTrackId,
  631. MP4TrackId videoTrackId,
  632. u_int8_t** ppBytes,
  633. u_int64_t* pNumBytes);
  634. void CreateESD(
  635. MP4DescriptorProperty* pEsProperty,
  636. u_int32_t esid,
  637. u_int8_t objectType,
  638. u_int8_t streamType,
  639. u_int32_t bufferSize,
  640. u_int32_t bitrate,
  641. const u_int8_t* pConfig,
  642. u_int32_t configLength,
  643. char* url);
  644. void CreateIsmaODUpdateCommandFromFileForFile(
  645. MP4TrackId odTrackId,
  646. MP4TrackId audioTrackId,
  647. MP4TrackId videoTrackId,
  648. u_int8_t** ppBytes,
  649. u_int64_t* pNumBytes);
  650. void CreateIsmaODUpdateCommandFromFileForStream(
  651. MP4TrackId audioTrackId,
  652. MP4TrackId videoTrackId,
  653. u_int8_t** ppBytes,
  654. u_int64_t* pNumBytes);
  655. void CreateIsmaODUpdateCommandForStream(
  656. MP4DescriptorProperty* pAudioEsdProperty,
  657. MP4DescriptorProperty* pVideoEsdProperty,
  658. u_int8_t** ppBytes,
  659. u_int64_t* pNumBytes);
  660. void CreateIsmaSceneCommand(
  661. bool hasAudio,
  662. bool hasVideo,
  663. u_int8_t** ppBytes,
  664. u_int64_t* pNumBytes);
  665. protected:
  666. MP4_FILENAME_CHAR *m_fileName;
  667. void* m_pFile;
  668. Virtual_IO *m_virtual_IO;
  669. u_int64_t m_orgFileSize;
  670. u_int64_t m_fileSize;
  671. MP4Atom* m_pRootAtom;
  672. MP4Integer32Array m_trakIds;
  673. MP4TrackArray m_pTracks;
  674. MP4TrackId m_odTrackId;
  675. u_int32_t m_verbosity;
  676. char m_mode;
  677. u_int32_t m_createFlags;
  678. bool m_useIsma;
  679. // cached properties
  680. MP4IntegerProperty* m_pModificationProperty;
  681. MP4Integer32Property* m_pTimeScaleProperty;
  682. MP4IntegerProperty* m_pDurationProperty;
  683. // read/write in memory
  684. u_int8_t* m_memoryBuffer;
  685. u_int64_t m_memoryBufferPosition;
  686. u_int64_t m_memoryBufferSize;
  687. // bit read/write buffering
  688. u_int8_t m_numReadBits;
  689. u_int8_t m_bufReadBits;
  690. u_int8_t m_numWriteBits;
  691. u_int8_t m_bufWriteBits;
  692. #ifndef _WIN32
  693. char m_tempFileName[64];
  694. #else
  695. wchar_t m_tempFileName[MAX_PATH];
  696. #endif
  697. char m_trakName[1024];
  698. char *m_editName;
  699. };
  700. #endif /* __MP4_FILE_INCLUDED__ */