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