mirror of
https://github.com/pikvm/ustreamer.git
synced 2026-05-26 15:26:12 +00:00
refactoring
This commit is contained in:
2
Makefile
2
Makefile
@@ -8,7 +8,7 @@ LDFLAGS ?=
|
|||||||
CC = gcc
|
CC = gcc
|
||||||
LIBS = -lm -ljpeg -pthread -levent -levent_pthreads -luuid
|
LIBS = -lm -ljpeg -pthread -levent -levent_pthreads -luuid
|
||||||
override CFLAGS += -c -std=c99 -Wall -Wextra -D_GNU_SOURCE
|
override CFLAGS += -c -std=c99 -Wall -Wextra -D_GNU_SOURCE
|
||||||
SOURCES = $(shell ls src/*.c src/encoders/jpeg/*.c src/encoders/hw/*.c)
|
SOURCES = $(shell ls src/*.c src/encoders/cpu/*.c src/encoders/hw/*.c)
|
||||||
OBJECTS = $(SOURCES:.c=.o)
|
OBJECTS = $(SOURCES:.c=.o)
|
||||||
PROG = ustreamer
|
PROG = ustreamer
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@
|
|||||||
#include "device.h"
|
#include "device.h"
|
||||||
#include "encoder.h"
|
#include "encoder.h"
|
||||||
|
|
||||||
#include "encoders/jpeg/encoder.h"
|
#include "encoders/cpu/encoder.h"
|
||||||
#include "encoders/hw/encoder.h"
|
#include "encoders/hw/encoder.h"
|
||||||
|
|
||||||
#ifdef OMX_ENCODER
|
#ifdef OMX_ENCODER
|
||||||
@@ -198,7 +198,7 @@ int encoder_compress_buffer(struct encoder_t *encoder, struct device_t *dev, uns
|
|||||||
assert(encoder->run->type != ENCODER_TYPE_UNKNOWN);
|
assert(encoder->run->type != ENCODER_TYPE_UNKNOWN);
|
||||||
|
|
||||||
if (encoder->run->type == ENCODER_TYPE_CPU) {
|
if (encoder->run->type == ENCODER_TYPE_CPU) {
|
||||||
jpeg_encoder_compress_buffer(dev, buf_index, encoder->quality);
|
cpu_encoder_compress_buffer(dev, buf_index, encoder->quality);
|
||||||
} else if (encoder->run->type == ENCODER_TYPE_HW) {
|
} else if (encoder->run->type == ENCODER_TYPE_HW) {
|
||||||
hw_encoder_compress_buffer(dev, buf_index);
|
hw_encoder_compress_buffer(dev, buf_index);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,7 @@
|
|||||||
#include "encoder.h"
|
#include "encoder.h"
|
||||||
|
|
||||||
|
|
||||||
struct _mjpg_destination_mgr {
|
struct _jpeg_dest_manager_t {
|
||||||
struct jpeg_destination_mgr mgr; // Default manager
|
struct jpeg_destination_mgr mgr; // Default manager
|
||||||
JOCTET *buffer; // Start of buffer
|
JOCTET *buffer; // Start of buffer
|
||||||
unsigned char *outbuffer_cursor;
|
unsigned char *outbuffer_cursor;
|
||||||
@@ -70,7 +70,7 @@ static boolean _jpeg_empty_output_buffer(j_compress_ptr jpeg);
|
|||||||
static void _jpeg_term_destination(j_compress_ptr jpeg);
|
static void _jpeg_term_destination(j_compress_ptr jpeg);
|
||||||
|
|
||||||
|
|
||||||
void jpeg_encoder_compress_buffer(struct device_t *dev, unsigned index, unsigned quality) {
|
void cpu_encoder_compress_buffer(struct device_t *dev, unsigned index, unsigned quality) {
|
||||||
// This function based on compress_image_to_jpeg() from mjpg-streamer
|
// This function based on compress_image_to_jpeg() from mjpg-streamer
|
||||||
|
|
||||||
struct jpeg_compress_struct jpeg;
|
struct jpeg_compress_struct jpeg;
|
||||||
@@ -115,15 +115,15 @@ void jpeg_encoder_compress_buffer(struct device_t *dev, unsigned index, unsigned
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void _jpeg_set_dest_picture(j_compress_ptr jpeg, unsigned char *picture, unsigned long *written) {
|
static void _jpeg_set_dest_picture(j_compress_ptr jpeg, unsigned char *picture, unsigned long *written) {
|
||||||
struct _mjpg_destination_mgr *dest;
|
struct _jpeg_dest_manager_t *dest;
|
||||||
|
|
||||||
if (jpeg->dest == NULL) {
|
if (jpeg->dest == NULL) {
|
||||||
assert((jpeg->dest = (struct jpeg_destination_mgr *)(*jpeg->mem->alloc_small)(
|
assert((jpeg->dest = (struct jpeg_destination_mgr *)(*jpeg->mem->alloc_small)(
|
||||||
(j_common_ptr) jpeg, JPOOL_PERMANENT, sizeof(struct _mjpg_destination_mgr)
|
(j_common_ptr) jpeg, JPOOL_PERMANENT, sizeof(struct _jpeg_dest_manager_t)
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
dest = (struct _mjpg_destination_mgr *)jpeg->dest;
|
dest = (struct _jpeg_dest_manager_t *)jpeg->dest;
|
||||||
dest->mgr.init_destination = _jpeg_init_destination;
|
dest->mgr.init_destination = _jpeg_init_destination;
|
||||||
dest->mgr.empty_output_buffer = _jpeg_empty_output_buffer;
|
dest->mgr.empty_output_buffer = _jpeg_empty_output_buffer;
|
||||||
dest->mgr.term_destination = _jpeg_term_destination;
|
dest->mgr.term_destination = _jpeg_term_destination;
|
||||||
@@ -257,7 +257,7 @@ static void _jpeg_write_scanlines_rgb24(
|
|||||||
#define JPEG_OUTPUT_BUFFER_SIZE 4096
|
#define JPEG_OUTPUT_BUFFER_SIZE 4096
|
||||||
|
|
||||||
static void _jpeg_init_destination(j_compress_ptr jpeg) {
|
static void _jpeg_init_destination(j_compress_ptr jpeg) {
|
||||||
struct _mjpg_destination_mgr *dest = (struct _mjpg_destination_mgr *)jpeg->dest;
|
struct _jpeg_dest_manager_t *dest = (struct _jpeg_dest_manager_t *)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->buffer = (JOCTET *)(*jpeg->mem->alloc_small)(
|
||||||
@@ -271,7 +271,7 @@ static void _jpeg_init_destination(j_compress_ptr jpeg) {
|
|||||||
static boolean _jpeg_empty_output_buffer(j_compress_ptr jpeg) {
|
static boolean _jpeg_empty_output_buffer(j_compress_ptr jpeg) {
|
||||||
// Called whenever local jpeg buffer fills up
|
// Called whenever local jpeg buffer fills up
|
||||||
|
|
||||||
struct _mjpg_destination_mgr *dest = (struct _mjpg_destination_mgr *)jpeg->dest;
|
struct _jpeg_dest_manager_t *dest = (struct _jpeg_dest_manager_t *)jpeg->dest;
|
||||||
|
|
||||||
memcpy(dest->outbuffer_cursor, dest->buffer, JPEG_OUTPUT_BUFFER_SIZE);
|
memcpy(dest->outbuffer_cursor, dest->buffer, JPEG_OUTPUT_BUFFER_SIZE);
|
||||||
dest->outbuffer_cursor += JPEG_OUTPUT_BUFFER_SIZE;
|
dest->outbuffer_cursor += JPEG_OUTPUT_BUFFER_SIZE;
|
||||||
@@ -287,7 +287,7 @@ static void _jpeg_term_destination(j_compress_ptr jpeg) {
|
|||||||
// Called by jpeg_finish_compress after all data has been written.
|
// Called by jpeg_finish_compress after all data has been written.
|
||||||
// Usually needs to flush buffer
|
// Usually needs to flush buffer
|
||||||
|
|
||||||
struct _mjpg_destination_mgr *dest = (struct _mjpg_destination_mgr *)jpeg->dest;
|
struct _jpeg_dest_manager_t *dest = (struct _jpeg_dest_manager_t *)jpeg->dest;
|
||||||
size_t data_count = JPEG_OUTPUT_BUFFER_SIZE - dest->mgr.free_in_buffer;
|
size_t data_count = JPEG_OUTPUT_BUFFER_SIZE - dest->mgr.free_in_buffer;
|
||||||
|
|
||||||
// Write any data remaining in the buffer
|
// Write any data remaining in the buffer
|
||||||
@@ -25,4 +25,4 @@
|
|||||||
#include "../../device.h"
|
#include "../../device.h"
|
||||||
|
|
||||||
|
|
||||||
void jpeg_encoder_compress_buffer(struct device_t *dev, unsigned index, unsigned quality);
|
void cpu_encoder_compress_buffer(struct device_t *dev, unsigned index, unsigned quality);
|
||||||
Reference in New Issue
Block a user