NuPlayerRenderer.h revision 43c3e6ce02215ca99d506458f596cb1211639f29
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 enum { 45 kWhatEOS, 46 kWhatFlushComplete, 47 kWhatPosition, 48 }; 49 50protected: 51 virtual ~Renderer(); 52 53 virtual void onMessageReceived(const sp<AMessage> &msg); 54 55private: 56 enum { 57 kWhatDrainAudioQueue, 58 kWhatDrainVideoQueue, 59 kWhatQueueBuffer, 60 kWhatQueueEOS, 61 kWhatFlush, 62 kWhatAudioSinkChanged, 63 }; 64 65 struct QueueEntry { 66 sp<ABuffer> mBuffer; 67 sp<AMessage> mNotifyConsumed; 68 size_t mOffset; 69 status_t mFinalResult; 70 }; 71 72 sp<MediaPlayerBase::AudioSink> mAudioSink; 73 sp<AMessage> mNotify; 74 List<QueueEntry> mAudioQueue; 75 List<QueueEntry> mVideoQueue; 76 uint32_t mNumFramesWritten; 77 78 bool mDrainAudioQueuePending; 79 bool mDrainVideoQueuePending; 80 int32_t mAudioQueueGeneration; 81 int32_t mVideoQueueGeneration; 82 83 int64_t mAnchorTimeMediaUs; 84 int64_t mAnchorTimeRealUs; 85 86 Mutex mFlushLock; // protects the following 2 member vars. 87 bool mFlushingAudio; 88 bool mFlushingVideo; 89 90 bool mHasAudio; 91 bool mHasVideo; 92 bool mSyncQueues; 93 94 void onDrainAudioQueue(); 95 void postDrainAudioQueue(); 96 97 void onDrainVideoQueue(); 98 void postDrainVideoQueue(); 99 100 void onQueueBuffer(const sp<AMessage> &msg); 101 void onQueueEOS(const sp<AMessage> &msg); 102 void onFlush(const sp<AMessage> &msg); 103 void onAudioSinkChanged(); 104 105 void notifyEOS(bool audio); 106 void notifyFlushComplete(bool audio); 107 void notifyPosition(); 108 109 void flushQueue(List<QueueEntry> *queue); 110 bool dropBufferWhileFlushing(bool audio, const sp<AMessage> &msg); 111 void syncQueuesDone(); 112 113 DISALLOW_EVIL_CONSTRUCTORS(Renderer); 114}; 115 116} // namespace android 117 118#endif // NUPLAYER_RENDERER_H_ 119