GenericSource.h revision 5e5a6e100920679f20b4d7fae0d8866ec5053f7e
1/* 2 * Copyright (C) 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 GENERIC_SOURCE_H_ 18 19#define GENERIC_SOURCE_H_ 20 21#include "NuPlayer.h" 22#include "NuPlayerSource.h" 23 24#include "ATSParser.h" 25 26#include <media/mediaplayer.h> 27 28namespace android { 29 30class DecryptHandle; 31class DrmManagerClient; 32struct AnotherPacketSource; 33struct ARTSPController; 34struct DataSource; 35struct IMediaHTTPService; 36struct MediaSource; 37class MediaBuffer; 38struct NuCachedSource2; 39struct WVMExtractor; 40 41struct NuPlayer::GenericSource : public NuPlayer::Source { 42 GenericSource(const sp<AMessage> ¬ify, bool uidValid, uid_t uid); 43 44 status_t setDataSource( 45 const sp<IMediaHTTPService> &httpService, 46 const char *url, 47 const KeyedVector<String8, String8> *headers); 48 49 status_t setDataSource(int fd, int64_t offset, int64_t length); 50 51 virtual void prepareAsync(); 52 53 virtual void start(); 54 virtual void stop(); 55 virtual void pause(); 56 virtual void resume(); 57 58 virtual void disconnect(); 59 60 virtual status_t feedMoreTSData(); 61 62 virtual sp<MetaData> getFileFormatMeta() const; 63 64 virtual status_t dequeueAccessUnit(bool audio, sp<ABuffer> *accessUnit); 65 66 virtual status_t getDuration(int64_t *durationUs); 67 virtual size_t getTrackCount() const; 68 virtual sp<AMessage> getTrackInfo(size_t trackIndex) const; 69 virtual ssize_t getSelectedTrack(media_track_type type) const; 70 virtual status_t selectTrack(size_t trackIndex, bool select); 71 virtual status_t seekTo(int64_t seekTimeUs); 72 73 virtual status_t setBuffers(bool audio, Vector<MediaBuffer *> &buffers); 74 75protected: 76 virtual ~GenericSource(); 77 78 virtual void onMessageReceived(const sp<AMessage> &msg); 79 80 virtual sp<MetaData> getFormatMeta(bool audio); 81 82private: 83 enum { 84 kWhatPrepareAsync, 85 kWhatFetchSubtitleData, 86 kWhatFetchTimedTextData, 87 kWhatSendSubtitleData, 88 kWhatSendTimedTextData, 89 kWhatChangeAVSource, 90 kWhatPollBuffering, 91 kWhatGetFormat, 92 kWhatGetSelectedTrack, 93 kWhatSelectTrack, 94 kWhatSeek, 95 kWhatReadBuffer, 96 }; 97 98 Vector<sp<MediaSource> > mSources; 99 100 struct Track { 101 size_t mIndex; 102 sp<MediaSource> mSource; 103 sp<AnotherPacketSource> mPackets; 104 }; 105 106 Track mAudioTrack; 107 int64_t mAudioTimeUs; 108 Track mVideoTrack; 109 int64_t mVideoTimeUs; 110 Track mSubtitleTrack; 111 Track mTimedTextTrack; 112 113 int32_t mFetchSubtitleDataGeneration; 114 int32_t mFetchTimedTextDataGeneration; 115 int64_t mDurationUs; 116 bool mAudioIsVorbis; 117 bool mIsWidevine; 118 bool mUIDValid; 119 uid_t mUID; 120 sp<IMediaHTTPService> mHTTPService; 121 AString mUri; 122 KeyedVector<String8, String8> mUriHeaders; 123 int mFd; 124 int64_t mOffset; 125 int64_t mLength; 126 127 sp<DataSource> mDataSource; 128 sp<NuCachedSource2> mCachedSource; 129 sp<WVMExtractor> mWVMExtractor; 130 sp<MetaData> mFileMeta; 131 DrmManagerClient *mDrmManagerClient; 132 sp<DecryptHandle> mDecryptHandle; 133 bool mStarted; 134 String8 mContentType; 135 AString mSniffedMIME; 136 off64_t mMetaDataSize; 137 int64_t mBitrate; 138 int32_t mPollBufferingGeneration; 139 uint32_t mPendingReadBufferTypes; 140 mutable Mutex mReadBufferLock; 141 142 sp<ALooper> mLooper; 143 144 void resetDataSource(); 145 146 status_t initFromDataSource(); 147 void checkDrmStatus(const sp<DataSource>& dataSource); 148 int64_t getLastReadPosition(); 149 void setDrmPlaybackStatusIfNeeded(int playbackStatus, int64_t position); 150 151 status_t prefillCacheIfNecessary(); 152 153 void notifyPreparedAndCleanup(status_t err); 154 155 void onGetFormatMeta(sp<AMessage> msg) const; 156 sp<MetaData> doGetFormatMeta(bool audio) const; 157 158 void onGetSelectedTrack(sp<AMessage> msg) const; 159 ssize_t doGetSelectedTrack(media_track_type type) const; 160 161 void onSelectTrack(sp<AMessage> msg); 162 status_t doSelectTrack(size_t trackIndex, bool select); 163 164 void onSeek(sp<AMessage> msg); 165 status_t doSeek(int64_t seekTimeUs); 166 167 void onPrepareAsync(); 168 169 void fetchTextData( 170 uint32_t what, media_track_type type, 171 int32_t curGen, sp<AnotherPacketSource> packets, sp<AMessage> msg); 172 173 void sendTextData( 174 uint32_t what, media_track_type type, 175 int32_t curGen, sp<AnotherPacketSource> packets, sp<AMessage> msg); 176 177 sp<ABuffer> mediaBufferToABuffer( 178 MediaBuffer *mbuf, 179 media_track_type trackType, 180 int64_t *actualTimeUs = NULL); 181 182 void postReadBuffer(media_track_type trackType); 183 void onReadBuffer(sp<AMessage> msg); 184 void readBuffer( 185 media_track_type trackType, 186 int64_t seekTimeUs = -1ll, int64_t *actualTimeUs = NULL, bool formatChange = false); 187 188 void schedulePollBuffering(); 189 void cancelPollBuffering(); 190 void onPollBuffering(); 191 void notifyBufferingUpdate(int percentage); 192 193 DISALLOW_EVIL_CONSTRUCTORS(GenericSource); 194}; 195 196} // namespace android 197 198#endif // GENERIC_SOURCE_H_ 199