Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "media/mojo/services/mojo_renderer_service.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/memory/scoped_vector.h" | |
| 9 #include "media/base/audio_decoder.h" | |
| 10 #include "media/base/audio_renderer.h" | |
| 11 #include "media/base/audio_renderer_sink.h" | |
| 12 #include "media/base/decryptor.h" | |
| 13 #include "media/filters/audio_renderer_impl.h" | |
| 14 #include "media/mojo/services/mojo_demuxer_stream_adapter.h" | |
| 15 #include "mojo/public/c/system/main.h" | |
| 16 #include "mojo/public/cpp/application/application_connection.h" | |
| 17 #include "mojo/public/cpp/application/application_delegate.h" | |
| 18 #include "mojo/public/cpp/application/application_runner_chromium.h" | |
| 19 #include "mojo/public/cpp/application/interface_factory_impl.h" | |
| 20 | |
| 21 namespace { | |
| 22 | |
| 23 // TODO(tim): We should use |connection| passed to the MojoRendererService | |
|
scherkus (not reviewing)
2014/09/09 20:35:33
remove extra space before passed
tim (not reviewing)
2014/09/10 23:08:31
Done.
| |
| 24 // to connect to a MojoAudioRendererSink implementation that we would wrap in | |
| 25 // media::AudioRendererSink and pass that to the AudioRendererImpl below. | |
| 26 class DummyAudioRendererSink : public media::AudioRendererSink { | |
|
scherkus (not reviewing)
2014/09/09 20:35:33
you might be able to use media::NullAudioSink here
tim (not reviewing)
2014/09/10 23:08:30
Ah thanks!
| |
| 27 virtual void Initialize(const media::AudioParameters& params, | |
| 28 RenderCallback* callback) OVERRIDE {} | |
| 29 virtual void Start() OVERRIDE {} | |
| 30 virtual void Stop() OVERRIDE {} | |
| 31 virtual void Pause() OVERRIDE {} | |
| 32 virtual void Play() OVERRIDE {} | |
| 33 virtual bool SetVolume(double volume) OVERRIDE { | |
| 34 return true; | |
| 35 } | |
| 36 protected: | |
| 37 virtual ~DummyAudioRendererSink() {} | |
| 38 }; | |
| 39 | |
| 40 } // namespace | |
| 41 | |
| 42 namespace media { | |
| 43 | |
| 44 class MojoRendererApplication | |
| 45 : public mojo::ApplicationDelegate, | |
| 46 public mojo::InterfaceFactory<mojo::MediaRenderer> { | |
| 47 public: | |
| 48 // mojo::ApplicationDelegate implementation. | |
| 49 virtual bool ConfigureIncomingConnection( | |
| 50 mojo::ApplicationConnection* connection) OVERRIDE { | |
| 51 connection->AddService(this); | |
| 52 return true; | |
| 53 } | |
| 54 | |
| 55 // mojo::InterfaceFactory<mojo::MediaRenderer> implementation. | |
| 56 virtual void Create( | |
| 57 mojo::ApplicationConnection* connection, | |
| 58 mojo::InterfaceRequest<mojo::MediaRenderer> request) OVERRIDE { | |
| 59 mojo::BindToRequest(new MojoRendererService(connection), &request); | |
| 60 } | |
| 61 }; | |
| 62 | |
| 63 MojoRendererService::MojoRendererService( | |
| 64 mojo::ApplicationConnection* connection) | |
| 65 : hardware_config_(media::AudioParameters(), media::AudioParameters()), | |
|
scherkus (not reviewing)
2014/09/09 20:35:33
remove media:: here and everywhere else
tim (not reviewing)
2014/09/10 23:08:30
Done.
| |
| 66 weak_factory_(this), | |
| 67 weak_this_(weak_factory_.GetWeakPtr()) { | |
| 68 audio_renderer_.reset(new media::AudioRendererImpl( | |
| 69 base::MessageLoop::current()->task_runner(), | |
| 70 new DummyAudioRendererSink(), | |
| 71 // TODO(tim): Figure out how to select decoders. | |
| 72 ScopedVector<media::AudioDecoder>(), | |
| 73 // TODO(tim): Not needed for now? | |
| 74 media::SetDecryptorReadyCB(), | |
| 75 hardware_config_)); | |
| 76 } | |
| 77 | |
| 78 MojoRendererService::~MojoRendererService() {} | |
| 79 | |
| 80 void MojoRendererService::Initialize( | |
| 81 mojo::DemuxerStreamPtr stream, | |
| 82 const mojo::Callback<void()>& callback) { | |
| 83 DCHECK(client()); | |
| 84 stream_.reset(new MojoDemuxerStreamAdapter(stream.Pass(), | |
| 85 base::Bind(&MojoRendererService::OnStreamReady, weak_this_))); | |
| 86 init_cb_ = callback;; | |
|
scherkus (not reviewing)
2014/09/09 20:35:33
remove extra ;
tim (not reviewing)
2014/09/10 23:08:30
Done.
| |
| 87 } | |
| 88 | |
| 89 void MojoRendererService::Flush(const mojo::Callback<void()>& callback) { | |
| 90 NOTIMPLEMENTED(); | |
| 91 } | |
| 92 | |
| 93 void MojoRendererService::StartPlayingFrom(int64_t time_delta_usec) { | |
| 94 NOTIMPLEMENTED(); | |
| 95 } | |
| 96 | |
| 97 void MojoRendererService::SetPlaybackRate(float playback_rate) { | |
| 98 NOTIMPLEMENTED(); | |
| 99 } | |
| 100 | |
| 101 void MojoRendererService::SetVolume(float volume) { | |
| 102 NOTIMPLEMENTED(); | |
| 103 } | |
| 104 | |
| 105 void MojoRendererService::OnStreamReady() { | |
| 106 audio_renderer_->Initialize( | |
| 107 stream_.get(), | |
| 108 base::Bind(&MojoRendererService::OnAudioRendererInitializeDone, | |
| 109 weak_this_), | |
| 110 base::Bind(&MojoRendererService::OnUpdateStatistics, weak_this_), | |
| 111 base::Bind(&MojoRendererService::OnAudioTimeUpdate, weak_this_), | |
| 112 base::Bind(&MojoRendererService::OnBufferingStateChanged, weak_this_), | |
| 113 base::Bind(&MojoRendererService::OnAudioRendererEnded, weak_this_), | |
| 114 base::Bind(&MojoRendererService::OnError, weak_this_)); | |
| 115 } | |
| 116 | |
| 117 void MojoRendererService::OnAudioRendererInitializeDone( | |
| 118 media::PipelineStatus status) { | |
| 119 if (status != media::PIPELINE_OK) { | |
| 120 audio_renderer_.reset(); | |
| 121 client()->OnError(); | |
| 122 } | |
| 123 init_cb_.Run(); | |
| 124 } | |
| 125 | |
| 126 void MojoRendererService::OnUpdateStatistics(const PipelineStatistics& stats) { | |
| 127 NOTIMPLEMENTED(); | |
| 128 } | |
| 129 | |
| 130 void MojoRendererService::OnAudioTimeUpdate(base::TimeDelta time, | |
| 131 base::TimeDelta max_time) { | |
| 132 client()->OnTimeUpdate(time.InMilliseconds(), max_time.InMilliseconds()); | |
|
xhwang
2014/09/10 00:00:52
InMicroseconds?
tim (not reviewing)
2014/09/10 23:08:30
Uh oh. Aaaaand here's why it's useful to have a t
| |
| 133 } | |
| 134 | |
| 135 void MojoRendererService::OnBufferingStateChanged( | |
| 136 media::BufferingState new_buffering_state) { | |
| 137 client()->OnBufferingStateChange( | |
| 138 static_cast<mojo::BufferingState>(new_buffering_state)); | |
| 139 } | |
| 140 | |
| 141 void MojoRendererService::OnAudioRendererEnded() { | |
| 142 client()->OnEnded(); | |
| 143 } | |
| 144 | |
| 145 void MojoRendererService::OnError(PipelineStatus error) { | |
| 146 client()->OnError(); | |
|
xhwang
2014/09/10 00:00:52
Pass |error| in OnError()?
tim (not reviewing)
2014/09/10 23:08:30
In the last CL I thought you proposed that the ren
| |
| 147 } | |
| 148 | |
| 149 } // namespace media | |
| 150 | |
| 151 MojoResult MojoMain(MojoHandle shell_handle) { | |
|
scherkus (not reviewing)
2014/09/09 20:35:33
does MojoMain() belong here?
tim (not reviewing)
2014/09/10 23:08:30
It typically goes wherever the ApplicationDelegate
| |
| 152 mojo::ApplicationRunnerChromium runner(new media::MojoRendererApplication); | |
| 153 return runner.Run(shell_handle); | |
| 154 } | |
| OLD | NEW |