diff options
Diffstat (limited to 'content')
4 files changed, 70 insertions, 69 deletions
diff --git a/content/renderer/media/android/media_source_delegate.cc b/content/renderer/media/android/media_source_delegate.cc index 4c0477b..9b4d312 100644 --- a/content/renderer/media/android/media_source_delegate.cc +++ b/content/renderer/media/android/media_source_delegate.cc @@ -146,7 +146,7 @@ void MediaSourceDelegate::InitializeMediaSource( const MediaSourceOpenedCB& media_source_opened_cb, const media::Demuxer::EncryptedMediaInitDataCB& encrypted_media_init_data_cb, - const media::SetDecryptorReadyCB& set_decryptor_ready_cb, + const media::SetCdmReadyCB& set_cdm_ready_cb, const UpdateNetworkStateCB& update_network_state_cb, const DurationChangeCB& duration_change_cb, const base::Closure& waiting_for_decryption_key_cb) { @@ -154,7 +154,7 @@ void MediaSourceDelegate::InitializeMediaSource( DCHECK(!media_source_opened_cb.is_null()); media_source_opened_cb_ = media_source_opened_cb; encrypted_media_init_data_cb_ = encrypted_media_init_data_cb; - set_decryptor_ready_cb_ = media::BindToCurrentLoop(set_decryptor_ready_cb); + set_cdm_ready_cb_ = media::BindToCurrentLoop(set_cdm_ready_cb); update_network_state_cb_ = media::BindToCurrentLoop(update_network_state_cb); duration_change_cb_ = duration_change_cb; waiting_for_decryption_key_cb_ = @@ -496,7 +496,7 @@ void MediaSourceDelegate::OnDemuxerInitDone(media::PipelineStatus status) { video_stream_ = chunk_demuxer_->GetStream(DemuxerStream::VIDEO); if (audio_stream_ && audio_stream_->audio_decoder_config().is_encrypted() && - !set_decryptor_ready_cb_.is_null()) { + !set_cdm_ready_cb_.is_null()) { InitAudioDecryptingDemuxerStream(); // InitVideoDecryptingDemuxerStream() will be called in // OnAudioDecryptingDemuxerStreamInitDone(). @@ -504,7 +504,7 @@ void MediaSourceDelegate::OnDemuxerInitDone(media::PipelineStatus status) { } if (video_stream_ && video_stream_->video_decoder_config().is_encrypted() && - !set_decryptor_ready_cb_.is_null()) { + !set_cdm_ready_cb_.is_null()) { InitVideoDecryptingDemuxerStream(); return; } @@ -517,10 +517,10 @@ void MediaSourceDelegate::OnDemuxerInitDone(media::PipelineStatus status) { void MediaSourceDelegate::InitAudioDecryptingDemuxerStream() { DCHECK(media_task_runner_->BelongsToCurrentThread()); DVLOG(1) << __FUNCTION__ << " : " << demuxer_client_id_; - DCHECK(!set_decryptor_ready_cb_.is_null()); + DCHECK(!set_cdm_ready_cb_.is_null()); audio_decrypting_demuxer_stream_.reset(new media::DecryptingDemuxerStream( - media_task_runner_, media_log_, set_decryptor_ready_cb_, + media_task_runner_, media_log_, set_cdm_ready_cb_, waiting_for_decryption_key_cb_)); audio_decrypting_demuxer_stream_->Initialize( audio_stream_, @@ -531,10 +531,10 @@ void MediaSourceDelegate::InitAudioDecryptingDemuxerStream() { void MediaSourceDelegate::InitVideoDecryptingDemuxerStream() { DCHECK(media_task_runner_->BelongsToCurrentThread()); DVLOG(1) << __FUNCTION__ << " : " << demuxer_client_id_; - DCHECK(!set_decryptor_ready_cb_.is_null()); + DCHECK(!set_cdm_ready_cb_.is_null()); video_decrypting_demuxer_stream_.reset(new media::DecryptingDemuxerStream( - media_task_runner_, media_log_, set_decryptor_ready_cb_, + media_task_runner_, media_log_, set_cdm_ready_cb_, waiting_for_decryption_key_cb_)); video_decrypting_demuxer_stream_->Initialize( video_stream_, diff --git a/content/renderer/media/android/media_source_delegate.h b/content/renderer/media/android/media_source_delegate.h index e644230..ee5e1a4 100644 --- a/content/renderer/media/android/media_source_delegate.h +++ b/content/renderer/media/android/media_source_delegate.h @@ -13,7 +13,7 @@ #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" #include "base/time/time.h" -#include "media/base/decryptor.h" +#include "media/base/cdm_context.h" #include "media/base/demuxer.h" #include "media/base/media_keys.h" #include "media/base/pipeline_status.h" @@ -60,7 +60,7 @@ class MediaSourceDelegate : public media::DemuxerHost { const MediaSourceOpenedCB& media_source_opened_cb, const media::Demuxer::EncryptedMediaInitDataCB& encrypted_media_init_data_cb, - const media::SetDecryptorReadyCB& set_decryptor_ready_cb, + const media::SetCdmReadyCB& set_cdm_ready_cb, const UpdateNetworkStateCB& update_network_state_cb, const DurationChangeCB& duration_change_cb, const base::Closure& waiting_for_decryption_key_cb); @@ -186,7 +186,7 @@ class MediaSourceDelegate : public media::DemuxerHost { scoped_ptr<media::ChunkDemuxer> chunk_demuxer_; bool is_demuxer_ready_; - media::SetDecryptorReadyCB set_decryptor_ready_cb_; + media::SetCdmReadyCB set_cdm_ready_cb_; scoped_ptr<media::DecryptingDemuxerStream> audio_decrypting_demuxer_stream_; scoped_ptr<media::DecryptingDemuxerStream> video_decrypting_demuxer_stream_; diff --git a/content/renderer/media/android/webmediaplayer_android.cc b/content/renderer/media/android/webmediaplayer_android.cc index ceecc08..cfd92af 100644 --- a/content/renderer/media/android/webmediaplayer_android.cc +++ b/content/renderer/media/android/webmediaplayer_android.cc @@ -186,19 +186,18 @@ WebMediaPlayerAndroid::WebMediaPlayerAndroid( needs_establish_peer_(true), has_size_info_(false), // Threaded compositing isn't enabled universally yet. - compositor_task_runner_( - params.compositor_task_runner() - ? params.compositor_task_runner() - : base::ThreadTaskRunnerHandle::Get()), + compositor_task_runner_(params.compositor_task_runner() + ? params.compositor_task_runner() + : base::ThreadTaskRunnerHandle::Get()), stream_texture_factory_(factory), needs_external_surface_(false), is_fullscreen_(false), - video_frame_provider_client_(NULL), + video_frame_provider_client_(nullptr), player_type_(MEDIA_PLAYER_TYPE_URL), is_remote_(false), media_log_(params.media_log()), init_data_type_(media::EmeInitDataType::UNKNOWN), - cdm_context_(NULL), + cdm_context_(nullptr), allow_stored_credentials_(false), is_local_resource_(false), interpolator_(&default_tick_clock_), @@ -326,7 +325,7 @@ void WebMediaPlayerAndroid::DoLoad(LoadType load_type, weak_factory_.GetWeakPtr()), base::Bind(&WebMediaPlayerAndroid::OnEncryptedMediaInitData, weak_factory_.GetWeakPtr()), - base::Bind(&WebMediaPlayerAndroid::SetDecryptorReadyCB, + base::Bind(&WebMediaPlayerAndroid::SetCdmReadyCB, weak_factory_.GetWeakPtr()), base::Bind(&WebMediaPlayerAndroid::UpdateNetworkState, weak_factory_.GetWeakPtr()), @@ -1711,12 +1710,12 @@ void WebMediaPlayerAndroid::setContentDecryptionModule( cdm_context_ = media::ToWebContentDecryptionModuleImpl(cdm)->GetCdmContext(); if (is_player_initialized_) { - SetCdmInternal(media::BindToCurrentLoop( + SetCdmInternal( base::Bind(&WebMediaPlayerAndroid::ContentDecryptionModuleAttached, - weak_factory_.GetWeakPtr(), result))); + weak_factory_.GetWeakPtr(), result)); } else { // No pipeline/decoder connected, so resolve the promise. When something - // is connected, setting the CDM will happen in SetDecryptorReadyCB(). + // is connected, setting the CDM will happen in SetCdmReadyCB(). ContentDecryptionModuleAttached(result, true); } } @@ -1830,70 +1829,69 @@ void WebMediaPlayerAndroid::OnCdmContextReady(media::CdmContext* cdm_context) { void WebMediaPlayerAndroid::SetCdmInternal( const media::CdmAttachedCB& cdm_attached_cb) { + DCHECK(main_thread_checker_.CalledOnValidThread()); DCHECK(cdm_context_ && is_player_initialized_); DCHECK(cdm_context_->GetDecryptor() || cdm_context_->GetCdmId() != media::CdmContext::kInvalidCdmId) << "CDM should support either a Decryptor or a CDM ID."; - media::Decryptor* decryptor = cdm_context_->GetDecryptor(); - - // Note: - // - If |decryptor| is non-null, only handles |decryptor_ready_cb_| and - // ignores the CDM ID. - // - If |decryptor| is null (in which case the CDM ID should be valid), - // returns any pending |decryptor_ready_cb_| with null, so that - // MediaSourceDelegate will fall back to use a browser side (IPC-based) CDM, - // then calls SetCdm() through the |player_manager_|. - - if (decryptor) { - if (!decryptor_ready_cb_.is_null()) { - base::ResetAndReturn(&decryptor_ready_cb_) - .Run(decryptor, cdm_attached_cb); - } else { - cdm_attached_cb.Run(true); - } + if (cdm_ready_cb_.is_null()) { + cdm_attached_cb.Run(true); return; } - // |decryptor| is null. - if (!decryptor_ready_cb_.is_null()) { - base::ResetAndReturn(&decryptor_ready_cb_) - .Run(nullptr, base::Bind(&media::IgnoreCdmAttached)); + // Satisfy |cdm_ready_cb_|. Use BindToCurrentLoop() since the callback could + // be fired on other threads. + base::ResetAndReturn(&cdm_ready_cb_) + .Run(cdm_context_, media::BindToCurrentLoop(base::Bind( + &WebMediaPlayerAndroid::OnCdmAttached, + weak_factory_.GetWeakPtr(), cdm_attached_cb))); +} + +void WebMediaPlayerAndroid::OnCdmAttached( + const media::CdmAttachedCB& cdm_attached_cb, + bool success) { + DCHECK(main_thread_checker_.CalledOnValidThread()); + + if (!success) { + if (cdm_context_->GetCdmId() == media::CdmContext::kInvalidCdmId) { + NOTREACHED() << "CDM cannot be attached to media player."; + cdm_attached_cb.Run(false); + return; + } + + // If the CDM is not attached (e.g. the CDM does not support a Decryptor), + // MediaSourceDelegate will fall back to use a browser side (IPC-based) CDM. + player_manager_->SetCdm(player_id_, cdm_context_->GetCdmId()); } - DCHECK(cdm_context_->GetCdmId() != media::CdmContext::kInvalidCdmId); - player_manager_->SetCdm(player_id_, cdm_context_->GetCdmId()); cdm_attached_cb.Run(true); } -void WebMediaPlayerAndroid::SetDecryptorReadyCB( - const media::DecryptorReadyCB& decryptor_ready_cb) { +void WebMediaPlayerAndroid::SetCdmReadyCB( + const media::CdmReadyCB& cdm_ready_cb) { DCHECK(main_thread_checker_.CalledOnValidThread()); DCHECK(is_player_initialized_); - // Cancels the previous decryptor request. - if (decryptor_ready_cb.is_null()) { - if (!decryptor_ready_cb_.is_null()) { - base::ResetAndReturn(&decryptor_ready_cb_) - .Run(NULL, base::Bind(&media::IgnoreCdmAttached)); + // Cancels the previous CDM request. + if (cdm_ready_cb.is_null()) { + if (!cdm_ready_cb_.is_null()) { + base::ResetAndReturn(&cdm_ready_cb_) + .Run(nullptr, base::Bind(&media::IgnoreCdmAttached)); } return; } - // TODO(xhwang): Support multiple decryptor notification request (e.g. from + // TODO(xhwang): Support multiple CDM notification request (e.g. from // video and audio). The current implementation is okay for the current // media pipeline since we initialize audio and video decoders in sequence. - // But WebMediaPlayerImpl should not depend on media pipeline's implementation - // detail. - DCHECK(decryptor_ready_cb_.is_null()); + // But WebMediaPlayerAndroid should not depend on media pipeline's + // implementation detail. + DCHECK(cdm_ready_cb_.is_null()); + cdm_ready_cb_ = cdm_ready_cb; - if (cdm_context_) { - decryptor_ready_cb.Run(cdm_context_->GetDecryptor(), - base::Bind(&media::IgnoreCdmAttached)); - return; - } - - decryptor_ready_cb_ = decryptor_ready_cb; + if (cdm_context_) + SetCdmInternal(base::Bind(&media::IgnoreCdmAttached)); } bool WebMediaPlayerAndroid::supportsOverlayFullscreenVideo() { diff --git a/content/renderer/media/android/webmediaplayer_android.h b/content/renderer/media/android/webmediaplayer_android.h index 2dea4b4..59859ff 100644 --- a/content/renderer/media/android/webmediaplayer_android.h +++ b/content/renderer/media/android/webmediaplayer_android.h @@ -320,15 +320,18 @@ class WebMediaPlayerAndroid : public blink::WebMediaPlayer, void OnCdmContextReady(media::CdmContext* cdm_context); // Sets the CDM. Should only be called when |is_player_initialized_| is true - // and a new non-null |cdm_context_| is available. Fires |cdm_attached_cb_| - // with the result after the CDM is attached. + // and a new non-null |cdm_context_| is available. Fires |cdm_attached_cb_| on + // the main thread with the result after the CDM is attached. void SetCdmInternal(const media::CdmAttachedCB& cdm_attached_cb); - // Requests that this object notifies when a decryptor is ready through the - // |decryptor_ready_cb| provided. - // If |decryptor_ready_cb| is null, the existing callback will be fired with + // Called when the CDM is attached. + void OnCdmAttached(const media::CdmAttachedCB& cdm_attached_cb, bool success); + + // Requests that this object notifies when a CDM is ready through the + // |cdm_ready_cb| provided. + // If |cdm_ready_cb| is null, the existing callback will be fired with // NULL immediately and reset. - void SetDecryptorReadyCB(const media::DecryptorReadyCB& decryptor_ready_cb); + void SetCdmReadyCB(const media::CdmReadyCB& cdm_ready_cb); // Called when the ContentDecryptionModule has been attached to the // pipeline/decoders. @@ -509,7 +512,7 @@ class WebMediaPlayerAndroid : public blink::WebMediaPlayer, // side CDM will be used. This is similar to WebMediaPlayerImpl. For other key // systems, a browser side CDM will be used and we set CDM by calling // player_manager_->SetCdm() directly. - media::DecryptorReadyCB decryptor_ready_cb_; + media::CdmReadyCB cdm_ready_cb_; SkBitmap bitmap_; |