Shaka Packager SDK
Loading...
Searching...
No Matches
crypto_flags.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/app/crypto_flags.h>
8
9#include <cstdio>
10
11#include <absl/flags/flag.h>
12
13ABSL_FLAG(std::string,
14 protection_scheme,
15 "cenc",
16 "Specify a protection scheme, 'cenc' or 'cbc1' or pattern-based "
17 "protection schemes 'cens' or 'cbcs'.");
18ABSL_FLAG(
19 int32_t,
20 crypt_byte_block,
21 1,
22 "Specify the count of the encrypted blocks in the protection pattern, "
23 "where block is of size 16-bytes. There are three common "
24 "patterns (crypt_byte_block:skip_byte_block): 1:9 (default), 5:5, 10:0. "
25 "Apply to video streams with 'cbcs' and 'cens' protection schemes only; "
26 "ignored otherwise.");
27ABSL_FLAG(
28 int32_t,
29 skip_byte_block,
30 9,
31 "Specify the count of the unencrypted blocks in the protection pattern. "
32 "Apply to video streams with 'cbcs' and 'cens' protection schemes only; "
33 "ignored otherwise.");
34ABSL_FLAG(bool,
35 vp9_subsample_encryption,
36 true,
37 "Enable VP9 subsample encryption.");
38ABSL_FLAG(std::string,
39 playready_extra_header_data,
40 "",
41 "Extra XML data to add to PlayReady headers.");
42
43bool ValueNotGreaterThanTen(const char* flagname, int32_t value) {
44 if (value > 10) {
45 fprintf(stderr, "ERROR: %s must not be greater than 10.\n", flagname);
46 return false;
47 }
48 if (value < 0) {
49 fprintf(stderr, "ERROR: %s must be non-negative.\n", flagname);
50 return false;
51 }
52 return true;
53}
54
55bool ValueIsXml(const char* flagname, const std::string& value) {
56 if (value.empty())
57 return true;
58
59 if (value[0] != '<' || value[value.size() - 1] != '>') {
60 fprintf(stderr, "ERROR: %s must be valid XML.\n", flagname);
61 return false;
62 }
63 return true;
64}
65
66namespace shaka {
67bool ValidateCryptoFlags() {
68 bool success = true;
69
70 auto crypt_byte_block = absl::GetFlag(FLAGS_crypt_byte_block);
71 if (!ValueNotGreaterThanTen("crypt_byte_block", crypt_byte_block)) {
72 success = false;
73 }
74
75 auto skip_byte_block = absl::GetFlag(FLAGS_skip_byte_block);
76 if (!ValueNotGreaterThanTen("skip_byte_block", skip_byte_block)) {
77 success = false;
78 }
79
80 auto playready_extra_header_data =
81 absl::GetFlag(FLAGS_playready_extra_header_data);
82 if (!ValueIsXml("playready_extra_header_data", playready_extra_header_data)) {
83 success = false;
84 }
85
86 return success;
87}
88} // namespace shaka
All the methods that are virtual are virtual for mocking.