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