summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorxhwang@chromium.org <xhwang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-30 00:40:57 +0000
committerxhwang@chromium.org <xhwang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-30 00:40:57 +0000
commit15b05a7d37381e8487fb7eebf2d90355a8774431 (patch)
tree3bfd05db47b68792b3dbd9c6b72f158e47cccb10 /media
parent2dcec1fbb4343693721ec1b81452a93883efbc2e (diff)
downloadchromium_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
Diffstat (limited to 'media')
-rw-r--r--media/base/decryptor.h80
-rw-r--r--media/base/media_keys.cc13
-rw-r--r--media/base/media_keys.h89
-rw-r--r--media/base/mock_filters.h14
-rw-r--r--media/crypto/aes_decryptor.cc10
-rw-r--r--media/crypto/aes_decryptor.h14
-rw-r--r--media/crypto/aes_decryptor_unittest.cc4
-rw-r--r--media/filters/pipeline_integration_test.cc5
-rw-r--r--media/filters/pipeline_integration_test_base.h1
-rw-r--r--media/media.gyp2
10 files changed, 138 insertions, 94 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',