diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-06 12:48:11 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-13 09:33:43 +0000 |
commit | 7b5b123ac58f58ffde0f4f6e488bcd09aa4decd3 (patch) | |
tree | fa14ba0ca8d2683ba2efdabd246dc9b18a1229c6 /chromium/media/mojo | |
parent | 79b4f909db1049fca459c07cca55af56a9b54fe3 (diff) | |
download | qtwebengine-chromium-7b5b123ac58f58ffde0f4f6e488bcd09aa4decd3.tar.gz |
BASELINE: Update Chromium to 84.0.4147.141
Change-Id: Ib85eb4cfa1cbe2b2b81e5022c8cad5c493969535
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/media/mojo')
77 files changed, 622 insertions, 1883 deletions
diff --git a/chromium/media/mojo/BUILD.gn b/chromium/media/mojo/BUILD.gn index 4401902c5b4..7005cfbbb78 100644 --- a/chromium/media/mojo/BUILD.gn +++ b/chromium/media/mojo/BUILD.gn @@ -18,41 +18,32 @@ buildflag_header("buildflags") { enable_mojo_media_in_gpu_process = false enable_mojo_media_in_utility_process = false - if (!enable_mojo_media) { - assert(mojo_media_services == [], "Mojo media is not enabled") - assert(mojo_media_host == "none", "Mojo media is not enabled") - assert(!enable_test_mojo_media_client, "Mojo media is not enabled") - } else { - assert(mojo_media_services != [], "No mojo media service specified") - foreach(service, mojo_media_services) { - if (service == "renderer") { - enable_mojo_renderer = true - } else if (service == "cdm") { - enable_mojo_cdm = true - } else if (service == "audio_decoder") { - enable_mojo_audio_decoder = true - } else if (service == "video_decoder") { - enable_mojo_video_decoder = true - } else { - assert(false, "Invalid mojo media service: $service") - } - } - - if (mojo_media_host == "browser") { - enable_mojo_media_in_browser_process = true - } else if (mojo_media_host == "gpu") { - enable_mojo_media_in_gpu_process = true - } else if (mojo_media_host == "utility") { - enable_mojo_media_in_utility_process = true + foreach(service, mojo_media_services) { + if (service == "renderer") { + enable_mojo_renderer = true + } else if (service == "cdm") { + enable_mojo_cdm = true + } else if (service == "audio_decoder") { + enable_mojo_audio_decoder = true + } else if (service == "video_decoder") { + enable_mojo_video_decoder = true } else { - assert(false, "Invalid mojo media host: $mojo_media_host") + assert(false, "Invalid mojo media service: $service") } } + if (mojo_media_host == "browser") { + enable_mojo_media_in_browser_process = true + } else if (mojo_media_host == "gpu") { + enable_mojo_media_in_gpu_process = true + } else if (mojo_media_host == "utility") { + enable_mojo_media_in_utility_process = true + } else if (mojo_media_host != "") { + assert(false, "Invalid mojo media host: $mojo_media_host") + } + flags = [ "ENABLE_CAST_RENDERER=$enable_cast_renderer", - "ENABLE_MOJO_MEDIA=$enable_mojo_media", - "ENABLE_TEST_MOJO_MEDIA_CLIENT=$enable_test_mojo_media_client", "ENABLE_MOJO_RENDERER=$enable_mojo_renderer", "ENABLE_MOJO_CDM=$enable_mojo_cdm", "ENABLE_MOJO_AUDIO_DECODER=$enable_mojo_audio_decoder", diff --git a/chromium/media/mojo/README.md b/chromium/media/mojo/README.md index 8ed718d7198..d13dc2c607e 100644 --- a/chromium/media/mojo/README.md +++ b/chromium/media/mojo/README.md @@ -62,10 +62,8 @@ specify which remote media components you want to enable. For example, with the following gn arguments, the media pipeline will enable `MojoRenderer` and `MojoCdm`: ``` -enable_mojo_media = true mojo_media_services = ["renderer", "cdm"] ``` -Note that you must set `enable_mojo_media` first. ### Media Mojo Interface Factory @@ -320,11 +318,6 @@ local media components get services from content layer through the `MediaClient` interface. In `MediaService` and `CdmService`, remote media components get services from the through **secure auxiliary services**. -Note that as a `service_manager::Service`, `MediaService` and `CdmService` can -always connect to other `service_manager::Service` hosted by the service_manager -through the `Connector` interface. However, these are generic services that -doesn’t belong to any individual `RenderFrame`, or even user profile. - Some services do require `RenderFrame` or user profile identity, e.g. file system. Since media components all belong to a given `RenderFrame`, we must maintain the frame identity when accessing these services for security reasons. @@ -332,10 +325,12 @@ These services are called secure auxiliary services. `FrameServiceBase` is a base class for all secure auxiliary services to help manage the lifetime of these services (e.g. to handle navigation). -In `MediaInterfaceProxy`, when we request `media::mojom::InterfaceFactory` in -the `MediaService` or `CdmService`, we call `GetFrameServices()` to configure -which secure auxiliary services are exposed to the remote components over the -separate `blink::mojom::BrowserInterfaceBroker`. +When a `MediaInterfaceProxy` is created, in addition to providing the +`media::mojom::InterfaceFactory`, the `RenderFrame` is provisioned with a +`media::mojom::FrameInterfaceFactory` that exposes these secure auxiliary +services on a per-frame basis. The `FrameInterfaceFactory` directly provides +services from //content, and it provides a way for //content embedders to +register additional auxiliary services via the `BindEmbedderReceiver()` method. Currently only the remote CDM needs secure auxiliary services. This is a list of currently supported services: @@ -344,7 +339,6 @@ currently supported services: * `PlatformVerification`: to check whether the platform is secure * `CdmFileIO`: for the CDM to store persistent data * `ProvisionFetcher`: for Android MediaDrm device provisioning -* `CdmProxy`: (in progress) ### Security @@ -363,8 +357,7 @@ which process in production, see [Adoption](#Adoption) below. Also note that all the [Secure Auxiliary Services](#Secure-Auxiliary-Services) are running in a more privileged process than the process where the media components that use them run in. For example, all of the existing services run -in the browser process except for the `CdmProxy`, which runs in the GPU process. -They must defend against compromised media components. +in the browser process. They must defend against compromised media components. ### Adoption @@ -405,7 +398,6 @@ They must defend against compromised media components. * `MediaService` in the GPU process (registered in `GpuServiceFactory` with `GpuMojoMediaClient`) * `MojoVideoDecoder` + hardware video decoders such as D3D11VideoDecoder - * Provides `CdmProxy` to the `CdmService` ## Other Services diff --git a/chromium/media/mojo/clients/mojo_cdm.cc b/chromium/media/mojo/clients/mojo_cdm.cc index 1bd9ba9b9e9..acc9d1ca9de 100644 --- a/chromium/media/mojo/clients/mojo_cdm.cc +++ b/chromium/media/mojo/clients/mojo_cdm.cc @@ -21,7 +21,6 @@ #include "media/mojo/clients/mojo_decryptor.h" #include "media/mojo/common/media_type_converters.h" #include "media/mojo/mojom/decryptor.mojom.h" -#include "media/mojo/mojom/interface_factory.mojom.h" #include "services/service_manager/public/cpp/connect.h" #include "services/service_manager/public/mojom/interface_provider.mojom.h" #include "url/origin.h" @@ -43,15 +42,14 @@ void MojoCdm::Create( const url::Origin& security_origin, const CdmConfig& cdm_config, mojo::PendingRemote<mojom::ContentDecryptionModule> remote_cdm, - mojom::InterfaceFactory* interface_factory, const SessionMessageCB& session_message_cb, const SessionClosedCB& session_closed_cb, const SessionKeysChangeCB& session_keys_change_cb, const SessionExpirationUpdateCB& session_expiration_update_cb, CdmCreatedCB cdm_created_cb) { - scoped_refptr<MojoCdm> mojo_cdm(new MojoCdm( - std::move(remote_cdm), interface_factory, session_message_cb, - session_closed_cb, session_keys_change_cb, session_expiration_update_cb)); + scoped_refptr<MojoCdm> mojo_cdm( + new MojoCdm(std::move(remote_cdm), session_message_cb, session_closed_cb, + session_keys_change_cb, session_expiration_update_cb)); // |mojo_cdm| ownership is passed to the promise. auto promise = std::make_unique<CdmInitializedPromise>( @@ -62,13 +60,11 @@ void MojoCdm::Create( } MojoCdm::MojoCdm(mojo::PendingRemote<mojom::ContentDecryptionModule> remote_cdm, - mojom::InterfaceFactory* interface_factory, const SessionMessageCB& session_message_cb, const SessionClosedCB& session_closed_cb, const SessionKeysChangeCB& session_keys_change_cb, const SessionExpirationUpdateCB& session_expiration_update_cb) : remote_cdm_(std::move(remote_cdm)), - interface_factory_(interface_factory), cdm_id_(CdmContext::kInvalidCdmId), session_message_cb_(session_message_cb), session_closed_cb_(session_closed_cb), @@ -305,26 +301,12 @@ Decryptor* MojoCdm::GetDecryptor() { if (decryptor_) return decryptor_.get(); - mojo::PendingRemote<mojom::Decryptor> decryptor_remote; - // Can be called on a different thread. if (decryptor_remote_.is_valid()) { DVLOG(1) << __func__ << ": Using Decryptor exposed by the CDM directly"; - decryptor_remote = std::move(decryptor_remote_); - } else if (interface_factory_ && cdm_id_ != CdmContext::kInvalidCdmId) { -#if BUILDFLAG(ENABLE_CDM_PROXY) - // TODO(xhwang): Pass back info on whether Decryptor is supported by the - // remote CDM. - DVLOG(1) << __func__ << ": Using Decryptor associated with CDM ID " - << cdm_id_ << ", typically hosted by CdmProxy in MediaService"; - interface_factory_->CreateDecryptor( - cdm_id_, decryptor_remote.InitWithNewPipeAndPassReceiver()); -#endif // BUILDFLAG(ENABLE_CDM_PROXY) + decryptor_ = std::make_unique<MojoDecryptor>(std::move(decryptor_remote_)); } - if (decryptor_remote) - decryptor_ = std::make_unique<MojoDecryptor>(std::move(decryptor_remote)); - return decryptor_.get(); } diff --git a/chromium/media/mojo/clients/mojo_cdm.h b/chromium/media/mojo/clients/mojo_cdm.h index 4c1a0ffbeff..45f0fcb09f1 100644 --- a/chromium/media/mojo/clients/mojo_cdm.h +++ b/chromium/media/mojo/clients/mojo_cdm.h @@ -35,10 +35,6 @@ class Origin; namespace media { -namespace mojom { -class InterfaceFactory; -} - class MojoDecryptor; // A ContentDecryptionModule that proxies to a mojom::ContentDecryptionModule. @@ -55,7 +51,6 @@ class MojoCdm : public ContentDecryptionModule, const url::Origin& security_origin, const CdmConfig& cdm_config, mojo::PendingRemote<mojom::ContentDecryptionModule> remote_cdm, - mojom::InterfaceFactory* interface_factory, const SessionMessageCB& session_message_cb, const SessionClosedCB& session_closed_cb, const SessionKeysChangeCB& session_keys_change_cb, @@ -91,7 +86,6 @@ class MojoCdm : public ContentDecryptionModule, private: MojoCdm(mojo::PendingRemote<mojom::ContentDecryptionModule> remote_cdm, - mojom::InterfaceFactory* interface_factory, const SessionMessageCB& session_message_cb, const SessionClosedCB& session_closed_cb, const SessionKeysChangeCB& session_keys_change_cb, @@ -140,7 +134,6 @@ class MojoCdm : public ContentDecryptionModule, THREAD_CHECKER(thread_checker_); mojo::Remote<mojom::ContentDecryptionModule> remote_cdm_; - mojom::InterfaceFactory* interface_factory_; mojo::AssociatedReceiver<ContentDecryptionModuleClient> client_receiver_{ this}; diff --git a/chromium/media/mojo/clients/mojo_cdm_factory.cc b/chromium/media/mojo/clients/mojo_cdm_factory.cc index 118f0abd01f..d606e735eb1 100644 --- a/chromium/media/mojo/clients/mojo_cdm_factory.cc +++ b/chromium/media/mojo/clients/mojo_cdm_factory.cc @@ -64,8 +64,8 @@ void MojoCdmFactory::Create( key_system, cdm_pending_remote.InitWithNewPipeAndPassReceiver()); MojoCdm::Create(key_system, security_origin, cdm_config, - std::move(cdm_pending_remote), interface_factory_, - session_message_cb, session_closed_cb, session_keys_change_cb, + std::move(cdm_pending_remote), session_message_cb, + session_closed_cb, session_keys_change_cb, session_expiration_update_cb, std::move(cdm_created_cb)); } diff --git a/chromium/media/mojo/clients/mojo_cdm_unittest.cc b/chromium/media/mojo/clients/mojo_cdm_unittest.cc index ab0eb09b91d..f7b402b4f54 100644 --- a/chromium/media/mojo/clients/mojo_cdm_unittest.cc +++ b/chromium/media/mojo/clients/mojo_cdm_unittest.cc @@ -99,7 +99,6 @@ class MojoCdmTest : public ::testing::Test { MojoCdm::Create(key_system, url::Origin::Create(GURL(kTestSecurityOrigin)), CdmConfig(), cdm_receiver_.BindNewPipeAndPassRemote(), - nullptr, base::Bind(&MockCdmClient::OnSessionMessage, base::Unretained(&cdm_client_)), base::Bind(&MockCdmClient::OnSessionClosed, diff --git a/chromium/media/mojo/mojom/BUILD.gn b/chromium/media/mojo/mojom/BUILD.gn index 10940dcef80..f86298e18d2 100644 --- a/chromium/media/mojo/mojom/BUILD.gn +++ b/chromium/media/mojo/mojom/BUILD.gn @@ -23,6 +23,7 @@ mojom("mojom") { "decryptor.mojom", "demuxer_stream.mojom", "display_media_information.mojom", + "frame_interface_factory.mojom", "interface_factory.mojom", "key_system_support.mojom", "media_log.mojom", @@ -31,10 +32,10 @@ mojom("mojom") { "media_types.mojom", "output_protection.mojom", "platform_verification.mojom", + "playback_events_recorder.mojom", "provision_fetcher.mojom", "renderer.mojom", "renderer_extensions.mojom", - "soda_service.mojom", "video_decode_perf_history.mojom", "video_decode_stats_recorder.mojom", "video_decoder.mojom", @@ -49,6 +50,8 @@ mojom("mojom") { if (is_android) { sources += [ "android_overlay.mojom" ] + } else { + sources += [ "speech_recognition_service.mojom" ] } if (is_chromecast) { @@ -76,11 +79,6 @@ mojom("mojom") { enabled_features = [ "enable_cast_renderer" ] } - if (enable_cdm_proxy) { - enabled_features = [ "enable_cdm_proxy" ] - sources += [ "cdm_proxy.mojom" ] - } - export_class_attribute_blink = "BLINK_PLATFORM_EXPORT" export_define_blink = "BLINK_PLATFORM_IMPLEMENTATION=1" export_header_blink = "third_party/blink/public/platform/web_common.h" @@ -115,7 +113,7 @@ source_set("unit_tests") { "audio_decoder_config_mojom_traits_unittest.cc", "cdm_key_information_mojom_traits_unittest.cc", "video_decoder_config_mojom_traits_unittest.cc", - "video_encoder_info_mojom_traits_unittest.cc", + "video_encode_accelerator_mojom_traits_unittest.cc", "video_frame_mojom_traits_unittest.cc", ] diff --git a/chromium/media/mojo/mojom/audio_output_stream.mojom b/chromium/media/mojo/mojom/audio_output_stream.mojom index 8e7077e9401..68ed6e7db47 100644 --- a/chromium/media/mojo/mojom/audio_output_stream.mojom +++ b/chromium/media/mojo/mojom/audio_output_stream.mojom @@ -75,8 +75,7 @@ interface AudioOutputStreamProvider { // output streams that are related during audio processing. // This method fails if it is called more than once. Acquire(AudioParameters params, - pending_remote<AudioOutputStreamProviderClient> client, - mojo_base.mojom.UnguessableToken? processing_id); + pending_remote<AudioOutputStreamProviderClient> client); }; interface AudioOutputStreamProviderClient { diff --git a/chromium/media/mojo/mojom/cdm_key_information_mojom_traits.cc b/chromium/media/mojo/mojom/cdm_key_information_mojom_traits.cc index 94a09fef5b2..e3b2182b4e9 100644 --- a/chromium/media/mojo/mojom/cdm_key_information_mojom_traits.cc +++ b/chromium/media/mojo/mojom/cdm_key_information_mojom_traits.cc @@ -4,7 +4,7 @@ #include "media/mojo/mojom/cdm_key_information_mojom_traits.h" -#include "base/logging.h" +#include "base/notreached.h" namespace mojo { diff --git a/chromium/media/mojo/mojom/cdm_proxy.mojom b/chromium/media/mojo/mojom/cdm_proxy.mojom deleted file mode 100644 index d5037632b77..00000000000 --- a/chromium/media/mojo/mojom/cdm_proxy.mojom +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -module media.mojom; - -// An interface that helps proxy part of ContentDecryptionModule (CDM) -// functionalities to a different entity, e.g. hardware CDM modules. -// In general, the interpretation of the method and callback parameters are -// protocol dependent. -// CdmProxy implementation is hosted in the GPU process. -interface CdmProxy { - // See media/cdm/cdm_proxy.h for the following native enums. - [Native] - enum Status; - - [Native] - enum Protocol; - - [Native] - enum Function; - - [Native] - enum KeyType; - - // Initializes the proxy. - // If the proxy created a crypto session, then the ID for the crypto session - // is |crypto_session_id|. - // |cdm_id| can be used to connect the remote media pipeline and CdmProxy. - Initialize(pending_associated_remote<CdmProxyClient> client) - => (Status status, - Protocol protocol, - uint32 crypto_session_id, - int32 cdm_id); - - // Processes and updates the state of the proxy. - // |func| specifies what type of function to use. - // |crypto_session_id| is a value returned from Initialize() or - // CreateMediaCryptoSessions(). - // |input_data| is the input data to be processed. - // |output_data_size| is the expected size of |output_data|. Some protocols - // require this field in order to determine the size of the output, but some - // may completely ignore it. - // The output data is passed back in |output_data|. - Process(Function func, - uint32 crypto_session_id, - array<uint8> input_data, - uint32 output_data_size) => (Status status, - array<uint8> output_data); - - // Creates a crypto session for handling media. - // If extra data has to be passed to further setup the media crypto session, - // pass the data as |input_data|. - // |crypto_session_id| is the ID for the crypto session. - // |output_data| is extra value, if any. - CreateMediaCryptoSession(array<uint8> input_data) => ( - Status status, uint32 crypto_session_id, uint64 output_data); - - // Sets a key in the proxy. - // |crypto_session_id| is the crypto session for decryption. - // |key_id| is the ID of the key. - // |key_blob| is the opaque key blob for decrypting or decoding. - SetKey(uint32 crypto_session_id, array<uint8> key_id, KeyType key_type, - array<uint8> key_blob) => (Status status); - - // Removes a key from the proxy. - // |crypto_session_id| is the crypto session for decryption. - // |key_id| is the ID of the key. - RemoveKey(uint32 crypto_session_id, array<uint8> key_id) => (Status status); -}; - -// Client of CdmProxy. -// CdmProxyClient is running in the fully sandboxed CDM (e.g. utility) process. -interface CdmProxyClient { - // Notifies the client that there has been a hardware reset. - NotifyHardwareReset(); -}; diff --git a/chromium/media/mojo/mojom/cdm_proxy.typemap b/chromium/media/mojo/mojom/cdm_proxy.typemap deleted file mode 100644 index d2f05392218..00000000000 --- a/chromium/media/mojo/mojom/cdm_proxy.typemap +++ /dev/null @@ -1,21 +0,0 @@ -# Copyright 2017 The Chromium Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -mojom = "//media/mojo/mojom/cdm_proxy.mojom" - -public_headers = [ "//media/cdm/cdm_proxy.h" ] - -traits_headers = [ "//media/base/ipc/media_param_traits_macros.h" ] - -deps = [ - "//media", - "//media/base/ipc", -] - -type_mappings = [ - "media.mojom.CdmProxy.Function=::media::CdmProxy::Function", - "media.mojom.CdmProxy.KeyType=::media::CdmProxy::KeyType", - "media.mojom.CdmProxy.Protocol=::media::CdmProxy::Protocol", - "media.mojom.CdmProxy.Status=::media::CdmProxy::Status", -] diff --git a/chromium/media/mojo/mojom/cdm_service.mojom b/chromium/media/mojo/mojom/cdm_service.mojom index a5402a788fa..e154033021c 100644 --- a/chromium/media/mojo/mojom/cdm_service.mojom +++ b/chromium/media/mojo/mojom/cdm_service.mojom @@ -5,6 +5,7 @@ module media.mojom; import "media/mojo/mojom/content_decryption_module.mojom"; +import "media/mojo/mojom/frame_interface_factory.mojom"; import "mojo/public/mojom/base/file_path.mojom"; import "services/service_manager/public/mojom/interface_provider.mojom"; @@ -28,11 +29,12 @@ interface CdmService { [EnableIf=is_mac] pending_remote<SeatbeltExtensionTokenProvider>? token_provider); - // Requests an CdmFactory. |host_interfaces| can optionally be used to provide - // interfaces hosted by the caller to the remote CdmFactory implementation. + // Requests an CdmFactory. |frame_interfaces| can optionally be used to + // provide interfaces hosted by the caller to the remote CdmFactory + // implementation. CreateCdmFactory( pending_receiver<CdmFactory> factory, - pending_remote<service_manager.mojom.InterfaceProvider> host_interfaces); + pending_remote<FrameInterfaceFactory> frame_interfaces); }; // An interface to provide a sandbox seatbelt extension token synchronously. diff --git a/chromium/media/mojo/mojom/frame_interface_factory.mojom b/chromium/media/mojo/mojom/frame_interface_factory.mojom new file mode 100644 index 00000000000..49a153bd05f --- /dev/null +++ b/chromium/media/mojo/mojom/frame_interface_factory.mojom @@ -0,0 +1,24 @@ +// Copyright 2020 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +module media.mojom; + +import "media/mojo/mojom/cdm_storage.mojom"; +import "media/mojo/mojom/provision_fetcher.mojom"; +import "mojo/public/mojom/base/generic_pending_receiver.mojom"; + +// A factory for acquiring media mojo interfaces that are bound to a +// RenderFrameHost. +interface FrameInterfaceFactory { + // Binds the ProvisionFetcher for the frame. + CreateProvisionFetcher(pending_receiver<ProvisionFetcher> provision_fetcher); + + // Binds the CdmStorage for the frame. This requires that the frame have + // CDM storage available. + CreateCdmStorage(pending_receiver<CdmStorage> cdm_storage); + + // Binds a generic media frame-bound interface. This is to allow //content + // embedders to provide additional interfaces. + BindEmbedderReceiver(mojo_base.mojom.GenericPendingReceiver receiver); +}; diff --git a/chromium/media/mojo/mojom/interface_factory.mojom b/chromium/media/mojo/mojom/interface_factory.mojom index 8cea7ee2d35..7215013dfa0 100644 --- a/chromium/media/mojo/mojom/interface_factory.mojom +++ b/chromium/media/mojo/mojom/interface_factory.mojom @@ -5,8 +5,6 @@ module media.mojom; import "media/mojo/mojom/audio_decoder.mojom"; -[EnableIf=enable_cdm_proxy] -import "media/mojo/mojom/cdm_proxy.mojom"; import "media/mojo/mojom/decryptor.mojom"; import "media/mojo/mojom/content_decryption_module.mojom"; import "media/mojo/mojom/renderer.mojom"; @@ -63,14 +61,4 @@ interface InterfaceFactory { // this call may be initiated by an untrusted process (e.g. renderer), so the // implementation must fully validate |key_system| before creating the CDM. CreateCdm(string key_system, pending_receiver<ContentDecryptionModule> cdm); - - // Creates a Decryptor associated with the |cdm_id|. - CreateDecryptor(int32 cdm_id, pending_receiver<Decryptor> decryptor); - - // Creates a CdmProxy that proxies part of CDM functionalities to a different - // entity, e.g. hardware CDM modules. The created |cdm_proxy| must match the - // type of the CDM, identified by |cdm_guid|. - [EnableIf=enable_cdm_proxy] - CreateCdmProxy(mojo_base.mojom.Token cdm_guid, - pending_receiver<CdmProxy> cdm_proxy); }; diff --git a/chromium/media/mojo/mojom/key_system_support.mojom b/chromium/media/mojo/mojom/key_system_support.mojom index 06ede1b0ee1..69d608ca7d5 100644 --- a/chromium/media/mojo/mojom/key_system_support.mojom +++ b/chromium/media/mojo/mojom/key_system_support.mojom @@ -16,8 +16,7 @@ struct KeySystemCapability { bool supports_vp9_profile2; array<EncryptionScheme> encryption_schemes; - // Hardware secure codecs and encryption schemes supported by the CDM, - // directly or indirectly through CdmProxy. + // Hardware secure codecs and encryption schemes supported by the CDM. array<VideoCodec> hw_secure_video_codecs; array<EncryptionScheme> hw_secure_encryption_schemes; diff --git a/chromium/media/mojo/mojom/media_metrics_provider.mojom b/chromium/media/mojo/mojom/media_metrics_provider.mojom index bb9ad8db7e4..526e2b17018 100644 --- a/chromium/media/mojo/mojom/media_metrics_provider.mojom +++ b/chromium/media/mojo/mojom/media_metrics_provider.mojom @@ -7,6 +7,7 @@ module media.mojom; import "media/learning/mojo/public/mojom/learning_task_controller.mojom"; import "media/mojo/mojom/media_types.mojom"; import "media/mojo/mojom/video_decode_stats_recorder.mojom"; +import "media/mojo/mojom/playback_events_recorder.mojom"; import "media/mojo/mojom/watch_time_recorder.mojom"; import "mojo/public/mojom/base/time.mojom"; import "ui/gfx/geometry/mojom/geometry.mojom"; @@ -64,8 +65,13 @@ interface MediaMetricsProvider { // Returns a LearningTaskController for the given |taskName|. AcquireLearningTaskController( - string taskName, - pending_receiver<media.learning.mojom.LearningTaskController> controller); + string taskName, + pending_receiver<media.learning.mojom.LearningTaskController> controller); + + // Returns a PlaybackEventsRecorder instance. Implementation may drop the + // |receiver| if it's not interested in recording playback events. + AcquirePlaybackEventsRecorder( + pending_receiver<PlaybackEventsRecorder> receiver); // Can be called multiple times to set properties about a playback. SetHasAudio(AudioCodec codec); diff --git a/chromium/media/mojo/mojom/media_service.mojom b/chromium/media/mojo/mojom/media_service.mojom index 995e6c55d98..738b54a72c7 100644 --- a/chromium/media/mojo/mojom/media_service.mojom +++ b/chromium/media/mojo/mojom/media_service.mojom @@ -4,18 +4,18 @@ module media.mojom; +import "media/mojo/mojom/frame_interface_factory.mojom"; import "media/mojo/mojom/interface_factory.mojom"; -import "services/service_manager/public/mojom/interface_provider.mojom"; // A service to provide media InterfaceFactory, typically to the media pipeline // running in the renderer process. The service itself runs in the process // specified by the |mojo_media_host| gn build flag. The service is always // connected from the browser process. interface MediaService { - // Requests an InterfaceFactory. |host_interfaces| can optionally be used to + // Requests an InterfaceFactory. |frame_interfaces| can optionally be used to // provide interfaces hosted by the caller to the remote InterfaceFactory // implementation. CreateInterfaceFactory( pending_receiver<InterfaceFactory> factory, - pending_remote<service_manager.mojom.InterfaceProvider> host_interfaces); + pending_remote<FrameInterfaceFactory> frame_interfaces); }; diff --git a/chromium/media/mojo/mojom/media_types.mojom b/chromium/media/mojo/mojom/media_types.mojom index 06f95f16679..6b083bfe691 100644 --- a/chromium/media/mojo/mojom/media_types.mojom +++ b/chromium/media/mojo/mojom/media_types.mojom @@ -279,6 +279,7 @@ struct VideoFrame { mojo_base.mojom.DictionaryValue metadata; gfx.mojom.ColorSpace color_space; + HDRMetadata? hdr_metadata; }; // Possible choices for storing VideoFrame data. diff --git a/chromium/media/mojo/mojom/playback_events_recorder.mojom b/chromium/media/mojo/mojom/playback_events_recorder.mojom new file mode 100644 index 00000000000..4971c776c16 --- /dev/null +++ b/chromium/media/mojo/mojom/playback_events_recorder.mojom @@ -0,0 +1,45 @@ +// Copyright 2020 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +module media.mojom; + +import "media/mojo/mojom/media_types.mojom"; +import "ui/gfx/geometry/mojom/geometry.mojom"; + +// PlaybackEventsRecorder allows to observe and record events occurring in the +// media pipeline. The interface is called by the renderer process (in +// blink::WebMediaPlayerImpl), while the implementation normally runs in the +// browser. +interface PlaybackEventsRecorder { + // Called when player has been started or resumed. + OnPlaying(); + + // Called when player has been paused. + OnPaused(); + + // Called when player position is being changed. + OnSeeking(); + + // Called when the player has reached the end of the current file. + OnEnded(); + + // Called when playback has failed due to the specified error. + OnError(PipelineStatus status); + + // Called when playback has been suspended while buffering the media. + OnBuffering(); + + // Called after media buffering has completed. The player is in buffering + // state after the following events until this method is called: + // 1. Player initialized (i.e. after PlaybackEventsRecorder is created). + // 2. Seek operation, see OnSeeking(). + // 3. Buffering started, see OnBuffering(). + OnBufferingComplete(); + + // Called when video playback starts and every time video resolution changes. + OnNaturalSizeChanged(gfx.mojom.Size size); + + // Called periodically (e.g. every second) while playback is active. + OnPipelineStatistics(PipelineStatistics stats); +}; diff --git a/chromium/media/mojo/mojom/soda_service.mojom b/chromium/media/mojo/mojom/soda_service.mojom deleted file mode 100644 index eb9057a32db..00000000000 --- a/chromium/media/mojo/mojom/soda_service.mojom +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -module media.mojom; - -import "media/mojo/mojom/media_types.mojom"; - -// The main interface a client uses to interact with a SODA service -// process. Every renderer can own one or more Remote<SodaContext>, -// with the receiver bound through the BrowserInterfaceBroker. -interface SodaContext { - // Bind the recognizers to the SODA service. - BindRecognizer(pending_receiver<SodaRecognizer> receiver, - pending_remote<SodaRecognizerClient> client); -}; - -// The main interface to a Speech On-Device API (SODA) service process. -// Used by the browser to issue top-level control requests to the service, -// acquired during process launch. -interface SodaService { - // Bind the SODA context to a new instance of SODA. - BindContext(pending_receiver<SodaContext> context); -}; - -// The interface used to pass raw audio from the renderer to the SODA -// service. The remote lives in the renderer process and the receiver -// lives in the SODA process. -interface SodaRecognizer { - // Initialize the SODA instance. SODA will use the SODA recognition client - // to return the recognition events containing the transcribed audio back - // to the originating media. - SendAudioToSoda(AudioDataS16 buffer); -}; - -// The interface used to return speech recognition events from the SODA -// service back to the originating media. The remote lives in the SODA -// process and the receiver lives in the renderer process. -interface SodaRecognizerClient { - // Triggered by SODA on a speech recognition event. - OnSodaRecognitionEvent(string transcription); -}; diff --git a/chromium/media/mojo/mojom/speech_recognition_service.mojom b/chromium/media/mojo/mojom/speech_recognition_service.mojom new file mode 100644 index 00000000000..6835c22c5ce --- /dev/null +++ b/chromium/media/mojo/mojom/speech_recognition_service.mojom @@ -0,0 +1,50 @@ +// Copyright 2020 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +module media.mojom; + +import "media/mojo/mojom/media_types.mojom"; + +// The main interface a client uses to interact with a speech recognition +// service process. Every renderer can own one or more +// Remote<SpeechRecognitionContext>, with the receiver bound through the +// BrowserInterfaceBroker. +interface SpeechRecognitionContext { + // Bind the recognizers to the speech recognition service. + BindRecognizer(pending_receiver<SpeechRecognitionRecognizer> receiver, + pending_remote<SpeechRecognitionRecognizerClient> client); +}; + +// The main interface to a speech secognition service process. +// Used by the browser to issue top-level control requests to the service, +// acquired during process launch. +interface SpeechRecognitionService { + // Bind the context to a new instance of the speech recognition. + BindContext(pending_receiver<SpeechRecognitionContext> context); +}; + +// The interface used to pass raw audio from the renderer to the speech +// recognition service. The remote lives in the renderer process and the +// receiver lives in the speech recognition process. +interface SpeechRecognitionRecognizer { + // Initialize the speech recognition instance. The speech recognition client + // will return the recognition events containing the transcribed audio back + // to the originating media. + SendAudioToSpeechRecognitionService(AudioDataS16 buffer); +}; + +// The interface used to return speech recognition events from the speech +// recognition service back to the originating media. The remote lives in the +// speech recognition process and the receiver lives in the renderer process. +interface SpeechRecognitionRecognizerClient { + // Triggered by speech recognition process on a speech recognition event. + OnSpeechRecognitionRecognitionEvent(SpeechRecognitionResult result); +}; + +// A speech recognition result created by the speech service and passed to the +// renderer. +struct SpeechRecognitionResult { + string transcription; + bool is_final; +}; diff --git a/chromium/media/mojo/mojom/typemaps.gni b/chromium/media/mojo/mojom/typemaps.gni index 8e5ef00405d..44e4010102d 100644 --- a/chromium/media/mojo/mojom/typemaps.gni +++ b/chromium/media/mojo/mojom/typemaps.gni @@ -27,7 +27,3 @@ typemaps = [ if (enable_media_drm_storage) { typemaps += [ "//media/mojo/mojom/media_drm_storage.typemap" ] } - -if (enable_cdm_proxy) { - typemaps += [ "//media/mojo/mojom/cdm_proxy.typemap" ] -} diff --git a/chromium/media/mojo/mojom/video_encode_accelerator.mojom b/chromium/media/mojo/mojom/video_encode_accelerator.mojom index b1baa0fd9d4..2bab244c42d 100644 --- a/chromium/media/mojo/mojom/video_encode_accelerator.mojom +++ b/chromium/media/mojo/mojom/video_encode_accelerator.mojom @@ -61,6 +61,17 @@ struct VideoBitrateAllocation { }; // This defines a mojo transport format for +// media::VideoEncodeAccelerator::Config::SpatialLayer. +struct SpatialLayer { + int32 width; + int32 height; + uint32 bitrate_bps; + uint32 framerate; + uint8 max_qp; + uint8 num_of_temporal_layers; +}; + +// This defines a mojo transport format for // media::VideoEncodeAccelerator::Config. struct VideoEncodeAcceleratorConfig { // See media::VideoEncodeAccelerator::Config::ContentType @@ -88,6 +99,7 @@ struct VideoEncodeAcceleratorConfig { StorageType storage_type; bool has_storage_type; // Whether or not config has storage type config ContentType content_type; + array<SpatialLayer> spatial_layers; }; interface VideoEncodeAccelerator { diff --git a/chromium/media/mojo/mojom/video_encode_accelerator.typemap b/chromium/media/mojo/mojom/video_encode_accelerator.typemap index 0f1caea7bf8..be2bfda9985 100644 --- a/chromium/media/mojo/mojom/video_encode_accelerator.typemap +++ b/chromium/media/mojo/mojom/video_encode_accelerator.typemap @@ -31,6 +31,7 @@ type_mappings = [ "media.mojom.VideoBitrateAllocation=::media::VideoBitrateAllocation", "media.mojom.VideoEncodeAccelerator.Error=::media::VideoEncodeAccelerator::Error", "media.mojom.VideoEncodeAcceleratorConfig=::media::VideoEncodeAccelerator::Config", + "media.mojom.SpatialLayer=::media::VideoEncodeAccelerator::Config::SpatialLayer", "media.mojom.VideoEncodeAcceleratorSupportedProfile=::media::VideoEncodeAccelerator::SupportedProfile", "media.mojom.Vp8Metadata=::media::Vp8Metadata", ] diff --git a/chromium/media/mojo/mojom/video_encode_accelerator_mojom_traits.cc b/chromium/media/mojo/mojom/video_encode_accelerator_mojom_traits.cc index 1d3b11b22a3..1a64d95d376 100644 --- a/chromium/media/mojo/mojom/video_encode_accelerator_mojom_traits.cc +++ b/chromium/media/mojo/mojom/video_encode_accelerator_mojom_traits.cc @@ -4,7 +4,7 @@ #include "media/mojo/mojom/video_encode_accelerator_mojom_traits.h" -#include "base/logging.h" +#include "base/notreached.h" #include "base/optional.h" #include "media/base/video_bitrate_allocation.h" #include "mojo/public/cpp/base/time_mojom_traits.h" @@ -196,6 +196,20 @@ bool EnumTraits<media::mojom::VideoEncodeAcceleratorConfig::ContentType, } // static +bool StructTraits<media::mojom::SpatialLayerDataView, + media::VideoEncodeAccelerator::Config::SpatialLayer>:: + Read(media::mojom::SpatialLayerDataView input, + media::VideoEncodeAccelerator::Config::SpatialLayer* output) { + output->width = input.width(); + output->height = input.height(); + output->bitrate_bps = input.bitrate_bps(); + output->framerate = input.framerate(); + output->max_qp = input.max_qp(); + output->num_of_temporal_layers = input.num_of_temporal_layers(); + return true; +} + +// static bool StructTraits<media::mojom::VideoEncodeAcceleratorConfigDataView, media::VideoEncodeAccelerator::Config>:: Read(media::mojom::VideoEncodeAcceleratorConfigDataView input, @@ -235,10 +249,15 @@ bool StructTraits<media::mojom::VideoEncodeAcceleratorConfigDataView, if (!input.ReadContentType(&content_type)) return false; + std::vector<media::VideoEncodeAccelerator::Config::SpatialLayer> + spatial_layers; + if (!input.ReadSpatialLayers(&spatial_layers)) + return false; + *output = media::VideoEncodeAccelerator::Config( input_format, input_visible_size, output_profile, input.initial_bitrate(), initial_framerate, gop_length, h264_output_level, storage_type, - content_type); + content_type, spatial_layers); return true; } diff --git a/chromium/media/mojo/mojom/video_encode_accelerator_mojom_traits.h b/chromium/media/mojo/mojom/video_encode_accelerator_mojom_traits.h index 6b1a5546ec8..eebc8813801 100644 --- a/chromium/media/mojo/mojom/video_encode_accelerator_mojom_traits.h +++ b/chromium/media/mojo/mojom/video_encode_accelerator_mojom_traits.h @@ -132,6 +132,43 @@ struct EnumTraits<media::mojom::VideoEncodeAcceleratorConfig::ContentType, }; template <> +struct StructTraits<media::mojom::SpatialLayerDataView, + media::VideoEncodeAccelerator::Config::SpatialLayer> { + static int32_t width( + const media::VideoEncodeAccelerator::Config::SpatialLayer& input) { + return input.width; + } + + static int32_t height( + const media::VideoEncodeAccelerator::Config::SpatialLayer& input) { + return input.height; + } + + static uint32_t bitrate_bps( + const media::VideoEncodeAccelerator::Config::SpatialLayer& input) { + return input.bitrate_bps; + } + + static uint32_t framerate( + const media::VideoEncodeAccelerator::Config::SpatialLayer& input) { + return input.framerate; + } + + static uint8_t max_qp( + const media::VideoEncodeAccelerator::Config::SpatialLayer& input) { + return input.max_qp; + } + + static uint8_t num_of_temporal_layers( + const media::VideoEncodeAccelerator::Config::SpatialLayer& input) { + return input.num_of_temporal_layers; + } + + static bool Read(media::mojom::SpatialLayerDataView input, + media::VideoEncodeAccelerator::Config::SpatialLayer* output); +}; + +template <> struct StructTraits<media::mojom::VideoEncodeAcceleratorConfigDataView, media::VideoEncodeAccelerator::Config> { static media::VideoPixelFormat input_format( @@ -200,6 +237,11 @@ struct StructTraits<media::mojom::VideoEncodeAcceleratorConfigDataView, return input.content_type; } + static const std::vector<media::VideoEncodeAccelerator::Config::SpatialLayer>& + spatial_layers(const media::VideoEncodeAccelerator::Config& input) { + return input.spatial_layers; + } + static bool Read(media::mojom::VideoEncodeAcceleratorConfigDataView input, media::VideoEncodeAccelerator::Config* output); }; diff --git a/chromium/media/mojo/mojom/video_encode_accelerator_mojom_traits_unittest.cc b/chromium/media/mojo/mojom/video_encode_accelerator_mojom_traits_unittest.cc new file mode 100644 index 00000000000..cfd516058b6 --- /dev/null +++ b/chromium/media/mojo/mojom/video_encode_accelerator_mojom_traits_unittest.cc @@ -0,0 +1,156 @@ +// Copyright 2019 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "media/mojo/mojom/video_encode_accelerator_mojom_traits.h" +#include "media/mojo/mojom/video_encoder_info_mojom_traits.h" + +#include "media/video/video_encode_accelerator.h" +#include "media/video/video_encoder_info.h" +#include "mojo/public/cpp/test_support/test_utils.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace media { + +// These binary operators are implemented here because they are used in this +// unittest. They cannot be enclosed by anonymous namespace, because they must +// be visible by gtest in linking. +bool operator==(const ::media::ScalingSettings& l, + const ::media::ScalingSettings& r) { + return l.min_qp == r.min_qp && l.max_qp == r.max_qp; +} + +bool operator!=(const ::media::ScalingSettings& l, + const ::media::ScalingSettings& r) { + return !(l == r); +} + +bool operator==(const ::media::ResolutionBitrateLimit& l, + const ::media::ResolutionBitrateLimit& r) { + return (l.frame_size == r.frame_size && + l.min_start_bitrate_bps == r.min_start_bitrate_bps && + l.min_bitrate_bps == r.min_bitrate_bps && + l.max_bitrate_bps == r.max_bitrate_bps); +} + +bool operator!=(const ::media::ResolutionBitrateLimit& l, + const ::media::ResolutionBitrateLimit& r) { + return !(l == r); +} + +bool operator==(const ::media::VideoEncoderInfo& l, + const ::media::VideoEncoderInfo& r) { + if (l.implementation_name != r.implementation_name) + return false; + if (l.supports_native_handle != r.supports_native_handle) + return false; + if (l.has_trusted_rate_controller != r.has_trusted_rate_controller) + return false; + if (l.is_hardware_accelerated != r.is_hardware_accelerated) + return false; + if (l.supports_simulcast != r.supports_simulcast) + return false; + if (l.scaling_settings != r.scaling_settings) + return false; + for (size_t i = 0; i < ::media::VideoEncoderInfo::kMaxSpatialLayers; ++i) { + if (l.fps_allocation[i] != r.fps_allocation[i]) + return false; + } + if (l.resolution_bitrate_limits != r.resolution_bitrate_limits) + return false; + return true; +} + +bool operator==( + const ::media::VideoEncodeAccelerator::Config::SpatialLayer& l, + const ::media::VideoEncodeAccelerator::Config::SpatialLayer& r) { + return (l.width == r.width && l.height == r.height && + l.bitrate_bps == r.bitrate_bps && l.framerate == r.framerate && + l.max_qp == r.max_qp && + l.num_of_temporal_layers == r.num_of_temporal_layers); +} + +bool operator==(const ::media::VideoEncodeAccelerator::Config& l, + const ::media::VideoEncodeAccelerator::Config& r) { + return l.input_format == r.input_format && + l.input_visible_size == r.input_visible_size && + l.output_profile == r.output_profile && + l.initial_bitrate == r.initial_bitrate && + l.initial_framerate == r.initial_framerate && + l.gop_length == r.gop_length && + l.h264_output_level == r.h264_output_level && + l.storage_type == r.storage_type && l.content_type == r.content_type && + l.spatial_layers == r.spatial_layers; +} + +TEST(VideoEncoderInfoStructTraitTest, RoundTrip) { + ::media::VideoEncoderInfo input; + input.implementation_name = "FakeVideoEncodeAccelerator"; + // Scaling settings. + input.scaling_settings = ::media::ScalingSettings(12, 123); + // FPS allocation. + for (size_t i = 0; i < ::media::VideoEncoderInfo::kMaxSpatialLayers; ++i) + input.fps_allocation[i] = {5, 5, 10}; + // Resolution bitrate limits. + input.resolution_bitrate_limits.push_back(::media::ResolutionBitrateLimit( + gfx::Size(123, 456), 123456, 123456, 789012)); + input.resolution_bitrate_limits.push_back(::media::ResolutionBitrateLimit( + gfx::Size(789, 1234), 1234567, 1234567, 7890123)); + // Other bool values. + input.supports_native_handle = true; + input.has_trusted_rate_controller = true; + input.is_hardware_accelerated = true; + input.supports_simulcast = true; + + ::media::VideoEncoderInfo output = input; + ASSERT_TRUE(mojo::test::SerializeAndDeserialize<mojom::VideoEncoderInfo>( + &input, &output)); + EXPECT_EQ(input, output); +} + +TEST(SpatialLayerStructTraitTest, RoundTrip) { + ::media::VideoEncodeAccelerator::Config::SpatialLayer input_spatial_layer; + input_spatial_layer.width = 320; + input_spatial_layer.width = 180; + input_spatial_layer.bitrate_bps = 12345678u; + input_spatial_layer.framerate = 24u; + input_spatial_layer.max_qp = 30u; + input_spatial_layer.num_of_temporal_layers = 3u; + ::media::VideoEncodeAccelerator::Config::SpatialLayer output_spatial_layer; + ASSERT_TRUE(mojo::test::SerializeAndDeserialize<mojom::SpatialLayer>( + &input_spatial_layer, &output_spatial_layer)); + EXPECT_EQ(input_spatial_layer, output_spatial_layer); +} + +TEST(VideoEncodeAcceleratorConfigStructTraitTest, RoundTrip) { + std::vector<::media::VideoEncodeAccelerator::Config::SpatialLayer> + input_spatial_layers(3); + gfx::Size kBaseSize(320, 180); + uint32_t kBaseBitrateBps = 123456u; + uint32_t kBaseFramerate = 24u; + for (size_t i = 0; i < input_spatial_layers.size(); ++i) { + input_spatial_layers[i].width = + static_cast<int32_t>(kBaseSize.width() * (i + 1)); + input_spatial_layers[i].height = + static_cast<int32_t>(kBaseSize.height() * (i + 1)); + input_spatial_layers[i].bitrate_bps = kBaseBitrateBps * (i + 1) / 2; + input_spatial_layers[i].framerate = kBaseFramerate * 2 / (i + 1); + input_spatial_layers[i].max_qp = 30 * (i + 1) / 2; + input_spatial_layers[i].num_of_temporal_layers = 3 - i; + } + ::media::VideoEncodeAccelerator::Config input_config( + ::media::PIXEL_FORMAT_NV12, kBaseSize, ::media::VP9PROFILE_PROFILE0, + kBaseBitrateBps, kBaseFramerate, base::nullopt, base::nullopt, + ::media::VideoEncodeAccelerator::Config::StorageType::kDmabuf, + ::media::VideoEncodeAccelerator::Config::ContentType::kCamera, + input_spatial_layers); + DVLOG(4) << input_config.AsHumanReadableString(); + + ::media::VideoEncodeAccelerator::Config output_config{}; + ASSERT_TRUE( + mojo::test::SerializeAndDeserialize<mojom::VideoEncodeAcceleratorConfig>( + &input_config, &output_config)); + DVLOG(4) << output_config.AsHumanReadableString(); + EXPECT_EQ(input_config, output_config); +} +} // namespace media diff --git a/chromium/media/mojo/mojom/video_encoder_info.mojom b/chromium/media/mojo/mojom/video_encoder_info.mojom index e02bead05ae..a299ca7f84e 100644 --- a/chromium/media/mojo/mojom/video_encoder_info.mojom +++ b/chromium/media/mojo/mojom/video_encoder_info.mojom @@ -26,7 +26,7 @@ struct VideoEncoderInfo { bool is_hardware_accelerated; bool supports_simulcast; - ScalingSettings scaling_settings; + ScalingSettings? scaling_settings; // This array size is equal to media::VideoEncoderInfo::kMaxSpatialLayers. array<array<uint8>, 5> fps_allocation; array<ResolutionBitrateLimit> resolution_bitrate_limits; diff --git a/chromium/media/mojo/mojom/video_encoder_info_mojom_traits.h b/chromium/media/mojo/mojom/video_encoder_info_mojom_traits.h index be13d828f3e..7489a2489c8 100644 --- a/chromium/media/mojo/mojom/video_encoder_info_mojom_traits.h +++ b/chromium/media/mojo/mojom/video_encoder_info_mojom_traits.h @@ -75,7 +75,7 @@ class StructTraits<media::mojom::VideoEncoderInfoDataView, const media::VideoEncoderInfo& video_encoder_info) { return video_encoder_info.supports_simulcast; } - static const media::ScalingSettings& scaling_settings( + static const base::Optional<media::ScalingSettings>& scaling_settings( const media::VideoEncoderInfo& video_encoder_info) { return video_encoder_info.scaling_settings; } diff --git a/chromium/media/mojo/mojom/video_encoder_info_mojom_traits_unittest.cc b/chromium/media/mojo/mojom/video_encoder_info_mojom_traits_unittest.cc deleted file mode 100644 index 455ac3bd893..00000000000 --- a/chromium/media/mojo/mojom/video_encoder_info_mojom_traits_unittest.cc +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "media/mojo/mojom/video_encoder_info_mojom_traits.h" - -#include "media/video/video_encoder_info.h" - -#include "mojo/public/cpp/test_support/test_utils.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace media { - -// These binary operators are implemented here because they are used in this -// unittest. They cannot be enclosed by anonymous namespace, because they must -// be visible by gtest in linking. -bool operator==(const ::media::ScalingSettings& l, - const ::media::ScalingSettings& r) { - return l.min_qp == r.min_qp && l.max_qp == r.max_qp; -} - -bool operator!=(const ::media::ScalingSettings& l, - const ::media::ScalingSettings& r) { - return !(l == r); -} - -bool operator==(const ::media::ResolutionBitrateLimit& l, - const ::media::ResolutionBitrateLimit& r) { - return (l.frame_size == r.frame_size && - l.min_start_bitrate_bps == r.min_start_bitrate_bps && - l.min_bitrate_bps == r.min_bitrate_bps && - l.max_bitrate_bps == r.max_bitrate_bps); -} - -bool operator!=(const ::media::ResolutionBitrateLimit& l, - const ::media::ResolutionBitrateLimit& r) { - return !(l == r); -} - -bool operator==(const ::media::VideoEncoderInfo& l, - const ::media::VideoEncoderInfo& r) { - if (l.implementation_name != r.implementation_name) - return false; - if (l.supports_native_handle != r.supports_native_handle) - return false; - if (l.has_trusted_rate_controller != r.has_trusted_rate_controller) - return false; - if (l.is_hardware_accelerated != r.is_hardware_accelerated) - return false; - if (l.supports_simulcast != r.supports_simulcast) - return false; - if (l.scaling_settings != r.scaling_settings) - return false; - for (size_t i = 0; i < ::media::VideoEncoderInfo::kMaxSpatialLayers; ++i) { - if (l.fps_allocation[i] != r.fps_allocation[i]) - return false; - } - if (l.resolution_bitrate_limits != r.resolution_bitrate_limits) - return false; - return true; -} - -TEST(VideoEncoderInfoStructTraitTest, RoundTrip) { - ::media::VideoEncoderInfo input; - input.implementation_name = "FakeVideoEncodeAccelerator"; - // Scaling settings. - input.scaling_settings.min_qp = 12; - input.scaling_settings.max_qp = 123; - // FPS allocation. - for (size_t i = 0; i < ::media::VideoEncoderInfo::kMaxSpatialLayers; ++i) - input.fps_allocation[i] = {5, 5, 10}; - // Resolution bitrate limits. - input.resolution_bitrate_limits.push_back(::media::ResolutionBitrateLimit( - gfx::Size(123, 456), 123456, 123456, 789012)); - input.resolution_bitrate_limits.push_back(::media::ResolutionBitrateLimit( - gfx::Size(789, 1234), 1234567, 1234567, 7890123)); - // Other bool values. - input.supports_native_handle = true; - input.has_trusted_rate_controller = true; - input.is_hardware_accelerated = true; - input.supports_simulcast = true; - - ::media::VideoEncoderInfo output = input; - ASSERT_TRUE(mojo::test::SerializeAndDeserialize<mojom::VideoEncoderInfo>( - &input, &output)); - EXPECT_EQ(input, output); -} -} // namespace media diff --git a/chromium/media/mojo/mojom/video_frame_mojom_traits.cc b/chromium/media/mojo/mojom/video_frame_mojom_traits.cc index 464be5dd0cf..b2c93afe712 100644 --- a/chromium/media/mojo/mojom/video_frame_mojom_traits.cc +++ b/chromium/media/mojo/mojom/video_frame_mojom_traits.cc @@ -14,6 +14,7 @@ #include "media/base/color_plane_layout.h" #include "media/base/format_utils.h" #include "media/mojo/common/mojo_shared_buffer_video_frame.h" +#include "media/mojo/mojom/hdr_metadata_mojom_traits.h" #include "mojo/public/cpp/base/time_mojom_traits.h" #include "mojo/public/cpp/base/values_mojom_traits.h" #include "mojo/public/cpp/system/handle.h" @@ -285,6 +286,11 @@ bool StructTraits<media::mojom::VideoFrameDataView, return false; frame->set_color_space(color_space); + base::Optional<media::HDRMetadata> hdr_metadata; + if (!input.ReadHdrMetadata(&hdr_metadata)) + return false; + frame->set_hdr_metadata(std::move(hdr_metadata)); + *output = std::move(frame); return true; } diff --git a/chromium/media/mojo/mojom/video_frame_mojom_traits.h b/chromium/media/mojo/mojom/video_frame_mojom_traits.h index 196243b4817..c064e76b79a 100644 --- a/chromium/media/mojo/mojom/video_frame_mojom_traits.h +++ b/chromium/media/mojo/mojom/video_frame_mojom_traits.h @@ -62,6 +62,11 @@ struct StructTraits<media::mojom::VideoFrameDataView, return input->ColorSpace(); } + static const base::Optional<media::HDRMetadata>& hdr_metadata( + const scoped_refptr<media::VideoFrame>& input) { + return input->hdr_metadata(); + } + static const base::Optional<gpu::VulkanYCbCrInfo>& ycbcr_info( const scoped_refptr<media::VideoFrame>& input) { return input->ycbcr_info(); diff --git a/chromium/media/mojo/services/BUILD.gn b/chromium/media/mojo/services/BUILD.gn index 89d10b71f40..3f39a35e113 100644 --- a/chromium/media/mojo/services/BUILD.gn +++ b/chromium/media/mojo/services/BUILD.gn @@ -15,8 +15,6 @@ jumbo_component("services") { "gpu_mojo_media_client.h", "interface_factory_impl.cc", "interface_factory_impl.h", - "media_interface_provider.cc", - "media_interface_provider.h", "media_metrics_provider.cc", "media_metrics_provider.h", "media_mojo_export.h", @@ -111,6 +109,10 @@ jumbo_component("services") { ] } + if (is_fuchsia) { + deps += [ "//media/fuchsia/metrics" ] + } + if (enable_media_drm_storage) { sources += [ "mojo_media_drm_storage.cc", @@ -134,19 +136,6 @@ jumbo_component("services") { "//media/cdm:cdm_paths", ] - if (enable_cdm_proxy) { - sources += [ - "mojo_cdm_proxy.cc", - "mojo_cdm_proxy.h", - "mojo_cdm_proxy_service.cc", - "mojo_cdm_proxy_service.h", - ] - deps += [ - # Needed by test_mojo_media_client.cc to create ClearKeyCdmProxy. - "//media/cdm/library_cdm/clear_key_cdm:clear_key_cdm_proxy", - ] - } - # TODO(xhwang): Ideally media should not worry about sandbox. Find a way to # remove this dependency. if (is_mac) { @@ -202,10 +191,6 @@ source_set("unit_tests") { "mojo_cdm_helper_unittest.cc", ] - if (enable_cdm_proxy) { - sources += [ "mojo_cdm_proxy_unittest.cc" ] - } - deps += [ "//media/cdm:cdm_api" ] } diff --git a/chromium/media/mojo/services/android_mojo_media_client.cc b/chromium/media/mojo/services/android_mojo_media_client.cc index aae7227cafb..fee056b790f 100644 --- a/chromium/media/mojo/services/android_mojo_media_client.cc +++ b/chromium/media/mojo/services/android_mojo_media_client.cc @@ -34,16 +34,16 @@ std::unique_ptr<AudioDecoder> AndroidMojoMediaClient::CreateAudioDecoder( } std::unique_ptr<CdmFactory> AndroidMojoMediaClient::CreateCdmFactory( - service_manager::mojom::InterfaceProvider* host_interfaces) { - if (!host_interfaces) { + mojom::FrameInterfaceFactory* frame_interfaces) { + if (!frame_interfaces) { NOTREACHED() << "Host interfaces should be provided when using CDM with " << "AndroidMojoMediaClient"; return nullptr; } return std::make_unique<AndroidCdmFactory>( - base::BindRepeating(&CreateProvisionFetcher, host_interfaces), - base::BindRepeating(&CreateMediaDrmStorage, host_interfaces)); + base::BindRepeating(&CreateProvisionFetcher, frame_interfaces), + base::BindRepeating(&CreateMediaDrmStorage, frame_interfaces)); } } // namespace media diff --git a/chromium/media/mojo/services/android_mojo_media_client.h b/chromium/media/mojo/services/android_mojo_media_client.h index 346a7081648..4ab6dc31782 100644 --- a/chromium/media/mojo/services/android_mojo_media_client.h +++ b/chromium/media/mojo/services/android_mojo_media_client.h @@ -23,7 +23,7 @@ class AndroidMojoMediaClient : public MojoMediaClient { scoped_refptr<base::SingleThreadTaskRunner> task_runner) final; std::unique_ptr<CdmFactory> CreateCdmFactory( - service_manager::mojom::InterfaceProvider* host_interfaces) final; + mojom::FrameInterfaceFactory* frame_interfaces) final; private: DISALLOW_COPY_AND_ASSIGN(AndroidMojoMediaClient); diff --git a/chromium/media/mojo/services/android_mojo_util.cc b/chromium/media/mojo/services/android_mojo_util.cc index 6b5a31e43fb..f91415e62a8 100644 --- a/chromium/media/mojo/services/android_mojo_util.cc +++ b/chromium/media/mojo/services/android_mojo_util.cc @@ -6,28 +6,25 @@ #include "media/mojo/services/mojo_media_drm_storage.h" #include "mojo/public/cpp/bindings/pending_remote.h" -#include "services/service_manager/public/mojom/interface_provider.mojom.h" namespace media { namespace android_mojo_util { std::unique_ptr<ProvisionFetcher> CreateProvisionFetcher( - service_manager::mojom::InterfaceProvider* host_interfaces) { - DCHECK(host_interfaces); + media::mojom::FrameInterfaceFactory* frame_interfaces) { + DCHECK(frame_interfaces); mojo::PendingRemote<mojom::ProvisionFetcher> provision_fetcher; - host_interfaces->GetInterface( - mojom::ProvisionFetcher::Name_, - provision_fetcher.InitWithNewPipeAndPassReceiver().PassPipe()); + frame_interfaces->CreateProvisionFetcher( + provision_fetcher.InitWithNewPipeAndPassReceiver()); return std::make_unique<MojoProvisionFetcher>(std::move(provision_fetcher)); } std::unique_ptr<MediaDrmStorage> CreateMediaDrmStorage( - service_manager::mojom::InterfaceProvider* host_interfaces) { - DCHECK(host_interfaces); + media::mojom::FrameInterfaceFactory* frame_interfaces) { + DCHECK(frame_interfaces); mojo::PendingRemote<mojom::MediaDrmStorage> media_drm_storage; - host_interfaces->GetInterface( - mojom::MediaDrmStorage::Name_, - media_drm_storage.InitWithNewPipeAndPassReceiver().PassPipe()); + frame_interfaces->BindEmbedderReceiver(mojo::GenericPendingReceiver( + media_drm_storage.InitWithNewPipeAndPassReceiver())); return std::make_unique<MojoMediaDrmStorage>(std::move(media_drm_storage)); } diff --git a/chromium/media/mojo/services/android_mojo_util.h b/chromium/media/mojo/services/android_mojo_util.h index 62f17839c18..3a41f51e251 100644 --- a/chromium/media/mojo/services/android_mojo_util.h +++ b/chromium/media/mojo/services/android_mojo_util.h @@ -7,25 +7,18 @@ #include <memory> +#include "media/mojo/mojom/frame_interface_factory.mojom.h" #include "media/mojo/services/mojo_media_drm_storage.h" #include "media/mojo/services/mojo_provision_fetcher.h" -namespace service_manager { -namespace mojom { - -class InterfaceProvider; - -} // namespace mojom -} // namespace service_manager - namespace media { namespace android_mojo_util { std::unique_ptr<ProvisionFetcher> CreateProvisionFetcher( - service_manager::mojom::InterfaceProvider* host_interfaces); + media::mojom::FrameInterfaceFactory* frame_interfaces); std::unique_ptr<MediaDrmStorage> CreateMediaDrmStorage( - service_manager::mojom::InterfaceProvider* host_interfaces); + media::mojom::FrameInterfaceFactory* frame_interfaces); } // namespace android_mojo_util } // namespace media diff --git a/chromium/media/mojo/services/cdm_service.cc b/chromium/media/mojo/services/cdm_service.cc index 06a61b8a1e8..7601bfdfda4 100644 --- a/chromium/media/mojo/services/cdm_service.cc +++ b/chromium/media/mojo/services/cdm_service.cc @@ -41,9 +41,8 @@ namespace { // details. class CdmFactoryImpl : public DeferredDestroy<mojom::CdmFactory> { public: - CdmFactoryImpl( - CdmService::Client* client, - mojo::PendingRemote<service_manager::mojom::InterfaceProvider> interfaces) + CdmFactoryImpl(CdmService::Client* client, + mojo::PendingRemote<mojom::FrameInterfaceFactory> interfaces) : client_(client), interfaces_(std::move(interfaces)) { DVLOG(1) << __func__; @@ -99,7 +98,7 @@ class CdmFactoryImpl : public DeferredDestroy<mojom::CdmFactory> { MojoCdmServiceContext cdm_service_context_; CdmService::Client* client_; - mojo::Remote<service_manager::mojom::InterfaceProvider> interfaces_; + mojo::Remote<mojom::FrameInterfaceFactory> interfaces_; mojo::UniqueReceiverSet<mojom::ContentDecryptionModule> cdm_receivers_; std::unique_ptr<media::CdmFactory> cdm_factory_; base::OnceClosure destroy_cb_; @@ -183,15 +182,14 @@ void CdmService::LoadCdm(const base::FilePath& cdm_path) { void CdmService::CreateCdmFactory( mojo::PendingReceiver<mojom::CdmFactory> receiver, - mojo::PendingRemote<service_manager::mojom::InterfaceProvider> - host_interfaces) { + mojo::PendingRemote<mojom::FrameInterfaceFactory> frame_interfaces) { // Ignore receiver if service has already stopped. if (!client_) return; cdm_factory_receivers_.AddReceiver( std::make_unique<CdmFactoryImpl>(client_.get(), - std::move(host_interfaces)), + std::move(frame_interfaces)), std::move(receiver)); } diff --git a/chromium/media/mojo/services/cdm_service.h b/chromium/media/mojo/services/cdm_service.h index 23f683b33f2..f85cb1af521 100644 --- a/chromium/media/mojo/services/cdm_service.h +++ b/chromium/media/mojo/services/cdm_service.h @@ -12,12 +12,12 @@ #include "media/media_buildflags.h" #include "media/mojo/mojom/cdm_service.mojom.h" #include "media/mojo/mojom/content_decryption_module.mojom.h" +#include "media/mojo/mojom/frame_interface_factory.mojom.h" #include "media/mojo/services/deferred_destroy_unique_receiver_set.h" #include "media/mojo/services/media_mojo_export.h" #include "mojo/public/cpp/bindings/pending_receiver.h" #include "mojo/public/cpp/bindings/pending_remote.h" #include "mojo/public/cpp/bindings/receiver.h" -#include "services/service_manager/public/mojom/interface_provider.mojom.h" #if BUILDFLAG(ENABLE_CDM_HOST_VERIFICATION) #include "media/cdm/cdm_host_file.h" @@ -37,11 +37,11 @@ class MEDIA_MOJO_EXPORT CdmService : public mojom::CdmService { // be a no-op if the process is already sandboxed. virtual void EnsureSandboxed() = 0; - // Returns the CdmFactory to be used by MojoCdmService. |host_interfaces| + // Returns the CdmFactory to be used by MojoCdmService. |frame_interfaces| // can be used to request interfaces provided remotely by the host. It may // be a nullptr if the host chose not to bind the InterfacePtr. virtual std::unique_ptr<CdmFactory> CreateCdmFactory( - service_manager::mojom::InterfaceProvider* host_interfaces) = 0; + mojom::FrameInterfaceFactory* frame_interfaces) = 0; #if BUILDFLAG(ENABLE_CDM_HOST_VERIFICATION) // Gets a list of CDM host file paths and put them in |cdm_host_file_paths|. @@ -73,8 +73,7 @@ class MEDIA_MOJO_EXPORT CdmService : public mojom::CdmService { #endif // defined(OS_MACOSX) void CreateCdmFactory( mojo::PendingReceiver<mojom::CdmFactory> receiver, - mojo::PendingRemote<service_manager::mojom::InterfaceProvider> - host_interfaces) final; + mojo::PendingRemote<mojom::FrameInterfaceFactory> frame_interfaces) final; mojo::Receiver<mojom::CdmService> receiver_; std::unique_ptr<Client> client_; diff --git a/chromium/media/mojo/services/cdm_service_unittest.cc b/chromium/media/mojo/services/cdm_service_unittest.cc index 3190e5d3e1b..02aec3d22e6 100644 --- a/chromium/media/mojo/services/cdm_service_unittest.cc +++ b/chromium/media/mojo/services/cdm_service_unittest.cc @@ -12,7 +12,6 @@ #include "media/cdm/default_cdm_factory.h" #include "media/media_buildflags.h" #include "media/mojo/services/cdm_service.h" -#include "media/mojo/services/media_interface_provider.h" #include "mojo/public/cpp/bindings/pending_remote.h" #include "mojo/public/cpp/bindings/remote.h" #include "testing/gmock/include/gmock/gmock.h" @@ -45,7 +44,7 @@ class MockCdmServiceClient : public media::CdmService::Client { MOCK_METHOD0(EnsureSandboxed, void()); std::unique_ptr<media::CdmFactory> CreateCdmFactory( - service_manager::mojom::InterfaceProvider* host_interfaces) override { + mojom::FrameInterfaceFactory* frame_interfaces) override { return std::make_unique<media::DefaultCdmFactory>(); } @@ -74,9 +73,8 @@ class CdmServiceTest : public testing::Test { base::TimeDelta(), base::BindRepeating(&CdmServiceTest::CdmServiceIdle, base::Unretained(this))); - mojo::PendingRemote<service_manager::mojom::InterfaceProvider> interfaces; - auto provider = std::make_unique<MediaInterfaceProvider>( - interfaces.InitWithNewPipeAndPassReceiver()); + mojo::PendingRemote<mojom::FrameInterfaceFactory> interfaces; + ignore_result(interfaces.InitWithNewPipeAndPassReceiver()); ASSERT_FALSE(cdm_factory_remote_); cdm_service_remote_->CreateCdmFactory( diff --git a/chromium/media/mojo/services/gpu_mojo_media_client.cc b/chromium/media/mojo/services/gpu_mojo_media_client.cc index 5074b4350a0..293591767dc 100644 --- a/chromium/media/mojo/services/gpu_mojo_media_client.cc +++ b/chromium/media/mojo/services/gpu_mojo_media_client.cc @@ -42,6 +42,7 @@ #if defined(OS_WIN) #include "media/gpu/windows/d3d11_video_decoder.h" +#include "ui/gl/direct_composition_surface_win.h" #include "ui/gl/gl_angle_util_win.h" #endif // defined(OS_WIN) @@ -117,18 +118,18 @@ GpuMojoMediaClient::GpuMojoMediaClient( scoped_refptr<base::SingleThreadTaskRunner> gpu_task_runner, base::WeakPtr<MediaGpuChannelManager> media_gpu_channel_manager, gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory, - AndroidOverlayMojoFactoryCB android_overlay_factory_cb, - CdmProxyFactoryCB cdm_proxy_factory_cb) + AndroidOverlayMojoFactoryCB android_overlay_factory_cb) : gpu_preferences_(gpu_preferences), gpu_workarounds_(gpu_workarounds), gpu_feature_info_(gpu_feature_info), gpu_task_runner_(std::move(gpu_task_runner)), media_gpu_channel_manager_(std::move(media_gpu_channel_manager)), - android_overlay_factory_cb_(std::move(android_overlay_factory_cb)), + android_overlay_factory_cb_(std::move(android_overlay_factory_cb)) #if BUILDFLAG(USE_CHROMEOS_MEDIA_ACCELERATION) - gpu_memory_buffer_factory_(gpu_memory_buffer_factory), + , + gpu_memory_buffer_factory_(gpu_memory_buffer_factory) #endif // BUILDFLAG(USE_CHROMEOS_MEDIA_ACCELERATION) - cdm_proxy_factory_cb_(std::move(cdm_proxy_factory_cb)) { +{ } GpuMojoMediaClient::~GpuMojoMediaClient() = default; @@ -240,8 +241,8 @@ std::unique_ptr<VideoDecoder> GpuMojoMediaClient::CreateVideoDecoder( // ignored. If we can tell that here, then VideoFrameFactory can use it // as a signal about whether it's supposed to get YCbCrInfo rather than // requiring the provider to set |is_vulkan| in the ImageRecord. - auto ycbcr_helper = - YCbCrHelper::Create(gpu_task_runner_, std::move(get_stub_cb)); + auto frame_info_helper = + FrameInfoHelper::Create(gpu_task_runner_, std::move(get_stub_cb)); video_decoder = std::make_unique<MediaCodecVideoDecoder>( gpu_preferences_, gpu_feature_info_, media_log->Clone(), DeviceInfo::GetInstance(), @@ -252,7 +253,7 @@ std::unique_ptr<VideoDecoder> GpuMojoMediaClient::CreateVideoDecoder( std::make_unique<VideoFrameFactoryImpl>( gpu_task_runner_, gpu_preferences_, std::move(image_provider), MaybeRenderEarlyManager::Create(gpu_task_runner_), - std::move(ycbcr_helper))); + std::move(frame_info_helper))); #elif BUILDFLAG(USE_CHROMEOS_MEDIA_ACCELERATION) if (IsNewAcceleratedVideoDecoderUsed(gpu_preferences_)) { @@ -309,7 +310,8 @@ std::unique_ptr<VideoDecoder> GpuMojoMediaClient::CreateVideoDecoder( media_gpu_channel_manager_, command_buffer_id->channel_token, command_buffer_id->route_id), - GetD3D11DeviceCallback(), *d3d11_supported_configs_); + GetD3D11DeviceCallback(), *d3d11_supported_configs_, + gl::DirectCompositionSurfaceWin::IsHDRSupported()); } #endif // defined(OS_WIN) break; @@ -320,7 +322,7 @@ std::unique_ptr<VideoDecoder> GpuMojoMediaClient::CreateVideoDecoder( } std::unique_ptr<CdmFactory> GpuMojoMediaClient::CreateCdmFactory( - service_manager::mojom::InterfaceProvider* interface_provider) { + mojom::FrameInterfaceFactory* interface_provider) { #if defined(OS_ANDROID) return std::make_unique<AndroidCdmFactory>( base::BindRepeating(&CreateProvisionFetcher, interface_provider), @@ -330,14 +332,4 @@ std::unique_ptr<CdmFactory> GpuMojoMediaClient::CreateCdmFactory( #endif // defined(OS_ANDROID) } -#if BUILDFLAG(ENABLE_CDM_PROXY) -std::unique_ptr<CdmProxy> GpuMojoMediaClient::CreateCdmProxy( - const base::Token& cdm_guid) { - if (cdm_proxy_factory_cb_) - return cdm_proxy_factory_cb_.Run(cdm_guid); - - return nullptr; -} -#endif // BUILDFLAG(ENABLE_CDM_PROXY) - } // namespace media diff --git a/chromium/media/mojo/services/gpu_mojo_media_client.h b/chromium/media/mojo/services/gpu_mojo_media_client.h index 889fa7fd67d..e62511df65a 100644 --- a/chromium/media/mojo/services/gpu_mojo_media_client.h +++ b/chromium/media/mojo/services/gpu_mojo_media_client.h @@ -17,7 +17,6 @@ #include "gpu/config/gpu_feature_info.h" #include "gpu/config/gpu_preferences.h" #include "media/base/android_overlay_mojo_factory.h" -#include "media/cdm/cdm_proxy.h" #include "media/media_buildflags.h" #include "media/mojo/services/mojo_media_client.h" #include "media/video/supported_video_decoder_config.h" @@ -34,8 +33,6 @@ class GpuMojoMediaClient : public MojoMediaClient { public: // |media_gpu_channel_manager| must only be used on |gpu_task_runner|, which // is expected to be the GPU main thread task runner. - // |cdm_proxy_factory_cb| can be used to create a CdmProxy. May be null if - // CdmProxy is not supported on the platform. GpuMojoMediaClient( const gpu::GpuPreferences& gpu_preferences, const gpu::GpuDriverBugWorkarounds& gpu_workarounds, @@ -43,8 +40,7 @@ class GpuMojoMediaClient : public MojoMediaClient { scoped_refptr<base::SingleThreadTaskRunner> gpu_task_runner, base::WeakPtr<MediaGpuChannelManager> media_gpu_channel_manager, gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory, - AndroidOverlayMojoFactoryCB android_overlay_factory_cb, - CdmProxyFactoryCB cdm_proxy_factory_cb); + AndroidOverlayMojoFactoryCB android_overlay_factory_cb); ~GpuMojoMediaClient() final; // MojoMediaClient implementation. @@ -59,10 +55,7 @@ class GpuMojoMediaClient : public MojoMediaClient { RequestOverlayInfoCB request_overlay_info_cb, const gfx::ColorSpace& target_color_space) final; std::unique_ptr<CdmFactory> CreateCdmFactory( - service_manager::mojom::InterfaceProvider* interface_provider) final; -#if BUILDFLAG(ENABLE_CDM_PROXY) - std::unique_ptr<CdmProxy> CreateCdmProxy(const base::Token& cdm_guid) final; -#endif // BUILDFLAG(ENABLE_CDM_PROXY) + mojom::FrameInterfaceFactory* interface_provider) final; private: gpu::GpuPreferences gpu_preferences_; @@ -76,7 +69,6 @@ class GpuMojoMediaClient : public MojoMediaClient { gpu::GpuMemoryBufferFactory* const gpu_memory_buffer_factory_; base::Optional<SupportedVideoDecoderConfigs> cros_supported_configs_; #endif // BUILDFLAG(USE_CHROMEOS_MEDIA_ACCELERATION) - CdmProxyFactoryCB cdm_proxy_factory_cb_; #if defined(OS_WIN) base::Optional<SupportedVideoDecoderConfigs> d3d11_supported_configs_; #endif // defined(OS_WIN) diff --git a/chromium/media/mojo/services/interface_factory_impl.cc b/chromium/media/mojo/services/interface_factory_impl.cc index 4b07b310208..d6a15e06943 100644 --- a/chromium/media/mojo/services/interface_factory_impl.cc +++ b/chromium/media/mojo/services/interface_factory_impl.cc @@ -14,7 +14,6 @@ #include "media/mojo/mojom/renderer_extensions.mojom.h" #include "media/mojo/services/mojo_decryptor_service.h" #include "media/mojo/services/mojo_media_client.h" -#include "services/service_manager/public/mojom/interface_provider.mojom.h" #if BUILDFLAG(ENABLE_MOJO_AUDIO_DECODER) #include "media/mojo/services/mojo_audio_decoder_service.h" @@ -35,17 +34,12 @@ #include "media/mojo/services/mojo_cdm_service.h" #endif // BUILDFLAG(ENABLE_MOJO_CDM) -#if BUILDFLAG(ENABLE_CDM_PROXY) -#include "media/mojo/services/mojo_cdm_proxy_service.h" -#endif // BUILDFLAG(ENABLE_CDM_PROXY) - namespace media { InterfaceFactoryImpl::InterfaceFactoryImpl( - mojo::PendingRemote<service_manager::mojom::InterfaceProvider> - host_interfaces, + mojo::PendingRemote<mojom::FrameInterfaceFactory> frame_interfaces, MojoMediaClient* mojo_media_client) - : host_interfaces_(std::move(host_interfaces)), + : frame_interfaces_(std::move(frame_interfaces)), mojo_media_client_(mojo_media_client) { DVLOG(1) << __func__; DCHECK(mojo_media_client_); @@ -96,7 +90,7 @@ void InterfaceFactoryImpl::CreateDefaultRenderer( DVLOG(2) << __func__; #if BUILDFLAG(ENABLE_MOJO_RENDERER) auto renderer = mojo_media_client_->CreateRenderer( - host_interfaces_.get(), base::ThreadTaskRunnerHandle::Get(), &media_log_, + frame_interfaces_.get(), base::ThreadTaskRunnerHandle::Get(), &media_log_, audio_device_id); if (!renderer) { DLOG(ERROR) << "Renderer creation failed."; @@ -126,7 +120,7 @@ void InterfaceFactoryImpl::CreateCastRenderer( mojo::PendingReceiver<media::mojom::Renderer> receiver) { DVLOG(2) << __func__; auto renderer = mojo_media_client_->CreateCastRenderer( - host_interfaces_.get(), base::ThreadTaskRunnerHandle::Get(), &media_log_, + frame_interfaces_.get(), base::ThreadTaskRunnerHandle::Get(), &media_log_, overlay_plane_id); if (!renderer) { DLOG(ERROR) << "Renderer creation failed."; @@ -184,37 +178,6 @@ void InterfaceFactoryImpl::CreateCdm( #endif // BUILDFLAG(ENABLE_MOJO_CDM) } -void InterfaceFactoryImpl::CreateDecryptor( - int cdm_id, - mojo::PendingReceiver<mojom::Decryptor> receiver) { - DVLOG(2) << __func__; - auto mojo_decryptor_service = - MojoDecryptorService::Create(cdm_id, &cdm_service_context_); - if (!mojo_decryptor_service) { - DLOG(ERROR) << "MojoDecryptorService creation failed."; - return; - } - - decryptor_receivers_.Add(std::move(mojo_decryptor_service), - std::move(receiver)); -} -#if BUILDFLAG(ENABLE_CDM_PROXY) -void InterfaceFactoryImpl::CreateCdmProxy( - const base::Token& cdm_guid, - mojo::PendingReceiver<mojom::CdmProxy> receiver) { - DVLOG(2) << __func__; - auto cdm_proxy = mojo_media_client_->CreateCdmProxy(cdm_guid); - if (!cdm_proxy) { - DLOG(ERROR) << "CdmProxy creation failed."; - return; - } - - cdm_proxy_receivers_.Add(std::make_unique<MojoCdmProxyService>( - std::move(cdm_proxy), &cdm_service_context_), - std::move(receiver)); -} -#endif // BUILDFLAG(ENABLE_CDM_PROXY) - void InterfaceFactoryImpl::OnDestroyPending(base::OnceClosure destroy_cb) { DVLOG(1) << __func__; destroy_cb_ = std::move(destroy_cb); @@ -244,11 +207,6 @@ bool InterfaceFactoryImpl::IsEmpty() { return false; #endif // BUILDFLAG(ENABLE_MOJO_CDM) -#if BUILDFLAG(ENABLE_CDM_PROXY) - if (!cdm_proxy_receivers_.empty()) - return false; -#endif // BUILDFLAG(ENABLE_CDM_PROXY) - if (!decryptor_receivers_.empty()) return false; @@ -278,10 +236,6 @@ void InterfaceFactoryImpl::SetReceiverDisconnectHandler() { cdm_receivers_.set_disconnect_handler(disconnect_cb); #endif // BUILDFLAG(ENABLE_MOJO_CDM) -#if BUILDFLAG(ENABLE_CDM_PROXY) - cdm_proxy_receivers_.set_disconnect_handler(disconnect_cb); -#endif // BUILDFLAG(ENABLE_CDM_PROXY) - decryptor_receivers_.set_disconnect_handler(disconnect_cb); } @@ -294,7 +248,8 @@ void InterfaceFactoryImpl::OnReceiverDisconnect() { #if BUILDFLAG(ENABLE_MOJO_CDM) CdmFactory* InterfaceFactoryImpl::GetCdmFactory() { if (!cdm_factory_) { - cdm_factory_ = mojo_media_client_->CreateCdmFactory(host_interfaces_.get()); + cdm_factory_ = + mojo_media_client_->CreateCdmFactory(frame_interfaces_.get()); LOG_IF(ERROR, !cdm_factory_) << "CdmFactory not available."; } return cdm_factory_.get(); diff --git a/chromium/media/mojo/services/interface_factory_impl.h b/chromium/media/mojo/services/interface_factory_impl.h index 79d71cb6e96..bf6d0e64b07 100644 --- a/chromium/media/mojo/services/interface_factory_impl.h +++ b/chromium/media/mojo/services/interface_factory_impl.h @@ -16,6 +16,7 @@ #include "media/mojo/mojom/audio_decoder.mojom.h" #include "media/mojo/mojom/content_decryption_module.mojom.h" #include "media/mojo/mojom/decryptor.mojom.h" +#include "media/mojo/mojom/frame_interface_factory.mojom.h" #include "media/mojo/mojom/interface_factory.mojom.h" #include "media/mojo/mojom/renderer.mojom.h" #include "media/mojo/mojom/video_decoder.mojom.h" @@ -26,11 +27,6 @@ #include "mojo/public/cpp/bindings/receiver.h" #include "mojo/public/cpp/bindings/remote.h" #include "mojo/public/cpp/bindings/unique_receiver_set.h" -#include "services/service_manager/public/mojom/interface_provider.mojom.h" - -#if BUILDFLAG(ENABLE_CDM_PROXY) -#include "media/mojo/mojom/cdm_proxy.mojom.h" -#endif // BUILDFLAG(ENABLE_CDM_PROXY) namespace media { @@ -40,8 +36,7 @@ class MojoMediaClient; class InterfaceFactoryImpl : public DeferredDestroy<mojom::InterfaceFactory> { public: InterfaceFactoryImpl( - mojo::PendingRemote<service_manager::mojom::InterfaceProvider> - host_interfaces, + mojo::PendingRemote<mojom::FrameInterfaceFactory> frame_interfaces, MojoMediaClient* mojo_media_client); ~InterfaceFactoryImpl() final; @@ -74,12 +69,6 @@ class InterfaceFactoryImpl : public DeferredDestroy<mojom::InterfaceFactory> { void CreateCdm( const std::string& key_system, mojo::PendingReceiver<mojom::ContentDecryptionModule> receiver) final; - void CreateDecryptor(int cdm_id, - mojo::PendingReceiver<mojom::Decryptor> receiver) final; -#if BUILDFLAG(ENABLE_CDM_PROXY) - void CreateCdmProxy(const base::Token& cdm_guid, - mojo::PendingReceiver<mojom::CdmProxy> receiver) final; -#endif // BUILDFLAG(ENABLE_CDM_PROXY) // DeferredDestroy<mojom::InterfaceFactory> implemenation. void OnDestroyPending(base::OnceClosure destroy_cb) final; @@ -120,11 +109,7 @@ class InterfaceFactoryImpl : public DeferredDestroy<mojom::InterfaceFactory> { mojo::UniqueReceiverSet<mojom::ContentDecryptionModule> cdm_receivers_; #endif // BUILDFLAG(ENABLE_MOJO_CDM) -#if BUILDFLAG(ENABLE_CDM_PROXY) - mojo::UniqueReceiverSet<mojom::CdmProxy> cdm_proxy_receivers_; -#endif // BUILDFLAG(ENABLE_CDM_PROXY) - - mojo::Remote<service_manager::mojom::InterfaceProvider> host_interfaces_; + mojo::Remote<mojom::FrameInterfaceFactory> frame_interfaces_; mojo::UniqueReceiverSet<mojom::Decryptor> decryptor_receivers_; diff --git a/chromium/media/mojo/services/media_interface_provider.cc b/chromium/media/mojo/services/media_interface_provider.cc deleted file mode 100644 index 844078fca80..00000000000 --- a/chromium/media/mojo/services/media_interface_provider.cc +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "media/mojo/services/media_interface_provider.h" - -namespace media { - -MediaInterfaceProvider::MediaInterfaceProvider( - mojo::PendingReceiver<service_manager::mojom::InterfaceProvider> receiver) - : receiver_(this, std::move(receiver)) {} - -MediaInterfaceProvider::~MediaInterfaceProvider() = default; - -void MediaInterfaceProvider::GetInterface( - const std::string& interface_name, - mojo::ScopedMessagePipeHandle handle) { - registry_.BindInterface(interface_name, std::move(handle)); -} - -} // namespace media diff --git a/chromium/media/mojo/services/media_interface_provider.h b/chromium/media/mojo/services/media_interface_provider.h deleted file mode 100644 index 26c1e2a652a..00000000000 --- a/chromium/media/mojo/services/media_interface_provider.h +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef MEDIA_MOJO_SERVICES_MEDIA_INTERFACE_PROVIDER_H_ -#define MEDIA_MOJO_SERVICES_MEDIA_INTERFACE_PROVIDER_H_ - -#include "media/mojo/services/media_mojo_export.h" -#include "mojo/public/cpp/bindings/pending_receiver.h" -#include "mojo/public/cpp/bindings/receiver.h" -#include "services/service_manager/public/cpp/binder_registry.h" -#include "services/service_manager/public/mojom/interface_provider.mojom.h" - -namespace media { - -class MEDIA_MOJO_EXPORT MediaInterfaceProvider - : public service_manager::mojom::InterfaceProvider { - public: - explicit MediaInterfaceProvider( - mojo::PendingReceiver<service_manager::mojom::InterfaceProvider> - receiver); - ~MediaInterfaceProvider() override; - - service_manager::BinderRegistry* registry() { return ®istry_; } - - private: - // service_manager::mojom::InterfaceProvider: - void GetInterface(const std::string& interface_name, - mojo::ScopedMessagePipeHandle handle) override; - - service_manager::BinderRegistry registry_; - - mojo::Receiver<service_manager::mojom::InterfaceProvider> receiver_; - - DISALLOW_COPY_AND_ASSIGN(MediaInterfaceProvider); -}; - -} // namespace media - -#endif // MEDIA_MOJO_SERVICES_MEDIA_BINDER_REGISTRY_H_ diff --git a/chromium/media/mojo/services/media_metrics_provider.cc b/chromium/media/mojo/services/media_metrics_provider.cc index f6cd6bedd49..e0920fce86b 100644 --- a/chromium/media/mojo/services/media_metrics_provider.cc +++ b/chromium/media/mojo/services/media_metrics_provider.cc @@ -20,7 +20,11 @@ #if !defined(OS_ANDROID) #include "media/filters/decrypting_video_decoder.h" -#endif +#endif // !defined(OS_ANDROID) + +#if defined(OS_FUCHSIA) +#include "media/fuchsia/metrics/fuchsia_playback_events_recorder.h" +#endif // defined(OS_FUCHSIA) namespace media { @@ -290,6 +294,13 @@ void MediaMetricsProvider::AcquireVideoDecodeStatsRecorder( std::move(receiver)); } +void MediaMetricsProvider::AcquirePlaybackEventsRecorder( + mojo::PendingReceiver<mojom::PlaybackEventsRecorder> receiver) { +#if defined(OS_FUCHSIA) + FuchsiaPlaybackEventsRecorder::Create(std::move(receiver)); +#endif +} + void MediaMetricsProvider::AcquireLearningTaskController( const std::string& taskName, mojo::PendingReceiver<media::learning::mojom::LearningTaskController> diff --git a/chromium/media/mojo/services/media_metrics_provider.h b/chromium/media/mojo/services/media_metrics_provider.h index 4141ad2934a..c9857f2c771 100644 --- a/chromium/media/mojo/services/media_metrics_provider.h +++ b/chromium/media/mojo/services/media_metrics_provider.h @@ -121,6 +121,8 @@ class MEDIA_MOJO_EXPORT MediaMetricsProvider mojo::PendingReceiver<mojom::WatchTimeRecorder> receiver) override; void AcquireVideoDecodeStatsRecorder( mojo::PendingReceiver<mojom::VideoDecodeStatsRecorder> receiver) override; + void AcquirePlaybackEventsRecorder( + mojo::PendingReceiver<mojom::PlaybackEventsRecorder> receiver) override; void AcquireLearningTaskController( const std::string& taskName, mojo::PendingReceiver<media::learning::mojom::LearningTaskController> diff --git a/chromium/media/mojo/services/media_service.cc b/chromium/media/mojo/services/media_service.cc index c669262a3c8..2ff11ac5139 100644 --- a/chromium/media/mojo/services/media_service.cc +++ b/chromium/media/mojo/services/media_service.cc @@ -5,7 +5,7 @@ #include "media/mojo/services/media_service.h" #include "base/bind.h" -#include "base/logging.h" +#include "base/check.h" #include "media/media_buildflags.h" #include "media/mojo/mojom/interface_factory.mojom.h" #include "media/mojo/services/interface_factory_impl.h" @@ -25,14 +25,13 @@ MediaService::~MediaService() = default; void MediaService::CreateInterfaceFactory( mojo::PendingReceiver<mojom::InterfaceFactory> receiver, - mojo::PendingRemote<service_manager::mojom::InterfaceProvider> - host_interfaces) { + mojo::PendingRemote<mojom::FrameInterfaceFactory> frame_interfaces) { // Ignore request if service has already stopped. if (!mojo_media_client_) return; interface_factory_receivers_.Add( - std::make_unique<InterfaceFactoryImpl>(std::move(host_interfaces), + std::make_unique<InterfaceFactoryImpl>(std::move(frame_interfaces), mojo_media_client_.get()), std::move(receiver)); } diff --git a/chromium/media/mojo/services/media_service.h b/chromium/media/mojo/services/media_service.h index 9656a8a1064..01f72aec1eb 100644 --- a/chromium/media/mojo/services/media_service.h +++ b/chromium/media/mojo/services/media_service.h @@ -9,6 +9,7 @@ #include "base/macros.h" #include "build/build_config.h" +#include "media/mojo/mojom/frame_interface_factory.mojom.h" #include "media/mojo/mojom/interface_factory.mojom.h" #include "media/mojo/mojom/media_service.mojom.h" #include "media/mojo/services/media_mojo_export.h" @@ -16,7 +17,6 @@ #include "mojo/public/cpp/bindings/pending_remote.h" #include "mojo/public/cpp/bindings/receiver.h" #include "mojo/public/cpp/bindings/unique_receiver_set.h" -#include "services/service_manager/public/mojom/interface_provider.mojom.h" namespace media { @@ -34,8 +34,7 @@ class MEDIA_MOJO_EXPORT MediaService : public mojom::MediaService { // mojom::MediaService implementation: void CreateInterfaceFactory( mojo::PendingReceiver<mojom::InterfaceFactory> receiver, - mojo::PendingRemote<service_manager::mojom::InterfaceProvider> - host_interfaces) final; + mojo::PendingRemote<mojom::FrameInterfaceFactory> frame_interfaces) final; mojo::Receiver<mojom::MediaService> receiver_; diff --git a/chromium/media/mojo/services/media_service_factory.cc b/chromium/media/mojo/services/media_service_factory.cc index 249632aada1..af044a25cf7 100644 --- a/chromium/media/mojo/services/media_service_factory.cc +++ b/chromium/media/mojo/services/media_service_factory.cc @@ -6,7 +6,8 @@ #include <memory> -#include "base/logging.h" +#include "base/notreached.h" +#include "build/build_config.h" #include "media/mojo/buildflags.h" #include "media/mojo/services/gpu_mojo_media_client.h" #include "media/mojo/services/media_service.h" @@ -20,9 +21,7 @@ namespace media { std::unique_ptr<MediaService> CreateMediaService( mojo::PendingReceiver<mojom::MediaService> receiver) { -#if BUILDFLAG(ENABLE_TEST_MOJO_MEDIA_CLIENT) - return CreateMediaServiceForTesting(std::move(receiver)); -#elif defined(OS_ANDROID) +#if defined(OS_ANDROID) return std::make_unique<MediaService>( std::make_unique<AndroidMojoMediaClient>(), std::move(receiver)); #else @@ -39,14 +38,12 @@ std::unique_ptr<MediaService> CreateGpuMediaService( scoped_refptr<base::SingleThreadTaskRunner> task_runner, base::WeakPtr<MediaGpuChannelManager> media_gpu_channel_manager, gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory, - AndroidOverlayMojoFactoryCB android_overlay_factory_cb, - CdmProxyFactoryCB cdm_proxy_factory_cb) { + AndroidOverlayMojoFactoryCB android_overlay_factory_cb) { return std::make_unique<MediaService>( std::make_unique<GpuMojoMediaClient>( gpu_preferences, gpu_workarounds, gpu_feature_info, task_runner, media_gpu_channel_manager, gpu_memory_buffer_factory, - std::move(android_overlay_factory_cb), - std::move(cdm_proxy_factory_cb)), + std::move(android_overlay_factory_cb)), std::move(receiver)); } diff --git a/chromium/media/mojo/services/media_service_factory.h b/chromium/media/mojo/services/media_service_factory.h index cc55902e763..d0052bf2acf 100644 --- a/chromium/media/mojo/services/media_service_factory.h +++ b/chromium/media/mojo/services/media_service_factory.h @@ -14,7 +14,6 @@ #include "gpu/config/gpu_feature_info.h" #include "gpu/config/gpu_preferences.h" #include "media/base/android_overlay_mojo_factory.h" -#include "media/cdm/cdm_proxy.h" #include "media/mojo/mojom/media_service.mojom.h" #include "media/mojo/services/media_mojo_export.h" #include "media/mojo/services/media_service.h" @@ -29,16 +28,13 @@ namespace media { class MediaGpuChannelManager; // Creates a MediaService instance using the default MojoMediaClient on each -// platform. Uses the TestMojoMediaClient if |enable_test_mojo_media_client| is -// true. +// platform. std::unique_ptr<MediaService> MEDIA_MOJO_EXPORT CreateMediaService(mojo::PendingReceiver<mojom::MediaService> receiver); // Creates a MediaService instance using the GpuMojoMediaClient. // |media_gpu_channel_manager| must only be used on |task_runner|, which is // expected to be the GPU main thread task runner. -// |cdm_proxy_factory_cb| can be used to create a CdmProxy. May be null if -// CdmProxy is not supported on the platform. std::unique_ptr<MediaService> MEDIA_MOJO_EXPORT CreateGpuMediaService( mojo::PendingReceiver<mojom::MediaService> receiver, const gpu::GpuPreferences& gpu_preferences, @@ -47,8 +43,7 @@ std::unique_ptr<MediaService> MEDIA_MOJO_EXPORT CreateGpuMediaService( scoped_refptr<base::SingleThreadTaskRunner> task_runner, base::WeakPtr<MediaGpuChannelManager> media_gpu_channel_manager, gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory, - AndroidOverlayMojoFactoryCB android_overlay_factory_cb, - CdmProxyFactoryCB cdm_proxy_factory_cb); + AndroidOverlayMojoFactoryCB android_overlay_factory_cb); // Creates a MediaService instance using the TestMojoMediaClient. std::unique_ptr<MediaService> MEDIA_MOJO_EXPORT CreateMediaServiceForTesting( diff --git a/chromium/media/mojo/services/media_service_unittest.cc b/chromium/media/mojo/services/media_service_unittest.cc index a0852d6b6c5..ef5f39687a0 100644 --- a/chromium/media/mojo/services/media_service_unittest.cc +++ b/chromium/media/mojo/services/media_service_unittest.cc @@ -27,7 +27,6 @@ #include "media/mojo/mojom/interface_factory.mojom.h" #include "media/mojo/mojom/media_service.mojom.h" #include "media/mojo/mojom/renderer.mojom.h" -#include "media/mojo/services/media_interface_provider.h" #include "media/mojo/services/media_service_factory.h" #include "mojo/public/cpp/bindings/associated_receiver.h" #include "mojo/public/cpp/bindings/pending_associated_receiver.h" @@ -38,11 +37,6 @@ #include "url/gurl.h" #include "url/origin.h" -#if BUILDFLAG(ENABLE_CDM_PROXY) -#include "media/cdm/cdm_paths.h" // nogncheck -#include "media/mojo/mojom/cdm_proxy.mojom.h" -#endif - namespace media { namespace { @@ -67,28 +61,6 @@ const char kInvalidKeySystem[] = "invalid.key.system"; const char kSecurityOrigin[] = "https://foo.com"; -// Returns a trivial encrypted DecoderBuffer. -scoped_refptr<DecoderBuffer> CreateEncryptedBuffer() { - scoped_refptr<DecoderBuffer> encrypted_buffer(new DecoderBuffer(100)); - encrypted_buffer->set_decrypt_config( - DecryptConfig::CreateCencConfig("dummy_key_id", "0123456789ABCDEF", {})); - return encrypted_buffer; -} - -#if BUILDFLAG(ENABLE_CDM_PROXY) -class MockCdmProxyClient : public mojom::CdmProxyClient { - public: - MockCdmProxyClient() = default; - ~MockCdmProxyClient() override = default; - - // mojom::CdmProxyClient implementation. - MOCK_METHOD0(NotifyHardwareReset, void()); - - private: - DISALLOW_COPY_AND_ASSIGN(MockCdmProxyClient); -}; -#endif // BUILDFLAG(ENABLE_CDM_PROXY) - class MockRendererClient : public mojom::RendererClient { public: MockRendererClient() = default; @@ -127,20 +99,13 @@ ACTION_P(QuitLoop, run_loop) { class MediaServiceTest : public testing::Test { public: MediaServiceTest() - : -#if BUILDFLAG(ENABLE_CDM_PROXY) - cdm_proxy_client_receiver_(&cdm_proxy_client_), -#endif - renderer_client_receiver_(&renderer_client_), - video_stream_(DemuxerStream::VIDEO) { - } + : renderer_client_receiver_(&renderer_client_), + video_stream_(DemuxerStream::VIDEO) {} ~MediaServiceTest() override = default; void SetUp() override { - mojo::PendingRemote<service_manager::mojom::InterfaceProvider> - host_interfaces; - auto provider = std::make_unique<MediaInterfaceProvider>( - host_interfaces.InitWithNewPipeAndPassReceiver()); + mojo::PendingRemote<mojom::FrameInterfaceFactory> frame_interfaces; + ignore_result(frame_interfaces.InitWithNewPipeAndPassReceiver()); media_service_impl_ = CreateMediaServiceForTesting( media_service_.BindNewPipeAndPassReceiver()); @@ -150,7 +115,7 @@ class MediaServiceTest : public testing::Test { base::Unretained(this))); media_service_->CreateInterfaceFactory( interface_factory_.BindNewPipeAndPassReceiver(), - std::move(host_interfaces)); + std::move(frame_interfaces)); } MOCK_METHOD3(OnCdmInitialized, @@ -182,58 +147,6 @@ class MediaServiceTest : public testing::Test { return cdm_id; } -#if BUILDFLAG(ENABLE_CDM_PROXY) - MOCK_METHOD4(OnCdmProxyInitialized, - void(CdmProxy::Status status, - CdmProxy::Protocol protocol, - uint32_t crypto_session_id, - int cdm_id)); - - // Returns the CDM ID associated with the CdmProxy. - int InitializeCdmProxy(const base::Token& cdm_guid) { - base::RunLoop run_loop; - interface_factory_->CreateCdmProxy(cdm_guid, - cdm_proxy_.BindNewPipeAndPassReceiver()); - - mojo::PendingAssociatedRemote<mojom::CdmProxyClient> client_remote; - cdm_proxy_client_receiver_.Bind( - client_remote.InitWithNewEndpointAndPassReceiver()); - int cdm_id = CdmContext::kInvalidCdmId; - - EXPECT_CALL(*this, OnCdmProxyInitialized(CdmProxy::Status::kOk, _, _, _)) - .WillOnce(DoAll(SaveArg<3>(&cdm_id), QuitLoop(&run_loop))); - cdm_proxy_->Initialize( - std::move(client_remote), - base::BindOnce(&MediaServiceTest::OnCdmProxyInitialized, - base::Unretained(this))); - run_loop.Run(); - return cdm_id; - } -#endif // BUILDFLAG(ENABLE_CDM_PROXY) - - MOCK_METHOD2(OnDecrypted, - void(Decryptor::Status, scoped_refptr<DecoderBuffer>)); - - void CreateDecryptor(int cdm_id, bool expected_result) { - base::RunLoop run_loop; - mojo::PendingRemote<mojom::Decryptor> decryptor_remote; - interface_factory_->CreateDecryptor( - cdm_id, decryptor_remote.InitWithNewPipeAndPassReceiver()); - MojoDecryptor mojo_decryptor(std::move(decryptor_remote)); - - // In the success case, there's no decryption key to decrypt the buffer so - // we would expect no-key. - auto expected_status = - expected_result ? Decryptor::kNoKey : Decryptor::kError; - - EXPECT_CALL(*this, OnDecrypted(expected_status, _)) - .WillOnce(QuitLoop(&run_loop)); - mojo_decryptor.Decrypt( - Decryptor::kVideo, CreateEncryptedBuffer(), - base::BindOnce(&MediaServiceTest::OnDecrypted, base::Unretained(this))); - run_loop.Run(); - } - MOCK_METHOD1(OnRendererInitialized, void(bool)); void InitializeRenderer(const VideoDecoderConfig& video_config, @@ -276,12 +189,6 @@ class MediaServiceTest : public testing::Test { std::unique_ptr<MediaService> media_service_impl_; -#if BUILDFLAG(ENABLE_CDM_PROXY) - mojo::Remote<mojom::CdmProxy> cdm_proxy_; - NiceMock<MockCdmProxyClient> cdm_proxy_client_; - mojo::AssociatedReceiver<mojom::CdmProxyClient> cdm_proxy_client_receiver_; -#endif // BUILDFLAG(ENABLE_CDM_PROXY) - NiceMock<MockRendererClient> renderer_client_; mojo::AssociatedReceiver<mojom::RendererClient> renderer_client_receiver_; @@ -311,11 +218,6 @@ TEST_F(MediaServiceTest, InitializeCdm_Success) { TEST_F(MediaServiceTest, InitializeCdm_InvalidKeySystem) { InitializeCdm(kInvalidKeySystem, false); } - -TEST_F(MediaServiceTest, Decryptor_WithCdm) { - int cdm_id = InitializeCdm(kClearKeyKeySystem, true); - CreateDecryptor(cdm_id, true); -} #endif // BUILDFLAG(ENABLE_MOJO_CDM) && !defined(OS_ANDROID) #if BUILDFLAG(ENABLE_MOJO_RENDERER) @@ -324,43 +226,6 @@ TEST_F(MediaServiceTest, InitializeRenderer) { } #endif // BUILDFLAG(ENABLE_MOJO_RENDERER) -#if BUILDFLAG(ENABLE_CDM_PROXY) -TEST_F(MediaServiceTest, CdmProxy) { - InitializeCdmProxy(kClearKeyCdmGuid); -} - -TEST_F(MediaServiceTest, Decryptor_WithCdmProxy) { - int cdm_id = InitializeCdmProxy(kClearKeyCdmGuid); - CreateDecryptor(cdm_id, true); -} - -TEST_F(MediaServiceTest, Decryptor_WrongCdmId) { - int cdm_id = InitializeCdmProxy(kClearKeyCdmGuid); - CreateDecryptor(cdm_id + 1, false); -} - -TEST_F(MediaServiceTest, CdmProxyPreventsIdling) { - InitializeCdmProxy(kClearKeyCdmGuid); - - // Disconnecting InterfaceFactory should not terminate the MediaService since - // there is still a CdmProxy hosted. - interface_factory_.reset(); - cdm_proxy_.FlushForTesting(); - - // Disconnecting CdmProxy will cause the service to idle since no other - // connections should be active. - base::RunLoop run_loop; - EXPECT_CALL(*this, OnMediaServiceIdle()).WillOnce(QuitLoop(&run_loop)); - cdm_proxy_.reset(); - run_loop.Run(); -} -#endif // BUILDFLAG(ENABLE_CDM_PROXY) - -TEST_F(MediaServiceTest, Decryptor_WithoutCdmOrCdmProxy) { - // Creating decryptor without creating CDM or CdmProxy. - CreateDecryptor(1, false); -} - TEST_F(MediaServiceTest, InterfaceFactoryPreventsIdling) { // The service should not idle during this operation. interface_factory_.FlushForTesting(); diff --git a/chromium/media/mojo/services/mojo_audio_output_stream_provider.cc b/chromium/media/mojo/services/mojo_audio_output_stream_provider.cc index 111ffb0cee0..7a1ab08dfbd 100644 --- a/chromium/media/mojo/services/mojo_audio_output_stream_provider.cc +++ b/chromium/media/mojo/services/mojo_audio_output_stream_provider.cc @@ -38,8 +38,8 @@ MojoAudioOutputStreamProvider::~MojoAudioOutputStreamProvider() { void MojoAudioOutputStreamProvider::Acquire( const AudioParameters& params, - mojo::PendingRemote<mojom::AudioOutputStreamProviderClient> provider_client, - const base::Optional<base::UnguessableToken>& processing_id) { + mojo::PendingRemote<mojom::AudioOutputStreamProviderClient> + provider_client) { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); // |processing_id| gets dropped here. It's not supported outside of the audio // service. As this class is slated for removal, it will not be updated to diff --git a/chromium/media/mojo/services/mojo_audio_output_stream_provider.h b/chromium/media/mojo/services/mojo_audio_output_stream_provider.h index a787e455853..52c23ee60ee 100644 --- a/chromium/media/mojo/services/mojo_audio_output_stream_provider.h +++ b/chromium/media/mojo/services/mojo_audio_output_stream_provider.h @@ -45,11 +45,9 @@ class MEDIA_MOJO_EXPORT MojoAudioOutputStreamProvider private: // mojom::AudioOutputStreamProvider implementation. - void Acquire( - const AudioParameters& params, - mojo::PendingRemote<mojom::AudioOutputStreamProviderClient> - provider_client, - const base::Optional<base::UnguessableToken>& processing_id) override; + void Acquire(const AudioParameters& params, + mojo::PendingRemote<mojom::AudioOutputStreamProviderClient> + provider_client) override; // Called when |audio_output_| had an error. void CleanUp(bool had_error); diff --git a/chromium/media/mojo/services/mojo_audio_output_stream_provider_unittest.cc b/chromium/media/mojo/services/mojo_audio_output_stream_provider_unittest.cc index 6484b81d97b..04fa66ef823 100644 --- a/chromium/media/mojo/services/mojo_audio_output_stream_provider_unittest.cc +++ b/chromium/media/mojo/services/mojo_audio_output_stream_provider_unittest.cc @@ -92,12 +92,12 @@ TEST(MojoAudioOutputStreamProviderTest, AcquireTwice_BadMessage) { mojo::PendingRemote<mojom::AudioOutputStreamProviderClient> client_1; ignore_result(client_1.InitWithNewPipeAndPassReceiver()); provider_remote->Acquire(media::AudioParameters::UnavailableDeviceParams(), - std::move(client_1), base::nullopt); + std::move(client_1)); mojo::PendingRemote<mojom::AudioOutputStreamProviderClient> client_2; ignore_result(client_2.InitWithNewPipeAndPassReceiver()); provider_remote->Acquire(media::AudioParameters::UnavailableDeviceParams(), - std::move(client_2), base::nullopt); + std::move(client_2)); EXPECT_CALL(deleter, Run(provider)).WillOnce(DeleteArg<0>()); base::RunLoop().RunUntilIdle(); @@ -130,7 +130,7 @@ TEST(MojoAudioOutputStreamProviderTest, mojo::PendingRemote<mojom::AudioOutputStreamProviderClient> client; ignore_result(client.InitWithNewPipeAndPassReceiver()); - provider_remote->Acquire(params, std::move(client), base::nullopt); + provider_remote->Acquire(params, std::move(client)); #if defined(OS_ANDROID) base::RunLoop().RunUntilIdle(); diff --git a/chromium/media/mojo/services/mojo_cdm_helper.cc b/chromium/media/mojo/services/mojo_cdm_helper.cc index ae74069d828..2d5761e44e5 100644 --- a/chromium/media/mojo/services/mojo_cdm_helper.cc +++ b/chromium/media/mojo/services/mojo_cdm_helper.cc @@ -11,13 +11,11 @@ #include "media/mojo/services/mojo_cdm_file_io.h" #include "mojo/public/cpp/bindings/callback_helpers.h" #include "mojo/public/cpp/bindings/pending_remote.h" -#include "services/service_manager/public/cpp/connect.h" namespace media { -MojoCdmHelper::MojoCdmHelper( - service_manager::mojom::InterfaceProvider* interface_provider) - : interface_provider_(interface_provider) {} +MojoCdmHelper::MojoCdmHelper(mojom::FrameInterfaceFactory* frame_interfaces) + : frame_interfaces_(frame_interfaces) {} MojoCdmHelper::~MojoCdmHelper() = default; @@ -39,27 +37,6 @@ cdm::FileIO* MojoCdmHelper::CreateCdmFileIO(cdm::FileIOClient* client) { return cdm_file_io; } -#if BUILDFLAG(ENABLE_CDM_PROXY) -cdm::CdmProxy* MojoCdmHelper::CreateCdmProxy(cdm::CdmProxyClient* client) { - DVLOG(3) << __func__; - if (cdm_proxy_) { - DVLOG(1) << __func__ << ": Only one outstanding CdmProxy allowed."; - return nullptr; - } - - mojo::PendingRemote<mojom::CdmProxy> cdm_proxy_remote; - service_manager::GetInterface<mojom::CdmProxy>( - interface_provider_, cdm_proxy_remote.InitWithNewPipeAndPassReceiver()); - cdm_proxy_ = - std::make_unique<MojoCdmProxy>(std::move(cdm_proxy_remote), client); - return cdm_proxy_.get(); -} - -int MojoCdmHelper::GetCdmProxyCdmId() { - return cdm_proxy_ ? cdm_proxy_->GetCdmId() : CdmContext::kInvalidCdmId; -} -#endif // BUILDFLAG(ENABLE_CDM_PROXY) - cdm::Buffer* MojoCdmHelper::CreateCdmBuffer(size_t capacity) { return GetAllocator()->CreateCdmBuffer(capacity); } @@ -118,8 +95,8 @@ void MojoCdmHelper::ReportFileReadSize(int file_size_bytes) { void MojoCdmHelper::ConnectToCdmStorage() { if (!cdm_storage_remote_) { - service_manager::GetInterface<mojom::CdmStorage>( - interface_provider_, cdm_storage_remote_.BindNewPipeAndPassReceiver()); + frame_interfaces_->CreateCdmStorage( + cdm_storage_remote_.BindNewPipeAndPassReceiver()); } } @@ -131,16 +108,15 @@ CdmAllocator* MojoCdmHelper::GetAllocator() { void MojoCdmHelper::ConnectToOutputProtection() { if (!output_protection_) { - service_manager::GetInterface<mojom::OutputProtection>( - interface_provider_, output_protection_.BindNewPipeAndPassReceiver()); + frame_interfaces_->BindEmbedderReceiver(mojo::GenericPendingReceiver( + output_protection_.BindNewPipeAndPassReceiver())); } } void MojoCdmHelper::ConnectToPlatformVerification() { if (!platform_verification_) { - interface_provider_->GetInterface( - mojom::PlatformVerification::Name_, - platform_verification_.BindNewPipeAndPassReceiver().PassPipe()); + frame_interfaces_->BindEmbedderReceiver(mojo::GenericPendingReceiver( + platform_verification_.BindNewPipeAndPassReceiver())); } } diff --git a/chromium/media/mojo/services/mojo_cdm_helper.h b/chromium/media/mojo/services/mojo_cdm_helper.h index 4a875028470..25bf7d13790 100644 --- a/chromium/media/mojo/services/mojo_cdm_helper.h +++ b/chromium/media/mojo/services/mojo_cdm_helper.h @@ -14,23 +14,13 @@ #include "media/cdm/cdm_auxiliary_helper.h" #include "media/media_buildflags.h" #include "media/mojo/mojom/cdm_storage.mojom.h" +#include "media/mojo/mojom/frame_interface_factory.mojom.h" #include "media/mojo/mojom/output_protection.mojom.h" #include "media/mojo/mojom/platform_verification.mojom.h" #include "media/mojo/services/media_mojo_export.h" #include "media/mojo/services/mojo_cdm_file_io.h" #include "mojo/public/cpp/bindings/remote.h" -#if BUILDFLAG(ENABLE_CDM_PROXY) -#include "media/mojo/mojom/cdm_proxy.mojom.h" -#include "media/mojo/services/mojo_cdm_proxy.h" -#endif - -namespace service_manager { -namespace mojom { -class InterfaceProvider; -} -} // namespace service_manager - namespace media { // Helper class that connects the CDM to various auxiliary services. All @@ -39,17 +29,12 @@ namespace media { class MEDIA_MOJO_EXPORT MojoCdmHelper final : public CdmAuxiliaryHelper, public MojoCdmFileIO::Delegate { public: - explicit MojoCdmHelper( - service_manager::mojom::InterfaceProvider* interface_provider); + explicit MojoCdmHelper(mojom::FrameInterfaceFactory* frame_interfaces); ~MojoCdmHelper() final; // CdmAuxiliaryHelper implementation. void SetFileReadCB(FileReadCB file_read_cb) final; cdm::FileIO* CreateCdmFileIO(cdm::FileIOClient* client) final; -#if BUILDFLAG(ENABLE_CDM_PROXY) - cdm::CdmProxy* CreateCdmProxy(cdm::CdmProxyClient* client) final; - int GetCdmProxyCdmId() final; -#endif cdm::Buffer* CreateCdmBuffer(size_t capacity) final; std::unique_ptr<VideoFrameImpl> CreateCdmVideoFrame() final; void QueryStatus(QueryStatusCB callback) final; @@ -72,7 +57,7 @@ class MEDIA_MOJO_EXPORT MojoCdmHelper final : public CdmAuxiliaryHelper, void ConnectToPlatformVerification(); // Provides interfaces when needed. - service_manager::mojom::InterfaceProvider* interface_provider_; + mojom::FrameInterfaceFactory* frame_interfaces_; // Connections to the additional services. For the mojom classes, if a // connection error occurs, we will not be able to reconnect to the @@ -89,10 +74,6 @@ class MEDIA_MOJO_EXPORT MojoCdmHelper final : public CdmAuxiliaryHelper, // TODO(xhwang): Switch to use UniquePtrComparator. std::vector<std::unique_ptr<MojoCdmFileIO>> cdm_file_io_set_; -#if BUILDFLAG(ENABLE_CDM_PROXY) - std::unique_ptr<MojoCdmProxy> cdm_proxy_; -#endif - base::WeakPtrFactory<MojoCdmHelper> weak_factory_{this}; DISALLOW_COPY_AND_ASSIGN(MojoCdmHelper); }; diff --git a/chromium/media/mojo/services/mojo_cdm_helper_unittest.cc b/chromium/media/mojo/services/mojo_cdm_helper_unittest.cc index fcdec73a081..1b52d254b27 100644 --- a/chromium/media/mojo/services/mojo_cdm_helper_unittest.cc +++ b/chromium/media/mojo/services/mojo_cdm_helper_unittest.cc @@ -13,8 +13,6 @@ #include "mojo/public/cpp/bindings/associated_receiver.h" #include "mojo/public/cpp/bindings/pending_receiver.h" #include "mojo/public/cpp/bindings/self_owned_receiver.h" -#include "services/service_manager/public/cpp/binder_registry.h" -#include "services/service_manager/public/mojom/interface_provider.mojom.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -66,36 +64,27 @@ class MockCdmStorage : public mojom::CdmStorage { mojo::AssociatedReceiver<mojom::CdmFile> client_receiver_{&cdm_file_}; }; -void CreateCdmStorage(mojo::PendingReceiver<mojom::CdmStorage> receiver) { - mojo::MakeSelfOwnedReceiver(std::make_unique<MockCdmStorage>(), - std::move(receiver)); -} - -class TestInterfaceProvider : public service_manager::mojom::InterfaceProvider { +class TestFrameInterfaceFactory : public mojom::FrameInterfaceFactory { public: - TestInterfaceProvider() { - registry_.AddInterface(base::Bind(&CreateCdmStorage)); - } - ~TestInterfaceProvider() override = default; - - void GetInterface(const std::string& interface_name, - mojo::ScopedMessagePipeHandle handle) override { - registry_.BindInterface(interface_name, std::move(handle)); + void CreateProvisionFetcher( + mojo::PendingReceiver<mojom::ProvisionFetcher>) override {} + void CreateCdmStorage( + mojo::PendingReceiver<mojom::CdmStorage> receiver) override { + mojo::MakeSelfOwnedReceiver(std::make_unique<MockCdmStorage>(), + std::move(receiver)); } - - private: - service_manager::BinderRegistry registry_; + void BindEmbedderReceiver(mojo::GenericPendingReceiver) override {} }; } // namespace class MojoCdmHelperTest : public testing::Test { protected: - MojoCdmHelperTest() : helper_(&test_interface_provider_) {} + MojoCdmHelperTest() : helper_(&frame_interfaces_) {} ~MojoCdmHelperTest() override = default; base::test::TaskEnvironment task_environment_; - TestInterfaceProvider test_interface_provider_; + TestFrameInterfaceFactory frame_interfaces_; MockFileIOClient file_io_client_; MojoCdmHelper helper_; }; diff --git a/chromium/media/mojo/services/mojo_cdm_promise.cc b/chromium/media/mojo/services/mojo_cdm_promise.cc index 41b18ec793e..5bd1295a42f 100644 --- a/chromium/media/mojo/services/mojo_cdm_promise.cc +++ b/chromium/media/mojo/services/mojo_cdm_promise.cc @@ -9,7 +9,7 @@ #include <vector> #include "base/bind.h" -#include "base/logging.h" +#include "base/check.h" #include "media/base/content_decryption_module.h" #include "media/base/decryptor.h" diff --git a/chromium/media/mojo/services/mojo_cdm_proxy.cc b/chromium/media/mojo/services/mojo_cdm_proxy.cc deleted file mode 100644 index 4c454fa19c4..00000000000 --- a/chromium/media/mojo/services/mojo_cdm_proxy.cc +++ /dev/null @@ -1,217 +0,0 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "media/mojo/services/mojo_cdm_proxy.h" - -#include <vector> - -#include "base/bind.h" -#include "base/callback.h" -#include "base/logging.h" -#include "media/base/cdm_context.h" -#include "mojo/public/cpp/bindings/callback_helpers.h" - -namespace media { - -namespace { - -inline std::ostream& operator<<(std::ostream& out, CdmProxy::Status status) { - switch (status) { - case CdmProxy::Status::kOk: - return out << "kOk"; - case CdmProxy::Status::kFail: - return out << "kFail"; - } - NOTREACHED(); - return out << "Invalid Status!"; -} - -cdm::CdmProxyClient::Status ToCdmStatus(CdmProxy::Status status) { - switch (status) { - case CdmProxy::Status::kOk: - return cdm::CdmProxyClient::Status::kOk; - case CdmProxy::Status::kFail: - return cdm::CdmProxyClient::Status::kFail; - } - - NOTREACHED() << "Unexpected status: " << status; - return cdm::CdmProxyClient::Status::kFail; -} - -cdm::CdmProxyClient::Protocol ToCdmProtocol(CdmProxy::Protocol protocol) { - switch (protocol) { - case CdmProxy::Protocol::kNone: - return cdm::CdmProxyClient::Protocol::kNone; - case CdmProxy::Protocol::kIntel: - return cdm::CdmProxyClient::Protocol::kIntel; - } - - NOTREACHED() << "Unexpected protocol: " << static_cast<int32_t>(protocol); - return cdm::CdmProxyClient::Protocol::kNone; -} - -CdmProxy::Function ToMediaFunction(cdm::CdmProxy::Function function) { - switch (function) { - case cdm::CdmProxy::Function::kIntelNegotiateCryptoSessionKeyExchange: - return CdmProxy::Function::kIntelNegotiateCryptoSessionKeyExchange; - } - - // TODO(xhwang): Return an invalid function? - NOTREACHED() << "Unexpected function: " << static_cast<int32_t>(function); - return CdmProxy::Function::kIntelNegotiateCryptoSessionKeyExchange; -} - -CdmProxy::KeyType ToMediaKeyType(cdm::CdmProxy::KeyType key_type) { - switch (key_type) { - case cdm::CdmProxy::KeyType::kDecryptOnly: - return CdmProxy::KeyType::kDecryptOnly; - case cdm::CdmProxy::KeyType::kDecryptAndDecode: - return CdmProxy::KeyType::kDecryptAndDecode; - } - - NOTREACHED() << "Unexpected key type: " << static_cast<int32_t>(key_type); - return CdmProxy::KeyType::kDecryptOnly; -} - -} // namespace - -MojoCdmProxy::MojoCdmProxy( - mojo::PendingRemote<mojom::CdmProxy> cdm_proxy_remote, - cdm::CdmProxyClient* client) - : cdm_proxy_remote_(std::move(cdm_proxy_remote)), client_(client) { - DVLOG(1) << __func__; - DCHECK(client); -} - -MojoCdmProxy::~MojoCdmProxy() { - DVLOG(1) << __func__; -} - -void MojoCdmProxy::Initialize() { - DVLOG(2) << __func__; - - auto callback = mojo::WrapCallbackWithDefaultInvokeIfNotRun( - base::BindOnce(&MojoCdmProxy::OnInitialized, weak_factory_.GetWeakPtr()), - media::CdmProxy::Status::kFail, media::CdmProxy::Protocol::kNone, 0, - CdmContext::kInvalidCdmId); - cdm_proxy_remote_->Initialize(client_receiver_.BindNewEndpointAndPassRemote(), - std::move(callback)); -} - -void MojoCdmProxy::Process(Function function, - uint32_t crypto_session_id, - const uint8_t* input_data, - uint32_t input_data_size, - uint32_t expected_output_data_size) { - DVLOG(3) << __func__; - CHECK(client_) << "Initialize not called."; - - auto callback = mojo::WrapCallbackWithDefaultInvokeIfNotRun( - base::BindOnce(&MojoCdmProxy::OnProcessed, weak_factory_.GetWeakPtr()), - media::CdmProxy::Status::kFail, std::vector<uint8_t>()); - - cdm_proxy_remote_->Process( - ToMediaFunction(function), crypto_session_id, - std::vector<uint8_t>(input_data, input_data + input_data_size), - expected_output_data_size, std::move(callback)); -} - -void MojoCdmProxy::CreateMediaCryptoSession(const uint8_t* input_data, - uint32_t input_data_size) { - DVLOG(3) << __func__; - CHECK(client_) << "Initialize not called."; - - auto callback = mojo::WrapCallbackWithDefaultInvokeIfNotRun( - base::BindOnce(&MojoCdmProxy::OnMediaCryptoSessionCreated, - weak_factory_.GetWeakPtr()), - media::CdmProxy::Status::kFail, 0, 0); - - cdm_proxy_remote_->CreateMediaCryptoSession( - std::vector<uint8_t>(input_data, input_data + input_data_size), - std::move(callback)); -} - -void MojoCdmProxy::SetKey(uint32_t crypto_session_id, - const uint8_t* key_id, - uint32_t key_id_size, - KeyType key_type, - const uint8_t* key_blob, - uint32_t key_blob_size) { - DVLOG(3) << __func__; - CHECK(client_) << "Initialize not called."; - - auto callback = mojo::WrapCallbackWithDefaultInvokeIfNotRun( - base::BindOnce(&MojoCdmProxy::OnKeySet, weak_factory_.GetWeakPtr()), - media::CdmProxy::Status::kFail); - - cdm_proxy_remote_->SetKey( - crypto_session_id, std::vector<uint8_t>(key_id, key_id + key_id_size), - ToMediaKeyType(key_type), - std::vector<uint8_t>(key_blob, key_blob + key_blob_size), - std::move(callback)); -} - -void MojoCdmProxy::RemoveKey(uint32_t crypto_session_id, - const uint8_t* key_id, - uint32_t key_id_size) { - DVLOG(3) << __func__; - CHECK(client_) << "Initialize not called."; - - auto callback = mojo::WrapCallbackWithDefaultInvokeIfNotRun( - base::BindOnce(&MojoCdmProxy::OnKeyRemoved, weak_factory_.GetWeakPtr()), - media::CdmProxy::Status::kFail); - - cdm_proxy_remote_->RemoveKey( - crypto_session_id, std::vector<uint8_t>(key_id, key_id + key_id_size), - std::move(callback)); -} - -void MojoCdmProxy::NotifyHardwareReset() { - DVLOG(2) << __func__; - client_->NotifyHardwareReset(); -} - -int MojoCdmProxy::GetCdmId() { - DVLOG(2) << __func__ << ": cdm_id = " << cdm_id_; - return cdm_id_; -} - -void MojoCdmProxy::OnInitialized(media::CdmProxy::Status status, - media::CdmProxy::Protocol protocol, - uint32_t crypto_session_id, - int cdm_id) { - DVLOG(3) << __func__ << ": status = " << status - << ", crypto_session_id = " << crypto_session_id; - cdm_id_ = cdm_id; - client_->OnInitialized(ToCdmStatus(status), ToCdmProtocol(protocol), - crypto_session_id); -} - -void MojoCdmProxy::OnProcessed(media::CdmProxy::Status status, - const std::vector<uint8_t>& output_data) { - DVLOG(3) << __func__ << ": status = " << status; - client_->OnProcessed(ToCdmStatus(status), output_data.data(), - output_data.size()); -} - -void MojoCdmProxy::OnMediaCryptoSessionCreated(media::CdmProxy::Status status, - uint32_t crypto_session_id, - uint64_t output_data) { - DVLOG(3) << __func__ << ": status = " << status - << ", crypto_session_id = " << crypto_session_id; - client_->OnMediaCryptoSessionCreated(ToCdmStatus(status), crypto_session_id, - output_data); -} - -void MojoCdmProxy::OnKeySet(media::CdmProxy::Status status) { - DVLOG(3) << __func__ << ": status = " << status; - client_->OnKeySet(ToCdmStatus(status)); -} - -void MojoCdmProxy::OnKeyRemoved(media::CdmProxy::Status status) { - DVLOG(3) << __func__ << ": status = " << status; - client_->OnKeyRemoved(ToCdmStatus(status)); -} - -} // namespace media diff --git a/chromium/media/mojo/services/mojo_cdm_proxy.h b/chromium/media/mojo/services/mojo_cdm_proxy.h deleted file mode 100644 index 5c7264052b2..00000000000 --- a/chromium/media/mojo/services/mojo_cdm_proxy.h +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef MEDIA_MOJO_SERVICES_MOJO_CDM_PROXY_H_ -#define MEDIA_MOJO_SERVICES_MOJO_CDM_PROXY_H_ - -#include <stdint.h> - -#include <vector> - -#include "base/macros.h" -#include "base/memory/weak_ptr.h" -#include "media/base/cdm_context.h" -#include "media/cdm/api/content_decryption_module.h" -#include "media/mojo/mojom/cdm_proxy.mojom.h" -#include "media/mojo/services/media_mojo_export.h" -#include "mojo/public/cpp/bindings/associated_receiver.h" -#include "mojo/public/cpp/bindings/pending_remote.h" -#include "mojo/public/cpp/bindings/remote.h" - -namespace media { - -// Implements a cdm::CdmProxy that communicates with mojom::CdmProxy. -class MEDIA_MOJO_EXPORT MojoCdmProxy : public cdm::CdmProxy, - mojom::CdmProxyClient { - public: - MojoCdmProxy(mojo::PendingRemote<mojom::CdmProxy> cdm_proxy_remote, - cdm::CdmProxyClient* client); - ~MojoCdmProxy() override; - - // cdm::CdmProxy implementation. - void Initialize() final; - void Process(Function function, - uint32_t crypto_session_id, - const uint8_t* input_data, - uint32_t input_data_size, - uint32_t expected_output_data_size) final; - void CreateMediaCryptoSession(const uint8_t* input_data, - uint32_t input_data_size) final; - void SetKey(uint32_t crypto_session_id, - const uint8_t* key_id, - uint32_t key_id_size, - KeyType key_type, - const uint8_t* key_blob, - uint32_t key_blob_size) final; - void RemoveKey(uint32_t crypto_session_id, - const uint8_t* key_id, - uint32_t key_id_size) final; - - // mojom::CdmProxyClient implementation. - void NotifyHardwareReset() final; - - // Returns the CDM ID associated with the remote CdmProxy. - int GetCdmId(); - - private: - void OnInitialized(media::CdmProxy::Status status, - media::CdmProxy::Protocol protocol, - uint32_t crypto_session_id, - int cdm_id); - void OnProcessed(media::CdmProxy::Status status, - const std::vector<uint8_t>& output_data); - void OnMediaCryptoSessionCreated(media::CdmProxy::Status status, - uint32_t crypto_session_id, - uint64_t output_data); - void OnKeySet(media::CdmProxy::Status status); - void OnKeyRemoved(media::CdmProxy::Status status); - - mojo::Remote<mojom::CdmProxy> cdm_proxy_remote_; - cdm::CdmProxyClient* client_; - - mojo::AssociatedReceiver<mojom::CdmProxyClient> client_receiver_{this}; - - int cdm_id_ = CdmContext::kInvalidCdmId; - - // NOTE: Weak pointers must be invalidated before all other member variables. - base::WeakPtrFactory<MojoCdmProxy> weak_factory_{this}; - - DISALLOW_COPY_AND_ASSIGN(MojoCdmProxy); -}; - -} // namespace media - -#endif // MEDIA_MOJO_SERVICES_MOJO_CDM_PROXY_H_ diff --git a/chromium/media/mojo/services/mojo_cdm_proxy_service.cc b/chromium/media/mojo/services/mojo_cdm_proxy_service.cc deleted file mode 100644 index 1c74993b907..00000000000 --- a/chromium/media/mojo/services/mojo_cdm_proxy_service.cc +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "media/mojo/services/mojo_cdm_proxy_service.h" - -#include "base/bind.h" -#include "base/macros.h" -#include "media/mojo/services/mojo_cdm_service_context.h" - -namespace media { - -MojoCdmProxyService::MojoCdmProxyService( - std::unique_ptr<::media::CdmProxy> cdm_proxy, - MojoCdmServiceContext* context) - : cdm_proxy_(std::move(cdm_proxy)), context_(context) { - DVLOG(1) << __func__; - DCHECK(cdm_proxy_); - DCHECK(context_); -} - -MojoCdmProxyService::~MojoCdmProxyService() { - DVLOG(1) << __func__; - - if (cdm_id_ != CdmContext::kInvalidCdmId) - context_->UnregisterCdmProxy(cdm_id_); -} - -void MojoCdmProxyService::Initialize( - mojo::PendingAssociatedRemote<mojom::CdmProxyClient> client, - InitializeCallback callback) { - DVLOG(2) << __func__; - - CHECK(!has_initialize_been_called_) << "Initialize should only happen once"; - has_initialize_been_called_ = true; - - client_.Bind(std::move(client)); - - cdm_proxy_->Initialize( - this, base::BindOnce(&MojoCdmProxyService::OnInitialized, - weak_factory_.GetWeakPtr(), std::move(callback))); -} - -void MojoCdmProxyService::Process(media::CdmProxy::Function function, - uint32_t crypto_session_id, - const std::vector<uint8_t>& input_data, - uint32_t expected_output_data_size, - ProcessCallback callback) { - DVLOG(3) << __func__; - cdm_proxy_->Process(function, crypto_session_id, input_data, - expected_output_data_size, std::move(callback)); -} - -void MojoCdmProxyService::CreateMediaCryptoSession( - const std::vector<uint8_t>& input_data, - CreateMediaCryptoSessionCallback callback) { - DVLOG(3) << __func__; - cdm_proxy_->CreateMediaCryptoSession(input_data, std::move(callback)); -} - -void MojoCdmProxyService::SetKey(uint32_t crypto_session_id, - const std::vector<uint8_t>& key_id, - media::CdmProxy::KeyType key_type, - const std::vector<uint8_t>& key_blob, - SetKeyCallback callback) { - DVLOG(3) << __func__; - cdm_proxy_->SetKey(crypto_session_id, key_id, key_type, key_blob, - std::move(callback)); -} - -void MojoCdmProxyService::RemoveKey(uint32_t crypto_session_id, - const std::vector<uint8_t>& key_id, - RemoveKeyCallback callback) { - DVLOG(3) << __func__; - cdm_proxy_->RemoveKey(crypto_session_id, key_id, std::move(callback)); -} - -void MojoCdmProxyService::NotifyHardwareReset() { - DVLOG(2) << __func__; - client_->NotifyHardwareReset(); -} - -base::WeakPtr<CdmContext> MojoCdmProxyService::GetCdmContext() { - DVLOG(2) << __func__; - return cdm_proxy_->GetCdmContext(); -} - -void MojoCdmProxyService::OnInitialized(InitializeCallback callback, - ::media::CdmProxy::Status status, - ::media::CdmProxy::Protocol protocol, - uint32_t crypto_session_id) { - CHECK_EQ(cdm_id_, CdmContext::kInvalidCdmId) - << "CDM proxy should only be created once."; - - if (status == ::media::CdmProxy::Status::kOk) - cdm_id_ = context_->RegisterCdmProxy(this); - - std::move(callback).Run(status, protocol, crypto_session_id, cdm_id_); -} - -} // namespace media diff --git a/chromium/media/mojo/services/mojo_cdm_proxy_service.h b/chromium/media/mojo/services/mojo_cdm_proxy_service.h deleted file mode 100644 index e8eaa950260..00000000000 --- a/chromium/media/mojo/services/mojo_cdm_proxy_service.h +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef MEDIA_MOJO_SERVICES_MOJO_CDM_PROXY_SERVICE_H_ -#define MEDIA_MOJO_SERVICES_MOJO_CDM_PROXY_SERVICE_H_ - -#include <stdint.h> - -#include <memory> - -#include "base/compiler_specific.h" -#include "base/macros.h" -#include "base/memory/weak_ptr.h" -#include "media/base/cdm_context.h" -#include "media/cdm/cdm_proxy.h" -#include "media/mojo/mojom/cdm_proxy.mojom.h" -#include "media/mojo/services/media_mojo_export.h" -#include "mojo/public/cpp/bindings/associated_remote.h" -#include "mojo/public/cpp/bindings/pending_associated_remote.h" - -namespace media { - -class MojoCdmServiceContext; - -// A mojom::CdmProxy implementation backed by a media::CdmProxy. -class MEDIA_MOJO_EXPORT MojoCdmProxyService : public mojom::CdmProxy, - public CdmProxy::Client { - public: - MojoCdmProxyService(std::unique_ptr<::media::CdmProxy> cdm_proxy, - MojoCdmServiceContext* context); - - ~MojoCdmProxyService() final; - - // mojom::CdmProxy implementation. - void Initialize(mojo::PendingAssociatedRemote<mojom::CdmProxyClient> client, - InitializeCallback callback) final; - void Process(media::CdmProxy::Function function, - uint32_t crypto_session_id, - const std::vector<uint8_t>& input_data, - uint32_t expected_output_data_size, - ProcessCallback callback) final; - void CreateMediaCryptoSession( - const std::vector<uint8_t>& input_data, - CreateMediaCryptoSessionCallback callback) final; - void SetKey(uint32_t crypto_session_id, - const std::vector<uint8_t>& key_id, - media::CdmProxy::KeyType key_type, - const std::vector<uint8_t>& key_blob, - SetKeyCallback callback) final; - void RemoveKey(uint32_t crypto_session_id, - const std::vector<uint8_t>& key_id, - RemoveKeyCallback callback) final; - - // CdmProxy::Client implementation. - void NotifyHardwareReset() final; - - // Get CdmContext to be used by the media pipeline. - base::WeakPtr<CdmContext> GetCdmContext(); - - int GetCdmIdForTesting() const { return cdm_id_; } - - private: - void OnInitialized(InitializeCallback callback, - ::media::CdmProxy::Status status, - ::media::CdmProxy::Protocol protocol, - uint32_t crypto_session_id); - - bool has_initialize_been_called_ = false; - - std::unique_ptr<::media::CdmProxy> cdm_proxy_; - MojoCdmServiceContext* const context_ = nullptr; - - mojo::AssociatedRemote<mojom::CdmProxyClient> client_; - - // Set to a valid CDM ID if the |cdm_proxy_| is successfully initialized. - int cdm_id_ = CdmContext::kInvalidCdmId; - - // NOTE: Weak pointers must be invalidated before all other member variables. - base::WeakPtrFactory<MojoCdmProxyService> weak_factory_{this}; - - DISALLOW_COPY_AND_ASSIGN(MojoCdmProxyService); -}; - -} // namespace media - -#endif // MEDIA_MOJO_SERVICES_MOJO_CDM_PROXY_SERVICE_H_ diff --git a/chromium/media/mojo/services/mojo_cdm_proxy_unittest.cc b/chromium/media/mojo/services/mojo_cdm_proxy_unittest.cc deleted file mode 100644 index 8088e2ffafe..00000000000 --- a/chromium/media/mojo/services/mojo_cdm_proxy_unittest.cc +++ /dev/null @@ -1,390 +0,0 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include <stdint.h> - -#include <memory> - -#include "base/bind.h" -#include "base/macros.h" -#include "base/memory/weak_ptr.h" -#include "base/run_loop.h" -#include "base/test/gmock_callback_support.h" -#include "base/test/gtest_util.h" -#include "base/test/test_message_loop.h" -#include "media/base/mock_filters.h" -#include "media/cdm/cdm_proxy_context.h" -#include "media/mojo/mojom/cdm_proxy.mojom.h" -#include "media/mojo/services/mojo_cdm_proxy.h" -#include "media/mojo/services/mojo_cdm_proxy_service.h" -#include "media/mojo/services/mojo_cdm_service_context.h" -#include "mojo/public/cpp/bindings/interface_request.h" -#include "mojo/public/cpp/bindings/receiver.h" -#include "testing/gtest/include/gtest/gtest.h" - -using ::testing::_; -using ::testing::NotNull; -using ::testing::SaveArg; -using ::testing::StrictMock; - -namespace media { - -namespace { - -MATCHER_P(StatusEq, status, "") { - return (arg == cdm::CdmProxyClient::Status::kOk && - status == media::CdmProxy::Status::kOk) || - (arg == cdm::CdmProxyClient::Status::kFail && - status == media::CdmProxy::Status::kFail); -} - -constexpr uint32_t kCryptoSessionId = 1010; - -class MockCdmProxyContext : public CdmProxyContext {}; - -class MockCdmProxy : public media::CdmProxy, public media::CdmContext { - public: - MockCdmProxy() {} - ~MockCdmProxy() override = default; - - // media::CdmProxy implementation. - - base::WeakPtr<CdmContext> GetCdmContext() override { - return weak_factory_.GetWeakPtr(); - } - - MOCK_METHOD2(Initialize, void(Client* client, InitializeCB init_cb)); - - MOCK_METHOD5(Process, - void(Function function, - uint32_t crypto_session_id, - const std::vector<uint8_t>& input_data, - uint32_t expected_output_data_size, - ProcessCB process_cb)); - - MOCK_METHOD2(CreateMediaCryptoSession, - void(const std::vector<uint8_t>& input_data, - CreateMediaCryptoSessionCB create_media_crypto_session_cb)); - - MOCK_METHOD5(SetKey, - void(uint32_t crypto_session_id, - const std::vector<uint8_t>& key_id, - KeyType key_type, - const std::vector<uint8_t>& key_blob, - SetKeyCB set_key_cb)); - MOCK_METHOD3(RemoveKey, - void(uint32_t crypto_session_id, - const std::vector<uint8_t>& key_id, - RemoveKeyCB remove_key_cb)); - - // media::CdmContext implementation. - CdmProxyContext* GetCdmProxyContext() override { - return &mock_cdm_proxy_context_; - } - - private: - MockCdmProxyContext mock_cdm_proxy_context_; - base::WeakPtrFactory<MockCdmProxy> weak_factory_{this}; -}; - -class MockCdmProxyClient : public cdm::CdmProxyClient { - public: - MockCdmProxyClient() = default; - ~MockCdmProxyClient() override = default; - - MOCK_METHOD3(OnInitialized, - void(Status status, - Protocol protocol, - uint32_t crypto_session_id)); - MOCK_METHOD3(OnProcessed, - void(Status status, - const uint8_t* output_data, - uint32_t output_data_size)); - MOCK_METHOD3(OnMediaCryptoSessionCreated, - void(Status status, - uint32_t crypto_session_id, - uint64_t output_data)); - MOCK_METHOD1(OnKeySet, void(Status status)); - MOCK_METHOD1(OnKeyRemoved, void(Status status)); - MOCK_METHOD0(NotifyHardwareReset, void()); -}; - -} // namespace - -class MojoCdmProxyTest : public ::testing::Test { - public: - using Status = CdmProxy::Status; - - MojoCdmProxyTest() { - // Client side setup. - mojo::PendingRemote<mojom::CdmProxy> cdm_proxy_remote; - auto receiver = cdm_proxy_remote.InitWithNewPipeAndPassReceiver(); - mojo_cdm_proxy_.reset( - new MojoCdmProxy(std::move(cdm_proxy_remote), &client_)); - cdm_proxy_ = mojo_cdm_proxy_.get(); - - // Service side setup. - std::unique_ptr<MockCdmProxy> mock_cdm_proxy(new MockCdmProxy()); - mock_cdm_proxy_ = mock_cdm_proxy.get(); - mojo_cdm_proxy_service_.reset(new MojoCdmProxyService( - std::move(mock_cdm_proxy), &mojo_cdm_service_context_)); - receiver_.reset(new mojo::Receiver<mojom::CdmProxy>( - mojo_cdm_proxy_service_.get(), std::move(receiver))); - receiver_->set_disconnect_handler(base::BindOnce( - &MojoCdmProxyTest::OnConnectionError, base::Unretained(this))); - - base::RunLoop().RunUntilIdle(); - } - - ~MojoCdmProxyTest() override = default; - - void Initialize(Status expected_status = Status::kOk, - bool has_connection = true) { - if (has_connection) { - EXPECT_CALL(*mock_cdm_proxy_, Initialize(NotNull(), _)) - .WillOnce([&](auto, auto init_cb) { - std::move(init_cb).Run(expected_status, CdmProxy::Protocol::kNone, - kCryptoSessionId); - }); - EXPECT_CALL(client_, - OnInitialized(StatusEq(expected_status), - cdm::CdmProxyClient::kNone, kCryptoSessionId)) - .WillOnce(SaveArg<2>(&crypto_session_id_)); - } else { - // Client should always be called even without connection. But we only - // care about status in this case. - EXPECT_CALL(client_, OnInitialized(StatusEq(expected_status), _, _)); - } - - cdm_proxy_->Initialize(); - base::RunLoop().RunUntilIdle(); - } - - void Process(Status expected_status = Status::kOk, - bool has_connection = true) { - const std::vector<uint8_t> kInputData = {1, 2}; - const uint32_t kExpectedOutputDataSize = 111; - const std::vector<uint8_t> kOutputData = {3, 4, 5}; - - if (has_connection) { - EXPECT_CALL( - *mock_cdm_proxy_, - Process(CdmProxy::Function::kIntelNegotiateCryptoSessionKeyExchange, - crypto_session_id_, kInputData, kExpectedOutputDataSize, _)) - .WillOnce([&](auto, auto, auto, auto, auto process_cb) { - std::move(process_cb).Run(expected_status, kOutputData); - }); - EXPECT_CALL(client_, OnProcessed(StatusEq(expected_status), NotNull(), - kOutputData.size())); - } else { - // Client should always be called even without connection. But we only - // care about status in this case. - EXPECT_CALL(client_, OnProcessed(StatusEq(expected_status), _, _)); - } - - cdm_proxy_->Process( - cdm::CdmProxy::Function::kIntelNegotiateCryptoSessionKeyExchange, - crypto_session_id_, kInputData.data(), kInputData.size(), - kExpectedOutputDataSize); - base::RunLoop().RunUntilIdle(); - } - - void CreateMediaCryptoSession(Status expected_status = Status::kOk, - bool has_connection = true) { - const std::vector<uint8_t> kInputData = {6, 7}; - const uint32_t kMediaCryptoSessionId = 222; - const uint64_t kOutputData = 333; - - if (has_connection) { - EXPECT_CALL(*mock_cdm_proxy_, CreateMediaCryptoSession(kInputData, _)) - .WillOnce([&](auto, auto create_media_crypto_session_cb) { - std::move(create_media_crypto_session_cb) - .Run(expected_status, kMediaCryptoSessionId, kOutputData); - }); - EXPECT_CALL(client_, OnMediaCryptoSessionCreated( - StatusEq(expected_status), kMediaCryptoSessionId, - kOutputData)); - } else { - // Client should always be called even without connection. But we only - // care about status in this case. - EXPECT_CALL(client_, - OnMediaCryptoSessionCreated(StatusEq(expected_status), _, _)); - } - - cdm_proxy_->CreateMediaCryptoSession(kInputData.data(), kInputData.size()); - base::RunLoop().RunUntilIdle(); - } - - void SetKey() { - const std::vector<uint8_t> key_id = {8, 9}; - const std::vector<uint8_t> key_blob = {10, 11, 12}; - EXPECT_CALL(*mock_cdm_proxy_, - SetKey(crypto_session_id_, key_id, _, key_blob, _)) - .WillOnce([&](auto, auto, auto, auto, auto set_key_cb) { - std::move(set_key_cb).Run(Status::kOk); - }); - EXPECT_CALL(client_, OnKeySet(StatusEq(Status::kOk))); - cdm_proxy_->SetKey(crypto_session_id_, key_id.data(), key_id.size(), - cdm::CdmProxy::KeyType::kDecryptOnly, key_blob.data(), - key_blob.size()); - base::RunLoop().RunUntilIdle(); - } - - void RemoveKey() { - const std::vector<uint8_t> key_id = {13, 14}; - EXPECT_CALL(*mock_cdm_proxy_, RemoveKey(crypto_session_id_, key_id, _)) - .WillOnce([&](auto, auto, auto remove_key_cb) { - std::move(remove_key_cb).Run(Status::kOk); - }); - EXPECT_CALL(client_, OnKeyRemoved(StatusEq(Status::kOk))); - cdm_proxy_->RemoveKey(crypto_session_id_, key_id.data(), key_id.size()); - base::RunLoop().RunUntilIdle(); - } - - // Simulate connecting the media component with the CdmContext. Can only be - // called after the CdmProxy is successfully initialized (see Initialize()). - void SetCdm() { - int cdm_id = mojo_cdm_proxy_service_->GetCdmIdForTesting(); - cdm_context_ref_ = mojo_cdm_service_context_.GetCdmContextRef(cdm_id); - cdm_context_ = cdm_context_ref_->GetCdmContext(); - } - - CdmProxyContext* GetCdmProxyContext() { - return cdm_context_->GetCdmProxyContext(); - } - - void Destroy() { - mojo_cdm_proxy_.reset(); - base::RunLoop().RunUntilIdle(); - } - - void OnConnectionError() { mojo_cdm_proxy_service_.reset(); } - - void ForceConnectionError() { - receiver_->ResetWithReason(2, "Test closed connection."); - mojo_cdm_proxy_service_.reset(); - base::RunLoop().RunUntilIdle(); - } - - base::TestMessageLoop message_loop_; - uint32_t crypto_session_id_ = 0; - - // Client side members. - StrictMock<MockCdmProxyClient> client_; - std::unique_ptr<MojoCdmProxy> mojo_cdm_proxy_; - cdm::CdmProxy* cdm_proxy_ = nullptr; - - // Service side members. - MojoCdmServiceContext mojo_cdm_service_context_; - std::unique_ptr<MojoCdmProxyService> mojo_cdm_proxy_service_; - std::unique_ptr<mojo::Receiver<mojom::CdmProxy>> receiver_; - MockCdmProxy* mock_cdm_proxy_ = nullptr; - - // Media component side members. - std::unique_ptr<CdmContextRef> cdm_context_ref_; - CdmContext* cdm_context_ = nullptr; - - private: - DISALLOW_COPY_AND_ASSIGN(MojoCdmProxyTest); -}; - -TEST_F(MojoCdmProxyTest, Initialize) { - Initialize(); -} - -TEST_F(MojoCdmProxyTest, Initialize_Failure) { - Initialize(Status::kFail); -} - -TEST_F(MojoCdmProxyTest, Initialize_Twice) { - Initialize(); - EXPECT_CHECK_DEATH(Initialize()); -} - -TEST_F(MojoCdmProxyTest, Process) { - Initialize(); - Process(); -} - -TEST_F(MojoCdmProxyTest, Process_Failure) { - Initialize(); - Process(Status::kFail); -} - -TEST_F(MojoCdmProxyTest, CreateMediaCryptoSession) { - Initialize(); - Process(); - CreateMediaCryptoSession(); -} - -TEST_F(MojoCdmProxyTest, CreateMediaCryptoSession_Failure) { - Initialize(); - Process(); - CreateMediaCryptoSession(Status::kFail); -} - -TEST_F(MojoCdmProxyTest, SetKey) { - Initialize(); - Process(); - CreateMediaCryptoSession(); - SetKey(); -} - -TEST_F(MojoCdmProxyTest, RemoveKey) { - Initialize(); - Process(); - CreateMediaCryptoSession(); - RemoveKey(); -} - -TEST_F(MojoCdmProxyTest, Destroy) { - Initialize(); - Process(); - EXPECT_TRUE(mojo_cdm_proxy_service_); - Destroy(); - EXPECT_FALSE(mojo_cdm_proxy_service_); -} - -TEST_F(MojoCdmProxyTest, ConnectionError_BeforeInitialize) { - ForceConnectionError(); - Initialize(Status::kFail, false); -} - -TEST_F(MojoCdmProxyTest, ConnectionError_AfterInitialize) { - Initialize(); - Process(); - CreateMediaCryptoSession(); - - ForceConnectionError(); - - // Calling Process() and CreateMediaCryptoSession() without connection. These - // calls should fail but the client should still get notified (about the - // failure). - Process(Status::kFail, false); - CreateMediaCryptoSession(Status::kFail, false); -} - -TEST_F(MojoCdmProxyTest, GetCdmProxyContext) { - Initialize(); - SetCdm(); - EXPECT_TRUE(GetCdmProxyContext()); -} - -TEST_F(MojoCdmProxyTest, GetCdmProxyContext_AfterDestroy) { - Initialize(); - SetCdm(); - EXPECT_TRUE(GetCdmProxyContext()); - Destroy(); - EXPECT_FALSE(GetCdmProxyContext()); -} - -TEST_F(MojoCdmProxyTest, GetCdmProxyContext_AfterConnectionError) { - Initialize(); - SetCdm(); - EXPECT_TRUE(GetCdmProxyContext()); - ForceConnectionError(); - EXPECT_FALSE(GetCdmProxyContext()); -} - -} // namespace media diff --git a/chromium/media/mojo/services/mojo_cdm_service.cc b/chromium/media/mojo/services/mojo_cdm_service.cc index 80910478b16..16e60b82eb9 100644 --- a/chromium/media/mojo/services/mojo_cdm_service.cc +++ b/chromium/media/mojo/services/mojo_cdm_service.cc @@ -188,16 +188,8 @@ void MojoCdmService::OnCdmCreated( &MojoCdmService::OnDecryptorConnectionError, base::Unretained(this))); } - // If the |context_| is not null, we should support connecting the |cdm| with - // the media player in the same process, which also has access to the - // |context_|. Hence pass back the |cdm_id_| obtained from the |context_|. - // Otherwise, if the |cdm| has a valid CDM ID by itself, this CDM can proxy - // all or parts of its functionalities to another remote CDM or CdmProxy. In - // this case, just we pass the remote CDM ID back. - int cdm_id = context_ ? cdm_id_ : cdm_context->GetCdmId(); - cdm_promise_result->success = true; - std::move(callback).Run(std::move(cdm_promise_result), cdm_id, + std::move(callback).Run(std::move(cdm_promise_result), cdm_id_, std::move(decryptor_remote)); } diff --git a/chromium/media/mojo/services/mojo_cdm_service_context.cc b/chromium/media/mojo/services/mojo_cdm_service_context.cc index a49f74ea49a..6279a4c717f 100644 --- a/chromium/media/mojo/services/mojo_cdm_service_context.cc +++ b/chromium/media/mojo/services/mojo_cdm_service_context.cc @@ -11,58 +11,18 @@ #include "media/cdm/cdm_context_ref_impl.h" #include "media/mojo/services/mojo_cdm_service.h" -#if BUILDFLAG(ENABLE_CDM_PROXY) -#include "media/mojo/services/mojo_cdm_proxy_service.h" -#endif // BUILDFLAG(ENABLE_CDM_PROXY) - namespace media { namespace { // Helper function to get the next unique (per-process) CDM ID to be assigned to -// a CDM or CdmProxy. It will be used to locate the CDM by the media players -// living in the same process. +// a CDM. It will be used to locate the CDM by the media players living in the +// same process. int GetNextCdmId() { static int g_next_cdm_id = CdmContext::kInvalidCdmId + 1; return g_next_cdm_id++; } -#if BUILDFLAG(ENABLE_CDM_PROXY) -class CdmProxyContextRef : public CdmContextRef, public CdmContext { - public: - explicit CdmProxyContextRef(base::WeakPtr<CdmContext> cdm_context) - : cdm_context_(cdm_context) {} - ~CdmProxyContextRef() final {} - - // CdmContextRef implementation. - CdmContext* GetCdmContext() final { return this; } - - private: - // CdmContext implementation. - std::unique_ptr<CallbackRegistration> RegisterEventCB( - EventCB event_cb) final { - DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); - return cdm_context_ ? cdm_context_->RegisterEventCB(std::move(event_cb)) - : nullptr; - } - - Decryptor* GetDecryptor() final { - DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); - return cdm_context_ ? cdm_context_->GetDecryptor() : nullptr; - } - - CdmProxyContext* GetCdmProxyContext() final { - DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); - return cdm_context_ ? cdm_context_->GetCdmProxyContext() : nullptr; - } - - base::WeakPtr<CdmContext> cdm_context_; - THREAD_CHECKER(thread_checker_); - - DISALLOW_COPY_AND_ASSIGN(CdmProxyContextRef); -}; -#endif // BUILDFLAG(ENABLE_CDM_PROXY) - } // namespace MojoCdmServiceContext::MojoCdmServiceContext() = default; @@ -83,23 +43,6 @@ void MojoCdmServiceContext::UnregisterCdm(int cdm_id) { cdm_services_.erase(cdm_id); } -#if BUILDFLAG(ENABLE_CDM_PROXY) -int MojoCdmServiceContext::RegisterCdmProxy( - MojoCdmProxyService* cdm_proxy_service) { - DCHECK(cdm_proxy_service); - int cdm_id = GetNextCdmId(); - cdm_proxy_services_[cdm_id] = cdm_proxy_service; - DVLOG(1) << __func__ << ": CdmProxyService registered with CDM ID " << cdm_id; - return cdm_id; -} - -void MojoCdmServiceContext::UnregisterCdmProxy(int cdm_id) { - DVLOG(1) << __func__ << ": cdm_id = " << cdm_id; - DCHECK(cdm_proxy_services_.count(cdm_id)); - cdm_proxy_services_.erase(cdm_id); -} -#endif // BUILDFLAG(ENABLE_CDM_PROXY) - std::unique_ptr<CdmContextRef> MojoCdmServiceContext::GetCdmContextRef( int cdm_id) { DVLOG(1) << __func__ << ": cdm_id = " << cdm_id; @@ -114,15 +57,6 @@ std::unique_ptr<CdmContextRef> MojoCdmServiceContext::GetCdmContextRef( return std::make_unique<CdmContextRefImpl>(cdm_service->second->GetCdm()); } -#if BUILDFLAG(ENABLE_CDM_PROXY) - // Next check all CdmProxies. - auto cdm_proxy_service = cdm_proxy_services_.find(cdm_id); - if (cdm_proxy_service != cdm_proxy_services_.end()) { - return std::make_unique<CdmProxyContextRef>( - cdm_proxy_service->second->GetCdmContext()); - } -#endif // BUILDFLAG(ENABLE_CDM_PROXY) - LOG(ERROR) << "CdmContextRef cannot be obtained for CDM ID: " << cdm_id; return nullptr; } diff --git a/chromium/media/mojo/services/mojo_cdm_service_context.h b/chromium/media/mojo/services/mojo_cdm_service_context.h index f074cf00b19..07290ba2a8f 100644 --- a/chromium/media/mojo/services/mojo_cdm_service_context.h +++ b/chromium/media/mojo/services/mojo_cdm_service_context.h @@ -16,10 +16,8 @@ namespace media { -class CdmProxy; class CdmContextRef; class MojoCdmService; -class MojoCdmProxyService; // A class that creates, owns and manages all MojoCdmService instances. class MEDIA_MOJO_EXPORT MojoCdmServiceContext { @@ -33,15 +31,6 @@ class MEDIA_MOJO_EXPORT MojoCdmServiceContext { // Unregisters the CDM. Must be called before the CDM is destroyed. void UnregisterCdm(int cdm_id); -#if BUILDFLAG(ENABLE_CDM_PROXY) - // Registers the |cdm_proxy_service| and returns a unique (per-process) CDM - // ID. - int RegisterCdmProxy(MojoCdmProxyService* cdm_proxy_service); - - // Unregisters the CdmProxy. Must be called before the CdmProxy is destroyed. - void UnregisterCdmProxy(int cdm_id); -#endif // BUILDFLAG(ENABLE_CDM_PROXY) - // Returns the CdmContextRef associated with |cdm_id|. std::unique_ptr<CdmContextRef> GetCdmContextRef(int cdm_id); @@ -49,11 +38,6 @@ class MEDIA_MOJO_EXPORT MojoCdmServiceContext { // A map between CDM ID and MojoCdmService. std::map<int, MojoCdmService*> cdm_services_; -#if BUILDFLAG(ENABLE_CDM_PROXY) - // A map between CDM ID and MojoCdmProxyService. - std::map<int, MojoCdmProxyService*> cdm_proxy_services_; -#endif // BUILDFLAG(ENABLE_CDM_PROXY) - DISALLOW_COPY_AND_ASSIGN(MojoCdmServiceContext); }; diff --git a/chromium/media/mojo/services/mojo_decryptor_service.cc b/chromium/media/mojo/services/mojo_decryptor_service.cc index 32ad28c74ac..900808c4f37 100644 --- a/chromium/media/mojo/services/mojo_decryptor_service.cc +++ b/chromium/media/mojo/services/mojo_decryptor_service.cc @@ -48,29 +48,6 @@ class FrameResourceReleaserImpl final : public mojom::FrameResourceReleaser { } // namespace -// static -std::unique_ptr<MojoDecryptorService> MojoDecryptorService::Create( - int cdm_id, - MojoCdmServiceContext* mojo_cdm_service_context) { - auto cdm_context_ref = mojo_cdm_service_context->GetCdmContextRef(cdm_id); - if (!cdm_context_ref) { - DVLOG(1) << "CdmContextRef not found for CDM ID: " << cdm_id; - return nullptr; - } - - auto* cdm_context = cdm_context_ref->GetCdmContext(); - DCHECK(cdm_context); - - auto* decryptor = cdm_context->GetDecryptor(); - if (!decryptor) { - DVLOG(1) << "CdmContext does not support Decryptor"; - return nullptr; - } - - return std::make_unique<MojoDecryptorService>(decryptor, - std::move(cdm_context_ref)); -} - MojoDecryptorService::MojoDecryptorService( media::Decryptor* decryptor, std::unique_ptr<CdmContextRef> cdm_context_ref) diff --git a/chromium/media/mojo/services/mojo_decryptor_service.h b/chromium/media/mojo/services/mojo_decryptor_service.h index b4fb2e7a699..4c9d6a02b0e 100644 --- a/chromium/media/mojo/services/mojo_decryptor_service.h +++ b/chromium/media/mojo/services/mojo_decryptor_service.h @@ -21,7 +21,6 @@ namespace media { class DecoderBuffer; -class MojoCdmServiceContext; class MojoDecoderBufferReader; class MojoDecoderBufferWriter; @@ -32,10 +31,6 @@ class MEDIA_MOJO_EXPORT MojoDecryptorService : public mojom::Decryptor { using StreamType = media::Decryptor::StreamType; using Status = media::Decryptor::Status; - static std::unique_ptr<MojoDecryptorService> Create( - int cdm_id, - MojoCdmServiceContext* mojo_cdm_service_context); - // If |cdm_context_ref| is null, caller must ensure that |decryptor| outlives // |this|. Otherwise, |decryptor| is guaranteed to be valid as long as // |cdm_context_ref| is held. diff --git a/chromium/media/mojo/services/mojo_media_client.cc b/chromium/media/mojo/services/mojo_media_client.cc index 4b4fca75d96..b9f53ad90c5 100644 --- a/chromium/media/mojo/services/mojo_media_client.cc +++ b/chromium/media/mojo/services/mojo_media_client.cc @@ -11,10 +11,6 @@ #include "media/base/renderer.h" #include "media/base/video_decoder.h" -#if BUILDFLAG(ENABLE_CDM_PROXY) -#include "media/cdm/cdm_proxy.h" -#endif // BUILDFLAG(ENABLE_CDM_PROXY) - namespace media { MojoMediaClient::MojoMediaClient() = default; @@ -44,7 +40,7 @@ std::unique_ptr<VideoDecoder> MojoMediaClient::CreateVideoDecoder( } std::unique_ptr<Renderer> MojoMediaClient::CreateRenderer( - service_manager::mojom::InterfaceProvider* host_interfaces, + mojom::FrameInterfaceFactory* frame_interfaces, scoped_refptr<base::SingleThreadTaskRunner> task_runner, MediaLog* media_log, const std::string& audio_device_id) { @@ -53,7 +49,7 @@ std::unique_ptr<Renderer> MojoMediaClient::CreateRenderer( #if BUILDFLAG(ENABLE_CAST_RENDERER) std::unique_ptr<Renderer> MojoMediaClient::CreateCastRenderer( - service_manager::mojom::InterfaceProvider* host_interfaces, + mojom::FrameInterfaceFactory* frame_interfaces, scoped_refptr<base::SingleThreadTaskRunner> task_runner, MediaLog* media_log, const base::UnguessableToken& overlay_plane_id) { @@ -62,15 +58,8 @@ std::unique_ptr<Renderer> MojoMediaClient::CreateCastRenderer( #endif // BUILDFLAG(ENABLE_CAST_RENDERER) std::unique_ptr<CdmFactory> MojoMediaClient::CreateCdmFactory( - service_manager::mojom::InterfaceProvider* host_interfaces) { - return nullptr; -} - -#if BUILDFLAG(ENABLE_CDM_PROXY) -std::unique_ptr<CdmProxy> MojoMediaClient::CreateCdmProxy( - const base::Token& cdm_guid) { + mojom::FrameInterfaceFactory* frame_interfaces) { return nullptr; } -#endif // BUILDFLAG(ENABLE_CDM_PROXY) } // namespace media diff --git a/chromium/media/mojo/services/mojo_media_client.h b/chromium/media/mojo/services/mojo_media_client.h index 03e62e3f3f0..03263ee3c63 100644 --- a/chromium/media/mojo/services/mojo_media_client.h +++ b/chromium/media/mojo/services/mojo_media_client.h @@ -15,30 +15,23 @@ #include "media/base/overlay_info.h" #include "media/media_buildflags.h" #include "media/mojo/buildflags.h" +#include "media/mojo/mojom/frame_interface_factory.mojom.h" #include "media/mojo/mojom/video_decoder.mojom.h" #include "media/mojo/services/media_mojo_export.h" #include "media/video/supported_video_decoder_config.h" namespace base { class SingleThreadTaskRunner; -class Token; } // namespace base namespace gfx { class ColorSpace; } // namespace gfx -namespace service_manager { -namespace mojom { -class InterfaceProvider; -} // namespace mojom -} // namespace service_manager - namespace media { class AudioDecoder; class CdmFactory; -class CdmProxy; class MediaLog; class Renderer; class VideoDecoder; @@ -76,7 +69,7 @@ class MEDIA_MOJO_EXPORT MojoMediaClient { // TODO(hubbe): Find out whether we should pass in |target_color_space| here. // TODO(guohuideng): Merge this function into CreateCastRenderer. virtual std::unique_ptr<Renderer> CreateRenderer( - service_manager::mojom::InterfaceProvider* host_interfaces, + mojom::FrameInterfaceFactory* frame_interfaces, scoped_refptr<base::SingleThreadTaskRunner> task_runner, MediaLog* media_log, const std::string& audio_device_id); @@ -88,23 +81,17 @@ class MEDIA_MOJO_EXPORT MojoMediaClient { // associtated with. // Chromecast also uses CreateRenderer to create "audio only" renderers. virtual std::unique_ptr<Renderer> CreateCastRenderer( - service_manager::mojom::InterfaceProvider* host_interfaces, + mojom::FrameInterfaceFactory* frame_interfaces, scoped_refptr<base::SingleThreadTaskRunner> task_runner, MediaLog* media_log, const base::UnguessableToken& overlay_plane_id); #endif // BUILDFLAG(ENABLE_CAST_RENDERER) - // Returns the CdmFactory to be used by MojoCdmService. |host_interfaces| can + // Returns the CdmFactory to be used by MojoCdmService. |frame_interfaces| can // be used to request interfaces provided remotely by the host. It may be a // nullptr if the host chose not to bind the InterfacePtr. virtual std::unique_ptr<CdmFactory> CreateCdmFactory( - service_manager::mojom::InterfaceProvider* host_interfaces); - -#if BUILDFLAG(ENABLE_CDM_PROXY) - // Creates a CdmProxy that proxies part of CDM functionalities to a different - // entity, e.g. hardware CDM modules. - virtual std::unique_ptr<CdmProxy> CreateCdmProxy(const base::Token& cdm_guid); -#endif // BUILDFLAG(ENABLE_CDM_PROXY) + mojom::FrameInterfaceFactory* frame_interfaces); protected: MojoMediaClient(); diff --git a/chromium/media/mojo/services/mojo_video_encode_accelerator_provider.cc b/chromium/media/mojo/services/mojo_video_encode_accelerator_provider.cc index c2644513bdc..0ade6cc8fd8 100644 --- a/chromium/media/mojo/services/mojo_video_encode_accelerator_provider.cc +++ b/chromium/media/mojo/services/mojo_video_encode_accelerator_provider.cc @@ -7,7 +7,6 @@ #include <memory> #include <utility> -#include "base/logging.h" #include "media/base/bind_to_current_loop.h" #include "media/base/limits.h" #include "media/gpu/gpu_video_encode_accelerator_factory.h" diff --git a/chromium/media/mojo/services/test_mojo_media_client.cc b/chromium/media/mojo/services/test_mojo_media_client.cc index aa6240b7912..7d51f3db006 100644 --- a/chromium/media/mojo/services/test_mojo_media_client.cc +++ b/chromium/media/mojo/services/test_mojo_media_client.cc @@ -8,6 +8,7 @@ #include "base/run_loop.h" #include "base/threading/thread_task_runner_handle.h" +#include "build/build_config.h" #include "media/audio/audio_device_description.h" #include "media/audio/audio_manager.h" #include "media/audio/audio_output_stream_sink.h" @@ -21,12 +22,6 @@ #include "media/renderers/default_decoder_factory.h" #include "media/renderers/default_renderer_factory.h" -#if BUILDFLAG(ENABLE_CDM_PROXY) -#include "media/cdm/cdm_paths.h" // nogncheck -#include "media/cdm/cdm_proxy.h" // nogncheck -#include "media/cdm/library_cdm/clear_key_cdm/clear_key_cdm_proxy.h" // nogncheck -#endif - namespace media { TestMojoMediaClient::TestMojoMediaClient() = default; @@ -55,7 +50,7 @@ void TestMojoMediaClient::Initialize() { } std::unique_ptr<Renderer> TestMojoMediaClient::CreateRenderer( - service_manager::mojom::InterfaceProvider* host_interfaces, + mojom::FrameInterfaceFactory* frame_interfaces, scoped_refptr<base::SingleThreadTaskRunner> task_runner, MediaLog* media_log, const std::string& /* audio_device_id */) { @@ -65,9 +60,15 @@ std::unique_ptr<Renderer> TestMojoMediaClient::CreateRenderer( } if (!renderer_factory_) { +#if defined(OS_ANDROID) + renderer_factory_ = std::make_unique<DefaultRendererFactory>( + media_log, decoder_factory_.get(), + DefaultRendererFactory::GetGpuFactoriesCB()); +#else renderer_factory_ = std::make_unique<DefaultRendererFactory>( media_log, decoder_factory_.get(), DefaultRendererFactory::GetGpuFactoriesCB(), nullptr); +#endif } // We cannot share AudioOutputStreamSink or NullVideoSink among different @@ -91,29 +92,19 @@ std::unique_ptr<Renderer> TestMojoMediaClient::CreateRenderer( #if BUILDFLAG(ENABLE_CAST_RENDERER) std::unique_ptr<Renderer> TestMojoMediaClient::CreateCastRenderer( - service_manager::mojom::InterfaceProvider* host_interfaces, + mojom::FrameInterfaceFactory* frame_interfaces, scoped_refptr<base::SingleThreadTaskRunner> task_runner, MediaLog* media_log, const base::UnguessableToken& /* overlay_plane_id */) { - return CreateRenderer(host_interfaces, task_runner, media_log, std::string()); + return CreateRenderer(frame_interfaces, task_runner, media_log, + std::string()); } #endif // BUILDFLAG(ENABLE_CAST_RENDERER) std::unique_ptr<CdmFactory> TestMojoMediaClient::CreateCdmFactory( - service_manager::mojom::InterfaceProvider* /* host_interfaces */) { + mojom::FrameInterfaceFactory* /* frame_interfaces */) { DVLOG(1) << __func__; return std::make_unique<DefaultCdmFactory>(); } -#if BUILDFLAG(ENABLE_CDM_PROXY) -std::unique_ptr<CdmProxy> TestMojoMediaClient::CreateCdmProxy( - const base::Token& cdm_guid) { - DVLOG(1) << __func__ << ": cdm_guid = " << cdm_guid.ToString(); - if (cdm_guid == kClearKeyCdmGuid) - return std::make_unique<ClearKeyCdmProxy>(); - - return nullptr; -} -#endif // BUILDFLAG(ENABLE_CDM_PROXY) - } // namespace media diff --git a/chromium/media/mojo/services/test_mojo_media_client.h b/chromium/media/mojo/services/test_mojo_media_client.h index d72fedd59a2..c8899c05404 100644 --- a/chromium/media/mojo/services/test_mojo_media_client.h +++ b/chromium/media/mojo/services/test_mojo_media_client.h @@ -30,22 +30,19 @@ class TestMojoMediaClient : public MojoMediaClient { // MojoMediaClient implementation. void Initialize() final; std::unique_ptr<Renderer> CreateRenderer( - service_manager::mojom::InterfaceProvider* host_interfaces, + mojom::FrameInterfaceFactory* frame_interfaces, scoped_refptr<base::SingleThreadTaskRunner> task_runner, MediaLog* media_log, const std::string& audio_device_id) final; #if BUILDFLAG(ENABLE_CAST_RENDERER) std::unique_ptr<Renderer> CreateCastRenderer( - service_manager::mojom::InterfaceProvider* host_interfaces, + mojom::FrameInterfaceFactory* frame_interfaces, scoped_refptr<base::SingleThreadTaskRunner> task_runner, MediaLog* media_log, const base::UnguessableToken& overlay_plane_id) final; #endif // BUILDFLAG(ENABLE_CAST_RENDERER) std::unique_ptr<CdmFactory> CreateCdmFactory( - service_manager::mojom::InterfaceProvider* /* host_interfaces */) final; -#if BUILDFLAG(ENABLE_CDM_PROXY) - std::unique_ptr<CdmProxy> CreateCdmProxy(const base::Token& cdm_guid) final; -#endif // BUILDFLAG(ENABLE_CDM_PROXY) + mojom::FrameInterfaceFactory* /* frame_interfaces */) final; private: std::unique_ptr<AudioManager> audio_manager_; diff --git a/chromium/media/mojo/services/video_decode_perf_history_unittest.cc b/chromium/media/mojo/services/video_decode_perf_history_unittest.cc index ac736bf0ae0..3a5a11b8d66 100644 --- a/chromium/media/mojo/services/video_decode_perf_history_unittest.cc +++ b/chromium/media/mojo/services/video_decode_perf_history_unittest.cc @@ -52,6 +52,7 @@ class FakeVideoDecodeStatsDB : public VideoDecodeStatsDB { // Call CompleteInitialize(...) to run |init_cb| callback. void Initialize(base::OnceCallback<void(bool)> init_cb) override { + EXPECT_FALSE(!!pendnding_init_cb_); pendnding_init_cb_ = std::move(init_cb); } @@ -59,7 +60,7 @@ class FakeVideoDecodeStatsDB : public VideoDecodeStatsDB { // for success. void CompleteInitialize(bool success) { DVLOG(2) << __func__ << " running with success = " << success; - EXPECT_FALSE(!pendnding_init_cb_); + EXPECT_TRUE(!!pendnding_init_cb_); std::move(pendnding_init_cb_).Run(success); } @@ -1037,4 +1038,50 @@ INSTANTIATE_TEST_SUITE_P(VaryDBInitTiming, VideoDecodePerfHistoryParamTest, ::testing::ValuesIn(kPerfHistoryTestParams)); -} // namespace media +// +// The following test are not parameterized. They instead always hard code +// deferred initialization. +// + +TEST_F(VideoDecodePerfHistoryTest, ClearHistoryTriggersSuccessfulInitialize) { + // Clear the DB. Completion callback shouldn't fire until initialize + // completes. + EXPECT_CALL(*this, MockOnClearedHistory()).Times(0); + perf_history_->ClearHistory( + base::BindOnce(&VideoDecodePerfHistoryParamTest::MockOnClearedHistory, + base::Unretained(this))); + + // Give completion callback a chance to fire. Confirm it did not fire. + task_environment_.RunUntilIdle(); + testing::Mock::VerifyAndClearExpectations(this); + + // Expect completion callback after we successfully initialize. + EXPECT_CALL(*this, MockOnClearedHistory()); + GetFakeDB()->CompleteInitialize(true); + + // Give deferred callback a chance to fire. + task_environment_.RunUntilIdle(); +} + +TEST_F(VideoDecodePerfHistoryTest, ClearHistoryTriggersFailedInitialize) { + // Clear the DB. Completion callback shouldn't fire until initialize + // completes. + EXPECT_CALL(*this, MockOnClearedHistory()).Times(0); + perf_history_->ClearHistory( + base::BindOnce(&VideoDecodePerfHistoryParamTest::MockOnClearedHistory, + base::Unretained(this))); + + // Give completion callback a chance to fire. Confirm it did not fire. + task_environment_.RunUntilIdle(); + testing::Mock::VerifyAndClearExpectations(this); + + // Expect completion callback after completing initialize. "Failure" is still + // a form of completion. + EXPECT_CALL(*this, MockOnClearedHistory()); + GetFakeDB()->CompleteInitialize(false); + + // Give deferred callback a chance to fire. + task_environment_.RunUntilIdle(); +} + +} // namespace media
\ No newline at end of file diff --git a/chromium/media/mojo/services/watch_time_recorder.cc b/chromium/media/mojo/services/watch_time_recorder.cc index 512e4c950a1..6c1d44c7632 100644 --- a/chromium/media/mojo/services/watch_time_recorder.cc +++ b/chromium/media/mojo/services/watch_time_recorder.cc @@ -421,7 +421,7 @@ void WatchTimeRecorder::RecordUkmPlaybackData() { base::flat_set<AudioCodecProfile> aac_profiles; - base::TimeDelta total_watch_time; + base::TimeDelta total_foreground_audible_watch_time; for (auto& ukm_record : ukm_records_) { ukm::builders::Media_BasicPlayback builder(source_id_); @@ -446,7 +446,11 @@ void WatchTimeRecorder::RecordUkmPlaybackData() { // Only one of these keys should be present. DCHECK(!recorded_all_metric); recorded_all_metric = true; - total_watch_time += kv.second; + + // We should only add to the total watchtime if we were not in the + // background and not muted. + if (!properties_->is_muted && !properties_->is_background) + total_foreground_audible_watch_time += kv.second; builder.SetWatchTime(kv.second.InMilliseconds()); if (ukm_record.total_underflow_count) { @@ -554,10 +558,10 @@ void WatchTimeRecorder::RecordUkmPlaybackData() { base::UmaHistogramEnumeration("Media.AudioCodecProfile.AAC", profile); } - if (total_watch_time > base::TimeDelta()) { + if (total_foreground_audible_watch_time > base::TimeDelta()) { std::move(record_playback_cb_) - .Run(total_watch_time, last_timestamp_, properties_->has_video, - properties_->has_audio); + .Run(total_foreground_audible_watch_time, last_timestamp_, + properties_->has_video, properties_->has_audio); } ukm_records_.clear(); |