Commit a05125d4 authored by Kuo Jen Wei's avatar Kuo Jen Wei Committed by Commit Bot

Fix CCA query resolution API not available on HALv1 device bug

Bug: 965933
Test: On HALv1 device the CCA function normally without resolution
settings menu. On HALv3 device the CCA is able to capture with specified
resolution from resolution settings menu.

Change-Id: If22961c55a052a7a6061c62569d88aca69e332d1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1626063
Commit-Queue: Kuo Jen Wei <inker@chromium.org>
Reviewed-by: default avatarSheng-hao Tsao <shenghao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#663002}
parent 0adc1e40
...@@ -1025,6 +1025,10 @@ body._10sec .description span[i18n-content=label_timer_10s], ...@@ -1025,6 +1025,10 @@ body._10sec .description span[i18n-content=label_timer_10s],
background-image: url(../images/settings_timer_duration.svg); background-image: url(../images/settings_timer_duration.svg);
} }
body.no-resolution-settings #settings-resolution {
display: none;
}
#settings-resolution .icon { #settings-resolution .icon {
background-image: url(../images/settings_resolution.svg); background-image: url(../images/settings_resolution.svg);
} }
......
...@@ -240,9 +240,16 @@ cca.views.Camera.prototype.stop_ = function() { ...@@ -240,9 +240,16 @@ cca.views.Camera.prototype.stop_ = function() {
cca.views.Camera.prototype.startWithDevice_ = async function(deviceId) { cca.views.Camera.prototype.startWithDevice_ = async function(deviceId) {
let supportedModes = null; let supportedModes = null;
for (const mode of this.modes_.getModeCandidates()) { for (const mode of this.modes_.getModeCandidates()) {
const previewRs = (await this.options_.getDeviceResolutions(deviceId))[1]; try {
for (const [[width, height], previewCandidates] of this.modes_ const previewRs = (await this.options_.getDeviceResolutions(deviceId))[1];
.getResolutionCandidates(mode, deviceId, previewRs)) { var resolCandidates =
this.modes_.getResolutionCandidates(mode, deviceId, previewRs);
} catch (e) {
// Assume the exception here is thrown from error of HALv1 not support
// resolution query, fallback to use v1 constraints-candidates.
resolCandidates = this.modes_.getResolutionCandidatesV1(mode, deviceId);
}
for (const [captureResolution, previewCandidates] of resolCandidates) {
for (const constraints of previewCandidates) { for (const constraints of previewCandidates) {
try { try {
const stream = await navigator.mediaDevices.getUserMedia(constraints); const stream = await navigator.mediaDevices.getUserMedia(constraints);
...@@ -256,7 +263,8 @@ cca.views.Camera.prototype.startWithDevice_ = async function(deviceId) { ...@@ -256,7 +263,8 @@ cca.views.Camera.prototype.startWithDevice_ = async function(deviceId) {
await this.preview_.start(stream); await this.preview_.start(stream);
this.facingMode_ = this.options_.updateValues(constraints, stream); this.facingMode_ = this.options_.updateValues(constraints, stream);
await this.modes_.updateModeSelectionUI(supportedModes); await this.modes_.updateModeSelectionUI(supportedModes);
await this.modes_.updateMode(mode, stream, deviceId, width, height); await this.modes_.updateMode(
mode, stream, deviceId, captureResolution);
cca.nav.close('warning', 'no-camera'); cca.nav.close('warning', 'no-camera');
return true; return true;
} catch (e) { } catch (e) {
......
...@@ -278,17 +278,29 @@ cca.views.camera.Options.prototype.maybeRefreshVideoDeviceIds_ = function() { ...@@ -278,17 +278,29 @@ cca.views.camera.Options.prototype.maybeRefreshVideoDeviceIds_ = function() {
this.refreshingVideoDeviceIds_ = false; this.refreshingVideoDeviceIds_ = false;
}); });
this.deviceResolutions_ = this.videoDevices_.then((devices) => { this.deviceResolutions_ =
return Promise.all(devices.map((d) => Promise.all([ this.videoDevices_
d, .then((devices) => {
cca.mojo.getPhotoResolutions(d.deviceId), return Promise.all(devices.map((d) => Promise.all([
cca.mojo.getVideoConfigs(d.deviceId) d,
.then((v) => v.filter(([, , fps]) => fps >= 24).map(([w, cca.mojo.getPhotoResolutions(d.deviceId),
h]) => [w, h])), cca.mojo.getVideoConfigs(d.deviceId)
]))); .then(
}); (v) => v.filter(([, , fps]) => fps >= 24)
.map(([w, h]) => [w, h])),
this.deviceResolutions_.then((deviceResolutions) => { ])));
})
.catch((e) => {
cca.state.set('no-resolution-settings', true);
throw e;
});
(async () => {
try {
var deviceResolutions = await this.deviceResolutions_;
} catch (e) {
return;
}
let frontSetting = null; let frontSetting = null;
let backSetting = null; let backSetting = null;
let externalSettings = []; let externalSettings = [];
...@@ -314,7 +326,7 @@ cca.views.camera.Options.prototype.maybeRefreshVideoDeviceIds_ = function() { ...@@ -314,7 +326,7 @@ cca.views.camera.Options.prototype.maybeRefreshVideoDeviceIds_ = function() {
frontSetting && [frontSetting[0], frontSetting[2]], frontSetting && [frontSetting[0], frontSetting[2]],
backSetting && [backSetting[0], backSetting[2]], backSetting && [backSetting[0], backSetting[2]],
externalSettings.map(([deviceId, , videoRs]) => [deviceId, videoRs])); externalSettings.map(([deviceId, , videoRs]) => [deviceId, videoRs]));
}); })();
}; };
/** /**
...@@ -348,6 +360,8 @@ cca.views.camera.Options.prototype.videoDeviceIds = function() { ...@@ -348,6 +360,8 @@ cca.views.camera.Options.prototype.videoDeviceIds = function() {
* @async * @async
* @param {string} deviceId Device id of the video device. * @param {string} deviceId Device id of the video device.
* @return {[ResolList, ResolList]} Supported photo and video resolutions. * @return {[ResolList, ResolList]} Supported photo and video resolutions.
* @throws {Error} May fail on HALv1 device without capability of querying
* supported resolutions.
*/ */
cca.views.camera.Options.prototype.getDeviceResolutions = cca.views.camera.Options.prototype.getDeviceResolutions =
async function(deviceId) { async function(deviceId) {
......
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