mirror of
https://github.com/pikvm/ustreamer.git
synced 2026-03-13 11:03:43 +00:00
refactoring
This commit is contained in:
@@ -89,7 +89,7 @@ void us_stream_loop(us_stream_s *stream) {
|
|||||||
ldf grab_after = 0;
|
ldf grab_after = 0;
|
||||||
uint fluency_passed = 0;
|
uint fluency_passed = 0;
|
||||||
uint captured_fps_accum = 0;
|
uint captured_fps_accum = 0;
|
||||||
sll captured_fps_second = 0;
|
sll captured_fps_ts = 0;
|
||||||
|
|
||||||
US_LOG_INFO("Capturing ...");
|
US_LOG_INFO("Capturing ...");
|
||||||
|
|
||||||
@@ -134,29 +134,29 @@ void us_stream_loop(us_stream_s *stream) {
|
|||||||
us_gpio_set_stream_online(true);
|
us_gpio_set_stream_online(true);
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
const ldf now = us_get_now_monotonic();
|
const ldf now_ts = us_get_now_monotonic();
|
||||||
|
|
||||||
if (now < grab_after) {
|
if (now_ts < grab_after) {
|
||||||
fluency_passed += 1;
|
fluency_passed += 1;
|
||||||
US_LOG_VERBOSE("Passed %u frames for fluency: now=%.03Lf, grab_after=%.03Lf",
|
US_LOG_VERBOSE("Passed %u frames for fluency: now=%.03Lf, grab_after=%.03Lf",
|
||||||
fluency_passed, now, grab_after);
|
fluency_passed, now_ts, grab_after);
|
||||||
if (us_device_release_buffer(stream->dev, hw) < 0) {
|
if (us_device_release_buffer(stream->dev, hw) < 0) {
|
||||||
goto close;
|
goto close;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fluency_passed = 0;
|
fluency_passed = 0;
|
||||||
|
|
||||||
const sll now_second = us_floor_ms(now);
|
const sll now_sec_ts = us_floor_ms(now_ts);
|
||||||
if (now_second != captured_fps_second) {
|
if (now_sec_ts != captured_fps_ts) {
|
||||||
US_LOG_PERF_FPS("A new second has come; captured_fps=%u", captured_fps_accum);
|
US_LOG_PERF_FPS("A new second has come; captured_fps=%u", captured_fps_accum);
|
||||||
atomic_store(&run->captured_fps, captured_fps_accum);
|
atomic_store(&run->captured_fps, captured_fps_accum);
|
||||||
captured_fps_accum = 0;
|
captured_fps_accum = 0;
|
||||||
captured_fps_second = now_second;
|
captured_fps_ts = now_sec_ts;
|
||||||
}
|
}
|
||||||
captured_fps_accum += 1;
|
captured_fps_accum += 1;
|
||||||
|
|
||||||
const ldf fluency_delay = us_workers_pool_get_fluency_delay(stream->enc->run->pool, ready_wr);
|
const ldf fluency_delay = us_workers_pool_get_fluency_delay(stream->enc->run->pool, ready_wr);
|
||||||
grab_after = now + fluency_delay;
|
grab_after = now_ts + fluency_delay;
|
||||||
US_LOG_VERBOSE("Fluency: delay=%.03Lf, grab_after=%.03Lf", fluency_delay, grab_after);
|
US_LOG_VERBOSE("Fluency: delay=%.03Lf, grab_after=%.03Lf", fluency_delay, grab_after);
|
||||||
|
|
||||||
ready_job->hw = hw;
|
ready_job->hw = hw;
|
||||||
@@ -191,15 +191,15 @@ static bool _stream_is_stopped(us_stream_s *stream) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (stream->exit_on_no_clients > 0) {
|
if (stream->exit_on_no_clients > 0) {
|
||||||
const ldf now = us_get_now_monotonic();
|
const ldf now_ts = us_get_now_monotonic();
|
||||||
const u64 http_last_request_ts = atomic_load(&run->http_last_request_ts); // Seconds
|
const ull http_last_request_ts = atomic_load(&run->http_last_request_ts); // Seconds
|
||||||
if (_stream_has_any_clients(stream)) {
|
if (_stream_has_any_clients(stream)) {
|
||||||
atomic_store(&run->http_last_request_ts, now);
|
atomic_store(&run->http_last_request_ts, now_ts);
|
||||||
} else if (http_last_request_ts + stream->exit_on_no_clients < now) {
|
} else if (http_last_request_ts + stream->exit_on_no_clients < now_ts) {
|
||||||
US_LOG_INFO("No requests or HTTP/sink clients found in last %u seconds, exiting ...",
|
US_LOG_INFO("No requests or HTTP/sink clients found in last %u seconds, exiting ...",
|
||||||
stream->exit_on_no_clients);
|
stream->exit_on_no_clients);
|
||||||
us_process_suicide();
|
us_process_suicide();
|
||||||
atomic_store(&run->http_last_request_ts, now);
|
atomic_store(&run->http_last_request_ts, now_ts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -53,7 +53,7 @@
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
us_ring_s *http_jpeg_ring;
|
us_ring_s *http_jpeg_ring;
|
||||||
atomic_bool http_has_clients;
|
atomic_bool http_has_clients;
|
||||||
atomic_uint_least64_t http_last_request_ts; // Seconds
|
atomic_ullong http_last_request_ts; // Seconds
|
||||||
atomic_uint captured_fps;
|
atomic_uint captured_fps;
|
||||||
|
|
||||||
bool last_online;
|
bool last_online;
|
||||||
|
|||||||
Reference in New Issue
Block a user