OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/logging.h" | 6 #include "base/logging.h" |
7 #include "media/mojo/services/mojo_cdm_factory_service.h" | |
8 #include "media/mojo/services/mojo_cdm_service_context.h" | |
7 #include "media/mojo/services/mojo_renderer_service.h" | 9 #include "media/mojo/services/mojo_renderer_service.h" |
8 #include "mojo/application/application_runner_chromium.h" | 10 #include "mojo/application/application_runner_chromium.h" |
9 #include "mojo/public/c/system/main.h" | 11 #include "mojo/public/c/system/main.h" |
10 #include "mojo/public/cpp/application/application_connection.h" | 12 #include "mojo/public/cpp/application/application_connection.h" |
11 #include "mojo/public/cpp/application/application_delegate.h" | 13 #include "mojo/public/cpp/application/application_delegate.h" |
12 #include "mojo/public/cpp/application/application_impl.h" | 14 #include "mojo/public/cpp/application/application_impl.h" |
13 #include "mojo/public/cpp/application/interface_factory_impl.h" | 15 #include "mojo/public/cpp/application/interface_factory_impl.h" |
14 | 16 |
15 namespace media { | 17 namespace media { |
16 | 18 |
19 static void EnableLoggingFromArgs(const std::vector<std::string>& args) { | |
xhwang
2015/01/05 23:52:38
This is moved from Initialize().
| |
20 base::CommandLine::StringVector command_line_args; | |
21 #if defined(OS_WIN) | |
22 for (const auto& arg : args) | |
23 command_line_args.push_back(base::UTF8ToUTF16(arg)); | |
24 #elif defined(OS_POSIX) | |
25 command_line_args = args; | |
26 #endif | |
27 | |
28 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
29 command_line->InitFromArgv(command_line_args); | |
30 | |
31 logging::LoggingSettings settings; | |
32 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; | |
33 logging::InitLogging(settings); | |
34 // Display process ID, thread ID and timestamp in logs. | |
35 logging::SetLogItems(true, true, true, false); | |
36 } | |
37 | |
38 // mojo:media app that provides multiple media services. | |
17 class MojoMediaApplication | 39 class MojoMediaApplication |
18 : public mojo::ApplicationDelegate, | 40 : public mojo::ApplicationDelegate, |
41 public mojo::InterfaceFactory<mojo::ContentDecryptionModuleFactory>, | |
19 public mojo::InterfaceFactory<mojo::MediaRenderer> { | 42 public mojo::InterfaceFactory<mojo::MediaRenderer> { |
20 public: | 43 public: |
21 // mojo::ApplicationDelegate implementation. | 44 // mojo::ApplicationDelegate implementation. |
22 void Initialize(mojo::ApplicationImpl* app) override { | 45 void Initialize(mojo::ApplicationImpl* app) override { |
23 base::CommandLine::StringVector command_line_args; | 46 EnableLoggingFromArgs(app->args()); |
24 #if defined(OS_WIN) | |
25 for (const auto& arg : app->args()) | |
26 command_line_args.push_back(base::UTF8ToUTF16(arg)); | |
27 #elif defined(OS_POSIX) | |
28 command_line_args = app->args(); | |
29 #endif | |
30 | |
31 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
32 command_line->InitFromArgv(command_line_args); | |
33 | |
34 logging::LoggingSettings settings; | |
35 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; | |
36 logging::InitLogging(settings); | |
37 // Display process ID, thread ID and timestamp in logs. | |
38 logging::SetLogItems(true, true, true, false); | |
39 } | 47 } |
40 | 48 |
41 bool ConfigureIncomingConnection( | 49 bool ConfigureIncomingConnection( |
42 mojo::ApplicationConnection* connection) override { | 50 mojo::ApplicationConnection* connection) final { |
43 connection->AddService(this); | 51 connection->AddService<mojo::ContentDecryptionModuleFactory>(this); |
52 connection->AddService<mojo::MediaRenderer>(this); | |
44 return true; | 53 return true; |
45 } | 54 } |
46 | 55 |
47 // mojo::InterfaceFactory<mojo::MediaRenderer> implementation. | 56 // mojo::InterfaceFactory<mojo::MediaRenderer> implementation. |
48 void Create(mojo::ApplicationConnection* connection, | 57 void Create(mojo::ApplicationConnection* connection, |
49 mojo::InterfaceRequest<mojo::MediaRenderer> request) override { | 58 mojo::InterfaceRequest<mojo::MediaRenderer> request) final { |
50 mojo::BindToRequest(new MojoRendererService(), &request); | 59 mojo::BindToRequest(new MojoRendererService(&cdm_service_context_), |
60 &request); | |
51 } | 61 } |
62 | |
63 // mojo::InterfaceFactory<mojo::ContentDecryptionModuleFactory> | |
64 // implementation. | |
65 void Create(mojo::ApplicationConnection* connection, | |
66 mojo::InterfaceRequest<mojo::ContentDecryptionModuleFactory> | |
67 request) final { | |
68 mojo::WeakBindToRequest(new MojoCdmFactoryService(&cdm_service_context_), | |
69 &request); | |
70 } | |
71 | |
72 private: | |
73 MojoCdmServiceContext cdm_service_context_; | |
52 }; | 74 }; |
53 | 75 |
54 } // namespace media | 76 } // namespace media |
55 | 77 |
56 MojoResult MojoMain(MojoHandle mojo_handle) { | 78 MojoResult MojoMain(MojoHandle mojo_handle) { |
57 mojo::ApplicationRunnerChromium runner(new media::MojoMediaApplication); | 79 mojo::ApplicationRunnerChromium runner(new media::MojoMediaApplication); |
58 return runner.Run(mojo_handle); | 80 return runner.Run(mojo_handle); |
59 } | 81 } |
OLD | NEW |