refactoring

This commit is contained in:
Maxim Devaev
2026-07-08 10:24:41 +03:00
parent 7cf03cf35a
commit 41a8eb46ca
8 changed files with 62 additions and 48 deletions

View File

@@ -46,7 +46,7 @@
#include "uslibs/list.h" #include "uslibs/list.h"
#include "uslibs/ring.h" #include "uslibs/ring.h"
#include "uslibs/memsink.h" #include "uslibs/memsink.h"
#include "uslibs/tc358743.h" #include "uslibs/chip.h"
#include "const.h" #include "const.h"
#include "client.h" #include "client.h"
@@ -187,6 +187,7 @@ static void *_video_sink_thread(void *arg) {
} }
static int _get_acap_hz(uint *hz) { static int _get_acap_hz(uint *hz) {
*hz = 0;
if (_g_config->acap_hz != 0) { if (_g_config->acap_hz != 0) {
*hz = _g_config->acap_hz; *hz = _g_config->acap_hz;
return 0; return 0;
@@ -195,14 +196,16 @@ static int _get_acap_hz(uint *hz) {
US_LOG_ERROR("No configured sampling rate"); US_LOG_ERROR("No configured sampling rate");
return -1; return -1;
} }
int fd; const int fd = open(_g_config->tc358743_dev_path, O_RDWR);
if ((fd = open(_g_config->tc358743_dev_path, O_RDWR)) < 0) { if (fd < 0) {
US_LOG_PERROR("Can't open TC358743 V4L2 device"); US_LOG_PERROR("Can't open TC358743 V4L2 device");
return -1; return -1;
} }
const int checked = us_tc358743_xioctl_get_audio_hz(fd, hz); const int result = us_chip_tc358743_get_audio_hz(fd);
if (checked < 0) { if (result > 0) {
US_LOG_PERROR("Can't check TC358743 audio state (%d)", checked); *hz = result;
} else if (result != US_ERROR_NO_SIGNAL) {
US_LOG_PERROR("Can't check TC358743 audio state (%d)", result);
close(fd); close(fd);
return -1; return -1;
} }

1
janus/src/uslibs/chip.c Symbolic link
View File

@@ -0,0 +1 @@
../../../src/libs/chip.c

1
janus/src/uslibs/chip.h Symbolic link
View File

@@ -0,0 +1 @@
../../../src/libs/chip.h

View File

@@ -1 +0,0 @@
../../../src/libs/tc358743.c

View File

@@ -1 +0,0 @@
../../../src/libs/tc358743.h

View File

@@ -38,7 +38,6 @@
#include <pthread.h> #include <pthread.h>
#include <linux/videodev2.h> #include <linux/videodev2.h>
#include <linux/v4l2-controls.h>
#include <linux/media.h> #include <linux/media.h>
#include <linux/v4l2-subdev.h> #include <linux/v4l2-subdev.h>
@@ -50,8 +49,8 @@
#include "threading.h" #include "threading.h"
#include "frame.h" #include "frame.h"
#include "xioctl.h" #include "xioctl.h"
#include "tc358743.h"
#include "media.h" #include "media.h"
#include "chip.h"
static const struct { static const struct {
@@ -208,11 +207,10 @@ int us_capture_open(us_capture_s *cap) {
} }
if (cap->dv_timings && cap->persistent) { if (cap->dv_timings && cap->persistent) {
struct v4l2_control ctl = {.id = V4L2_CID_DV_RX_POWER_PRESENT}; _LOG_DEBUG("Probing the cable ...")
if (!us_xioctl(run->fd, VIDIOC_G_CTRL, &ctl)) { switch (us_chip_check_cable(run->fd)) {
if (!ctl.value) { case 0: break;
goto error_no_cable; case US_ERROR_NO_CABLE: goto error_no_cable;
}
} }
_LOG_DEBUG("Probing DV-timings or QuerySTD ..."); _LOG_DEBUG("Probing DV-timings or QuerySTD ...");
switch (_capture_open_dv_timings(cap, false)) { switch (_capture_open_dv_timings(cap, false)) {
@@ -245,12 +243,9 @@ int us_capture_open(us_capture_s *cap) {
goto error; goto error;
} }
if (cap->dv_timings && cap->persistent) { if (cap->dv_timings && cap->persistent) {
struct v4l2_control ctl = {.id = TC358743_CID_LANES_ENOUGH}; switch (us_chip_tc358743_check_lanes(run->fd)) {
if (!us_xioctl(run->fd, VIDIOC_G_CTRL, &ctl)) { case 0: break;
if (!ctl.value) { case US_ERROR_NO_LANES: goto error_no_lanes;
_LOG_ERROR("Not enough lanes, hardware can't handle this signal");
goto error_no_lanes;
}
} }
} }
_capture_open_hw_fps(cap); _capture_open_hw_fps(cap);
@@ -300,6 +295,7 @@ error_no_sync:
return US_ERROR_NO_SYNC; return US_ERROR_NO_SYNC;
error_no_lanes: error_no_lanes:
US_ONCE_FOR(run->open_error_once, __LINE__, { _LOG_ERROR("Not enough lanes, the hardware can't handle this signal"); });
us_capture_close(cap); us_capture_close(cap);
return US_ERROR_NO_LANES; return US_ERROR_NO_LANES;

View File

@@ -20,7 +20,7 @@
*****************************************************************************/ *****************************************************************************/
#include "tc358743.h" #include "chip.h"
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
@@ -29,26 +29,57 @@
#include <linux/v4l2-controls.h> #include <linux/v4l2-controls.h>
#include "types.h" #include "types.h"
#include "errors.h"
#include "tools.h" #include "tools.h"
#include "xioctl.h" #include "xioctl.h"
int us_tc358743_xioctl_get_audio_hz(int fd, uint *audio_hz) { #ifndef V4L2_CID_USER_TC358743_BASE
*audio_hz = 0; # define V4L2_CID_USER_TC358743_BASE (V4L2_CID_USER_BASE + 0x1080)
#endif
#ifndef TC358743_CID_AUDIO_SAMPLING_RATE
# define TC358743_CID_AUDIO_SAMPLING_RATE (V4L2_CID_USER_TC358743_BASE + 0)
#endif
#ifndef TC358743_CID_AUDIO_PRESENT
# define TC358743_CID_AUDIO_PRESENT (V4L2_CID_USER_TC358743_BASE + 1)
#endif
#ifndef TC358743_CID_LANES_ENOUGH
# define TC358743_CID_LANES_ENOUGH (V4L2_CID_USER_TC358743_BASE + 2)
#endif
int us_chip_check_cable(int fd) {
struct v4l2_control ctl = {.id = V4L2_CID_DV_RX_POWER_PRESENT};
if (us_xioctl(fd, VIDIOC_G_CTRL, &ctl) < 0) {
return US_ERROR_COMMON;
}
return (ctl.value ? 0 : US_ERROR_NO_CABLE);
}
int us_chip_tc358743_check_lanes(int fd) {
struct v4l2_control ctl = {.id = TC358743_CID_LANES_ENOUGH};
if (us_xioctl(fd, VIDIOC_G_CTRL, &ctl) < 0) {
return US_ERROR_COMMON;
}
return (ctl.value ? 0 : US_ERROR_NO_LANES);
}
int us_chip_tc358743_get_audio_hz(int fd) {
struct v4l2_control ctl = {.id = TC358743_CID_AUDIO_PRESENT}; struct v4l2_control ctl = {.id = TC358743_CID_AUDIO_PRESENT};
if (us_xioctl(fd, VIDIOC_G_CTRL, &ctl) < 0) { if (us_xioctl(fd, VIDIOC_G_CTRL, &ctl) < 0) {
return -1; return US_ERROR_COMMON;
} }
if (!ctl.value) { if (!ctl.value) {
return 0; // No audio return US_ERROR_NO_SIGNAL; // No audio
} }
US_MEMSET_ZERO(ctl); US_MEMSET_ZERO(ctl);
ctl.id = TC358743_CID_AUDIO_SAMPLING_RATE; ctl.id = TC358743_CID_AUDIO_SAMPLING_RATE;
if (us_xioctl(fd, VIDIOC_G_CTRL, &ctl) < 0) { if (us_xioctl(fd, VIDIOC_G_CTRL, &ctl) < 0) {
return -1; return US_ERROR_COMMON;
} }
*audio_hz = ctl.value; return (ctl.value ? ctl.value : US_ERROR_NO_SIGNAL);
return 0;
} }

View File

@@ -22,26 +22,10 @@
#pragma once #pragma once
#include <linux/v4l2-controls.h>
#include "types.h" #include "types.h"
#ifndef V4L2_CID_USER_TC358743_BASE int us_chip_check_cable(int fd);
# define V4L2_CID_USER_TC358743_BASE (V4L2_CID_USER_BASE + 0x1080)
#endif
#ifndef TC358743_CID_AUDIO_SAMPLING_RATE int us_chip_tc358743_check_lanes(int fd);
# define TC358743_CID_AUDIO_SAMPLING_RATE (V4L2_CID_USER_TC358743_BASE + 0) int us_chip_tc358743_get_audio_hz(int fd);
#endif
#ifndef TC358743_CID_AUDIO_PRESENT
# define TC358743_CID_AUDIO_PRESENT (V4L2_CID_USER_TC358743_BASE + 1)
#endif
#ifndef TC358743_CID_LANES_ENOUGH
# define TC358743_CID_LANES_ENOUGH (V4L2_CID_USER_TC358743_BASE + 2)
#endif
int us_tc358743_xioctl_get_audio_hz(int fd, uint *audio_hz);