From d0ffcb46df08696316d829123921db2cd5d1a593 Mon Sep 17 00:00:00 2001 From: Ratchanan Srirattanamet Date: Sun, 12 Nov 2023 02:27:22 +0700 Subject: [PATCH] androidmedia: call all static_init() functions from single entry point This allows the implementations to do custom logic behind the hood. For example, when NDK implementation is added, the entrypoint can chooses to statically initialize the NDK implementations or the JNI one. Part-of: --- .../sys/androidmedia/gstamc-codec.h | 2 - .../sys/androidmedia/gstamc-codeclist.h | 2 - .../sys/androidmedia/gstamc-format.h | 2 - .../gst-plugins-bad/sys/androidmedia/gstamc.c | 11 +----- .../gst-plugins-bad/sys/androidmedia/gstamc.h | 2 + .../sys/androidmedia/gstamcsurfacetexture.h | 2 - .../sys/androidmedia/jni/gstamc-codec-jni.c | 3 +- .../androidmedia/jni/gstamc-codeclist-jni.c | 4 +- .../sys/androidmedia/jni/gstamc-format-jni.c | 3 +- .../sys/androidmedia/jni/gstamc-jni.c | 39 +++++++++++++++++++ .../sys/androidmedia/jni/gstamc-jni.h | 25 ++++++++++++ .../jni/gstamcsurfacetexture-jni.c | 3 +- .../androidmedia/magicleap/gstamc-codec-ml.c | 6 --- .../magicleap/gstamc-codeclist-ml.c | 6 --- .../androidmedia/magicleap/gstamc-format-ml.c | 6 --- .../sys/androidmedia/magicleap/gstamc-ml.c | 30 ++++++++++++++ .../magicleap/gstamc-surfacetexture-ml.c | 6 --- .../sys/androidmedia/meson.build | 2 + 18 files changed, 108 insertions(+), 46 deletions(-) create mode 100644 subprojects/gst-plugins-bad/sys/androidmedia/jni/gstamc-jni.c create mode 100644 subprojects/gst-plugins-bad/sys/androidmedia/jni/gstamc-jni.h create mode 100644 subprojects/gst-plugins-bad/sys/androidmedia/magicleap/gstamc-ml.c diff --git a/subprojects/gst-plugins-bad/sys/androidmedia/gstamc-codec.h b/subprojects/gst-plugins-bad/sys/androidmedia/gstamc-codec.h index 9c40f58da8..ce5d5a2e64 100644 --- a/subprojects/gst-plugins-bad/sys/androidmedia/gstamc-codec.h +++ b/subprojects/gst-plugins-bad/sys/androidmedia/gstamc-codec.h @@ -44,8 +44,6 @@ struct _GstAmcBufferInfo { gint size; }; -gboolean gst_amc_codec_static_init (void); - void gst_amc_buffer_free (GstAmcBuffer * buffer); gboolean gst_amc_buffer_set_position_and_limit (GstAmcBuffer * buffer, GError ** err, gint position, gint limit); diff --git a/subprojects/gst-plugins-bad/sys/androidmedia/gstamc-codeclist.h b/subprojects/gst-plugins-bad/sys/androidmedia/gstamc-codeclist.h index f7ebb01c13..f7ce2eae6f 100644 --- a/subprojects/gst-plugins-bad/sys/androidmedia/gstamc-codeclist.h +++ b/subprojects/gst-plugins-bad/sys/androidmedia/gstamc-codeclist.h @@ -35,8 +35,6 @@ struct _GstAmcCodecProfileLevel gint level; }; -gboolean gst_amc_codeclist_static_init (void); - gboolean gst_amc_codeclist_get_count (gint * count, GError **err); GstAmcCodecInfoHandle * gst_amc_codeclist_get_codec_info_at (gint index, GError **err); diff --git a/subprojects/gst-plugins-bad/sys/androidmedia/gstamc-format.h b/subprojects/gst-plugins-bad/sys/androidmedia/gstamc-format.h index b78d161578..8126ab039d 100644 --- a/subprojects/gst-plugins-bad/sys/androidmedia/gstamc-format.h +++ b/subprojects/gst-plugins-bad/sys/androidmedia/gstamc-format.h @@ -28,8 +28,6 @@ G_BEGIN_DECLS typedef struct _GstAmcFormat GstAmcFormat; typedef struct _GstAmcColorFormatInfo GstAmcColorFormatInfo; -gboolean gst_amc_format_static_init (void); - GstAmcFormat * gst_amc_format_new_audio (const gchar *mime, gint sample_rate, gint channels, GError **err); GstAmcFormat * gst_amc_format_new_video (const gchar *mime, gint width, gint height, GError **err); void gst_amc_format_free (GstAmcFormat * format); diff --git a/subprojects/gst-plugins-bad/sys/androidmedia/gstamc.c b/subprojects/gst-plugins-bad/sys/androidmedia/gstamc.c index 2da4657bd5..82fcdb6e94 100644 --- a/subprojects/gst-plugins-bad/sys/androidmedia/gstamc.c +++ b/subprojects/gst-plugins-bad/sys/androidmedia/gstamc.c @@ -1840,16 +1840,7 @@ amc_init (GstPlugin * plugin) gst_amc_codec_info_quark = g_quark_from_static_string ("gst-amc-codec-info"); - if (!gst_amc_codeclist_static_init ()) - return FALSE; - - if (!gst_amc_codec_static_init ()) - return FALSE; - - if (!gst_amc_format_static_init ()) - return FALSE; - - if (!gst_amc_surface_texture_static_init ()) + if (!gst_amc_static_init ()) return FALSE; /* Set this to TRUE to allow registering decoders that have diff --git a/subprojects/gst-plugins-bad/sys/androidmedia/gstamc.h b/subprojects/gst-plugins-bad/sys/androidmedia/gstamc.h index 511665de38..2434089666 100644 --- a/subprojects/gst-plugins-bad/sys/androidmedia/gstamc.h +++ b/subprojects/gst-plugins-bad/sys/androidmedia/gstamc.h @@ -53,6 +53,8 @@ struct _GstAmcCodecInfo { extern GQuark gst_amc_codec_info_quark; +gboolean gst_amc_static_init (void); + GstVideoFormat gst_amc_color_format_to_video_format (const GstAmcCodecInfo * codec_info, const gchar * mime, gint color_format); gint gst_amc_video_format_to_color_format (const GstAmcCodecInfo * codec_info, const gchar * mime, GstVideoFormat video_format); diff --git a/subprojects/gst-plugins-bad/sys/androidmedia/gstamcsurfacetexture.h b/subprojects/gst-plugins-bad/sys/androidmedia/gstamcsurfacetexture.h index 5c7f7c539f..69a70b3363 100644 --- a/subprojects/gst-plugins-bad/sys/androidmedia/gstamcsurfacetexture.h +++ b/subprojects/gst-plugins-bad/sys/androidmedia/gstamcsurfacetexture.h @@ -65,8 +65,6 @@ struct _GstAmcSurfaceTextureClass GError ** err); }; -gboolean gst_amc_surface_texture_static_init (void); - gboolean gst_amc_surface_texture_update_tex_image (GstAmcSurfaceTexture *texture, GError ** err); diff --git a/subprojects/gst-plugins-bad/sys/androidmedia/jni/gstamc-codec-jni.c b/subprojects/gst-plugins-bad/sys/androidmedia/jni/gstamc-codec-jni.c index dcc1314f64..49a5dc643a 100644 --- a/subprojects/gst-plugins-bad/sys/androidmedia/jni/gstamc-codec-jni.c +++ b/subprojects/gst-plugins-bad/sys/androidmedia/jni/gstamc-codec-jni.c @@ -26,6 +26,7 @@ #include "../gstjniutils.h" #include "../gstamc-codec.h" #include "../gstamc-constants.h" +#include "gstamc-jni.h" #include "gstamc-internal-jni.h" #include "gstamcsurfacetexture-jni.h" #include "gstamcsurface.h" @@ -90,7 +91,7 @@ static struct } java_nio_buffer; gboolean -gst_amc_codec_static_init (void) +gst_amc_codec_jni_static_init (void) { gboolean ret = TRUE; JNIEnv *env; diff --git a/subprojects/gst-plugins-bad/sys/androidmedia/jni/gstamc-codeclist-jni.c b/subprojects/gst-plugins-bad/sys/androidmedia/jni/gstamc-codeclist-jni.c index 6e88aeb05e..dbb0f98bac 100644 --- a/subprojects/gst-plugins-bad/sys/androidmedia/jni/gstamc-codeclist-jni.c +++ b/subprojects/gst-plugins-bad/sys/androidmedia/jni/gstamc-codeclist-jni.c @@ -26,6 +26,8 @@ #include "../gstjniutils.h" #include "../gstamc-codeclist.h" +#include "gstamc-jni.h" + struct _GstAmcCodecInfoHandle { jobject object; @@ -67,7 +69,7 @@ static struct } media_codecprofilelevel; gboolean -gst_amc_codeclist_static_init (void) +gst_amc_codeclist_jni_static_init (void) { JNIEnv *env; GError *err = NULL; diff --git a/subprojects/gst-plugins-bad/sys/androidmedia/jni/gstamc-format-jni.c b/subprojects/gst-plugins-bad/sys/androidmedia/jni/gstamc-format-jni.c index 784f93f0f1..898b76769d 100644 --- a/subprojects/gst-plugins-bad/sys/androidmedia/jni/gstamc-format-jni.c +++ b/subprojects/gst-plugins-bad/sys/androidmedia/jni/gstamc-format-jni.c @@ -25,6 +25,7 @@ #include "../gstjniutils.h" #include "../gstamc-format.h" +#include "gstamc-jni.h" #include "gstamc-internal-jni.h" static struct @@ -44,7 +45,7 @@ static struct } media_format; gboolean -gst_amc_format_static_init (void) +gst_amc_format_jni_static_init (void) { gboolean ret = TRUE; JNIEnv *env; diff --git a/subprojects/gst-plugins-bad/sys/androidmedia/jni/gstamc-jni.c b/subprojects/gst-plugins-bad/sys/androidmedia/jni/gstamc-jni.c new file mode 100644 index 0000000000..dde3c667ca --- /dev/null +++ b/subprojects/gst-plugins-bad/sys/androidmedia/jni/gstamc-jni.c @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2023, Ratchanan Srirattanamet + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation + * version 2.1 of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include "../gstamc.h" +#include "gstamc-jni.h" + +gboolean +gst_amc_static_init (void) +{ + if (!gst_amc_codeclist_jni_static_init ()) + return FALSE; + + if (!gst_amc_codec_jni_static_init ()) + return FALSE; + + if (!gst_amc_format_jni_static_init ()) + return FALSE; + + if (!gst_amc_surface_texture_jni_static_init ()) + return FALSE; + + return TRUE; +} diff --git a/subprojects/gst-plugins-bad/sys/androidmedia/jni/gstamc-jni.h b/subprojects/gst-plugins-bad/sys/androidmedia/jni/gstamc-jni.h new file mode 100644 index 0000000000..1ecaf2741d --- /dev/null +++ b/subprojects/gst-plugins-bad/sys/androidmedia/jni/gstamc-jni.h @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2023, Ratchanan Srirattanamet + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation + * version 2.1 of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include + +gboolean gst_amc_codeclist_jni_static_init (void); +gboolean gst_amc_format_jni_static_init (void); +gboolean gst_amc_codec_jni_static_init (void); +gboolean gst_amc_surface_texture_jni_static_init (void); diff --git a/subprojects/gst-plugins-bad/sys/androidmedia/jni/gstamcsurfacetexture-jni.c b/subprojects/gst-plugins-bad/sys/androidmedia/jni/gstamcsurfacetexture-jni.c index ec573de4f8..8438b8ce89 100644 --- a/subprojects/gst-plugins-bad/sys/androidmedia/jni/gstamcsurfacetexture-jni.c +++ b/subprojects/gst-plugins-bad/sys/androidmedia/jni/gstamcsurfacetexture-jni.c @@ -27,6 +27,7 @@ #include "gstjniutils.h" #include "gstamcsurfacetexture-jni.h" +#include "gstamc-jni.h" struct _GstAmcSurfaceTextureJNI { @@ -58,7 +59,7 @@ G_DEFINE_TYPE (GstAmcSurfaceTextureJNI, gst_amc_surface_texture_jni, GST_TYPE_AMC_SURFACE_TEXTURE); gboolean -gst_amc_surface_texture_static_init (void) +gst_amc_surface_texture_jni_static_init (void) { JNIEnv *env; GError *err = NULL; diff --git a/subprojects/gst-plugins-bad/sys/androidmedia/magicleap/gstamc-codec-ml.c b/subprojects/gst-plugins-bad/sys/androidmedia/magicleap/gstamc-codec-ml.c index e40df33ca8..660a5b8142 100644 --- a/subprojects/gst-plugins-bad/sys/androidmedia/magicleap/gstamc-codec-ml.c +++ b/subprojects/gst-plugins-bad/sys/androidmedia/magicleap/gstamc-codec-ml.c @@ -35,12 +35,6 @@ struct _GstAmcCodec GstAmcSurfaceTexture *surface_texture; }; -gboolean -gst_amc_codec_static_init (void) -{ - return TRUE; -} - void gst_amc_buffer_free (GstAmcBuffer * buffer) { diff --git a/subprojects/gst-plugins-bad/sys/androidmedia/magicleap/gstamc-codeclist-ml.c b/subprojects/gst-plugins-bad/sys/androidmedia/magicleap/gstamc-codeclist-ml.c index d2b38d8736..003bdd9c81 100644 --- a/subprojects/gst-plugins-bad/sys/androidmedia/magicleap/gstamc-codeclist-ml.c +++ b/subprojects/gst-plugins-bad/sys/androidmedia/magicleap/gstamc-codeclist-ml.c @@ -37,12 +37,6 @@ struct _GstAmcCodecCapabilitiesHandle gchar *type; }; -gboolean -gst_amc_codeclist_static_init (void) -{ - return TRUE; -} - gboolean gst_amc_codeclist_get_count (gint * count, GError ** err) { diff --git a/subprojects/gst-plugins-bad/sys/androidmedia/magicleap/gstamc-format-ml.c b/subprojects/gst-plugins-bad/sys/androidmedia/magicleap/gstamc-format-ml.c index e27c305323..6dada3cdc9 100644 --- a/subprojects/gst-plugins-bad/sys/androidmedia/magicleap/gstamc-format-ml.c +++ b/subprojects/gst-plugins-bad/sys/androidmedia/magicleap/gstamc-format-ml.c @@ -32,12 +32,6 @@ struct _GstAmcFormat MLHandle handle; }; -gboolean -gst_amc_format_static_init (void) -{ - return TRUE; -} - GstAmcFormat * gst_amc_format_new_audio (const gchar * mime, gint sample_rate, gint channels, GError ** err) diff --git a/subprojects/gst-plugins-bad/sys/androidmedia/magicleap/gstamc-ml.c b/subprojects/gst-plugins-bad/sys/androidmedia/magicleap/gstamc-ml.c new file mode 100644 index 0000000000..ca4a8f7d21 --- /dev/null +++ b/subprojects/gst-plugins-bad/sys/androidmedia/magicleap/gstamc-ml.c @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2023, Ratchanan Srirattanamet + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation + * version 2.1 of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include "../gstamc.h" + +gboolean +gst_amc_static_init (void) +{ + /* + * MagicLeap doesn't require any static initialization. All required + * functions are in C and are linked into the plugin directly. + */ + return TRUE; +} diff --git a/subprojects/gst-plugins-bad/sys/androidmedia/magicleap/gstamc-surfacetexture-ml.c b/subprojects/gst-plugins-bad/sys/androidmedia/magicleap/gstamc-surfacetexture-ml.c index c42f8294f9..f1bb3913b8 100644 --- a/subprojects/gst-plugins-bad/sys/androidmedia/magicleap/gstamc-surfacetexture-ml.c +++ b/subprojects/gst-plugins-bad/sys/androidmedia/magicleap/gstamc-surfacetexture-ml.c @@ -39,12 +39,6 @@ struct _GstAmcSurfaceTextureML G_DEFINE_TYPE (GstAmcSurfaceTextureML, gst_amc_surface_texture_ml, GST_TYPE_AMC_SURFACE_TEXTURE); -gboolean -gst_amc_surface_texture_static_init (void) -{ - return TRUE; -} - static gboolean gst_amc_surface_texture_ml_update_tex_image (GstAmcSurfaceTexture * base, GError ** err) diff --git a/subprojects/gst-plugins-bad/sys/androidmedia/meson.build b/subprojects/gst-plugins-bad/sys/androidmedia/meson.build index 7199faea2f..9fffe4ae0b 100644 --- a/subprojects/gst-plugins-bad/sys/androidmedia/meson.build +++ b/subprojects/gst-plugins-bad/sys/androidmedia/meson.build @@ -39,6 +39,7 @@ extra_deps = [] extra_cargs = [] if have_mlsdk androidmedia_sources += [ + 'magicleap/gstamc-ml.c', 'magicleap/gstamc-codec-ml.c', 'magicleap/gstamc-codeclist-ml.c', 'magicleap/gstamc-format-ml.c', @@ -65,6 +66,7 @@ else 'gst-android-hardware-camera.c', 'gst-android-hardware-sensor.c', 'gstjniutils.c', + 'jni/gstamc-jni.c', 'jni/gstamc-codec-jni.c', 'jni/gstamc-codeclist-jni.c', 'jni/gstamc-format-jni.c',