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