peterbay / uvc-gadget

uvc-gadget with resolution changing and video controls
GNU General Public License v2.0
81 stars 24 forks source link

brightness setting in camera.txt is being ignored #11

Closed zlorfi closed 3 years ago

zlorfi commented 3 years ago

After writing /boot/camera.txt with

#Tweak the auto exposure bias
auto_exposure_bias=15
#Tweak the brightness
brightness=55

the auto_expose_bias value is being honoured, but not the brightness value.

# /usr/bin/v4l2-ctl -L

User Controls

             brightness 0x00980900 (int)    : min=0 max=100 step=1 default=50 value=50 flags=slider
[...]          
             auto_exposure_bias 0x009a0913 (intmenu): min=0 max=24 default=12 value=15
[...]

Any idea how to fix this problem? In order to have the brightness at 55 after a reboot, I have to set it manually via /usr/bin/v4l2-ctl -c brightness=55 which seems to work until the next reboot.

This is the journalctl output:

Feb 07 15:50:57 piwebcam systemd[1]: Started Serial Getty on ttyAMA0.
Feb 07 15:50:58 piwebcam ifup[103]: ifup: can't open '/var/run/ifstate.new': No such file or directory
Feb 07 15:50:58 piwebcam systemd[1]: network.service: Main process exited, code=exited, status=1/FAILURE
Feb 07 15:50:58 piwebcam systemd[1]: network.service: Failed with result 'exit-code'.
Feb 07 15:50:58 piwebcam systemd[1]: Failed to start Network Connectivity.
Feb 07 15:50:58 piwebcam systemd[1]: Reached target Network.
Feb 07 15:50:58 piwebcam systemd[1]: Found device /dev/ttyGS0.
Feb 07 15:50:58 piwebcam systemd[1]: Started Serial Getty on ttyGS0.
Feb 07 15:50:58 piwebcam systemd[1]: Reached target Login Prompts.
Feb 07 15:50:58 piwebcam systemd[1]: Reached target Multi-User System.
Feb 07 15:50:58 piwebcam systemd[1]: Starting Update UTMP about System Runlevel Changes...
Feb 07 15:50:58 piwebcam systemd[1]: systemd-update-utmp-runlevel.service: Succeeded.
Feb 07 15:50:58 piwebcam systemd[1]: Started Update UTMP about System Runlevel Changes.
Feb 07 15:50:58 piwebcam systemd[1]: Startup finished in 2.180s (kernel) + 6.930s (userspace) = 9.110s.
Feb 07 15:50:58 piwebcam kernel: configfs-gadget gadget: uvc: uvc_function_bind()
Feb 07 15:50:58 piwebcam kernel: dwc2 20980000.usb: bound driver configfs-gadget
Feb 07 15:50:59 piwebcam piwebcam[170]: Found camera.txt, applying settings
Feb 07 15:50:59 piwebcam piwebcam[182]: Setting auto_exposure_bias -> 15
Feb 07 15:50:59 piwebcam piwebcam[190]: Setting brightness -> 55
Feb 07 15:50:59 piwebcam kernel: dwc2 20980000.usb: new device is high-speed
Feb 07 15:50:59 piwebcam kernel: dwc2 20980000.usb: new address 18
Feb 07 15:50:59 piwebcam kernel: configfs-gadget gadget: high-speed config #2: c
Feb 07 15:50:59 piwebcam kernel: configfs-gadget gadget: uvc: uvc_function_set_alt(0, 0)
Feb 07 15:50:59 piwebcam kernel: configfs-gadget gadget: uvc: reset UVC Control
Feb 07 15:50:59 piwebcam kernel: configfs-gadget gadget: uvc: uvc_function_set_alt(1, 0)
Feb 07 15:50:59 piwebcam kernel: configfs-gadget gadget: uvc: uvc_function_set_alt(1, 0)
Feb 07 15:50:59 piwebcam kernel: configfs-gadget gadget: uvc: uvc_function_set_alt(1, 0)
Feb 07 15:50:59 piwebcam piwebcam[192]: CONFIGFS: Initial path: /sys/kernel/config/usb_gadget
Feb 07 15:50:59 piwebcam piwebcam[192]: CONFIGFS: UVC: format: 1, frame: 10, resolution: 1600x1200, bitrate: [153600000, 307200000]
Feb 07 15:50:59 piwebcam piwebcam[192]: CONFIGFS: UVC: format: 1, frame: 9, resolution: 1600x900, bitrate: [115200000, 230400000]
Feb 07 15:50:59 piwebcam piwebcam[192]: CONFIGFS: UVC: format: 1, frame: 8, resolution: 1536x864, bitrate: [106168320, 212336640]
Feb 07 15:50:59 piwebcam piwebcam[192]: CONFIGFS: UVC: format: 1, frame: 7, resolution: 1920x1080, bitrate: [165888000, 331776000]
Feb 07 15:50:59 piwebcam piwebcam[192]: CONFIGFS: UVC: format: 1, frame: 6, resolution: 1280x960, bitrate: [98304000, 196608000]
Feb 07 15:50:59 piwebcam piwebcam[192]: CONFIGFS: UVC: format: 1, frame: 5, resolution: 1280x720, bitrate: [73728000, 147456000]
Feb 07 15:50:59 piwebcam piwebcam[192]: CONFIGFS: UVC: format: 1, frame: 4, resolution: 1024x768, bitrate: [62914560, 125829120]
Feb 07 15:50:59 piwebcam piwebcam[192]: CONFIGFS: UVC: format: 1, frame: 3, resolution: 800x600, bitrate: [38400000, 76800000]
Feb 07 15:50:59 piwebcam piwebcam[192]: CONFIGFS: UVC: format: 1, frame: 2, resolution: 640x480, bitrate: [24576000, 49152000]
Feb 07 15:50:59 piwebcam piwebcam[192]: CONFIGFS: UVC: format: 1, frame: 1, resolution: 640x360, bitrate: [18432000, 36864000]
Feb 07 15:50:59 piwebcam piwebcam[192]: SETTINGS: Number of buffers requested: 2
Feb 07 15:50:59 piwebcam piwebcam[192]: SETTINGS: Video format: V4L2_PIX_FMT_MJPEG
Feb 07 15:50:59 piwebcam piwebcam[192]: SETTINGS: Show FPS: DISABLED
Feb 07 15:50:59 piwebcam piwebcam[192]: SETTINGS: IO method requested: USER_PTR
Feb 07 15:50:59 piwebcam piwebcam[192]: SETTINGS: UVC device name: /dev/video1
Feb 07 15:50:59 piwebcam piwebcam[192]: SETTINGS: V4L2 device name: /dev/video0
Feb 07 15:50:59 piwebcam piwebcam[192]: DEVICE_UVC: Opening /dev/video1 device
Feb 07 15:50:59 piwebcam piwebcam[192]: DEVICE_UVC: Device is 20980000.usb on bus gadget
Feb 07 15:50:59 piwebcam piwebcam[192]: DEVICE_V4L2: Opening /dev/video0 device
Feb 07 15:50:59 piwebcam piwebcam[192]: DEVICE_V4L2: Device is mmal service 16.1 on bus platform:bcm2835-v4l2
Feb 07 15:50:59 piwebcam piwebcam[192]: DEVICE_V4L2: Getting highest frame size: YUYV 4056x3040
Feb 07 15:50:59 piwebcam piwebcam[192]: DEVICE_V4L2: Getting highest frame size: MJPG 4056x3040
Feb 07 15:50:59 piwebcam piwebcam[192]: V4L2: Supported control Brightness (V4L2_CID_BRIGHTNESS = UVC_PU_BRIGHTNESS_CONTROL)
Feb 07 15:50:59 piwebcam piwebcam[192]: V4L2:   V4L2: min: 0, max: 100, step: 1, default: 50, value: 55
Feb 07 15:50:59 piwebcam piwebcam[192]: V4L2:   UVC: min: 0, max: 100, step: 1, default: 50, value: 55
Feb 07 15:50:59 piwebcam piwebcam[192]: V4L2: Supported control Contrast (V4L2_CID_CONTRAST = UVC_PU_CONTRAST_CONTROL)
Feb 07 15:50:59 piwebcam piwebcam[192]: V4L2:   V4L2: min: -100, max: 100, step: 1, default: 0, value: 0
Feb 07 15:50:59 piwebcam piwebcam[192]: V4L2:   UVC: min: 0, max: 200, step: 1, default: 100, value: 100
Feb 07 15:50:59 piwebcam piwebcam[192]: V4L2: Supported control Saturation (V4L2_CID_SATURATION = UVC_PU_SATURATION_CONTROL)
Feb 07 15:50:59 piwebcam piwebcam[192]: V4L2:   V4L2: min: -100, max: 100, step: 1, default: 0, value: 0
Feb 07 15:50:59 piwebcam piwebcam[192]: V4L2:   UVC: min: 0, max: 200, step: 1, default: 100, value: 100
Feb 07 15:50:59 piwebcam piwebcam[192]: V4L2: Supported control Red Balance (V4L2_CID_RED_BALANCE + V4L2_CID_BLUE_BALANCE = UVC_PU_WHITE_BALANCE_COMPONENT_CONTROL)
Feb 07 15:50:59 piwebcam piwebcam[192]: V4L2:   V4L2: min: 1, max: 7999, step: 1, default: 1000, value: 1000
Feb 07 15:50:59 piwebcam piwebcam[192]: V4L2:   UVC: min: 0, max: 7998, step: 1, default: 999, value: 999
Feb 07 15:50:59 piwebcam piwebcam[192]: V4L2: Supported control Power Line Frequency (V4L2_CID_POWER_LINE_FREQUENCY = UVC_PU_POWER_LINE_FREQUENCY_CONTROL)
Feb 07 15:50:59 piwebcam piwebcam[192]: V4L2:   V4L2: min: 0, max: 3, step: 1, default: 1, value: 1
Feb 07 15:50:59 piwebcam piwebcam[192]: V4L2:   UVC: min: 0, max: 3, step: 1, default: 1, value: 1
Feb 07 15:50:59 piwebcam piwebcam[192]: V4L2: Supported control Sharpness (V4L2_CID_SHARPNESS = UVC_PU_SHARPNESS_CONTROL)
Feb 07 15:50:59 piwebcam piwebcam[192]: V4L2:   V4L2: min: -100, max: 100, step: 1, default: 0, value: 0
Feb 07 15:50:59 piwebcam piwebcam[192]: V4L2:   UVC: min: 0, max: 200, step: 1, default: 100, value: 100
Feb 07 15:50:59 piwebcam piwebcam[192]: V4L2: Supported control Auto Exposure (V4L2_CID_EXPOSURE_AUTO = UVC_CT_AE_MODE_CONTROL)
Feb 07 15:50:59 piwebcam piwebcam[192]: V4L2:   V4L2: min: 0, max: 3, step: 1, default: 0, value: 0
Feb 07 15:50:59 piwebcam piwebcam[192]: V4L2:   UVC: min: 0, max: 3, step: 1, default: 0, value: 0
Feb 07 15:50:59 piwebcam piwebcam[192]: V4L2: Supported control Exposure Time, Absolute (V4L2_CID_EXPOSURE_ABSOLUTE = UVC_CT_EXPOSURE_TIME_ABSOLUTE_CONTROL)
Feb 07 15:50:59 piwebcam piwebcam[192]: V4L2:   V4L2: min: 1, max: 10000, step: 1, default: 1000, value: 1000
Feb 07 15:50:59 piwebcam piwebcam[192]: V4L2:   UVC: min: 0, max: 9999, step: 1, default: 999, value: 999
Feb 07 15:50:59 piwebcam piwebcam[192]: V4L2: Supported control Exposure, Dynamic Framerate (V4L2_CID_EXPOSURE_AUTO_PRIORITY = UVC_CT_AE_PRIORITY_CONTROL)
Feb 07 15:50:59 piwebcam piwebcam[192]: V4L2:   V4L2: min: 0, max: 1, step: 1, default: 0, value: 0
Feb 07 15:50:59 piwebcam piwebcam[192]: V4L2:   UVC: min: 0, max: 1, step: 1, default: 0, value: 0
Feb 07 15:50:59 piwebcam piwebcam[192]: request uvc_fill_streaming_control: 0, 0
Feb 07 15:50:59 piwebcam piwebcam[192]: response: 1, 1
Feb 07 15:50:59 piwebcam piwebcam[192]: FRAME FORMAT: format: 1, frame: 1, resolution: 640x360, bitrate: [18432000, 36864000]
Feb 07 15:50:59 piwebcam piwebcam[192]: request uvc_fill_streaming_control: 0, 0
Feb 07 15:50:59 piwebcam piwebcam[192]: response: 1, 1
Feb 07 15:50:59 piwebcam piwebcam[192]: FRAME FORMAT: format: 1, frame: 1, resolution: 640x360, bitrate: [18432000, 36864000]
Feb 07 15:50:59 piwebcam piwebcam[192]: UVC: PROCESSING_UNIT - GET_INFO - UVC_PU_BRIGHTNESS_CONTROL
Feb 07 15:50:59 piwebcam piwebcam[192]: UVC: PROCESSING_UNIT - GET_MIN - UVC_PU_BRIGHTNESS_CONTROL
Feb 07 15:50:59 piwebcam piwebcam[192]: UVC: PROCESSING_UNIT - GET_MAX - UVC_PU_BRIGHTNESS_CONTROL
Feb 07 15:50:59 piwebcam piwebcam[192]: UVC: PROCESSING_UNIT - GET_RES - UVC_PU_BRIGHTNESS_CONTROL
Feb 07 15:51:11 piwebcam kernel: random: crng init done
Feb 07 15:51:11 piwebcam kernel: random: 7 urandom warning(s) missed due to ratelimiting
Feb 07 15:52:05 piwebcam login[133]: root login on 'ttyGS0'

