• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* ------------------------------------------------------------------
2  * Copyright (C) 1998-2009 PacketVideo
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13  * express or implied.
14  * See the License for the specific language governing permissions
15  * and limitations under the License.
16  * -------------------------------------------------------------------
17  */
18 /*
19     This PVA_FF_TrackAtom Class is the container for a single track in the MPEG-4
20     presentation.
21 */
22 
23 
24 #ifndef __TrackAtom_H__
25 #define __TrackAtom_H__
26 
27 #include "pv_mp4ffcomposer_config.h"
28 #include "atom.h"
29 #include "a_isucceedfail.h"
30 
31 #include "trackheaderatom.h"
32 #include "mediaatom.h"
33 #include "trackreferenceatom.h"
34 #include "editatom.h"
35 
36 #include "userdataatom.h"
37 
38 #include "oscl_byte_order.h"
39 #include "oscl_bin_stream.h"
40 typedef Oscl_Vector<uint32, OsclMemAllocator> uint32VecType;
41 typedef Oscl_Vector<int32, OsclMemAllocator> int32VecType;
42 typedef Oscl_Vector<uint8, OsclMemAllocator> uint8VecType;
43 
44 class PVA_FF_TrackAtom : public PVA_FF_Atom, public PVA_FF_ISucceedFail
45 {
46 
47     public:
48         // The protocol parameter is used when creating a HINT track.  It is passed
49         // down to the PVA_FF_SampleDescriptionAtom so it can create the appropriate PVA_FF_HintSampleEntry.
50         // If this constructor is used to create any other typ eof track atom, the protocol
51         // parameter is ignored - hence the default parameter value.
52         PVA_FF_TrackAtom(int32 type,
53                          uint32 id,
54                          uint32 fileAuthoringFlags,
55                          int32 codecType = 0,
56                          uint32 protocol = 0,
57                          uint8 profile = 1,
58                          uint8 profileComp = 0xFF,
59                          uint8 level = 0xFF); // Constructor
60 
getCodecType()61         int32 getCodecType()
62         {
63             return _codecType;
64         }
65 
66         virtual ~PVA_FF_TrackAtom();
67 
68         // Member get methods
getTrackHeaderAtom()69         const PVA_FF_TrackHeaderAtom &getTrackHeaderAtom() const
70         {
71             return *_ptrackHeader;
72         }
getTrackHeaderAtomPtr()73         PVA_FF_TrackHeaderAtom *getTrackHeaderAtomPtr()
74         {
75             return _ptrackHeader;
76         }
getMutableTrackHeaderAtom()77         PVA_FF_TrackHeaderAtom &getMutableTrackHeaderAtom()
78         {
79             return *_ptrackHeader;
80         }
getMediaAtom()81         const PVA_FF_MediaAtom &getMediaAtom() const
82         {
83             return *_pmediaAtom;
84         }
getMutableMediaAtom()85         const PVA_FF_MediaAtom &getMutableMediaAtom()
86         {
87             return *_pmediaAtom;
88         }
getTrackReferenceAtomPtr()89         PVA_FF_TrackReferenceAtom *getTrackReferenceAtomPtr()
90         {
91             return _ptrackReference;
92         }
93 
94         // Add a reference to another track - return index of reference in table (1-based)
95         int32 addTrackReference(uint32 ref);
getTrackID()96         uint32 getTrackID() const
97         {
98             return _ptrackHeader->getTrackID();
99         }
100 
101         // Update members with next sample received
102         void nextSample(int32 mediaType,
103                         void *psample,
104                         uint32 size,
105                         uint32 ts = 0,
106                         uint8 flags = 0,
107                         uint32 baseOffset = 0,
108                         bool oChunkStart = false);
109 
110         void nextTextSample(int32 mediaType,
111                             void *psample,
112                             uint32 size,
113                             uint32 ts = 0,
114                             uint8 flags = 0,
115                             int32 index = 0,
116                             uint32 baseOffset = 0,
117                             bool oChunkStart = false);
118 
119         void nextSample(int32 mediaType,
120                         Oscl_Vector <OsclMemoryFragment, OsclMemAllocator>& fragmentList,
121                         uint32 size,
122                         uint32 ts = 0,
123                         uint8 flags = 0,
124                         uint32 baseOffset = 0,
125                         bool oChunkStart = false);
126 
127         void nextTextSample(int32 mediaType,
128                             Oscl_Vector <OsclMemoryFragment, OsclMemAllocator>& fragmentList,
129                             uint32 size,
130                             uint32 ts = 0,
131                             uint8 flags = 0,
132                             int32 index = 0,
133                             uint32 baseOffset = 0,
134                             bool oChunkStart = false);
135 
136         bool reAuthorFirstSample(uint32 size,
137                                  uint32 baseOffset);
138 
139         // Create methods for the optional member atoms
140         void createTrackReferenceAtom();
141         void createEditAtom();
142 
143         // Called to update the member atoms if they depend on the actual
144         // file offsets where the media data atom (for which this track stores
145         // the meta data) is stored
updateAtomFileOffsets(uint32 offset)146         void updateAtomFileOffsets(uint32 offset)
147         {
148             _pmediaAtom->updateAtomFileOffsets(offset);
149         }
150 
151 
152         // Mpeg4 movie timescale
setTimeScale(uint32 ts)153         void setTimeScale(uint32 ts)
154         {
155             _ptrackHeader->setTimeScale(ts);
156         }
getTimeScale()157         uint32 getTimeScale() const
158         {
159             return _ptrackHeader->getTimeScale();
160         }
161 
162         uint32 convertTrackDurationToMediaTimeScale(uint32 duration);
163 
setDuration(uint32 duration)164         void setDuration(uint32 duration)
165         {
166             _ptrackHeader->setDuration(duration);
167 
168             uint32 trackDurationInMediaTimeScale =
169                 convertTrackDurationToMediaTimeScale(duration);
170 
171             _pmediaAtom->setDuration(trackDurationInMediaTimeScale);
172         }
173 
setLanguage(uint32 language)174         void setLanguage(uint32 language)
175         {
176             _pmediaAtom->setLanguage(language);
177         }
178 
getDuration()179         uint32 getDuration() const
180         {
181             return _ptrackHeader->getDuration();
182         }
183 
184         // Stream properties
setTargetBitrate(uint32 avgBitRate,uint32 maxBitRate,uint32 bufferSizeDB)185         void setTargetBitrate(uint32 avgBitRate, uint32 maxBitRate, uint32 bufferSizeDB)
186         {
187             _trackTargetBitRate = avgBitRate;
188             _pmediaAtom->setTargetBitrate(avgBitRate, maxBitRate, bufferSizeDB);
189         }
190 
191         // Media timescale
setMediaTimeScale(uint32 ts)192         void setMediaTimeScale(uint32 ts)
193         {
194             _pmediaAtom->setTimeScale(ts);
195         }
getMediaTimeScale()196         uint32 getMediaTimeScale() const
197         {
198             return _pmediaAtom->getTimeScale();
199         }
200 
201         // Track media type
getTrackMediaType()202         int32 getTrackMediaType() const
203         {
204             return _ptrackHeader->getTrackMediaType();
205         }
getMediaType()206         uint32 getMediaType() const
207         {
208             return _mediaType;
209         }
210 
211         // Rendering the PVA_FF_Atom in proper format (bitlengths, etc.) to an ostream
212         virtual bool renderToFileStream(MP4_AUTHOR_FF_FILE_IO_WRAP *fp);
213 
214         void prepareToRender();
215 
216         // Getting and setting the Mpeg4 VOL header
addDecoderSpecificInfo(PVA_FF_DecoderSpecificInfo * pinfo)217         void addDecoderSpecificInfo(PVA_FF_DecoderSpecificInfo *pinfo)
218         {
219             _setDecoderSpecificInfoDone = true;
220             _pmediaAtom->addDecoderSpecificInfo(pinfo);
221         }
222 
223         // Getting and setting the Mpeg4 VOL header for Timed text
addTextDecoderSpecificInfo(PVA_FF_TextSampleDescInfo * pinfo)224         void addTextDecoderSpecificInfo(PVA_FF_TextSampleDescInfo *pinfo)
225         {
226             _setDecoderSpecificInfoDone = true;
227             _pmediaAtom->addTextDecoderSpecificInfo(pinfo);
228         }
229 
setMaxBufferSizeDB(uint32 max)230         void setMaxBufferSizeDB(uint32 max)
231         {
232             _pmediaAtom->setMaxBufferSizeDB(max);
233         }
234 
235         void setVideoParams(uint32 frame_width, uint32 frame_height);
236 
237         void setAudioEncodeParams(PVMP4FFComposerAudioEncodeParams &audioParams);
238 
setH263ProfileLevel(uint8 profile,uint8 level)239         void setH263ProfileLevel(uint8 profile, uint8 level)
240         {
241             _pmediaAtom->setH263ProfileLevel(profile, level);
242         }
243 
setESID(uint16 esid)244         void setESID(uint16 esid)
245         {
246             _pmediaAtom->setESID(esid);
247         }
248 
IsDecoderSpecificInfoSet()249         bool IsDecoderSpecificInfoSet()
250         {
251             return _setDecoderSpecificInfoDone;
252         }
253 
getSampleCount()254         uint32 getSampleCount() const
255         {
256             return _pmediaAtom->getSampleCount();
257         }
258 
IsFirstSample()259         bool IsFirstSample()
260         {
261             return FIRST_SAMPLE;
262         }
263         void updateLastTSEntry(uint32 ts);
264         void SetMaxSampleSize(uint32);
265         void writeMaxSampleSize(MP4_AUTHOR_FF_FILE_IO_WRAP*);
266 
267     private:
268         virtual void recomputeSize();
269 
270         PVA_FF_TrackHeaderAtom    *_ptrackHeader;
271         PVA_FF_MediaAtom          *_pmediaAtom;
272         PVA_FF_TrackReferenceAtom *_ptrackReference; // Optional atom - MANDATORY for hint tracks
273 
274         PVA_FF_UserDataAtom       *_pUserDataAtom;
275 
276         int32 _codecType;
277         int32 _mediaType;
278 
279         bool FIRST_SAMPLE;
280         PVA_FF_EditAtom *_eList;
281 
282         bool   _oInterLeaveMode;
283 
284         bool _setDecoderSpecificInfoDone;
285         uint32 _trackTargetBitRate;
286 
287         uint32 _intialTrackTimeOffsetInMilliSeconds;
288 
289 
290 };
291 
292 
293 
294 #endif
295 
296