OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chromecast/media/cdm/playready_drm_delegate_android.h" |
| 6 |
| 7 #include "chromecast/media/base/key_systems_common.h" |
| 8 #include "media/base/bit_reader.h" |
| 9 |
| 10 namespace chromecast { |
| 11 namespace media { |
| 12 |
| 13 namespace { |
| 14 |
| 15 static const uint8 kPlayreadyCustomDataUuid[] = { |
| 16 0x2b, 0xf8, 0x66, 0x80, 0xc6, 0xe5, 0x4e, 0x24, |
| 17 0xbe, 0x23, 0x0f, 0x81, 0x5a, 0x60, 0x6e, 0xb2 }; |
| 18 |
| 19 } |
| 20 |
| 21 // static |
| 22 void PlayreadyDrmDelegateAndroid::Install() { |
| 23 ::media::MediaDrmBridge::RegisterDelegate( |
| 24 kChromecastPlayreadyKeySystem, new PlayreadyDrmDelegateAndroid); |
| 25 } |
| 26 |
| 27 PlayreadyDrmDelegateAndroid::PlayreadyDrmDelegateAndroid() { |
| 28 } |
| 29 |
| 30 PlayreadyDrmDelegateAndroid::~PlayreadyDrmDelegateAndroid() { |
| 31 } |
| 32 |
| 33 bool PlayreadyDrmDelegateAndroid::OnCreateSession( |
| 34 const ::media::EmeInitDataType init_data_type, |
| 35 const uint8* init_data, |
| 36 int init_data_length, |
| 37 std::vector<uint8>& init_data_out, |
| 38 std::vector<std::string>& optional_parameters_out) { |
| 39 if (init_data_type == ::media::EmeInitDataType::CENC) { |
| 40 ::media::BitReader reader(init_data, init_data_length); |
| 41 while (true) { |
| 42 uint32 box_size; |
| 43 uint32 box_type; |
| 44 reader.ReadBits(32, &box_size); |
| 45 reader.ReadBits(32, &box_type); |
| 46 int bytes_read = 8; |
| 47 |
| 48 if (!memcmp(&box_type, "uuid", 4)) { |
| 49 if (box_size < 8 + sizeof(kPlayreadyCustomDataUuid)) { |
| 50 break; |
| 51 } |
| 52 // Box size includes the bytes already consumed |
| 53 reader.SkipBits((box_size - bytes_read) * 8); |
| 54 continue; |
| 55 } |
| 56 |
| 57 // "uuid" was found, look for custom data format as per b/10246367 |
| 58 reader.SkipBits(128); |
| 59 bytes_read += 16; |
| 60 if (!memcmp(&init_data[0] + reader.bits_read() / 8, |
| 61 kPlayreadyCustomDataUuid, 16)) { |
| 62 reader.SkipBits((box_size - bytes_read) * 8); |
| 63 continue; |
| 64 } |
| 65 |
| 66 int custom_data_size = box_size - bytes_read; |
| 67 DCHECK(reader.bits_read() % 8 == 0); |
| 68 int total_bytes_read = reader.bits_read() / 8; |
| 69 |
| 70 optional_parameters_out.clear(); |
| 71 optional_parameters_out.push_back("PRCustomData"); |
| 72 optional_parameters_out.push_back( |
| 73 std::string(&init_data[0] + total_bytes_read, |
| 74 &init_data[0] + total_bytes_read + custom_data_size)); |
| 75 LOG(INFO) << "Including " << custom_data_size |
| 76 << " bytes of custom PlayReady data"; |
| 77 } |
| 78 } |
| 79 return true; |
| 80 } |
| 81 |
| 82 } // namespace media |
| 83 } // namespace chromecast |
OLD | NEW |