blob: 3b472a24cf984598fa3c7ecbcb84940bc0c52b53 [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());
Chong Zhang341ab6e2015-02-04 13:37:18 -08001188 if (mCCDecoder == NULL) {
1189 mCCDecoder = new CCDecoder(ccNotify);
1190 }
Lajos Molnar09524832014-07-17 14:29:51 -07001191
1192 if (mSourceFlags & Source::FLAG_SECURE) {
1193 format->setInt32("secure", true);
1194 }
Chong Zhang17134602015-01-07 16:14:34 -08001195
1196 if (mSourceFlags & Source::FLAG_PROTECTED) {
1197 format->setInt32("protected", true);
1198 }
Andreas Huber3fe62152011-09-16 15:09:22 -07001199 }
1200
Wei Jiabc2fb722014-07-08 16:37:57 -07001201 if (audio) {
Wei Jia88703c32014-08-06 11:24:07 -07001202 sp<AMessage> notify = new AMessage(kWhatAudioNotify, id());
1203 ++mAudioDecoderGeneration;
1204 notify->setInt32("generation", mAudioDecoderGeneration);
1205
Wei Jiabc2fb722014-07-08 16:37:57 -07001206 if (mOffloadAudio) {
Wei Jiac6cfd702014-11-11 16:33:20 -08001207 *decoder = new DecoderPassThrough(notify, mSource, mRenderer);
Wei Jiabc2fb722014-07-08 16:37:57 -07001208 } else {
Wei Jiac6cfd702014-11-11 16:33:20 -08001209 *decoder = new Decoder(notify, mSource, mRenderer);
Wei Jiabc2fb722014-07-08 16:37:57 -07001210 }
1211 } else {
Wei Jia88703c32014-08-06 11:24:07 -07001212 sp<AMessage> notify = new AMessage(kWhatVideoNotify, id());
1213 ++mVideoDecoderGeneration;
1214 notify->setInt32("generation", mVideoDecoderGeneration);
1215
Chong Zhang7137ec72014-11-12 16:41:05 -08001216 *decoder = new Decoder(
1217 notify, mSource, mRenderer, mNativeWindow, mCCDecoder);
Lajos Molnard9fd6312014-11-06 11:00:00 -08001218
1219 // enable FRC if high-quality AV sync is requested, even if not
1220 // queuing to native window, as this will even improve textureview
1221 // playback.
1222 {
1223 char value[PROPERTY_VALUE_MAX];
1224 if (property_get("persist.sys.media.avsync", value, NULL) &&
1225 (!strcmp("1", value) || !strcasecmp("true", value))) {
1226 format->setInt32("auto-frc", 1);
1227 }
1228 }
Wei Jiabc2fb722014-07-08 16:37:57 -07001229 }
Lajos Molnar1cd13982014-01-17 15:12:51 -08001230 (*decoder)->init();
Andreas Huber84066782011-08-16 09:34:26 -07001231 (*decoder)->configure(format);
Andreas Huberf9334412010-12-15 15:17:42 -08001232
Lajos Molnar09524832014-07-17 14:29:51 -07001233 // allocate buffers to decrypt widevine source buffers
1234 if (!audio && (mSourceFlags & Source::FLAG_SECURE)) {
1235 Vector<sp<ABuffer> > inputBufs;
1236 CHECK_EQ((*decoder)->getInputBuffers(&inputBufs), (status_t)OK);
1237
1238 Vector<MediaBuffer *> mediaBufs;
1239 for (size_t i = 0; i < inputBufs.size(); i++) {
1240 const sp<ABuffer> &buffer = inputBufs[i];
1241 MediaBuffer *mbuf = new MediaBuffer(buffer->data(), buffer->size());
1242 mediaBufs.push(mbuf);
1243 }
1244
1245 status_t err = mSource->setBuffers(audio, mediaBufs);
1246 if (err != OK) {
1247 for (size_t i = 0; i < mediaBufs.size(); ++i) {
1248 mediaBufs[i]->release();
1249 }
1250 mediaBufs.clear();
1251 ALOGE("Secure source didn't support secure mediaBufs.");
1252 return err;
1253 }
1254 }
Andreas Huberf9334412010-12-15 15:17:42 -08001255 return OK;
1256}
1257
Chong Zhangced1c2f2014-08-08 15:22:35 -07001258void NuPlayer::updateVideoSize(
1259 const sp<AMessage> &inputFormat,
1260 const sp<AMessage> &outputFormat) {
1261 if (inputFormat == NULL) {
1262 ALOGW("Unknown video size, reporting 0x0!");
1263 notifyListener(MEDIA_SET_VIDEO_SIZE, 0, 0);
1264 return;
1265 }
1266
1267 int32_t displayWidth, displayHeight;
1268 int32_t cropLeft, cropTop, cropRight, cropBottom;
1269
1270 if (outputFormat != NULL) {
1271 int32_t width, height;
1272 CHECK(outputFormat->findInt32("width", &width));
1273 CHECK(outputFormat->findInt32("height", &height));
1274
1275 int32_t cropLeft, cropTop, cropRight, cropBottom;
1276 CHECK(outputFormat->findRect(
1277 "crop",
1278 &cropLeft, &cropTop, &cropRight, &cropBottom));
1279
1280 displayWidth = cropRight - cropLeft + 1;
1281 displayHeight = cropBottom - cropTop + 1;
1282
1283 ALOGV("Video output format changed to %d x %d "
1284 "(crop: %d x %d @ (%d, %d))",
1285 width, height,
1286 displayWidth,
1287 displayHeight,
1288 cropLeft, cropTop);
1289 } else {
1290 CHECK(inputFormat->findInt32("width", &displayWidth));
1291 CHECK(inputFormat->findInt32("height", &displayHeight));
1292
1293 ALOGV("Video input format %d x %d", displayWidth, displayHeight);
1294 }
1295
1296 // Take into account sample aspect ratio if necessary:
1297 int32_t sarWidth, sarHeight;
1298 if (inputFormat->findInt32("sar-width", &sarWidth)
1299 && inputFormat->findInt32("sar-height", &sarHeight)) {
1300 ALOGV("Sample aspect ratio %d : %d", sarWidth, sarHeight);
1301
1302 displayWidth = (displayWidth * sarWidth) / sarHeight;
1303
1304 ALOGV("display dimensions %d x %d", displayWidth, displayHeight);
1305 }
1306
1307 int32_t rotationDegrees;
1308 if (!inputFormat->findInt32("rotation-degrees", &rotationDegrees)) {
1309 rotationDegrees = 0;
1310 }
1311
1312 if (rotationDegrees == 90 || rotationDegrees == 270) {
1313 int32_t tmp = displayWidth;
1314 displayWidth = displayHeight;
1315 displayHeight = tmp;
1316 }
1317
1318 notifyListener(
1319 MEDIA_SET_VIDEO_SIZE,
1320 displayWidth,
1321 displayHeight);
1322}
1323
Chong Zhangdcb89b32013-08-06 09:44:47 -07001324void NuPlayer::notifyListener(int msg, int ext1, int ext2, const Parcel *in) {
Andreas Huber43c3e6c2011-01-05 12:17:08 -08001325 if (mDriver == NULL) {
Andreas Huberf9334412010-12-15 15:17:42 -08001326 return;
1327 }
1328
Andreas Huber43c3e6c2011-01-05 12:17:08 -08001329 sp<NuPlayerDriver> driver = mDriver.promote();
Andreas Huberf9334412010-12-15 15:17:42 -08001330
Andreas Huber43c3e6c2011-01-05 12:17:08 -08001331 if (driver == NULL) {
Andreas Huberf9334412010-12-15 15:17:42 -08001332 return;
1333 }
1334
Chong Zhangdcb89b32013-08-06 09:44:47 -07001335 driver->notifyListener(msg, ext1, ext2, in);
Andreas Huberf9334412010-12-15 15:17:42 -08001336}
1337
Chong Zhang7137ec72014-11-12 16:41:05 -08001338void NuPlayer::flushDecoder(bool audio, bool needShutdown) {
Andreas Huber14f76722013-01-15 09:04:18 -08001339 ALOGV("[%s] flushDecoder needShutdown=%d",
1340 audio ? "audio" : "video", needShutdown);
1341
Chong Zhang7137ec72014-11-12 16:41:05 -08001342 const sp<DecoderBase> &decoder = getDecoder(audio);
Lajos Molnar87603c02014-08-20 19:25:30 -07001343 if (decoder == NULL) {
Steve Blockdf64d152012-01-04 20:05:49 +00001344 ALOGI("flushDecoder %s without decoder present",
Andreas Huber6e3d3112011-11-28 12:36:11 -08001345 audio ? "audio" : "video");
Lajos Molnar87603c02014-08-20 19:25:30 -07001346 return;
Andreas Huber6e3d3112011-11-28 12:36:11 -08001347 }
1348
Andreas Huber1aef2112011-01-04 14:01:29 -08001349 // Make sure we don't continue to scan sources until we finish flushing.
1350 ++mScanSourcesGeneration;
Andreas Huber43c3e6c2011-01-05 12:17:08 -08001351 mScanSourcesPending = false;
Andreas Huber1aef2112011-01-04 14:01:29 -08001352
Chong Zhang7137ec72014-11-12 16:41:05 -08001353 decoder->signalFlush();
Andreas Huber1aef2112011-01-04 14:01:29 -08001354
1355 FlushStatus newStatus =
1356 needShutdown ? FLUSHING_DECODER_SHUTDOWN : FLUSHING_DECODER;
1357
Andy Hung8d121d42014-10-03 09:53:53 -07001358 mFlushComplete[audio][false /* isDecoder */] = false;
1359 mFlushComplete[audio][true /* isDecoder */] = false;
Andreas Huber1aef2112011-01-04 14:01:29 -08001360 if (audio) {
Wei Jia53904f32014-07-29 10:22:53 -07001361 ALOGE_IF(mFlushingAudio != NONE,
1362 "audio flushDecoder() is called in state %d", mFlushingAudio);
Andreas Huber1aef2112011-01-04 14:01:29 -08001363 mFlushingAudio = newStatus;
Andreas Huber1aef2112011-01-04 14:01:29 -08001364 } else {
Wei Jia53904f32014-07-29 10:22:53 -07001365 ALOGE_IF(mFlushingVideo != NONE,
1366 "video flushDecoder() is called in state %d", mFlushingVideo);
Andreas Huber1aef2112011-01-04 14:01:29 -08001367 mFlushingVideo = newStatus;
Andreas Huber1aef2112011-01-04 14:01:29 -08001368 }
1369}
1370
Chong Zhangced1c2f2014-08-08 15:22:35 -07001371void NuPlayer::queueDecoderShutdown(
1372 bool audio, bool video, const sp<AMessage> &reply) {
1373 ALOGI("queueDecoderShutdown audio=%d, video=%d", audio, video);
Andreas Huber84066782011-08-16 09:34:26 -07001374
Chong Zhangced1c2f2014-08-08 15:22:35 -07001375 mDeferredActions.push_back(
Wei Jiafef808d2014-10-31 17:57:05 -07001376 new FlushDecoderAction(
1377 audio ? FLUSH_CMD_SHUTDOWN : FLUSH_CMD_NONE,
1378 video ? FLUSH_CMD_SHUTDOWN : FLUSH_CMD_NONE));
Andreas Huber84066782011-08-16 09:34:26 -07001379
Chong Zhangced1c2f2014-08-08 15:22:35 -07001380 mDeferredActions.push_back(
1381 new SimpleAction(&NuPlayer::performScanSources));
Andreas Huber84066782011-08-16 09:34:26 -07001382
Chong Zhangced1c2f2014-08-08 15:22:35 -07001383 mDeferredActions.push_back(new PostMessageAction(reply));
1384
1385 processDeferredActions();
Andreas Huber84066782011-08-16 09:34:26 -07001386}
1387
James Dong0d268a32012-08-31 12:18:27 -07001388status_t NuPlayer::setVideoScalingMode(int32_t mode) {
1389 mVideoScalingMode = mode;
Andreas Huber57a339c2012-12-03 11:18:00 -08001390 if (mNativeWindow != NULL) {
James Dong0d268a32012-08-31 12:18:27 -07001391 status_t ret = native_window_set_scaling_mode(
1392 mNativeWindow->getNativeWindow().get(), mVideoScalingMode);
1393 if (ret != OK) {
1394 ALOGE("Failed to set scaling mode (%d): %s",
1395 -ret, strerror(-ret));
1396 return ret;
1397 }
1398 }
1399 return OK;
1400}
1401
Chong Zhangdcb89b32013-08-06 09:44:47 -07001402status_t NuPlayer::getTrackInfo(Parcel* reply) const {
1403 sp<AMessage> msg = new AMessage(kWhatGetTrackInfo, id());
1404 msg->setPointer("reply", reply);
1405
1406 sp<AMessage> response;
1407 status_t err = msg->postAndAwaitResponse(&response);
1408 return err;
1409}
1410
Robert Shih7c4f0d72014-07-09 18:53:31 -07001411status_t NuPlayer::getSelectedTrack(int32_t type, Parcel* reply) const {
1412 sp<AMessage> msg = new AMessage(kWhatGetSelectedTrack, id());
1413 msg->setPointer("reply", reply);
1414 msg->setInt32("type", type);
1415
1416 sp<AMessage> response;
1417 status_t err = msg->postAndAwaitResponse(&response);
1418 if (err == OK && response != NULL) {
1419 CHECK(response->findInt32("err", &err));
1420 }
1421 return err;
1422}
1423
Robert Shih6ffb1fd2014-10-29 16:24:32 -07001424status_t NuPlayer::selectTrack(size_t trackIndex, bool select, int64_t timeUs) {
Chong Zhangdcb89b32013-08-06 09:44:47 -07001425 sp<AMessage> msg = new AMessage(kWhatSelectTrack, id());
1426 msg->setSize("trackIndex", trackIndex);
1427 msg->setInt32("select", select);
Robert Shih6ffb1fd2014-10-29 16:24:32 -07001428 msg->setInt64("timeUs", timeUs);
Chong Zhangdcb89b32013-08-06 09:44:47 -07001429
1430 sp<AMessage> response;
1431 status_t err = msg->postAndAwaitResponse(&response);
1432
Chong Zhang404fced2014-06-11 14:45:31 -07001433 if (err != OK) {
1434 return err;
1435 }
1436
1437 if (!response->findInt32("err", &err)) {
1438 err = OK;
1439 }
1440
Chong Zhangdcb89b32013-08-06 09:44:47 -07001441 return err;
1442}
1443
Ronghua Wua73d9e02014-10-08 15:13:29 -07001444status_t NuPlayer::getCurrentPosition(int64_t *mediaUs) {
1445 sp<Renderer> renderer = mRenderer;
1446 if (renderer == NULL) {
1447 return NO_INIT;
1448 }
1449
1450 return renderer->getCurrentPosition(mediaUs);
1451}
1452
1453void NuPlayer::getStats(int64_t *numFramesTotal, int64_t *numFramesDropped) {
Chong Zhang7137ec72014-11-12 16:41:05 -08001454 sp<DecoderBase> decoder = getDecoder(false /* audio */);
1455 if (decoder != NULL) {
1456 decoder->getStats(numFramesTotal, numFramesDropped);
1457 } else {
1458 *numFramesTotal = 0;
1459 *numFramesDropped = 0;
1460 }
Ronghua Wua73d9e02014-10-08 15:13:29 -07001461}
1462
Marco Nelissenf0b72b52014-09-16 15:43:44 -07001463sp<MetaData> NuPlayer::getFileMeta() {
1464 return mSource->getFileFormatMeta();
1465}
1466
Andreas Huberb7c8e912012-11-27 15:02:53 -08001467void NuPlayer::schedulePollDuration() {
1468 sp<AMessage> msg = new AMessage(kWhatPollDuration, id());
1469 msg->setInt32("generation", mPollDurationGeneration);
1470 msg->post();
1471}
1472
1473void NuPlayer::cancelPollDuration() {
1474 ++mPollDurationGeneration;
1475}
1476
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001477void NuPlayer::processDeferredActions() {
1478 while (!mDeferredActions.empty()) {
1479 // We won't execute any deferred actions until we're no longer in
1480 // an intermediate state, i.e. one more more decoders are currently
1481 // flushing or shutting down.
1482
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001483 if (mFlushingAudio != NONE || mFlushingVideo != NONE) {
1484 // We're currently flushing, postpone the reset until that's
1485 // completed.
1486
1487 ALOGV("postponing action mFlushingAudio=%d, mFlushingVideo=%d",
1488 mFlushingAudio, mFlushingVideo);
1489
1490 break;
1491 }
1492
1493 sp<Action> action = *mDeferredActions.begin();
1494 mDeferredActions.erase(mDeferredActions.begin());
1495
1496 action->execute(this);
1497 }
1498}
1499
Wei Jiae427abf2014-09-22 15:21:11 -07001500void NuPlayer::performSeek(int64_t seekTimeUs, bool needNotify) {
1501 ALOGV("performSeek seekTimeUs=%lld us (%.2f secs), needNotify(%d)",
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001502 seekTimeUs,
Wei Jiae427abf2014-09-22 15:21:11 -07001503 seekTimeUs / 1E6,
1504 needNotify);
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001505
Andy Hungadf34bf2014-09-03 18:22:22 -07001506 if (mSource == NULL) {
1507 // This happens when reset occurs right before the loop mode
1508 // asynchronously seeks to the start of the stream.
1509 LOG_ALWAYS_FATAL_IF(mAudioDecoder != NULL || mVideoDecoder != NULL,
1510 "mSource is NULL and decoders not NULL audio(%p) video(%p)",
1511 mAudioDecoder.get(), mVideoDecoder.get());
1512 return;
1513 }
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001514 mSource->seekTo(seekTimeUs);
Robert Shihd3b0bbb2014-07-23 15:00:25 -07001515 ++mTimedTextGeneration;
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001516
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001517 // everything's flushed, continue playback.
1518}
1519
Wei Jiafef808d2014-10-31 17:57:05 -07001520void NuPlayer::performDecoderFlush(FlushCommand audio, FlushCommand video) {
1521 ALOGV("performDecoderFlush audio=%d, video=%d", audio, video);
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001522
Wei Jiafef808d2014-10-31 17:57:05 -07001523 if ((audio == FLUSH_CMD_NONE || mAudioDecoder == NULL)
1524 && (video == FLUSH_CMD_NONE || mVideoDecoder == NULL)) {
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001525 return;
1526 }
1527
Wei Jiafef808d2014-10-31 17:57:05 -07001528 if (audio != FLUSH_CMD_NONE && mAudioDecoder != NULL) {
1529 flushDecoder(true /* audio */, (audio == FLUSH_CMD_SHUTDOWN));
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001530 }
1531
Wei Jiafef808d2014-10-31 17:57:05 -07001532 if (video != FLUSH_CMD_NONE && mVideoDecoder != NULL) {
1533 flushDecoder(false /* audio */, (video == FLUSH_CMD_SHUTDOWN));
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001534 }
1535}
1536
1537void NuPlayer::performReset() {
1538 ALOGV("performReset");
1539
1540 CHECK(mAudioDecoder == NULL);
1541 CHECK(mVideoDecoder == NULL);
1542
1543 cancelPollDuration();
1544
1545 ++mScanSourcesGeneration;
1546 mScanSourcesPending = false;
1547
Lajos Molnar09524832014-07-17 14:29:51 -07001548 if (mRendererLooper != NULL) {
1549 if (mRenderer != NULL) {
1550 mRendererLooper->unregisterHandler(mRenderer->id());
1551 }
1552 mRendererLooper->stop();
1553 mRendererLooper.clear();
1554 }
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001555 mRenderer.clear();
Wei Jia57568df2014-09-22 10:16:29 -07001556 ++mRendererGeneration;
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001557
1558 if (mSource != NULL) {
1559 mSource->stop();
Andreas Huberb5f25f02013-02-05 10:14:26 -08001560
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001561 mSource.clear();
1562 }
1563
1564 if (mDriver != NULL) {
1565 sp<NuPlayerDriver> driver = mDriver.promote();
1566 if (driver != NULL) {
1567 driver->notifyResetComplete();
1568 }
1569 }
Andreas Huber57a339c2012-12-03 11:18:00 -08001570
1571 mStarted = false;
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001572}
1573
1574void NuPlayer::performScanSources() {
1575 ALOGV("performScanSources");
1576
Andreas Huber57a339c2012-12-03 11:18:00 -08001577 if (!mStarted) {
1578 return;
1579 }
1580
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001581 if (mAudioDecoder == NULL || mVideoDecoder == NULL) {
1582 postScanSources();
1583 }
1584}
1585
Andreas Huber57a339c2012-12-03 11:18:00 -08001586void NuPlayer::performSetSurface(const sp<NativeWindowWrapper> &wrapper) {
1587 ALOGV("performSetSurface");
1588
1589 mNativeWindow = wrapper;
1590
1591 // XXX - ignore error from setVideoScalingMode for now
1592 setVideoScalingMode(mVideoScalingMode);
Chong Zhang13d6faa2014-08-22 15:35:28 -07001593
1594 if (mDriver != NULL) {
1595 sp<NuPlayerDriver> driver = mDriver.promote();
1596 if (driver != NULL) {
1597 driver->notifySetSurfaceComplete();
1598 }
1599 }
Andreas Huber57a339c2012-12-03 11:18:00 -08001600}
1601
Chong Zhangf8d71772014-11-26 15:08:34 -08001602void NuPlayer::performResumeDecoders(bool needNotify) {
1603 if (needNotify) {
1604 mResumePending = true;
1605 if (mVideoDecoder == NULL) {
1606 // if audio-only, we can notify seek complete now,
1607 // as the resume operation will be relatively fast.
1608 finishResume();
1609 }
1610 }
1611
Chong Zhang7137ec72014-11-12 16:41:05 -08001612 if (mVideoDecoder != NULL) {
Chong Zhangf8d71772014-11-26 15:08:34 -08001613 // When there is continuous seek, MediaPlayer will cache the seek
1614 // position, and send down new seek request when previous seek is
1615 // complete. Let's wait for at least one video output frame before
1616 // notifying seek complete, so that the video thumbnail gets updated
1617 // when seekbar is dragged.
1618 mVideoDecoder->signalResume(needNotify);
Chong Zhang7137ec72014-11-12 16:41:05 -08001619 }
1620
1621 if (mAudioDecoder != NULL) {
Chong Zhangf8d71772014-11-26 15:08:34 -08001622 mAudioDecoder->signalResume(false /* needNotify */);
1623 }
1624}
1625
1626void NuPlayer::finishResume() {
1627 if (mResumePending) {
1628 mResumePending = false;
1629 if (mDriver != NULL) {
1630 sp<NuPlayerDriver> driver = mDriver.promote();
1631 if (driver != NULL) {
1632 driver->notifySeekComplete();
1633 }
1634 }
Chong Zhang7137ec72014-11-12 16:41:05 -08001635 }
1636}
1637
Andreas Huber9575c962013-02-05 13:59:56 -08001638void NuPlayer::onSourceNotify(const sp<AMessage> &msg) {
1639 int32_t what;
1640 CHECK(msg->findInt32("what", &what));
1641
1642 switch (what) {
1643 case Source::kWhatPrepared:
1644 {
Andreas Huberb5f28d42013-04-25 15:11:19 -07001645 if (mSource == NULL) {
1646 // This is a stale notification from a source that was
1647 // asynchronously preparing when the client called reset().
1648 // We handled the reset, the source is gone.
1649 break;
1650 }
1651
Andreas Huberec0c5972013-02-05 14:47:13 -08001652 int32_t err;
1653 CHECK(msg->findInt32("err", &err));
1654
Andreas Huber9575c962013-02-05 13:59:56 -08001655 sp<NuPlayerDriver> driver = mDriver.promote();
1656 if (driver != NULL) {
Marco Nelissendd114d12014-05-28 15:23:14 -07001657 // notify duration first, so that it's definitely set when
1658 // the app received the "prepare complete" callback.
1659 int64_t durationUs;
1660 if (mSource->getDuration(&durationUs) == OK) {
1661 driver->notifyDuration(durationUs);
1662 }
Andreas Huberec0c5972013-02-05 14:47:13 -08001663 driver->notifyPrepareCompleted(err);
Andreas Huber9575c962013-02-05 13:59:56 -08001664 }
Andreas Huber99759402013-04-01 14:28:31 -07001665
Andreas Huber9575c962013-02-05 13:59:56 -08001666 break;
1667 }
1668
1669 case Source::kWhatFlagsChanged:
1670 {
1671 uint32_t flags;
1672 CHECK(msg->findInt32("flags", (int32_t *)&flags));
1673
Chong Zhang4b7069d2013-09-11 12:52:43 -07001674 sp<NuPlayerDriver> driver = mDriver.promote();
1675 if (driver != NULL) {
Wei Jia895651b2014-12-10 17:31:52 -08001676 if ((flags & NuPlayer::Source::FLAG_CAN_SEEK) == 0) {
1677 driver->notifyListener(
1678 MEDIA_INFO, MEDIA_INFO_NOT_SEEKABLE, 0);
1679 }
Chong Zhang4b7069d2013-09-11 12:52:43 -07001680 driver->notifyFlagsChanged(flags);
1681 }
1682
Andreas Huber9575c962013-02-05 13:59:56 -08001683 if ((mSourceFlags & Source::FLAG_DYNAMIC_DURATION)
1684 && (!(flags & Source::FLAG_DYNAMIC_DURATION))) {
1685 cancelPollDuration();
1686 } else if (!(mSourceFlags & Source::FLAG_DYNAMIC_DURATION)
1687 && (flags & Source::FLAG_DYNAMIC_DURATION)
1688 && (mAudioDecoder != NULL || mVideoDecoder != NULL)) {
1689 schedulePollDuration();
1690 }
1691
1692 mSourceFlags = flags;
1693 break;
1694 }
1695
1696 case Source::kWhatVideoSizeChanged:
1697 {
Chong Zhangced1c2f2014-08-08 15:22:35 -07001698 sp<AMessage> format;
1699 CHECK(msg->findMessage("format", &format));
Andreas Huber9575c962013-02-05 13:59:56 -08001700
Chong Zhangced1c2f2014-08-08 15:22:35 -07001701 updateVideoSize(format);
Andreas Huber9575c962013-02-05 13:59:56 -08001702 break;
1703 }
1704
Chong Zhang2a3cc9a2014-08-21 17:48:26 -07001705 case Source::kWhatBufferingUpdate:
1706 {
1707 int32_t percentage;
1708 CHECK(msg->findInt32("percentage", &percentage));
1709
1710 notifyListener(MEDIA_BUFFERING_UPDATE, percentage, 0);
1711 break;
1712 }
1713
Roger Jönssonb50e83e2013-01-21 16:26:41 +01001714 case Source::kWhatBufferingStart:
1715 {
1716 notifyListener(MEDIA_INFO, MEDIA_INFO_BUFFERING_START, 0);
1717 break;
1718 }
1719
1720 case Source::kWhatBufferingEnd:
1721 {
1722 notifyListener(MEDIA_INFO, MEDIA_INFO_BUFFERING_END, 0);
1723 break;
1724 }
1725
Chong Zhangdcb89b32013-08-06 09:44:47 -07001726 case Source::kWhatSubtitleData:
1727 {
1728 sp<ABuffer> buffer;
1729 CHECK(msg->findBuffer("buffer", &buffer));
1730
Chong Zhang404fced2014-06-11 14:45:31 -07001731 sendSubtitleData(buffer, 0 /* baseIndex */);
Chong Zhangdcb89b32013-08-06 09:44:47 -07001732 break;
1733 }
1734
Robert Shihd3b0bbb2014-07-23 15:00:25 -07001735 case Source::kWhatTimedTextData:
1736 {
1737 int32_t generation;
1738 if (msg->findInt32("generation", &generation)
1739 && generation != mTimedTextGeneration) {
1740 break;
1741 }
1742
1743 sp<ABuffer> buffer;
1744 CHECK(msg->findBuffer("buffer", &buffer));
1745
1746 sp<NuPlayerDriver> driver = mDriver.promote();
1747 if (driver == NULL) {
1748 break;
1749 }
1750
1751 int posMs;
1752 int64_t timeUs, posUs;
1753 driver->getCurrentPosition(&posMs);
1754 posUs = posMs * 1000;
1755 CHECK(buffer->meta()->findInt64("timeUs", &timeUs));
1756
1757 if (posUs < timeUs) {
1758 if (!msg->findInt32("generation", &generation)) {
1759 msg->setInt32("generation", mTimedTextGeneration);
1760 }
1761 msg->post(timeUs - posUs);
1762 } else {
1763 sendTimedTextData(buffer);
1764 }
1765 break;
1766 }
1767
Andreas Huber14f76722013-01-15 09:04:18 -08001768 case Source::kWhatQueueDecoderShutdown:
1769 {
1770 int32_t audio, video;
1771 CHECK(msg->findInt32("audio", &audio));
1772 CHECK(msg->findInt32("video", &video));
1773
1774 sp<AMessage> reply;
1775 CHECK(msg->findMessage("reply", &reply));
1776
1777 queueDecoderShutdown(audio, video, reply);
1778 break;
1779 }
1780
Ronghua Wu80276872014-08-28 15:50:29 -07001781 case Source::kWhatDrmNoLicense:
1782 {
1783 notifyListener(MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, ERROR_DRM_NO_LICENSE);
1784 break;
1785 }
1786
Andreas Huber9575c962013-02-05 13:59:56 -08001787 default:
1788 TRESPASS();
1789 }
1790}
1791
Chong Zhanga7fa1d92014-06-11 14:49:23 -07001792void NuPlayer::onClosedCaptionNotify(const sp<AMessage> &msg) {
1793 int32_t what;
1794 CHECK(msg->findInt32("what", &what));
1795
1796 switch (what) {
1797 case NuPlayer::CCDecoder::kWhatClosedCaptionData:
1798 {
1799 sp<ABuffer> buffer;
1800 CHECK(msg->findBuffer("buffer", &buffer));
1801
1802 size_t inbandTracks = 0;
1803 if (mSource != NULL) {
1804 inbandTracks = mSource->getTrackCount();
1805 }
1806
1807 sendSubtitleData(buffer, inbandTracks);
1808 break;
1809 }
1810
1811 case NuPlayer::CCDecoder::kWhatTrackAdded:
1812 {
1813 notifyListener(MEDIA_INFO, MEDIA_INFO_METADATA_UPDATE, 0);
1814
1815 break;
1816 }
1817
1818 default:
1819 TRESPASS();
1820 }
1821
1822
1823}
1824
Chong Zhang404fced2014-06-11 14:45:31 -07001825void NuPlayer::sendSubtitleData(const sp<ABuffer> &buffer, int32_t baseIndex) {
1826 int32_t trackIndex;
1827 int64_t timeUs, durationUs;
1828 CHECK(buffer->meta()->findInt32("trackIndex", &trackIndex));
1829 CHECK(buffer->meta()->findInt64("timeUs", &timeUs));
1830 CHECK(buffer->meta()->findInt64("durationUs", &durationUs));
1831
1832 Parcel in;
1833 in.writeInt32(trackIndex + baseIndex);
1834 in.writeInt64(timeUs);
1835 in.writeInt64(durationUs);
1836 in.writeInt32(buffer->size());
1837 in.writeInt32(buffer->size());
1838 in.write(buffer->data(), buffer->size());
1839
1840 notifyListener(MEDIA_SUBTITLE_DATA, 0, 0, &in);
1841}
Robert Shihd3b0bbb2014-07-23 15:00:25 -07001842
1843void NuPlayer::sendTimedTextData(const sp<ABuffer> &buffer) {
1844 const void *data;
1845 size_t size = 0;
1846 int64_t timeUs;
1847 int32_t flag = TextDescriptions::LOCAL_DESCRIPTIONS;
1848
1849 AString mime;
1850 CHECK(buffer->meta()->findString("mime", &mime));
1851 CHECK(strcasecmp(mime.c_str(), MEDIA_MIMETYPE_TEXT_3GPP) == 0);
1852
1853 data = buffer->data();
1854 size = buffer->size();
1855
1856 Parcel parcel;
1857 if (size > 0) {
1858 CHECK(buffer->meta()->findInt64("timeUs", &timeUs));
1859 flag |= TextDescriptions::IN_BAND_TEXT_3GPP;
1860 TextDescriptions::getParcelOfDescriptions(
1861 (const uint8_t *)data, size, flag, timeUs / 1000, &parcel);
1862 }
1863
1864 if ((parcel.dataSize() > 0)) {
1865 notifyListener(MEDIA_TIMED_TEXT, 0, 0, &parcel);
1866 } else { // send an empty timed text
1867 notifyListener(MEDIA_TIMED_TEXT, 0, 0);
1868 }
1869}
Andreas Huberb5f25f02013-02-05 10:14:26 -08001870////////////////////////////////////////////////////////////////////////////////
1871
Chong Zhangced1c2f2014-08-08 15:22:35 -07001872sp<AMessage> NuPlayer::Source::getFormat(bool audio) {
1873 sp<MetaData> meta = getFormatMeta(audio);
1874
1875 if (meta == NULL) {
1876 return NULL;
1877 }
1878
1879 sp<AMessage> msg = new AMessage;
1880
1881 if(convertMetaDataToMessage(meta, &msg) == OK) {
1882 return msg;
1883 }
1884 return NULL;
1885}
1886
Andreas Huber9575c962013-02-05 13:59:56 -08001887void NuPlayer::Source::notifyFlagsChanged(uint32_t flags) {
1888 sp<AMessage> notify = dupNotify();
1889 notify->setInt32("what", kWhatFlagsChanged);
1890 notify->setInt32("flags", flags);
1891 notify->post();
1892}
1893
Chong Zhangced1c2f2014-08-08 15:22:35 -07001894void NuPlayer::Source::notifyVideoSizeChanged(const sp<AMessage> &format) {
Andreas Huber9575c962013-02-05 13:59:56 -08001895 sp<AMessage> notify = dupNotify();
1896 notify->setInt32("what", kWhatVideoSizeChanged);
Chong Zhangced1c2f2014-08-08 15:22:35 -07001897 notify->setMessage("format", format);
Andreas Huber9575c962013-02-05 13:59:56 -08001898 notify->post();
1899}
1900
Andreas Huberec0c5972013-02-05 14:47:13 -08001901void NuPlayer::Source::notifyPrepared(status_t err) {
Andreas Huber9575c962013-02-05 13:59:56 -08001902 sp<AMessage> notify = dupNotify();
1903 notify->setInt32("what", kWhatPrepared);
Andreas Huberec0c5972013-02-05 14:47:13 -08001904 notify->setInt32("err", err);
Andreas Huber9575c962013-02-05 13:59:56 -08001905 notify->post();
1906}
1907
Andreas Huber84333e02014-02-07 15:36:10 -08001908void NuPlayer::Source::onMessageReceived(const sp<AMessage> & /* msg */) {
Andreas Huberb5f25f02013-02-05 10:14:26 -08001909 TRESPASS();
1910}
1911
Andreas Huberf9334412010-12-15 15:17:42 -08001912} // namespace android