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