Revert "Add ability to capture audio output to buffer (see issue #2381)"

This reverts commit 9f41a27e58.

This needs to be reimplemented to support out of process audio (see issue #2755).
This commit is contained in:
Marshall Greenblatt
2019-09-20 16:56:57 +03:00
parent 46d3a81ba0
commit e3723dcda5
27 changed files with 11 additions and 2116 deletions

View File

@@ -1,107 +0,0 @@
// Copyright (c) 2018 The Chromium Embedded Framework Authors.
// Portions copyright (c) 2011 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 "libcef/browser/audio_mirror_destination.h"
#include "libcef/browser/audio_push_sink.h"
#include "base/task/post_task.h"
#include "content/public/browser/browser_task_traits.h"
#include "media/base/bind_to_current_loop.h"
CefAudioMirrorDestination::CefAudioMirrorDestination(
CefRefPtr<CefBrowserHostImpl> browser,
CefRefPtr<CefAudioHandler> cef_audio_handler,
content::AudioMirroringManager* mirroring_manager)
: browser_(browser),
cef_audio_handler_(cef_audio_handler),
mirroring_manager_(mirroring_manager) {
DCHECK(mirroring_manager_);
thread_checker_.DetachFromThread();
}
void CefAudioMirrorDestination::Start() {
DCHECK(thread_checker_.CalledOnValidThread());
base::PostTaskWithTraits(
FROM_HERE, {content::BrowserThread::IO},
base::BindOnce(&content::AudioMirroringManager::StartMirroring,
base::Unretained(mirroring_manager_),
base::RetainedRef(this)));
}
void CefAudioMirrorDestination::Stop() {
DCHECK(thread_checker_.CalledOnValidThread());
base::PostTaskWithTraits(
FROM_HERE, {content::BrowserThread::IO},
base::BindOnce(&content::AudioMirroringManager::StopMirroring,
base::Unretained(mirroring_manager_),
base::RetainedRef(this)));
}
// Asynchronously query whether this MirroringDestination wants to consume
// audio sourced from each of the |candidates|. |results_callback| is run
// to indicate which of them (or none) should have audio routed to this
// MirroringDestination. The second parameter of |results_callback|
// indicates whether the MirroringDestination wants either: 1) exclusive
// access to a diverted audio flow versus 2) a duplicate copy of the audio
// flow. |results_callback| must be run on the same thread as the one that
// called QueryForMatches().
void CefAudioMirrorDestination::QueryForMatches(
const std::set<content::GlobalFrameRoutingId>& candidates,
MatchesCallback results_callback) {
base::PostTaskWithTraits(
FROM_HERE, {content::BrowserThread::UI},
base::BindOnce(&CefAudioMirrorDestination::QueryForMatchesOnUIThread,
base::RetainedRef(this), candidates,
media::BindToCurrentLoop(std::move(results_callback))));
}
void CefAudioMirrorDestination::QueryForMatchesOnUIThread(
const std::set<content::GlobalFrameRoutingId>& candidates,
MatchesCallback results_callback) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
std::set<content::GlobalFrameRoutingId> matches;
for (auto& candidate : candidates) {
CefRefPtr<CefBrowserHostImpl> browser =
CefBrowserHostImpl::GetBrowserForFrameRoute(candidate.child_id,
candidate.frame_routing_id);
if (browser == browser_) {
matches.insert(candidate);
}
}
std::move(results_callback).Run(matches, true);
}
// Create a consumer of audio data in the format specified by |params|, and
// connect it as an input to mirroring. This is used to provide
// MirroringDestination with exclusive access to pull the audio flow from
// the source. When Close() is called on the returned AudioOutputStream, the
// input is disconnected and the object becomes invalid.
media::AudioOutputStream* CefAudioMirrorDestination::AddInput(
const media::AudioParameters& params) {
// TODO Check and add usage on CEF
return nullptr;
}
// Create a consumer of audio data in the format specified by |params|, and
// connect it as an input to mirroring. This is used to provide
// MirroringDestination with duplicate audio data, which is pushed from the
// main audio flow. When Close() is called on the returned AudioPushSink,
// the input is disconnected and the object becomes invalid.
media::AudioPushSink* CefAudioMirrorDestination::AddPushInput(
const media::AudioParameters& params) {
return new CefAudioPushSink(
params, browser_, cef_audio_handler_,
base::Bind(&CefAudioMirrorDestination::ReleasePushInput,
base::RetainedRef(this)));
}
void CefAudioMirrorDestination::ReleasePushInput(CefAudioPushSink* sink) {
delete sink;
}

