NuPlayer.h revision 095248375e29adde961ec2a44989ecb3a6dda6a2
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 140 enum FlushStatus { 141 NONE, 142 AWAITING_DISCONTINUITY, 143 FLUSHING_DECODER, 144 FLUSHING_DECODER_SHUTDOWN, 145 SHUTTING_DOWN_DECODER, 146 FLUSHED, 147 SHUT_DOWN, 148 }; 149 150 // Once the current flush is complete this indicates whether the 151 // notion of time has changed. 152 bool mTimeDiscontinuityPending; 153 154 FlushStatus mFlushingAudio; 155 FlushStatus mFlushingVideo; 156 157 int64_t mSkipRenderingAudioUntilMediaTimeUs; 158 int64_t mSkipRenderingVideoUntilMediaTimeUs; 159 160 int64_t mVideoLateByUs; 161 int64_t mNumFramesTotal, mNumFramesDropped; 162 163 int32_t mVideoScalingMode; 164 165 bool mStarted; 166 167 status_t instantiateDecoder(bool audio, sp<Decoder> *decoder); 168 169 status_t feedDecoderInputData(bool audio, const sp<AMessage> &msg); 170 void renderBuffer(bool audio, const sp<AMessage> &msg); 171 172 void notifyListener(int msg, int ext1, int ext2, const Parcel *in = NULL); 173 174 void finishFlushIfPossible(); 175 176 void flushDecoder(bool audio, bool needShutdown); 177 178 static bool IsFlushingState(FlushStatus state, bool *needShutdown = NULL); 179 180 void postScanSources(); 181 182 void schedulePollDuration(); 183 void cancelPollDuration(); 184 185 void processDeferredActions(); 186 187 void performSeek(int64_t seekTimeUs); 188 void performDecoderFlush(); 189 void performDecoderShutdown(bool audio, bool video); 190 void performReset(); 191 void performScanSources(); 192 void performSetSurface(const sp<NativeWindowWrapper> &wrapper); 193 194 void onSourceNotify(const sp<AMessage> &msg); 195 void onClosedCaptionNotify(const sp<AMessage> &msg); 196 197 void queueDecoderShutdown( 198 bool audio, bool video, const sp<AMessage> &reply); 199 200 void sendSubtitleData(const sp<ABuffer> &buffer, int32_t baseIndex); 201 202 void writeTrackInfo(Parcel* reply, const sp<AMessage> format) const; 203 204 DISALLOW_EVIL_CONSTRUCTORS(NuPlayer); 205}; 206 207} // namespace android 208 209#endif // NU_PLAYER_H_ 210