mirror of
https://github.com/pikvm/ustreamer.git
synced 2026-03-01 21:26:33 +00:00
refactoring
This commit is contained in:
@@ -74,3 +74,7 @@ bool frame_compare(const frame_s *a, const frame_s *b);
|
||||
unsigned frame_get_padding(const frame_s *frame);
|
||||
|
||||
const char *fourcc_to_string(unsigned format, char *buf, size_t size);
|
||||
|
||||
inline bool is_jpeg(unsigned format) {
|
||||
return (format == V4L2_PIX_FMT_JPEG || format == V4L2_PIX_FMT_MJPEG);
|
||||
}
|
||||
|
||||
@@ -34,6 +34,8 @@ static void _jpeg_error_handler(j_common_ptr jpeg);
|
||||
|
||||
|
||||
int unjpeg(const frame_s *src, frame_s *dest, bool decode) {
|
||||
assert(is_jpeg(src->format));
|
||||
|
||||
volatile int retval = 0;
|
||||
|
||||
struct jpeg_decompress_struct jpeg;
|
||||
|
||||
@@ -582,7 +582,7 @@ static void _device_open_hw_fps(device_s *dev) {
|
||||
static void _device_open_jpeg_quality(device_s *dev) {
|
||||
unsigned quality = 0;
|
||||
|
||||
if (RUN(format) == V4L2_PIX_FMT_MJPEG || RUN(format) == V4L2_PIX_FMT_JPEG) {
|
||||
if (is_jpeg(RUN(format))) {
|
||||
struct v4l2_jpegcompression comp;
|
||||
MEMSET_ZERO(comp);
|
||||
|
||||
|
||||
@@ -96,13 +96,13 @@ void encoder_prepare(encoder_s *enc, device_s *dev) {
|
||||
|
||||
ER(n_workers) = min_u(enc->n_workers, DR(n_buffers));
|
||||
|
||||
if ((DR(format) == V4L2_PIX_FMT_MJPEG || DR(format) == V4L2_PIX_FMT_JPEG) && type != ENCODER_TYPE_HW) {
|
||||
if (is_jpeg(DR(format)) && type != ENCODER_TYPE_HW) {
|
||||
LOG_INFO("Switching to HW encoder: the input is (M)JPEG ...");
|
||||
type = ENCODER_TYPE_HW;
|
||||
}
|
||||
|
||||
if (type == ENCODER_TYPE_HW) {
|
||||
if (DR(format) != V4L2_PIX_FMT_MJPEG && DR(format) != V4L2_PIX_FMT_JPEG) {
|
||||
if (!is_jpeg(DR(format))) {
|
||||
LOG_INFO("Switching to CPU encoder: the input format is not (M)JPEG ...");
|
||||
goto use_cpu;
|
||||
}
|
||||
|
||||
@@ -33,9 +33,7 @@ static bool _is_huffman(const uint8_t *data);
|
||||
|
||||
|
||||
void hw_encoder_compress(const frame_s *src, frame_s *dest) {
|
||||
if (src->format != V4L2_PIX_FMT_MJPEG && src->format != V4L2_PIX_FMT_JPEG) {
|
||||
assert(0 && "Unsupported input format for HW encoder");
|
||||
}
|
||||
assert(is_jpeg(src->format));
|
||||
_copy_plus_huffman(src, dest);
|
||||
}
|
||||
|
||||
|
||||
@@ -263,7 +263,7 @@ int h264_encoder_compress(h264_encoder_s *enc, const frame_s *src, frame_s *dest
|
||||
dest->format = V4L2_PIX_FMT_H264;
|
||||
dest->stride = 0;
|
||||
|
||||
if (src->format == V4L2_PIX_FMT_MJPEG || src->format == V4L2_PIX_FMT_JPEG) {
|
||||
if (is_jpeg(src->format)) {
|
||||
LOG_DEBUG("H264: Input frame format is JPEG; decoding ...");
|
||||
if (unjpeg(src, RUN(tmp), true) < 0) {
|
||||
return -1;
|
||||
|
||||
Reference in New Issue
Block a user