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