From f89e23326d8e93aadc1f6c637b9aeca9b4aa5a04 Mon Sep 17 00:00:00 2001
From: Devarsh Thakkar <devarsht@xilinx.com>
Date: Mon, 26 Sep 2016 16:19:42 +0530
Subject: [PATCH 07/24] Add support for hw related properties of OMX IL

This adds support for following properties :
1. DMA bufpool enable/disable
2. Bypass mode enable/disable
3. MCU mode enable/disable

Signed-off-by: Devarsh Thakkar <devarsht@xilinx.com>
Upstream Status: Pending
---
 omx/gstomxvideodec.c       | 31 ++++++++++++++++++++++++++++++
 omx/gstomxvideoenc.c       | 30 +++++++++++++++++++++++++++++
 omx/openmax/OMX_VideoExt.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 109 insertions(+)

diff --git a/omx/gstomxvideodec.c b/omx/gstomxvideodec.c
index 8590301..8598376 100644
--- a/omx/gstomxvideodec.c
+++ b/omx/gstomxvideodec.c
@@ -150,6 +150,14 @@ gst_omx_video_dec_open (GstVideoDecoder * decoder)
   GstOMXVideoDecClass *klass = GST_OMX_VIDEO_DEC_GET_CLASS (self);
   gint in_port_index, out_port_index;
 
+#ifdef USE_OMX_TARGET_ZYNQ_USCALE_PLUS
+  OMX_INDEXTYPE type, DMAtype, MCUtype;
+  OMX_VIDEO_PARAM_ENABLEBOARD enable_board;
+  OMX_VIDEO_PARAM_ENABLEDMABUFFER enable_dmabuf;
+  OMX_VIDEO_PARAM_ENABLEMCU enable_mcu;
+  static int use_dmabuf = 0, use_mcu = 1, use_board = 0;
+#endif
+
   GST_DEBUG_OBJECT (self, "Opening decoder");
 
   self->dec =
@@ -193,6 +201,29 @@ gst_omx_video_dec_open (GstVideoDecoder * decoder)
   self->dec_in_port = gst_omx_component_add_port (self->dec, in_port_index);
   self->dec_out_port = gst_omx_component_add_port (self->dec, out_port_index);
 
+#ifdef USE_OMX_TARGET_ZYNQ_USCALE_PLUS
+  GST_INFO_OBJECT (self, "Custom settings needed for zynq VCU");
+  OMX_GetExtensionIndex (self->dec->handle,
+      (OMX_STRING) "OMX.allegro.enableBoard", &type);
+  memset (&enable_board, 0, sizeof (enable_board));
+  enable_board.bEnable = use_board;
+  OMX_SetParameter (self->dec->handle, type, &enable_board);
+
+  OMX_GetExtensionIndex (self->dec->handle,
+      (OMX_STRING) "OMX.allegro.linux.enableDMA", &DMAtype);
+
+  memset (&enable_dmabuf, 0, sizeof (enable_dmabuf));
+  enable_dmabuf.bEnable = (OMX_BOOL) use_dmabuf;
+  OMX_SetParameter (self->dec->handle, DMAtype, &enable_dmabuf);
+
+  OMX_GetExtensionIndex (self->dec->handle,
+      (OMX_STRING) "OMX.allegro.enableMCU", &MCUtype);
+  memset (&enable_mcu, 0, sizeof (enable_mcu));
+  enable_mcu.bEnable = (OMX_BOOL) use_mcu;
+  OMX_SetParameter (self->dec->handle, MCUtype, &enable_mcu);
+#endif
+
+
   if (!self->dec_in_port || !self->dec_out_port)
     return FALSE;
 
diff --git a/omx/gstomxvideoenc.c b/omx/gstomxvideoenc.c
index 0f64a02..35f5fb0 100644
--- a/omx/gstomxvideoenc.c
+++ b/omx/gstomxvideoenc.c
@@ -209,6 +209,14 @@ gst_omx_video_enc_open (GstVideoEncoder * encoder)
   GstOMXVideoEncClass *klass = GST_OMX_VIDEO_ENC_GET_CLASS (self);
   gint in_port_index, out_port_index;
 
