diff options
author | miu <miu@chromium.org> | 2015-05-09 15:17:15 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-05-09 22:17:45 +0000 |
commit | f79202747a089a00f653e5827409c779395bda70 (patch) | |
tree | d2818030a1838573579d94e5727cb29786855b88 | |
parent | 238eaa368547ea4a87f5ea605c927e9013d3da92 (diff) | |
download | chromium_src-f79202747a089a00f653e5827409c779395bda70.zip chromium_src-f79202747a089a00f653e5827409c779395bda70.tar.gz chromium_src-f79202747a089a00f653e5827409c779395bda70.tar.bz2 |
New resolution change policies for desktop and tab capture.
This change replaces the "fixed" versus "variable" resolution change
policies with a 3-tier set: fixed, variable with fixed aspect ratio, and
variable at any aspect ratio.
This allows users of the desktop and tab capture APIs to specify minimum
and maximum resolutions, and from those, a resolution change policy is
determined. The policy is used by the desktop and tab capture
implementation to activate or disable sender-side letterboxing of
screen-capture content.
BUG=473336
NOPRESUBMIT=true
NOTRY=true
Review URL: https://codereview.chromium.org/1124263004
Cr-Commit-Position: refs/heads/master@{#329056}
18 files changed, 297 insertions, 36 deletions
diff --git a/content/browser/media/capture/content_video_capture_device_core.cc b/content/browser/media/capture/content_video_capture_device_core.cc index 757db4a..8d44104 100644 --- a/content/browser/media/capture/content_video_capture_device_core.cc +++ b/content/browser/media/capture/content_video_capture_device_core.cc @@ -152,7 +152,7 @@ void ThreadSafeCaptureOracle::UpdateCaptureSize(const gfx::Size& source_size) { // been set; or 2) The resolution change policy specifies dynamic frame // sizes. if (capture_size_.IsEmpty() || params_.resolution_change_policy == - media::RESOLUTION_POLICY_DYNAMIC_WITHIN_LIMIT) { + media::RESOLUTION_POLICY_ANY_WITHIN_LIMIT) { capture_size_ = source_size; // The capture size should not exceed the maximum frame size. if (capture_size_.width() > max_frame_size().width() || diff --git a/content/browser/media/capture/desktop_capture_device.cc b/content/browser/media/capture/desktop_capture_device.cc index 410a224..a11e473 100644 --- a/content/browser/media/capture/desktop_capture_device.cc +++ b/content/browser/media/capture/desktop_capture_device.cc @@ -325,7 +325,7 @@ void DesktopCaptureDevice::Core::RefreshCaptureFormat( if (previous_frame_size_.is_empty() || requested_params_.resolution_change_policy == - media::RESOLUTION_POLICY_DYNAMIC_WITHIN_LIMIT) { + media::RESOLUTION_POLICY_ANY_WITHIN_LIMIT) { // If this is the first frame, or the receiver supports variable resolution // then determine the output size by treating the requested width & height // as maxima. diff --git a/content/browser/renderer_host/media/video_capture_host.cc b/content/browser/renderer_host/media/video_capture_host.cc index 72e440c..a546bbd 100644 --- a/content/browser/renderer_host/media/video_capture_host.cc +++ b/content/browser/renderer_host/media/video_capture_host.cc @@ -180,8 +180,11 @@ void VideoCaptureHost::OnStartCapture(int device_id, << ", format=" << params.requested_format.ToString() << "@" << params.requested_format.frame_rate << " (" << (params.resolution_change_policy == - media::RESOLUTION_POLICY_DYNAMIC_WITHIN_LIMIT ? - "variable" : "constant") + media::RESOLUTION_POLICY_FIXED_RESOLUTION ? + "fixed resolution" : + (params.resolution_change_policy == + media::RESOLUTION_POLICY_FIXED_ASPECT_RATIO ? + "fixed aspect ratio" : "variable resolution")) << ")"; VideoCaptureControllerID controller_id(device_id); if (entries_.find(controller_id) != entries_.end()) { diff --git a/content/renderer/media/media_stream_video_capture_source_unittest.cc b/content/renderer/media/media_stream_video_capture_source_unittest.cc index ceec813..7995437 100644 --- a/content/renderer/media/media_stream_video_capture_source_unittest.cc +++ b/content/renderer/media/media_stream_video_capture_source_unittest.cc @@ -66,12 +66,15 @@ class MediaStreamVideoCapturerSourceTest : public testing::Test { webkit_source_id_ = webkit_source_.id(); } + MockMediaConstraintFactory* constraint_factory() { + return &constraint_factory_; + } + blink::WebMediaStreamTrack StartSource() { - MockMediaConstraintFactory factory; bool enabled = true; // CreateVideoTrack will trigger OnConstraintsApplied. return MediaStreamVideoTrack::CreateVideoTrack( - source_, factory.CreateWebMediaConstraints(), + source_, constraint_factory_.CreateWebMediaConstraints(), base::Bind( &MediaStreamVideoCapturerSourceTest::OnConstraintsApplied, base::Unretained(this)), @@ -100,16 +103,28 @@ class MediaStreamVideoCapturerSourceTest : public testing::Test { MockVideoCapturerDelegate* delegate_; // owned by |source|. blink::WebString webkit_source_id_; bool source_stopped_; + MockMediaConstraintFactory constraint_factory_; }; -TEST_F(MediaStreamVideoCapturerSourceTest, TabCaptureAllowResolutionChange) { +TEST_F(MediaStreamVideoCapturerSourceTest, 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; + EXPECT_CALL(mock_delegate(), StartCapture( - testing::Field(&media::VideoCaptureParams::resolution_change_policy, - media::RESOLUTION_POLICY_DYNAMIC_WITHIN_LIMIT), + expected_params, testing::_, testing::_, testing::_)).Times(1); @@ -119,14 +134,88 @@ TEST_F(MediaStreamVideoCapturerSourceTest, TabCaptureAllowResolutionChange) { } TEST_F(MediaStreamVideoCapturerSourceTest, - DesktopCaptureAllowResolutionChange) { + 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; + + EXPECT_CALL(mock_delegate(), StartCapture( + expected_params, + testing::_, + testing::_, + testing::_)).Times(1); + blink::WebMediaStreamTrack track = StartSource(); + // When the track goes out of scope, the source will be stopped. + EXPECT_CALL(mock_delegate(), StopCapture()); +} + +TEST_F(MediaStreamVideoCapturerSourceTest, + 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()->AddMandatory(MediaStreamVideoSource::kMaxWidth, 1920); + constraint_factory()->AddMandatory(MediaStreamVideoSource::kMaxHeight, 1080); + constraint_factory()->AddMandatory(MediaStreamVideoSource::kMinWidth, 854); + constraint_factory()->AddMandatory(MediaStreamVideoSource::kMinHeight, 480); + constraint_factory()->AddMandatory(MediaStreamVideoSource::kMaxFrameRate, + 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; + EXPECT_CALL(mock_delegate(), StartCapture( testing::Field(&media::VideoCaptureParams::resolution_change_policy, - media::RESOLUTION_POLICY_DYNAMIC_WITHIN_LIMIT), + media::RESOLUTION_POLICY_FIXED_ASPECT_RATIO), + testing::_, + testing::_, + testing::_)).Times(1); + blink::WebMediaStreamTrack track = StartSource(); + // When the track goes out of scope, the source will be stopped. + EXPECT_CALL(mock_delegate(), StopCapture()); +} + +TEST_F(MediaStreamVideoCapturerSourceTest, + 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()->AddMandatory(MediaStreamVideoSource::kMaxWidth, 1920); + constraint_factory()->AddMandatory(MediaStreamVideoSource::kMaxHeight, 1080); + constraint_factory()->AddMandatory(MediaStreamVideoSource::kMinWidth, 0); + constraint_factory()->AddMandatory(MediaStreamVideoSource::kMinHeight, 0); + constraint_factory()->AddMandatory(MediaStreamVideoSource::kMaxFrameRate, + 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; + + EXPECT_CALL(mock_delegate(), StartCapture( + expected_params, testing::_, testing::_, testing::_)).Times(1); diff --git a/content/renderer/media/media_stream_video_capturer_source.cc b/content/renderer/media/media_stream_video_capturer_source.cc index 1c905cc..f2c1fd0 100644 --- a/content/renderer/media/media_stream_video_capturer_source.cc +++ b/content/renderer/media/media_stream_video_capturer_source.cc @@ -7,11 +7,16 @@ #include "base/bind.h" #include "base/callback_helpers.h" #include "base/location.h" +#include "content/public/common/media_stream_request.h" +#include "content/renderer/media/media_stream_constraints_util.h" #include "content/renderer/media/video_capture_impl_manager.h" #include "content/renderer/render_thread_impl.h" #include "media/base/bind_to_current_loop.h" +#include "media/base/limits.h" #include "media/base/video_frame.h" +namespace content { + namespace { // Resolutions used if the source doesn't support capability enumeration. @@ -32,9 +37,135 @@ const int kVideoFrameRates[] = {30, 60}; // Hard upper-bound frame rate for tab/desktop capture. const double kMaxScreenCastFrameRate = 120.0; -} // namespace +// Returns true if the value for width or height is reasonable. +bool DimensionValueIsValid(int x) { + return x > 0 && x <= media::limits::kMaxDimension; +} -namespace content { +// 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; +} + +// Interprets the properties in |constraints| to override values in |params| and +// determine the resolution change policy. +void SetScreenCastParamsFromConstraints( + 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 (GetConstraintValueAsInteger(constraints, + MediaStreamVideoSource::kMaxWidth, + &width) && + GetConstraintValueAsInteger(constraints, + MediaStreamVideoSource::kMaxHeight, + &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 (GetConstraintValueAsDouble(constraints, + MediaStreamVideoSource::kMaxFrameRate, + &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() && + GetConstraintValueAsInteger(constraints, + MediaStreamVideoSource::kMinWidth, + &width) && + GetConstraintValueAsInteger(constraints, + MediaStreamVideoSource::kMinHeight, + &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) << "SetScreenCastParamsFromConstraints: " + << params->requested_format.ToString() + << " with resolution change policy " + << params->resolution_change_policy; +} + +} // namespace VideoCapturerDelegate::VideoCapturerDelegate( const StreamDeviceInfo& device_info) @@ -246,13 +377,14 @@ void MediaStreamVideoCapturerSource::GetCurrentSupportedFormats( void MediaStreamVideoCapturerSource::StartSourceImpl( const media::VideoCaptureFormat& format, + const blink::WebMediaConstraints& constraints, const VideoCaptureDeliverFrameCB& frame_callback) { media::VideoCaptureParams new_params; new_params.requested_format = format; if (device_info().device.type == MEDIA_TAB_VIDEO_CAPTURE || device_info().device.type == MEDIA_DESKTOP_VIDEO_CAPTURE) { - new_params.resolution_change_policy = - media::RESOLUTION_POLICY_DYNAMIC_WITHIN_LIMIT; + SetScreenCastParamsFromConstraints( + constraints, device_info().device.type, &new_params); } delegate_->StartCapture( new_params, diff --git a/content/renderer/media/media_stream_video_capturer_source.h b/content/renderer/media/media_stream_video_capturer_source.h index f95dd59..3722b9d 100644 --- a/content/renderer/media/media_stream_video_capturer_source.h +++ b/content/renderer/media/media_stream_video_capturer_source.h @@ -97,6 +97,7 @@ class CONTENT_EXPORT MediaStreamVideoCapturerSource void StartSourceImpl( const media::VideoCaptureFormat& format, + const blink::WebMediaConstraints& constraints, const VideoCaptureDeliverFrameCB& frame_callback) override; void StopSourceImpl() override; diff --git a/content/renderer/media/media_stream_video_source.cc b/content/renderer/media/media_stream_video_source.cc index 6e50121..c4b0c22 100644 --- a/content/renderer/media/media_stream_video_source.cc +++ b/content/renderer/media/media_stream_video_source.cc @@ -464,8 +464,10 @@ void MediaStreamVideoSource::OnSupportedFormats( DCHECK_EQ(RETRIEVING_CAPABILITIES, state_); supported_formats_ = formats; + blink::WebMediaConstraints fulfilled_constraints; if (!FindBestFormatWithConstraints(supported_formats_, - ¤t_format_)) { + ¤t_format_, + &fulfilled_constraints)) { SetReadyState(blink::WebMediaStreamSource::ReadyStateEnded); // This object can be deleted after calling FinalizeAddTrack. See comment // in the header file. @@ -478,12 +480,14 @@ void MediaStreamVideoSource::OnSupportedFormats( StartSourceImpl( current_format_, + fulfilled_constraints, base::Bind(&VideoTrackAdapter::DeliverFrameOnIO, track_adapter_)); } bool MediaStreamVideoSource::FindBestFormatWithConstraints( const media::VideoCaptureFormats& formats, - media::VideoCaptureFormat* best_format) { + media::VideoCaptureFormat* best_format, + blink::WebMediaConstraints* fulfilled_constraints) { DCHECK(CalledOnValidThread()); // Find the first constraints that we can fulfill. for (const auto& request : requested_constraints_) { @@ -494,6 +498,7 @@ bool MediaStreamVideoSource::FindBestFormatWithConstraints( // 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(requested_constraints)) { + *fulfilled_constraints = requested_constraints; *best_format = media::VideoCaptureFormat(); return true; } @@ -502,6 +507,7 @@ bool MediaStreamVideoSource::FindBestFormatWithConstraints( FilterFormats(requested_constraints, formats, &unsatisfied_constraint); if (filtered_formats.size() > 0) { // A request with constraints that can be fulfilled. + *fulfilled_constraints = requested_constraints; GetBestCaptureFormat(filtered_formats, requested_constraints, best_format); diff --git a/content/renderer/media/media_stream_video_source.h b/content/renderer/media/media_stream_video_source.h index 3e2cbff..496bb85 100644 --- a/content/renderer/media/media_stream_video_source.h +++ b/content/renderer/media/media_stream_video_source.h @@ -70,7 +70,7 @@ class CONTENT_EXPORT MediaStreamVideoSource static const char kMinAspectRatio[]; // minAspectRatio static const char kMaxAspectRatio[]; // maxAspectRatio static const char kMaxWidth[]; // maxWidth - static const char kMinWidth[]; // minWidthOnCaptureFormats + static const char kMinWidth[]; // minWidth static const char kMaxHeight[]; // maxHeight static const char kMinHeight[]; // minHeight static const char kMaxFrameRate[]; // maxFrameRate @@ -107,12 +107,15 @@ class CONTENT_EXPORT MediaStreamVideoSource double max_requested_frame_rate, const VideoCaptureDeviceFormatsCB& callback) = 0; - // An implementation must start capture frames using the resolution in - // |params|. When the source has started or the source failed to start - // OnStartDone must be called. An implementation must call - // |frame_callback| on the IO thread with the captured frames. + // An implementation must start capturing frames using the requested + // |format|. The fulfilled |constraints| are provided as additional context, + // and may be used to modify the behavior of the source. When the source has + // started or the source failed to start OnStartDone must be called. An + // implementation must call |frame_callback| on the IO thread with the + // captured frames. virtual void StartSourceImpl( const media::VideoCaptureFormat& format, + const blink::WebMediaConstraints& constraints, const VideoCaptureDeliverFrameCB& frame_callback) = 0; void OnStartDone(MediaStreamRequestResult result); @@ -133,12 +136,14 @@ class CONTENT_EXPORT MediaStreamVideoSource private: void OnSupportedFormats(const media::VideoCaptureFormats& formats); - // Finds the first constraints in |requested_constraints_| that can be - // fulfilled. |best_format| is set to the video resolution that can be - // fulfilled. + // Finds the first WebMediaConstraints in |requested_constraints_| 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); + 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 diff --git a/content/renderer/media/mock_media_stream_video_source.cc b/content/renderer/media/mock_media_stream_video_source.cc index b99e4c3..cf9f685 100644 --- a/content/renderer/media/mock_media_stream_video_source.cc +++ b/content/renderer/media/mock_media_stream_video_source.cc @@ -63,6 +63,7 @@ void MockMediaStreamVideoSource::GetCurrentSupportedFormats( void MockMediaStreamVideoSource::StartSourceImpl( const media::VideoCaptureFormat& format, + const blink::WebMediaConstraints& constraints, const VideoCaptureDeliverFrameCB& frame_callback) { DCHECK(frame_callback_.is_null()); format_ = format; diff --git a/content/renderer/media/mock_media_stream_video_source.h b/content/renderer/media/mock_media_stream_video_source.h index d00a5fe..f912601 100644 --- a/content/renderer/media/mock_media_stream_video_source.h +++ b/content/renderer/media/mock_media_stream_video_source.h @@ -58,6 +58,7 @@ class MockMediaStreamVideoSource : public MediaStreamVideoSource { const VideoCaptureDeviceFormatsCB& callback) override; void StartSourceImpl( const media::VideoCaptureFormat& format, + const blink::WebMediaConstraints& constraints, const VideoCaptureDeliverFrameCB& frame_callback) override; void StopSourceImpl() override; diff --git a/content/renderer/media/webrtc/media_stream_remote_video_source.cc b/content/renderer/media/webrtc/media_stream_remote_video_source.cc index a151647..9fa3e5d 100644 --- a/content/renderer/media/webrtc/media_stream_remote_video_source.cc +++ b/content/renderer/media/webrtc/media_stream_remote_video_source.cc @@ -139,6 +139,7 @@ void MediaStreamRemoteVideoSource::GetCurrentSupportedFormats( void MediaStreamRemoteVideoSource::StartSourceImpl( const media::VideoCaptureFormat& format, + const blink::WebMediaConstraints& constraints, const VideoCaptureDeliverFrameCB& frame_callback) { DCHECK(CalledOnValidThread()); DCHECK(!delegate_.get()); diff --git a/content/renderer/media/webrtc/media_stream_remote_video_source.h b/content/renderer/media/webrtc/media_stream_remote_video_source.h index 5a42b8f..5607cd5 100644 --- a/content/renderer/media/webrtc/media_stream_remote_video_source.h +++ b/content/renderer/media/webrtc/media_stream_remote_video_source.h @@ -36,6 +36,7 @@ class CONTENT_EXPORT MediaStreamRemoteVideoSource void StartSourceImpl( const media::VideoCaptureFormat& format, + const blink::WebMediaConstraints& constraints, const VideoCaptureDeliverFrameCB& frame_callback) override; void StopSourceImpl() override; diff --git a/content/renderer/media/webrtc/video_destination_handler.cc b/content/renderer/media/webrtc/video_destination_handler.cc index 2e3c8b1..febc4e0 100644 --- a/content/renderer/media/webrtc/video_destination_handler.cc +++ b/content/renderer/media/webrtc/video_destination_handler.cc @@ -91,6 +91,7 @@ void PpFrameWriter::GetCurrentSupportedFormats( void PpFrameWriter::StartSourceImpl( const media::VideoCaptureFormat& format, + const blink::WebMediaConstraints& constraints, const VideoCaptureDeliverFrameCB& frame_callback) { DCHECK(CalledOnValidThread()); DCHECK(!delegate_.get()); diff --git a/content/renderer/media/webrtc/video_destination_handler.h b/content/renderer/media/webrtc/video_destination_handler.h index b2cf0bf..c71ae69 100644 --- a/content/renderer/media/webrtc/video_destination_handler.h +++ b/content/renderer/media/webrtc/video_destination_handler.h @@ -56,6 +56,7 @@ class CONTENT_EXPORT PpFrameWriter const VideoCaptureDeviceFormatsCB& callback) override; void StartSourceImpl( const media::VideoCaptureFormat& format, + const blink::WebMediaConstraints& constraints, const VideoCaptureDeliverFrameCB& frame_callback) override; void StopSourceImpl() override; 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 258ee56..14c6731 100644 --- a/content/renderer/pepper/pepper_media_stream_video_track_host.cc +++ b/content/renderer/pepper/pepper_media_stream_video_track_host.cc @@ -433,6 +433,7 @@ void PepperMediaStreamVideoTrackHost::GetCurrentSupportedFormats( void PepperMediaStreamVideoTrackHost::StartSourceImpl( const media::VideoCaptureFormat& format, + const blink::WebMediaConstraints& constraints, const VideoCaptureDeliverFrameCB& frame_callback) { output_started_ = true; frame_deliverer_ = new FrameDeliverer(io_message_loop(), frame_callback); diff --git a/content/renderer/pepper/pepper_media_stream_video_track_host.h b/content/renderer/pepper/pepper_media_stream_video_track_host.h index 74455ee..b0c7f67 100644 --- a/content/renderer/pepper/pepper_media_stream_video_track_host.h +++ b/content/renderer/pepper/pepper_media_stream_video_track_host.h @@ -67,6 +67,7 @@ class PepperMediaStreamVideoTrackHost : public PepperMediaStreamTrackHostBase, void StartSourceImpl( const media::VideoCaptureFormat& format, + const blink::WebMediaConstraints& constraints, const VideoCaptureDeliverFrameCB& frame_callback) override; void StopSourceImpl() override; diff --git a/media/base/video_capture_types.cc b/media/base/video_capture_types.cc index cc5f840..f8463cf 100644 --- a/media/base/video_capture_types.cc +++ b/media/base/video_capture_types.cc @@ -108,5 +108,6 @@ std::string VideoCaptureFormat::PixelFormatToString(VideoPixelFormat format) { } VideoCaptureParams::VideoCaptureParams() - : resolution_change_policy(RESOLUTION_POLICY_FIXED) {} + : resolution_change_policy(RESOLUTION_POLICY_FIXED_RESOLUTION) {} + } // namespace media diff --git a/media/base/video_capture_types.h b/media/base/video_capture_types.h index 463873f..c849ed7 100644 --- a/media/base/video_capture_types.h +++ b/media/base/video_capture_types.h @@ -34,19 +34,24 @@ enum VideoPixelFormat { PIXEL_FORMAT_MAX, }; -// Policies for capture devices that has source content with dynamic resolution. +// Policies for capture devices that have source content that varies in size. +// It is up to the implementation how the captured content will be transformed +// (e.g., scaling and/or letterboxing) in order to produce video frames that +// strictly adheree to one of these policies. enum ResolutionChangePolicy { // Capture device outputs a fixed resolution all the time. The resolution of // the first frame is the resolution for all frames. - // It is implementation specific for the capture device to scale, letter-box - // and pillar-box. The only guarantee is that resolution will never change. - RESOLUTION_POLICY_FIXED, + RESOLUTION_POLICY_FIXED_RESOLUTION, - // Capture device outputs frames with dynamic resolution. The width and height - // will not exceed the maximum dimensions specified. The typical scenario is - // the frames will have the same aspect ratio as the original content and - // scaled down to fit inside the limit. - RESOLUTION_POLICY_DYNAMIC_WITHIN_LIMIT, + // Capture device is allowed to output frames of varying resolutions. The + // width and height will not exceed the maximum dimensions specified. The + // aspect ratio of the frames will match the aspect ratio of the maximum + // dimensions as closely as possible. + RESOLUTION_POLICY_FIXED_ASPECT_RATIO, + + // Capture device is allowed to output frames of varying resolutions not + // exceeding the maximum dimensions specified. + RESOLUTION_POLICY_ANY_WITHIN_LIMIT, RESOLUTION_POLICY_LAST, }; @@ -77,6 +82,12 @@ class MEDIA_EXPORT VideoCaptureFormat { // in media::Limits. bool IsValid() const; + bool operator==(const VideoCaptureFormat& other) const { + return frame_size == other.frame_size && + frame_rate == other.frame_rate && + pixel_format == other.pixel_format; + } + gfx::Size frame_size; float frame_rate; VideoPixelFormat pixel_format; @@ -92,6 +103,11 @@ class MEDIA_EXPORT VideoCaptureParams { public: VideoCaptureParams(); + bool operator==(const VideoCaptureParams& other) const { + return requested_format == other.requested_format && + resolution_change_policy == other.resolution_change_policy; + } + // Requests a resolution and format at which the capture will occur. VideoCaptureFormat requested_format; |