blob: ef96a2886d9d4a3e58169344021c82c84df3088c [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),
189 mPaused(false),
Chong Zhang8a048332015-05-06 15:16:28 -0700190 mPausedByClient(false),
191 mPausedForBuffering(false) {
Andy Hung8d121d42014-10-03 09:53:53 -0700192 clearFlushComplete();
Andreas Huberf9334412010-12-15 15:17:42 -0800193}
194
195NuPlayer::~NuPlayer() {
196}
197
Andreas Huber9b80c2b2011-06-30 15:47:02 -0700198void NuPlayer::setUID(uid_t uid) {
199 mUIDValid = true;
200 mUID = uid;
201}
202
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800203void NuPlayer::setDriver(const wp<NuPlayerDriver> &driver) {
204 mDriver = driver;
Andreas Huberf9334412010-12-15 15:17:42 -0800205}
206
Andreas Huber9575c962013-02-05 13:59:56 -0800207void NuPlayer::setDataSourceAsync(const sp<IStreamSource> &source) {
Lajos Molnar1d15ab52015-03-04 16:46:34 -0800208 sp<AMessage> msg = new AMessage(kWhatSetDataSource, this);
Andreas Huberf9334412010-12-15 15:17:42 -0800209
Lajos Molnar1d15ab52015-03-04 16:46:34 -0800210 sp<AMessage> notify = new AMessage(kWhatSourceNotify, this);
Andreas Huberb5f25f02013-02-05 10:14:26 -0800211
Andreas Huber240abcc2014-02-13 13:32:37 -0800212 msg->setObject("source", new StreamingSource(notify, source));
Andreas Huber5bc087c2010-12-23 10:27:40 -0800213 msg->post();
214}
Andreas Huberf9334412010-12-15 15:17:42 -0800215
Andreas Huberafed0e12011-09-20 15:39:58 -0700216static bool IsHTTPLiveURL(const char *url) {
217 if (!strncasecmp("http://", url, 7)
Andreas Huber99759402013-04-01 14:28:31 -0700218 || !strncasecmp("https://", url, 8)
219 || !strncasecmp("file://", url, 7)) {
Andreas Huberafed0e12011-09-20 15:39:58 -0700220 size_t len = strlen(url);
221 if (len >= 5 && !strcasecmp(".m3u8", &url[len - 5])) {
222 return true;
223 }
224
225 if (strstr(url,"m3u8")) {
226 return true;
227 }
228 }
229
230 return false;
231}
232
Andreas Huber9575c962013-02-05 13:59:56 -0800233void NuPlayer::setDataSourceAsync(
Andreas Huber1b86fe02014-01-29 11:13:26 -0800234 const sp<IMediaHTTPService> &httpService,
235 const char *url,
236 const KeyedVector<String8, String8> *headers) {
Chong Zhang3de157d2014-08-05 20:54:44 -0700237
Lajos Molnar1d15ab52015-03-04 16:46:34 -0800238 sp<AMessage> msg = new AMessage(kWhatSetDataSource, this);
Oscar Rydhé7a33b772012-02-20 10:15:48 +0100239 size_t len = strlen(url);
Andreas Huber5bc087c2010-12-23 10:27:40 -0800240
Lajos Molnar1d15ab52015-03-04 16:46:34 -0800241 sp<AMessage> notify = new AMessage(kWhatSourceNotify, this);
Andreas Huberb5f25f02013-02-05 10:14:26 -0800242
Andreas Huberafed0e12011-09-20 15:39:58 -0700243 sp<Source> source;
244 if (IsHTTPLiveURL(url)) {
Andreas Huber81e68442014-02-05 11:52:33 -0800245 source = new HTTPLiveSource(notify, httpService, url, headers);
Andreas Huberafed0e12011-09-20 15:39:58 -0700246 } else if (!strncasecmp(url, "rtsp://", 7)) {
Andreas Huber1b86fe02014-01-29 11:13:26 -0800247 source = new RTSPSource(
248 notify, httpService, url, headers, mUIDValid, mUID);
Oscar Rydhé7a33b772012-02-20 10:15:48 +0100249 } else if ((!strncasecmp(url, "http://", 7)
250 || !strncasecmp(url, "https://", 8))
251 && ((len >= 4 && !strcasecmp(".sdp", &url[len - 4]))
252 || strstr(url, ".sdp?"))) {
Andreas Huber1b86fe02014-01-29 11:13:26 -0800253 source = new RTSPSource(
254 notify, httpService, url, headers, mUIDValid, mUID, true);
Andreas Huber2bfdd422011-10-11 15:24:07 -0700255 } else {
Chong Zhang3de157d2014-08-05 20:54:44 -0700256 sp<GenericSource> genericSource =
257 new GenericSource(notify, mUIDValid, mUID);
258 // Don't set FLAG_SECURE on mSourceFlags here for widevine.
259 // The correct flags will be updated in Source::kWhatFlagsChanged
260 // handler when GenericSource is prepared.
Andreas Huber2bfdd422011-10-11 15:24:07 -0700261
Chong Zhanga19f33e2014-08-07 15:35:07 -0700262 status_t err = genericSource->setDataSource(httpService, url, headers);
Chong Zhang3de157d2014-08-05 20:54:44 -0700263
264 if (err == OK) {
265 source = genericSource;
266 } else {
Chong Zhanga19f33e2014-08-07 15:35:07 -0700267 ALOGE("Failed to set data source!");
Chong Zhang3de157d2014-08-05 20:54:44 -0700268 }
269 }
Andreas Huberafed0e12011-09-20 15:39:58 -0700270 msg->setObject("source", source);
271 msg->post();
272}
273
Andreas Huber9575c962013-02-05 13:59:56 -0800274void NuPlayer::setDataSourceAsync(int fd, int64_t offset, int64_t length) {
Lajos Molnar1d15ab52015-03-04 16:46:34 -0800275 sp<AMessage> msg = new AMessage(kWhatSetDataSource, this);
Andreas Huberafed0e12011-09-20 15:39:58 -0700276
Lajos Molnar1d15ab52015-03-04 16:46:34 -0800277 sp<AMessage> notify = new AMessage(kWhatSourceNotify, this);
Andreas Huberb5f25f02013-02-05 10:14:26 -0800278
Chong Zhang3de157d2014-08-05 20:54:44 -0700279 sp<GenericSource> source =
280 new GenericSource(notify, mUIDValid, mUID);
281
Chong Zhanga19f33e2014-08-07 15:35:07 -0700282 status_t err = source->setDataSource(fd, offset, length);
Chong Zhang3de157d2014-08-05 20:54:44 -0700283
284 if (err != OK) {
Chong Zhanga19f33e2014-08-07 15:35:07 -0700285 ALOGE("Failed to set data source!");
Chong Zhang3de157d2014-08-05 20:54:44 -0700286 source = NULL;
287 }
288
Andreas Huberafed0e12011-09-20 15:39:58 -0700289 msg->setObject("source", source);
Andreas Huberf9334412010-12-15 15:17:42 -0800290 msg->post();
291}
292
Chris Watkins99f31602015-03-20 13:06:33 -0700293void NuPlayer::setDataSourceAsync(const sp<DataSource> &dataSource) {
294 sp<AMessage> msg = new AMessage(kWhatSetDataSource, this);
295 sp<AMessage> notify = new AMessage(kWhatSourceNotify, this);
296
297 sp<GenericSource> source = new GenericSource(notify, mUIDValid, mUID);
298 status_t err = source->setDataSource(dataSource);
299
300 if (err != OK) {
301 ALOGE("Failed to set data source!");
302 source = NULL;
303 }
304
305 msg->setObject("source", source);
306 msg->post();
307}
308
Andreas Huber9575c962013-02-05 13:59:56 -0800309void NuPlayer::prepareAsync() {
Lajos Molnar1d15ab52015-03-04 16:46:34 -0800310 (new AMessage(kWhatPrepare, this))->post();
Andreas Huber9575c962013-02-05 13:59:56 -0800311}
312
Andreas Huber57a339c2012-12-03 11:18:00 -0800313void NuPlayer::setVideoSurfaceTextureAsync(
Andy McFadden8ba01022012-12-18 09:46:54 -0800314 const sp<IGraphicBufferProducer> &bufferProducer) {
Lajos Molnar1de1e252015-04-30 18:18:34 -0700315 sp<AMessage> msg = new AMessage(kWhatSetVideoSurface, this);
Andreas Huber57a339c2012-12-03 11:18:00 -0800316
Andy McFadden8ba01022012-12-18 09:46:54 -0800317 if (bufferProducer == NULL) {
Lajos Molnar1de1e252015-04-30 18:18:34 -0700318 msg->setObject("surface", NULL);
Andreas Huber57a339c2012-12-03 11:18:00 -0800319 } else {
Lajos Molnar1de1e252015-04-30 18:18:34 -0700320 msg->setObject("surface", new Surface(bufferProducer, true /* controlledByApp */));
Andreas Huber57a339c2012-12-03 11:18:00 -0800321 }
322
Andreas Huberf9334412010-12-15 15:17:42 -0800323 msg->post();
324}
325
326void NuPlayer::setAudioSink(const sp<MediaPlayerBase::AudioSink> &sink) {
Lajos Molnar1d15ab52015-03-04 16:46:34 -0800327 sp<AMessage> msg = new AMessage(kWhatSetAudioSink, this);
Andreas Huberf9334412010-12-15 15:17:42 -0800328 msg->setObject("sink", sink);
329 msg->post();
330}
331
332void NuPlayer::start() {
Lajos Molnar1d15ab52015-03-04 16:46:34 -0800333 (new AMessage(kWhatStart, this))->post();
Andreas Huberf9334412010-12-15 15:17:42 -0800334}
335
Lajos Molnar3a474aa2015-04-24 17:10:07 -0700336status_t NuPlayer::setPlaybackSettings(const AudioPlaybackRate &rate) {
337 // do some cursory validation of the settings here. audio modes are
338 // only validated when set on the audiosink.
339 if ((rate.mSpeed != 0.f && rate.mSpeed < AUDIO_TIMESTRETCH_SPEED_MIN)
340 || rate.mSpeed > AUDIO_TIMESTRETCH_SPEED_MAX
341 || rate.mPitch < AUDIO_TIMESTRETCH_SPEED_MIN
342 || rate.mPitch > AUDIO_TIMESTRETCH_SPEED_MAX) {
343 return BAD_VALUE;
344 }
345 sp<AMessage> msg = new AMessage(kWhatConfigPlayback, this);
346 writeToAMessage(msg, rate);
347 sp<AMessage> response;
348 status_t err = msg->postAndAwaitResponse(&response);
349 if (err == OK && response != NULL) {
350 CHECK(response->findInt32("err", &err));
351 }
352 return err;
353}
354
355status_t NuPlayer::getPlaybackSettings(AudioPlaybackRate *rate /* nonnull */) {
356 sp<AMessage> msg = new AMessage(kWhatGetPlaybackSettings, this);
357 sp<AMessage> response;
358 status_t err = msg->postAndAwaitResponse(&response);
359 if (err == OK && response != NULL) {
360 CHECK(response->findInt32("err", &err));
361 if (err == OK) {
362 readFromAMessage(response, rate);
363 }
364 }
365 return err;
366}
367
368status_t NuPlayer::setSyncSettings(const AVSyncSettings &sync, float videoFpsHint) {
369 sp<AMessage> msg = new AMessage(kWhatConfigSync, this);
370 writeToAMessage(msg, sync, videoFpsHint);
371 sp<AMessage> response;
372 status_t err = msg->postAndAwaitResponse(&response);
373 if (err == OK && response != NULL) {
374 CHECK(response->findInt32("err", &err));
375 }
376 return err;
377}
378
379status_t NuPlayer::getSyncSettings(
380 AVSyncSettings *sync /* nonnull */, float *videoFps /* nonnull */) {
381 sp<AMessage> msg = new AMessage(kWhatGetSyncSettings, this);
382 sp<AMessage> response;
383 status_t err = msg->postAndAwaitResponse(&response);
384 if (err == OK && response != NULL) {
385 CHECK(response->findInt32("err", &err));
386 if (err == OK) {
387 readFromAMessage(response, sync, videoFps);
388 }
389 }
390 return err;
Wei Jia98160162015-02-04 17:01:11 -0800391}
392
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800393void NuPlayer::pause() {
Lajos Molnar1d15ab52015-03-04 16:46:34 -0800394 (new AMessage(kWhatPause, this))->post();
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800395}
396
Andreas Huber1aef2112011-01-04 14:01:29 -0800397void NuPlayer::resetAsync() {
Chong Zhang48296b72014-09-14 14:28:45 -0700398 if (mSource != NULL) {
399 // During a reset, the data source might be unresponsive already, we need to
400 // disconnect explicitly so that reads exit promptly.
401 // We can't queue the disconnect request to the looper, as it might be
402 // queued behind a stuck read and never gets processed.
403 // Doing a disconnect outside the looper to allows the pending reads to exit
404 // (either successfully or with error).
405 mSource->disconnect();
406 }
407
Lajos Molnar1d15ab52015-03-04 16:46:34 -0800408 (new AMessage(kWhatReset, this))->post();
Andreas Huber1aef2112011-01-04 14:01:29 -0800409}
410
Wei Jiae427abf2014-09-22 15:21:11 -0700411void NuPlayer::seekToAsync(int64_t seekTimeUs, bool needNotify) {
Lajos Molnar1d15ab52015-03-04 16:46:34 -0800412 sp<AMessage> msg = new AMessage(kWhatSeek, this);
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800413 msg->setInt64("seekTimeUs", seekTimeUs);
Wei Jiae427abf2014-09-22 15:21:11 -0700414 msg->setInt32("needNotify", needNotify);
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800415 msg->post();
416}
417
Andreas Huber53df1a42010-12-22 10:03:04 -0800418
Chong Zhang404fced2014-06-11 14:45:31 -0700419void NuPlayer::writeTrackInfo(
420 Parcel* reply, const sp<AMessage> format) const {
421 int32_t trackType;
422 CHECK(format->findInt32("type", &trackType));
423
Robert Shih755106e2015-04-30 14:36:45 -0700424 AString mime;
Robert Shih2e3a4252015-05-06 10:21:15 -0700425 if (!format->findString("mime", &mime)) {
426 // Java MediaPlayer only uses mimetype for subtitle and timedtext tracks.
427 // If we can't find the mimetype here it means that we wouldn't be needing
428 // the mimetype on the Java end. We still write a placeholder mime to keep the
429 // (de)serialization logic simple.
430 if (trackType == MEDIA_TRACK_TYPE_AUDIO) {
431 mime = "audio/";
432 } else if (trackType == MEDIA_TRACK_TYPE_VIDEO) {
433 mime = "video/";
434 } else {
435 TRESPASS();
436 }
437 }
Robert Shih755106e2015-04-30 14:36:45 -0700438
Chong Zhang404fced2014-06-11 14:45:31 -0700439 AString lang;
440 CHECK(format->findString("language", &lang));
441
442 reply->writeInt32(2); // write something non-zero
443 reply->writeInt32(trackType);
Robert Shih755106e2015-04-30 14:36:45 -0700444 reply->writeString16(String16(mime.c_str()));
Chong Zhang404fced2014-06-11 14:45:31 -0700445 reply->writeString16(String16(lang.c_str()));
446
447 if (trackType == MEDIA_TRACK_TYPE_SUBTITLE) {
Chong Zhang404fced2014-06-11 14:45:31 -0700448 int32_t isAuto, isDefault, isForced;
449 CHECK(format->findInt32("auto", &isAuto));
450 CHECK(format->findInt32("default", &isDefault));
451 CHECK(format->findInt32("forced", &isForced));
452
Chong Zhang404fced2014-06-11 14:45:31 -0700453 reply->writeInt32(isAuto);
454 reply->writeInt32(isDefault);
455 reply->writeInt32(isForced);
456 }
457}
458
Andreas Huberf9334412010-12-15 15:17:42 -0800459void NuPlayer::onMessageReceived(const sp<AMessage> &msg) {
460 switch (msg->what()) {
461 case kWhatSetDataSource:
462 {
Steve Block3856b092011-10-20 11:56:00 +0100463 ALOGV("kWhatSetDataSource");
Andreas Huberf9334412010-12-15 15:17:42 -0800464
465 CHECK(mSource == NULL);
466
Chong Zhang3de157d2014-08-05 20:54:44 -0700467 status_t err = OK;
Andreas Huber5bc087c2010-12-23 10:27:40 -0800468 sp<RefBase> obj;
469 CHECK(msg->findObject("source", &obj));
Chong Zhang3de157d2014-08-05 20:54:44 -0700470 if (obj != NULL) {
471 mSource = static_cast<Source *>(obj.get());
Chong Zhang3de157d2014-08-05 20:54:44 -0700472 } else {
473 err = UNKNOWN_ERROR;
474 }
Andreas Huber9575c962013-02-05 13:59:56 -0800475
476 CHECK(mDriver != NULL);
477 sp<NuPlayerDriver> driver = mDriver.promote();
478 if (driver != NULL) {
Chong Zhang3de157d2014-08-05 20:54:44 -0700479 driver->notifySetDataSourceCompleted(err);
Andreas Huber9575c962013-02-05 13:59:56 -0800480 }
481 break;
482 }
483
484 case kWhatPrepare:
485 {
486 mSource->prepareAsync();
Andreas Huberf9334412010-12-15 15:17:42 -0800487 break;
488 }
489
Chong Zhangdcb89b32013-08-06 09:44:47 -0700490 case kWhatGetTrackInfo:
491 {
Lajos Molnar3f274362015-03-05 14:35:41 -0800492 sp<AReplyToken> replyID;
Chong Zhangdcb89b32013-08-06 09:44:47 -0700493 CHECK(msg->senderAwaitsResponse(&replyID));
494
Chong Zhang404fced2014-06-11 14:45:31 -0700495 Parcel* reply;
496 CHECK(msg->findPointer("reply", (void**)&reply));
497
498 size_t inbandTracks = 0;
Chong Zhangdcb89b32013-08-06 09:44:47 -0700499 if (mSource != NULL) {
Chong Zhang404fced2014-06-11 14:45:31 -0700500 inbandTracks = mSource->getTrackCount();
501 }
502
Chong Zhanga7fa1d92014-06-11 14:49:23 -0700503 size_t ccTracks = 0;
504 if (mCCDecoder != NULL) {
505 ccTracks = mCCDecoder->getTrackCount();
506 }
507
Chong Zhang404fced2014-06-11 14:45:31 -0700508 // total track count
Chong Zhanga7fa1d92014-06-11 14:49:23 -0700509 reply->writeInt32(inbandTracks + ccTracks);
Chong Zhang404fced2014-06-11 14:45:31 -0700510
511 // write inband tracks
512 for (size_t i = 0; i < inbandTracks; ++i) {
513 writeTrackInfo(reply, mSource->getTrackInfo(i));
Chong Zhangdcb89b32013-08-06 09:44:47 -0700514 }
515
Chong Zhanga7fa1d92014-06-11 14:49:23 -0700516 // write CC track
517 for (size_t i = 0; i < ccTracks; ++i) {
518 writeTrackInfo(reply, mCCDecoder->getTrackInfo(i));
519 }
520
Chong Zhangdcb89b32013-08-06 09:44:47 -0700521 sp<AMessage> response = new AMessage;
Chong Zhangdcb89b32013-08-06 09:44:47 -0700522 response->postReply(replyID);
523 break;
524 }
525
Robert Shih7c4f0d72014-07-09 18:53:31 -0700526 case kWhatGetSelectedTrack:
527 {
528 status_t err = INVALID_OPERATION;
529 if (mSource != NULL) {
530 err = OK;
531
532 int32_t type32;
533 CHECK(msg->findInt32("type", (int32_t*)&type32));
534 media_track_type type = (media_track_type)type32;
535 ssize_t selectedTrack = mSource->getSelectedTrack(type);
536
537 Parcel* reply;
538 CHECK(msg->findPointer("reply", (void**)&reply));
539 reply->writeInt32(selectedTrack);
540 }
541
542 sp<AMessage> response = new AMessage;
543 response->setInt32("err", err);
544
Lajos Molnar3f274362015-03-05 14:35:41 -0800545 sp<AReplyToken> replyID;
Robert Shih7c4f0d72014-07-09 18:53:31 -0700546 CHECK(msg->senderAwaitsResponse(&replyID));
547 response->postReply(replyID);
548 break;
549 }
550
Chong Zhangdcb89b32013-08-06 09:44:47 -0700551 case kWhatSelectTrack:
552 {
Lajos Molnar3f274362015-03-05 14:35:41 -0800553 sp<AReplyToken> replyID;
Chong Zhangdcb89b32013-08-06 09:44:47 -0700554 CHECK(msg->senderAwaitsResponse(&replyID));
555
Chong Zhang404fced2014-06-11 14:45:31 -0700556 size_t trackIndex;
557 int32_t select;
Robert Shih6ffb1fd2014-10-29 16:24:32 -0700558 int64_t timeUs;
Chong Zhang404fced2014-06-11 14:45:31 -0700559 CHECK(msg->findSize("trackIndex", &trackIndex));
560 CHECK(msg->findInt32("select", &select));
Robert Shih6ffb1fd2014-10-29 16:24:32 -0700561 CHECK(msg->findInt64("timeUs", &timeUs));
Chong Zhang404fced2014-06-11 14:45:31 -0700562
Chong Zhangdcb89b32013-08-06 09:44:47 -0700563 status_t err = INVALID_OPERATION;
Chong Zhang404fced2014-06-11 14:45:31 -0700564
565 size_t inbandTracks = 0;
Chong Zhangdcb89b32013-08-06 09:44:47 -0700566 if (mSource != NULL) {
Chong Zhang404fced2014-06-11 14:45:31 -0700567 inbandTracks = mSource->getTrackCount();
568 }
Chong Zhanga7fa1d92014-06-11 14:49:23 -0700569 size_t ccTracks = 0;
570 if (mCCDecoder != NULL) {
571 ccTracks = mCCDecoder->getTrackCount();
572 }
Chong Zhang404fced2014-06-11 14:45:31 -0700573
574 if (trackIndex < inbandTracks) {
Robert Shih6ffb1fd2014-10-29 16:24:32 -0700575 err = mSource->selectTrack(trackIndex, select, timeUs);
Robert Shihd3b0bbb2014-07-23 15:00:25 -0700576
577 if (!select && err == OK) {
578 int32_t type;
579 sp<AMessage> info = mSource->getTrackInfo(trackIndex);
580 if (info != NULL
581 && info->findInt32("type", &type)
582 && type == MEDIA_TRACK_TYPE_TIMEDTEXT) {
583 ++mTimedTextGeneration;
584 }
585 }
Chong Zhanga7fa1d92014-06-11 14:49:23 -0700586 } else {
587 trackIndex -= inbandTracks;
588
589 if (trackIndex < ccTracks) {
590 err = mCCDecoder->selectTrack(trackIndex, select);
591 }
Chong Zhangdcb89b32013-08-06 09:44:47 -0700592 }
593
594 sp<AMessage> response = new AMessage;
595 response->setInt32("err", err);
596
597 response->postReply(replyID);
598 break;
599 }
600
Andreas Huberb7c8e912012-11-27 15:02:53 -0800601 case kWhatPollDuration:
602 {
603 int32_t generation;
604 CHECK(msg->findInt32("generation", &generation));
605
606 if (generation != mPollDurationGeneration) {
607 // stale
608 break;
609 }
610
611 int64_t durationUs;
612 if (mDriver != NULL && mSource->getDuration(&durationUs) == OK) {
613 sp<NuPlayerDriver> driver = mDriver.promote();
614 if (driver != NULL) {
615 driver->notifyDuration(durationUs);
616 }
617 }
618
619 msg->post(1000000ll); // poll again in a second.
620 break;
621 }
622
Lajos Molnar1de1e252015-04-30 18:18:34 -0700623 case kWhatSetVideoSurface:
Andreas Huberf9334412010-12-15 15:17:42 -0800624 {
Lajos Molnar1de1e252015-04-30 18:18:34 -0700625 ALOGV("kWhatSetVideoSurface");
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 Molnarf4849522014-12-10 16:58:57 -0800630 if (mSource == NULL || mSource->getFormat(false /* audio */) == NULL) {
Lajos Molnar1de1e252015-04-30 18:18:34 -0700631 performSetSurface(surface);
Wei Jiafef808d2014-10-31 17:57:05 -0700632 break;
633 }
634
635 mDeferredActions.push_back(
636 new FlushDecoderAction(FLUSH_CMD_FLUSH /* audio */,
637 FLUSH_CMD_SHUTDOWN /* video */));
638
Lajos Molnar1de1e252015-04-30 18:18:34 -0700639 mDeferredActions.push_back(new SetSurfaceAction(surface));
James Dong0d268a32012-08-31 12:18:27 -0700640
Andreas Huber57a339c2012-12-03 11:18:00 -0800641 if (obj != NULL) {
Wei Jiafef808d2014-10-31 17:57:05 -0700642 if (mStarted) {
Andy Hung73535852014-09-05 11:42:58 -0700643 // Issue a seek to refresh the video screen only if started otherwise
644 // the extractor may not yet be started and will assert.
645 // If the video decoder is not set (perhaps audio only in this case)
646 // do not perform a seek as it is not needed.
Ronghua Wua73d9e02014-10-08 15:13:29 -0700647 int64_t currentPositionUs = 0;
648 if (getCurrentPosition(&currentPositionUs) == OK) {
649 mDeferredActions.push_back(
Wei Jia29840802015-05-15 17:11:38 -0700650 new SeekAction(currentPositionUs));
Ronghua Wua73d9e02014-10-08 15:13:29 -0700651 }
Andy Hung73535852014-09-05 11:42:58 -0700652 }
Wei Jiaac428aa2014-09-02 19:01:34 -0700653
Andreas Huber57a339c2012-12-03 11:18:00 -0800654 // If there is a new surface texture, instantiate decoders
655 // again if possible.
656 mDeferredActions.push_back(
657 new SimpleAction(&NuPlayer::performScanSources));
658 }
659
Chong Zhangf8d71772014-11-26 15:08:34 -0800660 // After a flush without shutdown, decoder is paused.
661 // Don't resume it until source seek is done, otherwise it could
Chong Zhang7137ec72014-11-12 16:41:05 -0800662 // start pulling stale data too soon.
663 mDeferredActions.push_back(
Chong Zhangf8d71772014-11-26 15:08:34 -0800664 new ResumeDecoderAction(false /* needNotify */));
Chong Zhang7137ec72014-11-12 16:41:05 -0800665
Andreas Huber57a339c2012-12-03 11:18:00 -0800666 processDeferredActions();
Andreas Huberf9334412010-12-15 15:17:42 -0800667 break;
668 }
669
670 case kWhatSetAudioSink:
671 {
Steve Block3856b092011-10-20 11:56:00 +0100672 ALOGV("kWhatSetAudioSink");
Andreas Huberf9334412010-12-15 15:17:42 -0800673
674 sp<RefBase> obj;
675 CHECK(msg->findObject("sink", &obj));
676
677 mAudioSink = static_cast<MediaPlayerBase::AudioSink *>(obj.get());
678 break;
679 }
680
681 case kWhatStart:
682 {
Steve Block3856b092011-10-20 11:56:00 +0100683 ALOGV("kWhatStart");
Wei Jia94211742014-10-28 17:09:06 -0700684 if (mStarted) {
Chong Zhang8a048332015-05-06 15:16:28 -0700685 // do not resume yet if the source is still buffering
686 if (!mPausedForBuffering) {
687 onResume();
688 }
Wei Jia94211742014-10-28 17:09:06 -0700689 } else {
690 onStart();
Lajos Molnar09524832014-07-17 14:29:51 -0700691 }
Chong Zhangefbb6192015-01-30 17:13:27 -0800692 mPausedByClient = false;
Andreas Huberf9334412010-12-15 15:17:42 -0800693 break;
694 }
695
Lajos Molnar3a474aa2015-04-24 17:10:07 -0700696 case kWhatConfigPlayback:
Wei Jia98160162015-02-04 17:01:11 -0800697 {
Lajos Molnar3a474aa2015-04-24 17:10:07 -0700698 sp<AReplyToken> replyID;
699 CHECK(msg->senderAwaitsResponse(&replyID));
700 AudioPlaybackRate rate /* sanitized */;
701 readFromAMessage(msg, &rate);
702 status_t err = OK;
Wei Jia98160162015-02-04 17:01:11 -0800703 if (mRenderer != NULL) {
Lajos Molnar3a474aa2015-04-24 17:10:07 -0700704 err = mRenderer->setPlaybackSettings(rate);
705 }
706 if (err == OK) {
707 if (rate.mSpeed == 0.f) {
708 onPause();
709 // save all other settings (using non-paused speed)
710 // so we can restore them on start
711 AudioPlaybackRate newRate = rate;
712 newRate.mSpeed = mPlaybackSettings.mSpeed;
713 mPlaybackSettings = newRate;
714 } else { /* rate.mSpeed != 0.f */
715 onResume();
716 mPlaybackSettings = rate;
717 }
Wei Jia98160162015-02-04 17:01:11 -0800718 }
Ronghua Wu8db88132015-04-22 13:51:35 -0700719
720 if (mVideoDecoder != NULL) {
Ronghua Wuc8a70d32015-04-29 16:26:34 -0700721 float rate = getFrameRate();
722 if (rate > 0) {
Ronghua Wu8db88132015-04-22 13:51:35 -0700723 sp<AMessage> params = new AMessage();
Lajos Molnar3a474aa2015-04-24 17:10:07 -0700724 params->setFloat("operating-rate", rate * mPlaybackSettings.mSpeed);
Ronghua Wu8db88132015-04-22 13:51:35 -0700725 mVideoDecoder->setParameters(params);
726 }
727 }
728
Lajos Molnar3a474aa2015-04-24 17:10:07 -0700729 sp<AMessage> response = new AMessage;
730 response->setInt32("err", err);
731 response->postReply(replyID);
732 break;
733 }
734
735 case kWhatGetPlaybackSettings:
736 {
737 sp<AReplyToken> replyID;
738 CHECK(msg->senderAwaitsResponse(&replyID));
739 AudioPlaybackRate rate = mPlaybackSettings;
740 status_t err = OK;
741 if (mRenderer != NULL) {
742 err = mRenderer->getPlaybackSettings(&rate);
743 }
744 if (err == OK) {
745 // get playback settings used by renderer, as it may be
746 // slightly off due to audiosink not taking small changes.
747 mPlaybackSettings = rate;
748 if (mPaused) {
749 rate.mSpeed = 0.f;
750 }
751 }
752 sp<AMessage> response = new AMessage;
753 if (err == OK) {
754 writeToAMessage(response, rate);
755 }
756 response->setInt32("err", err);
757 response->postReply(replyID);
758 break;
759 }
760
761 case kWhatConfigSync:
762 {
763 sp<AReplyToken> replyID;
764 CHECK(msg->senderAwaitsResponse(&replyID));
765
766 ALOGV("kWhatConfigSync");
767 AVSyncSettings sync;
768 float videoFpsHint;
769 readFromAMessage(msg, &sync, &videoFpsHint);
770 status_t err = OK;
771 if (mRenderer != NULL) {
772 err = mRenderer->setSyncSettings(sync, videoFpsHint);
773 }
774 if (err == OK) {
775 mSyncSettings = sync;
776 mVideoFpsHint = videoFpsHint;
777 }
778 sp<AMessage> response = new AMessage;
779 response->setInt32("err", err);
780 response->postReply(replyID);
781 break;
782 }
783
784 case kWhatGetSyncSettings:
785 {
786 sp<AReplyToken> replyID;
787 CHECK(msg->senderAwaitsResponse(&replyID));
788 AVSyncSettings sync = mSyncSettings;
789 float videoFps = mVideoFpsHint;
790 status_t err = OK;
791 if (mRenderer != NULL) {
792 err = mRenderer->getSyncSettings(&sync, &videoFps);
793 if (err == OK) {
794 mSyncSettings = sync;
795 mVideoFpsHint = videoFps;
796 }
797 }
798 sp<AMessage> response = new AMessage;
799 if (err == OK) {
800 writeToAMessage(response, sync, videoFps);
801 }
802 response->setInt32("err", err);
803 response->postReply(replyID);
Wei Jia98160162015-02-04 17:01:11 -0800804 break;
805 }
806
Andreas Huberf9334412010-12-15 15:17:42 -0800807 case kWhatScanSources:
808 {
Andreas Huber1aef2112011-01-04 14:01:29 -0800809 int32_t generation;
810 CHECK(msg->findInt32("generation", &generation));
811 if (generation != mScanSourcesGeneration) {
812 // Drop obsolete msg.
813 break;
814 }
815
Andreas Huber5bc087c2010-12-23 10:27:40 -0800816 mScanSourcesPending = false;
817
Steve Block3856b092011-10-20 11:56:00 +0100818 ALOGV("scanning sources haveAudio=%d, haveVideo=%d",
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800819 mAudioDecoder != NULL, mVideoDecoder != NULL);
820
Andreas Huberb7c8e912012-11-27 15:02:53 -0800821 bool mHadAnySourcesBefore =
822 (mAudioDecoder != NULL) || (mVideoDecoder != NULL);
823
Andy Hung282a7e32014-08-14 15:56:34 -0700824 // initialize video before audio because successful initialization of
825 // video may change deep buffer mode of audio.
Lajos Molnar1de1e252015-04-30 18:18:34 -0700826 if (mSurface != NULL) {
Haynes Mathew George5d246ef2012-07-09 10:36:57 -0700827 instantiateDecoder(false, &mVideoDecoder);
828 }
Andreas Huberf9334412010-12-15 15:17:42 -0800829
Ronghua Wua10fd232014-11-06 16:15:20 -0800830 // Don't try to re-open audio sink if there's an existing decoder.
831 if (mAudioSink != NULL && mAudioDecoder == NULL) {
832 sp<MetaData> audioMeta = mSource->getFormatMeta(true /* audio */);
833 sp<AMessage> videoFormat = mSource->getFormat(false /* audio */);
834 audio_stream_type_t streamType = mAudioSink->getAudioStreamType();
Andy Hung202bce12014-12-03 11:47:36 -0800835 const bool hasVideo = (videoFormat != NULL);
836 const bool canOffload = canOffloadStream(
Ronghua Wu02cb98d2015-05-27 11:02:54 -0700837 audioMeta, hasVideo, mSource->isStreaming(), streamType);
Ronghua Wua10fd232014-11-06 16:15:20 -0800838 if (canOffload) {
839 if (!mOffloadAudio) {
840 mRenderer->signalEnableOffloadAudio();
841 }
Andy Hung282a7e32014-08-14 15:56:34 -0700842 // open audio sink early under offload mode.
843 sp<AMessage> format = mSource->getFormat(true /*audio*/);
Andy Hung202bce12014-12-03 11:47:36 -0800844 tryOpenAudioSinkForOffload(format, hasVideo);
Andy Hung282a7e32014-08-14 15:56:34 -0700845 }
Andreas Huber5bc087c2010-12-23 10:27:40 -0800846 instantiateDecoder(true, &mAudioDecoder);
Andreas Huberf9334412010-12-15 15:17:42 -0800847 }
848
Andreas Huberb7c8e912012-11-27 15:02:53 -0800849 if (!mHadAnySourcesBefore
850 && (mAudioDecoder != NULL || mVideoDecoder != NULL)) {
851 // This is the first time we've found anything playable.
852
Andreas Huber9575c962013-02-05 13:59:56 -0800853 if (mSourceFlags & Source::FLAG_DYNAMIC_DURATION) {
Andreas Huberb7c8e912012-11-27 15:02:53 -0800854 schedulePollDuration();
855 }
856 }
857
Andreas Hubereac68ba2011-09-27 12:12:25 -0700858 status_t err;
859 if ((err = mSource->feedMoreTSData()) != OK) {
Andreas Huber1aef2112011-01-04 14:01:29 -0800860 if (mAudioDecoder == NULL && mVideoDecoder == NULL) {
861 // We're not currently decoding anything (no audio or
862 // video tracks found) and we just ran out of input data.
Andreas Hubereac68ba2011-09-27 12:12:25 -0700863
864 if (err == ERROR_END_OF_STREAM) {
865 notifyListener(MEDIA_PLAYBACK_COMPLETE, 0, 0);
866 } else {
867 notifyListener(MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, err);
868 }
Andreas Huber1aef2112011-01-04 14:01:29 -0800869 }
Andreas Huberf9334412010-12-15 15:17:42 -0800870 break;
871 }
872
Andreas Huberfbe9d812012-08-31 14:05:27 -0700873 if ((mAudioDecoder == NULL && mAudioSink != NULL)
Lajos Molnar1de1e252015-04-30 18:18:34 -0700874 || (mVideoDecoder == NULL && mSurface != NULL)) {
Andreas Huberf9334412010-12-15 15:17:42 -0800875 msg->post(100000ll);
Andreas Huber5bc087c2010-12-23 10:27:40 -0800876 mScanSourcesPending = true;
Andreas Huberf9334412010-12-15 15:17:42 -0800877 }
878 break;
879 }
880
881 case kWhatVideoNotify:
882 case kWhatAudioNotify:
883 {
884 bool audio = msg->what() == kWhatAudioNotify;
885
Wei Jia88703c32014-08-06 11:24:07 -0700886 int32_t currentDecoderGeneration =
887 (audio? mAudioDecoderGeneration : mVideoDecoderGeneration);
888 int32_t requesterGeneration = currentDecoderGeneration - 1;
889 CHECK(msg->findInt32("generation", &requesterGeneration));
890
891 if (requesterGeneration != currentDecoderGeneration) {
892 ALOGV("got message from old %s decoder, generation(%d:%d)",
893 audio ? "audio" : "video", requesterGeneration,
894 currentDecoderGeneration);
895 sp<AMessage> reply;
896 if (!(msg->findMessage("reply", &reply))) {
897 return;
898 }
899
900 reply->setInt32("err", INFO_DISCONTINUITY);
901 reply->post();
902 return;
903 }
904
Andreas Huberf9334412010-12-15 15:17:42 -0800905 int32_t what;
Lajos Molnar1cd13982014-01-17 15:12:51 -0800906 CHECK(msg->findInt32("what", &what));
Andreas Huberf9334412010-12-15 15:17:42 -0800907
Chong Zhang7137ec72014-11-12 16:41:05 -0800908 if (what == DecoderBase::kWhatInputDiscontinuity) {
909 int32_t formatChange;
910 CHECK(msg->findInt32("formatChange", &formatChange));
Andreas Huberf9334412010-12-15 15:17:42 -0800911
Chong Zhang7137ec72014-11-12 16:41:05 -0800912 ALOGV("%s discontinuity: formatChange %d",
913 audio ? "audio" : "video", formatChange);
914
915 if (formatChange) {
916 mDeferredActions.push_back(
917 new FlushDecoderAction(
918 audio ? FLUSH_CMD_SHUTDOWN : FLUSH_CMD_NONE,
919 audio ? FLUSH_CMD_NONE : FLUSH_CMD_SHUTDOWN));
Andreas Huberf9334412010-12-15 15:17:42 -0800920 }
Chong Zhang7137ec72014-11-12 16:41:05 -0800921
922 mDeferredActions.push_back(
923 new SimpleAction(
924 &NuPlayer::performScanSources));
925
926 processDeferredActions();
927 } else if (what == DecoderBase::kWhatEOS) {
Andreas Huberdc9bacd2011-09-26 10:53:29 -0700928 int32_t err;
Lajos Molnar1cd13982014-01-17 15:12:51 -0800929 CHECK(msg->findInt32("err", &err));
Andreas Huberdc9bacd2011-09-26 10:53:29 -0700930
931 if (err == ERROR_END_OF_STREAM) {
Steve Block3856b092011-10-20 11:56:00 +0100932 ALOGV("got %s decoder EOS", audio ? "audio" : "video");
Andreas Huberdc9bacd2011-09-26 10:53:29 -0700933 } else {
Steve Block3856b092011-10-20 11:56:00 +0100934 ALOGV("got %s decoder EOS w/ error %d",
Andreas Huberdc9bacd2011-09-26 10:53:29 -0700935 audio ? "audio" : "video",
936 err);
937 }
938
939 mRenderer->queueEOS(audio, err);
Chong Zhang7137ec72014-11-12 16:41:05 -0800940 } else if (what == DecoderBase::kWhatFlushCompleted) {
Steve Block3856b092011-10-20 11:56:00 +0100941 ALOGV("decoder %s flush completed", audio ? "audio" : "video");
Andreas Huberf9334412010-12-15 15:17:42 -0800942
Andy Hung8d121d42014-10-03 09:53:53 -0700943 handleFlushComplete(audio, true /* isDecoder */);
Andreas Huber3831a062010-12-21 10:22:33 -0800944 finishFlushIfPossible();
Chong Zhang7137ec72014-11-12 16:41:05 -0800945 } else if (what == DecoderBase::kWhatVideoSizeChanged) {
Lajos Molnar1cd13982014-01-17 15:12:51 -0800946 sp<AMessage> format;
947 CHECK(msg->findMessage("format", &format));
948
Wei Jiac6cfd702014-11-11 16:33:20 -0800949 sp<AMessage> inputFormat =
950 mSource->getFormat(false /* audio */);
Andreas Huber3831a062010-12-21 10:22:33 -0800951
Wei Jiac6cfd702014-11-11 16:33:20 -0800952 updateVideoSize(inputFormat, format);
Chong Zhang7137ec72014-11-12 16:41:05 -0800953 } else if (what == DecoderBase::kWhatShutdownCompleted) {
Steve Block3856b092011-10-20 11:56:00 +0100954 ALOGV("%s shutdown completed", audio ? "audio" : "video");
Andreas Huber3831a062010-12-21 10:22:33 -0800955 if (audio) {
956 mAudioDecoder.clear();
Wei Jia57568df2014-09-22 10:16:29 -0700957 ++mAudioDecoderGeneration;
Andreas Huber3831a062010-12-21 10:22:33 -0800958
959 CHECK_EQ((int)mFlushingAudio, (int)SHUTTING_DOWN_DECODER);
960 mFlushingAudio = SHUT_DOWN;
961 } else {
962 mVideoDecoder.clear();
Wei Jia57568df2014-09-22 10:16:29 -0700963 ++mVideoDecoderGeneration;
Andreas Huber3831a062010-12-21 10:22:33 -0800964
965 CHECK_EQ((int)mFlushingVideo, (int)SHUTTING_DOWN_DECODER);
966 mFlushingVideo = SHUT_DOWN;
967 }
968
969 finishFlushIfPossible();
Chong Zhangf8d71772014-11-26 15:08:34 -0800970 } else if (what == DecoderBase::kWhatResumeCompleted) {
971 finishResume();
Chong Zhang7137ec72014-11-12 16:41:05 -0800972 } else if (what == DecoderBase::kWhatError) {
Chong Zhangf4c0a942014-08-11 15:14:10 -0700973 status_t err;
Andy Hung2abde2c2014-09-30 14:40:32 -0700974 if (!msg->findInt32("err", &err) || err == OK) {
Chong Zhangf4c0a942014-08-11 15:14:10 -0700975 err = UNKNOWN_ERROR;
976 }
Andy Hungcf31f1e2014-09-23 14:59:01 -0700977
Andy Hung2abde2c2014-09-30 14:40:32 -0700978 // Decoder errors can be due to Source (e.g. from streaming),
979 // or from decoding corrupted bitstreams, or from other decoder
980 // MediaCodec operations (e.g. from an ongoing reset or seek).
Andy Hung202bce12014-12-03 11:47:36 -0800981 // They may also be due to openAudioSink failure at
982 // decoder start or after a format change.
Andy Hung2abde2c2014-09-30 14:40:32 -0700983 //
984 // We try to gracefully shut down the affected decoder if possible,
985 // rather than trying to force the shutdown with something
986 // similar to performReset(). This method can lead to a hang
987 // if MediaCodec functions block after an error, but they should
988 // typically return INVALID_OPERATION instead of blocking.
989
990 FlushStatus *flushing = audio ? &mFlushingAudio : &mFlushingVideo;
991 ALOGE("received error(%#x) from %s decoder, flushing(%d), now shutting down",
992 err, audio ? "audio" : "video", *flushing);
993
994 switch (*flushing) {
995 case NONE:
996 mDeferredActions.push_back(
Wei Jiafef808d2014-10-31 17:57:05 -0700997 new FlushDecoderAction(
998 audio ? FLUSH_CMD_SHUTDOWN : FLUSH_CMD_NONE,
999 audio ? FLUSH_CMD_NONE : FLUSH_CMD_SHUTDOWN));
Andy Hung2abde2c2014-09-30 14:40:32 -07001000 processDeferredActions();
1001 break;
1002 case FLUSHING_DECODER:
1003 *flushing = FLUSHING_DECODER_SHUTDOWN; // initiate shutdown after flush.
1004 break; // Wait for flush to complete.
1005 case FLUSHING_DECODER_SHUTDOWN:
1006 break; // Wait for flush to complete.
1007 case SHUTTING_DOWN_DECODER:
1008 break; // Wait for shutdown to complete.
1009 case FLUSHED:
1010 // Widevine source reads must stop before releasing the video decoder.
1011 if (!audio && mSource != NULL && mSourceFlags & Source::FLAG_SECURE) {
1012 mSource->stop();
1013 }
1014 getDecoder(audio)->initiateShutdown(); // In the middle of a seek.
1015 *flushing = SHUTTING_DOWN_DECODER; // Shut down.
1016 break;
1017 case SHUT_DOWN:
1018 finishFlushIfPossible(); // Should not occur.
1019 break; // Finish anyways.
Marco Nelissen9e2b7912014-08-18 16:13:03 -07001020 }
Andy Hung2abde2c2014-09-30 14:40:32 -07001021 notifyListener(MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, err);
Lajos Molnar1cd13982014-01-17 15:12:51 -08001022 } else {
1023 ALOGV("Unhandled decoder notification %d '%c%c%c%c'.",
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001024 what,
1025 what >> 24,
1026 (what >> 16) & 0xff,
1027 (what >> 8) & 0xff,
1028 what & 0xff);
Andreas Huberf9334412010-12-15 15:17:42 -08001029 }
1030
1031 break;
1032 }
1033
1034 case kWhatRendererNotify:
1035 {
Wei Jia57568df2014-09-22 10:16:29 -07001036 int32_t requesterGeneration = mRendererGeneration - 1;
1037 CHECK(msg->findInt32("generation", &requesterGeneration));
1038 if (requesterGeneration != mRendererGeneration) {
1039 ALOGV("got message from old renderer, generation(%d:%d)",
1040 requesterGeneration, mRendererGeneration);
1041 return;
1042 }
1043
Andreas Huberf9334412010-12-15 15:17:42 -08001044 int32_t what;
1045 CHECK(msg->findInt32("what", &what));
1046
1047 if (what == Renderer::kWhatEOS) {
1048 int32_t audio;
1049 CHECK(msg->findInt32("audio", &audio));
1050
Andreas Huberc92fd242011-08-16 13:48:44 -07001051 int32_t finalResult;
1052 CHECK(msg->findInt32("finalResult", &finalResult));
1053
Andreas Huberf9334412010-12-15 15:17:42 -08001054 if (audio) {
1055 mAudioEOS = true;
1056 } else {
1057 mVideoEOS = true;
1058 }
1059
Andreas Huberc92fd242011-08-16 13:48:44 -07001060 if (finalResult == ERROR_END_OF_STREAM) {
Steve Block3856b092011-10-20 11:56:00 +01001061 ALOGV("reached %s EOS", audio ? "audio" : "video");
Andreas Huberc92fd242011-08-16 13:48:44 -07001062 } else {
Steve Block29357bc2012-01-06 19:20:56 +00001063 ALOGE("%s track encountered an error (%d)",
Andreas Huberc92fd242011-08-16 13:48:44 -07001064 audio ? "audio" : "video", finalResult);
1065
1066 notifyListener(
1067 MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, finalResult);
1068 }
Andreas Huberf9334412010-12-15 15:17:42 -08001069
1070 if ((mAudioEOS || mAudioDecoder == NULL)
1071 && (mVideoEOS || mVideoDecoder == NULL)) {
1072 notifyListener(MEDIA_PLAYBACK_COMPLETE, 0, 0);
1073 }
Andreas Huber3fe62152011-09-16 15:09:22 -07001074 } else if (what == Renderer::kWhatFlushComplete) {
Andreas Huberf9334412010-12-15 15:17:42 -08001075 int32_t audio;
1076 CHECK(msg->findInt32("audio", &audio));
1077
Steve Block3856b092011-10-20 11:56:00 +01001078 ALOGV("renderer %s flush completed.", audio ? "audio" : "video");
Andy Hung8d121d42014-10-03 09:53:53 -07001079 handleFlushComplete(audio, false /* isDecoder */);
1080 finishFlushIfPossible();
James Dongf57b4ea2012-07-20 13:38:36 -07001081 } else if (what == Renderer::kWhatVideoRenderingStart) {
1082 notifyListener(MEDIA_INFO, MEDIA_INFO_RENDERING_START, 0);
Lajos Molnarcbaffcf2013-08-14 18:30:38 -07001083 } else if (what == Renderer::kWhatMediaRenderingStart) {
1084 ALOGV("media rendering started");
1085 notifyListener(MEDIA_STARTED, 0, 0);
Ronghua Wufaeb0f22015-05-21 12:20:21 -07001086 } else if (what == Renderer::kWhatAudioTearDown) {
Wei Jia3a2956d2014-07-22 16:01:33 -07001087 int64_t positionUs;
1088 CHECK(msg->findInt64("positionUs", &positionUs));
Ronghua Wu08529172014-10-02 16:55:52 -07001089 int32_t reason;
1090 CHECK(msg->findInt32("reason", &reason));
Ronghua Wufaeb0f22015-05-21 12:20:21 -07001091 ALOGV("Tear down audio with reason %d.", reason);
Andy Hung282a7e32014-08-14 15:56:34 -07001092 closeAudioSink();
Wei Jia3a2956d2014-07-22 16:01:33 -07001093 mAudioDecoder.clear();
Wei Jia57568df2014-09-22 10:16:29 -07001094 ++mAudioDecoderGeneration;
Chong Zhang7137ec72014-11-12 16:41:05 -08001095 mRenderer->flush(
1096 true /* audio */, false /* notifyComplete */);
Wei Jia3a2956d2014-07-22 16:01:33 -07001097 if (mVideoDecoder != NULL) {
Chong Zhang7137ec72014-11-12 16:41:05 -08001098 mRenderer->flush(
1099 false /* audio */, false /* notifyComplete */);
Wei Jia3a2956d2014-07-22 16:01:33 -07001100 }
Wei Jia3a2956d2014-07-22 16:01:33 -07001101
Wei Jia29840802015-05-15 17:11:38 -07001102 performSeek(positionUs);
Ronghua Wufaeb0f22015-05-21 12:20:21 -07001103
Ronghua Wu08529172014-10-02 16:55:52 -07001104 if (reason == Renderer::kDueToError) {
Ronghua Wufaeb0f22015-05-21 12:20:21 -07001105 sp<MetaData> audioMeta = mSource->getFormatMeta(true /* audio */);
1106 sp<AMessage> videoFormat = mSource->getFormat(false /* audio */);
1107 audio_stream_type_t streamType = mAudioSink->getAudioStreamType();
1108 const bool hasVideo = (videoFormat != NULL);
1109 const bool canOffload = canOffloadStream(
Ronghua Wu02cb98d2015-05-27 11:02:54 -07001110 audioMeta, hasVideo, mSource->isStreaming(), streamType);
Ronghua Wufaeb0f22015-05-21 12:20:21 -07001111 if (canOffload) {
1112 mRenderer->signalEnableOffloadAudio();
1113 sp<AMessage> format = mSource->getFormat(true /*audio*/);
1114 tryOpenAudioSinkForOffload(format, hasVideo);
1115 } else {
1116 mRenderer->signalDisableOffloadAudio();
1117 mOffloadAudio = false;
1118 }
Ronghua Wu08529172014-10-02 16:55:52 -07001119 instantiateDecoder(true /* audio */, &mAudioDecoder);
1120 }
Andreas Huberf9334412010-12-15 15:17:42 -08001121 }
1122 break;
1123 }
1124
1125 case kWhatMoreDataQueued:
1126 {
1127 break;
1128 }
1129
Andreas Huber1aef2112011-01-04 14:01:29 -08001130 case kWhatReset:
1131 {
Steve Block3856b092011-10-20 11:56:00 +01001132 ALOGV("kWhatReset");
Andreas Huber1aef2112011-01-04 14:01:29 -08001133
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001134 mDeferredActions.push_back(
Wei Jiafef808d2014-10-31 17:57:05 -07001135 new FlushDecoderAction(
1136 FLUSH_CMD_SHUTDOWN /* audio */,
1137 FLUSH_CMD_SHUTDOWN /* video */));
Andreas Huberb7c8e912012-11-27 15:02:53 -08001138
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001139 mDeferredActions.push_back(
1140 new SimpleAction(&NuPlayer::performReset));
Andreas Huberb58ce9f2011-11-28 16:27:35 -08001141
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001142 processDeferredActions();
Andreas Huber1aef2112011-01-04 14:01:29 -08001143 break;
1144 }
1145
Andreas Huber43c3e6c2011-01-05 12:17:08 -08001146 case kWhatSeek:
1147 {
1148 int64_t seekTimeUs;
Wei Jiae427abf2014-09-22 15:21:11 -07001149 int32_t needNotify;
Andreas Huber43c3e6c2011-01-05 12:17:08 -08001150 CHECK(msg->findInt64("seekTimeUs", &seekTimeUs));
Wei Jiae427abf2014-09-22 15:21:11 -07001151 CHECK(msg->findInt32("needNotify", &needNotify));
Andreas Huber43c3e6c2011-01-05 12:17:08 -08001152
Wei Jiae427abf2014-09-22 15:21:11 -07001153 ALOGV("kWhatSeek seekTimeUs=%lld us, needNotify=%d",
Lajos Molnar6d339f12015-04-17 16:15:53 -07001154 (long long)seekTimeUs, needNotify);
Andreas Huber43c3e6c2011-01-05 12:17:08 -08001155
Wei Jia1061c9c2015-05-19 16:02:17 -07001156 if (!mStarted) {
1157 // Seek before the player is started. In order to preview video,
1158 // need to start the player and pause it. This branch is called
1159 // only once if needed. After the player is started, any seek
1160 // operation will go through normal path.
1161 // All cases, including audio-only, are handled in the same way
1162 // for the sake of simplicity.
1163 onStart(seekTimeUs);
1164 onPause();
1165 mPausedByClient = true;
1166 if (needNotify) {
1167 notifyDriverSeekComplete();
1168 }
1169 break;
1170 }
1171
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001172 mDeferredActions.push_back(
Wei Jiafef808d2014-10-31 17:57:05 -07001173 new FlushDecoderAction(FLUSH_CMD_FLUSH /* audio */,
1174 FLUSH_CMD_FLUSH /* video */));
Andreas Huber43c3e6c2011-01-05 12:17:08 -08001175
Wei Jiae427abf2014-09-22 15:21:11 -07001176 mDeferredActions.push_back(
Wei Jia29840802015-05-15 17:11:38 -07001177 new SeekAction(seekTimeUs));
Andreas Huber43c3e6c2011-01-05 12:17:08 -08001178
Chong Zhangf8d71772014-11-26 15:08:34 -08001179 // After a flush without shutdown, decoder is paused.
1180 // Don't resume it until source seek is done, otherwise it could
Chong Zhang7137ec72014-11-12 16:41:05 -08001181 // start pulling stale data too soon.
1182 mDeferredActions.push_back(
Chong Zhangf8d71772014-11-26 15:08:34 -08001183 new ResumeDecoderAction(needNotify));
Chong Zhang7137ec72014-11-12 16:41:05 -08001184
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001185 processDeferredActions();
Andreas Huber43c3e6c2011-01-05 12:17:08 -08001186 break;
1187 }
1188
Andreas Huberb4082222011-01-20 15:23:04 -08001189 case kWhatPause:
1190 {
Chong Zhangefbb6192015-01-30 17:13:27 -08001191 onPause();
1192 mPausedByClient = true;
Andreas Huberb4082222011-01-20 15:23:04 -08001193 break;
1194 }
1195
Andreas Huberb5f25f02013-02-05 10:14:26 -08001196 case kWhatSourceNotify:
1197 {
Andreas Huber9575c962013-02-05 13:59:56 -08001198 onSourceNotify(msg);
Andreas Huberb5f25f02013-02-05 10:14:26 -08001199 break;
1200 }
1201
Chong Zhanga7fa1d92014-06-11 14:49:23 -07001202 case kWhatClosedCaptionNotify:
1203 {
1204 onClosedCaptionNotify(msg);
1205 break;
1206 }
1207
Andreas Huberf9334412010-12-15 15:17:42 -08001208 default:
1209 TRESPASS();
1210 break;
1211 }
1212}
1213
Wei Jia94211742014-10-28 17:09:06 -07001214void NuPlayer::onResume() {
Chong Zhangefbb6192015-01-30 17:13:27 -08001215 if (!mPaused) {
1216 return;
1217 }
1218 mPaused = false;
Wei Jia94211742014-10-28 17:09:06 -07001219 if (mSource != NULL) {
1220 mSource->resume();
1221 } else {
1222 ALOGW("resume called when source is gone or not set");
1223 }
1224 // |mAudioDecoder| may have been released due to the pause timeout, so re-create it if
1225 // needed.
1226 if (audioDecoderStillNeeded() && mAudioDecoder == NULL) {
1227 instantiateDecoder(true /* audio */, &mAudioDecoder);
1228 }
1229 if (mRenderer != NULL) {
1230 mRenderer->resume();
1231 } else {
1232 ALOGW("resume called when renderer is gone or not set");
1233 }
1234}
1235
Lajos Molnarfcd3e942015-03-31 10:06:48 -07001236status_t NuPlayer::onInstantiateSecureDecoders() {
1237 status_t err;
1238 if (!(mSourceFlags & Source::FLAG_SECURE)) {
1239 return BAD_TYPE;
1240 }
1241
1242 if (mRenderer != NULL) {
1243 ALOGE("renderer should not be set when instantiating secure decoders");
1244 return UNKNOWN_ERROR;
1245 }
1246
1247 // TRICKY: We rely on mRenderer being null, so that decoder does not start requesting
1248 // data on instantiation.
Lajos Molnar1de1e252015-04-30 18:18:34 -07001249 if (mSurface != NULL) {
Lajos Molnarfcd3e942015-03-31 10:06:48 -07001250 err = instantiateDecoder(false, &mVideoDecoder);
1251 if (err != OK) {
1252 return err;
1253 }
1254 }
1255
1256 if (mAudioSink != NULL) {
1257 err = instantiateDecoder(true, &mAudioDecoder);
1258 if (err != OK) {
1259 return err;
1260 }
1261 }
1262 return OK;
1263}
1264
Wei Jia1061c9c2015-05-19 16:02:17 -07001265void NuPlayer::onStart(int64_t startPositionUs) {
Wei Jia94211742014-10-28 17:09:06 -07001266 mOffloadAudio = false;
1267 mAudioEOS = false;
1268 mVideoEOS = false;
Wei Jia94211742014-10-28 17:09:06 -07001269 mStarted = true;
1270
Wei Jia94211742014-10-28 17:09:06 -07001271 mSource->start();
Wei Jia1061c9c2015-05-19 16:02:17 -07001272 if (startPositionUs > 0) {
1273 performSeek(startPositionUs);
1274 }
Wei Jia94211742014-10-28 17:09:06 -07001275
1276 uint32_t flags = 0;
1277
1278 if (mSource->isRealTime()) {
1279 flags |= Renderer::FLAG_REAL_TIME;
1280 }
1281
1282 sp<MetaData> audioMeta = mSource->getFormatMeta(true /* audio */);
1283 audio_stream_type_t streamType = AUDIO_STREAM_MUSIC;
1284 if (mAudioSink != NULL) {
1285 streamType = mAudioSink->getAudioStreamType();
1286 }
1287
1288 sp<AMessage> videoFormat = mSource->getFormat(false /* audio */);
1289
1290 mOffloadAudio =
Ronghua Wu02cb98d2015-05-27 11:02:54 -07001291 canOffloadStream(audioMeta, (videoFormat != NULL), mSource->isStreaming(), streamType);
Wei Jia94211742014-10-28 17:09:06 -07001292 if (mOffloadAudio) {
1293 flags |= Renderer::FLAG_OFFLOAD_AUDIO;
1294 }
1295
Lajos Molnar1d15ab52015-03-04 16:46:34 -08001296 sp<AMessage> notify = new AMessage(kWhatRendererNotify, this);
Wei Jia94211742014-10-28 17:09:06 -07001297 ++mRendererGeneration;
1298 notify->setInt32("generation", mRendererGeneration);
1299 mRenderer = new Renderer(mAudioSink, notify, flags);
Wei Jia94211742014-10-28 17:09:06 -07001300 mRendererLooper = new ALooper;
1301 mRendererLooper->setName("NuPlayerRenderer");
1302 mRendererLooper->start(false, false, ANDROID_PRIORITY_AUDIO);
1303 mRendererLooper->registerHandler(mRenderer);
Lajos Molnar3a474aa2015-04-24 17:10:07 -07001304
1305 status_t err = mRenderer->setPlaybackSettings(mPlaybackSettings);
1306 if (err != OK) {
1307 mSource->stop();
1308 notifyListener(MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, err);
1309 return;
Wei Jiac8206ff2015-03-04 13:59:37 -08001310 }
Wei Jia94211742014-10-28 17:09:06 -07001311
Ronghua Wuc8a70d32015-04-29 16:26:34 -07001312 float rate = getFrameRate();
1313 if (rate > 0) {
Wei Jia94211742014-10-28 17:09:06 -07001314 mRenderer->setVideoFrameRate(rate);
1315 }
1316
Wei Jiac6cfd702014-11-11 16:33:20 -08001317 if (mVideoDecoder != NULL) {
1318 mVideoDecoder->setRenderer(mRenderer);
1319 }
1320 if (mAudioDecoder != NULL) {
1321 mAudioDecoder->setRenderer(mRenderer);
1322 }
1323
Wei Jia94211742014-10-28 17:09:06 -07001324 postScanSources();
1325}
1326
Chong Zhangefbb6192015-01-30 17:13:27 -08001327void NuPlayer::onPause() {
1328 if (mPaused) {
1329 return;
1330 }
1331 mPaused = true;
1332 if (mSource != NULL) {
1333 mSource->pause();
1334 } else {
1335 ALOGW("pause called when source is gone or not set");
1336 }
1337 if (mRenderer != NULL) {
1338 mRenderer->pause();
1339 } else {
1340 ALOGW("pause called when renderer is gone or not set");
1341 }
1342}
1343
Ronghua Wud7988b12014-10-03 15:19:10 -07001344bool NuPlayer::audioDecoderStillNeeded() {
1345 // Audio decoder is no longer needed if it's in shut/shutting down status.
1346 return ((mFlushingAudio != SHUT_DOWN) && (mFlushingAudio != SHUTTING_DOWN_DECODER));
1347}
1348
Andy Hung8d121d42014-10-03 09:53:53 -07001349void NuPlayer::handleFlushComplete(bool audio, bool isDecoder) {
1350 // We wait for both the decoder flush and the renderer flush to complete
1351 // before entering either the FLUSHED or the SHUTTING_DOWN_DECODER state.
1352
1353 mFlushComplete[audio][isDecoder] = true;
1354 if (!mFlushComplete[audio][!isDecoder]) {
1355 return;
1356 }
1357
1358 FlushStatus *state = audio ? &mFlushingAudio : &mFlushingVideo;
1359 switch (*state) {
1360 case FLUSHING_DECODER:
1361 {
1362 *state = FLUSHED;
Andy Hung8d121d42014-10-03 09:53:53 -07001363 break;
1364 }
1365
1366 case FLUSHING_DECODER_SHUTDOWN:
1367 {
1368 *state = SHUTTING_DOWN_DECODER;
1369
1370 ALOGV("initiating %s decoder shutdown", audio ? "audio" : "video");
1371 if (!audio) {
Andy Hung8d121d42014-10-03 09:53:53 -07001372 // Widevine source reads must stop before releasing the video decoder.
1373 if (mSource != NULL && mSourceFlags & Source::FLAG_SECURE) {
1374 mSource->stop();
1375 }
1376 }
1377 getDecoder(audio)->initiateShutdown();
1378 break;
1379 }
1380
1381 default:
1382 // decoder flush completes only occur in a flushing state.
1383 LOG_ALWAYS_FATAL_IF(isDecoder, "decoder flush in invalid state %d", *state);
1384 break;
1385 }
1386}
1387
Andreas Huber3831a062010-12-21 10:22:33 -08001388void NuPlayer::finishFlushIfPossible() {
Wei Jia53904f32014-07-29 10:22:53 -07001389 if (mFlushingAudio != NONE && mFlushingAudio != FLUSHED
1390 && mFlushingAudio != SHUT_DOWN) {
Andreas Huber3831a062010-12-21 10:22:33 -08001391 return;
1392 }
1393
Wei Jia53904f32014-07-29 10:22:53 -07001394 if (mFlushingVideo != NONE && mFlushingVideo != FLUSHED
1395 && mFlushingVideo != SHUT_DOWN) {
Andreas Huber3831a062010-12-21 10:22:33 -08001396 return;
1397 }
1398
Steve Block3856b092011-10-20 11:56:00 +01001399 ALOGV("both audio and video are flushed now.");
Andreas Huber3831a062010-12-21 10:22:33 -08001400
Andreas Huber3831a062010-12-21 10:22:33 -08001401 mFlushingAudio = NONE;
1402 mFlushingVideo = NONE;
Andreas Huber3831a062010-12-21 10:22:33 -08001403
Andy Hung8d121d42014-10-03 09:53:53 -07001404 clearFlushComplete();
1405
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001406 processDeferredActions();
Andreas Huber1aef2112011-01-04 14:01:29 -08001407}
1408
1409void NuPlayer::postScanSources() {
1410 if (mScanSourcesPending) {
1411 return;
1412 }
1413
Lajos Molnar1d15ab52015-03-04 16:46:34 -08001414 sp<AMessage> msg = new AMessage(kWhatScanSources, this);
Andreas Huber1aef2112011-01-04 14:01:29 -08001415 msg->setInt32("generation", mScanSourcesGeneration);
1416 msg->post();
1417
1418 mScanSourcesPending = true;
1419}
1420
Andy Hung202bce12014-12-03 11:47:36 -08001421void NuPlayer::tryOpenAudioSinkForOffload(const sp<AMessage> &format, bool hasVideo) {
1422 // Note: This is called early in NuPlayer to determine whether offloading
1423 // is possible; otherwise the decoders call the renderer openAudioSink directly.
Andy Hung282a7e32014-08-14 15:56:34 -07001424
Andy Hung202bce12014-12-03 11:47:36 -08001425 status_t err = mRenderer->openAudioSink(
1426 format, true /* offloadOnly */, hasVideo, AUDIO_OUTPUT_FLAG_NONE, &mOffloadAudio);
1427 if (err != OK) {
1428 // Any failure we turn off mOffloadAudio.
1429 mOffloadAudio = false;
1430 } else if (mOffloadAudio) {
Chong Zhang3b9eb1f2014-10-15 17:05:08 -07001431 sp<MetaData> audioMeta =
1432 mSource->getFormatMeta(true /* audio */);
1433 sendMetaDataToHal(mAudioSink, audioMeta);
Andy Hung282a7e32014-08-14 15:56:34 -07001434 }
1435}
1436
1437void NuPlayer::closeAudioSink() {
Chong Zhang3b9eb1f2014-10-15 17:05:08 -07001438 mRenderer->closeAudioSink();
Andy Hung282a7e32014-08-14 15:56:34 -07001439}
1440
Chong Zhang7137ec72014-11-12 16:41:05 -08001441status_t NuPlayer::instantiateDecoder(bool audio, sp<DecoderBase> *decoder) {
Andreas Huberf9334412010-12-15 15:17:42 -08001442 if (*decoder != NULL) {
1443 return OK;
1444 }
1445
Andreas Huber84066782011-08-16 09:34:26 -07001446 sp<AMessage> format = mSource->getFormat(audio);
Andreas Huberf9334412010-12-15 15:17:42 -08001447
Andreas Huber84066782011-08-16 09:34:26 -07001448 if (format == NULL) {
Andreas Huberf9334412010-12-15 15:17:42 -08001449 return -EWOULDBLOCK;
1450 }
1451
Ronghua Wu8db88132015-04-22 13:51:35 -07001452 format->setInt32("priority", 0 /* realtime */);
1453
Andreas Huber3fe62152011-09-16 15:09:22 -07001454 if (!audio) {
Andreas Huber84066782011-08-16 09:34:26 -07001455 AString mime;
1456 CHECK(format->findString("mime", &mime));
Chong Zhanga7fa1d92014-06-11 14:49:23 -07001457
Lajos Molnar1d15ab52015-03-04 16:46:34 -08001458 sp<AMessage> ccNotify = new AMessage(kWhatClosedCaptionNotify, this);
Chong Zhang341ab6e2015-02-04 13:37:18 -08001459 if (mCCDecoder == NULL) {
1460 mCCDecoder = new CCDecoder(ccNotify);
1461 }
Lajos Molnar09524832014-07-17 14:29:51 -07001462
1463 if (mSourceFlags & Source::FLAG_SECURE) {
1464 format->setInt32("secure", true);
1465 }
Chong Zhang17134602015-01-07 16:14:34 -08001466
1467 if (mSourceFlags & Source::FLAG_PROTECTED) {
1468 format->setInt32("protected", true);
1469 }
Ronghua Wu8db88132015-04-22 13:51:35 -07001470
Ronghua Wuc8a70d32015-04-29 16:26:34 -07001471 float rate = getFrameRate();
1472 if (rate > 0) {
Lajos Molnar3a474aa2015-04-24 17:10:07 -07001473 format->setFloat("operating-rate", rate * mPlaybackSettings.mSpeed);
Ronghua Wu8db88132015-04-22 13:51:35 -07001474 }
Andreas Huber3fe62152011-09-16 15:09:22 -07001475 }
1476
Wei Jiabc2fb722014-07-08 16:37:57 -07001477 if (audio) {
Lajos Molnar1d15ab52015-03-04 16:46:34 -08001478 sp<AMessage> notify = new AMessage(kWhatAudioNotify, this);
Wei Jia88703c32014-08-06 11:24:07 -07001479 ++mAudioDecoderGeneration;
1480 notify->setInt32("generation", mAudioDecoderGeneration);
1481
Wei Jiabc2fb722014-07-08 16:37:57 -07001482 if (mOffloadAudio) {
Haynes Mathew George8b635332015-03-30 17:59:47 -07001483 const bool hasVideo = (mSource->getFormat(false /*audio */) != NULL);
1484 format->setInt32("has-video", hasVideo);
Wei Jiac6cfd702014-11-11 16:33:20 -08001485 *decoder = new DecoderPassThrough(notify, mSource, mRenderer);
Wei Jiabc2fb722014-07-08 16:37:57 -07001486 } else {
Wei Jiac6cfd702014-11-11 16:33:20 -08001487 *decoder = new Decoder(notify, mSource, mRenderer);
Wei Jiabc2fb722014-07-08 16:37:57 -07001488 }
1489 } else {
Lajos Molnar1d15ab52015-03-04 16:46:34 -08001490 sp<AMessage> notify = new AMessage(kWhatVideoNotify, this);
Wei Jia88703c32014-08-06 11:24:07 -07001491 ++mVideoDecoderGeneration;
1492 notify->setInt32("generation", mVideoDecoderGeneration);
1493
Chong Zhang7137ec72014-11-12 16:41:05 -08001494 *decoder = new Decoder(
Lajos Molnar1de1e252015-04-30 18:18:34 -07001495 notify, mSource, mRenderer, mSurface, mCCDecoder);
Lajos Molnard9fd6312014-11-06 11:00:00 -08001496
1497 // enable FRC if high-quality AV sync is requested, even if not
Lajos Molnar1de1e252015-04-30 18:18:34 -07001498 // directly queuing to display, as this will even improve textureview
Lajos Molnard9fd6312014-11-06 11:00:00 -08001499 // playback.
1500 {
1501 char value[PROPERTY_VALUE_MAX];
1502 if (property_get("persist.sys.media.avsync", value, NULL) &&
1503 (!strcmp("1", value) || !strcasecmp("true", value))) {
1504 format->setInt32("auto-frc", 1);
1505 }
1506 }
Wei Jiabc2fb722014-07-08 16:37:57 -07001507 }
Lajos Molnar1cd13982014-01-17 15:12:51 -08001508 (*decoder)->init();
Andreas Huber84066782011-08-16 09:34:26 -07001509 (*decoder)->configure(format);
Andreas Huberf9334412010-12-15 15:17:42 -08001510
Lajos Molnar09524832014-07-17 14:29:51 -07001511 // allocate buffers to decrypt widevine source buffers
1512 if (!audio && (mSourceFlags & Source::FLAG_SECURE)) {
1513 Vector<sp<ABuffer> > inputBufs;
1514 CHECK_EQ((*decoder)->getInputBuffers(&inputBufs), (status_t)OK);
1515
1516 Vector<MediaBuffer *> mediaBufs;
1517 for (size_t i = 0; i < inputBufs.size(); i++) {
1518 const sp<ABuffer> &buffer = inputBufs[i];
1519 MediaBuffer *mbuf = new MediaBuffer(buffer->data(), buffer->size());
1520 mediaBufs.push(mbuf);
1521 }
1522
1523 status_t err = mSource->setBuffers(audio, mediaBufs);
1524 if (err != OK) {
1525 for (size_t i = 0; i < mediaBufs.size(); ++i) {
1526 mediaBufs[i]->release();
1527 }
1528 mediaBufs.clear();
1529 ALOGE("Secure source didn't support secure mediaBufs.");
1530 return err;
1531 }
1532 }
Andreas Huberf9334412010-12-15 15:17:42 -08001533 return OK;
1534}
1535
Chong Zhangced1c2f2014-08-08 15:22:35 -07001536void NuPlayer::updateVideoSize(
1537 const sp<AMessage> &inputFormat,
1538 const sp<AMessage> &outputFormat) {
1539 if (inputFormat == NULL) {
1540 ALOGW("Unknown video size, reporting 0x0!");
1541 notifyListener(MEDIA_SET_VIDEO_SIZE, 0, 0);
1542 return;
1543 }
1544
1545 int32_t displayWidth, displayHeight;
Chong Zhangced1c2f2014-08-08 15:22:35 -07001546 if (outputFormat != NULL) {
1547 int32_t width, height;
1548 CHECK(outputFormat->findInt32("width", &width));
1549 CHECK(outputFormat->findInt32("height", &height));
1550
1551 int32_t cropLeft, cropTop, cropRight, cropBottom;
1552 CHECK(outputFormat->findRect(
1553 "crop",
1554 &cropLeft, &cropTop, &cropRight, &cropBottom));
1555
1556 displayWidth = cropRight - cropLeft + 1;
1557 displayHeight = cropBottom - cropTop + 1;
1558
1559 ALOGV("Video output format changed to %d x %d "
1560 "(crop: %d x %d @ (%d, %d))",
1561 width, height,
1562 displayWidth,
1563 displayHeight,
1564 cropLeft, cropTop);
1565 } else {
1566 CHECK(inputFormat->findInt32("width", &displayWidth));
1567 CHECK(inputFormat->findInt32("height", &displayHeight));
1568
1569 ALOGV("Video input format %d x %d", displayWidth, displayHeight);
1570 }
1571
1572 // Take into account sample aspect ratio if necessary:
1573 int32_t sarWidth, sarHeight;
1574 if (inputFormat->findInt32("sar-width", &sarWidth)
1575 && inputFormat->findInt32("sar-height", &sarHeight)) {
1576 ALOGV("Sample aspect ratio %d : %d", sarWidth, sarHeight);
1577
1578 displayWidth = (displayWidth * sarWidth) / sarHeight;
1579
1580 ALOGV("display dimensions %d x %d", displayWidth, displayHeight);
1581 }
1582
1583 int32_t rotationDegrees;
1584 if (!inputFormat->findInt32("rotation-degrees", &rotationDegrees)) {
1585 rotationDegrees = 0;
1586 }
1587
1588 if (rotationDegrees == 90 || rotationDegrees == 270) {
1589 int32_t tmp = displayWidth;
1590 displayWidth = displayHeight;
1591 displayHeight = tmp;
1592 }
1593
1594 notifyListener(
1595 MEDIA_SET_VIDEO_SIZE,
1596 displayWidth,
1597 displayHeight);
1598}
1599
Chong Zhangdcb89b32013-08-06 09:44:47 -07001600void NuPlayer::notifyListener(int msg, int ext1, int ext2, const Parcel *in) {
Andreas Huber43c3e6c2011-01-05 12:17:08 -08001601 if (mDriver == NULL) {
Andreas Huberf9334412010-12-15 15:17:42 -08001602 return;
1603 }
1604
Andreas Huber43c3e6c2011-01-05 12:17:08 -08001605 sp<NuPlayerDriver> driver = mDriver.promote();
Andreas Huberf9334412010-12-15 15:17:42 -08001606
Andreas Huber43c3e6c2011-01-05 12:17:08 -08001607 if (driver == NULL) {
Andreas Huberf9334412010-12-15 15:17:42 -08001608 return;
1609 }
1610
Chong Zhangdcb89b32013-08-06 09:44:47 -07001611 driver->notifyListener(msg, ext1, ext2, in);
Andreas Huberf9334412010-12-15 15:17:42 -08001612}
1613
Chong Zhang7137ec72014-11-12 16:41:05 -08001614void NuPlayer::flushDecoder(bool audio, bool needShutdown) {
Andreas Huber14f76722013-01-15 09:04:18 -08001615 ALOGV("[%s] flushDecoder needShutdown=%d",
1616 audio ? "audio" : "video", needShutdown);
1617
Chong Zhang7137ec72014-11-12 16:41:05 -08001618 const sp<DecoderBase> &decoder = getDecoder(audio);
Lajos Molnar87603c02014-08-20 19:25:30 -07001619 if (decoder == NULL) {
Steve Blockdf64d152012-01-04 20:05:49 +00001620 ALOGI("flushDecoder %s without decoder present",
Andreas Huber6e3d3112011-11-28 12:36:11 -08001621 audio ? "audio" : "video");
Lajos Molnar87603c02014-08-20 19:25:30 -07001622 return;
Andreas Huber6e3d3112011-11-28 12:36:11 -08001623 }
1624
Andreas Huber1aef2112011-01-04 14:01:29 -08001625 // Make sure we don't continue to scan sources until we finish flushing.
1626 ++mScanSourcesGeneration;
Chong Zhang3b032b32015-04-17 15:49:06 -07001627 if (mScanSourcesPending) {
1628 mDeferredActions.push_back(
1629 new SimpleAction(&NuPlayer::performScanSources));
1630 mScanSourcesPending = false;
1631 }
Andreas Huber1aef2112011-01-04 14:01:29 -08001632
Chong Zhang7137ec72014-11-12 16:41:05 -08001633 decoder->signalFlush();
Andreas Huber1aef2112011-01-04 14:01:29 -08001634
1635 FlushStatus newStatus =
1636 needShutdown ? FLUSHING_DECODER_SHUTDOWN : FLUSHING_DECODER;
1637
Lajos Molnarfcd3e942015-03-31 10:06:48 -07001638 mFlushComplete[audio][false /* isDecoder */] = (mRenderer == NULL);
Andy Hung8d121d42014-10-03 09:53:53 -07001639 mFlushComplete[audio][true /* isDecoder */] = false;
Andreas Huber1aef2112011-01-04 14:01:29 -08001640 if (audio) {
Wei Jia53904f32014-07-29 10:22:53 -07001641 ALOGE_IF(mFlushingAudio != NONE,
1642 "audio flushDecoder() is called in state %d", mFlushingAudio);
Andreas Huber1aef2112011-01-04 14:01:29 -08001643 mFlushingAudio = newStatus;
Andreas Huber1aef2112011-01-04 14:01:29 -08001644 } else {
Wei Jia53904f32014-07-29 10:22:53 -07001645 ALOGE_IF(mFlushingVideo != NONE,
1646 "video flushDecoder() is called in state %d", mFlushingVideo);
Andreas Huber1aef2112011-01-04 14:01:29 -08001647 mFlushingVideo = newStatus;
Andreas Huber1aef2112011-01-04 14:01:29 -08001648 }
1649}
1650
Chong Zhangced1c2f2014-08-08 15:22:35 -07001651void NuPlayer::queueDecoderShutdown(
1652 bool audio, bool video, const sp<AMessage> &reply) {
1653 ALOGI("queueDecoderShutdown audio=%d, video=%d", audio, video);
Andreas Huber84066782011-08-16 09:34:26 -07001654
Chong Zhangced1c2f2014-08-08 15:22:35 -07001655 mDeferredActions.push_back(
Wei Jiafef808d2014-10-31 17:57:05 -07001656 new FlushDecoderAction(
1657 audio ? FLUSH_CMD_SHUTDOWN : FLUSH_CMD_NONE,
1658 video ? FLUSH_CMD_SHUTDOWN : FLUSH_CMD_NONE));
Andreas Huber84066782011-08-16 09:34:26 -07001659
Chong Zhangced1c2f2014-08-08 15:22:35 -07001660 mDeferredActions.push_back(
1661 new SimpleAction(&NuPlayer::performScanSources));
Andreas Huber84066782011-08-16 09:34:26 -07001662
Chong Zhangced1c2f2014-08-08 15:22:35 -07001663 mDeferredActions.push_back(new PostMessageAction(reply));
1664
1665 processDeferredActions();
Andreas Huber84066782011-08-16 09:34:26 -07001666}
1667
James Dong0d268a32012-08-31 12:18:27 -07001668status_t NuPlayer::setVideoScalingMode(int32_t mode) {
1669 mVideoScalingMode = mode;
Lajos Molnar1de1e252015-04-30 18:18:34 -07001670 if (mSurface != NULL) {
1671 status_t ret = native_window_set_scaling_mode(mSurface.get(), mVideoScalingMode);
James Dong0d268a32012-08-31 12:18:27 -07001672 if (ret != OK) {
1673 ALOGE("Failed to set scaling mode (%d): %s",
1674 -ret, strerror(-ret));
1675 return ret;
1676 }
1677 }
1678 return OK;
1679}
1680
Chong Zhangdcb89b32013-08-06 09:44:47 -07001681status_t NuPlayer::getTrackInfo(Parcel* reply) const {
Lajos Molnar1d15ab52015-03-04 16:46:34 -08001682 sp<AMessage> msg = new AMessage(kWhatGetTrackInfo, this);
Chong Zhangdcb89b32013-08-06 09:44:47 -07001683 msg->setPointer("reply", reply);
1684
1685 sp<AMessage> response;
1686 status_t err = msg->postAndAwaitResponse(&response);
1687 return err;
1688}
1689
Robert Shih7c4f0d72014-07-09 18:53:31 -07001690status_t NuPlayer::getSelectedTrack(int32_t type, Parcel* reply) const {
Lajos Molnar1d15ab52015-03-04 16:46:34 -08001691 sp<AMessage> msg = new AMessage(kWhatGetSelectedTrack, this);
Robert Shih7c4f0d72014-07-09 18:53:31 -07001692 msg->setPointer("reply", reply);
1693 msg->setInt32("type", type);
1694
1695 sp<AMessage> response;
1696 status_t err = msg->postAndAwaitResponse(&response);
1697 if (err == OK && response != NULL) {
1698 CHECK(response->findInt32("err", &err));
1699 }
1700 return err;
1701}
1702
Robert Shih6ffb1fd2014-10-29 16:24:32 -07001703status_t NuPlayer::selectTrack(size_t trackIndex, bool select, int64_t timeUs) {
Lajos Molnar1d15ab52015-03-04 16:46:34 -08001704 sp<AMessage> msg = new AMessage(kWhatSelectTrack, this);
Chong Zhangdcb89b32013-08-06 09:44:47 -07001705 msg->setSize("trackIndex", trackIndex);
1706 msg->setInt32("select", select);
Robert Shih6ffb1fd2014-10-29 16:24:32 -07001707 msg->setInt64("timeUs", timeUs);
Chong Zhangdcb89b32013-08-06 09:44:47 -07001708
1709 sp<AMessage> response;
1710 status_t err = msg->postAndAwaitResponse(&response);
1711
Chong Zhang404fced2014-06-11 14:45:31 -07001712 if (err != OK) {
1713 return err;
1714 }
1715
1716 if (!response->findInt32("err", &err)) {
1717 err = OK;
1718 }
1719
Chong Zhangdcb89b32013-08-06 09:44:47 -07001720 return err;
1721}
1722
Ronghua Wua73d9e02014-10-08 15:13:29 -07001723status_t NuPlayer::getCurrentPosition(int64_t *mediaUs) {
1724 sp<Renderer> renderer = mRenderer;
1725 if (renderer == NULL) {
1726 return NO_INIT;
1727 }
1728
1729 return renderer->getCurrentPosition(mediaUs);
1730}
1731
Praveen Chavane1e5d7a2015-05-19 19:09:48 -07001732void NuPlayer::getStats(Vector<sp<AMessage> > *mTrackStats) {
1733 CHECK(mTrackStats != NULL);
1734
1735 mTrackStats->clear();
1736 if (mVideoDecoder != NULL) {
1737 mTrackStats->push_back(mVideoDecoder->getStats());
1738 }
1739 if (mAudioDecoder != NULL) {
1740 mTrackStats->push_back(mAudioDecoder->getStats());
Chong Zhang7137ec72014-11-12 16:41:05 -08001741 }
Ronghua Wua73d9e02014-10-08 15:13:29 -07001742}
1743
Marco Nelissenf0b72b52014-09-16 15:43:44 -07001744sp<MetaData> NuPlayer::getFileMeta() {
1745 return mSource->getFileFormatMeta();
1746}
1747
Ronghua Wuc8a70d32015-04-29 16:26:34 -07001748float NuPlayer::getFrameRate() {
1749 sp<MetaData> meta = mSource->getFormatMeta(false /* audio */);
1750 if (meta == NULL) {
1751 return 0;
1752 }
1753 int32_t rate;
1754 if (!meta->findInt32(kKeyFrameRate, &rate)) {
1755 // fall back to try file meta
1756 sp<MetaData> fileMeta = getFileMeta();
1757 if (fileMeta == NULL) {
1758 ALOGW("source has video meta but not file meta");
1759 return -1;
1760 }
1761 int32_t fileMetaRate;
1762 if (!fileMeta->findInt32(kKeyFrameRate, &fileMetaRate)) {
1763 return -1;
1764 }
1765 return fileMetaRate;
1766 }
1767 return rate;
1768}
1769
Andreas Huberb7c8e912012-11-27 15:02:53 -08001770void NuPlayer::schedulePollDuration() {
Lajos Molnar1d15ab52015-03-04 16:46:34 -08001771 sp<AMessage> msg = new AMessage(kWhatPollDuration, this);
Andreas Huberb7c8e912012-11-27 15:02:53 -08001772 msg->setInt32("generation", mPollDurationGeneration);
1773 msg->post();
1774}
1775
1776void NuPlayer::cancelPollDuration() {
1777 ++mPollDurationGeneration;
1778}
1779
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001780void NuPlayer::processDeferredActions() {
1781 while (!mDeferredActions.empty()) {
1782 // We won't execute any deferred actions until we're no longer in
1783 // an intermediate state, i.e. one more more decoders are currently
1784 // flushing or shutting down.
1785
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001786 if (mFlushingAudio != NONE || mFlushingVideo != NONE) {
1787 // We're currently flushing, postpone the reset until that's
1788 // completed.
1789
1790 ALOGV("postponing action mFlushingAudio=%d, mFlushingVideo=%d",
1791 mFlushingAudio, mFlushingVideo);
1792
1793 break;
1794 }
1795
1796 sp<Action> action = *mDeferredActions.begin();
1797 mDeferredActions.erase(mDeferredActions.begin());
1798
1799 action->execute(this);
1800 }
1801}
1802
Wei Jia29840802015-05-15 17:11:38 -07001803void NuPlayer::performSeek(int64_t seekTimeUs) {
1804 ALOGV("performSeek seekTimeUs=%lld us (%.2f secs)",
Lajos Molnar6d339f12015-04-17 16:15:53 -07001805 (long long)seekTimeUs,
Wei Jia29840802015-05-15 17:11:38 -07001806 seekTimeUs / 1E6);
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001807
Andy Hungadf34bf2014-09-03 18:22:22 -07001808 if (mSource == NULL) {
1809 // This happens when reset occurs right before the loop mode
1810 // asynchronously seeks to the start of the stream.
1811 LOG_ALWAYS_FATAL_IF(mAudioDecoder != NULL || mVideoDecoder != NULL,
1812 "mSource is NULL and decoders not NULL audio(%p) video(%p)",
1813 mAudioDecoder.get(), mVideoDecoder.get());
1814 return;
1815 }
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001816 mSource->seekTo(seekTimeUs);
Robert Shihd3b0bbb2014-07-23 15:00:25 -07001817 ++mTimedTextGeneration;
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001818
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001819 // everything's flushed, continue playback.
1820}
1821
Wei Jiafef808d2014-10-31 17:57:05 -07001822void NuPlayer::performDecoderFlush(FlushCommand audio, FlushCommand video) {
1823 ALOGV("performDecoderFlush audio=%d, video=%d", audio, video);
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001824
Wei Jiafef808d2014-10-31 17:57:05 -07001825 if ((audio == FLUSH_CMD_NONE || mAudioDecoder == NULL)
1826 && (video == FLUSH_CMD_NONE || mVideoDecoder == NULL)) {
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001827 return;
1828 }
1829
Wei Jiafef808d2014-10-31 17:57:05 -07001830 if (audio != FLUSH_CMD_NONE && mAudioDecoder != NULL) {
1831 flushDecoder(true /* audio */, (audio == FLUSH_CMD_SHUTDOWN));
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001832 }
1833
Wei Jiafef808d2014-10-31 17:57:05 -07001834 if (video != FLUSH_CMD_NONE && mVideoDecoder != NULL) {
1835 flushDecoder(false /* audio */, (video == FLUSH_CMD_SHUTDOWN));
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001836 }
1837}
1838
1839void NuPlayer::performReset() {
1840 ALOGV("performReset");
1841
1842 CHECK(mAudioDecoder == NULL);
1843 CHECK(mVideoDecoder == NULL);
1844
1845 cancelPollDuration();
1846
1847 ++mScanSourcesGeneration;
1848 mScanSourcesPending = false;
1849
Lajos Molnar09524832014-07-17 14:29:51 -07001850 if (mRendererLooper != NULL) {
1851 if (mRenderer != NULL) {
1852 mRendererLooper->unregisterHandler(mRenderer->id());
1853 }
1854 mRendererLooper->stop();
1855 mRendererLooper.clear();
1856 }
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001857 mRenderer.clear();
Wei Jia57568df2014-09-22 10:16:29 -07001858 ++mRendererGeneration;
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001859
1860 if (mSource != NULL) {
1861 mSource->stop();
Andreas Huberb5f25f02013-02-05 10:14:26 -08001862
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001863 mSource.clear();
1864 }
1865
1866 if (mDriver != NULL) {
1867 sp<NuPlayerDriver> driver = mDriver.promote();
1868 if (driver != NULL) {
1869 driver->notifyResetComplete();
1870 }
1871 }
Andreas Huber57a339c2012-12-03 11:18:00 -08001872
1873 mStarted = false;
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001874}
1875
1876void NuPlayer::performScanSources() {
1877 ALOGV("performScanSources");
1878
Andreas Huber57a339c2012-12-03 11:18:00 -08001879 if (!mStarted) {
1880 return;
1881 }
1882
Andreas Hubera1f8ab02012-11-30 10:53:22 -08001883 if (mAudioDecoder == NULL || mVideoDecoder == NULL) {
1884 postScanSources();
1885 }
1886}
1887
Lajos Molnar1de1e252015-04-30 18:18:34 -07001888void NuPlayer::performSetSurface(const sp<Surface> &surface) {
Andreas Huber57a339c2012-12-03 11:18:00 -08001889 ALOGV("performSetSurface");
1890
Lajos Molnar1de1e252015-04-30 18:18:34 -07001891 mSurface = surface;
Andreas Huber57a339c2012-12-03 11:18:00 -08001892
1893 // XXX - ignore error from setVideoScalingMode for now
1894 setVideoScalingMode(mVideoScalingMode);
Chong Zhang13d6faa2014-08-22 15:35:28 -07001895
1896 if (mDriver != NULL) {
1897 sp<NuPlayerDriver> driver = mDriver.promote();
1898 if (driver != NULL) {
1899 driver->notifySetSurfaceComplete();
1900 }
1901 }
Andreas Huber57a339c2012-12-03 11:18:00 -08001902}
1903
Chong Zhangf8d71772014-11-26 15:08:34 -08001904void NuPlayer::performResumeDecoders(bool needNotify) {
1905 if (needNotify) {
1906 mResumePending = true;
1907 if (mVideoDecoder == NULL) {
1908 // if audio-only, we can notify seek complete now,
1909 // as the resume operation will be relatively fast.
1910 finishResume();
1911 }
1912 }
1913
Chong Zhang7137ec72014-11-12 16:41:05 -08001914 if (mVideoDecoder != NULL) {
Chong Zhangf8d71772014-11-26 15:08:34 -08001915 // When there is continuous seek, MediaPlayer will cache the seek
1916 // position, and send down new seek request when previous seek is
1917 // complete. Let's wait for at least one video output frame before
1918 // notifying seek complete, so that the video thumbnail gets updated
1919 // when seekbar is dragged.
1920 mVideoDecoder->signalResume(needNotify);
Chong Zhang7137ec72014-11-12 16:41:05 -08001921 }
1922
1923 if (mAudioDecoder != NULL) {
Chong Zhangf8d71772014-11-26 15:08:34 -08001924 mAudioDecoder->signalResume(false /* needNotify */);
1925 }
1926}
1927
1928void NuPlayer::finishResume() {
1929 if (mResumePending) {
1930 mResumePending = false;
Wei Jia1061c9c2015-05-19 16:02:17 -07001931 notifyDriverSeekComplete();
1932 }
1933}
1934
1935void NuPlayer::notifyDriverSeekComplete() {
1936 if (mDriver != NULL) {
1937 sp<NuPlayerDriver> driver = mDriver.promote();
1938 if (driver != NULL) {
1939 driver->notifySeekComplete();
Chong Zhangf8d71772014-11-26 15:08:34 -08001940 }
Chong Zhang7137ec72014-11-12 16:41:05 -08001941 }
1942}
1943
Andreas Huber9575c962013-02-05 13:59:56 -08001944void NuPlayer::onSourceNotify(const sp<AMessage> &msg) {
1945 int32_t what;
1946 CHECK(msg->findInt32("what", &what));
1947
1948 switch (what) {
Lajos Molnarfcd3e942015-03-31 10:06:48 -07001949 case Source::kWhatInstantiateSecureDecoders:
1950 {
1951 if (mSource == NULL) {
1952 // This is a stale notification from a source that was
1953 // asynchronously preparing when the client called reset().
1954 // We handled the reset, the source is gone.
1955 break;
1956 }
1957
1958 sp<AMessage> reply;
1959 CHECK(msg->findMessage("reply", &reply));
1960 status_t err = onInstantiateSecureDecoders();
1961 reply->setInt32("err", err);
1962 reply->post();
1963 break;
1964 }
1965
Andreas Huber9575c962013-02-05 13:59:56 -08001966 case Source::kWhatPrepared:
1967 {
Andreas Huberb5f28d42013-04-25 15:11:19 -07001968 if (mSource == NULL) {
1969 // This is a stale notification from a source that was
1970 // asynchronously preparing when the client called reset().
1971 // We handled the reset, the source is gone.
1972 break;
1973 }
1974
Andreas Huberec0c5972013-02-05 14:47:13 -08001975 int32_t err;
1976 CHECK(msg->findInt32("err", &err));
1977
Lajos Molnarfcd3e942015-03-31 10:06:48 -07001978 if (err != OK) {
1979 // shut down potential secure codecs in case client never calls reset
1980 mDeferredActions.push_back(
1981 new FlushDecoderAction(FLUSH_CMD_SHUTDOWN /* audio */,
1982 FLUSH_CMD_SHUTDOWN /* video */));
1983 processDeferredActions();
1984 }
1985
Andreas Huber9575c962013-02-05 13:59:56 -08001986 sp<NuPlayerDriver> driver = mDriver.promote();
1987 if (driver != NULL) {
Marco Nelissendd114d12014-05-28 15:23:14 -07001988 // notify duration first, so that it's definitely set when
1989 // the app received the "prepare complete" callback.
1990 int64_t durationUs;
1991 if (mSource->getDuration(&durationUs) == OK) {
1992 driver->notifyDuration(durationUs);
1993 }
Andreas Huberec0c5972013-02-05 14:47:13 -08001994 driver->notifyPrepareCompleted(err);
Andreas Huber9575c962013-02-05 13:59:56 -08001995 }
Andreas Huber99759402013-04-01 14:28:31 -07001996
Andreas Huber9575c962013-02-05 13:59:56 -08001997 break;
1998 }
1999
2000 case Source::kWhatFlagsChanged:
2001 {
2002 uint32_t flags;
2003 CHECK(msg->findInt32("flags", (int32_t *)&flags));
2004
Chong Zhang4b7069d2013-09-11 12:52:43 -07002005 sp<NuPlayerDriver> driver = mDriver.promote();
2006 if (driver != NULL) {
Wei Jia895651b2014-12-10 17:31:52 -08002007 if ((flags & NuPlayer::Source::FLAG_CAN_SEEK) == 0) {
2008 driver->notifyListener(
2009 MEDIA_INFO, MEDIA_INFO_NOT_SEEKABLE, 0);
2010 }
Chong Zhang4b7069d2013-09-11 12:52:43 -07002011 driver->notifyFlagsChanged(flags);
2012 }
2013
Andreas Huber9575c962013-02-05 13:59:56 -08002014 if ((mSourceFlags & Source::FLAG_DYNAMIC_DURATION)
2015 && (!(flags & Source::FLAG_DYNAMIC_DURATION))) {
2016 cancelPollDuration();
2017 } else if (!(mSourceFlags & Source::FLAG_DYNAMIC_DURATION)
2018 && (flags & Source::FLAG_DYNAMIC_DURATION)
2019 && (mAudioDecoder != NULL || mVideoDecoder != NULL)) {
2020 schedulePollDuration();
2021 }
2022
2023 mSourceFlags = flags;
2024 break;
2025 }
2026
2027 case Source::kWhatVideoSizeChanged:
2028 {
Chong Zhangced1c2f2014-08-08 15:22:35 -07002029 sp<AMessage> format;
2030 CHECK(msg->findMessage("format", &format));
Andreas Huber9575c962013-02-05 13:59:56 -08002031
Chong Zhangced1c2f2014-08-08 15:22:35 -07002032 updateVideoSize(format);
Andreas Huber9575c962013-02-05 13:59:56 -08002033 break;
2034 }
2035
Chong Zhang2a3cc9a2014-08-21 17:48:26 -07002036 case Source::kWhatBufferingUpdate:
2037 {
2038 int32_t percentage;
2039 CHECK(msg->findInt32("percentage", &percentage));
2040
2041 notifyListener(MEDIA_BUFFERING_UPDATE, percentage, 0);
2042 break;
2043 }
2044
Chong Zhangefbb6192015-01-30 17:13:27 -08002045 case Source::kWhatPauseOnBufferingStart:
2046 {
2047 // ignore if not playing
Chong Zhang8a048332015-05-06 15:16:28 -07002048 if (mStarted) {
Chong Zhangefbb6192015-01-30 17:13:27 -08002049 ALOGI("buffer low, pausing...");
2050
Chong Zhang8a048332015-05-06 15:16:28 -07002051 mPausedForBuffering = true;
Chong Zhangefbb6192015-01-30 17:13:27 -08002052 onPause();
2053 }
2054 // fall-thru
2055 }
2056
Roger Jönssonb50e83e2013-01-21 16:26:41 +01002057 case Source::kWhatBufferingStart:
2058 {
2059 notifyListener(MEDIA_INFO, MEDIA_INFO_BUFFERING_START, 0);
2060 break;
2061 }
2062
Chong Zhangefbb6192015-01-30 17:13:27 -08002063 case Source::kWhatResumeOnBufferingEnd:
2064 {
2065 // ignore if not playing
Chong Zhang8a048332015-05-06 15:16:28 -07002066 if (mStarted) {
Chong Zhangefbb6192015-01-30 17:13:27 -08002067 ALOGI("buffer ready, resuming...");
2068
Chong Zhang8a048332015-05-06 15:16:28 -07002069 mPausedForBuffering = false;
2070
2071 // do not resume yet if client didn't unpause
2072 if (!mPausedByClient) {
2073 onResume();
2074 }
Chong Zhangefbb6192015-01-30 17:13:27 -08002075 }
2076 // fall-thru
2077 }
2078
Roger Jönssonb50e83e2013-01-21 16:26:41 +01002079 case Source::kWhatBufferingEnd:
2080 {
2081 notifyListener(MEDIA_INFO, MEDIA_INFO_BUFFERING_END, 0);
2082 break;
2083 }
2084
Chong Zhangefbb6192015-01-30 17:13:27 -08002085 case Source::kWhatCacheStats:
2086 {
2087 int32_t kbps;
2088 CHECK(msg->findInt32("bandwidth", &kbps));
2089
2090 notifyListener(MEDIA_INFO, MEDIA_INFO_NETWORK_BANDWIDTH, kbps);
2091 break;
2092 }
2093
Chong Zhangdcb89b32013-08-06 09:44:47 -07002094 case Source::kWhatSubtitleData:
2095 {
2096 sp<ABuffer> buffer;
2097 CHECK(msg->findBuffer("buffer", &buffer));
2098
Chong Zhang404fced2014-06-11 14:45:31 -07002099 sendSubtitleData(buffer, 0 /* baseIndex */);
Chong Zhangdcb89b32013-08-06 09:44:47 -07002100 break;
2101 }
2102
Robert Shih08528432015-04-08 09:06:54 -07002103 case Source::kWhatTimedMetaData:
2104 {
2105 sp<ABuffer> buffer;
2106 if (!msg->findBuffer("buffer", &buffer)) {
2107 notifyListener(MEDIA_INFO, MEDIA_INFO_METADATA_UPDATE, 0);
2108 } else {
2109 sendTimedMetaData(buffer);
2110 }
2111 break;
2112 }
2113
Robert Shihd3b0bbb2014-07-23 15:00:25 -07002114 case Source::kWhatTimedTextData:
2115 {
2116 int32_t generation;
2117 if (msg->findInt32("generation", &generation)
2118 && generation != mTimedTextGeneration) {
2119 break;
2120 }
2121
2122 sp<ABuffer> buffer;
2123 CHECK(msg->findBuffer("buffer", &buffer));
2124
2125 sp<NuPlayerDriver> driver = mDriver.promote();
2126 if (driver == NULL) {
2127 break;
2128 }
2129
2130 int posMs;
2131 int64_t timeUs, posUs;
2132 driver->getCurrentPosition(&posMs);
2133 posUs = posMs * 1000;
2134 CHECK(buffer->meta()->findInt64("timeUs", &timeUs));
2135
2136 if (posUs < timeUs) {
2137 if (!msg->findInt32("generation", &generation)) {
2138 msg->setInt32("generation", mTimedTextGeneration);
2139 }
2140 msg->post(timeUs - posUs);
2141 } else {
2142 sendTimedTextData(buffer);
2143 }
2144 break;
2145 }
2146
Andreas Huber14f76722013-01-15 09:04:18 -08002147 case Source::kWhatQueueDecoderShutdown:
2148 {
2149 int32_t audio, video;
2150 CHECK(msg->findInt32("audio", &audio));
2151 CHECK(msg->findInt32("video", &video));
2152
2153 sp<AMessage> reply;
2154 CHECK(msg->findMessage("reply", &reply));
2155
2156 queueDecoderShutdown(audio, video, reply);
2157 break;
2158 }
2159
Ronghua Wu80276872014-08-28 15:50:29 -07002160 case Source::kWhatDrmNoLicense:
2161 {
2162 notifyListener(MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, ERROR_DRM_NO_LICENSE);
2163 break;
2164 }
2165
Andreas Huber9575c962013-02-05 13:59:56 -08002166 default:
2167 TRESPASS();
2168 }
2169}
2170
Chong Zhanga7fa1d92014-06-11 14:49:23 -07002171void NuPlayer::onClosedCaptionNotify(const sp<AMessage> &msg) {
2172 int32_t what;
2173 CHECK(msg->findInt32("what", &what));
2174
2175 switch (what) {
2176 case NuPlayer::CCDecoder::kWhatClosedCaptionData:
2177 {
2178 sp<ABuffer> buffer;
2179 CHECK(msg->findBuffer("buffer", &buffer));
2180
2181 size_t inbandTracks = 0;
2182 if (mSource != NULL) {
2183 inbandTracks = mSource->getTrackCount();
2184 }
2185
2186 sendSubtitleData(buffer, inbandTracks);
2187 break;
2188 }
2189
2190 case NuPlayer::CCDecoder::kWhatTrackAdded:
2191 {
2192 notifyListener(MEDIA_INFO, MEDIA_INFO_METADATA_UPDATE, 0);
2193
2194 break;
2195 }
2196
2197 default:
2198 TRESPASS();
2199 }
2200
2201
2202}
2203
Chong Zhang404fced2014-06-11 14:45:31 -07002204void NuPlayer::sendSubtitleData(const sp<ABuffer> &buffer, int32_t baseIndex) {
2205 int32_t trackIndex;
2206 int64_t timeUs, durationUs;
2207 CHECK(buffer->meta()->findInt32("trackIndex", &trackIndex));
2208 CHECK(buffer->meta()->findInt64("timeUs", &timeUs));
2209 CHECK(buffer->meta()->findInt64("durationUs", &durationUs));
2210
2211 Parcel in;
2212 in.writeInt32(trackIndex + baseIndex);
2213 in.writeInt64(timeUs);
2214 in.writeInt64(durationUs);
2215 in.writeInt32(buffer->size());
2216 in.writeInt32(buffer->size());
2217 in.write(buffer->data(), buffer->size());
2218
2219 notifyListener(MEDIA_SUBTITLE_DATA, 0, 0, &in);
2220}
Robert Shihd3b0bbb2014-07-23 15:00:25 -07002221
Robert Shih08528432015-04-08 09:06:54 -07002222void NuPlayer::sendTimedMetaData(const sp<ABuffer> &buffer) {
2223 int64_t timeUs;
2224 CHECK(buffer->meta()->findInt64("timeUs", &timeUs));
2225
2226 Parcel in;
2227 in.writeInt64(timeUs);
2228 in.writeInt32(buffer->size());
2229 in.writeInt32(buffer->size());
2230 in.write(buffer->data(), buffer->size());
2231
2232 notifyListener(MEDIA_META_DATA, 0, 0, &in);
2233}
2234
Robert Shihd3b0bbb2014-07-23 15:00:25 -07002235void NuPlayer::sendTimedTextData(const sp<ABuffer> &buffer) {
2236 const void *data;
2237 size_t size = 0;
2238 int64_t timeUs;
2239 int32_t flag = TextDescriptions::LOCAL_DESCRIPTIONS;
2240
2241 AString mime;
2242 CHECK(buffer->meta()->findString("mime", &mime));
2243 CHECK(strcasecmp(mime.c_str(), MEDIA_MIMETYPE_TEXT_3GPP) == 0);
2244
2245 data = buffer->data();
2246 size = buffer->size();
2247
2248 Parcel parcel;
2249 if (size > 0) {
2250 CHECK(buffer->meta()->findInt64("timeUs", &timeUs));
2251 flag |= TextDescriptions::IN_BAND_TEXT_3GPP;
2252 TextDescriptions::getParcelOfDescriptions(
2253 (const uint8_t *)data, size, flag, timeUs / 1000, &parcel);
2254 }
2255
2256 if ((parcel.dataSize() > 0)) {
2257 notifyListener(MEDIA_TIMED_TEXT, 0, 0, &parcel);
2258 } else { // send an empty timed text
2259 notifyListener(MEDIA_TIMED_TEXT, 0, 0);
2260 }
2261}
Andreas Huberb5f25f02013-02-05 10:14:26 -08002262////////////////////////////////////////////////////////////////////////////////
2263
Chong Zhangced1c2f2014-08-08 15:22:35 -07002264sp<AMessage> NuPlayer::Source::getFormat(bool audio) {
2265 sp<MetaData> meta = getFormatMeta(audio);
2266
2267 if (meta == NULL) {
2268 return NULL;
2269 }
2270
2271 sp<AMessage> msg = new AMessage;
2272
2273 if(convertMetaDataToMessage(meta, &msg) == OK) {
2274 return msg;
2275 }
2276 return NULL;
2277}
2278
Andreas Huber9575c962013-02-05 13:59:56 -08002279void NuPlayer::Source::notifyFlagsChanged(uint32_t flags) {
2280 sp<AMessage> notify = dupNotify();
2281 notify->setInt32("what", kWhatFlagsChanged);
2282 notify->setInt32("flags", flags);
2283 notify->post();
2284}
2285
Chong Zhangced1c2f2014-08-08 15:22:35 -07002286void NuPlayer::Source::notifyVideoSizeChanged(const sp<AMessage> &format) {
Andreas Huber9575c962013-02-05 13:59:56 -08002287 sp<AMessage> notify = dupNotify();
2288 notify->setInt32("what", kWhatVideoSizeChanged);
Chong Zhangced1c2f2014-08-08 15:22:35 -07002289 notify->setMessage("format", format);
Andreas Huber9575c962013-02-05 13:59:56 -08002290 notify->post();
2291}
2292
Andreas Huberec0c5972013-02-05 14:47:13 -08002293void NuPlayer::Source::notifyPrepared(status_t err) {
Andreas Huber9575c962013-02-05 13:59:56 -08002294 sp<AMessage> notify = dupNotify();
2295 notify->setInt32("what", kWhatPrepared);
Andreas Huberec0c5972013-02-05 14:47:13 -08002296 notify->setInt32("err", err);
Andreas Huber9575c962013-02-05 13:59:56 -08002297 notify->post();
2298}
2299
Lajos Molnarfcd3e942015-03-31 10:06:48 -07002300void NuPlayer::Source::notifyInstantiateSecureDecoders(const sp<AMessage> &reply) {
2301 sp<AMessage> notify = dupNotify();
2302 notify->setInt32("what", kWhatInstantiateSecureDecoders);
2303 notify->setMessage("reply", reply);
2304 notify->post();
2305}
2306
Andreas Huber84333e02014-02-07 15:36:10 -08002307void NuPlayer::Source::onMessageReceived(const sp<AMessage> & /* msg */) {
Andreas Huberb5f25f02013-02-05 10:14:26 -08002308 TRESPASS();
2309}
2310
Andreas Huberf9334412010-12-15 15:17:42 -08002311} // namespace android