Shaka Packager SDK
crypto_flags.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/app/crypto_flags.h"
8 
9 #include <stdio.h>
10 
11 DEFINE_string(protection_scheme,
12  "cenc",
13  "Specify a protection scheme, 'cenc' or 'cbc1' or pattern-based "
14  "protection schemes 'cens' or 'cbcs'.");
15 DEFINE_int32(
16  crypt_byte_block,
17  1,
18  "Specify the count of the encrypted blocks in the protection pattern, "
19  "where block is of size 16-bytes. There are three common "
20  "patterns (crypt_byte_block:skip_byte_block): 1:9 (default), 5:5, 10:0. "
21  "Apply to video streams with 'cbcs' and 'cens' protection schemes only; "
22  "ignored otherwise.");
23 DEFINE_int32(
24  skip_byte_block,
25  9,
26  "Specify the count of the unencrypted blocks in the protection pattern. "
27  "Apply to video streams with 'cbcs' and 'cens' protection schemes only; "
28  "ignored otherwise.");
29 DEFINE_bool(vp9_subsample_encryption, true, "Enable VP9 subsample encryption.");
30 DEFINE_string(playready_extra_header_data,
31  "",
32  "Extra XML data to add to PlayReady headers.");
33 
34 bool ValueNotGreaterThanTen(const char* flagname, int32_t value) {
35  if (value > 10) {
36  fprintf(stderr, "ERROR: %s must not be greater than 10.\n", flagname);
37  return false;
38  }
39  if (value < 0) {
40  fprintf(stderr, "ERROR: %s must be non-negative.\n", flagname);
41  return false;
42  }
43  return true;
44 }
45 
46 bool ValueIsXml(const char* flagname, const std::string& value) {
47  if (value.empty())
48  return true;
49 
50  if (value[0] != '<' || value[value.size() - 1] != '>') {
51  fprintf(stderr, "ERROR: %s must be valid XML.\n", flagname);
52  return false;
53  }
54  return true;
55 }
56 
57 DEFINE_validator(crypt_byte_block, &ValueNotGreaterThanTen);
58 DEFINE_validator(skip_byte_block, &ValueNotGreaterThanTen);
59 DEFINE_validator(playready_extra_header_data, &ValueIsXml);