NuPlayer.h revision 1173118eace0e9e347cb007f0da817cee87579ed
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 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 setVideoSurface(const sp<Surface> &surface); 44 void setVideoSurfaceTexture(const sp<ISurfaceTexture> &surfaceTexture); 45 void setAudioSink(const sp<MediaPlayerBase::AudioSink> &sink); 46 void start(); 47 48 void pause(); 49 void resume(); 50 51 // Will notify the driver through "notifyResetComplete" once finished. 52 void resetAsync(); 53 54 // Will notify the driver through "notifySeekComplete" once finished. 55 void seekToAsync(int64_t seekTimeUs); 56 57protected: 58 virtual ~NuPlayer(); 59 60 virtual void onMessageReceived(const sp<AMessage> &msg); 61 62private: 63 struct Decoder; 64 struct HTTPLiveSource; 65 struct NuPlayerStreamListener; 66 struct Renderer; 67 struct Source; 68 struct StreamingSource; 69 70 enum { 71 kWhatSetDataSource, 72 kWhatSetVideoNativeWindow, 73 kWhatSetAudioSink, 74 kWhatMoreDataQueued, 75 kWhatStart, 76 kWhatScanSources, 77 kWhatVideoNotify, 78 kWhatAudioNotify, 79 kWhatRendererNotify, 80 kWhatReset, 81 kWhatSeek, 82 kWhatPause, 83 kWhatResume, 84 }; 85 86 wp<NuPlayerDriver> mDriver; 87 sp<Source> mSource; 88 sp<NativeWindowWrapper> mNativeWindow; 89 sp<MediaPlayerBase::AudioSink> mAudioSink; 90 sp<Decoder> mVideoDecoder; 91 sp<Decoder> mAudioDecoder; 92 sp<Renderer> mRenderer; 93 94 bool mAudioEOS; 95 bool mVideoEOS; 96 97 bool mScanSourcesPending; 98 int32_t mScanSourcesGeneration; 99 100 enum FlushStatus { 101 NONE, 102 AWAITING_DISCONTINUITY, 103 FLUSHING_DECODER, 104 FLUSHING_DECODER_SHUTDOWN, 105 SHUTTING_DOWN_DECODER, 106 FLUSHED, 107 SHUT_DOWN, 108 }; 109 110 FlushStatus mFlushingAudio; 111 FlushStatus mFlushingVideo; 112 bool mResetInProgress; 113 bool mResetPostponed; 114 115 status_t instantiateDecoder(bool audio, sp<Decoder> *decoder); 116 117 status_t feedDecoderInputData(bool audio, const sp<AMessage> &msg); 118 void renderBuffer(bool audio, const sp<AMessage> &msg); 119 120 void notifyListener(int msg, int ext1, int ext2); 121 122 void finishFlushIfPossible(); 123 124 void flushDecoder(bool audio, bool needShutdown); 125 126 static bool IsFlushingState(FlushStatus state, bool *needShutdown = NULL); 127 128 void finishReset(); 129 void postScanSources(); 130 131 DISALLOW_EVIL_CONSTRUCTORS(NuPlayer); 132}; 133 134} // namespace android 135 136#endif // NU_PLAYER_H_ 137