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.
25 #ifndef _MP4_FILE_READER_H
26 #define _MP4_FILE_READER_H
29 #include <MediaDefs.h>
30 #include <MediaFormats.h>
31 #include <SupportDefs.h>
33 #include "MP4Parser.h"
39 AtomArray atomChildren
;
42 BPositionIO
*theStream
;
44 AtomBase
*GetChildAtom(uint32 patomType
, uint32 offset
=0);
45 uint32
CountChildAtoms(uint32 patomType
);
47 TRAKAtom
*GetTrack(uint32 streamIndex
);
49 uint32
GetMovieTimeScale();
51 // Add a atom to the children array (return false on failure)
52 bool AddChild(AtomBase
*pChildAtom
);
54 AudioMetaData theAudio
;
55 VideoMetaData theVideo
;
56 mp4_stream_header theStreamHeader
;
57 mp4_main_header theMainHeader
;
59 MVHDAtom
*theMVHDAtom
;
60 std::map
<uint32
, TRAKAtom
*, std::less
<uint32
> > tracks
;
63 MP4FileReader(BPositionIO
*pStream
);
64 virtual ~MP4FileReader();
66 // getter for MVHDAtom
67 MVHDAtom
*GetMVHDAtom();
69 bool IsEndOfFile(off_t pPosition
);
71 bool IsEndOfData(off_t pPosition
);
73 // Is this a quicktime file
74 static bool IsSupported(BPositionIO
*source
);
76 // How many tracks in file
77 uint32
GetStreamCount();
79 // Duration defined by the movie header
80 bigtime_t
GetMovieDuration();
82 // The first video track duration indexed by streamIndex
83 bigtime_t
GetVideoDuration(uint32 streamIndex
);
84 // the first audio track duration indexed by streamIndex
85 bigtime_t
GetAudioDuration(uint32 streamIndex
);
86 // the max of all active audio or video durations
87 bigtime_t
GetMaxDuration();
89 // The no of frames in the video track indexed by streamIndex
90 uint32
GetFrameCount(uint32 streamIndex
);
91 // The no of chunks in the audio track indexed by streamIndex
92 uint32
GetAudioChunkCount(uint32 streamIndex
);
93 // Is stream (track) a video track
94 bool IsVideo(uint32 streamIndex
);
95 // Is stream (track) a audio track
96 bool IsAudio(uint32 streamIndex
);
99 uint64
GetOffsetForFrame(uint32 streamIndex
, uint32 pFrameNo
);
100 uint32
GetChunkForFrame(uint32 streamIndex
, uint32 pFrameNo
);
101 uint32
GetFrameSize(uint32 streamIndex
, uint32 pFrameNo
);
104 uint64
GetOffsetForChunk(uint32 streamIndex
, uint32 pChunkIndex
);
105 uint32
GetFirstFrameInChunk(uint32 streamIndex
, uint32 pChunkIndex
);
106 uint32
GetChunkSize(uint32 streamIndex
, uint32 pChunkIndex
);
107 uint32
GetNoFramesInChunk(uint32 streamIndex
, uint32 pChunkIndex
);
109 bool isValidChunkIndex(uint32 streamIndex
, uint32 pChunkIndex
);
110 bool isValidFrame(uint32 streamIndex
, uint32 pFrameNo
);
111 bool IsKeyFrame(uint32 streamIndex
, uint32 pFrameNo
);
113 bigtime_t
GetTimeForFrame(uint32 streamIndex
, uint32 pFrameNo
);
114 uint32
GetFrameForTime(uint32 streamIndex
, bigtime_t time
);
115 uint32
GetFrameForSample(uint32 streamIndex
, uint32 sample
);
117 uint32
GetSampleForTime(uint32 streamIndex
, bigtime_t time
);
118 uint32
GetTimeForSample(uint32 streamIndex
, uint32 sample
);
120 status_t
ParseFile();
121 BPositionIO
*Source() {return theStream
;};
123 bool IsActive(uint32 streamIndex
);
125 bool GetBufferForChunk(uint32 streamIndex
, uint32 pChunkIndex
, off_t
*start
, uint32
*size
, bool *keyframe
, bigtime_t
*time
, uint32
*framesInBuffer
);
126 bool GetBufferForFrame(uint32 streamIndex
, uint32 pFrameNo
, off_t
*start
, uint32
*size
, bool *keyframe
, bigtime_t
*time
, uint32
*framesInBuffer
);
128 // Return all Audio Meta Data
129 const AudioMetaData
*AudioFormat(uint32 streamIndex
, size_t *size
= 0);
130 // Return all Video Meta Data
131 const VideoMetaData
*VideoFormat(uint32 streamIndex
);
133 // XXX these need work
134 const mp4_main_header
*MovMainHeader();
135 const mp4_stream_header
*StreamFormat(uint32 streamIndex
);