| 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 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 // Otherwise MediaDrm will report errors. | 282 // Otherwise MediaDrm will report errors. |
| 283 if (status == MEDIA_CODEC_NO_KEY) | 283 if (status == MEDIA_CODEC_NO_KEY) |
| 284 input_buf_index_ = input_buf_index; | 284 input_buf_index_ = input_buf_index; |
| 285 | 285 |
| 286 return status; | 286 return status; |
| 287 } | 287 } |
| 288 | 288 |
| 289 bool MediaDecoderJob::HasData() const { | 289 bool MediaDecoderJob::HasData() const { |
| 290 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | 290 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
| 291 // When |input_eos_encountered_| is set, |access_unit_index_| and | 291 // When |input_eos_encountered_| is set, |access_unit_index_| and |
| 292 // |current_demuxer_data_index_| must be pointing to an EOS unit. | 292 // |current_demuxer_data_index_| must be pointing to an EOS unit, |
| 293 // We'll reuse this unit to flush the decoder until we hit output EOS. | 293 // or a |kConfigChanged| unit if |drain_decoder_| is true. In both cases, |
| 294 // we'll feed an EOS input unit to drain the decoder until we hit output EOS. |
| 294 DCHECK(!input_eos_encountered_ || !NoAccessUnitsRemainingInChunk(true)); | 295 DCHECK(!input_eos_encountered_ || !NoAccessUnitsRemainingInChunk(true)); |
| 295 return !NoAccessUnitsRemainingInChunk(true) || | 296 return !NoAccessUnitsRemainingInChunk(true) || |
| 296 !NoAccessUnitsRemainingInChunk(false); | 297 !NoAccessUnitsRemainingInChunk(false); |
| 297 } | 298 } |
| 298 | 299 |
| 299 void MediaDecoderJob::RequestData(const base::Closure& done_cb) { | 300 void MediaDecoderJob::RequestData(const base::Closure& done_cb) { |
| 300 DVLOG(1) << __FUNCTION__; | 301 DVLOG(1) << __FUNCTION__; |
| 301 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | 302 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
| 302 DCHECK(data_received_cb_.is_null()); | 303 DCHECK(data_received_cb_.is_null()); |
| 303 DCHECK(!input_eos_encountered_); | 304 DCHECK(!input_eos_encountered_); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 325 void MediaDecoderJob::DecodeCurrentAccessUnit( | 326 void MediaDecoderJob::DecodeCurrentAccessUnit( |
| 326 base::TimeTicks start_time_ticks, | 327 base::TimeTicks start_time_ticks, |
| 327 base::TimeDelta start_presentation_timestamp) { | 328 base::TimeDelta start_presentation_timestamp) { |
| 328 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | 329 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
| 329 DCHECK(!decode_cb_.is_null()); | 330 DCHECK(!decode_cb_.is_null()); |
| 330 | 331 |
| 331 RequestCurrentChunkIfEmpty(); | 332 RequestCurrentChunkIfEmpty(); |
| 332 const AccessUnit& access_unit = CurrentAccessUnit(); | 333 const AccessUnit& access_unit = CurrentAccessUnit(); |
| 333 if (CurrentAccessUnit().status == DemuxerStream::kConfigChanged) { | 334 if (CurrentAccessUnit().status == DemuxerStream::kConfigChanged) { |
| 334 int index = CurrentReceivedDataChunkIndex(); | 335 int index = CurrentReceivedDataChunkIndex(); |
| 335 bool config_changed = SetDemuxerConfigs( | 336 const DemuxerConfigs& configs = received_data_[index].demuxer_configs[0]; |
| 336 received_data_[index].demuxer_configs[0]); | 337 bool reconfigure_needed = IsCodecReconfigureNeeded(configs); |
| 337 if (config_changed) | 338 // TODO(qinmin): |config_changed_cb_| should be run after draining finishes. |
| 339 // http://crbug.com/381975. |
| 340 if (SetDemuxerConfigs(configs)) |
| 338 config_changed_cb_.Run(); | 341 config_changed_cb_.Run(); |
| 339 if (!drain_decoder_) { | 342 if (!drain_decoder_) { |
| 340 // If we haven't decoded any data yet, just skip the current access unit | 343 // If we haven't decoded any data yet, just skip the current access unit |
| 341 // and request the MediaCodec to be recreated on next Decode(). | 344 // and request the MediaCodec to be recreated on next Decode(). |
| 342 if (skip_eos_enqueue_ || !config_changed) { | 345 if (skip_eos_enqueue_ || !reconfigure_needed) { |
| 343 need_to_reconfig_decoder_job_ = | 346 need_to_reconfig_decoder_job_ = |
| 344 need_to_reconfig_decoder_job_ || config_changed; | 347 need_to_reconfig_decoder_job_ || reconfigure_needed; |
| 345 ui_task_runner_->PostTask(FROM_HERE, base::Bind( | 348 ui_task_runner_->PostTask(FROM_HERE, base::Bind( |
| 346 &MediaDecoderJob::OnDecodeCompleted, base::Unretained(this), | 349 &MediaDecoderJob::OnDecodeCompleted, base::Unretained(this), |
| 347 MEDIA_CODEC_OUTPUT_FORMAT_CHANGED, kNoTimestamp(), kNoTimestamp())); | 350 MEDIA_CODEC_OUTPUT_FORMAT_CHANGED, kNoTimestamp(), kNoTimestamp())); |
| 348 return; | 351 return; |
| 349 } | 352 } |
| 350 // Start draining the decoder so that all the remaining frames are | 353 // Start draining the decoder so that all the remaining frames are |
| 351 // rendered. | 354 // rendered. |
| 352 drain_decoder_ = true; | 355 drain_decoder_ = true; |
| 353 } | 356 } |
| 354 } | 357 } |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 base::android::ScopedJavaLocalRef<jobject> media_crypto = GetMediaCrypto(); | 628 base::android::ScopedJavaLocalRef<jobject> media_crypto = GetMediaCrypto(); |
| 626 if (is_content_encrypted_ && media_crypto.is_null()) | 629 if (is_content_encrypted_ && media_crypto.is_null()) |
| 627 return false; | 630 return false; |
| 628 | 631 |
| 629 ReleaseMediaCodecBridge(); | 632 ReleaseMediaCodecBridge(); |
| 630 DVLOG(1) << __FUNCTION__ << " : creating new media codec bridge"; | 633 DVLOG(1) << __FUNCTION__ << " : creating new media codec bridge"; |
| 631 | 634 |
| 632 return CreateMediaCodecBridgeInternal(); | 635 return CreateMediaCodecBridgeInternal(); |
| 633 } | 636 } |
| 634 | 637 |
| 638 bool MediaDecoderJob::IsCodecReconfigureNeeded( |
| 639 const DemuxerConfigs& configs) const { |
| 640 if (!AreDemuxerConfigsChanged(configs)) |
| 641 return false; |
| 642 return true; |
| 643 } |
| 644 |
| 635 void MediaDecoderJob::ReleaseMediaCodecBridge() { | 645 void MediaDecoderJob::ReleaseMediaCodecBridge() { |
| 636 if (!media_codec_bridge_) | 646 if (!media_codec_bridge_) |
| 637 return; | 647 return; |
| 638 | 648 |
| 639 media_codec_bridge_.reset(); | 649 media_codec_bridge_.reset(); |
| 640 OnMediaCodecBridgeReleased(); | 650 OnMediaCodecBridgeReleased(); |
| 641 } | 651 } |
| 642 | 652 |
| 643 } // namespace media | 653 } // namespace media |
| OLD | NEW |