device: Keep DV-timing Hz

(cherry picked from commit 17a448223c0dd1cf420ba9a79232f433ff11c4b5)
Signed-off-by: Maxim Devaev <mdevaev@gmail.com>
This commit is contained in:
Maxim Devaev
2024-02-23 04:01:00 +00:00
parent 3c7564da19
commit 5f7c556697
2 changed files with 11 additions and 7 deletions

View File

@@ -68,7 +68,7 @@ static int _device_open_io_method(us_device_s *dev);
static int _device_open_io_method_mmap(us_device_s *dev); static int _device_open_io_method_mmap(us_device_s *dev);
static int _device_open_io_method_userptr(us_device_s *dev); static int _device_open_io_method_userptr(us_device_s *dev);
static int _device_open_queue_buffers(us_device_s *dev); static int _device_open_queue_buffers(us_device_s *dev);
static int _device_apply_resolution(us_device_s *dev, unsigned width, unsigned height); static int _device_apply_resolution(us_device_s *dev, unsigned width, unsigned height, float hz);
static void _device_apply_controls(us_device_s *dev); static void _device_apply_controls(us_device_s *dev);
static int _device_query_control( static int _device_query_control(
@@ -534,7 +534,7 @@ static int _device_open_check_cap(us_device_s *dev) {
} }
static int _device_open_dv_timings(us_device_s *dev) { static int _device_open_dv_timings(us_device_s *dev) {
_device_apply_resolution(dev, dev->width, dev->height); _device_apply_resolution(dev, dev->width, dev->height, dev->run->hz);
if (dev->dv_timings) { if (dev->dv_timings) {
US_LOG_DEBUG("Using DV-timings"); US_LOG_DEBUG("Using DV-timings");
@@ -559,13 +559,15 @@ static int _device_apply_dv_timings(us_device_s *dev) {
US_LOG_DEBUG("Calling us_xioctl(VIDIOC_QUERY_DV_TIMINGS) ..."); US_LOG_DEBUG("Calling us_xioctl(VIDIOC_QUERY_DV_TIMINGS) ...");
if (us_xioctl(run->fd, VIDIOC_QUERY_DV_TIMINGS, &dv) == 0) { if (us_xioctl(run->fd, VIDIOC_QUERY_DV_TIMINGS, &dv) == 0) {
float hz = 0;
if (dv.type == V4L2_DV_BT_656_1120) { if (dv.type == V4L2_DV_BT_656_1120) {
// See v4l2_print_dv_timings() in the kernel // See v4l2_print_dv_timings() in the kernel
const unsigned htot = V4L2_DV_BT_FRAME_WIDTH(&dv.bt); const unsigned htot = V4L2_DV_BT_FRAME_WIDTH(&dv.bt);
const unsigned vtot = V4L2_DV_BT_FRAME_HEIGHT(&dv.bt) / (dv.bt.interlaced ? 2 : 1); const unsigned vtot = V4L2_DV_BT_FRAME_HEIGHT(&dv.bt) / (dv.bt.interlaced ? 2 : 1);
const unsigned fps = ((htot * vtot) > 0 ? ((100 * (uint64_t)dv.bt.pixelclock)) / (htot * vtot) : 0); const unsigned fps = ((htot * vtot) > 0 ? ((100 * (uint64_t)dv.bt.pixelclock)) / (htot * vtot) : 0);
US_LOG_INFO("Got new DV-timings: %ux%u%s%u.%02u, pixclk=%llu, vsync=%u, hsync=%u", hz = (fps / 100) + (fps % 100) / 100.0;
dv.bt.width, dv.bt.height, (dv.bt.interlaced ? "i" : "p"), fps / 100, fps % 100, US_LOG_INFO("Got new DV-timings: %ux%u%s%.02f, pixclk=%llu, vsync=%u, hsync=%u",
dv.bt.width, dv.bt.height, (dv.bt.interlaced ? "i" : "p"), hz,
(unsigned long long)dv.bt.pixelclock, dv.bt.vsync, dv.bt.hsync); // See #11 about %llu (unsigned long long)dv.bt.pixelclock, dv.bt.vsync, dv.bt.hsync); // See #11 about %llu
} else { } else {
US_LOG_INFO("Got new DV-timings: %ux%u, pixclk=%llu, vsync=%u, hsync=%u", US_LOG_INFO("Got new DV-timings: %ux%u, pixclk=%llu, vsync=%u, hsync=%u",
@@ -579,7 +581,7 @@ static int _device_apply_dv_timings(us_device_s *dev) {
return -1; return -1;
} }
if (_device_apply_resolution(dev, dv.bt.width, dv.bt.height) < 0) { if (_device_apply_resolution(dev, dv.bt.width, dv.bt.height, hz) < 0) {
return -1; return -1;
} }
@@ -640,7 +642,7 @@ static int _device_open_format(us_device_s *dev, bool first) {
US_LOG_ERROR("Requested resolution=%ux%u is unavailable", run->width, run->height); US_LOG_ERROR("Requested resolution=%ux%u is unavailable", run->width, run->height);
retry = true; retry = true;
} }
if (_device_apply_resolution(dev, FMT(width), FMT(height)) < 0) { if (_device_apply_resolution(dev, FMT(width), FMT(height), run->hz) < 0) {
return -1; return -1;
} }
if (first && retry) { if (first && retry) {
@@ -897,7 +899,7 @@ static int _device_open_queue_buffers(us_device_s *dev) {
return 0; return 0;
} }
static int _device_apply_resolution(us_device_s *dev, unsigned width, unsigned height) { static int _device_apply_resolution(us_device_s *dev, unsigned width, unsigned height, float hz) {
// Тут VIDEO_MIN_* не используются из-за странностей минимального разрешения при отсутствии сигнала // Тут VIDEO_MIN_* не используются из-за странностей минимального разрешения при отсутствии сигнала
// у некоторых устройств, например TC358743 // у некоторых устройств, например TC358743
if ( if (
@@ -910,6 +912,7 @@ static int _device_apply_resolution(us_device_s *dev, unsigned width, unsigned h
} }
dev->run->width = width; dev->run->width = width;
dev->run->height = height; dev->run->height = height;
dev->run->hz = hz;
return 0; return 0;
} }

View File

@@ -80,6 +80,7 @@ typedef struct {
unsigned height; unsigned height;
unsigned format; unsigned format;
unsigned stride; unsigned stride;
float hz;
unsigned hw_fps; unsigned hw_fps;
unsigned jpeg_quality; unsigned jpeg_quality;
size_t raw_size; size_t raw_size;