Skip to contentSkip to conversation

Add V4L stateless video decoder API support to NVIDIA Tegra driver

PATCH Superseded Dmitry Osipenko 4 participants 10 messages Feb 7, 2022 – Feb 18, 2022

Subsystems (3)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v3 cover Add V4L stateless video decoder API support to NVIDIA Tegra driver

Support V4L stateless video decoder API by NVIDIA Tegra decoder driver. Tested using GStreamer [1] and libvdpau-tegra [2][8].

[1] https://github.com/grate-driver/gstreamer/commit/b8509bdbb69b534e61419ea1798f32f9ad2f3597
[2] https://github.com/grate-driver/libvdpau-tegra/commit/f822e95911e5e0c39f8ba19f843ddc1e0138d5ce
[8] https://github.com/grate-driver/libvdpau-tegra/commit/80db4d02369f2a984ce3173d6bc305f32e9fdb97

Changelog:

v3: - Added new decode_params flags [7] instead of V4L2_BUF_FLAG_*FRAME flags,
as was suggested by Nicolas Dufresne.

[7] https://github.com/grate-driver/gstreamer/commit/c5cd847f9c26b7669720ae58f9058de2515f51a2

- Added new patch that removes legacy UAPI.

v2: - Made V4L2_BUF_FLAG_*FRAME flags mandatory [3] and dropped reading
of raw bitstream from the driver code, as was suggested by Nicolas Dufresne.

[3] https://github.com/grate-driver/gstreamer/commit/aee292f0f2e84b7654a314dd7e63f916888ffaa5

- Ran v4l2-compliance [4] and fluster [5][6] tests, like was suggested by Nicolas Dufresne. Fixed minor v4l2-compliance errors that were related to a partial initialization of the coded format and were harmless in practice, but made compliance checker unhappy.

[4] https://gist.github.com/digetx/5d6bcdab633488f1dcc7c141ab90d30e
[5] https://gist.github.com/digetx/b06c5d779e9d25afa41d9f46946fe399
[6] https://gist.github.com/digetx/ac4198bc340e5065aa8ec3288bb21356

Dmitry Osipenko (4):
media: v4l2-ctrls: Add new V4L2_H264_DECODE_PARAM_FLAG_P/BFRAME flags
media: staging: tegra-vde: Factor out H.264 code
media: staging: tegra-vde: Support V4L stateless video decoder API
media: staging: tegra-vde: Remove legacy UAPI support

 .../media/v4l/ext-ctrls-codec-stateless.rst   |    6 +
 drivers/staging/media/tegra-vde/Kconfig       |    7 +
 drivers/staging/media/tegra-vde/Makefile      |    2 +-
 .../staging/media/tegra-vde/dmabuf-cache.c    |    2 +-
 drivers/staging/media/tegra-vde/h264.c        |  946 +++++++++++++++
 drivers/staging/media/tegra-vde/iommu.c       |    2 +-
 drivers/staging/media/tegra-vde/uapi.h        |   73 --
 drivers/staging/media/tegra-vde/v4l2.c        | 1018 +++++++++++++++++
 drivers/staging/media/tegra-vde/vde.c         |  945 ++-------------
 drivers/staging/media/tegra-vde/vde.h         |  121 +-
 include/uapi/linux/v4l2-controls.h            |    2 +
 11 files changed, 2170 insertions(+), 954 deletions(-)
 create mode 100644 drivers/staging/media/tegra-vde/h264.c
 delete mode 100644 drivers/staging/media/tegra-vde/uapi.h
 create mode 100644 drivers/staging/media/tegra-vde/v4l2.c
Signature · 1 line
2.34.1
#1 lore raw

PATCH v3 1/4 media: v4l2-ctrls: Add new V4L2_H264_DECODE_PARAM_FLAG_P/BFRAME flags

Add new V4L2_H264_DECODE_PARAM_FLAG_P/BFRAME flags that are needed by NVIDIA Tegra video decoder. Userspace will have to set these flags in accordance to the type of a decoded frame.

---
 .../userspace-api/media/v4l/ext-ctrls-codec-stateless.rst   | 6 ++++++
 include/uapi/linux/v4l2-controls.h                          | 2 ++
 2 files changed, 8 insertions(+)
