Wei Jia | bc2fb72 | 2014-07-08 16:37:57 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 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 "NuPlayerDecoderPassThrough" |
| 19 | #include <utils/Log.h> |
| 20 | #include <inttypes.h> |
| 21 | |
| 22 | #include "NuPlayerDecoderPassThrough.h" |
| 23 | |
Wei Jia | c6cfd70 | 2014-11-11 16:33:20 -0800 | [diff] [blame] | 24 | #include "NuPlayerRenderer.h" |
| 25 | #include "NuPlayerSource.h" |
| 26 | |
Wei Jia | bc2fb72 | 2014-07-08 16:37:57 -0700 | [diff] [blame] | 27 | #include <media/ICrypto.h> |
| 28 | #include <media/stagefright/foundation/ABuffer.h> |
| 29 | #include <media/stagefright/foundation/ADebug.h> |
| 30 | #include <media/stagefright/foundation/AMessage.h> |
Wei Jia | bc2fb72 | 2014-07-08 16:37:57 -0700 | [diff] [blame] | 31 | #include <media/stagefright/MediaErrors.h> |
| 32 | |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 33 | #include "ATSParser.h" |
| 34 | |
Wei Jia | bc2fb72 | 2014-07-08 16:37:57 -0700 | [diff] [blame] | 35 | namespace android { |
| 36 | |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 37 | // TODO optimize buffer size for power consumption |
| 38 | // The offload read buffer size is 32 KB but 24 KB uses less power. |
| 39 | static const size_t kAggregateBufferSizeBytes = 24 * 1024; |
Phil Burk | c5cc2e2 | 2014-09-09 20:08:39 -0700 | [diff] [blame] | 40 | static const size_t kMaxCachedBytes = 200000; |
Wei Jia | bc2fb72 | 2014-07-08 16:37:57 -0700 | [diff] [blame] | 41 | |
| 42 | NuPlayer::DecoderPassThrough::DecoderPassThrough( |
Wei Jia | c6cfd70 | 2014-11-11 16:33:20 -0800 | [diff] [blame] | 43 | const sp<AMessage> ¬ify, |
| 44 | const sp<Source> &source, |
| 45 | const sp<Renderer> &renderer) |
Andy Hung | 202bce1 | 2014-12-03 11:47:36 -0800 | [diff] [blame] | 46 | : DecoderBase(notify), |
Wei Jia | c6cfd70 | 2014-11-11 16:33:20 -0800 | [diff] [blame] | 47 | mSource(source), |
| 48 | mRenderer(renderer), |
| 49 | mSkipRenderingUntilMediaTimeUs(-1ll), |
Ronghua Wu | f182891 | 2014-12-01 15:33:36 -0800 | [diff] [blame] | 50 | mPaused(false), |
Wei Jia | bc2fb72 | 2014-07-08 16:37:57 -0700 | [diff] [blame] | 51 | mReachedEOS(true), |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 52 | mPendingAudioErr(OK), |
Phil Burk | c5cc2e2 | 2014-09-09 20:08:39 -0700 | [diff] [blame] | 53 | mPendingBuffersToDrain(0), |
Chong Zhang | de01afb | 2014-08-13 13:48:10 -0700 | [diff] [blame] | 54 | mCachedBytes(0), |
Wei Jia | bc2fb72 | 2014-07-08 16:37:57 -0700 | [diff] [blame] | 55 | mComponentName("pass through decoder") { |
Wei Jia | c6cfd70 | 2014-11-11 16:33:20 -0800 | [diff] [blame] | 56 | ALOGW_IF(renderer == NULL, "expect a non-NULL renderer"); |
Wei Jia | bc2fb72 | 2014-07-08 16:37:57 -0700 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | NuPlayer::DecoderPassThrough::~DecoderPassThrough() { |
| 60 | } |
| 61 | |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 62 | void NuPlayer::DecoderPassThrough::getStats( |
| 63 | int64_t *numFramesTotal, int64_t *numFramesDropped) const { |
| 64 | *numFramesTotal = 0; |
| 65 | *numFramesDropped = 0; |
Wei Jia | bc2fb72 | 2014-07-08 16:37:57 -0700 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | void NuPlayer::DecoderPassThrough::onConfigure(const sp<AMessage> &format) { |
| 69 | ALOGV("[%s] onConfigure", mComponentName.c_str()); |
Chong Zhang | de01afb | 2014-08-13 13:48:10 -0700 | [diff] [blame] | 70 | mCachedBytes = 0; |
Phil Burk | c5cc2e2 | 2014-09-09 20:08:39 -0700 | [diff] [blame] | 71 | mPendingBuffersToDrain = 0; |
Wei Jia | bc2fb72 | 2014-07-08 16:37:57 -0700 | [diff] [blame] | 72 | mReachedEOS = false; |
| 73 | ++mBufferGeneration; |
| 74 | |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 75 | onRequestInputBuffers(); |
Wei Jia | bc2fb72 | 2014-07-08 16:37:57 -0700 | [diff] [blame] | 76 | |
Haynes Mathew George | 8b63533 | 2015-03-30 17:59:47 -0700 | [diff] [blame] | 77 | int32_t hasVideo = 0; |
| 78 | format->findInt32("has-video", &hasVideo); |
| 79 | |
Andy Hung | 202bce1 | 2014-12-03 11:47:36 -0800 | [diff] [blame] | 80 | // The audio sink is already opened before the PassThrough decoder is created. |
| 81 | // Opening again might be relevant if decoder is instantiated after shutdown and |
| 82 | // format is different. |
| 83 | status_t err = mRenderer->openAudioSink( |
Haynes Mathew George | 8b63533 | 2015-03-30 17:59:47 -0700 | [diff] [blame] | 84 | format, true /* offloadOnly */, hasVideo, |
Andy Hung | 202bce1 | 2014-12-03 11:47:36 -0800 | [diff] [blame] | 85 | AUDIO_OUTPUT_FLAG_NONE /* flags */, NULL /* isOffloaded */); |
| 86 | if (err != OK) { |
| 87 | handleError(err); |
Wei Jia | c6cfd70 | 2014-11-11 16:33:20 -0800 | [diff] [blame] | 88 | } |
Wei Jia | bc2fb72 | 2014-07-08 16:37:57 -0700 | [diff] [blame] | 89 | } |
| 90 | |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 91 | void NuPlayer::DecoderPassThrough::onSetRenderer( |
| 92 | const sp<Renderer> &renderer) { |
| 93 | // renderer can't be changed during offloading |
| 94 | ALOGW_IF(renderer != mRenderer, |
| 95 | "ignoring request to change renderer"); |
| 96 | } |
| 97 | |
| 98 | void NuPlayer::DecoderPassThrough::onGetInputBuffers( |
| 99 | Vector<sp<ABuffer> > * /* dstBuffers */) { |
| 100 | ALOGE("onGetInputBuffers() called unexpectedly"); |
| 101 | } |
| 102 | |
Wei Jia | bc2fb72 | 2014-07-08 16:37:57 -0700 | [diff] [blame] | 103 | bool NuPlayer::DecoderPassThrough::isStaleReply(const sp<AMessage> &msg) { |
| 104 | int32_t generation; |
| 105 | CHECK(msg->findInt32("generation", &generation)); |
| 106 | return generation != mBufferGeneration; |
| 107 | } |
| 108 | |
Ronghua Wu | f182891 | 2014-12-01 15:33:36 -0800 | [diff] [blame] | 109 | bool NuPlayer::DecoderPassThrough::isDoneFetching() const { |
| 110 | ALOGV("[%s] mCachedBytes = %zu, mReachedEOS = %d mPaused = %d", |
| 111 | mComponentName.c_str(), mCachedBytes, mReachedEOS, mPaused); |
Wei Jia | bc2fb72 | 2014-07-08 16:37:57 -0700 | [diff] [blame] | 112 | |
Ronghua Wu | f182891 | 2014-12-01 15:33:36 -0800 | [diff] [blame] | 113 | return mCachedBytes >= kMaxCachedBytes || mReachedEOS || mPaused; |
Wei Jia | bc2fb72 | 2014-07-08 16:37:57 -0700 | [diff] [blame] | 114 | } |
| 115 | |
Chong Zhang | 3b032b3 | 2015-04-17 15:49:06 -0700 | [diff] [blame^] | 116 | /* |
| 117 | * returns true if we should request more data |
| 118 | */ |
| 119 | bool NuPlayer::DecoderPassThrough::doRequestBuffers() { |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 120 | status_t err = OK; |
Ronghua Wu | f182891 | 2014-12-01 15:33:36 -0800 | [diff] [blame] | 121 | while (!isDoneFetching()) { |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 122 | sp<AMessage> msg = new AMessage(); |
| 123 | |
| 124 | err = fetchInputData(msg); |
| 125 | if (err != OK) { |
| 126 | break; |
| 127 | } |
| 128 | |
| 129 | onInputBufferFetched(msg); |
| 130 | } |
| 131 | |
Chong Zhang | 3b032b3 | 2015-04-17 15:49:06 -0700 | [diff] [blame^] | 132 | return err == -EWOULDBLOCK |
| 133 | && mSource->feedMoreTSData() == OK; |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | status_t NuPlayer::DecoderPassThrough::dequeueAccessUnit(sp<ABuffer> *accessUnit) { |
| 137 | status_t err; |
| 138 | |
| 139 | // Did we save an accessUnit earlier because of a discontinuity? |
| 140 | if (mPendingAudioAccessUnit != NULL) { |
| 141 | *accessUnit = mPendingAudioAccessUnit; |
| 142 | mPendingAudioAccessUnit.clear(); |
| 143 | err = mPendingAudioErr; |
| 144 | ALOGV("feedDecoderInputData() use mPendingAudioAccessUnit"); |
| 145 | } else { |
| 146 | err = mSource->dequeueAccessUnit(true /* audio */, accessUnit); |
| 147 | } |
| 148 | |
| 149 | if (err == INFO_DISCONTINUITY || err == ERROR_END_OF_STREAM) { |
| 150 | if (mAggregateBuffer != NULL) { |
| 151 | // We already have some data so save this for later. |
| 152 | mPendingAudioErr = err; |
| 153 | mPendingAudioAccessUnit = *accessUnit; |
| 154 | (*accessUnit).clear(); |
| 155 | ALOGD("return aggregated buffer and save err(=%d) for later", err); |
| 156 | err = OK; |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | return err; |
| 161 | } |
| 162 | |
| 163 | sp<ABuffer> NuPlayer::DecoderPassThrough::aggregateBuffer( |
| 164 | const sp<ABuffer> &accessUnit) { |
| 165 | sp<ABuffer> aggregate; |
| 166 | |
| 167 | if (accessUnit == NULL) { |
| 168 | // accessUnit is saved to mPendingAudioAccessUnit |
| 169 | // return current mAggregateBuffer |
| 170 | aggregate = mAggregateBuffer; |
| 171 | mAggregateBuffer.clear(); |
| 172 | return aggregate; |
| 173 | } |
| 174 | |
| 175 | size_t smallSize = accessUnit->size(); |
| 176 | if ((mAggregateBuffer == NULL) |
| 177 | // Don't bother if only room for a few small buffers. |
| 178 | && (smallSize < (kAggregateBufferSizeBytes / 3))) { |
| 179 | // Create a larger buffer for combining smaller buffers from the extractor. |
| 180 | mAggregateBuffer = new ABuffer(kAggregateBufferSizeBytes); |
| 181 | mAggregateBuffer->setRange(0, 0); // start empty |
| 182 | } |
| 183 | |
| 184 | if (mAggregateBuffer != NULL) { |
| 185 | int64_t timeUs; |
| 186 | int64_t dummy; |
| 187 | bool smallTimestampValid = accessUnit->meta()->findInt64("timeUs", &timeUs); |
| 188 | bool bigTimestampValid = mAggregateBuffer->meta()->findInt64("timeUs", &dummy); |
| 189 | // Will the smaller buffer fit? |
| 190 | size_t bigSize = mAggregateBuffer->size(); |
| 191 | size_t roomLeft = mAggregateBuffer->capacity() - bigSize; |
| 192 | // Should we save this small buffer for the next big buffer? |
| 193 | // If the first small buffer did not have a timestamp then save |
| 194 | // any buffer that does have a timestamp until the next big buffer. |
| 195 | if ((smallSize > roomLeft) |
| 196 | || (!bigTimestampValid && (bigSize > 0) && smallTimestampValid)) { |
| 197 | mPendingAudioErr = OK; |
| 198 | mPendingAudioAccessUnit = accessUnit; |
| 199 | aggregate = mAggregateBuffer; |
| 200 | mAggregateBuffer.clear(); |
| 201 | } else { |
| 202 | // Grab time from first small buffer if available. |
| 203 | if ((bigSize == 0) && smallTimestampValid) { |
| 204 | mAggregateBuffer->meta()->setInt64("timeUs", timeUs); |
| 205 | } |
| 206 | // Append small buffer to the bigger buffer. |
| 207 | memcpy(mAggregateBuffer->base() + bigSize, accessUnit->data(), smallSize); |
| 208 | bigSize += smallSize; |
| 209 | mAggregateBuffer->setRange(0, bigSize); |
| 210 | |
| 211 | ALOGV("feedDecoderInputData() smallSize = %zu, bigSize = %zu, capacity = %zu", |
| 212 | smallSize, bigSize, mAggregateBuffer->capacity()); |
| 213 | } |
| 214 | } else { |
| 215 | // decided not to aggregate |
| 216 | aggregate = accessUnit; |
| 217 | } |
| 218 | |
| 219 | return aggregate; |
| 220 | } |
| 221 | |
| 222 | status_t NuPlayer::DecoderPassThrough::fetchInputData(sp<AMessage> &reply) { |
| 223 | sp<ABuffer> accessUnit; |
| 224 | |
| 225 | do { |
| 226 | status_t err = dequeueAccessUnit(&accessUnit); |
| 227 | |
| 228 | if (err == -EWOULDBLOCK) { |
| 229 | return err; |
| 230 | } else if (err != OK) { |
| 231 | if (err == INFO_DISCONTINUITY) { |
| 232 | int32_t type; |
| 233 | CHECK(accessUnit->meta()->findInt32("discontinuity", &type)); |
| 234 | |
| 235 | bool formatChange = |
| 236 | (type & ATSParser::DISCONTINUITY_AUDIO_FORMAT) != 0; |
| 237 | |
| 238 | bool timeChange = |
| 239 | (type & ATSParser::DISCONTINUITY_TIME) != 0; |
| 240 | |
| 241 | ALOGI("audio discontinuity (formatChange=%d, time=%d)", |
| 242 | formatChange, timeChange); |
| 243 | |
| 244 | if (formatChange || timeChange) { |
| 245 | sp<AMessage> msg = mNotify->dup(); |
| 246 | msg->setInt32("what", kWhatInputDiscontinuity); |
| 247 | // will perform seamless format change, |
| 248 | // only notify NuPlayer to scan sources |
| 249 | msg->setInt32("formatChange", false); |
| 250 | msg->post(); |
| 251 | } |
| 252 | |
| 253 | if (timeChange) { |
Chong Zhang | 66704af | 2015-03-03 19:32:35 -0800 | [diff] [blame] | 254 | doFlush(false /* notifyComplete */); |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 255 | err = OK; |
| 256 | } else if (formatChange) { |
| 257 | // do seamless format change |
| 258 | err = OK; |
| 259 | } else { |
| 260 | // This stream is unaffected by the discontinuity |
| 261 | return -EWOULDBLOCK; |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | reply->setInt32("err", err); |
| 266 | return OK; |
| 267 | } |
| 268 | |
| 269 | accessUnit = aggregateBuffer(accessUnit); |
| 270 | } while (accessUnit == NULL); |
| 271 | |
| 272 | #if 0 |
| 273 | int64_t mediaTimeUs; |
| 274 | CHECK(accessUnit->meta()->findInt64("timeUs", &mediaTimeUs)); |
| 275 | ALOGV("feeding audio input buffer at media time %.2f secs", |
| 276 | mediaTimeUs / 1E6); |
| 277 | #endif |
| 278 | |
| 279 | reply->setBuffer("buffer", accessUnit); |
| 280 | |
| 281 | return OK; |
| 282 | } |
| 283 | |
| 284 | void NuPlayer::DecoderPassThrough::onInputBufferFetched( |
Wei Jia | bc2fb72 | 2014-07-08 16:37:57 -0700 | [diff] [blame] | 285 | const sp<AMessage> &msg) { |
| 286 | if (mReachedEOS) { |
| 287 | return; |
| 288 | } |
| 289 | |
| 290 | sp<ABuffer> buffer; |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 291 | bool hasBuffer = msg->findBuffer("buffer", &buffer); |
Wei Jia | bc2fb72 | 2014-07-08 16:37:57 -0700 | [diff] [blame] | 292 | if (buffer == NULL) { |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 293 | int32_t streamErr = ERROR_END_OF_STREAM; |
| 294 | CHECK(msg->findInt32("err", &streamErr) || !hasBuffer); |
| 295 | if (streamErr == OK) { |
| 296 | return; |
| 297 | } |
| 298 | |
Wei Jia | bc2fb72 | 2014-07-08 16:37:57 -0700 | [diff] [blame] | 299 | mReachedEOS = true; |
Wei Jia | c6cfd70 | 2014-11-11 16:33:20 -0800 | [diff] [blame] | 300 | if (mRenderer != NULL) { |
| 301 | mRenderer->queueEOS(true /* audio */, ERROR_END_OF_STREAM); |
| 302 | } |
Wei Jia | bc2fb72 | 2014-07-08 16:37:57 -0700 | [diff] [blame] | 303 | return; |
| 304 | } |
| 305 | |
Wei Jia | c6cfd70 | 2014-11-11 16:33:20 -0800 | [diff] [blame] | 306 | sp<AMessage> extra; |
| 307 | if (buffer->meta()->findMessage("extra", &extra) && extra != NULL) { |
| 308 | int64_t resumeAtMediaTimeUs; |
| 309 | if (extra->findInt64( |
| 310 | "resume-at-mediatimeUs", &resumeAtMediaTimeUs)) { |
| 311 | ALOGI("[%s] suppressing rendering until %lld us", |
| 312 | mComponentName.c_str(), (long long)resumeAtMediaTimeUs); |
| 313 | mSkipRenderingUntilMediaTimeUs = resumeAtMediaTimeUs; |
| 314 | } |
| 315 | } |
| 316 | |
| 317 | int32_t bufferSize = buffer->size(); |
| 318 | mCachedBytes += bufferSize; |
| 319 | |
| 320 | if (mSkipRenderingUntilMediaTimeUs >= 0) { |
| 321 | int64_t timeUs = 0; |
| 322 | CHECK(buffer->meta()->findInt64("timeUs", &timeUs)); |
| 323 | |
| 324 | if (timeUs < mSkipRenderingUntilMediaTimeUs) { |
| 325 | ALOGV("[%s] dropping buffer at time %lld as requested.", |
| 326 | mComponentName.c_str(), (long long)timeUs); |
| 327 | |
| 328 | onBufferConsumed(bufferSize); |
| 329 | return; |
| 330 | } |
| 331 | |
| 332 | mSkipRenderingUntilMediaTimeUs = -1; |
| 333 | } |
| 334 | |
| 335 | if (mRenderer == NULL) { |
| 336 | onBufferConsumed(bufferSize); |
| 337 | return; |
| 338 | } |
Chong Zhang | de01afb | 2014-08-13 13:48:10 -0700 | [diff] [blame] | 339 | |
Lajos Molnar | 1d15ab5 | 2015-03-04 16:46:34 -0800 | [diff] [blame] | 340 | sp<AMessage> reply = new AMessage(kWhatBufferConsumed, this); |
Wei Jia | bc2fb72 | 2014-07-08 16:37:57 -0700 | [diff] [blame] | 341 | reply->setInt32("generation", mBufferGeneration); |
Wei Jia | c6cfd70 | 2014-11-11 16:33:20 -0800 | [diff] [blame] | 342 | reply->setInt32("size", bufferSize); |
Wei Jia | bc2fb72 | 2014-07-08 16:37:57 -0700 | [diff] [blame] | 343 | |
Wei Jia | c6cfd70 | 2014-11-11 16:33:20 -0800 | [diff] [blame] | 344 | mRenderer->queueBuffer(true /* audio */, buffer, reply); |
| 345 | |
Phil Burk | c5cc2e2 | 2014-09-09 20:08:39 -0700 | [diff] [blame] | 346 | ++mPendingBuffersToDrain; |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 347 | ALOGV("onInputBufferFilled: #ToDrain = %zu, cachedBytes = %zu", |
| 348 | mPendingBuffersToDrain, mCachedBytes); |
Wei Jia | bc2fb72 | 2014-07-08 16:37:57 -0700 | [diff] [blame] | 349 | } |
| 350 | |
Chong Zhang | de01afb | 2014-08-13 13:48:10 -0700 | [diff] [blame] | 351 | void NuPlayer::DecoderPassThrough::onBufferConsumed(int32_t size) { |
Phil Burk | c5cc2e2 | 2014-09-09 20:08:39 -0700 | [diff] [blame] | 352 | --mPendingBuffersToDrain; |
Chong Zhang | de01afb | 2014-08-13 13:48:10 -0700 | [diff] [blame] | 353 | mCachedBytes -= size; |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 354 | ALOGV("onBufferConsumed: #ToDrain = %zu, cachedBytes = %zu", |
| 355 | mPendingBuffersToDrain, mCachedBytes); |
| 356 | onRequestInputBuffers(); |
Wei Jia | bc2fb72 | 2014-07-08 16:37:57 -0700 | [diff] [blame] | 357 | } |
| 358 | |
Chong Zhang | f8d7177 | 2014-11-26 15:08:34 -0800 | [diff] [blame] | 359 | void NuPlayer::DecoderPassThrough::onResume(bool notifyComplete) { |
Ronghua Wu | f182891 | 2014-12-01 15:33:36 -0800 | [diff] [blame] | 360 | mPaused = false; |
| 361 | |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 362 | onRequestInputBuffers(); |
Chong Zhang | f8d7177 | 2014-11-26 15:08:34 -0800 | [diff] [blame] | 363 | |
| 364 | if (notifyComplete) { |
| 365 | sp<AMessage> notify = mNotify->dup(); |
| 366 | notify->setInt32("what", kWhatResumeCompleted); |
| 367 | notify->post(); |
| 368 | } |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 369 | } |
| 370 | |
Chong Zhang | 66704af | 2015-03-03 19:32:35 -0800 | [diff] [blame] | 371 | void NuPlayer::DecoderPassThrough::doFlush(bool notifyComplete) { |
Wei Jia | bc2fb72 | 2014-07-08 16:37:57 -0700 | [diff] [blame] | 372 | ++mBufferGeneration; |
Wei Jia | c6cfd70 | 2014-11-11 16:33:20 -0800 | [diff] [blame] | 373 | mSkipRenderingUntilMediaTimeUs = -1; |
Ronghua Wu | f182891 | 2014-12-01 15:33:36 -0800 | [diff] [blame] | 374 | mPendingAudioAccessUnit.clear(); |
| 375 | mPendingAudioErr = OK; |
| 376 | mAggregateBuffer.clear(); |
Wei Jia | c6cfd70 | 2014-11-11 16:33:20 -0800 | [diff] [blame] | 377 | |
| 378 | if (mRenderer != NULL) { |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 379 | mRenderer->flush(true /* audio */, notifyComplete); |
| 380 | mRenderer->signalTimeDiscontinuity(); |
Wei Jia | c6cfd70 | 2014-11-11 16:33:20 -0800 | [diff] [blame] | 381 | } |
Wei Jia | bc2fb72 | 2014-07-08 16:37:57 -0700 | [diff] [blame] | 382 | |
Phil Burk | c5cc2e2 | 2014-09-09 20:08:39 -0700 | [diff] [blame] | 383 | mPendingBuffersToDrain = 0; |
Chong Zhang | de01afb | 2014-08-13 13:48:10 -0700 | [diff] [blame] | 384 | mCachedBytes = 0; |
Wei Jia | bc2fb72 | 2014-07-08 16:37:57 -0700 | [diff] [blame] | 385 | mReachedEOS = false; |
| 386 | } |
| 387 | |
Chong Zhang | 66704af | 2015-03-03 19:32:35 -0800 | [diff] [blame] | 388 | void NuPlayer::DecoderPassThrough::onFlush() { |
| 389 | doFlush(true /* notifyComplete */); |
| 390 | |
| 391 | mPaused = true; |
| 392 | sp<AMessage> notify = mNotify->dup(); |
| 393 | notify->setInt32("what", kWhatFlushCompleted); |
| 394 | notify->post(); |
| 395 | |
| 396 | } |
| 397 | |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 398 | void NuPlayer::DecoderPassThrough::onShutdown(bool notifyComplete) { |
Wei Jia | bc2fb72 | 2014-07-08 16:37:57 -0700 | [diff] [blame] | 399 | ++mBufferGeneration; |
Wei Jia | c6cfd70 | 2014-11-11 16:33:20 -0800 | [diff] [blame] | 400 | mSkipRenderingUntilMediaTimeUs = -1; |
Wei Jia | bc2fb72 | 2014-07-08 16:37:57 -0700 | [diff] [blame] | 401 | |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 402 | if (notifyComplete) { |
| 403 | sp<AMessage> notify = mNotify->dup(); |
| 404 | notify->setInt32("what", kWhatShutdownCompleted); |
| 405 | notify->post(); |
| 406 | } |
| 407 | |
Wei Jia | bc2fb72 | 2014-07-08 16:37:57 -0700 | [diff] [blame] | 408 | mReachedEOS = true; |
| 409 | } |
| 410 | |
| 411 | void NuPlayer::DecoderPassThrough::onMessageReceived(const sp<AMessage> &msg) { |
| 412 | ALOGV("[%s] onMessage: %s", mComponentName.c_str(), |
| 413 | msg->debugString().c_str()); |
| 414 | |
| 415 | switch (msg->what()) { |
Wei Jia | bc2fb72 | 2014-07-08 16:37:57 -0700 | [diff] [blame] | 416 | case kWhatBufferConsumed: |
| 417 | { |
| 418 | if (!isStaleReply(msg)) { |
Chong Zhang | de01afb | 2014-08-13 13:48:10 -0700 | [diff] [blame] | 419 | int32_t size; |
| 420 | CHECK(msg->findInt32("size", &size)); |
| 421 | onBufferConsumed(size); |
Wei Jia | bc2fb72 | 2014-07-08 16:37:57 -0700 | [diff] [blame] | 422 | } |
| 423 | break; |
| 424 | } |
| 425 | |
Wei Jia | bc2fb72 | 2014-07-08 16:37:57 -0700 | [diff] [blame] | 426 | default: |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 427 | DecoderBase::onMessageReceived(msg); |
Wei Jia | bc2fb72 | 2014-07-08 16:37:57 -0700 | [diff] [blame] | 428 | break; |
| 429 | } |
| 430 | } |
| 431 | |
| 432 | } // namespace android |