Skip to contentSkip to conversation

gstreamer1.0-plugins-good: v4l2bufferpool: Set Video Meta to Imported Buffers

PATCH In review Sidraya Jayagond 2 participants 3 messages Feb 22, 2022 – Feb 24, 2022

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 gstreamer1.0-plugins-good: v4l2bufferpool: Set Video Meta to Imported Buffers

From: Sidraya <[email protected]>

When importing dmabufs, the video meta is set on the dest buffer, but not on the src buffer. In this case, the src buffer is not made aware of the stride of the video buffer, which is needed to properly display the buffer.

This is a result of the v4l2 plugin creating it's own empty dmabuf pool of GstBuffers, and then assigning the memory from the downstream GstBuffer. We then update the video meta of the buffer in our pool, but not the downstream pool.

The downstream pool buffer should be updated as well.

---
 ...l-Set-Video-Meta-to-Imported-Buffers.patch | 58 +++++++++++++++++++
 .../gstreamer1.0-plugins-good_1.16.%.bbappend |  1 +
 2 files changed, 59 insertions(+)
 create mode 100644 meta-arago-extras/recipes-multimedia/gstreamer/gstreamer1.0-plugins-good/0001-v4l2bufferpool-Set-Video-Meta-to-Imported-Buffers.patch
meta-arago-extras/recipes-multimedia/gstreamer/gstreamer1.0-plugins-good/0001-v4l2bufferpool-Set-Video-Meta-to-Imported-Buffers.patch new file +58 -0
new file mode 100644
index 00000000..59d9080c
@@ -0,0 +1,58 @@
+From e677028494081f93558d24b1f72da9e6835ef954 Mon Sep 17 00:00:00 2001
+From: Sidraya <[email protected]>
+Date: Mon, 18 Oct 2021 13:35:09 +0530
+Subject: [PATCH] v4l2bufferpool: Set Video Meta to Imported Buffers
+
+When importing dmabufs, the video meta is set on the dest
+buffer, but not on the src buffer. In this case, the src
+buffer is not made aware of the stride of the video buffer,
+which is needed to properly display the buffer.
+
+This is a result of the v4l2 plugin creating it's own
+empty dmabuf pool of GstBuffers, and then assigning the
+memory from the downstream GstBuffer. We then update the
+video meta of the buffer in our pool, but not the downstream
+pool.
+
+The downstream pool buffer should be updated as well.
+
+Upstream-Status: Submitted
+https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1723#note_1266433
+
+Signed-off-by: Sidraya <[email protected]>
+---
+ sys/v4l2/gstv4l2bufferpool.c | 11 +++++++++++
+ 1 file changed, 11 insertions(+)
+
+diff --git a/sys/v4l2/gstv4l2bufferpool.c b/sys/v4l2/gstv4l2bufferpool.c
+index 49f222b6e..f4d964b9e 100644
+--- a/sys/v4l2/gstv4l2bufferpool.c
++++ b/sys/v4l2/gstv4l2bufferpool.c
+@@ -330,6 +330,10 @@ gst_v4l2_buffer_pool_import_dmabuf (GstV4l2BufferPool * pool,
+   GstMemory *dma_mem[GST_VIDEO_MAX_PLANES] = { 0 };
+   guint n_mem = gst_buffer_n_memory (src);
+   gint i;
++  GstV4l2Object *obj;
++  GstVideoInfo *info;
++  obj = pool->obj;
++  info = &obj->info;
+ 
+   GST_LOG_OBJECT (pool, "importing dmabuf");
+ 
+@@ -346,6 +350,13 @@ gst_v4l2_buffer_pool_import_dmabuf (GstV4l2BufferPool * pool,
+           dma_mem))
+     goto import_failed;
+ 
++  /* add metadata to raw video buffers */
++  if (pool->add_videometa)
++    gst_buffer_add_video_meta_full (src, GST_VIDEO_FRAME_FLAG_NONE,
++        GST_VIDEO_INFO_FORMAT (info), GST_VIDEO_INFO_WIDTH (info),
++        GST_VIDEO_INFO_HEIGHT (info), GST_VIDEO_INFO_N_PLANES (info),
++        info->offset, info->stride);
++
+   gst_mini_object_set_qdata (GST_MINI_OBJECT (dest), GST_V4L2_IMPORT_QUARK,
+       gst_buffer_ref (src), (GDestroyNotify) gst_buffer_unref);
+ 
+-- 
+2.17.1
+
meta-arago-extras/recipes-multimedia/gstreamer/gstreamer1.0-plugins-good_1.16.%.bbappend +1 -0
index 11513f2f..07cd08a7 100644
@@ -10,6 +10,7 @@ SRC_URI += " \
     file://0001-qmlglsink-fix-build-on-EGL-platform-without-X11-head.patch \
     file://0001-gst-plugins-good-1.16.3-v4l2h264enc-Add-Extended-con.patch \
     file://0001-Avoiding-Failure-to-allocate-required-memory.patch \
+    file://0001-v4l2bufferpool-Set-Video-Meta-to-Imported-Buffers.patch \
 "
 
 PR_append = ".arago3"
