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

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

Issue 2319493002: Add mojo interface for audio rendering. (Closed)
Patch Set: Refactor factory. Created 3 years, 11 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/audio_output_service_context.cc
diff --git a/content/browser/renderer_host/media/audio_output_service_context.cc b/content/browser/renderer_host/media/audio_output_service_context.cc
new file mode 100644
index 0000000000000000000000000000000000000000..97a383747f92e50ea5402572d246534aeffafda2
--- /dev/null
+++ b/content/browser/renderer_host/media/audio_output_service_context.cc
@@ -0,0 +1,93 @@
+// 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/audio_output_service_context.h"
+
+#include <algorithm>
+#include <memory>
+#include <utility>
+
+#include "base/memory/ptr_util.h"
+#include "content/browser/media/media_internals.h"
+#include "content/browser/renderer_host/media/audio_output_impl.h"
+#include "content/browser/renderer_host/media/audio_output_service_impl.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/content_browser_client.h"
+#include "content/public/browser/render_frame_host.h"
+#include "content/public/common/content_client.h"
+#include "media/mojo/interfaces/audio_output.mojom.h"
+
+namespace content {
+
+AudioOutputServiceContext::AudioOutputServiceContext(
+ int render_process_id,
+ media::AudioManager* audio_manager,
+ MediaStreamManager* media_stream_manager,
+ AudioMirroringManager* mirroring_manager,
+ const std::string& salt)
+ : render_process_id_(render_process_id),
+ audio_manager_(audio_manager),
+ media_stream_manager_(media_stream_manager),
+ mirroring_manager_(mirroring_manager),
+ salt_(salt),
+ authorization_handler_(audio_manager_,
+ media_stream_manager_,
+ render_process_id_,
+ salt_),
+ services_() {}
+
+AudioOutputServiceContext::~AudioOutputServiceContext() {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+}
+
+void AudioOutputServiceContext::ServiceHadConnectionError(
+ AudioOutputServiceImpl* service) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+
+ auto it = std::find_if(
+ services_.begin(), services_.end(),
+ [service](const std::unique_ptr<AudioOutputServiceImpl>& other_service) {
+ return service == other_service.get();
+ });
+ if (it == services_.end())
+ return;
+ std::swap(*it, services_.back());
+ services_.pop_back();
+}
+
+void AudioOutputServiceContext::CreateService(
+ int frame_host_id,
+ mojo::InterfaceRequest<media::mojom::AudioOutputService> request) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+
+ services_.push_back(base::MakeUnique<AudioOutputServiceImpl>(
+ this, frame_host_id,
+ base::Bind(&AudioOutputServiceContext::ServiceHadConnectionError,
+ base::Unretained(this)),
+ std::move(request)));
+}
+
+AudioOutputDelegate::UniquePtr AudioOutputServiceContext::CreateDelegate(
+ const std::string& unique_device_id,
+ int render_frame_id,
+ AudioOutputDelegate::EventHandler* handler,
+ const media::AudioParameters& params) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ int stream_id = next_stream_id_++;
+ MediaObserver* const media_observer =
+ GetContentClient()->browser()->GetMediaObserver();
+
+ MediaInternals* const media_internals = MediaInternals::GetInstance();
+ std::unique_ptr<media::AudioLog> audio_log = media_internals->CreateAudioLog(
+ media::AudioLogFactory::AUDIO_OUTPUT_CONTROLLER);
+ media_internals->SetWebContentsTitleForAudioLogEntry(
+ stream_id, render_process_id_, render_frame_id, audio_log.get());
+
+ return AudioOutputDelegate::Create(
+ handler, audio_manager_, std::move(audio_log), mirroring_manager_,
+ media_observer, stream_id, render_frame_id, render_process_id_, params,
+ unique_device_id);
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698