Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Does anyone know where nativeInit GStreamer is? #16

Open
khomin opened this issue Feb 10, 2024 · 2 comments
Open

Does anyone know where nativeInit GStreamer is? #16

khomin opened this issue Feb 10, 2024 · 2 comments

Comments

@khomin
Copy link

khomin commented Feb 10, 2024

Does anyone know where nativeInit GStreamer is?

I have cmake for my project
It works fine except 'ahc'

I see 2 different 'nativeInit' methods

public class GStreamer {
    private static native void nativeInit(Context context) throws Exception;

    public static void init(Context context) throws Exception {
        copyFonts(context);
        copyCaCertificates(context);
        nativeInit(context);
    }
private GstAhc(Context context) {
        nativeInit();

But i see one JNI in 'android_camera.c' only
So i had to comment the first nativeInit in Gstreamer.java
But gst_element_factory_make("ahcsrc".. returns NULL

Apparently i still need GStreamer nativeInit to init 'ahc'

I searched for it in the whole gstreamer sources and could not find it

@ramgalin
Copy link

ramgalin commented Feb 11, 2024

I came up with the same problem (but actually I am trying to build my own project, not gst-android-camera). For me also gst_element_factory_make returns nullptr to everything I am trying create.

So far, my investigations brought me to the following. This "nativeInit" is actually in a library "gstreamer_android.so" which is actually automatically builds from "gstreamer_android-1.0.c.in" file (this file is placed in "$GSTREAMER_ROOT/$ANDROID_ABI/gst-android/ndk-build/"). You can see this lib is linked on 29th line:
https://github.com/justinjoy/gst-android-camera/blob/master/app/src/main/jni/Android.mk

This file is automatically generated by makefiles of gstreamer. Inside of this file, there are generated lines to include static plugins, kind of this:

...
GST_PLUGIN_STATIC_DECLARE(coreelements);
GST_PLUGIN_STATIC_DECLARE(ahcsrc);
GST_PLUGIN_STATIC_DECLARE(videotestsrc);
...

void gst_android_register_static_plugins() {
    ...
    GST_PLUGIN_STATIC_REGISTER(coreelements);
    GST_PLUGIN_STATIC_REGISTER(ahcsrc);
    GST_PLUGIN_STATIC_REGISTER(videotestsrc);
    ...
    __android_log_print (ANDROID_LOG_INFO, TAG, "plugins registered");
}

As I said all of these is made automatically, so if you work with makefile, you should just make sure that everything is set up correctly. I am working with CMake, so I did all of this work manually following the example. Also this link has quite good explanations for the related stuff.

Also in Android logcat I found the following lines generated by GStreamer which look strange:

GStreamer+...EMENT_PADS com.test.video_lib_playground     D  0:00:00.013422625 0xb4000077c1ee9000 ../gst/gstelement.c:316:gst_element_base_class_init type GstElement : factory 0x0
GStreamer+...EMENT_PADS com.test.video_lib_playground     D  0:00:00.013720292 0xb4000077c1ee9000 ../gst/gstelement.c:316:gst_element_base_class_init type GstBin : factory 0x0

So far i couldn't find solution for the problem, but hope that this additional info will help in search for the solution.

@khomin
Copy link
Author

khomin commented Feb 18, 2024

I ended up with with Camera2 and ImageReader

val i: Image? = reader.acquireLatestImage()

then planes go to:
jni -> libyuv -> gstreamer appsrc

auto dst_argb_size = width * height * 4;
auto dst_argb = std::shared_ptr<uint8_t>(new uint8_t[dst_argb_size]);

libyuv::Android420ToABGR(yPlaneCopy.get(),
                    yStride,
                    uPlaneCopy.get(),
                    uStride,
                    vPlaneCopy.get(),
                    vStride,
                    uvPixelStride,
                    dst_argb.get(),
                    width * 4,
                    width, height);

Performance seems ok

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants