Skip to content

Commit ba57594

Browse files
committed
v4l2-m2m: support userptr mode
Add userptr buffer mode support for v4l2-m2m. Signed-off-by: niyinghao <niyinghao@xiaomi.com>
1 parent 5c36887 commit ba57594

3 files changed

Lines changed: 80 additions & 0 deletions

File tree

drivers/video/v4l2_m2m.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ static int codec_querybuf(FAR struct file *filep,
352352
FAR codec_mng_t *cmng = inode->i_private;
353353
FAR codec_file_t *cfile = filep->f_priv;
354354
FAR codec_type_inf_t *type_inf;
355+
FAR vbuf_container_t *container;
355356
struct v4l2_format format;
356357
uint32_t offset = 0;
357358
size_t bufsize;
@@ -390,6 +391,8 @@ static int codec_querybuf(FAR struct file *filep,
390391
return -EINVAL;
391392
}
392393

394+
container = video_framebuff_find_container(&type_inf->bufinf, buf->index);
395+
393396
if (V4L2_TYPE_IS_MULTIPLANAR(buf->type))
394397
{
395398
for (i = 0; i < format.fmt.pix_mp.num_planes; i++)
@@ -404,6 +407,11 @@ static int codec_querybuf(FAR struct file *filep,
404407
offset += buf->m.planes[i].length;
405408
break;
406409

410+
case V4L2_MEMORY_USERPTR:
411+
buf->m.planes[i].m.userptr = container ?
412+
container->buf.m.planes[i].m.userptr : 0;
413+
break;
414+
407415
default:
408416
return -EINVAL;
409417
}
@@ -418,6 +426,10 @@ static int codec_querybuf(FAR struct file *filep,
418426
buf->m.offset = offset + bufsize * buf->index;
419427
break;
420428

429+
case V4L2_MEMORY_USERPTR:
430+
buf->m.userptr = container ? container->buf.m.userptr : 0;
431+
break;
432+
421433
default:
422434
return -EINVAL;
423435
}
@@ -483,6 +495,11 @@ static int codec_qbuf(FAR struct file *filep,
483495
offset + type_inf->bufheap);
484496
break;
485497

498+
case V4L2_MEMORY_USERPTR:
499+
container->buf.m.planes[i].m.vaddr =
500+
(FAR void *)buf->m.planes[i].m.userptr;
501+
break;
502+
486503
default:
487504
return -EINVAL;
488505
}
@@ -497,6 +514,10 @@ static int codec_qbuf(FAR struct file *filep,
497514
(FAR void *)(type_inf->bufheap + buf->m.offset - offset);
498515
break;
499516

517+
case V4L2_MEMORY_USERPTR:
518+
container->buf.m.vaddr = (FAR void *)buf->m.userptr;
519+
break;
520+
500521
default:
501522
return -EINVAL;
502523
}
@@ -580,6 +601,11 @@ static int codec_dqbuf(FAR struct file *filep,
580601
type_inf->bufheap + offset);
581602
break;
582603

604+
case V4L2_MEMORY_USERPTR:
605+
buf->m.planes[i].m.userptr = (unsigned long)
606+
buf->m.planes[i].m.vaddr;
607+
break;
608+
583609
default:
584610
return -EINVAL;
585611
}
@@ -594,6 +620,10 @@ static int codec_dqbuf(FAR struct file *filep,
594620
type_inf->bufheap + offset);
595621
break;
596622

623+
case V4L2_MEMORY_USERPTR:
624+
buf->m.userptr = (unsigned long)buf->m.vaddr;
625+
break;
626+
597627
default:
598628
return -EINVAL;
599629
}

drivers/video/video_framebuff.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,3 +289,51 @@ vbuf_container_t *video_framebuff_pop_curr_container(video_framebuff_t *fbuf)
289289
spin_unlock_irqrestore(&fbuf->lock_queue, flags);
290290
return ret;
291291
}
292+
293+
vbuf_container_t *video_framebuff_find_container(video_framebuff_t *fbuf,
294+
uint32_t index)
295+
{
296+
vbuf_container_t *ret = NULL;
297+
vbuf_container_t *curr;
298+
vbuf_container_t *start;
299+
irqstate_t flags;
300+
301+
flags = spin_lock_irqsave(&fbuf->lock_queue);
302+
if (fbuf->vbuf_top != NULL)
303+
{
304+
curr = start = fbuf->vbuf_top;
305+
do
306+
{
307+
if (curr->buf.index == index)
308+
{
309+
ret = curr;
310+
break;
311+
}
312+
313+
curr = curr->next;
314+
}
315+
while (curr != NULL && curr != start);
316+
}
317+
318+
spin_unlock_irqrestore(&fbuf->lock_queue, flags);
319+
320+
if (ret == NULL)
321+
{
322+
nxmutex_lock(&fbuf->lock_empty);
323+
curr = fbuf->vbuf_empty;
324+
while (curr != NULL)
325+
{
326+
if (curr->buf.index == index)
327+
{
328+
ret = curr;
329+
break;
330+
}
331+
332+
curr = curr->next;
333+
}
334+
335+
nxmutex_unlock(&fbuf->lock_empty);
336+
}
337+
338+
return ret;
339+
}

drivers/video/video_framebuff.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,7 @@ void video_framebuff_capture_done
9090
(video_framebuff_t *fbuf);
9191
void video_framebuff_change_mode
9292
(video_framebuff_t *fbuf, enum v4l2_buf_mode mode);
93+
vbuf_container_t *video_framebuff_find_container
94+
(video_framebuff_t *fbuf, uint32_t index);
9395

9496
#endif /* __DRIVERS_VIDEO_VIDEO_FRAMEBUFF_H */

0 commit comments

Comments
 (0)