Shaka Packager SDK
pssh_generator.cc
1 // Copyright 2017 Google Inc. All rights reserved.
2 //
3 // Use of this source code is governed by a BSD-style
4 // license that can be found in the LICENSE file or at
5 // https://developers.google.com/open-source/licenses/bsd
6 
7 #include "packager/media/base/pssh_generator.h"
8 
9 namespace shaka {
10 namespace media {
11 namespace {
12 
13 std::vector<uint8_t> CreatePsshBox(
14  const std::vector<uint8_t>& system_id,
15  uint8_t version,
16  const std::vector<std::vector<uint8_t>>& key_ids,
17  const std::vector<uint8_t>& pssh_data) {
18  PsshBoxBuilder pssh_builder;
19  pssh_builder.set_pssh_data(pssh_data);
20  for (const std::vector<uint8_t>& key_id : key_ids) {
21  pssh_builder.add_key_id(key_id);
22  }
23  pssh_builder.set_pssh_box_version(version);
24  pssh_builder.set_system_id(system_id.data(), system_id.size());
25 
26  return pssh_builder.CreateBox();
27 }
28 
29 } // namespace
30 
31 PsshGenerator::PsshGenerator() {}
32 
33 PsshGenerator::~PsshGenerator() {}
34 
36  const std::vector<std::vector<uint8_t>>& key_ids,
37  ProtectionSystemSpecificInfo* info) const {
38  base::Optional<std::vector<uint8_t>> pssh_data =
39  GeneratePsshDataFromKeyIds(key_ids);
40  if (!pssh_data) {
41  return Status(error::ENCRYPTION_FAILURE,
42  "Fail to generate PSSH data from multiple Key IDs.");
43  }
44  info->system_id = SystemId();
45  info->psshs =
46  CreatePsshBox(SystemId(), PsshBoxVersion(), key_ids, pssh_data.value());
47  return Status::OK;
48 }
49 
51  const std::vector<uint8_t>& key_id,
52  const std::vector<uint8_t>& key,
53  ProtectionSystemSpecificInfo* info) const {
54  base::Optional<std::vector<uint8_t>> pssh_data =
55  GeneratePsshDataFromKeyIdAndKey(key_id, key);
56  if (!pssh_data) {
57  return Status(error::ENCRYPTION_FAILURE,
58  "Fail to generate PSSH data from Key ID and Key.");
59  }
60  info->system_id = SystemId();
61  info->psshs =
62  CreatePsshBox(SystemId(), PsshBoxVersion(), {key_id}, pssh_data.value());
63  return Status::OK;
64 }
65 
66 } // namespace media
67 } // namespace shaka
Status GeneratePsshFromKeyIds(const std::vector< std::vector< uint8_t >> &key_ids, ProtectionSystemSpecificInfo *info) const
All the methods that are virtual are virtual for mocking.
Status GeneratePsshFromKeyIdAndKey(const std::vector< uint8_t > &key_id, const std::vector< uint8_t > &key, ProtectionSystemSpecificInfo *info) const