diff --git a/arch/sim/src/Makefile b/arch/sim/src/Makefile index dd1b10677c..a135e9042e 100644 --- a/arch/sim/src/Makefile +++ b/arch/sim/src/Makefile @@ -256,9 +256,9 @@ ifeq ($(CONFIG_SIM_VIDEO_DECODER),y) endif ifeq ($(CONFIG_SIM_VIDEO_ENCODER),y) - HOSTSRCS += sim_hostencoder.c CSRCS += sim_encoder.c - STDLIBS += -lx264 + CSRCS += sim_x264encoder.c + CFLAGS += -D_STDINT_H endif COBJS = $(CSRCS:.c=$(OBJEXT)) diff --git a/arch/sim/src/sim/CMakeLists.txt b/arch/sim/src/sim/CMakeLists.txt index 8d52f2012c..06d2d98b96 100644 --- a/arch/sim/src/sim/CMakeLists.txt +++ b/arch/sim/src/sim/CMakeLists.txt @@ -161,9 +161,8 @@ if(CONFIG_SIM_VIDEO_DECODER) endif() if(CONFIG_SIM_VIDEO_ENCODER) - list(APPEND HOSTSRCS sim_hostencoder.c) list(APPEND SRCS sim_encoder.c) - list(APPEND STDLIBS x264) + list(APPEND SRCS sim_x264encoder.c) endif() if(CONFIG_SPINLOCK) diff --git a/arch/sim/src/sim/sim_encoder.c b/arch/sim/src/sim/sim_encoder.c index bf3b417637..ae8e931fa0 100644 --- a/arch/sim/src/sim/sim_encoder.c +++ b/arch/sim/src/sim/sim_encoder.c @@ -27,7 +27,7 @@ #include #include -#include "sim_hostencoder.h" +#include "sim_x264encoder.h" #include "sim_internal.h" /**************************************************************************** @@ -42,7 +42,7 @@ struct sim_encoder_s { - struct host_encoder_s *encoder; + struct x264_wrapper_s *encoder; struct v4l2_format output_fmt; struct v4l2_format capture_fmt; struct work_s work; @@ -140,7 +140,7 @@ static struct codec_s g_sim_codec_encoder = static int sim_encoder_open(void *cookie, void **priv) { sim_encoder_t *sim_encoder; - struct host_encoder_s *encoder; + struct x264_wrapper_s *encoder; sim_encoder = kmm_zalloc(sizeof(struct sim_encoder_s)); if (sim_encoder == NULL) @@ -148,7 +148,7 @@ static int sim_encoder_open(void *cookie, void **priv) return -ENOMEM; } - encoder = host_encoder_open(); + encoder = x264_wrapper_open(); if (encoder == NULL) { kmm_free(sim_encoder); @@ -166,7 +166,7 @@ static int sim_encoder_close(void *priv) { sim_encoder_t *sim_encoder = priv; - host_encoder_close(sim_encoder->encoder); + x264_wrapper_close(sim_encoder->encoder); kmm_free(sim_encoder); return 0; @@ -187,7 +187,7 @@ static int sim_encoder_output_streamon(void *priv) { sim_encoder_t *sim_encoder = priv; - return host_encoder_streamon(sim_encoder->encoder, + return x264_wrapper_streamon(sim_encoder->encoder, sim_encoder->output_fmt.fmt.pix.width, sim_encoder->output_fmt.fmt.pix.height, sim_encoder->fps ? sim_encoder->fps : 30, @@ -227,7 +227,7 @@ static int sim_encoder_capture_streamoff(void *priv) sim_encoder_t *sim_encoder = priv; sim_encoder->capture_on = false; - return host_encoder_streamoff(sim_encoder->encoder); + return x264_wrapper_streamoff(sim_encoder->encoder); } static int sim_encoder_output_streamoff(void *priv) @@ -475,7 +475,7 @@ static int sim_encoder_process(sim_encoder_t *sim_encoder, src_buf->timestamp.tv_usec; } - ret = host_encoder_enqueue(sim_encoder->encoder, + ret = x264_wrapper_enqueue(sim_encoder->encoder, src_data, src_size, src_pts); if (ret >= 0 && src_buf != NULL) { @@ -487,7 +487,7 @@ static int sim_encoder_process(sim_encoder_t *sim_encoder, return ret; } - ret = host_encoder_dequeue(sim_encoder->encoder, + ret = x264_wrapper_dequeue(sim_encoder->encoder, (uint8_t *)dst_buf->m.userptr, &dst_buf->bytesused, &dst_pts, diff --git a/arch/sim/src/sim/sim_hostencoder.c b/arch/sim/src/sim/sim_x264encoder.c similarity index 70% rename from arch/sim/src/sim/sim_hostencoder.c rename to arch/sim/src/sim/sim_x264encoder.c index a7810f456e..7ea3891148 100644 --- a/arch/sim/src/sim/sim_hostencoder.c +++ b/arch/sim/src/sim/sim_x264encoder.c @@ -1,5 +1,5 @@ /**************************************************************************** - * arch/sim/src/sim/sim_hostencoder.c + * arch/sim/src/sim/sim_x264encoder.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -30,14 +30,13 @@ #include #include -#include "sim_hostencoder.h" -#include "sim_internal.h" +#include "sim_x264encoder.h" /**************************************************************************** * Private Types ****************************************************************************/ -struct host_encoder_s +struct x264_wrapper_s { x264_t *enc_ctx; x264_picture_t pic_in; @@ -52,28 +51,27 @@ struct host_encoder_s * Public Functions ****************************************************************************/ -struct host_encoder_s *host_encoder_open(void) +struct x264_wrapper_s *x264_wrapper_open(void) { - return calloc(1, sizeof(struct host_encoder_s)); + return calloc(1, sizeof(struct x264_wrapper_s)); } -int host_encoder_close(struct host_encoder_s *encoder) +int x264_wrapper_close(struct x264_wrapper_s *encoder) { free(encoder); return 0; } -int host_encoder_streamon(struct host_encoder_s *encoder, +int x264_wrapper_streamon(struct x264_wrapper_s *encoder, int width, int height, int fps, int bframe) { int ret; memset(&encoder->param, 0, sizeof(x264_param_t)); - ret = host_uninterruptible(x264_param_default_preset, - &encoder->param, - "fast", - "zerolatency"); + ret = x264_param_default_preset(&encoder->param, + "fast", + "zerolatency"); if (ret < 0) { return ret; @@ -89,37 +87,35 @@ int host_encoder_streamon(struct host_encoder_s *encoder, encoder->param.i_keyint_min = 25; encoder->param.i_bframe = bframe; - ret = host_uninterruptible(x264_picture_alloc, - &encoder->pic_in, - X264_CSP_I420, - width, - height); + ret = x264_picture_alloc(&encoder->pic_in, + X264_CSP_I420, + width, + height); if (ret < 0) { return ret; } - encoder->enc_ctx = host_uninterruptible(x264_encoder_open, - &encoder->param); + encoder->enc_ctx = x264_encoder_open(&encoder->param); if (!encoder->enc_ctx) { - host_uninterruptible_no_return(x264_picture_clean, &encoder->pic_in); + x264_picture_clean(&encoder->pic_in); return -EINVAL; } return 0; } -int host_encoder_streamoff(struct host_encoder_s *encoder) +int x264_wrapper_streamoff(struct x264_wrapper_s *encoder) { - host_uninterruptible_no_return(x264_encoder_close, encoder->enc_ctx); - host_uninterruptible_no_return(x264_picture_clean, &encoder->pic_in); + x264_encoder_close(encoder->enc_ctx); + x264_picture_clean(&encoder->pic_in); encoder->remaining_frames = 0; return 0; } -int host_encoder_enqueue(struct host_encoder_s *encoder, +int x264_wrapper_enqueue(struct x264_wrapper_s *encoder, uint8_t *data, uint32_t size, int64_t pts) { int ret; @@ -137,18 +133,16 @@ int host_encoder_enqueue(struct host_encoder_s *encoder, width * height / 4); } - ret = host_uninterruptible(x264_encoder_encode, - encoder->enc_ctx, - &encoder->nal, - &encoder->i_nal, - (data != NULL ? &encoder->pic_in : NULL), - &encoder->pic_out); + ret = x264_encoder_encode(encoder->enc_ctx, + &encoder->nal, + &encoder->i_nal, + (data != NULL ? &encoder->pic_in : NULL), + &encoder->pic_out); if (data == NULL) { encoder->remaining_frames = - host_uninterruptible(x264_encoder_delayed_frames, - encoder->enc_ctx); + x264_encoder_delayed_frames(encoder->enc_ctx); } if (ret >= 0) @@ -159,7 +153,7 @@ int host_encoder_enqueue(struct host_encoder_s *encoder, return ret; } -int host_encoder_dequeue(struct host_encoder_s *encoder, +int x264_wrapper_dequeue(struct x264_wrapper_s *encoder, uint8_t *data, uint32_t *size, int64_t *pts, uint32_t *flags) { diff --git a/arch/sim/src/sim/sim_hostencoder.h b/arch/sim/src/sim/sim_x264encoder.h similarity index 76% rename from arch/sim/src/sim/sim_hostencoder.h rename to arch/sim/src/sim/sim_x264encoder.h index fa02da4226..a7a023452c 100644 --- a/arch/sim/src/sim/sim_hostencoder.h +++ b/arch/sim/src/sim/sim_x264encoder.h @@ -1,5 +1,5 @@ /**************************************************************************** - * arch/sim/src/sim/sim_hostencoder.h + * arch/sim/src/sim/sim_x264encoder.h * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -18,8 +18,8 @@ * ****************************************************************************/ -#ifndef __ARCH_SIM_SRC_SIM_SIM_HOSTENCODER_H -#define __ARCH_SIM_SRC_SIM_SIM_HOSTENCODER_H +#ifndef __ARCH_SIM_SRC_SIM_SIM_X264ENCODER_H +#define __ARCH_SIM_SRC_SIM_SIM_X264ENCODER_H /**************************************************************************** * Included Files @@ -31,21 +31,21 @@ * Public Types ****************************************************************************/ -struct host_encoder_s; +struct x264_wrapper_s; /**************************************************************************** * Public Function Prototypes ****************************************************************************/ -struct host_encoder_s *host_encoder_open(void); -int host_encoder_close(struct host_encoder_s *encoder); -int host_encoder_streamon(struct host_encoder_s *encoder, +struct x264_wrapper_s *x264_wrapper_open(void); +int x264_wrapper_close(struct x264_wrapper_s *encoder); +int x264_wrapper_streamon(struct x264_wrapper_s *encoder, int width, int height, int fps, int bframe); -int host_encoder_streamoff(struct host_encoder_s *encoder); -int host_encoder_enqueue(struct host_encoder_s *encoder, +int x264_wrapper_streamoff(struct x264_wrapper_s *encoder); +int x264_wrapper_enqueue(struct x264_wrapper_s *encoder, uint8_t *data, uint32_t size, int64_t pts); -int host_encoder_dequeue(struct host_encoder_s *encoder, +int x264_wrapper_dequeue(struct x264_wrapper_s *encoder, uint8_t *data, uint32_t *size, int64_t *pts, uint32_t *flags); -#endif /* __ARCH_SIM_SRC_SIM_SIM_HOSTENCODER_H */ +#endif /* __ARCH_SIM_SRC_SIM_SIM_X264ENCODER_H */