Unable to limit the gain using nvargussrc

We have a custom board with imx335
We are using the below pipeline to limit the gain up to 30dB

sudo ./test-launch "nvarguscamerasrc gainrange='1 30' ispdigitalgainrange='1 1' exposurecompensation=0.42 aeantibanding=1 ! video/x-raw(memory:NVMM), width=2616, height=1964, framerate=30/1 ! nvvidconv ! nvv4l2h264enc control-rate=1 bitrate=8000000 ! rtph264pay name=pay0 pt=96 config-interval=1"
stream ready at rtsp://127.0.0.1:8554/test

while observing the camera driver logs, the gain is not limited to the given 30db

[  126.676170] imx335 6-001a: imx335_set_gain: gain reg 64, val 1940
[  126.710503] imx335 6-001a: imx335_set_gain: gain reg 64, val 1944
[  126.743525] imx335 6-001a: imx335_set_gain: gain reg 65, val 1974

Gain configuration of imx335 sensor

                                        gain_factor = "100";
                                        min_gain_val = "0";     /* 0dB */
                                        max_gain_val = "7200";  /* 72dB */
                                        step_gain_val = "3";    /* 0.3 */
                                        default_gain = "0";

Could you please help to sort out the issue to limit the gain to 30db using the gstreamer pipeline mentioned

hello krishnaprasad.k,

could you please also check with $ v4l2-ctl --all, and sharing the results.

Thanks for the info

Please check the output of v4l2-ctl --all

Driver Info (not using libv4l2):
    Driver name   : tegra-video
    Card type     : vi-output, imx335 6-001a
    Bus info      : platform:54080000.vi:0
    Driver version: 4.9.253
    Capabilities  : 0x84200001
        Video Capture
        Streaming
        Extended Pix Format
        Device Capabilities
    Device Caps   : 0x04200001
        Video Capture
        Streaming
        Extended Pix Format
Priority: 2
Video input : 0 (Camera 0: no power)
Format Video Capture:
    Width/Height      : 2592/1944
    Pixel Format      : 'RG10'
    Field             : None
    Bytes per Line    : 5184
    Size Image        : 10077696
    Colorspace        : sRGB
    Transfer Function : Default (maps to sRGB)
    YCbCr/HSV Encoding: Default (maps to ITU-R 601)
    Quantization      : Default (maps to Full Range)
    Flags             : 

Camera Controls

                     group_hold 0x009a2003 (bool)   : default=0 value=0 flags=execute-on-write
                    sensor_mode 0x009a2008 (int64)  : min=0 max=0 step=0 default=0 value=0 flags=slider
                           gain 0x009a2009 (int64)  : min=0 max=0 step=0 default=0 value=0 flags=slider
                       exposure 0x009a200a (int64)  : min=0 max=0 step=0 default=0 value=16 flags=slider
                     frame_rate 0x009a200b (int64)  : min=0 max=0 step=0 default=0 value=2000000 flags=slider
                    bypass_mode 0x009a2064 (intmenu): min=0 max=1 default=0 value=0
                override_enable 0x009a2065 (intmenu): min=0 max=1 default=0 value=0
                   height_align 0x009a2066 (int)    : min=1 max=16 step=1 default=1 value=1
                     size_align 0x009a2067 (intmenu): min=0 max=2 default=0 value=0
               write_isp_format 0x009a2068 (bool)   : default=0 value=0
       sensor_signal_properties 0x009a2069 (u32)    : min=0 max=0 step=0 default=0 flags=read-only, has-payload
        sensor_image_properties 0x009a206a (u32)    : min=0 max=0 step=0 default=0 flags=read-only, has-payload
      sensor_control_properties 0x009a206b (u32)    : min=0 max=0 step=0 default=0 flags=read-only, has-payload
              sensor_dv_timings 0x009a206c (u32)    : min=0 max=0 step=0 default=0 flags=read-only, has-payload
               low_latency_mode 0x009a206d (bool)   : default=0 value=0
               preferred_stride 0x009a206e (int)    : min=0 max=65535 step=1 default=0 value=0
                   sensor_modes 0x009a2082 (int)    : min=0 max=30 step=1 default=30 value=1 flags=read-only

Hi @krishnaprasad.k
The gainrange just sets the values that nvarguscamerasrc can use. The actual value written to the gain register is controlled by the driver. This issue could be caused by how your drivers set_gain function works.

Your driver could be receiving a value in the 1-30 range but then this could be processed and result in a larger value written to the register.

Can you also check how the gain control works with v4l2-ctl and share the output and kernel log:

v4l2-ctl -d /dev/video0 --set-ctrl gain=100
v4l2-ctl --all

Hi @jafeth.garcia @JerryChang
Sorry for the late reply
We have set the gain value 30dB using nvarguscamerasrc plugin properties
we have used this pipeline to achieve to set a constant gain of 30dB

sudo ./test-launch "nvarguscamerasrc gainrange='1 30' ispdigitalgainrange='1 1' exposurecompensation=0.42 aeantibanding=1 ! video/x-raw(memory:NVMM), width=2616, height=1964, framerate=30/1 ! nvvidconv ! nvv4l2h264enc control-rate=1 bitrate=8000000 ! rtph264pay name=pay0 pt=96 config-interval=1"
stream ready at rtsp://127.0.0.1:8554/test
GST_ARGUS: NvArgusCameraSrc: Setting Gain Range : '1 30'
GST_ARGUS: Invalid Gain Range Input
GST_ARGUS: NvArgusCameraSrc: Setting ISP Digital Gain Range : '1 1'
Opening in BLOCKING MODE 
NvMMLiteOpen : Block : BlockType = 4 
===== NVMEDIA: NVENC =====
NvMMLiteBlockCreate : Block : BlockType = 4 
GST_ARGUS: Creating output stream
CONSUMER: Waiting until producer is connected...
GST_ARGUS: Available Sensor modes :
GST_ARGUS: 2616 x 1964 FR = 29.999999 fps Duration = 33333334 ; Analog Gain range min 1.000000, max 3981.070801; Exposure Range min 16000, max 66533000;

but when we enabled driver logs, it seems gain value is changed according to the environment

[ 1381.550289] imx335 6-001a: imx335_set_gain: gain reg 36, val 1098
[ 1381.829538] imx335 6-001a: imx335_set_gain: gain reg 0, val 0
[ 1382.109674] imx335 6-001a: imx335_set_gain: gain reg 2, val 60
[ 1382.143755] imx335 6-001a: imx335_set_gain: gain reg 4, val 120
[ 1382.176372] imx335 6-001a: imx335_set_gain: gain reg 6, val 180
[ 1382.209611] imx335 6-001a: imx335_set_gain: gain reg 8, val 240
[ 1382.243369] imx335 6-001a: imx335_set_gain: gain reg 10, val 300
[ 1382.276615] imx335 6-001a: imx335_set_gain: gain reg 12, val 360
[ 1382.315049] imx335 6-001a: imx335_set_gain: gain reg 14, val 420
[ 1382.343689] imx335 6-001a: imx335_set_gain: gain reg 16, val 480
[ 1382.377853] imx335 6-001a: imx335_set_gain: gain reg 18, val 540
[ 1382.410905] imx335 6-001a: imx335_set_gain: gain reg 20, val 603
[ 1382.444374] imx335 6-001a: imx335_set_gain: gain reg 22, val 663
[ 1382.484738] imx335 6-001a: imx335_set_gain: gain reg 24, val 723
[ 1382.514194] imx335 6-001a: imx335_set_gain: gain reg 26, val 783
[ 1382.544504] imx335 6-001a: imx335_set_gain: gain reg 28, val 843
[ 1382.576878] imx335 6-001a: imx335_set_gain: gain reg 29, val 870
[ 1382.614663] imx335 6-001a: imx335_set_gain: gain reg 29, val 885
[ 1382.644896] imx335 6-001a: imx335_set_gain: gain reg 29, val 891
[ 1388.575194] imx335 6-001a: imx335_set_gain: gain reg 31, val 954
[ 1388.609403] imx335 6-001a: imx335_set_gain: gain reg 33, val 1014
[ 1388.641909] imx335 6-001a: imx335_set_gain: gain reg 35, val 1074
[ 1388.675453] imx335 6-001a: imx335_set_gain: gain reg 37, val 1134
[ 1388.712128] imx335 6-001a: imx335_set_gain: gain reg 39, val 1194
[ 1388.741621] imx335 6-001a: imx335_set_gain: gain reg 41, val 1254
[ 1388.776196] imx335 6-001a: imx335_set_gain: gain reg 43, val 1314
[ 1388.809675] imx335 6-001a: imx335_set_gain: gain reg 45, val 1374
[ 1388.841754] imx335 6-001a: imx335_set_gain: gain reg 47, val 1434
[ 1388.875643] imx335 6-001a: imx335_set_gain: gain reg 49, val 1494
[ 1388.908441] imx335 6-001a: imx335_set_gain: gain reg 51, val 1554
[ 1388.941499] imx335 6-001a: imx335_set_gain: gain reg 53, val 1614
[ 1388.975292] imx335 6-001a: imx335_set_gain: gain reg 55, val 1674
[ 1389.008129] imx335 6-001a: imx335_set_gain: gain reg 57, val 1734
[ 1389.041646] imx335 6-001a: imx335_set_gain: gain reg 59, val 1794
[ 1389.075740] imx335 6-001a: imx335_set_gain: gain reg 61, val 1857

