NuPlayer.h revision f0b72b509ab1147a2a0925aced970dd68fd7fa4f
1/* 2 * Copyright (C) 2010 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_PLAYER_H_ 18 19#define NU_PLAYER_H_ 20 21#include <media/MediaPlayerInterface.h> 22#include <media/stagefright/foundation/AHandler.h> 23#include <media/stagefright/NativeWindowWrapper.h> 24 25namespace android { 26 27struct ABuffer; 28struct AMessage; 29struct MetaData; 30struct NuPlayerDriver; 31 32struct NuPlayer : public AHandler { 33 NuPlayer(); 34 35 void setUID(uid_t uid); 36 37 void setDriver(const wp<NuPlayerDriver> &driver); 38 39 void setDataSourceAsync(const sp<IStreamSource> &source); 40 41 void setDataSourceAsync( 42 const sp<IMediaHTTPService> &httpService, 43 const char *url, 44 const KeyedVector<String8, String8> *headers); 45 46 void setDataSourceAsync(int fd, int64_t offset, int64_t length); 47 48 void prepareAsync(); 49 50 void setVideoSurfaceTextureAsync( 51 const sp<IGraphicBufferProducer> &bufferProducer); 52 53 void setAudioSink(const sp<MediaPlayerBase::AudioSink> &sink); 54 void start(); 55 56 void pause(); 57 void resume(); 58 59 // Will notify the driver through "notifyResetComplete" once finished. 60 void resetAsync(); 61 62 // Will notify the driver through "notifySeekComplete" once finished. 63 void seekToAsync(int64_t seekTimeUs); 64 65 status_t setVideoScalingMode(int32_t mode); 66 status_t getTrackInfo(Parcel* reply) const; 67 status_t getSelectedTrack(int32_t type, Parcel* reply) const; 68 status_t selectTrack(size_t trackIndex, bool select); 69 70 sp<MetaData> getFileMeta(); 71 72 static const size_t kAggregateBufferSizeBytes; 73 74protected: 75 virtual ~NuPlayer(); 76 77 virtual void onMessageReceived(const sp<AMessage> &msg); 78 79public: 80 struct NuPlayerStreamListener; 81 struct Source; 82 83private: 84 struct Decoder; 85 struct DecoderPassThrough; 86 struct CCDecoder; 87 struct GenericSource; 88 struct HTTPLiveSource; 89 struct Renderer; 90 struct RTSPSource; 91 struct StreamingSource; 92 struct Action; 93 struct SeekAction; 94 struct SetSurfaceAction; 95 struct ShutdownDecoderAction; 96 struct PostMessageAction; 97 struct SimpleAction; 98 99 enum { 100 kWhatSetDataSource = '=DaS', 101 kWhatPrepare = 'prep', 102 kWhatSetVideoNativeWindow = '=NaW', 103 kWhatSetAudioSink = '=AuS', 104 kWhatMoreDataQueued = 'more', 105 kWhatStart = 'strt', 106 kWhatScanSources = 'scan', 107 kWhatVideoNotify = 'vidN', 108 kWhatAudioNotify = 'audN', 109 kWhatClosedCaptionNotify = 'capN', 110 kWhatRendererNotify = 'renN', 111 kWhatReset = 'rset', 112 kWhatSeek = 'seek', 113 kWhatPause = 'paus', 114 kWhatResume = 'rsme', 115 kWhatPollDuration = 'polD', 116 kWhatSourceNotify = 'srcN', 117 kWhatGetTrackInfo = 'gTrI', 118 kWhatGetSelectedTrack = 'gSel', 119 kWhatSelectTrack = 'selT', 120 }; 121 122 wp<NuPlayerDriver> mDriver; 123 bool mUIDValid; 124 uid_t mUID; 125 sp<Source> mSource; 126 uint32_t mSourceFlags; 127 sp<NativeWindowWrapper> mNativeWindow; 128 int64_t mCurrentPositionUs; 129 sp<MediaPlayerBase::AudioSink> mAudioSink; 130 sp<Decoder> mVideoDecoder; 131 bool mVideoIsAVC; 132 bool mOffloadAudio; 133 audio_offload_info_t mCurrentOffloadInfo; 134 sp<Decoder> mAudioDecoder; 135 sp<CCDecoder> mCCDecoder; 136 sp<Renderer> mRenderer; 137 sp<ALooper> mRendererLooper; 138 int32_t mAudioDecoderGeneration; 139 int32_t mVideoDecoderGeneration; 140 141 List<sp<Action> > mDeferredActions; 142 143 bool mAudioEOS; 144 bool mVideoEOS; 145 146 bool mScanSourcesPending; 147 int32_t mScanSourcesGeneration; 148 149 int32_t mPollDurationGeneration; 150 int32_t mTimedTextGeneration; 151 152 enum FlushStatus { 153 NONE, 154 FLUSHING_DECODER, 155 FLUSHING_DECODER_SHUTDOWN, 156 SHUTTING_DOWN_DECODER, 157 FLUSHED, 158 SHUT_DOWN, 159 }; 160 161 // Once the current flush is complete this indicates whether the 162 // notion of time has changed. 163 bool mTimeDiscontinuityPending; 164 165 // Used by feedDecoderInputData to aggregate small buffers into 166 // one large buffer. 167 sp<ABuffer> mPendingAudioAccessUnit; 168 status_t mPendingAudioErr; 169 sp<ABuffer> mAggregateBuffer; 170 171 FlushStatus mFlushingAudio; 172 FlushStatus mFlushingVideo; 173 174 int64_t mSkipRenderingAudioUntilMediaTimeUs; 175 int64_t mSkipRenderingVideoUntilMediaTimeUs; 176 177 int64_t mVideoLateByUs; 178 int64_t mNumFramesTotal, mNumFramesDropped; 179 180 int32_t mVideoScalingMode; 181 182 bool mStarted; 183 184 inline const sp<Decoder> &getDecoder(bool audio) { 185 return audio ? mAudioDecoder : mVideoDecoder; 186 } 187 188 void openAudioSink(const sp<AMessage> &format, bool offloadOnly); 189 void closeAudioSink(); 190 191 status_t instantiateDecoder(bool audio, sp<Decoder> *decoder); 192 193 void updateVideoSize( 194 const sp<AMessage> &inputFormat, 195 const sp<AMessage> &outputFormat = NULL); 196 197 status_t feedDecoderInputData(bool audio, const sp<AMessage> &msg); 198 void renderBuffer(bool audio, const sp<AMessage> &msg); 199 200 void notifyListener(int msg, int ext1, int ext2, const Parcel *in = NULL); 201 202 void finishFlushIfPossible(); 203 204 void flushDecoder( 205 bool audio, bool needShutdown, const sp<AMessage> &newFormat = NULL); 206 void updateDecoderFormatWithoutFlush(bool audio, const sp<AMessage> &format); 207 208 static bool IsFlushingState(FlushStatus state, bool *needShutdown = NULL); 209 210 void postScanSources(); 211 212 void schedulePollDuration(); 213 void cancelPollDuration(); 214 215 void processDeferredActions(); 216 217 void performSeek(int64_t seekTimeUs); 218 void performDecoderFlush(); 219 void performDecoderShutdown(bool audio, bool video); 220 void performReset(); 221 void performScanSources(); 222 void performSetSurface(const sp<NativeWindowWrapper> &wrapper); 223 224 void onSourceNotify(const sp<AMessage> &msg); 225 void onClosedCaptionNotify(const sp<AMessage> &msg); 226 227 void queueDecoderShutdown( 228 bool audio, bool video, const sp<AMessage> &reply); 229 230 void sendSubtitleData(const sp<ABuffer> &buffer, int32_t baseIndex); 231 void sendTimedTextData(const sp<ABuffer> &buffer); 232 233 void writeTrackInfo(Parcel* reply, const sp<AMessage> format) const; 234 235 DISALLOW_EVIL_CONSTRUCTORS(NuPlayer); 236}; 237 238} // namespace android 239 240#endif // NU_PLAYER_H_ 241