Issue
I simply wanna push some byte array from my Java Class to Native Gstreamer methods. I've read all gstreamer documents for android and found that i should use gst_app_src_push_buffer to push data to the GstAppSrc but when i try to build the project, this error shown: error: undefined reference to 'gst_app_src_push_buffer'. here is my c code in mgstreamer.c file:
#define TAG "GSTREAMER_NATIVE"
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,TAG,__VA_ARGS__)
#include <string.h>
#include <jni.h>
#include <gst/gst.h>
#include <android/log.h>
#include <gst/app/gstappsrc.h>
#include <glib.h>
#include <glibconfig.h>
#define GST_VALUE_HOLDS_FOURCC(x) (G_VALUE_HOLDS(x, gst_type_fourcc))
#define GST_TYPE_FOURCC gst_type_fourcc
GST_EXPORT GType gst_type_fourcc;
static void initPipeline(JNIEnv *end,jobject clazz) {
gst_init(NULL, NULL);
mData = (MData *) g_malloc0(sizeof(MData));
gchar *uuid = g_uuid_string_random();
mData->pipeline = gst_pipeline_new(uuid);
gst_element_set_state(mData->pipeline, GST_STATE_PLAYING);
GstElement *appsrc = gst_element_factory_make("appsrc", NULL);
g_object_set(G_OBJECT(appsrc), "is-live", TRUE, "format", GST_FORMAT_TIME, "do-timestamp", TRUE,
"block", TRUE, NULL);
mData->appSrc = appsrc;
GstCaps *caps = gst_caps_new_simple("video/x-raw-yuv",
"format", GST_TYPE_FOURCC,
GST_MAKE_FOURCC ('N', 'V', '2', '1'),
"framerate", GST_TYPE_FRACTION, 15, 1,
"width", G_TYPE_INT, 128,
"height", G_TYPE_INT, 96,
NULL);
GstElement *capsfilter = gst_element_factory_make("capsfilter", NULL);
g_object_set(G_OBJECT(capsfilter), "caps", caps, NULL);
gst_bin_add_many(GST_BIN(mData->pipeline), appsrc, capsfilter, NULL);
gst_element_link_many(appsrc, capsfilter,NULL);
gst_element_sync_state_with_parent(appsrc);
gst_element_sync_state_with_parent(capsfilter);
}
static void onReceiveData(JNIEnv *env, jclass clazz, jbyteArray byteArrayData) {
jbyte *temp = (*env)->GetByteArrayElements(env, byteArrayData, NULL);
jsize size = (*env)->GetArrayLength(env, byteArrayData);
GstBuffer *buffer = gst_buffer_new_allocate(NULL, size, NULL);
gst_buffer_fill(buffer, 0, temp, size);
GstElement *source = gst_bin_get_by_name(GST_BIN(mData->pipeline), "source");
gst_app_src_push_buffer((GstAppSrc *) source, buffer);
gst_object_unref(source);
(*env)->ReleaseByteArrayElements(env, byteArrayData, temp, JNI_ABORT);
}
This is Android.mk file:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := test_g_streamer
LOCAL_SRC_FILES := mgstreamer.c
LOCAL_SHARED_LIBRARIES := gstreamer_android
LOCAL_LDLIBS := -llog
include $(BUILD_SHARED_LIBRARY)
ifndef GSTREAMER_ROOT_ANDROID
$(error GSTREAMER_ROOT_ANDROID is not defined!)
endif
ifeq ($(TARGET_ARCH_ABI),armeabi)
GSTREAMER_ROOT := $(GSTREAMER_ROOT_ANDROID)/arm
else ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
GSTREAMER_ROOT := $(GSTREAMER_ROOT_ANDROID)/armv7
else ifeq ($(TARGET_ARCH_ABI),arm64-v8a)
GSTREAMER_ROOT := $(GSTREAMER_ROOT_ANDROID)/arm64
else ifeq ($(TARGET_ARCH_ABI),x86)
GSTREAMER_ROOT := $(GSTREAMER_ROOT_ANDROID)/x86
else ifeq ($(TARGET_ARCH_ABI),x86_64)
GSTREAMER_ROOT := $(GSTREAMER_ROOT_ANDROID)/x86_64
else
$(error Target arch ABI not supported: $(TARGET_ARCH_ABI))
endif
LOCAL_EXPORT_C_INCLUDES +=$(GSTREAMER_ROOT)/include/gstreamer-1.0/
LOCAL_EXPORT_C_INCLUDES +=$(GSTREAMER_ROOT)/include/glib-2.0/gobject
LOCAL_EXPORT_C_INCLUDES +=$(GSTREAMER_ROOT)/include/glib-2.0/
LOCAL_EXPORT_C_INCLUDES +=$(GSTREAMER_ROOT)/lib/
GSTREAMER_NDK_BUILD_PATH := $(GSTREAMER_ROOT)/share/gst-android/ndk-build/
include $(GSTREAMER_NDK_BUILD_PATH)/plugins.mk
GSTREAMER_PLUGINS := $(GSTREAMER_PLUGINS_CORE) \
$(GSTREAMER_PLUGINS_PLAYBACK) \
$(GSTREAMER_PLUGINS_CODECS) \
$(GSTREAMER_PLUGINS_NET) \
$(GSTREAMER_PLUGINS_SYS) \
$(GSTREAMER_PLUGINS_CODECS_RESTRICTED) \
$(GSTREAMER_CODECS_GPL) \
$(GSTREAMER_PLUGINS_ENCODING) \
$(GSTREAMER_PLUGINS_VIS) \
$(GSTREAMER_PLUGINS_EFFECTS) \
$(GSTREAMER_PLUGINS_NET_RESTRICTED)
GSTREAMER_EXTRA_DEPS := gstreamer-1.0 glib-2.0 gio-2.0
include $(GSTREAMER_NDK_BUILD_PATH)/gstreamer-1.0.mk
include $(CLEAR_VARS)
LOCAL_MODULE := fast_image_converter
LOCAL_SRC_FILES := pr_convertor.cpp
LOCAL_LDLIBS := -llog
include $(BUILD_SHARED_LIBRARY)
and Appilcation.mk
APP_ABI = armeabi-v7a arm64-v8a x86 x86_64
APP_STL = c++_shared
APP_PLATFORM := android
build.gradle :
apply plugin: 'com.android.library'
android {
compileSdkVersion 30
buildToolsVersion "30.0.2"
defaultConfig {
minSdkVersion 19
targetSdkVersion 30
versionCode 1
versionName "1.0"
externalNativeBuild {
ndkBuild {
def gstRoot = System.env.GSTREAMER_ROOT_ANDROID
if (gstRoot == null)
throw new GradleException('GSTREAMER_ROOT_ANDROID must be set, or "gstAndroidRoot" must be defined in your gradle.properties in the top level directory of the unpacked universal GStreamer Android binaries')
arguments "NDK_APPLICATION_MK=src/main/jni/Application.mk", "GSTREAMER_JAVA_SRC_DIR=src", "GSTREAMER_ROOT_ANDROID=$gstRoot", "GSTREAMER_ASSETS_DIR=src/assets"
targets "test_g_streamer", "fast_image_converter"
// All archs except MIPS and MIPS64 are supported
abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
}
}
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
ndkBuild {
path 'src/main/jni/Android.mk'
}
}
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.2.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
and Project build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.0.1"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I've added all gstreamer's plugins but error still remained. Gstreamer versions that i tried to use: gstreamer-1.0-android-universal-1.18.3.tar and gstreamer-1.0-android-universal-1.18.0.tar NDK version: 21.3.6528147 PS: I'm developing on windows 10
Solution
This steps fixed the problem:
- I added GSTREAMER_EXTRA_DEPS to my Android.mk.
- GST_PLUGIN_STATIC_DECLARE and GST_PLUGIN_STATIC_REGISTER also needed because i tried to develop my own gstreamer module and i didn't use gstreamer_android.c file. Here is scripts and source codes for who need to do same:
Android.mk
STREAMER_NDK_BUILD_PATH := $(GSTREAMER_ROOT)/share/gst-android/ndk-build/
include $(GSTREAMER_NDK_BUILD_PATH)/plugins.mk
GSTREAMER_PLUGINS := libav videoparsersbad opengl rtp rtpmanager coreelements app vpx videoconvert x264 videofilter opus autodetect audioconvert audioresample audiorate
GSTREAMER_EXTRA_DEPS := gstreamer-plugins-base-1.0 gstreamer-rtp-1.0 gmodule-2.0 glib-2.0 gstreamer-app-1.0 gstreamer-video-1.0
GSTREAMER_EXTRA_LIBS := -liconv
include $(GSTREAMER_NDK_BUILD_PATH)/gstreamer-1.0.mk
and static register:
GST_PLUGIN_STATIC_DECLARE(coreelements);
GST_PLUGIN_STATIC_DECLARE(rtp);
GST_PLUGIN_STATIC_DECLARE(app);
GST_PLUGIN_STATIC_DECLARE(vpx);
GST_PLUGIN_STATIC_DECLARE(videoconvert);
GST_PLUGIN_STATIC_DECLARE(x264);
GST_PLUGIN_STATIC_DECLARE(opengl);
GST_PLUGIN_STATIC_DECLARE(videoparsersbad);
GST_PLUGIN_STATIC_DECLARE(videofilter);
GST_PLUGIN_STATIC_DECLARE(opus);
GST_PLUGIN_STATIC_DECLARE(autodetect);
GST_PLUGIN_STATIC_DECLARE(audioconvert);
GST_PLUGIN_STATIC_DECLARE(rtpmanager);
GST_PLUGIN_STATIC_DECLARE(libav);
/* Call this function to register static plugins */
void
gst_android_register_static_plugins(void) {
GST_PLUGIN_STATIC_REGISTER(coreelements);
GST_PLUGIN_STATIC_REGISTER(app);
GST_PLUGIN_STATIC_REGISTER(rtp);
GST_PLUGIN_STATIC_REGISTER(vpx);
GST_PLUGIN_STATIC_REGISTER(videoconvert);
GST_PLUGIN_STATIC_REGISTER(x264);
GST_PLUGIN_STATIC_REGISTER(opengl);
GST_PLUGIN_STATIC_REGISTER(videoparsersbad);
GST_PLUGIN_STATIC_REGISTER(videofilter);
GST_PLUGIN_STATIC_REGISTER(opus);
GST_PLUGIN_STATIC_REGISTER(autodetect);
GST_PLUGIN_STATIC_REGISTER(audioconvert);
GST_PLUGIN_STATIC_REGISTER(rtpmanager);
GST_PLUGIN_STATIC_REGISTER(libav);
}
Answered By - HiddenCoder7
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.