0017-support-mirror-rotation-scale-for-gstomxmjpegdec.patch 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. Support mirror rotation scale 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 13:42:12.749600862 +0800
  5. +++ b/omx/gstomxmjpegdec.c 2022-10-14 13:36:08.488195374 +0800
  6. @@ -30,8 +30,19 @@ GST_DEBUG_CATEGORY_STATIC (gst_omx_mjpeg
  7. #define GST_CAT_DEFAULT gst_omx_mjpeg_dec_debug_category
  8. #ifdef USE_OMX_TARGET_STARFIVE
  9. #define DEFAULT_FRAMERATE 0
  10. +#define DEFAULT_MIRROR 0
  11. +#define DEFAULT_ROTATION 0
  12. +#define DEFAULT_SCALEH 0
  13. +#define DEFAULT_SCALEV 0
  14. #endif
  15. /* prototypes */
  16. +
  17. +static gboolean
  18. +gst_omx_jpegdec_set_scale (GstOMXVideoDec * self);
  19. +static gboolean
  20. +gst_omx_jpegdec_set_rotation (GstOMXVideoDec * self);
  21. +static gboolean
  22. +gst_omx_jpegdec_set_mirror (GstOMXVideoDec * self);
  23. static gboolean gst_omx_mjpeg_dec_is_format_change (GstOMXVideoDec * dec,
  24. GstOMXPort * port, GstVideoCodecState * state);
  25. static gboolean gst_omx_mjpeg_dec_set_format (GstOMXVideoDec * dec,
  26. @@ -46,10 +57,14 @@ enum
  27. {
  28. #ifdef USE_OMX_TARGET_STARFIVE
  29. PROP_0,
  30. - PROP_FRAMERATE
  31. + PROP_FRAMERATE,
  32. #else
  33. - PROP_0
  34. + PROP_0,
  35. #endif
  36. + PROP_MIRROR,
  37. + PROP_SCALEH,
  38. + PROP_SCALEV,
  39. + PROP_ROTATION,
  40. };
  41. /* class initialization */
  42. @@ -61,6 +76,67 @@ enum
  43. G_DEFINE_TYPE_WITH_CODE (GstOMXMJPEGDec, gst_omx_mjpeg_dec,
  44. GST_TYPE_OMX_VIDEO_DEC, DEBUG_INIT);
  45. +#define GST_OMX_MJPEG_DEC_MIRROR_MODE (gst_omx_mjpeg_dec_mirror_mode_get_type ())
  46. +
  47. +static GType
  48. +gst_omx_mjpeg_dec_mirror_mode_get_type (void)
  49. +{
  50. + static GType qtype = 0;
  51. + if (qtype == 0) {
  52. + static const GEnumValue values[] = {
  53. + { OMX_MirrorNone, "None", "none"},
  54. + { OMX_MirrorVertical, "Mirror Vertical", "V"},
  55. + { OMX_MirrorHorizontal, "Mirror Horizontal", "H"},
  56. + { OMX_MirrorBoth, "Mirror Both", "VH"},
  57. + { 0, NULL, NULL}
  58. + };
  59. +
  60. + qtype = g_enum_register_static("GstOMXMJPEGDecMirrorMode",values);
  61. + }
  62. + return qtype;
  63. +}
  64. +
  65. +#define GST_OMX_MJPEG_DEC_ROTATION_MODE (gst_omx_mjpeg_dec_rotation_mode_get_type ())
  66. +
  67. +static GType
  68. +gst_omx_mjpeg_dec_rotation_mode_get_type (void)
  69. +{
  70. + static GType qtype = 0;
  71. + if (qtype == 0) {
  72. + static const GEnumValue values[] = {
  73. + { ROTATION_0, "None", "none"},
  74. + { ROTATION_90, "Rotate 90", "M1"},
  75. + { ROTATION_180, "Rotate 180", "M2"},
  76. + { ROTATION_270, "Rotate 270", "M3"},
  77. + { 0, NULL, NULL}
  78. + };
  79. +
  80. + qtype = g_enum_register_static ("GstOMXMJPEGDecRotationMode", values);
  81. + }
  82. + return qtype;
  83. +}
  84. +
  85. +#define GST_OMX_MJPEG_DEC_SCALE_MODE (gst_omx_mjpeg_dec_scale_mode_get_type ())
  86. +
  87. +static GType
  88. +gst_omx_mjpeg_dec_scale_mode_get_type (void)
  89. +{
  90. + static GType qtype = 0;
  91. + if (qtype == 0) {
  92. + static const GEnumValue values[] = {
  93. + { SCALEMODE_0, "None", "none"},
  94. + { SCALEMODE1_2, "Scale half", "1/2"},
  95. + { SCALEMODE1_4, "Scale quarter", "1/4"},
  96. + { SCALEMODE1_8, "Scale eighth", "1/8"},
  97. + { 0, NULL, NULL}
  98. + };
  99. +
  100. + qtype = g_enum_register_static ("GstOMXMJPEGDecScaleMode", values);
  101. + }
  102. + return qtype;
  103. +}
  104. +
  105. +
  106. static void
  107. gst_omx_mjpeg_dec_class_init (GstOMXMJPEGDecClass * klass)
  108. {
  109. @@ -94,12 +170,40 @@ gst_omx_mjpeg_dec_class_init (GstOMXMJPE
  110. 0, G_MAXINT,
  111. DEFAULT_FRAMERATE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
  112. #endif
  113. + g_object_class_install_property (gobject_class, PROP_MIRROR,
  114. + g_param_spec_enum ("mirror", "MIRROR",
  115. + "Mirror 0(none), 1(V), 2(H), 3(VH).",
  116. + GST_OMX_MJPEG_DEC_MIRROR_MODE,
  117. + DEFAULT_MIRROR, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
  118. +
  119. + g_object_class_install_property (gobject_class, PROP_ROTATION,
  120. + g_param_spec_enum ("rotation", "ROTATION",
  121. + "Rotation 0(none), 1(90), 2(180), 3(270).",
  122. + GST_OMX_MJPEG_DEC_ROTATION_MODE,
  123. + DEFAULT_ROTATION, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
  124. +
  125. + g_object_class_install_property (gobject_class, PROP_SCALEH,
  126. + g_param_spec_enum ("scaleH", "ScaleH",
  127. + "Horizontal downscale: 0(none), 1(1/2), 2(1/4), 3(1/8).",
  128. + GST_OMX_MJPEG_DEC_SCALE_MODE, DEFAULT_SCALEH,
  129. + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
  130. +
  131. + g_object_class_install_property (gobject_class, PROP_SCALEV,
  132. + g_param_spec_enum ("scaleV", "ScaleV",
  133. + "Vertical downscale: 0(none), 1(1/2), 2(1/4), 3(1/8).",
  134. + GST_OMX_MJPEG_DEC_SCALE_MODE, DEFAULT_SCALEV,
  135. + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
  136. +
  137. gst_omx_set_default_role (&videodec_class->cdata, "video_decoder.mjpeg");
  138. }
  139. static void
  140. gst_omx_mjpeg_dec_init (GstOMXMJPEGDec * self)
  141. {
  142. + self->mirror = DEFAULT_MIRROR;
  143. + self->rotation = DEFAULT_ROTATION;
  144. + self->scaleH = DEFAULT_SCALEH;
  145. + self->scaleV = DEFAULT_SCALEV;
  146. }
  147. static gboolean
  148. @@ -128,6 +232,15 @@ gst_omx_mjpeg_dec_set_format (GstOMXVide
  149. }
  150. }
  151. #endif
  152. + if (!gst_omx_jpegdec_set_mirror (dec))
  153. + return FALSE;
  154. +
  155. + if (!gst_omx_jpegdec_set_rotation (dec))
  156. + return FALSE;
  157. +
  158. + if (!gst_omx_jpegdec_set_scale (dec))
  159. + return FALSE;
  160. +
  161. gst_omx_port_get_port_definition (port, &port_def);
  162. port_def.format.video.eCompressionFormat = OMX_VIDEO_CodingMJPEG;
  163. ret = gst_omx_port_update_port_definition (port, &port_def) == OMX_ErrorNone;
  164. @@ -144,6 +257,18 @@ gst_omx_mjpeg_dec_set_property (GObject
  165. case PROP_FRAMERATE:
  166. mjpeg_dec->framerate = g_value_get_int (value);
  167. break;
  168. + case PROP_MIRROR:
  169. + mjpeg_dec->mirror = g_value_get_enum (value);
  170. + break;
  171. + case PROP_ROTATION:
  172. + mjpeg_dec->rotation = g_value_get_enum (value);
  173. + break;
  174. + case PROP_SCALEH:
  175. + mjpeg_dec->scaleH = g_value_get_enum (value);
  176. + break;
  177. + case PROP_SCALEV:
  178. + mjpeg_dec->scaleV = g_value_get_enum (value);
  179. + break;
  180. default:
  181. G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
  182. break;
  183. @@ -159,9 +284,164 @@ gst_omx_mjpeg_dec_get_property (GObject
  184. case PROP_FRAMERATE:
  185. g_value_set_int (value, mjpeg_dec->framerate);
  186. break;
  187. + case PROP_MIRROR:
  188. + g_value_set_enum (value, mjpeg_dec->mirror);
  189. + break;
  190. + case PROP_ROTATION:
  191. + g_value_set_enum (value, mjpeg_dec->rotation);
  192. + break;
  193. + case PROP_SCALEH:
  194. + g_value_set_enum (value, mjpeg_dec->scaleH);
  195. + break;
  196. + case PROP_SCALEV:
  197. + g_value_set_enum (value, mjpeg_dec->scaleV);
  198. + break;
  199. default:
  200. G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
  201. break;
  202. }
  203. }
  204. #endif
  205. +
  206. +static gboolean
  207. +gst_omx_jpegdec_set_rotation (GstOMXVideoDec * self)
  208. +{
  209. + OMX_ERRORTYPE err;
  210. + OMX_CONFIG_ROTATIONTYPE rotation_config;
  211. + gboolean result = TRUE;
  212. + GstOMXMJPEGDec * mjpeg_dec = GST_OMX_MJPEG_DEC (self);
  213. +
  214. + GST_OBJECT_LOCK (self);
  215. +
  216. + GST_OMX_INIT_STRUCT (&rotation_config);
  217. + rotation_config.nPortIndex = self->dec_out_port->index;
  218. +
  219. + err =
  220. + gst_omx_component_get_config (self->dec,
  221. + OMX_IndexConfigCommonRotate, &rotation_config);
  222. +
  223. + if (err == OMX_ErrorNone) {
  224. + if (mjpeg_dec->rotation >= 0 && mjpeg_dec->rotation <= 270)
  225. + rotation_config.nRotation = mjpeg_dec->rotation;
  226. +
  227. + err =
  228. + gst_omx_component_set_config (self->dec,
  229. + OMX_IndexConfigCommonRotate, &rotation_config);
  230. + if (err == OMX_ErrorUnsupportedIndex) {
  231. + GST_WARNING_OBJECT (self,
  232. + "Setting a rotation not supported by the component");
  233. + } else if (err == OMX_ErrorUnsupportedSetting) {
  234. + GST_WARNING_OBJECT (self,
  235. + "Setting rotation settings %u not supported by the component",
  236. + mjpeg_dec->rotation);
  237. + } else if (err != OMX_ErrorNone) {
  238. + GST_ERROR_OBJECT (self,
  239. + "Failed to set rotation parameters: %s (0x%08x)",
  240. + gst_omx_error_to_string (err), err);
  241. + result = FALSE;
  242. + }
  243. + } else {
  244. + GST_ERROR_OBJECT (self, "Failed to get rotation parameters: %s (0x%08x)",
  245. + gst_omx_error_to_string (err), err);
  246. + }
  247. +
  248. + GST_OBJECT_UNLOCK (self);
  249. + return result;
  250. +}
  251. +
  252. +
  253. +
  254. +static gboolean
  255. +gst_omx_jpegdec_set_mirror (GstOMXVideoDec * self)
  256. +{
  257. + OMX_ERRORTYPE err;
  258. + OMX_CONFIG_MIRRORTYPE mirror_config;
  259. + gboolean result = TRUE;
  260. + GstOMXMJPEGDec * mjpeg_dec = GST_OMX_MJPEG_DEC (self);
  261. +
  262. + GST_OBJECT_LOCK (self);
  263. +
  264. + GST_OMX_INIT_STRUCT (&mirror_config);
  265. + mirror_config.nPortIndex = self->dec_out_port->index;
  266. +
  267. + err =
  268. + gst_omx_component_get_config (self->dec,
  269. + OMX_IndexConfigCommonMirror, &mirror_config);
  270. +
  271. + if (err == OMX_ErrorNone) {
  272. + if (mjpeg_dec->mirror >= 0 && mjpeg_dec->mirror <= OMX_MirrorBoth)
  273. + mirror_config.eMirror = mjpeg_dec->mirror;
  274. +
  275. + err =
  276. + gst_omx_component_set_config (self->dec,
  277. + OMX_IndexConfigCommonMirror, &mirror_config);
  278. + if (err == OMX_ErrorUnsupportedIndex) {
  279. + GST_WARNING_OBJECT (self,
  280. + "Setting a mirror not supported by the component");
  281. + } else if (err == OMX_ErrorUnsupportedSetting) {
  282. + GST_WARNING_OBJECT (self,
  283. + "Setting mirror settings %u not supported by the component",
  284. + mjpeg_dec->mirror);
  285. + } else if (err != OMX_ErrorNone) {
  286. + GST_ERROR_OBJECT (self,
  287. + "Failed to set mirror parameters: %s (0x%08x)",
  288. + gst_omx_error_to_string (err), err);
  289. + result = FALSE;
  290. + }
  291. + } else {
  292. + GST_ERROR_OBJECT (self, "Failed to get mirror parameters: %s (0x%08x)",
  293. + gst_omx_error_to_string (err), err);
  294. + }
  295. +
  296. + GST_OBJECT_UNLOCK (self);
  297. + return result;
  298. +}
  299. +
  300. +static gboolean
  301. +gst_omx_jpegdec_set_scale (GstOMXVideoDec * self)
  302. +{
  303. + OMX_ERRORTYPE err;
  304. + OMX_CONFIG_SCALEFACTORTYPE scale_config;
  305. + gboolean result = TRUE;
  306. + GstOMXMJPEGDec * mjpeg_dec = GST_OMX_MJPEG_DEC (self);
  307. +
  308. + GST_OBJECT_LOCK (self);
  309. +
  310. + GST_OMX_INIT_STRUCT (&scale_config);
  311. + scale_config.nPortIndex = self->dec_out_port->index;
  312. +
  313. + err =
  314. + gst_omx_component_get_config (self->dec,
  315. + OMX_IndexConfigCommonScale, &scale_config);
  316. +
  317. + if (err == OMX_ErrorNone) {
  318. + if ((mjpeg_dec->scaleV >= 0 && mjpeg_dec->scaleV <= 3 ) ||
  319. + (mjpeg_dec->scaleH >= 0 && mjpeg_dec->scaleH <= 3)) {
  320. + scale_config.xWidth = (1 << 16) >> (mjpeg_dec->scaleH & 0x3);
  321. + scale_config.xHeight = (1 << 16) >> (mjpeg_dec->scaleV & 0x3);
  322. + }
  323. +
  324. + err =
  325. + gst_omx_component_set_config (self->dec,
  326. + OMX_IndexConfigCommonScale, &scale_config);
  327. + if (err == OMX_ErrorUnsupportedIndex) {
  328. + GST_WARNING_OBJECT (self,
  329. + "Setting a scale not supported by the component");
  330. + } else if (err == OMX_ErrorUnsupportedSetting) {
  331. + GST_WARNING_OBJECT (self,
  332. + "Setting scale settings %u %u not supported by the component",
  333. + mjpeg_dec->scaleV, mjpeg_dec->scaleH);
  334. + } else if (err != OMX_ErrorNone) {
  335. + GST_ERROR_OBJECT (self,
  336. + "Failed to set scale parameters: %s (0x%08x)",
  337. + gst_omx_error_to_string (err), err);
  338. + result = FALSE;
  339. + }
  340. + } else {
  341. + GST_ERROR_OBJECT (self, "Failed to get scale parameters: %s (0x%08x)",
  342. + gst_omx_error_to_string (err), err);
  343. + }
  344. +
  345. + GST_OBJECT_UNLOCK (self);
  346. + return result;
  347. +}
  348. \ No newline at end of file
  349. diff -purN a/omx/gstomxmjpegdec.h b/omx/gstomxmjpegdec.h
  350. --- a/omx/gstomxmjpegdec.h 2022-10-14 13:42:12.749600862 +0800
  351. +++ b/omx/gstomxmjpegdec.h 2022-10-14 13:29:24.849638506 +0800
  352. @@ -55,6 +55,10 @@ struct _GstOMXMJPEGDec
  353. // gst-launch-1.0 -v filesrc location=xxx.mjpeg ! jpegparse ! omxmjpegdec framerate=xxx ! kmssink driver-name=starfive force-modesetting=1
  354. gint framerate;
  355. #endif
  356. + guint32 mirror;
  357. + guint32 scaleH;
  358. + guint32 scaleV;
  359. + guint32 rotation;
  360. };
  361. struct _GstOMXMJPEGDecClass
  362. @@ -68,3 +72,19 @@ G_END_DECLS
  363. #endif /* __GST_OMX_MJPEG_DEC_H__ */
  364. +typedef enum ROTATIONTYPE
  365. +{
  366. + ROTATION_0 = 0,
  367. + ROTATION_90 = 90,
  368. + ROTATION_180 = 180,
  369. + ROTATION_270 = 270,
  370. +} ROTATIONTYPE;
  371. +
  372. +typedef enum SCALETYPE
  373. +{
  374. + SCALEMODE_0 = 0,
  375. + SCALEMODE1_2,
  376. + SCALEMODE1_4,
  377. + SCALEMODE1_8,
  378. +} SCALETYPE;
  379. +