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

Unified Diff: content/browser/renderer_host/media/render_frame_audio_output_stream_factory.cc

Issue 2697663003: Add mojo interface+impl creation of audio streams. (Closed)
Patch Set: Created 3 years, 9 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/renderer_host/media/render_frame_audio_output_stream_factory.cc
diff --git a/content/browser/renderer_host/media/render_frame_audio_output_stream_factory.cc b/content/browser/renderer_host/media/render_frame_audio_output_stream_factory.cc
new file mode 100644
index 0000000000000000000000000000000000000000..75e496094a28d675fd1785d4b7bd0f1b51b7f0ed
--- /dev/null
+++ b/content/browser/renderer_host/media/render_frame_audio_output_stream_factory.cc
@@ -0,0 +1,118 @@
+// Copyright 2017 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/renderer_host/media/render_frame_audio_output_stream_factory.h"
+
+#include <utility>
+
+#include "base/metrics/histogram_macros.h"
+#include "base/threading/thread_checker.h"
+#include "content/browser/bad_message.h"
+#include "content/browser/renderer_host/media/renderer_audio_output_stream_factory_context.h"
+#include "media/base/audio_parameters.h"
+#include "media/mojo/services/mojo_audio_output_stream_provider.h"
+#include "mojo/public/cpp/bindings/binding.h"
+
+namespace content {
+
+namespace {
+
+void UMALogDeviceAuthorizationTime(base::TimeTicks auth_start_time) {
+ UMA_HISTOGRAM_CUSTOM_TIMES("Media.Audio.OutputDeviceAuthorizationTime",
+ base::TimeTicks::Now() - auth_start_time,
+ base::TimeDelta::FromMilliseconds(1),
+ base::TimeDelta::FromMilliseconds(5000), 50);
+}
+
+} // namespace
+
+RenderFrameAudioOutputStreamFactory::RenderFrameAudioOutputStreamFactory(
+ RendererAudioOutputStreamFactoryContext* context,
+ int render_frame_id)
+ : context_(context), render_frame_id_(render_frame_id) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(context_);
+}
+
+RenderFrameAudioOutputStreamFactory::~RenderFrameAudioOutputStreamFactory() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+}
+
+void RenderFrameAudioOutputStreamFactory::RequestDeviceAuthorization(
+ media::mojom::AudioOutputStreamProviderRequest stream_provider_request,
+ int64_t session_id,
+ const std::string& device_id,
+ const url::Origin& origin,
+ const RequestDeviceAuthorizationCallback& callback) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ const base::TimeTicks auth_start_time = base::TimeTicks::Now();
+
+ if (!base::IsValueInRangeForNumericType<int>(session_id)) {
+ UMALogDeviceAuthorizationTime(auth_start_time);
+ bad_message::ReceivedBadMessage(context_->GetRenderProcessId(),
+ bad_message::RFAOSF_OUT_OF_RANGE_INTEGER);
+ // Note: We must call the callback even though we are killing the renderer.
+ // This is mandated by mojo.
+ callback.Run(
+ media::OutputDeviceStatus::OUTPUT_DEVICE_STATUS_ERROR_NOT_AUTHORIZED,
+ media::AudioParameters::UnavailableDeviceParams(), std::string());
+ return;
+ }
+
+ context_->RequestDeviceAuthorization(
+ render_frame_id_, static_cast<int>(session_id), device_id, origin,
+ base::Bind(&RenderFrameAudioOutputStreamFactory::AuthorizationCompleted,
+ base::Unretained(this), origin, auth_start_time,
+ base::Passed(std::move(stream_provider_request)), callback));
Ken Rockot(use gerrit already) 2017/03/23 18:28:35 nit: base::Passed(&stream_provider_request) is muc
+}
+
+void RenderFrameAudioOutputStreamFactory::AuthorizationCompleted(
+ const url::Origin& origin,
+ base::TimeTicks auth_start_time,
+ media::mojom::AudioOutputStreamProviderRequest request,
+ const RequestDeviceAuthorizationCallback& callback,
+ media::OutputDeviceStatus status,
+ bool should_send_id,
+ const media::AudioParameters& params,
+ const std::string& raw_device_id) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ UMALogDeviceAuthorizationTime(auth_start_time);
+
+ if (status != media::OUTPUT_DEVICE_STATUS_OK) {
+ callback.Run(media::OutputDeviceStatus(status),
+ media::AudioParameters::UnavailableDeviceParams(),
+ std::string());
+ return;
+ }
+
+ stream_providers_.push_back(
+ base::WrapUnique<media::mojom::AudioOutputStreamProvider>(
Ken Rockot(use gerrit already) 2017/03/23 18:28:35 nit: Please use base::MakeUnique<Foo>(args...) ins
+ new media::MojoAudioOutputStreamProvider(
+ std::move(request),
+ base::BindOnce(
+ &RendererAudioOutputStreamFactoryContext::CreateDelegate,
+ base::Unretained(context_), raw_device_id, render_frame_id_),
+ base::Bind(&RenderFrameAudioOutputStreamFactory::RemoveStream,
+ base::Unretained(this)))));
+
+ callback.Run(media::OutputDeviceStatus(status), params,
+ should_send_id
+ ? context_->GetHMACForDeviceId(origin, raw_device_id)
+ : std::string());
+}
+
+void RenderFrameAudioOutputStreamFactory::RemoveStream(
+ media::mojom::AudioOutputStreamProvider* stream_provider) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+
+ auto it = std::find_if(
+ stream_providers_.begin(), stream_providers_.end(),
+ [stream_provider](
+ const std::unique_ptr<media::mojom::AudioOutputStreamProvider>&
+ other) { return other.get() == stream_provider; });
+ std::swap(*it, stream_providers_.back());
+ stream_providers_.pop_back();
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698