mirror of
https://github.com/pikvm/ustreamer.git
synced 2026-07-21 03:01:55 +00:00
reused unjpeg
This commit is contained in:
@@ -26,19 +26,19 @@
|
||||
typedef struct {
|
||||
struct jpeg_error_mgr mgr; // Default manager
|
||||
jmp_buf jmp;
|
||||
const frame_s *frame;
|
||||
} _jpeg_error_manager_s;
|
||||
|
||||
|
||||
static void _jpeg_error_handler(j_common_ptr jpeg);
|
||||
|
||||
|
||||
int unjpeg(const frame_s *src, frame_s *dest) {
|
||||
int unjpeg(const frame_s *src, frame_s *dest, bool decode) {
|
||||
volatile int retval = 0;
|
||||
|
||||
struct jpeg_decompress_struct jpeg;
|
||||
jpeg_create_decompress(&jpeg);
|
||||
|
||||
frame_realloc_data(dest, ((src->width * src->height) << 1) * 2);
|
||||
frame_copy_meta(src, dest);
|
||||
dest->format = V4L2_PIX_FMT_RGB24;
|
||||
dest->used = 0;
|
||||
@@ -48,6 +48,7 @@ int unjpeg(const frame_s *src, frame_s *dest) {
|
||||
_jpeg_error_manager_s jpeg_error;
|
||||
jpeg.err = jpeg_std_error((struct jpeg_error_mgr *)&jpeg_error);
|
||||
jpeg_error.mgr.error_exit = _jpeg_error_handler;
|
||||
jpeg_error.frame = src;
|
||||
if (setjmp(jpeg_error.jmp) < 0) {
|
||||
retval = -1;
|
||||
goto done;
|
||||
@@ -58,18 +59,22 @@ int unjpeg(const frame_s *src, frame_s *dest) {
|
||||
jpeg.out_color_space = JCS_RGB;
|
||||
|
||||
jpeg_start_decompress(&jpeg);
|
||||
const unsigned row_stride = jpeg.output_width * jpeg.output_components;
|
||||
|
||||
JSAMPARRAY scanlines;
|
||||
scanlines = (*jpeg.mem->alloc_sarray)((j_common_ptr) &jpeg, JPOOL_IMAGE, row_stride, 1);
|
||||
if (decode) {
|
||||
const unsigned row_stride = jpeg.output_width * jpeg.output_components;
|
||||
|
||||
while (jpeg.output_scanline < jpeg.output_height) {
|
||||
jpeg_read_scanlines(&jpeg, scanlines, 1);
|
||||
frame_append_data(dest, scanlines[0], row_stride);
|
||||
JSAMPARRAY scanlines;
|
||||
scanlines = (*jpeg.mem->alloc_sarray)((j_common_ptr) &jpeg, JPOOL_IMAGE, row_stride, 1);
|
||||
|
||||
frame_realloc_data(dest, ((src->width * src->height) << 1) * 2);
|
||||
while (jpeg.output_scanline < jpeg.output_height) {
|
||||
jpeg_read_scanlines(&jpeg, scanlines, 1);
|
||||
frame_append_data(dest, scanlines[0], row_stride);
|
||||
}
|
||||
|
||||
jpeg_finish_decompress(&jpeg);
|
||||
}
|
||||
|
||||
jpeg_finish_decompress(&jpeg);
|
||||
|
||||
dest->width = jpeg.output_width;
|
||||
dest->height = jpeg.output_height;
|
||||
|
||||
@@ -83,6 +88,6 @@ static void _jpeg_error_handler(j_common_ptr jpeg) {
|
||||
char msg[JMSG_LENGTH_MAX];
|
||||
|
||||
(*jpeg_error->mgr.format_message)(jpeg, msg);
|
||||
LOG_ERROR("Can't decompress JPEG: %s", msg);
|
||||
LOG_ERROR("Can't decompress %s JPEG: %s", jpeg_error->frame->name, msg);
|
||||
longjmp(jpeg_error->jmp, -1);
|
||||
}
|
||||
@@ -23,6 +23,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <setjmp.h>
|
||||
#include <assert.h>
|
||||
@@ -32,8 +33,8 @@
|
||||
#include <jpeglib.h>
|
||||
#include <linux/videodev2.h>
|
||||
|
||||
#include "../common/logging.h"
|
||||
#include "../common/frame.h"
|
||||
#include "logging.h"
|
||||
#include "frame.h"
|
||||
|
||||
|
||||
int unjpeg(const frame_s *src, frame_s *dest);
|
||||
int unjpeg(const frame_s *src, frame_s *dest, bool decode);
|
||||
@@ -87,7 +87,7 @@ int h264_encoder_compress(h264_encoder_s *encoder, const frame_s *src, frame_s *
|
||||
|
||||
if (src->format == V4L2_PIX_FMT_MJPEG || src->format == V4L2_PIX_FMT_JPEG) {
|
||||
LOG_DEBUG("Input frame format is JPEG; decoding ...");
|
||||
if (unjpeg(src, RUN(tmp)) < 0) {
|
||||
if (unjpeg(src, RUN(tmp), true) < 0) {
|
||||
return -1;
|
||||
}
|
||||
src = RUN(tmp);
|
||||
|
||||
@@ -38,8 +38,7 @@
|
||||
#include "../common/tools.h"
|
||||
#include "../common/logging.h"
|
||||
#include "../common/frame.h"
|
||||
|
||||
#include "unjpeg.h"
|
||||
#include "../common/unjpeg.h"
|
||||
|
||||
|
||||
typedef struct {
|
||||
|
||||
Reference in New Issue
Block a user