Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "media/base/android/media_decoder_job.h" | 5 #include "media/base/android/media_decoder_job.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
| 9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
| 10 #include "base/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 196 // Since the decoder job is not decoding data, we can safely destroy | 196 // Since the decoder job is not decoding data, we can safely destroy |
| 197 // |media_codec_bridge_|. | 197 // |media_codec_bridge_|. |
| 198 ReleaseMediaCodecBridge(); | 198 ReleaseMediaCodecBridge(); |
| 199 return; | 199 return; |
| 200 } | 200 } |
| 201 | 201 |
| 202 // Release |media_codec_bridge_| once decoding is completed. | 202 // Release |media_codec_bridge_| once decoding is completed. |
| 203 release_resources_pending_ = true; | 203 release_resources_pending_ = true; |
| 204 } | 204 } |
| 205 | 205 |
| 206 bool MediaDecoderJob::SetDemuxerConfigs(const DemuxerConfigs& configs) { | |
| 207 bool config_changed = AreDemuxerConfigsChanged(configs); | |
| 208 if (config_changed) | |
| 209 UpdateDemuxerConfigs(configs); | |
| 210 return config_changed; | |
| 211 } | |
| 212 | |
| 213 base::android::ScopedJavaLocalRef<jobject> MediaDecoderJob::GetMediaCrypto() { | 206 base::android::ScopedJavaLocalRef<jobject> MediaDecoderJob::GetMediaCrypto() { |
| 214 base::android::ScopedJavaLocalRef<jobject> media_crypto; | 207 base::android::ScopedJavaLocalRef<jobject> media_crypto; |
| 215 if (drm_bridge_) | 208 if (drm_bridge_) |
| 216 media_crypto = drm_bridge_->GetMediaCrypto(); | 209 media_crypto = drm_bridge_->GetMediaCrypto(); |
| 217 return media_crypto; | 210 return media_crypto; |
| 218 } | 211 } |
| 219 | 212 |
| 220 void MediaDecoderJob::Release() { | 213 void MediaDecoderJob::Release() { |
| 221 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | 214 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
| 222 DVLOG(1) << __FUNCTION__; | 215 DVLOG(1) << __FUNCTION__; |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 328 base::TimeDelta start_presentation_timestamp) { | 321 base::TimeDelta start_presentation_timestamp) { |
| 329 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | 322 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
| 330 DCHECK(!decode_cb_.is_null()); | 323 DCHECK(!decode_cb_.is_null()); |
| 331 | 324 |
| 332 RequestCurrentChunkIfEmpty(); | 325 RequestCurrentChunkIfEmpty(); |
| 333 const AccessUnit& access_unit = CurrentAccessUnit(); | 326 const AccessUnit& access_unit = CurrentAccessUnit(); |
| 334 if (CurrentAccessUnit().status == DemuxerStream::kConfigChanged) { | 327 if (CurrentAccessUnit().status == DemuxerStream::kConfigChanged) { |
| 335 int index = CurrentReceivedDataChunkIndex(); | 328 int index = CurrentReceivedDataChunkIndex(); |
| 336 const DemuxerConfigs& configs = received_data_[index].demuxer_configs[0]; | 329 const DemuxerConfigs& configs = received_data_[index].demuxer_configs[0]; |
| 337 bool reconfigure_needed = IsCodecReconfigureNeeded(configs); | 330 bool reconfigure_needed = IsCodecReconfigureNeeded(configs); |
| 338 // TODO(qinmin): |config_changed_cb_| should be run after draining finishes. | 331 SetDemuxerConfigs(configs); |
| 339 // http://crbug.com/381975. | |
| 340 if (SetDemuxerConfigs(configs)) | |
| 341 config_changed_cb_.Run(); | |
| 342 if (!drain_decoder_) { | 332 if (!drain_decoder_) { |
| 343 // If we haven't decoded any data yet, just skip the current access unit | 333 // If we haven't decoded any data yet, just skip the current access unit |
| 344 // and request the MediaCodec to be recreated on next Decode(). | 334 // and request the MediaCodec to be recreated on next Decode(). |
| 345 if (skip_eos_enqueue_ || !reconfigure_needed) { | 335 if (skip_eos_enqueue_ || !reconfigure_needed) { |
| 346 need_to_reconfig_decoder_job_ = | 336 need_to_reconfig_decoder_job_ = |
| 347 need_to_reconfig_decoder_job_ || reconfigure_needed; | 337 need_to_reconfig_decoder_job_ || reconfigure_needed; |
| 338 // Report MEDIA_CODEC_OK status so decoder will continue decoding and | |
| 339 // MEDIA_CODEC_OUTPUT_FORMAT_CHANGED status will come later. | |
| 348 ui_task_runner_->PostTask(FROM_HERE, base::Bind( | 340 ui_task_runner_->PostTask(FROM_HERE, base::Bind( |
| 349 &MediaDecoderJob::OnDecodeCompleted, base::Unretained(this), | 341 &MediaDecoderJob::OnDecodeCompleted, base::Unretained(this), |
| 350 MEDIA_CODEC_OUTPUT_FORMAT_CHANGED, kNoTimestamp(), kNoTimestamp())); | 342 MEDIA_CODEC_OK, kNoTimestamp(), kNoTimestamp())); |
| 351 return; | 343 return; |
| 352 } | 344 } |
| 353 // Start draining the decoder so that all the remaining frames are | 345 // Start draining the decoder so that all the remaining frames are |
| 354 // rendered. | 346 // rendered. |
| 355 drain_decoder_ = true; | 347 drain_decoder_ = true; |
| 356 } | 348 } |
| 357 } | 349 } |
| 358 | 350 |
|
wolenetz
2014/10/08 19:41:33
Is there a possibility that the first AU is kConfi
qinmin
2014/10/08 22:52:41
MEDIA_CODEC_OUTPUT_FORMAT_CHANGED is reported when
| |
| 359 DCHECK(!(needs_flush_ && drain_decoder_)); | 351 DCHECK(!(needs_flush_ && drain_decoder_)); |
| 360 decoder_task_runner_->PostTask(FROM_HERE, base::Bind( | 352 decoder_task_runner_->PostTask(FROM_HERE, base::Bind( |
| 361 &MediaDecoderJob::DecodeInternal, base::Unretained(this), | 353 &MediaDecoderJob::DecodeInternal, base::Unretained(this), |
| 362 drain_decoder_ ? eos_unit_ : access_unit, | 354 drain_decoder_ ? eos_unit_ : access_unit, |
| 363 start_time_ticks, start_presentation_timestamp, needs_flush_, | 355 start_time_ticks, start_presentation_timestamp, needs_flush_, |
| 364 media::BindToCurrentLoop(base::Bind( | 356 media::BindToCurrentLoop(base::Bind( |
| 365 &MediaDecoderJob::OnDecodeCompleted, base::Unretained(this))))); | 357 &MediaDecoderJob::OnDecodeCompleted, base::Unretained(this))))); |
| 366 needs_flush_ = false; | 358 needs_flush_ = false; |
| 367 } | 359 } |
| 368 | 360 |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 534 case MEDIA_CODEC_ERROR: | 526 case MEDIA_CODEC_ERROR: |
| 535 // Do nothing. | 527 // Do nothing. |
| 536 break; | 528 break; |
| 537 }; | 529 }; |
| 538 | 530 |
| 539 if (status == MEDIA_CODEC_OUTPUT_END_OF_STREAM && drain_decoder_) { | 531 if (status == MEDIA_CODEC_OUTPUT_END_OF_STREAM && drain_decoder_) { |
| 540 OnDecoderDrained(); | 532 OnDecoderDrained(); |
| 541 status = MEDIA_CODEC_OK; | 533 status = MEDIA_CODEC_OK; |
| 542 } | 534 } |
| 543 | 535 |
| 536 if (status == MEDIA_CODEC_OUTPUT_FORMAT_CHANGED && UpdateOutputFormat()) | |
| 537 config_changed_cb_.Run(); | |
| 538 | |
| 544 if (release_resources_pending_) { | 539 if (release_resources_pending_) { |
| 545 ReleaseMediaCodecBridge(); | 540 ReleaseMediaCodecBridge(); |
| 546 release_resources_pending_ = false; | 541 release_resources_pending_ = false; |
| 547 if (drain_decoder_) | 542 if (drain_decoder_) |
| 548 OnDecoderDrained(); | 543 OnDecoderDrained(); |
| 549 } | 544 } |
| 550 | 545 |
| 551 stop_decode_pending_ = false; | 546 stop_decode_pending_ = false; |
| 552 base::ResetAndReturn(&decode_cb_).Run( | 547 base::ResetAndReturn(&decode_cb_).Run( |
| 553 status, current_presentation_timestamp, max_presentation_timestamp); | 548 status, current_presentation_timestamp, max_presentation_timestamp); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 644 | 639 |
| 645 void MediaDecoderJob::ReleaseMediaCodecBridge() { | 640 void MediaDecoderJob::ReleaseMediaCodecBridge() { |
| 646 if (!media_codec_bridge_) | 641 if (!media_codec_bridge_) |
| 647 return; | 642 return; |
| 648 | 643 |
| 649 media_codec_bridge_.reset(); | 644 media_codec_bridge_.reset(); |
| 650 input_buf_index_ = -1; | 645 input_buf_index_ = -1; |
| 651 } | 646 } |
| 652 | 647 |
| 653 } // namespace media | 648 } // namespace media |
| OLD | NEW |