View File

@@ -1,83 +0,0 @@
// Copyright (c) 2018 The Chromium Embedded Framework Authors.
// Portions copyright (c) 2011 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.
#ifndef CEF_LIBCEF_BROWSER_AUDIO_MIRROR_DESTINATION_H_
#define CEF_LIBCEF_BROWSER_AUDIO_MIRROR_DESTINATION_H_
#pragma once
#include "include/cef_audio_handler.h"
#include "include/cef_base.h"
#include "libcef/browser/browser_host_impl.h"
#include "base/callback.h"
#include "base/threading/thread_checker.h"
#include "content/browser/media/capture/audio_mirroring_manager.h"
#include "media/audio/audio_io.h"
#include "media/base/audio_converter.h"
#include "media/base/audio_parameters.h"
class CefAudioPushSink;
class CefBrowserHostImpl;
class CefAudioMirrorDestination
: public base::RefCountedThreadSafe<CefAudioMirrorDestination>,
public content::AudioMirroringManager::MirroringDestination {
public:
CefAudioMirrorDestination(CefRefPtr<CefBrowserHostImpl> browser,
CefRefPtr<CefAudioHandler> cef_audio_handler,
content::AudioMirroringManager* mirroring_manager);
// Start mirroring. This needs to be triggered on the IO thread.
void Start();
// Stop mirroring. This needs to be triggered on the IO thread.
void Stop();
// Asynchronously query whether this MirroringDestination wants to consume
// audio sourced from each of the |candidates|. |results_callback| is run
// to indicate which of them (or none) should have audio routed to this
// MirroringDestination. The second parameter of |results_callback|
// indicates whether the MirroringDestination wants either: 1) exclusive
// access to a diverted audio flow versus 2) a duplicate copy of the audio
// flow. |results_callback| must be run on the same thread as the one that
// called QueryForMatches().
void QueryForMatches(
const std::set<content::GlobalFrameRoutingId>& candidates,
MatchesCallback results_callback) override;
// Create a consumer of audio data in the format specified by |params|, and
// connect it as an input to mirroring. This is used to provide
// MirroringDestination with exclusive access to pull the audio flow from
// the source. When Close() is called on the returned AudioOutputStream, the
// input is disconnected and the object becomes invalid.
media::AudioOutputStream* AddInput(
const media::AudioParameters& params) override;
// Create a consumer of audio data in the format specified by |params|, and
// connect it as an input to mirroring. This is used to provide
// MirroringDestination with duplicate audio data, which is pushed from the
// main audio flow. When Close() is called on the returned AudioPushSink,
// the input is disconnected and the object becomes invalid.
media::AudioPushSink* AddPushInput(
const media::AudioParameters& params) override;
private:
friend class base::RefCountedThreadSafe<CefAudioMirrorDestination>;
~CefAudioMirrorDestination() override = default;
void QueryForMatchesOnUIThread(
const std::set<content::GlobalFrameRoutingId>& candidates,
MatchesCallback results_callback);
void ReleasePushInput(CefAudioPushSink* sink);
CefRefPtr<CefBrowserHostImpl> browser_;
CefRefPtr<CefAudioHandler> cef_audio_handler_;
content::AudioMirroringManager* mirroring_manager_;
base::ThreadChecker thread_checker_;
};
#endif // CEF_LIBCEF_BROWSER_AUDIO_MIRROR_DESTINATION_H_

View File

