Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef MEDIA_BASE_DECRYPT_CONFIG_H_ | 5 #ifndef MEDIA_BASE_DECRYPT_CONFIG_H_ |
| 6 #define MEDIA_BASE_DECRYPT_CONFIG_H_ | 6 #define MEDIA_BASE_DECRYPT_CONFIG_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "media/base/media_export.h" | 13 #include "media/base/media_export.h" |
| 14 | 14 |
| 15 namespace media { | 15 namespace media { |
| 16 | 16 |
| 17 // The Common Encryption spec provides for subsample encryption, where portions | 17 // The Common Encryption spec provides for subsample encryption, where portions |
| 18 // of a sample are set in cleartext. A SubsampleEntry specifies the number of | 18 // of a sample are set in cleartext. A SubsampleEntry specifies the number of |
| 19 // clear and encrypted bytes in each subsample. For decryption, all of the | 19 // clear and encrypted bytes in each subsample. For decryption, all of the |
| 20 // encrypted bytes in a sample should be considered a single logical stream, | 20 // encrypted bytes in a sample should be considered a single logical stream, |
| 21 // regardless of how they are divided into subsamples, and the clear bytes | 21 // regardless of how they are divided into subsamples, and the clear bytes |
| 22 // should not be considered as part of decryption. This is logically equivalent | 22 // should not be considered as part of decryption. This is logically equivalent |
| 23 // to concatenating all 'cypher_bytes' portions of subsamples, decrypting that | 23 // to concatenating all 'cypher_bytes' portions of subsamples, decrypting that |
| 24 // result, and then copying each byte from the decrypted block over the | 24 // result, and then copying each byte from the decrypted block over the |
| 25 // position of the corresponding encrypted byte. | 25 // position of the corresponding encrypted byte. |
| 26 struct SubsampleEntry { | 26 struct SubsampleEntry { |
| 27 SubsampleEntry() : clear_bytes(0), cypher_bytes(0) {} | |
|
ddorwin
2014/11/25 20:47:48
Do we need this? It seems like something that shou
xhwang
2014/11/25 22:13:44
This is needed as the default ctor because we need
| |
| 28 SubsampleEntry(uint32 clear_bytes, uint32 cypher_bytes) | |
| 29 : clear_bytes(clear_bytes), cypher_bytes(cypher_bytes) {} | |
| 27 uint32 clear_bytes; | 30 uint32 clear_bytes; |
| 28 uint32 cypher_bytes; | 31 uint32 cypher_bytes; |
| 29 }; | 32 }; |
| 30 | 33 |
| 31 // Contains all information that a decryptor needs to decrypt a media sample. | 34 // Contains all information that a decryptor needs to decrypt a media sample. |
| 32 class MEDIA_EXPORT DecryptConfig { | 35 class MEDIA_EXPORT DecryptConfig { |
| 33 public: | 36 public: |
| 34 // Keys are always 128 bits. | 37 // Keys are always 128 bits. |
| 35 static const int kDecryptionKeySize = 16; | 38 static const int kDecryptionKeySize = 16; |
| 36 | 39 |
| 37 // |key_id| is the ID that references the decryption key for this sample. | 40 // |key_id| is the ID that references the decryption key for this sample. |
| 38 // |iv| is the initialization vector defined by the encrypted format. | 41 // |iv| is the initialization vector defined by the encrypted format. |
| 39 // Currently |iv| must be 16 bytes as defined by WebM and ISO. Or must be | 42 // Currently |iv| must be 16 bytes as defined by WebM and ISO. Or must be |
| 40 // empty which signals an unencrypted frame. | 43 // empty which signals an unencrypted frame. |
| 41 // |subsamples| defines the clear and encrypted portions of the sample as | 44 // |subsamples| defines the clear and encrypted portions of the sample as |
| 42 // described above. A decrypted buffer will be equal in size to the sum | 45 // described above. A decrypted buffer will be equal in size to the sum |
| 43 // of the subsample sizes. | 46 // of the subsample sizes. |
| 44 DecryptConfig(const std::string& key_id, | 47 DecryptConfig(const std::string& key_id, |
| 45 const std::string& iv, | 48 const std::string& iv, |
| 46 const std::vector<SubsampleEntry>& subsamples); | 49 const std::vector<SubsampleEntry>& subsamples); |
| 47 ~DecryptConfig(); | 50 ~DecryptConfig(); |
| 48 | 51 |
| 49 const std::string& key_id() const { return key_id_; } | 52 const std::string& key_id() const { return key_id_; } |
| 50 const std::string& iv() const { return iv_; } | 53 const std::string& iv() const { return iv_; } |
| 51 const std::vector<SubsampleEntry>& subsamples() const { return subsamples_; } | 54 const std::vector<SubsampleEntry>& subsamples() const { return subsamples_; } |
| 52 | 55 |
| 56 // Returns true if all fields in |config| match this config. | |
| 57 bool Matches(const DecryptConfig& config) const; | |
| 58 | |
| 53 private: | 59 private: |
| 54 const std::string key_id_; | 60 const std::string key_id_; |
| 55 | 61 |
| 56 // Initialization vector. | 62 // Initialization vector. |
| 57 const std::string iv_; | 63 const std::string iv_; |
| 58 | 64 |
| 59 // Subsample information. May be empty for some formats, meaning entire frame | 65 // Subsample information. May be empty for some formats, meaning entire frame |
| 60 // (less data ignored by data_offset_) is encrypted. | 66 // (less data ignored by data_offset_) is encrypted. |
| 61 const std::vector<SubsampleEntry> subsamples_; | 67 const std::vector<SubsampleEntry> subsamples_; |
| 62 | 68 |
| 63 DISALLOW_COPY_AND_ASSIGN(DecryptConfig); | 69 DISALLOW_COPY_AND_ASSIGN(DecryptConfig); |
| 64 }; | 70 }; |
| 65 | 71 |
| 66 } // namespace media | 72 } // namespace media |
| 67 | 73 |
| 68 #endif // MEDIA_BASE_DECRYPT_CONFIG_H_ | 74 #endif // MEDIA_BASE_DECRYPT_CONFIG_H_ |
| OLD | NEW |