0018-support-cut-for-gstomxmjpegdec.patch 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. Support cut property for omxmjpegdec
  2. Signed-off-by: Leo Lu <leo.lu@starfivetech.com>
  3. diff -purN a/omx/gstomxmjpegdec.c b/omx/gstomxmjpegdec.c
  4. --- a/omx/gstomxmjpegdec.c 2022-10-14 14:48:24.207804442 +0800
  5. +++ b/omx/gstomxmjpegdec.c 2022-10-14 14:46:42.979857812 +0800
  6. @@ -34,6 +34,8 @@ GST_DEBUG_CATEGORY_STATIC (gst_omx_mjpeg
  7. #define DEFAULT_ROTATION 0
  8. #define DEFAULT_SCALEH 0
  9. #define DEFAULT_SCALEV 0
  10. +#define DEFAULT_ROI ""
  11. +
  12. #endif
  13. /* prototypes */
  14. @@ -43,6 +45,8 @@ static gboolean
  15. gst_omx_jpegdec_set_rotation (GstOMXVideoDec * self);
  16. static gboolean
  17. gst_omx_jpegdec_set_mirror (GstOMXVideoDec * self);
  18. +static gboolean
  19. +gst_omx_jpegdec_set_roi (GstOMXVideoDec * self);
  20. static gboolean gst_omx_mjpeg_dec_is_format_change (GstOMXVideoDec * dec,
  21. GstOMXPort * port, GstVideoCodecState * state);
  22. static gboolean gst_omx_mjpeg_dec_set_format (GstOMXVideoDec * dec,
  23. @@ -65,6 +69,7 @@ enum
  24. PROP_SCALEH,
  25. PROP_SCALEV,
  26. PROP_ROTATION,
  27. + PROP_ROI,
  28. };
  29. /* class initialization */
  30. @@ -194,6 +199,17 @@ gst_omx_mjpeg_dec_class_init (GstOMXMJPE
  31. GST_OMX_MJPEG_DEC_SCALE_MODE, DEFAULT_SCALEV,
  32. G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
  33. + g_object_class_install_property (gobject_class, PROP_ROI,
  34. + g_param_spec_string ("roi", "ROI",
  35. + "Cutting image roi=<x>,<y>,<w>,<h> .\n \
  36. + roi coord and width/height(from left top).\n \
  37. + <x> X Coordinate of the top left corner of the rectangle.\n \
  38. + <y> Y Coordinate of the top left corner of the rectangle.\n \
  39. + <w> Width of the rectangle.\n \
  40. + <h> Height of the rectangle.\n \
  41. + EX:omxmjpegdec roi=0,0,800,480",
  42. + DEFAULT_ROI, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
  43. +
  44. gst_omx_set_default_role (&videodec_class->cdata, "video_decoder.mjpeg");
  45. }
  46. @@ -204,6 +220,7 @@ gst_omx_mjpeg_dec_init (GstOMXMJPEGDec *
  47. self->rotation = DEFAULT_ROTATION;
  48. self->scaleH = DEFAULT_SCALEH;
  49. self->scaleV = DEFAULT_SCALEV;
  50. + memset (self->roi, 0, ROI_ARRAY_SIZE);
  51. }
  52. static gboolean
  53. @@ -240,6 +257,9 @@ gst_omx_mjpeg_dec_set_format (GstOMXVide
  54. if (!gst_omx_jpegdec_set_scale (dec))
  55. return FALSE;
  56. +
  57. + if (!gst_omx_jpegdec_set_roi (dec))
  58. + return FALSE;
  59. gst_omx_port_get_port_definition (port, &port_def);
  60. port_def.format.video.eCompressionFormat = OMX_VIDEO_CodingMJPEG;
  61. @@ -269,6 +289,9 @@ gst_omx_mjpeg_dec_set_property (GObject
  62. case PROP_SCALEV:
  63. mjpeg_dec->scaleV = g_value_get_enum (value);
  64. break;
  65. + case PROP_ROI:
  66. + strncpy (mjpeg_dec->roi, g_value_get_string (value), ROI_ARRAY_SIZE);
  67. + break;
  68. default:
  69. G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
  70. break;
  71. @@ -296,6 +319,9 @@ gst_omx_mjpeg_dec_get_property (GObject
  72. case PROP_SCALEV:
  73. g_value_set_enum (value, mjpeg_dec->scaleV);
  74. break;
  75. + case PROP_ROI:
  76. + g_value_set_string (value, mjpeg_dec->roi);
  77. + break;
  78. default:
  79. G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
  80. break;
  81. @@ -444,4 +470,81 @@ gst_omx_jpegdec_set_scale (GstOMXVideoDe
  82. GST_OBJECT_UNLOCK (self);
  83. return result;
  84. -}
  85. \ No newline at end of file
  86. +}
  87. +
  88. +static gboolean
  89. +gst_omx_jpegdec_set_roi (GstOMXVideoDec *self)
  90. +{
  91. + OMX_ERRORTYPE err;
  92. + OMX_CONFIG_RECTTYPE RectConfig;
  93. + gboolean result = TRUE;
  94. + GstOMXMJPEGDec * mjpeg_dec = GST_OMX_MJPEG_DEC (self);
  95. + gchar* val;
  96. + gchar roi_tmp[ROI_ARRAY_SIZE];
  97. + strncpy (roi_tmp, mjpeg_dec->roi, ROI_ARRAY_SIZE);
  98. +
  99. + GST_OBJECT_LOCK (self);
  100. + GST_OMX_INIT_STRUCT (&RectConfig);
  101. + RectConfig.nPortIndex = self->dec_out_port->index;
  102. +
  103. + err =
  104. + gst_omx_component_get_config (self->dec,
  105. + OMX_IndexConfigCommonScale, &RectConfig);
  106. + if (err == OMX_ErrorNone) {
  107. + if (strlen (mjpeg_dec->roi) > 0) {
  108. + val = strtok (roi_tmp, ",");
  109. + if (val == NULL) {
  110. + goto ROI_PARAM_ERROR;
  111. + } else {
  112. + RectConfig.nLeft = atoi (val);
  113. + }
  114. + val = strtok (NULL, ",");
  115. + if (val == NULL) {
  116. + goto ROI_PARAM_ERROR;
  117. + } else {
  118. + RectConfig.nTop = atoi (val);
  119. + }
  120. + val = strtok (NULL, ",");
  121. + if (val == NULL) {
  122. + goto ROI_PARAM_ERROR;
  123. + } else {
  124. + RectConfig.nWidth = atoi (val);
  125. + }
  126. + val = strtok (NULL, ",");
  127. + if (val == NULL) {
  128. + goto ROI_PARAM_ERROR;
  129. + } else {
  130. + RectConfig.nHeight = atoi (val);
  131. + }
  132. + } else {
  133. + GST_OBJECT_UNLOCK (self);
  134. + return TRUE;
  135. + }
  136. +
  137. + err =
  138. + gst_omx_component_set_config (self->dec,
  139. + OMX_IndexConfigCommonOutputCrop, &RectConfig);
  140. + if (err == OMX_ErrorUnsupportedIndex) {
  141. + GST_WARNING_OBJECT (self,
  142. + "Setting a ROI not supported by the component");
  143. + } else if (err == OMX_ErrorUnsupportedSetting) {
  144. + GST_WARNING_OBJECT (self,
  145. + "Setting ROI settings %s not supported by the component", mjpeg_dec->roi);
  146. + } else if (err != OMX_ErrorNone) {
  147. + GST_ERROR_OBJECT (self,
  148. + "Failed to set ROI parameters: %s (0x%08x)", gst_omx_error_to_string (err), err);
  149. + result = FALSE;
  150. + }
  151. + } else {
  152. + GST_ERROR_OBJECT (self, "Failed to get ROI parameters: %s (0x%08x)",
  153. + gst_omx_error_to_string (err), err);
  154. + }
  155. +
  156. + GST_OBJECT_UNLOCK (self);
  157. + return result;
  158. +
  159. +ROI_PARAM_ERROR:
  160. + GST_ERROR_OBJECT (self, "Invalid ROI parameter: %s", mjpeg_dec->roi);
  161. + GST_OBJECT_UNLOCK (self);
  162. + return FALSE;
  163. +}
  164. diff -purN a/omx/gstomxmjpegdec.h b/omx/gstomxmjpegdec.h
  165. --- a/omx/gstomxmjpegdec.h 2022-10-14 14:48:24.207804442 +0800
  166. +++ b/omx/gstomxmjpegdec.h 2022-10-14 14:42:09.876591323 +0800
  167. @@ -42,6 +42,8 @@ G_BEGIN_DECLS
  168. typedef struct _GstOMXMJPEGDec GstOMXMJPEGDec;
  169. typedef struct _GstOMXMJPEGDecClass GstOMXMJPEGDecClass;
  170. +#define ROI_ARRAY_SIZE 128
  171. +
  172. struct _GstOMXMJPEGDec
  173. {
  174. GstOMXVideoDec parent;
  175. @@ -59,6 +61,8 @@ struct _GstOMXMJPEGDec
  176. guint32 scaleH;
  177. guint32 scaleV;
  178. guint32 rotation;
  179. + gchar roi[ROI_ARRAY_SIZE];
  180. +
  181. };
  182. struct _GstOMXMJPEGDecClass