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 #include <gui/SurfaceTextureClient.h> 25 #include <surfaceflinger/Surface.h> 26 27 namespace android { 28 29 struct ACodec; 30 struct MetaData; 31 struct NuPlayerDriver; 32 33 struct NuPlayer : public AHandler { 34 NuPlayer(); 35 36 void setUID(uid_t uid); 37 38 void setDriver(const wp<NuPlayerDriver> &driver); 39 40 void setDataSource(const sp<IStreamSource> &source); 41 42 void setDataSource( 43 const char *url, const KeyedVector<String8, String8> *headers); 44 45 void setVideoSurfaceTexture(const sp<ISurfaceTexture> &surfaceTexture); 46 void setAudioSink(const sp<MediaPlayerBase::AudioSink> &sink); 47 void start(); 48 49 void pause(); 50 void resume(); 51 52 // Will notify the driver through "notifyResetComplete" once finished. 53 void resetAsync(); 54 55 // Will notify the driver through "notifySeekComplete" once finished. 56 void seekToAsync(int64_t seekTimeUs); 57 58 protected: 59 virtual ~NuPlayer(); 60 61 virtual void onMessageReceived(const sp<AMessage> &msg); 62 63 private: 64 struct Decoder; 65 struct HTTPLiveSource; 66 struct NuPlayerStreamListener; 67 struct Renderer; 68 struct Source; 69 struct StreamingSource; 70 struct RTSPSource; 71 72 enum { 73 kWhatSetDataSource = '=DaS', 74 kWhatSetVideoNativeWindow = '=NaW', 75 kWhatSetAudioSink = '=AuS', 76 kWhatMoreDataQueued = 'more', 77 kWhatStart = 'strt', 78 kWhatScanSources = 'scan', 79 kWhatVideoNotify = 'vidN', 80 kWhatAudioNotify = 'audN', 81 kWhatRendererNotify = 'renN', 82 kWhatReset = 'rset', 83 kWhatSeek = 'seek', 84 kWhatPause = 'paus', 85 kWhatResume = 'rsme', 86 }; 87 88 wp<NuPlayerDriver> mDriver; 89 bool mUIDValid; 90 uid_t mUID; 91 sp<Source> mSource; 92 sp<NativeWindowWrapper> mNativeWindow; 93 sp<MediaPlayerBase::AudioSink> mAudioSink; 94 sp<Decoder> mVideoDecoder; 95 bool mVideoIsAVC; 96 sp<Decoder> mAudioDecoder; 97 sp<Renderer> mRenderer; 98 99 bool mAudioEOS; 100 bool mVideoEOS; 101 102 bool mScanSourcesPending; 103 int32_t mScanSourcesGeneration; 104 105 enum FlushStatus { 106 NONE, 107 AWAITING_DISCONTINUITY, 108 FLUSHING_DECODER, 109 FLUSHING_DECODER_SHUTDOWN, 110 SHUTTING_DOWN_DECODER, 111 FLUSHED, 112 SHUT_DOWN, 113 }; 114 115 // Once the current flush is complete this indicates whether the 116 // notion of time has changed. 117 bool mTimeDiscontinuityPending; 118 119 FlushStatus mFlushingAudio; 120 FlushStatus mFlushingVideo; 121 bool mResetInProgress; 122 bool mResetPostponed; 123 124 int64_t mSkipRenderingAudioUntilMediaTimeUs; 125 int64_t mSkipRenderingVideoUntilMediaTimeUs; 126 127 int64_t mVideoLateByUs; 128 int64_t mNumFramesTotal, mNumFramesDropped; 129 130 status_t instantiateDecoder(bool audio, sp<Decoder> *decoder); 131 132 status_t feedDecoderInputData(bool audio, const sp<AMessage> &msg); 133 void renderBuffer(bool audio, const sp<AMessage> &msg); 134 135 void notifyListener(int msg, int ext1, int ext2); 136 137 void finishFlushIfPossible(); 138 139 void flushDecoder(bool audio, bool needShutdown); 140 141 static bool IsFlushingState(FlushStatus state, bool *needShutdown = NULL); 142 143 void finishReset(); 144 void postScanSources(); 145 146 DISALLOW_EVIL_CONSTRUCTORS(NuPlayer); 147 }; 148 149 } // namespace android 150 151 #endif // NU_PLAYER_H_ 152