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