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/content_decryption_module.h" |
17 #include "media/base/eme_constants.h" | 18 #include "media/base/eme_constants.h" |
18 #include "media/base/media_keys.h" | |
19 #include "media/mojo/interfaces/content_decryption_module.mojom.h" | 19 #include "media/mojo/interfaces/content_decryption_module.mojom.h" |
20 #include "media/mojo/services/media_mojo_export.h" | 20 #include "media/mojo/services/media_mojo_export.h" |
21 #include "media/mojo/services/mojo_cdm_promise.h" | 21 #include "media/mojo/services/mojo_cdm_promise.h" |
22 #include "media/mojo/services/mojo_cdm_service_context.h" | 22 #include "media/mojo/services/mojo_cdm_service_context.h" |
23 #include "media/mojo/services/mojo_decryptor_service.h" | 23 #include "media/mojo/services/mojo_decryptor_service.h" |
24 | 24 |
25 namespace media { | 25 namespace media { |
26 | 26 |
27 class CdmFactory; | 27 class CdmFactory; |
28 | 28 |
29 // A mojom::ContentDecryptionModule implementation backed by a | 29 // A mojom::ContentDecryptionModule implementation backed by a |
30 // media::MediaKeys. | 30 // media::ContentDecryptionModule. |
31 class MEDIA_MOJO_EXPORT MojoCdmService | 31 class MEDIA_MOJO_EXPORT MojoCdmService |
32 : NON_EXPORTED_BASE(public mojom::ContentDecryptionModule) { | 32 : NON_EXPORTED_BASE(public mojom::ContentDecryptionModule) { |
33 public: | 33 public: |
34 using SessionType = MediaKeys::SessionType; | 34 using SessionType = ::media::ContentDecryptionModule::SessionType; |
35 | 35 |
36 // Get the CDM associated with |cdm_id|, which is unique per process. | 36 // Get the CDM associated with |cdm_id|, which is unique per process. |
37 // Can be called on any thread. The returned CDM is not guaranteed to be | 37 // Can be called on any thread. The returned CDM is not guaranteed to be |
38 // thread safe. | 38 // thread safe. |
39 // Note: This provides a generic hack to get the CDM in the process where | 39 // Note: This provides a generic hack to get the CDM in the process where |
40 // MediaService is running, regardless of which render process or | 40 // MediaService is running, regardless of which render process or |
41 // render frame the caller is associated with. In the future, we should move | 41 // render frame the caller is associated with. In the future, we should move |
42 // all out-of-process media players into the MediaService so that we can use | 42 // all out-of-process media players into the MediaService so that we can use |
43 // MojoCdmServiceContext (per render frame) to get the CDM. | 43 // MojoCdmServiceContext (per render frame) to get the CDM. |
44 static scoped_refptr<MediaKeys> LegacyGetCdm(int cdm_id); | 44 static scoped_refptr<::media::ContentDecryptionModule> LegacyGetCdm( |
| 45 int cdm_id); |
45 | 46 |
46 // Constructs a MojoCdmService and strongly binds it to the |request|. | 47 // Constructs a MojoCdmService and strongly binds it to the |request|. |
47 MojoCdmService(base::WeakPtr<MojoCdmServiceContext> context, | 48 MojoCdmService(base::WeakPtr<MojoCdmServiceContext> context, |
48 CdmFactory* cdm_factory); | 49 CdmFactory* cdm_factory); |
49 | 50 |
50 ~MojoCdmService() final; | 51 ~MojoCdmService() final; |
51 | 52 |
52 // mojom::ContentDecryptionModule implementation. | 53 // mojom::ContentDecryptionModule implementation. |
53 void SetClient(mojom::ContentDecryptionModuleClientPtr client) final; | 54 void SetClient(mojom::ContentDecryptionModuleClientPtr client) final; |
54 void Initialize(const std::string& key_system, | 55 void Initialize(const std::string& key_system, |
(...skipping 12 matching lines...) Expand all Loading... |
67 const LoadSessionCallback& callback) final; | 68 const LoadSessionCallback& callback) final; |
68 void UpdateSession(const std::string& session_id, | 69 void UpdateSession(const std::string& session_id, |
69 const std::vector<uint8_t>& response, | 70 const std::vector<uint8_t>& response, |
70 const UpdateSessionCallback& callback) final; | 71 const UpdateSessionCallback& callback) final; |
71 void CloseSession(const std::string& session_id, | 72 void CloseSession(const std::string& session_id, |
72 const CloseSessionCallback& callback) final; | 73 const CloseSessionCallback& callback) final; |
73 void RemoveSession(const std::string& session_id, | 74 void RemoveSession(const std::string& session_id, |
74 const RemoveSessionCallback& callback) final; | 75 const RemoveSessionCallback& callback) final; |
75 | 76 |
76 // Get CDM to be used by the media pipeline. | 77 // Get CDM to be used by the media pipeline. |
77 scoped_refptr<MediaKeys> GetCdm(); | 78 scoped_refptr<::media::ContentDecryptionModule> GetCdm(); |
78 | 79 |
79 private: | 80 private: |
80 // Callback for CdmFactory::Create(). | 81 // Callback for CdmFactory::Create(). |
81 void OnCdmCreated(const InitializeCallback& callback, | 82 void OnCdmCreated(const InitializeCallback& callback, |
82 const scoped_refptr<MediaKeys>& cdm, | 83 const scoped_refptr<::media::ContentDecryptionModule>& cdm, |
83 const std::string& error_message); | 84 const std::string& error_message); |
84 | 85 |
85 // Callbacks for firing session events. | 86 // Callbacks for firing session events. |
86 void OnSessionMessage(const std::string& session_id, | 87 void OnSessionMessage( |
87 MediaKeys::MessageType message_type, | 88 const std::string& session_id, |
88 const std::vector<uint8_t>& message); | 89 ::media::ContentDecryptionModule::MessageType message_type, |
| 90 const std::vector<uint8_t>& message); |
89 void OnSessionKeysChange(const std::string& session_id, | 91 void OnSessionKeysChange(const std::string& session_id, |
90 bool has_additional_usable_key, | 92 bool has_additional_usable_key, |
91 CdmKeysInfo keys_info); | 93 CdmKeysInfo keys_info); |
92 void OnSessionExpirationUpdate(const std::string& session_id, | 94 void OnSessionExpirationUpdate(const std::string& session_id, |
93 base::Time new_expiry_time); | 95 base::Time new_expiry_time); |
94 void OnSessionClosed(const std::string& session_id); | 96 void OnSessionClosed(const std::string& session_id); |
95 | 97 |
96 // Callback for when |decryptor_| loses connectivity. | 98 // Callback for when |decryptor_| loses connectivity. |
97 void OnDecryptorConnectionError(); | 99 void OnDecryptorConnectionError(); |
98 | 100 |
99 // CDM ID to be assigned to the next successfully initialized CDM. This ID is | 101 // 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 | 102 // unique per process. It will be used to locate the CDM by the media players |
101 // living in the same process. | 103 // living in the same process. |
102 static int next_cdm_id_; | 104 static int next_cdm_id_; |
103 | 105 |
104 base::WeakPtr<MojoCdmServiceContext> context_; | 106 base::WeakPtr<MojoCdmServiceContext> context_; |
105 | 107 |
106 CdmFactory* cdm_factory_; | 108 CdmFactory* cdm_factory_; |
107 scoped_refptr<MediaKeys> cdm_; | 109 scoped_refptr<::media::ContentDecryptionModule> cdm_; |
108 | 110 |
109 std::unique_ptr<MojoDecryptorService> decryptor_; | 111 std::unique_ptr<MojoDecryptorService> decryptor_; |
110 | 112 |
111 // Set to a valid CDM ID if the |cdm_| is successfully created. | 113 // Set to a valid CDM ID if the |cdm_| is successfully created. |
112 int cdm_id_; | 114 int cdm_id_; |
113 | 115 |
114 mojom::ContentDecryptionModuleClientPtr client_; | 116 mojom::ContentDecryptionModuleClientPtr client_; |
115 | 117 |
116 base::WeakPtr<MojoCdmService> weak_this_; | 118 base::WeakPtr<MojoCdmService> weak_this_; |
117 base::WeakPtrFactory<MojoCdmService> weak_factory_; | 119 base::WeakPtrFactory<MojoCdmService> weak_factory_; |
118 | 120 |
119 DISALLOW_COPY_AND_ASSIGN(MojoCdmService); | 121 DISALLOW_COPY_AND_ASSIGN(MojoCdmService); |
120 }; | 122 }; |
121 | 123 |
122 } // namespace media | 124 } // namespace media |
123 | 125 |
124 #endif // MEDIA_MOJO_SERVICES_MOJO_CDM_SERVICE_H_ | 126 #endif // MEDIA_MOJO_SERVICES_MOJO_CDM_SERVICE_H_ |
OLD | NEW |