• 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 Mpeg4File Class                             */
21 /*     -------------------------------------------------------------------       */
22 /*********************************************************************************/
23 /*
24     The Mpeg4File Class is the class that will construct and maintain all the
25     mecessary data structures to be able to render a valid MP4 file to disk.
26     Format.
27 */
28 
29 #ifndef IMPEG4FILE_H_INCLUDED
30 #define IMPEG4FILE_H_INCLUDED
31 
32 #ifndef OSCL_BASE_H_INCLUDED
33 #include "oscl_base.h"
34 #endif
35 
36 #ifndef OSCL_MEM_H_INCLUDED
37 #include "oscl_mem.h"
38 #endif
39 
40 #ifndef OSCL_STRING_CONTAINERS_H_INCLUDED
41 #include "oscl_string_containers.h"
42 #endif
43 
44 //HEADER FILES REQD FOR MULTIPLE SAMPLE RETRIEVAL API
45 #ifndef OSCL_MEDIA_DATA_H_INCLUDED
46 #include "oscl_media_data.h"
47 #endif
48 #ifndef PV_GAU_H_INCLUDED
49 #include "pv_gau.h"
50 #endif
51 
52 #ifndef TEXTSAMPLEENTRY_H_INCLUDED
53 #include "textsampleentry.h"
54 #endif
55 #ifndef FONTRECORD_H_INCLUDED
56 #include "fontrecord.h"
57 #endif
58 
59 #ifndef ATOMDEFS_H_INCLUDED
60 #include "atomdefs.h"
61 #endif
62 
63 #ifndef PV_MP4FFPARSER_CONFIG_H_INCLUDED
64 #include "pv_mp4ffparser_config.h"
65 #endif
66 
67 /* CPM Related Header Files */
68 #ifndef CPM_H_INCLUDED
69 #include "cpm.h"
70 #endif
71 #include "pv_id3_parcom_types.h"
72 
73 class OsclFileHandle;
74 class PvmiDataStreamObserver;
75 class AVCSampleEntry;
76 /*------------- Interface of Class Mpeg4 File ----------------*/
77 class IMpeg4File : public ISucceedFail
78 {
79     public:
~IMpeg4File()80         virtual ~IMpeg4File() {} // So the Mpeg4File destructor gets called when delete the interface
81 
82         // MEDIA DATA APIS
83 
84         /* Returns media samples for the requested tracks
85            id:  The track ID of the track from which the method is to retrieve the samples.
86            buf: A pointer to the buffer into which to place the sample.
87            size:    The size of the data buffer
88            index:   An output parameter which is the index of the sample entry to which the returned sample refers.
89            return:  The size in bytes of the data placed into the provided buffer.  If the buffer is not large enough, the return value is the negative of the size that is needed.
90         */
91         virtual int32 getNextMediaSample(uint32 id, uint8 *buf, uint32 &size, uint32 &index, uint32 &SampleOffset) = 0;
92 
93         virtual int32 getMediaSample(uint32 id, uint32 sampleNumber, uint8 *buf, int32 &size, uint32 &index, uint32 &SampleOffset) = 0;
94 
95         virtual int32 getOffsetByTime(uint32 id, uint32 ts, int32* sampleFileOffset, uint32 jitterbuffersize) = 0;
96 
97         virtual int32 updateFileSize(uint32 filesize) = 0;
98 
99         virtual MP4_ERROR_CODE getKeyMediaSampleNumAt(uint32 aTrackId,
100                 uint32 aKeySampleNum,
101                 GAU    *pgau) = 0;
102         virtual int32 getPrevKeyMediaSample(uint32 inputtimestamp,
103                                             uint32 &aKeySampleNum,
104                                             uint32 id,
105                                             uint32 *n,
106                                             GAU    *pgau) = 0;
107         virtual int32 getNextKeyMediaSample(uint32 inputtimestamp,
108                                             uint32 &aKeySampleNum,
109                                             uint32 id,
110                                             uint32 *n,
111                                             GAU    *pgau) = 0;
112 
113         /* Returns the timestamp for the previously returned media samples from the requested track
114            id:  The track ID of the track from which the method is to retrieve the sample timestamp.
115            return:  The timestamp of the most recently return media sample in the "media timescale"
116         */
117         virtual uint32 getMediaTimestampForCurrentSample(uint32 id) = 0;
118 
119 
120         // META DATA APIS
121 
122         // From PVUserDataAtom 'pvmm'
123         virtual OSCL_wString& getPVVersion(MP4FFParserOriginalCharEnc &charType) = 0;       // return _version string
124         virtual OSCL_wHeapString<OsclMemAllocator> getCreationDate(MP4FFParserOriginalCharEnc &charType) = 0;   // return _creationDate string
125 
126         // from 'ftyp' atom
127         virtual uint32 getCompatibiltyMajorBrand() = 0;
128         virtual uint32 getCompatibiltyMajorBrandVersion() = 0;
129         virtual Oscl_Vector<uint32, OsclMemAllocator> *getCompatibiltyList() = 0;
130 
131         // From Movie
132         virtual int32 getNumTracks() = 0;
133         virtual int32 getTrackIDList(uint32 *ids, int size) = 0;
134         virtual uint32 getTrackWholeIDList(uint32 *ids) = 0;
135 
136         // From MovieHeader
137         virtual uint64 getMovieDuration() const = 0;
138         virtual uint32 getMovieTimescale() const = 0;
139 
140 
141         // From TrackHeader
142         virtual uint64 getTrackDuration(uint32 id) = 0; // in movie timescale
143 
144         // From TrackReference
145         // Returns the track ID of the track on which this track depends
146         virtual uint32 trackDependsOn(uint32 id) = 0;
147 
148         // From MediaHeader
149         virtual uint64 getTrackMediaDuration(uint32 id) = 0;
150         virtual uint32 getTrackMediaTimescale(uint32 id) = 0;
151         virtual uint16 getTrackLangCode(uint32 id) = 0;
152 
153         // From Handler
154         // Returns the 4CC of the track media type (i.e. 'vide' for video)
155         virtual uint32 getTrackMediaType(uint32 id) = 0;
156 
157         // From SampleDescription
158         // Returns the number of sample entries stored in the sample description
159         virtual int32 getTrackNumSampleEntries(uint32 id) = 0;
160 
161         // From DecoderConfigDescriptor
162         virtual void getTrackMIMEType(uint32 id, OSCL_String& aMimeType) = 0; // Based on OTI and string tables
163 
164         virtual int32  getTrackMaxBufferSizeDB(uint32 id) = 0;
165         virtual int32  getTrackAverageBitrate(uint32 id) = 0;
166 
167         virtual uint8 *getTrackDecoderSpecificInfoContent(uint32 id) = 0;
168         virtual uint32 getTrackDecoderSpecificInfoSize(uint32 id) = 0;
169         virtual DecoderSpecificInfo *getTrackDecoderSpecificInfoAtSDI(uint32 trackID, uint32 index) = 0;
170 
171         virtual uint32 getTimestampForSampleNumber(uint32 id, uint32 sampleNumber) = 0;
172         virtual int32 getSampleSizeAt(uint32 id, int32 sampleNum) = 0;
173 
174         //From PASP atom
175         virtual uint32 getHspacing(uint32 id) = 0;
176         virtual uint32 getVspacing(uint32 id) = 0;
177 
178 
179 
180         // MPEG4 header retrieval methods
181         virtual int32 getFileType() const = 0;
182         virtual int32 getScalability() const = 0;
183 
184         virtual int32 getTimestampForRandomAccessPoints(uint32 id, uint32 *num, uint32 *tsBuf, uint32* numBuf, uint32* offsetBuf = NULL) = 0;
185         virtual int32 getTimestampForRandomAccessPointsBeforeAfter(uint32 id, uint32 ts, uint32 *tsBuf, uint32* numBuf,
186                 uint32 &numsamplestoget,
187                 uint32 howManyKeySamples = 1) = 0;
188 
189         // Static method to read in an MP4 file from disk and return the IMpeg4File interface
190         OSCL_IMPORT_REF static IMpeg4File *readMP4File(OSCL_wString& aFilename,
191                 PVMFCPMPluginAccessInterfaceFactory* aCPMAccessFactory,
192                 OsclFileHandle* aHandle = NULL,
193                 uint32 aParsingMode = 0,
194                 Oscl_FileServer* aFileServSession = NULL);
195 
196         OSCL_IMPORT_REF static void DestroyMP4FileObject(IMpeg4File* aMP4FileObject);
197 
198         virtual bool CreateDataStreamSessionForExternalDownload(OSCL_wString& aFilename,
199                 PVMFCPMPluginAccessInterfaceFactory* aCPMAccessFactory,
200                 OsclFileHandle* aHandle = NULL,
201                 Oscl_FileServer* aFileServSession = NULL) = 0;
202 
203         virtual void DestroyDataStreamForExternalDownload() = 0;
204 
205         virtual void resetPlayback() = 0;
206         virtual uint32 resetPlayback(uint32 time, uint16 numTracks, uint32 *trackList, bool bResetToIFrame = true) = 0;
207         virtual int32 queryRepositionTime(uint32 time,
208                                           uint16 numTracks,
209                                           uint32 *trackList,
210                                           bool bResetToIFrame = true,
211                                           bool bBeforeRequestedTime = true) = 0;
212 
213         virtual int32 querySyncFrameBeforeTime(uint32 time, uint16 numTracks, uint32 *trackList) = 0;
214 
215         virtual int32 getNextBundledAccessUnits(const uint32 id,
216                                                 uint32 *n,
217                                                 GAU    *pgau) = 0;
218 
219         virtual int32 peekNextBundledAccessUnits(const uint32 id,
220                 uint32 *n,
221                 MediaMetaInfo *mInfo) = 0;
222 
223         virtual uint32 getSampleCountInTrack(uint32 id) = 0;
224 
225         virtual uint32 getAssetInfoClassificationEntity(int32 index = 0) const = 0;
226         virtual uint16 getAssetInfoClassificationTable(int32 index = 0) const = 0;
227         virtual uint16 getAssetInfoClassificationLangCode(int32 index = 0) const = 0;
228         virtual OSCL_wString& getAssetInfoClassificationNotice(MP4FFParserOriginalCharEnc &charType, int32 index = 0) const = 0;
229         virtual uint16 getAssetInfoNumKeyWords(int32 index = 0) const = 0;
230         virtual uint16 getAssetInfoKeyWordLangCode(int32 index = 0) const = 0;
231         virtual OSCL_wString& getAssetInfoKeyWord(int32 atomIndex, int32 keyWordIndex) const = 0;
232         virtual int32 getNumAssetInfoClassificationAtoms() = 0;
233         virtual int32 getNumAssetInfoKeyWordAtoms() = 0;
234         virtual int32 getNumAssetInfoLocationAtoms() = 0;
235 
236         virtual PvmfAssetInfo3GPPLocationStruct *getAssetInfoLocationStruct(int32 index = 0) const = 0;
237         virtual uint8 getAssetInfoAlbumTrackNumber(int32 index = 0) = 0;
238 
239         //id3
240         virtual PVID3Version GetID3Version() const = 0;
241         virtual void GetID3MetaData(PvmiKvpSharedPtrVector &id3Frames) = 0;
242 
243         virtual bool IsTFRAPresentForAllTrack(uint32 numTracks, uint32 *trackList) = 0;
244         virtual uint32 getNumKeyFrames(uint32 trackid) = 0;
245 
246         virtual int16 getLayer(uint32 trackid) = 0;
247         virtual uint16 getAlternateGroup(uint32 trackid) = 0;
248 
249         virtual int32 getVideoFrameHeight(uint32 trackid) = 0;
250         virtual int32 getVideoFrameWidth(uint32 trackid) = 0;
251 
252         virtual int32 getTextTrackWidth(uint32 trackid) = 0;
253         virtual int32 getTextTrackHeight(uint32 trackid) = 0;
254         virtual int32 getTextTrackXOffset(uint32 trackid) = 0;
255         virtual int32 getTextTrackYOffset(uint32 trackid) = 0;
256         virtual SampleEntry *getTextSampleEntryAt(uint32 trackid, uint32 index) = 0;
257 
258 
259         OSCL_IMPORT_REF static int32 IsXXXable(OSCL_wString& filename,
260                                                int32 &metaDataSize,
261                                                int32  &oMoovBeforeMdat,
262                                                uint32 *pMajorBrand,
263                                                uint32 *pCompatibleBrands,
264                                                Oscl_FileServer* fileServSession = NULL);
265 
266 
267         OSCL_IMPORT_REF static int32 IsXXXable(Oscl_File* fileRef,
268                                                int32 &metaDataSize,
269                                                int32  &oMoovBeforeMdat,
270                                                uint32 *pMajorBrand,
271                                                uint32 *pCompatibleBrands);
272 
273         virtual bool IsMobileMP4() = 0;
274 
275         virtual int32 getNumAMRFramesPerSample(uint32 trackID) = 0;
276 
277         virtual uint8 parseBufferAndGetNumAMRFrames(uint8* buffer, uint32 size) = 0;
278 
279         virtual uint32 getNumAVCSampleEntries(uint32 trackID) = 0;
280 
281         virtual AVCSampleEntry* getAVCSampleEntry(uint32 trackID, uint32 index = 0) = 0;
282 
283         virtual uint32 getAVCNALLengthSize(uint32 trackID, uint32 index = 0) = 0;
284 
285         /*
286          * @param Oscl_File* filePtr - File pointer to the MP4/3GP
287          * file. Please note that the file open and close are handled by the
288          * caller.
289          *
290          * @param uint32 fileSize - Size of the downloaded file, thus far.
291          *
292          *
293          * @param bool& oIsProgressiveDownloadable - Set to true if the clip is
294          * is progressive dowmloadable.
295          *
296          * @param uint32& metaDataSize - If the clip is progressive
297          * downloadable then this API also returns the meta data size. Player
298          * needs to wait for the file to grow past the metaDataSize before
299          * starting playback.This param is valid only if oIsProgressiveDownloadable
300          * is set to TRUE.
301          *
302          * @return MP4_ERROR_CODE - EVERYTHING_FINE, if a conclusion is reached
303          * either way on whether a clip is progressive downloadable or not.
304          * INSUFFICIENT_DATA, if more calls to this API are needed to reach a
305          * decision
306          * Any other return value indicates error.
307          */
308         OSCL_IMPORT_REF static MP4_ERROR_CODE IsProgressiveDownloadable(Oscl_File* filePtr,
309                 uint32  fileSize,
310                 bool& oIsProgressiveDownloadable,
311                 uint32& metaDataSize);
312 
313         /*
314          * @param aCPMAccessFactory aCPMAccessFactory - Pointer to the datastream
315          * factory.
316          *
317          * @param bool& oIsProgressiveDownloadable - Set to true if the clip is
318          * is progressive dowmloadable.
319          *
320          * @param uint32& metaDataSize - If the clip is progressive
321          * downloadable then this API also returns the meta data size. Player
322          * needs to wait for the file to grow past the metaDataSize before
323          * starting playback.This param is valid only if oIsProgressiveDownloadable
324          * is set to TRUE.
325          *
326          * @return MP4_ERROR_CODE - EVERYTHING_FINE, if a conclusion is reached
327          * either way on whether a clip is progressive downloadable or not.
328          * INSUFFICIENT_DATA, if more calls to this API are needed to reach a
329          * decision
330          * Any other return value indicates error.
331          */
332         OSCL_IMPORT_REF static MP4_ERROR_CODE GetMetaDataSize(PVMFCPMPluginAccessInterfaceFactory* aCPMAccessFactory,
333                 bool& oIsProgressiveDownloadable,
334                 uint32& metaDataSize);
335 
336 
337         /*
338          * This API return the timestamp of a sample that is closest to the given
339          * fileSize.
340          *
341          * @param trackID
342          *
343          * @param fileSize
344          *
345          * @param uint32& timeStamp
346          *
347          * @return EVERYTHING_FINE - In case a valid sample and corresponding time
348          * stamp was located.
349          * INSUFFICIENT_DATA in case the very first sample location is past the fileSize
350          * NOT_SUPPORTED - in case "parsingMode" is set to 1, in "readMP4File"
351          * call
352          * Any other return value indicates ERROR.
353          *
354          */
355 
356         MP4_ERROR_CODE virtual getMaxTrackTimeStamp(uint32 trackID,
357                 uint32 fileSize,
358                 uint32& timeStamp) = 0;
359 
360         /*
361          * This API returns the closest sample number, prior to the required timestamp
362          * The timestamp is assumed to be in media time scale, hence no timescale
363          * conversions are performed internally.Closest frame number is returned in
364          * the argument "sampleNumber", and it is offset by "sampleOffset".
365          *
366          * @param trackID
367          *
368          * @param frameNumber
369          *
370          * @param timeStamp
371          *
372          * @param frameOffset
373          *
374          * @return MP4_ERROR_CODE
375          * In case the frameNumber closest to timestamp plus frameOffset falls
376          * beyond the track boundary, frameNumber is set to total number of samples
377          * per track and the return code is "END_OF_TRACK".In other error scenarios
378          * (like invalid timestamps, some missing atoms etc) frameNumber is set to
379          * zero, and return code is "READ_FAILED". In case of normal operation,
380          * return code is "EVERYTHING_FINE"
381          */
382         virtual MP4_ERROR_CODE getSampleNumberClosestToTimeStamp(uint32 trackID,
383                 uint32 &sampleNumber,
384                 uint32 timeStamp,
385                 uint32 sampleOffset = 0) = 0;
386 
387         /*
388          * This API returns the size of the "odkm" header if present at the
389          * track level. If the "odkm" header were not present at the
390          * track level, this API would return ZERO. Please note that
391          * the "odkm" is only present for OMA2 protected content.
392          */
393         virtual uint32 getTrackLevelOMA2DRMInfoSize(uint32 trackID) = 0;
394         /*
395          * This API returns a buffer containing the "odkm" header if present at the
396          * track level. If the "odkm" header were not present at the
397          * track level, this API would return NULL. The memory buffer
398          * returned is owned by the file parser lib. Please note that
399          * the "odkm" is only present for OMA2 protected content.
400          */
401         virtual uint8* getTrackLevelOMA2DRMInfo(uint32 trackID) = 0;
402 
403         /*
404          * This API is used to set a callback request on the datastream interface.
405          */
406         virtual MP4_ERROR_CODE RequestReadCapacityNotification(PvmiDataStreamObserver& aObserver,
407                 uint32 aFileOffset,
408                 OsclAny* aContextData = NULL) = 0;
409 
410         /*
411          * This API is used to cancel the callback request on the datastream interface.
412          */
413         virtual MP4_ERROR_CODE CancelNotificationSync() = 0;
414 
415         /*
416          * This API is used to get the current file size from the datastream interface.
417          */
418         virtual MP4_ERROR_CODE GetCurrentFileSize(uint32& aFileSize) = 0;
419 
420         virtual int32 getTrackTSStartOffset(uint32& aTSOffset, uint32 aTrackID) = 0;
421 
422         // ITunes Specific functions
423 
424         virtual OSCL_wHeapString<OsclMemAllocator> getITunesTool() const = 0;
425         virtual OSCL_wHeapString<OsclMemAllocator> getITunesEncodedBy() const = 0;
426         virtual OSCL_wHeapString<OsclMemAllocator> getITunesWriter() const = 0;
427         virtual OSCL_wHeapString<OsclMemAllocator> getITunesGroupData() const = 0;
428         virtual uint16 getITunesThisTrackNo() const = 0;
429         virtual PvmfApicStruct* getITunesImageData() const = 0;
430         virtual uint16 getITunesTotalTracks() const = 0;
431         virtual bool IsITunesCompilationPart() const = 0;
432         virtual bool IsITunesContentRating() const = 0;
433         virtual uint16 getITunesBeatsPerMinute() const = 0;
434         virtual uint16 getITunesThisDiskNo() const = 0;
435         virtual uint16 getITunesTotalDisks() const = 0;
436         virtual OSCL_wHeapString<OsclMemAllocator> getITunesNormalizationData() const = 0;
437         virtual OSCL_wHeapString<OsclMemAllocator> getITunesCDIdentifierData(uint8 aCDdatanumIndex) = 0;
438         virtual OSCL_wHeapString<OsclMemAllocator> getITunesCDTrackNumberData() const = 0;
439         virtual OSCL_wHeapString<OsclMemAllocator> getITunesCDDB1Data() const = 0;
440         virtual OSCL_wHeapString<OsclMemAllocator> getITunesLyrics() const = 0;
441         virtual uint8 getITunesTotalCDIdentifierData() const = 0;
442         virtual bool IsMovieFragmentsPresent() const = 0;
443         //Returns the Subtitle of individual track
444         virtual OSCL_wHeapString<OsclMemAllocator> getITunesTrackSubTitle() const = 0;
445 
446         // Reposition Related Video Track present API
447         virtual void ResetVideoTrackPresentFlag() = 0;
448 
449         //APIs to return the no. of titles and their metadata values respectively.
450         virtual uint32 getNumTitle() = 0;
451         virtual PVMFStatus getTitle(uint32 index, OSCL_wString& aVal, uint16& aLangCode, MP4FFParserOriginalCharEnc& aCharEncType) = 0;
452 
453         //APIs to return the no. of authors and their metadata values respectively.
454         virtual uint32 getNumAuthor() = 0;
455         virtual PVMFStatus getAuthor(uint32 index, OSCL_wString& aVal, uint16& aLangCode, MP4FFParserOriginalCharEnc& aCharEncType) = 0;
456 
457         //APIs to return the no. of albums and their metadata values respectively.
458         virtual uint32 getNumAlbum() = 0;
459         virtual PVMFStatus getAlbum(uint32 index, OSCL_wString& aVal, uint16& aLangCode, MP4FFParserOriginalCharEnc& aCharEncType) = 0;
460 
461         //APIs to return the no. of artist and their metadata values respectively.
462         virtual uint32 getNumArtist() = 0;
463         virtual PVMFStatus getArtist(uint32 index, OSCL_wString& aVal, uint16& aLangCode, MP4FFParserOriginalCharEnc& aCharEncType) = 0;
464 
465         //APIs to return the no. of genre and their metadata values respectively.
466         virtual uint32 getNumGenre() = 0;
467         virtual PVMFStatus getGenre(uint32 index, OSCL_wString& aVal, uint16& aLangCode, MP4FFParserOriginalCharEnc& aCharEncType) = 0;
468         virtual uint16 getITunesGnreID() const = 0;
469 
470         //APIs to return the no. of year and their metadata values respectively.
471         virtual uint32 getNumYear() = 0;
472         virtual PVMFStatus getYear(uint32 index, uint32& aVal) = 0;
473 
474         //APIs to return the no. of copyright and their metadata values respectively.
475         virtual uint32 getNumCopyright() = 0;
476         virtual PVMFStatus getCopyright(uint32 index, OSCL_wString& aVal, uint16& aLangCode, MP4FFParserOriginalCharEnc& aCharEncType) = 0;
477 
478         //APIs to return the no. of comment and their metadata values respectively.
479         virtual uint32 getNumComment() = 0;
480         virtual PVMFStatus getComment(uint32 index, OSCL_wString& aVal, uint16& aLangCode, MP4FFParserOriginalCharEnc& aCharEncType) = 0;
481 
482         //APIs to return the no. of description and their metadata values respectively.
483         virtual uint32 getNumDescription() = 0;
484         virtual PVMFStatus getDescription(uint32 index, OSCL_wString& aVal, uint16& aLangCode, MP4FFParserOriginalCharEnc& aCharEncType) = 0;
485 
486         //APIs to return the no. of rating and their metadata values respectively.
487         virtual uint32 getNumRating() = 0;
488         virtual PVMFStatus getRating(uint32 index, OSCL_wString& aVal, uint16& aLangCode, MP4FFParserOriginalCharEnc& aCharEncType) = 0;
489 
490 
491 };
492 
493 #endif // IMPEG4FILE_H_INCLUDED
494