1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "media/mojo/services/service_factory_impl.h"
7 #include "base/logging.h"
8 #include "media/base/cdm_factory.h"
9 #include "media/base/media_log.h"
10 #include "media/base/renderer_factory.h"
11 #include "media/mojo/services/mojo_cdm_service.h"
12 #include "media/mojo/services/mojo_media_client.h"
13 #include "media/mojo/services/mojo_renderer_service.h"
14 #include "mojo/application/public/cpp/app_lifetime_helper.h"
18 ServiceFactoryImpl::ServiceFactoryImpl(
19 mojo::InterfaceRequest
<interfaces::ServiceFactory
> request
,
20 mojo::ServiceProvider
* service_provider
,
21 scoped_refptr
<MediaLog
> media_log
,
22 scoped_ptr
<mojo::AppRefCount
> parent_app_refcount
)
23 : binding_(this, request
.Pass()),
24 service_provider_(service_provider
),
25 media_log_(media_log
),
26 parent_app_refcount_(parent_app_refcount
.Pass()) {
27 DVLOG(1) << __FUNCTION__
;
30 ServiceFactoryImpl::~ServiceFactoryImpl() {
31 DVLOG(1) << __FUNCTION__
;
34 // interfaces::ServiceFactory implementation.
35 void ServiceFactoryImpl::CreateRenderer(
36 mojo::InterfaceRequest
<interfaces::Renderer
> request
) {
37 // The created object is owned by the pipe.
38 new MojoRendererService(cdm_service_context_
.GetWeakPtr(),
39 GetRendererFactory(), media_log_
, request
.Pass());
42 void ServiceFactoryImpl::CreateCdm(
43 mojo::InterfaceRequest
<interfaces::ContentDecryptionModule
> request
) {
44 // The created object is owned by the pipe.
45 new MojoCdmService(cdm_service_context_
.GetWeakPtr(), service_provider_
,
46 GetCdmFactory(), request
.Pass());
49 RendererFactory
* ServiceFactoryImpl::GetRendererFactory() {
50 if (!renderer_factory_
)
52 MojoMediaClient::Get()->CreateRendererFactory(media_log_
);
53 return renderer_factory_
.get();
56 CdmFactory
* ServiceFactoryImpl::GetCdmFactory() {
58 cdm_factory_
= MojoMediaClient::Get()->CreateCdmFactory();
59 return cdm_factory_
.get();