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 25 namespace android { 26 27 struct ACodec; 28 struct MetaData; 29 struct NuPlayerDriver; 30 31 struct 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 char *url, const KeyedVector<String8, String8> *headers); 42 43 void setDataSourceAsync(int fd, int64_t offset, int64_t length); 44 45 void prepareAsync(); 46 47 void setVideoSurfaceTextureAsync( 48 const sp<IGraphicBufferProducer> &bufferProducer); 49 50 void setAudioSink(const sp<MediaPlayerBase::AudioSink> &sink); 51 void start(); 52 53 void pause(); 54 void resume(); 55 56 // Will notify the driver through "notifyResetComplete" once finished. 57 void resetAsync(); 58 59 // Will notify the driver through "notifySeekComplete" once finished. 60 void seekToAsync(int64_t seekTimeUs); 61 62 status_t setVideoScalingMode(int32_t mode); 63 status_t getTrackInfo(Parcel* reply) const; 64 status_t selectTrack(size_t trackIndex, bool select); 65 66 protected: 67 virtual ~NuPlayer(); 68 69 virtual void onMessageReceived(const sp<AMessage> &msg); 70 71 public: 72 struct NuPlayerStreamListener; 73 struct Source; 74 75 private: 76 struct Decoder; 77 struct GenericSource; 78 struct HTTPLiveSource; 79 struct Renderer; 80 struct RTSPSource; 81 struct StreamingSource; 82 struct Action; 83 struct SeekAction; 84 struct SetSurfaceAction; 85 struct ShutdownDecoderAction; 86 struct PostMessageAction; 87 struct SimpleAction; 88 89 enum { 90 kWhatSetDataSource = '=DaS', 91 kWhatPrepare = 'prep', 92 kWhatSetVideoNativeWindow = '=NaW', 93 kWhatSetAudioSink = '=AuS', 94 kWhatMoreDataQueued = 'more', 95 kWhatStart = 'strt', 96 kWhatScanSources = 'scan', 97 kWhatVideoNotify = 'vidN', 98 kWhatAudioNotify = 'audN', 99 kWhatRendererNotify = 'renN', 100 kWhatReset = 'rset', 101 kWhatSeek = 'seek', 102 kWhatPause = 'paus', 103 kWhatResume = 'rsme', 104 kWhatPollDuration = 'polD', 105 kWhatSourceNotify = 'srcN', 106 kWhatGetTrackInfo = 'gTrI', 107 kWhatSelectTrack = 'selT', 108 }; 109 110 wp<NuPlayerDriver> mDriver; 111 bool mUIDValid; 112 uid_t mUID; 113 sp<Source> mSource; 114 uint32_t mSourceFlags; 115 sp<NativeWindowWrapper> mNativeWindow; 116 sp<MediaPlayerBase::AudioSink> mAudioSink; 117 sp<Decoder> mVideoDecoder; 118 bool mVideoIsAVC; 119 sp<Decoder> mAudioDecoder; 120 sp<Renderer> mRenderer; 121 122 List<sp<Action> > mDeferredActions; 123 124 bool mAudioEOS; 125 bool mVideoEOS; 126 127 bool mScanSourcesPending; 128 int32_t mScanSourcesGeneration; 129 130 int32_t mPollDurationGeneration; 131 132 enum FlushStatus { 133 NONE, 134 AWAITING_DISCONTINUITY, 135 FLUSHING_DECODER, 136 FLUSHING_DECODER_SHUTDOWN, 137 SHUTTING_DOWN_DECODER, 138 FLUSHED, 139 SHUT_DOWN, 140 }; 141 142 // Once the current flush is complete this indicates whether the 143 // notion of time has changed. 144 bool mTimeDiscontinuityPending; 145 146 FlushStatus mFlushingAudio; 147 FlushStatus mFlushingVideo; 148 149 int64_t mSkipRenderingAudioUntilMediaTimeUs; 150 int64_t mSkipRenderingVideoUntilMediaTimeUs; 151 152 int64_t mVideoLateByUs; 153 int64_t mNumFramesTotal, mNumFramesDropped; 154 155 int32_t mVideoScalingMode; 156 157 bool mStarted; 158 159 status_t instantiateDecoder(bool audio, sp<Decoder> *decoder); 160 161 status_t feedDecoderInputData(bool audio, const sp<AMessage> &msg); 162 void renderBuffer(bool audio, const sp<AMessage> &msg); 163 164 void notifyListener(int msg, int ext1, int ext2, const Parcel *in = NULL); 165 166 void finishFlushIfPossible(); 167 168 void flushDecoder(bool audio, bool needShutdown); 169 170 static bool IsFlushingState(FlushStatus state, bool *needShutdown = NULL); 171 172 void postScanSources(); 173 174 void schedulePollDuration(); 175 void cancelPollDuration(); 176 177 void processDeferredActions(); 178 179 void performSeek(int64_t seekTimeUs); 180 void performDecoderFlush(); 181 void performDecoderShutdown(bool audio, bool video); 182 void performReset(); 183 void performScanSources(); 184 void performSetSurface(const sp<NativeWindowWrapper> &wrapper); 185 186 void onSourceNotify(const sp<AMessage> &msg); 187 188 void queueDecoderShutdown( 189 bool audio, bool video, const sp<AMessage> &reply); 190 191 DISALLOW_EVIL_CONSTRUCTORS(NuPlayer); 192 }; 193 194 } // namespace android 195 196 #endif // NU_PLAYER_H_ 197