mirror of
https://github.com/pikvm/ustreamer.git
synced 2026-04-11 00:56:13 +00:00
initializing global object in main()
This commit is contained in:
@@ -57,9 +57,6 @@ void h264_encoder_destroy(h264_encoder_s *encoder) {
|
||||
if (RUN(i_handler_sem)) {
|
||||
vcos_semaphore_delete(&RUN(handler_sem));
|
||||
}
|
||||
if (RUN(i_bcm_host)) {
|
||||
bcm_host_deinit();
|
||||
}
|
||||
frame_destroy(RUN(tmp));
|
||||
free(encoder);
|
||||
}
|
||||
@@ -70,14 +67,7 @@ int h264_encoder_compress(h264_encoder_s *encoder, const frame_s *src, frame_s *
|
||||
assert(src->height > 0);
|
||||
assert(src->format > 0);
|
||||
|
||||
if (!RUN(i_bcm_host)) {
|
||||
LOG_INFO("Initializing BCM ...");
|
||||
bcm_host_init();
|
||||
RUN(i_bcm_host) = true;
|
||||
}
|
||||
|
||||
if (!RUN(i_handler_sem)) {
|
||||
LOG_INFO("Creating VCOS semaphore ...");
|
||||
if (vcos_semaphore_create(&RUN(handler_sem), "h264_handler_sem", 0) != VCOS_SUCCESS) {
|
||||
LOG_PERROR("Can't create VCOS semaphore");
|
||||
return -1;
|
||||
@@ -156,18 +146,16 @@ static int _h264_encoder_configure(h264_encoder_s *encoder, const frame_s *frame
|
||||
|
||||
# define IFMT(_next) RUN(input_port->format->_next)
|
||||
IFMT(type) = MMAL_ES_TYPE_VIDEO;
|
||||
if (frame->format == V4L2_PIX_FMT_UYVY) {
|
||||
LOG_INFO("Using pixelformat: UYVY");
|
||||
IFMT(encoding) = MMAL_ENCODING_UYVY;
|
||||
} else if (frame->format == V4L2_PIX_FMT_RGB24) {
|
||||
LOG_INFO("Using pixelformat: RGB24");
|
||||
IFMT(encoding) = MMAL_ENCODING_RGB24;
|
||||
} else {
|
||||
char fourcc_buf[8];
|
||||
LOG_ERROR("Unsupported pixelformat (fourcc): %s", fourcc_to_string(frame->format, fourcc_buf, 8));
|
||||
goto error;
|
||||
switch (frame->format) {
|
||||
case V4L2_PIX_FMT_YUYV: IFMT(encoding) = MMAL_ENCODING_YUYV; break;
|
||||
case V4L2_PIX_FMT_UYVY: IFMT(encoding) = MMAL_ENCODING_UYVY; break;
|
||||
case V4L2_PIX_FMT_RGB565: IFMT(encoding) = MMAL_ENCODING_RGB16; break;
|
||||
case V4L2_PIX_FMT_RGB24: IFMT(encoding) = MMAL_ENCODING_RGB24; break;
|
||||
default:
|
||||
char fourcc_buf[8];
|
||||
LOG_ERROR("Unsupported input format for MMAL (fourcc): %s", fourcc_to_string(frame->format, fourcc_buf, 8));
|
||||
goto error;
|
||||
}
|
||||
LOG_INFO("Using resolution: %ux%u", frame->width, frame->height);
|
||||
IFMT(es->video.width) = align_size(frame->width, 32);
|
||||
IFMT(es->video.height) = align_size(frame->height, 16);
|
||||
IFMT(es->video.crop.x) = 0;
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
|
||||
#include <linux/videodev2.h>
|
||||
|
||||
#include <bcm_host.h>
|
||||
#include <interface/mmal/mmal.h>
|
||||
#include <interface/mmal/mmal_format.h>
|
||||
#include <interface/mmal/util/mmal_default_components.h>
|
||||
@@ -46,7 +45,6 @@ typedef struct {
|
||||
MMAL_PORT_T *input_port;
|
||||
MMAL_PORT_T *output_port;
|
||||
VCOS_SEMAPHORE_T handler_sem;
|
||||
bool i_bcm_host;
|
||||
bool i_handler_sem;
|
||||
|
||||
unsigned width;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <bcm_host.h>
|
||||
|
||||
#include "../common/logging.h"
|
||||
#include "../common/frame.h"
|
||||
#include "../memsink/memsink.h"
|
||||
@@ -10,6 +12,8 @@ int main(void) {
|
||||
LOGGING_INIT;
|
||||
log_level = 3;
|
||||
|
||||
bcm_host_init();
|
||||
|
||||
frame_s *src = frame_init("src");
|
||||
frame_s *dest = frame_init("dest");
|
||||
h264_encoder_s *encoder = h264_encoder_init();
|
||||
|
||||
@@ -27,9 +27,6 @@ static const OMX_U32 _INPUT_PORT = 340;
|
||||
static const OMX_U32 _OUTPUT_PORT = 341;
|
||||
|
||||
|
||||
static int _i_omx = 0;
|
||||
|
||||
|
||||
static int _vcos_semwait(VCOS_SEMAPHORE_T *sem);
|
||||
static int _omx_init_component(omx_encoder_s *omx);
|
||||
static int _omx_init_disable_ports(omx_encoder_s *omx);
|
||||
@@ -65,19 +62,6 @@ omx_encoder_s *omx_encoder_init(void) {
|
||||
omx_encoder_s *omx;
|
||||
A_CALLOC(omx, 1);
|
||||
|
||||
assert(_i_omx >= 0);
|
||||
if (_i_omx == 0) {
|
||||
LOG_INFO("Initializing BCM ...");
|
||||
bcm_host_init();
|
||||
|
||||
LOG_INFO("Initializing OMX ...");
|
||||
if ((OMX_ERRORTYPE error = OMX_Init()) != OMX_ErrorNone) {
|
||||
LOG_ERROR_OMX(error, "Can't initialize OMX");
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
_i_omx += 1;
|
||||
|
||||
LOG_INFO("Initializing OMX encoder ...");
|
||||
|
||||
if (vcos_semaphore_create(&omx->handler_sem, "handler_sem", 0) != VCOS_SUCCESS) {
|
||||
@@ -118,16 +102,6 @@ void omx_encoder_destroy(omx_encoder_s *omx) {
|
||||
}
|
||||
}
|
||||
|
||||
assert(_i_omx >= 0);
|
||||
_i_omx -= 1;
|
||||
if (_i_omx == 0) {
|
||||
LOG_INFO("Destroying OMX ...");
|
||||
OMX_Deinit();
|
||||
|
||||
LOG_INFO("Destroying BCM ...");
|
||||
bcm_host_deinit();
|
||||
}
|
||||
|
||||
free(omx);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
|
||||
#include <linux/videodev2.h>
|
||||
|
||||
#include <bcm_host.h>
|
||||
#include <IL/OMX_Core.h>
|
||||
#include <IL/OMX_Component.h>
|
||||
#include <IL/OMX_Broadcom.h>
|
||||
|
||||
@@ -35,6 +35,10 @@
|
||||
#include <signal.h>
|
||||
|
||||
#include <pthread.h>
|
||||
#ifdef WITH_OMX
|
||||
# include <bcm_host.h>
|
||||
# include <IL/OMX_Core.h>
|
||||
#endif
|
||||
|
||||
#include "../libs/common/tools.h"
|
||||
#include "../libs/common/threading.h"
|
||||
@@ -123,6 +127,25 @@ int main(int argc, char *argv[]) {
|
||||
int exit_code = 0;
|
||||
|
||||
if ((exit_code = options_parse(options, dev, encoder, stream, server)) == 0) {
|
||||
# ifdef WITH_OMX
|
||||
bool i_bcm_host = false;
|
||||
if (encoder->type == ENCODER_TYPE_OMX) {
|
||||
LOG_INFO("Initializing BCM Host ...");
|
||||
bcm_host_init();
|
||||
i_bcm_host = true;
|
||||
}
|
||||
bool i_omx_core = false
|
||||
if (encodeer->type == ENCODER_TYPE_OMX) {
|
||||
LOG_INFO("Initializing OMX Core ...");
|
||||
if ((OMX_ERRORTYPE error = OMX_Init()) != OMX_ErrorNone) {
|
||||
LOG_ERROR_OMX(error, "Can't initialize OMX Core");
|
||||
exit_code = -1;
|
||||
goto omx_error;
|
||||
}
|
||||
i_omx_core = true;
|
||||
}
|
||||
# endif
|
||||
|
||||
# ifdef WITH_GPIO
|
||||
gpio_init();
|
||||
# endif
|
||||
@@ -151,6 +174,16 @@ int main(int argc, char *argv[]) {
|
||||
gpio_set_prog_running(false);
|
||||
gpio_destroy();
|
||||
# endif
|
||||
|
||||
# ifdef WITH_OMX
|
||||
omx_error:
|
||||
if (i_omx_core) {
|
||||
OMX_Deinit();
|
||||
}
|
||||
if (i_bcm_host) {
|
||||
bcm_host_deinit();
|
||||
}
|
||||
# endif
|
||||
}
|
||||
|
||||
server_destroy(server);
|
||||
|
||||
Reference in New Issue
Block a user