mirror of
https://github.com/pikvm/ustreamer.git
synced 2026-07-17 17:21:55 +00:00
refactoring
This commit is contained in:
@@ -38,7 +38,6 @@
|
||||
|
||||
#include <pthread.h>
|
||||
#include <linux/videodev2.h>
|
||||
#include <linux/v4l2-controls.h>
|
||||
#include <linux/media.h>
|
||||
#include <linux/v4l2-subdev.h>
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
*****************************************************************************/
|
||||
|
||||
|
||||
#include "tc358743.h"
|
||||
#include "chip.h"
|
||||
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
@@ -29,26 +29,57 @@
|
||||
#include <linux/v4l2-controls.h>
|
||||
|
||||
#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);
|
||||
}
|
||||
@@ -22,26 +22,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <linux/v4l2-controls.h>
|
||||
|
||||
#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);
|
||||
Reference in New Issue
Block a user