ref: 903596766a1a8216a356813df8f86ced02ef1bda
parent: 0eaa3913655fe91a36b8c0245654b033ab8af12e
author: menno <menno>
date: Tue Jul 27 04:28:24 EDT 2004
Moved mp4v2 library to faac module and updated to newest version Will require some changes for linux makefiles I guess
--- /dev/null
+++ b/common/mp4v2/3gp.cpp
@@ -1,0 +1,167 @@
+/*
+ * 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.
+ *
+ * 3GPP features implementation is based on 3GPP's TS26.234-v5.60,
+ * and was contributed by Ximpo Group Ltd.
+ *
+ * Portions created by Ximpo Group Ltd. are
+ * Copyright (C) Ximpo Group Ltd. 2003, 2004. All Rights Reserved.
+ *
+ * Contributor(s):
+ * Ximpo Group Ltd. mp4v2@ximpo.com
+ */
+
+#include "mp4common.h"
+
+#define _3GP_MAJOR_BRAND "3gp5"
+#define _3GP_MINOR_VERSION 0x0001
+
+void MP4File::Make3GPCompliant(const char* fileName, char* majorBrand, u_int32_t minorVersion, char** supportedBrands, u_int32_t supportedBrandsCount, bool deleteIodsAtom)
+{
+ char brand[5] = "3gp5";
+ char* _3gpSupportedBrands[1] = { (char*)&brand };
+
+ if (majorBrand) {
+ if (!supportedBrands || !supportedBrandsCount) {
+ throw new MP4Error("Invalid parameters", "MP4File::Make3GPCompliant");
+ }
+ }
+
+ m_fileName = MP4Stralloc(fileName);
+ m_mode = 'r';
+ // first load meta-info into memory
+ Open("rb");
+ ReadFromFile();
+
+ CacheProperties(); // of moov atom
+
+ // now switch over to writing the new file
+ MP4Free(m_fileName);
+ // create a temporary file
+ m_fileName = MP4Stralloc(TempFileName());
+
+ MakeFtypAtom(
+ majorBrand ? majorBrand : (char*)brand,
+ majorBrand ? minorVersion : _3GP_MINOR_VERSION,
+ majorBrand ? supportedBrands : (char**)_3gpSupportedBrands,
+ majorBrand ? supportedBrandsCount : 1);
+
+ if (deleteIodsAtom) {
+ // Delete the iods atom, if it exists....
+ MP4Atom* iodsAtom = m_pRootAtom->FindAtom("moov.iods");
+ if (iodsAtom) {
+ MP4Atom* moovAtom = m_pRootAtom->FindAtom("moov");
+ ASSERT(moovAtom);
+
+ moovAtom->DeleteChildAtom(iodsAtom);
+ }
+ }
+
+
+ FILE* pReadFile = m_pFile;
+ m_pFile = NULL;
+ m_mode = 'w';
+
+ Open("wb");
+
+ SetIntegerProperty("moov.mvhd.modificationTime",
+ MP4GetAbsTimestamp());
+
+ // writing meta info in the optimal order
+ ((MP4RootAtom*)m_pRootAtom)->BeginOptimalWrite();
+
+ // write data in optimal order
+ RewriteMdat(pReadFile, m_pFile);
+
+ // finish writing
+ ((MP4RootAtom*)m_pRootAtom)->FinishOptimalWrite();
+
+ // cleanup
+ fclose(m_pFile);
+ m_pFile = NULL;
+ fclose(pReadFile);
+
+ // move temporary file into place
+ Rename(m_fileName, fileName);
+}
+
+void MP4File::MakeFtypAtom(char* majorBrand, u_int32_t minorVersion, char** supportedBrands, u_int32_t supportedBrandsCount)
+{
+ bool rewriteNeeded = false;
+ u_int32_t currentSupportedBrandsCount;
+ u_int64_t currentSize;
+ u_int32_t i;
+
+
+
+
+ MP4Atom* ftypAtom = m_pRootAtom->FindAtom("ftyp");
+ ASSERT(ftypAtom);
+
+ currentSize = ftypAtom->GetSize();
+
+ MP4StringProperty* pMajorBrandProperty;
+ ftypAtom->FindProperty(
+ "ftyp.majorBrand",
+ (MP4Property**)&pMajorBrandProperty);
+
+ pMajorBrandProperty->SetValue(majorBrand);
+
+
+ MP4Integer32Property* pMinorVersionProperty;
+ ftypAtom->FindProperty(
+ "ftype.minorVersion",
+ (MP4Property**)&pMinorVersionProperty);
+
+ pMinorVersionProperty->SetValue(minorVersion);
+
+ MP4Integer32Property* pCompatibleBrandsCountProperty;
+ ftypAtom->FindProperty(
+ "ftyp.compatibleBrandsCount",
+ (MP4Property**)&pCompatibleBrandsCountProperty);
+
+ currentSupportedBrandsCount = pCompatibleBrandsCountProperty->GetValue();
+
+ MP4TableProperty* pCompatibleBrandsProperty;
+ ftypAtom->FindProperty(
+ "ftyp.compatibleBrands",
+ (MP4Property**)&pCompatibleBrandsProperty);
+
+ MP4StringProperty* pBrandProperty = (MP4StringProperty*)
+ pCompatibleBrandsProperty->GetProperty(0);
+ ASSERT(pBrandProperty);
+
+ for (i = 0 ; i < ((currentSupportedBrandsCount > supportedBrandsCount) ? supportedBrandsCount : currentSupportedBrandsCount) ; i++) {
+ pBrandProperty->SetValue(supportedBrands[i], i);
+
+ }
+
+ if (i < supportedBrandsCount) {
+ for ( ; i < supportedBrandsCount ; i++) {
+ pBrandProperty->AddValue(supportedBrands[i]);
+ }
+ }
+
+ if (currentSupportedBrandsCount != supportedBrandsCount) {
+ rewriteNeeded = true;
+ pBrandProperty->SetCount(supportedBrandsCount);
+ pCompatibleBrandsCountProperty->SetReadOnly(false);
+ pCompatibleBrandsCountProperty->SetValue(supportedBrandsCount);
+ pCompatibleBrandsCountProperty->SetReadOnly(true);
+ }
+
+}
--- /dev/null
+++ b/common/mp4v2/API_CHANGES
@@ -1,0 +1,124 @@
+Changes in xxxx
+---------------
+Change to MP4Create and MP4Modify to allow flags to be set for 64 bit
+to allow Quicktime compatibility
+Change to MP4CloneTrack and MP4CopyTrack for when you copy a hint
+track - you must now specify the track ID in the new file for the
+reference track.
+
+Changes in 0.9.9
+---------------------------
+Added support for ISMA's Ismacrypt specification:
+ MP4GetTrackEsdsObjectTypeId replaces MP4GetTrackAudioType
+ and MP4GetTrackVideoType.
+ MP4EncAndCloneTrack is used instead of MP4CloneTrack to encrypt a track
+ while cloning it.
+ MP4EncAndCopyTrack is used instead of MP4CopyTrack to encrypt a track
+ while copying it.
+ MP4AddEncAudioTrack adds an encrypted audio track.
+ MP4AddEncVideoTrack adds an encrypted video track.
+
+
+Changes in 0.9.8
+---------------------------
+ MP4WriteSample - changed "uint8_t * data" to "const uint8_t *data"
+
+Changes from 0.9.6
+---------------------------
+Modified
+ MP4SetHintTrackRtpPayload
+ payload parameter to get a dynamic payload is MP4_SET_DYNAMIC_PAYLOAD
+ (value 0xff) instead of 0.
+
+Changes from 0.9.5 to 0.9.6
+---------------------------
+Modified
+ MP4GetHintTrackRtpPayload
+ MP4SetHintTrackRtpPayload
+ get/set the encoding params (a=rtpmap <payloadname>/<timescale>[/<encoding params>])
+
+Changes from 0.9.4 to 0.9.5
+---------------------------
+Added
+ MP4GetTrackAudioMpeg4Type()
+ Returns MPEG-4 Audio type (e.g. AAC, CELP, HXVC, MIDI, etc.)
+ MP4ReadSampleFromTime()
+ Variant of MP4ReadSample() that uses time instead of sample id
+ (basically MP4GetSampleIdFromTime() + MP4ReadSample())
+ MP4Info()
+ MP4FileInfo()
+ Returns summary info on tracks in file (from util/mp4info.cpp)
+
+ The following functions add support for mp4 authoring/editting:
+
+ MP4CloneTrack()
+ Make a copy of a specified track, without media samples
+ MP4CopyTrack()
+ Make a copy of a specified track, with or without media samples
+ MP4CopySample()
+ Make a copy of a specified media sample
+
+ MP4AddTrackEdit()
+ Add a track edit list element
+ MP4DeleteTrackEdit()
+ Delete a track edit list element
+ MP4GetTrackNumberOfEdits()
+ Return the number of track edit list elements
+ MP4GetTrackEditTotalDuration()
+ Return the total duration of the track edit list
+ MP4GetTrackEditStart()
+ Return the edit start time for the edit list element
+ MP4GetTrackEditMediaStart()
+ Return the media start time for the edit list element
+ MP4SetTrackEditMediaStart()
+ Set the media start time for the edit list element
+ MP4GetTrackEditDuration()
+ Return the edit list element duration
+ MP4SetTrackEditDuration()
+ Set the edit list element duration
+ MP4GetTrackEditDwell()
+ Return the edit list element dwell parameter, see man page
+ MP4SetTrackEditDwell()
+ Set the edit list element dwell parameter, see man page
+ MP4ReadSampleFromEditTime()
+ Apply the edit list timeline to reading a sample
+ MP4GetSampleIdFromEditTime()
+ Return the sample id for a specified time on the edit list timeline
+
+Modified
+ MP4GetSampleIdFromTime()
+ Semantic change - now returns sample id corresponding
+ to specified time, not the sample id with the smallest positive
+ start time difference from the specified time.
+
+
+Changes from 0.9.3 to 0.9.4
+---------------------------
+Added
+ MP4GetTrackVideoFrameRate()
+ Returns video frame rate (average rate if video is variable rate).
+
+ MP4GetTrackBitRate()
+ Returns track average bit rate in bits-per-second.
+
+Changes from 0.9.2 to 0.9.3
+---------------------------
+Modified
+ MP4Optimize()
+ Second argument, newFileName, can now be NULL in which case
+ a temporary file is created for the results of the optimization.
+ Upon success, the existing file specified with the first argument
+ is overwritten with the optimized file.
+
+ MP4GetNumberOfTracks()
+ MP4FindTrackId()
+ Both have a new optional argument, subType, with default value 0.
+ The subType can be specified for audio and video tracks to
+ match only a specific encoding type. See man page for more details.
+
+Added
+ MP4GetTrackVideoWidth()
+ Returns video width in pixels. See man page for caveat.
+
+ MP4GetTrackVideoHeight()
+ Returns video height in pixels. See man page for caveat.
--- /dev/null
+++ b/common/mp4v2/INTERNALS
@@ -1,0 +1,209 @@
+January 7, 2002
+
+MP4V2 LIBRARY INTERNALS
+=======================
+
+This document provides an overview of the internals of the mp4v2 library
+to aid those who wish to modify and extend it. Before reading this document,
+I recommend familiarizing yourself with the MP4 (or Quicktime) file format
+standard and the mp4v2 library API. The API is described in a set of man pages
+in mpeg4ip/doc/mp4v2, or if you prefer by looking at mp4.h.
+
+All the library code is written in C++, however the library API follows uses
+C calling conventions hence is linkable by both C and C++ programs. The
+library has been compiled and used on Linux, BSD, Windows, and Mac OS X.
+Other than libc, the library has no external dependencies, and hence can
+be used independently of the mpeg4ip package if desired. The library is
+used for both real-time recording and playback in mpeg4ip, and its runtime
+performance is up to those tasks. On the IA32 architecture compiled with gcc,
+the stripped library is approximately 600 KB code and initialized data.
+
+It is useful to think of the mp4v2 library as consisting of four layers:
+infrastructure, file format, generic tracks, and type specific track helpers.
+A description of each layer follows, from the fundamental to the optional.
+
+
+Infrastructure
+==============
+
+The infrastructure layer provides basic file I/O, memory allocation,
+error handling, string utilities, and protected arrays. The source files
+for this layer are mp4file_io, mp4util, and mp4array.
+
+Note that the array classes uses preprocessor macros instead of C++
+templates. The rationale for this is to increase portability given the
+sometimes incomplete support by some compilers for templates.
+
+
+File Format
+===========
+
+The file format layer provides the translation from the on-disk MP4 file
+format to in-memory C++ structures and back to disk. It is intended
+to exactly match the MP4 specification in syntax and semantics. It
+represents the majority of the code.
+
+There are three key structures at the file format layer: atoms, properties,
+and descriptors.
+
+Atoms are the primary containers within an mp4 file. They can contain
+any combination of properties, other atoms, or descriptors.
+
+The mp4atom files contain the base class for all the atoms, and provide
+generic functions that cover most cases. However, each atom has it's own
+subclass contained in file atom_<name>.cpp, where <name> is the four
+letter name of the atom defined in the MP4 specification. Typically this
+atom file just specifies the properties of the atom or the possible child
+atoms in the case of a container atom. In more specialized cases the atom
+specific file provides routines to initialize, read, or write the atom.
+
+Properties are the atomic pieces of information. The basic types of
+properties are integers, floats, strings, and byte arrays. For integers
+and floats there are subclasses that represent the different storage sizes,
+e.g. 8, 16, 24, 32, and 64 bit integers. For strings, there is 1 property
+class with a number of options regarding exact storage details, e.g. null
+terminated, fixed length, counted.
+
+For implementation reasons, there are also two special properties, table
+and descriptor, that are actually containers for groups of properties.
+I.e by making these containers provide a property interface much code can
+be written in a generic fashion.
+
+The mp4property files contain all the property related classes.
+
+Descriptors are containers that derive from the MPEG conventions and use
+different encoding rules than the atoms derived from the QuickTime file
+format. This means more use of bitfields and conditional existence with
+an emphasis on bit efficiency at the cost of encoding/decoding complexity.
+Descriptors can contain other descriptors and/or properties.
+
+The mp4descriptor files contain the generic base class for descriptors.
+Also the mp4property files have a descriptor wrapper class that allows a
+descriptor to behave as if it were a property. The specific descriptors
+are implemented as subclasses of the base class descriptor in manner similar
+to that of atoms. The descriptors, ocidescriptors, and qosqualifiers files
+contain these implementations.
+
+Each atom/property/descriptor has a name closely related to that in the
+MP4 specification. The difference being that the mp4v2 library doesn't
+use '-' or '_' in property names and capitalizes the first letter of each
+word, e.g. "thisIsAPropertyName". A complete name specifies the complete
+container path. The names follow the C/C++ syntax for elements and array
+indices.
+
+Examples are:
+ "moov.mvhd.duration"
+ "moov.trak[2].tkhd.duration"
+ "moov.trak[3].minf.mdia.stbl.stsz[101].sampleSize"
+
+Note "*" can be used as a wildcard for an atom name (only). This is most
+useful when dealing with the stsd atom which contains child atoms with
+various names, but shared property names.
+
+Note that internally when performance matters the code looks up a property
+by name once, and then stores the returned pointer to the property class.
+
+
+Generic Tracks
+==============
+
+The two entities at this level are the mp4 file as a whole and the tracks
+which are contained with it. The mp4file and mp4track files contain the
+implementation.
+
+The critical work done by this layer is to map the collection of atoms,
+properties, and descriptors that represent a media track into a useful,
+and consistent set of operations. For example, reading or writing a media
+sample of a track is a relatively simple operation from the library API
+perspective. However there are numerous pieces of information in the mp4
+file that need to be properly used and updated to do this. This layer
+handles all those details.
+
+Given familiarity with the mp4 spec, the code should be straight-forward.
+What may not be immediately obvious are the functions to handle chunks of
+media samples. These exist to allow optimization of the mp4 file layout by
+reordering the chunks on disk to interleave the media sample chunks of
+multiple tracks in time order. (See MP4Optimize API doc).
+
+
+Type Specific Track Helpers
+===========================
+
+This specialized code goes beyond the meta-information about tracks in
+the mp4 file to understanding and manipulating the information in the
+track samples. There are currently two helpers in the library:
+the MPEG-4 Systems Helper, and the RTP Hint Track Helper.
+
+The MPEG-4 Systems Helper is currently limited to creating the OD, BIFS,
+and SDP information about a minimal audio/video scene consistent with
+the Internet Streaming Media Alliance (ISMA) specifications. We will be
+evaluating how best to generalize the library's helper functions for
+MPEG-4 Systems without overburdening the implementation. The code for
+this helper is found in the isma and odcommands files.
+
+The RTP Hint Track Helper is more extensive in its support. The hint
+tracks contain the track packetization information needed to build
+RTP packets for streaming. The library can construct RTP packets based
+on the hint track making RTP based servers significantly easier to write.
+
+All code related to rtp hint tracks is in the rtphint files. It would also
+be useful to look at test/mp4broadcaster and mpeg4ip/server/mp4creator for
+examples of how this part of the library API can be used.
+
+
+Library API
+===========
+
+The library API is defined and implemented in the mp4 files. The API uses
+C linkage conventions, and the mp4.h file adapts itself according to whether
+C or C++ is the compilation mode.
+
+All API calls are implemented in mp4.cpp and basically pass thru's to the
+MP4File member functions. This ensures that the library has internal access
+to the same functions as available via the API. All the calls in mp4.cpp use
+C++ try/catch blocks to protect against any runtime errors in the library.
+Upon error the library will print a diagnostic message if the verbostiy level
+has MP4_DETAILS_ERROR set, and return a distinguished error value, typically
+0 or -1.
+
+The test and util subdirectories contain useful examples of how to
+use the library. Also the mp4creator and mp4live programs within
+mpeg4ip demonstrate more complete usage of the library API.
+
+
+Debugging
+=========
+
+Since mp4 files are fairly complicated, extensive debugging support is
+built into the library. Multi-level diagnostic messages are available
+under the control of a verbosity bitmask described in the API.
+
+Also the library provides the MP4Dump() call which provides an ASCII
+version of the mp4 file meta-information. The mp4dump utilitity is a
+wrapper executable around this function.
+
+The mp4extract program is also provided in the utilities directory
+which is useful for extracting a track from an mp4file and putting the
+media data back into it's own file. It can also extract each sample of
+a track into its own file it that is desired.
+
+When all else fails, mp4 files are amenable to debugging by direct
+examination. Since the atom names are four letter ASCII codes finding
+reference points in a hex dump is feasible. On UNIX, the od command
+is your friend: "od -t x1z -A x [-j 0xXXXXXX] foo.mp4" will print
+a hex and ASCII dump, with hex addresses, starting optionally from
+a specified offset. The library diagnostic messages can provide
+information on where the library is reading or writing.
+
+
+General caveats
+===============
+
+The coding convention is to use the C++ throw operator whenever an
+unrecoverable error occurs. This throw is caught at the API layer
+in mp4.cpp and translated into an error value.
+
+Be careful about indices. Internally, we follow the C/C++ convention
+to use zero-based indices. However the MP4 spec uses one-based indices
+for things like samples and hence the library API uses this convention.
+
--- /dev/null
+++ b/common/mp4v2/Makefile.am
@@ -1,0 +1,134 @@
+SUBDIRS = . test util
+
+INCLUDES = -I$(top_srcdir)/include
+
+AM_CXXFLAGS = @BILLS_CPPWARNINGS@
+
+lib_LTLIBRARIES = libmp4v2.la
+
+include_HEADERS = mp4.h
+
+libmp4v2_la_SOURCES = \
+ 3gp.cpp \
+ atom_bitr.cpp \
+ atom_co64.cpp \
+ atom_cprt.cpp \
+ atom_ctts.cpp \
+ atom_d263.cpp \
+ atom_damr.cpp \
+ atom_dimm.cpp \
+ atom_dinf.cpp \
+ atom_dmax.cpp \
+ atom_dmed.cpp \
+ atom_dref.cpp \
+ atom_drep.cpp \
+ atom_edts.cpp \
+ atom_elst.cpp \
+ atom_enca.cpp \
+ atom_encv.cpp \
+ atom_esds.cpp \
+ atom_free.cpp \
+ atom_frma.cpp \
+ atom_ftyp.cpp \
+ atom_hdlr.cpp \
+ atom_hinf.cpp \
+ atom_hmhd.cpp \
+ atom_hnti.cpp \
+ atom_iods.cpp \
+ atom_iKMS.cpp \
+ atom_iSFM.cpp \
+ atom_maxr.cpp \
+ atom_mdat.cpp \
+ atom_mdhd.cpp \
+ atom_mdia.cpp \
+ atom_meta.cpp \
+ atom_mfhd.cpp \
+ atom_minf.cpp \
+ atom_moof.cpp \
+ atom_moov.cpp \
+ atom_mp4a.cpp \
+ atom_mp4s.cpp \
+ atom_mp4v.cpp \
+ atom_mvex.cpp \
+ atom_mvhd.cpp \
+ atom_nmhd.cpp \
+ atom_nump.cpp \
+ atom_payt.cpp \
+ atom_pmax.cpp \
+ atom_root.cpp \
+ atom_rtp.cpp \
+ atom_s263.cpp \
+ atom_samr.cpp \
+ atom_sawb.cpp \
+ atom_schi.cpp \
+ atom_schm.cpp \
+ atom_sdp.cpp \
+ atoms.h \
+ atom_sinf.cpp \
+ atom_smhd.cpp \
+ atom_snro.cpp \
+ atom_stbl.cpp \
+ atom_stco.cpp \
+ atom_stdp.cpp \
+ atom_stsc.cpp \
+ atom_stsd.cpp \
+ atom_stsh.cpp \
+ atom_stss.cpp \
+ atom_stsz.cpp \
+ atom_stts.cpp \
+ atom_tfhd.cpp \
+ atom_tims.cpp \
+ atom_tkhd.cpp \
+ atom_tmax.cpp \
+ atom_tmin.cpp \
+ atom_tpyl.cpp \
+ atom_traf.cpp \
+ atom_trak.cpp \
+ atom_tref.cpp \
+ atom_treftype.cpp \
+ atom_trex.cpp \
+ atom_trpy.cpp \
+ atom_trun.cpp \
+ atom_tsro.cpp \
+ atom_udta.cpp \
+ atom_url.cpp \
+ atom_urn.cpp \
+ atom_vmhd.cpp \
+ descriptors.cpp \
+ descriptors.h \
+ isma.cpp \
+ mp4array.h \
+ mp4atom.cpp \
+ mp4atom.h \
+ mp4common.h \
+ mp4container.cpp \
+ mp4container.h \
+ mp4.cpp \
+ mp4descriptor.cpp \
+ mp4descriptor.h \
+ mp4file.cpp \
+ mp4file.h \
+ mp4file_io.cpp \
+ mp4info.cpp \
+ mp4meta.cpp \
+ mp4property.cpp \
+ mp4property.h \
+ mp4track.cpp \
+ mp4track.h \
+ mp4util.cpp \
+ mp4util.h \
+ ocidescriptors.cpp \
+ ocidescriptors.h \
+ odcommands.cpp \
+ odcommands.h \
+ qosqualifiers.cpp \
+ qosqualifiers.h \
+ rtphint.cpp \
+ rtphint.h
+
+EXTRA_DIST = API_CHANGES \
+ INTERNALS \
+ libmp4v260.dsp \
+ libmp4v2_st60.dsp \
+ TODO \
+ libmp4v2.xcode/project.pbxproj
--- /dev/null
+++ b/common/mp4v2/README
@@ -1,0 +1,30 @@
+July 18, 2002
+
+MP4V2 Library
+=============
+
+This library provides functions to read, create, and modify mp4 files.
+
+The detailed documentation of the library is available as a set of man pages
+in mpeg4ip/doc/mp4v2. The MP4.3 man page gives an overview of the library.
+
+Alternately mp4.h in this directory specifies the complete API.
+
+The file INTERNALS provides an overview of what is happening behind the API.
+Note that although we using C++ object oriented features internally, that's
+all hidden behind a flat C style API (with C linkage conventions).
+
+The test and util subdirectories contain some simple programs that use
+this library.
+
+To use this library in your application, it should be sufficient to:
+
+1) add mpeg4ip/include and mpeg4ip/lib/mp4v2 to your INCLUDE path,
+ e.g. gcc -Impeg4ip/include -Impeg4ip/lib/mp4v2 ...
+
+2) add mpeg4ip/lib/mp4v2/libmp4v2.la (or /usr/local/lib/libmp4v2.la)
+ e.g. gcc ... -o foo foo.cpp mpeg4ip/lib/mp4v2/libmp4v2.a
+
+3) include mp4.h into your code,
+ e.g. #include <mp4.h>
+
--- /dev/null
+++ b/common/mp4v2/TODO
@@ -1,0 +1,9 @@
+
+Add ability to create samples referenced in multiple tracks
+
+Add ability to create atoms/properties via set or add operations
+
+Exploit extended format (ISO v2)
+
+List all possible atoms/properties with types
+
--- /dev/null
+++ b/common/mp4v2/atom_bitr.cpp
@@ -1,0 +1,41 @@
+/*
+ * 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.
+ *
+ * 3GPP features implementation is based on 3GPP's TS26.234-v5.60,
+ * and was contributed by Ximpo Group Ltd.
+ *
+ * Portions created by Ximpo Group Ltd. are
+ * Copyright (C) Ximpo Group Ltd. 2003, 2004. All Rights Reserved.
+ *
+ * Contributor(s):
+ * Ximpo Group Ltd. mp4v2@ximpo.com
+ */
+
+#include "mp4common.h"
+
+MP4BitrAtom::MP4BitrAtom()
+ : MP4Atom("bitr")
+{
+ AddProperty( /* 0 */
+ new MP4Integer32Property("avgBitrate"));
+
+ AddProperty( /* 1 */
+ new MP4Integer32Property("maxBitrate"));
+
+
+}
+
--- /dev/null
+++ b/common/mp4v2/atom_co64.cpp
@@ -1,0 +1,38 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4Co64Atom::MP4Co64Atom()
+ : MP4Atom("co64")
+{
+ AddVersionAndFlags();
+
+ MP4Integer32Property* pCount =
+ new MP4Integer32Property("entryCount");
+ AddProperty(pCount);
+
+ MP4TableProperty* pTable = new MP4TableProperty("entries", pCount);
+ AddProperty(pTable);
+
+ pTable->AddProperty(
+ new MP4Integer64Property("chunkOffset"));
+}
--- /dev/null
+++ b/common/mp4v2/atom_cprt.cpp
@@ -1,0 +1,32 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4CprtAtom::MP4CprtAtom()
+ : MP4Atom("cprt")
+{
+ AddVersionAndFlags();
+ AddProperty(
+ new MP4Integer16Property("language"));
+ AddProperty(
+ new MP4StringProperty("notice"));
+}
--- /dev/null
+++ b/common/mp4v2/atom_ctts.cpp
@@ -1,0 +1,40 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4CttsAtom::MP4CttsAtom()
+ : MP4Atom("ctts")
+{
+ AddVersionAndFlags();
+
+ MP4Integer32Property* pCount =
+ new MP4Integer32Property("entryCount");
+ AddProperty(pCount);
+
+ MP4TableProperty* pTable = new MP4TableProperty("entries", pCount);
+ AddProperty(pTable);
+
+ pTable->AddProperty(
+ new MP4Integer32Property("sampleCount"));
+ pTable->AddProperty(
+ new MP4Integer32Property("sampleOffset"));
+}
--- /dev/null
+++ b/common/mp4v2/atom_d263.cpp
@@ -1,0 +1,88 @@
+/*
+ * 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.
+ *
+ * 3GPP features implementation is based on 3GPP's TS26.234-v5.60,
+ * and was contributed by Ximpo Group Ltd.
+ *
+ * Portions created by Ximpo Group Ltd. are
+ * Copyright (C) Ximpo Group Ltd. 2003, 2004. All Rights Reserved.
+ *
+ * Contributor(s):
+ * Ximpo Group Ltd. mp4v2@ximpo.com
+ */
+
+#include "mp4common.h"
+
+#define H263_VENDOR 0x6d346970
+
+MP4D263Atom::MP4D263Atom()
+ : MP4Atom("d263")
+{
+ AddProperty( /* 0 */
+ new MP4Integer32Property("vendor"));
+
+ AddProperty( /* 1 */
+ new MP4Integer8Property("decoderVersion"));
+
+ AddProperty( /* 2 */
+ new MP4Integer8Property("h263Level"));
+
+ AddProperty( /* 3 */
+ new MP4Integer8Property("h263Profile"));
+
+ ExpectChildAtom("bitr", Optional, OnlyOne);
+
+}
+
+void MP4D263Atom::Generate()
+{
+ MP4Atom::Generate();
+
+ ((MP4Integer32Property*)m_pProperties[0])->SetValue(H263_VENDOR);
+ ((MP4Integer8Property*)m_pProperties[1])->SetValue(1);
+
+}
+
+void MP4D263Atom::Write()
+{
+ // Check whether we have valid values in the bitr atom
+ // (if it exists, of course)
+ MP4Atom* bitrAtom = FindAtom("d263.bitr");
+ if (bitrAtom) {
+ u_int32_t avgBitrate;
+ u_int32_t maxBitrate;
+
+ MP4Integer32Property* pProp;
+ bitrAtom->FindProperty("bitr.avgBitrate",
+ (MP4Property**)&pProp,
+ NULL);
+ ASSERT(pProp);
+ avgBitrate = pProp->GetValue();
+
+ bitrAtom->FindProperty("bitr.maxBitrate",
+ (MP4Property**)&pProp,
+ NULL);
+ ASSERT(pProp);
+ maxBitrate = pProp->GetValue();
+
+ if(!maxBitrate && !avgBitrate) {
+ DeleteChildAtom(bitrAtom);
+ }
+ }
+
+ MP4Atom::Write();
+}
--- /dev/null
+++ b/common/mp4v2/atom_damr.cpp
@@ -1,0 +1,59 @@
+/*
+ * 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.
+ *
+ * 3GPP features implementation is based on 3GPP's TS26.234-v5.60,
+ * and was contributed by Ximpo Group Ltd.
+ *
+ * Portions created by Ximpo Group Ltd. are
+ * Copyright (C) Ximpo Group Ltd. 2003, 2004. All Rights Reserved.
+ *
+ * Contributor(s):
+ * Ximpo Group Ltd. mp4v2@ximpo.com
+ */
+
+#include "mp4common.h"
+
+#define AMR_VENDOR 0x6d346970
+
+MP4DamrAtom::MP4DamrAtom()
+ : MP4Atom("damr")
+{
+ AddProperty( /* 0 */
+ new MP4Integer32Property("vendor"));
+
+ AddProperty( /* 1 */
+ new MP4Integer8Property("decoderVersion"));
+
+ AddProperty( /* 2 */
+ new MP4Integer16Property("modeSet"));
+
+ AddProperty( /* 3 */
+ new MP4Integer8Property("modeChangePeriod"));
+
+ AddProperty( /* 4 */
+ new MP4Integer8Property("framesPerSample"));
+
+}
+
+void MP4DamrAtom::Generate()
+{
+ MP4Atom::Generate();
+
+ ((MP4Integer32Property*)m_pProperties[0])->SetValue(AMR_VENDOR);
+ ((MP4Integer8Property*)m_pProperties[1])->SetValue(1);
+
+}
--- /dev/null
+++ b/common/mp4v2/atom_dimm.cpp
@@ -1,0 +1,29 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4DimmAtom::MP4DimmAtom()
+ : MP4Atom("dimm")
+{
+ AddProperty( // bytes of immediate data
+ new MP4Integer64Property("bytes"));
+}
--- /dev/null
+++ b/common/mp4v2/atom_dinf.cpp
@@ -1,0 +1,28 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4DinfAtom::MP4DinfAtom()
+ : MP4Atom("dinf")
+{
+ ExpectChildAtom("dref", Required, OnlyOne);
+}
--- /dev/null
+++ b/common/mp4v2/atom_dmax.cpp
@@ -1,0 +1,29 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4DmaxAtom::MP4DmaxAtom()
+ : MP4Atom("dmax")
+{
+ AddProperty( // max packet duration
+ new MP4Integer32Property("milliSecs"));
+}
--- /dev/null
+++ b/common/mp4v2/atom_dmed.cpp
@@ -1,0 +1,29 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4DmedAtom::MP4DmedAtom()
+ : MP4Atom("dmed")
+{
+ AddProperty( // bytes sent from media data
+ new MP4Integer64Property("bytes"));
+}
--- /dev/null
+++ b/common/mp4v2/atom_dref.cpp
@@ -1,0 +1,56 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4DrefAtom::MP4DrefAtom()
+ : MP4Atom("dref")
+{
+ AddVersionAndFlags();
+
+ MP4Integer32Property* pCount =
+ new MP4Integer32Property("entryCount");
+ pCount->SetReadOnly();
+ AddProperty(pCount);
+
+ ExpectChildAtom("url ", Optional, Many);
+ ExpectChildAtom("urn ", Optional, Many);
+}
+
+void MP4DrefAtom::Read()
+{
+ /* do the usual read */
+ MP4Atom::Read();
+
+ // check that number of children == entryCount
+ MP4Integer32Property* pCount =
+ (MP4Integer32Property*)m_pProperties[2];
+
+ if (m_pChildAtoms.Size() != pCount->GetValue()) {
+ VERBOSE_READ(GetVerbosity(),
+ MP4Printf("Warning: dref inconsistency with number of entries"));
+
+ /* fix it */
+ pCount->SetReadOnly(false);
+ pCount->SetValue(m_pChildAtoms.Size());
+ pCount->SetReadOnly(true);
+ }
+}
--- /dev/null
+++ b/common/mp4v2/atom_drep.cpp
@@ -1,0 +1,29 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4DrepAtom::MP4DrepAtom()
+ : MP4Atom("drep")
+{
+ AddProperty( // bytes of repeated data
+ new MP4Integer64Property("bytes"));
+}
--- /dev/null
+++ b/common/mp4v2/atom_edts.cpp
@@ -1,0 +1,28 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4EdtsAtom::MP4EdtsAtom()
+ : MP4Atom("edts")
+{
+ ExpectChildAtom("elst", Required, OnlyOne);
+}
--- /dev/null
+++ b/common/mp4v2/atom_elst.cpp
@@ -1,0 +1,80 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4ElstAtom::MP4ElstAtom()
+ : MP4Atom("elst")
+{
+ AddVersionAndFlags();
+
+ MP4Integer32Property* pCount =
+ new MP4Integer32Property("entryCount");
+ AddProperty(pCount);
+
+ MP4TableProperty* pTable = new MP4TableProperty("entries", pCount);
+ AddProperty(pTable);
+}
+
+void MP4ElstAtom::AddProperties(u_int8_t version)
+{
+ MP4TableProperty* pTable = (MP4TableProperty*)m_pProperties[3];
+
+ if (version == 1) {
+ pTable->AddProperty(
+ new MP4Integer64Property("segmentDuration"));
+ pTable->AddProperty(
+ new MP4Integer64Property("mediaTime"));
+ } else {
+ pTable->AddProperty(
+ new MP4Integer32Property("segmentDuration"));
+ pTable->AddProperty(
+ new MP4Integer32Property("mediaTime"));
+ }
+
+ pTable->AddProperty(
+ new MP4Integer16Property("mediaRate"));
+ pTable->AddProperty(
+ new MP4Integer16Property("reserved"));
+}
+
+void MP4ElstAtom::Generate()
+{
+ SetVersion(0);
+ AddProperties(GetVersion());
+
+ MP4Atom::Generate();
+}
+
+void MP4ElstAtom::Read()
+{
+ /* read atom version */
+ ReadProperties(0, 1);
+
+ /* need to create the properties based on the atom version */
+ AddProperties(GetVersion());
+
+ /* now we can read the remaining properties */
+ ReadProperties(1);
+
+ Skip(); // to end of atom
+}
+
--- /dev/null
+++ b/common/mp4v2/atom_enca.cpp
@@ -1,0 +1,61 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4EncaAtom::MP4EncaAtom()
+ : MP4Atom("enca")
+{
+ AddReserved("reserved1", 6); /* 0 */
+
+ AddProperty( /* 1 */
+ new MP4Integer16Property("dataReferenceIndex"));
+
+ AddReserved("reserved2", 16); /* 2 */
+
+ AddProperty( /* 3 */
+ new MP4Integer16Property("timeScale"));
+
+ AddReserved("reserved3", 2); /* 4 */
+
+ ExpectChildAtom("esds", Required, OnlyOne);
+ ExpectChildAtom("sinf", Required, OnlyOne);
+}
+
+void MP4EncaAtom::Generate()
+{
+ MP4Atom::Generate();
+
+ ((MP4Integer16Property*)m_pProperties[1])->SetValue(1);
+
+ // property reserved2 has non-zero fixed values
+ static u_int8_t reserved2[16] = {
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x02, 0x00, 0x10,
+ 0x00, 0x00, 0x00, 0x00,
+ };
+ m_pProperties[2]->SetReadOnly(false);
+ ((MP4BytesProperty*)m_pProperties[2])->
+ SetValue(reserved2, sizeof(reserved2));
+ m_pProperties[2]->SetReadOnly(true);
+}
--- /dev/null
+++ b/common/mp4v2/atom_encv.cpp
@@ -1,0 +1,80 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4EncvAtom::MP4EncvAtom()
+ : MP4Atom("encv")
+{
+ AddReserved("reserved1", 6); /* 0 */
+
+ AddProperty( /* 1 */
+ new MP4Integer16Property("dataReferenceIndex"));
+
+ AddReserved("reserved2", 16); /* 2 */
+
+ AddProperty( /* 3 */
+ new MP4Integer16Property("width"));
+ AddProperty( /* 4 */
+ new MP4Integer16Property("height"));
+
+ AddReserved("reserved3", 14); /* 5 */
+
+ MP4StringProperty* pProp =
+ new MP4StringProperty("compressorName");
+ pProp->SetFixedLength(32);
+ pProp->SetValue("");
+ AddProperty(pProp); /* 6 */
+ AddReserved("reserved4", 4); /* 7 */
+
+ ExpectChildAtom("esds", Required, OnlyOne);
+ ExpectChildAtom("sinf", Required, OnlyOne);
+}
+
+void MP4EncvAtom::Generate()
+{
+ MP4Atom::Generate();
+
+ ((MP4Integer16Property*)m_pProperties[1])->SetValue(1);
+
+ // property reserved3 has non-zero fixed values
+ static u_int8_t reserved3[14] = {
+ 0x00, 0x48, 0x00, 0x00,
+ 0x00, 0x48, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x01,
+ };
+ m_pProperties[5]->SetReadOnly(false);
+ ((MP4BytesProperty*)m_pProperties[5])->
+ SetValue(reserved3, sizeof(reserved3));
+ m_pProperties[5]->SetReadOnly(true);
+
+ // property reserved4 has non-zero fixed values
+ static u_int8_t reserved4[4] = {
+ 0x00, 0x18, 0xFF, 0xFF,
+ };
+ m_pProperties[7]->SetReadOnly(false);
+ ((MP4BytesProperty*)m_pProperties[7])->
+ SetValue(reserved4, sizeof(reserved4));
+ m_pProperties[7]->SetReadOnly(true);
+}
+
--- /dev/null
+++ b/common/mp4v2/atom_esds.cpp
@@ -1,0 +1,31 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4EsdsAtom::MP4EsdsAtom()
+ : MP4Atom("esds")
+{
+ AddVersionAndFlags();
+ AddProperty(
+ new MP4DescriptorProperty(NULL,
+ MP4ESDescrTag, 0, Required, OnlyOne));
+}
--- /dev/null
+++ b/common/mp4v2/atom_free.cpp
@@ -1,0 +1,43 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4FreeAtom::MP4FreeAtom()
+ : MP4Atom("free")
+{
+}
+
+void MP4FreeAtom::Read()
+{
+ Skip();
+}
+
+void MP4FreeAtom::Write()
+{
+ ASSERT(m_pFile);
+
+ bool use64 = (GetSize() > (0xFFFFFFFF - 8));
+ BeginWrite(use64);
+ m_pFile->SetPosition(m_pFile->GetPosition() + GetSize());
+ FinishWrite(use64);
+}
+
--- /dev/null
+++ b/common/mp4v2/atom_frma.cpp
@@ -1,0 +1,32 @@
+/*
+ * 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):
+ * Alix Marchandise-Franquet alix@cisco.com
+ *
+ * Add the OriginalFormatBox for ISMACrypt
+ * contains the original format of the data (i.e. decrypted format)
+ */
+
+#include "mp4common.h"
+
+MP4FrmaAtom::MP4FrmaAtom()
+ : MP4Atom("frma")
+{
+ AddProperty( /* 0 */
+ new MP4Integer32Property("data-format"));
+}
--- /dev/null
+++ b/common/mp4v2/atom_ftyp.cpp
@@ -1,0 +1,71 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4FtypAtom::MP4FtypAtom()
+ : MP4Atom("ftyp")
+{
+ MP4StringProperty* pProp = new MP4StringProperty("majorBrand");
+ pProp->SetFixedLength(4);
+ AddProperty(pProp); /* 0 */
+
+ AddProperty( /* 1 */
+ new MP4Integer32Property("minorVersion"));
+
+ MP4Integer32Property* pCount =
+ new MP4Integer32Property("compatibleBrandsCount");
+ pCount->SetImplicit();
+ AddProperty(pCount); /* 2 */
+
+ MP4TableProperty* pTable =
+ new MP4TableProperty("compatibleBrands", pCount);
+ AddProperty(pTable); /* 3 */
+
+ pProp = new MP4StringProperty("brand");
+ pProp->SetFixedLength(4);
+ pTable->AddProperty(pProp);
+}
+
+void MP4FtypAtom::Generate()
+{
+ MP4Atom::Generate();
+
+ ((MP4StringProperty*)m_pProperties[0])->SetValue("mp42");
+
+ MP4StringProperty* pBrandProperty = (MP4StringProperty*)
+ ((MP4TableProperty*)m_pProperties[3])->GetProperty(0);
+ ASSERT(pBrandProperty);
+ pBrandProperty->AddValue("mp42");
+ pBrandProperty->AddValue("isom");
+ ((MP4Integer32Property*)m_pProperties[2])->IncrementValue();
+ ((MP4Integer32Property*)m_pProperties[2])->IncrementValue();
+}
+
+void MP4FtypAtom::Read()
+{
+ // table entry count computed from atom size
+ ((MP4Integer32Property*)m_pProperties[2])->SetReadOnly(false);
+ ((MP4Integer32Property*)m_pProperties[2])->SetValue((m_size - 8) / 4);
+ ((MP4Integer32Property*)m_pProperties[2])->SetReadOnly(true);
+
+ MP4Atom::Read();
+}
--- /dev/null
+++ b/common/mp4v2/atom_hdlr.cpp
@@ -1,0 +1,64 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4HdlrAtom::MP4HdlrAtom()
+ : MP4Atom("hdlr")
+{
+ AddVersionAndFlags(); /* 0, 1 */
+ AddReserved("reserved1", 4); /* 2 */
+ MP4StringProperty* pProp = new MP4StringProperty("handlerType");
+ pProp->SetFixedLength(4);
+ AddProperty(pProp); /* 3 */
+ AddReserved("reserved2", 12); /* 4 */
+ AddProperty( /* 5 */
+ new MP4StringProperty("name"));
+}
+
+// There is a spec incompatiblity between QT and MP4
+// QT says name field is a counted string
+// MP4 says name field is a null terminated string
+// Here we attempt to make all things work
+void MP4HdlrAtom::Read()
+{
+ // read all the properties but the "name" field
+ ReadProperties(0, 5);
+
+ // take a peek at the next byte
+ u_int8_t strLength;
+ m_pFile->PeekBytes(&strLength, 1);
+
+ // if the value matches the remaining atom length
+ if (m_pFile->GetPosition() + strLength + 1 == GetEnd()) {
+ // read a counted string
+ MP4StringProperty* pNameProp =
+ (MP4StringProperty*)m_pProperties[5];
+ pNameProp->SetCountedFormat(true);
+ ReadProperties(5);
+ pNameProp->SetCountedFormat(false);
+ } else {
+ // read a null terminated string
+ ReadProperties(5);
+ }
+
+ Skip(); // to end of atom
+}
--- /dev/null
+++ b/common/mp4v2/atom_hinf.cpp
@@ -1,0 +1,57 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4HinfAtom::MP4HinfAtom()
+ : MP4Atom("hinf")
+{
+ ExpectChildAtom("trpy", Optional, OnlyOne);
+ ExpectChildAtom("nump", Optional, OnlyOne);
+ ExpectChildAtom("tpyl", Optional, OnlyOne);
+ ExpectChildAtom("maxr", Optional, Many);
+ ExpectChildAtom("dmed", Optional, OnlyOne);
+ ExpectChildAtom("dimm", Optional, OnlyOne);
+ ExpectChildAtom("drep", Optional, OnlyOne);
+ ExpectChildAtom("tmin", Optional, OnlyOne);
+ ExpectChildAtom("tmax", Optional, OnlyOne);
+ ExpectChildAtom("pmax", Optional, OnlyOne);
+ ExpectChildAtom("dmax", Optional, OnlyOne);
+ ExpectChildAtom("payt", Optional, OnlyOne);
+}
+
+void MP4HinfAtom::Generate()
+{
+ // hinf is special in that although all it's child atoms
+ // are optional (on read), if we generate it for writing
+ // we really want all the children
+
+ for (u_int32_t i = 0; i < m_pChildAtomInfos.Size(); i++) {
+ MP4Atom* pChildAtom =
+ CreateAtom(m_pChildAtomInfos[i]->m_name);
+
+ AddChildAtom(pChildAtom);
+
+ // and ask it to self generate
+ pChildAtom->Generate();
+ }
+}
+
--- /dev/null
+++ b/common/mp4v2/atom_hmhd.cpp
@@ -1,0 +1,39 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4HmhdAtom::MP4HmhdAtom()
+ : MP4Atom("hmhd")
+{
+ AddVersionAndFlags();
+
+ AddProperty(
+ new MP4Integer16Property("maxPduSize"));
+ AddProperty(
+ new MP4Integer16Property("avgPduSize"));
+ AddProperty(
+ new MP4Integer32Property("maxBitRate"));
+ AddProperty(
+ new MP4Integer32Property("avgBitRate"));
+ AddProperty(
+ new MP4Integer32Property("slidingAvgBitRate"));
+}
--- /dev/null
+++ b/common/mp4v2/atom_hnti.cpp
@@ -1,0 +1,40 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4HntiAtom::MP4HntiAtom()
+ : MP4Atom("hnti")
+{
+}
+
+void MP4HntiAtom::Read()
+{
+ MP4Atom* grandParent = m_pParentAtom->GetParentAtom();
+ ASSERT(grandParent);
+ if (ATOMID(grandParent->GetType()) == ATOMID("trak")) {
+ ExpectChildAtom("sdp ", Optional, OnlyOne);
+ } else {
+ ExpectChildAtom("rtp ", Optional, OnlyOne);
+ }
+
+ MP4Atom::Read();
+}
--- /dev/null
+++ b/common/mp4v2/atom_iKMS.cpp
@@ -1,0 +1,34 @@
+/*
+ * 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):
+ * Alix Marchandise-Franquet alix@cisco.com
+ *
+ * ISMAKMSBox for ISMACrypt
+ * Do we care about the string length? Do we need to handle the null-term
+ * issue like in the hdlr atom?
+ */
+
+#include "mp4common.h"
+
+MP4IKMSAtom::MP4IKMSAtom()
+ : MP4Atom("iKMS")
+{
+ AddVersionAndFlags(); /* 0, 1 */
+ MP4StringProperty* pProp = new MP4StringProperty("kms_URI");
+ AddProperty(pProp); /* 2 */
+}
--- /dev/null
+++ b/common/mp4v2/atom_iSFM.cpp
@@ -1,0 +1,38 @@
+/*
+ * 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):
+ * Alix Marchandise-Franquet alix@cisco.com
+ *
+ * ISMASampleFormatBox for ISMACrypt
+ */
+
+#include "mp4common.h"
+
+MP4ISFMAtom::MP4ISFMAtom()
+ : MP4Atom("iSFM")
+{
+ AddVersionAndFlags(); /* 0, 1 */
+ AddProperty( /* 2 */
+ new MP4BitfieldProperty("selective-encryption", 1));
+ AddProperty( /* 3 */
+ new MP4BitfieldProperty("reserved", 7));
+ AddProperty( /* 4 */
+ new MP4Integer8Property("key-indicator-length"));
+ AddProperty( /* 5 */
+ new MP4Integer8Property("IV-length"));
+}
--- /dev/null
+++ b/common/mp4v2/atom_iods.cpp
@@ -1,0 +1,31 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4IodsAtom::MP4IodsAtom()
+ : MP4Atom("iods")
+{
+ AddVersionAndFlags();
+ AddProperty(
+ new MP4DescriptorProperty(NULL,
+ MP4FileIODescrTag, MP4FileODescrTag, Required, OnlyOne));
+}
--- /dev/null
+++ b/common/mp4v2/atom_maxr.cpp
@@ -1,0 +1,31 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4MaxrAtom::MP4MaxrAtom()
+ : MP4Atom("maxr")
+{
+ AddProperty(
+ new MP4Integer32Property("granularity"));
+ AddProperty(
+ new MP4Integer32Property("bytes"));
+}
--- /dev/null
+++ b/common/mp4v2/atom_mdat.cpp
@@ -1,0 +1,38 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4MdatAtom::MP4MdatAtom()
+ : MP4Atom("mdat")
+{
+}
+
+void MP4MdatAtom::Read()
+{
+ Skip();
+}
+
+void MP4MdatAtom::Write()
+{
+ // should never get here
+ ASSERT(false);
+}
--- /dev/null
+++ b/common/mp4v2/atom_mdhd.cpp
@@ -1,0 +1,91 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4MdhdAtom::MP4MdhdAtom()
+ : MP4Atom("mdhd")
+{
+ AddVersionAndFlags();
+}
+
+void MP4MdhdAtom::AddProperties(u_int8_t version)
+{
+ if (version == 1) {
+ AddProperty(
+ new MP4Integer64Property("creationTime"));
+ AddProperty(
+ new MP4Integer64Property("modificationTime"));
+ } else {
+ AddProperty(
+ new MP4Integer32Property("creationTime"));
+ AddProperty(
+ new MP4Integer32Property("modificationTime"));
+ }
+
+ AddProperty(
+ new MP4Integer32Property("timeScale"));
+
+ if (version == 1) {
+ AddProperty(
+ new MP4Integer64Property("duration"));
+ } else {
+ AddProperty(
+ new MP4Integer32Property("duration"));
+ }
+
+ AddProperty(
+ new MP4Integer16Property("language"));
+ AddReserved("reserved", 2);
+}
+
+void MP4MdhdAtom::Generate()
+{
+ u_int8_t version = m_pFile->Use64Bits(GetType()) ? 1 : 0;
+ SetVersion(version);
+ AddProperties(version);
+
+ MP4Atom::Generate();
+
+ // set creation and modification times
+ MP4Timestamp now = MP4GetAbsTimestamp();
+ if (version == 1) {
+ ((MP4Integer64Property*)m_pProperties[2])->SetValue(now);
+ ((MP4Integer64Property*)m_pProperties[3])->SetValue(now);
+ } else {
+ ((MP4Integer32Property*)m_pProperties[2])->SetValue(now);
+ ((MP4Integer32Property*)m_pProperties[3])->SetValue(now);
+ }
+}
+
+void MP4MdhdAtom::Read()
+{
+ /* read atom version */
+ ReadProperties(0, 1);
+
+ /* need to create the properties based on the atom version */
+ AddProperties(GetVersion());
+
+ /* now we can read the remaining properties */
+ ReadProperties(1);
+
+ Skip(); // to end of atom
+}
--- /dev/null
+++ b/common/mp4v2/atom_mdia.cpp
@@ -1,0 +1,30 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4MdiaAtom::MP4MdiaAtom()
+ : MP4Atom("mdia")
+{
+ ExpectChildAtom("mdhd", Required, OnlyOne);
+ ExpectChildAtom("hdlr", Required, OnlyOne);
+ ExpectChildAtom("minf", Required, OnlyOne);
+}
--- /dev/null
+++ b/common/mp4v2/atom_meta.cpp
@@ -1,0 +1,197 @@
+/*
+ * 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):
+ * M. Bakker mbakker at nero.com
+ *
+ * Apple iTunes META data
+ */
+
+#include "mp4common.h"
+
+MP4MetaAtom::MP4MetaAtom()
+ : MP4Atom("meta")
+{
+ AddVersionAndFlags(); /* 0, 1 */
+
+ ExpectChildAtom("hdlr", Required, OnlyOne);
+ ExpectChildAtom("ilst", Required, OnlyOne);
+}
+
+MP4MeanAtom::MP4MeanAtom()
+ : MP4Atom("mean")
+{
+ AddVersionAndFlags(); /* 0, 1 */
+
+ AddProperty(
+ new MP4BytesProperty("metadata")); /* 2 */
+}
+
+void MP4MeanAtom::Read()
+{
+ // calculate size of the metadata from the atom size
+ ((MP4BytesProperty*)m_pProperties[2])->SetValueSize(m_size - 4);
+
+ MP4Atom::Read();
+}
+
+MP4NameAtom::MP4NameAtom()
+ : MP4Atom("name")
+{
+ AddVersionAndFlags(); /* 0, 1 */
+
+ AddProperty(
+ new MP4BytesProperty("metadata")); /* 2 */
+}
+
+void MP4NameAtom::Read()
+{
+ // calculate size of the metadata from the atom size
+ ((MP4BytesProperty*)m_pProperties[2])->SetValueSize(m_size - 4);
+
+ MP4Atom::Read();
+}
+
+MP4DataAtom::MP4DataAtom()
+ : MP4Atom("data")
+{
+ AddVersionAndFlags(); /* 0, 1 */
+ AddReserved("reserved2", 4); /* 2 */
+
+ AddProperty(
+ new MP4BytesProperty("metadata")); /* 3 */
+}
+
+void MP4DataAtom::Read()
+{
+ // calculate size of the metadata from the atom size
+ ((MP4BytesProperty*)m_pProperties[3])->SetValueSize(m_size - 8);
+
+ MP4Atom::Read();
+}
+
+MP4IlstAtom::MP4IlstAtom()
+ : MP4Atom("ilst")
+{
+ ExpectChildAtom("\251nam", Optional, OnlyOne); /* name */
+ ExpectChildAtom("\251ART", Optional, OnlyOne); /* artist */
+ ExpectChildAtom("\251wrt", Optional, OnlyOne); /* writer */
+ ExpectChildAtom("\251alb", Optional, OnlyOne); /* album */
+ ExpectChildAtom("\251day", Optional, OnlyOne); /* date */
+ ExpectChildAtom("\251too", Optional, OnlyOne); /* tool */
+ ExpectChildAtom("\251cmt", Optional, OnlyOne); /* comment */
+ ExpectChildAtom("\251gen", Optional, OnlyOne); /* custom genre */
+ ExpectChildAtom("trkn", Optional, OnlyOne); /* tracknumber */
+ ExpectChildAtom("disk", Optional, OnlyOne); /* disknumber */
+ ExpectChildAtom("gnre", Optional, OnlyOne); /* genre (ID3v1 index + 1) */
+ ExpectChildAtom("cpil", Optional, OnlyOne); /* compilation */
+ ExpectChildAtom("tmpo", Optional, OnlyOne); /* BPM */
+ ExpectChildAtom("covr", Optional, OnlyOne); /* cover art */
+ ExpectChildAtom("----", Optional, Many); /* ---- free form */
+}
+
+MP4DashAtom::MP4DashAtom()
+ : MP4Atom("----")
+{
+ ExpectChildAtom("mean", Required, OnlyOne);
+ ExpectChildAtom("name", Required, OnlyOne);
+ ExpectChildAtom("data", Required, OnlyOne);
+}
+
+MP4NamAtom::MP4NamAtom()
+ : MP4Atom("\251nam")
+{
+ ExpectChildAtom("data", Required, OnlyOne);
+}
+
+MP4ArtAtom::MP4ArtAtom()
+ : MP4Atom("\251ART")
+{
+ ExpectChildAtom("data", Required, OnlyOne);
+}
+
+MP4WrtAtom::MP4WrtAtom()
+ : MP4Atom("\251wrt")
+{
+ ExpectChildAtom("data", Required, OnlyOne);
+}
+
+MP4AlbAtom::MP4AlbAtom()
+ : MP4Atom("\251alb")
+{
+ ExpectChildAtom("data", Required, OnlyOne);
+}
+
+MP4CmtAtom::MP4CmtAtom()
+ : MP4Atom("\251cmt")
+{
+ ExpectChildAtom("data", Required, OnlyOne);
+}
+
+MP4TrknAtom::MP4TrknAtom()
+ : MP4Atom("trkn")
+{
+ ExpectChildAtom("data", Required, OnlyOne);
+}
+
+MP4DiskAtom::MP4DiskAtom()
+ : MP4Atom("disk")
+{
+ ExpectChildAtom("data", Required, OnlyOne);
+}
+
+MP4DayAtom::MP4DayAtom()
+ : MP4Atom("\251day")
+{
+ ExpectChildAtom("data", Required, OnlyOne);
+}
+
+MP4GenAtom::MP4GenAtom()
+ : MP4Atom("\251gen")
+{
+ ExpectChildAtom("data", Required, OnlyOne);
+}
+
+MP4TooAtom::MP4TooAtom()
+ : MP4Atom("\251too")
+{
+ ExpectChildAtom("data", Required, OnlyOne);
+}
+
+MP4GnreAtom::MP4GnreAtom()
+ : MP4Atom("gnre")
+{
+ ExpectChildAtom("data", Optional, OnlyOne);
+}
+
+MP4CpilAtom::MP4CpilAtom()
+ : MP4Atom("cpil")
+{
+ ExpectChildAtom("data", Required, OnlyOne);
+}
+
+MP4TmpoAtom::MP4TmpoAtom()
+ : MP4Atom("tmpo")
+{
+ ExpectChildAtom("data", Required, OnlyOne);
+}
+
+MP4CovrAtom::MP4CovrAtom()
+ : MP4Atom("covr")
+{
+ ExpectChildAtom("data", Required, OnlyOne);
+}
--- /dev/null
+++ b/common/mp4v2/atom_mfhd.cpp
@@ -1,0 +1,31 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4MfhdAtom::MP4MfhdAtom()
+ : MP4Atom("mfhd")
+{
+ AddVersionAndFlags(); /* 0, 1 */
+ AddProperty( /* 2 */
+ new MP4Integer32Property("sequenceNumber"));
+}
+
--- /dev/null
+++ b/common/mp4v2/atom_minf.cpp
@@ -1,0 +1,33 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4MinfAtom::MP4MinfAtom()
+ : MP4Atom("minf")
+{
+ ExpectChildAtom("vmhd", Optional, OnlyOne);
+ ExpectChildAtom("smhd", Optional, OnlyOne);
+ ExpectChildAtom("hmhd", Optional, OnlyOne);
+ ExpectChildAtom("nmhd", Optional, OnlyOne);
+ ExpectChildAtom("dinf", Required, OnlyOne);
+ ExpectChildAtom("stbl", Required, OnlyOne);
+}
--- /dev/null
+++ b/common/mp4v2/atom_moof.cpp
@@ -1,0 +1,30 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4MoofAtom::MP4MoofAtom()
+ : MP4Atom("moof")
+{
+ ExpectChildAtom("mfhd", Required, OnlyOne);
+ ExpectChildAtom("traf", Optional, Many);
+}
+
--- /dev/null
+++ b/common/mp4v2/atom_moov.cpp
@@ -1,0 +1,33 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4MoovAtom::MP4MoovAtom()
+ : MP4Atom("moov")
+{
+ ExpectChildAtom("mvhd", Required, OnlyOne);
+ ExpectChildAtom("iods", Required, OnlyOne);
+ ExpectChildAtom("trak", Required, Many);
+ ExpectChildAtom("udta", Optional, Many);
+ ExpectChildAtom("mvex", Optional, OnlyOne);
+}
+
--- /dev/null
+++ b/common/mp4v2/atom_mp4a.cpp
@@ -1,0 +1,59 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4Mp4aAtom::MP4Mp4aAtom()
+ : MP4Atom("mp4a")
+{
+ AddReserved("reserved1", 6); /* 0 */
+
+ AddProperty( /* 1 */
+ new MP4Integer16Property("dataReferenceIndex"));
+
+ AddReserved("reserved2", 16); /* 2 */
+
+ AddProperty( /* 3 */
+ new MP4Integer16Property("timeScale"));
+
+ AddReserved("reserved3", 2); /* 4 */
+
+ ExpectChildAtom("esds", Required, OnlyOne);
+}
+
+void MP4Mp4aAtom::Generate()
+{
+ MP4Atom::Generate();
+
+ ((MP4Integer16Property*)m_pProperties[1])->SetValue(1);
+
+ // property reserved2 has non-zero fixed values
+ static u_int8_t reserved2[16] = {
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x02, 0x00, 0x10,
+ 0x00, 0x00, 0x00, 0x00,
+ };
+ m_pProperties[2]->SetReadOnly(false);
+ ((MP4BytesProperty*)m_pProperties[2])->
+ SetValue(reserved2, sizeof(reserved2));
+ m_pProperties[2]->SetReadOnly(true);
+}
--- /dev/null
+++ b/common/mp4v2/atom_mp4s.cpp
@@ -1,0 +1,40 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4Mp4sAtom::MP4Mp4sAtom()
+ : MP4Atom("mp4s")
+{
+ AddReserved("reserved1", 6);
+ AddProperty(
+ new MP4Integer16Property("dataReferenceIndex"));
+
+ ExpectChildAtom("esds", Required, OnlyOne);
+}
+
+void MP4Mp4sAtom::Generate()
+{
+ MP4Atom::Generate();
+
+ ((MP4Integer16Property*)m_pProperties[1])->SetValue(1);
+}
+
--- /dev/null
+++ b/common/mp4v2/atom_mp4v.cpp
@@ -1,0 +1,79 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4Mp4vAtom::MP4Mp4vAtom()
+ : MP4Atom("mp4v")
+{
+ AddReserved("reserved1", 6); /* 0 */
+
+ AddProperty( /* 1 */
+ new MP4Integer16Property("dataReferenceIndex"));
+
+ AddReserved("reserved2", 16); /* 2 */
+
+ AddProperty( /* 3 */
+ new MP4Integer16Property("width"));
+ AddProperty( /* 4 */
+ new MP4Integer16Property("height"));
+
+ AddReserved("reserved3", 14); /* 5 */
+
+ MP4StringProperty* pProp =
+ new MP4StringProperty("compressorName");
+ pProp->SetFixedLength(32);
+ pProp->SetValue("");
+ AddProperty(pProp); /* 6 */
+
+ AddReserved("reserved4", 4); /* 7 */
+
+ ExpectChildAtom("esds", Required, OnlyOne);
+}
+
+void MP4Mp4vAtom::Generate()
+{
+ MP4Atom::Generate();
+
+ ((MP4Integer16Property*)m_pProperties[1])->SetValue(1);
+
+ // property reserved3 has non-zero fixed values
+ static u_int8_t reserved3[14] = {
+ 0x00, 0x48, 0x00, 0x00,
+ 0x00, 0x48, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x01,
+ };
+ m_pProperties[5]->SetReadOnly(false);
+ ((MP4BytesProperty*)m_pProperties[5])->
+ SetValue(reserved3, sizeof(reserved3));
+ m_pProperties[5]->SetReadOnly(true);
+
+ // property reserved4 has non-zero fixed values
+ static u_int8_t reserved4[4] = {
+ 0x00, 0x18, 0xFF, 0xFF,
+ };
+ m_pProperties[7]->SetReadOnly(false);
+ ((MP4BytesProperty*)m_pProperties[7])->
+ SetValue(reserved4, sizeof(reserved4));
+ m_pProperties[7]->SetReadOnly(true);
+}
+
--- /dev/null
+++ b/common/mp4v2/atom_mvex.cpp
@@ -1,0 +1,28 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4MvexAtom::MP4MvexAtom()
+ : MP4Atom("mvex")
+{
+ ExpectChildAtom("trex", Required, Many);
+}
--- /dev/null
+++ b/common/mp4v2/atom_mvhd.cpp
@@ -1,0 +1,136 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4MvhdAtom::MP4MvhdAtom()
+ : MP4Atom("mvhd")
+{
+ AddVersionAndFlags();
+}
+
+void MP4MvhdAtom::AddProperties(u_int8_t version)
+{
+ if (version == 1) {
+ AddProperty( /* 2 */
+ new MP4Integer64Property("creationTime"));
+ AddProperty( /* 3 */
+ new MP4Integer64Property("modificationTime"));
+ } else {
+ AddProperty( /* 2 */
+ new MP4Integer32Property("creationTime"));
+ AddProperty( /* 3 */
+ new MP4Integer32Property("modificationTime"));
+ }
+
+ AddProperty( /* 4 */
+ new MP4Integer32Property("timeScale"));
+
+ if (version == 1) {
+ AddProperty( /* 5 */
+ new MP4Integer64Property("duration"));
+ } else {
+ AddProperty( /* 5 */
+ new MP4Integer32Property("duration"));
+ }
+
+ MP4Float32Property* pProp;
+
+ pProp = new MP4Float32Property("rate");
+ pProp->SetFixed32Format();
+ AddProperty(pProp); /* 6 */
+
+ pProp = new MP4Float32Property("volume");
+ pProp->SetFixed16Format();
+ AddProperty(pProp); /* 7 */
+
+ AddReserved("reserved1", 70); /* 8 */
+
+ AddProperty( /* 9 */
+ new MP4Integer32Property("nextTrackId"));
+}
+
+void MP4MvhdAtom::Generate()
+{
+ u_int8_t version = m_pFile->Use64Bits(GetType()) ? 1 : 0;
+ SetVersion(version);
+ AddProperties(version);
+
+ MP4Atom::Generate();
+
+ // set creation and modification times
+ MP4Timestamp now = MP4GetAbsTimestamp();
+ if (version == 1) {
+ ((MP4Integer64Property*)m_pProperties[2])->SetValue(now);
+ ((MP4Integer64Property*)m_pProperties[3])->SetValue(now);
+ } else {
+ ((MP4Integer32Property*)m_pProperties[2])->SetValue(now);
+ ((MP4Integer32Property*)m_pProperties[3])->SetValue(now);
+ }
+
+ ((MP4Integer32Property*)m_pProperties[4])->SetValue(1000);
+
+ ((MP4Float32Property*)m_pProperties[6])->SetValue(1.0);
+ ((MP4Float32Property*)m_pProperties[7])->SetValue(1.0);
+
+ // property reserved has non-zero fixed values
+ static u_int8_t reserved[70] = {
+ 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x01, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x01, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x40, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ };
+ m_pProperties[8]->SetReadOnly(false);
+ ((MP4BytesProperty*)m_pProperties[8])->
+ SetValue(reserved, sizeof(reserved));
+ m_pProperties[8]->SetReadOnly(true);
+
+ // set next track id
+ ((MP4Integer32Property*)m_pProperties[9])->SetValue(1);
+}
+
+void MP4MvhdAtom::Read()
+{
+ /* read atom version */
+ ReadProperties(0, 1);
+
+ /* need to create the properties based on the atom version */
+ AddProperties(GetVersion());
+
+ /* now we can read the remaining properties */
+ ReadProperties(1);
+
+ Skip(); // to end of atom
+}
--- /dev/null
+++ b/common/mp4v2/atom_nmhd.cpp
@@ -1,0 +1,28 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4NmhdAtom::MP4NmhdAtom()
+ : MP4Atom("nmhd")
+{
+ AddVersionAndFlags();
+}
--- /dev/null
+++ b/common/mp4v2/atom_nump.cpp
@@ -1,0 +1,29 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4NumpAtom::MP4NumpAtom()
+ : MP4Atom("nump")
+{
+ AddProperty( // packets sent
+ new MP4Integer64Property("packets"));
+}
--- /dev/null
+++ b/common/mp4v2/atom_payt.cpp
@@ -1,0 +1,31 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4PaytAtom::MP4PaytAtom()
+ : MP4Atom("payt")
+{
+ AddProperty(
+ new MP4Integer32Property("payloadNumber"));
+ AddProperty(
+ new MP4StringProperty("rtpMap", Counted));
+}
--- /dev/null
+++ b/common/mp4v2/atom_pmax.cpp
@@ -1,0 +1,29 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4PmaxAtom::MP4PmaxAtom()
+ : MP4Atom("pmax")
+{
+ AddProperty( // max packet size
+ new MP4Integer32Property("bytes"));
+}
--- /dev/null
+++ b/common/mp4v2/atom_root.cpp
@@ -1,0 +1,123 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4RootAtom::MP4RootAtom()
+ : MP4Atom(NULL)
+{
+ ExpectChildAtom("ftyp", Required, OnlyOne);
+ ExpectChildAtom("moov", Required, OnlyOne);
+ ExpectChildAtom("mdat", Optional, Many);
+ ExpectChildAtom("free", Optional, Many);
+ ExpectChildAtom("skip", Optional, Many);
+ ExpectChildAtom("udta", Optional, Many);
+ ExpectChildAtom("moof", Optional, Many);
+}
+
+void MP4RootAtom::BeginWrite(bool use64)
+{
+ // only call under MP4Create() control
+ WriteAtomType("ftyp", OnlyOne);
+
+ m_pChildAtoms[GetLastMdatIndex()]->BeginWrite(m_pFile->Use64Bits("mdat"));
+}
+
+void MP4RootAtom::Write()
+{
+ // no-op
+}
+
+void MP4RootAtom::FinishWrite(bool use64)
+{
+ // finish writing last mdat atom
+ u_int32_t mdatIndex = GetLastMdatIndex();
+ m_pChildAtoms[mdatIndex]->FinishWrite(m_pFile->Use64Bits("mdat"));
+
+ // write all atoms after last mdat
+ u_int32_t size = m_pChildAtoms.Size();
+ for (u_int32_t i = mdatIndex + 1; i < size; i++) {
+ m_pChildAtoms[i]->Write();
+ }
+}
+
+void MP4RootAtom::BeginOptimalWrite()
+{
+ WriteAtomType("ftyp", OnlyOne);
+ WriteAtomType("moov", OnlyOne);
+ WriteAtomType("udta", Many);
+
+ m_pChildAtoms[GetLastMdatIndex()]->BeginWrite(m_pFile->Use64Bits("mdat"));
+}
+
+void MP4RootAtom::FinishOptimalWrite()
+{
+ // finish writing mdat
+ m_pChildAtoms[GetLastMdatIndex()]->FinishWrite(m_pFile->Use64Bits("mdat"));
+
+ // find moov atom
+ u_int32_t size = m_pChildAtoms.Size();
+ MP4Atom* pMoovAtom = NULL;
+
+ u_int32_t i;
+ for (i = 0; i < size; i++) {
+ if (!strcmp("moov", m_pChildAtoms[i]->GetType())) {
+ pMoovAtom = m_pChildAtoms[i];
+ break;
+ }
+ }
+ ASSERT(i < size);
+
+ // rewrite moov so that updated chunkOffsets are written to disk
+ m_pFile->SetPosition(pMoovAtom->GetStart());
+ u_int64_t oldSize = pMoovAtom->GetSize();
+
+ pMoovAtom->Write();
+
+ // sanity check
+ u_int64_t newSize = pMoovAtom->GetSize();
+ ASSERT(oldSize == newSize);
+}
+
+u_int32_t MP4RootAtom::GetLastMdatIndex()
+{
+ for (int32_t i = m_pChildAtoms.Size() - 1; i >= 0; i--) {
+ if (!strcmp("mdat", m_pChildAtoms[i]->GetType())) {
+ return i;
+ }
+ }
+ ASSERT(false);
+ return (u_int32_t)-1;
+}
+
+void MP4RootAtom::WriteAtomType(const char* type, bool onlyOne)
+{
+ u_int32_t size = m_pChildAtoms.Size();
+
+ for (u_int32_t i = 0; i < size; i++) {
+ if (!strcmp(type, m_pChildAtoms[i]->GetType())) {
+ m_pChildAtoms[i]->Write();
+ if (onlyOne) {
+ break;
+ }
+ }
+ }
+}
--- /dev/null
+++ b/common/mp4v2/atom_rtp.cpp
@@ -1,0 +1,147 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4RtpAtom::MP4RtpAtom()
+ : MP4Atom("rtp ")
+{
+ // The atom type "rtp " is used in two complete unrelated ways
+ // i.e. it's real two atoms with the same name
+ // To handle that we need to postpone property creation until
+ // we know who our parent atom is (stsd or hnti) which gives us
+ // the context info we need to know who we are
+}
+
+void MP4RtpAtom::AddPropertiesStsdType()
+{
+ AddReserved("reserved1", 6); /* 0 */
+
+ AddProperty( /* 1 */
+ new MP4Integer16Property("dataReferenceIndex"));
+
+ AddProperty( /* 2 */
+ new MP4Integer16Property("hintTrackVersion"));
+ AddProperty( /* 3 */
+ new MP4Integer16Property("highestCompatibleVersion"));
+ AddProperty( /* 4 */
+ new MP4Integer32Property("maxPacketSize"));
+
+ ExpectChildAtom("tims", Required, OnlyOne);
+ ExpectChildAtom("tsro", Optional, OnlyOne);
+ ExpectChildAtom("snro", Optional, OnlyOne);
+}
+
+void MP4RtpAtom::AddPropertiesHntiType()
+{
+ MP4StringProperty* pProp =
+ new MP4StringProperty("descriptionFormat");
+ pProp->SetFixedLength(4);
+ AddProperty(pProp); /* 0 */
+
+ AddProperty( /* 1 */
+ new MP4StringProperty("sdpText"));
+}
+
+void MP4RtpAtom::Generate()
+{
+ if (!strcmp(m_pParentAtom->GetType(), "stsd")) {
+ AddPropertiesStsdType();
+ GenerateStsdType();
+ } else if (!strcmp(m_pParentAtom->GetType(), "hnti")) {
+ AddPropertiesHntiType();
+ GenerateHntiType();
+ } else {
+ VERBOSE_WARNING(m_pFile->GetVerbosity(),
+ printf("Warning: rtp atom in unexpected context, can not generate"));
+ }
+}
+
+void MP4RtpAtom::GenerateStsdType()
+{
+ // generate children
+ MP4Atom::Generate();
+
+ ((MP4Integer16Property*)m_pProperties[1])->SetValue(1);
+ ((MP4Integer16Property*)m_pProperties[2])->SetValue(1);
+ ((MP4Integer16Property*)m_pProperties[3])->SetValue(1);
+}
+
+void MP4RtpAtom::GenerateHntiType()
+{
+ MP4Atom::Generate();
+
+ ((MP4StringProperty*)m_pProperties[0])->SetValue("sdp ");
+}
+
+void MP4RtpAtom::Read()
+{
+ if (!strcmp(m_pParentAtom->GetType(), "stsd")) {
+ AddPropertiesStsdType();
+ ReadStsdType();
+ } else if (!strcmp(m_pParentAtom->GetType(), "hnti")) {
+ AddPropertiesHntiType();
+ ReadHntiType();
+ } else {
+ VERBOSE_READ(m_pFile->GetVerbosity(),
+ printf("rtp atom in unexpected context, can not read"));
+ }
+
+ Skip(); // to end of atom
+}
+
+void MP4RtpAtom::ReadStsdType()
+{
+ MP4Atom::Read();
+}
+
+void MP4RtpAtom::ReadHntiType()
+{
+ ReadProperties(0, 1);
+
+ // read sdp string, length is implicit in size of atom
+ u_int64_t size = GetEnd() - m_pFile->GetPosition();
+ char* data = (char*)MP4Malloc(size + 1);
+ m_pFile->ReadBytes((u_int8_t*)data, size);
+ data[size] = '\0';
+ ((MP4StringProperty*)m_pProperties[1])->SetValue(data);
+ MP4Free(data);
+}
+
+void MP4RtpAtom::Write()
+{
+ if (!strcmp(m_pParentAtom->GetType(), "hnti")) {
+ WriteHntiType();
+ } else {
+ MP4Atom::Write();
+ }
+}
+
+void MP4RtpAtom::WriteHntiType()
+{
+ // since length of string is implicit in size of atom
+ // we need to handle this specially, and not write the terminating \0
+ MP4StringProperty* pSdp = (MP4StringProperty*)m_pProperties[1];
+ pSdp->SetFixedLength(strlen(pSdp->GetValue()));
+ MP4Atom::Write();
+ pSdp->SetFixedLength(0);
+}
+
--- /dev/null
+++ b/common/mp4v2/atom_s263.cpp
@@ -1,0 +1,78 @@
+/*
+ * 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.
+ *
+ * 3GPP features implementation is based on 3GPP's TS26.234-v5.60,
+ * and was contributed by Ximpo Group Ltd.
+ *
+ * Portions created by Ximpo Group Ltd. are
+ * Copyright (C) Ximpo Group Ltd. 2003, 2004. All Rights Reserved.
+ *
+ * Contributor(s):
+ * Ximpo Group Ltd. mp4v2@ximpo.com
+ */
+
+#include "mp4common.h"
+
+MP4S263Atom::MP4S263Atom()
+ : MP4Atom("s263")
+{
+ AddReserved("reserved1", 6); /* 0 */
+
+ AddProperty( /* 1 */
+ new MP4Integer16Property("dataReferenceIndex"));
+
+ AddReserved("reserved2", 16); /* 2 */
+
+ AddProperty( /* 3 */
+ new MP4Integer16Property("width"));
+
+ AddProperty( /* 4 */
+ new MP4Integer16Property("height"));
+
+ AddReserved("reserved3", 50); /* 5 */
+
+
+ ExpectChildAtom("d263", Required, OnlyOne);
+}
+
+void MP4S263Atom::Generate()
+{
+ MP4Atom::Generate();
+
+ ((MP4Integer16Property*)m_pProperties[1])->SetValue(1);
+
+ // property reserved2 has non-zero fixed values
+ static u_int8_t reserved3[50] = {
+ 0x00, 0x48, 0x00, 0x00,
+ 0x00, 0x48, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x01, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x24,
+ 0xFF, 0xFF
+ };
+ m_pProperties[5]->SetReadOnly(false);
+ ((MP4BytesProperty*)m_pProperties[5])->
+ SetValue(reserved3, sizeof(reserved3));
+ m_pProperties[5]->SetReadOnly(true);
+}
--- /dev/null
+++ b/common/mp4v2/atom_samr.cpp
@@ -1,0 +1,65 @@
+/*
+ * 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.
+ *
+ * 3GPP features implementation is based on 3GPP's TS26.234-v5.60,
+ * and was contributed by Ximpo Group Ltd.
+ *
+ * Portions created by Ximpo Group Ltd. are
+ * Copyright (C) Ximpo Group Ltd. 2003, 2004. All Rights Reserved.
+ *
+ * Contributor(s):
+ * Ximpo Group Ltd. mp4v2@ximpo.com
+ */
+
+#include "mp4common.h"
+
+MP4SamrAtom::MP4SamrAtom()
+ : MP4Atom("samr")
+{
+ AddReserved("reserved1", 6); /* 0 */
+
+ AddProperty( /* 1 */
+ new MP4Integer16Property("dataReferenceIndex"));
+
+ AddReserved("reserved2", 16); /* 2 */
+
+ AddProperty( /* 3 */
+ new MP4Integer16Property("timeScale"));
+
+ AddReserved("reserved3", 2); /* 4 */
+
+ ExpectChildAtom("damr", Required, OnlyOne);
+}
+
+void MP4SamrAtom::Generate()
+{
+ MP4Atom::Generate();
+
+ ((MP4Integer16Property*)m_pProperties[1])->SetValue(1);
+
+ // property reserved2 has non-zero fixed values
+ static u_int8_t reserved2[16] = {
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x02, 0x00, 0x10,
+ 0x00, 0x00, 0x00, 0x00,
+ };
+ m_pProperties[2]->SetReadOnly(false);
+ ((MP4BytesProperty*)m_pProperties[2])->
+ SetValue(reserved2, sizeof(reserved2));
+ m_pProperties[2]->SetReadOnly(true);
+}
--- /dev/null
+++ b/common/mp4v2/atom_sawb.cpp
@@ -1,0 +1,65 @@
+/*
+ * 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.
+ *
+ * 3GPP features implementation is based on 3GPP's TS26.234-v5.60,
+ * and was contributed by Ximpo Group Ltd.
+ *
+ * Portions created by Ximpo Group Ltd. are
+ * Copyright (C) Ximpo Group Ltd. 2003, 2004. All Rights Reserved.
+ *
+ * Contributor(s):
+ * Ximpo Group Ltd. mp4v2@ximpo.com
+ */
+
+#include "mp4common.h"
+
+MP4SawbAtom::MP4SawbAtom()
+ : MP4Atom("sawb")
+{
+ AddReserved("reserved1", 6); /* 0 */
+
+ AddProperty( /* 1 */
+ new MP4Integer16Property("dataReferenceIndex"));
+
+ AddReserved("reserved2", 16); /* 2 */
+
+ AddProperty( /* 3 */
+ new MP4Integer16Property("timeScale"));
+
+ AddReserved("reserved3", 2); /* 4 */
+
+ ExpectChildAtom("damr", Required, OnlyOne);
+}
+
+void MP4SawbAtom::Generate()
+{
+ MP4Atom::Generate();
+
+ ((MP4Integer16Property*)m_pProperties[1])->SetValue(1);
+
+ // property reserved2 has non-zero fixed values
+ static u_int8_t reserved2[16] = {
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x02, 0x00, 0x10,
+ 0x00, 0x00, 0x00, 0x00,
+ };
+ m_pProperties[2]->SetReadOnly(false);
+ ((MP4BytesProperty*)m_pProperties[2])->
+ SetValue(reserved2, sizeof(reserved2));
+ m_pProperties[2]->SetReadOnly(true);
+}
--- /dev/null
+++ b/common/mp4v2/atom_schi.cpp
@@ -1,0 +1,33 @@
+/*
+ * 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):
+ * Alix Marchandise-Franquet alix@cisco.com
+ *
+ * SchemeInformationBox for ISMACrypt
+ */
+
+#include "mp4common.h"
+
+MP4SchiAtom::MP4SchiAtom()
+ : MP4Atom("schi")
+{
+ // not sure if this is child atoms or table of boxes
+ // get clarification on spec 9.1.2.5
+ ExpectChildAtom("iKMS", Required, OnlyOne);
+ ExpectChildAtom("iSFM", Required, OnlyOne);
+}
--- /dev/null
+++ b/common/mp4v2/atom_schm.cpp
@@ -1,0 +1,35 @@
+/*
+ * 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):
+ * Alix Marchandise-Franquet alix@cisco.com
+ *
+ * Add the SchemeTypeBox for ISMACrypt
+ */
+
+#include "mp4common.h"
+
+MP4SchmAtom::MP4SchmAtom()
+ : MP4Atom("schm")
+{
+ AddVersionAndFlags(); /* 0, 1 */
+ AddProperty( /* 2 */
+ new MP4Integer32Property("scheme_type"));
+ AddProperty( /* 3 */
+ new MP4Integer32Property("scheme_version"));
+ // browser URI if flags set, TODO
+}
--- /dev/null
+++ b/common/mp4v2/atom_sdp.cpp
@@ -1,0 +1,53 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4SdpAtom::MP4SdpAtom() : MP4Atom("sdp ")
+{
+ AddProperty(
+ new MP4StringProperty("sdpText"));
+}
+
+void MP4SdpAtom::Read()
+{
+ // read sdp string, length is implicit in size of atom
+ u_int64_t size = GetEnd() - m_pFile->GetPosition();
+ char* data = (char*)MP4Malloc(size + 1);
+ m_pFile->ReadBytes((u_int8_t*)data, size);
+ data[size] = '\0';
+ ((MP4StringProperty*)m_pProperties[0])->SetValue(data);
+ MP4Free(data);
+}
+
+void MP4SdpAtom::Write()
+{
+ // since length of string is implicit in size of atom
+ // we need to handle this specially, and not write the terminating \0
+ MP4StringProperty* pSdp = (MP4StringProperty*)m_pProperties[0];
+ const char* sdpText = pSdp->GetValue();
+ if (sdpText) {
+ pSdp->SetFixedLength(strlen(sdpText));
+ }
+ MP4Atom::Write();
+ pSdp->SetFixedLength(0);
+}
+
--- /dev/null
+++ b/common/mp4v2/atom_sinf.cpp
@@ -1,0 +1,33 @@
+/*
+ * 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
+ *
+ * Add the ProtectionInfoBox for ISMACrypt
+ */
+
+#include "mp4common.h"
+
+MP4SinfAtom::MP4SinfAtom()
+ : MP4Atom("sinf")
+{
+ ExpectChildAtom("frma", Required, OnlyOne);
+ ExpectChildAtom("schm", Required, OnlyOne);
+ ExpectChildAtom("schi", Required, OnlyOne);
+}
--- /dev/null
+++ b/common/mp4v2/atom_smhd.cpp
@@ -1,0 +1,29 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4SmhdAtom::MP4SmhdAtom()
+ : MP4Atom("smhd")
+{
+ AddVersionAndFlags();
+ AddReserved("reserved", 4);
+}
--- /dev/null
+++ b/common/mp4v2/atom_snro.cpp
@@ -1,0 +1,30 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4SnroAtom::MP4SnroAtom()
+ : MP4Atom("snro")
+{
+ AddProperty(
+ new MP4Integer32Property("offset"));
+}
+
--- /dev/null
+++ b/common/mp4v2/atom_stbl.cpp
@@ -1,0 +1,57 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4StblAtom::MP4StblAtom()
+ : MP4Atom("stbl")
+{
+ ExpectChildAtom("stsd", Required, OnlyOne);
+ ExpectChildAtom("stts", Required, OnlyOne);
+ ExpectChildAtom("ctts", Optional, OnlyOne);
+ ExpectChildAtom("stsz", Required, OnlyOne);
+ ExpectChildAtom("stsc", Required, OnlyOne);
+ ExpectChildAtom("stco", Optional, OnlyOne);
+ ExpectChildAtom("co64", Optional, OnlyOne);
+ ExpectChildAtom("stss", Optional, OnlyOne);
+ ExpectChildAtom("stsh", Optional, OnlyOne);
+ ExpectChildAtom("stdp", Optional, OnlyOne);
+}
+
+void MP4StblAtom::Generate()
+{
+ // as usual
+ MP4Atom::Generate();
+
+ // but we also need one of the chunk offset atoms
+ MP4Atom* pChunkOffsetAtom;
+ if (m_pFile->Use64Bits(GetType())) {
+ pChunkOffsetAtom = CreateAtom("co64");
+ } else {
+ pChunkOffsetAtom = CreateAtom("stco");
+ }
+
+ AddChildAtom(pChunkOffsetAtom);
+
+ // and ask it to self generate
+ pChunkOffsetAtom->Generate();
+}
+
--- /dev/null
+++ b/common/mp4v2/atom_stco.cpp
@@ -1,0 +1,38 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4StcoAtom::MP4StcoAtom()
+ : MP4Atom("stco")
+{
+ AddVersionAndFlags();
+
+ MP4Integer32Property* pCount =
+ new MP4Integer32Property("entryCount");
+ AddProperty(pCount);
+
+ MP4TableProperty* pTable = new MP4TableProperty("entries", pCount);
+ AddProperty(pTable);
+
+ pTable->AddProperty(
+ new MP4Integer32Property("chunkOffset"));
+}
--- /dev/null
+++ b/common/mp4v2/atom_stdp.cpp
@@ -1,0 +1,49 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4StdpAtom::MP4StdpAtom()
+ : MP4Atom("stdp")
+{
+ AddVersionAndFlags();
+
+ MP4Integer32Property* pCount =
+ new MP4Integer32Property("entryCount");
+ pCount->SetImplicit();
+ AddProperty(pCount);
+
+ MP4TableProperty* pTable = new MP4TableProperty("entries", pCount);
+ AddProperty(pTable);
+
+ pTable->AddProperty(
+ new MP4Integer16Property("priority"));
+}
+
+void MP4StdpAtom::Read()
+{
+ // table entry count computed from atom size
+ ((MP4Integer32Property*)m_pProperties[2])->SetReadOnly(false);
+ ((MP4Integer32Property*)m_pProperties[2])->SetValue((m_size - 4) / 2);
+ ((MP4Integer32Property*)m_pProperties[2])->SetReadOnly(true);
+
+ MP4Atom::Read();
+}
--- /dev/null
+++ b/common/mp4v2/atom_stsc.cpp
@@ -1,0 +1,78 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4StscAtom::MP4StscAtom()
+ : MP4Atom("stsc")
+{
+ AddVersionAndFlags();
+
+ MP4Integer32Property* pCount =
+ new MP4Integer32Property("entryCount");
+ AddProperty(pCount);
+
+ MP4TableProperty* pTable = new MP4TableProperty("entries", pCount);
+ AddProperty(pTable);
+
+ pTable->AddProperty(
+ new MP4Integer32Property("firstChunk"));
+ pTable->AddProperty(
+ new MP4Integer32Property("samplesPerChunk"));
+ pTable->AddProperty(
+ new MP4Integer32Property("sampleDescriptionIndex"));
+
+ // As an optimization we add an implicit property to this table,
+ // "firstSample" that corresponds to the first sample of the firstChunk
+ MP4Integer32Property* pSample =
+ new MP4Integer32Property("firstSample");
+ pSample->SetImplicit();
+ pTable->AddProperty(pSample);
+}
+
+void MP4StscAtom::Read()
+{
+ // Read as usual
+ MP4Atom::Read();
+
+ // Compute the firstSample values for later use
+ u_int32_t count =
+ ((MP4Integer32Property*)m_pProperties[2])->GetValue();
+
+ MP4Integer32Property* pFirstChunk = (MP4Integer32Property*)
+ ((MP4TableProperty*)m_pProperties[3])->GetProperty(0);
+ MP4Integer32Property* pSamplesPerChunk = (MP4Integer32Property*)
+ ((MP4TableProperty*)m_pProperties[3])->GetProperty(1);
+ MP4Integer32Property* pFirstSample = (MP4Integer32Property*)
+ ((MP4TableProperty*)m_pProperties[3])->GetProperty(3);
+
+ MP4SampleId sampleId = 1;
+
+ for (u_int32_t i = 0; i < count; i++) {
+ pFirstSample->SetValue(sampleId, i);
+
+ if (i < count - 1) {
+ sampleId +=
+ (pFirstChunk->GetValue(i+1) - pFirstChunk->GetValue(i))
+ * pSamplesPerChunk->GetValue(i);
+ }
+ }
+}
--- /dev/null
+++ b/common/mp4v2/atom_stsd.cpp
@@ -1,0 +1,71 @@
+/*
+ * 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 - 2004. All Rights Reserved.
+ *
+ * 3GPP features implementation is based on 3GPP's TS26.234-v5.60,
+ * and was contributed by Ximpo Group Ltd.
+ *
+ * Portions created by Ximpo Group Ltd. are
+ * Copyright (C) Ximpo Group Ltd. 2003, 2004. All Rights Reserved.
+ *
+ * Contributor(s):
+ * Dave Mackie dmackie@cisco.com
+ * Alix Marchandise-Franquet alix@cisco.com
+ * Ximpo Group Ltd. mp4v2@ximpo.com
+ */
+
+#include "mp4common.h"
+
+MP4StsdAtom::MP4StsdAtom()
+ : MP4Atom("stsd")
+{
+ AddVersionAndFlags();
+
+ MP4Integer32Property* pCount =
+ new MP4Integer32Property("entryCount");
+ pCount->SetReadOnly();
+ AddProperty(pCount);
+
+ ExpectChildAtom("mp4a", Optional, Many);
+ ExpectChildAtom("enca", Optional, Many);
+ ExpectChildAtom("mp4s", Optional, Many);
+ ExpectChildAtom("mp4v", Optional, Many);
+ ExpectChildAtom("encv", Optional, Many);
+ ExpectChildAtom("rtp ", Optional, Many);
+ ExpectChildAtom("samr", Optional, Many); // For AMR-NB
+ ExpectChildAtom("sawb", Optional, Many); // For AMR-WB
+ ExpectChildAtom("s263", Optional, Many); // For H.263
+}
+
+void MP4StsdAtom::Read()
+{
+ /* do the usual read */
+ MP4Atom::Read();
+
+ // check that number of children == entryCount
+ MP4Integer32Property* pCount =
+ (MP4Integer32Property*)m_pProperties[2];
+
+ if (m_pChildAtoms.Size() != pCount->GetValue()) {
+ VERBOSE_READ(GetVerbosity(),
+ printf("Warning: stsd inconsistency with number of entries"));
+
+ /* fix it */
+ pCount->SetReadOnly(false);
+ pCount->SetValue(m_pChildAtoms.Size());
+ pCount->SetReadOnly(true);
+ }
+}
--- /dev/null
+++ b/common/mp4v2/atom_stsh.cpp
@@ -1,0 +1,40 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4StshAtom::MP4StshAtom()
+ : MP4Atom("stsh")
+{
+ AddVersionAndFlags();
+
+ MP4Integer32Property* pCount =
+ new MP4Integer32Property("entryCount");
+ AddProperty(pCount);
+
+ MP4TableProperty* pTable = new MP4TableProperty("entries", pCount);
+ AddProperty(pTable);
+
+ pTable->AddProperty(
+ new MP4Integer32Property("shadowedSampleNumber"));
+ pTable->AddProperty(
+ new MP4Integer32Property("syncSampleNumber"));
+}
--- /dev/null
+++ b/common/mp4v2/atom_stss.cpp
@@ -1,0 +1,38 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4StssAtom::MP4StssAtom()
+ : MP4Atom("stss")
+{
+ AddVersionAndFlags();
+
+ MP4Integer32Property* pCount =
+ new MP4Integer32Property("entryCount");
+ AddProperty(pCount);
+
+ MP4TableProperty* pTable = new MP4TableProperty("entries", pCount);
+ AddProperty(pTable);
+
+ pTable->AddProperty(
+ new MP4Integer32Property("sampleNumber"));
+}
--- /dev/null
+++ b/common/mp4v2/atom_stsz.cpp
@@ -1,0 +1,69 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4StszAtom::MP4StszAtom()
+ : MP4Atom("stsz")
+{
+ AddVersionAndFlags(); /* 0, 1 */
+
+ AddProperty( /* 2 */
+ new MP4Integer32Property("sampleSize"));
+
+ MP4Integer32Property* pCount =
+ new MP4Integer32Property("sampleCount");
+ AddProperty(pCount); /* 3 */
+
+ MP4TableProperty* pTable = new MP4TableProperty("entries", pCount);
+ AddProperty(pTable); /* 4 */
+
+ pTable->AddProperty( /* 4/0 */
+ new MP4Integer32Property("sampleSize"));
+}
+
+void MP4StszAtom::Read()
+{
+ ReadProperties(0, 4);
+
+ u_int32_t sampleSize =
+ ((MP4Integer32Property*)m_pProperties[2])->GetValue();
+
+ // only attempt to read entries table if sampleSize is zero
+ // i.e sample size is not constant
+ m_pProperties[4]->SetImplicit(sampleSize != 0);
+
+ ReadProperties(4);
+
+ Skip(); // to end of atom
+}
+
+void MP4StszAtom::Write()
+{
+ u_int32_t sampleSize =
+ ((MP4Integer32Property*)m_pProperties[2])->GetValue();
+
+ // only attempt to write entries table if sampleSize is zero
+ // i.e sample size is not constant
+ m_pProperties[4]->SetImplicit(sampleSize != 0);
+
+ MP4Atom::Write();
+}
--- /dev/null
+++ b/common/mp4v2/atom_stts.cpp
@@ -1,0 +1,40 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4SttsAtom::MP4SttsAtom()
+ : MP4Atom("stts")
+{
+ AddVersionAndFlags();
+
+ MP4Integer32Property* pCount =
+ new MP4Integer32Property("entryCount");
+ AddProperty(pCount);
+
+ MP4TableProperty* pTable = new MP4TableProperty("entries", pCount);
+ AddProperty(pTable);
+
+ pTable->AddProperty(
+ new MP4Integer32Property("sampleCount"));
+ pTable->AddProperty(
+ new MP4Integer32Property("sampleDelta"));
+}
--- /dev/null
+++ b/common/mp4v2/atom_tfhd.cpp
@@ -1,0 +1,69 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4TfhdAtom::MP4TfhdAtom()
+ : MP4Atom("tfhd")
+{
+ AddVersionAndFlags(); /* 0, 1 */
+ AddProperty( /* 2 */
+ new MP4Integer32Property("trackId"));
+}
+
+void MP4TfhdAtom::AddProperties(u_int32_t flags)
+{
+ if (flags & 0x01) {
+ // note this property is signed 64!
+ AddProperty(
+ new MP4Integer64Property("baseDataOffset"));
+ }
+ if (flags & 0x02) {
+ AddProperty(
+ new MP4Integer32Property("sampleDescriptionIndex"));
+ }
+ if (flags & 0x08) {
+ AddProperty(
+ new MP4Integer32Property("defaultSampleDuration"));
+ }
+ if (flags & 0x10) {
+ AddProperty(
+ new MP4Integer32Property("defaultSampleSize"));
+ }
+ if (flags & 0x20) {
+ AddProperty(
+ new MP4Integer32Property("defaultSampleFlags"));
+ }
+}
+
+void MP4TfhdAtom::Read()
+{
+ /* read atom version, flags, and trackId */
+ ReadProperties(0, 3);
+
+ /* need to create the properties based on the atom flags */
+ AddProperties(GetFlags());
+
+ /* now we can read the remaining properties */
+ ReadProperties(3);
+
+ Skip(); // to end of atom
+}
--- /dev/null
+++ b/common/mp4v2/atom_tims.cpp
@@ -1,0 +1,30 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4TimsAtom::MP4TimsAtom()
+ : MP4Atom("tims")
+{
+ AddProperty(
+ new MP4Integer32Property("timeScale"));
+}
+
--- /dev/null
+++ b/common/mp4v2/atom_tkhd.cpp
@@ -1,0 +1,124 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4TkhdAtom::MP4TkhdAtom()
+ : MP4Atom("tkhd")
+{
+ AddVersionAndFlags();
+}
+
+void MP4TkhdAtom::AddProperties(u_int8_t version)
+{
+ if (version == 1) {
+ AddProperty( /* 2 */
+ new MP4Integer64Property("creationTime"));
+ AddProperty( /* 3 */
+ new MP4Integer64Property("modificationTime"));
+ } else { // version == 0
+ AddProperty( /* 2 */
+ new MP4Integer32Property("creationTime"));
+ AddProperty( /* 3 */
+ new MP4Integer32Property("modificationTime"));
+ }
+
+ AddProperty( /* 4 */
+ new MP4Integer32Property("trackId"));
+ AddReserved("reserved1", 4); /* 5 */
+
+ if (version == 1) {
+ AddProperty( /* 6 */
+ new MP4Integer64Property("duration"));
+ } else {
+ AddProperty( /* 6 */
+ new MP4Integer32Property("duration"));
+ }
+
+ AddReserved("reserved2", 12); /* 7 */
+
+ MP4Float32Property* pProp;
+
+ pProp = new MP4Float32Property("volume");
+ pProp->SetFixed16Format();
+ AddProperty(pProp); /* 8 */
+
+ AddReserved("reserved3", 38); /* 9 */
+
+ pProp = new MP4Float32Property("width");
+ pProp->SetFixed32Format();
+ AddProperty(pProp); /* 10 */
+
+ pProp = new MP4Float32Property("height");
+ pProp->SetFixed32Format();
+ AddProperty(pProp); /* 11 */
+}
+
+void MP4TkhdAtom::Generate()
+{
+ u_int8_t version = m_pFile->Use64Bits(GetType()) ? 1 : 0;
+ SetVersion(version);
+ AddProperties(version);
+
+ MP4Atom::Generate();
+
+ // set creation and modification times
+ MP4Timestamp now = MP4GetAbsTimestamp();
+ if (version == 1) {
+ ((MP4Integer64Property*)m_pProperties[2])->SetValue(now);
+ ((MP4Integer64Property*)m_pProperties[3])->SetValue(now);
+ } else {
+ ((MP4Integer32Property*)m_pProperties[2])->SetValue(now);
+ ((MP4Integer32Property*)m_pProperties[3])->SetValue(now);
+ }
+
+ // property reserved3 has non-zero fixed values
+ static u_int8_t reserved3[38] = {
+ 0x00, 0x00,
+ 0x00, 0x01, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x01, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x40, 0x00, 0x00, 0x00,
+ };
+ m_pProperties[9]->SetReadOnly(false);
+ ((MP4BytesProperty*)m_pProperties[9])->
+ SetValue(reserved3, sizeof(reserved3));
+ m_pProperties[9]->SetReadOnly(true);
+}
+
+void MP4TkhdAtom::Read()
+{
+ /* read atom version */
+ ReadProperties(0, 1);
+
+ /* need to create the properties based on the atom version */
+ AddProperties(GetVersion());
+
+ /* now we can read the remaining properties */
+ ReadProperties(1);
+
+ Skip(); // to end of atom
+}
--- /dev/null
+++ b/common/mp4v2/atom_tmax.cpp
@@ -1,0 +1,29 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4TmaxAtom::MP4TmaxAtom()
+ : MP4Atom("tmax")
+{
+ AddProperty( // max relative xmit time
+ new MP4Integer32Property("milliSecs"));
+}
--- /dev/null
+++ b/common/mp4v2/atom_tmin.cpp
@@ -1,0 +1,29 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4TminAtom::MP4TminAtom()
+ : MP4Atom("tmin")
+{
+ AddProperty( // min relative xmit time
+ new MP4Integer32Property("milliSecs"));
+}
--- /dev/null
+++ b/common/mp4v2/atom_tpyl.cpp
@@ -1,0 +1,29 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4TpylAtom::MP4TpylAtom()
+ : MP4Atom("tpyl")
+{
+ AddProperty( // bytes sent of RTP payload data
+ new MP4Integer64Property("bytes"));
+}
--- /dev/null
+++ b/common/mp4v2/atom_traf.cpp
@@ -1,0 +1,30 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4TrafAtom::MP4TrafAtom()
+ : MP4Atom("traf")
+{
+ ExpectChildAtom("tfhd", Required, OnlyOne);
+ ExpectChildAtom("trun", Optional, Many);
+}
+
--- /dev/null
+++ b/common/mp4v2/atom_trak.cpp
@@ -1,0 +1,32 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4TrakAtom::MP4TrakAtom()
+ : MP4Atom("trak")
+{
+ ExpectChildAtom("tkhd", Required, OnlyOne);
+ ExpectChildAtom("tref", Optional, OnlyOne);
+ ExpectChildAtom("edts", Optional, OnlyOne);
+ ExpectChildAtom("mdia", Required, OnlyOne);
+ ExpectChildAtom("udta", Optional, Many);
+}
--- /dev/null
+++ b/common/mp4v2/atom_tref.cpp
@@ -1,0 +1,32 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4TrefAtom::MP4TrefAtom()
+ : MP4Atom("tref")
+{
+ ExpectChildAtom("dpnd", Optional, OnlyOne);
+ ExpectChildAtom("hint", Optional, OnlyOne);
+ ExpectChildAtom("ipir", Optional, OnlyOne);
+ ExpectChildAtom("mpod", Optional, OnlyOne);
+ ExpectChildAtom("sync", Optional, OnlyOne);
+}
--- /dev/null
+++ b/common/mp4v2/atom_treftype.cpp
@@ -1,0 +1,47 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4TrefTypeAtom::MP4TrefTypeAtom(const char* type)
+ : MP4Atom(type)
+{
+ MP4Integer32Property* pCount =
+ new MP4Integer32Property("entryCount");
+ pCount->SetImplicit();
+ AddProperty(pCount); /* 0 */
+
+ MP4TableProperty* pTable = new MP4TableProperty("entries", pCount);
+ AddProperty(pTable); /* 1 */
+
+ pTable->AddProperty( /* 1, 0 */
+ new MP4Integer32Property("trackId"));
+}
+
+void MP4TrefTypeAtom::Read()
+{
+ // table entry count computed from atom size
+ ((MP4Integer32Property*)m_pProperties[0])->SetReadOnly(false);
+ ((MP4Integer32Property*)m_pProperties[0])->SetValue(m_size / 4);
+ ((MP4Integer32Property*)m_pProperties[0])->SetReadOnly(true);
+
+ MP4Atom::Read();
+}
--- /dev/null
+++ b/common/mp4v2/atom_trex.cpp
@@ -1,0 +1,39 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4TrexAtom::MP4TrexAtom()
+ : MP4Atom("trex")
+{
+ AddVersionAndFlags(); /* 0, 1 */
+ AddProperty( /* 2 */
+ new MP4Integer32Property("trackId"));
+ AddProperty( /* 3 */
+ new MP4Integer32Property("defaultSampleDesriptionIndex"));
+ AddProperty( /* 4 */
+ new MP4Integer32Property("defaultSampleDuration"));
+ AddProperty( /* 5 */
+ new MP4Integer32Property("defaultSampleSize"));
+ AddProperty( /* 6 */
+ new MP4Integer32Property("defaultSampleFlags"));
+}
+
--- /dev/null
+++ b/common/mp4v2/atom_trpy.cpp
@@ -1,0 +1,29 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4TrpyAtom::MP4TrpyAtom()
+ : MP4Atom("trpy")
+{
+ AddProperty( // bytes sent including RTP headers
+ new MP4Integer64Property("bytes"));
+}
--- /dev/null
+++ b/common/mp4v2/atom_trun.cpp
@@ -1,0 +1,78 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4TrunAtom::MP4TrunAtom()
+ : MP4Atom("trun")
+{
+ AddVersionAndFlags(); /* 0, 1 */
+ AddProperty( /* 2 */
+ new MP4Integer32Property("sampleCount"));
+}
+
+void MP4TrunAtom::AddProperties(u_int32_t flags)
+{
+ if (flags & 0x01) {
+ // Note this is a signed 32 value
+ AddProperty(
+ new MP4Integer32Property("dataOffset"));
+ }
+ if (flags & 0x04) {
+ AddProperty(
+ new MP4Integer32Property("firstSampleFlags"));
+ }
+
+ MP4TableProperty* pTable =
+ new MP4TableProperty("samples", m_pProperties[2]);
+ AddProperty(pTable);
+
+ if (flags & 0x100) {
+ pTable->AddProperty(
+ new MP4Integer32Property("sampleDuration"));
+ }
+ if (flags & 0x200) {
+ pTable->AddProperty(
+ new MP4Integer32Property("sampleSize"));
+ }
+ if (flags & 0x400) {
+ pTable->AddProperty(
+ new MP4Integer32Property("sampleFlags"));
+ }
+ if (flags & 0x800) {
+ pTable->AddProperty(
+ new MP4Integer32Property("sampleCompositionTimeOffset"));
+ }
+}
+
+void MP4TrunAtom::Read()
+{
+ /* read atom version, flags, and sampleCount */
+ ReadProperties(0, 3);
+
+ /* need to create the properties based on the atom flags */
+ AddProperties(GetFlags());
+
+ /* now we can read the remaining properties */
+ ReadProperties(3);
+
+ Skip(); // to end of atom
+}
--- /dev/null
+++ b/common/mp4v2/atom_tsro.cpp
@@ -1,0 +1,30 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4TsroAtom::MP4TsroAtom()
+ : MP4Atom("tsro")
+{
+ AddProperty(
+ new MP4Integer32Property("offset"));
+}
+
--- /dev/null
+++ b/common/mp4v2/atom_udta.cpp
@@ -1,0 +1,39 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4UdtaAtom::MP4UdtaAtom()
+ : MP4Atom("udta")
+{
+ ExpectChildAtom("cprt", Optional, Many);
+ ExpectChildAtom("hnti", Optional, OnlyOne);
+ ExpectChildAtom("meta", Optional, OnlyOne);
+}
+
+void MP4UdtaAtom::Read()
+{
+ if (ATOMID(m_pParentAtom->GetType()) == ATOMID("trak")) {
+ ExpectChildAtom("hinf", Optional, OnlyOne);
+ }
+
+ MP4Atom::Read();
+}
--- /dev/null
+++ b/common/mp4v2/atom_url.cpp
@@ -1,0 +1,63 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4UrlAtom::MP4UrlAtom()
+ : MP4Atom("url ")
+{
+ AddVersionAndFlags();
+ AddProperty(new MP4StringProperty("location"));
+}
+
+void MP4UrlAtom::Read()
+{
+ // read the version and flags properties
+ ReadProperties(0, 2);
+
+ // check if self-contained flag is set
+ if (!(GetFlags() & 1)) {
+ // if not then read url location
+ ReadProperties(2);
+ }
+
+ Skip(); // to end of atom
+}
+
+void MP4UrlAtom::Write()
+{
+ MP4StringProperty* pLocationProp =
+ (MP4StringProperty*)m_pProperties[2];
+
+ // if no url location has been set
+ // then set self-contained flag
+ // and don't attempt to write anything
+ if (pLocationProp->GetValue() == NULL) {
+ SetFlags(GetFlags() | 1);
+ pLocationProp->SetImplicit(true);
+ } else {
+ SetFlags(GetFlags() & 0xFFFFFE);
+ pLocationProp->SetImplicit(false);
+ }
+
+ // write atom as usual
+ MP4Atom::Write();
+}
--- /dev/null
+++ b/common/mp4v2/atom_urn.cpp
@@ -1,0 +1,44 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4UrnAtom::MP4UrnAtom()
+ : MP4Atom("urn ")
+{
+ AddVersionAndFlags();
+ AddProperty(new MP4StringProperty("name"));
+ AddProperty(new MP4StringProperty("location"));
+}
+
+void MP4UrnAtom::Read()
+{
+ // read the version, flags, and name properties
+ ReadProperties(0, 3);
+
+ // check if location is present
+ if (m_pFile->GetPosition() < GetEnd()) {
+ // read it
+ ReadProperties(3);
+ }
+
+ Skip(); // to end of atom
+}
--- /dev/null
+++ b/common/mp4v2/atom_vmhd.cpp
@@ -1,0 +1,37 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4VmhdAtom::MP4VmhdAtom()
+ : MP4Atom("vmhd")
+{
+ AddVersionAndFlags();
+ AddReserved("reserved", 8);
+}
+
+void MP4VmhdAtom::Generate()
+{
+ MP4Atom::Generate();
+
+ SetFlags(1);
+}
+
--- /dev/null
+++ b/common/mp4v2/atoms.h
@@ -1,0 +1,635 @@
+/*
+ * 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 - 2004. All Rights Reserved.
+ *
+ * 3GPP features implementation is based on 3GPP's TS26.234-v5.60,
+ * and was contributed by Ximpo Group Ltd.
+ *
+ * Portions created by Ximpo Group Ltd. are
+ * Copyright (C) Ximpo Group Ltd. 2003, 2004. All Rights Reserved.
+ *
+ * Contributor(s):
+ * Dave Mackie dmackie@cisco.com
+ * Ximpo Group Ltd. mp4v2@ximpo.com
+ */
+
+#ifndef __MP4_ATOMS_INCLUDED__
+#define __MP4_ATOMS_INCLUDED__
+
+// declare all the atom subclasses
+// i.e. spare us atom_xxxx.h for all the atoms
+//
+// The majority of atoms just need their own constructor declared
+// Some atoms have a few special needs
+// A small minority of atoms need lots of special handling
+
+class MP4RootAtom : public MP4Atom {
+public:
+ MP4RootAtom();
+ void BeginWrite(bool use64 = false);
+ void Write();
+ void FinishWrite(bool use64 = false);
+
+ void BeginOptimalWrite();
+ void FinishOptimalWrite();
+
+protected:
+ u_int32_t GetLastMdatIndex();
+ void WriteAtomType(const char* type, bool onlyOne);
+};
+
+class MP4FtypAtom : public MP4Atom {
+public:
+ MP4FtypAtom();
+ void Generate();
+ void Read();
+};
+
+class MP4MdatAtom : public MP4Atom {
+public:
+ MP4MdatAtom();
+ void Read();
+ void Write();
+};
+
+class MP4MoovAtom : public MP4Atom {
+public:
+ MP4MoovAtom();
+};
+
+class MP4MvhdAtom : public MP4Atom {
+public:
+ MP4MvhdAtom();
+ void Generate();
+ void Read();
+protected:
+ void AddProperties(u_int8_t version);
+};
+
+class MP4IodsAtom : public MP4Atom {
+public:
+ MP4IodsAtom();
+};
+
+class MP4TrakAtom : public MP4Atom {
+public:
+ MP4TrakAtom();
+};
+
+class MP4TkhdAtom : public MP4Atom {
+public:
+ MP4TkhdAtom();
+ void Generate();
+ void Read();
+protected:
+ void AddProperties(u_int8_t version);
+};
+
+class MP4TrefAtom : public MP4Atom {
+public:
+ MP4TrefAtom();
+};
+
+class MP4TrefTypeAtom : public MP4Atom {
+public:
+ MP4TrefTypeAtom(const char* type);
+ void Read();
+};
+
+class MP4MdiaAtom : public MP4Atom {
+public:
+ MP4MdiaAtom();
+};
+
+class MP4MdhdAtom : public MP4Atom {
+public:
+ MP4MdhdAtom();
+ void Generate();
+ void Read();
+protected:
+ void AddProperties(u_int8_t version);
+};
+
+class MP4HdlrAtom : public MP4Atom {
+public:
+ MP4HdlrAtom();
+ void Read();
+};
+
+class MP4MinfAtom : public MP4Atom {
+public:
+ MP4MinfAtom();
+};
+
+class MP4VmhdAtom : public MP4Atom {
+public:
+ MP4VmhdAtom();
+ void Generate();
+};
+
+class MP4SmhdAtom : public MP4Atom {
+public:
+ MP4SmhdAtom();
+};
+
+class MP4HmhdAtom : public MP4Atom {
+public:
+ MP4HmhdAtom();
+};
+
+class MP4NmhdAtom : public MP4Atom {
+public:
+ MP4NmhdAtom();
+};
+
+class MP4DinfAtom : public MP4Atom {
+public:
+ MP4DinfAtom();
+};
+
+class MP4DrefAtom : public MP4Atom {
+public:
+ MP4DrefAtom();
+ void Read();
+};
+
+class MP4UrlAtom : public MP4Atom {
+public:
+ MP4UrlAtom();
+ void Read();
+ void Write();
+};
+
+class MP4UrnAtom : public MP4Atom {
+public:
+ MP4UrnAtom();
+ void Read();
+};
+
+class MP4StblAtom : public MP4Atom {
+public:
+ MP4StblAtom();
+ void Generate();
+};
+
+class MP4StsdAtom : public MP4Atom {
+public:
+ MP4StsdAtom();
+ void Read();
+};
+
+class MP4Mp4aAtom : public MP4Atom {
+public:
+ MP4Mp4aAtom();
+ void Generate();
+};
+
+class MP4Mp4sAtom : public MP4Atom {
+public:
+ MP4Mp4sAtom();
+ void Generate();
+};
+
+class MP4Mp4vAtom : public MP4Atom {
+public:
+ MP4Mp4vAtom();
+ void Generate();
+};
+
+class MP4EsdsAtom : public MP4Atom {
+public:
+ MP4EsdsAtom();
+};
+
+class MP4SttsAtom : public MP4Atom {
+public:
+ MP4SttsAtom();
+};
+
+class MP4CttsAtom : public MP4Atom {
+public:
+ MP4CttsAtom();
+};
+
+class MP4StszAtom : public MP4Atom {
+public:
+ MP4StszAtom();
+ void Read();
+ void Write();
+};
+
+class MP4StscAtom : public MP4Atom {
+public:
+ MP4StscAtom();
+ void Read();
+};
+
+class MP4StcoAtom : public MP4Atom {
+public:
+ MP4StcoAtom();
+};
+
+class MP4Co64Atom : public MP4Atom {
+public:
+ MP4Co64Atom();
+};
+
+class MP4StssAtom : public MP4Atom {
+public:
+ MP4StssAtom();
+};
+
+class MP4StshAtom : public MP4Atom {
+public:
+ MP4StshAtom();
+};
+
+class MP4StdpAtom : public MP4Atom {
+public:
+ MP4StdpAtom();
+ void Read();
+};
+
+class MP4EdtsAtom : public MP4Atom {
+public:
+ MP4EdtsAtom();
+};
+
+class MP4ElstAtom : public MP4Atom {
+public:
+ MP4ElstAtom();
+ void Generate();
+ void Read();
+protected:
+ void AddProperties(u_int8_t version);
+};
+
+class MP4UdtaAtom : public MP4Atom {
+public:
+ MP4UdtaAtom();
+ void Read();
+};
+
+class MP4CprtAtom : public MP4Atom {
+public:
+ MP4CprtAtom();
+};
+
+class MP4HntiAtom : public MP4Atom {
+public:
+ MP4HntiAtom();
+ void Read();
+};
+
+class MP4RtpAtom : public MP4Atom {
+public:
+ MP4RtpAtom();
+ void Generate();
+ void Read();
+ void Write();
+
+protected:
+ void AddPropertiesStsdType();
+ void AddPropertiesHntiType();
+
+ void GenerateStsdType();
+ void GenerateHntiType();
+
+ void ReadStsdType();
+ void ReadHntiType();
+
+ void WriteHntiType();
+};
+
+class MP4TimsAtom : public MP4Atom {
+public:
+ MP4TimsAtom();
+};
+
+class MP4TsroAtom : public MP4Atom {
+public:
+ MP4TsroAtom();
+};
+
+class MP4SnroAtom : public MP4Atom {
+public:
+ MP4SnroAtom();
+};
+
+class MP4SdpAtom : public MP4Atom {
+public:
+ MP4SdpAtom();
+ void Read();
+ void Write();
+};
+
+class MP4HinfAtom : public MP4Atom {
+public:
+ MP4HinfAtom();
+ void Generate();
+};
+
+class MP4TrpyAtom : public MP4Atom {
+public:
+ MP4TrpyAtom();
+};
+
+class MP4NumpAtom : public MP4Atom {
+public:
+ MP4NumpAtom();
+};
+
+class MP4TpylAtom : public MP4Atom {
+public:
+ MP4TpylAtom();
+};
+
+class MP4MaxrAtom : public MP4Atom {
+public:
+ MP4MaxrAtom();
+};
+
+class MP4DmedAtom : public MP4Atom {
+public:
+ MP4DmedAtom();
+};
+
+class MP4DimmAtom : public MP4Atom {
+public:
+ MP4DimmAtom();
+};
+
+class MP4DrepAtom : public MP4Atom {
+public:
+ MP4DrepAtom();
+};
+
+class MP4TminAtom : public MP4Atom {
+public:
+ MP4TminAtom();
+};
+
+class MP4TmaxAtom : public MP4Atom {
+public:
+ MP4TmaxAtom();
+};
+
+class MP4PmaxAtom : public MP4Atom {
+public:
+ MP4PmaxAtom();
+};
+
+class MP4DmaxAtom : public MP4Atom {
+public:
+ MP4DmaxAtom();
+};
+
+class MP4PaytAtom : public MP4Atom {
+public:
+ MP4PaytAtom();
+};
+
+class MP4MvexAtom : public MP4Atom {
+public:
+ MP4MvexAtom();
+};
+
+class MP4TrexAtom : public MP4Atom {
+public:
+ MP4TrexAtom();
+};
+
+class MP4MoofAtom : public MP4Atom {
+public:
+ MP4MoofAtom();
+};
+
+class MP4MfhdAtom : public MP4Atom {
+public:
+ MP4MfhdAtom();
+};
+
+class MP4TrafAtom : public MP4Atom {
+public:
+ MP4TrafAtom();
+};
+
+class MP4TfhdAtom : public MP4Atom {
+public:
+ MP4TfhdAtom();
+ void Read();
+protected:
+ void AddProperties(u_int32_t flags);
+};
+
+class MP4TrunAtom : public MP4Atom {
+public:
+ MP4TrunAtom();
+ void Read();
+protected:
+ void AddProperties(u_int32_t flags);
+};
+
+class MP4FreeAtom : public MP4Atom {
+public:
+ MP4FreeAtom();
+ void Read();
+ void Write();
+};
+
+class MP4EncaAtom : public MP4Atom {
+public:
+ MP4EncaAtom();
+ void Generate();
+};
+
+class MP4EncvAtom : public MP4Atom {
+public:
+ MP4EncvAtom();
+ void Generate();
+};
+
+class MP4FrmaAtom : public MP4Atom {
+public:
+ MP4FrmaAtom();
+};
+
+class MP4IKMSAtom : public MP4Atom {
+public:
+ MP4IKMSAtom();
+};
+
+class MP4ISFMAtom : public MP4Atom {
+public:
+ MP4ISFMAtom();
+};
+
+class MP4SchiAtom : public MP4Atom {
+public:
+ MP4SchiAtom();
+};
+
+class MP4SchmAtom : public MP4Atom {
+public:
+ MP4SchmAtom();
+};
+
+class MP4SinfAtom : public MP4Atom {
+public:
+ MP4SinfAtom();
+};
+
+/* iTunes META data atoms */
+class MP4MetaAtom : public MP4Atom {
+public:
+ MP4MetaAtom();
+};
+
+class MP4NameAtom : public MP4Atom {
+public:
+ MP4NameAtom();
+ void Read();
+};
+
+class MP4MeanAtom : public MP4Atom {
+public:
+ MP4MeanAtom();
+ void Read();
+};
+
+class MP4DataAtom : public MP4Atom {
+public:
+ MP4DataAtom();
+ void Read();
+};
+
+class MP4IlstAtom : public MP4Atom {
+public:
+ MP4IlstAtom();
+};
+
+class MP4DashAtom : public MP4Atom {
+public:
+ MP4DashAtom();
+};
+
+class MP4NamAtom : public MP4Atom {
+public:
+ MP4NamAtom();
+};
+
+class MP4ArtAtom : public MP4Atom {
+public:
+ MP4ArtAtom();
+};
+
+class MP4WrtAtom : public MP4Atom {
+public:
+ MP4WrtAtom();
+};
+
+class MP4AlbAtom : public MP4Atom {
+public:
+ MP4AlbAtom();
+};
+
+class MP4TrknAtom : public MP4Atom {
+public:
+ MP4TrknAtom();
+};
+
+class MP4DayAtom : public MP4Atom {
+public:
+ MP4DayAtom();
+};
+
+class MP4GenAtom : public MP4Atom {
+public:
+ MP4GenAtom();
+};
+
+class MP4TooAtom : public MP4Atom {
+public:
+ MP4TooAtom();
+};
+
+class MP4GnreAtom : public MP4Atom {
+public:
+ MP4GnreAtom();
+};
+
+class MP4CpilAtom : public MP4Atom {
+public:
+ MP4CpilAtom();
+};
+
+class MP4TmpoAtom : public MP4Atom {
+public:
+ MP4TmpoAtom();
+};
+
+class MP4CmtAtom : public MP4Atom {
+public:
+ MP4CmtAtom();
+};
+
+class MP4CovrAtom : public MP4Atom {
+ public:
+ MP4CovrAtom();
+};
+
+class MP4DiskAtom : public MP4Atom {
+public:
+ MP4DiskAtom();
+};
+
+class MP4BitrAtom : public MP4Atom {
+ public:
+ MP4BitrAtom();
+};
+
+class MP4D263Atom : public MP4Atom {
+ public:
+ MP4D263Atom();
+ void Generate();
+ void Write();
+};
+
+class MP4DamrAtom : public MP4Atom {
+ public:
+ MP4DamrAtom();
+ void Generate();
+};
+
+class MP4S263Atom : public MP4Atom {
+ public:
+ MP4S263Atom();
+ void Generate();
+};
+
+class MP4SamrAtom : public MP4Atom {
+ public:
+ MP4SamrAtom();
+ void Generate();
+};
+
+class MP4SawbAtom : public MP4Atom {
+ public:
+ MP4SawbAtom();
+ void Generate();
+};
+
+#endif /* __MP4_ATOMS_INCLUDED__ */
--- /dev/null
+++ b/common/mp4v2/descriptors.cpp
@@ -1,0 +1,634 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4IODescriptor::MP4IODescriptor()
+ : MP4Descriptor(MP4FileIODescrTag)
+{
+ /* N.B. other member functions depend on the property indicies */
+ AddProperty( /* 0 */
+ new MP4BitfieldProperty("objectDescriptorId", 10));
+ AddProperty( /* 1 */
+ new MP4BitfieldProperty("URLFlag", 1));
+ AddProperty( /* 2 */
+ new MP4BitfieldProperty("includeInlineProfileLevelFlag", 1));
+ AddProperty( /* 3 */
+ new MP4BitfieldProperty("reserved", 4));
+ AddProperty( /* 4 */
+ new MP4StringProperty("URL", Counted));
+ AddProperty( /* 5 */
+ new MP4Integer8Property("ODProfileLevelId"));
+ AddProperty( /* 6 */
+ new MP4Integer8Property("sceneProfileLevelId"));
+ AddProperty( /* 7 */
+ new MP4Integer8Property("audioProfileLevelId"));
+ AddProperty( /* 8 */
+ new MP4Integer8Property("visualProfileLevelId"));
+ AddProperty( /* 9 */
+ new MP4Integer8Property("graphicsProfileLevelId"));
+ AddProperty( /* 10 */
+ new MP4DescriptorProperty("esIds",
+ MP4ESIDIncDescrTag, 0, Required, Many));
+ AddProperty( /* 11 */
+ new MP4DescriptorProperty("ociDescr",
+ MP4OCIDescrTagsStart, MP4OCIDescrTagsEnd, Optional, Many));
+ AddProperty( /* 12 */
+ new MP4DescriptorProperty("ipmpDescrPtr",
+ MP4IPMPPtrDescrTag, 0, Optional, Many));
+ AddProperty( /* 13 */
+ new MP4DescriptorProperty("extDescr",
+ MP4ExtDescrTagsStart, MP4ExtDescrTagsEnd, Optional, Many));
+
+ SetReadMutate(2);
+}
+
+void MP4IODescriptor::Generate()
+{
+ ((MP4BitfieldProperty*)m_pProperties[0])->SetValue(1);
+ ((MP4BitfieldProperty*)m_pProperties[3])->SetValue(0xF);
+ for (u_int32_t i = 5; i <= 9; i++) {
+ ((MP4Integer8Property*)m_pProperties[i])->SetValue(0xFF);
+ }
+}
+
+void MP4IODescriptor::Mutate()
+{
+ bool urlFlag = ((MP4BitfieldProperty*)m_pProperties[1])->GetValue();
+
+ m_pProperties[4]->SetImplicit(!urlFlag);
+ for (u_int32_t i = 5; i <= 12; i++) {
+ m_pProperties[i]->SetImplicit(urlFlag);
+ }
+}
+
+MP4ODescriptor::MP4ODescriptor()
+ : MP4Descriptor(MP4FileODescrTag)
+{
+ /* N.B. other member functions depend on the property indicies */
+ AddProperty( /* 0 */
+ new MP4BitfieldProperty("objectDescriptorId", 10));
+ AddProperty( /* 1 */
+ new MP4BitfieldProperty("URLFlag", 1));
+ AddProperty( /* 2 */
+ new MP4BitfieldProperty("reserved", 5));
+ AddProperty( /* 3 */
+ new MP4StringProperty("URL", Counted));
+ AddProperty( /* 4 */
+ new MP4DescriptorProperty("esIds",
+ MP4ESIDRefDescrTag, 0, Required, Many));
+ AddProperty( /* 5 */
+ new MP4DescriptorProperty("ociDescr",
+ MP4OCIDescrTagsStart, MP4OCIDescrTagsEnd, Optional, Many));
+ AddProperty( /* 6 */
+ new MP4DescriptorProperty("ipmpDescrPtr",
+ MP4IPMPPtrDescrTag, 0, Optional, Many));
+ AddProperty( /* 7 */
+ new MP4DescriptorProperty("extDescr",
+ MP4ExtDescrTagsStart, MP4ExtDescrTagsEnd, Optional, Many));
+
+ SetReadMutate(2);
+}
+
+void MP4ODescriptor::Generate()
+{
+ ((MP4BitfieldProperty*)m_pProperties[2])->SetValue(0x1F);
+}
+
+void MP4ODescriptor::Mutate()
+{
+ bool urlFlag = ((MP4BitfieldProperty*)m_pProperties[1])->GetValue();
+
+ m_pProperties[3]->SetImplicit(!urlFlag);
+ for (u_int32_t i = 4; i <= 6; i++) {
+ m_pProperties[i]->SetImplicit(urlFlag);
+ }
+}
+
+MP4ESIDIncDescriptor::MP4ESIDIncDescriptor()
+ : MP4Descriptor(MP4ESIDIncDescrTag)
+{
+ AddProperty( /* 0 */
+ new MP4Integer32Property("id"));
+}
+
+MP4ESIDRefDescriptor::MP4ESIDRefDescriptor()
+ : MP4Descriptor(MP4ESIDRefDescrTag)
+{
+ AddProperty( /* 0 */
+ new MP4Integer16Property("refIndex"));
+}
+
+MP4ESDescriptor::MP4ESDescriptor()
+ : MP4Descriptor(MP4ESDescrTag)
+{
+ /* N.B. other class functions depend on the property indicies */
+ AddProperty( /* 0 */
+ new MP4Integer16Property("ESID"));
+ AddProperty( /* 1 */
+ new MP4BitfieldProperty("streamDependenceFlag", 1));
+ AddProperty( /* 2 */
+ new MP4BitfieldProperty("URLFlag", 1));
+ AddProperty( /* 3 */
+ new MP4BitfieldProperty("OCRstreamFlag", 1));
+ AddProperty( /* 4 */
+ new MP4BitfieldProperty("streamPriority", 5));
+ AddProperty( /* 5 */
+ new MP4Integer16Property("dependsOnESID"));
+ AddProperty( /* 6 */
+ new MP4StringProperty("URL", Counted));
+ AddProperty( /* 7 */
+ new MP4Integer16Property("OCRESID"));
+ AddProperty( /* 8 */
+ new MP4DescriptorProperty("decConfigDescr",
+ MP4DecConfigDescrTag, 0, Required, OnlyOne));
+ AddProperty( /* 9 */
+ new MP4DescriptorProperty("slConfigDescr",
+ MP4SLConfigDescrTag, 0, Required, OnlyOne));
+ AddProperty( /* 10 */
+ new MP4DescriptorProperty("ipiPtr",
+ MP4IPIPtrDescrTag, 0, Optional, OnlyOne));
+ AddProperty( /* 11 */
+ new MP4DescriptorProperty("ipIds",
+ MP4ContentIdDescrTag, MP4SupplContentIdDescrTag, Optional, Many));
+ AddProperty( /* 12 */
+ new MP4DescriptorProperty("ipmpDescrPtr",
+ MP4IPMPPtrDescrTag, 0, Optional, Many));
+ AddProperty( /* 13 */
+ new MP4DescriptorProperty("langDescr",
+ MP4LanguageDescrTag, 0, Optional, Many));
+ AddProperty( /* 14 */
+ new MP4DescriptorProperty("qosDescr",
+ MP4QosDescrTag, 0, Optional, OnlyOne));
+ AddProperty( /* 15 */
+ new MP4DescriptorProperty("regDescr",
+ MP4RegistrationDescrTag, 0, Optional, OnlyOne));
+ AddProperty( /* 16 */
+ new MP4DescriptorProperty("extDescr",
+ MP4ExtDescrTagsStart, MP4ExtDescrTagsEnd, Optional, Many));
+
+ SetReadMutate(5);
+}
+
+void MP4ESDescriptor::Mutate()
+{
+ bool streamDependFlag =
+ ((MP4BitfieldProperty*)m_pProperties[1])->GetValue();
+ m_pProperties[5]->SetImplicit(!streamDependFlag);
+
+ bool urlFlag =
+ ((MP4BitfieldProperty*)m_pProperties[2])->GetValue();
+ m_pProperties[6]->SetImplicit(!urlFlag);
+
+ bool ocrFlag =
+ ((MP4BitfieldProperty*)m_pProperties[3])->GetValue();
+ m_pProperties[7]->SetImplicit(!ocrFlag);
+}
+
+MP4DecConfigDescriptor::MP4DecConfigDescriptor()
+ : MP4Descriptor(MP4DecConfigDescrTag)
+{
+ AddProperty( /* 0 */
+ new MP4Integer8Property("objectTypeId"));
+ AddProperty( /* 1 */
+ new MP4BitfieldProperty("streamType", 6));
+ AddProperty( /* 2 */
+ new MP4BitfieldProperty("upStream", 1));
+ AddProperty( /* 3 */
+ new MP4BitfieldProperty("reserved", 1));
+ AddProperty( /* 4 */
+ new MP4BitfieldProperty("bufferSizeDB", 24));
+ AddProperty( /* 5 */
+ new MP4Integer32Property("maxBitrate"));
+ AddProperty( /* 6 */
+ new MP4Integer32Property("avgBitrate"));
+ AddProperty( /* 7 */
+ new MP4DescriptorProperty("decSpecificInfo",
+ MP4DecSpecificDescrTag, 0, Optional, OnlyOne));
+ AddProperty( /* 8 */
+ new MP4DescriptorProperty("profileLevelIndicationIndexDescr",
+ MP4ExtProfileLevelDescrTag, 0, Optional, Many));
+}
+
+void MP4DecConfigDescriptor::Generate()
+{
+ ((MP4BitfieldProperty*)m_pProperties[3])->SetValue(1);
+}
+
+MP4DecSpecificDescriptor::MP4DecSpecificDescriptor()
+ : MP4Descriptor(MP4DecSpecificDescrTag)
+{
+ AddProperty( /* 0 */
+ new MP4BytesProperty("info"));
+}
+
+void MP4DecSpecificDescriptor::Read(MP4File* pFile)
+{
+ ReadHeader(pFile);
+
+ /* byte properties need to know how long they are before reading */
+ ((MP4BytesProperty*)m_pProperties[0])->SetValueSize(m_size);
+
+ ReadProperties(pFile);
+}
+
+MP4SLConfigDescriptor::MP4SLConfigDescriptor()
+ : MP4Descriptor(MP4SLConfigDescrTag)
+{
+ AddProperty( /* 0 */
+ new MP4Integer8Property("predefined"));
+ AddProperty( /* 1 */
+ new MP4BitfieldProperty("useAccessUnitStartFlag", 1));
+ AddProperty( /* 2 */
+ new MP4BitfieldProperty("useAccessUnitEndFlag", 1));
+ AddProperty( /* 3 */
+ new MP4BitfieldProperty("useRandomAccessPointFlag", 1));
+ AddProperty( /* 4 */
+ new MP4BitfieldProperty("hasRandomAccessUnitsOnlyFlag", 1));
+ AddProperty( /* 5 */
+ new MP4BitfieldProperty("usePaddingFlag", 1));
+ AddProperty( /* 6 */
+ new MP4BitfieldProperty("useTimeStampsFlag", 1));
+ AddProperty( /* 7 */
+ new MP4BitfieldProperty("useIdleFlag", 1));
+ AddProperty( /* 8 */
+ new MP4BitfieldProperty("durationFlag", 1));
+ AddProperty( /* 9 */
+ new MP4Integer32Property("timeStampResolution"));
+ AddProperty( /* 10 */
+ new MP4Integer32Property("OCRResolution"));
+ AddProperty( /* 11 */
+ new MP4Integer8Property("timeStampLength"));
+ AddProperty( /* 12 */
+ new MP4Integer8Property("OCRLength"));
+ AddProperty( /* 13 */
+ new MP4Integer8Property("AULength"));
+ AddProperty( /* 14 */
+ new MP4Integer8Property("instantBitrateLength"));
+ AddProperty( /* 15 */
+ new MP4BitfieldProperty("degradationPriortyLength", 4));
+ AddProperty( /* 16 */
+ new MP4BitfieldProperty("AUSeqNumLength", 5));
+ AddProperty( /* 17 */
+ new MP4BitfieldProperty("packetSeqNumLength", 5));
+ AddProperty( /* 18 */
+ new MP4BitfieldProperty("reserved", 2));
+
+ // if durationFlag
+ AddProperty( /* 19 */
+ new MP4Integer32Property("timeScale"));
+ AddProperty( /* 20 */
+ new MP4Integer16Property("accessUnitDuration"));
+ AddProperty( /* 21 */
+ new MP4Integer16Property("compositionUnitDuration"));
+
+ // if !useTimeStampsFlag
+ AddProperty( /* 22 */
+ new MP4BitfieldProperty("startDecodingTimeStamp", 64));
+ AddProperty( /* 23 */
+ new MP4BitfieldProperty("startCompositionTimeStamp", 64));
+}
+
+void MP4SLConfigDescriptor::Generate()
+{
+ // by default all tracks in an mp4 file
+ // use predefined SLConfig descriptor == 2
+ ((MP4Integer8Property*)m_pProperties[0])->SetValue(2);
+
+ // which implies UseTimestampsFlag = 1
+ ((MP4BitfieldProperty*)m_pProperties[6])->SetValue(1);
+
+ // reserved = 3
+ ((MP4BitfieldProperty*)m_pProperties[18])->SetValue(3);
+}
+
+void MP4SLConfigDescriptor::Read(MP4File* pFile)
+{
+ ReadHeader(pFile);
+
+ // read the first property, 'predefined'
+ ReadProperties(pFile, 0, 1);
+
+ // if predefined == 0
+ if (((MP4Integer8Property*)m_pProperties[0])->GetValue() == 0) {
+
+ /* read the next 18 properties */
+ ReadProperties(pFile, 1, 18);
+ }
+
+ // now mutate
+ Mutate();
+
+ // and read the remaining properties
+ ReadProperties(pFile, 19);
+}
+
+void MP4SLConfigDescriptor::Mutate()
+{
+ u_int32_t i;
+ u_int8_t predefined =
+ ((MP4Integer8Property*)m_pProperties[0])->GetValue();
+
+ if (predefined) {
+ // properties 1-18 are implicit
+ for (i = 1; i < m_pProperties.Size(); i++) {
+ m_pProperties[i]->SetImplicit(true);
+ }
+
+ if (predefined == 1) {
+ // UseTimestampsFlag = 0
+ ((MP4BitfieldProperty*)m_pProperties[6])->SetValue(0);
+
+ // TimestampResolution = 1000
+ ((MP4Integer32Property*)m_pProperties[9])->SetValue(1000);
+
+ // TimeStampLength = 32
+ ((MP4Integer8Property*)m_pProperties[11])->SetValue(32);
+
+ } else if (predefined == 2) {
+ // UseTimestampsFlag = 1
+ ((MP4BitfieldProperty*)m_pProperties[6])->SetValue(1);
+ }
+ } else {
+#if 1
+ for (i = 1; i <= 18; i++) {
+ m_pProperties[i]->SetImplicit(false);
+ }
+ ((MP4BitfieldProperty*)m_pProperties[18])->SetValue(3);
+#endif
+ }
+
+ bool durationFlag =
+ ((MP4BitfieldProperty*)m_pProperties[8])->GetValue();
+
+ for (i = 19; i <= 21; i++) {
+ m_pProperties[i]->SetImplicit(!durationFlag);
+ }
+
+ bool useTimeStampsFlag =
+ ((MP4BitfieldProperty*)m_pProperties[6])->GetValue();
+
+ for (i = 22; i <= 23; i++) {
+ m_pProperties[i]->SetImplicit(useTimeStampsFlag);
+
+ u_int8_t timeStampLength = MIN(64,
+ ((MP4Integer8Property*)m_pProperties[11])->GetValue());
+
+ ((MP4BitfieldProperty*)m_pProperties[i])->SetNumBits(timeStampLength);
+
+ // handle a nonsensical situation gracefully
+ if (timeStampLength == 0) {
+ m_pProperties[i]->SetImplicit(true);
+ }
+ }
+}
+
+MP4IPIPtrDescriptor::MP4IPIPtrDescriptor()
+ : MP4Descriptor(MP4IPIPtrDescrTag)
+{
+ AddProperty( /* 0 */
+ new MP4Integer16Property("IPIESId"));
+}
+
+MP4ContentIdDescriptor::MP4ContentIdDescriptor()
+ : MP4Descriptor(MP4ContentIdDescrTag)
+{
+ AddProperty( /* 0 */
+ new MP4BitfieldProperty("compatibility", 2));
+ AddProperty( /* 1 */
+ new MP4BitfieldProperty("contentTypeFlag", 1));
+ AddProperty( /* 2 */
+ new MP4BitfieldProperty("contentIdFlag", 1));
+ AddProperty( /* 3 */
+ new MP4BitfieldProperty("protectedContent", 1));
+ AddProperty( /* 4 */
+ new MP4BitfieldProperty("reserved", 3));
+ AddProperty( /* 5 */
+ new MP4Integer8Property("contentType"));
+ AddProperty( /* 6 */
+ new MP4Integer8Property("contentIdType"));
+ AddProperty( /* 7 */
+ new MP4BytesProperty("contentId"));
+}
+
+void MP4ContentIdDescriptor::Read(MP4File* pFile)
+{
+ ReadHeader(pFile);
+
+ /* read the first property, 'compatiblity' */
+ ReadProperties(pFile, 0, 1);
+
+ /* if compatiblity != 0 */
+ if (((MP4Integer8Property*)m_pProperties[0])->GetValue() != 0) {
+ /* we don't understand it */
+ VERBOSE_READ(pFile->GetVerbosity(),
+ printf("incompatible content id descriptor\n"));
+ return;
+ }
+
+ /* read the next four properties */
+ ReadProperties(pFile, 1, 4);
+
+ /* which allows us to reconfigure ourselves */
+ Mutate();
+
+ /* read the remaining properties */
+ ReadProperties(pFile, 5);
+}
+
+void MP4ContentIdDescriptor::Mutate()
+{
+ bool contentTypeFlag = ((MP4BitfieldProperty*)m_pProperties[1])->GetValue();
+ m_pProperties[5]->SetImplicit(!contentTypeFlag);
+
+ bool contentIdFlag = ((MP4BitfieldProperty*)m_pProperties[2])->GetValue();
+ m_pProperties[6]->SetImplicit(!contentIdFlag);
+ m_pProperties[7]->SetImplicit(!contentIdFlag);
+}
+
+MP4SupplContentIdDescriptor::MP4SupplContentIdDescriptor()
+ : MP4Descriptor(MP4SupplContentIdDescrTag)
+{
+ AddProperty( /* 0 */
+ new MP4BytesProperty("languageCode", 3));
+ AddProperty( /* 1 */
+ new MP4StringProperty("title", Counted));
+ AddProperty( /* 2 */
+ new MP4StringProperty("value", Counted));
+}
+
+MP4IPMPPtrDescriptor::MP4IPMPPtrDescriptor()
+ : MP4Descriptor(MP4IPMPPtrDescrTag)
+{
+ AddProperty( /* 0 */
+ new MP4Integer8Property("IPMPDescriptorId"));
+}
+
+MP4IPMPDescriptor::MP4IPMPDescriptor()
+ : MP4Descriptor(MP4IPMPDescrTag)
+{
+ AddProperty( /* 0 */
+ new MP4Integer8Property("IPMPDescriptorId"));
+ AddProperty( /* 1 */
+ new MP4Integer16Property("IPMPSType"));
+ AddProperty( /* 2 */
+ new MP4BytesProperty("IPMPData"));
+ /* note: if IPMPSType == 0, IPMPData is an URL */
+}
+
+void MP4IPMPDescriptor::Read(MP4File* pFile)
+{
+ ReadHeader(pFile);
+
+ /* byte properties need to know how long they are before reading */
+ ((MP4BytesProperty*)m_pProperties[2])->SetValueSize(m_size - 3);
+
+ ReadProperties(pFile);
+}
+
+MP4RegistrationDescriptor::MP4RegistrationDescriptor()
+ : MP4Descriptor(MP4RegistrationDescrTag)
+{
+ AddProperty( /* 0 */
+ new MP4Integer32Property("formatIdentifier"));
+ AddProperty( /* 1 */
+ new MP4BytesProperty("additionalIdentificationInfo"));
+}
+
+void MP4RegistrationDescriptor::Read(MP4File* pFile)
+{
+ ReadHeader(pFile);
+
+ /* byte properties need to know how long they are before reading */
+ ((MP4BytesProperty*)m_pProperties[1])->SetValueSize(m_size - 4);
+
+ ReadProperties(pFile);
+}
+
+MP4ExtProfileLevelDescriptor::MP4ExtProfileLevelDescriptor()
+ : MP4Descriptor(MP4ExtProfileLevelDescrTag)
+{
+ AddProperty( /* 0 */
+ new MP4Integer8Property("profileLevelIndicationIndex"));
+ AddProperty( /* 1 */
+ new MP4Integer8Property("ODProfileLevelIndication"));
+ AddProperty( /* 2 */
+ new MP4Integer8Property("sceneProfileLevelIndication"));
+ AddProperty( /* 3 */
+ new MP4Integer8Property("audioProfileLevelIndication"));
+ AddProperty( /* 4 */
+ new MP4Integer8Property("visualProfileLevelIndication"));
+ AddProperty( /* 5 */
+ new MP4Integer8Property("graphicsProfileLevelIndication"));
+ AddProperty( /* 6 */
+ new MP4Integer8Property("MPEGJProfileLevelIndication"));
+}
+
+MP4ExtensionDescriptor::MP4ExtensionDescriptor()
+ : MP4Descriptor()
+{
+ AddProperty( /* 0 */
+ new MP4BytesProperty("data"));
+}
+
+void MP4ExtensionDescriptor::Read(MP4File* pFile)
+{
+ ReadHeader(pFile);
+
+ /* byte properties need to know how long they are before reading */
+ ((MP4BytesProperty*)m_pProperties[0])->SetValueSize(m_size);
+
+ ReadProperties(pFile);
+}
+
+MP4Descriptor* MP4DescriptorProperty::CreateDescriptor(u_int8_t tag)
+{
+ MP4Descriptor* pDescriptor = NULL;
+
+ switch (tag) {
+ case MP4ESDescrTag:
+ pDescriptor = new MP4ESDescriptor();
+ break;
+ case MP4DecConfigDescrTag:
+ pDescriptor = new MP4DecConfigDescriptor();
+ break;
+ case MP4DecSpecificDescrTag:
+ pDescriptor = new MP4DecSpecificDescriptor();
+ break;
+ case MP4SLConfigDescrTag:
+ pDescriptor = new MP4SLConfigDescriptor();
+ break;
+ case MP4ContentIdDescrTag:
+ pDescriptor = new MP4ContentIdDescriptor();
+ break;
+ case MP4SupplContentIdDescrTag:
+ pDescriptor = new MP4SupplContentIdDescriptor();
+ break;
+ case MP4IPIPtrDescrTag:
+ pDescriptor = new MP4IPIPtrDescriptor();
+ break;
+ case MP4IPMPPtrDescrTag:
+ pDescriptor = new MP4IPMPPtrDescriptor();
+ break;
+ case MP4IPMPDescrTag:
+ pDescriptor = new MP4IPMPDescriptor();
+ break;
+ case MP4QosDescrTag:
+ pDescriptor = new MP4QosDescriptor();
+ break;
+ case MP4RegistrationDescrTag:
+ pDescriptor = new MP4RegistrationDescriptor();
+ break;
+ case MP4ESIDIncDescrTag:
+ pDescriptor = new MP4ESIDIncDescriptor();
+ break;
+ case MP4ESIDRefDescrTag:
+ pDescriptor = new MP4ESIDRefDescriptor();
+ break;
+ case MP4IODescrTag:
+ case MP4FileIODescrTag:
+ pDescriptor = new MP4IODescriptor();
+ pDescriptor->SetTag(tag);
+ break;
+ case MP4ODescrTag:
+ case MP4FileODescrTag:
+ pDescriptor = new MP4ODescriptor();
+ pDescriptor->SetTag(tag);
+ break;
+ case MP4ExtProfileLevelDescrTag:
+ pDescriptor = new MP4ExtProfileLevelDescriptor();
+ break;
+ }
+
+ if (pDescriptor == NULL) {
+ if (tag >= MP4OCIDescrTagsStart && tag <= MP4OCIDescrTagsEnd) {
+ pDescriptor = CreateOCIDescriptor(tag);
+ }
+
+ if (tag >= MP4ExtDescrTagsStart && tag <= MP4ExtDescrTagsEnd) {
+ pDescriptor = new MP4ExtensionDescriptor();
+ pDescriptor->SetTag(tag);
+ }
+ }
+
+ return pDescriptor;
+}
+
--- /dev/null
+++ b/common/mp4v2/descriptors.h
@@ -1,0 +1,164 @@
+/*
+ * 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
+ */
+
+#ifndef __DESCRIPTORS_INCLUDED__
+#define __DESCRIPTORS_INCLUDED__
+
+const u_int8_t MP4ODescrTag = 0x01;
+const u_int8_t MP4IODescrTag = 0x02;
+const u_int8_t MP4ESDescrTag = 0x03;
+const u_int8_t MP4DecConfigDescrTag = 0x04;
+const u_int8_t MP4DecSpecificDescrTag = 0x05;
+const u_int8_t MP4SLConfigDescrTag = 0x06;
+const u_int8_t MP4ContentIdDescrTag = 0x07;
+const u_int8_t MP4SupplContentIdDescrTag = 0x08;
+const u_int8_t MP4IPIPtrDescrTag = 0x09;
+const u_int8_t MP4IPMPPtrDescrTag = 0x0A;
+const u_int8_t MP4IPMPDescrTag = 0x0B;
+const u_int8_t MP4RegistrationDescrTag = 0x0D;
+const u_int8_t MP4ESIDIncDescrTag = 0x0E;
+const u_int8_t MP4ESIDRefDescrTag = 0x0F;
+const u_int8_t MP4FileIODescrTag = 0x10;
+const u_int8_t MP4FileODescrTag = 0x11;
+const u_int8_t MP4ExtProfileLevelDescrTag = 0x13;
+const u_int8_t MP4ExtDescrTagsStart = 0x80;
+const u_int8_t MP4ExtDescrTagsEnd = 0xFE;
+
+class MP4IODescriptor : public MP4Descriptor {
+public:
+ MP4IODescriptor();
+ void Generate();
+protected:
+ void Mutate();
+};
+
+class MP4ODescriptor : public MP4Descriptor {
+public:
+ MP4ODescriptor();
+ void Generate();
+protected:
+ void Mutate();
+};
+
+class MP4ESIDIncDescriptor : public MP4Descriptor {
+public:
+ MP4ESIDIncDescriptor();
+};
+
+class MP4ESIDRefDescriptor : public MP4Descriptor {
+public:
+ MP4ESIDRefDescriptor();
+};
+
+class MP4ESDescriptor : public MP4Descriptor {
+public:
+ MP4ESDescriptor();
+protected:
+ void Mutate();
+};
+
+class MP4DecConfigDescriptor : public MP4Descriptor {
+public:
+ MP4DecConfigDescriptor();
+ void Generate();
+};
+
+class MP4DecSpecificDescriptor : public MP4Descriptor {
+public:
+ MP4DecSpecificDescriptor();
+ void Read(MP4File* pFile);
+};
+
+class MP4SLConfigDescriptor : public MP4Descriptor {
+public:
+ MP4SLConfigDescriptor();
+ void Generate();
+ void Read(MP4File* pFile);
+ protected:
+ void Mutate();
+};
+
+class MP4IPIPtrDescriptor : public MP4Descriptor {
+public:
+ MP4IPIPtrDescriptor();
+};
+
+class MP4ContentIdDescriptor : public MP4Descriptor {
+public:
+ MP4ContentIdDescriptor();
+ void Read(MP4File* pFile);
+protected:
+ void Mutate();
+};
+
+class MP4SupplContentIdDescriptor : public MP4Descriptor {
+public:
+ MP4SupplContentIdDescriptor();
+};
+
+class MP4IPMPPtrDescriptor : public MP4Descriptor {
+public:
+ MP4IPMPPtrDescriptor();
+};
+
+class MP4IPMPDescriptor : public MP4Descriptor {
+public:
+ MP4IPMPDescriptor();
+ void Read(MP4File* pFile);
+};
+
+class MP4RegistrationDescriptor : public MP4Descriptor {
+public:
+ MP4RegistrationDescriptor();
+ void Read(MP4File* pFile);
+};
+
+class MP4ExtProfileLevelDescriptor : public MP4Descriptor {
+public:
+ MP4ExtProfileLevelDescriptor();
+};
+
+class MP4ExtensionDescriptor : public MP4Descriptor {
+public:
+ MP4ExtensionDescriptor();
+ void Read(MP4File* pFile);
+};
+
+// associated values in descriptors
+
+// ES objectTypeId
+const u_int8_t MP4SystemsV1ObjectType = 0x01;
+const u_int8_t MP4SystemsV2ObjectType = 0x02;
+
+// ES streamType
+const u_int8_t MP4ObjectDescriptionStreamType = 0x01;
+const u_int8_t MP4ClockReferenceStreamType = 0x02;
+const u_int8_t MP4SceneDescriptionStreamType = 0x03;
+const u_int8_t MP4VisualStreamType = 0x04;
+const u_int8_t MP4AudioStreamType = 0x05;
+const u_int8_t MP4Mpeg7StreamType = 0x06;
+const u_int8_t MP4IPMPStreamType = 0x07;
+const u_int8_t MP4OCIStreamType = 0x08;
+const u_int8_t MP4MPEGJStreamType = 0x09;
+const u_int8_t MP4UserPrivateStreamType = 0x20;
+
+#endif /* __DESCRIPTORS_INCLUDED__ */
+
--- /dev/null
+++ b/common/mp4v2/isma.cpp
@@ -1,0 +1,904 @@
+/*
+ * 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 - 2004. All Rights Reserved.
+ *
+ * 3GPP features implementation is based on 3GPP's TS26.234-v5.60,
+ * and was contributed by Ximpo Group Ltd.
+ *
+ * Portions created by Ximpo Group Ltd. are
+ * Copyright (C) Ximpo Group Ltd. 2003, 2004. All Rights Reserved.
+ *
+ * Contributor(s):
+ * Dave Mackie dmackie@cisco.com
+ * Alix Marchandise-Franquet alix@cisco.com
+ * Ximpo Group Ltd. mp4v2@ximpo.com
+ */
+
+#include "mp4common.h"
+
+static u_int8_t BifsV2Config[3] = {
+ 0x00, 0x00, 0x60 // IsCommandStream = 1, PixelMetric = 1
+};
+
+void MP4File::MakeIsmaCompliant(bool addIsmaComplianceSdp)
+{
+ ProtectWriteOperation("MP4MakeIsmaCompliant");
+
+ if (m_useIsma) {
+ // already done
+ return;
+ }
+
+ // find first audio and/or video tracks
+
+ MP4TrackId audioTrackId = MP4_INVALID_TRACK_ID;
+ try {
+ audioTrackId = FindTrackId(0, MP4_AUDIO_TRACK_TYPE);
+ }
+ catch (MP4Error* e) {
+ delete e;
+ }
+
+ MP4TrackId videoTrackId = MP4_INVALID_TRACK_ID;
+ try {
+ videoTrackId = FindTrackId(0, MP4_VIDEO_TRACK_TYPE);
+ }
+ catch (MP4Error* e) {
+ delete e;
+ }
+ // Check whether it's an AMR-NB or AMR-WB trak
+ if ((MP4HaveTrackIntegerProperty(this, audioTrackId, "mdia.minf.stbl.stsd.sawb.damr.vendor")) ||
+ (MP4HaveTrackIntegerProperty(this, audioTrackId, "mdia.minf.stbl.stsd.samr.damr.vendor"))) {
+ throw new MP4Error("can't make ISMA compliant when file contains an AMR track", "MakeIsmaCompliant");
+ }
+ //
+ // Check whether it's an H.263 file
+ if (MP4HaveTrackIntegerProperty(this, videoTrackId, "mdia.minf.stbl.stsd.s263.d263.vendor")) {
+ throw new MP4Error("can't make ISMA compliant when file contains an H.263 track", "MakeIsmaCompliant");
+ }
+
+ m_useIsma = true;
+
+ u_int64_t fileMsDuration =
+ ConvertFromMovieDuration(GetDuration(), MP4_MSECS_TIME_SCALE);
+
+ // delete any existing OD track
+ if (m_odTrackId != MP4_INVALID_TRACK_ID) {
+ DeleteTrack(m_odTrackId);
+ }
+
+ AddODTrack();
+ SetODProfileLevel(0xFF);
+
+ if (audioTrackId != MP4_INVALID_TRACK_ID) {
+ AddTrackToOd(audioTrackId);
+ }
+
+ if (videoTrackId != MP4_INVALID_TRACK_ID) {
+ AddTrackToOd(videoTrackId);
+ }
+
+ // delete any existing scene track
+ MP4TrackId sceneTrackId = MP4_INVALID_TRACK_ID;
+ try {
+ sceneTrackId = FindTrackId(0, MP4_SCENE_TRACK_TYPE);
+ }
+ catch (MP4Error *e) {
+ delete e;
+ }
+ if (sceneTrackId != MP4_INVALID_TRACK_ID) {
+ DeleteTrack(sceneTrackId);
+ }
+
+ // add scene track
+ sceneTrackId = AddSceneTrack();
+ SetSceneProfileLevel(0xFF);
+ SetGraphicsProfileLevel(0xFF);
+ SetTrackIntegerProperty(sceneTrackId,
+ "mdia.minf.stbl.stsd.mp4s.esds.decConfigDescr.objectTypeId",
+ MP4SystemsV2ObjectType);
+
+ SetTrackESConfiguration(sceneTrackId,
+ BifsV2Config, sizeof(BifsV2Config));
+
+ u_int8_t* pBytes = NULL;
+ u_int64_t numBytes = 0;
+
+ // write OD Update Command
+ CreateIsmaODUpdateCommandFromFileForFile(
+ m_odTrackId,
+ audioTrackId,
+ videoTrackId,
+ &pBytes,
+ &numBytes);
+
+ WriteSample(m_odTrackId, pBytes, numBytes, fileMsDuration);
+
+ MP4Free(pBytes);
+ pBytes = NULL;
+
+ // write BIFS Scene Replace Command
+ CreateIsmaSceneCommand(
+ MP4_IS_VALID_TRACK_ID(audioTrackId),
+ MP4_IS_VALID_TRACK_ID(videoTrackId),
+ &pBytes,
+ &numBytes);
+
+ WriteSample(sceneTrackId, pBytes, numBytes, fileMsDuration);
+
+ MP4Free(pBytes);
+ pBytes = NULL;
+
+ // add session level sdp
+ CreateIsmaIodFromFile(
+ m_odTrackId,
+ sceneTrackId,
+ audioTrackId,
+ videoTrackId,
+ &pBytes,
+ &numBytes);
+
+ char* iodBase64 = MP4ToBase64(pBytes, numBytes);
+
+ char* sdpBuf = (char*)MP4Calloc(strlen(iodBase64) + 256);
+
+ if (addIsmaComplianceSdp) {
+ strcpy(sdpBuf, "a=isma-compliance:1,1.0,1\015\012");
+ }
+
+ sprintf(&sdpBuf[strlen(sdpBuf)],
+ "a=mpeg4-iod: \042data:application/mpeg4-iod;base64,%s\042\015\012",
+ iodBase64);
+
+ SetSessionSdp(sdpBuf);
+
+ VERBOSE_ISMA(GetVerbosity(),
+ printf("IOD SDP = %s\n", sdpBuf));
+
+ MP4Free(iodBase64);
+ iodBase64 = NULL;
+ MP4Free(pBytes);
+ pBytes = NULL;
+ MP4Free(sdpBuf);
+ sdpBuf = NULL;
+}
+
+static void CloneIntegerProperty(
+ MP4Descriptor* pDest,
+ MP4DescriptorProperty* pSrc,
+ const char* name)
+{
+ MP4IntegerProperty* pGetProperty;
+ MP4IntegerProperty* pSetProperty;
+
+ pSrc->FindProperty(name, (MP4Property**)&pGetProperty);
+ pDest->FindProperty(name, (MP4Property**)&pSetProperty);
+
+ pSetProperty->SetValue(pGetProperty->GetValue());
+}
+
+void MP4File::CreateIsmaIodFromFile(
+ MP4TrackId odTrackId,
+ MP4TrackId sceneTrackId,
+ MP4TrackId audioTrackId,
+ MP4TrackId videoTrackId,
+ u_int8_t** ppBytes,
+ u_int64_t* pNumBytes)
+{
+ MP4Descriptor* pIod = new MP4IODescriptor();
+ pIod->SetTag(MP4IODescrTag);
+ pIod->Generate();
+
+ MP4Atom* pIodsAtom = FindAtom("moov.iods");
+ ASSERT(pIodsAtom);
+ MP4DescriptorProperty* pSrcIod =
+ (MP4DescriptorProperty*)pIodsAtom->GetProperty(2);
+
+ CloneIntegerProperty(pIod, pSrcIod, "objectDescriptorId");
+ CloneIntegerProperty(pIod, pSrcIod, "ODProfileLevelId");
+ CloneIntegerProperty(pIod, pSrcIod, "sceneProfileLevelId");
+ CloneIntegerProperty(pIod, pSrcIod, "audioProfileLevelId");
+ CloneIntegerProperty(pIod, pSrcIod, "visualProfileLevelId");
+ CloneIntegerProperty(pIod, pSrcIod, "graphicsProfileLevelId");
+
+ // mutate esIds from MP4ESIDIncDescrTag to MP4ESDescrTag
+ MP4DescriptorProperty* pEsProperty;
+ pIod->FindProperty("esIds", (MP4Property**)&pEsProperty);
+ pEsProperty->SetTags(MP4ESDescrTag);
+
+ MP4IntegerProperty* pSetProperty;
+ MP4IntegerProperty* pSceneESID;
+ MP4IntegerProperty* pOdESID;
+
+ // OD
+ MP4Descriptor* pOdEsd =
+ pEsProperty->AddDescriptor(MP4ESDescrTag);
+ pOdEsd->Generate();
+
+ pOdEsd->FindProperty("ESID",
+ (MP4Property**)&pOdESID);
+
+ // we set the OD ESID to a non-zero unique value
+ pOdESID->SetValue(m_odTrackId);
+
+ pOdEsd->FindProperty("URLFlag",
+ (MP4Property**)&pSetProperty);
+ pSetProperty->SetValue(1);
+
+ u_int8_t* pBytes;
+ u_int64_t numBytes;
+
+ CreateIsmaODUpdateCommandFromFileForStream(
+ audioTrackId,
+ videoTrackId,
+ &pBytes,
+ &numBytes);
+
+ VERBOSE_ISMA(GetVerbosity(),
+ printf("OD data =\n"); MP4HexDump(pBytes, numBytes));
+
+ char* odCmdBase64 = MP4ToBase64(pBytes, numBytes);
+
+ char* urlBuf = (char*)MP4Malloc(strlen(odCmdBase64) + 64);
+
+ sprintf(urlBuf,
+ "data:application/mpeg4-od-au;base64,%s",
+ odCmdBase64);
+
+ MP4StringProperty* pUrlProperty;
+ pOdEsd->FindProperty("URL",
+ (MP4Property**)&pUrlProperty);
+ pUrlProperty->SetValue(urlBuf);
+
+ VERBOSE_ISMA(GetVerbosity(),
+ printf("OD data URL = \042%s\042\n", urlBuf));
+
+ MP4Free(odCmdBase64);
+ odCmdBase64 = NULL;
+ MP4Free(pBytes);
+ pBytes = NULL;
+ MP4Free(urlBuf);
+ urlBuf = NULL;
+
+ MP4DescriptorProperty* pSrcDcd = NULL;
+
+ // HACK temporarily point to scene decoder config
+ FindProperty(MakeTrackName(odTrackId,
+ "mdia.minf.stbl.stsd.mp4s.esds.decConfigDescr"),
+ (MP4Property**)&pSrcDcd);
+ ASSERT(pSrcDcd);
+ MP4Property* pOrgOdEsdProperty =
+ pOdEsd->GetProperty(8);
+ pOdEsd->SetProperty(8, pSrcDcd);
+
+ // bufferSizeDB needs to be set appropriately
+ MP4BitfieldProperty* pBufferSizeProperty = NULL;
+ pOdEsd->FindProperty("decConfigDescr.bufferSizeDB",
+ (MP4Property**)&pBufferSizeProperty);
+ ASSERT(pBufferSizeProperty);
+ pBufferSizeProperty->SetValue(numBytes);
+
+ // SL config needs to change from 2 (file) to 1 (null)
+ pOdEsd->FindProperty("slConfigDescr.predefined",
+ (MP4Property**)&pSetProperty);
+ pSetProperty->SetValue(1);
+
+
+ // Scene
+ MP4Descriptor* pSceneEsd =
+ pEsProperty->AddDescriptor(MP4ESDescrTag);
+ pSceneEsd->Generate();
+
+ pSceneEsd->FindProperty("ESID",
+ (MP4Property**)&pSceneESID);
+ // we set the Scene ESID to a non-zero unique value
+ pSceneESID->SetValue(sceneTrackId);
+
+ pSceneEsd->FindProperty("URLFlag",
+ (MP4Property**)&pSetProperty);
+ pSetProperty->SetValue(1);
+
+ CreateIsmaSceneCommand(
+ MP4_IS_VALID_TRACK_ID(audioTrackId),
+ MP4_IS_VALID_TRACK_ID(videoTrackId),
+ &pBytes,
+ &numBytes);
+
+ VERBOSE_ISMA(GetVerbosity(),
+ printf("Scene data =\n"); MP4HexDump(pBytes, numBytes));
+
+ char *sceneCmdBase64 = MP4ToBase64(pBytes, numBytes);
+
+ urlBuf = (char*)MP4Malloc(strlen(sceneCmdBase64) + 64);
+ sprintf(urlBuf,
+ "data:application/mpeg4-bifs-au;base64,%s",
+ sceneCmdBase64);
+
+ pSceneEsd->FindProperty("URL",
+ (MP4Property**)&pUrlProperty);
+ pUrlProperty->SetValue(urlBuf);
+
+ VERBOSE_ISMA(GetVerbosity(),
+ printf("Scene data URL = \042%s\042\n", urlBuf));
+
+ MP4Free(sceneCmdBase64);
+ sceneCmdBase64 = NULL;
+ MP4Free(urlBuf);
+ urlBuf = NULL;
+ MP4Free(pBytes);
+ pBytes = NULL;
+
+ // HACK temporarily point to scene decoder config
+ FindProperty(MakeTrackName(sceneTrackId,
+ "mdia.minf.stbl.stsd.mp4s.esds.decConfigDescr"),
+ (MP4Property**)&pSrcDcd);
+ ASSERT(pSrcDcd);
+ MP4Property* pOrgSceneEsdProperty =
+ pSceneEsd->GetProperty(8);
+ pSceneEsd->SetProperty(8, pSrcDcd);
+
+ // bufferSizeDB needs to be set
+ pBufferSizeProperty = NULL;
+ pSceneEsd->FindProperty("decConfigDescr.bufferSizeDB",
+ (MP4Property**)&pBufferSizeProperty);
+ ASSERT(pBufferSizeProperty);
+ pBufferSizeProperty->SetValue(numBytes);
+
+ // SL config needs to change from 2 (file) to 1 (null)
+ pSceneEsd->FindProperty("slConfigDescr.predefined",
+ (MP4Property**)&pSetProperty);
+ pSetProperty->SetValue(1);
+
+
+ // finally get the whole thing written to a memory
+ pIod->WriteToMemory(this, ppBytes, pNumBytes);
+
+
+ // now carefully replace esd properties before destroying
+ pOdEsd->SetProperty(8, pOrgOdEsdProperty);
+ pSceneEsd->SetProperty(8, pOrgSceneEsdProperty);
+ pSceneESID->SetValue(0); // restore 0 value
+ pOdESID->SetValue(0);
+
+ delete pIod;
+
+ VERBOSE_ISMA(GetVerbosity(),
+ printf("IOD data =\n"); MP4HexDump(*ppBytes, *pNumBytes));
+}
+
+void MP4File::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** ppIodBytes,
+ u_int64_t* pIodNumBytes)
+{
+ MP4IntegerProperty* pInt;
+ u_int8_t* pBytes = NULL;
+ u_int64_t numBytes;
+
+ // Create the IOD
+ MP4Descriptor* pIod = new MP4IODescriptor();
+ pIod->SetTag(MP4IODescrTag);
+ pIod->Generate();
+
+ // Set audio and video profileLevels
+ pIod->FindProperty("audioProfileLevelId",
+ (MP4Property**)&pInt);
+ pInt->SetValue(audioProfile);
+
+ pIod->FindProperty("visualProfileLevelId",
+ (MP4Property**)&pInt);
+ pInt->SetValue(videoProfile);
+
+ // Mutate esIds from MP4ESIDIncDescrTag to MP4ESDescrTag
+ MP4DescriptorProperty* pEsProperty;
+ pIod->FindProperty("esIds", (MP4Property**)&pEsProperty);
+ pEsProperty->SetTags(MP4ESDescrTag);
+
+ // Add ES Descriptors
+
+ // Scene
+ CreateIsmaSceneCommand(
+ (audioProfile != 0xFF),
+ (videoProfile != 0xFF),
+ &pBytes,
+ &numBytes);
+
+ VERBOSE_ISMA(GetVerbosity(),
+ printf("Scene data =\n"); MP4HexDump(pBytes, numBytes));
+
+ char* sceneCmdBase64 = MP4ToBase64(pBytes, numBytes);
+
+ char* urlBuf =
+ (char*)MP4Malloc(strlen(sceneCmdBase64) + 64);
+ sprintf(urlBuf,
+ "data:application/mpeg4-bifs-au;base64,%s",
+ sceneCmdBase64);
+
+ VERBOSE_ISMA(GetVerbosity(),
+ printf("Scene data URL = \042%s\042\n", urlBuf));
+
+ /* MP4Descriptor* pSceneEsd = */
+ CreateESD(
+ pEsProperty,
+ 201, // esid
+ MP4SystemsV2ObjectType,
+ MP4SceneDescriptionStreamType,
+ numBytes, // bufferSize
+ numBytes * 8, // bitrate
+ BifsV2Config,
+ sizeof(BifsV2Config),
+ urlBuf);
+
+ MP4Free(sceneCmdBase64);
+ sceneCmdBase64 = NULL;
+ MP4Free(urlBuf);
+ urlBuf = NULL;
+ MP4Free(pBytes);
+ pBytes = NULL;
+
+ // OD
+
+ // Video
+ MP4DescriptorProperty* pVideoEsdProperty =
+ new MP4DescriptorProperty();
+ pVideoEsdProperty->SetTags(MP4ESDescrTag);
+
+ /* MP4Descriptor* pVideoEsd = */
+ CreateESD(
+ pVideoEsdProperty,
+ 20, // esid
+ MP4_MPEG4_VIDEO_TYPE,
+ MP4VisualStreamType,
+ videoBitrate / 8, // bufferSize
+ videoBitrate,
+ videoConfig,
+ videoConfigLength,
+ NULL);
+
+ // Audio
+ MP4DescriptorProperty* pAudioEsdProperty =
+ new MP4DescriptorProperty();
+ pAudioEsdProperty->SetTags(MP4ESDescrTag);
+
+ /* MP4Descriptor* pAudioEsd = */
+ CreateESD(
+ pAudioEsdProperty,
+ 10, // esid
+ MP4_MPEG4_AUDIO_TYPE,
+ MP4AudioStreamType,
+ audioBitrate / 8, // bufferSize
+ audioBitrate,
+ audioConfig,
+ audioConfigLength,
+ NULL);
+
+ CreateIsmaODUpdateCommandForStream(
+ pAudioEsdProperty,
+ pVideoEsdProperty,
+ &pBytes,
+ &numBytes);
+
+ // cleanup temporary descriptor properties
+ delete pAudioEsdProperty;
+ delete pVideoEsdProperty;
+
+ VERBOSE_ISMA(GetVerbosity(),
+ printf("OD data = "U64" bytes\n", numBytes); MP4HexDump(pBytes, numBytes));
+
+ char* odCmdBase64 = MP4ToBase64(pBytes, numBytes);
+
+ urlBuf = (char*)MP4Malloc(strlen(odCmdBase64) + 64);
+
+ sprintf(urlBuf,
+ "data:application/mpeg4-od-au;base64,%s",
+ odCmdBase64);
+
+ VERBOSE_ISMA(GetVerbosity(),
+ printf("OD data URL = \042%s\042\n", urlBuf));
+
+ /* MP4Descriptor* pOdEsd = */
+ CreateESD(
+ pEsProperty,
+ 101,
+ MP4SystemsV1ObjectType,
+ MP4ObjectDescriptionStreamType,
+ numBytes, // bufferSize
+ numBytes * 8, // bitrate
+ NULL, // config
+ 0, // configLength
+ urlBuf);
+
+ MP4Free(odCmdBase64);
+ odCmdBase64 = NULL;
+ MP4Free(pBytes);
+ pBytes = NULL;
+ MP4Free(urlBuf);
+ urlBuf = NULL;
+
+ // finally get the whole thing written to a memory
+ pIod->WriteToMemory(this, ppIodBytes, pIodNumBytes);
+
+ delete pIod;
+
+ VERBOSE_ISMA(GetVerbosity(),
+ printf("IOD data =\n"); MP4HexDump(*ppIodBytes, *pIodNumBytes));
+}
+
+MP4Descriptor* MP4File::CreateESD(
+ MP4DescriptorProperty* pEsProperty,
+ u_int32_t esid,
+ u_int8_t objectType,
+ u_int8_t streamType,
+ u_int32_t bufferSize,
+ u_int32_t bitrate,
+ u_int8_t* pConfig,
+ u_int32_t configLength,
+ char* url)
+{
+ MP4IntegerProperty* pInt;
+ MP4StringProperty* pString;
+ MP4BytesProperty* pBytes;
+ MP4BitfieldProperty* pBits;
+
+ MP4Descriptor* pEsd =
+ pEsProperty->AddDescriptor(MP4ESDescrTag);
+ pEsd->Generate();
+
+ pEsd->FindProperty("ESID",
+ (MP4Property**)&pInt);
+ pInt->SetValue(esid);
+
+ pEsd->FindProperty("decConfigDescr.objectTypeId",
+ (MP4Property**)&pInt);
+ pInt->SetValue(objectType);
+
+ pEsd->FindProperty("decConfigDescr.streamType",
+ (MP4Property**)&pInt);
+ pInt->SetValue(streamType);
+
+ pEsd->FindProperty("decConfigDescr.bufferSizeDB",
+ (MP4Property**)&pInt);
+ pInt->SetValue(bufferSize);
+
+ pEsd->FindProperty("decConfigDescr.maxBitrate",
+ (MP4Property**)&pInt);
+ pInt->SetValue(bitrate);
+
+ pEsd->FindProperty("decConfigDescr.avgBitrate",
+ (MP4Property**)&pInt);
+ pInt->SetValue(bitrate);
+
+ MP4DescriptorProperty* pConfigDescrProperty;
+ pEsd->FindProperty("decConfigDescr.decSpecificInfo",
+ (MP4Property**)&pConfigDescrProperty);
+
+ MP4Descriptor* pConfigDescr =
+ pConfigDescrProperty->AddDescriptor(MP4DecSpecificDescrTag);
+ pConfigDescr->Generate();
+
+ pConfigDescrProperty->FindProperty("decSpecificInfo[0].info",
+ (MP4Property**)&pBytes);
+ pBytes->SetValue(pConfig, configLength);
+
+ pEsd->FindProperty("slConfigDescr.predefined",
+ (MP4Property**)&pInt);
+ // changed 12/5/02 from plugfest to value 0
+ pInt->SetValue(0);
+
+ pEsd->FindProperty("slConfig.useAccessUnitEndFlag",
+ (MP4Property **)&pBits);
+ pBits->SetValue(1);
+
+ if (url) {
+ pEsd->FindProperty("URLFlag",
+ (MP4Property**)&pInt);
+ pInt->SetValue(1);
+
+ pEsd->FindProperty("URL",
+ (MP4Property**)&pString);
+ pString->SetValue(url);
+ }
+
+ return pEsd;
+}
+
+void MP4File::CreateIsmaODUpdateCommandFromFileForFile(
+ MP4TrackId odTrackId,
+ MP4TrackId audioTrackId,
+ MP4TrackId videoTrackId,
+ u_int8_t** ppBytes,
+ u_int64_t* pNumBytes)
+{
+ MP4Descriptor* pCommand = CreateODCommand(MP4ODUpdateODCommandTag);
+ pCommand->Generate();
+
+ for (u_int8_t i = 0; i < 2; i++) {
+ MP4TrackId trackId;
+ u_int16_t odId;
+
+ if (i == 0) {
+ trackId = audioTrackId;
+ odId = 10;
+ } else {
+ trackId = videoTrackId;
+ odId = 20;
+ }
+
+ if (trackId == MP4_INVALID_TRACK_ID) {
+ continue;
+ }
+
+ MP4DescriptorProperty* pOdDescrProperty =
+ (MP4DescriptorProperty*)(pCommand->GetProperty(0));
+
+ pOdDescrProperty->SetTags(MP4FileODescrTag);
+
+ MP4Descriptor* pOd =
+ pOdDescrProperty->AddDescriptor(MP4FileODescrTag);
+
+ pOd->Generate();
+
+ MP4BitfieldProperty* pOdIdProperty = NULL;
+ pOd->FindProperty("objectDescriptorId",
+ (MP4Property**)&pOdIdProperty);
+ pOdIdProperty->SetValue(odId);
+
+ MP4DescriptorProperty* pEsIdsDescriptorProperty = NULL;
+ pOd->FindProperty("esIds",
+ (MP4Property**)&pEsIdsDescriptorProperty);
+ ASSERT(pEsIdsDescriptorProperty);
+
+ pEsIdsDescriptorProperty->SetTags(MP4ESIDRefDescrTag);
+
+ MP4Descriptor *pRefDescriptor =
+ pEsIdsDescriptorProperty->AddDescriptor(MP4ESIDRefDescrTag);
+ pRefDescriptor->Generate();
+
+ MP4Integer16Property* pRefIndexProperty = NULL;
+ pRefDescriptor->FindProperty("refIndex",
+ (MP4Property**)&pRefIndexProperty);
+ ASSERT(pRefIndexProperty);
+
+ u_int32_t mpodIndex = FindTrackReference(
+ MakeTrackName(odTrackId, "tref.mpod"), trackId);
+ ASSERT(mpodIndex != 0);
+
+ pRefIndexProperty->SetValue(mpodIndex);
+ }
+
+ pCommand->WriteToMemory(this, ppBytes, pNumBytes);
+
+ delete pCommand;
+}
+
+void MP4File::CreateIsmaODUpdateCommandFromFileForStream(
+ MP4TrackId audioTrackId,
+ MP4TrackId videoTrackId,
+ u_int8_t** ppBytes,
+ u_int64_t* pNumBytes)
+{
+ MP4DescriptorProperty* pAudioEsd = NULL;
+ MP4Integer8Property* pAudioSLConfigPredef = NULL;
+ MP4BitfieldProperty* pAudioAccessUnitEndFlag = NULL;
+ int oldAudioUnitEndFlagValue = 0;
+ MP4DescriptorProperty* pVideoEsd = NULL;
+ MP4Integer8Property* pVideoSLConfigPredef = NULL;
+ MP4BitfieldProperty* pVideoAccessUnitEndFlag = NULL;
+ int oldVideoUnitEndFlagValue = 0;
+ MP4IntegerProperty* pAudioEsdId = NULL;
+ MP4IntegerProperty* pVideoEsdId = NULL;
+
+ if (audioTrackId != MP4_INVALID_TRACK_ID) {
+ // changed mp4a to * to handle enca case
+ MP4Atom* pEsdsAtom =
+ FindAtom(MakeTrackName(audioTrackId,
+ "mdia.minf.stbl.stsd.*.esds"));
+ ASSERT(pEsdsAtom);
+
+ pAudioEsd = (MP4DescriptorProperty*)(pEsdsAtom->GetProperty(2));
+ // ESID is 0 for file, stream needs to be non-ze
+ pAudioEsd->FindProperty("ESID",
+ (MP4Property**)&pAudioEsdId);
+
+ ASSERT(pAudioEsdId);
+ pAudioEsdId->SetValue(audioTrackId);
+
+ // SL config needs to change from 2 (file) to 1 (null)
+ pAudioEsd->FindProperty("slConfigDescr.predefined",
+ (MP4Property**)&pAudioSLConfigPredef);
+ ASSERT(pAudioSLConfigPredef);
+ pAudioSLConfigPredef->SetValue(0);
+
+ pAudioEsd->FindProperty("slConfigDescr.useAccessUnitEndFlag",
+ (MP4Property **)&pAudioAccessUnitEndFlag);
+ oldAudioUnitEndFlagValue =
+ pAudioAccessUnitEndFlag->GetValue();
+ pAudioAccessUnitEndFlag->SetValue(1);
+ }
+
+ if (videoTrackId != MP4_INVALID_TRACK_ID) {
+ // changed mp4v to * to handle encv case
+ MP4Atom* pEsdsAtom =
+ FindAtom(MakeTrackName(videoTrackId,
+ "mdia.minf.stbl.stsd.*.esds"));
+ ASSERT(pEsdsAtom);
+
+ pVideoEsd = (MP4DescriptorProperty*)(pEsdsAtom->GetProperty(2));
+ pVideoEsd->FindProperty("ESID",
+ (MP4Property**)&pVideoEsdId);
+
+ ASSERT(pVideoEsdId);
+ pVideoEsdId->SetValue(videoTrackId);
+
+ // SL config needs to change from 2 (file) to 1 (null)
+ pVideoEsd->FindProperty("slConfigDescr.predefined",
+ (MP4Property**)&pVideoSLConfigPredef);
+ ASSERT(pVideoSLConfigPredef);
+ pVideoSLConfigPredef->SetValue(0);
+
+ pVideoEsd->FindProperty("slConfigDescr.useAccessUnitEndFlag",
+ (MP4Property **)&pVideoAccessUnitEndFlag);
+ oldVideoUnitEndFlagValue =
+ pVideoAccessUnitEndFlag->GetValue();
+ pVideoAccessUnitEndFlag->SetValue(1);
+ }
+
+ CreateIsmaODUpdateCommandForStream(
+ pAudioEsd, pVideoEsd, ppBytes, pNumBytes);
+ VERBOSE_ISMA(GetVerbosity(),
+ printf("After CreateImsaODUpdateCommandForStream len "U64" =\n", *pNumBytes); MP4HexDump(*ppBytes, *pNumBytes));
+ // return SL config values to 2 (file)
+ // return ESID values to 0
+ if (pAudioSLConfigPredef) {
+ pAudioSLConfigPredef->SetValue(2);
+ }
+ if (pAudioEsdId) {
+ pAudioEsdId->SetValue(0);
+ }
+ if (pAudioAccessUnitEndFlag) {
+ pAudioAccessUnitEndFlag->SetValue(oldAudioUnitEndFlagValue );
+ }
+ if (pVideoEsdId) {
+ pVideoEsdId->SetValue(0);
+ }
+ if (pVideoSLConfigPredef) {
+ pVideoSLConfigPredef->SetValue(2);
+ }
+ if (pVideoAccessUnitEndFlag) {
+ pVideoAccessUnitEndFlag->SetValue(oldVideoUnitEndFlagValue );
+ }
+}
+
+void MP4File::CreateIsmaODUpdateCommandForStream(
+ MP4DescriptorProperty* pAudioEsdProperty,
+ MP4DescriptorProperty* pVideoEsdProperty,
+ u_int8_t** ppBytes,
+ u_int64_t* pNumBytes)
+{
+ MP4Descriptor* pAudioOd = NULL;
+ MP4Descriptor* pVideoOd = NULL;
+
+ MP4Descriptor* pCommand =
+ CreateODCommand(MP4ODUpdateODCommandTag);
+ pCommand->Generate();
+
+ for (u_int8_t i = 0; i < 2; i++) {
+ u_int16_t odId;
+ MP4DescriptorProperty* pEsdProperty = NULL;
+
+ if (i == 0) {
+ odId = 10;
+ pEsdProperty = pAudioEsdProperty;
+ } else {
+ odId = 20;
+ pEsdProperty = pVideoEsdProperty;
+ }
+
+ if (pEsdProperty == NULL) {
+ continue;
+ }
+
+ MP4DescriptorProperty* pOdDescrProperty =
+ (MP4DescriptorProperty*)(pCommand->GetProperty(0));
+
+ pOdDescrProperty->SetTags(MP4ODescrTag);
+
+ MP4Descriptor* pOd =
+ pOdDescrProperty->AddDescriptor(MP4ODescrTag);
+ pOd->Generate();
+
+ if (i == 0) {
+ pAudioOd = pOd;
+ } else {
+ pVideoOd = pOd;
+ }
+
+ MP4BitfieldProperty* pOdIdProperty = NULL;
+ pOd->FindProperty("objectDescriptorId",
+ (MP4Property**)&pOdIdProperty);
+ pOdIdProperty->SetValue(odId);
+
+ delete (MP4DescriptorProperty*)pOd->GetProperty(4);
+ pOd->SetProperty(4, pEsdProperty);
+ }
+
+ // serialize OD command
+ pCommand->WriteToMemory(this, ppBytes, pNumBytes);
+
+ // detach from esd descriptor params
+ if (pAudioOd) {
+ pAudioOd->SetProperty(4, NULL);
+ }
+ if (pVideoOd) {
+ pVideoOd->SetProperty(4, NULL);
+ }
+
+ // then destroy
+ delete pCommand;
+}
+
+void MP4File::CreateIsmaSceneCommand(
+ bool hasAudio,
+ bool hasVideo,
+ u_int8_t** ppBytes,
+ u_int64_t* pNumBytes)
+{
+ // from ISMA 1.0 Tech Spec Appendix E
+ static u_int8_t bifsAudioOnly[] = {
+ 0xC0, 0x10, 0x12,
+ 0x81, 0x30, 0x2A, 0x05, 0x6D, 0xC0
+ };
+ static u_int8_t bifsVideoOnly[] = {
+ 0xC0, 0x10, 0x12,
+ 0x61, 0x04,
+ 0x1F, 0xC0, 0x00, 0x00,
+ 0x1F, 0xC0, 0x00, 0x00,
+ 0x44, 0x28, 0x22, 0x82, 0x9F, 0x80
+ };
+ static u_int8_t bifsAudioVideo[] = {
+ 0xC0, 0x10, 0x12,
+ 0x81, 0x30, 0x2A, 0x05, 0x6D, 0x26,
+ 0x10, 0x41, 0xFC, 0x00, 0x00, 0x01, 0xFC, 0x00, 0x00,
+ 0x04, 0x42, 0x82, 0x28, 0x29, 0xF8
+ };
+
+ if (hasAudio && hasVideo) {
+ *pNumBytes = sizeof(bifsAudioVideo);
+ *ppBytes = (u_int8_t*)MP4Malloc(*pNumBytes);
+ memcpy(*ppBytes, bifsAudioVideo, sizeof(bifsAudioVideo));
+
+ } else if (hasAudio) {
+ *pNumBytes = sizeof(bifsAudioOnly);
+ *ppBytes = (u_int8_t*)MP4Malloc(*pNumBytes);
+ memcpy(*ppBytes, bifsAudioOnly, sizeof(bifsAudioOnly));
+
+ } else if (hasVideo) {
+ *pNumBytes = sizeof(bifsVideoOnly);
+ *ppBytes = (u_int8_t*)MP4Malloc(*pNumBytes);
+ memcpy(*ppBytes, bifsVideoOnly, sizeof(bifsVideoOnly));
+ } else {
+ *pNumBytes = 0;
+ *ppBytes = NULL;
+ }
+}
+
--- /dev/null
+++ b/common/mp4v2/libmp4v260.dsp
@@ -1,0 +1,561 @@
+# Microsoft Developer Studio Project File - Name="libmp4v2" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Static Library" 0x0104
+
+CFG=libmp4v2 - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "libmp4v260.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "libmp4v260.mak" CFG="libmp4v2 - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "libmp4v2 - Win32 Release" (based on "Win32 (x86) Static Library")
+!MESSAGE "libmp4v2 - Win32 Debug" (based on "Win32 (x86) Static Library")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "libmp4v2 - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
+# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\..\include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
+# SUBTRACT CPP /Fr
+# ADD BASE RSC /l 0x409
+# ADD RSC /l 0x409
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LIB32=link.exe -lib
+# ADD BASE LIB32 /nologo
+# ADD LIB32 /nologo
+
+!ELSEIF "$(CFG)" == "libmp4v2 - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /Z7 /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
+# ADD CPP /nologo /MDd /W3 /GX /Zi /Od /I "..\..\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /FR /YX /FD /c
+# ADD BASE RSC /l 0x409
+# ADD RSC /l 0x409
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LIB32=link.exe -lib
+# ADD BASE LIB32 /nologo
+# ADD LIB32 /nologo
+
+!ENDIF
+
+# Begin Target
+
+# Name "libmp4v2 - Win32 Release"
+# Name "libmp4v2 - Win32 Debug"
+# Begin Group "source"
+
+# PROP Default_Filter ".c, .cpp"
+# Begin Source File
+
+SOURCE=.\3gp.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_bitr.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_co64.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_cprt.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_ctts.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_d263.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_damr.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_dimm.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_dinf.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_dmax.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_dmed.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_dref.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_drep.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_edts.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_elst.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_enca.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_encv.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_esds.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_free.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_frma.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_ftyp.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_hdlr.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_hinf.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_hmhd.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_hnti.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_iKMS.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_iods.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_iSFM.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_maxr.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_mdat.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_mdhd.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_mdia.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_meta.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_mfhd.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_minf.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_moof.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_moov.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_mp4a.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_mp4s.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_mp4v.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_mvex.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_mvhd.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_nmhd.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_nump.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_payt.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_pmax.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_root.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_rtp.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_s263.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_samr.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_sawb.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_schi.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_schm.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_sdp.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_sinf.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_smhd.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_snro.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_stbl.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_stco.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_stdp.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_stsc.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_stsd.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_stsh.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_stss.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_stsz.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_stts.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_tfhd.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_tims.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_tkhd.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_tmax.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_tmin.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_tpyl.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_traf.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_trak.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_tref.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_treftype.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_trex.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_trpy.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_trun.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_tsro.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_udta.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_url.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_urn.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_vmhd.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\descriptors.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\isma.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\mp4.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\mp4atom.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\mp4container.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\mp4descriptor.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\mp4file.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\mp4file_io.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\mp4info.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\mp4meta.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\mp4property.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\mp4track.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\mp4util.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\ocidescriptors.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\odcommands.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\qosqualifiers.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\rtphint.cpp
+# End Source File
+# End Group
+# Begin Group "include"
+
+# PROP Default_Filter ".h"
+# Begin Source File
+
+SOURCE=.\atoms.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\descriptors.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\mp4.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\mp4array.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\mp4atom.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\mp4common.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\mp4container.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\mp4descriptor.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\mp4file.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\mp4property.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\mp4track.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\mp4util.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\ocidescriptors.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\odcommands.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\qosqualifiers.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\rtphint.h
+# End Source File
+# End Group
+# End Target
+# End Project
--- /dev/null
+++ b/common/mp4v2/libmp4v2_st60.dsp
@@ -1,0 +1,568 @@
+# Microsoft Developer Studio Project File - Name="libmp4v2_st" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Static Library" 0x0104
+
+CFG=libmp4v2_st - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "libmp4v2_st60.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "libmp4v2_st60.mak" CFG="libmp4v2_st - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "libmp4v2_st - Win32 Release" (based on "Win32 (x86) Static Library")
+!MESSAGE "libmp4v2_st - Win32 Debug" (based on "Win32 (x86) Static Library")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=xicl6.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "libmp4v2_st - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "ST_Release"
+# PROP Intermediate_Dir "ST_Release"
+# PROP Target_Dir ""
+MTL=midl.exe
+F90=df.exe
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
+# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\..\include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
+# ADD BASE RSC /l 0x409
+# ADD RSC /l 0x409
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LIB32=link.exe -lib
+# ADD BASE LIB32 /nologo
+# ADD LIB32 /nologo
+
+!ELSEIF "$(CFG)" == "libmp4v2_st - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "ST_Debug"
+# PROP Intermediate_Dir "ST_Debug"
+# PROP Target_Dir ""
+MTL=midl.exe
+F90=df.exe
+# ADD BASE CPP /nologo /W3 /GX /Z7 /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
+# ADD CPP /nologo /W3 /GX /Z7 /Od /I "..\..\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
+# ADD BASE RSC /l 0x409
+# ADD RSC /l 0x409
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LIB32=link.exe -lib
+# ADD BASE LIB32 /nologo
+# ADD LIB32 /nologo
+
+!ENDIF
+
+# Begin Target
+
+# Name "libmp4v2_st - Win32 Release"
+# Name "libmp4v2_st - Win32 Debug"
+# Begin Group "source"
+
+# PROP Default_Filter ".c, .cpp"
+# Begin Source File
+
+SOURCE=.\3gp.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_bitr.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_co64.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_cprt.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_ctts.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_d263.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_damr.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_dimm.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_dinf.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_dmax.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_dmed.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_dref.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_drep.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_edts.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_elst.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_esds.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_free.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_ftyp.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_hdlr.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_hinf.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_hmhd.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_hnti.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_iods.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_maxr.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_mdat.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_mdhd.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_mdia.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_meta.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_mfhd.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_minf.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_moof.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_moov.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_mp4a.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_mp4s.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_mp4v.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_mvex.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_mvhd.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_nmhd.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_nump.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_payt.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_pmax.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_root.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_rtp.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_s263.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_samr.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_sawb.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_sdp.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_smhd.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_snro.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_stbl.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_stco.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_stdp.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_stsc.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_stsd.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_stsh.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_stss.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_stsz.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_stts.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_tfhd.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_tims.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_tkhd.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_tmax.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_tmin.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_tpyl.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_traf.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_trak.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_tref.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_treftype.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_trex.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_trpy.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_trun.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_tsro.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_udta.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_url.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_urn.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_vmhd.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\descriptors.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\isma.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\mp4.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\mp4atom.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\mp4container.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\mp4descriptor.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\mp4file.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\mp4file_io.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\mp4meta.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\mp4property.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\mp4track.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\mp4util.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\need_for_win32.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\ocidescriptors.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\odcommands.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\qosqualifiers.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\rtphint.cpp
+# End Source File
+# End Group
+# Begin Group "include"
+
+# PROP Default_Filter ".h"
+# Begin Source File
+
+SOURCE=.\atoms.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\descriptors.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\mp4.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\mp4array.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\mp4atom.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\mp4common.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\mp4container.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\mp4descriptor.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\mp4file.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\mp4property.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\mp4track.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\mp4util.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\ocidescriptors.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\odcommands.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\qosqualifiers.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\rtphint.h
+# End Source File
+# End Group
+# Begin Source File
+
+SOURCE=.\atom_enca.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_encv.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_frma.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_iKMS.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_iSFM.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_schi.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_schm.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\atom_sinf.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\mp4info.cpp
+# End Source File
+# End Target
+# End Project
--- /dev/null
+++ b/common/mp4v2/mp4.cpp
@@ -1,0 +1,3507 @@
+/*
+ * 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 - 2004. All Rights Reserved.
+ *
+ * 3GPP features implementation is based on 3GPP's TS26.234-v5.60,
+ * and was contributed by Ximpo Group Ltd.
+ *
+ * Portions created by Ximpo Group Ltd. are
+ * Copyright (C) Ximpo Group Ltd. 2003, 2004. All Rights Reserved.
+ *
+ * Contributor(s):
+ * Dave Mackie dmackie@cisco.com
+ * Alix Marchandise-Franquet alix@cisco.com
+ * Ximpo Group Ltd. mp4v2@ximpo.com
+ */
+
+/*
+ * MP4 library API functions
+ *
+ * These are wrapper functions that provide C linkage conventions
+ * to the library, and catch any internal errors, ensuring that
+ * a proper return value is given.
+ */
+
+#include "mp4common.h"
+
+#define PRINT_ERROR(e) \
+ VERBOSE_ERROR(((MP4File*)hFile)->GetVerbosity(), e->Print());
+
+/* file operations */
+
+extern "C" MP4FileHandle MP4Read(const char* fileName, u_int32_t verbosity)
+{
+ MP4File* pFile = NULL;
+ try {
+ pFile = new MP4File(verbosity);
+ pFile->Read(fileName);
+ return (MP4FileHandle)pFile;
+ }
+ catch (MP4Error* e) {
+ VERBOSE_ERROR(verbosity, e->Print());
+ delete e;
+ delete pFile;
+ return MP4_INVALID_FILE_HANDLE;
+ }
+}
+
+extern "C" MP4FileHandle MP4CreateEx(const char* fileName,
+ u_int32_t verbosity, u_int32_t flags,
+ char* majorBrand, u_int32_t minorVersion,
+ char** supportedBrands, u_int32_t supportedBrandsCount)
+{
+ MP4File* pFile = NULL;
+ try {
+ pFile = new MP4File(verbosity);
+ // LATER useExtensibleFormat, moov first, then mvex's
+ if (!majorBrand) {
+ pFile->Create(fileName, flags);
+ } else {
+ pFile->CreateEx(fileName, flags, majorBrand, minorVersion, supportedBrands, supportedBrandsCount);
+ }
+ return (MP4FileHandle)pFile;
+ }
+ catch (MP4Error* e) {
+ VERBOSE_ERROR(verbosity, e->Print());
+ delete e;
+ delete pFile;
+ return MP4_INVALID_FILE_HANDLE;
+ }
+}
+
+extern "C" MP4FileHandle MP4Create(const char* fileName,
+ u_int32_t verbosity,
+ u_int32_t flags)
+{
+ return MP4CreateEx(fileName, verbosity, flags, NULL, 0, NULL, 0 );
+}
+
+extern "C" MP4FileHandle MP4Modify(const char* fileName,
+ u_int32_t verbosity, u_int32_t flags)
+{
+ MP4File* pFile = NULL;
+ try {
+ pFile = new MP4File(verbosity);
+ // LATER useExtensibleFormat, moov first, then mvex's
+ pFile->Modify(fileName);
+ return (MP4FileHandle)pFile;
+ }
+ catch (MP4Error* e) {
+ VERBOSE_ERROR(verbosity, e->Print());
+ delete e;
+ delete pFile;
+ return MP4_INVALID_FILE_HANDLE;
+ }
+}
+
+extern "C" bool MP4Optimize(const char* existingFileName,
+ const char* newFileName,
+ u_int32_t verbosity)
+{
+ try {
+ MP4File* pFile = new MP4File(verbosity);
+ pFile->Optimize(existingFileName, newFileName);
+ delete pFile;
+ return true;
+ }
+ catch (MP4Error* e) {
+ VERBOSE_ERROR(verbosity, e->Print());
+ delete e;
+ }
+ return false;
+}
+
+extern "C" bool MP4Close(MP4FileHandle hFile)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ ((MP4File*)hFile)->Close();
+ delete (MP4File*)hFile;
+ return true;
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" bool MP4Dump(
+ MP4FileHandle hFile,
+ FILE* pDumpFile,
+ bool dumpImplicits)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ ((MP4File*)hFile)->Dump(pDumpFile, dumpImplicits);
+ return true;
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+
+/* specific file properties */
+
+extern "C" u_int32_t MP4GetVerbosity(MP4FileHandle hFile)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->GetVerbosity();
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return 0;
+}
+
+extern "C" bool MP4SetVerbosity(MP4FileHandle hFile, u_int32_t verbosity)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ ((MP4File*)hFile)->SetVerbosity(verbosity);
+ return true;
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" MP4Duration MP4GetDuration(MP4FileHandle hFile)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->GetDuration();
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return MP4_INVALID_DURATION;
+}
+
+extern "C" u_int32_t MP4GetTimeScale(MP4FileHandle hFile)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->GetTimeScale();
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return 0;
+}
+
+extern "C" bool MP4SetTimeScale(MP4FileHandle hFile, u_int32_t value)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ ((MP4File*)hFile)->SetTimeScale(value);
+ return true;
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" u_int8_t MP4GetODProfileLevel(MP4FileHandle hFile)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->GetODProfileLevel();
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return 0;
+}
+
+extern "C" bool MP4SetODProfileLevel(MP4FileHandle hFile, u_int8_t value)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ ((MP4File*)hFile)->SetODProfileLevel(value);
+ return true;
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" u_int8_t MP4GetSceneProfileLevel(MP4FileHandle hFile)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->GetSceneProfileLevel();
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return 0;
+}
+
+extern "C" bool MP4SetSceneProfileLevel(MP4FileHandle hFile, u_int8_t value)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ ((MP4File*)hFile)->SetSceneProfileLevel(value);
+ return true;
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" u_int8_t MP4GetVideoProfileLevel(MP4FileHandle hFile)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->GetVideoProfileLevel();
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return 0;
+}
+
+extern "C" bool MP4SetVideoProfileLevel(MP4FileHandle hFile, u_int8_t value)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ ((MP4File*)hFile)->SetVideoProfileLevel(value);
+ return true;
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" u_int8_t MP4GetAudioProfileLevel(MP4FileHandle hFile)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->GetAudioProfileLevel();
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return 0;
+}
+
+extern "C" bool MP4SetAudioProfileLevel(MP4FileHandle hFile, u_int8_t value)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ ((MP4File*)hFile)->SetAudioProfileLevel(value);
+ return true;
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" u_int8_t MP4GetGraphicsProfileLevel(MP4FileHandle hFile)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->GetGraphicsProfileLevel();
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return 0;
+}
+
+extern "C" bool MP4SetGraphicsProfileLevel(MP4FileHandle hFile, u_int8_t value)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ ((MP4File*)hFile)->SetGraphicsProfileLevel(value);
+ return true;
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+/* generic file properties */
+
+extern "C" u_int64_t MP4GetIntegerProperty(
+ MP4FileHandle hFile, const char* propName)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->GetIntegerProperty(propName);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return (u_int64_t)-1;
+}
+
+extern "C" float MP4GetFloatProperty(
+ MP4FileHandle hFile, const char* propName)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->GetFloatProperty(propName);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return NAN;
+}
+
+extern "C" const char* MP4GetStringProperty(
+ MP4FileHandle hFile, const char* propName)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->GetStringProperty(propName);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return NULL;
+}
+
+extern "C" void MP4GetBytesProperty(
+ MP4FileHandle hFile, const char* propName,
+ u_int8_t** ppValue, u_int32_t* pValueSize)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ ((MP4File*)hFile)->GetBytesProperty(propName, ppValue, pValueSize);
+ return;
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ *ppValue = NULL;
+ *pValueSize = 0;
+ return;
+}
+
+extern "C" bool MP4SetIntegerProperty(
+ MP4FileHandle hFile, const char* propName, int64_t value)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ ((MP4File*)hFile)->SetIntegerProperty(propName, value);
+ return true;
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" bool MP4SetFloatProperty(
+ MP4FileHandle hFile, const char* propName, float value)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ ((MP4File*)hFile)->SetFloatProperty(propName, value);
+ return true;
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" bool MP4SetStringProperty(
+ MP4FileHandle hFile, const char* propName, const char* value)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ ((MP4File*)hFile)->SetStringProperty(propName, value);
+ return true;
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" bool MP4SetBytesProperty(
+ MP4FileHandle hFile, const char* propName,
+ const u_int8_t* pValue, u_int32_t valueSize)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ ((MP4File*)hFile)->SetBytesProperty(propName, pValue, valueSize);
+ return true;
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+/* track operations */
+
+extern "C" MP4TrackId MP4AddTrack(
+ MP4FileHandle hFile, const char* type)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->AddSystemsTrack(type);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return MP4_INVALID_TRACK_ID;
+}
+
+extern "C" MP4TrackId MP4AddSystemsTrack(
+ MP4FileHandle hFile, const char* type)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->AddSystemsTrack(type);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return MP4_INVALID_TRACK_ID;
+}
+
+extern "C" MP4TrackId MP4AddODTrack(MP4FileHandle hFile)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->AddODTrack();
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return MP4_INVALID_TRACK_ID;
+}
+
+extern "C" MP4TrackId MP4AddSceneTrack(MP4FileHandle hFile)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->AddSceneTrack();
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return MP4_INVALID_TRACK_ID;
+}
+
+extern "C" MP4TrackId MP4AddAudioTrack(
+ MP4FileHandle hFile,
+ u_int32_t timeScale,
+ MP4Duration sampleDuration,
+ u_int8_t audioType)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->
+ AddAudioTrack(timeScale, sampleDuration, audioType);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return MP4_INVALID_TRACK_ID;
+}
+
+extern "C" MP4TrackId MP4AddEncAudioTrack(MP4FileHandle hFile,
+ u_int32_t timeScale,
+ MP4Duration sampleDuration,
+ mp4v2_ismacrypParams *icPp,
+ u_int8_t audioType
+ )
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->
+ AddEncAudioTrack(timeScale, sampleDuration, audioType,
+ icPp->scheme_type, icPp->scheme_version,
+ icPp->key_ind_len, icPp->iv_len,
+ icPp->selective_enc, icPp->kms_uri);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return MP4_INVALID_TRACK_ID;
+}
+extern "C" MP4TrackId MP4AddAmrAudioTrack(
+ MP4FileHandle hFile,
+ u_int32_t timeScale,
+ u_int16_t modeSet,
+ u_int8_t modeChangePeriod,
+ u_int8_t framesPerSample,
+ bool isAmrWB)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->
+ AddAmrAudioTrack(timeScale, modeSet, modeChangePeriod, framesPerSample, isAmrWB);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return MP4_INVALID_TRACK_ID;
+}
+
+extern "C" void MP4SetAmrVendor(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ u_int32_t vendor)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ ((MP4File*)hFile)->
+ SetAmrVendor(trackId, vendor);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+}
+
+extern "C" void MP4SetAmrDecoderVersion(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ u_int8_t decoderVersion)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ ((MP4File*)hFile)->
+ SetAmrDecoderVersion(trackId, decoderVersion);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+}
+
+extern "C" void MP4SetAmrModeSet(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ u_int16_t modeSet)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ ((MP4File*)hFile)->
+ SetAmrModeSet(trackId, modeSet);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+}
+
+
+extern "C" MP4TrackId MP4AddVideoTrack(
+ MP4FileHandle hFile,
+ u_int32_t timeScale,
+ MP4Duration sampleDuration,
+ u_int16_t width,
+ u_int16_t height,
+ u_int8_t videoType)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->AddVideoTrack(
+ timeScale, sampleDuration, width, height, videoType);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return MP4_INVALID_TRACK_ID;
+}
+
+extern "C" MP4TrackId MP4AddEncVideoTrack(MP4FileHandle hFile,
+ u_int32_t timeScale,
+ MP4Duration sampleDuration,
+ u_int16_t width,
+ u_int16_t height,
+ mp4v2_ismacrypParams *icPp,
+ u_int8_t videoType )
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->AddEncVideoTrack(timeScale, sampleDuration,
+ width, height, videoType,
+ icPp->scheme_type, icPp->scheme_version,
+ icPp->key_ind_len, icPp->iv_len,
+ icPp->selective_enc, icPp->kms_uri);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return MP4_INVALID_TRACK_ID;
+}
+extern "C" MP4TrackId MP4AddH263VideoTrack(
+ MP4FileHandle hFile,
+ u_int32_t timeScale,
+ MP4Duration sampleDuration,
+ u_int16_t width,
+ u_int16_t height,
+ u_int8_t h263Level,
+ u_int8_t h263Profile,
+ u_int32_t avgBitrate,
+ u_int32_t maxBitrate)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->
+ AddH263VideoTrack(timeScale, sampleDuration, width, height, h263Level, h263Profile, avgBitrate, maxBitrate);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+
+ return MP4_INVALID_TRACK_ID;
+}
+
+extern "C" void MP4SetH263Vendor(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ u_int32_t vendor)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ ((MP4File*)hFile)->
+ SetH263Vendor(trackId, vendor);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+}
+
+extern "C" void MP4SetH263DecoderVersion(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ u_int8_t decoderVersion)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+
+ try {
+ ((MP4File*)hFile)->
+ SetH263DecoderVersion(trackId, decoderVersion);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+}
+
+extern "C" void MP4SetH263Bitrates(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ u_int32_t avgBitrate,
+ u_int32_t maxBitrate)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+
+ try {
+ ((MP4File*)hFile)->
+ SetH263Bitrates(trackId, avgBitrate, maxBitrate);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+}
+
+extern "C" MP4TrackId MP4AddHintTrack(
+ MP4FileHandle hFile, MP4TrackId refTrackId)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->AddHintTrack(refTrackId);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return MP4_INVALID_TRACK_ID;
+}
+
+extern "C" MP4TrackId MP4CloneTrack(
+ MP4FileHandle srcFile,
+ MP4TrackId srcTrackId,
+ MP4FileHandle dstFile,
+ MP4TrackId dstHintTrackReferenceTrack)
+{
+ MP4TrackId dstTrackId = MP4_INVALID_TRACK_ID;
+
+ if (dstFile == NULL) {
+ dstFile = srcFile;
+ }
+
+ const char* trackType =
+ MP4GetTrackType(srcFile, srcTrackId);
+
+ if (!trackType) {
+ return dstTrackId;
+ }
+
+ if (MP4_IS_VIDEO_TRACK_TYPE(trackType)) {
+ MP4SetVideoProfileLevel(dstFile,
+ MP4GetVideoProfileLevel(srcFile));
+ dstTrackId = MP4AddVideoTrack(
+ dstFile,
+ MP4GetTrackTimeScale(srcFile, srcTrackId),
+ MP4GetTrackFixedSampleDuration(srcFile, srcTrackId),
+ MP4GetTrackVideoWidth(srcFile, srcTrackId),
+ MP4GetTrackVideoHeight(srcFile, srcTrackId),
+ MP4GetTrackEsdsObjectTypeId(srcFile, srcTrackId));
+
+ } else if (MP4_IS_AUDIO_TRACK_TYPE(trackType)) {
+ MP4SetAudioProfileLevel(dstFile,
+ MP4GetAudioProfileLevel(srcFile));
+ dstTrackId = MP4AddAudioTrack(
+ dstFile,
+ MP4GetTrackTimeScale(srcFile, srcTrackId),
+ MP4GetTrackFixedSampleDuration(srcFile, srcTrackId),
+ MP4GetTrackEsdsObjectTypeId(srcFile, srcTrackId));
+
+ } else if (MP4_IS_OD_TRACK_TYPE(trackType)) {
+ dstTrackId = MP4AddODTrack(dstFile);
+
+ } else if (MP4_IS_SCENE_TRACK_TYPE(trackType)) {
+ dstTrackId = MP4AddSceneTrack(dstFile);
+
+ } else if (MP4_IS_HINT_TRACK_TYPE(trackType)) {
+ if (dstHintTrackReferenceTrack == MP4_INVALID_TRACK_ID) {
+ dstTrackId = MP4_INVALID_TRACK_ID;
+ } else {
+ dstTrackId = MP4AddHintTrack(
+ dstFile,
+ dstHintTrackReferenceTrack);
+ }
+
+ } else if (MP4_IS_SYSTEMS_TRACK_TYPE(trackType)) {
+ dstTrackId = MP4AddSystemsTrack(dstFile, trackType);
+
+ } else {
+ dstTrackId = MP4AddTrack(dstFile, trackType);
+ }
+
+ if (dstTrackId == MP4_INVALID_TRACK_ID) {
+ return dstTrackId;
+ }
+
+ MP4SetTrackTimeScale(
+ dstFile,
+ dstTrackId,
+ MP4GetTrackTimeScale(srcFile, srcTrackId));
+
+ if (MP4_IS_AUDIO_TRACK_TYPE(trackType)
+ || MP4_IS_VIDEO_TRACK_TYPE(trackType)) {
+ // copy track ES configuration
+ u_int8_t* pConfig = NULL;
+ u_int32_t configSize = 0;
+
+ MP4GetTrackESConfiguration(
+ srcFile,
+ srcTrackId,
+ &pConfig,
+ &configSize);
+
+ MP4SetTrackESConfiguration(
+ dstFile,
+ dstTrackId,
+ pConfig,
+ configSize);
+
+ free(pConfig);
+ }
+
+ if (MP4_IS_HINT_TRACK_TYPE(trackType)) {
+ // probably not exactly what is wanted
+ // but caller can adjust later to fit their desires
+
+ char* payloadName = NULL;
+ char *encodingParms = NULL;
+ u_int8_t payloadNumber;
+ u_int16_t maxPayloadSize;
+
+ MP4GetHintTrackRtpPayload(
+ srcFile,
+ srcTrackId,
+ &payloadName,
+ &payloadNumber,
+ &maxPayloadSize,
+ &encodingParms);
+
+ MP4SetHintTrackRtpPayload(
+ dstFile,
+ dstTrackId,
+ payloadName,
+ &payloadNumber,
+ maxPayloadSize,
+ encodingParms);
+#if 0
+ MP4SetHintTrackSdp(
+ dstFile,
+ dstTrackId,
+ MP4GetHintTrackSdp(srcFile, srcTrackId));
+#endif
+ }
+
+ return dstTrackId;
+}
+
+// Given a track, make an encrypted clone of it in the dest. file
+extern "C" MP4TrackId MP4EncAndCloneTrack(MP4FileHandle srcFile,
+ MP4TrackId srcTrackId,
+ mp4v2_ismacrypParams *icPp,
+ MP4FileHandle dstFile,
+ MP4TrackId dstHintTrackReferenceTrack
+ )
+{
+ MP4TrackId dstTrackId = MP4_INVALID_TRACK_ID;
+
+ if (dstFile == NULL) {
+ dstFile = srcFile;
+ }
+
+ const char* trackType =
+ MP4GetTrackType(srcFile, srcTrackId);
+
+ if (!trackType) {
+ return dstTrackId;
+ }
+
+ if (MP4_IS_VIDEO_TRACK_TYPE(trackType)) {
+ MP4SetVideoProfileLevel(dstFile, MP4GetVideoProfileLevel(srcFile));
+ dstTrackId = MP4AddEncVideoTrack(dstFile,
+ MP4GetTrackTimeScale(srcFile, srcTrackId),
+ MP4GetTrackFixedSampleDuration(srcFile,
+ srcTrackId),
+ MP4GetTrackVideoWidth(srcFile, srcTrackId),
+ MP4GetTrackVideoHeight(srcFile, srcTrackId),
+ icPp,
+ MP4GetTrackEsdsObjectTypeId(srcFile,
+ srcTrackId)
+ );
+
+ } else if (MP4_IS_AUDIO_TRACK_TYPE(trackType)) {
+ MP4SetAudioProfileLevel(dstFile, MP4GetAudioProfileLevel(srcFile));
+ dstTrackId = MP4AddEncAudioTrack(dstFile,
+ MP4GetTrackTimeScale(srcFile, srcTrackId),
+ MP4GetTrackFixedSampleDuration(srcFile,
+ srcTrackId),
+ icPp,
+ MP4GetTrackEsdsObjectTypeId(srcFile,
+ srcTrackId)
+ );
+
+ } else if (MP4_IS_OD_TRACK_TYPE(trackType)) {
+ dstTrackId = MP4AddODTrack(dstFile);
+
+ } else if (MP4_IS_SCENE_TRACK_TYPE(trackType)) {
+ dstTrackId = MP4AddSceneTrack(dstFile);
+
+ } else if (MP4_IS_HINT_TRACK_TYPE(trackType)) {
+ if (dstHintTrackReferenceTrack == MP4_INVALID_TRACK_ID) {
+ dstTrackId = MP4_INVALID_TRACK_ID;
+ } else {
+ dstTrackId = MP4AddHintTrack(dstFile,
+ MP4GetHintTrackReferenceTrackId(srcFile,
+ srcTrackId));
+ }
+ } else if (MP4_IS_SYSTEMS_TRACK_TYPE(trackType)) {
+ dstTrackId = MP4AddSystemsTrack(dstFile, trackType);
+
+ } else {
+ dstTrackId = MP4AddTrack(dstFile, trackType);
+ }
+
+ if (dstTrackId == MP4_INVALID_TRACK_ID) {
+ return dstTrackId;
+ }
+
+ MP4SetTrackTimeScale(dstFile,
+ dstTrackId,
+ MP4GetTrackTimeScale(srcFile, srcTrackId));
+
+ if (MP4_IS_AUDIO_TRACK_TYPE(trackType)
+ || MP4_IS_VIDEO_TRACK_TYPE(trackType)) {
+ // copy track ES configuration
+ u_int8_t* pConfig = NULL;
+ u_int32_t configSize = 0;
+ if (MP4GetTrackESConfiguration(srcFile, srcTrackId,
+ &pConfig, &configSize)) {
+
+ if (pConfig != NULL) {
+ MP4SetTrackESConfiguration(dstFile, dstTrackId,
+ pConfig, configSize);
+ }
+ }
+ if (pConfig != NULL)
+ free(pConfig);
+ }
+
+ // Bill's change to MP4CloneTrack
+ if (MP4_IS_HINT_TRACK_TYPE(trackType)) {
+ // probably not exactly what is wanted
+ // but caller can adjust later to fit their desires
+
+ char* payloadName = NULL;
+ char *encodingParms = NULL;
+ u_int8_t payloadNumber;
+ u_int16_t maxPayloadSize;
+
+ MP4GetHintTrackRtpPayload(
+ srcFile,
+ srcTrackId,
+ &payloadName,
+ &payloadNumber,
+ &maxPayloadSize,
+ &encodingParms);
+
+ MP4SetHintTrackRtpPayload(
+ dstFile,
+ dstTrackId,
+ payloadName,
+ &payloadNumber,
+ maxPayloadSize,
+ encodingParms);
+#if 0
+ MP4SetHintTrackSdp(
+ dstFile,
+ dstTrackId,
+ MP4GetHintTrackSdp(srcFile, srcTrackId));
+#endif
+ }
+
+ return dstTrackId;
+}
+extern "C" MP4TrackId MP4CopyTrack(MP4FileHandle srcFile,
+ MP4TrackId srcTrackId,
+ MP4FileHandle dstFile,
+ bool applyEdits,
+ MP4TrackId dstHintTrackReferenceTrack)
+{
+ bool copySamples = true; // LATER allow false => reference samples
+
+ MP4TrackId dstTrackId =
+ MP4CloneTrack(srcFile, srcTrackId, dstFile, dstHintTrackReferenceTrack);
+
+ if (dstTrackId == MP4_INVALID_TRACK_ID) {
+ return dstTrackId;
+ }
+
+ bool viaEdits =
+ applyEdits && MP4GetTrackNumberOfEdits(srcFile, srcTrackId);
+
+ MP4SampleId sampleId = 0;
+ MP4SampleId numSamples =
+ MP4GetTrackNumberOfSamples(srcFile, srcTrackId);
+
+ MP4Timestamp when = 0;
+ MP4Duration editsDuration =
+ MP4GetTrackEditTotalDuration(srcFile, srcTrackId);
+
+ while (true) {
+ MP4Duration sampleDuration = MP4_INVALID_DURATION;
+
+ if (viaEdits) {
+ sampleId = MP4GetSampleIdFromEditTime(
+ srcFile,
+ srcTrackId,
+ when,
+ NULL,
+ &sampleDuration);
+
+ // in theory, this shouldn't happen
+ if (sampleId == MP4_INVALID_SAMPLE_ID) {
+ MP4DeleteTrack(dstFile, dstTrackId);
+ return MP4_INVALID_TRACK_ID;
+ }
+
+ when += sampleDuration;
+
+ if (when >= editsDuration) {
+ break;
+ }
+ } else {
+ sampleId++;
+ if (sampleId > numSamples) {
+ break;
+ }
+ }
+
+ bool rc = false;
+
+ if (copySamples) {
+ rc = MP4CopySample(
+ srcFile,
+ srcTrackId,
+ sampleId,
+ dstFile,
+ dstTrackId,
+ sampleDuration);
+
+ } else {
+ rc = MP4ReferenceSample(
+ srcFile,
+ srcTrackId,
+ sampleId,
+ dstFile,
+ dstTrackId,
+ sampleDuration);
+ }
+
+ if (!rc) {
+ MP4DeleteTrack(dstFile, dstTrackId);
+ return MP4_INVALID_TRACK_ID;
+ }
+ }
+
+ return dstTrackId;
+}
+
+// Given a source track in a source file, make an encrypted copy of
+// the track in the destination file, including sample encryption
+extern "C" MP4TrackId MP4EncAndCopyTrack(MP4FileHandle srcFile,
+ MP4TrackId srcTrackId,
+ mp4v2_ismacrypParams *icPp,
+ encryptFunc_t encfcnp,
+ u_int32_t encfcnparam1,
+ MP4FileHandle dstFile,
+ bool applyEdits,
+ MP4TrackId dstHintTrackReferenceTrack
+ )
+{
+ bool copySamples = true; // LATER allow false => reference samples
+
+ MP4TrackId dstTrackId =
+ MP4EncAndCloneTrack(srcFile, srcTrackId,
+ icPp,
+ dstFile, dstHintTrackReferenceTrack);
+
+ if (dstTrackId == MP4_INVALID_TRACK_ID) {
+ return dstTrackId;
+ }
+
+ bool viaEdits =
+ applyEdits && MP4GetTrackNumberOfEdits(srcFile, srcTrackId);
+
+ MP4SampleId sampleId = 0;
+ MP4SampleId numSamples =
+ MP4GetTrackNumberOfSamples(srcFile, srcTrackId);
+
+ MP4Timestamp when = 0;
+ MP4Duration editsDuration =
+ MP4GetTrackEditTotalDuration(srcFile, srcTrackId);
+
+ while (true) {
+ MP4Duration sampleDuration = MP4_INVALID_DURATION;
+
+ if (viaEdits) {
+ sampleId = MP4GetSampleIdFromEditTime(srcFile,
+ srcTrackId,
+ when,
+ NULL,
+ &sampleDuration);
+
+ // in theory, this shouldn't happen
+ if (sampleId == MP4_INVALID_SAMPLE_ID) {
+ MP4DeleteTrack(dstFile, dstTrackId);
+ return MP4_INVALID_TRACK_ID;
+ }
+
+ when += sampleDuration;
+
+ if (when >= editsDuration) {
+ break;
+ }
+ } else {
+ sampleId++;
+ if (sampleId > numSamples) {
+ break;
+ }
+ }
+
+ bool rc = false;
+
+ if (copySamples) {
+ // encrypt and copy
+ rc = MP4EncAndCopySample(srcFile,
+ srcTrackId,
+ sampleId,
+ encfcnp,
+ encfcnparam1,
+ dstFile,
+ dstTrackId,
+ sampleDuration);
+
+ } else {
+ // not sure what these are - encrypt?
+ rc = MP4ReferenceSample(srcFile,
+ srcTrackId,
+ sampleId,
+ dstFile,
+ dstTrackId,
+ sampleDuration);
+ }
+
+ if (!rc) {
+ MP4DeleteTrack(dstFile, dstTrackId);
+ return MP4_INVALID_TRACK_ID;
+ }
+ }
+
+ return dstTrackId;
+}
+
+extern "C" bool MP4DeleteTrack(
+ MP4FileHandle hFile,
+ MP4TrackId trackId)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ ((MP4File*)hFile)->DeleteTrack(trackId);
+ return true;
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" u_int32_t MP4GetNumberOfTracks(
+ MP4FileHandle hFile,
+ const char* type,
+ u_int8_t subType)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->GetNumberOfTracks(type, subType);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return 0;
+}
+
+extern "C" MP4TrackId MP4FindTrackId(
+ MP4FileHandle hFile,
+ u_int16_t index,
+ const char* type,
+ u_int8_t subType)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->FindTrackId(index, type, subType);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return MP4_INVALID_TRACK_ID;
+}
+
+extern "C" u_int16_t MP4FindTrackIndex(
+ MP4FileHandle hFile, MP4TrackId trackId)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->FindTrackIndex(trackId);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return (u_int16_t)-1;
+}
+
+/* specific track properties */
+
+extern "C" const char* MP4GetTrackType(
+ MP4FileHandle hFile, MP4TrackId trackId)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->GetTrackType(trackId);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return NULL;
+}
+
+extern "C" MP4Duration MP4GetTrackDuration(
+ MP4FileHandle hFile, MP4TrackId trackId)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->GetTrackDuration(trackId);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return MP4_INVALID_DURATION;
+}
+
+extern "C" u_int32_t MP4GetTrackTimeScale(
+ MP4FileHandle hFile, MP4TrackId trackId)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->GetTrackTimeScale(trackId);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return 0;
+}
+
+extern "C" bool MP4SetTrackTimeScale(
+ MP4FileHandle hFile, MP4TrackId trackId, u_int32_t value)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ ((MP4File*)hFile)->SetTrackTimeScale(trackId, value);
+ return true;
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+
+// This function should not be used anymore
+// use MP4GetTrackEsdsObjectTypeId instead
+extern "C" u_int8_t MP4GetTrackAudioType(
+ MP4FileHandle hFile, MP4TrackId trackId)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+
+ return ((MP4File*)hFile)->GetTrackAudioType(trackId);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return MP4_INVALID_AUDIO_TYPE;
+}
+
+extern "C" u_int8_t MP4GetTrackAudioMpeg4Type(
+ MP4FileHandle hFile, MP4TrackId trackId)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->GetTrackAudioMpeg4Type(trackId);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return MP4_MPEG4_INVALID_AUDIO_TYPE;
+}
+
+
+// This function should not be used anymore
+// use MP4GetTrackEsdsObjectTypeId instead
+extern "C" u_int8_t MP4GetTrackVideoType(
+ MP4FileHandle hFile, MP4TrackId trackId)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->GetTrackVideoType(trackId);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return MP4_INVALID_VIDEO_TYPE;
+}
+
+// Replacement to MP4GetTrackVideoType and MP4GetTrackAudioType
+// Basically does the same thing but with a more self-explanatory name
+extern "C" u_int8_t MP4GetTrackEsdsObjectTypeId(
+ MP4FileHandle hFile, MP4TrackId trackId)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+
+ return ((MP4File*)hFile)->GetTrackEsdsObjectTypeId(trackId);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return MP4_INVALID_AUDIO_TYPE;
+}
+
+extern "C" MP4Duration MP4GetTrackFixedSampleDuration(
+ MP4FileHandle hFile, MP4TrackId trackId)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->GetTrackFixedSampleDuration(trackId);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return MP4_INVALID_DURATION;
+}
+
+extern "C" u_int32_t MP4GetTrackBitRate(
+ MP4FileHandle hFile, MP4TrackId trackId)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->GetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsd.*.esds.decConfigDescr.avgBitrate");
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return 0;
+}
+
+extern "C" bool MP4GetTrackESConfiguration(
+ MP4FileHandle hFile, MP4TrackId trackId,
+ u_int8_t** ppConfig, u_int32_t* pConfigSize)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ ((MP4File*)hFile)->GetTrackESConfiguration(
+ trackId, ppConfig, pConfigSize);
+ return true;
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ *ppConfig = NULL;
+ *pConfigSize = 0;
+ return false;
+}
+
+extern "C" bool MP4SetTrackESConfiguration(
+ MP4FileHandle hFile, MP4TrackId trackId,
+ const u_int8_t* pConfig, u_int32_t configSize)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ ((MP4File*)hFile)->SetTrackESConfiguration(
+ trackId, pConfig, configSize);
+ return true;
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" MP4SampleId MP4GetTrackNumberOfSamples(
+ MP4FileHandle hFile, MP4TrackId trackId)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->GetTrackNumberOfSamples(trackId);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return 0;
+}
+
+extern "C" u_int16_t MP4GetTrackVideoWidth(
+ MP4FileHandle hFile, MP4TrackId trackId)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->GetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsd.*.width");
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return 0;
+}
+
+extern "C" u_int16_t MP4GetTrackVideoHeight(
+ MP4FileHandle hFile, MP4TrackId trackId)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->GetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsd.*.height");
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return 0;
+}
+
+extern "C" float MP4GetTrackVideoFrameRate(
+ MP4FileHandle hFile, MP4TrackId trackId)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->GetTrackVideoFrameRate(trackId);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return 0.0;
+}
+
+// returns true if the track is a media track encrypted according to ismacryp
+extern "C" bool MP4IsIsmaCrypMediaTrack(
+ MP4FileHandle hFile, MP4TrackId trackId)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->IsIsmaCrypMediaTrack(trackId);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+
+/* generic track properties */
+
+extern "C" u_int64_t MP4GetTrackIntegerProperty (
+ MP4FileHandle hFile, MP4TrackId trackId,
+ const char* propName)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->GetTrackIntegerProperty(trackId,
+ propName);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return (u_int64_t)-1;
+}
+extern "C" bool MP4HaveTrackIntegerProperty(
+ MP4FileHandle hFile, MP4TrackId trackId,
+ const char* propName)
+{
+ // The same as MP4GetTrackIntegerProperty but with no error reporting
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->GetTrackIntegerProperty(trackId,
+ propName) != (u_int64_t)-1;
+ }
+ catch (MP4Error* e) {
+ // No error reporting
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" float MP4GetTrackFloatProperty(
+ MP4FileHandle hFile, MP4TrackId trackId,
+ const char* propName)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->GetTrackFloatProperty(trackId, propName);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return NAN;
+}
+
+extern "C" const char* MP4GetTrackStringProperty(
+ MP4FileHandle hFile, MP4TrackId trackId,
+ const char* propName)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->GetTrackStringProperty(trackId, propName);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return NULL;
+}
+
+extern "C" void MP4GetTrackBytesProperty(
+ MP4FileHandle hFile, MP4TrackId trackId, const char* propName,
+ u_int8_t** ppValue, u_int32_t* pValueSize)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ ((MP4File*)hFile)->GetTrackBytesProperty(
+ trackId, propName, ppValue, pValueSize);
+ return;
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ *ppValue = NULL;
+ *pValueSize = 0;
+ return;
+}
+
+extern "C" bool MP4SetTrackIntegerProperty(
+ MP4FileHandle hFile, MP4TrackId trackId,
+ const char* propName, int64_t value)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ ((MP4File*)hFile)->SetTrackIntegerProperty(trackId,
+ propName, value);
+ return true;
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" bool MP4SetTrackFloatProperty(
+ MP4FileHandle hFile, MP4TrackId trackId,
+ const char* propName, float value)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ ((MP4File*)hFile)->SetTrackFloatProperty(trackId, propName, value);
+ return true;
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" bool MP4SetTrackStringProperty(
+ MP4FileHandle hFile, MP4TrackId trackId,
+ const char* propName, const char* value)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ ((MP4File*)hFile)->SetTrackStringProperty(trackId, propName, value);
+ return true;
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" bool MP4SetTrackBytesProperty(
+ MP4FileHandle hFile, MP4TrackId trackId,
+ const char* propName, const u_int8_t* pValue, u_int32_t valueSize)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ ((MP4File*)hFile)->SetTrackBytesProperty(
+ trackId, propName, pValue, valueSize);
+ return true;
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+/* sample operations */
+
+extern "C" bool MP4ReadSample(
+ /* input parameters */
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ MP4SampleId sampleId,
+ /* output parameters */
+ u_int8_t** ppBytes,
+ u_int32_t* pNumBytes,
+ MP4Timestamp* pStartTime,
+ MP4Duration* pDuration,
+ MP4Duration* pRenderingOffset,
+ bool* pIsSyncSample)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ ((MP4File*)hFile)->ReadSample(
+ trackId,
+ sampleId,
+ ppBytes,
+ pNumBytes,
+ pStartTime,
+ pDuration,
+ pRenderingOffset,
+ pIsSyncSample);
+ return true;
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ *pNumBytes = 0;
+ return false;
+}
+
+extern "C" bool MP4ReadSampleFromTime(
+ /* input parameters */
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ MP4Timestamp when,
+ /* output parameters */
+ u_int8_t** ppBytes,
+ u_int32_t* pNumBytes,
+ MP4Timestamp* pStartTime,
+ MP4Duration* pDuration,
+ MP4Duration* pRenderingOffset,
+ bool* pIsSyncSample)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ MP4SampleId sampleId =
+ ((MP4File*)hFile)->GetSampleIdFromTime(
+ trackId, when, false);
+
+ ((MP4File*)hFile)->ReadSample(
+ trackId,
+ sampleId,
+ ppBytes,
+ pNumBytes,
+ pStartTime,
+ pDuration,
+ pRenderingOffset,
+ pIsSyncSample);
+
+ return true;
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ *pNumBytes = 0;
+ return false;
+}
+
+extern "C" bool MP4WriteSample(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ const u_int8_t* pBytes,
+ u_int32_t numBytes,
+ MP4Duration duration,
+ MP4Duration renderingOffset,
+ bool isSyncSample)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ ((MP4File*)hFile)->WriteSample(
+ trackId,
+ pBytes,
+ numBytes,
+ duration,
+ renderingOffset,
+ isSyncSample);
+ return true;
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" bool MP4CopySample(
+ MP4FileHandle srcFile,
+ MP4TrackId srcTrackId,
+ MP4SampleId srcSampleId,
+ MP4FileHandle dstFile,
+ MP4TrackId dstTrackId,
+ MP4Duration dstSampleDuration)
+{
+ bool rc;
+ u_int8_t* pBytes = NULL;
+ u_int32_t numBytes = 0;
+ MP4Duration sampleDuration;
+ MP4Duration renderingOffset;
+ bool isSyncSample;
+
+ // Note: we leave it up to the caller to ensure that the
+ // source and destination tracks are compatible.
+ // i.e. copying audio samples into a video track
+ // is unlikely to do anything useful
+
+ rc = MP4ReadSample(
+ srcFile,
+ srcTrackId,
+ srcSampleId,
+ &pBytes,
+ &numBytes,
+ NULL,
+ &sampleDuration,
+ &renderingOffset,
+ &isSyncSample);
+
+ if (!rc) {
+ return false;
+ }
+
+ if (dstFile == MP4_INVALID_FILE_HANDLE) {
+ dstFile = srcFile;
+ }
+ if (dstTrackId == MP4_INVALID_TRACK_ID) {
+ dstTrackId = srcTrackId;
+ }
+ if (dstSampleDuration != MP4_INVALID_DURATION) {
+ sampleDuration = dstSampleDuration;
+ }
+
+ rc = MP4WriteSample(
+ dstFile,
+ dstTrackId,
+ pBytes,
+ numBytes,
+ sampleDuration,
+ renderingOffset,
+ isSyncSample);
+
+ free(pBytes);
+
+ return rc;
+}
+
+extern "C" bool MP4EncAndCopySample(
+ MP4FileHandle srcFile,
+ MP4TrackId srcTrackId,
+ MP4SampleId srcSampleId,
+ encryptFunc_t encfcnp,
+ u_int32_t encfcnparam1,
+ MP4FileHandle dstFile,
+ MP4TrackId dstTrackId,
+ MP4Duration dstSampleDuration)
+{
+ bool rc;
+ u_int8_t* pBytes = NULL;
+ u_int32_t numBytes = 0;
+ u_int8_t* encSampleData = NULL;
+ u_int32_t encSampleLength = 0;
+ MP4Duration sampleDuration;
+ MP4Duration renderingOffset;
+ bool isSyncSample;
+
+ // Note: we leave it up to the caller to ensure that the
+ // source and destination tracks are compatible.
+ // i.e. copying audio samples into a video track
+ // is unlikely to do anything useful
+
+ rc = MP4ReadSample(
+ srcFile,
+ srcTrackId,
+ srcSampleId,
+ &pBytes,
+ &numBytes,
+ NULL,
+ &sampleDuration,
+ &renderingOffset,
+ &isSyncSample);
+
+ if (!rc) {
+ return false;
+ }
+
+ if (dstFile == MP4_INVALID_FILE_HANDLE) {
+ dstFile = srcFile;
+ }
+ if (dstTrackId == MP4_INVALID_TRACK_ID) {
+ dstTrackId = srcTrackId;
+ }
+ if (dstSampleDuration != MP4_INVALID_DURATION) {
+ sampleDuration = dstSampleDuration;
+ }
+
+ //if (ismacrypEncryptSampleAddHeader(ismaCryptSId, numBytes, pBytes,
+ // &encSampleLength, &encSampleData) != 0) {
+ if (encfcnp(encfcnparam1, numBytes, pBytes,
+ &encSampleLength, &encSampleData) != 0) {
+ fprintf(stderr,
+ "Can't encrypt the sample and add its header %u\n",
+ srcSampleId);
+ }
+
+ rc = MP4WriteSample(
+ dstFile,
+ dstTrackId,
+ encSampleData,
+ encSampleLength,
+ sampleDuration,
+ renderingOffset,
+ isSyncSample);
+
+ free(pBytes);
+
+ if (encSampleData != NULL) {
+ free(encSampleData);
+ }
+
+ return rc;
+}
+
+extern "C" bool MP4ReferenceSample(
+ MP4FileHandle srcFile,
+ MP4TrackId srcTrackId,
+ MP4SampleId srcSampleId,
+ MP4FileHandle dstFile,
+ MP4TrackId dstTrackId,
+ MP4Duration dstSampleDuration)
+{
+ // LATER Not yet implemented
+ return false;
+}
+
+extern "C" u_int32_t MP4GetSampleSize(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ MP4SampleId sampleId)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->GetSampleSize(
+ trackId, sampleId);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return 0;
+}
+
+extern "C" u_int32_t MP4GetTrackMaxSampleSize(
+ MP4FileHandle hFile,
+ MP4TrackId trackId)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->GetTrackMaxSampleSize(trackId);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return 0;
+}
+
+extern "C" MP4SampleId MP4GetSampleIdFromTime(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ MP4Timestamp when,
+ bool wantSyncSample)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->GetSampleIdFromTime(
+ trackId, when, wantSyncSample);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return MP4_INVALID_SAMPLE_ID;
+}
+
+extern "C" MP4Timestamp MP4GetSampleTime(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ MP4SampleId sampleId)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->GetSampleTime(
+ trackId, sampleId);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return MP4_INVALID_TIMESTAMP;
+}
+
+extern "C" MP4Duration MP4GetSampleDuration(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ MP4SampleId sampleId)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->GetSampleDuration(
+ trackId, sampleId);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return MP4_INVALID_DURATION;
+}
+
+extern "C" MP4Duration MP4GetSampleRenderingOffset(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ MP4SampleId sampleId)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->GetSampleRenderingOffset(
+ trackId, sampleId);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return MP4_INVALID_DURATION;
+}
+
+extern "C" bool MP4SetSampleRenderingOffset(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ MP4SampleId sampleId,
+ MP4Duration renderingOffset)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ ((MP4File*)hFile)->SetSampleRenderingOffset(
+ trackId, sampleId, renderingOffset);
+ return true;
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" int8_t MP4GetSampleSync(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ MP4SampleId sampleId)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->GetSampleSync(
+ trackId, sampleId);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return -1;
+}
+
+
+extern "C" u_int64_t MP4ConvertFromMovieDuration(
+ MP4FileHandle hFile,
+ MP4Duration duration,
+ u_int32_t timeScale)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->ConvertFromMovieDuration(
+ duration, timeScale);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return (u_int64_t)MP4_INVALID_DURATION;
+}
+
+extern "C" u_int64_t MP4ConvertFromTrackTimestamp(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ MP4Timestamp timeStamp,
+ u_int32_t timeScale)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->ConvertFromTrackTimestamp(
+ trackId, timeStamp, timeScale);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return (u_int64_t)MP4_INVALID_TIMESTAMP;
+}
+
+extern "C" MP4Timestamp MP4ConvertToTrackTimestamp(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ u_int64_t timeStamp,
+ u_int32_t timeScale)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->ConvertToTrackTimestamp(
+ trackId, timeStamp, timeScale);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return MP4_INVALID_TIMESTAMP;
+}
+
+extern "C" u_int64_t MP4ConvertFromTrackDuration(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ MP4Duration duration,
+ u_int32_t timeScale)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->ConvertFromTrackDuration(
+ trackId, duration, timeScale);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return (u_int64_t)MP4_INVALID_DURATION;
+}
+
+extern "C" MP4Duration MP4ConvertToTrackDuration(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ u_int64_t duration,
+ u_int32_t timeScale)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->ConvertToTrackDuration(
+ trackId, duration, timeScale);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return MP4_INVALID_DURATION;
+}
+
+extern "C" bool MP4GetHintTrackRtpPayload(
+ MP4FileHandle hFile,
+ MP4TrackId hintTrackId,
+ char** ppPayloadName,
+ u_int8_t* pPayloadNumber,
+ u_int16_t* pMaxPayloadSize,
+ char **ppEncodingParams)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ ((MP4File*)hFile)->GetHintTrackRtpPayload(
+ hintTrackId, ppPayloadName, pPayloadNumber, pMaxPayloadSize,
+ ppEncodingParams);
+ return true;
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" bool MP4SetHintTrackRtpPayload(
+ MP4FileHandle hFile,
+ MP4TrackId hintTrackId,
+ const char* pPayloadName,
+ u_int8_t* pPayloadNumber,
+ u_int16_t maxPayloadSize,
+ const char *encode_params,
+ bool include_rtp_map,
+ bool include_mpeg4_esid)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ ((MP4File*)hFile)->SetHintTrackRtpPayload(
+ hintTrackId, pPayloadName, pPayloadNumber, maxPayloadSize, encode_params,
+ include_rtp_map, include_mpeg4_esid);
+ return true;
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" const char* MP4GetSessionSdp(
+ MP4FileHandle hFile)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->GetSessionSdp();
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return NULL;
+}
+
+extern "C" bool MP4SetSessionSdp(
+ MP4FileHandle hFile,
+ const char* sdpString)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ ((MP4File*)hFile)->SetSessionSdp(sdpString);
+ return true;
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" bool MP4AppendSessionSdp(
+ MP4FileHandle hFile,
+ const char* sdpString)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ ((MP4File*)hFile)->AppendSessionSdp(sdpString);
+ return true;
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" const char* MP4GetHintTrackSdp(
+ MP4FileHandle hFile,
+ MP4TrackId hintTrackId)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->GetHintTrackSdp(hintTrackId);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return NULL;
+}
+
+extern "C" bool MP4SetHintTrackSdp(
+ MP4FileHandle hFile,
+ MP4TrackId hintTrackId,
+ const char* sdpString)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ ((MP4File*)hFile)->SetHintTrackSdp(hintTrackId, sdpString);
+ return true;
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" bool MP4AppendHintTrackSdp(
+ MP4FileHandle hFile,
+ MP4TrackId hintTrackId,
+ const char* sdpString)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ ((MP4File*)hFile)->AppendHintTrackSdp(hintTrackId, sdpString);
+ return true;
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" MP4TrackId MP4GetHintTrackReferenceTrackId(
+ MP4FileHandle hFile,
+ MP4TrackId hintTrackId)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->
+ GetHintTrackReferenceTrackId(hintTrackId);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return MP4_INVALID_TRACK_ID;
+}
+
+extern "C" bool MP4ReadRtpHint(
+ MP4FileHandle hFile,
+ MP4TrackId hintTrackId,
+ MP4SampleId hintSampleId,
+ u_int16_t* pNumPackets)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ ((MP4File*)hFile)->ReadRtpHint(
+ hintTrackId, hintSampleId, pNumPackets);
+ return true;
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" u_int16_t MP4GetRtpHintNumberOfPackets(
+ MP4FileHandle hFile,
+ MP4TrackId hintTrackId)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->GetRtpHintNumberOfPackets(hintTrackId);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return 0;
+}
+
+extern "C" int8_t MP4GetRtpPacketBFrame(
+ MP4FileHandle hFile,
+ MP4TrackId hintTrackId,
+ u_int16_t packetIndex)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->
+ GetRtpPacketBFrame(hintTrackId, packetIndex);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return -1;
+}
+
+extern "C" int32_t MP4GetRtpPacketTransmitOffset(
+ MP4FileHandle hFile,
+ MP4TrackId hintTrackId,
+ u_int16_t packetIndex)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->
+ GetRtpPacketTransmitOffset(hintTrackId, packetIndex);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return 0;
+}
+
+extern "C" bool MP4ReadRtpPacket(
+ MP4FileHandle hFile,
+ MP4TrackId hintTrackId,
+ u_int16_t packetIndex,
+ u_int8_t** ppBytes,
+ u_int32_t* pNumBytes,
+ u_int32_t ssrc,
+ bool includeHeader,
+ bool includePayload)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ ((MP4File*)hFile)->ReadRtpPacket(
+ hintTrackId, packetIndex,
+ ppBytes, pNumBytes,
+ ssrc, includeHeader, includePayload);
+ return true;
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" MP4Timestamp MP4GetRtpTimestampStart(
+ MP4FileHandle hFile,
+ MP4TrackId hintTrackId)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->GetRtpTimestampStart(hintTrackId);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return MP4_INVALID_TIMESTAMP;
+}
+
+extern "C" bool MP4SetRtpTimestampStart(
+ MP4FileHandle hFile,
+ MP4TrackId hintTrackId,
+ MP4Timestamp rtpStart)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ ((MP4File*)hFile)->SetRtpTimestampStart(
+ hintTrackId, rtpStart);
+ return true;
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" bool MP4AddRtpHint(
+ MP4FileHandle hFile,
+ MP4TrackId hintTrackId)
+{
+ return MP4AddRtpVideoHint(hFile, hintTrackId, false, 0);
+}
+
+extern "C" bool MP4AddRtpVideoHint(
+ MP4FileHandle hFile,
+ MP4TrackId hintTrackId,
+ bool isBframe,
+ u_int32_t timestampOffset)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ ((MP4File*)hFile)->AddRtpHint(hintTrackId,
+ isBframe, timestampOffset);
+ return true;
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" bool MP4AddRtpPacket(
+ MP4FileHandle hFile,
+ MP4TrackId hintTrackId,
+ bool setMbit,
+ int32_t transmitOffset)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ ((MP4File*)hFile)->AddRtpPacket(
+ hintTrackId, setMbit, transmitOffset);
+ return true;
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" bool MP4AddRtpImmediateData(
+ MP4FileHandle hFile,
+ MP4TrackId hintTrackId,
+ const u_int8_t* pBytes,
+ u_int32_t numBytes)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ ((MP4File*)hFile)->AddRtpImmediateData(hintTrackId,
+ pBytes, numBytes);
+ return true;
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" bool MP4AddRtpSampleData(
+ MP4FileHandle hFile,
+ MP4TrackId hintTrackId,
+ MP4SampleId sampleId,
+ u_int32_t dataOffset,
+ u_int32_t dataLength)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ ((MP4File*)hFile)->AddRtpSampleData(
+ hintTrackId, sampleId, dataOffset, dataLength);
+ return true;
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" bool MP4AddRtpESConfigurationPacket(
+ MP4FileHandle hFile,
+ MP4TrackId hintTrackId)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ ((MP4File*)hFile)->AddRtpESConfigurationPacket(hintTrackId);
+ return true;
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" bool MP4WriteRtpHint(
+ MP4FileHandle hFile,
+ MP4TrackId hintTrackId,
+ MP4Duration duration,
+ bool isSyncSample)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ ((MP4File*)hFile)->WriteRtpHint(
+ hintTrackId, duration, isSyncSample);
+ return true;
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+/* 3GPP specific operations */
+
+extern "C" bool MP4Make3GPCompliant(
+ const char* fileName,
+ u_int32_t verbosity,
+ char* majorBrand,
+ u_int32_t minorVersion,
+ char** supportedBrands,
+ u_int32_t supportedBrandsCount,
+ bool deleteIodsAtom)
+{
+ MP4File* pFile = NULL;
+
+ try {
+ pFile = new MP4File(verbosity);
+ pFile->Make3GPCompliant(fileName, majorBrand, minorVersion, supportedBrands, supportedBrandsCount, deleteIodsAtom);
+ delete pFile;
+ return true;
+ }
+ catch (MP4Error* e) {
+ VERBOSE_ERROR(verbosity, e->Print());
+ delete e;
+ }
+ delete pFile;
+ return false;
+}
+
+/* ISMA specific operations */
+
+extern "C" bool MP4MakeIsmaCompliant(
+ const char* fileName,
+ u_int32_t verbosity,
+ bool addIsmaComplianceSdp)
+{
+ MP4File* pFile = NULL;
+
+ try {
+ pFile = new MP4File(verbosity);
+ pFile->Modify(fileName);
+ pFile->MakeIsmaCompliant(addIsmaComplianceSdp);
+ pFile->Close();
+ delete pFile;
+ return true;
+ }
+ catch (MP4Error* e) {
+ VERBOSE_ERROR(verbosity, e->Print());
+ delete e;
+ }
+ delete pFile;
+ return false;
+}
+
+extern "C" char* MP4MakeIsmaSdpIod(
+ 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_int32_t verbosity)
+{
+ MP4File* pFile = NULL;
+
+ try {
+ pFile = new MP4File(verbosity);
+
+ u_int8_t* pBytes = NULL;
+ u_int64_t numBytes = 0;
+
+ pFile->CreateIsmaIodFromParams(
+ videoProfile,
+ videoBitrate,
+ videoConfig,
+ videoConfigLength,
+ audioProfile,
+ audioBitrate,
+ audioConfig,
+ audioConfigLength,
+ &pBytes,
+ &numBytes);
+
+ char* iodBase64 =
+ MP4ToBase64(pBytes, numBytes);
+ MP4Free(pBytes);
+
+ char* sdpIod =
+ (char*)MP4Malloc(strlen(iodBase64) + 64);
+ sprintf(sdpIod,
+ "a=mpeg4-iod: \042data:application/mpeg4-iod;base64,%s\042",
+ iodBase64);
+ MP4Free(iodBase64);
+
+ delete pFile;
+
+ return sdpIod;
+ }
+ catch (MP4Error* e) {
+ VERBOSE_ERROR(verbosity, e->Print());
+ delete e;
+ }
+ delete pFile;
+ return NULL;
+}
+
+/* Edit list */
+
+extern "C" MP4EditId MP4AddTrackEdit(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ MP4EditId editId,
+ MP4Timestamp startTime,
+ MP4Duration duration,
+ bool dwell)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ MP4EditId newEditId =
+ ((MP4File*)hFile)->AddTrackEdit(trackId, editId);
+
+ if (newEditId != MP4_INVALID_EDIT_ID) {
+ ((MP4File*)hFile)->SetTrackEditMediaStart(
+ trackId, newEditId, startTime);
+ ((MP4File*)hFile)->SetTrackEditDuration(
+ trackId, newEditId, duration);
+ ((MP4File*)hFile)->SetTrackEditDwell(
+ trackId, newEditId, dwell);
+ }
+
+ return newEditId;
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return MP4_INVALID_EDIT_ID;
+}
+
+extern "C" bool MP4DeleteTrackEdit(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ MP4EditId editId)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ ((MP4File*)hFile)->DeleteTrackEdit(trackId, editId);
+ return true;
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" u_int32_t MP4GetTrackNumberOfEdits(
+ MP4FileHandle hFile,
+ MP4TrackId trackId)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->GetTrackNumberOfEdits(trackId);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return 0;
+}
+
+extern "C" MP4Timestamp MP4GetTrackEditMediaStart(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ MP4EditId editId)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->GetTrackEditMediaStart(
+ trackId, editId);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return MP4_INVALID_TIMESTAMP;
+}
+
+extern "C" MP4Duration MP4GetTrackEditTotalDuration(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ MP4EditId editId)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->GetTrackEditTotalDuration(
+ trackId, editId);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return MP4_INVALID_DURATION;
+}
+
+extern "C" bool MP4SetTrackEditMediaStart(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ MP4EditId editId,
+ MP4Timestamp startTime)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ ((MP4File*)hFile)->SetTrackEditMediaStart(
+ trackId, editId, startTime);
+ return true;
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" MP4Duration MP4GetTrackEditDuration(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ MP4EditId editId)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->GetTrackEditDuration(trackId, editId);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return MP4_INVALID_DURATION;
+}
+
+extern "C" bool MP4SetTrackEditDuration(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ MP4EditId editId,
+ MP4Duration duration)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ ((MP4File*)hFile)->SetTrackEditDuration(trackId, editId, duration);
+ return true;
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" int8_t MP4GetTrackEditDwell(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ MP4EditId editId)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->GetTrackEditDwell(trackId, editId);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return -1;
+}
+
+extern "C" bool MP4SetTrackEditDwell(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ MP4EditId editId,
+ bool dwell)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ ((MP4File*)hFile)->SetTrackEditDwell(trackId, editId, dwell);
+ return true;
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" bool MP4ReadSampleFromEditTime(
+ /* input parameters */
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ MP4Timestamp when,
+ /* output parameters */
+ u_int8_t** ppBytes,
+ u_int32_t* pNumBytes,
+ MP4Timestamp* pStartTime,
+ MP4Duration* pDuration,
+ MP4Duration* pRenderingOffset,
+ bool* pIsSyncSample)
+{
+ MP4SampleId sampleId =
+ MP4GetSampleIdFromEditTime(
+ hFile,
+ trackId,
+ when,
+ pStartTime,
+ pDuration);
+
+ return MP4ReadSample(
+ hFile,
+ trackId,
+ sampleId,
+ ppBytes,
+ pNumBytes,
+ NULL,
+ NULL,
+ pRenderingOffset,
+ pIsSyncSample);
+}
+
+extern "C" MP4SampleId MP4GetSampleIdFromEditTime(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ MP4Timestamp when,
+ MP4Timestamp* pStartTime,
+ MP4Duration* pDuration)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->GetSampleIdFromEditTime(
+ trackId, when, pStartTime, pDuration);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return MP4_INVALID_SAMPLE_ID;
+}
+
+/* Utlities */
+
+extern "C" char* MP4BinaryToBase16(
+ const u_int8_t* pData,
+ u_int32_t dataSize)
+{
+ if (pData || dataSize == 0) {
+ try {
+ return MP4ToBase16(pData, dataSize);
+ }
+ catch (MP4Error* e) {
+ delete e;
+ }
+ }
+ return NULL;
+}
+
+extern "C" char* MP4BinaryToBase64(
+ const u_int8_t* pData,
+ u_int32_t dataSize)
+{
+ if (pData || dataSize == 0) {
+ try {
+ return MP4ToBase64(pData, dataSize);
+ }
+ catch (MP4Error* e) {
+ delete e;
+ }
+ }
+ return NULL;
+}
+
+/* iTunes meta data handling */
+extern "C" bool MP4GetMetadataByIndex(MP4FileHandle hFile, u_int32_t index,
+ const char** ppName,
+ u_int8_t** ppValue, u_int32_t* pValueSize)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->GetMetadataByIndex(
+ index, ppName, ppValue, pValueSize);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" bool MP4MetadataDelete(MP4FileHandle hFile)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->MetadataDelete();
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" bool MP4SetMetadataName(MP4FileHandle hFile,
+ const char* value)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->SetMetadataName(value);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" bool MP4GetMetadataName(MP4FileHandle hFile,
+ char** value)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->GetMetadataName(value);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" bool MP4SetMetadataWriter(MP4FileHandle hFile,
+ const char* value)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->SetMetadataWriter(value);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" bool MP4GetMetadataWriter(MP4FileHandle hFile,
+ char** value)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->GetMetadataWriter(value);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" bool MP4SetMetadataAlbum(MP4FileHandle hFile,
+ const char* value)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->SetMetadataAlbum(value);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" bool MP4GetMetadataAlbum(MP4FileHandle hFile,
+ char** value)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->GetMetadataAlbum(value);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" bool MP4SetMetadataArtist(MP4FileHandle hFile,
+ const char* value)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->SetMetadataArtist(value);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" bool MP4GetMetadataArtist(MP4FileHandle hFile,
+ char** value)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->GetMetadataArtist(value);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" bool MP4SetMetadataTool(MP4FileHandle hFile,
+ const char* value)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->SetMetadataTool(value);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" bool MP4GetMetadataTool(MP4FileHandle hFile,
+ char** value)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->GetMetadataTool(value);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" bool MP4SetMetadataComment(MP4FileHandle hFile,
+ const char* value)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->SetMetadataComment(value);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" bool MP4GetMetadataComment(MP4FileHandle hFile,
+ char** value)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->GetMetadataComment(value);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" bool MP4SetMetadataYear(MP4FileHandle hFile,
+ const char* value)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->SetMetadataYear(value);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" bool MP4GetMetadataYear(MP4FileHandle hFile,
+ char** value)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->GetMetadataYear(value);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" bool MP4SetMetadataTrack(MP4FileHandle hFile,
+ u_int16_t track, u_int16_t totalTracks)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->SetMetadataTrack(track, totalTracks);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" bool MP4GetMetadataTrack(MP4FileHandle hFile,
+ u_int16_t* track, u_int16_t* totalTracks)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->GetMetadataTrack(track, totalTracks);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" bool MP4SetMetadataDisk(MP4FileHandle hFile,
+ u_int16_t disk, u_int16_t totalDisks)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->SetMetadataDisk(disk, totalDisks);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" bool MP4GetMetadataDisk(MP4FileHandle hFile,
+ u_int16_t* disk, u_int16_t* totalDisks)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->GetMetadataDisk(disk, totalDisks);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" bool MP4SetMetadataGenre(MP4FileHandle hFile, const char *genre)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->SetMetadataGenre(genre);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" bool MP4GetMetadataGenre(MP4FileHandle hFile, char **genre)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->GetMetadataGenre(genre);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" bool MP4SetMetadataTempo(MP4FileHandle hFile, u_int16_t tempo)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->SetMetadataTempo(tempo);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" bool MP4GetMetadataTempo(MP4FileHandle hFile, u_int16_t* tempo)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->GetMetadataTempo(tempo);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" bool MP4SetMetadataCompilation(MP4FileHandle hFile, u_int8_t cpl)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->SetMetadataCompilation(cpl);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" bool MP4GetMetadataCompilation(MP4FileHandle hFile, u_int8_t* cpl)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->GetMetadataCompilation(cpl);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" bool MP4SetMetadataCoverArt(MP4FileHandle hFile,
+ u_int8_t *coverArt, u_int32_t size)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->SetMetadataCoverArt(coverArt, size);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" bool MP4GetMetadataCoverArt(MP4FileHandle hFile,
+ u_int8_t **coverArt, u_int32_t* size)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->GetMetadataCoverArt(coverArt, size);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" bool MP4SetMetadataFreeForm(MP4FileHandle hFile, char *name,
+ u_int8_t* pValue, u_int32_t valueSize)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->SetMetadataFreeForm(name, pValue, valueSize);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
+
+extern "C" bool MP4GetMetadataFreeForm(MP4FileHandle hFile, char *name,
+ u_int8_t** pValue, u_int32_t* valueSize)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->GetMetadataFreeForm(name, pValue, valueSize);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return false;
+}
--- /dev/null
+++ b/common/mp4v2/mp4.h
@@ -1,0 +1,1146 @@
+/*
+ * 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 - 2004. All Rights Reserved.
+ *
+ * 3GPP features implementation is based on 3GPP's TS26.234-v5.60,
+ * and was contributed by Ximpo Group Ltd.
+ *
+ * Portions created by Ximpo Group Ltd. are
+ * Copyright (C) Ximpo Group Ltd. 2003, 2004. All Rights Reserved.
+ *
+ * Contributor(s):
+ * Dave Mackie dmackie@cisco.com
+ * Alix Marchandise-Franquet alix@cisco.com
+ * Ximpo Group Ltd. mp4v2@ximpo.com
+ */
+
+#ifndef __MP4_INCLUDED__
+#define __MP4_INCLUDED__
+
+/* include system and project specific headers */
+#include "mpeg4ip.h"
+
+#include <math.h> /* to define float HUGE_VAL and/or NAN */
+#ifndef NAN
+#define NAN HUGE_VAL
+#endif
+
+#ifdef __cplusplus
+/* exploit C++ ability of default values for function parameters */
+#define DEFAULT(x) =x
+#else
+#define DEFAULT(x)
+#endif
+
+/* MP4 API types */
+typedef void* MP4FileHandle;
+typedef u_int32_t MP4TrackId;
+typedef u_int32_t MP4SampleId;
+typedef u_int64_t MP4Timestamp;
+typedef u_int64_t MP4Duration;
+typedef u_int32_t MP4EditId;
+
+/* Invalid values for API types */
+#define MP4_INVALID_FILE_HANDLE ((MP4FileHandle)NULL)
+#define MP4_INVALID_TRACK_ID ((MP4TrackId)0)
+#define MP4_INVALID_SAMPLE_ID ((MP4SampleId)0)
+#define MP4_INVALID_TIMESTAMP ((MP4Timestamp)-1)
+#define MP4_INVALID_DURATION ((MP4Duration)-1)
+#define MP4_INVALID_EDIT_ID ((MP4EditId)0)
+
+/* Macros to test for API type validity */
+#define MP4_IS_VALID_FILE_HANDLE(x) ((x) != MP4_INVALID_FILE_HANDLE)
+#define MP4_IS_VALID_TRACK_ID(x) ((x) != MP4_INVALID_TRACK_ID)
+#define MP4_IS_VALID_SAMPLE_ID(x) ((x) != MP4_INVALID_SAMPLE_ID)
+#define MP4_IS_VALID_TIMESTAMP(x) ((x) != MP4_INVALID_TIMESTAMP)
+#define MP4_IS_VALID_DURATION(x) ((x) != MP4_INVALID_DURATION)
+#define MP4_IS_VALID_EDIT_ID(x) ((x) != MP4_INVALID_EDIT_ID)
+
+/* MP4 verbosity levels - e.g. MP4SetVerbosity() */
+#define MP4_DETAILS_ALL 0xFFFFFFFF
+#define MP4_DETAILS_ERROR 0x00000001
+#define MP4_DETAILS_WARNING 0x00000002
+#define MP4_DETAILS_READ 0x00000004
+#define MP4_DETAILS_WRITE 0x00000008
+#define MP4_DETAILS_FIND 0x00000010
+#define MP4_DETAILS_TABLE 0x00000020
+#define MP4_DETAILS_SAMPLE 0x00000040
+#define MP4_DETAILS_HINT 0x00000080
+#define MP4_DETAILS_ISMA 0x00000100
+#define MP4_DETAILS_EDIT 0x00000200
+
+#define MP4_DETAILS_READ_ALL \
+ (MP4_DETAILS_READ | MP4_DETAILS_TABLE | MP4_DETAILS_SAMPLE)
+#define MP4_DETAILS_WRITE_ALL \
+ (MP4_DETAILS_WRITE | MP4_DETAILS_TABLE | MP4_DETAILS_SAMPLE)
+
+/*
+ * MP4 Known track type names - e.g. MP4GetNumberOfTracks(type)
+ *
+ * Note this first group of track types should be created
+ * via the MP4Add<Type>Track() functions, and not MP4AddTrack(type)
+ */
+#define MP4_OD_TRACK_TYPE "odsm"
+#define MP4_SCENE_TRACK_TYPE "sdsm"
+#define MP4_AUDIO_TRACK_TYPE "soun"
+#define MP4_VIDEO_TRACK_TYPE "vide"
+#define MP4_HINT_TRACK_TYPE "hint"
+/*
+ * This second set of track types should be created
+ * via MP4AddSystemsTrack(type)
+ */
+#define MP4_CLOCK_TRACK_TYPE "crsm"
+#define MP4_MPEG7_TRACK_TYPE "m7sm"
+#define MP4_OCI_TRACK_TYPE "ocsm"
+#define MP4_IPMP_TRACK_TYPE "ipsm"
+#define MP4_MPEGJ_TRACK_TYPE "mjsm"
+
+#define MP4_IS_VIDEO_TRACK_TYPE(type) \
+ (!strcasecmp(type, MP4_VIDEO_TRACK_TYPE))
+
+#define MP4_IS_AUDIO_TRACK_TYPE(type) \
+ (!strcasecmp(type, MP4_AUDIO_TRACK_TYPE))
+
+#define MP4_IS_OD_TRACK_TYPE(type) \
+ (!strcasecmp(type, MP4_OD_TRACK_TYPE))
+
+#define MP4_IS_SCENE_TRACK_TYPE(type) \
+ (!strcasecmp(type, MP4_SCENE_TRACK_TYPE))
+
+#define MP4_IS_HINT_TRACK_TYPE(type) \
+ (!strcasecmp(type, MP4_HINT_TRACK_TYPE))
+
+#define MP4_IS_SYSTEMS_TRACK_TYPE(type) \
+ (!strcasecmp(type, MP4_CLOCK_TRACK_TYPE) \
+ || !strcasecmp(type, MP4_MPEG7_TRACK_TYPE) \
+ || !strcasecmp(type, MP4_OCI_TRACK_TYPE) \
+ || !strcasecmp(type, MP4_IPMP_TRACK_TYPE) \
+ || !strcasecmp(type, MP4_MPEGJ_TRACK_TYPE))
+
+/* MP4 Audio track types - see MP4AddAudioTrack()*/
+#define MP4_INVALID_AUDIO_TYPE 0x00
+#define MP4_MPEG1_AUDIO_TYPE 0x6B
+#define MP4_MPEG2_AUDIO_TYPE 0x69
+#define MP4_MP3_AUDIO_TYPE MP4_MPEG2_AUDIO_TYPE
+#define MP4_MPEG2_AAC_MAIN_AUDIO_TYPE 0x66
+#define MP4_MPEG2_AAC_LC_AUDIO_TYPE 0x67
+#define MP4_MPEG2_AAC_SSR_AUDIO_TYPE 0x68
+#define MP4_MPEG2_AAC_AUDIO_TYPE MP4_MPEG2_AAC_MAIN_AUDIO_TYPE
+#define MP4_MPEG4_AUDIO_TYPE 0x40
+#define MP4_PRIVATE_AUDIO_TYPE 0xC0
+#define MP4_PCM16_LITTLE_ENDIAN_AUDIO_TYPE 0xE0 /* a private definition */
+#define MP4_VORBIS_AUDIO_TYPE 0xE1 /* a private definition */
+#define MP4_AC3_AUDIO_TYPE 0xE2 /* a private definition */
+#define MP4_ALAW_AUDIO_TYPE 0xE3 /* a private definition */
+#define MP4_ULAW_AUDIO_TYPE 0xE4 /* a private definition */
+#define MP4_G723_AUDIO_TYPE 0xE5 /* a private definition */
+#define MP4_PCM16_BIG_ENDIAN_AUDIO_TYPE 0xE6 /* a private definition */
+
+/* MP4 MPEG-4 Audio types from 14496-3 Table 1.5.1 */
+#define MP4_MPEG4_INVALID_AUDIO_TYPE 0
+#define MP4_MPEG4_AAC_MAIN_AUDIO_TYPE 1
+#define MP4_MPEG4_AAC_LC_AUDIO_TYPE 2
+#define MP4_MPEG4_AAC_SSR_AUDIO_TYPE 3
+#define MP4_MPEG4_AAC_LTP_AUDIO_TYPE 4
+#define MP4_MPEG4_AAC_SCALABLE_AUDIO_TYPE 6
+#define MP4_MPEG4_CELP_AUDIO_TYPE 8
+#define MP4_MPEG4_HVXC_AUDIO_TYPE 9
+#define MP4_MPEG4_TTSI_AUDIO_TYPE 12
+#define MP4_MPEG4_MAIN_SYNTHETIC_AUDIO_TYPE 13
+#define MP4_MPEG4_WAVETABLE_AUDIO_TYPE 14
+#define MP4_MPEG4_MIDI_AUDIO_TYPE 15
+#define MP4_MPEG4_ALGORITHMIC_FX_AUDIO_TYPE 16
+
+/* MP4 Audio type utilities following common usage */
+#define MP4_IS_MP3_AUDIO_TYPE(type) \
+ ((type) == MP4_MPEG1_AUDIO_TYPE || (type) == MP4_MPEG2_AUDIO_TYPE)
+
+#define MP4_IS_MPEG2_AAC_AUDIO_TYPE(type) \
+ (((type) >= MP4_MPEG2_AAC_MAIN_AUDIO_TYPE \
+ && (type) <= MP4_MPEG2_AAC_SSR_AUDIO_TYPE))
+
+#define MP4_IS_MPEG4_AAC_AUDIO_TYPE(mpeg4Type) \
+ (((mpeg4Type) >= MP4_MPEG4_AAC_MAIN_AUDIO_TYPE \
+ && (mpeg4Type) <= MP4_MPEG4_AAC_LTP_AUDIO_TYPE) \
+ || (mpeg4Type) == MP4_MPEG4_AAC_SCALABLE_AUDIO_TYPE \
+ || (mpeg4Type) == 17)
+
+#define MP4_IS_AAC_AUDIO_TYPE(type) \
+ (MP4_IS_MPEG2_AAC_AUDIO_TYPE(type) \
+ || (type) == MP4_MPEG4_AUDIO_TYPE)
+
+/* MP4 Video track types - see MP4AddVideoTrack() */
+#define MP4_INVALID_VIDEO_TYPE 0x00
+#define MP4_MPEG1_VIDEO_TYPE 0x6A
+#define MP4_MPEG2_SIMPLE_VIDEO_TYPE 0x60
+#define MP4_MPEG2_MAIN_VIDEO_TYPE 0x61
+#define MP4_MPEG2_SNR_VIDEO_TYPE 0x62
+#define MP4_MPEG2_SPATIAL_VIDEO_TYPE 0x63
+#define MP4_MPEG2_HIGH_VIDEO_TYPE 0x64
+#define MP4_MPEG2_442_VIDEO_TYPE 0x65
+#define MP4_MPEG2_VIDEO_TYPE MP4_MPEG2_MAIN_VIDEO_TYPE
+#define MP4_MPEG4_VIDEO_TYPE 0x20
+#define MP4_JPEG_VIDEO_TYPE 0x6C
+#define MP4_PRIVATE_VIDEO_TYPE 0xD0
+#define MP4_YUV12_VIDEO_TYPE 0xF0 /* a private definition */
+#define MP4_H264_VIDEO_TYPE 0xF1 /* a private definition */
+#define MP4_H263_VIDEO_TYPE 0xF2 /* a private definition */
+#define MP4_H261_VIDEO_TYPE 0xF3 /* a private definition */
+
+/* MP4 Video type utilities */
+#define MP4_IS_MPEG1_VIDEO_TYPE(type) \
+ ((type) == MP4_MPEG1_VIDEO_TYPE)
+
+#define MP4_IS_MPEG2_VIDEO_TYPE(type) \
+ (((type) >= MP4_MPEG2_SIMPLE_VIDEO_TYPE \
+ && (type) <= MP4_MPEG2_442_VIDEO_TYPE) \
+ || MP4_IS_MPEG1_VIDEO_TYPE(type))
+
+#define MP4_IS_MPEG4_VIDEO_TYPE(type) \
+ ((type) == MP4_MPEG4_VIDEO_TYPE)
+
+/* Mpeg4 Visual Profile Defines - ISO/IEC 14496-2:2001/Amd.2:2002(E) */
+#define MPEG4_SP_L1 (0x1)
+#define MPEG4_SP_L2 (0x2)
+#define MPEG4_SP_L3 (0x3)
+#define MPEG4_SP_L0 (0x8)
+#define MPEG4_SSP_L1 (0x11)
+#define MPEG4_SSP_L2 (0x12)
+#define MPEG4_CP_L1 (0x21)
+#define MPEG4_CP_L2 (0x22)
+#define MPEG4_MP_L2 (0x32)
+#define MPEG4_MP_L3 (0x33)
+#define MPEG4_MP_L4 (0x34)
+#define MPEG4_NBP_L2 (0x42)
+#define MPEG4_STP_L1 (0x51)
+#define MPEG4_SFAP_L1 (0x61)
+#define MPEG4_SFAP_L2 (0x62)
+#define MPEG4_SFBAP_L1 (0x63)
+#define MPEG4_SFBAP_L2 (0x64)
+#define MPEG4_BATP_L1 (0x71)
+#define MPEG4_BATP_L2 (0x72)
+#define MPEG4_HP_L1 (0x81)
+#define MPEG4_HP_L2 (0x82)
+#define MPEG4_ARTSP_L1 (0x91)
+#define MPEG4_ARTSP_L2 (0x92)
+#define MPEG4_ARTSP_L3 (0x93)
+#define MPEG4_ARTSP_L4 (0x94)
+#define MPEG4_CSP_L1 (0xa1)
+#define MPEG4_CSP_L2 (0xa2)
+#define MPEG4_CSP_L3 (0xa3)
+#define MPEG4_ACEP_L1 (0xb1)
+#define MPEG4_ACEP_L2 (0xb2)
+#define MPEG4_ACEP_L3 (0xb3)
+#define MPEG4_ACEP_L4 (0xb4)
+#define MPEG4_ACP_L1 (0xc1)
+#define MPEG4_ACP_L2 (0xc2)
+#define MPEG4_AST_L1 (0xd1)
+#define MPEG4_AST_L2 (0xd2)
+#define MPEG4_AST_L3 (0xd3)
+#define MPEG4_S_STUDIO_P_L1 (0xe1)
+#define MPEG4_S_STUDIO_P_L2 (0xe2)
+#define MPEG4_S_STUDIO_P_L3 (0xe3)
+#define MPEG4_S_STUDIO_P_L4 (0xe4)
+#define MPEG4_C_STUDIO_P_L1 (0xe5)
+#define MPEG4_C_STUDIO_P_L2 (0xe6)
+#define MPEG4_C_STUDIO_P_L3 (0xe7)
+#define MPEG4_C_STUDIO_P_L4 (0xe8)
+#define MPEG4_ASP_L0 (0xF0)
+#define MPEG4_ASP_L1 (0xF1)
+#define MPEG4_ASP_L2 (0xF2)
+#define MPEG4_ASP_L3 (0xF3)
+#define MPEG4_ASP_L4 (0xF4)
+#define MPEG4_ASP_L5 (0xF5)
+#define MPEG4_ASP_L3B (0xF7)
+#define MPEG4_FGSP_L0 (0xf8)
+#define MPEG4_FGSP_L1 (0xf9)
+#define MPEG4_FGSP_L2 (0xfa)
+#define MPEG4_FGSP_L3 (0xfb)
+#define MPEG4_FGSP_L4 (0xfc)
+#define MPEG4_FGSP_L5 (0xfd)
+
+/* MP4 API declarations */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* file operations */
+#define MP4_CREATE_64BIT_DATA (0x01)
+#define MP4_CREATE_64BIT_TIME (0x02) // Quicktime is not compatible with this
+#define MP4_CREATE_64BIT (MP4_CREATE_64BIT_DATA | MP4_CREATE_64BIT_TIME)
+#define MP4_CREATE_EXTENSIBLE_FORMAT (0x04)
+
+MP4FileHandle MP4Create(
+ const char* fileName,
+ u_int32_t verbosity DEFAULT(0),
+ u_int32_t flags DEFAULT(0));
+
+MP4FileHandle MP4CreateEx(
+ const char* fileName,
+ u_int32_t verbosity DEFAULT(0),
+ u_int32_t flags DEFAULT(0),
+ char* majorBrand DEFAULT(0),
+ u_int32_t minorVersion DEFAULT(0),
+ char** supportedBrands DEFAULT(0),
+ u_int32_t supportedBrandsCount DEFAULT(0));
+
+MP4FileHandle MP4Modify(
+ const char* fileName,
+ u_int32_t verbosity DEFAULT(0),
+ u_int32_t flags DEFAULT(0));
+
+MP4FileHandle MP4Read(
+ const char* fileName,
+ u_int32_t verbosity DEFAULT(0));
+
+bool MP4Close(
+ MP4FileHandle hFile);
+
+bool MP4Optimize(
+ const char* existingFileName,
+ const char* newFileName DEFAULT(NULL),
+ u_int32_t verbosity DEFAULT(0));
+
+bool MP4Dump(
+ MP4FileHandle hFile,
+ FILE* pDumpFile DEFAULT(NULL),
+ bool dumpImplicits DEFAULT(0));
+
+char* MP4Info(
+ MP4FileHandle hFile,
+ MP4TrackId trackId DEFAULT(MP4_INVALID_TRACK_ID));
+
+char* MP4FileInfo(
+ const char* fileName,
+ MP4TrackId trackId DEFAULT(MP4_INVALID_TRACK_ID));
+
+/* file properties */
+
+/* specific file properties */
+
+u_int32_t MP4GetVerbosity(MP4FileHandle hFile);
+
+bool MP4SetVerbosity(MP4FileHandle hFile, u_int32_t verbosity);
+
+MP4Duration MP4GetDuration(MP4FileHandle hFile);
+
+u_int32_t MP4GetTimeScale(MP4FileHandle hFile);
+
+bool MP4SetTimeScale(MP4FileHandle hFile, u_int32_t value);
+
+u_int8_t MP4GetODProfileLevel(MP4FileHandle hFile);
+
+bool MP4SetODProfileLevel(MP4FileHandle hFile, u_int8_t value);
+
+u_int8_t MP4GetSceneProfileLevel(MP4FileHandle hFile);
+
+bool MP4SetSceneProfileLevel(MP4FileHandle hFile, u_int8_t value);
+
+u_int8_t MP4GetVideoProfileLevel(MP4FileHandle hFile);
+
+bool MP4SetVideoProfileLevel(MP4FileHandle hFile, u_int8_t value);
+
+u_int8_t MP4GetAudioProfileLevel(MP4FileHandle hFile);
+
+bool MP4SetAudioProfileLevel(MP4FileHandle hFile, u_int8_t value);
+
+u_int8_t MP4GetGraphicsProfileLevel(MP4FileHandle hFile);
+
+bool MP4SetGraphicsProfileLevel(MP4FileHandle hFile, u_int8_t value);
+
+/* generic file properties */
+
+u_int64_t MP4GetIntegerProperty(
+ MP4FileHandle hFile,
+ const char* propName);
+
+bool MP4HaveTrackIntegerProperty(
+ MP4FileHandle hFile, MP4TrackId trackId,
+ const char* propName);
+
+float MP4GetFloatProperty(
+ MP4FileHandle hFile,
+ const char* propName);
+
+const char* MP4GetStringProperty(
+ MP4FileHandle hFile,
+ const char* propName);
+
+void MP4GetBytesProperty(
+ MP4FileHandle hFile,
+ const char* propName,
+ u_int8_t** ppValue,
+ u_int32_t* pValueSize);
+
+bool MP4SetIntegerProperty(
+ MP4FileHandle hFile,
+ const char* propName,
+ int64_t value);
+
+bool MP4SetFloatProperty(
+ MP4FileHandle hFile,
+ const char* propName,
+ float value);
+
+bool MP4SetStringProperty(
+ MP4FileHandle hFile, const char* propName, const char* value);
+
+bool MP4SetBytesProperty(
+ MP4FileHandle hFile, const char* propName,
+ const u_int8_t* pValue, u_int32_t valueSize);
+
+/* track operations */
+
+MP4TrackId MP4AddTrack(
+ MP4FileHandle hFile,
+ const char* type);
+
+MP4TrackId MP4AddSystemsTrack(
+ MP4FileHandle hFile,
+ const char* type);
+
+MP4TrackId MP4AddODTrack(
+ MP4FileHandle hFile);
+
+MP4TrackId MP4AddSceneTrack(
+ MP4FileHandle hFile);
+
+MP4TrackId MP4AddAudioTrack(
+ MP4FileHandle hFile,
+ u_int32_t timeScale,
+ MP4Duration sampleDuration,
+ u_int8_t audioType DEFAULT(MP4_MPEG4_AUDIO_TYPE));
+
+typedef struct mp4v2_ismacryp_session_params {
+ u_int32_t scheme_type;
+ u_int16_t scheme_version;
+ u_int8_t key_ind_len;
+ u_int8_t iv_len;
+ u_int8_t selective_enc;
+ char *kms_uri;
+} mp4v2_ismacrypParams;
+
+
+MP4TrackId MP4AddEncAudioTrack(
+ MP4FileHandle hFile,
+ u_int32_t timeScale,
+ MP4Duration sampleDuration,
+ mp4v2_ismacrypParams *icPp,
+ u_int8_t audioType DEFAULT(MP4_MPEG4_AUDIO_TYPE));
+MP4TrackId MP4AddAmrAudioTrack(
+ MP4FileHandle hFile,
+ u_int32_t timeScale,
+ u_int16_t modeSet,
+ u_int8_t modeChangePeriod,
+ u_int8_t framesPerSample,
+ bool isAmrWB);
+
+void MP4SetAmrVendor(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ u_int32_t vendor);
+
+void MP4SetAmrDecoderVersion(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ u_int8_t decoderVersion);
+
+void MP4SetAmrModeSet(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ u_int16_t modeSet);
+
+MP4TrackId MP4AddVideoTrack(
+ MP4FileHandle hFile,
+ u_int32_t timeScale,
+ MP4Duration sampleDuration,
+ u_int16_t width,
+ u_int16_t height,
+ u_int8_t videoType DEFAULT(MP4_MPEG4_VIDEO_TYPE));
+
+MP4TrackId MP4AddEncVideoTrack(
+ MP4FileHandle hFile,
+ u_int32_t timeScale,
+ MP4Duration sampleDuration,
+ u_int16_t width,
+ u_int16_t height,
+ mp4v2_ismacrypParams *icPp,
+ u_int8_t videoType DEFAULT(MP4_MPEG4_VIDEO_TYPE));
+
+void MP4SetH263Vendor(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ u_int32_t vendor);
+
+void MP4SetH263DecoderVersion(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ u_int8_t decoderVersion);
+
+void MP4SetH263Bitrates(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ u_int32_t avgBitrate,
+ u_int32_t maxBitrate);
+
+MP4TrackId MP4AddH263VideoTrack(
+ MP4FileHandle hFile,
+ u_int32_t timeScale,
+ MP4Duration sampleDuration,
+ u_int16_t width,
+ u_int16_t height,
+ u_int8_t h263Level,
+ u_int8_t h263Profile,
+ u_int32_t avgBitrate,
+ u_int32_t maxBitrate);
+
+MP4TrackId MP4AddHintTrack(
+ MP4FileHandle hFile,
+ MP4TrackId refTrackId);
+
+MP4TrackId MP4CloneTrack(
+ MP4FileHandle srcFile,
+ MP4TrackId srcTrackId,
+ MP4FileHandle dstFile DEFAULT(MP4_INVALID_FILE_HANDLE),
+ MP4TrackId dstHintTrackReferenceTrack DEFAULT(MP4_INVALID_TRACK_ID));
+
+MP4TrackId MP4EncAndCloneTrack(
+ MP4FileHandle srcFile,
+ MP4TrackId srcTrackId,
+ mp4v2_ismacrypParams *icPp,
+ MP4FileHandle dstFile DEFAULT(MP4_INVALID_FILE_HANDLE),
+ MP4TrackId dstHintTrackReferenceTrack DEFAULT(MP4_INVALID_TRACK_ID));
+
+MP4TrackId MP4CopyTrack(
+ MP4FileHandle srcFile,
+ MP4TrackId srcTrackId,
+ MP4FileHandle dstFile DEFAULT(MP4_INVALID_FILE_HANDLE),
+ bool applyEdits DEFAULT(false),
+ MP4TrackId dstHintTrackReferenceTrack DEFAULT(MP4_INVALID_TRACK_ID));
+
+typedef u_int32_t (*encryptFunc_t)(u_int32_t, u_int32_t, u_int8_t*, u_int32_t*, u_int8_t **);
+
+MP4TrackId MP4EncAndCopyTrack(
+ MP4FileHandle srcFile,
+ MP4TrackId srcTrackId,
+ mp4v2_ismacrypParams *icPp,
+ encryptFunc_t encfcnp,
+ u_int32_t encfcnparam1,
+ MP4FileHandle dstFile DEFAULT(MP4_INVALID_FILE_HANDLE),
+ bool applyEdits DEFAULT(false),
+ MP4TrackId dstHintTrackReferenceTrack DEFAULT(MP4_INVALID_TRACK_ID));
+
+bool MP4DeleteTrack(
+ MP4FileHandle hFile,
+ MP4TrackId trackId);
+
+u_int32_t MP4GetNumberOfTracks(
+ MP4FileHandle hFile,
+ const char* type DEFAULT(NULL),
+ u_int8_t subType DEFAULT(0));
+
+MP4TrackId MP4FindTrackId(
+ MP4FileHandle hFile,
+ u_int16_t index,
+ const char* type DEFAULT(NULL),
+ u_int8_t subType DEFAULT(0));
+
+u_int16_t MP4FindTrackIndex(
+ MP4FileHandle hFile,
+ MP4TrackId trackId);
+
+/* track properties */
+
+/* specific track properties */
+
+const char* MP4GetTrackType(
+ MP4FileHandle hFile,
+ MP4TrackId trackId);
+
+MP4Duration MP4GetTrackDuration(
+ MP4FileHandle hFile,
+ MP4TrackId trackId);
+
+u_int32_t MP4GetTrackTimeScale(
+ MP4FileHandle hFile,
+ MP4TrackId trackId);
+
+bool MP4SetTrackTimeScale(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ u_int32_t value);
+
+// Should not be used, replace with MP4GetTrackEsdsObjectTypeId
+u_int8_t MP4GetTrackAudioType(
+ MP4FileHandle hFile,
+ MP4TrackId trackId);
+
+u_int8_t MP4GetTrackAudioMpeg4Type(
+ MP4FileHandle hFile,
+ MP4TrackId trackId);
+
+// Should not be used, replace with MP4GetTrackEsdsObjectTypeId
+u_int8_t MP4GetTrackVideoType(
+ MP4FileHandle hFile,
+ MP4TrackId trackId);
+
+u_int8_t MP4GetTrackEsdsObjectTypeId(
+ MP4FileHandle hFile,
+ MP4TrackId trackId);
+
+/* returns MP4_INVALID_DURATION if track samples do not have a fixed duration */
+MP4Duration MP4GetTrackFixedSampleDuration(
+ MP4FileHandle hFile,
+ MP4TrackId trackId);
+
+u_int32_t MP4GetTrackBitRate(
+ MP4FileHandle hFile,
+ MP4TrackId trackId);
+
+bool MP4GetTrackESConfiguration(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ u_int8_t** ppConfig,
+ u_int32_t* pConfigSize);
+
+bool MP4SetTrackESConfiguration(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ const u_int8_t* pConfig,
+ u_int32_t configSize);
+
+MP4SampleId MP4GetTrackNumberOfSamples(
+ MP4FileHandle hFile,
+ MP4TrackId trackId);
+
+u_int16_t MP4GetTrackVideoWidth(
+ MP4FileHandle hFile,
+ MP4TrackId trackId);
+
+u_int16_t MP4GetTrackVideoHeight(
+ MP4FileHandle hFile,
+ MP4TrackId trackId);
+
+float MP4GetTrackVideoFrameRate(
+ MP4FileHandle hFile,
+ MP4TrackId trackId);
+
+bool MP4IsIsmaCrypMediaTrack(
+ MP4FileHandle hFile,
+ MP4TrackId trackId);
+
+/* generic track properties */
+
+u_int64_t MP4GetTrackIntegerProperty(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ const char* propName);
+
+float MP4GetTrackFloatProperty(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ const char* propName);
+
+const char* MP4GetTrackStringProperty(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ const char* propName);
+
+void MP4GetTrackBytesProperty(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ const char* propName,
+ u_int8_t** ppValue,
+ u_int32_t* pValueSize);
+
+bool MP4SetTrackIntegerProperty(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ const char* propName,
+ int64_t value);
+
+bool MP4SetTrackFloatProperty(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ const char* propName,
+ float value);
+
+bool MP4SetTrackStringProperty(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ const char* propName,
+ const char* value);
+
+bool MP4SetTrackBytesProperty(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ const char* propName,
+ const u_int8_t* pValue,
+ u_int32_t valueSize);
+
+/* sample operations */
+
+bool MP4ReadSample(
+ /* input parameters */
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ MP4SampleId sampleId,
+ /* input/output parameters */
+ u_int8_t** ppBytes,
+ u_int32_t* pNumBytes,
+ /* output parameters */
+ MP4Timestamp* pStartTime DEFAULT(NULL),
+ MP4Duration* pDuration DEFAULT(NULL),
+ MP4Duration* pRenderingOffset DEFAULT(NULL),
+ bool* pIsSyncSample DEFAULT(NULL));
+
+/* uses (unedited) time to specify sample instead of sample id */
+bool MP4ReadSampleFromTime(
+ /* input parameters */
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ MP4Timestamp when,
+ /* input/output parameters */
+ u_int8_t** ppBytes,
+ u_int32_t* pNumBytes,
+ /* output parameters */
+ MP4Timestamp* pStartTime DEFAULT(NULL),
+ MP4Duration* pDuration DEFAULT(NULL),
+ MP4Duration* pRenderingOffset DEFAULT(NULL),
+ bool* pIsSyncSample DEFAULT(NULL));
+
+bool MP4WriteSample(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ const u_int8_t* pBytes,
+ u_int32_t numBytes,
+ MP4Duration duration DEFAULT(MP4_INVALID_DURATION),
+ MP4Duration renderingOffset DEFAULT(0),
+ bool isSyncSample DEFAULT(true));
+
+bool MP4CopySample(
+ MP4FileHandle srcFile,
+ MP4TrackId srcTrackId,
+ MP4SampleId srcSampleId,
+ MP4FileHandle dstFile DEFAULT(MP4_INVALID_FILE_HANDLE),
+ MP4TrackId dstTrackId DEFAULT(MP4_INVALID_TRACK_ID),
+ MP4Duration dstSampleDuration DEFAULT(MP4_INVALID_DURATION));
+
+bool MP4EncAndCopySample(
+ MP4FileHandle srcFile,
+ MP4TrackId srcTrackId,
+ MP4SampleId srcSampleId,
+ encryptFunc_t encfcnp,
+ u_int32_t encfcnparam1,
+ MP4FileHandle dstFile DEFAULT(MP4_INVALID_FILE_HANDLE),
+ MP4TrackId dstTrackId DEFAULT(MP4_INVALID_TRACK_ID),
+ MP4Duration dstSampleDuration DEFAULT(MP4_INVALID_DURATION));
+
+/* Note this function is not yet implemented */
+bool MP4ReferenceSample(
+ MP4FileHandle srcFile,
+ MP4TrackId srcTrackId,
+ MP4SampleId srcSampleId,
+ MP4FileHandle dstFile,
+ MP4TrackId dstTrackId,
+ MP4Duration dstSampleDuration DEFAULT(MP4_INVALID_DURATION));
+
+u_int32_t MP4GetSampleSize(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ MP4SampleId sampleId);
+
+u_int32_t MP4GetTrackMaxSampleSize(
+ MP4FileHandle hFile,
+ MP4TrackId trackId);
+
+MP4SampleId MP4GetSampleIdFromTime(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ MP4Timestamp when,
+ bool wantSyncSample DEFAULT(false));
+
+MP4Timestamp MP4GetSampleTime(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ MP4SampleId sampleId);
+
+MP4Duration MP4GetSampleDuration(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ MP4SampleId sampleId);
+
+MP4Duration MP4GetSampleRenderingOffset(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ MP4SampleId sampleId);
+
+bool MP4SetSampleRenderingOffset(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ MP4SampleId sampleId,
+ MP4Duration renderingOffset);
+
+int8_t MP4GetSampleSync(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ MP4SampleId sampleId);
+
+/* rtp hint track operations */
+
+bool MP4GetHintTrackRtpPayload(
+ MP4FileHandle hFile,
+ MP4TrackId hintTrackId,
+ char** ppPayloadName DEFAULT(NULL),
+ u_int8_t* pPayloadNumber DEFAULT(NULL),
+ u_int16_t* pMaxPayloadSize DEFAULT(NULL),
+ char **ppEncodingParams DEFAULT(NULL));
+
+#define MP4_SET_DYNAMIC_PAYLOAD 0xff
+
+bool MP4SetHintTrackRtpPayload(
+ MP4FileHandle hFile,
+ MP4TrackId hintTrackId,
+ const char* pPayloadName,
+ u_int8_t* pPayloadNumber,
+ u_int16_t maxPayloadSize DEFAULT(0),
+ const char *encode_params DEFAULT(NULL),
+ bool include_rtp_map DEFAULT(true),
+ bool include_mpeg4_esid DEFAULT(true));
+
+const char* MP4GetSessionSdp(
+ MP4FileHandle hFile);
+
+bool MP4SetSessionSdp(
+ MP4FileHandle hFile,
+ const char* sdpString);
+
+bool MP4AppendSessionSdp(
+ MP4FileHandle hFile,
+ const char* sdpString);
+
+const char* MP4GetHintTrackSdp(
+ MP4FileHandle hFile,
+ MP4TrackId hintTrackId);
+
+bool MP4SetHintTrackSdp(
+ MP4FileHandle hFile,
+ MP4TrackId hintTrackId,
+ const char* sdpString);
+
+bool MP4AppendHintTrackSdp(
+ MP4FileHandle hFile,
+ MP4TrackId hintTrackId,
+ const char* sdpString);
+
+MP4TrackId MP4GetHintTrackReferenceTrackId(
+ MP4FileHandle hFile,
+ MP4TrackId hintTrackId);
+
+bool MP4ReadRtpHint(
+ MP4FileHandle hFile,
+ MP4TrackId hintTrackId,
+ MP4SampleId hintSampleId,
+ u_int16_t* pNumPackets DEFAULT(NULL));
+
+u_int16_t MP4GetRtpHintNumberOfPackets(
+ MP4FileHandle hFile,
+ MP4TrackId hintTrackId);
+
+int8_t MP4GetRtpPacketBFrame(
+ MP4FileHandle hFile,
+ MP4TrackId hintTrackId,
+ u_int16_t packetIndex);
+
+int32_t MP4GetRtpPacketTransmitOffset(
+ MP4FileHandle hFile,
+ MP4TrackId hintTrackId,
+ u_int16_t packetIndex);
+
+bool MP4ReadRtpPacket(
+ MP4FileHandle hFile,
+ MP4TrackId hintTrackId,
+ u_int16_t packetIndex,
+ u_int8_t** ppBytes,
+ u_int32_t* pNumBytes,
+ u_int32_t ssrc DEFAULT(0),
+ bool includeHeader DEFAULT(true),
+ bool includePayload DEFAULT(true));
+
+MP4Timestamp MP4GetRtpTimestampStart(
+ MP4FileHandle hFile,
+ MP4TrackId hintTrackId);
+
+bool MP4SetRtpTimestampStart(
+ MP4FileHandle hFile,
+ MP4TrackId hintTrackId,
+ MP4Timestamp rtpStart);
+
+bool MP4AddRtpHint(
+ MP4FileHandle hFile,
+ MP4TrackId hintTrackId);
+
+bool MP4AddRtpVideoHint(
+ MP4FileHandle hFile,
+ MP4TrackId hintTrackId,
+ bool isBframe DEFAULT(false),
+ u_int32_t timestampOffset DEFAULT(0));
+
+bool MP4AddRtpPacket(
+ MP4FileHandle hFile,
+ MP4TrackId hintTrackId,
+ bool setMbit DEFAULT(false),
+ int32_t transmitOffset DEFAULT(0));
+
+bool MP4AddRtpImmediateData(
+ MP4FileHandle hFile,
+ MP4TrackId hintTrackId,
+ const u_int8_t* pBytes,
+ u_int32_t numBytes);
+
+bool MP4AddRtpSampleData(
+ MP4FileHandle hFile,
+ MP4TrackId hintTrackId,
+ MP4SampleId sampleId,
+ u_int32_t dataOffset,
+ u_int32_t dataLength);
+
+bool MP4AddRtpESConfigurationPacket(
+ MP4FileHandle hFile,
+ MP4TrackId hintTrackId);
+
+bool MP4WriteRtpHint(
+ MP4FileHandle hFile,
+ MP4TrackId hintTrackId,
+ MP4Duration duration,
+ bool isSyncSample DEFAULT(true));
+
+/* 3GP specific utilities */
+
+bool MP4Make3GPCompliant(
+ const char* fileName,
+ u_int32_t verbosity DEFAULT(0),
+ char* majorBrand DEFAULT(0),
+ u_int32_t minorVersion DEFAULT(0),
+ char** supportedBrands DEFAULT(NULL),
+ u_int32_t supportedBrandsCount DEFAULT(0),
+ bool deleteIodsAtom DEFAULT(true));
+
+/* ISMA specific utilities */
+
+bool MP4MakeIsmaCompliant(const char* fileName,
+ u_int32_t verbosity DEFAULT(0),
+ bool addIsmaComplianceSdp DEFAULT(true));
+
+char* MP4MakeIsmaSdpIod(
+ 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_int32_t verbosity DEFAULT(0));
+
+/* edit list */
+
+/* NOTE this section of functionality
+ * has not yet been fully tested
+ */
+
+MP4EditId MP4AddTrackEdit(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ MP4EditId editId DEFAULT(MP4_INVALID_EDIT_ID),
+ MP4Timestamp startTime DEFAULT(0),
+ MP4Duration duration DEFAULT(0),
+ bool dwell DEFAULT(false));
+
+bool MP4DeleteTrackEdit(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ MP4EditId editId);
+
+u_int32_t MP4GetTrackNumberOfEdits(
+ MP4FileHandle hFile,
+ MP4TrackId trackId);
+
+MP4Timestamp MP4GetTrackEditStart(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ MP4EditId editId);
+
+MP4Duration MP4GetTrackEditTotalDuration(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ MP4EditId editId DEFAULT(MP4_INVALID_EDIT_ID));
+
+MP4Timestamp MP4GetTrackEditMediaStart(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ MP4EditId editId);
+
+bool MP4SetTrackEditMediaStart(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ MP4EditId editId,
+ MP4Timestamp startTime);
+
+MP4Duration MP4GetTrackEditDuration(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ MP4EditId editId);
+
+bool MP4SetTrackEditDuration(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ MP4EditId editId,
+ MP4Duration duration);
+
+int8_t MP4GetTrackEditDwell(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ MP4EditId editId);
+
+bool MP4SetTrackEditDwell(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ MP4EditId editId,
+ bool dwell);
+
+bool MP4ReadSampleFromEditTime(
+ /* input parameters */
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ MP4Timestamp when,
+ /* input/output parameters */
+ u_int8_t** ppBytes,
+ u_int32_t* pNumBytes,
+ /* output parameters */
+ MP4Timestamp* pStartTime DEFAULT(NULL),
+ MP4Duration* pDuration DEFAULT(NULL),
+ MP4Duration* pRenderingOffset DEFAULT(NULL),
+ bool* pIsSyncSample DEFAULT(NULL));
+
+MP4SampleId MP4GetSampleIdFromEditTime(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ MP4Timestamp when,
+ MP4Timestamp* pStartTime DEFAULT(NULL),
+ MP4Duration* pDuration DEFAULT(NULL));
+/* iTunes metadata handling */
+bool MP4MetadataDelete(MP4FileHandle hFile);
+bool MP4GetMetadataByIndex(MP4FileHandle hFile, u_int32_t index,
+ const char** ppName,
+ u_int8_t** ppValue, u_int32_t* pValueSize);
+bool MP4SetMetadataName(MP4FileHandle hFile, const char* value);
+bool MP4GetMetadataName(MP4FileHandle hFile, char** value);
+bool MP4SetMetadataArtist(MP4FileHandle hFile, const char* value);
+bool MP4GetMetadataArtist(MP4FileHandle hFile, char** value);
+bool MP4SetMetadataWriter(MP4FileHandle hFile, const char* value);
+bool MP4GetMetadataWriter(MP4FileHandle hFile, char** value);
+bool MP4SetMetadataComment(MP4FileHandle hFile, const char* value);
+bool MP4GetMetadataComment(MP4FileHandle hFile, char** value);
+bool MP4SetMetadataTool(MP4FileHandle hFile, const char* value);
+bool MP4GetMetadataTool(MP4FileHandle hFile, char** value);
+bool MP4SetMetadataYear(MP4FileHandle hFile, const char* value);
+bool MP4GetMetadataYear(MP4FileHandle hFile, char** value);
+bool MP4SetMetadataAlbum(MP4FileHandle hFile, const char* value);
+bool MP4GetMetadataAlbum(MP4FileHandle hFile, char** value);
+bool MP4SetMetadataTrack(MP4FileHandle hFile,
+ u_int16_t track, u_int16_t totalTracks);
+bool MP4GetMetadataTrack(MP4FileHandle hFile,
+ u_int16_t* track, u_int16_t* totalTracks);
+bool MP4SetMetadataDisk(MP4FileHandle hFile,
+ u_int16_t disk, u_int16_t totalDisks);
+bool MP4GetMetadataDisk(MP4FileHandle hFile,
+ u_int16_t* disk, u_int16_t* totalDisks);
+bool MP4SetMetadataGenre(MP4FileHandle hFile, const char *genre);
+bool MP4GetMetadataGenre(MP4FileHandle hFile, char **genre);
+bool MP4SetMetadataTempo(MP4FileHandle hFile, u_int16_t tempo);
+bool MP4GetMetadataTempo(MP4FileHandle hFile, u_int16_t* tempo);
+bool MP4SetMetadataCompilation(MP4FileHandle hFile, u_int8_t cpl);
+bool MP4GetMetadataCompilation(MP4FileHandle hFile, u_int8_t* cpl);
+bool MP4SetMetadataCoverArt(MP4FileHandle hFile,
+ u_int8_t *coverArt, u_int32_t size);
+bool MP4GetMetadataCoverArt(MP4FileHandle hFile,
+ u_int8_t **coverArt, u_int32_t* size);
+bool MP4SetMetadataFreeForm(MP4FileHandle hFile, char *name,
+ u_int8_t* pValue, u_int32_t valueSize);
+bool MP4GetMetadataFreeForm(MP4FileHandle hFile, char *name,
+ u_int8_t** pValue, u_int32_t* valueSize);
+
+
+/* time conversion utilties */
+
+/* predefined values for timeScale parameter below */
+#define MP4_SECONDS_TIME_SCALE 1
+#define MP4_MILLISECONDS_TIME_SCALE 1000
+#define MP4_MICROSECONDS_TIME_SCALE 1000000
+#define MP4_NANOSECONDS_TIME_SCALE 1000000000
+
+#define MP4_SECS_TIME_SCALE MP4_SECONDS_TIME_SCALE
+#define MP4_MSECS_TIME_SCALE MP4_MILLISECONDS_TIME_SCALE
+#define MP4_USECS_TIME_SCALE MP4_MICROSECONDS_TIME_SCALE
+#define MP4_NSECS_TIME_SCALE MP4_NANOSECONDS_TIME_SCALE
+
+u_int64_t MP4ConvertFromMovieDuration(
+ MP4FileHandle hFile,
+ MP4Duration duration,
+ u_int32_t timeScale);
+
+u_int64_t MP4ConvertFromTrackTimestamp(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ MP4Timestamp timeStamp,
+ u_int32_t timeScale);
+
+MP4Timestamp MP4ConvertToTrackTimestamp(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ u_int64_t timeStamp,
+ u_int32_t timeScale);
+
+u_int64_t MP4ConvertFromTrackDuration(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ MP4Duration duration,
+ u_int32_t timeScale);
+
+MP4Duration MP4ConvertToTrackDuration(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ u_int64_t duration,
+ u_int32_t timeScale);
+
+char* MP4BinaryToBase16(
+ const u_int8_t* pData,
+ u_int32_t dataSize);
+
+char* MP4BinaryToBase64(
+ const u_int8_t* pData,
+ u_int32_t dataSize);
+
+#ifdef __cplusplus
+}
+#endif
+
+/* undefined our utlity macro to avoid conflicts */
+#undef DEFAULT
+
+#endif /* __MP4_INCLUDED__ */
--- /dev/null
+++ b/common/mp4v2/mp4array.h
@@ -1,0 +1,130 @@
+/*
+ * 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
+ */
+
+#ifndef __MP4_ARRAY_INCLUDED__
+#define __MP4_ARRAY_INCLUDED__
+
+typedef u_int32_t MP4ArrayIndex;
+
+class MP4Array {
+public:
+ MP4Array() {
+ m_numElements = 0;
+ m_maxNumElements = 0;
+ }
+
+ inline bool ValidIndex(MP4ArrayIndex index) {
+ if (m_numElements == 0 || index > m_numElements - 1) {
+ return false;
+ }
+ return true;
+ }
+
+ inline MP4ArrayIndex Size(void) {
+ return m_numElements;
+ }
+
+ inline MP4ArrayIndex MaxSize(void) {
+ return m_maxNumElements;
+ }
+
+protected:
+ MP4ArrayIndex m_numElements;
+ MP4ArrayIndex m_maxNumElements;
+};
+
+// macro to generate subclasses
+// we use this as an alternative to templates
+// due to the excessive compile time price of extensive template usage
+
+#define MP4ARRAY_DECL(name, type) \
+ class name##Array : public MP4Array { \
+ public: \
+ name##Array() { \
+ m_elements = NULL; \
+ } \
+ \
+ ~name##Array() { \
+ MP4Free(m_elements); \
+ } \
+ \
+ inline void Add(type newElement) { \
+ Insert(newElement, m_numElements); \
+ } \
+ \
+ void Insert(type newElement, MP4ArrayIndex newIndex) { \
+ if (newIndex > m_numElements) { \
+ throw new MP4Error(ERANGE, "MP4Array::Insert"); \
+ } \
+ if (m_numElements == m_maxNumElements) { \
+ m_maxNumElements = MAX(m_maxNumElements, 1) * 2; \
+ m_elements = (type*)MP4Realloc(m_elements, \
+ m_maxNumElements * sizeof(type)); \
+ } \
+ memmove(&m_elements[newIndex + 1], &m_elements[newIndex], \
+ (m_numElements - newIndex) * sizeof(type)); \
+ m_elements[newIndex] = newElement; \
+ m_numElements++; \
+ } \
+ \
+ void Delete(MP4ArrayIndex index) { \
+ if (!ValidIndex(index)) { \
+ throw new MP4Error(ERANGE, "MP4Array::Delete"); \
+ } \
+ memmove(&m_elements[index], &m_elements[index + 1], \
+ (m_numElements - index) * sizeof(type)); \
+ m_numElements--; \
+ } \
+ void Resize(MP4ArrayIndex newSize) { \
+ m_numElements = newSize; \
+ m_maxNumElements = newSize; \
+ m_elements = (type*)MP4Realloc(m_elements, \
+ m_maxNumElements * sizeof(type)); \
+ } \
+ \
+ type& operator[](MP4ArrayIndex index) { \
+ if (!ValidIndex(index)) { \
+ throw new MP4Error(ERANGE, "MP4Array::[]"); \
+ } \
+ return m_elements[index]; \
+ } \
+ \
+ protected: \
+ type* m_elements; \
+ };
+
+MP4ARRAY_DECL(MP4Integer8, u_int8_t)
+
+MP4ARRAY_DECL(MP4Integer16, u_int16_t)
+
+MP4ARRAY_DECL(MP4Integer32, u_int32_t)
+
+MP4ARRAY_DECL(MP4Integer64, u_int64_t)
+
+MP4ARRAY_DECL(MP4Float32, float)
+
+MP4ARRAY_DECL(MP4Float64, double)
+
+MP4ARRAY_DECL(MP4String, char*)
+
+MP4ARRAY_DECL(MP4Bytes, u_int8_t*)
+
+#endif /* __MP4_ARRAY_INCLUDED__ */
--- /dev/null
+++ b/common/mp4v2/mp4atom.cpp
@@ -1,0 +1,927 @@
+/*
+ * 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 - 2004. All Rights Reserved.
+ *
+ * 3GPP features implementation is based on 3GPP's TS26.234-v5.60,
+ * and was contributed by Ximpo Group Ltd.
+ *
+ * Portions created by Ximpo Group Ltd. are
+ * Copyright (C) Ximpo Group Ltd. 2003, 2004. All Rights Reserved.
+ *
+ * Contributor(s):
+ * Dave Mackie dmackie@cisco.com
+ * Alix Marchandise-Franquet alix@cisco.com
+ * Ximpo Group Ltd. mp4v2@ximpo.com
+ */
+
+#include "mp4common.h"
+#include "atoms.h"
+
+MP4AtomInfo::MP4AtomInfo(const char* name, bool mandatory, bool onlyOne)
+{
+ m_name = name;
+ m_mandatory = mandatory;
+ m_onlyOne = onlyOne;
+ m_count = 0;
+}
+
+MP4Atom::MP4Atom(const char* type)
+{
+ SetType(type);
+ m_unknownType = FALSE;
+ m_pFile = NULL;
+ m_start = 0;
+ m_end = 0;
+ m_size = 0;
+ m_pParentAtom = NULL;
+ m_depth = 0xFF;
+}
+
+MP4Atom::~MP4Atom()
+{
+ u_int32_t i;
+
+ for (i = 0; i < m_pProperties.Size(); i++) {
+ delete m_pProperties[i];
+ }
+ for (i = 0; i < m_pChildAtomInfos.Size(); i++) {
+ delete m_pChildAtomInfos[i];
+ }
+ for (i = 0; i < m_pChildAtoms.Size(); i++) {
+ delete m_pChildAtoms[i];
+ }
+}
+
+MP4Atom* MP4Atom::CreateAtom(const char* type)
+{
+ MP4Atom* pAtom = NULL;
+
+ if (type == NULL) {
+ pAtom = new MP4RootAtom();
+ } else {
+ switch((uint8_t)type[0]) {
+ case 'b':
+ if (ATOMID(type) == ATOMID("bitr")) {
+ pAtom = new MP4BitrAtom();
+ }
+ break;
+ case 'c':
+ if (ATOMID(type) == ATOMID("ctts")) {
+ pAtom = new MP4CttsAtom();
+ } else if (ATOMID(type) == ATOMID("co64")) {
+ pAtom = new MP4Co64Atom();
+ } else if (ATOMID(type) == ATOMID("cprt")) {
+ pAtom = new MP4CprtAtom();
+ } else if (ATOMID(type) == ATOMID("cpil")) { /* Apple iTunes */
+ pAtom = new MP4CpilAtom();
+ } else if (ATOMID(type) == ATOMID("covr")) { /* Apple iTunes */
+ pAtom = new MP4CovrAtom();
+ }
+ break;
+ case 'd':
+ if (ATOMID(type) == ATOMID("d263")) {
+ pAtom = new MP4D263Atom();
+ } else if (ATOMID(type) == ATOMID("damr")) {
+ pAtom = new MP4DamrAtom();
+ } else if (ATOMID(type) == ATOMID("dinf")) {
+ pAtom = new MP4DinfAtom();
+ } else if (ATOMID(type) == ATOMID("dref")) {
+ pAtom = new MP4DrefAtom();
+ } else if (ATOMID(type) == ATOMID("dpnd")) {
+ pAtom = new MP4TrefTypeAtom(type);
+ } else if (ATOMID(type) == ATOMID("dmed")) {
+ pAtom = new MP4DmedAtom();
+ } else if (ATOMID(type) == ATOMID("dimm")) {
+ pAtom = new MP4DimmAtom();
+ } else if (ATOMID(type) == ATOMID("drep")) {
+ pAtom = new MP4DrepAtom();
+ } else if (ATOMID(type) == ATOMID("dmax")) {
+ pAtom = new MP4DmaxAtom();
+ } else if (ATOMID(type) == ATOMID("data")) { /* Apple iTunes */
+ pAtom = new MP4DataAtom();
+ } else if (ATOMID(type) == ATOMID("disk")) { /* Apple iTunes */
+ pAtom = new MP4DiskAtom();
+ }
+ break;
+ case 'e':
+ if (ATOMID(type) == ATOMID("esds")) {
+ pAtom = new MP4EsdsAtom();
+ } else if (ATOMID(type) == ATOMID("edts")) {
+ pAtom = new MP4EdtsAtom();
+ } else if (ATOMID(type) == ATOMID("elst")) {
+ pAtom = new MP4ElstAtom();
+ } else if (ATOMID(type) == ATOMID("enca")) {
+ pAtom = new MP4EncaAtom();
+ } else if (ATOMID(type) == ATOMID("encv")) {
+ pAtom = new MP4EncvAtom();
+ }
+ break;
+ case 'f':
+ if (ATOMID(type) == ATOMID("free")) {
+ pAtom = new MP4FreeAtom();
+ } else if (ATOMID(type) == ATOMID("frma")) {
+ pAtom = new MP4FrmaAtom();
+ } else if (ATOMID(type) == ATOMID("ftyp")) {
+ pAtom = new MP4FtypAtom();
+ }
+ break;
+ case 'g':
+ if (ATOMID(type) == ATOMID("gnre")) { // Apple iTunes
+ pAtom = new MP4GnreAtom();
+ }
+ break;
+ case 'h':
+ if (ATOMID(type) == ATOMID("hdlr")) {
+ pAtom = new MP4HdlrAtom();
+ } else if (ATOMID(type) == ATOMID("hmhd")) {
+ pAtom = new MP4HmhdAtom();
+ } else if (ATOMID(type) == ATOMID("hint")) {
+ pAtom = new MP4TrefTypeAtom(type);
+ } else if (ATOMID(type) == ATOMID("hnti")) {
+ pAtom = new MP4HntiAtom();
+ } else if (ATOMID(type) == ATOMID("hinf")) {
+ pAtom = new MP4HinfAtom();
+ }
+ break;
+ case 'i':
+ if (ATOMID(type) == ATOMID("iKMS")) {
+ pAtom = new MP4IKMSAtom();
+ } else if (ATOMID(type) == ATOMID("iSFM")) {
+ pAtom = new MP4ISFMAtom();
+ } else if (ATOMID(type) == ATOMID("iods")) {
+ pAtom = new MP4IodsAtom();
+ } else if (ATOMID(type) == ATOMID("ipir")) {
+ pAtom = new MP4TrefTypeAtom(type);
+ } else if (ATOMID(type) == ATOMID("ilst")) {
+ pAtom = new MP4IlstAtom();
+ }
+ break;
+ case 'm':
+ if (ATOMID(type) == ATOMID("mdia")) {
+ pAtom = new MP4MdiaAtom();
+ } else if (ATOMID(type) == ATOMID("minf")) {
+ pAtom = new MP4MinfAtom();
+ } else if (ATOMID(type) == ATOMID("mdhd")) {
+ pAtom = new MP4MdhdAtom();
+ } else if (ATOMID(type) == ATOMID("mdat")) {
+ pAtom = new MP4MdatAtom();
+ } else if (ATOMID(type) == ATOMID("moov")) {
+ pAtom = new MP4MoovAtom();
+ } else if (ATOMID(type) == ATOMID("mvhd")) {
+ pAtom = new MP4MvhdAtom();
+ } else if (ATOMID(type) == ATOMID("mpod")) {
+ pAtom = new MP4TrefTypeAtom(type);
+ } else if (ATOMID(type) == ATOMID("mp4a")) {
+ pAtom = new MP4Mp4aAtom();
+ } else if (ATOMID(type) == ATOMID("mp4s")) {
+ pAtom = new MP4Mp4sAtom();
+ } else if (ATOMID(type) == ATOMID("mp4v")) {
+ pAtom = new MP4Mp4vAtom();
+ } else if (ATOMID(type) == ATOMID("moof")) {
+ pAtom = new MP4MoofAtom();
+ } else if (ATOMID(type) == ATOMID("mfhd")) {
+ pAtom = new MP4MfhdAtom();
+ } else if (ATOMID(type) == ATOMID("mvex")) {
+ pAtom = new MP4MvexAtom();
+ } else if (ATOMID(type) == ATOMID("maxr")) {
+ pAtom = new MP4MaxrAtom();
+ } else if (ATOMID(type) == ATOMID("meta")) { // iTunes
+ pAtom = new MP4MetaAtom();
+ } else if (ATOMID(type) == ATOMID("mean")) { // iTunes
+ pAtom = new MP4MeanAtom();
+ }
+ break;
+ case 'n':
+ if (ATOMID(type) == ATOMID("nmhd")) {
+ pAtom = new MP4NmhdAtom();
+ } else if (ATOMID(type) == ATOMID("nump")) {
+ pAtom = new MP4NumpAtom();
+ } else if (ATOMID(type) == ATOMID("name")) { // iTunes
+ pAtom = new MP4NameAtom();
+ }
+ break;
+ case 'p':
+ if (ATOMID(type) == ATOMID("pmax")) {
+ pAtom = new MP4PmaxAtom();
+ } else if (ATOMID(type) == ATOMID("payt")) {
+ pAtom = new MP4PaytAtom();
+ }
+ break;
+ case 'r':
+ if (ATOMID(type) == ATOMID("rtp ")) {
+ pAtom = new MP4RtpAtom();
+ }
+ break;
+ case 's':
+ if (ATOMID(type) == ATOMID("s263")) {
+ pAtom = new MP4S263Atom();
+ } else if (ATOMID(type) == ATOMID("samr")) {
+ pAtom = new MP4SamrAtom();
+ } else if (ATOMID(type) == ATOMID("sawb")) {
+ pAtom = new MP4SawbAtom();
+ } else if (ATOMID(type) == ATOMID("schi")) {
+ pAtom = new MP4SchiAtom();
+ } else if (ATOMID(type) == ATOMID("schm")) {
+ pAtom = new MP4SchmAtom();
+ } else if (ATOMID(type) == ATOMID("sinf")) {
+ pAtom = new MP4SinfAtom();
+ } else if (ATOMID(type) == ATOMID("stbl")) {
+ pAtom = new MP4StblAtom();
+ } else if (ATOMID(type) == ATOMID("stsd")) {
+ pAtom = new MP4StsdAtom();
+ } else if (ATOMID(type) == ATOMID("stts")) {
+ pAtom = new MP4SttsAtom();
+ } else if (ATOMID(type) == ATOMID("stsz")) {
+ pAtom = new MP4StszAtom();
+ } else if (ATOMID(type) == ATOMID("stsc")) {
+ pAtom = new MP4StscAtom();
+ } else if (ATOMID(type) == ATOMID("stco")) {
+ pAtom = new MP4StcoAtom();
+ } else if (ATOMID(type) == ATOMID("stss")) {
+ pAtom = new MP4StssAtom();
+ } else if (ATOMID(type) == ATOMID("stsh")) {
+ pAtom = new MP4StshAtom();
+ } else if (ATOMID(type) == ATOMID("stdp")) {
+ pAtom = new MP4StdpAtom();
+ } else if (ATOMID(type) == ATOMID("smhd")) {
+ pAtom = new MP4SmhdAtom();
+ } else if (ATOMID(type) == ATOMID("sdp ")) {
+ pAtom = new MP4SdpAtom();
+ } else if (ATOMID(type) == ATOMID("snro")) {
+ pAtom = new MP4SnroAtom();
+ } else if (ATOMID(type) == ATOMID("sync")) {
+ pAtom = new MP4TrefTypeAtom(type);
+ } else if (ATOMID(type) == ATOMID("skip")) {
+ pAtom = new MP4FreeAtom();
+ pAtom->SetType("skip");
+ }
+ break;
+ case 't':
+ if (ATOMID(type) == ATOMID("trak")) {
+ pAtom = new MP4TrakAtom();
+ } else if (ATOMID(type) == ATOMID("tkhd")) {
+ pAtom = new MP4TkhdAtom();
+ } else if (ATOMID(type) == ATOMID("tref")) {
+ pAtom = new MP4TrefAtom();
+ } else if (ATOMID(type) == ATOMID("traf")) {
+ pAtom = new MP4TrafAtom();
+ } else if (ATOMID(type) == ATOMID("tfhd")) {
+ pAtom = new MP4TfhdAtom();
+ } else if (ATOMID(type) == ATOMID("trex")) {
+ pAtom = new MP4TrexAtom();
+ } else if (ATOMID(type) == ATOMID("trun")) {
+ pAtom = new MP4TrunAtom();
+ } else if (ATOMID(type) == ATOMID("tmin")) {
+ pAtom = new MP4TminAtom();
+ } else if (ATOMID(type) == ATOMID("tmax")) {
+ pAtom = new MP4TmaxAtom();
+ } else if (ATOMID(type) == ATOMID("trpy")) {
+ pAtom = new MP4TrpyAtom();
+ } else if (ATOMID(type) == ATOMID("tpyl")) {
+ pAtom = new MP4TpylAtom();
+ } else if (ATOMID(type) == ATOMID("tims")) {
+ pAtom = new MP4TimsAtom();
+ } else if (ATOMID(type) == ATOMID("tsro")) {
+ pAtom = new MP4TsroAtom();
+ } else if (ATOMID(type) == ATOMID("trkn")) { // iTunes
+ pAtom = new MP4TrknAtom();
+ } else if (ATOMID(type) == ATOMID("tmpo")) { // iTunes
+ pAtom = new MP4TmpoAtom();
+ }
+ break;
+ case 'u':
+ if (ATOMID(type) == ATOMID("udta")) {
+ pAtom = new MP4UdtaAtom();
+ } else if (ATOMID(type) == ATOMID("url ")) {
+ pAtom = new MP4UrlAtom();
+ } else if (ATOMID(type) == ATOMID("urn ")) {
+ pAtom = new MP4UrnAtom();
+ }
+ break;
+ case 'v':
+ if (ATOMID(type) == ATOMID("vmhd")) {
+ pAtom = new MP4VmhdAtom();
+ }
+ break;
+ case 0251: { // copyright symbol
+static const char name[5]={0251,'n', 'a', 'm', '\0'};
+static const char art[5]={0251,'A', 'R', 'T', '\0'};
+static const char wrt[5]={0251,'w', 'r', 't', '\0'};
+static const char alb[5]={0251,'a', 'l', 'b', '\0'};
+static const char day[5]={0251,'d', 'a', 'y', '\0'};
+static const char too[5]={0251,'t', 'o', 'o', '\0'};
+static const char cmt[5]={0251,'c', 'm', 't', '\0'};
+ if (ATOMID(type) == ATOMID(name)) {
+ pAtom = new MP4NamAtom();
+ } else if (ATOMID(type) == ATOMID(art)) { /* Apple iTunes */
+ pAtom = new MP4ArtAtom();
+ } else if (ATOMID(type) == ATOMID(wrt)) { /* Apple iTunes */
+ pAtom = new MP4WrtAtom();
+ } else if (ATOMID(type) == ATOMID(alb)) { /* Apple iTunes */
+ pAtom = new MP4AlbAtom();
+ } else if (ATOMID(type) == ATOMID(day)) { /* Apple iTunes */
+ pAtom = new MP4DayAtom();
+ } else if (ATOMID(type) == ATOMID(too)) { /* Apple iTunes */
+ pAtom = new MP4TooAtom();
+ } else if (ATOMID(type) == ATOMID(cmt)) { /* Apple iTunes */
+ pAtom = new MP4CmtAtom();
+ }
+ break;
+ }
+ case '-':
+ if (ATOMID(type) == ATOMID("----")) { /* Apple iTunes */
+ pAtom = new MP4DashAtom();
+ }
+ }
+ }
+
+ if (pAtom == NULL) {
+ pAtom = new MP4Atom(type);
+ pAtom->SetUnknownType(true);
+ }
+
+ ASSERT(pAtom);
+ return pAtom;
+}
+
+// generate a skeletal self
+
+void MP4Atom::Generate()
+{
+ u_int32_t i;
+
+ // for all properties
+ for (i = 0; i < m_pProperties.Size(); i++) {
+ // ask it to self generate
+ m_pProperties[i]->Generate();
+ }
+
+ // for all mandatory, single child atom types
+ for (i = 0; i < m_pChildAtomInfos.Size(); i++) {
+ if (m_pChildAtomInfos[i]->m_mandatory
+ && m_pChildAtomInfos[i]->m_onlyOne) {
+
+ // create the mandatory, single child atom
+ MP4Atom* pChildAtom =
+ CreateAtom(m_pChildAtomInfos[i]->m_name);
+
+ AddChildAtom(pChildAtom);
+
+ // and ask it to self generate
+ pChildAtom->Generate();
+ }
+ }
+}
+
+MP4Atom* MP4Atom::ReadAtom(MP4File* pFile, MP4Atom* pParentAtom)
+{
+ u_int8_t hdrSize = 8;
+ u_int8_t extendedType[16];
+
+ u_int64_t pos = pFile->GetPosition();
+
+ VERBOSE_READ(pFile->GetVerbosity(),
+ printf("ReadAtom: pos = 0x"X64"\n", pos));
+
+ u_int64_t dataSize = pFile->ReadUInt32();
+
+ char type[5];
+ pFile->ReadBytes((u_int8_t*)&type[0], 4);
+ type[4] = '\0';
+
+ // extended size
+ if (dataSize == 1) {
+ dataSize = pFile->ReadUInt64();
+ hdrSize += 8;
+ }
+
+ // extended type
+ if (ATOMID(type) == ATOMID("uuid")) {
+ pFile->ReadBytes(extendedType, sizeof(extendedType));
+ hdrSize += sizeof(extendedType);
+ }
+
+ if (dataSize == 0) {
+ // extends to EOF
+ dataSize = pFile->GetSize() - pos;
+ }
+
+ dataSize -= hdrSize;
+
+ VERBOSE_READ(pFile->GetVerbosity(),
+ printf("ReadAtom: type = %s data-size = "U64" (0x"X64")\n",
+ type, dataSize, dataSize));
+
+ if (pos + hdrSize + dataSize > pParentAtom->GetEnd()) {
+ VERBOSE_READ(pFile->GetVerbosity(),
+ printf("ReadAtom: invalid atom size, extends outside parent atom\n"));
+ throw new MP4Error("invalid atom size", "ReadAtom");
+ }
+
+
+ MP4Atom* pAtom = CreateAtom(type);
+ pAtom->SetFile(pFile);
+ pAtom->SetStart(pos);
+ pAtom->SetEnd(pos + hdrSize + dataSize);
+ pAtom->SetSize(dataSize);
+ if (ATOMID(type) == ATOMID("uuid")) {
+ pAtom->SetExtendedType(extendedType);
+ }
+ if (pAtom->IsUnknownType()) {
+ if (!IsReasonableType(pAtom->GetType())) {
+ VERBOSE_READ(pFile->GetVerbosity(),
+ printf("Warning: atom type %s is suspect\n", pAtom->GetType()));
+ } else {
+ VERBOSE_READ(pFile->GetVerbosity(),
+ printf("Info: atom type %s is unknown\n", pAtom->GetType()));
+ }
+
+ if (dataSize > 0) {
+ pAtom->AddProperty(
+ new MP4BytesProperty("data", dataSize));
+ }
+ }
+
+ pAtom->SetParentAtom(pParentAtom);
+
+ pAtom->Read();
+
+ return pAtom;
+}
+
+bool MP4Atom::IsReasonableType(const char* type)
+{
+ for (u_int8_t i = 0; i < 4; i++) {
+ if (isalnum(type[i])) {
+ continue;
+ }
+ if (i == 3 && type[i] == ' ') {
+ continue;
+ }
+ return false;
+ }
+ return true;
+}
+
+// generic read
+void MP4Atom::Read()
+{
+ ASSERT(m_pFile);
+
+ if (ATOMID(m_type) != 0 && m_size > 1000000) {
+ VERBOSE_READ(GetVerbosity(),
+ printf("Warning: %s atom size "U64" is suspect\n",
+ m_type, m_size));
+ }
+
+ ReadProperties();
+
+ // read child atoms, if we expect there to be some
+ if (m_pChildAtomInfos.Size() > 0) {
+ ReadChildAtoms();
+ }
+
+ Skip(); // to end of atom
+}
+
+void MP4Atom::Skip()
+{
+ if (m_pFile->GetPosition() != m_end) {
+ VERBOSE_READ(m_pFile->GetVerbosity(),
+ printf("Skip: "U64" bytes\n", m_end - m_pFile->GetPosition()));
+ }
+ m_pFile->SetPosition(m_end);
+}
+
+MP4Atom* MP4Atom::FindAtom(const char* name)
+{
+ if (!IsMe(name)) {
+ return NULL;
+ }
+
+ if (!IsRootAtom()) {
+ VERBOSE_FIND(m_pFile->GetVerbosity(),
+ printf("FindAtom: matched %s\n", name));
+
+ name = MP4NameAfterFirst(name);
+
+ // I'm the sought after atom
+ if (name == NULL) {
+ return this;
+ }
+ }
+
+ // else it's one of my children
+ return FindChildAtom(name);
+}
+
+bool MP4Atom::FindProperty(const char *name,
+ MP4Property** ppProperty, u_int32_t* pIndex)
+{
+ if (!IsMe(name)) {
+ return false;
+ }
+
+ if (!IsRootAtom()) {
+ VERBOSE_FIND(m_pFile->GetVerbosity(),
+ printf("FindProperty: matched %s\n", name));
+
+ name = MP4NameAfterFirst(name);
+
+ // no property name given
+ if (name == NULL) {
+ return false;
+ }
+ }
+
+ return FindContainedProperty(name, ppProperty, pIndex);
+}
+
+bool MP4Atom::IsMe(const char* name)
+{
+ if (name == NULL) {
+ return false;
+ }
+
+ // root atom always matches
+ if (!strcmp(m_type, "")) {
+ return true;
+ }
+
+ // check if our atom name is specified as the first component
+ if (!MP4NameFirstMatches(m_type, name)) {
+ return false;
+ }
+
+ return true;
+}
+
+MP4Atom* MP4Atom::FindChildAtom(const char* name)
+{
+ u_int32_t atomIndex = 0;
+
+ // get the index if we have one, e.g. moov.trak[2].mdia...
+ MP4NameFirstIndex(name, &atomIndex);
+
+ // need to get to the index'th child atom of the right type
+ for (u_int32_t i = 0; i < m_pChildAtoms.Size(); i++) {
+ if (MP4NameFirstMatches(m_pChildAtoms[i]->GetType(), name)) {
+ if (atomIndex == 0) {
+ // this is the one, ask it to match
+ return m_pChildAtoms[i]->FindAtom(name);
+ }
+ atomIndex--;
+ }
+ }
+
+ return NULL;
+}
+
+bool MP4Atom::FindContainedProperty(const char *name,
+ MP4Property** ppProperty, u_int32_t* pIndex)
+{
+ u_int32_t numProperties = m_pProperties.Size();
+ u_int32_t i;
+ // check all of our properties
+ for (i = 0; i < numProperties; i++) {
+ if (m_pProperties[i]->FindProperty(name, ppProperty, pIndex)) {
+ return true;
+ }
+ }
+
+ // not one of our properties,
+ // presumably one of our children's properties
+ // check child atoms...
+
+ // check if we have an index, e.g. trak[2].mdia...
+ u_int32_t atomIndex = 0;
+ MP4NameFirstIndex(name, &atomIndex);
+
+ // need to get to the index'th child atom of the right type
+ for (i = 0; i < m_pChildAtoms.Size(); i++) {
+ if (MP4NameFirstMatches(m_pChildAtoms[i]->GetType(), name)) {
+ if (atomIndex == 0) {
+ // this is the one, ask it to match
+ return m_pChildAtoms[i]->FindProperty(name, ppProperty, pIndex);
+ }
+ atomIndex--;
+ }
+ }
+
+ VERBOSE_FIND(m_pFile->GetVerbosity(),
+ printf("FindProperty: no match for %s\n", name));
+ return false;
+}
+
+void MP4Atom::ReadProperties(u_int32_t startIndex, u_int32_t count)
+{
+ u_int32_t numProperties = MIN(count, m_pProperties.Size() - startIndex);
+
+ // read any properties of the atom
+ for (u_int32_t i = startIndex; i < startIndex + numProperties; i++) {
+
+ m_pProperties[i]->Read(m_pFile);
+
+ if (m_pFile->GetPosition() > m_end) {
+ VERBOSE_READ(GetVerbosity(),
+ printf("ReadProperties: insufficient data for property: %s pos 0x"X64" atom end 0x"X64"\n",
+ m_pProperties[i]->GetName(),
+ m_pFile->GetPosition(), m_end));
+
+ throw new MP4Error("atom is too small", "Atom ReadProperties");
+ }
+
+ if (m_pProperties[i]->GetType() == TableProperty) {
+ VERBOSE_READ_TABLE(GetVerbosity(),
+ printf("Read: "); m_pProperties[i]->Dump(stdout, 0, true));
+ } else if (m_pProperties[i]->GetType() != DescriptorProperty) {
+ VERBOSE_READ(GetVerbosity(),
+ printf("Read: "); m_pProperties[i]->Dump(stdout, 0, true));
+ }
+ }
+}
+
+void MP4Atom::ReadChildAtoms()
+{
+ VERBOSE_READ(GetVerbosity(),
+ printf("ReadChildAtoms: of %s\n", m_type[0] ? m_type : "root"));
+
+ // read any child atoms
+ while (m_pFile->GetPosition() < m_end) {
+ MP4Atom* pChildAtom = MP4Atom::ReadAtom(m_pFile, this);
+
+ AddChildAtom(pChildAtom);
+
+ MP4AtomInfo* pChildAtomInfo = FindAtomInfo(pChildAtom->GetType());
+
+ // if child atom is of known type
+ // but not expected here print warning
+ if (pChildAtomInfo == NULL && !pChildAtom->IsUnknownType()) {
+ VERBOSE_READ(GetVerbosity(),
+ printf("Warning: In atom %s unexpected child atom %s\n",
+ GetType(), pChildAtom->GetType()));
+ }
+
+ // if child atoms should have just one instance
+ // and this is more than one, print warning
+ if (pChildAtomInfo) {
+ pChildAtomInfo->m_count++;
+
+ if (pChildAtomInfo->m_onlyOne && pChildAtomInfo->m_count > 1) {
+ VERBOSE_READ(GetVerbosity(),
+ printf("Warning: In atom %s multiple child atoms %s\n",
+ GetType(), pChildAtom->GetType()));
+ }
+ }
+ }
+
+ // if mandatory child atom doesn't exist, print warning
+ u_int32_t numAtomInfo = m_pChildAtomInfos.Size();
+ for (u_int32_t i = 0; i < numAtomInfo; i++) {
+ if (m_pChildAtomInfos[i]->m_mandatory
+ && m_pChildAtomInfos[i]->m_count == 0) {
+ VERBOSE_READ(GetVerbosity(),
+ printf("Warning: In atom %s missing child atom %s\n",
+ GetType(), m_pChildAtomInfos[i]->m_name));
+ }
+ }
+
+ VERBOSE_READ(GetVerbosity(),
+ printf("ReadChildAtoms: finished %s\n", m_type));
+}
+
+MP4AtomInfo* MP4Atom::FindAtomInfo(const char* name)
+{
+ u_int32_t numAtomInfo = m_pChildAtomInfos.Size();
+ for (u_int32_t i = 0; i < numAtomInfo; i++) {
+ if (ATOMID(m_pChildAtomInfos[i]->m_name) == ATOMID(name)) {
+ return m_pChildAtomInfos[i];
+ }
+ }
+ return NULL;
+}
+
+// generic write
+void MP4Atom::Write()
+{
+ ASSERT(m_pFile);
+
+ BeginWrite();
+
+ WriteProperties();
+
+ WriteChildAtoms();
+
+ FinishWrite();
+}
+
+void MP4Atom::Rewrite()
+{
+ ASSERT(m_pFile);
+
+ if (!m_end) {
+ // This atom hasn't been written yet...
+ return;
+ }
+
+ u_int64_t fPos = m_pFile->GetPosition();
+ m_pFile->SetPosition(GetStart());
+ Write();
+ m_pFile->SetPosition(fPos);
+}
+
+void MP4Atom::BeginWrite(bool use64)
+{
+ m_start = m_pFile->GetPosition();
+ //use64 = m_pFile->Use64Bits();
+ if (use64) {
+ m_pFile->WriteUInt32(1);
+ } else {
+ m_pFile->WriteUInt32(0);
+ }
+ m_pFile->WriteBytes((u_int8_t*)&m_type[0], 4);
+ if (use64) {
+ m_pFile->WriteUInt64(0);
+ }
+ if (ATOMID(m_type) == ATOMID("uuid")) {
+ m_pFile->WriteBytes(m_extendedType, sizeof(m_extendedType));
+ }
+}
+
+void MP4Atom::FinishWrite(bool use64)
+{
+ m_end = m_pFile->GetPosition();
+ m_size = (m_end - m_start);
+ //use64 = m_pFile->Use64Bits();
+ if (use64) {
+ m_pFile->SetPosition(m_start + 8);
+ m_pFile->WriteUInt64(m_size);
+ } else {
+ ASSERT(m_size <= (u_int64_t)0xFFFFFFFF);
+ m_pFile->SetPosition(m_start);
+ m_pFile->WriteUInt32(m_size);
+ }
+ m_pFile->SetPosition(m_end);
+
+ // adjust size to just reflect data portion of atom
+ m_size -= (use64 ? 16 : 8);
+ if (ATOMID(m_type) == ATOMID("uuid")) {
+ m_size -= sizeof(m_extendedType);
+ }
+}
+
+void MP4Atom::WriteProperties(u_int32_t startIndex, u_int32_t count)
+{
+ u_int32_t numProperties = MIN(count, m_pProperties.Size() - startIndex);
+
+ VERBOSE_WRITE(GetVerbosity(),
+ printf("Write: type %s\n", m_type));
+
+ for (u_int32_t i = startIndex; i < startIndex + numProperties; i++) {
+ m_pProperties[i]->Write(m_pFile);
+
+ if (m_pProperties[i]->GetType() == TableProperty) {
+ VERBOSE_WRITE_TABLE(GetVerbosity(),
+ printf("Write: "); m_pProperties[i]->Dump(stdout, 0, false));
+ } else {
+ VERBOSE_WRITE(GetVerbosity(),
+ printf("Write: "); m_pProperties[i]->Dump(stdout, 0, false));
+ }
+ }
+}
+
+void MP4Atom::WriteChildAtoms()
+{
+ u_int32_t size = m_pChildAtoms.Size();
+ for (u_int32_t i = 0; i < size; i++) {
+ m_pChildAtoms[i]->Write();
+ }
+
+ VERBOSE_WRITE(GetVerbosity(),
+ printf("Write: finished %s\n", m_type));
+}
+
+void MP4Atom::AddProperty(MP4Property* pProperty)
+{
+ ASSERT(pProperty);
+ m_pProperties.Add(pProperty);
+ pProperty->SetParentAtom(this);
+}
+
+void MP4Atom::AddVersionAndFlags()
+{
+ AddProperty(new MP4Integer8Property("version"));
+ AddProperty(new MP4Integer24Property("flags"));
+}
+
+void MP4Atom::AddReserved(char* name, u_int32_t size)
+{
+ MP4BytesProperty* pReserved = new MP4BytesProperty(name, size);
+ pReserved->SetReadOnly();
+ AddProperty(pReserved);
+}
+
+void MP4Atom::ExpectChildAtom(const char* name, bool mandatory, bool onlyOne)
+{
+ m_pChildAtomInfos.Add(new MP4AtomInfo(name, mandatory, onlyOne));
+}
+
+u_int8_t MP4Atom::GetVersion()
+{
+ if (strcmp("version", m_pProperties[0]->GetName())) {
+ return 0;
+ }
+ return ((MP4Integer8Property*)m_pProperties[0])->GetValue();
+}
+
+void MP4Atom::SetVersion(u_int8_t version)
+{
+ if (strcmp("version", m_pProperties[0]->GetName())) {
+ return;
+ }
+ ((MP4Integer8Property*)m_pProperties[0])->SetValue(version);
+}
+
+u_int32_t MP4Atom::GetFlags()
+{
+ if (strcmp("flags", m_pProperties[1]->GetName())) {
+ return 0;
+ }
+ return ((MP4Integer24Property*)m_pProperties[1])->GetValue();
+}
+
+void MP4Atom::SetFlags(u_int32_t flags)
+{
+ if (strcmp("flags", m_pProperties[1]->GetName())) {
+ return;
+ }
+ ((MP4Integer24Property*)m_pProperties[1])->SetValue(flags);
+}
+
+void MP4Atom::Dump(FILE* pFile, u_int8_t indent, bool dumpImplicits)
+{
+ if (m_type[0] != '\0') {
+ Indent(pFile, indent);
+ fprintf(pFile, "type %s\n", m_type);
+ }
+
+ u_int32_t i;
+ u_int32_t size;
+
+ // dump our properties
+ size = m_pProperties.Size();
+ for (i = 0; i < size; i++) {
+
+ /* skip details of tables unless we're told to be verbose */
+ if (m_pProperties[i]->GetType() == TableProperty
+ && !(GetVerbosity() & MP4_DETAILS_TABLE)) {
+ Indent(pFile, indent + 1);
+ fprintf(pFile, "<table entries suppressed>\n");
+ continue;
+ }
+
+ m_pProperties[i]->Dump(pFile, indent + 1, dumpImplicits);
+ }
+
+ // dump our children
+ size = m_pChildAtoms.Size();
+ for (i = 0; i < size; i++) {
+ m_pChildAtoms[i]->Dump(pFile, indent + 1, dumpImplicits);
+ }
+}
+
+u_int32_t MP4Atom::GetVerbosity()
+{
+ ASSERT(m_pFile);
+ return m_pFile->GetVerbosity();
+}
+
+u_int8_t MP4Atom::GetDepth()
+{
+ if (m_depth < 0xFF) {
+ return m_depth;
+ }
+
+ MP4Atom *pAtom = this;
+ m_depth = 0;
+
+ while ((pAtom = pAtom->GetParentAtom()) != NULL) {
+ m_depth++;
+ ASSERT(m_depth < 255);
+ }
+ return m_depth;
+}
+
--- /dev/null
+++ b/common/mp4v2/mp4atom.h
@@ -1,0 +1,239 @@
+/*
+ * 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 - 2004. All Rights Reserved.
+ *
+ * 3GPP features implementation is based on 3GPP's TS26.234-v5.60,
+ * and was contributed by Ximpo Group Ltd.
+ *
+ * Portions created by Ximpo Group Ltd. are
+ * Copyright (C) Ximpo Group Ltd. 2003, 2004. All Rights Reserved.
+ *
+ * Contributor(s):
+ * Dave Mackie dmackie@cisco.com
+ * Ximpo Group Ltd. mp4v2@ximpo.com
+ */
+
+#ifndef __MP4_ATOM_INCLUDED__
+#define __MP4_ATOM_INCLUDED__
+
+class MP4Atom;
+MP4ARRAY_DECL(MP4Atom, MP4Atom*);
+
+#define Required true
+#define Optional false
+#define OnlyOne true
+#define Many false
+#define Counted true
+
+/* helper class */
+class MP4AtomInfo {
+public:
+ MP4AtomInfo() {
+ m_name = NULL;
+ }
+ MP4AtomInfo(const char* name, bool mandatory, bool onlyOne);
+
+ const char* m_name;
+ bool m_mandatory;
+ bool m_onlyOne;
+ u_int32_t m_count;
+};
+
+MP4ARRAY_DECL(MP4AtomInfo, MP4AtomInfo*);
+
+class MP4Atom {
+public:
+ MP4Atom(const char* type = NULL);
+ virtual ~MP4Atom();
+
+ static MP4Atom* ReadAtom(MP4File* pFile, MP4Atom* pParentAtom);
+ static MP4Atom* CreateAtom(const char* type);
+ static bool IsReasonableType(const char* type);
+
+ MP4File* GetFile() {
+ return m_pFile;
+ };
+ void SetFile(MP4File* pFile) {
+ m_pFile = pFile;
+ };
+
+ u_int64_t GetStart() {
+ return m_start;
+ };
+ void SetStart(u_int64_t pos) {
+ m_start = pos;
+ };
+
+ u_int64_t GetEnd() {
+ return m_end;
+ };
+ void SetEnd(u_int64_t pos) {
+ m_end = pos;
+ };
+
+ u_int64_t GetSize() {
+ return m_size;
+ }
+ void SetSize(u_int64_t size) {
+ m_size = size;
+ }
+
+ const char* GetType() {
+ return m_type;
+ };
+ void SetType(const char* type) {
+ if (type && *type != '\0') {
+ ASSERT(strlen(type) == 4);
+ memcpy(m_type, type, 4);
+ m_type[4] = '\0';
+ } else {
+ memset(m_type, 0, 5);
+ }
+ }
+
+ void GetExtendedType(u_int8_t* pExtendedType) {
+ memcpy(pExtendedType, m_extendedType, sizeof(m_extendedType));
+ };
+ void SetExtendedType(u_int8_t* pExtendedType) {
+ memcpy(m_extendedType, pExtendedType, sizeof(m_extendedType));
+ };
+
+ bool IsUnknownType() {
+ return m_unknownType;
+ }
+ void SetUnknownType(bool unknownType = true) {
+ m_unknownType = unknownType;
+ }
+
+ bool IsRootAtom() {
+ return m_type[0] == '\0';
+ }
+
+ MP4Atom* GetParentAtom() {
+ return m_pParentAtom;
+ }
+ void SetParentAtom(MP4Atom* pParentAtom) {
+ m_pParentAtom = pParentAtom;
+ }
+
+ void AddChildAtom(MP4Atom* pChildAtom) {
+ pChildAtom->SetFile(m_pFile);
+ pChildAtom->SetParentAtom(this);
+ m_pChildAtoms.Add(pChildAtom);
+ }
+
+ void InsertChildAtom(MP4Atom* pChildAtom, u_int32_t index) {
+ pChildAtom->SetFile(m_pFile);
+ pChildAtom->SetParentAtom(this);
+ m_pChildAtoms.Insert(pChildAtom, index);
+ }
+
+ void DeleteChildAtom(MP4Atom* pChildAtom) {
+ for (MP4ArrayIndex i = 0; i < m_pChildAtoms.Size(); i++) {
+ if (m_pChildAtoms[i] == pChildAtom) {
+ m_pChildAtoms.Delete(i);
+ return;
+ }
+ }
+ }
+
+ u_int32_t GetNumberOfChildAtoms() {
+ return m_pChildAtoms.Size();
+ }
+
+ MP4Atom* GetChildAtom(u_int32_t index) {
+ return m_pChildAtoms[index];
+ }
+
+ MP4Property* GetProperty(u_int32_t index) {
+ return m_pProperties[index];
+ }
+
+ MP4Atom* FindAtom(const char* name);
+
+ MP4Atom* FindChildAtom(const char* name);
+
+ bool FindProperty(const char* name,
+ MP4Property** ppProperty, u_int32_t* pIndex = NULL);
+
+ u_int32_t GetFlags();
+ void SetFlags(u_int32_t flags);
+
+ u_int8_t GetDepth();
+
+ void Skip();
+
+ virtual void Generate();
+ virtual void Read();
+ virtual void BeginWrite(bool use64 = false);
+ virtual void Write();
+ virtual void Rewrite();
+ virtual void FinishWrite(bool use64 = false);
+ virtual void Dump(FILE* pFile, u_int8_t indent, bool dumpImplicits);
+
+protected:
+ void AddProperty(MP4Property* pProperty);
+
+ void AddVersionAndFlags();
+
+ void AddReserved(char* name, u_int32_t size);
+
+ void ExpectChildAtom(const char* name,
+ bool mandatory, bool onlyOne = true);
+
+ MP4AtomInfo* FindAtomInfo(const char* name);
+
+ bool IsMe(const char* name);
+
+ bool FindContainedProperty(const char* name,
+ MP4Property** ppProperty, u_int32_t* pIndex);
+
+ void ReadProperties(
+ u_int32_t startIndex = 0, u_int32_t count = 0xFFFFFFFF);
+ void ReadChildAtoms();
+
+ void WriteProperties(
+ u_int32_t startIndex = 0, u_int32_t count = 0xFFFFFFFF);
+ void WriteChildAtoms();
+
+ u_int8_t GetVersion();
+ void SetVersion(u_int8_t version);
+
+ /* debugging aid */
+ u_int32_t GetVerbosity();
+
+protected:
+ MP4File* m_pFile;
+ u_int64_t m_start;
+ u_int64_t m_end;
+ u_int64_t m_size;
+ char m_type[5];
+ bool m_unknownType;
+ u_int8_t m_extendedType[16];
+
+ MP4Atom* m_pParentAtom;
+ u_int8_t m_depth;
+
+ MP4PropertyArray m_pProperties;
+ MP4AtomInfoArray m_pChildAtomInfos;
+ MP4AtomArray m_pChildAtoms;
+};
+
+inline u_int32_t ATOMID(const char* type) {
+ return STRTOINT32(type);
+}
+
+#endif /* __MP4_ATOM_INCLUDED__ */
--- /dev/null
+++ b/common/mp4v2/mp4common.h
@@ -1,0 +1,50 @@
+/*
+ * 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
+ */
+
+#ifndef __MP4_COMMON_INCLUDED__
+#define __MP4_COMMON_INCLUDED__
+
+// common includes for everything
+// with an internal view of the library
+// i.e. all the .cpp's just #include "mp4common.h"
+
+#include "mpeg4ip.h"
+
+#include "mp4.h"
+#include "mp4util.h"
+#include "mp4array.h"
+#include "mp4track.h"
+#include "mp4file.h"
+#include "mp4property.h"
+#include "mp4container.h"
+#include "mp4descriptor.h"
+#include "mp4atom.h"
+
+#include "atoms.h"
+#include "descriptors.h"
+#include "ocidescriptors.h"
+#include "qosqualifiers.h"
+
+#include "odcommands.h"
+
+#include "rtphint.h"
+
+#endif /* __MP4_COMMON_INCLUDED__ */
--- /dev/null
+++ b/common/mp4v2/mp4container.cpp
@@ -1,0 +1,227 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4Container::~MP4Container()
+{
+ for (u_int32_t i = 0; i < m_pProperties.Size(); i++) {
+ delete m_pProperties[i];
+ }
+}
+
+void MP4Container::AddProperty(MP4Property* pProperty)
+{
+ ASSERT(pProperty);
+ m_pProperties.Add(pProperty);
+}
+
+bool MP4Container::FindProperty(const char *name,
+ MP4Property** ppProperty, u_int32_t* pIndex)
+{
+ if (pIndex) {
+ *pIndex = 0; // set the default answer for index
+ }
+
+ u_int32_t numProperties = m_pProperties.Size();
+
+ for (u_int32_t i = 0; i < numProperties; i++) {
+ if (m_pProperties[i]->FindProperty(name, ppProperty, pIndex)) {
+ return true;
+ }
+ }
+ return false;
+}
+
+void MP4Container::FindIntegerProperty(const char* name,
+ MP4Property** ppProperty, u_int32_t* pIndex)
+{
+ if (!FindProperty(name, ppProperty, pIndex)) {
+ throw new MP4Error("no such property",
+ "MP4Container::FindIntegerProperty");
+ }
+
+ switch ((*ppProperty)->GetType()) {
+ case Integer8Property:
+ case Integer16Property:
+ case Integer24Property:
+ case Integer32Property:
+ case Integer64Property:
+ break;
+ default:
+ throw new MP4Error("type mismatch",
+ "MP4Container::FindIntegerProperty");
+ }
+}
+
+u_int64_t MP4Container::GetIntegerProperty(const char* name)
+{
+ MP4Property* pProperty;
+ u_int32_t index;
+
+ FindIntegerProperty(name, &pProperty, &index);
+
+ return ((MP4IntegerProperty*)pProperty)->GetValue(index);
+}
+
+void MP4Container::SetIntegerProperty(const char* name, u_int64_t value)
+{
+ MP4Property* pProperty = NULL;
+ u_int32_t index = 0;
+
+ FindIntegerProperty(name, &pProperty, &index);
+
+ ((MP4IntegerProperty*)pProperty)->SetValue(value, index);
+}
+
+void MP4Container::FindFloatProperty(const char* name,
+ MP4Property** ppProperty, u_int32_t* pIndex)
+{
+ if (!FindProperty(name, ppProperty, pIndex)) {
+ throw new MP4Error("no such property",
+ "MP4Container::FindFloatProperty");
+ }
+ if ((*ppProperty)->GetType() != Float32Property) {
+ throw new MP4Error("type mismatch",
+ "MP4Container::FindFloatProperty");
+ }
+}
+
+float MP4Container::GetFloatProperty(const char* name)
+{
+ MP4Property* pProperty;
+ u_int32_t index;
+
+ FindFloatProperty(name, &pProperty, &index);
+
+ return ((MP4Float32Property*)pProperty)->GetValue(index);
+}
+
+void MP4Container::SetFloatProperty(const char* name, float value)
+{
+ MP4Property* pProperty;
+ u_int32_t index;
+
+ FindFloatProperty(name, &pProperty, &index);
+
+ ((MP4Float32Property*)pProperty)->SetValue(value, index);
+}
+
+void MP4Container::FindStringProperty(const char* name,
+ MP4Property** ppProperty, u_int32_t* pIndex)
+{
+ if (!FindProperty(name, ppProperty, pIndex)) {
+ throw new MP4Error("no such property",
+ "MP4Container::FindStringProperty");
+ }
+ if ((*ppProperty)->GetType() != StringProperty) {
+ throw new MP4Error("type mismatch",
+ "MP4Container::FindStringProperty");
+ }
+}
+
+const char* MP4Container::GetStringProperty(const char* name)
+{
+ MP4Property* pProperty;
+ u_int32_t index;
+
+ FindStringProperty(name, &pProperty, &index);
+
+ return ((MP4StringProperty*)pProperty)->GetValue(index);
+}
+
+void MP4Container::SetStringProperty(const char* name, const char* value)
+{
+ MP4Property* pProperty;
+ u_int32_t index;
+
+ FindStringProperty(name, &pProperty, &index);
+
+ ((MP4StringProperty*)pProperty)->SetValue(value, index);
+}
+
+void MP4Container::FindBytesProperty(const char* name,
+ MP4Property** ppProperty, u_int32_t* pIndex)
+{
+ if (!FindProperty(name, ppProperty, pIndex)) {
+ throw new MP4Error("no such property",
+ "MP4Container::FindBytesProperty");
+ }
+ if ((*ppProperty)->GetType() != BytesProperty) {
+ throw new MP4Error("type mismatch",
+ "MP4Container::FindBytesProperty");
+ }
+}
+
+void MP4Container::GetBytesProperty(const char* name,
+ u_int8_t** ppValue, u_int32_t* pValueSize)
+{
+ MP4Property* pProperty;
+ u_int32_t index;
+
+ FindBytesProperty(name, &pProperty, &index);
+
+ ((MP4BytesProperty*)pProperty)->GetValue(ppValue, pValueSize, index);
+}
+
+void MP4Container::SetBytesProperty(const char* name,
+ const u_int8_t* pValue, u_int32_t valueSize)
+{
+ MP4Property* pProperty;
+ u_int32_t index;
+
+ FindBytesProperty(name, &pProperty, &index);
+
+ ((MP4BytesProperty*)pProperty)->SetValue(pValue, valueSize, index);
+}
+
+void MP4Container::Read(MP4File* pFile)
+{
+ u_int32_t numProperties = m_pProperties.Size();
+
+ for (u_int32_t i = 0; i < numProperties; i++) {
+ m_pProperties[i]->Read(pFile);
+ }
+}
+
+void MP4Container::Write(MP4File* pFile)
+{
+ u_int32_t numProperties = m_pProperties.Size();
+
+ if (numProperties == 0) {
+ WARNING(numProperties == 0);
+ return;
+ }
+
+ for (u_int32_t i = 0; i < numProperties; i++) {
+ m_pProperties[i]->Write(pFile);
+ }
+}
+
+void MP4Container::Dump(FILE* pFile, u_int8_t indent, bool dumpImplicits)
+{
+ u_int32_t numProperties = m_pProperties.Size();
+
+ for (u_int32_t i = 0; i < numProperties; i++) {
+ m_pProperties[i]->Dump(pFile, indent, dumpImplicits);
+ }
+}
+
--- /dev/null
+++ b/common/mp4v2/mp4container.h
@@ -1,0 +1,84 @@
+/*
+ * 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
+ */
+
+#ifndef __MP4_CONTAINER_INCLUDED__
+#define __MP4_CONTAINER_INCLUDED__
+
+// base class - container of mp4 properties
+class MP4Container {
+public:
+ MP4Container() { }
+
+ virtual ~MP4Container();
+
+ void AddProperty(MP4Property* pProperty);
+
+ virtual void Read(MP4File* pFile);
+
+ virtual void Write(MP4File* pFile);
+
+ virtual void Dump(FILE* pFile, u_int8_t indent, bool dumpImplicits);
+
+ MP4Property* GetProperty(u_int32_t index) {
+ return m_pProperties[index];
+ }
+
+ // LATER MP4Property* GetProperty(const char* name); throw on error
+ // LATER MP4Property* FindProperty(const char* name, u_int32_t* pIndex = NULL); returns NULL on error
+
+ bool FindProperty(const char* name,
+ MP4Property** ppProperty, u_int32_t* pIndex = NULL);
+
+ void FindIntegerProperty(const char* name,
+ MP4Property** ppProperty, u_int32_t* pIndex = NULL);
+
+ u_int64_t GetIntegerProperty(const char* name);
+
+ void SetIntegerProperty(const char* name, u_int64_t value);
+
+ void FindFloatProperty(const char* name,
+ MP4Property** ppProperty, u_int32_t* pIndex = NULL);
+
+ float GetFloatProperty(const char* name);
+
+ void SetFloatProperty(const char* name, float value);
+
+ void FindStringProperty(const char* name,
+ MP4Property** ppProperty, u_int32_t* pIndex = NULL);
+
+ const char* GetStringProperty(const char* name);
+
+ void SetStringProperty(const char* name, const char* value);
+
+ void FindBytesProperty(const char* name,
+ MP4Property** ppProperty, u_int32_t* pIndex = NULL);
+
+ void GetBytesProperty(const char* name,
+ u_int8_t** ppValue, u_int32_t* pValueSize);
+
+ void SetBytesProperty(const char* name,
+ const u_int8_t* pValue, u_int32_t valueSize);
+
+protected:
+ MP4PropertyArray m_pProperties;
+};
+
+#endif /* __MP4_CONTAINER_INCLUDED__ */
--- /dev/null
+++ b/common/mp4v2/mp4descriptor.cpp
@@ -1,0 +1,211 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4Descriptor::MP4Descriptor(u_int8_t tag) {
+ m_tag = tag;
+ m_pParentAtom = NULL;
+ m_start = 0;
+ m_size = 0;
+ m_readMutatePoint = 0;
+}
+
+MP4Descriptor::~MP4Descriptor()
+{
+ for (u_int32_t i = 0; i < m_pProperties.Size(); i++) {
+ delete m_pProperties[i];
+ }
+}
+
+void MP4Descriptor::AddProperty(MP4Property* pProperty)
+{
+ ASSERT(pProperty);
+ m_pProperties.Add(pProperty);
+ pProperty->SetParentAtom(m_pParentAtom);
+}
+
+bool MP4Descriptor::FindContainedProperty(const char *name,
+ MP4Property** ppProperty, u_int32_t* pIndex)
+{
+ u_int32_t numProperties = m_pProperties.Size();
+
+ for (u_int32_t i = 0; i < numProperties; i++) {
+ if (m_pProperties[i]->FindProperty(name, ppProperty, pIndex)) {
+ return true;
+ }
+ }
+ return false;
+}
+
+void MP4Descriptor::Generate()
+{
+ // generate properties
+ for (u_int32_t i = 0; i < m_pProperties.Size(); i++) {
+ m_pProperties[i]->Generate();
+ }
+}
+
+void MP4Descriptor::Read(MP4File* pFile)
+{
+ ReadHeader(pFile);
+
+ ReadProperties(pFile, 0, m_readMutatePoint);
+
+ Mutate();
+
+ ReadProperties(pFile, m_readMutatePoint);
+
+ // flush any leftover read bits
+ pFile->FlushReadBits();
+}
+
+void MP4Descriptor::ReadHeader(MP4File* pFile)
+{
+ VERBOSE_READ(pFile->GetVerbosity(),
+ printf("ReadDescriptor: pos = 0x"X64"\n",
+ pFile->GetPosition()));
+
+ // read tag and length
+ u_int8_t tag = pFile->ReadUInt8();
+ if (m_tag) {
+ ASSERT(tag == m_tag);
+ } else {
+ m_tag = tag;
+ }
+ m_size = pFile->ReadMpegLength();
+ m_start = pFile->GetPosition();
+
+ VERBOSE_READ(pFile->GetVerbosity(),
+ printf("ReadDescriptor: tag 0x%02x data size %u (0x%x)\n",
+ m_tag, m_size, m_size));
+}
+
+void MP4Descriptor::ReadProperties(MP4File* pFile,
+ u_int32_t propStartIndex, u_int32_t propCount)
+{
+ u_int32_t numProperties = MIN(propCount,
+ m_pProperties.Size() - propStartIndex);
+
+ for (u_int32_t i = propStartIndex;
+ i < propStartIndex + numProperties; i++) {
+
+ MP4Property* pProperty = m_pProperties[i];
+
+ int32_t remaining = m_size - (pFile->GetPosition() - m_start);
+
+ if (pProperty->GetType() == DescriptorProperty) {
+ if (remaining > 0) {
+ // place a limit on how far this sub-descriptor looks
+ ((MP4DescriptorProperty*)pProperty)->SetSizeLimit(remaining);
+ pProperty->Read(pFile);
+ } // else do nothing, empty descriptor
+ } else {
+ // non-descriptor property
+ if (remaining >= 0) {
+ pProperty->Read(pFile);
+
+ if (pProperty->GetType() == TableProperty) {
+ VERBOSE_READ_TABLE(pFile->GetVerbosity(),
+ printf("Read: "); pProperty->Dump(stdout, 0, true));
+ } else {
+ VERBOSE_READ(pFile->GetVerbosity(),
+ printf("Read: "); pProperty->Dump(stdout, 0, true));
+ }
+ } else {
+ VERBOSE_ERROR(pFile->GetVerbosity(),
+ printf("Overran descriptor, tag %u data size %u property %u\n",
+ m_tag, m_size, i));
+ throw new MP4Error("overran descriptor",
+ "MP4Descriptor::ReadProperties");
+ }
+ }
+ }
+}
+
+void MP4Descriptor::Write(MP4File* pFile)
+{
+ // call virtual function to adapt properties before writing
+ Mutate();
+
+ u_int32_t numProperties = m_pProperties.Size();
+
+ if (numProperties == 0) {
+ WARNING(numProperties == 0);
+ return;
+ }
+
+ // write tag and length placeholder
+ pFile->WriteUInt8(m_tag);
+ u_int64_t lengthPos = pFile->GetPosition();
+ pFile->WriteMpegLength(0);
+ u_int64_t startPos = pFile->GetPosition();
+
+ for (u_int32_t i = 0; i < numProperties; i++) {
+ m_pProperties[i]->Write(pFile);
+ }
+
+ // align with byte boundary (rarely necessary)
+ pFile->PadWriteBits();
+
+ // go back and write correct length
+ u_int64_t endPos = pFile->GetPosition();
+ pFile->SetPosition(lengthPos);
+ pFile->WriteMpegLength(endPos - startPos);
+ pFile->SetPosition(endPos);
+}
+
+void MP4Descriptor::WriteToMemory(MP4File* pFile,
+ u_int8_t** ppBytes, u_int64_t* pNumBytes)
+{
+ // use memory buffer to save descriptor in memory
+ // instead of going directly to disk
+
+ pFile->EnableMemoryBuffer();
+
+ Write(pFile);
+
+ pFile->DisableMemoryBuffer(ppBytes, pNumBytes);
+}
+
+void MP4Descriptor::Dump(FILE* pFile, u_int8_t indent, bool dumpImplicits)
+{
+ // call virtual function to adapt properties before dumping
+ Mutate();
+
+ u_int32_t numProperties = m_pProperties.Size();
+
+ if (numProperties == 0) {
+ WARNING(numProperties == 0);
+ return;
+ }
+ for (u_int32_t i = 0; i < numProperties; i++) {
+ m_pProperties[i]->Dump(pFile, indent, dumpImplicits);
+ }
+}
+
+u_int8_t MP4Descriptor::GetDepth()
+{
+ if (m_pParentAtom) {
+ return m_pParentAtom->GetDepth();
+ }
+ return 0;
+}
--- /dev/null
+++ b/common/mp4v2/mp4descriptor.h
@@ -1,0 +1,96 @@
+/*
+ * 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
+ */
+
+#ifndef __MP4_DESCRIPTOR_INCLUDED__
+#define __MP4_DESCRIPTOR_INCLUDED__
+
+class MP4Descriptor {
+public:
+ MP4Descriptor(u_int8_t tag = 0);
+
+ virtual ~MP4Descriptor();
+
+ u_int8_t GetTag() {
+ return m_tag;
+ }
+ void SetTag(u_int8_t tag) {
+ m_tag = tag;
+ }
+
+ void SetParentAtom(MP4Atom* pParentAtom) {
+ m_pParentAtom = pParentAtom;
+ for (u_int32_t i = 0; i < m_pProperties.Size(); i++) {
+ m_pProperties[i]->SetParentAtom(pParentAtom);
+ }
+ }
+
+ void AddProperty(MP4Property* pProperty);
+
+ virtual void Generate();
+ virtual void Read(MP4File* pFile);
+ virtual void Write(MP4File* pFile);
+ virtual void Dump(FILE* pFile, u_int8_t indent, bool dumpImplicits);
+
+ MP4Property* GetProperty(u_int32_t index) {
+ return m_pProperties[index];
+ }
+
+ // use with extreme caution
+ void SetProperty(u_int32_t index, MP4Property* pProperty) {
+ m_pProperties[index] = pProperty;
+ }
+
+ bool FindProperty(const char* name,
+ MP4Property** ppProperty, u_int32_t* pIndex = NULL) {
+ return FindContainedProperty(name, ppProperty, pIndex);
+ }
+
+ void WriteToMemory(MP4File* pFile,
+ u_int8_t** ppBytes, u_int64_t* pNumBytes);
+
+protected:
+ void SetReadMutate(u_int32_t propIndex) {
+ m_readMutatePoint = propIndex;
+ }
+
+ void ReadHeader(MP4File* pFile);
+ void ReadProperties(MP4File* pFile,
+ u_int32_t startIndex = 0, u_int32_t count = 0xFFFFFFFF);
+
+ virtual void Mutate() {
+ // default is a no-op
+ };
+
+ bool FindContainedProperty(const char* name,
+ MP4Property** ppProperty, u_int32_t* pIndex);
+
+ u_int8_t GetDepth();
+
+protected:
+ MP4Atom* m_pParentAtom;
+ u_int8_t m_tag;
+ u_int64_t m_start;
+ u_int32_t m_size;
+ MP4PropertyArray m_pProperties;
+ u_int32_t m_readMutatePoint;
+};
+
+#endif /* __MP4_DESCRIPTOR_INCLUDED__ */
--- /dev/null
+++ b/common/mp4v2/mp4file.cpp
@@ -1,0 +1,2881 @@
+/*
+ * 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 - 2004. All Rights Reserved.
+ *
+ * 3GPP features implementation is based on 3GPP's TS26.234-v5.60,
+ * and was contributed by Ximpo Group Ltd.
+ *
+ * Portions created by Ximpo Group Ltd. are
+ * Copyright (C) Ximpo Group Ltd. 2003, 2004. All Rights Reserved.
+ *
+ * Contributor(s):
+ * Dave Mackie dmackie@cisco.com
+ * Alix Marchandise-Franquet alix@cisco.com
+ * Ximpo Group Ltd. mp4v2@ximpo.com
+ */
+
+#include "mp4common.h"
+
+MP4File::MP4File(u_int32_t verbosity)
+{
+ m_fileName = NULL;
+ m_pFile = NULL;
+ m_orgFileSize = 0;
+ m_fileSize = 0;
+ m_pRootAtom = NULL;
+ m_odTrackId = MP4_INVALID_TRACK_ID;
+
+ m_verbosity = verbosity;
+ m_mode = 0;
+ m_createFlags = 0;
+ m_useIsma = false;
+
+ m_pModificationProperty = NULL;
+ m_pTimeScaleProperty = NULL;
+ m_pDurationProperty = NULL;
+
+ m_memoryBuffer = NULL;
+ m_memoryBufferSize = 0;
+ m_memoryBufferPosition = 0;
+
+ m_numReadBits = 0;
+ m_bufReadBits = 0;
+ m_numWriteBits = 0;
+ m_bufWriteBits = 0;
+}
+
+MP4File::~MP4File()
+{
+ MP4Free(m_fileName);
+ delete m_pRootAtom;
+ for (u_int32_t i = 0; i < m_pTracks.Size(); i++) {
+ delete m_pTracks[i];
+ }
+ MP4Free(m_memoryBuffer); // just in case
+}
+
+void MP4File::Read(const char* fileName)
+{
+ m_fileName = MP4Stralloc(fileName);
+ m_mode = 'r';
+
+ Open("rb");
+
+ ReadFromFile();
+
+ CacheProperties();
+}
+
+void MP4File::Create(const char* fileName, u_int32_t flags)
+{
+ CreateEx( fileName, flags, NULL, 0, NULL, 0 );
+}
+
+void MP4File::CreateEx(const char* fileName, u_int32_t flags,
+ char* majorBrand, u_int32_t minorVersion,
+ char** supportedBrands, u_int32_t supportedBrandsCount)
+{
+ m_fileName = MP4Stralloc(fileName);
+ m_mode = 'w';
+ m_createFlags = flags;
+
+ Open("wb+");
+
+ // generate a skeletal atom tree
+ m_pRootAtom = MP4Atom::CreateAtom(NULL);
+ m_pRootAtom->SetFile(this);
+ m_pRootAtom->Generate();
+
+ if ((majorBrand != NULL) || (minorVersion != 0)) {
+ MakeFtypAtom(majorBrand, minorVersion,
+ supportedBrands, supportedBrandsCount);
+ }
+
+ CacheProperties();
+
+ // create mdat, and insert it after ftyp, and before moov
+ InsertChildAtom(m_pRootAtom, "mdat", 1);
+
+ // start writing
+ m_pRootAtom->BeginWrite();
+}
+
+bool MP4File::Use64Bits (const char *atomName)
+{
+ if (!strcmp(atomName, "mdat") || !strcmp(atomName, "stbl")) {
+ return (m_createFlags & MP4_CREATE_64BIT_DATA) == MP4_CREATE_64BIT_DATA;
+ }
+
+ if (!strcmp(atomName, "mvhd") ||
+ !strcmp(atomName, "tkhd") ||
+ !strcmp(atomName, "mdhd")) {
+ return (m_createFlags & MP4_CREATE_64BIT_TIME) == MP4_CREATE_64BIT_TIME;
+ }
+ return false;
+}
+
+
+void MP4File::Modify(const char* fileName)
+{
+ m_fileName = MP4Stralloc(fileName);
+ m_mode = 'r';
+
+ Open("rb+");
+ ReadFromFile();
+
+ m_mode = 'w';
+
+ // find the moov atom
+ MP4Atom* pMoovAtom = m_pRootAtom->FindAtom("moov");
+ u_int32_t numAtoms;
+
+ if (pMoovAtom == NULL) {
+ // there isn't one, odd but we can still proceed
+ pMoovAtom = AddChildAtom(m_pRootAtom, "moov");
+ } else {
+ numAtoms = m_pRootAtom->GetNumberOfChildAtoms();
+
+ // work backwards thru the top level atoms
+ int32_t i;
+ bool lastAtomIsMoov = true;
+ MP4Atom* pLastAtom = NULL;
+
+ for (i = numAtoms - 1; i >= 0; i--) {
+ MP4Atom* pAtom = m_pRootAtom->GetChildAtom(i);
+ const char* type = pAtom->GetType();
+
+ // get rid of any trailing free or skips
+ if (!strcmp(type, "free") || !strcmp(type, "skip")) {
+ m_pRootAtom->DeleteChildAtom(pAtom);
+ continue;
+ }
+
+ if (strcmp(type, "moov")) {
+ if (pLastAtom == NULL) {
+ pLastAtom = pAtom;
+ lastAtomIsMoov = false;
+ }
+ continue;
+ }
+
+ // now at moov atom
+
+ // multiple moov atoms?!?
+ if (pAtom != pMoovAtom) {
+ throw new MP4Error(
+ "Badly formed mp4 file, multiple moov atoms",
+ "MP4Modify");
+ }
+
+ if (lastAtomIsMoov) {
+ // position to start of moov atom,
+ // effectively truncating file
+ // prior to adding new mdat
+ SetPosition(pMoovAtom->GetStart());
+
+ } else { // last atom isn't moov
+ // need to place a free atom
+ MP4Atom* pFreeAtom = MP4Atom::CreateAtom("free");
+
+ // in existing position of the moov atom
+ m_pRootAtom->InsertChildAtom(pFreeAtom, i);
+ m_pRootAtom->DeleteChildAtom(pMoovAtom);
+ m_pRootAtom->AddChildAtom(pMoovAtom);
+
+ // write free atom to disk
+ SetPosition(pMoovAtom->GetStart());
+ pFreeAtom->SetSize(pMoovAtom->GetSize());
+ pFreeAtom->Write();
+
+ // finally set our file position to the end of the last atom
+ SetPosition(pLastAtom->GetEnd());
+ }
+
+ break;
+ }
+ ASSERT(i != -1);
+ }
+
+ CacheProperties(); // of moov atom
+
+ numAtoms = m_pRootAtom->GetNumberOfChildAtoms();
+
+ // insert another mdat prior to moov atom (the last atom)
+ MP4Atom* pMdatAtom = InsertChildAtom(m_pRootAtom, "mdat", numAtoms - 1);
+
+ // start writing new mdat
+ pMdatAtom->BeginWrite();
+}
+
+void MP4File::Optimize(const char* orgFileName, const char* newFileName)
+{
+ m_fileName = MP4Stralloc(orgFileName);
+ m_mode = 'r';
+
+ // first load meta-info into memory
+ Open("rb");
+ ReadFromFile();
+
+ CacheProperties(); // of moov atom
+
+ // now switch over to writing the new file
+ MP4Free(m_fileName);
+
+ // create a temporary file if necessary
+ if (newFileName == NULL) {
+ m_fileName = MP4Stralloc(TempFileName());
+ } else {
+ m_fileName = MP4Stralloc(newFileName);
+ }
+
+ FILE* pReadFile = m_pFile;
+ m_pFile = NULL;
+ m_mode = 'w';
+
+ Open("wb");
+
+ SetIntegerProperty("moov.mvhd.modificationTime",
+ MP4GetAbsTimestamp());
+
+ // writing meta info in the optimal order
+ ((MP4RootAtom*)m_pRootAtom)->BeginOptimalWrite();
+
+ // write data in optimal order
+ RewriteMdat(pReadFile, m_pFile);
+
+ // finish writing
+ ((MP4RootAtom*)m_pRootAtom)->FinishOptimalWrite();
+
+ // cleanup
+ fclose(m_pFile);
+ m_pFile = NULL;
+ fclose(pReadFile);
+
+ // move temporary file into place
+ if (newFileName == NULL) {
+ Rename(m_fileName, orgFileName);
+ }
+}
+
+void MP4File::RewriteMdat(FILE* pReadFile, FILE* pWriteFile)
+{
+ u_int32_t numTracks = m_pTracks.Size();
+
+ MP4ChunkId* chunkIds = new MP4ChunkId[numTracks];
+ MP4ChunkId* maxChunkIds = new MP4ChunkId[numTracks];
+ MP4Timestamp* nextChunkTimes = new MP4Timestamp[numTracks];
+
+ for (u_int32_t i = 0; i < numTracks; i++) {
+ chunkIds[i] = 1;
+ maxChunkIds[i] = m_pTracks[i]->GetNumberOfChunks();
+ nextChunkTimes[i] = MP4_INVALID_TIMESTAMP;
+ }
+
+ while (true) {
+ u_int32_t nextTrackIndex = (u_int32_t)-1;
+ MP4Timestamp nextTime = MP4_INVALID_TIMESTAMP;
+
+ for (u_int32_t i = 0; i < numTracks; i++) {
+ if (chunkIds[i] > maxChunkIds[i]) {
+ continue;
+ }
+
+ if (nextChunkTimes[i] == MP4_INVALID_TIMESTAMP) {
+ MP4Timestamp chunkTime =
+ m_pTracks[i]->GetChunkTime(chunkIds[i]);
+
+ nextChunkTimes[i] = MP4ConvertTime(chunkTime,
+ m_pTracks[i]->GetTimeScale(), GetTimeScale());
+ }
+
+ // time is not earliest so far
+ if (nextChunkTimes[i] > nextTime) {
+ continue;
+ }
+
+ // prefer hint tracks to media tracks if times are equal
+ if (nextChunkTimes[i] == nextTime
+ && strcmp(m_pTracks[i]->GetType(), MP4_HINT_TRACK_TYPE)) {
+ continue;
+ }
+
+ // this is our current choice of tracks
+ nextTime = nextChunkTimes[i];
+ nextTrackIndex = i;
+ }
+
+ if (nextTrackIndex == (u_int32_t)-1) {
+ break;
+ }
+
+ // point into original mp4 file for read chunk call
+ m_pFile = pReadFile;
+ m_mode = 'r';
+
+ u_int8_t* pChunk;
+ u_int32_t chunkSize;
+
+ m_pTracks[nextTrackIndex]->
+ ReadChunk(chunkIds[nextTrackIndex], &pChunk, &chunkSize);
+
+ // point back at the new mp4 file for write chunk
+ m_pFile = pWriteFile;
+ m_mode = 'w';
+
+ m_pTracks[nextTrackIndex]->
+ RewriteChunk(chunkIds[nextTrackIndex], pChunk, chunkSize);
+
+ MP4Free(pChunk);
+
+ chunkIds[nextTrackIndex]++;
+ nextChunkTimes[nextTrackIndex] = MP4_INVALID_TIMESTAMP;
+ }
+
+ delete [] chunkIds;
+ delete [] maxChunkIds;
+ delete [] nextChunkTimes;
+}
+
+void MP4File::Open(const char* fmode)
+{
+ ASSERT(m_pFile == NULL);
+
+#ifdef O_LARGEFILE
+ // UGH! fopen doesn't open a file in 64-bit mode, period.
+ // So we need to use open() and then fdopen()
+ int fd;
+ int flags = O_LARGEFILE;
+
+ if (strchr(fmode, '+')) {
+ flags |= O_CREAT | O_RDWR;
+ if (fmode[0] == 'w') {
+ flags |= O_TRUNC;
+ }
+ } else {
+ if (fmode[0] == 'w') {
+ flags |= O_CREAT | O_TRUNC | O_WRONLY;
+ } else {
+ flags |= O_RDONLY;
+ }
+ }
+ fd = open(m_fileName, flags, 0666);
+
+ if (fd >= 0) {
+ m_pFile = fdopen(fd, fmode);
+ }
+#else
+ m_pFile = fopen(m_fileName, fmode);
+#endif
+ if (m_pFile == NULL) {
+ throw new MP4Error(errno, "failed", "MP4Open");
+ }
+
+ if (m_mode == 'r') {
+ struct stat s;
+ if (fstat(fileno(m_pFile), &s) < 0) {
+ throw new MP4Error(errno, "stat failed", "MP4Open");
+ }
+ m_orgFileSize = m_fileSize = s.st_size;
+ } else {
+ m_orgFileSize = m_fileSize = 0;
+ }
+}
+
+void MP4File::ReadFromFile()
+{
+ // ensure we start at beginning of file
+ SetPosition(0);
+
+ // create a new root atom
+ ASSERT(m_pRootAtom == NULL);
+ m_pRootAtom = MP4Atom::CreateAtom(NULL);
+
+ u_int64_t fileSize = GetSize();
+
+ m_pRootAtom->SetFile(this);
+ m_pRootAtom->SetStart(0);
+ m_pRootAtom->SetSize(fileSize);
+ m_pRootAtom->SetEnd(fileSize);
+
+ m_pRootAtom->Read();
+
+ // create MP4Track's for any tracks in the file
+ GenerateTracks();
+}
+
+void MP4File::GenerateTracks()
+{
+ u_int32_t trackIndex = 0;
+
+ while (true) {
+ char trackName[32];
+ snprintf(trackName, sizeof(trackName), "moov.trak[%u]", trackIndex);
+
+ // find next trak atom
+ MP4Atom* pTrakAtom = m_pRootAtom->FindAtom(trackName);
+
+ // done, no more trak atoms
+ if (pTrakAtom == NULL) {
+ break;
+ }
+
+ // find track id property
+ MP4Integer32Property* pTrackIdProperty = NULL;
+ pTrakAtom->FindProperty(
+ "trak.tkhd.trackId",
+ (MP4Property**)&pTrackIdProperty);
+
+ // find track type property
+ MP4StringProperty* pTypeProperty = NULL;
+ pTrakAtom->FindProperty(
+ "trak.mdia.hdlr.handlerType",
+ (MP4Property**)&pTypeProperty);
+
+ // ensure we have the basics properties
+ if (pTrackIdProperty && pTypeProperty) {
+
+ m_trakIds.Add(pTrackIdProperty->GetValue());
+
+ MP4Track* pTrack = NULL;
+ try {
+ if (!strcmp(pTypeProperty->GetValue(), MP4_HINT_TRACK_TYPE)) {
+ pTrack = new MP4RtpHintTrack(this, pTrakAtom);
+ } else {
+ pTrack = new MP4Track(this, pTrakAtom);
+ }
+ m_pTracks.Add(pTrack);
+ }
+ catch (MP4Error* e) {
+ VERBOSE_ERROR(m_verbosity, e->Print());
+ delete e;
+ }
+
+ // remember when we encounter the OD track
+ if (pTrack && !strcmp(pTrack->GetType(), MP4_OD_TRACK_TYPE)) {
+ if (m_odTrackId == MP4_INVALID_TRACK_ID) {
+ m_odTrackId = pTrackIdProperty->GetValue();
+ } else {
+ VERBOSE_READ(GetVerbosity(),
+ printf("Warning: multiple OD tracks present\n"));
+ }
+ }
+ } else {
+ m_trakIds.Add(0);
+ }
+
+ trackIndex++;
+ }
+}
+
+void MP4File::CacheProperties()
+{
+ FindIntegerProperty("moov.mvhd.modificationTime",
+ (MP4Property**)&m_pModificationProperty);
+
+ FindIntegerProperty("moov.mvhd.timeScale",
+ (MP4Property**)&m_pTimeScaleProperty);
+
+ FindIntegerProperty("moov.mvhd.duration",
+ (MP4Property**)&m_pDurationProperty);
+}
+
+void MP4File::BeginWrite()
+{
+ m_pRootAtom->BeginWrite();
+}
+
+void MP4File::FinishWrite()
+{
+ // for all tracks, flush chunking buffers
+ for (u_int32_t i = 0; i < m_pTracks.Size(); i++) {
+ ASSERT(m_pTracks[i]);
+ m_pTracks[i]->FinishWrite();
+ }
+
+ // ask root atom to write
+ m_pRootAtom->FinishWrite();
+
+ // check if file shrunk, e.g. we deleted a track
+ if (GetSize() < m_orgFileSize) {
+ // just use a free atom to mark unused space
+ // MP4Optimize() should be used to clean up this space
+ MP4Atom* pFreeAtom = MP4Atom::CreateAtom("free");
+ ASSERT(pFreeAtom);
+ pFreeAtom->SetFile(this);
+ int64_t size = m_orgFileSize - (m_fileSize + 8);
+ if (size < 0) size = 0;
+ pFreeAtom->SetSize(size);
+ pFreeAtom->Write();
+ delete pFreeAtom;
+ }
+}
+
+MP4Duration MP4File::UpdateDuration(MP4Duration duration)
+{
+ MP4Duration currentDuration = GetDuration();
+ if (duration > currentDuration) {
+ SetDuration(duration);
+ return duration;
+ }
+ return currentDuration;
+}
+
+void MP4File::Dump(FILE* pDumpFile, bool dumpImplicits)
+{
+ if (pDumpFile == NULL) {
+ pDumpFile = stdout;
+ }
+
+ fprintf(pDumpFile, "Dumping %s meta-information...\n", m_fileName);
+ m_pRootAtom->Dump(pDumpFile, 0, dumpImplicits);
+}
+
+void MP4File::Close()
+{
+ if (m_mode == 'w') {
+ SetIntegerProperty("moov.mvhd.modificationTime",
+ MP4GetAbsTimestamp());
+
+ FinishWrite();
+ }
+
+ fclose(m_pFile);
+ m_pFile = NULL;
+}
+
+const char* MP4File::TempFileName()
+{
+ // there are so many attempts in libc to get this right
+ // that for portablity reasons, it's best just to roll our own
+#ifndef _WIN32
+ static char tempFileName[64];
+ u_int32_t i;
+ for (i = getpid(); i < 0xFFFFFFFF; i++) {
+ sprintf(tempFileName, "./tmp%u.mp4", i);
+ if (access(tempFileName, F_OK) != 0) {
+ break;
+ }
+ }
+ if (i == 0xFFFFFFFF) {
+ throw new MP4Error("can't create temporary file", "TempFileName");
+ }
+#else
+ static char tempFileName[MAX_PATH + 3];
+ GetTempFileName(".", // dir. for temp. files
+ "mp4", // temp. filename prefix
+ 0, // create unique name
+ tempFileName); // buffer for name
+#endif
+
+ return tempFileName;
+}
+
+void MP4File::Rename(const char* oldFileName, const char* newFileName)
+{
+ int rc;
+
+#ifdef _WIN32
+ rc = remove(newFileName);
+ if (rc == 0) {
+ rc = rename(oldFileName, newFileName);
+ }
+#else
+ rc = rename(oldFileName, newFileName);
+#endif
+ if (rc != 0) {
+ throw new MP4Error(errno, "can't overwrite existing file", "Rename");
+ }
+}
+
+void MP4File::ProtectWriteOperation(char* where)
+{
+ if (m_mode == 'r') {
+ throw new MP4Error("operation not permitted in read mode", where);
+ }
+}
+
+MP4Track* MP4File::GetTrack(MP4TrackId trackId)
+{
+ return m_pTracks[FindTrackIndex(trackId)];
+}
+
+MP4Atom* MP4File::FindAtom(const char* name)
+{
+ MP4Atom* pAtom = NULL;
+ if (!name || !strcmp(name, "")) {
+ pAtom = m_pRootAtom;
+ } else {
+ pAtom = m_pRootAtom->FindAtom(name);
+ }
+ return pAtom;
+}
+
+MP4Atom* MP4File::AddChildAtom(
+ const char* parentName,
+ const char* childName)
+{
+ return AddChildAtom(FindAtom(parentName), childName);
+}
+
+MP4Atom* MP4File::AddChildAtom(
+ MP4Atom* pParentAtom,
+ const char* childName)
+{
+ return InsertChildAtom(pParentAtom, childName,
+ pParentAtom->GetNumberOfChildAtoms());
+}
+
+MP4Atom* MP4File::InsertChildAtom(
+ const char* parentName,
+ const char* childName,
+ u_int32_t index)
+{
+ return InsertChildAtom(FindAtom(parentName), childName, index);
+}
+
+MP4Atom* MP4File::InsertChildAtom(
+ MP4Atom* pParentAtom,
+ const char* childName,
+ u_int32_t index)
+{
+ MP4Atom* pChildAtom = MP4Atom::CreateAtom(childName);
+
+ ASSERT(pParentAtom);
+ pParentAtom->InsertChildAtom(pChildAtom, index);
+
+ pChildAtom->Generate();
+
+ return pChildAtom;
+}
+
+MP4Atom* MP4File::AddDescendantAtoms(
+ const char* ancestorName,
+ const char* descendantNames)
+{
+ return AddDescendantAtoms(FindAtom(ancestorName), descendantNames);
+}
+
+MP4Atom* MP4File::AddDescendantAtoms(
+ MP4Atom* pAncestorAtom, const char* descendantNames)
+{
+ ASSERT(pAncestorAtom);
+
+ MP4Atom* pParentAtom = pAncestorAtom;
+ MP4Atom* pChildAtom = NULL;
+
+ while (true) {
+ char* childName = MP4NameFirst(descendantNames);
+
+ if (childName == NULL) {
+ break;
+ }
+
+ descendantNames = MP4NameAfterFirst(descendantNames);
+
+ pChildAtom = pParentAtom->FindChildAtom(childName);
+
+ if (pChildAtom == NULL) {
+ pChildAtom = AddChildAtom(pParentAtom, childName);
+ }
+
+ pParentAtom = pChildAtom;
+
+ MP4Free(childName);
+ }
+
+ return pChildAtom;
+}
+
+bool MP4File::FindProperty(const char* name,
+ MP4Property** ppProperty, u_int32_t* pIndex)
+{
+ if (pIndex) {
+ *pIndex = 0; // set the default answer for index
+ }
+
+ return m_pRootAtom->FindProperty(name, ppProperty, pIndex);
+}
+
+void MP4File::FindIntegerProperty(const char* name,
+ MP4Property** ppProperty, u_int32_t* pIndex)
+{
+ if (!FindProperty(name, ppProperty, pIndex)) {
+ throw new MP4Error("no such property - %s", "MP4File::FindIntegerProperty", name);
+ }
+
+ switch ((*ppProperty)->GetType()) {
+ case Integer8Property:
+ case Integer16Property:
+ case Integer24Property:
+ case Integer32Property:
+ case Integer64Property:
+ break;
+ default:
+ throw new MP4Error("type mismatch - property %s type %d", "MP4File::FindIntegerProperty", name, (*ppProperty)->GetType());
+ }
+}
+
+u_int64_t MP4File::GetIntegerProperty(const char* name)
+{
+ MP4Property* pProperty;
+ u_int32_t index;
+
+ FindIntegerProperty(name, &pProperty, &index);
+
+ return ((MP4IntegerProperty*)pProperty)->GetValue(index);
+}
+
+void MP4File::SetIntegerProperty(const char* name, u_int64_t value)
+{
+ ProtectWriteOperation("SetIntegerProperty");
+
+ MP4Property* pProperty = NULL;
+ u_int32_t index = 0;
+
+ FindIntegerProperty(name, &pProperty, &index);
+
+ ((MP4IntegerProperty*)pProperty)->SetValue(value, index);
+}
+
+void MP4File::FindFloatProperty(const char* name,
+ MP4Property** ppProperty, u_int32_t* pIndex)
+{
+ if (!FindProperty(name, ppProperty, pIndex)) {
+ throw new MP4Error("no such property - %s", "MP4File::FindFloatProperty", name);
+ }
+ if ((*ppProperty)->GetType() != Float32Property) {
+ throw new MP4Error("type mismatch - property %s type %d",
+ "MP4File::FindFloatProperty",
+ name,
+ (*ppProperty)->GetType());
+ }
+}
+
+float MP4File::GetFloatProperty(const char* name)
+{
+ MP4Property* pProperty;
+ u_int32_t index;
+
+ FindFloatProperty(name, &pProperty, &index);
+
+ return ((MP4Float32Property*)pProperty)->GetValue(index);
+}
+
+void MP4File::SetFloatProperty(const char* name, float value)
+{
+ ProtectWriteOperation("SetFloatProperty");
+
+ MP4Property* pProperty;
+ u_int32_t index;
+
+ FindFloatProperty(name, &pProperty, &index);
+
+ ((MP4Float32Property*)pProperty)->SetValue(value, index);
+}
+
+void MP4File::FindStringProperty(const char* name,
+ MP4Property** ppProperty, u_int32_t* pIndex)
+{
+ if (!FindProperty(name, ppProperty, pIndex)) {
+ throw new MP4Error("no such property - %s", "MP4File::FindStringProperty", name);
+ }
+ if ((*ppProperty)->GetType() != StringProperty) {
+ throw new MP4Error("type mismatch - property %s type %d", "MP4File::FindStringProperty",
+ name, (*ppProperty)->GetType());
+ }
+}
+
+const char* MP4File::GetStringProperty(const char* name)
+{
+ MP4Property* pProperty;
+ u_int32_t index;
+
+ FindStringProperty(name, &pProperty, &index);
+
+ return ((MP4StringProperty*)pProperty)->GetValue(index);
+}
+
+void MP4File::SetStringProperty(const char* name, const char* value)
+{
+ ProtectWriteOperation("SetStringProperty");
+
+ MP4Property* pProperty;
+ u_int32_t index;
+
+ FindStringProperty(name, &pProperty, &index);
+
+ ((MP4StringProperty*)pProperty)->SetValue(value, index);
+}
+
+void MP4File::FindBytesProperty(const char* name,
+ MP4Property** ppProperty, u_int32_t* pIndex)
+{
+ if (!FindProperty(name, ppProperty, pIndex)) {
+ throw new MP4Error("no such property %s", "MP4File::FindBytesProperty", name);
+ }
+ if ((*ppProperty)->GetType() != BytesProperty) {
+ throw new MP4Error("type mismatch - property %s - type %d", "MP4File::FindBytesProperty", name, (*ppProperty)->GetType());
+ }
+}
+
+void MP4File::GetBytesProperty(const char* name,
+ u_int8_t** ppValue, u_int32_t* pValueSize)
+{
+ MP4Property* pProperty;
+ u_int32_t index;
+
+ FindBytesProperty(name, &pProperty, &index);
+
+ ((MP4BytesProperty*)pProperty)->GetValue(ppValue, pValueSize, index);
+}
+
+void MP4File::SetBytesProperty(const char* name,
+ const u_int8_t* pValue, u_int32_t valueSize)
+{
+ ProtectWriteOperation("SetBytesProperty");
+
+ MP4Property* pProperty;
+ u_int32_t index;
+
+ FindBytesProperty(name, &pProperty, &index);
+
+ ((MP4BytesProperty*)pProperty)->SetValue(pValue, valueSize, index);
+}
+
+
+// track functions
+
+MP4TrackId MP4File::AddTrack(const char* type, u_int32_t timeScale)
+{
+ ProtectWriteOperation("AddTrack");
+
+ // create and add new trak atom
+ MP4Atom* pTrakAtom = AddChildAtom("moov", "trak");
+
+ // allocate a new track id
+ MP4TrackId trackId = AllocTrackId();
+
+ m_trakIds.Add(trackId);
+
+ // set track id
+ MP4Integer32Property* pInteger32Property = NULL;
+ pTrakAtom->FindProperty(
+ "trak.tkhd.trackId", (MP4Property**)&pInteger32Property);
+ ASSERT(pInteger32Property);
+ pInteger32Property->SetValue(trackId);
+
+ // set track type
+ const char* normType = MP4Track::NormalizeTrackType(type);
+
+ // sanity check for user defined types
+ if (strlen(normType) > 4) {
+ VERBOSE_WARNING(m_verbosity,
+ printf("AddTrack: type truncated to four characters\n"));
+ // StringProperty::SetValue() will do the actual truncation
+ }
+
+ MP4StringProperty* pStringProperty = NULL;
+ pTrakAtom->FindProperty(
+ "trak.mdia.hdlr.handlerType", (MP4Property**)&pStringProperty);
+ ASSERT(pStringProperty);
+ pStringProperty->SetValue(normType);
+
+ // set track time scale
+ pInteger32Property = NULL;
+ pTrakAtom->FindProperty(
+ "trak.mdia.mdhd.timeScale", (MP4Property**)&pInteger32Property);
+ ASSERT(pInteger32Property);
+ pInteger32Property->SetValue(timeScale ? timeScale : 1000);
+
+ // now have enough to create MP4Track object
+ MP4Track* pTrack = NULL;
+ if (!strcmp(normType, MP4_HINT_TRACK_TYPE)) {
+ pTrack = new MP4RtpHintTrack(this, pTrakAtom);
+ } else {
+ pTrack = new MP4Track(this, pTrakAtom);
+ }
+ m_pTracks.Add(pTrack);
+
+ // mark non-hint tracks as enabled
+ if (strcmp(normType, MP4_HINT_TRACK_TYPE)) {
+ SetTrackIntegerProperty(trackId, "tkhd.flags", 1);
+ }
+
+ // mark track as contained in this file
+ // LATER will provide option for external data references
+ AddDataReference(trackId, NULL);
+
+ return trackId;
+}
+
+void MP4File::AddTrackToIod(MP4TrackId trackId)
+{
+ MP4DescriptorProperty* pDescriptorProperty = NULL;
+ m_pRootAtom->FindProperty("moov.iods.esIds",
+ (MP4Property**)&pDescriptorProperty);
+ ASSERT(pDescriptorProperty);
+
+ MP4Descriptor* pDescriptor =
+ pDescriptorProperty->AddDescriptor(MP4ESIDIncDescrTag);
+ ASSERT(pDescriptor);
+
+ MP4Integer32Property* pIdProperty = NULL;
+ pDescriptor->FindProperty("id",
+ (MP4Property**)&pIdProperty);
+ ASSERT(pIdProperty);
+
+ pIdProperty->SetValue(trackId);
+}
+
+ void MP4File::RemoveTrackFromIod(MP4TrackId trackId, bool shallHaveIods)
+{
+ MP4DescriptorProperty* pDescriptorProperty = NULL;
+ m_pRootAtom->FindProperty("moov.iods.esIds",
+ (MP4Property**)&pDescriptorProperty);
+
+ if (shallHaveIods) {
+ ASSERT(pDescriptorProperty);
+ } else {
+ if (!pDescriptorProperty) {
+ return;
+ }
+ }
+
+ for (u_int32_t i = 0; i < pDescriptorProperty->GetCount(); i++) {
+ static char name[32];
+ snprintf(name, sizeof(name), "esIds[%u].id", i);
+
+ MP4Integer32Property* pIdProperty = NULL;
+ pDescriptorProperty->FindProperty(name,
+ (MP4Property**)&pIdProperty);
+ ASSERT(pIdProperty);
+
+ if (pIdProperty->GetValue() == trackId) {
+ pDescriptorProperty->DeleteDescriptor(i);
+ break;
+ }
+ }
+}
+
+void MP4File::AddTrackToOd(MP4TrackId trackId)
+{
+ if (!m_odTrackId) {
+ return;
+ }
+
+ AddTrackReference(MakeTrackName(m_odTrackId, "tref.mpod"), trackId);
+}
+
+void MP4File::RemoveTrackFromOd(MP4TrackId trackId)
+{
+ if (!m_odTrackId) {
+ return;
+ }
+
+ RemoveTrackReference(MakeTrackName(m_odTrackId, "tref.mpod"), trackId);
+}
+
+void MP4File::GetTrackReferenceProperties(const char* trefName,
+ MP4Property** ppCountProperty, MP4Property** ppTrackIdProperty)
+{
+ char propName[1024];
+
+ snprintf(propName, sizeof(propName), "%s.%s", trefName, "entryCount");
+ m_pRootAtom->FindProperty(propName, ppCountProperty);
+ ASSERT(*ppCountProperty);
+
+ snprintf(propName, sizeof(propName), "%s.%s", trefName, "entries.trackId");
+ m_pRootAtom->FindProperty(propName, ppTrackIdProperty);
+ ASSERT(*ppTrackIdProperty);
+}
+
+void MP4File::AddTrackReference(const char* trefName, MP4TrackId refTrackId)
+{
+ MP4Integer32Property* pCountProperty = NULL;
+ MP4Integer32Property* pTrackIdProperty = NULL;
+
+ GetTrackReferenceProperties(trefName,
+ (MP4Property**)&pCountProperty,
+ (MP4Property**)&pTrackIdProperty);
+
+ pTrackIdProperty->AddValue(refTrackId);
+ pCountProperty->IncrementValue();
+}
+
+u_int32_t MP4File::FindTrackReference(const char* trefName,
+ MP4TrackId refTrackId)
+{
+ MP4Integer32Property* pCountProperty = NULL;
+ MP4Integer32Property* pTrackIdProperty = NULL;
+
+ GetTrackReferenceProperties(trefName,
+ (MP4Property**)&pCountProperty,
+ (MP4Property**)&pTrackIdProperty);
+
+ for (u_int32_t i = 0; i < pCountProperty->GetValue(); i++) {
+ if (refTrackId == pTrackIdProperty->GetValue(i)) {
+ return i + 1; // N.B. 1 not 0 based index
+ }
+ }
+ return 0;
+}
+
+void MP4File::RemoveTrackReference(const char* trefName, MP4TrackId refTrackId)
+{
+ MP4Integer32Property* pCountProperty = NULL;
+ MP4Integer32Property* pTrackIdProperty = NULL;
+
+ GetTrackReferenceProperties(trefName,
+ (MP4Property**)&pCountProperty,
+ (MP4Property**)&pTrackIdProperty);
+
+ for (u_int32_t i = 0; i < pCountProperty->GetValue(); i++) {
+ if (refTrackId == pTrackIdProperty->GetValue(i)) {
+ pTrackIdProperty->DeleteValue(i);
+ pCountProperty->IncrementValue(-1);
+ }
+ }
+}
+
+void MP4File::AddDataReference(MP4TrackId trackId, const char* url)
+{
+ MP4Atom* pDrefAtom =
+ FindAtom(MakeTrackName(trackId, "mdia.minf.dinf.dref"));
+ ASSERT(pDrefAtom);
+
+ MP4Integer32Property* pCountProperty = NULL;
+ pDrefAtom->FindProperty("dref.entryCount",
+ (MP4Property**)&pCountProperty);
+ ASSERT(pCountProperty);
+ pCountProperty->IncrementValue();
+
+ MP4Atom* pUrlAtom = AddChildAtom(pDrefAtom, "url ");
+
+ if (url && url[0] != '\0') {
+ pUrlAtom->SetFlags(pUrlAtom->GetFlags() & 0xFFFFFE);
+
+ MP4StringProperty* pUrlProperty = NULL;
+ pUrlAtom->FindProperty("url .location",
+ (MP4Property**)&pUrlProperty);
+ ASSERT(pUrlProperty);
+ pUrlProperty->SetValue(url);
+ } else {
+ pUrlAtom->SetFlags(pUrlAtom->GetFlags() | 1);
+ }
+}
+
+MP4TrackId MP4File::AddSystemsTrack(const char* type)
+{
+ const char* normType = MP4Track::NormalizeTrackType(type);
+
+ // TBD if user type, fix name to four chars, and warn
+
+ MP4TrackId trackId = AddTrack(type, MP4_MSECS_TIME_SCALE);
+
+ InsertChildAtom(MakeTrackName(trackId, "mdia.minf"), "nmhd", 0);
+
+ AddChildAtom(MakeTrackName(trackId, "mdia.minf.stbl.stsd"), "mp4s");
+
+ // stsd is a unique beast in that it has a count of the number
+ // of child atoms that needs to be incremented after we add the mp4s atom
+ MP4Integer32Property* pStsdCountProperty;
+ FindIntegerProperty(
+ MakeTrackName(trackId, "mdia.minf.stbl.stsd.entryCount"),
+ (MP4Property**)&pStsdCountProperty);
+ pStsdCountProperty->IncrementValue();
+
+ SetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsd.mp4s.esds.ESID",
+#if 0
+ // note - for a file, these values need to
+ // be 0 - wmay - 04/16/2003
+ trackId
+#else
+ 0
+#endif
+ );
+
+ SetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsd.mp4s.esds.decConfigDescr.objectTypeId",
+ MP4SystemsV1ObjectType);
+
+ SetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsd.mp4s.esds.decConfigDescr.streamType",
+ ConvertTrackTypeToStreamType(normType));
+
+ return trackId;
+}
+
+MP4TrackId MP4File::AddODTrack()
+{
+ // until a demonstrated need emerges
+ // we limit ourselves to one object description track
+ if (m_odTrackId != MP4_INVALID_TRACK_ID) {
+ throw new MP4Error("object description track already exists",
+ "AddObjectDescriptionTrack");
+ }
+
+ m_odTrackId = AddSystemsTrack(MP4_OD_TRACK_TYPE);
+
+ AddTrackToIod(m_odTrackId);
+
+ AddDescendantAtoms(MakeTrackName(m_odTrackId, NULL), "tref.mpod");
+
+ return m_odTrackId;
+}
+
+MP4TrackId MP4File::AddSceneTrack()
+{
+ MP4TrackId trackId = AddSystemsTrack(MP4_SCENE_TRACK_TYPE);
+
+ AddTrackToIod(trackId);
+ AddTrackToOd(trackId);
+
+ return trackId;
+}
+
+MP4Atom* MP4File::GetTrakDamrAtom(MP4TrackId trackId)
+{
+ MP4Atom* amrAtom;
+ u_int16_t trackIndex = FindTrackIndex(trackId);
+ MP4Track* pTrack = m_pTracks[trackIndex];
+ ASSERT(pTrack);
+ MP4Atom* pTrakAtom = pTrack->GetTrakAtom();
+ ASSERT(pTrakAtom);
+ if ((amrAtom = pTrakAtom->FindAtom("trak.mdia.minf.stbl.stsd.sawb.damr"))) {
+ return amrAtom;
+ }
+ else if ((amrAtom = pTrakAtom->FindAtom("trak.mdia.minf.stbl.stsd.samr.damr"))) {
+ return amrAtom;
+ }
+ return NULL;
+}
+// NULL terminated list of brands which require the IODS atom
+char *brandsWithIods[] = { "mp42",
+ "isom",
+ NULL};
+
+bool MP4File::ShallHaveIods()
+{
+ u_int32_t compatibleBrandsCount;
+ MP4StringProperty *pMajorBrandProperty;
+
+ MP4Atom* ftypAtom = m_pRootAtom->FindAtom("ftyp");
+ ASSERT(ftypAtom);
+
+ // Check the major brand
+ ftypAtom->FindProperty(
+ "ftyp.majorBrand",
+ (MP4Property**)&pMajorBrandProperty);
+ ASSERT(pMajorBrandProperty);
+ for(u_int32_t j = 0 ; brandsWithIods[j] != NULL ; j++) {
+ if (!strcasecmp( ((MP4StringProperty*)pMajorBrandProperty)->GetValue(),
+ brandsWithIods[j]))
+ return true;
+ }
+
+ // Check the compatible brands
+ MP4Integer32Property* pCompatibleBrandsCountProperty;
+ ftypAtom->FindProperty(
+ "ftyp.compatibleBrandsCount",
+ (MP4Property**)&pCompatibleBrandsCountProperty);
+ ASSERT(pCompatibleBrandsCountProperty);
+
+ compatibleBrandsCount = pCompatibleBrandsCountProperty->GetValue();
+
+ MP4TableProperty* pCompatibleBrandsProperty;
+ ftypAtom->FindProperty(
+ "ftyp.compatibleBrands",
+ (MP4Property**)&pCompatibleBrandsProperty);
+
+ MP4StringProperty* pBrandProperty = (MP4StringProperty*)pCompatibleBrandsProperty->GetProperty(0);
+ ASSERT(pBrandProperty);
+
+ for(u_int32_t i = 0 ; i < compatibleBrandsCount ; i++) {
+ for(u_int32_t j = 0 ; brandsWithIods[j] != NULL ; j++) {
+ if (!strcasecmp(pBrandProperty->GetValue(i), brandsWithIods[j]))
+ return true;
+ }
+ }
+
+ return false;
+}
+
+void MP4File::SetAmrVendor(
+ MP4TrackId trackId,
+ u_int32_t vendor)
+{
+
+ MP4Atom* damrAtom = GetTrakDamrAtom(trackId);
+
+ if (damrAtom == NULL)
+ return;
+
+ MP4Integer32Property* pVendorProperty = NULL;
+
+ damrAtom->FindProperty("damr.vendor",
+ (MP4Property**)&pVendorProperty,
+ NULL);
+ ASSERT(pVendorProperty);
+
+ pVendorProperty->SetValue(vendor);
+
+ damrAtom->Rewrite();
+
+}
+
+void MP4File::SetAmrDecoderVersion(
+ MP4TrackId trackId,
+ u_int8_t decoderVersion)
+{
+ MP4Atom* damrAtom = GetTrakDamrAtom(trackId);
+
+ if (damrAtom == NULL)
+ return;
+
+ MP4Integer8Property* pDecoderVersionProperty;
+
+ damrAtom->FindProperty("damr.decoderVersion",
+ (MP4Property**)&pDecoderVersionProperty,
+ NULL);
+ ASSERT(pDecoderVersionProperty);
+
+ pDecoderVersionProperty->SetValue(decoderVersion);
+
+ damrAtom->Rewrite();
+}
+
+void MP4File::SetAmrModeSet(
+ MP4TrackId trackId,
+ u_int16_t modeSet)
+{
+ MP4Atom* damrAtom = GetTrakDamrAtom(trackId);
+
+ if (damrAtom == NULL)
+ return;
+
+ MP4Integer16Property* pModeSetProperty;
+
+ damrAtom->FindProperty("damr.modeSet",
+ (MP4Property**)&pModeSetProperty,
+ NULL);
+ ASSERT(pModeSetProperty);
+
+ pModeSetProperty->SetValue(modeSet);
+
+ damrAtom->Rewrite();
+
+}
+
+MP4TrackId MP4File::AddAmrAudioTrack(
+ u_int32_t timeScale,
+ u_int16_t modeSet,
+ u_int8_t modeChangePeriod,
+ u_int8_t framesPerSample,
+ bool isAmrWB)
+{
+
+ u_int32_t fixedSampleDuration = (timeScale * 20)/1000; // 20mSec/Sample
+
+ MP4TrackId trackId = AddTrack(MP4_AUDIO_TRACK_TYPE, timeScale);
+
+ AddTrackToOd(trackId);
+
+ SetTrackFloatProperty(trackId, "tkhd.volume", 1.0);
+
+ InsertChildAtom(MakeTrackName(trackId, "mdia.minf"), "smhd", 0);
+
+ AddChildAtom(MakeTrackName(trackId, "mdia.minf.stbl.stsd"), isAmrWB ? "sawb" : "samr");
+
+ // stsd is a unique beast in that it has a count of the number
+ // of child atoms that needs to be incremented after we add the mp4a atom
+ MP4Integer32Property* pStsdCountProperty;
+ FindIntegerProperty(
+ MakeTrackName(trackId, "mdia.minf.stbl.stsd.entryCount"),
+ (MP4Property**)&pStsdCountProperty);
+ pStsdCountProperty->IncrementValue();
+
+ if (isAmrWB) {
+ SetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsd.sawb.timeScale", timeScale);
+
+ SetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsd.sawb.damr.modeSet", modeSet);
+
+ SetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsd.sawb.damr.modeChangePeriod", modeChangePeriod);
+
+ SetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsd.sawb.damr.framesPerSample", framesPerSample);
+
+ m_pTracks[FindTrackIndex(trackId)]->
+ SetFixedSampleDuration(fixedSampleDuration);
+
+ } else {
+ SetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsd.samr.timeScale", timeScale);
+
+ SetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsd.samr.damr.modeSet", modeSet);
+
+ SetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsd.samr.damr.modeChangePeriod", modeChangePeriod);
+
+ SetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsd.samr.damr.framesPerSample", framesPerSample);
+ }
+
+ m_pTracks[FindTrackIndex(trackId)]->
+ SetFixedSampleDuration(fixedSampleDuration);
+
+ return trackId;
+}
+
+MP4TrackId MP4File::AddAudioTrack(
+ u_int32_t timeScale,
+ MP4Duration sampleDuration,
+ u_int8_t audioType)
+{
+ MP4TrackId trackId = AddTrack(MP4_AUDIO_TRACK_TYPE, timeScale);
+
+ AddTrackToOd(trackId);
+
+ SetTrackFloatProperty(trackId, "tkhd.volume", 1.0);
+
+ InsertChildAtom(MakeTrackName(trackId, "mdia.minf"), "smhd", 0);
+
+ AddChildAtom(MakeTrackName(trackId, "mdia.minf.stbl.stsd"), "mp4a");
+
+ // stsd is a unique beast in that it has a count of the number
+ // of child atoms that needs to be incremented after we add the mp4a atom
+ MP4Integer32Property* pStsdCountProperty;
+ FindIntegerProperty(
+ MakeTrackName(trackId, "mdia.minf.stbl.stsd.entryCount"),
+ (MP4Property**)&pStsdCountProperty);
+ pStsdCountProperty->IncrementValue();
+
+ SetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsd.mp4a.timeScale", timeScale);
+
+ SetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsd.mp4a.esds.ESID",
+#if 0
+ // note - for a file, these values need to
+ // be 0 - wmay - 04/16/2003
+ trackId
+#else
+ 0
+#endif
+ );
+
+ SetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsd.mp4a.esds.decConfigDescr.objectTypeId",
+ audioType);
+
+ SetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsd.mp4a.esds.decConfigDescr.streamType",
+ MP4AudioStreamType);
+
+ m_pTracks[FindTrackIndex(trackId)]->
+ SetFixedSampleDuration(sampleDuration);
+
+ return trackId;
+}
+
+MP4TrackId MP4File::AddEncAudioTrack(u_int32_t timeScale,
+ MP4Duration sampleDuration,
+ u_int8_t audioType,
+ u_int32_t scheme_type,
+ u_int16_t scheme_version,
+ u_int8_t key_ind_len,
+ u_int8_t iv_len,
+ bool selective_enc,
+ char *kms_uri
+ )
+{
+ u_int32_t original_fmt = 0;
+
+ MP4TrackId trackId = AddTrack(MP4_AUDIO_TRACK_TYPE, timeScale);
+
+ AddTrackToOd(trackId);
+
+ SetTrackFloatProperty(trackId, "tkhd.volume", 1.0);
+
+ InsertChildAtom(MakeTrackName(trackId, "mdia.minf"), "smhd", 0);
+
+ AddChildAtom(MakeTrackName(trackId, "mdia.minf.stbl.stsd"), "enca");
+
+ // stsd is a unique beast in that it has a count of the number
+ // of child atoms that needs to be incremented after we add the enca atom
+ MP4Integer32Property* pStsdCountProperty;
+ FindIntegerProperty(MakeTrackName(trackId, "mdia.minf.stbl.stsd.entryCount"),
+ (MP4Property**)&pStsdCountProperty);
+ pStsdCountProperty->IncrementValue();
+
+
+ /* set all the ismacryp-specific values */
+ // original format is mp4a
+ original_fmt = ('m'<<24 | 'p'<<16 | '4'<<8 | 'a');
+ SetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsd.enca.sinf.frma.data-format",
+ original_fmt);
+
+ SetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsd.enca.sinf.schm.scheme_type",
+ scheme_type);
+
+ SetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsd.enca.sinf.schm.scheme_version",
+ scheme_version);
+
+ SetTrackStringProperty(trackId,
+ "mdia.minf.stbl.stsd.enca.sinf.schi.iKMS.kms_URI",
+ kms_uri);
+ if (kms_uri != NULL) {
+ free(kms_uri);
+ }
+
+ SetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsd.enca.sinf.schi.iSFM.selective-encryption",
+ selective_enc);
+
+ SetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsd.enca.sinf.schi.iSFM.key-indicator-length",
+ key_ind_len);
+
+ SetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsd.enca.sinf.schi.iSFM.IV-length",
+ iv_len);
+ /* end ismacryp */
+
+ SetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsd.enca.timeScale", timeScale);
+
+ SetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsd.enca.esds.ESID",
+#if 0
+ // note - for a file, these values need to
+ // be 0 - wmay - 04/16/2003
+ trackId
+#else
+ 0
+#endif
+ );
+
+ SetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsd.enca.esds.decConfigDescr.objectTypeId",
+ audioType);
+
+ SetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsd.enca.esds.decConfigDescr.streamType",
+ MP4AudioStreamType);
+
+ m_pTracks[FindTrackIndex(trackId)]->
+ SetFixedSampleDuration(sampleDuration);
+
+ return trackId;
+}
+
+MP4TrackId MP4File::AddVideoTrack(
+ u_int32_t timeScale,
+ MP4Duration sampleDuration,
+ u_int16_t width,
+ u_int16_t height,
+ u_int8_t videoType)
+{
+ MP4TrackId trackId = AddTrack(MP4_VIDEO_TRACK_TYPE, timeScale);
+
+ AddTrackToOd(trackId);
+
+ SetTrackFloatProperty(trackId, "tkhd.width", width);
+ SetTrackFloatProperty(trackId, "tkhd.height", height);
+
+ InsertChildAtom(MakeTrackName(trackId, "mdia.minf"), "vmhd", 0);
+
+ AddChildAtom(MakeTrackName(trackId, "mdia.minf.stbl.stsd"), "mp4v");
+
+ // stsd is a unique beast in that it has a count of the number
+ // of child atoms that needs to be incremented after we add the mp4v atom
+ MP4Integer32Property* pStsdCountProperty;
+ FindIntegerProperty(
+ MakeTrackName(trackId, "mdia.minf.stbl.stsd.entryCount"),
+ (MP4Property**)&pStsdCountProperty);
+ pStsdCountProperty->IncrementValue();
+
+ SetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsd.mp4v.width", width);
+ SetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsd.mp4v.height", height);
+
+ SetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsd.mp4v.esds.ESID",
+#if 0
+ // note - for a file, these values need to
+ // be 0 - wmay - 04/16/2003
+ trackId
+#else
+ 0
+#endif
+ );
+
+ SetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsd.mp4v.esds.decConfigDescr.objectTypeId",
+ videoType);
+
+ SetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsd.mp4v.esds.decConfigDescr.streamType",
+ MP4VisualStreamType);
+
+ SetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsz.sampleSize", sampleDuration);
+
+ m_pTracks[FindTrackIndex(trackId)]->
+ SetFixedSampleDuration(sampleDuration);
+
+ return trackId;
+}
+
+MP4TrackId MP4File::AddEncVideoTrack(u_int32_t timeScale,
+ MP4Duration sampleDuration,
+ u_int16_t width,
+ u_int16_t height,
+ u_int8_t videoType,
+ u_int32_t scheme_type,
+ u_int16_t scheme_version,
+ u_int8_t key_ind_len,
+ u_int8_t iv_len,
+ bool selective_enc,
+ char *kms_uri
+ )
+{
+ u_int32_t original_fmt = 0;
+
+ MP4TrackId trackId = AddTrack(MP4_VIDEO_TRACK_TYPE, timeScale);
+
+ AddTrackToOd(trackId);
+
+ SetTrackFloatProperty(trackId, "tkhd.width", width);
+ SetTrackFloatProperty(trackId, "tkhd.height", height);
+
+ InsertChildAtom(MakeTrackName(trackId, "mdia.minf"), "vmhd", 0);
+
+ AddChildAtom(MakeTrackName(trackId, "mdia.minf.stbl.stsd"), "encv");
+
+ // stsd is a unique beast in that it has a count of the number
+ // of child atoms that needs to be incremented after we add the encv atom
+ MP4Integer32Property* pStsdCountProperty;
+ FindIntegerProperty(
+ MakeTrackName(trackId, "mdia.minf.stbl.stsd.entryCount"),
+ (MP4Property**)&pStsdCountProperty);
+ pStsdCountProperty->IncrementValue();
+
+ SetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsd.encv.width", width);
+ SetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsd.encv.height", height);
+
+ /* set all the ismacryp-specific values */
+ // original format is mp4v
+ original_fmt = ('m'<<24 | 'p'<<16 | '4'<<8 | 'v');
+ SetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsd.encv.sinf.frma.data-format",
+ original_fmt);
+
+ SetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsd.encv.sinf.schm.scheme_type",
+ scheme_type);
+
+ SetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsd.encv.sinf.schm.scheme_version",
+ scheme_version);
+
+ SetTrackStringProperty(trackId,
+ "mdia.minf.stbl.stsd.encv.sinf.schi.iKMS.kms_URI",
+ kms_uri);
+ if (kms_uri != NULL) {
+ free(kms_uri);
+ }
+
+ SetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsd.encv.sinf.schi.iSFM.selective-encryption",
+ selective_enc);
+
+ SetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsd.encv.sinf.schi.iSFM.key-indicator-length",
+ key_ind_len);
+
+ SetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsd.encv.sinf.schi.iSFM.IV-length",
+ iv_len);
+ /* end ismacryp */
+
+
+ SetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsd.encv.esds.ESID",
+#if 0
+ // note - for a file, these values need to
+ // be 0 - wmay - 04/16/2003
+ trackId
+#else
+ 0
+#endif
+ );
+
+ SetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsd.encv.esds.decConfigDescr.objectTypeId",
+ videoType);
+
+ SetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsd.encv.esds.decConfigDescr.streamType",
+ MP4VisualStreamType);
+
+ SetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsz.sampleSize", sampleDuration);
+
+ m_pTracks[FindTrackIndex(trackId)]->
+ SetFixedSampleDuration(sampleDuration);
+
+ return trackId;
+}
+void MP4File::SetH263Vendor(
+ MP4TrackId trackId,
+ u_int32_t vendor)
+{
+
+ MP4Atom* d263Atom = FindAtom(MakeTrackName(trackId, "mdia.minf.stbl.stsd.s263.d263"));
+
+ if (d263Atom == NULL)
+ return;
+
+ SetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsd.s263.d263.vendor",
+ vendor);
+
+ d263Atom->Rewrite();
+
+}
+
+void MP4File::SetH263DecoderVersion(
+ MP4TrackId trackId,
+ u_int8_t decoderVersion)
+{
+ MP4Atom* d263Atom = FindAtom(MakeTrackName(trackId, "mdia.minf.stbl.stsd.s263.d263"));
+
+ if (d263Atom == NULL) {
+ return;
+ }
+
+ SetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsd.s263.d263.decoderVersion",
+ decoderVersion);
+
+ d263Atom->Rewrite();
+}
+
+void MP4File::SetH263Bitrates(
+ MP4TrackId trackId,
+ u_int32_t avgBitrate,
+ u_int32_t maxBitrate)
+{
+ MP4Atom* bitrAtom = FindAtom(MakeTrackName(trackId, "mdia.minf.stbl.stsd.s263.d263.bitr"));
+
+ if (bitrAtom == NULL) {
+ VERBOSE_ERROR(m_verbosity, WARNING("Could not find bitr atom!"));
+ return;
+ }
+
+ SetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsd.s263.d263.bitr.avgBitrate",
+ avgBitrate);
+
+ SetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsd.s263.d263.bitr.maxBitrate",
+ maxBitrate);
+
+ bitrAtom->Rewrite();
+
+}
+
+MP4TrackId MP4File::AddH263VideoTrack(
+ u_int32_t timeScale,
+ MP4Duration sampleDuration,
+ u_int16_t width,
+ u_int16_t height,
+ u_int8_t h263Level,
+ u_int8_t h263Profile,
+ u_int32_t avgBitrate,
+ u_int32_t maxBitrate)
+
+{
+ MP4TrackId trackId = AddTrack(MP4_VIDEO_TRACK_TYPE, timeScale);
+
+ AddTrackToOd(trackId);
+
+ SetTrackFloatProperty(trackId, "tkhd.width", width);
+ SetTrackFloatProperty(trackId, "tkhd.height", height);
+
+ InsertChildAtom(MakeTrackName(trackId, "mdia.minf"), "vmhd", 0);
+
+ AddChildAtom(MakeTrackName(trackId, "mdia.minf.stbl.stsd"), "s263");
+
+ // stsd is a unique beast in that it has a count of the number
+ // of child atoms that needs to be incremented after we add the mp4v atom
+ MP4Integer32Property* pStsdCountProperty;
+ FindIntegerProperty(
+ MakeTrackName(trackId, "mdia.minf.stbl.stsd.entryCount"),
+ (MP4Property**)&pStsdCountProperty);
+ pStsdCountProperty->IncrementValue();
+
+ SetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsd.s263.width", width);
+ SetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsd.s263.height", height);
+
+ SetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsd.s263.d263.h263Level", h263Level);
+
+ SetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsd.s263.d263.h263Profile", h263Profile);
+
+ // Add the bitr atom
+ AddChildAtom(MakeTrackName(trackId, "mdia.minf.stbl.stsd.s263.d263"),
+ "bitr");
+
+ SetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsd.s263.d263.bitr.avgBitrate", avgBitrate);
+
+ SetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsd.s263.d263.bitr.maxBitrate", maxBitrate);
+
+
+ SetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsz.sampleSize", sampleDuration);
+
+ m_pTracks[FindTrackIndex(trackId)]->
+ SetFixedSampleDuration(sampleDuration);
+
+ return trackId;
+
+}
+
+MP4TrackId MP4File::AddHintTrack(MP4TrackId refTrackId)
+{
+ // validate reference track id
+ FindTrackIndex(refTrackId);
+
+ MP4TrackId trackId =
+ AddTrack(MP4_HINT_TRACK_TYPE, GetTrackTimeScale(refTrackId));
+
+ InsertChildAtom(MakeTrackName(trackId, "mdia.minf"), "hmhd", 0);
+
+ AddChildAtom(MakeTrackName(trackId, "mdia.minf.stbl.stsd"), "rtp ");
+
+ // stsd is a unique beast in that it has a count of the number
+ // of child atoms that needs to be incremented after we add the rtp atom
+ MP4Integer32Property* pStsdCountProperty;
+ FindIntegerProperty(
+ MakeTrackName(trackId, "mdia.minf.stbl.stsd.entryCount"),
+ (MP4Property**)&pStsdCountProperty);
+ pStsdCountProperty->IncrementValue();
+
+ SetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsd.rtp .tims.timeScale",
+ GetTrackTimeScale(trackId));
+
+ AddDescendantAtoms(MakeTrackName(trackId, NULL), "tref.hint");
+
+ AddTrackReference(MakeTrackName(trackId, "tref.hint"), refTrackId);
+
+ AddDescendantAtoms(MakeTrackName(trackId, NULL), "udta.hnti.sdp ");
+
+ AddDescendantAtoms(MakeTrackName(trackId, NULL), "udta.hinf");
+
+ return trackId;
+}
+
+void MP4File::DeleteTrack(MP4TrackId trackId)
+{
+ ProtectWriteOperation("MP4DeleteTrack");
+
+ u_int32_t trakIndex = FindTrakAtomIndex(trackId);
+ u_int16_t trackIndex = FindTrackIndex(trackId);
+ MP4Track* pTrack = m_pTracks[trackIndex];
+
+ MP4Atom* pTrakAtom = pTrack->GetTrakAtom();
+ ASSERT(pTrakAtom);
+
+ MP4Atom* pMoovAtom = FindAtom("moov");
+ ASSERT(pMoovAtom);
+
+ RemoveTrackFromIod(trackId, ShallHaveIods());
+ RemoveTrackFromOd(trackId);
+
+ if (trackId == m_odTrackId) {
+ m_odTrackId = 0;
+ }
+
+ pMoovAtom->DeleteChildAtom(pTrakAtom);
+
+ m_trakIds.Delete(trakIndex);
+
+ m_pTracks.Delete(trackIndex);
+
+ delete pTrack;
+ delete pTrakAtom;
+}
+
+u_int32_t MP4File::GetNumberOfTracks(const char* type, u_int8_t subType)
+{
+ if (type == NULL) {
+ return m_pTracks.Size();
+ }
+
+ u_int32_t typeSeen = 0;
+ const char* normType = MP4Track::NormalizeTrackType(type);
+
+ for (u_int32_t i = 0; i < m_pTracks.Size(); i++) {
+ if (!strcmp(normType, m_pTracks[i]->GetType())) {
+ if (subType) {
+ if (normType == MP4_AUDIO_TRACK_TYPE) {
+ if (subType != GetTrackEsdsObjectTypeId(m_pTracks[i]->GetId())) {
+ continue;
+ }
+ } else if (normType == MP4_VIDEO_TRACK_TYPE) {
+ if (subType != GetTrackEsdsObjectTypeId(m_pTracks[i]->GetId())) {
+ continue;
+ }
+ }
+ // else unknown subtype, ignore it
+ }
+ typeSeen++;
+ }
+ }
+ return typeSeen;
+}
+
+MP4TrackId MP4File::AllocTrackId()
+{
+ MP4TrackId trackId =
+ GetIntegerProperty("moov.mvhd.nextTrackId");
+
+ if (trackId <= 0xFFFF) {
+ // check that nextTrackid is correct
+ try {
+ FindTrackIndex(trackId);
+ // ERROR, this trackId is in use
+ }
+ catch (MP4Error* e) {
+ // OK, this trackId is not in use, proceed
+ delete e;
+ SetIntegerProperty("moov.mvhd.nextTrackId", trackId + 1);
+ return trackId;
+ }
+ }
+
+ // we need to search for a track id
+ for (trackId = 1; trackId <= 0xFFFF; trackId++) {
+ try {
+ FindTrackIndex(trackId);
+ // KEEP LOOKING, this trackId is in use
+ }
+ catch (MP4Error* e) {
+ // OK, this trackId is not in use, proceed
+ delete e;
+ return trackId;
+ }
+ }
+
+ // extreme case where mp4 file has 2^16 tracks in it
+ throw new MP4Error("too many existing tracks", "AddTrack");
+ return MP4_INVALID_TRACK_ID; // to keep MSVC happy
+}
+
+MP4TrackId MP4File::FindTrackId(u_int16_t trackIndex,
+ const char* type, u_int8_t subType)
+{
+ if (type == NULL) {
+ return m_pTracks[trackIndex]->GetId();
+ }
+
+ u_int32_t typeSeen = 0;
+ const char* normType = MP4Track::NormalizeTrackType(type);
+
+ for (u_int32_t i = 0; i < m_pTracks.Size(); i++) {
+ if (!strcmp(normType, m_pTracks[i]->GetType())) {
+ if (subType) {
+ if (normType == MP4_AUDIO_TRACK_TYPE) {
+ if (subType != GetTrackEsdsObjectTypeId(m_pTracks[i]->GetId())) {
+ continue;
+ }
+ } else if (normType == MP4_VIDEO_TRACK_TYPE) {
+ if (subType != GetTrackEsdsObjectTypeId(m_pTracks[i]->GetId())) {
+ continue;
+ }
+ }
+ // else unknown subtype, ignore it
+ }
+
+ if (trackIndex == typeSeen) {
+ return m_pTracks[i]->GetId();
+ }
+
+ typeSeen++;
+ }
+ }
+
+ throw new MP4Error("Track index doesn't exist - track %d type %s",
+ "FindTrackId",
+ trackIndex, type);
+ return MP4_INVALID_TRACK_ID; // satisfy MS compiler
+}
+
+u_int16_t MP4File::FindTrackIndex(MP4TrackId trackId)
+{
+ for (u_int32_t i = 0; i < m_pTracks.Size() && i <= 0xFFFF; i++) {
+ if (m_pTracks[i]->GetId() == trackId) {
+ return (u_int16_t)i;
+ }
+ }
+
+ throw new MP4Error("Track id %d doesn't exist", "FindTrackIndex", trackId);
+ return (u_int16_t)-1; // satisfy MS compiler
+}
+
+u_int16_t MP4File::FindTrakAtomIndex(MP4TrackId trackId)
+{
+ if (trackId) {
+ for (u_int32_t i = 0; i < m_trakIds.Size(); i++) {
+ if (m_trakIds[i] == trackId) {
+ return i;
+ }
+ }
+ }
+
+ throw new MP4Error("Track id %d doesn't exist", "FindTrakAtomIndex",
+ trackId);
+ return (u_int16_t)-1; // satisfy MS compiler
+}
+
+u_int32_t MP4File::GetSampleSize(MP4TrackId trackId, MP4SampleId sampleId)
+{
+ return m_pTracks[FindTrackIndex(trackId)]->GetSampleSize(sampleId);
+}
+
+u_int32_t MP4File::GetTrackMaxSampleSize(MP4TrackId trackId)
+{
+ return m_pTracks[FindTrackIndex(trackId)]->GetMaxSampleSize();
+}
+
+MP4SampleId MP4File::GetSampleIdFromTime(MP4TrackId trackId,
+ MP4Timestamp when, bool wantSyncSample)
+{
+ return m_pTracks[FindTrackIndex(trackId)]->
+ GetSampleIdFromTime(when, wantSyncSample);
+}
+
+MP4Timestamp MP4File::GetSampleTime(
+ MP4TrackId trackId, MP4SampleId sampleId)
+{
+ MP4Timestamp timestamp;
+ m_pTracks[FindTrackIndex(trackId)]->
+ GetSampleTimes(sampleId, ×tamp, NULL);
+ return timestamp;
+}
+
+MP4Duration MP4File::GetSampleDuration(
+ MP4TrackId trackId, MP4SampleId sampleId)
+{
+ MP4Duration duration;
+ m_pTracks[FindTrackIndex(trackId)]->
+ GetSampleTimes(sampleId, NULL, &duration);
+ return duration;
+}
+
+MP4Duration MP4File::GetSampleRenderingOffset(
+ MP4TrackId trackId, MP4SampleId sampleId)
+{
+ return m_pTracks[FindTrackIndex(trackId)]->
+ GetSampleRenderingOffset(sampleId);
+}
+
+bool MP4File::GetSampleSync(MP4TrackId trackId, MP4SampleId sampleId)
+{
+ return m_pTracks[FindTrackIndex(trackId)]->IsSyncSample(sampleId);
+}
+
+void MP4File::ReadSample(MP4TrackId trackId, MP4SampleId sampleId,
+ u_int8_t** ppBytes, u_int32_t* pNumBytes,
+ MP4Timestamp* pStartTime, MP4Duration* pDuration,
+ MP4Duration* pRenderingOffset, bool* pIsSyncSample)
+{
+ m_pTracks[FindTrackIndex(trackId)]->
+ ReadSample(sampleId, ppBytes, pNumBytes,
+ pStartTime, pDuration, pRenderingOffset, pIsSyncSample);
+}
+
+void MP4File::WriteSample(MP4TrackId trackId,
+ const u_int8_t* pBytes, u_int32_t numBytes,
+ MP4Duration duration, MP4Duration renderingOffset, bool isSyncSample)
+{
+ ProtectWriteOperation("MP4WriteSample");
+
+ m_pTracks[FindTrackIndex(trackId)]->
+ WriteSample(pBytes, numBytes, duration, renderingOffset, isSyncSample);
+
+ m_pModificationProperty->SetValue(MP4GetAbsTimestamp());
+}
+
+void MP4File::SetSampleRenderingOffset(MP4TrackId trackId,
+ MP4SampleId sampleId, MP4Duration renderingOffset)
+{
+ ProtectWriteOperation("MP4SetSampleRenderingOffset");
+
+ m_pTracks[FindTrackIndex(trackId)]->
+ SetSampleRenderingOffset(sampleId, renderingOffset);
+
+ m_pModificationProperty->SetValue(MP4GetAbsTimestamp());
+}
+
+char* MP4File::MakeTrackName(MP4TrackId trackId, const char* name)
+{
+ u_int16_t trakIndex = FindTrakAtomIndex(trackId);
+
+ static char trakName[1024];
+ if (name == NULL || name[0] == '\0') {
+ snprintf(trakName, sizeof(trakName),
+ "moov.trak[%u]", trakIndex);
+ } else {
+ snprintf(trakName, sizeof(trakName),
+ "moov.trak[%u].%s", trakIndex, name);
+ }
+ return trakName;
+}
+
+u_int64_t MP4File::GetTrackIntegerProperty(MP4TrackId trackId, const char* name)
+{
+ return GetIntegerProperty(MakeTrackName(trackId, name));
+}
+
+void MP4File::SetTrackIntegerProperty(MP4TrackId trackId, const char* name,
+ int64_t value)
+{
+ SetIntegerProperty(MakeTrackName(trackId, name), value);
+}
+
+float MP4File::GetTrackFloatProperty(MP4TrackId trackId, const char* name)
+{
+ return GetFloatProperty(MakeTrackName(trackId, name));
+}
+
+void MP4File::SetTrackFloatProperty(MP4TrackId trackId, const char* name,
+ float value)
+{
+ SetFloatProperty(MakeTrackName(trackId, name), value);
+}
+
+const char* MP4File::GetTrackStringProperty(MP4TrackId trackId, const char* name)
+{
+ return GetStringProperty(MakeTrackName(trackId, name));
+}
+
+void MP4File::SetTrackStringProperty(MP4TrackId trackId, const char* name,
+ const char* value)
+{
+ SetStringProperty(MakeTrackName(trackId, name), value);
+}
+
+void MP4File::GetTrackBytesProperty(MP4TrackId trackId, const char* name,
+ u_int8_t** ppValue, u_int32_t* pValueSize)
+{
+ GetBytesProperty(MakeTrackName(trackId, name), ppValue, pValueSize);
+}
+
+void MP4File::SetTrackBytesProperty(MP4TrackId trackId, const char* name,
+ const u_int8_t* pValue, u_int32_t valueSize)
+{
+ SetBytesProperty(MakeTrackName(trackId, name), pValue, valueSize);
+}
+
+
+// file level convenience functions
+
+MP4Duration MP4File::GetDuration()
+{
+ return m_pDurationProperty->GetValue();
+}
+
+void MP4File::SetDuration(MP4Duration value)
+{
+ m_pDurationProperty->SetValue(value);
+}
+
+u_int32_t MP4File::GetTimeScale()
+{
+ return m_pTimeScaleProperty->GetValue();
+}
+
+void MP4File::SetTimeScale(u_int32_t value)
+{
+ if (value == 0) {
+ throw new MP4Error("invalid value", "SetTimeScale");
+ }
+ m_pTimeScaleProperty->SetValue(value);
+}
+
+u_int8_t MP4File::GetODProfileLevel()
+{
+ return GetIntegerProperty("moov.iods.ODProfileLevelId");
+}
+
+void MP4File::SetODProfileLevel(u_int8_t value)
+{
+ SetIntegerProperty("moov.iods.ODProfileLevelId", value);
+}
+
+u_int8_t MP4File::GetSceneProfileLevel()
+{
+ return GetIntegerProperty("moov.iods.sceneProfileLevelId");
+}
+
+void MP4File::SetSceneProfileLevel(u_int8_t value)
+{
+ SetIntegerProperty("moov.iods.sceneProfileLevelId", value);
+}
+
+u_int8_t MP4File::GetVideoProfileLevel()
+{
+ return GetIntegerProperty("moov.iods.visualProfileLevelId");
+}
+
+void MP4File::SetVideoProfileLevel(u_int8_t value)
+{
+ SetIntegerProperty("moov.iods.visualProfileLevelId", value);
+}
+
+u_int8_t MP4File::GetAudioProfileLevel()
+{
+ return GetIntegerProperty("moov.iods.audioProfileLevelId");
+}
+
+void MP4File::SetAudioProfileLevel(u_int8_t value)
+{
+ SetIntegerProperty("moov.iods.audioProfileLevelId", value);
+}
+
+u_int8_t MP4File::GetGraphicsProfileLevel()
+{
+ return GetIntegerProperty("moov.iods.graphicsProfileLevelId");
+}
+
+void MP4File::SetGraphicsProfileLevel(u_int8_t value)
+{
+ SetIntegerProperty("moov.iods.graphicsProfileLevelId", value);
+}
+
+const char* MP4File::GetSessionSdp()
+{
+ return GetStringProperty("moov.udta.hnti.rtp .sdpText");
+}
+
+void MP4File::SetSessionSdp(const char* sdpString)
+{
+ AddDescendantAtoms("moov", "udta.hnti.rtp ");
+
+ SetStringProperty("moov.udta.hnti.rtp .sdpText", sdpString);
+}
+
+void MP4File::AppendSessionSdp(const char* sdpFragment)
+{
+ const char* oldSdpString = NULL;
+ try {
+ oldSdpString = GetSessionSdp();
+ }
+ catch (MP4Error* e) {
+ delete e;
+ SetSessionSdp(sdpFragment);
+ return;
+ }
+
+ char* newSdpString =
+ (char*)MP4Malloc(strlen(oldSdpString) + strlen(sdpFragment) + 1);
+ strcpy(newSdpString, oldSdpString);
+ strcat(newSdpString, sdpFragment);
+ SetSessionSdp(newSdpString);
+ MP4Free(newSdpString);
+}
+
+
+// track level convenience functions
+
+MP4SampleId MP4File::GetTrackNumberOfSamples(MP4TrackId trackId)
+{
+ return m_pTracks[FindTrackIndex(trackId)]->GetNumberOfSamples();
+}
+
+const char* MP4File::GetTrackType(MP4TrackId trackId)
+{
+ return m_pTracks[FindTrackIndex(trackId)]->GetType();
+}
+
+u_int32_t MP4File::GetTrackTimeScale(MP4TrackId trackId)
+{
+ return m_pTracks[FindTrackIndex(trackId)]->GetTimeScale();
+}
+
+void MP4File::SetTrackTimeScale(MP4TrackId trackId, u_int32_t value)
+{
+ if (value == 0) {
+ throw new MP4Error("invalid value", "SetTrackTimeScale");
+ }
+ SetTrackIntegerProperty(trackId, "mdia.mdhd.timeScale", value);
+}
+
+MP4Duration MP4File::GetTrackDuration(MP4TrackId trackId)
+{
+ return GetTrackIntegerProperty(trackId, "mdia.mdhd.duration");
+}
+
+// now GetTrackEsdsObjectTypeId
+u_int8_t MP4File::GetTrackAudioType(MP4TrackId trackId)
+{
+ return GetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsd.mp4a.esds.decConfigDescr.objectTypeId");
+}
+
+u_int8_t MP4File::GetTrackEsdsObjectTypeId(MP4TrackId trackId)
+{
+ // changed mp4a to * to handle enca case
+ return GetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsd.*.esds.decConfigDescr.objectTypeId");
+}
+
+u_int8_t MP4File::GetTrackAudioMpeg4Type(MP4TrackId trackId)
+{
+ // verify that track is an MPEG-4 audio track
+ if (GetTrackEsdsObjectTypeId(trackId) != MP4_MPEG4_AUDIO_TYPE) {
+ return MP4_MPEG4_INVALID_AUDIO_TYPE;
+ }
+
+ u_int8_t* pEsConfig = NULL;
+ u_int32_t esConfigSize;
+
+ // The Mpeg4 audio type (AAC, CELP, HXVC, ...)
+ // is the first 5 bits of the ES configuration
+
+ GetTrackESConfiguration(trackId, &pEsConfig, &esConfigSize);
+
+ if (esConfigSize < 1) {
+ return MP4_MPEG4_INVALID_AUDIO_TYPE;
+ }
+
+ u_int8_t mpeg4Type = (pEsConfig[0] >> 3);
+
+ free(pEsConfig);
+
+ return mpeg4Type;
+}
+
+// replaced with GetTrackEsdsObjectTypeId
+u_int8_t MP4File::GetTrackVideoType(MP4TrackId trackId)
+{
+ return GetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsd.mp4v.esds.decConfigDescr.objectTypeId");
+}
+
+MP4Duration MP4File::GetTrackFixedSampleDuration(MP4TrackId trackId)
+{
+ return m_pTracks[FindTrackIndex(trackId)]->GetFixedSampleDuration();
+}
+
+float MP4File::GetTrackVideoFrameRate(MP4TrackId trackId)
+{
+ MP4SampleId numSamples =
+ GetTrackNumberOfSamples(trackId);
+ u_int64_t
+ msDuration =
+ ConvertFromTrackDuration(trackId,
+ GetTrackDuration(trackId), MP4_MSECS_TIME_SCALE);
+
+ if (msDuration == 0) {
+ return 0.0;
+ }
+
+ return ((double)numSamples / UINT64_TO_DOUBLE(msDuration)) * MP4_MSECS_TIME_SCALE;
+}
+
+// true if media track encrypted according to ismacryp
+bool MP4File::IsIsmaCrypMediaTrack(MP4TrackId trackId)
+{
+ if (GetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsd.*.sinf.frma.data-format")
+ != (u_int64_t)-1) {
+ return true;
+ }
+ return false;
+}
+
+
+void MP4File::GetTrackESConfiguration(MP4TrackId trackId,
+ u_int8_t** ppConfig, u_int32_t* pConfigSize)
+{
+ GetTrackBytesProperty(trackId,
+ "mdia.minf.stbl.stsd.*[0].esds.decConfigDescr.decSpecificInfo[0].info",
+ ppConfig, pConfigSize);
+}
+
+void MP4File::SetTrackESConfiguration(MP4TrackId trackId,
+ const u_int8_t* pConfig, u_int32_t configSize)
+{
+ // get a handle on the track decoder config descriptor
+ MP4DescriptorProperty* pConfigDescrProperty = NULL;
+ FindProperty(MakeTrackName(trackId,
+ "mdia.minf.stbl.stsd.*[0].esds.decConfigDescr.decSpecificInfo"),
+ (MP4Property**)&pConfigDescrProperty);
+
+ if (pConfigDescrProperty == NULL) {
+ // probably trackId refers to a hint track
+ throw new MP4Error("no such property", "MP4SetTrackESConfiguration");
+ }
+
+ // lookup the property to store the configuration
+ MP4BytesProperty* pInfoProperty = NULL;
+ pConfigDescrProperty->FindProperty("decSpecificInfo[0].info",
+ (MP4Property**)&pInfoProperty);
+
+ // configuration being set for the first time
+ if (pInfoProperty == NULL) {
+ // need to create a new descriptor to hold it
+ MP4Descriptor* pConfigDescr =
+ pConfigDescrProperty->AddDescriptor(MP4DecSpecificDescrTag);
+ pConfigDescr->Generate();
+
+ pConfigDescrProperty->FindProperty(
+ "decSpecificInfo[0].info",
+ (MP4Property**)&pInfoProperty);
+ ASSERT(pInfoProperty);
+ }
+
+ // set the value
+ pInfoProperty->SetValue(pConfig, configSize);
+}
+
+const char* MP4File::GetHintTrackSdp(MP4TrackId hintTrackId)
+{
+ return GetTrackStringProperty(hintTrackId, "udta.hnti.sdp .sdpText");
+}
+
+void MP4File::SetHintTrackSdp(MP4TrackId hintTrackId, const char* sdpString)
+{
+ MP4Track* pTrack = m_pTracks[FindTrackIndex(hintTrackId)];
+
+ if (strcmp(pTrack->GetType(), MP4_HINT_TRACK_TYPE)) {
+ throw new MP4Error("track is not a hint track",
+ "MP4SetHintTrackSdp");
+ }
+
+ AddDescendantAtoms(
+ MakeTrackName(hintTrackId, NULL), "udta.hnti.sdp ");
+
+ SetTrackStringProperty(hintTrackId, "udta.hnti.sdp .sdpText", sdpString);
+}
+
+void MP4File::AppendHintTrackSdp(MP4TrackId hintTrackId,
+ const char* sdpFragment)
+{
+ const char* oldSdpString = NULL;
+ try {
+ oldSdpString = GetHintTrackSdp(hintTrackId);
+ }
+ catch (MP4Error* e) {
+ delete e;
+ SetHintTrackSdp(hintTrackId, sdpFragment);
+ return;
+ }
+
+ char* newSdpString =
+ (char*)MP4Malloc(strlen(oldSdpString) + strlen(sdpFragment) + 1);
+ strcpy(newSdpString, oldSdpString);
+ strcat(newSdpString, sdpFragment);
+ SetHintTrackSdp(hintTrackId, newSdpString);
+ MP4Free(newSdpString);
+}
+
+void MP4File::GetHintTrackRtpPayload(
+ MP4TrackId hintTrackId,
+ char** ppPayloadName,
+ u_int8_t* pPayloadNumber,
+ u_int16_t* pMaxPayloadSize,
+ char **ppEncodingParams)
+{
+ MP4Track* pTrack = m_pTracks[FindTrackIndex(hintTrackId)];
+
+ if (strcmp(pTrack->GetType(), MP4_HINT_TRACK_TYPE)) {
+ throw new MP4Error("track is not a hint track",
+ "MP4GetHintTrackRtpPayload");
+ }
+
+ ((MP4RtpHintTrack*)pTrack)->GetPayload(
+ ppPayloadName, pPayloadNumber, pMaxPayloadSize, ppEncodingParams);
+}
+
+void MP4File::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)
+{
+ MP4Track* pTrack = m_pTracks[FindTrackIndex(hintTrackId)];
+
+ if (strcmp(pTrack->GetType(), MP4_HINT_TRACK_TYPE)) {
+ throw new MP4Error("track is not a hint track",
+ "MP4SetHintTrackRtpPayload");
+ }
+
+ u_int8_t payloadNumber;
+ if (pPayloadNumber && *pPayloadNumber != MP4_SET_DYNAMIC_PAYLOAD) {
+ payloadNumber = *pPayloadNumber;
+ } else {
+ payloadNumber = AllocRtpPayloadNumber();
+ if (pPayloadNumber) {
+ *pPayloadNumber = payloadNumber;
+ }
+ }
+
+ ((MP4RtpHintTrack*)pTrack)->SetPayload(
+ payloadName, payloadNumber, maxPayloadSize, encoding_params,
+ include_rtp_map, include_mpeg4_esid);
+}
+
+u_int8_t MP4File::AllocRtpPayloadNumber()
+{
+ MP4Integer32Array usedPayloads;
+ u_int32_t i;
+
+ // collect rtp payload numbers in use by existing tracks
+ for (i = 0; i < m_pTracks.Size(); i++) {
+ MP4Atom* pTrakAtom = m_pTracks[i]->GetTrakAtom();
+
+ MP4Integer32Property* pPayloadProperty = NULL;
+ pTrakAtom->FindProperty("trak.udta.hinf.payt.payloadNumber",
+ (MP4Property**)&pPayloadProperty);
+
+ if (pPayloadProperty) {
+ usedPayloads.Add(pPayloadProperty->GetValue());
+ }
+ }
+
+ // search dynamic payload range for an available slot
+ u_int8_t payload;
+ for (payload = 96; payload < 128; payload++) {
+ for (i = 0; i < usedPayloads.Size(); i++) {
+ if (payload == usedPayloads[i]) {
+ break;
+ }
+ }
+ if (i == usedPayloads.Size()) {
+ break;
+ }
+ }
+
+ if (payload >= 128) {
+ throw new MP4Error("no more available rtp payload numbers",
+ "AllocRtpPayloadNumber");
+ }
+
+ return payload;
+}
+
+MP4TrackId MP4File::GetHintTrackReferenceTrackId(
+ MP4TrackId hintTrackId)
+{
+ MP4Track* pTrack = m_pTracks[FindTrackIndex(hintTrackId)];
+
+ if (strcmp(pTrack->GetType(), MP4_HINT_TRACK_TYPE)) {
+ throw new MP4Error("track is not a hint track",
+ "MP4GetHintTrackReferenceTrackId");
+ }
+
+ MP4Track* pRefTrack = ((MP4RtpHintTrack*)pTrack)->GetRefTrack();
+
+ if (pRefTrack == NULL) {
+ return MP4_INVALID_TRACK_ID;
+ }
+ return pRefTrack->GetId();
+}
+
+void MP4File::ReadRtpHint(
+ MP4TrackId hintTrackId,
+ MP4SampleId hintSampleId,
+ u_int16_t* pNumPackets)
+{
+ MP4Track* pTrack = m_pTracks[FindTrackIndex(hintTrackId)];
+
+ if (strcmp(pTrack->GetType(), MP4_HINT_TRACK_TYPE)) {
+ throw new MP4Error("track is not a hint track", "MP4ReadRtpHint");
+ }
+ ((MP4RtpHintTrack*)pTrack)->
+ ReadHint(hintSampleId, pNumPackets);
+}
+
+u_int16_t MP4File::GetRtpHintNumberOfPackets(
+ MP4TrackId hintTrackId)
+{
+ MP4Track* pTrack = m_pTracks[FindTrackIndex(hintTrackId)];
+
+ if (strcmp(pTrack->GetType(), MP4_HINT_TRACK_TYPE)) {
+ throw new MP4Error("track is not a hint track",
+ "MP4GetRtpHintNumberOfPackets");
+ }
+ return ((MP4RtpHintTrack*)pTrack)->GetHintNumberOfPackets();
+}
+
+int8_t MP4File::GetRtpPacketBFrame(
+ MP4TrackId hintTrackId,
+ u_int16_t packetIndex)
+{
+ MP4Track* pTrack = m_pTracks[FindTrackIndex(hintTrackId)];
+
+ if (strcmp(pTrack->GetType(), MP4_HINT_TRACK_TYPE)) {
+ throw new MP4Error("track is not a hint track",
+ "MP4GetRtpHintBFrame");
+ }
+ return ((MP4RtpHintTrack*)pTrack)->GetPacketBFrame(packetIndex);
+}
+
+int32_t MP4File::GetRtpPacketTransmitOffset(
+ MP4TrackId hintTrackId,
+ u_int16_t packetIndex)
+{
+ MP4Track* pTrack = m_pTracks[FindTrackIndex(hintTrackId)];
+
+ if (strcmp(pTrack->GetType(), MP4_HINT_TRACK_TYPE)) {
+ throw new MP4Error("track is not a hint track",
+ "MP4GetRtpPacketTransmitOffset");
+ }
+ return ((MP4RtpHintTrack*)pTrack)->GetPacketTransmitOffset(packetIndex);
+}
+
+void MP4File::ReadRtpPacket(
+ MP4TrackId hintTrackId,
+ u_int16_t packetIndex,
+ u_int8_t** ppBytes,
+ u_int32_t* pNumBytes,
+ u_int32_t ssrc,
+ bool includeHeader,
+ bool includePayload)
+{
+ MP4Track* pTrack = m_pTracks[FindTrackIndex(hintTrackId)];
+
+ if (strcmp(pTrack->GetType(), MP4_HINT_TRACK_TYPE)) {
+ throw new MP4Error("track is not a hint track", "MP4ReadPacket");
+ }
+ ((MP4RtpHintTrack*)pTrack)->ReadPacket(
+ packetIndex, ppBytes, pNumBytes,
+ ssrc, includeHeader, includePayload);
+}
+
+MP4Timestamp MP4File::GetRtpTimestampStart(
+ MP4TrackId hintTrackId)
+{
+ MP4Track* pTrack = m_pTracks[FindTrackIndex(hintTrackId)];
+
+ if (strcmp(pTrack->GetType(), MP4_HINT_TRACK_TYPE)) {
+ throw new MP4Error("track is not a hint track",
+ "MP4GetRtpTimestampStart");
+ }
+ return ((MP4RtpHintTrack*)pTrack)->GetRtpTimestampStart();
+}
+
+void MP4File::SetRtpTimestampStart(
+ MP4TrackId hintTrackId,
+ MP4Timestamp rtpStart)
+{
+ MP4Track* pTrack = m_pTracks[FindTrackIndex(hintTrackId)];
+
+ if (strcmp(pTrack->GetType(), MP4_HINT_TRACK_TYPE)) {
+ throw new MP4Error("track is not a hint track",
+ "MP4SetRtpTimestampStart");
+ }
+ ((MP4RtpHintTrack*)pTrack)->SetRtpTimestampStart(rtpStart);
+}
+
+void MP4File::AddRtpHint(MP4TrackId hintTrackId,
+ bool isBframe, u_int32_t timestampOffset)
+{
+ ProtectWriteOperation("MP4AddRtpHint");
+
+ MP4Track* pTrack = m_pTracks[FindTrackIndex(hintTrackId)];
+
+ if (strcmp(pTrack->GetType(), MP4_HINT_TRACK_TYPE)) {
+ throw new MP4Error("track is not a hint track", "MP4AddRtpHint");
+ }
+ ((MP4RtpHintTrack*)pTrack)->AddHint(isBframe, timestampOffset);
+}
+
+void MP4File::AddRtpPacket(
+ MP4TrackId hintTrackId, bool setMbit, int32_t transmitOffset)
+{
+ ProtectWriteOperation("MP4AddRtpPacket");
+
+ MP4Track* pTrack = m_pTracks[FindTrackIndex(hintTrackId)];
+
+ if (strcmp(pTrack->GetType(), MP4_HINT_TRACK_TYPE)) {
+ throw new MP4Error("track is not a hint track", "MP4AddRtpPacket");
+ }
+ ((MP4RtpHintTrack*)pTrack)->AddPacket(setMbit, transmitOffset);
+}
+
+void MP4File::AddRtpImmediateData(MP4TrackId hintTrackId,
+ const u_int8_t* pBytes, u_int32_t numBytes)
+{
+ ProtectWriteOperation("MP4AddRtpImmediateData");
+
+ MP4Track* pTrack = m_pTracks[FindTrackIndex(hintTrackId)];
+
+ if (strcmp(pTrack->GetType(), MP4_HINT_TRACK_TYPE)) {
+ throw new MP4Error("track is not a hint track",
+ "MP4AddRtpImmediateData");
+ }
+ ((MP4RtpHintTrack*)pTrack)->AddImmediateData(pBytes, numBytes);
+}
+
+void MP4File::AddRtpSampleData(MP4TrackId hintTrackId,
+ MP4SampleId sampleId, u_int32_t dataOffset, u_int32_t dataLength)
+{
+ ProtectWriteOperation("MP4AddRtpSampleData");
+
+ MP4Track* pTrack = m_pTracks[FindTrackIndex(hintTrackId)];
+
+ if (strcmp(pTrack->GetType(), MP4_HINT_TRACK_TYPE)) {
+ throw new MP4Error("track is not a hint track",
+ "MP4AddRtpSampleData");
+ }
+ ((MP4RtpHintTrack*)pTrack)->AddSampleData(
+ sampleId, dataOffset, dataLength);
+}
+
+void MP4File::AddRtpESConfigurationPacket(MP4TrackId hintTrackId)
+{
+ ProtectWriteOperation("MP4AddRtpESConfigurationPacket");
+
+ MP4Track* pTrack = m_pTracks[FindTrackIndex(hintTrackId)];
+
+ if (strcmp(pTrack->GetType(), MP4_HINT_TRACK_TYPE)) {
+ throw new MP4Error("track is not a hint track",
+ "MP4AddRtpESConfigurationPacket");
+ }
+ ((MP4RtpHintTrack*)pTrack)->AddESConfigurationPacket();
+}
+
+void MP4File::WriteRtpHint(MP4TrackId hintTrackId,
+ MP4Duration duration, bool isSyncSample)
+{
+ ProtectWriteOperation("MP4WriteRtpHint");
+
+ MP4Track* pTrack = m_pTracks[FindTrackIndex(hintTrackId)];
+
+ if (strcmp(pTrack->GetType(), MP4_HINT_TRACK_TYPE)) {
+ throw new MP4Error("track is not a hint track",
+ "MP4WriteRtpHint");
+ }
+ ((MP4RtpHintTrack*)pTrack)->WriteHint(duration, isSyncSample);
+}
+
+u_int64_t MP4File::ConvertFromMovieDuration(
+ MP4Duration duration,
+ u_int32_t timeScale)
+{
+ return MP4ConvertTime((u_int64_t)duration,
+ GetTimeScale(), timeScale);
+}
+
+u_int64_t MP4File::ConvertFromTrackTimestamp(
+ MP4TrackId trackId,
+ MP4Timestamp timeStamp,
+ u_int32_t timeScale)
+{
+ return MP4ConvertTime(timeStamp,
+ GetTrackTimeScale(trackId), timeScale);
+}
+
+MP4Timestamp MP4File::ConvertToTrackTimestamp(
+ MP4TrackId trackId,
+ u_int64_t timeStamp,
+ u_int32_t timeScale)
+{
+ return (MP4Timestamp)MP4ConvertTime(timeStamp,
+ timeScale, GetTrackTimeScale(trackId));
+}
+
+u_int64_t MP4File::ConvertFromTrackDuration(
+ MP4TrackId trackId,
+ MP4Duration duration,
+ u_int32_t timeScale)
+{
+ return MP4ConvertTime((u_int64_t)duration,
+ GetTrackTimeScale(trackId), timeScale);
+}
+
+MP4Duration MP4File::ConvertToTrackDuration(
+ MP4TrackId trackId,
+ u_int64_t duration,
+ u_int32_t timeScale)
+{
+ return (MP4Duration)MP4ConvertTime(duration,
+ timeScale, GetTrackTimeScale(trackId));
+}
+
+u_int8_t MP4File::ConvertTrackTypeToStreamType(const char* trackType)
+{
+ u_int8_t streamType;
+
+ if (!strcmp(trackType, MP4_OD_TRACK_TYPE)) {
+ streamType = MP4ObjectDescriptionStreamType;
+ } else if (!strcmp(trackType, MP4_SCENE_TRACK_TYPE)) {
+ streamType = MP4SceneDescriptionStreamType;
+ } else if (!strcmp(trackType, MP4_CLOCK_TRACK_TYPE)) {
+ streamType = MP4ClockReferenceStreamType;
+ } else if (!strcmp(trackType, MP4_MPEG7_TRACK_TYPE)) {
+ streamType = MP4Mpeg7StreamType;
+ } else if (!strcmp(trackType, MP4_OCI_TRACK_TYPE)) {
+ streamType = MP4OCIStreamType;
+ } else if (!strcmp(trackType, MP4_IPMP_TRACK_TYPE)) {
+ streamType = MP4IPMPStreamType;
+ } else if (!strcmp(trackType, MP4_MPEGJ_TRACK_TYPE)) {
+ streamType = MP4MPEGJStreamType;
+ } else {
+ streamType = MP4UserPrivateStreamType;
+ }
+
+ return streamType;
+}
+
+// edit list
+
+char* MP4File::MakeTrackEditName(
+ MP4TrackId trackId,
+ MP4EditId editId,
+ const char* name)
+{
+ char* trakName = MakeTrackName(trackId, NULL);
+
+ static char editName[1024];
+ snprintf(editName, sizeof(editName),
+ "%s.edts.elst.entries[%u].%s",
+ trakName, editId - 1, name);
+ return editName;
+}
+
+MP4EditId MP4File::AddTrackEdit(
+ MP4TrackId trackId,
+ MP4EditId editId)
+{
+ ProtectWriteOperation("AddTrackEdit");
+ return m_pTracks[FindTrackIndex(trackId)]->AddEdit(editId);
+}
+
+void MP4File::DeleteTrackEdit(
+ MP4TrackId trackId,
+ MP4EditId editId)
+{
+ ProtectWriteOperation("DeleteTrackEdit");
+ m_pTracks[FindTrackIndex(trackId)]->DeleteEdit(editId);
+}
+
+u_int32_t MP4File::GetTrackNumberOfEdits(
+ MP4TrackId trackId)
+{
+ return GetTrackIntegerProperty(trackId, "edts.elst.entryCount");
+}
+
+MP4Duration MP4File::GetTrackEditTotalDuration(
+ MP4TrackId trackId,
+ MP4EditId editId)
+{
+ return m_pTracks[FindTrackIndex(trackId)]->GetEditTotalDuration(editId);
+}
+
+MP4Timestamp MP4File::GetTrackEditStart(
+ MP4TrackId trackId,
+ MP4EditId editId)
+{
+ return m_pTracks[FindTrackIndex(trackId)]->GetEditStart(editId);
+}
+
+MP4Timestamp MP4File::GetTrackEditMediaStart(
+ MP4TrackId trackId,
+ MP4EditId editId)
+{
+ return GetIntegerProperty(
+ MakeTrackEditName(trackId, editId, "mediaTime"));
+}
+
+void MP4File::SetTrackEditMediaStart(
+ MP4TrackId trackId,
+ MP4EditId editId,
+ MP4Timestamp startTime)
+{
+ SetIntegerProperty(
+ MakeTrackEditName(trackId, editId, "mediaTime"),
+ startTime);
+}
+
+MP4Duration MP4File::GetTrackEditDuration(
+ MP4TrackId trackId,
+ MP4EditId editId)
+{
+ return GetIntegerProperty(
+ MakeTrackEditName(trackId, editId, "segmentDuration"));
+}
+
+void MP4File::SetTrackEditDuration(
+ MP4TrackId trackId,
+ MP4EditId editId,
+ MP4Duration duration)
+{
+ SetIntegerProperty(
+ MakeTrackEditName(trackId, editId, "segmentDuration"),
+ duration);
+}
+
+bool MP4File::GetTrackEditDwell(
+ MP4TrackId trackId,
+ MP4EditId editId)
+{
+ return (GetIntegerProperty(
+ MakeTrackEditName(trackId, editId, "mediaRate")) == 0);
+}
+
+void MP4File::SetTrackEditDwell(
+ MP4TrackId trackId,
+ MP4EditId editId,
+ bool dwell)
+{
+ SetIntegerProperty(
+ MakeTrackEditName(trackId, editId, "mediaRate"),
+ (dwell ? 0 : 1));
+}
+
+MP4SampleId MP4File::GetSampleIdFromEditTime(
+ MP4TrackId trackId,
+ MP4Timestamp when,
+ MP4Timestamp* pStartTime,
+ MP4Duration* pDuration)
+{
+ return m_pTracks[FindTrackIndex(trackId)]->GetSampleIdFromEditTime(
+ when, pStartTime, pDuration);
+}
+
--- /dev/null
+++ b/common/mp4v2/mp4file.h
@@ -1,0 +1,767 @@
+/*
+ * 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 - 2004. All Rights Reserved.
+ *
+ * 3GPP features implementation is based on 3GPP's TS26.234-v5.60,
+ * and was contributed by Ximpo Group Ltd.
+ *
+ * Portions created by Ximpo Group Ltd. are
+ * Copyright (C) Ximpo Group Ltd. 2003, 2004. All Rights Reserved.
+ *
+ * Contributor(s):
+ * Dave Mackie dmackie@cisco.com
+ * Alix Marchandise-Franquet alix@cisco.com
+ * Ximpo Group Ltd. mp4v2@ximpo.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;
+
+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, u_int32_t flags);
+ void CreateEx(const char* fileName, u_int32_t flags, char* majorBrand,
+ u_int32_t minorVersion, char** supportedBrands,
+ u_int32_t supportedBrandsCount);
+ 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(const char *atomName);
+
+ /* 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( // ismacryp
+ u_int32_t timeScale,
+ MP4Duration sampleDuration,
+ u_int8_t audioType,
+ u_int32_t scheme_type,
+ u_int16_t scheme_version,
+ u_int8_t key_ind_len,
+ u_int8_t iv_len,
+ bool selective_enc,
+ char *kms_uri);
+
+ void SetAmrVendor(
+ MP4TrackId trackId,
+ u_int32_t vendor);
+
+ void SetAmrDecoderVersion(
+ MP4TrackId trackId,
+ u_int8_t decoderVersion);
+
+ void SetAmrModeSet(
+ MP4TrackId trackId,
+ u_int16_t modeSet);
+
+ MP4TrackId AddAmrAudioTrack(
+ u_int32_t timeScale,
+ u_int16_t modeSet,
+ u_int8_t modeChangePeriod,
+ u_int8_t framesPerSample,
+ bool isAmrWB);
+
+ MP4TrackId AddVideoTrack(
+ u_int32_t timeScale,
+ MP4Duration sampleDuration,
+ u_int16_t width,
+ u_int16_t height,
+ u_int8_t videoType);
+
+ MP4TrackId AddEncVideoTrack( // ismacryp
+ u_int32_t timeScale,
+ MP4Duration sampleDuration,
+ u_int16_t width,
+ u_int16_t height,
+ u_int8_t videoType,
+ u_int32_t scheme_type,
+ u_int16_t scheme_version,
+ u_int8_t key_ind_len,
+ u_int8_t iv_len,
+ bool selective_enc,
+ char *kms_uri);
+
+ void SetH263Vendor(
+ MP4TrackId trackId,
+ u_int32_t vendor);
+
+ void SetH263DecoderVersion(
+ MP4TrackId trackId,
+ u_int8_t decoderVersion);
+
+ void SetH263Bitrates(
+ MP4TrackId,
+ u_int32_t avgBitrate,
+ u_int32_t maxBitrate);
+
+ MP4TrackId AddH263VideoTrack(
+ u_int32_t timeScale,
+ MP4Duration sampleDuration,
+ u_int16_t width,
+ u_int16_t height,
+ u_int8_t h263Level,
+ u_int8_t h263Profile,
+ u_int32_t avgBitrate,
+ u_int32_t maxBitrate);
+
+ 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);
+
+ // 3GPP specific functions
+ void MakeFtypAtom(char* majorBrand,
+ u_int32_t minorVersion,
+ char** supportedBrands,
+ u_int32_t supportedBrandsCount);
+ void Make3GPCompliant(const char* fileName,
+ char* majorBrand,
+ u_int32_t minorVersion,
+ char** supportedBrands,
+ u_int32_t supportedBrandsCount,
+ bool deleteIodsAtom);
+
+ // ISMA specific functions
+
+ // true if media track encrypted according to ismacryp
+ bool IsIsmaCrypMediaTrack(MP4TrackId trackId);
+
+ 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,
+ bool setMbit,
+ int32_t transmitOffset);
+
+ void AddRtpImmediateData(
+ MP4TrackId hintTrackId,
+ const u_int8_t* pBytes,
+ u_int32_t numBytes);
+
+ void AddRtpSampleData(
+ MP4TrackId hintTrackId,
+ MP4SampleId sampleId,
+ u_int32_t dataOffset,
+ u_int32_t dataLength);
+
+ void AddRtpESConfigurationPacket(
+ MP4TrackId hintTrackId);
+
+ void WriteRtpHint(
+ MP4TrackId hintTrackId,
+ MP4Duration duration,
+ bool isSyncSample);
+
+ u_int8_t AllocRtpPayloadNumber();
+
+ // edit list related
+
+ char* MakeTrackEditName(
+ MP4TrackId trackId,
+ MP4EditId editId,
+ const char* name);
+
+ MP4EditId AddTrackEdit(
+ MP4TrackId trackId,
+ MP4EditId editId = MP4_INVALID_EDIT_ID);
+
+ void DeleteTrackEdit(
+ MP4TrackId trackId,
+ MP4EditId editId);
+
+ u_int32_t GetTrackNumberOfEdits(
+ MP4TrackId trackId);
+
+ MP4Timestamp GetTrackEditStart(
+ MP4TrackId trackId,
+ MP4EditId editId);
+
+ MP4Duration GetTrackEditTotalDuration(
+ MP4TrackId trackId,
+ MP4EditId editId);
+
+ MP4Timestamp GetTrackEditMediaStart(
+ MP4TrackId trackId,
+ MP4EditId editId);
+
+ void SetTrackEditMediaStart(
+ MP4TrackId trackId,
+ MP4EditId editId,
+ MP4Timestamp startTime);
+
+ MP4Duration GetTrackEditDuration(
+ MP4TrackId trackId,
+ MP4EditId editId);
+
+ void SetTrackEditDuration(
+ MP4TrackId trackId,
+ MP4EditId editId,
+ MP4Duration duration);
+
+ bool GetTrackEditDwell(
+ MP4TrackId trackId,
+ MP4EditId editId);
+
+ void SetTrackEditDwell(
+ MP4TrackId trackId,
+ MP4EditId editId,
+ bool dwell);
+
+ MP4SampleId GetSampleIdFromEditTime(
+ MP4TrackId trackId,
+ MP4Timestamp when,
+ MP4Timestamp* pStartTime = NULL,
+ MP4Duration* pDuration = NULL);
+
+ /* iTunes metadata handling */
+ bool CreateMetadataAtom(const char* name);
+ bool MetadataDelete(void);
+
+ /* set metadata */
+ bool SetMetadataName(const char* value);
+ bool SetMetadataWriter(const char* value);
+ bool SetMetadataAlbum(const char* value);
+ bool SetMetadataArtist(const char* value);
+ bool SetMetadataTool(const char* value);
+ bool SetMetadataComment(const char* value);
+ bool SetMetadataYear(const char* value);
+ bool SetMetadataTrack(u_int16_t track, u_int16_t totalTracks);
+ bool SetMetadataDisk(u_int16_t disk, u_int16_t totalDisks);
+ bool SetMetadataGenre(const char *value);
+ bool SetMetadataTempo(u_int16_t tempo);
+ bool SetMetadataCompilation(u_int8_t compilation);
+ bool SetMetadataCoverArt(u_int8_t *coverArt, u_int32_t size);
+ bool SetMetadataFreeForm(char *name,
+ u_int8_t* pValue,
+ u_int32_t valueSize);
+
+ /* get metadata */
+ bool GetMetadataByIndex(u_int32_t index,
+ const char** ppName,
+ u_int8_t** ppValue,
+ u_int32_t* pValueSize);
+ bool GetMetadataName(char** value);
+ bool GetMetadataWriter(char** value);
+ bool GetMetadataAlbum(char** value);
+ bool GetMetadataArtist(char** value);
+ bool GetMetadataTool(char** value);
+ bool GetMetadataComment(char** value);
+ bool GetMetadataYear(char** value);
+ bool GetMetadataTrack(u_int16_t* track, u_int16_t* totalTracks);
+ bool GetMetadataDisk(u_int16_t* disk, u_int16_t* totalDisks);
+ bool GetMetadataGenre(char **value);
+ bool GetMetadataTempo(u_int16_t* tempo);
+ bool GetMetadataCompilation(u_int8_t* compilation);
+ bool GetMetadataCoverArt(u_int8_t **coverArt, u_int32_t* size);
+ bool GetMetadataFreeForm(char *name,
+ u_int8_t** pValue,
+ u_int32_t* valueSize);
+ /* end of MP4 API */
+
+ /* "protected" interface to be used only by friends in library */
+
+ u_int64_t GetPosition(FILE* pFile = NULL);
+ void SetPosition(u_int64_t pos, FILE* pFile = NULL);
+
+ u_int64_t GetSize();
+
+ u_int32_t ReadBytes(
+ u_int8_t* pBytes, u_int32_t numBytes, FILE* pFile = NULL);
+ u_int64_t ReadUInt(u_int8_t size);
+ u_int8_t ReadUInt8();
+ u_int16_t ReadUInt16();
+ u_int32_t ReadUInt24();
+ u_int32_t ReadUInt32();
+ u_int64_t ReadUInt64();
+ float ReadFixed16();
+ float ReadFixed32();
+ float ReadFloat();
+ char* ReadString();
+ char* ReadCountedString(
+ u_int8_t charSize = 1, bool allowExpandedCount = false);
+ u_int64_t ReadBits(u_int8_t numBits);
+ void FlushReadBits();
+ u_int32_t ReadMpegLength();
+
+ u_int32_t PeekBytes(
+ u_int8_t* pBytes, u_int32_t numBytes, FILE* pFile = NULL);
+
+ void WriteBytes(u_int8_t* pBytes, u_int32_t numBytes, FILE* pFile = NULL);
+ void WriteUInt(u_int64_t value, u_int8_t size);
+ void WriteUInt8(u_int8_t value);
+ void WriteUInt16(u_int16_t value);
+ void WriteUInt24(u_int32_t value);
+ void WriteUInt32(u_int32_t value);
+ void WriteUInt64(u_int64_t value);
+ void WriteFixed16(float value);
+ void WriteFixed32(float value);
+ void WriteFloat(float value);
+ void WriteString(char* string);
+ void WriteCountedString(char* string,
+ u_int8_t charSize = 1, bool allowExpandedCount = false);
+ void WriteBits(u_int64_t bits, u_int8_t numBits);
+ void PadWriteBits(u_int8_t pad = 0);
+ void FlushWriteBits();
+ void WriteMpegLength(u_int32_t value, bool compact = false);
+
+ void EnableMemoryBuffer(
+ u_int8_t* pBytes = NULL, u_int64_t numBytes = 0);
+ void DisableMemoryBuffer(
+ u_int8_t** ppBytes = NULL, u_int64_t* pNumBytes = NULL);
+
+ char GetMode() {
+ return m_mode;
+ }
+
+ MP4Track* GetTrack(MP4TrackId trackId);
+
+ MP4Duration UpdateDuration(MP4Duration duration);
+
+ MP4Atom* FindAtom(const char* name);
+
+ MP4Atom* AddChildAtom(
+ const char* parentName,
+ const char* childName);
+
+ MP4Atom* AddChildAtom(
+ MP4Atom* pParentAtom,
+ const char* childName);
+
+ MP4Atom* InsertChildAtom(
+ const char* parentName,
+ const char* childName,
+ u_int32_t index);
+
+ MP4Atom* InsertChildAtom(
+ MP4Atom* pParentAtom,
+ const char* childName,
+ u_int32_t index);
+
+ MP4Atom* AddDescendantAtoms(
+ const char* ancestorName,
+ const char* childName);
+
+ MP4Atom* AddDescendantAtoms(
+ MP4Atom* pAncestorAtom,
+ const char* childName);
+
+protected:
+ void Open(const char* fmode);
+ void ReadFromFile();
+ void GenerateTracks();
+ void BeginWrite();
+ void FinishWrite();
+ void CacheProperties();
+ void RewriteMdat(FILE* pReadFile, FILE* pWriteFile);
+ MP4Atom* GetTrakDamrAtom(MP4TrackId trackId);
+ bool ShallHaveIods();
+
+ const char* TempFileName();
+ void Rename(const char* existingFileName, const char* newFileName);
+
+ void ProtectWriteOperation(char* where);
+
+ void FindIntegerProperty(const char* name,
+ MP4Property** ppProperty, u_int32_t* pIndex = NULL);
+ void FindFloatProperty(const char* name,
+ MP4Property** ppProperty, u_int32_t* pIndex = NULL);
+ void FindStringProperty(const char* name,
+ MP4Property** ppProperty, u_int32_t* pIndex = NULL);
+ void FindBytesProperty(const char* name,
+ MP4Property** ppProperty, u_int32_t* pIndex = NULL);
+
+ bool FindProperty(const char* name,
+ MP4Property** ppProperty, u_int32_t* pIndex = NULL);
+
+ void AddTrackToIod(MP4TrackId trackId);
+
+ void RemoveTrackFromIod(MP4TrackId trackId, bool shallHaveIods = true);
+
+ void AddTrackToOd(MP4TrackId trackId);
+
+ void RemoveTrackFromOd(MP4TrackId trackId);
+
+ void GetTrackReferenceProperties(const char* trefName,
+ MP4Property** ppCountProperty, MP4Property** ppTrackIdProperty);
+
+ void AddTrackReference(const char* trefName, MP4TrackId refTrackId);
+
+ u_int32_t FindTrackReference(const char* trefName, MP4TrackId refTrackId);
+
+ void RemoveTrackReference(const char* trefName, MP4TrackId refTrackId);
+
+ void AddDataReference(MP4TrackId trackId, const char* url);
+
+ char* MakeTrackName(MP4TrackId trackId, const char* name);
+
+ u_int8_t ConvertTrackTypeToStreamType(const char* trackType);
+
+ void CreateIsmaIodFromFile(
+ MP4TrackId odTrackId,
+ MP4TrackId sceneTrackId,
+ MP4TrackId audioTrackId,
+ MP4TrackId videoTrackId,
+ u_int8_t** ppBytes,
+ u_int64_t* pNumBytes);
+
+ MP4Descriptor* CreateESD(
+ MP4DescriptorProperty* pEsProperty,
+ u_int32_t esid,
+ u_int8_t objectType,
+ u_int8_t streamType,
+ u_int32_t bufferSize,
+ u_int32_t bitrate,
+ u_int8_t* pConfig,
+ u_int32_t configLength,
+ char* url);
+
+ void CreateIsmaODUpdateCommandFromFileForFile(
+ MP4TrackId odTrackId,
+ MP4TrackId audioTrackId,
+ MP4TrackId videoTrackId,
+ u_int8_t** ppBytes,
+ u_int64_t* pNumBytes);
+
+ void CreateIsmaODUpdateCommandFromFileForStream(
+ MP4TrackId audioTrackId,
+ MP4TrackId videoTrackId,
+ u_int8_t** ppBytes,
+ u_int64_t* pNumBytes);
+
+ void CreateIsmaODUpdateCommandForStream(
+ MP4DescriptorProperty* pAudioEsdProperty,
+ MP4DescriptorProperty* pVideoEsdProperty,
+ u_int8_t** ppBytes,
+ u_int64_t* pNumBytes);
+
+ void CreateIsmaSceneCommand(
+ bool hasAudio,
+ bool hasVideo,
+ u_int8_t** ppBytes,
+ u_int64_t* pNumBytes);
+
+protected:
+ char* m_fileName;
+ FILE* m_pFile;
+ u_int64_t m_orgFileSize;
+ u_int64_t m_fileSize;
+ MP4Atom* m_pRootAtom;
+ MP4Integer32Array m_trakIds;
+ MP4TrackArray m_pTracks;
+ MP4TrackId m_odTrackId;
+ u_int32_t m_verbosity;
+ char m_mode;
+ u_int32_t m_createFlags;
+ bool m_useIsma;
+
+ // cached properties
+ MP4IntegerProperty* m_pModificationProperty;
+ MP4Integer32Property* m_pTimeScaleProperty;
+ MP4IntegerProperty* m_pDurationProperty;
+
+ // read/write in memory
+ u_int8_t* m_memoryBuffer;
+ u_int64_t m_memoryBufferPosition;
+ u_int64_t m_memoryBufferSize;
+
+ // bit read/write buffering
+ u_int8_t m_numReadBits;
+ u_int8_t m_bufReadBits;
+ u_int8_t m_numWriteBits;
+ u_int8_t m_bufWriteBits;
+};
+
+#endif /* __MP4_FILE_INCLUDED__ */
--- /dev/null
+++ b/common/mp4v2/mp4file_io.cpp
@@ -1,0 +1,557 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+// MP4File low level IO support
+
+u_int64_t MP4File::GetPosition(FILE* pFile)
+{
+ if (m_memoryBuffer == NULL) {
+ if (pFile == NULL) {
+ ASSERT(m_pFile);
+ pFile = m_pFile;
+ }
+
+ fpos_t fpos;
+ if (fgetpos(pFile, &fpos) < 0) {
+ throw new MP4Error(errno, "MP4GetPosition");
+ }
+ uint64_t ret;
+ FPOS_TO_VAR(fpos, uint64_t, ret);
+ return ret;
+ } else {
+ return m_memoryBufferPosition;
+ }
+}
+
+void MP4File::SetPosition(u_int64_t pos, FILE* pFile)
+{
+ if (m_memoryBuffer == NULL) {
+ if (pFile == NULL) {
+ ASSERT(m_pFile);
+ pFile = m_pFile;
+ }
+
+ fpos_t fpos;
+ VAR_TO_FPOS(fpos, pos);
+ if (fsetpos(pFile, &fpos) < 0) {
+ throw new MP4Error(errno, "MP4SetPosition");
+ }
+ } else {
+ if (pos >= m_memoryBufferSize) {
+ // abort();
+ throw new MP4Error("position out of range", "MP4SetPosition");
+ }
+ m_memoryBufferPosition = pos;
+ }
+}
+
+u_int64_t MP4File::GetSize()
+{
+ if (m_mode == 'w') {
+ // we're always positioned at the end of file in write mode
+ // except for short intervals in ReadSample and FinishWrite routines
+ // so we rely on the faster approach of GetPosition()
+ // instead of flushing to disk, and then stat'ing the file
+ m_fileSize = GetPosition();
+ } // else read mode, fileSize was determined at Open()
+
+ return m_fileSize;
+}
+
+u_int32_t MP4File::ReadBytes(u_int8_t* pBytes, u_int32_t numBytes, FILE* pFile)
+{
+ // handle degenerate cases
+ if (numBytes == 0) {
+ return 0;
+ }
+
+ ASSERT(pBytes);
+ WARNING(m_numReadBits > 0);
+
+ if (pFile == NULL) {
+ pFile = m_pFile;
+ }
+ ASSERT(pFile);
+
+ if (m_memoryBuffer == NULL) {
+ if (fread(pBytes, 1, numBytes, pFile) != numBytes) {
+ if (feof(pFile)) {
+ throw new MP4Error(
+ "not enough bytes, reached end-of-file",
+ "MP4ReadBytes");
+ } else {
+ throw new MP4Error(errno, "MP4ReadBytes");
+ }
+ }
+ } else {
+ if (m_memoryBufferPosition + numBytes > m_memoryBufferSize) {
+ throw new MP4Error(
+ "not enough bytes, reached end-of-memory",
+ "MP4ReadBytes");
+ }
+ memcpy(pBytes, &m_memoryBuffer[m_memoryBufferPosition], numBytes);
+ m_memoryBufferPosition += numBytes;
+ }
+ return numBytes;
+}
+
+u_int32_t MP4File::PeekBytes(u_int8_t* pBytes, u_int32_t numBytes, FILE* pFile)
+{
+ u_int64_t pos = GetPosition(pFile);
+ ReadBytes(pBytes, numBytes, pFile);
+ SetPosition(pos, pFile);
+ return numBytes;
+}
+
+void MP4File::EnableMemoryBuffer(u_int8_t* pBytes, u_int64_t numBytes)
+{
+ ASSERT(m_memoryBuffer == NULL);
+
+ if (pBytes) {
+ m_memoryBuffer = pBytes;
+ m_memoryBufferSize = numBytes;
+ } else {
+ if (numBytes) {
+ m_memoryBufferSize = numBytes;
+ } else {
+ m_memoryBufferSize = 4096;
+ }
+ m_memoryBuffer = (u_int8_t*)MP4Malloc(m_memoryBufferSize);
+ }
+ m_memoryBufferPosition = 0;
+}
+
+void MP4File::DisableMemoryBuffer(u_int8_t** ppBytes, u_int64_t* pNumBytes)
+{
+ ASSERT(m_memoryBuffer != NULL);
+
+ if (ppBytes) {
+ *ppBytes = m_memoryBuffer;
+ }
+ if (pNumBytes) {
+ *pNumBytes = m_memoryBufferPosition;
+ }
+
+ m_memoryBuffer = NULL;
+ m_memoryBufferSize = 0;
+ m_memoryBufferPosition = 0;
+}
+
+void MP4File::WriteBytes(u_int8_t* pBytes, u_int32_t numBytes, FILE* pFile)
+{
+ ASSERT(m_numWriteBits == 0 || m_numWriteBits >= 8);
+
+ if (pBytes == NULL || numBytes == 0) {
+ return;
+ }
+
+ if (m_memoryBuffer == NULL) {
+ if (pFile == NULL) {
+ ASSERT(m_pFile);
+ pFile = m_pFile;
+ }
+
+ u_int32_t rc = fwrite(pBytes, 1, numBytes, pFile);
+ if (rc != numBytes) {
+ throw new MP4Error(errno, "MP4WriteBytes");
+ }
+ } else {
+ if (m_memoryBufferPosition + numBytes > m_memoryBufferSize) {
+ m_memoryBufferSize = 2 * (m_memoryBufferSize + numBytes);
+ m_memoryBuffer = (u_int8_t*)
+ MP4Realloc(m_memoryBuffer, m_memoryBufferSize);
+ }
+ memcpy(&m_memoryBuffer[m_memoryBufferPosition], pBytes, numBytes);
+ m_memoryBufferPosition += numBytes;
+ }
+}
+
+u_int64_t MP4File::ReadUInt(u_int8_t size)
+{
+ switch (size) {
+ case 1:
+ return ReadUInt8();
+ case 2:
+ return ReadUInt16();
+ case 3:
+ return ReadUInt24();
+ case 4:
+ return ReadUInt32();
+ case 8:
+ return ReadUInt64();
+ default:
+ ASSERT(false);
+ return 0;
+ }
+}
+
+void MP4File::WriteUInt(u_int64_t value, u_int8_t size)
+{
+ switch (size) {
+ case 1:
+ WriteUInt8(value);
+ case 2:
+ WriteUInt16(value);
+ case 3:
+ WriteUInt24(value);
+ case 4:
+ WriteUInt32(value);
+ case 8:
+ WriteUInt64(value);
+ default:
+ ASSERT(false);
+ }
+}
+
+u_int8_t MP4File::ReadUInt8()
+{
+ u_int8_t data;
+ ReadBytes(&data, 1);
+ return data;
+}
+
+void MP4File::WriteUInt8(u_int8_t value)
+{
+ WriteBytes(&value, 1);
+}
+
+u_int16_t MP4File::ReadUInt16()
+{
+ u_int8_t data[2];
+ ReadBytes(&data[0], 2);
+ return ((data[0] << 8) | data[1]);
+}
+
+void MP4File::WriteUInt16(u_int16_t value)
+{
+ u_int8_t data[2];
+ data[0] = (value >> 8) & 0xFF;
+ data[1] = value & 0xFF;
+ WriteBytes(data, 2);
+}
+
+u_int32_t MP4File::ReadUInt24()
+{
+ u_int8_t data[3];
+ ReadBytes(&data[0], 3);
+ return ((data[0] << 16) | (data[1] << 8) | data[2]);
+}
+
+void MP4File::WriteUInt24(u_int32_t value)
+{
+ u_int8_t data[3];
+ data[0] = (value >> 16) & 0xFF;
+ data[1] = (value >> 8) & 0xFF;
+ data[2] = value & 0xFF;
+ WriteBytes(data, 3);
+}
+
+u_int32_t MP4File::ReadUInt32()
+{
+ u_int8_t data[4];
+ ReadBytes(&data[0], 4);
+ return ((data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3]);
+}
+
+void MP4File::WriteUInt32(u_int32_t value)
+{
+ u_int8_t data[4];
+ data[0] = (value >> 24) & 0xFF;
+ data[1] = (value >> 16) & 0xFF;
+ data[2] = (value >> 8) & 0xFF;
+ data[3] = value & 0xFF;
+ WriteBytes(data, 4);
+}
+
+u_int64_t MP4File::ReadUInt64()
+{
+ u_int8_t data[8];
+ u_int64_t result = 0;
+ u_int64_t temp;
+
+ ReadBytes(&data[0], 8);
+
+ for (int i = 0; i < 8; i++) {
+ temp = data[i];
+ result |= temp << ((7 - i) * 8);
+ }
+ return result;
+}
+
+void MP4File::WriteUInt64(u_int64_t value)
+{
+ u_int8_t data[8];
+
+ for (int i = 7; i >= 0; i--) {
+ data[i] = value & 0xFF;
+ value >>= 8;
+ }
+ WriteBytes(data, 8);
+}
+
+float MP4File::ReadFixed16()
+{
+ u_int8_t iPart = ReadUInt8();
+ u_int8_t fPart = ReadUInt8();
+
+ return iPart + (((float)fPart) / 0x100);
+}
+
+void MP4File::WriteFixed16(float value)
+{
+ if (value >= 0x100) {
+ throw new MP4Error(ERANGE, "MP4WriteFixed16");
+ }
+
+ u_int8_t iPart = (u_int8_t)value;
+ u_int8_t fPart = (u_int8_t)((value - iPart) * 0x100);
+
+ WriteUInt8(iPart);
+ WriteUInt8(fPart);
+}
+
+float MP4File::ReadFixed32()
+{
+ u_int16_t iPart = ReadUInt16();
+ u_int16_t fPart = ReadUInt16();
+
+ return iPart + (((float)fPart) / 0x10000);
+}
+
+void MP4File::WriteFixed32(float value)
+{
+ if (value >= 0x10000) {
+ throw new MP4Error(ERANGE, "MP4WriteFixed32");
+ }
+
+ u_int16_t iPart = (u_int16_t)value;
+ u_int16_t fPart = (u_int16_t)((value - iPart) * 0x10000);
+
+ WriteUInt16(iPart);
+ WriteUInt16(fPart);
+}
+
+float MP4File::ReadFloat()
+{
+ union {
+ float f;
+ u_int32_t i;
+ } u;
+
+ u.i = ReadUInt32();
+ return u.f;
+}
+
+void MP4File::WriteFloat(float value)
+{
+ union {
+ float f;
+ u_int32_t i;
+ } u;
+
+ u.f = value;
+ WriteUInt32(u.i);
+}
+
+char* MP4File::ReadString()
+{
+ u_int32_t length = 0;
+ u_int32_t alloced = 64;
+ char* data = (char*)MP4Malloc(alloced);
+
+ do {
+ if (length == alloced) {
+ data = (char*)MP4Realloc(data, alloced * 2);
+ }
+ ReadBytes((u_int8_t*)&data[length], 1);
+ length++;
+ } while (data[length - 1] != 0);
+
+ data = (char*)MP4Realloc(data, length);
+ return data;
+}
+
+void MP4File::WriteString(char* string)
+{
+ if (string == NULL) {
+ static u_int8_t zero = 0;
+ WriteBytes(&zero, 1);
+ } else {
+ WriteBytes((u_int8_t*)string, strlen(string) + 1);
+ }
+}
+
+char* MP4File::ReadCountedString(u_int8_t charSize, bool allowExpandedCount)
+{
+ u_int32_t charLength;
+ if (allowExpandedCount) {
+ u_int8_t b;
+ charLength = 0;
+ do {
+ b = ReadUInt8();
+ charLength += b;
+ } while (b == 255);
+ } else {
+ charLength = ReadUInt8();
+ }
+
+ u_int32_t byteLength = charLength * charSize;
+ char* data = (char*)MP4Malloc(byteLength + 1);
+ if (byteLength > 0) {
+ ReadBytes((u_int8_t*)data, byteLength);
+ }
+ data[byteLength] = '\0';
+ return data;
+}
+
+void MP4File::WriteCountedString(char* string,
+ u_int8_t charSize, bool allowExpandedCount)
+{
+ u_int32_t byteLength;
+ if (string) {
+ byteLength = strlen(string);
+ } else {
+ byteLength = 0;
+ }
+ u_int32_t charLength = byteLength / charSize;
+
+ if (allowExpandedCount) {
+ while (charLength >= 0xFF) {
+ WriteUInt8(0xFF);
+ charLength -= 0xFF;
+ }
+ WriteUInt8(charLength);
+ } else {
+ if (charLength > 255) {
+ throw new MP4Error(ERANGE, "Length is %d", "MP4WriteCountedString", charLength);
+ }
+ WriteUInt8(charLength);
+ }
+
+ if (byteLength > 0) {
+ WriteBytes((u_int8_t*)string, byteLength);
+ }
+}
+
+u_int64_t MP4File::ReadBits(u_int8_t numBits)
+{
+ ASSERT(numBits > 0);
+ ASSERT(numBits <= 64);
+
+ u_int64_t bits = 0;
+
+ for (u_int8_t i = numBits; i > 0; i--) {
+ if (m_numReadBits == 0) {
+ ReadBytes(&m_bufReadBits, 1);
+ m_numReadBits = 8;
+ }
+ bits = (bits << 1) | ((m_bufReadBits >> (--m_numReadBits)) & 1);
+ }
+
+ return bits;
+}
+
+void MP4File::FlushReadBits()
+{
+ // eat any remaining bits in the read buffer
+ m_numReadBits = 0;
+}
+
+void MP4File::WriteBits(u_int64_t bits, u_int8_t numBits)
+{
+ ASSERT(numBits <= 64);
+
+ for (u_int8_t i = numBits; i > 0; i--) {
+ m_bufWriteBits |=
+ (((bits >> (i - 1)) & 1) << (8 - ++m_numWriteBits));
+
+ if (m_numWriteBits == 8) {
+ FlushWriteBits();
+ }
+ }
+}
+
+void MP4File::PadWriteBits(u_int8_t pad)
+{
+ if (m_numWriteBits) {
+ WriteBits(pad ? 0xFF : 0x00, 8 - m_numWriteBits);
+ }
+}
+
+void MP4File::FlushWriteBits()
+{
+ if (m_numWriteBits > 0) {
+ WriteBytes(&m_bufWriteBits, 1);
+ m_numWriteBits = 0;
+ m_bufWriteBits = 0;
+ }
+}
+
+u_int32_t MP4File::ReadMpegLength()
+{
+ u_int32_t length = 0;
+ u_int8_t numBytes = 0;
+ u_int8_t b;
+
+ do {
+ b = ReadUInt8();
+ length = (length << 7) | (b & 0x7F);
+ numBytes++;
+ } while ((b & 0x80) && numBytes < 4);
+
+ return length;
+}
+
+void MP4File::WriteMpegLength(u_int32_t value, bool compact)
+{
+ if (value > 0x0FFFFFFF) {
+ throw new MP4Error(ERANGE, "MP4WriteMpegLength");
+ }
+
+ int8_t numBytes;
+
+ if (compact) {
+ if (value <= 0x7F) {
+ numBytes = 1;
+ } else if (value <= 0x3FFF) {
+ numBytes = 2;
+ } else if (value <= 0x1FFFFF) {
+ numBytes = 3;
+ } else {
+ numBytes = 4;
+ }
+ } else {
+ numBytes = 4;
+ }
+
+ int8_t i = numBytes;
+ do {
+ i--;
+ u_int8_t b = (value >> (i * 7)) & 0x7F;
+ if (i > 0) {
+ b |= 0x80;
+ }
+ WriteUInt8(b);
+ } while (i > 0);
+}
+
--- /dev/null
+++ b/common/mp4v2/mp4info.cpp
@@ -1,0 +1,485 @@
+/*
+ * 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-2002. All Rights Reserved.
+ *
+ * Portions created by Ximpo Group Ltd. are
+ * Copyright (C) Ximpo Group Ltd. 2003, 2004. All Rights Reserved.
+ *
+ * Contributor(s):
+ * Dave Mackie dmackie@cisco.com
+ * Bill May wmay@cisco.com
+ * Alix Marchandise-Franquet alix@cisco.com
+ * Ximpo Group Ltd. mp4v2@ximpo.com
+ */
+
+#include "mp4common.h"
+
+static char* PrintAudioInfo(
+ MP4FileHandle mp4File,
+ MP4TrackId trackId)
+{
+ static const char* mpeg4AudioNames[] = {
+ "MPEG-4 AAC main",
+ "MPEG-4 AAC LC",
+ "MPEG-4 AAC SSR",
+ "MPEG-4 AAC LTP",
+ NULL,
+ "MPEG-4 AAC Scalable",
+ "MPEG-4 TwinVQ",
+ "MPEG-4 CELP",
+ "MPEG-4 HVXC",
+ NULL, NULL,
+ "MPEG-4 TTSI",
+ "MPEG-4 Main Synthetic",
+ "MPEG-4 Wavetable Syn",
+ "MPEG-4 General MIDI",
+ "MPEG-4 Algo Syn and Audio FX",
+ "MPEG-4 ER AAC LC",
+ NULL,
+ "MPEG-4 ER AAC LTP",
+ "MPEG-4 ER AAC Scalable",
+ "MPEG-4 ER TwinVQ",
+ "MPEG-4 ER BSAC",
+ "MPEG-4 ER ACC LD",
+ "MPEG-4 ER CELP",
+ "MPEG-4 ER HVXC",
+ "MPEG-4 ER HILN",
+ "MPEG-4 ER Parametric",
+ };
+
+ static u_int8_t mpegAudioTypes[] = {
+ MP4_MPEG2_AAC_MAIN_AUDIO_TYPE, // 0x66
+ MP4_MPEG2_AAC_LC_AUDIO_TYPE, // 0x67
+ MP4_MPEG2_AAC_SSR_AUDIO_TYPE, // 0x68
+ MP4_MPEG2_AUDIO_TYPE, // 0x69
+ MP4_MPEG1_AUDIO_TYPE, // 0x6B
+ // private types
+ MP4_PCM16_LITTLE_ENDIAN_AUDIO_TYPE,
+ MP4_VORBIS_AUDIO_TYPE,
+ MP4_ALAW_AUDIO_TYPE,
+ MP4_ULAW_AUDIO_TYPE,
+ MP4_G723_AUDIO_TYPE,
+ MP4_PCM16_BIG_ENDIAN_AUDIO_TYPE,
+ };
+ static const char* mpegAudioNames[] = {
+ "MPEG-2 AAC Main",
+ "MPEG-2 AAC LC",
+ "MPEG-2 AAC SSR",
+ "MPEG-2 Audio (13818-3)",
+ "MPEG-1 Audio (11172-3)",
+ // private types
+ "PCM16 (little endian)",
+ "Vorbis",
+ "G.711 aLaw",
+ "G.711 uLaw",
+ "G.723.1",
+ "PCM16 (big endian)",
+ };
+ static u_int8_t numMpegAudioTypes =
+ sizeof(mpegAudioTypes) / sizeof(u_int8_t);
+
+ const char* typeName = "Unknown";
+ bool foundType = false;
+ u_int8_t type = MP4GetTrackEsdsObjectTypeId(mp4File, trackId);
+
+ switch (type) {
+ case MP4_MPEG4_AUDIO_TYPE: {
+ u_int8_t* pAacConfig = NULL;
+ u_int32_t aacConfigLength;
+
+ MP4GetTrackESConfiguration(mp4File,
+ trackId,
+ &pAacConfig,
+ &aacConfigLength);
+
+ if (pAacConfig != NULL && aacConfigLength >= 2) {
+ type = (pAacConfig[0] >> 3) & 0x1f;
+ if (type == 0 || type == 5 || type == 10 || type == 11 ||
+ type == 18 || type >= 28) {
+ typeName = "MPEG-4 Unknown Profile";
+ } else {
+ typeName = mpeg4AudioNames[type - 1];
+ foundType = true;
+ }
+ free(pAacConfig);
+ } else {
+ typeName = "MPEG-4 (no GAConfig)";
+ foundType = true;
+ }
+ break;
+ }
+ case MP4_INVALID_AUDIO_TYPE:
+ // type not found
+ // try with 3gpp codecs
+ if (MP4HaveTrackIntegerProperty(mp4File, trackId,
+ "mdia.minf.stbl.stsd.samr.damr.vendor")) {
+ typeName = "AMR";
+ foundType = true;
+ } else if (MP4HaveTrackIntegerProperty(mp4File, trackId,
+ "mdia.minf.stbl.stsd.sawb.damr.vendor")) {
+ typeName = "AMR-WB";
+ foundType = true;
+ }
+ break;
+ // fall through
+ default:
+ for (u_int8_t i = 0; i < numMpegAudioTypes; i++) {
+ if (type == mpegAudioTypes[i]) {
+ typeName = mpegAudioNames[i];
+ foundType = true;
+ break;
+ }
+ }
+ }
+
+ u_int32_t timeScale =
+ MP4GetTrackTimeScale(mp4File, trackId);
+
+ MP4Duration trackDuration =
+ MP4GetTrackDuration(mp4File, trackId);
+
+ double msDuration =
+ UINT64_TO_DOUBLE(MP4ConvertFromTrackDuration(mp4File, trackId,
+ trackDuration, MP4_MSECS_TIME_SCALE));
+
+ u_int32_t avgBitRate =
+ MP4GetTrackBitRate(mp4File, trackId);
+
+ char *sInfo = (char*)MP4Malloc(256);
+
+ // type duration avgBitrate samplingFrequency
+ if (foundType)
+ sprintf(sInfo,
+ "%u\taudio\t%s%s, %.3f secs, %u kbps, %u Hz\n",
+ trackId,
+ MP4IsIsmaCrypMediaTrack(mp4File, trackId) ? "enca - " : "",
+ typeName,
+ msDuration / 1000.0,
+ (avgBitRate + 500) / 1000,
+ timeScale);
+ else
+ sprintf(sInfo,
+ "%u\taudio\t%s%s(%u), %.3f secs, %u kbps, %u Hz\n",
+ trackId,
+ MP4IsIsmaCrypMediaTrack(mp4File, trackId) ? "enca - " : "",
+ typeName,
+ type,
+ msDuration / 1000.0,
+ (avgBitRate + 500) / 1000,
+ timeScale);
+
+ return sInfo;
+}
+static struct {
+ uint8_t profile;
+ const char *name;
+} VisualProfileToName[] = {
+ { MPEG4_SP_L1, "MPEG-4 Simple @ L1"},
+ { MPEG4_SP_L2, "MPEG-4 Simple @ L2" },
+ { MPEG4_SP_L3, "MPEG-4 Simple @ L3" },
+ { MPEG4_SP_L0, "MPEG-4 Simple @ L0" },
+ { MPEG4_SSP_L1, "MPEG-4 Simple Scalable @ L1"},
+ { MPEG4_SSP_L2, "MPEG-4 Simple Scalable @ L2" },
+ { MPEG4_CP_L1, "MPEG-4 Core @ L1"},
+ { MPEG4_CP_L2, "MPEG-4 Core @ L2"},
+ { MPEG4_MP_L2, "MPEG-4 Main @ L2"},
+ { MPEG4_MP_L3, "MPEG-4 Main @ L3"},
+ { MPEG4_MP_L4, "MPEG-4 Main @ L4"},
+ { MPEG4_NBP_L2, "MPEG-4 N-bit @ L2"},
+ { MPEG4_STP_L1, "MPEG-4 Scalable Texture @ L1"},
+ { MPEG4_SFAP_L1, "MPEG-4 Simple Face Anim @ L1"},
+ { MPEG4_SFAP_L2, "MPEG-4 Simple Face Anim @ L2"},
+ { MPEG4_SFBAP_L1, "MPEG-4 Simple FBA @ L1"},
+ { MPEG4_SFBAP_L2, "MPEG-4 Simple FBA @ L2"},
+ { MPEG4_BATP_L1, "MPEG-4 Basic Anim Text @ L1"},
+ { MPEG4_BATP_L2, "MPEG-4 Basic Anim Text @ L2"},
+ { MPEG4_HP_L1, "MPEG-4 Hybrid @ L1"},
+ { MPEG4_HP_L2, "MPEG-4 Hybrid @ L2"},
+ { MPEG4_ARTSP_L1, "MPEG-4 Adv RT Simple @ L1"},
+ { MPEG4_ARTSP_L2, "MPEG-4 Adv RT Simple @ L2"},
+ { MPEG4_ARTSP_L3, "MPEG-4 Adv RT Simple @ L3"},
+ { MPEG4_ARTSP_L4, "MPEG-4 Adv RT Simple @ L4"},
+ { MPEG4_CSP_L1, "MPEG-4 Core Scalable @ L1"},
+ { MPEG4_CSP_L2, "MPEG-4 Core Scalable @ L2"},
+ { MPEG4_CSP_L3, "MPEG-4 Core Scalable @ L3"},
+ { MPEG4_ACEP_L1, "MPEG-4 Adv Coding Efficieny @ L1"},
+ { MPEG4_ACEP_L2, "MPEG-4 Adv Coding Efficieny @ L2"},
+ { MPEG4_ACEP_L3, "MPEG-4 Adv Coding Efficieny @ L3"},
+ { MPEG4_ACEP_L4, "MPEG-4 Adv Coding Efficieny @ L4"},
+ { MPEG4_ACP_L1, "MPEG-4 Adv Core Profile @ L1"},
+ { MPEG4_ACP_L2, "MPEG-4 Adv Core Profile @ L2"},
+ { MPEG4_AST_L1, "MPEG-4 Adv Scalable Texture @ L1"},
+ { MPEG4_AST_L2, "MPEG-4 Adv Scalable Texture @ L2"},
+ { MPEG4_AST_L3, "MPEG-4 Adv Scalable Texture @ L3"},
+ { MPEG4_S_STUDIO_P_L1, "MPEG-4 Simple Studio @ L1"},
+ { MPEG4_S_STUDIO_P_L2, "MPEG-4 Simple Studio @ L2"},
+ { MPEG4_S_STUDIO_P_L3, "MPEG-4 Simple Studio @ L3"},
+ { MPEG4_S_STUDIO_P_L4, "MPEG-4 Simple Studio @ L4"},
+ { MPEG4_C_STUDIO_P_L1, "MPEG-4 Core Studio @ L1"},
+ { MPEG4_C_STUDIO_P_L2, "MPEG-4 Core Studio @ L2"},
+ { MPEG4_C_STUDIO_P_L3, "MPEG-4 Core Studio @ L3"},
+ { MPEG4_C_STUDIO_P_L4, "MPEG-4 Core Studio @ L4"},
+ { MPEG4_ASP_L0, "MPEG-4 Adv Simple@L0"},
+ { MPEG4_ASP_L1, "MPEG-4 Adv Simple@L1"},
+ { MPEG4_ASP_L2, "MPEG-4 Adv Simple@L2"},
+ { MPEG4_ASP_L3, "MPEG-4 Adv Simple@L3"},
+ { MPEG4_ASP_L4, "MPEG-4 Adv Simple@L4"},
+ { MPEG4_ASP_L5, "MPEG-4 Adv Simple@L5"},
+ { MPEG4_ASP_L3B, "MPEG-4 Adv Simple@L3b"},
+ { MPEG4_FGSP_L0, "MPEG-4 FGS @ L0" },
+ { MPEG4_FGSP_L1, "MPEG-4 FGS @ L1" },
+ { MPEG4_FGSP_L2, "MPEG-4 FGS @ L2" },
+ { MPEG4_FGSP_L3, "MPEG-4 FGS @ L3" },
+ { MPEG4_FGSP_L4, "MPEG-4 FGS @ L4" },
+ { MPEG4_FGSP_L5, "MPEG-4 FGS @ L5" }
+};
+
+static const char *Mpeg4VisualProfileName (uint8_t visual_profile)
+{
+ size_t size = sizeof(VisualProfileToName) / sizeof(*VisualProfileToName);
+
+ for (size_t ix = 0; ix < size; ix++) {
+ if (visual_profile == VisualProfileToName[ix].profile) {
+ return (VisualProfileToName[ix].name);
+ }
+ }
+ return (NULL);
+}
+static char* PrintVideoInfo(
+ MP4FileHandle mp4File,
+ MP4TrackId trackId)
+{
+
+ static u_int8_t mpegVideoTypes[] = {
+ MP4_MPEG2_SIMPLE_VIDEO_TYPE, // 0x60
+ MP4_MPEG2_MAIN_VIDEO_TYPE, // 0x61
+ MP4_MPEG2_SNR_VIDEO_TYPE, // 0x62
+ MP4_MPEG2_SPATIAL_VIDEO_TYPE, // 0x63
+ MP4_MPEG2_HIGH_VIDEO_TYPE, // 0x64
+ MP4_MPEG2_442_VIDEO_TYPE, // 0x65
+ MP4_MPEG1_VIDEO_TYPE, // 0x6A
+ MP4_JPEG_VIDEO_TYPE, // 0x6C
+ MP4_YUV12_VIDEO_TYPE,
+ MP4_H264_VIDEO_TYPE,
+ MP4_H263_VIDEO_TYPE,
+ MP4_H261_VIDEO_TYPE,
+ };
+ static const char* mpegVideoNames[] = {
+ "MPEG-2 Simple",
+ "MPEG-2 Main",
+ "MPEG-2 SNR",
+ "MPEG-2 Spatial",
+ "MPEG-2 High",
+ "MPEG-2 4:2:2",
+ "MPEG-1",
+ "JPEG",
+ "YUV12",
+ "H.264",
+ "H.263",
+ "H.261",
+ };
+ static u_int8_t numMpegVideoTypes =
+ sizeof(mpegVideoTypes) / sizeof(u_int8_t);
+ bool foundTypeName = false;
+ const char* typeName = "Unknown";
+
+ u_int8_t type = MP4GetTrackEsdsObjectTypeId(mp4File, trackId);
+
+ if ( type == MP4_INVALID_VIDEO_TYPE ) {
+ // type not found
+ // try with 3gpp codecs
+ if (MP4HaveTrackIntegerProperty(mp4File, trackId, "mdia.minf.stbl.stsd.s263.d263.vendor")) {
+ type = MP4_H263_VIDEO_TYPE;
+ }
+ }
+
+ if (type == MP4_MPEG4_VIDEO_TYPE) {
+ type = MP4GetVideoProfileLevel(mp4File);
+ typeName = Mpeg4VisualProfileName(type);
+ if (typeName == NULL) {
+ typeName = "MPEG-4 Unknown Profile";
+ } else {
+ foundTypeName = true;
+ }
+ } else {
+ for (u_int8_t i = 0; i < numMpegVideoTypes; i++) {
+ if (type == mpegVideoTypes[i]) {
+ typeName = mpegVideoNames[i];
+ foundTypeName = true;
+ break;
+ }
+ }
+ }
+
+ MP4Duration trackDuration =
+ MP4GetTrackDuration(mp4File, trackId);
+
+ double msDuration =
+ UINT64_TO_DOUBLE(MP4ConvertFromTrackDuration(mp4File, trackId,
+ trackDuration, MP4_MSECS_TIME_SCALE));
+
+ u_int32_t avgBitRate =
+ MP4GetTrackBitRate(mp4File, trackId);
+
+ // Note not all mp4 implementations set width and height correctly
+ // The real answer can be buried inside the ES configuration info
+ u_int16_t width = MP4GetTrackVideoWidth(mp4File, trackId);
+
+ u_int16_t height = MP4GetTrackVideoHeight(mp4File, trackId);
+
+ float fps = MP4GetTrackVideoFrameRate(mp4File, trackId);
+
+ char *sInfo = (char*)MP4Malloc(256);
+
+ // type duration avgBitrate frameSize frameRate
+ if (foundTypeName) {
+ sprintf(sInfo,
+ "%u\tvideo\t%s%s, %.3f secs, %u kbps, %ux%u @ %.2f fps\n",
+ trackId,
+ MP4IsIsmaCrypMediaTrack(mp4File, trackId) ? "encv - " : "",
+ typeName,
+ msDuration / 1000.0,
+ (avgBitRate + 500) / 1000,
+ width,
+ height,
+ fps
+ );
+ } else {
+ sprintf(sInfo,
+ "%u\tvideo\t%s(%u), %.3f secs, %u kbps, %ux%u @ %.2f fps\n",
+ trackId,
+ typeName,
+ type,
+ msDuration / 1000.0,
+ (avgBitRate + 500) / 1000,
+ width,
+ height,
+ fps
+ );
+ }
+
+ return sInfo;
+}
+
+static char* PrintHintInfo(
+ MP4FileHandle mp4File,
+ MP4TrackId trackId)
+{
+ MP4TrackId referenceTrackId =
+ MP4GetHintTrackReferenceTrackId(mp4File, trackId);
+
+ char* payloadName = NULL;
+ MP4GetHintTrackRtpPayload(mp4File, trackId, &payloadName);
+
+ char *sInfo = (char*)MP4Malloc(256);
+
+ sprintf(sInfo,
+ "%u\thint\tPayload %s for track %u\n",
+ trackId,
+ payloadName,
+ referenceTrackId);
+
+ free(payloadName);
+
+ return sInfo;
+}
+
+static char* PrintTrackInfo(
+ MP4FileHandle mp4File,
+ MP4TrackId trackId)
+{
+ char* trackInfo = NULL;
+
+ const char* trackType =
+ MP4GetTrackType(mp4File, trackId);
+
+ if (!strcmp(trackType, MP4_AUDIO_TRACK_TYPE)) {
+ trackInfo = PrintAudioInfo(mp4File, trackId);
+ } else if (!strcmp(trackType, MP4_VIDEO_TRACK_TYPE)) {
+ trackInfo = PrintVideoInfo(mp4File, trackId);
+ } else if (!strcmp(trackType, MP4_HINT_TRACK_TYPE)) {
+ trackInfo = PrintHintInfo(mp4File, trackId);
+ } else {
+ trackInfo = (char*)MP4Malloc(256);
+ if (!strcmp(trackType, MP4_OD_TRACK_TYPE)) {
+ sprintf(trackInfo,
+ "%u\tod\tObject Descriptors\n",
+ trackId);
+ } else if (!strcmp(trackType, MP4_SCENE_TRACK_TYPE)) {
+ sprintf(trackInfo,
+ "%u\tscene\tBIFS\n",
+ trackId);
+ } else {
+ sprintf(trackInfo,
+ "%u\t%s\n",
+ trackId, trackType);
+ }
+ }
+
+ return trackInfo;
+}
+
+extern "C" char* MP4Info(
+ MP4FileHandle mp4File,
+ MP4TrackId trackId)
+{
+ char* info = NULL;
+
+ if (MP4_IS_VALID_FILE_HANDLE(mp4File)) {
+ try {
+ if (trackId == MP4_INVALID_TRACK_ID) {
+ info = (char*)MP4Calloc(4*1024);
+
+ sprintf(info, "Track\tType\tInfo\n");
+
+ u_int32_t numTracks = MP4GetNumberOfTracks(mp4File);
+
+ for (u_int32_t i = 0; i < numTracks; i++) {
+ trackId = MP4FindTrackId(mp4File, i);
+ char* trackInfo = PrintTrackInfo(mp4File, trackId);
+ strcat(info, trackInfo);
+ MP4Free(trackInfo);
+ }
+ } else {
+ info = PrintTrackInfo(mp4File, trackId);
+ }
+ }
+ catch (MP4Error* e) {
+ delete e;
+ }
+ }
+
+ return info;
+}
+
+extern "C" char* MP4FileInfo(
+ const char* fileName,
+ MP4TrackId trackId)
+{
+ MP4FileHandle mp4File =
+ MP4Read(fileName);
+
+ if (!mp4File) {
+ return NULL;
+ }
+
+ char* info = MP4Info(mp4File, trackId);
+
+ MP4Close(mp4File);
+
+ return info; // caller should free this
+}
+
--- /dev/null
+++ b/common/mp4v2/mp4meta.cpp
@@ -1,0 +1,987 @@
+/*
+ * 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):
+ * M. Bakker mbakker at nero.com
+ *
+ * Apple iTunes Metadata handling
+ */
+
+/**
+
+ The iTunes tagging seems to support any tag field name
+ but there are some predefined fields, also known from the QuickTime format
+
+ predefined fields (the ones I know of until now):
+ - �nam : Name of the song/movie (string)
+ - �ART : Name of the artist/performer (string)
+ - �wrt : Name of the writer (string)
+ - �alb : Name of the album (string)
+ - �day : Year (4 bytes, e.g. "2003") (string)
+ - �too : Tool(s) used to create the file (string)
+ - �cmt : Comment (string)
+ - �gen : Custom genre (string)
+ - trkn : Tracknumber (8 byte string)
+ 16 bit: empty
+ 16 bit: tracknumber
+ 16 bit: total tracks on album
+ 16 bit: empty
+ - disk : Disknumber (8 byte string)
+ 16 bit: empty
+ 16 bit: disknumber
+ 16 bit: total number of disks
+ 16 bit: empty
+ - gnre : Genre (16 bit genre) (ID3v1 index + 1)
+ - cpil : Part of a compilation (1 byte, 1 or 0)
+ - tmpo : Tempo in BPM (16 bit)
+ - covr : Cover art (xx bytes binary data)
+ - ---- : Free form metadata, can have any name and any data
+
+**/
+
+#include "mp4common.h"
+
+bool MP4File::GetMetadataByIndex(u_int32_t index,
+ const char** ppName,
+ u_int8_t** ppValue, u_int32_t* pValueSize)
+{
+ char s[256];
+
+ sprintf(s, "moov.udta.meta.ilst.*[%u].data.metadata", index);
+ GetBytesProperty(s, ppValue, pValueSize);
+
+ sprintf(s, "moov.udta.meta.ilst.*[%u]", index);
+ MP4Atom* pParent = m_pRootAtom->FindAtom(s);
+ *ppName = pParent->GetType();
+
+ /* check for free form tagfield */
+ if (memcmp(*ppName, "----", 4) == 0)
+ {
+ u_int8_t* pV;
+ u_int32_t VSize = 0;
+ char *pN;
+
+ sprintf(s, "moov.udta.meta.ilst.*[%u].name.metadata", index);
+ GetBytesProperty(s, &pV, &VSize);
+
+ pN = (char*)malloc((VSize+1)*sizeof(char));
+ memset(pN, 0, (VSize+1)*sizeof(char));
+ memcpy(pN, pV, VSize*sizeof(char));
+
+ *ppName = pN;
+ }
+
+ return true;
+}
+
+bool MP4File::CreateMetadataAtom(const char* name)
+{
+ char s[256];
+ char t[256];
+
+ sprintf(t, "udta.meta.ilst.%s.data", name);
+ sprintf(s, "moov.udta.meta.ilst.%s.data", name);
+ AddDescendantAtoms("moov", t);
+ MP4Atom *pMetaAtom = m_pRootAtom->FindAtom(s);
+
+ if (!pMetaAtom)
+ return false;
+
+ /* some fields need special flags set */
+ if ((uint8_t)name[0] == 0251)
+ {
+ pMetaAtom->SetFlags(0x1);
+ } else if ((memcmp(name, "cpil", 4) == 0) || (memcmp(name, "tmpo", 4) == 0)) {
+ pMetaAtom->SetFlags(0x15);
+ }
+
+ MP4Atom *pHdlrAtom = m_pRootAtom->FindAtom("moov.udta.meta.hdlr");
+ MP4StringProperty *pStringProperty = NULL;
+ MP4BytesProperty *pBytesProperty = NULL;
+ ASSERT(pHdlrAtom);
+
+ pHdlrAtom->FindProperty(
+ "hdlr.handlerType", (MP4Property**)&pStringProperty);
+ ASSERT(pStringProperty);
+ pStringProperty->SetValue("mdir");
+
+ u_int8_t val[12];
+ memset(val, 0, 12*sizeof(u_int8_t));
+ val[0] = 0x61;
+ val[1] = 0x70;
+ val[2] = 0x70;
+ val[3] = 0x6c;
+ pHdlrAtom->FindProperty(
+ "hdlr.reserved2", (MP4Property**)&pBytesProperty);
+ ASSERT(pBytesProperty);
+ pBytesProperty->SetReadOnly(false);
+ pBytesProperty->SetValue(val, 12);
+ pBytesProperty->SetReadOnly(true);
+
+ return true;
+}
+
+bool MP4File::SetMetadataName(const char* value)
+{
+ const char *s = "moov.udta.meta.ilst.\251nam.data";
+ MP4BytesProperty *pMetadataProperty = NULL;
+ MP4Atom *pMetaAtom = NULL;
+
+ pMetaAtom = m_pRootAtom->FindAtom(s);
+
+ if (!pMetaAtom)
+ {
+ if (!CreateMetadataAtom("\251nam"))
+ return false;
+
+ pMetaAtom = m_pRootAtom->FindAtom(s);
+ }
+
+ pMetaAtom->FindProperty("data.metadata", (MP4Property**)&pMetadataProperty);
+ ASSERT(pMetadataProperty);
+
+ pMetadataProperty->SetValue((u_int8_t*)value, strlen(value));
+
+ return true;
+}
+
+bool MP4File::GetMetadataName(char** value)
+{
+ unsigned char *val = NULL;
+ u_int32_t valSize = 0;
+ const char *s = "moov.udta.meta.ilst.\251nam.data.metadata";
+ GetBytesProperty(s, (u_int8_t**)&val, &valSize);
+
+ if (valSize > 0)
+ {
+ *value = (char*)malloc((valSize+1)*sizeof(unsigned char));
+ memset(*value, 0, (valSize+1)*sizeof(unsigned char));
+ memcpy(*value, val, valSize*sizeof(unsigned char));
+ return true;
+ } else {
+ *value = NULL;
+ return false;
+ }
+}
+
+bool MP4File::SetMetadataWriter(const char* value)
+{
+ const char *s = "moov.udta.meta.ilst.\251wrt.data";
+ MP4BytesProperty *pMetadataProperty = NULL;
+ MP4Atom *pMetaAtom = NULL;
+
+ pMetaAtom = m_pRootAtom->FindAtom(s);
+
+ if (!pMetaAtom)
+ {
+ if (!CreateMetadataAtom("\251wrt"))
+ return false;
+
+ pMetaAtom = m_pRootAtom->FindAtom(s);
+ }
+
+ pMetaAtom->FindProperty("data.metadata", (MP4Property**)&pMetadataProperty);
+ ASSERT(pMetadataProperty);
+
+ pMetadataProperty->SetValue((u_int8_t*)value, strlen(value));
+
+ return true;
+}
+
+bool MP4File::GetMetadataWriter(char** value)
+{
+ unsigned char *val = NULL;
+ u_int32_t valSize = 0;
+ const char *s = "moov.udta.meta.ilst.\251wrt.data.metadata";
+ GetBytesProperty(s, (u_int8_t**)&val, &valSize);
+
+ if (valSize > 0)
+ {
+ *value = (char*)malloc((valSize+1)*sizeof(unsigned char));
+ memset(*value, 0, (valSize+1)*sizeof(unsigned char));
+ memcpy(*value, val, valSize*sizeof(unsigned char));
+ return true;
+ } else {
+ *value = NULL;
+ return false;
+ }
+}
+
+bool MP4File::SetMetadataAlbum(const char* value)
+{
+ const char *s = "moov.udta.meta.ilst.\251alb.data";
+ MP4BytesProperty *pMetadataProperty = NULL;
+ MP4Atom *pMetaAtom = NULL;
+
+ pMetaAtom = m_pRootAtom->FindAtom(s);
+
+ if (!pMetaAtom)
+ {
+ if (!CreateMetadataAtom("\251alb"))
+ return false;
+
+ pMetaAtom = m_pRootAtom->FindAtom(s);
+ }
+
+ pMetaAtom->FindProperty("data.metadata", (MP4Property**)&pMetadataProperty);
+ ASSERT(pMetadataProperty);
+
+ pMetadataProperty->SetValue((u_int8_t*)value, strlen(value));
+
+ return true;
+}
+
+bool MP4File::GetMetadataAlbum(char** value)
+{
+ unsigned char *val = NULL;
+ u_int32_t valSize = 0;
+ const char *s = "moov.udta.meta.ilst.\251alb.data.metadata";
+ GetBytesProperty(s, (u_int8_t**)&val, &valSize);
+
+ if (valSize > 0)
+ {
+ *value = (char*)malloc((valSize+1)*sizeof(unsigned char));
+ memset(*value, 0, (valSize+1)*sizeof(unsigned char));
+ memcpy(*value, val, valSize*sizeof(unsigned char));
+ return true;
+ } else {
+ *value = NULL;
+ return false;
+ }
+}
+
+bool MP4File::SetMetadataArtist(const char* value)
+{
+ const char *s = "moov.udta.meta.ilst.\251ART.data";
+ MP4BytesProperty *pMetadataProperty = NULL;
+ MP4Atom *pMetaAtom = NULL;
+
+ pMetaAtom = m_pRootAtom->FindAtom(s);
+
+ if (!pMetaAtom)
+ {
+ if (!CreateMetadataAtom("\251ART"))
+ return false;
+
+ pMetaAtom = m_pRootAtom->FindAtom(s);
+ }
+
+ pMetaAtom->FindProperty("data.metadata", (MP4Property**)&pMetadataProperty);
+ ASSERT(pMetadataProperty);
+
+ pMetadataProperty->SetValue((u_int8_t*)value, strlen(value));
+
+ return true;
+}
+
+bool MP4File::GetMetadataArtist(char** value)
+{
+ unsigned char *val = NULL;
+ u_int32_t valSize = 0;
+ const char *s = "moov.udta.meta.ilst.\251ART.data.metadata";
+ GetBytesProperty(s, (u_int8_t**)&val, &valSize);
+
+ if (valSize > 0)
+ {
+ *value = (char*)malloc((valSize+1)*sizeof(unsigned char));
+ memset(*value, 0, (valSize+1)*sizeof(unsigned char));
+ memcpy(*value, val, valSize*sizeof(unsigned char));
+ return true;
+ } else {
+ *value = NULL;
+ return false;
+ }
+}
+
+bool MP4File::SetMetadataTool(const char* value)
+{
+ const char *s = "moov.udta.meta.ilst.\251too.data";
+ MP4BytesProperty *pMetadataProperty = NULL;
+ MP4Atom *pMetaAtom = NULL;
+
+ pMetaAtom = m_pRootAtom->FindAtom(s);
+
+ if (!pMetaAtom)
+ {
+ if (!CreateMetadataAtom("\251too"))
+ return false;
+
+ pMetaAtom = m_pRootAtom->FindAtom(s);
+ }
+
+ pMetaAtom->FindProperty("data.metadata", (MP4Property**)&pMetadataProperty);
+ ASSERT(pMetadataProperty);
+
+ pMetadataProperty->SetValue((u_int8_t*)value, strlen(value));
+
+ return true;
+}
+
+bool MP4File::GetMetadataTool(char** value)
+{
+ unsigned char *val = NULL;
+ u_int32_t valSize = 0;
+ const char *s = "moov.udta.meta.ilst.\251too.data.metadata";
+ GetBytesProperty(s, (u_int8_t**)&val, &valSize);
+
+ if (valSize > 0)
+ {
+ *value = (char*)malloc((valSize+1)*sizeof(unsigned char));
+ memset(*value, 0, (valSize+1)*sizeof(unsigned char));
+ memcpy(*value, val, valSize*sizeof(unsigned char));
+ return true;
+ } else {
+ *value = NULL;
+ return false;
+ }
+}
+
+bool MP4File::SetMetadataComment(const char* value)
+{
+ const char *s = "moov.udta.meta.ilst.\251cmt.data";
+ MP4BytesProperty *pMetadataProperty = NULL;
+ MP4Atom *pMetaAtom = NULL;
+
+ pMetaAtom = m_pRootAtom->FindAtom(s);
+
+ if (!pMetaAtom)
+ {
+ if (!CreateMetadataAtom("\251cmt"))
+ return false;
+
+ pMetaAtom = m_pRootAtom->FindAtom(s);
+ }
+
+ pMetaAtom->FindProperty("data.metadata", (MP4Property**)&pMetadataProperty);
+ ASSERT(pMetadataProperty);
+
+ pMetadataProperty->SetValue((u_int8_t*)value, strlen(value));
+
+ return true;
+}
+
+bool MP4File::GetMetadataComment(char** value)
+{
+ unsigned char *val = NULL;
+ u_int32_t valSize = 0;
+ const char *s = "moov.udta.meta.ilst.\251cmt.data.metadata";
+ GetBytesProperty(s, (u_int8_t**)&val, &valSize);
+
+ if (valSize > 0)
+ {
+ *value = (char*)malloc((valSize+1)*sizeof(unsigned char));
+ memset(*value, 0, (valSize+1)*sizeof(unsigned char));
+ memcpy(*value, val, valSize*sizeof(unsigned char));
+ return true;
+ } else {
+ *value = NULL;
+ return false;
+ }
+}
+
+bool MP4File::SetMetadataYear(const char* value)
+{
+ const char *s = "moov.udta.meta.ilst.\251day.data";
+ MP4BytesProperty *pMetadataProperty = NULL;
+ MP4Atom *pMetaAtom = NULL;
+
+ pMetaAtom = m_pRootAtom->FindAtom(s);
+
+ if (!pMetaAtom)
+ {
+ if (!CreateMetadataAtom("\251day"))
+ return false;
+
+ pMetaAtom = m_pRootAtom->FindAtom(s);
+ }
+
+ pMetaAtom->FindProperty("data.metadata", (MP4Property**)&pMetadataProperty);
+ ASSERT(pMetadataProperty);
+
+ if (strlen(value) < 4)
+ return false;
+
+ pMetadataProperty->SetValue((u_int8_t*)value, 4);
+
+ return true;
+}
+
+bool MP4File::GetMetadataYear(char** value)
+{
+ unsigned char *val = NULL;
+ u_int32_t valSize = 0;
+ const char *s = "moov.udta.meta.ilst.\251day.data.metadata";
+ GetBytesProperty(s, (u_int8_t**)&val, &valSize);
+
+ if (valSize > 0)
+ {
+ *value = (char*)malloc((valSize+1)*sizeof(unsigned char));
+ memset(*value, 0, (valSize+1)*sizeof(unsigned char));
+ memcpy(*value, val, valSize*sizeof(unsigned char));
+ return true;
+ } else {
+ *value = NULL;
+ return false;
+ }
+}
+
+bool MP4File::SetMetadataTrack(u_int16_t track, u_int16_t totalTracks)
+{
+ unsigned char t[9];
+ const char *s = "moov.udta.meta.ilst.trkn.data";
+ MP4BytesProperty *pMetadataProperty = NULL;
+ MP4Atom *pMetaAtom = NULL;
+
+ pMetaAtom = m_pRootAtom->FindAtom(s);
+
+ if (!pMetaAtom)
+ {
+ if (!CreateMetadataAtom("trkn"))
+ return false;
+
+ pMetaAtom = m_pRootAtom->FindAtom(s);
+ }
+
+ memset(t, 0, 9*sizeof(unsigned char));
+ t[2] = (unsigned char)(track>>8)&0xFF;
+ t[3] = (unsigned char)(track)&0xFF;
+ t[4] = (unsigned char)(totalTracks>>8)&0xFF;
+ t[5] = (unsigned char)(totalTracks)&0xFF;
+
+ pMetaAtom->FindProperty("data.metadata", (MP4Property**)&pMetadataProperty);
+ ASSERT(pMetadataProperty);
+
+ pMetadataProperty->SetValue((u_int8_t*)t, 8);
+
+ return true;
+}
+
+bool MP4File::GetMetadataTrack(u_int16_t* track, u_int16_t* totalTracks)
+{
+ unsigned char *val = NULL;
+ u_int32_t valSize = 0;
+ const char *s = "moov.udta.meta.ilst.trkn.data.metadata";
+ GetBytesProperty(s, (u_int8_t**)&val, &valSize);
+
+ *track = 0;
+ *totalTracks = 0;
+
+ if (valSize != 8)
+ return false;
+
+ *track = (u_int16_t)(val[3]);
+ *track += (u_int16_t)(val[2]<<8);
+ *totalTracks = (u_int16_t)(val[5]);
+ *totalTracks += (u_int16_t)(val[4]<<8);
+
+ return true;
+}
+
+bool MP4File::SetMetadataDisk(u_int16_t disk, u_int16_t totalDisks)
+{
+ unsigned char t[9];
+ const char *s = "moov.udta.meta.ilst.disk.data";
+ MP4BytesProperty *pMetadataProperty = NULL;
+ MP4Atom *pMetaAtom = NULL;
+
+ pMetaAtom = m_pRootAtom->FindAtom(s);
+
+ if (!pMetaAtom)
+ {
+ if (!CreateMetadataAtom("disk"))
+ return false;
+
+ pMetaAtom = m_pRootAtom->FindAtom(s);
+ }
+
+ memset(t, 0, 9*sizeof(unsigned char));
+ t[2] = (unsigned char)(disk>>8)&0xFF;
+ t[3] = (unsigned char)(disk)&0xFF;
+ t[4] = (unsigned char)(totalDisks>>8)&0xFF;
+ t[5] = (unsigned char)(totalDisks)&0xFF;
+
+ pMetaAtom->FindProperty("data.metadata", (MP4Property**)&pMetadataProperty);
+ ASSERT(pMetadataProperty);
+
+ pMetadataProperty->SetValue((u_int8_t*)t, 8);
+
+ return true;
+}
+
+bool MP4File::GetMetadataDisk(u_int16_t* disk, u_int16_t* totalDisks)
+{
+ unsigned char *val = NULL;
+ u_int32_t valSize = 0;
+ const char *s = "moov.udta.meta.ilst.disk.data.metadata";
+ GetBytesProperty(s, (u_int8_t**)&val, &valSize);
+
+ *disk = 0;
+ *totalDisks = 0;
+
+ if (valSize != 8)
+ return false;
+
+ *disk = (u_int16_t)(val[3]);
+ *disk += (u_int16_t)(val[2]<<8);
+ *totalDisks = (u_int16_t)(val[5]);
+ *totalDisks += (u_int16_t)(val[4]<<8);
+
+ return true;
+}
+
+static const char* ID3v1GenreList[] = {
+ "Blues", "Classic Rock", "Country", "Dance", "Disco", "Funk",
+ "Grunge", "Hip-Hop", "Jazz", "Metal", "New Age", "Oldies",
+ "Other", "Pop", "R&B", "Rap", "Reggae", "Rock",
+ "Techno", "Industrial", "Alternative", "Ska", "Death Metal", "Pranks",
+ "Soundtrack", "Euro-Techno", "Ambient", "Trip-Hop", "Vocal", "Jazz+Funk",
+ "Fusion", "Trance", "Classical", "Instrumental", "Acid", "House",
+ "Game", "Sound Clip", "Gospel", "Noise", "AlternRock", "Bass",
+ "Soul", "Punk", "Space", "Meditative", "Instrumental Pop", "Instrumental Rock",
+ "Ethnic", "Gothic", "Darkwave", "Techno-Industrial", "Electronic", "Pop-Folk",
+ "Eurodance", "Dream", "Southern Rock", "Comedy", "Cult", "Gangsta",
+ "Top 40", "Christian Rap", "Pop/Funk", "Jungle", "Native American", "Cabaret",
+ "New Wave", "Psychadelic", "Rave", "Showtunes", "Trailer", "Lo-Fi",
+ "Tribal", "Acid Punk", "Acid Jazz", "Polka", "Retro", "Musical",
+ "Rock & Roll", "Hard Rock", "Folk", "Folk/Rock", "National Folk", "Swing",
+ "Fast-Fusion", "Bebob", "Latin", "Revival", "Celtic", "Bluegrass", "Avantgarde",
+ "Gothic Rock", "Progressive Rock", "Psychedelic Rock", "Symphonic Rock", "Slow Rock", "Big Band",
+ "Chorus", "Easy Listening", "Acoustic", "Humour", "Speech", "Chanson",
+ "Opera", "Chamber Music", "Sonata", "Symphony", "Booty Bass", "Primus",
+ "Porn Groove", "Satire", "Slow Jam", "Club", "Tango", "Samba",
+ "Folklore", "Ballad", "Power Ballad", "Rhythmic Soul", "Freestyle", "Duet",
+ "Punk Rock", "Drum Solo", "A capella", "Euro-House", "Dance Hall",
+ "Goa", "Drum & Bass", "Club House", "Hardcore", "Terror",
+ "Indie", "BritPop", "NegerPunk", "Polsk Punk", "Beat",
+ "Christian Gangsta", "Heavy Metal", "Black Metal", "Crossover", "Contemporary C",
+ "Christian Rock", "Merengue", "Salsa", "Thrash Metal", "Anime", "JPop",
+ "SynthPop",
+};
+
+int GenreToString(char** GenreStr, const int genre)
+{
+ if (genre > 0 &&
+ genre <= (int)(sizeof(ID3v1GenreList)/sizeof(*ID3v1GenreList)))
+ {
+ *GenreStr = (char*)malloc((strlen(ID3v1GenreList[genre-1])+1)*sizeof(char));
+ memset(*GenreStr, 0, (strlen(ID3v1GenreList[genre-1])+1)*sizeof(char));
+ strcpy(*GenreStr, ID3v1GenreList[genre-1]);
+ return 0;
+ } else {
+ *GenreStr = (char*)malloc(2*sizeof(char));
+ memset(*GenreStr, 0, 2*sizeof(char));
+ return 1;
+ }
+}
+
+int StringToGenre(const char* GenreStr)
+{
+ unsigned int i;
+
+ for (i = 0; i < sizeof(ID3v1GenreList)/sizeof(*ID3v1GenreList); i++)
+ {
+ if (strcasecmp(GenreStr, ID3v1GenreList[i]) == 0)
+ return i+1;
+ }
+ return 0;
+}
+
+bool MP4File::SetMetadataGenre(const char* value)
+{
+ u_int16_t genreIndex = 0;
+ unsigned char t[3];
+ MP4BytesProperty *pMetadataProperty = NULL;
+ MP4Atom *pMetaAtom = NULL;
+
+ genreIndex = StringToGenre(value);
+
+ if (genreIndex != 0)
+ {
+ const char *s = "moov.udta.meta.ilst.gnre.data";
+ pMetaAtom = m_pRootAtom->FindAtom(s);
+
+ if (!pMetaAtom)
+ {
+ if (!CreateMetadataAtom("gnre"))
+ return false;
+
+ pMetaAtom = m_pRootAtom->FindAtom(s);
+ }
+
+ memset(t, 0, 3*sizeof(unsigned char));
+ t[0] = (unsigned char)(genreIndex>>8)&0xFF;
+ t[1] = (unsigned char)(genreIndex)&0xFF;
+
+ pMetaAtom->FindProperty("data.metadata", (MP4Property**)&pMetadataProperty);
+ ASSERT(pMetadataProperty);
+
+ pMetadataProperty->SetValue((u_int8_t*)t, 2);
+
+ return true;
+ } else {
+ const char *s2 = "moov.udta.meta.ilst.\251gen.data";
+ pMetaAtom = m_pRootAtom->FindAtom(s2);
+
+ if (!pMetaAtom)
+ {
+ if (!CreateMetadataAtom("\251gen"))
+ return false;
+
+ pMetaAtom = m_pRootAtom->FindAtom(s2);
+ }
+
+ pMetaAtom->FindProperty("data.metadata", (MP4Property**)&pMetadataProperty);
+ ASSERT(pMetadataProperty);
+
+ pMetadataProperty->SetValue((u_int8_t*)value, strlen(value));
+
+ return true;
+ }
+
+ return false;
+}
+
+bool MP4File::GetMetadataGenre(char** value)
+{
+ u_int16_t genreIndex = 0;
+ unsigned char *val = NULL;
+ u_int32_t valSize = 0;
+ const char *t = "moov.udta.meta.ilst.gnre";
+ const char *s = "moov.udta.meta.ilst.gnre.data.metadata";
+
+ MP4Atom *gnre = FindAtom(t);
+
+ if (gnre)
+ {
+ GetBytesProperty(s, (u_int8_t**)&val, &valSize);
+
+ if (valSize != 2)
+ return false;
+
+ genreIndex = (u_int16_t)(val[1]);
+ genreIndex += (u_int16_t)(val[0]<<8);
+
+ GenreToString(value, genreIndex);
+
+ return true;
+ } else {
+ const char *s2 = "moov.udta.meta.ilst.\251gen.data.metadata";
+
+ val = NULL;
+ valSize = 0;
+
+ GetBytesProperty(s2, (u_int8_t**)&val, &valSize);
+
+ if (valSize > 0)
+ {
+ *value = (char*)malloc((valSize+1)*sizeof(unsigned char));
+ memset(*value, 0, (valSize+1)*sizeof(unsigned char));
+ memcpy(*value, val, valSize*sizeof(unsigned char));
+ return true;
+ } else {
+ *value = NULL;
+ return false;
+ }
+ }
+
+ return false;
+}
+
+bool MP4File::SetMetadataTempo(u_int16_t tempo)
+{
+ unsigned char t[3];
+ const char *s = "moov.udta.meta.ilst.tmpo.data";
+ MP4BytesProperty *pMetadataProperty = NULL;
+ MP4Atom *pMetaAtom = NULL;
+
+ pMetaAtom = m_pRootAtom->FindAtom(s);
+
+ if (!pMetaAtom)
+ {
+ if (!CreateMetadataAtom("tmpo"))
+ return false;
+
+ pMetaAtom = m_pRootAtom->FindAtom(s);
+ }
+
+ memset(t, 0, 3*sizeof(unsigned char));
+ t[0] = (unsigned char)(tempo>>8)&0xFF;
+ t[1] = (unsigned char)(tempo)&0xFF;
+
+ pMetaAtom->FindProperty("data.metadata", (MP4Property**)&pMetadataProperty);
+ ASSERT(pMetadataProperty);
+
+ pMetadataProperty->SetValue((u_int8_t*)t, 2);
+
+ return true;
+}
+
+bool MP4File::GetMetadataTempo(u_int16_t* tempo)
+{
+ unsigned char *val = NULL;
+ u_int32_t valSize = 0;
+ const char *s = "moov.udta.meta.ilst.tmpo.data.metadata";
+ GetBytesProperty(s, (u_int8_t**)&val, &valSize);
+
+ *tempo = 0;
+
+ if (valSize != 2)
+ return false;
+
+ *tempo = (u_int16_t)(val[1]);
+ *tempo += (u_int16_t)(val[0]<<8);
+
+ return true;
+}
+
+bool MP4File::SetMetadataCompilation(u_int8_t compilation)
+{
+ const char *s = "moov.udta.meta.ilst.cpil.data";
+ MP4BytesProperty *pMetadataProperty = NULL;
+ MP4Atom *pMetaAtom = NULL;
+
+ pMetaAtom = m_pRootAtom->FindAtom(s);
+
+ if (!pMetaAtom)
+ {
+ if (!CreateMetadataAtom("cpil"))
+ return false;
+
+ pMetaAtom = m_pRootAtom->FindAtom(s);
+ }
+
+ pMetaAtom->FindProperty("data.metadata", (MP4Property**)&pMetadataProperty);
+ ASSERT(pMetadataProperty);
+
+ compilation &= 0x1;
+ pMetadataProperty->SetValue((u_int8_t*)&compilation, 1);
+
+ return true;
+}
+
+bool MP4File::GetMetadataCompilation(u_int8_t* compilation)
+{
+ unsigned char *val = NULL;
+ u_int32_t valSize = 0;
+ const char *s = "moov.udta.meta.ilst.cpil.data.metadata";
+ GetBytesProperty(s, (u_int8_t**)&val, &valSize);
+
+ *compilation = 0;
+
+ if (valSize != 1)
+ return false;
+
+ *compilation = (u_int16_t)(val[0]);
+
+ return true;
+}
+
+bool MP4File::SetMetadataCoverArt(u_int8_t *coverArt, u_int32_t size)
+{
+ const char *s = "moov.udta.meta.ilst.covr.data";
+ MP4BytesProperty *pMetadataProperty = NULL;
+ MP4Atom *pMetaAtom = NULL;
+
+ pMetaAtom = m_pRootAtom->FindAtom(s);
+
+ if (!pMetaAtom)
+ {
+ if (!CreateMetadataAtom("covr"))
+ return false;
+
+ pMetaAtom = m_pRootAtom->FindAtom(s);
+ }
+
+ pMetaAtom->FindProperty("data.metadata", (MP4Property**)&pMetadataProperty);
+ ASSERT(pMetadataProperty);
+
+ pMetadataProperty->SetValue(coverArt, size);
+
+ return true;
+}
+
+bool MP4File::GetMetadataCoverArt(u_int8_t **coverArt, u_int32_t *size)
+{
+ const char *s = "moov.udta.meta.ilst.covr.data.metadata";
+ GetBytesProperty(s, coverArt, size);
+
+ if (size == 0)
+ return false;
+
+ return true;
+}
+
+bool MP4File::SetMetadataFreeForm(char *name, u_int8_t* pValue, u_int32_t valueSize)
+{
+ MP4Atom *pMetaAtom = NULL;
+ MP4BytesProperty *pMetadataProperty = NULL;
+ char s[256];
+ int i = 0;
+
+ while (1)
+ {
+ MP4BytesProperty *pMetadataProperty;
+
+ sprintf(s, "moov.udta.meta.ilst.----[%u].name", i);
+
+ MP4Atom *pTagAtom = m_pRootAtom->FindAtom(s);
+
+ if (!pTagAtom)
+ break;
+
+ pTagAtom->FindProperty("name.metadata", (MP4Property**)&pMetadataProperty);
+ if (pMetadataProperty)
+ {
+ u_int8_t* pV;
+ u_int32_t VSize = 0;
+
+ pMetadataProperty->GetValue(&pV, &VSize);
+
+ if (VSize != 0)
+ {
+ if (memcmp(pV, name, VSize) == 0)
+ {
+ sprintf(s, "moov.udta.meta.ilst.----[%u].data.metadata", i);
+ SetBytesProperty(s, pValue, valueSize);
+
+ return true;
+ }
+ }
+ }
+
+ i++;
+ }
+
+ /* doesn't exist yet, create it */
+ char t[256];
+
+ sprintf(t, "udta.meta.ilst.----[%u]", i);
+ sprintf(s, "moov.udta.meta.ilst.----[%u].data", i);
+ AddDescendantAtoms("moov", t);
+
+ pMetaAtom = m_pRootAtom->FindAtom(s);
+
+ if (!pMetaAtom)
+ return false;
+
+ pMetaAtom->SetFlags(0x1);
+
+ MP4Atom *pHdlrAtom = m_pRootAtom->FindAtom("moov.udta.meta.hdlr");
+ MP4StringProperty *pStringProperty = NULL;
+ MP4BytesProperty *pBytesProperty = NULL;
+ ASSERT(pHdlrAtom);
+
+ pHdlrAtom->FindProperty(
+ "hdlr.handlerType", (MP4Property**)&pStringProperty);
+ ASSERT(pStringProperty);
+ pStringProperty->SetValue("mdir");
+
+ u_int8_t val[12];
+ memset(val, 0, 12*sizeof(u_int8_t));
+ val[0] = 0x61;
+ val[1] = 0x70;
+ val[2] = 0x70;
+ val[3] = 0x6c;
+ pHdlrAtom->FindProperty(
+ "hdlr.reserved2", (MP4Property**)&pBytesProperty);
+ ASSERT(pBytesProperty);
+ pBytesProperty->SetReadOnly(false);
+ pBytesProperty->SetValue(val, 12);
+ pBytesProperty->SetReadOnly(true);
+
+ pMetaAtom = m_pRootAtom->FindAtom(s);
+ pMetaAtom->FindProperty("data.metadata", (MP4Property**)&pMetadataProperty);
+ ASSERT(pMetadataProperty);
+ pMetadataProperty->SetValue(pValue, valueSize);
+
+ sprintf(s, "moov.udta.meta.ilst.----[%u].name", i);
+ pMetaAtom = m_pRootAtom->FindAtom(s);
+ pMetaAtom->FindProperty("name.metadata", (MP4Property**)&pMetadataProperty);
+ ASSERT(pMetadataProperty);
+ pMetadataProperty->SetValue((u_int8_t*)name, strlen(name));
+
+ sprintf(s, "moov.udta.meta.ilst.----[%u].mean", i);
+ pMetaAtom = m_pRootAtom->FindAtom(s);
+ pMetaAtom->FindProperty("mean.metadata", (MP4Property**)&pMetadataProperty);
+ ASSERT(pMetadataProperty);
+ pMetadataProperty->SetValue((u_int8_t*)"com.apple.iTunes", 16); /* ?? */
+
+ return true;
+}
+
+bool MP4File::GetMetadataFreeForm(char *name, u_int8_t** ppValue, u_int32_t *pValueSize)
+{
+ char s[256];
+ int i = 0;
+
+ while (1)
+ {
+ MP4BytesProperty *pMetadataProperty;
+
+ sprintf(s, "moov.udta.meta.ilst.----[%u].name", i);
+
+ MP4Atom *pTagAtom = m_pRootAtom->FindAtom(s);
+
+ if (!pTagAtom)
+ return false;
+
+ pTagAtom->FindProperty("name.metadata", (MP4Property**)&pMetadataProperty);
+ if (pMetadataProperty)
+ {
+ u_int8_t* pV;
+ u_int32_t VSize = 0;
+
+ pMetadataProperty->GetValue(&pV, &VSize);
+
+ if (VSize != 0)
+ {
+ if (memcmp(pV, name, VSize) == 0)
+ {
+ sprintf(s, "moov.udta.meta.ilst.----[%u].data.metadata", i);
+ GetBytesProperty(s, ppValue, pValueSize);
+
+ return true;
+ }
+ }
+ }
+
+ i++;
+ }
+}
+
+bool MP4File::MetadataDelete()
+{
+ MP4Atom *pMetaAtom = NULL;
+ char s[256];
+
+ sprintf(s, "moov.udta.meta");
+ pMetaAtom = m_pRootAtom->FindAtom(s);
+
+ /* if it exists, delete it */
+ if (pMetaAtom)
+ {
+ MP4Atom *pParent = pMetaAtom->GetParentAtom();
+
+ pParent->DeleteChildAtom(pMetaAtom);
+
+ delete pMetaAtom;
+
+ return true;
+ }
+
+ return false;
+}
--- /dev/null
+++ b/common/mp4v2/mp4property.cpp
@@ -1,0 +1,869 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4Property::MP4Property(const char* name)
+{
+ m_name = name;
+ m_pParentAtom = NULL;
+ m_readOnly = false;
+ m_implicit = false;
+}
+
+bool MP4Property::FindProperty(const char* name,
+ MP4Property** ppProperty, u_int32_t* pIndex)
+{
+ if (name == NULL) {
+ return false;
+ }
+
+ if (!strcasecmp(m_name, name)) {
+ if (m_pParentAtom) {
+ VERBOSE_FIND(m_pParentAtom->GetFile()->GetVerbosity(),
+ printf("FindProperty: matched %s\n", name));
+ }
+
+ *ppProperty = this;
+ return true;
+ }
+ return false;
+}
+
+// Integer Property
+
+u_int64_t MP4IntegerProperty::GetValue(u_int32_t index)
+{
+ switch (this->GetType()) {
+ case Integer8Property:
+ return ((MP4Integer8Property*)this)->GetValue(index);
+ case Integer16Property:
+ return ((MP4Integer16Property*)this)->GetValue(index);
+ case Integer24Property:
+ return ((MP4Integer24Property*)this)->GetValue(index);
+ case Integer32Property:
+ return ((MP4Integer32Property*)this)->GetValue(index);
+ case Integer64Property:
+ return ((MP4Integer64Property*)this)->GetValue(index);
+ default:
+ ASSERT(FALSE);
+ }
+ return (0);
+}
+
+void MP4IntegerProperty::SetValue(u_int64_t value, u_int32_t index)
+{
+ switch (this->GetType()) {
+ case Integer8Property:
+ ((MP4Integer8Property*)this)->SetValue(value, index);
+ break;
+ case Integer16Property:
+ ((MP4Integer16Property*)this)->SetValue(value, index);
+ break;
+ case Integer24Property:
+ ((MP4Integer24Property*)this)->SetValue(value, index);
+ break;
+ case Integer32Property:
+ ((MP4Integer32Property*)this)->SetValue(value, index);
+ break;
+ case Integer64Property:
+ ((MP4Integer64Property*)this)->SetValue(value, index);
+ break;
+ default:
+ ASSERT(FALSE);
+ }
+}
+
+void MP4IntegerProperty::InsertValue(u_int64_t value, u_int32_t index)
+{
+ switch (this->GetType()) {
+ case Integer8Property:
+ ((MP4Integer8Property*)this)->InsertValue(value, index);
+ break;
+ case Integer16Property:
+ ((MP4Integer16Property*)this)->InsertValue(value, index);
+ break;
+ case Integer24Property:
+ ((MP4Integer24Property*)this)->InsertValue(value, index);
+ break;
+ case Integer32Property:
+ ((MP4Integer32Property*)this)->InsertValue(value, index);
+ break;
+ case Integer64Property:
+ ((MP4Integer64Property*)this)->InsertValue(value, index);
+ break;
+ default:
+ ASSERT(FALSE);
+ }
+}
+
+void MP4IntegerProperty::DeleteValue(u_int32_t index)
+{
+ switch (this->GetType()) {
+ case Integer8Property:
+ ((MP4Integer8Property*)this)->DeleteValue(index);
+ break;
+ case Integer16Property:
+ ((MP4Integer16Property*)this)->DeleteValue(index);
+ break;
+ case Integer24Property:
+ ((MP4Integer24Property*)this)->DeleteValue(index);
+ break;
+ case Integer32Property:
+ ((MP4Integer32Property*)this)->DeleteValue(index);
+ break;
+ case Integer64Property:
+ ((MP4Integer64Property*)this)->DeleteValue(index);
+ break;
+ default:
+ ASSERT(FALSE);
+ }
+}
+
+void MP4IntegerProperty::IncrementValue(int32_t increment, u_int32_t index)
+{
+ SetValue(GetValue() + increment);
+}
+
+void MP4Integer8Property::Dump(FILE* pFile, u_int8_t indent,
+ bool dumpImplicits, u_int32_t index)
+{
+ if (m_implicit && !dumpImplicits) {
+ return;
+ }
+ Indent(pFile, indent);
+ fprintf(pFile, "%s = %u (0x%02x)\n",
+ m_name, m_values[index], m_values[index]);
+}
+
+void MP4Integer16Property::Dump(FILE* pFile, u_int8_t indent,
+ bool dumpImplicits, u_int32_t index)
+{
+ if (m_implicit && !dumpImplicits) {
+ return;
+ }
+ Indent(pFile, indent);
+ fprintf(pFile, "%s = %u (0x%04x)\n",
+ m_name, m_values[index], m_values[index]);
+}
+
+void MP4Integer24Property::Dump(FILE* pFile, u_int8_t indent,
+ bool dumpImplicits, u_int32_t index)
+{
+ if (m_implicit && !dumpImplicits) {
+ return;
+ }
+ Indent(pFile, indent);
+ fprintf(pFile, "%s = %u (0x%06x)\n",
+ m_name, m_values[index], m_values[index]);
+}
+
+void MP4Integer32Property::Dump(FILE* pFile, u_int8_t indent,
+ bool dumpImplicits, u_int32_t index)
+{
+ if (m_implicit && !dumpImplicits) {
+ return;
+ }
+ Indent(pFile, indent);
+ fprintf(pFile, "%s = %u (0x%08x)\n",
+ m_name, m_values[index], m_values[index]);
+}
+
+void MP4Integer64Property::Dump(FILE* pFile, u_int8_t indent,
+ bool dumpImplicits, u_int32_t index)
+{
+ if (m_implicit && !dumpImplicits) {
+ return;
+ }
+ Indent(pFile, indent);
+ fprintf(pFile,
+ "%s = "U64" (0x%016"X64F")\n",
+ m_name, m_values[index], m_values[index]);
+}
+
+// MP4BitfieldProperty
+
+void MP4BitfieldProperty::Read(MP4File* pFile, u_int32_t index)
+{
+ if (m_implicit) {
+ return;
+ }
+ m_values[index] = pFile->ReadBits(m_numBits);
+}
+
+void MP4BitfieldProperty::Write(MP4File* pFile, u_int32_t index)
+{
+ if (m_implicit) {
+ return;
+ }
+ pFile->WriteBits(m_values[index], m_numBits);
+}
+
+void MP4BitfieldProperty::Dump(FILE* pFile, u_int8_t indent,
+ bool dumpImplicits, u_int32_t index)
+{
+ if (m_implicit && !dumpImplicits) {
+ return;
+ }
+ Indent(pFile, indent);
+
+ u_int8_t hexWidth = m_numBits / 4;
+ if (hexWidth == 0 || (m_numBits % 4)) {
+ hexWidth++;
+ }
+ fprintf(pFile,
+ "%s = "U64" (0x%0*"X64F") <%u bits>\n",
+ m_name, m_values[index], (int)hexWidth, m_values[index], m_numBits);
+}
+
+// MP4Float32Property
+
+void MP4Float32Property::Read(MP4File* pFile, u_int32_t index)
+{
+ if (m_implicit) {
+ return;
+ }
+ if (m_useFixed16Format) {
+ m_values[index] = pFile->ReadFixed16();
+ } else if (m_useFixed32Format) {
+ m_values[index] = pFile->ReadFixed32();
+ } else {
+ m_values[index] = pFile->ReadFloat();
+ }
+}
+
+void MP4Float32Property::Write(MP4File* pFile, u_int32_t index)
+{
+ if (m_implicit) {
+ return;
+ }
+ if (m_useFixed16Format) {
+ pFile->WriteFixed16(m_values[index]);
+ } else if (m_useFixed32Format) {
+ pFile->WriteFixed32(m_values[index]);
+ } else {
+ pFile->WriteFloat(m_values[index]);
+ }
+}
+
+void MP4Float32Property::Dump(FILE* pFile, u_int8_t indent,
+ bool dumpImplicits, u_int32_t index)
+{
+ if (m_implicit && !dumpImplicits) {
+ return;
+ }
+ Indent(pFile, indent);
+ fprintf(pFile, "%s = %f\n",
+ m_name, m_values[index]);
+}
+
+// MP4StringProperty
+
+MP4StringProperty::MP4StringProperty(char* name,
+ bool useCountedFormat, bool useUnicode)
+ : MP4Property(name)
+{
+ SetCount(1);
+ m_values[0] = NULL;
+ m_useCountedFormat = useCountedFormat;
+ m_useExpandedCount = false;
+ m_useUnicode = useUnicode;
+ m_fixedLength = 0; // length not fixed
+}
+
+MP4StringProperty::~MP4StringProperty()
+{
+ u_int32_t count = GetCount();
+ for (u_int32_t i = 0; i < count; i++) {
+ MP4Free(m_values[i]);
+ }
+}
+
+void MP4StringProperty::SetCount(u_int32_t count)
+{
+ u_int32_t oldCount = m_values.Size();
+
+ m_values.Resize(count);
+
+ for (u_int32_t i = oldCount; i < count; i++) {
+ m_values[i] = NULL;
+ }
+}
+
+void MP4StringProperty::SetValue(const char* value, u_int32_t index)
+{
+ if (m_readOnly) {
+ throw new MP4Error(EACCES, "property is read-only", m_name);
+ }
+
+ MP4Free(m_values[index]);
+
+ if (m_fixedLength) {
+ m_values[index] = (char*)MP4Calloc(m_fixedLength + 1);
+ if (value) {
+ strncpy(m_values[index], value, m_fixedLength);
+ }
+ } else {
+ if (value) {
+ m_values[index] = MP4Stralloc(value);
+ } else {
+ m_values[index] = NULL;
+ }
+ }
+}
+
+void MP4StringProperty::Read(MP4File* pFile, u_int32_t index)
+{
+ if (m_implicit) {
+ return;
+ }
+ if (m_useCountedFormat) {
+ m_values[index] = pFile->ReadCountedString(
+ (m_useUnicode ? 2 : 1), m_useExpandedCount);
+ } else if (m_fixedLength) {
+ MP4Free(m_values[index]);
+ m_values[index] = (char*)MP4Calloc(m_fixedLength + 1);
+ pFile->ReadBytes((u_int8_t*)m_values[index], m_fixedLength);
+ } else {
+ m_values[index] = pFile->ReadString();
+ }
+}
+
+void MP4StringProperty::Write(MP4File* pFile, u_int32_t index)
+{
+ if (m_implicit) {
+ return;
+ }
+ if (m_useCountedFormat) {
+ pFile->WriteCountedString(m_values[index],
+ (m_useUnicode ? 2 : 1), m_useExpandedCount);
+ } else if (m_fixedLength) {
+ pFile->WriteBytes((u_int8_t*)m_values[index], m_fixedLength);
+ } else {
+ pFile->WriteString(m_values[index]);
+ }
+}
+
+void MP4StringProperty::Dump(FILE* pFile, u_int8_t indent,
+ bool dumpImplicits, u_int32_t index)
+{
+ if (m_implicit && !dumpImplicits) {
+ return;
+ }
+ Indent(pFile, indent);
+ if (m_useUnicode) {
+ fprintf(pFile, "%s = %ls\n", m_name, (wchar_t*)m_values[index]);
+ } else {
+ fprintf(pFile, "%s = %s\n", m_name, m_values[index]);
+ }
+}
+
+// MP4BytesProperty
+
+MP4BytesProperty::MP4BytesProperty(char* name, u_int32_t valueSize,
+ u_int32_t defaultValueSize)
+ : MP4Property(name)
+{
+ SetCount(1);
+ m_values[0] = (u_int8_t*)MP4Calloc(valueSize);
+ m_valueSizes[0] = valueSize;
+ m_fixedValueSize = 0;
+ m_defaultValueSize = defaultValueSize;
+}
+
+MP4BytesProperty::~MP4BytesProperty()
+{
+ u_int32_t count = GetCount();
+ for (u_int32_t i = 0; i < count; i++) {
+ MP4Free(m_values[i]);
+ }
+}
+
+void MP4BytesProperty::SetCount(u_int32_t count)
+{
+ u_int32_t oldCount = m_values.Size();
+
+ m_values.Resize(count);
+ m_valueSizes.Resize(count);
+
+ for (u_int32_t i = oldCount; i < count; i++) {
+ m_values[i] = NULL;
+ m_valueSizes[i] = m_defaultValueSize;
+ }
+}
+
+void MP4BytesProperty::SetValue(const u_int8_t* pValue, u_int32_t valueSize,
+ u_int32_t index)
+{
+ if (m_readOnly) {
+ throw new MP4Error(EACCES, "property is read-only", m_name);
+ }
+ if (m_fixedValueSize) {
+ if (valueSize > m_fixedValueSize) {
+ throw new MP4Error("value size exceeds fixed value size",
+ "MP4BytesProperty::SetValue");
+ }
+ if (m_values[index] == NULL) {
+ m_values[index] = (u_int8_t*)MP4Calloc(m_fixedValueSize);
+ m_valueSizes[index] = m_fixedValueSize;
+ }
+ if (pValue) {
+ memcpy(m_values[index], pValue, valueSize);
+ }
+ } else {
+ MP4Free(m_values[index]);
+ if (pValue) {
+ m_values[index] = (u_int8_t*)MP4Malloc(valueSize);
+ memcpy(m_values[index], pValue, valueSize);
+ m_valueSizes[index] = valueSize;
+ } else {
+ m_values[index] = NULL;
+ m_valueSizes[index] = 0;
+ }
+ }
+}
+
+void MP4BytesProperty::SetValueSize(u_int32_t valueSize, u_int32_t index)
+{
+ if (m_fixedValueSize) {
+ throw new MP4Error("can't change size of fixed sized property",
+ "MP4BytesProperty::SetValueSize");
+ }
+ if (m_values[index] != NULL) {
+ m_values[index] = (u_int8_t*)MP4Realloc(m_values[index], valueSize);
+ }
+ m_valueSizes[index] = valueSize;
+}
+
+void MP4BytesProperty::SetFixedSize(u_int32_t fixedSize)
+{
+ m_fixedValueSize = 0;
+ for (u_int32_t i = 0; i < GetCount(); i++) {
+ SetValueSize(fixedSize, i);
+ }
+ m_fixedValueSize = fixedSize;
+}
+
+void MP4BytesProperty::Read(MP4File* pFile, u_int32_t index)
+{
+ if (m_implicit) {
+ return;
+ }
+ MP4Free(m_values[index]);
+ m_values[index] = (u_int8_t*)MP4Malloc(m_valueSizes[index]);
+ pFile->ReadBytes(m_values[index], m_valueSizes[index]);
+}
+
+void MP4BytesProperty::Write(MP4File* pFile, u_int32_t index)
+{
+ if (m_implicit) {
+ return;
+ }
+ pFile->WriteBytes(m_values[index], m_valueSizes[index]);
+}
+
+void MP4BytesProperty::Dump(FILE* pFile, u_int8_t indent,
+ bool dumpImplicits, u_int32_t index)
+{
+ if (m_implicit && !dumpImplicits) {
+ return;
+ }
+ Indent(pFile, indent);
+ fprintf(pFile, "%s = <%u bytes> ", m_name, m_valueSizes[index]);
+ for (u_int32_t i = 0; i < m_valueSizes[index]; i++) {
+ if ((i % 16) == 0 && m_valueSizes[index] > 16) {
+ fprintf(pFile, "\n");
+ Indent(pFile, indent);
+ }
+ fprintf(pFile, "%02x ", m_values[index][i]);
+ }
+ fprintf(pFile, "\n");
+}
+
+// MP4TableProperty
+
+MP4TableProperty::MP4TableProperty(char* name, MP4Property* pCountProperty)
+ : MP4Property(name)
+{
+ ASSERT(pCountProperty->GetType() == Integer8Property
+ || pCountProperty->GetType() == Integer32Property);
+ m_pCountProperty = pCountProperty;
+ m_pCountProperty->SetReadOnly();
+}
+
+MP4TableProperty::~MP4TableProperty()
+{
+ for (u_int32_t i = 0; i < m_pProperties.Size(); i++) {
+ delete m_pProperties[i];
+ }
+}
+
+void MP4TableProperty::AddProperty(MP4Property* pProperty)
+{
+ ASSERT(pProperty);
+ ASSERT(pProperty->GetType() != TableProperty);
+ ASSERT(pProperty->GetType() != DescriptorProperty);
+ m_pProperties.Add(pProperty);
+ pProperty->SetParentAtom(m_pParentAtom);
+ pProperty->SetCount(0);
+}
+
+bool MP4TableProperty::FindProperty(const char *name,
+ MP4Property** ppProperty, u_int32_t* pIndex)
+{
+ ASSERT(m_name);
+
+ // check if first component of name matches ourselves
+ if (!MP4NameFirstMatches(m_name, name)) {
+ return false;
+ }
+
+ // check if the specified table entry exists
+ u_int32_t index;
+ bool haveIndex = MP4NameFirstIndex(name, &index);
+ if (haveIndex) {
+ if (index >= GetCount()) {
+ return false;
+ }
+ if (pIndex) {
+ *pIndex = index;
+ }
+ }
+
+ VERBOSE_FIND(m_pParentAtom->GetFile()->GetVerbosity(),
+ printf("FindProperty: matched %s\n", name));
+
+ // get name of table property
+ const char *tablePropName = MP4NameAfterFirst(name);
+ if (tablePropName == NULL) {
+ if (!haveIndex) {
+ *ppProperty = this;
+ return true;
+ }
+ return false;
+ }
+
+ // check if this table property exists
+ return FindContainedProperty(tablePropName, ppProperty, pIndex);
+}
+
+bool MP4TableProperty::FindContainedProperty(const char *name,
+ MP4Property** ppProperty, u_int32_t* pIndex)
+{
+ u_int32_t numProperties = m_pProperties.Size();
+
+ for (u_int32_t i = 0; i < numProperties; i++) {
+ if (m_pProperties[i]->FindProperty(name, ppProperty, pIndex)) {
+ return true;
+ }
+ }
+ return false;
+}
+
+void MP4TableProperty::Read(MP4File* pFile, u_int32_t index)
+{
+ ASSERT(index == 0);
+
+ if (m_implicit) {
+ return;
+ }
+
+ u_int32_t numProperties = m_pProperties.Size();
+
+ if (numProperties == 0) {
+ WARNING(numProperties == 0);
+ return;
+ }
+
+ u_int32_t numEntries = GetCount();
+
+ /* for each property set size */
+ for (u_int32_t j = 0; j < numProperties; j++) {
+ m_pProperties[j]->SetCount(numEntries);
+ }
+
+ for (u_int32_t i = 0; i < numEntries; i++) {
+ ReadEntry(pFile, i);
+ }
+}
+
+void MP4TableProperty::ReadEntry(MP4File* pFile, u_int32_t index)
+{
+ for (u_int32_t j = 0; j < m_pProperties.Size(); j++) {
+ m_pProperties[j]->Read(pFile, index);
+ }
+}
+
+void MP4TableProperty::Write(MP4File* pFile, u_int32_t index)
+{
+ ASSERT(index == 0);
+
+ if (m_implicit) {
+ return;
+ }
+
+ u_int32_t numProperties = m_pProperties.Size();
+
+ if (numProperties == 0) {
+ WARNING(numProperties == 0);
+ return;
+ }
+
+ u_int32_t numEntries = GetCount();
+
+ ASSERT(m_pProperties[0]->GetCount() == numEntries);
+
+ for (u_int32_t i = 0; i < numEntries; i++) {
+ WriteEntry(pFile, i);
+ }
+}
+
+void MP4TableProperty::WriteEntry(MP4File* pFile, u_int32_t index)
+{
+ for (u_int32_t j = 0; j < m_pProperties.Size(); j++) {
+ m_pProperties[j]->Write(pFile, index);
+ }
+}
+
+void MP4TableProperty::Dump(FILE* pFile, u_int8_t indent,
+ bool dumpImplicits, u_int32_t index)
+{
+ ASSERT(index == 0);
+
+ // implicit tables just can't be dumped
+ if (m_implicit) {
+ return;
+ }
+
+ u_int32_t numProperties = m_pProperties.Size();
+
+ if (numProperties == 0) {
+ WARNING(numProperties == 0);
+ return;
+ }
+
+ u_int32_t numEntries = GetCount();
+
+ for (u_int32_t i = 0; i < numEntries; i++) {
+ for (u_int32_t j = 0; j < numProperties; j++) {
+ m_pProperties[j]->Dump(pFile, indent + 1, dumpImplicits, i);
+ }
+ }
+}
+
+// MP4DescriptorProperty
+
+MP4DescriptorProperty::MP4DescriptorProperty(char* name,
+ u_int8_t tagsStart, u_int8_t tagsEnd, bool mandatory, bool onlyOne)
+ : MP4Property(name)
+{
+ SetTags(tagsStart, tagsEnd);
+ m_sizeLimit = 0;
+ m_mandatory = mandatory;
+ m_onlyOne = onlyOne;
+}
+
+MP4DescriptorProperty::~MP4DescriptorProperty()
+{
+ for (u_int32_t i = 0; i < m_pDescriptors.Size(); i++) {
+ delete m_pDescriptors[i];
+ }
+}
+
+void MP4DescriptorProperty::SetParentAtom(MP4Atom* pParentAtom) {
+ m_pParentAtom = pParentAtom;
+ for (u_int32_t i = 0; i < m_pDescriptors.Size(); i++) {
+ m_pDescriptors[i]->SetParentAtom(pParentAtom);
+ }
+}
+
+MP4Descriptor* MP4DescriptorProperty::AddDescriptor(u_int8_t tag)
+{
+ // check that tag is in expected range
+ ASSERT(tag >= m_tagsStart && tag <= m_tagsEnd);
+
+ MP4Descriptor* pDescriptor = CreateDescriptor(tag);
+ ASSERT(pDescriptor);
+
+ m_pDescriptors.Add(pDescriptor);
+ pDescriptor->SetParentAtom(m_pParentAtom);
+
+ return pDescriptor;
+}
+
+void MP4DescriptorProperty::DeleteDescriptor(u_int32_t index)
+{
+ delete m_pDescriptors[index];
+ m_pDescriptors.Delete(index);
+}
+
+void MP4DescriptorProperty::Generate()
+{
+ // generate a default descriptor
+ // if it is mandatory, and single
+ if (m_mandatory && m_onlyOne) {
+ MP4Descriptor* pDescriptor =
+ AddDescriptor(m_tagsStart);
+ pDescriptor->Generate();
+ }
+}
+
+bool MP4DescriptorProperty::FindProperty(const char *name,
+ MP4Property** ppProperty, u_int32_t* pIndex)
+{
+ // we're unnamed, so just check contained properties
+ if (m_name == NULL || !strcmp(m_name, "")) {
+ return FindContainedProperty(name, ppProperty, pIndex);
+ }
+
+ // check if first component of name matches ourselves
+ if (!MP4NameFirstMatches(m_name, name)) {
+ return false;
+ }
+
+ // check if the specific descriptor entry exists
+ u_int32_t descrIndex;
+ bool haveDescrIndex = MP4NameFirstIndex(name, &descrIndex);
+
+ if (haveDescrIndex && descrIndex >= GetCount()) {
+ return false;
+ }
+
+ if (m_pParentAtom) {
+ VERBOSE_FIND(m_pParentAtom->GetFile()->GetVerbosity(),
+ printf("FindProperty: matched %s\n", name));
+ }
+
+ // get name of descriptor property
+ name = MP4NameAfterFirst(name);
+ if (name == NULL) {
+ if (!haveDescrIndex) {
+ *ppProperty = this;
+ return true;
+ }
+ return false;
+ }
+
+ /* check rest of name */
+ if (haveDescrIndex) {
+ return m_pDescriptors[descrIndex]->FindProperty(name,
+ ppProperty, pIndex);
+ } else {
+ return FindContainedProperty(name, ppProperty, pIndex);
+ }
+}
+
+bool MP4DescriptorProperty::FindContainedProperty(const char *name,
+ MP4Property** ppProperty, u_int32_t* pIndex)
+{
+ for (u_int32_t i = 0; i < m_pDescriptors.Size(); i++) {
+ if (m_pDescriptors[i]->FindProperty(name, ppProperty, pIndex)) {
+ return true;
+ }
+ }
+ return false;
+}
+
+void MP4DescriptorProperty::Read(MP4File* pFile, u_int32_t index)
+{
+ ASSERT(index == 0);
+
+ if (m_implicit) {
+ return;
+ }
+
+ u_int64_t start = pFile->GetPosition();
+
+ while (true) {
+ // enforce size limitation
+ if (m_sizeLimit && pFile->GetPosition() >= start + m_sizeLimit) {
+ break;
+ }
+
+ u_int8_t tag;
+ try {
+ pFile->PeekBytes(&tag, 1);
+ }
+ catch (MP4Error* e) {
+ if (pFile->GetPosition() >= pFile->GetSize()) {
+ // EOF
+ delete e;
+ break;
+ }
+ throw e;
+ }
+
+ // check if tag is in desired range
+ if (tag < m_tagsStart || tag > m_tagsEnd) {
+ break;
+ }
+
+ MP4Descriptor* pDescriptor =
+ AddDescriptor(tag);
+
+ pDescriptor->Read(pFile);
+ }
+
+ // warnings
+ if (m_mandatory && m_pDescriptors.Size() == 0) {
+ VERBOSE_READ(pFile->GetVerbosity(),
+ printf("Warning: Mandatory descriptor 0x%02x missing\n",
+ m_tagsStart));
+ } else if (m_onlyOne && m_pDescriptors.Size() > 1) {
+ VERBOSE_READ(pFile->GetVerbosity(),
+ printf("Warning: Descriptor 0x%02x has more than one instance\n",
+ m_tagsStart));
+ }
+}
+
+void MP4DescriptorProperty::Write(MP4File* pFile, u_int32_t index)
+{
+ ASSERT(index == 0);
+
+ if (m_implicit) {
+ return;
+ }
+
+ for (u_int32_t i = 0; i < m_pDescriptors.Size(); i++) {
+ m_pDescriptors[i]->Write(pFile);
+ }
+}
+
+void MP4DescriptorProperty::Dump(FILE* pFile, u_int8_t indent,
+ bool dumpImplicits, u_int32_t index)
+{
+ ASSERT(index == 0);
+
+ if (m_implicit && !dumpImplicits) {
+ return;
+ }
+
+ if (m_name) {
+ Indent(pFile, indent);
+ fprintf(pFile, "%s\n", m_name);
+ indent++;
+ }
+
+ for (u_int32_t i = 0; i < m_pDescriptors.Size(); i++) {
+ m_pDescriptors[i]->Dump(pFile, indent, dumpImplicits);
+ }
+}
+
--- /dev/null
+++ b/common/mp4v2/mp4property.h
@@ -1,0 +1,551 @@
+/*
+ * 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
+ */
+
+#ifndef __MP4_PROPERTY_INCLUDED__
+#define __MP4_PROPERTY_INCLUDED__
+
+// forward declarations
+class MP4Atom;
+
+class MP4Descriptor;
+MP4ARRAY_DECL(MP4Descriptor, MP4Descriptor*);
+
+enum MP4PropertyType {
+ Integer8Property,
+ Integer16Property,
+ Integer24Property,
+ Integer32Property,
+ Integer64Property,
+ Float32Property,
+ StringProperty,
+ BytesProperty,
+ TableProperty,
+ DescriptorProperty,
+};
+
+class MP4Property {
+public:
+ MP4Property(const char *name = NULL);
+
+ virtual ~MP4Property() { }
+
+ MP4Atom* GetParentAtom() {
+ return m_pParentAtom;
+ }
+ virtual void SetParentAtom(MP4Atom* pParentAtom) {
+ m_pParentAtom = pParentAtom;
+ }
+
+ const char *GetName() {
+ return m_name;
+ }
+
+ virtual MP4PropertyType GetType() = 0;
+
+ bool IsReadOnly() {
+ return m_readOnly;
+ }
+ void SetReadOnly(bool value = true) {
+ m_readOnly = value;
+ }
+
+ bool IsImplicit() {
+ return m_implicit;
+ }
+ void SetImplicit(bool value = true) {
+ m_implicit = value;
+ }
+
+ virtual u_int32_t GetCount() = 0;
+ virtual void SetCount(u_int32_t count) = 0;
+
+ virtual void Generate() { /* default is a no-op */ };
+
+ virtual void Read(MP4File* pFile, u_int32_t index = 0) = 0;
+
+ virtual void Write(MP4File* pFile, u_int32_t index = 0) = 0;
+
+ virtual void Dump(FILE* pFile, u_int8_t indent,
+ bool dumpImplicits, u_int32_t index = 0) = 0;
+
+ virtual bool FindProperty(const char* name,
+ MP4Property** ppProperty, u_int32_t* pIndex = NULL);
+
+protected:
+ MP4Atom* m_pParentAtom;
+ const char* m_name;
+ bool m_readOnly;
+ bool m_implicit;
+};
+
+MP4ARRAY_DECL(MP4Property, MP4Property*);
+
+class MP4IntegerProperty : public MP4Property {
+protected:
+ MP4IntegerProperty(char* name)
+ : MP4Property(name) { };
+
+public:
+ u_int64_t GetValue(u_int32_t index = 0);
+
+ void SetValue(u_int64_t value, u_int32_t index = 0);
+
+ void InsertValue(u_int64_t value, u_int32_t index = 0);
+
+ void DeleteValue(u_int32_t index = 0);
+
+ void IncrementValue(int32_t increment = 1, u_int32_t index = 0);
+};
+
+#define MP4INTEGER_PROPERTY_DECL2(isize, xsize) \
+ class MP4Integer##xsize##Property : public MP4IntegerProperty { \
+ public: \
+ MP4Integer##xsize##Property(char* name) \
+ : MP4IntegerProperty(name) { \
+ SetCount(1); \
+ m_values[0] = 0; \
+ } \
+ \
+ MP4PropertyType GetType() { \
+ return Integer##xsize##Property; \
+ } \
+ \
+ u_int32_t GetCount() { \
+ return m_values.Size(); \
+ } \
+ void SetCount(u_int32_t count) { \
+ m_values.Resize(count); \
+ } \
+ \
+ u_int##isize##_t GetValue(u_int32_t index = 0) { \
+ return m_values[index]; \
+ } \
+ \
+ void SetValue(u_int##isize##_t value, u_int32_t index = 0) { \
+ if (m_readOnly) { \
+ throw new MP4Error(EACCES, "property is read-only", m_name); \
+ } \
+ m_values[index] = value; \
+ } \
+ void AddValue(u_int##isize##_t value) { \
+ m_values.Add(value); \
+ } \
+ void InsertValue(u_int##isize##_t value, u_int32_t index) { \
+ m_values.Insert(value, index); \
+ } \
+ void DeleteValue(u_int32_t index) { \
+ m_values.Delete(index); \
+ } \
+ void IncrementValue(int32_t increment = 1, u_int32_t index = 0) { \
+ m_values[index] += increment; \
+ } \
+ void Read(MP4File* pFile, u_int32_t index = 0) { \
+ if (m_implicit) { \
+ return; \
+ } \
+ m_values[index] = pFile->ReadUInt##xsize(); \
+ } \
+ \
+ void Write(MP4File* pFile, u_int32_t index = 0) { \
+ if (m_implicit) { \
+ return; \
+ } \
+ pFile->WriteUInt##xsize(m_values[index]); \
+ } \
+ void Dump(FILE* pFile, u_int8_t indent, \
+ bool dumpImplicits, u_int32_t index = 0); \
+ \
+ protected: \
+ MP4Integer##isize##Array m_values; \
+ };
+
+#define MP4INTEGER_PROPERTY_DECL(size) \
+ MP4INTEGER_PROPERTY_DECL2(size, size)
+
+MP4INTEGER_PROPERTY_DECL(8);
+MP4INTEGER_PROPERTY_DECL(16);
+MP4INTEGER_PROPERTY_DECL2(32, 24);
+MP4INTEGER_PROPERTY_DECL(32);
+MP4INTEGER_PROPERTY_DECL(64);
+
+class MP4BitfieldProperty : public MP4Integer64Property {
+public:
+ MP4BitfieldProperty(char* name, u_int8_t numBits)
+ : MP4Integer64Property(name) {
+ ASSERT(numBits != 0);
+ ASSERT(numBits <= 64);
+ m_numBits = numBits;
+ }
+
+ u_int8_t GetNumBits() {
+ return m_numBits;
+ }
+ void SetNumBits(u_int8_t numBits) {
+ m_numBits = numBits;
+ }
+
+ void Read(MP4File* pFile, u_int32_t index = 0);
+ void Write(MP4File* pFile, u_int32_t index = 0);
+ void Dump(FILE* pFile, u_int8_t indent,
+ bool dumpImplicits, u_int32_t index = 0);
+
+protected:
+ u_int8_t m_numBits;
+};
+
+class MP4Float32Property : public MP4Property {
+public:
+ MP4Float32Property(char* name)
+ : MP4Property(name) {
+ m_useFixed16Format = false;
+ m_useFixed32Format = false;
+ SetCount(1);
+ m_values[0] = 0.0;
+ }
+
+ MP4PropertyType GetType() {
+ return Float32Property;
+ }
+
+ u_int32_t GetCount() {
+ return m_values.Size();
+ }
+ void SetCount(u_int32_t count) {
+ m_values.Resize(count);
+ }
+
+ float GetValue(u_int32_t index = 0) {
+ return m_values[index];
+ }
+
+ void SetValue(float value, u_int32_t index = 0) {
+ if (m_readOnly) {
+ throw new MP4Error(EACCES, "property is read-only", m_name);
+ }
+ m_values[index] = value;
+ }
+
+ void AddValue(float value) {
+ m_values.Add(value);
+ }
+
+ void InsertValue(float value, u_int32_t index) {
+ m_values.Insert(value, index);
+ }
+
+ bool IsFixed16Format() {
+ return m_useFixed16Format;
+ }
+
+ void SetFixed16Format(bool useFixed16Format = true) {
+ m_useFixed16Format = useFixed16Format;
+ }
+
+ bool IsFixed32Format() {
+ return m_useFixed32Format;
+ }
+
+ void SetFixed32Format(bool useFixed32Format = true) {
+ m_useFixed32Format = useFixed32Format;
+ }
+
+ void Read(MP4File* pFile, u_int32_t index = 0);
+ void Write(MP4File* pFile, u_int32_t index = 0);
+ void Dump(FILE* pFile, u_int8_t indent,
+ bool dumpImplicits, u_int32_t index = 0);
+
+protected:
+ bool m_useFixed16Format;
+ bool m_useFixed32Format;
+ MP4Float32Array m_values;
+};
+
+class MP4StringProperty : public MP4Property {
+public:
+ MP4StringProperty(char* name,
+ bool useCountedFormat = false, bool useUnicode = false);
+
+ ~MP4StringProperty();
+
+ MP4PropertyType GetType() {
+ return StringProperty;
+ }
+
+ u_int32_t GetCount() {
+ return m_values.Size();
+ }
+
+ void SetCount(u_int32_t count);
+
+ const char* GetValue(u_int32_t index = 0) {
+ return m_values[index];
+ }
+
+ void SetValue(const char* value, u_int32_t index = 0);
+
+ void AddValue(char* value) {
+ u_int32_t count = GetCount();
+ SetCount(count + 1);
+ SetValue(value, count);
+ }
+
+ bool IsCountedFormat() {
+ return m_useCountedFormat;
+ }
+
+ void SetCountedFormat(bool useCountedFormat) {
+ m_useCountedFormat = useCountedFormat;
+ }
+
+ bool IsExpandedCountedFormat() {
+ return m_useExpandedCount;
+ }
+
+ void SetExpandedCountedFormat(bool useExpandedCount) {
+ m_useExpandedCount = useExpandedCount;
+ }
+
+ bool IsUnicode() {
+ return m_useUnicode;
+ }
+
+ void SetUnicode(bool useUnicode) {
+ m_useUnicode = useUnicode;
+ }
+
+ u_int32_t GetFixedLength() {
+ return m_fixedLength;
+ }
+
+ void SetFixedLength(u_int32_t fixedLength) {
+ m_fixedLength = fixedLength;
+ }
+
+ void Read(MP4File* pFile, u_int32_t index = 0);
+ void Write(MP4File* pFile, u_int32_t index = 0);
+ void Dump(FILE* pFile, u_int8_t indent,
+ bool dumpImplicits, u_int32_t index = 0);
+
+protected:
+ bool m_useCountedFormat;
+ bool m_useExpandedCount;
+ bool m_useUnicode;
+ u_int32_t m_fixedLength;
+
+ MP4StringArray m_values;
+};
+
+class MP4BytesProperty : public MP4Property {
+public:
+ MP4BytesProperty(char* name, u_int32_t valueSize = 0,
+ u_int32_t defaultValueSize = 0);
+
+ ~MP4BytesProperty();
+
+ MP4PropertyType GetType() {
+ return BytesProperty;
+ }
+
+ u_int32_t GetCount() {
+ return m_values.Size();
+ }
+
+ void SetCount(u_int32_t count);
+
+ void GetValue(u_int8_t** ppValue, u_int32_t* pValueSize,
+ u_int32_t index = 0) {
+ // N.B. caller must free memory
+ *ppValue = (u_int8_t*)MP4Malloc(m_valueSizes[index]);
+ memcpy(*ppValue, m_values[index], m_valueSizes[index]);
+ *pValueSize = m_valueSizes[index];
+ }
+
+ void CopyValue(u_int8_t* pValue, u_int32_t index = 0) {
+ // N.B. caller takes responsbility for valid pointer
+ // and sufficient memory at the destination
+ memcpy(pValue, m_values[index], m_valueSizes[index]);
+ }
+
+ void SetValue(const u_int8_t* pValue, u_int32_t valueSize,
+ u_int32_t index = 0);
+
+ void AddValue(u_int8_t* pValue, u_int32_t valueSize) {
+ u_int32_t count = GetCount();
+ SetCount(count + 1);
+ SetValue(pValue, valueSize, count);
+ }
+
+ u_int32_t GetValueSize(u_int32_t valueSize, u_int32_t index = 0) {
+ return m_valueSizes[index];
+ }
+
+ void SetValueSize(u_int32_t valueSize, u_int32_t index = 0);
+
+ u_int32_t GetFixedSize() {
+ return m_fixedValueSize;
+ }
+
+ void SetFixedSize(u_int32_t fixedSize);
+
+ void Read(MP4File* pFile, u_int32_t index = 0);
+ void Write(MP4File* pFile, u_int32_t index = 0);
+ void Dump(FILE* pFile, u_int8_t indent,
+ bool dumpImplicits, u_int32_t index = 0);
+
+protected:
+ u_int32_t m_fixedValueSize;
+ u_int32_t m_defaultValueSize;
+ MP4Integer32Array m_valueSizes;
+ MP4BytesArray m_values;
+};
+
+class MP4TableProperty : public MP4Property {
+public:
+ MP4TableProperty(char* name, MP4Property* pCountProperty);
+
+ ~MP4TableProperty();
+
+ MP4PropertyType GetType() {
+ return TableProperty;
+ }
+
+ void SetParentAtom(MP4Atom* pParentAtom) {
+ m_pParentAtom = pParentAtom;
+ for (u_int32_t i = 0; i < m_pProperties.Size(); i++) {
+ m_pProperties[i]->SetParentAtom(pParentAtom);
+ }
+ }
+
+ void AddProperty(MP4Property* pProperty);
+
+ MP4Property* GetProperty(u_int32_t index) {
+ return m_pProperties[index];
+ }
+
+ u_int32_t GetCount() {
+ if (m_pCountProperty->GetType() == Integer8Property) {
+ return ((MP4Integer8Property*)m_pCountProperty)->GetValue();
+ } else {
+ return ((MP4Integer32Property*)m_pCountProperty)->GetValue();
+ }
+ }
+ void SetCount(u_int32_t count) {
+ if (m_pCountProperty->GetType() == Integer8Property) {
+ ((MP4Integer8Property*)m_pCountProperty)->SetValue(count);
+ } else {
+ ((MP4Integer32Property*)m_pCountProperty)->SetValue(count);
+ }
+ }
+
+ void Read(MP4File* pFile, u_int32_t index = 0);
+ void Write(MP4File* pFile, u_int32_t index = 0);
+ void Dump(FILE* pFile, u_int8_t indent,
+ bool dumpImplicits, u_int32_t index = 0);
+
+ bool FindProperty(const char* name,
+ MP4Property** ppProperty, u_int32_t* pIndex = NULL);
+
+protected:
+ virtual void ReadEntry(MP4File* pFile, u_int32_t index);
+ virtual void WriteEntry(MP4File* pFile, u_int32_t index);
+
+ bool FindContainedProperty(const char* name,
+ MP4Property** ppProperty, u_int32_t* pIndex);
+
+protected:
+ MP4Property* m_pCountProperty;
+ MP4PropertyArray m_pProperties;
+};
+
+class MP4DescriptorProperty : public MP4Property {
+public:
+ MP4DescriptorProperty(char* name = NULL,
+ u_int8_t tagsStart = 0, u_int8_t tagsEnd = 0,
+ bool mandatory = false, bool onlyOne = false);
+
+ ~MP4DescriptorProperty();
+
+ MP4PropertyType GetType() {
+ return DescriptorProperty;
+ }
+
+ void SetParentAtom(MP4Atom* pParentAtom);
+
+ void SetSizeLimit(u_int64_t sizeLimit) {
+ m_sizeLimit = sizeLimit;
+ }
+
+ u_int32_t GetCount() {
+ return m_pDescriptors.Size();
+ }
+ void SetCount(u_int32_t count) {
+ m_pDescriptors.Resize(count);
+ }
+
+ void SetTags(u_int8_t tagsStart, u_int8_t tagsEnd = 0) {
+ m_tagsStart = tagsStart;
+ m_tagsEnd = tagsEnd ? tagsEnd : tagsStart;
+ }
+
+ MP4Descriptor* AddDescriptor(u_int8_t tag);
+
+ void AppendDescriptor(MP4Descriptor* pDescriptor) {
+ m_pDescriptors.Add(pDescriptor);
+ }
+
+ void DeleteDescriptor(u_int32_t index);
+
+ void Generate();
+ void Read(MP4File* pFile, u_int32_t index = 0);
+ void Write(MP4File* pFile, u_int32_t index = 0);
+ void Dump(FILE* pFile, u_int8_t indent,
+ bool dumpImplicits, u_int32_t index = 0);
+
+ bool FindProperty(const char* name,
+ MP4Property** ppProperty, u_int32_t* pIndex = NULL);
+
+protected:
+ virtual MP4Descriptor* CreateDescriptor(u_int8_t tag);
+
+ bool FindContainedProperty(const char* name,
+ MP4Property** ppProperty, u_int32_t* pIndex);
+
+protected:
+ u_int8_t m_tagsStart;
+ u_int8_t m_tagsEnd;
+ u_int64_t m_sizeLimit;
+ bool m_mandatory;
+ bool m_onlyOne;
+ MP4DescriptorArray m_pDescriptors;
+};
+
+class MP4QosQualifierProperty : public MP4DescriptorProperty {
+public:
+ MP4QosQualifierProperty(char* name = NULL,
+ u_int8_t tagsStart = 0, u_int8_t tagsEnd = 0,
+ bool mandatory = false, bool onlyOne = false) :
+ MP4DescriptorProperty(name, tagsStart, tagsEnd, mandatory, onlyOne) { }
+
+protected:
+ MP4Descriptor* CreateDescriptor(u_int8_t tag);
+};
+
+#endif /* __MP4_PROPERTY_INCLUDED__ */
--- /dev/null
+++ b/common/mp4v2/mp4track.cpp
@@ -1,0 +1,1670 @@
+/*
+ * 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 - 2004. All Rights Reserved.
+ *
+ * 3GPP features implementation is based on 3GPP's TS26.234-v5.60,
+ * and was contributed by Ximpo Group Ltd.
+ *
+ * Portions created by Ximpo Group Ltd. are
+ * Copyright (C) Ximpo Group Ltd. 2003, 2004. All Rights Reserved.
+ *
+ * Contributor(s):
+ * Dave Mackie dmackie@cisco.com
+ * Alix Marchandise-Franquet alix@cisco.com
+ * Ximpo Group Ltd. mp4v2@ximpo.com
+ */
+
+#include "mp4common.h"
+
+#define AMR_UNINITIALIZED -1
+#define AMR_TRUE 0
+#define AMR_FALSE 1
+
+MP4Track::MP4Track(MP4File* pFile, MP4Atom* pTrakAtom)
+{
+ m_pFile = pFile;
+ m_pTrakAtom = pTrakAtom;
+
+ m_lastStsdIndex = 0;
+ m_lastSampleFile = NULL;
+
+ m_cachedReadSampleId = MP4_INVALID_SAMPLE_ID;
+ m_pCachedReadSample = NULL;
+ m_cachedReadSampleSize = 0;
+
+ m_writeSampleId = 1;
+ m_fixedSampleDuration = 0;
+ m_pChunkBuffer = NULL;
+ m_chunkBufferSize = 0;
+ m_chunkSamples = 0;
+ m_chunkDuration = 0;
+
+ m_samplesPerChunk = 0;
+ m_durationPerChunk = 0;
+ m_isAmr = AMR_UNINITIALIZED;
+ m_curMode = 0;
+
+ bool success = true;
+
+ MP4Integer32Property* pTrackIdProperty;
+ success &= m_pTrakAtom->FindProperty(
+ "trak.tkhd.trackId",
+ (MP4Property**)&pTrackIdProperty);
+ if (success) {
+ m_trackId = pTrackIdProperty->GetValue();
+ }
+
+ success &= m_pTrakAtom->FindProperty(
+ "trak.mdia.mdhd.timeScale",
+ (MP4Property**)&m_pTimeScaleProperty);
+ if (success) {
+ // default chunking is 1 second of samples
+ m_durationPerChunk = m_pTimeScaleProperty->GetValue();
+ }
+
+ success &= m_pTrakAtom->FindProperty(
+ "trak.tkhd.duration",
+ (MP4Property**)&m_pTrackDurationProperty);
+
+ success &= m_pTrakAtom->FindProperty(
+ "trak.mdia.mdhd.duration",
+ (MP4Property**)&m_pMediaDurationProperty);
+
+ success &= m_pTrakAtom->FindProperty(
+ "trak.tkhd.modificationTime",
+ (MP4Property**)&m_pTrackModificationProperty);
+
+ success &= m_pTrakAtom->FindProperty(
+ "trak.mdia.mdhd.modificationTime",
+ (MP4Property**)&m_pMediaModificationProperty);
+
+ success &= m_pTrakAtom->FindProperty(
+ "trak.mdia.hdlr.handlerType",
+ (MP4Property**)&m_pTypeProperty);
+
+ // get handles on sample size information
+
+ success &= m_pTrakAtom->FindProperty(
+ "trak.mdia.minf.stbl.stsz.sampleSize",
+ (MP4Property**)&m_pStszFixedSampleSizeProperty);
+
+ success &= m_pTrakAtom->FindProperty(
+ "trak.mdia.minf.stbl.stsz.sampleCount",
+ (MP4Property**)&m_pStszSampleCountProperty);
+
+ success &= m_pTrakAtom->FindProperty(
+ "trak.mdia.minf.stbl.stsz.entries.sampleSize",
+ (MP4Property**)&m_pStszSampleSizeProperty);
+
+ // get handles on information needed to map sample id's to file offsets
+
+ success &= m_pTrakAtom->FindProperty(
+ "trak.mdia.minf.stbl.stsc.entryCount",
+ (MP4Property**)&m_pStscCountProperty);
+
+ success &= m_pTrakAtom->FindProperty(
+ "trak.mdia.minf.stbl.stsc.entries.firstChunk",
+ (MP4Property**)&m_pStscFirstChunkProperty);
+
+ success &= m_pTrakAtom->FindProperty(
+ "trak.mdia.minf.stbl.stsc.entries.samplesPerChunk",
+ (MP4Property**)&m_pStscSamplesPerChunkProperty);
+
+ success &= m_pTrakAtom->FindProperty(
+ "trak.mdia.minf.stbl.stsc.entries.sampleDescriptionIndex",
+ (MP4Property**)&m_pStscSampleDescrIndexProperty);
+
+ success &= m_pTrakAtom->FindProperty(
+ "trak.mdia.minf.stbl.stsc.entries.firstSample",
+ (MP4Property**)&m_pStscFirstSampleProperty);
+
+ bool haveStco = m_pTrakAtom->FindProperty(
+ "trak.mdia.minf.stbl.stco.entryCount",
+ (MP4Property**)&m_pChunkCountProperty);
+
+ if (haveStco) {
+ success &= m_pTrakAtom->FindProperty(
+ "trak.mdia.minf.stbl.stco.entries.chunkOffset",
+ (MP4Property**)&m_pChunkOffsetProperty);
+ } else {
+ success &= m_pTrakAtom->FindProperty(
+ "trak.mdia.minf.stbl.co64.entryCount",
+ (MP4Property**)&m_pChunkCountProperty);
+
+ success &= m_pTrakAtom->FindProperty(
+ "trak.mdia.minf.stbl.co64.entries.chunkOffset",
+ (MP4Property**)&m_pChunkOffsetProperty);
+ }
+
+ // get handles on sample timing info
+
+ success &= m_pTrakAtom->FindProperty(
+ "trak.mdia.minf.stbl.stts.entryCount",
+ (MP4Property**)&m_pSttsCountProperty);
+
+ success &= m_pTrakAtom->FindProperty(
+ "trak.mdia.minf.stbl.stts.entries.sampleCount",
+ (MP4Property**)&m_pSttsSampleCountProperty);
+
+ success &= m_pTrakAtom->FindProperty(
+ "trak.mdia.minf.stbl.stts.entries.sampleDelta",
+ (MP4Property**)&m_pSttsSampleDeltaProperty);
+
+ // get handles on rendering offset info if it exists
+
+ m_pCttsCountProperty = NULL;
+ m_pCttsSampleCountProperty = NULL;
+ m_pCttsSampleOffsetProperty = NULL;
+
+ bool haveCtts = m_pTrakAtom->FindProperty(
+ "trak.mdia.minf.stbl.ctts.entryCount",
+ (MP4Property**)&m_pCttsCountProperty);
+
+ if (haveCtts) {
+ success &= m_pTrakAtom->FindProperty(
+ "trak.mdia.minf.stbl.ctts.entries.sampleCount",
+ (MP4Property**)&m_pCttsSampleCountProperty);
+
+ success &= m_pTrakAtom->FindProperty(
+ "trak.mdia.minf.stbl.ctts.entries.sampleOffset",
+ (MP4Property**)&m_pCttsSampleOffsetProperty);
+ }
+
+ // get handles on sync sample info if it exists
+
+ m_pStssCountProperty = NULL;
+ m_pStssSampleProperty = NULL;
+
+ bool haveStss = m_pTrakAtom->FindProperty(
+ "trak.mdia.minf.stbl.stss.entryCount",
+ (MP4Property**)&m_pStssCountProperty);
+
+ if (haveStss) {
+ success &= m_pTrakAtom->FindProperty(
+ "trak.mdia.minf.stbl.stss.entries.sampleNumber",
+ (MP4Property**)&m_pStssSampleProperty);
+ }
+
+ // edit list
+ InitEditListProperties();
+
+ // was everything found?
+ if (!success) {
+ throw new MP4Error("invalid track", "MP4Track::MP4Track");
+ }
+}
+
+MP4Track::~MP4Track()
+{
+ MP4Free(m_pCachedReadSample);
+ MP4Free(m_pChunkBuffer);
+}
+
+const char* MP4Track::GetType()
+{
+ return m_pTypeProperty->GetValue();
+}
+
+void MP4Track::SetType(const char* type)
+{
+ m_pTypeProperty->SetValue(NormalizeTrackType(type));
+}
+
+void MP4Track::ReadSample(
+ MP4SampleId sampleId,
+ u_int8_t** ppBytes,
+ u_int32_t* pNumBytes,
+ MP4Timestamp* pStartTime,
+ MP4Duration* pDuration,
+ MP4Duration* pRenderingOffset,
+ bool* pIsSyncSample)
+{
+ if (sampleId == MP4_INVALID_SAMPLE_ID) {
+ throw new MP4Error("sample id can't be zero",
+ "MP4Track::ReadSample");
+ }
+
+ // handle unusual case of wanting to read a sample
+ // that is still sitting in the write chunk buffer
+ if (m_pChunkBuffer && sampleId >= m_writeSampleId - m_chunkSamples) {
+ WriteChunkBuffer();
+ }
+
+ FILE* pFile = GetSampleFile(sampleId);
+
+ if (pFile == (FILE*)-1) {
+ throw new MP4Error("sample is located in an inaccessible file",
+ "MP4Track::ReadSample");
+ }
+
+ u_int64_t fileOffset = GetSampleFileOffset(sampleId);
+
+ u_int32_t sampleSize = GetSampleSize(sampleId);
+ if (*ppBytes != NULL && *pNumBytes < sampleSize) {
+ throw new MP4Error("sample buffer is too small",
+ "MP4Track::ReadSample");
+ }
+ *pNumBytes = sampleSize;
+
+ VERBOSE_READ_SAMPLE(m_pFile->GetVerbosity(),
+ printf("ReadSample: track %u id %u offset 0x"X64" size %u (0x%x)\n",
+ m_trackId, sampleId, fileOffset, *pNumBytes, *pNumBytes));
+
+ bool bufferMalloc = false;
+ if (*ppBytes == NULL) {
+ *ppBytes = (u_int8_t*)MP4Malloc(*pNumBytes);
+ bufferMalloc = true;
+ }
+
+ u_int64_t oldPos = m_pFile->GetPosition(pFile); // only used in mode == 'w'
+ try {
+ m_pFile->SetPosition(fileOffset, pFile);
+ m_pFile->ReadBytes(*ppBytes, *pNumBytes, pFile);
+
+ if (pStartTime || pDuration) {
+ GetSampleTimes(sampleId, pStartTime, pDuration);
+
+ VERBOSE_READ_SAMPLE(m_pFile->GetVerbosity(),
+ printf("ReadSample: start "U64" duration "D64"\n",
+ (pStartTime ? *pStartTime : 0),
+ (pDuration ? *pDuration : 0)));
+ }
+ if (pRenderingOffset) {
+ *pRenderingOffset = GetSampleRenderingOffset(sampleId);
+
+ VERBOSE_READ_SAMPLE(m_pFile->GetVerbosity(),
+ printf("ReadSample: renderingOffset "D64"\n",
+ *pRenderingOffset));
+ }
+ if (pIsSyncSample) {
+ *pIsSyncSample = IsSyncSample(sampleId);
+
+ VERBOSE_READ_SAMPLE(m_pFile->GetVerbosity(),
+ printf("ReadSample: isSyncSample %u\n",
+ *pIsSyncSample));
+ }
+ }
+
+ catch (MP4Error* e) {
+ if (bufferMalloc) {
+ // let's not leak memory
+ MP4Free(*ppBytes);
+ *ppBytes = NULL;
+ }
+ if (m_pFile->GetMode() == 'w') {
+ m_pFile->SetPosition(oldPos, pFile);
+ }
+ throw e;
+ }
+
+ if (m_pFile->GetMode() == 'w') {
+ m_pFile->SetPosition(oldPos, pFile);
+ }
+}
+
+void MP4Track::ReadSampleFragment(
+ MP4SampleId sampleId,
+ u_int32_t sampleOffset,
+ u_int16_t sampleLength,
+ u_int8_t* pDest)
+{
+ if (sampleId == MP4_INVALID_SAMPLE_ID) {
+ throw new MP4Error("invalid sample id",
+ "MP4Track::ReadSampleFragment");
+ }
+
+ if (sampleId != m_cachedReadSampleId) {
+ MP4Free(m_pCachedReadSample);
+ m_pCachedReadSample = NULL;
+ m_cachedReadSampleSize = 0;
+ m_cachedReadSampleId = MP4_INVALID_SAMPLE_ID;
+
+ ReadSample(
+ sampleId,
+ &m_pCachedReadSample,
+ &m_cachedReadSampleSize);
+
+ m_cachedReadSampleId = sampleId;
+ }
+
+ if (sampleOffset + sampleLength > m_cachedReadSampleSize) {
+ throw new MP4Error("offset and/or length are too large",
+ "MP4Track::ReadSampleFragment");
+ }
+
+ memcpy(pDest, &m_pCachedReadSample[sampleOffset], sampleLength);
+}
+
+void MP4Track::WriteSample(
+ const u_int8_t* pBytes,
+ u_int32_t numBytes,
+ MP4Duration duration,
+ MP4Duration renderingOffset,
+ bool isSyncSample)
+{
+ u_int8_t curMode = 0;
+
+ VERBOSE_WRITE_SAMPLE(m_pFile->GetVerbosity(),
+ printf("WriteSample: track %u id %u size %u (0x%x) ",
+ m_trackId, m_writeSampleId, numBytes, numBytes));
+
+ if (pBytes == NULL && numBytes > 0) {
+ throw new MP4Error("no sample data", "MP4WriteSample");
+ }
+
+ if (m_isAmr == AMR_UNINITIALIZED ) {
+ // figure out if this is an AMR audio track
+ if (m_pTrakAtom->FindAtom("trak.mdia.minf.stbl.stsd.samr") ||
+ m_pTrakAtom->FindAtom("trak.mdia.minf.stbl.stsd.sawb")) {
+ m_isAmr = AMR_TRUE;
+ m_curMode = (pBytes[0] >> 3) & 0x000F;
+ } else {
+ m_isAmr = AMR_FALSE;
+ }
+ }
+
+ if (m_isAmr == AMR_TRUE) {
+ curMode = (pBytes[0] >> 3) &0x000F; // The mode is in the first byte
+ }
+
+ if (duration == MP4_INVALID_DURATION) {
+ duration = GetFixedSampleDuration();
+ }
+
+ VERBOSE_WRITE_SAMPLE(m_pFile->GetVerbosity(),
+ printf("duration "U64"\n", duration));
+
+ if ((m_isAmr == AMR_TRUE) &&
+ (m_curMode != curMode)) {
+ WriteChunkBuffer();
+ m_curMode = curMode;
+ }
+
+ // append sample bytes to chunk buffer
+ m_pChunkBuffer = (u_int8_t*)MP4Realloc(m_pChunkBuffer,
+ m_chunkBufferSize + numBytes);
+ memcpy(&m_pChunkBuffer[m_chunkBufferSize], pBytes, numBytes);
+ m_chunkBufferSize += numBytes;
+ m_chunkSamples++;
+ m_chunkDuration += duration;
+
+ UpdateSampleSizes(m_writeSampleId, numBytes);
+
+ UpdateSampleTimes(duration);
+
+ UpdateRenderingOffsets(m_writeSampleId, renderingOffset);
+
+ UpdateSyncSamples(m_writeSampleId, isSyncSample);
+
+ if ((m_isAmr == AMR_FALSE) &&
+ IsChunkFull(m_writeSampleId)) {
+ WriteChunkBuffer();
+ m_curMode = curMode;
+ }
+
+ UpdateDurations(duration);
+
+ UpdateModificationTimes();
+
+ m_writeSampleId++;
+}
+
+void MP4Track::WriteChunkBuffer()
+{
+ if (m_chunkBufferSize == 0) {
+ return;
+ }
+
+ u_int64_t chunkOffset = m_pFile->GetPosition();
+
+ // write chunk buffer
+ m_pFile->WriteBytes(m_pChunkBuffer, m_chunkBufferSize);
+
+ VERBOSE_WRITE_SAMPLE(m_pFile->GetVerbosity(),
+ printf("WriteChunk: track %u offset 0x"X64" size %u (0x%x) numSamples %u\n",
+ m_trackId, chunkOffset, m_chunkBufferSize,
+ m_chunkBufferSize, m_chunkSamples));
+
+ UpdateSampleToChunk(m_writeSampleId,
+ m_pChunkCountProperty->GetValue() + 1,
+ m_chunkSamples);
+
+ UpdateChunkOffsets(chunkOffset);
+
+ // clean up chunk buffer
+ MP4Free(m_pChunkBuffer);
+ m_pChunkBuffer = NULL;
+ m_chunkBufferSize = 0;
+ m_chunkSamples = 0;
+ m_chunkDuration = 0;
+}
+
+void MP4Track::FinishWrite()
+{
+ // write out any remaining samples in chunk buffer
+ WriteChunkBuffer();
+
+ // record buffer size and bitrates
+ MP4BitfieldProperty* pBufferSizeProperty;
+
+ if (m_pTrakAtom->FindProperty(
+ "trak.mdia.minf.stbl.stsd.*.esds.decConfigDescr.bufferSizeDB",
+ (MP4Property**)&pBufferSizeProperty)) {
+ pBufferSizeProperty->SetValue(GetMaxSampleSize());
+ }
+
+ MP4Integer32Property* pBitrateProperty;
+
+ if (m_pTrakAtom->FindProperty(
+ "trak.mdia.minf.stbl.stsd.*.esds.decConfigDescr.maxBitrate",
+ (MP4Property**)&pBitrateProperty)) {
+ pBitrateProperty->SetValue(GetMaxBitrate());
+ }
+
+ if (m_pTrakAtom->FindProperty(
+ "trak.mdia.minf.stbl.stsd.*.esds.decConfigDescr.avgBitrate",
+ (MP4Property**)&pBitrateProperty)) {
+ pBitrateProperty->SetValue(GetAvgBitrate());
+ }
+}
+
+bool MP4Track::IsChunkFull(MP4SampleId sampleId)
+{
+ if (m_samplesPerChunk) {
+ return m_chunkSamples >= m_samplesPerChunk;
+ }
+
+ ASSERT(m_durationPerChunk);
+ return m_chunkDuration >= m_durationPerChunk;
+}
+
+u_int32_t MP4Track::GetNumberOfSamples()
+{
+ return m_pStszSampleCountProperty->GetValue();
+}
+
+u_int32_t MP4Track::GetSampleSize(MP4SampleId sampleId)
+{
+ u_int32_t fixedSampleSize =
+ m_pStszFixedSampleSizeProperty->GetValue();
+
+ if (fixedSampleSize != 0) {
+ return fixedSampleSize;
+ }
+ return m_pStszSampleSizeProperty->GetValue(sampleId - 1);
+}
+
+u_int32_t MP4Track::GetMaxSampleSize()
+{
+ u_int32_t fixedSampleSize =
+ m_pStszFixedSampleSizeProperty->GetValue();
+
+ if (fixedSampleSize != 0) {
+ return fixedSampleSize;
+ }
+
+ u_int32_t maxSampleSize = 0;
+ u_int32_t numSamples = m_pStszSampleSizeProperty->GetCount();
+ for (MP4SampleId sid = 1; sid <= numSamples; sid++) {
+ u_int32_t sampleSize =
+ m_pStszSampleSizeProperty->GetValue(sid - 1);
+ if (sampleSize > maxSampleSize) {
+ maxSampleSize = sampleSize;
+ }
+ }
+ return maxSampleSize;
+}
+
+u_int64_t MP4Track::GetTotalOfSampleSizes()
+{
+ u_int32_t fixedSampleSize =
+ m_pStszFixedSampleSizeProperty->GetValue();
+
+ // if fixed sample size, just need to multiply by number of samples
+ if (fixedSampleSize != 0) {
+ return fixedSampleSize * GetNumberOfSamples();
+ }
+
+ // else non-fixed sample size, sum them
+ u_int64_t totalSampleSizes = 0;
+ u_int32_t numSamples = m_pStszSampleSizeProperty->GetCount();
+ for (MP4SampleId sid = 1; sid <= numSamples; sid++) {
+ u_int32_t sampleSize =
+ m_pStszSampleSizeProperty->GetValue(sid - 1);
+ totalSampleSizes += sampleSize;
+ }
+ return totalSampleSizes;
+}
+
+void MP4Track::UpdateSampleSizes(MP4SampleId sampleId, u_int32_t numBytes)
+{
+ // for first sample
+ if (sampleId == 1) {
+ if (numBytes > 0) {
+ // presume sample size is fixed
+ m_pStszFixedSampleSizeProperty->SetValue(numBytes);
+ } else {
+ // special case of first sample is zero bytes in length
+ // leave m_pStszFixedSampleSizeProperty at 0
+ // start recording variable sample sizes
+ m_pStszSampleSizeProperty->AddValue(0);
+ }
+
+ } else { // sampleId > 1
+ u_int32_t fixedSampleSize =
+ m_pStszFixedSampleSizeProperty->GetValue();
+
+ if (fixedSampleSize == 0 || numBytes != fixedSampleSize) {
+ // sample size is not fixed
+
+ if (fixedSampleSize) {
+ // need to clear fixed sample size
+ m_pStszFixedSampleSizeProperty->SetValue(0);
+
+ // and create sizes for all previous samples
+ for (MP4SampleId sid = 1; sid < sampleId; sid++) {
+ m_pStszSampleSizeProperty->AddValue(fixedSampleSize);
+ }
+ }
+
+ // add size value for this sample
+ m_pStszSampleSizeProperty->AddValue(numBytes);
+ }
+ }
+
+ m_pStszSampleCountProperty->IncrementValue();
+}
+
+u_int32_t MP4Track::GetAvgBitrate()
+{
+ if (GetDuration() == 0) {
+ return 0;
+ }
+
+ u_int64_t durationSecs =
+ MP4ConvertTime(GetDuration(), GetTimeScale(), MP4_SECS_TIME_SCALE);
+
+ if (GetDuration() % GetTimeScale() != 0) {
+ durationSecs++;
+ }
+
+ return (GetTotalOfSampleSizes() * 8) / durationSecs;
+}
+
+u_int32_t MP4Track::GetMaxBitrate()
+{
+ u_int32_t timeScale = GetTimeScale();
+ MP4SampleId numSamples = GetNumberOfSamples();
+ u_int32_t maxBytesPerSec = 0;
+ u_int32_t bytesThisSec = 0;
+ MP4Timestamp thisSec = 0;
+
+ for (MP4SampleId sid = 1; sid <= numSamples; sid++) {
+ u_int32_t sampleSize;
+ MP4Timestamp sampleTime;
+
+ sampleSize = GetSampleSize(sid);
+
+ GetSampleTimes(sid, &sampleTime, NULL);
+
+ // sample counts for current second
+ if (sampleTime < thisSec + timeScale) {
+ bytesThisSec += sampleSize;
+ } else { // sample is in a future second
+ if (bytesThisSec > maxBytesPerSec) {
+ maxBytesPerSec = bytesThisSec;
+ }
+
+ thisSec = sampleTime - (sampleTime % timeScale);
+ bytesThisSec = sampleSize;
+ }
+ }
+
+ // last second (or partial second)
+ if (bytesThisSec > maxBytesPerSec) {
+ maxBytesPerSec = bytesThisSec;
+ }
+
+ return maxBytesPerSec * 8;
+}
+
+u_int32_t MP4Track::GetSampleStscIndex(MP4SampleId sampleId)
+{
+ u_int32_t stscIndex;
+ u_int32_t numStscs = m_pStscCountProperty->GetValue();
+
+ if (numStscs == 0) {
+ throw new MP4Error("No data chunks exist", "GetSampleStscIndex");
+ }
+
+ for (stscIndex = 0; stscIndex < numStscs; stscIndex++) {
+ if (sampleId < m_pStscFirstSampleProperty->GetValue(stscIndex)) {
+ ASSERT(stscIndex != 0);
+ stscIndex -= 1;
+ break;
+ }
+ }
+ if (stscIndex == numStscs) {
+ ASSERT(stscIndex != 0);
+ stscIndex -= 1;
+ }
+
+ return stscIndex;
+}
+
+FILE* MP4Track::GetSampleFile(MP4SampleId sampleId)
+{
+ u_int32_t stscIndex =
+ GetSampleStscIndex(sampleId);
+
+ u_int32_t stsdIndex =
+ m_pStscSampleDescrIndexProperty->GetValue(stscIndex);
+
+ // check if the answer will be the same as last time
+ if (m_lastStsdIndex && stsdIndex == m_lastStsdIndex) {
+ return m_lastSampleFile;
+ }
+
+ MP4Atom* pStsdAtom =
+ m_pTrakAtom->FindAtom("trak.mdia.minf.stbl.stsd");
+ ASSERT(pStsdAtom);
+
+ MP4Atom* pStsdEntryAtom =
+ pStsdAtom->GetChildAtom(stsdIndex - 1);
+ ASSERT(pStsdEntryAtom);
+
+ MP4Integer16Property* pDrefIndexProperty = NULL;
+ pStsdEntryAtom->FindProperty(
+ "*.dataReferenceIndex",
+ (MP4Property**)&pDrefIndexProperty);
+
+ if (pDrefIndexProperty == NULL) {
+ throw new MP4Error("invalid stsd entry", "GetSampleFile");
+ }
+
+ u_int32_t drefIndex =
+ pDrefIndexProperty->GetValue();
+
+ MP4Atom* pDrefAtom =
+ m_pTrakAtom->FindAtom("trak.mdia.minf.dinf.dref");
+ ASSERT(pDrefAtom);
+
+ MP4Atom* pUrlAtom =
+ pDrefAtom->GetChildAtom(drefIndex - 1);
+ ASSERT(pUrlAtom);
+
+ FILE* pFile;
+
+ if (pUrlAtom->GetFlags() & 1) {
+ pFile = NULL; // self-contained
+ } else {
+ MP4StringProperty* pLocationProperty = NULL;
+ pUrlAtom->FindProperty(
+ "*.location",
+ (MP4Property**)&pLocationProperty);
+ ASSERT(pLocationProperty);
+
+ const char* url = pLocationProperty->GetValue();
+
+ VERBOSE_READ_SAMPLE(m_pFile->GetVerbosity(),
+ printf("dref url = %s\n", url));
+
+ pFile = (FILE*)-1;
+
+ // attempt to open url if it's a file url
+ // currently this is the only thing we understand
+ if (!strncmp(url, "file:", 5)) {
+ const char* fileName = url + 5;
+ if (!strncmp(fileName, "//", 2)) {
+ fileName = strchr(fileName + 2, '/');
+ }
+ if (fileName) {
+ pFile = fopen(fileName, "rb");
+ if (!pFile) {
+ pFile = (FILE*)-1;
+ }
+ }
+ }
+ }
+
+ if (m_lastSampleFile) {
+ fclose(m_lastSampleFile);
+ }
+
+ // cache the answer
+ m_lastStsdIndex = stsdIndex;
+ m_lastSampleFile = pFile;
+
+ return pFile;
+}
+
+u_int64_t MP4Track::GetSampleFileOffset(MP4SampleId sampleId)
+{
+ u_int32_t stscIndex =
+ GetSampleStscIndex(sampleId);
+
+ u_int32_t firstChunk =
+ m_pStscFirstChunkProperty->GetValue(stscIndex);
+
+ MP4SampleId firstSample =
+ m_pStscFirstSampleProperty->GetValue(stscIndex);
+
+ u_int32_t samplesPerChunk =
+ m_pStscSamplesPerChunkProperty->GetValue(stscIndex);
+
+ MP4ChunkId chunkId = firstChunk +
+ ((sampleId - firstSample) / samplesPerChunk);
+
+ u_int64_t chunkOffset = m_pChunkOffsetProperty->GetValue(chunkId - 1);
+
+ MP4SampleId firstSampleInChunk =
+ sampleId - ((sampleId - firstSample) % samplesPerChunk);
+
+ // need cumulative samples sizes from firstSample to sampleId - 1
+ u_int32_t sampleOffset = 0;
+ for (MP4SampleId i = firstSampleInChunk; i < sampleId; i++) {
+ sampleOffset += GetSampleSize(i);
+ }
+
+ return chunkOffset + sampleOffset;
+}
+
+void MP4Track::UpdateSampleToChunk(MP4SampleId sampleId,
+ MP4ChunkId chunkId, u_int32_t samplesPerChunk)
+{
+ u_int32_t numStsc = m_pStscCountProperty->GetValue();
+
+ // if samplesPerChunk == samplesPerChunk of last entry
+ if (numStsc && samplesPerChunk ==
+ m_pStscSamplesPerChunkProperty->GetValue(numStsc-1)) {
+
+ // nothing to do
+
+ } else {
+ // add stsc entry
+ m_pStscFirstChunkProperty->AddValue(chunkId);
+ m_pStscSamplesPerChunkProperty->AddValue(samplesPerChunk);
+ m_pStscSampleDescrIndexProperty->AddValue(1);
+ m_pStscFirstSampleProperty->AddValue(sampleId - samplesPerChunk + 1);
+
+ m_pStscCountProperty->IncrementValue();
+ }
+}
+
+void MP4Track::UpdateChunkOffsets(u_int64_t chunkOffset)
+{
+ if (m_pChunkOffsetProperty->GetType() == Integer32Property) {
+ ((MP4Integer32Property*)m_pChunkOffsetProperty)->AddValue(chunkOffset);
+ } else {
+ ((MP4Integer64Property*)m_pChunkOffsetProperty)->AddValue(chunkOffset);
+ }
+ m_pChunkCountProperty->IncrementValue();
+}
+
+MP4Duration MP4Track::GetFixedSampleDuration()
+{
+ u_int32_t numStts = m_pSttsCountProperty->GetValue();
+
+ if (numStts == 0) {
+ return m_fixedSampleDuration;
+ }
+ if (numStts != 1) {
+ return MP4_INVALID_DURATION; // sample duration is not fixed
+ }
+ return m_pSttsSampleDeltaProperty->GetValue(0);
+}
+
+bool MP4Track::SetFixedSampleDuration(MP4Duration duration)
+{
+ u_int32_t numStts = m_pSttsCountProperty->GetValue();
+
+ // setting this is only allowed before samples have been written
+ if (numStts != 0) {
+ return false;
+ }
+ m_fixedSampleDuration = duration;
+ return true;
+}
+
+void MP4Track::GetSampleTimes(MP4SampleId sampleId,
+ MP4Timestamp* pStartTime, MP4Duration* pDuration)
+{
+ u_int32_t numStts = m_pSttsCountProperty->GetValue();
+ MP4SampleId sid = 1;
+ MP4Duration elapsed = 0;
+
+ for (u_int32_t sttsIndex = 0; sttsIndex < numStts; sttsIndex++) {
+ u_int32_t sampleCount =
+ m_pSttsSampleCountProperty->GetValue(sttsIndex);
+ u_int32_t sampleDelta =
+ m_pSttsSampleDeltaProperty->GetValue(sttsIndex);
+
+ if (sampleId <= sid + sampleCount - 1) {
+ if (pStartTime) {
+ *pStartTime = (sampleId - sid);
+ *pStartTime *= sampleDelta;
+ *pStartTime += elapsed;
+ }
+ if (pDuration) {
+ *pDuration = sampleDelta;
+ }
+ return;
+ }
+ sid += sampleCount;
+ elapsed += sampleCount * sampleDelta;
+ }
+
+ throw new MP4Error("sample id out of range",
+ "MP4Track::GetSampleTimes");
+}
+
+MP4SampleId MP4Track::GetSampleIdFromTime(
+ MP4Timestamp when,
+ bool wantSyncSample)
+{
+ u_int32_t numStts = m_pSttsCountProperty->GetValue();
+ MP4SampleId sid = 1;
+ MP4Duration elapsed = 0;
+
+ for (u_int32_t sttsIndex = 0; sttsIndex < numStts; sttsIndex++) {
+ u_int32_t sampleCount =
+ m_pSttsSampleCountProperty->GetValue(sttsIndex);
+ u_int32_t sampleDelta =
+ m_pSttsSampleDeltaProperty->GetValue(sttsIndex);
+
+ if (sampleDelta == 0 && sttsIndex < numStts - 1) {
+ VERBOSE_READ(m_pFile->GetVerbosity(),
+ printf("Warning: Zero sample duration, stts entry %u\n",
+ sttsIndex));
+ }
+
+ MP4Duration d = when - elapsed;
+
+ if (d <= sampleCount * sampleDelta) {
+ MP4SampleId sampleId = sid;
+ if (sampleDelta) {
+ sampleId += (d / sampleDelta);
+ }
+
+ if (wantSyncSample) {
+ return GetNextSyncSample(sampleId);
+ }
+ return sampleId;
+ }
+
+ sid += sampleCount;
+ elapsed += sampleCount * sampleDelta;
+ }
+
+ throw new MP4Error("time out of range",
+ "MP4Track::GetSampleIdFromTime");
+
+ return 0; // satisfy MS compiler
+}
+
+void MP4Track::UpdateSampleTimes(MP4Duration duration)
+{
+ u_int32_t numStts = m_pSttsCountProperty->GetValue();
+
+ // if duration == duration of last entry
+ if (numStts
+ && duration == m_pSttsSampleDeltaProperty->GetValue(numStts-1)) {
+ // increment last entry sampleCount
+ m_pSttsSampleCountProperty->IncrementValue(1, numStts-1);
+
+ } else {
+ // add stts entry, sampleCount = 1, sampleDuration = duration
+ m_pSttsSampleCountProperty->AddValue(1);
+ m_pSttsSampleDeltaProperty->AddValue(duration);
+ m_pSttsCountProperty->IncrementValue();;
+ }
+}
+
+u_int32_t MP4Track::GetSampleCttsIndex(MP4SampleId sampleId,
+ MP4SampleId* pFirstSampleId)
+{
+ u_int32_t numCtts = m_pCttsCountProperty->GetValue();
+
+ MP4SampleId sid = 1;
+
+ for (u_int32_t cttsIndex = 0; cttsIndex < numCtts; cttsIndex++) {
+ u_int32_t sampleCount =
+ m_pCttsSampleCountProperty->GetValue(cttsIndex);
+
+ if (sampleId <= sid + sampleCount - 1) {
+ if (pFirstSampleId) {
+ *pFirstSampleId = sid;
+ }
+ return cttsIndex;
+ }
+ sid += sampleCount;
+ }
+
+ throw new MP4Error("sample id out of range",
+ "MP4Track::GetSampleCttsIndex");
+ return 0; // satisfy MS compiler
+}
+
+MP4Duration MP4Track::GetSampleRenderingOffset(MP4SampleId sampleId)
+{
+ if (m_pCttsCountProperty == NULL) {
+ return 0;
+ }
+ if (m_pCttsCountProperty->GetValue() == 0) {
+ return 0;
+ }
+
+ u_int32_t cttsIndex = GetSampleCttsIndex(sampleId);
+
+ return m_pCttsSampleOffsetProperty->GetValue(cttsIndex);
+}
+
+void MP4Track::UpdateRenderingOffsets(MP4SampleId sampleId,
+ MP4Duration renderingOffset)
+{
+ // if ctts atom doesn't exist
+ if (m_pCttsCountProperty == NULL) {
+
+ // no rendering offset, so nothing to do
+ if (renderingOffset == 0) {
+ return;
+ }
+
+ // else create a ctts atom
+ MP4Atom* pCttsAtom = AddAtom("trak.mdia.minf.stbl", "ctts");
+
+ // and get handles on the properties
+ pCttsAtom->FindProperty(
+ "ctts.entryCount",
+ (MP4Property**)&m_pCttsCountProperty);
+
+ pCttsAtom->FindProperty(
+ "ctts.entries.sampleCount",
+ (MP4Property**)&m_pCttsSampleCountProperty);
+
+ pCttsAtom->FindProperty(
+ "ctts.entries.sampleOffset",
+ (MP4Property**)&m_pCttsSampleOffsetProperty);
+
+ // if this is not the first sample
+ if (sampleId > 1) {
+ // add a ctts entry for all previous samples
+ // with rendering offset equal to zero
+ m_pCttsSampleCountProperty->AddValue(sampleId - 1);
+ m_pCttsSampleOffsetProperty->AddValue(0);
+ m_pCttsCountProperty->IncrementValue();;
+ }
+ }
+
+ // ctts atom exists (now)
+
+ u_int32_t numCtts = m_pCttsCountProperty->GetValue();
+
+ // if renderingOffset == renderingOffset of last entry
+ if (numCtts && renderingOffset
+ == m_pCttsSampleOffsetProperty->GetValue(numCtts-1)) {
+
+ // increment last entry sampleCount
+ m_pCttsSampleCountProperty->IncrementValue(1, numCtts-1);
+
+ } else {
+ // add ctts entry, sampleCount = 1, sampleOffset = renderingOffset
+ m_pCttsSampleCountProperty->AddValue(1);
+ m_pCttsSampleOffsetProperty->AddValue(renderingOffset);
+ m_pCttsCountProperty->IncrementValue();
+ }
+}
+
+void MP4Track::SetSampleRenderingOffset(MP4SampleId sampleId,
+ MP4Duration renderingOffset)
+{
+ // check if any ctts entries exist
+ if (m_pCttsCountProperty == NULL
+ || m_pCttsCountProperty->GetValue() == 0) {
+ // if not then Update routine can be used
+ // to create a ctts entry for samples before this one
+ // and a ctts entry for this sample
+ UpdateRenderingOffsets(sampleId, renderingOffset);
+
+ // but we also need a ctts entry
+ // for all samples after this one
+ u_int32_t afterSamples = GetNumberOfSamples() - sampleId;
+
+ if (afterSamples) {
+ m_pCttsSampleCountProperty->AddValue(afterSamples);
+ m_pCttsSampleOffsetProperty->AddValue(0);
+ m_pCttsCountProperty->IncrementValue();;
+ }
+
+ return;
+ }
+
+ MP4SampleId firstSampleId;
+ u_int32_t cttsIndex = GetSampleCttsIndex(sampleId, &firstSampleId);
+
+ // do nothing in the degenerate case
+ if (renderingOffset ==
+ m_pCttsSampleOffsetProperty->GetValue(cttsIndex)) {
+ return;
+ }
+
+ u_int32_t sampleCount =
+ m_pCttsSampleCountProperty->GetValue(cttsIndex);
+
+ // if this sample has it's own ctts entry
+ if (sampleCount == 1) {
+ // then just set the value,
+ // note we don't attempt to collapse entries
+ m_pCttsSampleOffsetProperty->SetValue(renderingOffset, cttsIndex);
+ return;
+ }
+
+ MP4SampleId lastSampleId = firstSampleId + sampleCount - 1;
+
+ // else we share this entry with other samples
+ // we need to insert our own entry
+ if (sampleId == firstSampleId) {
+ // our sample is the first one
+ m_pCttsSampleCountProperty->
+ InsertValue(1, cttsIndex);
+ m_pCttsSampleOffsetProperty->
+ InsertValue(renderingOffset, cttsIndex);
+
+ m_pCttsSampleCountProperty->
+ SetValue(sampleCount - 1, cttsIndex + 1);
+
+ m_pCttsCountProperty->IncrementValue();
+
+ } else if (sampleId == lastSampleId) {
+ // our sample is the last one
+ m_pCttsSampleCountProperty->
+ InsertValue(1, cttsIndex + 1);
+ m_pCttsSampleOffsetProperty->
+ InsertValue(renderingOffset, cttsIndex + 1);
+
+ m_pCttsSampleCountProperty->
+ SetValue(sampleCount - 1, cttsIndex);
+
+ m_pCttsCountProperty->IncrementValue();
+
+ } else {
+ // our sample is in the middle, UGH!
+
+ // insert our new entry
+ m_pCttsSampleCountProperty->
+ InsertValue(1, cttsIndex + 1);
+ m_pCttsSampleOffsetProperty->
+ InsertValue(renderingOffset, cttsIndex + 1);
+
+ // adjust count of previous entry
+ m_pCttsSampleCountProperty->
+ SetValue(sampleId - firstSampleId, cttsIndex);
+
+ // insert new entry for those samples beyond our sample
+ m_pCttsSampleCountProperty->
+ InsertValue(lastSampleId - sampleId, cttsIndex + 2);
+ u_int32_t oldRenderingOffset =
+ m_pCttsSampleOffsetProperty->GetValue(cttsIndex);
+ m_pCttsSampleOffsetProperty->
+ InsertValue(oldRenderingOffset, cttsIndex + 2);
+
+ m_pCttsCountProperty->IncrementValue(2);
+ }
+}
+
+bool MP4Track::IsSyncSample(MP4SampleId sampleId)
+{
+ if (m_pStssCountProperty == NULL) {
+ return true;
+ }
+
+ u_int32_t numStss = m_pStssCountProperty->GetValue();
+
+ for (u_int32_t stssIndex = 0; stssIndex < numStss; stssIndex++) {
+ MP4SampleId syncSampleId =
+ m_pStssSampleProperty->GetValue(stssIndex);
+
+ if (sampleId == syncSampleId) {
+ return true;
+ }
+ if (sampleId < syncSampleId) {
+ break;
+ }
+ }
+
+ return false;
+}
+
+// N.B. "next" is inclusive of this sample id
+MP4SampleId MP4Track::GetNextSyncSample(MP4SampleId sampleId)
+{
+ if (m_pStssCountProperty == NULL) {
+ return sampleId;
+ }
+
+ u_int32_t numStss = m_pStssCountProperty->GetValue();
+
+ for (u_int32_t stssIndex = 0; stssIndex < numStss; stssIndex++) {
+ MP4SampleId syncSampleId =
+ m_pStssSampleProperty->GetValue(stssIndex);
+
+ if (sampleId > syncSampleId) {
+ continue;
+ }
+ return syncSampleId;
+ }
+
+ // LATER check stsh for alternate sample
+
+ return MP4_INVALID_SAMPLE_ID;
+}
+
+void MP4Track::UpdateSyncSamples(MP4SampleId sampleId, bool isSyncSample)
+{
+ if (isSyncSample) {
+ // if stss atom exists, add entry
+ if (m_pStssCountProperty) {
+ m_pStssSampleProperty->AddValue(sampleId);
+ m_pStssCountProperty->IncrementValue();
+ } // else nothing to do (yet)
+
+ } else { // !isSyncSample
+ // if stss atom doesn't exist, create one
+ if (m_pStssCountProperty == NULL) {
+
+ MP4Atom* pStssAtom = AddAtom("trak.mdia.minf.stbl", "stss");
+
+ pStssAtom->FindProperty(
+ "stss.entryCount",
+ (MP4Property**)&m_pStssCountProperty);
+
+ pStssAtom->FindProperty(
+ "stss.entries.sampleNumber",
+ (MP4Property**)&m_pStssSampleProperty);
+
+ // set values for all samples that came before this one
+ for (MP4SampleId sid = 1; sid < sampleId; sid++) {
+ m_pStssSampleProperty->AddValue(sid);
+ m_pStssCountProperty->IncrementValue();
+ }
+ } // else nothing to do
+ }
+}
+
+MP4Atom* MP4Track::AddAtom(char* parentName, char* childName)
+{
+ MP4Atom* pChildAtom = MP4Atom::CreateAtom(childName);
+
+ MP4Atom* pParentAtom = m_pTrakAtom->FindAtom(parentName);
+ ASSERT(pParentAtom);
+
+ pParentAtom->AddChildAtom(pChildAtom);
+
+ pChildAtom->Generate();
+
+ return pChildAtom;
+}
+
+u_int64_t MP4Track::GetDuration()
+{
+ return m_pMediaDurationProperty->GetValue();
+}
+
+u_int32_t MP4Track::GetTimeScale()
+{
+ return m_pTimeScaleProperty->GetValue();
+}
+
+void MP4Track::UpdateDurations(MP4Duration duration)
+{
+ // update media, track, and movie durations
+ m_pMediaDurationProperty->SetValue(
+ m_pMediaDurationProperty->GetValue() + duration);
+
+ MP4Duration movieDuration = ToMovieDuration(duration);
+ m_pTrackDurationProperty->SetValue(
+ m_pTrackDurationProperty->GetValue() + movieDuration);
+
+ m_pFile->UpdateDuration(m_pTrackDurationProperty->GetValue());
+}
+
+MP4Duration MP4Track::ToMovieDuration(MP4Duration trackDuration)
+{
+ return (trackDuration * m_pFile->GetTimeScale())
+ / m_pTimeScaleProperty->GetValue();
+}
+
+void MP4Track::UpdateModificationTimes()
+{
+ // update media and track modification times
+ MP4Timestamp now = MP4GetAbsTimestamp();
+ m_pMediaModificationProperty->SetValue(now);
+ m_pTrackModificationProperty->SetValue(now);
+}
+
+u_int32_t MP4Track::GetNumberOfChunks()
+{
+ return m_pChunkOffsetProperty->GetCount();
+}
+
+u_int32_t MP4Track::GetChunkStscIndex(MP4ChunkId chunkId)
+{
+ u_int32_t stscIndex;
+ u_int32_t numStscs = m_pStscCountProperty->GetValue();
+
+ ASSERT(chunkId);
+ ASSERT(numStscs > 0);
+
+ for (stscIndex = 0; stscIndex < numStscs; stscIndex++) {
+ if (chunkId < m_pStscFirstChunkProperty->GetValue(stscIndex)) {
+ ASSERT(stscIndex != 0);
+ break;
+ }
+ }
+ return stscIndex - 1;
+}
+
+MP4Timestamp MP4Track::GetChunkTime(MP4ChunkId chunkId)
+{
+ u_int32_t stscIndex = GetChunkStscIndex(chunkId);
+
+ MP4ChunkId firstChunkId =
+ m_pStscFirstChunkProperty->GetValue(stscIndex);
+
+ MP4SampleId firstSample =
+ m_pStscFirstSampleProperty->GetValue(stscIndex);
+
+ u_int32_t samplesPerChunk =
+ m_pStscSamplesPerChunkProperty->GetValue(stscIndex);
+
+ MP4SampleId firstSampleInChunk =
+ firstSample + ((chunkId - firstChunkId) * samplesPerChunk);
+
+ MP4Timestamp chunkTime;
+
+ GetSampleTimes(firstSampleInChunk, &chunkTime, NULL);
+
+ return chunkTime;
+}
+
+u_int32_t MP4Track::GetChunkSize(MP4ChunkId chunkId)
+{
+ u_int32_t stscIndex = GetChunkStscIndex(chunkId);
+
+ MP4ChunkId firstChunkId =
+ m_pStscFirstChunkProperty->GetValue(stscIndex);
+
+ MP4SampleId firstSample =
+ m_pStscFirstSampleProperty->GetValue(stscIndex);
+
+ u_int32_t samplesPerChunk =
+ m_pStscSamplesPerChunkProperty->GetValue(stscIndex);
+
+ MP4SampleId firstSampleInChunk =
+ firstSample + ((chunkId - firstChunkId) * samplesPerChunk);
+
+ // need cumulative sizes of samples in chunk
+ u_int32_t chunkSize = 0;
+ for (u_int32_t i = 0; i < samplesPerChunk; i++) {
+ chunkSize += GetSampleSize(firstSampleInChunk + i);
+ }
+
+ return chunkSize;
+}
+
+void MP4Track::ReadChunk(MP4ChunkId chunkId,
+ u_int8_t** ppChunk, u_int32_t* pChunkSize)
+{
+ ASSERT(chunkId);
+ ASSERT(ppChunk);
+ ASSERT(pChunkSize);
+
+ u_int64_t chunkOffset =
+ m_pChunkOffsetProperty->GetValue(chunkId - 1);
+
+ *pChunkSize = GetChunkSize(chunkId);
+ *ppChunk = (u_int8_t*)MP4Malloc(*pChunkSize);
+
+ VERBOSE_READ_SAMPLE(m_pFile->GetVerbosity(),
+ printf("ReadChunk: track %u id %u offset 0x"X64" size %u (0x%x)\n",
+ m_trackId, chunkId, chunkOffset, *pChunkSize, *pChunkSize));
+
+ u_int64_t oldPos = m_pFile->GetPosition(); // only used in mode == 'w'
+ try {
+ m_pFile->SetPosition(chunkOffset);
+ m_pFile->ReadBytes(*ppChunk, *pChunkSize);
+ }
+ catch (MP4Error* e) {
+ // let's not leak memory
+ MP4Free(*ppChunk);
+ *ppChunk = NULL;
+
+ if (m_pFile->GetMode() == 'w') {
+ m_pFile->SetPosition(oldPos);
+ }
+ throw e;
+ }
+
+ if (m_pFile->GetMode() == 'w') {
+ m_pFile->SetPosition(oldPos);
+ }
+}
+
+void MP4Track::RewriteChunk(MP4ChunkId chunkId,
+ u_int8_t* pChunk, u_int32_t chunkSize)
+{
+ u_int64_t chunkOffset = m_pFile->GetPosition();
+
+ m_pFile->WriteBytes(pChunk, chunkSize);
+
+ m_pChunkOffsetProperty->SetValue(chunkOffset, chunkId - 1);
+
+ VERBOSE_WRITE_SAMPLE(m_pFile->GetVerbosity(),
+ printf("RewriteChunk: track %u id %u offset 0x"X64" size %u (0x%x)\n",
+ m_trackId, chunkId, chunkOffset, chunkSize, chunkSize));
+}
+
+// map track type name aliases to official names
+
+const char* MP4Track::NormalizeTrackType(const char* type)
+{
+ if (!strcasecmp(type, "vide")
+ || !strcasecmp(type, "video")
+ || !strcasecmp(type, "mp4v")
+ || !strcasecmp(type, "s263") // 3GPP H.263
+ || !strcasecmp(type, "encv")) {
+ return MP4_VIDEO_TRACK_TYPE;
+ }
+
+ if (!strcasecmp(type, "soun")
+ || !strcasecmp(type, "sound")
+ || !strcasecmp(type, "audio")
+ || !strcasecmp(type, "enca")
+ || !strcasecmp(type, "samr") // 3GPP AMR
+ || !strcasecmp(type, "sawb") // 3GPP AMR/WB
+ || !strcasecmp(type, "mp4a")) {
+ return MP4_AUDIO_TRACK_TYPE;
+ }
+
+ if (!strcasecmp(type, "sdsm")
+ || !strcasecmp(type, "scene")
+ || !strcasecmp(type, "bifs")) {
+ return MP4_SCENE_TRACK_TYPE;
+ }
+
+ if (!strcasecmp(type, "odsm")
+ || !strcasecmp(type, "od")) {
+ return MP4_OD_TRACK_TYPE;
+ }
+
+ return type;
+}
+
+bool MP4Track::InitEditListProperties()
+{
+ m_pElstCountProperty = NULL;
+ m_pElstMediaTimeProperty = NULL;
+ m_pElstDurationProperty = NULL;
+ m_pElstRateProperty = NULL;
+ m_pElstReservedProperty = NULL;
+
+ MP4Atom* pElstAtom =
+ m_pTrakAtom->FindAtom("trak.edts.elst");
+
+ if (!pElstAtom) {
+ return false;
+ }
+
+ pElstAtom->FindProperty(
+ "elst.entryCount",
+ (MP4Property**)&m_pElstCountProperty);
+
+ pElstAtom->FindProperty(
+ "elst.entries.mediaTime",
+ (MP4Property**)&m_pElstMediaTimeProperty);
+
+ pElstAtom->FindProperty(
+ "elst.entries.segmentDuration",
+ (MP4Property**)&m_pElstDurationProperty);
+
+ pElstAtom->FindProperty(
+ "elst.entries.mediaRate",
+ (MP4Property**)&m_pElstRateProperty);
+
+ pElstAtom->FindProperty(
+ "elst.entries.reserved",
+ (MP4Property**)&m_pElstReservedProperty);
+
+ return m_pElstCountProperty
+ && m_pElstMediaTimeProperty
+ && m_pElstDurationProperty
+ && m_pElstRateProperty
+ && m_pElstReservedProperty;
+}
+
+MP4EditId MP4Track::AddEdit(MP4EditId editId)
+{
+ if (!m_pElstCountProperty) {
+ m_pFile->AddDescendantAtoms(m_pTrakAtom, "edts.elst");
+ InitEditListProperties();
+ }
+
+ if (editId == MP4_INVALID_EDIT_ID) {
+ editId = m_pElstCountProperty->GetValue() + 1;
+ }
+
+ m_pElstMediaTimeProperty->InsertValue(0, editId - 1);
+ m_pElstDurationProperty->InsertValue(0, editId - 1);
+ m_pElstRateProperty->InsertValue(1, editId - 1);
+ m_pElstReservedProperty->InsertValue(0, editId - 1);
+
+ m_pElstCountProperty->IncrementValue();
+
+ return editId;
+}
+
+void MP4Track::DeleteEdit(MP4EditId editId)
+{
+ if (editId == MP4_INVALID_EDIT_ID) {
+ throw new MP4Error("edit id can't be zero",
+ "MP4Track::DeleteEdit");
+ }
+
+ if (!m_pElstCountProperty
+ || m_pElstCountProperty->GetValue() == 0) {
+ throw new MP4Error("no edits exist",
+ "MP4Track::DeleteEdit");
+ }
+
+ m_pElstMediaTimeProperty->DeleteValue(editId - 1);
+ m_pElstDurationProperty->DeleteValue(editId - 1);
+ m_pElstRateProperty->DeleteValue(editId - 1);
+ m_pElstReservedProperty->DeleteValue(editId - 1);
+
+ m_pElstCountProperty->IncrementValue(-1);
+
+ // clean up if last edit is deleted
+ if (m_pElstCountProperty->GetValue() == 0) {
+ m_pElstCountProperty = NULL;
+ m_pElstMediaTimeProperty = NULL;
+ m_pElstDurationProperty = NULL;
+ m_pElstRateProperty = NULL;
+ m_pElstReservedProperty = NULL;
+
+ m_pTrakAtom->DeleteChildAtom(
+ m_pTrakAtom->FindAtom("trak.edts"));
+ }
+}
+
+MP4Timestamp MP4Track::GetEditStart(
+ MP4EditId editId)
+{
+ if (editId == MP4_INVALID_EDIT_ID) {
+ return MP4_INVALID_TIMESTAMP;
+ } else if (editId == 1) {
+ return 0;
+ }
+ return (MP4Timestamp)GetEditTotalDuration(editId - 1);
+}
+
+MP4Duration MP4Track::GetEditTotalDuration(
+ MP4EditId editId)
+{
+ u_int32_t numEdits = 0;
+
+ if (m_pElstCountProperty) {
+ numEdits = m_pElstCountProperty->GetValue();
+ }
+
+ if (editId == MP4_INVALID_EDIT_ID) {
+ editId = numEdits;
+ }
+
+ if (numEdits == 0 || editId > numEdits) {
+ return MP4_INVALID_DURATION;
+ }
+
+ MP4Duration totalDuration = 0;
+
+ for (MP4EditId eid = 1; eid <= editId; eid++) {
+ totalDuration +=
+ m_pElstDurationProperty->GetValue(eid - 1);
+ }
+
+ return totalDuration;
+}
+
+MP4SampleId MP4Track::GetSampleIdFromEditTime(
+ MP4Timestamp editWhen,
+ MP4Timestamp* pStartTime,
+ MP4Duration* pDuration)
+{
+ MP4SampleId sampleId = MP4_INVALID_SAMPLE_ID;
+ u_int32_t numEdits = 0;
+
+ if (m_pElstCountProperty) {
+ numEdits = m_pElstCountProperty->GetValue();
+ }
+
+ if (numEdits) {
+ MP4Duration editElapsedDuration = 0;
+
+ for (MP4EditId editId = 1; editId <= numEdits; editId++) {
+ // remember edit segment's start time (in edit timeline)
+ MP4Timestamp editStartTime =
+ (MP4Timestamp)editElapsedDuration;
+
+ // accumulate edit segment's duration
+ editElapsedDuration +=
+ m_pElstDurationProperty->GetValue(editId - 1);
+
+ // calculate difference between the specified edit time
+ // and the end of this edit segment
+ if (editElapsedDuration - editWhen <= 0) {
+ // the specified time has not yet been reached
+ continue;
+ }
+
+ // 'editWhen' is within this edit segment
+
+ // calculate the specified edit time
+ // relative to just this edit segment
+ MP4Duration editOffset =
+ editWhen - editStartTime;
+
+ // calculate the media (track) time that corresponds
+ // to the specified edit time based on the edit list
+ MP4Timestamp mediaWhen =
+ m_pElstMediaTimeProperty->GetValue(editId - 1)
+ + editOffset;
+
+ // lookup the sample id for the media time
+ sampleId = GetSampleIdFromTime(mediaWhen, false);
+
+ // lookup the sample's media start time and duration
+ MP4Timestamp sampleStartTime;
+ MP4Duration sampleDuration;
+
+ GetSampleTimes(sampleId, &sampleStartTime, &sampleDuration);
+
+ // calculate the difference if any between when the sample
+ // would naturally start and when it starts in the edit timeline
+ MP4Duration sampleStartOffset =
+ mediaWhen - sampleStartTime;
+
+ // calculate the start time for the sample in the edit time line
+ MP4Timestamp editSampleStartTime =
+ editWhen - MIN(editOffset, sampleStartOffset);
+
+ MP4Duration editSampleDuration = 0;
+
+ // calculate how long this sample lasts in the edit list timeline
+ if (m_pElstRateProperty->GetValue(editId - 1) == 0) {
+ // edit segment is a "dwell"
+ // so sample duration is that of the edit segment
+ editSampleDuration =
+ m_pElstDurationProperty->GetValue(editId - 1);
+
+ } else {
+ // begin with the natural sample duration
+ editSampleDuration = sampleDuration;
+
+ // now shorten that if the edit segment starts
+ // after the sample would naturally start
+ if (editOffset < sampleStartOffset) {
+ editSampleDuration -= sampleStartOffset - editOffset;
+ }
+
+ // now shorten that if the edit segment ends
+ // before the sample would naturally end
+ if (editElapsedDuration
+ < editSampleStartTime + sampleDuration) {
+ editSampleDuration -= (editSampleStartTime + sampleDuration)
+ - editElapsedDuration;
+ }
+ }
+
+ if (pStartTime) {
+ *pStartTime = editSampleStartTime;
+ }
+
+ if (pDuration) {
+ *pDuration = editSampleDuration;
+ }
+
+ VERBOSE_EDIT(m_pFile->GetVerbosity(),
+ printf("GetSampleIdFromEditTime: when "U64" "
+ "sampleId %u start "U64" duration "D64"\n",
+ editWhen, sampleId,
+ editSampleStartTime, editSampleDuration));
+
+ return sampleId;
+ }
+
+ throw new MP4Error("time out of range",
+ "MP4Track::GetSampleIdFromEditTime");
+
+ } else { // no edit list
+ sampleId = GetSampleIdFromTime(editWhen, false);
+
+ if (pStartTime || pDuration) {
+ GetSampleTimes(sampleId, pStartTime, pDuration);
+ }
+ }
+
+ return sampleId;
+}
+
--- /dev/null
+++ b/common/mp4v2/mp4track.h
@@ -1,0 +1,251 @@
+/*
+ * 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 - 2004. All Rights Reserved.
+ *
+ * 3GPP features implementation is based on 3GPP's TS26.234-v5.60,
+ * and was contributed by Ximpo Group Ltd.
+ *
+ * Portions created by Ximpo Group Ltd. are
+ * Copyright (C) Ximpo Group Ltd. 2003, 2004. All Rights Reserved.
+ *
+ * Contributor(s):
+ * Dave Mackie dmackie@cisco.com
+ * Ximpo Group Ltd. mp4v2@ximpo.com
+ */
+
+#ifndef __MP4_TRACK_INCLUDED__
+#define __MP4_TRACK_INCLUDED__
+
+typedef u_int32_t MP4ChunkId;
+
+// forward declarations
+class MP4File;
+class MP4Atom;
+class MP4Property;
+class MP4IntegerProperty;
+class MP4Integer16Property;
+class MP4Integer32Property;
+class MP4Integer64Property;
+class MP4StringProperty;
+
+class MP4Track {
+public:
+ MP4Track(MP4File* pFile, MP4Atom* pTrakAtom);
+
+ virtual ~MP4Track();
+
+ MP4TrackId GetId() {
+ return m_trackId;
+ }
+
+ const char* GetType();
+
+ void SetType(const char* type);
+
+ MP4File* GetFile() {
+ return m_pFile;
+ }
+
+ MP4Atom* GetTrakAtom() {
+ return m_pTrakAtom;
+ }
+
+ void ReadSample(
+ // input parameters
+ 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(
+ const u_int8_t* pBytes,
+ u_int32_t numBytes,
+ MP4Duration duration = 0,
+ MP4Duration renderingOffset = 0,
+ bool isSyncSample = true);
+
+ virtual void FinishWrite();
+
+ u_int64_t GetDuration(); // in track timeScale units
+ u_int32_t GetTimeScale();
+ u_int32_t GetNumberOfSamples();
+ u_int32_t GetSampleSize(MP4SampleId sampleId);
+ u_int32_t GetMaxSampleSize();
+ u_int64_t GetTotalOfSampleSizes();
+ u_int32_t GetAvgBitrate(); // in bps
+ u_int32_t GetMaxBitrate(); // in bps
+
+ MP4Duration GetFixedSampleDuration();
+ bool SetFixedSampleDuration(MP4Duration duration);
+
+ void GetSampleTimes(MP4SampleId sampleId,
+ MP4Timestamp* pStartTime, MP4Duration* pDuration);
+
+ bool IsSyncSample(MP4SampleId sampleId);
+
+ MP4SampleId GetSampleIdFromTime(
+ MP4Timestamp when,
+ bool wantSyncSample = false);
+
+ MP4Duration GetSampleRenderingOffset(MP4SampleId sampleId);
+ void SetSampleRenderingOffset(MP4SampleId sampleId,
+ MP4Duration renderingOffset);
+
+ MP4EditId AddEdit(
+ MP4EditId editId = MP4_INVALID_EDIT_ID);
+
+ void DeleteEdit(
+ MP4EditId editId);
+
+ MP4Timestamp GetEditStart(
+ MP4EditId editId);
+
+ MP4Timestamp GetEditTotalDuration(
+ MP4EditId editId);
+
+ MP4SampleId GetSampleIdFromEditTime(
+ MP4Timestamp editWhen,
+ MP4Timestamp* pStartTime = NULL,
+ MP4Duration* pDuration = NULL);
+
+ static const char* NormalizeTrackType(const char* type);
+
+ // special operation for use during hint track packet assembly
+ void ReadSampleFragment(
+ MP4SampleId sampleId,
+ u_int32_t sampleOffset,
+ u_int16_t sampleLength,
+ u_int8_t* pDest);
+
+ // special operations for use during optimization
+
+ u_int32_t GetNumberOfChunks();
+
+ MP4Timestamp GetChunkTime(MP4ChunkId chunkId);
+
+ void ReadChunk(MP4ChunkId chunkId,
+ u_int8_t** ppChunk, u_int32_t* pChunkSize);
+
+ void RewriteChunk(MP4ChunkId chunkId,
+ u_int8_t* pChunk, u_int32_t chunkSize);
+
+protected:
+ bool InitEditListProperties();
+
+ FILE* GetSampleFile(MP4SampleId sampleId);
+ u_int64_t GetSampleFileOffset(MP4SampleId sampleId);
+ u_int32_t GetSampleStscIndex(MP4SampleId sampleId);
+ u_int32_t GetChunkStscIndex(MP4ChunkId chunkId);
+ u_int32_t GetChunkSize(MP4ChunkId chunkId);
+ u_int32_t GetSampleCttsIndex(MP4SampleId sampleId,
+ MP4SampleId* pFirstSampleId = NULL);
+ MP4SampleId GetNextSyncSample(MP4SampleId sampleId);
+
+ void UpdateSampleSizes(MP4SampleId sampleId,
+ u_int32_t numBytes);
+ bool IsChunkFull(MP4SampleId sampleId);
+ void UpdateSampleToChunk(MP4SampleId sampleId,
+ MP4ChunkId chunkId, u_int32_t samplesPerChunk);
+ void UpdateChunkOffsets(u_int64_t chunkOffset);
+ void UpdateSampleTimes(MP4Duration duration);
+ void UpdateRenderingOffsets(MP4SampleId sampleId,
+ MP4Duration renderingOffset);
+ void UpdateSyncSamples(MP4SampleId sampleId,
+ bool isSyncSample);
+
+ MP4Atom* AddAtom(char* parentName, char* childName);
+
+ void UpdateDurations(MP4Duration duration);
+ MP4Duration ToMovieDuration(MP4Duration trackDuration);
+
+ void UpdateModificationTimes();
+
+ void WriteChunkBuffer();
+
+protected:
+ MP4File* m_pFile;
+ MP4Atom* m_pTrakAtom; // moov.trak[]
+ MP4TrackId m_trackId; // moov.trak[].tkhd.trackId
+ MP4StringProperty* m_pTypeProperty; // moov.trak[].mdia.hdlr.handlerType
+
+ u_int32_t m_lastStsdIndex;
+ FILE* m_lastSampleFile;
+
+ // for efficient construction of hint track packets
+ MP4SampleId m_cachedReadSampleId;
+ u_int8_t* m_pCachedReadSample;
+ u_int32_t m_cachedReadSampleSize;
+
+ // for writing
+ MP4SampleId m_writeSampleId;
+ MP4Duration m_fixedSampleDuration;
+ u_int8_t* m_pChunkBuffer;
+ u_int32_t m_chunkBufferSize;
+ u_int32_t m_chunkSamples;
+ MP4Duration m_chunkDuration;
+
+ // controls for chunking
+ u_int32_t m_samplesPerChunk;
+ MP4Duration m_durationPerChunk;
+
+ // controls for AMR chunking
+ int m_isAmr;
+ u_int8_t m_curMode;
+
+ MP4Integer32Property* m_pTimeScaleProperty;
+ MP4IntegerProperty* m_pTrackDurationProperty; // 32 or 64 bits
+ MP4IntegerProperty* m_pMediaDurationProperty; // 32 or 64 bits
+ MP4IntegerProperty* m_pTrackModificationProperty; // 32 or 64 bits
+ MP4IntegerProperty* m_pMediaModificationProperty; // 32 or 64 bits
+
+ MP4Integer32Property* m_pStszFixedSampleSizeProperty;
+ MP4Integer32Property* m_pStszSampleCountProperty;
+ MP4Integer32Property* m_pStszSampleSizeProperty;
+
+ MP4Integer32Property* m_pStscCountProperty;
+ MP4Integer32Property* m_pStscFirstChunkProperty;
+ MP4Integer32Property* m_pStscSamplesPerChunkProperty;
+ MP4Integer32Property* m_pStscSampleDescrIndexProperty;
+ MP4Integer32Property* m_pStscFirstSampleProperty;
+
+ MP4Integer32Property* m_pChunkCountProperty;
+ MP4IntegerProperty* m_pChunkOffsetProperty; // 32 or 64 bits
+
+ MP4Integer32Property* m_pSttsCountProperty;
+ MP4Integer32Property* m_pSttsSampleCountProperty;
+ MP4Integer32Property* m_pSttsSampleDeltaProperty;
+
+ MP4Integer32Property* m_pCttsCountProperty;
+ MP4Integer32Property* m_pCttsSampleCountProperty;
+ MP4Integer32Property* m_pCttsSampleOffsetProperty;
+
+ MP4Integer32Property* m_pStssCountProperty;
+ MP4Integer32Property* m_pStssSampleProperty;
+
+ MP4Integer32Property* m_pElstCountProperty;
+ MP4IntegerProperty* m_pElstMediaTimeProperty; // 32 or 64 bits
+ MP4IntegerProperty* m_pElstDurationProperty; // 32 or 64 bits
+ MP4Integer16Property* m_pElstRateProperty;
+ MP4Integer16Property* m_pElstReservedProperty;
+};
+
+MP4ARRAY_DECL(MP4Track, MP4Track*);
+
+#endif /* __MP4_TRACK_INCLUDED__ */
--- /dev/null
+++ b/common/mp4v2/mp4util.cpp
@@ -1,0 +1,238 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+void MP4Error::Print(FILE* pFile)
+{
+ fprintf(pFile, "MP4ERROR: ");
+ if (m_where) {
+ fprintf(pFile, "%s", m_where);
+ }
+ if (m_errstring) {
+ if (m_where) {
+ fprintf(pFile, ": ");
+ }
+ fprintf(pFile, "%s", m_errstring);
+ }
+ if (m_errno) {
+ if (m_where || m_errstring) {
+ fprintf(pFile, ": ");
+ }
+ fprintf(pFile, "%s", strerror(m_errno));
+ }
+ fprintf(pFile, "\n");
+}
+
+void MP4HexDump(
+ u_int8_t* pBytes, u_int32_t numBytes,
+ FILE* pFile, u_int8_t indent)
+{
+ if (pFile == NULL) {
+ pFile = stdout;
+ }
+ Indent(pFile, indent);
+ fprintf(pFile, "<%u bytes> ", numBytes);
+ for (u_int32_t i = 0; i < numBytes; i++) {
+ if ((i % 16) == 0 && numBytes > 16) {
+ fprintf(pFile, "\n");
+ Indent(pFile, indent);
+ }
+ fprintf(pFile, "%02x ", pBytes[i]);
+ }
+ fprintf(pFile, "\n");
+}
+
+bool MP4NameFirstMatches(const char* s1, const char* s2)
+{
+ if (s1 == NULL || *s1 == '\0' || s2 == NULL || *s2 == '\0') {
+ return false;
+ }
+
+ if (*s2 == '*') {
+ return true;
+ }
+
+ while (*s1 != '\0') {
+ if (*s2 == '\0' || strchr("[.", *s2)) {
+ break;
+ }
+ if (tolower(*s1) != tolower(*s2)) {
+ return false;
+ }
+ s1++;
+ s2++;
+ }
+ return true;
+}
+
+bool MP4NameFirstIndex(const char* s, u_int32_t* pIndex)
+{
+ if (s == NULL) {
+ return false;
+ }
+
+ while (*s != '\0' && *s != '.') {
+ if (*s == '[') {
+ s++;
+ ASSERT(pIndex);
+ if (sscanf(s, "%u", pIndex) != 1) {
+ return false;
+ }
+ return true;
+ }
+ s++;
+ }
+ return false;
+}
+
+char* MP4NameFirst(const char *s)
+{
+ if (s == NULL) {
+ return NULL;
+ }
+
+ const char* end = s;
+
+ while (*end != '\0' && *end != '.') {
+ end++;
+ }
+
+ char* first = (char*)MP4Calloc((end - s) + 1);
+
+ if (first) {
+ strncpy(first, s, end - s);
+ }
+
+ return first;
+}
+
+const char* MP4NameAfterFirst(const char *s)
+{
+ if (s == NULL) {
+ return NULL;
+ }
+
+ while (*s != '\0') {
+ if (*s == '.') {
+ s++;
+ if (*s == '\0') {
+ return NULL;
+ }
+ return s;
+ }
+ s++;
+ }
+ return NULL;
+}
+
+char* MP4ToBase16(const u_int8_t* pData, u_int32_t dataSize)
+{
+ if (dataSize) {
+ ASSERT(pData);
+ }
+
+ char* s = (char*)MP4Calloc((2 * dataSize) + 1);
+
+ u_int32_t i, j;
+ for (i = 0, j = 0; i < dataSize; i++) {
+ sprintf(&s[j], "%02x", pData[i]);
+ j += 2;
+ }
+
+ return s; /* N.B. caller is responsible for free'ing s */
+}
+
+char* MP4ToBase64(const u_int8_t* pData, u_int32_t dataSize)
+{
+ if (dataSize) {
+ ASSERT(pData);
+ }
+
+ static char encoding[64] = {
+ 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P',
+ 'Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f',
+ 'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v',
+ 'w','x','y','z','0','1','2','3','4','5','6','7','8','9','+','/'
+ };
+
+ char* s = (char*)MP4Calloc((((dataSize + 2) * 4) / 3) + 1);
+
+ const u_int8_t* src = pData;
+ char* dest = s;
+ u_int32_t numGroups = dataSize / 3;
+
+ for (u_int32_t i = 0; i < numGroups; i++) {
+ *dest++ = encoding[src[0] >> 2];
+ *dest++ = encoding[((src[0] & 0x03) << 4) | (src[1] >> 4)];
+ *dest++ = encoding[((src[1] & 0x0F) << 2) | (src[2] >> 6)];
+ *dest++ = encoding[src[2] & 0x3F];
+ src += 3;
+ }
+
+ if (dataSize % 3 == 1) {
+ *dest++ = encoding[src[0] >> 2];
+ *dest++ = encoding[((src[0] & 0x03) << 4)];
+ *dest++ = '=';
+ *dest++ = '=';
+ } else if (dataSize % 3 == 2) {
+ *dest++ = encoding[src[0] >> 2];
+ *dest++ = encoding[((src[0] & 0x03) << 4) | (src[1] >> 4)];
+ *dest++ = encoding[((src[1] & 0x0F) << 2)];
+ *dest++ = '=';
+ }
+
+ return s; /* N.B. caller is responsible for free'ing s */
+}
+
+// log2 of value, rounded up
+static u_int8_t ilog2(u_int64_t value)
+{
+ u_int64_t powerOf2 = 1;
+ for (u_int8_t i = 0; i < 64; i++) {
+ if (value <= powerOf2) {
+ return i;
+ }
+ powerOf2 <<= 1;
+ }
+ return 64;
+}
+
+u_int64_t MP4ConvertTime(u_int64_t t,
+ u_int32_t oldTimeScale, u_int32_t newTimeScale)
+{
+ // avoid float point exception
+ if (oldTimeScale == 0) {
+ throw new MP4Error("division by zero", "MP4ConvertTime");
+ }
+
+ // check if we can safely use integer operations
+ if (ilog2(t) + ilog2(newTimeScale) <= 64) {
+ return (t * newTimeScale) / oldTimeScale;
+ }
+
+ // final resort is to use floating point
+ double d = ((double)newTimeScale / (double)oldTimeScale) + 0.5;
+ d *= UINT64_TO_DOUBLE(t);
+
+ return (u_int64_t)d;
+}
+
--- /dev/null
+++ b/common/mp4v2/mp4util.h
@@ -1,0 +1,242 @@
+/*
+ * 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
+ */
+
+#ifndef __MP4_UTIL_INCLUDED__
+#define __MP4_UTIL_INCLUDED__
+#include <assert.h>
+
+#ifndef ASSERT
+#ifdef NDEBUG
+#define ASSERT(expr)
+#else
+#define ASSERT(expr) \
+ if (!(expr)) { \
+ fflush(stdout); \
+ assert((expr)); \
+ }
+#endif
+#endif
+#ifdef NDEBUG
+#define WARNING(expr)
+#else
+#define WARNING(expr) \
+ if (expr) { \
+ fflush(stdout); \
+ fprintf(stderr, "Warning (%s) in %s at line %u\n", \
+ __STRING(expr), __FILE__, __LINE__); \
+ }
+#endif
+
+#define VERBOSE(exprverbosity, verbosity, expr) \
+ if (((exprverbosity) & (verbosity)) == (exprverbosity)) { expr; }
+
+#define VERBOSE_ERROR(verbosity, expr) \
+ VERBOSE(MP4_DETAILS_ERROR, verbosity, expr)
+
+#define VERBOSE_WARNING(verbosity, expr) \
+ VERBOSE(MP4_DETAILS_WARNING, verbosity, expr)
+
+#define VERBOSE_READ(verbosity, expr) \
+ VERBOSE(MP4_DETAILS_READ, verbosity, expr)
+
+#define VERBOSE_READ_TABLE(verbosity, expr) \
+ VERBOSE((MP4_DETAILS_READ | MP4_DETAILS_TABLE), verbosity, expr)
+
+#define VERBOSE_READ_SAMPLE(verbosity, expr) \
+ VERBOSE((MP4_DETAILS_READ | MP4_DETAILS_SAMPLE), verbosity, expr)
+
+#define VERBOSE_READ_HINT(verbosity, expr) \
+ VERBOSE((MP4_DETAILS_READ | MP4_DETAILS_HINT), verbosity, expr)
+
+#define VERBOSE_WRITE(verbosity, expr) \
+ VERBOSE(MP4_DETAILS_WRITE, verbosity, expr)
+
+#define VERBOSE_WRITE_TABLE(verbosity, expr) \
+ VERBOSE((MP4_DETAILS_WRITE | MP4_DETAILS_TABLE), verbosity, expr)
+
+#define VERBOSE_WRITE_SAMPLE(verbosity, expr) \
+ VERBOSE((MP4_DETAILS_WRITE | MP4_DETAILS_SAMPLE), verbosity, expr)
+
+#define VERBOSE_WRITE_HINT(verbosity, expr) \
+ VERBOSE((MP4_DETAILS_WRITE | MP4_DETAILS_HINT), verbosity, expr)
+
+#define VERBOSE_FIND(verbosity, expr) \
+ VERBOSE(MP4_DETAILS_FIND, verbosity, expr)
+
+#define VERBOSE_ISMA(verbosity, expr) \
+ VERBOSE(MP4_DETAILS_ISMA, verbosity, expr)
+
+#define VERBOSE_EDIT(verbosity, expr) \
+ VERBOSE(MP4_DETAILS_EDIT, verbosity, expr)
+
+inline void Indent(FILE* pFile, u_int8_t depth) {
+ fprintf(pFile, "%*c", depth, ' ');
+}
+
+static inline void MP4Printf(const char* fmt, ...)
+#ifndef _WIN32
+ __attribute__((format(__printf__, 1, 2)))
+#endif
+;
+
+static inline void MP4Printf(const char* fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ // TBD API call to set error_msg_func instead of just printf
+ vprintf(fmt, ap);
+ va_end(ap);
+}
+
+class MP4Error {
+public:
+ MP4Error() {
+ m_errno = 0;
+ m_errstring = NULL;
+ m_where = NULL;
+ m_free = 0;
+ }
+ ~MP4Error() {
+ if (m_free != 0) {
+ free((void *)m_errstring);
+ }
+ }
+ MP4Error(int err, const char* where = NULL) {
+ m_errno = err;
+ m_errstring = NULL;
+ m_where = where;
+ m_free = 0;
+ }
+ MP4Error(const char *format, const char *where, ...) {
+ char *string;
+ m_errno = 0;
+ string = (char *)malloc(512);
+ m_where = where;
+ if (string) {
+ va_list ap;
+ va_start(ap, where);
+ vsnprintf(string, 512, format, ap);
+ va_end(ap);
+ m_errstring = string;
+ m_free = 1;
+ } else {
+ m_errstring = format;
+ m_free = 0;
+ }
+ }
+ MP4Error(int err, const char* format, const char* where, ...) {
+ char *string;
+ m_errno = err;
+ string = (char *)malloc(512);
+ m_where = where;
+ if (string) {
+ va_list ap;
+ va_start(ap, where);
+ vsnprintf(string, 512, format, ap);
+ va_end(ap);
+ m_errstring = string;
+ m_free = 1;
+ } else {
+ m_errstring = format;
+ m_free = 0;
+ }
+ }
+
+ void Print(FILE* pFile = stderr);
+ int m_free;
+ int m_errno;
+ const char* m_errstring;
+ const char* m_where;
+};
+
+void MP4HexDump(
+ u_int8_t* pBytes, u_int32_t numBytes,
+ FILE* pFile = stdout, u_int8_t indent = 0);
+
+inline void* MP4Malloc(size_t size) {
+ void* p = malloc(size);
+ if (p == NULL && size > 0) {
+ throw new MP4Error(errno);
+ }
+ return p;
+}
+
+inline void* MP4Calloc(size_t size) {
+ return memset(MP4Malloc(size), 0, size);
+}
+
+inline char* MP4Stralloc(const char* s1) {
+ char* s2 = (char*)MP4Malloc(strlen(s1) + 1);
+ strcpy(s2, s1);
+ return s2;
+}
+
+inline void* MP4Realloc(void* p, u_int32_t newSize) {
+ // workaround library bug
+ if (p == NULL && newSize == 0) {
+ return NULL;
+ }
+ p = realloc(p, newSize);
+ if (p == NULL && newSize > 0) {
+ throw new MP4Error(errno);
+ }
+ return p;
+}
+
+inline void MP4Free(void* p) {
+ free(p);
+}
+
+inline u_int32_t STRTOINT32(const char* s) {
+ return (s[0] << 24) | (s[1] << 16) | (s[2] << 8) | s[3];
+}
+
+inline void INT32TOSTR(u_int32_t i, char* s) {
+ s[0] = ((i >> 24) & 0xFF); s[1] = ((i >> 16) & 0xFF);
+ s[2] = ((i >> 8) & 0xFF); s[3] = (i & 0xFF); s[4] = 0;
+}
+
+inline MP4Timestamp MP4GetAbsTimestamp() {
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ MP4Timestamp ret;
+ ret = tv.tv_sec;
+ ret += 2082844800;
+ return ret; // MP4 start date is 1/1/1904
+ // 208284480 is (((1970 - 1904) * 365) + 17) * 24 * 60 * 60
+}
+
+u_int64_t MP4ConvertTime(u_int64_t t,
+ u_int32_t oldTimeScale, u_int32_t newTimeScale);
+
+bool MP4NameFirstMatches(const char* s1, const char* s2);
+
+bool MP4NameFirstIndex(const char* s, u_int32_t* pIndex);
+
+char* MP4NameFirst(const char *s);
+
+const char* MP4NameAfterFirst(const char *s);
+
+char* MP4ToBase16(const u_int8_t* pData, u_int32_t dataSize);
+
+char* MP4ToBase64(const u_int8_t* pData, u_int32_t dataSize);
+
+#endif /* __MP4_UTIL_INCLUDED__ */
--- /dev/null
+++ b/common/mp4v2/mpeg4ip.h
@@ -1,0 +1,368 @@
+/*
+ * 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. 2000, 2001. All Rights Reserved.
+ *
+ * Contributor(s):
+ * Dave Mackie dmackie@cisco.com
+ */
+
+#ifndef __MPEG4IP_INCLUDED__
+#define __MPEG4IP_INCLUDED__
+
+/* project wide applicable stuff here */
+
+
+#ifdef WIN32
+#define HAVE_IN_PORT_T
+#define HAVE_SOCKLEN_T
+#define NEED_SDL_VIDEO_IN_MAIN_THREAD
+#else
+#undef PACKAGE
+#undef VERSION
+#include <mpeg4ip_config.h>
+#undef PACKAGE
+#undef VERSION
+// so these don't propogate
+#endif
+
+// the mpeg4ip_package and mpeg4ip_version are always in this
+// file
+#include "mpeg4ip_version.h"
+
+
+
+
+#ifdef WIN32
+
+#define _WIN32_WINNT 0x0400
+#define _WINSOCKAPI_
+#include <windows.h>
+#include <winsock2.h>
+#include <stdio.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <time.h>
+#include <limits.h>
+
+typedef unsigned __int64 uint64_t;
+typedef unsigned __int32 uint32_t;
+typedef unsigned __int16 uint16_t;
+typedef unsigned __int8 uint8_t;
+typedef unsigned __int64 u_int64_t;
+typedef unsigned __int32 u_int32_t;
+typedef unsigned __int16 u_int16_t;
+typedef unsigned __int8 u_int8_t;
+typedef __int64 int64_t;
+typedef __int32 int32_t;
+typedef __int16 int16_t;
+typedef __int8 int8_t;
+typedef unsigned short in_port_t;
+typedef int socklen_t;
+typedef int ssize_t;
+#define snprintf _snprintf
+#define strncasecmp _strnicmp
+#define strcasecmp _stricmp
+
+#include <io.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#define write _write
+#define lseek _lseek
+#define close _close
+#define open _open
+#define access _access
+#define vsnprintf _vsnprintf
+#define F_OK 0
+#define OPEN_RDWR (_O_RDWR | _O_BINARY)
+#define OPEN_CREAT (_O_CREAT | _O_BINARY)
+#define OPEN_RDONLY (_O_RDONLY | _O_BINARY)
+#define srandom srand
+#define random rand
+
+#define IOSBINARY ios::binary
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+int gettimeofday(struct timeval *t, void *);
+#ifdef __cplusplus
+}
+#endif
+
+#define PATH_MAX MAX_PATH
+#define MAX_UINT64 -1
+#define D64F "I64d"
+#define U64F "I64u"
+#define X64F "I64x"
+
+#define TO_D64(a) (a##I64)
+#define TO_U64(a) (a##UI64)
+
+#define LOG_EMERG 0
+#define LOG_ALERT 1
+#define LOG_CRIT 2
+#define LOG_ERR 3
+#define LOG_WARNING 4
+#define LOG_NOTICE 5
+#define LOG_INFO 6
+#define LOG_DEBUG 7
+
+#if !__STDC__ && _INTEGRAL_MAX_BITS >= 64
+#define VAR_TO_FPOS(fpos, var) (fpos) = (var)
+#define FPOS_TO_VAR(fpos, typed, var) (var) = (typed)(_FPOSOFF(fpos))
+#else
+#define VAR_TO_FPOS(fpos, var) (fpos).lopart = ((var) & UINT_MAX); (fpos).hipart = ((var) >> 32)
+#define FPOS_TO_VAR(fpos, typed, var) (var) = (typed)((uint64_t)((fpos).hipart ) << 32 | (fpos).lopart)
+#endif
+
+#define __STRING(expr) #expr
+
+#define FOPEN_READ_BINARY "rb"
+#define FOPEN_WRITE_BINARY "wb"
+
+#define UINT64_TO_DOUBLE(a) ((double)((int64_t)(a)))
+#else /* UNIX */
+/*****************************************************************************
+ * UNIX LIKE DEFINES BELOW THIS POINT
+ *****************************************************************************/
+#ifdef sun
+#include <sys/feature_tests.h>
+#endif
+
+#ifndef _FILE_OFFSET_BITS
+#define _FILE_OFFSET_BITS 64
+#else
+#ifndef sun
+#if _FILE_OFFSET_BITS < 64
+ #error File offset bits is already set to non-64 value
+#endif
+#endif
+#endif
+
+#ifndef _LARGEFILE_SOURCE
+#define _LARGEFILE_SOURCE
+#endif
+#include <stdio.h>
+#include <errno.h>
+#include <stdlib.h>
+
+#ifdef HAVE_INTTYPES_H
+#include <inttypes.h>
+#endif
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#endif
+#if !defined(HAVE_INTTYPES_H) || !defined(HAVE_STDINT_H)
+#error "Don't have stdint.h or inttypes.h - no way to get uint8_t"
+#endif
+
+#include <unistd.h>
+#include <fcntl.h>
+#include <netinet/in.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <syslog.h>
+#include <string.h>
+#include <ctype.h>
+#include <netdb.h>
+#include <sys/stat.h>
+#ifdef TIME_WITH_SYS_TIME
+#include <sys/time.h>
+#include <time.h>
+#else
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#else
+#include <time.h>
+#endif
+#endif
+#include <sys/param.h>
+
+#define OPEN_RDWR O_RDWR
+#define OPEN_CREAT O_CREAT
+#define OPEN_RDONLY O_RDONLY
+
+#define closesocket close
+#define IOSBINARY ios::bin
+
+#if SIZEOF_LONG == 8
+#define MAX_UINT64 -1LU
+#define D64F "ld"
+#define U64F "lu"
+#define X64F "lx"
+
+#define TO_D64(a) (a##LD)
+#define TO_U64(a) (a##LU)
+#else
+#define MAX_UINT64 -1LLU
+#define D64F "lld"
+#define U64F "llu"
+#define X64F "llx"
+
+#define TO_D64(a) (a##LLD)
+#define TO_U64(a) (a##LLU)
+#endif
+
+#ifdef HAVE_FPOS_T___POS
+#define FPOS_TO_VAR(fpos, typed, var) (var) = (typed)((fpos).__pos)
+#define VAR_TO_FPOS(fpos, var) (fpos).__pos = (var)
+#else
+#define FPOS_TO_VAR(fpos, typed, var) (var) = (typed)(fpos)
+#define VAR_TO_FPOS(fpos, var) (fpos) = (var)
+#endif
+
+#define FOPEN_READ_BINARY "r"
+#define FOPEN_WRITE_BINARY "w"
+#define UINT64_TO_DOUBLE(a) ((double)(a))
+#endif /* define unix */
+
+/*****************************************************************************
+ * Generic type includes used in the whole package *
+ *****************************************************************************/
+#define D64 "%"D64F
+#define U64 "%"U64F
+#define X64 "%"X64F
+
+#define M_LLU TO_U64(1000)
+#define M_64 TO_U64(1000)
+#define LLU U64
+
+#include <stdarg.h>
+typedef void (*error_msg_func_t)(int loglevel,
+ const char *lib,
+ const char *fmt,
+ va_list ap);
+typedef void (*lib_message_func_t)(int loglevel,
+ const char *lib,
+ const char *fmt,
+ ...);
+#ifndef HAVE_IN_PORT_T
+typedef uint16_t in_port_t;
+#endif
+
+#ifndef HAVE_SOCKLEN_T
+typedef unsigned int socklen_t;
+#endif
+
+#ifdef sun
+#include <limits.h>
+#define u_int8_t uint8_t
+#define u_int16_t uint16_t
+#define u_int32_t uint32_t
+#define u_int64_t uint64_t
+#define __STRING(expr) #expr
+#endif
+
+#ifndef HAVE_STRSEP
+#ifdef __cplusplus
+extern "C" {
+#endif
+char *strsep(char **strp, const char *delim);
+#ifdef __cplusplus
+}
+#endif
+#endif
+
+#ifndef MIN
+#define MIN(a,b) ((a) < (b) ? (a) : (b))
+#endif
+
+#ifndef MAX
+#define MAX(a,b) ((a) > (b) ? (a) : (b))
+#endif
+
+#ifndef INADDR_NONE
+#define INADDR_NONE (-1)
+#endif
+
+#define MALLOC_STRUCTURE(a) ((a *)malloc(sizeof(a)))
+
+#define CHECK_AND_FREE(a) if ((a) != NULL) { free((void *)(a)); (a) = NULL;}
+
+#define NUM_ELEMENTS_IN_ARRAY(name) ((sizeof((name))) / (sizeof(*(name))))
+
+#define ADV_SPACE(a) {while (isspace(*(a)) && (*(a) != '\0'))(a)++;}
+
+#ifndef HAVE_GTK
+typedef char gchar;
+typedef unsigned char guchar;
+
+typedef int gint;
+typedef unsigned int guint;
+
+typedef long glong;
+typedef unsigned long gulong;
+
+typedef double gdouble;
+
+typedef int gboolean;
+
+typedef int16_t gint16;
+typedef uint16_t guint16;
+
+typedef int32_t gint32;
+typedef uint32_t guint32;
+
+typedef int64_t gint64;
+typedef uint64_t guint64;
+
+typedef uint8_t guint8;
+typedef int8_t gint8;
+
+#endif
+
+#ifndef FALSE
+#define FALSE 0
+#endif
+
+#ifndef TRUE
+#define TRUE 1
+#endif
+
+#ifndef __cplusplus
+#ifndef bool
+typedef unsigned char bool;
+#endif
+#endif
+
+#ifndef ROUND
+# ifdef HAVE_RINT
+# define ROUND(f) rint(f)
+# else
+# define ROUND(f) (int)(floor((f) + 0.5))
+# endif
+#endif
+
+#ifndef INT16_MAX
+# define INT16_MAX (32767)
+#endif
+#ifndef INT16_MIN
+# define INT16_MIN (-32767-1)
+#endif
+
+#ifndef UINT32_MAX
+# define UINT32_MAX (4294967295U)
+#endif
+
+#ifndef UINT64_MAX
+# define UINT64_MAX TO_U64(0xffffffffffffffff)
+#endif
+
+#endif /* __MPEG4IP_INCLUDED__ */
+
--- /dev/null
+++ b/common/mp4v2/mpeg4ip_version.h
@@ -1,0 +1,2 @@
+#define MPEG4IP_PACKAGE "mpeg4ip"
+#define MPEG4IP_VERSION "1.1.3"
--- /dev/null
+++ b/common/mp4v2/need_for_win32.c
@@ -1,0 +1,12 @@
+#include "mpeg4ip.h"
+#include <sys/timeb.h>
+
+int gettimeofday (struct timeval *t, void *foo)
+{
+ struct _timeb temp;
+ _ftime(&temp);
+ t->tv_sec = temp.time;
+ t->tv_usec = temp.millitm * 1000;
+ return (0);
+}
+
--- /dev/null
+++ b/common/mp4v2/ocidescriptors.cpp
@@ -1,0 +1,307 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4ContentClassDescriptor::MP4ContentClassDescriptor()
+ : MP4Descriptor()
+{
+ AddProperty( /* 0 */
+ new MP4Integer32Property("classificationEntity"));
+ AddProperty( /* 1 */
+ new MP4Integer16Property("classificationTable"));
+ AddProperty( /* 2 */
+ new MP4BytesProperty("contentClassificationData"));
+}
+
+void MP4ContentClassDescriptor::Read(MP4File* pFile)
+{
+ ReadHeader(pFile);
+
+ /* byte properties need to know how long they are before reading */
+ ((MP4BytesProperty*)m_pProperties[2])->SetValueSize(m_size - 6);
+
+ ReadProperties(pFile);
+}
+
+MP4KeywordDescriptor::MP4KeywordDescriptor()
+ : MP4Descriptor()
+{
+ AddProperty( /* 0 */
+ new MP4BytesProperty("languageCode", 3));
+ AddProperty( /* 1 */
+ new MP4BitfieldProperty("isUTF8String", 1));
+ AddProperty( /* 2 */
+ new MP4BitfieldProperty("reserved", 7));
+ MP4Integer8Property* pCount =
+ new MP4Integer8Property("keywordCount");
+ AddProperty(pCount); /* 3 */
+
+ MP4TableProperty* pTable = new MP4TableProperty("keywords", pCount);
+ AddProperty(pTable); /* 4 */
+
+ pTable->AddProperty( /* 4, 0 */
+ new MP4StringProperty("string", Counted));
+
+ SetReadMutate(2);
+}
+
+void MP4KeywordDescriptor::Mutate()
+{
+ bool utf8Flag = ((MP4BitfieldProperty*)m_pProperties[1])->GetValue();
+ MP4Property* pProperty =
+ ((MP4TableProperty*)m_pProperties[4])->GetProperty(0);
+ ASSERT(pProperty);
+ ((MP4StringProperty*)pProperty)->SetUnicode(!utf8Flag);
+}
+
+MP4RatingDescriptor::MP4RatingDescriptor()
+ : MP4Descriptor()
+{
+ AddProperty( /* 0 */
+ new MP4Integer32Property("ratingEntity"));
+ AddProperty( /* 1 */
+ new MP4Integer16Property("ratingCriteria"));
+ AddProperty( /* 2 */
+ new MP4BytesProperty("ratingInfo"));
+}
+
+void MP4RatingDescriptor::Read(MP4File* pFile)
+{
+ ReadHeader(pFile);
+
+ /* byte properties need to know how long they are before reading */
+ ((MP4BytesProperty*)m_pProperties[2])->SetValueSize(m_size - 6);
+
+ ReadProperties(pFile);
+}
+
+MP4LanguageDescriptor::MP4LanguageDescriptor()
+ : MP4Descriptor()
+{
+ AddProperty( /* 0 */
+ new MP4BytesProperty("languageCode", 3));
+}
+
+MP4ShortTextDescriptor::MP4ShortTextDescriptor()
+ : MP4Descriptor()
+{
+ AddProperty( /* 0 */
+ new MP4BytesProperty("languageCode", 3));
+ AddProperty( /* 1 */
+ new MP4BitfieldProperty("isUTF8String", 1));
+ AddProperty( /* 2 */
+ new MP4BitfieldProperty("reserved", 7));
+ AddProperty( /* 3 */
+ new MP4StringProperty("eventName", Counted));
+ AddProperty( /* 4 */
+ new MP4StringProperty("eventText", Counted));
+
+ SetReadMutate(2);
+}
+
+void MP4ShortTextDescriptor::Mutate()
+{
+ bool utf8Flag = ((MP4BitfieldProperty*)m_pProperties[1])->GetValue();
+ ((MP4StringProperty*)m_pProperties[3])->SetUnicode(!utf8Flag);
+ ((MP4StringProperty*)m_pProperties[4])->SetUnicode(!utf8Flag);
+}
+
+MP4ExpandedTextDescriptor::MP4ExpandedTextDescriptor()
+ : MP4Descriptor()
+{
+ AddProperty( /* 0 */
+ new MP4BytesProperty("languageCode", 3));
+ AddProperty( /* 1 */
+ new MP4BitfieldProperty("isUTF8String", 1));
+ AddProperty( /* 2 */
+ new MP4BitfieldProperty("reserved", 7));
+ MP4Integer8Property* pCount =
+ new MP4Integer8Property("itemCount");
+ AddProperty(pCount); /* 3 */
+
+ MP4TableProperty* pTable = new MP4TableProperty("items", pCount);
+ AddProperty(pTable); /* 4 */
+
+ pTable->AddProperty( /* Table 0 */
+ new MP4StringProperty("itemDescription", Counted));
+ pTable->AddProperty( /* Table 1 */
+ new MP4StringProperty("itemText", Counted));
+
+ AddProperty( /* 5 */
+ new MP4StringProperty("nonItemText"));
+ ((MP4StringProperty*)m_pProperties[5])->SetExpandedCountedFormat(true);
+
+ SetReadMutate(2);
+}
+
+void MP4ExpandedTextDescriptor::Mutate()
+{
+ bool utf8Flag = ((MP4BitfieldProperty*)m_pProperties[1])->GetValue();
+
+ MP4Property* pProperty =
+ ((MP4TableProperty*)m_pProperties[4])->GetProperty(0);
+ ASSERT(pProperty);
+ ((MP4StringProperty*)pProperty)->SetUnicode(!utf8Flag);
+
+ pProperty = ((MP4TableProperty*)m_pProperties[4])->GetProperty(1);
+ ASSERT(pProperty);
+ ((MP4StringProperty*)pProperty)->SetUnicode(!utf8Flag);
+
+ ((MP4StringProperty*)m_pProperties[5])->SetUnicode(!utf8Flag);
+}
+
+class MP4CreatorTableProperty : public MP4TableProperty {
+public:
+ MP4CreatorTableProperty(char* name, MP4Integer8Property* pCountProperty) :
+ MP4TableProperty(name, pCountProperty) {
+ };
+protected:
+ void ReadEntry(MP4File* pFile, u_int32_t index);
+ void WriteEntry(MP4File* pFile, u_int32_t index);
+};
+
+MP4CreatorDescriptor::MP4CreatorDescriptor(u_int8_t tag)
+ : MP4Descriptor(tag)
+{
+ MP4Integer8Property* pCount =
+ new MP4Integer8Property("creatorCount");
+ AddProperty(pCount); /* 0 */
+
+ MP4TableProperty* pTable = new MP4CreatorTableProperty("creators", pCount);
+ AddProperty(pTable); /* 1 */
+
+ pTable->AddProperty( /* Table 0 */
+ new MP4BytesProperty("languageCode", 3, 3));
+ pTable->AddProperty( /* Table 1 */
+ new MP4BitfieldProperty("isUTF8String", 1));
+ pTable->AddProperty( /* Table 2 */
+ new MP4BitfieldProperty("reserved", 7));
+ pTable->AddProperty( /* Table 3 */
+ new MP4StringProperty("name", Counted));
+}
+
+void MP4CreatorTableProperty::ReadEntry(MP4File* pFile, u_int32_t index)
+{
+ m_pProperties[0]->Read(pFile, index);
+ m_pProperties[1]->Read(pFile, index);
+
+ bool utf8Flag = ((MP4BitfieldProperty*)m_pProperties[1])->GetValue(index);
+ ((MP4StringProperty*)m_pProperties[3])->SetUnicode(!utf8Flag);
+
+ m_pProperties[2]->Read(pFile, index);
+ m_pProperties[3]->Read(pFile, index);
+}
+
+void MP4CreatorTableProperty::WriteEntry(MP4File* pFile, u_int32_t index)
+{
+ bool utf8Flag = ((MP4BitfieldProperty*)m_pProperties[1])->GetValue(index);
+ ((MP4StringProperty*)m_pProperties[3])->SetUnicode(!utf8Flag);
+
+ MP4TableProperty::WriteEntry(pFile, index);
+}
+
+MP4CreationDescriptor::MP4CreationDescriptor(u_int8_t tag)
+ : MP4Descriptor(tag)
+{
+ AddProperty( /* 0 */
+ new MP4BitfieldProperty("contentCreationDate", 40));
+}
+
+MP4SmpteCameraDescriptor::MP4SmpteCameraDescriptor()
+ : MP4Descriptor()
+{
+ MP4Integer8Property* pCount =
+ new MP4Integer8Property("parameterCount");
+ AddProperty(pCount);
+
+ MP4TableProperty* pTable = new MP4TableProperty("parameters", pCount);
+ AddProperty(pTable);
+
+ pTable->AddProperty(
+ new MP4Integer8Property("id"));
+ pTable->AddProperty(
+ new MP4Integer32Property("value"));
+}
+
+MP4UnknownOCIDescriptor::MP4UnknownOCIDescriptor()
+ : MP4Descriptor()
+{
+ AddProperty( /* 0 */
+ new MP4BytesProperty("data"));
+}
+
+void MP4UnknownOCIDescriptor::Read(MP4File* pFile)
+{
+ ReadHeader(pFile);
+
+ /* byte properties need to know how long they are before reading */
+ ((MP4BytesProperty*)m_pProperties[0])->SetValueSize(m_size);
+
+ ReadProperties(pFile);
+}
+
+MP4Descriptor* CreateOCIDescriptor(u_int8_t tag)
+{
+ MP4Descriptor* pDescriptor = NULL;
+
+ switch (tag) {
+ case MP4ContentClassDescrTag:
+ pDescriptor = new MP4ContentClassDescriptor();
+ break;
+ case MP4KeywordDescrTag:
+ pDescriptor = new MP4KeywordDescriptor();
+ break;
+ case MP4RatingDescrTag:
+ pDescriptor = new MP4RatingDescriptor();
+ break;
+ case MP4LanguageDescrTag:
+ pDescriptor = new MP4LanguageDescriptor();
+ break;
+ case MP4ShortTextDescrTag:
+ pDescriptor = new MP4ShortTextDescriptor();
+ break;
+ case MP4ExpandedTextDescrTag:
+ pDescriptor = new MP4ExpandedTextDescriptor();
+ break;
+ case MP4ContentCreatorDescrTag:
+ case MP4OCICreatorDescrTag:
+ pDescriptor = new MP4CreatorDescriptor(tag);
+ break;
+ case MP4ContentCreationDescrTag:
+ case MP4OCICreationDescrTag:
+ pDescriptor = new MP4CreationDescriptor(tag);
+ break;
+ case MP4SmpteCameraDescrTag:
+ pDescriptor = new MP4SmpteCameraDescriptor();
+ break;
+ }
+
+ if (pDescriptor == NULL) {
+ if (tag >= MP4OCIDescrTagsStart && tag <= MP4OCIDescrTagsEnd) {
+ pDescriptor = new MP4UnknownOCIDescriptor();
+ pDescriptor->SetTag(tag);
+ }
+ }
+
+ return pDescriptor;
+}
+
--- /dev/null
+++ b/common/mp4v2/ocidescriptors.h
@@ -1,0 +1,101 @@
+/*
+ * 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
+ */
+
+#ifndef __OCIDESCRIPTORS_INCLUDED__
+#define __OCIDESCRIPTORS_INCLUDED__
+
+const u_int8_t MP4OCIDescrTagsStart = 0x40;
+const u_int8_t MP4ContentClassDescrTag = 0x40;
+const u_int8_t MP4KeywordDescrTag = 0x41;
+const u_int8_t MP4RatingDescrTag = 0x42;
+const u_int8_t MP4LanguageDescrTag = 0x43;
+const u_int8_t MP4ShortTextDescrTag = 0x44;
+const u_int8_t MP4ExpandedTextDescrTag = 0x45;
+const u_int8_t MP4ContentCreatorDescrTag = 0x46;
+const u_int8_t MP4ContentCreationDescrTag = 0x47;
+const u_int8_t MP4OCICreatorDescrTag = 0x48;
+const u_int8_t MP4OCICreationDescrTag = 0x49;
+const u_int8_t MP4SmpteCameraDescrTag = 0x4A;
+const u_int8_t MP4OCIDescrTagsEnd = 0x5F;
+
+class MP4ContentClassDescriptor : public MP4Descriptor {
+public:
+ MP4ContentClassDescriptor();
+ void Read(MP4File* pFile);
+};
+
+class MP4KeywordDescriptor : public MP4Descriptor {
+public:
+ MP4KeywordDescriptor();
+protected:
+ void Mutate();
+};
+
+class MP4RatingDescriptor : public MP4Descriptor {
+public:
+ MP4RatingDescriptor();
+ void Read(MP4File* pFile);
+};
+
+class MP4LanguageDescriptor : public MP4Descriptor {
+public:
+ MP4LanguageDescriptor();
+};
+
+class MP4ShortTextDescriptor : public MP4Descriptor {
+public:
+ MP4ShortTextDescriptor();
+protected:
+ void Mutate();
+};
+
+class MP4ExpandedTextDescriptor : public MP4Descriptor {
+public:
+ MP4ExpandedTextDescriptor();
+protected:
+ void Mutate();
+};
+
+class MP4CreatorDescriptor : public MP4Descriptor {
+public:
+ MP4CreatorDescriptor(u_int8_t tag);
+};
+
+class MP4CreationDescriptor : public MP4Descriptor {
+public:
+ MP4CreationDescriptor(u_int8_t tag);
+};
+
+class MP4SmpteCameraDescriptor : public MP4Descriptor {
+public:
+ MP4SmpteCameraDescriptor();
+};
+
+class MP4UnknownOCIDescriptor : public MP4Descriptor {
+public:
+ MP4UnknownOCIDescriptor();
+ void Read(MP4File* pFile);
+};
+
+
+extern MP4Descriptor *CreateOCIDescriptor(u_int8_t tag);
+
+#endif /* __OCIDESCRIPTORS_INCLUDED__ */
--- /dev/null
+++ b/common/mp4v2/odcommands.cpp
@@ -1,0 +1,104 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4ODUpdateDescriptor::MP4ODUpdateDescriptor()
+ : MP4Descriptor(MP4ODUpdateODCommandTag)
+{
+ // just a container for ObjectDescriptors
+ AddProperty( /* 0 */
+ new MP4DescriptorProperty(NULL,
+ MP4FileODescrTag, 0, Required, Many));
+}
+
+MP4ODRemoveDescriptor::MP4ODRemoveDescriptor()
+ : MP4Descriptor(MP4ODRemoveODCommandTag)
+{
+ MP4Integer32Property* pCount =
+ new MP4Integer32Property("entryCount");
+ pCount->SetImplicit();
+ AddProperty(pCount); /* 0 */
+
+ MP4TableProperty* pTable =
+ new MP4TableProperty("entries", pCount);
+ AddProperty(pTable); /* 1 */
+
+ pTable->AddProperty( /* 1, 0 */
+ new MP4BitfieldProperty("objectDescriptorId", 10));
+}
+
+void MP4ODRemoveDescriptor::Read(MP4File* pFile)
+{
+ // table entry count computed from descriptor size
+ ((MP4Integer32Property*)m_pProperties[0])->SetReadOnly(false);
+ ((MP4Integer32Property*)m_pProperties[0])->SetValue((m_size * 8) / 10);
+ ((MP4Integer32Property*)m_pProperties[0])->SetReadOnly(true);
+
+ MP4Descriptor::Read(pFile);
+}
+
+MP4ESUpdateDescriptor::MP4ESUpdateDescriptor()
+ : MP4Descriptor(MP4ESUpdateODCommandTag)
+{
+ AddProperty( /* 0 */
+ new MP4BitfieldProperty("objectDescriptorId", 10));
+ AddProperty( /* 1 */
+ new MP4BitfieldProperty("pad", 6));
+ AddProperty( /* 2 */
+ new MP4DescriptorProperty("esIdRefs",
+ MP4ESIDRefDescrTag, 0, Required, Many));
+}
+
+// LATER might be able to combine with ESUpdateDescriptor
+MP4ESRemoveDescriptor::MP4ESRemoveDescriptor()
+ : MP4Descriptor(MP4ESRemoveODCommandTag)
+{
+ AddProperty( /* 0 */
+ new MP4BitfieldProperty("objectDescriptorId", 10));
+ AddProperty( /* 1 */
+ new MP4BitfieldProperty("pad", 6));
+ AddProperty( /* 2 */
+ new MP4DescriptorProperty("esIdRefs",
+ MP4ESIDRefDescrTag, 0, Required, Many));
+}
+
+MP4Descriptor* CreateODCommand(u_int8_t tag)
+{
+ MP4Descriptor* pDescriptor = NULL;
+
+ switch (tag) {
+ case MP4ODUpdateODCommandTag:
+ pDescriptor = new MP4ODUpdateDescriptor();
+ break;
+ case MP4ODRemoveODCommandTag:
+ pDescriptor = new MP4ODRemoveDescriptor();
+ break;
+ case MP4ESUpdateODCommandTag:
+ pDescriptor = new MP4ESUpdateDescriptor();
+ break;
+ case MP4ESRemoveODCommandTag:
+ pDescriptor = new MP4ESRemoveDescriptor();
+ break;
+ }
+ return pDescriptor;
+}
+
--- /dev/null
+++ b/common/mp4v2/odcommands.h
@@ -1,0 +1,58 @@
+/*
+ * 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
+ */
+
+#ifndef __ODCOMMANDS_INCLUDED__
+#define __ODCOMMANDS_INCLUDED__
+
+// OD stream command descriptors
+const u_int8_t MP4ODUpdateODCommandTag = 0x01;
+const u_int8_t MP4ODRemoveODCommandTag = 0x02;
+const u_int8_t MP4ESUpdateODCommandTag = 0x03;
+const u_int8_t MP4ESRemoveODCommandTag = 0x04;
+const u_int8_t MP4IPMPUpdateODCommandTag = 0x05;
+const u_int8_t MP4IPMPRemoveODCommandTag = 0x06;
+const u_int8_t MP4ESRemoveRefODCommandTag = 0x07;
+
+class MP4ODUpdateDescriptor : public MP4Descriptor {
+public:
+ MP4ODUpdateDescriptor();
+};
+
+class MP4ODRemoveDescriptor : public MP4Descriptor {
+public:
+ MP4ODRemoveDescriptor();
+ void Read(MP4File* pFile);
+};
+
+class MP4ESUpdateDescriptor : public MP4Descriptor {
+public:
+ MP4ESUpdateDescriptor();
+};
+
+class MP4ESRemoveDescriptor : public MP4Descriptor {
+public:
+ MP4ESRemoveDescriptor();
+};
+
+MP4Descriptor* CreateODCommand(u_int8_t tag);
+
+#endif /* __ODCOMMANDS_INCLUDED__ */
+
--- /dev/null
+++ b/common/mp4v2/qosqualifiers.cpp
@@ -1,0 +1,133 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+MP4QosDescriptor::MP4QosDescriptor()
+ : MP4Descriptor(MP4QosDescrTag)
+{
+ AddProperty( /* 0 */
+ new MP4Integer8Property("predefined"));
+ AddProperty( /* 1 */
+ new MP4QosQualifierProperty("qualifiers",
+ MP4QosTagsStart, MP4QosTagsEnd, Optional, Many));
+}
+
+MP4MaxDelayQosQualifier::MP4MaxDelayQosQualifier()
+ : MP4QosQualifier(MP4MaxDelayQosTag)
+{
+ AddProperty( /* 0 */
+ new MP4Integer32Property("maxDelay"));
+}
+
+MP4PrefMaxDelayQosQualifier::MP4PrefMaxDelayQosQualifier()
+ : MP4QosQualifier(MP4PrefMaxDelayQosTag)
+{
+ AddProperty( /* 0 */
+ new MP4Integer32Property("prefMaxDelay"));
+}
+
+MP4LossProbQosQualifier::MP4LossProbQosQualifier()
+ : MP4QosQualifier(MP4LossProbQosTag)
+{
+ AddProperty( /* 0 */
+ new MP4Float32Property("lossProb"));
+}
+
+MP4MaxGapLossQosQualifier::MP4MaxGapLossQosQualifier()
+ : MP4QosQualifier(MP4MaxGapLossQosTag)
+{
+ AddProperty( /* 0 */
+ new MP4Integer32Property("maxGapLoss"));
+}
+
+MP4MaxAUSizeQosQualifier::MP4MaxAUSizeQosQualifier()
+ : MP4QosQualifier(MP4MaxAUSizeQosTag)
+{
+ AddProperty( /* 0 */
+ new MP4Integer32Property("maxAUSize"));
+}
+
+MP4AvgAUSizeQosQualifier::MP4AvgAUSizeQosQualifier()
+ : MP4QosQualifier(MP4AvgAUSizeQosTag)
+{
+ AddProperty( /* 0 */
+ new MP4Integer32Property("avgAUSize"));
+}
+
+MP4MaxAURateQosQualifier::MP4MaxAURateQosQualifier()
+ : MP4QosQualifier(MP4MaxAURateQosTag)
+{
+ AddProperty( /* 0 */
+ new MP4Integer32Property("maxAURate"));
+}
+
+MP4UnknownQosQualifier::MP4UnknownQosQualifier()
+ : MP4QosQualifier()
+{
+ AddProperty( /* 0 */
+ new MP4BytesProperty("data"));
+}
+
+void MP4UnknownQosQualifier::Read(MP4File* pFile)
+{
+ ReadHeader(pFile);
+
+ /* byte properties need to know how long they are before reading */
+ ((MP4BytesProperty*)m_pProperties[0])->SetValueSize(m_size);
+
+ ReadProperties(pFile);
+}
+
+MP4Descriptor* MP4QosQualifierProperty::CreateDescriptor(u_int8_t tag)
+{
+ MP4Descriptor* pDescriptor = NULL;
+
+ switch (tag) {
+ case MP4MaxDelayQosTag:
+ pDescriptor = new MP4MaxDelayQosQualifier();
+ break;
+ case MP4PrefMaxDelayQosTag:
+ pDescriptor = new MP4PrefMaxDelayQosQualifier();
+ break;
+ case MP4LossProbQosTag:
+ pDescriptor = new MP4LossProbQosQualifier();
+ break;
+ case MP4MaxGapLossQosTag:
+ pDescriptor = new MP4MaxGapLossQosQualifier();
+ break;
+ case MP4MaxAUSizeQosTag:
+ pDescriptor = new MP4MaxAUSizeQosQualifier();
+ break;
+ case MP4AvgAUSizeQosTag:
+ pDescriptor = new MP4AvgAUSizeQosQualifier();
+ break;
+ case MP4MaxAURateQosTag:
+ pDescriptor = new MP4MaxAURateQosQualifier();
+ break;
+ default:
+ pDescriptor = new MP4UnknownQosQualifier();
+ pDescriptor->SetTag(tag);
+ }
+
+ return pDescriptor;
+}
+
--- /dev/null
+++ b/common/mp4v2/qosqualifiers.h
@@ -1,0 +1,85 @@
+/*
+ * 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
+ */
+
+#ifndef __QOSQUALIFIERS_INCLUDED__
+#define __QOSQUALIFIERS_INCLUDED__
+
+const u_int8_t MP4QosDescrTag = 0x0C;
+
+class MP4QosDescriptor : public MP4Descriptor {
+public:
+ MP4QosDescriptor();
+};
+
+typedef MP4Descriptor MP4QosQualifier;
+
+const u_int8_t MP4QosTagsStart = 0x01;
+const u_int8_t MP4MaxDelayQosTag = 0x01;
+const u_int8_t MP4PrefMaxDelayQosTag = 0x02;
+const u_int8_t MP4LossProbQosTag = 0x03;
+const u_int8_t MP4MaxGapLossQosTag = 0x04;
+const u_int8_t MP4MaxAUSizeQosTag = 0x41;
+const u_int8_t MP4AvgAUSizeQosTag = 0x42;
+const u_int8_t MP4MaxAURateQosTag = 0x43;
+const u_int8_t MP4QosTagsEnd = 0xFF;
+
+class MP4MaxDelayQosQualifier : public MP4QosQualifier {
+public:
+ MP4MaxDelayQosQualifier();
+};
+
+class MP4PrefMaxDelayQosQualifier : public MP4QosQualifier {
+public:
+ MP4PrefMaxDelayQosQualifier();
+};
+
+class MP4LossProbQosQualifier : public MP4QosQualifier {
+public:
+ MP4LossProbQosQualifier();
+};
+
+class MP4MaxGapLossQosQualifier : public MP4QosQualifier {
+public:
+ MP4MaxGapLossQosQualifier();
+};
+
+class MP4MaxAUSizeQosQualifier : public MP4QosQualifier {
+public:
+ MP4MaxAUSizeQosQualifier();
+};
+
+class MP4AvgAUSizeQosQualifier : public MP4QosQualifier {
+public:
+ MP4AvgAUSizeQosQualifier();
+};
+
+class MP4MaxAURateQosQualifier : public MP4QosQualifier {
+public:
+ MP4MaxAURateQosQualifier();
+};
+
+class MP4UnknownQosQualifier : public MP4QosQualifier {
+public:
+ MP4UnknownQosQualifier();
+ void Read(MP4File* pFile);
+};
+
+#endif /* __QOSQUALIFIERS_INCLUDED__ */
--- /dev/null
+++ b/common/mp4v2/rtphint.cpp
@@ -1,0 +1,1361 @@
+/*
+ * 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
+ */
+
+#include "mp4common.h"
+
+/* rtp hint track operations */
+
+MP4RtpHintTrack::MP4RtpHintTrack(MP4File* pFile, MP4Atom* pTrakAtom)
+ : MP4Track(pFile, pTrakAtom)
+{
+ m_pRefTrack = NULL;
+
+ m_pRtpMapProperty = NULL;
+ m_pPayloadNumberProperty = NULL;
+ m_pMaxPacketSizeProperty = NULL;
+ m_pSnroProperty = NULL;
+ m_pTsroProperty = NULL;
+
+ m_pReadHint = NULL;
+ m_pReadHintSample = NULL;
+ m_readHintSampleSize = 0;
+
+ m_pWriteHint = NULL;
+ m_writeHintId = MP4_INVALID_SAMPLE_ID;
+ m_writePacketId = 0;
+
+ m_pTrpy = NULL;
+ m_pNump = NULL;
+ m_pTpyl = NULL;
+ m_pMaxr = NULL;
+ m_pDmed = NULL;
+ m_pDimm = NULL;
+ m_pPmax = NULL;
+ m_pDmax = NULL;
+
+ m_pMaxPdu = NULL;
+ m_pAvgPdu = NULL;
+ m_pMaxBitRate = NULL;
+ m_pAvgBitRate = NULL;
+
+ m_thisSec = 0;
+ m_bytesThisSec = 0;
+ m_bytesThisHint = 0;
+ m_bytesThisPacket = 0;
+}
+
+MP4RtpHintTrack::~MP4RtpHintTrack()
+{
+ delete m_pReadHint;
+ delete m_pReadHintSample;
+ delete m_pWriteHint;
+}
+
+void MP4RtpHintTrack::InitRefTrack()
+{
+ if (m_pRefTrack == NULL) {
+ MP4Integer32Property* pRefTrackIdProperty = NULL;
+ m_pTrakAtom->FindProperty(
+ "trak.tref.hint.entries[0].trackId",
+ (MP4Property**)&pRefTrackIdProperty);
+ ASSERT(pRefTrackIdProperty);
+
+ m_pRefTrack = m_pFile->GetTrack(pRefTrackIdProperty->GetValue());
+ }
+}
+
+void MP4RtpHintTrack::InitRtpStart()
+{
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ srandom((tv.tv_usec << 12) | (tv.tv_sec & 0xFFF));
+
+ ASSERT(m_pTrakAtom);
+
+ m_pTrakAtom->FindProperty(
+ "trak.udta.hnti.rtp .snro.offset",
+ (MP4Property**)&m_pSnroProperty);
+
+ if (m_pSnroProperty) {
+ m_rtpSequenceStart = m_pSnroProperty->GetValue();
+ } else {
+ m_rtpSequenceStart = random();
+ }
+
+ m_pTrakAtom->FindProperty(
+ "trak.udta.hnti.rtp .tsro.offset",
+ (MP4Property**)&m_pTsroProperty);
+
+ if (m_pTsroProperty) {
+ m_rtpTimestampStart = m_pTsroProperty->GetValue();
+ } else {
+ m_rtpTimestampStart = random();
+ }
+}
+
+void MP4RtpHintTrack::ReadHint(
+ MP4SampleId hintSampleId,
+ u_int16_t* pNumPackets)
+{
+ if (m_pRefTrack == NULL) {
+ InitRefTrack();
+ InitRtpStart();
+ }
+
+ // dispose of any old hint
+ delete m_pReadHint;
+ m_pReadHint = NULL;
+ delete m_pReadHintSample;
+ m_pReadHintSample = NULL;
+ m_readHintSampleSize = 0;
+
+ // read the desired hint sample into memory
+ ReadSample(
+ hintSampleId,
+ &m_pReadHintSample,
+ &m_readHintSampleSize,
+ &m_readHintTimestamp);
+
+ m_pFile->EnableMemoryBuffer(m_pReadHintSample, m_readHintSampleSize);
+
+ m_pReadHint = new MP4RtpHint(this);
+ m_pReadHint->Read(m_pFile);
+
+ m_pFile->DisableMemoryBuffer();
+
+ if (pNumPackets) {
+ *pNumPackets = GetHintNumberOfPackets();
+ }
+}
+
+u_int16_t MP4RtpHintTrack::GetHintNumberOfPackets()
+{
+ if (m_pReadHint == NULL) {
+ throw new MP4Error("no hint has been read",
+ "MP4GetRtpHintNumberOfPackets");
+ }
+ return m_pReadHint->GetNumberOfPackets();
+}
+
+bool MP4RtpHintTrack::GetPacketBFrame(u_int16_t packetIndex)
+{
+ if (m_pReadHint == NULL) {
+ throw new MP4Error("no hint has been read",
+ "MP4GetRtpPacketBFrame");
+ }
+ MP4RtpPacket* pPacket =
+ m_pReadHint->GetPacket(packetIndex);
+
+ return pPacket->IsBFrame();
+}
+
+u_int16_t MP4RtpHintTrack::GetPacketTransmitOffset(u_int16_t packetIndex)
+{
+ if (m_pReadHint == NULL) {
+ throw new MP4Error("no hint has been read",
+ "MP4GetRtpPacketTransmitOffset");
+ }
+
+ MP4RtpPacket* pPacket =
+ m_pReadHint->GetPacket(packetIndex);
+
+ return pPacket->GetTransmitOffset();
+}
+
+void MP4RtpHintTrack::ReadPacket(
+ u_int16_t packetIndex,
+ u_int8_t** ppBytes,
+ u_int32_t* pNumBytes,
+ u_int32_t ssrc,
+ bool addHeader,
+ bool addPayload)
+{
+ if (m_pReadHint == NULL) {
+ throw new MP4Error("no hint has been read",
+ "MP4ReadRtpPacket");
+ }
+ if (!addHeader && !addPayload) {
+ throw new MP4Error("no data requested",
+ "MP4ReadRtpPacket");
+ }
+
+ MP4RtpPacket* pPacket =
+ m_pReadHint->GetPacket(packetIndex);
+
+ *pNumBytes = 0;
+ if (addHeader) {
+ *pNumBytes += 12;
+ }
+ if (addPayload) {
+ *pNumBytes += pPacket->GetDataSize();
+ }
+
+ // if needed, allocate the packet memory
+ bool buffer_malloc = false;
+
+ if (*ppBytes == NULL) {
+ *ppBytes = (u_int8_t*)MP4Malloc(*pNumBytes);
+ buffer_malloc = true;
+ }
+
+ try {
+ u_int8_t* pDest = *ppBytes;
+
+ if (addHeader) {
+ *pDest++ =
+ 0x80 | (pPacket->GetPBit() << 5) | (pPacket->GetXBit() << 4);
+
+ *pDest++ =
+ (pPacket->GetMBit() << 7) | pPacket->GetPayload();
+
+ *((u_int16_t*)pDest) =
+ htons(m_rtpSequenceStart + pPacket->GetSequenceNumber());
+ pDest += 2;
+
+ *((u_int32_t*)pDest) =
+ htonl(m_rtpTimestampStart + (u_int32_t)m_readHintTimestamp);
+ pDest += 4;
+
+ *((u_int32_t*)pDest) =
+ htonl(ssrc);
+ pDest += 4;
+ }
+
+ if (addPayload) {
+ pPacket->GetData(pDest);
+ }
+ }
+ catch (MP4Error* e) {
+ if (buffer_malloc) {
+ MP4Free(*ppBytes);
+ *ppBytes = NULL;
+ }
+ throw e;
+ }
+
+ VERBOSE_READ_HINT(m_pFile->GetVerbosity(),
+ printf("ReadPacket: %u ", packetIndex);
+ MP4HexDump(*ppBytes, *pNumBytes););
+}
+
+MP4Timestamp MP4RtpHintTrack::GetRtpTimestampStart()
+{
+ if (m_pRefTrack == NULL) {
+ InitRefTrack();
+ InitRtpStart();
+ }
+
+ return m_rtpTimestampStart;
+}
+
+void MP4RtpHintTrack::SetRtpTimestampStart(MP4Timestamp start)
+{
+ if (!m_pTsroProperty) {
+ MP4Atom* pTsroAtom =
+ m_pFile->AddDescendantAtoms(m_pTrakAtom, "udta.hnti.rtp .tsro");
+
+ ASSERT(pTsroAtom);
+
+ pTsroAtom->FindProperty("offset",
+ (MP4Property**)&m_pTsroProperty);
+
+ ASSERT(m_pTsroProperty);
+ }
+
+ m_pTsroProperty->SetValue(start);
+ m_rtpTimestampStart = start;
+}
+
+void MP4RtpHintTrack::InitPayload()
+{
+ ASSERT(m_pTrakAtom);
+
+ if (m_pRtpMapProperty == NULL) {
+ m_pTrakAtom->FindProperty(
+ "trak.udta.hinf.payt.rtpMap",
+ (MP4Property**)&m_pRtpMapProperty);
+ }
+
+ if (m_pPayloadNumberProperty == NULL) {
+ m_pTrakAtom->FindProperty(
+ "trak.udta.hinf.payt.payloadNumber",
+ (MP4Property**)&m_pPayloadNumberProperty);
+ }
+
+ if (m_pMaxPacketSizeProperty == NULL) {
+ m_pTrakAtom->FindProperty(
+ "trak.mdia.minf.stbl.stsd.rtp .maxPacketSize",
+ (MP4Property**)&m_pMaxPacketSizeProperty);
+ }
+}
+
+void MP4RtpHintTrack::GetPayload(
+ char** ppPayloadName,
+ u_int8_t* pPayloadNumber,
+ u_int16_t* pMaxPayloadSize,
+ char **ppEncodingParams)
+{
+ const char* pRtpMap;
+ char* pSlash;
+ u_int32_t length;
+ InitPayload();
+
+ if (ppPayloadName || ppEncodingParams) {
+ if (ppPayloadName)
+ *ppPayloadName = NULL;
+ if (ppEncodingParams)
+ *ppEncodingParams = NULL;
+ if (m_pRtpMapProperty) {
+ pRtpMap = m_pRtpMapProperty->GetValue();
+ pSlash = strchr(pRtpMap, '/');
+
+ if (pSlash) {
+ length = pSlash - pRtpMap;
+ } else {
+ length = strlen(pRtpMap);
+ }
+
+ if (ppPayloadName) {
+ *ppPayloadName = (char*)MP4Calloc(length + 1);
+ strncpy(*ppPayloadName, pRtpMap, length);
+ }
+ if (pSlash && ppEncodingParams) {
+ pSlash++;
+ pSlash = strchr(pSlash, '/');
+ if (pSlash != NULL) {
+ pSlash++;
+ if (pSlash != '\0') {
+ length = strlen(pRtpMap) - (pSlash - pRtpMap);
+ *ppEncodingParams = (char *)MP4Calloc(length + 1);
+ strncpy(*ppEncodingParams, pSlash, length);
+ }
+ }
+ }
+ }
+ }
+
+ if (pPayloadNumber) {
+ if (m_pPayloadNumberProperty) {
+ *pPayloadNumber = m_pPayloadNumberProperty->GetValue();
+ } else {
+ *pPayloadNumber = 0;
+ }
+ }
+
+ if (pMaxPayloadSize) {
+ if (m_pMaxPacketSizeProperty) {
+ *pMaxPayloadSize = m_pMaxPacketSizeProperty->GetValue();
+ } else {
+ *pMaxPayloadSize = 0;
+ }
+ }
+}
+
+void MP4RtpHintTrack::SetPayload(
+ const char* payloadName,
+ u_int8_t payloadNumber,
+ u_int16_t maxPayloadSize,
+ const char *encoding_parms,
+ bool include_rtp_map,
+ bool include_mpeg4_esid)
+{
+ InitRefTrack();
+ InitPayload();
+
+ ASSERT(m_pRtpMapProperty);
+ ASSERT(m_pPayloadNumberProperty);
+ ASSERT(m_pMaxPacketSizeProperty);
+
+ size_t len = strlen(payloadName) + 16;
+ if (encoding_parms != NULL) {
+ size_t temp = strlen(encoding_parms);
+ if (temp == 0) {
+ encoding_parms = NULL;
+ } else {
+ len += temp;
+ }
+ }
+
+ char* rtpMapBuf = (char*)MP4Malloc(len);
+ sprintf(rtpMapBuf, "%s/%u%c%s",
+ payloadName,
+ GetTimeScale(),
+ encoding_parms != NULL ? '/' : '\0',
+ encoding_parms == NULL ? "" : encoding_parms);
+ m_pRtpMapProperty->SetValue(rtpMapBuf);
+
+ m_pPayloadNumberProperty->SetValue(payloadNumber);
+
+ if (maxPayloadSize == 0) {
+ maxPayloadSize = 1460;
+ }
+ m_pMaxPacketSizeProperty->SetValue(maxPayloadSize);
+
+ // set sdp media type
+ const char* sdpMediaType;
+ if (!strcmp(m_pRefTrack->GetType(), MP4_AUDIO_TRACK_TYPE)) {
+ sdpMediaType = "audio";
+ } else if (!strcmp(m_pRefTrack->GetType(), MP4_VIDEO_TRACK_TYPE)) {
+ sdpMediaType = "video";
+ } else {
+ sdpMediaType = "application";
+ }
+
+ char* sdpBuf = (char*)MP4Malloc(
+ strlen(sdpMediaType) + strlen(rtpMapBuf) + 256);
+ uint32_t buflen;
+ buflen = sprintf(sdpBuf,
+ "m=%s 0 RTP/AVP %u\015\012"
+ "a=control:trackID=%u\015\012",
+ sdpMediaType, payloadNumber,
+ m_trackId);
+ if (include_rtp_map) {
+ buflen += sprintf(sdpBuf + buflen,
+ "a=rtpmap:%u %s\015\012",
+ payloadNumber, rtpMapBuf);
+ }
+ if (include_mpeg4_esid) {
+ sprintf(sdpBuf + buflen,
+ "a=mpeg4-esid:%u\015\012",
+ m_pRefTrack->GetId());
+ }
+
+ MP4StringProperty* pSdpProperty = NULL;
+ m_pTrakAtom->FindProperty("trak.udta.hnti.sdp .sdpText",
+ (MP4Property**)&pSdpProperty);
+ ASSERT(pSdpProperty);
+ pSdpProperty->SetValue(sdpBuf);
+
+ // cleanup
+ MP4Free(rtpMapBuf);
+ MP4Free(sdpBuf);
+}
+
+void MP4RtpHintTrack::AddHint(bool isBFrame, u_int32_t timestampOffset)
+{
+ // on first hint, need to lookup the reference track
+ if (m_writeHintId == MP4_INVALID_SAMPLE_ID) {
+ InitRefTrack();
+ InitStats();
+ }
+
+ if (m_pWriteHint) {
+ throw new MP4Error("unwritten hint is still pending", "MP4AddRtpHint");
+ }
+
+ m_pWriteHint = new MP4RtpHint(this);
+ m_pWriteHint->SetBFrame(isBFrame);
+ m_pWriteHint->SetTimestampOffset(timestampOffset);
+
+ m_bytesThisHint = 0;
+ m_writeHintId++;
+}
+
+void MP4RtpHintTrack::AddPacket(bool setMbit, int32_t transmitOffset)
+{
+ if (m_pWriteHint == NULL) {
+ throw new MP4Error("no hint pending", "MP4RtpAddPacket");
+ }
+
+ MP4RtpPacket* pPacket = m_pWriteHint->AddPacket();
+
+ ASSERT(m_pPayloadNumberProperty);
+
+ pPacket->Set(
+ m_pPayloadNumberProperty->GetValue(),
+ m_writePacketId++,
+ setMbit);
+ pPacket->SetTransmitOffset(transmitOffset);
+
+ m_bytesThisHint += 12;
+ if (m_bytesThisPacket > m_pPmax->GetValue()) {
+ m_pPmax->SetValue(m_bytesThisPacket);
+ }
+ m_bytesThisPacket = 12;
+ m_pNump->IncrementValue();
+ m_pTrpy->IncrementValue(12); // RTP packet header size
+}
+
+void MP4RtpHintTrack::AddImmediateData(
+ const u_int8_t* pBytes,
+ u_int32_t numBytes)
+{
+ if (m_pWriteHint == NULL) {
+ throw new MP4Error("no hint pending", "MP4RtpAddImmediateData");
+ }
+
+ MP4RtpPacket* pPacket = m_pWriteHint->GetCurrentPacket();
+ if (pPacket == NULL) {
+ throw new MP4Error("no packet pending", "MP4RtpAddImmediateData");
+ }
+
+ if (pBytes == NULL || numBytes == 0) {
+ throw new MP4Error("no data",
+ "AddImmediateData");
+ }
+ if (numBytes > 14) {
+ throw new MP4Error("data size is larger than 14 bytes",
+ "AddImmediateData");
+ }
+
+ MP4RtpImmediateData* pData = new MP4RtpImmediateData(pPacket);
+ pData->Set(pBytes, numBytes);
+
+ pPacket->AddData(pData);
+
+ m_bytesThisHint += numBytes;
+ m_bytesThisPacket += numBytes;
+ m_pDimm->IncrementValue(numBytes);
+ m_pTpyl->IncrementValue(numBytes);
+ m_pTrpy->IncrementValue(numBytes);
+}
+
+void MP4RtpHintTrack::AddSampleData(
+ MP4SampleId sampleId,
+ u_int32_t dataOffset,
+ u_int32_t dataLength)
+{
+ if (m_pWriteHint == NULL) {
+ throw new MP4Error("no hint pending", "MP4RtpAddSampleData");
+ }
+
+ MP4RtpPacket* pPacket = m_pWriteHint->GetCurrentPacket();
+ if (pPacket == NULL) {
+ throw new MP4Error("no packet pending", "MP4RtpAddSampleData");
+ }
+
+ MP4RtpSampleData* pData = new MP4RtpSampleData(pPacket);
+
+ pData->SetReferenceSample(sampleId, dataOffset, dataLength);
+
+ pPacket->AddData(pData);
+
+ m_bytesThisHint += dataLength;
+ m_bytesThisPacket += dataLength;
+ m_pDmed->IncrementValue(dataLength);
+ m_pTpyl->IncrementValue(dataLength);
+ m_pTrpy->IncrementValue(dataLength);
+}
+
+void MP4RtpHintTrack::AddESConfigurationPacket()
+{
+ if (m_pWriteHint == NULL) {
+ throw new MP4Error("no hint pending",
+ "MP4RtpAddESConfigurationPacket");
+ }
+
+ u_int8_t* pConfig = NULL;
+ u_int32_t configSize = 0;
+
+ m_pFile->GetTrackESConfiguration(m_pRefTrack->GetId(),
+ &pConfig, &configSize);
+
+ if (pConfig == NULL) {
+ return;
+ }
+
+ ASSERT(m_pMaxPacketSizeProperty);
+
+ if (configSize > m_pMaxPacketSizeProperty->GetValue()) {
+ throw new MP4Error("ES configuration is too large for RTP payload",
+ "MP4RtpAddESConfigurationPacket");
+ }
+
+ AddPacket(false);
+
+ MP4RtpPacket* pPacket = m_pWriteHint->GetCurrentPacket();
+ ASSERT(pPacket);
+
+ // This is ugly!
+ // To get the ES configuration data somewhere known
+ // we create a sample data reference that points to
+ // this hint track (not the media track)
+ // and this sample of the hint track
+ // the offset into this sample is filled in during the write process
+ MP4RtpSampleData* pData = new MP4RtpSampleData(pPacket);
+
+ pData->SetEmbeddedImmediate(m_writeSampleId, pConfig, configSize);
+
+ pPacket->AddData(pData);
+
+ m_bytesThisHint += configSize;
+ m_bytesThisPacket += configSize;
+ m_pTpyl->IncrementValue(configSize);
+ m_pTrpy->IncrementValue(configSize);
+}
+
+void MP4RtpHintTrack::WriteHint(MP4Duration duration, bool isSyncSample)
+{
+ if (m_pWriteHint == NULL) {
+ throw new MP4Error("no hint pending", "MP4WriteRtpHint");
+ }
+
+ u_int8_t* pBytes;
+ u_int64_t numBytes;
+
+ m_pFile->EnableMemoryBuffer();
+
+ m_pWriteHint->Write(m_pFile);
+
+ m_pFile->DisableMemoryBuffer(&pBytes, &numBytes);
+
+ WriteSample(pBytes, numBytes, duration, 0, isSyncSample);
+
+ MP4Free(pBytes);
+
+ // update statistics
+ if (m_bytesThisPacket > m_pPmax->GetValue()) {
+ m_pPmax->SetValue(m_bytesThisPacket);
+ }
+
+ if (duration > m_pDmax->GetValue()) {
+ m_pDmax->SetValue(duration);
+ }
+
+ MP4Timestamp startTime;
+
+ GetSampleTimes(m_writeHintId, &startTime, NULL);
+
+ if (startTime < m_thisSec + GetTimeScale()) {
+ m_bytesThisSec += m_bytesThisHint;
+ } else {
+ if (m_bytesThisSec > m_pMaxr->GetValue()) {
+ m_pMaxr->SetValue(m_bytesThisSec);
+ }
+ m_thisSec = startTime - (startTime % GetTimeScale());
+ m_bytesThisSec = m_bytesThisHint;
+ }
+
+ // cleanup
+ delete m_pWriteHint;
+ m_pWriteHint = NULL;
+}
+
+void MP4RtpHintTrack::FinishWrite()
+{
+ if (m_writeHintId != MP4_INVALID_SAMPLE_ID) {
+ m_pMaxPdu->SetValue(m_pPmax->GetValue());
+ if (m_pNump->GetValue()) {
+ m_pAvgPdu->SetValue(m_pTrpy->GetValue() / m_pNump->GetValue());
+ }
+
+ m_pMaxBitRate->SetValue(m_pMaxr->GetValue() * 8);
+ if (GetDuration()) {
+ m_pAvgBitRate->SetValue(
+ m_pTrpy->GetValue() * 8 * GetTimeScale() / GetDuration());
+ }
+ }
+
+ MP4Track::FinishWrite();
+}
+
+void MP4RtpHintTrack::InitStats()
+{
+ MP4Atom* pHinfAtom = m_pTrakAtom->FindAtom("trak.udta.hinf");
+
+ ASSERT(pHinfAtom);
+
+ pHinfAtom->FindProperty("hinf.trpy.bytes", (MP4Property**)&m_pTrpy);
+ pHinfAtom->FindProperty("hinf.nump.packets", (MP4Property**)&m_pNump);
+ pHinfAtom->FindProperty("hinf.tpyl.bytes", (MP4Property**)&m_pTpyl);
+ pHinfAtom->FindProperty("hinf.maxr.bytes", (MP4Property**)&m_pMaxr);
+ pHinfAtom->FindProperty("hinf.dmed.bytes", (MP4Property**)&m_pDmed);
+ pHinfAtom->FindProperty("hinf.dimm.bytes", (MP4Property**)&m_pDimm);
+ pHinfAtom->FindProperty("hinf.pmax.bytes", (MP4Property**)&m_pPmax);
+ pHinfAtom->FindProperty("hinf.dmax.milliSecs", (MP4Property**)&m_pDmax);
+
+ MP4Atom* pHmhdAtom = m_pTrakAtom->FindAtom("trak.mdia.minf.hmhd");
+
+ ASSERT(pHmhdAtom);
+
+ pHmhdAtom->FindProperty("hmhd.maxPduSize", (MP4Property**)&m_pMaxPdu);
+ pHmhdAtom->FindProperty("hmhd.avgPduSize", (MP4Property**)&m_pAvgPdu);
+ pHmhdAtom->FindProperty("hmhd.maxBitRate", (MP4Property**)&m_pMaxBitRate);
+ pHmhdAtom->FindProperty("hmhd.avgBitRate", (MP4Property**)&m_pAvgBitRate);
+
+ MP4Integer32Property* pMaxrPeriod = NULL;
+ pHinfAtom->FindProperty("hinf.maxr.granularity",
+ (MP4Property**)&pMaxrPeriod);
+ if (pMaxrPeriod) {
+ pMaxrPeriod->SetValue(1000); // 1 second
+ }
+}
+
+
+MP4RtpHint::MP4RtpHint(MP4RtpHintTrack* pTrack)
+{
+ m_pTrack = pTrack;
+
+ AddProperty( /* 0 */
+ new MP4Integer16Property("packetCount"));
+ AddProperty( /* 1 */
+ new MP4Integer16Property("reserved"));
+}
+
+MP4RtpHint::~MP4RtpHint()
+{
+ for (u_int32_t i = 0; i < m_rtpPackets.Size(); i++) {
+ delete m_rtpPackets[i];
+ }
+}
+
+MP4RtpPacket* MP4RtpHint::AddPacket()
+{
+ MP4RtpPacket* pPacket = new MP4RtpPacket(this);
+ m_rtpPackets.Add(pPacket);
+
+ // packetCount property
+ ((MP4Integer16Property*)m_pProperties[0])->IncrementValue();
+
+ pPacket->SetBFrame(m_isBFrame);
+ pPacket->SetTimestampOffset(m_timestampOffset);
+
+ return pPacket;
+}
+
+void MP4RtpHint::Read(MP4File* pFile)
+{
+ // call base class Read for required properties
+ MP4Container::Read(pFile);
+
+ u_int16_t numPackets =
+ ((MP4Integer16Property*)m_pProperties[0])->GetValue();
+
+ for (u_int16_t i = 0; i < numPackets; i++) {
+ MP4RtpPacket* pPacket = new MP4RtpPacket(this);
+
+ m_rtpPackets.Add(pPacket);
+
+ pPacket->Read(pFile);
+ }
+
+ VERBOSE_READ_HINT(pFile->GetVerbosity(),
+ printf("ReadHint:\n"); Dump(stdout, 10, false););
+}
+
+void MP4RtpHint::Write(MP4File* pFile)
+{
+ u_int64_t hintStartPos = pFile->GetPosition();
+
+ MP4Container::Write(pFile);
+
+ u_int64_t packetStartPos = pFile->GetPosition();
+
+ u_int32_t i;
+
+ // first write out packet (and data) entries
+ for (i = 0; i < m_rtpPackets.Size(); i++) {
+ m_rtpPackets[i]->Write(pFile);
+ }
+
+ // now let packets write their extra data into the hint sample
+ for (i = 0; i < m_rtpPackets.Size(); i++) {
+ m_rtpPackets[i]->WriteEmbeddedData(pFile, hintStartPos);
+ }
+
+ u_int64_t endPos = pFile->GetPosition();
+
+ pFile->SetPosition(packetStartPos);
+
+ // finally rewrite the packet and data entries
+ // which now contain the correct offsets for the embedded data
+ for (i = 0; i < m_rtpPackets.Size(); i++) {
+ m_rtpPackets[i]->Write(pFile);
+ }
+
+ pFile->SetPosition(endPos);
+
+ VERBOSE_WRITE_HINT(pFile->GetVerbosity(),
+ printf("WriteRtpHint:\n"); Dump(stdout, 14, false));
+}
+
+void MP4RtpHint::Dump(FILE* pFile, u_int8_t indent, bool dumpImplicits)
+{
+ MP4Container::Dump(pFile, indent, dumpImplicits);
+
+ for (u_int32_t i = 0; i < m_rtpPackets.Size(); i++) {
+ Indent(pFile, indent);
+ fprintf(pFile, "RtpPacket: %u\n", i);
+ m_rtpPackets[i]->Dump(pFile, indent + 1, dumpImplicits);
+ }
+}
+
+MP4RtpPacket::MP4RtpPacket(MP4RtpHint* pHint)
+{
+ m_pHint = pHint;
+
+ AddProperty( /* 0 */
+ new MP4Integer32Property("relativeXmitTime"));
+ AddProperty( /* 1 */
+ new MP4BitfieldProperty("reserved1", 2));
+ AddProperty( /* 2 */
+ new MP4BitfieldProperty("Pbit", 1));
+ AddProperty( /* 3 */
+ new MP4BitfieldProperty("Xbit", 1));
+ AddProperty( /* 4 */
+ new MP4BitfieldProperty("reserved2", 4));
+ AddProperty( /* 5 */
+ new MP4BitfieldProperty("Mbit", 1));
+ AddProperty( /* 6 */
+ new MP4BitfieldProperty("payloadType", 7));
+ AddProperty( /* 7 */
+ new MP4Integer16Property("sequenceNumber"));
+ AddProperty( /* 8 */
+ new MP4BitfieldProperty("reserved3", 13));
+ AddProperty( /* 9 */
+ new MP4BitfieldProperty("extraFlag", 1));
+ AddProperty( /* 10 */
+ new MP4BitfieldProperty("bFrameFlag", 1));
+ AddProperty( /* 11 */
+ new MP4BitfieldProperty("repeatFlag", 1));
+ AddProperty( /* 12 */
+ new MP4Integer16Property("entryCount"));
+}
+
+MP4RtpPacket::~MP4RtpPacket()
+{
+ for (u_int32_t i = 0; i < m_rtpData.Size(); i++) {
+ delete m_rtpData[i];
+ }
+}
+
+void MP4RtpPacket::AddExtraProperties()
+{
+ AddProperty( /* 13 */
+ new MP4Integer32Property("extraInformationLength"));
+
+ // This is a bit of a hack, since the tlv entries are really defined
+ // as atoms but there is only one type defined now, rtpo, and getting
+ // our atom code hooked up here would be a major pain with little gain
+
+ AddProperty( /* 14 */
+ new MP4Integer32Property("tlvLength"));
+ AddProperty( /* 15 */
+ new MP4StringProperty("tlvType"));
+ AddProperty( /* 16 */
+ new MP4Integer32Property("timestampOffset"));
+
+ ((MP4Integer32Property*)m_pProperties[13])->SetValue(16);
+ ((MP4Integer32Property*)m_pProperties[14])->SetValue(12);
+ ((MP4StringProperty*)m_pProperties[15])->SetFixedLength(4);
+ ((MP4StringProperty*)m_pProperties[15])->SetValue("rtpo");
+}
+
+void MP4RtpPacket::Read(MP4File* pFile)
+{
+ // call base class Read for required properties
+ MP4Container::Read(pFile);
+
+ // read extra info if present
+ // we only support the rtpo field!
+ if (((MP4BitfieldProperty*)m_pProperties[9])->GetValue() == 1) {
+ ReadExtra(pFile);
+ }
+
+ u_int16_t numDataEntries =
+ ((MP4Integer16Property*)m_pProperties[12])->GetValue();
+
+ // read data entries
+ for (u_int16_t i = 0; i < numDataEntries; i++) {
+ u_int8_t dataType;
+ pFile->PeekBytes(&dataType, 1);
+
+ MP4RtpData* pData;
+
+ switch (dataType) {
+ case 0:
+ pData = new MP4RtpNullData(this);
+ break;
+ case 1:
+ pData = new MP4RtpImmediateData(this);
+ break;
+ case 2:
+ pData = new MP4RtpSampleData(this);
+ break;
+ case 3:
+ pData = new MP4RtpSampleDescriptionData(this);
+ break;
+ default:
+ throw new MP4Error("unknown packet data entry type",
+ "MP4ReadHint");
+ }
+
+ m_rtpData.Add(pData);
+
+ // read data entry's properties
+ pData->Read(pFile);
+ }
+}
+
+void MP4RtpPacket::ReadExtra(MP4File* pFile)
+{
+ AddExtraProperties();
+
+ int32_t extraLength = (int32_t)pFile->ReadUInt32();
+
+ if (extraLength < 4) {
+ throw new MP4Error("bad packet extra info length",
+ "MP4RtpPacket::ReadExtra");
+ }
+ extraLength -= 4;
+
+ while (extraLength > 0) {
+ u_int32_t entryLength = pFile->ReadUInt32();
+ u_int32_t entryTag = pFile->ReadUInt32();
+
+ if (entryLength < 8) {
+ throw new MP4Error("bad packet extra info entry length",
+ "MP4RtpPacket::ReadExtra");
+ }
+
+ if (entryTag == STRTOINT32("rtpo") && entryLength == 12) {
+ // read the rtp timestamp offset
+ m_pProperties[16]->Read(pFile);
+ } else {
+ // ignore it, LATER carry it along
+ pFile->SetPosition(pFile->GetPosition() + entryLength - 8);
+ }
+
+ extraLength -= entryLength;
+ }
+
+ if (extraLength < 0) {
+ throw new MP4Error("invalid packet extra info length",
+ "MP4RtpPacket::ReadExtra");
+ }
+}
+
+void MP4RtpPacket::Set(u_int8_t payloadNumber,
+ u_int32_t packetId, bool setMbit)
+{
+ ((MP4BitfieldProperty*)m_pProperties[5])->SetValue(setMbit);
+ ((MP4BitfieldProperty*)m_pProperties[6])->SetValue(payloadNumber);
+ ((MP4Integer16Property*)m_pProperties[7])->SetValue(packetId);
+}
+
+int32_t MP4RtpPacket::GetTransmitOffset()
+{
+ return ((MP4Integer32Property*)m_pProperties[0])->GetValue();
+}
+
+void MP4RtpPacket::SetTransmitOffset(int32_t transmitOffset)
+{
+ ((MP4Integer32Property*)m_pProperties[0])->SetValue(transmitOffset);
+}
+
+bool MP4RtpPacket::GetPBit()
+{
+ return ((MP4BitfieldProperty*)m_pProperties[2])->GetValue();
+}
+
+bool MP4RtpPacket::GetXBit()
+{
+ return ((MP4BitfieldProperty*)m_pProperties[3])->GetValue();
+}
+
+bool MP4RtpPacket::GetMBit()
+{
+ return ((MP4BitfieldProperty*)m_pProperties[5])->GetValue();
+}
+
+u_int8_t MP4RtpPacket::GetPayload()
+{
+ return ((MP4BitfieldProperty*)m_pProperties[6])->GetValue();
+}
+
+u_int16_t MP4RtpPacket::GetSequenceNumber()
+{
+ return ((MP4Integer16Property*)m_pProperties[7])->GetValue();
+}
+
+bool MP4RtpPacket::IsBFrame()
+{
+ return ((MP4BitfieldProperty*)m_pProperties[10])->GetValue();
+}
+
+void MP4RtpPacket::SetBFrame(bool isBFrame)
+{
+ ((MP4BitfieldProperty*)m_pProperties[10])->SetValue(isBFrame);
+}
+
+void MP4RtpPacket::SetTimestampOffset(u_int32_t timestampOffset)
+{
+ if (timestampOffset == 0) {
+ return;
+ }
+
+ ASSERT(((MP4BitfieldProperty*)m_pProperties[9])->GetValue() == 0);
+
+ // set X bit
+ ((MP4BitfieldProperty*)m_pProperties[9])->SetValue(1);
+
+ AddExtraProperties();
+
+ ((MP4Integer32Property*)m_pProperties[16])->SetValue(timestampOffset);
+}
+
+void MP4RtpPacket::AddData(MP4RtpData* pData)
+{
+ m_rtpData.Add(pData);
+
+ // increment entry count property
+ ((MP4Integer16Property*)m_pProperties[12])->IncrementValue();
+}
+
+u_int32_t MP4RtpPacket::GetDataSize()
+{
+ u_int32_t totalDataSize = 0;
+
+ for (u_int32_t i = 0; i < m_rtpData.Size(); i++) {
+ totalDataSize += m_rtpData[i]->GetDataSize();
+ }
+
+ return totalDataSize;
+}
+
+void MP4RtpPacket::GetData(u_int8_t* pDest)
+{
+ for (u_int32_t i = 0; i < m_rtpData.Size(); i++) {
+ m_rtpData[i]->GetData(pDest);
+ pDest += m_rtpData[i]->GetDataSize();
+ }
+}
+
+void MP4RtpPacket::Write(MP4File* pFile)
+{
+ MP4Container::Write(pFile);
+
+ for (u_int32_t i = 0; i < m_rtpData.Size(); i++) {
+ m_rtpData[i]->Write(pFile);
+ }
+}
+
+void MP4RtpPacket::WriteEmbeddedData(MP4File* pFile, u_int64_t startPos)
+{
+ for (u_int32_t i = 0; i < m_rtpData.Size(); i++) {
+ m_rtpData[i]->WriteEmbeddedData(pFile, startPos);
+ }
+}
+
+void MP4RtpPacket::Dump(FILE* pFile, u_int8_t indent, bool dumpImplicits)
+{
+ MP4Container::Dump(pFile, indent, dumpImplicits);
+
+ for (u_int32_t i = 0; i < m_rtpData.Size(); i++) {
+ Indent(pFile, indent);
+ fprintf(pFile, "RtpData: %u\n", i);
+ m_rtpData[i]->Dump(pFile, indent + 1, dumpImplicits);
+ }
+}
+
+MP4RtpData::MP4RtpData(MP4RtpPacket* pPacket)
+{
+ m_pPacket = pPacket;
+
+ AddProperty( /* 0 */
+ new MP4Integer8Property("type"));
+}
+
+MP4Track* MP4RtpData::FindTrackFromRefIndex(u_int8_t refIndex)
+{
+ MP4Track* pTrack;
+
+ if (refIndex == (u_int8_t)-1) {
+ // ourselves
+ pTrack = GetPacket()->GetHint()->GetTrack();
+ } else if (refIndex == 0) {
+ // our reference track
+ pTrack = GetPacket()->GetHint()->GetTrack()->GetRefTrack();
+ } else {
+ // some other track
+ MP4RtpHintTrack* pHintTrack =
+ GetPacket()->GetHint()->GetTrack();
+
+ MP4Atom* pTrakAtom = pHintTrack->GetTrakAtom();
+ ASSERT(pTrakAtom);
+
+ MP4Integer32Property* pTrackIdProperty = NULL;
+ pTrakAtom->FindProperty(
+ "trak.tref.hint.entries",
+ (MP4Property**)&pTrackIdProperty);
+ ASSERT(pTrackIdProperty);
+
+ u_int32_t refTrackId =
+ pTrackIdProperty->GetValue(refIndex - 1);
+
+ pTrack = pHintTrack->GetFile()->GetTrack(refTrackId);
+ }
+
+ return pTrack;
+}
+
+MP4RtpNullData::MP4RtpNullData(MP4RtpPacket* pPacket)
+ : MP4RtpData(pPacket)
+{
+ ((MP4Integer8Property*)m_pProperties[0])->SetValue(0);
+
+ AddProperty( /* 1 */
+ new MP4BytesProperty("pad", 15));
+
+ ((MP4BytesProperty*)m_pProperties[1])->SetFixedSize(15);
+}
+
+MP4RtpImmediateData::MP4RtpImmediateData(MP4RtpPacket* pPacket)
+ : MP4RtpData(pPacket)
+{
+ ((MP4Integer8Property*)m_pProperties[0])->SetValue(1);
+
+ AddProperty( /* 1 */
+ new MP4Integer8Property("count"));
+ AddProperty( /* 2 */
+ new MP4BytesProperty("data", 14));
+
+ ((MP4BytesProperty*)m_pProperties[2])->SetFixedSize(14);
+}
+
+void MP4RtpImmediateData::Set(const u_int8_t* pBytes, u_int8_t numBytes)
+{
+ ((MP4Integer8Property*)m_pProperties[1])->SetValue(numBytes);
+ ((MP4BytesProperty*)m_pProperties[2])->SetValue(pBytes, numBytes);
+}
+
+u_int16_t MP4RtpImmediateData::GetDataSize()
+{
+ return ((MP4Integer8Property*)m_pProperties[1])->GetValue();
+}
+
+void MP4RtpImmediateData::GetData(u_int8_t* pDest)
+{
+ u_int8_t* pValue;
+ u_int32_t valueSize;
+ ((MP4BytesProperty*)m_pProperties[2])->GetValue(&pValue, &valueSize);
+
+ memcpy(pDest, pValue, GetDataSize());
+ MP4Free(pValue);
+}
+
+MP4RtpSampleData::MP4RtpSampleData(MP4RtpPacket* pPacket)
+ : MP4RtpData(pPacket)
+{
+ ((MP4Integer8Property*)m_pProperties[0])->SetValue(2);
+
+ AddProperty( /* 1 */
+ new MP4Integer8Property("trackRefIndex"));
+ AddProperty( /* 2 */
+ new MP4Integer16Property("length"));
+ AddProperty( /* 3 */
+ new MP4Integer32Property("sampleNumber"));
+ AddProperty( /* 4 */
+ new MP4Integer32Property("sampleOffset"));
+ AddProperty( /* 5 */
+ new MP4Integer16Property("bytesPerBlock"));
+ AddProperty( /* 6 */
+ new MP4Integer16Property("samplesPerBlock"));
+
+ ((MP4Integer16Property*)m_pProperties[5])->SetValue(1);
+ ((MP4Integer16Property*)m_pProperties[6])->SetValue(1);
+
+ m_pRefData = NULL;
+ m_pRefTrack = NULL;
+ m_refSampleId = MP4_INVALID_SAMPLE_ID;
+ m_refSampleOffset = 0;
+}
+
+void MP4RtpSampleData::SetEmbeddedImmediate(MP4SampleId sampleId,
+ u_int8_t* pData, u_int16_t dataLength)
+{
+ ((MP4Integer8Property*)m_pProperties[1])->SetValue((u_int8_t)-1);
+ ((MP4Integer16Property*)m_pProperties[2])->SetValue(dataLength);
+ ((MP4Integer32Property*)m_pProperties[3])->SetValue(sampleId);
+ ((MP4Integer32Property*)m_pProperties[4])->SetValue(0);
+ CHECK_AND_FREE(m_pRefData);
+ m_pRefData = pData;
+}
+
+void MP4RtpSampleData::SetReferenceSample(
+ MP4SampleId refSampleId, u_int32_t refSampleOffset,
+ u_int16_t sampleLength)
+{
+ ((MP4Integer8Property*)m_pProperties[1])->SetValue(0);
+ ((MP4Integer16Property*)m_pProperties[2])->SetValue(sampleLength);
+ ((MP4Integer32Property*)m_pProperties[3])->SetValue(refSampleId);
+ ((MP4Integer32Property*)m_pProperties[4])->SetValue(refSampleOffset);
+}
+
+void MP4RtpSampleData::SetEmbeddedSample(
+ MP4SampleId sampleId, MP4Track* pRefTrack,
+ MP4SampleId refSampleId, u_int32_t refSampleOffset,
+ u_int16_t sampleLength)
+{
+ ((MP4Integer8Property*)m_pProperties[1])->SetValue((u_int8_t)-1);
+ ((MP4Integer16Property*)m_pProperties[2])->SetValue(sampleLength);
+ ((MP4Integer32Property*)m_pProperties[3])->SetValue(sampleId);
+ ((MP4Integer32Property*)m_pProperties[4])->SetValue(0);
+ m_pRefTrack = pRefTrack;
+ m_refSampleId = refSampleId;
+ m_refSampleOffset = refSampleOffset;
+}
+
+u_int16_t MP4RtpSampleData::GetDataSize()
+{
+ return ((MP4Integer16Property*)m_pProperties[2])->GetValue();
+}
+
+void MP4RtpSampleData::GetData(u_int8_t* pDest)
+{
+ u_int8_t trackRefIndex =
+ ((MP4Integer8Property*)m_pProperties[1])->GetValue();
+
+ MP4Track* pSampleTrack =
+ FindTrackFromRefIndex(trackRefIndex);
+
+ pSampleTrack->ReadSampleFragment(
+ ((MP4Integer32Property*)m_pProperties[3])->GetValue(), // sampleId
+ ((MP4Integer32Property*)m_pProperties[4])->GetValue(), // sampleOffset
+ ((MP4Integer16Property*)m_pProperties[2])->GetValue(), // sampleLength
+ pDest);
+}
+
+void MP4RtpSampleData::WriteEmbeddedData(MP4File* pFile, u_int64_t startPos)
+{
+ // if not using embedded data, nothing to do
+ if (((MP4Integer8Property*)m_pProperties[1])->GetValue() != (u_int8_t)-1) {
+ return;
+ }
+
+ // figure out the offset within this hint sample for this embedded data
+ u_int64_t offset = pFile->GetPosition() - startPos;
+ ASSERT(offset <= 0xFFFFFFFF);
+ ((MP4Integer32Property*)m_pProperties[4])->SetValue((u_int32_t)offset);
+
+ u_int16_t length = ((MP4Integer16Property*)m_pProperties[2])->GetValue();
+
+ if (m_pRefData) {
+ pFile->WriteBytes(m_pRefData, length);
+ return;
+ }
+
+ if (m_refSampleId != MP4_INVALID_SAMPLE_ID) {
+ u_int8_t* pSample = NULL;
+ u_int32_t sampleSize = 0;
+
+ ASSERT(m_pRefTrack);
+ m_pRefTrack->ReadSample(m_refSampleId, &pSample, &sampleSize);
+
+ ASSERT(m_refSampleOffset + length <= sampleSize);
+
+ pFile->WriteBytes(&pSample[m_refSampleOffset], length);
+
+ MP4Free(pSample);
+ return;
+ }
+}
+
+MP4RtpSampleDescriptionData::MP4RtpSampleDescriptionData(MP4RtpPacket* pPacket)
+ : MP4RtpData(pPacket)
+{
+ ((MP4Integer8Property*)m_pProperties[0])->SetValue(3);
+
+ AddProperty( /* 1 */
+ new MP4Integer8Property("trackRefIndex"));
+ AddProperty( /* 2 */
+ new MP4Integer16Property("length"));
+ AddProperty( /* 3 */
+ new MP4Integer32Property("sampleDescriptionIndex"));
+ AddProperty( /* 4 */
+ new MP4Integer32Property("sampleDescriptionOffset"));
+ AddProperty( /* 5 */
+ new MP4Integer32Property("reserved"));
+}
+
+void MP4RtpSampleDescriptionData::Set(u_int32_t sampleDescrIndex,
+ u_int32_t offset, u_int16_t length)
+{
+ ((MP4Integer16Property*)m_pProperties[2])->SetValue(length);
+ ((MP4Integer32Property*)m_pProperties[3])->SetValue(sampleDescrIndex);
+ ((MP4Integer32Property*)m_pProperties[4])->SetValue(offset);
+}
+
+u_int16_t MP4RtpSampleDescriptionData::GetDataSize()
+{
+ return ((MP4Integer16Property*)m_pProperties[2])->GetValue();
+}
+
+void MP4RtpSampleDescriptionData::GetData(u_int8_t* pDest)
+{
+ // we start with the index into our track references
+ u_int8_t trackRefIndex =
+ ((MP4Integer8Property*)m_pProperties[1])->GetValue();
+
+ // from which we can find the track structure
+ MP4Track* pSampleTrack =
+ FindTrackFromRefIndex(trackRefIndex);
+
+ // next find the desired atom in the track's sample description table
+ u_int32_t sampleDescrIndex =
+ ((MP4Integer32Property*)m_pProperties[3])->GetValue();
+
+ MP4Atom* pTrakAtom =
+ pSampleTrack->GetTrakAtom();
+
+ char sdName[64];
+ sprintf(sdName, "trak.mdia.minf.stbl.stsd.*[%u]", sampleDescrIndex);
+
+ MP4Atom* pSdAtom =
+ pTrakAtom->FindAtom(sdName);
+
+ // bad reference
+ if (pSdAtom == NULL) {
+ throw new MP4Error("invalid sample description index",
+ "MP4RtpSampleDescriptionData::GetData");
+ }
+
+ // check validity of the upcoming copy
+ u_int16_t length =
+ ((MP4Integer16Property*)m_pProperties[2])->GetValue();
+ u_int32_t offset =
+ ((MP4Integer32Property*)m_pProperties[4])->GetValue();
+
+ if (offset + length > pSdAtom->GetSize()) {
+ throw new MP4Error("offset and/or length are too large",
+ "MP4RtpSampleDescriptionData::GetData");
+ }
+
+ // now we use the raw file to get the desired bytes
+
+ MP4File* pFile = GetPacket()->GetHint()->GetTrack()->GetFile();
+
+ u_int64_t orgPos = pFile->GetPosition();
+
+ // It's not entirely clear from the spec whether the offset is from
+ // the start of the sample descirption atom, or the start of the atom's
+ // data. I believe it is the former, but the commented out code will
+ // realize the latter interpretation if I turn out to be wrong.
+ u_int64_t dataPos = pSdAtom->GetStart();
+ //u_int64_t dataPos = pSdAtom->GetEnd() - pSdAtom->GetSize();
+
+ pFile->SetPosition(dataPos + offset);
+
+ pFile->ReadBytes(pDest, length);
+
+ pFile->SetPosition(orgPos);
+}
+
--- /dev/null
+++ b/common/mp4v2/rtphint.h
@@ -1,0 +1,352 @@
+/*
+ * 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
+ */
+
+#ifndef __RTPHINT_INCLUDED__
+#define __RTPHINT_INCLUDED__
+
+// forward declarations
+class MP4RtpHintTrack;
+class MP4RtpHint;
+class MP4RtpPacket;
+
+class MP4RtpData : public MP4Container {
+public:
+ MP4RtpData(MP4RtpPacket* pPacket);
+
+ MP4RtpPacket* GetPacket() {
+ return m_pPacket;
+ }
+
+ virtual u_int16_t GetDataSize() = 0;
+ virtual void GetData(u_int8_t* pDest) = 0;
+
+ MP4Track* FindTrackFromRefIndex(u_int8_t refIndex);
+
+ virtual void WriteEmbeddedData(MP4File* pFile, u_int64_t startPos) {
+ // default is no-op
+ }
+
+protected:
+ MP4RtpPacket* m_pPacket;
+};
+
+MP4ARRAY_DECL(MP4RtpData, MP4RtpData*)
+
+class MP4RtpNullData : public MP4RtpData {
+public:
+ MP4RtpNullData(MP4RtpPacket* pPacket);
+
+ u_int16_t GetDataSize() {
+ return 0;
+ }
+
+ void GetData(u_int8_t* pDest) {
+ // no-op
+ }
+};
+
+class MP4RtpImmediateData : public MP4RtpData {
+public:
+ MP4RtpImmediateData(MP4RtpPacket* pPacket);
+
+ void Set(const u_int8_t* pBytes, u_int8_t numBytes);
+
+ u_int16_t GetDataSize();
+
+ void GetData(u_int8_t* pDest);
+};
+
+class MP4RtpSampleData : public MP4RtpData {
+public:
+ MP4RtpSampleData(MP4RtpPacket* pPacket);
+
+ ~MP4RtpSampleData(void) {
+ CHECK_AND_FREE(m_pRefData);
+ };
+
+ void SetEmbeddedImmediate(
+ MP4SampleId sampleId,
+ u_int8_t* pData, u_int16_t dataLength);
+
+ void SetReferenceSample(
+ MP4SampleId refSampleId, u_int32_t refSampleOffset,
+ u_int16_t sampleLength);
+
+ void SetEmbeddedSample(
+ MP4SampleId sampleId, MP4Track* pRefTrack,
+ MP4SampleId refSampleId, u_int32_t refSampleOffset,
+ u_int16_t sampleLength);
+
+ u_int16_t GetDataSize();
+
+ void GetData(u_int8_t* pDest);
+
+ void WriteEmbeddedData(MP4File* pFile, u_int64_t startPos);
+
+protected:
+ u_int8_t* m_pRefData;
+
+ MP4Track* m_pRefTrack;
+ MP4SampleId m_refSampleId;
+ u_int32_t m_refSampleOffset;
+};
+
+class MP4RtpSampleDescriptionData : public MP4RtpData {
+public:
+ MP4RtpSampleDescriptionData(MP4RtpPacket* pPacket);
+
+ void Set(u_int32_t sampleDescrIndex,
+ u_int32_t offset, u_int16_t length);
+
+ u_int16_t GetDataSize();
+
+ void GetData(u_int8_t* pDest);
+};
+
+class MP4RtpPacket : public MP4Container {
+public:
+ MP4RtpPacket(MP4RtpHint* pHint);
+
+ ~MP4RtpPacket();
+
+ void AddExtraProperties();
+
+ MP4RtpHint* GetHint() {
+ return m_pHint;
+ }
+
+ void Set(u_int8_t payloadNumber, u_int32_t packetId, bool setMbit);
+
+ int32_t GetTransmitOffset();
+
+ bool GetPBit();
+
+ bool GetXBit();
+
+ bool GetMBit();
+
+ u_int8_t GetPayload();
+
+ u_int16_t GetSequenceNumber();
+
+ void SetTransmitOffset(int32_t transmitOffset);
+
+ bool IsBFrame();
+
+ void SetBFrame(bool isBFrame);
+
+ void SetTimestampOffset(u_int32_t timestampOffset);
+
+ void AddData(MP4RtpData* pData);
+
+ u_int32_t GetDataSize();
+
+ void GetData(u_int8_t* pDest);
+
+ void Read(MP4File* pFile);
+
+ void ReadExtra(MP4File* pFile);
+
+ void Write(MP4File* pFile);
+
+ void WriteEmbeddedData(MP4File* pFile, u_int64_t startPos);
+
+ void Dump(FILE* pFile, u_int8_t indent, bool dumpImplicits);
+
+protected:
+ MP4RtpHint* m_pHint;
+ MP4RtpDataArray m_rtpData;
+};
+
+MP4ARRAY_DECL(MP4RtpPacket, MP4RtpPacket*)
+
+class MP4RtpHint : public MP4Container {
+public:
+ MP4RtpHint(MP4RtpHintTrack* pTrack);
+
+ ~MP4RtpHint();
+
+ MP4RtpHintTrack* GetTrack() {
+ return m_pTrack;
+ }
+
+ u_int16_t GetNumberOfPackets() {
+ return m_rtpPackets.Size();
+ }
+
+ bool IsBFrame() {
+ return m_isBFrame;
+ }
+ void SetBFrame(bool isBFrame) {
+ m_isBFrame = isBFrame;
+ }
+
+ u_int32_t GetTimestampOffset() {
+ return m_timestampOffset;
+ }
+ void SetTimestampOffset(u_int32_t timestampOffset) {
+ m_timestampOffset = timestampOffset;
+ }
+
+ MP4RtpPacket* AddPacket();
+
+ MP4RtpPacket* GetPacket(u_int16_t index) {
+ return m_rtpPackets[index];
+ }
+
+ MP4RtpPacket* GetCurrentPacket() {
+ if (m_rtpPackets.Size() == 0) {
+ return NULL;
+ }
+ return m_rtpPackets[m_rtpPackets.Size() - 1];
+ }
+
+ void Read(MP4File* pFile);
+
+ void Write(MP4File* pFile);
+
+ void Dump(FILE* pFile, u_int8_t indent, bool dumpImplicits);
+
+protected:
+ MP4RtpHintTrack* m_pTrack;
+ MP4RtpPacketArray m_rtpPackets;
+
+ // values when adding packets to a hint (write mode)
+ bool m_isBFrame;
+ u_int32_t m_timestampOffset;
+};
+
+class MP4RtpHintTrack : public MP4Track {
+public:
+ MP4RtpHintTrack(MP4File* pFile, MP4Atom* pTrakAtom);
+
+ ~MP4RtpHintTrack();
+
+ void InitRefTrack();
+
+ void InitPayload();
+
+ void InitRtpStart();
+
+ void InitStats();
+
+ MP4Track* GetRefTrack() {
+ InitRefTrack();
+ return m_pRefTrack;
+ }
+
+ void GetPayload(
+ char** ppPayloadName = NULL,
+ u_int8_t* pPayloadNumber = NULL,
+ u_int16_t* pMaxPayloadSize = NULL,
+ char **ppEncodingParams = NULL);
+
+ void SetPayload(
+ const char* payloadName,
+ u_int8_t payloadNumber,
+ u_int16_t maxPayloadSize,
+ const char *encoding_parms,
+ bool add_rtpmap,
+ bool add_mpeg4_esid);
+
+ void ReadHint(
+ MP4SampleId hintSampleId,
+ u_int16_t* pNumPackets = NULL);
+
+ u_int16_t GetHintNumberOfPackets();
+
+ bool GetPacketBFrame(u_int16_t packetIndex);
+
+ u_int16_t GetPacketTransmitOffset(u_int16_t packetIndex);
+
+ void ReadPacket(
+ u_int16_t packetIndex,
+ u_int8_t** ppBytes,
+ u_int32_t* pNumBytes,
+ u_int32_t ssrc,
+ bool includeHeader = true,
+ bool includePayload = true);
+
+ MP4Timestamp GetRtpTimestampStart();
+
+ void SetRtpTimestampStart(MP4Timestamp start);
+
+ void AddHint(bool isBFrame, u_int32_t timestampOffset);
+
+ void AddPacket(bool setMbit, int32_t transmitOffset = 0);
+
+ void AddImmediateData(const u_int8_t* pBytes, u_int32_t numBytes);
+
+ void AddSampleData(MP4SampleId sampleId,
+ u_int32_t dataOffset, u_int32_t dataLength);
+
+ void AddESConfigurationPacket();
+
+ void WriteHint(MP4Duration duration, bool isSyncSample);
+
+ void FinishWrite();
+
+protected:
+ MP4Track* m_pRefTrack;
+
+ MP4StringProperty* m_pRtpMapProperty;
+ MP4Integer32Property* m_pPayloadNumberProperty;
+ MP4Integer32Property* m_pMaxPacketSizeProperty;
+ MP4Integer32Property* m_pSnroProperty;
+ MP4Integer32Property* m_pTsroProperty;
+ u_int32_t m_rtpSequenceStart;
+ u_int32_t m_rtpTimestampStart;
+
+ // reading
+ MP4RtpHint* m_pReadHint;
+ u_int8_t* m_pReadHintSample;
+ u_int32_t m_readHintSampleSize;
+ MP4Timestamp m_readHintTimestamp;
+
+ // writing
+ MP4RtpHint* m_pWriteHint;
+ MP4SampleId m_writeHintId;
+ u_int32_t m_writePacketId;
+
+ // statistics
+ // in trak.udta.hinf
+ MP4Integer64Property* m_pTrpy;
+ MP4Integer64Property* m_pNump;
+ MP4Integer64Property* m_pTpyl;
+ MP4Integer32Property* m_pMaxr;
+ MP4Integer64Property* m_pDmed;
+ MP4Integer64Property* m_pDimm;
+ MP4Integer32Property* m_pPmax;
+ MP4Integer32Property* m_pDmax;
+
+ // in trak.mdia.minf.hmhd
+ MP4Integer16Property* m_pMaxPdu;
+ MP4Integer16Property* m_pAvgPdu;
+ MP4Integer32Property* m_pMaxBitRate;
+ MP4Integer32Property* m_pAvgBitRate;
+
+ MP4Timestamp m_thisSec;
+ u_int32_t m_bytesThisSec;
+ u_int32_t m_bytesThisHint;
+ u_int32_t m_bytesThisPacket;
+};
+
+#endif /* __RTPHINT_INCLUDED__ */
--- a/frontend/faac.dsw
+++ b/frontend/faac.dsw
@@ -36,7 +36,7 @@
###############################################################################
-Project: "libmp4v2_st"=..\..\faad2\common\mp4v2\libmp4v2_st60.dsp - Package Owner=<4>
+Project: "libmp4v2_st"=..\common\mp4v2\libmp4v2_st60.dsp - Package Owner=<4>
Package=<5>
{{{
--- a/libfaac/libfaac.dsp
+++ b/libfaac/libfaac.dsp
@@ -40,15 +40,16 @@
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Target_Dir ""
+F90=df.exe
MTL=midl.exe
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
-# ADD CPP /nologo /G6 /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
+# ADD CPP /nologo /G6 /MD /W3 /O2 /I "..\include" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
# ADD BASE RSC /l 0x413 /d "NDEBUG"
# ADD RSC /l 0x413 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
-LIB32=xilink6.exe -lib
+LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo
@@ -64,15 +65,16 @@
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Target_Dir ""
+F90=df.exe
MTL=midl.exe
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
-# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
+# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "..\include" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
# ADD BASE RSC /l 0x413 /d "_DEBUG"
# ADD RSC /l 0x413 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
-LIB32=xilink6.exe -lib
+LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo
--
⑨