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 "content/renderer/media/android/media_source_delegate.h" | 5 #include "content/renderer/media/android/media_source_delegate.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 void MediaSourceDelegate::InitializeMediaSource( | 146 void MediaSourceDelegate::InitializeMediaSource( |
147 const MediaSourceOpenedCB& media_source_opened_cb, | 147 const MediaSourceOpenedCB& media_source_opened_cb, |
148 const media::Demuxer::EncryptedMediaInitDataCB& | 148 const media::Demuxer::EncryptedMediaInitDataCB& |
149 encrypted_media_init_data_cb, | 149 encrypted_media_init_data_cb, |
150 const media::SetCdmReadyCB& set_cdm_ready_cb, | 150 const media::SetCdmReadyCB& set_cdm_ready_cb, |
151 const UpdateNetworkStateCB& update_network_state_cb, | 151 const UpdateNetworkStateCB& update_network_state_cb, |
152 const DurationChangeCB& duration_change_cb, | 152 const DurationChangeCB& duration_change_cb, |
153 const base::Closure& waiting_for_decryption_key_cb) { | 153 const base::Closure& waiting_for_decryption_key_cb) { |
154 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 154 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
155 DCHECK(!media_source_opened_cb.is_null()); | 155 DCHECK(!media_source_opened_cb.is_null()); |
| 156 DCHECK(!encrypted_media_init_data_cb.is_null()); |
| 157 DCHECK(!set_cdm_ready_cb.is_null()); |
| 158 DCHECK(!update_network_state_cb.is_null()); |
| 159 DCHECK(!duration_change_cb.is_null()); |
| 160 DCHECK(!waiting_for_decryption_key_cb.is_null()); |
| 161 |
156 media_source_opened_cb_ = media_source_opened_cb; | 162 media_source_opened_cb_ = media_source_opened_cb; |
157 encrypted_media_init_data_cb_ = encrypted_media_init_data_cb; | 163 encrypted_media_init_data_cb_ = encrypted_media_init_data_cb; |
158 set_cdm_ready_cb_ = media::BindToCurrentLoop(set_cdm_ready_cb); | 164 set_cdm_ready_cb_ = media::BindToCurrentLoop(set_cdm_ready_cb); |
159 update_network_state_cb_ = media::BindToCurrentLoop(update_network_state_cb); | 165 update_network_state_cb_ = media::BindToCurrentLoop(update_network_state_cb); |
160 duration_change_cb_ = duration_change_cb; | 166 duration_change_cb_ = duration_change_cb; |
161 waiting_for_decryption_key_cb_ = | 167 waiting_for_decryption_key_cb_ = |
162 media::BindToCurrentLoop(waiting_for_decryption_key_cb); | 168 media::BindToCurrentLoop(waiting_for_decryption_key_cb); |
163 access_unit_size_ = kAccessUnitSizeForMediaSource; | 169 access_unit_size_ = kAccessUnitSizeForMediaSource; |
164 | 170 |
165 chunk_demuxer_.reset(new media::ChunkDemuxer( | 171 chunk_demuxer_.reset(new media::ChunkDemuxer( |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 DCHECK(chunk_demuxer_); | 495 DCHECK(chunk_demuxer_); |
490 | 496 |
491 if (status != media::PIPELINE_OK) { | 497 if (status != media::PIPELINE_OK) { |
492 OnDemuxerError(status); | 498 OnDemuxerError(status); |
493 return; | 499 return; |
494 } | 500 } |
495 | 501 |
496 audio_stream_ = chunk_demuxer_->GetStream(DemuxerStream::AUDIO); | 502 audio_stream_ = chunk_demuxer_->GetStream(DemuxerStream::AUDIO); |
497 video_stream_ = chunk_demuxer_->GetStream(DemuxerStream::VIDEO); | 503 video_stream_ = chunk_demuxer_->GetStream(DemuxerStream::VIDEO); |
498 | 504 |
499 if (audio_stream_ && audio_stream_->audio_decoder_config().is_encrypted() && | 505 if (audio_stream_ && audio_stream_->audio_decoder_config().is_encrypted()) { |
500 !set_cdm_ready_cb_.is_null()) { | |
501 InitAudioDecryptingDemuxerStream(); | 506 InitAudioDecryptingDemuxerStream(); |
502 // InitVideoDecryptingDemuxerStream() will be called in | 507 // InitVideoDecryptingDemuxerStream() will be called in |
503 // OnAudioDecryptingDemuxerStreamInitDone(). | 508 // OnAudioDecryptingDemuxerStreamInitDone(). |
504 return; | 509 return; |
505 } | 510 } |
506 | 511 |
507 if (video_stream_ && video_stream_->video_decoder_config().is_encrypted() && | 512 if (video_stream_ && video_stream_->video_decoder_config().is_encrypted()) { |
508 !set_cdm_ready_cb_.is_null()) { | |
509 InitVideoDecryptingDemuxerStream(); | 513 InitVideoDecryptingDemuxerStream(); |
510 return; | 514 return; |
511 } | 515 } |
512 | 516 |
513 // Notify demuxer ready when both streams are not encrypted. | 517 // Notify demuxer ready when both streams are not encrypted. |
514 is_demuxer_ready_ = true; | 518 is_demuxer_ready_ = true; |
515 NotifyDemuxerReady(); | 519 NotifyDemuxerReady(); |
516 } | 520 } |
517 | 521 |
518 void MediaSourceDelegate::InitAudioDecryptingDemuxerStream() { | 522 void MediaSourceDelegate::InitAudioDecryptingDemuxerStream() { |
519 DCHECK(media_task_runner_->BelongsToCurrentThread()); | 523 DCHECK(media_task_runner_->BelongsToCurrentThread()); |
520 DVLOG(1) << __FUNCTION__ << " : " << demuxer_client_id_; | 524 DVLOG(1) << __FUNCTION__ << " : " << demuxer_client_id_; |
521 DCHECK(!set_cdm_ready_cb_.is_null()); | 525 DCHECK(!set_cdm_ready_cb_.is_null()); |
522 | |
523 audio_decrypting_demuxer_stream_.reset(new media::DecryptingDemuxerStream( | 526 audio_decrypting_demuxer_stream_.reset(new media::DecryptingDemuxerStream( |
524 media_task_runner_, media_log_, waiting_for_decryption_key_cb_)); | 527 media_task_runner_, media_log_, waiting_for_decryption_key_cb_)); |
525 audio_decrypting_demuxer_stream_->Initialize( | 528 audio_decrypting_demuxer_stream_->Initialize( |
526 audio_stream_, set_cdm_ready_cb_, | 529 audio_stream_, set_cdm_ready_cb_, |
527 base::Bind(&MediaSourceDelegate::OnAudioDecryptingDemuxerStreamInitDone, | 530 base::Bind(&MediaSourceDelegate::OnAudioDecryptingDemuxerStreamInitDone, |
528 media_weak_factory_.GetWeakPtr())); | 531 media_weak_factory_.GetWeakPtr())); |
529 } | 532 } |
530 | 533 |
531 void MediaSourceDelegate::InitVideoDecryptingDemuxerStream() { | 534 void MediaSourceDelegate::InitVideoDecryptingDemuxerStream() { |
532 DCHECK(media_task_runner_->BelongsToCurrentThread()); | 535 DCHECK(media_task_runner_->BelongsToCurrentThread()); |
533 DVLOG(1) << __FUNCTION__ << " : " << demuxer_client_id_; | 536 DVLOG(1) << __FUNCTION__ << " : " << demuxer_client_id_; |
534 DCHECK(!set_cdm_ready_cb_.is_null()); | 537 DCHECK(!set_cdm_ready_cb_.is_null()); |
535 | 538 |
536 video_decrypting_demuxer_stream_.reset(new media::DecryptingDemuxerStream( | 539 video_decrypting_demuxer_stream_.reset(new media::DecryptingDemuxerStream( |
537 media_task_runner_, media_log_, waiting_for_decryption_key_cb_)); | 540 media_task_runner_, media_log_, waiting_for_decryption_key_cb_)); |
538 video_decrypting_demuxer_stream_->Initialize( | 541 video_decrypting_demuxer_stream_->Initialize( |
539 video_stream_, set_cdm_ready_cb_, | 542 video_stream_, set_cdm_ready_cb_, |
540 base::Bind(&MediaSourceDelegate::OnVideoDecryptingDemuxerStreamInitDone, | 543 base::Bind(&MediaSourceDelegate::OnVideoDecryptingDemuxerStreamInitDone, |
541 media_weak_factory_.GetWeakPtr())); | 544 media_weak_factory_.GetWeakPtr())); |
542 } | 545 } |
543 | 546 |
544 void MediaSourceDelegate::OnAudioDecryptingDemuxerStreamInitDone( | 547 void MediaSourceDelegate::OnAudioDecryptingDemuxerStreamInitDone( |
545 media::PipelineStatus status) { | 548 media::PipelineStatus status) { |
546 DCHECK(media_task_runner_->BelongsToCurrentThread()); | 549 DCHECK(media_task_runner_->BelongsToCurrentThread()); |
547 DVLOG(1) << __FUNCTION__ << "(" << status << ") : " << demuxer_client_id_; | 550 DVLOG(1) << __FUNCTION__ << "(" << status << ") : " << demuxer_client_id_; |
548 DCHECK(chunk_demuxer_); | 551 DCHECK(chunk_demuxer_); |
549 | 552 |
550 if (status != media::PIPELINE_OK) | 553 if (status != media::PIPELINE_OK) { |
551 audio_decrypting_demuxer_stream_.reset(); | 554 audio_decrypting_demuxer_stream_.reset(); |
552 else | 555 // Different CDMs are supported differently. For CDMs that support a |
553 audio_stream_ = audio_decrypting_demuxer_stream_.get(); | 556 // Decryptor, we'll try to use DecryptingDemuxerStream in the render side. |
| 557 // Otherwise, we'll try to use the CDMs in the browser side. Therefore, if |
| 558 // DecryptingDemuxerStream initialization failed, it's still possible that |
| 559 // we can handle the audio with a CDM in the browser. Declare demuxer ready |
| 560 // now to try that path. Note there's no need to try DecryptingDemuxerStream |
| 561 // for video here since it is impossible to handle audio in the browser and |
| 562 // handle video in the render process. |
| 563 is_demuxer_ready_ = true; |
| 564 NotifyDemuxerReady(); |
| 565 return; |
| 566 } |
| 567 |
| 568 audio_stream_ = audio_decrypting_demuxer_stream_.get(); |
554 | 569 |
555 if (video_stream_ && video_stream_->video_decoder_config().is_encrypted()) { | 570 if (video_stream_ && video_stream_->video_decoder_config().is_encrypted()) { |
556 InitVideoDecryptingDemuxerStream(); | 571 InitVideoDecryptingDemuxerStream(); |
557 return; | 572 return; |
558 } | 573 } |
559 | 574 |
560 // Try to notify demuxer ready when audio DDS initialization finished and | 575 // Try to notify demuxer ready when audio DDS initialization finished and |
561 // video is not encrypted. | 576 // video is not encrypted. |
562 is_demuxer_ready_ = true; | 577 is_demuxer_ready_ = true; |
563 NotifyDemuxerReady(); | 578 NotifyDemuxerReady(); |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
750 configs->video_codec = config.codec(); | 765 configs->video_codec = config.codec(); |
751 configs->video_size = config.natural_size(); | 766 configs->video_size = config.natural_size(); |
752 configs->is_video_encrypted = config.is_encrypted(); | 767 configs->is_video_encrypted = config.is_encrypted(); |
753 configs->video_extra_data = config.extra_data(); | 768 configs->video_extra_data = config.extra_data(); |
754 return true; | 769 return true; |
755 } | 770 } |
756 return false; | 771 return false; |
757 } | 772 } |
758 | 773 |
759 } // namespace content | 774 } // namespace content |
OLD | NEW |