Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
mdevaev committed Mar 29, 2024
1 parent 3f69dd7 commit 9a3758e
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 189 deletions.
2 changes: 1 addition & 1 deletion src/dump/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ static int _dump_sink(
us_frame_s *frame = us_frame_init();
us_memsink_s *sink = NULL;

if ((sink = us_memsink_init("input", sink_name, false, 0, false, 0, sink_timeout)) == NULL) {
if ((sink = us_memsink_init_opened("input", sink_name, false, 0, false, 0, sink_timeout)) == NULL) {
goto error;
}

Expand Down
2 changes: 1 addition & 1 deletion src/libs/memsink.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#include "memsinksh.h"


us_memsink_s *us_memsink_init(
us_memsink_s *us_memsink_init_opened(
const char *name, const char *obj, bool server,
mode_t mode, bool rm, uint client_ttl, uint timeout) {

Expand Down
2 changes: 1 addition & 1 deletion src/libs/memsink.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ typedef struct {
} us_memsink_s;


us_memsink_s *us_memsink_init(
us_memsink_s *us_memsink_init_opened(
const char *name, const char *obj, bool server,
mode_t mode, bool rm, uint client_ttl, uint timeout);

Expand Down
78 changes: 0 additions & 78 deletions src/ustreamer/h264.c

This file was deleted.

46 changes: 0 additions & 46 deletions src/ustreamer/h264.h

This file was deleted.

4 changes: 2 additions & 2 deletions src/ustreamer/http/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -473,12 +473,12 @@ static void _http_callback_state(struct evhttp_request *request, void *v_server)
enc_quality
);

if (stream->run->h264 != NULL) {
if (stream->h264_sink != NULL) {
_A_EVBUFFER_ADD_PRINTF(buf,
" \"h264\": {\"bitrate\": %u, \"gop\": %u, \"online\": %s},",
stream->h264_bitrate,
stream->h264_gop,
us_bool_to_string(atomic_load(&stream->run->h264->online))
us_bool_to_string(atomic_load(&stream->run->h264_online))
);
}

Expand Down
23 changes: 20 additions & 3 deletions src/ustreamer/m2m.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,31 @@ void us_m2m_encoder_destroy(us_m2m_encoder_s *enc) {
int us_m2m_encoder_compress(us_m2m_encoder_s *enc, const us_frame_s *src, us_frame_s *dest, bool force_key) {
us_m2m_encoder_runtime_s *const run = enc->run;

us_frame_encoding_begin(src, dest, (enc->output_format == V4L2_PIX_FMT_MJPEG ? V4L2_PIX_FMT_JPEG : enc->output_format));
const ldf now_ts = us_get_now_monotonic();
uint dest_format = enc->output_format;
switch (enc->output_format) {
case V4L2_PIX_FMT_JPEG:
force_key = false;
// fall through
case V4L2_PIX_FMT_MJPEG:
dest_format = V4L2_PIX_FMT_JPEG;
break;
case V4L2_PIX_FMT_H264:
force_key = (
force_key
|| run->last_online != src->online
|| run->last_encode_ts + 0.5 < now_ts
);
break;
}

us_frame_encoding_begin(src, dest, dest_format);

_m2m_encoder_ensure(enc, src);
if (!run->ready) { // Already prepared but failed
return -1;
}

force_key = (enc->output_format == V4L2_PIX_FMT_H264 && (force_key || run->last_online != src->online));

_LOG_DEBUG("Compressing new frame; force_key=%d ...", force_key);

if (_m2m_encoder_compress_raw(enc, src, dest, force_key) < 0) {
Expand All @@ -118,6 +134,7 @@ int us_m2m_encoder_compress(us_m2m_encoder_s *enc, const us_frame_s *src, us_fra
dest->used, dest->encode_end_ts - dest->encode_begin_ts, force_key);

run->last_online = src->online;
run->last_encode_ts = now_ts;
return 0;
}

Expand Down
1 change: 1 addition & 0 deletions src/ustreamer/m2m.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ typedef struct {

bool ready;
int last_online;
ldf last_encode_ts;
} us_m2m_encoder_runtime_s;

typedef struct {
Expand Down
2 changes: 1 addition & 1 deletion src/ustreamer/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ int options_parse(us_options_s *options, us_capture_s *cap, us_encoder_s *enc, u

# define ADD_SINK(x_label, x_prefix) { \
if (x_prefix##_name && x_prefix##_name[0] != '\0') { \
options->x_prefix = us_memsink_init( \
options->x_prefix = us_memsink_init_opened( \
x_label, \
x_prefix##_name, \
true, \
Expand Down
Loading

0 comments on commit 9a3758e

Please sign in to comment.