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

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

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