I see, that the brightness is being set, but the output stays the same at 50.

v4l2-ctl -l

User Controls

                     brightness 0x00980900 (int)    : min=0 max=100 step=1 default=50 value=50 flags=slider
                       contrast 0x00980901 (int)    : min=-100 max=100 step=1 default=0 value=0 flags=slider
                     saturation 0x00980902 (int)    : min=-100 max=100 step=1 default=0 value=0 flags=slider
                    red_balance 0x0098090e (int)    : min=1 max=7999 step=1 default=1000 value=1000 flags=slider
                   blue_balance 0x0098090f (int)    : min=1 max=7999 step=1 default=1000 value=1000 flags=slider
                horizontal_flip 0x00980914 (bool)   : default=0 value=0
                  vertical_flip 0x00980915 (bool)   : default=0 value=0
           power_line_frequency 0x00980918 (menu)   : min=0 max=3 default=1 value=1
                      sharpness 0x0098091b (int)    : min=-100 max=100 step=1 default=0 value=0 flags=slider
                  color_effects 0x0098091f (menu)   : min=0 max=15 default=0 value=0
                         rotate 0x00980922 (int)    : min=0 max=360 step=90 default=0 value=0 flags=modify-layout
             color_effects_cbcr 0x0098092a (int)    : min=0 max=65535 step=1 default=32896 value=32896

