annotate Input/aac/libmp4v2/INTERNALS @ 16:6a86fdd4dea4 trunk

[svn] Replacement libmp4v2.
author nenolod
date Mon, 24 Oct 2005 15:33:32 -0700
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
1 January 7, 2002
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
2
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
3 MP4V2 LIBRARY INTERNALS
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
4 =======================
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
5
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
6 This document provides an overview of the internals of the mp4v2 library
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
7 to aid those who wish to modify and extend it. Before reading this document,
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
8 I recommend familiarizing yourself with the MP4 (or Quicktime) file format
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
9 standard and the mp4v2 library API. The API is described in a set of man pages
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
10 in mpeg4ip/doc/mp4v2, or if you prefer by looking at mp4.h.
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
11
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
12 All the library code is written in C++, however the library API follows uses
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
13 C calling conventions hence is linkable by both C and C++ programs. The
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
14 library has been compiled and used on Linux, BSD, Windows, and Mac OS X.
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
15 Other than libc, the library has no external dependencies, and hence can
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
16 be used independently of the mpeg4ip package if desired. The library is
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
17 used for both real-time recording and playback in mpeg4ip, and its runtime
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
18 performance is up to those tasks. On the IA32 architecture compiled with gcc,
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
19 the stripped library is approximately 600 KB code and initialized data.
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
20
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
21 It is useful to think of the mp4v2 library as consisting of four layers:
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
22 infrastructure, file format, generic tracks, and type specific track helpers.
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
23 A description of each layer follows, from the fundamental to the optional.
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
24
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
25
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
26 Infrastructure
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
27 ==============
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
28
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
29 The infrastructure layer provides basic file I/O, memory allocation,
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
30 error handling, string utilities, and protected arrays. The source files
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
31 for this layer are mp4file_io, mp4util, and mp4array.
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
32
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
33 Note that the array classes uses preprocessor macros instead of C++
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
34 templates. The rationale for this is to increase portability given the
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
35 sometimes incomplete support by some compilers for templates.
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
36
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
37
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
38 File Format
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
39 ===========
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
40
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
41 The file format layer provides the translation from the on-disk MP4 file
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
42 format to in-memory C++ structures and back to disk. It is intended
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
43 to exactly match the MP4 specification in syntax and semantics. It
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
44 represents the majority of the code.
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
45
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
46 There are three key structures at the file format layer: atoms, properties,
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
47 and descriptors.
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
48
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
49 Atoms are the primary containers within an mp4 file. They can contain
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
50 any combination of properties, other atoms, or descriptors.
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
51
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
52 The mp4atom files contain the base class for all the atoms, and provide
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
53 generic functions that cover most cases. Most atoms are covered in
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
54 atom_standard.cpp. Atoms that have a special read, generation or
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
55 write needs are contained in their subclass contained in file atom_<name>.cpp,
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
56 where <name> is the four letter name of the atom defined in the MP4
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
57 specification.
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
58
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
59 Atoms that only specifies the properties of the atom or the possible child
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
60 atoms in the case of a container atom are located in atom_standard.cpp.
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
61
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
62 In more specialized cases the atom specific file provides routines to
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
63 initialize, read, or write the atom.
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
64
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
65 Properties are the atomic pieces of information. The basic types of
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
66 properties are integers, floats, strings, and byte arrays. For integers
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
67 and floats there are subclasses that represent the different storage sizes,
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
68 e.g. 8, 16, 24, 32, and 64 bit integers. For strings, there is 1 property
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
69 class with a number of options regarding exact storage details, e.g. null
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
70 terminated, fixed length, counted.
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
71
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
72 For implementation reasons, there are also two special properties, table
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
73 and descriptor, that are actually containers for groups of properties.
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
74 I.e by making these containers provide a property interface much code can
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
75 be written in a generic fashion.
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
76
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
77 The mp4property files contain all the property related classes.
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
78
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
79 Descriptors are containers that derive from the MPEG conventions and use
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
80 different encoding rules than the atoms derived from the QuickTime file
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
81 format. This means more use of bitfields and conditional existence with
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
82 an emphasis on bit efficiency at the cost of encoding/decoding complexity.
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
83 Descriptors can contain other descriptors and/or properties.
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
84
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
85 The mp4descriptor files contain the generic base class for descriptors.
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
86 Also the mp4property files have a descriptor wrapper class that allows a
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
87 descriptor to behave as if it were a property. The specific descriptors
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
88 are implemented as subclasses of the base class descriptor in manner similar
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
89 to that of atoms. The descriptors, ocidescriptors, and qosqualifiers files
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
90 contain these implementations.
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
91
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
92 Each atom/property/descriptor has a name closely related to that in the
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
93 MP4 specification. The difference being that the mp4v2 library doesn't
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
94 use '-' or '_' in property names and capitalizes the first letter of each
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
95 word, e.g. "thisIsAPropertyName". A complete name specifies the complete
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
96 container path. The names follow the C/C++ syntax for elements and array
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
97 indices.
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
98
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
99 Examples are:
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
100 "moov.mvhd.duration"
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
101 "moov.trak[2].tkhd.duration"
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
102 "moov.trak[3].minf.mdia.stbl.stsz[101].sampleSize"
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
103
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
104 Note "*" can be used as a wildcard for an atom name (only). This is most
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
105 useful when dealing with the stsd atom which contains child atoms with
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
106 various names, but shared property names.
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
107
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
108 Note that internally when performance matters the code looks up a property
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
109 by name once, and then stores the returned pointer to the property class.
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
110
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
111 To add an atom, first you should see if an existing atom exists that
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
112 can be used. If not, you need to decide if special read/write or
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
113 generate properties need to be established; for example a property in the atom
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
114 changes other properties (adds, or subtracts). If there are no
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
115 special cases, add the atom properties to atom_standard.cpp. If there
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
116 are special properties, add a new file, add a new class to atoms.h, and
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
117 add the class to MP4Atom::CreateAtom in mp4atom.cpp.
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
118
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
119
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
120
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
121 Generic Tracks
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
122 ==============
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
123
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
124 The two entities at this level are the mp4 file as a whole and the tracks
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
125 which are contained with it. The mp4file and mp4track files contain the
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
126 implementation.
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
127
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
128 The critical work done by this layer is to map the collection of atoms,
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
129 properties, and descriptors that represent a media track into a useful,
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
130 and consistent set of operations. For example, reading or writing a media
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
131 sample of a track is a relatively simple operation from the library API
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
132 perspective. However there are numerous pieces of information in the mp4
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
133 file that need to be properly used and updated to do this. This layer
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
134 handles all those details.
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
135
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
136 Given familiarity with the mp4 spec, the code should be straight-forward.
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
137 What may not be immediately obvious are the functions to handle chunks of
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
138 media samples. These exist to allow optimization of the mp4 file layout by
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
139 reordering the chunks on disk to interleave the media sample chunks of
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
140 multiple tracks in time order. (See MP4Optimize API doc).
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
141
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
142
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
143 Type Specific Track Helpers
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
144 ===========================
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
145
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
146 This specialized code goes beyond the meta-information about tracks in
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
147 the mp4 file to understanding and manipulating the information in the
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
148 track samples. There are currently two helpers in the library:
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
149 the MPEG-4 Systems Helper, and the RTP Hint Track Helper.
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
150
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
151 The MPEG-4 Systems Helper is currently limited to creating the OD, BIFS,
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
152 and SDP information about a minimal audio/video scene consistent with
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
153 the Internet Streaming Media Alliance (ISMA) specifications. We will be
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
154 evaluating how best to generalize the library's helper functions for
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
155 MPEG-4 Systems without overburdening the implementation. The code for
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
156 this helper is found in the isma and odcommands files.
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
157
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
158 The RTP Hint Track Helper is more extensive in its support. The hint
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
159 tracks contain the track packetization information needed to build
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
160 RTP packets for streaming. The library can construct RTP packets based
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
161 on the hint track making RTP based servers significantly easier to write.
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
162
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
163 All code related to rtp hint tracks is in the rtphint files. It would also
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
164 be useful to look at test/mp4broadcaster and mpeg4ip/server/mp4creator for
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
165 examples of how this part of the library API can be used.
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
166
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
167
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
168 Library API
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
169 ===========
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
170
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
171 The library API is defined and implemented in the mp4 files. The API uses
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
172 C linkage conventions, and the mp4.h file adapts itself according to whether
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
173 C or C++ is the compilation mode.
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
174
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
175 All API calls are implemented in mp4.cpp and basically pass thru's to the
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
176 MP4File member functions. This ensures that the library has internal access
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
177 to the same functions as available via the API. All the calls in mp4.cpp use
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
178 C++ try/catch blocks to protect against any runtime errors in the library.
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
179 Upon error the library will print a diagnostic message if the verbostiy level
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
180 has MP4_DETAILS_ERROR set, and return a distinguished error value, typically
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
181 0 or -1.
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
182
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
183 The test and util subdirectories contain useful examples of how to
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
184 use the library. Also the mp4creator and mp4live programs within
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
185 mpeg4ip demonstrate more complete usage of the library API.
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
186
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
187
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
188 Debugging
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
189 =========
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
190
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
191 Since mp4 files are fairly complicated, extensive debugging support is
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
192 built into the library. Multi-level diagnostic messages are available
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
193 under the control of a verbosity bitmask described in the API.
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
194
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
195 Also the library provides the MP4Dump() call which provides an ASCII
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
196 version of the mp4 file meta-information. The mp4dump utilitity is a
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
197 wrapper executable around this function.
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
198
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
199 The mp4extract program is also provided in the utilities directory
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
200 which is useful for extracting a track from an mp4file and putting the
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
201 media data back into it's own file. It can also extract each sample of
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
202 a track into its own file it that is desired.
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
203
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
204 When all else fails, mp4 files are amenable to debugging by direct
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
205 examination. Since the atom names are four letter ASCII codes finding
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
206 reference points in a hex dump is feasible. On UNIX, the od command
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
207 is your friend: "od -t x1z -A x [-j 0xXXXXXX] foo.mp4" will print
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
208 a hex and ASCII dump, with hex addresses, starting optionally from
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
209 a specified offset. The library diagnostic messages can provide
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
210 information on where the library is reading or writing.
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
211
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
212
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
213 General caveats
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
214 ===============
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
215
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
216 The coding convention is to use the C++ throw operator whenever an
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
217 unrecoverable error occurs. This throw is caught at the API layer
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
218 in mp4.cpp and translated into an error value.
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
219
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
220 Be careful about indices. Internally, we follow the C/C++ convention
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
221 to use zero-based indices. However the MP4 spec uses one-based indices
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
222 for things like samples and hence the library API uses this convention.
6a86fdd4dea4 [svn] Replacement libmp4v2.
nenolod
parents:
diff changeset
223