OLD | NEW |
(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_PPAPI_CLEAR_KEY_CDM_H_ |
| 6 #define WEBKIT_MEDIA_CRYPTO_PPAPI_CLEAR_KEY_CDM_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/basictypes.h" |
| 11 #include "base/compiler_specific.h" |
| 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/synchronization/lock.h" |
| 14 #include "media/base/decryptor_client.h" |
| 15 #include "media/crypto/aes_decryptor.h" |
| 16 #include "webkit/media/crypto/ppapi/content_decryption_module.h" |
| 17 |
| 18 namespace media { |
| 19 class DecoderBuffer; |
| 20 } |
| 21 |
| 22 namespace webkit_media { |
| 23 |
| 24 // Clear key implementation of the cdm::ContentDecryptionModule interface. |
| 25 class ClearKeyCdm : public cdm::ContentDecryptionModule { |
| 26 public: |
| 27 ClearKeyCdm(); |
| 28 virtual ~ClearKeyCdm(); |
| 29 |
| 30 // ContentDecryptionModule implementation. |
| 31 virtual cdm::Status GenerateKeyRequest(const uint8_t* init_data, |
| 32 int init_data_size, |
| 33 cdm::KeyMessage* key_request) OVERRIDE; |
| 34 |
| 35 virtual cdm::Status AddKey(const char* session_id, |
| 36 int session_id_size, |
| 37 const uint8_t* key, |
| 38 int key_size, |
| 39 const uint8_t* key_id, |
| 40 int key_id_size) OVERRIDE; |
| 41 |
| 42 virtual cdm::Status CancelKeyRequest(const char* session_id, |
| 43 int session_id_size) OVERRIDE; |
| 44 |
| 45 virtual cdm::Status Decrypt(const cdm::InputBuffer& encrypted_buffer, |
| 46 cdm::OutputBuffer* decrypted_buffer) OVERRIDE; |
| 47 |
| 48 private: |
| 49 class Client : public media::DecryptorClient { |
| 50 public: |
| 51 enum Status { |
| 52 kKeyAdded, |
| 53 kKeyError, |
| 54 kKeyMessage, |
| 55 kNeedKey |
| 56 }; |
| 57 |
| 58 Client(); |
| 59 virtual ~Client(); |
| 60 |
| 61 Status status() { return status_; } |
| 62 const std::string& session_id() { return session_id_; } |
| 63 const uint8* key_message() { return key_message_.get(); } |
| 64 int key_message_length() { return key_message_length_; } |
| 65 const std::string& default_url() { return default_url_; } |
| 66 |
| 67 // Resets the Client to a clean state. |
| 68 void Reset(); |
| 69 |
| 70 // media::DecryptorClient implementation. |
| 71 virtual void KeyAdded(const std::string& key_system, |
| 72 const std::string& session_id) OVERRIDE; |
| 73 virtual void KeyError(const std::string& key_system, |
| 74 const std::string& session_id, |
| 75 media::Decryptor::KeyError error_code, |
| 76 int system_code) OVERRIDE; |
| 77 virtual void KeyMessage(const std::string& key_system, |
| 78 const std::string& session_id, |
| 79 scoped_array<uint8> message, |
| 80 int message_length, |
| 81 const std::string& default_url) OVERRIDE; |
| 82 virtual void NeedKey(const std::string& key_system, |
| 83 const std::string& session_id, |
| 84 scoped_array<uint8> init_data, |
| 85 int init_data_length) OVERRIDE; |
| 86 |
| 87 private: |
| 88 Status status_; |
| 89 std::string session_id_; |
| 90 scoped_array<uint8> key_message_; |
| 91 int key_message_length_; |
| 92 std::string default_url_; |
| 93 }; |
| 94 |
| 95 Client client_; |
| 96 media::AesDecryptor decryptor_; |
| 97 // Protects the |client_| from being accessed by the |decryptor_| |
| 98 // simultaneously. |
| 99 base::Lock client_lock_; |
| 100 }; |
| 101 |
| 102 } // namespace webkit_media |
| 103 |
| 104 #endif // WEBKIT_MEDIA_CRYPTO_PPAPI_CLEAR_KEY_CDM_H_ |
OLD | NEW |