Signature · 30 lines
2.17.1


-- 






This
message contains confidential information and is intended only 
for the
individual(s) named. If you are not the intended
recipient, you are 
notified that disclosing, copying, distributing or taking any
action in 
reliance on the contents of this mail and attached file/s is strictly
prohibited. Please notify the
sender immediately and delete this e-mail 
from your system. E-mail transmission
cannot be guaranteed to be secured or 
error-free as information could be
intercepted, corrupted, lost, destroyed, 
arrive late or incomplete, or contain
viruses. The sender therefore does 
not accept liability for any errors or
omissions in the contents of this 
message, which arise as a result of e-mail
transmission.
#1 lore raw

Thanks. From OE/meta-arago perspective this patch now looks good. But from gstreamer perspective I cannot judge the change as I don't have enough expertise there. Can you please follow up on your submission to upstream gstreamer, as the maintainer there has some questions? Thanks!

Signature · 1 line
Denys
Quoted 100 lines · Sidraya Jayagond via lists.yoctoproject.org

From: Sidraya <[email protected]>

When importing dmabufs, the video meta is set on the dest buffer, but not on the src buffer. In this case, the src buffer is not made aware of the stride of the video buffer, which is needed to properly display the buffer.

This is a result of the v4l2 plugin creating it's own empty dmabuf pool of GstBuffers, and then assigning the memory from the downstream GstBuffer. We then update the video meta of the buffer in our pool, but not the downstream pool.

The downstream pool buffer should be updated as well.

---
 ...l-Set-Video-Meta-to-Imported-Buffers.patch | 58 +++++++++++++++++++
 .../gstreamer1.0-plugins-good_1.16.%.bbappend |  1 +
 2 files changed, 59 insertions(+)
 create mode 100644 meta-arago-extras/recipes-multimedia/gstreamer/gstreamer1.0-plugins-good/0001-v4l2bufferpool-Set-Video-Meta-to-Imported-Buffers.patch
