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