Commit 2567caca authored by gunsch's avatar gunsch Committed by Commit bot

Chromecast: change BrowserCdmCast threading model.

Per crbug/444930 discussion, BrowserCdm should generally remain on UI
thread. Interactions between the CMA pipeline and BrowserCdm should
remain thread-safe.

R=erickung@chromium.org,lcwu@chromium.org

Review URL: https://codereview.chromium.org/903083003

Cr-Commit-Position: refs/heads/master@{#315359}
parent eaa83600
...@@ -9,11 +9,16 @@ ...@@ -9,11 +9,16 @@
namespace chromecast { namespace chromecast {
namespace media { namespace media {
BrowserCdmCast::BrowserCdmCast() { BrowserCdmCast::BrowserCdmCast()
: next_registration_id_(0) {
} }
BrowserCdmCast::~BrowserCdmCast() { BrowserCdmCast::~BrowserCdmCast() {
player_tracker_.NotifyCdmUnset(); base::AutoLock auto_lock(callback_lock_);
for (std::map<uint32_t, base::Closure>::const_iterator it =
cdm_unset_callbacks_.begin(); it != cdm_unset_callbacks_.end(); ++it) {
it->second.Run();
}
} }
void BrowserCdmCast::SetCallbacks( void BrowserCdmCast::SetCallbacks(
...@@ -31,11 +36,25 @@ void BrowserCdmCast::SetCallbacks( ...@@ -31,11 +36,25 @@ void BrowserCdmCast::SetCallbacks(
int BrowserCdmCast::RegisterPlayer(const base::Closure& new_key_cb, int BrowserCdmCast::RegisterPlayer(const base::Closure& new_key_cb,
const base::Closure& cdm_unset_cb) { const base::Closure& cdm_unset_cb) {
return player_tracker_.RegisterPlayer(new_key_cb, cdm_unset_cb); int registration_id = next_registration_id_++;
DCHECK(!new_key_cb.is_null());
DCHECK(!cdm_unset_cb.is_null());
{
base::AutoLock auto_lock(callback_lock_);
DCHECK(!ContainsKey(new_key_callbacks_, registration_id));
DCHECK(!ContainsKey(cdm_unset_callbacks_, registration_id));
new_key_callbacks_[registration_id] = new_key_cb;
cdm_unset_callbacks_[registration_id] = cdm_unset_cb;
}
return registration_id;
} }
void BrowserCdmCast::UnregisterPlayer(int registration_id) { void BrowserCdmCast::UnregisterPlayer(int registration_id) {
player_tracker_.UnregisterPlayer(registration_id); base::AutoLock auto_lock(callback_lock_);
DCHECK(ContainsKey(new_key_callbacks_, registration_id));
DCHECK(ContainsKey(cdm_unset_callbacks_, registration_id));
new_key_callbacks_.erase(registration_id);
cdm_unset_callbacks_.erase(registration_id);
} }
void BrowserCdmCast::OnSessionMessage(const std::string& web_session_id, void BrowserCdmCast::OnSessionMessage(const std::string& web_session_id,
...@@ -68,7 +87,13 @@ void BrowserCdmCast::OnSessionKeysChange( ...@@ -68,7 +87,13 @@ void BrowserCdmCast::OnSessionKeysChange(
session_keys_change_cb_.Run(web_session_id, true, cdm_keys_info.Pass()); session_keys_change_cb_.Run(web_session_id, true, cdm_keys_info.Pass());
// Notify listeners of a new key. // Notify listeners of a new key.
player_tracker_.NotifyNewKey(); {
base::AutoLock auto_lock(callback_lock_);
for (std::map<uint32_t, base::Closure>::const_iterator it =
new_key_callbacks_.begin(); it != new_key_callbacks_.end(); ++it) {
it->second.Run();
}
}
} }
} // namespace media } // namespace media
......
...@@ -13,9 +13,9 @@ ...@@ -13,9 +13,9 @@
#include "base/callback.h" #include "base/callback.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/synchronization/lock.h"
#include "media/base/browser_cdm.h" #include "media/base/browser_cdm.h"
#include "media/cdm/json_web_key.h" #include "media/cdm/json_web_key.h"
#include "media/cdm/player_tracker_impl.h"
namespace chromecast { namespace chromecast {
namespace media { namespace media {
...@@ -49,7 +49,7 @@ class BrowserCdmCast : public ::media::BrowserCdm { ...@@ -49,7 +49,7 @@ class BrowserCdmCast : public ::media::BrowserCdm {
// |key_id|. // |key_id|.
// Returns null if |key_id| is not available. // Returns null if |key_id| is not available.
virtual scoped_refptr<DecryptContext> GetDecryptContext( virtual scoped_refptr<DecryptContext> GetDecryptContext(
const std::string& key_id) const = 0; const std::string& key_id) = 0;
protected: protected:
void OnSessionMessage(const std::string& web_session_id, void OnSessionMessage(const std::string& web_session_id,
...@@ -66,7 +66,10 @@ class BrowserCdmCast : public ::media::BrowserCdm { ...@@ -66,7 +66,10 @@ class BrowserCdmCast : public ::media::BrowserCdm {
::media::SessionKeysChangeCB session_keys_change_cb_; ::media::SessionKeysChangeCB session_keys_change_cb_;
::media::SessionExpirationUpdateCB session_expiration_update_cb_; ::media::SessionExpirationUpdateCB session_expiration_update_cb_;
::media::PlayerTrackerImpl player_tracker_; base::Lock callback_lock_;
uint32_t next_registration_id_;
std::map<uint32_t, base::Closure> new_key_callbacks_;
std::map<uint32_t, base::Closure> cdm_unset_callbacks_;
DISALLOW_COPY_AND_ASSIGN(BrowserCdmCast); DISALLOW_COPY_AND_ASSIGN(BrowserCdmCast);
}; };
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "chromecast/media/cma/base/decoder_buffer_base.h" #include "chromecast/media/cma/base/decoder_buffer_base.h"
#include "chromecast/media/cma/pipeline/decrypt_util.h" #include "chromecast/media/cma/pipeline/decrypt_util.h"
#include "media/base/audio_decoder_config.h" #include "media/base/audio_decoder_config.h"
#include "media/base/bind_to_current_loop.h"
#include "media/base/decrypt_config.h" #include "media/base/decrypt_config.h"
namespace chromecast { namespace chromecast {
...@@ -187,8 +188,10 @@ void AvPipelineImpl::SetCdm(BrowserCdmCast* media_keys) { ...@@ -187,8 +188,10 @@ void AvPipelineImpl::SetCdm(BrowserCdmCast* media_keys) {
media_keys_ = media_keys; media_keys_ = media_keys;
media_keys_callback_id_ = media_keys_->RegisterPlayer( media_keys_callback_id_ = media_keys_->RegisterPlayer(
base::Bind(&AvPipelineImpl::OnCdmStateChanged, weak_this_), ::media::BindToCurrentLoop(
base::Bind(&AvPipelineImpl::OnCdmDestroyed, weak_this_)); base::Bind(&AvPipelineImpl::OnCdmStateChanged, weak_this_)),
::media::BindToCurrentLoop(
base::Bind(&AvPipelineImpl::OnCdmDestroyed, weak_this_)));
} }
void AvPipelineImpl::OnEos() { void AvPipelineImpl::OnEos() {
......
...@@ -114,6 +114,7 @@ void MediaPipelineImpl::SetCdm(int cdm_id) { ...@@ -114,6 +114,7 @@ void MediaPipelineImpl::SetCdm(int cdm_id) {
void MediaPipelineImpl::SetCdm(::media::BrowserCdm* media_keys) { void MediaPipelineImpl::SetCdm(::media::BrowserCdm* media_keys) {
CMALOG(kLogControl) << __FUNCTION__; CMALOG(kLogControl) << __FUNCTION__;
DCHECK(thread_checker_.CalledOnValidThread());
audio_pipeline_->SetCdm(static_cast<BrowserCdmCast*>(media_keys)); audio_pipeline_->SetCdm(static_cast<BrowserCdmCast*>(media_keys));
video_pipeline_->SetCdm(static_cast<BrowserCdmCast*>(media_keys)); video_pipeline_->SetCdm(static_cast<BrowserCdmCast*>(media_keys));
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment