blob: 3c4d6956e66db937e1f975e95b4316db0ce658b8 [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
Chong Zhang7137ec72014-11-12 16:41:05 -080036#include "avc_utils.h"
37#include "ATSParser.h"
38
Andreas Huberf9334412010-12-15 15:17:42 -080039namespace android {
40
41NuPlayer::Decoder::Decoder(
Glenn Kasten11731182011-02-08 17:26:17 -080042 const sp<AMessage> &notify,
Wei Jiac6cfd702014-11-11 16:33:20 -080043 const sp<Source> &source,
44 const sp<Renderer> &renderer,
Chong Zhang7137ec72014-11-12 16:41:05 -080045 const sp<NativeWindowWrapper> &nativeWindow,
46 const sp<CCDecoder> &ccDecoder)
Andy Hung202bce12014-12-03 11:47:36 -080047 : DecoderBase(notify),
Lajos Molnar1cd13982014-01-17 15:12:51 -080048 mNativeWindow(nativeWindow),
Wei Jiac6cfd702014-11-11 16:33:20 -080049 mSource(source),
50 mRenderer(renderer),
Chong Zhang7137ec72014-11-12 16:41:05 -080051 mCCDecoder(ccDecoder),
Wei Jiac6cfd702014-11-11 16:33:20 -080052 mSkipRenderingUntilMediaTimeUs(-1ll),
Chong Zhang7137ec72014-11-12 16:41:05 -080053 mNumFramesTotal(0ll),
54 mNumFramesDropped(0ll),
55 mIsAudio(true),
56 mIsVideoAVC(false),
57 mIsSecure(false),
58 mFormatChangePending(false),
Chong Zhang66704af2015-03-03 19:32:35 -080059 mTimeChangePending(false),
Wei Jia704e7262014-06-04 16:21:56 -070060 mPaused(true),
Chong Zhangf8d71772014-11-26 15:08:34 -080061 mResumePending(false),
Lajos Molnar1cd13982014-01-17 15:12:51 -080062 mComponentName("decoder") {
Lajos Molnar1cd13982014-01-17 15:12:51 -080063 mCodecLooper = new ALooper;
Marco Nelissen9e2b7912014-08-18 16:13:03 -070064 mCodecLooper->setName("NPDecoder-CL");
Lajos Molnar1cd13982014-01-17 15:12:51 -080065 mCodecLooper->start(false, false, ANDROID_PRIORITY_AUDIO);
Andreas Huberf9334412010-12-15 15:17:42 -080066}
67
68NuPlayer::Decoder::~Decoder() {
Wei Jia4923cee2014-09-24 14:25:19 -070069 releaseAndResetMediaBuffers();
Andreas Huberf9334412010-12-15 15:17:42 -080070}
71
Chong Zhang7137ec72014-11-12 16:41:05 -080072void NuPlayer::Decoder::getStats(
73 int64_t *numFramesTotal,
74 int64_t *numFramesDropped) const {
75 *numFramesTotal = mNumFramesTotal;
76 *numFramesDropped = mNumFramesDropped;
Lajos Molnar09524832014-07-17 14:29:51 -070077}
78
Chong Zhang7137ec72014-11-12 16:41:05 -080079void NuPlayer::Decoder::onMessageReceived(const sp<AMessage> &msg) {
80 ALOGV("[%s] onMessage: %s", mComponentName.c_str(), msg->debugString().c_str());
81
82 switch (msg->what()) {
83 case kWhatCodecNotify:
84 {
Chong Zhang3b032b32015-04-17 15:49:06 -070085 int32_t cbID;
86 CHECK(msg->findInt32("callbackID", &cbID));
87
88 ALOGV("[%s] kWhatCodecNotify: cbID = %d, paused = %d",
89 mIsAudio ? "audio" : "video", cbID, mPaused);
90
Marco Nelissen421f47c2015-03-25 14:40:32 -070091 if (mPaused) {
92 break;
Chong Zhang7137ec72014-11-12 16:41:05 -080093 }
94
Marco Nelissen421f47c2015-03-25 14:40:32 -070095 switch (cbID) {
96 case MediaCodec::CB_INPUT_AVAILABLE:
97 {
98 int32_t index;
99 CHECK(msg->findInt32("index", &index));
100
101 handleAnInputBuffer(index);
102 break;
103 }
104
105 case MediaCodec::CB_OUTPUT_AVAILABLE:
106 {
107 int32_t index;
108 size_t offset;
109 size_t size;
110 int64_t timeUs;
111 int32_t flags;
112
113 CHECK(msg->findInt32("index", &index));
114 CHECK(msg->findSize("offset", &offset));
115 CHECK(msg->findSize("size", &size));
116 CHECK(msg->findInt64("timeUs", &timeUs));
117 CHECK(msg->findInt32("flags", &flags));
118
119 handleAnOutputBuffer(index, offset, size, timeUs, flags);
120 break;
121 }
122
123 case MediaCodec::CB_OUTPUT_FORMAT_CHANGED:
124 {
125 sp<AMessage> format;
126 CHECK(msg->findMessage("format", &format));
127
128 handleOutputFormatChange(format);
129 break;
130 }
131
132 case MediaCodec::CB_ERROR:
133 {
134 status_t err;
135 CHECK(msg->findInt32("err", &err));
136 ALOGE("Decoder (%s) reported error : 0x%x",
137 mIsAudio ? "audio" : "video", err);
138
139 handleError(err);
140 break;
141 }
142
143 default:
144 {
145 TRESPASS();
146 break;
147 }
148 }
149
Lajos Molnar87603c02014-08-20 19:25:30 -0700150 break;
151 }
Chong Zhang7137ec72014-11-12 16:41:05 -0800152
153 case kWhatRenderBuffer:
154 {
155 if (!isStaleReply(msg)) {
156 onRenderBuffer(msg);
157 }
158 break;
159 }
160
161 default:
162 DecoderBase::onMessageReceived(msg);
163 break;
Lajos Molnar87603c02014-08-20 19:25:30 -0700164 }
165}
166
Lajos Molnar1cd13982014-01-17 15:12:51 -0800167void NuPlayer::Decoder::onConfigure(const sp<AMessage> &format) {
Andreas Huberf9334412010-12-15 15:17:42 -0800168 CHECK(mCodec == NULL);
Andreas Huberf9334412010-12-15 15:17:42 -0800169
Chong Zhang7137ec72014-11-12 16:41:05 -0800170 mFormatChangePending = false;
Chong Zhang66704af2015-03-03 19:32:35 -0800171 mTimeChangePending = false;
Chong Zhang7137ec72014-11-12 16:41:05 -0800172
Lajos Molnar1cd13982014-01-17 15:12:51 -0800173 ++mBufferGeneration;
174
Andreas Huber84066782011-08-16 09:34:26 -0700175 AString mime;
176 CHECK(format->findString("mime", &mime));
Andreas Huberf9334412010-12-15 15:17:42 -0800177
Chong Zhang7137ec72014-11-12 16:41:05 -0800178 mIsAudio = !strncasecmp("audio/", mime.c_str(), 6);
179 mIsVideoAVC = !strcasecmp(MEDIA_MIMETYPE_VIDEO_AVC, mime.c_str());
180
Lajos Molnar1cd13982014-01-17 15:12:51 -0800181 sp<Surface> surface = NULL;
182 if (mNativeWindow != NULL) {
183 surface = mNativeWindow->getSurfaceTextureClient();
Andreas Huber84066782011-08-16 09:34:26 -0700184 }
Andreas Huberf9334412010-12-15 15:17:42 -0800185
Lajos Molnar1cd13982014-01-17 15:12:51 -0800186 mComponentName = mime;
187 mComponentName.append(" decoder");
188 ALOGV("[%s] onConfigure (surface=%p)", mComponentName.c_str(), surface.get());
189
190 mCodec = MediaCodec::CreateByType(mCodecLooper, mime.c_str(), false /* encoder */);
Lajos Molnar09524832014-07-17 14:29:51 -0700191 int32_t secure = 0;
192 if (format->findInt32("secure", &secure) && secure != 0) {
193 if (mCodec != NULL) {
194 mCodec->getName(&mComponentName);
195 mComponentName.append(".secure");
196 mCodec->release();
197 ALOGI("[%s] creating", mComponentName.c_str());
198 mCodec = MediaCodec::CreateByComponentName(
199 mCodecLooper, mComponentName.c_str());
200 }
201 }
Lajos Molnar1cd13982014-01-17 15:12:51 -0800202 if (mCodec == NULL) {
Lajos Molnar09524832014-07-17 14:29:51 -0700203 ALOGE("Failed to create %s%s decoder",
204 (secure ? "secure " : ""), mime.c_str());
Lajos Molnar1cd13982014-01-17 15:12:51 -0800205 handleError(UNKNOWN_ERROR);
206 return;
207 }
Chong Zhang7137ec72014-11-12 16:41:05 -0800208 mIsSecure = secure;
Lajos Molnar1cd13982014-01-17 15:12:51 -0800209
210 mCodec->getName(&mComponentName);
211
Lajos Molnar14986f62014-09-15 11:04:44 -0700212 status_t err;
Glenn Kasten11731182011-02-08 17:26:17 -0800213 if (mNativeWindow != NULL) {
Lajos Molnar1cd13982014-01-17 15:12:51 -0800214 // disconnect from surface as MediaCodec will reconnect
Lajos Molnar14986f62014-09-15 11:04:44 -0700215 err = native_window_api_disconnect(
216 surface.get(), NATIVE_WINDOW_API_MEDIA);
217 // We treat this as a warning, as this is a preparatory step.
218 // Codec will try to connect to the surface, which is where
219 // any error signaling will occur.
220 ALOGW_IF(err != OK, "failed to disconnect from surface: %d", err);
Lajos Molnar1cd13982014-01-17 15:12:51 -0800221 }
Lajos Molnar14986f62014-09-15 11:04:44 -0700222 err = mCodec->configure(
Lajos Molnar1cd13982014-01-17 15:12:51 -0800223 format, surface, NULL /* crypto */, 0 /* flags */);
224 if (err != OK) {
225 ALOGE("Failed to configure %s decoder (err=%d)", mComponentName.c_str(), err);
Andy Hung2abde2c2014-09-30 14:40:32 -0700226 mCodec->release();
227 mCodec.clear();
Lajos Molnar1cd13982014-01-17 15:12:51 -0800228 handleError(err);
229 return;
230 }
Lajos Molnar87603c02014-08-20 19:25:30 -0700231 rememberCodecSpecificData(format);
232
Lajos Molnar1cd13982014-01-17 15:12:51 -0800233 // the following should work in configured state
234 CHECK_EQ((status_t)OK, mCodec->getOutputFormat(&mOutputFormat));
235 CHECK_EQ((status_t)OK, mCodec->getInputFormat(&mInputFormat));
236
Marco Nelissen421f47c2015-03-25 14:40:32 -0700237 sp<AMessage> reply = new AMessage(kWhatCodecNotify, this);
238 mCodec->setCallback(reply);
239
Lajos Molnar1cd13982014-01-17 15:12:51 -0800240 err = mCodec->start();
241 if (err != OK) {
242 ALOGE("Failed to start %s decoder (err=%d)", mComponentName.c_str(), err);
Andy Hung2abde2c2014-09-30 14:40:32 -0700243 mCodec->release();
244 mCodec.clear();
Lajos Molnar1cd13982014-01-17 15:12:51 -0800245 handleError(err);
246 return;
Andreas Huberf9334412010-12-15 15:17:42 -0800247 }
248
Lajos Molnar09524832014-07-17 14:29:51 -0700249 releaseAndResetMediaBuffers();
Marco Nelissen421f47c2015-03-25 14:40:32 -0700250
Wei Jia704e7262014-06-04 16:21:56 -0700251 mPaused = false;
Chong Zhangf8d71772014-11-26 15:08:34 -0800252 mResumePending = false;
Lajos Molnar1cd13982014-01-17 15:12:51 -0800253}
Andreas Huber078cfcf2011-09-15 12:25:04 -0700254
Ronghua Wu8db88132015-04-22 13:51:35 -0700255void NuPlayer::Decoder::onSetParameters(const sp<AMessage> &params) {
256 if (mCodec == NULL) {
257 ALOGW("onSetParameters called before codec is created.");
258 return;
259 }
260 mCodec->setParameters(params);
261}
262
Chong Zhang7137ec72014-11-12 16:41:05 -0800263void NuPlayer::Decoder::onSetRenderer(const sp<Renderer> &renderer) {
264 bool hadNoRenderer = (mRenderer == NULL);
265 mRenderer = renderer;
266 if (hadNoRenderer && mRenderer != NULL) {
Lajos Molnare6109e22015-04-10 17:18:22 -0700267 // this means that the widevine legacy source is ready
268 onRequestInputBuffers();
Chong Zhang7137ec72014-11-12 16:41:05 -0800269 }
270}
271
272void NuPlayer::Decoder::onGetInputBuffers(
273 Vector<sp<ABuffer> > *dstBuffers) {
Lajos Molnare6109e22015-04-10 17:18:22 -0700274 CHECK_EQ((status_t)OK, mCodec->getWidevineLegacyBuffers(dstBuffers));
Chong Zhang7137ec72014-11-12 16:41:05 -0800275}
276
Chong Zhangf8d71772014-11-26 15:08:34 -0800277void NuPlayer::Decoder::onResume(bool notifyComplete) {
Chong Zhang7137ec72014-11-12 16:41:05 -0800278 mPaused = false;
Chong Zhangf8d71772014-11-26 15:08:34 -0800279
280 if (notifyComplete) {
281 mResumePending = true;
282 }
Marco Nelissen421f47c2015-03-25 14:40:32 -0700283 mCodec->start();
Chong Zhang7137ec72014-11-12 16:41:05 -0800284}
285
Chong Zhang66704af2015-03-03 19:32:35 -0800286void NuPlayer::Decoder::doFlush(bool notifyComplete) {
Chong Zhang7137ec72014-11-12 16:41:05 -0800287 if (mCCDecoder != NULL) {
288 mCCDecoder->flush();
289 }
290
291 if (mRenderer != NULL) {
292 mRenderer->flush(mIsAudio, notifyComplete);
293 mRenderer->signalTimeDiscontinuity();
294 }
295
296 status_t err = OK;
297 if (mCodec != NULL) {
298 err = mCodec->flush();
299 mCSDsToSubmit = mCSDsForCurrentFormat; // copy operator
300 ++mBufferGeneration;
301 }
302
303 if (err != OK) {
304 ALOGE("failed to flush %s (err=%d)", mComponentName.c_str(), err);
305 handleError(err);
306 // finish with posting kWhatFlushCompleted.
307 // we attempt to release the buffers even if flush fails.
308 }
309 releaseAndResetMediaBuffers();
Marco Nelissen421f47c2015-03-25 14:40:32 -0700310 mPaused = true;
Chong Zhang66704af2015-03-03 19:32:35 -0800311}
Chong Zhang7137ec72014-11-12 16:41:05 -0800312
Marco Nelissen421f47c2015-03-25 14:40:32 -0700313
Chong Zhang66704af2015-03-03 19:32:35 -0800314void NuPlayer::Decoder::onFlush() {
315 doFlush(true);
316
317 if (isDiscontinuityPending()) {
318 // This could happen if the client starts seeking/shutdown
319 // after we queued an EOS for discontinuities.
320 // We can consider discontinuity handled.
321 finishHandleDiscontinuity(false /* flushOnTimeChange */);
Chong Zhang7137ec72014-11-12 16:41:05 -0800322 }
Chong Zhang66704af2015-03-03 19:32:35 -0800323
324 sp<AMessage> notify = mNotify->dup();
325 notify->setInt32("what", kWhatFlushCompleted);
326 notify->post();
Chong Zhang7137ec72014-11-12 16:41:05 -0800327}
328
329void NuPlayer::Decoder::onShutdown(bool notifyComplete) {
330 status_t err = OK;
Chong Zhangf8d71772014-11-26 15:08:34 -0800331
332 // if there is a pending resume request, notify complete now
333 notifyResumeCompleteIfNecessary();
334
Chong Zhang7137ec72014-11-12 16:41:05 -0800335 if (mCodec != NULL) {
336 err = mCodec->release();
337 mCodec = NULL;
338 ++mBufferGeneration;
339
340 if (mNativeWindow != NULL) {
341 // reconnect to surface as MediaCodec disconnected from it
342 status_t error =
343 native_window_api_connect(
344 mNativeWindow->getNativeWindow().get(),
345 NATIVE_WINDOW_API_MEDIA);
346 ALOGW_IF(error != NO_ERROR,
347 "[%s] failed to connect to native window, error=%d",
348 mComponentName.c_str(), error);
349 }
350 mComponentName = "decoder";
351 }
352
353 releaseAndResetMediaBuffers();
354
355 if (err != OK) {
356 ALOGE("failed to release %s (err=%d)", mComponentName.c_str(), err);
357 handleError(err);
358 // finish with posting kWhatShutdownCompleted.
359 }
360
361 if (notifyComplete) {
362 sp<AMessage> notify = mNotify->dup();
363 notify->setInt32("what", kWhatShutdownCompleted);
364 notify->post();
365 mPaused = true;
366 }
367}
368
Chong Zhang3b032b32015-04-17 15:49:06 -0700369/*
370 * returns true if we should request more data
371 */
372bool NuPlayer::Decoder::doRequestBuffers() {
Lajos Molnare6109e22015-04-10 17:18:22 -0700373 // mRenderer is only NULL if we have a legacy widevine source that
374 // is not yet ready. In this case we must not fetch input.
375 if (isDiscontinuityPending() || mRenderer == NULL) {
Chong Zhang3b032b32015-04-17 15:49:06 -0700376 return false;
Chong Zhang7137ec72014-11-12 16:41:05 -0800377 }
378 status_t err = OK;
Chong Zhang66704af2015-03-03 19:32:35 -0800379 while (err == OK && !mDequeuedInputBuffers.empty()) {
Chong Zhang7137ec72014-11-12 16:41:05 -0800380 size_t bufferIx = *mDequeuedInputBuffers.begin();
381 sp<AMessage> msg = new AMessage();
382 msg->setSize("buffer-ix", bufferIx);
383 err = fetchInputData(msg);
Chong Zhang66704af2015-03-03 19:32:35 -0800384 if (err != OK && err != ERROR_END_OF_STREAM) {
385 // if EOS, need to queue EOS buffer
Chong Zhang7137ec72014-11-12 16:41:05 -0800386 break;
387 }
388 mDequeuedInputBuffers.erase(mDequeuedInputBuffers.begin());
389
390 if (!mPendingInputMessages.empty()
391 || !onInputBufferFetched(msg)) {
392 mPendingInputMessages.push_back(msg);
Lajos Molnar09524832014-07-17 14:29:51 -0700393 }
394 }
Chong Zhang7137ec72014-11-12 16:41:05 -0800395
Chong Zhang3b032b32015-04-17 15:49:06 -0700396 return err == -EWOULDBLOCK
397 && mSource->feedMoreTSData() == OK;
Lajos Molnar09524832014-07-17 14:29:51 -0700398}
399
Marco Nelissen421f47c2015-03-25 14:40:32 -0700400void NuPlayer::Decoder::handleError(int32_t err)
401{
402 // We cannot immediately release the codec due to buffers still outstanding
403 // in the renderer. We signal to the player the error so it can shutdown/release the
404 // decoder after flushing and increment the generation to discard unnecessary messages.
405
406 ++mBufferGeneration;
407
408 sp<AMessage> notify = mNotify->dup();
409 notify->setInt32("what", kWhatError);
410 notify->setInt32("err", err);
411 notify->post();
412}
413
414bool NuPlayer::Decoder::handleAnInputBuffer(size_t index) {
Chong Zhang66704af2015-03-03 19:32:35 -0800415 if (isDiscontinuityPending()) {
Chong Zhang7137ec72014-11-12 16:41:05 -0800416 return false;
417 }
Marco Nelissen421f47c2015-03-25 14:40:32 -0700418
419 sp<ABuffer> buffer;
420 mCodec->getInputBuffer(index, &buffer);
421
422 if (index >= mInputBuffers.size()) {
423 for (size_t i = mInputBuffers.size(); i <= index; ++i) {
424 mInputBuffers.add();
425 mMediaBuffers.add();
426 mInputBufferIsDequeued.add();
427 mMediaBuffers.editItemAt(i) = NULL;
428 mInputBufferIsDequeued.editItemAt(i) = false;
Lajos Molnar1cd13982014-01-17 15:12:51 -0800429 }
Andreas Huber078cfcf2011-09-15 12:25:04 -0700430 }
Marco Nelissen421f47c2015-03-25 14:40:32 -0700431 mInputBuffers.editItemAt(index) = buffer;
Andreas Huber078cfcf2011-09-15 12:25:04 -0700432
Marco Nelissen421f47c2015-03-25 14:40:32 -0700433 //CHECK_LT(bufferIx, mInputBuffers.size());
Andreas Huberf9334412010-12-15 15:17:42 -0800434
Marco Nelissen421f47c2015-03-25 14:40:32 -0700435 if (mMediaBuffers[index] != NULL) {
436 mMediaBuffers[index]->release();
437 mMediaBuffers.editItemAt(index) = NULL;
Lajos Molnar09524832014-07-17 14:29:51 -0700438 }
Marco Nelissen421f47c2015-03-25 14:40:32 -0700439 mInputBufferIsDequeued.editItemAt(index) = true;
Lajos Molnar09524832014-07-17 14:29:51 -0700440
Lajos Molnar87603c02014-08-20 19:25:30 -0700441 if (!mCSDsToSubmit.isEmpty()) {
Chong Zhang7137ec72014-11-12 16:41:05 -0800442 sp<AMessage> msg = new AMessage();
Marco Nelissen421f47c2015-03-25 14:40:32 -0700443 msg->setSize("buffer-ix", index);
Chong Zhang7137ec72014-11-12 16:41:05 -0800444
Lajos Molnar87603c02014-08-20 19:25:30 -0700445 sp<ABuffer> buffer = mCSDsToSubmit.itemAt(0);
446 ALOGI("[%s] resubmitting CSD", mComponentName.c_str());
Chong Zhang7137ec72014-11-12 16:41:05 -0800447 msg->setBuffer("buffer", buffer);
Lajos Molnar87603c02014-08-20 19:25:30 -0700448 mCSDsToSubmit.removeAt(0);
Chong Zhang7137ec72014-11-12 16:41:05 -0800449 CHECK(onInputBufferFetched(msg));
Wei Jia2245fc62014-10-02 15:12:25 -0700450 return true;
451 }
452
453 while (!mPendingInputMessages.empty()) {
454 sp<AMessage> msg = *mPendingInputMessages.begin();
Chong Zhang7137ec72014-11-12 16:41:05 -0800455 if (!onInputBufferFetched(msg)) {
Wei Jia2245fc62014-10-02 15:12:25 -0700456 break;
457 }
458 mPendingInputMessages.erase(mPendingInputMessages.begin());
459 }
460
Marco Nelissen421f47c2015-03-25 14:40:32 -0700461 if (!mInputBufferIsDequeued.editItemAt(index)) {
Lajos Molnar87603c02014-08-20 19:25:30 -0700462 return true;
463 }
464
Marco Nelissen421f47c2015-03-25 14:40:32 -0700465 mDequeuedInputBuffers.push_back(index);
Chong Zhang7137ec72014-11-12 16:41:05 -0800466
467 onRequestInputBuffers();
Lajos Molnar1cd13982014-01-17 15:12:51 -0800468 return true;
469}
470
Marco Nelissen421f47c2015-03-25 14:40:32 -0700471bool NuPlayer::Decoder::handleAnOutputBuffer(
472 size_t index,
473 size_t offset,
474 size_t size,
475 int64_t timeUs,
476 int32_t flags) {
Marco Nelissen421f47c2015-03-25 14:40:32 -0700477// CHECK_LT(bufferIx, mOutputBuffers.size());
478 sp<ABuffer> buffer;
479 mCodec->getOutputBuffer(index, &buffer);
480
481 if (index >= mOutputBuffers.size()) {
482 for (size_t i = mOutputBuffers.size(); i <= index; ++i) {
483 mOutputBuffers.add();
484 }
485 }
486
487 mOutputBuffers.editItemAt(index) = buffer;
488
Chong Zhang7137ec72014-11-12 16:41:05 -0800489 buffer->setRange(offset, size);
490 buffer->meta()->clear();
491 buffer->meta()->setInt64("timeUs", timeUs);
Chong Zhang66704af2015-03-03 19:32:35 -0800492
493 bool eos = flags & MediaCodec::BUFFER_FLAG_EOS;
Chong Zhang7137ec72014-11-12 16:41:05 -0800494 // we do not expect CODECCONFIG or SYNCFRAME for decoder
495
Lajos Molnar1d15ab52015-03-04 16:46:34 -0800496 sp<AMessage> reply = new AMessage(kWhatRenderBuffer, this);
Marco Nelissen421f47c2015-03-25 14:40:32 -0700497 reply->setSize("buffer-ix", index);
Chong Zhang7137ec72014-11-12 16:41:05 -0800498 reply->setInt32("generation", mBufferGeneration);
499
Chong Zhang66704af2015-03-03 19:32:35 -0800500 if (eos) {
501 ALOGI("[%s] saw output EOS", mIsAudio ? "audio" : "video");
502
503 buffer->meta()->setInt32("eos", true);
504 reply->setInt32("eos", true);
505 } else if (mSkipRenderingUntilMediaTimeUs >= 0) {
Chong Zhang7137ec72014-11-12 16:41:05 -0800506 if (timeUs < mSkipRenderingUntilMediaTimeUs) {
507 ALOGV("[%s] dropping buffer at time %lld as requested.",
508 mComponentName.c_str(), (long long)timeUs);
509
510 reply->post();
511 return true;
512 }
513
514 mSkipRenderingUntilMediaTimeUs = -1;
515 }
516
Chong Zhangf8d71772014-11-26 15:08:34 -0800517 // wait until 1st frame comes out to signal resume complete
518 notifyResumeCompleteIfNecessary();
519
Chong Zhang7137ec72014-11-12 16:41:05 -0800520 if (mRenderer != NULL) {
521 // send the buffer to renderer.
522 mRenderer->queueBuffer(mIsAudio, buffer, reply);
Chong Zhang66704af2015-03-03 19:32:35 -0800523 if (eos && !isDiscontinuityPending()) {
Chong Zhang7137ec72014-11-12 16:41:05 -0800524 mRenderer->queueEOS(mIsAudio, ERROR_END_OF_STREAM);
525 }
526 }
527
528 return true;
529}
530
Marco Nelissen421f47c2015-03-25 14:40:32 -0700531void NuPlayer::Decoder::handleOutputFormatChange(const sp<AMessage> &format) {
532 if (!mIsAudio) {
533 sp<AMessage> notify = mNotify->dup();
534 notify->setInt32("what", kWhatVideoSizeChanged);
535 notify->setMessage("format", format);
536 notify->post();
537 } else if (mRenderer != NULL) {
538 uint32_t flags;
539 int64_t durationUs;
540 bool hasVideo = (mSource->getFormat(false /* audio */) != NULL);
541 if (!hasVideo &&
542 mSource->getDuration(&durationUs) == OK &&
543 durationUs > AUDIO_SINK_MIN_DEEP_BUFFER_DURATION_US) {
544 flags = AUDIO_OUTPUT_FLAG_DEEP_BUFFER;
545 } else {
546 flags = AUDIO_OUTPUT_FLAG_NONE;
547 }
548
549 mRenderer->openAudioSink(
550 format, false /* offloadOnly */, hasVideo, flags, NULL /* isOffloaed */);
551 }
552}
553
Chong Zhang7137ec72014-11-12 16:41:05 -0800554void NuPlayer::Decoder::releaseAndResetMediaBuffers() {
555 for (size_t i = 0; i < mMediaBuffers.size(); i++) {
556 if (mMediaBuffers[i] != NULL) {
557 mMediaBuffers[i]->release();
558 mMediaBuffers.editItemAt(i) = NULL;
559 }
560 }
561 mMediaBuffers.resize(mInputBuffers.size());
562 for (size_t i = 0; i < mMediaBuffers.size(); i++) {
563 mMediaBuffers.editItemAt(i) = NULL;
564 }
565 mInputBufferIsDequeued.clear();
566 mInputBufferIsDequeued.resize(mInputBuffers.size());
567 for (size_t i = 0; i < mInputBufferIsDequeued.size(); i++) {
568 mInputBufferIsDequeued.editItemAt(i) = false;
569 }
570
571 mPendingInputMessages.clear();
572 mDequeuedInputBuffers.clear();
573 mSkipRenderingUntilMediaTimeUs = -1;
574}
575
576void NuPlayer::Decoder::requestCodecNotification() {
Chong Zhang7137ec72014-11-12 16:41:05 -0800577 if (mCodec != NULL) {
Lajos Molnar1d15ab52015-03-04 16:46:34 -0800578 sp<AMessage> reply = new AMessage(kWhatCodecNotify, this);
Chong Zhang7137ec72014-11-12 16:41:05 -0800579 reply->setInt32("generation", mBufferGeneration);
580 mCodec->requestActivityNotification(reply);
581 }
582}
583
584bool NuPlayer::Decoder::isStaleReply(const sp<AMessage> &msg) {
585 int32_t generation;
586 CHECK(msg->findInt32("generation", &generation));
587 return generation != mBufferGeneration;
588}
589
590status_t NuPlayer::Decoder::fetchInputData(sp<AMessage> &reply) {
591 sp<ABuffer> accessUnit;
592 bool dropAccessUnit;
593 do {
594 status_t err = mSource->dequeueAccessUnit(mIsAudio, &accessUnit);
595
596 if (err == -EWOULDBLOCK) {
597 return err;
598 } else if (err != OK) {
599 if (err == INFO_DISCONTINUITY) {
600 int32_t type;
601 CHECK(accessUnit->meta()->findInt32("discontinuity", &type));
602
603 bool formatChange =
604 (mIsAudio &&
605 (type & ATSParser::DISCONTINUITY_AUDIO_FORMAT))
606 || (!mIsAudio &&
607 (type & ATSParser::DISCONTINUITY_VIDEO_FORMAT));
608
609 bool timeChange = (type & ATSParser::DISCONTINUITY_TIME) != 0;
610
611 ALOGI("%s discontinuity (format=%d, time=%d)",
612 mIsAudio ? "audio" : "video", formatChange, timeChange);
613
614 bool seamlessFormatChange = false;
615 sp<AMessage> newFormat = mSource->getFormat(mIsAudio);
616 if (formatChange) {
617 seamlessFormatChange =
618 supportsSeamlessFormatChange(newFormat);
619 // treat seamless format change separately
620 formatChange = !seamlessFormatChange;
621 }
622
Chong Zhang66704af2015-03-03 19:32:35 -0800623 // For format or time change, return EOS to queue EOS input,
624 // then wait for EOS on output.
Chong Zhang7137ec72014-11-12 16:41:05 -0800625 if (formatChange /* not seamless */) {
Chong Zhang7137ec72014-11-12 16:41:05 -0800626 mFormatChangePending = true;
Chong Zhang66704af2015-03-03 19:32:35 -0800627 err = ERROR_END_OF_STREAM;
Chong Zhang7137ec72014-11-12 16:41:05 -0800628 } else if (timeChange) {
Chong Zhang7137ec72014-11-12 16:41:05 -0800629 rememberCodecSpecificData(newFormat);
Chong Zhang66704af2015-03-03 19:32:35 -0800630 mTimeChangePending = true;
631 err = ERROR_END_OF_STREAM;
Chong Zhang7137ec72014-11-12 16:41:05 -0800632 } else if (seamlessFormatChange) {
633 // reuse existing decoder and don't flush
634 rememberCodecSpecificData(newFormat);
Chong Zhang66704af2015-03-03 19:32:35 -0800635 continue;
Chong Zhang7137ec72014-11-12 16:41:05 -0800636 } else {
637 // This stream is unaffected by the discontinuity
638 return -EWOULDBLOCK;
639 }
640 }
641
Chong Zhang66704af2015-03-03 19:32:35 -0800642 // reply should only be returned without a buffer set
643 // when there is an error (including EOS)
644 CHECK(err != OK);
645
Chong Zhang7137ec72014-11-12 16:41:05 -0800646 reply->setInt32("err", err);
Chong Zhang66704af2015-03-03 19:32:35 -0800647 return ERROR_END_OF_STREAM;
Chong Zhang7137ec72014-11-12 16:41:05 -0800648 }
649
650 if (!mIsAudio) {
651 ++mNumFramesTotal;
652 }
653
654 dropAccessUnit = false;
655 if (!mIsAudio
656 && !mIsSecure
657 && mRenderer->getVideoLateByUs() > 100000ll
658 && mIsVideoAVC
659 && !IsAVCReferenceFrame(accessUnit)) {
660 dropAccessUnit = true;
661 ++mNumFramesDropped;
662 }
663 } while (dropAccessUnit);
664
665 // ALOGV("returned a valid buffer of %s data", mIsAudio ? "mIsAudio" : "video");
666#if 0
667 int64_t mediaTimeUs;
668 CHECK(accessUnit->meta()->findInt64("timeUs", &mediaTimeUs));
Chong Zhang5abbd3d2015-04-20 16:03:00 -0700669 ALOGV("[%s] feeding input buffer at media time %.3f",
Chong Zhang7137ec72014-11-12 16:41:05 -0800670 mIsAudio ? "audio" : "video",
671 mediaTimeUs / 1E6);
672#endif
673
674 if (mCCDecoder != NULL) {
675 mCCDecoder->decode(accessUnit);
676 }
677
678 reply->setBuffer("buffer", accessUnit);
679
680 return OK;
681}
682
683bool NuPlayer::Decoder::onInputBufferFetched(const sp<AMessage> &msg) {
Lajos Molnar1cd13982014-01-17 15:12:51 -0800684 size_t bufferIx;
685 CHECK(msg->findSize("buffer-ix", &bufferIx));
686 CHECK_LT(bufferIx, mInputBuffers.size());
687 sp<ABuffer> codecBuffer = mInputBuffers[bufferIx];
688
689 sp<ABuffer> buffer;
690 bool hasBuffer = msg->findBuffer("buffer", &buffer);
Lajos Molnar09524832014-07-17 14:29:51 -0700691
692 // handle widevine classic source - that fills an arbitrary input buffer
693 MediaBuffer *mediaBuffer = NULL;
Wei Jia96e92b52014-09-18 17:36:20 -0700694 if (hasBuffer) {
695 mediaBuffer = (MediaBuffer *)(buffer->getMediaBufferBase());
696 if (mediaBuffer != NULL) {
Lajos Molnar09524832014-07-17 14:29:51 -0700697 // likely filled another buffer than we requested: adjust buffer index
698 size_t ix;
699 for (ix = 0; ix < mInputBuffers.size(); ix++) {
700 const sp<ABuffer> &buf = mInputBuffers[ix];
701 if (buf->data() == mediaBuffer->data()) {
702 // all input buffers are dequeued on start, hence the check
Wei Jia2245fc62014-10-02 15:12:25 -0700703 if (!mInputBufferIsDequeued[ix]) {
704 ALOGV("[%s] received MediaBuffer for #%zu instead of #%zu",
705 mComponentName.c_str(), ix, bufferIx);
706 mediaBuffer->release();
707 return false;
708 }
Lajos Molnar09524832014-07-17 14:29:51 -0700709
710 // TRICKY: need buffer for the metadata, so instead, set
711 // codecBuffer to the same (though incorrect) buffer to
712 // avoid a memcpy into the codecBuffer
713 codecBuffer = buffer;
714 codecBuffer->setRange(
715 mediaBuffer->range_offset(),
716 mediaBuffer->range_length());
717 bufferIx = ix;
718 break;
719 }
720 }
721 CHECK(ix < mInputBuffers.size());
722 }
723 }
724
Lajos Molnar1cd13982014-01-17 15:12:51 -0800725 if (buffer == NULL /* includes !hasBuffer */) {
726 int32_t streamErr = ERROR_END_OF_STREAM;
727 CHECK(msg->findInt32("err", &streamErr) || !hasBuffer);
728
Chong Zhang66704af2015-03-03 19:32:35 -0800729 CHECK(streamErr != OK);
Lajos Molnar1cd13982014-01-17 15:12:51 -0800730
731 // attempt to queue EOS
732 status_t err = mCodec->queueInputBuffer(
733 bufferIx,
734 0,
735 0,
736 0,
737 MediaCodec::BUFFER_FLAG_EOS);
Andy Hungcf31f1e2014-09-23 14:59:01 -0700738 if (err == OK) {
739 mInputBufferIsDequeued.editItemAt(bufferIx) = false;
740 } else if (streamErr == ERROR_END_OF_STREAM) {
Lajos Molnar1cd13982014-01-17 15:12:51 -0800741 streamErr = err;
742 // err will not be ERROR_END_OF_STREAM
743 }
744
745 if (streamErr != ERROR_END_OF_STREAM) {
Andy Hungcf31f1e2014-09-23 14:59:01 -0700746 ALOGE("Stream error for %s (err=%d), EOS %s queued",
747 mComponentName.c_str(),
748 streamErr,
749 err == OK ? "successfully" : "unsuccessfully");
Lajos Molnar1cd13982014-01-17 15:12:51 -0800750 handleError(streamErr);
751 }
752 } else {
Wei Jiac6cfd702014-11-11 16:33:20 -0800753 sp<AMessage> extra;
754 if (buffer->meta()->findMessage("extra", &extra) && extra != NULL) {
755 int64_t resumeAtMediaTimeUs;
756 if (extra->findInt64(
757 "resume-at-mediaTimeUs", &resumeAtMediaTimeUs)) {
758 ALOGI("[%s] suppressing rendering until %lld us",
759 mComponentName.c_str(), (long long)resumeAtMediaTimeUs);
760 mSkipRenderingUntilMediaTimeUs = resumeAtMediaTimeUs;
761 }
762 }
763
Lajos Molnar1cd13982014-01-17 15:12:51 -0800764 int64_t timeUs = 0;
765 uint32_t flags = 0;
766 CHECK(buffer->meta()->findInt64("timeUs", &timeUs));
767
Lajos Molnar87603c02014-08-20 19:25:30 -0700768 int32_t eos, csd;
769 // we do not expect SYNCFRAME for decoder
Lajos Molnar1cd13982014-01-17 15:12:51 -0800770 if (buffer->meta()->findInt32("eos", &eos) && eos) {
771 flags |= MediaCodec::BUFFER_FLAG_EOS;
Lajos Molnar87603c02014-08-20 19:25:30 -0700772 } else if (buffer->meta()->findInt32("csd", &csd) && csd) {
773 flags |= MediaCodec::BUFFER_FLAG_CODECCONFIG;
Lajos Molnar1cd13982014-01-17 15:12:51 -0800774 }
775
776 // copy into codec buffer
777 if (buffer != codecBuffer) {
778 CHECK_LE(buffer->size(), codecBuffer->capacity());
779 codecBuffer->setRange(0, buffer->size());
780 memcpy(codecBuffer->data(), buffer->data(), buffer->size());
781 }
782
783 status_t err = mCodec->queueInputBuffer(
784 bufferIx,
785 codecBuffer->offset(),
786 codecBuffer->size(),
787 timeUs,
788 flags);
789 if (err != OK) {
Andy Hungcf31f1e2014-09-23 14:59:01 -0700790 if (mediaBuffer != NULL) {
791 mediaBuffer->release();
792 }
Lajos Molnar1cd13982014-01-17 15:12:51 -0800793 ALOGE("Failed to queue input buffer for %s (err=%d)",
794 mComponentName.c_str(), err);
795 handleError(err);
Andy Hungcf31f1e2014-09-23 14:59:01 -0700796 } else {
797 mInputBufferIsDequeued.editItemAt(bufferIx) = false;
798 if (mediaBuffer != NULL) {
799 CHECK(mMediaBuffers[bufferIx] == NULL);
800 mMediaBuffers.editItemAt(bufferIx) = mediaBuffer;
801 }
Lajos Molnar09524832014-07-17 14:29:51 -0700802 }
Lajos Molnar1cd13982014-01-17 15:12:51 -0800803 }
Wei Jia2245fc62014-10-02 15:12:25 -0700804 return true;
Lajos Molnar1cd13982014-01-17 15:12:51 -0800805}
806
Lajos Molnar1cd13982014-01-17 15:12:51 -0800807void NuPlayer::Decoder::onRenderBuffer(const sp<AMessage> &msg) {
808 status_t err;
809 int32_t render;
810 size_t bufferIx;
Chong Zhang66704af2015-03-03 19:32:35 -0800811 int32_t eos;
Lajos Molnar1cd13982014-01-17 15:12:51 -0800812 CHECK(msg->findSize("buffer-ix", &bufferIx));
Wei Jiac6cfd702014-11-11 16:33:20 -0800813
Chong Zhang7137ec72014-11-12 16:41:05 -0800814 if (!mIsAudio) {
Wei Jiac6cfd702014-11-11 16:33:20 -0800815 int64_t timeUs;
816 sp<ABuffer> buffer = mOutputBuffers[bufferIx];
817 buffer->meta()->findInt64("timeUs", &timeUs);
Chong Zhang7137ec72014-11-12 16:41:05 -0800818
819 if (mCCDecoder != NULL && mCCDecoder->isSelected()) {
820 mCCDecoder->display(timeUs);
821 }
Wei Jiac6cfd702014-11-11 16:33:20 -0800822 }
823
Lajos Molnar1cd13982014-01-17 15:12:51 -0800824 if (msg->findInt32("render", &render) && render) {
Lajos Molnardc43dfa2014-05-07 15:33:04 -0700825 int64_t timestampNs;
826 CHECK(msg->findInt64("timestampNs", &timestampNs));
827 err = mCodec->renderOutputBufferAndRelease(bufferIx, timestampNs);
Lajos Molnar1cd13982014-01-17 15:12:51 -0800828 } else {
829 err = mCodec->releaseOutputBuffer(bufferIx);
830 }
831 if (err != OK) {
832 ALOGE("failed to release output buffer for %s (err=%d)",
833 mComponentName.c_str(), err);
834 handleError(err);
835 }
Chong Zhang66704af2015-03-03 19:32:35 -0800836 if (msg->findInt32("eos", &eos) && eos
837 && isDiscontinuityPending()) {
838 finishHandleDiscontinuity(true /* flushOnTimeChange */);
839 }
840}
841
842bool NuPlayer::Decoder::isDiscontinuityPending() const {
843 return mFormatChangePending || mTimeChangePending;
844}
845
846void NuPlayer::Decoder::finishHandleDiscontinuity(bool flushOnTimeChange) {
847 ALOGV("finishHandleDiscontinuity: format %d, time %d, flush %d",
848 mFormatChangePending, mTimeChangePending, flushOnTimeChange);
849
850 // If we have format change, pause and wait to be killed;
851 // If we have time change only, flush and restart fetching.
852
853 if (mFormatChangePending) {
854 mPaused = true;
855 } else if (mTimeChangePending) {
856 if (flushOnTimeChange) {
Marco Nelissen421f47c2015-03-25 14:40:32 -0700857 doFlush(false /* notifyComplete */);
858 signalResume(false /* notifyComplete */);
Chong Zhang66704af2015-03-03 19:32:35 -0800859 }
Chong Zhang66704af2015-03-03 19:32:35 -0800860 }
861
862 // Notify NuPlayer to either shutdown decoder, or rescan sources
863 sp<AMessage> msg = mNotify->dup();
864 msg->setInt32("what", kWhatInputDiscontinuity);
865 msg->setInt32("formatChange", mFormatChangePending);
866 msg->post();
867
868 mFormatChangePending = false;
869 mTimeChangePending = false;
Lajos Molnar1cd13982014-01-17 15:12:51 -0800870}
871
Chong Zhang7137ec72014-11-12 16:41:05 -0800872bool NuPlayer::Decoder::supportsSeamlessAudioFormatChange(
873 const sp<AMessage> &targetFormat) const {
Robert Shih6d0a94e2014-01-23 16:18:22 -0800874 if (targetFormat == NULL) {
875 return true;
876 }
877
878 AString mime;
879 if (!targetFormat->findString("mime", &mime)) {
880 return false;
881 }
882
883 if (!strcasecmp(mime.c_str(), MEDIA_MIMETYPE_AUDIO_AAC)) {
884 // field-by-field comparison
885 const char * keys[] = { "channel-count", "sample-rate", "is-adts" };
886 for (unsigned int i = 0; i < sizeof(keys) / sizeof(keys[0]); i++) {
887 int32_t oldVal, newVal;
joakim johansson7abbd4c2015-01-30 14:16:03 +0100888 if (!mInputFormat->findInt32(keys[i], &oldVal) ||
Lajos Molnar1cd13982014-01-17 15:12:51 -0800889 !targetFormat->findInt32(keys[i], &newVal) ||
890 oldVal != newVal) {
Robert Shih6d0a94e2014-01-23 16:18:22 -0800891 return false;
892 }
893 }
894
895 sp<ABuffer> oldBuf, newBuf;
joakim johansson7abbd4c2015-01-30 14:16:03 +0100896 if (mInputFormat->findBuffer("csd-0", &oldBuf) &&
Lajos Molnar1cd13982014-01-17 15:12:51 -0800897 targetFormat->findBuffer("csd-0", &newBuf)) {
Robert Shih6d0a94e2014-01-23 16:18:22 -0800898 if (oldBuf->size() != newBuf->size()) {
899 return false;
900 }
901 return !memcmp(oldBuf->data(), newBuf->data(), oldBuf->size());
902 }
903 }
904 return false;
905}
906
907bool NuPlayer::Decoder::supportsSeamlessFormatChange(const sp<AMessage> &targetFormat) const {
joakim johansson7abbd4c2015-01-30 14:16:03 +0100908 if (mInputFormat == NULL) {
Robert Shih6d0a94e2014-01-23 16:18:22 -0800909 return false;
910 }
911
912 if (targetFormat == NULL) {
913 return true;
914 }
915
916 AString oldMime, newMime;
joakim johansson7abbd4c2015-01-30 14:16:03 +0100917 if (!mInputFormat->findString("mime", &oldMime)
Robert Shih6d0a94e2014-01-23 16:18:22 -0800918 || !targetFormat->findString("mime", &newMime)
919 || !(oldMime == newMime)) {
920 return false;
921 }
922
923 bool audio = !strncasecmp(oldMime.c_str(), "audio/", strlen("audio/"));
924 bool seamless;
925 if (audio) {
926 seamless = supportsSeamlessAudioFormatChange(targetFormat);
927 } else {
Lajos Molnar1cd13982014-01-17 15:12:51 -0800928 int32_t isAdaptive;
929 seamless = (mCodec != NULL &&
930 mInputFormat->findInt32("adaptive-playback", &isAdaptive) &&
931 isAdaptive);
Robert Shih6d0a94e2014-01-23 16:18:22 -0800932 }
933
934 ALOGV("%s seamless support for %s", seamless ? "yes" : "no", oldMime.c_str());
935 return seamless;
936}
937
Chong Zhang7137ec72014-11-12 16:41:05 -0800938void NuPlayer::Decoder::rememberCodecSpecificData(const sp<AMessage> &format) {
939 if (format == NULL) {
Chong Zhangb86e68f2014-08-01 13:46:53 -0700940 return;
941 }
Chong Zhang7137ec72014-11-12 16:41:05 -0800942 mCSDsForCurrentFormat.clear();
943 for (int32_t i = 0; ; ++i) {
944 AString tag = "csd-";
945 tag.append(i);
946 sp<ABuffer> buffer;
947 if (!format->findBuffer(tag.c_str(), &buffer)) {
948 break;
949 }
950 mCSDsForCurrentFormat.push(buffer);
Chong Zhanga7fa1d92014-06-11 14:49:23 -0700951 }
Chong Zhangb86e68f2014-08-01 13:46:53 -0700952}
953
Chong Zhangf8d71772014-11-26 15:08:34 -0800954void NuPlayer::Decoder::notifyResumeCompleteIfNecessary() {
955 if (mResumePending) {
956 mResumePending = false;
957
958 sp<AMessage> notify = mNotify->dup();
959 notify->setInt32("what", kWhatResumeCompleted);
960 notify->post();
961 }
962}
963
Andreas Huberf9334412010-12-15 15:17:42 -0800964} // namespace android
965