blob: 3711eb4c0362445fe5652b5da69a076c43bc432f [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//#define LOG_NDEBUG 0
18#define LOG_TAG "NuPlayerRenderer"
19#include <utils/Log.h>
20
21#include "NuPlayerRenderer.h"
22
23#include <media/stagefright/foundation/ABuffer.h>
24#include <media/stagefright/foundation/ADebug.h>
Andreas Huber54e66492010-12-23 10:27:40 -080025#include <media/stagefright/foundation/AMessage.h>
Andreas Hubera1587462010-12-15 15:17:42 -080026
27namespace android {
28
Andreas Huberfa6dfdc2011-09-13 08:28:38 -070029// static
30const int64_t NuPlayer::Renderer::kMinPositionUpdateDelayUs = 100000ll;
31
Andreas Hubera1587462010-12-15 15:17:42 -080032NuPlayer::Renderer::Renderer(
33 const sp<MediaPlayerBase::AudioSink> &sink,
34 const sp<AMessage> &notify)
35 : mAudioSink(sink),
36 mNotify(notify),
37 mNumFramesWritten(0),
38 mDrainAudioQueuePending(false),
39 mDrainVideoQueuePending(false),
40 mAudioQueueGeneration(0),
41 mVideoQueueGeneration(0),
42 mAnchorTimeMediaUs(-1),
43 mAnchorTimeRealUs(-1),
44 mFlushingAudio(false),
45 mFlushingVideo(false),
Andreas Huber19922ad2011-01-21 10:15:23 -080046 mHasAudio(false),
47 mHasVideo(false),
48 mSyncQueues(false),
Andreas Huberfa6dfdc2011-09-13 08:28:38 -070049 mPaused(false),
Andreas Huber950fc9d2011-09-16 15:09:22 -070050 mLastPositionUpdateUs(-1ll),
51 mVideoLateByUs(0ll) {
Andreas Hubera1587462010-12-15 15:17:42 -080052}
53
54NuPlayer::Renderer::~Renderer() {
55}
56
57void NuPlayer::Renderer::queueBuffer(
58 bool audio,
59 const sp<ABuffer> &buffer,
60 const sp<AMessage> &notifyConsumed) {
61 sp<AMessage> msg = new AMessage(kWhatQueueBuffer, id());
62 msg->setInt32("audio", static_cast<int32_t>(audio));
63 msg->setObject("buffer", buffer);
64 msg->setMessage("notifyConsumed", notifyConsumed);
65 msg->post();
66}
67
68void NuPlayer::Renderer::queueEOS(bool audio, status_t finalResult) {
69 CHECK_NE(finalResult, (status_t)OK);
70
71 sp<AMessage> msg = new AMessage(kWhatQueueEOS, id());
72 msg->setInt32("audio", static_cast<int32_t>(audio));
73 msg->setInt32("finalResult", finalResult);
74 msg->post();
75}
76
77void NuPlayer::Renderer::flush(bool audio) {
78 {
79 Mutex::Autolock autoLock(mFlushLock);
80 if (audio) {
81 CHECK(!mFlushingAudio);
82 mFlushingAudio = true;
83 } else {
84 CHECK(!mFlushingVideo);
85 mFlushingVideo = true;
86 }
87 }
88
89 sp<AMessage> msg = new AMessage(kWhatFlush, id());
90 msg->setInt32("audio", static_cast<int32_t>(audio));
91 msg->post();
92}
93
94void NuPlayer::Renderer::signalTimeDiscontinuity() {
95 CHECK(mAudioQueue.empty());
96 CHECK(mVideoQueue.empty());
97 mAnchorTimeMediaUs = -1;
98 mAnchorTimeRealUs = -1;
Andreas Huber41c3f742010-12-21 10:22:33 -080099 mSyncQueues = mHasAudio && mHasVideo;
Andreas Hubera1587462010-12-15 15:17:42 -0800100}
101
Andreas Huber601fe0e2011-01-20 15:23:04 -0800102void NuPlayer::Renderer::pause() {
103 (new AMessage(kWhatPause, id()))->post();
104}
105
106void NuPlayer::Renderer::resume() {
107 (new AMessage(kWhatResume, id()))->post();
108}
109
Andreas Hubera1587462010-12-15 15:17:42 -0800110void NuPlayer::Renderer::onMessageReceived(const sp<AMessage> &msg) {
111 switch (msg->what()) {
112 case kWhatDrainAudioQueue:
113 {
114 int32_t generation;
115 CHECK(msg->findInt32("generation", &generation));
116 if (generation != mAudioQueueGeneration) {
117 break;
118 }
119
120 mDrainAudioQueuePending = false;
121
Andreas Huber115cac82011-09-15 12:25:04 -0700122 if (onDrainAudioQueue()) {
123 uint32_t numFramesPlayed;
124 CHECK_EQ(mAudioSink->getPosition(&numFramesPlayed),
125 (status_t)OK);
Andreas Hubera1587462010-12-15 15:17:42 -0800126
Andreas Huber115cac82011-09-15 12:25:04 -0700127 uint32_t numFramesPendingPlayout =
128 mNumFramesWritten - numFramesPlayed;
129
130 // This is how long the audio sink will have data to
131 // play back.
132 int64_t delayUs =
133 mAudioSink->msecsPerFrame()
134 * numFramesPendingPlayout * 1000ll;
135
136 // Let's give it more data after about half that time
137 // has elapsed.
138 postDrainAudioQueue(delayUs / 2);
139 }
Andreas Hubera1587462010-12-15 15:17:42 -0800140 break;
141 }
142
143 case kWhatDrainVideoQueue:
144 {
145 int32_t generation;
146 CHECK(msg->findInt32("generation", &generation));
147 if (generation != mVideoQueueGeneration) {
148 break;
149 }
150
151 mDrainVideoQueuePending = false;
152
153 onDrainVideoQueue();
154
155 postDrainVideoQueue();
156 break;
157 }
158
159 case kWhatQueueBuffer:
160 {
161 onQueueBuffer(msg);
162 break;
163 }
164
165 case kWhatQueueEOS:
166 {
167 onQueueEOS(msg);
168 break;
169 }
170
171 case kWhatFlush:
172 {
173 onFlush(msg);
174 break;
175 }
176
Andreas Huber41c3f742010-12-21 10:22:33 -0800177 case kWhatAudioSinkChanged:
178 {
179 onAudioSinkChanged();
180 break;
181 }
182
Andreas Huber601fe0e2011-01-20 15:23:04 -0800183 case kWhatPause:
184 {
185 onPause();
186 break;
187 }
188
189 case kWhatResume:
190 {
191 onResume();
192 break;
193 }
194
Andreas Hubera1587462010-12-15 15:17:42 -0800195 default:
196 TRESPASS();
197 break;
198 }
199}
200
Andreas Huber115cac82011-09-15 12:25:04 -0700201void NuPlayer::Renderer::postDrainAudioQueue(int64_t delayUs) {
Andreas Huber601fe0e2011-01-20 15:23:04 -0800202 if (mDrainAudioQueuePending || mSyncQueues || mPaused) {
Andreas Hubera1587462010-12-15 15:17:42 -0800203 return;
204 }
205
206 if (mAudioQueue.empty()) {
207 return;
208 }
209
210 mDrainAudioQueuePending = true;
211 sp<AMessage> msg = new AMessage(kWhatDrainAudioQueue, id());
212 msg->setInt32("generation", mAudioQueueGeneration);
Andreas Huber115cac82011-09-15 12:25:04 -0700213 msg->post(delayUs);
Andreas Hubera1587462010-12-15 15:17:42 -0800214}
215
Andreas Huber41c3f742010-12-21 10:22:33 -0800216void NuPlayer::Renderer::signalAudioSinkChanged() {
217 (new AMessage(kWhatAudioSinkChanged, id()))->post();
218}
219
Andreas Huber115cac82011-09-15 12:25:04 -0700220bool NuPlayer::Renderer::onDrainAudioQueue() {
221 uint32_t numFramesPlayed;
Andreas Hubera6be6dc2011-10-11 15:24:07 -0700222 if (mAudioSink->getPosition(&numFramesPlayed) != OK) {
223 return false;
224 }
Andreas Huberd84fd792011-08-16 13:48:44 -0700225
Andreas Huber115cac82011-09-15 12:25:04 -0700226 ssize_t numFramesAvailableToWrite =
227 mAudioSink->frameCount() - (mNumFramesWritten - numFramesPlayed);
228
229#if 0
230 if (numFramesAvailableToWrite == mAudioSink->frameCount()) {
231 LOGI("audio sink underrun");
232 } else {
Steve Block06ade6a2011-10-20 11:56:00 +0100233 ALOGV("audio queue has %d frames left to play",
Andreas Huber115cac82011-09-15 12:25:04 -0700234 mAudioSink->frameCount() - numFramesAvailableToWrite);
235 }
236#endif
237
238 size_t numBytesAvailableToWrite =
239 numFramesAvailableToWrite * mAudioSink->frameSize();
240
241 while (numBytesAvailableToWrite > 0 && !mAudioQueue.empty()) {
Andreas Huberd84fd792011-08-16 13:48:44 -0700242 QueueEntry *entry = &*mAudioQueue.begin();
243
244 if (entry->mBuffer == NULL) {
245 // EOS
246
247 notifyEOS(true /* audio */, entry->mFinalResult);
248
249 mAudioQueue.erase(mAudioQueue.begin());
250 entry = NULL;
Andreas Huber115cac82011-09-15 12:25:04 -0700251 return false;
Eric Laurent6667ac32011-03-21 11:49:00 -0700252 }
253
Andreas Hubera1587462010-12-15 15:17:42 -0800254 if (entry->mOffset == 0) {
255 int64_t mediaTimeUs;
256 CHECK(entry->mBuffer->meta()->findInt64("timeUs", &mediaTimeUs));
257
Steve Block06ade6a2011-10-20 11:56:00 +0100258 ALOGV("rendering audio at media time %.2f secs", mediaTimeUs / 1E6);
Andreas Hubera1587462010-12-15 15:17:42 -0800259
260 mAnchorTimeMediaUs = mediaTimeUs;
261
262 uint32_t numFramesPlayed;
263 CHECK_EQ(mAudioSink->getPosition(&numFramesPlayed), (status_t)OK);
264
265 uint32_t numFramesPendingPlayout =
266 mNumFramesWritten - numFramesPlayed;
267
268 int64_t realTimeOffsetUs =
269 (mAudioSink->latency() / 2 /* XXX */
270 + numFramesPendingPlayout
271 * mAudioSink->msecsPerFrame()) * 1000ll;
272
273 // LOGI("realTimeOffsetUs = %lld us", realTimeOffsetUs);
274
275 mAnchorTimeRealUs =
276 ALooper::GetNowUs() + realTimeOffsetUs;
277 }
278
279 size_t copy = entry->mBuffer->size() - entry->mOffset;
280 if (copy > numBytesAvailableToWrite) {
281 copy = numBytesAvailableToWrite;
282 }
283
284 CHECK_EQ(mAudioSink->write(
285 entry->mBuffer->data() + entry->mOffset, copy),
286 (ssize_t)copy);
287
288 entry->mOffset += copy;
289 if (entry->mOffset == entry->mBuffer->size()) {
290 entry->mNotifyConsumed->post();
291 mAudioQueue.erase(mAudioQueue.begin());
Eric Laurent6667ac32011-03-21 11:49:00 -0700292
Andreas Hubera1587462010-12-15 15:17:42 -0800293 entry = NULL;
294 }
295
Andreas Huber115cac82011-09-15 12:25:04 -0700296 numBytesAvailableToWrite -= copy;
297 size_t copiedFrames = copy / mAudioSink->frameSize();
298 mNumFramesWritten += copiedFrames;
Andreas Hubera1587462010-12-15 15:17:42 -0800299 }
Andreas Huber08e10cb2011-01-05 12:17:08 -0800300
301 notifyPosition();
Andreas Huber115cac82011-09-15 12:25:04 -0700302
303 return !mAudioQueue.empty();
Andreas Hubera1587462010-12-15 15:17:42 -0800304}
305
306void NuPlayer::Renderer::postDrainVideoQueue() {
Andreas Huber601fe0e2011-01-20 15:23:04 -0800307 if (mDrainVideoQueuePending || mSyncQueues || mPaused) {
Andreas Hubera1587462010-12-15 15:17:42 -0800308 return;
309 }
310
311 if (mVideoQueue.empty()) {
312 return;
313 }
314
315 QueueEntry &entry = *mVideoQueue.begin();
316
317 sp<AMessage> msg = new AMessage(kWhatDrainVideoQueue, id());
318 msg->setInt32("generation", mVideoQueueGeneration);
319
320 int64_t delayUs;
321
322 if (entry.mBuffer == NULL) {
323 // EOS doesn't carry a timestamp.
324 delayUs = 0;
325 } else {
326 int64_t mediaTimeUs;
327 CHECK(entry.mBuffer->meta()->findInt64("timeUs", &mediaTimeUs));
328
329 if (mAnchorTimeMediaUs < 0) {
330 delayUs = 0;
331
Andreas Huber41c3f742010-12-21 10:22:33 -0800332 if (!mHasAudio) {
Andreas Hubera1587462010-12-15 15:17:42 -0800333 mAnchorTimeMediaUs = mediaTimeUs;
334 mAnchorTimeRealUs = ALooper::GetNowUs();
335 }
336 } else {
337 int64_t realTimeUs =
338 (mediaTimeUs - mAnchorTimeMediaUs) + mAnchorTimeRealUs;
339
340 delayUs = realTimeUs - ALooper::GetNowUs();
341 }
342 }
343
344 msg->post(delayUs);
345
346 mDrainVideoQueuePending = true;
347}
348
349void NuPlayer::Renderer::onDrainVideoQueue() {
350 if (mVideoQueue.empty()) {
351 return;
352 }
353
354 QueueEntry *entry = &*mVideoQueue.begin();
355
356 if (entry->mBuffer == NULL) {
357 // EOS
358
Andreas Huberd84fd792011-08-16 13:48:44 -0700359 notifyEOS(false /* audio */, entry->mFinalResult);
Andreas Hubera1587462010-12-15 15:17:42 -0800360
361 mVideoQueue.erase(mVideoQueue.begin());
362 entry = NULL;
Andreas Huber950fc9d2011-09-16 15:09:22 -0700363
364 mVideoLateByUs = 0ll;
365
366 notifyPosition();
Andreas Hubera1587462010-12-15 15:17:42 -0800367 return;
368 }
369
Andreas Hubera1587462010-12-15 15:17:42 -0800370 int64_t mediaTimeUs;
371 CHECK(entry->mBuffer->meta()->findInt64("timeUs", &mediaTimeUs));
372
Andreas Huber115cac82011-09-15 12:25:04 -0700373 int64_t realTimeUs = mediaTimeUs - mAnchorTimeMediaUs + mAnchorTimeRealUs;
Andreas Huber950fc9d2011-09-16 15:09:22 -0700374 mVideoLateByUs = ALooper::GetNowUs() - realTimeUs;
Andreas Huber115cac82011-09-15 12:25:04 -0700375
Andreas Huber950fc9d2011-09-16 15:09:22 -0700376 bool tooLate = (mVideoLateByUs > 40000);
377
378 if (tooLate) {
Steve Block06ade6a2011-10-20 11:56:00 +0100379 ALOGV("video late by %lld us (%.2f secs)", lateByUs, lateByUs / 1E6);
Andreas Huber115cac82011-09-15 12:25:04 -0700380 } else {
Steve Block06ade6a2011-10-20 11:56:00 +0100381 ALOGV("rendering video at media time %.2f secs", mediaTimeUs / 1E6);
Andreas Huber115cac82011-09-15 12:25:04 -0700382 }
Andreas Hubera1587462010-12-15 15:17:42 -0800383
Glenn Kastenf3309862011-11-04 18:05:35 -0700384 entry->mNotifyConsumed->setInt32("render", !tooLate);
Andreas Hubera1587462010-12-15 15:17:42 -0800385 entry->mNotifyConsumed->post();
386 mVideoQueue.erase(mVideoQueue.begin());
387 entry = NULL;
Andreas Huber08e10cb2011-01-05 12:17:08 -0800388
389 notifyPosition();
Andreas Hubera1587462010-12-15 15:17:42 -0800390}
391
Andreas Huberd84fd792011-08-16 13:48:44 -0700392void NuPlayer::Renderer::notifyEOS(bool audio, status_t finalResult) {
Andreas Hubera1587462010-12-15 15:17:42 -0800393 sp<AMessage> notify = mNotify->dup();
394 notify->setInt32("what", kWhatEOS);
395 notify->setInt32("audio", static_cast<int32_t>(audio));
Andreas Huberd84fd792011-08-16 13:48:44 -0700396 notify->setInt32("finalResult", finalResult);
Andreas Hubera1587462010-12-15 15:17:42 -0800397 notify->post();
398}
399
400void NuPlayer::Renderer::onQueueBuffer(const sp<AMessage> &msg) {
401 int32_t audio;
402 CHECK(msg->findInt32("audio", &audio));
403
Andreas Huber19922ad2011-01-21 10:15:23 -0800404 if (audio) {
405 mHasAudio = true;
406 } else {
407 mHasVideo = true;
408 }
409
Andreas Hubera1587462010-12-15 15:17:42 -0800410 if (dropBufferWhileFlushing(audio, msg)) {
411 return;
412 }
413
414 sp<RefBase> obj;
415 CHECK(msg->findObject("buffer", &obj));
416 sp<ABuffer> buffer = static_cast<ABuffer *>(obj.get());
417
418 sp<AMessage> notifyConsumed;
419 CHECK(msg->findMessage("notifyConsumed", &notifyConsumed));
420
421 QueueEntry entry;
422 entry.mBuffer = buffer;
423 entry.mNotifyConsumed = notifyConsumed;
424 entry.mOffset = 0;
425 entry.mFinalResult = OK;
426
427 if (audio) {
428 mAudioQueue.push_back(entry);
429 postDrainAudioQueue();
430 } else {
431 mVideoQueue.push_back(entry);
432 postDrainVideoQueue();
433 }
434
Andreas Huber6032a602011-08-26 16:02:19 -0700435 if (!mSyncQueues || mAudioQueue.empty() || mVideoQueue.empty()) {
436 return;
Andreas Hubera1587462010-12-15 15:17:42 -0800437 }
Andreas Huber6032a602011-08-26 16:02:19 -0700438
439 sp<ABuffer> firstAudioBuffer = (*mAudioQueue.begin()).mBuffer;
440 sp<ABuffer> firstVideoBuffer = (*mVideoQueue.begin()).mBuffer;
441
442 if (firstAudioBuffer == NULL || firstVideoBuffer == NULL) {
443 // EOS signalled on either queue.
444 syncQueuesDone();
445 return;
446 }
447
448 int64_t firstAudioTimeUs;
449 int64_t firstVideoTimeUs;
450 CHECK(firstAudioBuffer->meta()
451 ->findInt64("timeUs", &firstAudioTimeUs));
452 CHECK(firstVideoBuffer->meta()
453 ->findInt64("timeUs", &firstVideoTimeUs));
454
455 int64_t diff = firstVideoTimeUs - firstAudioTimeUs;
456
Steve Block06ade6a2011-10-20 11:56:00 +0100457 ALOGV("queueDiff = %.2f secs", diff / 1E6);
Andreas Huber6032a602011-08-26 16:02:19 -0700458
459 if (diff > 100000ll) {
460 // Audio data starts More than 0.1 secs before video.
461 // Drop some audio.
462
463 (*mAudioQueue.begin()).mNotifyConsumed->post();
464 mAudioQueue.erase(mAudioQueue.begin());
465 return;
466 }
467
468 syncQueuesDone();
Andreas Hubera1587462010-12-15 15:17:42 -0800469}
470
471void NuPlayer::Renderer::syncQueuesDone() {
472 if (!mSyncQueues) {
473 return;
474 }
475
476 mSyncQueues = false;
477
478 if (!mAudioQueue.empty()) {
479 postDrainAudioQueue();
480 }
481
482 if (!mVideoQueue.empty()) {
483 postDrainVideoQueue();
484 }
485}
486
487void NuPlayer::Renderer::onQueueEOS(const sp<AMessage> &msg) {
488 int32_t audio;
489 CHECK(msg->findInt32("audio", &audio));
490
491 if (dropBufferWhileFlushing(audio, msg)) {
492 return;
493 }
494
495 int32_t finalResult;
496 CHECK(msg->findInt32("finalResult", &finalResult));
497
498 QueueEntry entry;
499 entry.mOffset = 0;
500 entry.mFinalResult = finalResult;
501
502 if (audio) {
503 mAudioQueue.push_back(entry);
504 postDrainAudioQueue();
505 } else {
506 mVideoQueue.push_back(entry);
507 postDrainVideoQueue();
508 }
509}
510
511void NuPlayer::Renderer::onFlush(const sp<AMessage> &msg) {
512 int32_t audio;
513 CHECK(msg->findInt32("audio", &audio));
514
515 // If we're currently syncing the queues, i.e. dropping audio while
516 // aligning the first audio/video buffer times and only one of the
517 // two queues has data, we may starve that queue by not requesting
518 // more buffers from the decoder. If the other source then encounters
519 // a discontinuity that leads to flushing, we'll never find the
520 // corresponding discontinuity on the other queue.
521 // Therefore we'll stop syncing the queues if at least one of them
522 // is flushed.
523 syncQueuesDone();
524
525 if (audio) {
526 flushQueue(&mAudioQueue);
527
528 Mutex::Autolock autoLock(mFlushLock);
529 mFlushingAudio = false;
530
531 mDrainAudioQueuePending = false;
532 ++mAudioQueueGeneration;
533 } else {
534 flushQueue(&mVideoQueue);
535
536 Mutex::Autolock autoLock(mFlushLock);
537 mFlushingVideo = false;
538
539 mDrainVideoQueuePending = false;
540 ++mVideoQueueGeneration;
541 }
542
543 notifyFlushComplete(audio);
544}
545
546void NuPlayer::Renderer::flushQueue(List<QueueEntry> *queue) {
547 while (!queue->empty()) {
548 QueueEntry *entry = &*queue->begin();
549
550 if (entry->mBuffer != NULL) {
551 entry->mNotifyConsumed->post();
552 }
553
554 queue->erase(queue->begin());
555 entry = NULL;
556 }
557}
558
559void NuPlayer::Renderer::notifyFlushComplete(bool audio) {
560 sp<AMessage> notify = mNotify->dup();
561 notify->setInt32("what", kWhatFlushComplete);
562 notify->setInt32("audio", static_cast<int32_t>(audio));
563 notify->post();
564}
565
566bool NuPlayer::Renderer::dropBufferWhileFlushing(
567 bool audio, const sp<AMessage> &msg) {
568 bool flushing = false;
569
570 {
571 Mutex::Autolock autoLock(mFlushLock);
572 if (audio) {
573 flushing = mFlushingAudio;
574 } else {
575 flushing = mFlushingVideo;
576 }
577 }
578
579 if (!flushing) {
580 return false;
581 }
582
583 sp<AMessage> notifyConsumed;
584 if (msg->findMessage("notifyConsumed", &notifyConsumed)) {
585 notifyConsumed->post();
586 }
587
588 return true;
589}
590
Andreas Huber41c3f742010-12-21 10:22:33 -0800591void NuPlayer::Renderer::onAudioSinkChanged() {
592 CHECK(!mDrainAudioQueuePending);
593 mNumFramesWritten = 0;
594}
595
Andreas Huber08e10cb2011-01-05 12:17:08 -0800596void NuPlayer::Renderer::notifyPosition() {
597 if (mAnchorTimeRealUs < 0 || mAnchorTimeMediaUs < 0) {
598 return;
599 }
600
601 int64_t nowUs = ALooper::GetNowUs();
Andreas Huberfa6dfdc2011-09-13 08:28:38 -0700602
603 if (mLastPositionUpdateUs >= 0
604 && nowUs < mLastPositionUpdateUs + kMinPositionUpdateDelayUs) {
605 return;
606 }
607 mLastPositionUpdateUs = nowUs;
608
Andreas Huber08e10cb2011-01-05 12:17:08 -0800609 int64_t positionUs = (nowUs - mAnchorTimeRealUs) + mAnchorTimeMediaUs;
610
611 sp<AMessage> notify = mNotify->dup();
612 notify->setInt32("what", kWhatPosition);
613 notify->setInt64("positionUs", positionUs);
Andreas Huber950fc9d2011-09-16 15:09:22 -0700614 notify->setInt64("videoLateByUs", mVideoLateByUs);
Andreas Huber08e10cb2011-01-05 12:17:08 -0800615 notify->post();
616}
617
Andreas Huber601fe0e2011-01-20 15:23:04 -0800618void NuPlayer::Renderer::onPause() {
619 CHECK(!mPaused);
620
621 mDrainAudioQueuePending = false;
622 ++mAudioQueueGeneration;
623
624 mDrainVideoQueuePending = false;
625 ++mVideoQueueGeneration;
626
627 if (mHasAudio) {
628 mAudioSink->pause();
629 }
630
Steve Block06ade6a2011-10-20 11:56:00 +0100631 ALOGV("now paused audio queue has %d entries, video has %d entries",
Andreas Huber551aeac2011-11-28 16:27:35 -0800632 mAudioQueue.size(), mVideoQueue.size());
633
Andreas Huber601fe0e2011-01-20 15:23:04 -0800634 mPaused = true;
635}
636
637void NuPlayer::Renderer::onResume() {
Andreas Huber551aeac2011-11-28 16:27:35 -0800638 if (!mPaused) {
639 return;
640 }
Andreas Huber601fe0e2011-01-20 15:23:04 -0800641
642 if (mHasAudio) {
643 mAudioSink->start();
644 }
645
646 mPaused = false;
647
648 if (!mAudioQueue.empty()) {
649 postDrainAudioQueue();
650 }
651
652 if (!mVideoQueue.empty()) {
653 postDrainVideoQueue();
654 }
655}
656
Andreas Hubera1587462010-12-15 15:17:42 -0800657} // namespace android
658