blob: fb3903c64a8e4572f574d2678dfb7696a33e47e1 [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,
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,
Andreas Huber3831a062010-12-21 10:22:33 -080061 kWhatAudioSinkChanged,
Andreas Huberf9334412010-12-15 15:17:42 -080062 };
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
Andreas Huber3831a062010-12-21 10:22:33 -080089 bool mHasAudio;
90 bool mHasVideo;
Andreas Huberf9334412010-12-15 15:17:42 -080091 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);
Andreas Huber3831a062010-12-21 10:22:33 -0800102 void onAudioSinkChanged();
Andreas Huberf9334412010-12-15 15:17:42 -0800103
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_