Commit b0f964e1 authored by Shik Chen's avatar Shik Chen Committed by Commit Bot

CCA: Show camera name, id and resolution in expert mode

This CL sets model_id for built-in USB cameras and shows camera name, id
(USB pid:vid), and resolution in expert mode preview overlay.

Bug: b/167127091
Test: Manually check expert mode result
Change-Id: I860152cd1e044e2f224a346134e6bdc81ebe5b96
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2397037Reviewed-by: default avatarWei Lee <wtlee@chromium.org>
Commit-Queue: Shik Chen <shik@chromium.org>
Cr-Commit-Position: refs/heads/master@{#804842}
parent 4951210d
......@@ -314,6 +314,13 @@ export class Preview {
},
};
// These should be per session static information and we don't need to
// recalculate them in every callback.
const {videoWidth, videoHeight} = this.video_;
const resolution = `${videoWidth}x${videoHeight}`;
const videoTrack = this.stream_.getVideoTracks()[0];
const deviceName = videoTrack.label;
// Currently there is no easy way to calculate the fps of a video element.
// Here we use the metadata events to calculate a reasonable approximation.
const updateFps = (() => {
......@@ -333,6 +340,8 @@ export class Preview {
})();
const callback = (metadata) => {
showValue('#preview-resolution', resolution);
showValue('#preview-device-name', deviceName);
const fps = updateFps();
if (fps !== null) {
showValue('#preview-fps', `${fps.toFixed(0)} FPS`);
......@@ -354,7 +363,7 @@ export class Preview {
return;
}
const deviceId = this.stream_.getVideoTracks()[0].getSettings().deviceId;
const deviceId = videoTrack.getSettings().deviceId;
this.metadataObserverId_ = await deviceOperator.addMetadataObserver(
deviceId, callback, cros.mojom.StreamType.PREVIEW_OUTPUT);
}
......
......@@ -35,6 +35,11 @@
</div>
<video id="preview-video" class="preview-content"></video>
<div id="preview-metadata">
<div id="preview-info" class="metadata-row mode-on">
<span class="metadata-category">Info</span>
<div id="preview-resolution" class="metadata-value"></div>
<div id="preview-device-name" class="metadata-value"></div>
</div>
<div id="preview-stat" class="metadata-row mode-on">
<span class="metadata-category">Stat</span>
<div id="preview-fps" class="metadata-value"></div>
......
......@@ -293,6 +293,17 @@ void CameraHalDelegate::GetDevicesInfo(
if (!camera_info) {
continue;
}
auto get_vendor_string = [&](const std::string& key) -> const char* {
const VendorTagInfo* info = vendor_tag_ops_delegate_.GetInfoByName(key);
if (info == nullptr) {
return nullptr;
}
auto val = GetMetadataEntryAsSpan<char>(
camera_info->static_camera_characteristics, info->tag);
return val.empty() ? nullptr : val.data();
};
VideoCaptureDeviceDescriptor desc;
desc.capture_api = VideoCaptureApi::ANDROID_API2_LIMITED;
desc.transport_type = VideoCaptureTransportType::OTHER_TRANSPORT;
......@@ -310,17 +321,6 @@ void CameraHalDelegate::GetDevicesInfo(
case cros::mojom::CameraFacing::CAMERA_FACING_EXTERNAL: {
desc.facing = VideoFacingMode::MEDIA_VIDEO_FACING_NONE;
auto get_vendor_string = [&](const std::string& key) -> const char* {
const VendorTagInfo* info =
vendor_tag_ops_delegate_.GetInfoByName(key);
if (info == nullptr) {
return nullptr;
}
auto val = GetMetadataEntryAsSpan<char>(
camera_info->static_camera_characteristics, info->tag);
return val.empty() ? nullptr : val.data();
};
// The webcam_private api expects that |device_id| to be set as the
// corresponding device path for external cameras used in GVC system.
auto* path = get_vendor_string("com.google.usb.devicePath");
......@@ -330,16 +330,16 @@ void CameraHalDelegate::GetDevicesInfo(
auto* name = get_vendor_string("com.google.usb.modelName");
desc.set_display_name(name != nullptr ? name : "External Camera");
auto* vid = get_vendor_string("com.google.usb.vendorId");
auto* pid = get_vendor_string("com.google.usb.productId");
if (vid != nullptr && pid != nullptr) {
desc.model_id = base::StrCat({vid, ":", pid});
}
break;
// Mojo validates the input parameters for us so we don't need to
// worry about malformed values.
}
}
auto* vid = get_vendor_string("com.google.usb.vendorId");
auto* pid = get_vendor_string("com.google.usb.productId");
if (vid != nullptr && pid != nullptr) {
desc.model_id = base::StrCat({vid, ":", pid});
}
desc.set_pan_tilt_zoom_supported(IsPanTiltZoomSupported(camera_info));
device_id_to_camera_id_[desc.device_id] = camera_id;
devices_info.emplace_back(desc);
......
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