blob: 73f8ba865eb4c5ef31b6b8496de743f441bb792e [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() {
Ronghua Wufaeb0f22015-05-21 12:20:21 -070071 mCodec->release();
Wei Jia4923cee2014-09-24 14:25:19 -070072 releaseAndResetMediaBuffers();
Andreas Huberf9334412010-12-15 15:17:42 -080073}
74
Chong Zhang7137ec72014-11-12 16:41:05 -080075void NuPlayer::Decoder::getStats(
76 int64_t *numFramesTotal,
77 int64_t *numFramesDropped) const {
78 *numFramesTotal = mNumFramesTotal;
79 *numFramesDropped = mNumFramesDropped;
Lajos Molnar09524832014-07-17 14:29:51 -070080}
81
Chong Zhang7137ec72014-11-12 16:41:05 -080082void NuPlayer::Decoder::onMessageReceived(const sp<AMessage> &msg) {
83 ALOGV("[%s] onMessage: %s", mComponentName.c_str(), msg->debugString().c_str());
84
85 switch (msg->what()) {
86 case kWhatCodecNotify:
87 {
Chong Zhang3b032b32015-04-17 15:49:06 -070088 int32_t cbID;
89 CHECK(msg->findInt32("callbackID", &cbID));
90
91 ALOGV("[%s] kWhatCodecNotify: cbID = %d, paused = %d",
92 mIsAudio ? "audio" : "video", cbID, mPaused);
93
Marco Nelissen421f47c2015-03-25 14:40:32 -070094 if (mPaused) {
95 break;
Chong Zhang7137ec72014-11-12 16:41:05 -080096 }
97
Marco Nelissen421f47c2015-03-25 14:40:32 -070098 switch (cbID) {
99 case MediaCodec::CB_INPUT_AVAILABLE:
100 {
101 int32_t index;
102 CHECK(msg->findInt32("index", &index));
103
104 handleAnInputBuffer(index);
105 break;
106 }
107
108 case MediaCodec::CB_OUTPUT_AVAILABLE:
109 {
110 int32_t index;
111 size_t offset;
112 size_t size;
113 int64_t timeUs;
114 int32_t flags;
115
116 CHECK(msg->findInt32("index", &index));
117 CHECK(msg->findSize("offset", &offset));
118 CHECK(msg->findSize("size", &size));
119 CHECK(msg->findInt64("timeUs", &timeUs));
120 CHECK(msg->findInt32("flags", &flags));
121
122 handleAnOutputBuffer(index, offset, size, timeUs, flags);
123 break;
124 }
125
126 case MediaCodec::CB_OUTPUT_FORMAT_CHANGED:
127 {
128 sp<AMessage> format;
129 CHECK(msg->findMessage("format", &format));
130
131 handleOutputFormatChange(format);
132 break;
133 }
134
135 case MediaCodec::CB_ERROR:
136 {
137 status_t err;
138 CHECK(msg->findInt32("err", &err));
139 ALOGE("Decoder (%s) reported error : 0x%x",
140 mIsAudio ? "audio" : "video", err);
141
142 handleError(err);
143 break;
144 }
145
146 default:
147 {
148 TRESPASS();
149 break;
150 }
151 }
152
Lajos Molnar87603c02014-08-20 19:25:30 -0700153 break;
154 }
Chong Zhang7137ec72014-11-12 16:41:05 -0800155
156 case kWhatRenderBuffer:
157 {
158 if (!isStaleReply(msg)) {
159 onRenderBuffer(msg);
160 }
161 break;
162 }
163
164 default:
165 DecoderBase::onMessageReceived(msg);
166 break;
Lajos Molnar87603c02014-08-20 19:25:30 -0700167 }
168}
169
Lajos Molnar1cd13982014-01-17 15:12:51 -0800170void NuPlayer::Decoder::onConfigure(const sp<AMessage> &format) {
Andreas Huberf9334412010-12-15 15:17:42 -0800171 CHECK(mCodec == NULL);
Andreas Huberf9334412010-12-15 15:17:42 -0800172
Chong Zhang7137ec72014-11-12 16:41:05 -0800173 mFormatChangePending = false;
Chong Zhang66704af2015-03-03 19:32:35 -0800174 mTimeChangePending = false;
Chong Zhang7137ec72014-11-12 16:41:05 -0800175
Lajos Molnar1cd13982014-01-17 15:12:51 -0800176 ++mBufferGeneration;
177
Andreas Huber84066782011-08-16 09:34:26 -0700178 AString mime;
179 CHECK(format->findString("mime", &mime));
Andreas Huberf9334412010-12-15 15:17:42 -0800180
Chong Zhang7137ec72014-11-12 16:41:05 -0800181 mIsAudio = !strncasecmp("audio/", mime.c_str(), 6);
182 mIsVideoAVC = !strcasecmp(MEDIA_MIMETYPE_VIDEO_AVC, mime.c_str());
183
Lajos Molnar1cd13982014-01-17 15:12:51 -0800184 mComponentName = mime;
185 mComponentName.append(" decoder");
Lajos Molnar1de1e252015-04-30 18:18:34 -0700186 ALOGV("[%s] onConfigure (surface=%p)", mComponentName.c_str(), mSurface.get());
Lajos Molnar1cd13982014-01-17 15:12:51 -0800187
188 mCodec = MediaCodec::CreateByType(mCodecLooper, mime.c_str(), false /* encoder */);
Lajos Molnar09524832014-07-17 14:29:51 -0700189 int32_t secure = 0;
190 if (format->findInt32("secure", &secure) && secure != 0) {
191 if (mCodec != NULL) {
192 mCodec->getName(&mComponentName);
193 mComponentName.append(".secure");
194 mCodec->release();
195 ALOGI("[%s] creating", mComponentName.c_str());
196 mCodec = MediaCodec::CreateByComponentName(
197 mCodecLooper, mComponentName.c_str());
198 }
199 }
Lajos Molnar1cd13982014-01-17 15:12:51 -0800200 if (mCodec == NULL) {
Lajos Molnar09524832014-07-17 14:29:51 -0700201 ALOGE("Failed to create %s%s decoder",
202 (secure ? "secure " : ""), mime.c_str());
Lajos Molnar1cd13982014-01-17 15:12:51 -0800203 handleError(UNKNOWN_ERROR);
204 return;
205 }
Chong Zhang7137ec72014-11-12 16:41:05 -0800206 mIsSecure = secure;
Lajos Molnar1cd13982014-01-17 15:12:51 -0800207
208 mCodec->getName(&mComponentName);
209
Lajos Molnar14986f62014-09-15 11:04:44 -0700210 status_t err;
Lajos Molnar1de1e252015-04-30 18:18:34 -0700211 if (mSurface != NULL) {
Lajos Molnar1cd13982014-01-17 15:12:51 -0800212 // disconnect from surface as MediaCodec will reconnect
Lajos Molnar14986f62014-09-15 11:04:44 -0700213 err = native_window_api_disconnect(
Lajos Molnar1de1e252015-04-30 18:18:34 -0700214 mSurface.get(), NATIVE_WINDOW_API_MEDIA);
Lajos Molnar14986f62014-09-15 11:04:44 -0700215 // We treat this as a warning, as this is a preparatory step.
216 // Codec will try to connect to the surface, which is where
217 // any error signaling will occur.
218 ALOGW_IF(err != OK, "failed to disconnect from surface: %d", err);
Lajos Molnar1cd13982014-01-17 15:12:51 -0800219 }
Lajos Molnar14986f62014-09-15 11:04:44 -0700220 err = mCodec->configure(
Lajos Molnar1de1e252015-04-30 18:18:34 -0700221 format, mSurface, NULL /* crypto */, 0 /* flags */);
Lajos Molnar1cd13982014-01-17 15:12:51 -0800222 if (err != OK) {
223 ALOGE("Failed to configure %s decoder (err=%d)", mComponentName.c_str(), err);
Andy Hung2abde2c2014-09-30 14:40:32 -0700224 mCodec->release();
225 mCodec.clear();
Lajos Molnar1cd13982014-01-17 15:12:51 -0800226 handleError(err);
227 return;
228 }
Lajos Molnar87603c02014-08-20 19:25:30 -0700229 rememberCodecSpecificData(format);
230
Lajos Molnar1cd13982014-01-17 15:12:51 -0800231 // the following should work in configured state
232 CHECK_EQ((status_t)OK, mCodec->getOutputFormat(&mOutputFormat));
233 CHECK_EQ((status_t)OK, mCodec->getInputFormat(&mInputFormat));
234
Marco Nelissen421f47c2015-03-25 14:40:32 -0700235 sp<AMessage> reply = new AMessage(kWhatCodecNotify, this);
236 mCodec->setCallback(reply);
237
Lajos Molnar1cd13982014-01-17 15:12:51 -0800238 err = mCodec->start();
239 if (err != OK) {
240 ALOGE("Failed to start %s decoder (err=%d)", mComponentName.c_str(), err);
Andy Hung2abde2c2014-09-30 14:40:32 -0700241 mCodec->release();
242 mCodec.clear();
Lajos Molnar1cd13982014-01-17 15:12:51 -0800243 handleError(err);
244 return;
Andreas Huberf9334412010-12-15 15:17:42 -0800245 }
246
Lajos Molnar09524832014-07-17 14:29:51 -0700247 releaseAndResetMediaBuffers();
Marco Nelissen421f47c2015-03-25 14:40:32 -0700248
Wei Jia704e7262014-06-04 16:21:56 -0700249 mPaused = false;
Chong Zhangf8d71772014-11-26 15:08:34 -0800250 mResumePending = false;
Lajos Molnar1cd13982014-01-17 15:12:51 -0800251}
Andreas Huber078cfcf2011-09-15 12:25:04 -0700252
Ronghua Wu8db88132015-04-22 13:51:35 -0700253void NuPlayer::Decoder::onSetParameters(const sp<AMessage> &params) {
254 if (mCodec == NULL) {
255 ALOGW("onSetParameters called before codec is created.");
256 return;
257 }
258 mCodec->setParameters(params);
259}
260
Chong Zhang7137ec72014-11-12 16:41:05 -0800261void NuPlayer::Decoder::onSetRenderer(const sp<Renderer> &renderer) {
262 bool hadNoRenderer = (mRenderer == NULL);
263 mRenderer = renderer;
264 if (hadNoRenderer && mRenderer != NULL) {
Lajos Molnare6109e22015-04-10 17:18:22 -0700265 // this means that the widevine legacy source is ready
266 onRequestInputBuffers();
Chong Zhang7137ec72014-11-12 16:41:05 -0800267 }
268}
269
270void NuPlayer::Decoder::onGetInputBuffers(
271 Vector<sp<ABuffer> > *dstBuffers) {
Lajos Molnare6109e22015-04-10 17:18:22 -0700272 CHECK_EQ((status_t)OK, mCodec->getWidevineLegacyBuffers(dstBuffers));
Chong Zhang7137ec72014-11-12 16:41:05 -0800273}
274
Chong Zhangf8d71772014-11-26 15:08:34 -0800275void NuPlayer::Decoder::onResume(bool notifyComplete) {
Chong Zhang7137ec72014-11-12 16:41:05 -0800276 mPaused = false;
Chong Zhangf8d71772014-11-26 15:08:34 -0800277
278 if (notifyComplete) {
279 mResumePending = true;
280 }
Marco Nelissen421f47c2015-03-25 14:40:32 -0700281 mCodec->start();
Chong Zhang7137ec72014-11-12 16:41:05 -0800282}
283
Chong Zhang66704af2015-03-03 19:32:35 -0800284void NuPlayer::Decoder::doFlush(bool notifyComplete) {
Chong Zhang7137ec72014-11-12 16:41:05 -0800285 if (mCCDecoder != NULL) {
286 mCCDecoder->flush();
287 }
288
289 if (mRenderer != NULL) {
290 mRenderer->flush(mIsAudio, notifyComplete);
291 mRenderer->signalTimeDiscontinuity();
292 }
293
294 status_t err = OK;
295 if (mCodec != NULL) {
296 err = mCodec->flush();
297 mCSDsToSubmit = mCSDsForCurrentFormat; // copy operator
298 ++mBufferGeneration;
299 }
300
301 if (err != OK) {
302 ALOGE("failed to flush %s (err=%d)", mComponentName.c_str(), err);
303 handleError(err);
304 // finish with posting kWhatFlushCompleted.
305 // we attempt to release the buffers even if flush fails.
306 }
307 releaseAndResetMediaBuffers();
Marco Nelissen421f47c2015-03-25 14:40:32 -0700308 mPaused = true;
Chong Zhang66704af2015-03-03 19:32:35 -0800309}
Chong Zhang7137ec72014-11-12 16:41:05 -0800310
Marco Nelissen421f47c2015-03-25 14:40:32 -0700311
Chong Zhang66704af2015-03-03 19:32:35 -0800312void NuPlayer::Decoder::onFlush() {
313 doFlush(true);
314
315 if (isDiscontinuityPending()) {
316 // This could happen if the client starts seeking/shutdown
317 // after we queued an EOS for discontinuities.
318 // We can consider discontinuity handled.
319 finishHandleDiscontinuity(false /* flushOnTimeChange */);
Chong Zhang7137ec72014-11-12 16:41:05 -0800320 }
Chong Zhang66704af2015-03-03 19:32:35 -0800321
322 sp<AMessage> notify = mNotify->dup();
323 notify->setInt32("what", kWhatFlushCompleted);
324 notify->post();
Chong Zhang7137ec72014-11-12 16:41:05 -0800325}
326
327void NuPlayer::Decoder::onShutdown(bool notifyComplete) {
328 status_t err = OK;
Chong Zhangf8d71772014-11-26 15:08:34 -0800329
330 // if there is a pending resume request, notify complete now
331 notifyResumeCompleteIfNecessary();
332
Chong Zhang7137ec72014-11-12 16:41:05 -0800333 if (mCodec != NULL) {
334 err = mCodec->release();
335 mCodec = NULL;
336 ++mBufferGeneration;
337
Lajos Molnar1de1e252015-04-30 18:18:34 -0700338 if (mSurface != NULL) {
Chong Zhang7137ec72014-11-12 16:41:05 -0800339 // reconnect to surface as MediaCodec disconnected from it
340 status_t error =
Lajos Molnar1de1e252015-04-30 18:18:34 -0700341 native_window_api_connect(mSurface.get(), NATIVE_WINDOW_API_MEDIA);
Chong Zhang7137ec72014-11-12 16:41:05 -0800342 ALOGW_IF(error != NO_ERROR,
343 "[%s] failed to connect to native window, error=%d",
344 mComponentName.c_str(), error);
345 }
346 mComponentName = "decoder";
347 }
348
349 releaseAndResetMediaBuffers();
350
351 if (err != OK) {
352 ALOGE("failed to release %s (err=%d)", mComponentName.c_str(), err);
353 handleError(err);
354 // finish with posting kWhatShutdownCompleted.
355 }
356
357 if (notifyComplete) {
358 sp<AMessage> notify = mNotify->dup();
359 notify->setInt32("what", kWhatShutdownCompleted);
360 notify->post();
361 mPaused = true;
362 }
363}
364
Chong Zhang3b032b32015-04-17 15:49:06 -0700365/*
366 * returns true if we should request more data
367 */
368bool NuPlayer::Decoder::doRequestBuffers() {
Lajos Molnare6109e22015-04-10 17:18:22 -0700369 // mRenderer is only NULL if we have a legacy widevine source that
370 // is not yet ready. In this case we must not fetch input.
371 if (isDiscontinuityPending() || mRenderer == NULL) {
Chong Zhang3b032b32015-04-17 15:49:06 -0700372 return false;
Chong Zhang7137ec72014-11-12 16:41:05 -0800373 }
374 status_t err = OK;
Chong Zhang66704af2015-03-03 19:32:35 -0800375 while (err == OK && !mDequeuedInputBuffers.empty()) {
Chong Zhang7137ec72014-11-12 16:41:05 -0800376 size_t bufferIx = *mDequeuedInputBuffers.begin();
377 sp<AMessage> msg = new AMessage();
378 msg->setSize("buffer-ix", bufferIx);
379 err = fetchInputData(msg);
Chong Zhang66704af2015-03-03 19:32:35 -0800380 if (err != OK && err != ERROR_END_OF_STREAM) {
381 // if EOS, need to queue EOS buffer
Chong Zhang7137ec72014-11-12 16:41:05 -0800382 break;
383 }
384 mDequeuedInputBuffers.erase(mDequeuedInputBuffers.begin());
385
386 if (!mPendingInputMessages.empty()
387 || !onInputBufferFetched(msg)) {
388 mPendingInputMessages.push_back(msg);
Lajos Molnar09524832014-07-17 14:29:51 -0700389 }
390 }
Chong Zhang7137ec72014-11-12 16:41:05 -0800391
Chong Zhang3b032b32015-04-17 15:49:06 -0700392 return err == -EWOULDBLOCK
393 && mSource->feedMoreTSData() == OK;
Lajos Molnar09524832014-07-17 14:29:51 -0700394}
395
Marco Nelissen421f47c2015-03-25 14:40:32 -0700396void NuPlayer::Decoder::handleError(int32_t err)
397{
398 // We cannot immediately release the codec due to buffers still outstanding
399 // in the renderer. We signal to the player the error so it can shutdown/release the
400 // decoder after flushing and increment the generation to discard unnecessary messages.
401
402 ++mBufferGeneration;
403
404 sp<AMessage> notify = mNotify->dup();
405 notify->setInt32("what", kWhatError);
406 notify->setInt32("err", err);
407 notify->post();
408}
409
410bool NuPlayer::Decoder::handleAnInputBuffer(size_t index) {
Chong Zhang66704af2015-03-03 19:32:35 -0800411 if (isDiscontinuityPending()) {
Chong Zhang7137ec72014-11-12 16:41:05 -0800412 return false;
413 }
Marco Nelissen421f47c2015-03-25 14:40:32 -0700414
415 sp<ABuffer> buffer;
416 mCodec->getInputBuffer(index, &buffer);
417
418 if (index >= mInputBuffers.size()) {
419 for (size_t i = mInputBuffers.size(); i <= index; ++i) {
420 mInputBuffers.add();
421 mMediaBuffers.add();
422 mInputBufferIsDequeued.add();
423 mMediaBuffers.editItemAt(i) = NULL;
424 mInputBufferIsDequeued.editItemAt(i) = false;
Lajos Molnar1cd13982014-01-17 15:12:51 -0800425 }
Andreas Huber078cfcf2011-09-15 12:25:04 -0700426 }
Marco Nelissen421f47c2015-03-25 14:40:32 -0700427 mInputBuffers.editItemAt(index) = buffer;
Andreas Huber078cfcf2011-09-15 12:25:04 -0700428
Marco Nelissen421f47c2015-03-25 14:40:32 -0700429 //CHECK_LT(bufferIx, mInputBuffers.size());
Andreas Huberf9334412010-12-15 15:17:42 -0800430
Marco Nelissen421f47c2015-03-25 14:40:32 -0700431 if (mMediaBuffers[index] != NULL) {
432 mMediaBuffers[index]->release();
433 mMediaBuffers.editItemAt(index) = NULL;
Lajos Molnar09524832014-07-17 14:29:51 -0700434 }
Marco Nelissen421f47c2015-03-25 14:40:32 -0700435 mInputBufferIsDequeued.editItemAt(index) = true;
Lajos Molnar09524832014-07-17 14:29:51 -0700436
Lajos Molnar87603c02014-08-20 19:25:30 -0700437 if (!mCSDsToSubmit.isEmpty()) {
Chong Zhang7137ec72014-11-12 16:41:05 -0800438 sp<AMessage> msg = new AMessage();
Marco Nelissen421f47c2015-03-25 14:40:32 -0700439 msg->setSize("buffer-ix", index);
Chong Zhang7137ec72014-11-12 16:41:05 -0800440
Lajos Molnar87603c02014-08-20 19:25:30 -0700441 sp<ABuffer> buffer = mCSDsToSubmit.itemAt(0);
442 ALOGI("[%s] resubmitting CSD", mComponentName.c_str());
Chong Zhang7137ec72014-11-12 16:41:05 -0800443 msg->setBuffer("buffer", buffer);
Lajos Molnar87603c02014-08-20 19:25:30 -0700444 mCSDsToSubmit.removeAt(0);
Chong Zhang7137ec72014-11-12 16:41:05 -0800445 CHECK(onInputBufferFetched(msg));
Wei Jia2245fc62014-10-02 15:12:25 -0700446 return true;
447 }
448
449 while (!mPendingInputMessages.empty()) {
450 sp<AMessage> msg = *mPendingInputMessages.begin();
Chong Zhang7137ec72014-11-12 16:41:05 -0800451 if (!onInputBufferFetched(msg)) {
Wei Jia2245fc62014-10-02 15:12:25 -0700452 break;
453 }
454 mPendingInputMessages.erase(mPendingInputMessages.begin());
455 }
456
Marco Nelissen421f47c2015-03-25 14:40:32 -0700457 if (!mInputBufferIsDequeued.editItemAt(index)) {
Lajos Molnar87603c02014-08-20 19:25:30 -0700458 return true;
459 }
460
Marco Nelissen421f47c2015-03-25 14:40:32 -0700461 mDequeuedInputBuffers.push_back(index);
Chong Zhang7137ec72014-11-12 16:41:05 -0800462
463 onRequestInputBuffers();
Lajos Molnar1cd13982014-01-17 15:12:51 -0800464 return true;
465}
466
Marco Nelissen421f47c2015-03-25 14:40:32 -0700467bool NuPlayer::Decoder::handleAnOutputBuffer(
468 size_t index,
469 size_t offset,
470 size_t size,
471 int64_t timeUs,
472 int32_t flags) {
Marco Nelissen421f47c2015-03-25 14:40:32 -0700473// CHECK_LT(bufferIx, mOutputBuffers.size());
474 sp<ABuffer> buffer;
475 mCodec->getOutputBuffer(index, &buffer);
476
477 if (index >= mOutputBuffers.size()) {
478 for (size_t i = mOutputBuffers.size(); i <= index; ++i) {
479 mOutputBuffers.add();
480 }
481 }
482
483 mOutputBuffers.editItemAt(index) = buffer;
484
Chong Zhang7137ec72014-11-12 16:41:05 -0800485 buffer->setRange(offset, size);
486 buffer->meta()->clear();
487 buffer->meta()->setInt64("timeUs", timeUs);
Chong Zhang66704af2015-03-03 19:32:35 -0800488
489 bool eos = flags & MediaCodec::BUFFER_FLAG_EOS;
Chong Zhang7137ec72014-11-12 16:41:05 -0800490 // we do not expect CODECCONFIG or SYNCFRAME for decoder
491
Lajos Molnar1d15ab52015-03-04 16:46:34 -0800492 sp<AMessage> reply = new AMessage(kWhatRenderBuffer, this);
Marco Nelissen421f47c2015-03-25 14:40:32 -0700493 reply->setSize("buffer-ix", index);
Chong Zhang7137ec72014-11-12 16:41:05 -0800494 reply->setInt32("generation", mBufferGeneration);
495
Chong Zhang66704af2015-03-03 19:32:35 -0800496 if (eos) {
497 ALOGI("[%s] saw output EOS", mIsAudio ? "audio" : "video");
498
499 buffer->meta()->setInt32("eos", true);
500 reply->setInt32("eos", true);
501 } else if (mSkipRenderingUntilMediaTimeUs >= 0) {
Chong Zhang7137ec72014-11-12 16:41:05 -0800502 if (timeUs < mSkipRenderingUntilMediaTimeUs) {
503 ALOGV("[%s] dropping buffer at time %lld as requested.",
504 mComponentName.c_str(), (long long)timeUs);
505
506 reply->post();
507 return true;
508 }
509
510 mSkipRenderingUntilMediaTimeUs = -1;
511 }
512
Chong Zhangf8d71772014-11-26 15:08:34 -0800513 // wait until 1st frame comes out to signal resume complete
514 notifyResumeCompleteIfNecessary();
515
Chong Zhang7137ec72014-11-12 16:41:05 -0800516 if (mRenderer != NULL) {
517 // send the buffer to renderer.
518 mRenderer->queueBuffer(mIsAudio, buffer, reply);
Chong Zhang66704af2015-03-03 19:32:35 -0800519 if (eos && !isDiscontinuityPending()) {
Chong Zhang7137ec72014-11-12 16:41:05 -0800520 mRenderer->queueEOS(mIsAudio, ERROR_END_OF_STREAM);
521 }
522 }
523
524 return true;
525}
526
Marco Nelissen421f47c2015-03-25 14:40:32 -0700527void NuPlayer::Decoder::handleOutputFormatChange(const sp<AMessage> &format) {
528 if (!mIsAudio) {
529 sp<AMessage> notify = mNotify->dup();
530 notify->setInt32("what", kWhatVideoSizeChanged);
531 notify->setMessage("format", format);
532 notify->post();
533 } else if (mRenderer != NULL) {
534 uint32_t flags;
535 int64_t durationUs;
536 bool hasVideo = (mSource->getFormat(false /* audio */) != NULL);
537 if (!hasVideo &&
538 mSource->getDuration(&durationUs) == OK &&
539 durationUs > AUDIO_SINK_MIN_DEEP_BUFFER_DURATION_US) {
540 flags = AUDIO_OUTPUT_FLAG_DEEP_BUFFER;
541 } else {
542 flags = AUDIO_OUTPUT_FLAG_NONE;
543 }
544
545 mRenderer->openAudioSink(
546 format, false /* offloadOnly */, hasVideo, flags, NULL /* isOffloaed */);
547 }
548}
549
Chong Zhang7137ec72014-11-12 16:41:05 -0800550void NuPlayer::Decoder::releaseAndResetMediaBuffers() {
551 for (size_t i = 0; i < mMediaBuffers.size(); i++) {
552 if (mMediaBuffers[i] != NULL) {
553 mMediaBuffers[i]->release();
554 mMediaBuffers.editItemAt(i) = NULL;
555 }
556 }
557 mMediaBuffers.resize(mInputBuffers.size());
558 for (size_t i = 0; i < mMediaBuffers.size(); i++) {
559 mMediaBuffers.editItemAt(i) = NULL;
560 }
561 mInputBufferIsDequeued.clear();
562 mInputBufferIsDequeued.resize(mInputBuffers.size());
563 for (size_t i = 0; i < mInputBufferIsDequeued.size(); i++) {
564 mInputBufferIsDequeued.editItemAt(i) = false;
565 }
566
567 mPendingInputMessages.clear();
568 mDequeuedInputBuffers.clear();
569 mSkipRenderingUntilMediaTimeUs = -1;
570}
571
572void NuPlayer::Decoder::requestCodecNotification() {
Chong Zhang7137ec72014-11-12 16:41:05 -0800573 if (mCodec != NULL) {
Lajos Molnar1d15ab52015-03-04 16:46:34 -0800574 sp<AMessage> reply = new AMessage(kWhatCodecNotify, this);
Chong Zhang7137ec72014-11-12 16:41:05 -0800575 reply->setInt32("generation", mBufferGeneration);
576 mCodec->requestActivityNotification(reply);
577 }
578}
579
580bool NuPlayer::Decoder::isStaleReply(const sp<AMessage> &msg) {
581 int32_t generation;
582 CHECK(msg->findInt32("generation", &generation));
583 return generation != mBufferGeneration;
584}
585
586status_t NuPlayer::Decoder::fetchInputData(sp<AMessage> &reply) {
587 sp<ABuffer> accessUnit;
588 bool dropAccessUnit;
589 do {
590 status_t err = mSource->dequeueAccessUnit(mIsAudio, &accessUnit);
591
592 if (err == -EWOULDBLOCK) {
593 return err;
594 } else if (err != OK) {
595 if (err == INFO_DISCONTINUITY) {
596 int32_t type;
597 CHECK(accessUnit->meta()->findInt32("discontinuity", &type));
598
599 bool formatChange =
600 (mIsAudio &&
601 (type & ATSParser::DISCONTINUITY_AUDIO_FORMAT))
602 || (!mIsAudio &&
603 (type & ATSParser::DISCONTINUITY_VIDEO_FORMAT));
604
605 bool timeChange = (type & ATSParser::DISCONTINUITY_TIME) != 0;
606
607 ALOGI("%s discontinuity (format=%d, time=%d)",
608 mIsAudio ? "audio" : "video", formatChange, timeChange);
609
610 bool seamlessFormatChange = false;
611 sp<AMessage> newFormat = mSource->getFormat(mIsAudio);
612 if (formatChange) {
613 seamlessFormatChange =
614 supportsSeamlessFormatChange(newFormat);
615 // treat seamless format change separately
616 formatChange = !seamlessFormatChange;
617 }
618
Chong Zhang66704af2015-03-03 19:32:35 -0800619 // For format or time change, return EOS to queue EOS input,
620 // then wait for EOS on output.
Chong Zhang7137ec72014-11-12 16:41:05 -0800621 if (formatChange /* not seamless */) {
Chong Zhang7137ec72014-11-12 16:41:05 -0800622 mFormatChangePending = true;
Chong Zhang66704af2015-03-03 19:32:35 -0800623 err = ERROR_END_OF_STREAM;
Chong Zhang7137ec72014-11-12 16:41:05 -0800624 } else if (timeChange) {
Chong Zhang7137ec72014-11-12 16:41:05 -0800625 rememberCodecSpecificData(newFormat);
Chong Zhang66704af2015-03-03 19:32:35 -0800626 mTimeChangePending = true;
627 err = ERROR_END_OF_STREAM;
Chong Zhang7137ec72014-11-12 16:41:05 -0800628 } else if (seamlessFormatChange) {
629 // reuse existing decoder and don't flush
630 rememberCodecSpecificData(newFormat);
Chong Zhang66704af2015-03-03 19:32:35 -0800631 continue;
Chong Zhang7137ec72014-11-12 16:41:05 -0800632 } else {
633 // This stream is unaffected by the discontinuity
634 return -EWOULDBLOCK;
635 }
636 }
637
Chong Zhang66704af2015-03-03 19:32:35 -0800638 // reply should only be returned without a buffer set
639 // when there is an error (including EOS)
640 CHECK(err != OK);
641
Chong Zhang7137ec72014-11-12 16:41:05 -0800642 reply->setInt32("err", err);
Chong Zhang66704af2015-03-03 19:32:35 -0800643 return ERROR_END_OF_STREAM;
Chong Zhang7137ec72014-11-12 16:41:05 -0800644 }
645
646 if (!mIsAudio) {
647 ++mNumFramesTotal;
648 }
649
650 dropAccessUnit = false;
651 if (!mIsAudio
652 && !mIsSecure
653 && mRenderer->getVideoLateByUs() > 100000ll
654 && mIsVideoAVC
655 && !IsAVCReferenceFrame(accessUnit)) {
656 dropAccessUnit = true;
657 ++mNumFramesDropped;
658 }
659 } while (dropAccessUnit);
660
661 // ALOGV("returned a valid buffer of %s data", mIsAudio ? "mIsAudio" : "video");
662#if 0
663 int64_t mediaTimeUs;
664 CHECK(accessUnit->meta()->findInt64("timeUs", &mediaTimeUs));
Chong Zhang5abbd3d2015-04-20 16:03:00 -0700665 ALOGV("[%s] feeding input buffer at media time %.3f",
Chong Zhang7137ec72014-11-12 16:41:05 -0800666 mIsAudio ? "audio" : "video",
667 mediaTimeUs / 1E6);
668#endif
669
670 if (mCCDecoder != NULL) {
671 mCCDecoder->decode(accessUnit);
672 }
673
674 reply->setBuffer("buffer", accessUnit);
675
676 return OK;
677}
678
679bool NuPlayer::Decoder::onInputBufferFetched(const sp<AMessage> &msg) {
Lajos Molnar1cd13982014-01-17 15:12:51 -0800680 size_t bufferIx;
681 CHECK(msg->findSize("buffer-ix", &bufferIx));
682 CHECK_LT(bufferIx, mInputBuffers.size());
683 sp<ABuffer> codecBuffer = mInputBuffers[bufferIx];
684
685 sp<ABuffer> buffer;
686 bool hasBuffer = msg->findBuffer("buffer", &buffer);
Lajos Molnar09524832014-07-17 14:29:51 -0700687
688 // handle widevine classic source - that fills an arbitrary input buffer
689 MediaBuffer *mediaBuffer = NULL;
Wei Jia96e92b52014-09-18 17:36:20 -0700690 if (hasBuffer) {
691 mediaBuffer = (MediaBuffer *)(buffer->getMediaBufferBase());
692 if (mediaBuffer != NULL) {
Lajos Molnar09524832014-07-17 14:29:51 -0700693 // likely filled another buffer than we requested: adjust buffer index
694 size_t ix;
695 for (ix = 0; ix < mInputBuffers.size(); ix++) {
696 const sp<ABuffer> &buf = mInputBuffers[ix];
697 if (buf->data() == mediaBuffer->data()) {
698 // all input buffers are dequeued on start, hence the check
Wei Jia2245fc62014-10-02 15:12:25 -0700699 if (!mInputBufferIsDequeued[ix]) {
700 ALOGV("[%s] received MediaBuffer for #%zu instead of #%zu",
701 mComponentName.c_str(), ix, bufferIx);
702 mediaBuffer->release();
703 return false;
704 }
Lajos Molnar09524832014-07-17 14:29:51 -0700705
706 // TRICKY: need buffer for the metadata, so instead, set
707 // codecBuffer to the same (though incorrect) buffer to
708 // avoid a memcpy into the codecBuffer
709 codecBuffer = buffer;
710 codecBuffer->setRange(
711 mediaBuffer->range_offset(),
712 mediaBuffer->range_length());
713 bufferIx = ix;
714 break;
715 }
716 }
717 CHECK(ix < mInputBuffers.size());
718 }
719 }
720
Lajos Molnar1cd13982014-01-17 15:12:51 -0800721 if (buffer == NULL /* includes !hasBuffer */) {
722 int32_t streamErr = ERROR_END_OF_STREAM;
723 CHECK(msg->findInt32("err", &streamErr) || !hasBuffer);
724
Chong Zhang66704af2015-03-03 19:32:35 -0800725 CHECK(streamErr != OK);
Lajos Molnar1cd13982014-01-17 15:12:51 -0800726
727 // attempt to queue EOS
728 status_t err = mCodec->queueInputBuffer(
729 bufferIx,
730 0,
731 0,
732 0,
733 MediaCodec::BUFFER_FLAG_EOS);
Andy Hungcf31f1e2014-09-23 14:59:01 -0700734 if (err == OK) {
735 mInputBufferIsDequeued.editItemAt(bufferIx) = false;
736 } else if (streamErr == ERROR_END_OF_STREAM) {
Lajos Molnar1cd13982014-01-17 15:12:51 -0800737 streamErr = err;
738 // err will not be ERROR_END_OF_STREAM
739 }
740
741 if (streamErr != ERROR_END_OF_STREAM) {
Andy Hungcf31f1e2014-09-23 14:59:01 -0700742 ALOGE("Stream error for %s (err=%d), EOS %s queued",
743 mComponentName.c_str(),
744 streamErr,
745 err == OK ? "successfully" : "unsuccessfully");
Lajos Molnar1cd13982014-01-17 15:12:51 -0800746 handleError(streamErr);
747 }
748 } else {
Wei Jiac6cfd702014-11-11 16:33:20 -0800749 sp<AMessage> extra;
750 if (buffer->meta()->findMessage("extra", &extra) && extra != NULL) {
751 int64_t resumeAtMediaTimeUs;
752 if (extra->findInt64(
753 "resume-at-mediaTimeUs", &resumeAtMediaTimeUs)) {
754 ALOGI("[%s] suppressing rendering until %lld us",
755 mComponentName.c_str(), (long long)resumeAtMediaTimeUs);
756 mSkipRenderingUntilMediaTimeUs = resumeAtMediaTimeUs;
757 }
758 }
759
Lajos Molnar1cd13982014-01-17 15:12:51 -0800760 int64_t timeUs = 0;
761 uint32_t flags = 0;
762 CHECK(buffer->meta()->findInt64("timeUs", &timeUs));
763
Lajos Molnar87603c02014-08-20 19:25:30 -0700764 int32_t eos, csd;
765 // we do not expect SYNCFRAME for decoder
Lajos Molnar1cd13982014-01-17 15:12:51 -0800766 if (buffer->meta()->findInt32("eos", &eos) && eos) {
767 flags |= MediaCodec::BUFFER_FLAG_EOS;
Lajos Molnar87603c02014-08-20 19:25:30 -0700768 } else if (buffer->meta()->findInt32("csd", &csd) && csd) {
769 flags |= MediaCodec::BUFFER_FLAG_CODECCONFIG;
Lajos Molnar1cd13982014-01-17 15:12:51 -0800770 }
771
772 // copy into codec buffer
773 if (buffer != codecBuffer) {
774 CHECK_LE(buffer->size(), codecBuffer->capacity());
775 codecBuffer->setRange(0, buffer->size());
776 memcpy(codecBuffer->data(), buffer->data(), buffer->size());
777 }
778
779 status_t err = mCodec->queueInputBuffer(
780 bufferIx,
781 codecBuffer->offset(),
782 codecBuffer->size(),
783 timeUs,
784 flags);
785 if (err != OK) {
Andy Hungcf31f1e2014-09-23 14:59:01 -0700786 if (mediaBuffer != NULL) {
787 mediaBuffer->release();
788 }
Lajos Molnar1cd13982014-01-17 15:12:51 -0800789 ALOGE("Failed to queue input buffer for %s (err=%d)",
790 mComponentName.c_str(), err);
791 handleError(err);
Andy Hungcf31f1e2014-09-23 14:59:01 -0700792 } else {
793 mInputBufferIsDequeued.editItemAt(bufferIx) = false;
794 if (mediaBuffer != NULL) {
795 CHECK(mMediaBuffers[bufferIx] == NULL);
796 mMediaBuffers.editItemAt(bufferIx) = mediaBuffer;
797 }
Lajos Molnar09524832014-07-17 14:29:51 -0700798 }
Lajos Molnar1cd13982014-01-17 15:12:51 -0800799 }
Wei Jia2245fc62014-10-02 15:12:25 -0700800 return true;
Lajos Molnar1cd13982014-01-17 15:12:51 -0800801}
802
Lajos Molnar1cd13982014-01-17 15:12:51 -0800803void NuPlayer::Decoder::onRenderBuffer(const sp<AMessage> &msg) {
804 status_t err;
805 int32_t render;
806 size_t bufferIx;
Chong Zhang66704af2015-03-03 19:32:35 -0800807 int32_t eos;
Lajos Molnar1cd13982014-01-17 15:12:51 -0800808 CHECK(msg->findSize("buffer-ix", &bufferIx));
Wei Jiac6cfd702014-11-11 16:33:20 -0800809
Chong Zhang7137ec72014-11-12 16:41:05 -0800810 if (!mIsAudio) {
Wei Jiac6cfd702014-11-11 16:33:20 -0800811 int64_t timeUs;
812 sp<ABuffer> buffer = mOutputBuffers[bufferIx];
813 buffer->meta()->findInt64("timeUs", &timeUs);
Chong Zhang7137ec72014-11-12 16:41:05 -0800814
815 if (mCCDecoder != NULL && mCCDecoder->isSelected()) {
816 mCCDecoder->display(timeUs);
817 }
Wei Jiac6cfd702014-11-11 16:33:20 -0800818 }
819
Lajos Molnar1cd13982014-01-17 15:12:51 -0800820 if (msg->findInt32("render", &render) && render) {
Lajos Molnardc43dfa2014-05-07 15:33:04 -0700821 int64_t timestampNs;
822 CHECK(msg->findInt64("timestampNs", &timestampNs));
823 err = mCodec->renderOutputBufferAndRelease(bufferIx, timestampNs);
Lajos Molnar1cd13982014-01-17 15:12:51 -0800824 } else {
825 err = mCodec->releaseOutputBuffer(bufferIx);
826 }
827 if (err != OK) {
828 ALOGE("failed to release output buffer for %s (err=%d)",
829 mComponentName.c_str(), err);
830 handleError(err);
831 }
Chong Zhang66704af2015-03-03 19:32:35 -0800832 if (msg->findInt32("eos", &eos) && eos
833 && isDiscontinuityPending()) {
834 finishHandleDiscontinuity(true /* flushOnTimeChange */);
835 }
836}
837
838bool NuPlayer::Decoder::isDiscontinuityPending() const {
839 return mFormatChangePending || mTimeChangePending;
840}
841
842void NuPlayer::Decoder::finishHandleDiscontinuity(bool flushOnTimeChange) {
843 ALOGV("finishHandleDiscontinuity: format %d, time %d, flush %d",
844 mFormatChangePending, mTimeChangePending, flushOnTimeChange);
845
846 // If we have format change, pause and wait to be killed;
847 // If we have time change only, flush and restart fetching.
848
849 if (mFormatChangePending) {
850 mPaused = true;
851 } else if (mTimeChangePending) {
852 if (flushOnTimeChange) {
Marco Nelissen421f47c2015-03-25 14:40:32 -0700853 doFlush(false /* notifyComplete */);
854 signalResume(false /* notifyComplete */);
Chong Zhang66704af2015-03-03 19:32:35 -0800855 }
Chong Zhang66704af2015-03-03 19:32:35 -0800856 }
857
858 // Notify NuPlayer to either shutdown decoder, or rescan sources
859 sp<AMessage> msg = mNotify->dup();
860 msg->setInt32("what", kWhatInputDiscontinuity);
861 msg->setInt32("formatChange", mFormatChangePending);
862 msg->post();
863
864 mFormatChangePending = false;
865 mTimeChangePending = false;
Lajos Molnar1cd13982014-01-17 15:12:51 -0800866}
867
Chong Zhang7137ec72014-11-12 16:41:05 -0800868bool NuPlayer::Decoder::supportsSeamlessAudioFormatChange(
869 const sp<AMessage> &targetFormat) const {
Robert Shih6d0a94e2014-01-23 16:18:22 -0800870 if (targetFormat == NULL) {
871 return true;
872 }
873
874 AString mime;
875 if (!targetFormat->findString("mime", &mime)) {
876 return false;
877 }
878
879 if (!strcasecmp(mime.c_str(), MEDIA_MIMETYPE_AUDIO_AAC)) {
880 // field-by-field comparison
881 const char * keys[] = { "channel-count", "sample-rate", "is-adts" };
882 for (unsigned int i = 0; i < sizeof(keys) / sizeof(keys[0]); i++) {
883 int32_t oldVal, newVal;
joakim johansson7abbd4c2015-01-30 14:16:03 +0100884 if (!mInputFormat->findInt32(keys[i], &oldVal) ||
Lajos Molnar1cd13982014-01-17 15:12:51 -0800885 !targetFormat->findInt32(keys[i], &newVal) ||
886 oldVal != newVal) {
Robert Shih6d0a94e2014-01-23 16:18:22 -0800887 return false;
888 }
889 }
890
891 sp<ABuffer> oldBuf, newBuf;
joakim johansson7abbd4c2015-01-30 14:16:03 +0100892 if (mInputFormat->findBuffer("csd-0", &oldBuf) &&
Lajos Molnar1cd13982014-01-17 15:12:51 -0800893 targetFormat->findBuffer("csd-0", &newBuf)) {
Robert Shih6d0a94e2014-01-23 16:18:22 -0800894 if (oldBuf->size() != newBuf->size()) {
895 return false;
896 }
897 return !memcmp(oldBuf->data(), newBuf->data(), oldBuf->size());
898 }
899 }
900 return false;
901}
902
903bool NuPlayer::Decoder::supportsSeamlessFormatChange(const sp<AMessage> &targetFormat) const {
joakim johansson7abbd4c2015-01-30 14:16:03 +0100904 if (mInputFormat == NULL) {
Robert Shih6d0a94e2014-01-23 16:18:22 -0800905 return false;
906 }
907
908 if (targetFormat == NULL) {
909 return true;
910 }
911
912 AString oldMime, newMime;
joakim johansson7abbd4c2015-01-30 14:16:03 +0100913 if (!mInputFormat->findString("mime", &oldMime)
Robert Shih6d0a94e2014-01-23 16:18:22 -0800914 || !targetFormat->findString("mime", &newMime)
915 || !(oldMime == newMime)) {
916 return false;
917 }
918
919 bool audio = !strncasecmp(oldMime.c_str(), "audio/", strlen("audio/"));
920 bool seamless;
921 if (audio) {
922 seamless = supportsSeamlessAudioFormatChange(targetFormat);
923 } else {
Lajos Molnar1cd13982014-01-17 15:12:51 -0800924 int32_t isAdaptive;
925 seamless = (mCodec != NULL &&
926 mInputFormat->findInt32("adaptive-playback", &isAdaptive) &&
927 isAdaptive);
Robert Shih6d0a94e2014-01-23 16:18:22 -0800928 }
929
930 ALOGV("%s seamless support for %s", seamless ? "yes" : "no", oldMime.c_str());
931 return seamless;
932}
933
Chong Zhang7137ec72014-11-12 16:41:05 -0800934void NuPlayer::Decoder::rememberCodecSpecificData(const sp<AMessage> &format) {
935 if (format == NULL) {
Chong Zhangb86e68f2014-08-01 13:46:53 -0700936 return;
937 }
Chong Zhang7137ec72014-11-12 16:41:05 -0800938 mCSDsForCurrentFormat.clear();
939 for (int32_t i = 0; ; ++i) {
940 AString tag = "csd-";
941 tag.append(i);
942 sp<ABuffer> buffer;
943 if (!format->findBuffer(tag.c_str(), &buffer)) {
944 break;
945 }
946 mCSDsForCurrentFormat.push(buffer);
Chong Zhanga7fa1d92014-06-11 14:49:23 -0700947 }
Chong Zhangb86e68f2014-08-01 13:46:53 -0700948}
949
Chong Zhangf8d71772014-11-26 15:08:34 -0800950void NuPlayer::Decoder::notifyResumeCompleteIfNecessary() {
951 if (mResumePending) {
952 mResumePending = false;
953
954 sp<AMessage> notify = mNotify->dup();
955 notify->setInt32("what", kWhatResumeCompleted);
956 notify->post();
957 }
958}
959
Andreas Huberf9334412010-12-15 15:17:42 -0800960} // namespace android
961