mirror of
https://github.com/pikvm/ustreamer.git
synced 2025-12-23 18:50:00 +00:00
renamed us_hw_buffer_s to us_capture_hwbuf_s
This commit is contained in:
parent
f0f5fcd67f
commit
8d4e9a6ca0
@ -266,11 +266,11 @@ void us_capture_close(us_capture_s *cap) {
|
||||
run->streamon = false;
|
||||
}
|
||||
|
||||
if (run->hw_bufs != NULL) {
|
||||
if (run->bufs != NULL) {
|
||||
say = true;
|
||||
_D_LOG_DEBUG("Releasing HW buffers ...");
|
||||
for (uint index = 0; index < run->n_bufs; ++index) {
|
||||
us_hw_buffer_s *hw = &run->hw_bufs[index];
|
||||
us_capture_hwbuf_s *hw = &run->bufs[index];
|
||||
|
||||
US_CLOSE_FD(hw->dma_fd);
|
||||
|
||||
@ -288,7 +288,7 @@ void us_capture_close(us_capture_s *cap) {
|
||||
free(hw->buf.m.planes);
|
||||
}
|
||||
}
|
||||
US_DELETE(run->hw_bufs, free);
|
||||
US_DELETE(run->bufs, free);
|
||||
run->n_bufs = 0;
|
||||
}
|
||||
|
||||
@ -299,7 +299,7 @@ void us_capture_close(us_capture_s *cap) {
|
||||
}
|
||||
}
|
||||
|
||||
int us_capture_grab_buffer(us_capture_s *cap, us_hw_buffer_s **hw) {
|
||||
int us_capture_grab_buffer(us_capture_s *cap, us_capture_hwbuf_s **hw) {
|
||||
// Это сложная функция, которая делает сразу много всего, чтобы получить новый фрейм.
|
||||
// - Вызывается _capture_wait_buffer() с select() внутри, чтобы подождать новый фрейм
|
||||
// или эвент V4L2. Обработка эвентов более приоритетна, чем кадров.
|
||||
@ -347,8 +347,8 @@ int us_capture_grab_buffer(us_capture_s *cap, us_hw_buffer_s **hw) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
# define GRABBED(x_buf) run->hw_bufs[x_buf.index].grabbed
|
||||
# define FRAME_DATA(x_buf) run->hw_bufs[x_buf.index].raw.data
|
||||
# define GRABBED(x_buf) run->bufs[x_buf.index].grabbed
|
||||
# define FRAME_DATA(x_buf) run->bufs[x_buf.index].raw.data
|
||||
|
||||
if (GRABBED(new)) {
|
||||
_D_LOG_ERROR("V4L2 error: grabbed HW buffer=%u is already used", new.index);
|
||||
@ -400,7 +400,7 @@ int us_capture_grab_buffer(us_capture_s *cap, us_hw_buffer_s **hw) {
|
||||
}
|
||||
} while (true);
|
||||
|
||||
*hw = &run->hw_bufs[buf.index];
|
||||
*hw = &run->bufs[buf.index];
|
||||
atomic_store(&(*hw)->refs, 0);
|
||||
(*hw)->raw.dma_fd = (*hw)->dma_fd;
|
||||
(*hw)->raw.used = buf.bytesused;
|
||||
@ -417,7 +417,7 @@ int us_capture_grab_buffer(us_capture_s *cap, us_hw_buffer_s **hw) {
|
||||
return buf.index;
|
||||
}
|
||||
|
||||
int us_capture_release_buffer(us_capture_s *cap, us_hw_buffer_s *hw) {
|
||||
int us_capture_release_buffer(us_capture_s *cap, us_capture_hwbuf_s *hw) {
|
||||
assert(atomic_load(&hw->refs) == 0);
|
||||
const uint index = hw->buf.index;
|
||||
_D_LOG_DEBUG("Releasing HW buffer=%u ...", index);
|
||||
@ -430,11 +430,11 @@ int us_capture_release_buffer(us_capture_s *cap, us_hw_buffer_s *hw) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void us_capture_buffer_incref(us_hw_buffer_s *hw) {
|
||||
void us_capture_buffer_incref(us_capture_hwbuf_s *hw) {
|
||||
atomic_fetch_add(&hw->refs, 1);
|
||||
}
|
||||
|
||||
void us_capture_buffer_decref(us_hw_buffer_s *hw) {
|
||||
void us_capture_buffer_decref(us_capture_hwbuf_s *hw) {
|
||||
atomic_fetch_sub(&hw->refs, 1);
|
||||
}
|
||||
|
||||
@ -862,7 +862,7 @@ static int _capture_open_io_method_mmap(us_capture_s *cap) {
|
||||
|
||||
_D_LOG_DEBUG("Allocating device buffers ...");
|
||||
|
||||
US_CALLOC(run->hw_bufs, req.count);
|
||||
US_CALLOC(run->bufs, req.count);
|
||||
|
||||
for (run->n_bufs = 0; run->n_bufs < req.count; ++run->n_bufs) {
|
||||
struct v4l2_buffer buf = {0};
|
||||
@ -881,7 +881,7 @@ static int _capture_open_io_method_mmap(us_capture_s *cap) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
us_hw_buffer_s *hw = &run->hw_bufs[run->n_bufs];
|
||||
us_capture_hwbuf_s *hw = &run->bufs[run->n_bufs];
|
||||
atomic_init(&hw->refs, 0);
|
||||
const uz buf_size = (run->capture_mplane ? buf.m.planes[0].length : buf.length);
|
||||
const off_t buf_offset = (run->capture_mplane ? buf.m.planes[0].m.mem_offset : buf.m.offset);
|
||||
@ -930,13 +930,13 @@ static int _capture_open_io_method_userptr(us_capture_s *cap) {
|
||||
|
||||
_D_LOG_DEBUG("Allocating device buffers ...");
|
||||
|
||||
US_CALLOC(run->hw_bufs, req.count);
|
||||
US_CALLOC(run->bufs, req.count);
|
||||
|
||||
const uint page_size = getpagesize();
|
||||
const uint buf_size = us_align_size(run->raw_size, page_size);
|
||||
|
||||
for (run->n_bufs = 0; run->n_bufs < req.count; ++run->n_bufs) {
|
||||
us_hw_buffer_s *hw = &run->hw_bufs[run->n_bufs];
|
||||
us_capture_hwbuf_s *hw = &run->bufs[run->n_bufs];
|
||||
assert((hw->raw.data = aligned_alloc(page_size, buf_size)) != NULL);
|
||||
memset(hw->raw.data, 0, buf_size);
|
||||
hw->raw.allocated = buf_size;
|
||||
@ -964,8 +964,8 @@ static int _capture_open_queue_buffers(us_capture_s *cap) {
|
||||
if (cap->io_method == V4L2_MEMORY_USERPTR) {
|
||||
// I am not sure, may be this is incorrect for mplane device,
|
||||
// but i don't have one which supports V4L2_MEMORY_USERPTR
|
||||
buf.m.userptr = (unsigned long)run->hw_bufs[index].raw.data;
|
||||
buf.length = run->hw_bufs[index].raw.allocated;
|
||||
buf.m.userptr = (unsigned long)run->bufs[index].raw.data;
|
||||
buf.length = run->bufs[index].raw.allocated;
|
||||
}
|
||||
|
||||
_D_LOG_DEBUG("Calling us_xioctl(VIDIOC_QBUF) for buffer=%u ...", index);
|
||||
@ -990,13 +990,13 @@ static int _capture_open_export_to_dma(us_capture_s *cap) {
|
||||
_D_LOG_PERROR("Can't export device buffer=%u to DMA", index);
|
||||
goto error;
|
||||
}
|
||||
run->hw_bufs[index].dma_fd = exp.fd;
|
||||
run->bufs[index].dma_fd = exp.fd;
|
||||
}
|
||||
return 0;
|
||||
|
||||
error:
|
||||
for (uint index = 0; index < run->n_bufs; ++index) {
|
||||
US_CLOSE_FD(run->hw_bufs[index].dma_fd);
|
||||
US_CLOSE_FD(run->bufs[index].dma_fd);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -49,7 +49,7 @@ typedef struct {
|
||||
int dma_fd;
|
||||
bool grabbed;
|
||||
atomic_int refs;
|
||||
} us_hw_buffer_s;
|
||||
} us_capture_hwbuf_s;
|
||||
|
||||
typedef struct {
|
||||
int fd;
|
||||
@ -62,7 +62,7 @@ typedef struct {
|
||||
uint jpeg_quality;
|
||||
uz raw_size;
|
||||
uint n_bufs;
|
||||
us_hw_buffer_s *hw_bufs;
|
||||
us_capture_hwbuf_s *bufs;
|
||||
bool dma;
|
||||
enum v4l2_buf_type capture_type;
|
||||
bool capture_mplane;
|
||||
@ -130,8 +130,8 @@ int us_capture_parse_io_method(const char *str);
|
||||
int us_capture_open(us_capture_s *cap);
|
||||
void us_capture_close(us_capture_s *cap);
|
||||
|
||||
int us_capture_grab_buffer(us_capture_s *cap, us_hw_buffer_s **hw);
|
||||
int us_capture_release_buffer(us_capture_s *cap, us_hw_buffer_s *hw);
|
||||
int us_capture_grab_buffer(us_capture_s *cap, us_capture_hwbuf_s **hw);
|
||||
int us_capture_release_buffer(us_capture_s *cap, us_capture_hwbuf_s *hw);
|
||||
|
||||
void us_capture_buffer_incref(us_hw_buffer_s *hw);
|
||||
void us_capture_buffer_decref(us_hw_buffer_s *hw);
|
||||
void us_capture_buffer_incref(us_capture_hwbuf_s *hw);
|
||||
void us_capture_buffer_decref(us_capture_hwbuf_s *hw);
|
||||
|
||||
@ -75,9 +75,9 @@ typedef struct {
|
||||
} us_encoder_s;
|
||||
|
||||
typedef struct {
|
||||
us_encoder_s *enc;
|
||||
us_hw_buffer_s *hw;
|
||||
us_frame_s *dest;
|
||||
us_encoder_s *enc;
|
||||
us_capture_hwbuf_s *hw;
|
||||
us_frame_s *dest;
|
||||
} us_encoder_job_s;
|
||||
|
||||
|
||||
|
||||
@ -72,7 +72,7 @@ static void *_jpeg_thread(void *v_ctx);
|
||||
static void *_h264_thread(void *v_ctx);
|
||||
static void *_raw_thread(void *v_ctx);
|
||||
|
||||
static us_hw_buffer_s *_get_latest_hw(us_queue_s *queue);
|
||||
static us_capture_hwbuf_s *_get_latest_hw(us_queue_s *queue);
|
||||
|
||||
static bool _stream_has_jpeg_clients_cached(us_stream_s *stream);
|
||||
static bool _stream_has_any_clients_cached(us_stream_s *stream);
|
||||
@ -176,7 +176,7 @@ void us_stream_loop(us_stream_s *stream) {
|
||||
|
||||
uint slowdown_count = 0;
|
||||
while (!atomic_load(&run->stop) && !atomic_load(&threads_stop)) {
|
||||
us_hw_buffer_s *hw;
|
||||
us_capture_hwbuf_s *hw;
|
||||
switch (us_capture_grab_buffer(cap, &hw)) {
|
||||
case -2: continue; // Broken frame
|
||||
case -1: goto close; // Error
|
||||
@ -283,7 +283,7 @@ static void *_releaser_thread(void *v_ctx) {
|
||||
_releaser_context_s *ctx = v_ctx;
|
||||
|
||||
while (!atomic_load(ctx->stop)) {
|
||||
us_hw_buffer_s *hw;
|
||||
us_capture_hwbuf_s *hw;
|
||||
if (us_queue_get(ctx->queue, (void**)&hw, 0.1) < 0) {
|
||||
continue;
|
||||
}
|
||||
@ -337,7 +337,7 @@ static void *_jpeg_thread(void *v_ctx) {
|
||||
}
|
||||
}
|
||||
|
||||
us_hw_buffer_s *hw = _get_latest_hw(ctx->queue);
|
||||
us_capture_hwbuf_s *hw = _get_latest_hw(ctx->queue);
|
||||
if (hw == NULL) {
|
||||
continue;
|
||||
}
|
||||
@ -379,7 +379,7 @@ static void *_h264_thread(void *v_ctx) {
|
||||
ldf last_encode_ts = us_get_now_monotonic();
|
||||
|
||||
while (!atomic_load(ctx->stop)) {
|
||||
us_hw_buffer_s *hw = _get_latest_hw(ctx->queue);
|
||||
us_capture_hwbuf_s *hw = _get_latest_hw(ctx->queue);
|
||||
if (hw == NULL) {
|
||||
continue;
|
||||
}
|
||||
@ -419,7 +419,7 @@ static void *_raw_thread(void *v_ctx) {
|
||||
_worker_context_s *ctx = v_ctx;
|
||||
|
||||
while (!atomic_load(ctx->stop)) {
|
||||
us_hw_buffer_s *hw = _get_latest_hw(ctx->queue);
|
||||
us_capture_hwbuf_s *hw = _get_latest_hw(ctx->queue);
|
||||
if (hw == NULL) {
|
||||
continue;
|
||||
}
|
||||
@ -436,8 +436,8 @@ static void *_raw_thread(void *v_ctx) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static us_hw_buffer_s *_get_latest_hw(us_queue_s *queue) {
|
||||
us_hw_buffer_s *hw;
|
||||
static us_capture_hwbuf_s *_get_latest_hw(us_queue_s *queue) {
|
||||
us_capture_hwbuf_s *hw;
|
||||
if (us_queue_get(queue, (void**)&hw, 0.1) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -377,7 +377,7 @@ int us_drm_expose_stub(us_drm_s *drm, us_drm_stub_e stub, const us_capture_s *ca
|
||||
return retval;
|
||||
}
|
||||
|
||||
int us_drm_expose_dma(us_drm_s *drm, const us_hw_buffer_s *hw) {
|
||||
int us_drm_expose_dma(us_drm_s *drm, const us_capture_hwbuf_s *hw) {
|
||||
us_drm_runtime_s *const run = drm->run;
|
||||
us_drm_buffer_s *const buf = &run->bufs[hw->buf.index];
|
||||
|
||||
@ -513,7 +513,7 @@ static int _drm_init_buffers(us_drm_s *drm, const us_capture_s *cap) {
|
||||
strides[0] = create.pitch;
|
||||
|
||||
} else {
|
||||
if (drmPrimeFDToHandle(run->fd, cap->run->hw_bufs[n_buf].dma_fd, &buf->handle) < 0) {
|
||||
if (drmPrimeFDToHandle(run->fd, cap->run->bufs[n_buf].dma_fd, &buf->handle) < 0) {
|
||||
_D_LOG_PERROR("Can't import DMA buffer=%u from capture device", n_buf);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -89,4 +89,4 @@ void us_drm_close(us_drm_s *drm);
|
||||
int us_drm_dpms_power_off(us_drm_s *drm);
|
||||
int us_drm_wait_for_vsync(us_drm_s *drm);
|
||||
int us_drm_expose_stub(us_drm_s *drm, us_drm_stub_e stub, const us_capture_s *cap);
|
||||
int us_drm_expose_dma(us_drm_s *drm, const us_hw_buffer_s *hw);
|
||||
int us_drm_expose_dma(us_drm_s *drm, const us_capture_hwbuf_s *hw);
|
||||
|
||||
@ -213,7 +213,7 @@ static void _main_loop(void) {
|
||||
us_drm_close(drm);
|
||||
CHECK(drm_opened = us_drm_open(drm, cap));
|
||||
|
||||
us_hw_buffer_s *prev_hw = NULL;
|
||||
us_capture_hwbuf_s *prev_hw = NULL;
|
||||
while (!atomic_load(&_g_stop)) {
|
||||
if (atomic_load(&_g_ustreamer_online)) {
|
||||
goto close;
|
||||
@ -226,7 +226,7 @@ static void _main_loop(void) {
|
||||
prev_hw = NULL;
|
||||
}
|
||||
|
||||
us_hw_buffer_s *hw;
|
||||
us_capture_hwbuf_s *hw;
|
||||
switch (us_capture_grab_buffer(cap, &hw)) {
|
||||
case -2: continue; // Broken frame
|
||||
case -1: goto close; // Any error
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user