diff options
author | dalecurtis@google.com <dalecurtis@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-31 20:35:25 +0000 |
---|---|---|
committer | dalecurtis@google.com <dalecurtis@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-31 20:35:25 +0000 |
commit | f42d6a10c8645a83220341ef9cfd22b36b3b49b5 (patch) | |
tree | db76016f0b892d43961d1ead916de9f79534fa62 /media/crypto | |
parent | 665e4fbc3d7de70829f6db36a955f63f9c4d7f9f (diff) | |
download | chromium_src-f42d6a10c8645a83220341ef9cfd22b36b3b49b5.zip chromium_src-f42d6a10c8645a83220341ef9cfd22b36b3b49b5.tar.gz chromium_src-f42d6a10c8645a83220341ef9cfd22b36b3b49b5.tar.bz2 |
Introducing DecoderBuffer and general Buffer cleanup.
FFmpeg expects data to be padded and aligned in a certain way. It's
currently possible to do this incorrectly and introduce dangerous issues.
I enforce padding and alignment by introducing a new Buffer called
DecoderBuffer and forcing DemuxerStream::Read to only accept it for
transfer into decoders.
DecoderBuffer allocates all memory through av_malloc (which takes care of
alignment) with the appropriate padding size (except for Android, which
doesn't care about this).
Along the way it was necessary to clean up a large smattering of code to
replace usage of DataBuffer with DecoderBuffer.
I've rolled in several cleanup actions as well:
- Moved DecryptConfig from Buffer to DecoderBuffer.
- Replaced AVPacketBuffer and av_dup_packet with a DecoderBuffer::CopyFrom.
- Fixed a resultant issue with FFmpegBitStreamConverter after removing the
av_dup_packet functionality. Removed some unsupported bitstream filters.
- Reduce TestDataUtil::ReadTestDataFile() to a single method returning a
DecoderBuffer so unit tests will always have safe buffers.
- Replace new DataBuffer(0)/new DecoderBuffer(0) w/
DecoderBuffer::CreateEOSBuffer.
- Remove extraneous IsEndOfStream check from FFmpegAudioDecoder.
BUG=129843
TEST=media_unittests + valgrind, layout tests.
Review URL: https://chromiumcodereview.appspot.com/10447035
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@139857 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/crypto')
-rw-r--r-- | media/crypto/aes_decryptor.cc | 22 | ||||
-rw-r--r-- | media/crypto/aes_decryptor.h | 7 | ||||
-rw-r--r-- | media/crypto/aes_decryptor_unittest.cc | 13 |
3 files changed, 22 insertions, 20 deletions
diff --git a/media/crypto/aes_decryptor.cc b/media/crypto/aes_decryptor.cc index 8d56d76..cbb75b3 100644 --- a/media/crypto/aes_decryptor.cc +++ b/media/crypto/aes_decryptor.cc @@ -9,8 +9,7 @@ #include "base/string_piece.h" #include "crypto/encryptor.h" #include "crypto/symmetric_key.h" -#include "media/base/buffers.h" -#include "media/base/data_buffer.h" +#include "media/base/decoder_buffer.h" #include "media/base/decrypt_config.h" namespace media { @@ -19,10 +18,10 @@ namespace media { static const char kInitialCounter[] = "0000000000000000"; // Decrypt |input| using |key|. -// Return a scoped_refptr to a Buffer object with the decrypted data on success. -// Return a scoped_refptr to NULL if the data could not be decrypted. -static scoped_refptr<Buffer> DecryptData(const Buffer& input, - crypto::SymmetricKey* key) { +// Return a DecoderBuffer with the decrypted data if decryption succeeded. +// Return NULL if decryption failed. +static scoped_refptr<DecoderBuffer> DecryptData(const DecoderBuffer& input, + crypto::SymmetricKey* key) { CHECK(input.GetDataSize()); CHECK(key); @@ -43,9 +42,8 @@ static scoped_refptr<Buffer> DecryptData(const Buffer& input, return NULL; } - // TODO(xhwang): Implement a string based Buffer implementation to avoid - // data copying. - return DataBuffer::CopyFrom( + // TODO(xhwang): Find a way to avoid this data copy. + return DecoderBuffer::CopyFrom( reinterpret_cast<const uint8*>(decrypted_text.data()), decrypted_text.size()); } @@ -81,8 +79,8 @@ void AesDecryptor::AddKey(const uint8* key_id, int key_id_size, key_map_[key_id_string] = symmetric_key; } -scoped_refptr<Buffer> AesDecryptor::Decrypt( - const scoped_refptr<Buffer>& encrypted) { +scoped_refptr<DecoderBuffer> AesDecryptor::Decrypt( + const scoped_refptr<DecoderBuffer>& encrypted) { CHECK(encrypted->GetDecryptConfig()); const uint8* key_id = encrypted->GetDecryptConfig()->key_id(); const int key_id_size = encrypted->GetDecryptConfig()->key_id_size(); @@ -101,7 +99,7 @@ scoped_refptr<Buffer> AesDecryptor::Decrypt( key = found->second; } - scoped_refptr<Buffer> decrypted = DecryptData(*encrypted, key); + scoped_refptr<DecoderBuffer> decrypted = DecryptData(*encrypted, key); if (decrypted) { decrypted->SetTimestamp(encrypted->GetTimestamp()); diff --git a/media/crypto/aes_decryptor.h b/media/crypto/aes_decryptor.h index 212c9ac..d62528f 100644 --- a/media/crypto/aes_decryptor.h +++ b/media/crypto/aes_decryptor.h @@ -19,7 +19,7 @@ class SymmetricKey; namespace media { -class Buffer; +class DecoderBuffer; // Decrypts AES encrypted buffer into unencrypted buffer. class MEDIA_EXPORT AesDecryptor { @@ -35,9 +35,10 @@ class MEDIA_EXPORT AesDecryptor { const uint8* key, int key_size); // Decrypt |input| buffer. The |input| should not be NULL. - // Return a Buffer that contains decrypted data if decryption succeeded. + // Return a DecoderBuffer with the decrypted data if decryption succeeded. // Return NULL if decryption failed. - scoped_refptr<Buffer> Decrypt(const scoped_refptr<Buffer>& input); + scoped_refptr<DecoderBuffer> Decrypt( + const scoped_refptr<DecoderBuffer>& input); private: // KeyMap owns the crypto::SymmetricKey* and must delete them when they are diff --git a/media/crypto/aes_decryptor_unittest.cc b/media/crypto/aes_decryptor_unittest.cc index 70b6881..0b33f61 100644 --- a/media/crypto/aes_decryptor_unittest.cc +++ b/media/crypto/aes_decryptor_unittest.cc @@ -4,7 +4,7 @@ #include <string> -#include "media/base/data_buffer.h" +#include "media/base/decoder_buffer.h" #include "media/base/decrypt_config.h" #include "media/crypto/aes_decryptor.h" #include "testing/gtest/include/gtest/gtest.h" @@ -28,7 +28,8 @@ static const unsigned char kKeyId2[] = "Key ID 2."; class AesDecryptorTest : public testing::Test { public: AesDecryptorTest() { - encrypted_data_ = DataBuffer::CopyFrom(kEncryptedData, kEncryptedDataSize); + encrypted_data_ = DecoderBuffer::CopyFrom( + kEncryptedData, kEncryptedDataSize); } protected: @@ -38,7 +39,8 @@ class AesDecryptorTest : public testing::Test { } void DecryptAndExpectToSucceed() { - scoped_refptr<Buffer> decrypted = decryptor_.Decrypt(encrypted_data_); + scoped_refptr<DecoderBuffer> decrypted = + decryptor_.Decrypt(encrypted_data_); ASSERT_TRUE(decrypted); int data_length = sizeof(kOriginalData) - 1; ASSERT_EQ(data_length, decrypted->GetDataSize()); @@ -46,11 +48,12 @@ class AesDecryptorTest : public testing::Test { } void DecryptAndExpectToFail() { - scoped_refptr<Buffer> decrypted = decryptor_.Decrypt(encrypted_data_); + scoped_refptr<DecoderBuffer> decrypted = + decryptor_.Decrypt(encrypted_data_); EXPECT_FALSE(decrypted); } - scoped_refptr<DataBuffer> encrypted_data_; + scoped_refptr<DecoderBuffer> encrypted_data_; AesDecryptor decryptor_; }; |