mirror of
https://github.com/pikvm/ustreamer.git
synced 2026-02-19 08:16:31 +00:00
simplified
This commit is contained in:
@@ -289,30 +289,31 @@ int us_device_switch_capturing(us_device_s *dev, bool enable) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int us_device_select(us_device_s *dev, bool *has_read, bool *has_write, bool *has_error) {
|
||||
int us_device_select(us_device_s *dev, bool *has_read, bool *has_error) {
|
||||
us_device_runtime_s *const run = dev->run;
|
||||
|
||||
# define INIT_FD_SET(x_set) \
|
||||
fd_set x_set; FD_ZERO(&x_set); FD_SET(run->fd, &x_set);
|
||||
INIT_FD_SET(read_fds);
|
||||
INIT_FD_SET(write_fds);
|
||||
INIT_FD_SET(error_fds);
|
||||
# undef INIT_FD_SET
|
||||
|
||||
// Раньше мы проверяли и has_write, но потом выяснилось, что libcamerify зачем-то
|
||||
// генерирует эвенты на запись, вероятно ошибочно. Судя по всему, игнорирование
|
||||
// has_write не делает никому плохо.
|
||||
|
||||
struct timeval timeout;
|
||||
timeout.tv_sec = dev->timeout;
|
||||
timeout.tv_usec = 0;
|
||||
|
||||
_D_LOG_DEBUG("Calling select() on video device ...");
|
||||
|
||||
int retval = select(run->fd + 1, &read_fds, &write_fds, &error_fds, &timeout);
|
||||
int retval = select(run->fd + 1, &read_fds, NULL, &error_fds, &timeout);
|
||||
if (retval > 0) {
|
||||
*has_read = FD_ISSET(run->fd, &read_fds);
|
||||
*has_write = FD_ISSET(run->fd, &write_fds);
|
||||
*has_error = FD_ISSET(run->fd, &error_fds);
|
||||
} else {
|
||||
*has_read = false;
|
||||
*has_write = false;
|
||||
*has_error = false;
|
||||
}
|
||||
_D_LOG_DEBUG("Device select() --> %d", retval);
|
||||
|
||||
@@ -131,7 +131,7 @@ void us_device_close(us_device_s *dev);
|
||||
|
||||
int us_device_export_to_dma(us_device_s *dev);
|
||||
int us_device_switch_capturing(us_device_s *dev, bool enable);
|
||||
int us_device_select(us_device_s *dev, bool *has_read, bool *has_write, bool *has_error);
|
||||
int us_device_select(us_device_s *dev, bool *has_read, bool *has_error);
|
||||
int us_device_grab_buffer(us_device_s *dev, us_hw_buffer_s **hw);
|
||||
int us_device_release_buffer(us_device_s *dev, us_hw_buffer_s *hw);
|
||||
int us_device_consume_event(us_device_s *dev);
|
||||
|
||||
@@ -136,9 +136,8 @@ void us_stream_loop(us_stream_s *stream) {
|
||||
}
|
||||
|
||||
bool has_read;
|
||||
bool has_write;
|
||||
bool has_error;
|
||||
const int selected = us_device_select(stream->dev, &has_read, &has_write, &has_error);
|
||||
const int selected = us_device_select(stream->dev, &has_read, &has_error);
|
||||
|
||||
if (selected < 0) {
|
||||
if (errno != EINTR) {
|
||||
@@ -198,14 +197,6 @@ void us_stream_loop(us_stream_s *stream) {
|
||||
}
|
||||
}
|
||||
|
||||
// Это условие было добавлено из параноидальных соображений, и мы ни разу не сталкивались
|
||||
// с подобными ошибками, кроме случая с libcamerify, который генерит эвенты на запись.
|
||||
// Судя по всему, игнорирование has_write не делает никому плохо.
|
||||
/*if (has_write) {
|
||||
US_LOG_ERROR("Got unexpected writing event, seems device was disconnected");
|
||||
break;
|
||||
}*/
|
||||
|
||||
if (has_error) {
|
||||
US_LOG_INFO("Got V4L2 event");
|
||||
if (us_device_consume_event(stream->dev) < 0) {
|
||||
|
||||
@@ -211,9 +211,6 @@ static void _main_loop(void) {
|
||||
|
||||
while (!atomic_load(&_g_stop)) {
|
||||
if (atomic_load(&_g_ustreamer_online)) {
|
||||
if (us_drm_wait_for_vsync(drm) == 0) {
|
||||
us_drm_expose(drm, US_DRM_EXPOSE_BUSY, NULL, 0);
|
||||
}
|
||||
goto close;
|
||||
}
|
||||
|
||||
@@ -223,9 +220,8 @@ static void _main_loop(void) {
|
||||
}
|
||||
|
||||
bool has_read;
|
||||
bool has_write;
|
||||
bool has_error;
|
||||
const int selected = us_device_select(dev, &has_read, &has_write, &has_error);
|
||||
const int selected = us_device_select(dev, &has_read, &has_error);
|
||||
|
||||
if (selected < 0) {
|
||||
if (errno != EINTR) {
|
||||
|
||||
Reference in New Issue
Block a user