Skip to content

Commit 8240958

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 598238c commit 8240958

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;
@@ -391,6 +392,8 @@ static int codec_querybuf(FAR struct file *filep,
391392
return -EINVAL;
392393
}
393394

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

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

430+
case V4L2_MEMORY_USERPTR:
431+
buf->m.userptr = container ? container->buf.m.userptr : 0;
432+
break;
433+
422434
default:
423435
return -EINVAL;
424436
}
@@ -485,6 +497,11 @@ static int codec_qbuf(FAR struct file *filep,
485497
offset + type_inf->bufheap);
486498
break;
487499

500+
case V4L2_MEMORY_USERPTR:
501+
container->buf.m.planes[i].m.vaddr =
502+
(FAR void *)buf->m.planes[i].m.userptr;
503+
break;
504+
488505
default:
489506
return -EINVAL;
490507
}
@@ -499,6 +516,10 @@ static int codec_qbuf(FAR struct file *filep,
499516
(FAR void *)(type_inf->bufheap + buf->m.offset - offset);
500517
break;
501518

519+
case V4L2_MEMORY_USERPTR:
520+
container->buf.m.vaddr = (FAR void *)buf->m.userptr;
521+
break;
522+
502523
default:
503524
return -EINVAL;
504525
}
@@ -583,6 +604,11 @@ static int codec_dqbuf(FAR struct file *filep,
583604
type_inf->bufheap + offset);
584605
break;
585606

607+
case V4L2_MEMORY_USERPTR:
608+
buf->m.planes[i].m.userptr = (unsigned long)
609+
buf->m.planes[i].m.vaddr;
610+
break;
611+
586612
default:
587613
return -EINVAL;
588614
}
@@ -597,6 +623,10 @@ static int codec_dqbuf(FAR struct file *filep,
597623
type_inf->bufheap + offset);
598624
break;
599625

626+
case V4L2_MEMORY_USERPTR:
627+
buf->m.userptr = (unsigned long)buf->m.vaddr;
628+
break;
629+
600630
default:
601631
return -EINVAL;
602632
}

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)