| 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_CLIENTS_MOJO_CDM_H_ | 5 #ifndef MEDIA_MOJO_CLIENTS_MOJO_CDM_H_ |
| 6 #define MEDIA_MOJO_CLIENTS_MOJO_CDM_H_ | 6 #define MEDIA_MOJO_CLIENTS_MOJO_CDM_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <utility> | 11 #include <utility> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "base/synchronization/lock.h" | 16 #include "base/synchronization/lock.h" |
| 17 #include "base/threading/thread_checker.h" | 17 #include "base/threading/thread_checker.h" |
| 18 #include "media/base/cdm_context.h" | 18 #include "media/base/cdm_context.h" |
| 19 #include "media/base/cdm_initialized_promise.h" | 19 #include "media/base/cdm_initialized_promise.h" |
| 20 #include "media/base/media_keys.h" | 20 #include "media/base/media_keys.h" |
| 21 #include "media/mojo/common/mojo_type_trait.h" | |
| 22 #include "media/mojo/interfaces/content_decryption_module.mojom.h" | 21 #include "media/mojo/interfaces/content_decryption_module.mojom.h" |
| 23 #include "mojo/public/cpp/bindings/binding.h" | 22 #include "mojo/public/cpp/bindings/binding.h" |
| 24 | 23 |
| 25 namespace base { | 24 namespace base { |
| 26 class SingleThreadTaskRunner; | 25 class SingleThreadTaskRunner; |
| 27 } | 26 } |
| 28 | 27 |
| 29 namespace media { | 28 namespace media { |
| 30 | 29 |
| 31 class MojoDecryptor; | 30 class MojoDecryptor; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 ~MojoCdm() final; | 82 ~MojoCdm() final; |
| 84 | 83 |
| 85 void InitializeCdm(const std::string& key_system, | 84 void InitializeCdm(const std::string& key_system, |
| 86 const GURL& security_origin, | 85 const GURL& security_origin, |
| 87 const media::CdmConfig& cdm_config, | 86 const media::CdmConfig& cdm_config, |
| 88 std::unique_ptr<CdmInitializedPromise> promise); | 87 std::unique_ptr<CdmInitializedPromise> promise); |
| 89 | 88 |
| 90 void OnConnectionError(); | 89 void OnConnectionError(); |
| 91 | 90 |
| 92 // mojom::ContentDecryptionModuleClient implementation. | 91 // mojom::ContentDecryptionModuleClient implementation. |
| 93 void OnSessionMessage(const mojo::String& session_id, | 92 void OnSessionMessage(const std::string& session_id, |
| 94 mojom::CdmMessageType message_type, | 93 mojom::CdmMessageType message_type, |
| 95 mojo::Array<uint8_t> message) final; | 94 const std::vector<uint8_t>& message) final; |
| 96 void OnSessionClosed(const mojo::String& session_id) final; | 95 void OnSessionClosed(const std::string& session_id) final; |
| 97 void OnSessionKeysChange( | 96 void OnSessionKeysChange( |
| 98 const mojo::String& session_id, | 97 const std::string& session_id, |
| 99 bool has_additional_usable_key, | 98 bool has_additional_usable_key, |
| 100 mojo::Array<mojom::CdmKeyInformationPtr> keys_info) final; | 99 std::vector<mojom::CdmKeyInformationPtr> keys_info) final; |
| 101 void OnSessionExpirationUpdate(const mojo::String& session_id, | 100 void OnSessionExpirationUpdate(const std::string& session_id, |
| 102 double new_expiry_time_sec) final; | 101 double new_expiry_time_sec) final; |
| 103 | 102 |
| 104 // Callback for InitializeCdm. | 103 // Callback for InitializeCdm. |
| 105 // Note: Cannot use OnPromiseResult() below since we need to handle connection | |
| 106 // error. Also we have extra parameters |cdm_id| and |decryptor|, which aren't | |
| 107 // needed in CdmInitializedPromise. | |
| 108 void OnCdmInitialized(mojom::CdmPromiseResultPtr result, | 104 void OnCdmInitialized(mojom::CdmPromiseResultPtr result, |
| 109 int cdm_id, | 105 int cdm_id, |
| 110 mojom::DecryptorPtr decryptor); | 106 mojom::DecryptorPtr decryptor); |
| 111 | 107 |
| 112 // Callback when new decryption key is available. | 108 // Callback when new decryption key is available. |
| 113 void OnKeyAdded(); | 109 void OnKeyAdded(); |
| 114 | 110 |
| 115 // Callbacks to handle CDM promises. | 111 // Callbacks to handle CDM promises. |
| 116 // We have to inline this method, since MS VS 2013 compiler fails to compile | 112 void OnSimpleCdmPromiseResult(std::unique_ptr<SimpleCdmPromise> promise, |
| 117 // it when this method is not inlined. It fails with error C2244 | 113 mojom::CdmPromiseResultPtr result); |
| 118 // "unable to match function definition to an existing declaration". | 114 void OnNewSessionCdmPromiseResult( |
| 119 template <typename... T> | 115 std::unique_ptr<NewSessionCdmPromise> promise, |
| 120 void OnPromiseResult(std::unique_ptr<CdmPromiseTemplate<T...>> promise, | 116 mojom::CdmPromiseResultPtr result, |
| 121 mojom::CdmPromiseResultPtr result, | 117 const std::string& session_id); |
| 122 typename MojoTypeTrait<T>::MojoType... args) { | |
| 123 if (result->success) | |
| 124 promise->resolve(args.template To<T>()...); // See ISO C++03 14.2/4. | |
| 125 else | |
| 126 RejectPromise(std::move(promise), std::move(result)); | |
| 127 } | |
| 128 | 118 |
| 129 base::ThreadChecker thread_checker_; | 119 base::ThreadChecker thread_checker_; |
| 130 | 120 |
| 131 mojom::ContentDecryptionModulePtr remote_cdm_; | 121 mojom::ContentDecryptionModulePtr remote_cdm_; |
| 132 mojo::Binding<ContentDecryptionModuleClient> binding_; | 122 mojo::Binding<ContentDecryptionModuleClient> binding_; |
| 133 | 123 |
| 134 // Protects |cdm_id_|, |decryptor_ptr_|, |decryptor_| and | 124 // Protects |cdm_id_|, |decryptor_ptr_|, |decryptor_| and |
| 135 // |decryptor_task_runner_| which could be accessed from other threads. | 125 // |decryptor_task_runner_| which could be accessed from other threads. |
| 136 // See CdmContext implementation above. | 126 // See CdmContext implementation above. |
| 137 mutable base::Lock lock_; | 127 mutable base::Lock lock_; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 162 | 152 |
| 163 // This must be the last member. | 153 // This must be the last member. |
| 164 base::WeakPtrFactory<MojoCdm> weak_factory_; | 154 base::WeakPtrFactory<MojoCdm> weak_factory_; |
| 165 | 155 |
| 166 DISALLOW_COPY_AND_ASSIGN(MojoCdm); | 156 DISALLOW_COPY_AND_ASSIGN(MojoCdm); |
| 167 }; | 157 }; |
| 168 | 158 |
| 169 } // namespace media | 159 } // namespace media |
| 170 | 160 |
| 171 #endif // MEDIA_MOJO_CLIENTS_MOJO_CDM_H_ | 161 #endif // MEDIA_MOJO_CLIENTS_MOJO_CDM_H_ |
| OLD | NEW |