Shaka Packager SDK
widevine_pssh_generator.cc
1 // Copyright 2017 Google LLC. 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/widevine_pssh_generator.h>
8 
9 #include <packager/macros/compiler.h>
10 #include <packager/macros/logging.h>
11 #include <packager/media/base/protection_system_ids.h>
12 #include <packager/media/base/widevine_pssh_data.pb.h>
13 
14 namespace shaka {
15 namespace media {
16 namespace {
17 // Use version 0 for backward compatibility.
18 const uint8_t kWidevinePsshBoxVersion = 0;
19 
20 std::vector<uint8_t> StringToBytes(const std::string& string) {
21  return std::vector<uint8_t>(string.begin(), string.end());
22 }
23 } // namespace
24 
25 WidevinePsshGenerator::WidevinePsshGenerator(FourCC protection_scheme)
26  : PsshGenerator(std::vector<uint8_t>(std::begin(kWidevineSystemId),
27  std::end(kWidevineSystemId)),
28  kWidevinePsshBoxVersion),
29  protection_scheme_(protection_scheme) {}
30 
31 WidevinePsshGenerator::~WidevinePsshGenerator() {}
32 
33 bool WidevinePsshGenerator::SupportMultipleKeys() {
34  return true;
35 }
36 
37 std::optional<std::vector<uint8_t>>
38 WidevinePsshGenerator::GeneratePsshDataFromKeyIds(
39  const std::vector<std::vector<uint8_t>>& key_ids) const {
40  media::WidevinePsshData widevine_pssh_data;
41  for (const std::vector<uint8_t>& key_id : key_ids)
42  widevine_pssh_data.add_key_id(key_id.data(), key_id.size());
43  if (protection_scheme_ != FOURCC_NULL)
44  widevine_pssh_data.set_protection_scheme(protection_scheme_);
45  return StringToBytes(widevine_pssh_data.SerializeAsString());
46 }
47 
48 std::optional<std::vector<uint8_t>>
49 WidevinePsshGenerator::GeneratePsshDataFromKeyIdAndKey(
50  const std::vector<uint8_t>& key_id,
51  const std::vector<uint8_t>& key) const {
52  UNUSED(key_id);
53  UNUSED(key);
54  NOTIMPLEMENTED();
55  return std::nullopt;
56 }
57 
58 } // namespace media
59 } // namespace shaka
All the methods that are virtual are virtual for mocking.
Definition: crypto_flags.cc:66