| 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_SERVICE_H_ | 5 #ifndef MEDIA_MOJO_SERVICES_MOJO_CDM_SERVICE_H_ |
| 6 #define MEDIA_MOJO_SERVICES_MOJO_CDM_SERVICE_H_ | 6 #define MEDIA_MOJO_SERVICES_MOJO_CDM_SERVICE_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 | 11 |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 17 #include "media/base/media_keys.h" | 17 #include "media/base/media_keys.h" |
| 18 #include "media/mojo/interfaces/content_decryption_module.mojom.h" | 18 #include "media/mojo/interfaces/content_decryption_module.mojom.h" |
| 19 #include "media/mojo/services/media_mojo_export.h" | 19 #include "media/mojo/services/media_mojo_export.h" |
| 20 #include "media/mojo/services/mojo_cdm_promise.h" | 20 #include "media/mojo/services/mojo_cdm_promise.h" |
| 21 #include "media/mojo/services/mojo_cdm_service_context.h" | 21 #include "media/mojo/services/mojo_cdm_service_context.h" |
| 22 #include "media/mojo/services/mojo_decryptor_service.h" | 22 #include "media/mojo/services/mojo_decryptor_service.h" |
| 23 #include "mojo/public/cpp/bindings/strong_binding.h" | |
| 24 | 23 |
| 25 namespace media { | 24 namespace media { |
| 26 | 25 |
| 27 class CdmFactory; | 26 class CdmFactory; |
| 28 | 27 |
| 29 // A mojom::ContentDecryptionModule implementation backed by a | 28 // A mojom::ContentDecryptionModule implementation backed by a |
| 30 // media::MediaKeys. | 29 // media::MediaKeys. |
| 31 class MEDIA_MOJO_EXPORT MojoCdmService | 30 class MEDIA_MOJO_EXPORT MojoCdmService |
| 32 : NON_EXPORTED_BASE(public mojom::ContentDecryptionModule) { | 31 : NON_EXPORTED_BASE(public mojom::ContentDecryptionModule) { |
| 33 public: | 32 public: |
| 34 // Get the CDM associated with |cdm_id|, which is unique per process. | 33 // Get the CDM associated with |cdm_id|, which is unique per process. |
| 35 // Can be called on any thread. The returned CDM is not guaranteed to be | 34 // Can be called on any thread. The returned CDM is not guaranteed to be |
| 36 // thread safe. | 35 // thread safe. |
| 37 // Note: This provides a generic hack to get the CDM in the process where | 36 // Note: This provides a generic hack to get the CDM in the process where |
| 38 // MojoMediaApplication is running, regardless of which render process or | 37 // MojoMediaApplication is running, regardless of which render process or |
| 39 // render frame the caller is associated with. In the future, we should move | 38 // render frame the caller is associated with. In the future, we should move |
| 40 // all out-of-process media players into the MojoMediaApplicaiton so that we | 39 // all out-of-process media players into the MojoMediaApplicaiton so that we |
| 41 // can use MojoCdmServiceContext (per render frame) to get the CDM. | 40 // can use MojoCdmServiceContext (per render frame) to get the CDM. |
| 42 static scoped_refptr<MediaKeys> LegacyGetCdm(int cdm_id); | 41 static scoped_refptr<MediaKeys> LegacyGetCdm(int cdm_id); |
| 43 | 42 |
| 44 // Constructs a MojoCdmService and strongly binds it to the |request|. | 43 // Constructs a MojoCdmService and strongly binds it to the |request|. |
| 45 MojoCdmService( | 44 MojoCdmService(base::WeakPtr<MojoCdmServiceContext> context, |
| 46 base::WeakPtr<MojoCdmServiceContext> context, | 45 CdmFactory* cdm_factory); |
| 47 CdmFactory* cdm_factory, | |
| 48 mojo::InterfaceRequest<mojom::ContentDecryptionModule> request); | |
| 49 | 46 |
| 50 ~MojoCdmService() final; | 47 ~MojoCdmService() final; |
| 51 | 48 |
| 52 // mojom::ContentDecryptionModule implementation. | 49 // mojom::ContentDecryptionModule implementation. |
| 53 void SetClient(mojom::ContentDecryptionModuleClientPtr client) final; | 50 void SetClient(mojom::ContentDecryptionModuleClientPtr client) final; |
| 54 void Initialize(const mojo::String& key_system, | 51 void Initialize(const mojo::String& key_system, |
| 55 const mojo::String& security_origin, | 52 const mojo::String& security_origin, |
| 56 mojom::CdmConfigPtr cdm_config, | 53 mojom::CdmConfigPtr cdm_config, |
| 57 const InitializeCallback& callback) final; | 54 const InitializeCallback& callback) final; |
| 58 void SetServerCertificate(mojo::Array<uint8_t> certificate_data, | 55 void SetServerCertificate(mojo::Array<uint8_t> certificate_data, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 void OnSessionClosed(const std::string& session_id); | 91 void OnSessionClosed(const std::string& session_id); |
| 95 | 92 |
| 96 // Callback for when |decryptor_| loses connectivity. | 93 // Callback for when |decryptor_| loses connectivity. |
| 97 void OnDecryptorConnectionError(); | 94 void OnDecryptorConnectionError(); |
| 98 | 95 |
| 99 // CDM ID to be assigned to the next successfully initialized CDM. This ID is | 96 // CDM ID to be assigned to the next successfully initialized CDM. This ID is |
| 100 // unique per process. It will be used to locate the CDM by the media players | 97 // unique per process. It will be used to locate the CDM by the media players |
| 101 // living in the same process. | 98 // living in the same process. |
| 102 static int next_cdm_id_; | 99 static int next_cdm_id_; |
| 103 | 100 |
| 104 mojo::StrongBinding<mojom::ContentDecryptionModule> binding_; | |
| 105 base::WeakPtr<MojoCdmServiceContext> context_; | 101 base::WeakPtr<MojoCdmServiceContext> context_; |
| 106 | 102 |
| 107 CdmFactory* cdm_factory_; | 103 CdmFactory* cdm_factory_; |
| 108 scoped_refptr<MediaKeys> cdm_; | 104 scoped_refptr<MediaKeys> cdm_; |
| 109 | 105 |
| 110 std::unique_ptr<MojoDecryptorService> decryptor_; | 106 std::unique_ptr<MojoDecryptorService> decryptor_; |
| 111 | 107 |
| 112 // Set to a valid CDM ID if the |cdm_| is successfully created. | 108 // Set to a valid CDM ID if the |cdm_| is successfully created. |
| 113 int cdm_id_; | 109 int cdm_id_; |
| 114 | 110 |
| 115 mojom::ContentDecryptionModuleClientPtr client_; | 111 mojom::ContentDecryptionModuleClientPtr client_; |
| 116 | 112 |
| 117 base::WeakPtr<MojoCdmService> weak_this_; | 113 base::WeakPtr<MojoCdmService> weak_this_; |
| 118 base::WeakPtrFactory<MojoCdmService> weak_factory_; | 114 base::WeakPtrFactory<MojoCdmService> weak_factory_; |
| 119 | 115 |
| 120 DISALLOW_COPY_AND_ASSIGN(MojoCdmService); | 116 DISALLOW_COPY_AND_ASSIGN(MojoCdmService); |
| 121 }; | 117 }; |
| 122 | 118 |
| 123 } // namespace media | 119 } // namespace media |
| 124 | 120 |
| 125 #endif // MEDIA_MOJO_SERVICES_MOJO_CDM_SERVICE_H_ | 121 #endif // MEDIA_MOJO_SERVICES_MOJO_CDM_SERVICE_H_ |
| OLD | NEW |