meta-arago-extras/recipes-multimedia/gstreamer/gstreamer1.0-plugins-good/0001-v4l2bufferpool-Set-Video-Meta-to-Imported-Buffers.patch new file +58 -0
new file mode 100644
index 00000000..59d9080c
@@ -0,0 +1,58 @@
+From e677028494081f93558d24b1f72da9e6835ef954 Mon Sep 17 00:00:00 2001
+From: Sidraya <[email protected]>
+Date: Mon, 18 Oct 2021 13:35:09 +0530
+Subject: [PATCH] v4l2bufferpool: Set Video Meta to Imported Buffers
+
+When importing dmabufs, the video meta is set on the dest
+buffer, but not on the src buffer. In this case, the src
+buffer is not made aware of the stride of the video buffer,
+which is needed to properly display the buffer.
+
+This is a result of the v4l2 plugin creating it's own
+empty dmabuf pool of GstBuffers, and then assigning the
+memory from the downstream GstBuffer. We then update the
+video meta of the buffer in our pool, but not the downstream
+pool.
+
+The downstream pool buffer should be updated as well.
+
+Upstream-Status: Submitted
+https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1723#note_1266433
+
+Signed-off-by: Sidraya <[email protected]>
+---
+ sys/v4l2/gstv4l2bufferpool.c | 11 +++++++++++
+ 1 file changed, 11 insertions(+)
+
+diff --git a/sys/v4l2/gstv4l2bufferpool.c b/sys/v4l2/gstv4l2bufferpool.c
+index 49f222b6e..f4d964b9e 100644
+--- a/sys/v4l2/gstv4l2bufferpool.c
++++ b/sys/v4l2/gstv4l2bufferpool.c
+@@ -330,6 +330,10 @@ gst_v4l2_buffer_pool_import_dmabuf (GstV4l2BufferPool * pool,
+   GstMemory *dma_mem[GST_VIDEO_MAX_PLANES] = { 0 };
+   guint n_mem = gst_buffer_n_memory (src);
+   gint i;
++  GstV4l2Object *obj;
++  GstVideoInfo *info;
++  obj = pool->obj;
++  info = &obj->info;
+ 
+   GST_LOG_OBJECT (pool, "importing dmabuf");
+ 
+@@ -346,6 +350,13 @@ gst_v4l2_buffer_pool_import_dmabuf (GstV4l2BufferPool * pool,
+           dma_mem))
+     goto import_failed;
+ 
++  /* add metadata to raw video buffers */
++  if (pool->add_videometa)
++    gst_buffer_add_video_meta_full (src, GST_VIDEO_FRAME_FLAG_NONE,
++        GST_VIDEO_INFO_FORMAT (info), GST_VIDEO_INFO_WIDTH (info),
++        GST_VIDEO_INFO_HEIGHT (info), GST_VIDEO_INFO_N_PLANES (info),
++        info->offset, info->stride);
++
+   gst_mini_object_set_qdata (GST_MINI_OBJECT (dest), GST_V4L2_IMPORT_QUARK,
+       gst_buffer_ref (src), (GDestroyNotify) gst_buffer_unref);
+ 
+-- 
+2.17.1
+
meta-arago-extras/recipes-multimedia/gstreamer/gstreamer1.0-plugins-good_1.16.%.bbappend +1 -0
index 11513f2f..07cd08a7 100644
@@ -10,6 +10,7 @@ SRC_URI += " \
     file://0001-qmlglsink-fix-build-on-EGL-platform-without-X11-head.patch \
     file://0001-gst-plugins-good-1.16.3-v4l2h264enc-Add-Extended-con.patch \
     file://0001-Avoiding-Failure-to-allocate-required-memory.patch \
+    file://0001-v4l2bufferpool-Set-Video-Meta-to-Imported-Buffers.patch \
 "
 
 PR_append = ".arago3"
Signature · 1 line
2.17.1
#2 lore raw
Quoted 8 lines · Denys Dmytriyenko

Thanks. From OE/meta-arago perspective this patch now looks good. But from gstreamer perspective I cannot judge the change as I don't have enough expertise there. Can you please follow up on your submission to upstream gstreamer, as the maintainer there has some questions? Thanks!

Signature · 1 line
Denys

Sure, I will respond to open source community questions.

Quoted 107 lines · Sidraya Jayagond via lists.yoctoproject.org
Quoted 100 lines

From: Sidraya <[email protected]>

When importing dmabufs, the video meta is set on the dest buffer, but not on the src buffer. In this case, the src buffer is not made aware of the stride of the video buffer, which is needed to properly display the buffer.

This is a result of the v4l2 plugin creating it's own empty dmabuf pool of GstBuffers, and then assigning the memory from the downstream GstBuffer. We then update the video meta of the buffer in our pool, but not the downstream pool.

The downstream pool buffer should be updated as well.

---
 ...l-Set-Video-Meta-to-Imported-Buffers.patch | 58 +++++++++++++++++++
 .../gstreamer1.0-plugins-good_1.16.%.bbappend |  1 +
 2 files changed, 59 insertions(+)
 create mode 100644 meta-arago-extras/recipes-multimedia/gstreamer/gstreamer1.0-plugins-good/0001-v4l2bufferpool-Set-Video-Meta-to-Imported-Buffers.patch
