blob: 3e0ee087442a649e6a8b251a46573165a7b78798 [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 {
Andreas Huberf9334412010-12-15 15:17:42 -0800626
627 sp<RefBase> obj;
Lajos Molnar1de1e252015-04-30 18:18:34 -0700628 CHECK(msg->findObject("surface", &obj));
629 sp<Surface> surface = static_cast<Surface *>(obj.get());
Lajos Molnara81c6222015-07-10 19:17:45 -0700630
631 ALOGD("onSetVideoSurface(%p, %s video decoder)",
632 surface.get(),
633 (mSource != NULL && mSource->getFormat(false /* audio */) != NULL
634 && mVideoDecoder != NULL) ? "have" : "no");
635
636 if (mSource == NULL || mSource->getFormat(false /* audio */) == NULL
637 // NOTE: mVideoDecoder's mSurface is always non-null
638 || (mVideoDecoder != NULL && mVideoDecoder->setVideoSurface(surface) == OK)) {
Lajos Molnar1de1e252015-04-30 18:18:34 -0700639 performSetSurface(surface);
Wei Jiafef808d2014-10-31 17:57:05 -0700640 break;
641 }
642
643 mDeferredActions.push_back(
644 new FlushDecoderAction(FLUSH_CMD_FLUSH /* audio */,
645 FLUSH_CMD_SHUTDOWN /* video */));
646
Lajos Molnar1de1e252015-04-30 18:18:34 -0700647 mDeferredActions.push_back(new SetSurfaceAction(surface));
James Dong0d268a32012-08-31 12:18:27 -0700648
Wei Jiac6e58412015-07-10 18:04:55 -0700649 if (obj != NULL || mAudioDecoder != NULL) {
Wei Jiafef808d2014-10-31 17:57:05 -0700650 if (mStarted) {
Andy Hung73535852014-09-05 11:42:58 -0700651 // Issue a seek to refresh the video screen only if started otherwise
652 // the extractor may not yet be started and will assert.
653 // If the video decoder is not set (perhaps audio only in this case)
654 // do not perform a seek as it is not needed.
Ronghua Wua73d9e02014-10-08 15:13:29 -0700655 int64_t currentPositionUs = 0;
656 if (getCurrentPosition(&currentPositionUs) == OK) {
657 mDeferredActions.push_back(
Wei Jia29840802015-05-15 17:11:38 -0700658 new SeekAction(currentPositionUs));
Ronghua Wua73d9e02014-10-08 15:13:29 -0700659 }
Andy Hung73535852014-09-05 11:42:58 -0700660 }
Wei Jiaac428aa2014-09-02 19:01:34 -0700661
Andreas Huber57a339c2012-12-03 11:18:00 -0800662 // If there is a new surface texture, instantiate decoders
663 // again if possible.
664 mDeferredActions.push_back(
665 new SimpleAction(&NuPlayer::performScanSources));
666 }
667
Chong Zhangf8d71772014-11-26 15:08:34 -0800668 // After a flush without shutdown, decoder is paused.
669 // Don't resume it until source seek is done, otherwise it could
Chong Zhang7137ec72014-11-12 16:41:05 -0800670 // start pulling stale data too soon.
671 mDeferredActions.push_back(
Chong Zhangf8d71772014-11-26 15:08:34 -0800672 new ResumeDecoderAction(false /* needNotify */));
Chong Zhang7137ec72014-11-12 16:41:05 -0800673
Andreas Huber57a339c2012-12-03 11:18:00 -0800674 processDeferredActions();
Andreas Huberf9334412010-12-15 15:17:42 -0800675 break;
676 }
677
678 case kWhatSetAudioSink:
679 {
Steve Block3856b092011-10-20 11:56:00 +0100680 ALOGV("kWhatSetAudioSink");
Andreas Huberf9334412010-12-15 15:17:42 -0800681
682 sp<RefBase> obj;
683 CHECK(msg->findObject("sink", &obj));
684
685 mAudioSink = static_cast<MediaPlayerBase::AudioSink *>(obj.get());
686 break;
687 }
688
689 case kWhatStart:
690 {
Steve Block3856b092011-10-20 11:56:00 +0100691 ALOGV("kWhatStart");
Wei Jia94211742014-10-28 17:09:06 -0700692 if (mStarted) {
Chong Zhang8a048332015-05-06 15:16:28 -0700693 // do not resume yet if the source is still buffering
694 if (!mPausedForBuffering) {
695 onResume();
696 }
Wei Jia94211742014-10-28 17:09:06 -0700697 } else {
698 onStart();
Lajos Molnar09524832014-07-17 14:29:51 -0700699 }
Chong Zhangefbb6192015-01-30 17:13:27 -0800700 mPausedByClient = false;
Andreas Huberf9334412010-12-15 15:17:42 -0800701 break;
702 }
703
Lajos Molnar3a474aa2015-04-24 17:10:07 -0700704 case kWhatConfigPlayback:
Wei Jia98160162015-02-04 17:01:11 -0800705 {
Lajos Molnar3a474aa2015-04-24 17:10:07 -0700706 sp<AReplyToken> replyID;
707 CHECK(msg->senderAwaitsResponse(&replyID));
708 AudioPlaybackRate rate /* sanitized */;
709 readFromAMessage(msg, &rate);
710 status_t err = OK;
Wei Jia98160162015-02-04 17:01:11 -0800711 if (mRenderer != NULL) {
Lajos Molnar3a474aa2015-04-24 17:10:07 -0700712 err = mRenderer->setPlaybackSettings(rate);
713 }
714 if (err == OK) {
715 if (rate.mSpeed == 0.f) {
716 onPause();
717 // save all other settings (using non-paused speed)
718 // so we can restore them on start
719 AudioPlaybackRate newRate = rate;
720 newRate.mSpeed = mPlaybackSettings.mSpeed;
721 mPlaybackSettings = newRate;
722 } else { /* rate.mSpeed != 0.f */
723 onResume();
724 mPlaybackSettings = rate;
725 }
Wei Jia98160162015-02-04 17:01:11 -0800726 }
Ronghua Wu8db88132015-04-22 13:51:35 -0700727
728 if (mVideoDecoder != NULL) {
Ronghua Wuc8a70d32015-04-29 16:26:34 -0700729 float rate = getFrameRate();
730 if (rate > 0) {
Ronghua Wu8db88132015-04-22 13:51:35 -0700731 sp<AMessage> params = new AMessage();
Lajos Molnar3a474aa2015-04-24 17:10:07 -0700732 params->setFloat("operating-rate", rate * mPlaybackSettings.mSpeed);
Ronghua Wu8db88132015-04-22 13:51:35 -0700733 mVideoDecoder->setParameters(params);
734 }
735 }
736
Lajos Molnar3a474aa2015-04-24 17:10:07 -0700737 sp<AMessage> response = new AMessage;
738 response->setInt32("err", err);
739 response->postReply(replyID);
740 break;
741 }
742
743 case kWhatGetPlaybackSettings:
744 {
745 sp<AReplyToken> replyID;
746 CHECK(msg->senderAwaitsResponse(&replyID));
747 AudioPlaybackRate rate = mPlaybackSettings;
748 status_t err = OK;
749 if (mRenderer != NULL) {
750 err = mRenderer->getPlaybackSettings(&rate);
751 }
752 if (err == OK) {
753 // get playback settings used by renderer, as it may be
754 // slightly off due to audiosink not taking small changes.
755 mPlaybackSettings = rate;
756 if (mPaused) {
757 rate.mSpeed = 0.f;
758 }
759 }
760 sp<AMessage> response = new AMessage;
761 if (err == OK) {
762 writeToAMessage(response, rate);
763 }
764 response->setInt32("err", err);
765 response->postReply(replyID);
766 break;
767 }
768
769 case kWhatConfigSync:
770 {
771 sp<AReplyToken> replyID;
772 CHECK(msg->senderAwaitsResponse(&replyID));
773
774 ALOGV("kWhatConfigSync");
775 AVSyncSettings sync;
776 float videoFpsHint;
777 readFromAMessage(msg, &sync, &videoFpsHint);
778 status_t err = OK;
779 if (mRenderer != NULL) {
780 err = mRenderer->setSyncSettings(sync, videoFpsHint);
781 }
782 if (err == OK) {
783 mSyncSettings = sync;
784 mVideoFpsHint = videoFpsHint;
785 }
786 sp<AMessage> response = new AMessage;
787 response->setInt32("err", err);
788 response->postReply(replyID);
789 break;
790 }
791
792 case kWhatGetSyncSettings:
793 {
794 sp<AReplyToken> replyID;
795 CHECK(msg->senderAwaitsResponse(&replyID));
796 AVSyncSettings sync = mSyncSettings;
797 float videoFps = mVideoFpsHint;
798 status_t err = OK;
799 if (mRenderer != NULL) {
800 err = mRenderer->getSyncSettings(&sync, &videoFps);
801 if (err == OK) {
802 mSyncSettings = sync;
803 mVideoFpsHint = videoFps;
804 }
805 }
806 sp<AMessage> response = new AMessage;
807 if (err == OK) {
808 writeToAMessage(response, sync, videoFps);
809 }
810 response->setInt32("err", err);
811 response->postReply(replyID);
Wei Jia98160162015-02-04 17:01:11 -0800812 break;
813 }
814
Andreas Huberf9334412010-12-15 15:17:42 -0800815 case kWhatScanSources:
816 {
Andreas Huber1aef2112011-01-04 14:01:29 -0800817 int32_t generation;
818 CHECK(msg->findInt32("generation", &generation));
819 if (generation != mScanSourcesGeneration) {
820 // Drop obsolete msg.
821 break;
822 }
823
Andreas Huber5bc087c2010-12-23 10:27:40 -0800824 mScanSourcesPending = false;
825
Steve Block3856b092011-10-20 11:56:00 +0100826 ALOGV("scanning sources haveAudio=%d, haveVideo=%d",
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800827 mAudioDecoder != NULL, mVideoDecoder != NULL);
828
Andreas Huberb7c8e912012-11-27 15:02:53 -0800829 bool mHadAnySourcesBefore =
830 (mAudioDecoder != NULL) || (mVideoDecoder != NULL);
831
Andy Hung282a7e32014-08-14 15:56:34 -0700832 // initialize video before audio because successful initialization of
833 // video may change deep buffer mode of audio.
Lajos Molnar1de1e252015-04-30 18:18:34 -0700834 if (mSurface != NULL) {
Haynes Mathew George5d246ef2012-07-09 10:36:57 -0700835 instantiateDecoder(false, &mVideoDecoder);
836 }
Andreas Huberf9334412010-12-15 15:17:42 -0800837
Ronghua Wua10fd232014-11-06 16:15:20 -0800838 // Don't try to re-open audio sink if there's an existing decoder.
839 if (mAudioSink != NULL && mAudioDecoder == NULL) {
Andreas Huber5bc087c2010-12-23 10:27:40 -0800840 instantiateDecoder(true, &mAudioDecoder);
Andreas Huberf9334412010-12-15 15:17:42 -0800841 }
842
Andreas Huberb7c8e912012-11-27 15:02:53 -0800843 if (!mHadAnySourcesBefore
844 && (mAudioDecoder != NULL || mVideoDecoder != NULL)) {
845 // This is the first time we've found anything playable.
846
Andreas Huber9575c962013-02-05 13:59:56 -0800847 if (mSourceFlags & Source::FLAG_DYNAMIC_DURATION) {
Andreas Huberb7c8e912012-11-27 15:02:53 -0800848 schedulePollDuration();
849 }
850 }
851
Andreas Hubereac68ba2011-09-27 12:12:25 -0700852 status_t err;
853 if ((err = mSource->feedMoreTSData()) != OK) {
Andreas Huber1aef2112011-01-04 14:01:29 -0800854 if (mAudioDecoder == NULL && mVideoDecoder == NULL) {
855 // We're not currently decoding anything (no audio or
856 // video tracks found) and we just ran out of input data.
Andreas Hubereac68ba2011-09-27 12:12:25 -0700857
858 if (err == ERROR_END_OF_STREAM) {
859 notifyListener(MEDIA_PLAYBACK_COMPLETE, 0, 0);
860 } else {
861 notifyListener(MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, err);
862 }
Andreas Huber1aef2112011-01-04 14:01:29 -0800863 }
Andreas Huberf9334412010-12-15 15:17:42 -0800864 break;
865 }
866
Andreas Huberfbe9d812012-08-31 14:05:27 -0700867 if ((mAudioDecoder == NULL && mAudioSink != NULL)
Lajos Molnar1de1e252015-04-30 18:18:34 -0700868 || (mVideoDecoder == NULL && mSurface != NULL)) {
Andreas Huberf9334412010-12-15 15:17:42 -0800869 msg->post(100000ll);
Andreas Huber5bc087c2010-12-23 10:27:40 -0800870 mScanSourcesPending = true;
Andreas Huberf9334412010-12-15 15:17:42 -0800871 }
872 break;
873 }
874
875 case kWhatVideoNotify:
876 case kWhatAudioNotify:
877 {
878 bool audio = msg->what() == kWhatAudioNotify;
879
Wei Jia88703c32014-08-06 11:24:07 -0700880 int32_t currentDecoderGeneration =
881 (audio? mAudioDecoderGeneration : mVideoDecoderGeneration);
882 int32_t requesterGeneration = currentDecoderGeneration - 1;
883 CHECK(msg->findInt32("generation", &requesterGeneration));
884
885 if (requesterGeneration != currentDecoderGeneration) {
886 ALOGV("got message from old %s decoder, generation(%d:%d)",
887 audio ? "audio" : "video", requesterGeneration,
888 currentDecoderGeneration);
889 sp<AMessage> reply;
890 if (!(msg->findMessage("reply", &reply))) {
891 return;
892 }
893
894 reply->setInt32("err", INFO_DISCONTINUITY);
895 reply->post();
896 return;
897 }
898
Andreas Huberf9334412010-12-15 15:17:42 -0800899 int32_t what;
Lajos Molnar1cd13982014-01-17 15:12:51 -0800900 CHECK(msg->findInt32("what", &what));
Andreas Huberf9334412010-12-15 15:17:42 -0800901
Chong Zhang7137ec72014-11-12 16:41:05 -0800902 if (what == DecoderBase::kWhatInputDiscontinuity) {
903 int32_t formatChange;
904 CHECK(msg->findInt32("formatChange", &formatChange));
Andreas Huberf9334412010-12-15 15:17:42 -0800905
Chong Zhang7137ec72014-11-12 16:41:05 -0800906 ALOGV("%s discontinuity: formatChange %d",
907 audio ? "audio" : "video", formatChange);
908
909 if (formatChange) {
910 mDeferredActions.push_back(
911 new FlushDecoderAction(
912 audio ? FLUSH_CMD_SHUTDOWN : FLUSH_CMD_NONE,
913 audio ? FLUSH_CMD_NONE : FLUSH_CMD_SHUTDOWN));
Andreas Huberf9334412010-12-15 15:17:42 -0800914 }
Chong Zhang7137ec72014-11-12 16:41:05 -0800915
916 mDeferredActions.push_back(
917 new SimpleAction(
918 &NuPlayer::performScanSources));
919
920 processDeferredActions();
921 } else if (what == DecoderBase::kWhatEOS) {
Andreas Huberdc9bacd2011-09-26 10:53:29 -0700922 int32_t err;
Lajos Molnar1cd13982014-01-17 15:12:51 -0800923 CHECK(msg->findInt32("err", &err));
Andreas Huberdc9bacd2011-09-26 10:53:29 -0700924
925 if (err == ERROR_END_OF_STREAM) {
Steve Block3856b092011-10-20 11:56:00 +0100926 ALOGV("got %s decoder EOS", audio ? "audio" : "video");
Andreas Huberdc9bacd2011-09-26 10:53:29 -0700927 } else {
Steve Block3856b092011-10-20 11:56:00 +0100928 ALOGV("got %s decoder EOS w/ error %d",
Andreas Huberdc9bacd2011-09-26 10:53:29 -0700929 audio ? "audio" : "video",
930 err);
931 }
932
933 mRenderer->queueEOS(audio, err);
Chong Zhang7137ec72014-11-12 16:41:05 -0800934 } else if (what == DecoderBase::kWhatFlushCompleted) {
Steve Block3856b092011-10-20 11:56:00 +0100935 ALOGV("decoder %s flush completed", audio ? "audio" : "video");
Andreas Huberf9334412010-12-15 15:17:42 -0800936
Andy Hung8d121d42014-10-03 09:53:53 -0700937 handleFlushComplete(audio, true /* isDecoder */);
Andreas Huber3831a062010-12-21 10:22:33 -0800938 finishFlushIfPossible();
Chong Zhang7137ec72014-11-12 16:41:05 -0800939 } else if (what == DecoderBase::kWhatVideoSizeChanged) {
Lajos Molnar1cd13982014-01-17 15:12:51 -0800940 sp<AMessage> format;
941 CHECK(msg->findMessage("format", &format));
942
Wei Jiac6cfd702014-11-11 16:33:20 -0800943 sp<AMessage> inputFormat =
944 mSource->getFormat(false /* audio */);
Andreas Huber3831a062010-12-21 10:22:33 -0800945
Wei Jiac6cfd702014-11-11 16:33:20 -0800946 updateVideoSize(inputFormat, format);
Chong Zhang7137ec72014-11-12 16:41:05 -0800947 } else if (what == DecoderBase::kWhatShutdownCompleted) {
Steve Block3856b092011-10-20 11:56:00 +0100948 ALOGV("%s shutdown completed", audio ? "audio" : "video");
Andreas Huber3831a062010-12-21 10:22:33 -0800949 if (audio) {
950 mAudioDecoder.clear();
Wei Jia57568df2014-09-22 10:16:29 -0700951 ++mAudioDecoderGeneration;
Andreas Huber3831a062010-12-21 10:22:33 -0800952
953 CHECK_EQ((int)mFlushingAudio, (int)SHUTTING_DOWN_DECODER);
954 mFlushingAudio = SHUT_DOWN;
955 } else {
956 mVideoDecoder.clear();
Wei Jia57568df2014-09-22 10:16:29 -0700957 ++mVideoDecoderGeneration;
Andreas Huber3831a062010-12-21 10:22:33 -0800958
959 CHECK_EQ((int)mFlushingVideo, (int)SHUTTING_DOWN_DECODER);
960 mFlushingVideo = SHUT_DOWN;
961 }
962
963 finishFlushIfPossible();
Chong Zhangf8d71772014-11-26 15:08:34 -0800964 } else if (what == DecoderBase::kWhatResumeCompleted) {
965 finishResume();
Chong Zhang7137ec72014-11-12 16:41:05 -0800966 } else if (what == DecoderBase::kWhatError) {
Chong Zhangf4c0a942014-08-11 15:14:10 -0700967 status_t err;
Andy Hung2abde2c2014-09-30 14:40:32 -0700968 if (!msg->findInt32("err", &err) || err == OK) {
Chong Zhangf4c0a942014-08-11 15:14:10 -0700969 err = UNKNOWN_ERROR;
970 }
Andy Hungcf31f1e2014-09-23 14:59:01 -0700971
Andy Hung2abde2c2014-09-30 14:40:32 -0700972 // Decoder errors can be due to Source (e.g. from streaming),
973 // or from decoding corrupted bitstreams, or from other decoder
974 // MediaCodec operations (e.g. from an ongoing reset or seek).
Andy Hung202bce12014-12-03 11:47:36 -0800975 // They may also be due to openAudioSink failure at
976 // decoder start or after a format change.
Andy Hung2abde2c2014-09-30 14:40:32 -0700977 //
978 // We try to gracefully shut down the affected decoder if possible,
979 // rather than trying to force the shutdown with something
980 // similar to performReset(). This method can lead to a hang
981 // if MediaCodec functions block after an error, but they should
982 // typically return INVALID_OPERATION instead of blocking.
983
984 FlushStatus *flushing = audio ? &mFlushingAudio : &mFlushingVideo;
985 ALOGE("received error(%#x) from %s decoder, flushing(%d), now shutting down",
986 err, audio ? "audio" : "video", *flushing);
987
988 switch (*flushing) {
989 case NONE:
990 mDeferredActions.push_back(
Wei Jiafef808d2014-10-31 17:57:05 -0700991 new FlushDecoderAction(
992 audio ? FLUSH_CMD_SHUTDOWN : FLUSH_CMD_NONE,
993 audio ? FLUSH_CMD_NONE : FLUSH_CMD_SHUTDOWN));
Andy Hung2abde2c2014-09-30 14:40:32 -0700994 processDeferredActions();
995 break;
996 case FLUSHING_DECODER:
997 *flushing = FLUSHING_DECODER_SHUTDOWN; // initiate shutdown after flush.
998 break; // Wait for flush to complete.
999 case FLUSHING_DECODER_SHUTDOWN:
1000 break; // Wait for flush to complete.
1001 case SHUTTING_DOWN_DECODER:
1002 break; // Wait for shutdown to complete.
1003 case FLUSHED:
1004 // Widevine source reads must stop before releasing the video decoder.
1005 if (!audio && mSource != NULL && mSourceFlags & Source::FLAG_SECURE) {
1006 mSource->stop();
Robert Shih0c61a0d2015-07-06 15:09:10 -07001007 mSourceStarted = false;
Andy Hung2abde2c2014-09-30 14:40:32 -07001008 }
1009 getDecoder(audio)->initiateShutdown(); // In the middle of a seek.
1010 *flushing = SHUTTING_DOWN_DECODER; // Shut down.
1011 break;
1012 case SHUT_DOWN:
1013 finishFlushIfPossible(); // Should not occur.
1014 break; // Finish anyways.
Marco Nelissen9e2b7912014-08-18 16:13:03 -07001015 }
Andy Hung2abde2c2014-09-30 14:40:32 -07001016 notifyListener(MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, err);
Lajos Molnar1cd13982014-01-17 15:12:51 -08001017 } else {
1018 ALOGV("Unhandled decoder notification %d '%c%c%c%c'.",
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001019 what,
1020 what >> 24,
1021 (what >> 16) & 0xff,
1022 (what >> 8) & 0xff,
1023 what & 0xff);
Andreas Huberf9334412010-12-15 15:17:42 -08001024 }
1025
1026 break;
1027 }
1028
1029 case kWhatRendererNotify:
1030 {
Wei Jia57568df2014-09-22 10:16:29 -07001031 int32_t requesterGeneration = mRendererGeneration - 1;
1032 CHECK(msg->findInt32("generation", &requesterGeneration));
1033 if (requesterGeneration != mRendererGeneration) {
1034 ALOGV("got message from old renderer, generation(%d:%d)",
1035 requesterGeneration, mRendererGeneration);
1036 return;
1037 }
1038
Andreas Huberf9334412010-12-15 15:17:42 -08001039 int32_t what;
1040 CHECK(msg->findInt32("what", &what));
1041
1042 if (what == Renderer::kWhatEOS) {
1043 int32_t audio;
1044 CHECK(msg->findInt32("audio", &audio));
1045
Andreas Huberc92fd242011-08-16 13:48:44 -07001046 int32_t finalResult;
1047 CHECK(msg->findInt32("finalResult", &finalResult));
1048
Andreas Huberf9334412010-12-15 15:17:42 -08001049 if (audio) {
1050 mAudioEOS = true;
1051 } else {
1052 mVideoEOS = true;
1053 }
1054
Andreas Huberc92fd242011-08-16 13:48:44 -07001055 if (finalResult == ERROR_END_OF_STREAM) {
Steve Block3856b092011-10-20 11:56:00 +01001056 ALOGV("reached %s EOS", audio ? "audio" : "video");
Andreas Huberc92fd242011-08-16 13:48:44 -07001057 } else {
Steve Block29357bc2012-01-06 19:20:56 +00001058 ALOGE("%s track encountered an error (%d)",
Andreas Huberc92fd242011-08-16 13:48:44 -07001059 audio ? "audio" : "video", finalResult);
1060
1061 notifyListener(
1062 MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, finalResult);
1063 }
Andreas Huberf9334412010-12-15 15:17:42 -08001064
1065 if ((mAudioEOS || mAudioDecoder == NULL)
1066 && (mVideoEOS || mVideoDecoder == NULL)) {
1067 notifyListener(MEDIA_PLAYBACK_COMPLETE, 0, 0);
1068 }
Andreas Huber3fe62152011-09-16 15:09:22 -07001069 } else if (what == Renderer::kWhatFlushComplete) {
Andreas Huberf9334412010-12-15 15:17:42 -08001070 int32_t audio;
1071 CHECK(msg->findInt32("audio", &audio));
1072
Steve Block3856b092011-10-20 11:56:00 +01001073 ALOGV("renderer %s flush completed.", audio ? "audio" : "video");
Andy Hung8d121d42014-10-03 09:53:53 -07001074 handleFlushComplete(audio, false /* isDecoder */);
1075 finishFlushIfPossible();
James Dongf57b4ea2012-07-20 13:38:36 -07001076 } else if (what == Renderer::kWhatVideoRenderingStart) {
1077 notifyListener(MEDIA_INFO, MEDIA_INFO_RENDERING_START, 0);
Lajos Molnarcbaffcf2013-08-14 18:30:38 -07001078 } else if (what == Renderer::kWhatMediaRenderingStart) {
1079 ALOGV("media rendering started");
1080 notifyListener(MEDIA_STARTED, 0, 0);
Ronghua Wufaeb0f22015-05-21 12:20:21 -07001081 } else if (what == Renderer::kWhatAudioTearDown) {
Wei Jia3a2956d2014-07-22 16:01:33 -07001082 int64_t positionUs;
1083 CHECK(msg->findInt64("positionUs", &positionUs));
Ronghua Wu08529172014-10-02 16:55:52 -07001084 int32_t reason;
1085 CHECK(msg->findInt32("reason", &reason));
Ronghua Wufaeb0f22015-05-21 12:20:21 -07001086 ALOGV("Tear down audio with reason %d.", reason);
Andy Hung282a7e32014-08-14 15:56:34 -07001087 closeAudioSink();
Wei Jia3a2956d2014-07-22 16:01:33 -07001088 mAudioDecoder.clear();
Wei Jia57568df2014-09-22 10:16:29 -07001089 ++mAudioDecoderGeneration;
Chong Zhang7137ec72014-11-12 16:41:05 -08001090 mRenderer->flush(
1091 true /* audio */, false /* notifyComplete */);
Wei Jia3a2956d2014-07-22 16:01:33 -07001092 if (mVideoDecoder != NULL) {
Chong Zhang7137ec72014-11-12 16:41:05 -08001093 mRenderer->flush(
1094 false /* audio */, false /* notifyComplete */);
Wei Jia3a2956d2014-07-22 16:01:33 -07001095 }
Wei Jia3a2956d2014-07-22 16:01:33 -07001096
Wei Jia29840802015-05-15 17:11:38 -07001097 performSeek(positionUs);
Ronghua Wufaeb0f22015-05-21 12:20:21 -07001098
Ronghua Wu08529172014-10-02 16:55:52 -07001099 if (reason == Renderer::kDueToError) {
1100 instantiateDecoder(true /* audio */, &mAudioDecoder);
1101 }
Andreas Huberf9334412010-12-15 15:17:42 -08001102 }
1103 break;
1104 }
1105
1106 case kWhatMoreDataQueued:
1107 {
1108 break;
1109 }
1110
Andreas Huber1aef2112011-01-04 14:01:29 -08001111 case kWhatReset:
1112 {
Steve Block3856b092011-10-20 11:56:00 +01001113 ALOGV("kWhatReset");
Andreas Huber1aef2112011-01-04 14:01:29 -08001114
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001115 mDeferredActions.push_back(
Wei Jiafef808d2014-10-31 17:57:05 -07001116 new FlushDecoderAction(
1117 FLUSH_CMD_SHUTDOWN /* audio */,
1118 FLUSH_CMD_SHUTDOWN /* video */));
Andreas Huberb7c8e912012-11-27 15:02:53 -08001119
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001120 mDeferredActions.push_back(
1121 new SimpleAction(&NuPlayer::performReset));
Andreas Huberb58ce9f2011-11-28 16:27:35 -08001122
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001123 processDeferredActions();
Andreas Huber1aef2112011-01-04 14:01:29 -08001124 break;
1125 }
1126
Andreas Huber43c3e6c2011-01-05 12:17:08 -08001127 case kWhatSeek:
1128 {
1129 int64_t seekTimeUs;
Wei Jiae427abf2014-09-22 15:21:11 -07001130 int32_t needNotify;
Andreas Huber43c3e6c2011-01-05 12:17:08 -08001131 CHECK(msg->findInt64("seekTimeUs", &seekTimeUs));
Wei Jiae427abf2014-09-22 15:21:11 -07001132 CHECK(msg->findInt32("needNotify", &needNotify));
Andreas Huber43c3e6c2011-01-05 12:17:08 -08001133
Wei Jiae427abf2014-09-22 15:21:11 -07001134 ALOGV("kWhatSeek seekTimeUs=%lld us, needNotify=%d",
Lajos Molnar6d339f12015-04-17 16:15:53 -07001135 (long long)seekTimeUs, needNotify);
Andreas Huber43c3e6c2011-01-05 12:17:08 -08001136
Wei Jia1061c9c2015-05-19 16:02:17 -07001137 if (!mStarted) {
1138 // Seek before the player is started. In order to preview video,
1139 // need to start the player and pause it. This branch is called
1140 // only once if needed. After the player is started, any seek
1141 // operation will go through normal path.
Robert Shih0c61a0d2015-07-06 15:09:10 -07001142 // Audio-only cases are handled separately.
Wei Jia1061c9c2015-05-19 16:02:17 -07001143 onStart(seekTimeUs);
Robert Shih0c61a0d2015-07-06 15:09:10 -07001144 if (mStarted) {
1145 onPause();
1146 mPausedByClient = true;
1147 }
Wei Jia1061c9c2015-05-19 16:02:17 -07001148 if (needNotify) {
1149 notifyDriverSeekComplete();
1150 }
1151 break;
1152 }
1153
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001154 mDeferredActions.push_back(
Wei Jiafef808d2014-10-31 17:57:05 -07001155 new FlushDecoderAction(FLUSH_CMD_FLUSH /* audio */,
1156 FLUSH_CMD_FLUSH /* video */));
Andreas Huber43c3e6c2011-01-05 12:17:08 -08001157
Wei Jiae427abf2014-09-22 15:21:11 -07001158 mDeferredActions.push_back(
Wei Jia29840802015-05-15 17:11:38 -07001159 new SeekAction(seekTimeUs));
Andreas Huber43c3e6c2011-01-05 12:17:08 -08001160
Chong Zhangf8d71772014-11-26 15:08:34 -08001161 // After a flush without shutdown, decoder is paused.
1162 // Don't resume it until source seek is done, otherwise it could
Chong Zhang7137ec72014-11-12 16:41:05 -08001163 // start pulling stale data too soon.
1164 mDeferredActions.push_back(
Chong Zhangf8d71772014-11-26 15:08:34 -08001165 new ResumeDecoderAction(needNotify));
Chong Zhang7137ec72014-11-12 16:41:05 -08001166
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001167 processDeferredActions();
Andreas Huber43c3e6c2011-01-05 12:17:08 -08001168 break;
1169 }
1170
Andreas Huberb4082222011-01-20 15:23:04 -08001171 case kWhatPause:
1172 {
Chong Zhangefbb6192015-01-30 17:13:27 -08001173 onPause();
1174 mPausedByClient = true;
Andreas Huberb4082222011-01-20 15:23:04 -08001175 break;
1176 }
1177
Andreas Huberb5f25f02013-02-05 10:14:26 -08001178 case kWhatSourceNotify:
1179 {
Andreas Huber9575c962013-02-05 13:59:56 -08001180 onSourceNotify(msg);
Andreas Huberb5f25f02013-02-05 10:14:26 -08001181 break;
1182 }
1183
Chong Zhanga7fa1d92014-06-11 14:49:23 -07001184 case kWhatClosedCaptionNotify:
1185 {
1186 onClosedCaptionNotify(msg);
1187 break;
1188 }
1189
Andreas Huberf9334412010-12-15 15:17:42 -08001190 default:
1191 TRESPASS();
1192 break;
1193 }
1194}
1195
Wei Jia94211742014-10-28 17:09:06 -07001196void NuPlayer::onResume() {
Chong Zhangefbb6192015-01-30 17:13:27 -08001197 if (!mPaused) {
1198 return;
1199 }
1200 mPaused = false;
Wei Jia94211742014-10-28 17:09:06 -07001201 if (mSource != NULL) {
1202 mSource->resume();
1203 } else {
1204 ALOGW("resume called when source is gone or not set");
1205 }
1206 // |mAudioDecoder| may have been released due to the pause timeout, so re-create it if
1207 // needed.
1208 if (audioDecoderStillNeeded() && mAudioDecoder == NULL) {
1209 instantiateDecoder(true /* audio */, &mAudioDecoder);
1210 }
1211 if (mRenderer != NULL) {
1212 mRenderer->resume();
1213 } else {
1214 ALOGW("resume called when renderer is gone or not set");
1215 }
1216}
1217
Lajos Molnarfcd3e942015-03-31 10:06:48 -07001218status_t NuPlayer::onInstantiateSecureDecoders() {
1219 status_t err;
1220 if (!(mSourceFlags & Source::FLAG_SECURE)) {
1221 return BAD_TYPE;
1222 }
1223
1224 if (mRenderer != NULL) {
1225 ALOGE("renderer should not be set when instantiating secure decoders");
1226 return UNKNOWN_ERROR;
1227 }
1228
1229 // TRICKY: We rely on mRenderer being null, so that decoder does not start requesting
1230 // data on instantiation.
Lajos Molnar1de1e252015-04-30 18:18:34 -07001231 if (mSurface != NULL) {
Lajos Molnarfcd3e942015-03-31 10:06:48 -07001232 err = instantiateDecoder(false, &mVideoDecoder);
1233 if (err != OK) {
1234 return err;
1235 }
1236 }
1237
1238 if (mAudioSink != NULL) {
1239 err = instantiateDecoder(true, &mAudioDecoder);
1240 if (err != OK) {
1241 return err;
1242 }
1243 }
1244 return OK;
1245}
1246
Wei Jia1061c9c2015-05-19 16:02:17 -07001247void NuPlayer::onStart(int64_t startPositionUs) {
Robert Shih0c61a0d2015-07-06 15:09:10 -07001248 if (!mSourceStarted) {
1249 mSourceStarted = true;
1250 mSource->start();
1251 }
1252 if (startPositionUs > 0) {
1253 performSeek(startPositionUs);
1254 if (mSource->getFormat(false /* audio */) == NULL) {
1255 return;
1256 }
1257 }
1258
Wei Jia94211742014-10-28 17:09:06 -07001259 mOffloadAudio = false;
1260 mAudioEOS = false;
1261 mVideoEOS = false;
Wei Jia94211742014-10-28 17:09:06 -07001262 mStarted = true;
1263
Wei Jia94211742014-10-28 17:09:06 -07001264 uint32_t flags = 0;
1265
1266 if (mSource->isRealTime()) {
1267 flags |= Renderer::FLAG_REAL_TIME;
1268 }
1269
1270 sp<MetaData> audioMeta = mSource->getFormatMeta(true /* audio */);
1271 audio_stream_type_t streamType = AUDIO_STREAM_MUSIC;
1272 if (mAudioSink != NULL) {
1273 streamType = mAudioSink->getAudioStreamType();
1274 }
1275
1276 sp<AMessage> videoFormat = mSource->getFormat(false /* audio */);
1277
1278 mOffloadAudio =
Ronghua Wu02cb98d2015-05-27 11:02:54 -07001279 canOffloadStream(audioMeta, (videoFormat != NULL), mSource->isStreaming(), streamType);
Wei Jia94211742014-10-28 17:09:06 -07001280 if (mOffloadAudio) {
1281 flags |= Renderer::FLAG_OFFLOAD_AUDIO;
1282 }
1283
Lajos Molnar1d15ab52015-03-04 16:46:34 -08001284 sp<AMessage> notify = new AMessage(kWhatRendererNotify, this);
Wei Jia94211742014-10-28 17:09:06 -07001285 ++mRendererGeneration;
1286 notify->setInt32("generation", mRendererGeneration);
1287 mRenderer = new Renderer(mAudioSink, notify, flags);
Wei Jia94211742014-10-28 17:09:06 -07001288 mRendererLooper = new ALooper;
1289 mRendererLooper->setName("NuPlayerRenderer");
1290 mRendererLooper->start(false, false, ANDROID_PRIORITY_AUDIO);
1291 mRendererLooper->registerHandler(mRenderer);
Lajos Molnar3a474aa2015-04-24 17:10:07 -07001292
1293 status_t err = mRenderer->setPlaybackSettings(mPlaybackSettings);
1294 if (err != OK) {
1295 mSource->stop();
Robert Shih0c61a0d2015-07-06 15:09:10 -07001296 mSourceStarted = false;
Lajos Molnar3a474aa2015-04-24 17:10:07 -07001297 notifyListener(MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, err);
1298 return;
Wei Jiac8206ff2015-03-04 13:59:37 -08001299 }
Wei Jia94211742014-10-28 17:09:06 -07001300
Ronghua Wuc8a70d32015-04-29 16:26:34 -07001301 float rate = getFrameRate();
1302 if (rate > 0) {
Wei Jia94211742014-10-28 17:09:06 -07001303 mRenderer->setVideoFrameRate(rate);
1304 }
1305
Wei Jiac6cfd702014-11-11 16:33:20 -08001306 if (mVideoDecoder != NULL) {
1307 mVideoDecoder->setRenderer(mRenderer);
1308 }
1309 if (mAudioDecoder != NULL) {
1310 mAudioDecoder->setRenderer(mRenderer);
1311 }
1312
Wei Jia94211742014-10-28 17:09:06 -07001313 postScanSources();
1314}
1315
Chong Zhangefbb6192015-01-30 17:13:27 -08001316void NuPlayer::onPause() {
1317 if (mPaused) {
1318 return;
1319 }
1320 mPaused = true;
1321 if (mSource != NULL) {
1322 mSource->pause();
1323 } else {
1324 ALOGW("pause called when source is gone or not set");
1325 }
1326 if (mRenderer != NULL) {
1327 mRenderer->pause();
1328 } else {
1329 ALOGW("pause called when renderer is gone or not set");
1330 }
1331}
1332
Ronghua Wud7988b12014-10-03 15:19:10 -07001333bool NuPlayer::audioDecoderStillNeeded() {
1334 // Audio decoder is no longer needed if it's in shut/shutting down status.
1335 return ((mFlushingAudio != SHUT_DOWN) && (mFlushingAudio != SHUTTING_DOWN_DECODER));
1336}
1337
Andy Hung8d121d42014-10-03 09:53:53 -07001338void NuPlayer::handleFlushComplete(bool audio, bool isDecoder) {
1339 // We wait for both the decoder flush and the renderer flush to complete
1340 // before entering either the FLUSHED or the SHUTTING_DOWN_DECODER state.
1341
1342 mFlushComplete[audio][isDecoder] = true;
1343 if (!mFlushComplete[audio][!isDecoder]) {
1344 return;
1345 }
1346
1347 FlushStatus *state = audio ? &mFlushingAudio : &mFlushingVideo;
1348 switch (*state) {
1349 case FLUSHING_DECODER:
1350 {
1351 *state = FLUSHED;
Andy Hung8d121d42014-10-03 09:53:53 -07001352 break;
1353 }
1354
1355 case FLUSHING_DECODER_SHUTDOWN:
1356 {
1357 *state = SHUTTING_DOWN_DECODER;
1358
1359 ALOGV("initiating %s decoder shutdown", audio ? "audio" : "video");
1360 if (!audio) {
Andy Hung8d121d42014-10-03 09:53:53 -07001361 // Widevine source reads must stop before releasing the video decoder.
1362 if (mSource != NULL && mSourceFlags & Source::FLAG_SECURE) {
1363 mSource->stop();
Robert Shih0c61a0d2015-07-06 15:09:10 -07001364 mSourceStarted = false;
Andy Hung8d121d42014-10-03 09:53:53 -07001365 }
1366 }
1367 getDecoder(audio)->initiateShutdown();
1368 break;
1369 }
1370
1371 default:
1372 // decoder flush completes only occur in a flushing state.
1373 LOG_ALWAYS_FATAL_IF(isDecoder, "decoder flush in invalid state %d", *state);
1374 break;
1375 }
1376}
1377
Andreas Huber3831a062010-12-21 10:22:33 -08001378void NuPlayer::finishFlushIfPossible() {
Wei Jia53904f32014-07-29 10:22:53 -07001379 if (mFlushingAudio != NONE && mFlushingAudio != FLUSHED
1380 && mFlushingAudio != SHUT_DOWN) {
Andreas Huber3831a062010-12-21 10:22:33 -08001381 return;
1382 }
1383
Wei Jia53904f32014-07-29 10:22:53 -07001384 if (mFlushingVideo != NONE && mFlushingVideo != FLUSHED
1385 && mFlushingVideo != SHUT_DOWN) {
Andreas Huber3831a062010-12-21 10:22:33 -08001386 return;
1387 }
1388
Steve Block3856b092011-10-20 11:56:00 +01001389 ALOGV("both audio and video are flushed now.");
Andreas Huber3831a062010-12-21 10:22:33 -08001390
Andreas Huber3831a062010-12-21 10:22:33 -08001391 mFlushingAudio = NONE;
1392 mFlushingVideo = NONE;
Andreas Huber3831a062010-12-21 10:22:33 -08001393
Andy Hung8d121d42014-10-03 09:53:53 -07001394 clearFlushComplete();
1395
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001396 processDeferredActions();
Andreas Huber1aef2112011-01-04 14:01:29 -08001397}
1398
1399void NuPlayer::postScanSources() {
1400 if (mScanSourcesPending) {
1401 return;
1402 }
1403
Lajos Molnar1d15ab52015-03-04 16:46:34 -08001404 sp<AMessage> msg = new AMessage(kWhatScanSources, this);
Andreas Huber1aef2112011-01-04 14:01:29 -08001405 msg->setInt32("generation", mScanSourcesGeneration);
1406 msg->post();
1407
1408 mScanSourcesPending = true;
1409}
1410
Andy Hung202bce12014-12-03 11:47:36 -08001411void NuPlayer::tryOpenAudioSinkForOffload(const sp<AMessage> &format, bool hasVideo) {
1412 // Note: This is called early in NuPlayer to determine whether offloading
1413 // is possible; otherwise the decoders call the renderer openAudioSink directly.
Andy Hung282a7e32014-08-14 15:56:34 -07001414
Andy Hung202bce12014-12-03 11:47:36 -08001415 status_t err = mRenderer->openAudioSink(
1416 format, true /* offloadOnly */, hasVideo, AUDIO_OUTPUT_FLAG_NONE, &mOffloadAudio);
1417 if (err != OK) {
1418 // Any failure we turn off mOffloadAudio.
1419 mOffloadAudio = false;
1420 } else if (mOffloadAudio) {
Chong Zhang3b9eb1f2014-10-15 17:05:08 -07001421 sp<MetaData> audioMeta =
1422 mSource->getFormatMeta(true /* audio */);
1423 sendMetaDataToHal(mAudioSink, audioMeta);
Andy Hung282a7e32014-08-14 15:56:34 -07001424 }
1425}
1426
1427void NuPlayer::closeAudioSink() {
Chong Zhang3b9eb1f2014-10-15 17:05:08 -07001428 mRenderer->closeAudioSink();
Andy Hung282a7e32014-08-14 15:56:34 -07001429}
1430
Wei Jiae4d18c72015-07-13 17:58:11 -07001431void NuPlayer::determineAudioModeChange() {
1432 if (mSource == NULL || mAudioSink == NULL) {
1433 return;
1434 }
1435
1436 if (mRenderer == NULL) {
1437 ALOGW("No renderer can be used to determine audio mode. Use non-offload for safety.");
1438 mOffloadAudio = false;
1439 return;
1440 }
1441
1442 sp<MetaData> audioMeta = mSource->getFormatMeta(true /* audio */);
1443 sp<AMessage> videoFormat = mSource->getFormat(false /* audio */);
1444 audio_stream_type_t streamType = mAudioSink->getAudioStreamType();
1445 const bool hasVideo = (videoFormat != NULL);
1446 const bool canOffload = canOffloadStream(
1447 audioMeta, hasVideo, mSource->isStreaming(), streamType);
1448 if (canOffload) {
1449 if (!mOffloadAudio) {
1450 mRenderer->signalEnableOffloadAudio();
1451 }
1452 // open audio sink early under offload mode.
1453 sp<AMessage> format = mSource->getFormat(true /*audio*/);
1454 tryOpenAudioSinkForOffload(format, hasVideo);
1455 } else {
1456 mRenderer->signalDisableOffloadAudio();
1457 mOffloadAudio = false;
1458 }
1459}
1460
Chong Zhang7137ec72014-11-12 16:41:05 -08001461status_t NuPlayer::instantiateDecoder(bool audio, sp<DecoderBase> *decoder) {
Andreas Huberf9334412010-12-15 15:17:42 -08001462 if (*decoder != NULL) {
1463 return OK;
1464 }
1465
Andreas Huber84066782011-08-16 09:34:26 -07001466 sp<AMessage> format = mSource->getFormat(audio);
Andreas Huberf9334412010-12-15 15:17:42 -08001467
Andreas Huber84066782011-08-16 09:34:26 -07001468 if (format == NULL) {
Andreas Huberf9334412010-12-15 15:17:42 -08001469 return -EWOULDBLOCK;
1470 }
1471
Ronghua Wu8db88132015-04-22 13:51:35 -07001472 format->setInt32("priority", 0 /* realtime */);
1473
Andreas Huber3fe62152011-09-16 15:09:22 -07001474 if (!audio) {
Andreas Huber84066782011-08-16 09:34:26 -07001475 AString mime;
1476 CHECK(format->findString("mime", &mime));
Chong Zhanga7fa1d92014-06-11 14:49:23 -07001477
Lajos Molnar1d15ab52015-03-04 16:46:34 -08001478 sp<AMessage> ccNotify = new AMessage(kWhatClosedCaptionNotify, this);
Chong Zhang341ab6e2015-02-04 13:37:18 -08001479 if (mCCDecoder == NULL) {
1480 mCCDecoder = new CCDecoder(ccNotify);
1481 }
Lajos Molnar09524832014-07-17 14:29:51 -07001482
1483 if (mSourceFlags & Source::FLAG_SECURE) {
1484 format->setInt32("secure", true);
1485 }
Chong Zhang17134602015-01-07 16:14:34 -08001486
1487 if (mSourceFlags & Source::FLAG_PROTECTED) {
1488 format->setInt32("protected", true);
1489 }
Ronghua Wu8db88132015-04-22 13:51:35 -07001490
Ronghua Wuc8a70d32015-04-29 16:26:34 -07001491 float rate = getFrameRate();
1492 if (rate > 0) {
Lajos Molnar3a474aa2015-04-24 17:10:07 -07001493 format->setFloat("operating-rate", rate * mPlaybackSettings.mSpeed);
Ronghua Wu8db88132015-04-22 13:51:35 -07001494 }
Andreas Huber3fe62152011-09-16 15:09:22 -07001495 }
1496
Wei Jiabc2fb722014-07-08 16:37:57 -07001497 if (audio) {
Lajos Molnar1d15ab52015-03-04 16:46:34 -08001498 sp<AMessage> notify = new AMessage(kWhatAudioNotify, this);
Wei Jia88703c32014-08-06 11:24:07 -07001499 ++mAudioDecoderGeneration;
1500 notify->setInt32("generation", mAudioDecoderGeneration);
1501
Wei Jiae4d18c72015-07-13 17:58:11 -07001502 determineAudioModeChange();
Wei Jiabc2fb722014-07-08 16:37:57 -07001503 if (mOffloadAudio) {
Haynes Mathew George8b635332015-03-30 17:59:47 -07001504 const bool hasVideo = (mSource->getFormat(false /*audio */) != NULL);
1505 format->setInt32("has-video", hasVideo);
Wei Jiac6cfd702014-11-11 16:33:20 -08001506 *decoder = new DecoderPassThrough(notify, mSource, mRenderer);
Wei Jiabc2fb722014-07-08 16:37:57 -07001507 } else {
Wei Jiac6cfd702014-11-11 16:33:20 -08001508 *decoder = new Decoder(notify, mSource, mRenderer);
Wei Jiabc2fb722014-07-08 16:37:57 -07001509 }
1510 } else {
Lajos Molnar1d15ab52015-03-04 16:46:34 -08001511 sp<AMessage> notify = new AMessage(kWhatVideoNotify, this);
Wei Jia88703c32014-08-06 11:24:07 -07001512 ++mVideoDecoderGeneration;
1513 notify->setInt32("generation", mVideoDecoderGeneration);
1514
Chong Zhang7137ec72014-11-12 16:41:05 -08001515 *decoder = new Decoder(
Lajos Molnar1de1e252015-04-30 18:18:34 -07001516 notify, mSource, mRenderer, mSurface, mCCDecoder);
Lajos Molnard9fd6312014-11-06 11:00:00 -08001517
1518 // enable FRC if high-quality AV sync is requested, even if not
Lajos Molnar1de1e252015-04-30 18:18:34 -07001519 // directly queuing to display, as this will even improve textureview
Lajos Molnard9fd6312014-11-06 11:00:00 -08001520 // playback.
1521 {
1522 char value[PROPERTY_VALUE_MAX];
1523 if (property_get("persist.sys.media.avsync", value, NULL) &&
1524 (!strcmp("1", value) || !strcasecmp("true", value))) {
1525 format->setInt32("auto-frc", 1);
1526 }
1527 }
Wei Jiabc2fb722014-07-08 16:37:57 -07001528 }
Lajos Molnar1cd13982014-01-17 15:12:51 -08001529 (*decoder)->init();
Andreas Huber84066782011-08-16 09:34:26 -07001530 (*decoder)->configure(format);
Andreas Huberf9334412010-12-15 15:17:42 -08001531
Lajos Molnar09524832014-07-17 14:29:51 -07001532 // allocate buffers to decrypt widevine source buffers
1533 if (!audio && (mSourceFlags & Source::FLAG_SECURE)) {
1534 Vector<sp<ABuffer> > inputBufs;
1535 CHECK_EQ((*decoder)->getInputBuffers(&inputBufs), (status_t)OK);
1536
1537 Vector<MediaBuffer *> mediaBufs;
1538 for (size_t i = 0; i < inputBufs.size(); i++) {
1539 const sp<ABuffer> &buffer = inputBufs[i];
1540 MediaBuffer *mbuf = new MediaBuffer(buffer->data(), buffer->size());
1541 mediaBufs.push(mbuf);
1542 }
1543
1544 status_t err = mSource->setBuffers(audio, mediaBufs);
1545 if (err != OK) {
1546 for (size_t i = 0; i < mediaBufs.size(); ++i) {
1547 mediaBufs[i]->release();
1548 }
1549 mediaBufs.clear();
1550 ALOGE("Secure source didn't support secure mediaBufs.");
1551 return err;
1552 }
1553 }
Andreas Huberf9334412010-12-15 15:17:42 -08001554 return OK;
1555}
1556
Chong Zhangced1c2f2014-08-08 15:22:35 -07001557void NuPlayer::updateVideoSize(
1558 const sp<AMessage> &inputFormat,
1559 const sp<AMessage> &outputFormat) {
1560 if (inputFormat == NULL) {
1561 ALOGW("Unknown video size, reporting 0x0!");
1562 notifyListener(MEDIA_SET_VIDEO_SIZE, 0, 0);
1563 return;
1564 }
1565
1566 int32_t displayWidth, displayHeight;
Chong Zhangced1c2f2014-08-08 15:22:35 -07001567 if (outputFormat != NULL) {
1568 int32_t width, height;
1569 CHECK(outputFormat->findInt32("width", &width));
1570 CHECK(outputFormat->findInt32("height", &height));
1571
1572 int32_t cropLeft, cropTop, cropRight, cropBottom;
1573 CHECK(outputFormat->findRect(
1574 "crop",
1575 &cropLeft, &cropTop, &cropRight, &cropBottom));
1576
1577 displayWidth = cropRight - cropLeft + 1;
1578 displayHeight = cropBottom - cropTop + 1;
1579
1580 ALOGV("Video output format changed to %d x %d "
1581 "(crop: %d x %d @ (%d, %d))",
1582 width, height,
1583 displayWidth,
1584 displayHeight,
1585 cropLeft, cropTop);
1586 } else {
1587 CHECK(inputFormat->findInt32("width", &displayWidth));
1588 CHECK(inputFormat->findInt32("height", &displayHeight));
1589
1590 ALOGV("Video input format %d x %d", displayWidth, displayHeight);
1591 }
1592
1593 // Take into account sample aspect ratio if necessary:
1594 int32_t sarWidth, sarHeight;
1595 if (inputFormat->findInt32("sar-width", &sarWidth)
1596 && inputFormat->findInt32("sar-height", &sarHeight)) {
1597 ALOGV("Sample aspect ratio %d : %d", sarWidth, sarHeight);
1598
1599 displayWidth = (displayWidth * sarWidth) / sarHeight;
1600
1601 ALOGV("display dimensions %d x %d", displayWidth, displayHeight);
1602 }
1603
1604 int32_t rotationDegrees;
1605 if (!inputFormat->findInt32("rotation-degrees", &rotationDegrees)) {
1606 rotationDegrees = 0;
1607 }
1608
1609 if (rotationDegrees == 90 || rotationDegrees == 270) {
1610 int32_t tmp = displayWidth;
1611 displayWidth = displayHeight;
1612 displayHeight = tmp;
1613 }
1614
1615 notifyListener(
1616 MEDIA_SET_VIDEO_SIZE,
1617 displayWidth,
1618 displayHeight);
1619}
1620
Chong Zhangdcb89b32013-08-06 09:44:47 -07001621void NuPlayer::notifyListener(int msg, int ext1, int ext2, const Parcel *in) {
Andreas Huber43c3e6c2011-01-05 12:17:08 -08001622 if (mDriver == NULL) {
Andreas Huberf9334412010-12-15 15:17:42 -08001623 return;
1624 }
1625
Andreas Huber43c3e6c2011-01-05 12:17:08 -08001626 sp<NuPlayerDriver> driver = mDriver.promote();
Andreas Huberf9334412010-12-15 15:17:42 -08001627
Andreas Huber43c3e6c2011-01-05 12:17:08 -08001628 if (driver == NULL) {
Andreas Huberf9334412010-12-15 15:17:42 -08001629 return;
1630 }
1631
Chong Zhangdcb89b32013-08-06 09:44:47 -07001632 driver->notifyListener(msg, ext1, ext2, in);
Andreas Huberf9334412010-12-15 15:17:42 -08001633}
1634
Chong Zhang7137ec72014-11-12 16:41:05 -08001635void NuPlayer::flushDecoder(bool audio, bool needShutdown) {
Andreas Huber14f76722013-01-15 09:04:18 -08001636 ALOGV("[%s] flushDecoder needShutdown=%d",
1637 audio ? "audio" : "video", needShutdown);
1638
Chong Zhang7137ec72014-11-12 16:41:05 -08001639 const sp<DecoderBase> &decoder = getDecoder(audio);
Lajos Molnar87603c02014-08-20 19:25:30 -07001640 if (decoder == NULL) {
Steve Blockdf64d152012-01-04 20:05:49 +00001641 ALOGI("flushDecoder %s without decoder present",
Andreas Huber6e3d3112011-11-28 12:36:11 -08001642 audio ? "audio" : "video");
Lajos Molnar87603c02014-08-20 19:25:30 -07001643 return;
Andreas Huber6e3d3112011-11-28 12:36:11 -08001644 }
1645
Andreas Huber1aef2112011-01-04 14:01:29 -08001646 // Make sure we don't continue to scan sources until we finish flushing.
1647 ++mScanSourcesGeneration;
Chong Zhang3b032b32015-04-17 15:49:06 -07001648 if (mScanSourcesPending) {
1649 mDeferredActions.push_back(
1650 new SimpleAction(&NuPlayer::performScanSources));
1651 mScanSourcesPending = false;
1652 }
Andreas Huber1aef2112011-01-04 14:01:29 -08001653
Chong Zhang7137ec72014-11-12 16:41:05 -08001654 decoder->signalFlush();
Andreas Huber1aef2112011-01-04 14:01:29 -08001655
1656 FlushStatus newStatus =
1657 needShutdown ? FLUSHING_DECODER_SHUTDOWN : FLUSHING_DECODER;
1658
Lajos Molnarfcd3e942015-03-31 10:06:48 -07001659 mFlushComplete[audio][false /* isDecoder */] = (mRenderer == NULL);
Andy Hung8d121d42014-10-03 09:53:53 -07001660 mFlushComplete[audio][true /* isDecoder */] = false;
Andreas Huber1aef2112011-01-04 14:01:29 -08001661 if (audio) {
Wei Jia53904f32014-07-29 10:22:53 -07001662 ALOGE_IF(mFlushingAudio != NONE,
1663 "audio flushDecoder() is called in state %d", mFlushingAudio);
Andreas Huber1aef2112011-01-04 14:01:29 -08001664 mFlushingAudio = newStatus;
Andreas Huber1aef2112011-01-04 14:01:29 -08001665 } else {
Wei Jia53904f32014-07-29 10:22:53 -07001666 ALOGE_IF(mFlushingVideo != NONE,
1667 "video flushDecoder() is called in state %d", mFlushingVideo);
Andreas Huber1aef2112011-01-04 14:01:29 -08001668 mFlushingVideo = newStatus;
Andreas Huber1aef2112011-01-04 14:01:29 -08001669 }
1670}
1671
Chong Zhangced1c2f2014-08-08 15:22:35 -07001672void NuPlayer::queueDecoderShutdown(
1673 bool audio, bool video, const sp<AMessage> &reply) {
1674 ALOGI("queueDecoderShutdown audio=%d, video=%d", audio, video);
Andreas Huber84066782011-08-16 09:34:26 -07001675
Chong Zhangced1c2f2014-08-08 15:22:35 -07001676 mDeferredActions.push_back(
Wei Jiafef808d2014-10-31 17:57:05 -07001677 new FlushDecoderAction(
1678 audio ? FLUSH_CMD_SHUTDOWN : FLUSH_CMD_NONE,
1679 video ? FLUSH_CMD_SHUTDOWN : FLUSH_CMD_NONE));
Andreas Huber84066782011-08-16 09:34:26 -07001680
Chong Zhangced1c2f2014-08-08 15:22:35 -07001681 mDeferredActions.push_back(
1682 new SimpleAction(&NuPlayer::performScanSources));
Andreas Huber84066782011-08-16 09:34:26 -07001683
Chong Zhangced1c2f2014-08-08 15:22:35 -07001684 mDeferredActions.push_back(new PostMessageAction(reply));
1685
1686 processDeferredActions();
Andreas Huber84066782011-08-16 09:34:26 -07001687}
1688
James Dong0d268a32012-08-31 12:18:27 -07001689status_t NuPlayer::setVideoScalingMode(int32_t mode) {
1690 mVideoScalingMode = mode;
Lajos Molnar1de1e252015-04-30 18:18:34 -07001691 if (mSurface != NULL) {
1692 status_t ret = native_window_set_scaling_mode(mSurface.get(), mVideoScalingMode);
James Dong0d268a32012-08-31 12:18:27 -07001693 if (ret != OK) {
1694 ALOGE("Failed to set scaling mode (%d): %s",
1695 -ret, strerror(-ret));
1696 return ret;
1697 }
1698 }
1699 return OK;
1700}
1701
Chong Zhangdcb89b32013-08-06 09:44:47 -07001702status_t NuPlayer::getTrackInfo(Parcel* reply) const {
Lajos Molnar1d15ab52015-03-04 16:46:34 -08001703 sp<AMessage> msg = new AMessage(kWhatGetTrackInfo, this);
Chong Zhangdcb89b32013-08-06 09:44:47 -07001704 msg->setPointer("reply", reply);
1705
1706 sp<AMessage> response;
1707 status_t err = msg->postAndAwaitResponse(&response);
1708 return err;
1709}
1710
Robert Shih7c4f0d72014-07-09 18:53:31 -07001711status_t NuPlayer::getSelectedTrack(int32_t type, Parcel* reply) const {
Lajos Molnar1d15ab52015-03-04 16:46:34 -08001712 sp<AMessage> msg = new AMessage(kWhatGetSelectedTrack, this);
Robert Shih7c4f0d72014-07-09 18:53:31 -07001713 msg->setPointer("reply", reply);
1714 msg->setInt32("type", type);
1715
1716 sp<AMessage> response;
1717 status_t err = msg->postAndAwaitResponse(&response);
1718 if (err == OK && response != NULL) {
1719 CHECK(response->findInt32("err", &err));
1720 }
1721 return err;
1722}
1723
Robert Shih6ffb1fd2014-10-29 16:24:32 -07001724status_t NuPlayer::selectTrack(size_t trackIndex, bool select, int64_t timeUs) {
Lajos Molnar1d15ab52015-03-04 16:46:34 -08001725 sp<AMessage> msg = new AMessage(kWhatSelectTrack, this);
Chong Zhangdcb89b32013-08-06 09:44:47 -07001726 msg->setSize("trackIndex", trackIndex);
1727 msg->setInt32("select", select);
Robert Shih6ffb1fd2014-10-29 16:24:32 -07001728 msg->setInt64("timeUs", timeUs);
Chong Zhangdcb89b32013-08-06 09:44:47 -07001729
1730 sp<AMessage> response;
1731 status_t err = msg->postAndAwaitResponse(&response);
1732
Chong Zhang404fced2014-06-11 14:45:31 -07001733 if (err != OK) {
1734 return err;
1735 }
1736
1737 if (!response->findInt32("err", &err)) {
1738 err = OK;
1739 }
1740
Chong Zhangdcb89b32013-08-06 09:44:47 -07001741 return err;
1742}
1743
Ronghua Wua73d9e02014-10-08 15:13:29 -07001744status_t NuPlayer::getCurrentPosition(int64_t *mediaUs) {
1745 sp<Renderer> renderer = mRenderer;
1746 if (renderer == NULL) {
1747 return NO_INIT;
1748 }
1749
1750 return renderer->getCurrentPosition(mediaUs);
1751}
1752
Praveen Chavane1e5d7a2015-05-19 19:09:48 -07001753void NuPlayer::getStats(Vector<sp<AMessage> > *mTrackStats) {
1754 CHECK(mTrackStats != NULL);
1755
1756 mTrackStats->clear();
1757 if (mVideoDecoder != NULL) {
1758 mTrackStats->push_back(mVideoDecoder->getStats());
1759 }
1760 if (mAudioDecoder != NULL) {
1761 mTrackStats->push_back(mAudioDecoder->getStats());
Chong Zhang7137ec72014-11-12 16:41:05 -08001762 }
Ronghua Wua73d9e02014-10-08 15:13:29 -07001763}
1764
Marco Nelissenf0b72b52014-09-16 15:43:44 -07001765sp<MetaData> NuPlayer::getFileMeta() {
1766 return mSource->getFileFormatMeta();
1767}
1768
Ronghua Wuc8a70d32015-04-29 16:26:34 -07001769float NuPlayer::getFrameRate() {
1770 sp<MetaData> meta = mSource->getFormatMeta(false /* audio */);
1771 if (meta == NULL) {
1772 return 0;
1773 }
1774 int32_t rate;
1775 if (!meta->findInt32(kKeyFrameRate, &rate)) {
1776 // fall back to try file meta
1777 sp<MetaData> fileMeta = getFileMeta();
1778 if (fileMeta == NULL) {
1779 ALOGW("source has video meta but not file meta");
1780 return -1;
1781 }
1782 int32_t fileMetaRate;
1783 if (!fileMeta->findInt32(kKeyFrameRate, &fileMetaRate)) {
1784 return -1;
1785 }
1786 return fileMetaRate;
1787 }
1788 return rate;
1789}
1790
Andreas Huberb7c8e912012-11-27 15:02:53 -08001791void NuPlayer::schedulePollDuration() {
Lajos Molnar1d15ab52015-03-04 16:46:34 -08001792 sp<AMessage> msg = new AMessage(kWhatPollDuration, this);
Andreas Huberb7c8e912012-11-27 15:02:53 -08001793 msg->setInt32("generation", mPollDurationGeneration);
1794 msg->post();
1795}
1796
1797void NuPlayer::cancelPollDuration() {
1798 ++mPollDurationGeneration;
1799}
1800
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001801void NuPlayer::processDeferredActions() {
1802 while (!mDeferredActions.empty()) {
1803 // We won't execute any deferred actions until we're no longer in
1804 // an intermediate state, i.e. one more more decoders are currently
1805 // flushing or shutting down.
1806
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001807 if (mFlushingAudio != NONE || mFlushingVideo != NONE) {
1808 // We're currently flushing, postpone the reset until that's
1809 // completed.
1810
1811 ALOGV("postponing action mFlushingAudio=%d, mFlushingVideo=%d",
1812 mFlushingAudio, mFlushingVideo);
1813
1814 break;
1815 }
1816
1817 sp<Action> action = *mDeferredActions.begin();
1818 mDeferredActions.erase(mDeferredActions.begin());
1819
1820 action->execute(this);
1821 }
1822}
1823
Wei Jia29840802015-05-15 17:11:38 -07001824void NuPlayer::performSeek(int64_t seekTimeUs) {
1825 ALOGV("performSeek seekTimeUs=%lld us (%.2f secs)",
Lajos Molnar6d339f12015-04-17 16:15:53 -07001826 (long long)seekTimeUs,
Wei Jia29840802015-05-15 17:11:38 -07001827 seekTimeUs / 1E6);
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001828
Andy Hungadf34bf2014-09-03 18:22:22 -07001829 if (mSource == NULL) {
1830 // This happens when reset occurs right before the loop mode
1831 // asynchronously seeks to the start of the stream.
1832 LOG_ALWAYS_FATAL_IF(mAudioDecoder != NULL || mVideoDecoder != NULL,
1833 "mSource is NULL and decoders not NULL audio(%p) video(%p)",
1834 mAudioDecoder.get(), mVideoDecoder.get());
1835 return;
1836 }
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001837 mSource->seekTo(seekTimeUs);
Robert Shihd3b0bbb2014-07-23 15:00:25 -07001838 ++mTimedTextGeneration;
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001839
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001840 // everything's flushed, continue playback.
1841}
1842
Wei Jiafef808d2014-10-31 17:57:05 -07001843void NuPlayer::performDecoderFlush(FlushCommand audio, FlushCommand video) {
1844 ALOGV("performDecoderFlush audio=%d, video=%d", audio, video);
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001845
Wei Jiafef808d2014-10-31 17:57:05 -07001846 if ((audio == FLUSH_CMD_NONE || mAudioDecoder == NULL)
1847 && (video == FLUSH_CMD_NONE || mVideoDecoder == NULL)) {
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001848 return;
1849 }
1850
Wei Jiafef808d2014-10-31 17:57:05 -07001851 if (audio != FLUSH_CMD_NONE && mAudioDecoder != NULL) {
1852 flushDecoder(true /* audio */, (audio == FLUSH_CMD_SHUTDOWN));
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001853 }
1854
Wei Jiafef808d2014-10-31 17:57:05 -07001855 if (video != FLUSH_CMD_NONE && mVideoDecoder != NULL) {
1856 flushDecoder(false /* audio */, (video == FLUSH_CMD_SHUTDOWN));
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001857 }
1858}
1859
1860void NuPlayer::performReset() {
1861 ALOGV("performReset");
1862
1863 CHECK(mAudioDecoder == NULL);
1864 CHECK(mVideoDecoder == NULL);
1865
1866 cancelPollDuration();
1867
1868 ++mScanSourcesGeneration;
1869 mScanSourcesPending = false;
1870
Lajos Molnar09524832014-07-17 14:29:51 -07001871 if (mRendererLooper != NULL) {
1872 if (mRenderer != NULL) {
1873 mRendererLooper->unregisterHandler(mRenderer->id());
1874 }
1875 mRendererLooper->stop();
1876 mRendererLooper.clear();
1877 }
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001878 mRenderer.clear();
Wei Jia57568df2014-09-22 10:16:29 -07001879 ++mRendererGeneration;
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001880
1881 if (mSource != NULL) {
1882 mSource->stop();
Andreas Huberb5f25f02013-02-05 10:14:26 -08001883
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001884 mSource.clear();
1885 }
1886
1887 if (mDriver != NULL) {
1888 sp<NuPlayerDriver> driver = mDriver.promote();
1889 if (driver != NULL) {
1890 driver->notifyResetComplete();
1891 }
1892 }
Andreas Huber57a339c2012-12-03 11:18:00 -08001893
1894 mStarted = false;
Robert Shih0c61a0d2015-07-06 15:09:10 -07001895 mSourceStarted = false;
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001896}
1897
1898void NuPlayer::performScanSources() {
1899 ALOGV("performScanSources");
1900
Andreas Huber57a339c2012-12-03 11:18:00 -08001901 if (!mStarted) {
1902 return;
1903 }
1904
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001905 if (mAudioDecoder == NULL || mVideoDecoder == NULL) {
1906 postScanSources();
1907 }
1908}
1909
Lajos Molnar1de1e252015-04-30 18:18:34 -07001910void NuPlayer::performSetSurface(const sp<Surface> &surface) {
Andreas Huber57a339c2012-12-03 11:18:00 -08001911 ALOGV("performSetSurface");
1912
Lajos Molnar1de1e252015-04-30 18:18:34 -07001913 mSurface = surface;
Andreas Huber57a339c2012-12-03 11:18:00 -08001914
1915 // XXX - ignore error from setVideoScalingMode for now
1916 setVideoScalingMode(mVideoScalingMode);
Chong Zhang13d6faa2014-08-22 15:35:28 -07001917
1918 if (mDriver != NULL) {
1919 sp<NuPlayerDriver> driver = mDriver.promote();
1920 if (driver != NULL) {
1921 driver->notifySetSurfaceComplete();
1922 }
1923 }
Andreas Huber57a339c2012-12-03 11:18:00 -08001924}
1925
Chong Zhangf8d71772014-11-26 15:08:34 -08001926void NuPlayer::performResumeDecoders(bool needNotify) {
1927 if (needNotify) {
1928 mResumePending = true;
1929 if (mVideoDecoder == NULL) {
1930 // if audio-only, we can notify seek complete now,
1931 // as the resume operation will be relatively fast.
1932 finishResume();
1933 }
1934 }
1935
Chong Zhang7137ec72014-11-12 16:41:05 -08001936 if (mVideoDecoder != NULL) {
Chong Zhangf8d71772014-11-26 15:08:34 -08001937 // When there is continuous seek, MediaPlayer will cache the seek
1938 // position, and send down new seek request when previous seek is
1939 // complete. Let's wait for at least one video output frame before
1940 // notifying seek complete, so that the video thumbnail gets updated
1941 // when seekbar is dragged.
1942 mVideoDecoder->signalResume(needNotify);
Chong Zhang7137ec72014-11-12 16:41:05 -08001943 }
1944
1945 if (mAudioDecoder != NULL) {
Chong Zhangf8d71772014-11-26 15:08:34 -08001946 mAudioDecoder->signalResume(false /* needNotify */);
1947 }
1948}
1949
1950void NuPlayer::finishResume() {
1951 if (mResumePending) {
1952 mResumePending = false;
Wei Jia1061c9c2015-05-19 16:02:17 -07001953 notifyDriverSeekComplete();
1954 }
1955}
1956
1957void NuPlayer::notifyDriverSeekComplete() {
1958 if (mDriver != NULL) {
1959 sp<NuPlayerDriver> driver = mDriver.promote();
1960 if (driver != NULL) {
1961 driver->notifySeekComplete();
Chong Zhangf8d71772014-11-26 15:08:34 -08001962 }
Chong Zhang7137ec72014-11-12 16:41:05 -08001963 }
1964}
1965
Andreas Huber9575c962013-02-05 13:59:56 -08001966void NuPlayer::onSourceNotify(const sp<AMessage> &msg) {
1967 int32_t what;
1968 CHECK(msg->findInt32("what", &what));
1969
1970 switch (what) {
Lajos Molnarfcd3e942015-03-31 10:06:48 -07001971 case Source::kWhatInstantiateSecureDecoders:
1972 {
1973 if (mSource == NULL) {
1974 // This is a stale notification from a source that was
1975 // asynchronously preparing when the client called reset().
1976 // We handled the reset, the source is gone.
1977 break;
1978 }
1979
1980 sp<AMessage> reply;
1981 CHECK(msg->findMessage("reply", &reply));
1982 status_t err = onInstantiateSecureDecoders();
1983 reply->setInt32("err", err);
1984 reply->post();
1985 break;
1986 }
1987
Andreas Huber9575c962013-02-05 13:59:56 -08001988 case Source::kWhatPrepared:
1989 {
Andreas Huberb5f28d42013-04-25 15:11:19 -07001990 if (mSource == NULL) {
1991 // This is a stale notification from a source that was
1992 // asynchronously preparing when the client called reset().
1993 // We handled the reset, the source is gone.
1994 break;
1995 }
1996
Andreas Huberec0c5972013-02-05 14:47:13 -08001997 int32_t err;
1998 CHECK(msg->findInt32("err", &err));
1999
Lajos Molnarfcd3e942015-03-31 10:06:48 -07002000 if (err != OK) {
2001 // shut down potential secure codecs in case client never calls reset
2002 mDeferredActions.push_back(
2003 new FlushDecoderAction(FLUSH_CMD_SHUTDOWN /* audio */,
2004 FLUSH_CMD_SHUTDOWN /* video */));
2005 processDeferredActions();
2006 }
2007
Andreas Huber9575c962013-02-05 13:59:56 -08002008 sp<NuPlayerDriver> driver = mDriver.promote();
2009 if (driver != NULL) {
Marco Nelissendd114d12014-05-28 15:23:14 -07002010 // notify duration first, so that it's definitely set when
2011 // the app received the "prepare complete" callback.
2012 int64_t durationUs;
2013 if (mSource->getDuration(&durationUs) == OK) {
2014 driver->notifyDuration(durationUs);
2015 }
Andreas Huberec0c5972013-02-05 14:47:13 -08002016 driver->notifyPrepareCompleted(err);
Andreas Huber9575c962013-02-05 13:59:56 -08002017 }
Andreas Huber99759402013-04-01 14:28:31 -07002018
Andreas Huber9575c962013-02-05 13:59:56 -08002019 break;
2020 }
2021
2022 case Source::kWhatFlagsChanged:
2023 {
2024 uint32_t flags;
2025 CHECK(msg->findInt32("flags", (int32_t *)&flags));
2026
Chong Zhang4b7069d2013-09-11 12:52:43 -07002027 sp<NuPlayerDriver> driver = mDriver.promote();
2028 if (driver != NULL) {
Wei Jia895651b2014-12-10 17:31:52 -08002029 if ((flags & NuPlayer::Source::FLAG_CAN_SEEK) == 0) {
2030 driver->notifyListener(
2031 MEDIA_INFO, MEDIA_INFO_NOT_SEEKABLE, 0);
2032 }
Chong Zhang4b7069d2013-09-11 12:52:43 -07002033 driver->notifyFlagsChanged(flags);
2034 }
2035
Andreas Huber9575c962013-02-05 13:59:56 -08002036 if ((mSourceFlags & Source::FLAG_DYNAMIC_DURATION)
2037 && (!(flags & Source::FLAG_DYNAMIC_DURATION))) {
2038 cancelPollDuration();
2039 } else if (!(mSourceFlags & Source::FLAG_DYNAMIC_DURATION)
2040 && (flags & Source::FLAG_DYNAMIC_DURATION)
2041 && (mAudioDecoder != NULL || mVideoDecoder != NULL)) {
2042 schedulePollDuration();
2043 }
2044
2045 mSourceFlags = flags;
2046 break;
2047 }
2048
2049 case Source::kWhatVideoSizeChanged:
2050 {
Chong Zhangced1c2f2014-08-08 15:22:35 -07002051 sp<AMessage> format;
2052 CHECK(msg->findMessage("format", &format));
Andreas Huber9575c962013-02-05 13:59:56 -08002053
Chong Zhangced1c2f2014-08-08 15:22:35 -07002054 updateVideoSize(format);
Andreas Huber9575c962013-02-05 13:59:56 -08002055 break;
2056 }
2057
Chong Zhang2a3cc9a2014-08-21 17:48:26 -07002058 case Source::kWhatBufferingUpdate:
2059 {
2060 int32_t percentage;
2061 CHECK(msg->findInt32("percentage", &percentage));
2062
2063 notifyListener(MEDIA_BUFFERING_UPDATE, percentage, 0);
2064 break;
2065 }
2066
Chong Zhangefbb6192015-01-30 17:13:27 -08002067 case Source::kWhatPauseOnBufferingStart:
2068 {
2069 // ignore if not playing
Chong Zhang8a048332015-05-06 15:16:28 -07002070 if (mStarted) {
Chong Zhangefbb6192015-01-30 17:13:27 -08002071 ALOGI("buffer low, pausing...");
2072
Chong Zhang8a048332015-05-06 15:16:28 -07002073 mPausedForBuffering = true;
Chong Zhangefbb6192015-01-30 17:13:27 -08002074 onPause();
2075 }
2076 // fall-thru
2077 }
2078
Roger Jönssonb50e83e2013-01-21 16:26:41 +01002079 case Source::kWhatBufferingStart:
2080 {
2081 notifyListener(MEDIA_INFO, MEDIA_INFO_BUFFERING_START, 0);
2082 break;
2083 }
2084
Chong Zhangefbb6192015-01-30 17:13:27 -08002085 case Source::kWhatResumeOnBufferingEnd:
2086 {
2087 // ignore if not playing
Chong Zhang8a048332015-05-06 15:16:28 -07002088 if (mStarted) {
Chong Zhangefbb6192015-01-30 17:13:27 -08002089 ALOGI("buffer ready, resuming...");
2090
Chong Zhang8a048332015-05-06 15:16:28 -07002091 mPausedForBuffering = false;
2092
2093 // do not resume yet if client didn't unpause
2094 if (!mPausedByClient) {
2095 onResume();
2096 }
Chong Zhangefbb6192015-01-30 17:13:27 -08002097 }
2098 // fall-thru
2099 }
2100
Roger Jönssonb50e83e2013-01-21 16:26:41 +01002101 case Source::kWhatBufferingEnd:
2102 {
2103 notifyListener(MEDIA_INFO, MEDIA_INFO_BUFFERING_END, 0);
2104 break;
2105 }
2106
Chong Zhangefbb6192015-01-30 17:13:27 -08002107 case Source::kWhatCacheStats:
2108 {
2109 int32_t kbps;
2110 CHECK(msg->findInt32("bandwidth", &kbps));
2111
2112 notifyListener(MEDIA_INFO, MEDIA_INFO_NETWORK_BANDWIDTH, kbps);
2113 break;
2114 }
2115
Chong Zhangdcb89b32013-08-06 09:44:47 -07002116 case Source::kWhatSubtitleData:
2117 {
2118 sp<ABuffer> buffer;
2119 CHECK(msg->findBuffer("buffer", &buffer));
2120
Chong Zhang404fced2014-06-11 14:45:31 -07002121 sendSubtitleData(buffer, 0 /* baseIndex */);
Chong Zhangdcb89b32013-08-06 09:44:47 -07002122 break;
2123 }
2124
Robert Shih08528432015-04-08 09:06:54 -07002125 case Source::kWhatTimedMetaData:
2126 {
2127 sp<ABuffer> buffer;
2128 if (!msg->findBuffer("buffer", &buffer)) {
2129 notifyListener(MEDIA_INFO, MEDIA_INFO_METADATA_UPDATE, 0);
2130 } else {
2131 sendTimedMetaData(buffer);
2132 }
2133 break;
2134 }
2135
Robert Shihd3b0bbb2014-07-23 15:00:25 -07002136 case Source::kWhatTimedTextData:
2137 {
2138 int32_t generation;
2139 if (msg->findInt32("generation", &generation)
2140 && generation != mTimedTextGeneration) {
2141 break;
2142 }
2143
2144 sp<ABuffer> buffer;
2145 CHECK(msg->findBuffer("buffer", &buffer));
2146
2147 sp<NuPlayerDriver> driver = mDriver.promote();
2148 if (driver == NULL) {
2149 break;
2150 }
2151
2152 int posMs;
2153 int64_t timeUs, posUs;
2154 driver->getCurrentPosition(&posMs);
2155 posUs = posMs * 1000;
2156 CHECK(buffer->meta()->findInt64("timeUs", &timeUs));
2157
2158 if (posUs < timeUs) {
2159 if (!msg->findInt32("generation", &generation)) {
2160 msg->setInt32("generation", mTimedTextGeneration);
2161 }
2162 msg->post(timeUs - posUs);
2163 } else {
2164 sendTimedTextData(buffer);
2165 }
2166 break;
2167 }
2168
Andreas Huber14f76722013-01-15 09:04:18 -08002169 case Source::kWhatQueueDecoderShutdown:
2170 {
2171 int32_t audio, video;
2172 CHECK(msg->findInt32("audio", &audio));
2173 CHECK(msg->findInt32("video", &video));
2174
2175 sp<AMessage> reply;
2176 CHECK(msg->findMessage("reply", &reply));
2177
2178 queueDecoderShutdown(audio, video, reply);
2179 break;
2180 }
2181
Ronghua Wu80276872014-08-28 15:50:29 -07002182 case Source::kWhatDrmNoLicense:
2183 {
2184 notifyListener(MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, ERROR_DRM_NO_LICENSE);
2185 break;
2186 }
2187
Andreas Huber9575c962013-02-05 13:59:56 -08002188 default:
2189 TRESPASS();
2190 }
2191}
2192
Chong Zhanga7fa1d92014-06-11 14:49:23 -07002193void NuPlayer::onClosedCaptionNotify(const sp<AMessage> &msg) {
2194 int32_t what;
2195 CHECK(msg->findInt32("what", &what));
2196
2197 switch (what) {
2198 case NuPlayer::CCDecoder::kWhatClosedCaptionData:
2199 {
2200 sp<ABuffer> buffer;
2201 CHECK(msg->findBuffer("buffer", &buffer));
2202
2203 size_t inbandTracks = 0;
2204 if (mSource != NULL) {
2205 inbandTracks = mSource->getTrackCount();
2206 }
2207
2208 sendSubtitleData(buffer, inbandTracks);
2209 break;
2210 }
2211
2212 case NuPlayer::CCDecoder::kWhatTrackAdded:
2213 {
2214 notifyListener(MEDIA_INFO, MEDIA_INFO_METADATA_UPDATE, 0);
2215
2216 break;
2217 }
2218
2219 default:
2220 TRESPASS();
2221 }
2222
2223
2224}
2225
Chong Zhang404fced2014-06-11 14:45:31 -07002226void NuPlayer::sendSubtitleData(const sp<ABuffer> &buffer, int32_t baseIndex) {
2227 int32_t trackIndex;
2228 int64_t timeUs, durationUs;
2229 CHECK(buffer->meta()->findInt32("trackIndex", &trackIndex));
2230 CHECK(buffer->meta()->findInt64("timeUs", &timeUs));
2231 CHECK(buffer->meta()->findInt64("durationUs", &durationUs));
2232
2233 Parcel in;
2234 in.writeInt32(trackIndex + baseIndex);
2235 in.writeInt64(timeUs);
2236 in.writeInt64(durationUs);
2237 in.writeInt32(buffer->size());
2238 in.writeInt32(buffer->size());
2239 in.write(buffer->data(), buffer->size());
2240
2241 notifyListener(MEDIA_SUBTITLE_DATA, 0, 0, &in);
2242}
Robert Shihd3b0bbb2014-07-23 15:00:25 -07002243
Robert Shih08528432015-04-08 09:06:54 -07002244void NuPlayer::sendTimedMetaData(const sp<ABuffer> &buffer) {
2245 int64_t timeUs;
2246 CHECK(buffer->meta()->findInt64("timeUs", &timeUs));
2247
2248 Parcel in;
2249 in.writeInt64(timeUs);
2250 in.writeInt32(buffer->size());
2251 in.writeInt32(buffer->size());
2252 in.write(buffer->data(), buffer->size());
2253
2254 notifyListener(MEDIA_META_DATA, 0, 0, &in);
2255}
2256
Robert Shihd3b0bbb2014-07-23 15:00:25 -07002257void NuPlayer::sendTimedTextData(const sp<ABuffer> &buffer) {
2258 const void *data;
2259 size_t size = 0;
2260 int64_t timeUs;
2261 int32_t flag = TextDescriptions::LOCAL_DESCRIPTIONS;
2262
2263 AString mime;
2264 CHECK(buffer->meta()->findString("mime", &mime));
2265 CHECK(strcasecmp(mime.c_str(), MEDIA_MIMETYPE_TEXT_3GPP) == 0);
2266
2267 data = buffer->data();
2268 size = buffer->size();
2269
2270 Parcel parcel;
2271 if (size > 0) {
2272 CHECK(buffer->meta()->findInt64("timeUs", &timeUs));
2273 flag |= TextDescriptions::IN_BAND_TEXT_3GPP;
2274 TextDescriptions::getParcelOfDescriptions(
2275 (const uint8_t *)data, size, flag, timeUs / 1000, &parcel);
2276 }
2277
2278 if ((parcel.dataSize() > 0)) {
2279 notifyListener(MEDIA_TIMED_TEXT, 0, 0, &parcel);
2280 } else { // send an empty timed text
2281 notifyListener(MEDIA_TIMED_TEXT, 0, 0);
2282 }
2283}
Andreas Huberb5f25f02013-02-05 10:14:26 -08002284////////////////////////////////////////////////////////////////////////////////
2285
Chong Zhangced1c2f2014-08-08 15:22:35 -07002286sp<AMessage> NuPlayer::Source::getFormat(bool audio) {
2287 sp<MetaData> meta = getFormatMeta(audio);
2288
2289 if (meta == NULL) {
2290 return NULL;
2291 }
2292
2293 sp<AMessage> msg = new AMessage;
2294
2295 if(convertMetaDataToMessage(meta, &msg) == OK) {
2296 return msg;
2297 }
2298 return NULL;
2299}
2300
Andreas Huber9575c962013-02-05 13:59:56 -08002301void NuPlayer::Source::notifyFlagsChanged(uint32_t flags) {
2302 sp<AMessage> notify = dupNotify();
2303 notify->setInt32("what", kWhatFlagsChanged);
2304 notify->setInt32("flags", flags);
2305 notify->post();
2306}
2307
Chong Zhangced1c2f2014-08-08 15:22:35 -07002308void NuPlayer::Source::notifyVideoSizeChanged(const sp<AMessage> &format) {
Andreas Huber9575c962013-02-05 13:59:56 -08002309 sp<AMessage> notify = dupNotify();
2310 notify->setInt32("what", kWhatVideoSizeChanged);
Chong Zhangced1c2f2014-08-08 15:22:35 -07002311 notify->setMessage("format", format);
Andreas Huber9575c962013-02-05 13:59:56 -08002312 notify->post();
2313}
2314
Andreas Huberec0c5972013-02-05 14:47:13 -08002315void NuPlayer::Source::notifyPrepared(status_t err) {
Andreas Huber9575c962013-02-05 13:59:56 -08002316 sp<AMessage> notify = dupNotify();
2317 notify->setInt32("what", kWhatPrepared);
Andreas Huberec0c5972013-02-05 14:47:13 -08002318 notify->setInt32("err", err);
Andreas Huber9575c962013-02-05 13:59:56 -08002319 notify->post();
2320}
2321
Lajos Molnarfcd3e942015-03-31 10:06:48 -07002322void NuPlayer::Source::notifyInstantiateSecureDecoders(const sp<AMessage> &reply) {
2323 sp<AMessage> notify = dupNotify();
2324 notify->setInt32("what", kWhatInstantiateSecureDecoders);
2325 notify->setMessage("reply", reply);
2326 notify->post();
2327}
2328
Andreas Huber84333e02014-02-07 15:36:10 -08002329void NuPlayer::Source::onMessageReceived(const sp<AMessage> & /* msg */) {
Andreas Huberb5f25f02013-02-05 10:14:26 -08002330 TRESPASS();
2331}
2332
Andreas Huberf9334412010-12-15 15:17:42 -08002333} // namespace android