mirror of
https://github.com/servo/servo.git
synced 2025-08-11 00:15:32 +01:00
Enable GStreamer support on Android
This commit is contained in:
parent
c576412f83
commit
b27881523c
10 changed files with 4599 additions and 35 deletions
|
@ -157,9 +157,9 @@ android {
|
|||
}
|
||||
|
||||
def taskName = "ndkbuild" + compileTask.name
|
||||
def debug = compileTask.name.contains("Debug")
|
||||
def arch = matcher.group(1)
|
||||
tasks.create(name: taskName, type: Exec) {
|
||||
def debug = compileTask.name.contains("Debug")
|
||||
def arch = matcher.group(1)
|
||||
commandLine getNdkDir(),
|
||||
'APP_BUILD_SCRIPT=../jni/Android.mk',
|
||||
'NDK_APPLICATION_MK=../jni/Application.mk',
|
||||
|
@ -170,7 +170,23 @@ android {
|
|||
'SERVO_TARGET_DIR=' + getTargetDir(debug, arch)
|
||||
}
|
||||
|
||||
compileTask.dependsOn taskName
|
||||
def src = getTargetDir(debug, arch) +
|
||||
'/../../gstreamer/gst-build-' +
|
||||
getNDKAbi(arch) +
|
||||
'/libgstreamer_android.so'
|
||||
Task copyGStreamerTask = project.task("copyGStreamerTask${compileTask.name}", type: Copy) {
|
||||
from src
|
||||
into getJniLibsPath(debug, arch) + '/' + getNDKAbi(arch) + '/'
|
||||
}
|
||||
|
||||
Task copyGStreamerObjTask = project.task("copyGStreamerTask${compileTask.name}Obj", type: Copy) {
|
||||
from src
|
||||
into getTargetDir(debug, arch) + '/apk/obj/local/' + getNDKAbi(arch) + '/'
|
||||
}
|
||||
|
||||
copyGStreamerObjTask.dependsOn taskName
|
||||
copyGStreamerTask.dependsOn copyGStreamerObjTask
|
||||
compileTask.dependsOn copyGStreamerTask
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ import android.app.Activity;
|
|||
public class JNIServo {
|
||||
JNIServo() {
|
||||
System.loadLibrary("c++_shared");
|
||||
System.loadLibrary("gstreamer_android");
|
||||
System.loadLibrary("simpleservo");
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,8 @@ import com.mozilla.servoview.Servo.RunCallback;
|
|||
import javax.microedition.khronos.egl.EGLConfig;
|
||||
import javax.microedition.khronos.opengles.GL10;
|
||||
|
||||
import org.freedesktop.gstreamer.GStreamer;
|
||||
|
||||
public class ServoView extends GLSurfaceView
|
||||
implements
|
||||
GestureDetector.OnGestureListener,
|
||||
|
@ -147,6 +149,11 @@ public class ServoView extends GLSurfaceView
|
|||
inGLThread(() -> {
|
||||
String uri = mInitialUri == null ? null : mInitialUri.toString();
|
||||
mServo = new Servo(this, this, mClient, mActivity, mServoArgs, uri, mServoLog, width, height, density, showLogs);
|
||||
try {
|
||||
GStreamer.init((Context) mActivity);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
package org.freedesktop.gstreamer;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.AssetManager;
|
||||
|
||||
public class GStreamer {
|
||||
private static native void nativeInit(Context context) throws Exception;
|
||||
|
||||
public static void init(Context context) throws Exception {
|
||||
nativeInit(context);
|
||||
copyFonts(context);
|
||||
copyCaCertificates(context);
|
||||
}
|
||||
|
||||
private static void copyFonts(Context context) {
|
||||
AssetManager assetManager = context.getAssets();
|
||||
File filesDir = context.getFilesDir();
|
||||
File fontsFCDir = new File (filesDir, "fontconfig");
|
||||
File fontsDir = new File (fontsFCDir, "fonts");
|
||||
File fontsCfg = new File (fontsFCDir, "fonts.conf");
|
||||
|
||||
fontsDir.mkdirs();
|
||||
|
||||
try {
|
||||
/* Copy the config file */
|
||||
copyFile (assetManager, "fontconfig/fonts.conf", fontsCfg);
|
||||
/* Copy the fonts */
|
||||
for(String filename : assetManager.list("fontconfig/fonts/truetype")) {
|
||||
File font = new File(fontsDir, filename);
|
||||
copyFile (assetManager, "fontconfig/fonts/truetype/" + filename, font);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static void copyCaCertificates(Context context) {
|
||||
AssetManager assetManager = context.getAssets();
|
||||
File filesDir = context.getFilesDir();
|
||||
File sslDir = new File (filesDir, "ssl");
|
||||
File certsDir = new File (sslDir, "certs");
|
||||
File certs = new File (certsDir, "ca-certificates.crt");
|
||||
|
||||
certsDir.mkdirs();
|
||||
|
||||
try {
|
||||
/* Copy the certificates file */
|
||||
copyFile (assetManager, "ssl/certs/ca-certificates.crt", certs);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static void copyFile(AssetManager assetManager, String assetPath, File outFile) throws IOException {
|
||||
InputStream in;
|
||||
OutputStream out;
|
||||
byte[] buffer = new byte[1024];
|
||||
int read;
|
||||
|
||||
if (outFile.exists())
|
||||
outFile.delete();
|
||||
|
||||
in = assetManager.open(assetPath);
|
||||
out = new FileOutputStream (outFile);
|
||||
while((read = in.read(buffer)) != -1){
|
||||
out.write(buffer, 0, read);
|
||||
}
|
||||
in.close();
|
||||
out.flush();
|
||||
out.close();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue