summaryrefslogtreecommitdiffstats
path: root/media/mojo
diff options
context:
space:
mode:
authorxhwang <xhwang@chromium.org>2016-02-11 15:26:25 -0800
committerCommit bot <commit-bot@chromium.org>2016-02-11 23:28:34 +0000
commit9efb1d1a266758c404c991ebb81f2f700133e516 (patch)
tree9686fb6db6a5deb08e37d90ad4012103f2ff1ac9 /media/mojo
parent9a62870fce8cd82a7dc43ea4786313c1b199e674 (diff)
downloadchromium_src-9efb1d1a266758c404c991ebb81f2f700133e516.zip
chromium_src-9efb1d1a266758c404c991ebb81f2f700133e516.tar.gz
chromium_src-9efb1d1a266758c404c991ebb81f2f700133e516.tar.bz2
media: Refactor MojoMediaClient.
Instead of specifying a platform based MojoMediaClient at compile time, provide the capability of setting one at run time. This improves the flexibility of using MojoMediaApplication in different cases. For example, on desktop, we may want to run the MojoMediaApplication in the utility process (for the CDM service) and in the GPU process (for hardware decoding). In those two cases, we'll want to specify two different MojoMediaClients even though we are on the same platform. BUG=570357,571155 Review URL: https://codereview.chromium.org/1688123002 Cr-Commit-Position: refs/heads/master@{#375037}
Diffstat (limited to 'media/mojo')
-rw-r--r--media/mojo/services/BUILD.gn22
-rw-r--r--media/mojo/services/android_mojo_media_client.cc30
-rw-r--r--media/mojo/services/android_mojo_media_client.h29
-rw-r--r--media/mojo/services/default_mojo_media_client.cc106
-rw-r--r--media/mojo/services/default_mojo_media_client.h48
-rw-r--r--media/mojo/services/main.cc4
-rw-r--r--media/mojo/services/mojo_media_application.cc37
-rw-r--r--media/mojo/services/mojo_media_application.h17
-rw-r--r--media/mojo/services/mojo_media_client.h9
9 files changed, 192 insertions, 110 deletions
diff --git a/media/mojo/services/BUILD.gn b/media/mojo/services/BUILD.gn
index 0f68858..39384c9 100644
--- a/media/mojo/services/BUILD.gn
+++ b/media/mojo/services/BUILD.gn
@@ -150,30 +150,24 @@ source_set("application") {
"service_factory_impl.h",
]
- public_configs = [ ":enable_mojo_media_config" ]
-
- deps = [
- ":cdm_service",
- ":renderer_service",
- "//mojo/shell/public/cpp",
- ]
-}
-
-source_set("default_application") {
if (is_android) {
- sources = [
+ sources += [
"android_mojo_media_client.cc",
+ "android_mojo_media_client.h",
]
} else {
- sources = [
+ sources += [
"default_mojo_media_client.cc",
+ "default_mojo_media_client.h",
]
}
public_configs = [ ":enable_mojo_media_config" ]
deps = [
- ":application",
+ ":cdm_service",
+ ":renderer_service",
+ "//mojo/shell/public/cpp",
]
}
@@ -203,7 +197,7 @@ mojo_native_application("media") {
]
deps = [
- ":default_application",
+ ":application",
"//mojo/logging",
"//mojo/public/c/system:for_shared_library",
]
diff --git a/media/mojo/services/android_mojo_media_client.cc b/media/mojo/services/android_mojo_media_client.cc
index efd25c2..a7c270f 100644
--- a/media/mojo/services/android_mojo_media_client.cc
+++ b/media/mojo/services/android_mojo_media_client.cc
@@ -2,13 +2,9 @@
// 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_media_client.h"
+#include "media/mojo/services/android_mojo_media_client.h"
-#include "base/macros.h"
-#include "base/memory/scoped_ptr.h"
#include "media/base/android/android_cdm_factory.h"
-#include "media/base/bind_to_current_loop.h"
-#include "media/base/media.h"
#include "media/mojo/interfaces/provision_fetcher.mojom.h"
#include "media/mojo/services/mojo_provision_fetcher.h"
#include "mojo/shell/public/cpp/connect.h"
@@ -16,6 +12,7 @@
namespace media {
namespace {
+
scoped_ptr<ProvisionFetcher> CreateProvisionFetcher(
mojo::shell::mojom::InterfaceProvider* service_provider) {
interfaces::ProvisionFetcherPtr provision_fetcher_ptr;
@@ -24,24 +21,17 @@ scoped_ptr<ProvisionFetcher> CreateProvisionFetcher(
new MojoProvisionFetcher(std::move(provision_fetcher_ptr)));
}
-class AndroidMojoMediaClient : public MojoMediaClient {
- public:
- AndroidMojoMediaClient() {}
+} // namespace
- // MojoMediaClient overrides.
- scoped_ptr<CdmFactory> CreateCdmFactory(
- mojo::shell::mojom::InterfaceProvider* service_provider) override {
- return make_scoped_ptr(new AndroidCdmFactory(
- base::Bind(&CreateProvisionFetcher, service_provider)));
- }
+AndroidMojoMediaClient::AndroidMojoMediaClient() {}
- private:
- DISALLOW_COPY_AND_ASSIGN(AndroidMojoMediaClient);
-};
-} // namespace (anonymous)
+AndroidMojoMediaClient::~AndroidMojoMediaClient() {}
-scoped_ptr<MojoMediaClient> MojoMediaClient::Create() {
- return make_scoped_ptr(new AndroidMojoMediaClient());
+// MojoMediaClient overrides.
+scoped_ptr<CdmFactory> AndroidMojoMediaClient::CreateCdmFactory(
+ mojo::shell::mojom::InterfaceProvider* service_provider) {
+ return make_scoped_ptr(new AndroidCdmFactory(
+ base::Bind(&CreateProvisionFetcher, service_provider)));
}
} // namespace media
diff --git a/media/mojo/services/android_mojo_media_client.h b/media/mojo/services/android_mojo_media_client.h
new file mode 100644
index 0000000..b625d16
--- /dev/null
+++ b/media/mojo/services/android_mojo_media_client.h
@@ -0,0 +1,29 @@
+// Copyright 2014 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_ANDROID_MOJO_MEDIA_CLIENT_H_
+#define MEDIA_MOJO_SERVICES_ANDROID_MOJO_MEDIA_CLIENT_H_
+
+#include "base/macros.h"
+#include "media/base/media_export.h"
+#include "media/mojo/services/mojo_media_client.h"
+
+namespace media {
+
+class MEDIA_EXPORT AndroidMojoMediaClient : public MojoMediaClient {
+ public:
+ AndroidMojoMediaClient();
+ ~AndroidMojoMediaClient() final;
+
+ // MojoMediaClient implementation.
+ scoped_ptr<CdmFactory> CreateCdmFactory(
+ mojo::shell::mojom::InterfaceProvider* service_provider) final;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(AndroidMojoMediaClient);
+};
+
+} // namespace media
+
+#endif // MEDIA_MOJO_SERVICES_ANDROID_MOJO_MEDIA_CLIENT_H_
diff --git a/media/mojo/services/default_mojo_media_client.cc b/media/mojo/services/default_mojo_media_client.cc
index 4facbd1..c602f64 100644
--- a/media/mojo/services/default_mojo_media_client.cc
+++ b/media/mojo/services/default_mojo_media_client.cc
@@ -2,13 +2,10 @@
// 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_media_client.h"
+#include "media/mojo/services/default_mojo_media_client.h"
-#include "base/macros.h"
-#include "base/memory/scoped_ptr.h"
#include "media/audio/audio_manager_base.h"
#include "media/audio/audio_output_stream_sink.h"
-#include "media/audio/fake_audio_log_factory.h"
#include "media/base/audio_hardware_config.h"
#include "media/base/media.h"
#include "media/base/null_video_sink.h"
@@ -18,72 +15,55 @@
namespace media {
-namespace {
-class DefaultMojoMediaClient : public MojoMediaClient {
- public:
- DefaultMojoMediaClient() {}
-
- // MojoMediaClient overrides.
- void Initialize() override {
- InitializeMediaLibrary();
- // TODO(dalecurtis): We should find a single owner per process for the audio
- // manager or make it a lazy instance. It's not safe to call Get()/Create()
- // across multiple threads...
- //
- // TODO(dalecurtis): Eventually we'll want something other than a fake audio
- // log factory here too. We should probably at least DVLOG() such info.
- AudioManager* audio_manager = AudioManager::Get();
- if (!audio_manager)
- audio_manager = media::AudioManager::Create(&fake_audio_log_factory_);
-
- audio_hardware_config_.reset(new AudioHardwareConfig(
- audio_manager->GetInputStreamParameters(
- AudioManagerBase::kDefaultDeviceId),
- audio_manager->GetDefaultOutputStreamParameters()));
- }
-
- scoped_ptr<RendererFactory> CreateRendererFactory(
- const scoped_refptr<MediaLog>& media_log) override {
- return make_scoped_ptr(new DefaultRendererFactory(media_log, nullptr,
- *audio_hardware_config_));
- }
-
- AudioRendererSink* CreateAudioRendererSink() override {
- if (!audio_renderer_sink_)
- audio_renderer_sink_ = new AudioOutputStreamSink();
+DefaultMojoMediaClient::DefaultMojoMediaClient() {}
+
+DefaultMojoMediaClient::~DefaultMojoMediaClient() {}
+
+void DefaultMojoMediaClient::Initialize() {
+ InitializeMediaLibrary();
+ // TODO(dalecurtis): We should find a single owner per process for the audio
+ // manager or make it a lazy instance. It's not safe to call Get()/Create()
+ // across multiple threads...
+ //
+ // TODO(dalecurtis): Eventually we'll want something other than a fake audio
+ // log factory here too. We should probably at least DVLOG() such info.
+ AudioManager* audio_manager = AudioManager::Get();
+ if (!audio_manager)
+ audio_manager = media::AudioManager::Create(&fake_audio_log_factory_);
+
+ audio_hardware_config_.reset(new AudioHardwareConfig(
+ audio_manager->GetInputStreamParameters(
+ AudioManagerBase::kDefaultDeviceId),
+ audio_manager->GetDefaultOutputStreamParameters()));
+}
- return audio_renderer_sink_.get();
- }
+scoped_ptr<RendererFactory> DefaultMojoMediaClient::CreateRendererFactory(
+ const scoped_refptr<MediaLog>& media_log) {
+ return make_scoped_ptr(
+ new DefaultRendererFactory(media_log, nullptr, *audio_hardware_config_));
+}
- VideoRendererSink* CreateVideoRendererSink(
- const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) override {
- if (!video_renderer_sink_) {
- video_renderer_sink_ = make_scoped_ptr(
- new NullVideoSink(false, base::TimeDelta::FromSecondsD(1.0 / 60),
- NullVideoSink::NewFrameCB(), task_runner));
- }
+AudioRendererSink* DefaultMojoMediaClient::CreateAudioRendererSink() {
+ if (!audio_renderer_sink_)
+ audio_renderer_sink_ = new AudioOutputStreamSink();
- return video_renderer_sink_.get();
- }
+ return audio_renderer_sink_.get();
+}
- scoped_ptr<CdmFactory> CreateCdmFactory(
- mojo::shell::mojom::InterfaceProvider* /* service_provider */) override {
- return make_scoped_ptr(new DefaultCdmFactory());
+VideoRendererSink* DefaultMojoMediaClient::CreateVideoRendererSink(
+ const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) {
+ if (!video_renderer_sink_) {
+ video_renderer_sink_ = make_scoped_ptr(
+ new NullVideoSink(false, base::TimeDelta::FromSecondsD(1.0 / 60),
+ NullVideoSink::NewFrameCB(), task_runner));
}
- private:
- FakeAudioLogFactory fake_audio_log_factory_;
- scoped_ptr<AudioHardwareConfig> audio_hardware_config_;
- scoped_refptr<AudioRendererSink> audio_renderer_sink_;
- scoped_ptr<VideoRendererSink> video_renderer_sink_;
-
- DISALLOW_COPY_AND_ASSIGN(DefaultMojoMediaClient);
-};
-
-} // namespace (anonymous)
+ return video_renderer_sink_.get();
+}
-scoped_ptr<MojoMediaClient> MojoMediaClient::Create() {
- return make_scoped_ptr(new DefaultMojoMediaClient());
+scoped_ptr<CdmFactory> DefaultMojoMediaClient::CreateCdmFactory(
+ mojo::shell::mojom::InterfaceProvider* /* service_provider */) {
+ return make_scoped_ptr(new DefaultCdmFactory());
}
} // namespace media
diff --git a/media/mojo/services/default_mojo_media_client.h b/media/mojo/services/default_mojo_media_client.h
new file mode 100644
index 0000000..9176c63
--- /dev/null
+++ b/media/mojo/services/default_mojo_media_client.h
@@ -0,0 +1,48 @@
+// Copyright 2014 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_DEFAULT_MOJO_MEDIA_CLIENT_H_
+#define MEDIA_MOJO_SERVICES_DEFAULT_MOJO_MEDIA_CLIENT_H_
+
+#include "base/macros.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "media/audio/fake_audio_log_factory.h"
+#include "media/base/media_export.h"
+#include "media/mojo/services/mojo_media_client.h"
+
+namespace media {
+
+class AudioHardwareConfig;
+class AudioRendererSink;
+class VideoRendererSink;
+
+// Default MojoMediaClient for MojoMediaApplication.
+class MEDIA_EXPORT DefaultMojoMediaClient : public MojoMediaClient {
+ public:
+ DefaultMojoMediaClient();
+ ~DefaultMojoMediaClient() final;
+
+ // MojoMediaClient implementation.
+ void Initialize() final;
+ scoped_ptr<RendererFactory> CreateRendererFactory(
+ const scoped_refptr<MediaLog>& media_log) final;
+ AudioRendererSink* CreateAudioRendererSink() final;
+ VideoRendererSink* CreateVideoRendererSink(
+ const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) final;
+ scoped_ptr<CdmFactory> CreateCdmFactory(
+ mojo::shell::mojom::InterfaceProvider* /* service_provider */) final;
+
+ private:
+ FakeAudioLogFactory fake_audio_log_factory_;
+ scoped_ptr<AudioHardwareConfig> audio_hardware_config_;
+ scoped_refptr<AudioRendererSink> audio_renderer_sink_;
+ scoped_ptr<VideoRendererSink> video_renderer_sink_;
+
+ DISALLOW_COPY_AND_ASSIGN(DefaultMojoMediaClient);
+};
+
+} // namespace media
+
+#endif // MEDIA_MOJO_SERVICES_DEFAULT_MOJO_MEDIA_CLIENT_H_
diff --git a/media/mojo/services/main.cc b/media/mojo/services/main.cc
index b3df5c8..2ab7d06 100644
--- a/media/mojo/services/main.cc
+++ b/media/mojo/services/main.cc
@@ -14,8 +14,8 @@ MojoResult MojoMain(MojoHandle mojo_handle) {
mojo::ApplicationRunner::InitBaseCommandLine();
mojo::InitLogging();
- scoped_ptr<mojo::ShellClient> app_delegate =
+ scoped_ptr<mojo::ShellClient> shell_client =
media::MojoMediaApplication::CreateApp();
- mojo::ApplicationRunner runner(app_delegate.release());
+ mojo::ApplicationRunner runner(shell_client.release());
return runner.Run(mojo_handle, false /* init_base */);
}
diff --git a/media/mojo/services/mojo_media_application.cc b/media/mojo/services/mojo_media_application.cc
index 74c0df5..8a92b02 100644
--- a/media/mojo/services/mojo_media_application.cc
+++ b/media/mojo/services/mojo_media_application.cc
@@ -12,12 +12,36 @@
#include "mojo/shell/public/cpp/connection.h"
#include "mojo/shell/public/cpp/shell.h"
+#if defined(OS_ANDROID)
+#include "media/mojo/services/android_mojo_media_client.h"
+#else
+#include "media/mojo/services/default_mojo_media_client.h"
+#endif
+
namespace media {
+#if defined(OS_ANDROID)
+using DefaultClient = AndroidMojoMediaClient;
+#else
+using DefaultClient = DefaultMojoMediaClient;
+#endif
+
// static
scoped_ptr<mojo::ShellClient> MojoMediaApplication::CreateApp() {
return scoped_ptr<mojo::ShellClient>(
- new MojoMediaApplication(MojoMediaClient::Create()));
+ new MojoMediaApplication(make_scoped_ptr(new DefaultClient())));
+}
+
+// static
+scoped_ptr<mojo::ShellClient> MojoMediaApplication::CreateAppWithClient(
+ const CreateMojoMediaClientCB& create_mojo_media_client_cb) {
+ scoped_ptr<MojoMediaClient> mojo_media_client =
+ create_mojo_media_client_cb.Run();
+ if (!mojo_media_client)
+ return nullptr;
+
+ return scoped_ptr<mojo::ShellClient>(
+ new MojoMediaApplication(std::move(mojo_media_client)));
}
// TODO(xhwang): Hook up MediaLog when possible.
@@ -25,14 +49,15 @@ MojoMediaApplication::MojoMediaApplication(
scoped_ptr<MojoMediaClient> mojo_media_client)
: mojo_media_client_(std::move(mojo_media_client)),
shell_(nullptr),
- media_log_(new MediaLog()) {}
-
-MojoMediaApplication::~MojoMediaApplication() {
+ media_log_(new MediaLog()) {
+ DCHECK(mojo_media_client_);
}
+MojoMediaApplication::~MojoMediaApplication() {}
+
void MojoMediaApplication::Initialize(mojo::Shell* shell,
- const std::string& url,
- uint32_t id) {
+ const std::string& /* url */,
+ uint32_t /* id */) {
shell_ = shell;
mojo_media_client_->Initialize();
}
diff --git a/media/mojo/services/mojo_media_application.h b/media/mojo/services/mojo_media_application.h
index 71b1e06..c1e24df 100644
--- a/media/mojo/services/mojo_media_application.h
+++ b/media/mojo/services/mojo_media_application.h
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/callback.h"
#include "base/memory/ref_counted.h"
#include "media/mojo/interfaces/service_factory.mojom.h"
#include "mojo/shell/public/cpp/interface_factory_impl.h"
@@ -17,12 +18,22 @@ class MojoMediaApplication
: public mojo::ShellClient,
public mojo::InterfaceFactory<interfaces::ServiceFactory> {
public:
+ // Callback to create a MojoMediaClient.
+ using CreateMojoMediaClientCB = base::Callback<scoped_ptr<MojoMediaClient>()>;
+
+ // Creates MojoMediaApplication using the default MojoMediaClient.
static scoped_ptr<mojo::ShellClient> CreateApp();
- explicit MojoMediaApplication(scoped_ptr<MojoMediaClient> mojo_media_client);
+ // Creates MojoMediaApplication using the MojoMediaClient provided by
+ // |create_mojo_media_client_cb|.
+ static scoped_ptr<mojo::ShellClient> CreateAppWithClient(
+ const CreateMojoMediaClientCB& create_mojo_media_client_cb);
+
~MojoMediaApplication() final;
private:
+ explicit MojoMediaApplication(scoped_ptr<MojoMediaClient> mojo_media_client);
+
// mojo::ShellClient implementation.
void Initialize(mojo::Shell* shell,
const std::string& url,
@@ -33,7 +44,11 @@ class MojoMediaApplication
void Create(mojo::Connection* connection,
mojo::InterfaceRequest<interfaces::ServiceFactory> request) final;
+ // Note: Since each instance runs on a different thread, do not share a common
+ // MojoMediaClient with other instances to avoid threading issues. Hence using
+ // a scoped_ptr here.
scoped_ptr<MojoMediaClient> mojo_media_client_;
+
mojo::Shell* shell_;
scoped_refptr<MediaLog> media_log_;
};
diff --git a/media/mojo/services/mojo_media_client.h b/media/mojo/services/mojo_media_client.h
index 4e4d39b..38bf338 100644
--- a/media/mojo/services/mojo_media_client.h
+++ b/media/mojo/services/mojo_media_client.h
@@ -5,13 +5,16 @@
#ifndef MEDIA_MOJO_SERVICES_MOJO_MEDIA_CLIENT_H_
#define MEDIA_MOJO_SERVICES_MOJO_MEDIA_CLIENT_H_
-#include "base/single_thread_task_runner.h"
#include "media/base/audio_renderer_sink.h"
#include "media/base/cdm_factory.h"
#include "media/base/media_log.h"
#include "media/base/renderer_factory.h"
#include "media/base/video_renderer_sink.h"
+namespace base {
+class SingleThreadTaskRunner;
+}
+
namespace mojo {
namespace shell {
namespace mojom {
@@ -22,12 +25,10 @@ class InterfaceProvider;
namespace media {
-class MojoMediaClient {
+class MEDIA_EXPORT MojoMediaClient {
public:
virtual ~MojoMediaClient();
- static scoped_ptr<MojoMediaClient> Create();
-
// Called exactly once before any other method.
virtual void Initialize();
// Returns the RendererFactory to be used by MojoRendererService. If returns