drivers: video: Fix video buffer alignment
k_mem_pool_malloc reserves some space for block descriptor at the start of the data block, causing misalignement of returned video buffer. In our context we want to return a video buffer with aligment matching the video buffer poll alignment config. Fix that by using the simpler k_mem_pool_alloc function. Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
This commit is contained in:
parent
55894dde58
commit
199ccba5e4
1 changed files with 17 additions and 3 deletions
|
@ -14,16 +14,19 @@ K_MEM_POOL_DEFINE(video_buffer_pool,
|
|||
CONFIG_VIDEO_BUFFER_POOL_ALIGN);
|
||||
|
||||
static struct video_buffer video_buf[CONFIG_VIDEO_BUFFER_POOL_NUM_MAX];
|
||||
static struct k_mem_block video_block[CONFIG_VIDEO_BUFFER_POOL_NUM_MAX];
|
||||
|
||||
struct video_buffer *video_buffer_alloc(size_t size)
|
||||
{
|
||||
struct video_buffer *vbuf = NULL;
|
||||
struct k_mem_block *block;
|
||||
int i;
|
||||
|
||||
/* find available video buffer */
|
||||
for (i = 0; i < ARRAY_SIZE(video_buf); i++) {
|
||||
if (video_buf[i].buffer == NULL) {
|
||||
vbuf = &video_buf[i];
|
||||
block = &video_block[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -33,11 +36,11 @@ struct video_buffer *video_buffer_alloc(size_t size)
|
|||
}
|
||||
|
||||
/* Alloc buffer memory */
|
||||
vbuf->buffer = k_mem_pool_malloc(&video_buffer_pool, size);
|
||||
if (vbuf->buffer == NULL) {
|
||||
if (k_mem_pool_alloc(&video_buffer_pool, block, size, K_FOREVER)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
vbuf->buffer = block->data;
|
||||
vbuf->size = size;
|
||||
vbuf->bytesused = 0;
|
||||
|
||||
|
@ -46,6 +49,17 @@ struct video_buffer *video_buffer_alloc(size_t size)
|
|||
|
||||
void video_buffer_release(struct video_buffer *vbuf)
|
||||
{
|
||||
k_free(vbuf->buffer);
|
||||
struct k_mem_block *block = NULL;
|
||||
int i;
|
||||
|
||||
/* vbuf to block */
|
||||
for (i = 0; i < ARRAY_SIZE(video_buf); i++) {
|
||||
if (video_block[i].data == vbuf->buffer) {
|
||||
block = &video_block[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
vbuf->buffer = NULL;
|
||||
k_mem_pool_free(block);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue