Chromium Code Reviews| Index: content/browser/media/audio_output_impl.cc |
| diff --git a/content/browser/media/audio_output_impl.cc b/content/browser/media/audio_output_impl.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ef824d4124b65318530d3370a551e02b8be30aa9 |
| --- /dev/null |
| +++ b/content/browser/media/audio_output_impl.cc |
| @@ -0,0 +1,102 @@ |
| +// Copyright 2015 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 "content/browser/media/audio_output_impl.h" |
| + |
| +#include <utility> |
| + |
| +#include "base/bind.h" |
| +#include "base/bind_helpers.h" |
| +#include "base/files/file.h" |
| +#include "base/logging.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "base/strings/string_number_conversions.h" |
| +#include "content/browser/media/webrtc/webrtc_internals.h" |
| +#include "content/public/browser/browser_thread.h" |
| +#include "content/public/browser/browser_thread.h" |
| +#include "content/public/browser/render_process_host.h" |
| +#include "content/public/common/child_process_host.h" |
| +#include "mojo/public/cpp/system/handle.h" |
| + |
| +namespace { |
| + |
| +media::AudioParameters convert( |
| + const content::mojom::AudioOutputStreamParametersPtr& input) { |
| + media::AudioParameters output( |
| + static_cast<media::AudioParameters::Format>(input->format_), |
| + static_cast<media::ChannelLayout>(input->channel_layout_), |
| + input->sample_rate_, input->bits_per_sample_, input->frames_per_buffer_); |
| + output.set_channels(input->channels_); |
| + output.set_effects(input->effects_); |
| + return output; |
| +} |
| + |
| +} // namespace |
| + |
| +namespace content { |
| + |
| +AudioOutputStreamImpl::AudioOutputStreamImpl( |
| + mojo::InterfaceRequest<AudioOutputStream> request, |
| + int stream_id, |
| + AudioRendererHost::AudioEntry* entry, |
| + AudioRendererHost* audio_renderer_host) |
| + : binding_(this, std::move(request)), |
| + stream_id_(stream_id), |
| + entry_(entry), |
|
Henrik Grunell
2016/04/19 15:36:08
Seems like the entry isn't used? Also, the rendere
rchtara
2016/04/21 09:10:17
Done.
|
| + audio_renderer_host_(audio_renderer_host) { |
| +} |
| + |
| +void AudioOutputStreamImpl::Close() { |
| + audio_renderer_host_->OnCloseStream(stream_id_); |
| +} |
| + |
| +AudioOutputStreamImpl::~AudioOutputStreamImpl() { |
| +} |
| + |
| +AudioOutputImpl::AudioOutputImpl(mojom::AudioOutputRequest request) |
| + : binding_(this) { |
| + BrowserThread::PostTask( |
| + BrowserThread::IO, FROM_HERE, |
| + base::Bind(&AudioOutputImpl::InitMojo, base::Unretained(this), |
|
Henrik Grunell
2016/04/19 15:36:08
How is base::Unretained safe here?
rchtara
2016/04/21 10:15:23
Done.
|
| + base::Passed(&request))); |
| +} |
| + |
| +AudioOutputImpl::~AudioOutputImpl() { |
| +} |
| + |
| +void AudioOutputImpl::CreateStream(int stream_id, |
| + int render_frame_id, |
| + mojom::AudioOutputStreamParametersPtr params, |
| + const CreateStreamCallback& callback) { |
| + mojom::AudioOutputStreamPtr stream; |
| + media::AudioParameters audio_params = convert(params); |
| + |
| + audio_renderer_host_->OnCreateStream(stream_id, render_frame_id, audio_params, |
|
Henrik Grunell
2016/04/19 15:36:08
I think you should remove "On" from OnCreateStream
rchtara
2016/04/21 09:10:17
Done.
|
| + callback); |
| +} |
| + |
| +mojom::AudioOutputStreamPtr* AudioOutputImpl::StreamFactory( |
| + int stream_id, |
| + AudioRendererHost::AudioEntry* entry, |
| + AudioRendererHost* audio_renderer_host) { |
| + mojom::AudioOutputStreamPtr* stream = new mojom::AudioOutputStreamPtr(); |
| + AudioOutputStreamImpl* stream_ptr(new AudioOutputStreamImpl( |
| + mojo::GetProxy(stream), stream_id, entry, audio_renderer_host)); |
| + entry->set_stream_ptr(stream_ptr); |
| + stream_impls[stream_id] = make_scoped_ptr(stream_ptr); |
| + return stream; |
| +} |
| + |
| +void AudioOutputImpl::InitMojo(mojo::InterfaceRequest<AudioOutput> request) { |
| + binding_.Bind(std::move(request)); |
| + binding_.set_connection_error_handler(base::Bind( |
| + base::Bind(&AudioOutputImpl::OnDisconnect, base::Unretained(this)), |
| + base::Unretained(this))); |
| +} |
| + |
| +void AudioOutputImpl::OnDisconnect(AudioOutputImpl* impl) { |
| + DLOG(ERROR) << "Mojo client connection error"; |
| +} |
| + |
| +} // namespace content |