NuPlayer.h revision 282a7e31681840253a4cb6fab3f6725d35798699
1e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)/* 2e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) * Copyright (C) 2010 The Android Open Source Project 3e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) * 4e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) * Licensed under the Apache License, Version 2.0 (the "License"); 5e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) * you may not use this file except in compliance with the License. 6e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) * You may obtain a copy of the License at 7e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) * 8e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) * http://www.apache.org/licenses/LICENSE-2.0 9e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) * 10e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) * Unless required by applicable law or agreed to in writing, software 11e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) * distributed under the License is distributed on an "AS IS" BASIS, 12e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) * See the License for the specific language governing permissions and 14e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) * limitations under the License. 15e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) */ 16e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) 17e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)#ifndef NU_PLAYER_H_ 18e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) 19e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)#define NU_PLAYER_H_ 20e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) 21e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)#include <media/MediaPlayerInterface.h> 22e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)#include <media/stagefright/foundation/AHandler.h> 23e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)#include <media/stagefright/NativeWindowWrapper.h> 24e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) 25e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)namespace android { 26e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) 27e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)struct ABuffer; 28e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)struct MetaData; 29e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)struct NuPlayerDriver; 30e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) 3109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)struct NuPlayer : public AHandler { 32e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) NuPlayer(); 33e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) 34e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) void setUID(uid_t uid); 35e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) 36e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) void setDriver(const wp<NuPlayerDriver> &driver); 37e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) 38e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) void setDataSourceAsync(const sp<IStreamSource> &source); 399bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 40e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) void setDataSourceAsync( 4109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) const sp<IMediaHTTPService> &httpService, 42e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) const char *url, 43e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) const KeyedVector<String8, String8> *headers); 448abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 45e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) void setDataSourceAsync(int fd, int64_t offset, int64_t length); 469bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 47e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) void prepareAsync(); 48e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) 4909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) void setVideoSurfaceTextureAsync( 50e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) const sp<IGraphicBufferProducer> &bufferProducer); 51e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) 52e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) void setAudioSink(const sp<MediaPlayerBase::AudioSink> &sink); 53e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) void start(); 54e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) 55e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) 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 AWAITING_DISCONTINUITY, 147 FLUSHING_DECODER, 148 FLUSHING_DECODER_SHUTDOWN, 149 SHUTTING_DOWN_DECODER, 150 FLUSHED, 151 SHUT_DOWN, 152 }; 153 154 // Once the current flush is complete this indicates whether the 155 // notion of time has changed. 156 bool mTimeDiscontinuityPending; 157 158 FlushStatus mFlushingAudio; 159 FlushStatus mFlushingVideo; 160 161 int64_t mSkipRenderingAudioUntilMediaTimeUs; 162 int64_t mSkipRenderingVideoUntilMediaTimeUs; 163 164 int64_t mVideoLateByUs; 165 int64_t mNumFramesTotal, mNumFramesDropped; 166 167 int32_t mVideoScalingMode; 168 169 bool mStarted; 170 171 void openAudioSink(const sp<AMessage> &format, bool offloadOnly); 172 void closeAudioSink(); 173 174 status_t instantiateDecoder(bool audio, sp<Decoder> *decoder); 175 176 void updateVideoSize( 177 const sp<AMessage> &inputFormat, 178 const sp<AMessage> &outputFormat = NULL); 179 180 status_t feedDecoderInputData(bool audio, const sp<AMessage> &msg); 181 void renderBuffer(bool audio, const sp<AMessage> &msg); 182 183 void notifyListener(int msg, int ext1, int ext2, const Parcel *in = NULL); 184 185 void finishFlushIfPossible(); 186 187 void flushDecoder(bool audio, bool needShutdown); 188 189 static bool IsFlushingState(FlushStatus state, bool *needShutdown = NULL); 190 191 void postScanSources(); 192 193 void schedulePollDuration(); 194 void cancelPollDuration(); 195 196 void processDeferredActions(); 197 198 void performSeek(int64_t seekTimeUs); 199 void performDecoderFlush(); 200 void performDecoderShutdown(bool audio, bool video); 201 void performReset(); 202 void performScanSources(); 203 void performSetSurface(const sp<NativeWindowWrapper> &wrapper); 204 205 void onSourceNotify(const sp<AMessage> &msg); 206 void onClosedCaptionNotify(const sp<AMessage> &msg); 207 208 void queueDecoderShutdown( 209 bool audio, bool video, const sp<AMessage> &reply); 210 211 void sendSubtitleData(const sp<ABuffer> &buffer, int32_t baseIndex); 212 void sendTimedTextData(const sp<ABuffer> &buffer); 213 214 void writeTrackInfo(Parcel* reply, const sp<AMessage> format) const; 215 216 DISALLOW_EVIL_CONSTRUCTORS(NuPlayer); 217}; 218 219} // namespace android 220 221#endif // NU_PLAYER_H_ 222