summaryrefslogtreecommitdiffstats
path: root/meta-arago-extras/recipes-multimedia/gstreamer/gstreamer1.0-plugins-good/0001-v4l2-Changes-for-DMA-Buf-import-j721s2.patch
blob: a1471661380ed5c799ba2b5874e27d3b18db6b54 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
From b9727b08f69649a2ec58055b4fb1d40c094ba8d0 Mon Sep 17 00:00:00 2001
From: Prasanth Babu Mantena <p-mantena@ti.com>
Date: Wed, 7 Jun 2023 18:24:55 +0530
Subject: [PATCH] v4l2: Changes for DMA Buf import j721s2

Add checks to release the buffer to downstream pool when returned with
error flag from the driver. This buffer which registered with driver is
used a an offset buffer without any new allocation in downstram pool.
Set buffer offset to ref_frames plus 3. Added check for buffer
allocations that are applied only for wave5 driver. v4l2src which uses
the buffer pool objects uses the default allocations.

Signed-off-by: Prasanth Babu Mantena <p-mantena@ti.com>
---
 sys/v4l2/gstv4l2bufferpool.c | 17 ++++++++++++++---
 sys/v4l2/gstv4l2bufferpool.h |  2 ++
 sys/v4l2/gstv4l2object.c     | 15 ++++++++++++---
 sys/v4l2/gstv4l2videodec.c   | 20 ++++++++++++++------
 4 files changed, 42 insertions(+), 12 deletions(-)

diff --git a/sys/v4l2/gstv4l2bufferpool.c b/sys/v4l2/gstv4l2bufferpool.c
index d85f036..e6a60dc 100644
--- a/sys/v4l2/gstv4l2bufferpool.c
+++ b/sys/v4l2/gstv4l2bufferpool.c
@@ -83,7 +83,7 @@ enum _GstV4l2BufferState
 static void gst_v4l2_buffer_pool_complete_release_buffer (GstBufferPool * bpool,
     GstBuffer * buffer, gboolean queued);

