diff options
-rw-r--r-- | chromecast/browser/media/cast_browser_cdm_factory.cc | 27 | ||||
-rw-r--r-- | chromecast/browser/media/cast_browser_cdm_factory.h | 11 | ||||
-rw-r--r-- | chromecast/browser/media/cast_browser_cdm_factory_simple.cc | 13 | ||||
-rw-r--r-- | chromecast/media/cdm/browser_cdm_cast.cc | 46 | ||||
-rw-r--r-- | chromecast/media/cdm/browser_cdm_cast.h | 22 |
5 files changed, 90 insertions, 29 deletions
diff --git a/chromecast/browser/media/cast_browser_cdm_factory.cc b/chromecast/browser/media/cast_browser_cdm_factory.cc index 6b6dfff..2dbb544 100644 --- a/chromecast/browser/media/cast_browser_cdm_factory.cc +++ b/chromecast/browser/media/cast_browser_cdm_factory.cc @@ -4,6 +4,8 @@ #include "chromecast/browser/media/cast_browser_cdm_factory.h" +#include "chromecast/media/cdm/browser_cdm_cast.h" + namespace chromecast { namespace media { @@ -16,17 +18,20 @@ scoped_ptr< ::media::BrowserCdm> CastBrowserCdmFactory::CreateBrowserCdm( const ::media::SessionExpirationUpdateCB& session_expiration_update_cb) { CastKeySystem key_system(GetKeySystemByName(key_system_name)); - // TODO(gunsch): handle ClearKey decryption. See crbug.com/441957 - - scoped_ptr< ::media::BrowserCdm> platform_cdm( - CreatePlatformBrowserCdm(key_system, - session_message_cb, - session_closed_cb, - session_error_cb, - session_keys_change_cb, - session_expiration_update_cb)); - if (platform_cdm) { - return platform_cdm.Pass(); + scoped_ptr<chromecast::media::BrowserCdmCast> browser_cdm; + if (key_system == chromecast::media::KEY_SYSTEM_CLEAR_KEY) { + // TODO(gunsch): handle ClearKey decryption. See crbug.com/441957 + } else { + browser_cdm = CreatePlatformBrowserCdm(key_system); + } + + if (browser_cdm) { + browser_cdm->SetCallbacks(session_message_cb, + session_closed_cb, + session_error_cb, + session_keys_change_cb, + session_expiration_update_cb); + return browser_cdm.Pass(); } LOG(INFO) << "No matching key system found."; diff --git a/chromecast/browser/media/cast_browser_cdm_factory.h b/chromecast/browser/media/cast_browser_cdm_factory.h index 245e579..03f4530 100644 --- a/chromecast/browser/media/cast_browser_cdm_factory.h +++ b/chromecast/browser/media/cast_browser_cdm_factory.h @@ -12,6 +12,8 @@ namespace chromecast { namespace media { +class BrowserCdmCast; + class CastBrowserCdmFactory : public ::media::BrowserCdmFactory { public: CastBrowserCdmFactory() {} @@ -32,13 +34,8 @@ class CastBrowserCdmFactory : public ::media::BrowserCdmFactory { }; // Allow platform-specific CDMs to be provided. -scoped_ptr< ::media::BrowserCdm> CreatePlatformBrowserCdm( - const CastKeySystem& key_system, - const ::media::SessionMessageCB& session_message_cb, - const ::media::SessionClosedCB& session_closed_cb, - const ::media::SessionErrorCB& session_error_cb, - const ::media::SessionKeysChangeCB& session_keys_change_cb, - const ::media::SessionExpirationUpdateCB& session_expiration_update_cb); +scoped_ptr<BrowserCdmCast> CreatePlatformBrowserCdm( + const CastKeySystem& key_system); } // namespace media } // namespace chromecast diff --git a/chromecast/browser/media/cast_browser_cdm_factory_simple.cc b/chromecast/browser/media/cast_browser_cdm_factory_simple.cc index 1ccec51..d9ebda1 100644 --- a/chromecast/browser/media/cast_browser_cdm_factory_simple.cc +++ b/chromecast/browser/media/cast_browser_cdm_factory_simple.cc @@ -4,17 +4,14 @@ #include "chromecast/browser/media/cast_browser_cdm_factory.h" +#include "chromecast/media/cdm/browser_cdm_cast.h" + namespace chromecast { namespace media { -scoped_ptr< ::media::BrowserCdm> CreatePlatformBrowserCdm( - const CastKeySystem& key_system, - const ::media::SessionMessageCB& session_message_cb, - const ::media::SessionClosedCB& session_closed_cb, - const ::media::SessionErrorCB& session_error_cb, - const ::media::SessionKeysChangeCB& session_keys_change_cb, - const ::media::SessionExpirationUpdateCB& session_expiration_update_cb) { - return scoped_ptr< ::media::BrowserCdm>(); +scoped_ptr<BrowserCdmCast> CreatePlatformBrowserCdm( + const CastKeySystem& key_system) { + return scoped_ptr<BrowserCdmCast>(); } } // namespace media diff --git a/chromecast/media/cdm/browser_cdm_cast.cc b/chromecast/media/cdm/browser_cdm_cast.cc index bde43a4..c9fbee7 100644 --- a/chromecast/media/cdm/browser_cdm_cast.cc +++ b/chromecast/media/cdm/browser_cdm_cast.cc @@ -4,6 +4,8 @@ #include "chromecast/media/cdm/browser_cdm_cast.h" +#include "media/base/cdm_key_information.h" + namespace chromecast { namespace media { @@ -14,6 +16,19 @@ BrowserCdmCast::~BrowserCdmCast() { player_tracker_.NotifyCdmUnset(); } +void BrowserCdmCast::SetCallbacks( + const ::media::SessionMessageCB& session_message_cb, + const ::media::SessionClosedCB& session_closed_cb, + const ::media::SessionErrorCB& session_error_cb, + const ::media::SessionKeysChangeCB& session_keys_change_cb, + const ::media::SessionExpirationUpdateCB& session_expiration_update_cb) { + session_message_cb_ = session_message_cb; + session_closed_cb_ = session_closed_cb; + session_error_cb_ = session_error_cb; + session_keys_change_cb_ = session_keys_change_cb; + session_expiration_update_cb_ = session_expiration_update_cb; +} + int BrowserCdmCast::RegisterPlayer(const base::Closure& new_key_cb, const base::Closure& cdm_unset_cb) { return player_tracker_.RegisterPlayer(new_key_cb, cdm_unset_cb); @@ -23,7 +38,36 @@ void BrowserCdmCast::UnregisterPlayer(int registration_id) { player_tracker_.UnregisterPlayer(registration_id); } -void BrowserCdmCast::NotifyKeyAdded() { +void BrowserCdmCast::OnSessionMessage(const std::string& web_session_id, + const std::vector<uint8>& message, + const GURL& destination_url) { + // Note: Message type is not supported in Chromecast. Do our best guess here. + ::media::MediaKeys::MessageType message_type = + destination_url.is_empty() ? ::media::MediaKeys::LICENSE_REQUEST + : ::media::MediaKeys::LICENSE_RENEWAL; + session_message_cb_.Run(web_session_id, + message_type, + message, + destination_url); +} + +void BrowserCdmCast::OnSessionClosed(const std::string& web_session_id) { + session_closed_cb_.Run(web_session_id); +} + +void BrowserCdmCast::OnSessionKeysChange( + const std::string& web_session_id, + const ::media::KeyIdAndKeyPairs& keys) { + ::media::CdmKeysInfo cdm_keys_info; + for (const std::pair<std::string, std::string>& key : keys) { + scoped_ptr< ::media::CdmKeyInformation> cdm_key_information( + new ::media::CdmKeyInformation()); + cdm_key_information->key_id.assign(key.first.begin(), key.first.end()); + cdm_keys_info.push_back(cdm_key_information.release()); + } + session_keys_change_cb_.Run(web_session_id, true, cdm_keys_info.Pass()); + + // Notify listeners of a new key. player_tracker_.NotifyNewKey(); } diff --git a/chromecast/media/cdm/browser_cdm_cast.h b/chromecast/media/cdm/browser_cdm_cast.h index 6a51ddc..66c1794 100644 --- a/chromecast/media/cdm/browser_cdm_cast.h +++ b/chromecast/media/cdm/browser_cdm_cast.h @@ -14,6 +14,7 @@ #include "base/macros.h" #include "base/memory/ref_counted.h" #include "media/base/browser_cdm.h" +#include "media/cdm/json_web_key.h" #include "media/cdm/player_tracker_impl.h" namespace chromecast { @@ -32,6 +33,13 @@ class BrowserCdmCast : public ::media::BrowserCdm { BrowserCdmCast(); ~BrowserCdmCast() override; + void SetCallbacks( + const ::media::SessionMessageCB& session_message_cb, + const ::media::SessionClosedCB& session_closed_cb, + const ::media::SessionErrorCB& session_error_cb, + const ::media::SessionKeysChangeCB& session_keys_change_cb, + const ::media::SessionExpirationUpdateCB& session_expiration_update_cb); + // PlayerTracker implementation. int RegisterPlayer(const base::Closure& new_key_cb, const base::Closure& cdm_unset_cb) override; @@ -44,10 +52,20 @@ class BrowserCdmCast : public ::media::BrowserCdm { const std::string& key_id) const = 0; protected: - // Notifies all listeners a new key was added. - void NotifyKeyAdded(); + void OnSessionMessage(const std::string& web_session_id, + const std::vector<uint8>& message, + const GURL& destination_url); + void OnSessionClosed(const std::string& web_session_id); + void OnSessionKeysChange(const std::string& web_session_id, + const ::media::KeyIdAndKeyPairs& keys); private: + ::media::SessionMessageCB session_message_cb_; + ::media::SessionClosedCB session_closed_cb_; + ::media::SessionErrorCB session_error_cb_; + ::media::SessionKeysChangeCB session_keys_change_cb_; + ::media::SessionExpirationUpdateCB session_expiration_update_cb_; + ::media::PlayerTrackerImpl player_tracker_; DISALLOW_COPY_AND_ASSIGN(BrowserCdmCast); |