blob: 9a4e81190db1451b033c2c6bf92aa960ca1da1bd [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"
Wei Jiabc2fb722014-07-08 16:37:57 -070025#include "NuPlayerDecoderPassThrough.h"
Andreas Huber43c3e6c2011-01-05 12:17:08 -080026#include "NuPlayerDriver.h"
Andreas Huberf9334412010-12-15 15:17:42 -080027#include "NuPlayerRenderer.h"
Andreas Huber5bc087c2010-12-23 10:27:40 -080028#include "NuPlayerSource.h"
Andreas Huber2bfdd422011-10-11 15:24:07 -070029#include "RTSPSource.h"
Andreas Huber5bc087c2010-12-23 10:27:40 -080030#include "StreamingSource.h"
Andreas Huberafed0e12011-09-20 15:39:58 -070031#include "GenericSource.h"
Robert Shihd3b0bbb2014-07-23 15:00:25 -070032#include "TextDescriptions.h"
Andreas Huber5bc087c2010-12-23 10:27:40 -080033
34#include "ATSParser.h"
Andreas Huberf9334412010-12-15 15:17:42 -080035
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>
Lajos Molnar09524832014-07-17 14:29:51 -070040#include <media/stagefright/MediaBuffer.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>
Andy McFadden8ba01022012-12-18 09:46:54 -080044#include <gui/IGraphicBufferProducer.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
Andreas Hubera1f8ab02012-11-30 10:53:22 -080053struct NuPlayer::Action : public RefBase {
54 Action() {}
55
56 virtual void execute(NuPlayer *player) = 0;
57
58private:
59 DISALLOW_EVIL_CONSTRUCTORS(Action);
60};
61
62struct NuPlayer::SeekAction : public Action {
63 SeekAction(int64_t seekTimeUs)
64 : mSeekTimeUs(seekTimeUs) {
65 }
66
67 virtual void execute(NuPlayer *player) {
68 player->performSeek(mSeekTimeUs);
69 }
70
71private:
72 int64_t mSeekTimeUs;
73
74 DISALLOW_EVIL_CONSTRUCTORS(SeekAction);
75};
76
Andreas Huber57a339c2012-12-03 11:18:00 -080077struct NuPlayer::SetSurfaceAction : public Action {
78 SetSurfaceAction(const sp<NativeWindowWrapper> &wrapper)
79 : mWrapper(wrapper) {
80 }
81
82 virtual void execute(NuPlayer *player) {
83 player->performSetSurface(mWrapper);
84 }
85
86private:
87 sp<NativeWindowWrapper> mWrapper;
88
89 DISALLOW_EVIL_CONSTRUCTORS(SetSurfaceAction);
90};
91
Andreas Huber14f76722013-01-15 09:04:18 -080092struct NuPlayer::ShutdownDecoderAction : public Action {
93 ShutdownDecoderAction(bool audio, bool video)
94 : mAudio(audio),
95 mVideo(video) {
96 }
97
98 virtual void execute(NuPlayer *player) {
99 player->performDecoderShutdown(mAudio, mVideo);
100 }
101
102private:
103 bool mAudio;
104 bool mVideo;
105
106 DISALLOW_EVIL_CONSTRUCTORS(ShutdownDecoderAction);
107};
108
109struct NuPlayer::PostMessageAction : public Action {
110 PostMessageAction(const sp<AMessage> &msg)
111 : mMessage(msg) {
112 }
113
114 virtual void execute(NuPlayer *) {
115 mMessage->post();
116 }
117
118private:
119 sp<AMessage> mMessage;
120
121 DISALLOW_EVIL_CONSTRUCTORS(PostMessageAction);
122};
123
Andreas Hubera1f8ab02012-11-30 10:53:22 -0800124// Use this if there's no state necessary to save in order to execute
125// the action.
126struct NuPlayer::SimpleAction : public Action {
127 typedef void (NuPlayer::*ActionFunc)();
128
129 SimpleAction(ActionFunc func)
130 : mFunc(func) {
131 }
132
133 virtual void execute(NuPlayer *player) {
134 (player->*mFunc)();
135 }
136
137private:
138 ActionFunc mFunc;
139
140 DISALLOW_EVIL_CONSTRUCTORS(SimpleAction);
141};
142
Andreas Huberf9334412010-12-15 15:17:42 -0800143////////////////////////////////////////////////////////////////////////////////
144
145NuPlayer::NuPlayer()
Andreas Huber9b80c2b2011-06-30 15:47:02 -0700146 : mUIDValid(false),
Andreas Huber9575c962013-02-05 13:59:56 -0800147 mSourceFlags(0),
Andreas Huber3fe62152011-09-16 15:09:22 -0700148 mVideoIsAVC(false),
Wei Jiabc2fb722014-07-08 16:37:57 -0700149 mOffloadAudio(false),
Andreas Huber9b80c2b2011-06-30 15:47:02 -0700150 mAudioEOS(false),
Andreas Huberf9334412010-12-15 15:17:42 -0800151 mVideoEOS(false),
Andreas Huber5bc087c2010-12-23 10:27:40 -0800152 mScanSourcesPending(false),
Andreas Huber1aef2112011-01-04 14:01:29 -0800153 mScanSourcesGeneration(0),
Andreas Huberb7c8e912012-11-27 15:02:53 -0800154 mPollDurationGeneration(0),
Robert Shihd3b0bbb2014-07-23 15:00:25 -0700155 mTimedTextGeneration(0),
Andreas Huber6e3d3112011-11-28 12:36:11 -0800156 mTimeDiscontinuityPending(false),
Andreas Huberf9334412010-12-15 15:17:42 -0800157 mFlushingAudio(NONE),
Andreas Huber1aef2112011-01-04 14:01:29 -0800158 mFlushingVideo(NONE),
Andreas Huber3fe62152011-09-16 15:09:22 -0700159 mSkipRenderingAudioUntilMediaTimeUs(-1ll),
160 mSkipRenderingVideoUntilMediaTimeUs(-1ll),
161 mVideoLateByUs(0ll),
162 mNumFramesTotal(0ll),
James Dong0d268a32012-08-31 12:18:27 -0700163 mNumFramesDropped(0ll),
Andreas Huber57a339c2012-12-03 11:18:00 -0800164 mVideoScalingMode(NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW),
165 mStarted(false) {
Andreas Huberf9334412010-12-15 15:17:42 -0800166}
167
168NuPlayer::~NuPlayer() {
169}
170
Andreas Huber9b80c2b2011-06-30 15:47:02 -0700171void NuPlayer::setUID(uid_t uid) {
172 mUIDValid = true;
173 mUID = uid;
174}
175
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800176void NuPlayer::setDriver(const wp<NuPlayerDriver> &driver) {
177 mDriver = driver;
Andreas Huberf9334412010-12-15 15:17:42 -0800178}
179
Andreas Huber9575c962013-02-05 13:59:56 -0800180void NuPlayer::setDataSourceAsync(const sp<IStreamSource> &source) {
Andreas Huberf9334412010-12-15 15:17:42 -0800181 sp<AMessage> msg = new AMessage(kWhatSetDataSource, id());
182
Andreas Huberb5f25f02013-02-05 10:14:26 -0800183 sp<AMessage> notify = new AMessage(kWhatSourceNotify, id());
184
Andreas Huber240abcc2014-02-13 13:32:37 -0800185 msg->setObject("source", new StreamingSource(notify, source));
Andreas Huber5bc087c2010-12-23 10:27:40 -0800186 msg->post();
187}
Andreas Huberf9334412010-12-15 15:17:42 -0800188
Andreas Huberafed0e12011-09-20 15:39:58 -0700189static bool IsHTTPLiveURL(const char *url) {
190 if (!strncasecmp("http://", url, 7)
Andreas Huber99759402013-04-01 14:28:31 -0700191 || !strncasecmp("https://", url, 8)
192 || !strncasecmp("file://", url, 7)) {
Andreas Huberafed0e12011-09-20 15:39:58 -0700193 size_t len = strlen(url);
194 if (len >= 5 && !strcasecmp(".m3u8", &url[len - 5])) {
195 return true;
196 }
197
198 if (strstr(url,"m3u8")) {
199 return true;
200 }
201 }
202
203 return false;
204}
205
Andreas Huber9575c962013-02-05 13:59:56 -0800206void NuPlayer::setDataSourceAsync(
Andreas Huber1b86fe02014-01-29 11:13:26 -0800207 const sp<IMediaHTTPService> &httpService,
208 const char *url,
209 const KeyedVector<String8, String8> *headers) {
Chong Zhang3de157d2014-08-05 20:54:44 -0700210
Andreas Huber5bc087c2010-12-23 10:27:40 -0800211 sp<AMessage> msg = new AMessage(kWhatSetDataSource, id());
Oscar Rydhé7a33b772012-02-20 10:15:48 +0100212 size_t len = strlen(url);
Andreas Huber5bc087c2010-12-23 10:27:40 -0800213
Andreas Huberb5f25f02013-02-05 10:14:26 -0800214 sp<AMessage> notify = new AMessage(kWhatSourceNotify, id());
215
Andreas Huberafed0e12011-09-20 15:39:58 -0700216 sp<Source> source;
217 if (IsHTTPLiveURL(url)) {
Andreas Huber81e68442014-02-05 11:52:33 -0800218 source = new HTTPLiveSource(notify, httpService, url, headers);
Andreas Huberafed0e12011-09-20 15:39:58 -0700219 } else if (!strncasecmp(url, "rtsp://", 7)) {
Andreas Huber1b86fe02014-01-29 11:13:26 -0800220 source = new RTSPSource(
221 notify, httpService, url, headers, mUIDValid, mUID);
Oscar Rydhé7a33b772012-02-20 10:15:48 +0100222 } else if ((!strncasecmp(url, "http://", 7)
223 || !strncasecmp(url, "https://", 8))
224 && ((len >= 4 && !strcasecmp(".sdp", &url[len - 4]))
225 || strstr(url, ".sdp?"))) {
Andreas Huber1b86fe02014-01-29 11:13:26 -0800226 source = new RTSPSource(
227 notify, httpService, url, headers, mUIDValid, mUID, true);
Andreas Huber2bfdd422011-10-11 15:24:07 -0700228 } else {
Chong Zhang3de157d2014-08-05 20:54:44 -0700229 sp<GenericSource> genericSource =
230 new GenericSource(notify, mUIDValid, mUID);
231 // Don't set FLAG_SECURE on mSourceFlags here for widevine.
232 // The correct flags will be updated in Source::kWhatFlagsChanged
233 // handler when GenericSource is prepared.
Andreas Huber2bfdd422011-10-11 15:24:07 -0700234
Chong Zhanga19f33e2014-08-07 15:35:07 -0700235 status_t err = genericSource->setDataSource(httpService, url, headers);
Chong Zhang3de157d2014-08-05 20:54:44 -0700236
237 if (err == OK) {
238 source = genericSource;
239 } else {
Chong Zhanga19f33e2014-08-07 15:35:07 -0700240 ALOGE("Failed to set data source!");
Chong Zhang3de157d2014-08-05 20:54:44 -0700241 }
242 }
Andreas Huberafed0e12011-09-20 15:39:58 -0700243 msg->setObject("source", source);
244 msg->post();
245}
246
Andreas Huber9575c962013-02-05 13:59:56 -0800247void NuPlayer::setDataSourceAsync(int fd, int64_t offset, int64_t length) {
Andreas Huberafed0e12011-09-20 15:39:58 -0700248 sp<AMessage> msg = new AMessage(kWhatSetDataSource, id());
249
Andreas Huberb5f25f02013-02-05 10:14:26 -0800250 sp<AMessage> notify = new AMessage(kWhatSourceNotify, id());
251
Chong Zhang3de157d2014-08-05 20:54:44 -0700252 sp<GenericSource> source =
253 new GenericSource(notify, mUIDValid, mUID);
254
Chong Zhanga19f33e2014-08-07 15:35:07 -0700255 status_t err = source->setDataSource(fd, offset, length);
Chong Zhang3de157d2014-08-05 20:54:44 -0700256
257 if (err != OK) {
Chong Zhanga19f33e2014-08-07 15:35:07 -0700258 ALOGE("Failed to set data source!");
Chong Zhang3de157d2014-08-05 20:54:44 -0700259 source = NULL;
260 }
261
Andreas Huberafed0e12011-09-20 15:39:58 -0700262 msg->setObject("source", source);
Andreas Huberf9334412010-12-15 15:17:42 -0800263 msg->post();
264}
265
Andreas Huber9575c962013-02-05 13:59:56 -0800266void NuPlayer::prepareAsync() {
267 (new AMessage(kWhatPrepare, id()))->post();
268}
269
Andreas Huber57a339c2012-12-03 11:18:00 -0800270void NuPlayer::setVideoSurfaceTextureAsync(
Andy McFadden8ba01022012-12-18 09:46:54 -0800271 const sp<IGraphicBufferProducer> &bufferProducer) {
Glenn Kasten11731182011-02-08 17:26:17 -0800272 sp<AMessage> msg = new AMessage(kWhatSetVideoNativeWindow, id());
Andreas Huber57a339c2012-12-03 11:18:00 -0800273
Andy McFadden8ba01022012-12-18 09:46:54 -0800274 if (bufferProducer == NULL) {
Andreas Huber57a339c2012-12-03 11:18:00 -0800275 msg->setObject("native-window", NULL);
276 } else {
277 msg->setObject(
278 "native-window",
279 new NativeWindowWrapper(
Mathias Agopian1a2952a2013-02-14 17:11:27 -0800280 new Surface(bufferProducer)));
Andreas Huber57a339c2012-12-03 11:18:00 -0800281 }
282
Andreas Huberf9334412010-12-15 15:17:42 -0800283 msg->post();
284}
285
286void NuPlayer::setAudioSink(const sp<MediaPlayerBase::AudioSink> &sink) {
287 sp<AMessage> msg = new AMessage(kWhatSetAudioSink, id());
288 msg->setObject("sink", sink);
289 msg->post();
290}
291
292void NuPlayer::start() {
293 (new AMessage(kWhatStart, id()))->post();
294}
295
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800296void NuPlayer::pause() {
Andreas Huberb4082222011-01-20 15:23:04 -0800297 (new AMessage(kWhatPause, id()))->post();
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800298}
299
300void NuPlayer::resume() {
Andreas Huberb4082222011-01-20 15:23:04 -0800301 (new AMessage(kWhatResume, id()))->post();
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800302}
303
Andreas Huber1aef2112011-01-04 14:01:29 -0800304void NuPlayer::resetAsync() {
305 (new AMessage(kWhatReset, id()))->post();
306}
307
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800308void NuPlayer::seekToAsync(int64_t seekTimeUs) {
309 sp<AMessage> msg = new AMessage(kWhatSeek, id());
310 msg->setInt64("seekTimeUs", seekTimeUs);
311 msg->post();
312}
313
Andreas Huber53df1a42010-12-22 10:03:04 -0800314// static
Andreas Huber1aef2112011-01-04 14:01:29 -0800315bool NuPlayer::IsFlushingState(FlushStatus state, bool *needShutdown) {
Andreas Huber53df1a42010-12-22 10:03:04 -0800316 switch (state) {
317 case FLUSHING_DECODER:
Andreas Huber1aef2112011-01-04 14:01:29 -0800318 if (needShutdown != NULL) {
319 *needShutdown = false;
Andreas Huber53df1a42010-12-22 10:03:04 -0800320 }
321 return true;
322
Andreas Huber1aef2112011-01-04 14:01:29 -0800323 case FLUSHING_DECODER_SHUTDOWN:
324 if (needShutdown != NULL) {
325 *needShutdown = true;
Andreas Huber53df1a42010-12-22 10:03:04 -0800326 }
327 return true;
328
329 default:
330 return false;
331 }
332}
333
Chong Zhang404fced2014-06-11 14:45:31 -0700334void NuPlayer::writeTrackInfo(
335 Parcel* reply, const sp<AMessage> format) const {
336 int32_t trackType;
337 CHECK(format->findInt32("type", &trackType));
338
339 AString lang;
340 CHECK(format->findString("language", &lang));
341
342 reply->writeInt32(2); // write something non-zero
343 reply->writeInt32(trackType);
344 reply->writeString16(String16(lang.c_str()));
345
346 if (trackType == MEDIA_TRACK_TYPE_SUBTITLE) {
347 AString mime;
348 CHECK(format->findString("mime", &mime));
349
350 int32_t isAuto, isDefault, isForced;
351 CHECK(format->findInt32("auto", &isAuto));
352 CHECK(format->findInt32("default", &isDefault));
353 CHECK(format->findInt32("forced", &isForced));
354
355 reply->writeString16(String16(mime.c_str()));
356 reply->writeInt32(isAuto);
357 reply->writeInt32(isDefault);
358 reply->writeInt32(isForced);
359 }
360}
361
Andreas Huberf9334412010-12-15 15:17:42 -0800362void NuPlayer::onMessageReceived(const sp<AMessage> &msg) {
363 switch (msg->what()) {
364 case kWhatSetDataSource:
365 {
Steve Block3856b092011-10-20 11:56:00 +0100366 ALOGV("kWhatSetDataSource");
Andreas Huberf9334412010-12-15 15:17:42 -0800367
368 CHECK(mSource == NULL);
369
Chong Zhang3de157d2014-08-05 20:54:44 -0700370 status_t err = OK;
Andreas Huber5bc087c2010-12-23 10:27:40 -0800371 sp<RefBase> obj;
372 CHECK(msg->findObject("source", &obj));
Chong Zhang3de157d2014-08-05 20:54:44 -0700373 if (obj != NULL) {
374 mSource = static_cast<Source *>(obj.get());
375 looper()->registerHandler(mSource);
376 } else {
377 err = UNKNOWN_ERROR;
378 }
Andreas Huber9575c962013-02-05 13:59:56 -0800379
380 CHECK(mDriver != NULL);
381 sp<NuPlayerDriver> driver = mDriver.promote();
382 if (driver != NULL) {
Chong Zhang3de157d2014-08-05 20:54:44 -0700383 driver->notifySetDataSourceCompleted(err);
Andreas Huber9575c962013-02-05 13:59:56 -0800384 }
385 break;
386 }
387
388 case kWhatPrepare:
389 {
390 mSource->prepareAsync();
Andreas Huberf9334412010-12-15 15:17:42 -0800391 break;
392 }
393
Chong Zhangdcb89b32013-08-06 09:44:47 -0700394 case kWhatGetTrackInfo:
395 {
396 uint32_t replyID;
397 CHECK(msg->senderAwaitsResponse(&replyID));
398
Chong Zhang404fced2014-06-11 14:45:31 -0700399 Parcel* reply;
400 CHECK(msg->findPointer("reply", (void**)&reply));
401
402 size_t inbandTracks = 0;
Chong Zhangdcb89b32013-08-06 09:44:47 -0700403 if (mSource != NULL) {
Chong Zhang404fced2014-06-11 14:45:31 -0700404 inbandTracks = mSource->getTrackCount();
405 }
406
Chong Zhanga7fa1d92014-06-11 14:49:23 -0700407 size_t ccTracks = 0;
408 if (mCCDecoder != NULL) {
409 ccTracks = mCCDecoder->getTrackCount();
410 }
411
Chong Zhang404fced2014-06-11 14:45:31 -0700412 // total track count
Chong Zhanga7fa1d92014-06-11 14:49:23 -0700413 reply->writeInt32(inbandTracks + ccTracks);
Chong Zhang404fced2014-06-11 14:45:31 -0700414
415 // write inband tracks
416 for (size_t i = 0; i < inbandTracks; ++i) {
417 writeTrackInfo(reply, mSource->getTrackInfo(i));
Chong Zhangdcb89b32013-08-06 09:44:47 -0700418 }
419
Chong Zhanga7fa1d92014-06-11 14:49:23 -0700420 // write CC track
421 for (size_t i = 0; i < ccTracks; ++i) {
422 writeTrackInfo(reply, mCCDecoder->getTrackInfo(i));
423 }
424
Chong Zhangdcb89b32013-08-06 09:44:47 -0700425 sp<AMessage> response = new AMessage;
Chong Zhangdcb89b32013-08-06 09:44:47 -0700426 response->postReply(replyID);
427 break;
428 }
429
Robert Shih7c4f0d72014-07-09 18:53:31 -0700430 case kWhatGetSelectedTrack:
431 {
432 status_t err = INVALID_OPERATION;
433 if (mSource != NULL) {
434 err = OK;
435
436 int32_t type32;
437 CHECK(msg->findInt32("type", (int32_t*)&type32));
438 media_track_type type = (media_track_type)type32;
439 ssize_t selectedTrack = mSource->getSelectedTrack(type);
440
441 Parcel* reply;
442 CHECK(msg->findPointer("reply", (void**)&reply));
443 reply->writeInt32(selectedTrack);
444 }
445
446 sp<AMessage> response = new AMessage;
447 response->setInt32("err", err);
448
449 uint32_t replyID;
450 CHECK(msg->senderAwaitsResponse(&replyID));
451 response->postReply(replyID);
452 break;
453 }
454
Chong Zhangdcb89b32013-08-06 09:44:47 -0700455 case kWhatSelectTrack:
456 {
457 uint32_t replyID;
458 CHECK(msg->senderAwaitsResponse(&replyID));
459
Chong Zhang404fced2014-06-11 14:45:31 -0700460 size_t trackIndex;
461 int32_t select;
462 CHECK(msg->findSize("trackIndex", &trackIndex));
463 CHECK(msg->findInt32("select", &select));
464
Chong Zhangdcb89b32013-08-06 09:44:47 -0700465 status_t err = INVALID_OPERATION;
Chong Zhang404fced2014-06-11 14:45:31 -0700466
467 size_t inbandTracks = 0;
Chong Zhangdcb89b32013-08-06 09:44:47 -0700468 if (mSource != NULL) {
Chong Zhang404fced2014-06-11 14:45:31 -0700469 inbandTracks = mSource->getTrackCount();
470 }
Chong Zhanga7fa1d92014-06-11 14:49:23 -0700471 size_t ccTracks = 0;
472 if (mCCDecoder != NULL) {
473 ccTracks = mCCDecoder->getTrackCount();
474 }
Chong Zhang404fced2014-06-11 14:45:31 -0700475
476 if (trackIndex < inbandTracks) {
Chong Zhangdcb89b32013-08-06 09:44:47 -0700477 err = mSource->selectTrack(trackIndex, select);
Robert Shihd3b0bbb2014-07-23 15:00:25 -0700478
479 if (!select && err == OK) {
480 int32_t type;
481 sp<AMessage> info = mSource->getTrackInfo(trackIndex);
482 if (info != NULL
483 && info->findInt32("type", &type)
484 && type == MEDIA_TRACK_TYPE_TIMEDTEXT) {
485 ++mTimedTextGeneration;
486 }
487 }
Chong Zhanga7fa1d92014-06-11 14:49:23 -0700488 } else {
489 trackIndex -= inbandTracks;
490
491 if (trackIndex < ccTracks) {
492 err = mCCDecoder->selectTrack(trackIndex, select);
493 }
Chong Zhangdcb89b32013-08-06 09:44:47 -0700494 }
495
496 sp<AMessage> response = new AMessage;
497 response->setInt32("err", err);
498
499 response->postReply(replyID);
500 break;
501 }
502
Andreas Huberb7c8e912012-11-27 15:02:53 -0800503 case kWhatPollDuration:
504 {
505 int32_t generation;
506 CHECK(msg->findInt32("generation", &generation));
507
508 if (generation != mPollDurationGeneration) {
509 // stale
510 break;
511 }
512
513 int64_t durationUs;
514 if (mDriver != NULL && mSource->getDuration(&durationUs) == OK) {
515 sp<NuPlayerDriver> driver = mDriver.promote();
516 if (driver != NULL) {
517 driver->notifyDuration(durationUs);
518 }
519 }
520
521 msg->post(1000000ll); // poll again in a second.
522 break;
523 }
524
Glenn Kasten11731182011-02-08 17:26:17 -0800525 case kWhatSetVideoNativeWindow:
Andreas Huberf9334412010-12-15 15:17:42 -0800526 {
Steve Block3856b092011-10-20 11:56:00 +0100527 ALOGV("kWhatSetVideoNativeWindow");
Andreas Huberf9334412010-12-15 15:17:42 -0800528
Andreas Huber57a339c2012-12-03 11:18:00 -0800529 mDeferredActions.push_back(
Andreas Huber14f76722013-01-15 09:04:18 -0800530 new ShutdownDecoderAction(
531 false /* audio */, true /* video */));
Andreas Huber57a339c2012-12-03 11:18:00 -0800532
Andreas Huberf9334412010-12-15 15:17:42 -0800533 sp<RefBase> obj;
Glenn Kasten11731182011-02-08 17:26:17 -0800534 CHECK(msg->findObject("native-window", &obj));
Andreas Huberf9334412010-12-15 15:17:42 -0800535
Andreas Huber57a339c2012-12-03 11:18:00 -0800536 mDeferredActions.push_back(
537 new SetSurfaceAction(
538 static_cast<NativeWindowWrapper *>(obj.get())));
James Dong0d268a32012-08-31 12:18:27 -0700539
Andreas Huber57a339c2012-12-03 11:18:00 -0800540 if (obj != NULL) {
541 // If there is a new surface texture, instantiate decoders
542 // again if possible.
543 mDeferredActions.push_back(
544 new SimpleAction(&NuPlayer::performScanSources));
545 }
546
547 processDeferredActions();
Andreas Huberf9334412010-12-15 15:17:42 -0800548 break;
549 }
550
551 case kWhatSetAudioSink:
552 {
Steve Block3856b092011-10-20 11:56:00 +0100553 ALOGV("kWhatSetAudioSink");
Andreas Huberf9334412010-12-15 15:17:42 -0800554
555 sp<RefBase> obj;
556 CHECK(msg->findObject("sink", &obj));
557
558 mAudioSink = static_cast<MediaPlayerBase::AudioSink *>(obj.get());
559 break;
560 }
561
562 case kWhatStart:
563 {
Steve Block3856b092011-10-20 11:56:00 +0100564 ALOGV("kWhatStart");
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800565
Andreas Huber3fe62152011-09-16 15:09:22 -0700566 mVideoIsAVC = false;
Wei Jiabc2fb722014-07-08 16:37:57 -0700567 mOffloadAudio = false;
Andreas Huber1aef2112011-01-04 14:01:29 -0800568 mAudioEOS = false;
569 mVideoEOS = false;
Andreas Huber32f3cef2011-03-02 15:34:46 -0800570 mSkipRenderingAudioUntilMediaTimeUs = -1;
571 mSkipRenderingVideoUntilMediaTimeUs = -1;
Andreas Huber3fe62152011-09-16 15:09:22 -0700572 mVideoLateByUs = 0;
573 mNumFramesTotal = 0;
574 mNumFramesDropped = 0;
Andreas Huber57a339c2012-12-03 11:18:00 -0800575 mStarted = true;
Andreas Huber1aef2112011-01-04 14:01:29 -0800576
Lajos Molnar09524832014-07-17 14:29:51 -0700577 /* instantiate decoders now for secure playback */
578 if (mSourceFlags & Source::FLAG_SECURE) {
579 if (mNativeWindow != NULL) {
580 instantiateDecoder(false, &mVideoDecoder);
581 }
582
583 if (mAudioSink != NULL) {
584 instantiateDecoder(true, &mAudioDecoder);
585 }
586 }
587
Andreas Huber5bc087c2010-12-23 10:27:40 -0800588 mSource->start();
Andreas Huberf9334412010-12-15 15:17:42 -0800589
Andreas Huberd5e56232013-03-12 11:01:43 -0700590 uint32_t flags = 0;
591
592 if (mSource->isRealTime()) {
593 flags |= Renderer::FLAG_REAL_TIME;
594 }
595
Wei Jiabc2fb722014-07-08 16:37:57 -0700596 sp<MetaData> audioMeta = mSource->getFormatMeta(true /* audio */);
597 audio_stream_type_t streamType = AUDIO_STREAM_MUSIC;
598 if (mAudioSink != NULL) {
599 streamType = mAudioSink->getAudioStreamType();
600 }
601
602 sp<AMessage> videoFormat = mSource->getFormat(false /* audio */);
603
604 mOffloadAudio =
605 canOffloadStream(audioMeta, (videoFormat != NULL),
606 true /* is_streaming */, streamType);
607 if (mOffloadAudio) {
608 flags |= Renderer::FLAG_OFFLOAD_AUDIO;
609 }
610
Andreas Huberf9334412010-12-15 15:17:42 -0800611 mRenderer = new Renderer(
612 mAudioSink,
Andreas Huberd5e56232013-03-12 11:01:43 -0700613 new AMessage(kWhatRendererNotify, id()),
614 flags);
Andreas Huberf9334412010-12-15 15:17:42 -0800615
Lajos Molnar09524832014-07-17 14:29:51 -0700616 mRendererLooper = new ALooper;
617 mRendererLooper->setName("NuPlayerRenderer");
618 mRendererLooper->start(false, false, ANDROID_PRIORITY_AUDIO);
619 mRendererLooper->registerHandler(mRenderer);
Andreas Huberf9334412010-12-15 15:17:42 -0800620
Andreas Huber1aef2112011-01-04 14:01:29 -0800621 postScanSources();
Andreas Huberf9334412010-12-15 15:17:42 -0800622 break;
623 }
624
625 case kWhatScanSources:
626 {
Andreas Huber1aef2112011-01-04 14:01:29 -0800627 int32_t generation;
628 CHECK(msg->findInt32("generation", &generation));
629 if (generation != mScanSourcesGeneration) {
630 // Drop obsolete msg.
631 break;
632 }
633
Andreas Huber5bc087c2010-12-23 10:27:40 -0800634 mScanSourcesPending = false;
635
Steve Block3856b092011-10-20 11:56:00 +0100636 ALOGV("scanning sources haveAudio=%d, haveVideo=%d",
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800637 mAudioDecoder != NULL, mVideoDecoder != NULL);
638
Andreas Huberb7c8e912012-11-27 15:02:53 -0800639 bool mHadAnySourcesBefore =
640 (mAudioDecoder != NULL) || (mVideoDecoder != NULL);
641
Haynes Mathew George5d246ef2012-07-09 10:36:57 -0700642 if (mNativeWindow != NULL) {
643 instantiateDecoder(false, &mVideoDecoder);
644 }
Andreas Huberf9334412010-12-15 15:17:42 -0800645
646 if (mAudioSink != NULL) {
Andreas Huber5bc087c2010-12-23 10:27:40 -0800647 instantiateDecoder(true, &mAudioDecoder);
Andreas Huberf9334412010-12-15 15:17:42 -0800648 }
649
Andreas Huberb7c8e912012-11-27 15:02:53 -0800650 if (!mHadAnySourcesBefore
651 && (mAudioDecoder != NULL || mVideoDecoder != NULL)) {
652 // This is the first time we've found anything playable.
653
Andreas Huber9575c962013-02-05 13:59:56 -0800654 if (mSourceFlags & Source::FLAG_DYNAMIC_DURATION) {
Andreas Huberb7c8e912012-11-27 15:02:53 -0800655 schedulePollDuration();
656 }
657 }
658
Andreas Hubereac68ba2011-09-27 12:12:25 -0700659 status_t err;
660 if ((err = mSource->feedMoreTSData()) != OK) {
Andreas Huber1aef2112011-01-04 14:01:29 -0800661 if (mAudioDecoder == NULL && mVideoDecoder == NULL) {
662 // We're not currently decoding anything (no audio or
663 // video tracks found) and we just ran out of input data.
Andreas Hubereac68ba2011-09-27 12:12:25 -0700664
665 if (err == ERROR_END_OF_STREAM) {
666 notifyListener(MEDIA_PLAYBACK_COMPLETE, 0, 0);
667 } else {
668 notifyListener(MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, err);
669 }
Andreas Huber1aef2112011-01-04 14:01:29 -0800670 }
Andreas Huberf9334412010-12-15 15:17:42 -0800671 break;
672 }
673
Andreas Huberfbe9d812012-08-31 14:05:27 -0700674 if ((mAudioDecoder == NULL && mAudioSink != NULL)
675 || (mVideoDecoder == NULL && mNativeWindow != NULL)) {
Andreas Huberf9334412010-12-15 15:17:42 -0800676 msg->post(100000ll);
Andreas Huber5bc087c2010-12-23 10:27:40 -0800677 mScanSourcesPending = true;
Andreas Huberf9334412010-12-15 15:17:42 -0800678 }
679 break;
680 }
681
682 case kWhatVideoNotify:
683 case kWhatAudioNotify:
684 {
685 bool audio = msg->what() == kWhatAudioNotify;
686
Andreas Huberf9334412010-12-15 15:17:42 -0800687 int32_t what;
Lajos Molnar1cd13982014-01-17 15:12:51 -0800688 CHECK(msg->findInt32("what", &what));
Andreas Huberf9334412010-12-15 15:17:42 -0800689
Lajos Molnar1cd13982014-01-17 15:12:51 -0800690 if (what == Decoder::kWhatFillThisBuffer) {
Andreas Huberf9334412010-12-15 15:17:42 -0800691 status_t err = feedDecoderInputData(
Lajos Molnar1cd13982014-01-17 15:12:51 -0800692 audio, msg);
Andreas Huberf9334412010-12-15 15:17:42 -0800693
Andreas Huber5bc087c2010-12-23 10:27:40 -0800694 if (err == -EWOULDBLOCK) {
Andreas Hubereac68ba2011-09-27 12:12:25 -0700695 if (mSource->feedMoreTSData() == OK) {
Andreas Huber1183a4a2011-11-03 11:00:21 -0700696 msg->post(10000ll);
Andreas Huber5bc087c2010-12-23 10:27:40 -0800697 }
Andreas Huberf9334412010-12-15 15:17:42 -0800698 }
Lajos Molnar1cd13982014-01-17 15:12:51 -0800699 } else if (what == Decoder::kWhatEOS) {
Andreas Huberdc9bacd2011-09-26 10:53:29 -0700700 int32_t err;
Lajos Molnar1cd13982014-01-17 15:12:51 -0800701 CHECK(msg->findInt32("err", &err));
Andreas Huberdc9bacd2011-09-26 10:53:29 -0700702
703 if (err == ERROR_END_OF_STREAM) {
Steve Block3856b092011-10-20 11:56:00 +0100704 ALOGV("got %s decoder EOS", audio ? "audio" : "video");
Andreas Huberdc9bacd2011-09-26 10:53:29 -0700705 } else {
Steve Block3856b092011-10-20 11:56:00 +0100706 ALOGV("got %s decoder EOS w/ error %d",
Andreas Huberdc9bacd2011-09-26 10:53:29 -0700707 audio ? "audio" : "video",
708 err);
709 }
710
711 mRenderer->queueEOS(audio, err);
Lajos Molnar1cd13982014-01-17 15:12:51 -0800712 } else if (what == Decoder::kWhatFlushCompleted) {
Andreas Huber1aef2112011-01-04 14:01:29 -0800713 bool needShutdown;
Andreas Huber53df1a42010-12-22 10:03:04 -0800714
Andreas Huberf9334412010-12-15 15:17:42 -0800715 if (audio) {
Andreas Huber1aef2112011-01-04 14:01:29 -0800716 CHECK(IsFlushingState(mFlushingAudio, &needShutdown));
Andreas Huberf9334412010-12-15 15:17:42 -0800717 mFlushingAudio = FLUSHED;
718 } else {
Andreas Huber1aef2112011-01-04 14:01:29 -0800719 CHECK(IsFlushingState(mFlushingVideo, &needShutdown));
Andreas Huberf9334412010-12-15 15:17:42 -0800720 mFlushingVideo = FLUSHED;
Andreas Huber3fe62152011-09-16 15:09:22 -0700721
722 mVideoLateByUs = 0;
Andreas Huberf9334412010-12-15 15:17:42 -0800723 }
724
Steve Block3856b092011-10-20 11:56:00 +0100725 ALOGV("decoder %s flush completed", audio ? "audio" : "video");
Andreas Huberf9334412010-12-15 15:17:42 -0800726
Andreas Huber1aef2112011-01-04 14:01:29 -0800727 if (needShutdown) {
Steve Block3856b092011-10-20 11:56:00 +0100728 ALOGV("initiating %s decoder shutdown",
Andreas Huber53df1a42010-12-22 10:03:04 -0800729 audio ? "audio" : "video");
Andreas Huberf9334412010-12-15 15:17:42 -0800730
Andreas Huber53df1a42010-12-22 10:03:04 -0800731 (audio ? mAudioDecoder : mVideoDecoder)->initiateShutdown();
Andreas Huberf9334412010-12-15 15:17:42 -0800732
Andreas Huber53df1a42010-12-22 10:03:04 -0800733 if (audio) {
734 mFlushingAudio = SHUTTING_DOWN_DECODER;
735 } else {
736 mFlushingVideo = SHUTTING_DOWN_DECODER;
737 }
Andreas Huberf9334412010-12-15 15:17:42 -0800738 }
Andreas Huber3831a062010-12-21 10:22:33 -0800739
740 finishFlushIfPossible();
Lajos Molnar1cd13982014-01-17 15:12:51 -0800741 } else if (what == Decoder::kWhatOutputFormatChanged) {
742 sp<AMessage> format;
743 CHECK(msg->findMessage("format", &format));
744
Andreas Huber31e25082011-01-10 10:38:31 -0800745 if (audio) {
746 int32_t numChannels;
Lajos Molnar1cd13982014-01-17 15:12:51 -0800747 CHECK(format->findInt32(
Andreas Huber516dacf2012-12-03 15:20:40 -0800748 "channel-count", &numChannels));
Andreas Huber2c2814b2010-12-15 17:18:20 -0800749
Andreas Huber31e25082011-01-10 10:38:31 -0800750 int32_t sampleRate;
Lajos Molnar1cd13982014-01-17 15:12:51 -0800751 CHECK(format->findInt32("sample-rate", &sampleRate));
Andreas Huber2c2814b2010-12-15 17:18:20 -0800752
Steve Block3856b092011-10-20 11:56:00 +0100753 ALOGV("Audio output format changed to %d Hz, %d channels",
Andreas Huber31e25082011-01-10 10:38:31 -0800754 sampleRate, numChannels);
Andreas Huber2c2814b2010-12-15 17:18:20 -0800755
Andreas Huber31e25082011-01-10 10:38:31 -0800756 mAudioSink->close();
Eric Laurent1948eb32012-04-13 16:50:19 -0700757
Wei Jiabc2fb722014-07-08 16:37:57 -0700758 uint32_t flags;
Eric Laurent1948eb32012-04-13 16:50:19 -0700759 int64_t durationUs;
Andreas Huber516dacf2012-12-03 15:20:40 -0800760 // FIXME: we should handle the case where the video decoder
761 // is created after we receive the format change indication.
762 // Current code will just make that we select deep buffer
763 // with video which should not be a problem as it should
Eric Laurent1948eb32012-04-13 16:50:19 -0700764 // not prevent from keeping A/V sync.
765 if (mVideoDecoder == NULL &&
766 mSource->getDuration(&durationUs) == OK &&
Andreas Huber516dacf2012-12-03 15:20:40 -0800767 durationUs
768 > AUDIO_SINK_MIN_DEEP_BUFFER_DURATION_US) {
Eric Laurent1948eb32012-04-13 16:50:19 -0700769 flags = AUDIO_OUTPUT_FLAG_DEEP_BUFFER;
770 } else {
771 flags = AUDIO_OUTPUT_FLAG_NONE;
772 }
773
Andreas Huber98065552012-05-03 11:33:01 -0700774 int32_t channelMask;
Lajos Molnar1cd13982014-01-17 15:12:51 -0800775 if (!format->findInt32("channel-mask", &channelMask)) {
Andreas Huber98065552012-05-03 11:33:01 -0700776 channelMask = CHANNEL_MASK_USE_CHANNEL_ORDER;
777 }
778
Wei Jiabc2fb722014-07-08 16:37:57 -0700779 if (mOffloadAudio) {
780 audio_format_t audioFormat = AUDIO_FORMAT_PCM_16_BIT;
781 audio_offload_info_t offloadInfo =
782 AUDIO_INFO_INITIALIZER;
783
784 AString mime;
785 CHECK(format->findString("mime", &mime));
786
787 status_t err =
788 mapMimeToAudioFormat(audioFormat, mime.c_str());
789 if (err != OK) {
790 ALOGE("Couldn't map mime \"%s\" to a valid "
791 "audio_format", mime.c_str());
792 mOffloadAudio = false;
793 } else {
794 ALOGV("Mime \"%s\" mapped to audio_format 0x%x",
795 mime.c_str(), audioFormat);
796
aarti jadhav-gaikwadccad7862014-08-02 16:21:32 +0530797 int32_t aacProfile = -1;
798 if (audioFormat == AUDIO_FORMAT_AAC
799 && format->findInt32("aac-profile", &aacProfile)) {
800 // Redefine AAC format as per aac profile
801 mapAACProfileToAudioFormat(
802 audioFormat,
803 aacProfile);
804 }
805
Wei Jiabc2fb722014-07-08 16:37:57 -0700806 flags |= AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD;
807
808 offloadInfo.duration_us = -1;
809 format->findInt64(
810 "durationUs", &offloadInfo.duration_us);
811
812 int avgBitRate = -1;
813 format->findInt32("bit-rate", &avgBitRate);
814
815 offloadInfo.sample_rate = sampleRate;
816 offloadInfo.channel_mask = channelMask;
817 offloadInfo.format = audioFormat;
818 offloadInfo.stream_type = AUDIO_STREAM_MUSIC;
819 offloadInfo.bit_rate = avgBitRate;
820 offloadInfo.has_video = (mVideoDecoder != NULL);
821 offloadInfo.is_streaming = true;
822
Wei Jia3a2956d2014-07-22 16:01:33 -0700823 ALOGV("try to open AudioSink in offload mode");
Wei Jiabc2fb722014-07-08 16:37:57 -0700824 err = mAudioSink->open(
825 sampleRate,
826 numChannels,
827 (audio_channel_mask_t)channelMask,
828 audioFormat,
829 8 /* bufferCount */,
830 &NuPlayer::Renderer::AudioSinkCallback,
831 mRenderer.get(),
832 (audio_output_flags_t)flags,
833 &offloadInfo);
834
835 if (err == OK) {
836 // If the playback is offloaded to h/w, we pass
837 // the HAL some metadata information.
838 // We don't want to do this for PCM because it
839 // will be going through the AudioFlinger mixer
840 // before reaching the hardware.
841 sp<MetaData> audioMeta =
842 mSource->getFormatMeta(true /* audio */);
843 sendMetaDataToHal(mAudioSink, audioMeta);
844
845 err = mAudioSink->start();
846 }
847 }
848
849 if (err != OK) {
850 // Clean up, fall back to non offload mode.
851 mAudioSink->close();
852 mAudioDecoder.clear();
853 mRenderer->signalDisableOffloadAudio();
854 mOffloadAudio = false;
855
856 instantiateDecoder(
857 true /* audio */, &mAudioDecoder);
858 }
859 }
860
861 if (!mOffloadAudio) {
862 flags &= ~AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD;
Wei Jia3a2956d2014-07-22 16:01:33 -0700863 ALOGV("open AudioSink in NON-offload mode");
Wei Jiabc2fb722014-07-08 16:37:57 -0700864 CHECK_EQ(mAudioSink->open(
865 sampleRate,
866 numChannels,
867 (audio_channel_mask_t)channelMask,
868 AUDIO_FORMAT_PCM_16_BIT,
869 8 /* bufferCount */,
870 NULL,
871 NULL,
872 (audio_output_flags_t)flags),
873 (status_t)OK);
874 mAudioSink->start();
875 }
Andreas Huber2c2814b2010-12-15 17:18:20 -0800876
Andreas Huber31e25082011-01-10 10:38:31 -0800877 mRenderer->signalAudioSinkChanged();
878 } else {
879 // video
Chong Zhangced1c2f2014-08-08 15:22:35 -0700880 sp<AMessage> inputFormat =
881 mSource->getFormat(false /* audio */);
Andreas Huber3831a062010-12-21 10:22:33 -0800882
Chong Zhangced1c2f2014-08-08 15:22:35 -0700883 updateVideoSize(inputFormat, format);
Andreas Huber31e25082011-01-10 10:38:31 -0800884 }
Lajos Molnar1cd13982014-01-17 15:12:51 -0800885 } else if (what == Decoder::kWhatShutdownCompleted) {
Steve Block3856b092011-10-20 11:56:00 +0100886 ALOGV("%s shutdown completed", audio ? "audio" : "video");
Andreas Huber3831a062010-12-21 10:22:33 -0800887 if (audio) {
888 mAudioDecoder.clear();
889
890 CHECK_EQ((int)mFlushingAudio, (int)SHUTTING_DOWN_DECODER);
891 mFlushingAudio = SHUT_DOWN;
892 } else {
893 mVideoDecoder.clear();
894
895 CHECK_EQ((int)mFlushingVideo, (int)SHUTTING_DOWN_DECODER);
896 mFlushingVideo = SHUT_DOWN;
897 }
898
899 finishFlushIfPossible();
Lajos Molnar1cd13982014-01-17 15:12:51 -0800900 } else if (what == Decoder::kWhatError) {
Steve Block29357bc2012-01-06 19:20:56 +0000901 ALOGE("Received error from %s decoder, aborting playback.",
Andreas Huberc92fd242011-08-16 13:48:44 -0700902 audio ? "audio" : "video");
903
Chong Zhangf4c0a942014-08-11 15:14:10 -0700904 status_t err;
905 if (!msg->findInt32("err", &err)) {
906 err = UNKNOWN_ERROR;
907 }
908 mRenderer->queueEOS(audio, err);
Lajos Molnar1cd13982014-01-17 15:12:51 -0800909 } else if (what == Decoder::kWhatDrainThisBuffer) {
910 renderBuffer(audio, msg);
911 } else {
912 ALOGV("Unhandled decoder notification %d '%c%c%c%c'.",
Andreas Hubera1f8ab02012-11-30 10:53:22 -0800913 what,
914 what >> 24,
915 (what >> 16) & 0xff,
916 (what >> 8) & 0xff,
917 what & 0xff);
Andreas Huberf9334412010-12-15 15:17:42 -0800918 }
919
920 break;
921 }
922
923 case kWhatRendererNotify:
924 {
925 int32_t what;
926 CHECK(msg->findInt32("what", &what));
927
928 if (what == Renderer::kWhatEOS) {
929 int32_t audio;
930 CHECK(msg->findInt32("audio", &audio));
931
Andreas Huberc92fd242011-08-16 13:48:44 -0700932 int32_t finalResult;
933 CHECK(msg->findInt32("finalResult", &finalResult));
934
Andreas Huberf9334412010-12-15 15:17:42 -0800935 if (audio) {
936 mAudioEOS = true;
937 } else {
938 mVideoEOS = true;
939 }
940
Andreas Huberc92fd242011-08-16 13:48:44 -0700941 if (finalResult == ERROR_END_OF_STREAM) {
Steve Block3856b092011-10-20 11:56:00 +0100942 ALOGV("reached %s EOS", audio ? "audio" : "video");
Andreas Huberc92fd242011-08-16 13:48:44 -0700943 } else {
Steve Block29357bc2012-01-06 19:20:56 +0000944 ALOGE("%s track encountered an error (%d)",
Andreas Huberc92fd242011-08-16 13:48:44 -0700945 audio ? "audio" : "video", finalResult);
946
947 notifyListener(
948 MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, finalResult);
949 }
Andreas Huberf9334412010-12-15 15:17:42 -0800950
951 if ((mAudioEOS || mAudioDecoder == NULL)
952 && (mVideoEOS || mVideoDecoder == NULL)) {
953 notifyListener(MEDIA_PLAYBACK_COMPLETE, 0, 0);
954 }
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800955 } else if (what == Renderer::kWhatPosition) {
956 int64_t positionUs;
957 CHECK(msg->findInt64("positionUs", &positionUs));
958
Andreas Huber3fe62152011-09-16 15:09:22 -0700959 CHECK(msg->findInt64("videoLateByUs", &mVideoLateByUs));
960
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800961 if (mDriver != NULL) {
962 sp<NuPlayerDriver> driver = mDriver.promote();
963 if (driver != NULL) {
964 driver->notifyPosition(positionUs);
Andreas Huber3fe62152011-09-16 15:09:22 -0700965
966 driver->notifyFrameStats(
967 mNumFramesTotal, mNumFramesDropped);
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800968 }
969 }
Andreas Huber3fe62152011-09-16 15:09:22 -0700970 } else if (what == Renderer::kWhatFlushComplete) {
Andreas Huberf9334412010-12-15 15:17:42 -0800971 int32_t audio;
972 CHECK(msg->findInt32("audio", &audio));
973
Steve Block3856b092011-10-20 11:56:00 +0100974 ALOGV("renderer %s flush completed.", audio ? "audio" : "video");
James Dongf57b4ea2012-07-20 13:38:36 -0700975 } else if (what == Renderer::kWhatVideoRenderingStart) {
976 notifyListener(MEDIA_INFO, MEDIA_INFO_RENDERING_START, 0);
Lajos Molnarcbaffcf2013-08-14 18:30:38 -0700977 } else if (what == Renderer::kWhatMediaRenderingStart) {
978 ALOGV("media rendering started");
979 notifyListener(MEDIA_STARTED, 0, 0);
Wei Jia3a2956d2014-07-22 16:01:33 -0700980 } else if (what == Renderer::kWhatAudioOffloadTearDown) {
981 ALOGV("Tear down audio offload, fall back to s/w path");
982 int64_t positionUs;
983 CHECK(msg->findInt64("positionUs", &positionUs));
984 mAudioSink->close();
985 mAudioDecoder.clear();
986 mRenderer->flush(true /* audio */);
987 if (mVideoDecoder != NULL) {
988 mRenderer->flush(false /* audio */);
989 }
990 mRenderer->signalDisableOffloadAudio();
991 mOffloadAudio = false;
992
993 performSeek(positionUs);
994 instantiateDecoder(true /* audio */, &mAudioDecoder);
Andreas Huberf9334412010-12-15 15:17:42 -0800995 }
996 break;
997 }
998
999 case kWhatMoreDataQueued:
1000 {
1001 break;
1002 }
1003
Andreas Huber1aef2112011-01-04 14:01:29 -08001004 case kWhatReset:
1005 {
Steve Block3856b092011-10-20 11:56:00 +01001006 ALOGV("kWhatReset");
Andreas Huber1aef2112011-01-04 14:01:29 -08001007
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001008 mDeferredActions.push_back(
Andreas Huber14f76722013-01-15 09:04:18 -08001009 new ShutdownDecoderAction(
1010 true /* audio */, true /* video */));
Andreas Huberb7c8e912012-11-27 15:02:53 -08001011
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001012 mDeferredActions.push_back(
1013 new SimpleAction(&NuPlayer::performReset));
Andreas Huberb58ce9f2011-11-28 16:27:35 -08001014
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001015 processDeferredActions();
Andreas Huber1aef2112011-01-04 14:01:29 -08001016 break;
1017 }
1018
Andreas Huber43c3e6c2011-01-05 12:17:08 -08001019 case kWhatSeek:
1020 {
1021 int64_t seekTimeUs;
1022 CHECK(msg->findInt64("seekTimeUs", &seekTimeUs));
1023
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001024 ALOGV("kWhatSeek seekTimeUs=%lld us", seekTimeUs);
Andreas Huber43c3e6c2011-01-05 12:17:08 -08001025
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001026 mDeferredActions.push_back(
1027 new SimpleAction(&NuPlayer::performDecoderFlush));
Andreas Huber43c3e6c2011-01-05 12:17:08 -08001028
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001029 mDeferredActions.push_back(new SeekAction(seekTimeUs));
Andreas Huber43c3e6c2011-01-05 12:17:08 -08001030
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001031 processDeferredActions();
Andreas Huber43c3e6c2011-01-05 12:17:08 -08001032 break;
1033 }
1034
Andreas Huberb4082222011-01-20 15:23:04 -08001035 case kWhatPause:
1036 {
1037 CHECK(mRenderer != NULL);
Roger Jönssonfba60da2013-01-21 17:15:45 +01001038 mSource->pause();
Andreas Huberb4082222011-01-20 15:23:04 -08001039 mRenderer->pause();
1040 break;
1041 }
1042
1043 case kWhatResume:
1044 {
1045 CHECK(mRenderer != NULL);
Roger Jönssonfba60da2013-01-21 17:15:45 +01001046 mSource->resume();
Andreas Huberb4082222011-01-20 15:23:04 -08001047 mRenderer->resume();
1048 break;
1049 }
1050
Andreas Huberb5f25f02013-02-05 10:14:26 -08001051 case kWhatSourceNotify:
1052 {
Andreas Huber9575c962013-02-05 13:59:56 -08001053 onSourceNotify(msg);
Andreas Huberb5f25f02013-02-05 10:14:26 -08001054 break;
1055 }
1056
Chong Zhanga7fa1d92014-06-11 14:49:23 -07001057 case kWhatClosedCaptionNotify:
1058 {
1059 onClosedCaptionNotify(msg);
1060 break;
1061 }
1062
Andreas Huberf9334412010-12-15 15:17:42 -08001063 default:
1064 TRESPASS();
1065 break;
1066 }
1067}
1068
Andreas Huber3831a062010-12-21 10:22:33 -08001069void NuPlayer::finishFlushIfPossible() {
1070 if (mFlushingAudio != FLUSHED && mFlushingAudio != SHUT_DOWN) {
1071 return;
1072 }
1073
1074 if (mFlushingVideo != FLUSHED && mFlushingVideo != SHUT_DOWN) {
1075 return;
1076 }
1077
Steve Block3856b092011-10-20 11:56:00 +01001078 ALOGV("both audio and video are flushed now.");
Andreas Huber3831a062010-12-21 10:22:33 -08001079
Andreas Huber6e3d3112011-11-28 12:36:11 -08001080 if (mTimeDiscontinuityPending) {
1081 mRenderer->signalTimeDiscontinuity();
1082 mTimeDiscontinuityPending = false;
1083 }
Andreas Huber3831a062010-12-21 10:22:33 -08001084
Andreas Huber22fc52f2011-01-05 16:24:27 -08001085 if (mAudioDecoder != NULL) {
Andreas Huber3831a062010-12-21 10:22:33 -08001086 mAudioDecoder->signalResume();
1087 }
1088
Andreas Huber22fc52f2011-01-05 16:24:27 -08001089 if (mVideoDecoder != NULL) {
Andreas Huber3831a062010-12-21 10:22:33 -08001090 mVideoDecoder->signalResume();
1091 }
1092
1093 mFlushingAudio = NONE;
1094 mFlushingVideo = NONE;
Andreas Huber3831a062010-12-21 10:22:33 -08001095
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001096 processDeferredActions();
Andreas Huber1aef2112011-01-04 14:01:29 -08001097}
1098
1099void NuPlayer::postScanSources() {
1100 if (mScanSourcesPending) {
1101 return;
1102 }
1103
1104 sp<AMessage> msg = new AMessage(kWhatScanSources, id());
1105 msg->setInt32("generation", mScanSourcesGeneration);
1106 msg->post();
1107
1108 mScanSourcesPending = true;
1109}
1110
Andreas Huber5bc087c2010-12-23 10:27:40 -08001111status_t NuPlayer::instantiateDecoder(bool audio, sp<Decoder> *decoder) {
Andreas Huberf9334412010-12-15 15:17:42 -08001112 if (*decoder != NULL) {
1113 return OK;
1114 }
1115
Andreas Huber84066782011-08-16 09:34:26 -07001116 sp<AMessage> format = mSource->getFormat(audio);
Andreas Huberf9334412010-12-15 15:17:42 -08001117
Andreas Huber84066782011-08-16 09:34:26 -07001118 if (format == NULL) {
Andreas Huberf9334412010-12-15 15:17:42 -08001119 return -EWOULDBLOCK;
1120 }
1121
Andreas Huber3fe62152011-09-16 15:09:22 -07001122 if (!audio) {
Andreas Huber84066782011-08-16 09:34:26 -07001123 AString mime;
1124 CHECK(format->findString("mime", &mime));
1125 mVideoIsAVC = !strcasecmp(MEDIA_MIMETYPE_VIDEO_AVC, mime.c_str());
Chong Zhanga7fa1d92014-06-11 14:49:23 -07001126
1127 sp<AMessage> ccNotify = new AMessage(kWhatClosedCaptionNotify, id());
1128 mCCDecoder = new CCDecoder(ccNotify);
Lajos Molnar09524832014-07-17 14:29:51 -07001129
1130 if (mSourceFlags & Source::FLAG_SECURE) {
1131 format->setInt32("secure", true);
1132 }
Andreas Huber3fe62152011-09-16 15:09:22 -07001133 }
1134
Andreas Huberf9334412010-12-15 15:17:42 -08001135 sp<AMessage> notify =
1136 new AMessage(audio ? kWhatAudioNotify : kWhatVideoNotify,
1137 id());
1138
Wei Jiabc2fb722014-07-08 16:37:57 -07001139 if (audio) {
1140 if (mOffloadAudio) {
1141 *decoder = new DecoderPassThrough(notify);
1142 } else {
1143 *decoder = new Decoder(notify);
1144 }
1145 } else {
1146 *decoder = new Decoder(notify, mNativeWindow);
1147 }
Lajos Molnar1cd13982014-01-17 15:12:51 -08001148 (*decoder)->init();
Andreas Huber84066782011-08-16 09:34:26 -07001149 (*decoder)->configure(format);
Andreas Huberf9334412010-12-15 15:17:42 -08001150
Lajos Molnar09524832014-07-17 14:29:51 -07001151 // allocate buffers to decrypt widevine source buffers
1152 if (!audio && (mSourceFlags & Source::FLAG_SECURE)) {
1153 Vector<sp<ABuffer> > inputBufs;
1154 CHECK_EQ((*decoder)->getInputBuffers(&inputBufs), (status_t)OK);
1155
1156 Vector<MediaBuffer *> mediaBufs;
1157 for (size_t i = 0; i < inputBufs.size(); i++) {
1158 const sp<ABuffer> &buffer = inputBufs[i];
1159 MediaBuffer *mbuf = new MediaBuffer(buffer->data(), buffer->size());
1160 mediaBufs.push(mbuf);
1161 }
1162
1163 status_t err = mSource->setBuffers(audio, mediaBufs);
1164 if (err != OK) {
1165 for (size_t i = 0; i < mediaBufs.size(); ++i) {
1166 mediaBufs[i]->release();
1167 }
1168 mediaBufs.clear();
1169 ALOGE("Secure source didn't support secure mediaBufs.");
1170 return err;
1171 }
1172 }
Andreas Huberf9334412010-12-15 15:17:42 -08001173 return OK;
1174}
1175
1176status_t NuPlayer::feedDecoderInputData(bool audio, const sp<AMessage> &msg) {
1177 sp<AMessage> reply;
1178 CHECK(msg->findMessage("reply", &reply));
1179
Wei Jiab189a5b2014-08-07 06:11:39 +00001180 if ((audio && IsFlushingState(mFlushingAudio))
1181 || (!audio && IsFlushingState(mFlushingVideo))) {
1182 reply->setInt32("err", INFO_DISCONTINUITY);
1183 reply->post();
1184 return OK;
Andreas Huberf9334412010-12-15 15:17:42 -08001185 }
1186
1187 sp<ABuffer> accessUnit;
Andreas Huberf9334412010-12-15 15:17:42 -08001188
Andreas Huber3fe62152011-09-16 15:09:22 -07001189 bool dropAccessUnit;
1190 do {
1191 status_t err = mSource->dequeueAccessUnit(audio, &accessUnit);
Andreas Huber5bc087c2010-12-23 10:27:40 -08001192
Andreas Huber3fe62152011-09-16 15:09:22 -07001193 if (err == -EWOULDBLOCK) {
1194 return err;
1195 } else if (err != OK) {
1196 if (err == INFO_DISCONTINUITY) {
1197 int32_t type;
1198 CHECK(accessUnit->meta()->findInt32("discontinuity", &type));
Andreas Huber53df1a42010-12-22 10:03:04 -08001199
Andreas Huber3fe62152011-09-16 15:09:22 -07001200 bool formatChange =
Andreas Huber6e3d3112011-11-28 12:36:11 -08001201 (audio &&
1202 (type & ATSParser::DISCONTINUITY_AUDIO_FORMAT))
1203 || (!audio &&
1204 (type & ATSParser::DISCONTINUITY_VIDEO_FORMAT));
Andreas Huber53df1a42010-12-22 10:03:04 -08001205
Andreas Huber6e3d3112011-11-28 12:36:11 -08001206 bool timeChange = (type & ATSParser::DISCONTINUITY_TIME) != 0;
1207
Steve Blockdf64d152012-01-04 20:05:49 +00001208 ALOGI("%s discontinuity (formatChange=%d, time=%d)",
Andreas Huber6e3d3112011-11-28 12:36:11 -08001209 audio ? "audio" : "video", formatChange, timeChange);
Andreas Huber32f3cef2011-03-02 15:34:46 -08001210
Andreas Huber3fe62152011-09-16 15:09:22 -07001211 if (audio) {
1212 mSkipRenderingAudioUntilMediaTimeUs = -1;
1213 } else {
1214 mSkipRenderingVideoUntilMediaTimeUs = -1;
1215 }
Andreas Huber32f3cef2011-03-02 15:34:46 -08001216
Andreas Huber6e3d3112011-11-28 12:36:11 -08001217 if (timeChange) {
1218 sp<AMessage> extra;
1219 if (accessUnit->meta()->findMessage("extra", &extra)
1220 && extra != NULL) {
1221 int64_t resumeAtMediaTimeUs;
1222 if (extra->findInt64(
1223 "resume-at-mediatimeUs", &resumeAtMediaTimeUs)) {
Steve Blockdf64d152012-01-04 20:05:49 +00001224 ALOGI("suppressing rendering of %s until %lld us",
Andreas Huber6e3d3112011-11-28 12:36:11 -08001225 audio ? "audio" : "video", resumeAtMediaTimeUs);
Andreas Huber3fe62152011-09-16 15:09:22 -07001226
Andreas Huber6e3d3112011-11-28 12:36:11 -08001227 if (audio) {
1228 mSkipRenderingAudioUntilMediaTimeUs =
1229 resumeAtMediaTimeUs;
1230 } else {
1231 mSkipRenderingVideoUntilMediaTimeUs =
1232 resumeAtMediaTimeUs;
1233 }
Andreas Huber3fe62152011-09-16 15:09:22 -07001234 }
Andreas Huber32f3cef2011-03-02 15:34:46 -08001235 }
1236 }
Andreas Huber3fe62152011-09-16 15:09:22 -07001237
Andreas Huber6e3d3112011-11-28 12:36:11 -08001238 mTimeDiscontinuityPending =
1239 mTimeDiscontinuityPending || timeChange;
1240
Robert Shiha2981012014-07-30 17:41:24 -07001241 if (mFlushingAudio == NONE && mFlushingVideo == NONE) {
1242 // And we'll resume scanning sources once we're done
1243 // flushing.
1244 mDeferredActions.push_front(
1245 new SimpleAction(
1246 &NuPlayer::performScanSources));
1247 }
1248
Andreas Huber6e3d3112011-11-28 12:36:11 -08001249 if (formatChange || timeChange) {
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001250
Robert Shih6d0a94e2014-01-23 16:18:22 -08001251 sp<AMessage> newFormat = mSource->getFormat(audio);
1252 sp<Decoder> &decoder = audio ? mAudioDecoder : mVideoDecoder;
1253 if (formatChange && !decoder->supportsSeamlessFormatChange(newFormat)) {
1254 flushDecoder(audio, /* needShutdown = */ true);
1255 } else {
1256 flushDecoder(audio, /* needShutdown = */ false);
1257 err = OK;
1258 }
Andreas Huber6e3d3112011-11-28 12:36:11 -08001259 } else {
1260 // This stream is unaffected by the discontinuity
1261
1262 if (audio) {
1263 mFlushingAudio = FLUSHED;
1264 } else {
1265 mFlushingVideo = FLUSHED;
1266 }
1267
1268 finishFlushIfPossible();
1269
1270 return -EWOULDBLOCK;
1271 }
Andreas Huber32f3cef2011-03-02 15:34:46 -08001272 }
1273
Andreas Huber3fe62152011-09-16 15:09:22 -07001274 reply->setInt32("err", err);
1275 reply->post();
1276 return OK;
Andreas Huberf9334412010-12-15 15:17:42 -08001277 }
1278
Andreas Huber3fe62152011-09-16 15:09:22 -07001279 if (!audio) {
1280 ++mNumFramesTotal;
1281 }
1282
1283 dropAccessUnit = false;
1284 if (!audio
Lajos Molnar09524832014-07-17 14:29:51 -07001285 && !(mSourceFlags & Source::FLAG_SECURE)
Andreas Huber3fe62152011-09-16 15:09:22 -07001286 && mVideoLateByUs > 100000ll
1287 && mVideoIsAVC
1288 && !IsAVCReferenceFrame(accessUnit)) {
1289 dropAccessUnit = true;
1290 ++mNumFramesDropped;
1291 }
1292 } while (dropAccessUnit);
Andreas Huberf9334412010-12-15 15:17:42 -08001293
Steve Block3856b092011-10-20 11:56:00 +01001294 // ALOGV("returned a valid buffer of %s data", audio ? "audio" : "video");
Andreas Huberf9334412010-12-15 15:17:42 -08001295
1296#if 0
1297 int64_t mediaTimeUs;
1298 CHECK(accessUnit->meta()->findInt64("timeUs", &mediaTimeUs));
Steve Block3856b092011-10-20 11:56:00 +01001299 ALOGV("feeding %s input buffer at media time %.2f secs",
Andreas Huberf9334412010-12-15 15:17:42 -08001300 audio ? "audio" : "video",
1301 mediaTimeUs / 1E6);
1302#endif
1303
Chong Zhanga7fa1d92014-06-11 14:49:23 -07001304 if (!audio) {
1305 mCCDecoder->decode(accessUnit);
1306 }
1307
Andreas Huber2d8bedd2012-02-21 14:38:23 -08001308 reply->setBuffer("buffer", accessUnit);
Andreas Huberf9334412010-12-15 15:17:42 -08001309 reply->post();
1310
1311 return OK;
1312}
1313
1314void NuPlayer::renderBuffer(bool audio, const sp<AMessage> &msg) {
Steve Block3856b092011-10-20 11:56:00 +01001315 // ALOGV("renderBuffer %s", audio ? "audio" : "video");
Andreas Huberf9334412010-12-15 15:17:42 -08001316
1317 sp<AMessage> reply;
1318 CHECK(msg->findMessage("reply", &reply));
1319
Andreas Huber18ac5402011-08-31 15:04:25 -07001320 if (IsFlushingState(audio ? mFlushingAudio : mFlushingVideo)) {
1321 // We're currently attempting to flush the decoder, in order
1322 // to complete this, the decoder wants all its buffers back,
1323 // so we don't want any output buffers it sent us (from before
1324 // we initiated the flush) to be stuck in the renderer's queue.
1325
Steve Block3856b092011-10-20 11:56:00 +01001326 ALOGV("we're still flushing the %s decoder, sending its output buffer"
Andreas Huber18ac5402011-08-31 15:04:25 -07001327 " right back.", audio ? "audio" : "video");
1328
1329 reply->post();
1330 return;
1331 }
1332
Andreas Huber2d8bedd2012-02-21 14:38:23 -08001333 sp<ABuffer> buffer;
1334 CHECK(msg->findBuffer("buffer", &buffer));
Andreas Huberf9334412010-12-15 15:17:42 -08001335
Chong Zhanga7fa1d92014-06-11 14:49:23 -07001336 int64_t mediaTimeUs;
1337 CHECK(buffer->meta()->findInt64("timeUs", &mediaTimeUs));
1338
Andreas Huber32f3cef2011-03-02 15:34:46 -08001339 int64_t &skipUntilMediaTimeUs =
1340 audio
1341 ? mSkipRenderingAudioUntilMediaTimeUs
1342 : mSkipRenderingVideoUntilMediaTimeUs;
1343
1344 if (skipUntilMediaTimeUs >= 0) {
Andreas Huber32f3cef2011-03-02 15:34:46 -08001345
1346 if (mediaTimeUs < skipUntilMediaTimeUs) {
Steve Block3856b092011-10-20 11:56:00 +01001347 ALOGV("dropping %s buffer at time %lld as requested.",
Andreas Huber32f3cef2011-03-02 15:34:46 -08001348 audio ? "audio" : "video",
1349 mediaTimeUs);
1350
1351 reply->post();
1352 return;
1353 }
1354
1355 skipUntilMediaTimeUs = -1;
1356 }
1357
Chong Zhanga7fa1d92014-06-11 14:49:23 -07001358 if (!audio && mCCDecoder->isSelected()) {
1359 mCCDecoder->display(mediaTimeUs);
1360 }
1361
Andreas Huberf9334412010-12-15 15:17:42 -08001362 mRenderer->queueBuffer(audio, buffer, reply);
1363}
1364
Chong Zhangced1c2f2014-08-08 15:22:35 -07001365void NuPlayer::updateVideoSize(
1366 const sp<AMessage> &inputFormat,
1367 const sp<AMessage> &outputFormat) {
1368 if (inputFormat == NULL) {
1369 ALOGW("Unknown video size, reporting 0x0!");
1370 notifyListener(MEDIA_SET_VIDEO_SIZE, 0, 0);
1371 return;
1372 }
1373
1374 int32_t displayWidth, displayHeight;
1375 int32_t cropLeft, cropTop, cropRight, cropBottom;
1376
1377 if (outputFormat != NULL) {
1378 int32_t width, height;
1379 CHECK(outputFormat->findInt32("width", &width));
1380 CHECK(outputFormat->findInt32("height", &height));
1381
1382 int32_t cropLeft, cropTop, cropRight, cropBottom;
1383 CHECK(outputFormat->findRect(
1384 "crop",
1385 &cropLeft, &cropTop, &cropRight, &cropBottom));
1386
1387 displayWidth = cropRight - cropLeft + 1;
1388 displayHeight = cropBottom - cropTop + 1;
1389
1390 ALOGV("Video output format changed to %d x %d "
1391 "(crop: %d x %d @ (%d, %d))",
1392 width, height,
1393 displayWidth,
1394 displayHeight,
1395 cropLeft, cropTop);
1396 } else {
1397 CHECK(inputFormat->findInt32("width", &displayWidth));
1398 CHECK(inputFormat->findInt32("height", &displayHeight));
1399
1400 ALOGV("Video input format %d x %d", displayWidth, displayHeight);
1401 }
1402
1403 // Take into account sample aspect ratio if necessary:
1404 int32_t sarWidth, sarHeight;
1405 if (inputFormat->findInt32("sar-width", &sarWidth)
1406 && inputFormat->findInt32("sar-height", &sarHeight)) {
1407 ALOGV("Sample aspect ratio %d : %d", sarWidth, sarHeight);
1408
1409 displayWidth = (displayWidth * sarWidth) / sarHeight;
1410
1411 ALOGV("display dimensions %d x %d", displayWidth, displayHeight);
1412 }
1413
1414 int32_t rotationDegrees;
1415 if (!inputFormat->findInt32("rotation-degrees", &rotationDegrees)) {
1416 rotationDegrees = 0;
1417 }
1418
1419 if (rotationDegrees == 90 || rotationDegrees == 270) {
1420 int32_t tmp = displayWidth;
1421 displayWidth = displayHeight;
1422 displayHeight = tmp;
1423 }
1424
1425 notifyListener(
1426 MEDIA_SET_VIDEO_SIZE,
1427 displayWidth,
1428 displayHeight);
1429}
1430
Chong Zhangdcb89b32013-08-06 09:44:47 -07001431void NuPlayer::notifyListener(int msg, int ext1, int ext2, const Parcel *in) {
Andreas Huber43c3e6c2011-01-05 12:17:08 -08001432 if (mDriver == NULL) {
Andreas Huberf9334412010-12-15 15:17:42 -08001433 return;
1434 }
1435
Andreas Huber43c3e6c2011-01-05 12:17:08 -08001436 sp<NuPlayerDriver> driver = mDriver.promote();
Andreas Huberf9334412010-12-15 15:17:42 -08001437
Andreas Huber43c3e6c2011-01-05 12:17:08 -08001438 if (driver == NULL) {
Andreas Huberf9334412010-12-15 15:17:42 -08001439 return;
1440 }
1441
Chong Zhangdcb89b32013-08-06 09:44:47 -07001442 driver->notifyListener(msg, ext1, ext2, in);
Andreas Huberf9334412010-12-15 15:17:42 -08001443}
1444
Andreas Huber1aef2112011-01-04 14:01:29 -08001445void NuPlayer::flushDecoder(bool audio, bool needShutdown) {
Andreas Huber14f76722013-01-15 09:04:18 -08001446 ALOGV("[%s] flushDecoder needShutdown=%d",
1447 audio ? "audio" : "video", needShutdown);
1448
Andreas Huber6e3d3112011-11-28 12:36:11 -08001449 if ((audio && mAudioDecoder == NULL) || (!audio && mVideoDecoder == NULL)) {
Steve Blockdf64d152012-01-04 20:05:49 +00001450 ALOGI("flushDecoder %s without decoder present",
Andreas Huber6e3d3112011-11-28 12:36:11 -08001451 audio ? "audio" : "video");
1452 }
1453
Andreas Huber1aef2112011-01-04 14:01:29 -08001454 // Make sure we don't continue to scan sources until we finish flushing.
1455 ++mScanSourcesGeneration;
Andreas Huber43c3e6c2011-01-05 12:17:08 -08001456 mScanSourcesPending = false;
Andreas Huber1aef2112011-01-04 14:01:29 -08001457
1458 (audio ? mAudioDecoder : mVideoDecoder)->signalFlush();
1459 mRenderer->flush(audio);
1460
1461 FlushStatus newStatus =
1462 needShutdown ? FLUSHING_DECODER_SHUTDOWN : FLUSHING_DECODER;
1463
1464 if (audio) {
1465 CHECK(mFlushingAudio == NONE
1466 || mFlushingAudio == AWAITING_DISCONTINUITY);
1467
1468 mFlushingAudio = newStatus;
1469
1470 if (mFlushingVideo == NONE) {
1471 mFlushingVideo = (mVideoDecoder != NULL)
1472 ? AWAITING_DISCONTINUITY
1473 : FLUSHED;
1474 }
1475 } else {
1476 CHECK(mFlushingVideo == NONE
1477 || mFlushingVideo == AWAITING_DISCONTINUITY);
1478
1479 mFlushingVideo = newStatus;
1480
1481 if (mFlushingAudio == NONE) {
1482 mFlushingAudio = (mAudioDecoder != NULL)
1483 ? AWAITING_DISCONTINUITY
1484 : FLUSHED;
1485 }
1486 }
1487}
1488
Chong Zhangced1c2f2014-08-08 15:22:35 -07001489void NuPlayer::queueDecoderShutdown(
1490 bool audio, bool video, const sp<AMessage> &reply) {
1491 ALOGI("queueDecoderShutdown audio=%d, video=%d", audio, video);
Andreas Huber84066782011-08-16 09:34:26 -07001492
Chong Zhangced1c2f2014-08-08 15:22:35 -07001493 mDeferredActions.push_back(
1494 new ShutdownDecoderAction(audio, video));
Andreas Huber84066782011-08-16 09:34:26 -07001495
Chong Zhangced1c2f2014-08-08 15:22:35 -07001496 mDeferredActions.push_back(
1497 new SimpleAction(&NuPlayer::performScanSources));
Andreas Huber84066782011-08-16 09:34:26 -07001498
Chong Zhangced1c2f2014-08-08 15:22:35 -07001499 mDeferredActions.push_back(new PostMessageAction(reply));
1500
1501 processDeferredActions();
Andreas Huber84066782011-08-16 09:34:26 -07001502}
1503
James Dong0d268a32012-08-31 12:18:27 -07001504status_t NuPlayer::setVideoScalingMode(int32_t mode) {
1505 mVideoScalingMode = mode;
Andreas Huber57a339c2012-12-03 11:18:00 -08001506 if (mNativeWindow != NULL) {
James Dong0d268a32012-08-31 12:18:27 -07001507 status_t ret = native_window_set_scaling_mode(
1508 mNativeWindow->getNativeWindow().get(), mVideoScalingMode);
1509 if (ret != OK) {
1510 ALOGE("Failed to set scaling mode (%d): %s",
1511 -ret, strerror(-ret));
1512 return ret;
1513 }
1514 }
1515 return OK;
1516}
1517
Chong Zhangdcb89b32013-08-06 09:44:47 -07001518status_t NuPlayer::getTrackInfo(Parcel* reply) const {
1519 sp<AMessage> msg = new AMessage(kWhatGetTrackInfo, id());
1520 msg->setPointer("reply", reply);
1521
1522 sp<AMessage> response;
1523 status_t err = msg->postAndAwaitResponse(&response);
1524 return err;
1525}
1526
Robert Shih7c4f0d72014-07-09 18:53:31 -07001527status_t NuPlayer::getSelectedTrack(int32_t type, Parcel* reply) const {
1528 sp<AMessage> msg = new AMessage(kWhatGetSelectedTrack, id());
1529 msg->setPointer("reply", reply);
1530 msg->setInt32("type", type);
1531
1532 sp<AMessage> response;
1533 status_t err = msg->postAndAwaitResponse(&response);
1534 if (err == OK && response != NULL) {
1535 CHECK(response->findInt32("err", &err));
1536 }
1537 return err;
1538}
1539
Chong Zhangdcb89b32013-08-06 09:44:47 -07001540status_t NuPlayer::selectTrack(size_t trackIndex, bool select) {
1541 sp<AMessage> msg = new AMessage(kWhatSelectTrack, id());
1542 msg->setSize("trackIndex", trackIndex);
1543 msg->setInt32("select", select);
1544
1545 sp<AMessage> response;
1546 status_t err = msg->postAndAwaitResponse(&response);
1547
Chong Zhang404fced2014-06-11 14:45:31 -07001548 if (err != OK) {
1549 return err;
1550 }
1551
1552 if (!response->findInt32("err", &err)) {
1553 err = OK;
1554 }
1555
Chong Zhangdcb89b32013-08-06 09:44:47 -07001556 return err;
1557}
1558
Andreas Huberb7c8e912012-11-27 15:02:53 -08001559void NuPlayer::schedulePollDuration() {
1560 sp<AMessage> msg = new AMessage(kWhatPollDuration, id());
1561 msg->setInt32("generation", mPollDurationGeneration);
1562 msg->post();
1563}
1564
1565void NuPlayer::cancelPollDuration() {
1566 ++mPollDurationGeneration;
1567}
1568
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001569void NuPlayer::processDeferredActions() {
1570 while (!mDeferredActions.empty()) {
1571 // We won't execute any deferred actions until we're no longer in
1572 // an intermediate state, i.e. one more more decoders are currently
1573 // flushing or shutting down.
1574
1575 if (mRenderer != NULL) {
1576 // There's an edge case where the renderer owns all output
1577 // buffers and is paused, therefore the decoder will not read
1578 // more input data and will never encounter the matching
1579 // discontinuity. To avoid this, we resume the renderer.
1580
1581 if (mFlushingAudio == AWAITING_DISCONTINUITY
1582 || mFlushingVideo == AWAITING_DISCONTINUITY) {
1583 mRenderer->resume();
1584 }
1585 }
1586
1587 if (mFlushingAudio != NONE || mFlushingVideo != NONE) {
1588 // We're currently flushing, postpone the reset until that's
1589 // completed.
1590
1591 ALOGV("postponing action mFlushingAudio=%d, mFlushingVideo=%d",
1592 mFlushingAudio, mFlushingVideo);
1593
1594 break;
1595 }
1596
1597 sp<Action> action = *mDeferredActions.begin();
1598 mDeferredActions.erase(mDeferredActions.begin());
1599
1600 action->execute(this);
1601 }
1602}
1603
1604void NuPlayer::performSeek(int64_t seekTimeUs) {
1605 ALOGV("performSeek seekTimeUs=%lld us (%.2f secs)",
1606 seekTimeUs,
1607 seekTimeUs / 1E6);
1608
1609 mSource->seekTo(seekTimeUs);
Robert Shihd3b0bbb2014-07-23 15:00:25 -07001610 ++mTimedTextGeneration;
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001611
1612 if (mDriver != NULL) {
1613 sp<NuPlayerDriver> driver = mDriver.promote();
1614 if (driver != NULL) {
1615 driver->notifyPosition(seekTimeUs);
1616 driver->notifySeekComplete();
1617 }
1618 }
1619
1620 // everything's flushed, continue playback.
1621}
1622
1623void NuPlayer::performDecoderFlush() {
1624 ALOGV("performDecoderFlush");
1625
Andreas Huberda9740e2013-04-16 10:54:03 -07001626 if (mAudioDecoder == NULL && mVideoDecoder == NULL) {
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001627 return;
1628 }
1629
1630 mTimeDiscontinuityPending = true;
1631
1632 if (mAudioDecoder != NULL) {
1633 flushDecoder(true /* audio */, false /* needShutdown */);
1634 }
1635
1636 if (mVideoDecoder != NULL) {
1637 flushDecoder(false /* audio */, false /* needShutdown */);
1638 }
1639}
1640
Andreas Huber14f76722013-01-15 09:04:18 -08001641void NuPlayer::performDecoderShutdown(bool audio, bool video) {
1642 ALOGV("performDecoderShutdown audio=%d, video=%d", audio, video);
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001643
Andreas Huber14f76722013-01-15 09:04:18 -08001644 if ((!audio || mAudioDecoder == NULL)
1645 && (!video || mVideoDecoder == NULL)) {
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001646 return;
1647 }
1648
1649 mTimeDiscontinuityPending = true;
1650
Andreas Huber14f76722013-01-15 09:04:18 -08001651 if (mFlushingAudio == NONE && (!audio || mAudioDecoder == NULL)) {
1652 mFlushingAudio = FLUSHED;
1653 }
1654
1655 if (mFlushingVideo == NONE && (!video || mVideoDecoder == NULL)) {
1656 mFlushingVideo = FLUSHED;
1657 }
1658
1659 if (audio && mAudioDecoder != NULL) {
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001660 flushDecoder(true /* audio */, true /* needShutdown */);
1661 }
1662
Andreas Huber14f76722013-01-15 09:04:18 -08001663 if (video && mVideoDecoder != NULL) {
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001664 flushDecoder(false /* audio */, true /* needShutdown */);
1665 }
1666}
1667
1668void NuPlayer::performReset() {
1669 ALOGV("performReset");
1670
1671 CHECK(mAudioDecoder == NULL);
1672 CHECK(mVideoDecoder == NULL);
1673
1674 cancelPollDuration();
1675
1676 ++mScanSourcesGeneration;
1677 mScanSourcesPending = false;
1678
Lajos Molnar09524832014-07-17 14:29:51 -07001679 if (mRendererLooper != NULL) {
1680 if (mRenderer != NULL) {
1681 mRendererLooper->unregisterHandler(mRenderer->id());
1682 }
1683 mRendererLooper->stop();
1684 mRendererLooper.clear();
1685 }
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001686 mRenderer.clear();
1687
1688 if (mSource != NULL) {
1689 mSource->stop();
Andreas Huberb5f25f02013-02-05 10:14:26 -08001690
1691 looper()->unregisterHandler(mSource->id());
1692
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001693 mSource.clear();
1694 }
1695
1696 if (mDriver != NULL) {
1697 sp<NuPlayerDriver> driver = mDriver.promote();
1698 if (driver != NULL) {
1699 driver->notifyResetComplete();
1700 }
1701 }
Andreas Huber57a339c2012-12-03 11:18:00 -08001702
1703 mStarted = false;
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001704}
1705
1706void NuPlayer::performScanSources() {
1707 ALOGV("performScanSources");
1708
Andreas Huber57a339c2012-12-03 11:18:00 -08001709 if (!mStarted) {
1710 return;
1711 }
1712
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001713 if (mAudioDecoder == NULL || mVideoDecoder == NULL) {
1714 postScanSources();
1715 }
1716}
1717
Andreas Huber57a339c2012-12-03 11:18:00 -08001718void NuPlayer::performSetSurface(const sp<NativeWindowWrapper> &wrapper) {
1719 ALOGV("performSetSurface");
1720
1721 mNativeWindow = wrapper;
1722
1723 // XXX - ignore error from setVideoScalingMode for now
1724 setVideoScalingMode(mVideoScalingMode);
1725
1726 if (mDriver != NULL) {
1727 sp<NuPlayerDriver> driver = mDriver.promote();
1728 if (driver != NULL) {
1729 driver->notifySetSurfaceComplete();
1730 }
1731 }
1732}
1733
Andreas Huber9575c962013-02-05 13:59:56 -08001734void NuPlayer::onSourceNotify(const sp<AMessage> &msg) {
1735 int32_t what;
1736 CHECK(msg->findInt32("what", &what));
1737
1738 switch (what) {
1739 case Source::kWhatPrepared:
1740 {
Andreas Huberb5f28d42013-04-25 15:11:19 -07001741 if (mSource == NULL) {
1742 // This is a stale notification from a source that was
1743 // asynchronously preparing when the client called reset().
1744 // We handled the reset, the source is gone.
1745 break;
1746 }
1747
Andreas Huberec0c5972013-02-05 14:47:13 -08001748 int32_t err;
1749 CHECK(msg->findInt32("err", &err));
1750
Andreas Huber9575c962013-02-05 13:59:56 -08001751 sp<NuPlayerDriver> driver = mDriver.promote();
1752 if (driver != NULL) {
Marco Nelissendd114d12014-05-28 15:23:14 -07001753 // notify duration first, so that it's definitely set when
1754 // the app received the "prepare complete" callback.
1755 int64_t durationUs;
1756 if (mSource->getDuration(&durationUs) == OK) {
1757 driver->notifyDuration(durationUs);
1758 }
Andreas Huberec0c5972013-02-05 14:47:13 -08001759 driver->notifyPrepareCompleted(err);
Andreas Huber9575c962013-02-05 13:59:56 -08001760 }
Andreas Huber99759402013-04-01 14:28:31 -07001761
Andreas Huber9575c962013-02-05 13:59:56 -08001762 break;
1763 }
1764
1765 case Source::kWhatFlagsChanged:
1766 {
1767 uint32_t flags;
1768 CHECK(msg->findInt32("flags", (int32_t *)&flags));
1769
Chong Zhang4b7069d2013-09-11 12:52:43 -07001770 sp<NuPlayerDriver> driver = mDriver.promote();
1771 if (driver != NULL) {
1772 driver->notifyFlagsChanged(flags);
1773 }
1774
Andreas Huber9575c962013-02-05 13:59:56 -08001775 if ((mSourceFlags & Source::FLAG_DYNAMIC_DURATION)
1776 && (!(flags & Source::FLAG_DYNAMIC_DURATION))) {
1777 cancelPollDuration();
1778 } else if (!(mSourceFlags & Source::FLAG_DYNAMIC_DURATION)
1779 && (flags & Source::FLAG_DYNAMIC_DURATION)
1780 && (mAudioDecoder != NULL || mVideoDecoder != NULL)) {
1781 schedulePollDuration();
1782 }
1783
1784 mSourceFlags = flags;
1785 break;
1786 }
1787
1788 case Source::kWhatVideoSizeChanged:
1789 {
Chong Zhangced1c2f2014-08-08 15:22:35 -07001790 sp<AMessage> format;
1791 CHECK(msg->findMessage("format", &format));
Andreas Huber9575c962013-02-05 13:59:56 -08001792
Chong Zhangced1c2f2014-08-08 15:22:35 -07001793 updateVideoSize(format);
Andreas Huber9575c962013-02-05 13:59:56 -08001794 break;
1795 }
1796
Roger Jönssonb50e83e2013-01-21 16:26:41 +01001797 case Source::kWhatBufferingStart:
1798 {
1799 notifyListener(MEDIA_INFO, MEDIA_INFO_BUFFERING_START, 0);
1800 break;
1801 }
1802
1803 case Source::kWhatBufferingEnd:
1804 {
1805 notifyListener(MEDIA_INFO, MEDIA_INFO_BUFFERING_END, 0);
1806 break;
1807 }
1808
Chong Zhangdcb89b32013-08-06 09:44:47 -07001809 case Source::kWhatSubtitleData:
1810 {
1811 sp<ABuffer> buffer;
1812 CHECK(msg->findBuffer("buffer", &buffer));
1813
Chong Zhang404fced2014-06-11 14:45:31 -07001814 sendSubtitleData(buffer, 0 /* baseIndex */);
Chong Zhangdcb89b32013-08-06 09:44:47 -07001815 break;
1816 }
1817
Robert Shihd3b0bbb2014-07-23 15:00:25 -07001818 case Source::kWhatTimedTextData:
1819 {
1820 int32_t generation;
1821 if (msg->findInt32("generation", &generation)
1822 && generation != mTimedTextGeneration) {
1823 break;
1824 }
1825
1826 sp<ABuffer> buffer;
1827 CHECK(msg->findBuffer("buffer", &buffer));
1828
1829 sp<NuPlayerDriver> driver = mDriver.promote();
1830 if (driver == NULL) {
1831 break;
1832 }
1833
1834 int posMs;
1835 int64_t timeUs, posUs;
1836 driver->getCurrentPosition(&posMs);
1837 posUs = posMs * 1000;
1838 CHECK(buffer->meta()->findInt64("timeUs", &timeUs));
1839
1840 if (posUs < timeUs) {
1841 if (!msg->findInt32("generation", &generation)) {
1842 msg->setInt32("generation", mTimedTextGeneration);
1843 }
1844 msg->post(timeUs - posUs);
1845 } else {
1846 sendTimedTextData(buffer);
1847 }
1848 break;
1849 }
1850
Andreas Huber14f76722013-01-15 09:04:18 -08001851 case Source::kWhatQueueDecoderShutdown:
1852 {
1853 int32_t audio, video;
1854 CHECK(msg->findInt32("audio", &audio));
1855 CHECK(msg->findInt32("video", &video));
1856
1857 sp<AMessage> reply;
1858 CHECK(msg->findMessage("reply", &reply));
1859
1860 queueDecoderShutdown(audio, video, reply);
1861 break;
1862 }
1863
Andreas Huber9575c962013-02-05 13:59:56 -08001864 default:
1865 TRESPASS();
1866 }
1867}
1868
Chong Zhanga7fa1d92014-06-11 14:49:23 -07001869void NuPlayer::onClosedCaptionNotify(const sp<AMessage> &msg) {
1870 int32_t what;
1871 CHECK(msg->findInt32("what", &what));
1872
1873 switch (what) {
1874 case NuPlayer::CCDecoder::kWhatClosedCaptionData:
1875 {
1876 sp<ABuffer> buffer;
1877 CHECK(msg->findBuffer("buffer", &buffer));
1878
1879 size_t inbandTracks = 0;
1880 if (mSource != NULL) {
1881 inbandTracks = mSource->getTrackCount();
1882 }
1883
1884 sendSubtitleData(buffer, inbandTracks);
1885 break;
1886 }
1887
1888 case NuPlayer::CCDecoder::kWhatTrackAdded:
1889 {
1890 notifyListener(MEDIA_INFO, MEDIA_INFO_METADATA_UPDATE, 0);
1891
1892 break;
1893 }
1894
1895 default:
1896 TRESPASS();
1897 }
1898
1899
1900}
1901
Chong Zhang404fced2014-06-11 14:45:31 -07001902void NuPlayer::sendSubtitleData(const sp<ABuffer> &buffer, int32_t baseIndex) {
1903 int32_t trackIndex;
1904 int64_t timeUs, durationUs;
1905 CHECK(buffer->meta()->findInt32("trackIndex", &trackIndex));
1906 CHECK(buffer->meta()->findInt64("timeUs", &timeUs));
1907 CHECK(buffer->meta()->findInt64("durationUs", &durationUs));
1908
1909 Parcel in;
1910 in.writeInt32(trackIndex + baseIndex);
1911 in.writeInt64(timeUs);
1912 in.writeInt64(durationUs);
1913 in.writeInt32(buffer->size());
1914 in.writeInt32(buffer->size());
1915 in.write(buffer->data(), buffer->size());
1916
1917 notifyListener(MEDIA_SUBTITLE_DATA, 0, 0, &in);
1918}
Robert Shihd3b0bbb2014-07-23 15:00:25 -07001919
1920void NuPlayer::sendTimedTextData(const sp<ABuffer> &buffer) {
1921 const void *data;
1922 size_t size = 0;
1923 int64_t timeUs;
1924 int32_t flag = TextDescriptions::LOCAL_DESCRIPTIONS;
1925
1926 AString mime;
1927 CHECK(buffer->meta()->findString("mime", &mime));
1928 CHECK(strcasecmp(mime.c_str(), MEDIA_MIMETYPE_TEXT_3GPP) == 0);
1929
1930 data = buffer->data();
1931 size = buffer->size();
1932
1933 Parcel parcel;
1934 if (size > 0) {
1935 CHECK(buffer->meta()->findInt64("timeUs", &timeUs));
1936 flag |= TextDescriptions::IN_BAND_TEXT_3GPP;
1937 TextDescriptions::getParcelOfDescriptions(
1938 (const uint8_t *)data, size, flag, timeUs / 1000, &parcel);
1939 }
1940
1941 if ((parcel.dataSize() > 0)) {
1942 notifyListener(MEDIA_TIMED_TEXT, 0, 0, &parcel);
1943 } else { // send an empty timed text
1944 notifyListener(MEDIA_TIMED_TEXT, 0, 0);
1945 }
1946}
Andreas Huberb5f25f02013-02-05 10:14:26 -08001947////////////////////////////////////////////////////////////////////////////////
1948
Chong Zhangced1c2f2014-08-08 15:22:35 -07001949sp<AMessage> NuPlayer::Source::getFormat(bool audio) {
1950 sp<MetaData> meta = getFormatMeta(audio);
1951
1952 if (meta == NULL) {
1953 return NULL;
1954 }
1955
1956 sp<AMessage> msg = new AMessage;
1957
1958 if(convertMetaDataToMessage(meta, &msg) == OK) {
1959 return msg;
1960 }
1961 return NULL;
1962}
1963
Andreas Huber9575c962013-02-05 13:59:56 -08001964void NuPlayer::Source::notifyFlagsChanged(uint32_t flags) {
1965 sp<AMessage> notify = dupNotify();
1966 notify->setInt32("what", kWhatFlagsChanged);
1967 notify->setInt32("flags", flags);
1968 notify->post();
1969}
1970
Chong Zhangced1c2f2014-08-08 15:22:35 -07001971void NuPlayer::Source::notifyVideoSizeChanged(const sp<AMessage> &format) {
Andreas Huber9575c962013-02-05 13:59:56 -08001972 sp<AMessage> notify = dupNotify();
1973 notify->setInt32("what", kWhatVideoSizeChanged);
Chong Zhangced1c2f2014-08-08 15:22:35 -07001974 notify->setMessage("format", format);
Andreas Huber9575c962013-02-05 13:59:56 -08001975 notify->post();
1976}
1977
Andreas Huberec0c5972013-02-05 14:47:13 -08001978void NuPlayer::Source::notifyPrepared(status_t err) {
Andreas Huber9575c962013-02-05 13:59:56 -08001979 sp<AMessage> notify = dupNotify();
1980 notify->setInt32("what", kWhatPrepared);
Andreas Huberec0c5972013-02-05 14:47:13 -08001981 notify->setInt32("err", err);
Andreas Huber9575c962013-02-05 13:59:56 -08001982 notify->post();
1983}
1984
Andreas Huber84333e02014-02-07 15:36:10 -08001985void NuPlayer::Source::onMessageReceived(const sp<AMessage> & /* msg */) {
Andreas Huberb5f25f02013-02-05 10:14:26 -08001986 TRESPASS();
1987}
1988
Andreas Huberf9334412010-12-15 15:17:42 -08001989} // namespace android