mirror of
https://github.com/pikvm/ustreamer.git
synced 2026-03-03 22:31:43 +00:00
new macro US_ONCE_FOR()
This commit is contained in:
@@ -176,10 +176,9 @@ int us_capture_open(us_capture_s *cap) {
|
||||
us_capture_runtime_s *const run = cap->run;
|
||||
|
||||
if (access(cap->path, R_OK | W_OK) < 0) {
|
||||
if (run->open_error_reported != -errno) {
|
||||
run->open_error_reported = -errno; // Don't confuse it with __LINE__
|
||||
US_ONCE_FOR(run->open_error_once, -errno, {
|
||||
US_LOG_PERROR("No access to capture device");
|
||||
}
|
||||
});
|
||||
goto error_no_device;
|
||||
}
|
||||
|
||||
@@ -193,11 +192,9 @@ int us_capture_open(us_capture_s *cap) {
|
||||
if (cap->dv_timings && cap->persistent) {
|
||||
_LOG_DEBUG("Probing DV-timings or QuerySTD ...");
|
||||
if (_capture_open_dv_timings(cap, false) < 0) {
|
||||
const int line = __LINE__;
|
||||
if (run->open_error_reported != line) {
|
||||
run->open_error_reported = line;
|
||||
US_ONCE_FOR(run->open_error_once, __LINE__, {
|
||||
_LOG_ERROR("No signal from source");
|
||||
}
|
||||
});
|
||||
goto error_no_signal;
|
||||
}
|
||||
}
|
||||
@@ -238,7 +235,7 @@ int us_capture_open(us_capture_s *cap) {
|
||||
}
|
||||
run->streamon = true;
|
||||
|
||||
run->open_error_reported = 0;
|
||||
run->open_error_once = 0;
|
||||
_LOG_INFO("Capturing started");
|
||||
return 0;
|
||||
|
||||
@@ -251,7 +248,7 @@ error_no_signal:
|
||||
return US_ERROR_NO_DATA;
|
||||
|
||||
error:
|
||||
run->open_error_reported = 0;
|
||||
run->open_error_once = 0;
|
||||
us_capture_close(cap);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ typedef struct {
|
||||
enum v4l2_buf_type capture_type;
|
||||
bool capture_mplane;
|
||||
bool streamon;
|
||||
int open_error_reported;
|
||||
int open_error_once;
|
||||
} us_capture_runtime_s;
|
||||
|
||||
typedef enum {
|
||||
|
||||
@@ -166,7 +166,7 @@ int us_drm_open(us_drm_s *drm, const us_capture_s *cap) {
|
||||
|
||||
run->opened_for_stub = (stub > 0);
|
||||
run->exposing_dma_fd = -1;
|
||||
run->unplugged_reported = false;
|
||||
run->unplugged_once = 0;
|
||||
_LOG_INFO("Opened for %s ...", (run->opened_for_stub ? "STUB" : "DMA"));
|
||||
return stub;
|
||||
|
||||
@@ -175,10 +175,9 @@ error:
|
||||
return -1;
|
||||
|
||||
unplugged:
|
||||
if (!run->unplugged_reported) {
|
||||
US_ONCE_FOR(run->unplugged_once, __LINE__, {
|
||||
_LOG_ERROR("Display is not plugged");
|
||||
run->unplugged_reported = true;
|
||||
}
|
||||
});
|
||||
us_drm_close(drm);
|
||||
return US_ERROR_NO_DEVICE;
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ typedef struct {
|
||||
bool has_vsync;
|
||||
int exposing_dma_fd;
|
||||
uint stub_n_buf;
|
||||
bool unplugged_reported;
|
||||
int unplugged_once;
|
||||
us_frametext_s *ft;
|
||||
} us_drm_runtime_s;
|
||||
|
||||
|
||||
@@ -72,14 +72,16 @@
|
||||
(m_a > m_b ? m_a : m_b); \
|
||||
})
|
||||
|
||||
#define US_ONCE(...) { \
|
||||
const int m_reported = __LINE__; \
|
||||
if (m_reported != once) { \
|
||||
#define US_ONCE_FOR(x_once, x_value, ...) { \
|
||||
const int m_reported = (x_value); \
|
||||
if (m_reported != (x_once)) { \
|
||||
__VA_ARGS__; \
|
||||
once = m_reported; \
|
||||
(x_once) = m_reported; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define US_ONCE(...) US_ONCE_FOR(once, __LINE__, ##__VA_ARGS__)
|
||||
|
||||
|
||||
INLINE char *us_strdup(const char *str) {
|
||||
char *const new = strdup(str);
|
||||
|
||||
@@ -576,7 +576,7 @@ static bool _stream_has_any_clients_cached(us_stream_s *stream) {
|
||||
static int _stream_init_loop(us_stream_s *stream) {
|
||||
us_stream_runtime_s *const run = stream->run;
|
||||
|
||||
bool waiting_reported = false;
|
||||
int once = 0;
|
||||
while (!atomic_load(&stream->run->stop)) {
|
||||
# ifdef WITH_GPIO
|
||||
us_gpio_set_stream_online(false);
|
||||
@@ -605,13 +605,10 @@ static int _stream_init_loop(us_stream_s *stream) {
|
||||
case 0: break;
|
||||
case US_ERROR_NO_DEVICE:
|
||||
case US_ERROR_NO_DATA:
|
||||
if (!waiting_reported) {
|
||||
waiting_reported = true;
|
||||
US_LOG_INFO("Waiting for the capture device ...");
|
||||
}
|
||||
US_ONCE({ US_LOG_INFO("Waiting for the capture device ..."); });
|
||||
goto offline_and_retry;
|
||||
default:
|
||||
waiting_reported = false;
|
||||
once = 0;
|
||||
goto offline_and_retry;
|
||||
}
|
||||
us_encoder_open(stream->enc, stream->cap);
|
||||
|
||||
Reference in New Issue
Block a user