h264-v4l2m2m: Align buffer size up to nearest multiple of 16

h264-v4l2m2m
Andri Yngvason 2024-03-16 17:30:41 +00:00
parent 87b308f15f
commit 6d8645d6e9
1 changed files with 5 additions and 3 deletions

View File

@ -13,8 +13,10 @@
#include <drm_fourcc.h> #include <drm_fourcc.h>
#include <gbm.h> #include <gbm.h>
#include <aml.h> #include <aml.h>
#include <dirent.h>
#define UDIV_UP(a, b) (((a) + (b) - 1) / (b)) #define UDIV_UP(a, b) (((a) + (b) - 1) / (b))
#define ALIGN_UP(a, b) ((b) * UDIV_UP((a), (b)))
#define ARRAY_LENGTH(a) (sizeof(a) / sizeof((a)[0])) #define ARRAY_LENGTH(a) (sizeof(a) / sizeof((a)[0]))
#define N_SRC_BUFS 3 #define N_SRC_BUFS 3
@ -221,8 +223,8 @@ static int set_src_fmt(struct h264_encoder_v4l2m2m* self)
struct v4l2_pix_format_mplane* pix_fmt = &fmt.fmt.pix_mp; struct v4l2_pix_format_mplane* pix_fmt = &fmt.fmt.pix_mp;
pix_fmt->pixelformat = format; pix_fmt->pixelformat = format;
pix_fmt->width = self->width; pix_fmt->width = ALIGN_UP(self->width, 16);
pix_fmt->height = self->height; pix_fmt->height = ALIGN_UP(self->height, 16);
rc = ioctl(self->fd, VIDIOC_S_FMT, &fmt); rc = ioctl(self->fd, VIDIOC_S_FMT, &fmt);
if (rc < 0) { if (rc < 0) {
@ -466,7 +468,7 @@ static void encode_buffer(struct h264_encoder_v4l2m2m* self,
int n_planes = gbm_bo_get_plane_count(bo); int n_planes = gbm_bo_get_plane_count(bo);
int fd = gbm_bo_get_fd(bo); int fd = gbm_bo_get_fd(bo);
uint32_t height = gbm_bo_get_height(bo); uint32_t height = ALIGN_UP(gbm_bo_get_height(bo), 16);
for (int i = 0; i < n_planes; ++i) { for (int i = 0; i < n_planes; ++i) {
uint32_t stride = gbm_bo_get_stride_for_plane(bo, i); uint32_t stride = gbm_bo_get_stride_for_plane(bo, i);