blob: f1467c418bb85043503402e815092a0c212888bb [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//#define LOG_NDEBUG 0
18#define LOG_TAG "NuPlayer"
19#include <utils/Log.h>
20
21#include "NuPlayer.h"
Andreas Huber5bc087c2010-12-23 10:27:40 -080022
23#include "HTTPLiveSource.h"
Andreas Huberf9334412010-12-15 15:17:42 -080024#include "NuPlayerDecoder.h"
Andreas Huber43c3e6c2011-01-05 12:17:08 -080025#include "NuPlayerDriver.h"
Andreas Huberf9334412010-12-15 15:17:42 -080026#include "NuPlayerRenderer.h"
Andreas Huber5bc087c2010-12-23 10:27:40 -080027#include "NuPlayerSource.h"
Andreas Huber2bfdd422011-10-11 15:24:07 -070028#include "RTSPSource.h"
Andreas Huber5bc087c2010-12-23 10:27:40 -080029#include "StreamingSource.h"
Andreas Huberafed0e12011-09-20 15:39:58 -070030#include "GenericSource.h"
Andreas Huber5bc087c2010-12-23 10:27:40 -080031
32#include "ATSParser.h"
Andreas Huberf9334412010-12-15 15:17:42 -080033
Andreas Huber3831a062010-12-21 10:22:33 -080034#include <media/stagefright/foundation/hexdump.h>
Andreas Huberf9334412010-12-15 15:17:42 -080035#include <media/stagefright/foundation/ABuffer.h>
36#include <media/stagefright/foundation/ADebug.h>
37#include <media/stagefright/foundation/AMessage.h>
38#include <media/stagefright/ACodec.h>
Andreas Huber3fe62152011-09-16 15:09:22 -070039#include <media/stagefright/MediaDefs.h>
Andreas Huberf9334412010-12-15 15:17:42 -080040#include <media/stagefright/MediaErrors.h>
41#include <media/stagefright/MetaData.h>
Marco Nelissen4110c102012-03-29 09:31:28 -070042#include <media/stagefright/SkipCutBuffer.h>
Glenn Kasten11731182011-02-08 17:26:17 -080043#include <gui/ISurfaceTexture.h>
Andreas Huberf9334412010-12-15 15:17:42 -080044
Andreas Huber3fe62152011-09-16 15:09:22 -070045#include "avc_utils.h"
46
Andreas Huberf9334412010-12-15 15:17:42 -080047namespace android {
48
49////////////////////////////////////////////////////////////////////////////////
50
51NuPlayer::NuPlayer()
Andreas Huber9b80c2b2011-06-30 15:47:02 -070052 : mUIDValid(false),
Andreas Huber3fe62152011-09-16 15:09:22 -070053 mVideoIsAVC(false),
Andreas Huber9b80c2b2011-06-30 15:47:02 -070054 mAudioEOS(false),
Andreas Huberf9334412010-12-15 15:17:42 -080055 mVideoEOS(false),
Andreas Huber5bc087c2010-12-23 10:27:40 -080056 mScanSourcesPending(false),
Andreas Huber1aef2112011-01-04 14:01:29 -080057 mScanSourcesGeneration(0),
Andreas Huber6e3d3112011-11-28 12:36:11 -080058 mTimeDiscontinuityPending(false),
Andreas Huberf9334412010-12-15 15:17:42 -080059 mFlushingAudio(NONE),
Andreas Huber1aef2112011-01-04 14:01:29 -080060 mFlushingVideo(NONE),
61 mResetInProgress(false),
Andreas Huber3fe62152011-09-16 15:09:22 -070062 mResetPostponed(false),
63 mSkipRenderingAudioUntilMediaTimeUs(-1ll),
64 mSkipRenderingVideoUntilMediaTimeUs(-1ll),
65 mVideoLateByUs(0ll),
66 mNumFramesTotal(0ll),
Marco Nelissen4110c102012-03-29 09:31:28 -070067 mNumFramesDropped(0ll),
68 mSkipCutBuffer(NULL) {
Andreas Huberf9334412010-12-15 15:17:42 -080069}
70
71NuPlayer::~NuPlayer() {
Marco Nelissen4110c102012-03-29 09:31:28 -070072 delete mSkipCutBuffer;
73 mSkipCutBuffer = NULL;
Andreas Huberf9334412010-12-15 15:17:42 -080074}
75
Andreas Huber9b80c2b2011-06-30 15:47:02 -070076void NuPlayer::setUID(uid_t uid) {
77 mUIDValid = true;
78 mUID = uid;
79}
80
Andreas Huber43c3e6c2011-01-05 12:17:08 -080081void NuPlayer::setDriver(const wp<NuPlayerDriver> &driver) {
82 mDriver = driver;
Andreas Huberf9334412010-12-15 15:17:42 -080083}
84
85void NuPlayer::setDataSource(const sp<IStreamSource> &source) {
86 sp<AMessage> msg = new AMessage(kWhatSetDataSource, id());
87
Andreas Huber5bc087c2010-12-23 10:27:40 -080088 msg->setObject("source", new StreamingSource(source));
89 msg->post();
90}
Andreas Huberf9334412010-12-15 15:17:42 -080091
Andreas Huberafed0e12011-09-20 15:39:58 -070092static bool IsHTTPLiveURL(const char *url) {
93 if (!strncasecmp("http://", url, 7)
94 || !strncasecmp("https://", url, 8)) {
95 size_t len = strlen(url);
96 if (len >= 5 && !strcasecmp(".m3u8", &url[len - 5])) {
97 return true;
98 }
99
100 if (strstr(url,"m3u8")) {
101 return true;
102 }
103 }
104
105 return false;
106}
107
Andreas Huber5bc087c2010-12-23 10:27:40 -0800108void NuPlayer::setDataSource(
109 const char *url, const KeyedVector<String8, String8> *headers) {
110 sp<AMessage> msg = new AMessage(kWhatSetDataSource, id());
111
Andreas Huberafed0e12011-09-20 15:39:58 -0700112 sp<Source> source;
113 if (IsHTTPLiveURL(url)) {
114 source = new HTTPLiveSource(url, headers, mUIDValid, mUID);
115 } else if (!strncasecmp(url, "rtsp://", 7)) {
116 source = new RTSPSource(url, headers, mUIDValid, mUID);
Andreas Huber2bfdd422011-10-11 15:24:07 -0700117 } else {
Andreas Huberafed0e12011-09-20 15:39:58 -0700118 source = new GenericSource(url, headers, mUIDValid, mUID);
Andreas Huber2bfdd422011-10-11 15:24:07 -0700119 }
120
Andreas Huberafed0e12011-09-20 15:39:58 -0700121 msg->setObject("source", source);
122 msg->post();
123}
124
125void NuPlayer::setDataSource(int fd, int64_t offset, int64_t length) {
126 sp<AMessage> msg = new AMessage(kWhatSetDataSource, id());
127
128 sp<Source> source = new GenericSource(fd, offset, length);
129 msg->setObject("source", source);
Andreas Huberf9334412010-12-15 15:17:42 -0800130 msg->post();
131}
132
Glenn Kasten11731182011-02-08 17:26:17 -0800133void NuPlayer::setVideoSurfaceTexture(const sp<ISurfaceTexture> &surfaceTexture) {
134 sp<AMessage> msg = new AMessage(kWhatSetVideoNativeWindow, id());
135 sp<SurfaceTextureClient> surfaceTextureClient(surfaceTexture != NULL ?
136 new SurfaceTextureClient(surfaceTexture) : NULL);
137 msg->setObject("native-window", new NativeWindowWrapper(surfaceTextureClient));
Andreas Huberf9334412010-12-15 15:17:42 -0800138 msg->post();
139}
140
141void NuPlayer::setAudioSink(const sp<MediaPlayerBase::AudioSink> &sink) {
142 sp<AMessage> msg = new AMessage(kWhatSetAudioSink, id());
143 msg->setObject("sink", sink);
144 msg->post();
145}
146
147void NuPlayer::start() {
148 (new AMessage(kWhatStart, id()))->post();
149}
150
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800151void NuPlayer::pause() {
Andreas Huberb4082222011-01-20 15:23:04 -0800152 (new AMessage(kWhatPause, id()))->post();
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800153}
154
155void NuPlayer::resume() {
Andreas Huberb4082222011-01-20 15:23:04 -0800156 (new AMessage(kWhatResume, id()))->post();
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800157}
158
Andreas Huber1aef2112011-01-04 14:01:29 -0800159void NuPlayer::resetAsync() {
160 (new AMessage(kWhatReset, id()))->post();
161}
162
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800163void NuPlayer::seekToAsync(int64_t seekTimeUs) {
164 sp<AMessage> msg = new AMessage(kWhatSeek, id());
165 msg->setInt64("seekTimeUs", seekTimeUs);
166 msg->post();
167}
168
Andreas Huber53df1a42010-12-22 10:03:04 -0800169// static
Andreas Huber1aef2112011-01-04 14:01:29 -0800170bool NuPlayer::IsFlushingState(FlushStatus state, bool *needShutdown) {
Andreas Huber53df1a42010-12-22 10:03:04 -0800171 switch (state) {
172 case FLUSHING_DECODER:
Andreas Huber1aef2112011-01-04 14:01:29 -0800173 if (needShutdown != NULL) {
174 *needShutdown = false;
Andreas Huber53df1a42010-12-22 10:03:04 -0800175 }
176 return true;
177
Andreas Huber1aef2112011-01-04 14:01:29 -0800178 case FLUSHING_DECODER_SHUTDOWN:
179 if (needShutdown != NULL) {
180 *needShutdown = true;
Andreas Huber53df1a42010-12-22 10:03:04 -0800181 }
182 return true;
183
184 default:
185 return false;
186 }
187}
188
Andreas Huberf9334412010-12-15 15:17:42 -0800189void NuPlayer::onMessageReceived(const sp<AMessage> &msg) {
190 switch (msg->what()) {
191 case kWhatSetDataSource:
192 {
Steve Block3856b092011-10-20 11:56:00 +0100193 ALOGV("kWhatSetDataSource");
Andreas Huberf9334412010-12-15 15:17:42 -0800194
195 CHECK(mSource == NULL);
196
Andreas Huber5bc087c2010-12-23 10:27:40 -0800197 sp<RefBase> obj;
198 CHECK(msg->findObject("source", &obj));
Andreas Huberf9334412010-12-15 15:17:42 -0800199
Andreas Huber5bc087c2010-12-23 10:27:40 -0800200 mSource = static_cast<Source *>(obj.get());
Andreas Huberf9334412010-12-15 15:17:42 -0800201 break;
202 }
203
Glenn Kasten11731182011-02-08 17:26:17 -0800204 case kWhatSetVideoNativeWindow:
Andreas Huberf9334412010-12-15 15:17:42 -0800205 {
Steve Block3856b092011-10-20 11:56:00 +0100206 ALOGV("kWhatSetVideoNativeWindow");
Andreas Huberf9334412010-12-15 15:17:42 -0800207
208 sp<RefBase> obj;
Glenn Kasten11731182011-02-08 17:26:17 -0800209 CHECK(msg->findObject("native-window", &obj));
Andreas Huberf9334412010-12-15 15:17:42 -0800210
Glenn Kasten11731182011-02-08 17:26:17 -0800211 mNativeWindow = static_cast<NativeWindowWrapper *>(obj.get());
Andreas Huberf9334412010-12-15 15:17:42 -0800212 break;
213 }
214
215 case kWhatSetAudioSink:
216 {
Steve Block3856b092011-10-20 11:56:00 +0100217 ALOGV("kWhatSetAudioSink");
Andreas Huberf9334412010-12-15 15:17:42 -0800218
219 sp<RefBase> obj;
220 CHECK(msg->findObject("sink", &obj));
221
222 mAudioSink = static_cast<MediaPlayerBase::AudioSink *>(obj.get());
223 break;
224 }
225
226 case kWhatStart:
227 {
Steve Block3856b092011-10-20 11:56:00 +0100228 ALOGV("kWhatStart");
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800229
Andreas Huber3fe62152011-09-16 15:09:22 -0700230 mVideoIsAVC = false;
Andreas Huber1aef2112011-01-04 14:01:29 -0800231 mAudioEOS = false;
232 mVideoEOS = false;
Andreas Huber32f3cef2011-03-02 15:34:46 -0800233 mSkipRenderingAudioUntilMediaTimeUs = -1;
234 mSkipRenderingVideoUntilMediaTimeUs = -1;
Andreas Huber3fe62152011-09-16 15:09:22 -0700235 mVideoLateByUs = 0;
236 mNumFramesTotal = 0;
237 mNumFramesDropped = 0;
Andreas Huber1aef2112011-01-04 14:01:29 -0800238
Andreas Huber5bc087c2010-12-23 10:27:40 -0800239 mSource->start();
Andreas Huberf9334412010-12-15 15:17:42 -0800240
Marco Nelissen4110c102012-03-29 09:31:28 -0700241 sp<MetaData> meta = mSource->getFormat(true /* audio */);
242 if (meta != NULL) {
243 int32_t delay = 0;
244 if (!meta->findInt32(kKeyEncoderDelay, &delay)) {
245 delay = 0;
246 }
247 int32_t padding = 0;
248 if (!meta->findInt32(kKeyEncoderPadding, &padding)) {
249 padding = 0;
250 }
251 int32_t numchannels = 0;
252 if (delay + padding) {
253 if (meta->findInt32(kKeyChannelCount, &numchannels)) {
254 size_t frameSize = numchannels * sizeof(int16_t);
255 if (mSkipCutBuffer) {
256 size_t prevbuffersize = mSkipCutBuffer->size();
257 if (prevbuffersize != 0) {
258 ALOGW("Replacing SkipCutBuffer holding %d bytes", prevbuffersize);
259 }
260 delete mSkipCutBuffer;
261 }
262 mSkipCutBuffer = new SkipCutBuffer(delay * frameSize, padding * frameSize);
263 }
264 }
265 }
266
Andreas Huberf9334412010-12-15 15:17:42 -0800267 mRenderer = new Renderer(
268 mAudioSink,
269 new AMessage(kWhatRendererNotify, id()));
270
271 looper()->registerHandler(mRenderer);
272
Andreas Huber1aef2112011-01-04 14:01:29 -0800273 postScanSources();
Andreas Huberf9334412010-12-15 15:17:42 -0800274 break;
275 }
276
277 case kWhatScanSources:
278 {
Andreas Huber1aef2112011-01-04 14:01:29 -0800279 int32_t generation;
280 CHECK(msg->findInt32("generation", &generation));
281 if (generation != mScanSourcesGeneration) {
282 // Drop obsolete msg.
283 break;
284 }
285
Andreas Huber5bc087c2010-12-23 10:27:40 -0800286 mScanSourcesPending = false;
287
Steve Block3856b092011-10-20 11:56:00 +0100288 ALOGV("scanning sources haveAudio=%d, haveVideo=%d",
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800289 mAudioDecoder != NULL, mVideoDecoder != NULL);
290
Andreas Huber5bc087c2010-12-23 10:27:40 -0800291 instantiateDecoder(false, &mVideoDecoder);
Andreas Huberf9334412010-12-15 15:17:42 -0800292
293 if (mAudioSink != NULL) {
Andreas Huber5bc087c2010-12-23 10:27:40 -0800294 instantiateDecoder(true, &mAudioDecoder);
Andreas Huberf9334412010-12-15 15:17:42 -0800295 }
296
Andreas Hubereac68ba2011-09-27 12:12:25 -0700297 status_t err;
298 if ((err = mSource->feedMoreTSData()) != OK) {
Andreas Huber1aef2112011-01-04 14:01:29 -0800299 if (mAudioDecoder == NULL && mVideoDecoder == NULL) {
300 // We're not currently decoding anything (no audio or
301 // video tracks found) and we just ran out of input data.
Andreas Hubereac68ba2011-09-27 12:12:25 -0700302
303 if (err == ERROR_END_OF_STREAM) {
304 notifyListener(MEDIA_PLAYBACK_COMPLETE, 0, 0);
305 } else {
306 notifyListener(MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, err);
307 }
Andreas Huber1aef2112011-01-04 14:01:29 -0800308 }
Andreas Huberf9334412010-12-15 15:17:42 -0800309 break;
310 }
311
Andreas Huberf9334412010-12-15 15:17:42 -0800312 if (mAudioDecoder == NULL || mVideoDecoder == NULL) {
313 msg->post(100000ll);
Andreas Huber5bc087c2010-12-23 10:27:40 -0800314 mScanSourcesPending = true;
Andreas Huberf9334412010-12-15 15:17:42 -0800315 }
316 break;
317 }
318
319 case kWhatVideoNotify:
320 case kWhatAudioNotify:
321 {
322 bool audio = msg->what() == kWhatAudioNotify;
323
324 sp<AMessage> codecRequest;
325 CHECK(msg->findMessage("codec-request", &codecRequest));
326
327 int32_t what;
328 CHECK(codecRequest->findInt32("what", &what));
329
330 if (what == ACodec::kWhatFillThisBuffer) {
331 status_t err = feedDecoderInputData(
332 audio, codecRequest);
333
Andreas Huber5bc087c2010-12-23 10:27:40 -0800334 if (err == -EWOULDBLOCK) {
Andreas Hubereac68ba2011-09-27 12:12:25 -0700335 if (mSource->feedMoreTSData() == OK) {
Andreas Huber1183a4a2011-11-03 11:00:21 -0700336 msg->post(10000ll);
Andreas Huber5bc087c2010-12-23 10:27:40 -0800337 }
Andreas Huberf9334412010-12-15 15:17:42 -0800338 }
339 } else if (what == ACodec::kWhatEOS) {
Andreas Huberdc9bacd2011-09-26 10:53:29 -0700340 int32_t err;
341 CHECK(codecRequest->findInt32("err", &err));
342
343 if (err == ERROR_END_OF_STREAM) {
Steve Block3856b092011-10-20 11:56:00 +0100344 ALOGV("got %s decoder EOS", audio ? "audio" : "video");
Andreas Huberdc9bacd2011-09-26 10:53:29 -0700345 } else {
Steve Block3856b092011-10-20 11:56:00 +0100346 ALOGV("got %s decoder EOS w/ error %d",
Andreas Huberdc9bacd2011-09-26 10:53:29 -0700347 audio ? "audio" : "video",
348 err);
349 }
350
351 mRenderer->queueEOS(audio, err);
Andreas Huberf9334412010-12-15 15:17:42 -0800352 } else if (what == ACodec::kWhatFlushCompleted) {
Andreas Huber1aef2112011-01-04 14:01:29 -0800353 bool needShutdown;
Andreas Huber53df1a42010-12-22 10:03:04 -0800354
Andreas Huberf9334412010-12-15 15:17:42 -0800355 if (audio) {
Andreas Huber1aef2112011-01-04 14:01:29 -0800356 CHECK(IsFlushingState(mFlushingAudio, &needShutdown));
Andreas Huberf9334412010-12-15 15:17:42 -0800357 mFlushingAudio = FLUSHED;
358 } else {
Andreas Huber1aef2112011-01-04 14:01:29 -0800359 CHECK(IsFlushingState(mFlushingVideo, &needShutdown));
Andreas Huberf9334412010-12-15 15:17:42 -0800360 mFlushingVideo = FLUSHED;
Andreas Huber3fe62152011-09-16 15:09:22 -0700361
362 mVideoLateByUs = 0;
Andreas Huberf9334412010-12-15 15:17:42 -0800363 }
364
Steve Block3856b092011-10-20 11:56:00 +0100365 ALOGV("decoder %s flush completed", audio ? "audio" : "video");
Andreas Huberf9334412010-12-15 15:17:42 -0800366
Andreas Huber1aef2112011-01-04 14:01:29 -0800367 if (needShutdown) {
Steve Block3856b092011-10-20 11:56:00 +0100368 ALOGV("initiating %s decoder shutdown",
Andreas Huber53df1a42010-12-22 10:03:04 -0800369 audio ? "audio" : "video");
Andreas Huberf9334412010-12-15 15:17:42 -0800370
Andreas Huber53df1a42010-12-22 10:03:04 -0800371 (audio ? mAudioDecoder : mVideoDecoder)->initiateShutdown();
Andreas Huberf9334412010-12-15 15:17:42 -0800372
Andreas Huber53df1a42010-12-22 10:03:04 -0800373 if (audio) {
374 mFlushingAudio = SHUTTING_DOWN_DECODER;
375 } else {
376 mFlushingVideo = SHUTTING_DOWN_DECODER;
377 }
Andreas Huberf9334412010-12-15 15:17:42 -0800378 }
Andreas Huber3831a062010-12-21 10:22:33 -0800379
380 finishFlushIfPossible();
Andreas Huber2c2814b2010-12-15 17:18:20 -0800381 } else if (what == ACodec::kWhatOutputFormatChanged) {
Andreas Huber31e25082011-01-10 10:38:31 -0800382 if (audio) {
383 int32_t numChannels;
384 CHECK(codecRequest->findInt32("channel-count", &numChannels));
Andreas Huber2c2814b2010-12-15 17:18:20 -0800385
Andreas Huber31e25082011-01-10 10:38:31 -0800386 int32_t sampleRate;
387 CHECK(codecRequest->findInt32("sample-rate", &sampleRate));
Andreas Huber2c2814b2010-12-15 17:18:20 -0800388
Steve Block3856b092011-10-20 11:56:00 +0100389 ALOGV("Audio output format changed to %d Hz, %d channels",
Andreas Huber31e25082011-01-10 10:38:31 -0800390 sampleRate, numChannels);
Andreas Huber2c2814b2010-12-15 17:18:20 -0800391
Andreas Huber31e25082011-01-10 10:38:31 -0800392 mAudioSink->close();
Eric Laurent1948eb32012-04-13 16:50:19 -0700393
394 audio_output_flags_t flags;
395 int64_t durationUs;
396 // FIXME: we should handle the case where the video decoder is created after
397 // we receive the format change indication. Current code will just make that
398 // we select deep buffer with video which should not be a problem as it should
399 // not prevent from keeping A/V sync.
400 if (mVideoDecoder == NULL &&
401 mSource->getDuration(&durationUs) == OK &&
402 durationUs > AUDIO_SINK_MIN_DEEP_BUFFER_DURATION_US) {
403 flags = AUDIO_OUTPUT_FLAG_DEEP_BUFFER;
404 } else {
405 flags = AUDIO_OUTPUT_FLAG_NONE;
406 }
407
Andreas Huber078cfcf2011-09-15 12:25:04 -0700408 CHECK_EQ(mAudioSink->open(
409 sampleRate,
410 numChannels,
Jean-Michel Trivi786618f2012-03-02 14:54:07 -0800411 CHANNEL_MASK_USE_CHANNEL_ORDER,
Andreas Huber078cfcf2011-09-15 12:25:04 -0700412 AUDIO_FORMAT_PCM_16_BIT,
Eric Laurent1948eb32012-04-13 16:50:19 -0700413 8 /* bufferCount */,
414 NULL,
415 NULL,
416 flags),
Andreas Huber078cfcf2011-09-15 12:25:04 -0700417 (status_t)OK);
Andreas Huber31e25082011-01-10 10:38:31 -0800418 mAudioSink->start();
Andreas Huber2c2814b2010-12-15 17:18:20 -0800419
Andreas Huber31e25082011-01-10 10:38:31 -0800420 mRenderer->signalAudioSinkChanged();
421 } else {
422 // video
Andreas Huber3831a062010-12-21 10:22:33 -0800423
Andreas Huber31e25082011-01-10 10:38:31 -0800424 int32_t width, height;
425 CHECK(codecRequest->findInt32("width", &width));
426 CHECK(codecRequest->findInt32("height", &height));
427
428 int32_t cropLeft, cropTop, cropRight, cropBottom;
429 CHECK(codecRequest->findRect(
430 "crop",
431 &cropLeft, &cropTop, &cropRight, &cropBottom));
432
Steve Block3856b092011-10-20 11:56:00 +0100433 ALOGV("Video output format changed to %d x %d "
Andreas Hubercb67cd12011-08-26 16:02:19 -0700434 "(crop: %d x %d @ (%d, %d))",
Andreas Huber31e25082011-01-10 10:38:31 -0800435 width, height,
Andreas Hubercb67cd12011-08-26 16:02:19 -0700436 (cropRight - cropLeft + 1),
437 (cropBottom - cropTop + 1),
438 cropLeft, cropTop);
Andreas Huber31e25082011-01-10 10:38:31 -0800439
440 notifyListener(
441 MEDIA_SET_VIDEO_SIZE,
442 cropRight - cropLeft + 1,
443 cropBottom - cropTop + 1);
444 }
Andreas Huber3831a062010-12-21 10:22:33 -0800445 } else if (what == ACodec::kWhatShutdownCompleted) {
Steve Block3856b092011-10-20 11:56:00 +0100446 ALOGV("%s shutdown completed", audio ? "audio" : "video");
Andreas Huber3831a062010-12-21 10:22:33 -0800447 if (audio) {
448 mAudioDecoder.clear();
449
450 CHECK_EQ((int)mFlushingAudio, (int)SHUTTING_DOWN_DECODER);
451 mFlushingAudio = SHUT_DOWN;
452 } else {
453 mVideoDecoder.clear();
454
455 CHECK_EQ((int)mFlushingVideo, (int)SHUTTING_DOWN_DECODER);
456 mFlushingVideo = SHUT_DOWN;
457 }
458
459 finishFlushIfPossible();
Andreas Huberc92fd242011-08-16 13:48:44 -0700460 } else if (what == ACodec::kWhatError) {
Steve Block29357bc2012-01-06 19:20:56 +0000461 ALOGE("Received error from %s decoder, aborting playback.",
Andreas Huberc92fd242011-08-16 13:48:44 -0700462 audio ? "audio" : "video");
463
464 mRenderer->queueEOS(audio, UNKNOWN_ERROR);
Andreas Huber57788222012-02-21 11:47:18 -0800465 } else if (what == ACodec::kWhatDrainThisBuffer) {
Andreas Huberf9334412010-12-15 15:17:42 -0800466 renderBuffer(audio, codecRequest);
Andreas Huber57788222012-02-21 11:47:18 -0800467 } else {
468 ALOGV("Unhandled codec notification %d.", what);
Andreas Huberf9334412010-12-15 15:17:42 -0800469 }
470
471 break;
472 }
473
474 case kWhatRendererNotify:
475 {
476 int32_t what;
477 CHECK(msg->findInt32("what", &what));
478
479 if (what == Renderer::kWhatEOS) {
480 int32_t audio;
481 CHECK(msg->findInt32("audio", &audio));
482
Andreas Huberc92fd242011-08-16 13:48:44 -0700483 int32_t finalResult;
484 CHECK(msg->findInt32("finalResult", &finalResult));
485
Andreas Huberf9334412010-12-15 15:17:42 -0800486 if (audio) {
487 mAudioEOS = true;
488 } else {
489 mVideoEOS = true;
490 }
491
Andreas Huberc92fd242011-08-16 13:48:44 -0700492 if (finalResult == ERROR_END_OF_STREAM) {
Steve Block3856b092011-10-20 11:56:00 +0100493 ALOGV("reached %s EOS", audio ? "audio" : "video");
Andreas Huberc92fd242011-08-16 13:48:44 -0700494 } else {
Steve Block29357bc2012-01-06 19:20:56 +0000495 ALOGE("%s track encountered an error (%d)",
Andreas Huberc92fd242011-08-16 13:48:44 -0700496 audio ? "audio" : "video", finalResult);
497
498 notifyListener(
499 MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, finalResult);
500 }
Andreas Huberf9334412010-12-15 15:17:42 -0800501
502 if ((mAudioEOS || mAudioDecoder == NULL)
503 && (mVideoEOS || mVideoDecoder == NULL)) {
504 notifyListener(MEDIA_PLAYBACK_COMPLETE, 0, 0);
505 }
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800506 } else if (what == Renderer::kWhatPosition) {
507 int64_t positionUs;
508 CHECK(msg->findInt64("positionUs", &positionUs));
509
Andreas Huber3fe62152011-09-16 15:09:22 -0700510 CHECK(msg->findInt64("videoLateByUs", &mVideoLateByUs));
511
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800512 if (mDriver != NULL) {
513 sp<NuPlayerDriver> driver = mDriver.promote();
514 if (driver != NULL) {
515 driver->notifyPosition(positionUs);
Andreas Huber3fe62152011-09-16 15:09:22 -0700516
517 driver->notifyFrameStats(
518 mNumFramesTotal, mNumFramesDropped);
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800519 }
520 }
Andreas Huber3fe62152011-09-16 15:09:22 -0700521 } else if (what == Renderer::kWhatFlushComplete) {
Andreas Huberf9334412010-12-15 15:17:42 -0800522 CHECK_EQ(what, (int32_t)Renderer::kWhatFlushComplete);
523
524 int32_t audio;
525 CHECK(msg->findInt32("audio", &audio));
526
Steve Block3856b092011-10-20 11:56:00 +0100527 ALOGV("renderer %s flush completed.", audio ? "audio" : "video");
Andreas Huberf9334412010-12-15 15:17:42 -0800528 }
529 break;
530 }
531
532 case kWhatMoreDataQueued:
533 {
534 break;
535 }
536
Andreas Huber1aef2112011-01-04 14:01:29 -0800537 case kWhatReset:
538 {
Steve Block3856b092011-10-20 11:56:00 +0100539 ALOGV("kWhatReset");
Andreas Huber1aef2112011-01-04 14:01:29 -0800540
Andreas Huberb58ce9f2011-11-28 16:27:35 -0800541 if (mRenderer != NULL) {
542 // There's an edge case where the renderer owns all output
543 // buffers and is paused, therefore the decoder will not read
544 // more input data and will never encounter the matching
545 // discontinuity. To avoid this, we resume the renderer.
546
547 if (mFlushingAudio == AWAITING_DISCONTINUITY
548 || mFlushingVideo == AWAITING_DISCONTINUITY) {
549 mRenderer->resume();
550 }
551 }
552
Andreas Huber1aef2112011-01-04 14:01:29 -0800553 if (mFlushingAudio != NONE || mFlushingVideo != NONE) {
554 // We're currently flushing, postpone the reset until that's
555 // completed.
556
Andreas Huberea9d51b2011-11-30 09:53:40 -0800557 ALOGV("postponing reset mFlushingAudio=%d, mFlushingVideo=%d",
558 mFlushingAudio, mFlushingVideo);
Andreas Huber1aef2112011-01-04 14:01:29 -0800559
560 mResetPostponed = true;
561 break;
562 }
563
564 if (mAudioDecoder == NULL && mVideoDecoder == NULL) {
565 finishReset();
566 break;
567 }
568
Andreas Huber6e3d3112011-11-28 12:36:11 -0800569 mTimeDiscontinuityPending = true;
570
Andreas Huber1aef2112011-01-04 14:01:29 -0800571 if (mAudioDecoder != NULL) {
572 flushDecoder(true /* audio */, true /* needShutdown */);
573 }
574
575 if (mVideoDecoder != NULL) {
576 flushDecoder(false /* audio */, true /* needShutdown */);
577 }
578
579 mResetInProgress = true;
580 break;
581 }
582
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800583 case kWhatSeek:
584 {
585 int64_t seekTimeUs;
586 CHECK(msg->findInt64("seekTimeUs", &seekTimeUs));
587
Steve Block3856b092011-10-20 11:56:00 +0100588 ALOGV("kWhatSeek seekTimeUs=%lld us (%.2f secs)",
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800589 seekTimeUs, seekTimeUs / 1E6);
590
591 mSource->seekTo(seekTimeUs);
592
593 if (mDriver != NULL) {
594 sp<NuPlayerDriver> driver = mDriver.promote();
595 if (driver != NULL) {
596 driver->notifySeekComplete();
597 }
598 }
599
600 break;
601 }
602
Andreas Huberb4082222011-01-20 15:23:04 -0800603 case kWhatPause:
604 {
605 CHECK(mRenderer != NULL);
606 mRenderer->pause();
607 break;
608 }
609
610 case kWhatResume:
611 {
612 CHECK(mRenderer != NULL);
613 mRenderer->resume();
614 break;
615 }
616
Andreas Huberf9334412010-12-15 15:17:42 -0800617 default:
618 TRESPASS();
619 break;
620 }
621}
622
Andreas Huber3831a062010-12-21 10:22:33 -0800623void NuPlayer::finishFlushIfPossible() {
624 if (mFlushingAudio != FLUSHED && mFlushingAudio != SHUT_DOWN) {
625 return;
626 }
627
628 if (mFlushingVideo != FLUSHED && mFlushingVideo != SHUT_DOWN) {
629 return;
630 }
631
Steve Block3856b092011-10-20 11:56:00 +0100632 ALOGV("both audio and video are flushed now.");
Andreas Huber3831a062010-12-21 10:22:33 -0800633
Andreas Huber6e3d3112011-11-28 12:36:11 -0800634 if (mTimeDiscontinuityPending) {
635 mRenderer->signalTimeDiscontinuity();
636 mTimeDiscontinuityPending = false;
637 }
Andreas Huber3831a062010-12-21 10:22:33 -0800638
Andreas Huber22fc52f2011-01-05 16:24:27 -0800639 if (mAudioDecoder != NULL) {
Andreas Huber3831a062010-12-21 10:22:33 -0800640 mAudioDecoder->signalResume();
641 }
642
Andreas Huber22fc52f2011-01-05 16:24:27 -0800643 if (mVideoDecoder != NULL) {
Andreas Huber3831a062010-12-21 10:22:33 -0800644 mVideoDecoder->signalResume();
645 }
646
647 mFlushingAudio = NONE;
648 mFlushingVideo = NONE;
Andreas Huber3831a062010-12-21 10:22:33 -0800649
Andreas Huber1aef2112011-01-04 14:01:29 -0800650 if (mResetInProgress) {
Steve Block3856b092011-10-20 11:56:00 +0100651 ALOGV("reset completed");
Andreas Huber1aef2112011-01-04 14:01:29 -0800652
653 mResetInProgress = false;
654 finishReset();
655 } else if (mResetPostponed) {
656 (new AMessage(kWhatReset, id()))->post();
657 mResetPostponed = false;
Andreas Huber22fc52f2011-01-05 16:24:27 -0800658 } else if (mAudioDecoder == NULL || mVideoDecoder == NULL) {
Andreas Huber1aef2112011-01-04 14:01:29 -0800659 postScanSources();
Andreas Huberf9334412010-12-15 15:17:42 -0800660 }
661}
662
Andreas Huber1aef2112011-01-04 14:01:29 -0800663void NuPlayer::finishReset() {
664 CHECK(mAudioDecoder == NULL);
665 CHECK(mVideoDecoder == NULL);
666
Andreas Huber2bfdd422011-10-11 15:24:07 -0700667 ++mScanSourcesGeneration;
668 mScanSourcesPending = false;
669
Andreas Huber1aef2112011-01-04 14:01:29 -0800670 mRenderer.clear();
Andreas Huber2bfdd422011-10-11 15:24:07 -0700671
672 if (mSource != NULL) {
673 mSource->stop();
674 mSource.clear();
675 }
Andreas Huber1aef2112011-01-04 14:01:29 -0800676
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800677 if (mDriver != NULL) {
678 sp<NuPlayerDriver> driver = mDriver.promote();
679 if (driver != NULL) {
680 driver->notifyResetComplete();
681 }
682 }
Andreas Huber1aef2112011-01-04 14:01:29 -0800683}
684
685void NuPlayer::postScanSources() {
686 if (mScanSourcesPending) {
687 return;
688 }
689
690 sp<AMessage> msg = new AMessage(kWhatScanSources, id());
691 msg->setInt32("generation", mScanSourcesGeneration);
692 msg->post();
693
694 mScanSourcesPending = true;
695}
696
Andreas Huber5bc087c2010-12-23 10:27:40 -0800697status_t NuPlayer::instantiateDecoder(bool audio, sp<Decoder> *decoder) {
Andreas Huberf9334412010-12-15 15:17:42 -0800698 if (*decoder != NULL) {
699 return OK;
700 }
701
Andreas Huber5bc087c2010-12-23 10:27:40 -0800702 sp<MetaData> meta = mSource->getFormat(audio);
Andreas Huberf9334412010-12-15 15:17:42 -0800703
Andreas Huber5bc087c2010-12-23 10:27:40 -0800704 if (meta == NULL) {
Andreas Huberf9334412010-12-15 15:17:42 -0800705 return -EWOULDBLOCK;
706 }
707
Andreas Huber3fe62152011-09-16 15:09:22 -0700708 if (!audio) {
709 const char *mime;
710 CHECK(meta->findCString(kKeyMIMEType, &mime));
711 mVideoIsAVC = !strcasecmp(MEDIA_MIMETYPE_VIDEO_AVC, mime);
712 }
713
Andreas Huberf9334412010-12-15 15:17:42 -0800714 sp<AMessage> notify =
715 new AMessage(audio ? kWhatAudioNotify : kWhatVideoNotify,
716 id());
717
Glenn Kasten11731182011-02-08 17:26:17 -0800718 *decoder = audio ? new Decoder(notify) :
719 new Decoder(notify, mNativeWindow);
Andreas Huberf9334412010-12-15 15:17:42 -0800720 looper()->registerHandler(*decoder);
721
Andreas Huber5bc087c2010-12-23 10:27:40 -0800722 (*decoder)->configure(meta);
Andreas Huberf9334412010-12-15 15:17:42 -0800723
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800724 int64_t durationUs;
725 if (mDriver != NULL && mSource->getDuration(&durationUs) == OK) {
726 sp<NuPlayerDriver> driver = mDriver.promote();
727 if (driver != NULL) {
728 driver->notifyDuration(durationUs);
729 }
730 }
731
Andreas Huberf9334412010-12-15 15:17:42 -0800732 return OK;
733}
734
735status_t NuPlayer::feedDecoderInputData(bool audio, const sp<AMessage> &msg) {
736 sp<AMessage> reply;
737 CHECK(msg->findMessage("reply", &reply));
738
Andreas Huber53df1a42010-12-22 10:03:04 -0800739 if ((audio && IsFlushingState(mFlushingAudio))
740 || (!audio && IsFlushingState(mFlushingVideo))) {
Andreas Huberf9334412010-12-15 15:17:42 -0800741 reply->setInt32("err", INFO_DISCONTINUITY);
742 reply->post();
743 return OK;
744 }
745
746 sp<ABuffer> accessUnit;
Andreas Huberf9334412010-12-15 15:17:42 -0800747
Andreas Huber3fe62152011-09-16 15:09:22 -0700748 bool dropAccessUnit;
749 do {
750 status_t err = mSource->dequeueAccessUnit(audio, &accessUnit);
Andreas Huber5bc087c2010-12-23 10:27:40 -0800751
Andreas Huber3fe62152011-09-16 15:09:22 -0700752 if (err == -EWOULDBLOCK) {
753 return err;
754 } else if (err != OK) {
755 if (err == INFO_DISCONTINUITY) {
756 int32_t type;
757 CHECK(accessUnit->meta()->findInt32("discontinuity", &type));
Andreas Huber53df1a42010-12-22 10:03:04 -0800758
Andreas Huber3fe62152011-09-16 15:09:22 -0700759 bool formatChange =
Andreas Huber6e3d3112011-11-28 12:36:11 -0800760 (audio &&
761 (type & ATSParser::DISCONTINUITY_AUDIO_FORMAT))
762 || (!audio &&
763 (type & ATSParser::DISCONTINUITY_VIDEO_FORMAT));
Andreas Huber53df1a42010-12-22 10:03:04 -0800764
Andreas Huber6e3d3112011-11-28 12:36:11 -0800765 bool timeChange = (type & ATSParser::DISCONTINUITY_TIME) != 0;
766
Steve Blockdf64d152012-01-04 20:05:49 +0000767 ALOGI("%s discontinuity (formatChange=%d, time=%d)",
Andreas Huber6e3d3112011-11-28 12:36:11 -0800768 audio ? "audio" : "video", formatChange, timeChange);
Andreas Huber32f3cef2011-03-02 15:34:46 -0800769
Andreas Huber3fe62152011-09-16 15:09:22 -0700770 if (audio) {
771 mSkipRenderingAudioUntilMediaTimeUs = -1;
772 } else {
773 mSkipRenderingVideoUntilMediaTimeUs = -1;
774 }
Andreas Huber32f3cef2011-03-02 15:34:46 -0800775
Andreas Huber6e3d3112011-11-28 12:36:11 -0800776 if (timeChange) {
777 sp<AMessage> extra;
778 if (accessUnit->meta()->findMessage("extra", &extra)
779 && extra != NULL) {
780 int64_t resumeAtMediaTimeUs;
781 if (extra->findInt64(
782 "resume-at-mediatimeUs", &resumeAtMediaTimeUs)) {
Steve Blockdf64d152012-01-04 20:05:49 +0000783 ALOGI("suppressing rendering of %s until %lld us",
Andreas Huber6e3d3112011-11-28 12:36:11 -0800784 audio ? "audio" : "video", resumeAtMediaTimeUs);
Andreas Huber3fe62152011-09-16 15:09:22 -0700785
Andreas Huber6e3d3112011-11-28 12:36:11 -0800786 if (audio) {
787 mSkipRenderingAudioUntilMediaTimeUs =
788 resumeAtMediaTimeUs;
789 } else {
790 mSkipRenderingVideoUntilMediaTimeUs =
791 resumeAtMediaTimeUs;
792 }
Andreas Huber3fe62152011-09-16 15:09:22 -0700793 }
Andreas Huber32f3cef2011-03-02 15:34:46 -0800794 }
795 }
Andreas Huber3fe62152011-09-16 15:09:22 -0700796
Andreas Huber6e3d3112011-11-28 12:36:11 -0800797 mTimeDiscontinuityPending =
798 mTimeDiscontinuityPending || timeChange;
799
800 if (formatChange || timeChange) {
801 flushDecoder(audio, formatChange);
802 } else {
803 // This stream is unaffected by the discontinuity
804
805 if (audio) {
806 mFlushingAudio = FLUSHED;
807 } else {
808 mFlushingVideo = FLUSHED;
809 }
810
811 finishFlushIfPossible();
812
813 return -EWOULDBLOCK;
814 }
Andreas Huber32f3cef2011-03-02 15:34:46 -0800815 }
816
Andreas Huber3fe62152011-09-16 15:09:22 -0700817 reply->setInt32("err", err);
818 reply->post();
819 return OK;
Andreas Huberf9334412010-12-15 15:17:42 -0800820 }
821
Andreas Huber3fe62152011-09-16 15:09:22 -0700822 if (!audio) {
823 ++mNumFramesTotal;
824 }
825
826 dropAccessUnit = false;
827 if (!audio
828 && mVideoLateByUs > 100000ll
829 && mVideoIsAVC
830 && !IsAVCReferenceFrame(accessUnit)) {
831 dropAccessUnit = true;
832 ++mNumFramesDropped;
833 }
834 } while (dropAccessUnit);
Andreas Huberf9334412010-12-15 15:17:42 -0800835
Steve Block3856b092011-10-20 11:56:00 +0100836 // ALOGV("returned a valid buffer of %s data", audio ? "audio" : "video");
Andreas Huberf9334412010-12-15 15:17:42 -0800837
838#if 0
839 int64_t mediaTimeUs;
840 CHECK(accessUnit->meta()->findInt64("timeUs", &mediaTimeUs));
Steve Block3856b092011-10-20 11:56:00 +0100841 ALOGV("feeding %s input buffer at media time %.2f secs",
Andreas Huberf9334412010-12-15 15:17:42 -0800842 audio ? "audio" : "video",
843 mediaTimeUs / 1E6);
844#endif
845
Andreas Huber2d8bedd2012-02-21 14:38:23 -0800846 reply->setBuffer("buffer", accessUnit);
Andreas Huberf9334412010-12-15 15:17:42 -0800847 reply->post();
848
849 return OK;
850}
851
852void NuPlayer::renderBuffer(bool audio, const sp<AMessage> &msg) {
Steve Block3856b092011-10-20 11:56:00 +0100853 // ALOGV("renderBuffer %s", audio ? "audio" : "video");
Andreas Huberf9334412010-12-15 15:17:42 -0800854
855 sp<AMessage> reply;
856 CHECK(msg->findMessage("reply", &reply));
857
Andreas Huber18ac5402011-08-31 15:04:25 -0700858 if (IsFlushingState(audio ? mFlushingAudio : mFlushingVideo)) {
859 // We're currently attempting to flush the decoder, in order
860 // to complete this, the decoder wants all its buffers back,
861 // so we don't want any output buffers it sent us (from before
862 // we initiated the flush) to be stuck in the renderer's queue.
863
Steve Block3856b092011-10-20 11:56:00 +0100864 ALOGV("we're still flushing the %s decoder, sending its output buffer"
Andreas Huber18ac5402011-08-31 15:04:25 -0700865 " right back.", audio ? "audio" : "video");
866
867 reply->post();
868 return;
869 }
870
Andreas Huber2d8bedd2012-02-21 14:38:23 -0800871 sp<ABuffer> buffer;
872 CHECK(msg->findBuffer("buffer", &buffer));
Andreas Huberf9334412010-12-15 15:17:42 -0800873
Andreas Huber32f3cef2011-03-02 15:34:46 -0800874 int64_t &skipUntilMediaTimeUs =
875 audio
876 ? mSkipRenderingAudioUntilMediaTimeUs
877 : mSkipRenderingVideoUntilMediaTimeUs;
878
879 if (skipUntilMediaTimeUs >= 0) {
880 int64_t mediaTimeUs;
881 CHECK(buffer->meta()->findInt64("timeUs", &mediaTimeUs));
882
883 if (mediaTimeUs < skipUntilMediaTimeUs) {
Steve Block3856b092011-10-20 11:56:00 +0100884 ALOGV("dropping %s buffer at time %lld as requested.",
Andreas Huber32f3cef2011-03-02 15:34:46 -0800885 audio ? "audio" : "video",
886 mediaTimeUs);
887
888 reply->post();
889 return;
890 }
891
892 skipUntilMediaTimeUs = -1;
893 }
894
Marco Nelissen4110c102012-03-29 09:31:28 -0700895 if (audio && mSkipCutBuffer) {
896 mSkipCutBuffer->submit(buffer);
897 }
898
Andreas Huberf9334412010-12-15 15:17:42 -0800899 mRenderer->queueBuffer(audio, buffer, reply);
900}
901
902void NuPlayer::notifyListener(int msg, int ext1, int ext2) {
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800903 if (mDriver == NULL) {
Andreas Huberf9334412010-12-15 15:17:42 -0800904 return;
905 }
906
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800907 sp<NuPlayerDriver> driver = mDriver.promote();
Andreas Huberf9334412010-12-15 15:17:42 -0800908
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800909 if (driver == NULL) {
Andreas Huberf9334412010-12-15 15:17:42 -0800910 return;
911 }
912
Andreas Hubera4af2142011-10-26 15:23:31 -0700913 driver->notifyListener(msg, ext1, ext2);
Andreas Huberf9334412010-12-15 15:17:42 -0800914}
915
Andreas Huber1aef2112011-01-04 14:01:29 -0800916void NuPlayer::flushDecoder(bool audio, bool needShutdown) {
Andreas Huber6e3d3112011-11-28 12:36:11 -0800917 if ((audio && mAudioDecoder == NULL) || (!audio && mVideoDecoder == NULL)) {
Steve Blockdf64d152012-01-04 20:05:49 +0000918 ALOGI("flushDecoder %s without decoder present",
Andreas Huber6e3d3112011-11-28 12:36:11 -0800919 audio ? "audio" : "video");
920 }
921
Andreas Huber1aef2112011-01-04 14:01:29 -0800922 // Make sure we don't continue to scan sources until we finish flushing.
923 ++mScanSourcesGeneration;
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800924 mScanSourcesPending = false;
Andreas Huber1aef2112011-01-04 14:01:29 -0800925
926 (audio ? mAudioDecoder : mVideoDecoder)->signalFlush();
927 mRenderer->flush(audio);
928
929 FlushStatus newStatus =
930 needShutdown ? FLUSHING_DECODER_SHUTDOWN : FLUSHING_DECODER;
931
932 if (audio) {
933 CHECK(mFlushingAudio == NONE
934 || mFlushingAudio == AWAITING_DISCONTINUITY);
935
936 mFlushingAudio = newStatus;
937
938 if (mFlushingVideo == NONE) {
939 mFlushingVideo = (mVideoDecoder != NULL)
940 ? AWAITING_DISCONTINUITY
941 : FLUSHED;
942 }
943 } else {
944 CHECK(mFlushingVideo == NONE
945 || mFlushingVideo == AWAITING_DISCONTINUITY);
946
947 mFlushingVideo = newStatus;
948
949 if (mFlushingAudio == NONE) {
950 mFlushingAudio = (mAudioDecoder != NULL)
951 ? AWAITING_DISCONTINUITY
952 : FLUSHED;
953 }
954 }
955}
956
Andreas Huberf9334412010-12-15 15:17:42 -0800957} // namespace android