2 * Copyright (c) 2005, David McPaul
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
8 * * Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
18 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
19 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
22 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
23 * OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include <MediaDefs.h>
33 #include <MediaFormats.h>
34 #include <SupportDefs.h>
39 typedef SoundDescriptionV1
* SoundDescPtr
;
40 typedef std::map
<uint32
, SoundDescPtr
, std::less
<uint32
> > SoundDescArray
;
41 typedef VideoDescriptionV0
* VideoDescPtr
;
42 typedef std::map
<uint32
, VideoDescPtr
, std::less
<uint32
> > VideoDescArray
;
43 typedef TimeToSample
* TimeToSamplePtr
;
44 typedef std::map
<uint32
, TimeToSamplePtr
, std::less
<uint32
> > TimeToSampleArray
;
45 typedef SampleToChunk
* SampleToChunkPtr
;
46 typedef std::map
<uint32
, SampleToChunkPtr
, std::less
<uint32
> > SampleToChunkArray
;
47 typedef ChunkToOffset
* ChunkToOffsetPtr
;
48 typedef std::map
<uint32
, ChunkToOffsetPtr
, std::less
<uint32
> > ChunkToOffsetArray
;
49 typedef SyncSample
* SyncSamplePtr
;
50 typedef std::map
<uint32
, SyncSamplePtr
, std::less
<uint32
> > SyncSampleArray
;
51 typedef SampleSizeEntry
* SampleSizeEntryPtr
;
52 typedef std::map
<uint32
, SampleSizeEntryPtr
, std::less
<uint32
> > SampleSizeArray
;
54 // Atom class for reading the movie header atom
55 class MVHDAtom
: public AtomBase
{
57 MVHDAtom(BPositionIO
*pStream
, off_t pstreamOffset
, uint32 patomType
, uint64 patomSize
);
59 void OnProcessMetaData();
60 char *OnGetAtomName();
61 uint32
getTimeScale() {return theHeader
.TimeScale
;};
62 uint32
getDuration() {return theHeader
.Duration
;};
68 // Atom class for reading the moov atom
69 class MOOVAtom
: public AtomContainer
{
71 MOOVAtom(BPositionIO
*pStream
, off_t pstreamOffset
, uint32 patomType
, uint64 patomSize
);
73 void OnProcessMetaData();
74 char *OnGetAtomName();
76 MVHDAtom
*getMVHDAtom();
78 MVHDAtom
*theMVHDAtom
;
81 // Atom class for reading the cmov atom
82 class CMOVAtom
: public AtomContainer
{
84 CMOVAtom(BPositionIO
*pStream
, off_t pstreamOffset
, uint32 patomType
, uint64 patomSize
);
87 BPositionIO
*OnGetStream();
88 void OnProcessMetaData();
89 void OnChildProcessingComplete();
91 char *OnGetAtomName();
93 BMallocIO
*theUncompressedStream
;
96 // Atom class for reading the dcom atom
97 class DCOMAtom
: public AtomBase
{
99 DCOMAtom(BPositionIO
*pStream
, off_t pstreamOffset
, uint32 patomType
, uint64 patomSize
);
101 void OnProcessMetaData();
102 char *OnGetAtomName();
103 uint32
getCompressionID() {return compressionID
;};
105 uint32 compressionID
;
108 // Atom class for reading the cmvd atom
109 class CMVDAtom
: public AtomBase
{
111 CMVDAtom(BPositionIO
*pStream
, off_t pstreamOffset
, uint32 patomType
, uint64 patomSize
);
113 void OnProcessMetaData();
114 char *OnGetAtomName();
115 uint32
getUncompressedSize() {return UncompressedSize
;};
116 uint8
*getCompressedData() {return Buffer
;};
117 uint32
getBufferSize() {return BufferSize
;};
119 uint32 UncompressedSize
;
124 // Atom class for reading the wide atom
125 class WIDEAtom
: public AtomBase
{
127 WIDEAtom(BPositionIO
*pStream
, off_t pstreamOffset
, uint32 patomType
, uint64 patomSize
);
129 void OnProcessMetaData();
130 char *OnGetAtomName();
134 // Atom class for reading the free atom
135 class FREEAtom
: public AtomBase
{
137 FREEAtom(BPositionIO
*pStream
, off_t pstreamOffset
, uint32 patomType
, uint64 patomSize
);
139 void OnProcessMetaData();
140 char *OnGetAtomName();
144 // Atom class for reading the preview atom
145 class PNOTAtom
: public AtomBase
{
147 PNOTAtom(BPositionIO
*pStream
, off_t pstreamOffset
, uint32 patomType
, uint64 patomSize
);
149 void OnProcessMetaData();
150 char *OnGetAtomName();
154 // Atom class for reading the time to sample atom
155 class STTSAtom
: public AtomBase
{
157 STTSAtom(BPositionIO
*pStream
, off_t pstreamOffset
, uint32 patomType
, uint64 patomSize
);
159 void OnProcessMetaData();
160 char *OnGetAtomName();
162 uint64
getSUMCounts() {return SUMCounts
;};
163 uint64
getSUMDurations() {return SUMDurations
;};
164 uint32
getSampleForTime(uint32 pTime
);
165 uint32
getSampleForFrame(uint32 pFrame
);
167 array_header theHeader
;
168 TimeToSampleArray theTimeToSampleArray
;
173 // Atom class for reading the sample to chunk atom
174 class STSCAtom
: public AtomBase
{
176 STSCAtom(BPositionIO
*pStream
, off_t pstreamOffset
, uint32 patomType
, uint64 patomSize
);
178 void OnProcessMetaData();
179 char *OnGetAtomName();
181 uint32
getChunkForSample(uint32 pSample
, uint32
*pOffsetInChunk
);
182 uint32
getFirstSampleInChunk(uint32 pChunkID
);
183 uint32
getNoSamplesInChunk(uint32 pChunkID
);
185 array_header theHeader
;
186 SampleToChunkArray theSampleToChunkArray
;
189 // Atom class for reading the chunk to offset atom
190 class STCOAtom
: public AtomBase
{
192 STCOAtom(BPositionIO
*pStream
, off_t pstreamOffset
, uint32 patomType
, uint64 patomSize
);
194 void OnProcessMetaData();
195 char *OnGetAtomName();
197 uint64
getOffsetForChunk(uint32 pChunkID
);
198 uint32
getTotalChunks() {return theHeader
.NoEntries
;};
201 // Read a single chunk offset from Stream
202 virtual uint64
OnGetChunkOffset();
205 array_header theHeader
;
206 ChunkToOffsetArray theChunkToOffsetArray
;
209 // Atom class for reading the sync sample atom
210 class STSSAtom
: public AtomBase
{
212 STSSAtom(BPositionIO
*pStream
, off_t pstreamOffset
, uint32 patomType
, uint64 patomSize
);
214 void OnProcessMetaData();
215 char *OnGetAtomName();
217 bool IsSyncSample(uint32 pSampleNo
);
219 array_header theHeader
;
220 SyncSampleArray theSyncSampleArray
;
223 // Atom class for reading the sample size atom
224 class STSZAtom
: public AtomBase
{
226 STSZAtom(BPositionIO
*pStream
, off_t pstreamOffset
, uint32 patomType
, uint64 patomSize
);
228 void OnProcessMetaData();
229 char *OnGetAtomName();
231 uint32
getSizeForSample(uint32 pSampleNo
);
232 bool IsSingleSampleSize();
234 SampleSizeHeader theHeader
;
235 SampleSizeArray theSampleSizeArray
;
238 // Atom class for reading the skip atom
239 class SKIPAtom
: public AtomBase
{
241 SKIPAtom(BPositionIO
*pStream
, off_t pstreamOffset
, uint32 patomType
, uint64 patomSize
);
243 void OnProcessMetaData();
244 char *OnGetAtomName();
248 // Atom class for reading the media data atom
249 class MDATAtom
: public AtomBase
{
251 MDATAtom(BPositionIO
*pStream
, off_t pstreamOffset
, uint32 patomType
, uint64 patomSize
);
253 void OnProcessMetaData();
254 char *OnGetAtomName();
258 class ESDSAtom
: public AtomBase
{
260 ESDSAtom(BPositionIO
*pStream
, off_t pstreamOffset
, uint32 patomType
, uint64 patomSize
);
262 void OnProcessMetaData();
263 char *OnGetAtomName();
270 // Atom class for reading the sdst atom
271 class STSDAtom
: public AtomBase
{
273 STSDAtom(BPositionIO
*pStream
, off_t pstreamOffset
, uint32 patomType
, uint64 patomSize
);
275 void OnProcessMetaData();
276 char *OnGetAtomName();
278 VideoDescriptionV0
getAsVideo();
279 SoundDescriptionV1
getAsAudio();
282 uint32
getMediaComponentSubType();
284 void ReadSoundDescription();
285 void ReadVideoDescription();
287 array_header theHeader
;
288 SoundDescArray theAudioDescArray
;
289 VideoDescArray theVideoDescArray
;
292 // Atom class for reading the track header atom
293 class TKHDAtom
: public AtomBase
{
295 TKHDAtom(BPositionIO
*pStream
, off_t pstreamOffset
, uint32 patomType
, uint64 patomSize
);
297 void OnProcessMetaData();
298 char *OnGetAtomName();
300 uint32
getDuration() {return theHeader
.Duration
;}; // duration is in the scale of the media
302 // Flags3 should contain the following
303 // 0x001 Track enabled
304 // 0x002 Track in Movie
305 // 0x004 Track in Preview
306 // 0x008 Track in Poster
307 // It seems active tracks have all 4 flags set?
309 bool IsActive() {return ((theHeader
.Flags3
== 0x0f) || (theHeader
.Flags3
== 0x03));};
317 // Atom class for reading the media header atom
318 class MDHDAtom
: public AtomBase
{
320 MDHDAtom(BPositionIO
*pStream
, off_t pstreamOffset
, uint32 patomType
, uint64 patomSize
);
322 void OnProcessMetaData();
323 char *OnGetAtomName();
325 // return duration in ms
326 bigtime_t
getDuration();
327 uint32
getTimeScale();
334 // Atom class for reading the video media header atom
335 class VMHDAtom
: public AtomBase
{
337 VMHDAtom(BPositionIO
*pStream
, off_t pstreamOffset
, uint32 patomType
, uint64 patomSize
);
339 void OnProcessMetaData();
340 char *OnGetAtomName();
344 // Atom class for reading the sound media header atom
345 class SMHDAtom
: public AtomBase
{
347 SMHDAtom(BPositionIO
*pStream
, off_t pstreamOffset
, uint32 patomType
, uint64 patomSize
);
349 void OnProcessMetaData();
350 char *OnGetAtomName();
354 // Atom class for reading the track atom
355 class TRAKAtom
: public AtomContainer
{
357 TRAKAtom(BPositionIO
*pStream
, off_t pstreamOffset
, uint32 patomType
, uint64 patomSize
);
359 void OnProcessMetaData();
360 char *OnGetAtomName();
361 void OnChildProcessingComplete();
363 bigtime_t
Duration(uint32 TimeScale
); // Return duration of track
364 uint32
FrameCount() {return framecount
;};
365 bool IsVideo(); // Is this a video track
366 bool IsAudio(); // Is this a audio track
367 // GetAudioMetaData() // If this is a audio track get the audio meta data
368 // GetVideoMetaData() // If this is a video track get the video meta data
370 uint32
getTimeForFrame(uint32 pFrame
, uint32 pTimeScale
);
371 uint32
getSampleForTime(uint32 pTime
);
372 uint32
getSampleForFrame(uint32 pFrame
);
373 uint32
getChunkForSample(uint32 pSample
, uint32
*pOffsetInChunk
);
374 uint64
getOffsetForChunk(uint32 pChunkID
);
375 uint32
getFirstSampleInChunk(uint32 pChunkID
);
376 uint32
getSizeForSample(uint32 pSample
);
377 uint32
getNoSamplesInChunk(uint32 pChunkID
);
378 uint32
getTotalChunks();
380 bool IsSyncSample(uint32 pSampleNo
);
381 bool IsSingleSampleSize();
384 uint32
getBytesPerSample();
386 TKHDAtom
*getTKHDAtom();
387 MDHDAtom
*getMDHDAtom();
389 TKHDAtom
*theTKHDAtom
;
390 MDHDAtom
*theMDHDAtom
;
393 uint32 bytespersample
;
396 // Atom class for reading the media container atom
397 class MDIAAtom
: public AtomContainer
{
399 MDIAAtom(BPositionIO
*pStream
, off_t pstreamOffset
, uint32 patomType
, uint64 patomSize
);
401 void OnProcessMetaData();
402 char *OnGetAtomName();
404 uint32
getMediaComponentSubType();
407 // Atom class for reading the media information atom
408 class MINFAtom
: public AtomContainer
{
410 MINFAtom(BPositionIO
*pStream
, off_t pstreamOffset
, uint32 patomType
, uint64 patomSize
);
412 void OnProcessMetaData();
413 char *OnGetAtomName();
415 uint32
getMediaComponentSubType();
418 // Atom class for reading the stbl atom
419 class STBLAtom
: public AtomContainer
{
421 STBLAtom(BPositionIO
*pStream
, off_t pstreamOffset
, uint32 patomType
, uint64 patomSize
);
423 void OnProcessMetaData();
424 char *OnGetAtomName();
426 uint32
getMediaComponentSubType();
429 // Atom class for reading the dinf atom
430 class DINFAtom
: public AtomContainer
{
432 DINFAtom(BPositionIO
*pStream
, off_t pstreamOffset
, uint32 patomType
, uint64 patomSize
);
434 void OnProcessMetaData();
435 char *OnGetAtomName();
438 // Atom class for reading the tmcd atom
439 class TMCDAtom
: public AtomBase
{
441 TMCDAtom(BPositionIO
*pStream
, off_t pstreamOffset
, uint32 patomType
, uint64 patomSize
);
443 void OnProcessMetaData();
444 char *OnGetAtomName();
448 // Atom class for reading the wave atom
449 class WAVEAtom
: public AtomBase
{
451 WAVEAtom(BPositionIO
*pStream
, off_t pstreamOffset
, uint32 patomType
, uint64 patomSize
);
453 void OnProcessMetaData();
454 char *OnGetAtomName();
455 wave_format_ex
getWaveFormat() {return theWaveFormat
;};
457 wave_format_ex theWaveFormat
;
460 // Atom class for reading the Media Handler atom
461 class HDLRAtom
: public AtomBase
{
463 HDLRAtom(BPositionIO
*pStream
, off_t pstreamOffset
, uint32 patomType
, uint64 patomSize
);
465 void OnProcessMetaData();
466 char *OnGetAtomName();
468 bool IsVideoHandler();
469 bool IsAudioHandler();
470 uint32
getMediaComponentSubType();
476 class FTYPAtom
: public AtomBase
{
478 FTYPAtom(BPositionIO
*pStream
, off_t pstreamOffset
, uint32 patomType
, uint64 patomSize
);
480 void OnProcessMetaData();
481 char *OnGetAtomName();
482 bool HasBrand(uint32 brand
);
486 uint32 minor_version
;
487 uint32 compatable_brands
[32]; // Should be infinite but we will settle for max 32