Commit dfd01e83 authored by Antonio Gomes's avatar Antonio Gomes Committed by Commit Bot

Onion soup content/renderer/media_capture_from_element/html_audio_element_capturer_source.cc

This is the last CL on Onion Soup'ing
content/renderer/media_capture_from_element.

The migration was straightforward. Highlights:
- CreateHTMLAudioElementCapturer was moved from blink::Platform to
  html_media_element_capture.cc's anonymous namespace, where it is used.
- content -> blink namespace
- base::Bind{Once,Repeating} -> WTF::Bind{Repeating}
- Removed the use of ScopedTaskEnvironment from the unit tests,
  since the run_blink_ has it already.

BUG=787261
R=dalecurtis@chromium.org, guidou@chromium.org, haraken@chromium.org

Change-Id: I187cfc0889bac56e66d92b2aab79a3a7eb25f76c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1631871
Commit-Queue: Antonio Gomes <tonikitoo@igalia.com>
Reviewed-by: default avatarGuido Urdaneta <guidou@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarDale Curtis <dalecurtis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#665034}
parent 3a858b52
...@@ -350,8 +350,6 @@ target(link_target_type, "renderer") { ...@@ -350,8 +350,6 @@ target(link_target_type, "renderer") {
"media/webrtc_local_audio_source_provider.h", "media/webrtc_local_audio_source_provider.h",
"media/webrtc_logging.cc", "media/webrtc_logging.cc",
"media/webrtc_logging.h", "media/webrtc_logging.h",
"media_capture_from_element/html_audio_element_capturer_source.cc",
"media_capture_from_element/html_audio_element_capturer_source.h",
"media_recorder/audio_track_encoder.cc", "media_recorder/audio_track_encoder.cc",
"media_recorder/audio_track_encoder.h", "media_recorder/audio_track_encoder.h",
"media_recorder/audio_track_opus_encoder.cc", "media_recorder/audio_track_opus_encoder.cc",
......
include_rules = [
"+third_party/libyuv",
]
guidou@chromium.org
# Original (legacy) owner.
emircan@chromium.org
mcasas@chromium.org
# COMPONENT: Blink>MediaStream>CaptureFromElement
# TEAM: webrtc-dev@chromium.org
...@@ -53,7 +53,6 @@ ...@@ -53,7 +53,6 @@
#include "content/renderer/media/audio_decoder.h" #include "content/renderer/media/audio_decoder.h"
#include "content/renderer/media/renderer_webaudiodevice_impl.h" #include "content/renderer/media/renderer_webaudiodevice_impl.h"
#include "content/renderer/media/webrtc/transmission_encoding_info_handler.h" #include "content/renderer/media/webrtc/transmission_encoding_info_handler.h"
#include "content/renderer/media_capture_from_element/html_audio_element_capturer_source.h"
#include "content/renderer/media_recorder/media_recorder_handler.h" #include "content/renderer/media_recorder/media_recorder_handler.h"
#include "content/renderer/mojo/blink_interface_provider_impl.h" #include "content/renderer/mojo/blink_interface_provider_impl.h"
#include "content/renderer/p2p/port_allocator.h" #include "content/renderer/p2p/port_allocator.h"
...@@ -125,9 +124,7 @@ using blink::WebAudioDevice; ...@@ -125,9 +124,7 @@ using blink::WebAudioDevice;
using blink::WebAudioLatencyHint; using blink::WebAudioLatencyHint;
using blink::WebBlobRegistry; using blink::WebBlobRegistry;
using blink::WebDatabaseObserver; using blink::WebDatabaseObserver;
using blink::WebMediaPlayer;
using blink::WebMediaRecorderHandler; using blink::WebMediaRecorderHandler;
using blink::WebMediaStream;
using blink::WebMediaStreamCenter; using blink::WebMediaStreamCenter;
using blink::WebMediaStreamTrack; using blink::WebMediaStreamTrack;
using blink::WebRTCPeerConnectionHandler; using blink::WebRTCPeerConnectionHandler;
...@@ -742,47 +739,6 @@ RendererBlinkPlatformImpl::CreateWebRtcAsyncResolverFactory() { ...@@ -742,47 +739,6 @@ RendererBlinkPlatformImpl::CreateWebRtcAsyncResolverFactory() {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void RendererBlinkPlatformImpl::CreateHTMLAudioElementCapturer(
WebMediaStream* web_media_stream,
WebMediaPlayer* web_media_player,
scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
DCHECK(web_media_stream);
DCHECK(web_media_player);
blink::WebMediaStreamSource web_media_stream_source;
blink::WebMediaStreamTrack web_media_stream_track;
const WebString track_id = WebString::FromUTF8(base::GenerateGUID());
web_media_stream_source.Initialize(track_id,
blink::WebMediaStreamSource::kTypeAudio,
track_id, false /* is_remote */);
web_media_stream_track.Initialize(web_media_stream_source);
blink::MediaStreamAudioSource* const media_stream_source =
HtmlAudioElementCapturerSource::CreateFromWebMediaPlayerImpl(
web_media_player, std::move(task_runner));
// Takes ownership of |media_stream_source|.
web_media_stream_source.SetPlatformSource(
base::WrapUnique(media_stream_source));
blink::WebMediaStreamSource::Capabilities capabilities;
capabilities.device_id = track_id;
capabilities.echo_cancellation = std::vector<bool>({false});
capabilities.auto_gain_control = std::vector<bool>({false});
capabilities.noise_suppression = std::vector<bool>({false});
capabilities.sample_size = {
media::SampleFormatToBitsPerChannel(media::kSampleFormatS16), // min
media::SampleFormatToBitsPerChannel(media::kSampleFormatS16) // max
};
web_media_stream_source.SetCapabilities(capabilities);
media_stream_source->ConnectToTrack(web_media_stream_track);
web_media_stream->AddTrack(web_media_stream_track);
}
//------------------------------------------------------------------------------
std::unique_ptr<webrtc::RtpCapabilities> std::unique_ptr<webrtc::RtpCapabilities>
RendererBlinkPlatformImpl::GetRtpSenderCapabilities( RendererBlinkPlatformImpl::GetRtpSenderCapabilities(
const blink::WebString& kind) { const blink::WebString& kind) {
......
...@@ -40,9 +40,7 @@ namespace scheduler { ...@@ -40,9 +40,7 @@ namespace scheduler {
class WebThreadScheduler; class WebThreadScheduler;
} }
class WebGraphicsContext3DProvider; class WebGraphicsContext3DProvider;
class WebMediaPlayer;
class WebMediaRecorderHandler; class WebMediaRecorderHandler;
class WebMediaStream;
class WebSecurityOrigin; class WebSecurityOrigin;
} // namespace blink } // namespace blink
...@@ -158,10 +156,6 @@ class CONTENT_EXPORT RendererBlinkPlatformImpl : public BlinkPlatformImpl { ...@@ -158,10 +156,6 @@ class CONTENT_EXPORT RendererBlinkPlatformImpl : public BlinkPlatformImpl {
blink::WebLocalFrame* frame) override; blink::WebLocalFrame* frame) override;
std::unique_ptr<webrtc::AsyncResolverFactory> std::unique_ptr<webrtc::AsyncResolverFactory>
CreateWebRtcAsyncResolverFactory() override; CreateWebRtcAsyncResolverFactory() override;
void CreateHTMLAudioElementCapturer(
blink::WebMediaStream* web_media_stream,
blink::WebMediaPlayer* web_media_player,
scoped_refptr<base::SingleThreadTaskRunner> task_runner) override;
std::unique_ptr<webrtc::RtpCapabilities> GetRtpSenderCapabilities( std::unique_ptr<webrtc::RtpCapabilities> GetRtpSenderCapabilities(
const blink::WebString& kind) override; const blink::WebString& kind) override;
std::unique_ptr<webrtc::RtpCapabilities> GetRtpReceiverCapabilities( std::unique_ptr<webrtc::RtpCapabilities> GetRtpReceiverCapabilities(
......
...@@ -1871,7 +1871,6 @@ test("content_unittests") { ...@@ -1871,7 +1871,6 @@ test("content_unittests") {
"../renderer/media/webrtc/webrtc_set_description_observer_unittest.cc", "../renderer/media/webrtc/webrtc_set_description_observer_unittest.cc",
"../renderer/media/webrtc/webrtc_video_track_source_unittest.cc", "../renderer/media/webrtc/webrtc_video_track_source_unittest.cc",
"../renderer/media/webrtc_local_audio_source_provider_unittest.cc", "../renderer/media/webrtc_local_audio_source_provider_unittest.cc",
"../renderer/media_capture_from_element/html_audio_element_capturer_source_unittest.cc",
"../renderer/media_recorder/audio_track_recorder_unittest.cc", "../renderer/media_recorder/audio_track_recorder_unittest.cc",
"../renderer/media_recorder/media_recorder_handler_unittest.cc", "../renderer/media_recorder/media_recorder_handler_unittest.cc",
"../renderer/media_recorder/video_track_recorder_unittest.cc", "../renderer/media_recorder/video_track_recorder_unittest.cc",
......
...@@ -110,9 +110,7 @@ class WebDedicatedWorker; ...@@ -110,9 +110,7 @@ class WebDedicatedWorker;
class WebGraphicsContext3DProvider; class WebGraphicsContext3DProvider;
class WebLocalFrame; class WebLocalFrame;
class WebMediaCapabilitiesClient; class WebMediaCapabilitiesClient;
class WebMediaPlayer;
class WebMediaRecorderHandler; class WebMediaRecorderHandler;
class WebMediaStream;
class WebMediaStreamCenter; class WebMediaStreamCenter;
class WebPrescientNetworking; class WebPrescientNetworking;
class WebPublicSuffixList; class WebPublicSuffixList;
...@@ -629,13 +627,6 @@ class BLINK_PLATFORM_EXPORT Platform { ...@@ -629,13 +627,6 @@ class BLINK_PLATFORM_EXPORT Platform {
virtual std::unique_ptr<webrtc::AsyncResolverFactory> virtual std::unique_ptr<webrtc::AsyncResolverFactory>
CreateWebRtcAsyncResolverFactory(); CreateWebRtcAsyncResolverFactory();
// Fills in the WebMediaStream to capture from the WebMediaPlayer identified
// by the second parameter.
virtual void CreateHTMLAudioElementCapturer(
WebMediaStream*,
WebMediaPlayer*,
scoped_refptr<base::SingleThreadTaskRunner>) {}
// Returns the most optimistic view of the capabilities of the system for // Returns the most optimistic view of the capabilities of the system for
// sending or receiving media of the given kind ("audio" or "video"). // sending or receiving media of the given kind ("audio" or "video").
virtual std::unique_ptr<webrtc::RtpCapabilities> GetRtpSenderCapabilities( virtual std::unique_ptr<webrtc::RtpCapabilities> GetRtpSenderCapabilities(
......
...@@ -323,6 +323,7 @@ jumbo_source_set("unit_tests") { ...@@ -323,6 +323,7 @@ jumbo_source_set("unit_tests") {
"media_controls/media_controls_orientation_lock_delegate_test.cc", "media_controls/media_controls_orientation_lock_delegate_test.cc",
"media_controls/media_controls_rotate_to_fullscreen_delegate_test.cc", "media_controls/media_controls_rotate_to_fullscreen_delegate_test.cc",
"mediacapturefromelement/canvas_capture_handler_unittest.cc", "mediacapturefromelement/canvas_capture_handler_unittest.cc",
"mediacapturefromelement/html_audio_element_capturer_source_unittest.cc",
"mediacapturefromelement/html_video_element_capturer_source_unittest.cc", "mediacapturefromelement/html_video_element_capturer_source_unittest.cc",
"mediastream/media_constraints_test.cc", "mediastream/media_constraints_test.cc",
"mediastream/media_devices_test.cc", "mediastream/media_devices_test.cc",
...@@ -418,6 +419,7 @@ jumbo_source_set("unit_tests") { ...@@ -418,6 +419,7 @@ jumbo_source_set("unit_tests") {
deps = [ deps = [
":modules", ":modules",
":modules_testing", ":modules_testing",
"//media:test_support",
"//net:quic_test_tools", "//net:quic_test_tools",
"//services/device/public/cpp:test_support", "//services/device/public/cpp:test_support",
"//services/viz/public/interfaces:interfaces_blink", "//services/viz/public/interfaces:interfaces_blink",
......
...@@ -12,6 +12,8 @@ blink_modules_sources("mediacapturefromelement") { ...@@ -12,6 +12,8 @@ blink_modules_sources("mediacapturefromelement") {
"canvas_capture_handler.h", "canvas_capture_handler.h",
"canvas_capture_media_stream_track.cc", "canvas_capture_media_stream_track.cc",
"canvas_capture_media_stream_track.h", "canvas_capture_media_stream_track.h",
"html_audio_element_capturer_source.cc",
"html_audio_element_capturer_source.h",
"html_canvas_element_capture.cc", "html_canvas_element_capture.cc",
"html_canvas_element_capture.h", "html_canvas_element_capture.h",
"html_media_element_capture.cc", "html_media_element_capture.cc",
......
...@@ -20,4 +20,7 @@ specific_include_rules = { ...@@ -20,4 +20,7 @@ specific_include_rules = {
"+base/run_loop.h", "+base/run_loop.h",
"+cc/paint/paint_flags.h", "+cc/paint/paint_flags.h",
], ],
"html_audio_element_capturer_source_unittest.cc" : [
"+media/audio/null_audio_sink.h",
],
} }
...@@ -2,20 +2,21 @@ ...@@ -2,20 +2,21 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "content/renderer/media_capture_from_element/html_audio_element_capturer_source.h" #include "third_party/blink/renderer/modules/mediacapturefromelement/html_audio_element_capturer_source.h"
#include <utility> #include <utility>
#include "base/bind.h"
#include "base/threading/thread_task_runner_handle.h"
#include "media/base/audio_parameters.h" #include "media/base/audio_parameters.h"
#include "media/base/audio_renderer_sink.h" #include "media/base/audio_renderer_sink.h"
#include "third_party/blink/public/platform/web_media_player.h" #include "third_party/blink/public/platform/web_media_player.h"
#include "third_party/blink/public/platform/webaudiosourceprovider_impl.h" #include "third_party/blink/public/platform/webaudiosourceprovider_impl.h"
#include "third_party/blink/renderer/platform/cross_thread_functional.h"
#include "third_party/blink/renderer/platform/scheduler/public/thread.h"
#include "third_party/blink/renderer/platform/wtf/functional.h"
namespace content { namespace blink {
//static // static
HtmlAudioElementCapturerSource* HtmlAudioElementCapturerSource*
HtmlAudioElementCapturerSource::CreateFromWebMediaPlayerImpl( HtmlAudioElementCapturerSource::CreateFromWebMediaPlayerImpl(
blink::WebMediaPlayer* player, blink::WebMediaPlayer* player,
...@@ -42,34 +43,35 @@ HtmlAudioElementCapturerSource::HtmlAudioElementCapturerSource( ...@@ -42,34 +43,35 @@ HtmlAudioElementCapturerSource::HtmlAudioElementCapturerSource(
} }
HtmlAudioElementCapturerSource::~HtmlAudioElementCapturerSource() { HtmlAudioElementCapturerSource::~HtmlAudioElementCapturerSource() {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
EnsureSourceIsStopped(); EnsureSourceIsStopped();
} }
bool HtmlAudioElementCapturerSource::EnsureSourceIsStarted() { bool HtmlAudioElementCapturerSource::EnsureSourceIsStarted() {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
if (audio_source_ && !is_started_) { if (audio_source_ && !is_started_) {
base::ThreadTaskRunnerHandle::Get()->PostTask( // TODO(crbug.com/964463): Use per-frame task runner.
FROM_HERE, Thread::Current()->GetTaskRunner()->PostTask(
base::BindOnce(&HtmlAudioElementCapturerSource::SetAudioCallback, FROM_HERE, WTF::Bind(&HtmlAudioElementCapturerSource::SetAudioCallback,
weak_factory_.GetWeakPtr())); weak_factory_.GetWeakPtr()));
is_started_ = true; is_started_ = true;
} }
return is_started_; return is_started_;
} }
void HtmlAudioElementCapturerSource::SetAudioCallback() { void HtmlAudioElementCapturerSource::SetAudioCallback() {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
if (audio_source_ && is_started_) { if (audio_source_ && is_started_) {
// base:Unretained() is safe here since EnsureSourceIsStopped() guarantees // WTF::Unretained() is safe here since EnsureSourceIsStopped() guarantees
// no more calls to OnAudioBus(). // no more calls to OnAudioBus().
audio_source_->SetCopyAudioCallback(base::BindRepeating( audio_source_->SetCopyAudioCallback(ConvertToBaseCallback(
&HtmlAudioElementCapturerSource::OnAudioBus, base::Unretained(this))); CrossThreadBind(&HtmlAudioElementCapturerSource::OnAudioBus,
CrossThreadUnretained(this))));
} }
} }
void HtmlAudioElementCapturerSource::EnsureSourceIsStopped() { void HtmlAudioElementCapturerSource::EnsureSourceIsStopped() {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
if (!is_started_) if (!is_started_)
return; return;
...@@ -104,4 +106,4 @@ void HtmlAudioElementCapturerSource::OnAudioBus( ...@@ -104,4 +106,4 @@ void HtmlAudioElementCapturerSource::OnAudioBus(
blink::MediaStreamAudioSource::DeliverDataToTracks(*audio_bus, capture_time); blink::MediaStreamAudioSource::DeliverDataToTracks(*audio_bus, capture_time);
} }
} // namespace content } // namespace blink
...@@ -2,14 +2,15 @@ ...@@ -2,14 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CONTENT_RENDERER_MEDIA_CAPTURE_FROM_ELEMENT_HTML_AUDIO_ELEMENT_CAPTURER_SOURCE_H_ #ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_MEDIACAPTUREFROMELEMENT_HTML_AUDIO_ELEMENT_CAPTURER_SOURCE_H_
#define CONTENT_RENDERER_MEDIA_CAPTURE_FROM_ELEMENT_HTML_AUDIO_ELEMENT_CAPTURER_SOURCE_H_ #define THIRD_PARTY_BLINK_RENDERER_MODULES_MEDIACAPTUREFROMELEMENT_HTML_AUDIO_ELEMENT_CAPTURER_SOURCE_H_
#include "base/callback.h" #include "base/callback.h"
#include "base/memory/scoped_refptr.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/threading/thread_checker.h" #include "base/threading/thread_checker.h"
#include "content/common/content_export.h"
#include "third_party/blink/public/platform/modules/mediastream/media_stream_audio_source.h" #include "third_party/blink/public/platform/modules/mediastream/media_stream_audio_source.h"
#include "third_party/blink/renderer/modules/modules_export.h"
namespace blink { namespace blink {
class WebMediaPlayer; class WebMediaPlayer;
...@@ -20,13 +21,13 @@ namespace media { ...@@ -20,13 +21,13 @@ namespace media {
class AudioBus; class AudioBus;
} // namespace media } // namespace media
namespace content { namespace blink {
// This class is a blink::MediaStreamAudioSource that registers to the // This class is a blink::MediaStreamAudioSource that registers to the
// constructor- passed weak WebAudioSourceProviderImpl to receive a copy of the // constructor- passed weak WebAudioSourceProviderImpl to receive a copy of the
// audio data intended for rendering. This copied data is received on // audio data intended for rendering. This copied data is received on
// OnAudioBus() and sent to all the registered Tracks. // OnAudioBus() and sent to all the registered Tracks.
class CONTENT_EXPORT HtmlAudioElementCapturerSource final class MODULES_EXPORT HtmlAudioElementCapturerSource final
: public blink::MediaStreamAudioSource { : public blink::MediaStreamAudioSource {
public: public:
static HtmlAudioElementCapturerSource* CreateFromWebMediaPlayerImpl( static HtmlAudioElementCapturerSource* CreateFromWebMediaPlayerImpl(
...@@ -56,13 +57,13 @@ class CONTENT_EXPORT HtmlAudioElementCapturerSource final ...@@ -56,13 +57,13 @@ class CONTENT_EXPORT HtmlAudioElementCapturerSource final
int last_num_channels_; int last_num_channels_;
int last_bus_frames_; int last_bus_frames_;
base::ThreadChecker thread_checker_; THREAD_CHECKER(thread_checker_);
base::WeakPtrFactory<HtmlAudioElementCapturerSource> weak_factory_; base::WeakPtrFactory<HtmlAudioElementCapturerSource> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(HtmlAudioElementCapturerSource); DISALLOW_COPY_AND_ASSIGN(HtmlAudioElementCapturerSource);
}; };
} // namespace content } // namespace blink
#endif // CONTENT_RENDERER_MEDIA_CAPTURE_FROM_ELEMENT_HTML_AUDIO_ELEMENT_CAPTURER_SOURCE_H_ #endif // THIRD_PARTY_BLINK_RENDERER_MODULES_MEDIACAPTUREFROMELEMENT_HTML_AUDIO_ELEMENT_CAPTURER_SOURCE_H_
...@@ -2,11 +2,10 @@ ...@@ -2,11 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "content/renderer/media_capture_from_element/html_audio_element_capturer_source.h" #include "third_party/blink/renderer/modules/mediacapturefromelement/html_audio_element_capturer_source.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/test/scoped_task_environment.h"
#include "base/threading/thread_task_runner_handle.h"
#include "media/audio/null_audio_sink.h" #include "media/audio/null_audio_sink.h"
#include "media/base/audio_parameters.h" #include "media/base/audio_parameters.h"
#include "media/base/fake_audio_render_callback.h" #include "media/base/fake_audio_render_callback.h"
...@@ -26,7 +25,7 @@ using ::testing::InSequence; ...@@ -26,7 +25,7 @@ using ::testing::InSequence;
using ::testing::Mock; using ::testing::Mock;
using ::testing::Property; using ::testing::Property;
namespace content { namespace blink {
static const int kNumChannelsForTest = 1; static const int kNumChannelsForTest = 1;
static const int kBufferDurationMs = 10; static const int kBufferDurationMs = 10;
...@@ -116,8 +115,6 @@ class HTMLAudioElementCapturerSourceTest : public testing::Test { ...@@ -116,8 +115,6 @@ class HTMLAudioElementCapturerSourceTest : public testing::Test {
ASSERT_TRUE(source()->ConnectToTrack(blink_audio_track_)); ASSERT_TRUE(source()->ConnectToTrack(blink_audio_track_));
} }
const base::test::ScopedTaskEnvironment scoped_task_environment_;
blink::WebMediaStreamSource blink_audio_source_; blink::WebMediaStreamSource blink_audio_source_;
blink::WebMediaStreamTrack blink_audio_track_; blink::WebMediaStreamTrack blink_audio_track_;
...@@ -127,8 +124,7 @@ class HTMLAudioElementCapturerSourceTest : public testing::Test { ...@@ -127,8 +124,7 @@ class HTMLAudioElementCapturerSourceTest : public testing::Test {
}; };
// Constructs and destructs all objects. This is a non trivial sequence. // Constructs and destructs all objects. This is a non trivial sequence.
TEST_F(HTMLAudioElementCapturerSourceTest, ConstructAndDestruct) { TEST_F(HTMLAudioElementCapturerSourceTest, ConstructAndDestruct) {}
}
// This test verifies that Audio can be properly captured when injected in the // This test verifies that Audio can be properly captured when injected in the
// WebAudioSourceProviderImpl. // WebAudioSourceProviderImpl.
...@@ -150,8 +146,8 @@ TEST_F(HTMLAudioElementCapturerSourceTest, CaptureAudio) { ...@@ -150,8 +146,8 @@ TEST_F(HTMLAudioElementCapturerSourceTest, CaptureAudio) {
.Times(1) .Times(1)
.WillOnce([&](const auto&, auto) { std::move(quit_closure).Run(); }); .WillOnce([&](const auto&, auto) { std::move(quit_closure).Run(); });
std::unique_ptr<media::AudioBus> bus = media::AudioBus::Create( std::unique_ptr<media::AudioBus> bus =
kNumChannelsForTest, kAudioTrackSamplesPerBuffer); media::AudioBus::Create(kNumChannelsForTest, kAudioTrackSamplesPerBuffer);
InjectAudio(bus.get()); InjectAudio(bus.get());
run_loop.Run(); run_loop.Run();
...@@ -191,4 +187,4 @@ TEST_F(HTMLAudioElementCapturerSourceTest, ...@@ -191,4 +187,4 @@ TEST_F(HTMLAudioElementCapturerSourceTest,
track()->RemoveSink(&sink); track()->RemoveSink(&sink);
} }
} // namespace content } // namespace blink
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "third_party/blink/renderer/modules/mediacapturefromelement/html_media_element_capture.h" #include "third_party/blink/renderer/modules/mediacapturefromelement/html_media_element_capture.h"
#include "third_party/blink/public/platform/modules/mediastream/media_stream_audio_source.h"
#include "third_party/blink/public/platform/platform.h" #include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/public/platform/task_type.h" #include "third_party/blink/public/platform/task_type.h"
#include "third_party/blink/public/platform/web_media_stream.h" #include "third_party/blink/public/platform/web_media_stream.h"
...@@ -18,6 +19,7 @@ ...@@ -18,6 +19,7 @@
#include "third_party/blink/renderer/core/html/track/video_track_list.h" #include "third_party/blink/renderer/core/html/track/video_track_list.h"
#include "third_party/blink/renderer/modules/encryptedmedia/html_media_element_encrypted_media.h" #include "third_party/blink/renderer/modules/encryptedmedia/html_media_element_encrypted_media.h"
#include "third_party/blink/renderer/modules/encryptedmedia/media_keys.h" #include "third_party/blink/renderer/modules/encryptedmedia/media_keys.h"
#include "third_party/blink/renderer/modules/mediacapturefromelement/html_audio_element_capturer_source.h"
#include "third_party/blink/renderer/modules/mediacapturefromelement/html_video_element_capturer_source.h" #include "third_party/blink/renderer/modules/mediacapturefromelement/html_video_element_capturer_source.h"
#include "third_party/blink/renderer/modules/mediastream/media_stream.h" #include "third_party/blink/renderer/modules/mediastream/media_stream.h"
#include "third_party/blink/renderer/platform/mediastream/media_stream_center.h" #include "third_party/blink/renderer/platform/mediastream/media_stream_center.h"
...@@ -83,6 +85,47 @@ void CreateHTMLVideoElementCapturer( ...@@ -83,6 +85,47 @@ void CreateHTMLVideoElementCapturer(
web_media_stream); web_media_stream);
} }
// Fills in the WebMediaStream to capture from the WebMediaPlayer identified
// by the second parameter.
void CreateHTMLAudioElementCapturer(
WebMediaStream* web_media_stream,
WebMediaPlayer* web_media_player,
scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
DCHECK(web_media_stream);
DCHECK(web_media_player);
blink::WebMediaStreamSource web_media_stream_source;
blink::WebMediaStreamTrack web_media_stream_track;
const WebString track_id(CreateCanonicalUUIDString());
web_media_stream_source.Initialize(track_id,
blink::WebMediaStreamSource::kTypeAudio,
track_id, false /* is_remote */);
web_media_stream_track.Initialize(web_media_stream_source);
blink::MediaStreamAudioSource* const media_stream_source =
HtmlAudioElementCapturerSource::CreateFromWebMediaPlayerImpl(
web_media_player, std::move(task_runner));
// Takes ownership of |media_stream_source|.
web_media_stream_source.SetPlatformSource(
base::WrapUnique(media_stream_source));
blink::WebMediaStreamSource::Capabilities capabilities;
capabilities.device_id = track_id;
capabilities.echo_cancellation = std::vector<bool>({false});
capabilities.auto_gain_control = std::vector<bool>({false});
capabilities.noise_suppression = std::vector<bool>({false});
capabilities.sample_size = {
media::SampleFormatToBitsPerChannel(media::kSampleFormatS16), // min
media::SampleFormatToBitsPerChannel(media::kSampleFormatS16) // max
};
web_media_stream_source.SetCapabilities(capabilities);
media_stream_source->ConnectToTrack(web_media_stream_track);
web_media_stream->AddTrack(web_media_stream_track);
}
// Class to register to the events of |m_mediaElement|, acting accordingly on // Class to register to the events of |m_mediaElement|, acting accordingly on
// the tracks of |m_mediaStream|. // the tracks of |m_mediaStream|.
class MediaElementEventListener final : public NativeEventListener { class MediaElementEventListener final : public NativeEventListener {
...@@ -157,7 +200,7 @@ void MediaElementEventListener::Invoke(ExecutionContext* context, ...@@ -157,7 +200,7 @@ void MediaElementEventListener::Invoke(ExecutionContext* context,
TaskType::kInternalMediaRealTime)); TaskType::kInternalMediaRealTime));
} }
if (media_element_->HasAudio()) { if (media_element_->HasAudio()) {
Platform::Current()->CreateHTMLAudioElementCapturer( CreateHTMLAudioElementCapturer(
&web_stream, media_element_->GetWebMediaPlayer(), &web_stream, media_element_->GetWebMediaPlayer(),
media_element_->GetExecutionContext()->GetTaskRunner( media_element_->GetExecutionContext()->GetTaskRunner(
TaskType::kInternalMediaRealTime)); TaskType::kInternalMediaRealTime));
...@@ -243,10 +286,9 @@ MediaStream* HTMLMediaElementCapture::captureStream( ...@@ -243,10 +286,9 @@ MediaStream* HTMLMediaElementCapture::captureStream(
TaskType::kInternalMediaRealTime)); TaskType::kInternalMediaRealTime));
} }
if (element.HasAudio()) { if (element.HasAudio()) {
Platform::Current()->CreateHTMLAudioElementCapturer( CreateHTMLAudioElementCapturer(&web_stream, element.GetWebMediaPlayer(),
&web_stream, element.GetWebMediaPlayer(), element.GetExecutionContext()->GetTaskRunner(
element.GetExecutionContext()->GetTaskRunner( TaskType::kInternalMediaRealTime));
TaskType::kInternalMediaRealTime));
} }
listener->UpdateSources(context); listener->UpdateSources(context);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment