diff --git a/janus/src/plugin.c b/janus/src/plugin.c index d76ef57..18c5ff2 100644 --- a/janus/src/plugin.c +++ b/janus/src/plugin.c @@ -46,7 +46,7 @@ #include "uslibs/list.h" #include "uslibs/ring.h" #include "uslibs/memsink.h" -#include "uslibs/tc358743.h" +#include "uslibs/chip.h" #include "const.h" #include "client.h" @@ -187,6 +187,7 @@ static void *_video_sink_thread(void *arg) { } static int _get_acap_hz(uint *hz) { + *hz = 0; if (_g_config->acap_hz != 0) { *hz = _g_config->acap_hz; return 0; @@ -195,14 +196,16 @@ static int _get_acap_hz(uint *hz) { US_LOG_ERROR("No configured sampling rate"); return -1; } - int fd; - if ((fd = open(_g_config->tc358743_dev_path, O_RDWR)) < 0) { + const int fd = open(_g_config->tc358743_dev_path, O_RDWR); + if (fd < 0) { US_LOG_PERROR("Can't open TC358743 V4L2 device"); return -1; } - const int checked = us_tc358743_xioctl_get_audio_hz(fd, hz); - if (checked < 0) { - US_LOG_PERROR("Can't check TC358743 audio state (%d)", checked); + const int result = us_chip_tc358743_get_audio_hz(fd); + if (result > 0) { + *hz = result; + } else if (result != US_ERROR_NO_SIGNAL) { + US_LOG_PERROR("Can't check TC358743 audio state (%d)", result); close(fd); return -1; } diff --git a/janus/src/uslibs/chip.c b/janus/src/uslibs/chip.c new file mode 120000 index 0000000..c9223d1 --- /dev/null +++ b/janus/src/uslibs/chip.c @@ -0,0 +1 @@ +../../../src/libs/chip.c \ No newline at end of file diff --git a/janus/src/uslibs/chip.h b/janus/src/uslibs/chip.h new file mode 120000 index 0000000..9626c87 --- /dev/null +++ b/janus/src/uslibs/chip.h @@ -0,0 +1 @@ +../../../src/libs/chip.h \ No newline at end of file diff --git a/janus/src/uslibs/tc358743.c b/janus/src/uslibs/tc358743.c deleted file mode 120000 index 80c3d4d..0000000 --- a/janus/src/uslibs/tc358743.c +++ /dev/null @@ -1 +0,0 @@ -../../../src/libs/tc358743.c \ No newline at end of file diff --git a/janus/src/uslibs/tc358743.h b/janus/src/uslibs/tc358743.h deleted file mode 120000 index 7fa5903..0000000 --- a/janus/src/uslibs/tc358743.h +++ /dev/null @@ -1 +0,0 @@ -../../../src/libs/tc358743.h \ No newline at end of file diff --git a/src/libs/capture.c b/src/libs/capture.c index dd48d52..a8590b2 100644 --- a/src/libs/capture.c +++ b/src/libs/capture.c @@ -38,7 +38,6 @@ #include #include -#include #include #include @@ -50,8 +49,8 @@ #include "threading.h" #include "frame.h" #include "xioctl.h" -#include "tc358743.h" #include "media.h" +#include "chip.h" static const struct { @@ -208,11 +207,10 @@ int us_capture_open(us_capture_s *cap) { } if (cap->dv_timings && cap->persistent) { - struct v4l2_control ctl = {.id = V4L2_CID_DV_RX_POWER_PRESENT}; - if (!us_xioctl(run->fd, VIDIOC_G_CTRL, &ctl)) { - if (!ctl.value) { - goto error_no_cable; - } + _LOG_DEBUG("Probing the cable ...") + switch (us_chip_check_cable(run->fd)) { + case 0: break; + case US_ERROR_NO_CABLE: goto error_no_cable; } _LOG_DEBUG("Probing DV-timings or QuerySTD ..."); switch (_capture_open_dv_timings(cap, false)) { @@ -245,12 +243,9 @@ int us_capture_open(us_capture_s *cap) { goto error; } if (cap->dv_timings && cap->persistent) { - struct v4l2_control ctl = {.id = TC358743_CID_LANES_ENOUGH}; - if (!us_xioctl(run->fd, VIDIOC_G_CTRL, &ctl)) { - if (!ctl.value) { - _LOG_ERROR("Not enough lanes, hardware can't handle this signal"); - goto error_no_lanes; - } + switch (us_chip_tc358743_check_lanes(run->fd)) { + case 0: break; + case US_ERROR_NO_LANES: goto error_no_lanes; } } _capture_open_hw_fps(cap); @@ -300,6 +295,7 @@ error_no_sync: return US_ERROR_NO_SYNC; 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); return US_ERROR_NO_LANES; diff --git a/src/libs/tc358743.c b/src/libs/chip.c similarity index 63% rename from src/libs/tc358743.c rename to src/libs/chip.c index 5098a99..042c13a 100644 --- a/src/libs/tc358743.c +++ b/src/libs/chip.c @@ -20,7 +20,7 @@ *****************************************************************************/ -#include "tc358743.h" +#include "chip.h" #include #include @@ -29,26 +29,57 @@ #include #include "types.h" +#include "errors.h" #include "tools.h" #include "xioctl.h" -int us_tc358743_xioctl_get_audio_hz(int fd, uint *audio_hz) { - *audio_hz = 0; +#ifndef V4L2_CID_USER_TC358743_BASE +# 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}; if (us_xioctl(fd, VIDIOC_G_CTRL, &ctl) < 0) { - return -1; + return US_ERROR_COMMON; } if (!ctl.value) { - return 0; // No audio + return US_ERROR_NO_SIGNAL; // No audio } US_MEMSET_ZERO(ctl); ctl.id = TC358743_CID_AUDIO_SAMPLING_RATE; if (us_xioctl(fd, VIDIOC_G_CTRL, &ctl) < 0) { - return -1; + return US_ERROR_COMMON; } - *audio_hz = ctl.value; - return 0; + return (ctl.value ? ctl.value : US_ERROR_NO_SIGNAL); } diff --git a/src/libs/tc358743.h b/src/libs/chip.h similarity index 74% rename from src/libs/tc358743.h rename to src/libs/chip.h index 590544b..743bef5 100644 --- a/src/libs/tc358743.h +++ b/src/libs/chip.h @@ -22,26 +22,10 @@ #pragma once -#include - #include "types.h" -#ifndef V4L2_CID_USER_TC358743_BASE -# define V4L2_CID_USER_TC358743_BASE (V4L2_CID_USER_BASE + 0x1080) -#endif +int us_chip_check_cable(int fd); -#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_tc358743_xioctl_get_audio_hz(int fd, uint *audio_hz); +int us_chip_tc358743_check_lanes(int fd); +int us_chip_tc358743_get_audio_hz(int fd);