mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
First pass at adding transcode support
This does a hard-coded audio encode to vorbis-in-ogg. In the long term, this should use encodebin and real encoding profiles.
This commit is contained in:
parent
efecef0a6c
commit
e915be9208
4 changed files with 131 additions and 0 deletions
22
jni/Android.mk
Normal file
22
jni/Android.mk
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
LOCAL_PATH := $(call my-dir)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE := libtranscode
|
||||
LOCAL_SRC_FILES := transcode.c
|
||||
LOCAL_SHARED_LIBRARIES := gstreamer_android
|
||||
LOCAL_LDLIBS := -landroid
|
||||
|
||||
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) \
|
||||
audioparsers id3demux isomp4 ogg vorbis \
|
||||
amrnb amrwbdec faad mad mpegaudioparse \
|
||||
amc
|
||||
|
||||
include $(GSTREAMER_NDK_BUILD_PATH)/gstreamer.mk
|
||||
8
jni/README.gst-sdk
Normal file
8
jni/README.gst-sdk
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
* 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
|
||||
* cd jni; <NDK path>/ndk-build
|
||||
* cd ..; Continue building as usual
|
||||
91
jni/transcode.c
Normal file
91
jni/transcode.c
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
#include <gst/gst.h>
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
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)
|
||||
{
|
||||
GstElement *pipeline;
|
||||
GstBus *bus;
|
||||
GstMessage *msg;
|
||||
gchar pipeline_str[1024];
|
||||
|
||||
init();
|
||||
|
||||
snprintf(pipeline_str, 1024,
|
||||
"filesrc location=%s ! 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);
|
||||
msg = gst_bus_timed_pop_filtered(bus, GST_CLOCK_TIME_NONE,
|
||||
GST_MESSAGE_ERROR | GST_MESSAGE_EOS);
|
||||
|
||||
if (GST_MESSAGE_TYPE(msg) == 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);
|
||||
}
|
||||
|
||||
if (msg != NULL)
|
||||
gst_message_unref (msg);
|
||||
|
||||
gst_object_unref (bus);
|
||||
gst_element_set_state (pipeline, GST_STATE_NULL);
|
||||
gst_object_unref (pipeline);
|
||||
}
|
||||
|
||||
jint Java_org_wikimedia_commons_Transcoder_transcode(JNIEnv* env,
|
||||
jclass *klass, jstring infile, jstring outfile, jstring profile)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
#ifdef TEST
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (argc != 3)
|
||||
return -1;
|
||||
|
||||
transcode(argv[1], argv[2], NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
10
src/org/wikimedia/commons/Transcoder.java
Normal file
10
src/org/wikimedia/commons/Transcoder.java
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
package org.wikimedia.commons;
|
||||
|
||||
public class Transcoder {
|
||||
public static native int transcode(String infile, String outfile,
|
||||
String profile);
|
||||
|
||||
static {
|
||||
System.loadLibrary("transcode");
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue