blob: 564a256147d6322e97ff20cd215856a0b4e56487 [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 int32_t audio;
513 CHECK(msg->findInt32("audio", &audio));
514
Steve Block3856b092011-10-20 11:56:00 +0100515 ALOGV("renderer %s flush completed.", audio ? "audio" : "video");
James Dongf57b4ea2012-07-20 13:38:36 -0700516 } else if (what == Renderer::kWhatVideoRenderingStart) {
517 notifyListener(MEDIA_INFO, MEDIA_INFO_RENDERING_START, 0);
Andreas Huberf9334412010-12-15 15:17:42 -0800518 }
519 break;
520 }
521
522 case kWhatMoreDataQueued:
523 {
524 break;
525 }
526
Andreas Huber1aef2112011-01-04 14:01:29 -0800527 case kWhatReset:
528 {
Steve Block3856b092011-10-20 11:56:00 +0100529 ALOGV("kWhatReset");
Andreas Huber1aef2112011-01-04 14:01:29 -0800530
Andreas Huberb58ce9f2011-11-28 16:27:35 -0800531 if (mRenderer != NULL) {
532 // There's an edge case where the renderer owns all output
533 // buffers and is paused, therefore the decoder will not read
534 // more input data and will never encounter the matching
535 // discontinuity. To avoid this, we resume the renderer.
536
537 if (mFlushingAudio == AWAITING_DISCONTINUITY
538 || mFlushingVideo == AWAITING_DISCONTINUITY) {
539 mRenderer->resume();
540 }
541 }
542
Andreas Huber1aef2112011-01-04 14:01:29 -0800543 if (mFlushingAudio != NONE || mFlushingVideo != NONE) {
544 // We're currently flushing, postpone the reset until that's
545 // completed.
546
Andreas Huberea9d51b2011-11-30 09:53:40 -0800547 ALOGV("postponing reset mFlushingAudio=%d, mFlushingVideo=%d",
548 mFlushingAudio, mFlushingVideo);
Andreas Huber1aef2112011-01-04 14:01:29 -0800549
550 mResetPostponed = true;
551 break;
552 }
553
554 if (mAudioDecoder == NULL && mVideoDecoder == NULL) {
555 finishReset();
556 break;
557 }
558
Andreas Huber6e3d3112011-11-28 12:36:11 -0800559 mTimeDiscontinuityPending = true;
560
Andreas Huber1aef2112011-01-04 14:01:29 -0800561 if (mAudioDecoder != NULL) {
562 flushDecoder(true /* audio */, true /* needShutdown */);
563 }
564
565 if (mVideoDecoder != NULL) {
566 flushDecoder(false /* audio */, true /* needShutdown */);
567 }
568
569 mResetInProgress = true;
570 break;
571 }
572
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800573 case kWhatSeek:
574 {
575 int64_t seekTimeUs;
576 CHECK(msg->findInt64("seekTimeUs", &seekTimeUs));
577
Steve Block3856b092011-10-20 11:56:00 +0100578 ALOGV("kWhatSeek seekTimeUs=%lld us (%.2f secs)",
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800579 seekTimeUs, seekTimeUs / 1E6);
580
581 mSource->seekTo(seekTimeUs);
582
583 if (mDriver != NULL) {
584 sp<NuPlayerDriver> driver = mDriver.promote();
585 if (driver != NULL) {
586 driver->notifySeekComplete();
587 }
588 }
589
590 break;
591 }
592
Andreas Huberb4082222011-01-20 15:23:04 -0800593 case kWhatPause:
594 {
595 CHECK(mRenderer != NULL);
596 mRenderer->pause();
597 break;
598 }
599
600 case kWhatResume:
601 {
602 CHECK(mRenderer != NULL);
603 mRenderer->resume();
604 break;
605 }
606
Andreas Huberf9334412010-12-15 15:17:42 -0800607 default:
608 TRESPASS();
609 break;
610 }
611}
612
Andreas Huber3831a062010-12-21 10:22:33 -0800613void NuPlayer::finishFlushIfPossible() {
614 if (mFlushingAudio != FLUSHED && mFlushingAudio != SHUT_DOWN) {
615 return;
616 }
617
618 if (mFlushingVideo != FLUSHED && mFlushingVideo != SHUT_DOWN) {
619 return;
620 }
621
Steve Block3856b092011-10-20 11:56:00 +0100622 ALOGV("both audio and video are flushed now.");
Andreas Huber3831a062010-12-21 10:22:33 -0800623
Andreas Huber6e3d3112011-11-28 12:36:11 -0800624 if (mTimeDiscontinuityPending) {
625 mRenderer->signalTimeDiscontinuity();
626 mTimeDiscontinuityPending = false;
627 }
Andreas Huber3831a062010-12-21 10:22:33 -0800628
Andreas Huber22fc52f2011-01-05 16:24:27 -0800629 if (mAudioDecoder != NULL) {
Andreas Huber3831a062010-12-21 10:22:33 -0800630 mAudioDecoder->signalResume();
631 }
632
Andreas Huber22fc52f2011-01-05 16:24:27 -0800633 if (mVideoDecoder != NULL) {
Andreas Huber3831a062010-12-21 10:22:33 -0800634 mVideoDecoder->signalResume();
635 }
636
637 mFlushingAudio = NONE;
638 mFlushingVideo = NONE;
Andreas Huber3831a062010-12-21 10:22:33 -0800639
Andreas Huber1aef2112011-01-04 14:01:29 -0800640 if (mResetInProgress) {
Steve Block3856b092011-10-20 11:56:00 +0100641 ALOGV("reset completed");
Andreas Huber1aef2112011-01-04 14:01:29 -0800642
643 mResetInProgress = false;
644 finishReset();
645 } else if (mResetPostponed) {
646 (new AMessage(kWhatReset, id()))->post();
647 mResetPostponed = false;
Andreas Huber22fc52f2011-01-05 16:24:27 -0800648 } else if (mAudioDecoder == NULL || mVideoDecoder == NULL) {
Andreas Huber1aef2112011-01-04 14:01:29 -0800649 postScanSources();
Andreas Huberf9334412010-12-15 15:17:42 -0800650 }
651}
652
Andreas Huber1aef2112011-01-04 14:01:29 -0800653void NuPlayer::finishReset() {
654 CHECK(mAudioDecoder == NULL);
655 CHECK(mVideoDecoder == NULL);
656
Andreas Huber2bfdd422011-10-11 15:24:07 -0700657 ++mScanSourcesGeneration;
658 mScanSourcesPending = false;
659
Andreas Huber1aef2112011-01-04 14:01:29 -0800660 mRenderer.clear();
Andreas Huber2bfdd422011-10-11 15:24:07 -0700661
662 if (mSource != NULL) {
663 mSource->stop();
664 mSource.clear();
665 }
Andreas Huber1aef2112011-01-04 14:01:29 -0800666
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800667 if (mDriver != NULL) {
668 sp<NuPlayerDriver> driver = mDriver.promote();
669 if (driver != NULL) {
670 driver->notifyResetComplete();
671 }
672 }
Andreas Huber1aef2112011-01-04 14:01:29 -0800673}
674
675void NuPlayer::postScanSources() {
676 if (mScanSourcesPending) {
677 return;
678 }
679
680 sp<AMessage> msg = new AMessage(kWhatScanSources, id());
681 msg->setInt32("generation", mScanSourcesGeneration);
682 msg->post();
683
684 mScanSourcesPending = true;
685}
686
Andreas Huber5bc087c2010-12-23 10:27:40 -0800687status_t NuPlayer::instantiateDecoder(bool audio, sp<Decoder> *decoder) {
Andreas Huberf9334412010-12-15 15:17:42 -0800688 if (*decoder != NULL) {
689 return OK;
690 }
691
Andreas Huber84066782011-08-16 09:34:26 -0700692 sp<AMessage> format = mSource->getFormat(audio);
Andreas Huberf9334412010-12-15 15:17:42 -0800693
Andreas Huber84066782011-08-16 09:34:26 -0700694 if (format == NULL) {
Andreas Huberf9334412010-12-15 15:17:42 -0800695 return -EWOULDBLOCK;
696 }
697
Andreas Huber3fe62152011-09-16 15:09:22 -0700698 if (!audio) {
Andreas Huber84066782011-08-16 09:34:26 -0700699 AString mime;
700 CHECK(format->findString("mime", &mime));
701 mVideoIsAVC = !strcasecmp(MEDIA_MIMETYPE_VIDEO_AVC, mime.c_str());
Andreas Huber3fe62152011-09-16 15:09:22 -0700702 }
703
Andreas Huberf9334412010-12-15 15:17:42 -0800704 sp<AMessage> notify =
705 new AMessage(audio ? kWhatAudioNotify : kWhatVideoNotify,
706 id());
707
Glenn Kasten11731182011-02-08 17:26:17 -0800708 *decoder = audio ? new Decoder(notify) :
709 new Decoder(notify, mNativeWindow);
Andreas Huberf9334412010-12-15 15:17:42 -0800710 looper()->registerHandler(*decoder);
711
Andreas Huber84066782011-08-16 09:34:26 -0700712 (*decoder)->configure(format);
Andreas Huberf9334412010-12-15 15:17:42 -0800713
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800714 int64_t durationUs;
715 if (mDriver != NULL && mSource->getDuration(&durationUs) == OK) {
716 sp<NuPlayerDriver> driver = mDriver.promote();
717 if (driver != NULL) {
718 driver->notifyDuration(durationUs);
719 }
720 }
721
Andreas Huberf9334412010-12-15 15:17:42 -0800722 return OK;
723}
724
725status_t NuPlayer::feedDecoderInputData(bool audio, const sp<AMessage> &msg) {
726 sp<AMessage> reply;
727 CHECK(msg->findMessage("reply", &reply));
728
Andreas Huber53df1a42010-12-22 10:03:04 -0800729 if ((audio && IsFlushingState(mFlushingAudio))
730 || (!audio && IsFlushingState(mFlushingVideo))) {
Andreas Huberf9334412010-12-15 15:17:42 -0800731 reply->setInt32("err", INFO_DISCONTINUITY);
732 reply->post();
733 return OK;
734 }
735
736 sp<ABuffer> accessUnit;
Andreas Huberf9334412010-12-15 15:17:42 -0800737
Andreas Huber3fe62152011-09-16 15:09:22 -0700738 bool dropAccessUnit;
739 do {
740 status_t err = mSource->dequeueAccessUnit(audio, &accessUnit);
Andreas Huber5bc087c2010-12-23 10:27:40 -0800741
Andreas Huber3fe62152011-09-16 15:09:22 -0700742 if (err == -EWOULDBLOCK) {
743 return err;
744 } else if (err != OK) {
745 if (err == INFO_DISCONTINUITY) {
746 int32_t type;
747 CHECK(accessUnit->meta()->findInt32("discontinuity", &type));
Andreas Huber53df1a42010-12-22 10:03:04 -0800748
Andreas Huber3fe62152011-09-16 15:09:22 -0700749 bool formatChange =
Andreas Huber6e3d3112011-11-28 12:36:11 -0800750 (audio &&
751 (type & ATSParser::DISCONTINUITY_AUDIO_FORMAT))
752 || (!audio &&
753 (type & ATSParser::DISCONTINUITY_VIDEO_FORMAT));
Andreas Huber53df1a42010-12-22 10:03:04 -0800754
Andreas Huber6e3d3112011-11-28 12:36:11 -0800755 bool timeChange = (type & ATSParser::DISCONTINUITY_TIME) != 0;
756
Steve Blockdf64d152012-01-04 20:05:49 +0000757 ALOGI("%s discontinuity (formatChange=%d, time=%d)",
Andreas Huber6e3d3112011-11-28 12:36:11 -0800758 audio ? "audio" : "video", formatChange, timeChange);
Andreas Huber32f3cef2011-03-02 15:34:46 -0800759
Andreas Huber3fe62152011-09-16 15:09:22 -0700760 if (audio) {
761 mSkipRenderingAudioUntilMediaTimeUs = -1;
762 } else {
763 mSkipRenderingVideoUntilMediaTimeUs = -1;
764 }
Andreas Huber32f3cef2011-03-02 15:34:46 -0800765
Andreas Huber6e3d3112011-11-28 12:36:11 -0800766 if (timeChange) {
767 sp<AMessage> extra;
768 if (accessUnit->meta()->findMessage("extra", &extra)
769 && extra != NULL) {
770 int64_t resumeAtMediaTimeUs;
771 if (extra->findInt64(
772 "resume-at-mediatimeUs", &resumeAtMediaTimeUs)) {
Steve Blockdf64d152012-01-04 20:05:49 +0000773 ALOGI("suppressing rendering of %s until %lld us",
Andreas Huber6e3d3112011-11-28 12:36:11 -0800774 audio ? "audio" : "video", resumeAtMediaTimeUs);
Andreas Huber3fe62152011-09-16 15:09:22 -0700775
Andreas Huber6e3d3112011-11-28 12:36:11 -0800776 if (audio) {
777 mSkipRenderingAudioUntilMediaTimeUs =
778 resumeAtMediaTimeUs;
779 } else {
780 mSkipRenderingVideoUntilMediaTimeUs =
781 resumeAtMediaTimeUs;
782 }
Andreas Huber3fe62152011-09-16 15:09:22 -0700783 }
Andreas Huber32f3cef2011-03-02 15:34:46 -0800784 }
785 }
Andreas Huber3fe62152011-09-16 15:09:22 -0700786
Andreas Huber6e3d3112011-11-28 12:36:11 -0800787 mTimeDiscontinuityPending =
788 mTimeDiscontinuityPending || timeChange;
789
790 if (formatChange || timeChange) {
791 flushDecoder(audio, formatChange);
792 } else {
793 // This stream is unaffected by the discontinuity
794
795 if (audio) {
796 mFlushingAudio = FLUSHED;
797 } else {
798 mFlushingVideo = FLUSHED;
799 }
800
801 finishFlushIfPossible();
802
803 return -EWOULDBLOCK;
804 }
Andreas Huber32f3cef2011-03-02 15:34:46 -0800805 }
806
Andreas Huber3fe62152011-09-16 15:09:22 -0700807 reply->setInt32("err", err);
808 reply->post();
809 return OK;
Andreas Huberf9334412010-12-15 15:17:42 -0800810 }
811
Andreas Huber3fe62152011-09-16 15:09:22 -0700812 if (!audio) {
813 ++mNumFramesTotal;
814 }
815
816 dropAccessUnit = false;
817 if (!audio
818 && mVideoLateByUs > 100000ll
819 && mVideoIsAVC
820 && !IsAVCReferenceFrame(accessUnit)) {
821 dropAccessUnit = true;
822 ++mNumFramesDropped;
823 }
824 } while (dropAccessUnit);
Andreas Huberf9334412010-12-15 15:17:42 -0800825
Steve Block3856b092011-10-20 11:56:00 +0100826 // ALOGV("returned a valid buffer of %s data", audio ? "audio" : "video");
Andreas Huberf9334412010-12-15 15:17:42 -0800827
828#if 0
829 int64_t mediaTimeUs;
830 CHECK(accessUnit->meta()->findInt64("timeUs", &mediaTimeUs));
Steve Block3856b092011-10-20 11:56:00 +0100831 ALOGV("feeding %s input buffer at media time %.2f secs",
Andreas Huberf9334412010-12-15 15:17:42 -0800832 audio ? "audio" : "video",
833 mediaTimeUs / 1E6);
834#endif
835
Andreas Huber2d8bedd2012-02-21 14:38:23 -0800836 reply->setBuffer("buffer", accessUnit);
Andreas Huberf9334412010-12-15 15:17:42 -0800837 reply->post();
838
839 return OK;
840}
841
842void NuPlayer::renderBuffer(bool audio, const sp<AMessage> &msg) {
Steve Block3856b092011-10-20 11:56:00 +0100843 // ALOGV("renderBuffer %s", audio ? "audio" : "video");
Andreas Huberf9334412010-12-15 15:17:42 -0800844
845 sp<AMessage> reply;
846 CHECK(msg->findMessage("reply", &reply));
847
Andreas Huber18ac5402011-08-31 15:04:25 -0700848 if (IsFlushingState(audio ? mFlushingAudio : mFlushingVideo)) {
849 // We're currently attempting to flush the decoder, in order
850 // to complete this, the decoder wants all its buffers back,
851 // so we don't want any output buffers it sent us (from before
852 // we initiated the flush) to be stuck in the renderer's queue.
853
Steve Block3856b092011-10-20 11:56:00 +0100854 ALOGV("we're still flushing the %s decoder, sending its output buffer"
Andreas Huber18ac5402011-08-31 15:04:25 -0700855 " right back.", audio ? "audio" : "video");
856
857 reply->post();
858 return;
859 }
860
Andreas Huber2d8bedd2012-02-21 14:38:23 -0800861 sp<ABuffer> buffer;
862 CHECK(msg->findBuffer("buffer", &buffer));
Andreas Huberf9334412010-12-15 15:17:42 -0800863
Andreas Huber32f3cef2011-03-02 15:34:46 -0800864 int64_t &skipUntilMediaTimeUs =
865 audio
866 ? mSkipRenderingAudioUntilMediaTimeUs
867 : mSkipRenderingVideoUntilMediaTimeUs;
868
869 if (skipUntilMediaTimeUs >= 0) {
870 int64_t mediaTimeUs;
871 CHECK(buffer->meta()->findInt64("timeUs", &mediaTimeUs));
872
873 if (mediaTimeUs < skipUntilMediaTimeUs) {
Steve Block3856b092011-10-20 11:56:00 +0100874 ALOGV("dropping %s buffer at time %lld as requested.",
Andreas Huber32f3cef2011-03-02 15:34:46 -0800875 audio ? "audio" : "video",
876 mediaTimeUs);
877
878 reply->post();
879 return;
880 }
881
882 skipUntilMediaTimeUs = -1;
883 }
884
Andreas Huberf9334412010-12-15 15:17:42 -0800885 mRenderer->queueBuffer(audio, buffer, reply);
886}
887
888void NuPlayer::notifyListener(int msg, int ext1, int ext2) {
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800889 if (mDriver == NULL) {
Andreas Huberf9334412010-12-15 15:17:42 -0800890 return;
891 }
892
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800893 sp<NuPlayerDriver> driver = mDriver.promote();
Andreas Huberf9334412010-12-15 15:17:42 -0800894
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800895 if (driver == NULL) {
Andreas Huberf9334412010-12-15 15:17:42 -0800896 return;
897 }
898
Andreas Hubera4af2142011-10-26 15:23:31 -0700899 driver->notifyListener(msg, ext1, ext2);
Andreas Huberf9334412010-12-15 15:17:42 -0800900}
901
Andreas Huber1aef2112011-01-04 14:01:29 -0800902void NuPlayer::flushDecoder(bool audio, bool needShutdown) {
Andreas Huber6e3d3112011-11-28 12:36:11 -0800903 if ((audio && mAudioDecoder == NULL) || (!audio && mVideoDecoder == NULL)) {
Steve Blockdf64d152012-01-04 20:05:49 +0000904 ALOGI("flushDecoder %s without decoder present",
Andreas Huber6e3d3112011-11-28 12:36:11 -0800905 audio ? "audio" : "video");
906 }
907
Andreas Huber1aef2112011-01-04 14:01:29 -0800908 // Make sure we don't continue to scan sources until we finish flushing.
909 ++mScanSourcesGeneration;
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800910 mScanSourcesPending = false;
Andreas Huber1aef2112011-01-04 14:01:29 -0800911
912 (audio ? mAudioDecoder : mVideoDecoder)->signalFlush();
913 mRenderer->flush(audio);
914
915 FlushStatus newStatus =
916 needShutdown ? FLUSHING_DECODER_SHUTDOWN : FLUSHING_DECODER;
917
918 if (audio) {
919 CHECK(mFlushingAudio == NONE
920 || mFlushingAudio == AWAITING_DISCONTINUITY);
921
922 mFlushingAudio = newStatus;
923
924 if (mFlushingVideo == NONE) {
925 mFlushingVideo = (mVideoDecoder != NULL)
926 ? AWAITING_DISCONTINUITY
927 : FLUSHED;
928 }
929 } else {
930 CHECK(mFlushingVideo == NONE
931 || mFlushingVideo == AWAITING_DISCONTINUITY);
932
933 mFlushingVideo = newStatus;
934
935 if (mFlushingAudio == NONE) {
936 mFlushingAudio = (mAudioDecoder != NULL)
937 ? AWAITING_DISCONTINUITY
938 : FLUSHED;
939 }
940 }
941}
942
Andreas Huber84066782011-08-16 09:34:26 -0700943sp<AMessage> NuPlayer::Source::getFormat(bool audio) {
944 sp<MetaData> meta = getFormatMeta(audio);
945
946 if (meta == NULL) {
947 return NULL;
948 }
949
950 sp<AMessage> msg = new AMessage;
951
952 if(convertMetaDataToMessage(meta, &msg) == OK) {
953 return msg;
954 }
955 return NULL;
956}
957
Andreas Huberf9334412010-12-15 15:17:42 -0800958} // namespace android