NuPlayer.h revision da38df5f080eb62a06b22c5bada4357cf756255e
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 ACodec; 28struct MetaData; 29struct NuPlayerDriver; 30 31struct NuPlayer : public AHandler { 32 NuPlayer(); 33 34 void setUID(uid_t uid); 35 36 void setDriver(const wp<NuPlayerDriver> &driver); 37 38 void setDataSourceAsync(const sp<IStreamSource> &source); 39 40 void setDataSourceAsync( 41 const char *url, const KeyedVector<String8, String8> *headers); 42 43 void setDataSourceAsync(int fd, int64_t offset, int64_t length); 44 45 void prepareAsync(); 46 47 void setVideoSurfaceTextureAsync( 48 const sp<IGraphicBufferProducer> &bufferProducer); 49 50 void setAudioSink(const sp<MediaPlayerBase::AudioSink> &sink); 51 void start(); 52 53 void pause(); 54 void resume(); 55 56 // Will notify the driver through "notifyResetComplete" once finished. 57 void resetAsync(); 58 59 // Will notify the driver through "notifySeekComplete" once finished. 60 void seekToAsync(int64_t seekTimeUs); 61 62 status_t setVideoScalingMode(int32_t mode); 63 64protected: 65 virtual ~NuPlayer(); 66 67 virtual void onMessageReceived(const sp<AMessage> &msg); 68 69public: 70 struct NuPlayerStreamListener; 71 struct Source; 72 73private: 74 struct Decoder; 75 struct GenericSource; 76 struct HTTPLiveSource; 77 struct Renderer; 78 struct RTSPSource; 79 struct StreamingSource; 80 struct Action; 81 struct SeekAction; 82 struct SetSurfaceAction; 83 struct SimpleAction; 84 85 enum { 86 kWhatSetDataSource = '=DaS', 87 kWhatPrepare = 'prep', 88 kWhatSetVideoNativeWindow = '=NaW', 89 kWhatSetAudioSink = '=AuS', 90 kWhatMoreDataQueued = 'more', 91 kWhatStart = 'strt', 92 kWhatScanSources = 'scan', 93 kWhatVideoNotify = 'vidN', 94 kWhatAudioNotify = 'audN', 95 kWhatRendererNotify = 'renN', 96 kWhatReset = 'rset', 97 kWhatSeek = 'seek', 98 kWhatPause = 'paus', 99 kWhatResume = 'rsme', 100 kWhatPollDuration = 'polD', 101 kWhatSourceNotify = 'srcN', 102 }; 103 104 wp<NuPlayerDriver> mDriver; 105 bool mUIDValid; 106 uid_t mUID; 107 sp<Source> mSource; 108 uint32_t mSourceFlags; 109 sp<NativeWindowWrapper> mNativeWindow; 110 sp<MediaPlayerBase::AudioSink> mAudioSink; 111 sp<Decoder> mVideoDecoder; 112 bool mVideoIsAVC; 113 bool mNeedsSwRenderer; 114 sp<Decoder> mAudioDecoder; 115 sp<Renderer> mRenderer; 116 117 List<sp<Action> > mDeferredActions; 118 119 bool mAudioEOS; 120 bool mVideoEOS; 121 122 bool mScanSourcesPending; 123 int32_t mScanSourcesGeneration; 124 125 int32_t mPollDurationGeneration; 126 127 enum FlushStatus { 128 NONE, 129 AWAITING_DISCONTINUITY, 130 FLUSHING_DECODER, 131 FLUSHING_DECODER_SHUTDOWN, 132 SHUTTING_DOWN_DECODER, 133 FLUSHED, 134 SHUT_DOWN, 135 }; 136 137 // Once the current flush is complete this indicates whether the 138 // notion of time has changed. 139 bool mTimeDiscontinuityPending; 140 141 FlushStatus mFlushingAudio; 142 FlushStatus mFlushingVideo; 143 144 int64_t mSkipRenderingAudioUntilMediaTimeUs; 145 int64_t mSkipRenderingVideoUntilMediaTimeUs; 146 147 int64_t mVideoLateByUs; 148 int64_t mNumFramesTotal, mNumFramesDropped; 149 150 int32_t mVideoScalingMode; 151 152 bool mStarted; 153 154 status_t instantiateDecoder(bool audio, sp<Decoder> *decoder); 155 156 status_t feedDecoderInputData(bool audio, const sp<AMessage> &msg); 157 void renderBuffer(bool audio, const sp<AMessage> &msg); 158 159 void notifyListener(int msg, int ext1, int ext2); 160 161 void finishFlushIfPossible(); 162 163 void flushDecoder(bool audio, bool needShutdown); 164 165 static bool IsFlushingState(FlushStatus state, bool *needShutdown = NULL); 166 167 void postScanSources(); 168 169 void schedulePollDuration(); 170 void cancelPollDuration(); 171 172 void processDeferredActions(); 173 174 void performSeek(int64_t seekTimeUs); 175 void performDecoderFlush(); 176 void performDecoderShutdown(); 177 void performReset(); 178 void performScanSources(); 179 void performSetSurface(const sp<NativeWindowWrapper> &wrapper); 180 181 void onSourceNotify(const sp<AMessage> &msg); 182 183 DISALLOW_EVIL_CONSTRUCTORS(NuPlayer); 184}; 185 186} // namespace android 187 188#endif // NU_PLAYER_H_ 189