Codec Controls

             video_bitrate_mode 0x009909ce (menu)   : min=0 max=1 default=0 value=0 flags=update
                  video_bitrate 0x009909cf (int)    : min=25000 max=25000000 step=25000 default=10000000 value=25000000
         repeat_sequence_header 0x009909e2 (bool)   : default=0 value=0
            h264_i_frame_period 0x00990a66 (int)    : min=0 max=2147483647 step=1 default=60 value=60
                     h264_level 0x00990a67 (menu)   : min=0 max=11 default=11 value=11
                   h264_profile 0x00990a6b (menu)   : min=0 max=4 default=4 value=4

Camera Controls

                  auto_exposure 0x009a0901 (menu)   : min=0 max=3 default=0 value=0
         exposure_time_absolute 0x009a0902 (int)    : min=1 max=10000 step=1 default=1000 value=1000
     exposure_dynamic_framerate 0x009a0903 (bool)   : default=0 value=0
             auto_exposure_bias 0x009a0913 (intmenu): min=0 max=24 default=12 value=15
      white_balance_auto_preset 0x009a0914 (menu)   : min=0 max=10 default=1 value=1
            image_stabilization 0x009a0916 (bool)   : default=0 value=0
                iso_sensitivity 0x009a0917 (intmenu): min=0 max=4 default=0 value=0
           iso_sensitivity_auto 0x009a0918 (menu)   : min=0 max=1 default=1 value=1
         exposure_metering_mode 0x009a0919 (menu)   : min=0 max=2 default=0 value=0
                     scene_mode 0x009a091a (menu)   : min=0 max=13 default=0 value=0