@@ -1,172 +0,0 @@
// Copyright (c) 2018 The Chromium Embedded Framework Authors.
// Portions copyright (c) 2011 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 "libcef/browser/audio_push_sink.h"
#include "libcef/browser/thread_util.h"
#include "base/bind.h"
#include "base/logging.h"
#include "media/base/audio_sample_types.h"
#include "media/base/data_buffer.h"
using namespace media;
namespace {
cef_channel_layout_t TranslateChannelLayout(ChannelLayout channel) {
switch (channel) {
case CHANNEL_LAYOUT_UNSUPPORTED:
return CEF_CHANNEL_LAYOUT_UNSUPPORTED;
case CHANNEL_LAYOUT_MONO:
return CEF_CHANNEL_LAYOUT_MONO;
case CHANNEL_LAYOUT_STEREO:
return CEF_CHANNEL_LAYOUT_STEREO;
case CHANNEL_LAYOUT_2_1:
return CEF_CHANNEL_LAYOUT_2_1;
case CHANNEL_LAYOUT_SURROUND:
return CEF_CHANNEL_LAYOUT_SURROUND;
case CHANNEL_LAYOUT_4_0:
return CEF_CHANNEL_LAYOUT_4_0;
case CHANNEL_LAYOUT_2_2:
return CEF_CHANNEL_LAYOUT_2_2;
case CHANNEL_LAYOUT_QUAD:
return CEF_CHANNEL_LAYOUT_QUAD;
case CHANNEL_LAYOUT_5_0:
return CEF_CHANNEL_LAYOUT_5_0;
case CHANNEL_LAYOUT_5_1:
return CEF_CHANNEL_LAYOUT_5_1;
case CHANNEL_LAYOUT_5_0_BACK:
return CEF_CHANNEL_LAYOUT_5_0_BACK;
case CHANNEL_LAYOUT_5_1_BACK:
return CEF_CHANNEL_LAYOUT_5_1_BACK;
case CHANNEL_LAYOUT_7_0:
return CEF_CHANNEL_LAYOUT_7_0;
case CHANNEL_LAYOUT_7_1:
return CEF_CHANNEL_LAYOUT_7_1;
case CHANNEL_LAYOUT_7_1_WIDE:
return CEF_CHANNEL_LAYOUT_7_1_WIDE;
case CHANNEL_LAYOUT_STEREO_DOWNMIX:
return CEF_CHANNEL_LAYOUT_STEREO_DOWNMIX;
case CHANNEL_LAYOUT_2POINT1:
return CEF_CHANNEL_LAYOUT_2POINT1;
case CHANNEL_LAYOUT_3_1:
return CEF_CHANNEL_LAYOUT_3_1;
case CHANNEL_LAYOUT_4_1:
return CEF_CHANNEL_LAYOUT_4_1;
case CHANNEL_LAYOUT_6_0:
return CEF_CHANNEL_LAYOUT_6_0;
case CHANNEL_LAYOUT_6_0_FRONT:
return CEF_CHANNEL_LAYOUT_6_0_FRONT;
case CHANNEL_LAYOUT_HEXAGONAL:
return CEF_CHANNEL_LAYOUT_HEXAGONAL;
case CHANNEL_LAYOUT_6_1:
return CEF_CHANNEL_LAYOUT_6_1;
case CHANNEL_LAYOUT_6_1_BACK:
return CEF_CHANNEL_LAYOUT_6_1_BACK;
case CHANNEL_LAYOUT_6_1_FRONT:
return CEF_CHANNEL_LAYOUT_6_1_FRONT;
case CHANNEL_LAYOUT_7_0_FRONT:
return CEF_CHANNEL_LAYOUT_7_0_FRONT;
case CHANNEL_LAYOUT_7_1_WIDE_BACK:
return CEF_CHANNEL_LAYOUT_7_1_WIDE_BACK;
case CHANNEL_LAYOUT_OCTAGONAL:
return CEF_CHANNEL_LAYOUT_OCTAGONAL;
case CHANNEL_LAYOUT_DISCRETE:
return CEF_CHANNEL_LAYOUT_DISCRETE;
case CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC:
return CEF_CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC;
case CHANNEL_LAYOUT_4_1_QUAD_SIDE:
return CEF_CHANNEL_LAYOUT_4_1_QUAD_SIDE;
case CHANNEL_LAYOUT_BITSTREAM:
return CEF_CHANNEL_LAYOUT_BITSTREAM;
case CHANNEL_LAYOUT_NONE:
return CEF_CHANNEL_LAYOUT_NONE;
}
return CEF_CHANNEL_LAYOUT_NONE;
}
} // namespace
int CefAudioPushSink::audio_stream_id = 0;
CefAudioPushSink::CefAudioPushSink(const AudioParameters& params,
CefRefPtr<CefBrowserHostImpl> browser,
CefRefPtr<CefAudioHandler> cef_audio_handler,
const CloseCallback& callback)
: params_(params),
browser_(browser),
cef_audio_handler_(cef_audio_handler),
close_callback_(callback),
stop_stream_(false),
audio_stream_id_(++audio_stream_id) {
// Verify that our enum matches Chromium's values.
static_assert(
static_cast<int>(CEF_CHANNEL_LAYOUT_MAX) ==
static_cast<int>(CHANNEL_LAYOUT_MAX),
"cef_channel_layout_t must match the ChannelLayout enum in Chromium");
DCHECK(params_.IsValid());
DCHECK(browser);
DCHECK(cef_audio_handler);
// VAOS can be constructed on any thread, but will DCHECK that all
// AudioOutputStream methods are called from the same thread.
thread_checker_.DetachFromThread();
base::PostTaskWithTraits(FROM_HERE, {content::BrowserThread::UI},
base::BindOnce(&CefAudioPushSink::InitOnUIThread,
base::Unretained(this)));
}
CefAudioPushSink::~CefAudioPushSink() = default;
void CefAudioPushSink::InitOnUIThread() {
DCHECK(thread_checker_.CalledOnValidThread());
cef_audio_handler_->OnAudioStreamStarted(
browser_.get(), audio_stream_id_, params_.channels(),
TranslateChannelLayout(params_.channel_layout()), params_.sample_rate(),
params_.frames_per_buffer());
}
void CefAudioPushSink::OnData(std::unique_ptr<media::AudioBus> source,
base::TimeTicks reference_time) {
// early exit if stream already stopped
if (stop_stream_)
return;
if (!CEF_CURRENTLY_ON_UIT()) {
CEF_POST_TASK(CEF_UIT, base::BindOnce(&CefAudioPushSink::OnData,
base::Unretained(this),
std::move(source), reference_time));
return;
}
const int channels = source->channels();
std::vector<const float*> data(channels);
for (int c = 0; c < channels; ++c) {
data[c] = source->channel(c);
}
// Add the packet to the buffer.
base::TimeDelta pts = reference_time - base::TimeTicks::UnixEpoch();
cef_audio_handler_->OnAudioStreamPacket(browser_.get(), audio_stream_id_,
data.data(), source->frames(),
pts.InMilliseconds());
}
void CefAudioPushSink::Close() {
if (!CEF_CURRENTLY_ON_UIT()) {
CEF_POST_TASK(CEF_UIT, base::BindOnce(&CefAudioPushSink::Close,
base::Unretained(this)));
return;
}
if (!stop_stream_) {
stop_stream_ = true;
cef_audio_handler_->OnAudioStreamStopped(browser_.get(), audio_stream_id_);
if (!close_callback_.is_null()) {
std::move(close_callback_).Run(this);
}
}
}

