summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorxhwang@chromium.org <xhwang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-05 23:41:38 +0000
committerxhwang@chromium.org <xhwang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-05 23:41:38 +0000
commitc80fed54d4925a9bb77741f45ed95f0e83fb073f (patch)
tree64add865ae00bef6d077dd3d60a8425e83c24e15 /media
parentc02f93e47ba08e8dd00c6904e0cc788db647b07e (diff)
downloadchromium_src-c80fed54d4925a9bb77741f45ed95f0e83fb073f.zip
chromium_src-c80fed54d4925a9bb77741f45ed95f0e83fb073f.tar.gz
chromium_src-c80fed54d4925a9bb77741f45ed95f0e83fb073f.tar.bz2
Move AesDecryptor out of FFmpegVideoDecoder.
BUG=130693 TEST=media_unittests Review URL: https://chromiumcodereview.appspot.com/10500003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@140654 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r--media/filters/ffmpeg_video_decoder.cc11
-rw-r--r--media/filters/ffmpeg_video_decoder.h6
-rw-r--r--media/filters/ffmpeg_video_decoder_unittest.cc14
-rw-r--r--media/filters/pipeline_integration_test.cc2
-rw-r--r--media/filters/pipeline_integration_test_base.cc3
-rw-r--r--media/filters/pipeline_integration_test_base.h3
6 files changed, 27 insertions, 12 deletions
diff --git a/media/filters/ffmpeg_video_decoder.cc b/media/filters/ffmpeg_video_decoder.cc
index 930a290..81ddd8b 100644
--- a/media/filters/ffmpeg_video_decoder.cc
+++ b/media/filters/ffmpeg_video_decoder.cc
@@ -57,7 +57,8 @@ FFmpegVideoDecoder::FFmpegVideoDecoder(
codec_context_(NULL),
av_frame_(NULL),
frame_rate_numerator_(0),
- frame_rate_denominator_(0) {
+ frame_rate_denominator_(0),
+ decryptor_(NULL) {
}
void FFmpegVideoDecoder::Initialize(const scoped_refptr<DemuxerStream>& stream,
@@ -172,8 +173,9 @@ const gfx::Size& FFmpegVideoDecoder::natural_size() {
return natural_size_;
}
-AesDecryptor* FFmpegVideoDecoder::decryptor() {
- return &decryptor_;
+void FFmpegVideoDecoder::set_decryptor(AesDecryptor* decryptor) {
+ DCHECK_EQ(state_, kUninitialized);
+ decryptor_ = decryptor;
}
FFmpegVideoDecoder::~FFmpegVideoDecoder() {
@@ -267,7 +269,8 @@ void FFmpegVideoDecoder::DoDecodeBuffer(
scoped_refptr<DecoderBuffer> unencrypted_buffer = buffer;
if (buffer->GetDecryptConfig() && buffer->GetDataSize()) {
- unencrypted_buffer = decryptor_.Decrypt(buffer);
+ unencrypted_buffer = decryptor_->Decrypt(buffer);
+
if (!unencrypted_buffer || !unencrypted_buffer->GetDataSize()) {
state_ = kDecodeFinished;
base::ResetAndReturn(&read_cb_).Run(kDecryptError, NULL);
diff --git a/media/filters/ffmpeg_video_decoder.h b/media/filters/ffmpeg_video_decoder.h
index 4d99a43..e52ce2e 100644
--- a/media/filters/ffmpeg_video_decoder.h
+++ b/media/filters/ffmpeg_video_decoder.h
@@ -33,7 +33,9 @@ class MEDIA_EXPORT FFmpegVideoDecoder : public VideoDecoder {
virtual void Stop(const base::Closure& closure) OVERRIDE;
virtual const gfx::Size& natural_size() OVERRIDE;
- AesDecryptor* decryptor();
+ // Must be called prior to initialization if decrypted buffers will be
+ // encountered.
+ void set_decryptor(AesDecryptor* decryptor);
protected:
virtual ~FFmpegVideoDecoder();
@@ -99,7 +101,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_;
+ AesDecryptor* 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 b0fc360..6367ab2 100644
--- a/media/filters/ffmpeg_video_decoder_unittest.cc
+++ b/media/filters/ffmpeg_video_decoder_unittest.cc
@@ -48,13 +48,16 @@ ACTION_P(ReturnBuffer, buffer) {
class FFmpegVideoDecoderTest : public testing::Test {
public:
FFmpegVideoDecoderTest()
- : decoder_(new FFmpegVideoDecoder(base::Bind(&Identity<MessageLoop*>,
+ : decryptor_(new AesDecryptor()),
+ decoder_(new FFmpegVideoDecoder(base::Bind(&Identity<MessageLoop*>,
&message_loop_))),
demuxer_(new StrictMock<MockDemuxerStream>()),
read_cb_(base::Bind(&FFmpegVideoDecoderTest::FrameReady,
base::Unretained(this))) {
CHECK(FFmpegGlue::GetInstance());
+ decoder_->set_decryptor(decryptor_.get());
+
// Initialize various test buffers.
frame_buffer_.reset(new uint8[kCodedSize.GetArea()]);
end_of_stream_buffer_ = DecoderBuffer::CreateEOSBuffer();
@@ -194,6 +197,7 @@ class FFmpegVideoDecoderTest : public testing::Test {
scoped_refptr<VideoFrame>));
MessageLoop message_loop_;
+ scoped_ptr<AesDecryptor> decryptor_;
scoped_refptr<FFmpegVideoDecoder> decoder_;
scoped_refptr<StrictMock<MockDemuxerStream> > demuxer_;
MockStatisticsCB statistics_cb_;
@@ -371,8 +375,8 @@ TEST_F(FFmpegVideoDecoderTest, DecodeFrame_SmallerHeight) {
TEST_F(FFmpegVideoDecoderTest, DecodeEncryptedFrame_Normal) {
Initialize();
- decoder_->decryptor()->AddKey(kKeyId, arraysize(kKeyId) - 1,
- kRawKey, arraysize(kRawKey) - 1);
+ decryptor_->AddKey(kKeyId, arraysize(kKeyId) - 1,
+ kRawKey, arraysize(kRawKey) - 1);
// Simulate decoding a single encrypted frame.
encrypted_i_frame_buffer_->SetDecryptConfig(scoped_ptr<DecryptConfig>(
@@ -411,8 +415,8 @@ TEST_F(FFmpegVideoDecoderTest, DecodeEncryptedFrame_NoKey) {
// Test decrypting an encrypted frame with a wrong key.
TEST_F(FFmpegVideoDecoderTest, DecodeEncryptedFrame_WrongKey) {
Initialize();
- decoder_->decryptor()->AddKey(kKeyId, arraysize(kKeyId) - 1,
- kWrongKey, arraysize(kWrongKey) - 1);
+ decryptor_->AddKey(kKeyId, arraysize(kKeyId) - 1,
+ kWrongKey, arraysize(kWrongKey) - 1);
encrypted_i_frame_buffer_->SetDecryptConfig(scoped_ptr<DecryptConfig>(
new DecryptConfig(kKeyId, arraysize(kKeyId) - 1)));
diff --git a/media/filters/pipeline_integration_test.cc b/media/filters/pipeline_integration_test.cc
index cfb3583..5a91850 100644
--- a/media/filters/pipeline_integration_test.cc
+++ b/media/filters/pipeline_integration_test.cc
@@ -117,7 +117,7 @@ class PipelineIntegrationTest
NetworkEventCB(), QuitOnStatusCB(PIPELINE_OK));
ASSERT_TRUE(decoder_.get());
- source.set_decryptor(decoder_->decryptor());
+ source.set_decryptor(decryptor_.get());
message_loop_.Run();
}
diff --git a/media/filters/pipeline_integration_test_base.cc b/media/filters/pipeline_integration_test_base.cc
index b6f8b47..e995565 100644
--- a/media/filters/pipeline_integration_test_base.cc
+++ b/media/filters/pipeline_integration_test_base.cc
@@ -6,6 +6,7 @@
#include "base/bind.h"
#include "media/base/media_log.h"
+#include "media/crypto/aes_decryptor.h"
#include "media/filters/audio_renderer_impl.h"
#include "media/filters/chunk_demuxer.h"
#include "media/filters/ffmpeg_audio_decoder.h"
@@ -168,6 +169,7 @@ PipelineIntegrationTestBase::CreateFilterCollection(
const scoped_refptr<Demuxer>& demuxer) {
scoped_ptr<FilterCollection> collection(new FilterCollection());
collection->SetDemuxer(demuxer);
+ decryptor_.reset(new AesDecryptor());
collection->AddAudioDecoder(new FFmpegAudioDecoder(
base::Bind(&MessageLoopFactory::GetMessageLoop,
base::Unretained(message_loop_factory_.get()),
@@ -176,6 +178,7 @@ PipelineIntegrationTestBase::CreateFilterCollection(
base::Bind(&MessageLoopFactory::GetMessageLoop,
base::Unretained(message_loop_factory_.get()),
"VideoDecoderThread"));
+ decoder_->set_decryptor(decryptor_.get());
collection->AddVideoDecoder(decoder_);
// Disable frame dropping if hashing is enabled.
renderer_ = new VideoRendererBase(
diff --git a/media/filters/pipeline_integration_test_base.h b/media/filters/pipeline_integration_test_base.h
index 21d61bb..a617211 100644
--- a/media/filters/pipeline_integration_test_base.h
+++ b/media/filters/pipeline_integration_test_base.h
@@ -18,6 +18,8 @@
namespace media {
+class AesDecryptor;
+
// Empty MD5 hash string. Used to verify empty audio or video tracks.
extern const char kNullHash[];
@@ -68,6 +70,7 @@ class PipelineIntegrationTestBase {
bool hashing_enabled_;
scoped_ptr<MessageLoopFactory> message_loop_factory_;
scoped_refptr<Pipeline> pipeline_;
+ scoped_ptr<AesDecryptor> decryptor_;
scoped_refptr<FFmpegVideoDecoder> decoder_;
scoped_refptr<VideoRendererBase> renderer_;
scoped_refptr<NullAudioSink> audio_sink_;