mirror of
https://github.com/pikvm/ustreamer.git
synced 2026-03-12 02:23:43 +00:00
refactoring
This commit is contained in:
@@ -110,6 +110,7 @@ unsigned frame_get_padding(const frame_s *frame) {
|
|||||||
case V4L2_PIX_FMT_UYVY:
|
case V4L2_PIX_FMT_UYVY:
|
||||||
case V4L2_PIX_FMT_RGB565: bytes_per_pixel = 2; break;
|
case V4L2_PIX_FMT_RGB565: bytes_per_pixel = 2; break;
|
||||||
case V4L2_PIX_FMT_RGB24: bytes_per_pixel = 3; break;
|
case V4L2_PIX_FMT_RGB24: bytes_per_pixel = 3; break;
|
||||||
|
// case V4L2_PIX_FMT_H264:
|
||||||
case V4L2_PIX_FMT_MJPEG:
|
case V4L2_PIX_FMT_MJPEG:
|
||||||
case V4L2_PIX_FMT_JPEG: bytes_per_pixel = 0; break;
|
case V4L2_PIX_FMT_JPEG: bytes_per_pixel = 0; break;
|
||||||
default: assert(0 && "Unknown pixelformat");
|
default: assert(0 && "Unknown pixelformat");
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ device_s *device_init(void) {
|
|||||||
dev->jpeg_quality = 80;
|
dev->jpeg_quality = 80;
|
||||||
dev->standard = V4L2_STD_UNKNOWN;
|
dev->standard = V4L2_STD_UNKNOWN;
|
||||||
dev->io_method = V4L2_MEMORY_MMAP;
|
dev->io_method = V4L2_MEMORY_MMAP;
|
||||||
dev->n_buffers = get_cores_available() + 1;
|
dev->n_bufs = get_cores_available() + 1;
|
||||||
dev->min_frame_size = 128;
|
dev->min_frame_size = 128;
|
||||||
dev->timeout = 1;
|
dev->timeout = 1;
|
||||||
dev->run = run;
|
dev->run = run;
|
||||||
@@ -173,10 +173,10 @@ int device_open(device_s *dev) {
|
|||||||
void device_close(device_s *dev) {
|
void device_close(device_s *dev) {
|
||||||
RUN(persistent_timeout_reported) = false;
|
RUN(persistent_timeout_reported) = false;
|
||||||
|
|
||||||
if (RUN(hw_buffers)) {
|
if (RUN(hw_bufs)) {
|
||||||
LOG_DEBUG("Releasing device buffers ...");
|
LOG_DEBUG("Releasing device buffers ...");
|
||||||
for (unsigned index = 0; index < RUN(n_buffers); ++index) {
|
for (unsigned index = 0; index < RUN(n_bufs); ++index) {
|
||||||
# define HW(_next) RUN(hw_buffers)[index]._next
|
# define HW(_next) RUN(hw_bufs)[index]._next
|
||||||
|
|
||||||
if (dev->io_method == V4L2_MEMORY_MMAP) {
|
if (dev->io_method == V4L2_MEMORY_MMAP) {
|
||||||
if (HW(raw.allocated) > 0 && HW(raw.data) != MAP_FAILED) {
|
if (HW(raw.allocated) > 0 && HW(raw.data) != MAP_FAILED) {
|
||||||
@@ -193,9 +193,9 @@ void device_close(device_s *dev) {
|
|||||||
|
|
||||||
# undef HW
|
# undef HW
|
||||||
}
|
}
|
||||||
RUN(n_buffers) = 0;
|
RUN(n_bufs) = 0;
|
||||||
free(RUN(hw_buffers));
|
free(RUN(hw_bufs));
|
||||||
RUN(hw_buffers) = NULL;
|
RUN(hw_bufs) = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (RUN(fd) >= 0) {
|
if (RUN(fd) >= 0) {
|
||||||
@@ -290,9 +290,9 @@ int device_grab_buffer(device_s *dev, hw_buffer_s **hw) {
|
|||||||
LOG_DEBUG("Grabbed new frame in device buffer: index=%u, bytesused=%u",
|
LOG_DEBUG("Grabbed new frame in device buffer: index=%u, bytesused=%u",
|
||||||
buf_info.index, buf_info.bytesused);
|
buf_info.index, buf_info.bytesused);
|
||||||
|
|
||||||
if (buf_info.index >= RUN(n_buffers)) {
|
if (buf_info.index >= RUN(n_bufs)) {
|
||||||
LOG_ERROR("V4L2 error: grabbed invalid device buffer: index=%u, nbuffers=%u",
|
LOG_ERROR("V4L2 error: grabbed invalid device buffer: index=%u, n_bufs=%u",
|
||||||
buf_info.index, RUN(n_buffers));
|
buf_info.index, RUN(n_bufs));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -311,7 +311,7 @@ int device_grab_buffer(device_s *dev, hw_buffer_s **hw) {
|
|||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
# define HW(_next) RUN(hw_buffers)[buf_info.index]._next
|
# define HW(_next) RUN(hw_bufs)[buf_info.index]._next
|
||||||
|
|
||||||
A_MUTEX_LOCK(&HW(grabbed_mutex));
|
A_MUTEX_LOCK(&HW(grabbed_mutex));
|
||||||
if (HW(grabbed)) {
|
if (HW(grabbed)) {
|
||||||
@@ -333,7 +333,7 @@ int device_grab_buffer(device_s *dev, hw_buffer_s **hw) {
|
|||||||
HW(raw.grab_ts) = get_now_monotonic();
|
HW(raw.grab_ts) = get_now_monotonic();
|
||||||
|
|
||||||
# undef HW
|
# undef HW
|
||||||
*hw = &RUN(hw_buffers[buf_info.index]);
|
*hw = &RUN(hw_bufs[buf_info.index]);
|
||||||
return buf_info.index;
|
return buf_info.index;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -613,7 +613,7 @@ static int _device_open_io_method(device_s *dev) {
|
|||||||
static int _device_open_io_method_mmap(device_s *dev) {
|
static int _device_open_io_method_mmap(device_s *dev) {
|
||||||
struct v4l2_requestbuffers req;
|
struct v4l2_requestbuffers req;
|
||||||
MEMSET_ZERO(req);
|
MEMSET_ZERO(req);
|
||||||
req.count = dev->n_buffers;
|
req.count = dev->n_bufs;
|
||||||
req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
||||||
req.memory = V4L2_MEMORY_MMAP;
|
req.memory = V4L2_MEMORY_MMAP;
|
||||||
|
|
||||||
@@ -627,30 +627,30 @@ static int _device_open_io_method_mmap(device_s *dev) {
|
|||||||
LOG_ERROR("Insufficient buffer memory: %u", req.count);
|
LOG_ERROR("Insufficient buffer memory: %u", req.count);
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
LOG_INFO("Requested %u device buffers, got %u", dev->n_buffers, req.count);
|
LOG_INFO("Requested %u device buffers, got %u", dev->n_bufs, req.count);
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_DEBUG("Allocating device buffers ...");
|
LOG_DEBUG("Allocating device buffers ...");
|
||||||
|
|
||||||
A_CALLOC(RUN(hw_buffers), req.count);
|
A_CALLOC(RUN(hw_bufs), req.count);
|
||||||
for (RUN(n_buffers) = 0; RUN(n_buffers) < req.count; ++RUN(n_buffers)) {
|
for (RUN(n_bufs) = 0; RUN(n_bufs) < req.count; ++RUN(n_bufs)) {
|
||||||
struct v4l2_buffer buf_info;
|
struct v4l2_buffer buf_info;
|
||||||
MEMSET_ZERO(buf_info);
|
MEMSET_ZERO(buf_info);
|
||||||
buf_info.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
buf_info.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
||||||
buf_info.memory = V4L2_MEMORY_MMAP;
|
buf_info.memory = V4L2_MEMORY_MMAP;
|
||||||
buf_info.index = RUN(n_buffers);
|
buf_info.index = RUN(n_bufs);
|
||||||
|
|
||||||
LOG_DEBUG("Calling ioctl(VIDIOC_QUERYBUF) for device buffer %u ...", RUN(n_buffers));
|
LOG_DEBUG("Calling ioctl(VIDIOC_QUERYBUF) for device buffer %u ...", RUN(n_bufs));
|
||||||
if (xioctl(RUN(fd), VIDIOC_QUERYBUF, &buf_info) < 0) {
|
if (xioctl(RUN(fd), VIDIOC_QUERYBUF, &buf_info) < 0) {
|
||||||
LOG_PERROR("Can't VIDIOC_QUERYBUF");
|
LOG_PERROR("Can't VIDIOC_QUERYBUF");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
# define HW(_next) RUN(hw_buffers)[RUN(n_buffers)]._next
|
# define HW(_next) RUN(hw_bufs)[RUN(n_bufs)]._next
|
||||||
|
|
||||||
A_MUTEX_INIT(&HW(grabbed_mutex));
|
A_MUTEX_INIT(&HW(grabbed_mutex));
|
||||||
|
|
||||||
LOG_DEBUG("Mapping device buffer %u ...", RUN(n_buffers));
|
LOG_DEBUG("Mapping device buffer %u ...", RUN(n_bufs));
|
||||||
if ((HW(raw.data) = mmap(
|
if ((HW(raw.data) = mmap(
|
||||||
NULL,
|
NULL,
|
||||||
buf_info.length,
|
buf_info.length,
|
||||||
@@ -659,7 +659,7 @@ static int _device_open_io_method_mmap(device_s *dev) {
|
|||||||
RUN(fd),
|
RUN(fd),
|
||||||
buf_info.m.offset
|
buf_info.m.offset
|
||||||
)) == MAP_FAILED) {
|
)) == MAP_FAILED) {
|
||||||
LOG_PERROR("Can't map device buffer %u", RUN(n_buffers));
|
LOG_PERROR("Can't map device buffer %u", RUN(n_bufs));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
HW(raw.allocated) = buf_info.length;
|
HW(raw.allocated) = buf_info.length;
|
||||||
@@ -672,7 +672,7 @@ static int _device_open_io_method_mmap(device_s *dev) {
|
|||||||
static int _device_open_io_method_userptr(device_s *dev) {
|
static int _device_open_io_method_userptr(device_s *dev) {
|
||||||
struct v4l2_requestbuffers req;
|
struct v4l2_requestbuffers req;
|
||||||
MEMSET_ZERO(req);
|
MEMSET_ZERO(req);
|
||||||
req.count = dev->n_buffers;
|
req.count = dev->n_bufs;
|
||||||
req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
||||||
req.memory = V4L2_MEMORY_USERPTR;
|
req.memory = V4L2_MEMORY_USERPTR;
|
||||||
|
|
||||||
@@ -686,18 +686,18 @@ static int _device_open_io_method_userptr(device_s *dev) {
|
|||||||
LOG_ERROR("Insufficient buffer memory: %u", req.count);
|
LOG_ERROR("Insufficient buffer memory: %u", req.count);
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
LOG_INFO("Requested %u device buffers, got %u", dev->n_buffers, req.count);
|
LOG_INFO("Requested %u device buffers, got %u", dev->n_bufs, req.count);
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_DEBUG("Allocating device buffers ...");
|
LOG_DEBUG("Allocating device buffers ...");
|
||||||
|
|
||||||
A_CALLOC(RUN(hw_buffers), req.count);
|
A_CALLOC(RUN(hw_bufs), req.count);
|
||||||
|
|
||||||
const unsigned page_size = getpagesize();
|
const unsigned page_size = getpagesize();
|
||||||
const unsigned buf_size = align_size(RUN(raw_size), page_size);
|
const unsigned buf_size = align_size(RUN(raw_size), page_size);
|
||||||
|
|
||||||
for (RUN(n_buffers) = 0; RUN(n_buffers) < req.count; ++RUN(n_buffers)) {
|
for (RUN(n_bufs) = 0; RUN(n_bufs) < req.count; ++RUN(n_bufs)) {
|
||||||
# define HW(_next) RUN(hw_buffers)[RUN(n_buffers)]._next
|
# define HW(_next) RUN(hw_bufs)[RUN(n_bufs)]._next
|
||||||
assert(HW(raw.data) = aligned_alloc(page_size, buf_size));
|
assert(HW(raw.data) = aligned_alloc(page_size, buf_size));
|
||||||
memset(HW(raw.data), 0, buf_size);
|
memset(HW(raw.data), 0, buf_size);
|
||||||
HW(raw.allocated) = buf_size;
|
HW(raw.allocated) = buf_size;
|
||||||
@@ -707,15 +707,15 @@ static int _device_open_io_method_userptr(device_s *dev) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int _device_open_queue_buffers(device_s *dev) {
|
static int _device_open_queue_buffers(device_s *dev) {
|
||||||
for (unsigned index = 0; index < RUN(n_buffers); ++index) {
|
for (unsigned index = 0; index < RUN(n_bufs); ++index) {
|
||||||
struct v4l2_buffer buf_info;
|
struct v4l2_buffer buf_info;
|
||||||
MEMSET_ZERO(buf_info);
|
MEMSET_ZERO(buf_info);
|
||||||
buf_info.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
buf_info.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
||||||
buf_info.memory = dev->io_method;
|
buf_info.memory = dev->io_method;
|
||||||
buf_info.index = index;
|
buf_info.index = index;
|
||||||
if (dev->io_method == V4L2_MEMORY_USERPTR) {
|
if (dev->io_method == V4L2_MEMORY_USERPTR) {
|
||||||
buf_info.m.userptr = (unsigned long)RUN(hw_buffers)[index].raw.data;
|
buf_info.m.userptr = (unsigned long)RUN(hw_bufs)[index].raw.data;
|
||||||
buf_info.length = RUN(hw_buffers)[index].raw.allocated;
|
buf_info.length = RUN(hw_bufs)[index].raw.allocated;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_DEBUG("Calling ioctl(VIDIOC_QBUF) for buffer %u ...", index);
|
LOG_DEBUG("Calling ioctl(VIDIOC_QBUF) for buffer %u ...", index);
|
||||||
|
|||||||
@@ -85,8 +85,8 @@ typedef struct {
|
|||||||
unsigned hw_fps;
|
unsigned hw_fps;
|
||||||
unsigned jpeg_quality;
|
unsigned jpeg_quality;
|
||||||
size_t raw_size;
|
size_t raw_size;
|
||||||
unsigned n_buffers;
|
unsigned n_bufs;
|
||||||
hw_buffer_s *hw_buffers;
|
hw_buffer_s *hw_bufs;
|
||||||
bool capturing;
|
bool capturing;
|
||||||
bool persistent_timeout_reported;
|
bool persistent_timeout_reported;
|
||||||
} device_runtime_s;
|
} device_runtime_s;
|
||||||
@@ -128,7 +128,7 @@ typedef struct {
|
|||||||
v4l2_std_id standard;
|
v4l2_std_id standard;
|
||||||
enum v4l2_memory io_method;
|
enum v4l2_memory io_method;
|
||||||
bool dv_timings;
|
bool dv_timings;
|
||||||
unsigned n_buffers;
|
unsigned n_bufs;
|
||||||
unsigned desired_fps;
|
unsigned desired_fps;
|
||||||
size_t min_frame_size;
|
size_t min_frame_size;
|
||||||
bool persistent;
|
bool persistent;
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ void encoder_prepare(encoder_s *enc, device_s *dev) {
|
|||||||
unsigned quality = dev->jpeg_quality;
|
unsigned quality = dev->jpeg_quality;
|
||||||
bool cpu_forced = false;
|
bool cpu_forced = false;
|
||||||
|
|
||||||
ER(n_workers) = min_u(enc->n_workers, DR(n_buffers));
|
ER(n_workers) = min_u(enc->n_workers, DR(n_bufs));
|
||||||
|
|
||||||
if (is_jpeg(DR(format)) && type != ENCODER_TYPE_HW) {
|
if (is_jpeg(DR(format)) && type != ENCODER_TYPE_HW) {
|
||||||
LOG_INFO("Switching to HW encoder: the input is (M)JPEG ...");
|
LOG_INFO("Switching to HW encoder: the input is (M)JPEG ...");
|
||||||
|
|||||||
@@ -30,7 +30,7 @@
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
struct jpeg_destination_mgr mgr; // Default manager
|
struct jpeg_destination_mgr mgr; // Default manager
|
||||||
JOCTET *buffer; // Start of buffer
|
JOCTET *buf; // Start of buffer
|
||||||
frame_s *frame;
|
frame_s *frame;
|
||||||
} _jpeg_dest_manager_s;
|
} _jpeg_dest_manager_s;
|
||||||
|
|
||||||
@@ -110,15 +110,15 @@ static void _jpeg_set_dest_frame(j_compress_ptr jpeg, frame_s *frame) {
|
|||||||
#define NORM_COMPONENT(_x) (((_x) > 255) ? 255 : (((_x) < 0) ? 0 : (_x)))
|
#define NORM_COMPONENT(_x) (((_x) > 255) ? 255 : (((_x) < 0) ? 0 : (_x)))
|
||||||
|
|
||||||
static void _jpeg_write_scanlines_yuyv(struct jpeg_compress_struct *jpeg, const frame_s *frame) {
|
static void _jpeg_write_scanlines_yuyv(struct jpeg_compress_struct *jpeg, const frame_s *frame) {
|
||||||
uint8_t *line_buffer;
|
uint8_t *line_buf;
|
||||||
A_CALLOC(line_buffer, frame->width * 3);
|
A_CALLOC(line_buf, frame->width * 3);
|
||||||
|
|
||||||
const unsigned padding = frame_get_padding(frame);
|
const unsigned padding = frame_get_padding(frame);
|
||||||
const uint8_t *data = frame->data;
|
const uint8_t *data = frame->data;
|
||||||
unsigned z = 0;
|
unsigned z = 0;
|
||||||
|
|
||||||
while (jpeg->next_scanline < frame->height) {
|
while (jpeg->next_scanline < frame->height) {
|
||||||
uint8_t *ptr = line_buffer;
|
uint8_t *ptr = line_buf;
|
||||||
|
|
||||||
for (unsigned x = 0; x < frame->width; ++x) {
|
for (unsigned x = 0; x < frame->width; ++x) {
|
||||||
int y = (!z ? data[0] << 8 : data[2] << 8);
|
int y = (!z ? data[0] << 8 : data[2] << 8);
|
||||||
@@ -140,23 +140,23 @@ static void _jpeg_write_scanlines_yuyv(struct jpeg_compress_struct *jpeg, const
|
|||||||
}
|
}
|
||||||
data += padding;
|
data += padding;
|
||||||
|
|
||||||
JSAMPROW scanlines[1] = {line_buffer};
|
JSAMPROW scanlines[1] = {line_buf};
|
||||||
jpeg_write_scanlines(jpeg, scanlines, 1);
|
jpeg_write_scanlines(jpeg, scanlines, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(line_buffer);
|
free(line_buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _jpeg_write_scanlines_uyvy(struct jpeg_compress_struct *jpeg, const frame_s *frame) {
|
static void _jpeg_write_scanlines_uyvy(struct jpeg_compress_struct *jpeg, const frame_s *frame) {
|
||||||
uint8_t *line_buffer;
|
uint8_t *line_buf;
|
||||||
A_CALLOC(line_buffer, frame->width * 3);
|
A_CALLOC(line_buf, frame->width * 3);
|
||||||
|
|
||||||
const unsigned padding = frame_get_padding(frame);
|
const unsigned padding = frame_get_padding(frame);
|
||||||
const uint8_t *data = frame->data;
|
const uint8_t *data = frame->data;
|
||||||
unsigned z = 0;
|
unsigned z = 0;
|
||||||
|
|
||||||
while (jpeg->next_scanline < frame->height) {
|
while (jpeg->next_scanline < frame->height) {
|
||||||
uint8_t *ptr = line_buffer;
|
uint8_t *ptr = line_buf;
|
||||||
|
|
||||||
for (unsigned x = 0; x < frame->width; ++x) {
|
for (unsigned x = 0; x < frame->width; ++x) {
|
||||||
int y = (!z ? data[1] << 8 : data[3] << 8);
|
int y = (!z ? data[1] << 8 : data[3] << 8);
|
||||||
@@ -178,11 +178,11 @@ static void _jpeg_write_scanlines_uyvy(struct jpeg_compress_struct *jpeg, const
|
|||||||
}
|
}
|
||||||
data += padding;
|
data += padding;
|
||||||
|
|
||||||
JSAMPROW scanlines[1] = {line_buffer};
|
JSAMPROW scanlines[1] = {line_buf};
|
||||||
jpeg_write_scanlines(jpeg, scanlines, 1);
|
jpeg_write_scanlines(jpeg, scanlines, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(line_buffer);
|
free(line_buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef NORM_COMPONENT
|
#undef NORM_COMPONENT
|
||||||
@@ -191,14 +191,14 @@ static void _jpeg_write_scanlines_uyvy(struct jpeg_compress_struct *jpeg, const
|
|||||||
#undef YUV_R
|
#undef YUV_R
|
||||||
|
|
||||||
static void _jpeg_write_scanlines_rgb565(struct jpeg_compress_struct *jpeg, const frame_s *frame) {
|
static void _jpeg_write_scanlines_rgb565(struct jpeg_compress_struct *jpeg, const frame_s *frame) {
|
||||||
uint8_t *line_buffer;
|
uint8_t *line_buf;
|
||||||
A_CALLOC(line_buffer, frame->width * 3);
|
A_CALLOC(line_buf, frame->width * 3);
|
||||||
|
|
||||||
const unsigned padding = frame_get_padding(frame);
|
const unsigned padding = frame_get_padding(frame);
|
||||||
const uint8_t *data = frame->data;
|
const uint8_t *data = frame->data;
|
||||||
|
|
||||||
while (jpeg->next_scanline < frame->height) {
|
while (jpeg->next_scanline < frame->height) {
|
||||||
uint8_t *ptr = line_buffer;
|
uint8_t *ptr = line_buf;
|
||||||
|
|
||||||
for (unsigned x = 0; x < frame->width; ++x) {
|
for (unsigned x = 0; x < frame->width; ++x) {
|
||||||
unsigned int two_byte = (data[1] << 8) + data[0];
|
unsigned int two_byte = (data[1] << 8) + data[0];
|
||||||
@@ -211,11 +211,11 @@ static void _jpeg_write_scanlines_rgb565(struct jpeg_compress_struct *jpeg, cons
|
|||||||
}
|
}
|
||||||
data += padding;
|
data += padding;
|
||||||
|
|
||||||
JSAMPROW scanlines[1] = {line_buffer};
|
JSAMPROW scanlines[1] = {line_buf};
|
||||||
jpeg_write_scanlines(jpeg, scanlines, 1);
|
jpeg_write_scanlines(jpeg, scanlines, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(line_buffer);
|
free(line_buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _jpeg_write_scanlines_rgb24(struct jpeg_compress_struct *jpeg, const frame_s *frame) {
|
static void _jpeg_write_scanlines_rgb24(struct jpeg_compress_struct *jpeg, const frame_s *frame) {
|
||||||
@@ -236,11 +236,11 @@ static void _jpeg_init_destination(j_compress_ptr jpeg) {
|
|||||||
_jpeg_dest_manager_s *dest = (_jpeg_dest_manager_s *)jpeg->dest;
|
_jpeg_dest_manager_s *dest = (_jpeg_dest_manager_s *)jpeg->dest;
|
||||||
|
|
||||||
// Allocate the output buffer - it will be released when done with image
|
// Allocate the output buffer - it will be released when done with image
|
||||||
assert((dest->buffer = (JOCTET *)(*jpeg->mem->alloc_small)(
|
assert((dest->buf = (JOCTET *)(*jpeg->mem->alloc_small)(
|
||||||
(j_common_ptr) jpeg, JPOOL_IMAGE, JPEG_OUTPUT_BUFFER_SIZE * sizeof(JOCTET)
|
(j_common_ptr) jpeg, JPOOL_IMAGE, JPEG_OUTPUT_BUFFER_SIZE * sizeof(JOCTET)
|
||||||
)));
|
)));
|
||||||
|
|
||||||
dest->mgr.next_output_byte = dest->buffer;
|
dest->mgr.next_output_byte = dest->buf;
|
||||||
dest->mgr.free_in_buffer = JPEG_OUTPUT_BUFFER_SIZE;
|
dest->mgr.free_in_buffer = JPEG_OUTPUT_BUFFER_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -249,9 +249,9 @@ static boolean _jpeg_empty_output_buffer(j_compress_ptr jpeg) {
|
|||||||
|
|
||||||
_jpeg_dest_manager_s *dest = (_jpeg_dest_manager_s *)jpeg->dest;
|
_jpeg_dest_manager_s *dest = (_jpeg_dest_manager_s *)jpeg->dest;
|
||||||
|
|
||||||
frame_append_data(dest->frame, dest->buffer, JPEG_OUTPUT_BUFFER_SIZE);
|
frame_append_data(dest->frame, dest->buf, JPEG_OUTPUT_BUFFER_SIZE);
|
||||||
|
|
||||||
dest->mgr.next_output_byte = dest->buffer;
|
dest->mgr.next_output_byte = dest->buf;
|
||||||
dest->mgr.free_in_buffer = JPEG_OUTPUT_BUFFER_SIZE;
|
dest->mgr.free_in_buffer = JPEG_OUTPUT_BUFFER_SIZE;
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@@ -265,7 +265,7 @@ static void _jpeg_term_destination(j_compress_ptr jpeg) {
|
|||||||
size_t final = JPEG_OUTPUT_BUFFER_SIZE - dest->mgr.free_in_buffer;
|
size_t final = JPEG_OUTPUT_BUFFER_SIZE - dest->mgr.free_in_buffer;
|
||||||
|
|
||||||
// Write any data remaining in the buffer.
|
// Write any data remaining in the buffer.
|
||||||
frame_append_data(dest->frame, dest->buffer, final);
|
frame_append_data(dest->frame, dest->buf, final);
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef JPEG_OUTPUT_BUFFER_SIZE
|
#undef JPEG_OUTPUT_BUFFER_SIZE
|
||||||
|
|||||||
@@ -41,11 +41,11 @@ static OMX_ERRORTYPE _omx_event_handler(
|
|||||||
|
|
||||||
static OMX_ERRORTYPE _omx_input_required_handler(
|
static OMX_ERRORTYPE _omx_input_required_handler(
|
||||||
UNUSED OMX_HANDLETYPE comp,
|
UNUSED OMX_HANDLETYPE comp,
|
||||||
OMX_PTR v_omx, UNUSED OMX_BUFFERHEADERTYPE *buffer);
|
OMX_PTR v_omx, UNUSED OMX_BUFFERHEADERTYPE *buf);
|
||||||
|
|
||||||
static OMX_ERRORTYPE _omx_output_available_handler(
|
static OMX_ERRORTYPE _omx_output_available_handler(
|
||||||
UNUSED OMX_HANDLETYPE comp,
|
UNUSED OMX_HANDLETYPE comp,
|
||||||
OMX_PTR v_omx, UNUSED OMX_BUFFERHEADERTYPE *buffer);
|
OMX_PTR v_omx, UNUSED OMX_BUFFERHEADERTYPE *buf);
|
||||||
|
|
||||||
|
|
||||||
omx_encoder_s *omx_encoder_init(void) {
|
omx_encoder_s *omx_encoder_init(void) {
|
||||||
@@ -131,12 +131,12 @@ int omx_encoder_prepare(omx_encoder_s *omx, const frame_s *frame, unsigned quali
|
|||||||
}
|
}
|
||||||
|
|
||||||
int omx_encoder_compress(omx_encoder_s *omx, const frame_s *src, frame_s *dest) {
|
int omx_encoder_compress(omx_encoder_s *omx, const frame_s *src, frame_s *dest) {
|
||||||
# define IN(_next) omx->input_buffer->_next
|
# define IN(_next) omx->input_buf->_next
|
||||||
# define OUT(_next) omx->output_buffer->_next
|
# define OUT(_next) omx->output_buf->_next
|
||||||
|
|
||||||
OMX_ERRORTYPE error;
|
OMX_ERRORTYPE error;
|
||||||
|
|
||||||
if ((error = OMX_FillThisBuffer(omx->comp, omx->output_buffer)) != OMX_ErrorNone) {
|
if ((error = OMX_FillThisBuffer(omx->comp, omx->output_buf)) != OMX_ErrorNone) {
|
||||||
LOG_ERROR_OMX(error, "Failed to request filling of the output buffer on encoder");
|
LOG_ERROR_OMX(error, "Failed to request filling of the output buffer on encoder");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -165,7 +165,7 @@ int omx_encoder_compress(omx_encoder_s *omx, const frame_s *src, frame_s *dest)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((error = OMX_FillThisBuffer(omx->comp, omx->output_buffer)) != OMX_ErrorNone) {
|
if ((error = OMX_FillThisBuffer(omx->comp, omx->output_buf)) != OMX_ErrorNone) {
|
||||||
LOG_ERROR_OMX(error, "Failed to request filling of the output buffer on encoder");
|
LOG_ERROR_OMX(error, "Failed to request filling of the output buffer on encoder");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -188,7 +188,7 @@ int omx_encoder_compress(omx_encoder_s *omx, const frame_s *src, frame_s *dest)
|
|||||||
slice_size = src->used - pos;
|
slice_size = src->used - pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((error = OMX_EmptyThisBuffer(omx->comp, omx->input_buffer)) != OMX_ErrorNone) {
|
if ((error = OMX_EmptyThisBuffer(omx->comp, omx->input_buf)) != OMX_ErrorNone) {
|
||||||
LOG_ERROR_OMX(error, "Failed to request emptying of the input buffer on encoder");
|
LOG_ERROR_OMX(error, "Failed to request emptying of the input buffer on encoder");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -332,7 +332,7 @@ static int _omx_setup_input(omx_encoder_s *omx, const frame_s *frame) {
|
|||||||
}
|
}
|
||||||
omx->i_input_port_enabled = true;
|
omx->i_input_port_enabled = true;
|
||||||
|
|
||||||
if ((error = OMX_AllocateBuffer(omx->comp, &omx->input_buffer, _INPUT_PORT, NULL, portdef.nBufferSize)) != OMX_ErrorNone) {
|
if ((error = OMX_AllocateBuffer(omx->comp, &omx->input_buf, _INPUT_PORT, NULL, portdef.nBufferSize)) != OMX_ErrorNone) {
|
||||||
LOG_ERROR_OMX(error, "Can't allocate OMX JPEG input buffer");
|
LOG_ERROR_OMX(error, "Can't allocate OMX JPEG input buffer");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -396,7 +396,7 @@ static int _omx_setup_output(omx_encoder_s *omx, unsigned quality) {
|
|||||||
}
|
}
|
||||||
omx->i_output_port_enabled = true;
|
omx->i_output_port_enabled = true;
|
||||||
|
|
||||||
if ((error = OMX_AllocateBuffer(omx->comp, &omx->output_buffer, _OUTPUT_PORT, NULL, portdef.nBufferSize)) != OMX_ErrorNone) {
|
if ((error = OMX_AllocateBuffer(omx->comp, &omx->output_buf, _OUTPUT_PORT, NULL, portdef.nBufferSize)) != OMX_ErrorNone) {
|
||||||
LOG_ERROR_OMX(error, "Can't allocate OMX JPEG output buffer");
|
LOG_ERROR_OMX(error, "Can't allocate OMX JPEG output buffer");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -416,19 +416,19 @@ static int _omx_encoder_clear_ports(omx_encoder_s *omx) {
|
|||||||
omx->i_input_port_enabled = false;
|
omx->i_input_port_enabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (omx->input_buffer) {
|
if (omx->input_buf) {
|
||||||
if ((error = OMX_FreeBuffer(omx->comp, _INPUT_PORT, omx->input_buffer)) != OMX_ErrorNone) {
|
if ((error = OMX_FreeBuffer(omx->comp, _INPUT_PORT, omx->input_buf)) != OMX_ErrorNone) {
|
||||||
LOG_ERROR_OMX(error, "Can't free OMX JPEG input buffer");
|
LOG_ERROR_OMX(error, "Can't free OMX JPEG input buffer");
|
||||||
// retval -= 1;
|
// retval -= 1;
|
||||||
}
|
}
|
||||||
omx->input_buffer = NULL;
|
omx->input_buf = NULL;
|
||||||
}
|
}
|
||||||
if (omx->output_buffer) {
|
if (omx->output_buf) {
|
||||||
if ((error = OMX_FreeBuffer(omx->comp, _OUTPUT_PORT, omx->output_buffer)) != OMX_ErrorNone) {
|
if ((error = OMX_FreeBuffer(omx->comp, _OUTPUT_PORT, omx->output_buf)) != OMX_ErrorNone) {
|
||||||
LOG_ERROR_OMX(error, "Can't free OMX JPEG output buffer");
|
LOG_ERROR_OMX(error, "Can't free OMX JPEG output buffer");
|
||||||
// retval -= 1;
|
// retval -= 1;
|
||||||
}
|
}
|
||||||
omx->output_buffer = NULL;
|
omx->output_buf = NULL;
|
||||||
}
|
}
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
@@ -452,7 +452,7 @@ static OMX_ERRORTYPE _omx_event_handler(
|
|||||||
|
|
||||||
static OMX_ERRORTYPE _omx_input_required_handler(
|
static OMX_ERRORTYPE _omx_input_required_handler(
|
||||||
UNUSED OMX_HANDLETYPE comp,
|
UNUSED OMX_HANDLETYPE comp,
|
||||||
OMX_PTR v_omx, UNUSED OMX_BUFFERHEADERTYPE *buffer) {
|
OMX_PTR v_omx, UNUSED OMX_BUFFERHEADERTYPE *buf) {
|
||||||
|
|
||||||
// Called by OMX when the encoder component requires
|
// Called by OMX when the encoder component requires
|
||||||
// the input buffer to be filled with RAW image data
|
// the input buffer to be filled with RAW image data
|
||||||
@@ -466,7 +466,7 @@ static OMX_ERRORTYPE _omx_input_required_handler(
|
|||||||
|
|
||||||
static OMX_ERRORTYPE _omx_output_available_handler(
|
static OMX_ERRORTYPE _omx_output_available_handler(
|
||||||
UNUSED OMX_HANDLETYPE comp,
|
UNUSED OMX_HANDLETYPE comp,
|
||||||
OMX_PTR v_omx, UNUSED OMX_BUFFERHEADERTYPE *buffer) {
|
OMX_PTR v_omx, UNUSED OMX_BUFFERHEADERTYPE *buf) {
|
||||||
|
|
||||||
// Called by OMX when the encoder component has filled
|
// Called by OMX when the encoder component has filled
|
||||||
// the output buffer with JPEG data
|
// the output buffer with JPEG data
|
||||||
|
|||||||
@@ -51,8 +51,8 @@
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
OMX_HANDLETYPE comp;
|
OMX_HANDLETYPE comp;
|
||||||
OMX_BUFFERHEADERTYPE *input_buffer;
|
OMX_BUFFERHEADERTYPE *input_buf;
|
||||||
OMX_BUFFERHEADERTYPE *output_buffer;
|
OMX_BUFFERHEADERTYPE *output_buf;
|
||||||
bool input_required;
|
bool input_required;
|
||||||
bool output_available;
|
bool output_available;
|
||||||
bool failed;
|
bool failed;
|
||||||
|
|||||||
@@ -369,7 +369,7 @@ int options_parse(options_s *options, device_s *dev, encoder_s *enc, stream_s *s
|
|||||||
case _O_MIN_FRAME_SIZE: OPT_NUMBER("--min-frame-size", dev->min_frame_size, 1, 8192, 0);
|
case _O_MIN_FRAME_SIZE: OPT_NUMBER("--min-frame-size", dev->min_frame_size, 1, 8192, 0);
|
||||||
case _O_PERSISTENT: OPT_SET(dev->persistent, true);
|
case _O_PERSISTENT: OPT_SET(dev->persistent, true);
|
||||||
case _O_DV_TIMINGS: OPT_SET(dev->dv_timings, true);
|
case _O_DV_TIMINGS: OPT_SET(dev->dv_timings, true);
|
||||||
case _O_BUFFERS: OPT_NUMBER("--buffers", dev->n_buffers, 1, 32, 0);
|
case _O_BUFFERS: OPT_NUMBER("--buffers", dev->n_bufs, 1, 32, 0);
|
||||||
case _O_WORKERS: OPT_NUMBER("--workers", enc->n_workers, 1, 32, 0);
|
case _O_WORKERS: OPT_NUMBER("--workers", enc->n_workers, 1, 32, 0);
|
||||||
case _O_QUALITY: OPT_NUMBER("--quality", dev->jpeg_quality, 1, 100, 0);
|
case _O_QUALITY: OPT_NUMBER("--quality", dev->jpeg_quality, 1, 100, 0);
|
||||||
case _O_ENCODER: OPT_PARSE("encoder type", enc->type, encoder_parse_type, ENCODER_TYPE_UNKNOWN, ENCODER_TYPES_STR);
|
case _O_ENCODER: OPT_PARSE("encoder type", enc->type, encoder_parse_type, ENCODER_TYPE_UNKNOWN, ENCODER_TYPES_STR);
|
||||||
@@ -585,7 +585,7 @@ static void _help(FILE *fp, device_s *dev, encoder_s *enc, stream_s *stream, ser
|
|||||||
SAY(" to automatic resolution change. Default: disabled.\n");
|
SAY(" to automatic resolution change. Default: disabled.\n");
|
||||||
SAY(" -b|--buffers <N> ──────────────────── The number of buffers to receive data from the device.");
|
SAY(" -b|--buffers <N> ──────────────────── The number of buffers to receive data from the device.");
|
||||||
SAY(" Each buffer may processed using an independent thread.");
|
SAY(" Each buffer may processed using an independent thread.");
|
||||||
SAY(" Default: %u (the number of CPU cores (but not more than 4) + 1).\n", dev->n_buffers);
|
SAY(" Default: %u (the number of CPU cores (but not more than 4) + 1).\n", dev->n_bufs);
|
||||||
SAY(" -w|--workers <N> ──────────────────── The number of worker threads but not more than buffers.");
|
SAY(" -w|--workers <N> ──────────────────── The number of worker threads but not more than buffers.");
|
||||||
SAY(" Default: %u (the number of CPU cores (but not more than 4)).\n", enc->n_workers);
|
SAY(" Default: %u (the number of CPU cores (but not more than 4)).\n", enc->n_workers);
|
||||||
SAY(" -q|--quality <N> ──────────────────── Set quality of JPEG encoding from 1 to 100 (best). Default: %u.", dev->jpeg_quality);
|
SAY(" -q|--quality <N> ──────────────────── Set quality of JPEG encoding from 1 to 100 (best). Default: %u.", dev->jpeg_quality);
|
||||||
|
|||||||
Reference in New Issue
Block a user