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 WEBKIT_MEDIA_CRYPTO_CONTENT_DECRYPTION_MODULE_H_ | 5 #ifndef WEBKIT_MEDIA_CRYPTO_CONTENT_DECRYPTION_MODULE_H_ |
| 6 #define WEBKIT_MEDIA_CRYPTO_CONTENT_DECRYPTION_MODULE_H_ | 6 #define WEBKIT_MEDIA_CRYPTO_CONTENT_DECRYPTION_MODULE_H_ |
| 7 | 7 |
| 8 #if defined(_MSC_VER) | 8 #if defined(_MSC_VER) |
| 9 typedef unsigned char uint8_t; | 9 typedef unsigned char uint8_t; |
| 10 typedef unsigned int uint32_t; | 10 typedef unsigned int uint32_t; |
| 11 typedef __int64 int64_t; | 11 typedef __int64 int64_t; |
| 12 #else | 12 #else |
| 13 #include <stdint.h> | 13 #include <stdint.h> |
| 14 #endif | 14 #endif |
| 15 | 15 |
| 16 #include "cdm_export.h" | |
| 17 | |
| 16 namespace cdm { | 18 namespace cdm { |
| 17 class ContentDecryptionModule; | 19 class ContentDecryptionModule; |
| 18 } | 20 } |
| 19 | 21 |
| 20 extern "C" { | 22 extern "C" { |
| 21 cdm::ContentDecryptionModule* CreateCdmInstance(); | 23 CDM_EXPORT cdm::ContentDecryptionModule* CreateCdmInstance(); |
|
xhwang
2012/08/20 21:09:45
This is to simulate what's in MEDIA_EXPORT, or CON
ddorwin
2012/08/20 21:27:07
I don't think its definition should be based on de
xhwang
2012/08/20 21:57:10
Done.
| |
| 22 void DestroyCdmInstance(cdm::ContentDecryptionModule* instance); | 24 CDM_EXPORT void DestroyCdmInstance(cdm::ContentDecryptionModule* instance); |
| 23 const char* GetCdmVersion(); | 25 CDM_EXPORT const char* GetCdmVersion(); |
| 24 } | 26 } |
| 25 | 27 |
| 26 namespace cdm { | 28 namespace cdm { |
| 27 | 29 |
| 30 enum Status { | |
|
xhwang
2012/08/20 21:09:45
Move it here so that the caller (e.g. CdmWrapper)
| |
| 31 kSuccess = 0, | |
| 32 kErrorUnknown, | |
| 33 kErrorNoKey | |
| 34 }; | |
| 35 | |
| 36 struct KeyRequest { | |
| 37 char* session_id; | |
| 38 uint32_t session_id_size; | |
| 39 uint8_t* key_request; | |
| 40 uint32_t key_request_size; | |
| 41 char* default_url; | |
| 42 uint32_t default_url_size; | |
| 43 }; | |
| 44 | |
| 28 // An input buffer can be split into several continuous subsamples. | 45 // An input buffer can be split into several continuous subsamples. |
| 29 // A SubsampleEntry specifies the number of clear and cipher bytes in each | 46 // A SubsampleEntry specifies the number of clear and cipher bytes in each |
| 30 // subsample. For example, the following buffer has three subsamples: | 47 // subsample. For example, the following buffer has three subsamples: |
| 31 // | 48 // |
| 32 // |<----- subsample1 ----->|<----- subsample2 ----->|<----- subsample3 ----->| | 49 // |<----- subsample1 ----->|<----- subsample2 ----->|<----- subsample3 ----->| |
| 33 // | clear1 | cipher1 | clear2 | cipher2 | clear3 | cipher3 | | 50 // | clear1 | cipher1 | clear2 | cipher2 | clear3 | cipher3 | |
| 34 // | 51 // |
| 35 // For decryption, all of the cipher bytes in a buffer should be concatenated | 52 // 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 | 53 // (in the subsample order) into a single logical stream. The clear bytes should |
| 37 // not be considered as part of decryption. | 54 // not be considered as part of decryption. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 | 92 |
| 76 struct OutputBuffer { | 93 struct OutputBuffer { |
| 77 uint8_t* data; // Pointer to the beginning of the output data. | 94 uint8_t* data; // Pointer to the beginning of the output data. |
| 78 uint32_t data_size; // Size (in bytes) of |data|. | 95 uint32_t data_size; // Size (in bytes) of |data|. |
| 79 | 96 |
| 80 int64_t timestamp; // Presentation timestamp in microseconds. | 97 int64_t timestamp; // Presentation timestamp in microseconds. |
| 81 }; | 98 }; |
| 82 | 99 |
| 83 class ContentDecryptionModule { | 100 class ContentDecryptionModule { |
| 84 public: | 101 public: |
| 85 enum Status { | 102 // Generates a |key_request| given the |init_data|. |
| 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, | 103 // Returns kSuccess if the key request was successfully generated, |
| 94 // in which case the callee should have allocated memory for the output | 104 // 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. | 105 // parameters (e.g |session_id| in |key_request|) and passed the ownership |
| 96 // Returns kErrorUnknown otherwise, in which case the output | 106 // to the caller. |
| 97 // parameters should not be used by the caller. | 107 // Returns kErrorUnknown otherwise, in which case the output parameters should |
| 108 // not be used by the caller. | |
| 98 // | 109 // |
| 99 // TODO(xhwang): It's not safe to pass the ownership of the dynamically | 110 // 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 | 111 // allocated memory over library boundaries. Fix it after related PPAPI change |
| 101 // and sample CDM are landed. | 112 // and sample CDM are landed. |
| 102 virtual Status GenerateKeyRequest(const uint8_t* init_data, | 113 virtual Status GenerateKeyRequest(const uint8_t* init_data, |
| 103 int init_data_size, | 114 int init_data_size, |
| 104 char** session_id, | 115 KeyRequest* key_request) = 0; |
| 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 | 116 |
| 111 // Adds the |key| to the CDM to be associated with |key_id|. | 117 // Adds the |key| to the CDM to be associated with |key_id|. |
| 112 // Returns kSuccess if the key was successfully added. | 118 // Returns kSuccess if the key was successfully added. |
| 113 // Returns kErrorUnknown otherwise. | 119 // Returns kErrorUnknown otherwise. |
| 114 virtual Status AddKey(const char* session_id, | 120 virtual Status AddKey(const char* session_id, |
| 115 int session_id_size, | 121 int session_id_size, |
| 116 const uint8_t* key, | 122 const uint8_t* key, |
| 117 int key_size, | 123 int key_size, |
| 118 const uint8_t* key_id, | 124 const uint8_t* key_id, |
| 119 int key_id_size) = 0; | 125 int key_id_size) = 0; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 130 // should have filled the |decrypted_buffer| and passed the ownership of | 136 // should have filled the |decrypted_buffer| and passed the ownership of |
| 131 // |data| in |decrypted_buffer| to the caller. | 137 // |data| in |decrypted_buffer| to the caller. |
| 132 // Returns kErrorNoKey if the CDM did not have the necessary decryption key | 138 // Returns kErrorNoKey if the CDM did not have the necessary decryption key |
| 133 // to decrypt. | 139 // to decrypt. |
| 134 // Returns kErrorUnknown if any other error happened. | 140 // Returns kErrorUnknown if any other error happened. |
| 135 // In these two cases, |decrypted_buffer| should not be used by the caller. | 141 // In these two cases, |decrypted_buffer| should not be used by the caller. |
| 136 // | 142 // |
| 137 // TODO(xhwang): It's not safe to pass the ownership of the dynamically | 143 // 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 | 144 // allocated memory over library boundaries. Fix it after related PPAPI change |
| 139 // and sample CDM are landed. | 145 // and sample CDM are landed. |
| 140 virtual Status Decrypt(const char* session_id, | 146 virtual Status Decrypt(const InputBuffer& encrypted_buffer, |
| 141 int session_id_size, | |
| 142 const InputBuffer& encrypted_buffer, | |
| 143 OutputBuffer* decrypted_buffer) = 0; | 147 OutputBuffer* decrypted_buffer) = 0; |
| 144 | 148 |
| 145 virtual ~ContentDecryptionModule() {}; | 149 virtual ~ContentDecryptionModule() {}; |
| 146 }; | 150 }; |
| 147 | 151 |
| 148 } // namespace cdm | 152 } // namespace cdm |
| 149 | 153 |
| 150 #endif // WEBKIT_MEDIA_CRYPTO_CONTENT_DECRYPTION_MODULE_H_ | 154 #endif // WEBKIT_MEDIA_CRYPTO_CONTENT_DECRYPTION_MODULE_H_ |
| OLD | NEW |