+#ifdef USE_OMX_TARGET_ZYNQ_USCALE_PLUS
+  OMX_INDEXTYPE type, DMAtype, MCUtype;
+  OMX_VIDEO_PARAM_ENABLEBOARD enable_board;
+  OMX_VIDEO_PARAM_ENABLEDMABUFFER enable_dmabuf;
+  OMX_VIDEO_PARAM_ENABLEMCU enable_mcu;
+  static int use_dmabuf = 0, use_mcu = 1, use_board = 0;
+#endif
+
   self->enc =
       gst_omx_component_new (GST_OBJECT_CAST (self), klass->cdata.core_name,
       klass->cdata.component_name, klass->cdata.component_role,
@@ -251,6 +259,28 @@ gst_omx_video_enc_open (GstVideoEncoder * encoder)
   self->enc_in_port = gst_omx_component_add_port (self->enc, in_port_index);
   self->enc_out_port = gst_omx_component_add_port (self->enc, out_port_index);
 
+#ifdef USE_OMX_TARGET_ZYNQ_USCALE_PLUS
+  GST_INFO_OBJECT (self, "Custom settings needed for zynq VCU");
+  OMX_GetExtensionIndex (self->enc->handle,
+      (OMX_STRING) "OMX.allegro.enableBoard", &type);
+  memset (&enable_board, 0, sizeof (enable_board));
+  enable_board.bEnable = use_board;
+  OMX_SetParameter (self->enc->handle, type, &enable_board);
+
+  OMX_GetExtensionIndex (self->enc->handle,
+      (OMX_STRING) "OMX.allegro.linux.enableDMA", &DMAtype);
+
+  memset (&enable_dmabuf, 0, sizeof (enable_dmabuf));
+  enable_dmabuf.bEnable = (OMX_BOOL) use_dmabuf;
+  OMX_SetParameter (self->enc->handle, DMAtype, &enable_dmabuf);
+
+  OMX_GetExtensionIndex (self->enc->handle,
+      (OMX_STRING) "OMX.allegro.enableMCU", &MCUtype);
+  memset (&enable_mcu, 0, sizeof (enable_mcu));
+  enable_mcu.bEnable = (OMX_BOOL) use_mcu;
+  OMX_SetParameter (self->enc->handle, MCUtype, &enable_mcu);
+#endif
+
   if (!self->enc_in_port || !self->enc_out_port)
     return FALSE;
 
diff --git a/omx/openmax/OMX_VideoExt.h b/omx/openmax/OMX_VideoExt.h
index 9f07a94..bd57a1d 100644
--- a/omx/openmax/OMX_VideoExt.h
+++ b/omx/openmax/OMX_VideoExt.h
@@ -284,6 +284,54 @@ typedef struct OMX_VIDEO_SLICESEGMENTSTYPE {
     OMX_BOOL bEnableLoopFilterAcrossSlices;
 } OMX_VIDEO_SLICESEGMENTSTYPE;
 
+#ifdef USE_OMX_TARGET_ZYNQ_USCALE_PLUS
+// Use Board
+#ifndef bUSELIBREF
+#define bUSELIBREF true
+#endif
+
+/**
+ *
+ * Define Index Param Video
+ *
+ */
+typedef enum AL_INDEX_PARAM_VIDEO_TYPE
+{
+  OMX_IndexParamVideoHevc = OMX_IndexVendorStartUnused,
+  OMX_IndexParamVideoEnableBoard,
+  OMX_IndexParamVideoEnableMCU,
+  OMX_IndexParamVideoEnableDMA,
+}AL_INDEX_PARAM_VIDEO_TYPE;
+
+#define OMX_AL_CUSTOMPARAM_ENABLE_BOARD "OMX.allegro.enableBoard"
+#define OMX_AL_CUSTOMPARAM_ENABLE_MCU "OMX.allegro.enableMCU"
+
+typedef struct OMX_VIDEO_PARAM_ENABLEMCU
+{
+  OMX_U32 nSize;
+  OMX_VERSIONTYPE nVersion;
+  OMX_BOOL bEnable;
+}OMX_VIDEO_PARAM_ENABLEMCU;
+
+#define OMX_AL_CUSTOMPARAM_ENABLE_DMA "OMX.allegro.linux.enableDMA"
+
+typedef struct OMX_VIDEO_PARAM_ENABLEDMABUFFER
+{
+  OMX_U32 nSize;
+  OMX_VERSIONTYPE nVersion;
+  OMX_U32 nPortIndex;
+  OMX_BOOL bEnable;
+}OMX_VIDEO_PARAM_ENABLEDMABUFFER;
+
+typedef struct OMX_VIDEO_PARAM_ENABLEBOARD
+{
+  OMX_U32 nSize;
+  OMX_VERSIONTYPE nVersion;
+  OMX_BOOL bEnable;
+}OMX_VIDEO_PARAM_ENABLEBOARD;
+
+#endif
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
-- 
2.7.4