So what is the real use of gainrange property in nvarguscamerasrc, if we need to capture an image for 30dB gain range do we need to disable autoexposure with and set the gain using v4l-ctl is that what you are suggesting for our use case please comment on this

hello krishnaprasad.k,

here shows failure, it looks gain range did not apply correctly.
it should be double quotes to assign the property settings according to $ gst-inspect-1.0 nvarguscamerasrc
re-cap as following for an example.

  gainrange           : Property to adjust gain range
                        Use string with values of Gain Time Range (low, high)
                        in that order, to set the property.
                        eg: gainrange="1 16"

please also note it’s by default using analog gain, you should toggle use_decibel_gain as true, and please refer to below formula for using decibels gain.
i.e. dB = 20 × log(analog gain)

Hi @JerryChang
Thanks for the corrections, we have used this pipeline

sudo ./test-launch "nvarguscamerasrc gainrange=\"1 32\" ispdigitalgainrange='1 1' exposurecompensation=0.42 aeantibanding=1 ! video/x-raw(memory:NVMM), width=2616, height=1964, framerate=30/1 ! nvvidconv ! nvv4l2h264enc control-rate=1 bitrate=8000000 ! rtph264pay name=pay0 pt=96 config-interval=1"
stream ready at rtsp://127.0.0.1:8554/test
GST_ARGUS: NvArgusCameraSrc: Setting Gain Range : 1 32
GST_ARGUS: Invalid Gain Range Input
GST_ARGUS: NvArgusCameraSrc: Setting ISP Digital Gain Range : '1 1'
Opening in BLOCKING MODE
in device tree camera gain properties 

use_decibel_gain = “true”;
gain_factor = “100”;
min_gain_val = “0”; /* 0dB /
max_gain_val = “7200”; /
72dB /
step_gain_val = “3”; /
0.3 */
default_gain = “0”;

What value should we give to the gainrange property to achieve this 30dB gain, please comment on this?

@krishnaprasad.k if you want a fixed gain to be used (and for this value to not change from the specified value) you have to limit the range to that value. The gainrange specifies which values the autoexposure can use to give a better image. If you want to disable the autoexposure, set nvarguscamerasrc property aelock=1.

To limit the gainrange you can set it similar to this:

nvarguscamerasrc gainrange=\"30 30\" ispdigitalgainrange='1 1' exposurecompensation=0.42 aeantibanding=1 ! video/x-raw(memory:NVMM), width=2616, height=1964, framerate=30/1 ! nvvidconv ! nvv4l2h264enc control-rate=1 bitrate=8000000 ! rtph264pay name=pay0 pt=96 config-interval=1

Hi @jafeth.garcia
Thanks for the response
I will check your pipeline and share the result

