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> | |
9 #include <vector> | |
10 | |
8 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
9 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
10 #include "media/base/media_export.h" | 13 #include "media/base/media_export.h" |
11 | 14 |
12 namespace media { | 15 namespace media { |
13 | 16 |
14 // Contains all information that a decryptor needs to decrypt a frame. | 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 | |
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, | |
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 | |
23 // to concatenating all 'cypher_bytes' portions of subsamples, decrypting that | |
24 // result, and then copying each byte from the decrypted block over the | |
25 // position of the corresponding encrypted byte. | |
26 struct SubsampleEntry { | |
27 uint32 clear_bytes; | |
28 uint32 cypher_bytes; | |
29 }; | |
30 | |
31 // Contains all information that a decryptor needs to decrypt a media sample. | |
15 class MEDIA_EXPORT DecryptConfig { | 32 class MEDIA_EXPORT DecryptConfig { |
16 public: | 33 public: |
17 // Keys are always 128 bits. | 34 // Keys are always 128 bits. |
18 static const int kDecryptionKeySize = 16; | 35 static const int kDecryptionKeySize = 16; |
19 | 36 |
20 // |key_id| is the ID that references the decryption key for this frame. |iv| | 37 // |key_id| is the ID that references the decryption key for this sample. |
21 // is the initialization vector defined by the encrypted format. Currently | 38 // |iv| is the initialization vector defined by the encrypted format. |
22 // |iv_size| must be 16 bytes as defined by WebM and ISO. |checksum| is the | 39 // Currently |iv_size| must be 16 bytes as defined by WebM and ISO. |
23 // hash value of the encrypted buffer. |checksum| is defined by the | 40 // |checksum| is the hash value of the encrypted buffer. |checksum| is |
24 // encrypted format and may be NULL. |encrypted_frame_offset| is the offset | 41 // defined by the encrypted format and may be NULL. |
25 // into the encrypted buffer that the encrypted frame starts. The class | 42 // |data_offset| is the amount of data that should be discarded from the |
26 // will copy the data from |key_id|, |iv|, and |checksum|. | 43 // head of the sample buffer before applying subsample information. A |
27 DecryptConfig(const uint8* key_id, int key_id_size, | 44 // decrypted buffer will be shorter than an encrypted buffer by this amount. |
28 const uint8* iv, int iv_size, | 45 // |subsamples| defines the clear and encrypted portions of the sample as |
29 const uint8* checksum, int checksum_size, | 46 // described above. A decrypted buffer will be equal in size to the sum |
30 int encrypted_frame_offset); | 47 // of the subsample sizes. |
48 // | |
49 // |data_offset| is applied after |checksum|, but before |subsamples|. | |
50 DecryptConfig(const std::string& key_id, | |
51 const std::string& iv, | |
52 const std::string& checksum, | |
53 const int data_offset, | |
54 const std::vector<SubsampleEntry>& subsamples); | |
31 ~DecryptConfig(); | 55 ~DecryptConfig(); |
32 | 56 |
33 const uint8* key_id() const { return key_id_.get(); } | 57 const std::string& key_id() const { return key_id_; } |
34 int key_id_size() const { return key_id_size_; } | 58 const std::string& iv() const { return iv_; } |
35 const uint8* iv() const { return iv_.get(); } | 59 const std::string& checksum() const { return checksum_; } |
36 int iv_size() const { return iv_size_; } | 60 const int data_offset() const { return data_offset_; } |
37 const uint8* checksum() const { return checksum_.get(); } | 61 const std::vector<SubsampleEntry>& subsamples() const { return subsamples_; } |
38 int checksum_size() const { return checksum_size_; } | |
39 int encrypted_frame_offset() const { return encrypted_frame_offset_; } | |
40 | 62 |
41 private: | 63 private: |
42 const scoped_array<uint8> key_id_; | 64 std::string key_id_; |
ddorwin
2012/07/24 01:00:10
Why was const removed from all these?
strobe_
2012/07/25 01:05:13
...I have no idea. Fixed.
| |
43 const int key_id_size_; | |
44 | 65 |
45 // Initialization vector. | 66 // Initialization vector. |
46 const scoped_array<uint8> iv_; | 67 std::string iv_; |
47 const int iv_size_; | |
48 | 68 |
49 // Checksum of the data to be verified before decrypting the data. This may | 69 // Checksum of the data to be verified before decrypting the data. This may |
50 // be NULL for some formats. | 70 // be empty for some formats. |
51 const scoped_array<uint8> checksum_; | 71 std::string checksum_; |
52 const int checksum_size_; | |
53 | 72 |
54 // This is the offset in bytes to where the encrypted data starts within | 73 // Amount of data to be discarded before applying subsample information. |
55 // the input buffer. | 74 int data_offset_; |
56 const int encrypted_frame_offset_; | 75 |
76 // Subsample information. May be empty for some formats, meaning entire frame | |
77 // (less data ignored by data_offset_) is encrypted. | |
78 std::vector<SubsampleEntry> subsamples_; | |
57 | 79 |
58 DISALLOW_COPY_AND_ASSIGN(DecryptConfig); | 80 DISALLOW_COPY_AND_ASSIGN(DecryptConfig); |
59 }; | 81 }; |
60 | 82 |
61 } // namespace media | 83 } // namespace media |
62 | 84 |
63 #endif // MEDIA_BASE_DECRYPT_CONFIG_H_ | 85 #endif // MEDIA_BASE_DECRYPT_CONFIG_H_ |
OLD | NEW |