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