Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
mdevaev committed Feb 29, 2024
1 parent a3f4294 commit 3e5a444
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 17 deletions.
2 changes: 1 addition & 1 deletion python/src/ustreamer.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ static int _wait_frame(_MemsinkObject *self) {
if (mem->magic == US_MEMSINK_MAGIC && mem->version == US_MEMSINK_VERSION && mem->id != self->frame_id) {
if (self->drop_same_frames > 0) {
if (
US_FRAME_COMPARE_META_USED_NOTS(self->mem, self->frame)
US_FRAME_COMPARE_GEOMETRY(self->mem, self->frame)
&& (self->frame_ts + self->drop_same_frames > now_ts)
&& !memcmp(self->frame->data, mem->data, mem->used)
) {
Expand Down
6 changes: 5 additions & 1 deletion src/libs/frame.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void us_frame_copy(const us_frame_s *src, us_frame_s *dest) {
bool us_frame_compare(const us_frame_s *a, const us_frame_s *b) {
return (
a->allocated && b->allocated
&& US_FRAME_COMPARE_META_USED_NOTS(a, b)
&& US_FRAME_COMPARE_GEOMETRY(a, b)
&& !memcmp(a->data, b->data, b->used)
);
}
Expand All @@ -99,6 +99,10 @@ uint us_frame_get_padding(const us_frame_s *frame) {
return 0;
}

bool us_is_jpeg(uint format) {
return (format == V4L2_PIX_FMT_JPEG || format == V4L2_PIX_FMT_MJPEG);
}

const char *us_fourcc_to_string(uint format, char *buf, uz size) {
assert(size >= 8);
buf[0] = format & 0x7F;
Expand Down
17 changes: 4 additions & 13 deletions src/libs/frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

#pragma once

#include <linux/videodev2.h>

#include "types.h"
#include "tools.h"

Expand All @@ -41,7 +39,6 @@ typedef struct {
// Stride is a bytesperline in V4L2
// https://www.kernel.org/doc/html/v4.14/media/uapi/v4l/pixfmt-v4l2.html
// https://medium.com/@oleg.shipitko/what-does-stride-mean-in-image-processing-bba158a72bcd

bool online;
bool key;
uint gop;
Expand All @@ -65,11 +62,8 @@ typedef struct {
x_dest->encode_end_ts = x_src->encode_end_ts; \
}

static inline void us_frame_copy_meta(const us_frame_s *src, us_frame_s *dest) {
US_FRAME_COPY_META(src, dest);
}

#define US_FRAME_COMPARE_META_USED_NOTS(x_a, x_b) ( \
#define US_FRAME_COMPARE_GEOMETRY(x_a, x_b) ( \
/* Compare the used size and significant meta (no timings) */ \
x_a->used == x_b->used \
&& x_a->width == x_b->width \
&& x_a->height == x_b->height \
Expand All @@ -83,7 +77,7 @@ static inline void us_frame_copy_meta(const us_frame_s *src, us_frame_s *dest) {

static inline void us_frame_encoding_begin(const us_frame_s *src, us_frame_s *dest, uint format) {
assert(src->used > 0);
us_frame_copy_meta(src, dest);
US_FRAME_COPY_META(src, dest);
dest->encode_begin_ts = us_get_now_monotonic();
dest->format = format;
dest->stride = 0;
Expand All @@ -108,8 +102,5 @@ bool us_frame_compare(const us_frame_s *a, const us_frame_s *b);

uint us_frame_get_padding(const us_frame_s *frame);

bool us_is_jpeg(uint format);
const char *us_fourcc_to_string(uint format, char *buf, uz size);

static inline bool us_is_jpeg(uint format) {
return (format == V4L2_PIX_FMT_JPEG || format == V4L2_PIX_FMT_MJPEG);
}
2 changes: 1 addition & 1 deletion src/libs/memsink.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ bool us_memsink_server_check(us_memsink_s *sink, const us_frame_s *frame) {
US_LOG_PERROR("%s-sink: Can't unlock memory", sink->name);
return false;
}
return (has_clients || !US_FRAME_COMPARE_META_USED_NOTS(sink->mem, frame));;
return (has_clients || !US_FRAME_COMPARE_GEOMETRY(sink->mem, frame));;
}

int us_memsink_server_put(us_memsink_s *sink, const us_frame_s *frame, bool *key_requested) {
Expand Down
2 changes: 1 addition & 1 deletion src/libs/unjpeg.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ int us_unjpeg(const us_frame_s *src, us_frame_s *dest, bool decode) {

jpeg_start_decompress(&jpeg);

us_frame_copy_meta(src, dest);
US_FRAME_COPY_META(src, dest);
dest->format = V4L2_PIX_FMT_RGB24;
dest->width = jpeg.output_width;
dest->height = jpeg.output_height;
Expand Down
2 changes: 2 additions & 0 deletions src/v4p/drm.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#include <sys/stat.h>
#include <sys/sysmacros.h>

#include <linux/videodev2.h>

#include <xf86drm.h>
#include <xf86drmMode.h>
#include <drm_fourcc.h>
Expand Down

0 comments on commit 3e5a444

Please sign in to comment.