Skip to content

Commit

Permalink
we don't need us_fpsi_reset() anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
mdevaev committed Mar 30, 2024
1 parent a9e0cb4 commit 165a93e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 26 deletions.
19 changes: 3 additions & 16 deletions src/libs/fpsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
#include "frame.h"


static void _fpsi_bump_unsafe(us_fpsi_s *fpsi, const us_frame_s *frame);


us_fpsi_s *us_fpsi_init(const char *name, bool with_meta) {
us_fpsi_s *fpsi;
US_CALLOC(fpsi, 1);
Expand All @@ -51,13 +48,8 @@ void us_fpsi_destroy(us_fpsi_s *fpsi) {

void us_fpsi_bump(us_fpsi_s *fpsi, const us_frame_s *frame) {
US_MUTEX_LOCK(fpsi->mutex);
_fpsi_bump_unsafe(fpsi, frame);
US_MUTEX_UNLOCK(fpsi->mutex);
}

static void _fpsi_bump_unsafe(us_fpsi_s *fpsi, const us_frame_s *frame) {
const sll now_sec_ts = us_floor_ms(us_get_now_monotonic());
if (now_sec_ts != fpsi->ts) {
if (fpsi->ts != now_sec_ts) {
US_LOG_PERF_FPS("FPS: %s: %u", fpsi->name, fpsi->accum);
fpsi->current = fpsi->accum;
fpsi->accum = 0;
Expand All @@ -70,12 +62,6 @@ static void _fpsi_bump_unsafe(us_fpsi_s *fpsi, const us_frame_s *frame) {
} else {
assert(!fpsi->with_meta);
}
}

void us_fpsi_reset(us_fpsi_s *fpsi, const us_frame_s *frame) {
US_MUTEX_LOCK(fpsi->mutex);
_fpsi_bump_unsafe(fpsi, frame); // Just show the log record
fpsi->accum = 0;
US_MUTEX_UNLOCK(fpsi->mutex);
}

Expand All @@ -86,7 +72,8 @@ uint us_fpsi_get(us_fpsi_s *fpsi, us_fpsi_meta_s *meta) {
assert(!fpsi->with_meta);
}
US_MUTEX_LOCK(fpsi->mutex);
uint current = fpsi->current;
const sll now_sec_ts = us_floor_ms(us_get_now_monotonic());
const uint current = (fpsi->ts == now_sec_ts ? fpsi->current : 0);
if (meta != NULL) {
US_FRAME_COPY_META(&fpsi->meta, meta);
}
Expand Down
1 change: 0 additions & 1 deletion src/libs/fpsi.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,4 @@ 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_reset(us_fpsi_s *fpsi, const us_frame_s *meta);
uint us_fpsi_get(us_fpsi_s *fpsi, us_fpsi_meta_s *meta);
5 changes: 0 additions & 5 deletions src/ustreamer/http/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,6 @@ static void _http_send_stream(us_server_s *server, bool stream_updated, bool fra
us_server_runtime_s *const run = server->run;
us_server_exposed_s *const ex = run->exposed;

bool has_clients = false;
bool queued = false;

US_LIST_ITERATE(run->stream_clients, client, { // cppcheck-suppress constStatement
Expand Down Expand Up @@ -845,15 +844,11 @@ 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);
} else if (!has_clients) {
us_fpsi_reset(ex->queued_fpsi, NULL);
}
}

Expand Down
12 changes: 8 additions & 4 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_reset(http->captured_fpsi, run->blank->raw);
us_fpsi_bump(http->captured_fpsi, run->blank->raw);
return stream;
}

Expand Down Expand Up @@ -465,16 +465,19 @@ static void *_drm_thread(void *v_ctx) {
}

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

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

SLOWDOWN;
}

close:
atomic_store(&stream->run->http->drm_live, false);
us_drm_close(stream->drm);
US_DELETE(prev_hw, us_capture_hwbuf_decref);

atomic_store(&stream->run->http->drm_live, false);

SLOWDOWN;

# undef SLOWDOWN
Expand Down Expand Up @@ -570,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_reset(run->http->captured_fpsi, run->blank->raw);
us_fpsi_bump(run->http->captured_fpsi, run->blank->raw);

_stream_expose_jpeg(stream, run->blank->jpeg);
_stream_expose_raw(stream, run->blank->raw);
Expand All @@ -591,6 +594,7 @@ static void _stream_drm_ensure_no_signal(us_stream_s *stream) {
if (stream->drm == NULL) {
return;
}
atomic_store(&stream->run->http->drm_live, false);
if (stream->drm->run->opened <= 0) {
us_drm_close(stream->drm);
if (us_drm_open(stream->drm, NULL) < 0) {
Expand Down

0 comments on commit 165a93e

Please sign in to comment.