blob: 2713031f4b70a2b9517ace09b30edbbcdf02b38e [file] [log] [blame]
Andreas Hubera1587462010-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 Huber54e66492010-12-23 10:27:40 -080025struct ABuffer;
26
Andreas Hubera1587462010-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 Huber41c3f742010-12-21 10:22:33 -080042 void signalAudioSinkChanged();
43
Andreas Huber601fe0e2011-01-20 15:23:04 -080044 void pause();
45 void resume();
46
Andreas Hubera1587462010-12-15 15:17:42 -080047 enum {
48 kWhatEOS,
49 kWhatFlushComplete,
Andreas Huber08e10cb2011-01-05 12:17:08 -080050 kWhatPosition,
Andreas Hubera1587462010-12-15 15:17:42 -080051 };
52
53protected:
54 virtual ~Renderer();
55
56 virtual void onMessageReceived(const sp<AMessage> &msg);
57
58private:
59 enum {
60 kWhatDrainAudioQueue,
61 kWhatDrainVideoQueue,
62 kWhatQueueBuffer,
63 kWhatQueueEOS,
64 kWhatFlush,
Andreas Huber41c3f742010-12-21 10:22:33 -080065 kWhatAudioSinkChanged,
Andreas Huber601fe0e2011-01-20 15:23:04 -080066 kWhatPause,
67 kWhatResume,
Andreas Hubera1587462010-12-15 15:17:42 -080068 };
69
70 struct QueueEntry {
71 sp<ABuffer> mBuffer;
72 sp<AMessage> mNotifyConsumed;
73 size_t mOffset;
74 status_t mFinalResult;
75 };
76
77 sp<MediaPlayerBase::AudioSink> mAudioSink;
78 sp<AMessage> mNotify;
79 List<QueueEntry> mAudioQueue;
80 List<QueueEntry> mVideoQueue;
81 uint32_t mNumFramesWritten;
82
83 bool mDrainAudioQueuePending;
84 bool mDrainVideoQueuePending;
85 int32_t mAudioQueueGeneration;
86 int32_t mVideoQueueGeneration;
87
88 int64_t mAnchorTimeMediaUs;
89 int64_t mAnchorTimeRealUs;
90
91 Mutex mFlushLock; // protects the following 2 member vars.
92 bool mFlushingAudio;
93 bool mFlushingVideo;
94
Andreas Huber41c3f742010-12-21 10:22:33 -080095 bool mHasAudio;
96 bool mHasVideo;
Andreas Hubera1587462010-12-15 15:17:42 -080097 bool mSyncQueues;
98
Andreas Huber601fe0e2011-01-20 15:23:04 -080099 bool mPaused;
100
Andreas Hubera1587462010-12-15 15:17:42 -0800101 void onDrainAudioQueue();
102 void postDrainAudioQueue();
103
104 void onDrainVideoQueue();
105 void postDrainVideoQueue();
106
107 void onQueueBuffer(const sp<AMessage> &msg);
108 void onQueueEOS(const sp<AMessage> &msg);
109 void onFlush(const sp<AMessage> &msg);
Andreas Huber41c3f742010-12-21 10:22:33 -0800110 void onAudioSinkChanged();
Andreas Huber601fe0e2011-01-20 15:23:04 -0800111 void onPause();
112 void onResume();
Andreas Hubera1587462010-12-15 15:17:42 -0800113
Andreas Huberd84fd792011-08-16 13:48:44 -0700114 void notifyEOS(bool audio, status_t finalResult);
Andreas Hubera1587462010-12-15 15:17:42 -0800115 void notifyFlushComplete(bool audio);
Andreas Huber08e10cb2011-01-05 12:17:08 -0800116 void notifyPosition();
Andreas Hubera1587462010-12-15 15:17:42 -0800117
118 void flushQueue(List<QueueEntry> *queue);
119 bool dropBufferWhileFlushing(bool audio, const sp<AMessage> &msg);
120 void syncQueuesDone();
121
122 DISALLOW_EVIL_CONSTRUCTORS(Renderer);
123};
124
125} // namespace android
126
127#endif // NUPLAYER_RENDERER_H_