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