blob: e02a2d5a4a951bf72374bda98f2bb07dfa8bfad2 [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
Lajos Molnarf4849522014-12-10 16:58:57 -0800540 if (mSource == NULL || mSource->getFormat(false /* audio */) == NULL) {
Wei Jiafef808d2014-10-31 17:57:05 -0700541 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();
Andy Hung202bce12014-12-03 11:47:36 -0800632 const bool hasVideo = (videoFormat != NULL);
633 const bool canOffload = canOffloadStream(
634 audioMeta, hasVideo, true /* is_streaming */, streamType);
Ronghua Wua10fd232014-11-06 16:15:20 -0800635 if (canOffload) {
636 if (!mOffloadAudio) {
637 mRenderer->signalEnableOffloadAudio();
638 }
Andy Hung282a7e32014-08-14 15:56:34 -0700639 // open audio sink early under offload mode.
640 sp<AMessage> format = mSource->getFormat(true /*audio*/);
Andy Hung202bce12014-12-03 11:47:36 -0800641 tryOpenAudioSinkForOffload(format, hasVideo);
Andy Hung282a7e32014-08-14 15:56:34 -0700642 }
Andreas Huber5bc087c2010-12-23 10:27:40 -0800643 instantiateDecoder(true, &mAudioDecoder);
Andreas Huberf9334412010-12-15 15:17:42 -0800644 }
645
Andreas Huberb7c8e912012-11-27 15:02:53 -0800646 if (!mHadAnySourcesBefore
647 && (mAudioDecoder != NULL || mVideoDecoder != NULL)) {
648 // This is the first time we've found anything playable.
649
Andreas Huber9575c962013-02-05 13:59:56 -0800650 if (mSourceFlags & Source::FLAG_DYNAMIC_DURATION) {
Andreas Huberb7c8e912012-11-27 15:02:53 -0800651 schedulePollDuration();
652 }
653 }
654
Andreas Hubereac68ba2011-09-27 12:12:25 -0700655 status_t err;
656 if ((err = mSource->feedMoreTSData()) != OK) {
Andreas Huber1aef2112011-01-04 14:01:29 -0800657 if (mAudioDecoder == NULL && mVideoDecoder == NULL) {
658 // We're not currently decoding anything (no audio or
659 // video tracks found) and we just ran out of input data.
Andreas Hubereac68ba2011-09-27 12:12:25 -0700660
661 if (err == ERROR_END_OF_STREAM) {
662 notifyListener(MEDIA_PLAYBACK_COMPLETE, 0, 0);
663 } else {
664 notifyListener(MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, err);
665 }
Andreas Huber1aef2112011-01-04 14:01:29 -0800666 }
Andreas Huberf9334412010-12-15 15:17:42 -0800667 break;
668 }
669
Andreas Huberfbe9d812012-08-31 14:05:27 -0700670 if ((mAudioDecoder == NULL && mAudioSink != NULL)
671 || (mVideoDecoder == NULL && mNativeWindow != NULL)) {
Andreas Huberf9334412010-12-15 15:17:42 -0800672 msg->post(100000ll);
Andreas Huber5bc087c2010-12-23 10:27:40 -0800673 mScanSourcesPending = true;
Andreas Huberf9334412010-12-15 15:17:42 -0800674 }
675 break;
676 }
677
678 case kWhatVideoNotify:
679 case kWhatAudioNotify:
680 {
681 bool audio = msg->what() == kWhatAudioNotify;
682
Wei Jia88703c32014-08-06 11:24:07 -0700683 int32_t currentDecoderGeneration =
684 (audio? mAudioDecoderGeneration : mVideoDecoderGeneration);
685 int32_t requesterGeneration = currentDecoderGeneration - 1;
686 CHECK(msg->findInt32("generation", &requesterGeneration));
687
688 if (requesterGeneration != currentDecoderGeneration) {
689 ALOGV("got message from old %s decoder, generation(%d:%d)",
690 audio ? "audio" : "video", requesterGeneration,
691 currentDecoderGeneration);
692 sp<AMessage> reply;
693 if (!(msg->findMessage("reply", &reply))) {
694 return;
695 }
696
697 reply->setInt32("err", INFO_DISCONTINUITY);
698 reply->post();
699 return;
700 }
701
Andreas Huberf9334412010-12-15 15:17:42 -0800702 int32_t what;
Lajos Molnar1cd13982014-01-17 15:12:51 -0800703 CHECK(msg->findInt32("what", &what));
Andreas Huberf9334412010-12-15 15:17:42 -0800704
Chong Zhang7137ec72014-11-12 16:41:05 -0800705 if (what == DecoderBase::kWhatInputDiscontinuity) {
706 int32_t formatChange;
707 CHECK(msg->findInt32("formatChange", &formatChange));
Andreas Huberf9334412010-12-15 15:17:42 -0800708
Chong Zhang7137ec72014-11-12 16:41:05 -0800709 ALOGV("%s discontinuity: formatChange %d",
710 audio ? "audio" : "video", formatChange);
711
712 if (formatChange) {
713 mDeferredActions.push_back(
714 new FlushDecoderAction(
715 audio ? FLUSH_CMD_SHUTDOWN : FLUSH_CMD_NONE,
716 audio ? FLUSH_CMD_NONE : FLUSH_CMD_SHUTDOWN));
Andreas Huberf9334412010-12-15 15:17:42 -0800717 }
Chong Zhang7137ec72014-11-12 16:41:05 -0800718
719 mDeferredActions.push_back(
720 new SimpleAction(
721 &NuPlayer::performScanSources));
722
723 processDeferredActions();
724 } else if (what == DecoderBase::kWhatEOS) {
Andreas Huberdc9bacd2011-09-26 10:53:29 -0700725 int32_t err;
Lajos Molnar1cd13982014-01-17 15:12:51 -0800726 CHECK(msg->findInt32("err", &err));
Andreas Huberdc9bacd2011-09-26 10:53:29 -0700727
728 if (err == ERROR_END_OF_STREAM) {
Steve Block3856b092011-10-20 11:56:00 +0100729 ALOGV("got %s decoder EOS", audio ? "audio" : "video");
Andreas Huberdc9bacd2011-09-26 10:53:29 -0700730 } else {
Steve Block3856b092011-10-20 11:56:00 +0100731 ALOGV("got %s decoder EOS w/ error %d",
Andreas Huberdc9bacd2011-09-26 10:53:29 -0700732 audio ? "audio" : "video",
733 err);
734 }
735
736 mRenderer->queueEOS(audio, err);
Chong Zhang7137ec72014-11-12 16:41:05 -0800737 } else if (what == DecoderBase::kWhatFlushCompleted) {
Steve Block3856b092011-10-20 11:56:00 +0100738 ALOGV("decoder %s flush completed", audio ? "audio" : "video");
Andreas Huberf9334412010-12-15 15:17:42 -0800739
Andy Hung8d121d42014-10-03 09:53:53 -0700740 handleFlushComplete(audio, true /* isDecoder */);
Andreas Huber3831a062010-12-21 10:22:33 -0800741 finishFlushIfPossible();
Chong Zhang7137ec72014-11-12 16:41:05 -0800742 } else if (what == DecoderBase::kWhatVideoSizeChanged) {
Lajos Molnar1cd13982014-01-17 15:12:51 -0800743 sp<AMessage> format;
744 CHECK(msg->findMessage("format", &format));
745
Wei Jiac6cfd702014-11-11 16:33:20 -0800746 sp<AMessage> inputFormat =
747 mSource->getFormat(false /* audio */);
Andreas Huber3831a062010-12-21 10:22:33 -0800748
Wei Jiac6cfd702014-11-11 16:33:20 -0800749 updateVideoSize(inputFormat, format);
Chong Zhang7137ec72014-11-12 16:41:05 -0800750 } else if (what == DecoderBase::kWhatShutdownCompleted) {
Steve Block3856b092011-10-20 11:56:00 +0100751 ALOGV("%s shutdown completed", audio ? "audio" : "video");
Andreas Huber3831a062010-12-21 10:22:33 -0800752 if (audio) {
753 mAudioDecoder.clear();
Wei Jia57568df2014-09-22 10:16:29 -0700754 ++mAudioDecoderGeneration;
Andreas Huber3831a062010-12-21 10:22:33 -0800755
756 CHECK_EQ((int)mFlushingAudio, (int)SHUTTING_DOWN_DECODER);
757 mFlushingAudio = SHUT_DOWN;
758 } else {
759 mVideoDecoder.clear();
Wei Jia57568df2014-09-22 10:16:29 -0700760 ++mVideoDecoderGeneration;
Andreas Huber3831a062010-12-21 10:22:33 -0800761
762 CHECK_EQ((int)mFlushingVideo, (int)SHUTTING_DOWN_DECODER);
763 mFlushingVideo = SHUT_DOWN;
764 }
765
766 finishFlushIfPossible();
Chong Zhangf8d71772014-11-26 15:08:34 -0800767 } else if (what == DecoderBase::kWhatResumeCompleted) {
768 finishResume();
Chong Zhang7137ec72014-11-12 16:41:05 -0800769 } else if (what == DecoderBase::kWhatError) {
Chong Zhangf4c0a942014-08-11 15:14:10 -0700770 status_t err;
Andy Hung2abde2c2014-09-30 14:40:32 -0700771 if (!msg->findInt32("err", &err) || err == OK) {
Chong Zhangf4c0a942014-08-11 15:14:10 -0700772 err = UNKNOWN_ERROR;
773 }
Andy Hungcf31f1e2014-09-23 14:59:01 -0700774
Andy Hung2abde2c2014-09-30 14:40:32 -0700775 // Decoder errors can be due to Source (e.g. from streaming),
776 // or from decoding corrupted bitstreams, or from other decoder
777 // MediaCodec operations (e.g. from an ongoing reset or seek).
Andy Hung202bce12014-12-03 11:47:36 -0800778 // They may also be due to openAudioSink failure at
779 // decoder start or after a format change.
Andy Hung2abde2c2014-09-30 14:40:32 -0700780 //
781 // We try to gracefully shut down the affected decoder if possible,
782 // rather than trying to force the shutdown with something
783 // similar to performReset(). This method can lead to a hang
784 // if MediaCodec functions block after an error, but they should
785 // typically return INVALID_OPERATION instead of blocking.
786
787 FlushStatus *flushing = audio ? &mFlushingAudio : &mFlushingVideo;
788 ALOGE("received error(%#x) from %s decoder, flushing(%d), now shutting down",
789 err, audio ? "audio" : "video", *flushing);
790
791 switch (*flushing) {
792 case NONE:
793 mDeferredActions.push_back(
Wei Jiafef808d2014-10-31 17:57:05 -0700794 new FlushDecoderAction(
795 audio ? FLUSH_CMD_SHUTDOWN : FLUSH_CMD_NONE,
796 audio ? FLUSH_CMD_NONE : FLUSH_CMD_SHUTDOWN));
Andy Hung2abde2c2014-09-30 14:40:32 -0700797 processDeferredActions();
798 break;
799 case FLUSHING_DECODER:
800 *flushing = FLUSHING_DECODER_SHUTDOWN; // initiate shutdown after flush.
801 break; // Wait for flush to complete.
802 case FLUSHING_DECODER_SHUTDOWN:
803 break; // Wait for flush to complete.
804 case SHUTTING_DOWN_DECODER:
805 break; // Wait for shutdown to complete.
806 case FLUSHED:
807 // Widevine source reads must stop before releasing the video decoder.
808 if (!audio && mSource != NULL && mSourceFlags & Source::FLAG_SECURE) {
809 mSource->stop();
810 }
811 getDecoder(audio)->initiateShutdown(); // In the middle of a seek.
812 *flushing = SHUTTING_DOWN_DECODER; // Shut down.
813 break;
814 case SHUT_DOWN:
815 finishFlushIfPossible(); // Should not occur.
816 break; // Finish anyways.
Marco Nelissen9e2b7912014-08-18 16:13:03 -0700817 }
Andy Hung2abde2c2014-09-30 14:40:32 -0700818 notifyListener(MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, err);
Lajos Molnar1cd13982014-01-17 15:12:51 -0800819 } else {
820 ALOGV("Unhandled decoder notification %d '%c%c%c%c'.",
Andreas Hubera1f8ab02012-11-30 10:53:22 -0800821 what,
822 what >> 24,
823 (what >> 16) & 0xff,
824 (what >> 8) & 0xff,
825 what & 0xff);
Andreas Huberf9334412010-12-15 15:17:42 -0800826 }
827
828 break;
829 }
830
831 case kWhatRendererNotify:
832 {
Wei Jia57568df2014-09-22 10:16:29 -0700833 int32_t requesterGeneration = mRendererGeneration - 1;
834 CHECK(msg->findInt32("generation", &requesterGeneration));
835 if (requesterGeneration != mRendererGeneration) {
836 ALOGV("got message from old renderer, generation(%d:%d)",
837 requesterGeneration, mRendererGeneration);
838 return;
839 }
840
Andreas Huberf9334412010-12-15 15:17:42 -0800841 int32_t what;
842 CHECK(msg->findInt32("what", &what));
843
844 if (what == Renderer::kWhatEOS) {
845 int32_t audio;
846 CHECK(msg->findInt32("audio", &audio));
847
Andreas Huberc92fd242011-08-16 13:48:44 -0700848 int32_t finalResult;
849 CHECK(msg->findInt32("finalResult", &finalResult));
850
Andreas Huberf9334412010-12-15 15:17:42 -0800851 if (audio) {
852 mAudioEOS = true;
853 } else {
854 mVideoEOS = true;
855 }
856
Andreas Huberc92fd242011-08-16 13:48:44 -0700857 if (finalResult == ERROR_END_OF_STREAM) {
Steve Block3856b092011-10-20 11:56:00 +0100858 ALOGV("reached %s EOS", audio ? "audio" : "video");
Andreas Huberc92fd242011-08-16 13:48:44 -0700859 } else {
Steve Block29357bc2012-01-06 19:20:56 +0000860 ALOGE("%s track encountered an error (%d)",
Andreas Huberc92fd242011-08-16 13:48:44 -0700861 audio ? "audio" : "video", finalResult);
862
863 notifyListener(
864 MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, finalResult);
865 }
Andreas Huberf9334412010-12-15 15:17:42 -0800866
867 if ((mAudioEOS || mAudioDecoder == NULL)
868 && (mVideoEOS || mVideoDecoder == NULL)) {
869 notifyListener(MEDIA_PLAYBACK_COMPLETE, 0, 0);
870 }
Andreas Huber3fe62152011-09-16 15:09:22 -0700871 } else if (what == Renderer::kWhatFlushComplete) {
Andreas Huberf9334412010-12-15 15:17:42 -0800872 int32_t audio;
873 CHECK(msg->findInt32("audio", &audio));
874
Steve Block3856b092011-10-20 11:56:00 +0100875 ALOGV("renderer %s flush completed.", audio ? "audio" : "video");
Andy Hung8d121d42014-10-03 09:53:53 -0700876 handleFlushComplete(audio, false /* isDecoder */);
877 finishFlushIfPossible();
James Dongf57b4ea2012-07-20 13:38:36 -0700878 } else if (what == Renderer::kWhatVideoRenderingStart) {
879 notifyListener(MEDIA_INFO, MEDIA_INFO_RENDERING_START, 0);
Lajos Molnarcbaffcf2013-08-14 18:30:38 -0700880 } else if (what == Renderer::kWhatMediaRenderingStart) {
881 ALOGV("media rendering started");
882 notifyListener(MEDIA_STARTED, 0, 0);
Wei Jia3a2956d2014-07-22 16:01:33 -0700883 } else if (what == Renderer::kWhatAudioOffloadTearDown) {
Ronghua Wua10fd232014-11-06 16:15:20 -0800884 ALOGV("Tear down audio offload, fall back to s/w path if due to error.");
Wei Jia3a2956d2014-07-22 16:01:33 -0700885 int64_t positionUs;
886 CHECK(msg->findInt64("positionUs", &positionUs));
Ronghua Wu08529172014-10-02 16:55:52 -0700887 int32_t reason;
888 CHECK(msg->findInt32("reason", &reason));
Andy Hung282a7e32014-08-14 15:56:34 -0700889 closeAudioSink();
Wei Jia3a2956d2014-07-22 16:01:33 -0700890 mAudioDecoder.clear();
Wei Jia57568df2014-09-22 10:16:29 -0700891 ++mAudioDecoderGeneration;
Chong Zhang7137ec72014-11-12 16:41:05 -0800892 mRenderer->flush(
893 true /* audio */, false /* notifyComplete */);
Wei Jia3a2956d2014-07-22 16:01:33 -0700894 if (mVideoDecoder != NULL) {
Chong Zhang7137ec72014-11-12 16:41:05 -0800895 mRenderer->flush(
896 false /* audio */, false /* notifyComplete */);
Wei Jia3a2956d2014-07-22 16:01:33 -0700897 }
Wei Jia3a2956d2014-07-22 16:01:33 -0700898
Wei Jiae427abf2014-09-22 15:21:11 -0700899 performSeek(positionUs, false /* needNotify */);
Ronghua Wu08529172014-10-02 16:55:52 -0700900 if (reason == Renderer::kDueToError) {
Ronghua Wua10fd232014-11-06 16:15:20 -0800901 mRenderer->signalDisableOffloadAudio();
902 mOffloadAudio = false;
Ronghua Wu08529172014-10-02 16:55:52 -0700903 instantiateDecoder(true /* audio */, &mAudioDecoder);
904 }
Andreas Huberf9334412010-12-15 15:17:42 -0800905 }
906 break;
907 }
908
909 case kWhatMoreDataQueued:
910 {
911 break;
912 }
913
Andreas Huber1aef2112011-01-04 14:01:29 -0800914 case kWhatReset:
915 {
Steve Block3856b092011-10-20 11:56:00 +0100916 ALOGV("kWhatReset");
Andreas Huber1aef2112011-01-04 14:01:29 -0800917
Andreas Hubera1f8ab02012-11-30 10:53:22 -0800918 mDeferredActions.push_back(
Wei Jiafef808d2014-10-31 17:57:05 -0700919 new FlushDecoderAction(
920 FLUSH_CMD_SHUTDOWN /* audio */,
921 FLUSH_CMD_SHUTDOWN /* video */));
Andreas Huberb7c8e912012-11-27 15:02:53 -0800922
Andreas Hubera1f8ab02012-11-30 10:53:22 -0800923 mDeferredActions.push_back(
924 new SimpleAction(&NuPlayer::performReset));
Andreas Huberb58ce9f2011-11-28 16:27:35 -0800925
Andreas Hubera1f8ab02012-11-30 10:53:22 -0800926 processDeferredActions();
Andreas Huber1aef2112011-01-04 14:01:29 -0800927 break;
928 }
929
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800930 case kWhatSeek:
931 {
932 int64_t seekTimeUs;
Wei Jiae427abf2014-09-22 15:21:11 -0700933 int32_t needNotify;
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800934 CHECK(msg->findInt64("seekTimeUs", &seekTimeUs));
Wei Jiae427abf2014-09-22 15:21:11 -0700935 CHECK(msg->findInt32("needNotify", &needNotify));
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800936
Wei Jiae427abf2014-09-22 15:21:11 -0700937 ALOGV("kWhatSeek seekTimeUs=%lld us, needNotify=%d",
938 seekTimeUs, needNotify);
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800939
Andreas Hubera1f8ab02012-11-30 10:53:22 -0800940 mDeferredActions.push_back(
Wei Jiafef808d2014-10-31 17:57:05 -0700941 new FlushDecoderAction(FLUSH_CMD_FLUSH /* audio */,
942 FLUSH_CMD_FLUSH /* video */));
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800943
Wei Jiae427abf2014-09-22 15:21:11 -0700944 mDeferredActions.push_back(
945 new SeekAction(seekTimeUs, needNotify));
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800946
Chong Zhangf8d71772014-11-26 15:08:34 -0800947 // After a flush without shutdown, decoder is paused.
948 // Don't resume it until source seek is done, otherwise it could
Chong Zhang7137ec72014-11-12 16:41:05 -0800949 // start pulling stale data too soon.
950 mDeferredActions.push_back(
Chong Zhangf8d71772014-11-26 15:08:34 -0800951 new ResumeDecoderAction(needNotify));
Chong Zhang7137ec72014-11-12 16:41:05 -0800952
Andreas Hubera1f8ab02012-11-30 10:53:22 -0800953 processDeferredActions();
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800954 break;
955 }
956
Andreas Huberb4082222011-01-20 15:23:04 -0800957 case kWhatPause:
958 {
Wei Jia7e9f7f72014-09-23 10:55:35 -0700959 if (mSource != NULL) {
960 mSource->pause();
961 } else {
962 ALOGW("pause called when source is gone or not set");
963 }
964 if (mRenderer != NULL) {
965 mRenderer->pause();
966 } else {
967 ALOGW("pause called when renderer is gone or not set");
968 }
Andreas Huberb4082222011-01-20 15:23:04 -0800969 break;
970 }
971
Andreas Huberb5f25f02013-02-05 10:14:26 -0800972 case kWhatSourceNotify:
973 {
Andreas Huber9575c962013-02-05 13:59:56 -0800974 onSourceNotify(msg);
Andreas Huberb5f25f02013-02-05 10:14:26 -0800975 break;
976 }
977
Chong Zhanga7fa1d92014-06-11 14:49:23 -0700978 case kWhatClosedCaptionNotify:
979 {
980 onClosedCaptionNotify(msg);
981 break;
982 }
983
Andreas Huberf9334412010-12-15 15:17:42 -0800984 default:
985 TRESPASS();
986 break;
987 }
988}
989
Wei Jia94211742014-10-28 17:09:06 -0700990void NuPlayer::onResume() {
991 if (mSource != NULL) {
992 mSource->resume();
993 } else {
994 ALOGW("resume called when source is gone or not set");
995 }
996 // |mAudioDecoder| may have been released due to the pause timeout, so re-create it if
997 // needed.
998 if (audioDecoderStillNeeded() && mAudioDecoder == NULL) {
999 instantiateDecoder(true /* audio */, &mAudioDecoder);
1000 }
1001 if (mRenderer != NULL) {
1002 mRenderer->resume();
1003 } else {
1004 ALOGW("resume called when renderer is gone or not set");
1005 }
1006}
1007
1008void NuPlayer::onStart() {
Wei Jia94211742014-10-28 17:09:06 -07001009 mOffloadAudio = false;
1010 mAudioEOS = false;
1011 mVideoEOS = false;
Wei Jia94211742014-10-28 17:09:06 -07001012 mStarted = true;
1013
1014 /* instantiate decoders now for secure playback */
1015 if (mSourceFlags & Source::FLAG_SECURE) {
1016 if (mNativeWindow != NULL) {
1017 instantiateDecoder(false, &mVideoDecoder);
1018 }
1019
1020 if (mAudioSink != NULL) {
1021 instantiateDecoder(true, &mAudioDecoder);
1022 }
1023 }
1024
1025 mSource->start();
1026
1027 uint32_t flags = 0;
1028
1029 if (mSource->isRealTime()) {
1030 flags |= Renderer::FLAG_REAL_TIME;
1031 }
1032
1033 sp<MetaData> audioMeta = mSource->getFormatMeta(true /* audio */);
1034 audio_stream_type_t streamType = AUDIO_STREAM_MUSIC;
1035 if (mAudioSink != NULL) {
1036 streamType = mAudioSink->getAudioStreamType();
1037 }
1038
1039 sp<AMessage> videoFormat = mSource->getFormat(false /* audio */);
1040
1041 mOffloadAudio =
1042 canOffloadStream(audioMeta, (videoFormat != NULL),
1043 true /* is_streaming */, streamType);
1044 if (mOffloadAudio) {
1045 flags |= Renderer::FLAG_OFFLOAD_AUDIO;
1046 }
1047
1048 sp<AMessage> notify = new AMessage(kWhatRendererNotify, id());
1049 ++mRendererGeneration;
1050 notify->setInt32("generation", mRendererGeneration);
1051 mRenderer = new Renderer(mAudioSink, notify, flags);
1052
1053 mRendererLooper = new ALooper;
1054 mRendererLooper->setName("NuPlayerRenderer");
1055 mRendererLooper->start(false, false, ANDROID_PRIORITY_AUDIO);
1056 mRendererLooper->registerHandler(mRenderer);
1057
1058 sp<MetaData> meta = getFileMeta();
1059 int32_t rate;
1060 if (meta != NULL
1061 && meta->findInt32(kKeyFrameRate, &rate) && rate > 0) {
1062 mRenderer->setVideoFrameRate(rate);
1063 }
1064
Wei Jiac6cfd702014-11-11 16:33:20 -08001065 if (mVideoDecoder != NULL) {
1066 mVideoDecoder->setRenderer(mRenderer);
1067 }
1068 if (mAudioDecoder != NULL) {
1069 mAudioDecoder->setRenderer(mRenderer);
1070 }
1071
Wei Jia94211742014-10-28 17:09:06 -07001072 postScanSources();
1073}
1074
Ronghua Wud7988b12014-10-03 15:19:10 -07001075bool NuPlayer::audioDecoderStillNeeded() {
1076 // Audio decoder is no longer needed if it's in shut/shutting down status.
1077 return ((mFlushingAudio != SHUT_DOWN) && (mFlushingAudio != SHUTTING_DOWN_DECODER));
1078}
1079
Andy Hung8d121d42014-10-03 09:53:53 -07001080void NuPlayer::handleFlushComplete(bool audio, bool isDecoder) {
1081 // We wait for both the decoder flush and the renderer flush to complete
1082 // before entering either the FLUSHED or the SHUTTING_DOWN_DECODER state.
1083
1084 mFlushComplete[audio][isDecoder] = true;
1085 if (!mFlushComplete[audio][!isDecoder]) {
1086 return;
1087 }
1088
1089 FlushStatus *state = audio ? &mFlushingAudio : &mFlushingVideo;
1090 switch (*state) {
1091 case FLUSHING_DECODER:
1092 {
1093 *state = FLUSHED;
Andy Hung8d121d42014-10-03 09:53:53 -07001094 break;
1095 }
1096
1097 case FLUSHING_DECODER_SHUTDOWN:
1098 {
1099 *state = SHUTTING_DOWN_DECODER;
1100
1101 ALOGV("initiating %s decoder shutdown", audio ? "audio" : "video");
1102 if (!audio) {
Andy Hung8d121d42014-10-03 09:53:53 -07001103 // Widevine source reads must stop before releasing the video decoder.
1104 if (mSource != NULL && mSourceFlags & Source::FLAG_SECURE) {
1105 mSource->stop();
1106 }
1107 }
1108 getDecoder(audio)->initiateShutdown();
1109 break;
1110 }
1111
1112 default:
1113 // decoder flush completes only occur in a flushing state.
1114 LOG_ALWAYS_FATAL_IF(isDecoder, "decoder flush in invalid state %d", *state);
1115 break;
1116 }
1117}
1118
Andreas Huber3831a062010-12-21 10:22:33 -08001119void NuPlayer::finishFlushIfPossible() {
Wei Jia53904f32014-07-29 10:22:53 -07001120 if (mFlushingAudio != NONE && mFlushingAudio != FLUSHED
1121 && mFlushingAudio != SHUT_DOWN) {
Andreas Huber3831a062010-12-21 10:22:33 -08001122 return;
1123 }
1124
Wei Jia53904f32014-07-29 10:22:53 -07001125 if (mFlushingVideo != NONE && mFlushingVideo != FLUSHED
1126 && mFlushingVideo != SHUT_DOWN) {
Andreas Huber3831a062010-12-21 10:22:33 -08001127 return;
1128 }
1129
Steve Block3856b092011-10-20 11:56:00 +01001130 ALOGV("both audio and video are flushed now.");
Andreas Huber3831a062010-12-21 10:22:33 -08001131
Andreas Huber3831a062010-12-21 10:22:33 -08001132 mFlushingAudio = NONE;
1133 mFlushingVideo = NONE;
Andreas Huber3831a062010-12-21 10:22:33 -08001134
Andy Hung8d121d42014-10-03 09:53:53 -07001135 clearFlushComplete();
1136
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001137 processDeferredActions();
Andreas Huber1aef2112011-01-04 14:01:29 -08001138}
1139
1140void NuPlayer::postScanSources() {
1141 if (mScanSourcesPending) {
1142 return;
1143 }
1144
1145 sp<AMessage> msg = new AMessage(kWhatScanSources, id());
1146 msg->setInt32("generation", mScanSourcesGeneration);
1147 msg->post();
1148
1149 mScanSourcesPending = true;
1150}
1151
Andy Hung202bce12014-12-03 11:47:36 -08001152void NuPlayer::tryOpenAudioSinkForOffload(const sp<AMessage> &format, bool hasVideo) {
1153 // Note: This is called early in NuPlayer to determine whether offloading
1154 // is possible; otherwise the decoders call the renderer openAudioSink directly.
Andy Hung282a7e32014-08-14 15:56:34 -07001155
Andy Hung202bce12014-12-03 11:47:36 -08001156 status_t err = mRenderer->openAudioSink(
1157 format, true /* offloadOnly */, hasVideo, AUDIO_OUTPUT_FLAG_NONE, &mOffloadAudio);
1158 if (err != OK) {
1159 // Any failure we turn off mOffloadAudio.
1160 mOffloadAudio = false;
1161 } else if (mOffloadAudio) {
Chong Zhang3b9eb1f2014-10-15 17:05:08 -07001162 sp<MetaData> audioMeta =
1163 mSource->getFormatMeta(true /* audio */);
1164 sendMetaDataToHal(mAudioSink, audioMeta);
Andy Hung282a7e32014-08-14 15:56:34 -07001165 }
1166}
1167
1168void NuPlayer::closeAudioSink() {
Chong Zhang3b9eb1f2014-10-15 17:05:08 -07001169 mRenderer->closeAudioSink();
Andy Hung282a7e32014-08-14 15:56:34 -07001170}
1171
Chong Zhang7137ec72014-11-12 16:41:05 -08001172status_t NuPlayer::instantiateDecoder(bool audio, sp<DecoderBase> *decoder) {
Andreas Huberf9334412010-12-15 15:17:42 -08001173 if (*decoder != NULL) {
1174 return OK;
1175 }
1176
Andreas Huber84066782011-08-16 09:34:26 -07001177 sp<AMessage> format = mSource->getFormat(audio);
Andreas Huberf9334412010-12-15 15:17:42 -08001178
Andreas Huber84066782011-08-16 09:34:26 -07001179 if (format == NULL) {
Andreas Huberf9334412010-12-15 15:17:42 -08001180 return -EWOULDBLOCK;
1181 }
1182
Andreas Huber3fe62152011-09-16 15:09:22 -07001183 if (!audio) {
Andreas Huber84066782011-08-16 09:34:26 -07001184 AString mime;
1185 CHECK(format->findString("mime", &mime));
Chong Zhanga7fa1d92014-06-11 14:49:23 -07001186
1187 sp<AMessage> ccNotify = new AMessage(kWhatClosedCaptionNotify, id());
1188 mCCDecoder = new CCDecoder(ccNotify);
Lajos Molnar09524832014-07-17 14:29:51 -07001189
1190 if (mSourceFlags & Source::FLAG_SECURE) {
1191 format->setInt32("secure", true);
1192 }
Chong Zhang17134602015-01-07 16:14:34 -08001193
1194 if (mSourceFlags & Source::FLAG_PROTECTED) {
1195 format->setInt32("protected", true);
1196 }
Andreas Huber3fe62152011-09-16 15:09:22 -07001197 }
1198
Wei Jiabc2fb722014-07-08 16:37:57 -07001199 if (audio) {
Wei Jia88703c32014-08-06 11:24:07 -07001200 sp<AMessage> notify = new AMessage(kWhatAudioNotify, id());
1201 ++mAudioDecoderGeneration;
1202 notify->setInt32("generation", mAudioDecoderGeneration);
1203
Wei Jiabc2fb722014-07-08 16:37:57 -07001204 if (mOffloadAudio) {
Wei Jiac6cfd702014-11-11 16:33:20 -08001205 *decoder = new DecoderPassThrough(notify, mSource, mRenderer);
Wei Jiabc2fb722014-07-08 16:37:57 -07001206 } else {
Wei Jiac6cfd702014-11-11 16:33:20 -08001207 *decoder = new Decoder(notify, mSource, mRenderer);
Wei Jiabc2fb722014-07-08 16:37:57 -07001208 }
1209 } else {
Wei Jia88703c32014-08-06 11:24:07 -07001210 sp<AMessage> notify = new AMessage(kWhatVideoNotify, id());
1211 ++mVideoDecoderGeneration;
1212 notify->setInt32("generation", mVideoDecoderGeneration);
1213
Chong Zhang7137ec72014-11-12 16:41:05 -08001214 *decoder = new Decoder(
1215 notify, mSource, mRenderer, mNativeWindow, mCCDecoder);
Lajos Molnard9fd6312014-11-06 11:00:00 -08001216
1217 // enable FRC if high-quality AV sync is requested, even if not
1218 // queuing to native window, as this will even improve textureview
1219 // playback.
1220 {
1221 char value[PROPERTY_VALUE_MAX];
1222 if (property_get("persist.sys.media.avsync", value, NULL) &&
1223 (!strcmp("1", value) || !strcasecmp("true", value))) {
1224 format->setInt32("auto-frc", 1);
1225 }
1226 }
Wei Jiabc2fb722014-07-08 16:37:57 -07001227 }
Lajos Molnar1cd13982014-01-17 15:12:51 -08001228 (*decoder)->init();
Andreas Huber84066782011-08-16 09:34:26 -07001229 (*decoder)->configure(format);
Andreas Huberf9334412010-12-15 15:17:42 -08001230
Lajos Molnar09524832014-07-17 14:29:51 -07001231 // allocate buffers to decrypt widevine source buffers
1232 if (!audio && (mSourceFlags & Source::FLAG_SECURE)) {
1233 Vector<sp<ABuffer> > inputBufs;
1234 CHECK_EQ((*decoder)->getInputBuffers(&inputBufs), (status_t)OK);
1235
1236 Vector<MediaBuffer *> mediaBufs;
1237 for (size_t i = 0; i < inputBufs.size(); i++) {
1238 const sp<ABuffer> &buffer = inputBufs[i];
1239 MediaBuffer *mbuf = new MediaBuffer(buffer->data(), buffer->size());
1240 mediaBufs.push(mbuf);
1241 }
1242
1243 status_t err = mSource->setBuffers(audio, mediaBufs);
1244 if (err != OK) {
1245 for (size_t i = 0; i < mediaBufs.size(); ++i) {
1246 mediaBufs[i]->release();
1247 }
1248 mediaBufs.clear();
1249 ALOGE("Secure source didn't support secure mediaBufs.");
1250 return err;
1251 }
1252 }
Andreas Huberf9334412010-12-15 15:17:42 -08001253 return OK;
1254}
1255
Chong Zhangced1c2f2014-08-08 15:22:35 -07001256void NuPlayer::updateVideoSize(
1257 const sp<AMessage> &inputFormat,
1258 const sp<AMessage> &outputFormat) {
1259 if (inputFormat == NULL) {
1260 ALOGW("Unknown video size, reporting 0x0!");
1261 notifyListener(MEDIA_SET_VIDEO_SIZE, 0, 0);
1262 return;
1263 }
1264
1265 int32_t displayWidth, displayHeight;
1266 int32_t cropLeft, cropTop, cropRight, cropBottom;
1267
1268 if (outputFormat != NULL) {
1269 int32_t width, height;
1270 CHECK(outputFormat->findInt32("width", &width));
1271 CHECK(outputFormat->findInt32("height", &height));
1272
1273 int32_t cropLeft, cropTop, cropRight, cropBottom;
1274 CHECK(outputFormat->findRect(
1275 "crop",
1276 &cropLeft, &cropTop, &cropRight, &cropBottom));
1277
1278 displayWidth = cropRight - cropLeft + 1;
1279 displayHeight = cropBottom - cropTop + 1;
1280
1281 ALOGV("Video output format changed to %d x %d "
1282 "(crop: %d x %d @ (%d, %d))",
1283 width, height,
1284 displayWidth,
1285 displayHeight,
1286 cropLeft, cropTop);
1287 } else {
1288 CHECK(inputFormat->findInt32("width", &displayWidth));
1289 CHECK(inputFormat->findInt32("height", &displayHeight));
1290
1291 ALOGV("Video input format %d x %d", displayWidth, displayHeight);
1292 }
1293
1294 // Take into account sample aspect ratio if necessary:
1295 int32_t sarWidth, sarHeight;
1296 if (inputFormat->findInt32("sar-width", &sarWidth)
1297 && inputFormat->findInt32("sar-height", &sarHeight)) {
1298 ALOGV("Sample aspect ratio %d : %d", sarWidth, sarHeight);
1299
1300 displayWidth = (displayWidth * sarWidth) / sarHeight;
1301
1302 ALOGV("display dimensions %d x %d", displayWidth, displayHeight);
1303 }
1304
1305 int32_t rotationDegrees;
1306 if (!inputFormat->findInt32("rotation-degrees", &rotationDegrees)) {
1307 rotationDegrees = 0;
1308 }
1309
1310 if (rotationDegrees == 90 || rotationDegrees == 270) {
1311 int32_t tmp = displayWidth;
1312 displayWidth = displayHeight;
1313 displayHeight = tmp;
1314 }
1315
1316 notifyListener(
1317 MEDIA_SET_VIDEO_SIZE,
1318 displayWidth,
1319 displayHeight);
1320}
1321
Chong Zhangdcb89b32013-08-06 09:44:47 -07001322void NuPlayer::notifyListener(int msg, int ext1, int ext2, const Parcel *in) {
Andreas Huber43c3e6c2011-01-05 12:17:08 -08001323 if (mDriver == NULL) {
Andreas Huberf9334412010-12-15 15:17:42 -08001324 return;
1325 }
1326
Andreas Huber43c3e6c2011-01-05 12:17:08 -08001327 sp<NuPlayerDriver> driver = mDriver.promote();
Andreas Huberf9334412010-12-15 15:17:42 -08001328
Andreas Huber43c3e6c2011-01-05 12:17:08 -08001329 if (driver == NULL) {
Andreas Huberf9334412010-12-15 15:17:42 -08001330 return;
1331 }
1332
Chong Zhangdcb89b32013-08-06 09:44:47 -07001333 driver->notifyListener(msg, ext1, ext2, in);
Andreas Huberf9334412010-12-15 15:17:42 -08001334}
1335
Chong Zhang7137ec72014-11-12 16:41:05 -08001336void NuPlayer::flushDecoder(bool audio, bool needShutdown) {
Andreas Huber14f76722013-01-15 09:04:18 -08001337 ALOGV("[%s] flushDecoder needShutdown=%d",
1338 audio ? "audio" : "video", needShutdown);
1339
Chong Zhang7137ec72014-11-12 16:41:05 -08001340 const sp<DecoderBase> &decoder = getDecoder(audio);
Lajos Molnar87603c02014-08-20 19:25:30 -07001341 if (decoder == NULL) {
Steve Blockdf64d152012-01-04 20:05:49 +00001342 ALOGI("flushDecoder %s without decoder present",
Andreas Huber6e3d3112011-11-28 12:36:11 -08001343 audio ? "audio" : "video");
Lajos Molnar87603c02014-08-20 19:25:30 -07001344 return;
Andreas Huber6e3d3112011-11-28 12:36:11 -08001345 }
1346
Andreas Huber1aef2112011-01-04 14:01:29 -08001347 // Make sure we don't continue to scan sources until we finish flushing.
1348 ++mScanSourcesGeneration;
Andreas Huber43c3e6c2011-01-05 12:17:08 -08001349 mScanSourcesPending = false;
Andreas Huber1aef2112011-01-04 14:01:29 -08001350
Chong Zhang7137ec72014-11-12 16:41:05 -08001351 decoder->signalFlush();
Andreas Huber1aef2112011-01-04 14:01:29 -08001352
1353 FlushStatus newStatus =
1354 needShutdown ? FLUSHING_DECODER_SHUTDOWN : FLUSHING_DECODER;
1355
Andy Hung8d121d42014-10-03 09:53:53 -07001356 mFlushComplete[audio][false /* isDecoder */] = false;
1357 mFlushComplete[audio][true /* isDecoder */] = false;
Andreas Huber1aef2112011-01-04 14:01:29 -08001358 if (audio) {
Wei Jia53904f32014-07-29 10:22:53 -07001359 ALOGE_IF(mFlushingAudio != NONE,
1360 "audio flushDecoder() is called in state %d", mFlushingAudio);
Andreas Huber1aef2112011-01-04 14:01:29 -08001361 mFlushingAudio = newStatus;
Andreas Huber1aef2112011-01-04 14:01:29 -08001362 } else {
Wei Jia53904f32014-07-29 10:22:53 -07001363 ALOGE_IF(mFlushingVideo != NONE,
1364 "video flushDecoder() is called in state %d", mFlushingVideo);
Andreas Huber1aef2112011-01-04 14:01:29 -08001365 mFlushingVideo = newStatus;
Andreas Huber1aef2112011-01-04 14:01:29 -08001366 }
1367}
1368
Chong Zhangced1c2f2014-08-08 15:22:35 -07001369void NuPlayer::queueDecoderShutdown(
1370 bool audio, bool video, const sp<AMessage> &reply) {
1371 ALOGI("queueDecoderShutdown audio=%d, video=%d", audio, video);
Andreas Huber84066782011-08-16 09:34:26 -07001372
Chong Zhangced1c2f2014-08-08 15:22:35 -07001373 mDeferredActions.push_back(
Wei Jiafef808d2014-10-31 17:57:05 -07001374 new FlushDecoderAction(
1375 audio ? FLUSH_CMD_SHUTDOWN : FLUSH_CMD_NONE,
1376 video ? FLUSH_CMD_SHUTDOWN : FLUSH_CMD_NONE));
Andreas Huber84066782011-08-16 09:34:26 -07001377
Chong Zhangced1c2f2014-08-08 15:22:35 -07001378 mDeferredActions.push_back(
1379 new SimpleAction(&NuPlayer::performScanSources));
Andreas Huber84066782011-08-16 09:34:26 -07001380
Chong Zhangced1c2f2014-08-08 15:22:35 -07001381 mDeferredActions.push_back(new PostMessageAction(reply));
1382
1383 processDeferredActions();
Andreas Huber84066782011-08-16 09:34:26 -07001384}
1385
James Dong0d268a32012-08-31 12:18:27 -07001386status_t NuPlayer::setVideoScalingMode(int32_t mode) {
1387 mVideoScalingMode = mode;
Andreas Huber57a339c2012-12-03 11:18:00 -08001388 if (mNativeWindow != NULL) {
James Dong0d268a32012-08-31 12:18:27 -07001389 status_t ret = native_window_set_scaling_mode(
1390 mNativeWindow->getNativeWindow().get(), mVideoScalingMode);
1391 if (ret != OK) {
1392 ALOGE("Failed to set scaling mode (%d): %s",
1393 -ret, strerror(-ret));
1394 return ret;
1395 }
1396 }
1397 return OK;
1398}
1399
Chong Zhangdcb89b32013-08-06 09:44:47 -07001400status_t NuPlayer::getTrackInfo(Parcel* reply) const {
1401 sp<AMessage> msg = new AMessage(kWhatGetTrackInfo, id());
1402 msg->setPointer("reply", reply);
1403
1404 sp<AMessage> response;
1405 status_t err = msg->postAndAwaitResponse(&response);
1406 return err;
1407}
1408
Robert Shih7c4f0d72014-07-09 18:53:31 -07001409status_t NuPlayer::getSelectedTrack(int32_t type, Parcel* reply) const {
1410 sp<AMessage> msg = new AMessage(kWhatGetSelectedTrack, id());
1411 msg->setPointer("reply", reply);
1412 msg->setInt32("type", type);
1413
1414 sp<AMessage> response;
1415 status_t err = msg->postAndAwaitResponse(&response);
1416 if (err == OK && response != NULL) {
1417 CHECK(response->findInt32("err", &err));
1418 }
1419 return err;
1420}
1421
Robert Shih6ffb1fd2014-10-29 16:24:32 -07001422status_t NuPlayer::selectTrack(size_t trackIndex, bool select, int64_t timeUs) {
Chong Zhangdcb89b32013-08-06 09:44:47 -07001423 sp<AMessage> msg = new AMessage(kWhatSelectTrack, id());
1424 msg->setSize("trackIndex", trackIndex);
1425 msg->setInt32("select", select);
Robert Shih6ffb1fd2014-10-29 16:24:32 -07001426 msg->setInt64("timeUs", timeUs);
Chong Zhangdcb89b32013-08-06 09:44:47 -07001427
1428 sp<AMessage> response;
1429 status_t err = msg->postAndAwaitResponse(&response);
1430
Chong Zhang404fced2014-06-11 14:45:31 -07001431 if (err != OK) {
1432 return err;
1433 }
1434
1435 if (!response->findInt32("err", &err)) {
1436 err = OK;
1437 }
1438
Chong Zhangdcb89b32013-08-06 09:44:47 -07001439 return err;
1440}
1441
Ronghua Wua73d9e02014-10-08 15:13:29 -07001442status_t NuPlayer::getCurrentPosition(int64_t *mediaUs) {
1443 sp<Renderer> renderer = mRenderer;
1444 if (renderer == NULL) {
1445 return NO_INIT;
1446 }
1447
1448 return renderer->getCurrentPosition(mediaUs);
1449}
1450
1451void NuPlayer::getStats(int64_t *numFramesTotal, int64_t *numFramesDropped) {
Chong Zhang7137ec72014-11-12 16:41:05 -08001452 sp<DecoderBase> decoder = getDecoder(false /* audio */);
1453 if (decoder != NULL) {
1454 decoder->getStats(numFramesTotal, numFramesDropped);
1455 } else {
1456 *numFramesTotal = 0;
1457 *numFramesDropped = 0;
1458 }
Ronghua Wua73d9e02014-10-08 15:13:29 -07001459}
1460
Marco Nelissenf0b72b52014-09-16 15:43:44 -07001461sp<MetaData> NuPlayer::getFileMeta() {
1462 return mSource->getFileFormatMeta();
1463}
1464
Andreas Huberb7c8e912012-11-27 15:02:53 -08001465void NuPlayer::schedulePollDuration() {
1466 sp<AMessage> msg = new AMessage(kWhatPollDuration, id());
1467 msg->setInt32("generation", mPollDurationGeneration);
1468 msg->post();
1469}
1470
1471void NuPlayer::cancelPollDuration() {
1472 ++mPollDurationGeneration;
1473}
1474
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001475void NuPlayer::processDeferredActions() {
1476 while (!mDeferredActions.empty()) {
1477 // We won't execute any deferred actions until we're no longer in
1478 // an intermediate state, i.e. one more more decoders are currently
1479 // flushing or shutting down.
1480
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001481 if (mFlushingAudio != NONE || mFlushingVideo != NONE) {
1482 // We're currently flushing, postpone the reset until that's
1483 // completed.
1484
1485 ALOGV("postponing action mFlushingAudio=%d, mFlushingVideo=%d",
1486 mFlushingAudio, mFlushingVideo);
1487
1488 break;
1489 }
1490
1491 sp<Action> action = *mDeferredActions.begin();
1492 mDeferredActions.erase(mDeferredActions.begin());
1493
1494 action->execute(this);
1495 }
1496}
1497
Wei Jiae427abf2014-09-22 15:21:11 -07001498void NuPlayer::performSeek(int64_t seekTimeUs, bool needNotify) {
1499 ALOGV("performSeek seekTimeUs=%lld us (%.2f secs), needNotify(%d)",
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001500 seekTimeUs,
Wei Jiae427abf2014-09-22 15:21:11 -07001501 seekTimeUs / 1E6,
1502 needNotify);
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001503
Andy Hungadf34bf2014-09-03 18:22:22 -07001504 if (mSource == NULL) {
1505 // This happens when reset occurs right before the loop mode
1506 // asynchronously seeks to the start of the stream.
1507 LOG_ALWAYS_FATAL_IF(mAudioDecoder != NULL || mVideoDecoder != NULL,
1508 "mSource is NULL and decoders not NULL audio(%p) video(%p)",
1509 mAudioDecoder.get(), mVideoDecoder.get());
1510 return;
1511 }
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001512 mSource->seekTo(seekTimeUs);
Robert Shihd3b0bbb2014-07-23 15:00:25 -07001513 ++mTimedTextGeneration;
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001514
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001515 // everything's flushed, continue playback.
1516}
1517
Wei Jiafef808d2014-10-31 17:57:05 -07001518void NuPlayer::performDecoderFlush(FlushCommand audio, FlushCommand video) {
1519 ALOGV("performDecoderFlush audio=%d, video=%d", audio, video);
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001520
Wei Jiafef808d2014-10-31 17:57:05 -07001521 if ((audio == FLUSH_CMD_NONE || mAudioDecoder == NULL)
1522 && (video == FLUSH_CMD_NONE || mVideoDecoder == NULL)) {
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001523 return;
1524 }
1525
Wei Jiafef808d2014-10-31 17:57:05 -07001526 if (audio != FLUSH_CMD_NONE && mAudioDecoder != NULL) {
1527 flushDecoder(true /* audio */, (audio == FLUSH_CMD_SHUTDOWN));
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001528 }
1529
Wei Jiafef808d2014-10-31 17:57:05 -07001530 if (video != FLUSH_CMD_NONE && mVideoDecoder != NULL) {
1531 flushDecoder(false /* audio */, (video == FLUSH_CMD_SHUTDOWN));
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001532 }
1533}
1534
1535void NuPlayer::performReset() {
1536 ALOGV("performReset");
1537
1538 CHECK(mAudioDecoder == NULL);
1539 CHECK(mVideoDecoder == NULL);
1540
1541 cancelPollDuration();
1542
1543 ++mScanSourcesGeneration;
1544 mScanSourcesPending = false;
1545
Lajos Molnar09524832014-07-17 14:29:51 -07001546 if (mRendererLooper != NULL) {
1547 if (mRenderer != NULL) {
1548 mRendererLooper->unregisterHandler(mRenderer->id());
1549 }
1550 mRendererLooper->stop();
1551 mRendererLooper.clear();
1552 }
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001553 mRenderer.clear();
Wei Jia57568df2014-09-22 10:16:29 -07001554 ++mRendererGeneration;
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001555
1556 if (mSource != NULL) {
1557 mSource->stop();
Andreas Huberb5f25f02013-02-05 10:14:26 -08001558
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001559 mSource.clear();
1560 }
1561
1562 if (mDriver != NULL) {
1563 sp<NuPlayerDriver> driver = mDriver.promote();
1564 if (driver != NULL) {
1565 driver->notifyResetComplete();
1566 }
1567 }
Andreas Huber57a339c2012-12-03 11:18:00 -08001568
1569 mStarted = false;
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001570}
1571
1572void NuPlayer::performScanSources() {
1573 ALOGV("performScanSources");
1574
Andreas Huber57a339c2012-12-03 11:18:00 -08001575 if (!mStarted) {
1576 return;
1577 }
1578
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001579 if (mAudioDecoder == NULL || mVideoDecoder == NULL) {
1580 postScanSources();
1581 }
1582}
1583
Andreas Huber57a339c2012-12-03 11:18:00 -08001584void NuPlayer::performSetSurface(const sp<NativeWindowWrapper> &wrapper) {
1585 ALOGV("performSetSurface");
1586
1587 mNativeWindow = wrapper;
1588
1589 // XXX - ignore error from setVideoScalingMode for now
1590 setVideoScalingMode(mVideoScalingMode);
Chong Zhang13d6faa2014-08-22 15:35:28 -07001591
1592 if (mDriver != NULL) {
1593 sp<NuPlayerDriver> driver = mDriver.promote();
1594 if (driver != NULL) {
1595 driver->notifySetSurfaceComplete();
1596 }
1597 }
Andreas Huber57a339c2012-12-03 11:18:00 -08001598}
1599
Chong Zhangf8d71772014-11-26 15:08:34 -08001600void NuPlayer::performResumeDecoders(bool needNotify) {
1601 if (needNotify) {
1602 mResumePending = true;
1603 if (mVideoDecoder == NULL) {
1604 // if audio-only, we can notify seek complete now,
1605 // as the resume operation will be relatively fast.
1606 finishResume();
1607 }
1608 }
1609
Chong Zhang7137ec72014-11-12 16:41:05 -08001610 if (mVideoDecoder != NULL) {
Chong Zhangf8d71772014-11-26 15:08:34 -08001611 // When there is continuous seek, MediaPlayer will cache the seek
1612 // position, and send down new seek request when previous seek is
1613 // complete. Let's wait for at least one video output frame before
1614 // notifying seek complete, so that the video thumbnail gets updated
1615 // when seekbar is dragged.
1616 mVideoDecoder->signalResume(needNotify);
Chong Zhang7137ec72014-11-12 16:41:05 -08001617 }
1618
1619 if (mAudioDecoder != NULL) {
Chong Zhangf8d71772014-11-26 15:08:34 -08001620 mAudioDecoder->signalResume(false /* needNotify */);
1621 }
1622}
1623
1624void NuPlayer::finishResume() {
1625 if (mResumePending) {
1626 mResumePending = false;
1627 if (mDriver != NULL) {
1628 sp<NuPlayerDriver> driver = mDriver.promote();
1629 if (driver != NULL) {
1630 driver->notifySeekComplete();
1631 }
1632 }
Chong Zhang7137ec72014-11-12 16:41:05 -08001633 }
1634}
1635
Andreas Huber9575c962013-02-05 13:59:56 -08001636void NuPlayer::onSourceNotify(const sp<AMessage> &msg) {
1637 int32_t what;
1638 CHECK(msg->findInt32("what", &what));
1639
1640 switch (what) {
1641 case Source::kWhatPrepared:
1642 {
Andreas Huberb5f28d42013-04-25 15:11:19 -07001643 if (mSource == NULL) {
1644 // This is a stale notification from a source that was
1645 // asynchronously preparing when the client called reset().
1646 // We handled the reset, the source is gone.
1647 break;
1648 }
1649
Andreas Huberec0c5972013-02-05 14:47:13 -08001650 int32_t err;
1651 CHECK(msg->findInt32("err", &err));
1652
Andreas Huber9575c962013-02-05 13:59:56 -08001653 sp<NuPlayerDriver> driver = mDriver.promote();
1654 if (driver != NULL) {
Marco Nelissendd114d12014-05-28 15:23:14 -07001655 // notify duration first, so that it's definitely set when
1656 // the app received the "prepare complete" callback.
1657 int64_t durationUs;
1658 if (mSource->getDuration(&durationUs) == OK) {
1659 driver->notifyDuration(durationUs);
1660 }
Andreas Huberec0c5972013-02-05 14:47:13 -08001661 driver->notifyPrepareCompleted(err);
Andreas Huber9575c962013-02-05 13:59:56 -08001662 }
Andreas Huber99759402013-04-01 14:28:31 -07001663
Andreas Huber9575c962013-02-05 13:59:56 -08001664 break;
1665 }
1666
1667 case Source::kWhatFlagsChanged:
1668 {
1669 uint32_t flags;
1670 CHECK(msg->findInt32("flags", (int32_t *)&flags));
1671
Chong Zhang4b7069d2013-09-11 12:52:43 -07001672 sp<NuPlayerDriver> driver = mDriver.promote();
1673 if (driver != NULL) {
Wei Jia895651b2014-12-10 17:31:52 -08001674 if ((flags & NuPlayer::Source::FLAG_CAN_SEEK) == 0) {
1675 driver->notifyListener(
1676 MEDIA_INFO, MEDIA_INFO_NOT_SEEKABLE, 0);
1677 }
Chong Zhang4b7069d2013-09-11 12:52:43 -07001678 driver->notifyFlagsChanged(flags);
1679 }
1680
Andreas Huber9575c962013-02-05 13:59:56 -08001681 if ((mSourceFlags & Source::FLAG_DYNAMIC_DURATION)
1682 && (!(flags & Source::FLAG_DYNAMIC_DURATION))) {
1683 cancelPollDuration();
1684 } else if (!(mSourceFlags & Source::FLAG_DYNAMIC_DURATION)
1685 && (flags & Source::FLAG_DYNAMIC_DURATION)
1686 && (mAudioDecoder != NULL || mVideoDecoder != NULL)) {
1687 schedulePollDuration();
1688 }
1689
1690 mSourceFlags = flags;
1691 break;
1692 }
1693
1694 case Source::kWhatVideoSizeChanged:
1695 {
Chong Zhangced1c2f2014-08-08 15:22:35 -07001696 sp<AMessage> format;
1697 CHECK(msg->findMessage("format", &format));
Andreas Huber9575c962013-02-05 13:59:56 -08001698
Chong Zhangced1c2f2014-08-08 15:22:35 -07001699 updateVideoSize(format);
Andreas Huber9575c962013-02-05 13:59:56 -08001700 break;
1701 }
1702
Chong Zhang2a3cc9a2014-08-21 17:48:26 -07001703 case Source::kWhatBufferingUpdate:
1704 {
1705 int32_t percentage;
1706 CHECK(msg->findInt32("percentage", &percentage));
1707
1708 notifyListener(MEDIA_BUFFERING_UPDATE, percentage, 0);
1709 break;
1710 }
1711
Roger Jönssonb50e83e2013-01-21 16:26:41 +01001712 case Source::kWhatBufferingStart:
1713 {
1714 notifyListener(MEDIA_INFO, MEDIA_INFO_BUFFERING_START, 0);
1715 break;
1716 }
1717
1718 case Source::kWhatBufferingEnd:
1719 {
1720 notifyListener(MEDIA_INFO, MEDIA_INFO_BUFFERING_END, 0);
1721 break;
1722 }
1723
Chong Zhangdcb89b32013-08-06 09:44:47 -07001724 case Source::kWhatSubtitleData:
1725 {
1726 sp<ABuffer> buffer;
1727 CHECK(msg->findBuffer("buffer", &buffer));
1728
Chong Zhang404fced2014-06-11 14:45:31 -07001729 sendSubtitleData(buffer, 0 /* baseIndex */);
Chong Zhangdcb89b32013-08-06 09:44:47 -07001730 break;
1731 }
1732
Robert Shihd3b0bbb2014-07-23 15:00:25 -07001733 case Source::kWhatTimedTextData:
1734 {
1735 int32_t generation;
1736 if (msg->findInt32("generation", &generation)
1737 && generation != mTimedTextGeneration) {
1738 break;
1739 }
1740
1741 sp<ABuffer> buffer;
1742 CHECK(msg->findBuffer("buffer", &buffer));
1743
1744 sp<NuPlayerDriver> driver = mDriver.promote();
1745 if (driver == NULL) {
1746 break;
1747 }
1748
1749 int posMs;
1750 int64_t timeUs, posUs;
1751 driver->getCurrentPosition(&posMs);
1752 posUs = posMs * 1000;
1753 CHECK(buffer->meta()->findInt64("timeUs", &timeUs));
1754
1755 if (posUs < timeUs) {
1756 if (!msg->findInt32("generation", &generation)) {
1757 msg->setInt32("generation", mTimedTextGeneration);
1758 }
1759 msg->post(timeUs - posUs);
1760 } else {
1761 sendTimedTextData(buffer);
1762 }
1763 break;
1764 }
1765
Andreas Huber14f76722013-01-15 09:04:18 -08001766 case Source::kWhatQueueDecoderShutdown:
1767 {
1768 int32_t audio, video;
1769 CHECK(msg->findInt32("audio", &audio));
1770 CHECK(msg->findInt32("video", &video));
1771
1772 sp<AMessage> reply;
1773 CHECK(msg->findMessage("reply", &reply));
1774
1775 queueDecoderShutdown(audio, video, reply);
1776 break;
1777 }
1778
Ronghua Wu80276872014-08-28 15:50:29 -07001779 case Source::kWhatDrmNoLicense:
1780 {
1781 notifyListener(MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, ERROR_DRM_NO_LICENSE);
1782 break;
1783 }
1784
Andreas Huber9575c962013-02-05 13:59:56 -08001785 default:
1786 TRESPASS();
1787 }
1788}
1789
Chong Zhanga7fa1d92014-06-11 14:49:23 -07001790void NuPlayer::onClosedCaptionNotify(const sp<AMessage> &msg) {
1791 int32_t what;
1792 CHECK(msg->findInt32("what", &what));
1793
1794 switch (what) {
1795 case NuPlayer::CCDecoder::kWhatClosedCaptionData:
1796 {
1797 sp<ABuffer> buffer;
1798 CHECK(msg->findBuffer("buffer", &buffer));
1799
1800 size_t inbandTracks = 0;
1801 if (mSource != NULL) {
1802 inbandTracks = mSource->getTrackCount();
1803 }
1804
1805 sendSubtitleData(buffer, inbandTracks);
1806 break;
1807 }
1808
1809 case NuPlayer::CCDecoder::kWhatTrackAdded:
1810 {
1811 notifyListener(MEDIA_INFO, MEDIA_INFO_METADATA_UPDATE, 0);
1812
1813 break;
1814 }
1815
1816 default:
1817 TRESPASS();
1818 }
1819
1820
1821}
1822
Chong Zhang404fced2014-06-11 14:45:31 -07001823void NuPlayer::sendSubtitleData(const sp<ABuffer> &buffer, int32_t baseIndex) {
1824 int32_t trackIndex;
1825 int64_t timeUs, durationUs;
1826 CHECK(buffer->meta()->findInt32("trackIndex", &trackIndex));
1827 CHECK(buffer->meta()->findInt64("timeUs", &timeUs));
1828 CHECK(buffer->meta()->findInt64("durationUs", &durationUs));
1829
1830 Parcel in;
1831 in.writeInt32(trackIndex + baseIndex);
1832 in.writeInt64(timeUs);
1833 in.writeInt64(durationUs);
1834 in.writeInt32(buffer->size());
1835 in.writeInt32(buffer->size());
1836 in.write(buffer->data(), buffer->size());
1837
1838 notifyListener(MEDIA_SUBTITLE_DATA, 0, 0, &in);
1839}
Robert Shihd3b0bbb2014-07-23 15:00:25 -07001840
1841void NuPlayer::sendTimedTextData(const sp<ABuffer> &buffer) {
1842 const void *data;
1843 size_t size = 0;
1844 int64_t timeUs;
1845 int32_t flag = TextDescriptions::LOCAL_DESCRIPTIONS;
1846
1847 AString mime;
1848 CHECK(buffer->meta()->findString("mime", &mime));
1849 CHECK(strcasecmp(mime.c_str(), MEDIA_MIMETYPE_TEXT_3GPP) == 0);
1850
1851 data = buffer->data();
1852 size = buffer->size();
1853
1854 Parcel parcel;
1855 if (size > 0) {
1856 CHECK(buffer->meta()->findInt64("timeUs", &timeUs));
1857 flag |= TextDescriptions::IN_BAND_TEXT_3GPP;
1858 TextDescriptions::getParcelOfDescriptions(
1859 (const uint8_t *)data, size, flag, timeUs / 1000, &parcel);
1860 }
1861
1862 if ((parcel.dataSize() > 0)) {
1863 notifyListener(MEDIA_TIMED_TEXT, 0, 0, &parcel);
1864 } else { // send an empty timed text
1865 notifyListener(MEDIA_TIMED_TEXT, 0, 0);
1866 }
1867}
Andreas Huberb5f25f02013-02-05 10:14:26 -08001868////////////////////////////////////////////////////////////////////////////////
1869
Chong Zhangced1c2f2014-08-08 15:22:35 -07001870sp<AMessage> NuPlayer::Source::getFormat(bool audio) {
1871 sp<MetaData> meta = getFormatMeta(audio);
1872
1873 if (meta == NULL) {
1874 return NULL;
1875 }
1876
1877 sp<AMessage> msg = new AMessage;
1878
1879 if(convertMetaDataToMessage(meta, &msg) == OK) {
1880 return msg;
1881 }
1882 return NULL;
1883}
1884
Andreas Huber9575c962013-02-05 13:59:56 -08001885void NuPlayer::Source::notifyFlagsChanged(uint32_t flags) {
1886 sp<AMessage> notify = dupNotify();
1887 notify->setInt32("what", kWhatFlagsChanged);
1888 notify->setInt32("flags", flags);
1889 notify->post();
1890}
1891
Chong Zhangced1c2f2014-08-08 15:22:35 -07001892void NuPlayer::Source::notifyVideoSizeChanged(const sp<AMessage> &format) {
Andreas Huber9575c962013-02-05 13:59:56 -08001893 sp<AMessage> notify = dupNotify();
1894 notify->setInt32("what", kWhatVideoSizeChanged);
Chong Zhangced1c2f2014-08-08 15:22:35 -07001895 notify->setMessage("format", format);
Andreas Huber9575c962013-02-05 13:59:56 -08001896 notify->post();
1897}
1898
Andreas Huberec0c5972013-02-05 14:47:13 -08001899void NuPlayer::Source::notifyPrepared(status_t err) {
Andreas Huber9575c962013-02-05 13:59:56 -08001900 sp<AMessage> notify = dupNotify();
1901 notify->setInt32("what", kWhatPrepared);
Andreas Huberec0c5972013-02-05 14:47:13 -08001902 notify->setInt32("err", err);
Andreas Huber9575c962013-02-05 13:59:56 -08001903 notify->post();
1904}
1905
Andreas Huber84333e02014-02-07 15:36:10 -08001906void NuPlayer::Source::onMessageReceived(const sp<AMessage> & /* msg */) {
Andreas Huberb5f25f02013-02-05 10:14:26 -08001907 TRESPASS();
1908}
1909
Andreas Huberf9334412010-12-15 15:17:42 -08001910} // namespace android