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 setDataSource(const sp<IStreamSource> &source); 39 40 void setDataSource( 41 const char *url, const KeyedVector<String8, String8> *headers); 42 43 void setDataSource(int fd, int64_t offset, int64_t length); 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 status_t setVideoScalingMode(int32_t mode); 59 60 protected: 61 virtual ~NuPlayer(); 62 63 virtual void onMessageReceived(const sp<AMessage> &msg); 64 65 public: 66 struct NuPlayerStreamListener; 67 struct Source; 68 69 private: 70 struct Decoder; 71 struct GenericSource; 72 struct HTTPLiveSource; 73 struct Renderer; 74 struct RTSPSource; 75 struct StreamingSource; 76 77 enum { 78 kWhatSetDataSource = '=DaS', 79 kWhatSetVideoNativeWindow = '=NaW', 80 kWhatSetAudioSink = '=AuS', 81 kWhatMoreDataQueued = 'more', 82 kWhatStart = 'strt', 83 kWhatScanSources = 'scan', 84 kWhatVideoNotify = 'vidN', 85 kWhatAudioNotify = 'audN', 86 kWhatRendererNotify = 'renN', 87 kWhatReset = 'rset', 88 kWhatSeek = 'seek', 89 kWhatPause = 'paus', 90 kWhatResume = 'rsme', 91 }; 92 93 wp<NuPlayerDriver> mDriver; 94 bool mUIDValid; 95 uid_t mUID; 96 sp<Source> mSource; 97 sp<NativeWindowWrapper> mNativeWindow; 98 sp<MediaPlayerBase::AudioSink> mAudioSink; 99 sp<Decoder> mVideoDecoder; 100 bool mVideoIsAVC; 101 sp<Decoder> mAudioDecoder; 102 sp<Renderer> mRenderer; 103 104 bool mAudioEOS; 105 bool mVideoEOS; 106 107 bool mScanSourcesPending; 108 int32_t mScanSourcesGeneration; 109 110 enum FlushStatus { 111 NONE, 112 AWAITING_DISCONTINUITY, 113 FLUSHING_DECODER, 114 FLUSHING_DECODER_SHUTDOWN, 115 SHUTTING_DOWN_DECODER, 116 FLUSHED, 117 SHUT_DOWN, 118 }; 119 120 // Once the current flush is complete this indicates whether the 121 // notion of time has changed. 122 bool mTimeDiscontinuityPending; 123 124 FlushStatus mFlushingAudio; 125 FlushStatus mFlushingVideo; 126 bool mResetInProgress; 127 bool mResetPostponed; 128 129 int64_t mSkipRenderingAudioUntilMediaTimeUs; 130 int64_t mSkipRenderingVideoUntilMediaTimeUs; 131 132 int64_t mVideoLateByUs; 133 int64_t mNumFramesTotal, mNumFramesDropped; 134 135 int32_t mVideoScalingMode; 136 137 status_t instantiateDecoder(bool audio, sp<Decoder> *decoder); 138 139 status_t feedDecoderInputData(bool audio, const sp<AMessage> &msg); 140 void renderBuffer(bool audio, const sp<AMessage> &msg); 141 142 void notifyListener(int msg, int ext1, int ext2); 143 144 void finishFlushIfPossible(); 145 146 void flushDecoder(bool audio, bool needShutdown); 147 148 static bool IsFlushingState(FlushStatus state, bool *needShutdown = NULL); 149 150 void finishReset(); 151 void postScanSources(); 152 153 DISALLOW_EVIL_CONSTRUCTORS(NuPlayer); 154 }; 155 156 } // namespace android 157 158 #endif // NU_PLAYER_H_ 159