ref: f007cb73f33286454e881969a377c7f1d90201c5
parent: c7dc7254c1ecfeb2227275f56bddac4f4e822760
author: menno <menno>
date: Tue Jan 15 07:59:48 EST 2002
Added MP4 file support
--- /dev/null
+++ b/common/mp4v2/COPYING
@@ -1,0 +1,471 @@
+
+ MOZILLA PUBLIC LICENSE
+ Version 1.1
+
+ ---------------
+
+1. Definitions.
+
+ 1.0.1. "Commercial Use" means distribution or otherwise making the
+ Covered Code available to a third party.
+
+ 1.1. "Contributor" means each entity that creates or contributes to
+ the creation of Modifications.
+
+ 1.2. "Contributor Version" means the combination of the Original
+ Code, prior Modifications used by a Contributor, and the Modifications
+ made by that particular Contributor.
+
+ 1.3. "Covered Code" means the Original Code or Modifications or the
+ combination of the Original Code and Modifications, in each case
+ including portions thereof.
+
+ 1.4. "Electronic Distribution Mechanism" means a mechanism generally
+ accepted in the software development community for the electronic
+ transfer of data.
+
+ 1.5. "Executable" means Covered Code in any form other than Source
+ Code.
+
+ 1.6. "Initial Developer" means the individual or entity identified
+ as the Initial Developer in the Source Code notice required by Exhibit
+ A.
+
+ 1.7. "Larger Work" means a work which combines Covered Code or
+ portions thereof with code not governed by the terms of this License.
+
+ 1.8. "License" means this document.
+
+ 1.8.1. "Licensable" means having the right to grant, to the maximum
+ extent possible, whether at the time of the initial grant or
+ subsequently acquired, any and all of the rights conveyed herein.
+
+ 1.9. "Modifications" means any addition to or deletion from the
+ substance or structure of either the Original Code or any previous
+ Modifications. When Covered Code is released as a series of files, a
+ Modification is:
+ A. Any addition to or deletion from the contents of a file
+ containing Original Code or previous Modifications.
+
+ B. Any new file that contains any part of the Original Code or
+ previous Modifications.
+
+ 1.10. "Original Code" means Source Code of computer software code
+ which is described in the Source Code notice required by Exhibit A as
+ Original Code, and which, at the time of its release under this
+ License is not already Covered Code governed by this License.
+
+ 1.10.1. "Patent Claims" means any patent claim(s), now owned or
+ hereafter acquired, including without limitation, method, process,
+ and apparatus claims, in any patent Licensable by grantor.
+
+ 1.11. "Source Code" means the preferred form of the Covered Code for
+ making modifications to it, including all modules it contains, plus
+ any associated interface definition files, scripts used to control
+ compilation and installation of an Executable, or source code
+ differential comparisons against either the Original Code or another
+ well known, available Covered Code of the Contributor's choice. The
+ Source Code can be in a compressed or archival form, provided the
+ appropriate decompression or de-archiving software is widely available
+ for no charge.
+
+ 1.12. "You" (or "Your") means an individual or a legal entity
+ exercising rights under, and complying with all of the terms of, this
+ License or a future version of this License issued under Section 6.1.
+ For legal entities, "You" includes any entity which controls, is
+ controlled by, or is under common control with You. For purposes of
+ this definition, "control" means (a) the power, direct or indirect,
+ to cause the direction or management of such entity, whether by
+ contract or otherwise, or (b) ownership of more than fifty percent
+ (50%) of the outstanding shares or beneficial ownership of such
+ entity.
+
+2. Source Code License.
+
+ 2.1. The Initial Developer Grant.
+ The Initial Developer hereby grants You a world-wide, royalty-free,
+ non-exclusive license, subject to third party intellectual property
+ claims:
+ (a) under intellectual property rights (other than patent or
+ trademark) Licensable by Initial Developer to use, reproduce,
+ modify, display, perform, sublicense and distribute the Original
+ Code (or portions thereof) with or without Modifications, and/or
+ as part of a Larger Work; and
+
+ (b) under Patents Claims infringed by the making, using or
+ selling of Original Code, to make, have made, use, practice,
+ sell, and offer for sale, and/or otherwise dispose of the
+ Original Code (or portions thereof).
+
+ (c) the licenses granted in this Section 2.1(a) and (b) are
+ effective on the date Initial Developer first distributes
+ Original Code under the terms of this License.
+
+ (d) Notwithstanding Section 2.1(b) above, no patent license is
+ granted: 1) for code that You delete from the Original Code; 2)
+ separate from the Original Code; or 3) for infringements caused
+ by: i) the modification of the Original Code or ii) the
+ combination of the Original Code with other software or devices.
+
+ 2.2. Contributor Grant.
+ Subject to third party intellectual property claims, each Contributor
+ hereby grants You a world-wide, royalty-free, non-exclusive license
+
+ (a) under intellectual property rights (other than patent or
+ trademark) Licensable by Contributor, to use, reproduce, modify,
+ display, perform, sublicense and distribute the Modifications
+ created by such Contributor (or portions thereof) either on an
+ unmodified basis, with other Modifications, as Covered Code
+ and/or as part of a Larger Work; and
+
+ (b) under Patent Claims infringed by the making, using, or
+ selling of Modifications made by that Contributor either alone
+ and/or in combination with its Contributor Version (or portions
+ of such combination), to make, use, sell, offer for sale, have
+ made, and/or otherwise dispose of: 1) Modifications made by that
+ Contributor (or portions thereof); and 2) the combination of
+ Modifications made by that Contributor with its Contributor
+ Version (or portions of such combination).
+
+ (c) the licenses granted in Sections 2.2(a) and 2.2(b) are
+ effective on the date Contributor first makes Commercial Use of
+ the Covered Code.
+
+ (d) Notwithstanding Section 2.2(b) above, no patent license is
+ granted: 1) for any code that Contributor has deleted from the
+ Contributor Version; 2) separate from the Contributor Version;
+ 3) for infringements caused by: i) third party modifications of
+ Contributor Version or ii) the combination of Modifications made
+ by that Contributor with other software (except as part of the
+ Contributor Version) or other devices; or 4) under Patent Claims
+ infringed by Covered Code in the absence of Modifications made by
+ that Contributor.
+
+3. Distribution Obligations.
+
+ 3.1. Application of License.
+ The Modifications which You create or to which You contribute are
+ governed by the terms of this License, including without limitation
+ Section 2.2. The Source Code version of Covered Code may be
+ distributed only under the terms of this License or a future version
+ of this License released under Section 6.1, and You must include a
+ copy of this License with every copy of the Source Code You
+ distribute. You may not offer or impose any terms on any Source Code
+ version that alters or restricts the applicable version of this
+ License or the recipients' rights hereunder. However, You may include
+ an additional document offering the additional rights described in
+ Section 3.5.
+
+ 3.2. Availability of Source Code.
+ Any Modification which You create or to which You contribute must be
+ made available in Source Code form under the terms of this License
+ either on the same media as an Executable version or via an accepted
+ Electronic Distribution Mechanism to anyone to whom you made an
+ Executable version available; and if made available via Electronic
+ Distribution Mechanism, must remain available for at least twelve (12)
+ months after the date it initially became available, or at least six
+ (6) months after a subsequent version of that particular Modification
+ has been made available to such recipients. You are responsible for
+ ensuring that the Source Code version remains available even if the
+ Electronic Distribution Mechanism is maintained by a third party.
+
+ 3.3. Description of Modifications.
+ You must cause all Covered Code to which You contribute to contain a
+ file documenting the changes You made to create that Covered Code and
+ the date of any change. You must include a prominent statement that
+ the Modification is derived, directly or indirectly, from Original
+ Code provided by the Initial Developer and including the name of the
+ Initial Developer in (a) the Source Code, and (b) in any notice in an
+ Executable version or related documentation in which You describe the
+ origin or ownership of the Covered Code.
+
+ 3.4. Intellectual Property Matters
+ (a) Third Party Claims.
+ If Contributor has knowledge that a license under a third party's
+ intellectual property rights is required to exercise the rights
+ granted by such Contributor under Sections 2.1 or 2.2,
+ Contributor must include a text file with the Source Code
+ distribution titled "LEGAL" which describes the claim and the
+ party making the claim in sufficient detail that a recipient will
+ know whom to contact. If Contributor obtains such knowledge after
+ the Modification is made available as described in Section 3.2,
+ Contributor shall promptly modify the LEGAL file in all copies
+ Contributor makes available thereafter and shall take other steps
+ (such as notifying appropriate mailing lists or newsgroups)
+ reasonably calculated to inform those who received the Covered
+ Code that new knowledge has been obtained.
+
+ (b) Contributor APIs.
+ If Contributor's Modifications include an application programming
+ interface and Contributor has knowledge of patent licenses which
+ are reasonably necessary to implement that API, Contributor must
+ also include this information in the LEGAL file.
+
+ (c) Representations.
+ Contributor represents that, except as disclosed pursuant to
+ Section 3.4(a) above, Contributor believes that Contributor's
+ Modifications are Contributor's original creation(s) and/or
+ Contributor has sufficient rights to grant the rights conveyed by
+ this License.
+
+ 3.5. Required Notices.
+ You must duplicate the notice in Exhibit A in each file of the Source
+ Code. If it is not possible to put such notice in a particular Source
+ Code file due to its structure, then You must include such notice in a
+ location (such as a relevant directory) where a user would be likely
+ to look for such a notice. If You created one or more Modification(s)
+ You may add your name as a Contributor to the notice described in
+ Exhibit A. You must also duplicate this License in any documentation
+ for the Source Code where You describe recipients' rights or ownership
+ rights relating to Covered Code. You may choose to offer, and to
+ charge a fee for, warranty, support, indemnity or liability
+ obligations to one or more recipients of Covered Code. However, You
+ may do so only on Your own behalf, and not on behalf of the Initial
+ Developer or any Contributor. You must make it absolutely clear than
+ any such warranty, support, indemnity or liability obligation is
+ offered by You alone, and You hereby agree to indemnify the Initial
+ Developer and every Contributor for any liability incurred by the
+ Initial Developer or such Contributor as a result of warranty,
+ support, indemnity or liability terms You offer.
+
+ 3.6. Distribution of Executable Versions.
+ You may distribute Covered Code in Executable form only if the
+ requirements of Section 3.1-3.5 have been met for that Covered Code,
+ and if You include a notice stating that the Source Code version of
+ the Covered Code is available under the terms of this License,
+ including a description of how and where You have fulfilled the
+ obligations of Section 3.2. The notice must be conspicuously included
+ in any notice in an Executable version, related documentation or
+ collateral in which You describe recipients' rights relating to the
+ Covered Code. You may distribute the Executable version of Covered
+ Code or ownership rights under a license of Your choice, which may
+ contain terms different from this License, provided that You are in
+ compliance with the terms of this License and that the license for the
+ Executable version does not attempt to limit or alter the recipient's
+ rights in the Source Code version from the rights set forth in this
+ License. If You distribute the Executable version under a different
+ license You must make it absolutely clear that any terms which differ
+ from this License are offered by You alone, not by the Initial
+ Developer or any Contributor. You hereby agree to indemnify the
+ Initial Developer and every Contributor for any liability incurred by
+ the Initial Developer or such Contributor as a result of any such
+ terms You offer.
+
+ 3.7. Larger Works.
+ You may create a Larger Work by combining Covered Code with other code
+ not governed by the terms of this License and distribute the Larger
+ Work as a single product. In such a case, You must make sure the
+ requirements of this License are fulfilled for the Covered Code.
+
+4. Inability to Comply Due to Statute or Regulation.
+
+ If it is impossible for You to comply with any of the terms of this
+ License with respect to some or all of the Covered Code due to
+ statute, judicial order, or regulation then You must: (a) comply with
+ the terms of this License to the maximum extent possible; and (b)
+ describe the limitations and the code they affect. Such description
+ must be included in the LEGAL file described in Section 3.4 and must
+ be included with all distributions of the Source Code. Except to the
+ extent prohibited by statute or regulation, such description must be
+ sufficiently detailed for a recipient of ordinary skill to be able to
+ understand it.
+
+5. Application of this License.
+
+ This License applies to code to which the Initial Developer has
+ attached the notice in Exhibit A and to related Covered Code.
+
+6. Versions of the License.
+
+ 6.1. New Versions.
+ Netscape Communications Corporation ("Netscape") may publish revised
+ and/or new versions of the License from time to time. Each version
+ will be given a distinguishing version number.
+
+ 6.2. Effect of New Versions.
+ Once Covered Code has been published under a particular version of the
+ License, You may always continue to use it under the terms of that
+ version. You may also choose to use such Covered Code under the terms
+ of any subsequent version of the License published by Netscape. No one
+ other than Netscape has the right to modify the terms applicable to
+ Covered Code created under this License.
+
+ 6.3. Derivative Works.
+ If You create or use a modified version of this License (which you may
+ only do in order to apply it to code which is not already Covered Code
+ governed by this License), You must (a) rename Your license so that
+ the phrases "Mozilla", "MOZILLAPL", "MOZPL", "Netscape",
+ "MPL", "NPL" or any confusingly similar phrase do not appear in your
+ license (except to note that your license differs from this License)
+ and (b) otherwise make it clear that Your version of the license
+ contains terms which differ from the Mozilla Public License and
+ Netscape Public License. (Filling in the name of the Initial
+ Developer, Original Code or Contributor in the notice described in
+ Exhibit A shall not of themselves be deemed to be modifications of
+ this License.)
+
+7. DISCLAIMER OF WARRANTY.
+
+ COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ WITHOUT LIMITATION, WARRANTIES THAT THE COVERED CODE IS FREE OF
+ DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE OR NON-INFRINGING.
+ THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED CODE
+ IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT,
+ YOU (NOT THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE
+ COST OF ANY NECESSARY SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER
+ OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. NO USE OF
+ ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS DISCLAIMER.
+
+8. TERMINATION.
+
+ 8.1. This License and the rights granted hereunder will terminate
+ automatically if You fail to comply with terms herein and fail to cure
+ such breach within 30 days of becoming aware of the breach. All
+ sublicenses to the Covered Code which are properly granted shall
+ survive any termination of this License. Provisions which, by their
+ nature, must remain in effect beyond the termination of this License
+ shall survive.
+
+ 8.2. If You initiate litigation by asserting a patent infringement
+ claim (excluding declatory judgment actions) against Initial Developer
+ or a Contributor (the Initial Developer or Contributor against whom
+ You file such action is referred to as "Participant") alleging that:
+
+ (a) such Participant's Contributor Version directly or indirectly
+ infringes any patent, then any and all rights granted by such
+ Participant to You under Sections 2.1 and/or 2.2 of this License
+ shall, upon 60 days notice from Participant terminate prospectively,
+ unless if within 60 days after receipt of notice You either: (i)
+ agree in writing to pay Participant a mutually agreeable reasonable
+ royalty for Your past and future use of Modifications made by such
+ Participant, or (ii) withdraw Your litigation claim with respect to
+ the Contributor Version against such Participant. If within 60 days
+ of notice, a reasonable royalty and payment arrangement are not
+ mutually agreed upon in writing by the parties or the litigation claim
+ is not withdrawn, the rights granted by Participant to You under
+ Sections 2.1 and/or 2.2 automatically terminate at the expiration of
+ the 60 day notice period specified above.
+
+ (b) any software, hardware, or device, other than such Participant's
+ Contributor Version, directly or indirectly infringes any patent, then
+ any rights granted to You by such Participant under Sections 2.1(b)
+ and 2.2(b) are revoked effective as of the date You first made, used,
+ sold, distributed, or had made, Modifications made by that
+ Participant.
+
+ 8.3. If You assert a patent infringement claim against Participant
+ alleging that such Participant's Contributor Version directly or
+ indirectly infringes any patent where such claim is resolved (such as
+ by license or settlement) prior to the initiation of patent
+ infringement litigation, then the reasonable value of the licenses
+ granted by such Participant under Sections 2.1 or 2.2 shall be taken
+ into account in determining the amount or value of any payment or
+ license.
+
+ 8.4. In the event of termination under Sections 8.1 or 8.2 above,
+ all end user license agreements (excluding distributors and resellers)
+ which have been validly granted by You or any distributor hereunder
+ prior to termination shall survive termination.
+
+9. LIMITATION OF LIABILITY.
+
+ UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT
+ (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL YOU, THE INITIAL
+ DEVELOPER, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF COVERED CODE,
+ OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO ANY PERSON FOR
+ ANY INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY
+ CHARACTER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF GOODWILL,
+ WORK STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER
+ COMMERCIAL DAMAGES OR LOSSES, EVEN IF SUCH PARTY SHALL HAVE BEEN
+ INFORMED OF THE POSSIBILITY OF SUCH DAMAGES. THIS LIMITATION OF
+ LIABILITY SHALL NOT APPLY TO LIABILITY FOR DEATH OR PERSONAL INJURY
+ RESULTING FROM SUCH PARTY'S NEGLIGENCE TO THE EXTENT APPLICABLE LAW
+ PROHIBITS SUCH LIMITATION. SOME JURISDICTIONS DO NOT ALLOW THE
+ EXCLUSION OR LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO
+ THIS EXCLUSION AND LIMITATION MAY NOT APPLY TO YOU.
+
+10. U.S. GOVERNMENT END USERS.
+
+ The Covered Code is a "commercial item," as that term is defined in
+ 48 C.F.R. 2.101 (Oct. 1995), consisting of "commercial computer
+ software" and "commercial computer software documentation," as such
+ terms are used in 48 C.F.R. 12.212 (Sept. 1995). Consistent with 48
+ C.F.R. 12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (June 1995),
+ all U.S. Government End Users acquire Covered Code with only those
+ rights set forth herein.
+
+11. MISCELLANEOUS.
+
+ This License represents the complete agreement concerning subject
+ matter hereof. If any provision of this License is held to be
+ unenforceable, such provision shall be reformed only to the extent
+ necessary to make it enforceable. This License shall be governed by
+ California law provisions (except to the extent applicable law, if
+ any, provides otherwise), excluding its conflict-of-law provisions.
+ With respect to disputes in which at least one party is a citizen of,
+ or an entity chartered or registered to do business in the United
+ States of America, any litigation relating to this License shall be
+ subject to the jurisdiction of the Federal Courts of the Northern
+ District of California, with venue lying in Santa Clara County,
+ California, with the losing party responsible for costs, including
+ without limitation, court costs and reasonable attorneys' fees and
+ expenses. The application of the United Nations Convention on
+ Contracts for the International Sale of Goods is expressly excluded.
+ Any law or regulation which provides that the language of a contract
+ shall be construed against the drafter shall not apply to this
+ License.
+
+12. RESPONSIBILITY FOR CLAIMS.
+
+ As between Initial Developer and the Contributors, each party is
+ responsible for claims and damages arising, directly or indirectly,
+ out of its utilization of rights under this License and You agree to
+ work with Initial Developer and Contributors to distribute such
+ responsibility on an equitable basis. Nothing herein is intended or
+ shall be deemed to constitute any admission of liability.
+
+13. MULTIPLE-LICENSED CODE.
+
+ Initial Developer may designate portions of the Covered Code as
+ "Multiple-Licensed". "Multiple-Licensed" means that the Initial
+ Developer permits you to utilize portions of the Covered Code under
+ Your choice of the NPL or the alternative licenses, if any, specified
+ by the Initial Developer in the file described in Exhibit A.
+
+EXHIBIT A -Mozilla Public License.
+
+ ``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 ______________________________________.
+
+ The Initial Developer of the Original Code is ________________________.
+ Portions created by ______________________ are Copyright (C) ______
+ _______________________. All Rights Reserved.
+
+ Contributor(s): ______________________________________.
+
+ Alternatively, the contents of this file may be used under the terms
+ of the _____ license (the "[___] License"), in which case the
+ provisions of [______] License are applicable instead of those
+ above. If you wish to allow use of your version of this file only
+ under the terms of the [____] License and not to allow others to use
+ your version of this file under the MPL, indicate your decision by
+ deleting the provisions above and replace them with the notice and
+ other provisions required by the [___] License. If you do not delete
+ the provisions above, a recipient may use your version of this file
+ under either the MPL or the [___] License."
+
+ [NOTE: The text of this Exhibit A may differ slightly from the text of
+ the notices in the Source Code files of the Original Code. You should
+ use the text of this Exhibit A rather than the text found in the
+ Original Code Source Code for Your Modifications.]
+
--- /dev/null
+++ b/common/mp4v2/INTERNALS
@@ -1,0 +1,209 @@
+January 7, 2002
+
+MP4V2 LIBRARY INTERNALS
+=======================
+
+This document provides an overview of the interals 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,109 @@
+SUBDIRS = . test util
+
+INCLUDES = -I$(top_srcdir)/include
+
+AM_CXXFLAGS = -Wall
+
+lib_LTLIBRARIES = libmp4v2.la
+
+libmp4v2_la_SOURCES = \
+ mp4.h \
+ mp4.cpp \
+ mp4array.h \
+ mp4atom.h \
+ mp4atom.cpp \
+ mp4common.h \
+ mp4container.h \
+ mp4container.cpp \
+ mp4descriptor.h \
+ mp4descriptor.cpp \
+ mp4file.h \
+ mp4file.cpp \
+ mp4file_io.cpp \
+ mp4property.h \
+ mp4property.cpp \
+ mp4track.h \
+ mp4track.cpp \
+ mp4util.h \
+ mp4util.cpp \
+ atoms.h \
+ atom_co64.cpp \
+ atom_cprt.cpp \
+ atom_ctts.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_esds.cpp \
+ atom_free.cpp \
+ atom_ftyp.cpp \
+ atom_hdlr.cpp \
+ atom_hinf.cpp \
+ atom_hmhd.cpp \
+ atom_hnti.cpp \
+ atom_iods.cpp \
+ atom_maxr.cpp \
+ atom_mdat.cpp \
+ atom_mdhd.cpp \
+ atom_mdia.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_sdp.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.h \
+ descriptors.cpp \
+ ocidescriptors.h \
+ ocidescriptors.cpp \
+ qosqualifiers.h \
+ qosqualifiers.cpp \
+ odcommands.h \
+ odcommands.cpp \
+ rtphint.h \
+ rtphint.cpp \
+ isma.cpp
+
--- /dev/null
+++ b/common/mp4v2/TODO
@@ -1,0 +1,17 @@
+
+API and INTERNALS documentation
+
+Extended format support
+
+---
+
+Means to dump all possible atoms/properties with types
+
+Wrap printf's for verbosity - see example is player/lib/http/http_util.c
+
+Distinguish cases of no ES Config and error parsing esds
+
+Improve error recovery when length of atom/descriptor is larger than parent/file, resync on parent.
+
+Reshape things to use MPContainer as a base class?
+
--- /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 [email protected]
+ */
+
+#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 [email protected]
+ */
+
+#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 [email protected]
+ */
+
+#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_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 [email protected]
+ */
+
+#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 [email protected]
+ */
+
+#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 [email protected]
+ */
+
+#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 [email protected]
+ */
+
+#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 [email protected]
+ */
+
+#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 [email protected]
+ */
+
+#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 [email protected]
+ */
+
+#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 [email protected]
+ */
+
+#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_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 [email protected]
+ */
+
+#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 [email protected]
+ */
+
+#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_ftyp.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 [email protected]
+ */
+
+#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("isom");
+
+ MP4StringProperty* pBrandProperty = (MP4StringProperty*)
+ ((MP4TableProperty*)m_pProperties[3])->GetProperty(0);
+ ASSERT(pBrandProperty);
+ pBrandProperty->AddValue("mp41");
+ ((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 [email protected]
+ */
+
+#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 [email protected]
+ */
+
+#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 [email protected]
+ */
+
+#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 [email protected]
+ */
+
+#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_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 [email protected]
+ */
+
+#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 [email protected]
+ */
+
+#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 [email protected]
+ */
+
+#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 [email protected]
+ */
+
+#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() ? 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 [email protected]
+ */
+
+#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_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 [email protected]
+ */
+
+#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 [email protected]
+ */
+
+#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 [email protected]
+ */
+
+#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 [email protected]
+ */
+
+#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 [email protected]
+ */
+
+#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 [email protected]
+ */
+
+#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 [email protected]
+ */
+
+#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 [email protected]
+ */
+
+#include "mp4common.h"
+
+MP4MvexAtom::MP4MvexAtom()
+ : MP4Atom("mvex")
+{
+ ExpectChildAtom("trex", Required, Many);
+}
--- /dev/null
+++ b/common/mp4v2/atom_mvhd.cpp
@@ -1,0 +1,134 @@
+/*
+ * 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 [email protected]
+ */
+
+#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() ? 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);
+ }
+
+ ((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 [email protected]
+ */
+
+#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 [email protected]
+ */
+
+#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 [email protected]
+ */
+
+#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 [email protected]
+ */
+
+#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 [email protected]
+ */
+
+#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());
+}
+
+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());
+
+ // 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());
+}
+
+void MP4RootAtom::FinishOptimalWrite()
+{
+ // finish writing mdat
+ m_pChildAtoms[GetLastMdatIndex()]->FinishWrite(m_pFile->Use64Bits());
+
+ // 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 [email protected]
+ */
+
+#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_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 [email protected]
+ */
+
+#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_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 [email protected]
+ */
+
+#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 [email protected]
+ */
+
+#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 [email protected]
+ */
+
+#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()) {
+ 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 [email protected]
+ */
+
+#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 [email protected]
+ */
+
+#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[0])->SetReadOnly(false);
+ ((MP4Integer32Property*)m_pProperties[0])->SetValue((m_size - 4) / 2);
+ ((MP4Integer32Property*)m_pProperties[0])->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 [email protected]
+ */
+
+#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,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 [email protected]
+ */
+
+#include "mp4common.h"
+
+MP4StsdAtom::MP4StsdAtom()
+ : MP4Atom("stsd")
+{
+ AddVersionAndFlags();
+
+ MP4Integer32Property* pCount =
+ new MP4Integer32Property("entryCount");
+ pCount->SetReadOnly();
+ AddProperty(pCount);
+
+ ExpectChildAtom("mp4a", Optional, Many);
+ ExpectChildAtom("mp4s", Optional, Many);
+ ExpectChildAtom("mp4v", Optional, Many);
+ ExpectChildAtom("rtp ", Optional, Many);
+}
+
+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 [email protected]
+ */
+
+#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 [email protected]
+ */
+
+#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 [email protected]
+ */
+
+#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 [email protected]
+ */
+
+#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 [email protected]
+ */
+
+#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 [email protected]
+ */
+
+#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 [email protected]
+ */
+
+#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() ? 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 [email protected]
+ */
+
+#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 [email protected]
+ */
+
+#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 [email protected]
+ */
+
+#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 [email protected]
+ */
+
+#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 [email protected]
+ */
+
+#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 [email protected]
+ */
+
+#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 [email protected]
+ */
+
+#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 [email protected]
+ */
+
+#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 [email protected]
+ */
+
+#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 [email protected]
+ */
+
+#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 [email protected]
+ */
+
+#include "mp4common.h"
+
+MP4TsroAtom::MP4TsroAtom()
+ : MP4Atom("tsro")
+{
+ AddProperty(
+ new MP4Integer32Property("offset"));
+}
+
--- /dev/null
+++ b/common/mp4v2/atom_udta.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 [email protected]
+ */
+
+#include "mp4common.h"
+
+MP4UdtaAtom::MP4UdtaAtom()
+ : MP4Atom("udta")
+{
+ ExpectChildAtom("cprt", Optional, Many);
+ ExpectChildAtom("hnti", 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 [email protected]
+ */
+
+#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 [email protected]
+ */
+
+#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 [email protected]
+ */
+
+#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,439 @@
+/*
+ * 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 [email protected]
+ */
+
+#ifndef __MP4_ATOMS_INCLUDED__
+#define __MP4_ATOMS_INCLUDED__
+
+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();
+};
+
+#endif /* __MP4_ATOMS_INCLUDED__ */
--- /dev/null
+++ b/common/mp4v2/descriptors.cpp
@@ -1,0 +1,627 @@
+/*
+ * 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 [email protected]
+ */
+
+#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",
+ MP4ESIDIncDescrTag, 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);
+ }
+ }
+
+ 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 [email protected]
+ */
+
+#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,518 @@
+/*
+ * 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 [email protected]
+ */
+
+#include "mp4common.h"
+
+void MP4File::MakeIsmaCompliant(bool addIsmaComplianceSdp)
+{
+ ProtectWriteOperation("MP4MakeIsmaCompliant");
+
+ if (m_useIsma) {
+ // already done
+ return;
+ }
+ m_useIsma = true;
+
+ // 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;
+ }
+
+ // 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);
+ static u_int8_t bifsv2Config[3] = {
+ 0x00, 0x00, 0x40 // IsCommandStream
+ };
+ SetTrackESConfiguration(sceneTrackId,
+ bifsv2Config, sizeof(bifsv2Config));
+
+ u_int8_t* pBytes = NULL;
+ u_int64_t numBytes = 0;
+
+ // write OD Update Command
+ CreateIsmaODUpdateCommand(
+ m_odTrackId, audioTrackId, videoTrackId, true,
+ &pBytes, &numBytes);
+
+ WriteSample(m_odTrackId, pBytes, numBytes, 1);
+
+ MP4Free(pBytes);
+ pBytes = NULL;
+
+ // write BIFS Scene Replace Command
+ CreateIsmaSceneCommand(
+ sceneTrackId, audioTrackId, videoTrackId,
+ &pBytes, &numBytes);
+
+ WriteSample(sceneTrackId, pBytes, numBytes, 1);
+
+ MP4Free(pBytes);
+ pBytes = NULL;
+
+ // add session level sdp
+ CreateIsmaIod(
+ m_odTrackId, sceneTrackId, audioTrackId, videoTrackId,
+ &pBytes, &numBytes);
+
+ char* sdpBuf = (char*)MP4Calloc(numBytes + 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",
+ MP4ToBase64(pBytes, numBytes));
+
+ SetSessionSdp(sdpBuf);
+
+ VERBOSE_ISMA(GetVerbosity(),
+ printf("IOD SDP = %s\n", sdpBuf));
+
+ 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::CreateIsmaIod(
+ 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;
+
+ // OD
+ MP4Descriptor* pOdEsd =
+ pEsProperty->AddDescriptor(MP4ESDescrTag);
+ pOdEsd->Generate();
+
+ pOdEsd->FindProperty("ESID",
+ (MP4Property**)&pSetProperty);
+ pSetProperty->SetValue(m_odTrackId);
+
+ pOdEsd->FindProperty("URLFlag",
+ (MP4Property**)&pSetProperty);
+ pSetProperty->SetValue(1);
+
+ u_int8_t* pBytes;
+ u_int64_t numBytes;
+
+ CreateIsmaODUpdateCommand(
+ m_odTrackId, audioTrackId, videoTrackId, false,
+ &pBytes, &numBytes);
+
+ VERBOSE_ISMA(GetVerbosity(),
+ printf("OD data =\n"); MP4HexDump(pBytes, numBytes));
+
+ MP4StringProperty* pUrlProperty;
+ char* urlBuf = NULL;
+
+ urlBuf = (char*)MP4Malloc((numBytes * 4 / 3) + 64);
+
+ sprintf(urlBuf,
+ "data:application/mpeg4-od-au;base64,%s",
+ MP4ToBase64(pBytes, numBytes));
+
+ pOdEsd->FindProperty("URL",
+ (MP4Property**)&pUrlProperty);
+ pUrlProperty->SetValue(urlBuf);
+
+ VERBOSE_ISMA(GetVerbosity(),
+ printf("OD data URL = \042%s\042\n", urlBuf));
+
+ 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("slConfigDescr.predefined",
+ (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**)&pSetProperty);
+ pSetProperty->SetValue(sceneTrackId);
+
+ pSceneEsd->FindProperty("URLFlag",
+ (MP4Property**)&pSetProperty);
+ pSetProperty->SetValue(1);
+
+ CreateIsmaSceneCommand(
+ sceneTrackId, audioTrackId, videoTrackId,
+ &pBytes, &numBytes);
+
+ VERBOSE_ISMA(GetVerbosity(),
+ printf("Scene data =\n"); MP4HexDump(pBytes, numBytes));
+
+ urlBuf = (char*)MP4Malloc((numBytes * 4 / 3) + 64);
+ sprintf(urlBuf,
+ "data:application/mpeg4-bifs-au;base64,%s",
+ MP4ToBase64(pBytes, numBytes));
+
+ pSceneEsd->FindProperty("URL",
+ (MP4Property**)&pUrlProperty);
+ pUrlProperty->SetValue(urlBuf);
+
+ VERBOSE_ISMA(GetVerbosity(),
+ printf("Scene data URL = \042%s\042\n", urlBuf));
+
+ 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("slConfigDescr.predefined",
+ (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);
+
+ delete pIod;
+
+ VERBOSE_ISMA(GetVerbosity(),
+ printf("IOD data =\n"); MP4HexDump(*ppBytes, *pNumBytes));
+}
+
+void MP4File::CreateIsmaODUpdateCommand(
+ MP4TrackId odTrackId,
+ MP4TrackId audioTrackId,
+ MP4TrackId videoTrackId,
+ bool mp4FileMode,
+ u_int8_t** ppBytes,
+ u_int64_t* pNumBytes)
+{
+ MP4Descriptor* pCommand = CreateODCommand(MP4ODUpdateODCommandTag);
+ pCommand->Generate();
+
+ MP4Descriptor* pAudioOd = NULL;
+ MP4Descriptor* pVideoOd = NULL;
+ MP4DescriptorProperty* pOrgAudioEsdProperty = NULL;
+ MP4DescriptorProperty* pOrgVideoEsdProperty = NULL;
+ MP4DescriptorProperty* pRealAudioEsdProperty = NULL;
+ MP4DescriptorProperty* pRealVideoEsdProperty = NULL;
+
+ 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;
+ }
+
+ u_int32_t mpodIndex = FindTrackReference(
+ MakeTrackName(odTrackId, "tref.mpod"), trackId);
+ ASSERT(mpodIndex != 0);
+
+ u_int8_t odTag;
+ if (mp4FileMode) {
+ odTag = MP4FileODescrTag;
+ } else {
+ odTag = MP4ODescrTag;
+ }
+
+ MP4DescriptorProperty* pOdDescrProperty =
+ (MP4DescriptorProperty*)(pCommand->GetProperty(0));
+
+ pOdDescrProperty->SetTags(odTag);
+
+ MP4Descriptor* pOd =
+ pOdDescrProperty->AddDescriptor(odTag);
+
+ pOd->Generate();
+
+ if (i == 0) {
+ pAudioOd = pOd;
+ } else {
+ pVideoOd = pOd;
+ }
+
+ MP4BitfieldProperty* pOdIdProperty = NULL;
+ pOd->FindProperty("objectDescriptorId",
+ (MP4Property**)&pOdIdProperty);
+ pOdIdProperty->SetValue(odId);
+
+ MP4DescriptorProperty* pEsIdsDescriptorProperty = NULL;
+ pOd->FindProperty("esIds",
+ (MP4Property**)&pEsIdsDescriptorProperty);
+ ASSERT(pEsIdsDescriptorProperty);
+
+ if (mp4FileMode) {
+ pEsIdsDescriptorProperty->SetTags(MP4ESIDRefDescrTag);
+
+ MP4Descriptor *pRefDescriptor =
+ pEsIdsDescriptorProperty->AddDescriptor(MP4ESIDRefDescrTag);
+ pRefDescriptor->Generate();
+
+ MP4Integer16Property* pRefIndexProperty = NULL;
+ pRefDescriptor->FindProperty("refIndex",
+ (MP4Property**)&pRefIndexProperty);
+ ASSERT(pRefIndexProperty);
+
+ pRefIndexProperty->SetValue(mpodIndex);
+
+ } else { // stream mode
+ pEsIdsDescriptorProperty->SetTags(MP4ESDescrTag);
+
+ MP4Atom* pEsdsAtom =
+ FindAtom(MakeTrackName(trackId, "mdia.minf.stbl.stsd.*.esds"));
+ ASSERT(pEsdsAtom);
+
+ MP4DescriptorProperty* pEsdProperty =
+ (MP4DescriptorProperty*)(pEsdsAtom->GetProperty(2));
+
+ // HACK we temporarily point to the esds
+ if (i == 0) {
+ pOrgAudioEsdProperty = pEsIdsDescriptorProperty;
+ pRealAudioEsdProperty = pEsdProperty;
+ } else {
+ pOrgVideoEsdProperty = pEsIdsDescriptorProperty;
+ pRealVideoEsdProperty = pEsdProperty;
+ }
+ pOd->SetProperty(4, pEsdProperty);
+
+ // SL config needs to change from 2 (file) to 1 (null)
+ MP4Integer8Property* pSLConfigProperty = NULL;
+ pEsdProperty->FindProperty("slConfigDescr.predefined",
+ (MP4Property**)&pSLConfigProperty);
+ ASSERT(pSLConfigProperty);
+ pSLConfigProperty->SetValue(1);
+ }
+ }
+
+ pCommand->WriteToMemory(this, ppBytes, pNumBytes);
+
+ // carefully replace esd properties before destroying
+ if (pAudioOd) {
+ pAudioOd->SetProperty(4, pOrgAudioEsdProperty);
+
+ // SL config needs to go back to 2 (file)
+ if (!mp4FileMode) {
+ ASSERT(pRealAudioEsdProperty);
+ MP4Integer8Property* pSLConfigProperty = NULL;
+ pRealAudioEsdProperty->FindProperty("slConfigDescr.predefined",
+ (MP4Property**)&pSLConfigProperty);
+ ASSERT(pSLConfigProperty);
+ pSLConfigProperty->SetValue(2);
+ }
+ }
+
+ if (pVideoOd) {
+ pVideoOd->SetProperty(4, pOrgVideoEsdProperty);
+
+ // SL config needs to go back to 2 (file)
+ if (!mp4FileMode) {
+ ASSERT(pRealVideoEsdProperty);
+ MP4Integer8Property* pSLConfigProperty = NULL;
+ pRealVideoEsdProperty->FindProperty("slConfigDescr.predefined",
+ (MP4Property**)&pSLConfigProperty);
+ ASSERT(pSLConfigProperty);
+ pSLConfigProperty->SetValue(2);
+ }
+ }
+
+ delete pCommand;
+}
+
+void MP4File::CreateIsmaSceneCommand(
+ MP4TrackId sceneTrackId,
+ MP4TrackId audioTrackId,
+ MP4TrackId videoTrackId,
+ 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, 0x7C
+ };
+ static u_int8_t bifsVideoOnly[] = {
+ 0xC0, 0x10, 0x12,
+ 0x61, 0x04, 0x88, 0x50, 0x45, 0x05, 0x3F, 0x00
+ };
+ static u_int8_t bifsAudioVideo[] = {
+ 0xC0, 0x10, 0x12,
+ 0x81, 0x30, 0x2A, 0x05, 0x72,
+ 0x61, 0x04, 0x88, 0x50, 0x45, 0x05, 0x3F, 0x00
+ };
+
+ if (audioTrackId != MP4_INVALID_TRACK_ID
+ && videoTrackId != MP4_INVALID_TRACK_ID) {
+ *pNumBytes = sizeof(bifsAudioVideo);
+ *ppBytes = (u_int8_t*)MP4Malloc(*pNumBytes);
+ memcpy(*ppBytes, bifsAudioVideo, sizeof(bifsAudioVideo));
+
+ } else if (audioTrackId != MP4_INVALID_TRACK_ID) {
+ *pNumBytes = sizeof(bifsAudioOnly);
+ *ppBytes = (u_int8_t*)MP4Malloc(*pNumBytes);
+ memcpy(*ppBytes, bifsAudioOnly, sizeof(bifsAudioOnly));
+
+ } else if (videoTrackId != MP4_INVALID_TRACK_ID) {
+ *pNumBytes = sizeof(bifsVideoOnly);
+ *ppBytes = (u_int8_t*)MP4Malloc(*pNumBytes);
+ memcpy(*ppBytes, bifsVideoOnly, sizeof(bifsVideoOnly));
+ } else {
+ *pNumBytes = 0;
+ *ppBytes = NULL;
+ }
+}
+
--- /dev/null
+++ b/common/mp4v2/libmp4v2.dsp
@@ -1,0 +1,484 @@
+# Microsoft Developer Studio Project File - Name="libmp4v2" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 5.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 "libmp4v2.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.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 Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.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 ""
+RSC=rc.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
+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 ""
+RSC=rc.exe
+# ADD BASE CPP /nologo /W3 /GX /Z7 /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
+# ADD CPP /nologo /MDd /W3 /GX /Z7 /Od /I "..\..\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
+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=.\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_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_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_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=.\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/libmp4v260.dsp
@@ -1,0 +1,488 @@
+# 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
+# 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 /Z7 /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=.\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_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_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_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=.\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_st.dsp
@@ -1,0 +1,484 @@
+# Microsoft Developer Studio Project File - Name="libmp4v2_st" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 5.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_st.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_st.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 Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.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 ""
+RSC=rc.exe
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
+# ADD CPP /nologo /W3 /GX /O2 /I "..\..\include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
+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 ""
+RSC=rc.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
+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=.\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_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_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_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=.\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,504 @@
+# 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 ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
+# ADD CPP /nologo /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=xilink6.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 ""
+# 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=xilink6.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=.\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_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_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_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=.\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=.\mpeg4ip.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
+# Begin Source File
+
+SOURCE=.\systems.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\win32_ver.h
+# End Source File
+# End Group
+# End Target
+# End Project
--- /dev/null
+++ b/common/mp4v2/mp4.cpp
@@ -1,0 +1,1723 @@
+/*
+ * 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 [email protected]
+ */
+
+/*
+ * 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 MP4Create(const char* fileName,
+ u_int32_t verbosity, bool use64bits, bool useExtensibleFormat)
+{
+ MP4File* pFile = NULL;
+ try {
+ pFile = new MP4File(verbosity);
+ // LATER useExtensibleFormat, moov first, then mvex's
+ pFile->Create(fileName, use64bits);
+ return (MP4FileHandle)pFile;
+ }
+ catch (MP4Error* e) {
+ VERBOSE_ERROR(verbosity, e->Print());
+ delete e;
+ delete pFile;
+ return MP4_INVALID_FILE_HANDLE;
+ }
+}
+
+extern "C" MP4FileHandle MP4Modify(const char* fileName,
+ u_int32_t verbosity, bool useExtensibleFormat)
+{
+ 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)->AddTrack(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, u_int32_t 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 MP4AddVideoTrack(MP4FileHandle hFile,
+ u_int32_t timeScale, u_int32_t 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 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" 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)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->GetNumberOfTracks(type);
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ return 0;
+}
+
+extern "C" MP4TrackId MP4FindTrackId(
+ MP4FileHandle hFile, u_int16_t index, const char* type)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ return ((MP4File*)hFile)->FindTrackId(index, type);
+ }
+ 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;
+}
+
+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 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;
+}
+
+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" void 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;
+ }
+ catch (MP4Error* e) {
+ PRINT_ERROR(e);
+ delete e;
+ }
+ }
+ *ppConfig = NULL;
+ *pConfigSize = 0;
+ return;
+}
+
+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;
+}
+
+/* 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" 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 MP4WriteSample(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ 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" 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)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ ((MP4File*)hFile)->GetHintTrackRtpPayload(
+ hintTrackId, ppPayloadName, pPayloadNumber, pMaxPayloadSize);
+ 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)
+{
+ if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+ try {
+ ((MP4File*)hFile)->SetHintTrackRtpPayload(
+ hintTrackId, pPayloadName, pPayloadNumber, maxPayloadSize);
+ 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;
+}
+
+/* ISMA specific operations */
+
+extern "C" bool MP4MakeIsmaCompliant(
+ const char* fileName,
+ u_int32_t verbosity,
+ bool addIsmaComplianceSdp)
+{
+ try {
+ MP4File* 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;
+ }
+ return false;
+}
+
+/* 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;
+}
+
--- /dev/null
+++ b/common/mp4v2/mp4.h
@@ -1,0 +1,579 @@
+/*
+ * 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 [email protected]
+ */
+
+#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;
+
+/* 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)
+
+/* 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)
+
+/* 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_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"
+
+/* 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
+
+/* 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 0xC1
+
+
+/* MP4 API declarations */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* file operations */
+
+MP4FileHandle MP4Create(const char* fileName,
+ u_int32_t verbosity DEFAULT(0),
+ bool use64bits DEFAULT(0),
+ bool useExtensibleFormat DEFAULT(0));
+
+MP4FileHandle MP4Modify(const char* fileName,
+ u_int32_t verbosity DEFAULT(0),
+ bool useExtensibleFormat 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,
+ u_int32_t verbosity DEFAULT(0));
+
+bool MP4Dump(MP4FileHandle hFile,
+ FILE* pDumpFile DEFAULT(NULL),
+ bool dumpImplicits DEFAULT(0));
+
+/* 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);
+
+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, u_int32_t sampleDuration,
+ u_int8_t audioType DEFAULT(MP4_MPEG4_AUDIO_TYPE));
+
+MP4TrackId MP4AddVideoTrack(
+ MP4FileHandle hFile, u_int32_t timeScale, u_int32_t sampleDuration,
+ u_int16_t width, u_int16_t height,
+ u_int8_t videoType DEFAULT(MP4_MPEG4_VIDEO_TYPE));
+
+MP4TrackId MP4AddHintTrack(
+ MP4FileHandle hFile, MP4TrackId refTrackId);
+
+bool MP4DeleteTrack(
+ MP4FileHandle hFile, MP4TrackId trackId);
+
+u_int32_t MP4GetNumberOfTracks(
+ MP4FileHandle hFile, const char* type DEFAULT(NULL));
+
+MP4TrackId MP4FindTrackId(
+ MP4FileHandle hFile, u_int16_t index, const char* type DEFAULT(NULL));
+
+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);
+
+u_int8_t MP4GetTrackAudioType(
+ MP4FileHandle hFile, MP4TrackId trackId);
+
+u_int8_t MP4GetTrackVideoType(
+ MP4FileHandle hFile, MP4TrackId trackId);
+
+/* returns MP4_INVALID_DURATION if track samples do not have a fixed duration */
+MP4Duration MP4GetTrackFixedSampleDuration(
+ MP4FileHandle hFile, MP4TrackId trackId);
+
+void 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);
+
+/* 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));
+
+bool MP4WriteSample(
+ MP4FileHandle hFile,
+ MP4TrackId trackId,
+ u_int8_t* pBytes,
+ u_int32_t numBytes,
+ MP4Duration duration DEFAULT(MP4_INVALID_DURATION),
+ MP4Duration renderingOffset DEFAULT(0),
+ bool isSyncSample DEFAULT(true));
+
+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));
+
+bool MP4SetHintTrackRtpPayload(
+ MP4FileHandle hFile,
+ MP4TrackId hintTrackId,
+ const char* pPayloadName,
+ u_int8_t* pPayloadNumber,
+ u_int16_t maxPayloadSize DEFAULT(0));
+
+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));
+
+/* ISMA specific operations */
+
+bool MP4MakeIsmaCompliant(const char* fileName,
+ u_int32_t verbosity DEFAULT(0),
+ bool addIsmaComplianceSdp DEFAULT(true));
+
+/* 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 [email protected]
+ */
+
+#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,787 @@
+/*
+ * 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 [email protected]
+ */
+
+#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 if (type[0] == '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 (type[0] == 'd') {
+ 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 (type[0] == '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 (type[0] == '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();
+ }
+ } else if (type[0] == '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 (type[0] == 's') {
+ 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");
+ }
+ } else if (type[0] == '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 (type[0] == '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();
+ }
+ } else {
+ if (ATOMID(type) == ATOMID("free")) {
+ pAtom = new MP4FreeAtom();
+ } else if (ATOMID(type) == ATOMID("ftyp")) {
+ pAtom = new MP4FtypAtom();
+ } else if (ATOMID(type) == ATOMID("iods")) {
+ pAtom = new MP4IodsAtom();
+ } else if (ATOMID(type) == ATOMID("ipir")) {
+ pAtom = new MP4TrefTypeAtom(type);
+ } else if (ATOMID(type) == ATOMID("nmhd")) {
+ pAtom = new MP4NmhdAtom();
+ } else if (ATOMID(type) == ATOMID("nump")) {
+ pAtom = new MP4NumpAtom();
+ } else if (ATOMID(type) == ATOMID("pmax")) {
+ pAtom = new MP4PmaxAtom();
+ } else if (ATOMID(type) == ATOMID("payt")) {
+ pAtom = new MP4PaytAtom();
+ } else if (ATOMID(type) == ATOMID("rtp ")) {
+ pAtom = new MP4RtpAtom();
+ } else if (ATOMID(type) == ATOMID("vmhd")) {
+ pAtom = new MP4VmhdAtom();
+ }
+ }
+
+ 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"LLX"\n", pos));
+
+ u_int64_t dataSize = pFile->ReadUInt32();
+
+ if (dataSize == 1) {
+ dataSize = pFile->ReadUInt64();
+ hdrSize += 8;
+ }
+
+ char type[5];
+ pFile->ReadBytes((u_int8_t*)&type[0], 4);
+ type[4] = '\0';
+
+ // 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 = "LLU" (0x"LLX")\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 "LLU" 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: "LLU" 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"LLX" atom end 0x"LLX"\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::BeginWrite(bool use64)
+{
+ m_start = m_pFile->GetPosition();
+ if (use64) {
+ m_pFile->WriteUInt32(1);
+ m_pFile->WriteUInt64(0);
+ } else {
+ m_pFile->WriteUInt32(0);
+ }
+ m_pFile->WriteBytes((u_int8_t*)&m_type[0], 4);
+ 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);
+ if (use64) {
+ m_pFile->SetPosition(m_start + 4);
+ 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,231 @@
+/*
+ * 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 [email protected]
+ */
+
+#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) {
+ 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 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,46 @@
+/*
+ * 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 [email protected]
+ */
+
+#ifndef __MP4_COMMON_INCLUDED__
+#define __MP4_COMMON_INCLUDED__
+
+#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 [email protected]
+ */
+
+#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 [email protected]
+ */
+
+#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,207 @@
+/*
+ * 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 [email protected]
+ */
+
+#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%llx\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++) {
+
+ int32_t remaining = m_size - (pFile->GetPosition() - m_start);
+
+ if (m_pProperties[i]->GetType() == DescriptorProperty
+ && remaining >= 0) {
+ // place a limit on how far this sub-descriptor looks
+ ((MP4DescriptorProperty*)m_pProperties[i])->SetSizeLimit(remaining);
+ m_pProperties[i]->Read(pFile);
+
+ } else if (remaining >= 0) {
+ m_pProperties[i]->Read(pFile);
+
+ if (m_pProperties[i]->GetType() == TableProperty) {
+ VERBOSE_READ_TABLE(pFile->GetVerbosity(),
+ printf("Read: "); m_pProperties[i]->Dump(stdout, 0, true));
+ } else {
+ VERBOSE_READ(pFile->GetVerbosity(),
+ printf("Read: "); m_pProperties[i]->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 [email protected]
+ */
+
+#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,1973 @@
+/*
+ * 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 [email protected]
+ */
+
+#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_use64bits = false;
+ 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, bool use64bits)
+{
+ m_fileName = MP4Stralloc(fileName);
+ m_mode = 'w';
+ m_use64bits = use64bits;
+
+ Open("wb+");
+
+ // generate a skeletal atom tree
+ m_pRootAtom = MP4Atom::CreateAtom(NULL);
+ m_pRootAtom->SetFile(this);
+ m_pRootAtom->Generate();
+
+ CacheProperties();
+
+ // create mdat, and insert it after ftyp, and before moov
+ InsertChildAtom(m_pRootAtom, "mdat", 1);
+
+ // start writing
+ m_pRootAtom->BeginWrite();
+}
+
+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);
+ 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);
+}
+
+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);
+ m_pFile = fopen(m_fileName, fmode);
+ 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);
+ pFreeAtom->SetSize(MAX(m_orgFileSize - (m_fileSize + 8), 0));
+ 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;
+}
+
+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", "MP4File::FindIntegerProperty");
+ }
+
+ switch ((*ppProperty)->GetType()) {
+ case Integer8Property:
+ case Integer16Property:
+ case Integer24Property:
+ case Integer32Property:
+ case Integer64Property:
+ break;
+ default:
+ throw new MP4Error("type mismatch", "MP4File::FindIntegerProperty");
+ }
+}
+
+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", "MP4File::FindFloatProperty");
+ }
+ if ((*ppProperty)->GetType() != Float32Property) {
+ throw new MP4Error("type mismatch", "MP4File::FindFloatProperty");
+ }
+}
+
+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", "MP4File::FindStringProperty");
+ }
+ if ((*ppProperty)->GetType() != StringProperty) {
+ throw new MP4Error("type mismatch", "MP4File::FindStringProperty");
+ }
+}
+
+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", "MP4File::FindBytesProperty");
+ }
+ if ((*ppProperty)->GetType() != BytesProperty) {
+ throw new MP4Error("type mismatch", "MP4File::FindBytesProperty");
+ }
+}
+
+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);
+
+ 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 : 1);
+
+ // 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)
+{
+ MP4DescriptorProperty* pDescriptorProperty = NULL;
+ m_pRootAtom->FindProperty("moov.iods.esIds",
+ (MP4Property**)&pDescriptorProperty);
+ ASSERT(pDescriptorProperty);
+
+ 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->SetValue(pCountProperty->GetValue() - 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);
+
+ 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", trackId);
+
+ 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;
+}
+
+MP4TrackId MP4File::AddAudioTrack(u_int32_t timeScale,
+ u_int32_t 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", trackId);
+
+ 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::AddVideoTrack(
+ u_int32_t timeScale, u_int32_t 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", trackId);
+
+ 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::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);
+ 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)
+{
+ if (type == NULL) {
+ return m_pTracks.Size();
+ } else {
+ u_int16_t typeSeen = 0;
+ const char* normType = MP4Track::NormalizeTrackType(type);
+
+ for (u_int16_t i = 0; i < m_pTracks.Size(); i++) {
+ if (!strcmp(normType, m_pTracks[i]->GetType())) {
+ typeSeen++;
+ }
+ }
+ return typeSeen;
+ }
+}
+
+MP4TrackId MP4File::AllocTrackId()
+{
+ MP4TrackId trackId = GetIntegerProperty("moov.mvhd.nextTrackId");
+
+ if (trackId <= 0xFFFF) {
+ SetIntegerProperty("moov.mvhd.nextTrackId", trackId + 1);
+ } else {
+ // extremely rare case where we need to search for a track id
+ for (u_int16_t i = 1; i <= 0xFFFF; i++) {
+ try {
+ FindTrackIndex(i);
+ }
+ catch (MP4Error* e) {
+ trackId = i;
+ delete e;
+ }
+ }
+ // even more extreme case where mp4 file has 2^16 tracks in it
+ if (trackId > 0xFFFF) {
+ throw new MP4Error("too many exising tracks", "AddTrack");
+ }
+ }
+
+ return trackId;
+}
+
+MP4TrackId MP4File::FindTrackId(u_int16_t trackIndex, const char* type)
+{
+ if (type == NULL) {
+ return m_pTracks[trackIndex]->GetId();
+ } else {
+ u_int16_t typeSeen = 0;
+ const char* normType = MP4Track::NormalizeTrackType(type);
+
+ for (u_int16_t i = 0; i < m_pTracks.Size(); i++) {
+ if (!strcmp(normType, m_pTracks[i]->GetType())) {
+ if (trackIndex == typeSeen) {
+ return m_pTracks[i]->GetId();
+ }
+ typeSeen++;
+ }
+ }
+ throw new MP4Error("Track index doesn't exist", "FindTrackId");
+ return MP4_INVALID_TRACK_ID; // satisfy MS compiler
+ }
+}
+
+u_int16_t MP4File::FindTrackIndex(MP4TrackId trackId)
+{
+ for (u_int16_t i = 0; i < m_pTracks.Size(); i++) {
+ if (m_pTracks[i]->GetId() == trackId) {
+ return i;
+ }
+ }
+
+ throw new MP4Error("Track id doesn't exist", "FindTrackIndex");
+ 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 doesn't exist", "FindTrakAtomIndex");
+ 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,
+ 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");
+}
+
+u_int8_t MP4File::GetTrackAudioType(MP4TrackId trackId)
+{
+ return GetTrackIntegerProperty(trackId,
+ "mdia.minf.stbl.stsd.mp4a.esds.decConfigDescr.objectTypeId");
+}
+
+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();
+}
+
+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)
+{
+ 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);
+}
+
+void MP4File::SetHintTrackRtpPayload(MP4TrackId hintTrackId,
+ const char* payloadName, u_int8_t* pPayloadNumber, u_int16_t maxPayloadSize)
+{
+ 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 != 0) {
+ payloadNumber = *pPayloadNumber;
+ } else {
+ payloadNumber = AllocRtpPayloadNumber();
+ if (pPayloadNumber) {
+ *pPayloadNumber = payloadNumber;
+ }
+ }
+
+ ((MP4RtpHintTrack*)pTrack)->SetPayload(
+ payloadName, payloadNumber, maxPayloadSize);
+}
+
+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((u_int64_t)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;
+}
+
--- /dev/null
+++ b/common/mp4v2/mp4file.h
@@ -1,0 +1,508 @@
+/*
+ * 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 [email protected]
+ */
+
+#ifndef __MP4_FILE_INCLUDED__
+#define __MP4_FILE_INCLUDED__
+
+// forward declarations
+class MP4Atom;
+class MP4Property;
+class MP4Float32Property;
+class MP4StringProperty;
+class MP4BytesProperty;
+class MP4Descriptor;
+
+class MP4File {
+public: /* equivalent to MP4 library API */
+ MP4File(u_int32_t verbosity = 0);
+ ~MP4File();
+
+ /* file operations */
+ void Read(const char* fileName);
+ void Create(const char* fileName, bool use64bits);
+ void Modify(const char* fileName);
+ void Optimize(const char* orgFileName,
+ const char* newFileName);
+ void MakeIsmaCompliant(bool addIsmaComplianceSdp = true);
+ void Dump(FILE* pDumpFile = NULL, bool dumpImplicits = false);
+ void Close();
+
+ /* library property per file */
+
+ u_int32_t GetVerbosity() {
+ return m_verbosity;
+ }
+ void SetVerbosity(u_int32_t verbosity) {
+ m_verbosity = verbosity;
+ }
+
+ bool Use64Bits() {
+ return m_use64bits;
+ }
+
+ /* file properties */
+
+ u_int64_t GetIntegerProperty(const char* name);
+ float GetFloatProperty(const char* name);
+ const char* GetStringProperty(const char* name);
+ void GetBytesProperty(const char* name,
+ u_int8_t** ppValue, u_int32_t* pValueSize);
+
+ void SetIntegerProperty(const char* name, u_int64_t value);
+ void SetFloatProperty(const char* name, float value);
+ void SetStringProperty(const char* name, const char* value);
+ void SetBytesProperty(const char* name,
+ const u_int8_t* pValue, u_int32_t valueSize);
+
+ // file level convenience functions
+
+ MP4Duration GetDuration();
+ void SetDuration(MP4Duration value);
+
+ u_int32_t GetTimeScale();
+ void SetTimeScale(u_int32_t value);
+
+ u_int8_t GetODProfileLevel();
+ void SetODProfileLevel(u_int8_t value);
+
+ u_int8_t GetSceneProfileLevel();
+ void SetSceneProfileLevel(u_int8_t value);
+
+ u_int8_t GetVideoProfileLevel();
+ void SetVideoProfileLevel(u_int8_t value);
+
+ u_int8_t GetAudioProfileLevel();
+ void SetAudioProfileLevel(u_int8_t value);
+
+ u_int8_t GetGraphicsProfileLevel();
+ void SetGraphicsProfileLevel(u_int8_t value);
+
+ const char* GetSessionSdp();
+ void SetSessionSdp(const char* sdpString);
+ void AppendSessionSdp(const char* sdpString);
+
+ /* track operations */
+
+ MP4TrackId AddTrack(const char* type, u_int32_t timeScale = 1);
+ void DeleteTrack(MP4TrackId trackId);
+
+ u_int32_t GetNumberOfTracks(const char* type = NULL);
+
+ MP4TrackId AllocTrackId();
+ MP4TrackId FindTrackId(u_int16_t trackIndex, const char* type = NULL);
+ 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,
+ 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, u_int32_t sampleDuration,
+ u_int8_t audioType);
+
+ MP4TrackId AddVideoTrack(u_int32_t timeScale, u_int32_t sampleDuration,
+ u_int16_t width, u_int16_t height, u_int8_t videoType);
+
+ MP4TrackId AddHintTrack(MP4TrackId refTrackId);
+
+ MP4SampleId GetTrackNumberOfSamples(MP4TrackId trackId);
+
+ const char* GetTrackType(MP4TrackId trackId);
+
+ MP4Duration GetTrackDuration(MP4TrackId trackId);
+
+ u_int32_t GetTrackTimeScale(MP4TrackId trackId);
+ void SetTrackTimeScale(MP4TrackId trackId, u_int32_t value);
+
+ u_int8_t GetTrackAudioType(MP4TrackId trackId);
+ u_int8_t GetTrackVideoType(MP4TrackId trackId);
+
+ MP4Duration GetTrackFixedSampleDuration(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);
+
+ // 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);
+
+ void SetHintTrackRtpPayload(
+ MP4TrackId hintTrackId,
+ const char* payloadName,
+ u_int8_t* pPayloadNumber,
+ u_int16_t maxPayloadSize);
+
+ 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();
+
+ /* 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);
+
+ 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);
+
+ 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 CreateIsmaIod(
+ MP4TrackId odTrackId, MP4TrackId sceneTrackId,
+ MP4TrackId audioTrackId, MP4TrackId videoTrackId,
+ u_int8_t** ppBytes, u_int64_t* pNumBytes);
+
+ void CreateIsmaODUpdateCommand(
+ MP4TrackId odTrackId,
+ MP4TrackId audioTrackId, MP4TrackId videoTrackId,
+ bool mp4FileMode,
+ u_int8_t** ppBytes, u_int64_t* pNumBytes);
+
+ void CreateIsmaSceneCommand(MP4TrackId sceneTrackId,
+ MP4TrackId audioTrackId, MP4TrackId videoTrackId,
+ 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;
+ bool m_use64bits;
+ 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,563 @@
+/*
+ * 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 [email protected]
+ */
+
+#include "mp4common.h"
+
+#ifdef HAVE_FPOS_T_POS
+#define FPOS_TO_UINT64(x) ((u_int64_t)((x).__pos))
+#define UINT64_TO_FPOS(x, y) ((x).__pos = (y))
+#else
+#define FPOS_TO_UINT64(x) ((u_int64_t)(x))
+#define UINT64_TO_FPOS(x, y) ((x) = (fpos)(y))
+#endif
+
+// 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");
+ }
+ return FPOS_TO_UINT64(fpos);
+ } 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) {
+ 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 = 1024;
+ }
+ 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)
+{
+ WARNING(pBytes == NULL);
+ WARNING(numBytes == 0);
+ ASSERT(m_numWriteBits == 0 || m_numWriteBits >= 8);
+
+ if (pBytes == NULL || numBytes == 0) {
+ return;
+ }
+ if (pFile == NULL) {
+ ASSERT(m_pFile);
+ pFile = m_pFile;
+ }
+
+ if (m_memoryBuffer == NULL) {
+ 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) {
+ do {
+ u_int8_t b = MIN(charLength, 255);
+ WriteUInt8(b);
+ charLength -= b;
+ } while (charLength);
+ } else {
+ if (charLength > 255) {
+ throw new MP4Error(ERANGE, "MP4WriteCountedString");
+ }
+ 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/mp4property.cpp
@@ -1,0 +1,831 @@
+/*
+ * 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 [email protected]
+ */
+
+#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::IncrementValue(u_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,
+#ifdef WIN32
+ "%s = "LLU" (0x%016I64x)\n",
+#else
+ "%s = "LLU" (0x%016llx)\n",
+#endif
+ 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,
+#ifdef WIN32
+ "%s = "LLU" (0x%0*I64) <%u bits>\n",
+#else
+ "%s = "LLU" (0x%0*llx) <%u bits>\n",
+#endif
+ 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)
+ : MP4Property(name)
+{
+ SetCount(1);
+ m_values[0] = (u_int8_t*)MP4Calloc(valueSize);
+ m_valueSizes[0] = valueSize;
+ m_fixedValueSize = 0;
+}
+
+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] = 0;
+ }
+}
+
+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]);
+ WARNING(m_valueSizes[index] == 0);
+ 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;
+ }
+ WARNING(m_values[index] == NULL);
+ WARNING(m_valueSizes[index] == 0);
+ 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) {
+ 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,541 @@
+/*
+ * 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 [email protected]
+ */
+
+#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() = NULL;
+
+ 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() = NULL;
+ virtual void SetCount(u_int32_t count) = NULL;
+
+ virtual void Generate() { /* default is a no-op */ };
+
+ virtual void Read(MP4File* pFile, u_int32_t index = 0) = NULL;
+
+ virtual void Write(MP4File* pFile, u_int32_t index = 0) = NULL;
+
+ virtual void Dump(FILE* pFile, u_int8_t indent,
+ bool dumpImplicits, u_int32_t index = 0) = NULL;
+
+ 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 IncrementValue(u_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(u_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);
+
+ ~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;
+ 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 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,1365 @@
+/*
+ * 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 [email protected]
+ */
+
+#include "mp4common.h"
+
+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;
+
+ 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);
+ }
+
+ // 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"LLX" 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 "LLU" duration "LLD"\n",
+ (pStartTime ? *pStartTime : 0),
+ (pDuration ? *pDuration : 0)));
+ }
+ if (pRenderingOffset) {
+ *pRenderingOffset = GetSampleRenderingOffset(sampleId);
+
+ VERBOSE_READ_SAMPLE(m_pFile->GetVerbosity(),
+ printf("ReadSample: renderingOffset "LLD"\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(
+ u_int8_t* pBytes,
+ u_int32_t numBytes,
+ MP4Duration duration,
+ MP4Duration renderingOffset,
+ bool isSyncSample)
+{
+ 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) {
+ throw new MP4Error("no sample data", "MP4WriteSample");
+ }
+
+ if (numBytes == 0) {
+ throw new MP4Error("sample size is zero", "MP4WriteSample");
+ }
+
+ if (duration == MP4_INVALID_DURATION) {
+ duration = GetFixedSampleDuration();
+ }
+
+ VERBOSE_WRITE_SAMPLE(m_pFile->GetVerbosity(),
+ printf("duration "LLU"\n", duration));
+
+ // 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 (IsChunkFull(m_writeSampleId)) {
+ WriteChunkBuffer();
+ }
+
+ 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"LLX" 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) {
+ // presume sample size is fixed
+ m_pStszFixedSampleSizeProperty->SetValue(numBytes);
+
+ } else { // sampleId > 1
+ u_int32_t fixedSampleSize =
+ m_pStszFixedSampleSizeProperty->GetValue();
+
+ if (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 = elapsed + ((sampleId - sid) * sampleDelta);
+ }
+ 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 (d % sampleDelta) {
+ sampleId++;
+ }
+ }
+
+ 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"LLX" 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"LLX" 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")) {
+ return MP4_VIDEO_TRACK_TYPE;
+ }
+
+ if (!strcasecmp(type, "soun")
+ || !strcasecmp(type, "sound")
+ || !strcasecmp(type, "audio")
+ || !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;
+}
+
--- /dev/null
+++ b/common/mp4v2/mp4track.h
@@ -1,0 +1,213 @@
+/*
+ * 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 [email protected]
+ */
+
+#ifndef __MP4_TRACK_INCLUDED__
+#define __MP4_TRACK_INCLUDED__
+
+typedef u_int32_t MP4ChunkId;
+
+// forward declarations
+class MP4File;
+class MP4Atom;
+class MP4Property;
+class MP4IntegerProperty;
+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(
+ 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);
+
+ 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:
+ 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;
+
+ 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;
+};
+
+MP4ARRAY_DECL(MP4Track, MP4Track*);
+
+#endif /* __MP4_TRACK_INCLUDED__ */
--- /dev/null
+++ b/common/mp4v2/mp4util.cpp
@@ -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 [email protected]
+ */
+
+#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;
+#ifdef _WINDOWS
+ d *= (double)(int64_t)t;
+#else
+ d *= (double)t;
+#endif
+
+ return (u_int64_t)d;
+}
+
--- /dev/null
+++ b/common/mp4v2/mp4util.h
@@ -1,0 +1,188 @@
+/*
+ * 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 [email protected]
+ */
+
+#ifndef __MP4_UTIL_INCLUDED__
+#define __MP4_UTIL_INCLUDED__
+
+#include <assert.h>
+
+#ifdef NDEBUG
+#define ASSERT(expr)
+#define WARNING(expr)
+#else
+#define ASSERT(expr) assert(expr)
+#define WARNING(expr) \
+ if (expr) { \
+ 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)
+
+inline void Indent(FILE* pFile, u_int8_t depth) {
+ fprintf(pFile, "%*c", depth, ' ');
+}
+
+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
+ fprintf(stdout, fmt, ap);
+ va_end(ap);
+}
+
+class MP4Error {
+public:
+ MP4Error() {
+ m_errno = 0;
+ m_errstring = NULL;
+ m_where = NULL;
+ }
+ MP4Error(int err, const char* where = NULL) {
+ m_errno = err;
+ m_errstring = NULL;
+ m_where = where;
+ }
+ MP4Error(const char* errstring, const char* where = NULL) {
+ m_errno = 0;
+ m_errstring = errstring;
+ m_where = where;
+ }
+ MP4Error(int err, const char* errstring, const char* where) {
+ m_errno = err;
+ m_errstring = errstring;
+ m_where = where;
+ }
+
+ void Print(FILE* pFile = stderr);
+
+ 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);
+ return tv.tv_sec + 209606400; // MP4 start date is 1/1/1904
+}
+
+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,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. 2000, 2001. All Rights Reserved.
+ *
+ * Contributor(s):
+ * Dave Mackie [email protected]
+ */
+
+#ifndef __MPEG4IP_INCLUDED__
+#define __MPEG4IP_INCLUDED__
+
+/* project wide applicable stuff here */
+
+#include "systems.h"
+
+#ifndef FALSE
+#define FALSE 0
+#endif
+#ifndef TRUE
+#define TRUE 1
+#endif
+
+#ifndef __cplusplus
+#ifndef bool
+typedef unsigned char bool;
+#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 ROUND
+# ifdef HAVE_RINT
+# define ROUND(f) rint(f)
+# else
+# define ROUND(f) (int)(floor((f) + 0.5))
+# endif
+#endif
+
+#endif /* __MPEG4IP_INCLUDED__ */
+
--- /dev/null
+++ b/common/mp4v2/need_for_win32.c
@@ -1,0 +1,12 @@
+#include "systems.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 [email protected]
+ */
+
+#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));
+ 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 [email protected]
+ */
+
+#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 [email protected]
+ */
+
+#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 [email protected]
+ */
+
+#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 [email protected]
+ */
+
+#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 [email protected]
+ */
+
+#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,1317 @@
+/*
+ * 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 [email protected]
+ */
+
+#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)
+{
+ InitPayload();
+
+ if (ppPayloadName) {
+ if (m_pRtpMapProperty) {
+ const char* pRtpMap = m_pRtpMapProperty->GetValue();
+ char* pSlash = strchr(pRtpMap, '/');
+
+ u_int32_t length;
+ if (pSlash) {
+ length = pSlash - pRtpMap;
+ } else {
+ length = strlen(pRtpMap);
+ }
+
+ *ppPayloadName = (char*)MP4Calloc(length + 1);
+ strncpy(*ppPayloadName, pRtpMap, length);
+ } else {
+ *ppPayloadName = NULL;
+ }
+ }
+
+ 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)
+{
+ InitRefTrack();
+ InitPayload();
+
+ ASSERT(m_pRtpMapProperty);
+ ASSERT(m_pPayloadNumberProperty);
+ ASSERT(m_pMaxPacketSizeProperty);
+
+ char* rtpMapBuf = (char*)MP4Malloc(strlen(payloadName) + 16);
+ sprintf(rtpMapBuf, "%s/%u", payloadName, GetTimeScale());
+ 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);
+ sprintf(sdpBuf,
+ "m=%s 0 RTP/AVP %u\015\012"
+ "a=rtpmap:%u %s\015\012"
+ "a=control:trackID=%u\015\012"
+ "a=mpeg4-esid:%u\015\012",
+ sdpMediaType, payloadNumber,
+ payloadNumber, rtpMapBuf,
+ m_trackId,
+ 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(true);
+
+ 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);
+ 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,344 @@
+/*
+ * 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 [email protected]
+ */
+
+#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() = NULL;
+ virtual void GetData(u_int8_t* pDest) = NULL;
+
+ 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);
+
+ 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);
+
+ void SetPayload(
+ const char* payloadName,
+ u_int8_t payloadNumber,
+ u_int16_t maxPayloadSize);
+
+ 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__ */
--- /dev/null
+++ b/common/mp4v2/systems.h
@@ -1,0 +1,216 @@
+/*
+ * 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 [email protected]
+ * Bill May [email protected]
+ */
+
+#ifdef WIN32
+#define HAVE_IN_PORT_T
+#define HAVE_SOCKLEN_T
+#include "win32_ver.h"
+#else
+#include <config.h>
+#endif
+
+#ifndef __SYSTEMS_H__
+#define __SYSTEMS_H__
+
+
+
+#ifdef WIN32
+
+#define _WIN32_WINNT 0x0400
+#include <windows.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 char 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 unsigned 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 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 LLD "%I64d"
+#define LLU "%I64u"
+#define LLX "%I64x"
+#define M_LLU 1000i64
+#define C_LLU 100i64
+#define I_LLU 1i64
+
+#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"
+
+#else /* UNIX */
+
+#include <stdio.h>
+#include <errno.h>
+#include <stdlib.h>
+
+#ifdef HAVE_INTTYPES_H
+#include <inttypes.h>
+#else
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#else
+#error "Don't have stdint.h or inttypes.h - no way to get uint8_t"
+#endif
+#endif
+
+#include <unistd.h>
+#include <fcntl.h>
+#include <netinet/in.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <syslog.h>
+#include <string.h>
+#include <ctype.h>
+#include <netdb.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#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
+#define MAX_UINT64 -1LLU
+#define LLD "%lld"
+#define LLU "%llu"
+#define LLX "%llx"
+#define M_LLU 1000LLU
+#define C_LLU 100LLU
+#define I_LLU 1LLU
+#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"
+#endif /* define unix */
+
+#include <stdarg.h>
+typedef void (*error_msg_func_t)(int loglevel,
+ const char *lib,
+ const char *fmt,
+ va_list ap);
+
+#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 uint8_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
+#endif /* __SYSTEMS_H__ */
--- /dev/null
+++ b/common/mp4v2/win32_ver.h
@@ -1,0 +1,2 @@
+#define PACKAGE "mpeg4ip"
+#define VERSION "0.9.2.8"
--- /dev/null
+++ b/frontend/audio.c
@@ -1,0 +1,93 @@
+/*
+** FAAD - Freeware Advanced Audio Decoder
+** Copyright (C) 2002 M. Bakker
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+**
+** $Id: audio.c,v 1.1 2002/01/15 12:58:38 menno Exp $
+**/
+
+#include <io.h>
+#include <fcntl.h>
+#include <sndfile.h>
+#include <faad.h>
+#include "audio.h"
+
+
+audio_file *open_audio_file(char *infile, int samplerate, int channels,
+ int outputFormat, int fileType)
+{
+ audio_file *aufile = malloc(sizeof(audio_file));
+
+ aufile->outputFormat = outputFormat;
+
+ aufile->sfinfo.samplerate = samplerate;
+ switch (outputFormat)
+ {
+ case FAAD_FMT_16BIT:
+ aufile->sfinfo.pcmbitwidth = 16;
+ aufile->sfinfo.format = ((1<<(fileType+15)) | SF_FORMAT_PCM);
+ break;
+ case FAAD_FMT_24BIT:
+ aufile->sfinfo.pcmbitwidth = 24;
+ aufile->sfinfo.format = ((1<<(fileType+15)) | SF_FORMAT_PCM);
+ break;
+ case FAAD_FMT_32BIT:
+ aufile->sfinfo.pcmbitwidth = 32;
+ aufile->sfinfo.format = ((1<<(fileType+15)) | SF_FORMAT_PCM);
+ break;
+ case FAAD_FMT_FLOAT:
+ aufile->sfinfo.pcmbitwidth = 32;
+ aufile->sfinfo.format = ((1<<(fileType+15)) | SF_FORMAT_FLOAT);
+ break;
+ }
+ aufile->sfinfo.channels = channels;
+ aufile->sfinfo.samples = 0;
+ if(infile[0] == '-')
+ {
+ setmode(fileno(stdout), O_BINARY);
+ }
+ aufile->sndfile = sf_open_write(infile, &aufile->sfinfo);
+
+ if (aufile->sndfile == NULL)
+ {
+ sf_perror(NULL);
+ if (aufile) free(aufile);
+ return NULL;
+ }
+
+ return aufile;
+}
+
+int write_audio_file(audio_file *aufile, void *sample_buffer, int samples)
+{
+ switch (aufile->outputFormat)
+ {
+ case FAAD_FMT_16BIT:
+ return sf_write_short(aufile->sndfile, (short*)sample_buffer, samples);
+ case FAAD_FMT_24BIT:
+ case FAAD_FMT_32BIT:
+ return sf_write_int(aufile->sndfile, (int*)sample_buffer, samples);
+ case FAAD_FMT_FLOAT:
+ return sf_write_float(aufile->sndfile, (float*)sample_buffer, samples);
+ }
+}
+
+void close_audio_file(audio_file *aufile)
+{
+ sf_close(aufile->sndfile);
+
+ if (aufile) free(aufile);
+}
\ No newline at end of file
--- /dev/null
+++ b/frontend/audio.h
@@ -1,0 +1,45 @@
+/*
+** FAAD - Freeware Advanced Audio Decoder
+** Copyright (C) 2002 M. Bakker
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+**
+** $Id: audio.h,v 1.1 2002/01/15 12:58:38 menno Exp $
+**/
+
+#ifndef AUDIO_H_INCLUDED
+#define AUDIO_H_INCLUDED
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+typedef struct
+{
+ int outputFormat;
+ SF_INFO sfinfo;
+ SNDFILE *sndfile;
+} audio_file;
+
+audio_file *open_audio_file(char *infile, int samplerate, int channels,
+ int outputFormat, int fileType);
+int write_audio_file(audio_file *aufile, void *sample_buffer, int samples);
+void close_audio_file(audio_file *aufile);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
--- a/frontend/faad.dsp
+++ b/frontend/faad.dsp
@@ -42,7 +42,7 @@
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
-# ADD CPP /nologo /W3 /GX /O2 /I "../include" /I "../common/faad" /I "../common/libsndfile/src" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /W3 /GX /O2 /I "../include" /I "../common/mp4v2" /I "../common/faad" /I "../common/libsndfile/src" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD BASE RSC /l 0x413 /d "NDEBUG"
# ADD RSC /l 0x413 /d "NDEBUG"
BSC32=bscmake.exe
@@ -50,7 +50,7 @@
# ADD BSC32 /nologo
LINK32=xilink6.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /profile /machine:I386
+# ADD LINK32 ws2_32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /profile /machine:I386
!ELSEIF "$(CFG)" == "faad - Win32 Debug"
@@ -66,7 +66,7 @@
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
-# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "../include" /I "../common/faad" /I "../common/libsndfile/src" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "../include" /I "../common/mp4v2" /I "../common/faad" /I "../common/libsndfile/src" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD BASE RSC /l 0x413 /d "_DEBUG"
# ADD RSC /l 0x413 /d "_DEBUG"
BSC32=bscmake.exe
@@ -74,7 +74,7 @@
# ADD BSC32 /nologo
LINK32=xilink6.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 ws2_32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
!ENDIF
@@ -87,6 +87,10 @@
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
+SOURCE=.\audio.c
+# End Source File
+# Begin Source File
+
SOURCE=..\common\faad\getopt.c
# End Source File
# Begin Source File
@@ -99,6 +103,10 @@
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
+SOURCE=.\audio.h
+# End Source File
+# Begin Source File
+
SOURCE=..\include\faad.h
# End Source File
# Begin Source File
@@ -107,7 +115,23 @@
# End Source File
# Begin Source File
+SOURCE=..\common\mp4v2\mp4.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\common\mp4v2\mpeg4ip.h
+# End Source File
+# Begin Source File
+
SOURCE=..\common\libsndfile\src\sndfile.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\common\mp4v2\systems.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\common\mp4v2\win32_ver.h
# End Source File
# End Group
# End Target
--- a/frontend/faad.dsw
+++ b/frontend/faad.dsw
@@ -17,11 +17,26 @@
Begin Project Dependency
Project_Dep_Name libsndfile
End Project Dependency
+ Begin Project Dependency
+ Project_Dep_Name libmp4v2_st
+ End Project Dependency
}}}
###############################################################################
Project: "libfaad"=..\libfaad\libfaad.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Project: "libmp4v2_st"=..\common\mp4v2\libmp4v2_st60.dsp - Package Owner=<4>
Package=<5>
{{{
--- a/frontend/main.c
+++ b/frontend/main.c
@@ -16,7 +16,7 @@
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
-** $Id: main.c,v 1.1 2002/01/14 19:15:55 menno Exp $
+** $Id: main.c,v 1.2 2002/01/15 12:58:38 menno Exp $
**/
#ifdef _WIN32
@@ -27,14 +27,15 @@
#endif
#include <stdio.h>
-#include <io.h>
-#include <fcntl.h>
#include <stdlib.h>
#include <getopt.h>
#include <faad.h>
#include <sndfile.h>
+#include <mp4.h>
+#include "audio.h"
+
#ifndef min
#define min(a,b) ( (a) < (b) ? (a) : (b) )
#endif
@@ -45,7 +46,7 @@
/* FAAD file buffering routines */
/* declare buffering variables */
#define DEC_BUFF_VARS \
- int fileread, tagsize, bytesconsumed, k; \
+ int fileread, bytesconsumed, k; \
int buffercount = 0, buffer_index = 0; \
unsigned char *buffer;
@@ -140,32 +141,25 @@
fprintf(stderr, " -l Use Long Term Prediction (for RAW files).\n");
fprintf(stderr, " -w Write output to stdio instead of a file.\n");
fprintf(stderr, "Example:\n");
- fprintf(stderr, " faad -o aac infile.aac\n");
+ fprintf(stderr, " faad infile.aac\n");
+ fprintf(stderr, " faad infile.mp4\n");
+ fprintf(stderr, " faad -o outfile.wav infile.aac\n");
+ fprintf(stderr, " faad -w infile.aac > outfile.wav\n");
return;
}
-int main(int argc, char *argv[])
+int decodeAACfile(char *aacfile, char *sndfile, int to_stdout,
+ int def_srate, int use_ltp, int outputFormat, int fileType)
{
- void *sample_buffer;
- int writeToStdio = 0;
- int def_sr_set = 0;
- int use_ltp = 0;
- int def_srate;
+ int tagsize;
unsigned long samplerate, channels;
- int format = 1;
- int outputFormat = FAAD_FMT_16BIT;
- int outfile_set = 0;
- int showHelp = 0;
- char *fnp;
- char aacFileName[255];
- char audioFileName[255];
+ void *sample_buffer;
- SNDFILE *sndfile = NULL;
- SF_INFO sfinfo;
-
FILE *infile;
+ audio_file *aufile;
+
faacDecHandle hDecoder;
faacDecFrameInfo frameInfo;
faacDecConfigurationPtr config;
@@ -175,6 +169,319 @@
int first_time = 1;
+ /* declare variables for buffering */
+ DEC_BUFF_VARS
+
+
+ infile = fopen(aacfile, "rb");
+ if (infile == NULL)
+ {
+ /* unable to open file */
+ fprintf(stderr, "Error opening file: %s\n", aacfile);
+ return 1;
+ }
+ INIT_BUFF(infile)
+
+ tagsize = id3v2_tag(buffer);
+ if (tagsize) {
+ UPDATE_BUFF_SKIP(tagsize)
+ }
+
+ hDecoder = faacDecOpen();
+
+ /* Set the default object type and samplerate */
+ /* This is useful for RAW AAC files */
+ config = faacDecGetCurrentConfiguration(hDecoder);
+ if (def_srate)
+ config->defSampleRate = def_srate;
+ if (use_ltp)
+ config->defObjectType = LTP;
+ config->outputFormat = outputFormat;
+
+ faacDecSetConfiguration(hDecoder, config);
+
+ if((bytesconsumed = faacDecInit(hDecoder, buffer, &samplerate,
+ &channels)) < 0)
+ {
+ /* If some error initializing occured, skip the file */
+ fprintf(stderr, "Error initializing decoder library.\n");
+ END_BUFF
+ faacDecClose(hDecoder);
+ fclose(infile);
+ return 1;
+ }
+
+ /* update buffer */
+ UPDATE_BUFF_READ
+
+ do
+ {
+ /* update buffer */
+ UPDATE_BUFF_READ
+
+ sample_buffer = faacDecDecode(hDecoder, &frameInfo, buffer);
+
+ /* update buffer indices */
+ UPDATE_BUFF_IDX(frameInfo)
+
+ if (frameInfo.error > 0)
+ {
+ fprintf(stderr, "Error: %s\n",
+ faacDecGetErrorMessage(frameInfo.error));
+ }
+
+ percent = min((int)(buffer_index*100)/fileread, 100);
+ if (percent > old_percent)
+ {
+ old_percent = percent;
+ sprintf(percents, "%d%% decoding %s.", percent, aacfile);
+ fprintf(stderr, "%s\r", percents);
+#ifdef _WIN32
+ SetConsoleTitle(percents);
+#endif
+ }
+
+ /* open the sound file now that the number of channels are known */
+ if (first_time && !frameInfo.error)
+ {
+ if(!to_stdout)
+ {
+ aufile = open_audio_file(sndfile, samplerate, frameInfo.channels,
+ outputFormat, fileType);
+ } else {
+ setmode(fileno(stdout), O_BINARY);
+ aufile = open_audio_file("-", samplerate, frameInfo.channels,
+ outputFormat, fileType);
+ }
+ if (aufile == NULL)
+ {
+ END_BUFF
+ faacDecClose(hDecoder);
+ fclose(infile);
+ return 0;
+ }
+ first_time = 0;
+ }
+
+ if ((frameInfo.error == 0) && (frameInfo.samples > 0))
+ {
+ write_audio_file(aufile, sample_buffer, frameInfo.samples);
+ }
+
+ if (IS_FILE_END)
+ sample_buffer = NULL; /* to make sure it stops now */
+
+ } while (sample_buffer != NULL);
+
+
+ faacDecClose(hDecoder);
+
+ fclose(infile);
+
+ close_audio_file(aufile);
+
+ END_BUFF
+
+ return frameInfo.error;
+}
+
+int use_ltp;
+
+int GetAACTrack(MP4FileHandle *infile)
+{
+ /* find AAC track */
+ int i;
+ int numTracks = MP4GetNumberOfTracks(infile, NULL);
+
+ for (i = 0; i < numTracks; i++)
+ {
+ MP4TrackId trackId = MP4FindTrackId(infile, i, NULL);
+ const char* trackType = MP4GetTrackType(infile, trackId);
+
+ if (!strcmp(trackType, MP4_AUDIO_TRACK_TYPE))
+ {
+ int type = MP4GetTrackAudioType(infile, trackId);
+
+ switch (type)
+ {
+ case MP4_MPEG4_AUDIO_TYPE:
+ /* could be LTP */
+ use_ltp = 1;
+
+ return trackId;
+ case MP4_MPEG2_AAC_MAIN_AUDIO_TYPE:
+ case MP4_MPEG2_AAC_LC_AUDIO_TYPE:
+ case MP4_MPEG2_AAC_SSR_AUDIO_TYPE:
+ /* MPEG2: no LTP */
+ use_ltp = 0;
+
+ return trackId;
+ }
+ }
+ }
+
+ /* can't decode this */
+ return -1;
+}
+
+int decodeMP4file(char *mp4file, char *sndfile, int to_stdout,
+ int outputFormat, int fileType)
+{
+ int track, srate;
+ unsigned long samplerate, channels;
+ void *sample_buffer;
+
+ MP4FileHandle *infile;
+ MP4SampleId sampleId, numSamples;
+
+ audio_file *aufile;
+
+ faacDecHandle hDecoder;
+ faacDecConfigurationPtr config;
+ faacDecFrameInfo frameInfo;
+
+ unsigned char *buffer;
+ int buffer_size;
+
+ char percents[200];
+ int percent, old_percent = -1;
+
+ int first_time = 1;
+
+ infile = MP4Read(mp4file, 0);
+ if (!infile)
+ {
+ /* unable to open file */
+ fprintf(stderr, "Error opening file: %s\n", mp4file);
+ return 1;
+ }
+
+ use_ltp = 0;
+
+ if ((track = GetAACTrack(infile)) < 0)
+ {
+ fprintf(stderr, "Unable to find correct AAC sound track in the MP4 file.\n");
+ MP4Close(infile);
+ return 1;
+ }
+ srate = MP4GetTrackTimeScale(infile, track);
+
+ hDecoder = faacDecOpen();
+
+ /* Set the default object type and samplerate */
+ /* This is useful for RAW AAC files */
+ config = faacDecGetCurrentConfiguration(hDecoder);
+ config->defSampleRate = srate;
+ if (use_ltp)
+ config->defObjectType = LTP;
+ config->outputFormat = outputFormat;
+
+ faacDecSetConfiguration(hDecoder, config);
+
+
+ if(faacDecInit(hDecoder, NULL, &samplerate,
+ &channels) < 0)
+ {
+ /* If some error initializing occured, skip the file */
+ fprintf(stderr, "Error initializing decoder library.\n");
+ faacDecClose(hDecoder);
+ MP4Close(infile);
+ return 1;
+ }
+
+ numSamples = MP4GetTrackNumberOfSamples(infile, track);
+
+ for (sampleId = 1; sampleId <= numSamples; sampleId++)
+ {
+ int rc;
+
+ /* get acces unit from MP4 file */
+ buffer = NULL;
+ buffer_size = 0;
+
+ rc = MP4ReadSample(infile, track, sampleId, &buffer, &buffer_size,
+ NULL, NULL, NULL, NULL);
+ if (rc == 0)
+ {
+ fprintf(stderr, "Reading from MP4 file failed.\n");
+ faacDecClose(hDecoder);
+ MP4Close(infile);
+ return 1;
+ }
+
+ sample_buffer = faacDecDecode(hDecoder, &frameInfo, buffer);
+
+ if (frameInfo.error > 0)
+ {
+ fprintf(stderr, "Error: %s\n",
+ faacDecGetErrorMessage(frameInfo.error));
+ }
+
+ percent = min((int)(sampleId*100)/numSamples, 100);
+ if (percent > old_percent)
+ {
+ old_percent = percent;
+ sprintf(percents, "%d%% decoding %s.", percent, mp4file);
+ fprintf(stderr, "%s\r", percents);
+#ifdef _WIN32
+ SetConsoleTitle(percents);
+#endif
+ }
+
+ /* open the sound file now that the number of channels are known */
+ if (first_time && !frameInfo.error)
+ {
+ if(!to_stdout)
+ {
+ aufile = open_audio_file(sndfile, srate, frameInfo.channels,
+ outputFormat, fileType);
+ } else {
+ setmode(fileno(stdout), O_BINARY);
+ aufile = open_audio_file("-", srate, frameInfo.channels,
+ outputFormat, fileType);
+ }
+ if (aufile == NULL)
+ {
+ faacDecClose(hDecoder);
+ MP4Close(infile);
+ return 0;
+ }
+ first_time = 0;
+ }
+
+ if ((frameInfo.error == 0) && (frameInfo.samples > 0))
+ {
+ write_audio_file(aufile, sample_buffer, frameInfo.samples);
+ }
+ }
+
+
+ faacDecClose(hDecoder);
+
+ MP4Close(infile);
+
+ close_audio_file(aufile);
+
+ return frameInfo.error;
+}
+
+int main(int argc, char *argv[])
+{
+ int result;
+ int writeToStdio = 0;
+ int use_ltp = 0;
+ int def_srate = 0;
+ int format = 1;
+ int outputFormat = FAAD_FMT_16BIT;
+ int outfile_set = 0;
+ int showHelp = 0;
+ int mp4file = 0;
+ char *fnp;
+ char aacFileName[255];
+ char audioFileName[255];
+
+ FILE *infile;
+
/* System dependant types */
#ifdef _WIN32
long begin, end;
@@ -182,9 +489,6 @@
clock_t begin;
#endif
- /* declare variables for buffering */
- DEC_BUFF_VARS
-
fprintf(stderr, "FAAD (Freeware AAC Decoder) Compiled on: " __DATE__ "\n");
fprintf(stderr, "Copyright: M. Bakker\n");
fprintf(stderr, " http://www.audiocoding.com\n\n");
@@ -226,9 +530,8 @@
if (optarg) {
char dr[10];
if (sscanf(optarg, "%s", dr) < 1) {
- def_sr_set = 0;
+ def_srate = 0;
} else {
- def_sr_set = 1;
def_srate = atoi(dr);
}
}
@@ -288,48 +591,7 @@
begin = clock();
#endif
- infile = fopen(aacFileName, "rb");
- if (infile == NULL)
- {
- /* unable to open file */
- fprintf(stderr, "Error opening file: %s\n", aacFileName);
- return 1;
- }
- INIT_BUFF(infile)
- tagsize = id3v2_tag(buffer);
- if (tagsize) {
- UPDATE_BUFF_SKIP(tagsize)
- }
-
- hDecoder = faacDecOpen();
-
- /* Set the default object type and samplerate */
- /* This is useful for RAW AAC files */
- config = faacDecGetCurrentConfiguration(hDecoder);
- if (def_sr_set)
- config->defSampleRate = def_srate;
- if (use_ltp)
- config->defObjectType = LTP;
- config->outputFormat = outputFormat;
-
- faacDecSetConfiguration(hDecoder, config);
-
- if((bytesconsumed = faacDecInit(hDecoder, buffer, &samplerate,
- &channels)) < 0)
- {
- /* If some error initializing occured, skip the file */
- fprintf(stderr, "Error initializing decoder library.\n");
- END_BUFF
- faacDecClose(hDecoder);
- fclose(infile);
- return 1;
- }
-
- /* update buffer */
- UPDATE_BUFF_READ
-
-
/* Only calculate the path and open the file for writing if
we are not writing to stdout.
*/
@@ -345,110 +607,21 @@
strcat(audioFileName, file_ext[format]);
}
+ fnp = (char *)strrchr(aacFileName, '.');
+ if (!stricmp(fnp, ".MP4"))
+ mp4file = 1;
- do
+ if (mp4file)
{
- /* update buffer */
- UPDATE_BUFF_READ
+ result = decodeMP4file(aacFileName, audioFileName, writeToStdio,
+ outputFormat, format);
+ } else {
+ result = decodeAACfile(aacFileName, audioFileName, writeToStdio,
+ def_srate, use_ltp, outputFormat, format);
+ }
- sample_buffer = faacDecDecode(hDecoder, &frameInfo, buffer);
- /* update buffer indices */
- UPDATE_BUFF_IDX(frameInfo)
-
- if (frameInfo.error > 0)
- {
- fprintf(stderr, "Error: %s\n",
- faacDecGetErrorMessage(frameInfo.error));
- }
-
- percent = min((int)(buffer_index*100)/fileread, 100);
- if (percent > old_percent)
- {
- old_percent = percent;
- sprintf(percents, "%d%% decoding %s.", percent, aacFileName);
- fprintf(stderr, "%s\r", percents);
-#ifdef _WIN32
- SetConsoleTitle(percents);
-#endif
- }
-
- /* open the sound file now that the number of channels are known */
- if (first_time && !frameInfo.error)
- {
- sfinfo.samplerate = samplerate;
- switch (outputFormat)
- {
- case FAAD_FMT_16BIT:
- sfinfo.pcmbitwidth = 16;
- sfinfo.format = ((1<<(format+15)) | SF_FORMAT_PCM);
- break;
- case FAAD_FMT_24BIT:
- sfinfo.pcmbitwidth = 24;
- sfinfo.format = ((1<<(format+15)) | SF_FORMAT_PCM);
- break;
- case FAAD_FMT_32BIT:
- sfinfo.pcmbitwidth = 32;
- sfinfo.format = ((1<<(format+15)) | SF_FORMAT_PCM);
- break;
- case FAAD_FMT_FLOAT:
- sfinfo.pcmbitwidth = 32;
- sfinfo.format = ((1<<(format+15)) | SF_FORMAT_FLOAT);
- break;
- }
- sfinfo.channels = frameInfo.channels;
- sfinfo.samples = 0;
- if(!writeToStdio)
- {
- sndfile = sf_open_write(audioFileName, &sfinfo);
- } else {
- setmode(fileno(stdout), O_BINARY);
- sndfile = sf_open_write("-", &sfinfo);
- }
-
- if (sndfile == NULL)
- {
- sf_perror(NULL);
- END_BUFF
- faacDecClose(hDecoder);
- fclose(infile);
- return 1;
- }
-
- first_time = 0;
- }
-
- if ((frameInfo.error == 0) && (frameInfo.samples > 0))
- {
- switch (outputFormat)
- {
- case FAAD_FMT_16BIT:
- sf_write_short(sndfile, (short*)sample_buffer, frameInfo.samples);
- break;
- case FAAD_FMT_24BIT:
- case FAAD_FMT_32BIT:
- sf_write_int(sndfile, (int*)sample_buffer, frameInfo.samples);
- break;
- case FAAD_FMT_FLOAT:
- sf_write_float(sndfile, (float*)sample_buffer, frameInfo.samples);
- break;
- }
- }
-
- if (IS_FILE_END)
- sample_buffer = NULL; /* to make sure it stops now */
-
- } while (sample_buffer != NULL);
-
-
- faacDecClose(hDecoder);
-
- fclose(infile);
-
- if (sndfile)
- sf_close(sndfile);
-
- if (!frameInfo.error)
+ if (!result)
{
#ifdef _WIN32
end = GetTickCount();
@@ -463,8 +636,6 @@
(float)(clock() - begin)/(float)CLOCKS_PER_SEC);
#endif
}
-
- END_BUFF
return 0;
}
--- a/libfaad/decoder.c
+++ b/libfaad/decoder.c
@@ -16,7 +16,7 @@
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
-** $Id: decoder.c,v 1.1 2002/01/14 19:15:55 menno Exp $
+** $Id: decoder.c,v 1.2 2002/01/15 12:58:56 menno Exp $
**/
#include <stdlib.h>
@@ -128,38 +128,41 @@
hDecoder->sf_index = get_sr_index(hDecoder->config.defSampleRate);
hDecoder->object_type = hDecoder->config.defObjectType;
- faad_initbits(&ld, buffer);
-
- /* Check if an ADIF header is present */
- if ((buffer[0] == 'A') && (buffer[1] == 'D') &&
- (buffer[2] == 'I') && (buffer[3] == 'F'))
+ if (buffer != NULL)
{
- hDecoder->adif_header_present = 1;
+ faad_initbits(&ld, buffer);
- get_adif_header(&adif, &ld);
+ /* Check if an ADIF header is present */
+ if ((buffer[0] == 'A') && (buffer[1] == 'D') &&
+ (buffer[2] == 'I') && (buffer[3] == 'F'))
+ {
+ hDecoder->adif_header_present = 1;
- hDecoder->sf_index = adif.pce.sf_index;
- hDecoder->object_type = adif.pce.object_type;
+ get_adif_header(&adif, &ld);
- *samplerate = sample_rates[hDecoder->sf_index];
- *channels = adif.pce.channels;
+ hDecoder->sf_index = adif.pce.sf_index;
+ hDecoder->object_type = adif.pce.object_type;
- return bit2byte(faad_get_processed_bits(&ld));
+ *samplerate = sample_rates[hDecoder->sf_index];
+ *channels = adif.pce.channels;
- /* Check if an ADTS header is present */
- } else if (faad_showbits(&ld, 12) == 0xfff) {
- hDecoder->adts_header_present = 1;
+ return bit2byte(faad_get_processed_bits(&ld));
- adts_frame(&adts, &ld);
+ /* Check if an ADTS header is present */
+ } else if (faad_showbits(&ld, 12) == 0xfff) {
+ hDecoder->adts_header_present = 1;
- hDecoder->sf_index = adts.sf_index;
- hDecoder->object_type = adts.profile;
+ adts_frame(&adts, &ld);
- *samplerate = sample_rates[hDecoder->sf_index];
- *channels = (adts.channel_configuration > 6) ?
- 2 : adts.channel_configuration;
+ hDecoder->sf_index = adts.sf_index;
+ hDecoder->object_type = adts.profile;
- return 0;
+ *samplerate = sample_rates[hDecoder->sf_index];
+ *channels = (adts.channel_configuration > 6) ?
+ 2 : adts.channel_configuration;
+
+ return 0;
+ }
}
*samplerate = sample_rates[hDecoder->sf_index];