| 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( |
| 25 const 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 AudioOutputStreamImpl::AudioOutputStreamImpl( |
| 36 mojo::InterfaceRequest<AudioOutputStream> request, |
| 37 AudioEntry* entry, |
| 38 int stream_id, |
| 39 AudioRendererHost* audio_renderer_host) |
| 40 : binding_(this, std::move(request)), |
| 41 entry_(entry), |
| 42 stream_id_(stream_id), |
| 43 audio_renderer_host_(audio_renderer_host) { |
| 44 DLOG(WARNING) << "AudioOutputImpl::AudioOutputImpl"; |
| 45 }; |
| 46 |
| 47 void AudioOutputStreamImpl::set(int a) { |
| 48 DLOG(WARNING) << "set" << a_ << "set" << a; |
| 49 a_ = a; |
| 50 }; |
| 51 |
| 52 void AudioOutputStreamImpl::Play(const PlayCallback& callback) { |
| 53 DLOG(WARNING) << "play" << a_; |
| 54 DLOG(WARNING) << "play" << stream_id_; |
| 55 audio_renderer_host_->OnPlayEntry(entry_); |
| 56 // entry->controller()->Play(); |
| 57 // audio_log_->OnStarted(stream_id); |
| 58 callback.Run(true); |
| 59 }; |
| 60 |
| 61 AudioOutputStreamImpl::~AudioOutputStreamImpl(){}; |
| 62 |
| 63 AudioRendererHost* AudioOutputImpl::audio_renderer_host_ = 0; |
| 64 |
| 65 AudioOutputImpl::AudioOutputImpl(AudioRendererHost* audio_renderer_host, |
| 66 mojom::AudioOutputRequest request) |
| 67 : binding_(this) { |
| 68 audio_renderer_host_ = audio_renderer_host; |
| 69 BrowserThread::PostTask( |
| 70 BrowserThread::IO, FROM_HERE, |
| 71 base::Bind(&AudioOutputImpl::InitMojo, base::Unretained(this), |
| 72 base::Passed(&request))); |
| 73 } |
| 74 |
| 75 AudioOutputImpl::~AudioOutputImpl() { |
| 76 DLOG(WARNING) << "AudioOutputImpl::~AudioOutputImpl"; |
| 77 } |
| 78 |
| 79 void AudioOutputImpl::CloseStream(int32_t id) { |
| 80 // DCHECK(thread_checker_.CalledOnValidThread()); |
| 81 DLOG(WARNING) << "Close mojo" << id; |
| 82 audio_renderer_host_->OnCloseStream(id); |
| 83 }; |
| 84 |
| 85 void AudioOutputImpl::DoCloseStream(int32_t id) { |
| 86 DLOG(WARNING) << "do Close mojo" << id; |
| 87 audio_renderer_host_->OnCloseStream(id); |
| 88 }; |
| 89 |
| 90 void AudioOutputImpl::CreateStream(int stream_id, |
| 91 int render_frame_id, |
| 92 mojom::AudioOutputStreamParametersPtr params, |
| 93 const CreateStreamCallback& callback) { |
| 94 DLOG(WARNING) << "AudioOutputImpl::CreateStream" << stream_id; |
| 95 mojom::AudioOutputStreamPtr stream; |
| 96 media::AudioParameters audio_params = convert(params); |
| 97 scoped_ptr<AudioOutputStreamImpl> stream_ptr(new AudioOutputStreamImpl( |
| 98 mojo::GetProxy(&stream), 0, stream_id, audio_renderer_host_)); |
| 99 stream_ptr->set(5); |
| 100 audio_renderer_host_->OnCreateStreamMojo( |
| 101 stream_id, render_frame_id, audio_params, std::move(stream), callback); |
| 102 } |
| 103 |
| 104 mojom::AudioOutputStreamPtr* AudioOutputImpl::CreateStream(AudioEntry* entry, |
| 105 int stream_id) { |
| 106 mojom::AudioOutputStreamPtr* stream = new mojom::AudioOutputStreamPtr(); |
| 107 |
| 108 AudioOutputStreamImpl* stream_ptr(new AudioOutputStreamImpl( |
| 109 mojo::GetProxy(stream), entry, stream_id, audio_renderer_host_)); |
| 110 stream_ptr->set(20); |
| 111 return stream; |
| 112 } |
| 113 |
| 114 void AudioOutputImpl::InitMojo(mojo::InterfaceRequest<AudioOutput> request) { |
| 115 binding_.Bind(std::move(request)); |
| 116 binding_.set_connection_error_handler(base::Bind( |
| 117 base::Bind(&AudioOutputImpl::OnDisconnect, base::Unretained(this)), |
| 118 base::Unretained(this))); |
| 119 } |
| 120 |
| 121 void AudioOutputImpl::OnDisconnect(AudioOutputImpl* impl) { |
| 122 DLOG(WARNING) << "error"; |
| 123 } |
| 124 |
| 125 } // namespace content |
| OLD | NEW |