• 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 /*     -------------------------------------------------------------------       */
20 /*                            MPEG-4 MediaAtom Class                             */
21 /*     -------------------------------------------------------------------       */
22 /*********************************************************************************/
23 /*
24     This MediaAtom Class contains all the objects that declare information
25     about the media data within the stream.
26 */
27 
28 
29 #ifndef MEDIAATOM_H_INCLUDED
30 #define MEDIAATOM_H_INCLUDED
31 
32 #ifndef OSCL_FILE_IO_H_INCLUDED
33 #include "oscl_file_io.h"
34 #endif
35 
36 #ifndef ATOM_H_INCLUDED
37 #include "atom.h"
38 #endif
39 
40 #ifndef MEDIAHEADERATOM_H_INCLUDED
41 #include "mediaheaderatom.h"
42 #endif
43 
44 #ifndef HANDLERATOM_H_INCLUDED
45 #include "handleratom.h"
46 #endif
47 
48 #ifndef MEDIAINFORMATIONATOM_H_INCLUDED
49 #include "mediainformationatom.h"
50 #endif
51 
52 #ifndef ESDESCRIPTOR_H_INCLUDED
53 #include "esdescriptor.h"
54 #endif
55 
56 #ifndef OSCL_MEDIA_DATA_H_INCLUDED
57 #include "oscl_media_data.h"
58 #endif
59 
60 #ifndef PV_GAU_H_INCLUDED
61 #include "pv_gau.h"
62 #endif
63 
64 class AVCSampleEntry;
65 
66 class MediaAtom : public Atom
67 {
68 
69     public:
70         MediaAtom(MP4_FF_FILE *fp,
71                   OSCL_wString& filename,
72                   uint32 size,
73                   uint32 type,
74                   bool oPVContentDownloadable = false,
75                   uint32 parsingMode = 0);
76 
77         virtual ~MediaAtom();
78 
79 
getMediaHandlerType()80         uint32 getMediaHandlerType() const
81         {
82             if (_phandler != NULL)
83             {
84                 return _phandler->getHandlerType();
85             }
86             else
87             {
88                 return 0;
89             }
90         }
91 
getSampleProtocol()92         uint32 getSampleProtocol() const
93         {
94             if (_pmediaInformation != NULL)
95             {
96                 return _pmediaInformation->getSampleProtocol();
97             }
98             else
99             {
100                 return 0;
101             }
102         }
103 
104 
105         // Return the ESID for the track - undefined if a HINT track
getESID()106         uint32 getESID() const
107         {
108             if (_pmediaInformation != NULL)
109             {
110                 return _pmediaInformation->getESID();
111             }
112             else
113             {
114                 return 0;
115             }
116         }
117 
118         // Return the first ESDescriptor for the track - undefined if a HINT track
getESDescriptor()119         const ESDescriptor *getESDescriptor() const
120         {
121             if (_pmediaInformation != NULL)
122             {
123                 return _pmediaInformation->getESDescriptor();
124             }
125             else
126             {
127                 return NULL;
128             }
129         }
130 
getTimeScale()131         uint32 getTimeScale() const
132         {
133             if (_pmediaHeader != NULL)
134             {
135                 return _pmediaHeader->getTimeScale();
136             }
137             else
138             {
139                 // UNDEFINED VALUE
140                 return 0xFFFFFFFF;
141             }
142         }
143 
updateFileSize(uint32 filesize)144         int32 updateFileSize(uint32 filesize)
145         {
146             if (_pmediaInformation != NULL)
147             {
148                 return _pmediaInformation->updateFileSize(filesize);
149             }
150             return DEFAULT_ERROR;
151         }
152 
153         // Returns next video frame
getNextSample(uint8 * buf,int32 & size,uint32 & index,uint32 & SampleOffset)154         int32 getNextSample(uint8 *buf, int32 &size, uint32 &index, uint32 &SampleOffset)
155         {
156             if (_pmediaInformation == NULL)
157             {
158                 return READ_MEDIA_INFORMATION_ATOM_FAILED;
159             }
160             return _pmediaInformation->getNextSample(buf, size, index, SampleOffset);
161         }
162 
getKeyMediaSampleNumAt(uint32 aKeySampleNum,GAU * pgau)163         MP4_ERROR_CODE getKeyMediaSampleNumAt(uint32 aKeySampleNum,
164                                               GAU    *pgau)
165         {
166             if (_pmediaInformation == NULL)
167             {
168                 return READ_MEDIA_INFORMATION_ATOM_FAILED;
169             }
170             return _pmediaInformation->getKeyMediaSampleNumAt(aKeySampleNum, pgau);
171         }
172 
getNumKeyFrames()173         uint32 getNumKeyFrames()
174         {
175             if (_pmediaInformation != NULL)
176             {
177                 return (_pmediaInformation->getNumKeyFrames());
178             }
179             else
180             {
181                 return 0;
182             }
183         }
184 
getPrevKeyMediaSample(uint32 inputtimestamp,uint32 & aKeySampleNum,uint32 * n,GAU * pgau)185         int32 getPrevKeyMediaSample(uint32 inputtimestamp,
186                                     uint32 &aKeySampleNum,
187                                     uint32 *n,
188                                     GAU    *pgau)
189         {
190             if (_pmediaInformation == NULL)
191             {
192                 return READ_MEDIA_INFORMATION_ATOM_FAILED;
193             }
194             return _pmediaInformation->getPrevKeyMediaSample(inputtimestamp, aKeySampleNum, n, pgau);
195         }
196 
getNextKeyMediaSample(uint32 inputtimestamp,uint32 & aKeySampleNum,uint32 * n,GAU * pgau)197         int32 getNextKeyMediaSample(uint32 inputtimestamp,
198                                     uint32 &aKeySampleNum,
199                                     uint32 *n,
200                                     GAU    *pgau)
201         {
202             if (_pmediaInformation == NULL)
203             {
204                 return READ_MEDIA_INFORMATION_ATOM_FAILED;
205             }
206             return _pmediaInformation->getNextKeyMediaSample(inputtimestamp, aKeySampleNum, n, pgau);
207         }
208 
getMediaSample(uint32 sampleNumber,uint8 * buf,int32 & size,uint32 & index,uint32 & SampleOffset)209         int32 getMediaSample(uint32 sampleNumber, uint8 *buf, int32 &size, uint32 &index, uint32 &SampleOffset)
210         {
211             if (_pmediaInformation == NULL)
212             {
213                 return READ_MEDIA_INFORMATION_ATOM_FAILED;
214             }
215             return _pmediaInformation->getMediaSample(sampleNumber, buf, size, index, SampleOffset);
216         }
217 
getOffsetByTime(uint32 ts,int32 * sampleFileOffset)218         int32 getOffsetByTime(uint32 ts, int32* sampleFileOffset)
219         {
220             if (_pmediaInformation == NULL)
221             {
222                 return DEFAULT_ERROR;
223             }
224             return _pmediaInformation->getOffsetByTime(ts, sampleFileOffset);
225         }
226 
resetPlayBack()227         void resetPlayBack()
228         {
229             if (_pmediaInformation != NULL)
230             {
231                 _pmediaInformation->resetPlayBack();
232             }
233         }
234 
resetTrackToEOT()235         void resetTrackToEOT()
236         {
237             if (_pmediaInformation != NULL)
238             {
239                 _pmediaInformation->resetTrackToEOT();
240             }
241         }
242 
resetPlayBack(int32 time,bool oDependsOn)243         int32 resetPlayBack(int32 time, bool oDependsOn)
244         {
245             if (_pmediaInformation != NULL)
246             {
247                 return _pmediaInformation->resetPlayBack(time, oDependsOn);
248             }
249             else
250             {
251                 return 0;
252             }
253         }
254 
queryRepositionTime(int32 time,bool oDependsOn,bool bBeforeRequestedTime)255         int32 queryRepositionTime(int32 time, bool oDependsOn, bool bBeforeRequestedTime)
256         {
257             if (_pmediaInformation != NULL)
258             {
259                 return _pmediaInformation->queryRepositionTime(time, oDependsOn, bBeforeRequestedTime);
260             }
261             else
262             {
263                 return 0;
264             }
265         }
266 
IsResetNeeded(int32 time)267         int32 IsResetNeeded(int32 time)
268         {
269             if (_pmediaInformation == NULL)
270                 return READ_MEDIA_INFORMATION_ATOM_FAILED;
271             return _pmediaInformation->IsResetNeeded(time);
272         }
273 
getTimestampForSampleNumber(uint32 sampleNumber)274         uint32 getTimestampForSampleNumber(uint32 sampleNumber)
275         {
276             if (_pmediaInformation != NULL)
277             {
278                 return _pmediaInformation->getTimestampForSampleNumber(sampleNumber);
279             }
280             else
281             {
282                 return 0;
283             }
284         }
285 
getSampleSizeAt(int32 sampleNum)286         int32 getSampleSizeAt(int32 sampleNum)
287         {
288             if (_pmediaInformation != NULL)
289             {
290                 return _pmediaInformation->getSampleSizeAt(sampleNum);
291             }
292             else
293             {
294                 return 0;
295             }
296         }
297 
298 
299         // Returns the timestamp  from the last video sample
300         // This is mainly to be used when seeking in the bitstream - you request a video frame at timestamp
301         // X, but the actual frame you get is Y, this method returns the timestamp for Y so you know which
302         // audio sample to request.
getTimestampForCurrentSample()303         int32 getTimestampForCurrentSample()
304         {
305             if (_pmediaInformation != NULL)
306             {
307                 return _pmediaInformation->getTimestampForCurrentSample();
308             }
309             else
310             {
311                 return 0;
312             }
313         }
314 
315         // Returns the sample number of the last samplle returned
316         // Used when requesting a hint sample for a specific randomly accessed sample
getSampleNumberForCurrentSample()317         int32 getSampleNumberForCurrentSample()
318         {
319             if (_pmediaInformation != NULL)
320             {
321                 return _pmediaInformation->getSampleNumberForCurrentSample();
322             }
323             else
324             {
325                 return 0;
326             }
327         }
328 
advance()329         void advance()
330         {
331             if (_pmediaInformation != NULL)
332             {
333                 _pmediaInformation->advance();
334             }
335         } // Advances the currentPlayback number
336 
advance(int32 sampleNum)337         void advance(int32 sampleNum)
338         {
339             if (_pmediaInformation != NULL)
340             {
341                 _pmediaInformation->advance(sampleNum);
342             }
343         } // Advances the currentPlayback number to sampleNum
344 
seek(int32 baseLayerSampleNum)345         void seek(int32 baseLayerSampleNum)
346         {
347             if (_pmediaInformation != NULL)
348             {
349                 _pmediaInformation->seek(baseLayerSampleNum);
350             }
351         } // Seeks to the base-layer sample in the hint track
352 
353 
354 
355         // From MediaHeader
getMediaDuration()356         uint64 getMediaDuration()
357         {
358             if (_pmediaHeader != NULL)
359             {
360                 return _pmediaHeader->getDuration();
361             }
362             else
363             {
364                 return 0;
365             }
366         } // in terms of the media timescale
367 
getMediaTimescale()368         uint32 getMediaTimescale()
369         {
370             if (_pmediaHeader != NULL)
371             {
372                 return _pmediaHeader->getTimeScale();
373             }
374             else
375             {
376                 return 0;
377             }
378         }
379 
getLanguageCode()380         uint16 getLanguageCode()
381         {
382             if (_pmediaHeader != NULL)
383             {
384                 return _pmediaHeader->getLanguage();
385             }
386             else
387             {
388                 return (0xFFFF);
389             }
390 
391         }
392 
393 
394         // From Handler
getTrackStreamType()395         uint32 getTrackStreamType()
396         {
397             if (_phandler != NULL)
398             {
399                 return _phandler->getHandlerType();
400             }
401             else
402             {
403                 return 0;
404             }
405         }
406 
407         // From SampleDescription
getNumSampleEntries()408         uint32 getNumSampleEntries()
409         {
410             if (_pmediaInformation != NULL)
411             {
412                 return _pmediaInformation->getNumSampleEntries();
413             }
414             else
415             {
416                 return 0;
417             }
418         }
419 
420         //From DecoderConfigDescriptor
421         // Getting and setting the Mpeg4 VOL header
getDecoderSpecificInfo()422         DecoderSpecificInfo *getDecoderSpecificInfo() const
423         {
424             if (_pmediaInformation != NULL)
425             {
426                 return _pmediaInformation->getDecoderSpecificInfo();
427             }
428             else
429             {
430                 return NULL;
431             }
432         }
433 
getDecoderSpecificInfoForSDI(uint32 index)434         DecoderSpecificInfo *getDecoderSpecificInfoForSDI(uint32 index) const
435         {
436             if (_pmediaInformation != NULL)
437             {
438                 return _pmediaInformation->getDecoderSpecificInfoForSDI(index);
439             }
440             else
441             {
442                 return NULL;
443             }
444         }
445 
getMIMEType(OSCL_String & aMimeType)446         void getMIMEType(OSCL_String& aMimeType)
447         {
448             if (_pmediaInformation != NULL)
449             {
450                 _pmediaInformation->getMIMEType(aMimeType);
451             }
452         }
453 
getObjectTypeIndication()454         uint8  getObjectTypeIndication()
455         {
456             if (_pmediaInformation != NULL)
457             {
458                 return _pmediaInformation->getObjectTypeIndication();
459             }
460             else
461             {
462                 return 0;
463             }
464         }
465 
466         // Get the max size buffer needed to retrieve the media samples
getMaxBufferSizeDB()467         uint32 getMaxBufferSizeDB() const
468         {
469             if (_pmediaInformation != NULL)
470             {
471                 return _pmediaInformation->getMaxBufferSizeDB();
472             }
473             else
474             {
475                 return 0;
476             }
477         }
478 
getAverageBitrate()479         int32 getAverageBitrate()
480         {
481             if (_pmediaInformation != NULL)
482             {
483                 return _pmediaInformation->getAverageBitrate();
484             }
485             else
486             {
487                 return 0;
488             }
489         }
490 
getHeight()491         int32 getHeight()
492         {
493             if (_pmediaInformation != NULL)
494             {
495                 return _pmediaInformation->getHeight();
496             }
497             else
498             {
499                 return 0;
500             }
501 
502         }
503 
getWidth()504         int32 getWidth()
505         {
506             if (_pmediaInformation != NULL)
507             {
508                 return _pmediaInformation->getWidth();
509             }
510             else
511             {
512                 return 0;
513             }
514         }
515 
516         //PASP box
getHspacing()517         uint32 getHspacing()
518         {
519             if (_pmediaInformation != NULL)
520             {
521                 return _pmediaInformation->getHspacing();
522             }
523             else
524             {
525                 return 0;
526             }
527         }
528 
getVspacing()529         uint32 getVspacing()
530         {
531             if (_pmediaInformation != NULL)
532             {
533                 return _pmediaInformation->getVspacing();
534             }
535             else
536             {
537                 return 0;
538             }
539         }
540 
541         // TS offset value for the start of the media track.  The STTS
542         // Atom only holds TS deltas.  For a track that does not begin at 0s, we need to hold an
543         // offset timestamp value.
setTrackTSOffset(uint32 ts)544         void setTrackTSOffset(uint32 ts)
545         {
546             _trackStartOffset = ts;
547             if (_pmediaInformation != NULL)
548             {
549                 _pmediaInformation->setTrackTSOffset(ts);
550             }
551         }
552 
getSampleDescriptionIndex()553         uint32 getSampleDescriptionIndex()
554         {
555             if (_pmediaInformation != NULL)
556             {
557                 return _pmediaInformation->getSampleDescriptionIndex();
558             }
559             else
560             {
561                 return (0xFFFFFFFF);
562             }
563         }
564 
getNextBundledAccessUnits(uint32 * n,GAU * pgau)565         int32 getNextBundledAccessUnits(uint32 *n,
566                                         GAU    *pgau)
567         {
568             if (_pmediaInformation != NULL)
569             {
570                 return _pmediaInformation->getNextBundledAccessUnits(n, pgau);
571             }
572             else
573             {
574                 return -1;
575             }
576         }
577 
peekNextBundledAccessUnits(uint32 * n,MediaMetaInfo * mInfo)578         int32 peekNextBundledAccessUnits(uint32 *n,
579                                          MediaMetaInfo *mInfo)
580         {
581             if (_pmediaInformation != NULL)
582             {
583                 return _pmediaInformation->peekNextBundledAccessUnits(n, mInfo);
584             }
585             else
586             {
587                 return -1;
588             }
589         }
590 
getSampleCount()591         uint32 getSampleCount()
592         {
593             if (_pmediaInformation != NULL)
594             {
595                 return (_pmediaInformation->getSampleCount());
596             }
597             else
598             {
599                 return 0;
600             }
601         }
602 
getTextSampleEntryAt(uint32 index)603         SampleEntry *getTextSampleEntryAt(uint32 index)
604         {
605             if (_pmediaInformation != NULL)
606             {
607                 return (_pmediaInformation-> getTextSampleEntryAt(index));
608             }
609             else
610             {
611                 return NULL;
612             }
613         }
614 
getTimestampForRandomAccessPoints(uint32 * num,uint32 * tsBuf,uint32 * numBuf,uint32 * offsetBuf)615         int32 getTimestampForRandomAccessPoints(uint32 *num, uint32 *tsBuf, uint32* numBuf, uint32 *offsetBuf)
616         {
617             if (_pmediaInformation != NULL)
618             {
619                 return _pmediaInformation->getTimestampForRandomAccessPoints(num, tsBuf, numBuf, offsetBuf);
620             }
621             else
622             {
623                 return 0;
624             }
625         }
626 
getTimestampForRandomAccessPointsBeforeAfter(uint32 ts,uint32 * tsBuf,uint32 * numBuf,uint32 & numsamplestoget,uint32 howManyKeySamples)627         int32 getTimestampForRandomAccessPointsBeforeAfter(uint32 ts, uint32 *tsBuf, uint32* numBuf,
628                 uint32& numsamplestoget,
629                 uint32 howManyKeySamples)
630         {
631             if (_pmediaInformation != NULL)
632             {
633                 return _pmediaInformation->getTimestampForRandomAccessPointsBeforeAfter(ts, tsBuf, numBuf, numsamplestoget, howManyKeySamples);
634             }
635             else
636             {
637                 return 0;
638             }
639 
640         }
641 
642 
getNumAMRFramesPerSample()643         int32 getNumAMRFramesPerSample()
644         {
645             if (_pmediaInformation != NULL)
646             {
647                 return (_pmediaInformation->getNumAMRFramesPerSample());
648             }
649             else
650             {
651                 return 0;
652             }
653         }
654 
getMaxTrackTimeStamp(uint32 fileSize,uint32 & timeStamp)655         MP4_ERROR_CODE getMaxTrackTimeStamp(uint32 fileSize, uint32& timeStamp)
656         {
657             if (_pmediaInformation != NULL)
658             {
659                 return (_pmediaInformation->getMaxTrackTimeStamp(fileSize, timeStamp));
660             }
661             else
662             {
663                 return DEFAULT_ERROR;
664             }
665         }
666 
667         MP4_ERROR_CODE getSampleNumberClosestToTimeStamp(uint32 &sampleNumber,
668                 uint32 timeStamp,
669                 uint32 sampleOffset = 0)
670         {
671             if (_pmediaInformation != NULL)
672             {
673                 return
674                     (_pmediaInformation->getSampleNumberClosestToTimeStamp(sampleNumber,
675                             timeStamp,
676                             sampleOffset));
677             }
678             else
679             {
680                 return (READ_FAILED);
681             }
682         }
683 
getAVCSampleEntry(uint32 index)684         AVCSampleEntry* getAVCSampleEntry(uint32 index)
685         {
686             if (_pmediaInformation != NULL)
687             {
688                 return (_pmediaInformation->getAVCSampleEntry(index));
689             }
690             return (NULL);
691         }
692 
getAVCNALLengthSize(uint32 index)693         uint32 getAVCNALLengthSize(uint32 index)
694         {
695             if (_pmediaInformation != NULL)
696             {
697                 return (_pmediaInformation->getAVCNALLengthSize(index));
698             }
699             return 0;
700         }
701 
getNumAVCSampleEntries()702         uint32 getNumAVCSampleEntries()
703         {
704             if (_pmediaInformation != NULL)
705             {
706                 return (_pmediaInformation->getNumAVCSampleEntries());
707             }
708             return 0;
709         }
710 
getTrackLevelOMA2DRMInfoSize()711         uint32 getTrackLevelOMA2DRMInfoSize()
712         {
713             if (_pmediaInformation != NULL)
714             {
715                 return (_pmediaInformation->getTrackLevelOMA2DRMInfoSize());
716             }
717             return 0;
718         }
719 
getTrackLevelOMA2DRMInfo()720         uint8* getTrackLevelOMA2DRMInfo()
721         {
722             if (_pmediaInformation != NULL)
723             {
724                 return (_pmediaInformation->getTrackLevelOMA2DRMInfo());
725             }
726             return NULL;
727         }
728 
isMultipleSampleDescriptionAvailable()729         bool isMultipleSampleDescriptionAvailable()
730         {
731             if (_pmediaInformation != NULL)
732             {
733                 return (_pmediaInformation->isMultipleSampleDescriptionAvailable());
734             }
735             return 0;
736         }
737 
738     private:
739         MediaHeaderAtom *_pmediaHeader;
740         HandlerAtom *_phandler;
741         MediaInformationAtom *_pmediaInformation;
742 
743         uint32 _trackStartOffset;
744 };
745 
746 #endif // MEDIAATOM_H_INCLUDED
747 
748