refactoring

This commit is contained in:
Devaev Maxim
2020-12-08 10:32:10 +03:00
parent 2fd3bc34b5
commit f7ddb635a5
25 changed files with 139 additions and 209 deletions

View File

@@ -20,10 +20,6 @@
*****************************************************************************/
#include <stdbool.h>
#include <pthread.h>
#include "logging.h"

View File

@@ -22,20 +22,6 @@
#include "rawsink.h"
#include <stdbool.h>
#include <string.h>
#include <fcntl.h>
#include <semaphore.h>
#include <errno.h>
#include <assert.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include "../common/tools.h"
#include "../common/logging.h"
static int _sem_wait_monotonic(sem_t *sem, long double timeout);
@@ -181,14 +167,14 @@ void rawsink_put(
goto error;
}
# define SH(_field) rawsink->shared->_field = _field
SH(format);
SH(width);
SH(height);
SH(grab_ts);
SH(size);
# define COPY(_field) rawsink->shared->_field = _field
COPY(format);
COPY(width);
COPY(height);
COPY(grab_ts);
COPY(size);
memcpy(rawsink->shared->data, data, size);
# undef SH
# undef COPY
if (sem_post(rawsink->signal_sem) < 0) {
LOG_PERROR("RAWSINK: Can't post %s", rawsink->signal_name);
@@ -237,14 +223,14 @@ int rawsink_get(
WAIT_SEM(signal);
WAIT_SEM(lock);
# define SH(_field) *_field = rawsink->shared->_field
SH(format);
SH(width);
SH(height);
SH(grab_ts);
SH(size);
# define COPY(_field) *_field = rawsink->shared->_field
COPY(format);
COPY(width);
COPY(height);
COPY(grab_ts);
COPY(size);
memcpy(data, rawsink->shared->data, *size);
# undef SH
# undef COPY
if (sem_post(rawsink->lock_sem) < 0) {
LOG_PERROR("RAWSINK: Can't post %s", rawsink->lock_name);

View File

@@ -23,10 +23,18 @@
#pragma once
#include <stdbool.h>
#include <string.h>
#include <fcntl.h>
#include <semaphore.h>
#include <errno.h>
#include <assert.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include "../common/tools.h"
#include "../common/logging.h"
#ifndef CFG_RAWSINK_MAX_DATA

View File

@@ -22,29 +22,6 @@
#include "device.h"
#include <stdlib.h>
#include <stddef.h>
#include <stdbool.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <assert.h>
#include <sys/select.h>
#include <sys/mman.h>
#include <sys/time.h>
#include <linux/videodev2.h>
#include <linux/v4l2-controls.h>
#include "../common/tools.h"
#include "../common/logging.h"
#include "../common/threading.h"
#include "xioctl.h"
static const struct {
const char *name;

View File

@@ -22,11 +22,29 @@
#pragma once
#include <stdlib.h>
#include <stddef.h>
#include <stdbool.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <assert.h>
#include <sys/select.h>
#include <sys/mman.h>
#include <sys/time.h>
#include <pthread.h>
#include <linux/videodev2.h>
#include <linux/v4l2-controls.h>
#include "../common/tools.h"
#include "../common/logging.h"
#include "../common/threading.h"
#include "xioctl.h"
#ifdef WITH_RAWSINK
# include "../rawsink/rawsink.h"

View File

@@ -22,26 +22,6 @@
#include "encoder.h"
#include <stdlib.h>
#include <stdbool.h>
#include <strings.h>
#include <assert.h>
#include <linux/videodev2.h>
#include "../common/tools.h"
#include "../common/threading.h"
#include "../common/logging.h"
#include "device.h"
#include "picture.h"
#include "encoders/cpu/encoder.h"
#include "encoders/hw/encoder.h"
#ifdef WITH_OMX
# include "encoders/omx/encoder.h"
#endif
static const struct {
const char *name;

View File

@@ -22,18 +22,27 @@
#pragma once
#include <stdlib.h>
#include <stdbool.h>
#include <strings.h>
#include <assert.h>
#include <pthread.h>
#include <linux/videodev2.h>
#include "../common/tools.h"
#include "../common/threading.h"
#include "../common/logging.h"
#include "device.h"
#include "picture.h"
#include "encoders/cpu/encoder.h"
#include "encoders/hw/encoder.h"
#ifdef WITH_OMX
# include "encoders/omx/encoder.h"
# define ENCODER_TYPES_OMX_HINT ", OMX"
# ifndef CFG_MAX_GLITCHED_RESOLUTIONS
# define CFG_MAX_GLITCHED_RESOLUTIONS 1024
# endif

View File

@@ -27,18 +27,6 @@
#include "encoder.h"
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <jpeglib.h>
#include <linux/videodev2.h>
#include "../../../common/tools.h"
#include "../../picture.h"
#include "../../device.h"
struct _jpeg_dest_manager_t {
struct jpeg_destination_mgr mgr; // Default manager

View File

@@ -22,8 +22,17 @@
#pragma once
#include "../../device.h"
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <jpeglib.h>
#include <linux/videodev2.h>
#include "../../../common/tools.h"
#include "../../picture.h"
#include "../../device.h"
void cpu_encoder_compress_buffer(struct hw_buffer_t *hw, struct picture_t *picture, unsigned quality);

View File

@@ -27,20 +27,6 @@
#include "encoder.h"
#include <stdbool.h>
#include <string.h>
#include <assert.h>
#include <linux/videodev2.h>
#include "../../../common/tools.h"
#include "../../../common/logging.h"
#include "../../xioctl.h"
#include "../../picture.h"
#include "../../device.h"
#include "huffman.h"
void _copy_plus_huffman(const struct hw_buffer_t *src, struct picture_t *dest);
static bool _is_huffman(const unsigned char *data);

View File

@@ -22,8 +22,19 @@
#pragma once
#include "../../device.h"
#include <stdbool.h>
#include <string.h>
#include <assert.h>
#include <linux/videodev2.h>
#include "../../../common/tools.h"
#include "../../../common/logging.h"
#include "../../xioctl.h"
#include "../../picture.h"
#include "../../device.h"
#include "huffman.h"
int hw_encoder_prepare(struct device_t *dev, unsigned quality);

View File

@@ -22,15 +22,6 @@
#include "component.h"
#include <unistd.h>
#include <IL/OMX_Core.h>
#include <IL/OMX_Component.h>
#include "../../../common/logging.h"
#include "formatters.h"
static int _component_wait_port_changed(OMX_HANDLETYPE *component, OMX_U32 port, OMX_BOOL enabled);
static int _component_wait_state_changed(OMX_HANDLETYPE *component, OMX_STATETYPE wanted);

View File

@@ -23,10 +23,15 @@
#pragma once
#include <string.h>
#include <unistd.h>
#include <IL/OMX_Core.h>
#include <IL/OMX_Component.h>
#include "../../../common/logging.h"
#include "formatters.h"
#define OMX_INIT_STRUCTURE(_var) { \
memset(&(_var), 0, sizeof(_var)); \

View File

@@ -22,28 +22,6 @@
#include "encoder.h"
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <unistd.h>
#include <assert.h>
#include <linux/videodev2.h>
#include <bcm_host.h>
#include <IL/OMX_Core.h>
#include <IL/OMX_Component.h>
#include <IL/OMX_Broadcom.h>
#include <interface/vcos/vcos_semaphore.h>
#include "../../../common/logging.h"
#include "../../../common/tools.h"
#include "../../device.h"
#include "../../picture.h"
#include "formatters.h"
#include "component.h"
static const OMX_U32 _INPUT_PORT = 340;
static const OMX_U32 _OUTPUT_PORT = 341;

View File

@@ -22,14 +22,29 @@
#pragma once
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <unistd.h>
#include <assert.h>
#include <linux/videodev2.h>
#include <bcm_host.h>
#include <IL/OMX_Core.h>
#include <IL/OMX_Component.h>
#include <IL/OMX_Broadcom.h>
#include <interface/vcos/vcos_semaphore.h>
#include "../../../common/logging.h"
#include "../../../common/tools.h"
#include "../../device.h"
#include "../../picture.h"
#include "formatters.h"
#include "component.h"
#ifndef CFG_OMX_MAX_ENCODERS
# define CFG_OMX_MAX_ENCODERS 3 // Raspberry Pi limitation
#endif

View File

@@ -22,14 +22,6 @@
#include "formatters.h"
#include <stdio.h>
#include <assert.h>
#include <IL/OMX_IVCommon.h>
#include <IL/OMX_Core.h>
#include "../../../common/tools.h"
#define CASE_TO_STRING(_value) \
case _value: { return #_value; }

View File

@@ -22,10 +22,14 @@
#pragma once
#include <stdio.h>
#include <assert.h>
#include <IL/OMX_IVCommon.h>
#include <IL/OMX_Core.h>
#include <IL/OMX_Image.h>
#include "../../../common/tools.h"
#include "../../../common/logging.h"

View File

@@ -22,18 +22,6 @@
#include "gpio.h"
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <assert.h>
#include <pthread.h>
#include <gpiod.h>
#include "../../common/tools.h"
#include "../../common/logging.h"
#include "../../common/threading.h"
struct gpio_t gpio = {
.path = "/dev/gpiochip0",

View File

@@ -22,13 +22,17 @@
#pragma once
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <assert.h>
#include <pthread.h>
#include <gpiod.h>
#include "../../common/tools.h"
#include "../../common/logging.h"
#include "../../common/threading.h"
struct gpio_output_t {

View File

@@ -22,28 +22,6 @@
#include "options.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <strings.h>
#include <ctype.h>
#include <limits.h>
#include <getopt.h>
#include <errno.h>
#include <assert.h>
#include "../common/config.h"
#include "../common/logging.h"
#include "../common/process.h"
#include "device.h"
#include "encoder.h"
#include "http/server.h"
#ifdef WITH_GPIO
# include "gpio/gpio.h"
#endif
enum _OPT_VALUES {
_O_DEVICE = 'd',

View File

@@ -22,9 +22,27 @@
#pragma once
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <strings.h>
#include <ctype.h>
#include <limits.h>
#include <getopt.h>
#include <errno.h>
#include <assert.h>
#include "../common/config.h"
#include "../common/logging.h"
#include "../common/process.h"
#include "device.h"
#include "encoder.h"
#include "http/server.h"
#ifdef WITH_GPIO
# include "gpio/gpio.h"
#endif
struct options_t {

View File

@@ -22,14 +22,6 @@
#include "picture.h"
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <assert.h>
#include "../common/tools.h"
#include "../common/logging.h"
struct picture_t *picture_init(void) {
struct picture_t *picture;

View File

@@ -24,6 +24,12 @@
#include <stddef.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "../common/tools.h"
#include "../common/logging.h"
struct picture_t {

View File

@@ -22,29 +22,6 @@
#include "stream.h"
#include <stdlib.h>
#include <stdbool.h>
#include <stdatomic.h>
#include <unistd.h>
#include <errno.h>
#include <assert.h>
#include <pthread.h>
#include "../common/tools.h"
#include "../common/threading.h"
#include "../common/logging.h"
#include "picture.h"
#include "device.h"
#include "encoder.h"
#ifdef WITH_RAWSINK
# include "../rawsink/rawsink.h"
#endif
#ifdef WITH_GPIO
# include "gpio/gpio.h"
#endif
struct _worker_t {
pthread_t tid;

View File

@@ -22,14 +22,28 @@
#pragma once
#include <stdlib.h>
#include <stdbool.h>
#include <stdatomic.h>
#include <unistd.h>
#include <errno.h>
#include <assert.h>
#include <pthread.h>
#include "../common/tools.h"
#include "../common/threading.h"
#include "../common/logging.h"
#include "picture.h"
#include "device.h"
#include "encoder.h"
#ifdef WITH_RAWSINK
# include "../rawsink/rawsink.h"
#endif
#ifdef WITH_GPIO
# include "gpio/gpio.h"
#endif
struct process_t {