OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "content/browser/media/audio_output_impl.h" |
| 6 |
| 7 #include <utility> |
| 8 |
| 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" |
| 11 #include "base/files/file.h" |
| 12 #include "base/logging.h" |
| 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/strings/string_number_conversions.h" |
| 15 #include "content/browser/media/webrtc/webrtc_internals.h" |
| 16 #include "content/public/browser/browser_thread.h" |
| 17 #include "content/public/browser/browser_thread.h" |
| 18 #include "content/public/browser/render_process_host.h" |
| 19 #include "content/public/common/child_process_host.h" |
| 20 #include "mojo/public/cpp/system/handle.h" |
| 21 |
| 22 namespace { |
| 23 |
| 24 media::AudioParameters convert( |
| 25 const content::mojom::AudioOutputStreamParametersPtr& input) { |
| 26 media::AudioParameters output( |
| 27 static_cast<media::AudioParameters::Format>(input->format_), |
| 28 static_cast<media::ChannelLayout>(input->channel_layout_), |
| 29 input->sample_rate_, input->bits_per_sample_, input->frames_per_buffer_); |
| 30 output.set_channels(input->channels_); |
| 31 output.set_effects(input->effects_); |
| 32 return output; |
| 33 } |
| 34 |
| 35 } // namespace |
| 36 |
| 37 namespace content { |
| 38 |
| 39 AudioOutputStreamImpl::AudioOutputStreamImpl( |
| 40 mojo::InterfaceRequest<AudioOutputStream> request, |
| 41 int stream_id, |
| 42 AudioRendererHost::AudioEntry* entry, |
| 43 AudioRendererHost* audio_renderer_host) |
| 44 : binding_(this, std::move(request)), |
| 45 stream_id_(stream_id), |
| 46 entry_(entry), |
| 47 audio_renderer_host_(audio_renderer_host) { |
| 48 } |
| 49 |
| 50 void AudioOutputStreamImpl::Close() { |
| 51 audio_renderer_host_->OnCloseStream(stream_id_); |
| 52 } |
| 53 |
| 54 AudioOutputStreamImpl::~AudioOutputStreamImpl() { |
| 55 } |
| 56 |
| 57 AudioOutputImpl::AudioOutputImpl(mojom::AudioOutputRequest request) |
| 58 : binding_(this) { |
| 59 BrowserThread::PostTask( |
| 60 BrowserThread::IO, FROM_HERE, |
| 61 base::Bind(&AudioOutputImpl::InitMojo, base::Unretained(this), |
| 62 base::Passed(&request))); |
| 63 } |
| 64 |
| 65 AudioOutputImpl::~AudioOutputImpl() { |
| 66 } |
| 67 |
| 68 void AudioOutputImpl::CreateStream(int stream_id, |
| 69 int render_frame_id, |
| 70 mojom::AudioOutputStreamParametersPtr params, |
| 71 const CreateStreamCallback& callback) { |
| 72 mojom::AudioOutputStreamPtr stream; |
| 73 media::AudioParameters audio_params = convert(params); |
| 74 |
| 75 audio_renderer_host_->OnCreateStream(stream_id, render_frame_id, audio_params, |
| 76 callback); |
| 77 } |
| 78 |
| 79 mojom::AudioOutputStreamPtr* AudioOutputImpl::StreamFactory( |
| 80 int stream_id, |
| 81 AudioRendererHost::AudioEntry* entry, |
| 82 AudioRendererHost* audio_renderer_host) { |
| 83 mojom::AudioOutputStreamPtr* stream = new mojom::AudioOutputStreamPtr(); |
| 84 AudioOutputStreamImpl* stream_ptr(new AudioOutputStreamImpl( |
| 85 mojo::GetProxy(stream), stream_id, entry, audio_renderer_host)); |
| 86 entry->set_stream_ptr(stream_ptr); |
| 87 stream_impls[stream_id] = make_scoped_ptr(stream_ptr); |
| 88 return stream; |
| 89 } |
| 90 |
| 91 void AudioOutputImpl::InitMojo(mojo::InterfaceRequest<AudioOutput> request) { |
| 92 binding_.Bind(std::move(request)); |
| 93 binding_.set_connection_error_handler(base::Bind( |
| 94 base::Bind(&AudioOutputImpl::OnDisconnect, base::Unretained(this)), |
| 95 base::Unretained(this))); |
| 96 } |
| 97 |
| 98 void AudioOutputImpl::OnDisconnect(AudioOutputImpl* impl) { |
| 99 DLOG(ERROR) << "Mojo client connection error"; |
| 100 } |
| 101 |
| 102 } // namespace content |
OLD | NEW |