NuPlayer.h revision 078cfcf7cce9185ec7559910d08b0bc02bfc88a3
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 27namespace android { 28 29struct ACodec; 30struct MetaData; 31struct NuPlayerDriver; 32 33struct 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 setVideoSurface(const sp<Surface> &surface); 46 void setVideoSurfaceTexture(const sp<ISurfaceTexture> &surfaceTexture); 47 void setAudioSink(const sp<MediaPlayerBase::AudioSink> &sink); 48 void start(); 49 50 void pause(); 51 void resume(); 52 53 // Will notify the driver through "notifyResetComplete" once finished. 54 void resetAsync(); 55 56 // Will notify the driver through "notifySeekComplete" once finished. 57 void seekToAsync(int64_t seekTimeUs); 58 59protected: 60 virtual ~NuPlayer(); 61 62 virtual void onMessageReceived(const sp<AMessage> &msg); 63 64private: 65 struct Decoder; 66 struct HTTPLiveSource; 67 struct NuPlayerStreamListener; 68 struct Renderer; 69 struct Source; 70 struct StreamingSource; 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 sp<Decoder> mAudioDecoder; 96 sp<Renderer> mRenderer; 97 98 bool mAudioEOS; 99 bool mVideoEOS; 100 101 bool mScanSourcesPending; 102 int32_t mScanSourcesGeneration; 103 104 enum FlushStatus { 105 NONE, 106 AWAITING_DISCONTINUITY, 107 FLUSHING_DECODER, 108 FLUSHING_DECODER_SHUTDOWN, 109 SHUTTING_DOWN_DECODER, 110 FLUSHED, 111 SHUT_DOWN, 112 }; 113 114 FlushStatus mFlushingAudio; 115 FlushStatus mFlushingVideo; 116 bool mResetInProgress; 117 bool mResetPostponed; 118 119 int64_t mSkipRenderingAudioUntilMediaTimeUs; 120 int64_t mSkipRenderingVideoUntilMediaTimeUs; 121 122 status_t instantiateDecoder(bool audio, sp<Decoder> *decoder); 123 124 status_t feedDecoderInputData(bool audio, const sp<AMessage> &msg); 125 void renderBuffer(bool audio, const sp<AMessage> &msg); 126 127 void notifyListener(int msg, int ext1, int ext2); 128 129 void finishFlushIfPossible(); 130 131 void flushDecoder(bool audio, bool needShutdown); 132 133 static bool IsFlushingState(FlushStatus state, bool *needShutdown = NULL); 134 135 void finishReset(); 136 void postScanSources(); 137 138 DISALLOW_EVIL_CONSTRUCTORS(NuPlayer); 139}; 140 141} // namespace android 142 143#endif // NU_PLAYER_H_ 144