NuPlayer.h revision 1cd139824b2e6832f239cd27d8962d3239053c02
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 MetaData; 28struct NuPlayerDriver; 29 30struct NuPlayer : public AHandler { 31 NuPlayer(); 32 33 void setUID(uid_t uid); 34 35 void setDriver(const wp<NuPlayerDriver> &driver); 36 37 void setDataSourceAsync(const sp<IStreamSource> &source); 38 39 void setDataSourceAsync( 40 const sp<IMediaHTTPService> &httpService, 41 const char *url, 42 const KeyedVector<String8, String8> *headers); 43 44 void setDataSourceAsync(int fd, int64_t offset, int64_t length); 45 46 void prepareAsync(); 47 48 void setVideoSurfaceTextureAsync( 49 const sp<IGraphicBufferProducer> &bufferProducer); 50 51 void setAudioSink(const sp<MediaPlayerBase::AudioSink> &sink); 52 void start(); 53 54 void pause(); 55 void resume(); 56 57 // Will notify the driver through "notifyResetComplete" once finished. 58 void resetAsync(); 59 60 // Will notify the driver through "notifySeekComplete" once finished. 61 void seekToAsync(int64_t seekTimeUs); 62 63 status_t setVideoScalingMode(int32_t mode); 64 status_t getTrackInfo(Parcel* reply) const; 65 status_t selectTrack(size_t trackIndex, bool select); 66 67protected: 68 virtual ~NuPlayer(); 69 70 virtual void onMessageReceived(const sp<AMessage> &msg); 71 72public: 73 struct NuPlayerStreamListener; 74 struct Source; 75 76private: 77 struct Decoder; 78 struct GenericSource; 79 struct HTTPLiveSource; 80 struct Renderer; 81 struct RTSPSource; 82 struct StreamingSource; 83 struct Action; 84 struct SeekAction; 85 struct SetSurfaceAction; 86 struct ShutdownDecoderAction; 87 struct PostMessageAction; 88 struct SimpleAction; 89 90 enum { 91 kWhatSetDataSource = '=DaS', 92 kWhatPrepare = 'prep', 93 kWhatSetVideoNativeWindow = '=NaW', 94 kWhatSetAudioSink = '=AuS', 95 kWhatMoreDataQueued = 'more', 96 kWhatStart = 'strt', 97 kWhatScanSources = 'scan', 98 kWhatVideoNotify = 'vidN', 99 kWhatAudioNotify = 'audN', 100 kWhatRendererNotify = 'renN', 101 kWhatReset = 'rset', 102 kWhatSeek = 'seek', 103 kWhatPause = 'paus', 104 kWhatResume = 'rsme', 105 kWhatPollDuration = 'polD', 106 kWhatSourceNotify = 'srcN', 107 kWhatGetTrackInfo = 'gTrI', 108 kWhatSelectTrack = 'selT', 109 }; 110 111 wp<NuPlayerDriver> mDriver; 112 bool mUIDValid; 113 uid_t mUID; 114 sp<Source> mSource; 115 uint32_t mSourceFlags; 116 sp<NativeWindowWrapper> mNativeWindow; 117 sp<MediaPlayerBase::AudioSink> mAudioSink; 118 sp<Decoder> mVideoDecoder; 119 bool mVideoIsAVC; 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