NuPlayer.h revision 53904f372b9c4a5ea7f839012b52b3d564e41207
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 audio_offload_info_t mCurrentOffloadInfo; 128 sp<Decoder> mAudioDecoder; 129 sp<CCDecoder> mCCDecoder; 130 sp<Renderer> mRenderer; 131 sp<ALooper> mRendererLooper; 132 133 List<sp<Action> > mDeferredActions; 134 135 bool mAudioEOS; 136 bool mVideoEOS; 137 138 bool mScanSourcesPending; 139 int32_t mScanSourcesGeneration; 140 141 int32_t mPollDurationGeneration; 142 int32_t mTimedTextGeneration; 143 144 enum FlushStatus { 145 NONE, 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 void openAudioSink(const sp<AMessage> &format, bool offloadOnly); 171 void closeAudioSink(); 172 173 status_t instantiateDecoder(bool audio, sp<Decoder> *decoder); 174 175 void updateVideoSize( 176 const sp<AMessage> &inputFormat, 177 const sp<AMessage> &outputFormat = NULL); 178 179 status_t feedDecoderInputData(bool audio, const sp<AMessage> &msg); 180 void renderBuffer(bool audio, const sp<AMessage> &msg); 181 182 void notifyListener(int msg, int ext1, int ext2, const Parcel *in = NULL); 183 184 void finishFlushIfPossible(); 185 186 void flushDecoder(bool audio, bool needShutdown); 187 188 static bool IsFlushingState(FlushStatus state, bool *needShutdown = NULL); 189 190 void postScanSources(); 191 192 void schedulePollDuration(); 193 void cancelPollDuration(); 194 195 void processDeferredActions(); 196 197 void performSeek(int64_t seekTimeUs); 198 void performDecoderFlush(); 199 void performDecoderShutdown(bool audio, bool video); 200 void performReset(); 201 void performScanSources(); 202 void performSetSurface(const sp<NativeWindowWrapper> &wrapper); 203 204 void onSourceNotify(const sp<AMessage> &msg); 205 void onClosedCaptionNotify(const sp<AMessage> &msg); 206 207 void queueDecoderShutdown( 208 bool audio, bool video, const sp<AMessage> &reply); 209 210 void sendSubtitleData(const sp<ABuffer> &buffer, int32_t baseIndex); 211 void sendTimedTextData(const sp<ABuffer> &buffer); 212 213 void writeTrackInfo(Parcel* reply, const sp<AMessage> format) const; 214 215 DISALLOW_EVIL_CONSTRUCTORS(NuPlayer); 216}; 217 218} // namespace android 219 220#endif // NU_PLAYER_H_ 221