libv4l-rs: Panic: v4l-0.14.0/src/control.rs:172:45: called Result::unwrap() on an Err value: ()

Hi, there is a panic happening when using this lib inside an i.MX 8M Plus:

v4l-0.14.0/src/control.rs:172:45: called Result::unwrap() on an Err value: ()

Maybe we are missing part of the specification?

Below is the output of v4l2-ctl --list-ctrls-menus for both devices available:

root@ucm-imx8m-plus:~# v4l2-ctl --list-ctrls-menus --device=/dev/video0

User Controls

                         rotate 0x00980922 (int)    : min=0 max=270 step=90 default=0 value=0 flags=modify-layout
  min_number_of_capture_buffers 0x00980927 (int)    : min=1 max=16 step=1 default=1 value=1 flags=read-only, volatile
   min_number_of_output_buffers 0x00980928 (int)    : min=1 max=16 step=1 default=1 value=1 flags=read-only, volatile
      get_max_roi_region_number 0x009819b2 (int)    : min=0 max=8 step=1 default=0 value=8 flags=read-only, volatile
   vsi_priv_v4l2_roi_params_set 0x009819b3 (unknown): type=164 value=unsupported payload type flags=has-payload
     get_max_ipcm_region_number 0x009819b4 (int)    : min=0 max=2 step=1 default=0 value=2 flags=read-only, volatile
  vsi_priv_v4l2_ipcm_params_set 0x009819b5 (unknown): type=165 value=unsupported payload type flags=has-payload

Codec Controls

                 video_b_frames 0x009909ca (int)    : min=0 max=0 step=1 default=0 value=0 flags=update
                 video_gop_size 0x009909cb (int)    : min=1 max=2147483647 step=1 default=30 value=30
             video_bitrate_mode 0x009909ce (menu)   : min=0 max=1 default=0 value=0 (Variable Bitrate) flags=update
                                0: Variable Bitrate
                                1: Constant Bitrate
                  video_bitrate 0x009909cf (int)    : min=10000 max=288000000 step=1 default=2097152 value=2097152
frame_level_rate_control_enable 0x009909d7 (bool)   : default=0 value=0
           sequence_header_mode 0x009909d8 (menu)   : min=0 max=1 default=1 value=1 (Joined With 1st Frame)
                                0: Separate Buffer
                                1: Joined With 1st Frame
     h264_mb_level_rate_control 0x009909da (bool)   : default=0 value=0
       number_of_mbs_in_a_slice 0x009909dc (int)    : min=1 max=120 step=1 default=1 value=1
      slice_partitioning_method 0x009909dd (menu)   : min=0 max=1 default=0 value=0 (Single)
                                0: Single
                                1: Max Macroblocks
         repeat_sequence_header 0x009909e2 (bool)   : default=1 value=1
                force_key_frame 0x009909e5 (button) : value=0 flags=write-only, execute-on-write
          h264_i_frame_qp_value 0x00990a5e (int)    : min=-1 max=51 step=1 default=30 value=30
          h264_p_frame_qp_value 0x00990a5f (int)    : min=-1 max=51 step=1 default=30 value=30
          h264_b_frame_qp_value 0x00990a60 (int)    : min=-1 max=51 step=1 default=30 value=30
          h264_minimum_qp_value 0x00990a61 (int)    : min=0 max=51 step=1 default=0 value=0
          h264_maximum_qp_value 0x00990a62 (int)    : min=0 max=51 step=1 default=51 value=51
           h264_cpb_buffer_size 0x00990a64 (int)    : min=0 max=288000000 step=1 default=0 value=0
                     h264_level 0x00990a67 (menu)   : min=0 max=15 default=14 value=14 (5)
                                0: 1
                                1: 1b
                                2: 1.1
                                3: 1.2
                                4: 1.3
                                5: 2
                                6: 2.1
                                7: 2.2
                                8: 3
                                9: 3.1
                                10: 3.2
                                11: 4
                                12: 4.1
                                13: 4.2
                                14: 5
                                15: 5.1
                   h264_profile 0x00990a6b (menu)   : min=0 max=16 default=0 value=0 (Baseline)
                                0: Baseline
                                1: Constrained Baseline
                                2: Main
                                3: Extended
                                4: High
                                5: High 10
                                6: High 422
                                7: High 444 Predictive
                                8: High 10 Intra
                                9: High 422 Intra
                                10: High 444 Intra
                                11: CAVLC 444 Intra
                                12: Scalable Baseline
                                13: Scalable High
                                14: Scalable High Intra
                                15: Stereo High
                                16: Multiview High
    h264_chroma_qp_index_offset 0x00990a80 (int)    : min=-12 max=12 step=1 default=0 value=0
           vpx_minimum_qp_value 0x00990afb (int)    : min=0 max=127 step=1 default=0 value=0
           vpx_maximum_qp_value 0x00990afc (int)    : min=0 max=127 step=1 default=127 value=127
           vpx_i_frame_qp_value 0x00990afd (int)    : min=-1 max=127 step=1 default=30 value=30
           vpx_p_frame_qp_value 0x00990afe (int)    : min=-1 max=127 step=1 default=30 value=30
                    vp8_profile 0x00990aff (menu)   : min=0 max=3 default=0 value=0 (0)
                                0: 0
                                1: 1
                                2: 2
                                3: 3
                    vp9_profile 0x00990b00 (menu)   : min=0 max=3 default=0 value=0 (0)
                                0: 0
                                1: 1
                                2: 2
                                3: 3
          hevc_minimum_qp_value 0x00990b58 (int)    : min=0 max=51 step=1 default=0 value=0
          hevc_maximum_qp_value 0x00990b59 (int)    : min=0 max=51 step=1 default=51 value=51
          hevc_i_frame_qp_value 0x00990b5a (int)    : min=-1 max=51 step=1 default=30 value=30
          hevc_p_frame_qp_value 0x00990b5b (int)    : min=-1 max=51 step=1 default=30 value=30
                   hevc_profile 0x00990b67 (menu)   : min=0 max=2 default=0 value=0 (Main)
                                0: Main
                                1: Main Still Picture
                                2: Main 10
                     hevc_level 0x00990b68 (menu)   : min=0 max=8 default=7 value=7 (5)
                                0: 1
                                1: 2
                                2: 2.1
                                3: 3
                                4: 3.1
                                5: 4
                                6: 4.1
                                7: 5
                                8: 5.1

