| 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 "media/mojo/services/mojo_cdm_promise.h" |
| 14 #include "mojo/application/public/interfaces/service_provider.mojom.h" | 15 #include "mojo/application/public/interfaces/service_provider.mojom.h" |
| 15 #include "mojo/public/cpp/bindings/strong_binding.h" | 16 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 16 | 17 |
| 17 namespace media { | 18 namespace media { |
| 18 | 19 |
| 20 class CdmFactory; |
| 19 class MojoCdmServiceContext; | 21 class MojoCdmServiceContext; |
| 20 | 22 |
| 21 // A mojo::ContentDecryptionModule implementation backed by a media::MediaKeys. | 23 // A mojo::ContentDecryptionModule implementation backed by a media::MediaKeys. |
| 22 class MojoCdmService : public mojo::ContentDecryptionModule { | 24 class MojoCdmService : public mojo::ContentDecryptionModule { |
| 23 public: | 25 public: |
| 24 // Constructs a MojoCdmService and strongly binds it to the |request|. | 26 // Constructs a MojoCdmService and strongly binds it to the |request|. |
| 25 MojoCdmService(MojoCdmServiceContext* context, | 27 MojoCdmService(MojoCdmServiceContext* context, |
| 26 mojo::ServiceProvider* service_provider, | 28 mojo::ServiceProvider* service_provider, |
| 29 CdmFactory* cdm_factory, |
| 27 mojo::InterfaceRequest<mojo::ContentDecryptionModule> request); | 30 mojo::InterfaceRequest<mojo::ContentDecryptionModule> request); |
| 28 | 31 |
| 29 ~MojoCdmService() final; | 32 ~MojoCdmService() final; |
| 30 | 33 |
| 31 // mojo::ContentDecryptionModule implementation. | 34 // mojo::ContentDecryptionModule implementation. |
| 32 void SetClient(mojo::ContentDecryptionModuleClientPtr client) final; | 35 void SetClient(mojo::ContentDecryptionModuleClientPtr client) final; |
| 33 void Initialize( | 36 void Initialize( |
| 34 const mojo::String& key_system, | 37 const mojo::String& key_system, |
| 35 const mojo::String& security_origin, | 38 const mojo::String& security_origin, |
| 36 int32_t cdm_id, | 39 int32_t cdm_id, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 57 const mojo::Callback<void(mojo::CdmPromiseResultPtr)>& callback) final; | 60 const mojo::Callback<void(mojo::CdmPromiseResultPtr)>& callback) final; |
| 58 void RemoveSession( | 61 void RemoveSession( |
| 59 const mojo::String& session_id, | 62 const mojo::String& session_id, |
| 60 const mojo::Callback<void(mojo::CdmPromiseResultPtr)>& callback) final; | 63 const mojo::Callback<void(mojo::CdmPromiseResultPtr)>& callback) final; |
| 61 void GetDecryptor(mojo::InterfaceRequest<mojo::Decryptor> decryptor) final; | 64 void GetDecryptor(mojo::InterfaceRequest<mojo::Decryptor> decryptor) final; |
| 62 | 65 |
| 63 // Get CdmContext to be used by the media pipeline. | 66 // Get CdmContext to be used by the media pipeline. |
| 64 CdmContext* GetCdmContext(); | 67 CdmContext* GetCdmContext(); |
| 65 | 68 |
| 66 private: | 69 private: |
| 70 // Callback for CdmFactory::Create(). |
| 71 void OnCdmCreated(int cdm_id, |
| 72 scoped_ptr<MojoCdmPromise<>> promise, |
| 73 scoped_ptr<MediaKeys> cdm, |
| 74 const std::string& error_message); |
| 75 |
| 67 // Callbacks for firing session events. | 76 // Callbacks for firing session events. |
| 68 void OnSessionMessage(const std::string& session_id, | 77 void OnSessionMessage(const std::string& session_id, |
| 69 MediaKeys::MessageType message_type, | 78 MediaKeys::MessageType message_type, |
| 70 const std::vector<uint8_t>& message, | 79 const std::vector<uint8_t>& message, |
| 71 const GURL& legacy_destination_url); | 80 const GURL& legacy_destination_url); |
| 72 void OnSessionKeysChange(const std::string& session_id, | 81 void OnSessionKeysChange(const std::string& session_id, |
| 73 bool has_additional_usable_key, | 82 bool has_additional_usable_key, |
| 74 CdmKeysInfo keys_info); | 83 CdmKeysInfo keys_info); |
| 75 void OnSessionExpirationUpdate(const std::string& session_id, | 84 void OnSessionExpirationUpdate(const std::string& session_id, |
| 76 const base::Time& new_expiry_time); | 85 const base::Time& new_expiry_time); |
| 77 void OnSessionClosed(const std::string& session_id); | 86 void OnSessionClosed(const std::string& session_id); |
| 78 void OnLegacySessionError(const std::string& session_id, | 87 void OnLegacySessionError(const std::string& session_id, |
| 79 MediaKeys::Exception exception, | 88 MediaKeys::Exception exception, |
| 80 uint32_t system_code, | 89 uint32_t system_code, |
| 81 const std::string& error_message); | 90 const std::string& error_message); |
| 82 | 91 |
| 83 mojo::StrongBinding<mojo::ContentDecryptionModule> binding_; | 92 mojo::StrongBinding<mojo::ContentDecryptionModule> binding_; |
| 84 MojoCdmServiceContext* context_; | 93 MojoCdmServiceContext* context_; |
| 85 mojo::ServiceProvider* service_provider_; | 94 mojo::ServiceProvider* service_provider_; |
| 95 CdmFactory* cdm_factory_; |
| 86 scoped_ptr<MediaKeys> cdm_; | 96 scoped_ptr<MediaKeys> cdm_; |
| 87 | 97 |
| 88 // Set to a valid CDM ID if the |cdm_| is successfully created. | 98 // Set to a valid CDM ID if the |cdm_| is successfully created. |
| 89 int cdm_id_; | 99 int cdm_id_; |
| 90 | 100 |
| 91 mojo::ContentDecryptionModuleClientPtr client_; | 101 mojo::ContentDecryptionModuleClientPtr client_; |
| 92 | 102 |
| 93 base::WeakPtr<MojoCdmService> weak_this_; | 103 base::WeakPtr<MojoCdmService> weak_this_; |
| 94 base::WeakPtrFactory<MojoCdmService> weak_factory_; | 104 base::WeakPtrFactory<MojoCdmService> weak_factory_; |
| 95 | 105 |
| 96 DISALLOW_COPY_AND_ASSIGN(MojoCdmService); | 106 DISALLOW_COPY_AND_ASSIGN(MojoCdmService); |
| 97 }; | 107 }; |
| 98 | 108 |
| 99 } // namespace media | 109 } // namespace media |
| 100 | 110 |
| 101 #endif // MEDIA_MOJO_SERVICES_MOJO_CDM_SERVICE_H_ | 111 #endif // MEDIA_MOJO_SERVICES_MOJO_CDM_SERVICE_H_ |
| OLD | NEW |