NuPlayer.h revision ced1c2f8f6c422063092f5cc5c675ccdebb2dc10
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 ABuffer; 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 sp<IMediaHTTPService> &httpService, 42 const char *url, 43 const KeyedVector<String8, String8> *headers); 44 45 void setDataSourceAsync(int fd, int64_t offset, int64_t length); 46 47 void prepareAsync(); 48 49 void setVideoSurfaceTextureAsync( 50 const sp<IGraphicBufferProducer> &bufferProducer); 51 52 void setAudioSink(const sp<MediaPlayerBase::AudioSink> &sink); 53 void start(); 54 55 void pause(); 56 void resume(); 57 58 // Will notify the driver through "notifyResetComplete" once finished. 59 void resetAsync(); 60 61 // Will notify the driver through "notifySeekComplete" once finished. 62 void seekToAsync(int64_t seekTimeUs); 63 64 status_t setVideoScalingMode(int32_t mode); 65 status_t getTrackInfo(Parcel* reply) const; 66 status_t selectTrack(size_t trackIndex, bool select); 67 68protected: 69 virtual ~NuPlayer(); 70 71 virtual void onMessageReceived(const sp<AMessage> &msg); 72 73public: 74 struct NuPlayerStreamListener; 75 struct Source; 76 77private: 78 struct Decoder; 79 struct DecoderPassThrough; 80 struct CCDecoder; 81 struct GenericSource; 82 struct HTTPLiveSource; 83 struct Renderer; 84 struct RTSPSource; 85 struct StreamingSource; 86 struct Action; 87 struct SeekAction; 88 struct SetSurfaceAction; 89 struct ShutdownDecoderAction; 90 struct PostMessageAction; 91 struct SimpleAction; 92 93 enum { 94 kWhatSetDataSource = '=DaS', 95 kWhatPrepare = 'prep', 96 kWhatSetVideoNativeWindow = '=NaW', 97 kWhatSetAudioSink = '=AuS', 98 kWhatMoreDataQueued = 'more', 99 kWhatStart = 'strt', 100 kWhatScanSources = 'scan', 101 kWhatVideoNotify = 'vidN', 102 kWhatAudioNotify = 'audN', 103 kWhatClosedCaptionNotify = 'capN', 104 kWhatRendererNotify = 'renN', 105 kWhatReset = 'rset', 106 kWhatSeek = 'seek', 107 kWhatPause = 'paus', 108 kWhatResume = 'rsme', 109 kWhatPollDuration = 'polD', 110 kWhatSourceNotify = 'srcN', 111 kWhatGetTrackInfo = 'gTrI', 112 kWhatSelectTrack = 'selT', 113 }; 114 115 wp<NuPlayerDriver> mDriver; 116 bool mUIDValid; 117 uid_t mUID; 118 sp<Source> mSource; 119 uint32_t mSourceFlags; 120 sp<NativeWindowWrapper> mNativeWindow; 121 sp<MediaPlayerBase::AudioSink> mAudioSink; 122 sp<Decoder> mVideoDecoder; 123 bool mVideoIsAVC; 124 bool mOffloadAudio; 125 sp<Decoder> mAudioDecoder; 126 sp<CCDecoder> mCCDecoder; 127 sp<Renderer> mRenderer; 128 sp<ALooper> mRendererLooper; 129 130 List<sp<Action> > mDeferredActions; 131 132 bool mAudioEOS; 133 bool mVideoEOS; 134 135 bool mScanSourcesPending; 136 int32_t mScanSourcesGeneration; 137 138 int32_t mPollDurationGeneration; 139 int32_t mTimedTextGeneration; 140 141 enum FlushStatus { 142 NONE, 143 AWAITING_DISCONTINUITY, 144 FLUSHING_DECODER, 145 FLUSHING_DECODER_SHUTDOWN, 146 SHUTTING_DOWN_DECODER, 147 FLUSHED, 148 SHUT_DOWN, 149 }; 150 151 // Once the current flush is complete this indicates whether the 152 // notion of time has changed. 153 bool mTimeDiscontinuityPending; 154 155 FlushStatus mFlushingAudio; 156 FlushStatus mFlushingVideo; 157 158 int64_t mSkipRenderingAudioUntilMediaTimeUs; 159 int64_t mSkipRenderingVideoUntilMediaTimeUs; 160 161 int64_t mVideoLateByUs; 162 int64_t mNumFramesTotal, mNumFramesDropped; 163 164 int32_t mVideoScalingMode; 165 166 bool mStarted; 167 168 status_t instantiateDecoder(bool audio, sp<Decoder> *decoder); 169 170 void updateVideoSize( 171 const sp<AMessage> &inputFormat, 172 const sp<AMessage> &outputFormat = NULL); 173 174 status_t feedDecoderInputData(bool audio, const sp<AMessage> &msg); 175 void renderBuffer(bool audio, const sp<AMessage> &msg); 176 177 void notifyListener(int msg, int ext1, int ext2, const Parcel *in = NULL); 178 179 void finishFlushIfPossible(); 180 181 void flushDecoder(bool audio, bool needShutdown); 182 183 static bool IsFlushingState(FlushStatus state, bool *needShutdown = NULL); 184 185 void postScanSources(); 186 187 void schedulePollDuration(); 188 void cancelPollDuration(); 189 190 void processDeferredActions(); 191 192 void performSeek(int64_t seekTimeUs); 193 void performDecoderFlush(); 194 void performDecoderShutdown(bool audio, bool video); 195 void performReset(); 196 void performScanSources(); 197 void performSetSurface(const sp<NativeWindowWrapper> &wrapper); 198 199 void onSourceNotify(const sp<AMessage> &msg); 200 void onClosedCaptionNotify(const sp<AMessage> &msg); 201 202 void queueDecoderShutdown( 203 bool audio, bool video, const sp<AMessage> &reply); 204 205 void sendSubtitleData(const sp<ABuffer> &buffer, int32_t baseIndex); 206 void sendTimedTextData(const sp<ABuffer> &buffer); 207 208 void writeTrackInfo(Parcel* reply, const sp<AMessage> format) const; 209 210 DISALLOW_EVIL_CONSTRUCTORS(NuPlayer); 211}; 212 213} // namespace android 214 215#endif // NU_PLAYER_H_ 216