Shaka Packager SDK
decrypt_config.h
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef PACKAGER_MEDIA_BASE_DECRYPT_CONFIG_H_
6 #define PACKAGER_MEDIA_BASE_DECRYPT_CONFIG_H_
7 
8 #include <stdint.h>
9 
10 #include <string>
11 #include <vector>
12 
13 #include "packager/base/macros.h"
14 #include "packager/media/base/fourccs.h"
15 
16 namespace shaka {
17 namespace media {
18 
30  : clear_bytes(0), cipher_bytes(0) {}
31  SubsampleEntry(uint16_t clear_bytes, uint32_t cipher_bytes)
32  : clear_bytes(clear_bytes), cipher_bytes(cipher_bytes) {}
33 
34  uint16_t clear_bytes;
35  uint32_t cipher_bytes;
36 };
37 
41  public:
43  static const size_t kDecryptionKeySize = 16;
44 
51  DecryptConfig(const std::vector<uint8_t>& key_id,
52  const std::vector<uint8_t>& iv,
53  const std::vector<SubsampleEntry>& subsamples);
54 
67  DecryptConfig(const std::vector<uint8_t>& key_id,
68  const std::vector<uint8_t>& iv,
69  const std::vector<SubsampleEntry>& subsamples,
70  FourCC protection_scheme,
71  uint8_t crypt_byte_block,
72  uint8_t skip_byte_block);
73 
74  ~DecryptConfig();
75 
80  void AddSubsample(uint16_t clear_bytes, uint32_t cipher_bytes) {
81  subsamples_.emplace_back(clear_bytes, cipher_bytes);
82  }
83 
85  size_t GetTotalSizeOfSubsamples() const;
86 
87  const std::vector<uint8_t>& key_id() const { return key_id_; }
88  const std::vector<uint8_t>& iv() const { return iv_; }
89  const std::vector<SubsampleEntry>& subsamples() const { return subsamples_; }
90  FourCC protection_scheme() const { return protection_scheme_; }
91  uint8_t crypt_byte_block() const { return crypt_byte_block_; }
92  uint8_t skip_byte_block() const { return skip_byte_block_; }
93 
94  private:
95  const std::vector<uint8_t> key_id_;
96 
97  // Initialization vector.
98  const std::vector<uint8_t> iv_;
99 
100  // Subsample information. May be empty for some formats, meaning entire frame
101  // (less data ignored by data_offset_) is encrypted.
102  std::vector<SubsampleEntry> subsamples_;
103 
104  const FourCC protection_scheme_;
105  // For pattern-based protection schemes, like CENS and CBCS.
106  const uint8_t crypt_byte_block_;
107  const uint8_t skip_byte_block_;
108 
109  DISALLOW_COPY_AND_ASSIGN(DecryptConfig);
110 };
111 
112 } // namespace media
113 } // namespace shaka
114 
115 #endif // PACKAGER_MEDIA_BASE_DECRYPT_CONFIG_H_
DecryptConfig(const std::vector< uint8_t > &key_id, const std::vector< uint8_t > &iv, const std::vector< SubsampleEntry > &subsamples)
void AddSubsample(uint16_t clear_bytes, uint32_t cipher_bytes)
size_t GetTotalSizeOfSubsamples() const
static const size_t kDecryptionKeySize
Keys are always 128 bits.
All the methods that are virtual are virtual for mocking.