blob: 65e80c3ddc68e690cfc450180e72c5e977e7ee67 [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
Chong Zhang7137ec72014-11-12 16:41:05 -0800255void NuPlayer::Decoder::onSetRenderer(const sp<Renderer> &renderer) {
256 bool hadNoRenderer = (mRenderer == NULL);
257 mRenderer = renderer;
258 if (hadNoRenderer && mRenderer != NULL) {
Lajos Molnare6109e22015-04-10 17:18:22 -0700259 // this means that the widevine legacy source is ready
260 onRequestInputBuffers();
Chong Zhang7137ec72014-11-12 16:41:05 -0800261 }
262}
263
264void NuPlayer::Decoder::onGetInputBuffers(
265 Vector<sp<ABuffer> > *dstBuffers) {
Lajos Molnare6109e22015-04-10 17:18:22 -0700266 CHECK_EQ((status_t)OK, mCodec->getWidevineLegacyBuffers(dstBuffers));
Chong Zhang7137ec72014-11-12 16:41:05 -0800267}
268
Chong Zhangf8d71772014-11-26 15:08:34 -0800269void NuPlayer::Decoder::onResume(bool notifyComplete) {
Chong Zhang7137ec72014-11-12 16:41:05 -0800270 mPaused = false;
Chong Zhangf8d71772014-11-26 15:08:34 -0800271
272 if (notifyComplete) {
273 mResumePending = true;
274 }
Marco Nelissen421f47c2015-03-25 14:40:32 -0700275 mCodec->start();
Chong Zhang7137ec72014-11-12 16:41:05 -0800276}
277
Chong Zhang66704af2015-03-03 19:32:35 -0800278void NuPlayer::Decoder::doFlush(bool notifyComplete) {
Chong Zhang7137ec72014-11-12 16:41:05 -0800279 if (mCCDecoder != NULL) {
280 mCCDecoder->flush();
281 }
282
283 if (mRenderer != NULL) {
284 mRenderer->flush(mIsAudio, notifyComplete);
285 mRenderer->signalTimeDiscontinuity();
286 }
287
288 status_t err = OK;
289 if (mCodec != NULL) {
290 err = mCodec->flush();
291 mCSDsToSubmit = mCSDsForCurrentFormat; // copy operator
292 ++mBufferGeneration;
293 }
294
295 if (err != OK) {
296 ALOGE("failed to flush %s (err=%d)", mComponentName.c_str(), err);
297 handleError(err);
298 // finish with posting kWhatFlushCompleted.
299 // we attempt to release the buffers even if flush fails.
300 }
301 releaseAndResetMediaBuffers();
Marco Nelissen421f47c2015-03-25 14:40:32 -0700302 mPaused = true;
Chong Zhang66704af2015-03-03 19:32:35 -0800303}
Chong Zhang7137ec72014-11-12 16:41:05 -0800304
Marco Nelissen421f47c2015-03-25 14:40:32 -0700305
Chong Zhang66704af2015-03-03 19:32:35 -0800306void NuPlayer::Decoder::onFlush() {
307 doFlush(true);
308
309 if (isDiscontinuityPending()) {
310 // This could happen if the client starts seeking/shutdown
311 // after we queued an EOS for discontinuities.
312 // We can consider discontinuity handled.
313 finishHandleDiscontinuity(false /* flushOnTimeChange */);
Chong Zhang7137ec72014-11-12 16:41:05 -0800314 }
Chong Zhang66704af2015-03-03 19:32:35 -0800315
316 sp<AMessage> notify = mNotify->dup();
317 notify->setInt32("what", kWhatFlushCompleted);
318 notify->post();
Chong Zhang7137ec72014-11-12 16:41:05 -0800319}
320
321void NuPlayer::Decoder::onShutdown(bool notifyComplete) {
322 status_t err = OK;
Chong Zhangf8d71772014-11-26 15:08:34 -0800323
324 // if there is a pending resume request, notify complete now
325 notifyResumeCompleteIfNecessary();
326
Chong Zhang7137ec72014-11-12 16:41:05 -0800327 if (mCodec != NULL) {
328 err = mCodec->release();
329 mCodec = NULL;
330 ++mBufferGeneration;
331
332 if (mNativeWindow != NULL) {
333 // reconnect to surface as MediaCodec disconnected from it
334 status_t error =
335 native_window_api_connect(
336 mNativeWindow->getNativeWindow().get(),
337 NATIVE_WINDOW_API_MEDIA);
338 ALOGW_IF(error != NO_ERROR,
339 "[%s] failed to connect to native window, error=%d",
340 mComponentName.c_str(), error);
341 }
342 mComponentName = "decoder";
343 }
344
345 releaseAndResetMediaBuffers();
346
347 if (err != OK) {
348 ALOGE("failed to release %s (err=%d)", mComponentName.c_str(), err);
349 handleError(err);
350 // finish with posting kWhatShutdownCompleted.
351 }
352
353 if (notifyComplete) {
354 sp<AMessage> notify = mNotify->dup();
355 notify->setInt32("what", kWhatShutdownCompleted);
356 notify->post();
357 mPaused = true;
358 }
359}
360
Chong Zhang3b032b32015-04-17 15:49:06 -0700361/*
362 * returns true if we should request more data
363 */
364bool NuPlayer::Decoder::doRequestBuffers() {
Lajos Molnare6109e22015-04-10 17:18:22 -0700365 // mRenderer is only NULL if we have a legacy widevine source that
366 // is not yet ready. In this case we must not fetch input.
367 if (isDiscontinuityPending() || mRenderer == NULL) {
Chong Zhang3b032b32015-04-17 15:49:06 -0700368 return false;
Chong Zhang7137ec72014-11-12 16:41:05 -0800369 }
370 status_t err = OK;
Chong Zhang66704af2015-03-03 19:32:35 -0800371 while (err == OK && !mDequeuedInputBuffers.empty()) {
Chong Zhang7137ec72014-11-12 16:41:05 -0800372 size_t bufferIx = *mDequeuedInputBuffers.begin();
373 sp<AMessage> msg = new AMessage();
374 msg->setSize("buffer-ix", bufferIx);
375 err = fetchInputData(msg);
Chong Zhang66704af2015-03-03 19:32:35 -0800376 if (err != OK && err != ERROR_END_OF_STREAM) {
377 // if EOS, need to queue EOS buffer
Chong Zhang7137ec72014-11-12 16:41:05 -0800378 break;
379 }
380 mDequeuedInputBuffers.erase(mDequeuedInputBuffers.begin());
381
382 if (!mPendingInputMessages.empty()
383 || !onInputBufferFetched(msg)) {
384 mPendingInputMessages.push_back(msg);
Lajos Molnar09524832014-07-17 14:29:51 -0700385 }
386 }
Chong Zhang7137ec72014-11-12 16:41:05 -0800387
Chong Zhang3b032b32015-04-17 15:49:06 -0700388 return err == -EWOULDBLOCK
389 && mSource->feedMoreTSData() == OK;
Lajos Molnar09524832014-07-17 14:29:51 -0700390}
391
Marco Nelissen421f47c2015-03-25 14:40:32 -0700392void NuPlayer::Decoder::handleError(int32_t err)
393{
394 // We cannot immediately release the codec due to buffers still outstanding
395 // in the renderer. We signal to the player the error so it can shutdown/release the
396 // decoder after flushing and increment the generation to discard unnecessary messages.
397
398 ++mBufferGeneration;
399
400 sp<AMessage> notify = mNotify->dup();
401 notify->setInt32("what", kWhatError);
402 notify->setInt32("err", err);
403 notify->post();
404}
405
406bool NuPlayer::Decoder::handleAnInputBuffer(size_t index) {
Chong Zhang66704af2015-03-03 19:32:35 -0800407 if (isDiscontinuityPending()) {
Chong Zhang7137ec72014-11-12 16:41:05 -0800408 return false;
409 }
Marco Nelissen421f47c2015-03-25 14:40:32 -0700410
411 sp<ABuffer> buffer;
412 mCodec->getInputBuffer(index, &buffer);
413
414 if (index >= mInputBuffers.size()) {
415 for (size_t i = mInputBuffers.size(); i <= index; ++i) {
416 mInputBuffers.add();
417 mMediaBuffers.add();
418 mInputBufferIsDequeued.add();
419 mMediaBuffers.editItemAt(i) = NULL;
420 mInputBufferIsDequeued.editItemAt(i) = false;
Lajos Molnar1cd13982014-01-17 15:12:51 -0800421 }
Andreas Huber078cfcf2011-09-15 12:25:04 -0700422 }
Marco Nelissen421f47c2015-03-25 14:40:32 -0700423 mInputBuffers.editItemAt(index) = buffer;
Andreas Huber078cfcf2011-09-15 12:25:04 -0700424
Marco Nelissen421f47c2015-03-25 14:40:32 -0700425 //CHECK_LT(bufferIx, mInputBuffers.size());
Andreas Huberf9334412010-12-15 15:17:42 -0800426
Marco Nelissen421f47c2015-03-25 14:40:32 -0700427 if (mMediaBuffers[index] != NULL) {
428 mMediaBuffers[index]->release();
429 mMediaBuffers.editItemAt(index) = NULL;
Lajos Molnar09524832014-07-17 14:29:51 -0700430 }
Marco Nelissen421f47c2015-03-25 14:40:32 -0700431 mInputBufferIsDequeued.editItemAt(index) = true;
Lajos Molnar09524832014-07-17 14:29:51 -0700432
Lajos Molnar87603c02014-08-20 19:25:30 -0700433 if (!mCSDsToSubmit.isEmpty()) {
Chong Zhang7137ec72014-11-12 16:41:05 -0800434 sp<AMessage> msg = new AMessage();
Marco Nelissen421f47c2015-03-25 14:40:32 -0700435 msg->setSize("buffer-ix", index);
Chong Zhang7137ec72014-11-12 16:41:05 -0800436
Lajos Molnar87603c02014-08-20 19:25:30 -0700437 sp<ABuffer> buffer = mCSDsToSubmit.itemAt(0);
438 ALOGI("[%s] resubmitting CSD", mComponentName.c_str());
Chong Zhang7137ec72014-11-12 16:41:05 -0800439 msg->setBuffer("buffer", buffer);
Lajos Molnar87603c02014-08-20 19:25:30 -0700440 mCSDsToSubmit.removeAt(0);
Chong Zhang7137ec72014-11-12 16:41:05 -0800441 CHECK(onInputBufferFetched(msg));
Wei Jia2245fc62014-10-02 15:12:25 -0700442 return true;
443 }
444
445 while (!mPendingInputMessages.empty()) {
446 sp<AMessage> msg = *mPendingInputMessages.begin();
Chong Zhang7137ec72014-11-12 16:41:05 -0800447 if (!onInputBufferFetched(msg)) {
Wei Jia2245fc62014-10-02 15:12:25 -0700448 break;
449 }
450 mPendingInputMessages.erase(mPendingInputMessages.begin());
451 }
452
Marco Nelissen421f47c2015-03-25 14:40:32 -0700453 if (!mInputBufferIsDequeued.editItemAt(index)) {
Lajos Molnar87603c02014-08-20 19:25:30 -0700454 return true;
455 }
456
Marco Nelissen421f47c2015-03-25 14:40:32 -0700457 mDequeuedInputBuffers.push_back(index);
Chong Zhang7137ec72014-11-12 16:41:05 -0800458
459 onRequestInputBuffers();
Lajos Molnar1cd13982014-01-17 15:12:51 -0800460 return true;
461}
462
Marco Nelissen421f47c2015-03-25 14:40:32 -0700463bool NuPlayer::Decoder::handleAnOutputBuffer(
464 size_t index,
465 size_t offset,
466 size_t size,
467 int64_t timeUs,
468 int32_t flags) {
Marco Nelissen421f47c2015-03-25 14:40:32 -0700469// CHECK_LT(bufferIx, mOutputBuffers.size());
470 sp<ABuffer> buffer;
471 mCodec->getOutputBuffer(index, &buffer);
472
473 if (index >= mOutputBuffers.size()) {
474 for (size_t i = mOutputBuffers.size(); i <= index; ++i) {
475 mOutputBuffers.add();
476 }
477 }
478
479 mOutputBuffers.editItemAt(index) = buffer;
480
Chong Zhang7137ec72014-11-12 16:41:05 -0800481 buffer->setRange(offset, size);
482 buffer->meta()->clear();
483 buffer->meta()->setInt64("timeUs", timeUs);
Chong Zhang66704af2015-03-03 19:32:35 -0800484
485 bool eos = flags & MediaCodec::BUFFER_FLAG_EOS;
Chong Zhang7137ec72014-11-12 16:41:05 -0800486 // we do not expect CODECCONFIG or SYNCFRAME for decoder
487
Lajos Molnar1d15ab52015-03-04 16:46:34 -0800488 sp<AMessage> reply = new AMessage(kWhatRenderBuffer, this);
Marco Nelissen421f47c2015-03-25 14:40:32 -0700489 reply->setSize("buffer-ix", index);
Chong Zhang7137ec72014-11-12 16:41:05 -0800490 reply->setInt32("generation", mBufferGeneration);
491
Chong Zhang66704af2015-03-03 19:32:35 -0800492 if (eos) {
493 ALOGI("[%s] saw output EOS", mIsAudio ? "audio" : "video");
494
495 buffer->meta()->setInt32("eos", true);
496 reply->setInt32("eos", true);
497 } else if (mSkipRenderingUntilMediaTimeUs >= 0) {
Chong Zhang7137ec72014-11-12 16:41:05 -0800498 if (timeUs < mSkipRenderingUntilMediaTimeUs) {
499 ALOGV("[%s] dropping buffer at time %lld as requested.",
500 mComponentName.c_str(), (long long)timeUs);
501
502 reply->post();
503 return true;
504 }
505
506 mSkipRenderingUntilMediaTimeUs = -1;
507 }
508
Chong Zhangf8d71772014-11-26 15:08:34 -0800509 // wait until 1st frame comes out to signal resume complete
510 notifyResumeCompleteIfNecessary();
511
Chong Zhang7137ec72014-11-12 16:41:05 -0800512 if (mRenderer != NULL) {
513 // send the buffer to renderer.
514 mRenderer->queueBuffer(mIsAudio, buffer, reply);
Chong Zhang66704af2015-03-03 19:32:35 -0800515 if (eos && !isDiscontinuityPending()) {
Chong Zhang7137ec72014-11-12 16:41:05 -0800516 mRenderer->queueEOS(mIsAudio, ERROR_END_OF_STREAM);
517 }
518 }
519
520 return true;
521}
522
Marco Nelissen421f47c2015-03-25 14:40:32 -0700523void NuPlayer::Decoder::handleOutputFormatChange(const sp<AMessage> &format) {
524 if (!mIsAudio) {
525 sp<AMessage> notify = mNotify->dup();
526 notify->setInt32("what", kWhatVideoSizeChanged);
527 notify->setMessage("format", format);
528 notify->post();
529 } else if (mRenderer != NULL) {
530 uint32_t flags;
531 int64_t durationUs;
532 bool hasVideo = (mSource->getFormat(false /* audio */) != NULL);
533 if (!hasVideo &&
534 mSource->getDuration(&durationUs) == OK &&
535 durationUs > AUDIO_SINK_MIN_DEEP_BUFFER_DURATION_US) {
536 flags = AUDIO_OUTPUT_FLAG_DEEP_BUFFER;
537 } else {
538 flags = AUDIO_OUTPUT_FLAG_NONE;
539 }
540
541 mRenderer->openAudioSink(
542 format, false /* offloadOnly */, hasVideo, flags, NULL /* isOffloaed */);
543 }
544}
545
Chong Zhang7137ec72014-11-12 16:41:05 -0800546void NuPlayer::Decoder::releaseAndResetMediaBuffers() {
547 for (size_t i = 0; i < mMediaBuffers.size(); i++) {
548 if (mMediaBuffers[i] != NULL) {
549 mMediaBuffers[i]->release();
550 mMediaBuffers.editItemAt(i) = NULL;
551 }
552 }
553 mMediaBuffers.resize(mInputBuffers.size());
554 for (size_t i = 0; i < mMediaBuffers.size(); i++) {
555 mMediaBuffers.editItemAt(i) = NULL;
556 }
557 mInputBufferIsDequeued.clear();
558 mInputBufferIsDequeued.resize(mInputBuffers.size());
559 for (size_t i = 0; i < mInputBufferIsDequeued.size(); i++) {
560 mInputBufferIsDequeued.editItemAt(i) = false;
561 }
562
563 mPendingInputMessages.clear();
564 mDequeuedInputBuffers.clear();
565 mSkipRenderingUntilMediaTimeUs = -1;
566}
567
568void NuPlayer::Decoder::requestCodecNotification() {
Chong Zhang7137ec72014-11-12 16:41:05 -0800569 if (mCodec != NULL) {
Lajos Molnar1d15ab52015-03-04 16:46:34 -0800570 sp<AMessage> reply = new AMessage(kWhatCodecNotify, this);
Chong Zhang7137ec72014-11-12 16:41:05 -0800571 reply->setInt32("generation", mBufferGeneration);
572 mCodec->requestActivityNotification(reply);
573 }
574}
575
576bool NuPlayer::Decoder::isStaleReply(const sp<AMessage> &msg) {
577 int32_t generation;
578 CHECK(msg->findInt32("generation", &generation));
579 return generation != mBufferGeneration;
580}
581
582status_t NuPlayer::Decoder::fetchInputData(sp<AMessage> &reply) {
583 sp<ABuffer> accessUnit;
584 bool dropAccessUnit;
585 do {
586 status_t err = mSource->dequeueAccessUnit(mIsAudio, &accessUnit);
587
588 if (err == -EWOULDBLOCK) {
589 return err;
590 } else if (err != OK) {
591 if (err == INFO_DISCONTINUITY) {
592 int32_t type;
593 CHECK(accessUnit->meta()->findInt32("discontinuity", &type));
594
595 bool formatChange =
596 (mIsAudio &&
597 (type & ATSParser::DISCONTINUITY_AUDIO_FORMAT))
598 || (!mIsAudio &&
599 (type & ATSParser::DISCONTINUITY_VIDEO_FORMAT));
600
601 bool timeChange = (type & ATSParser::DISCONTINUITY_TIME) != 0;
602
603 ALOGI("%s discontinuity (format=%d, time=%d)",
604 mIsAudio ? "audio" : "video", formatChange, timeChange);
605
606 bool seamlessFormatChange = false;
607 sp<AMessage> newFormat = mSource->getFormat(mIsAudio);
608 if (formatChange) {
609 seamlessFormatChange =
610 supportsSeamlessFormatChange(newFormat);
611 // treat seamless format change separately
612 formatChange = !seamlessFormatChange;
613 }
614
Chong Zhang66704af2015-03-03 19:32:35 -0800615 // For format or time change, return EOS to queue EOS input,
616 // then wait for EOS on output.
Chong Zhang7137ec72014-11-12 16:41:05 -0800617 if (formatChange /* not seamless */) {
Chong Zhang7137ec72014-11-12 16:41:05 -0800618 mFormatChangePending = true;
Chong Zhang66704af2015-03-03 19:32:35 -0800619 err = ERROR_END_OF_STREAM;
Chong Zhang7137ec72014-11-12 16:41:05 -0800620 } else if (timeChange) {
Chong Zhang7137ec72014-11-12 16:41:05 -0800621 rememberCodecSpecificData(newFormat);
Chong Zhang66704af2015-03-03 19:32:35 -0800622 mTimeChangePending = true;
623 err = ERROR_END_OF_STREAM;
Chong Zhang7137ec72014-11-12 16:41:05 -0800624 } else if (seamlessFormatChange) {
625 // reuse existing decoder and don't flush
626 rememberCodecSpecificData(newFormat);
Chong Zhang66704af2015-03-03 19:32:35 -0800627 continue;
Chong Zhang7137ec72014-11-12 16:41:05 -0800628 } else {
629 // This stream is unaffected by the discontinuity
630 return -EWOULDBLOCK;
631 }
632 }
633
Chong Zhang66704af2015-03-03 19:32:35 -0800634 // reply should only be returned without a buffer set
635 // when there is an error (including EOS)
636 CHECK(err != OK);
637
Chong Zhang7137ec72014-11-12 16:41:05 -0800638 reply->setInt32("err", err);
Chong Zhang66704af2015-03-03 19:32:35 -0800639 return ERROR_END_OF_STREAM;
Chong Zhang7137ec72014-11-12 16:41:05 -0800640 }
641
642 if (!mIsAudio) {
643 ++mNumFramesTotal;
644 }
645
646 dropAccessUnit = false;
647 if (!mIsAudio
648 && !mIsSecure
649 && mRenderer->getVideoLateByUs() > 100000ll
650 && mIsVideoAVC
651 && !IsAVCReferenceFrame(accessUnit)) {
652 dropAccessUnit = true;
653 ++mNumFramesDropped;
654 }
655 } while (dropAccessUnit);
656
657 // ALOGV("returned a valid buffer of %s data", mIsAudio ? "mIsAudio" : "video");
658#if 0
659 int64_t mediaTimeUs;
660 CHECK(accessUnit->meta()->findInt64("timeUs", &mediaTimeUs));
Chong Zhang66704af2015-03-03 19:32:35 -0800661 ALOGV("[%s] feeding input buffer at media time %" PRId64,
Chong Zhang7137ec72014-11-12 16:41:05 -0800662 mIsAudio ? "audio" : "video",
663 mediaTimeUs / 1E6);
664#endif
665
666 if (mCCDecoder != NULL) {
667 mCCDecoder->decode(accessUnit);
668 }
669
670 reply->setBuffer("buffer", accessUnit);
671
672 return OK;
673}
674
675bool NuPlayer::Decoder::onInputBufferFetched(const sp<AMessage> &msg) {
Lajos Molnar1cd13982014-01-17 15:12:51 -0800676 size_t bufferIx;
677 CHECK(msg->findSize("buffer-ix", &bufferIx));
678 CHECK_LT(bufferIx, mInputBuffers.size());
679 sp<ABuffer> codecBuffer = mInputBuffers[bufferIx];
680
681 sp<ABuffer> buffer;
682 bool hasBuffer = msg->findBuffer("buffer", &buffer);
Lajos Molnar09524832014-07-17 14:29:51 -0700683
684 // handle widevine classic source - that fills an arbitrary input buffer
685 MediaBuffer *mediaBuffer = NULL;
Wei Jia96e92b52014-09-18 17:36:20 -0700686 if (hasBuffer) {
687 mediaBuffer = (MediaBuffer *)(buffer->getMediaBufferBase());
688 if (mediaBuffer != NULL) {
Lajos Molnar09524832014-07-17 14:29:51 -0700689 // likely filled another buffer than we requested: adjust buffer index
690 size_t ix;
691 for (ix = 0; ix < mInputBuffers.size(); ix++) {
692 const sp<ABuffer> &buf = mInputBuffers[ix];
693 if (buf->data() == mediaBuffer->data()) {
694 // all input buffers are dequeued on start, hence the check
Wei Jia2245fc62014-10-02 15:12:25 -0700695 if (!mInputBufferIsDequeued[ix]) {
696 ALOGV("[%s] received MediaBuffer for #%zu instead of #%zu",
697 mComponentName.c_str(), ix, bufferIx);
698 mediaBuffer->release();
699 return false;
700 }
Lajos Molnar09524832014-07-17 14:29:51 -0700701
702 // TRICKY: need buffer for the metadata, so instead, set
703 // codecBuffer to the same (though incorrect) buffer to
704 // avoid a memcpy into the codecBuffer
705 codecBuffer = buffer;
706 codecBuffer->setRange(
707 mediaBuffer->range_offset(),
708 mediaBuffer->range_length());
709 bufferIx = ix;
710 break;
711 }
712 }
713 CHECK(ix < mInputBuffers.size());
714 }
715 }
716
Lajos Molnar1cd13982014-01-17 15:12:51 -0800717 if (buffer == NULL /* includes !hasBuffer */) {
718 int32_t streamErr = ERROR_END_OF_STREAM;
719 CHECK(msg->findInt32("err", &streamErr) || !hasBuffer);
720
Chong Zhang66704af2015-03-03 19:32:35 -0800721 CHECK(streamErr != OK);
Lajos Molnar1cd13982014-01-17 15:12:51 -0800722
723 // attempt to queue EOS
724 status_t err = mCodec->queueInputBuffer(
725 bufferIx,
726 0,
727 0,
728 0,
729 MediaCodec::BUFFER_FLAG_EOS);
Andy Hungcf31f1e2014-09-23 14:59:01 -0700730 if (err == OK) {
731 mInputBufferIsDequeued.editItemAt(bufferIx) = false;
732 } else if (streamErr == ERROR_END_OF_STREAM) {
Lajos Molnar1cd13982014-01-17 15:12:51 -0800733 streamErr = err;
734 // err will not be ERROR_END_OF_STREAM
735 }
736
737 if (streamErr != ERROR_END_OF_STREAM) {
Andy Hungcf31f1e2014-09-23 14:59:01 -0700738 ALOGE("Stream error for %s (err=%d), EOS %s queued",
739 mComponentName.c_str(),
740 streamErr,
741 err == OK ? "successfully" : "unsuccessfully");
Lajos Molnar1cd13982014-01-17 15:12:51 -0800742 handleError(streamErr);
743 }
744 } else {
Wei Jiac6cfd702014-11-11 16:33:20 -0800745 sp<AMessage> extra;
746 if (buffer->meta()->findMessage("extra", &extra) && extra != NULL) {
747 int64_t resumeAtMediaTimeUs;
748 if (extra->findInt64(
749 "resume-at-mediaTimeUs", &resumeAtMediaTimeUs)) {
750 ALOGI("[%s] suppressing rendering until %lld us",
751 mComponentName.c_str(), (long long)resumeAtMediaTimeUs);
752 mSkipRenderingUntilMediaTimeUs = resumeAtMediaTimeUs;
753 }
754 }
755
Lajos Molnar1cd13982014-01-17 15:12:51 -0800756 int64_t timeUs = 0;
757 uint32_t flags = 0;
758 CHECK(buffer->meta()->findInt64("timeUs", &timeUs));
759
Lajos Molnar87603c02014-08-20 19:25:30 -0700760 int32_t eos, csd;
761 // we do not expect SYNCFRAME for decoder
Lajos Molnar1cd13982014-01-17 15:12:51 -0800762 if (buffer->meta()->findInt32("eos", &eos) && eos) {
763 flags |= MediaCodec::BUFFER_FLAG_EOS;
Lajos Molnar87603c02014-08-20 19:25:30 -0700764 } else if (buffer->meta()->findInt32("csd", &csd) && csd) {
765 flags |= MediaCodec::BUFFER_FLAG_CODECCONFIG;
Lajos Molnar1cd13982014-01-17 15:12:51 -0800766 }
767
768 // copy into codec buffer
769 if (buffer != codecBuffer) {
770 CHECK_LE(buffer->size(), codecBuffer->capacity());
771 codecBuffer->setRange(0, buffer->size());
772 memcpy(codecBuffer->data(), buffer->data(), buffer->size());
773 }
774
775 status_t err = mCodec->queueInputBuffer(
776 bufferIx,
777 codecBuffer->offset(),
778 codecBuffer->size(),
779 timeUs,
780 flags);
781 if (err != OK) {
Andy Hungcf31f1e2014-09-23 14:59:01 -0700782 if (mediaBuffer != NULL) {
783 mediaBuffer->release();
784 }
Lajos Molnar1cd13982014-01-17 15:12:51 -0800785 ALOGE("Failed to queue input buffer for %s (err=%d)",
786 mComponentName.c_str(), err);
787 handleError(err);
Andy Hungcf31f1e2014-09-23 14:59:01 -0700788 } else {
789 mInputBufferIsDequeued.editItemAt(bufferIx) = false;
790 if (mediaBuffer != NULL) {
791 CHECK(mMediaBuffers[bufferIx] == NULL);
792 mMediaBuffers.editItemAt(bufferIx) = mediaBuffer;
793 }
Lajos Molnar09524832014-07-17 14:29:51 -0700794 }
Lajos Molnar1cd13982014-01-17 15:12:51 -0800795 }
Wei Jia2245fc62014-10-02 15:12:25 -0700796 return true;
Lajos Molnar1cd13982014-01-17 15:12:51 -0800797}
798
Lajos Molnar1cd13982014-01-17 15:12:51 -0800799void NuPlayer::Decoder::onRenderBuffer(const sp<AMessage> &msg) {
800 status_t err;
801 int32_t render;
802 size_t bufferIx;
Chong Zhang66704af2015-03-03 19:32:35 -0800803 int32_t eos;
Lajos Molnar1cd13982014-01-17 15:12:51 -0800804 CHECK(msg->findSize("buffer-ix", &bufferIx));
Wei Jiac6cfd702014-11-11 16:33:20 -0800805
Chong Zhang7137ec72014-11-12 16:41:05 -0800806 if (!mIsAudio) {
Wei Jiac6cfd702014-11-11 16:33:20 -0800807 int64_t timeUs;
808 sp<ABuffer> buffer = mOutputBuffers[bufferIx];
809 buffer->meta()->findInt64("timeUs", &timeUs);
Chong Zhang7137ec72014-11-12 16:41:05 -0800810
811 if (mCCDecoder != NULL && mCCDecoder->isSelected()) {
812 mCCDecoder->display(timeUs);
813 }
Wei Jiac6cfd702014-11-11 16:33:20 -0800814 }
815
Lajos Molnar1cd13982014-01-17 15:12:51 -0800816 if (msg->findInt32("render", &render) && render) {
Lajos Molnardc43dfa2014-05-07 15:33:04 -0700817 int64_t timestampNs;
818 CHECK(msg->findInt64("timestampNs", &timestampNs));
819 err = mCodec->renderOutputBufferAndRelease(bufferIx, timestampNs);
Lajos Molnar1cd13982014-01-17 15:12:51 -0800820 } else {
821 err = mCodec->releaseOutputBuffer(bufferIx);
822 }
823 if (err != OK) {
824 ALOGE("failed to release output buffer for %s (err=%d)",
825 mComponentName.c_str(), err);
826 handleError(err);
827 }
Chong Zhang66704af2015-03-03 19:32:35 -0800828 if (msg->findInt32("eos", &eos) && eos
829 && isDiscontinuityPending()) {
830 finishHandleDiscontinuity(true /* flushOnTimeChange */);
831 }
832}
833
834bool NuPlayer::Decoder::isDiscontinuityPending() const {
835 return mFormatChangePending || mTimeChangePending;
836}
837
838void NuPlayer::Decoder::finishHandleDiscontinuity(bool flushOnTimeChange) {
839 ALOGV("finishHandleDiscontinuity: format %d, time %d, flush %d",
840 mFormatChangePending, mTimeChangePending, flushOnTimeChange);
841
842 // If we have format change, pause and wait to be killed;
843 // If we have time change only, flush and restart fetching.
844
845 if (mFormatChangePending) {
846 mPaused = true;
847 } else if (mTimeChangePending) {
848 if (flushOnTimeChange) {
Marco Nelissen421f47c2015-03-25 14:40:32 -0700849 doFlush(false /* notifyComplete */);
850 signalResume(false /* notifyComplete */);
Chong Zhang66704af2015-03-03 19:32:35 -0800851 }
Chong Zhang66704af2015-03-03 19:32:35 -0800852 }
853
854 // Notify NuPlayer to either shutdown decoder, or rescan sources
855 sp<AMessage> msg = mNotify->dup();
856 msg->setInt32("what", kWhatInputDiscontinuity);
857 msg->setInt32("formatChange", mFormatChangePending);
858 msg->post();
859
860 mFormatChangePending = false;
861 mTimeChangePending = false;
Lajos Molnar1cd13982014-01-17 15:12:51 -0800862}
863
Chong Zhang7137ec72014-11-12 16:41:05 -0800864bool NuPlayer::Decoder::supportsSeamlessAudioFormatChange(
865 const sp<AMessage> &targetFormat) const {
Robert Shih6d0a94e2014-01-23 16:18:22 -0800866 if (targetFormat == NULL) {
867 return true;
868 }
869
870 AString mime;
871 if (!targetFormat->findString("mime", &mime)) {
872 return false;
873 }
874
875 if (!strcasecmp(mime.c_str(), MEDIA_MIMETYPE_AUDIO_AAC)) {
876 // field-by-field comparison
877 const char * keys[] = { "channel-count", "sample-rate", "is-adts" };
878 for (unsigned int i = 0; i < sizeof(keys) / sizeof(keys[0]); i++) {
879 int32_t oldVal, newVal;
joakim johansson7abbd4c2015-01-30 14:16:03 +0100880 if (!mInputFormat->findInt32(keys[i], &oldVal) ||
Lajos Molnar1cd13982014-01-17 15:12:51 -0800881 !targetFormat->findInt32(keys[i], &newVal) ||
882 oldVal != newVal) {
Robert Shih6d0a94e2014-01-23 16:18:22 -0800883 return false;
884 }
885 }
886
887 sp<ABuffer> oldBuf, newBuf;
joakim johansson7abbd4c2015-01-30 14:16:03 +0100888 if (mInputFormat->findBuffer("csd-0", &oldBuf) &&
Lajos Molnar1cd13982014-01-17 15:12:51 -0800889 targetFormat->findBuffer("csd-0", &newBuf)) {
Robert Shih6d0a94e2014-01-23 16:18:22 -0800890 if (oldBuf->size() != newBuf->size()) {
891 return false;
892 }
893 return !memcmp(oldBuf->data(), newBuf->data(), oldBuf->size());
894 }
895 }
896 return false;
897}
898
899bool NuPlayer::Decoder::supportsSeamlessFormatChange(const sp<AMessage> &targetFormat) const {
joakim johansson7abbd4c2015-01-30 14:16:03 +0100900 if (mInputFormat == NULL) {
Robert Shih6d0a94e2014-01-23 16:18:22 -0800901 return false;
902 }
903
904 if (targetFormat == NULL) {
905 return true;
906 }
907
908 AString oldMime, newMime;
joakim johansson7abbd4c2015-01-30 14:16:03 +0100909 if (!mInputFormat->findString("mime", &oldMime)
Robert Shih6d0a94e2014-01-23 16:18:22 -0800910 || !targetFormat->findString("mime", &newMime)
911 || !(oldMime == newMime)) {
912 return false;
913 }
914
915 bool audio = !strncasecmp(oldMime.c_str(), "audio/", strlen("audio/"));
916 bool seamless;
917 if (audio) {
918 seamless = supportsSeamlessAudioFormatChange(targetFormat);
919 } else {
Lajos Molnar1cd13982014-01-17 15:12:51 -0800920 int32_t isAdaptive;
921 seamless = (mCodec != NULL &&
922 mInputFormat->findInt32("adaptive-playback", &isAdaptive) &&
923 isAdaptive);
Robert Shih6d0a94e2014-01-23 16:18:22 -0800924 }
925
926 ALOGV("%s seamless support for %s", seamless ? "yes" : "no", oldMime.c_str());
927 return seamless;
928}
929
Chong Zhang7137ec72014-11-12 16:41:05 -0800930void NuPlayer::Decoder::rememberCodecSpecificData(const sp<AMessage> &format) {
931 if (format == NULL) {
Chong Zhangb86e68f2014-08-01 13:46:53 -0700932 return;
933 }
Chong Zhang7137ec72014-11-12 16:41:05 -0800934 mCSDsForCurrentFormat.clear();
935 for (int32_t i = 0; ; ++i) {
936 AString tag = "csd-";
937 tag.append(i);
938 sp<ABuffer> buffer;
939 if (!format->findBuffer(tag.c_str(), &buffer)) {
940 break;
941 }
942 mCSDsForCurrentFormat.push(buffer);
Chong Zhanga7fa1d92014-06-11 14:49:23 -0700943 }
Chong Zhangb86e68f2014-08-01 13:46:53 -0700944}
945
Chong Zhangf8d71772014-11-26 15:08:34 -0800946void NuPlayer::Decoder::notifyResumeCompleteIfNecessary() {
947 if (mResumePending) {
948 mResumePending = false;
949
950 sp<AMessage> notify = mNotify->dup();
951 notify->setInt32("what", kWhatResumeCompleted);
952 notify->post();
953 }
954}
955
Andreas Huberf9334412010-12-15 15:17:42 -0800956} // namespace android
957