diff --git a/src/libs/tools.h b/src/libs/tools.h index df01b6b..87a9902 100644 --- a/src/libs/tools.h +++ b/src/libs/tools.h @@ -66,6 +66,18 @@ #define US_SNPRINTF(x_dest, x_size, x_fmt, ...) assert(snprintf((x_dest), (x_size), (x_fmt), ##__VA_ARGS__) > 0) #define US_ASPRINTF(x_dest, x_fmt, ...) assert(asprintf(&(x_dest), (x_fmt), ##__VA_ARGS__) > 0) +#define US_MIN(x_a, x_b) ({ \ + __typeof__(x_a) m_a = (x_a); \ + __typeof__(x_b) m_b = (x_b); \ + (m_a < m_b ? m_a : m_b); \ + }) + +#define US_MAX(x_a, x_b) ({ \ + __typeof__(x_a) m_a = (x_a); \ + __typeof__(x_b) m_b = (x_b); \ + (m_a > m_b ? m_a : m_b); \ + }) + INLINE char *us_strdup(const char *str) { char *const new = strdup(str); @@ -81,14 +93,6 @@ INLINE size_t us_align_size(size_t size, size_t to) { return ((size + (to - 1)) & ~(to - 1)); } -INLINE unsigned us_min_u(unsigned a, unsigned b) { - return (a < b ? a : b); -} - -INLINE unsigned us_max_u(unsigned a, unsigned b) { - return (a > b ? a : b); -} - INLINE long long us_floor_ms(long double now) { return (long long)now - (now < (long long)now); // floor() } @@ -145,7 +149,7 @@ INLINE long double us_get_now_real(void) { INLINE unsigned us_get_cores_available(void) { long cores_sysconf = sysconf(_SC_NPROCESSORS_ONLN); cores_sysconf = (cores_sysconf < 0 ? 0 : cores_sysconf); - return us_max_u(us_min_u(cores_sysconf, 4), 1); + return US_MAX(US_MIN(cores_sysconf, 4), 1); } INLINE void us_ld_to_timespec(long double ld, struct timespec *ts) { diff --git a/src/ustreamer/encoder.c b/src/ustreamer/encoder.c index 8b72c7c..b0f943b 100644 --- a/src/ustreamer/encoder.c +++ b/src/ustreamer/encoder.c @@ -96,7 +96,7 @@ us_workers_pool_s *us_encoder_workers_pool_init(us_encoder_s *enc, us_device_s * us_encoder_type_e type = (_ER(cpu_forced) ? US_ENCODER_TYPE_CPU : enc->type); unsigned quality = dev->jpeg_quality; - unsigned n_workers = us_min_u(enc->n_workers, DR(n_bufs)); + unsigned n_workers = US_MIN(enc->n_workers, DR(n_bufs)); bool cpu_forced = false; if (us_is_jpeg(DR(format)) && type != US_ENCODER_TYPE_HW) { diff --git a/src/v4p/drm.c b/src/v4p/drm.c index 6cb58c7..f9915b6 100644 --- a/src/v4p/drm.c +++ b/src/v4p/drm.c @@ -210,7 +210,7 @@ static int _drm_expose_raw(us_drm_s *drm, const us_frame_s *frame) { if (frame == NULL) { memset(buf->data, 0, buf->allocated); } else { - memcpy(buf->data, frame->data, us_min_u(frame->used, buf->allocated)); + memcpy(buf->data, frame->data, US_MIN(frame->used, buf->allocated)); } const int retval = drmModePageFlip( diff --git a/src/v4p/ftext.c b/src/v4p/ftext.c index ba29a05..e1bc4ab 100644 --- a/src/v4p/ftext.c +++ b/src/v4p/ftext.c @@ -85,7 +85,7 @@ void us_ftext_draw(us_ftext_s *ft, const char *text, uint width, uint height) { uint block_width = 0; uint block_height = 0; while ((line = strtok_r((block_height == 0 ? str : NULL), "\n", &rest)) != NULL) { - block_width = us_max_u(strlen(line) * 8, block_width); + block_width = US_MAX(strlen(line) * 8, block_width); block_height += 8; } if (block_width == 0 || block_height == 0) { @@ -139,7 +139,7 @@ void _ftext_draw_line( break; } - const u8 ch = us_min_u(line[ch_x / 8 / scale_x], sizeof(US_FTEXT_FONT) / 8 - 1); + const u8 ch = US_MIN((u8)line[ch_x / 8 / scale_x], sizeof(US_FTEXT_FONT) / 8 - 1); const uint ch_byte = (ch_y / scale_y) % 8; const uint ch_bit = (ch_x / scale_x) % 8; const bool pix_on = !!(US_FTEXT_FONT[ch][ch_byte] & (1 << ch_bit));