amlv4l2dec: CB2 config buffer pool issue [1/1]

PD#SWPL-177028

Problem:
config capture buffer pool to negative numbers

Solution:
set min buffer count of other buffer pool to 4

Verify:
ap222

Change-Id: I3a6c8bf1f51f19a6cc2ea9f3500f24f64c7a0c9e
Signed-off-by: fei.deng <fei.deng@amlogic.com>
diff --git a/src/gstamlv4l2bufferpool.c b/src/gstamlv4l2bufferpool.c
index 95af721..6766ac4 100644
--- a/src/gstamlv4l2bufferpool.c
+++ b/src/gstamlv4l2bufferpool.c
@@ -2119,6 +2119,8 @@
             if (outstanding_buf_num != obj->outstanding_buf_num)
             {
                 guint update = 0;
+                GstStructure *config = NULL;
+                guint size, min_buffers = 0, old_max_buffers = 0;
 
                 if (outstanding_buf_num > obj->outstanding_buf_num)
                 {
@@ -2128,7 +2130,20 @@
                 GST_DEBUG_OBJECT(pool, "amlmodbuf oop outstanding buf num from %d reduce to %d", obj->outstanding_buf_num, outstanding_buf_num);
 
                 update = obj->outstanding_buf_num - outstanding_buf_num;
-                if (!gst_buffer_pool_increase_max_num(pool->other_pool, update))
+                /*get buffer pool config to calculate max buffer count*/
+                config = gst_buffer_pool_get_config(pool->other_pool);
+                if (config) { //have outstanding buffer
+                    if (gst_buffer_pool_config_get_params(config, NULL, &size, &min_buffers, &old_max_buffers) != FALSE) {
+                        //obj->min_buffers is driver request min buffers count
+                        int diff = obj->min_buffers - old_max_buffers;
+                        update = diff >= update ? update : diff;
+                        //all outstanding buffers had freed,increase all left buffer
+                        if (outstanding_buf_num == 0) {
+                            update = obj->min_buffers - old_max_buffers;
+                        }
+                    }
+                }
+                if (update > 0 && !gst_buffer_pool_increase_max_num(pool->other_pool, update))
                 {
                     GST_ERROR_OBJECT(pool, "amlmodbuf update other pool max buffer num error");
                     return FALSE;
diff --git a/src/gstamlv4l2object.c b/src/gstamlv4l2object.c
index 225a5a0..de495ab 100644
--- a/src/gstamlv4l2object.c
+++ b/src/gstamlv4l2object.c
@@ -5636,8 +5636,11 @@
         if (obj->old_other_pool || obj->old_old_other_pool) //jxsdbg for switching
         {
             obj->outstanding_buf_num = gst_aml_v4l2_object_get_outstanding_capture_buf_num(obj);
-            other_min = min - obj->outstanding_buf_num;
-            other_max = max - obj->outstanding_buf_num;
+            //when doing resolution changed,set new other buffer pool count to 1
+            //the buffer pool count will increase after buffer released
+            if (obj->outstanding_buf_num > 0) {
+                other_min = other_max = 1;
+            }
             GST_DEBUG_OBJECT(obj, "oop:%p, ooop:%p, outstanding buf num:%d, set min, max to %d,%d",
                              obj->old_other_pool, obj->old_old_other_pool,
                              obj->outstanding_buf_num, other_min, other_max);