From 6beb0cec0f47293fc637421c85e275a657caf7e7 Mon Sep 17 00:00:00 2001 From: guidou Date: Tue, 4 Jul 2017 23:57:51 -0700 Subject: [PATCH] Remove support for old getUserMedia video constraints algorithm. This CL removes most code implementing the old algorithm for processing getUserMedia video constraints. The new algorithm has been in stable Chrome for a few weeks now and having the option to switch back to the old algorithm is no longer necessary. BUG=706408 Review-Url: https://codereview.chromium.org/2964003002 Cr-Commit-Position: refs/heads/master@{#484202} --- .../webrtc/webrtc_getusermedia_browsertest.cc | 42 +- content/public/common/content_features.cc | 4 - content/public/common/content_features.h | 1 - content/renderer/media/media_stream_center.cc | 50 +- .../media_stream_video_capturer_source.cc | 440 +-------- .../media_stream_video_capturer_source.h | 6 - ...a_stream_video_capturer_source_unittest.cc | 361 +------- .../media/media_stream_video_source.cc | 514 +---------- .../media/media_stream_video_source.h | 33 - .../media_stream_video_source_unittest.cc | 854 ------------------ .../media/media_stream_video_track.cc | 51 +- .../renderer/media/media_stream_video_track.h | 26 - .../media_stream_video_track_unittest.cc | 270 +----- .../media/mock_media_stream_registry.cc | 32 +- .../media/mock_media_stream_registry.h | 7 - .../media/mock_media_stream_video_source.cc | 3 - .../renderer/media/user_media_client_impl.cc | 12 - .../webrtc/media_stream_video_webrtc_sink.cc | 51 +- ...media_stream_video_webrtc_sink_unittest.cc | 92 +- .../pepper_media_stream_video_track_host.cc | 1 - 20 files changed, 45 insertions(+), 2805 deletions(-) diff --git a/content/browser/webrtc/webrtc_getusermedia_browsertest.cc b/content/browser/webrtc/webrtc_getusermedia_browsertest.cc index 57b608b49e0412..3550c0c2f3c11f 100644 --- a/content/browser/webrtc/webrtc_getusermedia_browsertest.cc +++ b/content/browser/webrtc/webrtc_getusermedia_browsertest.cc @@ -109,9 +109,8 @@ namespace content { class WebRtcGetUserMediaBrowserTest : public WebRtcContentBrowserTestBase { public: WebRtcGetUserMediaBrowserTest() : trace_log_(NULL) { - scoped_feature_list_.InitWithFeatures( - {}, {features::kMediaStreamOldVideoConstraints, - features::kMediaStreamOldAudioConstraints}); + scoped_feature_list_.InitAndDisableFeature( + features::kMediaStreamOldAudioConstraints); // Automatically grant device permission. AppendUseFakeUIForMediaStreamFlag(); } @@ -806,10 +805,8 @@ class WebRtcGetUserMediaOldConstraintsBrowserTest : public WebRtcContentBrowserTestBase { public: WebRtcGetUserMediaOldConstraintsBrowserTest() : trace_log_(NULL) { - scoped_feature_list_.InitWithFeatures( - {features::kMediaStreamOldVideoConstraints, - features::kMediaStreamOldAudioConstraints}, - {}); + scoped_feature_list_.InitAndEnableFeature( + features::kMediaStreamOldAudioConstraints); // Automatically grant device permission. AppendUseFakeUIForMediaStreamFlag(); } @@ -1193,37 +1190,6 @@ IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaOldConstraintsBrowserTest, expected_result); } -// TODO(guidou): Remove this test. http://crbug.com/706408 -IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaOldConstraintsBrowserTest, - TwoGetUserMediaWithSecondVideoCropped) { - std::string constraints1 = "{video: true}"; - std::string constraints2 = "{video: {mandatory: {maxHeight: 360}}}"; - std::string expected_result = "w=640:h=480-w=640:h=360"; - RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1, constraints2, - expected_result); -} - -// Test fails under MSan, http://crbug.com/445745 -// TODO(guidou): Remove this test. http://crbug.com/706408 -#if defined(MEMORY_SANITIZER) -#define MAYBE_TwoGetUserMediaWithFirstHdSecondVga \ - DISABLED_TwoGetUserMediaWithFirstHdSecondVga -#else -#define MAYBE_TwoGetUserMediaWithFirstHdSecondVga \ - TwoGetUserMediaWithFirstHdSecondVga -#endif -IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaOldConstraintsBrowserTest, - MAYBE_TwoGetUserMediaWithFirstHdSecondVga) { - std::string constraints1 = - "{video: {mandatory: {maxWidth:1280 , minWidth:1280 , maxHeight: 720, " - "minHeight: 720}}}"; - std::string constraints2 = - "{video: {mandatory: {maxWidth:640 , maxHeight: 480}}}"; - std::string expected_result = "w=1280:h=720-w=640:h=480"; - RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1, constraints2, - expected_result); -} - // Timing out on Windows 7 bot: http://crbug.com/443294 // Flaky: http://crbug.com/660656; possible the test is too perf sensitive. IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaOldConstraintsBrowserTest, diff --git a/content/public/common/content_features.cc b/content/public/common/content_features.cc index e1544f66fd4c16..102701fdf088bc 100644 --- a/content/public/common/content_features.cc +++ b/content/public/common/content_features.cc @@ -146,10 +146,6 @@ const base::Feature kMediaDocumentDownloadButton{ const base::Feature kMediaStreamOldAudioConstraints{ "MediaStreamOldAudioConstraints", base::FEATURE_DISABLED_BY_DEFAULT}; -// Enables the old algorithm for processing video constraints in getUserMedia(). -const base::Feature kMediaStreamOldVideoConstraints{ - "MediaStreamOldVideoConstraints", base::FEATURE_DISABLED_BY_DEFAULT}; - // Enables the memory coordinator. // WARNING: // The memory coordinator is not ready for use and enabling this may cause diff --git a/content/public/common/content_features.h b/content/public/common/content_features.h index 122195ca581677..ca805403ae9a14 100644 --- a/content/public/common/content_features.h +++ b/content/public/common/content_features.h @@ -45,7 +45,6 @@ CONTENT_EXPORT extern const base::Feature kLazyParseCSS; CONTENT_EXPORT extern const base::Feature kLoadingWithMojo; CONTENT_EXPORT extern const base::Feature kMediaDocumentDownloadButton; CONTENT_EXPORT extern const base::Feature kMediaStreamOldAudioConstraints; -CONTENT_EXPORT extern const base::Feature kMediaStreamOldVideoConstraints; CONTENT_EXPORT extern const base::Feature kMemoryCoordinator; CONTENT_EXPORT extern const base::Feature kNotificationContentImage; CONTENT_EXPORT extern const base::Feature kMainThreadBusyScrollIntervention; diff --git a/content/renderer/media/media_stream_center.cc b/content/renderer/media/media_stream_center.cc index e7d146a7236588..d6bb4c9167445c 100644 --- a/content/renderer/media/media_stream_center.cc +++ b/content/renderer/media/media_stream_center.cc @@ -68,23 +68,9 @@ void CreateNativeVideoMediaStreamTrack(blink::WebMediaStreamTrack track) { MediaStreamVideoSource* native_source = MediaStreamVideoSource::GetVideoSource(source); DCHECK(native_source); - if (IsOldVideoConstraints()) { - // TODO(perkj): The constraints to use here should be passed from blink when - // a new track is created. For cloning, it should be the constraints of the - // cloned track and not the originating source. - // Also - source.constraints() returns an uninitialized constraint if the - // source is coming from a remote video track. See http://crbug/287805. - blink::WebMediaConstraints constraints = source.Constraints(); - if (constraints.IsNull()) - constraints.Initialize(); - track.SetTrackData(new MediaStreamVideoTrack( - native_source, constraints, - MediaStreamVideoSource::ConstraintsCallback(), track.IsEnabled())); - } else { - track.SetTrackData(new MediaStreamVideoTrack( - native_source, MediaStreamVideoSource::ConstraintsCallback(), - track.IsEnabled())); - } + track.SetTrackData(new MediaStreamVideoTrack( + native_source, MediaStreamVideoSource::ConstraintsCallback(), + track.IsEnabled())); } void CloneNativeVideoMediaStreamTrack( @@ -96,28 +82,14 @@ void CloneNativeVideoMediaStreamTrack( MediaStreamVideoSource* native_source = MediaStreamVideoSource::GetVideoSource(source); DCHECK(native_source); - if (IsOldVideoConstraints()) { - // TODO(perkj): The constraints to use here should be passed from blink when - // a new track is created. For cloning, it should be the constraints of the - // cloned track and not the originating source. - // Also - source.constraints() returns an uninitialized constraint if the - // source is coming from a remote video track. See http://crbug/287805. - blink::WebMediaConstraints constraints = source.Constraints(); - if (constraints.IsNull()) - constraints.Initialize(); - clone.SetTrackData(new MediaStreamVideoTrack( - native_source, constraints, - MediaStreamVideoSource::ConstraintsCallback(), clone.IsEnabled())); - } else { - MediaStreamVideoTrack* original_track = - MediaStreamVideoTrack::GetVideoTrack(original); - DCHECK(original_track); - clone.SetTrackData(new MediaStreamVideoTrack( - native_source, original_track->adapter_settings(), - original_track->noise_reduction(), original_track->is_screencast(), - original_track->min_frame_rate(), - MediaStreamVideoSource::ConstraintsCallback(), clone.IsEnabled())); - } + MediaStreamVideoTrack* original_track = + MediaStreamVideoTrack::GetVideoTrack(original); + DCHECK(original_track); + clone.SetTrackData(new MediaStreamVideoTrack( + native_source, original_track->adapter_settings(), + original_track->noise_reduction(), original_track->is_screencast(), + original_track->min_frame_rate(), + MediaStreamVideoSource::ConstraintsCallback(), clone.IsEnabled())); } } // namespace diff --git a/content/renderer/media/media_stream_video_capturer_source.cc b/content/renderer/media/media_stream_video_capturer_source.cc index 1eccdda77dd697..f4d0568dfacd9f 100644 --- a/content/renderer/media/media_stream_video_capturer_source.cc +++ b/content/renderer/media/media_stream_video_capturer_source.cc @@ -27,409 +27,6 @@ namespace content { namespace { -// Resolutions used if the source doesn't support capability enumeration. -struct { - int width; - int height; -} const kVideoResolutions[] = {{1920, 1080}, - {1280, 720}, - {960, 720}, - {640, 480}, - {640, 360}, - {320, 240}, - {320, 180}}; - -// Frame rates for sources with no support for capability enumeration. -const int kVideoFrameRates[] = {30, 60}; - -// Hard upper-bound frame rate for tab/desktop capture. -const double kMaxScreenCastFrameRate = 120.0; - -// Allows the user to Override default power line frequency. -const char kPowerLineFrequency[] = "googPowerLineFrequency"; - -// Returns true if the value for width or height is reasonable. -bool DimensionValueIsValid(int x) { - return x > 0 && x <= media::limits::kMaxDimension; -} - -// Returns true if the value for frame rate is reasonable. -bool FrameRateValueIsValid(double frame_rate) { - return (frame_rate > (1.0 / 60.0)) && // Lower-bound: One frame per minute. - (frame_rate <= media::limits::kMaxFramesPerSecond); -} - -// Returns true if the aspect ratio of |a| and |b| are equivalent to two -// significant digits. -bool AreNearlyEquivalentInAspectRatio(const gfx::Size& a, const gfx::Size& b) { - DCHECK(!a.IsEmpty()); - DCHECK(!b.IsEmpty()); - const int aspect_ratio_a = (100 * a.width()) / a.height(); - const int aspect_ratio_b = (100 * b.width()) / b.height(); - return aspect_ratio_a == aspect_ratio_b; -} - -// Checks if |device_info|s type is a generated content, e.g. Tab or Desktop. -bool IsContentVideoCaptureDevice(const StreamDeviceInfo& device_info) { - return device_info.device.type == MEDIA_TAB_VIDEO_CAPTURE || - device_info.device.type == MEDIA_DESKTOP_VIDEO_CAPTURE; -} - -// Interprets the properties in |constraints| to override values in |params| and -// determine the resolution change policy. -void SetContentCaptureParamsFromConstraints( - const blink::WebMediaConstraints& constraints, - MediaStreamType type, - media::VideoCaptureParams* params) { - // The default resolution change policies for tab versus desktop capture are - // the way they are for legacy reasons. - if (type == MEDIA_TAB_VIDEO_CAPTURE) { - params->resolution_change_policy = - media::RESOLUTION_POLICY_FIXED_RESOLUTION; - } else if (type == MEDIA_DESKTOP_VIDEO_CAPTURE) { - params->resolution_change_policy = - media::RESOLUTION_POLICY_ANY_WITHIN_LIMIT; - } else { - NOTREACHED(); - } - - // If the maximum frame resolution was provided in the constraints, use it if - // either: 1) none has been set yet; or 2) the maximum specificed is smaller - // than the current setting. - int width = 0; - int height = 0; - gfx::Size desired_max_frame_size; - if (GetConstraintMaxAsInteger( - constraints, &blink::WebMediaTrackConstraintSet::width, &width) && - GetConstraintMaxAsInteger( - constraints, &blink::WebMediaTrackConstraintSet::height, &height) && - DimensionValueIsValid(width) && DimensionValueIsValid(height)) { - desired_max_frame_size.SetSize(width, height); - if (params->requested_format.frame_size.IsEmpty() || - desired_max_frame_size.width() < - params->requested_format.frame_size.width() || - desired_max_frame_size.height() < - params->requested_format.frame_size.height()) { - params->requested_format.frame_size = desired_max_frame_size; - } - } - - // Set the default frame resolution if none was provided. - if (params->requested_format.frame_size.IsEmpty()) { - params->requested_format.frame_size.SetSize( - MediaStreamVideoSource::kDefaultWidth, - MediaStreamVideoSource::kDefaultHeight); - } - - // If the maximum frame rate was provided, use it if either: 1) none has been - // set yet; or 2) the maximum specificed is smaller than the current setting. - double frame_rate = 0.0; - if (GetConstraintMaxAsDouble(constraints, - &blink::WebMediaTrackConstraintSet::frame_rate, - &frame_rate) && - FrameRateValueIsValid(frame_rate)) { - if (params->requested_format.frame_rate <= 0.0f || - frame_rate < params->requested_format.frame_rate) { - params->requested_format.frame_rate = frame_rate; - } - } - - // Set the default frame rate if none was provided. - if (params->requested_format.frame_rate <= 0.0f) { - params->requested_format.frame_rate = - MediaStreamVideoSource::kDefaultFrameRate; - } - - // If the minimum frame resolution was provided, compare it to the maximum - // frame resolution to determine the intended resolution change policy. - if (!desired_max_frame_size.IsEmpty() && - GetConstraintMinAsInteger( - constraints, &blink::WebMediaTrackConstraintSet::width, &width) && - GetConstraintMinAsInteger( - constraints, &blink::WebMediaTrackConstraintSet::height, &height) && - width <= desired_max_frame_size.width() && - height <= desired_max_frame_size.height()) { - if (width == desired_max_frame_size.width() && - height == desired_max_frame_size.height()) { - // Constraints explicitly require a single frame resolution. - params->resolution_change_policy = - media::RESOLUTION_POLICY_FIXED_RESOLUTION; - } else if (DimensionValueIsValid(width) && - DimensionValueIsValid(height) && - AreNearlyEquivalentInAspectRatio(gfx::Size(width, height), - desired_max_frame_size)) { - // Constraints only mention a single aspect ratio. - params->resolution_change_policy = - media::RESOLUTION_POLICY_FIXED_ASPECT_RATIO; - } else { - // Constraints specify a minimum resolution that is smaller than the - // maximum resolution and has a different aspect ratio (possibly even - // 0x0). This indicates any frame resolution and aspect ratio is - // acceptable. - params->resolution_change_policy = - media::RESOLUTION_POLICY_ANY_WITHIN_LIMIT; - } - } - - DVLOG(1) << __func__ << " " - << media::VideoCaptureFormat::ToString(params->requested_format) - << " with resolution change policy " - << params->resolution_change_policy; -} - -// Interprets the properties in |constraints| to override values in |params| and -// determine the power line frequency. -void SetPowerLineFrequencyParamFromConstraints( - const blink::WebMediaConstraints& constraints, - media::VideoCaptureParams* params) { - int freq; - params->power_line_frequency = media::PowerLineFrequency::FREQUENCY_DEFAULT; - if (!GetConstraintValueAsInteger( - constraints, - &blink::WebMediaTrackConstraintSet::goog_power_line_frequency, - &freq)) { - return; - } - if (freq == static_cast(media::PowerLineFrequency::FREQUENCY_50HZ)) - params->power_line_frequency = media::PowerLineFrequency::FREQUENCY_50HZ; - else if (freq == static_cast(media::PowerLineFrequency::FREQUENCY_60HZ)) - params->power_line_frequency = media::PowerLineFrequency::FREQUENCY_60HZ; -} - -// LegacyLocalVideoCapturerSource is a delegate used by -// MediaStreamVideoCapturerSource for local video capture. It uses the Render -// singleton VideoCaptureImplManager to start / stop and receive I420 frames -// from Chrome's video capture implementation. This is a main Render thread only -// object. -// TODO(guidou): Remove this class. http://crbug.com/706408 -class LegacyLocalVideoCapturerSource final : public media::VideoCapturerSource { - public: - explicit LegacyLocalVideoCapturerSource(const StreamDeviceInfo& device_info); - ~LegacyLocalVideoCapturerSource() override; - - // VideoCaptureDelegate Implementation. - void GetCurrentSupportedFormats( - int max_requested_width, - int max_requested_height, - double max_requested_frame_rate, - const VideoCaptureDeviceFormatsCB& callback) override; - media::VideoCaptureFormats GetPreferredFormats() override; - void StartCapture(const media::VideoCaptureParams& params, - const VideoCaptureDeliverFrameCB& new_frame_callback, - const RunningCallback& running_callback) override; - void RequestRefreshFrame() override; - void MaybeSuspend() override; - void Resume() override; - void StopCapture() override; - - private: - void OnStateUpdate(VideoCaptureState state); - void OnDeviceFormatsInUseReceived(const media::VideoCaptureFormats& formats); - void OnDeviceSupportedFormatsEnumerated( - const media::VideoCaptureFormats& formats); - - // |session_id_| identifies the capture device used for this capture session. - const media::VideoCaptureSessionId session_id_; - - VideoCaptureImplManager* const manager_; - - const base::Closure release_device_cb_; - - // Indicates if we are capturing generated content, e.g. Tab or Desktop. - const bool is_content_capture_; - - // These two are valid between StartCapture() and StopCapture(). - // |running_call_back_| is run when capture is successfully started, and when - // it is stopped or error happens. - RunningCallback running_callback_; - base::Closure stop_capture_cb_; - - // Placeholder keeping the callback between asynchronous device enumeration - // calls. - VideoCaptureDeviceFormatsCB formats_enumerated_callback_; - - // Bound to the main render thread. - base::ThreadChecker thread_checker_; - - base::WeakPtrFactory weak_factory_; - - DISALLOW_COPY_AND_ASSIGN(LegacyLocalVideoCapturerSource); -}; - -LegacyLocalVideoCapturerSource::LegacyLocalVideoCapturerSource( - const StreamDeviceInfo& device_info) - : session_id_(device_info.session_id), - manager_(RenderThreadImpl::current()->video_capture_impl_manager()), - release_device_cb_(manager_->UseDevice(session_id_)), - is_content_capture_(IsContentVideoCaptureDevice(device_info)), - weak_factory_(this) { - DCHECK(RenderThreadImpl::current()); -} - -LegacyLocalVideoCapturerSource::~LegacyLocalVideoCapturerSource() { - DCHECK(thread_checker_.CalledOnValidThread()); - release_device_cb_.Run(); -} - -void LegacyLocalVideoCapturerSource::GetCurrentSupportedFormats( - int max_requested_width, - int max_requested_height, - double max_requested_frame_rate, - const VideoCaptureDeviceFormatsCB& callback) { - DVLOG(3) << "GetCurrentSupportedFormats({ max_requested_height = " - << max_requested_height << "}) { max_requested_width = " - << max_requested_width << "}) { max_requested_frame_rate = " - << max_requested_frame_rate << "})"; - DCHECK(thread_checker_.CalledOnValidThread()); - - if (is_content_capture_) { - const int width = max_requested_width ? - max_requested_width : MediaStreamVideoSource::kDefaultWidth; - const int height = max_requested_height ? - max_requested_height : MediaStreamVideoSource::kDefaultHeight; - callback.Run(media::VideoCaptureFormats( - 1, media::VideoCaptureFormat( - gfx::Size(width, height), - static_cast( - std::min(kMaxScreenCastFrameRate, max_requested_frame_rate)), - media::PIXEL_FORMAT_I420))); - return; - } - - DCHECK(formats_enumerated_callback_.is_null()); - formats_enumerated_callback_ = callback; - manager_->GetDeviceFormatsInUse( - session_id_, - media::BindToCurrentLoop(base::Bind( - &LegacyLocalVideoCapturerSource::OnDeviceFormatsInUseReceived, - weak_factory_.GetWeakPtr()))); -} - -media::VideoCaptureFormats -LegacyLocalVideoCapturerSource::GetPreferredFormats() { - return media::VideoCaptureFormats(); -} - -void LegacyLocalVideoCapturerSource::StartCapture( - const media::VideoCaptureParams& params, - const VideoCaptureDeliverFrameCB& new_frame_callback, - const RunningCallback& running_callback) { - DCHECK(params.requested_format.IsValid()); - DCHECK(thread_checker_.CalledOnValidThread()); - running_callback_ = running_callback; - - stop_capture_cb_ = - manager_->StartCapture(session_id_, params, - media::BindToCurrentLoop(base::Bind( - &LegacyLocalVideoCapturerSource::OnStateUpdate, - weak_factory_.GetWeakPtr())), - new_frame_callback); -} - -void LegacyLocalVideoCapturerSource::RequestRefreshFrame() { - DVLOG(3) << __func__; - DCHECK(thread_checker_.CalledOnValidThread()); - if (stop_capture_cb_.is_null()) - return; // Do not request frames if the source is stopped. - manager_->RequestRefreshFrame(session_id_); -} - -void LegacyLocalVideoCapturerSource::MaybeSuspend() { - DVLOG(3) << __func__; - DCHECK(thread_checker_.CalledOnValidThread()); - manager_->Suspend(session_id_); -} - -void LegacyLocalVideoCapturerSource::Resume() { - DVLOG(3) << __func__; - DCHECK(thread_checker_.CalledOnValidThread()); - manager_->Resume(session_id_); -} - -void LegacyLocalVideoCapturerSource::StopCapture() { - DVLOG(3) << __func__; - DCHECK(thread_checker_.CalledOnValidThread()); - // Immediately make sure we don't provide more frames. - if (!stop_capture_cb_.is_null()) - base::ResetAndReturn(&stop_capture_cb_).Run(); - running_callback_.Reset(); - // Invalidate any potential format enumerations going on. - formats_enumerated_callback_.Reset(); -} - -void LegacyLocalVideoCapturerSource::OnStateUpdate(VideoCaptureState state) { - DVLOG(3) << __func__ << " state = " << state; - DCHECK(thread_checker_.CalledOnValidThread()); - if (running_callback_.is_null()) - return; - switch (state) { - case VIDEO_CAPTURE_STATE_STARTED: - running_callback_.Run(true); - break; - - case VIDEO_CAPTURE_STATE_STOPPING: - case VIDEO_CAPTURE_STATE_STOPPED: - case VIDEO_CAPTURE_STATE_ERROR: - case VIDEO_CAPTURE_STATE_ENDED: - base::ResetAndReturn(&running_callback_).Run(false); - break; - - case VIDEO_CAPTURE_STATE_STARTING: - case VIDEO_CAPTURE_STATE_PAUSED: - case VIDEO_CAPTURE_STATE_RESUMED: - // Not applicable to reporting on device starts or errors. - break; - } -} - -void LegacyLocalVideoCapturerSource::OnDeviceFormatsInUseReceived( - const media::VideoCaptureFormats& formats_in_use) { - DVLOG(3) << __func__ << ", #formats received: " << formats_in_use.size(); - DCHECK(thread_checker_.CalledOnValidThread()); - // StopCapture() might have destroyed |formats_enumerated_callback_| before - // arriving here. - if (formats_enumerated_callback_.is_null()) - return; - if (formats_in_use.size()) { - base::ResetAndReturn(&formats_enumerated_callback_).Run(formats_in_use); - return; - } - - // The device doesn't seem to have formats in use so try and retrieve the - // whole list of supported ones. - manager_->GetDeviceSupportedFormats( - session_id_, - media::BindToCurrentLoop(base::Bind( - &LegacyLocalVideoCapturerSource::OnDeviceSupportedFormatsEnumerated, - weak_factory_.GetWeakPtr()))); -} - -void LegacyLocalVideoCapturerSource::OnDeviceSupportedFormatsEnumerated( - const media::VideoCaptureFormats& formats) { - DVLOG(3) << __func__ << ", #formats received: " << formats.size(); - DCHECK(thread_checker_.CalledOnValidThread()); - // StopCapture() might have destroyed |formats_enumerated_callback_| before - // arriving here. - if (formats_enumerated_callback_.is_null()) - return; - if (formats.size()) { - base::ResetAndReturn(&formats_enumerated_callback_).Run(formats); - return; - } - - // The capture device doesn't seem to support capability enumeration, compose - // a fallback list of capabilities. - media::VideoCaptureFormats default_formats; - for (const auto& resolution : kVideoResolutions) { - for (const auto frame_rate : kVideoFrameRates) { - default_formats.push_back(media::VideoCaptureFormat( - gfx::Size(resolution.width, resolution.height), frame_rate, - media::PIXEL_FORMAT_I420)); - } - } - base::ResetAndReturn(&formats_enumerated_callback_).Run(default_formats); -} - // LocalVideoCapturerSource is a delegate used by MediaStreamVideoCapturerSource // for local video capture. It uses the Render singleton VideoCaptureImplManager // to start / stop and receive I420 frames from Chrome's video capture @@ -563,24 +160,10 @@ MediaStreamVideoCapturerSource::MediaStreamVideoCapturerSource( const SourceStoppedCallback& stop_callback, std::unique_ptr source) : RenderFrameObserver(nullptr), source_(std::move(source)) { - if (!IsOldVideoConstraints()) { - media::VideoCaptureFormats preferred_formats = - source_->GetPreferredFormats(); - if (!preferred_formats.empty()) - capture_params_.requested_format = preferred_formats.front(); - } - SetStopCallback(stop_callback); -} - -MediaStreamVideoCapturerSource::MediaStreamVideoCapturerSource( - const SourceStoppedCallback& stop_callback, - const StreamDeviceInfo& device_info, - RenderFrame* render_frame) - : RenderFrameObserver(render_frame), - source_(new LegacyLocalVideoCapturerSource(device_info)) { - DCHECK(IsOldVideoConstraints()); + media::VideoCaptureFormats preferred_formats = source_->GetPreferredFormats(); + if (!preferred_formats.empty()) + capture_params_.requested_format = preferred_formats.front(); SetStopCallback(stop_callback); - SetDeviceInfo(device_info); } MediaStreamVideoCapturerSource::MediaStreamVideoCapturerSource( @@ -591,7 +174,6 @@ MediaStreamVideoCapturerSource::MediaStreamVideoCapturerSource( : RenderFrameObserver(render_frame), source_(new LocalVideoCapturerSource(device_info)), capture_params_(capture_params) { - DCHECK(!IsOldVideoConstraints()); SetStopCallback(stop_callback); SetDeviceInfo(device_info); } @@ -631,16 +213,6 @@ void MediaStreamVideoCapturerSource::StartSourceImpl( const media::VideoCaptureFormat& format, const blink::WebMediaConstraints& constraints, const VideoCaptureDeliverFrameCB& frame_callback) { - if (IsOldVideoConstraints()) { - capture_params_.requested_format = format; - if (IsContentVideoCaptureDevice(device_info())) { - SetContentCaptureParamsFromConstraints( - constraints, device_info().device.type, &capture_params_); - } else if (device_info().device.type == MEDIA_DEVICE_VIDEO_CAPTURE) { - SetPowerLineFrequencyParamFromConstraints(constraints, &capture_params_); - } - } - is_capture_starting_ = true; source_->StartCapture( capture_params_, frame_callback, @@ -654,7 +226,6 @@ void MediaStreamVideoCapturerSource::StopSourceImpl() { base::Optional MediaStreamVideoCapturerSource::GetCurrentFormatImpl() const { - DCHECK(!IsOldVideoConstraints()); return base::Optional( capture_params_.requested_format); } @@ -669,9 +240,4 @@ void MediaStreamVideoCapturerSource::OnRunStateChanged(bool is_running) { } } -const char* -MediaStreamVideoCapturerSource::GetPowerLineFrequencyForTesting() const { - return kPowerLineFrequency; -} - } // namespace content diff --git a/content/renderer/media/media_stream_video_capturer_source.h b/content/renderer/media/media_stream_video_capturer_source.h index df704687cd072c..ee8abe264ecc04 100644 --- a/content/renderer/media/media_stream_video_capturer_source.h +++ b/content/renderer/media/media_stream_video_capturer_source.h @@ -32,10 +32,6 @@ class CONTENT_EXPORT MediaStreamVideoCapturerSource MediaStreamVideoCapturerSource( const SourceStoppedCallback& stop_callback, std::unique_ptr source); - // TODO(guidou): Remove this constructor. http://crbug.com/706408 - MediaStreamVideoCapturerSource(const SourceStoppedCallback& stop_callback, - const StreamDeviceInfo& device_info, - RenderFrame* render_frame); MediaStreamVideoCapturerSource( const SourceStoppedCallback& stop_callback, const StreamDeviceInfo& device_info, @@ -71,8 +67,6 @@ class CONTENT_EXPORT MediaStreamVideoCapturerSource // Method to bind as RunningCallback in VideoCapturerSource::StartCapture(). void OnRunStateChanged(bool is_running); - const char* GetPowerLineFrequencyForTesting() const; - // The source that provides video frames. const std::unique_ptr source_; diff --git a/content/renderer/media/media_stream_video_capturer_source_unittest.cc b/content/renderer/media/media_stream_video_capturer_source_unittest.cc index e4cffd6526b7f1..11efe040786b6f 100644 --- a/content/renderer/media/media_stream_video_capturer_source_unittest.cc +++ b/content/renderer/media/media_stream_video_capturer_source_unittest.cc @@ -12,13 +12,10 @@ #include "base/run_loop.h" #include "base/single_thread_task_runner.h" #include "base/strings/utf_string_conversions.h" -#include "base/test/scoped_feature_list.h" #include "base/test/scoped_task_environment.h" #include "content/child/child_process.h" -#include "content/public/common/content_features.h" #include "content/public/renderer/media_stream_video_sink.h" #include "content/renderer/media/media_stream_video_track.h" -#include "content/renderer/media/mock_constraint_factory.h" #include "content/renderer/media/video_track_adapter.h" #include "media/base/bind_to_current_loop.h" #include "testing/gmock/include/gmock/gmock.h" @@ -110,10 +107,7 @@ class MediaStreamVideoCapturerSourceTest : public testing::Test { child_process_(new ChildProcess()), source_(nullptr), delegate_(nullptr), - source_stopped_(false) { - scoped_feature_list_.InitAndDisableFeature( - features::kMediaStreamOldVideoConstraints); - } + source_stopped_(false) {} void TearDown() override { webkit_source_.Reset(); @@ -138,18 +132,6 @@ class MediaStreamVideoCapturerSourceTest : public testing::Test { webkit_source_id_ = webkit_source_.Id(); } - MockConstraintFactory* constraint_factory() { return &constraint_factory_; } - - blink::WebMediaStreamTrack StartSource() { - bool enabled = true; - // CreateVideoTrack will trigger OnConstraintsApplied. - return MediaStreamVideoTrack::CreateVideoTrack( - source_, constraint_factory_.CreateWebMediaConstraints(), - base::Bind(&MediaStreamVideoCapturerSourceTest::OnConstraintsApplied, - base::Unretained(this)), - enabled); - } - blink::WebMediaStreamTrack StartSource( const VideoTrackAdapterSettings& adapter_settings, const base::Optional& noise_reduction, @@ -167,10 +149,6 @@ class MediaStreamVideoCapturerSourceTest : public testing::Test { MockVideoCapturerSource& mock_delegate() { return *delegate_; } - const char* GetPowerLineFrequencyForTesting() const { - return source_->GetPowerLineFrequencyForTesting(); - } - void OnSourceStopped(const blink::WebMediaStreamSource& source) { source_stopped_ = true; EXPECT_EQ(source.Id(), webkit_source_id_); @@ -192,8 +170,6 @@ class MediaStreamVideoCapturerSourceTest : public testing::Test { MockVideoCapturerSource* delegate_; // owned by |source|. blink::WebString webkit_source_id_; bool source_stopped_; - MockConstraintFactory constraint_factory_; - base::test::ScopedFeatureList scoped_feature_list_; }; TEST_F(MediaStreamVideoCapturerSourceTest, StartAndStop) { @@ -287,339 +263,4 @@ TEST_F(MediaStreamVideoCapturerSourceTest, CaptureTimeAndMetadataPlumbing) { EXPECT_EQ(30.0, metadata_value); } -class MediaStreamVideoCapturerSourceOldConstraintsTest : public testing::Test { - public: - MediaStreamVideoCapturerSourceOldConstraintsTest() - : scoped_task_environment_( - base::test::ScopedTaskEnvironment::MainThreadType::UI), - child_process_(new ChildProcess()), - source_(nullptr), - delegate_(nullptr), - source_stopped_(false) { - scoped_feature_list_.InitAndEnableFeature( - features::kMediaStreamOldVideoConstraints); - } - - void TearDown() override { - webkit_source_.Reset(); - blink::WebHeap::CollectAllGarbageForTesting(); - } - - void InitWithDeviceInfo(const StreamDeviceInfo& device_info) { - std::unique_ptr delegate( - new MockVideoCapturerSource()); - delegate_ = delegate.get(); - source_ = new MediaStreamVideoCapturerSource( - base::Bind( - &MediaStreamVideoCapturerSourceOldConstraintsTest::OnSourceStopped, - base::Unretained(this)), - std::move(delegate)); - source_->SetDeviceInfo(device_info); - - webkit_source_.Initialize(blink::WebString::FromASCII("dummy_source_id"), - blink::WebMediaStreamSource::kTypeVideo, - blink::WebString::FromASCII("dummy_source_name"), - false /* remote */); - webkit_source_.SetExtraData(source_); - webkit_source_id_ = webkit_source_.Id(); - } - - MockConstraintFactory* constraint_factory() { return &constraint_factory_; } - - blink::WebMediaStreamTrack StartSource() { - bool enabled = true; - // CreateVideoTrack will trigger OnConstraintsApplied. - return MediaStreamVideoTrack::CreateVideoTrack( - source_, constraint_factory_.CreateWebMediaConstraints(), - base::Bind(&MediaStreamVideoCapturerSourceOldConstraintsTest:: - OnConstraintsApplied, - base::Unretained(this)), - enabled); - } - - blink::WebMediaStreamTrack StartSource( - const VideoTrackAdapterSettings& adapter_settings, - const base::Optional& noise_reduction, - bool is_screencast, - double min_frame_rate) { - bool enabled = true; - // CreateVideoTrack will trigger OnConstraintsApplied. - return MediaStreamVideoTrack::CreateVideoTrack( - source_, adapter_settings, noise_reduction, is_screencast, - min_frame_rate, - base::Bind(&MediaStreamVideoCapturerSourceOldConstraintsTest:: - OnConstraintsApplied, - base::Unretained(this)), - enabled); - } - - MockVideoCapturerSource& mock_delegate() { return *delegate_; } - - const char* GetPowerLineFrequencyForTesting() const { - return source_->GetPowerLineFrequencyForTesting(); - } - - void OnSourceStopped(const blink::WebMediaStreamSource& source) { - source_stopped_ = true; - EXPECT_EQ(source.Id(), webkit_source_id_); - } - void OnStarted(bool result) { source_->OnRunStateChanged(result); } - - protected: - void OnConstraintsApplied(MediaStreamSource* source, - MediaStreamRequestResult result, - const blink::WebString& result_name) {} - - // A ChildProcess and a MessageLoopForUI are both needed to fool the Tracks - // and Sources below into believing they are on the right threads. - base::test::ScopedTaskEnvironment scoped_task_environment_; - std::unique_ptr child_process_; - - blink::WebMediaStreamSource webkit_source_; - MediaStreamVideoCapturerSource* source_; // owned by |webkit_source_|. - MockVideoCapturerSource* delegate_; // owned by |source|. - blink::WebString webkit_source_id_; - bool source_stopped_; - MockConstraintFactory constraint_factory_; - base::test::ScopedFeatureList scoped_feature_list_; -}; - -TEST_F(MediaStreamVideoCapturerSourceOldConstraintsTest, - TabCaptureFixedResolutionByDefault) { - StreamDeviceInfo device_info; - device_info.device.type = MEDIA_TAB_VIDEO_CAPTURE; - InitWithDeviceInfo(device_info); - - // No constraints are being provided to the implementation, so expect only - // default values. - media::VideoCaptureParams expected_params; - expected_params.requested_format.frame_size.SetSize( - MediaStreamVideoSource::kDefaultWidth, - MediaStreamVideoSource::kDefaultHeight); - expected_params.requested_format.frame_rate = - MediaStreamVideoSource::kDefaultFrameRate; - expected_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; - expected_params.resolution_change_policy = - media::RESOLUTION_POLICY_FIXED_RESOLUTION; - - InSequence s; - EXPECT_CALL(mock_delegate(), GetCurrentSupportedFormats(_, _, _, _)); - EXPECT_CALL(mock_delegate(), StartCapture(expected_params, _, _)); - blink::WebMediaStreamTrack track = StartSource(); - // When the track goes out of scope, the source will be stopped. - EXPECT_CALL(mock_delegate(), StopCapture()); -} - -TEST_F(MediaStreamVideoCapturerSourceOldConstraintsTest, - DesktopCaptureAllowAnyResolutionChangeByDefault) { - StreamDeviceInfo device_info; - device_info.device.type = MEDIA_DESKTOP_VIDEO_CAPTURE; - InitWithDeviceInfo(device_info); - - // No constraints are being provided to the implementation, so expect only - // default values. - media::VideoCaptureParams expected_params; - expected_params.requested_format.frame_size.SetSize( - MediaStreamVideoSource::kDefaultWidth, - MediaStreamVideoSource::kDefaultHeight); - expected_params.requested_format.frame_rate = - MediaStreamVideoSource::kDefaultFrameRate; - expected_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; - expected_params.resolution_change_policy = - media::RESOLUTION_POLICY_ANY_WITHIN_LIMIT; - - InSequence s; - EXPECT_CALL(mock_delegate(), GetCurrentSupportedFormats(_, _, _, _)); - EXPECT_CALL(mock_delegate(), StartCapture(expected_params, _, _)); - blink::WebMediaStreamTrack track = StartSource(); - // When the track goes out of scope, the source will be stopped. - EXPECT_CALL(mock_delegate(), StopCapture()); -} - -TEST_F(MediaStreamVideoCapturerSourceOldConstraintsTest, - TabCaptureConstraintsImplyFixedAspectRatio) { - StreamDeviceInfo device_info; - device_info.device.type = MEDIA_TAB_VIDEO_CAPTURE; - InitWithDeviceInfo(device_info); - - // Specify max and min size constraints that have the same ~16:9 aspect ratio. - constraint_factory()->basic().width.SetMax(1920); - constraint_factory()->basic().height.SetMax(1080); - constraint_factory()->basic().width.SetMin(854); - constraint_factory()->basic().height.SetMin(480); - constraint_factory()->basic().frame_rate.SetMax(60.0); - - media::VideoCaptureParams expected_params; - expected_params.requested_format.frame_size.SetSize(1920, 1080); - expected_params.requested_format.frame_rate = 60.0; - expected_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; - expected_params.resolution_change_policy = - media::RESOLUTION_POLICY_FIXED_ASPECT_RATIO; - - InSequence s; - EXPECT_CALL(mock_delegate(), GetCurrentSupportedFormats(_, _, _, _)); - EXPECT_CALL( - mock_delegate(), - StartCapture( - testing::Field(&media::VideoCaptureParams::resolution_change_policy, - media::RESOLUTION_POLICY_FIXED_ASPECT_RATIO), - _, _)); - blink::WebMediaStreamTrack track = StartSource(); - // When the track goes out of scope, the source will be stopped. - EXPECT_CALL(mock_delegate(), StopCapture()); -} - -TEST_F(MediaStreamVideoCapturerSourceOldConstraintsTest, - TabCaptureConstraintsImplyAllowingAnyResolutionChange) { - StreamDeviceInfo device_info; - device_info.device.type = MEDIA_TAB_VIDEO_CAPTURE; - InitWithDeviceInfo(device_info); - - // Specify max and min size constraints with different aspect ratios. - constraint_factory()->basic().width.SetMax(1920); - constraint_factory()->basic().height.SetMax(1080); - constraint_factory()->basic().width.SetMin(0); - constraint_factory()->basic().height.SetMin(0); - constraint_factory()->basic().frame_rate.SetMax(60.0); - - media::VideoCaptureParams expected_params; - expected_params.requested_format.frame_size.SetSize(1920, 1080); - expected_params.requested_format.frame_rate = 60.0; - expected_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; - expected_params.resolution_change_policy = - media::RESOLUTION_POLICY_ANY_WITHIN_LIMIT; - - InSequence s; - EXPECT_CALL(mock_delegate(), GetCurrentSupportedFormats(_, _, _, _)); - EXPECT_CALL( - mock_delegate(), - StartCapture( - testing::Field(&media::VideoCaptureParams::resolution_change_policy, - media::RESOLUTION_POLICY_ANY_WITHIN_LIMIT), - _, _)); - blink::WebMediaStreamTrack track = StartSource(); - // When the track goes out of scope, the source will be stopped. - EXPECT_CALL(mock_delegate(), StopCapture()); -} - -TEST_F(MediaStreamVideoCapturerSourceOldConstraintsTest, - DeviceCaptureConstraintsSupportPowerLineFrequency) { - for (int frequency = -100; frequency < 100; ++frequency) { - StreamDeviceInfo device_info; - device_info.device.type = MEDIA_DEVICE_VIDEO_CAPTURE; - InitWithDeviceInfo(device_info); - constraint_factory_.Reset(); - - constraint_factory()->AddAdvanced().goog_power_line_frequency.SetExact( - frequency); - - media::VideoCaptureParams expected_params; - expected_params.requested_format.frame_size.SetSize( - MediaStreamVideoSource::kDefaultWidth, - MediaStreamVideoSource::kDefaultHeight); - expected_params.requested_format.frame_rate = - MediaStreamVideoSource::kDefaultFrameRate; - expected_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; - expected_params.resolution_change_policy = - media::RESOLUTION_POLICY_FIXED_RESOLUTION; - if (frequency == 50) { - expected_params.power_line_frequency = - media::PowerLineFrequency::FREQUENCY_50HZ; - } else if (frequency == 60) { - expected_params.power_line_frequency = - media::PowerLineFrequency::FREQUENCY_60HZ; - } else { - expected_params.power_line_frequency = - media::PowerLineFrequency::FREQUENCY_DEFAULT; - } - - InSequence s; - EXPECT_CALL(mock_delegate(), GetCurrentSupportedFormats(_, _, _, _)); - EXPECT_CALL(mock_delegate(), StartCapture(expected_params, _, _)); - blink::WebMediaStreamTrack track = StartSource(); - // When the track goes out of scope, the source will be stopped. - EXPECT_CALL(mock_delegate(), StopCapture()); - } -} - -TEST_F(MediaStreamVideoCapturerSourceOldConstraintsTest, Ended) { - std::unique_ptr delegate( - new MockVideoCapturerSource()); - delegate_ = delegate.get(); - source_ = new MediaStreamVideoCapturerSource( - base::Bind( - &MediaStreamVideoCapturerSourceOldConstraintsTest::OnSourceStopped, - base::Unretained(this)), - std::move(delegate)); - webkit_source_.Initialize(blink::WebString::FromASCII("dummy_source_id"), - blink::WebMediaStreamSource::kTypeVideo, - blink::WebString::FromASCII("dummy_source_name"), - false /* remote */); - webkit_source_.SetExtraData(source_); - webkit_source_id_ = webkit_source_.Id(); - - InSequence s; - EXPECT_CALL(mock_delegate(), GetCurrentSupportedFormats(_, _, _, _)); - EXPECT_CALL(mock_delegate(), StartCapture(_, _, _)); - blink::WebMediaStreamTrack track = StartSource(); - base::RunLoop().RunUntilIdle(); - - OnStarted(true); - base::RunLoop().RunUntilIdle(); - EXPECT_EQ(blink::WebMediaStreamSource::kReadyStateLive, - webkit_source_.GetReadyState()); - - EXPECT_FALSE(source_stopped_); - - EXPECT_CALL(mock_delegate(), StopCapture()); - OnStarted(false); - base::RunLoop().RunUntilIdle(); - EXPECT_EQ(blink::WebMediaStreamSource::kReadyStateEnded, - webkit_source_.GetReadyState()); - // Verify that MediaStreamSource::SourceStoppedCallback has been triggered. - EXPECT_TRUE(source_stopped_); -} - -TEST_F(MediaStreamVideoCapturerSourceOldConstraintsTest, - CaptureTimeAndMetadataPlumbing) { - StreamDeviceInfo device_info; - device_info.device.type = MEDIA_DESKTOP_VIDEO_CAPTURE; - InitWithDeviceInfo(device_info); - - VideoCaptureDeliverFrameCB deliver_frame_cb; - media::VideoCapturerSource::RunningCallback running_cb; - - InSequence s; - EXPECT_CALL(mock_delegate(), GetCurrentSupportedFormats(_, _, _, _)); - EXPECT_CALL(mock_delegate(), StartCapture(_, _, _)) - .WillOnce(testing::DoAll(testing::SaveArg<1>(&deliver_frame_cb), - testing::SaveArg<2>(&running_cb))); - EXPECT_CALL(mock_delegate(), RequestRefreshFrame()); - EXPECT_CALL(mock_delegate(), StopCapture()); - blink::WebMediaStreamTrack track = StartSource(); - running_cb.Run(true); - - base::RunLoop run_loop; - base::TimeTicks reference_capture_time = - base::TimeTicks::FromInternalValue(60013); - base::TimeTicks capture_time; - media::VideoFrameMetadata metadata; - FakeMediaStreamVideoSink fake_sink( - &capture_time, &metadata, - media::BindToCurrentLoop(run_loop.QuitClosure())); - fake_sink.ConnectToTrack(track); - const scoped_refptr frame = - media::VideoFrame::CreateBlackFrame(gfx::Size(2, 2)); - frame->metadata()->SetDouble(media::VideoFrameMetadata::FRAME_RATE, 30.0); - child_process_->io_task_runner()->PostTask( - FROM_HERE, base::Bind(deliver_frame_cb, frame, reference_capture_time)); - run_loop.Run(); - fake_sink.DisconnectFromTrack(); - EXPECT_EQ(reference_capture_time, capture_time); - double metadata_value; - EXPECT_TRUE(metadata.GetDouble(media::VideoFrameMetadata::FRAME_RATE, - &metadata_value)); - EXPECT_EQ(30.0, metadata_value); -} - } // namespace content diff --git a/content/renderer/media/media_stream_video_source.cc b/content/renderer/media/media_stream_video_source.cc index a9e158a65123a6..54852968b1f2fd 100644 --- a/content/renderer/media/media_stream_video_source.cc +++ b/content/renderer/media/media_stream_video_source.cc @@ -23,299 +23,6 @@ namespace content { -namespace { - -const char* const kLegalVideoConstraints[] = {"width", - "height", - "aspectRatio", - "frameRate", - "facingMode", - "deviceId", - "groupId", - "mediaStreamSource", - "googNoiseReduction", - "videoKind"}; - -// Returns true if |constraint| has mandatory constraints. -bool HasMandatoryConstraints(const blink::WebMediaConstraints& constraints) { - return constraints.Basic().HasMandatory(); -} - -// Retrieve the desired max width and height from |constraints|. If not set, -// the |desired_width| and |desired_height| are set to -// std::numeric_limits::max(); -// If either max or exact width or height is set as a mandatory constraint, -// the advanced constraints are not checked. -void GetDesiredMaxWidthAndHeight(const blink::WebMediaConstraints& constraints, - int* desired_width, int* desired_height) { - *desired_width = std::numeric_limits::max(); - *desired_height = std::numeric_limits::max(); - - const auto& basic_constraints = constraints.Basic(); - - if (basic_constraints.width.HasMax() || basic_constraints.height.HasMax() || - basic_constraints.width.HasExact() || - basic_constraints.height.HasExact()) { - if (basic_constraints.width.HasMax()) - *desired_width = basic_constraints.width.Max(); - if (basic_constraints.height.HasMax()) - *desired_height = basic_constraints.height.Max(); - // Exact constraints override max constraints if both are specified. - // Specifying both in the same structure is meaningless. - if (basic_constraints.width.HasExact()) - *desired_width = basic_constraints.width.Exact(); - if (basic_constraints.height.HasExact()) - *desired_height = basic_constraints.height.Exact(); - return; - } - - for (const auto& constraint_set : constraints.Advanced()) { - if (constraint_set.width.HasMax()) - *desired_width = constraint_set.width.Max(); - if (constraint_set.height.HasMax()) - *desired_height = constraint_set.height.Max(); - if (constraint_set.width.HasExact()) - *desired_width = constraint_set.width.Exact(); - if (constraint_set.height.HasExact()) - *desired_height = constraint_set.height.Exact(); - } -} - -// Retrieve the desired max and min aspect ratio from |constraints|. If not set, -// the |min_aspect_ratio| is set to 0 and |max_aspect_ratio| is set to -// std::numeric_limits::max(); -// If either min or max aspect ratio is set as a mandatory constraint, the -// optional constraints are not checked. -void GetDesiredMinAndMaxAspectRatio( - const blink::WebMediaConstraints& constraints, - double* min_aspect_ratio, - double* max_aspect_ratio) { - *min_aspect_ratio = 0; - *max_aspect_ratio = std::numeric_limits::max(); - - if (constraints.Basic().aspect_ratio.HasMin() || - constraints.Basic().aspect_ratio.HasMax()) { - if (constraints.Basic().aspect_ratio.HasMin()) - *min_aspect_ratio = constraints.Basic().aspect_ratio.Min(); - if (constraints.Basic().aspect_ratio.HasMax()) - *max_aspect_ratio = constraints.Basic().aspect_ratio.Max(); - return; - // Note - the code will ignore attempts at successive refinement - // of the aspect ratio with advanced constraint. This may be wrong. - } - // Note - the code below will potentially pick min and max from different - // constraint sets, some of which might have been ignored. - for (const auto& constraint_set : constraints.Advanced()) { - if (constraint_set.aspect_ratio.HasMin()) { - *min_aspect_ratio = constraint_set.aspect_ratio.Min(); - break; - } - } - for (const auto& constraint_set : constraints.Advanced()) { - // Advanced constraint sets with max aspect ratio 0 are unsatisfiable and - // must be ignored. - if (constraint_set.aspect_ratio.HasMax() && - constraint_set.aspect_ratio.Max() > 0) { - *max_aspect_ratio = constraint_set.aspect_ratio.Max(); - break; - } - } -} - -// Returns true if |constraints| are fulfilled. |format| can be changed by a -// constraint, e.g. the frame rate can be changed by setting maxFrameRate. -bool UpdateFormatForConstraints( - const blink::WebMediaTrackConstraintSet& constraints, - media::VideoCaptureFormat* format, - std::string* failing_constraint_name) { - DCHECK(format != NULL); - - if (!format->IsValid()) - return false; - - // The width and height are matched based on cropping occuring later: - // min width/height has to be >= the size of the frame (no upscale). - // max width/height just has to be > 0 (we can crop anything too large). - if ((constraints.width.HasMin() && - constraints.width.Min() > format->frame_size.width()) || - (constraints.width.HasMax() && constraints.width.Max() <= 0) || - (constraints.width.HasExact() && - constraints.width.Exact() > format->frame_size.width())) { - *failing_constraint_name = constraints.width.GetName(); - } else if ((constraints.height.HasMin() && - constraints.height.Min() > format->frame_size.height()) || - (constraints.height.HasMax() && constraints.height.Max() <= 0) || - (constraints.height.HasExact() && - constraints.height.Exact() > format->frame_size.height())) { - *failing_constraint_name = constraints.height.GetName(); - } else if (constraints.video_kind.HasExact() && - !constraints.video_kind.Matches(GetVideoKindForFormat(*format))) { - *failing_constraint_name = constraints.video_kind.GetName(); - } else if (!constraints.frame_rate.Matches(format->frame_rate)) { - if (constraints.frame_rate.HasMax()) { - const double value = constraints.frame_rate.Max(); - // TODO(hta): Check if handling of max = 0.0 is relevant. - // (old handling was to set rate to 1.0 if 0.0 was specified) - if (constraints.frame_rate.Matches(value)) { - format->frame_rate = - (format->frame_rate > value) ? value : format->frame_rate; - return true; - } - } - *failing_constraint_name = constraints.frame_rate.GetName(); - } else { - return true; - } - - DCHECK(!failing_constraint_name->empty()); - return false; -} - -// Removes media::VideoCaptureFormats from |formats| that don't meet -// |constraints|. -void FilterFormatsByConstraints( - const blink::WebMediaTrackConstraintSet& constraints, - media::VideoCaptureFormats* formats, - std::string* failing_constraint_name) { - media::VideoCaptureFormats::iterator format_it = formats->begin(); - while (format_it != formats->end()) { - // Modify |format_it| to fulfill the constraint if possible. - // Delete it otherwise. - if (!UpdateFormatForConstraints(constraints, &(*format_it), - failing_constraint_name)) { - DVLOG(2) << "Format filter: Discarding format " - << format_it->frame_size.width() << "x" - << format_it->frame_size.height() << "@" - << format_it->frame_rate; - format_it = formats->erase(format_it); - } else { - ++format_it; - } - } -} - -// Returns the media::VideoCaptureFormats that matches |constraints|. -// If the return value is empty, and the reason is a specific constraint, -// |unsatisfied_constraint| returns the name of the constraint. -media::VideoCaptureFormats FilterFormats( - const blink::WebMediaConstraints& constraints, - const media::VideoCaptureFormats& supported_formats, - std::string* unsatisfied_constraint) { - if (constraints.IsNull()) - return supported_formats; - - const auto& basic = constraints.Basic(); - - // Do some checks that won't be done when filtering candidates. - - if (basic.width.HasMin() && basic.width.HasMax() && - basic.width.Min() > basic.width.Max()) { - *unsatisfied_constraint = basic.width.GetName(); - return media::VideoCaptureFormats(); - } - - if (basic.height.HasMin() && basic.height.HasMax() && - basic.height.Min() > basic.height.Max()) { - *unsatisfied_constraint = basic.height.GetName(); - return media::VideoCaptureFormats(); - } - - double max_aspect_ratio; - double min_aspect_ratio; - GetDesiredMinAndMaxAspectRatio(constraints, - &min_aspect_ratio, - &max_aspect_ratio); - - if (min_aspect_ratio > max_aspect_ratio || max_aspect_ratio < 0.05f) { - DLOG(WARNING) << "Wrong requested aspect ratio: min " << min_aspect_ratio - << " max " << max_aspect_ratio; - *unsatisfied_constraint = basic.aspect_ratio.GetName(); - return media::VideoCaptureFormats(); - } - - std::vector temp( - &kLegalVideoConstraints[0], - &kLegalVideoConstraints[sizeof(kLegalVideoConstraints) / - sizeof(kLegalVideoConstraints[0])]); - std::string failing_name; - if (basic.HasMandatoryOutsideSet(temp, failing_name)) { - *unsatisfied_constraint = failing_name; - return media::VideoCaptureFormats(); - } - - media::VideoCaptureFormats candidates = supported_formats; - FilterFormatsByConstraints(basic, &candidates, unsatisfied_constraint); - - if (candidates.empty()) - return candidates; - - // Ok - all mandatory checked and we still have candidates. - // Let's try filtering using the advanced constraints. The advanced - // constraints must be filtered in the order they occur in |advanced|. - // But if a constraint produce zero candidates, the constraint is ignored and - // the next constraint is tested. - // http://w3c.github.io/mediacapture-main/getusermedia.html#dfn-selectsettings - for (const auto& constraint_set : constraints.Advanced()) { - media::VideoCaptureFormats current_candidates = candidates; - std::string unsatisfied_constraint; - FilterFormatsByConstraints(constraint_set, ¤t_candidates, - &unsatisfied_constraint); - if (!current_candidates.empty()) - candidates = current_candidates; - } - - // We have done as good as we can to filter the supported resolutions. - return candidates; -} - -media::VideoCaptureFormat GetBestFormatBasedOnArea( - const media::VideoCaptureFormats& formats, - int area) { - DCHECK(!formats.empty()); - const media::VideoCaptureFormat* best_format = nullptr; - int best_diff = std::numeric_limits::max(); - for (const auto& format : formats) { - const int diff = abs(area - format.frame_size.GetArea()); - if (diff < best_diff) { - best_diff = diff; - best_format = &format; - } - } - DVLOG(3) << "GetBestFormatBasedOnArea chose format " - << media::VideoCaptureFormat::ToString(*best_format); - return *best_format; -} - -// Find the format that best matches the default video size. -// This algorithm is chosen since a resolution must be picked even if no -// constraints are provided. We don't just select the maximum supported -// resolution since higher resolutions cost more in terms of complexity and -// many cameras have lower frame rate and have more noise in the image at -// their maximum supported resolution. -media::VideoCaptureFormat GetBestCaptureFormat( - const media::VideoCaptureFormats& formats, - const blink::WebMediaConstraints& constraints) { - DCHECK(!formats.empty()); - - int max_width; - int max_height; - GetDesiredMaxWidthAndHeight(constraints, &max_width, &max_height); - const int area = - std::min(max_width, - static_cast(MediaStreamVideoSource::kDefaultWidth)) * - std::min(max_height, - static_cast(MediaStreamVideoSource::kDefaultHeight)); - - return GetBestFormatBasedOnArea(formats, area); -} - -} // anonymous namespace - -bool IsOldVideoConstraints() { - return base::FeatureList::IsEnabled( - features::kMediaStreamOldVideoConstraints); -} - // static MediaStreamVideoSource* MediaStreamVideoSource::GetVideoSource( const blink::WebMediaStreamSource& source) { @@ -336,62 +43,6 @@ MediaStreamVideoSource::~MediaStreamVideoSource() { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); } -void MediaStreamVideoSource::AddTrackLegacy( - MediaStreamVideoTrack* track, - const VideoCaptureDeliverFrameCB& frame_callback, - const blink::WebMediaConstraints& constraints, - const ConstraintsCallback& callback) { - DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - DCHECK(IsOldVideoConstraints()); - DCHECK(!constraints.IsNull()); - DCHECK(std::find(tracks_.begin(), tracks_.end(), track) == tracks_.end()); - tracks_.push_back(track); - secure_tracker_.Add(track, true); - - track_descriptors_.push_back( - TrackDescriptor(track, frame_callback, constraints, callback)); - - switch (state_) { - case NEW: { - // Tab capture and Screen capture needs the maximum requested height - // and width to decide on the resolution. - // NOTE: Optional constraints are deliberately ignored. - int max_requested_width = 0; - if (constraints.Basic().width.HasMax()) - max_requested_width = constraints.Basic().width.Max(); - - int max_requested_height = 0; - if (constraints.Basic().height.HasMax()) - max_requested_height = constraints.Basic().height.Max(); - - double max_requested_frame_rate = kDefaultFrameRate; - if (constraints.Basic().frame_rate.HasMax()) - max_requested_frame_rate = constraints.Basic().frame_rate.Max(); - - state_ = RETRIEVING_CAPABILITIES; - GetCurrentSupportedFormats( - max_requested_width, - max_requested_height, - max_requested_frame_rate, - base::Bind(&MediaStreamVideoSource::OnSupportedFormats, - weak_factory_.GetWeakPtr())); - - break; - } - case STARTING: - case RETRIEVING_CAPABILITIES: { - // The |callback| will be triggered once the source has started or - // the capabilities have been retrieved. - break; - } - case ENDED: - case STARTED: { - // Currently, reconfiguring the source is not supported. - FinalizeAddTrackLegacy(); - } - } -} - void MediaStreamVideoSource::AddTrack( MediaStreamVideoTrack* track, const VideoTrackAdapterSettings& track_adapter_settings, @@ -419,10 +70,6 @@ void MediaStreamVideoSource::AddTrack( case STARTING: { break; } - case RETRIEVING_CAPABILITIES: { - NOTREACHED(); - break; - } case ENDED: case STARTED: { // Currently, reconfiguring the source is not supported. @@ -485,13 +132,7 @@ base::SingleThreadTaskRunner* MediaStreamVideoSource::io_task_runner() const { base::Optional MediaStreamVideoSource::GetCurrentFormat() const { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - if (IsOldVideoConstraints()) { - if (state_ == STARTING || state_ == STARTED) - return current_format_; - return base::Optional(); - } else { - return GetCurrentFormatImpl(); - } + return GetCurrentFormatImpl(); } base::Optional @@ -510,76 +151,6 @@ void MediaStreamVideoSource::DoStopSource() { SetReadyState(blink::WebMediaStreamSource::kReadyStateEnded); } -void MediaStreamVideoSource::OnSupportedFormats( - const media::VideoCaptureFormats& formats) { - DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - DCHECK(IsOldVideoConstraints()); - DCHECK_EQ(RETRIEVING_CAPABILITIES, state_); - - supported_formats_ = formats; - blink::WebMediaConstraints fulfilled_constraints; - if (!FindBestFormatWithConstraints(supported_formats_, - ¤t_format_, - &fulfilled_constraints)) { - SetReadyState(blink::WebMediaStreamSource::kReadyStateEnded); - DVLOG(3) << "OnSupportedFormats failed to find an usable format"; - // This object can be deleted after calling FinalizeAddTrack. See comment - // in the header file. - FinalizeAddTrackLegacy(); - return; - } - - state_ = STARTING; - DVLOG(3) << "Starting the capturer with " - << media::VideoCaptureFormat::ToString(current_format_); - - StartSourceImpl( - current_format_, - fulfilled_constraints, - base::Bind(&VideoTrackAdapter::DeliverFrameOnIO, track_adapter_)); -} - -bool MediaStreamVideoSource::FindBestFormatWithConstraints( - const media::VideoCaptureFormats& formats, - media::VideoCaptureFormat* best_format, - blink::WebMediaConstraints* fulfilled_constraints) { - DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - DVLOG(3) << "MediaStreamVideoSource::FindBestFormatWithConstraints " - << "with " << formats.size() << " formats"; - // Find the first track descriptor that can fulfil the constraints. - for (const auto& track : track_descriptors_) { - const blink::WebMediaConstraints& track_constraints = track.constraints; - - // If the source doesn't support capability enumeration it is still ok if - // no mandatory constraints have been specified. That just means that - // we will start with whatever format is native to the source. - if (formats.empty() && !HasMandatoryConstraints(track_constraints)) { - DVLOG(3) << "No mandatory constraints and no formats"; - *fulfilled_constraints = track_constraints; - *best_format = media::VideoCaptureFormat(); - return true; - } - std::string unsatisfied_constraint; - const media::VideoCaptureFormats filtered_formats = - FilterFormats(track_constraints, formats, &unsatisfied_constraint); - if (filtered_formats.empty()) - continue; - - // A request with constraints that can be fulfilled. - *fulfilled_constraints = track_constraints; - media::VideoCaptureFormat best_format_candidate = - GetBestCaptureFormat(filtered_formats, track_constraints); - if (!best_format_candidate.IsValid()) - continue; - - *best_format = best_format_candidate; - DVLOG(3) << "Found a track that matches the constraints"; - return true; - } - DVLOG(3) << "No usable format found"; - return false; -} - void MediaStreamVideoSource::OnStartDone(MediaStreamRequestResult result) { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DVLOG(3) << "OnStartDone({result =" << result << "})"; @@ -598,76 +169,11 @@ void MediaStreamVideoSource::OnStartDone(MediaStreamRequestResult result) { // This object can be deleted after calling FinalizeAddTrack. See comment in // the header file. - if (IsOldVideoConstraints()) - FinalizeAddTrackLegacy(); - else - FinalizeAddTrack(); -} - -void MediaStreamVideoSource::FinalizeAddTrackLegacy() { - DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - DCHECK(IsOldVideoConstraints()); - const media::VideoCaptureFormats formats(1, current_format_); - - std::vector track_descriptors; - track_descriptors.swap(track_descriptors_); - for (const auto& track : track_descriptors) { - MediaStreamRequestResult result = MEDIA_DEVICE_OK; - std::string unsatisfied_constraint; - - if (HasMandatoryConstraints(track.constraints) && - FilterFormats(track.constraints, formats, &unsatisfied_constraint) - .empty()) { - result = MEDIA_DEVICE_CONSTRAINT_NOT_SATISFIED; - DVLOG(3) << "FinalizeAddTrackLegacy() ignoring device on constraint " - << unsatisfied_constraint; - } - - if (state_ != STARTED && result == MEDIA_DEVICE_OK) - result = MEDIA_DEVICE_TRACK_START_FAILURE; - - if (result == MEDIA_DEVICE_OK) { - int max_width; - int max_height; - GetDesiredMaxWidthAndHeight(track.constraints, &max_width, &max_height); - double max_aspect_ratio; - double min_aspect_ratio; - GetDesiredMinAndMaxAspectRatio(track.constraints, - &min_aspect_ratio, - &max_aspect_ratio); - double max_frame_rate = 0.0f; - // Note: Optional and ideal constraints are ignored; this is - // purely a hard max limit. - if (track.constraints.Basic().frame_rate.HasMax()) - max_frame_rate = track.constraints.Basic().frame_rate.Max(); - - track_adapter_->AddTrack( - track.track, track.frame_callback, - VideoTrackAdapterSettings(max_width, max_height, min_aspect_ratio, - max_aspect_ratio, max_frame_rate, - base::Optional())); - // Calculate resulting frame size if the source delivers frames - // according to the current format. Note: Format may change later. - gfx::Size desired_size; - VideoTrackAdapter::CalculateTargetSize( - false /* is_rotated */, current_format_.frame_size, - gfx::Size(max_width, max_height), min_aspect_ratio, max_aspect_ratio, - &desired_size); - track.track->SetTargetSizeAndFrameRate( - desired_size.width(), desired_size.height(), max_frame_rate); - } - - DVLOG(3) << "FinalizeAddTrackLegacy() result " << result; - - if (!track.callback.is_null()) - track.callback.Run(this, result, - blink::WebString::FromUTF8(unsatisfied_constraint)); - } + FinalizeAddTrack(); } void MediaStreamVideoSource::FinalizeAddTrack() { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - DCHECK(!IsOldVideoConstraints()); std::vector track_descriptors; track_descriptors.swap(track_descriptors_); for (const auto& track : track_descriptors) { @@ -721,18 +227,6 @@ void MediaStreamVideoSource::SetMutedState(bool muted_state) { } } -MediaStreamVideoSource::TrackDescriptor::TrackDescriptor( - MediaStreamVideoTrack* track, - const VideoCaptureDeliverFrameCB& frame_callback, - const blink::WebMediaConstraints& constraints, - const ConstraintsCallback& callback) - : track(track), - frame_callback(frame_callback), - constraints(constraints), - callback(callback) { - DCHECK(IsOldVideoConstraints()); -} - MediaStreamVideoSource::TrackDescriptor::TrackDescriptor( MediaStreamVideoTrack* track, const VideoCaptureDeliverFrameCB& frame_callback, @@ -741,9 +235,7 @@ MediaStreamVideoSource::TrackDescriptor::TrackDescriptor( : track(track), frame_callback(frame_callback), adapter_settings(std::move(adapter_settings)), - callback(callback) { - DCHECK(!IsOldVideoConstraints()); -} + callback(callback) {} MediaStreamVideoSource::TrackDescriptor::TrackDescriptor( TrackDescriptor&& other) = default; diff --git a/content/renderer/media/media_stream_video_source.h b/content/renderer/media/media_stream_video_source.h index 6015caf7198e21..c5f03c63dde63e 100644 --- a/content/renderer/media/media_stream_video_source.h +++ b/content/renderer/media/media_stream_video_source.h @@ -30,8 +30,6 @@ class MediaStreamVideoTrack; class VideoTrackAdapter; struct VideoTrackAdapterSettings; -CONTENT_EXPORT bool IsOldVideoConstraints(); - // MediaStreamVideoSource is an interface used for sending video frames to a // MediaStreamVideoTrack. // http://dev.w3.org/2011/webrtc/editor/getusermedia.html @@ -73,11 +71,6 @@ class CONTENT_EXPORT MediaStreamVideoSource : public MediaStreamSource { const VideoTrackAdapterSettings& track_adapter_settings, const VideoCaptureDeliverFrameCB& frame_callback, const ConstraintsCallback& callback); - // TODO(guidou): Remove this method. http://crbug.com/706408 - void AddTrackLegacy(MediaStreamVideoTrack* track, - const VideoCaptureDeliverFrameCB& frame_callback, - const blink::WebMediaConstraints& constraints, - const ConstraintsCallback& callback); void RemoveTrack(MediaStreamVideoTrack* track); // Called by |track| to notify the source whether it has any paths to a @@ -156,8 +149,6 @@ class CONTENT_EXPORT MediaStreamVideoSource : public MediaStreamSource { enum State { NEW, - // TODO(guidou): Remove this state. http://crbug.com/706408 - RETRIEVING_CAPABILITIES, STARTING, STARTED, ENDED @@ -167,17 +158,6 @@ class CONTENT_EXPORT MediaStreamVideoSource : public MediaStreamSource { SEQUENCE_CHECKER(sequence_checker_); private: - void OnSupportedFormats(const media::VideoCaptureFormats& formats); - - // Finds the first WebMediaConstraints in |track_descriptors_| that allows - // the use of one of the |formats|. |best_format| and |fulfilled_constraints| - // are set to the results of this search-and-match operation. Returns false - // if no WebMediaConstraints allow the use any of the |formats|. - bool FindBestFormatWithConstraints( - const media::VideoCaptureFormats& formats, - media::VideoCaptureFormat* best_format, - blink::WebMediaConstraints* fulfilled_constraints); - // Trigger all cached callbacks from AddTrack. AddTrack is successful // if the capture delegate has started and the constraints provided in // AddTrack match the format that was used to start the device. @@ -186,19 +166,10 @@ class CONTENT_EXPORT MediaStreamVideoSource : public MediaStreamSource { // simply drop the references to the blink source and track which will lead // to this object being deleted. void FinalizeAddTrack(); - // TODO(guidou): Remove this method. http://crbug.com/706408 - void FinalizeAddTrackLegacy(); State state_; - // TODO(guidou): Remove this field. http://crbug.com/706408 - media::VideoCaptureFormat current_format_; - struct TrackDescriptor { - TrackDescriptor(MediaStreamVideoTrack* track, - const VideoCaptureDeliverFrameCB& frame_callback, - const blink::WebMediaConstraints& constraints, - const ConstraintsCallback& callback); TrackDescriptor(MediaStreamVideoTrack* track, const VideoCaptureDeliverFrameCB& frame_callback, std::unique_ptr adapter_settings, @@ -209,8 +180,6 @@ class CONTENT_EXPORT MediaStreamVideoSource : public MediaStreamSource { MediaStreamVideoTrack* track; VideoCaptureDeliverFrameCB frame_callback; - // TODO(guidou): remove this field. http://crbug.com/706408 - blink::WebMediaConstraints constraints; // TODO(guidou): Make |adapter_settings| a regular field instead of a // unique_ptr. std::unique_ptr adapter_settings; @@ -218,8 +187,6 @@ class CONTENT_EXPORT MediaStreamVideoSource : public MediaStreamSource { }; std::vector track_descriptors_; - media::VideoCaptureFormats supported_formats_; - // |track_adapter_| delivers video frames to the tracks on the IO-thread. const scoped_refptr track_adapter_; diff --git a/content/renderer/media/media_stream_video_source_unittest.cc b/content/renderer/media/media_stream_video_source_unittest.cc index 3da29505d4fa7b..b1a9c3ce413258 100644 --- a/content/renderer/media/media_stream_video_source_unittest.cc +++ b/content/renderer/media/media_stream_video_source_unittest.cc @@ -9,11 +9,9 @@ #include "base/run_loop.h" #include "base/strings/string_number_conversions.h" #include "base/strings/utf_string_conversions.h" -#include "base/test/scoped_feature_list.h" #include "base/test/scoped_task_environment.h" #include "build/build_config.h" #include "content/child/child_process.h" -#include "content/public/common/content_features.h" #include "content/renderer/media/media_stream_video_source.h" #include "content/renderer/media/media_stream_video_track.h" #include "content/renderer/media/mock_constraint_factory.h" @@ -50,9 +48,6 @@ class MediaStreamVideoSourceTest : public ::testing::Test { 1000.0, media::PIXEL_FORMAT_I420), false)) { - scoped_feature_list_.InitAndDisableFeature( - features::kMediaStreamOldVideoConstraints); - media::VideoCaptureFormats formats; formats.push_back(media::VideoCaptureFormat(gfx::Size(1280, 720), 30, media::PIXEL_FORMAT_I420)); @@ -105,7 +100,6 @@ class MediaStreamVideoSourceTest : public ::testing::Test { int height, double frame_rate, bool detect_rotation = false) { - DCHECK(!IsOldVideoConstraints()); blink::WebMediaStreamTrack track = CreateTrack("123", VideoTrackAdapterSettings( @@ -141,7 +135,6 @@ class MediaStreamVideoSourceTest : public ::testing::Test { int capture_height, int expected_width, int expected_height) { - DCHECK(!IsOldVideoConstraints()); // Configure the track to crop to the expected resolution. blink::WebMediaStreamTrack track = CreateTrackAndStartSource(expected_width, expected_height, 30.0); @@ -268,7 +261,6 @@ class MediaStreamVideoSourceTest : public ::testing::Test { blink::WebMediaStreamSource webkit_source_; // |mock_source_| is owned by |webkit_source_|. MockMediaStreamVideoSource* mock_source_; - base::test::ScopedFeatureList scoped_feature_list_; }; TEST_F(MediaStreamVideoSourceTest, AddTrackAndStartSource) { @@ -418,850 +410,4 @@ TEST_F(MediaStreamVideoSourceTest, MutedSource) { sink.DisconnectFromTrack(); } -class MediaStreamVideoSourceOldConstraintsTest : public ::testing::Test { - public: - MediaStreamVideoSourceOldConstraintsTest() - : scoped_task_environment_( - base::test::ScopedTaskEnvironment::MainThreadType::UI), - child_process_(new ChildProcess()), - number_of_successful_constraints_applied_(0), - number_of_failed_constraints_applied_(0), - result_(MEDIA_DEVICE_OK), - result_name_(""), - mock_source_(new MockMediaStreamVideoSource(true)) { - scoped_feature_list_.InitAndEnableFeature( - features::kMediaStreamOldVideoConstraints); - - media::VideoCaptureFormats formats; - formats.push_back(media::VideoCaptureFormat( - gfx::Size(1280, 720), 30, media::PIXEL_FORMAT_I420)); - formats.push_back(media::VideoCaptureFormat( - gfx::Size(640, 480), 30, media::PIXEL_FORMAT_I420)); - formats.push_back(media::VideoCaptureFormat( - gfx::Size(352, 288), 30, media::PIXEL_FORMAT_I420)); - formats.push_back(media::VideoCaptureFormat( - gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420)); - mock_source_->SetSupportedFormats(formats); - webkit_source_.Initialize(blink::WebString::FromASCII("dummy_source_id"), - blink::WebMediaStreamSource::kTypeVideo, - blink::WebString::FromASCII("dummy_source_name"), - false /* remote */); - webkit_source_.SetExtraData(mock_source_); - } - - void TearDown() override { - webkit_source_.Reset(); - blink::WebHeap::CollectAllGarbageForTesting(); - } - - protected: - // Create a track that's associated with |webkit_source_|. - blink::WebMediaStreamTrack CreateTrack( - const std::string& id, - const blink::WebMediaConstraints& constraints) { - bool enabled = true; - return MediaStreamVideoTrack::CreateVideoTrack( - mock_source_, constraints, - base::Bind( - &MediaStreamVideoSourceOldConstraintsTest::OnConstraintsApplied, - base::Unretained(this)), - enabled); - } - - blink::WebMediaStreamTrack CreateTrackAndStartSource( - const blink::WebMediaConstraints& constraints, - int expected_width, - int expected_height, - int expected_frame_rate) { - DCHECK(IsOldVideoConstraints()); - blink::WebMediaStreamTrack track = CreateTrack("123", constraints); - - mock_source_->CompleteGetSupportedFormats(); - const media::VideoCaptureFormat& format = mock_source()->start_format(); - EXPECT_EQ(expected_width, format.frame_size.width()); - EXPECT_EQ(expected_height, format.frame_size.height()); - EXPECT_EQ(expected_frame_rate, format.frame_rate); - - EXPECT_EQ(0, NumberOfSuccessConstraintsCallbacks()); - mock_source_->StartMockedSource(); - // Once the source has started successfully we expect that the - // ConstraintsCallback in MediaStreamSource::AddTrack completes. - EXPECT_EQ(1, NumberOfSuccessConstraintsCallbacks()); - return track; - } - - int NumberOfSuccessConstraintsCallbacks() const { - return number_of_successful_constraints_applied_; - } - - int NumberOfFailedConstraintsCallbacks() const { - return number_of_failed_constraints_applied_; - } - - content::MediaStreamRequestResult error_type() const { return result_; } - blink::WebString error_name() const { return result_name_; } - - MockMediaStreamVideoSource* mock_source() { return mock_source_; } - - const blink::WebMediaStreamSource& webkit_source() { return webkit_source_; } - - // Test that the source crops/scales to the requested width and - // height even though the camera delivers a larger frame. - void TestSourceCropFrame(int capture_width, - int capture_height, - const blink::WebMediaConstraints& constraints, - int expected_width, - int expected_height) { - DCHECK(IsOldVideoConstraints()); - // Expect the source to start capture with the supported resolution. - blink::WebMediaStreamTrack track = CreateTrackAndStartSource( - constraints, capture_width, capture_height, 30); - - MockMediaStreamVideoSink sink; - sink.ConnectToTrack(track); - DeliverVideoFrameAndWaitForRenderer(capture_width, capture_height, &sink); - EXPECT_EQ(1, sink.number_of_frames()); - - // Expect the delivered frame to be cropped. - EXPECT_EQ(expected_height, sink.frame_size().height()); - EXPECT_EQ(expected_width, sink.frame_size().width()); - sink.DisconnectFromTrack(); - } - - void DeliverVideoFrameAndWaitForRenderer(int width, int height, - MockMediaStreamVideoSink* sink) { - base::RunLoop run_loop; - base::Closure quit_closure = run_loop.QuitClosure(); - EXPECT_CALL(*sink, OnVideoFrame()).WillOnce( - RunClosure(quit_closure)); - scoped_refptr frame = - media::VideoFrame::CreateBlackFrame(gfx::Size(width, height)); - mock_source()->DeliverVideoFrame(frame); - run_loop.Run(); - } - - void DeliverVideoFrameAndWaitForTwoRenderers( - int width, - int height, - MockMediaStreamVideoSink* sink1, - MockMediaStreamVideoSink* sink2) { - base::RunLoop run_loop; - base::Closure quit_closure = run_loop.QuitClosure(); - EXPECT_CALL(*sink1, OnVideoFrame()); - EXPECT_CALL(*sink2, OnVideoFrame()).WillOnce( - RunClosure(quit_closure)); - scoped_refptr frame = - media::VideoFrame::CreateBlackFrame(gfx::Size(width, height)); - mock_source()->DeliverVideoFrame(frame); - run_loop.Run(); - } - - void TestTwoTracksWithDifferentConstraints( - const blink::WebMediaConstraints& constraints1, - const blink::WebMediaConstraints& constraints2, - int capture_width, - int capture_height, - int expected_width1, - int expected_height1, - int expected_width2, - int expected_height2) { - blink::WebMediaStreamTrack track1 = - CreateTrackAndStartSource(constraints1, capture_width, capture_height, - MediaStreamVideoSource::kDefaultFrameRate); - - blink::WebMediaStreamTrack track2 = CreateTrack("dummy", constraints2); - - MockMediaStreamVideoSink sink1; - sink1.ConnectToTrack(track1); - EXPECT_EQ(0, sink1.number_of_frames()); - - MockMediaStreamVideoSink sink2; - sink2.ConnectToTrack(track2); - EXPECT_EQ(0, sink2.number_of_frames()); - - DeliverVideoFrameAndWaitForTwoRenderers(capture_width, - capture_height, - &sink1, - &sink2); - - EXPECT_EQ(1, sink1.number_of_frames()); - EXPECT_EQ(expected_width1, sink1.frame_size().width()); - EXPECT_EQ(expected_height1, sink1.frame_size().height()); - - EXPECT_EQ(1, sink2.number_of_frames()); - EXPECT_EQ(expected_width2, sink2.frame_size().width()); - EXPECT_EQ(expected_height2, sink2.frame_size().height()); - - sink1.DisconnectFromTrack(); - sink2.DisconnectFromTrack(); - } - - void SetSourceSupportedFormats(const media::VideoCaptureFormats& formats) { - mock_source_->SetSupportedFormats(formats); - } - - void ReleaseTrackAndSourceOnAddTrackCallback( - const blink::WebMediaStreamTrack& track_to_release) { - track_to_release_ = track_to_release; - } - - private: - void OnConstraintsApplied(MediaStreamSource* source, - MediaStreamRequestResult result, - const blink::WebString& result_name) { - ASSERT_EQ(source, webkit_source().GetExtraData()); - - if (result == MEDIA_DEVICE_OK) { - ++number_of_successful_constraints_applied_; - } else { - result_ = result; - result_name_ = result_name; - ++number_of_failed_constraints_applied_; - } - - if (!track_to_release_.IsNull()) { - mock_source_ = nullptr; - webkit_source_.Reset(); - track_to_release_.Reset(); - } - } - const base::test::ScopedTaskEnvironment scoped_task_environment_; - const std::unique_ptr child_process_; - blink::WebMediaStreamTrack track_to_release_; - int number_of_successful_constraints_applied_; - int number_of_failed_constraints_applied_; - content::MediaStreamRequestResult result_; - blink::WebString result_name_; - blink::WebMediaStreamSource webkit_source_; - // |mock_source_| is owned by |webkit_source_|. - MockMediaStreamVideoSource* mock_source_; - base::test::ScopedFeatureList scoped_feature_list_; -}; - -// TODO(guidou): Remove this test. http://crbug.com/706408 -TEST_F(MediaStreamVideoSourceOldConstraintsTest, AddTrackAndStartSource) { - blink::WebMediaConstraints constraints; - constraints.Initialize(); - blink::WebMediaStreamTrack track = CreateTrack("123", constraints); - mock_source()->CompleteGetSupportedFormats(); - mock_source()->StartMockedSource(); - EXPECT_EQ(1, NumberOfSuccessConstraintsCallbacks()); -} - -// TODO(guidou): Remove this test. http://crbug.com/706408 -TEST_F(MediaStreamVideoSourceOldConstraintsTest, - AddTwoTracksBeforeSourceStarts) { - blink::WebMediaConstraints constraints; - constraints.Initialize(); - blink::WebMediaStreamTrack track1 = CreateTrack("123", constraints); - mock_source()->CompleteGetSupportedFormats(); - blink::WebMediaStreamTrack track2 = CreateTrack("123", constraints); - EXPECT_EQ(0, NumberOfSuccessConstraintsCallbacks()); - mock_source()->StartMockedSource(); - EXPECT_EQ(2, NumberOfSuccessConstraintsCallbacks()); -} - -// TODO(guidou): Remove this test. http://crbug.com/706408 -TEST_F(MediaStreamVideoSourceOldConstraintsTest, AddTrackAfterSourceStarts) { - blink::WebMediaConstraints constraints; - constraints.Initialize(); - blink::WebMediaStreamTrack track1 = CreateTrack("123", constraints); - mock_source()->CompleteGetSupportedFormats(); - mock_source()->StartMockedSource(); - EXPECT_EQ(1, NumberOfSuccessConstraintsCallbacks()); - blink::WebMediaStreamTrack track2 = CreateTrack("123", constraints); - EXPECT_EQ(2, NumberOfSuccessConstraintsCallbacks()); -} - -// TODO(guidou): Remove this test. http://crbug.com/706408 -TEST_F(MediaStreamVideoSourceOldConstraintsTest, AddTrackAndFailToStartSource) { - blink::WebMediaConstraints constraints; - constraints.Initialize(); - blink::WebMediaStreamTrack track = CreateTrack("123", constraints); - mock_source()->CompleteGetSupportedFormats(); - mock_source()->FailToStartMockedSource(); - EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); -} - -// Does not apply with spec-compliant constraints. -// TODO(guidou): Remove this test. http://crbug.com/706408 -TEST_F(MediaStreamVideoSourceOldConstraintsTest, - AddTwoTracksBeforeGetSupportedFormats) { - blink::WebMediaConstraints constraints; - constraints.Initialize(); - blink::WebMediaStreamTrack track1 = CreateTrack("123", constraints); - blink::WebMediaStreamTrack track2 = CreateTrack("123", constraints); - mock_source()->CompleteGetSupportedFormats(); - mock_source()->StartMockedSource(); - EXPECT_EQ(2, NumberOfSuccessConstraintsCallbacks()); -} - -// Test that the capture output is CIF if we set max constraints to CIF. -// and the capture device support CIF. -// Does not apply with spec-compliant constraints. -// TODO(guidou): Remove this test. http://crbug.com/706408 -TEST_F(MediaStreamVideoSourceOldConstraintsTest, MandatoryConstraintCif5Fps) { - MockConstraintFactory factory; - factory.basic().width.SetMax(352); - factory.basic().height.SetMax(288); - factory.basic().frame_rate.SetMax(5.0); - - CreateTrackAndStartSource(factory.CreateWebMediaConstraints(), 352, 288, 5); -} - -// Test that the capture output is 720P if the camera support it and the -// optional constraint is set to 720P. -// Does not apply with spec-compliant constraints. -// TODO(guidou): Remove this test. http://crbug.com/706408 -TEST_F(MediaStreamVideoSourceOldConstraintsTest, MandatoryMinVgaOptional720P) { - MockConstraintFactory factory; - factory.basic().width.SetMin(640); - factory.basic().height.SetMin(480); - factory.AddAdvanced().width.SetMin(1280); - factory.AddAdvanced().aspect_ratio.SetMin(1280.0 / 720); - - CreateTrackAndStartSource(factory.CreateWebMediaConstraints(), 1280, 720, 30); -} - -// Test that the capture output is 720P if the camera supports it and the -// mandatory constraint is exactly width 1280. -// Does not apply with spec-compliant constraints. -// TODO(guidou): Remove this test. http://crbug.com/706408 -TEST_F(MediaStreamVideoSourceOldConstraintsTest, MandatoryExact720P) { - MockConstraintFactory factory; - factory.basic().width.SetExact(1280); - CreateTrackAndStartSource(factory.CreateWebMediaConstraints(), 1280, 720, 30); -} - -// Test that the capture output have aspect ratio 4:3 if a mandatory constraint -// require it even if an optional constraint request a higher resolution -// that don't have this aspect ratio. -// TODO(guidou): Remove this test. http://crbug.com/706408 -TEST_F(MediaStreamVideoSourceOldConstraintsTest, MandatoryAspectRatio4To3) { - MockConstraintFactory factory; - factory.basic().width.SetMin(640); - factory.basic().height.SetMin(480); - factory.basic().aspect_ratio.SetMax(640.0 / 480); - factory.AddAdvanced().width.SetMin(1280); - - TestSourceCropFrame(1280, 720, factory.CreateWebMediaConstraints(), 960, 720); -} - -// Test that AddTrack succeeds if the mandatory min aspect ratio it set to 2. -TEST_F(MediaStreamVideoSourceOldConstraintsTest, MandatoryAspectRatio2) { - MockConstraintFactory factory; - factory.basic().aspect_ratio.SetMin(2.0); - - TestSourceCropFrame(MediaStreamVideoSource::kDefaultWidth, - MediaStreamVideoSource::kDefaultHeight, - factory.CreateWebMediaConstraints(), 640, 320); -} - -// Does not apply with spec-compliant constraints. -// TODO(guidou): Remove this test. http://crbug.com/706408 -TEST_F(MediaStreamVideoSourceOldConstraintsTest, - MinAspectRatioLargerThanMaxAspectRatio) { - MockConstraintFactory factory; - factory.basic().aspect_ratio.SetMin(2.0); - factory.basic().aspect_ratio.SetMax(1.0); - blink::WebMediaStreamTrack track = - CreateTrack("123", factory.CreateWebMediaConstraints()); - mock_source()->CompleteGetSupportedFormats(); - EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); -} - -// Does not apply with spec-compliant constraints. -// TODO(guidou): Remove this test. http://crbug.com/706408 -TEST_F(MediaStreamVideoSourceOldConstraintsTest, MinWidthLargerThanMaxWidth) { - MockConstraintFactory factory; - factory.basic().width.SetMin(640); - factory.basic().width.SetMax(320); - blink::WebMediaStreamTrack track = - CreateTrack("123", factory.CreateWebMediaConstraints()); - mock_source()->CompleteGetSupportedFormats(); - EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); -} - -// Does not apply with spec-compliant constraints. -// TODO(guidou): Remove this test. http://crbug.com/706408 -TEST_F(MediaStreamVideoSourceOldConstraintsTest, MinHeightLargerThanMaxHeight) { - MockConstraintFactory factory; - factory.basic().height.SetMin(480); - factory.basic().height.SetMax(360); - - blink::WebMediaStreamTrack track = - CreateTrack("123", factory.CreateWebMediaConstraints()); - mock_source()->CompleteGetSupportedFormats(); - EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); -} - -// Does not apply with spec-compliant constraints. -// TODO(guidou): Remove this test. http://crbug.com/706408 -TEST_F(MediaStreamVideoSourceOldConstraintsTest, - MinFrameRateLargerThanMaxFrameRate) { - MockConstraintFactory factory; - factory.basic().frame_rate.SetMin(25); - factory.basic().frame_rate.SetMax(15); - blink::WebMediaStreamTrack track = - CreateTrack("123", factory.CreateWebMediaConstraints()); - mock_source()->CompleteGetSupportedFormats(); - EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); -} - -// Does not apply with spec-compliant constraints. -// TODO(guidou): Remove this test. http://crbug.com/706408 -TEST_F(MediaStreamVideoSourceOldConstraintsTest, ExactWidthNotSupported) { - MockConstraintFactory factory; - factory.basic().width.SetExact(12000); - blink::WebMediaStreamTrack track = - CreateTrack("123", factory.CreateWebMediaConstraints()); - mock_source()->CompleteGetSupportedFormats(); - EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); -} - -// Does not apply with spec-compliant constraints. -// TODO(guidou): Remove this test. http://crbug.com/706408 -TEST_F(MediaStreamVideoSourceOldConstraintsTest, MinWidthNotSupported) { - MockConstraintFactory factory; - factory.basic().width.SetMin(12000); - blink::WebMediaStreamTrack track = - CreateTrack("123", factory.CreateWebMediaConstraints()); - mock_source()->CompleteGetSupportedFormats(); - EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); -} - -// Test that its safe to release the last reference of a blink track and the -// source during the callback if adding a track succeeds. -// TODO(guidou): Remove this test. http://crbug.com/706408 -TEST_F(MediaStreamVideoSourceOldConstraintsTest, - ReleaseTrackAndSourceOnSuccessCallBack) { - MockConstraintFactory factory; - blink::WebMediaStreamTrack track = - CreateTrack("123", factory.CreateWebMediaConstraints()); - ReleaseTrackAndSourceOnAddTrackCallback(track); - mock_source()->CompleteGetSupportedFormats(); - mock_source()->StartMockedSource(); - EXPECT_EQ(1, NumberOfSuccessConstraintsCallbacks()); -} - -// Test that its safe to release the last reference of a blink track and the -// source during the callback if adding a track fails. -// Does not apply with spec-compliant constraints. -// TODO(guidou): Remove this test. http://crbug.com/706408 -TEST_F(MediaStreamVideoSourceOldConstraintsTest, - ReleaseTrackAndSourceOnFailureCallBack) { - MockConstraintFactory factory; - factory.basic().width.SetMin(99999); - { - blink::WebMediaStreamTrack track = - CreateTrack("123", factory.CreateWebMediaConstraints()); - ReleaseTrackAndSourceOnAddTrackCallback(track); - } - mock_source()->CompleteGetSupportedFormats(); - EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); -} - -// Test that the source ignores an optional aspect ratio that is higher than -// supported. -// Does not apply with spec-compliant constraints. -// TODO(guidou): Remove this test. http://crbug.com/706408 -TEST_F(MediaStreamVideoSourceOldConstraintsTest, OptionalAspectRatioTooHigh) { - MockConstraintFactory factory; - factory.AddAdvanced().aspect_ratio.SetMin(2.0); - blink::WebMediaStreamTrack track = - CreateTrack("123", factory.CreateWebMediaConstraints()); - mock_source()->CompleteGetSupportedFormats(); - - const media::VideoCaptureFormat& format = mock_source()->start_format(); - const double aspect_ratio = static_cast(format.frame_size.width()) / - format.frame_size.height(); - EXPECT_LT(aspect_ratio, 2); -} - -// Test that the source starts video with the default resolution if the -// that is the only supported. -// Does not apply with spec-compliant constraints. -// TODO(guidou): Remove this test. http://crbug.com/706408 -TEST_F(MediaStreamVideoSourceOldConstraintsTest, DefaultCapability) { - media::VideoCaptureFormats formats; - formats.push_back(media::VideoCaptureFormat( - gfx::Size(MediaStreamVideoSource::kDefaultWidth, - MediaStreamVideoSource::kDefaultHeight), - MediaStreamVideoSource::kDefaultFrameRate, media::PIXEL_FORMAT_I420)); - mock_source()->SetSupportedFormats(formats); - - blink::WebMediaConstraints constraints; - constraints.Initialize(); - CreateTrackAndStartSource(constraints, MediaStreamVideoSource::kDefaultWidth, - MediaStreamVideoSource::kDefaultHeight, 30); -} - -// Does not apply with spec-compliant constraints. -// TODO(guidou): Remove this test. http://crbug.com/706408 -TEST_F(MediaStreamVideoSourceOldConstraintsTest, InvalidMandatoryConstraint) { - MockConstraintFactory factory; - // Use a constraint that is only known for audio. - factory.basic().echo_cancellation.SetExact(true); - blink::WebMediaStreamTrack track = - CreateTrack("123", factory.CreateWebMediaConstraints()); - mock_source()->CompleteGetSupportedFormats(); - EXPECT_EQ(MEDIA_DEVICE_CONSTRAINT_NOT_SATISFIED, error_type()); - EXPECT_EQ("echoCancellation", error_name()); - EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); -} - -// Test that the source ignores an unknown optional constraint. -// Does not apply with spec-compliant constraints. -// TODO(guidou): Remove this test. http://crbug.com/706408 -TEST_F(MediaStreamVideoSourceOldConstraintsTest, InvalidOptionalConstraint) { - MockConstraintFactory factory; - factory.AddAdvanced().echo_cancellation.SetExact(true); - - CreateTrackAndStartSource(factory.CreateWebMediaConstraints(), - MediaStreamVideoSource::kDefaultWidth, - MediaStreamVideoSource::kDefaultHeight, 30); -} - -// Tests that the source starts video with the max width and height set by -// constraints for screencast. -// Does not apply with spec-compliant constraints. -// TODO(guidou): Remove this test. http://crbug.com/706408 -TEST_F(MediaStreamVideoSourceOldConstraintsTest, - ScreencastResolutionWithConstraint) { - media::VideoCaptureFormats formats; - formats.push_back(media::VideoCaptureFormat(gfx::Size(480, 270), 30, - media::PIXEL_FORMAT_I420)); - mock_source()->SetSupportedFormats(formats); - MockConstraintFactory factory; - factory.basic().width.SetMax(480); - factory.basic().height.SetMax(270); - - blink::WebMediaStreamTrack track = CreateTrackAndStartSource( - factory.CreateWebMediaConstraints(), 480, 270, 30); - EXPECT_EQ(480, mock_source()->max_requested_height()); - EXPECT_EQ(270, mock_source()->max_requested_width()); -} - -// Test that optional constraints are applied in order. -// Does not apply with spec-compliant constraints. -// TODO(guidou): Remove this test. http://crbug.com/706408 -TEST_F(MediaStreamVideoSourceOldConstraintsTest, OptionalConstraints) { - MockConstraintFactory factory; - // Min width of 2056 pixels can not be fulfilled. - factory.AddAdvanced().width.SetMin(2056); - factory.AddAdvanced().width.SetMin(641); - // Since min width is set to 641 pixels, max width 640 can not be fulfilled. - factory.AddAdvanced().width.SetMax(640); - CreateTrackAndStartSource(factory.CreateWebMediaConstraints(), 1280, 720, 30); -} - -// Test that the source crops to the requested max width and -// height even though the camera delivers a larger frame. -// Redundant with spec-compliant constraints. -// TODO(guidou): Remove this test. http://crbug.com/706408 -TEST_F(MediaStreamVideoSourceOldConstraintsTest, - DeliverCroppedVideoFrameOptional640360) { - MockConstraintFactory factory; - factory.AddAdvanced().width.SetMax(640); - factory.AddAdvanced().height.SetMax(360); - TestSourceCropFrame(640, 480, factory.CreateWebMediaConstraints(), 640, 360); -} - -// Redundant with spec-compliant constraints. -// TODO(guidou): Remove this test. http://crbug.com/706408 -TEST_F(MediaStreamVideoSourceOldConstraintsTest, - DeliverCroppedVideoFrameMandatory640360) { - MockConstraintFactory factory; - factory.basic().width.SetMax(640); - factory.basic().height.SetMax(360); - TestSourceCropFrame(640, 480, factory.CreateWebMediaConstraints(), 640, 360); -} - -// Redundant with spec-compliant constraints. -// TODO(guidou): Remove this test. http://crbug.com/706408 -TEST_F(MediaStreamVideoSourceOldConstraintsTest, - DeliverCroppedVideoFrameMandatory732489) { - MockConstraintFactory factory; - factory.basic().width.SetMax(732); - factory.basic().height.SetMax(489); - factory.basic().width.SetMin(732); - factory.basic().height.SetMin(489); - TestSourceCropFrame(1280, 720, factory.CreateWebMediaConstraints(), 732, 489); -} - -// Test that the source crops to the requested max width and -// height even though the requested frame has odd size. -// Redundant with spec-compliant constraints. -// TODO(guidou): Remove this test. http://crbug.com/706408 -TEST_F(MediaStreamVideoSourceOldConstraintsTest, - DeliverCroppedVideoFrame637359) { - MockConstraintFactory factory; - factory.AddAdvanced().width.SetMax(637); - factory.AddAdvanced().height.SetMax(359); - TestSourceCropFrame(640, 480, factory.CreateWebMediaConstraints(), 637, 359); -} - -// Redundant with spec-compliant constraints. -// TODO(guidou): Remove this test. http://crbug.com/706408 -TEST_F(MediaStreamVideoSourceOldConstraintsTest, - DeliverCroppedVideoFrame320320) { - MockConstraintFactory factory; - factory.basic().width.SetMax(320); - factory.basic().height.SetMax(320); - factory.basic().height.SetMin(320); - factory.basic().width.SetMax(320); - TestSourceCropFrame(640, 480, factory.CreateWebMediaConstraints(), 320, 320); -} - -// Redundant with spec-compliant constraints. -// TODO(guidou): Remove this test. http://crbug.com/706408 -TEST_F(MediaStreamVideoSourceOldConstraintsTest, - DeliverSmallerSizeWhenTooLargeMax) { - MockConstraintFactory factory; - factory.AddAdvanced().width.SetMax(1920); - factory.AddAdvanced().height.SetMax(1080); - factory.AddAdvanced().width.SetMin(1280); - factory.AddAdvanced().height.SetMin(720); - TestSourceCropFrame(1280, 720, factory.CreateWebMediaConstraints(), 1280, - 720); -} - -// TODO(guidou): Remove this test. http://crbug.com/706408 -TEST_F(MediaStreamVideoSourceOldConstraintsTest, TwoTracksWithVGAAndWVGA) { - MockConstraintFactory factory1; - factory1.AddAdvanced().width.SetMax(640); - factory1.AddAdvanced().height.SetMax(480); - - MockConstraintFactory factory2; - factory2.AddAdvanced().height.SetMax(360); - - TestTwoTracksWithDifferentConstraints(factory1.CreateWebMediaConstraints(), - factory2.CreateWebMediaConstraints(), - 640, 480, 640, 480, 640, 360); -} - -// Redundant with spec-compliant constraints -// TODO(guidou): Remove this test. http://crbug.com/706408 -TEST_F(MediaStreamVideoSourceOldConstraintsTest, TwoTracksWith720AndWVGA) { - MockConstraintFactory factory1; - factory1.AddAdvanced().width.SetMin(1280); - factory1.AddAdvanced().height.SetMin(720); - - MockConstraintFactory factory2; - factory2.basic().width.SetMax(640); - factory2.basic().height.SetMax(360); - - TestTwoTracksWithDifferentConstraints(factory1.CreateWebMediaConstraints(), - factory2.CreateWebMediaConstraints(), - 1280, 720, 1280, 720, 640, 360); -} - -// Redundant with spec-compliant constraints -// TODO(guidou): Remove this test. http://crbug.com/706408 -TEST_F(MediaStreamVideoSourceOldConstraintsTest, TwoTracksWith720AndW700H700) { - MockConstraintFactory factory1; - factory1.AddAdvanced().width.SetMin(1280); - factory1.AddAdvanced().height.SetMin(720); - - MockConstraintFactory factory2; - factory2.basic().width.SetMax(700); - factory2.basic().height.SetMax(700); - - TestTwoTracksWithDifferentConstraints(factory1.CreateWebMediaConstraints(), - factory2.CreateWebMediaConstraints(), - 1280, 720, 1280, 720, 700, 700); -} - -// Redundant with spec-compliant constraints -// TODO(guidou): Remove this test. http://crbug.com/706408 -TEST_F(MediaStreamVideoSourceOldConstraintsTest, - TwoTracksWith720AndMaxAspectRatio4To3) { - MockConstraintFactory factory1; - factory1.AddAdvanced().width.SetMin(1280); - factory1.AddAdvanced().height.SetMin(720); - - MockConstraintFactory factory2; - factory2.basic().aspect_ratio.SetMax(640.0 / 480); - - TestTwoTracksWithDifferentConstraints(factory1.CreateWebMediaConstraints(), - factory2.CreateWebMediaConstraints(), - 1280, 720, 1280, 720, 960, 720); -} - -// Redundant with spec-compliant constraints -// TODO(guidou): Remove this test. http://crbug.com/706408 -TEST_F(MediaStreamVideoSourceOldConstraintsTest, - TwoTracksWithVgaAndMinAspectRatio) { - MockConstraintFactory factory1; - factory1.AddAdvanced().width.SetMax(640); - factory1.AddAdvanced().height.SetMax(480); - - MockConstraintFactory factory2; - factory2.basic().aspect_ratio.SetMin(640.0 / 360); - - TestTwoTracksWithDifferentConstraints(factory1.CreateWebMediaConstraints(), - factory2.CreateWebMediaConstraints(), - 640, 480, 640, 480, 640, 360); -} - -// Does not apply with spec-compliant constraints -// TODO(guidou): Remove this test. http://crbug.com/706408 -TEST_F(MediaStreamVideoSourceOldConstraintsTest, - TwoTracksWithSecondTrackFrameRateHigherThanFirst) { - MockConstraintFactory factory1; - factory1.basic().frame_rate.SetMin(15); - factory1.basic().frame_rate.SetMax(15); - - blink::WebMediaStreamTrack track1 = - CreateTrackAndStartSource(factory1.CreateWebMediaConstraints(), - MediaStreamVideoSource::kDefaultWidth, - MediaStreamVideoSource::kDefaultHeight, 15); - - MockConstraintFactory factory2; - factory2.basic().frame_rate.SetMin(30); - blink::WebMediaStreamTrack track2 = - CreateTrack("123", factory2.CreateWebMediaConstraints()); - EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); -} - -// Test that a source can change the frame resolution on the fly and that -// tracks sinks get the new frame size unless constraints force the frame to be -// cropped. -// TODO(guidou): Remove this test. http://crbug.com/706408 -TEST_F(MediaStreamVideoSourceOldConstraintsTest, SourceChangeFrameSize) { - MockConstraintFactory factory; - factory.AddAdvanced().width.SetMax(800); - factory.AddAdvanced().height.SetMax(700); - - // Expect the source to start capture with the supported resolution. - // Disable frame-rate adjustment in spec-compliant mode to ensure no frames - // are dropped. - blink::WebMediaStreamTrack track = CreateTrackAndStartSource( - factory.CreateWebMediaConstraints(), 640, 480, 30); - - MockMediaStreamVideoSink sink; - sink.ConnectToTrack(track); - EXPECT_EQ(0, sink.number_of_frames()); - DeliverVideoFrameAndWaitForRenderer(320, 240, &sink); - EXPECT_EQ(1, sink.number_of_frames()); - // Expect the delivered frame to be passed unchanged since its smaller than - // max requested. - EXPECT_EQ(320, sink.frame_size().width()); - EXPECT_EQ(240, sink.frame_size().height()); - - DeliverVideoFrameAndWaitForRenderer(640, 480, &sink); - EXPECT_EQ(2, sink.number_of_frames()); - // Expect the delivered frame to be passed unchanged since its smaller than - // max requested. - EXPECT_EQ(640, sink.frame_size().width()); - EXPECT_EQ(480, sink.frame_size().height()); - - DeliverVideoFrameAndWaitForRenderer(1280, 720, &sink); - EXPECT_EQ(3, sink.number_of_frames()); - // Expect a frame to be cropped since its larger than max requested. - EXPECT_EQ(800, sink.frame_size().width()); - EXPECT_EQ(700, sink.frame_size().height()); - - sink.DisconnectFromTrack(); -} - -// Test that the constraint negotiation can handle 0.0 fps as frame rate. -TEST_F(MediaStreamVideoSourceOldConstraintsTest, Use0FpsSupportedFormat) { - media::VideoCaptureFormats formats; - formats.push_back(media::VideoCaptureFormat(gfx::Size(640, 480), 0.0f, - media::PIXEL_FORMAT_I420)); - formats.push_back(media::VideoCaptureFormat(gfx::Size(320, 240), 0.0f, - media::PIXEL_FORMAT_I420)); - mock_source()->SetSupportedFormats(formats); - - blink::WebMediaConstraints constraints; - constraints.Initialize(); - blink::WebMediaStreamTrack track = CreateTrack("123", constraints); - mock_source()->CompleteGetSupportedFormats(); - mock_source()->StartMockedSource(); - EXPECT_EQ(1, NumberOfSuccessConstraintsCallbacks()); - - MockMediaStreamVideoSink sink; - sink.ConnectToTrack(track); - EXPECT_EQ(0, sink.number_of_frames()); - DeliverVideoFrameAndWaitForRenderer(320, 240, &sink); - EXPECT_EQ(1, sink.number_of_frames()); - // Expect the delivered frame to be passed unchanged since its smaller than - // max requested. - EXPECT_EQ(320, sink.frame_size().width()); - EXPECT_EQ(240, sink.frame_size().height()); - sink.DisconnectFromTrack(); -} - -// Test that a source producing no frames change the source ReadyState to muted. -// that in a reasonable time frame the muted state turns to false. -TEST_F(MediaStreamVideoSourceOldConstraintsTest, MutedSource) { - // Setup the source for support a frame rate of 999 fps in order to test - // the muted event faster. This is since the frame monitoring uses - // PostDelayedTask that is dependent on the source frame rate. - // Note that media::limits::kMaxFramesPerSecond is 1000. - media::VideoCaptureFormats formats; - formats.push_back(media::VideoCaptureFormat( - gfx::Size(640, 480), media::limits::kMaxFramesPerSecond - 1, - media::PIXEL_FORMAT_I420)); - SetSourceSupportedFormats(formats); - - MockConstraintFactory factory; - blink::WebMediaStreamTrack track = - CreateTrackAndStartSource(factory.CreateWebMediaConstraints(), 640, 480, - media::limits::kMaxFramesPerSecond - 1); - - MockMediaStreamVideoSink sink; - sink.ConnectToTrack(track); - EXPECT_EQ(track.Source().GetReadyState(), - blink::WebMediaStreamSource::kReadyStateLive); - - base::RunLoop run_loop; - base::Closure quit_closure = run_loop.QuitClosure(); - bool muted_state = false; - EXPECT_CALL(*mock_source(), DoSetMutedState(_)) - .WillOnce(DoAll(SaveArg<0>(&muted_state), RunClosure(quit_closure))); - run_loop.Run(); - EXPECT_EQ(muted_state, true); - - EXPECT_EQ(track.Source().GetReadyState(), - blink::WebMediaStreamSource::kReadyStateMuted); - - base::RunLoop run_loop2; - base::Closure quit_closure2 = run_loop2.QuitClosure(); - EXPECT_CALL(*mock_source(), DoSetMutedState(_)) - .WillOnce(DoAll(SaveArg<0>(&muted_state), RunClosure(quit_closure2))); - DeliverVideoFrameAndWaitForRenderer(640, 480, &sink); - run_loop2.Run(); - - EXPECT_EQ(muted_state, false); - EXPECT_EQ(track.Source().GetReadyState(), - blink::WebMediaStreamSource::kReadyStateLive); - - sink.DisconnectFromTrack(); -} - -// Test that an optional constraint with an invalid aspect ratio is ignored. -TEST_F(MediaStreamVideoSourceOldConstraintsTest, - InvalidOptionalAspectRatioIgnored) { - MockConstraintFactory factory; - factory.AddAdvanced().aspect_ratio.SetMax(0.0); - blink::WebMediaStreamTrack track = - CreateTrack("123", factory.CreateWebMediaConstraints()); - mock_source()->CompleteGetSupportedFormats(); - EXPECT_EQ(0, NumberOfFailedConstraintsCallbacks()); -} - -// Test that setting an invalid mandatory aspect ratio fails. -// Does not apply with spec-compliant constraints. -TEST_F(MediaStreamVideoSourceOldConstraintsTest, - InvalidMandatoryAspectRatioFails) { - MockConstraintFactory factory; - factory.basic().aspect_ratio.SetMax(0.0); - blink::WebMediaStreamTrack track = - CreateTrack("123", factory.CreateWebMediaConstraints()); - mock_source()->CompleteGetSupportedFormats(); - EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); -} - } // namespace content diff --git a/content/renderer/media/media_stream_video_track.cc b/content/renderer/media/media_stream_video_track.cc index d23adb2d19126a..6dce6ab9c48375 100644 --- a/content/renderer/media/media_stream_video_track.cc +++ b/content/renderer/media/media_stream_video_track.cc @@ -197,20 +197,6 @@ MediaStreamVideoTrack::FrameDeliverer::GetBlackFrame( return wrapped_black_frame; } -// static -blink::WebMediaStreamTrack MediaStreamVideoTrack::CreateVideoTrack( - MediaStreamVideoSource* source, - const blink::WebMediaConstraints& constraints, - const MediaStreamVideoSource::ConstraintsCallback& callback, - bool enabled) { - DCHECK(IsOldVideoConstraints()); - blink::WebMediaStreamTrack track; - track.Initialize(source->Owner()); - track.SetTrackData( - new MediaStreamVideoTrack(source, constraints, callback, enabled)); - return track; -} - // static blink::WebMediaStreamTrack MediaStreamVideoTrack::CreateVideoTrack( MediaStreamVideoSource* source, @@ -261,41 +247,11 @@ MediaStreamVideoTrack::MediaStreamVideoTrack( VideoTrackAdapterSettings())), is_screencast_(false), source_(source->GetWeakPtr()) { - if (IsOldVideoConstraints()) { - blink::WebMediaConstraints constraints; - constraints.Initialize(); - source->AddTrackLegacy( - this, - base::Bind(&MediaStreamVideoTrack::FrameDeliverer::DeliverFrameOnIO, - frame_deliverer_), - constraints, callback); - } else { - source->AddTrack( - this, VideoTrackAdapterSettings(), - base::Bind(&MediaStreamVideoTrack::FrameDeliverer::DeliverFrameOnIO, - frame_deliverer_), - callback); - } -} - -MediaStreamVideoTrack::MediaStreamVideoTrack( - MediaStreamVideoSource* source, - const blink::WebMediaConstraints& constraints, - const MediaStreamVideoSource::ConstraintsCallback& callback, - bool enabled) - : MediaStreamTrack(true), - frame_deliverer_( - new MediaStreamVideoTrack::FrameDeliverer(source->io_task_runner(), - enabled)), - constraints_(constraints), - source_(source->GetWeakPtr()) { - DCHECK(IsOldVideoConstraints()); - DCHECK(!constraints.IsNull()); - source->AddTrackLegacy( - this, + source->AddTrack( + this, VideoTrackAdapterSettings(), base::Bind(&MediaStreamVideoTrack::FrameDeliverer::DeliverFrameOnIO, frame_deliverer_), - constraints, callback); + callback); } MediaStreamVideoTrack::MediaStreamVideoTrack( @@ -316,7 +272,6 @@ MediaStreamVideoTrack::MediaStreamVideoTrack( is_screencast_(is_screen_cast), min_frame_rate_(min_frame_rate), source_(source->GetWeakPtr()) { - DCHECK(!IsOldVideoConstraints()); source->AddTrack( this, adapter_settings, base::Bind(&MediaStreamVideoTrack::FrameDeliverer::DeliverFrameOnIO, diff --git a/content/renderer/media/media_stream_video_track.h b/content/renderer/media/media_stream_video_track.h index 5bd53b5ab1d3ba..581d78dd63d74c 100644 --- a/content/renderer/media/media_stream_video_track.h +++ b/content/renderer/media/media_stream_video_track.h @@ -36,17 +36,10 @@ class CONTENT_EXPORT MediaStreamVideoTrack : public MediaStreamTrack { // or if the source fails to provide video frames. // If |enabled| is true, sinks added to the track will // receive video frames when the source delivers frames to the track. - // TODO(guidou): Remove the variant that takes a |constraints| argument. - // http://crbug.com/706408 static blink::WebMediaStreamTrack CreateVideoTrack( MediaStreamVideoSource* source, const MediaStreamVideoSource::ConstraintsCallback& callback, bool enabled); - static blink::WebMediaStreamTrack CreateVideoTrack( - MediaStreamVideoSource* source, - const blink::WebMediaConstraints& constraints, - const MediaStreamVideoSource::ConstraintsCallback& callback, - bool enabled); static blink::WebMediaStreamTrack CreateVideoTrack( MediaStreamVideoSource* source, const VideoTrackAdapterSettings& adapter_settings, @@ -60,15 +53,8 @@ class CONTENT_EXPORT MediaStreamVideoTrack : public MediaStreamTrack { const blink::WebMediaStreamTrack& track); // Constructors for video tracks. - // TODO(guidou): Remove the variant that takes a |constraints| argument. - // http://crbug.com/706408 - MediaStreamVideoTrack( - MediaStreamVideoSource* source, - const MediaStreamVideoSource::ConstraintsCallback& callback, - bool enabled); MediaStreamVideoTrack( MediaStreamVideoSource* source, - const blink::WebMediaConstraints& constraints, const MediaStreamVideoSource::ConstraintsCallback& callback, bool enabled); MediaStreamVideoTrack( @@ -90,28 +76,19 @@ class CONTENT_EXPORT MediaStreamVideoTrack : public MediaStreamTrack { void OnReadyStateChanged(blink::WebMediaStreamSource::ReadyState state); - const blink::WebMediaConstraints& constraints() const { - DCHECK(IsOldVideoConstraints()); - return constraints_; - } const base::Optional& noise_reduction() const { - DCHECK(!IsOldVideoConstraints()); return noise_reduction_; } bool is_screencast() const { - DCHECK(!IsOldVideoConstraints()); return is_screencast_; } const base::Optional& min_frame_rate() const { - DCHECK(!IsOldVideoConstraints()); return min_frame_rate_; } const base::Optional& max_frame_rate() const { - DCHECK(!IsOldVideoConstraints()); return max_frame_rate_; } const VideoTrackAdapterSettings& adapter_settings() const { - DCHECK(!IsOldVideoConstraints()); return *adapter_settings_; } @@ -149,9 +126,6 @@ class CONTENT_EXPORT MediaStreamVideoTrack : public MediaStreamTrack { class FrameDeliverer; const scoped_refptr frame_deliverer_; - // TODO(guidou): remove this field. http://crbug.com/706408 - const blink::WebMediaConstraints constraints_; - // TODO(guidou): Make this field a regular field instead of a unique_ptr. std::unique_ptr adapter_settings_; base::Optional noise_reduction_; diff --git a/content/renderer/media/media_stream_video_track_unittest.cc b/content/renderer/media/media_stream_video_track_unittest.cc index b82549d4ed881e..32c0ff0231171b 100644 --- a/content/renderer/media/media_stream_video_track_unittest.cc +++ b/content/renderer/media/media_stream_video_track_unittest.cc @@ -10,10 +10,8 @@ #include "base/message_loop/message_loop.h" #include "base/run_loop.h" #include "base/strings/utf_string_conversions.h" -#include "base/test/scoped_feature_list.h" #include "base/threading/thread_checker_impl.h" #include "content/child/child_process.h" -#include "content/public/common/content_features.h" #include "content/renderer/media/media_stream_video_track.h" #include "content/renderer/media/mock_media_stream_video_sink.h" #include "content/renderer/media/mock_media_stream_video_source.h" @@ -38,10 +36,7 @@ class MediaStreamVideoTrackTest : public ::testing::Test { MediaStreamVideoTrackTest() : child_process_(new ChildProcess()), mock_source_(nullptr), - source_started_(false) { - scoped_feature_list_.InitAndDisableFeature( - features::kMediaStreamOldVideoConstraints); - } + source_started_(false) {} ~MediaStreamVideoTrackTest() override {} @@ -70,13 +65,11 @@ class MediaStreamVideoTrackTest : public ::testing::Test { void InitializeSource() { blink_source_.Reset(); - mock_source_ = IsOldVideoConstraints() - ? new MockMediaStreamVideoSource(false) - : new MockMediaStreamVideoSource( - media::VideoCaptureFormat( - gfx::Size(kMockSourceWidth, kMockSourceHeight), - 30.0, media::PIXEL_FORMAT_I420), - false); + mock_source_ = new MockMediaStreamVideoSource( + media::VideoCaptureFormat( + gfx::Size(kMockSourceWidth, kMockSourceHeight), 30.0, + media::PIXEL_FORMAT_I420), + false); blink_source_.Initialize(blink::WebString::FromASCII("dummy_source_id"), blink::WebMediaStreamSource::kTypeVideo, blink::WebString::FromASCII("dummy_source_name"), @@ -113,13 +106,11 @@ class MediaStreamVideoTrackTest : public ::testing::Test { void UpdateVideoSourceToRespondToRequestRefreshFrame() { blink_source_.Reset(); - mock_source_ = IsOldVideoConstraints() - ? new MockMediaStreamVideoSource(false, true) - : new MockMediaStreamVideoSource( - media::VideoCaptureFormat( - gfx::Size(kMockSourceWidth, kMockSourceHeight), - 30.0, media::PIXEL_FORMAT_I420), - true); + mock_source_ = new MockMediaStreamVideoSource( + media::VideoCaptureFormat( + gfx::Size(kMockSourceWidth, kMockSourceHeight), 30.0, + media::PIXEL_FORMAT_I420), + true); blink_source_.Initialize(blink::WebString::FromASCII("dummy_source_id"), blink::WebMediaStreamSource::kTypeVideo, blink::WebString::FromASCII("dummy_source_name"), @@ -139,7 +130,6 @@ class MediaStreamVideoTrackTest : public ::testing::Test { // |mock_source_| is owned by |webkit_source_|. MockMediaStreamVideoSource* mock_source_; bool source_started_; - base::test::ScopedFeatureList scoped_feature_list_; }; TEST_F(MediaStreamVideoTrackTest, AddAndRemoveSink) { @@ -348,242 +338,4 @@ TEST_F(MediaStreamVideoTrackTest, GetSettingsStopped) { EXPECT_TRUE(settings.device_id.IsNull()); } -// TODO(guidou): Remove this test. http://crbug.com/706408 -class MediaStreamVideoTrackOldConstraintsTest : public ::testing::Test { - public: - MediaStreamVideoTrackOldConstraintsTest() - : child_process_(new ChildProcess()), - mock_source_(nullptr), - source_started_(false) { - scoped_feature_list_.InitAndEnableFeature( - features::kMediaStreamOldVideoConstraints); - } - - ~MediaStreamVideoTrackOldConstraintsTest() override {} - - void TearDown() override { - blink_source_.Reset(); - blink::WebHeap::CollectAllGarbageForTesting(); - } - - void DeliverVideoFrameAndWaitForRenderer(MockMediaStreamVideoSink* sink) { - base::RunLoop run_loop; - base::Closure quit_closure = run_loop.QuitClosure(); - EXPECT_CALL(*sink, OnVideoFrame()).WillOnce(RunClosure(quit_closure)); - const scoped_refptr frame = - media::VideoFrame::CreateColorFrame( - gfx::Size(MediaStreamVideoSource::kDefaultWidth, - MediaStreamVideoSource::kDefaultHeight), - kColorValue, kColorValue, kColorValue, base::TimeDelta()); - mock_source()->DeliverVideoFrame(frame); - run_loop.Run(); - } - - protected: - base::MessageLoop* io_message_loop() const { - return child_process_->io_message_loop(); - } - - void InitializeSource() { - blink_source_.Reset(); - mock_source_ = IsOldVideoConstraints() - ? new MockMediaStreamVideoSource(false) - : new MockMediaStreamVideoSource( - media::VideoCaptureFormat( - gfx::Size(kMockSourceWidth, kMockSourceHeight), - 30.0, media::PIXEL_FORMAT_I420), - false); - blink_source_.Initialize(blink::WebString::FromASCII("dummy_source_id"), - blink::WebMediaStreamSource::kTypeVideo, - blink::WebString::FromASCII("dummy_source_name"), - false /* remote */); - blink_source_.SetExtraData(mock_source_); - } - - // Create a track that's associated with |mock_source_|. - blink::WebMediaStreamTrack CreateTrack() { - const bool enabled = true; - blink::WebMediaStreamTrack track = MediaStreamVideoTrack::CreateVideoTrack( - mock_source_, MediaStreamSource::ConstraintsCallback(), enabled); - if (!source_started_) { - mock_source_->StartMockedSource(); - source_started_ = true; - } - return track; - } - - void UpdateVideoSourceToRespondToRequestRefreshFrame() { - blink_source_.Reset(); - mock_source_ = IsOldVideoConstraints() - ? new MockMediaStreamVideoSource(false, true) - : new MockMediaStreamVideoSource( - media::VideoCaptureFormat( - gfx::Size(kMockSourceWidth, kMockSourceHeight), - 30.0, media::PIXEL_FORMAT_I420), - true); - blink_source_.Initialize(blink::WebString::FromASCII("dummy_source_id"), - blink::WebMediaStreamSource::kTypeVideo, - blink::WebString::FromASCII("dummy_source_name"), - false /* remote */); - blink_source_.SetExtraData(mock_source_); - } - - MockMediaStreamVideoSource* mock_source() { return mock_source_; } - const blink::WebMediaStreamSource& blink_source() const { - return blink_source_; - } - - private: - const base::MessageLoopForUI message_loop_; - const std::unique_ptr child_process_; - blink::WebMediaStreamSource blink_source_; - // |mock_source_| is owned by |webkit_source_|. - MockMediaStreamVideoSource* mock_source_; - bool source_started_; - base::test::ScopedFeatureList scoped_feature_list_; -}; - -TEST_F(MediaStreamVideoTrackOldConstraintsTest, AddAndRemoveSink) { - InitializeSource(); - MockMediaStreamVideoSink sink; - blink::WebMediaStreamTrack track = CreateTrack(); - sink.ConnectToTrack(track); - - DeliverVideoFrameAndWaitForRenderer(&sink); - EXPECT_EQ(1, sink.number_of_frames()); - - DeliverVideoFrameAndWaitForRenderer(&sink); - - sink.DisconnectFromTrack(); - - scoped_refptr frame = media::VideoFrame::CreateBlackFrame( - gfx::Size(MediaStreamVideoSource::kDefaultWidth, - MediaStreamVideoSource::kDefaultHeight)); - mock_source()->DeliverVideoFrame(frame); - // Wait for the IO thread to complete delivering frames. - base::RunLoop().RunUntilIdle(); - EXPECT_EQ(2, sink.number_of_frames()); -} - -// Checks that the callback given to the track is reset on the right thread. -TEST_F(MediaStreamVideoTrackOldConstraintsTest, ResetCallbackOnThread) { - InitializeSource(); - MockMediaStreamVideoSink sink; - blink::WebMediaStreamTrack track = CreateTrack(); - - base::RunLoop run_loop; - bool correct = false; - sink.ConnectToTrackWithCallback( - track, base::Bind(&CheckThreadVideoFrameReceiver, - base::Owned(new CheckThreadHelper( - run_loop.QuitClosure(), &correct)))); - sink.DisconnectFromTrack(); - run_loop.Run(); - EXPECT_TRUE(correct) << "Not called on correct thread."; -} - -TEST_F(MediaStreamVideoTrackOldConstraintsTest, SetEnabled) { - InitializeSource(); - MockMediaStreamVideoSink sink; - blink::WebMediaStreamTrack track = CreateTrack(); - sink.ConnectToTrack(track); - - MediaStreamVideoTrack* video_track = - MediaStreamVideoTrack::GetVideoTrack(track); - - DeliverVideoFrameAndWaitForRenderer(&sink); - EXPECT_EQ(1, sink.number_of_frames()); - EXPECT_EQ(kColorValue, *sink.last_frame()->data(media::VideoFrame::kYPlane)); - - video_track->SetEnabled(false); - EXPECT_FALSE(sink.enabled()); - - DeliverVideoFrameAndWaitForRenderer(&sink); - EXPECT_EQ(2, sink.number_of_frames()); - EXPECT_EQ(kBlackValue, *sink.last_frame()->data(media::VideoFrame::kYPlane)); - - video_track->SetEnabled(true); - EXPECT_TRUE(sink.enabled()); - DeliverVideoFrameAndWaitForRenderer(&sink); - EXPECT_EQ(3, sink.number_of_frames()); - EXPECT_EQ(kColorValue, *sink.last_frame()->data(media::VideoFrame::kYPlane)); - sink.DisconnectFromTrack(); -} - -TEST_F(MediaStreamVideoTrackOldConstraintsTest, SourceStopped) { - InitializeSource(); - MockMediaStreamVideoSink sink; - blink::WebMediaStreamTrack track = CreateTrack(); - sink.ConnectToTrack(track); - EXPECT_EQ(blink::WebMediaStreamSource::kReadyStateLive, sink.state()); - - mock_source()->StopSource(); - EXPECT_EQ(blink::WebMediaStreamSource::kReadyStateEnded, sink.state()); - sink.DisconnectFromTrack(); -} - -TEST_F(MediaStreamVideoTrackOldConstraintsTest, StopLastTrack) { - InitializeSource(); - MockMediaStreamVideoSink sink1; - blink::WebMediaStreamTrack track1 = CreateTrack(); - sink1.ConnectToTrack(track1); - EXPECT_EQ(blink::WebMediaStreamSource::kReadyStateLive, sink1.state()); - - EXPECT_EQ(blink::WebMediaStreamSource::kReadyStateLive, - blink_source().GetReadyState()); - - MockMediaStreamVideoSink sink2; - blink::WebMediaStreamTrack track2 = CreateTrack(); - sink2.ConnectToTrack(track2); - EXPECT_EQ(blink::WebMediaStreamSource::kReadyStateLive, sink2.state()); - - MediaStreamVideoTrack* const native_track1 = - MediaStreamVideoTrack::GetVideoTrack(track1); - native_track1->Stop(); - EXPECT_EQ(blink::WebMediaStreamSource::kReadyStateEnded, sink1.state()); - EXPECT_EQ(blink::WebMediaStreamSource::kReadyStateLive, - blink_source().GetReadyState()); - sink1.DisconnectFromTrack(); - - MediaStreamVideoTrack* const native_track2 = - MediaStreamVideoTrack::GetVideoTrack(track2); - native_track2->Stop(); - EXPECT_EQ(blink::WebMediaStreamSource::kReadyStateEnded, sink2.state()); - EXPECT_EQ(blink::WebMediaStreamSource::kReadyStateEnded, - blink_source().GetReadyState()); - sink2.DisconnectFromTrack(); -} - -TEST_F(MediaStreamVideoTrackOldConstraintsTest, - CheckTrackRequestsFrameOldConstraintsOldConstraints) { - UpdateVideoSourceToRespondToRequestRefreshFrame(); - blink::WebMediaStreamTrack track = CreateTrack(); - - // Add sink and expect to get a frame. - MockMediaStreamVideoSink sink; - base::RunLoop run_loop; - base::Closure quit_closure = run_loop.QuitClosure(); - EXPECT_CALL(sink, OnVideoFrame()).WillOnce(RunClosure(quit_closure)); - sink.ConnectToTrack(track); - run_loop.Run(); - EXPECT_EQ(1, sink.number_of_frames()); - - sink.DisconnectFromTrack(); -} - -TEST_F(MediaStreamVideoTrackOldConstraintsTest, GetSettingsOldConstraints) { - InitializeSource(); - blink::WebMediaStreamTrack track = CreateTrack(); - MediaStreamVideoTrack* const native_track = - MediaStreamVideoTrack::GetVideoTrack(track); - blink::WebMediaStreamTrack::Settings settings; - native_track->GetSettings(settings); - // These values come straight from the mock video track implementation. - EXPECT_EQ(640, settings.width); - EXPECT_EQ(480, settings.height); - EXPECT_EQ(30.0, settings.frame_rate); - EXPECT_EQ(blink::WebMediaStreamTrack::FacingMode::kNone, - settings.facing_mode); -} - } // namespace content diff --git a/content/renderer/media/mock_media_stream_registry.cc b/content/renderer/media/mock_media_stream_registry.cc index c775e7cfd5641d..7f10526e358227 100644 --- a/content/renderer/media/mock_media_stream_registry.cc +++ b/content/renderer/media/mock_media_stream_registry.cc @@ -56,34 +56,12 @@ void MockMediaStreamRegistry::Init(const std::string& stream_url) { test_stream_.SetExtraData(new MediaStream()); } -void MockMediaStreamRegistry::AddVideoTrack( - const std::string& track_id, - const blink::WebMediaConstraints& constraints) { - DCHECK(IsOldVideoConstraints()); - blink::WebMediaStreamSource blink_source; - blink_source.Initialize("mock video source id", - blink::WebMediaStreamSource::kTypeVideo, - "mock video source name", false /* remote */); - MockMediaStreamVideoSource* native_source = - new MockMediaStreamVideoSource(false /* manual get supported formats */); - blink_source.SetExtraData(native_source); - blink::WebMediaStreamTrack blink_track; - blink_track.Initialize(blink::WebString::FromUTF8(track_id), blink_source); - - MediaStreamVideoTrack* native_track = new MediaStreamVideoTrack( - native_source, constraints, MediaStreamVideoSource::ConstraintsCallback(), - true /* enabled */); - blink_track.SetTrackData(native_track); - test_stream_.AddTrack(blink_track); -} - void MockMediaStreamRegistry::AddVideoTrack( const std::string& track_id, const VideoTrackAdapterSettings& adapter_settings, const base::Optional& noise_reduction, bool is_screencast, double min_frame_rate) { - DCHECK(!IsOldVideoConstraints()); blink::WebMediaStreamSource blink_source; blink_source.Initialize("mock video source id", blink::WebMediaStreamSource::kTypeVideo, @@ -103,14 +81,8 @@ void MockMediaStreamRegistry::AddVideoTrack( } void MockMediaStreamRegistry::AddVideoTrack(const std::string& track_id) { - if (IsOldVideoConstraints()) { - blink::WebMediaConstraints constraints; - constraints.Initialize(); - AddVideoTrack(track_id, constraints); - } else { - AddVideoTrack(track_id, VideoTrackAdapterSettings(), base::Optional(), - false /* is_screncast */, 0.0 /* min_frame_rate */); - } + AddVideoTrack(track_id, VideoTrackAdapterSettings(), base::Optional(), + false /* is_screncast */, 0.0 /* min_frame_rate */); } void MockMediaStreamRegistry::AddAudioTrack(const std::string& track_id) { diff --git a/content/renderer/media/mock_media_stream_registry.h b/content/renderer/media/mock_media_stream_registry.h index f57ebe94ae02f7..e37dbb5a36d704 100644 --- a/content/renderer/media/mock_media_stream_registry.h +++ b/content/renderer/media/mock_media_stream_registry.h @@ -10,10 +10,6 @@ #include "base/optional.h" #include "content/renderer/media/media_stream_registry_interface.h" -namespace blink { -class WebMediaConstraints; -} - namespace content { struct VideoTrackAdapterSettings; @@ -26,9 +22,6 @@ class MockMediaStreamRegistry final : public MediaStreamRegistryInterface { MockMediaStreamRegistry(); void Init(const std::string& stream_url); - // TODO(guidou): Remove this method. http://crbug.com/706408 - void AddVideoTrack(const std::string& track_id, - const blink::WebMediaConstraints& constraints); void AddVideoTrack(const std::string& track_id, const VideoTrackAdapterSettings& adapter_settings, const base::Optional& noise_reduction, diff --git a/content/renderer/media/mock_media_stream_video_source.cc b/content/renderer/media/mock_media_stream_video_source.cc index f459bf1255c5cf..05070df442a8bf 100644 --- a/content/renderer/media/mock_media_stream_video_source.cc +++ b/content/renderer/media/mock_media_stream_video_source.cc @@ -92,9 +92,6 @@ void MockMediaStreamVideoSource::StartSourceImpl( const blink::WebMediaConstraints& constraints, const VideoCaptureDeliverFrameCB& frame_callback) { DCHECK(frame_callback_.is_null()); - if (IsOldVideoConstraints()) - format_ = format; - attempted_to_start_ = true; frame_callback_ = frame_callback; } diff --git a/content/renderer/media/user_media_client_impl.cc b/content/renderer/media/user_media_client_impl.cc index 96ebd7bdfa3e90..8cdc27b0e21548 100644 --- a/content/renderer/media/user_media_client_impl.cc +++ b/content/renderer/media/user_media_client_impl.cc @@ -1010,11 +1010,6 @@ MediaStreamVideoSource* UserMediaClientImpl::CreateVideoSource( const MediaStreamSource::SourceStoppedCallback& stop_callback) { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK(current_request_info_); - if (IsOldVideoConstraints()) { - return new MediaStreamVideoCapturerSource(stop_callback, device, - render_frame()); - } - DCHECK(current_request_info_->video_capture_settings().HasValue()); return new MediaStreamVideoCapturerSource( stop_callback, device, @@ -1484,13 +1479,6 @@ UserMediaClientImpl::UserMediaRequestInfo::CreateAndStartVideoTrack( DCHECK(native_source); sources_.push_back(source); sources_waiting_for_callback_.push_back(native_source); - if (IsOldVideoConstraints()) { - return MediaStreamVideoTrack::CreateVideoTrack( - native_source, request_.VideoConstraints(), - base::Bind(&UserMediaClientImpl::UserMediaRequestInfo::OnTrackStarted, - AsWeakPtr()), - true); - } return MediaStreamVideoTrack::CreateVideoTrack( native_source, video_capture_settings_.track_adapter_settings(), video_capture_settings_.noise_reduction(), is_video_content_capture_, diff --git a/content/renderer/media/webrtc/media_stream_video_webrtc_sink.cc b/content/renderer/media/webrtc/media_stream_video_webrtc_sink.cc index 1f6f9aa5708e68..24bad310bcadef 100644 --- a/content/renderer/media/webrtc/media_stream_video_webrtc_sink.cc +++ b/content/renderer/media/webrtc/media_stream_video_webrtc_sink.cc @@ -266,51 +266,12 @@ MediaStreamVideoWebRtcSink::MediaStreamVideoWebRtcSink( MediaStreamVideoTrack* video_track = MediaStreamVideoTrack::GetVideoTrack(track); DCHECK(video_track); - rtc::Optional needs_denoising; - bool is_screencast = false; - base::Optional min_frame_rate; - base::Optional max_frame_rate; - - if (IsOldVideoConstraints()) { - const blink::WebMediaConstraints& constraints = video_track->constraints(); - - // Check for presence of mediaStreamSource constraint. The value is ignored. - std::string value; - is_screencast = GetConstraintValueAsString( - constraints, &blink::WebMediaTrackConstraintSet::media_stream_source, - &value); - - // Extract denoising preference, if no value is set this currently falls - // back to a codec-specific default inside webrtc, hence the tri-state of - // {on, off unset}. - // TODO(pbos): Add tests that make sure that googNoiseReduction has properly - // propagated from getUserMedia down to a VideoTrackSource. - bool denoising_value; - if (GetConstraintValueAsBoolean( - constraints, - &blink::WebMediaTrackConstraintSet::goog_noise_reduction, - &denoising_value)) { - needs_denoising = rtc::Optional(denoising_value); - } - double frame_rate_value; - if (GetConstraintMinAsDouble(constraints, - &blink::WebMediaTrackConstraintSet::frame_rate, - &frame_rate_value) && - frame_rate_value >= 0.0) { - min_frame_rate = frame_rate_value; - } - if (GetConstraintMaxAsDouble(constraints, - &blink::WebMediaTrackConstraintSet::frame_rate, - &frame_rate_value) && - frame_rate_value >= 0.0) { - max_frame_rate = frame_rate_value; - } - } else { - needs_denoising = ToRtcOptional(video_track->noise_reduction()); - is_screencast = video_track->is_screencast(); - min_frame_rate = video_track->min_frame_rate(); - max_frame_rate = video_track->max_frame_rate(); - } + + rtc::Optional needs_denoising = + ToRtcOptional(video_track->noise_reduction()); + bool is_screencast = is_screencast = video_track->is_screencast(); + base::Optional min_frame_rate = video_track->min_frame_rate(); + base::Optional max_frame_rate = video_track->max_frame_rate(); // Enable automatic frame refreshes for the screen capture sources, which will // stop producing frames whenever screen content is not changing. Check the diff --git a/content/renderer/media/webrtc/media_stream_video_webrtc_sink_unittest.cc b/content/renderer/media/webrtc/media_stream_video_webrtc_sink_unittest.cc index ed6ea4ef98895d..5fff8785d1a010 100644 --- a/content/renderer/media/webrtc/media_stream_video_webrtc_sink_unittest.cc +++ b/content/renderer/media/webrtc/media_stream_video_webrtc_sink_unittest.cc @@ -4,10 +4,8 @@ #include "content/renderer/media/webrtc/media_stream_video_webrtc_sink.h" -#include "base/test/scoped_feature_list.h" #include "base/test/scoped_task_environment.h" #include "content/child/child_process.h" -#include "content/public/common/content_features.h" #include "content/renderer/media/mock_constraint_factory.h" #include "content/renderer/media/mock_media_stream_registry.h" #include "content/renderer/media/video_track_adapter.h" @@ -21,10 +19,7 @@ class MediaStreamVideoWebRtcSinkTest : public ::testing::Test { public: MediaStreamVideoWebRtcSinkTest() : scoped_task_environment_( - base::test::ScopedTaskEnvironment::MainThreadType::UI) { - scoped_feature_list_.InitAndDisableFeature( - features::kMediaStreamOldVideoConstraints); - } + base::test::ScopedTaskEnvironment::MainThreadType::UI) {} void SetVideoTrack() { registry_.Init("stream URL"); @@ -36,16 +31,6 @@ class MediaStreamVideoWebRtcSinkTest : public ::testing::Test { // no valid format, using the track will cause a crash. } - void SetVideoTrack(blink::WebMediaConstraints constraints) { - registry_.Init("stream URL"); - registry_.AddVideoTrack("test video track", constraints); - blink::WebVector video_tracks; - registry_.test_stream().VideoTracks(video_tracks); - track_ = video_tracks[0]; - // TODO(hta): Verify that track_ is valid. When constraints produce - // no valid format, using the track will cause a crash. - } - void SetVideoTrack(const base::Optional& noise_reduction) { registry_.Init("stream URL"); registry_.AddVideoTrack("test video track", VideoTrackAdapterSettings(), @@ -67,7 +52,6 @@ class MediaStreamVideoWebRtcSinkTest : public ::testing::Test { // and Sources in |registry_| into believing they are on the right threads. base::test::ScopedTaskEnvironment scoped_task_environment_; const ChildProcess child_process_; - base::test::ScopedFeatureList scoped_feature_list_; }; TEST_F(MediaStreamVideoWebRtcSinkTest, NoiseReductionDefaultsToNotSet) { @@ -85,79 +69,5 @@ TEST_F(MediaStreamVideoWebRtcSinkTest, NoiseReductionConstraintPassThrough) { EXPECT_TRUE(*(my_sink.SourceNeedsDenoisingForTesting())); } -// TODO(guidou): Remove this test. http://crbug.com/706408 -class MediaStreamVideoWebRtcSinkOldConstraintsTest : public ::testing::Test { - public: - MediaStreamVideoWebRtcSinkOldConstraintsTest() - : scoped_task_environment_( - base::test::ScopedTaskEnvironment::MainThreadType::UI) { - scoped_feature_list_.InitAndEnableFeature( - features::kMediaStreamOldVideoConstraints); - } - - void SetVideoTrack() { - registry_.Init("stream URL"); - registry_.AddVideoTrack("test video track"); - blink::WebVector video_tracks; - registry_.test_stream().VideoTracks(video_tracks); - track_ = video_tracks[0]; - // TODO(hta): Verify that track_ is valid. When constraints produce - // no valid format, using the track will cause a crash. - } - - void SetVideoTrack(blink::WebMediaConstraints constraints) { - registry_.Init("stream URL"); - registry_.AddVideoTrack("test video track", constraints); - blink::WebVector video_tracks; - registry_.test_stream().VideoTracks(video_tracks); - track_ = video_tracks[0]; - // TODO(hta): Verify that track_ is valid. When constraints produce - // no valid format, using the track will cause a crash. - } - - void SetVideoTrack(const base::Optional& noise_reduction) { - registry_.Init("stream URL"); - registry_.AddVideoTrack("test video track", VideoTrackAdapterSettings(), - noise_reduction, false, 0.0); - blink::WebVector video_tracks; - registry_.test_stream().VideoTracks(video_tracks); - track_ = video_tracks[0]; - // TODO(hta): Verify that track_ is valid. When constraints produce - // no valid format, using the track will cause a crash. - } - - protected: - blink::WebMediaStreamTrack track_; - MockPeerConnectionDependencyFactory dependency_factory_; - - private: - MockMediaStreamRegistry registry_; - // A ChildProcess and a MessageLoopForUI are both needed to fool the Tracks - // and Sources in |registry_| into believing they are on the right threads. - base::test::ScopedTaskEnvironment scoped_task_environment_; - const ChildProcess child_process_; - base::test::ScopedFeatureList scoped_feature_list_; -}; - -TEST_F(MediaStreamVideoWebRtcSinkOldConstraintsTest, - NoiseReductionDefaultsToNotSet) { - blink::WebMediaConstraints constraints; - constraints.Initialize(); - SetVideoTrack(constraints); - MediaStreamVideoWebRtcSink my_sink(track_, &dependency_factory_); - EXPECT_TRUE(my_sink.webrtc_video_track()); - EXPECT_FALSE(my_sink.SourceNeedsDenoisingForTesting()); -} - -TEST_F(MediaStreamVideoWebRtcSinkOldConstraintsTest, - NoiseReductionConstraintPassThrough) { - MockConstraintFactory factory; - factory.basic().goog_noise_reduction.SetExact(true); - SetVideoTrack(factory.CreateWebMediaConstraints()); - MediaStreamVideoWebRtcSink my_sink(track_, &dependency_factory_); - EXPECT_TRUE(my_sink.SourceNeedsDenoisingForTesting()); - EXPECT_TRUE(*(my_sink.SourceNeedsDenoisingForTesting())); -} - } // namespace } // namespace content diff --git a/content/renderer/pepper/pepper_media_stream_video_track_host.cc b/content/renderer/pepper/pepper_media_stream_video_track_host.cc index 52911b6ac47c94..4924a9879d97ec 100644 --- a/content/renderer/pepper/pepper_media_stream_video_track_host.cc +++ b/content/renderer/pepper/pepper_media_stream_video_track_host.cc @@ -446,7 +446,6 @@ class PepperMediaStreamVideoTrackHost::VideoSource final private: base::Optional GetCurrentFormatImpl() const override { - DCHECK(!IsOldVideoConstraints()); if (host_) { return base::Optional( media::VideoCaptureFormat(