Shaka Packager SDK
Loading...
Searching...
No Matches
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
14namespace shaka {
15namespace media {
16namespace {
17// Use version 0 for backward compatibility.
18const uint8_t kWidevinePsshBoxVersion = 0;
19
20std::vector<uint8_t> StringToBytes(const std::string& string) {
21 return std::vector<uint8_t>(string.begin(), string.end());
22}
23} // namespace
24
25WidevinePsshGenerator::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
31WidevinePsshGenerator::~WidevinePsshGenerator() {}
32
33bool WidevinePsshGenerator::SupportMultipleKeys() {
34 return true;
35}
36
37std::optional<std::vector<uint8_t>>
38WidevinePsshGenerator::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
48std::optional<std::vector<uint8_t>>
49WidevinePsshGenerator::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.