Chromium Code Reviews| 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 mojo::InterfaceRequest<AudioOutputStream> 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(mojom::AudioOutputRequest request) | |
| 29 : binding_(this) { | |
| 30 binding_.Bind(std::move(request)); | |
| 31 | |
| 32 binding_.set_connection_error_handler(base::Bind( | |
| 33 base::Bind(&AudioOutputImpl::OnDisconnect, base::Unretained(this)), | |
| 34 base::Unretained(this))); | |
|
tommi (sloooow) - chröme
2016/04/26 15:29:52
using Unretained() always raises an alarm. Is it g
rchtara
2016/04/29 12:54:44
I will not use AudioOutputImpl::OnDisconnect. So I
| |
| 35 } | |
| 36 | |
| 37 AudioOutputImpl::~AudioOutputImpl() {} | |
| 38 | |
| 39 // static | |
| 40 void AudioOutputImpl::CreateService( | |
| 41 scoped_refptr<AudioRendererHost> audio_renderer_host, | |
| 42 mojom::AudioOutputRequest request) { | |
| 43 | |
|
tommi (sloooow) - chröme
2016/04/26 15:29:52
remove whitespace
rchtara
2016/04/29 12:54:44
Done.
| |
| 44 BrowserThread::PostTask( | |
| 45 BrowserThread::IO, FROM_HERE, | |
| 46 base::Bind(&AudioOutputImpl::CreateServiceOnIOThread, audio_renderer_host, | |
| 47 base::Passed(&request))); | |
| 48 } | |
| 49 | |
| 50 void AudioOutputImpl::CreateServiceOnIOThread( | |
| 51 scoped_refptr<AudioRendererHost> audio_renderer_host, | |
| 52 mojo::InterfaceRequest<AudioOutput> request) { | |
| 53 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 54 auto service = new AudioOutputImpl(std::move(request)); | |
| 55 service->audio_renderer_host_ = audio_renderer_host; | |
| 56 audio_renderer_host->audio_output_impl_ = service; | |
| 57 } | |
| 58 | |
| 59 // static | |
| 60 void AudioOutputImpl::CreateStream( | |
| 61 int stream_id, | |
| 62 int render_frame_id, | |
| 63 media::interfaces::AudioOutputStreamParametersPtr params, | |
| 64 const CreateStreamCallback& callback) { | |
| 65 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 66 | |
| 67 mojom::AudioOutputStreamPtr stream; | |
| 68 media::AudioParameters audio_params = | |
| 69 mojo::ConvertTo<media::AudioParameters>(params); | |
| 70 | |
| 71 audio_renderer_host_->CreateStream(stream_id, render_frame_id, audio_params, | |
| 72 callback); | |
| 73 } | |
| 74 | |
| 75 mojom::AudioOutputStreamPtr* AudioOutputImpl::StreamFactory( | |
| 76 int stream_id, | |
| 77 AudioRendererHost* audio_renderer_host) { | |
| 78 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 79 | |
| 80 mojom::AudioOutputStreamPtr* stream = new mojom::AudioOutputStreamPtr(); | |
| 81 std::unique_ptr<AudioOutputStreamImpl> stream_ptr(new AudioOutputStreamImpl( | |
| 82 mojo::GetProxy(stream), stream_id, audio_renderer_host)); | |
| 83 | |
| 84 stream_impls_[stream_id] = std::move(stream_ptr); | |
|
tommi (sloooow) - chröme
2016/04/26 15:29:52
use insert() instead? This will do a lookup+inser
rchtara
2016/04/29 12:54:44
Done.
| |
| 85 return stream; | |
|
tommi (sloooow) - chröme
2016/04/26 15:29:52
returning a pointer to an object that's owned by t
tommi (sloooow) - chröme
2016/04/26 15:29:52
this returns a "Ptr*". is that a **? Maybe the "
rchtara
2016/04/29 12:54:44
Because the map is changed in this function only.
rchtara
2016/04/29 12:54:44
Done.
| |
| 86 } | |
| 87 | |
| 88 void AudioOutputImpl::OnDisconnect(AudioOutputImpl* impl) { | |
| 89 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 90 | |
| 91 DLOG(ERROR) << "Mojo client connection error"; | |
|
tommi (sloooow) - chröme
2016/04/26 15:29:52
LOG? even fatal or dfatal?
rchtara
2016/04/29 12:54:44
This could be caused by an error in mojo connectio
| |
| 92 } | |
| 93 | |
| 94 } // namespace content | |
| OLD | NEW |