summaryrefslogtreecommitdiffstats
path: root/media/webm/webm_crypto_helpers.cc
diff options
context:
space:
mode:
authorfgalligan@chromium.org <fgalligan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-14 23:52:41 +0000
committerfgalligan@chromium.org <fgalligan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-14 23:52:41 +0000
commit4d98e445c98768bb5eb44f8947bea55c1da8334b (patch)
treeb6cf720b8d7ac51b47ab9196bbcaa7c5349977f9 /media/webm/webm_crypto_helpers.cc
parent76e5e6d404fa7d608a9da91e3903a9a2c9165a77 (diff)
downloadchromium_src-4d98e445c98768bb5eb44f8947bea55c1da8334b.zip
chromium_src-4d98e445c98768bb5eb44f8947bea55c1da8334b.tar.gz
chromium_src-4d98e445c98768bb5eb44f8947bea55c1da8334b.tar.bz2
Support for parsing encrypted WebM streams by src.
- Note: Only looking for comments on direction. A lot of work still needs to be done before committing. - Added support to FFmpegDemuxer to decrypt encrypted WebM streams. - Added support to FFmpegDemuxer to handle the needKey and keyAdded messages. - Added support to WebMediaPlayerImpl to handle the needKey and keyAdded messages. BUG=123426 TEST=All media_unittests pass Review URL: https://chromiumcodereview.appspot.com/10829470 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@188228 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/webm/webm_crypto_helpers.cc')
-rw-r--r--media/webm/webm_crypto_helpers.cc60
1 files changed, 60 insertions, 0 deletions
diff --git a/media/webm/webm_crypto_helpers.cc b/media/webm/webm_crypto_helpers.cc
new file mode 100644
index 0000000..ea63f87
--- /dev/null
+++ b/media/webm/webm_crypto_helpers.cc
@@ -0,0 +1,60 @@
+// Copyright (c) 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/webm/webm_crypto_helpers.h"
+
+#include "base/logging.h"
+#include "base/sys_byteorder.h"
+#include "media/base/decrypt_config.h"
+#include "media/webm/webm_constants.h"
+
+namespace media {
+namespace {
+
+// Generates a 16 byte CTR counter block. The CTR counter block format is a
+// CTR IV appended with a CTR block counter. |iv| is an 8 byte CTR IV.
+// |iv_size| is the size of |iv| in btyes. Returns a string of
+// kDecryptionKeySize bytes.
+std::string GenerateWebMCounterBlock(const uint8* iv, int iv_size) {
+ std::string counter_block(reinterpret_cast<const char*>(iv), iv_size);
+ counter_block.append(DecryptConfig::kDecryptionKeySize - iv_size, 0);
+ return counter_block;
+}
+
+} // namespace anonymous
+
+scoped_ptr<DecryptConfig> WebMCreateDecryptConfig(
+ const uint8* data, int data_size,
+ const uint8* key_id, int key_id_size) {
+ if (data_size < kWebMSignalByteSize) {
+ DVLOG(1) << "Got a block from an encrypted stream with no data.";
+ return scoped_ptr<DecryptConfig>(NULL);
+ }
+
+ uint8 signal_byte = data[0];
+ int frame_offset = sizeof(signal_byte);
+
+ // Setting the DecryptConfig object of the buffer while leaving the
+ // initialization vector empty will tell the decryptor that the frame is
+ // unencrypted.
+ std::string counter_block;
+
+ if (signal_byte & kWebMFlagEncryptedFrame) {
+ if (data_size < kWebMSignalByteSize + kWebMIvSize) {
+ DVLOG(1) << "Got an encrypted block with not enough data " << data_size;
+ return scoped_ptr<DecryptConfig>(NULL);
+ }
+ counter_block = GenerateWebMCounterBlock(data + frame_offset, kWebMIvSize);
+ frame_offset += kWebMIvSize;
+ }
+
+ scoped_ptr<DecryptConfig> config(new DecryptConfig(
+ std::string(reinterpret_cast<const char*>(key_id), key_id_size),
+ counter_block,
+ frame_offset,
+ std::vector<SubsampleEntry>()));
+ return config.Pass();
+}
+
+} // namespace media