Commit 890ceb96 authored by Chandan Padhi's avatar Chandan Padhi Committed by Commit Bot

Use screen size as default resolution for screen capture

Currently, default resolution is set to 2880x1800.
This CL now sets it to the actual screen size.

Bug: 257097
Change-Id: I547262c563453e31cd8be30e79148d4b92d8c90a
Reviewed-on: https://chromium-review.googlesource.com/989531
Commit-Queue: Chandan Padhi <c.padhi@samsung.com>
Reviewed-by: default avatarGuido Urdaneta <guidou@chromium.org>
Cr-Commit-Position: refs/heads/master@{#547433}
parent 1dde62c2
......@@ -28,8 +28,6 @@ static_assert(kMaxScreenCastDimension * kMaxScreenCastDimension <
const int kDefaultScreenCastWidth = 2880;
const int kDefaultScreenCastHeight = 1800;
const double kDefaultScreenCastAspectRatio =
static_cast<double>(kDefaultScreenCastWidth) / kDefaultScreenCastHeight;
static_assert(kDefaultScreenCastWidth <= kMaxScreenCastDimension,
"Invalid kDefaultScreenCastWidth");
static_assert(kDefaultScreenCastHeight <= kMaxScreenCastDimension,
......@@ -260,28 +258,30 @@ int ClampToValidScreenCastDimension(int value) {
VideoCaptureSettings SelectResultFromCandidates(
const VideoContentCaptureCandidates& candidates,
const blink::WebMediaTrackConstraintSet& basic_constraint_set,
const std::string& stream_source) {
const std::string& stream_source,
int screen_width,
int screen_height) {
std::string device_id = SelectDeviceIDFromCandidates(
candidates.device_id_set(), basic_constraint_set);
// If a maximum width or height is explicitly given, use them as default.
// If only one of them is given, use the default aspect ratio to determine the
// other default value.
// TODO(guidou): Use native screen-capture resolution as default.
// http://crbug.com/257097
int default_height = kDefaultScreenCastHeight;
int default_width = kDefaultScreenCastWidth;
int default_width = screen_width;
int default_height = screen_height;
double default_aspect_ratio =
static_cast<double>(default_width) / default_height;
if (candidates.has_explicit_max_height() &&
candidates.has_explicit_max_width()) {
default_height = candidates.resolution_set().max_height();
default_width = candidates.resolution_set().max_width();
} else if (candidates.has_explicit_max_height()) {
default_height = candidates.resolution_set().max_height();
default_width = static_cast<int>(
std::round(default_height * kDefaultScreenCastAspectRatio));
default_width =
static_cast<int>(std::round(default_height * default_aspect_ratio));
} else if (candidates.has_explicit_max_width()) {
default_width = candidates.resolution_set().max_width();
default_height = static_cast<int>(
std::round(default_width / kDefaultScreenCastAspectRatio));
default_height =
static_cast<int>(std::round(default_width / default_aspect_ratio));
}
// When the given maximum values are large, the computed values using default
// aspect ratio may fall out of range. Ensure the defaults are in the valid
......@@ -344,7 +344,9 @@ VideoCaptureSettings UnsatisfiedConstraintsResult(
VideoCaptureSettings SelectSettingsVideoContentCapture(
const blink::WebMediaConstraints& constraints,
const std::string& stream_source) {
const std::string& stream_source,
int screen_width,
int screen_height) {
VideoContentCaptureCandidates candidates;
candidates.set_resolution_set(ScreenCastResolutionCapabilities());
......@@ -363,7 +365,7 @@ VideoCaptureSettings SelectSettingsVideoContentCapture(
DCHECK(!candidates.IsEmpty());
return SelectResultFromCandidates(candidates, constraints.Basic(),
stream_source);
stream_source, screen_width, screen_height);
}
} // namespace content
......@@ -21,7 +21,6 @@ CONTENT_EXPORT extern const int kMinScreenCastDimension;
CONTENT_EXPORT extern const int kMaxScreenCastDimension;
CONTENT_EXPORT extern const int kDefaultScreenCastWidth;
CONTENT_EXPORT extern const int kDefaultScreenCastHeight;
CONTENT_EXPORT extern const double kDefaultScreenCastAspectRatio;
CONTENT_EXPORT extern const double kMaxScreenCastFrameRate;
CONTENT_EXPORT extern const double kDefaultScreenCastFrameRate;
......@@ -30,7 +29,9 @@ CONTENT_EXPORT extern const double kDefaultScreenCastFrameRate;
// for content video capture based on the given |constraints|.
VideoCaptureSettings CONTENT_EXPORT
SelectSettingsVideoContentCapture(const blink::WebMediaConstraints& constraints,
const std::string& stream_source);
const std::string& stream_source,
int screen_width,
int screen_height);
} // namespace content
......
......@@ -17,6 +17,9 @@ namespace content {
namespace {
const double kDefaultScreenCastAspectRatio =
static_cast<double>(kDefaultScreenCastWidth) / kDefaultScreenCastHeight;
void CheckNonResolutionDefaults(const VideoCaptureSettings& result) {
EXPECT_EQ(kDefaultScreenCastFrameRate, result.FrameRate());
EXPECT_EQ(base::Optional<double>(), result.min_frame_rate());
......@@ -61,7 +64,9 @@ class MediaStreamConstraintsUtilVideoContentTest : public testing::Test {
std::string(kMediaStreamSourceScreen)) {
blink::WebMediaConstraints constraints =
constraint_factory_.CreateWebMediaConstraints();
return SelectSettingsVideoContentCapture(constraints, stream_source);
return SelectSettingsVideoContentCapture(constraints, stream_source,
kDefaultScreenCastWidth,
kDefaultScreenCastHeight);
}
MockConstraintFactory constraint_factory_;
......
......@@ -13,13 +13,13 @@
#include "base/memory/ptr_util.h"
#include "base/strings/stringprintf.h"
#include "base/task_runner.h"
#include "content/public/renderer/render_frame.h"
#include "content/renderer/media/stream/apply_constraints_processor.h"
#include "content/renderer/media/stream/media_stream_device_observer.h"
#include "content/renderer/media/stream/media_stream_video_track.h"
#include "content/renderer/media/webrtc/peer_connection_tracker.h"
#include "content/renderer/media/webrtc/webrtc_uma_histograms.h"
#include "content/renderer/media/webrtc_logging.h"
#include "content/renderer/render_frame_impl.h"
#include "content/renderer/render_thread_impl.h"
#include "services/service_manager/public/cpp/interface_provider.h"
#include "third_party/WebKit/public/platform/WebMediaConstraints.h"
......@@ -86,7 +86,7 @@ UserMediaClientImpl::Request::MoveUserMediaRequest() {
}
UserMediaClientImpl::UserMediaClientImpl(
RenderFrame* render_frame,
RenderFrameImpl* render_frame,
std::unique_ptr<UserMediaProcessor> user_media_processor)
: RenderFrameObserver(render_frame),
user_media_processor_(std::move(user_media_processor)),
......@@ -98,7 +98,7 @@ UserMediaClientImpl::UserMediaClientImpl(
// base::Unretained(this) is safe here because |this| owns
// |user_media_processor_|.
UserMediaClientImpl::UserMediaClientImpl(
RenderFrame* render_frame,
RenderFrameImpl* render_frame,
PeerConnectionDependencyFactory* dependency_factory,
std::unique_ptr<MediaStreamDeviceObserver> media_stream_device_observer)
: UserMediaClientImpl(
......
......@@ -38,10 +38,10 @@ class CONTENT_EXPORT UserMediaClientImpl : public RenderFrameObserver,
// the free store. http://crbug.com/764293
// |render_frame| and |dependency_factory| must outlive this instance.
UserMediaClientImpl(
RenderFrame* render_frame,
RenderFrameImpl* render_frame,
PeerConnectionDependencyFactory* dependency_factory,
std::unique_ptr<MediaStreamDeviceObserver> media_stream_device_observer);
UserMediaClientImpl(RenderFrame* render_frame,
UserMediaClientImpl(RenderFrameImpl* render_frame,
std::unique_ptr<UserMediaProcessor> user_media_processor);
~UserMediaClientImpl() override;
......
......@@ -18,7 +18,6 @@
#include "base/task_runner_util.h"
#include "base/threading/thread_task_runner_handle.h"
#include "content/common/media/media_stream_controls.h"
#include "content/public/renderer/render_frame.h"
#include "content/renderer/media/stream/local_media_stream_audio_source.h"
#include "content/renderer/media/stream/media_stream_audio_processor.h"
#include "content/renderer/media/stream/media_stream_audio_source.h"
......@@ -34,6 +33,8 @@
#include "content/renderer/media/webrtc/peer_connection_dependency_factory.h"
#include "content/renderer/media/webrtc/webrtc_uma_histograms.h"
#include "content/renderer/media/webrtc_logging.h"
#include "content/renderer/render_frame_impl.h"
#include "content/renderer/render_widget.h"
#include "media/base/audio_parameters.h"
#include "media/capture/video_capture_types.h"
#include "services/service_manager/public/cpp/interface_provider.h"
......@@ -355,7 +356,7 @@ void UserMediaProcessor::RequestInfo::OnAudioSourceStarted(
}
UserMediaProcessor::UserMediaProcessor(
RenderFrame* render_frame,
RenderFrameImpl* render_frame,
PeerConnectionDependencyFactory* dependency_factory,
std::unique_ptr<MediaStreamDeviceObserver> media_stream_device_observer,
MediaDevicesDispatcherCallback media_devices_dispatcher_cb)
......@@ -570,9 +571,18 @@ void UserMediaProcessor::SelectVideoDeviceSettings(
void UserMediaProcessor::SelectVideoContentSettings() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(current_request_info_);
int screen_width = kDefaultScreenCastWidth;
int screen_height = kDefaultScreenCastHeight;
if (render_frame_) { // Can be null in tests.
blink::WebScreenInfo info =
render_frame_->GetRenderWidget()->GetScreenInfo();
screen_width = info.rect.width;
screen_height = info.rect.height;
}
VideoCaptureSettings settings = SelectSettingsVideoContentCapture(
current_request_info_->web_request().VideoConstraints(),
current_request_info_->stream_controls()->video.stream_source);
current_request_info_->stream_controls()->video.stream_source,
screen_width, screen_height);
if (!settings.HasValue()) {
blink::WebString failed_constraint_name =
blink::WebString::FromASCII(settings.failed_constraint_name());
......
......@@ -38,7 +38,7 @@ class MediaStreamDeviceObserver;
class MediaStreamVideoSource;
class PeerConnectionDependencyFactory;
class VideoCaptureSettings;
class RenderFrame;
class RenderFrameImpl;
// TODO(guidou): Add |request_id| and |is_processing_user_gesture| to
// blink::WebUserMediaRequest and remove this struct.
......@@ -65,7 +65,7 @@ class CONTENT_EXPORT UserMediaProcessor
const blink::mojom::MediaDevicesDispatcherHostPtr&()>;
// |render_frame| and |dependency_factory| must outlive this instance.
UserMediaProcessor(
RenderFrame* render_frame,
RenderFrameImpl* render_frame,
PeerConnectionDependencyFactory* dependency_factory,
std::unique_ptr<MediaStreamDeviceObserver> media_stream_device_observer,
MediaDevicesDispatcherCallback media_devices_dispatcher_cb);
......@@ -292,7 +292,7 @@ class CONTENT_EXPORT UserMediaProcessor
MediaDevicesDispatcherCallback media_devices_dispatcher_cb_;
base::OnceClosure request_completed_cb_;
RenderFrame* const render_frame_;
RenderFrameImpl* const render_frame_;
SEQUENCE_CHECKER(sequence_checker_);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment