blob: a2ec6999273c7be73ab9f0aa640443aaadb4a9de [file] [log] [blame]
Andreas Huberf9334412010-12-15 15:17:42 -08001/*
Chong Zhang7137ec72014-11-12 16:41:05 -08002 * Copyright 2014 The Android Open Source Project
Andreas Huberf9334412010-12-15 15:17:42 -08003 *
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 "NuPlayerDecoder"
19#include <utils/Log.h>
Lajos Molnar1cd13982014-01-17 15:12:51 -080020#include <inttypes.h>
Andreas Huberf9334412010-12-15 15:17:42 -080021
Lajos Molnar9fb81522016-07-14 07:33:43 -070022#include <algorithm>
23
Chong Zhang7137ec72014-11-12 16:41:05 -080024#include "NuPlayerCCDecoder.h"
Andreas Huberf9334412010-12-15 15:17:42 -080025#include "NuPlayerDecoder.h"
Hassan Shojaniacefac142017-02-06 21:02:02 -080026#include "NuPlayerDrm.h"
Wei Jiac6cfd702014-11-11 16:33:20 -080027#include "NuPlayerRenderer.h"
28#include "NuPlayerSource.h"
29
Andy Hung288da022015-05-31 22:55:59 -070030#include <cutils/properties.h>
Lajos Molnar1cd13982014-01-17 15:12:51 -080031#include <media/ICrypto.h>
Dongwon Kangbc8f53b2018-01-25 17:01:44 -080032#include <media/MediaBufferHolder.h>
Wonsik Kim7e34bf52016-08-23 00:09:18 +090033#include <media/MediaCodecBuffer.h>
Andreas Huberf9334412010-12-15 15:17:42 -080034#include <media/stagefright/foundation/ABuffer.h>
35#include <media/stagefright/foundation/ADebug.h>
Andreas Huber5bc087c2010-12-23 10:27:40 -080036#include <media/stagefright/foundation/AMessage.h>
Dongwon Kangd91dc5a2017-10-10 00:07:09 -070037#include <media/stagefright/foundation/avc_utils.h>
Lajos Molnar09524832014-07-17 14:29:51 -070038#include <media/stagefright/MediaBuffer.h>
Lajos Molnar1cd13982014-01-17 15:12:51 -080039#include <media/stagefright/MediaCodec.h>
Andreas Huberf9334412010-12-15 15:17:42 -080040#include <media/stagefright/MediaDefs.h>
Lajos Molnar1cd13982014-01-17 15:12:51 -080041#include <media/stagefright/MediaErrors.h>
Chong Zhang181fd9b2017-02-16 15:53:03 -080042#include <media/stagefright/SurfaceUtils.h>
Lajos Molnar1de1e252015-04-30 18:18:34 -070043#include <gui/Surface.h>
44
Chong Zhang7137ec72014-11-12 16:41:05 -080045#include "ATSParser.h"
46
Andreas Huberf9334412010-12-15 15:17:42 -080047namespace android {
48
Lajos Molnar9fb81522016-07-14 07:33:43 -070049static float kDisplayRefreshingRate = 60.f; // TODO: get this from the display
Praveen Chavanbbaa1442016-04-08 13:33:49 -070050
51// The default total video frame rate of a stream when that info is not available from
52// the source.
53static float kDefaultVideoFrameRateTotal = 30.f;
54
Andy Hung288da022015-05-31 22:55:59 -070055static inline bool getAudioDeepBufferSetting() {
56 return property_get_bool("media.stagefright.audio.deep", false /* default_value */);
57}
58
Andreas Huberf9334412010-12-15 15:17:42 -080059NuPlayer::Decoder::Decoder(
Glenn Kasten11731182011-02-08 17:26:17 -080060 const sp<AMessage> &notify,
Wei Jiac6cfd702014-11-11 16:33:20 -080061 const sp<Source> &source,
Ronghua Wu68845c12015-07-21 09:50:48 -070062 pid_t pid,
Wei Jiaf2ae3e12016-10-27 17:10:59 -070063 uid_t uid,
Wei Jiac6cfd702014-11-11 16:33:20 -080064 const sp<Renderer> &renderer,
Lajos Molnar1de1e252015-04-30 18:18:34 -070065 const sp<Surface> &surface,
Chong Zhang7137ec72014-11-12 16:41:05 -080066 const sp<CCDecoder> &ccDecoder)
Andy Hung202bce12014-12-03 11:47:36 -080067 : DecoderBase(notify),
Lajos Molnar1de1e252015-04-30 18:18:34 -070068 mSurface(surface),
Wei Jiac6cfd702014-11-11 16:33:20 -080069 mSource(source),
70 mRenderer(renderer),
Chong Zhang7137ec72014-11-12 16:41:05 -080071 mCCDecoder(ccDecoder),
Ronghua Wu68845c12015-07-21 09:50:48 -070072 mPid(pid),
Wei Jiaf2ae3e12016-10-27 17:10:59 -070073 mUid(uid),
Wei Jiac6cfd702014-11-11 16:33:20 -080074 mSkipRenderingUntilMediaTimeUs(-1ll),
Chong Zhang7137ec72014-11-12 16:41:05 -080075 mNumFramesTotal(0ll),
Praveen Chavane1e5d7a2015-05-19 19:09:48 -070076 mNumInputFramesDropped(0ll),
77 mNumOutputFramesDropped(0ll),
78 mVideoWidth(0),
79 mVideoHeight(0),
Chong Zhang7137ec72014-11-12 16:41:05 -080080 mIsAudio(true),
81 mIsVideoAVC(false),
82 mIsSecure(false),
Hassan Shojania62dec952017-05-18 10:45:27 -070083 mIsEncrypted(false),
84 mIsEncryptedObservedEarlier(false),
Chong Zhang7137ec72014-11-12 16:41:05 -080085 mFormatChangePending(false),
Chong Zhang66704af2015-03-03 19:32:35 -080086 mTimeChangePending(false),
Praveen Chavanbbaa1442016-04-08 13:33:49 -070087 mFrameRateTotal(kDefaultVideoFrameRateTotal),
88 mPlaybackSpeed(1.0f),
Lajos Molnar9fb81522016-07-14 07:33:43 -070089 mNumVideoTemporalLayerTotal(1), // decode all layers
Praveen Chavanbbaa1442016-04-08 13:33:49 -070090 mNumVideoTemporalLayerAllowed(1),
91 mCurrentMaxVideoTemporalLayerId(0),
Chong Zhangf8d71772014-11-26 15:08:34 -080092 mResumePending(false),
Lajos Molnar1cd13982014-01-17 15:12:51 -080093 mComponentName("decoder") {
Lajos Molnar1cd13982014-01-17 15:12:51 -080094 mCodecLooper = new ALooper;
Marco Nelissen9e2b7912014-08-18 16:13:03 -070095 mCodecLooper->setName("NPDecoder-CL");
Lajos Molnar1cd13982014-01-17 15:12:51 -080096 mCodecLooper->start(false, false, ANDROID_PRIORITY_AUDIO);
Praveen Chavanbbaa1442016-04-08 13:33:49 -070097 mVideoTemporalLayerAggregateFps[0] = mFrameRateTotal;
Andreas Huberf9334412010-12-15 15:17:42 -080098}
99
100NuPlayer::Decoder::~Decoder() {
Wei Jia37ff0e62017-04-21 11:24:45 -0700101 // Need to stop looper first since mCodec could be accessed on the mDecoderLooper.
102 stopLooper();
103 if (mCodec != NULL) {
104 mCodec->release();
105 }
Wei Jia4923cee2014-09-24 14:25:19 -0700106 releaseAndResetMediaBuffers();
Andreas Huberf9334412010-12-15 15:17:42 -0800107}
108
Praveen Chavane1e5d7a2015-05-19 19:09:48 -0700109sp<AMessage> NuPlayer::Decoder::getStats() const {
110 mStats->setInt64("frames-total", mNumFramesTotal);
111 mStats->setInt64("frames-dropped-input", mNumInputFramesDropped);
112 mStats->setInt64("frames-dropped-output", mNumOutputFramesDropped);
Ray Essick092f74a2018-11-20 10:25:13 -0800113 mStats->setFloat("frame-rate-total", mFrameRateTotal);
Praveen Chavane1e5d7a2015-05-19 19:09:48 -0700114 return mStats;
Lajos Molnar09524832014-07-17 14:29:51 -0700115}
116
Lajos Molnara81c6222015-07-10 19:17:45 -0700117status_t NuPlayer::Decoder::setVideoSurface(const sp<Surface> &surface) {
118 if (surface == NULL || ADebug::isExperimentEnabled("legacy-setsurface")) {
119 return BAD_VALUE;
120 }
121
122 sp<AMessage> msg = new AMessage(kWhatSetVideoSurface, this);
123
124 msg->setObject("surface", surface);
125 sp<AMessage> response;
126 status_t err = msg->postAndAwaitResponse(&response);
127 if (err == OK && response != NULL) {
128 CHECK(response->findInt32("err", &err));
129 }
130 return err;
131}
132
Chong Zhang7137ec72014-11-12 16:41:05 -0800133void NuPlayer::Decoder::onMessageReceived(const sp<AMessage> &msg) {
134 ALOGV("[%s] onMessage: %s", mComponentName.c_str(), msg->debugString().c_str());
135
136 switch (msg->what()) {
137 case kWhatCodecNotify:
138 {
Chong Zhang3b032b32015-04-17 15:49:06 -0700139 int32_t cbID;
140 CHECK(msg->findInt32("callbackID", &cbID));
141
142 ALOGV("[%s] kWhatCodecNotify: cbID = %d, paused = %d",
143 mIsAudio ? "audio" : "video", cbID, mPaused);
144
Marco Nelissen421f47c2015-03-25 14:40:32 -0700145 if (mPaused) {
146 break;
Chong Zhang7137ec72014-11-12 16:41:05 -0800147 }
148
Marco Nelissen421f47c2015-03-25 14:40:32 -0700149 switch (cbID) {
150 case MediaCodec::CB_INPUT_AVAILABLE:
151 {
152 int32_t index;
153 CHECK(msg->findInt32("index", &index));
154
155 handleAnInputBuffer(index);
156 break;
157 }
158
159 case MediaCodec::CB_OUTPUT_AVAILABLE:
160 {
161 int32_t index;
162 size_t offset;
163 size_t size;
164 int64_t timeUs;
165 int32_t flags;
166
167 CHECK(msg->findInt32("index", &index));
168 CHECK(msg->findSize("offset", &offset));
169 CHECK(msg->findSize("size", &size));
170 CHECK(msg->findInt64("timeUs", &timeUs));
171 CHECK(msg->findInt32("flags", &flags));
172
173 handleAnOutputBuffer(index, offset, size, timeUs, flags);
174 break;
175 }
176
177 case MediaCodec::CB_OUTPUT_FORMAT_CHANGED:
178 {
179 sp<AMessage> format;
180 CHECK(msg->findMessage("format", &format));
181
182 handleOutputFormatChange(format);
183 break;
184 }
185
186 case MediaCodec::CB_ERROR:
187 {
188 status_t err;
189 CHECK(msg->findInt32("err", &err));
190 ALOGE("Decoder (%s) reported error : 0x%x",
191 mIsAudio ? "audio" : "video", err);
192
193 handleError(err);
194 break;
195 }
196
197 default:
198 {
199 TRESPASS();
200 break;
201 }
202 }
203
Lajos Molnar87603c02014-08-20 19:25:30 -0700204 break;
205 }
Chong Zhang7137ec72014-11-12 16:41:05 -0800206
207 case kWhatRenderBuffer:
208 {
209 if (!isStaleReply(msg)) {
210 onRenderBuffer(msg);
211 }
212 break;
213 }
214
Wei Jia9a3101b2016-11-08 14:34:24 -0800215 case kWhatAudioOutputFormatChanged:
216 {
217 if (!isStaleReply(msg)) {
218 status_t err;
219 if (msg->findInt32("err", &err) && err != OK) {
220 ALOGE("Renderer reported 0x%x when changing audio output format", err);
221 handleError(err);
222 }
223 }
224 break;
225 }
226
Lajos Molnara81c6222015-07-10 19:17:45 -0700227 case kWhatSetVideoSurface:
228 {
229 sp<AReplyToken> replyID;
230 CHECK(msg->senderAwaitsResponse(&replyID));
231
232 sp<RefBase> obj;
233 CHECK(msg->findObject("surface", &obj));
234 sp<Surface> surface = static_cast<Surface *>(obj.get()); // non-null
235 int32_t err = INVALID_OPERATION;
236 // NOTE: in practice mSurface is always non-null, but checking here for completeness
237 if (mCodec != NULL && mSurface != NULL) {
238 // TODO: once AwesomePlayer is removed, remove this automatic connecting
239 // to the surface by MediaPlayerService.
240 //
241 // at this point MediaPlayerService::client has already connected to the
242 // surface, which MediaCodec does not expect
Chong Zhang181fd9b2017-02-16 15:53:03 -0800243 err = nativeWindowDisconnect(surface.get(), "kWhatSetVideoSurface(surface)");
Lajos Molnara81c6222015-07-10 19:17:45 -0700244 if (err == OK) {
245 err = mCodec->setSurface(surface);
246 ALOGI_IF(err, "codec setSurface returned: %d", err);
247 if (err == OK) {
248 // reconnect to the old surface as MPS::Client will expect to
249 // be able to disconnect from it.
Chong Zhang181fd9b2017-02-16 15:53:03 -0800250 (void)nativeWindowConnect(mSurface.get(), "kWhatSetVideoSurface(mSurface)");
Lajos Molnara81c6222015-07-10 19:17:45 -0700251 mSurface = surface;
252 }
253 }
254 if (err != OK) {
255 // reconnect to the new surface on error as MPS::Client will expect to
256 // be able to disconnect from it.
Chong Zhang181fd9b2017-02-16 15:53:03 -0800257 (void)nativeWindowConnect(surface.get(), "kWhatSetVideoSurface(err)");
Lajos Molnara81c6222015-07-10 19:17:45 -0700258 }
259 }
260
261 sp<AMessage> response = new AMessage;
262 response->setInt32("err", err);
263 response->postReply(replyID);
264 break;
265 }
266
Hassan Shojaniacefac142017-02-06 21:02:02 -0800267 case kWhatDrmReleaseCrypto:
268 {
269 ALOGV("kWhatDrmReleaseCrypto");
270 onReleaseCrypto(msg);
271 break;
272 }
273
Chong Zhang7137ec72014-11-12 16:41:05 -0800274 default:
275 DecoderBase::onMessageReceived(msg);
276 break;
Lajos Molnar87603c02014-08-20 19:25:30 -0700277 }
278}
279
Lajos Molnar1cd13982014-01-17 15:12:51 -0800280void NuPlayer::Decoder::onConfigure(const sp<AMessage> &format) {
Andreas Huberf9334412010-12-15 15:17:42 -0800281 CHECK(mCodec == NULL);
Andreas Huberf9334412010-12-15 15:17:42 -0800282
Chong Zhang7137ec72014-11-12 16:41:05 -0800283 mFormatChangePending = false;
Chong Zhang66704af2015-03-03 19:32:35 -0800284 mTimeChangePending = false;
Chong Zhang7137ec72014-11-12 16:41:05 -0800285
Lajos Molnar1cd13982014-01-17 15:12:51 -0800286 ++mBufferGeneration;
287
Andreas Huber84066782011-08-16 09:34:26 -0700288 AString mime;
289 CHECK(format->findString("mime", &mime));
Andreas Huberf9334412010-12-15 15:17:42 -0800290
Chong Zhang7137ec72014-11-12 16:41:05 -0800291 mIsAudio = !strncasecmp("audio/", mime.c_str(), 6);
292 mIsVideoAVC = !strcasecmp(MEDIA_MIMETYPE_VIDEO_AVC, mime.c_str());
293
Lajos Molnar1cd13982014-01-17 15:12:51 -0800294 mComponentName = mime;
295 mComponentName.append(" decoder");
Lajos Molnar1de1e252015-04-30 18:18:34 -0700296 ALOGV("[%s] onConfigure (surface=%p)", mComponentName.c_str(), mSurface.get());
Lajos Molnar1cd13982014-01-17 15:12:51 -0800297
Ronghua Wu68845c12015-07-21 09:50:48 -0700298 mCodec = MediaCodec::CreateByType(
Wei Jiaf2ae3e12016-10-27 17:10:59 -0700299 mCodecLooper, mime.c_str(), false /* encoder */, NULL /* err */, mPid, mUid);
Lajos Molnar09524832014-07-17 14:29:51 -0700300 int32_t secure = 0;
301 if (format->findInt32("secure", &secure) && secure != 0) {
302 if (mCodec != NULL) {
303 mCodec->getName(&mComponentName);
304 mComponentName.append(".secure");
305 mCodec->release();
306 ALOGI("[%s] creating", mComponentName.c_str());
307 mCodec = MediaCodec::CreateByComponentName(
Wei Jiaf2ae3e12016-10-27 17:10:59 -0700308 mCodecLooper, mComponentName.c_str(), NULL /* err */, mPid, mUid);
Lajos Molnar09524832014-07-17 14:29:51 -0700309 }
310 }
Lajos Molnar1cd13982014-01-17 15:12:51 -0800311 if (mCodec == NULL) {
Lajos Molnar09524832014-07-17 14:29:51 -0700312 ALOGE("Failed to create %s%s decoder",
313 (secure ? "secure " : ""), mime.c_str());
Lajos Molnar1cd13982014-01-17 15:12:51 -0800314 handleError(UNKNOWN_ERROR);
315 return;
316 }
Chong Zhang7137ec72014-11-12 16:41:05 -0800317 mIsSecure = secure;
Lajos Molnar1cd13982014-01-17 15:12:51 -0800318
319 mCodec->getName(&mComponentName);
320
Lajos Molnar14986f62014-09-15 11:04:44 -0700321 status_t err;
Lajos Molnar1de1e252015-04-30 18:18:34 -0700322 if (mSurface != NULL) {
Lajos Molnar1cd13982014-01-17 15:12:51 -0800323 // disconnect from surface as MediaCodec will reconnect
Chong Zhang181fd9b2017-02-16 15:53:03 -0800324 err = nativeWindowDisconnect(mSurface.get(), "onConfigure");
Lajos Molnar14986f62014-09-15 11:04:44 -0700325 // We treat this as a warning, as this is a preparatory step.
326 // Codec will try to connect to the surface, which is where
327 // any error signaling will occur.
328 ALOGW_IF(err != OK, "failed to disconnect from surface: %d", err);
Lajos Molnar1cd13982014-01-17 15:12:51 -0800329 }
Hassan Shojaniacefac142017-02-06 21:02:02 -0800330
331 // Modular DRM
332 void *pCrypto;
333 if (!format->findPointer("crypto", &pCrypto)) {
334 pCrypto = NULL;
335 }
336 sp<ICrypto> crypto = (ICrypto*)pCrypto;
Hassan Shojania62dec952017-05-18 10:45:27 -0700337 // non-encrypted source won't have a crypto
338 mIsEncrypted = (crypto != NULL);
339 // configure is called once; still using OR in case the behavior changes.
340 mIsEncryptedObservedEarlier = mIsEncryptedObservedEarlier || mIsEncrypted;
Hassan Shojaniacefac142017-02-06 21:02:02 -0800341 ALOGV("onConfigure mCrypto: %p (%d) mIsSecure: %d",
342 crypto.get(), (crypto != NULL ? crypto->getStrongCount() : 0), mIsSecure);
343
Lajos Molnar14986f62014-09-15 11:04:44 -0700344 err = mCodec->configure(
Hassan Shojaniacefac142017-02-06 21:02:02 -0800345 format, mSurface, crypto, 0 /* flags */);
346
Lajos Molnar1cd13982014-01-17 15:12:51 -0800347 if (err != OK) {
Wei Jiafcd87872017-07-28 15:50:04 -0700348 ALOGE("Failed to configure [%s] decoder (err=%d)", mComponentName.c_str(), err);
Andy Hung2abde2c2014-09-30 14:40:32 -0700349 mCodec->release();
350 mCodec.clear();
Lajos Molnar1cd13982014-01-17 15:12:51 -0800351 handleError(err);
352 return;
353 }
Lajos Molnar87603c02014-08-20 19:25:30 -0700354 rememberCodecSpecificData(format);
355
Lajos Molnar1cd13982014-01-17 15:12:51 -0800356 // the following should work in configured state
357 CHECK_EQ((status_t)OK, mCodec->getOutputFormat(&mOutputFormat));
358 CHECK_EQ((status_t)OK, mCodec->getInputFormat(&mInputFormat));
359
Praveen Chavane1e5d7a2015-05-19 19:09:48 -0700360 mStats->setString("mime", mime.c_str());
361 mStats->setString("component-name", mComponentName.c_str());
362
363 if (!mIsAudio) {
364 int32_t width, height;
365 if (mOutputFormat->findInt32("width", &width)
366 && mOutputFormat->findInt32("height", &height)) {
367 mStats->setInt32("width", width);
368 mStats->setInt32("height", height);
369 }
370 }
371
Marco Nelissen421f47c2015-03-25 14:40:32 -0700372 sp<AMessage> reply = new AMessage(kWhatCodecNotify, this);
373 mCodec->setCallback(reply);
374
Lajos Molnar1cd13982014-01-17 15:12:51 -0800375 err = mCodec->start();
376 if (err != OK) {
Wei Jiafcd87872017-07-28 15:50:04 -0700377 ALOGE("Failed to start [%s] decoder (err=%d)", mComponentName.c_str(), err);
Andy Hung2abde2c2014-09-30 14:40:32 -0700378 mCodec->release();
379 mCodec.clear();
Lajos Molnar1cd13982014-01-17 15:12:51 -0800380 handleError(err);
381 return;
Andreas Huberf9334412010-12-15 15:17:42 -0800382 }
383
Lajos Molnar09524832014-07-17 14:29:51 -0700384 releaseAndResetMediaBuffers();
Marco Nelissen421f47c2015-03-25 14:40:32 -0700385
Wei Jia704e7262014-06-04 16:21:56 -0700386 mPaused = false;
Chong Zhangf8d71772014-11-26 15:08:34 -0800387 mResumePending = false;
Lajos Molnar1cd13982014-01-17 15:12:51 -0800388}
Andreas Huber078cfcf2011-09-15 12:25:04 -0700389
Ronghua Wu8db88132015-04-22 13:51:35 -0700390void NuPlayer::Decoder::onSetParameters(const sp<AMessage> &params) {
Praveen Chavanbbaa1442016-04-08 13:33:49 -0700391 bool needAdjustLayers = false;
392 float frameRateTotal;
393 if (params->findFloat("frame-rate-total", &frameRateTotal)
394 && mFrameRateTotal != frameRateTotal) {
395 needAdjustLayers = true;
396 mFrameRateTotal = frameRateTotal;
Ronghua Wu8db88132015-04-22 13:51:35 -0700397 }
Praveen Chavanbbaa1442016-04-08 13:33:49 -0700398
399 int32_t numVideoTemporalLayerTotal;
400 if (params->findInt32("temporal-layer-count", &numVideoTemporalLayerTotal)
Lajos Molnar9fb81522016-07-14 07:33:43 -0700401 && numVideoTemporalLayerTotal >= 0
Praveen Chavanbbaa1442016-04-08 13:33:49 -0700402 && numVideoTemporalLayerTotal <= kMaxNumVideoTemporalLayers
403 && mNumVideoTemporalLayerTotal != numVideoTemporalLayerTotal) {
404 needAdjustLayers = true;
Lajos Molnar9fb81522016-07-14 07:33:43 -0700405 mNumVideoTemporalLayerTotal = std::max(numVideoTemporalLayerTotal, 1);
Praveen Chavanbbaa1442016-04-08 13:33:49 -0700406 }
407
Lajos Molnar9fb81522016-07-14 07:33:43 -0700408 if (needAdjustLayers && mNumVideoTemporalLayerTotal > 1) {
Praveen Chavanbbaa1442016-04-08 13:33:49 -0700409 // TODO: For now, layer fps is calculated for some specific architectures.
410 // But it really should be extracted from the stream.
411 mVideoTemporalLayerAggregateFps[0] =
412 mFrameRateTotal / (float)(1ll << (mNumVideoTemporalLayerTotal - 1));
413 for (int32_t i = 1; i < mNumVideoTemporalLayerTotal; ++i) {
414 mVideoTemporalLayerAggregateFps[i] =
415 mFrameRateTotal / (float)(1ll << (mNumVideoTemporalLayerTotal - i))
416 + mVideoTemporalLayerAggregateFps[i - 1];
417 }
418 }
419
420 float playbackSpeed;
421 if (params->findFloat("playback-speed", &playbackSpeed)
422 && mPlaybackSpeed != playbackSpeed) {
423 needAdjustLayers = true;
424 mPlaybackSpeed = playbackSpeed;
425 }
426
427 if (needAdjustLayers) {
Lajos Molnar9fb81522016-07-14 07:33:43 -0700428 float decodeFrameRate = mFrameRateTotal;
429 // enable temporal layering optimization only if we know the layering depth
430 if (mNumVideoTemporalLayerTotal > 1) {
431 int32_t layerId;
432 for (layerId = 0; layerId < mNumVideoTemporalLayerTotal - 1; ++layerId) {
433 if (mVideoTemporalLayerAggregateFps[layerId] * mPlaybackSpeed
434 >= kDisplayRefreshingRate * 0.9) {
435 break;
436 }
Praveen Chavanbbaa1442016-04-08 13:33:49 -0700437 }
Lajos Molnar9fb81522016-07-14 07:33:43 -0700438 mNumVideoTemporalLayerAllowed = layerId + 1;
439 decodeFrameRate = mVideoTemporalLayerAggregateFps[layerId];
Praveen Chavanbbaa1442016-04-08 13:33:49 -0700440 }
Lajos Molnar9fb81522016-07-14 07:33:43 -0700441 ALOGV("onSetParameters: allowed layers=%d, decodeFps=%g",
442 mNumVideoTemporalLayerAllowed, decodeFrameRate);
Praveen Chavanbbaa1442016-04-08 13:33:49 -0700443
444 if (mCodec == NULL) {
445 ALOGW("onSetParameters called before codec is created.");
446 return;
447 }
448
449 sp<AMessage> codecParams = new AMessage();
Lajos Molnar9fb81522016-07-14 07:33:43 -0700450 codecParams->setFloat("operating-rate", decodeFrameRate * mPlaybackSpeed);
Praveen Chavanbbaa1442016-04-08 13:33:49 -0700451 mCodec->setParameters(codecParams);
452 }
Ronghua Wu8db88132015-04-22 13:51:35 -0700453}
454
Chong Zhang7137ec72014-11-12 16:41:05 -0800455void NuPlayer::Decoder::onSetRenderer(const sp<Renderer> &renderer) {
Chong Zhang7137ec72014-11-12 16:41:05 -0800456 mRenderer = renderer;
Chong Zhang7137ec72014-11-12 16:41:05 -0800457}
458
Chong Zhangf8d71772014-11-26 15:08:34 -0800459void NuPlayer::Decoder::onResume(bool notifyComplete) {
Chong Zhang7137ec72014-11-12 16:41:05 -0800460 mPaused = false;
Chong Zhangf8d71772014-11-26 15:08:34 -0800461
462 if (notifyComplete) {
463 mResumePending = true;
464 }
Wei Jiafcd87872017-07-28 15:50:04 -0700465
466 if (mCodec == NULL) {
467 ALOGE("[%s] onResume without a valid codec", mComponentName.c_str());
468 handleError(NO_INIT);
469 return;
470 }
Marco Nelissen421f47c2015-03-25 14:40:32 -0700471 mCodec->start();
Chong Zhang7137ec72014-11-12 16:41:05 -0800472}
473
Chong Zhang66704af2015-03-03 19:32:35 -0800474void NuPlayer::Decoder::doFlush(bool notifyComplete) {
Chong Zhang7137ec72014-11-12 16:41:05 -0800475 if (mCCDecoder != NULL) {
476 mCCDecoder->flush();
477 }
478
479 if (mRenderer != NULL) {
480 mRenderer->flush(mIsAudio, notifyComplete);
481 mRenderer->signalTimeDiscontinuity();
482 }
483
484 status_t err = OK;
485 if (mCodec != NULL) {
486 err = mCodec->flush();
487 mCSDsToSubmit = mCSDsForCurrentFormat; // copy operator
488 ++mBufferGeneration;
489 }
490
491 if (err != OK) {
Wei Jiafcd87872017-07-28 15:50:04 -0700492 ALOGE("failed to flush [%s] (err=%d)", mComponentName.c_str(), err);
Chong Zhang7137ec72014-11-12 16:41:05 -0800493 handleError(err);
494 // finish with posting kWhatFlushCompleted.
495 // we attempt to release the buffers even if flush fails.
496 }
497 releaseAndResetMediaBuffers();
Marco Nelissen421f47c2015-03-25 14:40:32 -0700498 mPaused = true;
Chong Zhang66704af2015-03-03 19:32:35 -0800499}
Chong Zhang7137ec72014-11-12 16:41:05 -0800500
Marco Nelissen421f47c2015-03-25 14:40:32 -0700501
Chong Zhang66704af2015-03-03 19:32:35 -0800502void NuPlayer::Decoder::onFlush() {
503 doFlush(true);
504
505 if (isDiscontinuityPending()) {
506 // This could happen if the client starts seeking/shutdown
507 // after we queued an EOS for discontinuities.
508 // We can consider discontinuity handled.
509 finishHandleDiscontinuity(false /* flushOnTimeChange */);
Chong Zhang7137ec72014-11-12 16:41:05 -0800510 }
Chong Zhang66704af2015-03-03 19:32:35 -0800511
512 sp<AMessage> notify = mNotify->dup();
513 notify->setInt32("what", kWhatFlushCompleted);
514 notify->post();
Chong Zhang7137ec72014-11-12 16:41:05 -0800515}
516
517void NuPlayer::Decoder::onShutdown(bool notifyComplete) {
518 status_t err = OK;
Chong Zhangf8d71772014-11-26 15:08:34 -0800519
520 // if there is a pending resume request, notify complete now
521 notifyResumeCompleteIfNecessary();
522
Chong Zhang7137ec72014-11-12 16:41:05 -0800523 if (mCodec != NULL) {
524 err = mCodec->release();
525 mCodec = NULL;
526 ++mBufferGeneration;
527
Lajos Molnar1de1e252015-04-30 18:18:34 -0700528 if (mSurface != NULL) {
Chong Zhang7137ec72014-11-12 16:41:05 -0800529 // reconnect to surface as MediaCodec disconnected from it
Chong Zhang181fd9b2017-02-16 15:53:03 -0800530 status_t error = nativeWindowConnect(mSurface.get(), "onShutdown");
Chong Zhang7137ec72014-11-12 16:41:05 -0800531 ALOGW_IF(error != NO_ERROR,
532 "[%s] failed to connect to native window, error=%d",
533 mComponentName.c_str(), error);
534 }
535 mComponentName = "decoder";
536 }
537
538 releaseAndResetMediaBuffers();
539
540 if (err != OK) {
Wei Jiafcd87872017-07-28 15:50:04 -0700541 ALOGE("failed to release [%s] (err=%d)", mComponentName.c_str(), err);
Chong Zhang7137ec72014-11-12 16:41:05 -0800542 handleError(err);
543 // finish with posting kWhatShutdownCompleted.
544 }
545
546 if (notifyComplete) {
547 sp<AMessage> notify = mNotify->dup();
548 notify->setInt32("what", kWhatShutdownCompleted);
549 notify->post();
550 mPaused = true;
551 }
552}
553
Chong Zhang3b032b32015-04-17 15:49:06 -0700554/*
555 * returns true if we should request more data
556 */
557bool NuPlayer::Decoder::doRequestBuffers() {
Jeff Tinker29b7dcf2016-10-24 10:28:30 -0700558 if (isDiscontinuityPending()) {
Chong Zhang3b032b32015-04-17 15:49:06 -0700559 return false;
Chong Zhang7137ec72014-11-12 16:41:05 -0800560 }
561 status_t err = OK;
Chong Zhang66704af2015-03-03 19:32:35 -0800562 while (err == OK && !mDequeuedInputBuffers.empty()) {
Chong Zhang7137ec72014-11-12 16:41:05 -0800563 size_t bufferIx = *mDequeuedInputBuffers.begin();
564 sp<AMessage> msg = new AMessage();
565 msg->setSize("buffer-ix", bufferIx);
566 err = fetchInputData(msg);
Chong Zhang66704af2015-03-03 19:32:35 -0800567 if (err != OK && err != ERROR_END_OF_STREAM) {
568 // if EOS, need to queue EOS buffer
Chong Zhang7137ec72014-11-12 16:41:05 -0800569 break;
570 }
571 mDequeuedInputBuffers.erase(mDequeuedInputBuffers.begin());
572
573 if (!mPendingInputMessages.empty()
574 || !onInputBufferFetched(msg)) {
575 mPendingInputMessages.push_back(msg);
Lajos Molnar09524832014-07-17 14:29:51 -0700576 }
577 }
Chong Zhang7137ec72014-11-12 16:41:05 -0800578
Chong Zhang3b032b32015-04-17 15:49:06 -0700579 return err == -EWOULDBLOCK
580 && mSource->feedMoreTSData() == OK;
Lajos Molnar09524832014-07-17 14:29:51 -0700581}
582
Marco Nelissen421f47c2015-03-25 14:40:32 -0700583void NuPlayer::Decoder::handleError(int32_t err)
584{
585 // We cannot immediately release the codec due to buffers still outstanding
586 // in the renderer. We signal to the player the error so it can shutdown/release the
587 // decoder after flushing and increment the generation to discard unnecessary messages.
588
589 ++mBufferGeneration;
590
591 sp<AMessage> notify = mNotify->dup();
592 notify->setInt32("what", kWhatError);
593 notify->setInt32("err", err);
594 notify->post();
595}
596
Hassan Shojaniacefac142017-02-06 21:02:02 -0800597status_t NuPlayer::Decoder::releaseCrypto()
598{
599 ALOGV("releaseCrypto");
600
601 sp<AMessage> msg = new AMessage(kWhatDrmReleaseCrypto, this);
602
603 sp<AMessage> response;
604 status_t status = msg->postAndAwaitResponse(&response);
605 if (status == OK && response != NULL) {
606 CHECK(response->findInt32("status", &status));
607 ALOGV("releaseCrypto ret: %d ", status);
608 } else {
609 ALOGE("releaseCrypto err: %d", status);
610 }
611
612 return status;
613}
614
615void NuPlayer::Decoder::onReleaseCrypto(const sp<AMessage>& msg)
616{
617 status_t status = INVALID_OPERATION;
618 if (mCodec != NULL) {
619 status = mCodec->releaseCrypto();
620 } else {
621 // returning OK if the codec has been already released
622 status = OK;
623 ALOGE("onReleaseCrypto No mCodec. err: %d", status);
624 }
625
626 sp<AMessage> response = new AMessage;
627 response->setInt32("status", status);
Hassan Shojania62dec952017-05-18 10:45:27 -0700628 // Clearing the state as it's tied to crypto. mIsEncryptedObservedEarlier is sticky though
629 // and lasts for the lifetime of this codec. See its use in fetchInputData.
630 mIsEncrypted = false;
Hassan Shojaniacefac142017-02-06 21:02:02 -0800631
632 sp<AReplyToken> replyID;
633 CHECK(msg->senderAwaitsResponse(&replyID));
634 response->postReply(replyID);
635}
636
Marco Nelissen421f47c2015-03-25 14:40:32 -0700637bool NuPlayer::Decoder::handleAnInputBuffer(size_t index) {
Chong Zhang66704af2015-03-03 19:32:35 -0800638 if (isDiscontinuityPending()) {
Chong Zhang7137ec72014-11-12 16:41:05 -0800639 return false;
640 }
Marco Nelissen421f47c2015-03-25 14:40:32 -0700641
Wei Jiafcd87872017-07-28 15:50:04 -0700642 if (mCodec == NULL) {
643 ALOGE("[%s] handleAnInputBuffer without a valid codec", mComponentName.c_str());
644 handleError(NO_INIT);
645 return false;
646 }
647
Wonsik Kim7e34bf52016-08-23 00:09:18 +0900648 sp<MediaCodecBuffer> buffer;
Marco Nelissen421f47c2015-03-25 14:40:32 -0700649 mCodec->getInputBuffer(index, &buffer);
650
Wei Jia6301a5e2015-05-13 13:15:18 -0700651 if (buffer == NULL) {
Wei Jiafcd87872017-07-28 15:50:04 -0700652 ALOGE("[%s] handleAnInputBuffer, failed to get input buffer", mComponentName.c_str());
Wei Jia6301a5e2015-05-13 13:15:18 -0700653 handleError(UNKNOWN_ERROR);
654 return false;
655 }
656
Marco Nelissen421f47c2015-03-25 14:40:32 -0700657 if (index >= mInputBuffers.size()) {
658 for (size_t i = mInputBuffers.size(); i <= index; ++i) {
659 mInputBuffers.add();
660 mMediaBuffers.add();
661 mInputBufferIsDequeued.add();
662 mMediaBuffers.editItemAt(i) = NULL;
663 mInputBufferIsDequeued.editItemAt(i) = false;
Lajos Molnar1cd13982014-01-17 15:12:51 -0800664 }
Andreas Huber078cfcf2011-09-15 12:25:04 -0700665 }
Marco Nelissen421f47c2015-03-25 14:40:32 -0700666 mInputBuffers.editItemAt(index) = buffer;
Andreas Huber078cfcf2011-09-15 12:25:04 -0700667
Marco Nelissen421f47c2015-03-25 14:40:32 -0700668 //CHECK_LT(bufferIx, mInputBuffers.size());
Andreas Huberf9334412010-12-15 15:17:42 -0800669
Marco Nelissen421f47c2015-03-25 14:40:32 -0700670 if (mMediaBuffers[index] != NULL) {
671 mMediaBuffers[index]->release();
672 mMediaBuffers.editItemAt(index) = NULL;
Lajos Molnar09524832014-07-17 14:29:51 -0700673 }
Marco Nelissen421f47c2015-03-25 14:40:32 -0700674 mInputBufferIsDequeued.editItemAt(index) = true;
Lajos Molnar09524832014-07-17 14:29:51 -0700675
Lajos Molnar87603c02014-08-20 19:25:30 -0700676 if (!mCSDsToSubmit.isEmpty()) {
Chong Zhang7137ec72014-11-12 16:41:05 -0800677 sp<AMessage> msg = new AMessage();
Marco Nelissen421f47c2015-03-25 14:40:32 -0700678 msg->setSize("buffer-ix", index);
Chong Zhang7137ec72014-11-12 16:41:05 -0800679
Lajos Molnar87603c02014-08-20 19:25:30 -0700680 sp<ABuffer> buffer = mCSDsToSubmit.itemAt(0);
681 ALOGI("[%s] resubmitting CSD", mComponentName.c_str());
Chong Zhang7137ec72014-11-12 16:41:05 -0800682 msg->setBuffer("buffer", buffer);
Lajos Molnar87603c02014-08-20 19:25:30 -0700683 mCSDsToSubmit.removeAt(0);
Wei Jia56097a82016-01-07 16:03:03 -0800684 if (!onInputBufferFetched(msg)) {
685 handleError(UNKNOWN_ERROR);
686 return false;
687 }
Wei Jia2245fc62014-10-02 15:12:25 -0700688 return true;
689 }
690
691 while (!mPendingInputMessages.empty()) {
692 sp<AMessage> msg = *mPendingInputMessages.begin();
Chong Zhang7137ec72014-11-12 16:41:05 -0800693 if (!onInputBufferFetched(msg)) {
Wei Jia2245fc62014-10-02 15:12:25 -0700694 break;
695 }
696 mPendingInputMessages.erase(mPendingInputMessages.begin());
697 }
698
Marco Nelissen421f47c2015-03-25 14:40:32 -0700699 if (!mInputBufferIsDequeued.editItemAt(index)) {
Lajos Molnar87603c02014-08-20 19:25:30 -0700700 return true;
701 }
702
Marco Nelissen421f47c2015-03-25 14:40:32 -0700703 mDequeuedInputBuffers.push_back(index);
Chong Zhang7137ec72014-11-12 16:41:05 -0800704
705 onRequestInputBuffers();
Lajos Molnar1cd13982014-01-17 15:12:51 -0800706 return true;
707}
708
Marco Nelissen421f47c2015-03-25 14:40:32 -0700709bool NuPlayer::Decoder::handleAnOutputBuffer(
710 size_t index,
711 size_t offset,
712 size_t size,
713 int64_t timeUs,
714 int32_t flags) {
Wei Jiafcd87872017-07-28 15:50:04 -0700715 if (mCodec == NULL) {
716 ALOGE("[%s] handleAnOutputBuffer without a valid codec", mComponentName.c_str());
717 handleError(NO_INIT);
718 return false;
719 }
720
Marco Nelissen421f47c2015-03-25 14:40:32 -0700721// CHECK_LT(bufferIx, mOutputBuffers.size());
Wonsik Kim7e34bf52016-08-23 00:09:18 +0900722 sp<MediaCodecBuffer> buffer;
Marco Nelissen421f47c2015-03-25 14:40:32 -0700723 mCodec->getOutputBuffer(index, &buffer);
724
Santhosh Behara3539def2015-10-09 17:32:58 -0700725 if (buffer == NULL) {
Wei Jiafcd87872017-07-28 15:50:04 -0700726 ALOGE("[%s] handleAnOutputBuffer, failed to get output buffer", mComponentName.c_str());
Santhosh Behara3539def2015-10-09 17:32:58 -0700727 handleError(UNKNOWN_ERROR);
728 return false;
729 }
730
Marco Nelissen421f47c2015-03-25 14:40:32 -0700731 if (index >= mOutputBuffers.size()) {
732 for (size_t i = mOutputBuffers.size(); i <= index; ++i) {
733 mOutputBuffers.add();
734 }
735 }
736
737 mOutputBuffers.editItemAt(index) = buffer;
738
Chong Zhang7137ec72014-11-12 16:41:05 -0800739 buffer->setRange(offset, size);
740 buffer->meta()->clear();
741 buffer->meta()->setInt64("timeUs", timeUs);
Chong Zhang66704af2015-03-03 19:32:35 -0800742
743 bool eos = flags & MediaCodec::BUFFER_FLAG_EOS;
Chong Zhang7137ec72014-11-12 16:41:05 -0800744 // we do not expect CODECCONFIG or SYNCFRAME for decoder
745
Lajos Molnar1d15ab52015-03-04 16:46:34 -0800746 sp<AMessage> reply = new AMessage(kWhatRenderBuffer, this);
Marco Nelissen421f47c2015-03-25 14:40:32 -0700747 reply->setSize("buffer-ix", index);
Chong Zhang7137ec72014-11-12 16:41:05 -0800748 reply->setInt32("generation", mBufferGeneration);
Praveen Chavanbc5fe9a2018-04-27 16:18:11 -0700749 reply->setSize("size", size);
Chong Zhang7137ec72014-11-12 16:41:05 -0800750
Chong Zhang66704af2015-03-03 19:32:35 -0800751 if (eos) {
752 ALOGI("[%s] saw output EOS", mIsAudio ? "audio" : "video");
753
754 buffer->meta()->setInt32("eos", true);
755 reply->setInt32("eos", true);
Wei Jiaaec8d822017-08-25 15:27:57 -0700756 }
757
Ray Essickc6e9f6e2017-12-07 16:57:36 -0800758 mNumFramesTotal += !mIsAudio;
759
Wei Jiaaec8d822017-08-25 15:27:57 -0700760 if (mSkipRenderingUntilMediaTimeUs >= 0) {
Chong Zhang7137ec72014-11-12 16:41:05 -0800761 if (timeUs < mSkipRenderingUntilMediaTimeUs) {
762 ALOGV("[%s] dropping buffer at time %lld as requested.",
763 mComponentName.c_str(), (long long)timeUs);
764
765 reply->post();
Wei Jiaaec8d822017-08-25 15:27:57 -0700766 if (eos) {
767 notifyResumeCompleteIfNecessary();
768 if (mRenderer != NULL && !isDiscontinuityPending()) {
769 mRenderer->queueEOS(mIsAudio, ERROR_END_OF_STREAM);
770 }
771 }
Chong Zhang7137ec72014-11-12 16:41:05 -0800772 return true;
773 }
774
775 mSkipRenderingUntilMediaTimeUs = -1;
776 }
777
Chong Zhangf8d71772014-11-26 15:08:34 -0800778 // wait until 1st frame comes out to signal resume complete
779 notifyResumeCompleteIfNecessary();
780
Chong Zhang7137ec72014-11-12 16:41:05 -0800781 if (mRenderer != NULL) {
782 // send the buffer to renderer.
783 mRenderer->queueBuffer(mIsAudio, buffer, reply);
Chong Zhang66704af2015-03-03 19:32:35 -0800784 if (eos && !isDiscontinuityPending()) {
Chong Zhang7137ec72014-11-12 16:41:05 -0800785 mRenderer->queueEOS(mIsAudio, ERROR_END_OF_STREAM);
786 }
787 }
788
789 return true;
790}
791
Marco Nelissen421f47c2015-03-25 14:40:32 -0700792void NuPlayer::Decoder::handleOutputFormatChange(const sp<AMessage> &format) {
793 if (!mIsAudio) {
Praveen Chavane1e5d7a2015-05-19 19:09:48 -0700794 int32_t width, height;
795 if (format->findInt32("width", &width)
796 && format->findInt32("height", &height)) {
797 mStats->setInt32("width", width);
798 mStats->setInt32("height", height);
799 }
Marco Nelissen421f47c2015-03-25 14:40:32 -0700800 sp<AMessage> notify = mNotify->dup();
801 notify->setInt32("what", kWhatVideoSizeChanged);
802 notify->setMessage("format", format);
803 notify->post();
804 } else if (mRenderer != NULL) {
805 uint32_t flags;
806 int64_t durationUs;
807 bool hasVideo = (mSource->getFormat(false /* audio */) != NULL);
Andy Hung288da022015-05-31 22:55:59 -0700808 if (getAudioDeepBufferSetting() // override regardless of source duration
Andy Hung71c8e5c2017-04-03 15:50:27 -0700809 || (mSource->getDuration(&durationUs) == OK
Andy Hung288da022015-05-31 22:55:59 -0700810 && durationUs > AUDIO_SINK_MIN_DEEP_BUFFER_DURATION_US)) {
Marco Nelissen421f47c2015-03-25 14:40:32 -0700811 flags = AUDIO_OUTPUT_FLAG_DEEP_BUFFER;
812 } else {
813 flags = AUDIO_OUTPUT_FLAG_NONE;
814 }
815
Wei Jia9a3101b2016-11-08 14:34:24 -0800816 sp<AMessage> reply = new AMessage(kWhatAudioOutputFormatChanged, this);
817 reply->setInt32("generation", mBufferGeneration);
818 mRenderer->changeAudioFormat(
Dhananjay Kumarc387f2b2015-08-06 10:43:16 +0530819 format, false /* offloadOnly */, hasVideo,
820 flags, mSource->isStreaming(), reply);
Marco Nelissen421f47c2015-03-25 14:40:32 -0700821 }
822}
823
Chong Zhang7137ec72014-11-12 16:41:05 -0800824void NuPlayer::Decoder::releaseAndResetMediaBuffers() {
825 for (size_t i = 0; i < mMediaBuffers.size(); i++) {
826 if (mMediaBuffers[i] != NULL) {
827 mMediaBuffers[i]->release();
828 mMediaBuffers.editItemAt(i) = NULL;
829 }
830 }
831 mMediaBuffers.resize(mInputBuffers.size());
832 for (size_t i = 0; i < mMediaBuffers.size(); i++) {
833 mMediaBuffers.editItemAt(i) = NULL;
834 }
835 mInputBufferIsDequeued.clear();
836 mInputBufferIsDequeued.resize(mInputBuffers.size());
837 for (size_t i = 0; i < mInputBufferIsDequeued.size(); i++) {
838 mInputBufferIsDequeued.editItemAt(i) = false;
839 }
840
841 mPendingInputMessages.clear();
842 mDequeuedInputBuffers.clear();
843 mSkipRenderingUntilMediaTimeUs = -1;
844}
845
846void NuPlayer::Decoder::requestCodecNotification() {
Chong Zhang7137ec72014-11-12 16:41:05 -0800847 if (mCodec != NULL) {
Lajos Molnar1d15ab52015-03-04 16:46:34 -0800848 sp<AMessage> reply = new AMessage(kWhatCodecNotify, this);
Chong Zhang7137ec72014-11-12 16:41:05 -0800849 reply->setInt32("generation", mBufferGeneration);
850 mCodec->requestActivityNotification(reply);
851 }
852}
853
854bool NuPlayer::Decoder::isStaleReply(const sp<AMessage> &msg) {
855 int32_t generation;
856 CHECK(msg->findInt32("generation", &generation));
857 return generation != mBufferGeneration;
858}
859
860status_t NuPlayer::Decoder::fetchInputData(sp<AMessage> &reply) {
861 sp<ABuffer> accessUnit;
Robert Shih59e9ca72016-10-20 13:51:42 -0700862 bool dropAccessUnit = true;
Chong Zhang7137ec72014-11-12 16:41:05 -0800863 do {
864 status_t err = mSource->dequeueAccessUnit(mIsAudio, &accessUnit);
865
866 if (err == -EWOULDBLOCK) {
867 return err;
868 } else if (err != OK) {
869 if (err == INFO_DISCONTINUITY) {
870 int32_t type;
871 CHECK(accessUnit->meta()->findInt32("discontinuity", &type));
872
873 bool formatChange =
874 (mIsAudio &&
875 (type & ATSParser::DISCONTINUITY_AUDIO_FORMAT))
876 || (!mIsAudio &&
877 (type & ATSParser::DISCONTINUITY_VIDEO_FORMAT));
878
879 bool timeChange = (type & ATSParser::DISCONTINUITY_TIME) != 0;
880
881 ALOGI("%s discontinuity (format=%d, time=%d)",
882 mIsAudio ? "audio" : "video", formatChange, timeChange);
883
884 bool seamlessFormatChange = false;
885 sp<AMessage> newFormat = mSource->getFormat(mIsAudio);
886 if (formatChange) {
887 seamlessFormatChange =
888 supportsSeamlessFormatChange(newFormat);
889 // treat seamless format change separately
890 formatChange = !seamlessFormatChange;
891 }
892
Chong Zhang66704af2015-03-03 19:32:35 -0800893 // For format or time change, return EOS to queue EOS input,
894 // then wait for EOS on output.
Chong Zhang7137ec72014-11-12 16:41:05 -0800895 if (formatChange /* not seamless */) {
Chong Zhang7137ec72014-11-12 16:41:05 -0800896 mFormatChangePending = true;
Chong Zhang66704af2015-03-03 19:32:35 -0800897 err = ERROR_END_OF_STREAM;
Chong Zhang7137ec72014-11-12 16:41:05 -0800898 } else if (timeChange) {
Chong Zhang7137ec72014-11-12 16:41:05 -0800899 rememberCodecSpecificData(newFormat);
Chong Zhang66704af2015-03-03 19:32:35 -0800900 mTimeChangePending = true;
901 err = ERROR_END_OF_STREAM;
Chong Zhang7137ec72014-11-12 16:41:05 -0800902 } else if (seamlessFormatChange) {
903 // reuse existing decoder and don't flush
904 rememberCodecSpecificData(newFormat);
Chong Zhang66704af2015-03-03 19:32:35 -0800905 continue;
Chong Zhang7137ec72014-11-12 16:41:05 -0800906 } else {
907 // This stream is unaffected by the discontinuity
908 return -EWOULDBLOCK;
909 }
910 }
911
Chong Zhang66704af2015-03-03 19:32:35 -0800912 // reply should only be returned without a buffer set
913 // when there is an error (including EOS)
914 CHECK(err != OK);
915
Chong Zhang7137ec72014-11-12 16:41:05 -0800916 reply->setInt32("err", err);
Chong Zhang66704af2015-03-03 19:32:35 -0800917 return ERROR_END_OF_STREAM;
Chong Zhang7137ec72014-11-12 16:41:05 -0800918 }
919
Chong Zhang7137ec72014-11-12 16:41:05 -0800920 dropAccessUnit = false;
Hassan Shojania62dec952017-05-18 10:45:27 -0700921 if (!mIsAudio && !mIsEncrypted) {
922 // Extra safeguard if higher-level behavior changes. Otherwise, not required now.
923 // Preventing the buffer from being processed (and sent to codec) if this is a later
924 // round of playback but this time without prepareDrm. Or if there is a race between
925 // stop (which is not blocking) and releaseDrm allowing buffers being processed after
926 // Crypto has been released (GenericSource currently prevents this race though).
927 // Particularly doing this check before IsAVCReferenceFrame call to prevent parsing
928 // of encrypted data.
929 if (mIsEncryptedObservedEarlier) {
930 ALOGE("fetchInputData: mismatched mIsEncrypted/mIsEncryptedObservedEarlier (0/1)");
931
932 return INVALID_OPERATION;
933 }
934
Praveen Chavanbbaa1442016-04-08 13:33:49 -0700935 int32_t layerId = 0;
Lajos Molnar9fb81522016-07-14 07:33:43 -0700936 bool haveLayerId = accessUnit->meta()->findInt32("temporal-layer-id", &layerId);
Praveen Chavanbbaa1442016-04-08 13:33:49 -0700937 if (mRenderer->getVideoLateByUs() > 100000ll
938 && mIsVideoAVC
939 && !IsAVCReferenceFrame(accessUnit)) {
940 dropAccessUnit = true;
Lajos Molnar9fb81522016-07-14 07:33:43 -0700941 } else if (haveLayerId && mNumVideoTemporalLayerTotal > 1) {
Praveen Chavanbbaa1442016-04-08 13:33:49 -0700942 // Add only one layer each time.
943 if (layerId > mCurrentMaxVideoTemporalLayerId + 1
944 || layerId >= mNumVideoTemporalLayerAllowed) {
945 dropAccessUnit = true;
946 ALOGV("dropping layer(%d), speed=%g, allowed layer count=%d, max layerId=%d",
947 layerId, mPlaybackSpeed, mNumVideoTemporalLayerAllowed,
948 mCurrentMaxVideoTemporalLayerId);
949 } else if (layerId > mCurrentMaxVideoTemporalLayerId) {
950 mCurrentMaxVideoTemporalLayerId = layerId;
Dongwon Kangd91dc5a2017-10-10 00:07:09 -0700951 } else if (layerId == 0 && mNumVideoTemporalLayerTotal > 1
952 && IsIDR(accessUnit->data(), accessUnit->size())) {
Lajos Molnar9fb81522016-07-14 07:33:43 -0700953 mCurrentMaxVideoTemporalLayerId = mNumVideoTemporalLayerTotal - 1;
Praveen Chavanbbaa1442016-04-08 13:33:49 -0700954 }
955 }
956 if (dropAccessUnit) {
Lajos Molnar9fb81522016-07-14 07:33:43 -0700957 if (layerId <= mCurrentMaxVideoTemporalLayerId && layerId > 0) {
958 mCurrentMaxVideoTemporalLayerId = layerId - 1;
959 }
Praveen Chavanbbaa1442016-04-08 13:33:49 -0700960 ++mNumInputFramesDropped;
961 }
Chong Zhang7137ec72014-11-12 16:41:05 -0800962 }
963 } while (dropAccessUnit);
964
965 // ALOGV("returned a valid buffer of %s data", mIsAudio ? "mIsAudio" : "video");
966#if 0
967 int64_t mediaTimeUs;
968 CHECK(accessUnit->meta()->findInt64("timeUs", &mediaTimeUs));
Chong Zhang5abbd3d2015-04-20 16:03:00 -0700969 ALOGV("[%s] feeding input buffer at media time %.3f",
Chong Zhang7137ec72014-11-12 16:41:05 -0800970 mIsAudio ? "audio" : "video",
971 mediaTimeUs / 1E6);
972#endif
973
974 if (mCCDecoder != NULL) {
975 mCCDecoder->decode(accessUnit);
976 }
977
978 reply->setBuffer("buffer", accessUnit);
979
980 return OK;
981}
982
983bool NuPlayer::Decoder::onInputBufferFetched(const sp<AMessage> &msg) {
Wei Jiafcd87872017-07-28 15:50:04 -0700984 if (mCodec == NULL) {
985 ALOGE("[%s] onInputBufferFetched without a valid codec", mComponentName.c_str());
986 handleError(NO_INIT);
987 return false;
988 }
989
Lajos Molnar1cd13982014-01-17 15:12:51 -0800990 size_t bufferIx;
991 CHECK(msg->findSize("buffer-ix", &bufferIx));
992 CHECK_LT(bufferIx, mInputBuffers.size());
Wonsik Kim7e34bf52016-08-23 00:09:18 +0900993 sp<MediaCodecBuffer> codecBuffer = mInputBuffers[bufferIx];
Lajos Molnar1cd13982014-01-17 15:12:51 -0800994
995 sp<ABuffer> buffer;
996 bool hasBuffer = msg->findBuffer("buffer", &buffer);
Wonsik Kim7e34bf52016-08-23 00:09:18 +0900997 bool needsCopy = true;
Lajos Molnar09524832014-07-17 14:29:51 -0700998
Lajos Molnar1cd13982014-01-17 15:12:51 -0800999 if (buffer == NULL /* includes !hasBuffer */) {
1000 int32_t streamErr = ERROR_END_OF_STREAM;
1001 CHECK(msg->findInt32("err", &streamErr) || !hasBuffer);
1002
Chong Zhang66704af2015-03-03 19:32:35 -08001003 CHECK(streamErr != OK);
Lajos Molnar1cd13982014-01-17 15:12:51 -08001004
1005 // attempt to queue EOS
1006 status_t err = mCodec->queueInputBuffer(
1007 bufferIx,
1008 0,
1009 0,
1010 0,
1011 MediaCodec::BUFFER_FLAG_EOS);
Andy Hungcf31f1e2014-09-23 14:59:01 -07001012 if (err == OK) {
1013 mInputBufferIsDequeued.editItemAt(bufferIx) = false;
1014 } else if (streamErr == ERROR_END_OF_STREAM) {
Lajos Molnar1cd13982014-01-17 15:12:51 -08001015 streamErr = err;
1016 // err will not be ERROR_END_OF_STREAM
1017 }
1018
1019 if (streamErr != ERROR_END_OF_STREAM) {
Wei Jiafcd87872017-07-28 15:50:04 -07001020 ALOGE("Stream error for [%s] (err=%d), EOS %s queued",
Andy Hungcf31f1e2014-09-23 14:59:01 -07001021 mComponentName.c_str(),
1022 streamErr,
1023 err == OK ? "successfully" : "unsuccessfully");
Lajos Molnar1cd13982014-01-17 15:12:51 -08001024 handleError(streamErr);
1025 }
1026 } else {
Wei Jiac6cfd702014-11-11 16:33:20 -08001027 sp<AMessage> extra;
1028 if (buffer->meta()->findMessage("extra", &extra) && extra != NULL) {
1029 int64_t resumeAtMediaTimeUs;
1030 if (extra->findInt64(
1031 "resume-at-mediaTimeUs", &resumeAtMediaTimeUs)) {
1032 ALOGI("[%s] suppressing rendering until %lld us",
1033 mComponentName.c_str(), (long long)resumeAtMediaTimeUs);
1034 mSkipRenderingUntilMediaTimeUs = resumeAtMediaTimeUs;
1035 }
1036 }
1037
Lajos Molnar1cd13982014-01-17 15:12:51 -08001038 int64_t timeUs = 0;
1039 uint32_t flags = 0;
1040 CHECK(buffer->meta()->findInt64("timeUs", &timeUs));
1041
Lajos Molnar87603c02014-08-20 19:25:30 -07001042 int32_t eos, csd;
1043 // we do not expect SYNCFRAME for decoder
Lajos Molnar1cd13982014-01-17 15:12:51 -08001044 if (buffer->meta()->findInt32("eos", &eos) && eos) {
1045 flags |= MediaCodec::BUFFER_FLAG_EOS;
Lajos Molnar87603c02014-08-20 19:25:30 -07001046 } else if (buffer->meta()->findInt32("csd", &csd) && csd) {
1047 flags |= MediaCodec::BUFFER_FLAG_CODECCONFIG;
Lajos Molnar1cd13982014-01-17 15:12:51 -08001048 }
1049
Hassan Shojaniacefac142017-02-06 21:02:02 -08001050 // Modular DRM
Dongwon Kang1889c3e2018-02-01 13:44:57 -08001051 MediaBufferBase *mediaBuf = NULL;
Hassan Shojaniacefac142017-02-06 21:02:02 -08001052 NuPlayerDrm::CryptoInfo *cryptInfo = NULL;
1053
Lajos Molnar1cd13982014-01-17 15:12:51 -08001054 // copy into codec buffer
Wonsik Kim7e34bf52016-08-23 00:09:18 +09001055 if (needsCopy) {
Wei Jia56097a82016-01-07 16:03:03 -08001056 if (buffer->size() > codecBuffer->capacity()) {
1057 handleError(ERROR_BUFFER_TOO_SMALL);
1058 mDequeuedInputBuffers.push_back(bufferIx);
1059 return false;
1060 }
Lajos Molnar1cd13982014-01-17 15:12:51 -08001061
Hassan Shojaniacefac142017-02-06 21:02:02 -08001062 if (buffer->data() != NULL) {
1063 codecBuffer->setRange(0, buffer->size());
1064 memcpy(codecBuffer->data(), buffer->data(), buffer->size());
1065 } else { // No buffer->data()
1066 //Modular DRM
Dongwon Kangbc8f53b2018-01-25 17:01:44 -08001067 sp<RefBase> holder;
1068 if (buffer->meta()->findObject("mediaBufferHolder", &holder)) {
1069 mediaBuf = (holder != nullptr) ?
1070 static_cast<MediaBufferHolder*>(holder.get())->mediaBuffer() : nullptr;
1071 }
Hassan Shojaniacefac142017-02-06 21:02:02 -08001072 if (mediaBuf != NULL) {
Wei Jia9b5a7ad2018-07-27 17:33:24 -07001073 if (mediaBuf->size() > codecBuffer->capacity()) {
1074 handleError(ERROR_BUFFER_TOO_SMALL);
1075 mDequeuedInputBuffers.push_back(bufferIx);
1076 return false;
1077 }
1078
Hassan Shojaniacefac142017-02-06 21:02:02 -08001079 codecBuffer->setRange(0, mediaBuf->size());
1080 memcpy(codecBuffer->data(), mediaBuf->data(), mediaBuf->size());
1081
Marco Nelissen3d21ae32018-02-16 08:24:08 -08001082 MetaDataBase &meta_data = mediaBuf->meta_data();
Hassan Shojaniacefac142017-02-06 21:02:02 -08001083 cryptInfo = NuPlayerDrm::getSampleCryptoInfo(meta_data);
Hassan Shojaniacefac142017-02-06 21:02:02 -08001084 } else { // No mediaBuf
1085 ALOGE("onInputBufferFetched: buffer->data()/mediaBuf are NULL for %p",
1086 buffer.get());
1087 handleError(UNKNOWN_ERROR);
1088 return false;
1089 }
1090 } // buffer->data()
1091 } // needsCopy
1092
1093 status_t err;
1094 AString errorDetailMsg;
1095 if (cryptInfo != NULL) {
1096 err = mCodec->queueSecureInputBuffer(
1097 bufferIx,
1098 codecBuffer->offset(),
1099 cryptInfo->subSamples,
1100 cryptInfo->numSubSamples,
1101 cryptInfo->key,
1102 cryptInfo->iv,
1103 cryptInfo->mode,
1104 cryptInfo->pattern,
1105 timeUs,
1106 flags,
1107 &errorDetailMsg);
1108 // synchronous call so done with cryptInfo here
1109 free(cryptInfo);
1110 } else {
1111 err = mCodec->queueInputBuffer(
1112 bufferIx,
1113 codecBuffer->offset(),
1114 codecBuffer->size(),
1115 timeUs,
1116 flags,
1117 &errorDetailMsg);
1118 } // no cryptInfo
1119
Lajos Molnar1cd13982014-01-17 15:12:51 -08001120 if (err != OK) {
Wei Jiafcd87872017-07-28 15:50:04 -07001121 ALOGE("onInputBufferFetched: queue%sInputBuffer failed for [%s] (err=%d, %s)",
Hassan Shojaniacefac142017-02-06 21:02:02 -08001122 (cryptInfo != NULL ? "Secure" : ""),
1123 mComponentName.c_str(), err, errorDetailMsg.c_str());
Lajos Molnar1cd13982014-01-17 15:12:51 -08001124 handleError(err);
Andy Hungcf31f1e2014-09-23 14:59:01 -07001125 } else {
1126 mInputBufferIsDequeued.editItemAt(bufferIx) = false;
Lajos Molnar09524832014-07-17 14:29:51 -07001127 }
Hassan Shojaniacefac142017-02-06 21:02:02 -08001128
1129 } // buffer != NULL
Wei Jia2245fc62014-10-02 15:12:25 -07001130 return true;
Lajos Molnar1cd13982014-01-17 15:12:51 -08001131}
1132
Lajos Molnar1cd13982014-01-17 15:12:51 -08001133void NuPlayer::Decoder::onRenderBuffer(const sp<AMessage> &msg) {
1134 status_t err;
1135 int32_t render;
1136 size_t bufferIx;
Chong Zhang66704af2015-03-03 19:32:35 -08001137 int32_t eos;
Praveen Chavanbc5fe9a2018-04-27 16:18:11 -07001138 size_t size;
Lajos Molnar1cd13982014-01-17 15:12:51 -08001139 CHECK(msg->findSize("buffer-ix", &bufferIx));
Wei Jiac6cfd702014-11-11 16:33:20 -08001140
Chong Zhang7137ec72014-11-12 16:41:05 -08001141 if (!mIsAudio) {
Wei Jiac6cfd702014-11-11 16:33:20 -08001142 int64_t timeUs;
Wonsik Kim7e34bf52016-08-23 00:09:18 +09001143 sp<MediaCodecBuffer> buffer = mOutputBuffers[bufferIx];
Wei Jiac6cfd702014-11-11 16:33:20 -08001144 buffer->meta()->findInt64("timeUs", &timeUs);
Chong Zhang7137ec72014-11-12 16:41:05 -08001145
1146 if (mCCDecoder != NULL && mCCDecoder->isSelected()) {
1147 mCCDecoder->display(timeUs);
1148 }
Wei Jiac6cfd702014-11-11 16:33:20 -08001149 }
1150
Wei Jiafcd87872017-07-28 15:50:04 -07001151 if (mCodec == NULL) {
1152 err = NO_INIT;
1153 } else if (msg->findInt32("render", &render) && render) {
Lajos Molnardc43dfa2014-05-07 15:33:04 -07001154 int64_t timestampNs;
1155 CHECK(msg->findInt64("timestampNs", &timestampNs));
1156 err = mCodec->renderOutputBufferAndRelease(bufferIx, timestampNs);
Lajos Molnar1cd13982014-01-17 15:12:51 -08001157 } else {
Praveen Chavanbc5fe9a2018-04-27 16:18:11 -07001158 if (!msg->findInt32("eos", &eos) || !eos ||
1159 !msg->findSize("size", &size) || size) {
1160 mNumOutputFramesDropped += !mIsAudio;
1161 }
Lajos Molnar1cd13982014-01-17 15:12:51 -08001162 err = mCodec->releaseOutputBuffer(bufferIx);
1163 }
1164 if (err != OK) {
Wei Jiafcd87872017-07-28 15:50:04 -07001165 ALOGE("failed to release output buffer for [%s] (err=%d)",
Lajos Molnar1cd13982014-01-17 15:12:51 -08001166 mComponentName.c_str(), err);
1167 handleError(err);
1168 }
Chong Zhang66704af2015-03-03 19:32:35 -08001169 if (msg->findInt32("eos", &eos) && eos
1170 && isDiscontinuityPending()) {
1171 finishHandleDiscontinuity(true /* flushOnTimeChange */);
1172 }
1173}
1174
1175bool NuPlayer::Decoder::isDiscontinuityPending() const {
1176 return mFormatChangePending || mTimeChangePending;
1177}
1178
1179void NuPlayer::Decoder::finishHandleDiscontinuity(bool flushOnTimeChange) {
1180 ALOGV("finishHandleDiscontinuity: format %d, time %d, flush %d",
1181 mFormatChangePending, mTimeChangePending, flushOnTimeChange);
1182
1183 // If we have format change, pause and wait to be killed;
1184 // If we have time change only, flush and restart fetching.
1185
1186 if (mFormatChangePending) {
1187 mPaused = true;
1188 } else if (mTimeChangePending) {
1189 if (flushOnTimeChange) {
Marco Nelissen421f47c2015-03-25 14:40:32 -07001190 doFlush(false /* notifyComplete */);
1191 signalResume(false /* notifyComplete */);
Chong Zhang66704af2015-03-03 19:32:35 -08001192 }
Chong Zhang66704af2015-03-03 19:32:35 -08001193 }
1194
1195 // Notify NuPlayer to either shutdown decoder, or rescan sources
1196 sp<AMessage> msg = mNotify->dup();
1197 msg->setInt32("what", kWhatInputDiscontinuity);
1198 msg->setInt32("formatChange", mFormatChangePending);
1199 msg->post();
1200
1201 mFormatChangePending = false;
1202 mTimeChangePending = false;
Lajos Molnar1cd13982014-01-17 15:12:51 -08001203}
1204
Chong Zhang7137ec72014-11-12 16:41:05 -08001205bool NuPlayer::Decoder::supportsSeamlessAudioFormatChange(
1206 const sp<AMessage> &targetFormat) const {
Robert Shih6d0a94e2014-01-23 16:18:22 -08001207 if (targetFormat == NULL) {
1208 return true;
1209 }
1210
1211 AString mime;
1212 if (!targetFormat->findString("mime", &mime)) {
1213 return false;
1214 }
1215
1216 if (!strcasecmp(mime.c_str(), MEDIA_MIMETYPE_AUDIO_AAC)) {
1217 // field-by-field comparison
1218 const char * keys[] = { "channel-count", "sample-rate", "is-adts" };
1219 for (unsigned int i = 0; i < sizeof(keys) / sizeof(keys[0]); i++) {
1220 int32_t oldVal, newVal;
joakim johansson7abbd4c2015-01-30 14:16:03 +01001221 if (!mInputFormat->findInt32(keys[i], &oldVal) ||
Lajos Molnar1cd13982014-01-17 15:12:51 -08001222 !targetFormat->findInt32(keys[i], &newVal) ||
1223 oldVal != newVal) {
Robert Shih6d0a94e2014-01-23 16:18:22 -08001224 return false;
1225 }
1226 }
1227
1228 sp<ABuffer> oldBuf, newBuf;
joakim johansson7abbd4c2015-01-30 14:16:03 +01001229 if (mInputFormat->findBuffer("csd-0", &oldBuf) &&
Lajos Molnar1cd13982014-01-17 15:12:51 -08001230 targetFormat->findBuffer("csd-0", &newBuf)) {
Robert Shih6d0a94e2014-01-23 16:18:22 -08001231 if (oldBuf->size() != newBuf->size()) {
1232 return false;
1233 }
1234 return !memcmp(oldBuf->data(), newBuf->data(), oldBuf->size());
1235 }
1236 }
1237 return false;
1238}
1239
1240bool NuPlayer::Decoder::supportsSeamlessFormatChange(const sp<AMessage> &targetFormat) const {
joakim johansson7abbd4c2015-01-30 14:16:03 +01001241 if (mInputFormat == NULL) {
Robert Shih6d0a94e2014-01-23 16:18:22 -08001242 return false;
1243 }
1244
1245 if (targetFormat == NULL) {
1246 return true;
1247 }
1248
1249 AString oldMime, newMime;
joakim johansson7abbd4c2015-01-30 14:16:03 +01001250 if (!mInputFormat->findString("mime", &oldMime)
Robert Shih6d0a94e2014-01-23 16:18:22 -08001251 || !targetFormat->findString("mime", &newMime)
1252 || !(oldMime == newMime)) {
1253 return false;
1254 }
1255
1256 bool audio = !strncasecmp(oldMime.c_str(), "audio/", strlen("audio/"));
1257 bool seamless;
1258 if (audio) {
1259 seamless = supportsSeamlessAudioFormatChange(targetFormat);
1260 } else {
Lajos Molnar1cd13982014-01-17 15:12:51 -08001261 int32_t isAdaptive;
1262 seamless = (mCodec != NULL &&
1263 mInputFormat->findInt32("adaptive-playback", &isAdaptive) &&
1264 isAdaptive);
Robert Shih6d0a94e2014-01-23 16:18:22 -08001265 }
1266
1267 ALOGV("%s seamless support for %s", seamless ? "yes" : "no", oldMime.c_str());
1268 return seamless;
1269}
1270
Chong Zhang7137ec72014-11-12 16:41:05 -08001271void NuPlayer::Decoder::rememberCodecSpecificData(const sp<AMessage> &format) {
1272 if (format == NULL) {
Chong Zhangb86e68f2014-08-01 13:46:53 -07001273 return;
1274 }
Chong Zhang7137ec72014-11-12 16:41:05 -08001275 mCSDsForCurrentFormat.clear();
1276 for (int32_t i = 0; ; ++i) {
1277 AString tag = "csd-";
1278 tag.append(i);
1279 sp<ABuffer> buffer;
1280 if (!format->findBuffer(tag.c_str(), &buffer)) {
1281 break;
1282 }
1283 mCSDsForCurrentFormat.push(buffer);
Chong Zhanga7fa1d92014-06-11 14:49:23 -07001284 }
Chong Zhangb86e68f2014-08-01 13:46:53 -07001285}
1286
Chong Zhangf8d71772014-11-26 15:08:34 -08001287void NuPlayer::Decoder::notifyResumeCompleteIfNecessary() {
1288 if (mResumePending) {
1289 mResumePending = false;
1290
1291 sp<AMessage> notify = mNotify->dup();
1292 notify->setInt32("what", kWhatResumeCompleted);
1293 notify->post();
1294 }
1295}
1296
Andreas Huberf9334412010-12-15 15:17:42 -08001297} // namespace android
1298