1 /* 2 * Copyright 2012, 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 NU_MEDIA_EXTRACTOR_H_ 18 #define NU_MEDIA_EXTRACTOR_H_ 19 20 #include <media/stagefright/foundation/ABase.h> 21 #include <media/stagefright/MediaSource.h> 22 #include <utils/Errors.h> 23 #include <utils/KeyedVector.h> 24 #include <utils/RefBase.h> 25 #include <utils/String8.h> 26 #include <utils/threads.h> 27 #include <utils/Vector.h> 28 29 namespace android { 30 31 struct ABuffer; 32 struct AMessage; 33 struct DataSource; 34 struct IMediaHTTPService; 35 struct MediaBuffer; 36 struct MediaExtractor; 37 struct MediaSource; 38 struct MetaData; 39 40 struct NuMediaExtractor : public RefBase { 41 enum SampleFlags { 42 SAMPLE_FLAG_SYNC = 1, 43 SAMPLE_FLAG_ENCRYPTED = 2, 44 }; 45 46 NuMediaExtractor(); 47 48 status_t setDataSource( 49 const sp<IMediaHTTPService> &httpService, 50 const char *path, 51 const KeyedVector<String8, String8> *headers = NULL); 52 53 status_t setDataSource(int fd, off64_t offset, off64_t size); 54 55 status_t setDataSource(const sp<DataSource> &datasource); 56 57 size_t countTracks() const; 58 status_t getTrackFormat(size_t index, sp<AMessage> *format) const; 59 60 status_t getFileFormat(sp<AMessage> *format) const; 61 62 status_t selectTrack(size_t index); 63 status_t unselectTrack(size_t index); 64 65 status_t seekTo( 66 int64_t timeUs, 67 MediaSource::ReadOptions::SeekMode mode = 68 MediaSource::ReadOptions::SEEK_CLOSEST_SYNC); 69 70 status_t advance(); 71 status_t readSampleData(const sp<ABuffer> &buffer); 72 status_t getSampleTrackIndex(size_t *trackIndex); 73 status_t getSampleTime(int64_t *sampleTimeUs); 74 status_t getSampleMeta(sp<MetaData> *sampleMeta); 75 76 bool getCachedDuration(int64_t *durationUs, bool *eos) const; 77 78 protected: 79 virtual ~NuMediaExtractor(); 80 81 private: 82 enum TrackFlags { 83 kIsVorbis = 1, 84 }; 85 86 struct TrackInfo { 87 sp<MediaSource> mSource; 88 size_t mTrackIndex; 89 status_t mFinalResult; 90 MediaBuffer *mSample; 91 int64_t mSampleTimeUs; 92 93 uint32_t mTrackFlags; // bitmask of "TrackFlags" 94 }; 95 96 mutable Mutex mLock; 97 98 sp<DataSource> mDataSource; 99 100 sp<MediaExtractor> mImpl; 101 bool mIsWidevineExtractor; 102 103 Vector<TrackInfo> mSelectedTracks; 104 int64_t mTotalBitrate; // in bits/sec 105 int64_t mDurationUs; 106 107 ssize_t fetchTrackSamples( 108 int64_t seekTimeUs = -1ll, 109 MediaSource::ReadOptions::SeekMode mode = 110 MediaSource::ReadOptions::SEEK_CLOSEST_SYNC); 111 112 void releaseTrackSamples(); 113 114 bool getTotalBitrate(int64_t *bitRate) const; 115 void updateDurationAndBitrate(); 116 117 DISALLOW_EVIL_CONSTRUCTORS(NuMediaExtractor); 118 }; 119 120 } // namespace android 121 122 #endif // NU_MEDIA_EXTRACTOR_H_ 123 124