blob: 376c93a8134aa31601ceb4ca6c73a616acc6baec [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
Chong Zhang7137ec72014-11-12 16:41:05 -080022#include "NuPlayerCCDecoder.h"
Andreas Huberf9334412010-12-15 15:17:42 -080023#include "NuPlayerDecoder.h"
Wei Jiac6cfd702014-11-11 16:33:20 -080024#include "NuPlayerRenderer.h"
25#include "NuPlayerSource.h"
26
Lajos Molnar1cd13982014-01-17 15:12:51 -080027#include <media/ICrypto.h>
Andreas Huberf9334412010-12-15 15:17:42 -080028#include <media/stagefright/foundation/ABuffer.h>
29#include <media/stagefright/foundation/ADebug.h>
Andreas Huber5bc087c2010-12-23 10:27:40 -080030#include <media/stagefright/foundation/AMessage.h>
Lajos Molnar09524832014-07-17 14:29:51 -070031#include <media/stagefright/MediaBuffer.h>
Lajos Molnar1cd13982014-01-17 15:12:51 -080032#include <media/stagefright/MediaCodec.h>
Andreas Huberf9334412010-12-15 15:17:42 -080033#include <media/stagefright/MediaDefs.h>
Lajos Molnar1cd13982014-01-17 15:12:51 -080034#include <media/stagefright/MediaErrors.h>
Andreas Huberf9334412010-12-15 15:17:42 -080035
Lajos Molnar1de1e252015-04-30 18:18:34 -070036#include <gui/Surface.h>
37
Chong Zhang7137ec72014-11-12 16:41:05 -080038#include "avc_utils.h"
39#include "ATSParser.h"
40
Andreas Huberf9334412010-12-15 15:17:42 -080041namespace android {
42
43NuPlayer::Decoder::Decoder(
Glenn Kasten11731182011-02-08 17:26:17 -080044 const sp<AMessage> &notify,
Wei Jiac6cfd702014-11-11 16:33:20 -080045 const sp<Source> &source,
46 const sp<Renderer> &renderer,
Lajos Molnar1de1e252015-04-30 18:18:34 -070047 const sp<Surface> &surface,
Chong Zhang7137ec72014-11-12 16:41:05 -080048 const sp<CCDecoder> &ccDecoder)
Andy Hung202bce12014-12-03 11:47:36 -080049 : DecoderBase(notify),
Lajos Molnar1de1e252015-04-30 18:18:34 -070050 mSurface(surface),
Wei Jiac6cfd702014-11-11 16:33:20 -080051 mSource(source),
52 mRenderer(renderer),
Chong Zhang7137ec72014-11-12 16:41:05 -080053 mCCDecoder(ccDecoder),
Wei Jiac6cfd702014-11-11 16:33:20 -080054 mSkipRenderingUntilMediaTimeUs(-1ll),
Chong Zhang7137ec72014-11-12 16:41:05 -080055 mNumFramesTotal(0ll),
56 mNumFramesDropped(0ll),
57 mIsAudio(true),
58 mIsVideoAVC(false),
59 mIsSecure(false),
60 mFormatChangePending(false),
Chong Zhang66704af2015-03-03 19:32:35 -080061 mTimeChangePending(false),
Wei Jia704e7262014-06-04 16:21:56 -070062 mPaused(true),
Chong Zhangf8d71772014-11-26 15:08:34 -080063 mResumePending(false),
Lajos Molnar1cd13982014-01-17 15:12:51 -080064 mComponentName("decoder") {
Lajos Molnar1cd13982014-01-17 15:12:51 -080065 mCodecLooper = new ALooper;
Marco Nelissen9e2b7912014-08-18 16:13:03 -070066 mCodecLooper->setName("NPDecoder-CL");
Lajos Molnar1cd13982014-01-17 15:12:51 -080067 mCodecLooper->start(false, false, ANDROID_PRIORITY_AUDIO);
Andreas Huberf9334412010-12-15 15:17:42 -080068}
69
70NuPlayer::Decoder::~Decoder() {
Wei Jia4923cee2014-09-24 14:25:19 -070071 releaseAndResetMediaBuffers();
Andreas Huberf9334412010-12-15 15:17:42 -080072}
73
Chong Zhang7137ec72014-11-12 16:41:05 -080074void NuPlayer::Decoder::getStats(
75 int64_t *numFramesTotal,
76 int64_t *numFramesDropped) const {
77 *numFramesTotal = mNumFramesTotal;
78 *numFramesDropped = mNumFramesDropped;
Lajos Molnar09524832014-07-17 14:29:51 -070079}
80
Chong Zhang7137ec72014-11-12 16:41:05 -080081void NuPlayer::Decoder::onMessageReceived(const sp<AMessage> &msg) {
82 ALOGV("[%s] onMessage: %s", mComponentName.c_str(), msg->debugString().c_str());
83
84 switch (msg->what()) {
85 case kWhatCodecNotify:
86 {
Chong Zhang3b032b32015-04-17 15:49:06 -070087 int32_t cbID;
88 CHECK(msg->findInt32("callbackID", &cbID));
89
90 ALOGV("[%s] kWhatCodecNotify: cbID = %d, paused = %d",
91 mIsAudio ? "audio" : "video", cbID, mPaused);
92
Marco Nelissen421f47c2015-03-25 14:40:32 -070093 if (mPaused) {
94 break;
Chong Zhang7137ec72014-11-12 16:41:05 -080095 }
96
Marco Nelissen421f47c2015-03-25 14:40:32 -070097 switch (cbID) {
98 case MediaCodec::CB_INPUT_AVAILABLE:
99 {
100 int32_t index;
101 CHECK(msg->findInt32("index", &index));
102
103 handleAnInputBuffer(index);
104 break;
105 }
106
107 case MediaCodec::CB_OUTPUT_AVAILABLE:
108 {
109 int32_t index;
110 size_t offset;
111 size_t size;
112 int64_t timeUs;
113 int32_t flags;
114
115 CHECK(msg->findInt32("index", &index));
116 CHECK(msg->findSize("offset", &offset));
117 CHECK(msg->findSize("size", &size));
118 CHECK(msg->findInt64("timeUs", &timeUs));
119 CHECK(msg->findInt32("flags", &flags));
120
121 handleAnOutputBuffer(index, offset, size, timeUs, flags);
122 break;
123 }
124
125 case MediaCodec::CB_OUTPUT_FORMAT_CHANGED:
126 {
127 sp<AMessage> format;
128 CHECK(msg->findMessage("format", &format));
129
130 handleOutputFormatChange(format);
131 break;
132 }
133
134 case MediaCodec::CB_ERROR:
135 {
136 status_t err;
137 CHECK(msg->findInt32("err", &err));
138 ALOGE("Decoder (%s) reported error : 0x%x",
139 mIsAudio ? "audio" : "video", err);
140
141 handleError(err);
142 break;
143 }
144
145 default:
146 {
147 TRESPASS();
148 break;
149 }
150 }
151
Lajos Molnar87603c02014-08-20 19:25:30 -0700152 break;
153 }
Chong Zhang7137ec72014-11-12 16:41:05 -0800154
155 case kWhatRenderBuffer:
156 {
157 if (!isStaleReply(msg)) {
158 onRenderBuffer(msg);
159 }
160 break;
161 }
162
163 default:
164 DecoderBase::onMessageReceived(msg);
165 break;
Lajos Molnar87603c02014-08-20 19:25:30 -0700166 }
167}
168
Lajos Molnar1cd13982014-01-17 15:12:51 -0800169void NuPlayer::Decoder::onConfigure(const sp<AMessage> &format) {
Andreas Huberf9334412010-12-15 15:17:42 -0800170 CHECK(mCodec == NULL);
Andreas Huberf9334412010-12-15 15:17:42 -0800171
Chong Zhang7137ec72014-11-12 16:41:05 -0800172 mFormatChangePending = false;
Chong Zhang66704af2015-03-03 19:32:35 -0800173 mTimeChangePending = false;
Chong Zhang7137ec72014-11-12 16:41:05 -0800174
Lajos Molnar1cd13982014-01-17 15:12:51 -0800175 ++mBufferGeneration;
176
Andreas Huber84066782011-08-16 09:34:26 -0700177 AString mime;
178 CHECK(format->findString("mime", &mime));
Andreas Huberf9334412010-12-15 15:17:42 -0800179
Chong Zhang7137ec72014-11-12 16:41:05 -0800180 mIsAudio = !strncasecmp("audio/", mime.c_str(), 6);
181 mIsVideoAVC = !strcasecmp(MEDIA_MIMETYPE_VIDEO_AVC, mime.c_str());
182
Lajos Molnar1cd13982014-01-17 15:12:51 -0800183 mComponentName = mime;
184 mComponentName.append(" decoder");
Lajos Molnar1de1e252015-04-30 18:18:34 -0700185 ALOGV("[%s] onConfigure (surface=%p)", mComponentName.c_str(), mSurface.get());
Lajos Molnar1cd13982014-01-17 15:12:51 -0800186
187 mCodec = MediaCodec::CreateByType(mCodecLooper, mime.c_str(), false /* encoder */);
Lajos Molnar09524832014-07-17 14:29:51 -0700188 int32_t secure = 0;
189 if (format->findInt32("secure", &secure) && secure != 0) {
190 if (mCodec != NULL) {
191 mCodec->getName(&mComponentName);
192 mComponentName.append(".secure");
193 mCodec->release();
194 ALOGI("[%s] creating", mComponentName.c_str());
195 mCodec = MediaCodec::CreateByComponentName(
196 mCodecLooper, mComponentName.c_str());
197 }
198 }
Lajos Molnar1cd13982014-01-17 15:12:51 -0800199 if (mCodec == NULL) {
Lajos Molnar09524832014-07-17 14:29:51 -0700200 ALOGE("Failed to create %s%s decoder",
201 (secure ? "secure " : ""), mime.c_str());
Lajos Molnar1cd13982014-01-17 15:12:51 -0800202 handleError(UNKNOWN_ERROR);
203 return;
204 }
Chong Zhang7137ec72014-11-12 16:41:05 -0800205 mIsSecure = secure;
Lajos Molnar1cd13982014-01-17 15:12:51 -0800206
207 mCodec->getName(&mComponentName);
208
Lajos Molnar14986f62014-09-15 11:04:44 -0700209 status_t err;
Lajos Molnar1de1e252015-04-30 18:18:34 -0700210 if (mSurface != NULL) {
Lajos Molnar1cd13982014-01-17 15:12:51 -0800211 // disconnect from surface as MediaCodec will reconnect
Lajos Molnar14986f62014-09-15 11:04:44 -0700212 err = native_window_api_disconnect(
Lajos Molnar1de1e252015-04-30 18:18:34 -0700213 mSurface.get(), NATIVE_WINDOW_API_MEDIA);
Lajos Molnar14986f62014-09-15 11:04:44 -0700214 // We treat this as a warning, as this is a preparatory step.
215 // Codec will try to connect to the surface, which is where
216 // any error signaling will occur.
217 ALOGW_IF(err != OK, "failed to disconnect from surface: %d", err);
Lajos Molnar1cd13982014-01-17 15:12:51 -0800218 }
Lajos Molnar14986f62014-09-15 11:04:44 -0700219 err = mCodec->configure(
Lajos Molnar1de1e252015-04-30 18:18:34 -0700220 format, mSurface, NULL /* crypto */, 0 /* flags */);
Lajos Molnar1cd13982014-01-17 15:12:51 -0800221 if (err != OK) {
222 ALOGE("Failed to configure %s decoder (err=%d)", mComponentName.c_str(), err);
Andy Hung2abde2c2014-09-30 14:40:32 -0700223 mCodec->release();
224 mCodec.clear();
Lajos Molnar1cd13982014-01-17 15:12:51 -0800225 handleError(err);
226 return;
227 }
Lajos Molnar87603c02014-08-20 19:25:30 -0700228 rememberCodecSpecificData(format);
229
Lajos Molnar1cd13982014-01-17 15:12:51 -0800230 // the following should work in configured state
231 CHECK_EQ((status_t)OK, mCodec->getOutputFormat(&mOutputFormat));
232 CHECK_EQ((status_t)OK, mCodec->getInputFormat(&mInputFormat));
233
Marco Nelissen421f47c2015-03-25 14:40:32 -0700234 sp<AMessage> reply = new AMessage(kWhatCodecNotify, this);
235 mCodec->setCallback(reply);
236
Lajos Molnar1cd13982014-01-17 15:12:51 -0800237 err = mCodec->start();
238 if (err != OK) {
239 ALOGE("Failed to start %s decoder (err=%d)", mComponentName.c_str(), err);
Andy Hung2abde2c2014-09-30 14:40:32 -0700240 mCodec->release();
241 mCodec.clear();
Lajos Molnar1cd13982014-01-17 15:12:51 -0800242 handleError(err);
243 return;
Andreas Huberf9334412010-12-15 15:17:42 -0800244 }
245
Lajos Molnar09524832014-07-17 14:29:51 -0700246 releaseAndResetMediaBuffers();
Marco Nelissen421f47c2015-03-25 14:40:32 -0700247
Wei Jia704e7262014-06-04 16:21:56 -0700248 mPaused = false;
Chong Zhangf8d71772014-11-26 15:08:34 -0800249 mResumePending = false;
Lajos Molnar1cd13982014-01-17 15:12:51 -0800250}
Andreas Huber078cfcf2011-09-15 12:25:04 -0700251
Ronghua Wu8db88132015-04-22 13:51:35 -0700252void NuPlayer::Decoder::onSetParameters(const sp<AMessage> &params) {
253 if (mCodec == NULL) {
254 ALOGW("onSetParameters called before codec is created.");
255 return;
256 }
257 mCodec->setParameters(params);
258}
259
Chong Zhang7137ec72014-11-12 16:41:05 -0800260void NuPlayer::Decoder::onSetRenderer(const sp<Renderer> &renderer) {
261 bool hadNoRenderer = (mRenderer == NULL);
262 mRenderer = renderer;
263 if (hadNoRenderer && mRenderer != NULL) {
Lajos Molnare6109e22015-04-10 17:18:22 -0700264 // this means that the widevine legacy source is ready
265 onRequestInputBuffers();
Chong Zhang7137ec72014-11-12 16:41:05 -0800266 }
267}
268
269void NuPlayer::Decoder::onGetInputBuffers(
270 Vector<sp<ABuffer> > *dstBuffers) {
Lajos Molnare6109e22015-04-10 17:18:22 -0700271 CHECK_EQ((status_t)OK, mCodec->getWidevineLegacyBuffers(dstBuffers));
Chong Zhang7137ec72014-11-12 16:41:05 -0800272}
273
Chong Zhangf8d71772014-11-26 15:08:34 -0800274void NuPlayer::Decoder::onResume(bool notifyComplete) {
Chong Zhang7137ec72014-11-12 16:41:05 -0800275 mPaused = false;
Chong Zhangf8d71772014-11-26 15:08:34 -0800276
277 if (notifyComplete) {
278 mResumePending = true;
279 }
Marco Nelissen421f47c2015-03-25 14:40:32 -0700280 mCodec->start();
Chong Zhang7137ec72014-11-12 16:41:05 -0800281}
282
Chong Zhang66704af2015-03-03 19:32:35 -0800283void NuPlayer::Decoder::doFlush(bool notifyComplete) {
Chong Zhang7137ec72014-11-12 16:41:05 -0800284 if (mCCDecoder != NULL) {
285 mCCDecoder->flush();
286 }
287
288 if (mRenderer != NULL) {
289 mRenderer->flush(mIsAudio, notifyComplete);
290 mRenderer->signalTimeDiscontinuity();
291 }
292
293 status_t err = OK;
294 if (mCodec != NULL) {
295 err = mCodec->flush();
296 mCSDsToSubmit = mCSDsForCurrentFormat; // copy operator
297 ++mBufferGeneration;
298 }
299
300 if (err != OK) {
301 ALOGE("failed to flush %s (err=%d)", mComponentName.c_str(), err);
302 handleError(err);
303 // finish with posting kWhatFlushCompleted.
304 // we attempt to release the buffers even if flush fails.
305 }
306 releaseAndResetMediaBuffers();
Marco Nelissen421f47c2015-03-25 14:40:32 -0700307 mPaused = true;
Chong Zhang66704af2015-03-03 19:32:35 -0800308}
Chong Zhang7137ec72014-11-12 16:41:05 -0800309
Marco Nelissen421f47c2015-03-25 14:40:32 -0700310
Chong Zhang66704af2015-03-03 19:32:35 -0800311void NuPlayer::Decoder::onFlush() {
312 doFlush(true);
313
314 if (isDiscontinuityPending()) {
315 // This could happen if the client starts seeking/shutdown
316 // after we queued an EOS for discontinuities.
317 // We can consider discontinuity handled.
318 finishHandleDiscontinuity(false /* flushOnTimeChange */);
Chong Zhang7137ec72014-11-12 16:41:05 -0800319 }
Chong Zhang66704af2015-03-03 19:32:35 -0800320
321 sp<AMessage> notify = mNotify->dup();
322 notify->setInt32("what", kWhatFlushCompleted);
323 notify->post();
Chong Zhang7137ec72014-11-12 16:41:05 -0800324}
325
326void NuPlayer::Decoder::onShutdown(bool notifyComplete) {
327 status_t err = OK;
Chong Zhangf8d71772014-11-26 15:08:34 -0800328
329 // if there is a pending resume request, notify complete now
330 notifyResumeCompleteIfNecessary();
331
Chong Zhang7137ec72014-11-12 16:41:05 -0800332 if (mCodec != NULL) {
333 err = mCodec->release();
334 mCodec = NULL;
335 ++mBufferGeneration;
336
Lajos Molnar1de1e252015-04-30 18:18:34 -0700337 if (mSurface != NULL) {
Chong Zhang7137ec72014-11-12 16:41:05 -0800338 // reconnect to surface as MediaCodec disconnected from it
339 status_t error =
Lajos Molnar1de1e252015-04-30 18:18:34 -0700340 native_window_api_connect(mSurface.get(), NATIVE_WINDOW_API_MEDIA);
Chong Zhang7137ec72014-11-12 16:41:05 -0800341 ALOGW_IF(error != NO_ERROR,
342 "[%s] failed to connect to native window, error=%d",
343 mComponentName.c_str(), error);
344 }
345 mComponentName = "decoder";
346 }
347
348 releaseAndResetMediaBuffers();
349
350 if (err != OK) {
351 ALOGE("failed to release %s (err=%d)", mComponentName.c_str(), err);
352 handleError(err);
353 // finish with posting kWhatShutdownCompleted.
354 }
355
356 if (notifyComplete) {
357 sp<AMessage> notify = mNotify->dup();
358 notify->setInt32("what", kWhatShutdownCompleted);
359 notify->post();
360 mPaused = true;
361 }
362}
363
Chong Zhang3b032b32015-04-17 15:49:06 -0700364/*
365 * returns true if we should request more data
366 */
367bool NuPlayer::Decoder::doRequestBuffers() {
Lajos Molnare6109e22015-04-10 17:18:22 -0700368 // mRenderer is only NULL if we have a legacy widevine source that
369 // is not yet ready. In this case we must not fetch input.
370 if (isDiscontinuityPending() || mRenderer == NULL) {
Chong Zhang3b032b32015-04-17 15:49:06 -0700371 return false;
Chong Zhang7137ec72014-11-12 16:41:05 -0800372 }
373 status_t err = OK;
Chong Zhang66704af2015-03-03 19:32:35 -0800374 while (err == OK && !mDequeuedInputBuffers.empty()) {
Chong Zhang7137ec72014-11-12 16:41:05 -0800375 size_t bufferIx = *mDequeuedInputBuffers.begin();
376 sp<AMessage> msg = new AMessage();
377 msg->setSize("buffer-ix", bufferIx);
378 err = fetchInputData(msg);
Chong Zhang66704af2015-03-03 19:32:35 -0800379 if (err != OK && err != ERROR_END_OF_STREAM) {
380 // if EOS, need to queue EOS buffer
Chong Zhang7137ec72014-11-12 16:41:05 -0800381 break;
382 }
383 mDequeuedInputBuffers.erase(mDequeuedInputBuffers.begin());
384
385 if (!mPendingInputMessages.empty()
386 || !onInputBufferFetched(msg)) {
387 mPendingInputMessages.push_back(msg);
Lajos Molnar09524832014-07-17 14:29:51 -0700388 }
389 }
Chong Zhang7137ec72014-11-12 16:41:05 -0800390
Chong Zhang3b032b32015-04-17 15:49:06 -0700391 return err == -EWOULDBLOCK
392 && mSource->feedMoreTSData() == OK;
Lajos Molnar09524832014-07-17 14:29:51 -0700393}
394
Marco Nelissen421f47c2015-03-25 14:40:32 -0700395void NuPlayer::Decoder::handleError(int32_t err)
396{
397 // We cannot immediately release the codec due to buffers still outstanding
398 // in the renderer. We signal to the player the error so it can shutdown/release the
399 // decoder after flushing and increment the generation to discard unnecessary messages.
400
401 ++mBufferGeneration;
402
403 sp<AMessage> notify = mNotify->dup();
404 notify->setInt32("what", kWhatError);
405 notify->setInt32("err", err);
406 notify->post();
407}
408
409bool NuPlayer::Decoder::handleAnInputBuffer(size_t index) {
Chong Zhang66704af2015-03-03 19:32:35 -0800410 if (isDiscontinuityPending()) {
Chong Zhang7137ec72014-11-12 16:41:05 -0800411 return false;
412 }
Marco Nelissen421f47c2015-03-25 14:40:32 -0700413
414 sp<ABuffer> buffer;
415 mCodec->getInputBuffer(index, &buffer);
416
417 if (index >= mInputBuffers.size()) {
418 for (size_t i = mInputBuffers.size(); i <= index; ++i) {
419 mInputBuffers.add();
420 mMediaBuffers.add();
421 mInputBufferIsDequeued.add();
422 mMediaBuffers.editItemAt(i) = NULL;
423 mInputBufferIsDequeued.editItemAt(i) = false;
Lajos Molnar1cd13982014-01-17 15:12:51 -0800424 }
Andreas Huber078cfcf2011-09-15 12:25:04 -0700425 }
Marco Nelissen421f47c2015-03-25 14:40:32 -0700426 mInputBuffers.editItemAt(index) = buffer;
Andreas Huber078cfcf2011-09-15 12:25:04 -0700427
Marco Nelissen421f47c2015-03-25 14:40:32 -0700428 //CHECK_LT(bufferIx, mInputBuffers.size());
Andreas Huberf9334412010-12-15 15:17:42 -0800429
Marco Nelissen421f47c2015-03-25 14:40:32 -0700430 if (mMediaBuffers[index] != NULL) {
431 mMediaBuffers[index]->release();
432 mMediaBuffers.editItemAt(index) = NULL;
Lajos Molnar09524832014-07-17 14:29:51 -0700433 }
Marco Nelissen421f47c2015-03-25 14:40:32 -0700434 mInputBufferIsDequeued.editItemAt(index) = true;
Lajos Molnar09524832014-07-17 14:29:51 -0700435
Lajos Molnar87603c02014-08-20 19:25:30 -0700436 if (!mCSDsToSubmit.isEmpty()) {
Chong Zhang7137ec72014-11-12 16:41:05 -0800437 sp<AMessage> msg = new AMessage();
Marco Nelissen421f47c2015-03-25 14:40:32 -0700438 msg->setSize("buffer-ix", index);
Chong Zhang7137ec72014-11-12 16:41:05 -0800439
Lajos Molnar87603c02014-08-20 19:25:30 -0700440 sp<ABuffer> buffer = mCSDsToSubmit.itemAt(0);
441 ALOGI("[%s] resubmitting CSD", mComponentName.c_str());
Chong Zhang7137ec72014-11-12 16:41:05 -0800442 msg->setBuffer("buffer", buffer);
Lajos Molnar87603c02014-08-20 19:25:30 -0700443 mCSDsToSubmit.removeAt(0);
Chong Zhang7137ec72014-11-12 16:41:05 -0800444 CHECK(onInputBufferFetched(msg));
Wei Jia2245fc62014-10-02 15:12:25 -0700445 return true;
446 }
447
448 while (!mPendingInputMessages.empty()) {
449 sp<AMessage> msg = *mPendingInputMessages.begin();
Chong Zhang7137ec72014-11-12 16:41:05 -0800450 if (!onInputBufferFetched(msg)) {
Wei Jia2245fc62014-10-02 15:12:25 -0700451 break;
452 }
453 mPendingInputMessages.erase(mPendingInputMessages.begin());
454 }
455
Marco Nelissen421f47c2015-03-25 14:40:32 -0700456 if (!mInputBufferIsDequeued.editItemAt(index)) {
Lajos Molnar87603c02014-08-20 19:25:30 -0700457 return true;
458 }
459
Marco Nelissen421f47c2015-03-25 14:40:32 -0700460 mDequeuedInputBuffers.push_back(index);
Chong Zhang7137ec72014-11-12 16:41:05 -0800461
462 onRequestInputBuffers();
Lajos Molnar1cd13982014-01-17 15:12:51 -0800463 return true;
464}
465
Marco Nelissen421f47c2015-03-25 14:40:32 -0700466bool NuPlayer::Decoder::handleAnOutputBuffer(
467 size_t index,
468 size_t offset,
469 size_t size,
470 int64_t timeUs,
471 int32_t flags) {
Marco Nelissen421f47c2015-03-25 14:40:32 -0700472// CHECK_LT(bufferIx, mOutputBuffers.size());
473 sp<ABuffer> buffer;
474 mCodec->getOutputBuffer(index, &buffer);
475
476 if (index >= mOutputBuffers.size()) {
477 for (size_t i = mOutputBuffers.size(); i <= index; ++i) {
478 mOutputBuffers.add();
479 }
480 }
481
482 mOutputBuffers.editItemAt(index) = buffer;
483
Chong Zhang7137ec72014-11-12 16:41:05 -0800484 buffer->setRange(offset, size);
485 buffer->meta()->clear();
486 buffer->meta()->setInt64("timeUs", timeUs);
Chong Zhang66704af2015-03-03 19:32:35 -0800487
488 bool eos = flags & MediaCodec::BUFFER_FLAG_EOS;
Chong Zhang7137ec72014-11-12 16:41:05 -0800489 // we do not expect CODECCONFIG or SYNCFRAME for decoder
490
Lajos Molnar1d15ab52015-03-04 16:46:34 -0800491 sp<AMessage> reply = new AMessage(kWhatRenderBuffer, this);
Marco Nelissen421f47c2015-03-25 14:40:32 -0700492 reply->setSize("buffer-ix", index);
Chong Zhang7137ec72014-11-12 16:41:05 -0800493 reply->setInt32("generation", mBufferGeneration);
494
Chong Zhang66704af2015-03-03 19:32:35 -0800495 if (eos) {
496 ALOGI("[%s] saw output EOS", mIsAudio ? "audio" : "video");
497
498 buffer->meta()->setInt32("eos", true);
499 reply->setInt32("eos", true);
500 } else if (mSkipRenderingUntilMediaTimeUs >= 0) {
Chong Zhang7137ec72014-11-12 16:41:05 -0800501 if (timeUs < mSkipRenderingUntilMediaTimeUs) {
502 ALOGV("[%s] dropping buffer at time %lld as requested.",
503 mComponentName.c_str(), (long long)timeUs);
504
505 reply->post();
506 return true;
507 }
508
509 mSkipRenderingUntilMediaTimeUs = -1;
510 }
511
Chong Zhangf8d71772014-11-26 15:08:34 -0800512 // wait until 1st frame comes out to signal resume complete
513 notifyResumeCompleteIfNecessary();
514
Chong Zhang7137ec72014-11-12 16:41:05 -0800515 if (mRenderer != NULL) {
516 // send the buffer to renderer.
517 mRenderer->queueBuffer(mIsAudio, buffer, reply);
Chong Zhang66704af2015-03-03 19:32:35 -0800518 if (eos && !isDiscontinuityPending()) {
Chong Zhang7137ec72014-11-12 16:41:05 -0800519 mRenderer->queueEOS(mIsAudio, ERROR_END_OF_STREAM);
520 }
521 }
522
523 return true;
524}
525
Marco Nelissen421f47c2015-03-25 14:40:32 -0700526void NuPlayer::Decoder::handleOutputFormatChange(const sp<AMessage> &format) {
527 if (!mIsAudio) {
528 sp<AMessage> notify = mNotify->dup();
529 notify->setInt32("what", kWhatVideoSizeChanged);
530 notify->setMessage("format", format);
531 notify->post();
532 } else if (mRenderer != NULL) {
533 uint32_t flags;
534 int64_t durationUs;
535 bool hasVideo = (mSource->getFormat(false /* audio */) != NULL);
536 if (!hasVideo &&
537 mSource->getDuration(&durationUs) == OK &&
538 durationUs > AUDIO_SINK_MIN_DEEP_BUFFER_DURATION_US) {
539 flags = AUDIO_OUTPUT_FLAG_DEEP_BUFFER;
540 } else {
541 flags = AUDIO_OUTPUT_FLAG_NONE;
542 }
543
544 mRenderer->openAudioSink(
545 format, false /* offloadOnly */, hasVideo, flags, NULL /* isOffloaed */);
546 }
547}
548
Chong Zhang7137ec72014-11-12 16:41:05 -0800549void NuPlayer::Decoder::releaseAndResetMediaBuffers() {
550 for (size_t i = 0; i < mMediaBuffers.size(); i++) {
551 if (mMediaBuffers[i] != NULL) {
552 mMediaBuffers[i]->release();
553 mMediaBuffers.editItemAt(i) = NULL;
554 }
555 }
556 mMediaBuffers.resize(mInputBuffers.size());
557 for (size_t i = 0; i < mMediaBuffers.size(); i++) {
558 mMediaBuffers.editItemAt(i) = NULL;
559 }
560 mInputBufferIsDequeued.clear();
561 mInputBufferIsDequeued.resize(mInputBuffers.size());
562 for (size_t i = 0; i < mInputBufferIsDequeued.size(); i++) {
563 mInputBufferIsDequeued.editItemAt(i) = false;
564 }
565
566 mPendingInputMessages.clear();
567 mDequeuedInputBuffers.clear();
568 mSkipRenderingUntilMediaTimeUs = -1;
569}
570
571void NuPlayer::Decoder::requestCodecNotification() {
Chong Zhang7137ec72014-11-12 16:41:05 -0800572 if (mCodec != NULL) {
Lajos Molnar1d15ab52015-03-04 16:46:34 -0800573 sp<AMessage> reply = new AMessage(kWhatCodecNotify, this);
Chong Zhang7137ec72014-11-12 16:41:05 -0800574 reply->setInt32("generation", mBufferGeneration);
575 mCodec->requestActivityNotification(reply);
576 }
577}
578
579bool NuPlayer::Decoder::isStaleReply(const sp<AMessage> &msg) {
580 int32_t generation;
581 CHECK(msg->findInt32("generation", &generation));
582 return generation != mBufferGeneration;
583}
584
585status_t NuPlayer::Decoder::fetchInputData(sp<AMessage> &reply) {
586 sp<ABuffer> accessUnit;
587 bool dropAccessUnit;
588 do {
589 status_t err = mSource->dequeueAccessUnit(mIsAudio, &accessUnit);
590
591 if (err == -EWOULDBLOCK) {
592 return err;
593 } else if (err != OK) {
594 if (err == INFO_DISCONTINUITY) {
595 int32_t type;
596 CHECK(accessUnit->meta()->findInt32("discontinuity", &type));
597
598 bool formatChange =
599 (mIsAudio &&
600 (type & ATSParser::DISCONTINUITY_AUDIO_FORMAT))
601 || (!mIsAudio &&
602 (type & ATSParser::DISCONTINUITY_VIDEO_FORMAT));
603
604 bool timeChange = (type & ATSParser::DISCONTINUITY_TIME) != 0;
605
606 ALOGI("%s discontinuity (format=%d, time=%d)",
607 mIsAudio ? "audio" : "video", formatChange, timeChange);
608
609 bool seamlessFormatChange = false;
610 sp<AMessage> newFormat = mSource->getFormat(mIsAudio);
611 if (formatChange) {
612 seamlessFormatChange =
613 supportsSeamlessFormatChange(newFormat);
614 // treat seamless format change separately
615 formatChange = !seamlessFormatChange;
616 }
617
Chong Zhang66704af2015-03-03 19:32:35 -0800618 // For format or time change, return EOS to queue EOS input,
619 // then wait for EOS on output.
Chong Zhang7137ec72014-11-12 16:41:05 -0800620 if (formatChange /* not seamless */) {
Chong Zhang7137ec72014-11-12 16:41:05 -0800621 mFormatChangePending = true;
Chong Zhang66704af2015-03-03 19:32:35 -0800622 err = ERROR_END_OF_STREAM;
Chong Zhang7137ec72014-11-12 16:41:05 -0800623 } else if (timeChange) {
Chong Zhang7137ec72014-11-12 16:41:05 -0800624 rememberCodecSpecificData(newFormat);
Chong Zhang66704af2015-03-03 19:32:35 -0800625 mTimeChangePending = true;
626 err = ERROR_END_OF_STREAM;
Chong Zhang7137ec72014-11-12 16:41:05 -0800627 } else if (seamlessFormatChange) {
628 // reuse existing decoder and don't flush
629 rememberCodecSpecificData(newFormat);
Chong Zhang66704af2015-03-03 19:32:35 -0800630 continue;
Chong Zhang7137ec72014-11-12 16:41:05 -0800631 } else {
632 // This stream is unaffected by the discontinuity
633 return -EWOULDBLOCK;
634 }
635 }
636
Chong Zhang66704af2015-03-03 19:32:35 -0800637 // reply should only be returned without a buffer set
638 // when there is an error (including EOS)
639 CHECK(err != OK);
640
Chong Zhang7137ec72014-11-12 16:41:05 -0800641 reply->setInt32("err", err);
Chong Zhang66704af2015-03-03 19:32:35 -0800642 return ERROR_END_OF_STREAM;
Chong Zhang7137ec72014-11-12 16:41:05 -0800643 }
644
645 if (!mIsAudio) {
646 ++mNumFramesTotal;
647 }
648
649 dropAccessUnit = false;
650 if (!mIsAudio
651 && !mIsSecure
652 && mRenderer->getVideoLateByUs() > 100000ll
653 && mIsVideoAVC
654 && !IsAVCReferenceFrame(accessUnit)) {
655 dropAccessUnit = true;
656 ++mNumFramesDropped;
657 }
658 } while (dropAccessUnit);
659
660 // ALOGV("returned a valid buffer of %s data", mIsAudio ? "mIsAudio" : "video");
661#if 0
662 int64_t mediaTimeUs;
663 CHECK(accessUnit->meta()->findInt64("timeUs", &mediaTimeUs));
Chong Zhang5abbd3d2015-04-20 16:03:00 -0700664 ALOGV("[%s] feeding input buffer at media time %.3f",
Chong Zhang7137ec72014-11-12 16:41:05 -0800665 mIsAudio ? "audio" : "video",
666 mediaTimeUs / 1E6);
667#endif
668
669 if (mCCDecoder != NULL) {
670 mCCDecoder->decode(accessUnit);
671 }
672
673 reply->setBuffer("buffer", accessUnit);
674
675 return OK;
676}
677
678bool NuPlayer::Decoder::onInputBufferFetched(const sp<AMessage> &msg) {
Lajos Molnar1cd13982014-01-17 15:12:51 -0800679 size_t bufferIx;
680 CHECK(msg->findSize("buffer-ix", &bufferIx));
681 CHECK_LT(bufferIx, mInputBuffers.size());
682 sp<ABuffer> codecBuffer = mInputBuffers[bufferIx];
683
684 sp<ABuffer> buffer;
685 bool hasBuffer = msg->findBuffer("buffer", &buffer);
Lajos Molnar09524832014-07-17 14:29:51 -0700686
687 // handle widevine classic source - that fills an arbitrary input buffer
688 MediaBuffer *mediaBuffer = NULL;
Wei Jia96e92b52014-09-18 17:36:20 -0700689 if (hasBuffer) {
690 mediaBuffer = (MediaBuffer *)(buffer->getMediaBufferBase());
691 if (mediaBuffer != NULL) {
Lajos Molnar09524832014-07-17 14:29:51 -0700692 // likely filled another buffer than we requested: adjust buffer index
693 size_t ix;
694 for (ix = 0; ix < mInputBuffers.size(); ix++) {
695 const sp<ABuffer> &buf = mInputBuffers[ix];
696 if (buf->data() == mediaBuffer->data()) {
697 // all input buffers are dequeued on start, hence the check
Wei Jia2245fc62014-10-02 15:12:25 -0700698 if (!mInputBufferIsDequeued[ix]) {
699 ALOGV("[%s] received MediaBuffer for #%zu instead of #%zu",
700 mComponentName.c_str(), ix, bufferIx);
701 mediaBuffer->release();
702 return false;
703 }
Lajos Molnar09524832014-07-17 14:29:51 -0700704
705 // TRICKY: need buffer for the metadata, so instead, set
706 // codecBuffer to the same (though incorrect) buffer to
707 // avoid a memcpy into the codecBuffer
708 codecBuffer = buffer;
709 codecBuffer->setRange(
710 mediaBuffer->range_offset(),
711 mediaBuffer->range_length());
712 bufferIx = ix;
713 break;
714 }
715 }
716 CHECK(ix < mInputBuffers.size());
717 }
718 }
719
Lajos Molnar1cd13982014-01-17 15:12:51 -0800720 if (buffer == NULL /* includes !hasBuffer */) {
721 int32_t streamErr = ERROR_END_OF_STREAM;
722 CHECK(msg->findInt32("err", &streamErr) || !hasBuffer);
723
Chong Zhang66704af2015-03-03 19:32:35 -0800724 CHECK(streamErr != OK);
Lajos Molnar1cd13982014-01-17 15:12:51 -0800725
726 // attempt to queue EOS
727 status_t err = mCodec->queueInputBuffer(
728 bufferIx,
729 0,
730 0,
731 0,
732 MediaCodec::BUFFER_FLAG_EOS);
Andy Hungcf31f1e2014-09-23 14:59:01 -0700733 if (err == OK) {
734 mInputBufferIsDequeued.editItemAt(bufferIx) = false;
735 } else if (streamErr == ERROR_END_OF_STREAM) {
Lajos Molnar1cd13982014-01-17 15:12:51 -0800736 streamErr = err;
737 // err will not be ERROR_END_OF_STREAM
738 }
739
740 if (streamErr != ERROR_END_OF_STREAM) {
Andy Hungcf31f1e2014-09-23 14:59:01 -0700741 ALOGE("Stream error for %s (err=%d), EOS %s queued",
742 mComponentName.c_str(),
743 streamErr,
744 err == OK ? "successfully" : "unsuccessfully");
Lajos Molnar1cd13982014-01-17 15:12:51 -0800745 handleError(streamErr);
746 }
747 } else {
Wei Jiac6cfd702014-11-11 16:33:20 -0800748 sp<AMessage> extra;
749 if (buffer->meta()->findMessage("extra", &extra) && extra != NULL) {
750 int64_t resumeAtMediaTimeUs;
751 if (extra->findInt64(
752 "resume-at-mediaTimeUs", &resumeAtMediaTimeUs)) {
753 ALOGI("[%s] suppressing rendering until %lld us",
754 mComponentName.c_str(), (long long)resumeAtMediaTimeUs);
755 mSkipRenderingUntilMediaTimeUs = resumeAtMediaTimeUs;
756 }
757 }
758
Lajos Molnar1cd13982014-01-17 15:12:51 -0800759 int64_t timeUs = 0;
760 uint32_t flags = 0;
761 CHECK(buffer->meta()->findInt64("timeUs", &timeUs));
762
Lajos Molnar87603c02014-08-20 19:25:30 -0700763 int32_t eos, csd;
764 // we do not expect SYNCFRAME for decoder
Lajos Molnar1cd13982014-01-17 15:12:51 -0800765 if (buffer->meta()->findInt32("eos", &eos) && eos) {
766 flags |= MediaCodec::BUFFER_FLAG_EOS;
Lajos Molnar87603c02014-08-20 19:25:30 -0700767 } else if (buffer->meta()->findInt32("csd", &csd) && csd) {
768 flags |= MediaCodec::BUFFER_FLAG_CODECCONFIG;
Lajos Molnar1cd13982014-01-17 15:12:51 -0800769 }
770
771 // copy into codec buffer
772 if (buffer != codecBuffer) {
773 CHECK_LE(buffer->size(), codecBuffer->capacity());
774 codecBuffer->setRange(0, buffer->size());
775 memcpy(codecBuffer->data(), buffer->data(), buffer->size());
776 }
777
778 status_t err = mCodec->queueInputBuffer(
779 bufferIx,
780 codecBuffer->offset(),
781 codecBuffer->size(),
782 timeUs,
783 flags);
784 if (err != OK) {
Andy Hungcf31f1e2014-09-23 14:59:01 -0700785 if (mediaBuffer != NULL) {
786 mediaBuffer->release();
787 }
Lajos Molnar1cd13982014-01-17 15:12:51 -0800788 ALOGE("Failed to queue input buffer for %s (err=%d)",
789 mComponentName.c_str(), err);
790 handleError(err);
Andy Hungcf31f1e2014-09-23 14:59:01 -0700791 } else {
792 mInputBufferIsDequeued.editItemAt(bufferIx) = false;
793 if (mediaBuffer != NULL) {
794 CHECK(mMediaBuffers[bufferIx] == NULL);
795 mMediaBuffers.editItemAt(bufferIx) = mediaBuffer;
796 }
Lajos Molnar09524832014-07-17 14:29:51 -0700797 }
Lajos Molnar1cd13982014-01-17 15:12:51 -0800798 }
Wei Jia2245fc62014-10-02 15:12:25 -0700799 return true;
Lajos Molnar1cd13982014-01-17 15:12:51 -0800800}
801
Lajos Molnar1cd13982014-01-17 15:12:51 -0800802void NuPlayer::Decoder::onRenderBuffer(const sp<AMessage> &msg) {
803 status_t err;
804 int32_t render;
805 size_t bufferIx;
Chong Zhang66704af2015-03-03 19:32:35 -0800806 int32_t eos;
Lajos Molnar1cd13982014-01-17 15:12:51 -0800807 CHECK(msg->findSize("buffer-ix", &bufferIx));
Wei Jiac6cfd702014-11-11 16:33:20 -0800808
Chong Zhang7137ec72014-11-12 16:41:05 -0800809 if (!mIsAudio) {
Wei Jiac6cfd702014-11-11 16:33:20 -0800810 int64_t timeUs;
811 sp<ABuffer> buffer = mOutputBuffers[bufferIx];
812 buffer->meta()->findInt64("timeUs", &timeUs);
Chong Zhang7137ec72014-11-12 16:41:05 -0800813
814 if (mCCDecoder != NULL && mCCDecoder->isSelected()) {
815 mCCDecoder->display(timeUs);
816 }
Wei Jiac6cfd702014-11-11 16:33:20 -0800817 }
818
Lajos Molnar1cd13982014-01-17 15:12:51 -0800819 if (msg->findInt32("render", &render) && render) {
Lajos Molnardc43dfa2014-05-07 15:33:04 -0700820 int64_t timestampNs;
821 CHECK(msg->findInt64("timestampNs", &timestampNs));
822 err = mCodec->renderOutputBufferAndRelease(bufferIx, timestampNs);
Lajos Molnar1cd13982014-01-17 15:12:51 -0800823 } else {
824 err = mCodec->releaseOutputBuffer(bufferIx);
825 }
826 if (err != OK) {
827 ALOGE("failed to release output buffer for %s (err=%d)",
828 mComponentName.c_str(), err);
829 handleError(err);
830 }
Chong Zhang66704af2015-03-03 19:32:35 -0800831 if (msg->findInt32("eos", &eos) && eos
832 && isDiscontinuityPending()) {
833 finishHandleDiscontinuity(true /* flushOnTimeChange */);
834 }
835}
836
837bool NuPlayer::Decoder::isDiscontinuityPending() const {
838 return mFormatChangePending || mTimeChangePending;
839}
840
841void NuPlayer::Decoder::finishHandleDiscontinuity(bool flushOnTimeChange) {
842 ALOGV("finishHandleDiscontinuity: format %d, time %d, flush %d",
843 mFormatChangePending, mTimeChangePending, flushOnTimeChange);
844
845 // If we have format change, pause and wait to be killed;
846 // If we have time change only, flush and restart fetching.
847
848 if (mFormatChangePending) {
849 mPaused = true;
850 } else if (mTimeChangePending) {
851 if (flushOnTimeChange) {
Marco Nelissen421f47c2015-03-25 14:40:32 -0700852 doFlush(false /* notifyComplete */);
853 signalResume(false /* notifyComplete */);
Chong Zhang66704af2015-03-03 19:32:35 -0800854 }
Chong Zhang66704af2015-03-03 19:32:35 -0800855 }
856
857 // Notify NuPlayer to either shutdown decoder, or rescan sources
858 sp<AMessage> msg = mNotify->dup();
859 msg->setInt32("what", kWhatInputDiscontinuity);
860 msg->setInt32("formatChange", mFormatChangePending);
861 msg->post();
862
863 mFormatChangePending = false;
864 mTimeChangePending = false;
Lajos Molnar1cd13982014-01-17 15:12:51 -0800865}
866
Chong Zhang7137ec72014-11-12 16:41:05 -0800867bool NuPlayer::Decoder::supportsSeamlessAudioFormatChange(
868 const sp<AMessage> &targetFormat) const {
Robert Shih6d0a94e2014-01-23 16:18:22 -0800869 if (targetFormat == NULL) {
870 return true;
871 }
872
873 AString mime;
874 if (!targetFormat->findString("mime", &mime)) {
875 return false;
876 }
877
878 if (!strcasecmp(mime.c_str(), MEDIA_MIMETYPE_AUDIO_AAC)) {
879 // field-by-field comparison
880 const char * keys[] = { "channel-count", "sample-rate", "is-adts" };
881 for (unsigned int i = 0; i < sizeof(keys) / sizeof(keys[0]); i++) {
882 int32_t oldVal, newVal;
joakim johansson7abbd4c2015-01-30 14:16:03 +0100883 if (!mInputFormat->findInt32(keys[i], &oldVal) ||
Lajos Molnar1cd13982014-01-17 15:12:51 -0800884 !targetFormat->findInt32(keys[i], &newVal) ||
885 oldVal != newVal) {
Robert Shih6d0a94e2014-01-23 16:18:22 -0800886 return false;
887 }
888 }
889
890 sp<ABuffer> oldBuf, newBuf;
joakim johansson7abbd4c2015-01-30 14:16:03 +0100891 if (mInputFormat->findBuffer("csd-0", &oldBuf) &&
Lajos Molnar1cd13982014-01-17 15:12:51 -0800892 targetFormat->findBuffer("csd-0", &newBuf)) {
Robert Shih6d0a94e2014-01-23 16:18:22 -0800893 if (oldBuf->size() != newBuf->size()) {
894 return false;
895 }
896 return !memcmp(oldBuf->data(), newBuf->data(), oldBuf->size());
897 }
898 }
899 return false;
900}
901
902bool NuPlayer::Decoder::supportsSeamlessFormatChange(const sp<AMessage> &targetFormat) const {
joakim johansson7abbd4c2015-01-30 14:16:03 +0100903 if (mInputFormat == NULL) {
Robert Shih6d0a94e2014-01-23 16:18:22 -0800904 return false;
905 }
906
907 if (targetFormat == NULL) {
908 return true;
909 }
910
911 AString oldMime, newMime;
joakim johansson7abbd4c2015-01-30 14:16:03 +0100912 if (!mInputFormat->findString("mime", &oldMime)
Robert Shih6d0a94e2014-01-23 16:18:22 -0800913 || !targetFormat->findString("mime", &newMime)
914 || !(oldMime == newMime)) {
915 return false;
916 }
917
918 bool audio = !strncasecmp(oldMime.c_str(), "audio/", strlen("audio/"));
919 bool seamless;
920 if (audio) {
921 seamless = supportsSeamlessAudioFormatChange(targetFormat);
922 } else {
Lajos Molnar1cd13982014-01-17 15:12:51 -0800923 int32_t isAdaptive;
924 seamless = (mCodec != NULL &&
925 mInputFormat->findInt32("adaptive-playback", &isAdaptive) &&
926 isAdaptive);
Robert Shih6d0a94e2014-01-23 16:18:22 -0800927 }
928
929 ALOGV("%s seamless support for %s", seamless ? "yes" : "no", oldMime.c_str());
930 return seamless;
931}
932
Chong Zhang7137ec72014-11-12 16:41:05 -0800933void NuPlayer::Decoder::rememberCodecSpecificData(const sp<AMessage> &format) {
934 if (format == NULL) {
Chong Zhangb86e68f2014-08-01 13:46:53 -0700935 return;
936 }
Chong Zhang7137ec72014-11-12 16:41:05 -0800937 mCSDsForCurrentFormat.clear();
938 for (int32_t i = 0; ; ++i) {
939 AString tag = "csd-";
940 tag.append(i);
941 sp<ABuffer> buffer;
942 if (!format->findBuffer(tag.c_str(), &buffer)) {
943 break;
944 }
945 mCSDsForCurrentFormat.push(buffer);
Chong Zhanga7fa1d92014-06-11 14:49:23 -0700946 }
Chong Zhangb86e68f2014-08-01 13:46:53 -0700947}
948
Chong Zhangf8d71772014-11-26 15:08:34 -0800949void NuPlayer::Decoder::notifyResumeCompleteIfNecessary() {
950 if (mResumePending) {
951 mResumePending = false;
952
953 sp<AMessage> notify = mNotify->dup();
954 notify->setInt32("what", kWhatResumeCompleted);
955 notify->post();
956 }
957}
958
Andreas Huberf9334412010-12-15 15:17:42 -0800959} // namespace android
960