NuPlayerRenderer.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 NUPLAYER_RENDERER_H_ 18 19#define NUPLAYER_RENDERER_H_ 20 21#include "NuPlayer.h" 22 23namespace android { 24 25struct ABuffer; 26 27struct NuPlayer::Renderer : public AHandler { 28 Renderer(const sp<MediaPlayerBase::AudioSink> &sink, 29 const sp<AMessage> ¬ify); 30 31 void queueBuffer( 32 bool audio, 33 const sp<ABuffer> &buffer, 34 const sp<AMessage> ¬ifyConsumed); 35 36 void queueEOS(bool audio, status_t finalResult); 37 38 void flush(bool audio); 39 40 void signalTimeDiscontinuity(); 41 42 void signalAudioSinkChanged(); 43 44 void pause(); 45 void resume(); 46 47 enum { 48 kWhatEOS, 49 kWhatFlushComplete, 50 kWhatPosition, 51 }; 52 53protected: 54 virtual ~Renderer(); 55 56 virtual void onMessageReceived(const sp<AMessage> &msg); 57 58private: 59 enum { 60 kWhatDrainAudioQueue, 61 kWhatDrainVideoQueue, 62 kWhatQueueBuffer, 63 kWhatQueueEOS, 64 kWhatFlush, 65 kWhatAudioSinkChanged, 66 kWhatPause, 67 kWhatResume, 68 }; 69 70 struct QueueEntry { 71 sp<ABuffer> mBuffer; 72 sp<AMessage> mNotifyConsumed; 73 size_t mOffset; 74 status_t mFinalResult; 75 }; 76 77 sp<MediaPlayerBase::AudioSink> mAudioSink; 78 sp<AMessage> mNotify; 79 List<QueueEntry> mAudioQueue; 80 List<QueueEntry> mVideoQueue; 81 uint32_t mNumFramesWritten; 82 83 bool mDrainAudioQueuePending; 84 bool mDrainVideoQueuePending; 85 int32_t mAudioQueueGeneration; 86 int32_t mVideoQueueGeneration; 87 88 int64_t mAnchorTimeMediaUs; 89 int64_t mAnchorTimeRealUs; 90 91 Mutex mFlushLock; // protects the following 2 member vars. 92 bool mFlushingAudio; 93 bool mFlushingVideo; 94 95 bool mHasAudio; 96 bool mHasVideo; 97 bool mSyncQueues; 98 99 bool mPaused; 100 101 void onDrainAudioQueue(); 102 void postDrainAudioQueue(); 103 104 void onDrainVideoQueue(); 105 void postDrainVideoQueue(); 106 107 void onQueueBuffer(const sp<AMessage> &msg); 108 void onQueueEOS(const sp<AMessage> &msg); 109 void onFlush(const sp<AMessage> &msg); 110 void onAudioSinkChanged(); 111 void onPause(); 112 void onResume(); 113 114 void notifyEOS(bool audio); 115 void notifyFlushComplete(bool audio); 116 void notifyPosition(); 117 118 void flushQueue(List<QueueEntry> *queue); 119 bool dropBufferWhileFlushing(bool audio, const sp<AMessage> &msg); 120 void syncQueuesDone(); 121 122 DISALLOW_EVIL_CONSTRUCTORS(Renderer); 123}; 124 125} // namespace android 126 127#endif // NUPLAYER_RENDERER_H_ 128