| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "media/base/android/media_codec_decoder.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" |
| 9 #include "base/callback_helpers.h" |
| 10 #include "base/logging.h" |
| 11 #include "media/base/android/media_codec_bridge.h" |
| 12 |
| 13 namespace media { |
| 14 |
| 15 namespace { |
| 16 |
| 17 // Stop requesting new data in the kPrefetching state when the queue size |
| 18 // reaches this limit. |
| 19 const int kPrefetchLimit = 8; |
| 20 |
| 21 // Request new data in the kRunning state if the queue size is less than this. |
| 22 const int kPlaybackLowLimit = 4; |
| 23 |
| 24 // Posting delay of the next frame processing, in milliseconds |
| 25 const int kNextFrameDelay = 1; |
| 26 |
| 27 // Timeout for dequeuing an input buffer from MediaCodec in milliseconds. |
| 28 const int kInputBufferTimeout = 20; |
| 29 |
| 30 // Timeout for dequeuing an output buffer from MediaCodec in milliseconds. |
| 31 const int kOutputBufferTimeout = 20; |
| 32 } |
| 33 |
| 34 MediaCodecDecoder::MediaCodecDecoder( |
| 35 const scoped_refptr<base::SingleThreadTaskRunner>& media_task_runner, |
| 36 const base::Closure& request_data_cb, |
| 37 const base::Closure& starvation_cb, |
| 38 const base::Closure& stop_done_cb, |
| 39 const base::Closure& error_cb, |
| 40 const char* decoder_thread_name) |
| 41 : media_task_runner_(media_task_runner), |
| 42 decoder_thread_(decoder_thread_name), |
| 43 request_data_cb_(request_data_cb), |
| 44 starvation_cb_(starvation_cb), |
| 45 stop_done_cb_(stop_done_cb), |
| 46 error_cb_(error_cb), |
| 47 state_(kStopped), |
| 48 eos_enqueued_(false), |
| 49 completed_(false), |
| 50 last_frame_posted_(false), |
| 51 weak_factory_(this) { |
| 52 DCHECK(media_task_runner_->BelongsToCurrentThread()); |
| 53 |
| 54 DVLOG(1) << "Decoder::Decoder() " << decoder_thread_name; |
| 55 |
| 56 internal_error_cb_ = |
| 57 base::Bind(&MediaCodecDecoder::OnCodecError, weak_factory_.GetWeakPtr()); |
| 58 } |
| 59 |
| 60 MediaCodecDecoder::~MediaCodecDecoder() { |
| 61 DCHECK(media_task_runner_->BelongsToCurrentThread()); |
| 62 |
| 63 DVLOG(1) << "Decoder::~Decoder()"; |
| 64 |
| 65 // NB: ReleaseDecoderResources() is virtual |
| 66 ReleaseDecoderResources(); |
| 67 } |
| 68 |
| 69 void MediaCodecDecoder::ReleaseDecoderResources() { |
| 70 DCHECK(media_task_runner_->BelongsToCurrentThread()); |
| 71 |
| 72 DVLOG(1) << class_name() << "::" << __FUNCTION__; |
| 73 |
| 74 decoder_thread_.Stop(); // synchronous |
| 75 state_ = kStopped; |
| 76 media_codec_bridge_.reset(); |
| 77 } |
| 78 |
| 79 void MediaCodecDecoder::Flush() { |
| 80 DCHECK(media_task_runner_->BelongsToCurrentThread()); |
| 81 |
| 82 DVLOG(1) << class_name() << "::" << __FUNCTION__; |
| 83 |
| 84 DCHECK_EQ(GetState(), kStopped); |
| 85 |
| 86 eos_enqueued_ = false; |
| 87 completed_ = false; |
| 88 au_queue_.Flush(); |
| 89 |
| 90 if (media_codec_bridge_) { |
| 91 // MediaCodecBridge::Reset() performs MediaCodecBridge.flush() |
| 92 MediaCodecStatus flush_status = media_codec_bridge_->Reset(); |
| 93 if (flush_status != MEDIA_CODEC_OK) { |
| 94 DVLOG(0) << class_name() << "::" << __FUNCTION__ |
| 95 << "MediaCodecBridge::Reset() failed"; |
| 96 media_task_runner_->PostTask(FROM_HERE, internal_error_cb_); |
| 97 } |
| 98 } |
| 99 } |
| 100 |
| 101 void MediaCodecDecoder::ReleaseMediaCodec() { |
| 102 DCHECK(media_task_runner_->BelongsToCurrentThread()); |
| 103 |
| 104 DVLOG(1) << class_name() << "::" << __FUNCTION__; |
| 105 |
| 106 media_codec_bridge_.reset(); |
| 107 } |
| 108 |
| 109 bool MediaCodecDecoder::IsPrefetchingOrPlaying() const { |
| 110 DCHECK(media_task_runner_->BelongsToCurrentThread()); |
| 111 |
| 112 base::AutoLock lock(state_lock_); |
| 113 return state_ == kPrefetching || state_ == kRunning; |
| 114 } |
| 115 |
| 116 bool MediaCodecDecoder::IsStopped() const { |
| 117 DCHECK(media_task_runner_->BelongsToCurrentThread()); |
| 118 |
| 119 return GetState() == kStopped; |
| 120 } |
| 121 |
| 122 bool MediaCodecDecoder::IsCompleted() const { |
| 123 DCHECK(media_task_runner_->BelongsToCurrentThread()); |
| 124 |
| 125 return completed_; |
| 126 } |
| 127 |
| 128 base::android::ScopedJavaLocalRef<jobject> MediaCodecDecoder::GetMediaCrypto() { |
| 129 base::android::ScopedJavaLocalRef<jobject> media_crypto; |
| 130 |
| 131 // TODO(timav): implement DRM. |
| 132 // drm_bridge_ is not implemented |
| 133 // if (drm_bridge_) |
| 134 // media_crypto = drm_bridge_->GetMediaCrypto(); |
| 135 return media_crypto; |
| 136 } |
| 137 |
| 138 void MediaCodecDecoder::Prefetch(const base::Closure& prefetch_done_cb) { |
| 139 DCHECK(media_task_runner_->BelongsToCurrentThread()); |
| 140 |
| 141 DVLOG(1) << class_name() << "::" << __FUNCTION__; |
| 142 |
| 143 DCHECK(GetState() == kStopped); |
| 144 |
| 145 prefetch_done_cb_ = prefetch_done_cb; |
| 146 |
| 147 SetState(kPrefetching); |
| 148 PrefetchNextChunk(); |
| 149 } |
| 150 |
| 151 MediaCodecDecoder::ConfigStatus MediaCodecDecoder::Configure() { |
| 152 DCHECK(media_task_runner_->BelongsToCurrentThread()); |
| 153 |
| 154 DVLOG(1) << class_name() << "::" << __FUNCTION__; |
| 155 |
| 156 if (GetState() == kError) { |
| 157 DVLOG(0) << class_name() << "::" << __FUNCTION__ << ": wrong state kError"; |
| 158 return CONFIG_FAILURE; |
| 159 } |
| 160 |
| 161 // Here I assume that OnDemuxerConfigsAvailable won't come |
| 162 // in the middle of demuxer data. |
| 163 |
| 164 if (media_codec_bridge_) { |
| 165 DVLOG(1) << class_name() << "::" << __FUNCTION__ |
| 166 << ": reconfiguration is not required, ignoring"; |
| 167 return CONFIG_OK; |
| 168 } |
| 169 |
| 170 return ConfigureInternal(); |
| 171 } |
| 172 |
| 173 bool MediaCodecDecoder::Start(base::TimeDelta current_time) { |
| 174 DCHECK(media_task_runner_->BelongsToCurrentThread()); |
| 175 |
| 176 DVLOG(1) << class_name() << "::" << __FUNCTION__ |
| 177 << " current_time:" << current_time; |
| 178 |
| 179 DecoderState state = GetState(); |
| 180 if (state == kRunning) { |
| 181 DVLOG(1) << class_name() << "::" << __FUNCTION__ << ": already started"; |
| 182 return true; // already started |
| 183 } |
| 184 |
| 185 if (state != kPrefetched) { |
| 186 DVLOG(0) << class_name() << "::" << __FUNCTION__ << ": wrong state " |
| 187 << AsString(state) << " ignoring"; |
| 188 return false; |
| 189 } |
| 190 |
| 191 if (!media_codec_bridge_) { |
| 192 DVLOG(0) << class_name() << "::" << __FUNCTION__ |
| 193 << ": not configured, ignoring"; |
| 194 return false; |
| 195 } |
| 196 |
| 197 DCHECK(!decoder_thread_.IsRunning()); |
| 198 |
| 199 // We only synchronize video stream. |
| 200 // When audio is present, the |current_time| is audio time. |
| 201 SynchronizePTSWithTime(current_time); |
| 202 |
| 203 last_frame_posted_ = false; |
| 204 |
| 205 // Start the decoder thread |
| 206 if (!decoder_thread_.Start()) { |
| 207 DVLOG(1) << class_name() << "::" << __FUNCTION__ |
| 208 << ": cannot start decoder thread"; |
| 209 return false; |
| 210 } |
| 211 |
| 212 SetState(kRunning); |
| 213 |
| 214 decoder_thread_.task_runner()->PostTask( |
| 215 FROM_HERE, |
| 216 base::Bind(&MediaCodecDecoder::ProcessNextFrame, base::Unretained(this))); |
| 217 |
| 218 return true; |
| 219 } |
| 220 |
| 221 void MediaCodecDecoder::SyncStop() { |
| 222 DCHECK(media_task_runner_->BelongsToCurrentThread()); |
| 223 |
| 224 DVLOG(1) << class_name() << "::" << __FUNCTION__; |
| 225 |
| 226 if (GetState() == kError) { |
| 227 DVLOG(0) << class_name() << "::" << __FUNCTION__ |
| 228 << ": wrong state kError, ignoring"; |
| 229 return; |
| 230 } |
| 231 |
| 232 // After this method returns, decoder thread will not be running. |
| 233 |
| 234 decoder_thread_.Stop(); // synchronous |
| 235 state_ = kStopped; |
| 236 |
| 237 // Shall we move |delayed_buffers_| from VideoDecoder to Decoder class? |
| 238 ReleaseDelayedBuffers(); |
| 239 } |
| 240 |
| 241 void MediaCodecDecoder::RequestToStop() { |
| 242 DCHECK(media_task_runner_->BelongsToCurrentThread()); |
| 243 |
| 244 DVLOG(1) << class_name() << "::" << __FUNCTION__; |
| 245 |
| 246 DecoderState state = GetState(); |
| 247 switch (state) { |
| 248 case kError: |
| 249 DVLOG(0) << class_name() << "::" << __FUNCTION__ |
| 250 << ": wrong state kError, ignoring"; |
| 251 break; |
| 252 case kRunning: |
| 253 SetState(kStopping); |
| 254 break; |
| 255 case kStopping: |
| 256 break; // ignore |
| 257 case kStopped: |
| 258 case kPrefetching: |
| 259 case kPrefetched: |
| 260 // There is nothing to wait for, we can sent nofigication right away. |
| 261 DCHECK(!decoder_thread_.IsRunning()); |
| 262 SetState(kStopped); |
| 263 media_task_runner_->PostTask(FROM_HERE, stop_done_cb_); |
| 264 break; |
| 265 default: |
| 266 NOTREACHED(); |
| 267 break; |
| 268 } |
| 269 } |
| 270 |
| 271 void MediaCodecDecoder::OnLastFrameRendered(bool completed) { |
| 272 DCHECK(media_task_runner_->BelongsToCurrentThread()); |
| 273 |
| 274 DVLOG(1) << class_name() << "::" << __FUNCTION__ |
| 275 << " completed:" << completed; |
| 276 |
| 277 decoder_thread_.Stop(); // synchronous |
| 278 state_ = kStopped; |
| 279 completed_ = completed; |
| 280 |
| 281 media_task_runner_->PostTask(FROM_HERE, stop_done_cb_); |
| 282 } |
| 283 |
| 284 void MediaCodecDecoder::OnDemuxerDataAvailable(const DemuxerData& data) { |
| 285 DCHECK(media_task_runner_->BelongsToCurrentThread()); |
| 286 |
| 287 DVLOG(2) << class_name() << "::" << __FUNCTION__ |
| 288 << " #AUs:" << data.access_units.size() |
| 289 << " #Configs:" << data.demuxer_configs.size(); |
| 290 #if !defined(NDEBUG) |
| 291 for (const auto& unit : data.access_units) |
| 292 DVLOG(2) << class_name() << "::" << __FUNCTION__ << " au: " << unit; |
| 293 #endif |
| 294 |
| 295 au_queue_.PushBack(data); |
| 296 |
| 297 if (state_ == kPrefetching) |
| 298 PrefetchNextChunk(); |
| 299 } |
| 300 |
| 301 void MediaCodecDecoder::CheckLastFrame(bool eos_encountered, |
| 302 bool has_delayed_tasks) { |
| 303 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread()); |
| 304 |
| 305 bool last_frame_when_stopping = GetState() == kStopping && !has_delayed_tasks; |
| 306 |
| 307 if (last_frame_when_stopping || eos_encountered) { |
| 308 media_task_runner_->PostTask( |
| 309 FROM_HERE, base::Bind(&MediaCodecDecoder::OnLastFrameRendered, |
| 310 weak_factory_.GetWeakPtr(), eos_encountered)); |
| 311 last_frame_posted_ = true; |
| 312 } |
| 313 } |
| 314 |
| 315 void MediaCodecDecoder::OnCodecError() { |
| 316 DCHECK(media_task_runner_->BelongsToCurrentThread()); |
| 317 |
| 318 SetState(kError); |
| 319 error_cb_.Run(); |
| 320 } |
| 321 |
| 322 void MediaCodecDecoder::PrefetchNextChunk() { |
| 323 DCHECK(media_task_runner_->BelongsToCurrentThread()); |
| 324 |
| 325 DVLOG(1) << class_name() << "::" << __FUNCTION__; |
| 326 |
| 327 AccessUnitQueue::Info au_info = au_queue_.GetInfo(); |
| 328 |
| 329 if (eos_enqueued_ || au_info.length >= kPrefetchLimit || au_info.has_eos) { |
| 330 // We are done prefetching |
| 331 SetState(kPrefetched); |
| 332 DVLOG(1) << class_name() << "::" << __FUNCTION__ << " posting PrefetchDone"; |
| 333 media_task_runner_->PostTask(FROM_HERE, |
| 334 base::ResetAndReturn(&prefetch_done_cb_)); |
| 335 return; |
| 336 } |
| 337 |
| 338 request_data_cb_.Run(); |
| 339 } |
| 340 |
| 341 void MediaCodecDecoder::ProcessNextFrame() { |
| 342 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread()); |
| 343 |
| 344 DVLOG(2) << class_name() << "::" << __FUNCTION__; |
| 345 |
| 346 DecoderState state = GetState(); |
| 347 |
| 348 if (state != kRunning && state != kStopping) { |
| 349 DVLOG(1) << class_name() << "::" << __FUNCTION__ << ": not running"; |
| 350 return; |
| 351 } |
| 352 |
| 353 if (state == kStopping) { |
| 354 if (NumDelayedRenderTasks() == 0 && !last_frame_posted_) { |
| 355 DVLOG(1) << class_name() << "::" << __FUNCTION__ |
| 356 << ": kStopping, posting OnLastFrameRendered"; |
| 357 media_task_runner_->PostTask( |
| 358 FROM_HERE, base::Bind(&MediaCodecDecoder::OnLastFrameRendered, |
| 359 weak_factory_.GetWeakPtr(), false)); |
| 360 last_frame_posted_ = true; |
| 361 } |
| 362 |
| 363 // We can stop processing, the |au_queue_| and MediaCodec queues can freeze. |
| 364 // We only need to let finish the delayed rendering tasks. |
| 365 return; |
| 366 } |
| 367 |
| 368 DCHECK(state == kRunning); |
| 369 |
| 370 if (!EnqueueInputBuffer()) |
| 371 return; |
| 372 |
| 373 bool eos_encountered = false; |
| 374 if (!DepleteOutputBufferQueue(&eos_encountered)) |
| 375 return; |
| 376 |
| 377 if (eos_encountered) { |
| 378 DVLOG(1) << class_name() << "::" << __FUNCTION__ |
| 379 << " EOS dequeued, stopping frame processing"; |
| 380 return; |
| 381 } |
| 382 |
| 383 // We need a small delay if we want to stop this thread by |
| 384 // decoder_thread_.Stop() reliably. |
| 385 // The decoder thread message loop processes all pending |
| 386 // (but not delayed) tasks before it can quit; without a delay |
| 387 // the message loop might be forever processing the pendng tasks. |
| 388 decoder_thread_.task_runner()->PostDelayedTask( |
| 389 FROM_HERE, |
| 390 base::Bind(&MediaCodecDecoder::ProcessNextFrame, base::Unretained(this)), |
| 391 base::TimeDelta::FromMilliseconds(kNextFrameDelay)); |
| 392 } |
| 393 |
| 394 // Returns false if we should stop decoding process. Right now |
| 395 // it happens if we got MediaCodec error or detected starvation. |
| 396 bool MediaCodecDecoder::EnqueueInputBuffer() { |
| 397 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread()); |
| 398 |
| 399 DVLOG(2) << class_name() << "::" << __FUNCTION__; |
| 400 |
| 401 if (eos_enqueued_) { |
| 402 DVLOG(1) << class_name() << "::" << __FUNCTION__ |
| 403 << ": eos_enqueued, returning"; |
| 404 return true; // Nothing to do |
| 405 } |
| 406 |
| 407 // Keep the number pending video frames low, ideally maintaining |
| 408 // the same audio and video duration after stop request |
| 409 if (NumDelayedRenderTasks() > 1) { |
| 410 DVLOG(2) << class_name() << "::" << __FUNCTION__ << ": # delayed buffers (" |
| 411 << NumDelayedRenderTasks() << ") exceeds 1, returning"; |
| 412 return true; // Nothing to do |
| 413 } |
| 414 |
| 415 // Get the next frame from the queue and the queue info |
| 416 |
| 417 AccessUnitQueue::Info au_info = au_queue_.GetInfo(); |
| 418 |
| 419 // Request the data from Demuxer |
| 420 if (au_info.length <= kPlaybackLowLimit && !au_info.has_eos) |
| 421 media_task_runner_->PostTask(FROM_HERE, request_data_cb_); |
| 422 |
| 423 // Get the next frame from the queue |
| 424 |
| 425 if (!au_info.length) { |
| 426 // Report starvation and return, Start() will be called again later. |
| 427 DVLOG(1) << class_name() << "::" << __FUNCTION__ << ": starvation detected"; |
| 428 media_task_runner_->PostTask(FROM_HERE, starvation_cb_); |
| 429 return false; |
| 430 } |
| 431 |
| 432 if (au_info.configs) { |
| 433 DVLOG(1) << class_name() << "::" << __FUNCTION__ |
| 434 << ": received new configs, not implemented"; |
| 435 // post an error for now? |
| 436 media_task_runner_->PostTask(FROM_HERE, internal_error_cb_); |
| 437 return false; |
| 438 } |
| 439 |
| 440 // Dequeue input buffer |
| 441 |
| 442 base::TimeDelta timeout = |
| 443 base::TimeDelta::FromMilliseconds(kInputBufferTimeout); |
| 444 int index = -1; |
| 445 MediaCodecStatus status = |
| 446 media_codec_bridge_->DequeueInputBuffer(timeout, &index); |
| 447 |
| 448 DVLOG(2) << class_name() << ":: DequeueInputBuffer index:" << index; |
| 449 |
| 450 switch (status) { |
| 451 case MEDIA_CODEC_ERROR: |
| 452 DVLOG(0) << class_name() << "::" << __FUNCTION__ |
| 453 << ": MEDIA_CODEC_ERROR DequeueInputBuffer failed"; |
| 454 media_task_runner_->PostTask(FROM_HERE, internal_error_cb_); |
| 455 return false; |
| 456 |
| 457 case MEDIA_CODEC_DEQUEUE_INPUT_AGAIN_LATER: |
| 458 return true; |
| 459 |
| 460 default: |
| 461 break; |
| 462 } |
| 463 |
| 464 // We got the buffer |
| 465 DCHECK_EQ(status, MEDIA_CODEC_OK); |
| 466 DCHECK_GE(index, 0); |
| 467 |
| 468 const AccessUnit* unit = au_info.front_unit; |
| 469 DCHECK(unit); |
| 470 |
| 471 if (unit->is_end_of_stream) { |
| 472 DVLOG(1) << class_name() << "::" << __FUNCTION__ << ": QueueEOS"; |
| 473 media_codec_bridge_->QueueEOS(index); |
| 474 eos_enqueued_ = true; |
| 475 return true; |
| 476 } |
| 477 |
| 478 DVLOG(2) << class_name() << ":: QueueInputBuffer pts:" << unit->timestamp; |
| 479 |
| 480 status = media_codec_bridge_->QueueInputBuffer( |
| 481 index, &unit->data[0], unit->data.size(), unit->timestamp); |
| 482 |
| 483 if (status == MEDIA_CODEC_ERROR) { |
| 484 DVLOG(0) << class_name() << "::" << __FUNCTION__ |
| 485 << ": MEDIA_CODEC_ERROR: QueueInputBuffer failed"; |
| 486 media_task_runner_->PostTask(FROM_HERE, internal_error_cb_); |
| 487 return false; |
| 488 } |
| 489 |
| 490 // Have successfully queued input buffer, go to next access unit. |
| 491 au_queue_.Advance(); |
| 492 return true; |
| 493 } |
| 494 |
| 495 // Returns false if there was MediaCodec error. |
| 496 bool MediaCodecDecoder::DepleteOutputBufferQueue(bool* eos_encountered) { |
| 497 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread()); |
| 498 |
| 499 DVLOG(2) << class_name() << "::" << __FUNCTION__; |
| 500 |
| 501 int buffer_index = 0; |
| 502 size_t offset = 0; |
| 503 size_t size = 0; |
| 504 base::TimeDelta pts; |
| 505 MediaCodecStatus status; |
| 506 |
| 507 base::TimeDelta timeout = |
| 508 base::TimeDelta::FromMilliseconds(kOutputBufferTimeout); |
| 509 |
| 510 // Extract all output buffers that are available. |
| 511 // Usually there will be only one, but sometimes it is preceeded by |
| 512 // MEDIA_CODEC_OUTPUT_BUFFERS_CHANGED or MEDIA_CODEC_OUTPUT_FORMAT_CHANGED. |
| 513 do { |
| 514 status = media_codec_bridge_->DequeueOutputBuffer( |
| 515 timeout, &buffer_index, &offset, &size, &pts, eos_encountered, nullptr); |
| 516 |
| 517 // Reset the timeout to 0 for the subsequent DequeueOutputBuffer() calls |
| 518 // to quickly break the loop after we got all currently available buffers. |
| 519 timeout = base::TimeDelta::FromMilliseconds(0); |
| 520 |
| 521 switch (status) { |
| 522 case MEDIA_CODEC_OUTPUT_BUFFERS_CHANGED: |
| 523 // Output buffers are replaced in MediaCodecBridge, nothing to do. |
| 524 break; |
| 525 |
| 526 case MEDIA_CODEC_OUTPUT_FORMAT_CHANGED: |
| 527 DVLOG(2) << class_name() << "::" << __FUNCTION__ |
| 528 << " MEDIA_CODEC_OUTPUT_FORMAT_CHANGED"; |
| 529 OnOutputFormatChanged(); |
| 530 break; |
| 531 |
| 532 case MEDIA_CODEC_OK: |
| 533 // We got the decoded frame |
| 534 Render(buffer_index, size, true, pts, *eos_encountered); |
| 535 break; |
| 536 |
| 537 case MEDIA_CODEC_DEQUEUE_OUTPUT_AGAIN_LATER: |
| 538 // Nothing to do. |
| 539 break; |
| 540 |
| 541 case MEDIA_CODEC_ERROR: |
| 542 DVLOG(0) << class_name() << "::" << __FUNCTION__ |
| 543 << ": MEDIA_CODEC_ERROR from DequeueOutputBuffer"; |
| 544 media_task_runner_->PostTask(FROM_HERE, internal_error_cb_); |
| 545 break; |
| 546 |
| 547 default: |
| 548 NOTREACHED(); |
| 549 break; |
| 550 } |
| 551 |
| 552 } while (status != MEDIA_CODEC_DEQUEUE_OUTPUT_AGAIN_LATER && |
| 553 status != MEDIA_CODEC_ERROR && !*eos_encountered); |
| 554 |
| 555 return status != MEDIA_CODEC_ERROR; |
| 556 } |
| 557 |
| 558 MediaCodecDecoder::DecoderState MediaCodecDecoder::GetState() const { |
| 559 base::AutoLock lock(state_lock_); |
| 560 return state_; |
| 561 } |
| 562 |
| 563 void MediaCodecDecoder::SetState(DecoderState state) { |
| 564 DVLOG(1) << class_name() << "::" << __FUNCTION__ << " " << state; |
| 565 |
| 566 base::AutoLock lock(state_lock_); |
| 567 state_ = state; |
| 568 } |
| 569 |
| 570 #undef RETURN_STRING |
| 571 #define RETURN_STRING(x) \ |
| 572 case x: \ |
| 573 return #x; |
| 574 |
| 575 const char* MediaCodecDecoder::AsString(DecoderState state) { |
| 576 switch (state) { |
| 577 RETURN_STRING(kStopped); |
| 578 RETURN_STRING(kPrefetching); |
| 579 RETURN_STRING(kPrefetched); |
| 580 RETURN_STRING(kRunning); |
| 581 RETURN_STRING(kStopping); |
| 582 RETURN_STRING(kError); |
| 583 default: |
| 584 return "Unknown DecoderState"; |
| 585 } |
| 586 } |
| 587 |
| 588 #undef RETURN_STRING |
| 589 |
| 590 } // namespace media |
| OLD | NEW |