JPEG Compression Controls

            compression_quality 0x009d0903 (int)    : min=1 max=100 step=1 default=30 value=30
zlorfi commented 3 years ago

I reported this issue originally here

peterbay commented 3 years ago

Your journalctl log contains information about available video controls and mapping between v4l2 and UVC.

If host computer need to change brightness, then tou can see in log messages like this - UVC: PROCESSING_UNIT - GET_CUR - UVC_PU_BRIGHTNESS_CONTROL UVC: PROCESSING_UNIT - GET_CUR - UVC_PU_BRIGHTNESS_CONTROL UVC: PROCESSING_UNIT - SET_CUR - UVC_PU_BRIGHTNESS_CONTROL UVC: Control CONTROL_UNDEFINED, length: 2 DEVICE_UVC: V4L2_CID_BRIGHTNESS changed value (V4L2: 54, UVC: 54)

Your journalctl doesn't contain a message like "DEVICE_UVC: V4L2_CID_BRIGHTNESS changed value (V4L2: 54, UVC: 54)", so uvc-gadget don't change brightness.

mattstudio commented 3 years ago

I'm encountering the same problem. Other settings in the camera.txt are being honored, but the 'brightness' value is ignored. I have to set it manually using the serial interface each time I connect the webcam.

peterbay commented 3 years ago

In branch new-code https://github.com/peterbay/uvc-gadget/tree/feat/new-code is now added argument -z for ignoring controls from v4l2 source device and host computer.