encryption_pattern.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright 2018 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. #ifndef MEDIA_BASE_ENCRYPTION_PATTERN_H_
  5. #define MEDIA_BASE_ENCRYPTION_PATTERN_H_
  6. #include <stdint.h>
  7. #include "media/base/media_export.h"
  8. namespace media {
  9. // CENC 3rd Edition adds pattern encryption, through two new protection
  10. // schemes: 'cens' (with AES-CTR) and 'cbcs' (with AES-CBC).
  11. // The pattern applies independently to each 'encrypted' part of the frame (as
  12. // defined by the relevant subsample entries), and reduces further the
  13. // actual encryption applied through a repeating pattern of (encrypt:skip)
  14. // 16 byte blocks. For example, in a (1:9) pattern, the first block is
  15. // encrypted, and the next nine are skipped. This pattern is applied
  16. // repeatedly until the end of the last 16-byte block in the subsample.
  17. // Any remaining bytes are left clear.
  18. // TODO(jrummell): Use absl::optional<EncryptionPattern> everywhere.
  19. class MEDIA_EXPORT EncryptionPattern {
  20. public:
  21. EncryptionPattern();
  22. EncryptionPattern(uint32_t crypt_byte_block, uint32_t skip_byte_block);
  23. EncryptionPattern(const EncryptionPattern& rhs);
  24. EncryptionPattern& operator=(const EncryptionPattern& rhs);
  25. ~EncryptionPattern();
  26. uint32_t crypt_byte_block() const { return crypt_byte_block_; }
  27. uint32_t skip_byte_block() const { return skip_byte_block_; }
  28. bool operator==(const EncryptionPattern& other) const;
  29. bool operator!=(const EncryptionPattern& other) const;
  30. private:
  31. // ISO/IEC 23001-7(2016), section 10.3, discussing 'cens' pattern encryption
  32. // scheme, states "Tracks other than video are protected using whole-block
  33. // full-sample encryption as specified in 9.7 and hence skip_byte_block
  34. // SHALL be 0." So patterns where |skip_byte_block| = 0 should be treated
  35. // as whole-block full-sample encryption.
  36. uint32_t crypt_byte_block_ = 0; // Count of the encrypted blocks.
  37. uint32_t skip_byte_block_ = 0; // Count of the unencrypted blocks.
  38. };
  39. } // namespace media
  40. #endif // MEDIA_BASE_ENCRYPTION_PATTERN_H_