-static gboolean
+gboolean
 gst_v4l2_is_buffer_valid (GstBuffer * buffer, GstV4l2MemoryGroup ** out_group)
 {
   GstMemory *mem = gst_buffer_peek_memory (buffer, 0);
@@ -1638,11 +1638,22 @@ gst_v4l2_buffer_pool_complete_release_buffer (GstBufferPool * bpool,
             gst_v4l2_allocator_reset_group (pool->vallocator, group);
             /* queue back in the device */
             if (pool->other_pool)
-              ret = gst_v4l2_buffer_pool_prepare_buffer (pool, buffer, NULL);
-            if (ret != GST_FLOW_OK ||
+	    {
+	      if(!(group->buffer.flags & V4L2_BUF_FLAG_ERROR))
+	              ret = gst_v4l2_buffer_pool_prepare_buffer (pool, buffer, NULL);
+	    }
+            if(!(group->buffer.flags & V4L2_BUF_FLAG_ERROR)) {
+	    if (ret != GST_FLOW_OK ||
                 gst_v4l2_buffer_pool_qbuf (pool, buffer, group,
                     NULL) != GST_FLOW_OK)
               pclass->release_buffer (bpool, buffer);
+	    }
+	    else
+	    {
+                GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_TAG_MEMORY);
+                pclass->release_buffer (bpool, buffer);
+
+	    }
           } else {
             /* Simply release invalid/modified buffer, the allocator will
              * give it back later */
diff --git a/sys/v4l2/gstv4l2bufferpool.h b/sys/v4l2/gstv4l2bufferpool.h
index 60340c2..cec4207 100644
--- a/sys/v4l2/gstv4l2bufferpool.h
+++ b/sys/v4l2/gstv4l2bufferpool.h
@@ -124,6 +124,8 @@ gboolean            gst_v4l2_buffer_pool_orphan  (GstV4l2Object * v4l2object);

 void                gst_v4l2_buffer_pool_enable_resolution_change (GstV4l2BufferPool *self);

+gboolean            gst_v4l2_is_buffer_valid (GstBuffer * buffer, GstV4l2MemoryGroup ** out_group);
+
 G_END_DECLS

 #endif /*__GST_V4L2_BUFFER_POOL_H__ */
diff --git a/sys/v4l2/gstv4l2object.c b/sys/v4l2/gstv4l2object.c
index ee60540..eff1cf2 100644
--- a/sys/v4l2/gstv4l2object.c
+++ b/sys/v4l2/gstv4l2object.c
@@ -5040,7 +5040,11 @@ gst_v4l2_object_decide_allocation (GstV4l2Object * obj, GstQuery * query)
   } else {
     /* In this case we'll have to configure two buffer pool. For our buffer
      * pool, we'll need what the driver one, and one more, so we can dequeu */
-    own_min = obj->min_buffers + 1;
+    if (0 == strcmp(obj->vcap.driver, "wave5-dec")) {
+        own_min = obj->min_buffers + 3;
+    } else {
+        own_min = obj->min_buffers + 1;
+    }
     own_min = MAX (own_min, GST_V4L2_MIN_BUFFERS (obj));

     /* for the downstream pool, we keep what downstream wants, though ensure
@@ -5049,8 +5053,13 @@ gst_v4l2_object_decide_allocation (GstV4l2Object * obj, GstQuery * query)
     min = MAX (min, GST_V4L2_MIN_BUFFERS (obj));

     /* To import we need the other pool to hold at least own_min */
-    if (obj_pool == pool)
-      min += own_min;
+    if (obj_pool == pool) {
+        if (0 == strcmp(obj->vcap.driver, "wave5-dec")) {
+            min = own_min;
+        } else {
+            min += own_min;
+        }
+    }
   }

   /* Request a bigger max, if one was suggested but it's too small */
diff --git a/sys/v4l2/gstv4l2videodec.c b/sys/v4l2/gstv4l2videodec.c
index 3042995..0e4ac09 100644
--- a/sys/v4l2/gstv4l2videodec.c
+++ b/sys/v4l2/gstv4l2videodec.c
@@ -536,6 +536,8 @@ gst_v4l2_video_dec_loop (GstVideoDecoder * decoder)
   GstVideoCodecFrame *frame;
   GstBuffer *buffer = NULL;
   GstFlowReturn ret;
+  GstV4l2MemoryGroup *group;
+  int buffer_valid=0;

   GST_LOG_OBJECT (decoder, "Allocate output buffer");

@@ -558,6 +560,7 @@ gst_v4l2_video_dec_loop (GstVideoDecoder * decoder)

     if (ret != GST_FLOW_OK)
       goto beach;
+    buffer_valid = gst_v4l2_is_buffer_valid (buffer, &group);

     GST_LOG_OBJECT (decoder, "Process output buffer");
     {
@@ -602,13 +605,18 @@ gst_v4l2_video_dec_loop (GstVideoDecoder * decoder)
     if (oldest_frame)
       gst_video_codec_frame_unref (oldest_frame);

-    frame->duration = self->v4l2capture->duration;
-    frame->output_buffer = buffer;
-    buffer = NULL;
-    ret = gst_video_decoder_finish_frame (decoder, frame);
+    if(!(buffer_valid && (group->buffer.flags & V4L2_BUF_FLAG_ERROR))) {
+	       frame->duration = self->v4l2capture->duration;
+               frame->output_buffer = buffer;
+               buffer = NULL;
+               ret = gst_video_decoder_finish_frame (decoder, frame);
+               if (ret != GST_FLOW_OK)
+                       goto beach;
+       }
+       else {
+               gst_buffer_unref (buffer);
+       }

-    if (ret != GST_FLOW_OK)
-      goto beach;
   } else {
     GST_WARNING_OBJECT (decoder, "Decoder is producing too many buffers");
     gst_buffer_unref (buffer);
--
2.39.0