View File

@@ -1,54 +0,0 @@
// Copyright (c) 2018 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.
#ifndef CEF_LIBCEF_BROWSER_AUDIO_PUSH_SINK_H_
#define CEF_LIBCEF_BROWSER_AUDIO_PUSH_SINK_H_
#pragma once
#include "include/cef_audio_handler.h"
#include "include/cef_base.h"
#include "libcef/browser/browser_host_impl.h"
#include "base/callback.h"
#include "base/memory/weak_ptr.h"
#include "base/message_loop/message_loop.h"
#include "base/threading/thread_checker.h"
#include "media/audio/audio_io.h"
#include "media/base/audio_converter.h"
#include "media/base/audio_parameters.h"
#include "media/base/channel_layout.h"
class CefAudioPushSink : public media::AudioPushSink {
public:
typedef base::Callback<void(CefAudioPushSink* sink)> CloseCallback;
CefAudioPushSink(const media::AudioParameters& params,
CefRefPtr<CefBrowserHostImpl> browser,
CefRefPtr<CefAudioHandler> cef_audio_handler,
const CloseCallback& callback);
virtual ~CefAudioPushSink();
void OnData(std::unique_ptr<media::AudioBus> source,
base::TimeTicks reference_time) override;
void Close() override;
private:
void InitOnUIThread();
const media::AudioParameters params_;
CefRefPtr<CefBrowserHostImpl> browser_;
CefRefPtr<CefAudioHandler> cef_audio_handler_;
CloseCallback close_callback_;
base::ThreadChecker thread_checker_;
bool stop_stream_;
int audio_stream_id_;
static int audio_stream_id;
DISALLOW_COPY_AND_ASSIGN(CefAudioPushSink);
};
#endif // CEF_LIBCEF_BROWSER_AUDIO_PUSH_SINK_H_

