summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorxhwang@chromium.org <xhwang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-19 20:06:18 +0000
committerxhwang@chromium.org <xhwang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-19 20:06:18 +0000
commit3942cc79573bf0234b43f49f0ae90571698d8067 (patch)
tree91b7b971049f05336728b0d96ec200539001c27d /media
parentcbd9de3af676b13af875bf52980ace4ad8a576e0 (diff)
downloadchromium_src-3942cc79573bf0234b43f49f0ae90571698d8067.zip
chromium_src-3942cc79573bf0234b43f49f0ae90571698d8067.tar.gz
chromium_src-3942cc79573bf0234b43f49f0ae90571698d8067.tar.bz2
Add Decryptor interface.
This is in preparation for the ProxyDecryptor and PpapiDecryptor. BUG=123260 TEST=media_unittests, media layout tests Review URL: https://chromiumcodereview.appspot.com/10539150 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@143030 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r--media/base/decryptor.h69
-rw-r--r--media/base/decryptor_client.h (renamed from media/crypto/decryptor_client.h)10
-rw-r--r--media/base/mock_filters.h4
-rw-r--r--media/crypto/aes_decryptor.cc6
-rw-r--r--media/crypto/aes_decryptor.h69
-rw-r--r--media/crypto/aes_decryptor_unittest.cc2
-rw-r--r--media/filters/ffmpeg_video_decoder.cc3
-rw-r--r--media/filters/ffmpeg_video_decoder.h6
-rw-r--r--media/filters/ffmpeg_video_decoder_unittest.cc3
-rw-r--r--media/filters/pipeline_integration_test.cc10
-rw-r--r--media/media.gyp3
11 files changed, 115 insertions, 70 deletions
diff --git a/media/base/decryptor.h b/media/base/decryptor.h
new file mode 100644
index 0000000..924f3ac
--- /dev/null
+++ b/media/base/decryptor.h
@@ -0,0 +1,69 @@
+// Copyright (c) 2012 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_DECRYPTOR_H_
+#define MEDIA_BASE_DECRYPTOR_H_
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/memory/ref_counted.h"
+#include "media/base/media_export.h"
+
+namespace media {
+
+class DecoderBuffer;
+
+// Performs key operations and decrypts encrypted buffer.
+// All public methods other than Decrypt() will be called on the renderer
+// thread. Therefore, these calls should be fast and nonblocking, with key
+// events fired asynchronously. Decrypt() will be called on the (video/audio)
+// decoder thread synchronously.
+class MEDIA_EXPORT Decryptor {
+ public:
+ enum KeyError {
+ kUnknownError = 1,
+ kClientError,
+ kServiceError,
+ kOutputError,
+ kHardwareChangeError,
+ kDomainError
+ };
+
+ Decryptor() {}
+ virtual ~Decryptor() {}
+
+ // Generates a key request for the |key_system| with |init_data| provided.
+ virtual void GenerateKeyRequest(const std::string& key_system,
+ 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;
+
+ // Decrypts the |input| buffer, which should not be NULL.
+ // Returns a DecoderBuffer with the decrypted data if decryption succeeded.
+ // Returns NULL if decryption failed.
+ virtual scoped_refptr<DecoderBuffer> Decrypt(
+ const scoped_refptr<DecoderBuffer>& input) = 0;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(Decryptor);
+};
+
+} // namespace media
+
+#endif // MEDIA_BASE_DECRYPTOR_H_
diff --git a/media/crypto/decryptor_client.h b/media/base/decryptor_client.h
index c15a2f0..9db50ce 100644
--- a/media/crypto/decryptor_client.h
+++ b/media/base/decryptor_client.h
@@ -2,13 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef MEDIA_CRYPTO_DECRYPTOR_CLIENT_H_
-#define MEDIA_CRYPTO_DECRYPTOR_CLIENT_H_
+#ifndef MEDIA_BASE_DECRYPTOR_CLIENT_H_
+#define MEDIA_BASE_DECRYPTOR_CLIENT_H_
#include <string>
#include "base/memory/scoped_ptr.h"
-#include "media/crypto/aes_decryptor.h"
+#include "media/base/decryptor.h"
namespace media {
@@ -24,7 +24,7 @@ class DecryptorClient {
// system-dependent. For clear key system, the |system_code| is always zero.
virtual void KeyError(const std::string& key_system,
const std::string& session_id,
- AesDecryptor::KeyError error_code,
+ Decryptor::KeyError error_code,
int system_code) = 0;
// Signals that a key message has been generated.
@@ -47,4 +47,4 @@ class DecryptorClient {
} // namespace media
-#endif // MEDIA_CRYPTO_DECRYPTOR_CLIENT_H_
+#endif // MEDIA_BASE_DECRYPTOR_CLIENT_H_
diff --git a/media/base/mock_filters.h b/media/base/mock_filters.h
index cf8fa28..e3d50ff 100644
--- a/media/base/mock_filters.h
+++ b/media/base/mock_filters.h
@@ -18,6 +18,7 @@
#include "media/base/audio_decoder.h"
#include "media/base/audio_decoder_config.h"
#include "media/base/audio_renderer.h"
+#include "media/base/decryptor_client.h"
#include "media/base/demuxer.h"
#include "media/base/filters.h"
#include "media/base/filter_collection.h"
@@ -26,7 +27,6 @@
#include "media/base/video_decoder_config.h"
#include "media/base/video_frame.h"
#include "media/base/video_renderer.h"
-#include "media/crypto/decryptor_client.h"
#include "testing/gmock/include/gmock/gmock.h"
namespace media {
@@ -217,7 +217,7 @@ class MockDecryptorClient : public DecryptorClient {
MOCK_METHOD2(KeyAdded, void(const std::string&, const std::string&));
MOCK_METHOD4(KeyError, void(const std::string&, const std::string&,
- AesDecryptor::KeyError, int));
+ Decryptor::KeyError, int));
// TODO(xhwang): This is a workaround of the issue that move-only parameters
// are not supported in mocked methods. Remove this when the issue is fixed
// (http://code.google.com/p/googletest/issues/detail?id=395) or when we use
diff --git a/media/crypto/aes_decryptor.cc b/media/crypto/aes_decryptor.cc
index 49275fb..129bc33 100644
--- a/media/crypto/aes_decryptor.cc
+++ b/media/crypto/aes_decryptor.cc
@@ -12,7 +12,7 @@
#include "crypto/symmetric_key.h"
#include "media/base/decoder_buffer.h"
#include "media/base/decrypt_config.h"
-#include "media/crypto/decryptor_client.h"
+#include "media/base/decryptor_client.h"
namespace media {
@@ -89,7 +89,7 @@ void AesDecryptor::AddKey(const std::string& key_system,
const int kSupportedKeyLength = 16; // 128-bit key.
if (key_length != kSupportedKeyLength) {
DVLOG(1) << "Invalid key length: " << key_length;
- client_->KeyError(key_system, session_id, kUnknownError, 0);
+ client_->KeyError(key_system, session_id, Decryptor::kUnknownError, 0);
return;
}
@@ -110,7 +110,7 @@ void AesDecryptor::AddKey(const std::string& key_system,
crypto::SymmetricKey::AES, key_string);
if (!symmetric_key) {
DVLOG(1) << "Could not import key.";
- client_->KeyError(key_system, session_id, kUnknownError, 0);
+ client_->KeyError(key_system, session_id, Decryptor::kUnknownError, 0);
return;
}
diff --git a/media/crypto/aes_decryptor.h b/media/crypto/aes_decryptor.h
index 3471c53..7201052 100644
--- a/media/crypto/aes_decryptor.h
+++ b/media/crypto/aes_decryptor.h
@@ -11,6 +11,7 @@
#include "base/hash_tables.h"
#include "base/memory/ref_counted.h"
#include "base/synchronization/lock.h"
+#include "media/base/decryptor.h"
#include "media/base/media_export.h"
namespace crypto {
@@ -19,58 +20,30 @@ class SymmetricKey;
namespace media {
-class DecoderBuffer;
class DecryptorClient;
-// Decrypts AES encrypted buffer into unencrypted buffer.
-// All public methods other than Decrypt() will be called on the renderer
-// thread. Therefore, these calls should be fast and nonblocking, with key
-// events fired asynchronously. Decrypt() will be called on the (video/audio)
-// decoder thread synchronously.
-class MEDIA_EXPORT AesDecryptor {
+// Decryptor implementation that decrypts AES-encrypted buffer.
+class MEDIA_EXPORT AesDecryptor : public Decryptor {
public:
- enum KeyError {
- kUnknownError = 1,
- kClientError,
- kServiceError,
- kOutputError,
- kHardwareChangeError,
- kDomainError
- };
-
// The AesDecryptor does not take ownership of the |client|. The |client|
// must be valid throughout the lifetime of the AesDecryptor.
explicit AesDecryptor(DecryptorClient* client);
- ~AesDecryptor();
-
- // Generates a key request. The result of this call will be reported via the
- // client's KeyMessage() or KeyError() methods.
- void GenerateKeyRequest(const std::string& key_system,
- const uint8* init_data,
- int init_data_length);
-
- // 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.
- // The result of this call will be reported via the client's KeyAdded(),
- // KeyMessage() or KeyError() methods.
- 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);
-
- // Cancels the key request specified by |session_id|.
- void CancelKeyRequest(const std::string& key_system,
- const std::string& session_id);
-
- // Decrypts the |input| buffer, which should not be NULL.
- // Returns a DecoderBuffer with the decrypted data if decryption succeeded.
- // Returns NULL if decryption failed.
- scoped_refptr<DecoderBuffer> Decrypt(
- const scoped_refptr<DecoderBuffer>& input);
+ virtual ~AesDecryptor();
+
+ // Decryptor implementation.
+ virtual void GenerateKeyRequest(const std::string& key_system,
+ 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;
+ virtual scoped_refptr<DecoderBuffer> Decrypt(
+ const scoped_refptr<DecoderBuffer>& input) OVERRIDE;
private:
// KeyMap owns the crypto::SymmetricKey* and must delete them when they are
@@ -83,13 +56,13 @@ class MEDIA_EXPORT AesDecryptor {
KeyMap key_map_; // Protected by the |key_map_lock_|.
base::Lock key_map_lock_; // Protects the |key_map_|.
- DecryptorClient* client_;
-
// Make session ID unique per renderer by making it static.
// TODO(xhwang): Make session ID more strictly defined if needed:
// https://www.w3.org/Bugs/Public/show_bug.cgi?id=16739#c0
static uint32 next_session_id_;
+ DecryptorClient* const client_;
+
DISALLOW_COPY_AND_ASSIGN(AesDecryptor);
};
diff --git a/media/crypto/aes_decryptor_unittest.cc b/media/crypto/aes_decryptor_unittest.cc
index 69cca61..814bd6c 100644
--- a/media/crypto/aes_decryptor_unittest.cc
+++ b/media/crypto/aes_decryptor_unittest.cc
@@ -75,7 +75,7 @@ class AesDecryptorTest : public testing::Test {
void AddKeyAndExpectToFail(const uint8 (&key_id)[KeyIdSize],
const uint8 (&key)[KeySize]) {
EXPECT_CALL(client_, KeyError(kClearKeySystem, session_id_string_,
- AesDecryptor::kUnknownError, 0));
+ Decryptor::kUnknownError, 0));
decryptor_.AddKey(kClearKeySystem, key, KeySize, key_id, KeyIdSize,
session_id_string_);
}
diff --git a/media/filters/ffmpeg_video_decoder.cc b/media/filters/ffmpeg_video_decoder.cc
index c8e512b..1902fd8 100644
--- a/media/filters/ffmpeg_video_decoder.cc
+++ b/media/filters/ffmpeg_video_decoder.cc
@@ -10,6 +10,7 @@
#include "base/message_loop.h"
#include "base/string_number_conversions.h"
#include "media/base/decoder_buffer.h"
+#include "media/base/decryptor.h"
#include "media/base/demuxer_stream.h"
#include "media/base/limits.h"
#include "media/base/media_switches.h"
@@ -177,7 +178,7 @@ const gfx::Size& FFmpegVideoDecoder::natural_size() {
return natural_size_;
}
-void FFmpegVideoDecoder::set_decryptor(AesDecryptor* decryptor) {
+void FFmpegVideoDecoder::set_decryptor(Decryptor* decryptor) {
DCHECK_EQ(state_, kUninitialized);
decryptor_ = decryptor;
}
diff --git a/media/filters/ffmpeg_video_decoder.h b/media/filters/ffmpeg_video_decoder.h
index 3c4d39a..f493792 100644
--- a/media/filters/ffmpeg_video_decoder.h
+++ b/media/filters/ffmpeg_video_decoder.h
@@ -10,7 +10,6 @@
#include "base/callback.h"
#include "base/memory/ref_counted.h"
#include "media/base/video_decoder.h"
-#include "media/crypto/aes_decryptor.h"
class MessageLoop;
@@ -20,6 +19,7 @@ struct AVFrame;
namespace media {
class DecoderBuffer;
+class Decryptor;
class MEDIA_EXPORT FFmpegVideoDecoder : public VideoDecoder {
public:
@@ -36,7 +36,7 @@ class MEDIA_EXPORT FFmpegVideoDecoder : public VideoDecoder {
// Must be called prior to initialization if decrypted buffers will be
// encountered.
- void set_decryptor(AesDecryptor* decryptor);
+ void set_decryptor(Decryptor* decryptor);
protected:
virtual ~FFmpegVideoDecoder();
@@ -102,7 +102,7 @@ class MEDIA_EXPORT FFmpegVideoDecoder : public VideoDecoder {
// Pointer to the demuxer stream that will feed us compressed buffers.
scoped_refptr<DemuxerStream> demuxer_stream_;
- AesDecryptor* decryptor_;
+ Decryptor* decryptor_;
DISALLOW_COPY_AND_ASSIGN(FFmpegVideoDecoder);
};
diff --git a/media/filters/ffmpeg_video_decoder_unittest.cc b/media/filters/ffmpeg_video_decoder_unittest.cc
index a787384..26f7f8b 100644
--- a/media/filters/ffmpeg_video_decoder_unittest.cc
+++ b/media/filters/ffmpeg_video_decoder_unittest.cc
@@ -17,6 +17,7 @@
#include "media/base/test_data_util.h"
#include "media/base/video_decoder.h"
#include "media/base/video_frame.h"
+#include "media/crypto/aes_decryptor.h"
#include "media/ffmpeg/ffmpeg_common.h"
#include "media/filters/ffmpeg_decoder_unittest.h"
#include "media/filters/ffmpeg_glue.h"
@@ -210,7 +211,7 @@ class FFmpegVideoDecoderTest : public testing::Test {
scoped_refptr<VideoFrame>));
MessageLoop message_loop_;
- scoped_ptr<AesDecryptor> decryptor_;
+ scoped_ptr<Decryptor> decryptor_;
scoped_refptr<FFmpegVideoDecoder> decoder_;
scoped_refptr<StrictMock<MockDemuxerStream> > demuxer_;
MockStatisticsCB statistics_cb_;
diff --git a/media/filters/pipeline_integration_test.cc b/media/filters/pipeline_integration_test.cc
index c0a5b67..6817505 100644
--- a/media/filters/pipeline_integration_test.cc
+++ b/media/filters/pipeline_integration_test.cc
@@ -6,10 +6,10 @@
#include "base/bind.h"
#include "media/base/decoder_buffer.h"
+#include "media/base/decryptor_client.h"
#include "media/base/mock_filters.h"
#include "media/base/test_data_util.h"
#include "media/crypto/aes_decryptor.h"
-#include "media/crypto/decryptor_client.h"
#include "media/filters/chunk_demuxer_client.h"
namespace media {
@@ -112,9 +112,9 @@ class MockMediaSource : public ChunkDemuxerClient {
DecryptorClient* decryptor_client_;
};
-class MockDecryptorClientImpl : public DecryptorClient {
+class FakeDecryptorClient : public DecryptorClient {
public:
- MockDecryptorClientImpl() : decryptor_(this) {}
+ FakeDecryptorClient() : decryptor_(this) {}
AesDecryptor* decryptor() {
return &decryptor_;
@@ -196,7 +196,7 @@ class PipelineIntegrationTest
void StartPipelineWithEncryptedMedia(
MockMediaSource* source,
- MockDecryptorClientImpl* encrypted_media) {
+ FakeDecryptorClient* encrypted_media) {
pipeline_->Start(
CreateFilterCollection(source),
base::Bind(&PipelineIntegrationTest::OnEnded, base::Unretained(this)),
@@ -265,7 +265,7 @@ TEST_F(PipelineIntegrationTest, BasicPlaybackHashed) {
TEST_F(PipelineIntegrationTest, EncryptedPlayback) {
MockMediaSource source("bear-320x240-encrypted.webm", 219726, true, true);
- MockDecryptorClientImpl encrypted_media;
+ FakeDecryptorClient encrypted_media;
StartPipelineWithEncryptedMedia(&source, &encrypted_media);
source.EndOfStream();
diff --git a/media/media.gyp b/media/media.gyp
index 498006e..0d60e6b 100644
--- a/media/media.gyp
+++ b/media/media.gyp
@@ -148,6 +148,8 @@
'base/decoder_buffer.h',
'base/decrypt_config.cc',
'base/decrypt_config.h',
+ 'base/decryptor.h',
+ 'base/decryptor_client.h',
'base/demuxer.cc',
'base/demuxer.h',
'base/demuxer_stream.cc',
@@ -196,7 +198,6 @@
'base/video_util.h',
'crypto/aes_decryptor.cc',
'crypto/aes_decryptor.h',
- 'crypto/decryptor_client.h',
'ffmpeg/ffmpeg_common.cc',
'ffmpeg/ffmpeg_common.h',
'ffmpeg/file_protocol.cc',