blob: a02732b0655f096a2f36185587fe45fcc44dd3c6 [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 Huber84066782011-08-16 09:34:26 -070031#include "mp4/MP4Source.h"
Andreas Huber5bc087c2010-12-23 10:27:40 -080032
33#include "ATSParser.h"
Andreas Huberf9334412010-12-15 15:17:42 -080034
Andreas Huber84066782011-08-16 09:34:26 -070035#include <cutils/properties.h> // for property_get
Andreas Huber3831a062010-12-21 10:22:33 -080036#include <media/stagefright/foundation/hexdump.h>
Andreas Huberf9334412010-12-15 15:17:42 -080037#include <media/stagefright/foundation/ABuffer.h>
38#include <media/stagefright/foundation/ADebug.h>
39#include <media/stagefright/foundation/AMessage.h>
40#include <media/stagefright/ACodec.h>
Andreas Huber3fe62152011-09-16 15:09:22 -070041#include <media/stagefright/MediaDefs.h>
Andreas Huberf9334412010-12-15 15:17:42 -080042#include <media/stagefright/MediaErrors.h>
43#include <media/stagefright/MetaData.h>
Glenn Kasten11731182011-02-08 17:26:17 -080044#include <gui/ISurfaceTexture.h>
Andreas Huberf9334412010-12-15 15:17:42 -080045
Andreas Huber3fe62152011-09-16 15:09:22 -070046#include "avc_utils.h"
47
Andreas Huber84066782011-08-16 09:34:26 -070048#include "ESDS.h"
49#include <media/stagefright/Utils.h>
50
Andreas Huberf9334412010-12-15 15:17:42 -080051namespace android {
52
53////////////////////////////////////////////////////////////////////////////////
54
55NuPlayer::NuPlayer()
Andreas Huber9b80c2b2011-06-30 15:47:02 -070056 : mUIDValid(false),
Andreas Huber3fe62152011-09-16 15:09:22 -070057 mVideoIsAVC(false),
Andreas Huber9b80c2b2011-06-30 15:47:02 -070058 mAudioEOS(false),
Andreas Huberf9334412010-12-15 15:17:42 -080059 mVideoEOS(false),
Andreas Huber5bc087c2010-12-23 10:27:40 -080060 mScanSourcesPending(false),
Andreas Huber1aef2112011-01-04 14:01:29 -080061 mScanSourcesGeneration(0),
Andreas Huber6e3d3112011-11-28 12:36:11 -080062 mTimeDiscontinuityPending(false),
Andreas Huberf9334412010-12-15 15:17:42 -080063 mFlushingAudio(NONE),
Andreas Huber1aef2112011-01-04 14:01:29 -080064 mFlushingVideo(NONE),
65 mResetInProgress(false),
Andreas Huber3fe62152011-09-16 15:09:22 -070066 mResetPostponed(false),
67 mSkipRenderingAudioUntilMediaTimeUs(-1ll),
68 mSkipRenderingVideoUntilMediaTimeUs(-1ll),
69 mVideoLateByUs(0ll),
70 mNumFramesTotal(0ll),
Marco Nelissen8b712412012-04-27 09:33:24 -070071 mNumFramesDropped(0ll) {
Andreas Huberf9334412010-12-15 15:17:42 -080072}
73
74NuPlayer::~NuPlayer() {
75}
76
Andreas Huber9b80c2b2011-06-30 15:47:02 -070077void NuPlayer::setUID(uid_t uid) {
78 mUIDValid = true;
79 mUID = uid;
80}
81
Andreas Huber43c3e6c2011-01-05 12:17:08 -080082void NuPlayer::setDriver(const wp<NuPlayerDriver> &driver) {
83 mDriver = driver;
Andreas Huberf9334412010-12-15 15:17:42 -080084}
85
86void NuPlayer::setDataSource(const sp<IStreamSource> &source) {
87 sp<AMessage> msg = new AMessage(kWhatSetDataSource, id());
88
Andreas Huber84066782011-08-16 09:34:26 -070089 char prop[PROPERTY_VALUE_MAX];
90 if (property_get("media.stagefright.use-mp4source", prop, NULL)
91 && (!strcmp(prop, "1") || !strcasecmp(prop, "true"))) {
92 msg->setObject("source", new MP4Source(source));
93 } else {
94 msg->setObject("source", new StreamingSource(source));
95 }
96
Andreas Huber5bc087c2010-12-23 10:27:40 -080097 msg->post();
98}
Andreas Huberf9334412010-12-15 15:17:42 -080099
Andreas Huberafed0e12011-09-20 15:39:58 -0700100static bool IsHTTPLiveURL(const char *url) {
101 if (!strncasecmp("http://", url, 7)
102 || !strncasecmp("https://", url, 8)) {
103 size_t len = strlen(url);
104 if (len >= 5 && !strcasecmp(".m3u8", &url[len - 5])) {
105 return true;
106 }
107
108 if (strstr(url,"m3u8")) {
109 return true;
110 }
111 }
112
113 return false;
114}
115
Andreas Huber5bc087c2010-12-23 10:27:40 -0800116void NuPlayer::setDataSource(
117 const char *url, const KeyedVector<String8, String8> *headers) {
118 sp<AMessage> msg = new AMessage(kWhatSetDataSource, id());
119
Andreas Huberafed0e12011-09-20 15:39:58 -0700120 sp<Source> source;
121 if (IsHTTPLiveURL(url)) {
122 source = new HTTPLiveSource(url, headers, mUIDValid, mUID);
123 } else if (!strncasecmp(url, "rtsp://", 7)) {
124 source = new RTSPSource(url, headers, mUIDValid, mUID);
Andreas Huber2bfdd422011-10-11 15:24:07 -0700125 } else {
Andreas Huberafed0e12011-09-20 15:39:58 -0700126 source = new GenericSource(url, headers, mUIDValid, mUID);
Andreas Huber2bfdd422011-10-11 15:24:07 -0700127 }
128
Andreas Huberafed0e12011-09-20 15:39:58 -0700129 msg->setObject("source", source);
130 msg->post();
131}
132
133void NuPlayer::setDataSource(int fd, int64_t offset, int64_t length) {
134 sp<AMessage> msg = new AMessage(kWhatSetDataSource, id());
135
136 sp<Source> source = new GenericSource(fd, offset, length);
137 msg->setObject("source", source);
Andreas Huberf9334412010-12-15 15:17:42 -0800138 msg->post();
139}
140
Glenn Kasten11731182011-02-08 17:26:17 -0800141void NuPlayer::setVideoSurfaceTexture(const sp<ISurfaceTexture> &surfaceTexture) {
142 sp<AMessage> msg = new AMessage(kWhatSetVideoNativeWindow, id());
143 sp<SurfaceTextureClient> surfaceTextureClient(surfaceTexture != NULL ?
144 new SurfaceTextureClient(surfaceTexture) : NULL);
145 msg->setObject("native-window", new NativeWindowWrapper(surfaceTextureClient));
Andreas Huberf9334412010-12-15 15:17:42 -0800146 msg->post();
147}
148
149void NuPlayer::setAudioSink(const sp<MediaPlayerBase::AudioSink> &sink) {
150 sp<AMessage> msg = new AMessage(kWhatSetAudioSink, id());
151 msg->setObject("sink", sink);
152 msg->post();
153}
154
155void NuPlayer::start() {
156 (new AMessage(kWhatStart, id()))->post();
157}
158
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800159void NuPlayer::pause() {
Andreas Huberb4082222011-01-20 15:23:04 -0800160 (new AMessage(kWhatPause, id()))->post();
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800161}
162
163void NuPlayer::resume() {
Andreas Huberb4082222011-01-20 15:23:04 -0800164 (new AMessage(kWhatResume, id()))->post();
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800165}
166
Andreas Huber1aef2112011-01-04 14:01:29 -0800167void NuPlayer::resetAsync() {
168 (new AMessage(kWhatReset, id()))->post();
169}
170
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800171void NuPlayer::seekToAsync(int64_t seekTimeUs) {
172 sp<AMessage> msg = new AMessage(kWhatSeek, id());
173 msg->setInt64("seekTimeUs", seekTimeUs);
174 msg->post();
175}
176
Andreas Huber53df1a42010-12-22 10:03:04 -0800177// static
Andreas Huber1aef2112011-01-04 14:01:29 -0800178bool NuPlayer::IsFlushingState(FlushStatus state, bool *needShutdown) {
Andreas Huber53df1a42010-12-22 10:03:04 -0800179 switch (state) {
180 case FLUSHING_DECODER:
Andreas Huber1aef2112011-01-04 14:01:29 -0800181 if (needShutdown != NULL) {
182 *needShutdown = false;
Andreas Huber53df1a42010-12-22 10:03:04 -0800183 }
184 return true;
185
Andreas Huber1aef2112011-01-04 14:01:29 -0800186 case FLUSHING_DECODER_SHUTDOWN:
187 if (needShutdown != NULL) {
188 *needShutdown = true;
Andreas Huber53df1a42010-12-22 10:03:04 -0800189 }
190 return true;
191
192 default:
193 return false;
194 }
195}
196
Andreas Huberf9334412010-12-15 15:17:42 -0800197void NuPlayer::onMessageReceived(const sp<AMessage> &msg) {
198 switch (msg->what()) {
199 case kWhatSetDataSource:
200 {
Steve Block3856b092011-10-20 11:56:00 +0100201 ALOGV("kWhatSetDataSource");
Andreas Huberf9334412010-12-15 15:17:42 -0800202
203 CHECK(mSource == NULL);
204
Andreas Huber5bc087c2010-12-23 10:27:40 -0800205 sp<RefBase> obj;
206 CHECK(msg->findObject("source", &obj));
Andreas Huberf9334412010-12-15 15:17:42 -0800207
Andreas Huber5bc087c2010-12-23 10:27:40 -0800208 mSource = static_cast<Source *>(obj.get());
Andreas Huberf9334412010-12-15 15:17:42 -0800209 break;
210 }
211
Glenn Kasten11731182011-02-08 17:26:17 -0800212 case kWhatSetVideoNativeWindow:
Andreas Huberf9334412010-12-15 15:17:42 -0800213 {
Steve Block3856b092011-10-20 11:56:00 +0100214 ALOGV("kWhatSetVideoNativeWindow");
Andreas Huberf9334412010-12-15 15:17:42 -0800215
216 sp<RefBase> obj;
Glenn Kasten11731182011-02-08 17:26:17 -0800217 CHECK(msg->findObject("native-window", &obj));
Andreas Huberf9334412010-12-15 15:17:42 -0800218
Glenn Kasten11731182011-02-08 17:26:17 -0800219 mNativeWindow = static_cast<NativeWindowWrapper *>(obj.get());
Andreas Huberf9334412010-12-15 15:17:42 -0800220 break;
221 }
222
223 case kWhatSetAudioSink:
224 {
Steve Block3856b092011-10-20 11:56:00 +0100225 ALOGV("kWhatSetAudioSink");
Andreas Huberf9334412010-12-15 15:17:42 -0800226
227 sp<RefBase> obj;
228 CHECK(msg->findObject("sink", &obj));
229
230 mAudioSink = static_cast<MediaPlayerBase::AudioSink *>(obj.get());
231 break;
232 }
233
234 case kWhatStart:
235 {
Steve Block3856b092011-10-20 11:56:00 +0100236 ALOGV("kWhatStart");
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800237
Andreas Huber3fe62152011-09-16 15:09:22 -0700238 mVideoIsAVC = false;
Andreas Huber1aef2112011-01-04 14:01:29 -0800239 mAudioEOS = false;
240 mVideoEOS = false;
Andreas Huber32f3cef2011-03-02 15:34:46 -0800241 mSkipRenderingAudioUntilMediaTimeUs = -1;
242 mSkipRenderingVideoUntilMediaTimeUs = -1;
Andreas Huber3fe62152011-09-16 15:09:22 -0700243 mVideoLateByUs = 0;
244 mNumFramesTotal = 0;
245 mNumFramesDropped = 0;
Andreas Huber1aef2112011-01-04 14:01:29 -0800246
Andreas Huber5bc087c2010-12-23 10:27:40 -0800247 mSource->start();
Andreas Huberf9334412010-12-15 15:17:42 -0800248
249 mRenderer = new Renderer(
250 mAudioSink,
251 new AMessage(kWhatRendererNotify, id()));
252
253 looper()->registerHandler(mRenderer);
254
Andreas Huber1aef2112011-01-04 14:01:29 -0800255 postScanSources();
Andreas Huberf9334412010-12-15 15:17:42 -0800256 break;
257 }
258
259 case kWhatScanSources:
260 {
Andreas Huber1aef2112011-01-04 14:01:29 -0800261 int32_t generation;
262 CHECK(msg->findInt32("generation", &generation));
263 if (generation != mScanSourcesGeneration) {
264 // Drop obsolete msg.
265 break;
266 }
267
Andreas Huber5bc087c2010-12-23 10:27:40 -0800268 mScanSourcesPending = false;
269
Steve Block3856b092011-10-20 11:56:00 +0100270 ALOGV("scanning sources haveAudio=%d, haveVideo=%d",
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800271 mAudioDecoder != NULL, mVideoDecoder != NULL);
272
Haynes Mathew George5d246ef2012-07-09 10:36:57 -0700273 if (mNativeWindow != NULL) {
274 instantiateDecoder(false, &mVideoDecoder);
275 }
Andreas Huberf9334412010-12-15 15:17:42 -0800276
277 if (mAudioSink != NULL) {
Andreas Huber5bc087c2010-12-23 10:27:40 -0800278 instantiateDecoder(true, &mAudioDecoder);
Andreas Huberf9334412010-12-15 15:17:42 -0800279 }
280
Andreas Hubereac68ba2011-09-27 12:12:25 -0700281 status_t err;
282 if ((err = mSource->feedMoreTSData()) != OK) {
Andreas Huber1aef2112011-01-04 14:01:29 -0800283 if (mAudioDecoder == NULL && mVideoDecoder == NULL) {
284 // We're not currently decoding anything (no audio or
285 // video tracks found) and we just ran out of input data.
Andreas Hubereac68ba2011-09-27 12:12:25 -0700286
287 if (err == ERROR_END_OF_STREAM) {
288 notifyListener(MEDIA_PLAYBACK_COMPLETE, 0, 0);
289 } else {
290 notifyListener(MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, err);
291 }
Andreas Huber1aef2112011-01-04 14:01:29 -0800292 }
Andreas Huberf9334412010-12-15 15:17:42 -0800293 break;
294 }
295
Haynes Mathew George5d246ef2012-07-09 10:36:57 -0700296 if (mAudioDecoder == NULL && mAudioSink != NULL ||
297 mVideoDecoder == NULL && mNativeWindow != NULL) {
Andreas Huberf9334412010-12-15 15:17:42 -0800298 msg->post(100000ll);
Andreas Huber5bc087c2010-12-23 10:27:40 -0800299 mScanSourcesPending = true;
Andreas Huberf9334412010-12-15 15:17:42 -0800300 }
301 break;
302 }
303
304 case kWhatVideoNotify:
305 case kWhatAudioNotify:
306 {
307 bool audio = msg->what() == kWhatAudioNotify;
308
309 sp<AMessage> codecRequest;
310 CHECK(msg->findMessage("codec-request", &codecRequest));
311
312 int32_t what;
313 CHECK(codecRequest->findInt32("what", &what));
314
315 if (what == ACodec::kWhatFillThisBuffer) {
316 status_t err = feedDecoderInputData(
317 audio, codecRequest);
318
Andreas Huber5bc087c2010-12-23 10:27:40 -0800319 if (err == -EWOULDBLOCK) {
Andreas Hubereac68ba2011-09-27 12:12:25 -0700320 if (mSource->feedMoreTSData() == OK) {
Andreas Huber1183a4a2011-11-03 11:00:21 -0700321 msg->post(10000ll);
Andreas Huber5bc087c2010-12-23 10:27:40 -0800322 }
Andreas Huberf9334412010-12-15 15:17:42 -0800323 }
324 } else if (what == ACodec::kWhatEOS) {
Andreas Huberdc9bacd2011-09-26 10:53:29 -0700325 int32_t err;
326 CHECK(codecRequest->findInt32("err", &err));
327
328 if (err == ERROR_END_OF_STREAM) {
Steve Block3856b092011-10-20 11:56:00 +0100329 ALOGV("got %s decoder EOS", audio ? "audio" : "video");
Andreas Huberdc9bacd2011-09-26 10:53:29 -0700330 } else {
Steve Block3856b092011-10-20 11:56:00 +0100331 ALOGV("got %s decoder EOS w/ error %d",
Andreas Huberdc9bacd2011-09-26 10:53:29 -0700332 audio ? "audio" : "video",
333 err);
334 }
335
336 mRenderer->queueEOS(audio, err);
Andreas Huberf9334412010-12-15 15:17:42 -0800337 } else if (what == ACodec::kWhatFlushCompleted) {
Andreas Huber1aef2112011-01-04 14:01:29 -0800338 bool needShutdown;
Andreas Huber53df1a42010-12-22 10:03:04 -0800339
Andreas Huberf9334412010-12-15 15:17:42 -0800340 if (audio) {
Andreas Huber1aef2112011-01-04 14:01:29 -0800341 CHECK(IsFlushingState(mFlushingAudio, &needShutdown));
Andreas Huberf9334412010-12-15 15:17:42 -0800342 mFlushingAudio = FLUSHED;
343 } else {
Andreas Huber1aef2112011-01-04 14:01:29 -0800344 CHECK(IsFlushingState(mFlushingVideo, &needShutdown));
Andreas Huberf9334412010-12-15 15:17:42 -0800345 mFlushingVideo = FLUSHED;
Andreas Huber3fe62152011-09-16 15:09:22 -0700346
347 mVideoLateByUs = 0;
Andreas Huberf9334412010-12-15 15:17:42 -0800348 }
349
Steve Block3856b092011-10-20 11:56:00 +0100350 ALOGV("decoder %s flush completed", audio ? "audio" : "video");
Andreas Huberf9334412010-12-15 15:17:42 -0800351
Andreas Huber1aef2112011-01-04 14:01:29 -0800352 if (needShutdown) {
Steve Block3856b092011-10-20 11:56:00 +0100353 ALOGV("initiating %s decoder shutdown",
Andreas Huber53df1a42010-12-22 10:03:04 -0800354 audio ? "audio" : "video");
Andreas Huberf9334412010-12-15 15:17:42 -0800355
Andreas Huber53df1a42010-12-22 10:03:04 -0800356 (audio ? mAudioDecoder : mVideoDecoder)->initiateShutdown();
Andreas Huberf9334412010-12-15 15:17:42 -0800357
Andreas Huber53df1a42010-12-22 10:03:04 -0800358 if (audio) {
359 mFlushingAudio = SHUTTING_DOWN_DECODER;
360 } else {
361 mFlushingVideo = SHUTTING_DOWN_DECODER;
362 }
Andreas Huberf9334412010-12-15 15:17:42 -0800363 }
Andreas Huber3831a062010-12-21 10:22:33 -0800364
365 finishFlushIfPossible();
Andreas Huber2c2814b2010-12-15 17:18:20 -0800366 } else if (what == ACodec::kWhatOutputFormatChanged) {
Andreas Huber31e25082011-01-10 10:38:31 -0800367 if (audio) {
368 int32_t numChannels;
369 CHECK(codecRequest->findInt32("channel-count", &numChannels));
Andreas Huber2c2814b2010-12-15 17:18:20 -0800370
Andreas Huber31e25082011-01-10 10:38:31 -0800371 int32_t sampleRate;
372 CHECK(codecRequest->findInt32("sample-rate", &sampleRate));
Andreas Huber2c2814b2010-12-15 17:18:20 -0800373
Steve Block3856b092011-10-20 11:56:00 +0100374 ALOGV("Audio output format changed to %d Hz, %d channels",
Andreas Huber31e25082011-01-10 10:38:31 -0800375 sampleRate, numChannels);
Andreas Huber2c2814b2010-12-15 17:18:20 -0800376
Andreas Huber31e25082011-01-10 10:38:31 -0800377 mAudioSink->close();
Eric Laurent1948eb32012-04-13 16:50:19 -0700378
379 audio_output_flags_t flags;
380 int64_t durationUs;
381 // FIXME: we should handle the case where the video decoder is created after
382 // we receive the format change indication. Current code will just make that
383 // we select deep buffer with video which should not be a problem as it should
384 // not prevent from keeping A/V sync.
385 if (mVideoDecoder == NULL &&
386 mSource->getDuration(&durationUs) == OK &&
387 durationUs > AUDIO_SINK_MIN_DEEP_BUFFER_DURATION_US) {
388 flags = AUDIO_OUTPUT_FLAG_DEEP_BUFFER;
389 } else {
390 flags = AUDIO_OUTPUT_FLAG_NONE;
391 }
392
Andreas Huber98065552012-05-03 11:33:01 -0700393 int32_t channelMask;
394 if (!codecRequest->findInt32("channel-mask", &channelMask)) {
395 channelMask = CHANNEL_MASK_USE_CHANNEL_ORDER;
396 }
397
Andreas Huber078cfcf2011-09-15 12:25:04 -0700398 CHECK_EQ(mAudioSink->open(
399 sampleRate,
400 numChannels,
Andreas Huber98065552012-05-03 11:33:01 -0700401 (audio_channel_mask_t)channelMask,
Andreas Huber078cfcf2011-09-15 12:25:04 -0700402 AUDIO_FORMAT_PCM_16_BIT,
Eric Laurent1948eb32012-04-13 16:50:19 -0700403 8 /* bufferCount */,
404 NULL,
405 NULL,
406 flags),
Andreas Huber078cfcf2011-09-15 12:25:04 -0700407 (status_t)OK);
Andreas Huber31e25082011-01-10 10:38:31 -0800408 mAudioSink->start();
Andreas Huber2c2814b2010-12-15 17:18:20 -0800409
Andreas Huber31e25082011-01-10 10:38:31 -0800410 mRenderer->signalAudioSinkChanged();
411 } else {
412 // video
Andreas Huber3831a062010-12-21 10:22:33 -0800413
Andreas Huber31e25082011-01-10 10:38:31 -0800414 int32_t width, height;
415 CHECK(codecRequest->findInt32("width", &width));
416 CHECK(codecRequest->findInt32("height", &height));
417
418 int32_t cropLeft, cropTop, cropRight, cropBottom;
419 CHECK(codecRequest->findRect(
420 "crop",
421 &cropLeft, &cropTop, &cropRight, &cropBottom));
422
Steve Block3856b092011-10-20 11:56:00 +0100423 ALOGV("Video output format changed to %d x %d "
Andreas Hubercb67cd12011-08-26 16:02:19 -0700424 "(crop: %d x %d @ (%d, %d))",
Andreas Huber31e25082011-01-10 10:38:31 -0800425 width, height,
Andreas Hubercb67cd12011-08-26 16:02:19 -0700426 (cropRight - cropLeft + 1),
427 (cropBottom - cropTop + 1),
428 cropLeft, cropTop);
Andreas Huber31e25082011-01-10 10:38:31 -0800429
430 notifyListener(
431 MEDIA_SET_VIDEO_SIZE,
432 cropRight - cropLeft + 1,
433 cropBottom - cropTop + 1);
434 }
Andreas Huber3831a062010-12-21 10:22:33 -0800435 } else if (what == ACodec::kWhatShutdownCompleted) {
Steve Block3856b092011-10-20 11:56:00 +0100436 ALOGV("%s shutdown completed", audio ? "audio" : "video");
Andreas Huber3831a062010-12-21 10:22:33 -0800437 if (audio) {
438 mAudioDecoder.clear();
439
440 CHECK_EQ((int)mFlushingAudio, (int)SHUTTING_DOWN_DECODER);
441 mFlushingAudio = SHUT_DOWN;
442 } else {
443 mVideoDecoder.clear();
444
445 CHECK_EQ((int)mFlushingVideo, (int)SHUTTING_DOWN_DECODER);
446 mFlushingVideo = SHUT_DOWN;
447 }
448
449 finishFlushIfPossible();
Andreas Huberc92fd242011-08-16 13:48:44 -0700450 } else if (what == ACodec::kWhatError) {
Steve Block29357bc2012-01-06 19:20:56 +0000451 ALOGE("Received error from %s decoder, aborting playback.",
Andreas Huberc92fd242011-08-16 13:48:44 -0700452 audio ? "audio" : "video");
453
454 mRenderer->queueEOS(audio, UNKNOWN_ERROR);
Andreas Huber57788222012-02-21 11:47:18 -0800455 } else if (what == ACodec::kWhatDrainThisBuffer) {
Andreas Huberf9334412010-12-15 15:17:42 -0800456 renderBuffer(audio, codecRequest);
Andreas Huber57788222012-02-21 11:47:18 -0800457 } else {
458 ALOGV("Unhandled codec notification %d.", what);
Andreas Huberf9334412010-12-15 15:17:42 -0800459 }
460
461 break;
462 }
463
464 case kWhatRendererNotify:
465 {
466 int32_t what;
467 CHECK(msg->findInt32("what", &what));
468
469 if (what == Renderer::kWhatEOS) {
470 int32_t audio;
471 CHECK(msg->findInt32("audio", &audio));
472
Andreas Huberc92fd242011-08-16 13:48:44 -0700473 int32_t finalResult;
474 CHECK(msg->findInt32("finalResult", &finalResult));
475
Andreas Huberf9334412010-12-15 15:17:42 -0800476 if (audio) {
477 mAudioEOS = true;
478 } else {
479 mVideoEOS = true;
480 }
481
Andreas Huberc92fd242011-08-16 13:48:44 -0700482 if (finalResult == ERROR_END_OF_STREAM) {
Steve Block3856b092011-10-20 11:56:00 +0100483 ALOGV("reached %s EOS", audio ? "audio" : "video");
Andreas Huberc92fd242011-08-16 13:48:44 -0700484 } else {
Steve Block29357bc2012-01-06 19:20:56 +0000485 ALOGE("%s track encountered an error (%d)",
Andreas Huberc92fd242011-08-16 13:48:44 -0700486 audio ? "audio" : "video", finalResult);
487
488 notifyListener(
489 MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, finalResult);
490 }
Andreas Huberf9334412010-12-15 15:17:42 -0800491
492 if ((mAudioEOS || mAudioDecoder == NULL)
493 && (mVideoEOS || mVideoDecoder == NULL)) {
494 notifyListener(MEDIA_PLAYBACK_COMPLETE, 0, 0);
495 }
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800496 } else if (what == Renderer::kWhatPosition) {
497 int64_t positionUs;
498 CHECK(msg->findInt64("positionUs", &positionUs));
499
Andreas Huber3fe62152011-09-16 15:09:22 -0700500 CHECK(msg->findInt64("videoLateByUs", &mVideoLateByUs));
501
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800502 if (mDriver != NULL) {
503 sp<NuPlayerDriver> driver = mDriver.promote();
504 if (driver != NULL) {
505 driver->notifyPosition(positionUs);
Andreas Huber3fe62152011-09-16 15:09:22 -0700506
507 driver->notifyFrameStats(
508 mNumFramesTotal, mNumFramesDropped);
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800509 }
510 }
Andreas Huber3fe62152011-09-16 15:09:22 -0700511 } else if (what == Renderer::kWhatFlushComplete) {
Andreas Huberf9334412010-12-15 15:17:42 -0800512 CHECK_EQ(what, (int32_t)Renderer::kWhatFlushComplete);
513
514 int32_t audio;
515 CHECK(msg->findInt32("audio", &audio));
516
Steve Block3856b092011-10-20 11:56:00 +0100517 ALOGV("renderer %s flush completed.", audio ? "audio" : "video");
James Dongf57b4ea2012-07-20 13:38:36 -0700518 } else if (what == Renderer::kWhatVideoRenderingStart) {
519 notifyListener(MEDIA_INFO, MEDIA_INFO_RENDERING_START, 0);
Andreas Huberf9334412010-12-15 15:17:42 -0800520 }
521 break;
522 }
523
524 case kWhatMoreDataQueued:
525 {
526 break;
527 }
528
Andreas Huber1aef2112011-01-04 14:01:29 -0800529 case kWhatReset:
530 {
Steve Block3856b092011-10-20 11:56:00 +0100531 ALOGV("kWhatReset");
Andreas Huber1aef2112011-01-04 14:01:29 -0800532
Andreas Huberb58ce9f2011-11-28 16:27:35 -0800533 if (mRenderer != NULL) {
534 // There's an edge case where the renderer owns all output
535 // buffers and is paused, therefore the decoder will not read
536 // more input data and will never encounter the matching
537 // discontinuity. To avoid this, we resume the renderer.
538
539 if (mFlushingAudio == AWAITING_DISCONTINUITY
540 || mFlushingVideo == AWAITING_DISCONTINUITY) {
541 mRenderer->resume();
542 }
543 }
544
Andreas Huber1aef2112011-01-04 14:01:29 -0800545 if (mFlushingAudio != NONE || mFlushingVideo != NONE) {
546 // We're currently flushing, postpone the reset until that's
547 // completed.
548
Andreas Huberea9d51b2011-11-30 09:53:40 -0800549 ALOGV("postponing reset mFlushingAudio=%d, mFlushingVideo=%d",
550 mFlushingAudio, mFlushingVideo);
Andreas Huber1aef2112011-01-04 14:01:29 -0800551
552 mResetPostponed = true;
553 break;
554 }
555
556 if (mAudioDecoder == NULL && mVideoDecoder == NULL) {
557 finishReset();
558 break;
559 }
560
Andreas Huber6e3d3112011-11-28 12:36:11 -0800561 mTimeDiscontinuityPending = true;
562
Andreas Huber1aef2112011-01-04 14:01:29 -0800563 if (mAudioDecoder != NULL) {
564 flushDecoder(true /* audio */, true /* needShutdown */);
565 }
566
567 if (mVideoDecoder != NULL) {
568 flushDecoder(false /* audio */, true /* needShutdown */);
569 }
570
571 mResetInProgress = true;
572 break;
573 }
574
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800575 case kWhatSeek:
576 {
577 int64_t seekTimeUs;
578 CHECK(msg->findInt64("seekTimeUs", &seekTimeUs));
579
Steve Block3856b092011-10-20 11:56:00 +0100580 ALOGV("kWhatSeek seekTimeUs=%lld us (%.2f secs)",
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800581 seekTimeUs, seekTimeUs / 1E6);
582
583 mSource->seekTo(seekTimeUs);
584
585 if (mDriver != NULL) {
586 sp<NuPlayerDriver> driver = mDriver.promote();
587 if (driver != NULL) {
588 driver->notifySeekComplete();
589 }
590 }
591
592 break;
593 }
594
Andreas Huberb4082222011-01-20 15:23:04 -0800595 case kWhatPause:
596 {
597 CHECK(mRenderer != NULL);
598 mRenderer->pause();
599 break;
600 }
601
602 case kWhatResume:
603 {
604 CHECK(mRenderer != NULL);
605 mRenderer->resume();
606 break;
607 }
608
Andreas Huberf9334412010-12-15 15:17:42 -0800609 default:
610 TRESPASS();
611 break;
612 }
613}
614
Andreas Huber3831a062010-12-21 10:22:33 -0800615void NuPlayer::finishFlushIfPossible() {
616 if (mFlushingAudio != FLUSHED && mFlushingAudio != SHUT_DOWN) {
617 return;
618 }
619
620 if (mFlushingVideo != FLUSHED && mFlushingVideo != SHUT_DOWN) {
621 return;
622 }
623
Steve Block3856b092011-10-20 11:56:00 +0100624 ALOGV("both audio and video are flushed now.");
Andreas Huber3831a062010-12-21 10:22:33 -0800625
Andreas Huber6e3d3112011-11-28 12:36:11 -0800626 if (mTimeDiscontinuityPending) {
627 mRenderer->signalTimeDiscontinuity();
628 mTimeDiscontinuityPending = false;
629 }
Andreas Huber3831a062010-12-21 10:22:33 -0800630
Andreas Huber22fc52f2011-01-05 16:24:27 -0800631 if (mAudioDecoder != NULL) {
Andreas Huber3831a062010-12-21 10:22:33 -0800632 mAudioDecoder->signalResume();
633 }
634
Andreas Huber22fc52f2011-01-05 16:24:27 -0800635 if (mVideoDecoder != NULL) {
Andreas Huber3831a062010-12-21 10:22:33 -0800636 mVideoDecoder->signalResume();
637 }
638
639 mFlushingAudio = NONE;
640 mFlushingVideo = NONE;
Andreas Huber3831a062010-12-21 10:22:33 -0800641
Andreas Huber1aef2112011-01-04 14:01:29 -0800642 if (mResetInProgress) {
Steve Block3856b092011-10-20 11:56:00 +0100643 ALOGV("reset completed");
Andreas Huber1aef2112011-01-04 14:01:29 -0800644
645 mResetInProgress = false;
646 finishReset();
647 } else if (mResetPostponed) {
648 (new AMessage(kWhatReset, id()))->post();
649 mResetPostponed = false;
Andreas Huber22fc52f2011-01-05 16:24:27 -0800650 } else if (mAudioDecoder == NULL || mVideoDecoder == NULL) {
Andreas Huber1aef2112011-01-04 14:01:29 -0800651 postScanSources();
Andreas Huberf9334412010-12-15 15:17:42 -0800652 }
653}
654
Andreas Huber1aef2112011-01-04 14:01:29 -0800655void NuPlayer::finishReset() {
656 CHECK(mAudioDecoder == NULL);
657 CHECK(mVideoDecoder == NULL);
658
Andreas Huber2bfdd422011-10-11 15:24:07 -0700659 ++mScanSourcesGeneration;
660 mScanSourcesPending = false;
661
Andreas Huber1aef2112011-01-04 14:01:29 -0800662 mRenderer.clear();
Andreas Huber2bfdd422011-10-11 15:24:07 -0700663
664 if (mSource != NULL) {
665 mSource->stop();
666 mSource.clear();
667 }
Andreas Huber1aef2112011-01-04 14:01:29 -0800668
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800669 if (mDriver != NULL) {
670 sp<NuPlayerDriver> driver = mDriver.promote();
671 if (driver != NULL) {
672 driver->notifyResetComplete();
673 }
674 }
Andreas Huber1aef2112011-01-04 14:01:29 -0800675}
676
677void NuPlayer::postScanSources() {
678 if (mScanSourcesPending) {
679 return;
680 }
681
682 sp<AMessage> msg = new AMessage(kWhatScanSources, id());
683 msg->setInt32("generation", mScanSourcesGeneration);
684 msg->post();
685
686 mScanSourcesPending = true;
687}
688
Andreas Huber5bc087c2010-12-23 10:27:40 -0800689status_t NuPlayer::instantiateDecoder(bool audio, sp<Decoder> *decoder) {
Andreas Huberf9334412010-12-15 15:17:42 -0800690 if (*decoder != NULL) {
691 return OK;
692 }
693
Andreas Huber84066782011-08-16 09:34:26 -0700694 sp<AMessage> format = mSource->getFormat(audio);
Andreas Huberf9334412010-12-15 15:17:42 -0800695
Andreas Huber84066782011-08-16 09:34:26 -0700696 if (format == NULL) {
Andreas Huberf9334412010-12-15 15:17:42 -0800697 return -EWOULDBLOCK;
698 }
699
Andreas Huber3fe62152011-09-16 15:09:22 -0700700 if (!audio) {
Andreas Huber84066782011-08-16 09:34:26 -0700701 AString mime;
702 CHECK(format->findString("mime", &mime));
703 mVideoIsAVC = !strcasecmp(MEDIA_MIMETYPE_VIDEO_AVC, mime.c_str());
Andreas Huber3fe62152011-09-16 15:09:22 -0700704 }
705
Andreas Huberf9334412010-12-15 15:17:42 -0800706 sp<AMessage> notify =
707 new AMessage(audio ? kWhatAudioNotify : kWhatVideoNotify,
708 id());
709
Glenn Kasten11731182011-02-08 17:26:17 -0800710 *decoder = audio ? new Decoder(notify) :
711 new Decoder(notify, mNativeWindow);
Andreas Huberf9334412010-12-15 15:17:42 -0800712 looper()->registerHandler(*decoder);
713
Andreas Huber84066782011-08-16 09:34:26 -0700714 (*decoder)->configure(format);
Andreas Huberf9334412010-12-15 15:17:42 -0800715
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800716 int64_t durationUs;
717 if (mDriver != NULL && mSource->getDuration(&durationUs) == OK) {
718 sp<NuPlayerDriver> driver = mDriver.promote();
719 if (driver != NULL) {
720 driver->notifyDuration(durationUs);
721 }
722 }
723
Andreas Huberf9334412010-12-15 15:17:42 -0800724 return OK;
725}
726
727status_t NuPlayer::feedDecoderInputData(bool audio, const sp<AMessage> &msg) {
728 sp<AMessage> reply;
729 CHECK(msg->findMessage("reply", &reply));
730
Andreas Huber53df1a42010-12-22 10:03:04 -0800731 if ((audio && IsFlushingState(mFlushingAudio))
732 || (!audio && IsFlushingState(mFlushingVideo))) {
Andreas Huberf9334412010-12-15 15:17:42 -0800733 reply->setInt32("err", INFO_DISCONTINUITY);
734 reply->post();
735 return OK;
736 }
737
738 sp<ABuffer> accessUnit;
Andreas Huberf9334412010-12-15 15:17:42 -0800739
Andreas Huber3fe62152011-09-16 15:09:22 -0700740 bool dropAccessUnit;
741 do {
742 status_t err = mSource->dequeueAccessUnit(audio, &accessUnit);
Andreas Huber5bc087c2010-12-23 10:27:40 -0800743
Andreas Huber3fe62152011-09-16 15:09:22 -0700744 if (err == -EWOULDBLOCK) {
745 return err;
746 } else if (err != OK) {
747 if (err == INFO_DISCONTINUITY) {
748 int32_t type;
749 CHECK(accessUnit->meta()->findInt32("discontinuity", &type));
Andreas Huber53df1a42010-12-22 10:03:04 -0800750
Andreas Huber3fe62152011-09-16 15:09:22 -0700751 bool formatChange =
Andreas Huber6e3d3112011-11-28 12:36:11 -0800752 (audio &&
753 (type & ATSParser::DISCONTINUITY_AUDIO_FORMAT))
754 || (!audio &&
755 (type & ATSParser::DISCONTINUITY_VIDEO_FORMAT));
Andreas Huber53df1a42010-12-22 10:03:04 -0800756
Andreas Huber6e3d3112011-11-28 12:36:11 -0800757 bool timeChange = (type & ATSParser::DISCONTINUITY_TIME) != 0;
758
Steve Blockdf64d152012-01-04 20:05:49 +0000759 ALOGI("%s discontinuity (formatChange=%d, time=%d)",
Andreas Huber6e3d3112011-11-28 12:36:11 -0800760 audio ? "audio" : "video", formatChange, timeChange);
Andreas Huber32f3cef2011-03-02 15:34:46 -0800761
Andreas Huber3fe62152011-09-16 15:09:22 -0700762 if (audio) {
763 mSkipRenderingAudioUntilMediaTimeUs = -1;
764 } else {
765 mSkipRenderingVideoUntilMediaTimeUs = -1;
766 }
Andreas Huber32f3cef2011-03-02 15:34:46 -0800767
Andreas Huber6e3d3112011-11-28 12:36:11 -0800768 if (timeChange) {
769 sp<AMessage> extra;
770 if (accessUnit->meta()->findMessage("extra", &extra)
771 && extra != NULL) {
772 int64_t resumeAtMediaTimeUs;
773 if (extra->findInt64(
774 "resume-at-mediatimeUs", &resumeAtMediaTimeUs)) {
Steve Blockdf64d152012-01-04 20:05:49 +0000775 ALOGI("suppressing rendering of %s until %lld us",
Andreas Huber6e3d3112011-11-28 12:36:11 -0800776 audio ? "audio" : "video", resumeAtMediaTimeUs);
Andreas Huber3fe62152011-09-16 15:09:22 -0700777
Andreas Huber6e3d3112011-11-28 12:36:11 -0800778 if (audio) {
779 mSkipRenderingAudioUntilMediaTimeUs =
780 resumeAtMediaTimeUs;
781 } else {
782 mSkipRenderingVideoUntilMediaTimeUs =
783 resumeAtMediaTimeUs;
784 }
Andreas Huber3fe62152011-09-16 15:09:22 -0700785 }
Andreas Huber32f3cef2011-03-02 15:34:46 -0800786 }
787 }
Andreas Huber3fe62152011-09-16 15:09:22 -0700788
Andreas Huber6e3d3112011-11-28 12:36:11 -0800789 mTimeDiscontinuityPending =
790 mTimeDiscontinuityPending || timeChange;
791
792 if (formatChange || timeChange) {
793 flushDecoder(audio, formatChange);
794 } else {
795 // This stream is unaffected by the discontinuity
796
797 if (audio) {
798 mFlushingAudio = FLUSHED;
799 } else {
800 mFlushingVideo = FLUSHED;
801 }
802
803 finishFlushIfPossible();
804
805 return -EWOULDBLOCK;
806 }
Andreas Huber32f3cef2011-03-02 15:34:46 -0800807 }
808
Andreas Huber3fe62152011-09-16 15:09:22 -0700809 reply->setInt32("err", err);
810 reply->post();
811 return OK;
Andreas Huberf9334412010-12-15 15:17:42 -0800812 }
813
Andreas Huber3fe62152011-09-16 15:09:22 -0700814 if (!audio) {
815 ++mNumFramesTotal;
816 }
817
818 dropAccessUnit = false;
819 if (!audio
820 && mVideoLateByUs > 100000ll
821 && mVideoIsAVC
822 && !IsAVCReferenceFrame(accessUnit)) {
823 dropAccessUnit = true;
824 ++mNumFramesDropped;
825 }
826 } while (dropAccessUnit);
Andreas Huberf9334412010-12-15 15:17:42 -0800827
Steve Block3856b092011-10-20 11:56:00 +0100828 // ALOGV("returned a valid buffer of %s data", audio ? "audio" : "video");
Andreas Huberf9334412010-12-15 15:17:42 -0800829
830#if 0
831 int64_t mediaTimeUs;
832 CHECK(accessUnit->meta()->findInt64("timeUs", &mediaTimeUs));
Steve Block3856b092011-10-20 11:56:00 +0100833 ALOGV("feeding %s input buffer at media time %.2f secs",
Andreas Huberf9334412010-12-15 15:17:42 -0800834 audio ? "audio" : "video",
835 mediaTimeUs / 1E6);
836#endif
837
Andreas Huber2d8bedd2012-02-21 14:38:23 -0800838 reply->setBuffer("buffer", accessUnit);
Andreas Huberf9334412010-12-15 15:17:42 -0800839 reply->post();
840
841 return OK;
842}
843
844void NuPlayer::renderBuffer(bool audio, const sp<AMessage> &msg) {
Steve Block3856b092011-10-20 11:56:00 +0100845 // ALOGV("renderBuffer %s", audio ? "audio" : "video");
Andreas Huberf9334412010-12-15 15:17:42 -0800846
847 sp<AMessage> reply;
848 CHECK(msg->findMessage("reply", &reply));
849
Andreas Huber18ac5402011-08-31 15:04:25 -0700850 if (IsFlushingState(audio ? mFlushingAudio : mFlushingVideo)) {
851 // We're currently attempting to flush the decoder, in order
852 // to complete this, the decoder wants all its buffers back,
853 // so we don't want any output buffers it sent us (from before
854 // we initiated the flush) to be stuck in the renderer's queue.
855
Steve Block3856b092011-10-20 11:56:00 +0100856 ALOGV("we're still flushing the %s decoder, sending its output buffer"
Andreas Huber18ac5402011-08-31 15:04:25 -0700857 " right back.", audio ? "audio" : "video");
858
859 reply->post();
860 return;
861 }
862
Andreas Huber2d8bedd2012-02-21 14:38:23 -0800863 sp<ABuffer> buffer;
864 CHECK(msg->findBuffer("buffer", &buffer));
Andreas Huberf9334412010-12-15 15:17:42 -0800865
Andreas Huber32f3cef2011-03-02 15:34:46 -0800866 int64_t &skipUntilMediaTimeUs =
867 audio
868 ? mSkipRenderingAudioUntilMediaTimeUs
869 : mSkipRenderingVideoUntilMediaTimeUs;
870
871 if (skipUntilMediaTimeUs >= 0) {
872 int64_t mediaTimeUs;
873 CHECK(buffer->meta()->findInt64("timeUs", &mediaTimeUs));
874
875 if (mediaTimeUs < skipUntilMediaTimeUs) {
Steve Block3856b092011-10-20 11:56:00 +0100876 ALOGV("dropping %s buffer at time %lld as requested.",
Andreas Huber32f3cef2011-03-02 15:34:46 -0800877 audio ? "audio" : "video",
878 mediaTimeUs);
879
880 reply->post();
881 return;
882 }
883
884 skipUntilMediaTimeUs = -1;
885 }
886
Andreas Huberf9334412010-12-15 15:17:42 -0800887 mRenderer->queueBuffer(audio, buffer, reply);
888}
889
890void NuPlayer::notifyListener(int msg, int ext1, int ext2) {
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800891 if (mDriver == NULL) {
Andreas Huberf9334412010-12-15 15:17:42 -0800892 return;
893 }
894
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800895 sp<NuPlayerDriver> driver = mDriver.promote();
Andreas Huberf9334412010-12-15 15:17:42 -0800896
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800897 if (driver == NULL) {
Andreas Huberf9334412010-12-15 15:17:42 -0800898 return;
899 }
900
Andreas Hubera4af2142011-10-26 15:23:31 -0700901 driver->notifyListener(msg, ext1, ext2);
Andreas Huberf9334412010-12-15 15:17:42 -0800902}
903
Andreas Huber1aef2112011-01-04 14:01:29 -0800904void NuPlayer::flushDecoder(bool audio, bool needShutdown) {
Andreas Huber6e3d3112011-11-28 12:36:11 -0800905 if ((audio && mAudioDecoder == NULL) || (!audio && mVideoDecoder == NULL)) {
Steve Blockdf64d152012-01-04 20:05:49 +0000906 ALOGI("flushDecoder %s without decoder present",
Andreas Huber6e3d3112011-11-28 12:36:11 -0800907 audio ? "audio" : "video");
908 }
909
Andreas Huber1aef2112011-01-04 14:01:29 -0800910 // Make sure we don't continue to scan sources until we finish flushing.
911 ++mScanSourcesGeneration;
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800912 mScanSourcesPending = false;
Andreas Huber1aef2112011-01-04 14:01:29 -0800913
914 (audio ? mAudioDecoder : mVideoDecoder)->signalFlush();
915 mRenderer->flush(audio);
916
917 FlushStatus newStatus =
918 needShutdown ? FLUSHING_DECODER_SHUTDOWN : FLUSHING_DECODER;
919
920 if (audio) {
921 CHECK(mFlushingAudio == NONE
922 || mFlushingAudio == AWAITING_DISCONTINUITY);
923
924 mFlushingAudio = newStatus;
925
926 if (mFlushingVideo == NONE) {
927 mFlushingVideo = (mVideoDecoder != NULL)
928 ? AWAITING_DISCONTINUITY
929 : FLUSHED;
930 }
931 } else {
932 CHECK(mFlushingVideo == NONE
933 || mFlushingVideo == AWAITING_DISCONTINUITY);
934
935 mFlushingVideo = newStatus;
936
937 if (mFlushingAudio == NONE) {
938 mFlushingAudio = (mAudioDecoder != NULL)
939 ? AWAITING_DISCONTINUITY
940 : FLUSHED;
941 }
942 }
943}
944
Andreas Huber84066782011-08-16 09:34:26 -0700945sp<AMessage> NuPlayer::Source::getFormat(bool audio) {
946 sp<MetaData> meta = getFormatMeta(audio);
947
948 if (meta == NULL) {
949 return NULL;
950 }
951
952 sp<AMessage> msg = new AMessage;
953
954 if(convertMetaDataToMessage(meta, &msg) == OK) {
955 return msg;
956 }
957 return NULL;
958}
959
Andreas Huberf9334412010-12-15 15:17:42 -0800960} // namespace android