OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_MOJO_SERVICES_MOJO_CDM_H_ | 5 #ifndef MEDIA_MOJO_SERVICES_MOJO_CDM_H_ |
6 #define MEDIA_MOJO_SERVICES_MOJO_CDM_H_ | 6 #define MEDIA_MOJO_SERVICES_MOJO_CDM_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "mojo/public/cpp/bindings/binding.h" | 23 #include "mojo/public/cpp/bindings/binding.h" |
24 | 24 |
25 namespace base { | 25 namespace base { |
26 class SingleThreadTaskRunner; | 26 class SingleThreadTaskRunner; |
27 } | 27 } |
28 | 28 |
29 namespace media { | 29 namespace media { |
30 | 30 |
31 class MojoDecryptor; | 31 class MojoDecryptor; |
32 | 32 |
33 // A MediaKeys that proxies to a interfaces::ContentDecryptionModule. That | 33 // A MediaKeys that proxies to a mojom::ContentDecryptionModule. That |
34 // interfaces::ContentDecryptionModule proxies back to the MojoCdm via the | 34 // mojom::ContentDecryptionModule proxies back to the MojoCdm via the |
35 // interfaces::ContentDecryptionModuleClient interface. | 35 // mojom::ContentDecryptionModuleClient interface. |
36 class MojoCdm : public MediaKeys, | 36 class MojoCdm : public MediaKeys, |
37 public CdmContext, | 37 public CdmContext, |
38 public interfaces::ContentDecryptionModuleClient { | 38 public mojom::ContentDecryptionModuleClient { |
39 public: | 39 public: |
40 static void Create( | 40 static void Create( |
41 const std::string& key_system, | 41 const std::string& key_system, |
42 const GURL& security_origin, | 42 const GURL& security_origin, |
43 const media::CdmConfig& cdm_config, | 43 const media::CdmConfig& cdm_config, |
44 interfaces::ContentDecryptionModulePtr remote_cdm, | 44 mojom::ContentDecryptionModulePtr remote_cdm, |
45 const media::SessionMessageCB& session_message_cb, | 45 const media::SessionMessageCB& session_message_cb, |
46 const media::SessionClosedCB& session_closed_cb, | 46 const media::SessionClosedCB& session_closed_cb, |
47 const media::LegacySessionErrorCB& legacy_session_error_cb, | 47 const media::LegacySessionErrorCB& legacy_session_error_cb, |
48 const media::SessionKeysChangeCB& session_keys_change_cb, | 48 const media::SessionKeysChangeCB& session_keys_change_cb, |
49 const media::SessionExpirationUpdateCB& session_expiration_update_cb, | 49 const media::SessionExpirationUpdateCB& session_expiration_update_cb, |
50 const media::CdmCreatedCB& cdm_created_cb); | 50 const media::CdmCreatedCB& cdm_created_cb); |
51 | 51 |
52 // MediaKeys implementation. | 52 // MediaKeys implementation. |
53 void SetServerCertificate(const std::vector<uint8_t>& certificate, | 53 void SetServerCertificate(const std::vector<uint8_t>& certificate, |
54 std::unique_ptr<SimpleCdmPromise> promise) final; | 54 std::unique_ptr<SimpleCdmPromise> promise) final; |
(...skipping 13 matching lines...) Expand all Loading... |
68 void RemoveSession(const std::string& session_id, | 68 void RemoveSession(const std::string& session_id, |
69 std::unique_ptr<SimpleCdmPromise> promise) final; | 69 std::unique_ptr<SimpleCdmPromise> promise) final; |
70 CdmContext* GetCdmContext() final; | 70 CdmContext* GetCdmContext() final; |
71 | 71 |
72 // CdmContext implementation. Can be called on a different thread. | 72 // CdmContext implementation. Can be called on a different thread. |
73 // All GetDecryptor() calls must be made on the same thread. | 73 // All GetDecryptor() calls must be made on the same thread. |
74 media::Decryptor* GetDecryptor() final; | 74 media::Decryptor* GetDecryptor() final; |
75 int GetCdmId() const final; | 75 int GetCdmId() const final; |
76 | 76 |
77 private: | 77 private: |
78 MojoCdm(interfaces::ContentDecryptionModulePtr remote_cdm, | 78 MojoCdm(mojom::ContentDecryptionModulePtr remote_cdm, |
79 const SessionMessageCB& session_message_cb, | 79 const SessionMessageCB& session_message_cb, |
80 const SessionClosedCB& session_closed_cb, | 80 const SessionClosedCB& session_closed_cb, |
81 const LegacySessionErrorCB& legacy_session_error_cb, | 81 const LegacySessionErrorCB& legacy_session_error_cb, |
82 const SessionKeysChangeCB& session_keys_change_cb, | 82 const SessionKeysChangeCB& session_keys_change_cb, |
83 const SessionExpirationUpdateCB& session_expiration_update_cb); | 83 const SessionExpirationUpdateCB& session_expiration_update_cb); |
84 | 84 |
85 ~MojoCdm() final; | 85 ~MojoCdm() final; |
86 | 86 |
87 void InitializeCdm(const std::string& key_system, | 87 void InitializeCdm(const std::string& key_system, |
88 const GURL& security_origin, | 88 const GURL& security_origin, |
89 const media::CdmConfig& cdm_config, | 89 const media::CdmConfig& cdm_config, |
90 std::unique_ptr<CdmInitializedPromise> promise); | 90 std::unique_ptr<CdmInitializedPromise> promise); |
91 | 91 |
92 void OnConnectionError(); | 92 void OnConnectionError(); |
93 | 93 |
94 // interfaces::ContentDecryptionModuleClient implementation. | 94 // mojom::ContentDecryptionModuleClient implementation. |
95 void OnSessionMessage(const mojo::String& session_id, | 95 void OnSessionMessage(const mojo::String& session_id, |
96 interfaces::CdmMessageType message_type, | 96 mojom::CdmMessageType message_type, |
97 mojo::Array<uint8_t> message, | 97 mojo::Array<uint8_t> message, |
98 const mojo::String& legacy_destination_url) final; | 98 const mojo::String& legacy_destination_url) final; |
99 void OnSessionClosed(const mojo::String& session_id) final; | 99 void OnSessionClosed(const mojo::String& session_id) final; |
100 void OnLegacySessionError(const mojo::String& session_id, | 100 void OnLegacySessionError(const mojo::String& session_id, |
101 interfaces::CdmException exception, | 101 mojom::CdmException exception, |
102 uint32_t system_code, | 102 uint32_t system_code, |
103 const mojo::String& error_message) final; | 103 const mojo::String& error_message) final; |
104 void OnSessionKeysChange( | 104 void OnSessionKeysChange( |
105 const mojo::String& session_id, | 105 const mojo::String& session_id, |
106 bool has_additional_usable_key, | 106 bool has_additional_usable_key, |
107 mojo::Array<interfaces::CdmKeyInformationPtr> keys_info) final; | 107 mojo::Array<mojom::CdmKeyInformationPtr> keys_info) final; |
108 void OnSessionExpirationUpdate(const mojo::String& session_id, | 108 void OnSessionExpirationUpdate(const mojo::String& session_id, |
109 double new_expiry_time_sec) final; | 109 double new_expiry_time_sec) final; |
110 | 110 |
111 // Callback for InitializeCdm. | 111 // Callback for InitializeCdm. |
112 // Note: Cannot use OnPromiseResult() below since we need to handle connection | 112 // Note: Cannot use OnPromiseResult() below since we need to handle connection |
113 // error. Also we have extra parameters |cdm_id| and |decryptor|, which aren't | 113 // error. Also we have extra parameters |cdm_id| and |decryptor|, which aren't |
114 // needed in CdmInitializedPromise. | 114 // needed in CdmInitializedPromise. |
115 void OnCdmInitialized(interfaces::CdmPromiseResultPtr result, | 115 void OnCdmInitialized(mojom::CdmPromiseResultPtr result, |
116 int cdm_id, | 116 int cdm_id, |
117 interfaces::DecryptorPtr decryptor); | 117 mojom::DecryptorPtr decryptor); |
118 | 118 |
119 // Callback when new decryption key is available. | 119 // Callback when new decryption key is available. |
120 void OnKeyAdded(); | 120 void OnKeyAdded(); |
121 | 121 |
122 // Callbacks to handle CDM promises. | 122 // Callbacks to handle CDM promises. |
123 // We have to inline this method, since MS VS 2013 compiler fails to compile | 123 // We have to inline this method, since MS VS 2013 compiler fails to compile |
124 // it when this method is not inlined. It fails with error C2244 | 124 // it when this method is not inlined. It fails with error C2244 |
125 // "unable to match function definition to an existing declaration". | 125 // "unable to match function definition to an existing declaration". |
126 template <typename... T> | 126 template <typename... T> |
127 void OnPromiseResult(std::unique_ptr<CdmPromiseTemplate<T...>> promise, | 127 void OnPromiseResult(std::unique_ptr<CdmPromiseTemplate<T...>> promise, |
128 interfaces::CdmPromiseResultPtr result, | 128 mojom::CdmPromiseResultPtr result, |
129 typename MojoTypeTrait<T>::MojoType... args) { | 129 typename MojoTypeTrait<T>::MojoType... args) { |
130 if (result->success) | 130 if (result->success) |
131 promise->resolve(args.template To<T>()...); // See ISO C++03 14.2/4. | 131 promise->resolve(args.template To<T>()...); // See ISO C++03 14.2/4. |
132 else | 132 else |
133 RejectPromise(std::move(promise), std::move(result)); | 133 RejectPromise(std::move(promise), std::move(result)); |
134 } | 134 } |
135 | 135 |
136 base::ThreadChecker thread_checker_; | 136 base::ThreadChecker thread_checker_; |
137 | 137 |
138 interfaces::ContentDecryptionModulePtr remote_cdm_; | 138 mojom::ContentDecryptionModulePtr remote_cdm_; |
139 mojo::Binding<ContentDecryptionModuleClient> binding_; | 139 mojo::Binding<ContentDecryptionModuleClient> binding_; |
140 | 140 |
141 // Protects |cdm_id_|, |decryptor_ptr_|, |decryptor_| and | 141 // Protects |cdm_id_|, |decryptor_ptr_|, |decryptor_| and |
142 // |decryptor_task_runner_| which could be accessed from other threads. | 142 // |decryptor_task_runner_| which could be accessed from other threads. |
143 // See CdmContext implementation above. | 143 // See CdmContext implementation above. |
144 mutable base::Lock lock_; | 144 mutable base::Lock lock_; |
145 | 145 |
146 // CDM ID of the remote CDM. Set after initialization is completed. Must not | 146 // CDM ID of the remote CDM. Set after initialization is completed. Must not |
147 // be invalid if initialization succeeded. | 147 // be invalid if initialization succeeded. |
148 int cdm_id_; | 148 int cdm_id_; |
149 | 149 |
150 // The DecryptorPtr exposed by the remote CDM. Set after initialization is | 150 // The DecryptorPtr exposed by the remote CDM. Set after initialization is |
151 // completed and cleared after |decryptor_| is created. May be null after | 151 // completed and cleared after |decryptor_| is created. May be null after |
152 // initialization if the CDM doesn't support a Decryptor. | 152 // initialization if the CDM doesn't support a Decryptor. |
153 interfaces::DecryptorPtr decryptor_ptr_; | 153 mojom::DecryptorPtr decryptor_ptr_; |
154 | 154 |
155 // Decryptor based on |decryptor_ptr_|, lazily created in GetDecryptor(). | 155 // Decryptor based on |decryptor_ptr_|, lazily created in GetDecryptor(). |
156 // Since GetDecryptor() can be called on a different thread, use | 156 // Since GetDecryptor() can be called on a different thread, use |
157 // |decryptor_task_runner_| to bind |decryptor_| to that thread. | 157 // |decryptor_task_runner_| to bind |decryptor_| to that thread. |
158 std::unique_ptr<MojoDecryptor> decryptor_; | 158 std::unique_ptr<MojoDecryptor> decryptor_; |
159 scoped_refptr<base::SingleThreadTaskRunner> decryptor_task_runner_; | 159 scoped_refptr<base::SingleThreadTaskRunner> decryptor_task_runner_; |
160 | 160 |
161 // Callbacks for firing session events. | 161 // Callbacks for firing session events. |
162 SessionMessageCB session_message_cb_; | 162 SessionMessageCB session_message_cb_; |
163 SessionClosedCB session_closed_cb_; | 163 SessionClosedCB session_closed_cb_; |
164 LegacySessionErrorCB legacy_session_error_cb_; | 164 LegacySessionErrorCB legacy_session_error_cb_; |
165 SessionKeysChangeCB session_keys_change_cb_; | 165 SessionKeysChangeCB session_keys_change_cb_; |
166 SessionExpirationUpdateCB session_expiration_update_cb_; | 166 SessionExpirationUpdateCB session_expiration_update_cb_; |
167 | 167 |
168 // Pending promise for InitializeCdm(). | 168 // Pending promise for InitializeCdm(). |
169 std::unique_ptr<CdmInitializedPromise> pending_init_promise_; | 169 std::unique_ptr<CdmInitializedPromise> pending_init_promise_; |
170 | 170 |
171 // This must be the last member. | 171 // This must be the last member. |
172 base::WeakPtrFactory<MojoCdm> weak_factory_; | 172 base::WeakPtrFactory<MojoCdm> weak_factory_; |
173 | 173 |
174 DISALLOW_COPY_AND_ASSIGN(MojoCdm); | 174 DISALLOW_COPY_AND_ASSIGN(MojoCdm); |
175 }; | 175 }; |
176 | 176 |
177 } // namespace media | 177 } // namespace media |
178 | 178 |
179 #endif // MEDIA_MOJO_SERVICES_MOJO_CDM_H_ | 179 #endif // MEDIA_MOJO_SERVICES_MOJO_CDM_H_ |
OLD | NEW |