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