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/base/decrypt_config.h"
10 #include "packager/media/formats/webm/webm_constants.h"
12 namespace edash_packager {
20 std::string GenerateWebMCounterBlock(
const uint8_t* iv,
int iv_size) {
21 std::string counter_block(reinterpret_cast<const char*>(iv), iv_size);
28 bool WebMCreateDecryptConfig(
const uint8_t* data,
30 const uint8_t* key_id,
32 scoped_ptr<DecryptConfig>* decrypt_config,
34 if (data_size < kWebMSignalByteSize) {
35 DVLOG(1) <<
"Got a block from an encrypted stream with no data.";
39 uint8_t signal_byte = data[0];
40 int frame_offset =
sizeof(signal_byte);
45 std::string counter_block;
47 if (signal_byte & kWebMFlagEncryptedFrame) {
48 if (data_size < kWebMSignalByteSize + kWebMIvSize) {
49 DVLOG(1) <<
"Got an encrypted block with not enough data " << data_size;
52 counter_block = GenerateWebMCounterBlock(data + frame_offset, kWebMIvSize);
53 frame_offset += kWebMIvSize;
56 decrypt_config->reset(
new DecryptConfig(
57 std::vector<uint8_t>(key_id, key_id + key_id_size),
58 std::vector<uint8_t>(counter_block.begin(), counter_block.end()),
59 frame_offset, std::vector<SubsampleEntry>()));
60 *data_offset = frame_offset;