blob: eaa004ab4d61e8f73932cf495cd918bbcb766957 [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
25struct NuPlayer::Renderer : public AHandler {
26 Renderer(const sp<MediaPlayerBase::AudioSink> &sink,
27 const sp<AMessage> &notify);
28
29 void queueBuffer(
30 bool audio,
31 const sp<ABuffer> &buffer,
32 const sp<AMessage> &notifyConsumed);
33
34 void queueEOS(bool audio, status_t finalResult);
35
36 void flush(bool audio);
37
38 void signalTimeDiscontinuity();
39
Andreas Huber3831a062010-12-21 10:22:33 -080040 void signalAudioSinkChanged();
41
Andreas Huberf9334412010-12-15 15:17:42 -080042 enum {
43 kWhatEOS,
44 kWhatFlushComplete,
45 };
46
47protected:
48 virtual ~Renderer();
49
50 virtual void onMessageReceived(const sp<AMessage> &msg);
51
52private:
53 enum {
54 kWhatDrainAudioQueue,
55 kWhatDrainVideoQueue,
56 kWhatQueueBuffer,
57 kWhatQueueEOS,
58 kWhatFlush,
Andreas Huber3831a062010-12-21 10:22:33 -080059 kWhatAudioSinkChanged,
Andreas Huberf9334412010-12-15 15:17:42 -080060 };
61
62 struct QueueEntry {
63 sp<ABuffer> mBuffer;
64 sp<AMessage> mNotifyConsumed;
65 size_t mOffset;
66 status_t mFinalResult;
67 };
68
69 sp<MediaPlayerBase::AudioSink> mAudioSink;
70 sp<AMessage> mNotify;
71 List<QueueEntry> mAudioQueue;
72 List<QueueEntry> mVideoQueue;
73 uint32_t mNumFramesWritten;
74
75 bool mDrainAudioQueuePending;
76 bool mDrainVideoQueuePending;
77 int32_t mAudioQueueGeneration;
78 int32_t mVideoQueueGeneration;
79
80 int64_t mAnchorTimeMediaUs;
81 int64_t mAnchorTimeRealUs;
82
83 Mutex mFlushLock; // protects the following 2 member vars.
84 bool mFlushingAudio;
85 bool mFlushingVideo;
86
Andreas Huber3831a062010-12-21 10:22:33 -080087 bool mHasAudio;
88 bool mHasVideo;
Andreas Huberf9334412010-12-15 15:17:42 -080089 bool mSyncQueues;
90
91 void onDrainAudioQueue();
92 void postDrainAudioQueue();
93
94 void onDrainVideoQueue();
95 void postDrainVideoQueue();
96
97 void onQueueBuffer(const sp<AMessage> &msg);
98 void onQueueEOS(const sp<AMessage> &msg);
99 void onFlush(const sp<AMessage> &msg);
Andreas Huber3831a062010-12-21 10:22:33 -0800100 void onAudioSinkChanged();
Andreas Huberf9334412010-12-15 15:17:42 -0800101
102 void notifyEOS(bool audio);
103 void notifyFlushComplete(bool audio);
104
105 void flushQueue(List<QueueEntry> *queue);
106 bool dropBufferWhileFlushing(bool audio, const sp<AMessage> &msg);
107 void syncQueuesDone();
108
109 DISALLOW_EVIL_CONSTRUCTORS(Renderer);
110};
111
112} // namespace android
113
114#endif // NUPLAYER_RENDERER_H_