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/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
12 #include "media/base/media_keys.h" | 12 #include "media/base/media_keys.h" |
13 #include "media/mojo/interfaces/content_decryption_module.mojom.h" | 13 #include "media/mojo/interfaces/content_decryption_module.mojom.h" |
14 #include "third_party/mojo/src/mojo/public/cpp/bindings/strong_binding.h" | 14 #include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h" |
15 #include "third_party/mojo/src/mojo/public/cpp/bindings/error_handler.h" | |
15 | 16 |
16 namespace media { | 17 namespace media { |
17 | 18 |
19 class MojoCdmServiceContext; | |
20 | |
18 // A mojo::ContentDecryptionModule implementation backed by a media::MediaKeys. | 21 // A mojo::ContentDecryptionModule implementation backed by a media::MediaKeys. |
19 class MojoCdmService : public mojo::ContentDecryptionModule { | 22 class MojoCdmService : public mojo::ContentDecryptionModule, |
23 public mojo::ErrorHandler { | |
20 public: | 24 public: |
21 MojoCdmService(const mojo::String& key_system, | 25 // Creates MojoCdmService for |key_system|. Returns nullptr if |key_system| is |
22 mojo::InterfaceRequest<mojo::ContentDecryptionModule> request); | 26 // not supported. The returned object is owned by the |context| and will be |
27 // destructed when OnConnectionError() happens. | |
ddorwin
2015/06/08 18:33:10
nit: A function can be called but not "happen". A
xhwang
2015/06/08 22:12:33
Done.
| |
28 static MojoCdmService* Create( | |
29 MojoCdmServiceContext* context, | |
30 const mojo::String& key_system, | |
31 mojo::InterfaceRequest<mojo::ContentDecryptionModule> request); | |
32 | |
23 ~MojoCdmService() final; | 33 ~MojoCdmService() final; |
24 | 34 |
25 // mojo::ContentDecryptionModule implementation. | 35 // mojo::ContentDecryptionModule implementation. |
26 void SetClient(mojo::ContentDecryptionModuleClientPtr client) final; | 36 void SetClient(mojo::ContentDecryptionModuleClientPtr client) final; |
27 void SetServerCertificate( | 37 void SetServerCertificate( |
28 mojo::Array<uint8_t> certificate_data, | 38 mojo::Array<uint8_t> certificate_data, |
29 const mojo::Callback<void(mojo::CdmPromiseResultPtr)>& callback) final; | 39 const mojo::Callback<void(mojo::CdmPromiseResultPtr)>& callback) final; |
30 void CreateSessionAndGenerateRequest( | 40 void CreateSessionAndGenerateRequest( |
31 mojo::ContentDecryptionModule::SessionType session_type, | 41 mojo::ContentDecryptionModule::SessionType session_type, |
32 mojo::ContentDecryptionModule::InitDataType init_data_type, | 42 mojo::ContentDecryptionModule::InitDataType init_data_type, |
33 mojo::Array<uint8_t> init_data, | 43 mojo::Array<uint8_t> init_data, |
34 const mojo::Callback<void(mojo::CdmPromiseResultPtr, mojo::String)>& | 44 const mojo::Callback<void(mojo::CdmPromiseResultPtr, mojo::String)>& |
35 callback) final; | 45 callback) final; |
36 void LoadSession(mojo::ContentDecryptionModule::SessionType session_type, | 46 void LoadSession(mojo::ContentDecryptionModule::SessionType session_type, |
37 const mojo::String& session_id, | 47 const mojo::String& session_id, |
38 const mojo::Callback<void(mojo::CdmPromiseResultPtr, | 48 const mojo::Callback<void(mojo::CdmPromiseResultPtr, |
39 mojo::String)>& callback) final; | 49 mojo::String)>& callback) final; |
40 void UpdateSession( | 50 void UpdateSession( |
41 const mojo::String& session_id, | 51 const mojo::String& session_id, |
42 mojo::Array<uint8_t> response, | 52 mojo::Array<uint8_t> response, |
43 const mojo::Callback<void(mojo::CdmPromiseResultPtr)>& callback) final; | 53 const mojo::Callback<void(mojo::CdmPromiseResultPtr)>& callback) final; |
44 void CloseSession( | 54 void CloseSession( |
45 const mojo::String& session_id, | 55 const mojo::String& session_id, |
46 const mojo::Callback<void(mojo::CdmPromiseResultPtr)>& callback) final; | 56 const mojo::Callback<void(mojo::CdmPromiseResultPtr)>& callback) final; |
47 void RemoveSession( | 57 void RemoveSession( |
48 const mojo::String& session_id, | 58 const mojo::String& session_id, |
49 const mojo::Callback<void(mojo::CdmPromiseResultPtr)>& callback) final; | 59 const mojo::Callback<void(mojo::CdmPromiseResultPtr)>& callback) final; |
60 // TODO(xhwang): Rename this to GetDecryptor in the mojom interface. | |
ddorwin
2015/06/08 18:33:10
Is this going to be used for the desktop case only
xhwang
2015/06/08 22:12:33
Yes. I'll fix this TODO in the next CL.
| |
50 void GetCdmContext(int32_t cdm_id, | 61 void GetCdmContext(int32_t cdm_id, |
51 mojo::InterfaceRequest<mojo::Decryptor> decryptor) final; | 62 mojo::InterfaceRequest<mojo::Decryptor> decryptor) final; |
52 | 63 |
64 // Get CdmContext to be used by the media pipeline. | |
65 CdmContext* GetCdmContext(); | |
66 | |
53 private: | 67 private: |
68 MojoCdmService(MojoCdmServiceContext* context, | |
69 const mojo::String& key_system, | |
70 mojo::InterfaceRequest<mojo::ContentDecryptionModule> request); | |
71 | |
72 // mojo::ErrorHandler implementation. | |
73 void OnConnectionError() override; | |
74 | |
54 // Callbacks for firing session events. | 75 // Callbacks for firing session events. |
55 void OnSessionMessage(const std::string& session_id, | 76 void OnSessionMessage(const std::string& session_id, |
56 MediaKeys::MessageType message_type, | 77 MediaKeys::MessageType message_type, |
57 const std::vector<uint8_t>& message, | 78 const std::vector<uint8_t>& message, |
58 const GURL& legacy_destination_url); | 79 const GURL& legacy_destination_url); |
59 void OnSessionKeysChange(const std::string& session_id, | 80 void OnSessionKeysChange(const std::string& session_id, |
60 bool has_additional_usable_key, | 81 bool has_additional_usable_key, |
61 CdmKeysInfo keys_info); | 82 CdmKeysInfo keys_info); |
62 void OnSessionExpirationUpdate(const std::string& session_id, | 83 void OnSessionExpirationUpdate(const std::string& session_id, |
63 const base::Time& new_expiry_time); | 84 const base::Time& new_expiry_time); |
64 void OnSessionClosed(const std::string& session_id); | 85 void OnSessionClosed(const std::string& session_id); |
65 void OnLegacySessionError(const std::string& session_id, | 86 void OnLegacySessionError(const std::string& session_id, |
66 MediaKeys::Exception exception, | 87 MediaKeys::Exception exception, |
67 uint32_t system_code, | 88 uint32_t system_code, |
68 const std::string& error_message); | 89 const std::string& error_message); |
69 | 90 |
70 mojo::StrongBinding<mojo::ContentDecryptionModule> binding_; | 91 mojo::Binding<mojo::ContentDecryptionModule> binding_; |
71 | 92 |
93 MojoCdmServiceContext* context_; | |
72 scoped_ptr<MediaKeys> cdm_; | 94 scoped_ptr<MediaKeys> cdm_; |
73 | 95 |
74 mojo::ContentDecryptionModuleClientPtr client_; | 96 mojo::ContentDecryptionModuleClientPtr client_; |
75 | 97 |
76 base::WeakPtr<MojoCdmService> weak_this_; | 98 base::WeakPtr<MojoCdmService> weak_this_; |
77 base::WeakPtrFactory<MojoCdmService> weak_factory_; | 99 base::WeakPtrFactory<MojoCdmService> weak_factory_; |
78 | 100 |
79 DISALLOW_COPY_AND_ASSIGN(MojoCdmService); | 101 DISALLOW_COPY_AND_ASSIGN(MojoCdmService); |
80 }; | 102 }; |
81 | 103 |
82 } // namespace media | 104 } // namespace media |
83 | 105 |
84 #endif // MEDIA_MOJO_SERVICES_MOJO_CDM_SERVICE_H_ | 106 #endif // MEDIA_MOJO_SERVICES_MOJO_CDM_SERVICE_H_ |
OLD | NEW |