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