How to add gstreamer and selected plugins to AOSP module?

Hi,
Trying to add previously downloaded gstreamer static libs(gstreamer-1.0-android-universal-1.14.5 need older version) to my AOSP audio module in Anroid.bp like this:

cc_library {
    name: "mygstreamer_pipeline",
    vendor: true,
    defaults: ["cpp_library_defaults"],
    srcs: [
        "default/mysrc/*.cpp"
    ],
    export_include_dirs: ["default/myincludes/include"],
    static_libs: [
        "libgstreamer",
        "libgmodule",
        "libgobject",
        "libffi",
        "libglib",
        "libintl",
        "libiconv",
        "libgstrtp",
    ],
    shared_libs: ["liblog",],
    cflags: [
        "-ggdb",
    ],

Example of one of the static libs above

cc_prebuilt_library_static {
    name: "libgobject",
    strip: {
        none: true,
    },
    vendor: true,
    compile_multilib: "both",
    target: {
        android_x86_64: {
        srcs: ["prebuilt/gstreamer-1.0-android-universal-1.14.5/x86_64/lib/libgobject-2.0.a"],
        },
        android_x86: {
            srcs: ["prebuilt/gstreamer-1.0-android-universal-1.14.5/x86/lib/libgobject-2.0.a"],
        }
    }
}

Everything compiles but when code trying to create whole pipeline the only element that is created is pipeline(gst_pipeline_new) but no plugins(like appsrc, rtpbin etc…).

How can I fix it or compile maybe differently libs to my module?
Thanks upfront.

1.14 is ancient at this point, FWIW.

The Android binaries provided by the GStreamer project are meant to be used inside Android apps, and come with a custom build system for apps. Specifically, all plugins are statically linked into the app and the build system is adding initialization code for all selected plugins.

For AOSP integration you’re probably better off compiling GStreamer yourself instead of using the binaries. Either dynamically linked or statically linked (but then you need to actually link to the plugins you want to use and initialize them). Or if you use 1.24 or newer you can also build a single GStreamer library with all plugins (and their dependencies) that you want to use and have it initialize those automatically (“gstreamer-full”).

Alternatively, you could statically link the plugins and initialize them accordingly inside your code, just like the app build system would do (check the ndk-build parts that come with the binaries for inspiration).

Thanks for fast answer.
Compiling GStreamer was my first option but I failed due to many errors and then some “Wrong version of Ubuntu”, maybe its because I wanted to make 1.14 version of lib.

As for alternative option, hope I got you right, this what helped to compile and see plugins alive:
All, static libs for plugins and dependencies was added as

cc_prebuilt_library_static {name: "libgobject"...}
to cc_library { name: "mygstreamer_pipeline", static_libs: ["libgobject", ...], }

and then called from pipeline init class, like

extern "C" {
    void gst_plugin_app_register();
    void gst_plugin_rtpmanager_register();
    void gst_plugin_rtp_register();
    void gst_plugin_udp_register();
    void gst_plugin_audioconvert_register();
    void gst_plugin_rawparse_register();
}

bool init_gstream_audio(RtpStreamPipe *rtp_pipe) {

// Initialize GStreamer
    gst_init(NULL, NULL);
    gst_plugin_app_register();
    gst_plugin_rtpmanager_register();
    gst_plugin_rtp_register();
    gst_plugin_udp_register();
    gst_plugin_audioconvert_register();
    gst_plugin_rawparse_register();

Dont think its perfect but working for now, so thank you :slight_smile:

Hi, i am new to gstreamer and android but i am trying something similar to you and facing same issue like you.
I also tried gstreamer prebuilt binaries to AOSP under external/gstreamer* directory in the source tree, this is my Android.bp file under external/gstreamer directory:

cc_prebuilt_library_static {
    name: "libglib",
    strip: {
        none: true,
    },
    vendor: true,
    compile_multilib: "both",
    target: {
        android_x86_64: {
            srcs: ["x86_64/lib/libglib-2.0.a"],
            export_include_dirs: [
                "x86_64/include/glib-2.0",
                "x86_64/lib/glib-2.0/include",
            ],
        },
        android_x86: {
            srcs: ["x86/lib/libglib-2.0.a"],
            export_include_dirs: [
                "x86/include/glib-2.0",
                "x86/lib/glib-2.0/include",
            ],
        }
    },
}

cc_prebuilt_library_static {
    name: "libgstapp",
    strip: {
        none: true,
    },
    vendor: true,
    compile_multilib: "both",
    target: {
        android_x86_64: {
            srcs: ["x86_64/lib/libgstapp-1.0.a"],
            export_include_dirs: [
            	"x86_64/include",
                
            ],
        },
        android_x86: {
            srcs: ["x86/lib/libgstapp-1.0.a"],
            export_include_dirs: [
                "x86/include",
            ],
        }
    },
}

cc_prebuilt_library_static {
    name: "libgstbase",
    strip: {
        none: true,
    },
    vendor: true,
    compile_multilib: "both",
    target: {
        android_x86_64: {
            srcs: ["x86_64/lib/libgstbase-1.0.a"],
            export_include_dirs: [
                "x86_64/include",
                
            ],
        },
        android_x86: {
            srcs: ["x86/lib/libgstbase-1.0.a"],
            export_include_dirs: [
                "x86/include",
                
            ],
        }
    },
}

cc_prebuilt_library_static {
    name: "libgobject",
    strip: {
        none: true,
    },
    vendor: true,
    compile_multilib: "both",
    target: {
        android_x86_64: {
            srcs: ["x86_64/lib/libgobject-2.0.a"],
            export_include_dirs: [
            	
                "x86_64/include",
            ],
        },
        android_x86: {
            srcs: ["x86/lib/libgobject-2.0.a"],
            export_include_dirs: [
                "x86/include",
                
            ],
        }
    },
}

cc_prebuilt_library_static {
    name: "libffi",
    strip: {
        none: true,
    },
    vendor: true,
    compile_multilib: "both",
    target: {
        android_x86_64: {
            srcs: ["x86_64/lib/libffi.a"],
            export_include_dirs: [
            
                "x86_64/include",
            ],
        },
        android_x86: {
            srcs: ["x86/lib/libffi.a"],
            export_include_dirs: [
                "x86/include",
                
            ],
        }
    },
}

cc_prebuilt_library_static {
    name: "libintl",
    strip: {
        none: true,
    },
    vendor: true,
    compile_multilib: "both",
    target: {
        android_x86_64: {
            srcs: ["x86_64/lib/libintl.a"],
            export_include_dirs: [
                "x86_64/include",
            ],
        },
        android_x86: {
            srcs: ["x86/lib/libintl.a"],
            export_include_dirs: [
                "x86/include",
            ],
        }
    },
}

cc_prebuilt_library_static {
    name: "libgstreamer",
    strip: {
        none: true,
    },
    vendor: true,
    compile_multilib: "both",
    target: {
        android_x86_64: {
            srcs: ["x86_64/lib/libgstreamer-1.0.a"],
            export_include_dirs: [
            	"x86_64/include/glib-2.0",
                "x86_64/include/gstreamer-1.0",
            ],
        },
        android_x86: {
            srcs: ["x86/lib/libgstreamer-1.0.a"],
            export_include_dirs: [
                "x86/include/gstreamer-1.0",
                "x86/include/glib-2.0",
            ],
        }
    },
    static_libs: [
        "libglib",
        "libintl",
        "libgmodule",
        "libiconv",
        "libpcre2",
        "libgstapp",
        "libgobject",
        "libgstbase",
        "libgstplugin",
    ],
}


cc_prebuilt_library_static {
    name: "libgmodule",
    strip: {
        none: true,
    },
    vendor: true,
    compile_multilib: "both",
    target: {
        android_x86_64: {
            srcs: ["x86_64/lib/libgmodule-2.0.a"],
            export_include_dirs: [
                "x86_64/include/glib-2.0",
            
            ],
        },
        android_x86: {
            srcs: ["x86/lib/libgmodule-2.0.a"],
            export_include_dirs: [
                "x86/include/glib-2.0",
            
            ],
        }
    },
}

cc_prebuilt_library_static {
    name: "libgstplugin",
    strip: {
        none: true,
    },
    vendor: true,
    compile_multilib: "both",
    target: {
        android_x86_64: {
            srcs: ["x86_64/lib/gstreamer-1.0/libgstapp.a"],
            export_include_dirs: [
                "x86_64/include",
            
            ],
        },
        android_x86: {
            srcs: ["x86/lib/gstreamer-1.0/libgstapp.a"],
            export_include_dirs: [
                "x86/include",
            
            ],
        }
    },
    static_libs: [
        "libglib",
        "libintl",
        "libgmodule",
        "libiconv",
        "libpcre2",
        "libgstapp",
        "libgobject",
        "libgstbase",
    ],
}

cc_prebuilt_library_static {
    name: "libiconv",
    strip: {
        none: true,
    },
    vendor: true,
    compile_multilib: "both",
    target: {
        android_x86_64: {
            srcs: ["x86_64/lib/libiconv.a"],
            export_include_dirs: [
            	"x86_64/include",
                
            ],
        },
        android_x86: {
            srcs: ["x86/lib/libiconv.a"],
            export_include_dirs: [
                "x86/include/",
               
            ],
        }
    },
}

cc_prebuilt_library_static {
    name: "libpcre2",
    strip: {
        none: true,
    },
    vendor: true,
    compile_multilib: "both",
    target: {
        android_x86_64: {
            srcs: ["x86_64/lib/libpcre2-8.a"],
            export_include_dirs: [
          
                "x86_64/include",
            ],
        },
        android_x86: {
            srcs: ["x86/lib/libpcre2-8.a"],
            export_include_dirs: [
                "x86/include",
               
            ],
        }
    },
}


And then under this directory device/generic/goldfish/audio i am linking those libraries in this Android.bp file:


//
// Copyright (C) 2011 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package {
    default_applicable_licenses: ["device_generic_goldfish_audio_license"],
}

// Added automatically by a large-scale-change
// See: http://go/android-license-faq
license {
    name: "device_generic_goldfish_audio_license",
    visibility: [":__subpackages__"],
    license_kinds: [
        "SPDX-license-identifier-Apache-2.0",
    ],
    license_text: [
        "NOTICE",
    ],
}

cc_library_shared {
    name: "android.hardware.audio.legacy@7.0-impl.ranchu",
    defaults: ["android.hardware.audio@7.0-impl_default"],
    relative_install_path: "hw",
    vendor: true,
}

cc_defaults {
    name: "android.hardware.audio@7.x-impl.ranchu_default",
    vendor: true,
    relative_install_path: "hw",
    defaults: ["hidl_defaults"],
    srcs: [
        "entry.cpp",
        "device_factory.cpp",
        "primary_device.cpp",
        "stream_common.cpp",
        "stream_in.cpp",
        "stream_out.cpp",
        "io_thread.cpp",
        "device_port_source.cpp",
        "device_port_sink.cpp",
        "talsa.cpp",
        "ring_buffer.cpp",
        "audio_ops.cpp",
        "util.cpp",
    ],
    shared_libs: [
        "android.hardware.audio@7.0",
        "android.hardware.audio@7.0-util",
        "android.hardware.audio.common@7.0",
        "android.hardware.audio.common@7.0-util",
        "libaudioutils",
        "libbase",
        "libcutils",
        "libhidlbase",
        "liblog",
        "libtinyalsav2",
        "libutils",
        "libfmq",
        "libprocessgroup",
       // "mygstreamer",
    ],
    static_libs: [
    	"libgstreamer",
   	    "libglib",
    	"libintl",
    	"libgobject",
    	"libgmodule",   // Added gmodule dependency
        "libiconv",    // Added libiconv dependency
        "libpcre2",    // Added pcre2 dependency
        "libffi",
        "libgstapp",
        "libgstbase",
        
    	],
    header_libs: [
        "android.hardware.audio.common.util@all-versions",
        "libaudio_system_headers",
    ],
    cflags: [
        "-include common/all-versions/VersionMacro.h",
    ],
}


cc_library_shared {
    name: "android.hardware.audio@7.0-impl.ranchu",
    defaults: ["android.hardware.audio@7.x-impl.ranchu_default"],
    vintf_fragments: ["android.hardware.audio@7.0-impl.ranchu.xml"],
    shared_libs: [
        "android.hardware.audio.common@7.0-enums",
    ],
    cflags: [
        "-DLOG_TAG=\"android.hardware.audio@7.0-impl.ranchu\"",
        "-DMAJOR_VERSION=7",
        "-DMINOR_VERSION=0",
        "-include common/all-versions/VersionMacro.h",
    ],
    // a.h.audio@X.0-impl.ranchu (see above) loads a.h.audio.legacy@X.0-impl
    // which loads:
    //  - audio.r_submix.default which provides the r_submix device (b/161485545)
    //  - audio.a2dp.default which provides the a2dp device (b/228804498)
    //  - audio.bluetooth.default which provides the bluetooth device (b/228804498)
    // This should be retired once we don't need to load the
    // deprecated libhardware modules listed above.
    //
    // audio.a2dp.default is not part of the required list as it's already in the
    // generic system image
    required: [
        "android.hardware.audio.legacy@7.0-impl.ranchu",
        "audio.r_submix.default",
        "audio.bluetooth.default",
    ],
}

cc_library_shared {
    name: "android.hardware.audio.legacy@7.1-impl.ranchu",
    defaults: ["android.hardware.audio@7.1-impl_default"],
    relative_install_path: "hw",
    vendor: true,
}

cc_library_shared {
    name: "android.hardware.audio@7.1-impl.ranchu",
    defaults: ["android.hardware.audio@7.x-impl.ranchu_default"],
    vintf_fragments: ["android.hardware.audio@7.1-impl.ranchu.xml"],
    shared_libs: [
        "android.hardware.audio@7.1",
        "android.hardware.audio.common@7.1-enums",
       // "mygstreamer",
    ],
    static_libs: [
    	"libgstreamer",
    	"libglib",
    	"libintl",
    	"libgobject",
    	"libgmodule",   // Added gmodule dependency
        "libiconv",    // Added libiconv dependency
        "libpcre2",    // Added pcre2 dependency
        "libffi",
        "libgstapp",
        "libgstbase",
        "libgstplugin"
    	],
    cflags: [
        "-DLOG_TAG=\"android.hardware.audio@7.1-impl.ranchu\"",
        "-DMAJOR_VERSION=7",
        "-DMINOR_VERSION=1",
        "-DCOMMON_TYPES_MINOR_VERSION=0",
        "-DCORE_TYPES_MINOR_VERSION=0",
    ],
    // a.h.audio@X.0-impl.ranchu (see above) loads a.h.audio.legacy@X.0-impl
    // which loads:
    //  - audio.r_submix.default which provides the r_submix device (b/161485545)
    //  - audio.a2dp.default which provides the a2dp device (b/228804498)
    //  - audio.bluetooth.default which provides the bluetooth device (b/228804498)
    // This should be retired once we don't need to load the
    // deprecated libhardware modules listed above.
    //
    // audio.a2dp.default is not part of the required list as it's already in the
    // generic system image
    required: [
        "android.hardware.audio.legacy@7.1-impl.ranchu",
        "audio.r_submix.default",
        "audio.bluetooth.default",
    ],
}

Please help me to figure out what i am doing wrong here.
Thanks in Advance!