blob: 04e8a6a1bdd8c7858ec8d2b8581a37faa4a74773 [file] [log] [blame]
Andreas Hubere46b7be2009-07-14 16:56:47 -07001/*
2 * Copyright (C) 2009 The Android Open Source Project
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 express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef MPEG4_EXTRACTOR_H_
18
19#define MPEG4_EXTRACTOR_H_
20
21#include <media/stagefright/MediaExtractor.h>
Andreas Huberc2c9dd32010-01-19 16:43:53 -080022#include <utils/Vector.h>
Andreas Hubere46b7be2009-07-14 16:56:47 -070023
24namespace android {
25
Andreas Huberefdd0882010-08-25 11:09:41 -070026struct AMessage;
Andreas Hubere46b7be2009-07-14 16:56:47 -070027class DataSource;
28class SampleTable;
29class String8;
30
31class MPEG4Extractor : public MediaExtractor {
32public:
33 // Extractor assumes ownership of "source".
Andreas Huberbe06d262009-08-14 14:37:10 -070034 MPEG4Extractor(const sp<DataSource> &source);
Andreas Hubere46b7be2009-07-14 16:56:47 -070035
Andreas Huber1cb02bf2010-01-13 11:25:10 -080036 virtual size_t countTracks();
37 virtual sp<MediaSource> getTrack(size_t index);
38 virtual sp<MetaData> getTrackMetaData(size_t index, uint32_t flags);
39
40 virtual sp<MetaData> getMetaData();
Andreas Huberbe06d262009-08-14 14:37:10 -070041
Gloria Wangd5770912010-06-22 13:55:38 -070042 // for DRM
43 virtual void setDrmFlag(bool flag);
44 virtual char* getDrmTrackInfo(size_t trackID, int *len);
45
Andreas Huberbe06d262009-08-14 14:37:10 -070046protected:
47 virtual ~MPEG4Extractor();
Andreas Hubere46b7be2009-07-14 16:56:47 -070048
49private:
50 struct Track {
51 Track *next;
52 sp<MetaData> meta;
53 uint32_t timescale;
Andreas Huberbe06d262009-08-14 14:37:10 -070054 sp<SampleTable> sampleTable;
Andreas Hubere981c332009-10-22 13:49:30 -070055 bool includes_expensive_metadata;
Andreas Huber4d60fc52010-03-12 16:15:53 -080056 bool skipTrack;
Andreas Hubere46b7be2009-07-14 16:56:47 -070057 };
58
Andreas Huberbe06d262009-08-14 14:37:10 -070059 sp<DataSource> mDataSource;
Andreas Hubere46b7be2009-07-14 16:56:47 -070060 bool mHaveMetadata;
Andreas Huber1cb02bf2010-01-13 11:25:10 -080061 bool mHasVideo;
Andreas Hubere46b7be2009-07-14 16:56:47 -070062
63 Track *mFirstTrack, *mLastTrack;
64
Andreas Huberc2c9dd32010-01-19 16:43:53 -080065 sp<MetaData> mFileMetaData;
66
Andreas Huberc2c9dd32010-01-19 16:43:53 -080067 Vector<uint32_t> mPath;
Andreas Hubere46b7be2009-07-14 16:56:47 -070068
69 status_t readMetaData();
James Dongb1262a82010-11-16 14:04:54 -080070 status_t parseChunk(off64_t *offset, int depth);
71 status_t parseMetaData(off64_t offset, size_t size);
Andreas Hubere46b7be2009-07-14 16:56:47 -070072
Andreas Huberd2315962010-01-29 14:46:59 -080073 status_t updateAudioTrackInfoFromESDS_MPEG4Audio(
74 const void *esds_data, size_t esds_size);
75
Andreas Huber5ee0bce2010-02-23 10:12:02 -080076 static status_t verifyTrack(Track *track);
77
Gloria Wangd5770912010-06-22 13:55:38 -070078 struct SINF {
79 SINF *next;
80 uint16_t trackID;
81 uint8_t IPMPDescriptorID;
82 ssize_t len;
83 char *IPMPData;
84 };
85
86 SINF *mFirstSINF;
87
88 bool mIsDrm;
James Dongb1262a82010-11-16 14:04:54 -080089 status_t parseDrmSINF(off64_t *offset, off64_t data_offset);
Gloria Wangd5770912010-06-22 13:55:38 -070090
James Dongb1262a82010-11-16 14:04:54 -080091 status_t parseTrackHeader(off64_t data_offset, off64_t data_size);
Andreas Huber940c8662010-11-16 15:26:30 -080092
Andreas Hubere46b7be2009-07-14 16:56:47 -070093 MPEG4Extractor(const MPEG4Extractor &);
94 MPEG4Extractor &operator=(const MPEG4Extractor &);
95};
96
Andreas Huberbe06d262009-08-14 14:37:10 -070097bool SniffMPEG4(
Andreas Huberefdd0882010-08-25 11:09:41 -070098 const sp<DataSource> &source, String8 *mimeType, float *confidence,
99 sp<AMessage> *);
Andreas Hubere46b7be2009-07-14 16:56:47 -0700100
101} // namespace android
102
103#endif // MPEG4_EXTRACTOR_H_