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

Change CanvasCaptureHandler to operate over MediaStreamComponent

... instead of its Blink API wrapper WebMediaStreamTrack.

This is part of the effort to reduce the needless use of
public Blink APIs (wrappers) within renderer/modules.

BUG=704136
R=guidou@chromium.org

Change-Id: I402e0b38edc5d52bda41eac592b3fd9355db850f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2216046Reviewed-by: default avatarGuido Urdaneta <guidou@chromium.org>
Commit-Queue: Antonio Gomes <tonikitoo@igalia.com>
Cr-Commit-Position: refs/heads/master@{#772194}
parent 008bec4a
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "third_party/blink/renderer/modules/mediastream/media_stream_video_capturer_source.h" #include "third_party/blink/renderer/modules/mediastream/media_stream_video_capturer_source.h"
#include "third_party/blink/renderer/platform/graphics/static_bitmap_image.h" #include "third_party/blink/renderer/platform/graphics/static_bitmap_image.h"
#include "third_party/blink/renderer/platform/graphics/web_graphics_context_3d_provider_wrapper.h" #include "third_party/blink/renderer/platform/graphics/web_graphics_context_3d_provider_wrapper.h"
#include "third_party/blink/renderer/platform/mediastream/media_stream_component.h"
#include "third_party/blink/renderer/platform/mediastream/webrtc_uma_histograms.h" #include "third_party/blink/renderer/platform/mediastream/webrtc_uma_histograms.h"
#include "third_party/blink/renderer/platform/wtf/functional.h" #include "third_party/blink/renderer/platform/wtf/functional.h"
#include "third_party/blink/renderer/platform/wtf/text/base64.h" #include "third_party/blink/renderer/platform/wtf/text/base64.h"
...@@ -142,12 +143,12 @@ CanvasCaptureHandler::CanvasCaptureHandler( ...@@ -142,12 +143,12 @@ CanvasCaptureHandler::CanvasCaptureHandler(
const blink::WebSize& size, const blink::WebSize& size,
double frame_rate, double frame_rate,
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
blink::WebMediaStreamTrack* track) MediaStreamComponent** component)
: ask_for_new_frame_(false), io_task_runner_(std::move(io_task_runner)) { : ask_for_new_frame_(false), io_task_runner_(std::move(io_task_runner)) {
std::unique_ptr<media::VideoCapturerSource> video_source( std::unique_ptr<media::VideoCapturerSource> video_source(
new VideoCapturerSource(weak_ptr_factory_.GetWeakPtr(), size, new VideoCapturerSource(weak_ptr_factory_.GetWeakPtr(), size,
frame_rate)); frame_rate));
AddVideoCapturerSourceToVideoTrack(frame, std::move(video_source), track); AddVideoCapturerSourceToVideoTrack(frame, std::move(video_source), component);
} }
CanvasCaptureHandler::~CanvasCaptureHandler() { CanvasCaptureHandler::~CanvasCaptureHandler() {
...@@ -163,13 +164,13 @@ CanvasCaptureHandler::CreateCanvasCaptureHandler( ...@@ -163,13 +164,13 @@ CanvasCaptureHandler::CreateCanvasCaptureHandler(
const blink::WebSize& size, const blink::WebSize& size,
double frame_rate, double frame_rate,
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
blink::WebMediaStreamTrack* track) { MediaStreamComponent** component) {
// Save histogram data so we can see how much CanvasCapture is used. // Save histogram data so we can see how much CanvasCapture is used.
// The histogram counts the number of calls to the JS API. // The histogram counts the number of calls to the JS API.
UpdateWebRTCMethodCount(RTCAPIName::kCanvasCaptureStream); UpdateWebRTCMethodCount(RTCAPIName::kCanvasCaptureStream);
return std::unique_ptr<CanvasCaptureHandler>(new CanvasCaptureHandler( return std::unique_ptr<CanvasCaptureHandler>(new CanvasCaptureHandler(
frame, size, frame_rate, std::move(io_task_runner), track)); frame, size, frame_rate, std::move(io_task_runner), component));
} }
void CanvasCaptureHandler::SendNewFrame( void CanvasCaptureHandler::SendNewFrame(
...@@ -507,7 +508,7 @@ void CanvasCaptureHandler::SendFrame(scoped_refptr<VideoFrame> video_frame, ...@@ -507,7 +508,7 @@ void CanvasCaptureHandler::SendFrame(scoped_refptr<VideoFrame> video_frame,
void CanvasCaptureHandler::AddVideoCapturerSourceToVideoTrack( void CanvasCaptureHandler::AddVideoCapturerSourceToVideoTrack(
LocalFrame* frame, LocalFrame* frame,
std::unique_ptr<media::VideoCapturerSource> source, std::unique_ptr<media::VideoCapturerSource> source,
blink::WebMediaStreamTrack* web_track) { MediaStreamComponent** component) {
uint8_t track_id_bytes[64]; uint8_t track_id_bytes[64];
base::RandBytes(track_id_bytes, sizeof(track_id_bytes)); base::RandBytes(track_id_bytes, sizeof(track_id_bytes));
WebString track_id = Base64Encode(track_id_bytes); WebString track_id = Base64Encode(track_id_bytes);
...@@ -525,10 +526,11 @@ void CanvasCaptureHandler::AddVideoCapturerSourceToVideoTrack( ...@@ -525,10 +526,11 @@ void CanvasCaptureHandler::AddVideoCapturerSourceToVideoTrack(
media::VideoFacingMode::MEDIA_VIDEO_FACING_NONE, media::VideoFacingMode::MEDIA_VIDEO_FACING_NONE,
false /* is_device_capture */)); false /* is_device_capture */));
web_track->Initialize(webkit_source); *component = MakeGarbageCollected<MediaStreamComponent>(webkit_source);
web_track->SetPlatformTrack(std::make_unique<blink::MediaStreamVideoTrack>( (*component)
media_stream_source, ->SetPlatformTrack(std::make_unique<MediaStreamVideoTrack>(
blink::MediaStreamVideoSource::ConstraintsOnceCallback(), true)); media_stream_source,
MediaStreamVideoSource::ConstraintsOnceCallback(), true));
} }
void CanvasCaptureHandler::IncrementOngoingAsyncPixelReadouts() { void CanvasCaptureHandler::IncrementOngoingAsyncPixelReadouts() {
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
#include "gpu/GLES2/gl2extchromium.h" #include "gpu/GLES2/gl2extchromium.h"
#include "media/base/video_frame_pool.h" #include "media/base/video_frame_pool.h"
#include "media/capture/video_capturer_source.h" #include "media/capture/video_capturer_source.h"
#include "third_party/blink/public/platform/web_media_stream_track.h"
#include "third_party/blink/public/platform/web_size.h" #include "third_party/blink/public/platform/web_size.h"
#include "third_party/blink/renderer/modules/modules_export.h" #include "third_party/blink/renderer/modules/modules_export.h"
#include "third_party/skia/include/core/SkImageInfo.h" #include "third_party/skia/include/core/SkImageInfo.h"
...@@ -28,6 +27,7 @@ class SkImage; ...@@ -28,6 +27,7 @@ class SkImage;
namespace blink { namespace blink {
class LocalFrame; class LocalFrame;
class MediaStreamComponent;
class StaticBitmapImage; class StaticBitmapImage;
class WebGraphicsContext3DProvider; class WebGraphicsContext3DProvider;
class WebGraphicsContext3DProviderWrapper; class WebGraphicsContext3DProviderWrapper;
...@@ -51,7 +51,7 @@ class MODULES_EXPORT CanvasCaptureHandler { ...@@ -51,7 +51,7 @@ class MODULES_EXPORT CanvasCaptureHandler {
const blink::WebSize& size, const blink::WebSize& size,
double frame_rate, double frame_rate,
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
blink::WebMediaStreamTrack* track); MediaStreamComponent** component);
void SendNewFrame(scoped_refptr<StaticBitmapImage> image, void SendNewFrame(scoped_refptr<StaticBitmapImage> image,
base::WeakPtr<blink::WebGraphicsContext3DProviderWrapper> base::WeakPtr<blink::WebGraphicsContext3DProviderWrapper>
...@@ -77,7 +77,7 @@ class MODULES_EXPORT CanvasCaptureHandler { ...@@ -77,7 +77,7 @@ class MODULES_EXPORT CanvasCaptureHandler {
const blink::WebSize& size, const blink::WebSize& size,
double frame_rate, double frame_rate,
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
blink::WebMediaStreamTrack* track); MediaStreamComponent** component);
// Helper functions to read pixel content. // Helper functions to read pixel content.
void ReadARGBPixelsSync(scoped_refptr<StaticBitmapImage> image); void ReadARGBPixelsSync(scoped_refptr<StaticBitmapImage> image);
...@@ -112,7 +112,7 @@ class MODULES_EXPORT CanvasCaptureHandler { ...@@ -112,7 +112,7 @@ class MODULES_EXPORT CanvasCaptureHandler {
void AddVideoCapturerSourceToVideoTrack( void AddVideoCapturerSourceToVideoTrack(
LocalFrame* frame, LocalFrame* frame,
std::unique_ptr<media::VideoCapturerSource> source, std::unique_ptr<media::VideoCapturerSource> source,
blink::WebMediaStreamTrack* web_track); MediaStreamComponent** component);
// Helper methods to increment/decrement the number of ongoing async pixel // Helper methods to increment/decrement the number of ongoing async pixel
// readouts currently happening. // readouts currently happening.
......
...@@ -12,11 +12,12 @@ ...@@ -12,11 +12,12 @@
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/platform/scheduler/test/renderer_scheduler_test_support.h" #include "third_party/blink/public/platform/scheduler/test/renderer_scheduler_test_support.h"
#include "third_party/blink/public/platform/web_media_stream_source.h" #include "third_party/blink/public/platform/web_media_stream_source.h"
#include "third_party/blink/public/platform/web_media_stream_track.h"
#include "third_party/blink/public/platform/web_size.h" #include "third_party/blink/public/platform/web_size.h"
#include "third_party/blink/public/web/web_heap.h" #include "third_party/blink/public/web/web_heap.h"
#include "third_party/blink/renderer/modules/mediastream/media_stream_video_capturer_source.h" #include "third_party/blink/renderer/modules/mediastream/media_stream_video_capturer_source.h"
#include "third_party/blink/renderer/platform/graphics/unaccelerated_static_bitmap_image.h" #include "third_party/blink/renderer/platform/graphics/unaccelerated_static_bitmap_image.h"
#include "third_party/blink/renderer/platform/mediastream/media_stream_component.h"
#include "third_party/blink/renderer/platform/mediastream/media_stream_source.h"
#include "third_party/blink/renderer/platform/testing/io_task_runner_testing_platform_support.h" #include "third_party/blink/renderer/platform/testing/io_task_runner_testing_platform_support.h"
#include "third_party/skia/include/core/SkImage.h" #include "third_party/skia/include/core/SkImage.h"
#include "third_party/skia/include/core/SkRefCnt.h" #include "third_party/skia/include/core/SkRefCnt.h"
...@@ -50,15 +51,17 @@ class CanvasCaptureHandlerTest ...@@ -50,15 +51,17 @@ class CanvasCaptureHandlerTest
CanvasCaptureHandlerTest() = default; CanvasCaptureHandlerTest() = default;
void SetUp() override { void SetUp() override {
MediaStreamComponent* component = nullptr;
canvas_capture_handler_ = CanvasCaptureHandler::CreateCanvasCaptureHandler( canvas_capture_handler_ = CanvasCaptureHandler::CreateCanvasCaptureHandler(
/*LocalFrame =*/nullptr, /*LocalFrame =*/nullptr,
blink::WebSize(kTestCanvasCaptureWidth, kTestCanvasCaptureHeight), blink::WebSize(kTestCanvasCaptureWidth, kTestCanvasCaptureHeight),
kTestCanvasCaptureFramesPerSecond, kTestCanvasCaptureFramesPerSecond,
blink::scheduler::GetSingleThreadTaskRunnerForTesting(), &track_); blink::scheduler::GetSingleThreadTaskRunnerForTesting(), &component);
component_ = component;
} }
void TearDown() override { void TearDown() override {
track_.Reset(); component_ = nullptr;
blink::WebHeap::CollectAllGarbageForTesting(); blink::WebHeap::CollectAllGarbageForTesting();
canvas_capture_handler_.reset(); canvas_capture_handler_.reset();
...@@ -120,7 +123,7 @@ class CanvasCaptureHandlerTest ...@@ -120,7 +123,7 @@ class CanvasCaptureHandlerTest
} }
} }
blink::WebMediaStreamTrack track_; Persistent<MediaStreamComponent> component_;
// The Class under test. Needs to be scoped_ptr to force its destruction. // The Class under test. Needs to be scoped_ptr to force its destruction.
std::unique_ptr<CanvasCaptureHandler> canvas_capture_handler_; std::unique_ptr<CanvasCaptureHandler> canvas_capture_handler_;
...@@ -145,7 +148,7 @@ TEST_F(CanvasCaptureHandlerTest, ConstructAndDestruct) { ...@@ -145,7 +148,7 @@ TEST_F(CanvasCaptureHandlerTest, ConstructAndDestruct) {
// Checks that the destruction sequence works fine. // Checks that the destruction sequence works fine.
TEST_F(CanvasCaptureHandlerTest, DestructTrack) { TEST_F(CanvasCaptureHandlerTest, DestructTrack) {
EXPECT_TRUE(canvas_capture_handler_->NeedsNewFrame()); EXPECT_TRUE(canvas_capture_handler_->NeedsNewFrame());
track_.Reset(); component_ = nullptr;
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
} }
...@@ -159,7 +162,7 @@ TEST_F(CanvasCaptureHandlerTest, DestructHandler) { ...@@ -159,7 +162,7 @@ TEST_F(CanvasCaptureHandlerTest, DestructHandler) {
// Checks that VideoCapturerSource call sequence works fine. // Checks that VideoCapturerSource call sequence works fine.
TEST_P(CanvasCaptureHandlerTest, GetFormatsStartAndStop) { TEST_P(CanvasCaptureHandlerTest, GetFormatsStartAndStop) {
InSequence s; InSequence s;
const blink::WebMediaStreamSource& web_media_stream_source = track_.Source(); const WebMediaStreamSource& web_media_stream_source = component_->Source();
EXPECT_FALSE(web_media_stream_source.IsNull()); EXPECT_FALSE(web_media_stream_source.IsNull());
blink::MediaStreamVideoCapturerSource* const ms_source = blink::MediaStreamVideoCapturerSource* const ms_source =
static_cast<blink::MediaStreamVideoCapturerSource*>( static_cast<blink::MediaStreamVideoCapturerSource*>(
...@@ -205,7 +208,7 @@ TEST_P(CanvasCaptureHandlerTest, VerifyFrame) { ...@@ -205,7 +208,7 @@ TEST_P(CanvasCaptureHandlerTest, VerifyFrame) {
InSequence s; InSequence s;
media::VideoCapturerSource* const source = GetVideoCapturerSource( media::VideoCapturerSource* const source = GetVideoCapturerSource(
static_cast<blink::MediaStreamVideoCapturerSource*>( static_cast<blink::MediaStreamVideoCapturerSource*>(
track_.Source().GetPlatformSource())); component_->Source()->GetPlatformSource()));
EXPECT_TRUE(source); EXPECT_TRUE(source);
base::RunLoop run_loop; base::RunLoop run_loop;
...@@ -227,7 +230,7 @@ TEST_F(CanvasCaptureHandlerTest, CheckNeedsNewFrame) { ...@@ -227,7 +230,7 @@ TEST_F(CanvasCaptureHandlerTest, CheckNeedsNewFrame) {
InSequence s; InSequence s;
media::VideoCapturerSource* source = GetVideoCapturerSource( media::VideoCapturerSource* source = GetVideoCapturerSource(
static_cast<blink::MediaStreamVideoCapturerSource*>( static_cast<blink::MediaStreamVideoCapturerSource*>(
track_.Source().GetPlatformSource())); component_->Source()->GetPlatformSource()));
EXPECT_TRUE(source); EXPECT_TRUE(source);
EXPECT_TRUE(canvas_capture_handler_->NeedsNewFrame()); EXPECT_TRUE(canvas_capture_handler_->NeedsNewFrame());
source->StopCapture(); source->StopCapture();
......
...@@ -7,13 +7,13 @@ ...@@ -7,13 +7,13 @@
#include <memory> #include <memory>
#include "third_party/blink/public/platform/platform.h" #include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/public/platform/web_media_stream.h" #include "third_party/blink/public/platform/web_media_stream.h"
#include "third_party/blink/public/platform/web_media_stream_track.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h" #include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h"
#include "third_party/blink/renderer/core/frame/local_frame.h" #include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/html/canvas/html_canvas_element.h" #include "third_party/blink/renderer/core/html/canvas/html_canvas_element.h"
#include "third_party/blink/renderer/modules/mediacapturefromelement/canvas_capture_handler.h" #include "third_party/blink/renderer/modules/mediacapturefromelement/canvas_capture_handler.h"
#include "third_party/blink/renderer/modules/mediacapturefromelement/canvas_capture_media_stream_track.h" #include "third_party/blink/renderer/modules/mediacapturefromelement/canvas_capture_media_stream_track.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_component.h"
namespace { namespace {
const double kDefaultFrameRate = 60.0; const double kDefaultFrameRate = 60.0;
...@@ -56,17 +56,17 @@ MediaStream* HTMLCanvasElementCapture::captureStream( ...@@ -56,17 +56,17 @@ MediaStream* HTMLCanvasElementCapture::captureStream(
} }
LocalFrame* frame = ToLocalFrameIfNotDetached(script_state->GetContext()); LocalFrame* frame = ToLocalFrameIfNotDetached(script_state->GetContext());
WebMediaStreamTrack track; MediaStreamComponent* component = nullptr;
const WebSize size(element.width(), element.height()); const WebSize size(element.width(), element.height());
std::unique_ptr<CanvasCaptureHandler> handler; std::unique_ptr<CanvasCaptureHandler> handler;
if (given_frame_rate) { if (given_frame_rate) {
handler = CanvasCaptureHandler::CreateCanvasCaptureHandler( handler = CanvasCaptureHandler::CreateCanvasCaptureHandler(
frame, size, frame_rate, Platform::Current()->GetIOTaskRunner(), frame, size, frame_rate, Platform::Current()->GetIOTaskRunner(),
&track); &component);
} else { } else {
handler = CanvasCaptureHandler::CreateCanvasCaptureHandler( handler = CanvasCaptureHandler::CreateCanvasCaptureHandler(
frame, size, kDefaultFrameRate, Platform::Current()->GetIOTaskRunner(), frame, size, kDefaultFrameRate, Platform::Current()->GetIOTaskRunner(),
&track); &component);
} }
if (!handler) { if (!handler) {
...@@ -81,10 +81,10 @@ MediaStream* HTMLCanvasElementCapture::captureStream( ...@@ -81,10 +81,10 @@ MediaStream* HTMLCanvasElementCapture::captureStream(
CanvasCaptureMediaStreamTrack* canvas_track; CanvasCaptureMediaStreamTrack* canvas_track;
if (given_frame_rate) { if (given_frame_rate) {
canvas_track = MakeGarbageCollected<CanvasCaptureMediaStreamTrack>( canvas_track = MakeGarbageCollected<CanvasCaptureMediaStreamTrack>(
track, &element, context, std::move(handler), frame_rate); component, &element, context, std::move(handler), frame_rate);
} else { } else {
canvas_track = MakeGarbageCollected<CanvasCaptureMediaStreamTrack>( canvas_track = MakeGarbageCollected<CanvasCaptureMediaStreamTrack>(
track, &element, context, std::move(handler)); component, &element, context, std::move(handler));
} }
// We want to capture a frame in the beginning. // We want to capture a frame in the beginning.
canvas_track->requestFrame(); canvas_track->requestFrame();
......
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