blob: dbf3ecff1996e8d753c82b77b04594459698f55e [file] [log] [blame]
Andreas Huberf9334412010-12-15 15:17:42 -08001/*
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
Andreas Huber5bc087c2010-12-23 10:27:40 -080025struct ABuffer;
26
Andreas Huberf9334412010-12-15 15:17:42 -080027struct NuPlayer::Renderer : public AHandler {
28 Renderer(const sp<MediaPlayerBase::AudioSink> &sink,
29 const sp<AMessage> &notify);
30
31 void queueBuffer(
32 bool audio,
33 const sp<ABuffer> &buffer,
34 const sp<AMessage> &notifyConsumed);
35
36 void queueEOS(bool audio, status_t finalResult);
37
38 void flush(bool audio);
39
40 void signalTimeDiscontinuity();
41
Andreas Huber3831a062010-12-21 10:22:33 -080042 void signalAudioSinkChanged();
43
Andreas Huberf9334412010-12-15 15:17:42 -080044 enum {
45 kWhatEOS,
46 kWhatFlushComplete,
Andreas Huber43c3e6c2011-01-05 12:17:08 -080047 kWhatPosition,
Andreas Huberf9334412010-12-15 15:17:42 -080048 };
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,
Andreas Huber3831a062010-12-21 10:22:33 -080062 kWhatAudioSinkChanged,
Andreas Huberf9334412010-12-15 15:17:42 -080063 };
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
Andreas Huber3831a062010-12-21 10:22:33 -080090 bool mHasAudio;
91 bool mHasVideo;
Andreas Huberf9334412010-12-15 15:17:42 -080092 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);
Andreas Huber3831a062010-12-21 10:22:33 -0800103 void onAudioSinkChanged();
Andreas Huberf9334412010-12-15 15:17:42 -0800104
105 void notifyEOS(bool audio);
106 void notifyFlushComplete(bool audio);
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800107 void notifyPosition();
Andreas Huberf9334412010-12-15 15:17:42 -0800108
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_