Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(222)

Unified Diff: content/browser/media/audio_output_impl.cc

Issue 1896883002: Mojo interfaces needed for switching audio rendering stream creation and closing from IPC to Mojo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/media/audio_output_impl.cc
diff --git a/content/browser/media/audio_output_impl.cc b/content/browser/media/audio_output_impl.cc
new file mode 100644
index 0000000000000000000000000000000000000000..031866cc1db3a6d681398aec995a00c4a889041e
--- /dev/null
+++ b/content/browser/media/audio_output_impl.cc
@@ -0,0 +1,104 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/browser/media/audio_output_impl.h"
+#include "media/mojo/common/media_type_converters.h"
+
+namespace content {
+
+AudioOutputStreamImpl::AudioOutputStreamImpl(
+ media::interfaces::AudioOutputStreamRequest request,
+ int stream_id,
+ AudioRendererHost* audio_renderer_host)
+ : binding_(this, std::move(request)),
+ stream_id_(stream_id),
+ audio_renderer_host_(audio_renderer_host) {
+}
+
+AudioOutputStreamImpl::~AudioOutputStreamImpl() {
+}
+
+void AudioOutputStreamImpl::Close() {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+
+ audio_renderer_host_->OnCloseStream(stream_id_);
+}
+
+AudioOutputImpl::AudioOutputImpl(
+ scoped_refptr<AudioRendererHost> audio_renderer_host,
+ media::interfaces::AudioOutputRequest request)
+ : audio_renderer_host_(audio_renderer_host.get()), binding_(this) {
+ binding_.Bind(std::move(request));
+
+ binding_.set_connection_error_handler(base::Bind(
+ base::Bind(&AudioOutputImpl::OnDisconnect, base::Unretained(this)),
+ base::Unretained(this)));
+}
+
+AudioOutputImpl::~AudioOutputImpl() {}
+
+// static
+void AudioOutputImpl::CreateService(
+ scoped_refptr<AudioRendererHost> audio_renderer_host,
+ AudioOutputImpl** audio_output_impl,
+ media::interfaces::AudioOutputRequest request) {
+
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(&AudioOutputImpl::CreateServiceOnIOThread, audio_renderer_host,
+ audio_output_impl,
+ base::Passed(&request)));
+}
+
+// static
+void AudioOutputImpl::CreateServiceOnIOThread(
+ scoped_refptr<AudioRendererHost> audio_renderer_host,
+ AudioOutputImpl** audio_output_impl,
+ media::interfaces::AudioOutputRequest request) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ auto service = new AudioOutputImpl(audio_renderer_host, std::move(request));
+ audio_renderer_host->audio_output_impl_ = service;
+ *audio_output_impl = service;
+}
+
+void AudioOutputImpl::CreateStream(
+ int stream_id,
+ int render_frame_id,
+ media::interfaces::AudioOutputStreamParametersPtr params,
+ const CreateStreamCallback& callback) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+
+ media::interfaces::AudioOutputStreamPtr stream;
+ media::AudioParameters audio_params =
+ mojo::ConvertTo<media::AudioParameters>(params);
+
+ audio_renderer_host_->CreateStream(stream_id, render_frame_id, audio_params,
+ callback);
+}
+
+media::interfaces::AudioOutputStreamPtr* AudioOutputImpl::StreamFactory(
+ int stream_id,
+ AudioRendererHost* audio_renderer_host) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+
+
+ media::interfaces::AudioOutputStreamPtr* stream = new media::interfaces::AudioOutputStreamPtr();
+ std::unique_ptr<AudioOutputStreamImpl> stream_ptr(new AudioOutputStreamImpl(
+ mojo::GetProxy(stream), stream_id, audio_renderer_host));
+
+
+ auto ret = stream_impls_.insert(
+ std::pair<int, std::unique_ptr<AudioOutputStreamImpl>>(
+ stream_id,std::move(stream_ptr)));
+ DCHECK(!ret.second);
+ return stream;
+}
+
+void AudioOutputImpl::OnDisconnect(AudioOutputImpl* impl) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+
+ DLOG(ERROR) << "Mojo client connection error";
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698