Commit 88fcefac authored by delima02's avatar delima02 Committed by Commit Bot

Reset Aver cameras to their home position using an extension unit

Bug: b:139355993
Change-Id: If5a0ddae8b277f7487b7a3a4aa744a312a574181
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1841946Reviewed-by: default avatarZachary Kuznia <zork@chromium.org>
Commit-Queue: Juan Pablo De Lima <jpdelima@chromium.org>
Auto-Submit: Juan Pablo De Lima <jpdelima@chromium.org>
Cr-Commit-Position: refs/heads/master@{#703888}
parent 7fddc4e8
......@@ -21,19 +21,45 @@
// GUID of the Extension Unit for Logitech CC3300e motor control:
// {212de5ff-3080-2c4e-82d9-f587d00540bd}
#define UVC_GUID_LOGITECH_CC3000E_MOTORS \
{0x21, 0x2d, 0xe5, 0xff, 0x30, 0x80, 0x2c, 0x4e, \
0x82, 0xd9, 0xf5, 0x87, 0xd0, 0x05, 0x40, 0xbd}
#define UVC_GUID_LOGITECH_CC3000E_MOTORS \
{ \
0x21, 0x2d, 0xe5, 0xff, 0x30, 0x80, 0x2c, 0x4e, 0x82, 0xd9, 0xf5, 0x87, \
0xd0, 0x05, 0x40, 0xbd \
}
// GUID of the Extension Unit for AVER XU1 motor control:
// {cb666936-6e26-a047-8451-96ecf60330d6}
#define UVC_GUID_AVER \
{ \
0xcb, 0x66, 0x69, 0x36, 0x6e, 0x26, 0xa0, 0x47, 0x84, 0x51, 0x96, 0xec, \
0xf6, 0x03, 0x30, 0xd6 \
}
#define LOGITECH_MOTORCONTROL_PANTILT_CMD 2
#define AVER_UVCX_UCAM_PRESET 0x12
namespace {
const int kLogitechMenuIndexGoHome = 2;
const int kAverMenuIndexGoHome = 1;
const uvc_menu_info kLogitechCmdMenu[] = {
{1, "Set Preset"}, {2, "Get Preset"}, {3, "Go Home"}
};
// Preset 0 is equivalent to HOME in Aver cameras.
const uvc_menu_info kAverPresetMenu[] = {
/*0*/ {0x0000, "Set Preset 0"}, /*1*/ {0x0001, "Restore preset 0"},
/*2*/ {0x0100, "Set Preset 1"}, /*3*/ {0x0101, "Restore preset 1"},
/*4*/ {0x0200, "Set Preset 2"}, /*5*/ {0x0202, "Restore preset 2"},
/*6*/ {0x0300, "Set Preset 3"}, /*7*/ {0x0303, "Restore preset 3"},
/*8*/ {0x0400, "Set Preset 4"}, /*9*/ {0x0404, "Restore preset 4"},
/*10*/ {0x0500, "Set Preset 5"}, /*11*/ {0x0505, "Restore preset 5"},
/*12*/ {0x0600, "Set Preset 6"}, /*13*/ {0x0606, "Restore preset 6"},
/*14*/ {0x0700, "Set Preset 7"}, /*15*/ {0x0707, "Restore preset 7"},
/*16*/ {0x0800, "Set Preset 8"}, /*17*/ {0x0808, "Restore preset 8"},
/*18*/ {0x0900, "Set Preset 9"}, /*19*/ {0x0909, "Restore preset 9"},
};
const uvc_xu_control_mapping kLogitechCmdMapping = {
V4L2_CID_PANTILT_CMD,
"Pan/Tilt Go",
......@@ -69,6 +95,19 @@ const uvc_xu_control_mapping kLogitechTiltAbsoluteMapping = {
UVC_CTRL_DATA_TYPE_SIGNED,
};
const uvc_xu_control_mapping kAverCmdMapping = {
V4L2_CID_PANTILT_CMD,
"PTZ Preset",
UVC_GUID_AVER,
AVER_UVCX_UCAM_PRESET,
24,
0,
V4L2_CTRL_TYPE_MENU,
UVC_CTRL_DATA_TYPE_ENUM,
const_cast<uvc_menu_info*>(kAverPresetMenu),
base::size(kAverPresetMenu),
};
} // namespace
namespace extensions {
......@@ -94,6 +133,14 @@ bool V4L2Webcam::EnsureLogitechCommandsMapped() {
return res >= 0 || errno == EEXIST || errno == EFAULT;
}
bool V4L2Webcam::EnsureAverCommandsMapped() {
int res = HANDLE_EINTR(ioctl(fd_.get(), UVCIOC_CTRL_MAP, &kAverCmdMapping));
// If mapping is successful or it's already mapped, this is an Aver camera.
// NOTE: On success, occasionally EFAULT is returned. On a real error,
// ENOMEM, EPERM, EINVAL, or EOVERFLOW should be returned.
return res >= 0 || errno == EEXIST || errno == EFAULT;
}
bool V4L2Webcam::SetWebcamParameter(int fd, uint32_t control_id, int value) {
// Try to map the V4L2 control to the Logitech extension unit. If the
// connected camera does not implement these extension unit this will just
......@@ -251,6 +298,12 @@ void V4L2Webcam::Reset(bool pan,
callback.Run(false);
return;
}
} else if (EnsureAverCommandsMapped()) {
if (!SetWebcamParameter(fd_.get(), V4L2_CID_PANTILT_CMD,
kAverMenuIndexGoHome)) {
callback.Run(false);
return;
}
} else {
if (pan) {
struct v4l2_control v4l2_ctrl = {V4L2_CID_PAN_RESET};
......
......@@ -22,6 +22,7 @@ class V4L2Webcam : public Webcam {
private:
~V4L2Webcam() override;
bool EnsureLogitechCommandsMapped();
bool EnsureAverCommandsMapped();
static bool SetWebcamParameter(int fd, uint32_t control_id, int value);
static bool GetWebcamParameter(int fd,
uint32_t control_id,
......
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