meta-arago-extras/recipes-multimedia/gstreamer/gstreamer1.0-plugins-good/0001-v4l2bufferpool-Set-Video-Meta-to-Imported-Buffers.patch new file +58 -0
new file mode 100644
index 00000000..59d9080c
@@ -0,0 +1,58 @@
+From e677028494081f93558d24b1f72da9e6835ef954 Mon Sep 17 00:00:00 2001
+From: Sidraya <[email protected]>
+Date: Mon, 18 Oct 2021 13:35:09 +0530
+Subject: [PATCH] v4l2bufferpool: Set Video Meta to Imported Buffers
+
+When importing dmabufs, the video meta is set on the dest
+buffer, but not on the src buffer. In this case, the src
+buffer is not made aware of the stride of the video buffer,
+which is needed to properly display the buffer.
+
+This is a result of the v4l2 plugin creating it's own
+empty dmabuf pool of GstBuffers, and then assigning the
+memory from the downstream GstBuffer. We then update the
+video meta of the buffer in our pool, but not the downstream
+pool.
+
+The downstream pool buffer should be updated as well.
+
+Upstream-Status: Submitted
+https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1723#note_1266433
+
+Signed-off-by: Sidraya <[email protected]>
+---
+ sys/v4l2/gstv4l2bufferpool.c | 11 +++++++++++
+ 1 file changed, 11 insertions(+)
+
+diff --git a/sys/v4l2/gstv4l2bufferpool.c b/sys/v4l2/gstv4l2bufferpool.c
+index 49f222b6e..f4d964b9e 100644
+--- a/sys/v4l2/gstv4l2bufferpool.c
++++ b/sys/v4l2/gstv4l2bufferpool.c
+@@ -330,6 +330,10 @@ gst_v4l2_buffer_pool_import_dmabuf (GstV4l2BufferPool * pool,
+   GstMemory *dma_mem[GST_VIDEO_MAX_PLANES] = { 0 };
+   guint n_mem = gst_buffer_n_memory (src);
+   gint i;
++  GstV4l2Object *obj;
++  GstVideoInfo *info;
++  obj = pool->obj;
++  info = &obj->info;
+ 
+   GST_LOG_OBJECT (pool, "importing dmabuf");
+ 
+@@ -346,6 +350,13 @@ gst_v4l2_buffer_pool_import_dmabuf (GstV4l2BufferPool * pool,
+           dma_mem))
+     goto import_failed;
+ 
++  /* add metadata to raw video buffers */
++  if (pool->add_videometa)
++    gst_buffer_add_video_meta_full (src, GST_VIDEO_FRAME_FLAG_NONE,
++        GST_VIDEO_INFO_FORMAT (info), GST_VIDEO_INFO_WIDTH (info),
++        GST_VIDEO_INFO_HEIGHT (info), GST_VIDEO_INFO_N_PLANES (info),
++        info->offset, info->stride);
++
+   gst_mini_object_set_qdata (GST_MINI_OBJECT (dest), GST_V4L2_IMPORT_QUARK,
+       gst_buffer_ref (src), (GDestroyNotify) gst_buffer_unref);
+ 
+-- 
+2.17.1
+
meta-arago-extras/recipes-multimedia/gstreamer/gstreamer1.0-plugins-good_1.16.%.bbappend +1 -0
index 11513f2f..07cd08a7 100644
@@ -10,6 +10,7 @@ SRC_URI += " \
     file://0001-qmlglsink-fix-build-on-EGL-platform-without-X11-head.patch \
     file://0001-gst-plugins-good-1.16.3-v4l2h264enc-Add-Extended-con.patch \
     file://0001-Avoiding-Failure-to-allocate-required-memory.patch \
+    file://0001-v4l2bufferpool-Set-Video-Meta-to-Imported-Buffers.patch \
 "
 
 PR_append = ".arago3"
Signature · 1 line
2.17.1
Signature · 20 lines
This
message contains confidential information and is intended only 
for the
individual(s) named. If you are not the intended
recipient, you are 
notified that disclosing, copying, distributing or taking any
action in 
reliance on the contents of this mail and attached file/s is strictly
prohibited. Please notify the
sender immediately and delete this e-mail 
from your system. E-mail transmission
cannot be guaranteed to be secured or 
error-free as information could be
intercepted, corrupted, lost, destroyed, 
arrive late or incomplete, or contain
viruses. The sender therefore does 
not accept liability for any errors or
omissions in the contents of this 
message, which arise as a result of e-mail
transmission.