Documentation/userspace-api/media/v4l/ext-ctrls-codec-stateless.rst +6 -0
index cc080c4257d0..f87584ad90ba 100644
@@ -616,6 +616,12 @@ Stateless Codec Control ID
     * - ``V4L2_H264_DECODE_PARAM_FLAG_BOTTOM_FIELD``
       - 0x00000004
       -
+    * - ``V4L2_H264_DECODE_PARAM_FLAG_PFRAME``
+      - 0x00000008
+      -
+    * - ``V4L2_H264_DECODE_PARAM_FLAG_BFRAME``
+      - 0x00000010
+      -
 
 .. raw:: latex
 
include/uapi/linux/v4l2-controls.h +2 -0
index c8e0f84d204d..e3d48d571062 100644
@@ -1563,6 +1563,8 @@ struct v4l2_h264_dpb_entry {
 #define V4L2_H264_DECODE_PARAM_FLAG_IDR_PIC		0x01
 #define V4L2_H264_DECODE_PARAM_FLAG_FIELD_PIC		0x02
 #define V4L2_H264_DECODE_PARAM_FLAG_BOTTOM_FIELD	0x04
+#define V4L2_H264_DECODE_PARAM_FLAG_PFRAME		0x08
+#define V4L2_H264_DECODE_PARAM_FLAG_BFRAME		0x10
 
 #define V4L2_CID_STATELESS_H264_DECODE_PARAMS	(V4L2_CID_CODEC_STATELESS_BASE + 7)
 /**
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH v3 1/4] media: v4l2-ctrls: Add new V4L2_H264_DECODE_PARAM_FLAG_P/BFRAME flags

Le lundi 07 février 2022 à 17:19 +0300, Dmitry Osipenko a écrit :

Quoted 6 lines

Add new V4L2_H264_DECODE_PARAM_FLAG_P/BFRAME flags that are needed by NVIDIA Tegra video decoder. Userspace will have to set these flags in accordance to the type of a decoded frame.

---

Can you share here (out of commit) a userland implementation that was used to demonstrate the new API ? It does not matter which project (GStreamer, FFMPEG, Chromium, your_test_progtram). Should be fairly straightforward. This is just to be transparent.

Quoted 26 lines
 .../userspace-api/media/v4l/ext-ctrls-codec-stateless.rst   | 6 ++++++
 include/uapi/linux/v4l2-controls.h                          | 2 ++
 2 files changed, 8 insertions(+)
Documentation/userspace-api/media/v4l/ext-ctrls-codec-stateless.rst +6 -0
index cc080c4257d0..f87584ad90ba 100644
@@ -616,6 +616,12 @@ Stateless Codec Control ID
     * - ``V4L2_H264_DECODE_PARAM_FLAG_BOTTOM_FIELD``
       - 0x00000004
       -
+    * - ``V4L2_H264_DECODE_PARAM_FLAG_PFRAME``
+      - 0x00000008
+      -
+    * - ``V4L2_H264_DECODE_PARAM_FLAG_BFRAME``
+      - 0x00000010
+      -
 
 .. raw:: latex
 
include/uapi/linux/v4l2-controls.h +0 -0
index c8e0f84d204d..e3d48d571062 100644

include/uapi/linux/v4l2-controls.h struct v4l2_h264_dpb_entry { · line 1570

Quoted 8 lines
include/uapi/linux/v4l2-controls.h +2 -0
@@ -1563,6 +1563,8 @@ struct v4l2_h264_dpb_entry {
 #define V4L2_H264_DECODE_PARAM_FLAG_IDR_PIC		0x01
 #define V4L2_H264_DECODE_PARAM_FLAG_FIELD_PIC		0x02
 #define V4L2_H264_DECODE_PARAM_FLAG_BOTTOM_FIELD	0x04
+#define V4L2_H264_DECODE_PARAM_FLAG_PFRAME		0x08
+#define V4L2_H264_DECODE_PARAM_FLAG_BFRAME		0x10
 
 #define V4L2_CID_STATELESS_H264_DECODE_PARAMS	(V4L2_CID_CODEC_STATELESS_BASE + 7)
 /**

Please update the doc too, see:
Documentation/userspace-api/media/v4l/ext-ctrls-codec-stateless.rst:

#3 lore raw

Re: [PATCH v3 1/4] media: v4l2-ctrls: Add new V4L2_H264_DECODE_PARAM_FLAG_P/BFRAME flags

11.02.2022 16:29, Nicolas Dufresne пишет:

Quoted 5 lines

Le lundi 07 février 2022 à 17:19 +0300, Dmitry Osipenko a écrit :

Quoted 4 lines

Add new V4L2_H264_DECODE_PARAM_FLAG_P/BFRAME flags that are needed by NVIDIA Tegra video decoder. Userspace will have to set these flags in accordance to the type of a decoded frame.

Quoted 7 lines
Quoted 2 lines

---

Can you share here (out of commit) a userland implementation that was used to demonstrate the new API ? It does not matter which project (GStreamer, FFMPEG, Chromium, your_test_progtram). Should be fairly straightforward. This is just to be transparent.

You may find all the links in the cover letter, please see the grate-driver's GStreamer [1] and libvdpau-tegra [2]:

[1] https://github.com/grate-driver/gstreamer/commits/main
[2] https://github.com/grate-driver/libvdpau-tegra/commits/master

Reviewed-by on v3 1/4
#4 lore raw

Re: [PATCH v3 1/4] media: v4l2-ctrls: Add new V4L2_H264_DECODE_PARAM_FLAG_P/BFRAME flags

In reply to Dmitry Osipenko

Le lundi 07 février 2022 à 17:19 +0300, Dmitry Osipenko a écrit :

Quoted 5 lines

Add new V4L2_H264_DECODE_PARAM_FLAG_P/BFRAME flags that are needed by NVIDIA Tegra video decoder. Userspace will have to set these flags in accordance to the type of a decoded frame.

Quoted 35 lines
---
 .../userspace-api/media/v4l/ext-ctrls-codec-stateless.rst   | 6 ++++++
 include/uapi/linux/v4l2-controls.h                          | 2 ++
 2 files changed, 8 insertions(+)
Documentation/userspace-api/media/v4l/ext-ctrls-codec-stateless.rst +6 -0
index cc080c4257d0..f87584ad90ba 100644
@@ -616,6 +616,12 @@ Stateless Codec Control ID
     * - ``V4L2_H264_DECODE_PARAM_FLAG_BOTTOM_FIELD``
       - 0x00000004
       -
+    * - ``V4L2_H264_DECODE_PARAM_FLAG_PFRAME``
+      - 0x00000008
+      -
+    * - ``V4L2_H264_DECODE_PARAM_FLAG_BFRAME``
+      - 0x00000010
+      -
 
 .. raw:: latex
 
include/uapi/linux/v4l2-controls.h +2 -0
index c8e0f84d204d..e3d48d571062 100644
@@ -1563,6 +1563,8 @@ struct v4l2_h264_dpb_entry {
 #define V4L2_H264_DECODE_PARAM_FLAG_IDR_PIC		0x01
 #define V4L2_H264_DECODE_PARAM_FLAG_FIELD_PIC		0x02
 #define V4L2_H264_DECODE_PARAM_FLAG_BOTTOM_FIELD	0x04
+#define V4L2_H264_DECODE_PARAM_FLAG_PFRAME		0x08
+#define V4L2_H264_DECODE_PARAM_FLAG_BFRAME		0x10
 
 #define V4L2_CID_STATELESS_H264_DECODE_PARAMS	(V4L2_CID_CODEC_STATELESS_BASE + 7)
 /**
#5 lore raw

PATCH v3 2/4 media: staging: tegra-vde: Factor out H.264 code

In reply to Dmitry Osipenko

Factor out H.264 hardware programming code into separate source file in a preparation to support V4L API by the Tegra video decoder driver.

---
 drivers/staging/media/tegra-vde/Makefile |   2 +-
 drivers/staging/media/tegra-vde/h264.c   | 647 +++++++++++++++++++++++
 drivers/staging/media/tegra-vde/vde.c    | 626 +---------------------
 drivers/staging/media/tegra-vde/vde.h    |  42 ++
 4 files changed, 706 insertions(+), 611 deletions(-)
 create mode 100644 drivers/staging/media/tegra-vde/h264.c
drivers/staging/media/tegra-vde/Makefile +1 -1
index 2827f7601de8..43525b08b3b0 100644
@@ -1,3 +1,3 @@
 # SPDX-License-Identifier: GPL-2.0
-tegra-vde-y := vde.o iommu.o dmabuf-cache.o
+tegra-vde-y := vde.o iommu.o dmabuf-cache.o h264.o
 obj-$(CONFIG_TEGRA_VDE)	+= tegra-vde.o
drivers/staging/media/tegra-vde/h264.c new file +647 -0

647 lines not on this page · raw message

drivers/staging/media/tegra-vde/vde.c +16 -610

709 lines not on this page · raw message

drivers/staging/media/tegra-vde/vde.h +42 -0

70 lines not on this page · raw message

Signature · 1 line
2.34.1
#6 lore raw

PATCH v3 3/4 media: staging: tegra-vde: Support V4L stateless video decoder API

In reply to Dmitry Osipenko

Expose Tegra video decoder as a generic V4L M2M stateless video decoder.

---
 drivers/staging/media/tegra-vde/Kconfig  |    7 +
 drivers/staging/media/tegra-vde/Makefile |    2 +-
 drivers/staging/media/tegra-vde/h264.c   |  304 ++++++-
 drivers/staging/media/tegra-vde/v4l2.c   | 1018 ++++++++++++++++++++++
 drivers/staging/media/tegra-vde/vde.c    |   74 +-
 drivers/staging/media/tegra-vde/vde.h    |   86 ++
 6 files changed, 1483 insertions(+), 8 deletions(-)
 create mode 100644 drivers/staging/media/tegra-vde/v4l2.c
drivers/staging/media/tegra-vde/Kconfig +7 -0
index 0dc78afd09e0..07dbc1f44ca8 100644
@@ -2,9 +2,16 @@
 config TEGRA_VDE
 	tristate "NVIDIA Tegra Video Decoder Engine driver"
 	depends on ARCH_TEGRA || COMPILE_TEST
+	depends on VIDEO_DEV && VIDEO_V4L2
 	select DMA_SHARED_BUFFER
 	select IOMMU_IOVA
+	select MEDIA_CONTROLLER
+	select MEDIA_CONTROLLER_REQUEST_API
 	select SRAM
+	select VIDEOBUF2_DMA_CONTIG
+	select VIDEOBUF2_DMA_SG
+	select V4L2_H264
+	select V4L2_MEM2MEM_DEV
 	help
 	    Say Y here to enable support for the NVIDIA Tegra video decoder
 	    driver.
drivers/staging/media/tegra-vde/Makefile +1 -1
index 43525b08b3b0..1758aa201baa 100644
@@ -1,3 +1,3 @@
 # SPDX-License-Identifier: GPL-2.0
-tegra-vde-y := vde.o iommu.o dmabuf-cache.o h264.o
+tegra-vde-y := vde.o iommu.o dmabuf-cache.o h264.o v4l2.o
 obj-$(CONFIG_TEGRA_VDE)	+= tegra-vde.o
drivers/staging/media/tegra-vde/h264.c +302 -2

323 lines not on this page · raw message

drivers/staging/media/tegra-vde/v4l2.c new file +1018 -0

1,018 lines not on this page · raw message

drivers/staging/media/tegra-vde/vde.c +69 -5

126 lines not on this page · raw message

drivers/staging/media/tegra-vde/vde.h +86 -0

129 lines not on this page · raw message

Signature · 1 line
2.34.1
#7 lore raw

PATCH v3 4/4 media: staging: tegra-vde: Remove legacy UAPI support

In reply to Dmitry Osipenko

The legacy UAPI became unnecessary with the V4L stateless decoder API support addition to the Tegra decoder driver. Remove legacy UAPI support.

---
 .../staging/media/tegra-vde/dmabuf-cache.c    |   2 +-
 drivers/staging/media/tegra-vde/h264.c        |  61 ++--
 drivers/staging/media/tegra-vde/iommu.c       |   2 +-
 drivers/staging/media/tegra-vde/uapi.h        |  73 -----
 drivers/staging/media/tegra-vde/vde.c         | 283 +-----------------
 drivers/staging/media/tegra-vde/vde.h         |  11 -
 6 files changed, 35 insertions(+), 397 deletions(-)
 delete mode 100644 drivers/staging/media/tegra-vde/uapi.h
drivers/staging/media/tegra-vde/dmabuf-cache.c +1 -1
index a98d03419b8f..69c346148070 100644
@@ -66,9 +66,9 @@ int tegra_vde_dmabuf_cache_map(struct tegra_vde *vde,
 			       struct dma_buf_attachment **ap,
 			       dma_addr_t *addrp)
 {
-	struct device *dev = vde->miscdev.parent;
 	struct dma_buf_attachment *attachment;
 	struct tegra_vde_cache_entry *entry;
+	struct device *dev = vde->dev;
 	struct sg_table *sgt;
 	struct iova *iova;
 	int err;
drivers/staging/media/tegra-vde/h264.c +30 -31

81 lines not on this page · raw message

drivers/staging/media/tegra-vde/iommu.c +1 -1
index adf8dc7ee25c..5521ed3e465f 100644
@@ -60,7 +60,7 @@ void tegra_vde_iommu_unmap(struct tegra_vde *vde, struct iova *iova)
 
 int tegra_vde_iommu_init(struct tegra_vde *vde)
 {
-	struct device *dev = vde->miscdev.parent;
+	struct device *dev = vde->dev;
 	struct iova *iova;
 	unsigned long order;
 	unsigned long shift;
drivers/staging/media/tegra-vde/uapi.h deleted +0 -73

73 lines not on this page · raw message

drivers/staging/media/tegra-vde/vde.c +3 -280

338 lines not on this page · raw message

drivers/staging/media/tegra-vde/vde.h +0 -11
index e0396bb0b986..0fbb1f3d2c88 100644
@@ -12,7 +12,6 @@
 #include <linux/dma-direction.h>
 #include <linux/iova.h>
 #include <linux/list.h>
-#include <linux/miscdevice.h>
 #include <linux/mutex.h>
 #include <linux/types.h>
 #include <linux/workqueue.h>
@@ -107,7 +106,6 @@ struct tegra_vde {
 	struct mutex lock;
 	struct mutex map_lock;
 	struct list_head map_list;
-	struct miscdevice miscdev;
 	struct reset_control *rst;
 	struct reset_control *rst_mc;
 	struct gen_pool *iram_pool;
@@ -183,15 +181,6 @@ u32 tegra_vde_readl(struct tegra_vde *vde, void __iomem *base, u32 offset);
 void tegra_vde_set_bits(struct tegra_vde *vde, u32 mask, void __iomem *base,
 			u32 offset);
 
-int tegra_vde_validate_h264_frame(struct device *dev,
-				  struct tegra_vde_h264_frame *frame);
-int tegra_vde_validate_h264_ctx(struct device *dev,
-				struct tegra_vde_h264_decoder_ctx *ctx);
-int tegra_vde_decode_h264(struct tegra_vde *vde,
-			  struct tegra_vde_h264_decoder_ctx *ctx,
-			  struct tegra_video_frame *dpb_frames,
-			  dma_addr_t bitstream_data_addr,
-			  size_t bitstream_data_size);
 int tegra_vde_h264_decode_run(struct tegra_ctx *ctx);
 int tegra_vde_h264_decode_wait(struct tegra_ctx *ctx);
 
Signature · 1 line
2.34.1
#8 lore raw
In reply to Dmitry Osipenko

Dmitry,

Quoted 6 lines · Dmitry Osipenko

Support V4L stateless video decoder API by NVIDIA Tegra decoder driver. Tested using GStreamer [1] and libvdpau-tegra [2][8].

[1] https://github.com/grate-driver/gstreamer/commit/b8509bdbb69b534e61419ea1798f32f9ad2f3597
[2] https://github.com/grate-driver/libvdpau-tegra/commit/f822e95911e5e0c39f8ba19f843ddc1e0138d5ce
[8] https://github.com/grate-driver/libvdpau-tegra/commit/80db4d02369f2a984ce3173d6bc305f32e9fdb97

Nice work!

Can you make a v4 that just moves the whole driver to drivers/media/platform? I see no reason for keeping this in staging.

Once I have a v4 that does that I plan to make a PR for it.

For the v4 don't forget to update MAINTAINERS with the new path and to drop the TODO file in staging.

Regards,

Hans

Quoted 47 lines

Changelog:

v3: - Added new decode_params flags [7] instead of V4L2_BUF_FLAG_*FRAME flags,
as was suggested by Nicolas Dufresne.

[7] https://github.com/grate-driver/gstreamer/commit/c5cd847f9c26b7669720ae58f9058de2515f51a2

- Added new patch that removes legacy UAPI.

v2: - Made V4L2_BUF_FLAG_*FRAME flags mandatory [3] and dropped reading
of raw bitstream from the driver code, as was suggested by Nicolas Dufresne.

[3] https://github.com/grate-driver/gstreamer/commit/aee292f0f2e84b7654a314dd7e63f916888ffaa5

- Ran v4l2-compliance [4] and fluster [5][6] tests, like was suggested by Nicolas Dufresne. Fixed minor v4l2-compliance errors that were related to a partial initialization of the coded format and were harmless in practice, but made compliance checker unhappy.

[4] https://gist.github.com/digetx/5d6bcdab633488f1dcc7c141ab90d30e
[5] https://gist.github.com/digetx/b06c5d779e9d25afa41d9f46946fe399
[6] https://gist.github.com/digetx/ac4198bc340e5065aa8ec3288bb21356

Dmitry Osipenko (4):
media: v4l2-ctrls: Add new V4L2_H264_DECODE_PARAM_FLAG_P/BFRAME flags
media: staging: tegra-vde: Factor out H.264 code
media: staging: tegra-vde: Support V4L stateless video decoder API
media: staging: tegra-vde: Remove legacy UAPI support

 .../media/v4l/ext-ctrls-codec-stateless.rst   |    6 +
 drivers/staging/media/tegra-vde/Kconfig       |    7 +
 drivers/staging/media/tegra-vde/Makefile      |    2 +-
 .../staging/media/tegra-vde/dmabuf-cache.c    |    2 +-
 drivers/staging/media/tegra-vde/h264.c        |  946 +++++++++++++++
 drivers/staging/media/tegra-vde/iommu.c       |    2 +-
 drivers/staging/media/tegra-vde/uapi.h        |   73 --
 drivers/staging/media/tegra-vde/v4l2.c        | 1018 +++++++++++++++++
 drivers/staging/media/tegra-vde/vde.c         |  945 ++-------------
 drivers/staging/media/tegra-vde/vde.h         |  121 +-
 include/uapi/linux/v4l2-controls.h            |    2 +
 11 files changed, 2170 insertions(+), 954 deletions(-)
 create mode 100644 drivers/staging/media/tegra-vde/h264.c
 delete mode 100644 drivers/staging/media/tegra-vde/uapi.h
 create mode 100644 drivers/staging/media/tegra-vde/v4l2.c
#9 lore raw

18.02.2022 18:04, Hans Verkuil пишет:

Quoted 11 lines

Dmitry,

Quoted 6 lines · Dmitry Osipenko

Support V4L stateless video decoder API by NVIDIA Tegra decoder driver. Tested using GStreamer [1] and libvdpau-tegra [2][8].

[1] https://github.com/grate-driver/gstreamer/commit/b8509bdbb69b534e61419ea1798f32f9ad2f3597
[2] https://github.com/grate-driver/libvdpau-tegra/commit/f822e95911e5e0c39f8ba19f843ddc1e0138d5ce
[8] https://github.com/grate-driver/libvdpau-tegra/commit/80db4d02369f2a984ce3173d6bc305f32e9fdb97

Nice work!

Quoted 7 lines

Can you make a v4 that just moves the whole driver to drivers/media/platform? I see no reason for keeping this in staging.

Once I have a v4 that does that I plan to make a PR for it.

For the v4 don't forget to update MAINTAINERS with the new path and to drop the TODO file in staging.

I'll prepare v4 over the weekend, thanks to you and Nicolas.