root@ucm-imx8m-plus:~# v4l2-ctl --list-ctrls-menus --device=/dev/video1

User Controls

  min_number_of_capture_buffers 0x00980927 (int)    : min=1 max=16 step=1 default=1 value=1 flags=read-only, volatile
   min_number_of_output_buffers 0x00980928 (int)    : min=1 max=16 step=1 default=1 value=1 flags=read-only, volatile
     frame_disable_reorder_ctrl 0x009819b1 (bool)   : default=0 value=0
             vsi_get_10bit_meta 0x009819b6 (unknown): type=166 value=unsupported payload type flags=read-only, volatile, has-payload
         en_disable_secure_mode 0x009819b7 (bool)   : default=0 value=0

Codec Controls

                   h264_profile 0x00990a6b (menu)   : min=0 max=16 default=0 value=0 (Baseline)
                                0: Baseline
                                1: Constrained Baseline
                                2: Main
                                3: Extended
                                4: High
                                5: High 10
                                6: High 422
                                7: High 444 Predictive
                                8: High 10 Intra
                                9: High 422 Intra
                                10: High 444 Intra
                                11: CAVLC 444 Intra
                                12: Scalable Baseline
                                13: Scalable High
                                14: Scalable High Intra
                                15: Stereo High
                                16: Multiview High
                    vp8_profile 0x00990aff (menu)   : min=0 max=3 default=0 value=0 (0)
                                0: 0
                                1: 1
                                2: 2
                                3: 3
                    vp9_profile 0x00990b00 (menu)   : min=0 max=3 default=0 value=0 (0)
                                0: 0
                                1: 1
                                2: 2
                                3: 3
                   hevc_profile 0x00990b67 (menu)   : min=0 max=2 default=0 value=0 (Main)
                                0: Main
                                1: Main Still Picture
                                2: Main 10

Thanks

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 15 (3 by maintainers)

Most upvoted comments

Little workaround in https://github.com/raymanfx/libv4l-rs/compare/control-type-unknown, thoughts? We could alternatively also turn the impl From<v4l2_query_ext_ctrl> for Description conversion where this panic is happening into a TryFrom?

Sure, let’s do it. I definitely cut some corners in the past in order to produce something workable, but now is the right time to rip off those bandaids.

No good way to prevent panics other than actively fixing the library that has them (or having a panic-catcher). There are special lints to disallow them and maybe @raymanfx we should enable that as a nicety for libraries, and turn the remaining ones into proper fallible (Result-returning) constructs?

@joaoantoniocardoso since control::Type and control::Description are pub including everything around it, warn/ignore is quite a broad thing to task.

We could warn and return a fallible error by replacing From with TryFrom as suggested as alternative, I guess that counts as ignore when the consumer crate skips instead of unwraps on the conversion.


@raymanfx which of the two approaches quoted there sound fine to you? The branch is technically breaking due to layout changes in Type, not to mention trait changes.

Inlined link to the affected bit of code:

https://github.com/raymanfx/libv4l-rs/blob/867d9b122fde603ff7f1bfcdf19de48845c9e1f7/src/control.rs#L172

This error is returned from:

https://github.com/raymanfx/libv4l-rs/blob/867d9b122fde603ff7f1bfcdf19de48845c9e1f7/src/control.rs#L33-L50

Could it be those custom type=164, 165, 166? We don’t see it because this TryFrom doesn’t return the original value.

I guess we should set up a patch that skips those types, as v4l-ctl is also handling these unknown “vendor” types?