Commit b76cd025 authored by Wei Lee's avatar Wei Lee Committed by Commit Bot

Removes cache fps range when SetFpsRange() gets invalid input

This CL removes cache fps range entry if SetFpsRange() gets invalid input so that it will use default fps range rather than
unexpected cache range.

In addition, it fixes a bug of method typo in options.js and avoids reporting error when the SetFpsRange() fails intendedly.

Bug: None
Test: Manually.

Change-Id: I924a663607a5d0829c8f0aa5873a7488aca072f8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1687569
Auto-Submit: Wei Lee <wtlee@chromium.org>
Reviewed-by: default avatarShik Chen <shik@chromium.org>
Reviewed-by: default avatarRobert Sesek <rsesek@chromium.org>
Reviewed-by: default avatarSheng-hao Tsao <shenghao@chromium.org>
Commit-Queue: Wei Lee <wtlee@chromium.org>
Cr-Commit-Position: refs/heads/master@{#676309}
parent f1ddcc97
...@@ -342,12 +342,21 @@ cca.mojo.getUserMedia = function(deviceId, constraints) { ...@@ -342,12 +342,21 @@ cca.mojo.getUserMedia = function(deviceId, constraints) {
streamHeight = constraints.video.height; streamHeight = constraints.video.height;
} }
let hasSpecifiedFrameRateRange = minFrameRate > 0 && maxFrameRate > 0;
// If the frame rate range is specified in |constraints|, we should try to set
// the frame rate range and should report error if fails since it is
// unexpected.
//
// Otherwise, if the frame rate is incomplete or totally missing in
// |constraints| , we assume the app wants to use default frame rate range.
// We set the frame rate range to an invalid range (e.g. 0 fps) so that it
// will fallback to use the default one.
try { try {
return cca.mojo.MojoInterface.getProxy() return cca.mojo.MojoInterface.getProxy()
.setFpsRange( .setFpsRange(
deviceId, streamWidth, streamHeight, minFrameRate, maxFrameRate) deviceId, streamWidth, streamHeight, minFrameRate, maxFrameRate)
.then(({isSuccess}) => { .then(({isSuccess}) => {
if (!isSuccess) { if (!isSuccess && hasSpecifiedFrameRateRange) {
console.error('Failed to negotiate the frame rate range.'); console.error('Failed to negotiate the frame rate range.');
} }
return navigator.mediaDevices.getUserMedia(constraints); return navigator.mediaDevices.getUserMedia(constraints);
......
...@@ -33,14 +33,15 @@ interface CrosImageCapture { ...@@ -33,14 +33,15 @@ interface CrosImageCapture {
SetReprocessOption(string source_id, Effect effect) SetReprocessOption(string source_id, Effect effect)
=> (int32 status, media.mojom.Blob blob); => (int32 status, media.mojom.Blob blob);
// Sets the frame rate range for upcoming configured camera stream. // Sets the fps range for upcoming configured camera stream.
// The |source_id| might need translation to be actual video device id. // The |source_id| might need translation to be actual video device id.
// The |stream_width| and |stream_height| are the target stream resolution // The |stream_width| and |stream_height| are the target stream resolution
// that the caller sets the frame rate range for. // that the caller sets the fps range for.
// The |min_frame_rate| and |max_frame_rate| represent the frame rate range. // The |min_fps| and |max_fps| represent the target fps range.
// If the given frame rate is valid and set successfully, |is_success| returns // If the given fps range is valid and set successfully, |is_success| returns
// true. False otherwise. // true. If the given fps range is invalid, the fps range which is cached
// previously will be cleared and |is_success| will return false.
SetFpsRange(string source_id, uint32 stream_width, uint32 stream_height, SetFpsRange(string source_id, uint32 stream_width, uint32 stream_height,
int32 min_frame_rate, int32 max_frame_rate) int32 min_fps, int32 max_fps)
=> (bool is_success); => (bool is_success);
}; };
\ No newline at end of file
...@@ -211,14 +211,21 @@ void ReprocessManager::ReprocessManagerImpl::SetFpsRange( ...@@ -211,14 +211,21 @@ void ReprocessManager::ReprocessManagerImpl::SetFpsRange(
} }
} }
auto resolution = gfx::Size(stream_width, stream_height);
auto& fps_map = resolution_fps_range_map_[device_id];
if (!is_valid) { if (!is_valid) {
// If the input range is invalid, we should still clear the cache range so
// that it will fallback to use default fps range rather than the cache one.
auto it = fps_map.find(resolution);
if (it != fps_map.end()) {
fps_map.erase(it);
}
std::move(callback).Run(false); std::move(callback).Run(false);
return; return;
} }
auto resolution = gfx::Size(stream_width, stream_height);
auto fps_range = gfx::Range(min_fps, max_fps); auto fps_range = gfx::Range(min_fps, max_fps);
resolution_fps_range_map_[device_id][resolution] = fps_range; fps_map[resolution] = fps_range;
std::move(callback).Run(true); std::move(callback).Run(true);
} }
......
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