Commit 1048384f authored by Guido Urdaneta's avatar Guido Urdaneta Committed by Commit Bot

[Onion Soup] Move MediaStreamVideoCapturerSource to Blink

The header for this class is temporarily in public since
it is still referenced in content. Final destination will be
blink/renderer/modules.

The move was not completely straightforward due to restrictions
placed on headers in public and usage of render frame IDs.

This CL contains blink style violations with regards to the use
of base::Bind variations and helpers. They will be converted
to WTF in follow-up CLs.

Bug: 921006
Change-Id: I75fa61a73acaebaddeed6df7018e7ba80b0f87e4
TBR: haraken@chromium.org
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1536176Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Guido Urdaneta <guidou@chromium.org>
Cr-Commit-Position: refs/heads/master@{#643792}
parent e4f9a01b
...@@ -273,8 +273,6 @@ target(link_target_type, "renderer") { ...@@ -273,8 +273,6 @@ target(link_target_type, "renderer") {
"media/stream/media_stream_dispatcher_eventhandler.h", "media/stream/media_stream_dispatcher_eventhandler.h",
"media/stream/media_stream_renderer_factory_impl.cc", "media/stream/media_stream_renderer_factory_impl.cc",
"media/stream/media_stream_renderer_factory_impl.h", "media/stream/media_stream_renderer_factory_impl.h",
"media/stream/media_stream_video_capturer_source.cc",
"media/stream/media_stream_video_capturer_source.h",
"media/stream/media_stream_video_renderer_sink.cc", "media/stream/media_stream_video_renderer_sink.cc",
"media/stream/media_stream_video_renderer_sink.h", "media/stream/media_stream_video_renderer_sink.h",
"media/stream/processed_local_audio_source.cc", "media/stream/processed_local_audio_source.cc",
......
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
#include "content/renderer/media/stream/media_stream_constraints_util_audio.h" #include "content/renderer/media/stream/media_stream_constraints_util_audio.h"
#include "content/renderer/media/stream/media_stream_constraints_util_video_content.h" #include "content/renderer/media/stream/media_stream_constraints_util_video_content.h"
#include "content/renderer/media/stream/media_stream_device_observer.h" #include "content/renderer/media/stream/media_stream_device_observer.h"
#include "content/renderer/media/stream/media_stream_video_capturer_source.h"
#include "content/renderer/media/stream/processed_local_audio_source.h" #include "content/renderer/media/stream/processed_local_audio_source.h"
#include "content/renderer/media/stream/user_media_client_impl.h" #include "content/renderer/media/stream/user_media_client_impl.h"
#include "content/renderer/media/webrtc/peer_connection_dependency_factory.h" #include "content/renderer/media/webrtc/peer_connection_dependency_factory.h"
...@@ -46,6 +45,7 @@ ...@@ -46,6 +45,7 @@
#include "third_party/blink/public/platform/web_string.h" #include "third_party/blink/public/platform/web_string.h"
#include "third_party/blink/public/web/modules/mediastream/media_stream_constraints_util.h" #include "third_party/blink/public/web/modules/mediastream/media_stream_constraints_util.h"
#include "third_party/blink/public/web/modules/mediastream/media_stream_constraints_util_video_device.h" #include "third_party/blink/public/web/modules/mediastream/media_stream_constraints_util_video_device.h"
#include "third_party/blink/public/web/modules/mediastream/media_stream_video_capturer_source.h"
#include "third_party/blink/public/web/modules/mediastream/media_stream_video_track.h" #include "third_party/blink/public/web/modules/mediastream/media_stream_video_track.h"
#include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size.h"
#include "url/origin.h" #include "url/origin.h"
...@@ -1068,8 +1068,8 @@ UserMediaProcessor::CreateVideoSource( ...@@ -1068,8 +1068,8 @@ UserMediaProcessor::CreateVideoSource(
DCHECK(current_request_info_); DCHECK(current_request_info_);
DCHECK(current_request_info_->video_capture_settings().HasValue()); DCHECK(current_request_info_->video_capture_settings().HasValue());
return std::make_unique<MediaStreamVideoCapturerSource>( return std::make_unique<blink::MediaStreamVideoCapturerSource>(
render_frame_->GetRoutingID(), stop_callback, device, render_frame_->GetWebFrame(), stop_callback, device,
current_request_info_->video_capture_settings().capture_params(), current_request_info_->video_capture_settings().capture_params(),
base::BindRepeating( base::BindRepeating(
&LocalVideoCapturerSource::Create, &LocalVideoCapturerSource::Create,
......
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "components/viz/common/gl_helper.h" #include "components/viz/common/gl_helper.h"
#include "content/public/renderer/render_thread.h" #include "content/public/renderer/render_thread.h"
#include "content/renderer/media/stream/media_stream_video_capturer_source.h"
#include "content/renderer/render_thread_impl.h" #include "content/renderer/render_thread_impl.h"
#include "media/base/limits.h" #include "media/base/limits.h"
#include "third_party/blink/public/platform/modules/mediastream/webrtc_uma_histograms.h" #include "third_party/blink/public/platform/modules/mediastream/webrtc_uma_histograms.h"
...@@ -22,6 +21,7 @@ ...@@ -22,6 +21,7 @@
#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_string.h" #include "third_party/blink/public/platform/web_string.h"
#include "third_party/blink/public/web/modules/mediastream/media_stream_constraints_util.h" #include "third_party/blink/public/web/modules/mediastream/media_stream_constraints_util.h"
#include "third_party/blink/public/web/modules/mediastream/media_stream_video_capturer_source.h"
#include "third_party/blink/public/web/modules/mediastream/media_stream_video_source.h" #include "third_party/blink/public/web/modules/mediastream/media_stream_video_source.h"
#include "third_party/blink/public/web/modules/mediastream/media_stream_video_track.h" #include "third_party/blink/public/web/modules/mediastream/media_stream_video_track.h"
#include "third_party/libyuv/include/libyuv.h" #include "third_party/libyuv/include/libyuv.h"
...@@ -486,7 +486,7 @@ void CanvasCaptureHandler::AddVideoCapturerSourceToVideoTrack( ...@@ -486,7 +486,7 @@ void CanvasCaptureHandler::AddVideoCapturerSourceToVideoTrack(
const blink::WebString track_id = blink::WebString::FromASCII(str_track_id); const blink::WebString track_id = blink::WebString::FromASCII(str_track_id);
media::VideoCaptureFormats preferred_formats = source->GetPreferredFormats(); media::VideoCaptureFormats preferred_formats = source->GetPreferredFormats();
blink::MediaStreamVideoSource* media_stream_source = blink::MediaStreamVideoSource* media_stream_source =
new MediaStreamVideoCapturerSource( new blink::MediaStreamVideoCapturerSource(
blink::WebPlatformMediaStreamSource::SourceStoppedCallback(), blink::WebPlatformMediaStreamSource::SourceStoppedCallback(),
std::move(source)); std::move(source));
blink::WebMediaStreamSource webkit_source; blink::WebMediaStreamSource webkit_source;
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#include "base/test/scoped_task_environment.h" #include "base/test/scoped_task_environment.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "content/child/child_process.h" #include "content/child/child_process.h"
#include "content/renderer/media/stream/media_stream_video_capturer_source.h"
#include "media/base/limits.h" #include "media/base/limits.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -17,6 +16,7 @@ ...@@ -17,6 +16,7 @@
#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_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/modules/mediastream/media_stream_video_capturer_source.h"
#include "third_party/blink/public/web/web_heap.h" #include "third_party/blink/public/web/web_heap.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"
...@@ -128,8 +128,8 @@ class CanvasCaptureHandlerTest ...@@ -128,8 +128,8 @@ class CanvasCaptureHandlerTest
protected: protected:
media::VideoCapturerSource* GetVideoCapturerSource( media::VideoCapturerSource* GetVideoCapturerSource(
MediaStreamVideoCapturerSource* ms_source) { blink::MediaStreamVideoCapturerSource* ms_source) {
return ms_source->source_.get(); return ms_source->GetSourceForTesting();
} }
// A ChildProcess is needed to fool the Tracks and Sources believing they are // A ChildProcess is needed to fool the Tracks and Sources believing they are
...@@ -167,8 +167,8 @@ TEST_P(CanvasCaptureHandlerTest, GetFormatsStartAndStop) { ...@@ -167,8 +167,8 @@ TEST_P(CanvasCaptureHandlerTest, GetFormatsStartAndStop) {
InSequence s; InSequence s;
const blink::WebMediaStreamSource& web_media_stream_source = track_.Source(); const blink::WebMediaStreamSource& web_media_stream_source = track_.Source();
EXPECT_FALSE(web_media_stream_source.IsNull()); EXPECT_FALSE(web_media_stream_source.IsNull());
MediaStreamVideoCapturerSource* const ms_source = blink::MediaStreamVideoCapturerSource* const ms_source =
static_cast<MediaStreamVideoCapturerSource*>( static_cast<blink::MediaStreamVideoCapturerSource*>(
web_media_stream_source.GetPlatformSource()); web_media_stream_source.GetPlatformSource());
EXPECT_TRUE(ms_source != nullptr); EXPECT_TRUE(ms_source != nullptr);
media::VideoCapturerSource* source = GetVideoCapturerSource(ms_source); media::VideoCapturerSource* source = GetVideoCapturerSource(ms_source);
...@@ -207,8 +207,8 @@ TEST_P(CanvasCaptureHandlerTest, VerifyFrame) { ...@@ -207,8 +207,8 @@ TEST_P(CanvasCaptureHandlerTest, VerifyFrame) {
const bool width = testing::get<1>(GetParam()); const bool width = testing::get<1>(GetParam());
const bool height = testing::get<1>(GetParam()); const bool height = testing::get<1>(GetParam());
InSequence s; InSequence s;
media::VideoCapturerSource* const source = media::VideoCapturerSource* const source = GetVideoCapturerSource(
GetVideoCapturerSource(static_cast<MediaStreamVideoCapturerSource*>( static_cast<blink::MediaStreamVideoCapturerSource*>(
track_.Source().GetPlatformSource())); track_.Source().GetPlatformSource()));
EXPECT_TRUE(source != nullptr); EXPECT_TRUE(source != nullptr);
...@@ -228,8 +228,8 @@ TEST_P(CanvasCaptureHandlerTest, VerifyFrame) { ...@@ -228,8 +228,8 @@ TEST_P(CanvasCaptureHandlerTest, VerifyFrame) {
// Checks that needsNewFrame() works as expected. // Checks that needsNewFrame() works as expected.
TEST_F(CanvasCaptureHandlerTest, CheckNeedsNewFrame) { TEST_F(CanvasCaptureHandlerTest, CheckNeedsNewFrame) {
InSequence s; InSequence s;
media::VideoCapturerSource* source = media::VideoCapturerSource* source = GetVideoCapturerSource(
GetVideoCapturerSource(static_cast<MediaStreamVideoCapturerSource*>( static_cast<blink::MediaStreamVideoCapturerSource*>(
track_.Source().GetPlatformSource())); track_.Source().GetPlatformSource()));
EXPECT_TRUE(source != nullptr); EXPECT_TRUE(source != nullptr);
EXPECT_TRUE(canvas_capture_handler_->NeedsNewFrame()); EXPECT_TRUE(canvas_capture_handler_->NeedsNewFrame());
......
...@@ -9,11 +9,11 @@ ...@@ -9,11 +9,11 @@
#include "base/callback.h" #include "base/callback.h"
#include "base/guid.h" #include "base/guid.h"
#include "content/renderer/media/stream/media_stream_video_capturer_source.h"
#include "media/capture/video_capturer_source.h" #include "media/capture/video_capturer_source.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_source.h" #include "third_party/blink/public/platform/web_media_stream_source.h"
#include "third_party/blink/public/web/modules/mediastream/media_stream_constraints_util.h" #include "third_party/blink/public/web/modules/mediastream/media_stream_constraints_util.h"
#include "third_party/blink/public/web/modules/mediastream/media_stream_video_capturer_source.h"
#include "third_party/blink/public/web/modules/mediastream/media_stream_video_source.h" #include "third_party/blink/public/web/modules/mediastream/media_stream_video_source.h"
#include "third_party/blink/public/web/modules/mediastream/media_stream_video_track.h" #include "third_party/blink/public/web/modules/mediastream/media_stream_video_track.h"
...@@ -32,7 +32,7 @@ bool AddVideoTrackToMediaStream( ...@@ -32,7 +32,7 @@ bool AddVideoTrackToMediaStream(
media::VideoCaptureFormats preferred_formats = media::VideoCaptureFormats preferred_formats =
video_source->GetPreferredFormats(); video_source->GetPreferredFormats();
blink::MediaStreamVideoSource* const media_stream_source = blink::MediaStreamVideoSource* const media_stream_source =
new MediaStreamVideoCapturerSource( new blink::MediaStreamVideoCapturerSource(
blink::WebPlatformMediaStreamSource::SourceStoppedCallback(), blink::WebPlatformMediaStreamSource::SourceStoppedCallback(),
std::move(video_source)); std::move(video_source));
const blink::WebString track_id = const blink::WebString track_id =
......
...@@ -1804,7 +1804,6 @@ test("content_unittests") { ...@@ -1804,7 +1804,6 @@ test("content_unittests") {
"../renderer/media/stream/media_stream_constraints_util_video_content_unittest.cc", "../renderer/media/stream/media_stream_constraints_util_video_content_unittest.cc",
"../renderer/media/stream/media_stream_constraints_util_video_device_unittest.cc", "../renderer/media/stream/media_stream_constraints_util_video_device_unittest.cc",
"../renderer/media/stream/media_stream_device_observer_unittest.cc", "../renderer/media/stream/media_stream_device_observer_unittest.cc",
"../renderer/media/stream/media_stream_video_capturer_source_unittest.cc",
"../renderer/media/stream/media_stream_video_renderer_sink_unittest.cc", "../renderer/media/stream/media_stream_video_renderer_sink_unittest.cc",
"../renderer/media/stream/media_stream_video_source_unittest.cc", "../renderer/media/stream/media_stream_video_source_unittest.cc",
"../renderer/media/stream/media_stream_video_track_unittest.cc", "../renderer/media/stream/media_stream_video_track_unittest.cc",
......
...@@ -390,6 +390,7 @@ source_set("blink_headers") { ...@@ -390,6 +390,7 @@ source_set("blink_headers") {
"web/modules/mediastream/media_stream_constraints_util.h", "web/modules/mediastream/media_stream_constraints_util.h",
"web/modules/mediastream/media_stream_constraints_util_sets.h", "web/modules/mediastream/media_stream_constraints_util_sets.h",
"web/modules/mediastream/media_stream_constraints_util_video_device.h", "web/modules/mediastream/media_stream_constraints_util_video_device.h",
"web/modules/mediastream/media_stream_video_capturer_source.h",
"web/modules/mediastream/media_stream_video_sink.h", "web/modules/mediastream/media_stream_video_sink.h",
"web/modules/mediastream/media_stream_video_source.h", "web/modules/mediastream/media_stream_video_source.h",
"web/modules/mediastream/media_stream_video_track.h", "web/modules/mediastream/media_stream_video_track.h",
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// 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_STREAM_MEDIA_STREAM_VIDEO_CAPTURER_SOURCE_H_ #ifndef THIRD_PARTY_BLINK_PUBLIC_WEB_MODULES_MEDIASTREAM_MEDIA_STREAM_VIDEO_CAPTURER_SOURCE_H_
#define CONTENT_RENDERER_MEDIA_STREAM_MEDIA_STREAM_VIDEO_CAPTURER_SOURCE_H_ #define THIRD_PARTY_BLINK_PUBLIC_WEB_MODULES_MEDIASTREAM_MEDIA_STREAM_VIDEO_CAPTURER_SOURCE_H_
#include <memory> #include <memory>
#include <string> #include <string>
...@@ -12,26 +12,25 @@ ...@@ -12,26 +12,25 @@
#include "base/macros.h" #include "base/macros.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 "media/capture/video_capture_types.h" #include "media/capture/video_capture_types.h"
#include "third_party/blink/public/common/media/video_capture.h" #include "third_party/blink/public/common/media/video_capture.h"
#include "third_party/blink/public/mojom/mediastream/media_stream.mojom.h" #include "third_party/blink/public/platform/web_common.h"
#include "third_party/blink/public/web/modules/mediastream/media_stream_video_source.h" #include "third_party/blink/public/web/modules/mediastream/media_stream_video_source.h"
namespace media { namespace media {
class VideoCapturerSource; class VideoCapturerSource;
} // namespace media } // namespace media
namespace content { namespace blink {
class RenderFrame; class WebLocalFrame;
// Representation of a video stream coming from a camera, owned by Blink as // Representation of a video stream coming from a camera, owned by Blink as
// WebMediaStreamSource. Objects of this class are created and live on main // WebMediaStreamSource. Objects of this class are created and live on main
// Render thread. Objects can be constructed either by indicating a |device| to // Render thread. Objects can be constructed either by indicating a |device| to
// look for, or by plugging in a |source| constructed elsewhere. // look for, or by plugging in a |source| constructed elsewhere.
class CONTENT_EXPORT MediaStreamVideoCapturerSource class BLINK_EXPORT MediaStreamVideoCapturerSource
: public blink::MediaStreamVideoSource { : public MediaStreamVideoSource {
public: public:
using DeviceCapturerFactoryCallback = using DeviceCapturerFactoryCallback =
base::RepeatingCallback<std::unique_ptr<media::VideoCapturerSource>( base::RepeatingCallback<std::unique_ptr<media::VideoCapturerSource>(
...@@ -40,9 +39,9 @@ class CONTENT_EXPORT MediaStreamVideoCapturerSource ...@@ -40,9 +39,9 @@ class CONTENT_EXPORT MediaStreamVideoCapturerSource
const SourceStoppedCallback& stop_callback, const SourceStoppedCallback& stop_callback,
std::unique_ptr<media::VideoCapturerSource> source); std::unique_ptr<media::VideoCapturerSource> source);
MediaStreamVideoCapturerSource( MediaStreamVideoCapturerSource(
int render_frame_id, WebLocalFrame* web_frame,
const SourceStoppedCallback& stop_callback, const SourceStoppedCallback& stop_callback,
const blink::MediaStreamDevice& device, const MediaStreamDevice& device,
const media::VideoCaptureParams& capture_params, const media::VideoCaptureParams& capture_params,
DeviceCapturerFactoryCallback device_capturer_factory_callback); DeviceCapturerFactoryCallback device_capturer_factory_callback);
~MediaStreamVideoCapturerSource() override; ~MediaStreamVideoCapturerSource() override;
...@@ -50,41 +49,43 @@ class CONTENT_EXPORT MediaStreamVideoCapturerSource ...@@ -50,41 +49,43 @@ class CONTENT_EXPORT MediaStreamVideoCapturerSource
void SetDeviceCapturerFactoryCallbackForTesting( void SetDeviceCapturerFactoryCallbackForTesting(
DeviceCapturerFactoryCallback testing_factory_callback); DeviceCapturerFactoryCallback testing_factory_callback);
// TODO(crbug.com/704136) Use a mojom::blink::MediaStreamDispatcherHostPtr
// once this header file moves to blink/renderer.
void SetMediaStreamDispatcherHostForTesting(void* dispatcher_host);
media::VideoCapturerSource* GetSourceForTesting();
private: private:
friend class CanvasCaptureHandlerTest;
friend class MediaStreamVideoCapturerSourceTest; friend class MediaStreamVideoCapturerSourceTest;
friend class MediaStreamVideoCapturerSourceOldConstraintsTest;
FRIEND_TEST_ALL_PREFIXES(MediaStreamVideoCapturerSourceTest, StartAndStop); FRIEND_TEST_ALL_PREFIXES(MediaStreamVideoCapturerSourceTest, StartAndStop);
FRIEND_TEST_ALL_PREFIXES(MediaStreamVideoCapturerSourceTest, FRIEND_TEST_ALL_PREFIXES(MediaStreamVideoCapturerSourceTest,
CaptureTimeAndMetadataPlumbing); CaptureTimeAndMetadataPlumbing);
FRIEND_TEST_ALL_PREFIXES(MediaStreamVideoCapturerSourceTest, ChangeSource); FRIEND_TEST_ALL_PREFIXES(MediaStreamVideoCapturerSourceTest, ChangeSource);
// blink::MediaStreamVideoSource overrides. // MediaStreamVideoSource overrides.
void RequestRefreshFrame() override; void RequestRefreshFrame() override;
void OnFrameDropped(media::VideoCaptureFrameDropReason reason) override; void OnFrameDropped(media::VideoCaptureFrameDropReason reason) override;
void OnLog(const std::string& message) override; void OnLog(const std::string& message) override;
void OnHasConsumers(bool has_consumers) override; void OnHasConsumers(bool has_consumers) override;
void OnCapturingLinkSecured(bool is_secure) override; void OnCapturingLinkSecured(bool is_secure) override;
void StartSourceImpl( void StartSourceImpl(
const blink::VideoCaptureDeliverFrameCB& frame_callback) override; const VideoCaptureDeliverFrameCB& frame_callback) override;
void StopSourceImpl() override; void StopSourceImpl() override;
void StopSourceForRestartImpl() override; void StopSourceForRestartImpl() override;
void RestartSourceImpl(const media::VideoCaptureFormat& new_format) override; void RestartSourceImpl(const media::VideoCaptureFormat& new_format) override;
base::Optional<media::VideoCaptureFormat> GetCurrentFormat() const override; base::Optional<media::VideoCaptureFormat> GetCurrentFormat() const override;
base::Optional<media::VideoCaptureParams> GetCurrentCaptureParams() base::Optional<media::VideoCaptureParams> GetCurrentCaptureParams()
const override; const override;
void ChangeSourceImpl(const blink::MediaStreamDevice& new_device) override; void ChangeSourceImpl(const MediaStreamDevice& new_device) override;
// Method to bind as RunningCallback in VideoCapturerSource::StartCapture(). // Method to bind as RunningCallback in VideoCapturerSource::StartCapture().
void OnRunStateChanged(const media::VideoCaptureParams& new_capture_params, void OnRunStateChanged(const media::VideoCaptureParams& new_capture_params,
bool is_running); bool is_running);
const blink::mojom::MediaStreamDispatcherHostPtr& // TODO(crbug.com/704136): Replace |internal_state_| with regular fields once
GetMediaStreamDispatcherHost(RenderFrame* render_frame); // this header file moves to blink/renderer.
class InternalState;
blink::mojom::MediaStreamDispatcherHostPtr dispatcher_host_; std::unique_ptr<InternalState> internal_state_;
int render_frame_id_;
// The source that provides video frames. // The source that provides video frames.
std::unique_ptr<media::VideoCapturerSource> source_; std::unique_ptr<media::VideoCapturerSource> source_;
...@@ -100,12 +101,12 @@ class CONTENT_EXPORT MediaStreamVideoCapturerSource ...@@ -100,12 +101,12 @@ class CONTENT_EXPORT MediaStreamVideoCapturerSource
State state_ = STOPPED; State state_ = STOPPED;
media::VideoCaptureParams capture_params_; media::VideoCaptureParams capture_params_;
blink::VideoCaptureDeliverFrameCB frame_callback_; VideoCaptureDeliverFrameCB frame_callback_;
DeviceCapturerFactoryCallback device_capturer_factory_callback_; DeviceCapturerFactoryCallback device_capturer_factory_callback_;
DISALLOW_COPY_AND_ASSIGN(MediaStreamVideoCapturerSource); DISALLOW_COPY_AND_ASSIGN(MediaStreamVideoCapturerSource);
}; };
} // namespace content } // namespace blink
#endif // CONTENT_RENDERER_MEDIA_STREAM_MEDIA_STREAM_VIDEO_CAPTURER_SOURCE_H_ #endif // THIRD_PARTY_BLINK_PUBLIC_WEB_MODULES_MEDIASTREAM_MEDIA_STREAM_VIDEO_CAPTURER_SOURCE_H_
...@@ -301,6 +301,9 @@ jumbo_source_set("unit_tests") { ...@@ -301,6 +301,9 @@ jumbo_source_set("unit_tests") {
"media_controls/non_touch/media_controls_non_touch_impl_test.cc", "media_controls/non_touch/media_controls_non_touch_impl_test.cc",
"mediastream/media_constraints_test.cc", "mediastream/media_constraints_test.cc",
"mediastream/media_devices_test.cc", "mediastream/media_devices_test.cc",
"mediastream/media_stream_video_capturer_source_test.cc",
"mediastream/mock_mojo_media_stream_dispatcher_host.cc",
"mediastream/mock_mojo_media_stream_dispatcher_host.h",
"notifications/notification_data_test.cc", "notifications/notification_data_test.cc",
"notifications/notification_image_loader_test.cc", "notifications/notification_image_loader_test.cc",
"notifications/notification_resources_loader_test.cc", "notifications/notification_resources_loader_test.cc",
......
...@@ -31,6 +31,7 @@ blink_modules_sources("mediastream") { ...@@ -31,6 +31,7 @@ blink_modules_sources("mediastream") {
"media_stream_track_content_hint.h", "media_stream_track_content_hint.h",
"media_stream_track_event.cc", "media_stream_track_event.cc",
"media_stream_track_event.h", "media_stream_track_event.h",
"media_stream_video_capturer_source.cc",
"media_stream_video_sink.cc", "media_stream_video_sink.cc",
"media_stream_video_source.cc", "media_stream_video_source.cc",
"media_stream_video_track.cc", "media_stream_video_track.cc",
......
...@@ -4,9 +4,13 @@ include_rules = [ ...@@ -4,9 +4,13 @@ include_rules = [
"+base/strings/utf_string_conversions.h", "+base/strings/utf_string_conversions.h",
"+base/strings/string_number_conversions.h", "+base/strings/string_number_conversions.h",
"+base/containers/flat_map.h", "+base/containers/flat_map.h",
"+base/callback_helpers.h",
# TODO(crbug.com/923394): Remove these dependencies once per-frame
# task runners are used in all cases.
"+base/threading/sequenced_task_runner_handle.h", "+base/threading/sequenced_task_runner_handle.h",
"+base/threading/thread_task_runner_handle.h", "+base/threading/thread_task_runner_handle.h",
"+base/trace_event/trace_event.h", "+base/trace_event/trace_event.h",
"+media/base", "+media/base",
"+media/capture", "+media/capture",
...@@ -19,3 +23,9 @@ include_rules = [ ...@@ -19,3 +23,9 @@ include_rules = [
"+third_party/blink/renderer/modules/mediastream", "+third_party/blink/renderer/modules/mediastream",
"+third_party/blink/renderer/modules/modules_export.h", "+third_party/blink/renderer/modules/modules_export.h",
] ]
specific_include_rules = {
"media_stream_video_capturer_source_test\.cc" : [
"+base/run_loop.h",
],
}
...@@ -2,28 +2,54 @@ ...@@ -2,28 +2,54 @@
// 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/stream/media_stream_video_capturer_source.h" #include "third_party/blink/public/web/modules/mediastream/media_stream_video_capturer_source.h"
#include <utility> #include <utility>
#include "base/bind.h" #include "base/bind.h"
#include "content/public/renderer/render_frame.h"
#include "media/capture/video_capturer_source.h" #include "media/capture/video_capturer_source.h"
#include "services/service_manager/public/cpp/interface_provider.h" #include "services/service_manager/public/cpp/interface_provider.h"
#include "third_party/blink/public/mojom/mediastream/media_stream.mojom-blink.h"
#include "third_party/blink/public/web/modules/mediastream/media_stream_constraints_util.h" #include "third_party/blink/public/web/modules/mediastream/media_stream_constraints_util.h"
#include "third_party/blink/public/web/web_local_frame.h" #include "third_party/blink/public/web/web_local_frame.h"
#include "third_party/blink/public/web/web_local_frame_client.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
namespace blink {
class MediaStreamVideoCapturerSource::InternalState {
public:
InternalState(WebLocalFrame* web_frame)
: frame_(web_frame ? static_cast<LocalFrame*>(
WebLocalFrame::ToCoreFrame(*web_frame))
: nullptr) {}
LocalFrame* frame() { return frame_.Get(); }
const mojom::blink::MediaStreamDispatcherHostPtr&
GetMediaStreamDispatcherHost() {
DCHECK(frame_);
if (!host_)
frame_->GetInterfaceProvider().GetInterface(mojo::MakeRequest(&host_));
return host_;
}
void SetMediaStreamDispatcherHostForTesting(
mojom::blink::MediaStreamDispatcherHostPtr host) {
host_ = std::move(host);
}
namespace content { private:
WeakPersistent<LocalFrame> frame_;
mojom::blink::MediaStreamDispatcherHostPtr host_;
};
MediaStreamVideoCapturerSource::MediaStreamVideoCapturerSource( MediaStreamVideoCapturerSource::MediaStreamVideoCapturerSource(
const SourceStoppedCallback& stop_callback, const SourceStoppedCallback& stop_callback,
std::unique_ptr<media::VideoCapturerSource> source) std::unique_ptr<media::VideoCapturerSource> source)
: source_(std::move(source)) { : internal_state_(std::make_unique<InternalState>(
blink::WebLocalFrame* web_frame = blink::WebLocalFrame::FrameForCurrentContext())),
blink::WebLocalFrame::FrameForCurrentContext(); source_(std::move(source)) {
RenderFrame* render_frame = RenderFrame::FromWebFrame(web_frame);
render_frame_id_ =
render_frame ? render_frame->GetRoutingID() : MSG_ROUTING_NONE;
media::VideoCaptureFormats preferred_formats = source_->GetPreferredFormats(); media::VideoCaptureFormats preferred_formats = source_->GetPreferredFormats();
if (!preferred_formats.empty()) if (!preferred_formats.empty())
capture_params_.requested_format = preferred_formats.front(); capture_params_.requested_format = preferred_formats.front();
...@@ -31,12 +57,12 @@ MediaStreamVideoCapturerSource::MediaStreamVideoCapturerSource( ...@@ -31,12 +57,12 @@ MediaStreamVideoCapturerSource::MediaStreamVideoCapturerSource(
} }
MediaStreamVideoCapturerSource::MediaStreamVideoCapturerSource( MediaStreamVideoCapturerSource::MediaStreamVideoCapturerSource(
int render_frame_id, WebLocalFrame* web_frame,
const SourceStoppedCallback& stop_callback, const SourceStoppedCallback& stop_callback,
const blink::MediaStreamDevice& device, const MediaStreamDevice& device,
const media::VideoCaptureParams& capture_params, const media::VideoCaptureParams& capture_params,
DeviceCapturerFactoryCallback device_capturer_factory_callback) DeviceCapturerFactoryCallback device_capturer_factory_callback)
: render_frame_id_(render_frame_id), : internal_state_(std::make_unique<InternalState>(web_frame)),
source_(device_capturer_factory_callback.Run(device.session_id)), source_(device_capturer_factory_callback.Run(device.session_id)),
capture_params_(capture_params), capture_params_(capture_params),
device_capturer_factory_callback_( device_capturer_factory_callback_(
...@@ -81,15 +107,15 @@ void MediaStreamVideoCapturerSource::OnHasConsumers(bool has_consumers) { ...@@ -81,15 +107,15 @@ void MediaStreamVideoCapturerSource::OnHasConsumers(bool has_consumers) {
void MediaStreamVideoCapturerSource::OnCapturingLinkSecured(bool is_secure) { void MediaStreamVideoCapturerSource::OnCapturingLinkSecured(bool is_secure) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
RenderFrame* render_frame = RenderFrame::FromRoutingID(render_frame_id_); if (!internal_state_->frame())
if (!render_frame)
return; return;
GetMediaStreamDispatcherHost(render_frame) internal_state_->GetMediaStreamDispatcherHost()->SetCapturingLinkSecured(
->SetCapturingLinkSecured(device().session_id, device().type, is_secure); device().session_id, static_cast<mojom::MediaStreamType>(device().type),
is_secure);
} }
void MediaStreamVideoCapturerSource::StartSourceImpl( void MediaStreamVideoCapturerSource::StartSourceImpl(
const blink::VideoCaptureDeliverFrameCB& frame_callback) { const VideoCaptureDeliverFrameCB& frame_callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
state_ = STARTING; state_ = STARTING;
frame_callback_ = frame_callback; frame_callback_ = frame_callback;
...@@ -115,7 +141,7 @@ void MediaStreamVideoCapturerSource::StopSourceForRestartImpl() { ...@@ -115,7 +141,7 @@ void MediaStreamVideoCapturerSource::StopSourceForRestartImpl() {
// Force state update for nondevice sources, since they do not // Force state update for nondevice sources, since they do not
// automatically update state after StopCapture(). // automatically update state after StopCapture().
if (device().type == blink::MEDIA_NO_SERVICE) if (device().type == MEDIA_NO_SERVICE)
OnRunStateChanged(capture_params_, false); OnRunStateChanged(capture_params_, false);
} }
...@@ -144,7 +170,7 @@ MediaStreamVideoCapturerSource::GetCurrentCaptureParams() const { ...@@ -144,7 +170,7 @@ MediaStreamVideoCapturerSource::GetCurrentCaptureParams() const {
} }
void MediaStreamVideoCapturerSource::ChangeSourceImpl( void MediaStreamVideoCapturerSource::ChangeSourceImpl(
const blink::MediaStreamDevice& new_device) { const MediaStreamDevice& new_device) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(device_capturer_factory_callback_); DCHECK(device_capturer_factory_callback_);
...@@ -172,10 +198,10 @@ void MediaStreamVideoCapturerSource::OnRunStateChanged( ...@@ -172,10 +198,10 @@ void MediaStreamVideoCapturerSource::OnRunStateChanged(
if (is_running) { if (is_running) {
state_ = STARTED; state_ = STARTED;
DCHECK(capture_params_ == new_capture_params); DCHECK(capture_params_ == new_capture_params);
OnStartDone(blink::MEDIA_DEVICE_OK); OnStartDone(MEDIA_DEVICE_OK);
} else { } else {
state_ = STOPPED; state_ = STOPPED;
OnStartDone(blink::MEDIA_DEVICE_TRACK_START_FAILURE_VIDEO); OnStartDone(MEDIA_DEVICE_TRACK_START_FAILURE_VIDEO);
} }
break; break;
case STARTED: case STARTED:
...@@ -208,15 +234,16 @@ void MediaStreamVideoCapturerSource::OnRunStateChanged( ...@@ -208,15 +234,16 @@ void MediaStreamVideoCapturerSource::OnRunStateChanged(
} }
} }
const blink::mojom::MediaStreamDispatcherHostPtr& void MediaStreamVideoCapturerSource::SetMediaStreamDispatcherHostForTesting(
MediaStreamVideoCapturerSource::GetMediaStreamDispatcherHost( void* dispatcher_host) {
RenderFrame* render_frame) { mojom::blink::MediaStreamDispatcherHostPtr* host =
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); static_cast<mojom::blink::MediaStreamDispatcherHostPtr*>(dispatcher_host);
if (!dispatcher_host_) { internal_state_->SetMediaStreamDispatcherHostForTesting(std::move(*host));
render_frame->GetRemoteInterfaces()->GetInterface( }
mojo::MakeRequest(&dispatcher_host_));
} media::VideoCapturerSource*
return dispatcher_host_; MediaStreamVideoCapturerSource::GetSourceForTesting() {
return source_.get();
} }
} // namespace content } // namespace blink
// Copyright (c) 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 "third_party/blink/renderer/modules/mediastream/mock_mojo_media_stream_dispatcher_host.h"
#include <utility>
#include "base/strings/string_number_conversions.h"
namespace blink {
MockMojoMediaStreamDispatcherHost::MockMojoMediaStreamDispatcherHost()
: binding_(this) {}
MockMojoMediaStreamDispatcherHost::~MockMojoMediaStreamDispatcherHost() {}
mojom::blink::MediaStreamDispatcherHostPtr
MockMojoMediaStreamDispatcherHost::CreateInterfacePtrAndBind() {
mojom::blink::MediaStreamDispatcherHostPtr dispatcher_host;
binding_.Bind(mojo::MakeRequest(&dispatcher_host));
return dispatcher_host;
}
void MockMojoMediaStreamDispatcherHost::GenerateStream(
int32_t request_id,
mojom::blink::StreamControlsPtr controls,
bool user_gesture,
GenerateStreamCallback callback) {
request_id_ = request_id;
audio_devices_.clear();
video_devices_.clear();
++request_stream_counter_;
if (controls->audio->requested) {
mojom::blink::MediaStreamDevicePtr audio_device =
mojom::blink::MediaStreamDevice::New();
audio_device->id =
controls->audio->device_id + WTF::String::Number(session_id_);
audio_device->name = "microphone";
audio_device->type = controls->audio->stream_type;
audio_device->session_id = session_id_;
audio_device->matched_output_device_id =
"associated_output_device_id" + WTF::String::Number(request_id_);
audio_devices_.push_back(std::move(audio_device));
}
if (controls->video->requested) {
mojom::blink::MediaStreamDevicePtr video_device =
mojom::blink::MediaStreamDevice::New();
video_device->id =
controls->video->device_id + WTF::String::Number(session_id_);
video_device->name = "usb video camera";
video_device->type = controls->video->stream_type;
video_device->video_facing = media::mojom::blink::VideoFacingMode::USER;
video_device->session_id = session_id_;
video_devices_.push_back(std::move(video_device));
}
if (do_not_run_cb_) {
generate_stream_cb_ = std::move(callback);
} else {
std::move(callback).Run(
mojom::blink::MediaStreamRequestResult::OK,
WTF::String("dummy") + WTF::String::Number(request_id_),
std::move(audio_devices_), std::move(video_devices_));
}
}
void MockMojoMediaStreamDispatcherHost::CancelRequest(int32_t request_id) {
EXPECT_EQ(request_id, request_id_);
}
void MockMojoMediaStreamDispatcherHost::StopStreamDevice(
const WTF::String& device_id,
int32_t session_id) {
for (const mojom::blink::MediaStreamDevicePtr& device : audio_devices_) {
if (device->id == device_id && device->session_id == session_id) {
++stop_audio_device_counter_;
return;
}
}
for (const mojom::blink::MediaStreamDevicePtr& device : video_devices_) {
if (device->id == device_id && device->session_id == session_id) {
++stop_video_device_counter_;
return;
}
}
NOTREACHED();
}
void MockMojoMediaStreamDispatcherHost::OpenDevice(
int32_t request_id,
const WTF::String& device_id,
mojom::blink::MediaStreamType type,
OpenDeviceCallback callback) {
mojom::blink::MediaStreamDevicePtr device =
mojom::blink::MediaStreamDevice::New();
device->id = device_id;
device->type = type;
device->session_id = session_id_;
std::move(callback).Run(true /* success */,
"dummy" + WTF::String::Number(request_id),
std::move(device));
}
} // namespace blink
// Copyright (c) 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.
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_MEDIASTREAM_MOCK_MOJO_MEDIA_STREAM_DISPATCHER_HOST_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_MEDIASTREAM_MOCK_MOJO_MEDIA_STREAM_DISPATCHER_HOST_H_
#include <string>
#include "base/macros.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "third_party/blink/public/common/mediastream/media_stream_controls.h"
#include "third_party/blink/public/common/mediastream/media_stream_request.h"
#include "third_party/blink/public/mojom/mediastream/media_stream.mojom-blink.h"
namespace blink {
class MockMojoMediaStreamDispatcherHost
: public mojom::blink::MediaStreamDispatcherHost {
public:
MockMojoMediaStreamDispatcherHost();
~MockMojoMediaStreamDispatcherHost() override;
mojom::blink::MediaStreamDispatcherHostPtr CreateInterfacePtrAndBind();
void GenerateStream(int32_t request_id,
mojom::blink::StreamControlsPtr controls,
bool user_gesture,
GenerateStreamCallback callback) override;
void CancelRequest(int32_t request_id) override;
void StopStreamDevice(const WTF::String& device_id,
int32_t session_id) override;
void OpenDevice(int32_t request_id,
const WTF::String& device_id,
mojom::blink::MediaStreamType type,
OpenDeviceCallback callback) override;
MOCK_METHOD1(CloseDevice, void(const WTF::String&));
MOCK_METHOD3(SetCapturingLinkSecured,
void(int32_t, mojom::blink::MediaStreamType, bool));
MOCK_METHOD1(OnStreamStarted, void(const WTF::String&));
void IncrementSessionId() { ++session_id_; }
void DoNotRunCallback() { do_not_run_cb_ = true; }
int request_stream_counter() const { return request_stream_counter_; }
int stop_audio_device_counter() const { return stop_audio_device_counter_; }
int stop_video_device_counter() const { return stop_video_device_counter_; }
const WTF::Vector<mojom::blink::MediaStreamDevicePtr>& audio_devices() const {
return audio_devices_;
}
const WTF::Vector<mojom::blink::MediaStreamDevicePtr>& video_devices() const {
return video_devices_;
}
private:
int request_id_ = -1;
int request_stream_counter_ = 0;
int stop_audio_device_counter_ = 0;
int stop_video_device_counter_ = 0;
int session_id_ = 0;
bool do_not_run_cb_ = false;
WTF::Vector<mojom::blink::MediaStreamDevicePtr> audio_devices_;
WTF::Vector<mojom::blink::MediaStreamDevicePtr> video_devices_;
GenerateStreamCallback generate_stream_cb_;
mojo::Binding<mojom::blink::MediaStreamDispatcherHost> binding_;
DISALLOW_COPY_AND_ASSIGN(MockMojoMediaStreamDispatcherHost);
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_MEDIASTREAM_MOCK_MOJO_MEDIA_STREAM_DISPATCHER_HOST_H_
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