OpenIPC / majestic

Majestic Community edition integration kit
MIT License
38 stars 6 forks source link

exposure overblown on hi3518ev100 + ov9712 #147

Open zerog2k opened 11 months ago

zerog2k commented 11 months ago

majestic (or something underneath it) appears to be setting the AEC (auto exposure control) registers too high

when majestic starts up, if I immediate stream the video the image is normal, but over a few seconds the exposure climbs until it's almost completely washed out white

I can see that this has something to do with the AEC (0x10 LSBs) & AECH (0x16 MSBs) i2c registers of the ov9712, as compared to oem firmware, the AEC value is much lower on original: original AEC ( 0x0026 == 38) while the majestic raises to higher values like 0x0326 == 806

I have tried playing with the majestic.yaml isp.exposure setting (auto, 100, 1000, 100000), but this does not appear to do anything meaningful that I can see

I can (very temporarily) fix this by setting the AECH high byte register to zero (ipctool i2cset 0x60 0x16 0), and I can see the image return to proper exposure on the video stream, however something in majestic (or sensor lib?) is immediately setting this value back to higher number, because the image will flicker back to over-exposed again

I'm really not sure why majestic (or something) is trying to set AEC values so high. Is there some way to control this, override, or debug this better?

20:34:14  <       majestic> [    main] main@195                      Majestic Lite for HiSilicon, version master+5ad7bfc, built on 2023-12-14
20:34:14  <       majestic> [app_conf] parse_app_config@313          Main audio codec is ulaw (other options: opus, pcm, alaw)
20:34:15  <       majestic> [watchdog] watchdog_start@101            Detected Hisilicon Watchdog
20:34:15  <       majestic> [watchdog] watchdog_start@121            Watchdog timeout set to 16 seconds
20:34:15  <       majestic> [   httpd] new_http_server@371           HTTP server started on :::80
20:34:15  <       majestic> [app_conf] load_config@108               Using /etc/majestic.yaml as main configuration
20:34:15  <       majestic> [app_conf] parse_app_config@313          Main audio codec is ulaw (other options: opus, pcm, alaw)
20:34:15  <       majestic> [     sdk] try_sensor_config@3376        SENSOR=ov9712
20:34:15  <       majestic> [     sdk] find_sensor_config@3339       matched sensor config: ov9712_i2c_dc_720p.ini
20:34:15  <       majestic> [     sdk] start_sdk@415                 Using /etc/sensors/ov9712_i2c_dc_720p.ini sensor configuration file
20:34:15  <       majestic> [     sdk] start_sdk@423                 App was built with MPP version: Hi3518_MPP_V1.0.B.0.
20:34:15  <       majestic> [     sdk] start_sdk@428                 Current MPP version: HI_VERSION=Hi3518_MPP_V1.0.B.0 
20:34:15  <       majestic> [     sdk] start_sdk@448                 sensor ov9712
20:34:15  <       majestic> [     sdk] start_sdk@456                   dev [1280x720]@0x0 15fps, BGGR
20:34:15  <       majestic> [  sensor] try_to_load@19                trying to load /usr/lib/sensors/libsns_ov9712_i2c_dc.so
20:34:15  <       majestic> [     hal] hisi_free_mem_ex@755          Free MMZ mem before allocation: 15484KB
20:34:15  <       majestic> [     sdk] dump_vb_configuration@2231    VB configuration:
20:34:15  <       majestic> [     sdk] dump_vb_configuration@2234      [0]: 1413120 x 5
20:34:15  <       majestic> [     hal] hisi_free_mem_ex@755          Free MMZ mem after allocation: 8572KB
20:34:15  <       majestic> [     sdk] init_sensor@2427              Sensor driver loaded
20:34:16  <       majestic> [     sdk] log_venc_chn@1256             H.264 1280x720 15fps 4096Kbit  15 GOP
20:34:16  <     iq_monitor> [     sdk] monitor_thread@344            Loading IQ profile /etc/sensors/iq/default.ini
20:34:16  <       majestic> [     sdk] create_vpss_chn@1001            new venc: 0   vpss_grp: 0,   vpss_chn: 0
20:34:16  <       majestic> [     sdk] start_video@1976                venc took 3400KB of MMZ [675]
20:34:16  <       majestic> [     log] printf@268                    pageaddr:4036b000,dgbaddr:4036b000,size:0
20:34:16  <       majestic> [   audio] init_audio_in@478             Ai(0,0) bind to AencChn:0 ok!
20:34:16  <       majestic> [     sdk] start_sdk@543                   Audio took 328KB of MMZ
20:34:16  <       majestic> [     sdk] start_sdk@560                 HiSilicon SDK started
20:34:16  <       majestic> [     hal] hisi_free_mem_ex@755          Free MMZ mem finally: 688KB
20:34:16  <       majestic> [    rtsp] rtsp_init@31                  RTSP server started on port 554
20:34:18  <       majestic> [  client] RtspClient_before@402         RTSP OPTIONS rtsp://10.0.3.78:554/stream=0 CSeq=8 from 10.0.0.143:55077
20:34:22  <       majestic> [  client] RtspClient_before@402         RTSP TEARDOWN rtsp://10.0.3.78:554/stream=0 CSeq=9 from 10.0.0.143:55077
20:34:22  <       majestic> [  client] RtspClient_on_closed_conn@654 RTSP connection closed.
20:34:22  <       majestic> [  client] RtspClient_before@402         RTSP OPTIONS rtsp://10.0.3.78:554/stream=0 CSeq=2 from 10.0.0.143:55078
20:34:22  <       majestic> [  client] RtspClient_before@402         RTSP OPTIONS rtsp://10.0.3.78:554/stream=0 CSeq=3 from 10.0.0.143:55078
20:34:22  <       majestic> [  client] RtspClient_before@402         RTSP DESCRIBE rtsp://10.0.3.78:554/stream=0 CSeq=4 from 10.0.0.143:55078
20:34:22  <       majestic> [     nal] NalCodec_describe@127         RTSP chn 0 sps_len 0
20:34:22  <       majestic> [     nal] NalCodec_describe@130         RTSP chn 0 pps_len 0
20:34:22  <       majestic> [     nal] NalCodec_describe@138         RTSP chn 0 profile_level_id 000000
20:34:22  <       majestic> [  client] RtspClient_before@402         RTSP SETUP rtsp://10.0.3.78:554/stream=0/video CSeq=5 from 10.0.0.143:55078
20:34:22  <       majestic> [  client] RtspClient_setup@313          UDP RTSP SETUP done, stream_id=0 from 10.0.0.143:55078
20:34:22  <       majestic> [  client] RtspClient_before@402         RTSP SETUP rtsp://10.0.3.78:554/stream=0/audio CSeq=6 from 10.0.0.143:55078
20:34:22  <       majestic> [  client] RtspClient_setup@313          UDP RTSP SETUP done, stream_id=0 from 10.0.0.143:55078
20:34:22  <       majestic> [  client] RtspClient_before@402         RTSP PLAY rtsp://10.0.3.78:554/stream=0 CSeq=7 from 10.0.0.143:55078

