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