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],
background-image: url(../images/settings_timer_duration.svg);
}
body.no-resolution-settings #settings-resolution {
display: none;
}
#settings-resolution .icon {
background-image: url(../images/settings_resolution.svg);
}
......
......@@ -240,9 +240,16 @@ cca.views.Camera.prototype.stop_ = function() {
cca.views.Camera.prototype.startWithDevice_ = async function(deviceId) {
let supportedModes = null;
for (const mode of this.modes_.getModeCandidates()) {
try {
const previewRs = (await this.options_.getDeviceResolutions(deviceId))[1];
for (const [[width, height], previewCandidates] of this.modes_
.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) {
try {
const stream = await navigator.mediaDevices.getUserMedia(constraints);
......@@ -256,7 +263,8 @@ cca.views.Camera.prototype.startWithDevice_ = async function(deviceId) {
await this.preview_.start(stream);
this.facingMode_ = this.options_.updateValues(constraints, stream);
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');
return true;
} catch (e) {
......
......@@ -278,17 +278,29 @@ cca.views.camera.Options.prototype.maybeRefreshVideoDeviceIds_ = function() {
this.refreshingVideoDeviceIds_ = false;
});
this.deviceResolutions_ = this.videoDevices_.then((devices) => {
this.deviceResolutions_ =
this.videoDevices_
.then((devices) => {
return Promise.all(devices.map((d) => Promise.all([
d,
cca.mojo.getPhotoResolutions(d.deviceId),
cca.mojo.getVideoConfigs(d.deviceId)
.then((v) => v.filter(([, , fps]) => fps >= 24).map(([w,
h]) => [w, h])),
.then(
(v) => v.filter(([, , fps]) => fps >= 24)
.map(([w, h]) => [w, h])),
])));
})
.catch((e) => {
cca.state.set('no-resolution-settings', true);
throw e;
});
this.deviceResolutions_.then((deviceResolutions) => {
(async () => {
try {
var deviceResolutions = await this.deviceResolutions_;
} catch (e) {
return;
}
let frontSetting = null;
let backSetting = null;
let externalSettings = [];
......@@ -314,7 +326,7 @@ cca.views.camera.Options.prototype.maybeRefreshVideoDeviceIds_ = function() {
frontSetting && [frontSetting[0], frontSetting[2]],
backSetting && [backSetting[0], backSetting[2]],
externalSettings.map(([deviceId, , videoRs]) => [deviceId, videoRs]));
});
})();
};
/**
......@@ -348,6 +360,8 @@ cca.views.camera.Options.prototype.videoDeviceIds = function() {
* @async
* @param {string} deviceId Device id of the video device.
* @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 =
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