Screen Shot 2023-12-21 at 12 13 50 PM (2) Screen Shot 2023-12-21 at 12 13 53 PM (2) Screen Shot 2023-12-21 at 12 13 58 PM (2)

openipc:

root@openipc-test3:~# ipctool i2cdump 0x60 0 0xff
       0  1  2  3  4  5  6  7   8  9  A  B  C  D  E  F
    : 00 40 40 0A 08 40 00 00  00 00 97 11 30 01 40 00  |  .@@..@......0.@. 
  10: 26 01 00 80 40 00 03 25  A2 01 CA 81 7F A2 07 00  |  &...@..%........ 
  20: 00 03 03 00 55 40 A1 00  00 00 38 0D 50 00 00 C7  |  ....U@....8.P... 
  30: 08 20 07 00 00 00 00 02  00 28 09 00 00 3C 03 00  |  . .......(...<.. 
  40: 00 84 14 C0 B9 B9 B8 B8  55 CE 00 36 13 90 55 55  |  ........U..6..UU 
  50: 55 55 10 42 30 FF 1F 00  B4 A0 57 20 52 00 0A 18  |  UU.B0.....W R... 
  60: 9D 82 02 00 33 2A 0C 02  0A 04 02 00 01 02 C0 E0  |  ....3*.......... 
  70: 02 00 60 B0 40 E0 C0 C0  FF FF 10 00 00 00 00 00  |  ..`.@........... 
  80: 00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |  ................ 
  90: 00 00 00 00 00 00 01 80  00 28 00 04 00 FF 00 80  |  .........(...... 
  a0: F1 6A 00 80 90 12 22 C2  87 80 90 12 22 C2 87 80  |  .j...."....."... 
  b0: 90 12 22 C2 87 00 07 00  04 08 00 20 68 A0 B4 00  |  .."........ h... 
  c0: 00 80 80 20 AB B6 80 9D  00 80 20 A6 40 00 01 00  |  ... ...... .@... 
  d0: FF FF FF 00 03 00 0C 00  00 00 00 00 01 00 00 00  |  ................ 
  e0: 00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |  ................ 
  f0: 00 00 00 00 00 00 00 00  00 00 00 00 00 00 00     |  ............... 

oem firmware:

# /etc/conf.d/jovision/network/ipctool i2cdump 0x60 0 0xFF
       0  1  2  3  4  5  6  7   8  9  A  B  C  D  E  F
    : 00 40 40 0A 08 40 00 00  00 00 97 11 30 01 40 00  |  .@@..@......0.@. 
  10: 57 01 00 80 40 00 00 25  A2 01 CA 81 7F A2 07 00  |  W...@..%........ 
  20: 00 03 03 00 55 40 A1 00  00 00 F0 07 50 00 00 28  |  ....U@......P..( 
  30: 08 07 07 00 00 00 00 06  00 28 09 00 00 3C 03 00  |  .........(...<.. 
  40: 00 84 14 C0 BA BB B8 B9  55 CE 00 36 13 90 55 55  |  ........U..6..UU 
  50: 55 55 10 42 30 FF 1F 81  B4 A0 57 20 52 00 0A 18  |  UU.B0.....W R... 
  60: 9D 82 02 00 33 2A 0C 02  0A 04 02 00 01 02 C0 E0  |  ....3*.......... 
  70: 02 00 60 B0 40 E0 C0 C0  FF FF 10 00 00 00 00 00  |  ..`.@........... 
  80: 00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |  ................ 
  90: 00 00 00 00 00 00 01 80  00 28 00 04 00 FF 00 80  |  .........(...... 
  a0: F1 6A 00 80 90 12 22 C2  87 80 90 12 22 C2 87 80  |  .j...."....."... 
  b0: 90 12 22 C2 87 00 07 00  04 08 00 20 68 A0 B4 00  |  .."........ h... 
  c0: 00 80 80 20 AB B6 80 9D  00 80 20 A6 40 00 01 00  |  ... ...... .@... 
  d0: FF FF FF 00 03 00 0C 00  00 00 00 00 01 00 00 00  |  ................ 
  e0: 60 88 83 A7 D8 01 00 00  00 00 00 00 00 00 00 00  |  `............... 
  f0: 00 00 00 00 00 00 00 00  00 00 00 00 00 00 00     |  ............... 

# 
zerog2k commented 11 months ago

also this register seems to correspond to the prometheus metrics isp_exposure & isp_exptime I'm not sure if it's ok that these are the same value - are they the same thing?

# HELP isp_exptime Sensor exposure time
# TYPE isp_exptime gauge
isp_exptime 687
# HELP isp_again Analog Gain
# TYPE isp_again gauge
isp_again 1024
# HELP isp_dgain Digital Gain
# TYPE isp_dgain gauge
isp_dgain 1024
# HELP isp_ispdgain ISP Gain
# TYPE isp_ispdgain gauge
isp_ispdgain 1024
# HELP isp_exposure Exposure
# TYPE isp_exposure gauge
isp_exposure 687
# HELP isp_avelum Average luminance
# TYPE isp_avelum gauge
isp_avelum 47
# HELP isp_exposureismax Exposure reached maximum
# TYPE isp_exposureismax gauge
isp_exposureismax 0
zerog2k commented 11 months ago

ok I was able to test using libsns_ov9712.so from oem firmware, and the issue still exists, so I suspect it's majestic doing something here with AEC

zerog2k commented 11 months ago

So an update - after some playing around with the camera positioning, if I angle the camera down just a bit, the image exposure balances out a bit better. I think the main issue here may be that non of the isp exposure/gain settings (exposure, aGain, dGain, ispGain, etc) seem to have any effect on the ov9712 sensor, but it does look like this may be something controlled or influenced by majestic itself. So looking for advice on troubleshooting this. (none of the debug settings like system.logLevel=TRACE seem to induce majestic to output anything extra or meaningful for this investigation.)

widgetii commented 11 months ago

You may use HiSilicon's PQTools to adjust low level ISP settings and play with different settings