| Index: chromecast/media/cdm/playready_drm_delegate_android.cc
|
| diff --git a/chromecast/media/cdm/playready_drm_delegate_android.cc b/chromecast/media/cdm/playready_drm_delegate_android.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..00c64ce6684a0dc547a776b5812896bcb7c689bd
|
| --- /dev/null
|
| +++ b/chromecast/media/cdm/playready_drm_delegate_android.cc
|
| @@ -0,0 +1,83 @@
|
| +// Copyright 2015 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 "chromecast/media/cdm/playready_drm_delegate_android.h"
|
| +
|
| +#include "chromecast/media/base/key_systems_common.h"
|
| +#include "media/base/bit_reader.h"
|
| +
|
| +namespace chromecast {
|
| +namespace media {
|
| +
|
| +namespace {
|
| +
|
| +static const uint8 kPlayreadyCustomDataUuid[] = {
|
| + 0x2b, 0xf8, 0x66, 0x80, 0xc6, 0xe5, 0x4e, 0x24,
|
| + 0xbe, 0x23, 0x0f, 0x81, 0x5a, 0x60, 0x6e, 0xb2 };
|
| +
|
| +}
|
| +
|
| +// static
|
| +void PlayreadyDrmDelegateAndroid::Install() {
|
| + ::media::MediaDrmBridge::RegisterDelegate(
|
| + kChromecastPlayreadyKeySystem, new PlayreadyDrmDelegateAndroid);
|
| +}
|
| +
|
| +PlayreadyDrmDelegateAndroid::PlayreadyDrmDelegateAndroid() {
|
| +}
|
| +
|
| +PlayreadyDrmDelegateAndroid::~PlayreadyDrmDelegateAndroid() {
|
| +}
|
| +
|
| +bool PlayreadyDrmDelegateAndroid::OnCreateSession(
|
| + const ::media::EmeInitDataType init_data_type,
|
| + const uint8* init_data,
|
| + int init_data_length,
|
| + std::vector<uint8>& init_data_out,
|
| + std::vector<std::string>& optional_parameters_out) {
|
| + if (init_data_type == ::media::EmeInitDataType::CENC) {
|
| + ::media::BitReader reader(init_data, init_data_length);
|
| + while (true) {
|
| + uint32 box_size;
|
| + uint32 box_type;
|
| + reader.ReadBits(32, &box_size);
|
| + reader.ReadBits(32, &box_type);
|
| + int bytes_read = 8;
|
| +
|
| + if (!memcmp(&box_type, "uuid", 4)) {
|
| + if (box_size < 8 + sizeof(kPlayreadyCustomDataUuid)) {
|
| + break;
|
| + }
|
| + // Box size includes the bytes already consumed
|
| + reader.SkipBits((box_size - bytes_read) * 8);
|
| + continue;
|
| + }
|
| +
|
| + // "uuid" was found, look for custom data format as per b/10246367
|
| + reader.SkipBits(128);
|
| + bytes_read += 16;
|
| + if (!memcmp(&init_data[0] + reader.bits_read() / 8,
|
| + kPlayreadyCustomDataUuid, 16)) {
|
| + reader.SkipBits((box_size - bytes_read) * 8);
|
| + continue;
|
| + }
|
| +
|
| + int custom_data_size = box_size - bytes_read;
|
| + DCHECK(reader.bits_read() % 8 == 0);
|
| + int total_bytes_read = reader.bits_read() / 8;
|
| +
|
| + optional_parameters_out.clear();
|
| + optional_parameters_out.push_back("PRCustomData");
|
| + optional_parameters_out.push_back(
|
| + std::string(&init_data[0] + total_bytes_read,
|
| + &init_data[0] + total_bytes_read + custom_data_size));
|
| + LOG(INFO) << "Including " << custom_data_size
|
| + << " bytes of custom PlayReady data";
|
| + }
|
| + }
|
| + return true;
|
| +}
|
| +
|
| +} // namespace media
|
| +} // namespace chromecast
|
|
|