blob: c69f74b91990a2aab3a649bce93e50b7c59f1eda [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"
Chong Zhang7137ec72014-11-12 16:41:05 -080024#include "NuPlayerCCDecoder.h"
Andreas Huberf9334412010-12-15 15:17:42 -080025#include "NuPlayerDecoder.h"
Chong Zhang7137ec72014-11-12 16:41:05 -080026#include "NuPlayerDecoderBase.h"
Wei Jiabc2fb722014-07-08 16:37:57 -070027#include "NuPlayerDecoderPassThrough.h"
Andreas Huber43c3e6c2011-01-05 12:17:08 -080028#include "NuPlayerDriver.h"
Andreas Huberf9334412010-12-15 15:17:42 -080029#include "NuPlayerRenderer.h"
Andreas Huber5bc087c2010-12-23 10:27:40 -080030#include "NuPlayerSource.h"
Andreas Huber2bfdd422011-10-11 15:24:07 -070031#include "RTSPSource.h"
Andreas Huber5bc087c2010-12-23 10:27:40 -080032#include "StreamingSource.h"
Andreas Huberafed0e12011-09-20 15:39:58 -070033#include "GenericSource.h"
Robert Shihd3b0bbb2014-07-23 15:00:25 -070034#include "TextDescriptions.h"
Andreas Huber5bc087c2010-12-23 10:27:40 -080035
36#include "ATSParser.h"
Andreas Huberf9334412010-12-15 15:17:42 -080037
Lajos Molnard9fd6312014-11-06 11:00:00 -080038#include <cutils/properties.h>
39
Andreas Huber3831a062010-12-21 10:22:33 -080040#include <media/stagefright/foundation/hexdump.h>
Andreas Huberf9334412010-12-15 15:17:42 -080041#include <media/stagefright/foundation/ABuffer.h>
42#include <media/stagefright/foundation/ADebug.h>
43#include <media/stagefright/foundation/AMessage.h>
Lajos Molnar09524832014-07-17 14:29:51 -070044#include <media/stagefright/MediaBuffer.h>
Andreas Huber3fe62152011-09-16 15:09:22 -070045#include <media/stagefright/MediaDefs.h>
Andreas Huberf9334412010-12-15 15:17:42 -080046#include <media/stagefright/MediaErrors.h>
47#include <media/stagefright/MetaData.h>
Andy McFadden8ba01022012-12-18 09:46:54 -080048#include <gui/IGraphicBufferProducer.h>
Andreas Huberf9334412010-12-15 15:17:42 -080049
Andreas Huber3fe62152011-09-16 15:09:22 -070050#include "avc_utils.h"
51
Andreas Huber84066782011-08-16 09:34:26 -070052#include "ESDS.h"
53#include <media/stagefright/Utils.h>
54
Andreas Huberf9334412010-12-15 15:17:42 -080055namespace android {
56
Andreas Hubera1f8ab02012-11-30 10:53:22 -080057struct NuPlayer::Action : public RefBase {
58 Action() {}
59
60 virtual void execute(NuPlayer *player) = 0;
61
62private:
63 DISALLOW_EVIL_CONSTRUCTORS(Action);
64};
65
66struct NuPlayer::SeekAction : public Action {
Wei Jiae427abf2014-09-22 15:21:11 -070067 SeekAction(int64_t seekTimeUs, bool needNotify)
68 : mSeekTimeUs(seekTimeUs),
69 mNeedNotify(needNotify) {
Andreas Hubera1f8ab02012-11-30 10:53:22 -080070 }
71
72 virtual void execute(NuPlayer *player) {
Wei Jiae427abf2014-09-22 15:21:11 -070073 player->performSeek(mSeekTimeUs, mNeedNotify);
Andreas Hubera1f8ab02012-11-30 10:53:22 -080074 }
75
76private:
77 int64_t mSeekTimeUs;
Wei Jiae427abf2014-09-22 15:21:11 -070078 bool mNeedNotify;
Andreas Hubera1f8ab02012-11-30 10:53:22 -080079
80 DISALLOW_EVIL_CONSTRUCTORS(SeekAction);
81};
82
Chong Zhangf8d71772014-11-26 15:08:34 -080083struct NuPlayer::ResumeDecoderAction : public Action {
84 ResumeDecoderAction(bool needNotify)
85 : mNeedNotify(needNotify) {
86 }
87
88 virtual void execute(NuPlayer *player) {
89 player->performResumeDecoders(mNeedNotify);
90 }
91
92private:
93 bool mNeedNotify;
94
95 DISALLOW_EVIL_CONSTRUCTORS(ResumeDecoderAction);
96};
97
Andreas Huber57a339c2012-12-03 11:18:00 -080098struct NuPlayer::SetSurfaceAction : public Action {
99 SetSurfaceAction(const sp<NativeWindowWrapper> &wrapper)
100 : mWrapper(wrapper) {
101 }
102
103 virtual void execute(NuPlayer *player) {
104 player->performSetSurface(mWrapper);
105 }
106
107private:
108 sp<NativeWindowWrapper> mWrapper;
109
110 DISALLOW_EVIL_CONSTRUCTORS(SetSurfaceAction);
111};
112
Wei Jiafef808d2014-10-31 17:57:05 -0700113struct NuPlayer::FlushDecoderAction : public Action {
114 FlushDecoderAction(FlushCommand audio, FlushCommand video)
Andreas Huber14f76722013-01-15 09:04:18 -0800115 : mAudio(audio),
116 mVideo(video) {
117 }
118
119 virtual void execute(NuPlayer *player) {
Wei Jiafef808d2014-10-31 17:57:05 -0700120 player->performDecoderFlush(mAudio, mVideo);
Andreas Huber14f76722013-01-15 09:04:18 -0800121 }
122
123private:
Wei Jiafef808d2014-10-31 17:57:05 -0700124 FlushCommand mAudio;
125 FlushCommand mVideo;
Andreas Huber14f76722013-01-15 09:04:18 -0800126
Wei Jiafef808d2014-10-31 17:57:05 -0700127 DISALLOW_EVIL_CONSTRUCTORS(FlushDecoderAction);
Andreas Huber14f76722013-01-15 09:04:18 -0800128};
129
130struct NuPlayer::PostMessageAction : public Action {
131 PostMessageAction(const sp<AMessage> &msg)
132 : mMessage(msg) {
133 }
134
135 virtual void execute(NuPlayer *) {
136 mMessage->post();
137 }
138
139private:
140 sp<AMessage> mMessage;
141
142 DISALLOW_EVIL_CONSTRUCTORS(PostMessageAction);
143};
144
Andreas Hubera1f8ab02012-11-30 10:53:22 -0800145// Use this if there's no state necessary to save in order to execute
146// the action.
147struct NuPlayer::SimpleAction : public Action {
148 typedef void (NuPlayer::*ActionFunc)();
149
150 SimpleAction(ActionFunc func)
151 : mFunc(func) {
152 }
153
154 virtual void execute(NuPlayer *player) {
155 (player->*mFunc)();
156 }
157
158private:
159 ActionFunc mFunc;
160
161 DISALLOW_EVIL_CONSTRUCTORS(SimpleAction);
162};
163
Andreas Huberf9334412010-12-15 15:17:42 -0800164////////////////////////////////////////////////////////////////////////////////
165
166NuPlayer::NuPlayer()
Andreas Huber9b80c2b2011-06-30 15:47:02 -0700167 : mUIDValid(false),
Andreas Huber9575c962013-02-05 13:59:56 -0800168 mSourceFlags(0),
Wei Jiabc2fb722014-07-08 16:37:57 -0700169 mOffloadAudio(false),
Wei Jia88703c32014-08-06 11:24:07 -0700170 mAudioDecoderGeneration(0),
171 mVideoDecoderGeneration(0),
Wei Jia57568df2014-09-22 10:16:29 -0700172 mRendererGeneration(0),
Andreas Huber9b80c2b2011-06-30 15:47:02 -0700173 mAudioEOS(false),
Andreas Huberf9334412010-12-15 15:17:42 -0800174 mVideoEOS(false),
Andreas Huber5bc087c2010-12-23 10:27:40 -0800175 mScanSourcesPending(false),
Andreas Huber1aef2112011-01-04 14:01:29 -0800176 mScanSourcesGeneration(0),
Andreas Huberb7c8e912012-11-27 15:02:53 -0800177 mPollDurationGeneration(0),
Robert Shihd3b0bbb2014-07-23 15:00:25 -0700178 mTimedTextGeneration(0),
Andreas Huberf9334412010-12-15 15:17:42 -0800179 mFlushingAudio(NONE),
Andreas Huber1aef2112011-01-04 14:01:29 -0800180 mFlushingVideo(NONE),
Chong Zhangf8d71772014-11-26 15:08:34 -0800181 mResumePending(false),
Andreas Huber57a339c2012-12-03 11:18:00 -0800182 mVideoScalingMode(NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW),
183 mStarted(false) {
Andy Hung8d121d42014-10-03 09:53:53 -0700184 clearFlushComplete();
Andreas Huberf9334412010-12-15 15:17:42 -0800185}
186
187NuPlayer::~NuPlayer() {
188}
189
Andreas Huber9b80c2b2011-06-30 15:47:02 -0700190void NuPlayer::setUID(uid_t uid) {
191 mUIDValid = true;
192 mUID = uid;
193}
194
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800195void NuPlayer::setDriver(const wp<NuPlayerDriver> &driver) {
196 mDriver = driver;
Andreas Huberf9334412010-12-15 15:17:42 -0800197}
198
Andreas Huber9575c962013-02-05 13:59:56 -0800199void NuPlayer::setDataSourceAsync(const sp<IStreamSource> &source) {
Andreas Huberf9334412010-12-15 15:17:42 -0800200 sp<AMessage> msg = new AMessage(kWhatSetDataSource, id());
201
Andreas Huberb5f25f02013-02-05 10:14:26 -0800202 sp<AMessage> notify = new AMessage(kWhatSourceNotify, id());
203
Andreas Huber240abcc2014-02-13 13:32:37 -0800204 msg->setObject("source", new StreamingSource(notify, source));
Andreas Huber5bc087c2010-12-23 10:27:40 -0800205 msg->post();
206}
Andreas Huberf9334412010-12-15 15:17:42 -0800207
Andreas Huberafed0e12011-09-20 15:39:58 -0700208static bool IsHTTPLiveURL(const char *url) {
209 if (!strncasecmp("http://", url, 7)
Andreas Huber99759402013-04-01 14:28:31 -0700210 || !strncasecmp("https://", url, 8)
211 || !strncasecmp("file://", url, 7)) {
Andreas Huberafed0e12011-09-20 15:39:58 -0700212 size_t len = strlen(url);
213 if (len >= 5 && !strcasecmp(".m3u8", &url[len - 5])) {
214 return true;
215 }
216
217 if (strstr(url,"m3u8")) {
218 return true;
219 }
220 }
221
222 return false;
223}
224
Andreas Huber9575c962013-02-05 13:59:56 -0800225void NuPlayer::setDataSourceAsync(
Andreas Huber1b86fe02014-01-29 11:13:26 -0800226 const sp<IMediaHTTPService> &httpService,
227 const char *url,
228 const KeyedVector<String8, String8> *headers) {
Chong Zhang3de157d2014-08-05 20:54:44 -0700229
Andreas Huber5bc087c2010-12-23 10:27:40 -0800230 sp<AMessage> msg = new AMessage(kWhatSetDataSource, id());
Oscar Rydhé7a33b772012-02-20 10:15:48 +0100231 size_t len = strlen(url);
Andreas Huber5bc087c2010-12-23 10:27:40 -0800232
Andreas Huberb5f25f02013-02-05 10:14:26 -0800233 sp<AMessage> notify = new AMessage(kWhatSourceNotify, id());
234
Andreas Huberafed0e12011-09-20 15:39:58 -0700235 sp<Source> source;
236 if (IsHTTPLiveURL(url)) {
Andreas Huber81e68442014-02-05 11:52:33 -0800237 source = new HTTPLiveSource(notify, httpService, url, headers);
Andreas Huberafed0e12011-09-20 15:39:58 -0700238 } else if (!strncasecmp(url, "rtsp://", 7)) {
Andreas Huber1b86fe02014-01-29 11:13:26 -0800239 source = new RTSPSource(
240 notify, httpService, url, headers, mUIDValid, mUID);
Oscar Rydhé7a33b772012-02-20 10:15:48 +0100241 } else if ((!strncasecmp(url, "http://", 7)
242 || !strncasecmp(url, "https://", 8))
243 && ((len >= 4 && !strcasecmp(".sdp", &url[len - 4]))
244 || strstr(url, ".sdp?"))) {
Andreas Huber1b86fe02014-01-29 11:13:26 -0800245 source = new RTSPSource(
246 notify, httpService, url, headers, mUIDValid, mUID, true);
Andreas Huber2bfdd422011-10-11 15:24:07 -0700247 } else {
Chong Zhang3de157d2014-08-05 20:54:44 -0700248 sp<GenericSource> genericSource =
249 new GenericSource(notify, mUIDValid, mUID);
250 // Don't set FLAG_SECURE on mSourceFlags here for widevine.
251 // The correct flags will be updated in Source::kWhatFlagsChanged
252 // handler when GenericSource is prepared.
Andreas Huber2bfdd422011-10-11 15:24:07 -0700253
Chong Zhanga19f33e2014-08-07 15:35:07 -0700254 status_t err = genericSource->setDataSource(httpService, url, headers);
Chong Zhang3de157d2014-08-05 20:54:44 -0700255
256 if (err == OK) {
257 source = genericSource;
258 } else {
Chong Zhanga19f33e2014-08-07 15:35:07 -0700259 ALOGE("Failed to set data source!");
Chong Zhang3de157d2014-08-05 20:54:44 -0700260 }
261 }
Andreas Huberafed0e12011-09-20 15:39:58 -0700262 msg->setObject("source", source);
263 msg->post();
264}
265
Andreas Huber9575c962013-02-05 13:59:56 -0800266void NuPlayer::setDataSourceAsync(int fd, int64_t offset, int64_t length) {
Andreas Huberafed0e12011-09-20 15:39:58 -0700267 sp<AMessage> msg = new AMessage(kWhatSetDataSource, id());
268
Andreas Huberb5f25f02013-02-05 10:14:26 -0800269 sp<AMessage> notify = new AMessage(kWhatSourceNotify, id());
270
Chong Zhang3de157d2014-08-05 20:54:44 -0700271 sp<GenericSource> source =
272 new GenericSource(notify, mUIDValid, mUID);
273
Chong Zhanga19f33e2014-08-07 15:35:07 -0700274 status_t err = source->setDataSource(fd, offset, length);
Chong Zhang3de157d2014-08-05 20:54:44 -0700275
276 if (err != OK) {
Chong Zhanga19f33e2014-08-07 15:35:07 -0700277 ALOGE("Failed to set data source!");
Chong Zhang3de157d2014-08-05 20:54:44 -0700278 source = NULL;
279 }
280
Andreas Huberafed0e12011-09-20 15:39:58 -0700281 msg->setObject("source", source);
Andreas Huberf9334412010-12-15 15:17:42 -0800282 msg->post();
283}
284
Andreas Huber9575c962013-02-05 13:59:56 -0800285void NuPlayer::prepareAsync() {
286 (new AMessage(kWhatPrepare, id()))->post();
287}
288
Andreas Huber57a339c2012-12-03 11:18:00 -0800289void NuPlayer::setVideoSurfaceTextureAsync(
Andy McFadden8ba01022012-12-18 09:46:54 -0800290 const sp<IGraphicBufferProducer> &bufferProducer) {
Glenn Kasten11731182011-02-08 17:26:17 -0800291 sp<AMessage> msg = new AMessage(kWhatSetVideoNativeWindow, id());
Andreas Huber57a339c2012-12-03 11:18:00 -0800292
Andy McFadden8ba01022012-12-18 09:46:54 -0800293 if (bufferProducer == NULL) {
Andreas Huber57a339c2012-12-03 11:18:00 -0800294 msg->setObject("native-window", NULL);
295 } else {
296 msg->setObject(
297 "native-window",
298 new NativeWindowWrapper(
Wei Jia9c03a402014-08-26 15:24:43 -0700299 new Surface(bufferProducer, true /* controlledByApp */)));
Andreas Huber57a339c2012-12-03 11:18:00 -0800300 }
301
Andreas Huberf9334412010-12-15 15:17:42 -0800302 msg->post();
303}
304
305void NuPlayer::setAudioSink(const sp<MediaPlayerBase::AudioSink> &sink) {
306 sp<AMessage> msg = new AMessage(kWhatSetAudioSink, id());
307 msg->setObject("sink", sink);
308 msg->post();
309}
310
311void NuPlayer::start() {
312 (new AMessage(kWhatStart, id()))->post();
313}
314
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800315void NuPlayer::pause() {
Andreas Huberb4082222011-01-20 15:23:04 -0800316 (new AMessage(kWhatPause, id()))->post();
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800317}
318
Andreas Huber1aef2112011-01-04 14:01:29 -0800319void NuPlayer::resetAsync() {
Chong Zhang48296b72014-09-14 14:28:45 -0700320 if (mSource != NULL) {
321 // During a reset, the data source might be unresponsive already, we need to
322 // disconnect explicitly so that reads exit promptly.
323 // We can't queue the disconnect request to the looper, as it might be
324 // queued behind a stuck read and never gets processed.
325 // Doing a disconnect outside the looper to allows the pending reads to exit
326 // (either successfully or with error).
327 mSource->disconnect();
328 }
329
Andreas Huber1aef2112011-01-04 14:01:29 -0800330 (new AMessage(kWhatReset, id()))->post();
331}
332
Wei Jiae427abf2014-09-22 15:21:11 -0700333void NuPlayer::seekToAsync(int64_t seekTimeUs, bool needNotify) {
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800334 sp<AMessage> msg = new AMessage(kWhatSeek, id());
335 msg->setInt64("seekTimeUs", seekTimeUs);
Wei Jiae427abf2014-09-22 15:21:11 -0700336 msg->setInt32("needNotify", needNotify);
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800337 msg->post();
338}
339
Andreas Huber53df1a42010-12-22 10:03:04 -0800340
Chong Zhang404fced2014-06-11 14:45:31 -0700341void NuPlayer::writeTrackInfo(
342 Parcel* reply, const sp<AMessage> format) const {
343 int32_t trackType;
344 CHECK(format->findInt32("type", &trackType));
345
346 AString lang;
347 CHECK(format->findString("language", &lang));
348
349 reply->writeInt32(2); // write something non-zero
350 reply->writeInt32(trackType);
351 reply->writeString16(String16(lang.c_str()));
352
353 if (trackType == MEDIA_TRACK_TYPE_SUBTITLE) {
354 AString mime;
355 CHECK(format->findString("mime", &mime));
356
357 int32_t isAuto, isDefault, isForced;
358 CHECK(format->findInt32("auto", &isAuto));
359 CHECK(format->findInt32("default", &isDefault));
360 CHECK(format->findInt32("forced", &isForced));
361
362 reply->writeString16(String16(mime.c_str()));
363 reply->writeInt32(isAuto);
364 reply->writeInt32(isDefault);
365 reply->writeInt32(isForced);
366 }
367}
368
Andreas Huberf9334412010-12-15 15:17:42 -0800369void NuPlayer::onMessageReceived(const sp<AMessage> &msg) {
370 switch (msg->what()) {
371 case kWhatSetDataSource:
372 {
Steve Block3856b092011-10-20 11:56:00 +0100373 ALOGV("kWhatSetDataSource");
Andreas Huberf9334412010-12-15 15:17:42 -0800374
375 CHECK(mSource == NULL);
376
Chong Zhang3de157d2014-08-05 20:54:44 -0700377 status_t err = OK;
Andreas Huber5bc087c2010-12-23 10:27:40 -0800378 sp<RefBase> obj;
379 CHECK(msg->findObject("source", &obj));
Chong Zhang3de157d2014-08-05 20:54:44 -0700380 if (obj != NULL) {
381 mSource = static_cast<Source *>(obj.get());
Chong Zhang3de157d2014-08-05 20:54:44 -0700382 } else {
383 err = UNKNOWN_ERROR;
384 }
Andreas Huber9575c962013-02-05 13:59:56 -0800385
386 CHECK(mDriver != NULL);
387 sp<NuPlayerDriver> driver = mDriver.promote();
388 if (driver != NULL) {
Chong Zhang3de157d2014-08-05 20:54:44 -0700389 driver->notifySetDataSourceCompleted(err);
Andreas Huber9575c962013-02-05 13:59:56 -0800390 }
391 break;
392 }
393
394 case kWhatPrepare:
395 {
396 mSource->prepareAsync();
Andreas Huberf9334412010-12-15 15:17:42 -0800397 break;
398 }
399
Chong Zhangdcb89b32013-08-06 09:44:47 -0700400 case kWhatGetTrackInfo:
401 {
402 uint32_t replyID;
403 CHECK(msg->senderAwaitsResponse(&replyID));
404
Chong Zhang404fced2014-06-11 14:45:31 -0700405 Parcel* reply;
406 CHECK(msg->findPointer("reply", (void**)&reply));
407
408 size_t inbandTracks = 0;
Chong Zhangdcb89b32013-08-06 09:44:47 -0700409 if (mSource != NULL) {
Chong Zhang404fced2014-06-11 14:45:31 -0700410 inbandTracks = mSource->getTrackCount();
411 }
412
Chong Zhanga7fa1d92014-06-11 14:49:23 -0700413 size_t ccTracks = 0;
414 if (mCCDecoder != NULL) {
415 ccTracks = mCCDecoder->getTrackCount();
416 }
417
Chong Zhang404fced2014-06-11 14:45:31 -0700418 // total track count
Chong Zhanga7fa1d92014-06-11 14:49:23 -0700419 reply->writeInt32(inbandTracks + ccTracks);
Chong Zhang404fced2014-06-11 14:45:31 -0700420
421 // write inband tracks
422 for (size_t i = 0; i < inbandTracks; ++i) {
423 writeTrackInfo(reply, mSource->getTrackInfo(i));
Chong Zhangdcb89b32013-08-06 09:44:47 -0700424 }
425
Chong Zhanga7fa1d92014-06-11 14:49:23 -0700426 // write CC track
427 for (size_t i = 0; i < ccTracks; ++i) {
428 writeTrackInfo(reply, mCCDecoder->getTrackInfo(i));
429 }
430
Chong Zhangdcb89b32013-08-06 09:44:47 -0700431 sp<AMessage> response = new AMessage;
Chong Zhangdcb89b32013-08-06 09:44:47 -0700432 response->postReply(replyID);
433 break;
434 }
435
Robert Shih7c4f0d72014-07-09 18:53:31 -0700436 case kWhatGetSelectedTrack:
437 {
438 status_t err = INVALID_OPERATION;
439 if (mSource != NULL) {
440 err = OK;
441
442 int32_t type32;
443 CHECK(msg->findInt32("type", (int32_t*)&type32));
444 media_track_type type = (media_track_type)type32;
445 ssize_t selectedTrack = mSource->getSelectedTrack(type);
446
447 Parcel* reply;
448 CHECK(msg->findPointer("reply", (void**)&reply));
449 reply->writeInt32(selectedTrack);
450 }
451
452 sp<AMessage> response = new AMessage;
453 response->setInt32("err", err);
454
455 uint32_t replyID;
456 CHECK(msg->senderAwaitsResponse(&replyID));
457 response->postReply(replyID);
458 break;
459 }
460
Chong Zhangdcb89b32013-08-06 09:44:47 -0700461 case kWhatSelectTrack:
462 {
463 uint32_t replyID;
464 CHECK(msg->senderAwaitsResponse(&replyID));
465
Chong Zhang404fced2014-06-11 14:45:31 -0700466 size_t trackIndex;
467 int32_t select;
Robert Shih6ffb1fd2014-10-29 16:24:32 -0700468 int64_t timeUs;
Chong Zhang404fced2014-06-11 14:45:31 -0700469 CHECK(msg->findSize("trackIndex", &trackIndex));
470 CHECK(msg->findInt32("select", &select));
Robert Shih6ffb1fd2014-10-29 16:24:32 -0700471 CHECK(msg->findInt64("timeUs", &timeUs));
Chong Zhang404fced2014-06-11 14:45:31 -0700472
Chong Zhangdcb89b32013-08-06 09:44:47 -0700473 status_t err = INVALID_OPERATION;
Chong Zhang404fced2014-06-11 14:45:31 -0700474
475 size_t inbandTracks = 0;
Chong Zhangdcb89b32013-08-06 09:44:47 -0700476 if (mSource != NULL) {
Chong Zhang404fced2014-06-11 14:45:31 -0700477 inbandTracks = mSource->getTrackCount();
478 }
Chong Zhanga7fa1d92014-06-11 14:49:23 -0700479 size_t ccTracks = 0;
480 if (mCCDecoder != NULL) {
481 ccTracks = mCCDecoder->getTrackCount();
482 }
Chong Zhang404fced2014-06-11 14:45:31 -0700483
484 if (trackIndex < inbandTracks) {
Robert Shih6ffb1fd2014-10-29 16:24:32 -0700485 err = mSource->selectTrack(trackIndex, select, timeUs);
Robert Shihd3b0bbb2014-07-23 15:00:25 -0700486
487 if (!select && err == OK) {
488 int32_t type;
489 sp<AMessage> info = mSource->getTrackInfo(trackIndex);
490 if (info != NULL
491 && info->findInt32("type", &type)
492 && type == MEDIA_TRACK_TYPE_TIMEDTEXT) {
493 ++mTimedTextGeneration;
494 }
495 }
Chong Zhanga7fa1d92014-06-11 14:49:23 -0700496 } else {
497 trackIndex -= inbandTracks;
498
499 if (trackIndex < ccTracks) {
500 err = mCCDecoder->selectTrack(trackIndex, select);
501 }
Chong Zhangdcb89b32013-08-06 09:44:47 -0700502 }
503
504 sp<AMessage> response = new AMessage;
505 response->setInt32("err", err);
506
507 response->postReply(replyID);
508 break;
509 }
510
Andreas Huberb7c8e912012-11-27 15:02:53 -0800511 case kWhatPollDuration:
512 {
513 int32_t generation;
514 CHECK(msg->findInt32("generation", &generation));
515
516 if (generation != mPollDurationGeneration) {
517 // stale
518 break;
519 }
520
521 int64_t durationUs;
522 if (mDriver != NULL && mSource->getDuration(&durationUs) == OK) {
523 sp<NuPlayerDriver> driver = mDriver.promote();
524 if (driver != NULL) {
525 driver->notifyDuration(durationUs);
526 }
527 }
528
529 msg->post(1000000ll); // poll again in a second.
530 break;
531 }
532
Glenn Kasten11731182011-02-08 17:26:17 -0800533 case kWhatSetVideoNativeWindow:
Andreas Huberf9334412010-12-15 15:17:42 -0800534 {
Steve Block3856b092011-10-20 11:56:00 +0100535 ALOGV("kWhatSetVideoNativeWindow");
Andreas Huberf9334412010-12-15 15:17:42 -0800536
537 sp<RefBase> obj;
Glenn Kasten11731182011-02-08 17:26:17 -0800538 CHECK(msg->findObject("native-window", &obj));
Andreas Huberf9334412010-12-15 15:17:42 -0800539
Wei Jiafef808d2014-10-31 17:57:05 -0700540 if (mSource->getFormat(false /* audio */) == NULL) {
541 performSetSurface(static_cast<NativeWindowWrapper *>(obj.get()));
542 break;
543 }
544
545 mDeferredActions.push_back(
546 new FlushDecoderAction(FLUSH_CMD_FLUSH /* audio */,
547 FLUSH_CMD_SHUTDOWN /* video */));
548
Andreas Huber57a339c2012-12-03 11:18:00 -0800549 mDeferredActions.push_back(
550 new SetSurfaceAction(
551 static_cast<NativeWindowWrapper *>(obj.get())));
James Dong0d268a32012-08-31 12:18:27 -0700552
Andreas Huber57a339c2012-12-03 11:18:00 -0800553 if (obj != NULL) {
Wei Jiafef808d2014-10-31 17:57:05 -0700554 if (mStarted) {
Andy Hung73535852014-09-05 11:42:58 -0700555 // Issue a seek to refresh the video screen only if started otherwise
556 // the extractor may not yet be started and will assert.
557 // If the video decoder is not set (perhaps audio only in this case)
558 // do not perform a seek as it is not needed.
Ronghua Wua73d9e02014-10-08 15:13:29 -0700559 int64_t currentPositionUs = 0;
560 if (getCurrentPosition(&currentPositionUs) == OK) {
561 mDeferredActions.push_back(
562 new SeekAction(currentPositionUs, false /* needNotify */));
563 }
Andy Hung73535852014-09-05 11:42:58 -0700564 }
Wei Jiaac428aa2014-09-02 19:01:34 -0700565
Andreas Huber57a339c2012-12-03 11:18:00 -0800566 // If there is a new surface texture, instantiate decoders
567 // again if possible.
568 mDeferredActions.push_back(
569 new SimpleAction(&NuPlayer::performScanSources));
570 }
571
Chong Zhangf8d71772014-11-26 15:08:34 -0800572 // After a flush without shutdown, decoder is paused.
573 // Don't resume it until source seek is done, otherwise it could
Chong Zhang7137ec72014-11-12 16:41:05 -0800574 // start pulling stale data too soon.
575 mDeferredActions.push_back(
Chong Zhangf8d71772014-11-26 15:08:34 -0800576 new ResumeDecoderAction(false /* needNotify */));
Chong Zhang7137ec72014-11-12 16:41:05 -0800577
Andreas Huber57a339c2012-12-03 11:18:00 -0800578 processDeferredActions();
Andreas Huberf9334412010-12-15 15:17:42 -0800579 break;
580 }
581
582 case kWhatSetAudioSink:
583 {
Steve Block3856b092011-10-20 11:56:00 +0100584 ALOGV("kWhatSetAudioSink");
Andreas Huberf9334412010-12-15 15:17:42 -0800585
586 sp<RefBase> obj;
587 CHECK(msg->findObject("sink", &obj));
588
589 mAudioSink = static_cast<MediaPlayerBase::AudioSink *>(obj.get());
590 break;
591 }
592
593 case kWhatStart:
594 {
Steve Block3856b092011-10-20 11:56:00 +0100595 ALOGV("kWhatStart");
Wei Jia94211742014-10-28 17:09:06 -0700596 if (mStarted) {
597 onResume();
598 } else {
599 onStart();
Lajos Molnar09524832014-07-17 14:29:51 -0700600 }
Andreas Huberf9334412010-12-15 15:17:42 -0800601 break;
602 }
603
604 case kWhatScanSources:
605 {
Andreas Huber1aef2112011-01-04 14:01:29 -0800606 int32_t generation;
607 CHECK(msg->findInt32("generation", &generation));
608 if (generation != mScanSourcesGeneration) {
609 // Drop obsolete msg.
610 break;
611 }
612
Andreas Huber5bc087c2010-12-23 10:27:40 -0800613 mScanSourcesPending = false;
614
Steve Block3856b092011-10-20 11:56:00 +0100615 ALOGV("scanning sources haveAudio=%d, haveVideo=%d",
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800616 mAudioDecoder != NULL, mVideoDecoder != NULL);
617
Andreas Huberb7c8e912012-11-27 15:02:53 -0800618 bool mHadAnySourcesBefore =
619 (mAudioDecoder != NULL) || (mVideoDecoder != NULL);
620
Andy Hung282a7e32014-08-14 15:56:34 -0700621 // initialize video before audio because successful initialization of
622 // video may change deep buffer mode of audio.
Haynes Mathew George5d246ef2012-07-09 10:36:57 -0700623 if (mNativeWindow != NULL) {
624 instantiateDecoder(false, &mVideoDecoder);
625 }
Andreas Huberf9334412010-12-15 15:17:42 -0800626
Ronghua Wua10fd232014-11-06 16:15:20 -0800627 // Don't try to re-open audio sink if there's an existing decoder.
628 if (mAudioSink != NULL && mAudioDecoder == NULL) {
629 sp<MetaData> audioMeta = mSource->getFormatMeta(true /* audio */);
630 sp<AMessage> videoFormat = mSource->getFormat(false /* audio */);
631 audio_stream_type_t streamType = mAudioSink->getAudioStreamType();
632 bool canOffload = canOffloadStream(audioMeta, (videoFormat != NULL),
633 true /* is_streaming */, streamType);
634 if (canOffload) {
635 if (!mOffloadAudio) {
636 mRenderer->signalEnableOffloadAudio();
637 }
Andy Hung282a7e32014-08-14 15:56:34 -0700638 // open audio sink early under offload mode.
639 sp<AMessage> format = mSource->getFormat(true /*audio*/);
640 openAudioSink(format, true /*offloadOnly*/);
641 }
Andreas Huber5bc087c2010-12-23 10:27:40 -0800642 instantiateDecoder(true, &mAudioDecoder);
Andreas Huberf9334412010-12-15 15:17:42 -0800643 }
644
Andreas Huberb7c8e912012-11-27 15:02:53 -0800645 if (!mHadAnySourcesBefore
646 && (mAudioDecoder != NULL || mVideoDecoder != NULL)) {
647 // This is the first time we've found anything playable.
648
Andreas Huber9575c962013-02-05 13:59:56 -0800649 if (mSourceFlags & Source::FLAG_DYNAMIC_DURATION) {
Andreas Huberb7c8e912012-11-27 15:02:53 -0800650 schedulePollDuration();
651 }
652 }
653
Andreas Hubereac68ba2011-09-27 12:12:25 -0700654 status_t err;
655 if ((err = mSource->feedMoreTSData()) != OK) {
Andreas Huber1aef2112011-01-04 14:01:29 -0800656 if (mAudioDecoder == NULL && mVideoDecoder == NULL) {
657 // We're not currently decoding anything (no audio or
658 // video tracks found) and we just ran out of input data.
Andreas Hubereac68ba2011-09-27 12:12:25 -0700659
660 if (err == ERROR_END_OF_STREAM) {
661 notifyListener(MEDIA_PLAYBACK_COMPLETE, 0, 0);
662 } else {
663 notifyListener(MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, err);
664 }
Andreas Huber1aef2112011-01-04 14:01:29 -0800665 }
Andreas Huberf9334412010-12-15 15:17:42 -0800666 break;
667 }
668
Andreas Huberfbe9d812012-08-31 14:05:27 -0700669 if ((mAudioDecoder == NULL && mAudioSink != NULL)
670 || (mVideoDecoder == NULL && mNativeWindow != NULL)) {
Andreas Huberf9334412010-12-15 15:17:42 -0800671 msg->post(100000ll);
Andreas Huber5bc087c2010-12-23 10:27:40 -0800672 mScanSourcesPending = true;
Andreas Huberf9334412010-12-15 15:17:42 -0800673 }
674 break;
675 }
676
677 case kWhatVideoNotify:
678 case kWhatAudioNotify:
679 {
680 bool audio = msg->what() == kWhatAudioNotify;
681
Wei Jia88703c32014-08-06 11:24:07 -0700682 int32_t currentDecoderGeneration =
683 (audio? mAudioDecoderGeneration : mVideoDecoderGeneration);
684 int32_t requesterGeneration = currentDecoderGeneration - 1;
685 CHECK(msg->findInt32("generation", &requesterGeneration));
686
687 if (requesterGeneration != currentDecoderGeneration) {
688 ALOGV("got message from old %s decoder, generation(%d:%d)",
689 audio ? "audio" : "video", requesterGeneration,
690 currentDecoderGeneration);
691 sp<AMessage> reply;
692 if (!(msg->findMessage("reply", &reply))) {
693 return;
694 }
695
696 reply->setInt32("err", INFO_DISCONTINUITY);
697 reply->post();
698 return;
699 }
700
Andreas Huberf9334412010-12-15 15:17:42 -0800701 int32_t what;
Lajos Molnar1cd13982014-01-17 15:12:51 -0800702 CHECK(msg->findInt32("what", &what));
Andreas Huberf9334412010-12-15 15:17:42 -0800703
Chong Zhang7137ec72014-11-12 16:41:05 -0800704 if (what == DecoderBase::kWhatInputDiscontinuity) {
705 int32_t formatChange;
706 CHECK(msg->findInt32("formatChange", &formatChange));
Andreas Huberf9334412010-12-15 15:17:42 -0800707
Chong Zhang7137ec72014-11-12 16:41:05 -0800708 ALOGV("%s discontinuity: formatChange %d",
709 audio ? "audio" : "video", formatChange);
710
711 if (formatChange) {
712 mDeferredActions.push_back(
713 new FlushDecoderAction(
714 audio ? FLUSH_CMD_SHUTDOWN : FLUSH_CMD_NONE,
715 audio ? FLUSH_CMD_NONE : FLUSH_CMD_SHUTDOWN));
Andreas Huberf9334412010-12-15 15:17:42 -0800716 }
Chong Zhang7137ec72014-11-12 16:41:05 -0800717
718 mDeferredActions.push_back(
719 new SimpleAction(
720 &NuPlayer::performScanSources));
721
722 processDeferredActions();
723 } else if (what == DecoderBase::kWhatEOS) {
Andreas Huberdc9bacd2011-09-26 10:53:29 -0700724 int32_t err;
Lajos Molnar1cd13982014-01-17 15:12:51 -0800725 CHECK(msg->findInt32("err", &err));
Andreas Huberdc9bacd2011-09-26 10:53:29 -0700726
727 if (err == ERROR_END_OF_STREAM) {
Steve Block3856b092011-10-20 11:56:00 +0100728 ALOGV("got %s decoder EOS", audio ? "audio" : "video");
Andreas Huberdc9bacd2011-09-26 10:53:29 -0700729 } else {
Steve Block3856b092011-10-20 11:56:00 +0100730 ALOGV("got %s decoder EOS w/ error %d",
Andreas Huberdc9bacd2011-09-26 10:53:29 -0700731 audio ? "audio" : "video",
732 err);
733 }
734
735 mRenderer->queueEOS(audio, err);
Chong Zhang7137ec72014-11-12 16:41:05 -0800736 } else if (what == DecoderBase::kWhatFlushCompleted) {
Steve Block3856b092011-10-20 11:56:00 +0100737 ALOGV("decoder %s flush completed", audio ? "audio" : "video");
Andreas Huberf9334412010-12-15 15:17:42 -0800738
Andy Hung8d121d42014-10-03 09:53:53 -0700739 handleFlushComplete(audio, true /* isDecoder */);
Andreas Huber3831a062010-12-21 10:22:33 -0800740 finishFlushIfPossible();
Chong Zhang7137ec72014-11-12 16:41:05 -0800741 } else if (what == DecoderBase::kWhatVideoSizeChanged) {
Lajos Molnar1cd13982014-01-17 15:12:51 -0800742 sp<AMessage> format;
743 CHECK(msg->findMessage("format", &format));
744
Wei Jiac6cfd702014-11-11 16:33:20 -0800745 sp<AMessage> inputFormat =
746 mSource->getFormat(false /* audio */);
Andreas Huber3831a062010-12-21 10:22:33 -0800747
Wei Jiac6cfd702014-11-11 16:33:20 -0800748 updateVideoSize(inputFormat, format);
Chong Zhang7137ec72014-11-12 16:41:05 -0800749 } else if (what == DecoderBase::kWhatShutdownCompleted) {
Steve Block3856b092011-10-20 11:56:00 +0100750 ALOGV("%s shutdown completed", audio ? "audio" : "video");
Andreas Huber3831a062010-12-21 10:22:33 -0800751 if (audio) {
752 mAudioDecoder.clear();
Wei Jia57568df2014-09-22 10:16:29 -0700753 ++mAudioDecoderGeneration;
Andreas Huber3831a062010-12-21 10:22:33 -0800754
755 CHECK_EQ((int)mFlushingAudio, (int)SHUTTING_DOWN_DECODER);
756 mFlushingAudio = SHUT_DOWN;
757 } else {
758 mVideoDecoder.clear();
Wei Jia57568df2014-09-22 10:16:29 -0700759 ++mVideoDecoderGeneration;
Andreas Huber3831a062010-12-21 10:22:33 -0800760
761 CHECK_EQ((int)mFlushingVideo, (int)SHUTTING_DOWN_DECODER);
762 mFlushingVideo = SHUT_DOWN;
763 }
764
765 finishFlushIfPossible();
Chong Zhangf8d71772014-11-26 15:08:34 -0800766 } else if (what == DecoderBase::kWhatResumeCompleted) {
767 finishResume();
Chong Zhang7137ec72014-11-12 16:41:05 -0800768 } else if (what == DecoderBase::kWhatError) {
Chong Zhangf4c0a942014-08-11 15:14:10 -0700769 status_t err;
Andy Hung2abde2c2014-09-30 14:40:32 -0700770 if (!msg->findInt32("err", &err) || err == OK) {
Chong Zhangf4c0a942014-08-11 15:14:10 -0700771 err = UNKNOWN_ERROR;
772 }
Andy Hungcf31f1e2014-09-23 14:59:01 -0700773
Andy Hung2abde2c2014-09-30 14:40:32 -0700774 // Decoder errors can be due to Source (e.g. from streaming),
775 // or from decoding corrupted bitstreams, or from other decoder
776 // MediaCodec operations (e.g. from an ongoing reset or seek).
777 //
778 // We try to gracefully shut down the affected decoder if possible,
779 // rather than trying to force the shutdown with something
780 // similar to performReset(). This method can lead to a hang
781 // if MediaCodec functions block after an error, but they should
782 // typically return INVALID_OPERATION instead of blocking.
783
784 FlushStatus *flushing = audio ? &mFlushingAudio : &mFlushingVideo;
785 ALOGE("received error(%#x) from %s decoder, flushing(%d), now shutting down",
786 err, audio ? "audio" : "video", *flushing);
787
788 switch (*flushing) {
789 case NONE:
790 mDeferredActions.push_back(
Wei Jiafef808d2014-10-31 17:57:05 -0700791 new FlushDecoderAction(
792 audio ? FLUSH_CMD_SHUTDOWN : FLUSH_CMD_NONE,
793 audio ? FLUSH_CMD_NONE : FLUSH_CMD_SHUTDOWN));
Andy Hung2abde2c2014-09-30 14:40:32 -0700794 processDeferredActions();
795 break;
796 case FLUSHING_DECODER:
797 *flushing = FLUSHING_DECODER_SHUTDOWN; // initiate shutdown after flush.
798 break; // Wait for flush to complete.
799 case FLUSHING_DECODER_SHUTDOWN:
800 break; // Wait for flush to complete.
801 case SHUTTING_DOWN_DECODER:
802 break; // Wait for shutdown to complete.
803 case FLUSHED:
804 // Widevine source reads must stop before releasing the video decoder.
805 if (!audio && mSource != NULL && mSourceFlags & Source::FLAG_SECURE) {
806 mSource->stop();
807 }
808 getDecoder(audio)->initiateShutdown(); // In the middle of a seek.
809 *flushing = SHUTTING_DOWN_DECODER; // Shut down.
810 break;
811 case SHUT_DOWN:
812 finishFlushIfPossible(); // Should not occur.
813 break; // Finish anyways.
Marco Nelissen9e2b7912014-08-18 16:13:03 -0700814 }
Andy Hung2abde2c2014-09-30 14:40:32 -0700815 notifyListener(MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, err);
Lajos Molnar1cd13982014-01-17 15:12:51 -0800816 } else {
817 ALOGV("Unhandled decoder notification %d '%c%c%c%c'.",
Andreas Hubera1f8ab02012-11-30 10:53:22 -0800818 what,
819 what >> 24,
820 (what >> 16) & 0xff,
821 (what >> 8) & 0xff,
822 what & 0xff);
Andreas Huberf9334412010-12-15 15:17:42 -0800823 }
824
825 break;
826 }
827
828 case kWhatRendererNotify:
829 {
Wei Jia57568df2014-09-22 10:16:29 -0700830 int32_t requesterGeneration = mRendererGeneration - 1;
831 CHECK(msg->findInt32("generation", &requesterGeneration));
832 if (requesterGeneration != mRendererGeneration) {
833 ALOGV("got message from old renderer, generation(%d:%d)",
834 requesterGeneration, mRendererGeneration);
835 return;
836 }
837
Andreas Huberf9334412010-12-15 15:17:42 -0800838 int32_t what;
839 CHECK(msg->findInt32("what", &what));
840
841 if (what == Renderer::kWhatEOS) {
842 int32_t audio;
843 CHECK(msg->findInt32("audio", &audio));
844
Andreas Huberc92fd242011-08-16 13:48:44 -0700845 int32_t finalResult;
846 CHECK(msg->findInt32("finalResult", &finalResult));
847
Andreas Huberf9334412010-12-15 15:17:42 -0800848 if (audio) {
849 mAudioEOS = true;
850 } else {
851 mVideoEOS = true;
852 }
853
Andreas Huberc92fd242011-08-16 13:48:44 -0700854 if (finalResult == ERROR_END_OF_STREAM) {
Steve Block3856b092011-10-20 11:56:00 +0100855 ALOGV("reached %s EOS", audio ? "audio" : "video");
Andreas Huberc92fd242011-08-16 13:48:44 -0700856 } else {
Steve Block29357bc2012-01-06 19:20:56 +0000857 ALOGE("%s track encountered an error (%d)",
Andreas Huberc92fd242011-08-16 13:48:44 -0700858 audio ? "audio" : "video", finalResult);
859
860 notifyListener(
861 MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, finalResult);
862 }
Andreas Huberf9334412010-12-15 15:17:42 -0800863
864 if ((mAudioEOS || mAudioDecoder == NULL)
865 && (mVideoEOS || mVideoDecoder == NULL)) {
866 notifyListener(MEDIA_PLAYBACK_COMPLETE, 0, 0);
867 }
Andreas Huber3fe62152011-09-16 15:09:22 -0700868 } else if (what == Renderer::kWhatFlushComplete) {
Andreas Huberf9334412010-12-15 15:17:42 -0800869 int32_t audio;
870 CHECK(msg->findInt32("audio", &audio));
871
Steve Block3856b092011-10-20 11:56:00 +0100872 ALOGV("renderer %s flush completed.", audio ? "audio" : "video");
Andy Hung8d121d42014-10-03 09:53:53 -0700873 handleFlushComplete(audio, false /* isDecoder */);
874 finishFlushIfPossible();
James Dongf57b4ea2012-07-20 13:38:36 -0700875 } else if (what == Renderer::kWhatVideoRenderingStart) {
876 notifyListener(MEDIA_INFO, MEDIA_INFO_RENDERING_START, 0);
Lajos Molnarcbaffcf2013-08-14 18:30:38 -0700877 } else if (what == Renderer::kWhatMediaRenderingStart) {
878 ALOGV("media rendering started");
879 notifyListener(MEDIA_STARTED, 0, 0);
Wei Jia3a2956d2014-07-22 16:01:33 -0700880 } else if (what == Renderer::kWhatAudioOffloadTearDown) {
Ronghua Wua10fd232014-11-06 16:15:20 -0800881 ALOGV("Tear down audio offload, fall back to s/w path if due to error.");
Wei Jia3a2956d2014-07-22 16:01:33 -0700882 int64_t positionUs;
883 CHECK(msg->findInt64("positionUs", &positionUs));
Ronghua Wu08529172014-10-02 16:55:52 -0700884 int32_t reason;
885 CHECK(msg->findInt32("reason", &reason));
Andy Hung282a7e32014-08-14 15:56:34 -0700886 closeAudioSink();
Wei Jia3a2956d2014-07-22 16:01:33 -0700887 mAudioDecoder.clear();
Wei Jia57568df2014-09-22 10:16:29 -0700888 ++mAudioDecoderGeneration;
Chong Zhang7137ec72014-11-12 16:41:05 -0800889 mRenderer->flush(
890 true /* audio */, false /* notifyComplete */);
Wei Jia3a2956d2014-07-22 16:01:33 -0700891 if (mVideoDecoder != NULL) {
Chong Zhang7137ec72014-11-12 16:41:05 -0800892 mRenderer->flush(
893 false /* audio */, false /* notifyComplete */);
Wei Jia3a2956d2014-07-22 16:01:33 -0700894 }
Wei Jia3a2956d2014-07-22 16:01:33 -0700895
Wei Jiae427abf2014-09-22 15:21:11 -0700896 performSeek(positionUs, false /* needNotify */);
Ronghua Wu08529172014-10-02 16:55:52 -0700897 if (reason == Renderer::kDueToError) {
Ronghua Wua10fd232014-11-06 16:15:20 -0800898 mRenderer->signalDisableOffloadAudio();
899 mOffloadAudio = false;
Ronghua Wu08529172014-10-02 16:55:52 -0700900 instantiateDecoder(true /* audio */, &mAudioDecoder);
901 }
Andreas Huberf9334412010-12-15 15:17:42 -0800902 }
903 break;
904 }
905
906 case kWhatMoreDataQueued:
907 {
908 break;
909 }
910
Andreas Huber1aef2112011-01-04 14:01:29 -0800911 case kWhatReset:
912 {
Steve Block3856b092011-10-20 11:56:00 +0100913 ALOGV("kWhatReset");
Andreas Huber1aef2112011-01-04 14:01:29 -0800914
Andreas Hubera1f8ab02012-11-30 10:53:22 -0800915 mDeferredActions.push_back(
Wei Jiafef808d2014-10-31 17:57:05 -0700916 new FlushDecoderAction(
917 FLUSH_CMD_SHUTDOWN /* audio */,
918 FLUSH_CMD_SHUTDOWN /* video */));
Andreas Huberb7c8e912012-11-27 15:02:53 -0800919
Andreas Hubera1f8ab02012-11-30 10:53:22 -0800920 mDeferredActions.push_back(
921 new SimpleAction(&NuPlayer::performReset));
Andreas Huberb58ce9f2011-11-28 16:27:35 -0800922
Andreas Hubera1f8ab02012-11-30 10:53:22 -0800923 processDeferredActions();
Andreas Huber1aef2112011-01-04 14:01:29 -0800924 break;
925 }
926
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800927 case kWhatSeek:
928 {
929 int64_t seekTimeUs;
Wei Jiae427abf2014-09-22 15:21:11 -0700930 int32_t needNotify;
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800931 CHECK(msg->findInt64("seekTimeUs", &seekTimeUs));
Wei Jiae427abf2014-09-22 15:21:11 -0700932 CHECK(msg->findInt32("needNotify", &needNotify));
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800933
Wei Jiae427abf2014-09-22 15:21:11 -0700934 ALOGV("kWhatSeek seekTimeUs=%lld us, needNotify=%d",
935 seekTimeUs, needNotify);
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800936
Andreas Hubera1f8ab02012-11-30 10:53:22 -0800937 mDeferredActions.push_back(
Wei Jiafef808d2014-10-31 17:57:05 -0700938 new FlushDecoderAction(FLUSH_CMD_FLUSH /* audio */,
939 FLUSH_CMD_FLUSH /* video */));
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800940
Wei Jiae427abf2014-09-22 15:21:11 -0700941 mDeferredActions.push_back(
942 new SeekAction(seekTimeUs, needNotify));
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800943
Chong Zhangf8d71772014-11-26 15:08:34 -0800944 // After a flush without shutdown, decoder is paused.
945 // Don't resume it until source seek is done, otherwise it could
Chong Zhang7137ec72014-11-12 16:41:05 -0800946 // start pulling stale data too soon.
947 mDeferredActions.push_back(
Chong Zhangf8d71772014-11-26 15:08:34 -0800948 new ResumeDecoderAction(needNotify));
Chong Zhang7137ec72014-11-12 16:41:05 -0800949
Andreas Hubera1f8ab02012-11-30 10:53:22 -0800950 processDeferredActions();
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800951 break;
952 }
953
Andreas Huberb4082222011-01-20 15:23:04 -0800954 case kWhatPause:
955 {
Wei Jia7e9f7f72014-09-23 10:55:35 -0700956 if (mSource != NULL) {
957 mSource->pause();
958 } else {
959 ALOGW("pause called when source is gone or not set");
960 }
961 if (mRenderer != NULL) {
962 mRenderer->pause();
963 } else {
964 ALOGW("pause called when renderer is gone or not set");
965 }
Andreas Huberb4082222011-01-20 15:23:04 -0800966 break;
967 }
968
Andreas Huberb5f25f02013-02-05 10:14:26 -0800969 case kWhatSourceNotify:
970 {
Andreas Huber9575c962013-02-05 13:59:56 -0800971 onSourceNotify(msg);
Andreas Huberb5f25f02013-02-05 10:14:26 -0800972 break;
973 }
974
Chong Zhanga7fa1d92014-06-11 14:49:23 -0700975 case kWhatClosedCaptionNotify:
976 {
977 onClosedCaptionNotify(msg);
978 break;
979 }
980
Andreas Huberf9334412010-12-15 15:17:42 -0800981 default:
982 TRESPASS();
983 break;
984 }
985}
986
Wei Jia94211742014-10-28 17:09:06 -0700987void NuPlayer::onResume() {
988 if (mSource != NULL) {
989 mSource->resume();
990 } else {
991 ALOGW("resume called when source is gone or not set");
992 }
993 // |mAudioDecoder| may have been released due to the pause timeout, so re-create it if
994 // needed.
995 if (audioDecoderStillNeeded() && mAudioDecoder == NULL) {
996 instantiateDecoder(true /* audio */, &mAudioDecoder);
997 }
998 if (mRenderer != NULL) {
999 mRenderer->resume();
1000 } else {
1001 ALOGW("resume called when renderer is gone or not set");
1002 }
1003}
1004
1005void NuPlayer::onStart() {
Wei Jia94211742014-10-28 17:09:06 -07001006 mOffloadAudio = false;
1007 mAudioEOS = false;
1008 mVideoEOS = false;
Wei Jia94211742014-10-28 17:09:06 -07001009 mStarted = true;
1010
1011 /* instantiate decoders now for secure playback */
1012 if (mSourceFlags & Source::FLAG_SECURE) {
1013 if (mNativeWindow != NULL) {
1014 instantiateDecoder(false, &mVideoDecoder);
1015 }
1016
1017 if (mAudioSink != NULL) {
1018 instantiateDecoder(true, &mAudioDecoder);
1019 }
1020 }
1021
1022 mSource->start();
1023
1024 uint32_t flags = 0;
1025
1026 if (mSource->isRealTime()) {
1027 flags |= Renderer::FLAG_REAL_TIME;
1028 }
1029
1030 sp<MetaData> audioMeta = mSource->getFormatMeta(true /* audio */);
1031 audio_stream_type_t streamType = AUDIO_STREAM_MUSIC;
1032 if (mAudioSink != NULL) {
1033 streamType = mAudioSink->getAudioStreamType();
1034 }
1035
1036 sp<AMessage> videoFormat = mSource->getFormat(false /* audio */);
1037
1038 mOffloadAudio =
1039 canOffloadStream(audioMeta, (videoFormat != NULL),
1040 true /* is_streaming */, streamType);
1041 if (mOffloadAudio) {
1042 flags |= Renderer::FLAG_OFFLOAD_AUDIO;
1043 }
1044
1045 sp<AMessage> notify = new AMessage(kWhatRendererNotify, id());
1046 ++mRendererGeneration;
1047 notify->setInt32("generation", mRendererGeneration);
1048 mRenderer = new Renderer(mAudioSink, notify, flags);
1049
1050 mRendererLooper = new ALooper;
1051 mRendererLooper->setName("NuPlayerRenderer");
1052 mRendererLooper->start(false, false, ANDROID_PRIORITY_AUDIO);
1053 mRendererLooper->registerHandler(mRenderer);
1054
1055 sp<MetaData> meta = getFileMeta();
1056 int32_t rate;
1057 if (meta != NULL
1058 && meta->findInt32(kKeyFrameRate, &rate) && rate > 0) {
1059 mRenderer->setVideoFrameRate(rate);
1060 }
1061
Wei Jiac6cfd702014-11-11 16:33:20 -08001062 if (mVideoDecoder != NULL) {
1063 mVideoDecoder->setRenderer(mRenderer);
1064 }
1065 if (mAudioDecoder != NULL) {
1066 mAudioDecoder->setRenderer(mRenderer);
1067 }
1068
Wei Jia94211742014-10-28 17:09:06 -07001069 postScanSources();
1070}
1071
Ronghua Wud7988b12014-10-03 15:19:10 -07001072bool NuPlayer::audioDecoderStillNeeded() {
1073 // Audio decoder is no longer needed if it's in shut/shutting down status.
1074 return ((mFlushingAudio != SHUT_DOWN) && (mFlushingAudio != SHUTTING_DOWN_DECODER));
1075}
1076
Andy Hung8d121d42014-10-03 09:53:53 -07001077void NuPlayer::handleFlushComplete(bool audio, bool isDecoder) {
1078 // We wait for both the decoder flush and the renderer flush to complete
1079 // before entering either the FLUSHED or the SHUTTING_DOWN_DECODER state.
1080
1081 mFlushComplete[audio][isDecoder] = true;
1082 if (!mFlushComplete[audio][!isDecoder]) {
1083 return;
1084 }
1085
1086 FlushStatus *state = audio ? &mFlushingAudio : &mFlushingVideo;
1087 switch (*state) {
1088 case FLUSHING_DECODER:
1089 {
1090 *state = FLUSHED;
Andy Hung8d121d42014-10-03 09:53:53 -07001091 break;
1092 }
1093
1094 case FLUSHING_DECODER_SHUTDOWN:
1095 {
1096 *state = SHUTTING_DOWN_DECODER;
1097
1098 ALOGV("initiating %s decoder shutdown", audio ? "audio" : "video");
1099 if (!audio) {
Andy Hung8d121d42014-10-03 09:53:53 -07001100 // Widevine source reads must stop before releasing the video decoder.
1101 if (mSource != NULL && mSourceFlags & Source::FLAG_SECURE) {
1102 mSource->stop();
1103 }
1104 }
1105 getDecoder(audio)->initiateShutdown();
1106 break;
1107 }
1108
1109 default:
1110 // decoder flush completes only occur in a flushing state.
1111 LOG_ALWAYS_FATAL_IF(isDecoder, "decoder flush in invalid state %d", *state);
1112 break;
1113 }
1114}
1115
Andreas Huber3831a062010-12-21 10:22:33 -08001116void NuPlayer::finishFlushIfPossible() {
Wei Jia53904f32014-07-29 10:22:53 -07001117 if (mFlushingAudio != NONE && mFlushingAudio != FLUSHED
1118 && mFlushingAudio != SHUT_DOWN) {
Andreas Huber3831a062010-12-21 10:22:33 -08001119 return;
1120 }
1121
Wei Jia53904f32014-07-29 10:22:53 -07001122 if (mFlushingVideo != NONE && mFlushingVideo != FLUSHED
1123 && mFlushingVideo != SHUT_DOWN) {
Andreas Huber3831a062010-12-21 10:22:33 -08001124 return;
1125 }
1126
Steve Block3856b092011-10-20 11:56:00 +01001127 ALOGV("both audio and video are flushed now.");
Andreas Huber3831a062010-12-21 10:22:33 -08001128
Andreas Huber3831a062010-12-21 10:22:33 -08001129 mFlushingAudio = NONE;
1130 mFlushingVideo = NONE;
Andreas Huber3831a062010-12-21 10:22:33 -08001131
Andy Hung8d121d42014-10-03 09:53:53 -07001132 clearFlushComplete();
1133
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001134 processDeferredActions();
Andreas Huber1aef2112011-01-04 14:01:29 -08001135}
1136
1137void NuPlayer::postScanSources() {
1138 if (mScanSourcesPending) {
1139 return;
1140 }
1141
1142 sp<AMessage> msg = new AMessage(kWhatScanSources, id());
1143 msg->setInt32("generation", mScanSourcesGeneration);
1144 msg->post();
1145
1146 mScanSourcesPending = true;
1147}
1148
Andy Hung282a7e32014-08-14 15:56:34 -07001149void NuPlayer::openAudioSink(const sp<AMessage> &format, bool offloadOnly) {
Andy Hung282a7e32014-08-14 15:56:34 -07001150 uint32_t flags;
1151 int64_t durationUs;
Chong Zhang3b9eb1f2014-10-15 17:05:08 -07001152 bool hasVideo = (mVideoDecoder != NULL);
Andy Hung282a7e32014-08-14 15:56:34 -07001153 // FIXME: we should handle the case where the video decoder
1154 // is created after we receive the format change indication.
1155 // Current code will just make that we select deep buffer
1156 // with video which should not be a problem as it should
1157 // not prevent from keeping A/V sync.
Eric Laurentd88c3ca2014-10-28 10:52:11 -07001158 if (!hasVideo &&
Andy Hung282a7e32014-08-14 15:56:34 -07001159 mSource->getDuration(&durationUs) == OK &&
1160 durationUs
1161 > AUDIO_SINK_MIN_DEEP_BUFFER_DURATION_US) {
1162 flags = AUDIO_OUTPUT_FLAG_DEEP_BUFFER;
1163 } else {
1164 flags = AUDIO_OUTPUT_FLAG_NONE;
1165 }
1166
Chong Zhang3b9eb1f2014-10-15 17:05:08 -07001167 mOffloadAudio = mRenderer->openAudioSink(
1168 format, offloadOnly, hasVideo, flags);
1169
Andy Hung282a7e32014-08-14 15:56:34 -07001170 if (mOffloadAudio) {
Chong Zhang3b9eb1f2014-10-15 17:05:08 -07001171 sp<MetaData> audioMeta =
1172 mSource->getFormatMeta(true /* audio */);
1173 sendMetaDataToHal(mAudioSink, audioMeta);
Andy Hung282a7e32014-08-14 15:56:34 -07001174 }
1175}
1176
1177void NuPlayer::closeAudioSink() {
Chong Zhang3b9eb1f2014-10-15 17:05:08 -07001178 mRenderer->closeAudioSink();
Andy Hung282a7e32014-08-14 15:56:34 -07001179}
1180
Chong Zhang7137ec72014-11-12 16:41:05 -08001181status_t NuPlayer::instantiateDecoder(bool audio, sp<DecoderBase> *decoder) {
Andreas Huberf9334412010-12-15 15:17:42 -08001182 if (*decoder != NULL) {
1183 return OK;
1184 }
1185
Andreas Huber84066782011-08-16 09:34:26 -07001186 sp<AMessage> format = mSource->getFormat(audio);
Andreas Huberf9334412010-12-15 15:17:42 -08001187
Andreas Huber84066782011-08-16 09:34:26 -07001188 if (format == NULL) {
Andreas Huberf9334412010-12-15 15:17:42 -08001189 return -EWOULDBLOCK;
1190 }
1191
Andreas Huber3fe62152011-09-16 15:09:22 -07001192 if (!audio) {
Andreas Huber84066782011-08-16 09:34:26 -07001193 AString mime;
1194 CHECK(format->findString("mime", &mime));
Chong Zhanga7fa1d92014-06-11 14:49:23 -07001195
1196 sp<AMessage> ccNotify = new AMessage(kWhatClosedCaptionNotify, id());
1197 mCCDecoder = new CCDecoder(ccNotify);
Lajos Molnar09524832014-07-17 14:29:51 -07001198
1199 if (mSourceFlags & Source::FLAG_SECURE) {
1200 format->setInt32("secure", true);
1201 }
Andreas Huber3fe62152011-09-16 15:09:22 -07001202 }
1203
Wei Jiabc2fb722014-07-08 16:37:57 -07001204 if (audio) {
Wei Jia88703c32014-08-06 11:24:07 -07001205 sp<AMessage> notify = new AMessage(kWhatAudioNotify, id());
1206 ++mAudioDecoderGeneration;
1207 notify->setInt32("generation", mAudioDecoderGeneration);
1208
Wei Jiabc2fb722014-07-08 16:37:57 -07001209 if (mOffloadAudio) {
Wei Jiac6cfd702014-11-11 16:33:20 -08001210 *decoder = new DecoderPassThrough(notify, mSource, mRenderer);
Wei Jiabc2fb722014-07-08 16:37:57 -07001211 } else {
Wei Jiac6cfd702014-11-11 16:33:20 -08001212 *decoder = new Decoder(notify, mSource, mRenderer);
Wei Jiabc2fb722014-07-08 16:37:57 -07001213 }
1214 } else {
Wei Jia88703c32014-08-06 11:24:07 -07001215 sp<AMessage> notify = new AMessage(kWhatVideoNotify, id());
1216 ++mVideoDecoderGeneration;
1217 notify->setInt32("generation", mVideoDecoderGeneration);
1218
Chong Zhang7137ec72014-11-12 16:41:05 -08001219 *decoder = new Decoder(
1220 notify, mSource, mRenderer, mNativeWindow, mCCDecoder);
Lajos Molnard9fd6312014-11-06 11:00:00 -08001221
1222 // enable FRC if high-quality AV sync is requested, even if not
1223 // queuing to native window, as this will even improve textureview
1224 // playback.
1225 {
1226 char value[PROPERTY_VALUE_MAX];
1227 if (property_get("persist.sys.media.avsync", value, NULL) &&
1228 (!strcmp("1", value) || !strcasecmp("true", value))) {
1229 format->setInt32("auto-frc", 1);
1230 }
1231 }
Wei Jiabc2fb722014-07-08 16:37:57 -07001232 }
Lajos Molnar1cd13982014-01-17 15:12:51 -08001233 (*decoder)->init();
Andreas Huber84066782011-08-16 09:34:26 -07001234 (*decoder)->configure(format);
Andreas Huberf9334412010-12-15 15:17:42 -08001235
Lajos Molnar09524832014-07-17 14:29:51 -07001236 // allocate buffers to decrypt widevine source buffers
1237 if (!audio && (mSourceFlags & Source::FLAG_SECURE)) {
1238 Vector<sp<ABuffer> > inputBufs;
1239 CHECK_EQ((*decoder)->getInputBuffers(&inputBufs), (status_t)OK);
1240
1241 Vector<MediaBuffer *> mediaBufs;
1242 for (size_t i = 0; i < inputBufs.size(); i++) {
1243 const sp<ABuffer> &buffer = inputBufs[i];
1244 MediaBuffer *mbuf = new MediaBuffer(buffer->data(), buffer->size());
1245 mediaBufs.push(mbuf);
1246 }
1247
1248 status_t err = mSource->setBuffers(audio, mediaBufs);
1249 if (err != OK) {
1250 for (size_t i = 0; i < mediaBufs.size(); ++i) {
1251 mediaBufs[i]->release();
1252 }
1253 mediaBufs.clear();
1254 ALOGE("Secure source didn't support secure mediaBufs.");
1255 return err;
1256 }
1257 }
Andreas Huberf9334412010-12-15 15:17:42 -08001258 return OK;
1259}
1260
Chong Zhangced1c2f2014-08-08 15:22:35 -07001261void NuPlayer::updateVideoSize(
1262 const sp<AMessage> &inputFormat,
1263 const sp<AMessage> &outputFormat) {
1264 if (inputFormat == NULL) {
1265 ALOGW("Unknown video size, reporting 0x0!");
1266 notifyListener(MEDIA_SET_VIDEO_SIZE, 0, 0);
1267 return;
1268 }
1269
1270 int32_t displayWidth, displayHeight;
1271 int32_t cropLeft, cropTop, cropRight, cropBottom;
1272
1273 if (outputFormat != NULL) {
1274 int32_t width, height;
1275 CHECK(outputFormat->findInt32("width", &width));
1276 CHECK(outputFormat->findInt32("height", &height));
1277
1278 int32_t cropLeft, cropTop, cropRight, cropBottom;
1279 CHECK(outputFormat->findRect(
1280 "crop",
1281 &cropLeft, &cropTop, &cropRight, &cropBottom));
1282
1283 displayWidth = cropRight - cropLeft + 1;
1284 displayHeight = cropBottom - cropTop + 1;
1285
1286 ALOGV("Video output format changed to %d x %d "
1287 "(crop: %d x %d @ (%d, %d))",
1288 width, height,
1289 displayWidth,
1290 displayHeight,
1291 cropLeft, cropTop);
1292 } else {
1293 CHECK(inputFormat->findInt32("width", &displayWidth));
1294 CHECK(inputFormat->findInt32("height", &displayHeight));
1295
1296 ALOGV("Video input format %d x %d", displayWidth, displayHeight);
1297 }
1298
1299 // Take into account sample aspect ratio if necessary:
1300 int32_t sarWidth, sarHeight;
1301 if (inputFormat->findInt32("sar-width", &sarWidth)
1302 && inputFormat->findInt32("sar-height", &sarHeight)) {
1303 ALOGV("Sample aspect ratio %d : %d", sarWidth, sarHeight);
1304
1305 displayWidth = (displayWidth * sarWidth) / sarHeight;
1306
1307 ALOGV("display dimensions %d x %d", displayWidth, displayHeight);
1308 }
1309
1310 int32_t rotationDegrees;
1311 if (!inputFormat->findInt32("rotation-degrees", &rotationDegrees)) {
1312 rotationDegrees = 0;
1313 }
1314
1315 if (rotationDegrees == 90 || rotationDegrees == 270) {
1316 int32_t tmp = displayWidth;
1317 displayWidth = displayHeight;
1318 displayHeight = tmp;
1319 }
1320
1321 notifyListener(
1322 MEDIA_SET_VIDEO_SIZE,
1323 displayWidth,
1324 displayHeight);
1325}
1326
Chong Zhangdcb89b32013-08-06 09:44:47 -07001327void NuPlayer::notifyListener(int msg, int ext1, int ext2, const Parcel *in) {
Andreas Huber43c3e6c2011-01-05 12:17:08 -08001328 if (mDriver == NULL) {
Andreas Huberf9334412010-12-15 15:17:42 -08001329 return;
1330 }
1331
Andreas Huber43c3e6c2011-01-05 12:17:08 -08001332 sp<NuPlayerDriver> driver = mDriver.promote();
Andreas Huberf9334412010-12-15 15:17:42 -08001333
Andreas Huber43c3e6c2011-01-05 12:17:08 -08001334 if (driver == NULL) {
Andreas Huberf9334412010-12-15 15:17:42 -08001335 return;
1336 }
1337
Chong Zhangdcb89b32013-08-06 09:44:47 -07001338 driver->notifyListener(msg, ext1, ext2, in);
Andreas Huberf9334412010-12-15 15:17:42 -08001339}
1340
Chong Zhang7137ec72014-11-12 16:41:05 -08001341void NuPlayer::flushDecoder(bool audio, bool needShutdown) {
Andreas Huber14f76722013-01-15 09:04:18 -08001342 ALOGV("[%s] flushDecoder needShutdown=%d",
1343 audio ? "audio" : "video", needShutdown);
1344
Chong Zhang7137ec72014-11-12 16:41:05 -08001345 const sp<DecoderBase> &decoder = getDecoder(audio);
Lajos Molnar87603c02014-08-20 19:25:30 -07001346 if (decoder == NULL) {
Steve Blockdf64d152012-01-04 20:05:49 +00001347 ALOGI("flushDecoder %s without decoder present",
Andreas Huber6e3d3112011-11-28 12:36:11 -08001348 audio ? "audio" : "video");
Lajos Molnar87603c02014-08-20 19:25:30 -07001349 return;
Andreas Huber6e3d3112011-11-28 12:36:11 -08001350 }
1351
Andreas Huber1aef2112011-01-04 14:01:29 -08001352 // Make sure we don't continue to scan sources until we finish flushing.
1353 ++mScanSourcesGeneration;
Andreas Huber43c3e6c2011-01-05 12:17:08 -08001354 mScanSourcesPending = false;
Andreas Huber1aef2112011-01-04 14:01:29 -08001355
Chong Zhang7137ec72014-11-12 16:41:05 -08001356 decoder->signalFlush();
Andreas Huber1aef2112011-01-04 14:01:29 -08001357
1358 FlushStatus newStatus =
1359 needShutdown ? FLUSHING_DECODER_SHUTDOWN : FLUSHING_DECODER;
1360
Andy Hung8d121d42014-10-03 09:53:53 -07001361 mFlushComplete[audio][false /* isDecoder */] = false;
1362 mFlushComplete[audio][true /* isDecoder */] = false;
Andreas Huber1aef2112011-01-04 14:01:29 -08001363 if (audio) {
Wei Jia53904f32014-07-29 10:22:53 -07001364 ALOGE_IF(mFlushingAudio != NONE,
1365 "audio flushDecoder() is called in state %d", mFlushingAudio);
Andreas Huber1aef2112011-01-04 14:01:29 -08001366 mFlushingAudio = newStatus;
Andreas Huber1aef2112011-01-04 14:01:29 -08001367 } else {
Wei Jia53904f32014-07-29 10:22:53 -07001368 ALOGE_IF(mFlushingVideo != NONE,
1369 "video flushDecoder() is called in state %d", mFlushingVideo);
Andreas Huber1aef2112011-01-04 14:01:29 -08001370 mFlushingVideo = newStatus;
Andreas Huber1aef2112011-01-04 14:01:29 -08001371 }
1372}
1373
Chong Zhangced1c2f2014-08-08 15:22:35 -07001374void NuPlayer::queueDecoderShutdown(
1375 bool audio, bool video, const sp<AMessage> &reply) {
1376 ALOGI("queueDecoderShutdown audio=%d, video=%d", audio, video);
Andreas Huber84066782011-08-16 09:34:26 -07001377
Chong Zhangced1c2f2014-08-08 15:22:35 -07001378 mDeferredActions.push_back(
Wei Jiafef808d2014-10-31 17:57:05 -07001379 new FlushDecoderAction(
1380 audio ? FLUSH_CMD_SHUTDOWN : FLUSH_CMD_NONE,
1381 video ? FLUSH_CMD_SHUTDOWN : FLUSH_CMD_NONE));
Andreas Huber84066782011-08-16 09:34:26 -07001382
Chong Zhangced1c2f2014-08-08 15:22:35 -07001383 mDeferredActions.push_back(
1384 new SimpleAction(&NuPlayer::performScanSources));
Andreas Huber84066782011-08-16 09:34:26 -07001385
Chong Zhangced1c2f2014-08-08 15:22:35 -07001386 mDeferredActions.push_back(new PostMessageAction(reply));
1387
1388 processDeferredActions();
Andreas Huber84066782011-08-16 09:34:26 -07001389}
1390
James Dong0d268a32012-08-31 12:18:27 -07001391status_t NuPlayer::setVideoScalingMode(int32_t mode) {
1392 mVideoScalingMode = mode;
Andreas Huber57a339c2012-12-03 11:18:00 -08001393 if (mNativeWindow != NULL) {
James Dong0d268a32012-08-31 12:18:27 -07001394 status_t ret = native_window_set_scaling_mode(
1395 mNativeWindow->getNativeWindow().get(), mVideoScalingMode);
1396 if (ret != OK) {
1397 ALOGE("Failed to set scaling mode (%d): %s",
1398 -ret, strerror(-ret));
1399 return ret;
1400 }
1401 }
1402 return OK;
1403}
1404
Chong Zhangdcb89b32013-08-06 09:44:47 -07001405status_t NuPlayer::getTrackInfo(Parcel* reply) const {
1406 sp<AMessage> msg = new AMessage(kWhatGetTrackInfo, id());
1407 msg->setPointer("reply", reply);
1408
1409 sp<AMessage> response;
1410 status_t err = msg->postAndAwaitResponse(&response);
1411 return err;
1412}
1413
Robert Shih7c4f0d72014-07-09 18:53:31 -07001414status_t NuPlayer::getSelectedTrack(int32_t type, Parcel* reply) const {
1415 sp<AMessage> msg = new AMessage(kWhatGetSelectedTrack, id());
1416 msg->setPointer("reply", reply);
1417 msg->setInt32("type", type);
1418
1419 sp<AMessage> response;
1420 status_t err = msg->postAndAwaitResponse(&response);
1421 if (err == OK && response != NULL) {
1422 CHECK(response->findInt32("err", &err));
1423 }
1424 return err;
1425}
1426
Robert Shih6ffb1fd2014-10-29 16:24:32 -07001427status_t NuPlayer::selectTrack(size_t trackIndex, bool select, int64_t timeUs) {
Chong Zhangdcb89b32013-08-06 09:44:47 -07001428 sp<AMessage> msg = new AMessage(kWhatSelectTrack, id());
1429 msg->setSize("trackIndex", trackIndex);
1430 msg->setInt32("select", select);
Robert Shih6ffb1fd2014-10-29 16:24:32 -07001431 msg->setInt64("timeUs", timeUs);
Chong Zhangdcb89b32013-08-06 09:44:47 -07001432
1433 sp<AMessage> response;
1434 status_t err = msg->postAndAwaitResponse(&response);
1435
Chong Zhang404fced2014-06-11 14:45:31 -07001436 if (err != OK) {
1437 return err;
1438 }
1439
1440 if (!response->findInt32("err", &err)) {
1441 err = OK;
1442 }
1443
Chong Zhangdcb89b32013-08-06 09:44:47 -07001444 return err;
1445}
1446
Ronghua Wua73d9e02014-10-08 15:13:29 -07001447status_t NuPlayer::getCurrentPosition(int64_t *mediaUs) {
1448 sp<Renderer> renderer = mRenderer;
1449 if (renderer == NULL) {
1450 return NO_INIT;
1451 }
1452
1453 return renderer->getCurrentPosition(mediaUs);
1454}
1455
1456void NuPlayer::getStats(int64_t *numFramesTotal, int64_t *numFramesDropped) {
Chong Zhang7137ec72014-11-12 16:41:05 -08001457 sp<DecoderBase> decoder = getDecoder(false /* audio */);
1458 if (decoder != NULL) {
1459 decoder->getStats(numFramesTotal, numFramesDropped);
1460 } else {
1461 *numFramesTotal = 0;
1462 *numFramesDropped = 0;
1463 }
Ronghua Wua73d9e02014-10-08 15:13:29 -07001464}
1465
Marco Nelissenf0b72b52014-09-16 15:43:44 -07001466sp<MetaData> NuPlayer::getFileMeta() {
1467 return mSource->getFileFormatMeta();
1468}
1469
Andreas Huberb7c8e912012-11-27 15:02:53 -08001470void NuPlayer::schedulePollDuration() {
1471 sp<AMessage> msg = new AMessage(kWhatPollDuration, id());
1472 msg->setInt32("generation", mPollDurationGeneration);
1473 msg->post();
1474}
1475
1476void NuPlayer::cancelPollDuration() {
1477 ++mPollDurationGeneration;
1478}
1479
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001480void NuPlayer::processDeferredActions() {
1481 while (!mDeferredActions.empty()) {
1482 // We won't execute any deferred actions until we're no longer in
1483 // an intermediate state, i.e. one more more decoders are currently
1484 // flushing or shutting down.
1485
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001486 if (mFlushingAudio != NONE || mFlushingVideo != NONE) {
1487 // We're currently flushing, postpone the reset until that's
1488 // completed.
1489
1490 ALOGV("postponing action mFlushingAudio=%d, mFlushingVideo=%d",
1491 mFlushingAudio, mFlushingVideo);
1492
1493 break;
1494 }
1495
1496 sp<Action> action = *mDeferredActions.begin();
1497 mDeferredActions.erase(mDeferredActions.begin());
1498
1499 action->execute(this);
1500 }
1501}
1502
Wei Jiae427abf2014-09-22 15:21:11 -07001503void NuPlayer::performSeek(int64_t seekTimeUs, bool needNotify) {
1504 ALOGV("performSeek seekTimeUs=%lld us (%.2f secs), needNotify(%d)",
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001505 seekTimeUs,
Wei Jiae427abf2014-09-22 15:21:11 -07001506 seekTimeUs / 1E6,
1507 needNotify);
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001508
Andy Hungadf34bf2014-09-03 18:22:22 -07001509 if (mSource == NULL) {
1510 // This happens when reset occurs right before the loop mode
1511 // asynchronously seeks to the start of the stream.
1512 LOG_ALWAYS_FATAL_IF(mAudioDecoder != NULL || mVideoDecoder != NULL,
1513 "mSource is NULL and decoders not NULL audio(%p) video(%p)",
1514 mAudioDecoder.get(), mVideoDecoder.get());
1515 return;
1516 }
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001517 mSource->seekTo(seekTimeUs);
Robert Shihd3b0bbb2014-07-23 15:00:25 -07001518 ++mTimedTextGeneration;
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001519
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001520 // everything's flushed, continue playback.
1521}
1522
Wei Jiafef808d2014-10-31 17:57:05 -07001523void NuPlayer::performDecoderFlush(FlushCommand audio, FlushCommand video) {
1524 ALOGV("performDecoderFlush audio=%d, video=%d", audio, video);
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001525
Wei Jiafef808d2014-10-31 17:57:05 -07001526 if ((audio == FLUSH_CMD_NONE || mAudioDecoder == NULL)
1527 && (video == FLUSH_CMD_NONE || mVideoDecoder == NULL)) {
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001528 return;
1529 }
1530
Wei Jiafef808d2014-10-31 17:57:05 -07001531 if (audio != FLUSH_CMD_NONE && mAudioDecoder != NULL) {
1532 flushDecoder(true /* audio */, (audio == FLUSH_CMD_SHUTDOWN));
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001533 }
1534
Wei Jiafef808d2014-10-31 17:57:05 -07001535 if (video != FLUSH_CMD_NONE && mVideoDecoder != NULL) {
1536 flushDecoder(false /* audio */, (video == FLUSH_CMD_SHUTDOWN));
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001537 }
1538}
1539
1540void NuPlayer::performReset() {
1541 ALOGV("performReset");
1542
1543 CHECK(mAudioDecoder == NULL);
1544 CHECK(mVideoDecoder == NULL);
1545
1546 cancelPollDuration();
1547
1548 ++mScanSourcesGeneration;
1549 mScanSourcesPending = false;
1550
Lajos Molnar09524832014-07-17 14:29:51 -07001551 if (mRendererLooper != NULL) {
1552 if (mRenderer != NULL) {
1553 mRendererLooper->unregisterHandler(mRenderer->id());
1554 }
1555 mRendererLooper->stop();
1556 mRendererLooper.clear();
1557 }
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001558 mRenderer.clear();
Wei Jia57568df2014-09-22 10:16:29 -07001559 ++mRendererGeneration;
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001560
1561 if (mSource != NULL) {
1562 mSource->stop();
Andreas Huberb5f25f02013-02-05 10:14:26 -08001563
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001564 mSource.clear();
1565 }
1566
1567 if (mDriver != NULL) {
1568 sp<NuPlayerDriver> driver = mDriver.promote();
1569 if (driver != NULL) {
1570 driver->notifyResetComplete();
1571 }
1572 }
Andreas Huber57a339c2012-12-03 11:18:00 -08001573
1574 mStarted = false;
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001575}
1576
1577void NuPlayer::performScanSources() {
1578 ALOGV("performScanSources");
1579
Andreas Huber57a339c2012-12-03 11:18:00 -08001580 if (!mStarted) {
1581 return;
1582 }
1583
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001584 if (mAudioDecoder == NULL || mVideoDecoder == NULL) {
1585 postScanSources();
1586 }
1587}
1588
Andreas Huber57a339c2012-12-03 11:18:00 -08001589void NuPlayer::performSetSurface(const sp<NativeWindowWrapper> &wrapper) {
1590 ALOGV("performSetSurface");
1591
1592 mNativeWindow = wrapper;
1593
1594 // XXX - ignore error from setVideoScalingMode for now
1595 setVideoScalingMode(mVideoScalingMode);
Chong Zhang13d6faa2014-08-22 15:35:28 -07001596
1597 if (mDriver != NULL) {
1598 sp<NuPlayerDriver> driver = mDriver.promote();
1599 if (driver != NULL) {
1600 driver->notifySetSurfaceComplete();
1601 }
1602 }
Andreas Huber57a339c2012-12-03 11:18:00 -08001603}
1604
Chong Zhangf8d71772014-11-26 15:08:34 -08001605void NuPlayer::performResumeDecoders(bool needNotify) {
1606 if (needNotify) {
1607 mResumePending = true;
1608 if (mVideoDecoder == NULL) {
1609 // if audio-only, we can notify seek complete now,
1610 // as the resume operation will be relatively fast.
1611 finishResume();
1612 }
1613 }
1614
Chong Zhang7137ec72014-11-12 16:41:05 -08001615 if (mVideoDecoder != NULL) {
Chong Zhangf8d71772014-11-26 15:08:34 -08001616 // When there is continuous seek, MediaPlayer will cache the seek
1617 // position, and send down new seek request when previous seek is
1618 // complete. Let's wait for at least one video output frame before
1619 // notifying seek complete, so that the video thumbnail gets updated
1620 // when seekbar is dragged.
1621 mVideoDecoder->signalResume(needNotify);
Chong Zhang7137ec72014-11-12 16:41:05 -08001622 }
1623
1624 if (mAudioDecoder != NULL) {
Chong Zhangf8d71772014-11-26 15:08:34 -08001625 mAudioDecoder->signalResume(false /* needNotify */);
1626 }
1627}
1628
1629void NuPlayer::finishResume() {
1630 if (mResumePending) {
1631 mResumePending = false;
1632 if (mDriver != NULL) {
1633 sp<NuPlayerDriver> driver = mDriver.promote();
1634 if (driver != NULL) {
1635 driver->notifySeekComplete();
1636 }
1637 }
Chong Zhang7137ec72014-11-12 16:41:05 -08001638 }
1639}
1640
Andreas Huber9575c962013-02-05 13:59:56 -08001641void NuPlayer::onSourceNotify(const sp<AMessage> &msg) {
1642 int32_t what;
1643 CHECK(msg->findInt32("what", &what));
1644
1645 switch (what) {
1646 case Source::kWhatPrepared:
1647 {
Andreas Huberb5f28d42013-04-25 15:11:19 -07001648 if (mSource == NULL) {
1649 // This is a stale notification from a source that was
1650 // asynchronously preparing when the client called reset().
1651 // We handled the reset, the source is gone.
1652 break;
1653 }
1654
Andreas Huberec0c5972013-02-05 14:47:13 -08001655 int32_t err;
1656 CHECK(msg->findInt32("err", &err));
1657
Andreas Huber9575c962013-02-05 13:59:56 -08001658 sp<NuPlayerDriver> driver = mDriver.promote();
1659 if (driver != NULL) {
Marco Nelissendd114d12014-05-28 15:23:14 -07001660 // notify duration first, so that it's definitely set when
1661 // the app received the "prepare complete" callback.
1662 int64_t durationUs;
1663 if (mSource->getDuration(&durationUs) == OK) {
1664 driver->notifyDuration(durationUs);
1665 }
Andreas Huberec0c5972013-02-05 14:47:13 -08001666 driver->notifyPrepareCompleted(err);
Andreas Huber9575c962013-02-05 13:59:56 -08001667 }
Andreas Huber99759402013-04-01 14:28:31 -07001668
Andreas Huber9575c962013-02-05 13:59:56 -08001669 break;
1670 }
1671
1672 case Source::kWhatFlagsChanged:
1673 {
1674 uint32_t flags;
1675 CHECK(msg->findInt32("flags", (int32_t *)&flags));
1676
Chong Zhang4b7069d2013-09-11 12:52:43 -07001677 sp<NuPlayerDriver> driver = mDriver.promote();
1678 if (driver != NULL) {
1679 driver->notifyFlagsChanged(flags);
1680 }
1681
Andreas Huber9575c962013-02-05 13:59:56 -08001682 if ((mSourceFlags & Source::FLAG_DYNAMIC_DURATION)
1683 && (!(flags & Source::FLAG_DYNAMIC_DURATION))) {
1684 cancelPollDuration();
1685 } else if (!(mSourceFlags & Source::FLAG_DYNAMIC_DURATION)
1686 && (flags & Source::FLAG_DYNAMIC_DURATION)
1687 && (mAudioDecoder != NULL || mVideoDecoder != NULL)) {
1688 schedulePollDuration();
1689 }
1690
1691 mSourceFlags = flags;
1692 break;
1693 }
1694
1695 case Source::kWhatVideoSizeChanged:
1696 {
Chong Zhangced1c2f2014-08-08 15:22:35 -07001697 sp<AMessage> format;
1698 CHECK(msg->findMessage("format", &format));
Andreas Huber9575c962013-02-05 13:59:56 -08001699
Chong Zhangced1c2f2014-08-08 15:22:35 -07001700 updateVideoSize(format);
Andreas Huber9575c962013-02-05 13:59:56 -08001701 break;
1702 }
1703
Chong Zhang2a3cc9a2014-08-21 17:48:26 -07001704 case Source::kWhatBufferingUpdate:
1705 {
1706 int32_t percentage;
1707 CHECK(msg->findInt32("percentage", &percentage));
1708
1709 notifyListener(MEDIA_BUFFERING_UPDATE, percentage, 0);
1710 break;
1711 }
1712
Roger Jönssonb50e83e2013-01-21 16:26:41 +01001713 case Source::kWhatBufferingStart:
1714 {
1715 notifyListener(MEDIA_INFO, MEDIA_INFO_BUFFERING_START, 0);
1716 break;
1717 }
1718
1719 case Source::kWhatBufferingEnd:
1720 {
1721 notifyListener(MEDIA_INFO, MEDIA_INFO_BUFFERING_END, 0);
1722 break;
1723 }
1724
Chong Zhangdcb89b32013-08-06 09:44:47 -07001725 case Source::kWhatSubtitleData:
1726 {
1727 sp<ABuffer> buffer;
1728 CHECK(msg->findBuffer("buffer", &buffer));
1729
Chong Zhang404fced2014-06-11 14:45:31 -07001730 sendSubtitleData(buffer, 0 /* baseIndex */);
Chong Zhangdcb89b32013-08-06 09:44:47 -07001731 break;
1732 }
1733
Robert Shihd3b0bbb2014-07-23 15:00:25 -07001734 case Source::kWhatTimedTextData:
1735 {
1736 int32_t generation;
1737 if (msg->findInt32("generation", &generation)
1738 && generation != mTimedTextGeneration) {
1739 break;
1740 }
1741
1742 sp<ABuffer> buffer;
1743 CHECK(msg->findBuffer("buffer", &buffer));
1744
1745 sp<NuPlayerDriver> driver = mDriver.promote();
1746 if (driver == NULL) {
1747 break;
1748 }
1749
1750 int posMs;
1751 int64_t timeUs, posUs;
1752 driver->getCurrentPosition(&posMs);
1753 posUs = posMs * 1000;
1754 CHECK(buffer->meta()->findInt64("timeUs", &timeUs));
1755
1756 if (posUs < timeUs) {
1757 if (!msg->findInt32("generation", &generation)) {
1758 msg->setInt32("generation", mTimedTextGeneration);
1759 }
1760 msg->post(timeUs - posUs);
1761 } else {
1762 sendTimedTextData(buffer);
1763 }
1764 break;
1765 }
1766
Andreas Huber14f76722013-01-15 09:04:18 -08001767 case Source::kWhatQueueDecoderShutdown:
1768 {
1769 int32_t audio, video;
1770 CHECK(msg->findInt32("audio", &audio));
1771 CHECK(msg->findInt32("video", &video));
1772
1773 sp<AMessage> reply;
1774 CHECK(msg->findMessage("reply", &reply));
1775
1776 queueDecoderShutdown(audio, video, reply);
1777 break;
1778 }
1779
Ronghua Wu80276872014-08-28 15:50:29 -07001780 case Source::kWhatDrmNoLicense:
1781 {
1782 notifyListener(MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, ERROR_DRM_NO_LICENSE);
1783 break;
1784 }
1785
Andreas Huber9575c962013-02-05 13:59:56 -08001786 default:
1787 TRESPASS();
1788 }
1789}
1790
Chong Zhanga7fa1d92014-06-11 14:49:23 -07001791void NuPlayer::onClosedCaptionNotify(const sp<AMessage> &msg) {
1792 int32_t what;
1793 CHECK(msg->findInt32("what", &what));
1794
1795 switch (what) {
1796 case NuPlayer::CCDecoder::kWhatClosedCaptionData:
1797 {
1798 sp<ABuffer> buffer;
1799 CHECK(msg->findBuffer("buffer", &buffer));
1800
1801 size_t inbandTracks = 0;
1802 if (mSource != NULL) {
1803 inbandTracks = mSource->getTrackCount();
1804 }
1805
1806 sendSubtitleData(buffer, inbandTracks);
1807 break;
1808 }
1809
1810 case NuPlayer::CCDecoder::kWhatTrackAdded:
1811 {
1812 notifyListener(MEDIA_INFO, MEDIA_INFO_METADATA_UPDATE, 0);
1813
1814 break;
1815 }
1816
1817 default:
1818 TRESPASS();
1819 }
1820
1821
1822}
1823
Chong Zhang404fced2014-06-11 14:45:31 -07001824void NuPlayer::sendSubtitleData(const sp<ABuffer> &buffer, int32_t baseIndex) {
1825 int32_t trackIndex;
1826 int64_t timeUs, durationUs;
1827 CHECK(buffer->meta()->findInt32("trackIndex", &trackIndex));
1828 CHECK(buffer->meta()->findInt64("timeUs", &timeUs));
1829 CHECK(buffer->meta()->findInt64("durationUs", &durationUs));
1830
1831 Parcel in;
1832 in.writeInt32(trackIndex + baseIndex);
1833 in.writeInt64(timeUs);
1834 in.writeInt64(durationUs);
1835 in.writeInt32(buffer->size());
1836 in.writeInt32(buffer->size());
1837 in.write(buffer->data(), buffer->size());
1838
1839 notifyListener(MEDIA_SUBTITLE_DATA, 0, 0, &in);
1840}
Robert Shihd3b0bbb2014-07-23 15:00:25 -07001841
1842void NuPlayer::sendTimedTextData(const sp<ABuffer> &buffer) {
1843 const void *data;
1844 size_t size = 0;
1845 int64_t timeUs;
1846 int32_t flag = TextDescriptions::LOCAL_DESCRIPTIONS;
1847
1848 AString mime;
1849 CHECK(buffer->meta()->findString("mime", &mime));
1850 CHECK(strcasecmp(mime.c_str(), MEDIA_MIMETYPE_TEXT_3GPP) == 0);
1851
1852 data = buffer->data();
1853 size = buffer->size();
1854
1855 Parcel parcel;
1856 if (size > 0) {
1857 CHECK(buffer->meta()->findInt64("timeUs", &timeUs));
1858 flag |= TextDescriptions::IN_BAND_TEXT_3GPP;
1859 TextDescriptions::getParcelOfDescriptions(
1860 (const uint8_t *)data, size, flag, timeUs / 1000, &parcel);
1861 }
1862
1863 if ((parcel.dataSize() > 0)) {
1864 notifyListener(MEDIA_TIMED_TEXT, 0, 0, &parcel);
1865 } else { // send an empty timed text
1866 notifyListener(MEDIA_TIMED_TEXT, 0, 0);
1867 }
1868}
Andreas Huberb5f25f02013-02-05 10:14:26 -08001869////////////////////////////////////////////////////////////////////////////////
1870
Chong Zhangced1c2f2014-08-08 15:22:35 -07001871sp<AMessage> NuPlayer::Source::getFormat(bool audio) {
1872 sp<MetaData> meta = getFormatMeta(audio);
1873
1874 if (meta == NULL) {
1875 return NULL;
1876 }
1877
1878 sp<AMessage> msg = new AMessage;
1879
1880 if(convertMetaDataToMessage(meta, &msg) == OK) {
1881 return msg;
1882 }
1883 return NULL;
1884}
1885
Andreas Huber9575c962013-02-05 13:59:56 -08001886void NuPlayer::Source::notifyFlagsChanged(uint32_t flags) {
1887 sp<AMessage> notify = dupNotify();
1888 notify->setInt32("what", kWhatFlagsChanged);
1889 notify->setInt32("flags", flags);
1890 notify->post();
1891}
1892
Chong Zhangced1c2f2014-08-08 15:22:35 -07001893void NuPlayer::Source::notifyVideoSizeChanged(const sp<AMessage> &format) {
Andreas Huber9575c962013-02-05 13:59:56 -08001894 sp<AMessage> notify = dupNotify();
1895 notify->setInt32("what", kWhatVideoSizeChanged);
Chong Zhangced1c2f2014-08-08 15:22:35 -07001896 notify->setMessage("format", format);
Andreas Huber9575c962013-02-05 13:59:56 -08001897 notify->post();
1898}
1899
Andreas Huberec0c5972013-02-05 14:47:13 -08001900void NuPlayer::Source::notifyPrepared(status_t err) {
Andreas Huber9575c962013-02-05 13:59:56 -08001901 sp<AMessage> notify = dupNotify();
1902 notify->setInt32("what", kWhatPrepared);
Andreas Huberec0c5972013-02-05 14:47:13 -08001903 notify->setInt32("err", err);
Andreas Huber9575c962013-02-05 13:59:56 -08001904 notify->post();
1905}
1906
Andreas Huber84333e02014-02-07 15:36:10 -08001907void NuPlayer::Source::onMessageReceived(const sp<AMessage> & /* msg */) {
Andreas Huberb5f25f02013-02-05 10:14:26 -08001908 TRESPASS();
1909}
1910
Andreas Huberf9334412010-12-15 15:17:42 -08001911} // namespace android