NuPlayer.h revision 92630351d265a61faae2dfe006a8bb330283aa7b
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 status_t getTrackInfo(Parcel* reply) const; 64 status_t selectTrack(size_t trackIndex, bool select); 65 66protected: 67 virtual ~NuPlayer(); 68 69 virtual void onMessageReceived(const sp<AMessage> &msg); 70 71public: 72 struct NuPlayerStreamListener; 73 struct Source; 74 75private: 76 struct Decoder; 77 struct GenericSource; 78 struct HTTPLiveSource; 79 struct Renderer; 80 struct RTSPSource; 81 struct StreamingSource; 82 struct Action; 83 struct SeekAction; 84 struct SetSurfaceAction; 85 struct ShutdownDecoderAction; 86 struct PostMessageAction; 87 struct SimpleAction; 88 89 enum { 90 kWhatSetDataSource = '=DaS', 91 kWhatPrepare = 'prep', 92 kWhatSetVideoNativeWindow = '=NaW', 93 kWhatSetAudioSink = '=AuS', 94 kWhatMoreDataQueued = 'more', 95 kWhatStart = 'strt', 96 kWhatScanSources = 'scan', 97 kWhatVideoNotify = 'vidN', 98 kWhatAudioNotify = 'audN', 99 kWhatRendererNotify = 'renN', 100 kWhatReset = 'rset', 101 kWhatSeek = 'seek', 102 kWhatPause = 'paus', 103 kWhatResume = 'rsme', 104 kWhatPollDuration = 'polD', 105 kWhatSourceNotify = 'srcN', 106 kWhatGetTrackInfo = 'gTrI', 107 kWhatSelectTrack = 'selT', 108 }; 109 110 wp<NuPlayerDriver> mDriver; 111 bool mUIDValid; 112 uid_t mUID; 113 sp<Source> mSource; 114 uint32_t mSourceFlags; 115 sp<NativeWindowWrapper> mNativeWindow; 116 sp<MediaPlayerBase::AudioSink> mAudioSink; 117 sp<Decoder> mVideoDecoder; 118 bool mVideoIsAVC; 119 bool mNeedsSwRenderer; 120 sp<Decoder> mAudioDecoder; 121 sp<Renderer> mRenderer; 122 123 List<sp<Action> > mDeferredActions; 124 125 bool mAudioEOS; 126 bool mVideoEOS; 127 128 bool mScanSourcesPending; 129 int32_t mScanSourcesGeneration; 130 131 int32_t mPollDurationGeneration; 132 133 enum FlushStatus { 134 NONE, 135 AWAITING_DISCONTINUITY, 136 FLUSHING_DECODER, 137 FLUSHING_DECODER_SHUTDOWN, 138 SHUTTING_DOWN_DECODER, 139 FLUSHED, 140 SHUT_DOWN, 141 }; 142 143 // Once the current flush is complete this indicates whether the 144 // notion of time has changed. 145 bool mTimeDiscontinuityPending; 146 147 FlushStatus mFlushingAudio; 148 FlushStatus mFlushingVideo; 149 150 int64_t mSkipRenderingAudioUntilMediaTimeUs; 151 int64_t mSkipRenderingVideoUntilMediaTimeUs; 152 153 int64_t mVideoLateByUs; 154 int64_t mNumFramesTotal, mNumFramesDropped; 155 156 int32_t mVideoScalingMode; 157 158 bool mStarted; 159 160 status_t instantiateDecoder(bool audio, sp<Decoder> *decoder); 161 162 status_t feedDecoderInputData(bool audio, const sp<AMessage> &msg); 163 void renderBuffer(bool audio, const sp<AMessage> &msg); 164 165 void notifyListener(int msg, int ext1, int ext2, const Parcel *in = NULL); 166 167 void finishFlushIfPossible(); 168 169 void flushDecoder(bool audio, bool needShutdown); 170 171 static bool IsFlushingState(FlushStatus state, bool *needShutdown = NULL); 172 173 void postScanSources(); 174 175 void schedulePollDuration(); 176 void cancelPollDuration(); 177 178 void processDeferredActions(); 179 180 void performSeek(int64_t seekTimeUs); 181 void performDecoderFlush(); 182 void performDecoderShutdown(bool audio, bool video); 183 void performReset(); 184 void performScanSources(); 185 void performSetSurface(const sp<NativeWindowWrapper> &wrapper); 186 187 void onSourceNotify(const sp<AMessage> &msg); 188 189 void queueDecoderShutdown( 190 bool audio, bool video, const sp<AMessage> &reply); 191 192 DISALLOW_EVIL_CONSTRUCTORS(NuPlayer); 193}; 194 195} // namespace android 196 197#endif // NU_PLAYER_H_ 198