Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(726)

Side by Side Diff: webkit/media/crypto/content_decryption_module.h

Issue 10823299: Add ContentDecryptionModule interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Drop duration and fixed typo. Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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 WEBKIT_MEDIA_CRYPTO_CONTENT_DECRYPTION_MODULE_H_
6 #define WEBKIT_MEDIA_CRYPTO_CONTENT_DECRYPTION_MODULE_H_
7
8 #if defined(_MSC_VER)
9 typedef unsigned char uint8_t;
10 typedef unsigned int uint32_t;
11 typedef __int64 int64_t;
12 #else
13 #include <stdint.h>
14 #endif
15
16 namespace cdm {
17 class ContentDecryptionModule;
18 }
19
20 extern "C" cdm::ContentDecryptionModule* CreateCdmInstance();
scherkus (not reviewing) 2012/08/16 21:18:57 nit: extern "C" { }
xhwang 2012/08/16 21:44:24 Done.
21 extern "C" void DestroyCdmInstance(cdm::ContentDecryptionModule* instance);
22 extern "C" const char* GetCdmVersion();
23
24 namespace cdm {
25
26 // An input buffer can be split into several continuous subsamples.
27 // A SubsampleEntry specifies the number of clear and cipher bytes in each
28 // subsample. For example, the following buffer has three subsamples:
29 //
30 // |<----- subsample1 ----->|<----- subsample2 ----->|<----- subsample3 ----->|
31 // | clear1 | cipher1 | clear2 | cipher2 | clear3 | cipher3 |
32 //
33 // For decryption, all of the cipher bytes in a buffer should be concatenated
34 // (in the subsample order) into a single logical stream. The clear bytes should
35 // not be considered as part of decryption.
36 //
37 // Stream to decrypt: | cipher1 | cipher2 | cipher3 |
38 // Decrypted stream: | decrypted1| decrypted2 | decrypted3 |
39 //
40 // After decryption, the decrypted bytes should be copied over the position
41 // of the corresponding cipher bytes in the original buffer to form the output
42 // buffer. Following the above example, the decrypted buffer should be:
43 //
44 // |<----- subsample1 ----->|<----- subsample2 ----->|<----- subsample3 ----->|
45 // | clear1 | decrypted1| clear2 | decrypted2 | clear3 | decrypted3 |
46 //
47 // TODO(xhwang): Add checks to make sure these structs have fixed layout.
48 struct SubsampleEntry {
49 uint32_t clear_bytes;
50 uint32_t cipher_bytes;
51 };
52
53 struct InputBuffer {
54 uint8_t* data; // Pointer to the beginning of the input data.
55 uint32_t data_size; // Size (in bytes) of |data|.
56
57 uint32_t data_offset; // Number of bytes to be discarded before decryption.
58
59 uint8_t* key_id; // Key ID to identify the decryption key.
60 uint32_t key_id_size; // Size (in bytes) of |key_id|.
61
62 uint8_t* iv; // Initialization vector.
63 uint32_t iv_size; // Size (in bytes) of |iv|.
64
65 uint8_t* checksum;
66 uint32_t checksum_size; // Size (in bytes) of the |checksum|.
67
68 struct SubsampleEntry* subsamples;
69 uint32_t num_subsamples; // Number of subsamples in |subsamples|.
70
71 int64_t timestamp; // Presentation timestamp in microseconds.
72 };
73
74 struct OutputBuffer {
75 uint8_t* data; // Pointer to the beginning of the output data.
76 uint32_t data_size; // Size (in bytes) of |data|.
77
78 int64_t timestamp; // Presentation timestamp in microseconds.
79 };
80
81 class ContentDecryptionModule {
82 public:
83 enum Status {
84 kSuccess = 0,
85 kErrorUnknown,
86 kErrorNoKey
87 };
88
89 // Generates a |key_request| as well as a |session_id| given the |init_data|.
90 // The CDM may also extract a |default_url|.
91 // Returns kSuccess if the key request was successfully generated,
92 // in which case the callee should have allocated memory for the output
93 // parameters (e.g |session_id|) and passed the ownership to the caller.
94 // Returns kErrorUnknown otherwise, in which case the output
95 // parameters should not be used by the caller.
96 //
97 // TODO(xhwang): It's not safe to pass the ownership of the dynamically
98 // allocated memory over library boundaries. Fix it after related PPAPI change
99 // and sample CDM are landed.
100 virtual Status GenerateKeyRequest(const uint8_t* init_data,
101 int init_data_size,
102 char** session_id,
103 int* session_id_size,
104 uint8_t** key_request,
105 int* key_request_size,
106 char** default_url,
107 int* default_url_size) = 0;
108
109 // Adds the |key| to the CDM to be associated with |key_id|.
110 // Returns kSuccess if the key was successfully added.
111 // Returns kErrorUnknown otherwise.
112 virtual Status AddKey(const char* session_id,
113 int session_id_size,
114 const uint8_t* key,
115 int key_size,
116 const uint8_t* key_id,
117 int key_id_size) = 0;
118
119 // Cancels any pending key request made to the CDM for |session_id|.
120 // Returns kSuccess if all pending key requests for |session_id| were
121 // successfully canceled or there was no key request to be canceled.
122 // Returns kErrorUnknown otherwise.
123 virtual Status CancelKeyRequest(const char* session_id,
124 int session_id_size) = 0;
125
126 // Decrypts the |encrypted_buffer|.
127 // Returns kSuccess if decryption succeeded, in which case the callee
128 // should have filled the |decrypted_buffer| and passed the ownership of
129 // |data| in |decrypted_buffer| to the caller.
130 // Returns kErrorNoKey if the CDM did not have the necessary decryption key
131 // to decrypt.
132 // Returns kErrorUnknown if any other error happened.
133 // In these two cases, |decrypted_buffer| should not be used by the caller.
134 //
135 // TODO(xhwang): It's not safe to pass the ownership of the dynamically
136 // allocated memory over library boundaries. Fix it after related PPAPI change
137 // and sample CDM are landed.
138 virtual Status Decrypt(const char* session_id,
139 int session_id_size,
140 const InputBuffer& encrypted_buffer,
141 OutputBuffer* decrypted_buffer) = 0;
142
143 virtual ~ContentDecryptionModule() {};
144 };
145
146 } // namespace cdm
147
148 #endif // WEBKIT_MEDIA_CRYPTO_CONTENT_DECRYPTION_MODULE_H_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698