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