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.
5 #ifndef MEDIA_BASE_DECRYPT_CONFIG_H_
6 #define MEDIA_BASE_DECRYPT_CONFIG_H_
11 #include "base/basictypes.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "media/base/media_export.h"
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 SubsampleEntry() : clear_bytes(0), cypher_bytes(0) {}
28 SubsampleEntry(uint32 clear_bytes
, uint32 cypher_bytes
)
29 : clear_bytes(clear_bytes
), cypher_bytes(cypher_bytes
) {}
34 // Contains all information that a decryptor needs to decrypt a media sample.
35 class MEDIA_EXPORT DecryptConfig
{
37 // Keys are always 128 bits.
38 static const int kDecryptionKeySize
= 16;
40 // |key_id| is the ID that references the decryption key for this sample.
41 // |iv| is the initialization vector defined by the encrypted format.
42 // Currently |iv| must be 16 bytes as defined by WebM and ISO. Or must be
43 // empty which signals an unencrypted frame.
44 // |subsamples| defines the clear and encrypted portions of the sample as
45 // described above. A decrypted buffer will be equal in size to the sum
46 // of the subsample sizes.
47 DecryptConfig(const std::string
& key_id
,
48 const std::string
& iv
,
49 const std::vector
<SubsampleEntry
>& subsamples
);
52 const std::string
& key_id() const { return key_id_
; }
53 const std::string
& iv() const { return iv_
; }
54 const std::vector
<SubsampleEntry
>& subsamples() const { return subsamples_
; }
56 // Returns true if all fields in |config| match this config.
57 bool Matches(const DecryptConfig
& config
) const;
60 const std::string key_id_
;
62 // Initialization vector.
63 const std::string iv_
;
65 // Subsample information. May be empty for some formats, meaning entire frame
66 // (less data ignored by data_offset_) is encrypted.
67 const std::vector
<SubsampleEntry
> subsamples_
;
69 DISALLOW_COPY_AND_ASSIGN(DecryptConfig
);
74 #endif // MEDIA_BASE_DECRYPT_CONFIG_H_