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") {
"media/webrtc_local_audio_source_provider.h",
"media/webrtc_logging.cc",
"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.h",
"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 @@
#include "content/renderer/media/audio_decoder.h"
#include "content/renderer/media/renderer_webaudiodevice_impl.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/mojo/blink_interface_provider_impl.h"
#include "content/renderer/p2p/port_allocator.h"
......@@ -125,9 +124,7 @@ using blink::WebAudioDevice;
using blink::WebAudioLatencyHint;
using blink::WebBlobRegistry;
using blink::WebDatabaseObserver;
using blink::WebMediaPlayer;
using blink::WebMediaRecorderHandler;
using blink::WebMediaStream;
using blink::WebMediaStreamCenter;
using blink::WebMediaStreamTrack;
using blink::WebRTCPeerConnectionHandler;
......@@ -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>
RendererBlinkPlatformImpl::GetRtpSenderCapabilities(
const blink::WebString& kind) {
......
......@@ -40,9 +40,7 @@ namespace scheduler {
class WebThreadScheduler;
}
class WebGraphicsContext3DProvider;
class WebMediaPlayer;
class WebMediaRecorderHandler;
class WebMediaStream;
class WebSecurityOrigin;
} // namespace blink
......@@ -158,10 +156,6 @@ class CONTENT_EXPORT RendererBlinkPlatformImpl : public BlinkPlatformImpl {
blink::WebLocalFrame* frame) override;
std::unique_ptr<webrtc::AsyncResolverFactory>
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(
const blink::WebString& kind) override;
std::unique_ptr<webrtc::RtpCapabilities> GetRtpReceiverCapabilities(
......
......@@ -1871,7 +1871,6 @@ test("content_unittests") {
"../renderer/media/webrtc/webrtc_set_description_observer_unittest.cc",
"../renderer/media/webrtc/webrtc_video_track_source_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/media_recorder_handler_unittest.cc",
"../renderer/media_recorder/video_track_recorder_unittest.cc",
......
......@@ -110,9 +110,7 @@ class WebDedicatedWorker;
class WebGraphicsContext3DProvider;
class WebLocalFrame;
class WebMediaCapabilitiesClient;
class WebMediaPlayer;
class WebMediaRecorderHandler;
class WebMediaStream;
class WebMediaStreamCenter;
class WebPrescientNetworking;
class WebPublicSuffixList;
......@@ -629,13 +627,6 @@ class BLINK_PLATFORM_EXPORT Platform {
virtual std::unique_ptr<webrtc::AsyncResolverFactory>
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
// sending or receiving media of the given kind ("audio" or "video").
virtual std::unique_ptr<webrtc::RtpCapabilities> GetRtpSenderCapabilities(
......
......@@ -323,6 +323,7 @@ jumbo_source_set("unit_tests") {
"media_controls/media_controls_orientation_lock_delegate_test.cc",
"media_controls/media_controls_rotate_to_fullscreen_delegate_test.cc",
"mediacapturefromelement/canvas_capture_handler_unittest.cc",
"mediacapturefromelement/html_audio_element_capturer_source_unittest.cc",
"mediacapturefromelement/html_video_element_capturer_source_unittest.cc",
"mediastream/media_constraints_test.cc",
"mediastream/media_devices_test.cc",
......@@ -418,6 +419,7 @@ jumbo_source_set("unit_tests") {
deps = [
":modules",
":modules_testing",
"//media:test_support",
"//net:quic_test_tools",
"//services/device/public/cpp:test_support",
"//services/viz/public/interfaces:interfaces_blink",
......
......@@ -12,6 +12,8 @@ blink_modules_sources("mediacapturefromelement") {
"canvas_capture_handler.h",
"canvas_capture_media_stream_track.cc",
"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.h",
"html_media_element_capture.cc",
......
......@@ -20,4 +20,7 @@ specific_include_rules = {
"+base/run_loop.h",
"+cc/paint/paint_flags.h",
],
"html_audio_element_capturer_source_unittest.cc" : [
"+media/audio/null_audio_sink.h",
],
}
......@@ -2,20 +2,21 @@
// Use of this source code is governed by a BSD-style license that can be
// 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 "base/bind.h"
#include "base/threading/thread_task_runner_handle.h"
#include "media/base/audio_parameters.h"
#include "media/base/audio_renderer_sink.h"
#include "third_party/blink/public/platform/web_media_player.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::CreateFromWebMediaPlayerImpl(
blink::WebMediaPlayer* player,
......@@ -42,34 +43,35 @@ HtmlAudioElementCapturerSource::HtmlAudioElementCapturerSource(
}
HtmlAudioElementCapturerSource::~HtmlAudioElementCapturerSource() {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
EnsureSourceIsStopped();
}
bool HtmlAudioElementCapturerSource::EnsureSourceIsStarted() {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
if (audio_source_ && !is_started_) {
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::BindOnce(&HtmlAudioElementCapturerSource::SetAudioCallback,
weak_factory_.GetWeakPtr()));
// TODO(crbug.com/964463): Use per-frame task runner.
Thread::Current()->GetTaskRunner()->PostTask(
FROM_HERE, WTF::Bind(&HtmlAudioElementCapturerSource::SetAudioCallback,
weak_factory_.GetWeakPtr()));
is_started_ = true;
}
return is_started_;
}
void HtmlAudioElementCapturerSource::SetAudioCallback() {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
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().
audio_source_->SetCopyAudioCallback(base::BindRepeating(
&HtmlAudioElementCapturerSource::OnAudioBus, base::Unretained(this)));
audio_source_->SetCopyAudioCallback(ConvertToBaseCallback(
CrossThreadBind(&HtmlAudioElementCapturerSource::OnAudioBus,
CrossThreadUnretained(this))));
}
}
void HtmlAudioElementCapturerSource::EnsureSourceIsStopped() {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
if (!is_started_)
return;
......@@ -104,4 +106,4 @@ void HtmlAudioElementCapturerSource::OnAudioBus(
blink::MediaStreamAudioSource::DeliverDataToTracks(*audio_bus, capture_time);
}
} // namespace content
} // namespace blink
......@@ -2,14 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_RENDERER_MEDIA_CAPTURE_FROM_ELEMENT_HTML_AUDIO_ELEMENT_CAPTURER_SOURCE_H_
#define 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 THIRD_PARTY_BLINK_RENDERER_MODULES_MEDIACAPTUREFROMELEMENT_HTML_AUDIO_ELEMENT_CAPTURER_SOURCE_H_
#include "base/callback.h"
#include "base/memory/scoped_refptr.h"
#include "base/memory/weak_ptr.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/renderer/modules/modules_export.h"
namespace blink {
class WebMediaPlayer;
......@@ -20,13 +21,13 @@ namespace media {
class AudioBus;
} // namespace media
namespace content {
namespace blink {
// This class is a blink::MediaStreamAudioSource that registers to the
// constructor- passed weak WebAudioSourceProviderImpl to receive a copy of the
// audio data intended for rendering. This copied data is received on
// OnAudioBus() and sent to all the registered Tracks.
class CONTENT_EXPORT HtmlAudioElementCapturerSource final
class MODULES_EXPORT HtmlAudioElementCapturerSource final
: public blink::MediaStreamAudioSource {
public:
static HtmlAudioElementCapturerSource* CreateFromWebMediaPlayerImpl(
......@@ -56,13 +57,13 @@ class CONTENT_EXPORT HtmlAudioElementCapturerSource final
int last_num_channels_;
int last_bus_frames_;
base::ThreadChecker thread_checker_;
THREAD_CHECKER(thread_checker_);
base::WeakPtrFactory<HtmlAudioElementCapturerSource> weak_factory_;
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 @@
// Use of this source code is governed by a BSD-style license that can be
// 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/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/base/audio_parameters.h"
#include "media/base/fake_audio_render_callback.h"
......@@ -26,7 +25,7 @@ using ::testing::InSequence;
using ::testing::Mock;
using ::testing::Property;
namespace content {
namespace blink {
static const int kNumChannelsForTest = 1;
static const int kBufferDurationMs = 10;
......@@ -116,8 +115,6 @@ class HTMLAudioElementCapturerSourceTest : public testing::Test {
ASSERT_TRUE(source()->ConnectToTrack(blink_audio_track_));
}
const base::test::ScopedTaskEnvironment scoped_task_environment_;
blink::WebMediaStreamSource blink_audio_source_;
blink::WebMediaStreamTrack blink_audio_track_;
......@@ -127,8 +124,7 @@ class HTMLAudioElementCapturerSourceTest : public testing::Test {
};
// 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
// WebAudioSourceProviderImpl.
......@@ -150,8 +146,8 @@ TEST_F(HTMLAudioElementCapturerSourceTest, CaptureAudio) {
.Times(1)
.WillOnce([&](const auto&, auto) { std::move(quit_closure).Run(); });
std::unique_ptr<media::AudioBus> bus = media::AudioBus::Create(
kNumChannelsForTest, kAudioTrackSamplesPerBuffer);
std::unique_ptr<media::AudioBus> bus =
media::AudioBus::Create(kNumChannelsForTest, kAudioTrackSamplesPerBuffer);
InjectAudio(bus.get());
run_loop.Run();
......@@ -191,4 +187,4 @@ TEST_F(HTMLAudioElementCapturerSourceTest,
track()->RemoveSink(&sink);
}
} // namespace content
} // namespace blink
......@@ -4,6 +4,7 @@
#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/task_type.h"
#include "third_party/blink/public/platform/web_media_stream.h"
......@@ -18,6 +19,7 @@
#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/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/mediastream/media_stream.h"
#include "third_party/blink/renderer/platform/mediastream/media_stream_center.h"
......@@ -83,6 +85,47 @@ void CreateHTMLVideoElementCapturer(
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
// the tracks of |m_mediaStream|.
class MediaElementEventListener final : public NativeEventListener {
......@@ -157,7 +200,7 @@ void MediaElementEventListener::Invoke(ExecutionContext* context,
TaskType::kInternalMediaRealTime));
}
if (media_element_->HasAudio()) {
Platform::Current()->CreateHTMLAudioElementCapturer(
CreateHTMLAudioElementCapturer(
&web_stream, media_element_->GetWebMediaPlayer(),
media_element_->GetExecutionContext()->GetTaskRunner(
TaskType::kInternalMediaRealTime));
......@@ -243,10 +286,9 @@ MediaStream* HTMLMediaElementCapture::captureStream(
TaskType::kInternalMediaRealTime));
}
if (element.HasAudio()) {
Platform::Current()->CreateHTMLAudioElementCapturer(
&web_stream, element.GetWebMediaPlayer(),
element.GetExecutionContext()->GetTaskRunner(
TaskType::kInternalMediaRealTime));
CreateHTMLAudioElementCapturer(&web_stream, element.GetWebMediaPlayer(),
element.GetExecutionContext()->GetTaskRunner(
TaskType::kInternalMediaRealTime));
}
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