NuPlayer.h revision 1aef211b4e5dc952081727bfd2318b2cb5ca4506
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 24namespace android { 25 26struct ACodec; 27struct MetaData; 28 29struct NuPlayer : public AHandler { 30 NuPlayer(); 31 32 void setListener(const wp<MediaPlayerBase> &listener); 33 34 void setDataSource(const sp<IStreamSource> &source); 35 36 void setDataSource( 37 const char *url, const KeyedVector<String8, String8> *headers); 38 39 void setVideoSurface(const sp<Surface> &surface); 40 void setAudioSink(const sp<MediaPlayerBase::AudioSink> &sink); 41 void start(); 42 43 // Will notify the listener that reset() has completed 44 // with code MEDIA_RESET_COMPLETE. 45 void resetAsync(); 46 47protected: 48 virtual ~NuPlayer(); 49 50 virtual void onMessageReceived(const sp<AMessage> &msg); 51 52private: 53 struct Decoder; 54 struct HTTPLiveSource; 55 struct NuPlayerStreamListener; 56 struct Renderer; 57 struct Source; 58 struct StreamingSource; 59 60 enum { 61 kWhatSetDataSource, 62 kWhatSetVideoSurface, 63 kWhatSetAudioSink, 64 kWhatMoreDataQueued, 65 kWhatStart, 66 kWhatScanSources, 67 kWhatVideoNotify, 68 kWhatAudioNotify, 69 kWhatRendererNotify, 70 kWhatReset, 71 }; 72 73 wp<MediaPlayerBase> mListener; 74 sp<Source> mSource; 75 sp<Surface> mSurface; 76 sp<MediaPlayerBase::AudioSink> mAudioSink; 77 sp<Decoder> mVideoDecoder; 78 sp<Decoder> mAudioDecoder; 79 sp<Renderer> mRenderer; 80 81 bool mAudioEOS; 82 bool mVideoEOS; 83 84 bool mScanSourcesPending; 85 int32_t mScanSourcesGeneration; 86 87 enum FlushStatus { 88 NONE, 89 AWAITING_DISCONTINUITY, 90 FLUSHING_DECODER, 91 FLUSHING_DECODER_SHUTDOWN, 92 SHUTTING_DOWN_DECODER, 93 FLUSHED, 94 SHUT_DOWN, 95 }; 96 97 FlushStatus mFlushingAudio; 98 FlushStatus mFlushingVideo; 99 bool mResetInProgress; 100 bool mResetPostponed; 101 102 status_t instantiateDecoder(bool audio, sp<Decoder> *decoder); 103 104 status_t feedDecoderInputData(bool audio, const sp<AMessage> &msg); 105 void renderBuffer(bool audio, const sp<AMessage> &msg); 106 107 void notifyListener(int msg, int ext1, int ext2); 108 109 void finishFlushIfPossible(); 110 111 void flushDecoder(bool audio, bool needShutdown); 112 113 static bool IsFlushingState(FlushStatus state, bool *needShutdown = NULL); 114 115 void finishReset(); 116 void postScanSources(); 117 118 DISALLOW_EVIL_CONSTRUCTORS(NuPlayer); 119}; 120 121} // namespace android 122 123#endif // NU_PLAYER_H_ 124