| 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/public/browser/browser_thread.h" |
| 16 #include "content/browser/media/webrtc/webrtc_internals.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 content { |
| 23 |
| 24 media::AudioParameters convert(const AudioOutputStreamParametersPtr& input) { |
| 25 media::AudioParameters output( |
| 26 static_cast<media::AudioParameters::Format>(input->format_), |
| 27 static_cast<media::ChannelLayout>(input->channel_layout_), |
| 28 input->sample_rate_, input->bits_per_sample_, input->frames_per_buffer_); |
| 29 output.set_channels(input->channels_); |
| 30 output.set_effects(input->effects_); |
| 31 return output; |
| 32 } |
| 33 |
| 34 AudioOutputImpl::AudioOutputImpl( |
| 35 scoped_refptr<AudioRendererHost> audio_renderer_host, |
| 36 AudioOutputRequest request) |
| 37 : audio_renderer_host_(audio_renderer_host), binding_(this) { |
| 38 BrowserThread::PostTask( |
| 39 BrowserThread::IO, FROM_HERE, |
| 40 base::Bind(&AudioOutputImpl::InitMojo, base::Unretained(this), |
| 41 base::Passed(&request))); |
| 42 } |
| 43 |
| 44 AudioOutputImpl::~AudioOutputImpl() {} |
| 45 |
| 46 void AudioOutputImpl::CloseStream(int32_t id) { |
| 47 // DCHECK(thread_checker_.CalledOnValidThread()); |
| 48 DLOG(WARNING) << "Close mojo" << id; |
| 49 audio_renderer_host_->OnCloseStream(id); |
| 50 }; |
| 51 |
| 52 class AudioOutputStreamÍmpl : public AudioOutputStream { |
| 53 public: |
| 54 explicit AudioOutputStreamÍmpl( |
| 55 mojo::InterfaceRequest<AudioOutputStream> request) |
| 56 : binding_(this, std::move(request)){}; |
| 57 void set(int a) override { |
| 58 DLOG(WARNING) << "set" << a_ << "set" << a_; |
| 59 a_ = a; |
| 60 }; |
| 61 |
| 62 void Play() override { DLOG(WARNING) << "set" << a_ << "set" << a_; }; |
| 63 |
| 64 private: |
| 65 int a_; |
| 66 mojo::Binding<AudioOutputStream> binding_; |
| 67 |
| 68 DISALLOW_COPY_AND_ASSIGN(AudioOutputStreamÍmpl); |
| 69 }; |
| 70 |
| 71 void AudioOutputImpl::DoCloseStream(int32_t id) { |
| 72 DLOG(WARNING) << "do Close mojo" << id; |
| 73 audio_renderer_host_->OnCloseStream(id); |
| 74 }; |
| 75 |
| 76 void AudioOutputImpl::CreateStream(int stream_id_, |
| 77 int render_frame_id_, |
| 78 AudioOutputStreamParametersPtr params, |
| 79 const CreateStreamCallback& callback) { |
| 80 AudioOutputStreamPtr stream; |
| 81 media::AudioParameters audio_params = convert(params); |
| 82 scoped_ptr<AudioOutputStreamÍmpl> stream_ptr( |
| 83 new AudioOutputStreamÍmpl(mojo::GetProxy(&stream))); |
| 84 stream_ptr->set(5); |
| 85 audio_renderer_host_->OnCreateStreamMojo( |
| 86 stream_id_, render_frame_id_, audio_params, std::move(stream), callback); |
| 87 // callback.Run(std::move(stream)); |
| 88 } |
| 89 |
| 90 void AudioOutputImpl::InitMojo(mojo::InterfaceRequest<AudioOutput> request) { |
| 91 binding_.Bind(std::move(request)); |
| 92 binding_.set_connection_error_handler(base::Bind( |
| 93 base::Bind(&AudioOutputImpl::OnDisconnect, base::Unretained(this)), |
| 94 base::Unretained(this))); |
| 95 } |
| 96 |
| 97 void AudioOutputImpl::OnDisconnect(AudioOutputImpl* impl) { |
| 98 DLOG(WARNING) << "error"; |
| 99 ; |
| 100 } |
| 101 |
| 102 } // namespace content |
| OLD | NEW |