OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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 #include "media/mojo/common/media_type_converters.h" |
| 7 |
| 8 namespace content { |
| 9 |
| 10 AudioOutputStreamImpl::AudioOutputStreamImpl( |
| 11 media::interfaces::AudioOutputStreamRequest request, |
| 12 int stream_id, |
| 13 AudioRendererHost* audio_renderer_host) |
| 14 : binding_(this, std::move(request)), |
| 15 stream_id_(stream_id), |
| 16 audio_renderer_host_(audio_renderer_host) { |
| 17 } |
| 18 |
| 19 AudioOutputStreamImpl::~AudioOutputStreamImpl() { |
| 20 } |
| 21 |
| 22 void AudioOutputStreamImpl::Close() { |
| 23 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 24 |
| 25 audio_renderer_host_->OnCloseStream(stream_id_); |
| 26 } |
| 27 |
| 28 AudioOutputImpl::AudioOutputImpl( |
| 29 scoped_refptr<AudioRendererHost> audio_renderer_host, |
| 30 media::interfaces::AudioOutputRequest request) |
| 31 : audio_renderer_host_(audio_renderer_host.get()), binding_(this) { |
| 32 binding_.Bind(std::move(request)); |
| 33 |
| 34 binding_.set_connection_error_handler(base::Bind( |
| 35 base::Bind(&AudioOutputImpl::OnDisconnect, base::Unretained(this)), |
| 36 base::Unretained(this))); |
| 37 } |
| 38 |
| 39 AudioOutputImpl::~AudioOutputImpl() {} |
| 40 |
| 41 // static |
| 42 void AudioOutputImpl::CreateService( |
| 43 scoped_refptr<AudioRendererHost> audio_renderer_host, |
| 44 AudioOutputImpl** audio_output_impl, |
| 45 media::interfaces::AudioOutputRequest request) { |
| 46 |
| 47 BrowserThread::PostTask( |
| 48 BrowserThread::IO, FROM_HERE, |
| 49 base::Bind(&AudioOutputImpl::CreateServiceOnIOThread, audio_renderer_host, |
| 50 audio_output_impl, |
| 51 base::Passed(&request))); |
| 52 } |
| 53 |
| 54 // static |
| 55 void AudioOutputImpl::CreateServiceOnIOThread( |
| 56 scoped_refptr<AudioRendererHost> audio_renderer_host, |
| 57 AudioOutputImpl** audio_output_impl, |
| 58 media::interfaces::AudioOutputRequest request) { |
| 59 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 60 auto service = new AudioOutputImpl(audio_renderer_host, std::move(request)); |
| 61 audio_renderer_host->audio_output_impl_ = service; |
| 62 *audio_output_impl = service; |
| 63 } |
| 64 |
| 65 void AudioOutputImpl::CreateStream( |
| 66 int stream_id, |
| 67 int render_frame_id, |
| 68 media::interfaces::AudioOutputStreamParametersPtr params, |
| 69 const CreateStreamCallback& callback) { |
| 70 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 71 |
| 72 media::interfaces::AudioOutputStreamPtr stream; |
| 73 media::AudioParameters audio_params = |
| 74 mojo::ConvertTo<media::AudioParameters>(params); |
| 75 |
| 76 audio_renderer_host_->CreateStream(stream_id, render_frame_id, audio_params, |
| 77 callback); |
| 78 } |
| 79 |
| 80 media::interfaces::AudioOutputStreamPtr* AudioOutputImpl::StreamFactory( |
| 81 int stream_id, |
| 82 AudioRendererHost* audio_renderer_host) { |
| 83 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 84 |
| 85 |
| 86 media::interfaces::AudioOutputStreamPtr* stream = new media::interfaces::Audio
OutputStreamPtr(); |
| 87 std::unique_ptr<AudioOutputStreamImpl> stream_ptr(new AudioOutputStreamImpl( |
| 88 mojo::GetProxy(stream), stream_id, audio_renderer_host)); |
| 89 |
| 90 |
| 91 auto ret = stream_impls_.insert( |
| 92 std::pair<int, std::unique_ptr<AudioOutputStreamImpl>>( |
| 93 stream_id,std::move(stream_ptr))); |
| 94 DCHECK(!ret.second); |
| 95 return stream; |
| 96 } |
| 97 |
| 98 void AudioOutputImpl::OnDisconnect(AudioOutputImpl* impl) { |
| 99 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 100 |
| 101 DLOG(ERROR) << "Mojo client connection error"; |
| 102 } |
| 103 |
| 104 } // namespace content |
OLD | NEW |