support mirror rotation scale cut property for gstomxmjpegdec

This commit is contained in:
leo.lu
2022-10-14 17:18:27 +08:00
committed by Andy Hu
parent 1336f5ff16
commit afb700c0cc
2 changed files with 311 additions and 125 deletions
@@ -3,8 +3,8 @@ Support mirror rotation scale for omxmjpegdec
Signed-off-by: Leo Lu <leo.lu@starfivetech.com> Signed-off-by: Leo Lu <leo.lu@starfivetech.com>
diff -purN a/omx/gstomxmjpegdec.c b/omx/gstomxmjpegdec.c diff -purN a/omx/gstomxmjpegdec.c b/omx/gstomxmjpegdec.c
--- a/omx/gstomxmjpegdec.c 2022-09-27 15:31:41.826975878 +0800 --- a/omx/gstomxmjpegdec.c 2022-10-14 13:42:12.749600862 +0800
+++ b/omx/gstomxmjpegdec.c 2022-09-27 15:19:10.924240508 +0800 +++ b/omx/gstomxmjpegdec.c 2022-10-14 13:36:08.488195374 +0800
@@ -30,8 +30,19 @@ GST_DEBUG_CATEGORY_STATIC (gst_omx_mjpeg @@ -30,8 +30,19 @@ GST_DEBUG_CATEGORY_STATIC (gst_omx_mjpeg
#define GST_CAT_DEFAULT gst_omx_mjpeg_dec_debug_category #define GST_CAT_DEFAULT gst_omx_mjpeg_dec_debug_category
#ifdef USE_OMX_TARGET_STARFIVE #ifdef USE_OMX_TARGET_STARFIVE
@@ -17,11 +17,11 @@ diff -purN a/omx/gstomxmjpegdec.c b/omx/gstomxmjpegdec.c
/* prototypes */ /* prototypes */
+ +
+static gboolean +static gboolean
+gst_omx_jepgdec_set_scale(GstOMXVideoDec *self); +gst_omx_jpegdec_set_scale (GstOMXVideoDec * self);
+static gboolean +static gboolean
+gst_omx_jepgdec_set_rotation(GstOMXVideoDec *self); +gst_omx_jpegdec_set_rotation (GstOMXVideoDec * self);
+static gboolean +static gboolean
+gst_omx_jepgdec_set_mirror(GstOMXVideoDec *self); +gst_omx_jpegdec_set_mirror (GstOMXVideoDec * self);
static gboolean gst_omx_mjpeg_dec_is_format_change (GstOMXVideoDec * dec, static gboolean gst_omx_mjpeg_dec_is_format_change (GstOMXVideoDec * dec,
GstOMXPort * port, GstVideoCodecState * state); GstOMXPort * port, GstVideoCodecState * state);
static gboolean gst_omx_mjpeg_dec_set_format (GstOMXVideoDec * dec, static gboolean gst_omx_mjpeg_dec_set_format (GstOMXVideoDec * dec,
@@ -42,7 +42,7 @@ diff -purN a/omx/gstomxmjpegdec.c b/omx/gstomxmjpegdec.c
}; };
/* class initialization */ /* class initialization */
@@ -61,6 +76,71 @@ enum @@ -61,6 +76,67 @@ enum
G_DEFINE_TYPE_WITH_CODE (GstOMXMJPEGDec, gst_omx_mjpeg_dec, G_DEFINE_TYPE_WITH_CODE (GstOMXMJPEGDec, gst_omx_mjpeg_dec,
GST_TYPE_OMX_VIDEO_DEC, DEBUG_INIT); GST_TYPE_OMX_VIDEO_DEC, DEBUG_INIT);
@@ -62,10 +62,8 @@ diff -purN a/omx/gstomxmjpegdec.c b/omx/gstomxmjpegdec.c
+ }; + };
+ +
+ qtype = g_enum_register_static("GstOMXMJPEGDecMirrorMode",values); + qtype = g_enum_register_static("GstOMXMJPEGDecMirrorMode",values);
+
+ } + }
+ return qtype; + return qtype;
+
+} +}
+ +
+#define GST_OMX_MJPEG_DEC_ROTATION_MODE (gst_omx_mjpeg_dec_rotation_mode_get_type ()) +#define GST_OMX_MJPEG_DEC_ROTATION_MODE (gst_omx_mjpeg_dec_rotation_mode_get_type ())
@@ -84,7 +82,6 @@ diff -purN a/omx/gstomxmjpegdec.c b/omx/gstomxmjpegdec.c
+ }; + };
+ +
+ qtype = g_enum_register_static ("GstOMXMJPEGDecRotationMode", values); + qtype = g_enum_register_static ("GstOMXMJPEGDecRotationMode", values);
+
+ } + }
+ return qtype; + return qtype;
+} +}
@@ -105,7 +102,6 @@ diff -purN a/omx/gstomxmjpegdec.c b/omx/gstomxmjpegdec.c
+ }; + };
+ +
+ qtype = g_enum_register_static ("GstOMXMJPEGDecScaleMode", values); + qtype = g_enum_register_static ("GstOMXMJPEGDecScaleMode", values);
+
+ } + }
+ return qtype; + return qtype;
+} +}
@@ -114,7 +110,7 @@ diff -purN a/omx/gstomxmjpegdec.c b/omx/gstomxmjpegdec.c
static void static void
gst_omx_mjpeg_dec_class_init (GstOMXMJPEGDecClass * klass) gst_omx_mjpeg_dec_class_init (GstOMXMJPEGDecClass * klass)
{ {
@@ -94,12 +174,41 @@ gst_omx_mjpeg_dec_class_init (GstOMXMJPE @@ -94,12 +170,40 @@ gst_omx_mjpeg_dec_class_init (GstOMXMJPE
0, G_MAXINT, 0, G_MAXINT,
DEFAULT_FRAMERATE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); DEFAULT_FRAMERATE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
#endif #endif
@@ -141,7 +137,6 @@ diff -purN a/omx/gstomxmjpegdec.c b/omx/gstomxmjpegdec.c
+ "Vertical downscale: 0(none), 1(1/2), 2(1/4), 3(1/8).", + "Vertical downscale: 0(none), 1(1/2), 2(1/4), 3(1/8).",
+ GST_OMX_MJPEG_DEC_SCALE_MODE, DEFAULT_SCALEV, + GST_OMX_MJPEG_DEC_SCALE_MODE, DEFAULT_SCALEV,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+ +
gst_omx_set_default_role (&videodec_class->cdata, "video_decoder.mjpeg"); gst_omx_set_default_role (&videodec_class->cdata, "video_decoder.mjpeg");
} }
@@ -156,23 +151,23 @@ diff -purN a/omx/gstomxmjpegdec.c b/omx/gstomxmjpegdec.c
} }
static gboolean static gboolean
@@ -128,6 +237,15 @@ gst_omx_mjpeg_dec_set_format (GstOMXVide @@ -128,6 +232,15 @@ gst_omx_mjpeg_dec_set_format (GstOMXVide
} }
} }
#endif #endif
+ if(!gst_omx_jepgdec_set_mirror(dec)) + if (!gst_omx_jpegdec_set_mirror (dec))
+ return FALSE; + return FALSE;
+ +
+ if(!gst_omx_jepgdec_set_rotation(dec)) + if (!gst_omx_jpegdec_set_rotation (dec))
+ return FALSE; + return FALSE;
+ +
+ if(!gst_omx_jepgdec_set_scale(dec)) + if (!gst_omx_jpegdec_set_scale (dec))
+ return FALSE; + return FALSE;
+ +
gst_omx_port_get_port_definition (port, &port_def); gst_omx_port_get_port_definition (port, &port_def);
port_def.format.video.eCompressionFormat = OMX_VIDEO_CodingMJPEG; port_def.format.video.eCompressionFormat = OMX_VIDEO_CodingMJPEG;
ret = gst_omx_port_update_port_definition (port, &port_def) == OMX_ErrorNone; ret = gst_omx_port_update_port_definition (port, &port_def) == OMX_ErrorNone;
@@ -144,6 +262,18 @@ gst_omx_mjpeg_dec_set_property (GObject @@ -144,6 +257,18 @@ gst_omx_mjpeg_dec_set_property (GObject
case PROP_FRAMERATE: case PROP_FRAMERATE:
mjpeg_dec->framerate = g_value_get_int (value); mjpeg_dec->framerate = g_value_get_int (value);
break; break;
@@ -191,7 +186,7 @@ diff -purN a/omx/gstomxmjpegdec.c b/omx/gstomxmjpegdec.c
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
@@ -159,9 +289,168 @@ gst_omx_mjpeg_dec_get_property (GObject @@ -159,9 +284,164 @@ gst_omx_mjpeg_dec_get_property (GObject
case PROP_FRAMERATE: case PROP_FRAMERATE:
g_value_set_int (value, mjpeg_dec->framerate); g_value_set_int (value, mjpeg_dec->framerate);
break; break;
@@ -215,7 +210,7 @@ diff -purN a/omx/gstomxmjpegdec.c b/omx/gstomxmjpegdec.c
#endif #endif
+ +
+static gboolean +static gboolean
+gst_omx_jepgdec_set_rotation(GstOMXVideoDec *self) +gst_omx_jpegdec_set_rotation (GstOMXVideoDec * self)
+{ +{
+ OMX_ERRORTYPE err; + OMX_ERRORTYPE err;
+ OMX_CONFIG_ROTATIONTYPE rotation_config; + OMX_CONFIG_ROTATIONTYPE rotation_config;
@@ -227,17 +222,17 @@ diff -purN a/omx/gstomxmjpegdec.c b/omx/gstomxmjpegdec.c
+ GST_OMX_INIT_STRUCT (&rotation_config); + GST_OMX_INIT_STRUCT (&rotation_config);
+ rotation_config.nPortIndex = self->dec_out_port->index; + rotation_config.nPortIndex = self->dec_out_port->index;
+ +
+ err = gst_omx_component_get_config(self->dec, + err =
+ gst_omx_component_get_config (self->dec,
+ OMX_IndexConfigCommonRotate, &rotation_config); + OMX_IndexConfigCommonRotate, &rotation_config);
+ +
+ if (err == OMX_ErrorNone) { + if (err == OMX_ErrorNone) {
+
+ if (mjpeg_dec->rotation >= 0 && mjpeg_dec->rotation <= 270) + if (mjpeg_dec->rotation >= 0 && mjpeg_dec->rotation <= 270)
+ rotation_config.nRotation = mjpeg_dec->rotation; + rotation_config.nRotation = mjpeg_dec->rotation;
+ +
+ err = gst_omx_component_set_config(self->dec, + err =
+ gst_omx_component_set_config (self->dec,
+ OMX_IndexConfigCommonRotate, &rotation_config); + OMX_IndexConfigCommonRotate, &rotation_config);
+
+ if (err == OMX_ErrorUnsupportedIndex) { + if (err == OMX_ErrorUnsupportedIndex) {
+ GST_WARNING_OBJECT (self, + GST_WARNING_OBJECT (self,
+ "Setting a rotation not supported by the component"); + "Setting a rotation not supported by the component");
@@ -258,13 +253,12 @@ diff -purN a/omx/gstomxmjpegdec.c b/omx/gstomxmjpegdec.c
+ +
+ GST_OBJECT_UNLOCK (self); + GST_OBJECT_UNLOCK (self);
+ return result; + return result;
+
+} +}
+ +
+ +
+ +
+static gboolean +static gboolean
+gst_omx_jepgdec_set_mirror(GstOMXVideoDec *self) +gst_omx_jpegdec_set_mirror (GstOMXVideoDec * self)
+{ +{
+ OMX_ERRORTYPE err; + OMX_ERRORTYPE err;
+ OMX_CONFIG_MIRRORTYPE mirror_config; + OMX_CONFIG_MIRRORTYPE mirror_config;
@@ -276,17 +270,17 @@ diff -purN a/omx/gstomxmjpegdec.c b/omx/gstomxmjpegdec.c
+ GST_OMX_INIT_STRUCT (&mirror_config); + GST_OMX_INIT_STRUCT (&mirror_config);
+ mirror_config.nPortIndex = self->dec_out_port->index; + mirror_config.nPortIndex = self->dec_out_port->index;
+ +
+ err = gst_omx_component_get_config(self->dec, + err =
+ gst_omx_component_get_config (self->dec,
+ OMX_IndexConfigCommonMirror, &mirror_config); + OMX_IndexConfigCommonMirror, &mirror_config);
+ +
+ if (err == OMX_ErrorNone) { + if (err == OMX_ErrorNone) {
+
+ if (mjpeg_dec->mirror >= 0 && mjpeg_dec->mirror <= OMX_MirrorBoth) + if (mjpeg_dec->mirror >= 0 && mjpeg_dec->mirror <= OMX_MirrorBoth)
+ mirror_config.eMirror = mjpeg_dec->mirror; + mirror_config.eMirror = mjpeg_dec->mirror;
+ +
+ err = gst_omx_component_set_config(self->dec, + err =
+ gst_omx_component_set_config (self->dec,
+ OMX_IndexConfigCommonMirror, &mirror_config); + OMX_IndexConfigCommonMirror, &mirror_config);
+
+ if (err == OMX_ErrorUnsupportedIndex) { + if (err == OMX_ErrorUnsupportedIndex) {
+ GST_WARNING_OBJECT (self, + GST_WARNING_OBJECT (self,
+ "Setting a mirror not supported by the component"); + "Setting a mirror not supported by the component");
@@ -307,11 +301,10 @@ diff -purN a/omx/gstomxmjpegdec.c b/omx/gstomxmjpegdec.c
+ +
+ GST_OBJECT_UNLOCK (self); + GST_OBJECT_UNLOCK (self);
+ return result; + return result;
+
+} +}
+ +
+static gboolean +static gboolean
+gst_omx_jepgdec_set_scale(GstOMXVideoDec *self) +gst_omx_jpegdec_set_scale (GstOMXVideoDec * self)
+{ +{
+ OMX_ERRORTYPE err; + OMX_ERRORTYPE err;
+ OMX_CONFIG_SCALEFACTORTYPE scale_config; + OMX_CONFIG_SCALEFACTORTYPE scale_config;
@@ -323,21 +316,20 @@ diff -purN a/omx/gstomxmjpegdec.c b/omx/gstomxmjpegdec.c
+ GST_OMX_INIT_STRUCT (&scale_config); + GST_OMX_INIT_STRUCT (&scale_config);
+ scale_config.nPortIndex = self->dec_out_port->index; + scale_config.nPortIndex = self->dec_out_port->index;
+ +
+ err = gst_omx_component_get_config(self->dec, + err =
+ gst_omx_component_get_config (self->dec,
+ OMX_IndexConfigCommonScale, &scale_config); + OMX_IndexConfigCommonScale, &scale_config);
+ +
+ if (err == OMX_ErrorNone) { + if (err == OMX_ErrorNone) {
+
+ if ((mjpeg_dec->scaleV >= 0 && mjpeg_dec->scaleV <= 3 ) || + if ((mjpeg_dec->scaleV >= 0 && mjpeg_dec->scaleV <= 3 ) ||
+ (mjpeg_dec->scaleH >= 0 && mjpeg_dec->scaleH <= 3)) { + (mjpeg_dec->scaleH >= 0 && mjpeg_dec->scaleH <= 3)) {
+
+ scale_config.xWidth = (1 << 16) >> (mjpeg_dec->scaleH & 0x3); + scale_config.xWidth = (1 << 16) >> (mjpeg_dec->scaleH & 0x3);
+ scale_config.xHeight = (1 << 16) >> (mjpeg_dec->scaleV & 0x3); + scale_config.xHeight = (1 << 16) >> (mjpeg_dec->scaleV & 0x3);
+ } + }
+ +
+ err = gst_omx_component_set_config(self->dec, + err =
+ gst_omx_component_set_config (self->dec,
+ OMX_IndexConfigCommonScale, &scale_config); + OMX_IndexConfigCommonScale, &scale_config);
+
+ if (err == OMX_ErrorUnsupportedIndex) { + if (err == OMX_ErrorUnsupportedIndex) {
+ GST_WARNING_OBJECT (self, + GST_WARNING_OBJECT (self,
+ "Setting a scale not supported by the component"); + "Setting a scale not supported by the component");
@@ -358,12 +350,11 @@ diff -purN a/omx/gstomxmjpegdec.c b/omx/gstomxmjpegdec.c
+ +
+ GST_OBJECT_UNLOCK (self); + GST_OBJECT_UNLOCK (self);
+ return result; + return result;
+
+} +}
\ No newline at end of file \ No newline at end of file
diff -purN a/omx/gstomxmjpegdec.h b/omx/gstomxmjpegdec.h diff -purN a/omx/gstomxmjpegdec.h b/omx/gstomxmjpegdec.h
--- a/omx/gstomxmjpegdec.h 2022-09-27 15:31:41.826975878 +0800 --- a/omx/gstomxmjpegdec.h 2022-10-14 13:42:12.749600862 +0800
+++ b/omx/gstomxmjpegdec.h 2022-09-27 14:14:46.115432778 +0800 +++ b/omx/gstomxmjpegdec.h 2022-10-14 13:29:24.849638506 +0800
@@ -55,6 +55,10 @@ struct _GstOMXMJPEGDec @@ -55,6 +55,10 @@ struct _GstOMXMJPEGDec
// gst-launch-1.0 -v filesrc location=xxx.mjpeg ! jpegparse ! omxmjpegdec framerate=xxx ! kmssink driver-name=starfive force-modesetting=1 // gst-launch-1.0 -v filesrc location=xxx.mjpeg ! jpegparse ! omxmjpegdec framerate=xxx ! kmssink driver-name=starfive force-modesetting=1
gint framerate; gint framerate;
@@ -375,19 +366,20 @@ diff -purN a/omx/gstomxmjpegdec.h b/omx/gstomxmjpegdec.h
}; };
struct _GstOMXMJPEGDecClass struct _GstOMXMJPEGDecClass
@@ -68,3 +72,18 @@ G_END_DECLS @@ -68,3 +72,19 @@ G_END_DECLS
#endif /* __GST_OMX_MJPEG_DEC_H__ */ #endif /* __GST_OMX_MJPEG_DEC_H__ */
+typedef enum ROTATIONTYPE { +typedef enum ROTATIONTYPE
+{
+ ROTATION_0 = 0, + ROTATION_0 = 0,
+ ROTATION_90 = 90, + ROTATION_90 = 90,
+ ROTATION_180 = 180, + ROTATION_180 = 180,
+ ROTATION_270 = 270, + ROTATION_270 = 270,
+} ROTATIONTYPE; +} ROTATIONTYPE;
+ +
+ +typedef enum SCALETYPE
+typedef enum SCALETYPE { +{
+ SCALEMODE_0 = 0, + SCALEMODE_0 = 0,
+ SCALEMODE1_2, + SCALEMODE1_2,
+ SCALEMODE1_4, + SCALEMODE1_4,
@@ -0,0 +1,194 @@
Support cut property for omxmjpegdec
Signed-off-by: Leo Lu <leo.lu@starfivetech.com>
diff -purN a/omx/gstomxmjpegdec.c b/omx/gstomxmjpegdec.c
--- a/omx/gstomxmjpegdec.c 2022-10-14 14:48:24.207804442 +0800
+++ b/omx/gstomxmjpegdec.c 2022-10-14 14:46:42.979857812 +0800
@@ -34,6 +34,8 @@ GST_DEBUG_CATEGORY_STATIC (gst_omx_mjpeg
#define DEFAULT_ROTATION 0
#define DEFAULT_SCALEH 0
#define DEFAULT_SCALEV 0
+#define DEFAULT_ROI ""
+
#endif
/* prototypes */
@@ -43,6 +45,8 @@ static gboolean
gst_omx_jpegdec_set_rotation (GstOMXVideoDec * self);
static gboolean
gst_omx_jpegdec_set_mirror (GstOMXVideoDec * self);
+static gboolean
+gst_omx_jpegdec_set_roi (GstOMXVideoDec * self);
static gboolean gst_omx_mjpeg_dec_is_format_change (GstOMXVideoDec * dec,
GstOMXPort * port, GstVideoCodecState * state);
static gboolean gst_omx_mjpeg_dec_set_format (GstOMXVideoDec * dec,
@@ -65,6 +69,7 @@ enum
PROP_SCALEH,
PROP_SCALEV,
PROP_ROTATION,
+ PROP_ROI,
};
/* class initialization */
@@ -194,6 +199,17 @@ gst_omx_mjpeg_dec_class_init (GstOMXMJPE
GST_OMX_MJPEG_DEC_SCALE_MODE, DEFAULT_SCALEV,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (gobject_class, PROP_ROI,
+ g_param_spec_string ("roi", "ROI",
+ "Cutting image roi=<x>,<y>,<w>,<h> .\n \
+ roi coord and width/height(from left top).\n \
+ <x> X Coordinate of the top left corner of the rectangle.\n \
+ <y> Y Coordinate of the top left corner of the rectangle.\n \
+ <w> Width of the rectangle.\n \
+ <h> Height of the rectangle.\n \
+ EX:omxmjpegdec roi=0,0,800,480",
+ DEFAULT_ROI, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
gst_omx_set_default_role (&videodec_class->cdata, "video_decoder.mjpeg");
}
@@ -204,6 +220,7 @@ gst_omx_mjpeg_dec_init (GstOMXMJPEGDec *
self->rotation = DEFAULT_ROTATION;
self->scaleH = DEFAULT_SCALEH;
self->scaleV = DEFAULT_SCALEV;
+ memset (self->roi, 0, ROI_ARRAY_SIZE);
}
static gboolean
@@ -240,6 +257,9 @@ gst_omx_mjpeg_dec_set_format (GstOMXVide
if (!gst_omx_jpegdec_set_scale (dec))
return FALSE;
+
+ if (!gst_omx_jpegdec_set_roi (dec))
+ return FALSE;
gst_omx_port_get_port_definition (port, &port_def);
port_def.format.video.eCompressionFormat = OMX_VIDEO_CodingMJPEG;
@@ -269,6 +289,9 @@ gst_omx_mjpeg_dec_set_property (GObject
case PROP_SCALEV:
mjpeg_dec->scaleV = g_value_get_enum (value);
break;
+ case PROP_ROI:
+ strncpy (mjpeg_dec->roi, g_value_get_string (value), ROI_ARRAY_SIZE);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -296,6 +319,9 @@ gst_omx_mjpeg_dec_get_property (GObject
case PROP_SCALEV:
g_value_set_enum (value, mjpeg_dec->scaleV);
break;
+ case PROP_ROI:
+ g_value_set_string (value, mjpeg_dec->roi);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -444,4 +470,81 @@ gst_omx_jpegdec_set_scale (GstOMXVideoDe
GST_OBJECT_UNLOCK (self);
return result;
-}
\ No newline at end of file
+}
+
+static gboolean
+gst_omx_jpegdec_set_roi (GstOMXVideoDec *self)
+{
+ OMX_ERRORTYPE err;
+ OMX_CONFIG_RECTTYPE RectConfig;
+ gboolean result = TRUE;
+ GstOMXMJPEGDec * mjpeg_dec = GST_OMX_MJPEG_DEC (self);
+ gchar* val;
+ gchar roi_tmp[ROI_ARRAY_SIZE];
+ strncpy (roi_tmp, mjpeg_dec->roi, ROI_ARRAY_SIZE);
+
+ GST_OBJECT_LOCK (self);
+ GST_OMX_INIT_STRUCT (&RectConfig);
+ RectConfig.nPortIndex = self->dec_out_port->index;
+
+ err =
+ gst_omx_component_get_config (self->dec,
+ OMX_IndexConfigCommonScale, &RectConfig);
+ if (err == OMX_ErrorNone) {
+ if (strlen (mjpeg_dec->roi) > 0) {
+ val = strtok (roi_tmp, ",");
+ if (val == NULL) {
+ goto ROI_PARAM_ERROR;
+ } else {
+ RectConfig.nLeft = atoi (val);
+ }
+ val = strtok (NULL, ",");
+ if (val == NULL) {
+ goto ROI_PARAM_ERROR;
+ } else {
+ RectConfig.nTop = atoi (val);
+ }
+ val = strtok (NULL, ",");
+ if (val == NULL) {
+ goto ROI_PARAM_ERROR;
+ } else {
+ RectConfig.nWidth = atoi (val);
+ }
+ val = strtok (NULL, ",");
+ if (val == NULL) {
+ goto ROI_PARAM_ERROR;
+ } else {
+ RectConfig.nHeight = atoi (val);
+ }
+ } else {
+ GST_OBJECT_UNLOCK (self);
+ return TRUE;
+ }
+
+ err =
+ gst_omx_component_set_config (self->dec,
+ OMX_IndexConfigCommonOutputCrop, &RectConfig);
+ if (err == OMX_ErrorUnsupportedIndex) {
+ GST_WARNING_OBJECT (self,
+ "Setting a ROI not supported by the component");
+ } else if (err == OMX_ErrorUnsupportedSetting) {
+ GST_WARNING_OBJECT (self,
+ "Setting ROI settings %s not supported by the component", mjpeg_dec->roi);
+ } else if (err != OMX_ErrorNone) {
+ GST_ERROR_OBJECT (self,
+ "Failed to set ROI parameters: %s (0x%08x)", gst_omx_error_to_string (err), err);
+ result = FALSE;
+ }
+ } else {
+ GST_ERROR_OBJECT (self, "Failed to get ROI parameters: %s (0x%08x)",
+ gst_omx_error_to_string (err), err);
+ }
+
+ GST_OBJECT_UNLOCK (self);
+ return result;
+
+ROI_PARAM_ERROR:
+ GST_ERROR_OBJECT (self, "Invalid ROI parameter: %s", mjpeg_dec->roi);
+ GST_OBJECT_UNLOCK (self);
+ return FALSE;
+}
diff -purN a/omx/gstomxmjpegdec.h b/omx/gstomxmjpegdec.h
--- a/omx/gstomxmjpegdec.h 2022-10-14 14:48:24.207804442 +0800
+++ b/omx/gstomxmjpegdec.h 2022-10-14 14:42:09.876591323 +0800
@@ -42,6 +42,8 @@ G_BEGIN_DECLS
typedef struct _GstOMXMJPEGDec GstOMXMJPEGDec;
typedef struct _GstOMXMJPEGDecClass GstOMXMJPEGDecClass;
+#define ROI_ARRAY_SIZE 128
+
struct _GstOMXMJPEGDec
{
GstOMXVideoDec parent;
@@ -59,6 +61,8 @@ struct _GstOMXMJPEGDec
guint32 scaleH;
guint32 scaleV;
guint32 rotation;
+ gchar roi[ROI_ARRAY_SIZE];
+
};
struct _GstOMXMJPEGDecClass