0010-add-property-framerate.patch 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. --- a/omx/gstomxmjpegdec.h
  2. +++ b/omx/gstomxmjpegdec.h
  3. @@ -45,6 +45,16 @@
  4. struct _GstOMXMJPEGDec
  5. {
  6. GstOMXVideoDec parent;
  7. +#ifdef USE_OMX_TARGET_STARFIVE
  8. + //If container shows fps as public api, it won't work
  9. + //as GstBuffer containing pts/dts/duration and it will calculate fps in upstream.
  10. + //i.e.
  11. + //not works:
  12. + // gst-launch-1.0 -v filesrc location=xxx.mp4 ! qtdemux name=demux demux.video_0 ! jpegparse ! omxmjpegdec framerate=xxx ! kmssink driver-name=starfive force-modesetting=1
  13. + //works:
  14. + // gst-launch-1.0 -v filesrc location=xxx.mjpeg ! jpegparse ! omxmjpegdec framerate=xxx ! kmssink driver-name=starfive force-modesetting=1
  15. + gint framerate;
  16. +#endif
  17. };
  18. struct _GstOMXMJPEGDecClass
  19. --- a/omx/gstomxmjpegdec.c
  20. +++ b/omx/gstomxmjpegdec.c
  21. @@ -28,16 +28,28 @@
  22. GST_DEBUG_CATEGORY_STATIC (gst_omx_mjpeg_dec_debug_category);
  23. #define GST_CAT_DEFAULT gst_omx_mjpeg_dec_debug_category
  24. -
  25. +#ifdef USE_OMX_TARGET_STARFIVE
  26. +#define DEFAULT_FRAMERATE 0
  27. +#endif
  28. /* prototypes */
  29. static gboolean gst_omx_mjpeg_dec_is_format_change (GstOMXVideoDec * dec,
  30. GstOMXPort * port, GstVideoCodecState * state);
  31. static gboolean gst_omx_mjpeg_dec_set_format (GstOMXVideoDec * dec,
  32. GstOMXPort * port, GstVideoCodecState * state);
  33. -
  34. +#ifdef USE_OMX_TARGET_STARFIVE
  35. +static void gst_omx_mjpeg_dec_set_property (GObject * object, guint prop_id,
  36. + const GValue * value, GParamSpec * pspec);
  37. +static void gst_omx_mjpeg_dec_get_property (GObject * object, guint prop_id,
  38. + GValue * value, GParamSpec * pspec);
  39. +#endif
  40. enum
  41. {
  42. +#ifdef USE_OMX_TARGET_STARFIVE
  43. + PROP_0,
  44. + PROP_FRAMERATE
  45. +#else
  46. PROP_0
  47. +#endif
  48. };
  49. /* class initialization */
  50. @@ -54,11 +66,16 @@
  51. {
  52. GstOMXVideoDecClass *videodec_class = GST_OMX_VIDEO_DEC_CLASS (klass);
  53. GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
  54. -
  55. +#ifdef USE_OMX_TARGET_STARFIVE
  56. + GObjectClass *gobject_class = G_OBJECT_CLASS (videodec_class);
  57. +#endif
  58. videodec_class->is_format_change =
  59. GST_DEBUG_FUNCPTR (gst_omx_mjpeg_dec_is_format_change);
  60. videodec_class->set_format = GST_DEBUG_FUNCPTR (gst_omx_mjpeg_dec_set_format);
  61. -
  62. +#ifdef USE_OMX_TARGET_STARFIVE
  63. + gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_omx_mjpeg_dec_set_property);
  64. + gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_omx_mjpeg_dec_get_property);
  65. +#endif
  66. videodec_class->cdata.default_sink_template_caps = "image/jpeg, "
  67. "width=(int) [1,MAX], " "height=(int) [1,MAX]";
  68. @@ -67,7 +84,16 @@
  69. "Codec/Decoder/Video/Hardware",
  70. "Decode MJPEG video streams",
  71. "Sebastian Dröge <sebastian.droege@collabora.co.uk>");
  72. -
  73. +#ifdef USE_OMX_TARGET_STARFIVE
  74. + g_object_class_install_property (gobject_class, PROP_FRAMERATE,
  75. + g_param_spec_int ("framerate",
  76. + "Framerate",
  77. + "Frames per second in raw stream.\n \
  78. + Only workable for the container not exposing fps.\n\
  79. + '0' means disabled.",
  80. + 0, G_MAXINT,
  81. + DEFAULT_FRAMERATE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
  82. +#endif
  83. gst_omx_set_default_role (&videodec_class->cdata, "video_decoder.mjpeg");
  84. }
  85. @@ -89,10 +115,53 @@
  86. {
  87. gboolean ret;
  88. OMX_PARAM_PORTDEFINITIONTYPE port_def;
  89. +#ifdef USE_OMX_TARGET_STARFIVE
  90. + GstVideoInfo *info = &state->info;
  91. + GstOMXMJPEGDec * mjpeg_dec = GST_OMX_MJPEG_DEC (dec);
  92. + if (mjpeg_dec->framerate != DEFAULT_FRAMERATE) {
  93. + GST_DEBUG_OBJECT (dec, " change fps from %d/%d to %d/1" GST_PTR_FORMAT, info->fps_n, info->fps_d, mjpeg_dec->framerate);
  94. + info->fps_n = mjpeg_dec->framerate;
  95. + info->fps_d = 1;
  96. + if (state->caps) {
  97. + gst_caps_set_simple (state->caps, "framerate", GST_TYPE_FRACTION, info->fps_n, info->fps_d, NULL);
  98. + }
  99. + }
  100. +#endif
  101. gst_omx_port_get_port_definition (port, &port_def);
  102. port_def.format.video.eCompressionFormat = OMX_VIDEO_CodingMJPEG;
  103. ret = gst_omx_port_update_port_definition (port, &port_def) == OMX_ErrorNone;
  104. return ret;
  105. }
  106. +#ifdef USE_OMX_TARGET_STARFIVE
  107. +static void
  108. +gst_omx_mjpeg_dec_set_property (GObject * object, guint prop_id,
  109. + const GValue * value, GParamSpec * pspec)
  110. +{
  111. + GstOMXMJPEGDec * mjpeg_dec = GST_OMX_MJPEG_DEC (object);
  112. + switch (prop_id) {
  113. + case PROP_FRAMERATE:
  114. + mjpeg_dec->framerate = g_value_get_int (value);
  115. + break;
  116. + default:
  117. + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
  118. + break;
  119. + }
  120. +}
  121. +
  122. +static void
  123. +gst_omx_mjpeg_dec_get_property (GObject * object, guint prop_id, GValue * value,
  124. + GParamSpec * pspec)
  125. +{
  126. + GstOMXMJPEGDec * mjpeg_dec = GST_OMX_MJPEG_DEC (object);
  127. + switch (prop_id) {
  128. + case PROP_FRAMERATE:
  129. + g_value_set_int (value, mjpeg_dec->framerate);
  130. + break;
  131. + default:
  132. + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
  133. + break;
  134. + }
  135. +}
  136. +#endif