• 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 #ifndef PVMF_MEDIA_PRESENTATION_INFO_H_INCLUDED
19 #define PVMF_MEDIA_PRESENTATION_INFO_H_INCLUDED
20 
21 #ifndef OSCL_BASE_H_INCLUDED
22 #include "oscl_base.h"
23 #endif
24 #ifndef OSCL_TYPES_H_INCLUDED
25 #include "oscl_types.h"
26 #endif
27 #ifndef OSCL_VECTOR_H_INCLUDED
28 #include "oscl_vector.h"
29 #endif
30 #ifndef OSCL_MEM_H_INCLUDED
31 #include "oscl_mem.h"
32 #endif
33 #ifndef OSCL_SHARED_PTR_H_INCLUDED
34 #include "oscl_shared_ptr.h"
35 #endif
36 #ifndef OSCL_STRING_H_INCLUDED
37 #include "oscl_string.h"
38 #endif
39 #ifndef OSCL_STRING_CONTAINERS_H_INCLUDED
40 #include "oscl_string_containers.h"
41 #endif
42 #ifndef OSCL_REFCOUNTER_MEMFRAG_H_INCLUDED
43 #include "oscl_refcounter_memfrag.h"
44 #endif
45 
46 enum PVMF_TRACK_INFO_TRACK_ALTERNATE_TYPE
47 {
48     PVMF_TRACK_ALTERNATE_TYPE_UNDEFINED,
49     PVMF_TRACK_ALTERNATE_TYPE_LANGUAGE,
50     PVMF_TRACK_ALTERNATE_TYPE_BANDWIDTH,
51     PVMF_TRACK_ALTERNATE_TYPE_BANDWIDTH_AND_CODEC_PARAMS,
52 };
53 
54 class PVMFTrackInfo : public HeapBase
55 {
56     public:
PVMFTrackInfo()57         PVMFTrackInfo()
58         {
59             iTrackID = -1;
60             iPortTag = -1;
61             iDurationValue = 0;
62             iDurationTimeScale = 0;
63             iDependsOn = false;
64             iHasAlternates = false;
65             iTrackAlternateType = PVMF_TRACK_ALTERNATE_TYPE_UNDEFINED;
66             oDurationAvailable = true;
67             iTrackFrameRate = 0;
68         }
69 
PVMFTrackInfo(const PVMFTrackInfo & aSourceTrackInfo)70         PVMFTrackInfo(const PVMFTrackInfo& aSourceTrackInfo) : HeapBase(aSourceTrackInfo)
71         {
72             iTrackMimeType       = aSourceTrackInfo.iTrackMimeType;
73             iTrackID             = aSourceTrackInfo.iTrackID;
74             iPortTag             = aSourceTrackInfo.iPortTag;
75             iDurationValue       = aSourceTrackInfo.iDurationValue;
76             iDurationTimeScale   = aSourceTrackInfo.iDurationTimeScale;
77             iTrackBitRate        = aSourceTrackInfo.iTrackBitRate;
78             iTrackFrameRate      = aSourceTrackInfo.iTrackFrameRate;
79             iTrackConfigInfo     = aSourceTrackInfo.iTrackConfigInfo;
80             iDependsOn           = aSourceTrackInfo.iDependsOn;
81             iHasAlternates       = aSourceTrackInfo.iHasAlternates;
82             iTrackAlternateType  = aSourceTrackInfo.iTrackAlternateType;
83             iDependsOnTrackIDVec = aSourceTrackInfo.iDependsOnTrackIDVec;
84             iAlternateTrackIDVec = aSourceTrackInfo.iAlternateTrackIDVec;
85             oDurationAvailable   = aSourceTrackInfo.oDurationAvailable;
86             iLanguage            = aSourceTrackInfo.iLanguage;
87         }
88 
89         PVMFTrackInfo& operator=(const PVMFTrackInfo& aSourceTrackInfo)
90         {
91             if (&aSourceTrackInfo != this)
92             {
93                 iTrackMimeType       = aSourceTrackInfo.iTrackMimeType;
94                 iTrackID             = aSourceTrackInfo.iTrackID;
95                 iPortTag             = aSourceTrackInfo.iPortTag;
96                 iDurationValue       = aSourceTrackInfo.iDurationValue;
97                 iDurationTimeScale   = aSourceTrackInfo.iDurationTimeScale;
98                 iTrackBitRate        = aSourceTrackInfo.iTrackBitRate;
99                 iTrackFrameRate      = aSourceTrackInfo.iTrackFrameRate;
100                 iTrackConfigInfo     = aSourceTrackInfo.iTrackConfigInfo;
101                 iDependsOn           = aSourceTrackInfo.iDependsOn;
102                 iHasAlternates       = aSourceTrackInfo.iHasAlternates;
103                 iTrackAlternateType  = aSourceTrackInfo.iTrackAlternateType;
104                 iDependsOnTrackIDVec = aSourceTrackInfo.iDependsOnTrackIDVec;
105                 iAlternateTrackIDVec = aSourceTrackInfo.iAlternateTrackIDVec;
106                 oDurationAvailable   = aSourceTrackInfo.oDurationAvailable;
107                 iLanguage            = aSourceTrackInfo.iLanguage;
108             }
109             return *this;
110         }
111 
~PVMFTrackInfo()112         ~PVMFTrackInfo()
113         {
114         }
115 
116         /*
117          * Track mimetype is a mimestring that uniquely identifies
118          * a media track and its format to some extent, within a
119          * presentation.
120          */
getTrackMimeType()121         OSCL_String& getTrackMimeType()
122         {
123             return iTrackMimeType;
124         }
setTrackMimeType(OSCL_String & aMimeType)125         void setTrackMimeType(OSCL_String& aMimeType)
126         {
127             iTrackMimeType = aMimeType;
128         }
129 
getTrackID()130         uint32 getTrackID()
131         {
132             return iTrackID;
133         }
setTrackID(uint32 aId)134         void setTrackID(uint32 aId)
135         {
136             iTrackID = aId;
137         }
138 
getPortTag()139         uint32 getPortTag()
140         {
141             return iPortTag;
142         }
setPortTag(uint32 aTag)143         void setPortTag(uint32 aTag)
144         {
145             iPortTag = aTag;
146         }
147 
IsDurationAvailable()148         bool IsDurationAvailable()
149         {
150             return oDurationAvailable;
151         }
152 
SetDurationAvailable(bool aDurationAvailable)153         void SetDurationAvailable(bool aDurationAvailable)
154         {
155             oDurationAvailable = aDurationAvailable;
156         }
157 
getTrackDurationValue()158         uint64 getTrackDurationValue()
159         {
160             return iDurationValue;
161         }
setTrackDurationValue(uint64 aDuration)162         void setTrackDurationValue(uint64 aDuration)
163         {
164             iDurationValue = aDuration;
165         }
166 
getTrackDurationTimeScale()167         uint64  getTrackDurationTimeScale()
168         {
169             return iDurationTimeScale;
170         }
setTrackDurationTimeScale(uint64 aTimeScale)171         void setTrackDurationTimeScale(uint64  aTimeScale)
172         {
173             iDurationTimeScale = aTimeScale;
174         }
175 
getTrackBitRate()176         uint32 getTrackBitRate()
177         {
178             return iTrackBitRate;
179         }
setTrackBitRate(uint32 aBitRate)180         void setTrackBitRate(uint32 aBitRate)
181         {
182             iTrackBitRate = aBitRate;
183         }
184 
getTrackFrameRate()185         uint32 getTrackFrameRate()
186         {
187             return iTrackFrameRate;
188         }
setTrackFrameRate(uint32 aFrameRate)189         void setTrackFrameRate(uint32 aFrameRate)
190         {
191             iTrackFrameRate = aFrameRate;
192         }
193 
194         /*
195          * TrackConfig info typically holds info that gets passed to
196          * decoders to initialize, aka, mpeg4 vol header, mpeg4 audio
197          * config etc. For tracks that expose a fixed set of parameters
198          * as part of config as opposed to some opaque data, the void
199          * pointer in the memory fragement is actually a pointer to a
200          * strcuture that the user of this field would know how to
201          * interpret. For example in case of H263, we could have a structure
202          * that could be defined as:
203          * struct H263ConfigInfo
204          * {
205          *      uint32 maxWidth;
206          *      uint32 maxHeight;
207          *      uint32 codecProfile;
208          *      uint32 codecLevel;
209          * };
210          * Memory fragment holds a pointer to this strcuture.
211          *
212          */
getTrackConfigInfo()213         OsclRefCounterMemFrag& getTrackConfigInfo()
214         {
215             return iTrackConfigInfo;
216         }
setTrackConfigInfo(OsclRefCounterMemFrag & aConfig)217         void setTrackConfigInfo(OsclRefCounterMemFrag& aConfig)
218         {
219             iTrackConfigInfo = aConfig;
220         }
221 
setDependsOn()222         void setDependsOn()
223         {
224             iDependsOn = true;
225         }
226 
DoesTrackHaveDependency()227         bool DoesTrackHaveDependency()
228         {
229             return (iDependsOn);
230         }
231 
addDependsOnTrackID(int32 aTrackID)232         void addDependsOnTrackID(int32 aTrackID)
233         {
234             iDependsOnTrackIDVec.push_back(aTrackID);
235         }
236 
getDependsOnTrackIDVec()237         Oscl_Vector<int32, OsclMemAllocator> getDependsOnTrackIDVec()
238         {
239             return (iDependsOnTrackIDVec);
240         }
241 
setTrackAlternates(PVMF_TRACK_INFO_TRACK_ALTERNATE_TYPE aAlternateType)242         void setTrackAlternates(PVMF_TRACK_INFO_TRACK_ALTERNATE_TYPE aAlternateType)
243         {
244             if (aAlternateType != PVMF_TRACK_ALTERNATE_TYPE_UNDEFINED)
245             {
246                 iHasAlternates = true;
247                 iTrackAlternateType = aAlternateType;
248             }
249         }
250 
DoesTrackHaveAlternates()251         bool DoesTrackHaveAlternates()
252         {
253             return (iHasAlternates);
254         }
255 
getTrackAlternateType()256         PVMF_TRACK_INFO_TRACK_ALTERNATE_TYPE getTrackAlternateType()
257         {
258             return iTrackAlternateType;
259         }
260 
addAlternateTrackID(int32 aTrackID)261         void addAlternateTrackID(int32 aTrackID)
262         {
263             iAlternateTrackIDVec.push_back(aTrackID);
264         }
265 
getAlternateTrackIDVec()266         Oscl_Vector<int32, OsclMemAllocator> getAlternateTrackIDVec()
267         {
268             return (iAlternateTrackIDVec);
269         }
270 
getTrackLanguage()271         OSCL_String& getTrackLanguage()
272         {
273             return iLanguage;
274         }
275 
276     private:
277         OSCL_HeapString<OsclMemAllocator> iTrackMimeType;
278         int32 iTrackID;
279         int32 iPortTag;
280         uint64  iDurationValue;
281         uint64  iDurationTimeScale;
282         uint32 iTrackBitRate;
283         uint32 iTrackFrameRate;
284         OsclRefCounterMemFrag iTrackConfigInfo;
285         bool iDependsOn;
286         Oscl_Vector<int32, OsclMemAllocator> iDependsOnTrackIDVec;
287         bool iHasAlternates;
288         PVMF_TRACK_INFO_TRACK_ALTERNATE_TYPE iTrackAlternateType;
289         Oscl_Vector<int32, OsclMemAllocator> iAlternateTrackIDVec;
290         bool oDurationAvailable;
291         /*
292          * ISO-639-2/T language codes, which are basically 3 character codes
293          * assigned to each language. Typically applicable to audio tracks.
294          * If the language code exists it will be returned in the iLanguage parameter.
295          * If iLanguage is empty English should be assumed.
296          */
297         OSCL_HeapString<OsclMemAllocator> iLanguage;
298 };
299 
300 
301 /**
302  * Primary goals of this class are to provide:
303  * - a common interface for the track selection modules, across
304  *   local playback, streaming and download
305  * - provide enough information to perform track selection
306  */
307 class PVMFMediaPresentationInfo
308 {
309     public:
PVMFMediaPresentationInfo()310         PVMFMediaPresentationInfo()
311         {
312             oIsSeekable = false;
313             oDurationAvailable = true;
314         }
315 
PVMFMediaPresentationInfo(const PVMFMediaPresentationInfo & aInfo)316         PVMFMediaPresentationInfo(const PVMFMediaPresentationInfo& aInfo)
317         {
318             iPresentationType = aInfo.iPresentationType;
319             iDurationValue = aInfo.iDurationValue;
320             iDurationTimeScale = aInfo.iDurationTimeScale;
321             oIsSeekable = aInfo.oIsSeekable;
322             iTrackInfoVec = aInfo.iTrackInfoVec;
323             oDurationAvailable = aInfo.oDurationAvailable;
324         }
325 
~PVMFMediaPresentationInfo()326         ~PVMFMediaPresentationInfo()
327         {
328             iTrackInfoVec.clear();
329         }
330 
331         PVMFMediaPresentationInfo& operator=(const PVMFMediaPresentationInfo& aInfo)
332         {
333             if (&aInfo != this)
334             {
335                 iPresentationType = aInfo.iPresentationType;
336                 iDurationValue = aInfo.iDurationValue;
337                 iDurationTimeScale = aInfo.iDurationTimeScale;
338                 oIsSeekable = aInfo.oIsSeekable;
339                 iTrackInfoVec = aInfo.iTrackInfoVec;
340                 oDurationAvailable = aInfo.oDurationAvailable;
341             }
342             return *this;
343         }
344 
345         /*
346          * Presentation type is a mime string that identifies the
347          * media presentation, viz, mp4, asf, mp3 etc
348          */
getPresentationType()349         OSCL_String& getPresentationType()
350         {
351             return iPresentationType;
352         }
353 
setPresentationType(OSCL_String & aPresentationType)354         void setPresentationType(OSCL_String& aPresentationType)
355         {
356             iPresentationType = aPresentationType;
357         }
358 
IsSeekable()359         bool IsSeekable()
360         {
361             return oIsSeekable;
362         }
363 
setSeekableFlag(bool aFlag)364         void setSeekableFlag(bool aFlag)
365         {
366             oIsSeekable = aFlag;
367         }
368 
addTrackInfo(PVMFTrackInfo & aTrackInfo)369         void addTrackInfo(PVMFTrackInfo& aTrackInfo)
370         {
371             iTrackInfoVec.push_back(aTrackInfo);
372         }
373 
getNumTracks()374         uint32 getNumTracks() const
375         {
376             return (iTrackInfoVec.size());
377         }
378 
getTrackInfo(uint32 aIndex)379         PVMFTrackInfo* getTrackInfo(uint32 aIndex) const
380         {
381             if (aIndex >= iTrackInfoVec.size())
382             {
383                 return NULL;
384             }
385             return (OSCL_CONST_CAST(PVMFTrackInfo*, &(iTrackInfoVec[aIndex])));
386         }
387 
getTrackInfoBasedOnTrackID(uint32 aTrackID)388         PVMFTrackInfo* getTrackInfoBasedOnTrackID(uint32 aTrackID)
389         {
390             Oscl_Vector<PVMFTrackInfo, OsclMemAllocator>::iterator it;
391             for (it = iTrackInfoVec.begin(); it != iTrackInfoVec.end(); it++)
392             {
393                 if (it->getTrackID() == aTrackID)
394                 {
395                     return (it);
396                 }
397             }
398             return NULL;
399         }
400 
IsDurationAvailable()401         bool IsDurationAvailable()
402         {
403             return oDurationAvailable;
404         }
405 
SetDurationAvailable(bool aDurationAvailable)406         void SetDurationAvailable(bool aDurationAvailable)
407         {
408             oDurationAvailable = aDurationAvailable;
409         }
410 
getDurationValue()411         uint64  getDurationValue()
412         {
413             return iDurationValue;
414         }
415 
setDurationValue(uint64 aDuration)416         void setDurationValue(uint64 aDuration)
417         {
418             iDurationValue = aDuration;
419         }
420 
getDurationTimeScale()421         uint64  getDurationTimeScale()
422         {
423             return iDurationTimeScale;
424         }
425 
setDurationTimeScale(uint64 aTimeScale)426         void setDurationTimeScale(uint64  aTimeScale)
427         {
428             iDurationTimeScale = aTimeScale;
429         }
430 
Reset()431         void Reset()
432         {
433             iTrackInfoVec.clear();
434             iDurationValue = 0;
435             iDurationTimeScale = 0;
436             oIsSeekable = false;
437             iPresentationType = _STRLIT_CHAR("");
438             oDurationAvailable = true;
439         }
440 
441     private:
442         OSCL_HeapString<OsclMemAllocator> iPresentationType;
443         uint64  iDurationValue;
444         uint64  iDurationTimeScale;
445         bool   oIsSeekable;
446         Oscl_Vector<PVMFTrackInfo, OsclMemAllocator> iTrackInfoVec;
447         bool   oDurationAvailable;
448 };
449 
450 #endif //PVMF_MEDIA_PRESENTATION_INFO_H_INCLUDED
451 
452