diff --git a/commons/app/src/main/resources/main/native/Android.mk b/commons/app/src/main/resources/main/native/Android.mk deleted file mode 100644 index cbfeb34b4..000000000 --- a/commons/app/src/main/resources/main/native/Android.mk +++ /dev/null @@ -1,22 +0,0 @@ -LOCAL_PATH := $(call my-dir) - -include $(CLEAR_VARS) - -LOCAL_MODULE := libtranscode -LOCAL_SRC_FILES := transcode.c -LOCAL_SHARED_LIBRARIES := gstreamer_android -LOCAL_LDLIBS := -landroid -llog - -include $(BUILD_SHARED_LIBRARY) - -GSTREAMER_SDK_ROOT := $(GSTREAMER_SDK_ROOT_ANDROID) -GSTREAMER_NDK_BUILD_PATH := $(GSTREAMER_SDK_ROOT)/share/gst-android/ndk-build/ -include $(GSTREAMER_NDK_BUILD_PATH)/plugins.mk -GSTREAMER_PLUGINS := \ - $(GSTREAMER_PLUGINS_CORE) \ - $(GSTREAMER_PLUGINS_PLAYBACK) \ - debug \ - audioparsers id3demux isomp4 ogg vorbis wavparse \ - amrnb amrwbdec faad mad mpegaudioparse - -include $(GSTREAMER_NDK_BUILD_PATH)/gstreamer.mk diff --git a/commons/app/src/main/resources/main/native/README.gst-sdk b/commons/app/src/main/resources/main/native/README.gst-sdk deleted file mode 100644 index b095c9c68..000000000 --- a/commons/app/src/main/resources/main/native/README.gst-sdk +++ /dev/null @@ -1,8 +0,0 @@ -* Get the GStreamer SDK for Android - - http://docs.gstreamer.com/display/GstSDK/Installing+for+Android+development - - user: test, pass: Jo6eem7e (these will go away once the SDK gets out of the - beta stage) -* Get the NDK -* export GSTREAMER_SDK_ROOT_ANDROID=/path/to/unpacked/gstreamer/sdk -* (in top-level source dir) /ndk-build -* Continue building as usual diff --git a/commons/app/src/main/resources/main/native/gst-build/gstreamer_android.c b/commons/app/src/main/resources/main/native/gst-build/gstreamer_android.c deleted file mode 100644 index c9d4a7322..000000000 --- a/commons/app/src/main/resources/main/native/gst-build/gstreamer_android.c +++ /dev/null @@ -1,308 +0,0 @@ -#include -#include -#include -#include - -#define CAT_FMT "%s:%d:%s" - -static GstClockTime _priv_gst_info_start_time; - -/* Declaration of static plugins */ - GST_PLUGIN_STATIC_DECLARE(coreelements); - GST_PLUGIN_STATIC_DECLARE(coreindexers); - GST_PLUGIN_STATIC_DECLARE(adder); - GST_PLUGIN_STATIC_DECLARE(app); - GST_PLUGIN_STATIC_DECLARE(audioconvert); - GST_PLUGIN_STATIC_DECLARE(audiorate); - GST_PLUGIN_STATIC_DECLARE(audioresample); - GST_PLUGIN_STATIC_DECLARE(audiotestsrc); - GST_PLUGIN_STATIC_DECLARE(ffmpegcolorspace); - GST_PLUGIN_STATIC_DECLARE(gdp); - GST_PLUGIN_STATIC_DECLARE(gio); - GST_PLUGIN_STATIC_DECLARE(pango); - GST_PLUGIN_STATIC_DECLARE(typefindfunctions); - GST_PLUGIN_STATIC_DECLARE(videorate); - GST_PLUGIN_STATIC_DECLARE(videoscale); - GST_PLUGIN_STATIC_DECLARE(videotestsrc); - GST_PLUGIN_STATIC_DECLARE(volume); - GST_PLUGIN_STATIC_DECLARE(autodetect); - GST_PLUGIN_STATIC_DECLARE(videofilter); - GST_PLUGIN_STATIC_DECLARE(uridecodebin); - GST_PLUGIN_STATIC_DECLARE(playback); - GST_PLUGIN_STATIC_DECLARE(debug); - GST_PLUGIN_STATIC_DECLARE(audioparsers); - GST_PLUGIN_STATIC_DECLARE(id3demux); - GST_PLUGIN_STATIC_DECLARE(isomp4); - GST_PLUGIN_STATIC_DECLARE(ogg); - GST_PLUGIN_STATIC_DECLARE(vorbis); - GST_PLUGIN_STATIC_DECLARE(wavparse); - GST_PLUGIN_STATIC_DECLARE(amrnb); - GST_PLUGIN_STATIC_DECLARE(amrwbdec); - GST_PLUGIN_STATIC_DECLARE(faad); - GST_PLUGIN_STATIC_DECLARE(mad); - GST_PLUGIN_STATIC_DECLARE(mpegaudioparse); - - -/* Declaration of static gio modules */ - - -/* Call this function to register static plugins */ -void -gst_android_register_static_plugins (void) -{ - GST_PLUGIN_STATIC_REGISTER(coreelements); - GST_PLUGIN_STATIC_REGISTER(coreindexers); - GST_PLUGIN_STATIC_REGISTER(adder); - GST_PLUGIN_STATIC_REGISTER(app); - GST_PLUGIN_STATIC_REGISTER(audioconvert); - GST_PLUGIN_STATIC_REGISTER(audiorate); - GST_PLUGIN_STATIC_REGISTER(audioresample); - GST_PLUGIN_STATIC_REGISTER(audiotestsrc); - GST_PLUGIN_STATIC_REGISTER(ffmpegcolorspace); - GST_PLUGIN_STATIC_REGISTER(gdp); - GST_PLUGIN_STATIC_REGISTER(gio); - GST_PLUGIN_STATIC_REGISTER(pango); - GST_PLUGIN_STATIC_REGISTER(typefindfunctions); - GST_PLUGIN_STATIC_REGISTER(videorate); - GST_PLUGIN_STATIC_REGISTER(videoscale); - GST_PLUGIN_STATIC_REGISTER(videotestsrc); - GST_PLUGIN_STATIC_REGISTER(volume); - GST_PLUGIN_STATIC_REGISTER(autodetect); - GST_PLUGIN_STATIC_REGISTER(videofilter); - GST_PLUGIN_STATIC_REGISTER(uridecodebin); - GST_PLUGIN_STATIC_REGISTER(playback); - GST_PLUGIN_STATIC_REGISTER(debug); - GST_PLUGIN_STATIC_REGISTER(audioparsers); - GST_PLUGIN_STATIC_REGISTER(id3demux); - GST_PLUGIN_STATIC_REGISTER(isomp4); - GST_PLUGIN_STATIC_REGISTER(ogg); - GST_PLUGIN_STATIC_REGISTER(vorbis); - GST_PLUGIN_STATIC_REGISTER(wavparse); - GST_PLUGIN_STATIC_REGISTER(amrnb); - GST_PLUGIN_STATIC_REGISTER(amrwbdec); - GST_PLUGIN_STATIC_REGISTER(faad); - GST_PLUGIN_STATIC_REGISTER(mad); - GST_PLUGIN_STATIC_REGISTER(mpegaudioparse); - -} - -/* Call this function to load GIO modules */ -void -gst_android_load_gio_modules (void) -{ - -} - -void -gst_debug_logcat (GstDebugCategory * category, GstDebugLevel level, - const gchar * file, const gchar * function, gint line, - GObject * object, GstDebugMessage * message, gpointer unused) -{ - GstClockTime elapsed; - gint android_log_level; - gchar *tag; - - if (level > gst_debug_category_get_threshold (category)) - return; - - elapsed = GST_CLOCK_DIFF (_priv_gst_info_start_time, - gst_util_get_timestamp ()); - - switch (level) { - case GST_LEVEL_ERROR: - android_log_level = ANDROID_LOG_ERROR; - break; - case GST_LEVEL_WARNING: - android_log_level = ANDROID_LOG_WARN; - break; - case GST_LEVEL_INFO: - android_log_level = ANDROID_LOG_INFO; - break; - case GST_LEVEL_DEBUG: - android_log_level = ANDROID_LOG_DEBUG; - break; - default: - android_log_level = ANDROID_LOG_VERBOSE; - break; - } - - tag = g_strdup_printf ("GStreamer+%s", - gst_debug_category_get_name (category)); - __android_log_print (android_log_level, tag, - "%" GST_TIME_FORMAT " " CAT_FMT " %s\n", GST_TIME_ARGS (elapsed), - file, line, function, gst_debug_message_get (message)); - g_free (tag); -} - -static gboolean -get_application_dirs (JNIEnv * env, jobject context, gchar ** cache_dir, - gchar ** files_dir) -{ - jclass context_class; - jmethodID get_cache_dir_id, get_files_dir_id; - jclass file_class; - jmethodID get_absolute_path_id; - jobject dir; - jstring abs_path; - const gchar *abs_path_str; - - *cache_dir = *files_dir = NULL; - - context_class = (*env)->GetObjectClass (env, context); - if (!context_class) { - return FALSE; - } - get_cache_dir_id = - (*env)->GetMethodID (env, context_class, "getCacheDir", - "()Ljava/io/File;"); - get_files_dir_id = - (*env)->GetMethodID (env, context_class, "getFilesDir", - "()Ljava/io/File;"); - if (!get_cache_dir_id || !get_files_dir_id) { - return FALSE; - } - - file_class = (*env)->FindClass (env, "java/io/File"); - get_absolute_path_id = - (*env)->GetMethodID (env, file_class, "getAbsolutePath", - "()Ljava/lang/String;"); - if (!get_absolute_path_id) { - return FALSE; - } - - dir = (*env)->CallObjectMethod (env, context, get_cache_dir_id); - if ((*env)->ExceptionCheck (env)) { - return FALSE; - } - - if (dir) { - abs_path = (*env)->CallObjectMethod (env, dir, get_absolute_path_id); - if ((*env)->ExceptionCheck (env)) { - return FALSE; - } - abs_path_str = (*env)->GetStringUTFChars (env, abs_path, NULL); - if ((*env)->ExceptionCheck (env)) { - return FALSE; - } - *cache_dir = abs_path ? g_strdup (abs_path_str) : NULL; - - (*env)->ReleaseStringUTFChars (env, abs_path, abs_path_str); - (*env)->DeleteLocalRef (env, abs_path); - (*env)->DeleteLocalRef (env, dir); - } - - dir = (*env)->CallObjectMethod (env, context, get_files_dir_id); - if ((*env)->ExceptionCheck (env)) { - return FALSE; - } - if (dir) { - abs_path = (*env)->CallObjectMethod (env, dir, get_absolute_path_id); - if ((*env)->ExceptionCheck (env)) { - return FALSE; - } - abs_path_str = (*env)->GetStringUTFChars (env, abs_path, NULL); - if ((*env)->ExceptionCheck (env)) { - return FALSE; - } - *files_dir = files_dir ? g_strdup (abs_path_str) : NULL; - - (*env)->ReleaseStringUTFChars (env, abs_path, abs_path_str); - (*env)->DeleteLocalRef (env, abs_path); - (*env)->DeleteLocalRef (env, dir); - } - - (*env)->DeleteLocalRef (env, file_class); - (*env)->DeleteLocalRef (env, context_class); - - return TRUE; -} - -static void -gst_android_init (JNIEnv * env, jclass klass, jobject context) -{ - gchar *cache_dir; - gchar *files_dir; - gchar *registry; - GError *error = NULL; - - if (gst_is_initialized ()) { - __android_log_print (ANDROID_LOG_INFO, "GStreamer", - "GStreamer already initialized"); - return; - } - - if (!get_application_dirs (env, context, &cache_dir, &files_dir)) - return; - - if (cache_dir) { - g_setenv ("TMP", cache_dir, TRUE); - g_setenv ("TMPDIR", cache_dir, TRUE); - g_setenv ("XDG_RUNTIME_DIR", cache_dir, TRUE); - g_setenv ("XDG_CACHE_DIR", cache_dir, TRUE); - registry = g_build_filename (cache_dir, "registry.bin", NULL); - g_setenv ("GST_REGISTRY", registry, TRUE); - g_free (registry); - g_setenv ("GST_REUSE_PLUGIN_SCANNER", "no", TRUE); - /* FIXME: Should probably also set GST_PLUGIN_SCANNER and GST_PLUGIN_SYSTEM_PATH */ - } - if (files_dir) { - g_setenv ("HOME", files_dir, TRUE); - g_setenv ("XDG_DATA_DIRS", files_dir, TRUE); - g_setenv ("XDG_CONFIG_DIRS", files_dir, TRUE); - } - g_free (cache_dir); - g_free (files_dir); - - /* Disable this for releases if performance is important - * or increase the threshold to get more information */ - gst_debug_set_active (TRUE); - gst_debug_set_default_threshold (GST_LEVEL_WARNING); - gst_debug_remove_log_function (gst_debug_log_default); - gst_debug_add_log_function ((GstLogFunction) gst_debug_logcat, NULL); - /* get time we started for debugging messages */ - _priv_gst_info_start_time = gst_util_get_timestamp (); - - if (!gst_init_check (NULL, NULL, &error)) { - gchar *message = g_strdup_printf ("GStreamer initialization failed: %s", - error && error->message ? error->message : "(no message)"); - jclass exception_class = (*env)->FindClass (env, "java/lang/Exception"); - __android_log_print (ANDROID_LOG_ERROR, "GStreamer", message); - (*env)->ThrowNew (env, exception_class, message); - g_free (message); - return; - } - gst_android_register_static_plugins (); - gst_android_load_gio_modules(); - __android_log_print (ANDROID_LOG_INFO, "GStreamer", - "GStreamer initialization complete"); -} - -static JNINativeMethod native_methods[] = { - {"init", "(Landroid/content/Context;)V", (void *) gst_android_init} -}; - -jint -JNI_OnLoad (JavaVM * vm, void *reserved) -{ - JNIEnv *env = NULL; - - if ((*vm)->GetEnv (vm, (void **) &env, JNI_VERSION_1_4) != JNI_OK) { - __android_log_print (ANDROID_LOG_ERROR, "GStreamer", - "Could not retrieve JNIEnv"); - return 0; - } - jclass klass = (*env)->FindClass (env, "com/gst_sdk/GStreamer"); - if (!klass) { - __android_log_print (ANDROID_LOG_ERROR, "GStreamer", - "Could not retrieve class com.gst_sdk.GStreamer"); - return 0; - } - if ((*env)->RegisterNatives (env, klass, native_methods, - G_N_ELEMENTS (native_methods))) { - __android_log_print (ANDROID_LOG_ERROR, "GStreamer", - "Could not register native methods for com.gst_sdk_GStreamer"); - return 0; - } - - return JNI_VERSION_1_4; -} diff --git a/commons/app/src/main/resources/main/native/gst-build/gstreamer_android.o b/commons/app/src/main/resources/main/native/gst-build/gstreamer_android.o deleted file mode 100644 index 85be70ec7..000000000 Binary files a/commons/app/src/main/resources/main/native/gst-build/gstreamer_android.o and /dev/null differ diff --git a/commons/app/src/main/resources/main/native/transcode.c b/commons/app/src/main/resources/main/native/transcode.c deleted file mode 100644 index 2547236bb..000000000 --- a/commons/app/src/main/resources/main/native/transcode.c +++ /dev/null @@ -1,148 +0,0 @@ -#include - -#include -#include - -static int init(void) -{ - /* XXX: ZERO thread-safety guarantees here */ - static gboolean inited = 0; - - if (inited) - return 0; - - gst_init(NULL, NULL); - return 0; -} - -static int transcode(const char *infile, const char *outfile, - const char *profile, jobject cb_obj, JNIEnv *env) -{ - GstElement *pipeline; - GstBus *bus; - GstMessage *msg; - gchar pipeline_str[1024]; - int ret = 0; - - init(); - - snprintf(pipeline_str, 1024, - "filesrc location=\"%s\" ! " - "progressreport silent=true format=percent update-freq=1 ! " - "decodebin2 ! audioconvert ! vorbisenc ! oggmux ! " - "filesink location=\"%s\"", - infile, outfile); - - pipeline = gst_parse_launch(pipeline_str, NULL); - - gst_element_set_state (pipeline, GST_STATE_PLAYING); - - bus = gst_element_get_bus(pipeline); - - for (;;) { - msg = gst_bus_timed_pop_filtered(bus, GST_CLOCK_TIME_NONE, - GST_MESSAGE_ERROR | GST_MESSAGE_EOS | GST_MESSAGE_ELEMENT); - - switch (GST_MESSAGE_TYPE(msg)) { - case GST_MESSAGE_ELEMENT: { - const GstStructure *s = gst_message_get_structure(msg); - int percent; - jclass cb_class; - jmethodID cb_id; - - if (!cb_obj) - break; - - if (!g_str_equal(gst_structure_get_name(s), "progress")) - break; - - gst_structure_get_int(s, "percent", &percent); - - cb_class = (*env)->FindClass(env, "fr/free/nrw/commons/Transcoder$TranscoderProgressCallback"); - if ((*env)->ExceptionCheck(env)) { - __android_log_print(ANDROID_LOG_ERROR, "GStreamer", "Class not found"); - break; - } - - cb_id = (*env)->GetMethodID(env, cb_class, "transcodeProgressCb", "(I)V"); - if ((*env)->ExceptionCheck(env)) { - __android_log_print(ANDROID_LOG_ERROR, "GStreamer", "Method not found"); - break; - } - - (*env)->CallVoidMethod(env, cb_obj, cb_id, percent); - if ((*env)->ExceptionCheck(env)) { - __android_log_print(ANDROID_LOG_ERROR, "GStreamer", "Method call failed"); - break; - } - - break; - } - - case GST_MESSAGE_ERROR: { - GError *err = NULL; - gchar *debug_info = NULL; - - gst_message_parse_error(msg, &err, &debug_info); - - GST_ERROR_OBJECT(pipeline, "%s -- %s", err->message, - debug_info ? debug_info : "no debug info"); - - g_error_free(err); - g_free(debug_info); - - ret = -1; - goto done; - } - - case GST_MESSAGE_EOS: - goto done; - - default: - break; - } - } - -done: - if (msg != NULL) - gst_message_unref (msg); - - gst_object_unref (bus); - gst_element_set_state (pipeline, GST_STATE_NULL); - gst_object_unref (pipeline); - - return ret; -} - -jint Java_fr_free_nrw_commons_Transcoder_transcode(JNIEnv* env, - jclass *klass, jstring infile, jstring outfile, jstring profile, - jobject cb_obj) -{ - const char *in; - const char *out; - const char *prof = NULL; - - if (!infile || !outfile) - return -1; - - in = (*env)->GetStringUTFChars(env, infile, 0); - out = (*env)->GetStringUTFChars(env, outfile, 0); - - if (profile) - prof = (*env)->GetStringUTFChars(env, profile, 0); - - return transcode(in, out, prof, cb_obj, env); -} - - -#ifdef TEST -int main(int argc, char **argv) -{ - if (argc != 3) - return -1; - - transcode(argv[1], argv[2], NULL); - - return 0; -} -#endif