Open taylorchu opened 6 months ago
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#define H264E_ENABLE_PLAIN_C 1
#define MINIH264_IMPLEMENTATION
#include "minih264e.h"
typedef struct Encoder {
H264E_create_param_t create_param;
H264E_persist_t *enc;
H264E_scratch_t *scratch;
} Encoder;
#define ALIGNED_ALLOC(n, size) aligned_alloc(n, (size + n - 1) / n * n)
int enc_new(Encoder **out) {
H264E_create_param_t create_param;
memset(&create_param, 0, sizeof(create_param));
int sizeof_persist = 0, sizeof_scratch = 0;
if (H264E_sizeof(&create_param, &sizeof_persist, &sizeof_scratch) != 0) {
return 1001;
}
H264E_persist_t *enc = (H264E_persist_t *)ALIGNED_ALLOC(64, sizeof_persist);
H264E_scratch_t *scratch =
(H264E_scratch_t *)ALIGNED_ALLOC(64, sizeof_scratch);
if (H264E_init(enc, &create_param) != 0) {
return 1002;
}
Encoder *e = (Encoder *)calloc(1, sizeof(Encoder));
e->create_param = create_param;
e->enc = enc;
e->scratch = scratch;
*out = e;
return 0;
}
int enc_encode(Encoder *e, uint8_t *y, uint8_t *cb, uint8_t *cr, void **out,
int *out_size) {
H264E_io_yuv_t yuv;
memset(&yuv, 0, sizeof(yuv));
yuv.yuv[0] = y;
yuv.stride[0] = e->create_param.width;
yuv.yuv[1] = cb;
yuv.stride[1] = e->create_param.width / 2;
yuv.yuv[2] = cr;
yuv.stride[2] = e->create_param.width / 2;
H264E_run_param_t run_param;
memset(&run_param, 0, sizeof(run_param));
if (H264E_encode(e->enc, e->scratch, &run_param, &yuv, (unsigned char **)out,
out_size) != 0) {
return 2001;
}
return 0;
}
void enc_close(Encoder *e) {
free(e->enc);
free(e->scratch);
free(e);
}
incompatible type 'uint8x8_t'