NuMediaExtractor.h revision 9d07855aaff8a6b502a3ab058002cdd4a278b965
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 size_t countTracks() const; 54 status_t getTrackFormat(size_t index, sp<AMessage> *format) const; 55 56 status_t selectTrack(size_t index); 57 status_t unselectTrack(size_t index); 58 59 status_t seekTo( 60 int64_t timeUs, 61 MediaSource::ReadOptions::SeekMode mode = 62 MediaSource::ReadOptions::SEEK_CLOSEST_SYNC); 63 64 status_t advance(); 65 status_t readSampleData(const sp<ABuffer> &buffer); 66 status_t getSampleTrackIndex(size_t *trackIndex); 67 status_t getSampleTime(int64_t *sampleTimeUs); 68 status_t getSampleMeta(sp<MetaData> *sampleMeta); 69 70 bool getCachedDuration(int64_t *durationUs, bool *eos) const; 71 72protected: 73 virtual ~NuMediaExtractor(); 74 75private: 76 enum TrackFlags { 77 kIsVorbis = 1, 78 }; 79 80 struct TrackInfo { 81 sp<MediaSource> mSource; 82 size_t mTrackIndex; 83 status_t mFinalResult; 84 MediaBuffer *mSample; 85 int64_t mSampleTimeUs; 86 87 uint32_t mTrackFlags; // bitmask of "TrackFlags" 88 }; 89 90 mutable Mutex mLock; 91 92 sp<DataSource> mDataSource; 93 94 sp<MediaExtractor> mImpl; 95 bool mIsWidevineExtractor; 96 97 Vector<TrackInfo> mSelectedTracks; 98 int64_t mTotalBitrate; // in bits/sec 99 int64_t mDurationUs; 100 101 ssize_t fetchTrackSamples( 102 int64_t seekTimeUs = -1ll, 103 MediaSource::ReadOptions::SeekMode mode = 104 MediaSource::ReadOptions::SEEK_CLOSEST_SYNC); 105 106 void releaseTrackSamples(); 107 108 bool getTotalBitrate(int64_t *bitRate) const; 109 void updateDurationAndBitrate(); 110 111 DISALLOW_EVIL_CONSTRUCTORS(NuMediaExtractor); 112}; 113 114} // namespace android 115 116#endif // NU_MEDIA_EXTRACTOR_H_ 117 118