diff options
author | xhwang@chromium.org <xhwang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-30 00:40:57 +0000 |
---|---|---|
committer | xhwang@chromium.org <xhwang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-30 00:40:57 +0000 |
commit | 15b05a7d37381e8487fb7eebf2d90355a8774431 (patch) | |
tree | 3bfd05db47b68792b3dbd9c6b72f158e47cccb10 | |
parent | 2dcec1fbb4343693721ec1b81452a93883efbc2e (diff) | |
download | chromium_src-15b05a7d37381e8487fb7eebf2d90355a8774431.zip chromium_src-15b05a7d37381e8487fb7eebf2d90355a8774431.tar.gz chromium_src-15b05a7d37381e8487fb7eebf2d90355a8774431.tar.bz2 |
Separate MediaKeys interface from Decryptor interface.
BUG=none
TEST=none
Review URL: https://chromiumcodereview.appspot.com/15772012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@203026 0039d316-1c4b-4281-b951-d872f2087c98
22 files changed, 189 insertions, 132 deletions
diff --git a/media/base/decryptor.h b/media/base/decryptor.h index e3a2cb6..f3a3c22 100644 --- a/media/base/decryptor.h +++ b/media/base/decryptor.h @@ -6,7 +6,6 @@ #define MEDIA_BASE_DECRYPTOR_H_ #include <list> -#include <string> #include "base/basictypes.h" #include "base/callback.h" @@ -18,34 +17,18 @@ namespace media { class AudioDecoderConfig; class DataBuffer; class DecoderBuffer; +class MediaKeys; class VideoDecoderConfig; class VideoFrame; -// Performs key operations and decrypts (and decodes) encrypted buffer. +// Decrypts (and decodes) encrypted buffer. // -// Key operations (GenerateKeyRequest(), AddKey() and CancelKeyRequest()) -// are called on the renderer thread. Therefore, these calls should be fast -// and nonblocking; key events should be fired asynchronously. -// All other methods are called on the (video/audio) decoder thread. -// Decryptor implementations must be thread safe when methods are called -// following the above model. +// All methods are called on the (video/audio) decoder thread. Decryptor +// implementations must be thread safe when methods are called this way. // Depending on the implementation callbacks may be fired synchronously or // asynchronously. class MEDIA_EXPORT Decryptor { public: - // Reported to UMA, so never reuse a value! - // Must be kept in sync with WebKit::WebMediaPlayerClient::MediaKeyErrorCode - // (enforced in webmediaplayer_impl.cc). - enum KeyError { - kUnknownError = 1, - kClientError, - kServiceError, - kOutputError, - kHardwareChangeError, - kDomainError, - kMaxKeyError // Must be last and greater than any legit value. - }; - // TODO(xhwang): Replace kError with kDecryptError and kDecodeError. // TODO(xhwang): Replace kNeedMoreData with kNotEnoughData. enum Status { @@ -64,32 +47,13 @@ class MEDIA_EXPORT Decryptor { Decryptor(); virtual ~Decryptor(); - // Generates a key request for the |key_system| with |type| and - // |init_data| provided. - // Returns true if generating key request succeeded, false otherwise. - // Note: AddKey() and CancelKeyRequest() should only be called after - // GenerateKeyRequest() returns true. - virtual bool GenerateKeyRequest(const std::string& key_system, - const std::string& type, - const uint8* init_data, - int init_data_length) = 0; - - // Adds a |key| to the |key_system|. The |key| is not limited to a decryption - // key. It can be any data that the key system accepts, such as a license. - // If multiple calls of this function set different keys for the same - // key ID, the older key will be replaced by the newer key. - virtual void AddKey(const std::string& key_system, - const uint8* key, - int key_length, - const uint8* init_data, - int init_data_length, - const std::string& session_id) = 0; - - // Cancels the key request specified by |session_id|. - virtual void CancelKeyRequest(const std::string& key_system, - const std::string& session_id) = 0; - - // Indicates that a new key has been added to the Decryptor. + // Gets the MediaKey object associated with the Decryptor. Returns NULL if + // no MediaKey object is associated. The returned object is only guaranteed + // to be valid during the Decryptor's lifetime. + virtual MediaKeys* GetMediaKeys() = 0; + + // Indicates that a new key has been added to the MediaKeys object associated + // with the Decryptor. typedef base::Callback<void()> NewKeyCB; // Registers a NewKeyCB which should be called when a new key is added to the @@ -215,28 +179,6 @@ typedef base::Callback<void(Decryptor*)> DecryptorReadyCB; // fired immediately with NULL. typedef base::Callback<void(const DecryptorReadyCB&)> SetDecryptorReadyCB; - -// Key event callbacks. See the spec for details: -// http://dvcs.w3.org/hg/html-media/raw-file/eme-v0.1b/encrypted-media/encrypted-media.html#event-summary -typedef base::Callback<void(const std::string& key_system, - const std::string& session_id)> KeyAddedCB; - -typedef base::Callback<void(const std::string& key_system, - const std::string& session_id, - media::Decryptor::KeyError error_code, - int system_code)> KeyErrorCB; - -typedef base::Callback<void(const std::string& key_system, - const std::string& session_id, - const std::string& message, - const std::string& default_url)> KeyMessageCB; - -typedef base::Callback<void(const std::string& key_system, - const std::string& session_id, - const std::string& type, - scoped_ptr<uint8[]> init_data, - int init_data_size)> NeedKeyCB; - } // namespace media #endif // MEDIA_BASE_DECRYPTOR_H_ diff --git a/media/base/media_keys.cc b/media/base/media_keys.cc new file mode 100644 index 0000000..cf5256b --- /dev/null +++ b/media/base/media_keys.cc @@ -0,0 +1,13 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "media/base/media_keys.h" + +namespace media { + +MediaKeys::MediaKeys() {} + +MediaKeys::~MediaKeys() {} + +} // namespace media diff --git a/media/base/media_keys.h b/media/base/media_keys.h new file mode 100644 index 0000000..14789e2 --- /dev/null +++ b/media/base/media_keys.h @@ -0,0 +1,89 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef MEDIA_BASE_MEDIA_KEYS_H_ +#define MEDIA_BASE_MEDIA_KEYS_H_ + +#include <string> + +#include "base/basictypes.h" +#include "base/callback.h" +#include "base/memory/scoped_ptr.h" +#include "media/base/media_export.h" + +namespace media { + +// Performs media key operations. +// +// All key operations are called on the renderer thread. Therefore, these calls +// should be fast and nonblocking; key events should be fired asynchronously. +class MEDIA_EXPORT MediaKeys { + public: + // Reported to UMA, so never reuse a value! + // Must be kept in sync with WebKit::WebMediaPlayerClient::MediaKeyErrorCode + // (enforced in webmediaplayer_impl.cc). + enum KeyError { + kUnknownError = 1, + kClientError, + kServiceError, + kOutputError, + kHardwareChangeError, + kDomainError, + kMaxKeyError // Must be last and greater than any legit value. + }; + + MediaKeys(); + virtual ~MediaKeys(); + + // Generates a key request for the |key_system| with |type| and + // |init_data| provided. + // Returns true if generating key request succeeded, false otherwise. + // Note: AddKey() and CancelKeyRequest() should only be called after + // GenerateKeyRequest() returns true. + virtual bool GenerateKeyRequest(const std::string& key_system, + const std::string& type, + const uint8* init_data, + int init_data_length) = 0; + + // Adds a |key| to the |key_system|. The |key| is not limited to a decryption + // key. It can be any data that the key system accepts, such as a license. + // If multiple calls of this function set different keys for the same + // key ID, the older key will be replaced by the newer key. + virtual void AddKey(const std::string& key_system, + const uint8* key, int key_length, + const uint8* init_data, int init_data_length, + const std::string& session_id) = 0; + + // Cancels the key request specified by |session_id|. + virtual void CancelKeyRequest(const std::string& key_system, + const std::string& session_id) = 0; + + private: + DISALLOW_COPY_AND_ASSIGN(MediaKeys); +}; + +// Key event callbacks. See the spec for details: +// http://dvcs.w3.org/hg/html-media/raw-file/eme-v0.1b/encrypted-media/encrypted-media.html#event-summary +typedef base::Callback<void(const std::string& key_system, + const std::string& session_id)> KeyAddedCB; + +typedef base::Callback<void(const std::string& key_system, + const std::string& session_id, + media::MediaKeys::KeyError error_code, + int system_code)> KeyErrorCB; + +typedef base::Callback<void(const std::string& key_system, + const std::string& session_id, + const std::string& message, + const std::string& default_url)> KeyMessageCB; + +typedef base::Callback<void(const std::string& key_system, + const std::string& session_id, + const std::string& type, + scoped_ptr<uint8[]> init_data, + int init_data_size)> NeedKeyCB; + +} // namespace media + +#endif // MEDIA_BASE_MEDIA_KEYS_H_ diff --git a/media/base/mock_filters.h b/media/base/mock_filters.h index 5bc9071..5b9062a 100644 --- a/media/base/mock_filters.h +++ b/media/base/mock_filters.h @@ -160,18 +160,8 @@ class MockDecryptor : public Decryptor { MockDecryptor(); virtual ~MockDecryptor(); - MOCK_METHOD4(GenerateKeyRequest, bool(const std::string& key_system, - const std::string& type, - const uint8* init_data, - int init_data_length)); - MOCK_METHOD6(AddKey, void(const std::string& key_system, - const uint8* key, - int key_length, - const uint8* init_data, - int init_data_length, - const std::string& session_id)); - MOCK_METHOD2(CancelKeyRequest, void(const std::string& key_system, - const std::string& session_id)); + MOCK_METHOD0(GetMediaKeys, MediaKeys*(void)); + MOCK_METHOD2(RegisterNewKeyCB, void(StreamType stream_type, const NewKeyCB& new_key_cb)); MOCK_METHOD3(Decrypt, void(StreamType stream_type, diff --git a/media/crypto/aes_decryptor.cc b/media/crypto/aes_decryptor.cc index 29faca0..6402ef0 100644 --- a/media/crypto/aes_decryptor.cc +++ b/media/crypto/aes_decryptor.cc @@ -169,7 +169,7 @@ void AesDecryptor::AddKey(const std::string& key_system, // https://www.w3.org/Bugs/Public/show_bug.cgi?id=16550 if (key_length != DecryptConfig::kDecryptionKeySize) { DVLOG(1) << "Invalid key length: " << key_length; - key_error_cb_.Run(key_system, session_id, Decryptor::kUnknownError, 0); + key_error_cb_.Run(key_system, session_id, MediaKeys::kUnknownError, 0); return; } @@ -189,13 +189,13 @@ void AesDecryptor::AddKey(const std::string& key_system, scoped_ptr<DecryptionKey> decryption_key(new DecryptionKey(key_string)); if (!decryption_key) { DVLOG(1) << "Could not create key."; - key_error_cb_.Run(key_system, session_id, Decryptor::kUnknownError, 0); + key_error_cb_.Run(key_system, session_id, MediaKeys::kUnknownError, 0); return; } if (!decryption_key->Init()) { DVLOG(1) << "Could not initialize decryption key."; - key_error_cb_.Run(key_system, session_id, Decryptor::kUnknownError, 0); + key_error_cb_.Run(key_system, session_id, MediaKeys::kUnknownError, 0); return; } @@ -214,6 +214,10 @@ void AesDecryptor::CancelKeyRequest(const std::string& key_system, const std::string& session_id) { } +MediaKeys* AesDecryptor::GetMediaKeys() { + return this; +} + void AesDecryptor::RegisterNewKeyCB(StreamType stream_type, const NewKeyCB& new_key_cb) { switch (stream_type) { diff --git a/media/crypto/aes_decryptor.h b/media/crypto/aes_decryptor.h index 38d6788..312e29c 100644 --- a/media/crypto/aes_decryptor.h +++ b/media/crypto/aes_decryptor.h @@ -15,6 +15,7 @@ #include "base/synchronization/lock.h" #include "media/base/decryptor.h" #include "media/base/media_export.h" +#include "media/base/media_keys.h" namespace crypto { class SymmetricKey; @@ -24,7 +25,7 @@ namespace media { // Decrypts an AES encrypted buffer into an unencrypted buffer. The AES // encryption must be CTR with a key size of 128bits. -class MEDIA_EXPORT AesDecryptor : public Decryptor { +class MEDIA_EXPORT AesDecryptor : public MediaKeys, public Decryptor { public: AesDecryptor(const KeyAddedCB& key_added_cb, const KeyErrorCB& key_error_cb, @@ -32,19 +33,20 @@ class MEDIA_EXPORT AesDecryptor : public Decryptor { const NeedKeyCB& need_key_cb); virtual ~AesDecryptor(); - // Decryptor implementation. + // MediaKeys implementation. virtual bool GenerateKeyRequest(const std::string& key_system, const std::string& type, const uint8* init_data, int init_data_length) OVERRIDE; virtual void AddKey(const std::string& key_system, - const uint8* key, - int key_length, - const uint8* init_data, - int init_data_length, + const uint8* key, int key_length, + const uint8* init_data, int init_data_length, const std::string& session_id) OVERRIDE; virtual void CancelKeyRequest(const std::string& key_system, const std::string& session_id) OVERRIDE; + + // Decryptor implementation. + virtual MediaKeys* GetMediaKeys() OVERRIDE; virtual void RegisterNewKeyCB(StreamType stream_type, const NewKeyCB& key_added_cb) OVERRIDE; virtual void Decrypt(StreamType stream_type, diff --git a/media/crypto/aes_decryptor_unittest.cc b/media/crypto/aes_decryptor_unittest.cc index abc7e6e..120be12 100644 --- a/media/crypto/aes_decryptor_unittest.cc +++ b/media/crypto/aes_decryptor_unittest.cc @@ -261,7 +261,7 @@ class AesDecryptorTest : public testing::Test { void AddKeyAndExpectToFail(const uint8* key_id, int key_id_size, const uint8* key, int key_size) { EXPECT_CALL(*this, KeyError(kClearKeySystem, session_id_string_, - Decryptor::kUnknownError, 0)); + MediaKeys::kUnknownError, 0)); decryptor_.AddKey(kClearKeySystem, key, key_size, key_id, key_id_size, session_id_string_); } @@ -314,7 +314,7 @@ class AesDecryptorTest : public testing::Test { MOCK_METHOD2(KeyAdded, void(const std::string&, const std::string&)); MOCK_METHOD4(KeyError, void(const std::string&, const std::string&, - Decryptor::KeyError, int)); + MediaKeys::KeyError, int)); MOCK_METHOD4(KeyMessage, void(const std::string& key_system, const std::string& session_id, const std::string& message, diff --git a/media/filters/pipeline_integration_test.cc b/media/filters/pipeline_integration_test.cc index db0ce12..5881f26 100644 --- a/media/filters/pipeline_integration_test.cc +++ b/media/filters/pipeline_integration_test.cc @@ -9,6 +9,7 @@ #include "base/string_util.h" #include "build/build_config.h" #include "media/base/decoder_buffer.h" +#include "media/base/media_keys.h" #include "media/base/test_data_util.h" #include "media/crypto/aes_decryptor.h" #include "media/filters/chunk_demuxer.h" @@ -71,7 +72,7 @@ class FakeEncryptedMedia { // Errors are not expected unless overridden. virtual void KeyError(const std::string& key_system, const std::string& session_id, - AesDecryptor::KeyError error_code, + MediaKeys::KeyError error_code, int system_code) { FAIL() << "Unexpected Key Error"; } @@ -111,7 +112,7 @@ class FakeEncryptedMedia { void KeyError(const std::string& key_system, const std::string& session_id, - AesDecryptor::KeyError error_code, + MediaKeys::KeyError error_code, int system_code) { app_->KeyError(key_system, session_id, error_code, system_code); } diff --git a/media/filters/pipeline_integration_test_base.h b/media/filters/pipeline_integration_test_base.h index ab6b8af..88783ea 100644 --- a/media/filters/pipeline_integration_test_base.h +++ b/media/filters/pipeline_integration_test_base.h @@ -9,6 +9,7 @@ #include "base/md5.h" #include "media/audio/null_audio_sink.h" #include "media/base/filter_collection.h" +#include "media/base/media_keys.h" #include "media/base/pipeline.h" #include "media/base/video_frame.h" #include "media/filters/video_renderer_base.h" diff --git a/media/media.gyp b/media/media.gyp index 3a9cb7b..aa924b5 100644 --- a/media/media.gyp +++ b/media/media.gyp @@ -264,6 +264,8 @@ 'base/filter_collection.h', 'base/media.cc', 'base/media.h', + 'base/media_keys.cc', + 'base/media_keys.h', 'base/media_log.cc', 'base/media_log.h', 'base/media_log_event.h', diff --git a/webkit/media/android/media_source_delegate.cc b/webkit/media/android/media_source_delegate.cc index 1386ca2..f4d53b2 100644 --- a/webkit/media/android/media_source_delegate.cc +++ b/webkit/media/android/media_source_delegate.cc @@ -441,7 +441,7 @@ void MediaSourceDelegate::OnDemuxerOpened() { void MediaSourceDelegate::OnKeyError(const std::string& key_system, const std::string& session_id, - media::Decryptor::KeyError error_code, + media::MediaKeys::KeyError error_code, int system_code) { if (!client_) return; diff --git a/webkit/media/android/media_source_delegate.h b/webkit/media/android/media_source_delegate.h index ae0c656..3c5ddf6 100644 --- a/webkit/media/android/media_source_delegate.h +++ b/webkit/media/android/media_source_delegate.h @@ -12,6 +12,7 @@ #include "base/time.h" #include "media/base/decryptor.h" #include "media/base/demuxer.h" +#include "media/base/media_keys.h" #include "media/base/pipeline_status.h" #include "media/base/ranges.h" #include "media/base/text_track.h" @@ -110,7 +111,7 @@ class MediaSourceDelegate : public media::DemuxerHost { void OnKeyAdded(const std::string& key_system, const std::string& session_id); void OnKeyError(const std::string& key_system, const std::string& session_id, - media::Decryptor::KeyError error_code, + media::MediaKeys::KeyError error_code, int system_code); void OnKeyMessage(const std::string& key_system, const std::string& session_id, diff --git a/webkit/media/crypto/ppapi/clear_key_cdm.cc b/webkit/media/crypto/ppapi/clear_key_cdm.cc index faa6635..94ea181 100644 --- a/webkit/media/crypto/ppapi/clear_key_cdm.cc +++ b/webkit/media/crypto/ppapi/clear_key_cdm.cc @@ -168,7 +168,7 @@ void ClearKeyCdm::Client::KeyAdded(const std::string& key_system, void ClearKeyCdm::Client::KeyError(const std::string& key_system, const std::string& session_id, - media::Decryptor::KeyError error_code, + media::MediaKeys::KeyError error_code, int system_code) { status_ = kKeyError; session_id_ = session_id; diff --git a/webkit/media/crypto/ppapi/clear_key_cdm.h b/webkit/media/crypto/ppapi/clear_key_cdm.h index 35f0187..8b1715b 100644 --- a/webkit/media/crypto/ppapi/clear_key_cdm.h +++ b/webkit/media/crypto/ppapi/clear_key_cdm.h @@ -88,7 +88,7 @@ class ClearKeyCdm : public cdm::ContentDecryptionModule { void KeyAdded(const std::string& key_system, const std::string& session_id); void KeyError(const std::string& key_system, const std::string& session_id, - media::Decryptor::KeyError error_code, + media::MediaKeys::KeyError error_code, int system_code); void KeyMessage(const std::string& key_system, const std::string& session_id, diff --git a/webkit/media/crypto/ppapi_decryptor.cc b/webkit/media/crypto/ppapi_decryptor.cc index 7f45178..7777a66 100644 --- a/webkit/media/crypto/ppapi_decryptor.cc +++ b/webkit/media/crypto/ppapi_decryptor.cc @@ -105,6 +105,10 @@ void PpapiDecryptor::CancelKeyRequest(const std::string& key_system, ReportFailureToCallPlugin(key_system, session_id); } +media::MediaKeys* PpapiDecryptor::GetMediaKeys() { + return this; +} + void PpapiDecryptor::RegisterNewKeyCB(StreamType stream_type, const NewKeyCB& new_key_cb) { switch (stream_type) { @@ -264,7 +268,7 @@ void PpapiDecryptor::KeyAdded(const std::string& key_system, void PpapiDecryptor::KeyError(const std::string& key_system, const std::string& session_id, - media::Decryptor::KeyError error_code, + media::MediaKeys::KeyError error_code, int system_code) { DCHECK(render_loop_proxy_->BelongsToCurrentThread()); key_error_cb_.Run(key_system, session_id, error_code, system_code); diff --git a/webkit/media/crypto/ppapi_decryptor.h b/webkit/media/crypto/ppapi_decryptor.h index aad28c6..0827732 100644 --- a/webkit/media/crypto/ppapi_decryptor.h +++ b/webkit/media/crypto/ppapi_decryptor.h @@ -10,6 +10,7 @@ #include "base/memory/ref_counted.h" #include "base/memory/weak_ptr.h" #include "media/base/decryptor.h" +#include "media/base/media_keys.h" #include "media/base/video_decoder_config.h" namespace base { @@ -28,7 +29,7 @@ namespace webkit_media { // PpapiDecryptor implements media::Decryptor and forwards all calls to the // PluginInstance. // This class should always be created & destroyed on the main renderer thread. -class PpapiDecryptor : public media::Decryptor { +class PpapiDecryptor : public media::MediaKeys, public media::Decryptor { public: PpapiDecryptor( const scoped_refptr<webkit::ppapi::PluginInstance>& plugin_instance, @@ -38,19 +39,20 @@ class PpapiDecryptor : public media::Decryptor { const media::NeedKeyCB& need_key_cb); virtual ~PpapiDecryptor(); - // media::Decryptor implementation. + // media::MediaKeys implementation. virtual bool GenerateKeyRequest(const std::string& key_system, const std::string& type, const uint8* init_data, int init_data_length) OVERRIDE; virtual void AddKey(const std::string& key_system, - const uint8* key, - int key_length, - const uint8* init_data, - int init_data_length, + const uint8* key, int key_length, + const uint8* init_data, int init_data_length, const std::string& session_id) OVERRIDE; virtual void CancelKeyRequest(const std::string& key_system, const std::string& session_id) OVERRIDE; + + // media::Decryptor implementation. + virtual media::MediaKeys* GetMediaKeys() OVERRIDE; virtual void RegisterNewKeyCB(StreamType stream_type, const NewKeyCB& key_added_cb) OVERRIDE; virtual void Decrypt(StreamType stream_type, @@ -80,7 +82,7 @@ class PpapiDecryptor : public media::Decryptor { void KeyAdded(const std::string& key_system, const std::string& session_id); void KeyError(const std::string& key_system, const std::string& session_id, - media::Decryptor::KeyError error_code, + media::MediaKeys::KeyError error_code, int system_code); void KeyMessage(const std::string& key_system, const std::string& session_id, diff --git a/webkit/media/crypto/proxy_decryptor.cc b/webkit/media/crypto/proxy_decryptor.cc index 9372f4a4..c542945 100644 --- a/webkit/media/crypto/proxy_decryptor.cc +++ b/webkit/media/crypto/proxy_decryptor.cc @@ -121,13 +121,13 @@ bool ProxyDecryptor::GenerateKeyRequest(const std::string& key_system, decryptor_ = CreateDecryptor(key_system); if (!decryptor_) { key_error_cb_.Run( - key_system, std::string(), media::Decryptor::kClientError, 0); + key_system, std::string(), media::MediaKeys::kClientError, 0); return false; } } - if (!decryptor_->GenerateKeyRequest(key_system, type, - init_data, init_data_length)) { + if (!decryptor_->GetMediaKeys()->GenerateKeyRequest( + key_system, type, init_data, init_data_length)) { decryptor_.reset(); return false; } @@ -147,8 +147,8 @@ void ProxyDecryptor::AddKey(const std::string& key_system, DVLOG(1) << "AddKey()"; // WebMediaPlayerImpl ensures GenerateKeyRequest() has been called. - decryptor_->AddKey(key_system, key, key_length, init_data, init_data_length, - session_id); + decryptor_->GetMediaKeys()->AddKey( + key_system, key, key_length, init_data, init_data_length, session_id); } void ProxyDecryptor::CancelKeyRequest(const std::string& key_system, @@ -156,7 +156,7 @@ void ProxyDecryptor::CancelKeyRequest(const std::string& key_system, DVLOG(1) << "CancelKeyRequest()"; // WebMediaPlayerImpl ensures GenerateKeyRequest() has been called. - decryptor_->CancelKeyRequest(key_system, session_id); + decryptor_->GetMediaKeys()->CancelKeyRequest(key_system, session_id); } #if defined(ENABLE_PEPPER_CDMS) @@ -210,7 +210,7 @@ void ProxyDecryptor::KeyAdded(const std::string& key_system, void ProxyDecryptor::KeyError(const std::string& key_system, const std::string& session_id, - media::Decryptor::KeyError error_code, + media::MediaKeys::KeyError error_code, int system_code) { key_error_cb_.Run(key_system, session_id, error_code, system_code); } diff --git a/webkit/media/crypto/proxy_decryptor.h b/webkit/media/crypto/proxy_decryptor.h index 3e81ce3..df498f9 100644 --- a/webkit/media/crypto/proxy_decryptor.h +++ b/webkit/media/crypto/proxy_decryptor.h @@ -11,6 +11,7 @@ #include "base/memory/weak_ptr.h" #include "base/synchronization/lock.h" #include "media/base/decryptor.h" +#include "media/base/media_keys.h" namespace WebKit { class WebFrame; @@ -23,7 +24,8 @@ namespace webkit_media { // forwards decryptor calls to it. // TODO(xhwang): Currently we don't support run-time switching among decryptor // objects. Fix this when needed. -class ProxyDecryptor { +// TODO(xhwang): The ProxyDecryptor is not a Decryptor. Find a better name! +class ProxyDecryptor : public media::MediaKeys { public: ProxyDecryptor(WebKit::WebMediaPlayerClient* web_media_player_client, WebKit::WebFrame* web_frame, @@ -39,15 +41,17 @@ class ProxyDecryptor { // NULL immediately and reset. void SetDecryptorReadyCB(const media::DecryptorReadyCB& decryptor_ready_cb); - bool GenerateKeyRequest(const std::string& key_system, - const std::string& type, - const uint8* init_data, int init_data_length); - void AddKey(const std::string& key_system, - const uint8* key, int key_length, - const uint8* init_data, int init_data_length, - const std::string& session_id); - void CancelKeyRequest(const std::string& key_system, - const std::string& session_id); + // MediaKeys implementation. + virtual bool GenerateKeyRequest(const std::string& key_system, + const std::string& type, + const uint8* init_data, + int init_data_length) OVERRIDE; + virtual void AddKey(const std::string& key_system, + const uint8* key, int key_length, + const uint8* init_data, int init_data_length, + const std::string& session_id) OVERRIDE; + virtual void CancelKeyRequest(const std::string& key_system, + const std::string& session_id) OVERRIDE; private: // Helper functions to create decryptors to handle the given |key_system|. @@ -61,7 +65,7 @@ class ProxyDecryptor { void KeyAdded(const std::string& key_system, const std::string& session_id); void KeyError(const std::string& key_system, const std::string& session_id, - media::Decryptor::KeyError error_code, + media::MediaKeys::KeyError error_code, int system_code); void KeyMessage(const std::string& key_system, const std::string& session_id, diff --git a/webkit/media/webmediaplayer_impl.cc b/webkit/media/webmediaplayer_impl.cc index 3e2b88a..f489ce4 100644 --- a/webkit/media/webmediaplayer_impl.cc +++ b/webkit/media/webmediaplayer_impl.cc @@ -973,7 +973,7 @@ WebMediaPlayerImpl::OnTextTrack(media::TextKind kind, #define COMPILE_ASSERT_MATCHING_ENUM(name) \ COMPILE_ASSERT(static_cast<int>(WebKit::WebMediaPlayerClient::name) == \ - static_cast<int>(media::Decryptor::k ## name), \ + static_cast<int>(media::MediaKeys::k ## name), \ mismatching_enums) COMPILE_ASSERT_MATCHING_ENUM(UnknownError); COMPILE_ASSERT_MATCHING_ENUM(ClientError); @@ -985,12 +985,12 @@ COMPILE_ASSERT_MATCHING_ENUM(DomainError); void WebMediaPlayerImpl::OnKeyError(const std::string& key_system, const std::string& session_id, - media::Decryptor::KeyError error_code, + media::MediaKeys::KeyError error_code, int system_code) { DCHECK(main_loop_->BelongsToCurrentThread()); EmeUMAHistogramEnumeration( - key_system, "KeyError", error_code, media::Decryptor::kMaxKeyError); + key_system, "KeyError", error_code, media::MediaKeys::kMaxKeyError); GetClient()->keyError( WebString::fromUTF8(key_system), diff --git a/webkit/media/webmediaplayer_impl.h b/webkit/media/webmediaplayer_impl.h index ee7be74..a9763f5 100644 --- a/webkit/media/webmediaplayer_impl.h +++ b/webkit/media/webmediaplayer_impl.h @@ -30,6 +30,7 @@ #include "googleurl/src/gurl.h" #include "media/base/audio_renderer_sink.h" #include "media/base/decryptor.h" +#include "media/base/media_keys.h" #include "media/base/pipeline.h" #include "media/base/text_track.h" #include "media/filters/gpu_video_decoder.h" @@ -201,7 +202,7 @@ class WebMediaPlayerImpl void OnKeyAdded(const std::string& key_system, const std::string& session_id); void OnKeyError(const std::string& key_system, const std::string& session_id, - media::Decryptor::KeyError error_code, + media::MediaKeys::KeyError error_code, int system_code); void OnKeyMessage(const std::string& key_system, const std::string& session_id, diff --git a/webkit/plugins/ppapi/content_decryptor_delegate.cc b/webkit/plugins/ppapi/content_decryptor_delegate.cc index e9567be..be4531a 100644 --- a/webkit/plugins/ppapi/content_decryptor_delegate.cc +++ b/webkit/plugins/ppapi/content_decryptor_delegate.cc @@ -628,7 +628,7 @@ void ContentDecryptorDelegate::KeyAdded(PP_Var key_system_var, StringVar* session_id_string = StringVar::FromPPVar(session_id_var); if (!key_system_string || !session_id_string) { key_error_cb_.Run( - std::string(), std::string(), media::Decryptor::kUnknownError, 0); + std::string(), std::string(), media::MediaKeys::kUnknownError, 0); return; } @@ -658,7 +658,7 @@ void ContentDecryptorDelegate::KeyMessage(PP_Var key_system_var, if (!key_system_string || !session_id_string || !default_url_string) { key_error_cb_.Run( - std::string(), std::string(), media::Decryptor::kUnknownError, 0); + std::string(), std::string(), media::MediaKeys::kUnknownError, 0); return; } @@ -679,14 +679,14 @@ void ContentDecryptorDelegate::KeyError(PP_Var key_system_var, StringVar* session_id_string = StringVar::FromPPVar(session_id_var); if (!key_system_string || !session_id_string) { key_error_cb_.Run( - std::string(), std::string(), media::Decryptor::kUnknownError, 0); + std::string(), std::string(), media::MediaKeys::kUnknownError, 0); return; } key_error_cb_.Run( key_system_string->value(), session_id_string->value(), - static_cast<media::Decryptor::KeyError>(media_error), + static_cast<media::MediaKeys::KeyError>(media_error), system_code); } diff --git a/webkit/plugins/ppapi/content_decryptor_delegate.h b/webkit/plugins/ppapi/content_decryptor_delegate.h index 8cb53b9..07f64cf 100644 --- a/webkit/plugins/ppapi/content_decryptor_delegate.h +++ b/webkit/plugins/ppapi/content_decryptor_delegate.h @@ -13,6 +13,7 @@ #include "base/memory/ref_counted.h" #include "base/memory/weak_ptr.h" #include "media/base/decryptor.h" +#include "media/base/media_keys.h" #include "ppapi/c/private/pp_content_decryptor.h" #include "ppapi/c/private/ppp_content_decryptor_private.h" #include "ui/gfx/size.h" |