Skip to content

Commit

Permalink
Allow MediaStream constraints to specify higher than 30 FPS tab capture.
Browse files Browse the repository at this point in the history
This will allow true 720p/60fps tab/desktop capture, if configured
through the constraints (and the system hardware performance supports
it).  In addition, this will enable tab capture perf tests to run at
higher frame rates so that more-subtle regressions are caught.

A new hard upper-bound of 120 FPS is enforced with this change.

BUG=400631
TBR=yzshen@chromium.org

Review URL: https://codereview.chromium.org/442643002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@287642 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
miu@chromium.org committed Aug 5, 2014
1 parent 1e7c29f commit 683511a
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 16 deletions.
26 changes: 16 additions & 10 deletions content/renderer/media/media_stream_video_capturer_source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ const SourceVideoResolution kVideoResolutions[] = {{1920, 1080},
// 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;

} // namespace

namespace content {
Expand Down Expand Up @@ -59,23 +62,24 @@ VideoCapturerDelegate::~VideoCapturerDelegate() {
void VideoCapturerDelegate::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 << "})";
DVLOG(3)
<< "GetCurrentSupportedFormats("
<< " { max_requested_height = " << max_requested_height << "})"
<< " { max_requested_width = " << max_requested_width << "})"
<< " { max_requested_frame_rate = " << max_requested_frame_rate << "})";

if (is_screen_cast_) {
media::VideoCaptureFormats formats;
const int width = max_requested_width ?
max_requested_width : MediaStreamVideoSource::kDefaultWidth;
const int height = max_requested_height ?
max_requested_height : MediaStreamVideoSource::kDefaultHeight;
formats.push_back(
media::VideoCaptureFormat(
gfx::Size(width, height),
MediaStreamVideoSource::kDefaultFrameRate,
media::PIXEL_FORMAT_I420));
callback.Run(formats);
callback.Run(media::VideoCaptureFormats(1, media::VideoCaptureFormat(
gfx::Size(width, height),
static_cast<float>(std::min(kMaxScreenCastFrameRate,
max_requested_frame_rate)),
media::PIXEL_FORMAT_I420)));
return;
}

Expand Down Expand Up @@ -216,10 +220,12 @@ MediaStreamVideoCapturerSource::~MediaStreamVideoCapturerSource() {
void MediaStreamVideoCapturerSource::GetCurrentSupportedFormats(
int max_requested_width,
int max_requested_height,
double max_requested_frame_rate,
const VideoCaptureDeviceFormatsCB& callback) {
delegate_->GetCurrentSupportedFormats(
max_requested_width,
max_requested_height,
max_requested_frame_rate,
callback);
}

Expand Down
9 changes: 6 additions & 3 deletions content/renderer/media/media_stream_video_capturer_source.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ class CONTENT_EXPORT VideoCapturerDelegate
const StreamDeviceInfo& device_info);

// Collects the formats that can currently be used.
// |max_requested_height| and |max_requested_width| is used by Tab and Screen
// capture to decide what resolution to generate.
// |callback| is triggered when the formats have been collected.
// |max_requested_height|, |max_requested_width|, and
// |max_requested_frame_rate| is used by Tab and Screen capture to decide what
// resolution/framerate to generate. |callback| is triggered when the formats
// have been collected.
virtual void GetCurrentSupportedFormats(
int max_requested_width,
int max_requested_height,
double max_requested_frame_rate,
const VideoCaptureDeviceFormatsCB& callback);

// Starts capturing frames using the resolution in |params|.
Expand Down Expand Up @@ -102,6 +104,7 @@ class CONTENT_EXPORT MediaStreamVideoCapturerSource
virtual void GetCurrentSupportedFormats(
int max_requested_width,
int max_requested_height,
double max_requested_frame_rate,
const VideoCaptureDeviceFormatsCB& callback) OVERRIDE;

virtual void StartSourceImpl(
Expand Down
11 changes: 9 additions & 2 deletions content/renderer/media/media_stream_video_source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ bool UpdateFormatForConstraint(
} else if (constraint_name == MediaStreamVideoSource::kMaxHeight) {
return value > 0.0;
} else if (constraint_name == MediaStreamVideoSource::kMinFrameRate) {
return (value <= format->frame_rate);
return (value > 0.0) && (value <= format->frame_rate);
} else if (constraint_name == MediaStreamVideoSource::kMaxFrameRate) {
if (value == 0.0) {
if (value <= 0.0) {
// The frame rate is set by constraint.
// Don't allow 0 as frame rate if it is a mandatory constraint.
// Set the frame rate to 1 if it is not mandatory.
Expand Down Expand Up @@ -387,10 +387,17 @@ void MediaStreamVideoSource::AddTrack(
GetMandatoryConstraintValueAsInteger(constraints, kMaxHeight,
&max_requested_height);

double max_requested_frame_rate;
if (!GetConstraintValueAsDouble(constraints, kMaxFrameRate,
&max_requested_frame_rate)) {
max_requested_frame_rate = kDefaultFrameRate;
}

state_ = RETRIEVING_CAPABILITIES;
GetCurrentSupportedFormats(
max_requested_width,
max_requested_height,
max_requested_frame_rate,
base::Bind(&MediaStreamVideoSource::OnSupportedFormats,
weak_factory_.GetWeakPtr()));

Expand Down
1 change: 1 addition & 0 deletions content/renderer/media/media_stream_video_source.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class CONTENT_EXPORT MediaStreamVideoSource
virtual void GetCurrentSupportedFormats(
int max_requested_width,
int max_requested_height,
double max_requested_frame_rate,
const VideoCaptureDeviceFormatsCB& callback) = 0;

// An implementation must start capture frames using the resolution in
Expand Down
3 changes: 3 additions & 0 deletions content/renderer/media/mock_media_stream_video_source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ MockMediaStreamVideoSource::MockMediaStreamVideoSource(
: manual_get_supported_formats_(manual_get_supported_formats),
max_requested_height_(0),
max_requested_width_(0),
max_requested_frame_rate_(0.0),
attempted_to_start_(false) {
supported_formats_.push_back(
media::VideoCaptureFormat(
Expand Down Expand Up @@ -46,10 +47,12 @@ void MockMediaStreamVideoSource::CompleteGetSupportedFormats() {
void MockMediaStreamVideoSource::GetCurrentSupportedFormats(
int max_requested_height,
int max_requested_width,
double max_requested_frame_rate,
const VideoCaptureDeviceFormatsCB& callback) {
DCHECK(formats_callback_.is_null());
max_requested_height_ = max_requested_height;
max_requested_width_ = max_requested_width;
max_requested_frame_rate_ = max_requested_frame_rate;

if (manual_get_supported_formats_) {
formats_callback_ = callback;
Expand Down
3 changes: 3 additions & 0 deletions content/renderer/media/mock_media_stream_video_source.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class MockMediaStreamVideoSource : public MediaStreamVideoSource {
const media::VideoCaptureParams& start_params() const { return params_; }
int max_requested_height() const { return max_requested_height_; }
int max_requested_width() const { return max_requested_width_; }
double max_requested_frame_rate() const { return max_requested_frame_rate_; }

void SetMutedState(bool muted_state) {
MediaStreamVideoSource::SetMutedState(muted_state);
Expand All @@ -58,6 +59,7 @@ class MockMediaStreamVideoSource : public MediaStreamVideoSource {
virtual void GetCurrentSupportedFormats(
int max_requested_height,
int max_requested_width,
double max_requested_frame_rate,
const VideoCaptureDeviceFormatsCB& callback) OVERRIDE;
virtual void StartSourceImpl(
const media::VideoCaptureParams& params,
Expand All @@ -70,6 +72,7 @@ class MockMediaStreamVideoSource : public MediaStreamVideoSource {
bool manual_get_supported_formats_;
int max_requested_height_;
int max_requested_width_;
double max_requested_frame_rate_;
bool attempted_to_start_;
VideoCaptureDeviceFormatsCB formats_callback_;
VideoCaptureDeliverFrameCB frame_callback_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ MediaStreamRemoteVideoSource::~MediaStreamRemoteVideoSource() {
void MediaStreamRemoteVideoSource::GetCurrentSupportedFormats(
int max_requested_width,
int max_requested_height,
double max_requested_frame_rate,
const VideoCaptureDeviceFormatsCB& callback) {
DCHECK(thread_checker_.CalledOnValidThread());
media::VideoCaptureFormats formats;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class CONTENT_EXPORT MediaStreamRemoteVideoSource
virtual void GetCurrentSupportedFormats(
int max_requested_width,
int max_requested_height,
double max_requested_frame_rate,
const VideoCaptureDeviceFormatsCB& callback) OVERRIDE;

virtual void StartSourceImpl(
Expand Down
1 change: 1 addition & 0 deletions content/renderer/media/webrtc/video_destination_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ PpFrameWriter::~PpFrameWriter() {
void PpFrameWriter::GetCurrentSupportedFormats(
int max_requested_width,
int max_requested_height,
double max_requested_frame_rate,
const VideoCaptureDeviceFormatsCB& callback) {
DCHECK(CalledOnValidThread());
DVLOG(3) << "PpFrameWriter::GetCurrentSupportedFormats()";
Expand Down
2 changes: 1 addition & 1 deletion content/renderer/media/webrtc/video_destination_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class CONTENT_EXPORT PpFrameWriter
virtual void GetCurrentSupportedFormats(
int max_requested_width,
int max_requested_height,
double max_requested_frame_rate,
const VideoCaptureDeviceFormatsCB& callback) OVERRIDE;
virtual void StartSourceImpl(
const media::VideoCaptureParams& params,
Expand Down Expand Up @@ -89,4 +90,3 @@ class CONTENT_EXPORT VideoDestinationHandler {
} // namespace content

#endif // CONTENT_RENDERER_MEDIA_VIDEO_DESTINATION_HANDLER_H_

Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ void PepperMediaStreamVideoTrackHost::OnVideoFrame(

void PepperMediaStreamVideoTrackHost::GetCurrentSupportedFormats(
int max_requested_width, int max_requested_height,
double max_requested_frame_rate,
const VideoCaptureDeviceFormatsCB& callback) {
if (type_ != kWrite) {
DVLOG(1) << "GetCurrentSupportedFormats is only supported in output mode.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class PepperMediaStreamVideoTrackHost : public PepperMediaStreamTrackHostBase,
virtual void GetCurrentSupportedFormats(
int max_requested_width,
int max_requested_height,
double max_requested_frame_rate,
const VideoCaptureDeviceFormatsCB& callback) OVERRIDE;

virtual void StartSourceImpl(
Expand Down

0 comments on commit 683511a

Please sign in to comment.