Upstreaming browser/ui/uikit_ui_util from iOS.
[chromium-blink-merge.git] / chromecast / media / cdm / chromecast_init_data.cc
blob7f4d03fed00ad884670c8ce44d71d0c222f1d59b
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.
5 #include "chromecast/media/cdm/chromecast_init_data.h"
7 #include "base/logging.h"
8 #include "base/stl_util.h"
9 #include "media/base/bit_reader.h"
10 #include "media/cdm/cenc_utils.h"
12 namespace chromecast {
13 namespace media {
15 #define RCHECK(x) \
16 do { \
17 if (!(x)) \
18 return false; \
19 } while (0)
21 namespace {
23 const uint8_t kChromecastPlayreadyUuid[] = {
24 0x2b, 0xf8, 0x66, 0x80, 0xc6, 0xe5, 0x4e, 0x24,
25 0xbe, 0x23, 0x0f, 0x81, 0x5a, 0x60, 0x6e, 0xb2};
27 } // namespace
29 ChromecastInitData::ChromecastInitData() {
32 ChromecastInitData::~ChromecastInitData() {
35 bool FindChromecastInitData(const std::vector<uint8_t>& init_data,
36 InitDataMessageType type,
37 ChromecastInitData* chromecast_init_data_out) {
38 // Chromecast initData assumes a CENC data format and searches for PSSH boxes
39 // with SystemID |kChromecastPlayreadyUuid|. The PSSH box content is as
40 // follows:
41 // * |type| (2 bytes, InitDataMessageType)
42 // * |data| (all remaining bytes)
43 // Data may or may not be present and is specific to the given |type|.
45 std::vector<uint8_t> pssh_data;
46 if (!::media::GetPsshData(
47 init_data, std::vector<uint8_t>(kChromecastPlayreadyUuid,
48 kChromecastPlayreadyUuid +
49 sizeof(kChromecastPlayreadyUuid)),
50 &pssh_data)) {
51 return false;
54 ::media::BitReader reader(vector_as_array(&pssh_data), pssh_data.size());
56 uint16_t msg_type;
57 RCHECK(reader.ReadBits(2 * 8, &msg_type));
58 RCHECK(msg_type < static_cast<uint16_t>(InitDataMessageType::END));
59 RCHECK(msg_type == static_cast<uint16_t>(type));
61 chromecast_init_data_out->type = static_cast<InitDataMessageType>(msg_type);
62 chromecast_init_data_out->data.assign(
63 pssh_data.begin() + reader.bits_read() / 8, pssh_data.end());
64 return true;
67 } // namespace media
68 } // namespace chromecast