5 #include "packager/media/formats/webm/webm_crypto_helpers.h"
7 #include "packager/base/logging.h"
8 #include "packager/base/sys_byteorder.h"
9 #include "packager/media/formats/webm/webm_constants.h"
11 namespace edash_packager {
19 std::string GenerateWebMCounterBlock(
const uint8_t* iv,
int iv_size) {
20 std::string counter_block(reinterpret_cast<const char*>(iv), iv_size);
27 bool WebMCreateDecryptConfig(
const uint8_t* data,
29 const uint8_t* key_id,
31 scoped_ptr<DecryptConfig>* decrypt_config,
33 if (data_size < kWebMSignalByteSize) {
34 DVLOG(1) <<
"Got a block from an encrypted stream with no data.";
38 uint8_t signal_byte = data[0];
39 int frame_offset =
sizeof(signal_byte);
44 std::string counter_block;
46 if (signal_byte & kWebMFlagEncryptedFrame) {
47 if (data_size < kWebMSignalByteSize + kWebMIvSize) {
48 DVLOG(1) <<
"Got an encrypted block with not enough data " << data_size;
51 counter_block = GenerateWebMCounterBlock(data + frame_offset, kWebMIvSize);
52 frame_offset += kWebMIvSize;
55 decrypt_config->reset(
new DecryptConfig(
56 std::vector<uint8_t>(key_id, key_id + key_id_size),
57 std::vector<uint8_t>(counter_block.begin(), counter_block.end()),
58 std::vector<SubsampleEntry>()));
59 *data_offset = frame_offset;