From 416c98897b8fe5a8d3aa7b0129251fc3a966537b Mon Sep 17 00:00:00 2001
From: Jeegar Patel <jeegarp@xilinx.com>
Date: Tue, 10 Jan 2017 20:19:59 +0530
Subject: [PATCH 10/24] Handling for dynamic numbers of input buffers

Currently we have assumed OMX i/p buffers will be 2(fixed),
But it can be updated from OMX component. So we should
query OMX component for number of buffers and then
perform OMX_Usebuffer.

Signed-off-by: Jeegar Patel <jeegarp@xilinx.com>
Upstream Status: Pending
---
 omx/gstomxvideodec.c | 26 +++++++++++++++-----------
 omx/gstomxvideoenc.c | 19 ++++++++++++-------
 2 files changed, 27 insertions(+), 18 deletions(-)

diff --git a/omx/gstomxvideodec.c b/omx/gstomxvideodec.c
index 9555701..c45fc3d 100644
--- a/omx/gstomxvideodec.c
+++ b/omx/gstomxvideodec.c
@@ -938,8 +938,8 @@ gst_omx_video_dec_deallocate_output_buffers (GstOMXVideoDec * self)
   }
 #if defined (USE_OMX_TARGET_RPI) && defined (HAVE_GST_GL)
   err =
-      gst_omx_port_deallocate_buffers (self->
-      eglimage ? self->egl_out_port : self->dec_out_port);
+      gst_omx_port_deallocate_buffers (self->eglimage ? self->
+      egl_out_port : self->dec_out_port);
 #else
   err = gst_omx_port_deallocate_buffers (self->dec_out_port);
 #endif
@@ -1336,8 +1336,8 @@ gst_omx_video_dec_loop (GstOMXVideoDec * self)
           OMX_VIDEO_CodingUnused);
 
       format =
-          gst_omx_video_get_format_from_omx (port_def.format.
-          video.eColorFormat);
+          gst_omx_video_get_format_from_omx (port_def.format.video.
+          eColorFormat);
 
       if (format == GST_VIDEO_FORMAT_UNKNOWN) {
         GST_ERROR_OBJECT (self, "Unsupported color format: %d",
@@ -1846,6 +1846,10 @@ gst_omx_video_dec_set_format (GstVideoDecoder * decoder,
   gboolean is_format_change = FALSE;
   gboolean needs_disable = FALSE;
   OMX_PARAM_PORTDEFINITIONTYPE port_def;
+  GList *buffer_list = NULL;
+  GstMapInfo map_info;
+  GstBuffer *mem = NULL;
+  gint i;
 
   self = GST_OMX_VIDEO_DEC (decoder);
   klass = GST_OMX_VIDEO_DEC_GET_CLASS (decoder);
@@ -2063,19 +2067,19 @@ gst_omx_video_dec_set_format (GstVideoDecoder * decoder,
       /* if (gst_omx_port_allocate_buffers (self->dec_in_port) != OMX_ErrorNone)
          return FALSE; */
 
-      GstMapInfo info;
-      GstBuffer *mem = gst_buffer_new_allocate (NULL, 1024, NULL);
-      gst_buffer_map (mem, &info, GST_MAP_READ);
+      mem = gst_buffer_new_allocate (NULL, 1024, NULL);
+      gst_buffer_map (mem, &map_info, GST_MAP_READ);
 
-      GList *buffer_list = NULL;
-      buffer_list = g_list_append (buffer_list, info.data);
-      buffer_list = g_list_append (buffer_list, info.data);
+      gst_omx_port_update_port_definition (self->dec_in_port, NULL);
+
+      for (i = 0; i < self->dec_in_port->port_def.nBufferCountActual; i++)
+        buffer_list = g_list_append (buffer_list, map_info.data);
 
       if (gst_omx_port_use_buffers (self->dec_in_port,
               buffer_list) != OMX_ErrorNone)
         return FALSE;
 
-      gst_buffer_unmap (mem, &info);
+      gst_buffer_unmap (mem, &map_info);
       gst_buffer_unref (mem);
       g_list_free (buffer_list);
 
diff --git a/omx/gstomxvideoenc.c b/omx/gstomxvideoenc.c
index dce886d..516c201 100644
--- a/omx/gstomxvideoenc.c
+++ b/omx/gstomxvideoenc.c
@@ -982,6 +982,11 @@ gst_omx_video_enc_set_format (GstVideoEncoder * encoder,
   OMX_PARAM_PORTDEFINITIONTYPE port_def;
   GstVideoInfo *info = &state->info;
   GList *negotiation_map = NULL, *l;
+  GList *buffer_list = NULL;
+  GstMapInfo map_info;
+  GstBuffer *mem = NULL;
+  gint i;
+
 
   self = GST_OMX_VIDEO_ENC (encoder);
   klass = GST_OMX_VIDEO_ENC_GET_CLASS (encoder);
@@ -1199,19 +1204,19 @@ gst_omx_video_enc_set_format (GstVideoEncoder * encoder,
       /* if (gst_omx_port_allocate_buffers (self->enc_in_port) != OMX_ErrorNone)
          return FALSE; */
 
-      GstMapInfo info;
-      GstBuffer *mem = gst_buffer_new_allocate (NULL, 1024, NULL);
-      gst_buffer_map (mem, &info, GST_MAP_READ);
+      mem = gst_buffer_new_allocate (NULL, 1024, NULL);
+      gst_buffer_map (mem, &map_info, GST_MAP_READ);
+
+      gst_omx_port_update_port_definition (self->enc_in_port, NULL);
 
-      GList *buffer_list = NULL;
-      buffer_list = g_list_append (buffer_list, info.data);
-      buffer_list = g_list_append (buffer_list, info.data);
+      for (i = 0; i < self->enc_in_port->port_def.nBufferCountActual; i++)
+        buffer_list = g_list_append (buffer_list, map_info.data);
 
       if (gst_omx_port_use_buffers (self->enc_in_port,
               buffer_list) != OMX_ErrorNone)
         return FALSE;
 
-      gst_buffer_unmap (mem, &info);
+      gst_buffer_unmap (mem, &map_info);
       gst_buffer_unref (mem);
       g_list_free (buffer_list);
 
-- 
2.7.4

