Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 MEDIA_CDM_PROXY_DECRYPTOR_H_ | 5 #ifndef MEDIA_CDM_PROXY_DECRYPTOR_H_ |
| 6 #define MEDIA_CDM_PROXY_DECRYPTOR_H_ | 6 #define MEDIA_CDM_PROXY_DECRYPTOR_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/containers/hash_tables.h" | 12 #include "base/containers/hash_tables.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "media/base/cdm_context.h" | |
| 15 #include "media/base/decryptor.h" | 16 #include "media/base/decryptor.h" |
| 16 #include "media/base/eme_constants.h" | 17 #include "media/base/eme_constants.h" |
| 17 #include "media/base/media_export.h" | 18 #include "media/base/media_export.h" |
| 18 #include "media/base/media_keys.h" | 19 #include "media/base/media_keys.h" |
| 19 #include "url/gurl.h" | 20 #include "url/gurl.h" |
| 20 | 21 |
| 21 namespace media { | 22 namespace media { |
| 22 | 23 |
| 23 class CdmFactory; | 24 class CdmFactory; |
| 24 class MediaPermission; | 25 class MediaPermission; |
| 25 | 26 |
| 26 // ProxyDecryptor is for EME v0.1b only. It should not be used for the WD API. | 27 // ProxyDecryptor is for EME v0.1b only. It should not be used for the WD API. |
| 27 // A decryptor proxy that creates a real decryptor object on demand and | 28 // A decryptor proxy that creates a real decryptor object on demand and |
| 28 // forwards decryptor calls to it. | 29 // forwards decryptor calls to it. |
| 29 // | 30 // |
| 30 // TODO(xhwang): Currently we don't support run-time switching among decryptor | 31 // TODO(xhwang): Currently we don't support run-time switching among decryptor |
| 31 // objects. Fix this when needed. | 32 // objects. Fix this when needed. |
| 32 // TODO(xhwang): The ProxyDecryptor is not a Decryptor. Find a better name! | 33 // TODO(xhwang): The ProxyDecryptor is not a Decryptor. Find a better name! |
| 33 class MEDIA_EXPORT ProxyDecryptor { | 34 class MEDIA_EXPORT ProxyDecryptor { |
| 34 public: | 35 public: |
| 36 // Callback to provide a CdmContext when the CDM creation is finished. | |
| 37 // If CDM creation failed, |cdm_context| will be null. | |
| 38 typedef base::Callback<void(CdmContext* cdm_context)> CdmContextReadyCB; | |
| 39 | |
| 35 // These are similar to the callbacks in media_keys.h, but pass back the | 40 // These are similar to the callbacks in media_keys.h, but pass back the |
| 36 // session ID rather than the internal session ID. | 41 // session ID rather than the internal session ID. |
| 37 typedef base::Callback<void(const std::string& session_id)> KeyAddedCB; | 42 typedef base::Callback<void(const std::string& session_id)> KeyAddedCB; |
| 38 typedef base::Callback<void(const std::string& session_id, | 43 typedef base::Callback<void(const std::string& session_id, |
| 39 MediaKeys::KeyError error_code, | 44 MediaKeys::KeyError error_code, |
| 40 uint32 system_code)> KeyErrorCB; | 45 uint32 system_code)> KeyErrorCB; |
| 41 typedef base::Callback<void(const std::string& session_id, | 46 typedef base::Callback<void(const std::string& session_id, |
| 42 const std::vector<uint8>& message, | 47 const std::vector<uint8>& message, |
| 43 const GURL& destination_url)> KeyMessageCB; | 48 const GURL& destination_url)> KeyMessageCB; |
| 44 | 49 |
| 45 ProxyDecryptor(MediaPermission* media_permission, | 50 ProxyDecryptor(MediaPermission* media_permission, |
| 46 const KeyAddedCB& key_added_cb, | 51 const KeyAddedCB& key_added_cb, |
| 47 const KeyErrorCB& key_error_cb, | 52 const KeyErrorCB& key_error_cb, |
| 48 const KeyMessageCB& key_message_cb); | 53 const KeyMessageCB& key_message_cb); |
| 49 virtual ~ProxyDecryptor(); | 54 virtual ~ProxyDecryptor(); |
| 50 | 55 |
| 51 // Returns the CdmContext associated with this object. | 56 // Creates the CDM and fires |cdm_created_cb|. This method should only be |
| 52 CdmContext* GetCdmContext(); | 57 // called once. If CDM creation failed, all following GenerateKeyRequest, |
| 58 // AddKey and CancelKeyRequest calls will result in a KeyError. | |
| 59 void CreateCdm(CdmFactory* cdm_factory, | |
| 60 const std::string& key_system, | |
| 61 const GURL& security_origin, | |
| 62 const CdmContextReadyCB& cdm_context_ready_cb); | |
| 53 | 63 |
| 54 // Only call this once. | 64 // May only be called after CreateCDM(). |
| 55 bool InitializeCDM(CdmFactory* cdm_factory, | 65 void GenerateKeyRequest(EmeInitDataType init_data_type, |
| 56 const std::string& key_system, | |
| 57 const GURL& security_origin); | |
| 58 | |
| 59 // May only be called after InitializeCDM() succeeds. | |
| 60 bool GenerateKeyRequest(EmeInitDataType init_data_type, | |
| 61 const uint8* init_data, | 66 const uint8* init_data, |
| 62 int init_data_length); | 67 int init_data_length); |
| 63 void AddKey(const uint8* key, int key_length, | 68 void AddKey(const uint8* key, int key_length, |
| 64 const uint8* init_data, int init_data_length, | 69 const uint8* init_data, int init_data_length, |
| 65 const std::string& session_id); | 70 const std::string& session_id); |
| 66 void CancelKeyRequest(const std::string& session_id); | 71 void CancelKeyRequest(const std::string& session_id); |
| 67 | 72 |
| 68 private: | 73 private: |
| 69 // Helper function to create MediaKeys to handle the given |key_system|. | 74 // Callback for CreateCdm(). |
| 70 scoped_ptr<MediaKeys> CreateMediaKeys( | 75 void OnCdmCreated(const std::string& key_system, |
| 71 CdmFactory* cdm_factory, | 76 const GURL& security_origin, |
| 72 const std::string& key_system, | 77 const CdmContextReadyCB& cdm_context_ready_cb, |
| 73 const GURL& security_origin); | 78 scoped_ptr<MediaKeys> cdm); |
| 79 | |
| 80 void GenerateKeyRequestInternal(EmeInitDataType init_data_type, | |
| 81 const std::vector<uint8>& init_data); | |
| 74 | 82 |
| 75 // Callbacks for firing session events. | 83 // Callbacks for firing session events. |
| 76 void OnSessionMessage(const std::string& session_id, | 84 void OnSessionMessage(const std::string& session_id, |
| 77 MediaKeys::MessageType message_type, | 85 MediaKeys::MessageType message_type, |
| 78 const std::vector<uint8>& message, | 86 const std::vector<uint8>& message, |
| 79 const GURL& legacy_destination_url); | 87 const GURL& legacy_destination_url); |
| 80 void OnSessionKeysChange(const std::string& session_id, | 88 void OnSessionKeysChange(const std::string& session_id, |
| 81 bool has_additional_usable_key, | 89 bool has_additional_usable_key, |
| 82 CdmKeysInfo keys_info); | 90 CdmKeysInfo keys_info); |
| 83 void OnSessionExpirationUpdate(const std::string& session_id, | 91 void OnSessionExpirationUpdate(const std::string& session_id, |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 99 enum SessionCreationType { | 107 enum SessionCreationType { |
| 100 TemporarySession, | 108 TemporarySession, |
| 101 PersistentSession, | 109 PersistentSession, |
| 102 LoadSession | 110 LoadSession |
| 103 }; | 111 }; |
| 104 | 112 |
| 105 // Called when a session is actually created or loaded. | 113 // Called when a session is actually created or loaded. |
| 106 void SetSessionId(SessionCreationType session_type, | 114 void SetSessionId(SessionCreationType session_type, |
| 107 const std::string& session_id); | 115 const std::string& session_id); |
| 108 | 116 |
| 117 struct PendingGenerateKeyRequestData { | |
| 118 PendingGenerateKeyRequestData(EmeInitDataType init_data_type, | |
| 119 const std::vector<uint8>& init_data); | |
| 120 ~PendingGenerateKeyRequestData(); | |
| 121 | |
| 122 EmeInitDataType init_data_type; | |
|
ddorwin
2015/04/11 02:41:48
nit: consts?
xhwang
2015/04/13 18:56:10
Done.
xhwang
2015/04/13 20:46:20
Actually I need this to be non-const here because
| |
| 123 std::vector<uint8> init_data; | |
| 124 }; | |
| 125 | |
| 126 bool is_creating_cdm_; | |
| 127 | |
| 109 // The real MediaKeys that manages key operations for the ProxyDecryptor. | 128 // The real MediaKeys that manages key operations for the ProxyDecryptor. |
| 110 scoped_ptr<MediaKeys> media_keys_; | 129 scoped_ptr<MediaKeys> media_keys_; |
| 111 | 130 |
| 112 MediaPermission* media_permission_; | 131 MediaPermission* media_permission_; |
| 113 | 132 |
| 114 // Callbacks for firing key events. | 133 // Callbacks for firing key events. |
| 115 KeyAddedCB key_added_cb_; | 134 KeyAddedCB key_added_cb_; |
| 116 KeyErrorCB key_error_cb_; | 135 KeyErrorCB key_error_cb_; |
| 117 KeyMessageCB key_message_cb_; | 136 KeyMessageCB key_message_cb_; |
| 118 | 137 |
| 119 std::string key_system_; | 138 std::string key_system_; |
| 120 GURL security_origin_; | 139 GURL security_origin_; |
| 121 | 140 |
| 122 // Keep track of both persistent and non-persistent sessions. | 141 // Keep track of both persistent and non-persistent sessions. |
| 123 base::hash_map<std::string, bool> active_sessions_; | 142 base::hash_map<std::string, bool> active_sessions_; |
| 124 | 143 |
| 125 bool is_clear_key_; | 144 bool is_clear_key_; |
| 126 | 145 |
| 146 std::vector<PendingGenerateKeyRequestData> pending_requests_; | |
| 147 | |
| 127 // NOTE: Weak pointers must be invalidated before all other member variables. | 148 // NOTE: Weak pointers must be invalidated before all other member variables. |
| 128 base::WeakPtrFactory<ProxyDecryptor> weak_ptr_factory_; | 149 base::WeakPtrFactory<ProxyDecryptor> weak_ptr_factory_; |
| 129 | 150 |
| 130 DISALLOW_COPY_AND_ASSIGN(ProxyDecryptor); | 151 DISALLOW_COPY_AND_ASSIGN(ProxyDecryptor); |
| 131 }; | 152 }; |
| 132 | 153 |
| 133 } // namespace media | 154 } // namespace media |
| 134 | 155 |
| 135 #endif // MEDIA_CDM_PROXY_DECRYPTOR_H_ | 156 #endif // MEDIA_CDM_PROXY_DECRYPTOR_H_ |
| OLD | NEW |