From f54626a805ca6af589b80ba7a936540791b2f243 Mon Sep 17 00:00:00 2001 From: "andy.hu" Date: Tue, 21 Dec 2021 18:23:28 +0800 Subject: [PATCH 01/14] gst1-rtsp-server: enable example code build for rtsp server feature Signed-off-by: andy.hu --- ...nstall-operation-when-build-examples.patch | 25 +++++++++++++++++++ .../gst1-rtsp-server/gst1-rtsp-server.mk | 8 +++--- 2 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 package/gstreamer1/gst1-rtsp-server/0001-Enable-install-operation-when-build-examples.patch diff --git a/package/gstreamer1/gst1-rtsp-server/0001-Enable-install-operation-when-build-examples.patch b/package/gstreamer1/gst1-rtsp-server/0001-Enable-install-operation-when-build-examples.patch new file mode 100644 index 00000000..61401dae --- /dev/null +++ b/package/gstreamer1/gst1-rtsp-server/0001-Enable-install-operation-when-build-examples.patch @@ -0,0 +1,25 @@ +From 25af3820863d70905268710761784fd84298f80f Mon Sep 17 00:00:00 2001 +From: "andy.hu" +Date: Mon, 25 Oct 2021 11:13:54 +0800 +Subject: [PATCH] Enable install operation when build examples + +--- + examples/meson.build | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/examples/meson.build b/examples/meson.build +index 2bacd48..757ac49 100644 +--- a/examples/meson.build ++++ b/examples/meson.build +@@ -26,7 +26,7 @@ foreach example : examples + c_args : rtspserver_args, + include_directories : rtspserver_incs, + dependencies : [glib_dep, gst_dep, gstapp_dep, gstnet_dep, gst_rtsp_server_dep], +- install: false) ++ install: true) + endforeach + + cgroup_dep = dependency('libcgroup', version : '>= 0.26', required : false) +-- +2.33.0 + diff --git a/package/gstreamer1/gst1-rtsp-server/gst1-rtsp-server.mk b/package/gstreamer1/gst1-rtsp-server/gst1-rtsp-server.mk index 37942423..19588863 100644 --- a/package/gstreamer1/gst1-rtsp-server/gst1-rtsp-server.mk +++ b/package/gstreamer1/gst1-rtsp-server/gst1-rtsp-server.mk @@ -21,13 +21,13 @@ GST1_RTSP_SERVER_DEPENDENCIES = \ GST1_RTSP_SERVER_LDFLAGS = $(TARGET_LDFLAGS) $(TARGET_NLS_LIBS) GST1_RTSP_SERVER_CONF_OPTS = \ - -Dexamples=disabled \ - -Dtests=disabled \ + -Dexamples=enabled \ + -Dtests=enabled \ -Ddoc=disabled GST1_RTSP_SERVER_CONF_OPTS += \ - -Dexamples=disabled \ - -Dtests=disabled \ + -Dexamples=enabled \ + -Dtests=enabled \ -Dgobject-cast-checks=disabled \ -Dglib-asserts=disabled \ -Dglib-checks=disabled From c7412fed6aa2f6d578a0e7e308f0c1e116c493e9 Mon Sep 17 00:00:00 2001 From: Andy Hu Date: Fri, 22 Apr 2022 09:27:32 +0800 Subject: [PATCH 02/14] gstreamer: fix build warning Signed-off-by: sw.multimedia --- .../0002-quit-when-pipeline-interrupted.patch | 106 ++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 package/gstreamer1/gst1-plugins-base/0002-quit-when-pipeline-interrupted.patch diff --git a/package/gstreamer1/gst1-plugins-base/0002-quit-when-pipeline-interrupted.patch b/package/gstreamer1/gst1-plugins-base/0002-quit-when-pipeline-interrupted.patch new file mode 100644 index 00000000..9c8e77e6 --- /dev/null +++ b/package/gstreamer1/gst1-plugins-base/0002-quit-when-pipeline-interrupted.patch @@ -0,0 +1,106 @@ +diff -Naur a/tools/gst-play.c b/tools/gst-play.c +--- a/tools/gst-play.c 2020-10-26 19:10:32.459882500 +0800 ++++ b/tools/gst-play.c 2022-04-07 14:13:15.126395339 +0800 +@@ -19,7 +19,6 @@ + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ +- + #ifdef HAVE_CONFIG_H + #include "config.h" + #endif +@@ -40,6 +39,9 @@ + #include + + #include "gst-play-kb.h" ++#ifdef G_OS_UNIX ++#include ++#endif + + #define VOLUME_STEPS 20 + +@@ -104,6 +106,31 @@ + gdouble rate; + } GstPlay; + ++#if defined(G_OS_UNIX) ++static guint signal_watch_intr_id; ++#endif ++ ++#if defined(G_OS_UNIX) ++/* As the interrupt handler is dispatched from GMainContext as a GSourceFunc ++ * handler, we can react to this by posting a message. */ ++static gboolean ++intr_handler (gpointer user_data) ++{ ++ GstPlay *play = (GstPlay *) user_data; ++ gst_print ("handling interrupt.\n"); ++ ++ /* post an application specific message */ ++ gst_element_post_message (GST_ELEMENT (play->playbin), ++ gst_message_new_application (GST_OBJECT (play->playbin), ++ gst_structure_new ("GstLaunchInterrupt", ++ "message", G_TYPE_STRING, "Pipeline interrupted", NULL))); ++ ++ /* remove signal handler */ ++ signal_watch_intr_id = 0; ++ return G_SOURCE_REMOVE; ++} ++#endif /* G_OS_UNIX */ ++ + static gboolean quiet = FALSE; + static gboolean instant_rate_changes = FALSE; + +@@ -594,6 +621,24 @@ + } + break; + } ++ case GST_MESSAGE_APPLICATION:{ ++ const GstStructure *s; ++ ++ s = gst_message_get_structure (msg); ++ ++ if (gst_structure_has_name (s, "GstLaunchInterrupt")) { ++ /* this application message is posted when we caught an interrupt and ++ * we need to stop the pipeline. */ ++ ++ gst_print (_("Interrupt: GST_MESSAGE_APPLICATION ...\n")); ++ if (play->desired_state == GST_STATE_PLAYING){ ++ gst_print (_("Interrupt: Stopping pipeline ...\n")); ++ g_main_loop_quit (play->loop); ++ } ++ ++ } ++ break; ++ } + default: + if (gst_is_missing_plugin_message (msg)) { + gchar *desc; +@@ -1622,6 +1667,12 @@ + } + } + ++#ifdef G_OS_UNIX ++ gst_print("g_source_remove signal_watch_intr_id \n"); ++ signal_watch_intr_id = ++ g_unix_signal_add (SIGINT, (GSourceFunc) intr_handler, play); ++#endif ++ + /* play */ + do_play (play); + +@@ -1632,6 +1683,14 @@ + g_free (video_sink); + + gst_print ("\n"); ++ ++#ifdef G_OS_UNIX ++ if (signal_watch_intr_id > 0){ ++ gst_print("g_source_remove signal_watch_intr_id \n"); ++ g_source_remove (signal_watch_intr_id); ++ } ++#endif ++ + gst_deinit (); + return 0; + } From 620f471e3c3e5986c613920a4f444c6c8860d0d6 Mon Sep 17 00:00:00 2001 From: "sw.multimedia" Date: Fri, 27 Aug 2021 16:40:43 +0800 Subject: [PATCH 03/14] Add Multimedia Feature: 1. add starfive private packages: v4l2_test, pp_test, sf-gst-omx, sf-omx-il, stfisp_setfile, wave511, wave521 v4l2_test: used to test v4l2 device pp_test: used to switch format and resolution for framebuffer framework sf-gst-omx: from gst-omx and compatible with the omx-il library sf-omx-il: starfive openmax il library for VPU hardware decode stfisp_setfile: this is the host build package, used to generate the isp registrer setting bin for v4l2 framework wave511: this is chip&media decode hardware wave511 vendor code building wave521: this is chip&media encode hardware wave521 vendor code building 2. Add the following gstreamer patch: add patch to support gstreamer plugin fbdevsink NV12 format add patch to support gst-play take priority to decoding h264/h265 with gst-omx plugin Signed-off-by: sw.multimedia Signed-off-by: andy.hu Signed-off-by: michael.yan Signed-off-by: david.li Signed-off-by: Curry Zhang Signed-off-by: keithzhao --- .../gst1-plugins-bad/0001-add-I420.patch | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100755 package/gstreamer1/gst1-plugins-bad/0001-add-I420.patch diff --git a/package/gstreamer1/gst1-plugins-bad/0001-add-I420.patch b/package/gstreamer1/gst1-plugins-bad/0001-add-I420.patch new file mode 100755 index 00000000..b532de14 --- /dev/null +++ b/package/gstreamer1/gst1-plugins-bad/0001-add-I420.patch @@ -0,0 +1,72 @@ +--- a/sys/fbdev/gstfbdevsink.c 2021-07-06 16:02:46.304928800 +0800 ++++ b/sys/fbdev/gstfbdevsink.c 2021-07-06 16:02:11.593693100 +0800 +@@ -73,7 +73,7 @@ + static GstStateChangeReturn gst_fbdevsink_change_state (GstElement * element, + GstStateChange transition); + +-#define VIDEO_CAPS "{ RGB, BGR, BGRx, xBGR, RGB, RGBx, xRGB, RGB15, RGB16 }" ++#define VIDEO_CAPS "{ RGB, BGR, BGRx, xBGR, RGB, RGBx, xRGB, RGB15, RGB16, I420, NV12, NV21 }" + + static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink", + GST_PAD_SINK, +@@ -133,7 +133,10 @@ + /* FIXME: locking */ + if (!fbdevsink->framebuffer) + goto done; +- ++ if (fbdevsink->varinfo.grayscale == 1) { ++ format = GST_VIDEO_FORMAT_NV12; ++ goto common; ++ } + bpp = fbdevsink->varinfo.bits_per_pixel; + + rmask = ((1 << fbdevsink->varinfo.red.length) - 1) +@@ -182,6 +185,8 @@ + if (format == GST_VIDEO_FORMAT_UNKNOWN) + goto unknown_format; + ++common: ++ + caps = gst_caps_make_writable (caps); + gst_caps_set_simple (caps, "format", G_TYPE_STRING, + gst_video_format_to_string (format), NULL); +@@ -272,12 +277,33 @@ + if (!gst_buffer_map (buf, &map, GST_MAP_READ)) + return GST_FLOW_ERROR; + +- for (i = 0; i < fbdevsink->lines; i++) { +- memcpy (fbdevsink->framebuffer +- + (i + fbdevsink->cy) * fbdevsink->fixinfo.line_length +- + fbdevsink->cx * fbdevsink->bytespp, +- map.data + i * fbdevsink->width * fbdevsink->bytespp, +- fbdevsink->linelen); ++ if (fbdevsink->varinfo.grayscale == 1) { ++ int screen_offset = fbdevsink->varinfo.xres * fbdevsink->varinfo.yres; ++ int buffer_offset = fbdevsink->height * fbdevsink->width; ++ ++ for (i = 0; i < fbdevsink->lines; i++) { ++ memcpy (fbdevsink->framebuffer ++ + (i + fbdevsink->cy) * fbdevsink->varinfo.xres ++ + fbdevsink->cx * 1, ++ map.data + i * fbdevsink->width * 1, ++ fbdevsink->width); ++ } ++ ++ for (i = 0; i < fbdevsink->lines/2; i++) { ++ memcpy (fbdevsink->framebuffer + screen_offset ++ + (i + fbdevsink->cy/2) * fbdevsink->varinfo.xres ++ + fbdevsink->cx * 1, ++ map.data + buffer_offset + i * fbdevsink->width * 1, ++ fbdevsink->width); ++ } ++ } else { ++ for (i = 0; i < fbdevsink->lines; i++) { ++ memcpy (fbdevsink->framebuffer ++ + (i + fbdevsink->cy) * fbdevsink->fixinfo.line_length ++ + fbdevsink->cx * fbdevsink->bytespp, ++ map.data + i * fbdevsink->width * fbdevsink->bytespp, ++ fbdevsink->linelen); ++ } + } + + gst_buffer_unmap (buf, &map); From 725957a92c3b7d15fcc10be3fc9a41c2a33e2aa1 Mon Sep 17 00:00:00 2001 From: Andy Hu Date: Fri, 13 May 2022 14:01:26 +0800 Subject: [PATCH 04/14] gstreamer: fix patch and building warning for gst-plugins-bad Signed-off-by: Andy Hu (cherry picked from commit f475d9a3bceeefd19bebf3d3471cedf12a46b8fa) --- .../0002-set-init-buffer-to-black.patch | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 package/gstreamer1/gst1-plugins-bad/0002-set-init-buffer-to-black.patch diff --git a/package/gstreamer1/gst1-plugins-bad/0002-set-init-buffer-to-black.patch b/package/gstreamer1/gst1-plugins-bad/0002-set-init-buffer-to-black.patch new file mode 100644 index 00000000..299214fc --- /dev/null +++ b/package/gstreamer1/gst1-plugins-bad/0002-set-init-buffer-to-black.patch @@ -0,0 +1,21 @@ +--- a/sys/kms/gstkmssink.c 2020-10-26 19:14:46.656235000 +0800 ++++ b/sys/kms/gstkmssink.c 2021-12-16 15:35:15.590755066 +0800 +@@ -450,6 +450,18 @@ + goto bo_failed; + fb_id = kmsmem->fb_id; + ++ GST_INFO_OBJECT (self, "size = %lu, width = %d, height = %d.", vinfo->size, vinfo->width, vinfo->height); ++ if (vinfo->size == vinfo->width * vinfo->height * 3 / 2) { ++ GstMapInfo mapInfo; ++ if (gst_memory_map((GstMemory *)kmsmem, &mapInfo, GST_MAP_WRITE)) { ++ guint8 *start = mapInfo.data + vinfo->width * vinfo->height; ++ guint32 size = vinfo->width * vinfo->height / 2; ++ GST_INFO_OBJECT (self, "Set buffer to blank."); ++ memset(start, 128, size); ++ gst_memory_unmap((GstMemory *)kmsmem, &mapInfo); ++ } ++ } ++ + conn = drmModeGetConnector (self->fd, self->conn_id); + if (!conn) + goto connector_failed; From da79fd844e7fec8223d4678215c62a4228a38442 Mon Sep 17 00:00:00 2001 From: "sw.multimedia" Date: Fri, 27 Aug 2021 16:40:43 +0800 Subject: [PATCH 05/14] Add Multimedia Feature: 1. add starfive private packages: v4l2_test, pp_test, sf-gst-omx, sf-omx-il, stfisp_setfile, wave511, wave521 v4l2_test: used to test v4l2 device pp_test: used to switch format and resolution for framebuffer framework sf-gst-omx: from gst-omx and compatible with the omx-il library sf-omx-il: starfive openmax il library for VPU hardware decode stfisp_setfile: this is the host build package, used to generate the isp registrer setting bin for v4l2 framework wave511: this is chip&media decode hardware wave511 vendor code building wave521: this is chip&media encode hardware wave521 vendor code building 2. Add the following gstreamer patch: add patch to support gstreamer plugin fbdevsink NV12 format add patch to support gst-play take priority to decoding h264/h265 with gst-omx plugin Signed-off-by: sw.multimedia Signed-off-by: andy.hu Signed-off-by: michael.yan Signed-off-by: david.li Signed-off-by: Curry Zhang Signed-off-by: keithzhao (cherry picked from http://192.168.110.45/jh7100/buildroot/-/commit/fce6b25d98f81388fa4372739631c49222bf8eea) --- package/Config.in | 1 - .../0001-add-starfive-support.patch | 69 ++++++++++++++++++ ...le-the-gst-omx-VPU-decoding-and-enco.patch | 70 +++++++++++++++++++ .../0003-add-video-scale-support.patch | 50 +++++++++++++ .../0004-rank-257-for-sf-codecs.patch | 19 +++++ package/starfive/sf-gst-omx/Config.in | 11 +++ package/starfive/sf-gst-omx/sf-gst-omx.hash | 3 + package/starfive/sf-gst-omx/sf-gst-omx.mk | 36 ++++++++++ 8 files changed, 258 insertions(+), 1 deletion(-) create mode 100644 package/starfive/sf-gst-omx/0001-add-starfive-support.patch create mode 100755 package/starfive/sf-gst-omx/0002-Fix-gst-omx-Enable-the-gst-omx-VPU-decoding-and-enco.patch create mode 100644 package/starfive/sf-gst-omx/0003-add-video-scale-support.patch create mode 100644 package/starfive/sf-gst-omx/0004-rank-257-for-sf-codecs.patch create mode 100644 package/starfive/sf-gst-omx/Config.in create mode 100644 package/starfive/sf-gst-omx/sf-gst-omx.hash create mode 100644 package/starfive/sf-gst-omx/sf-gst-omx.mk diff --git a/package/Config.in b/package/Config.in index b7abc074..af06777a 100644 --- a/package/Config.in +++ b/package/Config.in @@ -2572,7 +2572,6 @@ menu "Text editors and viewers" source "package/vim/Config.in" endmenu - menu "starfive packages" source "package/starfive/Config.in" endmenu diff --git a/package/starfive/sf-gst-omx/0001-add-starfive-support.patch b/package/starfive/sf-gst-omx/0001-add-starfive-support.patch new file mode 100644 index 00000000..28801e63 --- /dev/null +++ b/package/starfive/sf-gst-omx/0001-add-starfive-support.patch @@ -0,0 +1,69 @@ +diff --git a/config/meson.build b/config/meson.build +index 1068c6d..7f8abe9 100755 +--- a/config/meson.build ++++ b/config/meson.build +@@ -6,6 +6,8 @@ elif omx_target == 'zynqultrascaleplus' + sub = 'zynqultrascaleplus' + elif omx_target == 'tizonia' + sub = 'tizonia' ++ elif omx_target == 'stf' ++ sub = 'stf' + else + # No config file defined for the 'generic' target + sub = '' +diff --git a/config/stf/gstomx.conf b/config/stf/gstomx.conf +new file mode 100644 +index 0000000..b4cdebb +--- /dev/null ++++ b/config/stf/gstomx.conf +@@ -0,0 +1,17 @@ ++[omxh265dec] ++type-name=GstOMXH265Dec ++core-name=/usr/lib/libsf-omx-il.so ++component-name=sf.dec.decoder.h265 ++in-port-index=0 ++out-port-index=1 ++rank=0 ++hacks=pass-profile-to-decoder;pass-color-format-to-decoder;ensure-buffer-count-actual ++ ++[omxh264dec] ++type-name=GstOMXH264Dec ++core-name=/usr/lib/libsf-omx-il.so ++component-name=sf.dec.decoder.h264 ++in-port-index=0 ++out-port-index=1 ++rank=1 ++hacks=pass-profile-to-decoder;pass-color-format-to-decoder;ensure-buffer-count-actual +diff --git a/config/stf/meson.build b/config/stf/meson.build +new file mode 100644 +index 0000000..dc99c08 +--- /dev/null ++++ b/config/stf/meson.build +@@ -0,0 +1 @@ ++install_data (['gstomx.conf'], install_dir : omx_conf_dir) +diff --git a/meson.build b/meson.build +index 32c7fa7..aeda56a 100755 +--- a/meson.build ++++ b/meson.build +@@ -216,6 +216,8 @@ elif omx_target == 'tizonia' + tizil_includedir = tizil_dep.get_pkgconfig_variable('includedir') + gst_omx_args += ['-I' + tizil_includedir + '/tizonia'] + omx_inc = [] ++elif omx_target == 'stf' ++ warning('stf selected') + else + error ('Unsupported omx target specified. Use the -Dtarget option') + endif +diff --git a/meson_options.txt b/meson_options.txt +index e18beb2..4fc6139 100755 +--- a/meson_options.txt ++++ b/meson_options.txt +@@ -1,7 +1,7 @@ + option('header_path', type : 'string', value : '', + description : 'An extra include directory to find the OpenMax headers') + option('target', type : 'combo', +- choices : ['none', 'generic', 'rpi', 'bellagio', 'tizonia', 'zynqultrascaleplus'], value : 'none', ++ choices : ['none', 'generic', 'rpi', 'bellagio', 'tizonia', 'zynqultrascaleplus', 'stf'], value : 'none', + description : 'The OMX platform to target') + option('struct_packing', type : 'combo', + choices : ['0', '1', '2', '4', '8'], value : '0', diff --git a/package/starfive/sf-gst-omx/0002-Fix-gst-omx-Enable-the-gst-omx-VPU-decoding-and-enco.patch b/package/starfive/sf-gst-omx/0002-Fix-gst-omx-Enable-the-gst-omx-VPU-decoding-and-enco.patch new file mode 100755 index 00000000..ae9e95bb --- /dev/null +++ b/package/starfive/sf-gst-omx/0002-Fix-gst-omx-Enable-the-gst-omx-VPU-decoding-and-enco.patch @@ -0,0 +1,70 @@ +From 810800c303965e5cb0cf135210667c003f050ee0 Mon Sep 17 00:00:00 2001 +From: "andy.hu" +Date: Tue, 10 Aug 2021 19:18:00 +0800 +Subject: [PATCH] Fix(gst-omx): Enable the gst-omx VPU decoding and encoding + support h264 High L5.2 + +--- + +diff --git a/meson.build b/meson.build +index aeda56a..48121ab 100644 +--- a/meson.build ++++ b/meson.build +@@ -217,6 +217,7 @@ elif omx_target == 'tizonia' + gst_omx_args += ['-I' + tizil_includedir + '/tizonia'] + omx_inc = [] + elif omx_target == 'stf' ++ cdata.set('USE_OMX_TARGET_STARFIVE', 1) + warning('stf selected') + else + error ('Unsupported omx target specified. Use the -Dtarget option') +diff --git a/omx/gstomxh264enc.c b/omx/gstomxh264enc.c +index 51d84a8..875f974 100644 +--- a/omx/gstomxh264enc.c ++++ b/omx/gstomxh264enc.c +@@ -824,6 +824,11 @@ gst_omx_h264_enc_get_caps (GstOMXVideoEnc * enc, GstOMXPort * port, + case OMX_VIDEO_AVCLevel51: + level = "5.1"; + break; ++#ifdef USE_OMX_TARGET_STARFIVE ++ case OMX_VIDEO_AVCLevel52: ++ level = "5.2"; ++ break; ++#else + #ifdef USE_OMX_TARGET_ZYNQ_USCALE_PLUS + case OMX_ALG_VIDEO_AVCLevel52: + level = "5.2"; +@@ -837,6 +842,7 @@ gst_omx_h264_enc_get_caps (GstOMXVideoEnc * enc, GstOMXPort * port, + case OMX_ALG_VIDEO_AVCLevel62: + level = "6.2"; + break; ++#endif + #endif + default: + g_assert_not_reached (); +diff --git a/omx/gstomxh264utils.c b/omx/gstomxh264utils.c +index ba29211..a6e95e3 100644 +--- a/omx/gstomxh264utils.c ++++ b/omx/gstomxh264utils.c +@@ -115,6 +115,10 @@ gst_omx_h264_utils_get_level_from_str (const gchar * level) + return OMX_VIDEO_AVCLevel5; + } else if (g_str_equal (level, "5.1")) { + return OMX_VIDEO_AVCLevel51; ++#ifdef USE_OMX_TARGET_STARFIVE ++ } else if (g_str_equal (level, "5.2")) { ++ return OMX_VIDEO_AVCLevel52; ++#else + #ifdef USE_OMX_TARGET_ZYNQ_USCALE_PLUS + } else if (g_str_equal (level, "5.2")) { + return (OMX_VIDEO_AVCLEVELTYPE) OMX_ALG_VIDEO_AVCLevel52; +@@ -124,6 +128,7 @@ gst_omx_h264_utils_get_level_from_str (const gchar * level) + return (OMX_VIDEO_AVCLEVELTYPE) OMX_ALG_VIDEO_AVCLevel61; + } else if (g_str_equal (level, "6.2")) { + return (OMX_VIDEO_AVCLEVELTYPE) OMX_ALG_VIDEO_AVCLevel62; ++#endif + #endif + } + +-- +2.17.1 + diff --git a/package/starfive/sf-gst-omx/0003-add-video-scale-support.patch b/package/starfive/sf-gst-omx/0003-add-video-scale-support.patch new file mode 100644 index 00000000..fd088ca4 --- /dev/null +++ b/package/starfive/sf-gst-omx/0003-add-video-scale-support.patch @@ -0,0 +1,50 @@ +--- a/omx/gstomxvideodec.c 2020-10-26 19:17:03.000000000 +0800 ++++ b/omx/gstomxvideodec.c 2021-08-16 16:23:08.082113380 +0800 +@@ -2185,6 +2185,7 @@ + gst_omx_video_dec_negotiate (GstOMXVideoDec * self) + { + OMX_VIDEO_PARAM_PORTFORMATTYPE param; ++ OMX_PARAM_PORTDEFINITIONTYPE port_def; + OMX_ERRORTYPE err; + GstCaps *comp_supported_caps; + GList *negotiation_map = NULL, *l; +@@ -2192,6 +2193,7 @@ + GstVideoFormat format; + GstStructure *s; + const gchar *format_str; ++ gint width, height; + + GST_DEBUG_OBJECT (self, "Trying to negotiate a video format with downstream"); + +@@ -2281,6 +2283,31 @@ + gst_omx_error_to_string (err), err); + } + ++ if (gst_structure_get_int(s, "width", &width) && gst_structure_get_int(s, "height", &height)) ++ { ++ GST_OMX_INIT_STRUCT (&port_def); ++ port_def.nPortIndex = self->dec_out_port->index; ++ err = gst_omx_component_get_parameter (self->dec, ++ OMX_IndexParamPortDefinition, &port_def); ++ if (err != OMX_ErrorNone) { ++ GST_ERROR_OBJECT (self, "Failed to get video port definition: %s (0x%08x)", ++ gst_omx_error_to_string (err), err); ++ return FALSE; ++ } ++ ++ port_def.format.video.nFrameHeight = height; ++ port_def.format.video.nFrameWidth = width; ++ ++ err = ++ gst_omx_component_set_parameter (self->dec, ++ OMX_IndexParamPortDefinition, &port_def); ++ if (err != OMX_ErrorNone) { ++ GST_ERROR_OBJECT (self, "Failed to set video port definition: %s (0x%08x)", ++ gst_omx_error_to_string (err), err); ++ return FALSE; ++ } ++ } ++ + gst_caps_unref (intersection); + return (err == OMX_ErrorNone); + } diff --git a/package/starfive/sf-gst-omx/0004-rank-257-for-sf-codecs.patch b/package/starfive/sf-gst-omx/0004-rank-257-for-sf-codecs.patch new file mode 100644 index 00000000..2d2f9ba0 --- /dev/null +++ b/package/starfive/sf-gst-omx/0004-rank-257-for-sf-codecs.patch @@ -0,0 +1,19 @@ +diff -Naur a/config/stf/gstomx.conf b/config/stf/gstomx.conf +--- a/config/stf/gstomx.conf 2021-08-23 16:04:48.928905742 +0800 ++++ b/config/stf/gstomx.conf 2021-08-23 16:03:38.590578856 +0800 +@@ -4,7 +4,7 @@ + component-name=sf.dec.decoder.h265 + in-port-index=0 + out-port-index=1 +-rank=0 ++rank=257 + hacks=pass-profile-to-decoder;pass-color-format-to-decoder;ensure-buffer-count-actual + + [omxh264dec] +@@ -13,5 +13,5 @@ + component-name=sf.dec.decoder.h264 + in-port-index=0 + out-port-index=1 +-rank=1 ++rank=257 + hacks=pass-profile-to-decoder;pass-color-format-to-decoder;ensure-buffer-count-actual diff --git a/package/starfive/sf-gst-omx/Config.in b/package/starfive/sf-gst-omx/Config.in new file mode 100644 index 00000000..d1180511 --- /dev/null +++ b/package/starfive/sf-gst-omx/Config.in @@ -0,0 +1,11 @@ +config SF_PACKAGE_GST_OMX + bool "sf-gst-omx" + depends on BR2_PACKAGE_SF_OMX_IL + select BR2_PACKAGE_GST1_PLUGINS_BASE + help + GStreamer plug-in to use OpenMAX API. + + https://cgit.freedesktop.org/gstreamer/gst-omx + +comment "gst-omx requires a OpenMAX implementation" + depends on !BR2_PACKAGE_SF_OMX_IL diff --git a/package/starfive/sf-gst-omx/sf-gst-omx.hash b/package/starfive/sf-gst-omx/sf-gst-omx.hash new file mode 100644 index 00000000..90403935 --- /dev/null +++ b/package/starfive/sf-gst-omx/sf-gst-omx.hash @@ -0,0 +1,3 @@ +# From https://gstreamer.freedesktop.org/src/gst-omx/gst-omx-1.18.5.tar.xz.sha256sum +sha256 2cd457c1e8deb1a9b39608048fb36a44f6c9a864a6b6115b1453a32e7be93b42 gst-omx-1.18.5.tar.xz +sha256 dc626520dcd53a22f727af3ee42c770e56c97a64fe3adb063799d8ab032fe551 COPYING diff --git a/package/starfive/sf-gst-omx/sf-gst-omx.mk b/package/starfive/sf-gst-omx/sf-gst-omx.mk new file mode 100644 index 00000000..2439d31c --- /dev/null +++ b/package/starfive/sf-gst-omx/sf-gst-omx.mk @@ -0,0 +1,36 @@ +################################################################################ +# +# sf-gst-omx +# +################################################################################ + +SF_GST_OMX_VERSION = 1.18.5 +SF_GST_OMX_SOURCE = gst-omx-$(GST_OMX_VERSION).tar.xz +SF_GST_OMX_SITE = https://gstreamer.freedesktop.org/src/gst-omx + +SF_GST_OMX_LICENSE = LGPL-2.1 +SF_GST_OMX_LICENSE_FILES = COPYING + +SF_GST_OMX_CONF_OPTS = \ + -Dexamples=disabled \ + -Dtests=disabled \ + -Dtools=disabled \ + -Ddoc=disabled + + +SF_GST_OMX_VARIANT = stf +SF_GST_OMX_CONF_OPTS += -Dheader_path=$(STAGING_DIR)/usr/include/omx-il + +SF_GST_OMX_CONF_OPTS += -Dtarget=$(SF_GST_OMX_VARIANT) + +SF_GST_OMX_DEPENDENCIES = gstreamer1 gst1-plugins-base sf-omx-il + +# adjust library paths to where buildroot installs them +define SF_GST_OMX_FIXUP_CONFIG_PATHS + find $(@D)/config -name gstomx.conf | \ + xargs $(SED) 's|/usr/local|/usr|g' -e 's|/opt/vc|/usr|g' +endef + +SF_GST_OMX_POST_PATCH_HOOKS += SF_GST_OMX_FIXUP_CONFIG_PATHS + +$(eval $(meson-package)) From a43eb08bf4a5bcfba5f33473f753e88d78f4022b Mon Sep 17 00:00:00 2001 From: "andy.hu" Date: Tue, 21 Dec 2021 18:16:51 +0800 Subject: [PATCH 06/14] sf-gst-omx: add support for wave521 encode 1. Modify package config name to BR2_PACKAGE_SF_GST_OMX 2. Support wave521 264/265 encode in gst-omx Signed-off-by: sw.multimedia Signed-off-by: andy.hu --- .../sf-gst-omx/0004-add-encoder-support.patch | 24 +++++++++++++++++++ package/starfive/sf-gst-omx/Config.in | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 package/starfive/sf-gst-omx/0004-add-encoder-support.patch diff --git a/package/starfive/sf-gst-omx/0004-add-encoder-support.patch b/package/starfive/sf-gst-omx/0004-add-encoder-support.patch new file mode 100644 index 00000000..25633e74 --- /dev/null +++ b/package/starfive/sf-gst-omx/0004-add-encoder-support.patch @@ -0,0 +1,24 @@ +--- a/config/stf/gstomx.conf 2021-08-18 14:51:51.384176799 +0800 ++++ b/config/stf/gstomx.conf 2021-08-18 14:50:58.972186447 +0800 +@@ -15,3 +15,21 @@ + out-port-index=1 + rank=1 + hacks=pass-profile-to-decoder;pass-color-format-to-decoder;ensure-buffer-count-actual ++ ++[omxh265enc] ++type-name=GstOMXH265Enc ++core-name=/usr/lib/libsf-omx-il.so ++component-name=sf.enc.encoder.h265 ++in-port-index=0 ++out-port-index=1 ++rank=1 ++hacks=pass-profile-to-decoder;pass-color-format-to-decoder;ensure-buffer-count-actual;video-framerate-integer ++ ++[omxh264enc] ++type-name=GstOMXH264Enc ++core-name=/usr/lib/libsf-omx-il.so ++component-name=sf.enc.encoder.h264 ++in-port-index=0 ++out-port-index=1 ++rank=1 ++hacks=pass-profile-to-decoder;pass-color-format-to-decoder;ensure-buffer-count-actual;video-framerate-integer diff --git a/package/starfive/sf-gst-omx/Config.in b/package/starfive/sf-gst-omx/Config.in index d1180511..b47ab3cb 100644 --- a/package/starfive/sf-gst-omx/Config.in +++ b/package/starfive/sf-gst-omx/Config.in @@ -1,4 +1,4 @@ -config SF_PACKAGE_GST_OMX +config BR2_PACKAGE_SF_GST_OMX bool "sf-gst-omx" depends on BR2_PACKAGE_SF_OMX_IL select BR2_PACKAGE_GST1_PLUGINS_BASE From a5260c099daacd411f36bfccf6585c207b896962 Mon Sep 17 00:00:00 2001 From: Andy Hu Date: Fri, 7 Jan 2022 21:04:22 +0800 Subject: [PATCH 07/14] sf-gst-omx: update to fix issue for gst-play 1. recorrect the queue index for patches name 2. USE_BUFFER is only available for dma buffer. If not dma buffer, don't come into it. sw.multimedia (cherry picked from http://192.168.110.45/jh7100/buildroot/-/commit/5249d14e587639c534b8084a541ec84bc1e953f0) --- ...atch => 0005-rank-257-for-sf-codecs.patch} | 0 ...nt-invoke-USE_BUFFER-if-no-dmabuffer.patch | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+) rename package/starfive/sf-gst-omx/{0004-rank-257-for-sf-codecs.patch => 0005-rank-257-for-sf-codecs.patch} (100%) create mode 100644 package/starfive/sf-gst-omx/0006-dont-invoke-USE_BUFFER-if-no-dmabuffer.patch diff --git a/package/starfive/sf-gst-omx/0004-rank-257-for-sf-codecs.patch b/package/starfive/sf-gst-omx/0005-rank-257-for-sf-codecs.patch similarity index 100% rename from package/starfive/sf-gst-omx/0004-rank-257-for-sf-codecs.patch rename to package/starfive/sf-gst-omx/0005-rank-257-for-sf-codecs.patch diff --git a/package/starfive/sf-gst-omx/0006-dont-invoke-USE_BUFFER-if-no-dmabuffer.patch b/package/starfive/sf-gst-omx/0006-dont-invoke-USE_BUFFER-if-no-dmabuffer.patch new file mode 100644 index 00000000..518e60b8 --- /dev/null +++ b/package/starfive/sf-gst-omx/0006-dont-invoke-USE_BUFFER-if-no-dmabuffer.patch @@ -0,0 +1,19 @@ +--- a/omx/gstomxvideodec.c ++++ b/omx/gstomxvideodec.c +@@ -718,6 +718,15 @@ + goto out; + } + ++#ifdef USE_OMX_TARGET_STARFIVE ++ if ( !gst_is_dmabuf_memory (mem)) { ++ GST_INFO_OBJECT (self, ++ " %d-th buffer doesn't contain dmabuf, go to out. port->port_def.nBufferSize: %d", ++ i, port->port_def.nBufferSize); ++ goto out; ++ } ++#endif ++ + *frame = g_slice_new0 (GstVideoFrame); + + is_mapped = gst_video_frame_map (*frame, v_info, buffer, flags); + From 326572e55b3e672c6bc6e7b72b48ba1a4888c957 Mon Sep 17 00:00:00 2001 From: Andy Hu Date: Fri, 22 Apr 2022 09:27:32 +0800 Subject: [PATCH 08/14] gstreamer: fix build warning Signed-off-by: sw.multimedia (cherry picked from http://192.168.110.45/jh7100/buildroot/-/commit/9d20c03dc2f5d4f108d05d4d8d1e37c59356efe0) --- .../0006-dont-invoke-USE_BUFFER-if-no-dmabuffer.patch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/starfive/sf-gst-omx/0006-dont-invoke-USE_BUFFER-if-no-dmabuffer.patch b/package/starfive/sf-gst-omx/0006-dont-invoke-USE_BUFFER-if-no-dmabuffer.patch index 518e60b8..55387cce 100644 --- a/package/starfive/sf-gst-omx/0006-dont-invoke-USE_BUFFER-if-no-dmabuffer.patch +++ b/package/starfive/sf-gst-omx/0006-dont-invoke-USE_BUFFER-if-no-dmabuffer.patch @@ -7,7 +7,7 @@ +#ifdef USE_OMX_TARGET_STARFIVE + if ( !gst_is_dmabuf_memory (mem)) { + GST_INFO_OBJECT (self, -+ " %d-th buffer doesn't contain dmabuf, go to out. port->port_def.nBufferSize: %d", ++ " %d-th buffer doesn't contain dmabuf, go to out. port->port_def.nBufferSize: %lu", + i, port->port_def.nBufferSize); + goto out; + } From df07978514296d7e6e65654ebc7a30a7a331e80e Mon Sep 17 00:00:00 2001 From: "sw.multimedia" Date: Wed, 9 Mar 2022 14:32:58 +0800 Subject: [PATCH 09/14] sf-gst-omx: add omxmjpegdec to support decoding mjpeg. Signed-off-by: sw.multimedia (cherry picked from http://192.168.110.45/jh7100/buildroot/-/commit/66e086938c0dee776b46c6ce6fee22316041a67c) --- .../0007-add-omxmjpegdec-support.patch | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 package/starfive/sf-gst-omx/0007-add-omxmjpegdec-support.patch diff --git a/package/starfive/sf-gst-omx/0007-add-omxmjpegdec-support.patch b/package/starfive/sf-gst-omx/0007-add-omxmjpegdec-support.patch new file mode 100644 index 00000000..def9fe64 --- /dev/null +++ b/package/starfive/sf-gst-omx/0007-add-omxmjpegdec-support.patch @@ -0,0 +1,16 @@ +--- a/config/stf/gstomx.conf ++++ b/config/stf/gstomx.conf +@@ -33,3 +33,12 @@ + out-port-index=1 + rank=1 + hacks=pass-profile-to-decoder;pass-color-format-to-decoder;ensure-buffer-count-actual;video-framerate-integer ++ ++[omxmjpegdec] ++type-name=GstOMXMJPEGDec ++core-name=/usr/lib/libsf-omx-il.so ++component-name=sf.dec.decoder.mjpeg ++in-port-index=0 ++out-port-index=1 ++rank=1 ++hacks=pass-profile-to-decoder;pass-color-format-to-decoder;ensure-buffer-count-actual + From 585ee24213310712f0a34e0e33fb2a0d24c62609 Mon Sep 17 00:00:00 2001 From: "sw.multimedia" Date: Wed, 27 Apr 2022 17:46:44 +0800 Subject: [PATCH 10/14] omxmjpegdec: fix corresponding relations between gst-format and omx-format for-NV21 Signed-off-by: sw.multimedia (cherry picked from http://192.168.110.45/jh7100/buildroot/-/commit/8dd812d3d6873cab52e558e95d85499309378759) --- ...pport-nv21-i422-y444-for-omxmjpegdec.patch | 100 ++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 package/starfive/sf-gst-omx/0008-support-nv21-i422-y444-for-omxmjpegdec.patch diff --git a/package/starfive/sf-gst-omx/0008-support-nv21-i422-y444-for-omxmjpegdec.patch b/package/starfive/sf-gst-omx/0008-support-nv21-i422-y444-for-omxmjpegdec.patch new file mode 100644 index 00000000..c360b822 --- /dev/null +++ b/package/starfive/sf-gst-omx/0008-support-nv21-i422-y444-for-omxmjpegdec.patch @@ -0,0 +1,100 @@ +--- a/config/stf/gstomx.conf ++++ b/config/stf/gstomx.conf +@@ -42,3 +42,4 @@ + out-port-index=1 + rank=1 + hacks=pass-profile-to-decoder;pass-color-format-to-decoder;ensure-buffer-count-actual ++src-template-caps=video/x-raw, format = (string) { NV16_10LE32, NV12_10LE32, NV16, YUY2, YVYU, UYVY, NV12, NV21, I420, RGB16, BGR16, ABGR, ARGB, GRAY8, Y42B, Y444 }, width = (int) [ 1, max ], height = (int) [ 1, max ], framerate = (fraction) [ 0, max ] +--- a/omx/gstomxbufferpool.c ++++ b/omx/gstomxbufferpool.c +@@ -370,9 +370,29 @@ + case GST_VIDEO_FORMAT_NV12_10LE32: + case GST_VIDEO_FORMAT_NV16: + case GST_VIDEO_FORMAT_NV16_10LE32: ++#ifdef USE_OMX_TARGET_STARFIVE ++ case GST_VIDEO_FORMAT_NV21: ++#endif + stride[1] = nstride; + offset[1] = offset[0] + stride[0] * nslice; + break; ++#ifdef USE_OMX_TARGET_STARFIVE ++ case GST_VIDEO_FORMAT_Y42B: ++ stride[0] = GST_ROUND_UP_4 (nstride); ++ stride[1] = GST_ROUND_UP_8 (nstride) / 2; ++ stride[2] = stride[1]; ++ ++ offset[1] = stride[0] * nslice; ++ offset[2] = offset[1] + stride[1] * nslice; ++ break; ++ ++ case GST_VIDEO_FORMAT_Y444: ++ stride[1] = nstride; ++ stride[2] = nstride; ++ offset[1] = offset[0] + stride[0] * nslice; ++ offset[2] = offset[1] + stride[1] * nslice; ++ break; ++#endif + default: + g_assert_not_reached (); + break; +--- a/omx/gstomxvideo.c ++++ b/omx/gstomxvideo.c +@@ -93,6 +93,17 @@ + format = GST_VIDEO_FORMAT_NV16_10LE32; + break; + #pragma GCC diagnostic pop ++#endif ++#ifdef USE_OMX_TARGET_STARFIVE ++ case OMX_COLOR_FormatYUV422Planar: ++ format = GST_VIDEO_FORMAT_Y42B; ++ break; ++ case OMX_COLOR_FormatYUV444Interleaved: ++ format = GST_VIDEO_FORMAT_Y444; ++ break; ++ case OMX_COLOR_FormatYVU420SemiPlanar: ++ format = GST_VIDEO_FORMAT_NV21; ++ break; + #endif + default: + format = GST_VIDEO_FORMAT_UNKNOWN; +--- a/omx/gstomxvideodec.c ++++ b/omx/gstomxvideodec.c +@@ -592,6 +592,9 @@ + case GST_VIDEO_FORMAT_YUY2: + case GST_VIDEO_FORMAT_UYVY: + case GST_VIDEO_FORMAT_YVYU: ++#ifdef USE_OMX_TARGET_STARFIVE ++ case GST_VIDEO_FORMAT_Y42B: ++#endif + dst_width[0] = GST_VIDEO_INFO_WIDTH (vinfo) * 2; + break; + case GST_VIDEO_FORMAT_GRAY8: +@@ -609,6 +612,9 @@ + dst_height[2] = GST_VIDEO_INFO_FIELD_HEIGHT (vinfo) / 2; + break; + case GST_VIDEO_FORMAT_NV12: ++#ifdef USE_OMX_TARGET_STARFIVE ++ case GST_VIDEO_FORMAT_NV21: ++#endif + dst_width[0] = GST_VIDEO_INFO_WIDTH (vinfo); + src_stride[1] = nstride; + src_size[1] = src_stride[1] * nslice / 2; +@@ -638,6 +644,18 @@ + src_size[1] = src_stride[1] * nslice; + dst_height[1] = GST_VIDEO_INFO_FIELD_HEIGHT (vinfo); + break; ++#ifdef USE_OMX_TARGET_STARFIVE ++ case GST_VIDEO_FORMAT_Y444: ++ dst_width[0] = GST_VIDEO_INFO_WIDTH (vinfo); ++ dst_width[1] = GST_VIDEO_INFO_WIDTH (vinfo); ++ dst_width[2] = GST_VIDEO_INFO_WIDTH (vinfo); ++ src_size[1] = src_size[0]; ++ src_size[2] = src_size[0]; ++ src_stride[1] = nstride; ++ dst_height[1] = dst_height[0]; ++ dst_height[2] = dst_height[0]; ++ break; ++#endif + default: + g_assert_not_reached (); + break; From 95d402819f71f5b5232e8786dc3a916fc06d738f Mon Sep 17 00:00:00 2001 From: "sw.multimedia" Date: Sun, 24 Apr 2022 19:25:47 +0800 Subject: [PATCH 11/14] gst/libcamera-app: fix build warning Signed-off-by: sw.multimedia (cherry picked from http://192.168.110.45/jh7100/buildroot/-/commit/c7ff2afdc55ffdc98491bc15c617db871805906b) --- ...9-suport-usebuffer-mode-for-encoding.patch | 247 ++++++++++++++++++ 1 file changed, 247 insertions(+) create mode 100644 package/starfive/sf-gst-omx/0009-suport-usebuffer-mode-for-encoding.patch diff --git a/package/starfive/sf-gst-omx/0009-suport-usebuffer-mode-for-encoding.patch b/package/starfive/sf-gst-omx/0009-suport-usebuffer-mode-for-encoding.patch new file mode 100644 index 00000000..a98259da --- /dev/null +++ b/package/starfive/sf-gst-omx/0009-suport-usebuffer-mode-for-encoding.patch @@ -0,0 +1,247 @@ +diff -Naur a/omx/gstomx.h b/omx/gstomx.h +--- a/omx/gstomx.h 2020-10-26 19:17:03.488452200 +0800 ++++ b/omx/gstomx.h 2022-04-24 18:50:01.353690234 +0800 +@@ -332,6 +332,7 @@ + */ + gint settings_cookie; + gint configured_settings_cookie; ++ GstBuffer * c_buf; + }; + + struct _GstOMXComponent { +diff -Naur a/omx/gstomxvideoenc.c b/omx/gstomxvideoenc.c +--- a/omx/gstomxvideoenc.c 2020-10-26 19:17:03.492452100 +0800 ++++ b/omx/gstomxvideoenc.c 2022-04-24 18:53:42.211595096 +0800 +@@ -2102,6 +2102,143 @@ + return TRUE; + } + ++#ifdef USE_OMX_TARGET_STARFIVE ++static GstBuffer * ++gst_omx_try_importing_buffer (GstOMXVideoEnc * self, GstBufferPool * pool, ++ GstOMXPort * port, GstVideoInfo * v_info, guint i, GstVideoFrame ** frame) ++{ ++ GstBufferPoolAcquireParams params = { 0, }; ++ GstBuffer *buffer = NULL; ++ GstMemory *mem; ++ GstMapFlags flags = GST_MAP_WRITE | GST_VIDEO_FRAME_MAP_FLAG_NO_REF; ++ gboolean is_mapped = FALSE; ++ ++ *frame = NULL; ++ ++ if (gst_buffer_pool_acquire_buffer (pool, &buffer, ¶ms) != GST_FLOW_OK) { ++ GST_INFO_OBJECT (self, "Failed to acquire %d-th buffer", i); ++ return NULL; ++ } ++ ++ if (gst_buffer_n_memory (buffer) != 1) { ++ GST_INFO_OBJECT (self, "%d-th buffer has more than one memory (%d)", i, ++ gst_buffer_n_memory (buffer)); ++ goto out; ++ } ++ ++ mem = gst_buffer_peek_memory (buffer, 0); ++ if (!mem) { ++ GST_INFO_OBJECT (self, "Failed to acquire memory of %d-th buffer", i); ++ goto out; ++ } ++ ++ if ( !gst_is_dmabuf_memory (mem)) { ++ GST_INFO_OBJECT (self, ++ " %d-th buffer doesn't contain dmabuf, go to out. port->port_def.nBufferSize: %lu", ++ i, port->port_def.nBufferSize); ++ goto out; ++ } ++ ++ *frame = g_slice_new0 (GstVideoFrame); ++ ++ is_mapped = gst_video_frame_map (*frame, v_info, buffer, flags); ++ GST_INFO_OBJECT (self, " *frame = %p, mem: %p", *frame, mem); ++ ++ if (!is_mapped) { ++ GST_INFO_OBJECT (self, "Failed to map %d-th buffer", i); ++ goto out; ++ } ++ ++ if (GST_VIDEO_FRAME_SIZE (*frame) < port->port_def.nBufferSize) { ++ GST_INFO_OBJECT (self, ++ "Frame size of %d-th buffer (%" G_GSIZE_FORMAT ++ ") is too small for port buffer size (%d)", i, ++ GST_VIDEO_FRAME_SIZE (*frame), (guint32) port->port_def.nBufferSize); ++ goto out; ++ } ++ ++ return buffer; ++ ++out: ++ if (*frame) { ++ if (is_mapped) ++ gst_video_frame_unmap (*frame); ++ g_slice_free (GstVideoFrame, *frame); ++ *frame = NULL; ++ } ++ gst_buffer_unref (buffer); ++ return NULL; ++} ++#endif ++ ++#ifdef USE_OMX_TARGET_STARFIVE ++static gboolean ++gst_omx_video_enc_use_buffers (GstOMXVideoEnc * self) ++{ ++ GstOMXPort * port = self->enc_in_port; ++ GstBufferPool *pool = port->c_buf->pool; ++ GstVideoCodecState *input_state = self->input_state; ++ GstVideoInfo v_info = input_state->info; ++ guint n = port->port_def.nBufferCountActual; ++ GList *images = NULL; ++ GList *buffers = NULL; ++ GList *frames = NULL; ++ OMX_ERRORTYPE err = OMX_ErrorNone; ++ gboolean is_mapped = FALSE ; ++ GST_DEBUG(" nBufferCountActual=%d, nBufferCountMin= %lu", n, port->port_def.nBufferCountMin); ++ ++ if ( pool != NULL ) { ++ guint i; ++ for (i = 0; i < n; i++) { ++ GstBuffer * buf = NULL; ++ GstVideoFrame *frame = NULL; ++ buf = gst_omx_try_importing_buffer (self, pool, port, &v_info, i, &frame); ++ if (!buf) { ++ GST_DEBUG_OBJECT (self, "Failed to import %d-th buffer", i); ++ g_list_free (images); ++ g_list_free_full (frames, (GDestroyNotify) gst_video_frame_unmap); ++ g_list_free_full (buffers, (GDestroyNotify) gst_buffer_unref); ++ break; ++ } else { ++ buffers = g_list_append (buffers, buf); ++ frames = g_list_append (frames, frame); ++ images = g_list_append (images, GST_VIDEO_FRAME_PLANE_DATA (frame, 0)); ++ GST_DEBUG_OBJECT (self, " pBuffer: %p", GST_VIDEO_FRAME_PLANE_DATA (frame, 0)); ++ } ++ } ++ } ++ ++ if (images) { ++ is_mapped = TRUE; ++ ++ err = gst_omx_port_use_buffers (port, images); ++ g_list_free (images); ++ g_list_free_full (frames, (GDestroyNotify) gst_video_frame_unmap); ++ ++ if (err == OMX_ErrorNone) { ++ GST_DEBUG_OBJECT (self, "Using %d buffers", n); ++ } else { ++ GST_INFO_OBJECT (self, ++ "Failed to OMX_UseBuffer on port: %s (0x%08x)", ++ gst_omx_error_to_string (err), err); ++ g_list_free_full (buffers, (GDestroyNotify) gst_buffer_unref); ++ return FALSE; ++ } ++ } ++ ++ if ( !is_mapped ) { ++ GST_WARNING_OBJECT (self, " failed to call UseBuffer, trying to use allocation"); ++ self->input_dmabuf = FALSE; ++ self->input_allocation = GST_OMX_BUFFER_ALLOCATION_ALLOCATE_BUFFER; ++ if (gst_omx_port_allocate_buffers (self->enc_in_port) != OMX_ErrorNone){ ++ return FALSE; ++ } ++ } ++ ++ return TRUE; ++} ++#endif ++ + static gboolean + gst_omx_video_enc_allocate_in_buffers (GstOMXVideoEnc * self) + { +@@ -2115,6 +2252,9 @@ + return FALSE; + break; + case GST_OMX_BUFFER_ALLOCATION_USE_BUFFER: ++#ifdef USE_OMX_TARGET_STARFIVE ++ return gst_omx_video_enc_use_buffers(self); ++#endif + default: + /* Not supported */ + g_return_val_if_reached (FALSE); +@@ -2179,8 +2319,18 @@ + gst_omx_video_enc_pick_input_allocation_mode (GstOMXVideoEnc * self, + GstBuffer * inbuf) + { ++#ifdef USE_OMX_TARGET_STARFIVE ++ if (!gst_omx_is_dynamic_allocation_supported ()){ ++ if (gst_is_dmabuf_memory (gst_buffer_peek_memory (inbuf, 0))){ ++ GST_DEBUG_OBJECT (self, "select GST_OMX_BUFFER_ALLOCATION_USE_BUFFER"); ++ return GST_OMX_BUFFER_ALLOCATION_USE_BUFFER; ++ } ++ return GST_OMX_BUFFER_ALLOCATION_ALLOCATE_BUFFER; ++ } ++#else + if (!gst_omx_is_dynamic_allocation_supported ()) + return GST_OMX_BUFFER_ALLOCATION_ALLOCATE_BUFFER; ++#endif + + if (can_use_dynamic_buffer_mode (self, inbuf)) { + GST_DEBUG_OBJECT (self, +@@ -2272,6 +2422,15 @@ + input); + self->input_dmabuf = FALSE; + ++#ifdef USE_OMX_TARGET_STARFIVE ++ if (self->input_allocation == ++ GST_OMX_BUFFER_ALLOCATION_USE_BUFFER) { ++ self->input_dmabuf = TRUE; ++ self->enc_in_port->c_buf = input; ++ GST_DEBUG_OBJECT (self, "input_dmabuf is true"); ++ } ++#endif ++ + #ifdef USE_OMX_TARGET_ZYNQ_USCALE_PLUS + if (gst_is_dmabuf_memory (gst_buffer_peek_memory (input, 0))) { + if (self->input_allocation == +@@ -2786,7 +2945,11 @@ + } + + if (self->enc_in_port->allocation == +- GST_OMX_BUFFER_ALLOCATION_USE_BUFFER_DYNAMIC) { ++ GST_OMX_BUFFER_ALLOCATION_USE_BUFFER_DYNAMIC ++#ifdef USE_OMX_TARGET_STARFIVE ++ || self->enc_in_port->allocation == GST_OMX_BUFFER_ALLOCATION_USE_BUFFER ++#endif ++ ) { + if (gst_buffer_n_memory (inbuf) > 1) { + GST_ELEMENT_ERROR (self, STREAM, FORMAT, (NULL), + ("input buffer now has more than one memory, can't use dynamic allocation any more")); +@@ -2812,12 +2975,29 @@ + gst_buffer_get_size (inbuf)); + } else { + /* dmabuf input */ ++#ifdef USE_OMX_TARGET_STARFIVE ++ if (self->enc_in_port->allocation == GST_OMX_BUFFER_ALLOCATION_USE_BUFFER) { ++ GstMemory *mem = gst_buffer_peek_memory (inbuf, 0); ++ GST_LOG_OBJECT (self, " mem: %p, inbuf: %p, outbuf: %p", mem, inbuf, outbuf); ++ if (!gst_omx_buffer_map_memory (outbuf, mem)) { ++ GST_ELEMENT_ERROR (self, STREAM, FORMAT, (NULL),("failed to import")); ++ GST_ERROR_OBJECT (self, "failed to import dmabuf %p, inbuf: %p",mem, inbuf); ++ return FALSE; ++ } ++ } else { ++ if (!gst_omx_buffer_import_fd (outbuf, inbuf)) { ++ GST_ELEMENT_ERROR (self, STREAM, FORMAT, (NULL), ++ ("failed to import dmabuf")); ++ return FALSE; ++ } ++ } ++#else + if (!gst_omx_buffer_import_fd (outbuf, inbuf)) { + GST_ELEMENT_ERROR (self, STREAM, FORMAT, (NULL), + ("failed to import dmabuf")); + return FALSE; + } +- ++#endif + GST_LOG_OBJECT (self, "Import dmabuf of %" G_GSIZE_FORMAT " bytes", + gst_buffer_get_size (inbuf)); + } From 995214a89edb6351055a98d1488b074c9a85b7b0 Mon Sep 17 00:00:00 2001 From: "sw.multimedia" Date: Thu, 21 Apr 2022 10:03:52 +0800 Subject: [PATCH 12/14] omxmjpegdec: add property 'framerate' for omxmjpegdec. Signed-off-by: sw.multimedia (cherry picked from http://192.168.110.45/jh7100/buildroot/-/commit/fe368e0af9c3bd485245b1fb37b2496300b91e67) --- .../0010-add-property-framerate.patch | 144 ++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 package/starfive/sf-gst-omx/0010-add-property-framerate.patch diff --git a/package/starfive/sf-gst-omx/0010-add-property-framerate.patch b/package/starfive/sf-gst-omx/0010-add-property-framerate.patch new file mode 100644 index 00000000..c007634c --- /dev/null +++ b/package/starfive/sf-gst-omx/0010-add-property-framerate.patch @@ -0,0 +1,144 @@ +--- a/omx/gstomxmjpegdec.h ++++ b/omx/gstomxmjpegdec.h +@@ -45,6 +45,16 @@ + struct _GstOMXMJPEGDec + { + GstOMXVideoDec parent; ++#ifdef USE_OMX_TARGET_STARFIVE ++ //If container shows fps as public api, it won't work ++ //as GstBuffer containing pts/dts/duration and it will calculate fps in upstream. ++ //i.e. ++ //not works: ++ // 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 ++ //works: ++ // gst-launch-1.0 -v filesrc location=xxx.mjpeg ! jpegparse ! omxmjpegdec framerate=xxx ! kmssink driver-name=starfive force-modesetting=1 ++ gint framerate; ++#endif + }; + + struct _GstOMXMJPEGDecClass + +--- a/omx/gstomxmjpegdec.c ++++ b/omx/gstomxmjpegdec.c +@@ -28,16 +28,28 @@ + + GST_DEBUG_CATEGORY_STATIC (gst_omx_mjpeg_dec_debug_category); + #define GST_CAT_DEFAULT gst_omx_mjpeg_dec_debug_category +- ++#ifdef USE_OMX_TARGET_STARFIVE ++#define DEFAULT_FRAMERATE 0 ++#endif + /* prototypes */ + 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, + GstOMXPort * port, GstVideoCodecState * state); +- ++#ifdef USE_OMX_TARGET_STARFIVE ++static void gst_omx_mjpeg_dec_set_property (GObject * object, guint prop_id, ++ const GValue * value, GParamSpec * pspec); ++static void gst_omx_mjpeg_dec_get_property (GObject * object, guint prop_id, ++ GValue * value, GParamSpec * pspec); ++#endif + enum + { ++#ifdef USE_OMX_TARGET_STARFIVE ++ PROP_0, ++ PROP_FRAMERATE ++#else + PROP_0 ++#endif + }; + + /* class initialization */ +@@ -54,11 +66,16 @@ + { + GstOMXVideoDecClass *videodec_class = GST_OMX_VIDEO_DEC_CLASS (klass); + GstElementClass *element_class = GST_ELEMENT_CLASS (klass); +- ++#ifdef USE_OMX_TARGET_STARFIVE ++ GObjectClass *gobject_class = G_OBJECT_CLASS (videodec_class); ++#endif + videodec_class->is_format_change = + GST_DEBUG_FUNCPTR (gst_omx_mjpeg_dec_is_format_change); + videodec_class->set_format = GST_DEBUG_FUNCPTR (gst_omx_mjpeg_dec_set_format); +- ++#ifdef USE_OMX_TARGET_STARFIVE ++ gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_omx_mjpeg_dec_set_property); ++ gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_omx_mjpeg_dec_get_property); ++#endif + videodec_class->cdata.default_sink_template_caps = "image/jpeg, " + "width=(int) [1,MAX], " "height=(int) [1,MAX]"; + +@@ -67,7 +84,16 @@ + "Codec/Decoder/Video/Hardware", + "Decode MJPEG video streams", + "Sebastian Dröge "); +- ++#ifdef USE_OMX_TARGET_STARFIVE ++ g_object_class_install_property (gobject_class, PROP_FRAMERATE, ++ g_param_spec_int ("framerate", ++ "Framerate", ++ "Frames per second in raw stream.\n \ ++ Only workable for the container not exposing fps.\n\ ++ '0' means disabled.", ++ 0, G_MAXINT, ++ DEFAULT_FRAMERATE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); ++#endif + gst_omx_set_default_role (&videodec_class->cdata, "video_decoder.mjpeg"); + } + +@@ -89,10 +115,53 @@ + { + gboolean ret; + OMX_PARAM_PORTDEFINITIONTYPE port_def; ++#ifdef USE_OMX_TARGET_STARFIVE ++ GstVideoInfo *info = &state->info; ++ GstOMXMJPEGDec * mjpeg_dec = GST_OMX_MJPEG_DEC (dec); + ++ if (mjpeg_dec->framerate != DEFAULT_FRAMERATE) { ++ GST_DEBUG_OBJECT (dec, " change fps from %d/%d to %d/1" GST_PTR_FORMAT, info->fps_n, info->fps_d, mjpeg_dec->framerate); ++ info->fps_n = mjpeg_dec->framerate; ++ info->fps_d = 1; ++ if (state->caps) { ++ gst_caps_set_simple (state->caps, "framerate", GST_TYPE_FRACTION, info->fps_n, info->fps_d, NULL); ++ } ++ } ++#endif + gst_omx_port_get_port_definition (port, &port_def); + port_def.format.video.eCompressionFormat = OMX_VIDEO_CodingMJPEG; + ret = gst_omx_port_update_port_definition (port, &port_def) == OMX_ErrorNone; + + return ret; + } ++#ifdef USE_OMX_TARGET_STARFIVE ++static void ++gst_omx_mjpeg_dec_set_property (GObject * object, guint prop_id, ++ const GValue * value, GParamSpec * pspec) ++{ ++ GstOMXMJPEGDec * mjpeg_dec = GST_OMX_MJPEG_DEC (object); ++ switch (prop_id) { ++ case PROP_FRAMERATE: ++ mjpeg_dec->framerate = g_value_get_int (value); ++ break; ++ default: ++ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); ++ break; ++ } ++} ++ ++static void ++gst_omx_mjpeg_dec_get_property (GObject * object, guint prop_id, GValue * value, ++ GParamSpec * pspec) ++{ ++ GstOMXMJPEGDec * mjpeg_dec = GST_OMX_MJPEG_DEC (object); ++ switch (prop_id) { ++ case PROP_FRAMERATE: ++ g_value_set_int (value, mjpeg_dec->framerate); ++ break; ++ default: ++ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); ++ break; ++ } ++} ++#endif From 951fcfe90a52f34edad69f1bcfca6e59dba24370 Mon Sep 17 00:00:00 2001 From: "sw.multimedia" Date: Fri, 6 May 2022 18:35:00 +0800 Subject: [PATCH 13/14] gst-omx: hanle some extra profile about avc. Signed-off-by: sw.multimedia (cherry picked from http://192.168.110.45/jh7100/buildroot/-/commit/39f08c81f5a05ad0b06a95c4a3599602641c07af) --- ...011-hanle-some-extra-profile-for-avc.patch | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 package/starfive/sf-gst-omx/0011-hanle-some-extra-profile-for-avc.patch diff --git a/package/starfive/sf-gst-omx/0011-hanle-some-extra-profile-for-avc.patch b/package/starfive/sf-gst-omx/0011-hanle-some-extra-profile-for-avc.patch new file mode 100644 index 00000000..c9916ed4 --- /dev/null +++ b/package/starfive/sf-gst-omx/0011-hanle-some-extra-profile-for-avc.patch @@ -0,0 +1,38 @@ +--- a/omx/gstomxh264utils.c ++++ b/omx/gstomxh264utils.c +@@ -54,6 +54,19 @@ + #endif + }; + ++#ifdef USE_OMX_TARGET_STARFIVE ++static const H264ProfileMapping h264_ext_profiles[] = { ++ {"progressive-high", ++ (OMX_VIDEO_AVCPROFILETYPE) OMX_VIDEO_AVCProfileHigh}, ++ {"constrained-high", ++ (OMX_VIDEO_AVCPROFILETYPE) OMX_VIDEO_AVCProfileHigh}, ++ {"high-10-intra", ++ (OMX_VIDEO_AVCPROFILETYPE) OMX_VIDEO_AVCProfileHigh10}, ++ {"high-4:2:2-intra", ++ (OMX_VIDEO_AVCPROFILETYPE) OMX_VIDEO_AVCProfileHigh422}, ++}; ++#endif ++ + OMX_VIDEO_AVCPROFILETYPE + gst_omx_h264_utils_get_profile_from_str (const gchar * profile) + { +@@ -63,6 +76,15 @@ + if (g_str_equal (profile, h264_profiles[i].profile)) + return h264_profiles[i].e; + } ++ ++#ifdef USE_OMX_TARGET_STARFIVE ++ for (i = 0; i < G_N_ELEMENTS (h264_ext_profiles); i++) { ++ if (g_str_equal (profile, h264_ext_profiles[i].profile)) { ++ GST_INFO("extra profile: %s ==> avc profie type: %d", profile, h264_ext_profiles[i].e); ++ return h264_ext_profiles[i].e; ++ } ++ } ++#endif + + return OMX_VIDEO_AVCProfileMax; + } From 7e6088067ed0bcc38be5842ce98c192c0385fa2d Mon Sep 17 00:00:00 2001 From: Windsome Zeng Date: Fri, 13 May 2022 12:16:07 +0800 Subject: [PATCH 14/14] Combine SPS/PPS header to IDR frame. (cherry picked from http://192.168.110.45/jh7100/buildroot/-/commit/ed8e94ec351c61073a1408df54fb01b5c1deff2c) --- .../0012-combine-sps-pps-header-to-idr.patch | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 package/starfive/sf-gst-omx/0012-combine-sps-pps-header-to-idr.patch diff --git a/package/starfive/sf-gst-omx/0012-combine-sps-pps-header-to-idr.patch b/package/starfive/sf-gst-omx/0012-combine-sps-pps-header-to-idr.patch new file mode 100644 index 00000000..b5116e84 --- /dev/null +++ b/package/starfive/sf-gst-omx/0012-combine-sps-pps-header-to-idr.patch @@ -0,0 +1,67 @@ +Combine SPS/PPS header to IDR frame. + +Signed-off-by: Windsome Zeng + +diff -purN a/meson.build b/meson.build +--- a/meson.build 2022-05-13 11:31:02.725614796 +0800 ++++ b/meson.build 2022-05-13 11:32:26.213975419 +0800 +@@ -218,6 +218,7 @@ elif omx_target == 'tizonia' + omx_inc = [] + elif omx_target == 'stf' + cdata.set('USE_OMX_TARGET_STARFIVE', 1) ++ gst_omx_args += ['-DCOMBINE_SPS_PPS_HEADERS'] + warning('stf selected') + else + error ('Unsupported omx target specified. Use the -Dtarget option') +diff -purN a/omx/gstomx.c b/omx/gstomx.c +--- a/omx/gstomx.c 2022-05-13 11:31:02.725614796 +0800 ++++ b/omx/gstomx.c 2022-05-13 11:33:15.461950978 +0800 +@@ -70,6 +70,11 @@ static GHashTable *core_handles; + G_LOCK_DEFINE_STATIC (buffer_flags_str); + static GHashTable *buffer_flags_str; + ++#ifdef COMBINE_SPS_PPS_HEADERS ++static OMX_U8 *sps_pps_header = NULL; ++static OMX_U32 sps_pps_header_size = 0; ++#endif ++ + GstOMXCore * + gst_omx_core_acquire (const gchar * filename) + { +@@ -903,6 +908,36 @@ FillBufferDone (OMX_HANDLETYPE hComponen + + g_assert (buf->omx_buf == pBuffer); + ++#ifdef COMBINE_SPS_PPS_HEADERS ++ if (pBuffer->nFlags == 0x80) { ++ g_assert (sps_pps_header == NULL); ++ if (sps_pps_header) ++ g_free (sps_pps_header); ++ ++ sps_pps_header = g_new (OMX_U8, pBuffer->nFilledLen); ++ if (sps_pps_header) { ++ sps_pps_header_size = pBuffer->nFilledLen; ++ memcpy(sps_pps_header, pBuffer->pBuffer + pBuffer->nOffset, pBuffer->nFilledLen); ++ } ++ return OMX_ErrorNone; ++ } ++ ++ if (sps_pps_header) { ++ g_assert (sps_pps_header_size + pBuffer->nFilledLen <= pBuffer->nAllocLen); ++ if (sps_pps_header_size + pBuffer->nFilledLen <= pBuffer->nAllocLen) { ++ OMX_U8 *buf; ++ buf = pBuffer->pBuffer + pBuffer->nOffset; ++ memmove (buf + sps_pps_header_size, buf, pBuffer->nFilledLen); ++ memcpy (buf, sps_pps_header, sps_pps_header_size); ++ pBuffer->nFilledLen += sps_pps_header_size; ++ ++ g_free (sps_pps_header); ++ sps_pps_header = NULL; ++ sps_pps_header_size = 0; ++ } ++ } ++#endif /* COMBINE_SPS_PPS_HEADERS */ ++ + if (buf->port->tunneled) { + GST_ERROR ("FillBufferDone on tunneled port"); + return OMX_ErrorBadParameter;