Skip to content

Commit

Permalink
sort of fps reset
Browse files Browse the repository at this point in the history
  • Loading branch information
mdevaev committed Mar 30, 2024
1 parent 3a3889d commit 5f3198e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/dump/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ static int _dump_sink(
US_LOG_DEBUG(" stride=%u, grab_ts=%.3Lf, encode_begin_ts=%.3Lf, encode_end_ts=%.3Lf",
frame->stride, frame->grab_ts, frame->encode_begin_ts, frame->encode_end_ts);

us_fpsi_bump(fpsi, NULL);
us_fpsi_bump(fpsi, NULL, false);

if (ctx->v_output != NULL) {
ctx->write(ctx->v_output, frame);
Expand Down
6 changes: 4 additions & 2 deletions src/libs/fpsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void us_fpsi_destroy(us_fpsi_s *fpsi) {
free(fpsi);
}

void us_fpsi_bump(us_fpsi_s *fpsi, const us_frame_s *frame) {
void us_fpsi_bump(us_fpsi_s *fpsi, const us_frame_s *frame, bool noop) {
if (frame != NULL) {
assert(fpsi->with_meta);
} else {
Expand All @@ -72,7 +72,9 @@ void us_fpsi_bump(us_fpsi_s *fpsi, const us_frame_s *frame) {
atomic_store(&fpsi->ts, now_sec_ts);
fpsi->accum = 0;
}
++fpsi->accum;
if (!noop) {
++fpsi->accum;
}

if (fpsi->with_meta) {
assert(frame != NULL);
Expand Down
2 changes: 1 addition & 1 deletion src/libs/fpsi.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@ typedef struct {
us_fpsi_s *us_fpsi_init(const char *name, bool with_meta);
void us_fpsi_destroy(us_fpsi_s *fpsi);

void us_fpsi_bump(us_fpsi_s *fpsi, const us_frame_s *frame);
void us_fpsi_bump(us_fpsi_s *fpsi, const us_frame_s *frame, bool noop);
uint us_fpsi_get(us_fpsi_s *fpsi, us_fpsi_meta_s *meta);
8 changes: 6 additions & 2 deletions src/ustreamer/http/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ static void _http_callback_stream_write(struct bufferevent *buf_event, void *v_c
us_server_s *const server = client->server;
us_server_exposed_s *const ex = server->run->exposed;

us_fpsi_bump(client->fpsi, NULL);
us_fpsi_bump(client->fpsi, NULL, false);

struct evbuffer *buf;
_A_EVBUFFER_NEW(buf);
Expand Down Expand Up @@ -815,6 +815,7 @@ static void _http_send_stream(us_server_s *server, bool stream_updated, bool fra
us_server_exposed_s *const ex = run->exposed;

bool queued = false;
bool has_clients = true;

US_LIST_ITERATE(run->stream_clients, client, { // cppcheck-suppress constStatement
struct evhttp_connection *const conn = evhttp_request_get_connection(client->request);
Expand Down Expand Up @@ -844,11 +845,14 @@ static void _http_send_stream(us_server_s *server, bool stream_updated, bool fra
} else if (stream_updated) { // Для dual
client->updated_prev = false;
}
has_clients = true;
}
});

if (queued) {
us_fpsi_bump(ex->queued_fpsi, NULL);
us_fpsi_bump(ex->queued_fpsi, NULL, false);
} else if (!has_clients) {
us_fpsi_bump(ex->queued_fpsi, NULL, true);
}
}

Expand Down
14 changes: 7 additions & 7 deletions src/ustreamer/stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ us_stream_s *us_stream_init(us_capture_s *cap, us_encoder_s *enc) {
stream->run = run;

us_blank_draw(run->blank, "< NO SIGNAL >", cap->width, cap->height);
us_fpsi_bump(http->captured_fpsi, run->blank->raw);
us_fpsi_bump(http->captured_fpsi, run->blank->raw, true);
return stream;
}

Expand Down Expand Up @@ -200,7 +200,7 @@ void us_stream_loop(us_stream_s *stream) {
default: goto close; // Any error
}

us_fpsi_bump(run->http->captured_fpsi, &hw->raw);
us_fpsi_bump(run->http->captured_fpsi, &hw->raw, false);

# ifdef WITH_GPIO
us_gpio_set_stream_online(true);
Expand Down Expand Up @@ -460,14 +460,14 @@ static void *_drm_thread(void *v_ctx) {
CHECK(us_drm_expose_dma(stream->drm, hw));
prev_hw = hw;
atomic_store(&stream->run->http->drm_live, true);
us_fpsi_bump(stream->run->http->drm_fpsi, NULL);
us_fpsi_bump(stream->run->http->drm_fpsi, NULL, false);
continue;
}

CHECK(us_drm_expose_stub(stream->drm, stream->drm->run->opened, ctx->stream->cap));
us_capture_hwbuf_decref(hw);

us_fpsi_bump(stream->run->http->drm_fpsi, NULL);
us_fpsi_bump(stream->run->http->drm_fpsi, NULL, false);

SLOWDOWN;
}
Expand Down Expand Up @@ -573,7 +573,7 @@ static int _stream_init_loop(us_stream_s *stream) {
height = stream->cap->height;
}
us_blank_draw(run->blank, "< NO SIGNAL >", width, height);
us_fpsi_bump(run->http->captured_fpsi, run->blank->raw);
us_fpsi_bump(run->http->captured_fpsi, run->blank->raw, true);

_stream_expose_jpeg(stream, run->blank->jpeg);
_stream_expose_raw(stream, run->blank->raw);
Expand Down Expand Up @@ -604,7 +604,7 @@ static void _stream_drm_ensure_no_signal(us_stream_s *stream) {
if (us_drm_ensure_no_signal(stream->drm) < 0) {
goto close;
}
us_fpsi_bump(stream->run->http->drm_fpsi, NULL);
us_fpsi_bump(stream->run->http->drm_fpsi, NULL, false);
return;
close:
us_drm_close(stream->drm);
Expand Down Expand Up @@ -655,10 +655,10 @@ static void _stream_encode_expose_h264(us_stream_s *stream, const us_frame_s *fr
if (!us_m2m_encoder_compress(run->h264_enc, frame, run->h264_dest, force_key)) {
online = !us_memsink_server_put(stream->h264_sink, run->h264_dest, &run->h264_key_requested);
}
us_fpsi_bump(run->http->h264_fpsi, NULL, false);

done:
atomic_store(&run->http->h264_online, online);
us_fpsi_bump(run->http->h264_fpsi, NULL);
}

static void _stream_check_suicide(us_stream_s *stream) {
Expand Down

0 comments on commit 5f3198e

Please sign in to comment.