View File

@@ -8,7 +8,6 @@
#include <string>
#include <utility>
#include "libcef/browser/audio_mirror_destination.h"
#include "libcef/browser/browser_context.h"
#include "libcef/browser/browser_info.h"
#include "libcef/browser/browser_info_manager.h"
@@ -49,7 +48,6 @@
#include "chrome/browser/ui/prefs/prefs_tab_helper.h"
#include "components/zoom/zoom_controller.h"
#include "content/browser/gpu/compositor_util.h"
#include "content/browser/media/capture/audio_mirroring_manager.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/common/widget_messages.h"
#include "content/public/browser/desktop_media_id.h"
@@ -1543,8 +1541,6 @@ void CefBrowserHostImpl::DestroyBrowser() {
menu_manager_->Destroy();
DestroyExtensionHost();
StopAudioMirroring();
// Notify any observers that may have state associated with this browser.
for (auto& observer : observers_)
observer.OnBrowserDestroyed(this);
@@ -2768,28 +2764,6 @@ bool CefBrowserHostImpl::HasObserver(Observer* observer) const {
return observers_.HasObserver(observer);
}
bool CefBrowserHostImpl::StartAudioMirroring() {
if (client_.get()) {
CefRefPtr<CefAudioHandler> audio_handler = client_->GetAudioHandler();
if (audio_handler.get()) {
audio_mirror_destination_ = new CefAudioMirrorDestination(
this, audio_handler, content::AudioMirroringManager::GetInstance());
audio_mirror_destination_->Start();
return true;
}
}
return false;
}
bool CefBrowserHostImpl::StopAudioMirroring() {
if (audio_mirror_destination_.get()) {
audio_mirror_destination_->Stop();
audio_mirror_destination_.reset();
return true;
}
return false;
}
CefBrowserHostImpl::NavigationLock::NavigationLock(
CefRefPtr<CefBrowserHostImpl> browser)
: browser_(browser) {
@@ -2913,8 +2887,6 @@ CefBrowserHostImpl::CefBrowserHostImpl(
// Make sure RenderViewCreated is called at least one time.
RenderViewCreated(web_contents->GetRenderViewHost());
StartAudioMirroring();
// Associate the platform delegate with this browser.
platform_delegate_->BrowserCreated(this);
}

View File

@@ -15,7 +15,6 @@
#include "include/cef_client.h"
#include "include/cef_frame.h"
#include "include/views/cef_browser_view.h"
#include "libcef/browser/audio_mirror_destination.h"
#include "libcef/browser/browser_info.h"
#include "libcef/browser/file_dialog_manager.h"
#include "libcef/browser/frame_host_impl.h"
@@ -49,7 +48,6 @@ class Widget;
}
#endif // defined(USE_AURA)
class CefAudioMirrorDestination;
class CefBrowserInfo;
class CefBrowserPlatformDelegate;
class CefDevToolsFrontend;
@@ -502,10 +500,6 @@ class CefBrowserHostImpl : public CefBrowserHost,
void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer);
bool HasObserver(Observer* observer) const;
bool StartAudioMirroring();
bool StopAudioMirroring();
class NavigationLock final {
private:
friend class CefBrowserHostImpl;
@@ -668,9 +662,6 @@ class CefBrowserHostImpl : public CefBrowserHost,
CefRefPtr<CefExtension> extension_;
bool is_background_host_ = false;
// Used to mirror audio streams
scoped_refptr<CefAudioMirrorDestination> audio_mirror_destination_;
// Used with auto-resize.
bool auto_resize_enabled_ = false;
gfx::Size auto_resize_min_;

View File

@@ -599,13 +599,6 @@ bool CefMainDelegate::BasicStartupComplete(int* exit_code) {
features::kMimeHandlerViewInCrossProcessFrame.name);
}
if (features::kAudioServiceAudioStreams.default_state ==
base::FEATURE_ENABLED_BY_DEFAULT) {
// TODO: Add support for audio service (see issue #2755)
disable_features.push_back(
features::kAudioServiceAudioStreams.name);
}
if (!disable_features.empty()) {
DCHECK(!base::FeatureList::GetInstance());
std::string disable_features_str =