nvarguscamerasrc gainrange=\"30 30\" ispdigitalgainrange='1 1' exposurecompensation=0.42 aeantibanding=1 ! video/x-raw(memory:NVMM), width=2616, height=1964, framerate=30/1 ! nvvidconv ! nvv4l2h264enc control-rate=1 bitrate=8000000 ! rtph264pay name=pay0 pt=96 config-interval=1

But when I used the gain range value beyond the limit 16 it shows invalid gain range input
I used the below pipeline

./test-launch "nvarguscamerasrc gainrange=\"1 32\" ispdigitalgainrange=\"1 1\" exposurecompensation=0.42 aeantibanding=1 ! video/x-raw(memory:NVMM), width=2616, height=1964, framerate=30/1 ! nvvidconv ! nvv4l2h264enc control-rate=1 bitrate=8000000 ! rtph264pay name=pay0 pt=96 config-interval=1"

Is this any limitation from nvarguscamerasrc gainrange properties for jetson nano
Can you please comment how to resolve this issues @JerryChang?

hello krishnaprasad.k,

let me double confirm the Jetpack release version, please check $ cat /etc/nv_tegra_release for confirmation.
besides checking with nvarguscamerasrc, could you please give it a try with argus_camera application, there’re user-interface for setting sensor controls, including gain range.

@JerryChang thanks for the response

cat /etc/nv_tegra_release 
# R32 (release), REVISION: 7.4, GCID: 33514132, BOARD: t210ref, EABI: aarch64, DATE: Fri Jun  9 04:25:08 UTC 2023

Our custom board don’t have the display port, Argus application will work without display port? So, can you specify any other method to achieve our use case?

hello krishnaprasad.k,

it’s calling Argus::ISourceSettings::setGainRange to set the gain range for the sensor.
since it’s reporting Invalid Gain Range Input, your settings did not apply to camera software stack.

please give it a try with…
$ gst-launch-1.0 nvarguscamerasrc sensor-id=0 sensor-mode=0 gainrange="1.0 2.0" ! 'video/x-raw(memory:NVMM),width=1920, height=1080, framerate=30/1, format=NV12' ! nvoverlaysink -ev

Hi @JerryChang
Thanks for the input we will check the below pipeline and confirm

gst-launch-1.0 nvarguscamerasrc sensor-id=0 sensor-mode=0 gainrange="1.0 2.0" ! 'video/x-raw(memory:NVMM),width=1920, height=1080, framerate=30/1, format=NV12' ! nvoverlaysink -ev

But we need to limit the linear scale gain beyond 16 Can you confirm that is that limitation of nvarguscamerasrc in jetson nano?

@krishnaprasad.k I have seen that this is indeed a limitation within the nvarguscamerasrc element. You can apply a patch to the element to allow for a larger gain limit.

This will extend what values are considered as valid by the plugin. You can find this in the gstnvarguscamerasrc.cpp as the MAX_GAIN

#define MIN_BUFFERS 6
#define MAX_BUFFERS 8

#define MIN_GAIN 1
#define MAX_GAIN 16

#define MIN_EXPOSURE_TIME 34000
#define MAX_EXPOSURE_TIME 358733000

#define MIN_DIGITAL_GAIN 1
#define MAX_DIGITAL_GAIN 256

You should be able to get the source for the nvarguscamerasrc element from the download center (Driver package (BSP) sources):

Just untar the package and under Linux_for_Tegra/source/public you should see the st-nvarguscamera_src.tbz2 package where the sources are.

Hi @jafeth.garcia

Thanks for the input
How to reflect this change in our image as we are currently fetching the source files from the script only in the Jetpack SDK

We are Unable to download the source files from this link

I have seen that this is indeed a limitation within the nvarguscamerasrc element

@JerryChang Do you agree to this point?

hello krishnaprasad.k,

please try again to visit this page, https://developer.nvidia.com/embedded/linux-tegra-r3274
yes, there’s limitation within the nvarguscamerasrc element, please update the sources accordingly.

@JerryChang Thanks for the input
Unable to connect to this link, can you try this from your end?

it looks okay to me, I’m able to open that linux-tegra-r3274 page and also download BSP sources.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.