From patchwork Fri Apr 24 10:46:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 3514 Return-Path: Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7854062E4D for ; Fri, 24 Apr 2020 12:47:14 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="qos4tUx7"; dkim-atps=neutral Received: by mail-wm1-x344.google.com with SMTP id v4so9683130wme.1 for ; Fri, 24 Apr 2020 03:47:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=gTRrnru+PEsPZVPxI0mivFWeXV0qYZx2apBaEDWKgbI=; b=qos4tUx7wSzuke2rPZSlwDe3iG2qdsEXTD2mRSvwFeMAK4RhYNBRYCdbs3SQTmRa5J Q1FUdL+joqiENOYT5dkL4L3KMlfFUm+hL9flRp2JF4lR4jj9FFlf3E8fPf6jxNmblqZs sKLztGViVndgYxrEtPslpOb+vZltFavf/ByU9h8WOuWjB0w12bCTjDsVTEN0QXNw0Nu2 uqhEC6gfxa+zPTbR+DMcPzS6cwqxjIW++k5KQw8g+Lg4YVUnmCzA0A/+wtA2CA6Fso/M bSw06JbgCkrpIoZzL4EDmxbpnqyjqxOZpSIqlBU37W2oy/0jz7zIcUsjIfQdmR7X99ya ZHvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=gTRrnru+PEsPZVPxI0mivFWeXV0qYZx2apBaEDWKgbI=; b=aZsxxHDZzNTMSJS5cggM0u2XVoJm/rsJ4QFHsJqrNsQWqUPKs5oi8gD2g9xqQ6PO45 GxaFfDhh7CSUPbjX61YaKsEILYXY+Q2kujYh35TEGW0/qF15Te6ZXbeKm6hEGQvfV1K8 +az7Ab2FrlOlCrWw8+Y1FVvO0zAQXy1jzM7dorgCUIr6yYELqs48iCVs0yI0cbGQFNBR THgvq6YZCdrm/gMDS2FGFK/hqW+tGb5ufBdNU/9tNcphKsNU8sFcwQaYQm4g+8zCV8Bc AY4XRR371QmyQEVb1+PL9ZnBmVhxdQbWJ1fIr74VczIJfxFlJv3bOuOXAM6shCMPP2Wb /yjQ== X-Gm-Message-State: AGi0Pua1tYgUbLw8hcEDUDrwIdNZPLSzVs/CiR5BgttIM0zoFJlTCaL+ LyfolOWRknpi8WT81bTw/cjEm37F9rM1mw== X-Google-Smtp-Source: APiQypIiVH0IeCi/DR3TE+Y4QwL726AmNiT3cLXncfHsN+20cLKTIoneCd9pLqOyS3RbdMjuwx2X3Q== X-Received: by 2002:a1c:770f:: with SMTP id t15mr9250290wmi.178.1587725233726; Fri, 24 Apr 2020 03:47:13 -0700 (PDT) Received: from naushir-VirtualBox.patuck.local ([88.97.76.4]) by smtp.gmail.com with ESMTPSA id j68sm7884997wrj.32.2020.04.24.03.47.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Apr 2020 03:47:13 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Fri, 24 Apr 2020 11:46:57 +0100 Message-Id: <20200424104700.26819-3-naush@raspberrypi.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200424104700.26819-1-naush@raspberrypi.com> References: <20200424104700.26819-1-naush@raspberrypi.com> Subject: [libcamera-devel] [PATCH v4 2/5] libcamera: controls: Updates to gain and exposure controls X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 24 Apr 2020 10:47:14 -0000 Rename: ManualExposure -> ExposureTime ManualGain -> AnalogueGain Use micro-seconds units for ExposureTime. This is changed from milli- seconds. The latter would not allow very low exposure times. AnalogueGain switch to use a float to allow fractional gain adjustments. Update the uvcvideo pipeline handler to use the new exposure and gain units. For ExposureTime, UVC uses units of 100 micro-seconds, so map the values before setting V4L2_CID_EXPOSURE_ABSOLUTE. For AnalogueGain, UVC has no explicit gain units, so map the default gain value to 1.0 and linearly scale to the requested value. Signed-off-by: Naushir Patuck Signed-off-by: Laurent Pinchart --- src/libcamera/control_ids.yaml | 22 +++++++----- src/libcamera/pipeline/uvcvideo/uvcvideo.cpp | 37 ++++++++++++++++---- 2 files changed, 44 insertions(+), 15 deletions(-) diff --git a/src/libcamera/control_ids.yaml b/src/libcamera/control_ids.yaml index bcbab195..d8bdb382 100644 --- a/src/libcamera/control_ids.yaml +++ b/src/libcamera/control_ids.yaml @@ -12,7 +12,7 @@ controls: description: | Enable or disable the AE. - \sa ManualExposure + \sa ExposureTime AnalogueGain - AeLocked: type: bool @@ -30,8 +30,6 @@ controls: description: | Enable or disable the AWB. - \sa ManualGain - - Brightness: type: int32_t description: Specify a fixed brightness parameter @@ -44,12 +42,20 @@ controls: type: int32_t description: Specify a fixed saturation parameter - - ManualExposure: + - ExposureTime: type: int32_t - description: Specify a fixed exposure time in milli-seconds + description: | + Exposure time (shutter speed) for the frame applied in the sensor + device. This value is specified in micro-seconds. - - ManualGain: - type: int32_t - description: Specify a fixed gain parameter + \sa AnalogueGain AeEnable + + - AnalogueGain: + type: float + description: | + Analogue gain value applied in the sensor device. + The value of the control specifies the gain multiplier applied to all + colour channels. This value cannot be lower than 1.0. + \sa ExposureTime AeEnable ... diff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp index ffbddf27..b518ad16 100644 --- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp +++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -251,11 +252,24 @@ int PipelineHandlerUVC::processControls(UVCCameraData *data, Request *request) controls.set(V4L2_CID_CONTRAST, value); } else if (id == controls::Saturation) { controls.set(V4L2_CID_SATURATION, value); - } else if (id == controls::ManualExposure) { + } else if (id == controls::ExposureTime) { controls.set(V4L2_CID_EXPOSURE_AUTO, static_cast(1)); - controls.set(V4L2_CID_EXPOSURE_ABSOLUTE, value); - } else if (id == controls::ManualGain) { - controls.set(V4L2_CID_GAIN, value); + /* + * controls::ExposureTime is in units of 1 us, and UVC + * expects V4L2_CID_EXPOSURE_ABSOLUTE in units of 100 us. + */ + controls.set(V4L2_CID_EXPOSURE_ABSOLUTE, + value.get() / 100); + } else if (id == controls::AnalogueGain) { + /* + * controls::AnalogueGain is specified as an absolute + * multiplier for all RGB samples. Map this multiplier + * in a linear way such that 1.0 -> default gain + * of the V4L2_CID_GAIN control on the uvcvideo device. + */ + const ControlInfo &gainInfo = controls.infoMap()->at(V4L2_CID_GAIN); + int32_t gain = lroundf(value.get() * gainInfo.def().get()); + controls.set(V4L2_CID_GAIN, gain); } } @@ -350,7 +364,7 @@ int UVCCameraData::init(MediaEntity *entity) ControlInfoMap::Map ctrls; for (const auto &ctrl : controls) { - const ControlInfo &info = ctrl.second; + ControlInfo info = ctrl.second; const ControlId *id; switch (ctrl.first->id()) { @@ -364,10 +378,19 @@ int UVCCameraData::init(MediaEntity *entity) id = &controls::Saturation; break; case V4L2_CID_EXPOSURE_ABSOLUTE: - id = &controls::ManualExposure; + id = &controls::ExposureTime; break; case V4L2_CID_GAIN: - id = &controls::ManualGain; + id = &controls::AnalogueGain; + /* + * AnalogueGain is a float control, convert the type of + * the range. + */ + info = ControlInfo{ + { static_cast(info.min().get()) }, + { static_cast(info.max().get()) }, + { static_cast(info.def().get()) } + }; break; default: continue;