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

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

Issue 1930393002: Switch stream creation and closing in Chrome audio rendering 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..e27d2735ca5213f084764c2ec0ad3ddaf0ee4bc6
--- /dev/null
+++ b/content/browser/media/audio_output_impl.cc
@@ -0,0 +1,95 @@
+// 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) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+}
+
+AudioOutputStreamImpl::~AudioOutputStreamImpl() {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+}
+
+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) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+
+ binding_.Bind(std::move(request));
+}
+
+AudioOutputImpl::~AudioOutputImpl() {}
+
+// static
+void AudioOutputImpl::CreateService(
+ scoped_refptr<AudioRendererHost> audio_renderer_host,
+ media::interfaces::AudioOutputRequest request) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(&AudioOutputImpl::CreateServiceOnIOThread, audio_renderer_host,
+ base::Passed(&request)));
+}
+
+// static
+void AudioOutputImpl::CreateServiceOnIOThread(
+ scoped_refptr<AudioRendererHost> audio_renderer_host,
+ 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;
mcasas 2016/04/29 18:29:00 Don't make AudioOutput*Impl friend of AudioRendere
rchtara 2016/05/23 16:38:17 Done.
+}
+
+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 =
+ 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>>(
mcasas 2016/04/29 18:29:00 std::make_pair(stream_id, std::move(stream_ptr));
rchtara 2016/05/23 16:38:17 Done.
+ stream_id, std::move(stream_ptr)));
+ DCHECK(ret.second);
+ return stream;
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698