blob: 26b83bb3cfabea4c1862c5a16bc0dadf4492bcb4 [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
Lajos Molnar3a474aa2015-04-24 17:10:07 -070040#include <media/AudioResamplerPublic.h>
41#include <media/AVSyncSettings.h>
42
Andreas Huber3831a062010-12-21 10:22:33 -080043#include <media/stagefright/foundation/hexdump.h>
Andreas Huberf9334412010-12-15 15:17:42 -080044#include <media/stagefright/foundation/ABuffer.h>
45#include <media/stagefright/foundation/ADebug.h>
46#include <media/stagefright/foundation/AMessage.h>
Lajos Molnar09524832014-07-17 14:29:51 -070047#include <media/stagefright/MediaBuffer.h>
Andreas Huber3fe62152011-09-16 15:09:22 -070048#include <media/stagefright/MediaDefs.h>
Andreas Huberf9334412010-12-15 15:17:42 -080049#include <media/stagefright/MediaErrors.h>
50#include <media/stagefright/MetaData.h>
Lajos Molnar1de1e252015-04-30 18:18:34 -070051
Andy McFadden8ba01022012-12-18 09:46:54 -080052#include <gui/IGraphicBufferProducer.h>
Lajos Molnar1de1e252015-04-30 18:18:34 -070053#include <gui/Surface.h>
Andreas Huberf9334412010-12-15 15:17:42 -080054
Andreas Huber3fe62152011-09-16 15:09:22 -070055#include "avc_utils.h"
56
Andreas Huber84066782011-08-16 09:34:26 -070057#include "ESDS.h"
58#include <media/stagefright/Utils.h>
59
Andreas Huberf9334412010-12-15 15:17:42 -080060namespace android {
61
Andreas Hubera1f8ab02012-11-30 10:53:22 -080062struct NuPlayer::Action : public RefBase {
63 Action() {}
64
65 virtual void execute(NuPlayer *player) = 0;
66
67private:
68 DISALLOW_EVIL_CONSTRUCTORS(Action);
69};
70
71struct NuPlayer::SeekAction : public Action {
Wei Jia29840802015-05-15 17:11:38 -070072 SeekAction(int64_t seekTimeUs)
73 : mSeekTimeUs(seekTimeUs) {
Andreas Hubera1f8ab02012-11-30 10:53:22 -080074 }
75
76 virtual void execute(NuPlayer *player) {
Wei Jia29840802015-05-15 17:11:38 -070077 player->performSeek(mSeekTimeUs);
Andreas Hubera1f8ab02012-11-30 10:53:22 -080078 }
79
80private:
81 int64_t mSeekTimeUs;
82
83 DISALLOW_EVIL_CONSTRUCTORS(SeekAction);
84};
85
Chong Zhangf8d71772014-11-26 15:08:34 -080086struct NuPlayer::ResumeDecoderAction : public Action {
87 ResumeDecoderAction(bool needNotify)
88 : mNeedNotify(needNotify) {
89 }
90
91 virtual void execute(NuPlayer *player) {
92 player->performResumeDecoders(mNeedNotify);
93 }
94
95private:
96 bool mNeedNotify;
97
98 DISALLOW_EVIL_CONSTRUCTORS(ResumeDecoderAction);
99};
100
Andreas Huber57a339c2012-12-03 11:18:00 -0800101struct NuPlayer::SetSurfaceAction : public Action {
Lajos Molnar1de1e252015-04-30 18:18:34 -0700102 SetSurfaceAction(const sp<Surface> &surface)
103 : mSurface(surface) {
Andreas Huber57a339c2012-12-03 11:18:00 -0800104 }
105
106 virtual void execute(NuPlayer *player) {
Lajos Molnar1de1e252015-04-30 18:18:34 -0700107 player->performSetSurface(mSurface);
Andreas Huber57a339c2012-12-03 11:18:00 -0800108 }
109
110private:
Lajos Molnar1de1e252015-04-30 18:18:34 -0700111 sp<Surface> mSurface;
Andreas Huber57a339c2012-12-03 11:18:00 -0800112
113 DISALLOW_EVIL_CONSTRUCTORS(SetSurfaceAction);
114};
115
Wei Jiafef808d2014-10-31 17:57:05 -0700116struct NuPlayer::FlushDecoderAction : public Action {
117 FlushDecoderAction(FlushCommand audio, FlushCommand video)
Andreas Huber14f76722013-01-15 09:04:18 -0800118 : mAudio(audio),
119 mVideo(video) {
120 }
121
122 virtual void execute(NuPlayer *player) {
Wei Jiafef808d2014-10-31 17:57:05 -0700123 player->performDecoderFlush(mAudio, mVideo);
Andreas Huber14f76722013-01-15 09:04:18 -0800124 }
125
126private:
Wei Jiafef808d2014-10-31 17:57:05 -0700127 FlushCommand mAudio;
128 FlushCommand mVideo;
Andreas Huber14f76722013-01-15 09:04:18 -0800129
Wei Jiafef808d2014-10-31 17:57:05 -0700130 DISALLOW_EVIL_CONSTRUCTORS(FlushDecoderAction);
Andreas Huber14f76722013-01-15 09:04:18 -0800131};
132
133struct NuPlayer::PostMessageAction : public Action {
134 PostMessageAction(const sp<AMessage> &msg)
135 : mMessage(msg) {
136 }
137
138 virtual void execute(NuPlayer *) {
139 mMessage->post();
140 }
141
142private:
143 sp<AMessage> mMessage;
144
145 DISALLOW_EVIL_CONSTRUCTORS(PostMessageAction);
146};
147
Andreas Hubera1f8ab02012-11-30 10:53:22 -0800148// Use this if there's no state necessary to save in order to execute
149// the action.
150struct NuPlayer::SimpleAction : public Action {
151 typedef void (NuPlayer::*ActionFunc)();
152
153 SimpleAction(ActionFunc func)
154 : mFunc(func) {
155 }
156
157 virtual void execute(NuPlayer *player) {
158 (player->*mFunc)();
159 }
160
161private:
162 ActionFunc mFunc;
163
164 DISALLOW_EVIL_CONSTRUCTORS(SimpleAction);
165};
166
Andreas Huberf9334412010-12-15 15:17:42 -0800167////////////////////////////////////////////////////////////////////////////////
168
169NuPlayer::NuPlayer()
Andreas Huber9b80c2b2011-06-30 15:47:02 -0700170 : mUIDValid(false),
Andreas Huber9575c962013-02-05 13:59:56 -0800171 mSourceFlags(0),
Wei Jiabc2fb722014-07-08 16:37:57 -0700172 mOffloadAudio(false),
Wei Jia88703c32014-08-06 11:24:07 -0700173 mAudioDecoderGeneration(0),
174 mVideoDecoderGeneration(0),
Wei Jia57568df2014-09-22 10:16:29 -0700175 mRendererGeneration(0),
Andreas Huber9b80c2b2011-06-30 15:47:02 -0700176 mAudioEOS(false),
Andreas Huberf9334412010-12-15 15:17:42 -0800177 mVideoEOS(false),
Andreas Huber5bc087c2010-12-23 10:27:40 -0800178 mScanSourcesPending(false),
Andreas Huber1aef2112011-01-04 14:01:29 -0800179 mScanSourcesGeneration(0),
Andreas Huberb7c8e912012-11-27 15:02:53 -0800180 mPollDurationGeneration(0),
Robert Shihd3b0bbb2014-07-23 15:00:25 -0700181 mTimedTextGeneration(0),
Andreas Huberf9334412010-12-15 15:17:42 -0800182 mFlushingAudio(NONE),
Andreas Huber1aef2112011-01-04 14:01:29 -0800183 mFlushingVideo(NONE),
Chong Zhangf8d71772014-11-26 15:08:34 -0800184 mResumePending(false),
Andreas Huber57a339c2012-12-03 11:18:00 -0800185 mVideoScalingMode(NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW),
Lajos Molnar3a474aa2015-04-24 17:10:07 -0700186 mPlaybackSettings(AUDIO_PLAYBACK_RATE_DEFAULT),
187 mVideoFpsHint(-1.f),
Chong Zhangefbb6192015-01-30 17:13:27 -0800188 mStarted(false),
Robert Shih0c61a0d2015-07-06 15:09:10 -0700189 mSourceStarted(false),
Chong Zhangefbb6192015-01-30 17:13:27 -0800190 mPaused(false),
Chong Zhang8a048332015-05-06 15:16:28 -0700191 mPausedByClient(false),
192 mPausedForBuffering(false) {
Andy Hung8d121d42014-10-03 09:53:53 -0700193 clearFlushComplete();
Andreas Huberf9334412010-12-15 15:17:42 -0800194}
195
196NuPlayer::~NuPlayer() {
197}
198
Andreas Huber9b80c2b2011-06-30 15:47:02 -0700199void NuPlayer::setUID(uid_t uid) {
200 mUIDValid = true;
201 mUID = uid;
202}
203
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800204void NuPlayer::setDriver(const wp<NuPlayerDriver> &driver) {
205 mDriver = driver;
Andreas Huberf9334412010-12-15 15:17:42 -0800206}
207
Andreas Huber9575c962013-02-05 13:59:56 -0800208void NuPlayer::setDataSourceAsync(const sp<IStreamSource> &source) {
Lajos Molnar1d15ab52015-03-04 16:46:34 -0800209 sp<AMessage> msg = new AMessage(kWhatSetDataSource, this);
Andreas Huberf9334412010-12-15 15:17:42 -0800210
Lajos Molnar1d15ab52015-03-04 16:46:34 -0800211 sp<AMessage> notify = new AMessage(kWhatSourceNotify, this);
Andreas Huberb5f25f02013-02-05 10:14:26 -0800212
Andreas Huber240abcc2014-02-13 13:32:37 -0800213 msg->setObject("source", new StreamingSource(notify, source));
Andreas Huber5bc087c2010-12-23 10:27:40 -0800214 msg->post();
215}
Andreas Huberf9334412010-12-15 15:17:42 -0800216
Andreas Huberafed0e12011-09-20 15:39:58 -0700217static bool IsHTTPLiveURL(const char *url) {
218 if (!strncasecmp("http://", url, 7)
Andreas Huber99759402013-04-01 14:28:31 -0700219 || !strncasecmp("https://", url, 8)
220 || !strncasecmp("file://", url, 7)) {
Andreas Huberafed0e12011-09-20 15:39:58 -0700221 size_t len = strlen(url);
222 if (len >= 5 && !strcasecmp(".m3u8", &url[len - 5])) {
223 return true;
224 }
225
226 if (strstr(url,"m3u8")) {
227 return true;
228 }
229 }
230
231 return false;
232}
233
Andreas Huber9575c962013-02-05 13:59:56 -0800234void NuPlayer::setDataSourceAsync(
Andreas Huber1b86fe02014-01-29 11:13:26 -0800235 const sp<IMediaHTTPService> &httpService,
236 const char *url,
237 const KeyedVector<String8, String8> *headers) {
Chong Zhang3de157d2014-08-05 20:54:44 -0700238
Lajos Molnar1d15ab52015-03-04 16:46:34 -0800239 sp<AMessage> msg = new AMessage(kWhatSetDataSource, this);
Oscar Rydhé7a33b772012-02-20 10:15:48 +0100240 size_t len = strlen(url);
Andreas Huber5bc087c2010-12-23 10:27:40 -0800241
Lajos Molnar1d15ab52015-03-04 16:46:34 -0800242 sp<AMessage> notify = new AMessage(kWhatSourceNotify, this);
Andreas Huberb5f25f02013-02-05 10:14:26 -0800243
Andreas Huberafed0e12011-09-20 15:39:58 -0700244 sp<Source> source;
245 if (IsHTTPLiveURL(url)) {
Andreas Huber81e68442014-02-05 11:52:33 -0800246 source = new HTTPLiveSource(notify, httpService, url, headers);
Andreas Huberafed0e12011-09-20 15:39:58 -0700247 } else if (!strncasecmp(url, "rtsp://", 7)) {
Andreas Huber1b86fe02014-01-29 11:13:26 -0800248 source = new RTSPSource(
249 notify, httpService, url, headers, mUIDValid, mUID);
Oscar Rydhé7a33b772012-02-20 10:15:48 +0100250 } else if ((!strncasecmp(url, "http://", 7)
251 || !strncasecmp(url, "https://", 8))
252 && ((len >= 4 && !strcasecmp(".sdp", &url[len - 4]))
253 || strstr(url, ".sdp?"))) {
Andreas Huber1b86fe02014-01-29 11:13:26 -0800254 source = new RTSPSource(
255 notify, httpService, url, headers, mUIDValid, mUID, true);
Andreas Huber2bfdd422011-10-11 15:24:07 -0700256 } else {
Chong Zhang3de157d2014-08-05 20:54:44 -0700257 sp<GenericSource> genericSource =
258 new GenericSource(notify, mUIDValid, mUID);
259 // Don't set FLAG_SECURE on mSourceFlags here for widevine.
260 // The correct flags will be updated in Source::kWhatFlagsChanged
261 // handler when GenericSource is prepared.
Andreas Huber2bfdd422011-10-11 15:24:07 -0700262
Chong Zhanga19f33e2014-08-07 15:35:07 -0700263 status_t err = genericSource->setDataSource(httpService, url, headers);
Chong Zhang3de157d2014-08-05 20:54:44 -0700264
265 if (err == OK) {
266 source = genericSource;
267 } else {
Chong Zhanga19f33e2014-08-07 15:35:07 -0700268 ALOGE("Failed to set data source!");
Chong Zhang3de157d2014-08-05 20:54:44 -0700269 }
270 }
Andreas Huberafed0e12011-09-20 15:39:58 -0700271 msg->setObject("source", source);
272 msg->post();
273}
274
Andreas Huber9575c962013-02-05 13:59:56 -0800275void NuPlayer::setDataSourceAsync(int fd, int64_t offset, int64_t length) {
Lajos Molnar1d15ab52015-03-04 16:46:34 -0800276 sp<AMessage> msg = new AMessage(kWhatSetDataSource, this);
Andreas Huberafed0e12011-09-20 15:39:58 -0700277
Lajos Molnar1d15ab52015-03-04 16:46:34 -0800278 sp<AMessage> notify = new AMessage(kWhatSourceNotify, this);
Andreas Huberb5f25f02013-02-05 10:14:26 -0800279
Chong Zhang3de157d2014-08-05 20:54:44 -0700280 sp<GenericSource> source =
281 new GenericSource(notify, mUIDValid, mUID);
282
Chong Zhanga19f33e2014-08-07 15:35:07 -0700283 status_t err = source->setDataSource(fd, offset, length);
Chong Zhang3de157d2014-08-05 20:54:44 -0700284
285 if (err != OK) {
Chong Zhanga19f33e2014-08-07 15:35:07 -0700286 ALOGE("Failed to set data source!");
Chong Zhang3de157d2014-08-05 20:54:44 -0700287 source = NULL;
288 }
289
Andreas Huberafed0e12011-09-20 15:39:58 -0700290 msg->setObject("source", source);
Andreas Huberf9334412010-12-15 15:17:42 -0800291 msg->post();
292}
293
Chris Watkins99f31602015-03-20 13:06:33 -0700294void NuPlayer::setDataSourceAsync(const sp<DataSource> &dataSource) {
295 sp<AMessage> msg = new AMessage(kWhatSetDataSource, this);
296 sp<AMessage> notify = new AMessage(kWhatSourceNotify, this);
297
298 sp<GenericSource> source = new GenericSource(notify, mUIDValid, mUID);
299 status_t err = source->setDataSource(dataSource);
300
301 if (err != OK) {
302 ALOGE("Failed to set data source!");
303 source = NULL;
304 }
305
306 msg->setObject("source", source);
307 msg->post();
308}
309
Andreas Huber9575c962013-02-05 13:59:56 -0800310void NuPlayer::prepareAsync() {
Lajos Molnar1d15ab52015-03-04 16:46:34 -0800311 (new AMessage(kWhatPrepare, this))->post();
Andreas Huber9575c962013-02-05 13:59:56 -0800312}
313
Andreas Huber57a339c2012-12-03 11:18:00 -0800314void NuPlayer::setVideoSurfaceTextureAsync(
Andy McFadden8ba01022012-12-18 09:46:54 -0800315 const sp<IGraphicBufferProducer> &bufferProducer) {
Lajos Molnar1de1e252015-04-30 18:18:34 -0700316 sp<AMessage> msg = new AMessage(kWhatSetVideoSurface, this);
Andreas Huber57a339c2012-12-03 11:18:00 -0800317
Andy McFadden8ba01022012-12-18 09:46:54 -0800318 if (bufferProducer == NULL) {
Lajos Molnar1de1e252015-04-30 18:18:34 -0700319 msg->setObject("surface", NULL);
Andreas Huber57a339c2012-12-03 11:18:00 -0800320 } else {
Lajos Molnar1de1e252015-04-30 18:18:34 -0700321 msg->setObject("surface", new Surface(bufferProducer, true /* controlledByApp */));
Andreas Huber57a339c2012-12-03 11:18:00 -0800322 }
323
Andreas Huberf9334412010-12-15 15:17:42 -0800324 msg->post();
325}
326
327void NuPlayer::setAudioSink(const sp<MediaPlayerBase::AudioSink> &sink) {
Lajos Molnar1d15ab52015-03-04 16:46:34 -0800328 sp<AMessage> msg = new AMessage(kWhatSetAudioSink, this);
Andreas Huberf9334412010-12-15 15:17:42 -0800329 msg->setObject("sink", sink);
330 msg->post();
331}
332
333void NuPlayer::start() {
Lajos Molnar1d15ab52015-03-04 16:46:34 -0800334 (new AMessage(kWhatStart, this))->post();
Andreas Huberf9334412010-12-15 15:17:42 -0800335}
336
Lajos Molnar3a474aa2015-04-24 17:10:07 -0700337status_t NuPlayer::setPlaybackSettings(const AudioPlaybackRate &rate) {
338 // do some cursory validation of the settings here. audio modes are
339 // only validated when set on the audiosink.
340 if ((rate.mSpeed != 0.f && rate.mSpeed < AUDIO_TIMESTRETCH_SPEED_MIN)
341 || rate.mSpeed > AUDIO_TIMESTRETCH_SPEED_MAX
342 || rate.mPitch < AUDIO_TIMESTRETCH_SPEED_MIN
343 || rate.mPitch > AUDIO_TIMESTRETCH_SPEED_MAX) {
344 return BAD_VALUE;
345 }
346 sp<AMessage> msg = new AMessage(kWhatConfigPlayback, this);
347 writeToAMessage(msg, rate);
348 sp<AMessage> response;
349 status_t err = msg->postAndAwaitResponse(&response);
350 if (err == OK && response != NULL) {
351 CHECK(response->findInt32("err", &err));
352 }
353 return err;
354}
355
356status_t NuPlayer::getPlaybackSettings(AudioPlaybackRate *rate /* nonnull */) {
357 sp<AMessage> msg = new AMessage(kWhatGetPlaybackSettings, this);
358 sp<AMessage> response;
359 status_t err = msg->postAndAwaitResponse(&response);
360 if (err == OK && response != NULL) {
361 CHECK(response->findInt32("err", &err));
362 if (err == OK) {
363 readFromAMessage(response, rate);
364 }
365 }
366 return err;
367}
368
369status_t NuPlayer::setSyncSettings(const AVSyncSettings &sync, float videoFpsHint) {
370 sp<AMessage> msg = new AMessage(kWhatConfigSync, this);
371 writeToAMessage(msg, sync, videoFpsHint);
372 sp<AMessage> response;
373 status_t err = msg->postAndAwaitResponse(&response);
374 if (err == OK && response != NULL) {
375 CHECK(response->findInt32("err", &err));
376 }
377 return err;
378}
379
380status_t NuPlayer::getSyncSettings(
381 AVSyncSettings *sync /* nonnull */, float *videoFps /* nonnull */) {
382 sp<AMessage> msg = new AMessage(kWhatGetSyncSettings, this);
383 sp<AMessage> response;
384 status_t err = msg->postAndAwaitResponse(&response);
385 if (err == OK && response != NULL) {
386 CHECK(response->findInt32("err", &err));
387 if (err == OK) {
388 readFromAMessage(response, sync, videoFps);
389 }
390 }
391 return err;
Wei Jia98160162015-02-04 17:01:11 -0800392}
393
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800394void NuPlayer::pause() {
Lajos Molnar1d15ab52015-03-04 16:46:34 -0800395 (new AMessage(kWhatPause, this))->post();
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800396}
397
Andreas Huber1aef2112011-01-04 14:01:29 -0800398void NuPlayer::resetAsync() {
Chong Zhang48296b72014-09-14 14:28:45 -0700399 if (mSource != NULL) {
400 // During a reset, the data source might be unresponsive already, we need to
401 // disconnect explicitly so that reads exit promptly.
402 // We can't queue the disconnect request to the looper, as it might be
403 // queued behind a stuck read and never gets processed.
404 // Doing a disconnect outside the looper to allows the pending reads to exit
405 // (either successfully or with error).
406 mSource->disconnect();
407 }
408
Lajos Molnar1d15ab52015-03-04 16:46:34 -0800409 (new AMessage(kWhatReset, this))->post();
Andreas Huber1aef2112011-01-04 14:01:29 -0800410}
411
Wei Jiae427abf2014-09-22 15:21:11 -0700412void NuPlayer::seekToAsync(int64_t seekTimeUs, bool needNotify) {
Lajos Molnar1d15ab52015-03-04 16:46:34 -0800413 sp<AMessage> msg = new AMessage(kWhatSeek, this);
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800414 msg->setInt64("seekTimeUs", seekTimeUs);
Wei Jiae427abf2014-09-22 15:21:11 -0700415 msg->setInt32("needNotify", needNotify);
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800416 msg->post();
417}
418
Andreas Huber53df1a42010-12-22 10:03:04 -0800419
Chong Zhang404fced2014-06-11 14:45:31 -0700420void NuPlayer::writeTrackInfo(
421 Parcel* reply, const sp<AMessage> format) const {
422 int32_t trackType;
423 CHECK(format->findInt32("type", &trackType));
424
Robert Shih755106e2015-04-30 14:36:45 -0700425 AString mime;
Robert Shih2e3a4252015-05-06 10:21:15 -0700426 if (!format->findString("mime", &mime)) {
427 // Java MediaPlayer only uses mimetype for subtitle and timedtext tracks.
428 // If we can't find the mimetype here it means that we wouldn't be needing
429 // the mimetype on the Java end. We still write a placeholder mime to keep the
430 // (de)serialization logic simple.
431 if (trackType == MEDIA_TRACK_TYPE_AUDIO) {
432 mime = "audio/";
433 } else if (trackType == MEDIA_TRACK_TYPE_VIDEO) {
434 mime = "video/";
435 } else {
436 TRESPASS();
437 }
438 }
Robert Shih755106e2015-04-30 14:36:45 -0700439
Chong Zhang404fced2014-06-11 14:45:31 -0700440 AString lang;
441 CHECK(format->findString("language", &lang));
442
443 reply->writeInt32(2); // write something non-zero
444 reply->writeInt32(trackType);
Robert Shih755106e2015-04-30 14:36:45 -0700445 reply->writeString16(String16(mime.c_str()));
Chong Zhang404fced2014-06-11 14:45:31 -0700446 reply->writeString16(String16(lang.c_str()));
447
448 if (trackType == MEDIA_TRACK_TYPE_SUBTITLE) {
Chong Zhang404fced2014-06-11 14:45:31 -0700449 int32_t isAuto, isDefault, isForced;
450 CHECK(format->findInt32("auto", &isAuto));
451 CHECK(format->findInt32("default", &isDefault));
452 CHECK(format->findInt32("forced", &isForced));
453
Chong Zhang404fced2014-06-11 14:45:31 -0700454 reply->writeInt32(isAuto);
455 reply->writeInt32(isDefault);
456 reply->writeInt32(isForced);
457 }
458}
459
Andreas Huberf9334412010-12-15 15:17:42 -0800460void NuPlayer::onMessageReceived(const sp<AMessage> &msg) {
461 switch (msg->what()) {
462 case kWhatSetDataSource:
463 {
Steve Block3856b092011-10-20 11:56:00 +0100464 ALOGV("kWhatSetDataSource");
Andreas Huberf9334412010-12-15 15:17:42 -0800465
466 CHECK(mSource == NULL);
467
Chong Zhang3de157d2014-08-05 20:54:44 -0700468 status_t err = OK;
Andreas Huber5bc087c2010-12-23 10:27:40 -0800469 sp<RefBase> obj;
470 CHECK(msg->findObject("source", &obj));
Chong Zhang3de157d2014-08-05 20:54:44 -0700471 if (obj != NULL) {
472 mSource = static_cast<Source *>(obj.get());
Chong Zhang3de157d2014-08-05 20:54:44 -0700473 } else {
474 err = UNKNOWN_ERROR;
475 }
Andreas Huber9575c962013-02-05 13:59:56 -0800476
477 CHECK(mDriver != NULL);
478 sp<NuPlayerDriver> driver = mDriver.promote();
479 if (driver != NULL) {
Chong Zhang3de157d2014-08-05 20:54:44 -0700480 driver->notifySetDataSourceCompleted(err);
Andreas Huber9575c962013-02-05 13:59:56 -0800481 }
482 break;
483 }
484
485 case kWhatPrepare:
486 {
487 mSource->prepareAsync();
Andreas Huberf9334412010-12-15 15:17:42 -0800488 break;
489 }
490
Chong Zhangdcb89b32013-08-06 09:44:47 -0700491 case kWhatGetTrackInfo:
492 {
Lajos Molnar3f274362015-03-05 14:35:41 -0800493 sp<AReplyToken> replyID;
Chong Zhangdcb89b32013-08-06 09:44:47 -0700494 CHECK(msg->senderAwaitsResponse(&replyID));
495
Chong Zhang404fced2014-06-11 14:45:31 -0700496 Parcel* reply;
497 CHECK(msg->findPointer("reply", (void**)&reply));
498
499 size_t inbandTracks = 0;
Chong Zhangdcb89b32013-08-06 09:44:47 -0700500 if (mSource != NULL) {
Chong Zhang404fced2014-06-11 14:45:31 -0700501 inbandTracks = mSource->getTrackCount();
502 }
503
Chong Zhanga7fa1d92014-06-11 14:49:23 -0700504 size_t ccTracks = 0;
505 if (mCCDecoder != NULL) {
506 ccTracks = mCCDecoder->getTrackCount();
507 }
508
Chong Zhang404fced2014-06-11 14:45:31 -0700509 // total track count
Chong Zhanga7fa1d92014-06-11 14:49:23 -0700510 reply->writeInt32(inbandTracks + ccTracks);
Chong Zhang404fced2014-06-11 14:45:31 -0700511
512 // write inband tracks
513 for (size_t i = 0; i < inbandTracks; ++i) {
514 writeTrackInfo(reply, mSource->getTrackInfo(i));
Chong Zhangdcb89b32013-08-06 09:44:47 -0700515 }
516
Chong Zhanga7fa1d92014-06-11 14:49:23 -0700517 // write CC track
518 for (size_t i = 0; i < ccTracks; ++i) {
519 writeTrackInfo(reply, mCCDecoder->getTrackInfo(i));
520 }
521
Chong Zhangdcb89b32013-08-06 09:44:47 -0700522 sp<AMessage> response = new AMessage;
Chong Zhangdcb89b32013-08-06 09:44:47 -0700523 response->postReply(replyID);
524 break;
525 }
526
Robert Shih7c4f0d72014-07-09 18:53:31 -0700527 case kWhatGetSelectedTrack:
528 {
529 status_t err = INVALID_OPERATION;
530 if (mSource != NULL) {
531 err = OK;
532
533 int32_t type32;
534 CHECK(msg->findInt32("type", (int32_t*)&type32));
535 media_track_type type = (media_track_type)type32;
536 ssize_t selectedTrack = mSource->getSelectedTrack(type);
537
538 Parcel* reply;
539 CHECK(msg->findPointer("reply", (void**)&reply));
540 reply->writeInt32(selectedTrack);
541 }
542
543 sp<AMessage> response = new AMessage;
544 response->setInt32("err", err);
545
Lajos Molnar3f274362015-03-05 14:35:41 -0800546 sp<AReplyToken> replyID;
Robert Shih7c4f0d72014-07-09 18:53:31 -0700547 CHECK(msg->senderAwaitsResponse(&replyID));
548 response->postReply(replyID);
549 break;
550 }
551
Chong Zhangdcb89b32013-08-06 09:44:47 -0700552 case kWhatSelectTrack:
553 {
Lajos Molnar3f274362015-03-05 14:35:41 -0800554 sp<AReplyToken> replyID;
Chong Zhangdcb89b32013-08-06 09:44:47 -0700555 CHECK(msg->senderAwaitsResponse(&replyID));
556
Chong Zhang404fced2014-06-11 14:45:31 -0700557 size_t trackIndex;
558 int32_t select;
Robert Shih6ffb1fd2014-10-29 16:24:32 -0700559 int64_t timeUs;
Chong Zhang404fced2014-06-11 14:45:31 -0700560 CHECK(msg->findSize("trackIndex", &trackIndex));
561 CHECK(msg->findInt32("select", &select));
Robert Shih6ffb1fd2014-10-29 16:24:32 -0700562 CHECK(msg->findInt64("timeUs", &timeUs));
Chong Zhang404fced2014-06-11 14:45:31 -0700563
Chong Zhangdcb89b32013-08-06 09:44:47 -0700564 status_t err = INVALID_OPERATION;
Chong Zhang404fced2014-06-11 14:45:31 -0700565
566 size_t inbandTracks = 0;
Chong Zhangdcb89b32013-08-06 09:44:47 -0700567 if (mSource != NULL) {
Chong Zhang404fced2014-06-11 14:45:31 -0700568 inbandTracks = mSource->getTrackCount();
569 }
Chong Zhanga7fa1d92014-06-11 14:49:23 -0700570 size_t ccTracks = 0;
571 if (mCCDecoder != NULL) {
572 ccTracks = mCCDecoder->getTrackCount();
573 }
Chong Zhang404fced2014-06-11 14:45:31 -0700574
575 if (trackIndex < inbandTracks) {
Robert Shih6ffb1fd2014-10-29 16:24:32 -0700576 err = mSource->selectTrack(trackIndex, select, timeUs);
Robert Shihd3b0bbb2014-07-23 15:00:25 -0700577
578 if (!select && err == OK) {
579 int32_t type;
580 sp<AMessage> info = mSource->getTrackInfo(trackIndex);
581 if (info != NULL
582 && info->findInt32("type", &type)
583 && type == MEDIA_TRACK_TYPE_TIMEDTEXT) {
584 ++mTimedTextGeneration;
585 }
586 }
Chong Zhanga7fa1d92014-06-11 14:49:23 -0700587 } else {
588 trackIndex -= inbandTracks;
589
590 if (trackIndex < ccTracks) {
591 err = mCCDecoder->selectTrack(trackIndex, select);
592 }
Chong Zhangdcb89b32013-08-06 09:44:47 -0700593 }
594
595 sp<AMessage> response = new AMessage;
596 response->setInt32("err", err);
597
598 response->postReply(replyID);
599 break;
600 }
601
Andreas Huberb7c8e912012-11-27 15:02:53 -0800602 case kWhatPollDuration:
603 {
604 int32_t generation;
605 CHECK(msg->findInt32("generation", &generation));
606
607 if (generation != mPollDurationGeneration) {
608 // stale
609 break;
610 }
611
612 int64_t durationUs;
613 if (mDriver != NULL && mSource->getDuration(&durationUs) == OK) {
614 sp<NuPlayerDriver> driver = mDriver.promote();
615 if (driver != NULL) {
616 driver->notifyDuration(durationUs);
617 }
618 }
619
620 msg->post(1000000ll); // poll again in a second.
621 break;
622 }
623
Lajos Molnar1de1e252015-04-30 18:18:34 -0700624 case kWhatSetVideoSurface:
Andreas Huberf9334412010-12-15 15:17:42 -0800625 {
Lajos Molnar1de1e252015-04-30 18:18:34 -0700626 ALOGV("kWhatSetVideoSurface");
Andreas Huberf9334412010-12-15 15:17:42 -0800627
628 sp<RefBase> obj;
Lajos Molnar1de1e252015-04-30 18:18:34 -0700629 CHECK(msg->findObject("surface", &obj));
630 sp<Surface> surface = static_cast<Surface *>(obj.get());
Lajos Molnarf4849522014-12-10 16:58:57 -0800631 if (mSource == NULL || mSource->getFormat(false /* audio */) == NULL) {
Lajos Molnar1de1e252015-04-30 18:18:34 -0700632 performSetSurface(surface);
Wei Jiafef808d2014-10-31 17:57:05 -0700633 break;
634 }
635
636 mDeferredActions.push_back(
637 new FlushDecoderAction(FLUSH_CMD_FLUSH /* audio */,
638 FLUSH_CMD_SHUTDOWN /* video */));
639
Lajos Molnar1de1e252015-04-30 18:18:34 -0700640 mDeferredActions.push_back(new SetSurfaceAction(surface));
James Dong0d268a32012-08-31 12:18:27 -0700641
Wei Jiac6e58412015-07-10 18:04:55 -0700642 if (obj != NULL || mAudioDecoder != NULL) {
Wei Jiafef808d2014-10-31 17:57:05 -0700643 if (mStarted) {
Andy Hung73535852014-09-05 11:42:58 -0700644 // Issue a seek to refresh the video screen only if started otherwise
645 // the extractor may not yet be started and will assert.
646 // If the video decoder is not set (perhaps audio only in this case)
647 // do not perform a seek as it is not needed.
Ronghua Wua73d9e02014-10-08 15:13:29 -0700648 int64_t currentPositionUs = 0;
649 if (getCurrentPosition(&currentPositionUs) == OK) {
650 mDeferredActions.push_back(
Wei Jia29840802015-05-15 17:11:38 -0700651 new SeekAction(currentPositionUs));
Ronghua Wua73d9e02014-10-08 15:13:29 -0700652 }
Andy Hung73535852014-09-05 11:42:58 -0700653 }
Wei Jiaac428aa2014-09-02 19:01:34 -0700654
Andreas Huber57a339c2012-12-03 11:18:00 -0800655 // If there is a new surface texture, instantiate decoders
656 // again if possible.
657 mDeferredActions.push_back(
658 new SimpleAction(&NuPlayer::performScanSources));
659 }
660
Chong Zhangf8d71772014-11-26 15:08:34 -0800661 // After a flush without shutdown, decoder is paused.
662 // Don't resume it until source seek is done, otherwise it could
Chong Zhang7137ec72014-11-12 16:41:05 -0800663 // start pulling stale data too soon.
664 mDeferredActions.push_back(
Chong Zhangf8d71772014-11-26 15:08:34 -0800665 new ResumeDecoderAction(false /* needNotify */));
Chong Zhang7137ec72014-11-12 16:41:05 -0800666
Andreas Huber57a339c2012-12-03 11:18:00 -0800667 processDeferredActions();
Andreas Huberf9334412010-12-15 15:17:42 -0800668 break;
669 }
670
671 case kWhatSetAudioSink:
672 {
Steve Block3856b092011-10-20 11:56:00 +0100673 ALOGV("kWhatSetAudioSink");
Andreas Huberf9334412010-12-15 15:17:42 -0800674
675 sp<RefBase> obj;
676 CHECK(msg->findObject("sink", &obj));
677
678 mAudioSink = static_cast<MediaPlayerBase::AudioSink *>(obj.get());
679 break;
680 }
681
682 case kWhatStart:
683 {
Steve Block3856b092011-10-20 11:56:00 +0100684 ALOGV("kWhatStart");
Wei Jia94211742014-10-28 17:09:06 -0700685 if (mStarted) {
Chong Zhang8a048332015-05-06 15:16:28 -0700686 // do not resume yet if the source is still buffering
687 if (!mPausedForBuffering) {
688 onResume();
689 }
Wei Jia94211742014-10-28 17:09:06 -0700690 } else {
691 onStart();
Lajos Molnar09524832014-07-17 14:29:51 -0700692 }
Chong Zhangefbb6192015-01-30 17:13:27 -0800693 mPausedByClient = false;
Andreas Huberf9334412010-12-15 15:17:42 -0800694 break;
695 }
696
Lajos Molnar3a474aa2015-04-24 17:10:07 -0700697 case kWhatConfigPlayback:
Wei Jia98160162015-02-04 17:01:11 -0800698 {
Lajos Molnar3a474aa2015-04-24 17:10:07 -0700699 sp<AReplyToken> replyID;
700 CHECK(msg->senderAwaitsResponse(&replyID));
701 AudioPlaybackRate rate /* sanitized */;
702 readFromAMessage(msg, &rate);
703 status_t err = OK;
Wei Jia98160162015-02-04 17:01:11 -0800704 if (mRenderer != NULL) {
Lajos Molnar3a474aa2015-04-24 17:10:07 -0700705 err = mRenderer->setPlaybackSettings(rate);
706 }
707 if (err == OK) {
708 if (rate.mSpeed == 0.f) {
709 onPause();
710 // save all other settings (using non-paused speed)
711 // so we can restore them on start
712 AudioPlaybackRate newRate = rate;
713 newRate.mSpeed = mPlaybackSettings.mSpeed;
714 mPlaybackSettings = newRate;
715 } else { /* rate.mSpeed != 0.f */
716 onResume();
717 mPlaybackSettings = rate;
718 }
Wei Jia98160162015-02-04 17:01:11 -0800719 }
Ronghua Wu8db88132015-04-22 13:51:35 -0700720
721 if (mVideoDecoder != NULL) {
Ronghua Wuc8a70d32015-04-29 16:26:34 -0700722 float rate = getFrameRate();
723 if (rate > 0) {
Ronghua Wu8db88132015-04-22 13:51:35 -0700724 sp<AMessage> params = new AMessage();
Lajos Molnar3a474aa2015-04-24 17:10:07 -0700725 params->setFloat("operating-rate", rate * mPlaybackSettings.mSpeed);
Ronghua Wu8db88132015-04-22 13:51:35 -0700726 mVideoDecoder->setParameters(params);
727 }
728 }
729
Lajos Molnar3a474aa2015-04-24 17:10:07 -0700730 sp<AMessage> response = new AMessage;
731 response->setInt32("err", err);
732 response->postReply(replyID);
733 break;
734 }
735
736 case kWhatGetPlaybackSettings:
737 {
738 sp<AReplyToken> replyID;
739 CHECK(msg->senderAwaitsResponse(&replyID));
740 AudioPlaybackRate rate = mPlaybackSettings;
741 status_t err = OK;
742 if (mRenderer != NULL) {
743 err = mRenderer->getPlaybackSettings(&rate);
744 }
745 if (err == OK) {
746 // get playback settings used by renderer, as it may be
747 // slightly off due to audiosink not taking small changes.
748 mPlaybackSettings = rate;
749 if (mPaused) {
750 rate.mSpeed = 0.f;
751 }
752 }
753 sp<AMessage> response = new AMessage;
754 if (err == OK) {
755 writeToAMessage(response, rate);
756 }
757 response->setInt32("err", err);
758 response->postReply(replyID);
759 break;
760 }
761
762 case kWhatConfigSync:
763 {
764 sp<AReplyToken> replyID;
765 CHECK(msg->senderAwaitsResponse(&replyID));
766
767 ALOGV("kWhatConfigSync");
768 AVSyncSettings sync;
769 float videoFpsHint;
770 readFromAMessage(msg, &sync, &videoFpsHint);
771 status_t err = OK;
772 if (mRenderer != NULL) {
773 err = mRenderer->setSyncSettings(sync, videoFpsHint);
774 }
775 if (err == OK) {
776 mSyncSettings = sync;
777 mVideoFpsHint = videoFpsHint;
778 }
779 sp<AMessage> response = new AMessage;
780 response->setInt32("err", err);
781 response->postReply(replyID);
782 break;
783 }
784
785 case kWhatGetSyncSettings:
786 {
787 sp<AReplyToken> replyID;
788 CHECK(msg->senderAwaitsResponse(&replyID));
789 AVSyncSettings sync = mSyncSettings;
790 float videoFps = mVideoFpsHint;
791 status_t err = OK;
792 if (mRenderer != NULL) {
793 err = mRenderer->getSyncSettings(&sync, &videoFps);
794 if (err == OK) {
795 mSyncSettings = sync;
796 mVideoFpsHint = videoFps;
797 }
798 }
799 sp<AMessage> response = new AMessage;
800 if (err == OK) {
801 writeToAMessage(response, sync, videoFps);
802 }
803 response->setInt32("err", err);
804 response->postReply(replyID);
Wei Jia98160162015-02-04 17:01:11 -0800805 break;
806 }
807
Andreas Huberf9334412010-12-15 15:17:42 -0800808 case kWhatScanSources:
809 {
Andreas Huber1aef2112011-01-04 14:01:29 -0800810 int32_t generation;
811 CHECK(msg->findInt32("generation", &generation));
812 if (generation != mScanSourcesGeneration) {
813 // Drop obsolete msg.
814 break;
815 }
816
Andreas Huber5bc087c2010-12-23 10:27:40 -0800817 mScanSourcesPending = false;
818
Steve Block3856b092011-10-20 11:56:00 +0100819 ALOGV("scanning sources haveAudio=%d, haveVideo=%d",
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800820 mAudioDecoder != NULL, mVideoDecoder != NULL);
821
Andreas Huberb7c8e912012-11-27 15:02:53 -0800822 bool mHadAnySourcesBefore =
823 (mAudioDecoder != NULL) || (mVideoDecoder != NULL);
824
Andy Hung282a7e32014-08-14 15:56:34 -0700825 // initialize video before audio because successful initialization of
826 // video may change deep buffer mode of audio.
Lajos Molnar1de1e252015-04-30 18:18:34 -0700827 if (mSurface != NULL) {
Haynes Mathew George5d246ef2012-07-09 10:36:57 -0700828 instantiateDecoder(false, &mVideoDecoder);
829 }
Andreas Huberf9334412010-12-15 15:17:42 -0800830
Ronghua Wua10fd232014-11-06 16:15:20 -0800831 // Don't try to re-open audio sink if there's an existing decoder.
832 if (mAudioSink != NULL && mAudioDecoder == NULL) {
Andreas Huber5bc087c2010-12-23 10:27:40 -0800833 instantiateDecoder(true, &mAudioDecoder);
Andreas Huberf9334412010-12-15 15:17:42 -0800834 }
835
Andreas Huberb7c8e912012-11-27 15:02:53 -0800836 if (!mHadAnySourcesBefore
837 && (mAudioDecoder != NULL || mVideoDecoder != NULL)) {
838 // This is the first time we've found anything playable.
839
Andreas Huber9575c962013-02-05 13:59:56 -0800840 if (mSourceFlags & Source::FLAG_DYNAMIC_DURATION) {
Andreas Huberb7c8e912012-11-27 15:02:53 -0800841 schedulePollDuration();
842 }
843 }
844
Andreas Hubereac68ba2011-09-27 12:12:25 -0700845 status_t err;
846 if ((err = mSource->feedMoreTSData()) != OK) {
Andreas Huber1aef2112011-01-04 14:01:29 -0800847 if (mAudioDecoder == NULL && mVideoDecoder == NULL) {
848 // We're not currently decoding anything (no audio or
849 // video tracks found) and we just ran out of input data.
Andreas Hubereac68ba2011-09-27 12:12:25 -0700850
851 if (err == ERROR_END_OF_STREAM) {
852 notifyListener(MEDIA_PLAYBACK_COMPLETE, 0, 0);
853 } else {
854 notifyListener(MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, err);
855 }
Andreas Huber1aef2112011-01-04 14:01:29 -0800856 }
Andreas Huberf9334412010-12-15 15:17:42 -0800857 break;
858 }
859
Andreas Huberfbe9d812012-08-31 14:05:27 -0700860 if ((mAudioDecoder == NULL && mAudioSink != NULL)
Lajos Molnar1de1e252015-04-30 18:18:34 -0700861 || (mVideoDecoder == NULL && mSurface != NULL)) {
Andreas Huberf9334412010-12-15 15:17:42 -0800862 msg->post(100000ll);
Andreas Huber5bc087c2010-12-23 10:27:40 -0800863 mScanSourcesPending = true;
Andreas Huberf9334412010-12-15 15:17:42 -0800864 }
865 break;
866 }
867
868 case kWhatVideoNotify:
869 case kWhatAudioNotify:
870 {
871 bool audio = msg->what() == kWhatAudioNotify;
872
Wei Jia88703c32014-08-06 11:24:07 -0700873 int32_t currentDecoderGeneration =
874 (audio? mAudioDecoderGeneration : mVideoDecoderGeneration);
875 int32_t requesterGeneration = currentDecoderGeneration - 1;
876 CHECK(msg->findInt32("generation", &requesterGeneration));
877
878 if (requesterGeneration != currentDecoderGeneration) {
879 ALOGV("got message from old %s decoder, generation(%d:%d)",
880 audio ? "audio" : "video", requesterGeneration,
881 currentDecoderGeneration);
882 sp<AMessage> reply;
883 if (!(msg->findMessage("reply", &reply))) {
884 return;
885 }
886
887 reply->setInt32("err", INFO_DISCONTINUITY);
888 reply->post();
889 return;
890 }
891
Andreas Huberf9334412010-12-15 15:17:42 -0800892 int32_t what;
Lajos Molnar1cd13982014-01-17 15:12:51 -0800893 CHECK(msg->findInt32("what", &what));
Andreas Huberf9334412010-12-15 15:17:42 -0800894
Chong Zhang7137ec72014-11-12 16:41:05 -0800895 if (what == DecoderBase::kWhatInputDiscontinuity) {
896 int32_t formatChange;
897 CHECK(msg->findInt32("formatChange", &formatChange));
Andreas Huberf9334412010-12-15 15:17:42 -0800898
Chong Zhang7137ec72014-11-12 16:41:05 -0800899 ALOGV("%s discontinuity: formatChange %d",
900 audio ? "audio" : "video", formatChange);
901
902 if (formatChange) {
903 mDeferredActions.push_back(
904 new FlushDecoderAction(
905 audio ? FLUSH_CMD_SHUTDOWN : FLUSH_CMD_NONE,
906 audio ? FLUSH_CMD_NONE : FLUSH_CMD_SHUTDOWN));
Andreas Huberf9334412010-12-15 15:17:42 -0800907 }
Chong Zhang7137ec72014-11-12 16:41:05 -0800908
909 mDeferredActions.push_back(
910 new SimpleAction(
911 &NuPlayer::performScanSources));
912
913 processDeferredActions();
914 } else if (what == DecoderBase::kWhatEOS) {
Andreas Huberdc9bacd2011-09-26 10:53:29 -0700915 int32_t err;
Lajos Molnar1cd13982014-01-17 15:12:51 -0800916 CHECK(msg->findInt32("err", &err));
Andreas Huberdc9bacd2011-09-26 10:53:29 -0700917
918 if (err == ERROR_END_OF_STREAM) {
Steve Block3856b092011-10-20 11:56:00 +0100919 ALOGV("got %s decoder EOS", audio ? "audio" : "video");
Andreas Huberdc9bacd2011-09-26 10:53:29 -0700920 } else {
Steve Block3856b092011-10-20 11:56:00 +0100921 ALOGV("got %s decoder EOS w/ error %d",
Andreas Huberdc9bacd2011-09-26 10:53:29 -0700922 audio ? "audio" : "video",
923 err);
924 }
925
926 mRenderer->queueEOS(audio, err);
Chong Zhang7137ec72014-11-12 16:41:05 -0800927 } else if (what == DecoderBase::kWhatFlushCompleted) {
Steve Block3856b092011-10-20 11:56:00 +0100928 ALOGV("decoder %s flush completed", audio ? "audio" : "video");
Andreas Huberf9334412010-12-15 15:17:42 -0800929
Andy Hung8d121d42014-10-03 09:53:53 -0700930 handleFlushComplete(audio, true /* isDecoder */);
Andreas Huber3831a062010-12-21 10:22:33 -0800931 finishFlushIfPossible();
Chong Zhang7137ec72014-11-12 16:41:05 -0800932 } else if (what == DecoderBase::kWhatVideoSizeChanged) {
Lajos Molnar1cd13982014-01-17 15:12:51 -0800933 sp<AMessage> format;
934 CHECK(msg->findMessage("format", &format));
935
Wei Jiac6cfd702014-11-11 16:33:20 -0800936 sp<AMessage> inputFormat =
937 mSource->getFormat(false /* audio */);
Andreas Huber3831a062010-12-21 10:22:33 -0800938
Wei Jiac6cfd702014-11-11 16:33:20 -0800939 updateVideoSize(inputFormat, format);
Chong Zhang7137ec72014-11-12 16:41:05 -0800940 } else if (what == DecoderBase::kWhatShutdownCompleted) {
Steve Block3856b092011-10-20 11:56:00 +0100941 ALOGV("%s shutdown completed", audio ? "audio" : "video");
Andreas Huber3831a062010-12-21 10:22:33 -0800942 if (audio) {
943 mAudioDecoder.clear();
Wei Jia57568df2014-09-22 10:16:29 -0700944 ++mAudioDecoderGeneration;
Andreas Huber3831a062010-12-21 10:22:33 -0800945
946 CHECK_EQ((int)mFlushingAudio, (int)SHUTTING_DOWN_DECODER);
947 mFlushingAudio = SHUT_DOWN;
948 } else {
949 mVideoDecoder.clear();
Wei Jia57568df2014-09-22 10:16:29 -0700950 ++mVideoDecoderGeneration;
Andreas Huber3831a062010-12-21 10:22:33 -0800951
952 CHECK_EQ((int)mFlushingVideo, (int)SHUTTING_DOWN_DECODER);
953 mFlushingVideo = SHUT_DOWN;
954 }
955
956 finishFlushIfPossible();
Chong Zhangf8d71772014-11-26 15:08:34 -0800957 } else if (what == DecoderBase::kWhatResumeCompleted) {
958 finishResume();
Chong Zhang7137ec72014-11-12 16:41:05 -0800959 } else if (what == DecoderBase::kWhatError) {
Chong Zhangf4c0a942014-08-11 15:14:10 -0700960 status_t err;
Andy Hung2abde2c2014-09-30 14:40:32 -0700961 if (!msg->findInt32("err", &err) || err == OK) {
Chong Zhangf4c0a942014-08-11 15:14:10 -0700962 err = UNKNOWN_ERROR;
963 }
Andy Hungcf31f1e2014-09-23 14:59:01 -0700964
Andy Hung2abde2c2014-09-30 14:40:32 -0700965 // Decoder errors can be due to Source (e.g. from streaming),
966 // or from decoding corrupted bitstreams, or from other decoder
967 // MediaCodec operations (e.g. from an ongoing reset or seek).
Andy Hung202bce12014-12-03 11:47:36 -0800968 // They may also be due to openAudioSink failure at
969 // decoder start or after a format change.
Andy Hung2abde2c2014-09-30 14:40:32 -0700970 //
971 // We try to gracefully shut down the affected decoder if possible,
972 // rather than trying to force the shutdown with something
973 // similar to performReset(). This method can lead to a hang
974 // if MediaCodec functions block after an error, but they should
975 // typically return INVALID_OPERATION instead of blocking.
976
977 FlushStatus *flushing = audio ? &mFlushingAudio : &mFlushingVideo;
978 ALOGE("received error(%#x) from %s decoder, flushing(%d), now shutting down",
979 err, audio ? "audio" : "video", *flushing);
980
981 switch (*flushing) {
982 case NONE:
983 mDeferredActions.push_back(
Wei Jiafef808d2014-10-31 17:57:05 -0700984 new FlushDecoderAction(
985 audio ? FLUSH_CMD_SHUTDOWN : FLUSH_CMD_NONE,
986 audio ? FLUSH_CMD_NONE : FLUSH_CMD_SHUTDOWN));
Andy Hung2abde2c2014-09-30 14:40:32 -0700987 processDeferredActions();
988 break;
989 case FLUSHING_DECODER:
990 *flushing = FLUSHING_DECODER_SHUTDOWN; // initiate shutdown after flush.
991 break; // Wait for flush to complete.
992 case FLUSHING_DECODER_SHUTDOWN:
993 break; // Wait for flush to complete.
994 case SHUTTING_DOWN_DECODER:
995 break; // Wait for shutdown to complete.
996 case FLUSHED:
997 // Widevine source reads must stop before releasing the video decoder.
998 if (!audio && mSource != NULL && mSourceFlags & Source::FLAG_SECURE) {
999 mSource->stop();
Robert Shih0c61a0d2015-07-06 15:09:10 -07001000 mSourceStarted = false;
Andy Hung2abde2c2014-09-30 14:40:32 -07001001 }
1002 getDecoder(audio)->initiateShutdown(); // In the middle of a seek.
1003 *flushing = SHUTTING_DOWN_DECODER; // Shut down.
1004 break;
1005 case SHUT_DOWN:
1006 finishFlushIfPossible(); // Should not occur.
1007 break; // Finish anyways.
Marco Nelissen9e2b7912014-08-18 16:13:03 -07001008 }
Andy Hung2abde2c2014-09-30 14:40:32 -07001009 notifyListener(MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, err);
Lajos Molnar1cd13982014-01-17 15:12:51 -08001010 } else {
1011 ALOGV("Unhandled decoder notification %d '%c%c%c%c'.",
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001012 what,
1013 what >> 24,
1014 (what >> 16) & 0xff,
1015 (what >> 8) & 0xff,
1016 what & 0xff);
Andreas Huberf9334412010-12-15 15:17:42 -08001017 }
1018
1019 break;
1020 }
1021
1022 case kWhatRendererNotify:
1023 {
Wei Jia57568df2014-09-22 10:16:29 -07001024 int32_t requesterGeneration = mRendererGeneration - 1;
1025 CHECK(msg->findInt32("generation", &requesterGeneration));
1026 if (requesterGeneration != mRendererGeneration) {
1027 ALOGV("got message from old renderer, generation(%d:%d)",
1028 requesterGeneration, mRendererGeneration);
1029 return;
1030 }
1031
Andreas Huberf9334412010-12-15 15:17:42 -08001032 int32_t what;
1033 CHECK(msg->findInt32("what", &what));
1034
1035 if (what == Renderer::kWhatEOS) {
1036 int32_t audio;
1037 CHECK(msg->findInt32("audio", &audio));
1038
Andreas Huberc92fd242011-08-16 13:48:44 -07001039 int32_t finalResult;
1040 CHECK(msg->findInt32("finalResult", &finalResult));
1041
Andreas Huberf9334412010-12-15 15:17:42 -08001042 if (audio) {
1043 mAudioEOS = true;
1044 } else {
1045 mVideoEOS = true;
1046 }
1047
Andreas Huberc92fd242011-08-16 13:48:44 -07001048 if (finalResult == ERROR_END_OF_STREAM) {
Steve Block3856b092011-10-20 11:56:00 +01001049 ALOGV("reached %s EOS", audio ? "audio" : "video");
Andreas Huberc92fd242011-08-16 13:48:44 -07001050 } else {
Steve Block29357bc2012-01-06 19:20:56 +00001051 ALOGE("%s track encountered an error (%d)",
Andreas Huberc92fd242011-08-16 13:48:44 -07001052 audio ? "audio" : "video", finalResult);
1053
1054 notifyListener(
1055 MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, finalResult);
1056 }
Andreas Huberf9334412010-12-15 15:17:42 -08001057
1058 if ((mAudioEOS || mAudioDecoder == NULL)
1059 && (mVideoEOS || mVideoDecoder == NULL)) {
1060 notifyListener(MEDIA_PLAYBACK_COMPLETE, 0, 0);
1061 }
Andreas Huber3fe62152011-09-16 15:09:22 -07001062 } else if (what == Renderer::kWhatFlushComplete) {
Andreas Huberf9334412010-12-15 15:17:42 -08001063 int32_t audio;
1064 CHECK(msg->findInt32("audio", &audio));
1065
Steve Block3856b092011-10-20 11:56:00 +01001066 ALOGV("renderer %s flush completed.", audio ? "audio" : "video");
Andy Hung8d121d42014-10-03 09:53:53 -07001067 handleFlushComplete(audio, false /* isDecoder */);
1068 finishFlushIfPossible();
James Dongf57b4ea2012-07-20 13:38:36 -07001069 } else if (what == Renderer::kWhatVideoRenderingStart) {
1070 notifyListener(MEDIA_INFO, MEDIA_INFO_RENDERING_START, 0);
Lajos Molnarcbaffcf2013-08-14 18:30:38 -07001071 } else if (what == Renderer::kWhatMediaRenderingStart) {
1072 ALOGV("media rendering started");
1073 notifyListener(MEDIA_STARTED, 0, 0);
Ronghua Wufaeb0f22015-05-21 12:20:21 -07001074 } else if (what == Renderer::kWhatAudioTearDown) {
Wei Jia3a2956d2014-07-22 16:01:33 -07001075 int64_t positionUs;
1076 CHECK(msg->findInt64("positionUs", &positionUs));
Ronghua Wu08529172014-10-02 16:55:52 -07001077 int32_t reason;
1078 CHECK(msg->findInt32("reason", &reason));
Ronghua Wufaeb0f22015-05-21 12:20:21 -07001079 ALOGV("Tear down audio with reason %d.", reason);
Andy Hung282a7e32014-08-14 15:56:34 -07001080 closeAudioSink();
Wei Jia3a2956d2014-07-22 16:01:33 -07001081 mAudioDecoder.clear();
Wei Jia57568df2014-09-22 10:16:29 -07001082 ++mAudioDecoderGeneration;
Chong Zhang7137ec72014-11-12 16:41:05 -08001083 mRenderer->flush(
1084 true /* audio */, false /* notifyComplete */);
Wei Jia3a2956d2014-07-22 16:01:33 -07001085 if (mVideoDecoder != NULL) {
Chong Zhang7137ec72014-11-12 16:41:05 -08001086 mRenderer->flush(
1087 false /* audio */, false /* notifyComplete */);
Wei Jia3a2956d2014-07-22 16:01:33 -07001088 }
Wei Jia3a2956d2014-07-22 16:01:33 -07001089
Wei Jia29840802015-05-15 17:11:38 -07001090 performSeek(positionUs);
Ronghua Wufaeb0f22015-05-21 12:20:21 -07001091
Ronghua Wu08529172014-10-02 16:55:52 -07001092 if (reason == Renderer::kDueToError) {
1093 instantiateDecoder(true /* audio */, &mAudioDecoder);
1094 }
Andreas Huberf9334412010-12-15 15:17:42 -08001095 }
1096 break;
1097 }
1098
1099 case kWhatMoreDataQueued:
1100 {
1101 break;
1102 }
1103
Andreas Huber1aef2112011-01-04 14:01:29 -08001104 case kWhatReset:
1105 {
Steve Block3856b092011-10-20 11:56:00 +01001106 ALOGV("kWhatReset");
Andreas Huber1aef2112011-01-04 14:01:29 -08001107
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001108 mDeferredActions.push_back(
Wei Jiafef808d2014-10-31 17:57:05 -07001109 new FlushDecoderAction(
1110 FLUSH_CMD_SHUTDOWN /* audio */,
1111 FLUSH_CMD_SHUTDOWN /* video */));
Andreas Huberb7c8e912012-11-27 15:02:53 -08001112
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001113 mDeferredActions.push_back(
1114 new SimpleAction(&NuPlayer::performReset));
Andreas Huberb58ce9f2011-11-28 16:27:35 -08001115
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001116 processDeferredActions();
Andreas Huber1aef2112011-01-04 14:01:29 -08001117 break;
1118 }
1119
Andreas Huber43c3e6c2011-01-05 12:17:08 -08001120 case kWhatSeek:
1121 {
1122 int64_t seekTimeUs;
Wei Jiae427abf2014-09-22 15:21:11 -07001123 int32_t needNotify;
Andreas Huber43c3e6c2011-01-05 12:17:08 -08001124 CHECK(msg->findInt64("seekTimeUs", &seekTimeUs));
Wei Jiae427abf2014-09-22 15:21:11 -07001125 CHECK(msg->findInt32("needNotify", &needNotify));
Andreas Huber43c3e6c2011-01-05 12:17:08 -08001126
Wei Jiae427abf2014-09-22 15:21:11 -07001127 ALOGV("kWhatSeek seekTimeUs=%lld us, needNotify=%d",
Lajos Molnar6d339f12015-04-17 16:15:53 -07001128 (long long)seekTimeUs, needNotify);
Andreas Huber43c3e6c2011-01-05 12:17:08 -08001129
Wei Jia1061c9c2015-05-19 16:02:17 -07001130 if (!mStarted) {
1131 // Seek before the player is started. In order to preview video,
1132 // need to start the player and pause it. This branch is called
1133 // only once if needed. After the player is started, any seek
1134 // operation will go through normal path.
Robert Shih0c61a0d2015-07-06 15:09:10 -07001135 // Audio-only cases are handled separately.
Wei Jia1061c9c2015-05-19 16:02:17 -07001136 onStart(seekTimeUs);
Robert Shih0c61a0d2015-07-06 15:09:10 -07001137 if (mStarted) {
1138 onPause();
1139 mPausedByClient = true;
1140 }
Wei Jia1061c9c2015-05-19 16:02:17 -07001141 if (needNotify) {
1142 notifyDriverSeekComplete();
1143 }
1144 break;
1145 }
1146
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001147 mDeferredActions.push_back(
Wei Jiafef808d2014-10-31 17:57:05 -07001148 new FlushDecoderAction(FLUSH_CMD_FLUSH /* audio */,
1149 FLUSH_CMD_FLUSH /* video */));
Andreas Huber43c3e6c2011-01-05 12:17:08 -08001150
Wei Jiae427abf2014-09-22 15:21:11 -07001151 mDeferredActions.push_back(
Wei Jia29840802015-05-15 17:11:38 -07001152 new SeekAction(seekTimeUs));
Andreas Huber43c3e6c2011-01-05 12:17:08 -08001153
Chong Zhangf8d71772014-11-26 15:08:34 -08001154 // After a flush without shutdown, decoder is paused.
1155 // Don't resume it until source seek is done, otherwise it could
Chong Zhang7137ec72014-11-12 16:41:05 -08001156 // start pulling stale data too soon.
1157 mDeferredActions.push_back(
Chong Zhangf8d71772014-11-26 15:08:34 -08001158 new ResumeDecoderAction(needNotify));
Chong Zhang7137ec72014-11-12 16:41:05 -08001159
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001160 processDeferredActions();
Andreas Huber43c3e6c2011-01-05 12:17:08 -08001161 break;
1162 }
1163
Andreas Huberb4082222011-01-20 15:23:04 -08001164 case kWhatPause:
1165 {
Chong Zhangefbb6192015-01-30 17:13:27 -08001166 onPause();
1167 mPausedByClient = true;
Andreas Huberb4082222011-01-20 15:23:04 -08001168 break;
1169 }
1170
Andreas Huberb5f25f02013-02-05 10:14:26 -08001171 case kWhatSourceNotify:
1172 {
Andreas Huber9575c962013-02-05 13:59:56 -08001173 onSourceNotify(msg);
Andreas Huberb5f25f02013-02-05 10:14:26 -08001174 break;
1175 }
1176
Chong Zhanga7fa1d92014-06-11 14:49:23 -07001177 case kWhatClosedCaptionNotify:
1178 {
1179 onClosedCaptionNotify(msg);
1180 break;
1181 }
1182
Andreas Huberf9334412010-12-15 15:17:42 -08001183 default:
1184 TRESPASS();
1185 break;
1186 }
1187}
1188
Wei Jia94211742014-10-28 17:09:06 -07001189void NuPlayer::onResume() {
Chong Zhangefbb6192015-01-30 17:13:27 -08001190 if (!mPaused) {
1191 return;
1192 }
1193 mPaused = false;
Wei Jia94211742014-10-28 17:09:06 -07001194 if (mSource != NULL) {
1195 mSource->resume();
1196 } else {
1197 ALOGW("resume called when source is gone or not set");
1198 }
1199 // |mAudioDecoder| may have been released due to the pause timeout, so re-create it if
1200 // needed.
1201 if (audioDecoderStillNeeded() && mAudioDecoder == NULL) {
1202 instantiateDecoder(true /* audio */, &mAudioDecoder);
1203 }
1204 if (mRenderer != NULL) {
1205 mRenderer->resume();
1206 } else {
1207 ALOGW("resume called when renderer is gone or not set");
1208 }
1209}
1210
Lajos Molnarfcd3e942015-03-31 10:06:48 -07001211status_t NuPlayer::onInstantiateSecureDecoders() {
1212 status_t err;
1213 if (!(mSourceFlags & Source::FLAG_SECURE)) {
1214 return BAD_TYPE;
1215 }
1216
1217 if (mRenderer != NULL) {
1218 ALOGE("renderer should not be set when instantiating secure decoders");
1219 return UNKNOWN_ERROR;
1220 }
1221
1222 // TRICKY: We rely on mRenderer being null, so that decoder does not start requesting
1223 // data on instantiation.
Lajos Molnar1de1e252015-04-30 18:18:34 -07001224 if (mSurface != NULL) {
Lajos Molnarfcd3e942015-03-31 10:06:48 -07001225 err = instantiateDecoder(false, &mVideoDecoder);
1226 if (err != OK) {
1227 return err;
1228 }
1229 }
1230
1231 if (mAudioSink != NULL) {
1232 err = instantiateDecoder(true, &mAudioDecoder);
1233 if (err != OK) {
1234 return err;
1235 }
1236 }
1237 return OK;
1238}
1239
Wei Jia1061c9c2015-05-19 16:02:17 -07001240void NuPlayer::onStart(int64_t startPositionUs) {
Robert Shih0c61a0d2015-07-06 15:09:10 -07001241 if (!mSourceStarted) {
1242 mSourceStarted = true;
1243 mSource->start();
1244 }
1245 if (startPositionUs > 0) {
1246 performSeek(startPositionUs);
1247 if (mSource->getFormat(false /* audio */) == NULL) {
1248 return;
1249 }
1250 }
1251
Wei Jia94211742014-10-28 17:09:06 -07001252 mOffloadAudio = false;
1253 mAudioEOS = false;
1254 mVideoEOS = false;
Wei Jia94211742014-10-28 17:09:06 -07001255 mStarted = true;
1256
Wei Jia94211742014-10-28 17:09:06 -07001257 uint32_t flags = 0;
1258
1259 if (mSource->isRealTime()) {
1260 flags |= Renderer::FLAG_REAL_TIME;
1261 }
1262
1263 sp<MetaData> audioMeta = mSource->getFormatMeta(true /* audio */);
1264 audio_stream_type_t streamType = AUDIO_STREAM_MUSIC;
1265 if (mAudioSink != NULL) {
1266 streamType = mAudioSink->getAudioStreamType();
1267 }
1268
1269 sp<AMessage> videoFormat = mSource->getFormat(false /* audio */);
1270
1271 mOffloadAudio =
Ronghua Wu02cb98d2015-05-27 11:02:54 -07001272 canOffloadStream(audioMeta, (videoFormat != NULL), mSource->isStreaming(), streamType);
Wei Jia94211742014-10-28 17:09:06 -07001273 if (mOffloadAudio) {
1274 flags |= Renderer::FLAG_OFFLOAD_AUDIO;
1275 }
1276
Lajos Molnar1d15ab52015-03-04 16:46:34 -08001277 sp<AMessage> notify = new AMessage(kWhatRendererNotify, this);
Wei Jia94211742014-10-28 17:09:06 -07001278 ++mRendererGeneration;
1279 notify->setInt32("generation", mRendererGeneration);
1280 mRenderer = new Renderer(mAudioSink, notify, flags);
Wei Jia94211742014-10-28 17:09:06 -07001281 mRendererLooper = new ALooper;
1282 mRendererLooper->setName("NuPlayerRenderer");
1283 mRendererLooper->start(false, false, ANDROID_PRIORITY_AUDIO);
1284 mRendererLooper->registerHandler(mRenderer);
Lajos Molnar3a474aa2015-04-24 17:10:07 -07001285
1286 status_t err = mRenderer->setPlaybackSettings(mPlaybackSettings);
1287 if (err != OK) {
1288 mSource->stop();
Robert Shih0c61a0d2015-07-06 15:09:10 -07001289 mSourceStarted = false;
Lajos Molnar3a474aa2015-04-24 17:10:07 -07001290 notifyListener(MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, err);
1291 return;
Wei Jiac8206ff2015-03-04 13:59:37 -08001292 }
Wei Jia94211742014-10-28 17:09:06 -07001293
Ronghua Wuc8a70d32015-04-29 16:26:34 -07001294 float rate = getFrameRate();
1295 if (rate > 0) {
Wei Jia94211742014-10-28 17:09:06 -07001296 mRenderer->setVideoFrameRate(rate);
1297 }
1298
Wei Jiac6cfd702014-11-11 16:33:20 -08001299 if (mVideoDecoder != NULL) {
1300 mVideoDecoder->setRenderer(mRenderer);
1301 }
1302 if (mAudioDecoder != NULL) {
1303 mAudioDecoder->setRenderer(mRenderer);
1304 }
1305
Wei Jia94211742014-10-28 17:09:06 -07001306 postScanSources();
1307}
1308
Chong Zhangefbb6192015-01-30 17:13:27 -08001309void NuPlayer::onPause() {
1310 if (mPaused) {
1311 return;
1312 }
1313 mPaused = true;
1314 if (mSource != NULL) {
1315 mSource->pause();
1316 } else {
1317 ALOGW("pause called when source is gone or not set");
1318 }
1319 if (mRenderer != NULL) {
1320 mRenderer->pause();
1321 } else {
1322 ALOGW("pause called when renderer is gone or not set");
1323 }
1324}
1325
Ronghua Wud7988b12014-10-03 15:19:10 -07001326bool NuPlayer::audioDecoderStillNeeded() {
1327 // Audio decoder is no longer needed if it's in shut/shutting down status.
1328 return ((mFlushingAudio != SHUT_DOWN) && (mFlushingAudio != SHUTTING_DOWN_DECODER));
1329}
1330
Andy Hung8d121d42014-10-03 09:53:53 -07001331void NuPlayer::handleFlushComplete(bool audio, bool isDecoder) {
1332 // We wait for both the decoder flush and the renderer flush to complete
1333 // before entering either the FLUSHED or the SHUTTING_DOWN_DECODER state.
1334
1335 mFlushComplete[audio][isDecoder] = true;
1336 if (!mFlushComplete[audio][!isDecoder]) {
1337 return;
1338 }
1339
1340 FlushStatus *state = audio ? &mFlushingAudio : &mFlushingVideo;
1341 switch (*state) {
1342 case FLUSHING_DECODER:
1343 {
1344 *state = FLUSHED;
Andy Hung8d121d42014-10-03 09:53:53 -07001345 break;
1346 }
1347
1348 case FLUSHING_DECODER_SHUTDOWN:
1349 {
1350 *state = SHUTTING_DOWN_DECODER;
1351
1352 ALOGV("initiating %s decoder shutdown", audio ? "audio" : "video");
1353 if (!audio) {
Andy Hung8d121d42014-10-03 09:53:53 -07001354 // Widevine source reads must stop before releasing the video decoder.
1355 if (mSource != NULL && mSourceFlags & Source::FLAG_SECURE) {
1356 mSource->stop();
Robert Shih0c61a0d2015-07-06 15:09:10 -07001357 mSourceStarted = false;
Andy Hung8d121d42014-10-03 09:53:53 -07001358 }
1359 }
1360 getDecoder(audio)->initiateShutdown();
1361 break;
1362 }
1363
1364 default:
1365 // decoder flush completes only occur in a flushing state.
1366 LOG_ALWAYS_FATAL_IF(isDecoder, "decoder flush in invalid state %d", *state);
1367 break;
1368 }
1369}
1370
Andreas Huber3831a062010-12-21 10:22:33 -08001371void NuPlayer::finishFlushIfPossible() {
Wei Jia53904f32014-07-29 10:22:53 -07001372 if (mFlushingAudio != NONE && mFlushingAudio != FLUSHED
1373 && mFlushingAudio != SHUT_DOWN) {
Andreas Huber3831a062010-12-21 10:22:33 -08001374 return;
1375 }
1376
Wei Jia53904f32014-07-29 10:22:53 -07001377 if (mFlushingVideo != NONE && mFlushingVideo != FLUSHED
1378 && mFlushingVideo != SHUT_DOWN) {
Andreas Huber3831a062010-12-21 10:22:33 -08001379 return;
1380 }
1381
Steve Block3856b092011-10-20 11:56:00 +01001382 ALOGV("both audio and video are flushed now.");
Andreas Huber3831a062010-12-21 10:22:33 -08001383
Andreas Huber3831a062010-12-21 10:22:33 -08001384 mFlushingAudio = NONE;
1385 mFlushingVideo = NONE;
Andreas Huber3831a062010-12-21 10:22:33 -08001386
Andy Hung8d121d42014-10-03 09:53:53 -07001387 clearFlushComplete();
1388
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001389 processDeferredActions();
Andreas Huber1aef2112011-01-04 14:01:29 -08001390}
1391
1392void NuPlayer::postScanSources() {
1393 if (mScanSourcesPending) {
1394 return;
1395 }
1396
Lajos Molnar1d15ab52015-03-04 16:46:34 -08001397 sp<AMessage> msg = new AMessage(kWhatScanSources, this);
Andreas Huber1aef2112011-01-04 14:01:29 -08001398 msg->setInt32("generation", mScanSourcesGeneration);
1399 msg->post();
1400
1401 mScanSourcesPending = true;
1402}
1403
Andy Hung202bce12014-12-03 11:47:36 -08001404void NuPlayer::tryOpenAudioSinkForOffload(const sp<AMessage> &format, bool hasVideo) {
1405 // Note: This is called early in NuPlayer to determine whether offloading
1406 // is possible; otherwise the decoders call the renderer openAudioSink directly.
Andy Hung282a7e32014-08-14 15:56:34 -07001407
Andy Hung202bce12014-12-03 11:47:36 -08001408 status_t err = mRenderer->openAudioSink(
1409 format, true /* offloadOnly */, hasVideo, AUDIO_OUTPUT_FLAG_NONE, &mOffloadAudio);
1410 if (err != OK) {
1411 // Any failure we turn off mOffloadAudio.
1412 mOffloadAudio = false;
1413 } else if (mOffloadAudio) {
Chong Zhang3b9eb1f2014-10-15 17:05:08 -07001414 sp<MetaData> audioMeta =
1415 mSource->getFormatMeta(true /* audio */);
1416 sendMetaDataToHal(mAudioSink, audioMeta);
Andy Hung282a7e32014-08-14 15:56:34 -07001417 }
1418}
1419
1420void NuPlayer::closeAudioSink() {
Chong Zhang3b9eb1f2014-10-15 17:05:08 -07001421 mRenderer->closeAudioSink();
Andy Hung282a7e32014-08-14 15:56:34 -07001422}
1423
Wei Jiae4d18c72015-07-13 17:58:11 -07001424void NuPlayer::determineAudioModeChange() {
1425 if (mSource == NULL || mAudioSink == NULL) {
1426 return;
1427 }
1428
1429 if (mRenderer == NULL) {
1430 ALOGW("No renderer can be used to determine audio mode. Use non-offload for safety.");
1431 mOffloadAudio = false;
1432 return;
1433 }
1434
1435 sp<MetaData> audioMeta = mSource->getFormatMeta(true /* audio */);
1436 sp<AMessage> videoFormat = mSource->getFormat(false /* audio */);
1437 audio_stream_type_t streamType = mAudioSink->getAudioStreamType();
1438 const bool hasVideo = (videoFormat != NULL);
1439 const bool canOffload = canOffloadStream(
1440 audioMeta, hasVideo, mSource->isStreaming(), streamType);
1441 if (canOffload) {
1442 if (!mOffloadAudio) {
1443 mRenderer->signalEnableOffloadAudio();
1444 }
1445 // open audio sink early under offload mode.
1446 sp<AMessage> format = mSource->getFormat(true /*audio*/);
1447 tryOpenAudioSinkForOffload(format, hasVideo);
1448 } else {
1449 mRenderer->signalDisableOffloadAudio();
1450 mOffloadAudio = false;
1451 }
1452}
1453
Chong Zhang7137ec72014-11-12 16:41:05 -08001454status_t NuPlayer::instantiateDecoder(bool audio, sp<DecoderBase> *decoder) {
Andreas Huberf9334412010-12-15 15:17:42 -08001455 if (*decoder != NULL) {
1456 return OK;
1457 }
1458
Andreas Huber84066782011-08-16 09:34:26 -07001459 sp<AMessage> format = mSource->getFormat(audio);
Andreas Huberf9334412010-12-15 15:17:42 -08001460
Andreas Huber84066782011-08-16 09:34:26 -07001461 if (format == NULL) {
Andreas Huberf9334412010-12-15 15:17:42 -08001462 return -EWOULDBLOCK;
1463 }
1464
Ronghua Wu8db88132015-04-22 13:51:35 -07001465 format->setInt32("priority", 0 /* realtime */);
1466
Andreas Huber3fe62152011-09-16 15:09:22 -07001467 if (!audio) {
Andreas Huber84066782011-08-16 09:34:26 -07001468 AString mime;
1469 CHECK(format->findString("mime", &mime));
Chong Zhanga7fa1d92014-06-11 14:49:23 -07001470
Lajos Molnar1d15ab52015-03-04 16:46:34 -08001471 sp<AMessage> ccNotify = new AMessage(kWhatClosedCaptionNotify, this);
Chong Zhang341ab6e2015-02-04 13:37:18 -08001472 if (mCCDecoder == NULL) {
1473 mCCDecoder = new CCDecoder(ccNotify);
1474 }
Lajos Molnar09524832014-07-17 14:29:51 -07001475
1476 if (mSourceFlags & Source::FLAG_SECURE) {
1477 format->setInt32("secure", true);
1478 }
Chong Zhang17134602015-01-07 16:14:34 -08001479
1480 if (mSourceFlags & Source::FLAG_PROTECTED) {
1481 format->setInt32("protected", true);
1482 }
Ronghua Wu8db88132015-04-22 13:51:35 -07001483
Ronghua Wuc8a70d32015-04-29 16:26:34 -07001484 float rate = getFrameRate();
1485 if (rate > 0) {
Lajos Molnar3a474aa2015-04-24 17:10:07 -07001486 format->setFloat("operating-rate", rate * mPlaybackSettings.mSpeed);
Ronghua Wu8db88132015-04-22 13:51:35 -07001487 }
Andreas Huber3fe62152011-09-16 15:09:22 -07001488 }
1489
Wei Jiabc2fb722014-07-08 16:37:57 -07001490 if (audio) {
Lajos Molnar1d15ab52015-03-04 16:46:34 -08001491 sp<AMessage> notify = new AMessage(kWhatAudioNotify, this);
Wei Jia88703c32014-08-06 11:24:07 -07001492 ++mAudioDecoderGeneration;
1493 notify->setInt32("generation", mAudioDecoderGeneration);
1494
Wei Jiae4d18c72015-07-13 17:58:11 -07001495 determineAudioModeChange();
Wei Jiabc2fb722014-07-08 16:37:57 -07001496 if (mOffloadAudio) {
Haynes Mathew George8b635332015-03-30 17:59:47 -07001497 const bool hasVideo = (mSource->getFormat(false /*audio */) != NULL);
1498 format->setInt32("has-video", hasVideo);
Wei Jiac6cfd702014-11-11 16:33:20 -08001499 *decoder = new DecoderPassThrough(notify, mSource, mRenderer);
Wei Jiabc2fb722014-07-08 16:37:57 -07001500 } else {
Wei Jiac6cfd702014-11-11 16:33:20 -08001501 *decoder = new Decoder(notify, mSource, mRenderer);
Wei Jiabc2fb722014-07-08 16:37:57 -07001502 }
1503 } else {
Lajos Molnar1d15ab52015-03-04 16:46:34 -08001504 sp<AMessage> notify = new AMessage(kWhatVideoNotify, this);
Wei Jia88703c32014-08-06 11:24:07 -07001505 ++mVideoDecoderGeneration;
1506 notify->setInt32("generation", mVideoDecoderGeneration);
1507
Chong Zhang7137ec72014-11-12 16:41:05 -08001508 *decoder = new Decoder(
Lajos Molnar1de1e252015-04-30 18:18:34 -07001509 notify, mSource, mRenderer, mSurface, mCCDecoder);
Lajos Molnard9fd6312014-11-06 11:00:00 -08001510
1511 // enable FRC if high-quality AV sync is requested, even if not
Lajos Molnar1de1e252015-04-30 18:18:34 -07001512 // directly queuing to display, as this will even improve textureview
Lajos Molnard9fd6312014-11-06 11:00:00 -08001513 // playback.
1514 {
1515 char value[PROPERTY_VALUE_MAX];
1516 if (property_get("persist.sys.media.avsync", value, NULL) &&
1517 (!strcmp("1", value) || !strcasecmp("true", value))) {
1518 format->setInt32("auto-frc", 1);
1519 }
1520 }
Wei Jiabc2fb722014-07-08 16:37:57 -07001521 }
Lajos Molnar1cd13982014-01-17 15:12:51 -08001522 (*decoder)->init();
Andreas Huber84066782011-08-16 09:34:26 -07001523 (*decoder)->configure(format);
Andreas Huberf9334412010-12-15 15:17:42 -08001524
Lajos Molnar09524832014-07-17 14:29:51 -07001525 // allocate buffers to decrypt widevine source buffers
1526 if (!audio && (mSourceFlags & Source::FLAG_SECURE)) {
1527 Vector<sp<ABuffer> > inputBufs;
1528 CHECK_EQ((*decoder)->getInputBuffers(&inputBufs), (status_t)OK);
1529
1530 Vector<MediaBuffer *> mediaBufs;
1531 for (size_t i = 0; i < inputBufs.size(); i++) {
1532 const sp<ABuffer> &buffer = inputBufs[i];
1533 MediaBuffer *mbuf = new MediaBuffer(buffer->data(), buffer->size());
1534 mediaBufs.push(mbuf);
1535 }
1536
1537 status_t err = mSource->setBuffers(audio, mediaBufs);
1538 if (err != OK) {
1539 for (size_t i = 0; i < mediaBufs.size(); ++i) {
1540 mediaBufs[i]->release();
1541 }
1542 mediaBufs.clear();
1543 ALOGE("Secure source didn't support secure mediaBufs.");
1544 return err;
1545 }
1546 }
Andreas Huberf9334412010-12-15 15:17:42 -08001547 return OK;
1548}
1549
Chong Zhangced1c2f2014-08-08 15:22:35 -07001550void NuPlayer::updateVideoSize(
1551 const sp<AMessage> &inputFormat,
1552 const sp<AMessage> &outputFormat) {
1553 if (inputFormat == NULL) {
1554 ALOGW("Unknown video size, reporting 0x0!");
1555 notifyListener(MEDIA_SET_VIDEO_SIZE, 0, 0);
1556 return;
1557 }
1558
1559 int32_t displayWidth, displayHeight;
Chong Zhangced1c2f2014-08-08 15:22:35 -07001560 if (outputFormat != NULL) {
1561 int32_t width, height;
1562 CHECK(outputFormat->findInt32("width", &width));
1563 CHECK(outputFormat->findInt32("height", &height));
1564
1565 int32_t cropLeft, cropTop, cropRight, cropBottom;
1566 CHECK(outputFormat->findRect(
1567 "crop",
1568 &cropLeft, &cropTop, &cropRight, &cropBottom));
1569
1570 displayWidth = cropRight - cropLeft + 1;
1571 displayHeight = cropBottom - cropTop + 1;
1572
1573 ALOGV("Video output format changed to %d x %d "
1574 "(crop: %d x %d @ (%d, %d))",
1575 width, height,
1576 displayWidth,
1577 displayHeight,
1578 cropLeft, cropTop);
1579 } else {
1580 CHECK(inputFormat->findInt32("width", &displayWidth));
1581 CHECK(inputFormat->findInt32("height", &displayHeight));
1582
1583 ALOGV("Video input format %d x %d", displayWidth, displayHeight);
1584 }
1585
1586 // Take into account sample aspect ratio if necessary:
1587 int32_t sarWidth, sarHeight;
1588 if (inputFormat->findInt32("sar-width", &sarWidth)
1589 && inputFormat->findInt32("sar-height", &sarHeight)) {
1590 ALOGV("Sample aspect ratio %d : %d", sarWidth, sarHeight);
1591
1592 displayWidth = (displayWidth * sarWidth) / sarHeight;
1593
1594 ALOGV("display dimensions %d x %d", displayWidth, displayHeight);
1595 }
1596
1597 int32_t rotationDegrees;
1598 if (!inputFormat->findInt32("rotation-degrees", &rotationDegrees)) {
1599 rotationDegrees = 0;
1600 }
1601
1602 if (rotationDegrees == 90 || rotationDegrees == 270) {
1603 int32_t tmp = displayWidth;
1604 displayWidth = displayHeight;
1605 displayHeight = tmp;
1606 }
1607
1608 notifyListener(
1609 MEDIA_SET_VIDEO_SIZE,
1610 displayWidth,
1611 displayHeight);
1612}
1613
Chong Zhangdcb89b32013-08-06 09:44:47 -07001614void NuPlayer::notifyListener(int msg, int ext1, int ext2, const Parcel *in) {
Andreas Huber43c3e6c2011-01-05 12:17:08 -08001615 if (mDriver == NULL) {
Andreas Huberf9334412010-12-15 15:17:42 -08001616 return;
1617 }
1618
Andreas Huber43c3e6c2011-01-05 12:17:08 -08001619 sp<NuPlayerDriver> driver = mDriver.promote();
Andreas Huberf9334412010-12-15 15:17:42 -08001620
Andreas Huber43c3e6c2011-01-05 12:17:08 -08001621 if (driver == NULL) {
Andreas Huberf9334412010-12-15 15:17:42 -08001622 return;
1623 }
1624
Chong Zhangdcb89b32013-08-06 09:44:47 -07001625 driver->notifyListener(msg, ext1, ext2, in);
Andreas Huberf9334412010-12-15 15:17:42 -08001626}
1627
Chong Zhang7137ec72014-11-12 16:41:05 -08001628void NuPlayer::flushDecoder(bool audio, bool needShutdown) {
Andreas Huber14f76722013-01-15 09:04:18 -08001629 ALOGV("[%s] flushDecoder needShutdown=%d",
1630 audio ? "audio" : "video", needShutdown);
1631
Chong Zhang7137ec72014-11-12 16:41:05 -08001632 const sp<DecoderBase> &decoder = getDecoder(audio);
Lajos Molnar87603c02014-08-20 19:25:30 -07001633 if (decoder == NULL) {
Steve Blockdf64d152012-01-04 20:05:49 +00001634 ALOGI("flushDecoder %s without decoder present",
Andreas Huber6e3d3112011-11-28 12:36:11 -08001635 audio ? "audio" : "video");
Lajos Molnar87603c02014-08-20 19:25:30 -07001636 return;
Andreas Huber6e3d3112011-11-28 12:36:11 -08001637 }
1638
Andreas Huber1aef2112011-01-04 14:01:29 -08001639 // Make sure we don't continue to scan sources until we finish flushing.
1640 ++mScanSourcesGeneration;
Chong Zhang3b032b32015-04-17 15:49:06 -07001641 if (mScanSourcesPending) {
1642 mDeferredActions.push_back(
1643 new SimpleAction(&NuPlayer::performScanSources));
1644 mScanSourcesPending = false;
1645 }
Andreas Huber1aef2112011-01-04 14:01:29 -08001646
Chong Zhang7137ec72014-11-12 16:41:05 -08001647 decoder->signalFlush();
Andreas Huber1aef2112011-01-04 14:01:29 -08001648
1649 FlushStatus newStatus =
1650 needShutdown ? FLUSHING_DECODER_SHUTDOWN : FLUSHING_DECODER;
1651
Lajos Molnarfcd3e942015-03-31 10:06:48 -07001652 mFlushComplete[audio][false /* isDecoder */] = (mRenderer == NULL);
Andy Hung8d121d42014-10-03 09:53:53 -07001653 mFlushComplete[audio][true /* isDecoder */] = false;
Andreas Huber1aef2112011-01-04 14:01:29 -08001654 if (audio) {
Wei Jia53904f32014-07-29 10:22:53 -07001655 ALOGE_IF(mFlushingAudio != NONE,
1656 "audio flushDecoder() is called in state %d", mFlushingAudio);
Andreas Huber1aef2112011-01-04 14:01:29 -08001657 mFlushingAudio = newStatus;
Andreas Huber1aef2112011-01-04 14:01:29 -08001658 } else {
Wei Jia53904f32014-07-29 10:22:53 -07001659 ALOGE_IF(mFlushingVideo != NONE,
1660 "video flushDecoder() is called in state %d", mFlushingVideo);
Andreas Huber1aef2112011-01-04 14:01:29 -08001661 mFlushingVideo = newStatus;
Andreas Huber1aef2112011-01-04 14:01:29 -08001662 }
1663}
1664
Chong Zhangced1c2f2014-08-08 15:22:35 -07001665void NuPlayer::queueDecoderShutdown(
1666 bool audio, bool video, const sp<AMessage> &reply) {
1667 ALOGI("queueDecoderShutdown audio=%d, video=%d", audio, video);
Andreas Huber84066782011-08-16 09:34:26 -07001668
Chong Zhangced1c2f2014-08-08 15:22:35 -07001669 mDeferredActions.push_back(
Wei Jiafef808d2014-10-31 17:57:05 -07001670 new FlushDecoderAction(
1671 audio ? FLUSH_CMD_SHUTDOWN : FLUSH_CMD_NONE,
1672 video ? FLUSH_CMD_SHUTDOWN : FLUSH_CMD_NONE));
Andreas Huber84066782011-08-16 09:34:26 -07001673
Chong Zhangced1c2f2014-08-08 15:22:35 -07001674 mDeferredActions.push_back(
1675 new SimpleAction(&NuPlayer::performScanSources));
Andreas Huber84066782011-08-16 09:34:26 -07001676
Chong Zhangced1c2f2014-08-08 15:22:35 -07001677 mDeferredActions.push_back(new PostMessageAction(reply));
1678
1679 processDeferredActions();
Andreas Huber84066782011-08-16 09:34:26 -07001680}
1681
James Dong0d268a32012-08-31 12:18:27 -07001682status_t NuPlayer::setVideoScalingMode(int32_t mode) {
1683 mVideoScalingMode = mode;
Lajos Molnar1de1e252015-04-30 18:18:34 -07001684 if (mSurface != NULL) {
1685 status_t ret = native_window_set_scaling_mode(mSurface.get(), mVideoScalingMode);
James Dong0d268a32012-08-31 12:18:27 -07001686 if (ret != OK) {
1687 ALOGE("Failed to set scaling mode (%d): %s",
1688 -ret, strerror(-ret));
1689 return ret;
1690 }
1691 }
1692 return OK;
1693}
1694
Chong Zhangdcb89b32013-08-06 09:44:47 -07001695status_t NuPlayer::getTrackInfo(Parcel* reply) const {
Lajos Molnar1d15ab52015-03-04 16:46:34 -08001696 sp<AMessage> msg = new AMessage(kWhatGetTrackInfo, this);
Chong Zhangdcb89b32013-08-06 09:44:47 -07001697 msg->setPointer("reply", reply);
1698
1699 sp<AMessage> response;
1700 status_t err = msg->postAndAwaitResponse(&response);
1701 return err;
1702}
1703
Robert Shih7c4f0d72014-07-09 18:53:31 -07001704status_t NuPlayer::getSelectedTrack(int32_t type, Parcel* reply) const {
Lajos Molnar1d15ab52015-03-04 16:46:34 -08001705 sp<AMessage> msg = new AMessage(kWhatGetSelectedTrack, this);
Robert Shih7c4f0d72014-07-09 18:53:31 -07001706 msg->setPointer("reply", reply);
1707 msg->setInt32("type", type);
1708
1709 sp<AMessage> response;
1710 status_t err = msg->postAndAwaitResponse(&response);
1711 if (err == OK && response != NULL) {
1712 CHECK(response->findInt32("err", &err));
1713 }
1714 return err;
1715}
1716
Robert Shih6ffb1fd2014-10-29 16:24:32 -07001717status_t NuPlayer::selectTrack(size_t trackIndex, bool select, int64_t timeUs) {
Lajos Molnar1d15ab52015-03-04 16:46:34 -08001718 sp<AMessage> msg = new AMessage(kWhatSelectTrack, this);
Chong Zhangdcb89b32013-08-06 09:44:47 -07001719 msg->setSize("trackIndex", trackIndex);
1720 msg->setInt32("select", select);
Robert Shih6ffb1fd2014-10-29 16:24:32 -07001721 msg->setInt64("timeUs", timeUs);
Chong Zhangdcb89b32013-08-06 09:44:47 -07001722
1723 sp<AMessage> response;
1724 status_t err = msg->postAndAwaitResponse(&response);
1725
Chong Zhang404fced2014-06-11 14:45:31 -07001726 if (err != OK) {
1727 return err;
1728 }
1729
1730 if (!response->findInt32("err", &err)) {
1731 err = OK;
1732 }
1733
Chong Zhangdcb89b32013-08-06 09:44:47 -07001734 return err;
1735}
1736
Ronghua Wua73d9e02014-10-08 15:13:29 -07001737status_t NuPlayer::getCurrentPosition(int64_t *mediaUs) {
1738 sp<Renderer> renderer = mRenderer;
1739 if (renderer == NULL) {
1740 return NO_INIT;
1741 }
1742
1743 return renderer->getCurrentPosition(mediaUs);
1744}
1745
Praveen Chavane1e5d7a2015-05-19 19:09:48 -07001746void NuPlayer::getStats(Vector<sp<AMessage> > *mTrackStats) {
1747 CHECK(mTrackStats != NULL);
1748
1749 mTrackStats->clear();
1750 if (mVideoDecoder != NULL) {
1751 mTrackStats->push_back(mVideoDecoder->getStats());
1752 }
1753 if (mAudioDecoder != NULL) {
1754 mTrackStats->push_back(mAudioDecoder->getStats());
Chong Zhang7137ec72014-11-12 16:41:05 -08001755 }
Ronghua Wua73d9e02014-10-08 15:13:29 -07001756}
1757
Marco Nelissenf0b72b52014-09-16 15:43:44 -07001758sp<MetaData> NuPlayer::getFileMeta() {
1759 return mSource->getFileFormatMeta();
1760}
1761
Ronghua Wuc8a70d32015-04-29 16:26:34 -07001762float NuPlayer::getFrameRate() {
1763 sp<MetaData> meta = mSource->getFormatMeta(false /* audio */);
1764 if (meta == NULL) {
1765 return 0;
1766 }
1767 int32_t rate;
1768 if (!meta->findInt32(kKeyFrameRate, &rate)) {
1769 // fall back to try file meta
1770 sp<MetaData> fileMeta = getFileMeta();
1771 if (fileMeta == NULL) {
1772 ALOGW("source has video meta but not file meta");
1773 return -1;
1774 }
1775 int32_t fileMetaRate;
1776 if (!fileMeta->findInt32(kKeyFrameRate, &fileMetaRate)) {
1777 return -1;
1778 }
1779 return fileMetaRate;
1780 }
1781 return rate;
1782}
1783
Andreas Huberb7c8e912012-11-27 15:02:53 -08001784void NuPlayer::schedulePollDuration() {
Lajos Molnar1d15ab52015-03-04 16:46:34 -08001785 sp<AMessage> msg = new AMessage(kWhatPollDuration, this);
Andreas Huberb7c8e912012-11-27 15:02:53 -08001786 msg->setInt32("generation", mPollDurationGeneration);
1787 msg->post();
1788}
1789
1790void NuPlayer::cancelPollDuration() {
1791 ++mPollDurationGeneration;
1792}
1793
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001794void NuPlayer::processDeferredActions() {
1795 while (!mDeferredActions.empty()) {
1796 // We won't execute any deferred actions until we're no longer in
1797 // an intermediate state, i.e. one more more decoders are currently
1798 // flushing or shutting down.
1799
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001800 if (mFlushingAudio != NONE || mFlushingVideo != NONE) {
1801 // We're currently flushing, postpone the reset until that's
1802 // completed.
1803
1804 ALOGV("postponing action mFlushingAudio=%d, mFlushingVideo=%d",
1805 mFlushingAudio, mFlushingVideo);
1806
1807 break;
1808 }
1809
1810 sp<Action> action = *mDeferredActions.begin();
1811 mDeferredActions.erase(mDeferredActions.begin());
1812
1813 action->execute(this);
1814 }
1815}
1816
Wei Jia29840802015-05-15 17:11:38 -07001817void NuPlayer::performSeek(int64_t seekTimeUs) {
1818 ALOGV("performSeek seekTimeUs=%lld us (%.2f secs)",
Lajos Molnar6d339f12015-04-17 16:15:53 -07001819 (long long)seekTimeUs,
Wei Jia29840802015-05-15 17:11:38 -07001820 seekTimeUs / 1E6);
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001821
Andy Hungadf34bf2014-09-03 18:22:22 -07001822 if (mSource == NULL) {
1823 // This happens when reset occurs right before the loop mode
1824 // asynchronously seeks to the start of the stream.
1825 LOG_ALWAYS_FATAL_IF(mAudioDecoder != NULL || mVideoDecoder != NULL,
1826 "mSource is NULL and decoders not NULL audio(%p) video(%p)",
1827 mAudioDecoder.get(), mVideoDecoder.get());
1828 return;
1829 }
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001830 mSource->seekTo(seekTimeUs);
Robert Shihd3b0bbb2014-07-23 15:00:25 -07001831 ++mTimedTextGeneration;
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001832
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001833 // everything's flushed, continue playback.
1834}
1835
Wei Jiafef808d2014-10-31 17:57:05 -07001836void NuPlayer::performDecoderFlush(FlushCommand audio, FlushCommand video) {
1837 ALOGV("performDecoderFlush audio=%d, video=%d", audio, video);
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001838
Wei Jiafef808d2014-10-31 17:57:05 -07001839 if ((audio == FLUSH_CMD_NONE || mAudioDecoder == NULL)
1840 && (video == FLUSH_CMD_NONE || mVideoDecoder == NULL)) {
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001841 return;
1842 }
1843
Wei Jiafef808d2014-10-31 17:57:05 -07001844 if (audio != FLUSH_CMD_NONE && mAudioDecoder != NULL) {
1845 flushDecoder(true /* audio */, (audio == FLUSH_CMD_SHUTDOWN));
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001846 }
1847
Wei Jiafef808d2014-10-31 17:57:05 -07001848 if (video != FLUSH_CMD_NONE && mVideoDecoder != NULL) {
1849 flushDecoder(false /* audio */, (video == FLUSH_CMD_SHUTDOWN));
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001850 }
1851}
1852
1853void NuPlayer::performReset() {
1854 ALOGV("performReset");
1855
1856 CHECK(mAudioDecoder == NULL);
1857 CHECK(mVideoDecoder == NULL);
1858
1859 cancelPollDuration();
1860
1861 ++mScanSourcesGeneration;
1862 mScanSourcesPending = false;
1863
Lajos Molnar09524832014-07-17 14:29:51 -07001864 if (mRendererLooper != NULL) {
1865 if (mRenderer != NULL) {
1866 mRendererLooper->unregisterHandler(mRenderer->id());
1867 }
1868 mRendererLooper->stop();
1869 mRendererLooper.clear();
1870 }
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001871 mRenderer.clear();
Wei Jia57568df2014-09-22 10:16:29 -07001872 ++mRendererGeneration;
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001873
1874 if (mSource != NULL) {
1875 mSource->stop();
Andreas Huberb5f25f02013-02-05 10:14:26 -08001876
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001877 mSource.clear();
1878 }
1879
1880 if (mDriver != NULL) {
1881 sp<NuPlayerDriver> driver = mDriver.promote();
1882 if (driver != NULL) {
1883 driver->notifyResetComplete();
1884 }
1885 }
Andreas Huber57a339c2012-12-03 11:18:00 -08001886
1887 mStarted = false;
Robert Shih0c61a0d2015-07-06 15:09:10 -07001888 mSourceStarted = false;
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001889}
1890
1891void NuPlayer::performScanSources() {
1892 ALOGV("performScanSources");
1893
Andreas Huber57a339c2012-12-03 11:18:00 -08001894 if (!mStarted) {
1895 return;
1896 }
1897
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001898 if (mAudioDecoder == NULL || mVideoDecoder == NULL) {
1899 postScanSources();
1900 }
1901}
1902
Lajos Molnar1de1e252015-04-30 18:18:34 -07001903void NuPlayer::performSetSurface(const sp<Surface> &surface) {
Andreas Huber57a339c2012-12-03 11:18:00 -08001904 ALOGV("performSetSurface");
1905
Lajos Molnar1de1e252015-04-30 18:18:34 -07001906 mSurface = surface;
Andreas Huber57a339c2012-12-03 11:18:00 -08001907
1908 // XXX - ignore error from setVideoScalingMode for now
1909 setVideoScalingMode(mVideoScalingMode);
Chong Zhang13d6faa2014-08-22 15:35:28 -07001910
1911 if (mDriver != NULL) {
1912 sp<NuPlayerDriver> driver = mDriver.promote();
1913 if (driver != NULL) {
1914 driver->notifySetSurfaceComplete();
1915 }
1916 }
Andreas Huber57a339c2012-12-03 11:18:00 -08001917}
1918
Chong Zhangf8d71772014-11-26 15:08:34 -08001919void NuPlayer::performResumeDecoders(bool needNotify) {
1920 if (needNotify) {
1921 mResumePending = true;
1922 if (mVideoDecoder == NULL) {
1923 // if audio-only, we can notify seek complete now,
1924 // as the resume operation will be relatively fast.
1925 finishResume();
1926 }
1927 }
1928
Chong Zhang7137ec72014-11-12 16:41:05 -08001929 if (mVideoDecoder != NULL) {
Chong Zhangf8d71772014-11-26 15:08:34 -08001930 // When there is continuous seek, MediaPlayer will cache the seek
1931 // position, and send down new seek request when previous seek is
1932 // complete. Let's wait for at least one video output frame before
1933 // notifying seek complete, so that the video thumbnail gets updated
1934 // when seekbar is dragged.
1935 mVideoDecoder->signalResume(needNotify);
Chong Zhang7137ec72014-11-12 16:41:05 -08001936 }
1937
1938 if (mAudioDecoder != NULL) {
Chong Zhangf8d71772014-11-26 15:08:34 -08001939 mAudioDecoder->signalResume(false /* needNotify */);
1940 }
1941}
1942
1943void NuPlayer::finishResume() {
1944 if (mResumePending) {
1945 mResumePending = false;
Wei Jia1061c9c2015-05-19 16:02:17 -07001946 notifyDriverSeekComplete();
1947 }
1948}
1949
1950void NuPlayer::notifyDriverSeekComplete() {
1951 if (mDriver != NULL) {
1952 sp<NuPlayerDriver> driver = mDriver.promote();
1953 if (driver != NULL) {
1954 driver->notifySeekComplete();
Chong Zhangf8d71772014-11-26 15:08:34 -08001955 }
Chong Zhang7137ec72014-11-12 16:41:05 -08001956 }
1957}
1958
Andreas Huber9575c962013-02-05 13:59:56 -08001959void NuPlayer::onSourceNotify(const sp<AMessage> &msg) {
1960 int32_t what;
1961 CHECK(msg->findInt32("what", &what));
1962
1963 switch (what) {
Lajos Molnarfcd3e942015-03-31 10:06:48 -07001964 case Source::kWhatInstantiateSecureDecoders:
1965 {
1966 if (mSource == NULL) {
1967 // This is a stale notification from a source that was
1968 // asynchronously preparing when the client called reset().
1969 // We handled the reset, the source is gone.
1970 break;
1971 }
1972
1973 sp<AMessage> reply;
1974 CHECK(msg->findMessage("reply", &reply));
1975 status_t err = onInstantiateSecureDecoders();
1976 reply->setInt32("err", err);
1977 reply->post();
1978 break;
1979 }
1980
Andreas Huber9575c962013-02-05 13:59:56 -08001981 case Source::kWhatPrepared:
1982 {
Andreas Huberb5f28d42013-04-25 15:11:19 -07001983 if (mSource == NULL) {
1984 // This is a stale notification from a source that was
1985 // asynchronously preparing when the client called reset().
1986 // We handled the reset, the source is gone.
1987 break;
1988 }
1989
Andreas Huberec0c5972013-02-05 14:47:13 -08001990 int32_t err;
1991 CHECK(msg->findInt32("err", &err));
1992
Lajos Molnarfcd3e942015-03-31 10:06:48 -07001993 if (err != OK) {
1994 // shut down potential secure codecs in case client never calls reset
1995 mDeferredActions.push_back(
1996 new FlushDecoderAction(FLUSH_CMD_SHUTDOWN /* audio */,
1997 FLUSH_CMD_SHUTDOWN /* video */));
1998 processDeferredActions();
1999 }
2000
Andreas Huber9575c962013-02-05 13:59:56 -08002001 sp<NuPlayerDriver> driver = mDriver.promote();
2002 if (driver != NULL) {
Marco Nelissendd114d12014-05-28 15:23:14 -07002003 // notify duration first, so that it's definitely set when
2004 // the app received the "prepare complete" callback.
2005 int64_t durationUs;
2006 if (mSource->getDuration(&durationUs) == OK) {
2007 driver->notifyDuration(durationUs);
2008 }
Andreas Huberec0c5972013-02-05 14:47:13 -08002009 driver->notifyPrepareCompleted(err);
Andreas Huber9575c962013-02-05 13:59:56 -08002010 }
Andreas Huber99759402013-04-01 14:28:31 -07002011
Andreas Huber9575c962013-02-05 13:59:56 -08002012 break;
2013 }
2014
2015 case Source::kWhatFlagsChanged:
2016 {
2017 uint32_t flags;
2018 CHECK(msg->findInt32("flags", (int32_t *)&flags));
2019
Chong Zhang4b7069d2013-09-11 12:52:43 -07002020 sp<NuPlayerDriver> driver = mDriver.promote();
2021 if (driver != NULL) {
Wei Jia895651b2014-12-10 17:31:52 -08002022 if ((flags & NuPlayer::Source::FLAG_CAN_SEEK) == 0) {
2023 driver->notifyListener(
2024 MEDIA_INFO, MEDIA_INFO_NOT_SEEKABLE, 0);
2025 }
Chong Zhang4b7069d2013-09-11 12:52:43 -07002026 driver->notifyFlagsChanged(flags);
2027 }
2028
Andreas Huber9575c962013-02-05 13:59:56 -08002029 if ((mSourceFlags & Source::FLAG_DYNAMIC_DURATION)
2030 && (!(flags & Source::FLAG_DYNAMIC_DURATION))) {
2031 cancelPollDuration();
2032 } else if (!(mSourceFlags & Source::FLAG_DYNAMIC_DURATION)
2033 && (flags & Source::FLAG_DYNAMIC_DURATION)
2034 && (mAudioDecoder != NULL || mVideoDecoder != NULL)) {
2035 schedulePollDuration();
2036 }
2037
2038 mSourceFlags = flags;
2039 break;
2040 }
2041
2042 case Source::kWhatVideoSizeChanged:
2043 {
Chong Zhangced1c2f2014-08-08 15:22:35 -07002044 sp<AMessage> format;
2045 CHECK(msg->findMessage("format", &format));
Andreas Huber9575c962013-02-05 13:59:56 -08002046
Chong Zhangced1c2f2014-08-08 15:22:35 -07002047 updateVideoSize(format);
Andreas Huber9575c962013-02-05 13:59:56 -08002048 break;
2049 }
2050
Chong Zhang2a3cc9a2014-08-21 17:48:26 -07002051 case Source::kWhatBufferingUpdate:
2052 {
2053 int32_t percentage;
2054 CHECK(msg->findInt32("percentage", &percentage));
2055
2056 notifyListener(MEDIA_BUFFERING_UPDATE, percentage, 0);
2057 break;
2058 }
2059
Chong Zhangefbb6192015-01-30 17:13:27 -08002060 case Source::kWhatPauseOnBufferingStart:
2061 {
2062 // ignore if not playing
Chong Zhang8a048332015-05-06 15:16:28 -07002063 if (mStarted) {
Chong Zhangefbb6192015-01-30 17:13:27 -08002064 ALOGI("buffer low, pausing...");
2065
Chong Zhang8a048332015-05-06 15:16:28 -07002066 mPausedForBuffering = true;
Chong Zhangefbb6192015-01-30 17:13:27 -08002067 onPause();
2068 }
2069 // fall-thru
2070 }
2071
Roger Jönssonb50e83e2013-01-21 16:26:41 +01002072 case Source::kWhatBufferingStart:
2073 {
2074 notifyListener(MEDIA_INFO, MEDIA_INFO_BUFFERING_START, 0);
2075 break;
2076 }
2077
Chong Zhangefbb6192015-01-30 17:13:27 -08002078 case Source::kWhatResumeOnBufferingEnd:
2079 {
2080 // ignore if not playing
Chong Zhang8a048332015-05-06 15:16:28 -07002081 if (mStarted) {
Chong Zhangefbb6192015-01-30 17:13:27 -08002082 ALOGI("buffer ready, resuming...");
2083
Chong Zhang8a048332015-05-06 15:16:28 -07002084 mPausedForBuffering = false;
2085
2086 // do not resume yet if client didn't unpause
2087 if (!mPausedByClient) {
2088 onResume();
2089 }
Chong Zhangefbb6192015-01-30 17:13:27 -08002090 }
2091 // fall-thru
2092 }
2093
Roger Jönssonb50e83e2013-01-21 16:26:41 +01002094 case Source::kWhatBufferingEnd:
2095 {
2096 notifyListener(MEDIA_INFO, MEDIA_INFO_BUFFERING_END, 0);
2097 break;
2098 }
2099
Chong Zhangefbb6192015-01-30 17:13:27 -08002100 case Source::kWhatCacheStats:
2101 {
2102 int32_t kbps;
2103 CHECK(msg->findInt32("bandwidth", &kbps));
2104
2105 notifyListener(MEDIA_INFO, MEDIA_INFO_NETWORK_BANDWIDTH, kbps);
2106 break;
2107 }
2108
Chong Zhangdcb89b32013-08-06 09:44:47 -07002109 case Source::kWhatSubtitleData:
2110 {
2111 sp<ABuffer> buffer;
2112 CHECK(msg->findBuffer("buffer", &buffer));
2113
Chong Zhang404fced2014-06-11 14:45:31 -07002114 sendSubtitleData(buffer, 0 /* baseIndex */);
Chong Zhangdcb89b32013-08-06 09:44:47 -07002115 break;
2116 }
2117
Robert Shih08528432015-04-08 09:06:54 -07002118 case Source::kWhatTimedMetaData:
2119 {
2120 sp<ABuffer> buffer;
2121 if (!msg->findBuffer("buffer", &buffer)) {
2122 notifyListener(MEDIA_INFO, MEDIA_INFO_METADATA_UPDATE, 0);
2123 } else {
2124 sendTimedMetaData(buffer);
2125 }
2126 break;
2127 }
2128
Robert Shihd3b0bbb2014-07-23 15:00:25 -07002129 case Source::kWhatTimedTextData:
2130 {
2131 int32_t generation;
2132 if (msg->findInt32("generation", &generation)
2133 && generation != mTimedTextGeneration) {
2134 break;
2135 }
2136
2137 sp<ABuffer> buffer;
2138 CHECK(msg->findBuffer("buffer", &buffer));
2139
2140 sp<NuPlayerDriver> driver = mDriver.promote();
2141 if (driver == NULL) {
2142 break;
2143 }
2144
2145 int posMs;
2146 int64_t timeUs, posUs;
2147 driver->getCurrentPosition(&posMs);
2148 posUs = posMs * 1000;
2149 CHECK(buffer->meta()->findInt64("timeUs", &timeUs));
2150
2151 if (posUs < timeUs) {
2152 if (!msg->findInt32("generation", &generation)) {
2153 msg->setInt32("generation", mTimedTextGeneration);
2154 }
2155 msg->post(timeUs - posUs);
2156 } else {
2157 sendTimedTextData(buffer);
2158 }
2159 break;
2160 }
2161
Andreas Huber14f76722013-01-15 09:04:18 -08002162 case Source::kWhatQueueDecoderShutdown:
2163 {
2164 int32_t audio, video;
2165 CHECK(msg->findInt32("audio", &audio));
2166 CHECK(msg->findInt32("video", &video));
2167
2168 sp<AMessage> reply;
2169 CHECK(msg->findMessage("reply", &reply));
2170
2171 queueDecoderShutdown(audio, video, reply);
2172 break;
2173 }
2174
Ronghua Wu80276872014-08-28 15:50:29 -07002175 case Source::kWhatDrmNoLicense:
2176 {
2177 notifyListener(MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, ERROR_DRM_NO_LICENSE);
2178 break;
2179 }
2180
Andreas Huber9575c962013-02-05 13:59:56 -08002181 default:
2182 TRESPASS();
2183 }
2184}
2185
Chong Zhanga7fa1d92014-06-11 14:49:23 -07002186void NuPlayer::onClosedCaptionNotify(const sp<AMessage> &msg) {
2187 int32_t what;
2188 CHECK(msg->findInt32("what", &what));
2189
2190 switch (what) {
2191 case NuPlayer::CCDecoder::kWhatClosedCaptionData:
2192 {
2193 sp<ABuffer> buffer;
2194 CHECK(msg->findBuffer("buffer", &buffer));
2195
2196 size_t inbandTracks = 0;
2197 if (mSource != NULL) {
2198 inbandTracks = mSource->getTrackCount();
2199 }
2200
2201 sendSubtitleData(buffer, inbandTracks);
2202 break;
2203 }
2204
2205 case NuPlayer::CCDecoder::kWhatTrackAdded:
2206 {
2207 notifyListener(MEDIA_INFO, MEDIA_INFO_METADATA_UPDATE, 0);
2208
2209 break;
2210 }
2211
2212 default:
2213 TRESPASS();
2214 }
2215
2216
2217}
2218
Chong Zhang404fced2014-06-11 14:45:31 -07002219void NuPlayer::sendSubtitleData(const sp<ABuffer> &buffer, int32_t baseIndex) {
2220 int32_t trackIndex;
2221 int64_t timeUs, durationUs;
2222 CHECK(buffer->meta()->findInt32("trackIndex", &trackIndex));
2223 CHECK(buffer->meta()->findInt64("timeUs", &timeUs));
2224 CHECK(buffer->meta()->findInt64("durationUs", &durationUs));
2225
2226 Parcel in;
2227 in.writeInt32(trackIndex + baseIndex);
2228 in.writeInt64(timeUs);
2229 in.writeInt64(durationUs);
2230 in.writeInt32(buffer->size());
2231 in.writeInt32(buffer->size());
2232 in.write(buffer->data(), buffer->size());
2233
2234 notifyListener(MEDIA_SUBTITLE_DATA, 0, 0, &in);
2235}
Robert Shihd3b0bbb2014-07-23 15:00:25 -07002236
Robert Shih08528432015-04-08 09:06:54 -07002237void NuPlayer::sendTimedMetaData(const sp<ABuffer> &buffer) {
2238 int64_t timeUs;
2239 CHECK(buffer->meta()->findInt64("timeUs", &timeUs));
2240
2241 Parcel in;
2242 in.writeInt64(timeUs);
2243 in.writeInt32(buffer->size());
2244 in.writeInt32(buffer->size());
2245 in.write(buffer->data(), buffer->size());
2246
2247 notifyListener(MEDIA_META_DATA, 0, 0, &in);
2248}
2249
Robert Shihd3b0bbb2014-07-23 15:00:25 -07002250void NuPlayer::sendTimedTextData(const sp<ABuffer> &buffer) {
2251 const void *data;
2252 size_t size = 0;
2253 int64_t timeUs;
2254 int32_t flag = TextDescriptions::LOCAL_DESCRIPTIONS;
2255
2256 AString mime;
2257 CHECK(buffer->meta()->findString("mime", &mime));
2258 CHECK(strcasecmp(mime.c_str(), MEDIA_MIMETYPE_TEXT_3GPP) == 0);
2259
2260 data = buffer->data();
2261 size = buffer->size();
2262
2263 Parcel parcel;
2264 if (size > 0) {
2265 CHECK(buffer->meta()->findInt64("timeUs", &timeUs));
2266 flag |= TextDescriptions::IN_BAND_TEXT_3GPP;
2267 TextDescriptions::getParcelOfDescriptions(
2268 (const uint8_t *)data, size, flag, timeUs / 1000, &parcel);
2269 }
2270
2271 if ((parcel.dataSize() > 0)) {
2272 notifyListener(MEDIA_TIMED_TEXT, 0, 0, &parcel);
2273 } else { // send an empty timed text
2274 notifyListener(MEDIA_TIMED_TEXT, 0, 0);
2275 }
2276}
Andreas Huberb5f25f02013-02-05 10:14:26 -08002277////////////////////////////////////////////////////////////////////////////////
2278
Chong Zhangced1c2f2014-08-08 15:22:35 -07002279sp<AMessage> NuPlayer::Source::getFormat(bool audio) {
2280 sp<MetaData> meta = getFormatMeta(audio);
2281
2282 if (meta == NULL) {
2283 return NULL;
2284 }
2285
2286 sp<AMessage> msg = new AMessage;
2287
2288 if(convertMetaDataToMessage(meta, &msg) == OK) {
2289 return msg;
2290 }
2291 return NULL;
2292}
2293
Andreas Huber9575c962013-02-05 13:59:56 -08002294void NuPlayer::Source::notifyFlagsChanged(uint32_t flags) {
2295 sp<AMessage> notify = dupNotify();
2296 notify->setInt32("what", kWhatFlagsChanged);
2297 notify->setInt32("flags", flags);
2298 notify->post();
2299}
2300
Chong Zhangced1c2f2014-08-08 15:22:35 -07002301void NuPlayer::Source::notifyVideoSizeChanged(const sp<AMessage> &format) {
Andreas Huber9575c962013-02-05 13:59:56 -08002302 sp<AMessage> notify = dupNotify();
2303 notify->setInt32("what", kWhatVideoSizeChanged);
Chong Zhangced1c2f2014-08-08 15:22:35 -07002304 notify->setMessage("format", format);
Andreas Huber9575c962013-02-05 13:59:56 -08002305 notify->post();
2306}
2307
Andreas Huberec0c5972013-02-05 14:47:13 -08002308void NuPlayer::Source::notifyPrepared(status_t err) {
Andreas Huber9575c962013-02-05 13:59:56 -08002309 sp<AMessage> notify = dupNotify();
2310 notify->setInt32("what", kWhatPrepared);
Andreas Huberec0c5972013-02-05 14:47:13 -08002311 notify->setInt32("err", err);
Andreas Huber9575c962013-02-05 13:59:56 -08002312 notify->post();
2313}
2314
Lajos Molnarfcd3e942015-03-31 10:06:48 -07002315void NuPlayer::Source::notifyInstantiateSecureDecoders(const sp<AMessage> &reply) {
2316 sp<AMessage> notify = dupNotify();
2317 notify->setInt32("what", kWhatInstantiateSecureDecoders);
2318 notify->setMessage("reply", reply);
2319 notify->post();
2320}
2321
Andreas Huber84333e02014-02-07 15:36:10 -08002322void NuPlayer::Source::onMessageReceived(const sp<AMessage> & /* msg */) {
Andreas Huberb5f25f02013-02-05 10:14:26 -08002323 TRESPASS();
2324}
2325
Andreas Huberf9334412010-12-15 15:17:42 -08002326} // namespace android