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