blob: da735b51ec695137bc829081d01dc82cc20b8c46 [file] [log] [blame]
Ajit Khare73cfaf42013-01-07 23:28:47 -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 DASHPLAYER_RENDERER_H_
18
19#define DASHPLAYER_RENDERER_H_
20
21#include "DashPlayer.h"
22
23namespace android {
24
25struct ABuffer;
26
27struct DashPlayer::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#ifdef QCOM_WFD_SINK
36 virtual void queueEOS(bool audio, status_t finalResult);
37
38 virtual void flush(bool audio);
39
40 virtual void signalTimeDiscontinuity();
41
42 virtual void signalAudioSinkChanged();
43
44 virtual void pause();
45 virtual void resume();
46#else
47
48 void queueEOS(bool audio, status_t finalResult);
49
50 void flush(bool audio);
51
52 void signalTimeDiscontinuity();
53
54 void signalAudioSinkChanged();
55
56 void pause();
57 void resume();
Surajit Podderc72631d2013-08-20 14:26:43 +053058 void notifySeekPosition(int64_t seekTime);
Ajit Khare73cfaf42013-01-07 23:28:47 -080059#endif /* QCOM_WFD_SINK */
60 enum {
61 kWhatEOS = 'eos ',
62 kWhatFlushComplete = 'fluC',
63 kWhatPosition = 'posi',
64 };
65
66protected:
67 virtual ~Renderer();
68
69 virtual void onMessageReceived(const sp<AMessage> &msg);
70
71private:
72 enum {
73 kWhatDrainAudioQueue = 'draA',
74 kWhatDrainVideoQueue = 'draV',
75 kWhatQueueBuffer = 'queB',
76 kWhatQueueEOS = 'qEOS',
77 kWhatFlush = 'flus',
78 kWhatAudioSinkChanged = 'auSC',
79 kWhatPause = 'paus',
80 kWhatResume = 'resm',
81 };
82
83 struct QueueEntry {
84 sp<ABuffer> mBuffer;
85 sp<AMessage> mNotifyConsumed;
86 size_t mOffset;
87 status_t mFinalResult;
88 };
89
90 static const int64_t kMinPositionUpdateDelayUs;
91
92 sp<MediaPlayerBase::AudioSink> mAudioSink;
93 sp<AMessage> mNotify;
94 List<QueueEntry> mAudioQueue;
95 List<QueueEntry> mVideoQueue;
96 uint32_t mNumFramesWritten;
97
98 bool mDrainAudioQueuePending;
99 bool mDrainVideoQueuePending;
100 int32_t mAudioQueueGeneration;
101 int32_t mVideoQueueGeneration;
102
103 int64_t mAnchorTimeMediaUs;
104 int64_t mAnchorTimeRealUs;
Surajit Podderc72631d2013-08-20 14:26:43 +0530105 int64_t mSeekTimeUs;
Ajit Khare73cfaf42013-01-07 23:28:47 -0800106
107 Mutex mFlushLock; // protects the following 2 member vars.
108 bool mFlushingAudio;
109 bool mFlushingVideo;
110
111 bool mHasAudio;
112 bool mHasVideo;
113 bool mSyncQueues;
114
115 bool mPaused;
116 bool mWasPaused; // if paused then store the info
117
118 int64_t mLastPositionUpdateUs;
119 int64_t mVideoLateByUs;
Surajit Poddere6471132013-08-20 17:01:03 +0530120 int64_t mAVSyncDelayWindowUs;
Ajit Khare73cfaf42013-01-07 23:28:47 -0800121
122 bool onDrainAudioQueue();
123 void postDrainAudioQueue(int64_t delayUs = 0);
124
125 void onDrainVideoQueue();
126 void postDrainVideoQueue();
127#ifdef QCOM_WFD_SINK
128 virtual void onQueueBuffer(const sp<AMessage> &msg);
129#else
130 void onQueueBuffer(const sp<AMessage> &msg);
131#endif /* QCOM_WFD_SINK */
132 void onQueueEOS(const sp<AMessage> &msg);
133 void onFlush(const sp<AMessage> &msg);
134 void onAudioSinkChanged();
135 void onPause();
136 void onResume();
137
138 void notifyEOS(bool audio, status_t finalResult);
139 void notifyFlushComplete(bool audio);
Surajit Podder1b763112013-05-22 14:16:51 +0530140 void notifyPosition(bool isEOS = false);
Ajit Khare73cfaf42013-01-07 23:28:47 -0800141 void notifyVideoLateBy(int64_t lateByUs);
142
143 void flushQueue(List<QueueEntry> *queue);
144 bool dropBufferWhileFlushing(bool audio, const sp<AMessage> &msg);
145 void syncQueuesDone();
146
147 // for qualcomm statistics profiling
148 public:
149#ifdef QCOM_WFD_SINK
150 virtual void registerStats(sp<DashPlayerStats> stats);
151 virtual status_t setMediaPresence(bool audio, bool bValue);
152#else
153 void registerStats(sp<DashPlayerStats> stats);
154 status_t setMediaPresence(bool audio, bool bValue);
155#endif /* QCOM_WFD_SINK */
156 private:
157 sp<DashPlayerStats> mStats;
158
159 DISALLOW_EVIL_CONSTRUCTORS(Renderer);
160};
161
162} // namespace android
163
164#endif // DASHPLAYER_RENDERER_H_