From eLinux.org
< R-Car
Revision as of 04:10, 15 November 2017 by Laurent.pinchart (talk | contribs) (Fix formatting of the dmabuf-sharing example)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This page describes how to use the dmabuf-sharing application to test buffer sharing between V4L2 and DRM/KMS drivers.

Setting up dmabuf-sharing


The dmabuf-sharing application requires libdrm to be present both on the target system and in the build environment.

Getting the source code

The upstream git tree for the dmabuf-sharing application is git://linuxtv.org/snawrocki/samsung-utils.git. The cloned tree git://git.ideasonboard.org/samsung-utils.git contains one required additional patch to select the exporter.

The application is located in the v4l2-drm-example directory.

Building dmabuf-sharing

To compile the application, run make with the following variables set:

  • CROSS_COMPILE should be set to the cross-compilation prefix of your compiler (e.g. CROSS_COMPILE=aarch64-buildroot-linux-gnu-)
  • LIBDRM_DIR should be set to the root of a directory tree that contains the libdrm headers and libraries (e.g. LIBDRM_DIR=$HOME/src/buildroot/output/arm64/staging/)
  • KDIR should be set to the root of a directory tree that contains the installed kernel headers (e.g. KDIR=$HOME/src/kernel/ after running make headers_install in that directory)

Patching the kernel

The examples below capture frames in 640x480 resolution to ensure maximum compatibility with different displays. That resolution is unfortunately not supported by the vivid driver by default, and requires the following patch to be applied.

commit 0510bc9bd6177c10c2adfe5764bfbee09def94e6
Author: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Date:   Mon Nov 13 05:49:01 2017 +0200

    [HACK] vivid: Accept 640x480 resolution
    This allows displaying the virtual video full screen with a 640x480
    resolution. The closest resolution supported by vivid, 640x360, is not
    widely supported by displays.

diff --git a/drivers/media/platform/vivid/vivid-vid-cap.c b/drivers/media/platform/vivid/vivid-vid-cap.c
index 01419455e545..c620ea0fe3a9 100644
--- a/drivers/media/platform/vivid/vivid-vid-cap.c
+++ b/drivers/media/platform/vivid/vivid-vid-cap.c
@@ -63,7 +63,7 @@ static const struct vivid_fmt formats_ovl[] = {
 /* The number of discrete webcam framesizes */
 /* The number of discrete webcam frameintervals */
@@ -71,6 +71,7 @@ static const struct vivid_fmt formats_ovl[] = {
 static const struct v4l2_frmsize_discrete webcam_sizes[VIVID_WEBCAM_SIZES] = {
 	{  320, 180 },
 	{  640, 360 },
+	{  640, 480 },
 	{ 1280, 720 },
 	{ 1920, 1080 },
 	{ 3840, 2160 },

Using dmabuf-sharing

dmabuf-sharing sources frames from a V4L2 device and pushes them to a DRM/KMS device. It shares buffers between the two devices using dma-buf to achieve zero-copy operation. In the examples below we will use the vivid driver as a frame source to avoid depending on a particular video capture hardware. The command lines assume that the vivid device is accessible through /dev/video0. If other V4L2 devices exist in the system the device node might need to be changed.

V4L2 as an exporter

The following example captures frames in 640x480 resolution from vivid and displays them full screen on the R-Car DU. The -o parameter takes the IDs of the VGA connector and the associated CRTC. You might need to change the values depending on the target system. The modest application (part of libdrm) can be used to list available connectors and CRTCs and retrieve their IDs.

$ dmabuf-sharing -i /dev/video0 -f YUYV -S 640,480 -s 640,480@0,0 \
          -M rcar-du -o 70:68:640x480 -F YUYV -t 640,480@0,0 \
          -b 4 -e v4l2