Enable GStreamer support on Android

This commit is contained in:
Fernando Jiménez Moreno 2018-09-17 13:12:10 +02:00
parent c576412f83
commit b27881523c
10 changed files with 4599 additions and 35 deletions

View file

@ -13,8 +13,12 @@ import datetime
import os
import os.path as path
import platform
import sys
import re
import shutil
import subprocess
import sys
import urllib
import zipfile
from time import time
@ -394,6 +398,45 @@ class MachCommands(CommandBase):
if not os.path.exists(aar_out_dir):
os.makedirs(aar_out_dir)
env["AAR_OUT_DIR"] = aar_out_dir
# GStreamer and its dependencies use pkg-config and this flag is required
# to make it work in a cross-compilation context.
env["PKG_CONFIG_ALLOW_CROSS"] = '1'
# Build the name of the package containing all GStreamer dependencies
# according to the build target.
gst_lib = None
if re.match("arm-([a-z])*-androideabi", target):
gst_lib = "gst-build-armeabi"
elif re.match("armv7-([a-z])*-androideabi", target):
gst_lib = "gst-build-armeabi-v7a"
elif re.match("x86_64-([a-z])*-android", target):
gst_lib = "gst-build-x86_64"
elif re.match("i686-([a-z])*-android", target):
gst_lib = "gst-build-x86"
else:
raise Exception("Invalid target architecture '%s'" % target)
gst_lib_zip = "%s.zip" % gst_lib
gst_dir = os.path.join(base_path, "gstreamer")
gst_lib_path = os.path.join(base_path, gst_dir, gst_lib)
pkg_config_path = os.path.join(gst_lib_path, "pkgconfig")
env["PKG_CONFIG_PATH"] = pkg_config_path
if not os.path.exists(gst_lib_path):
# Download GStreamer dependencies if they have not already been downloaded
print("Downloading GStreamer dependencies")
gst_url = "https://github.com/servo/libgstreamer_android_gen/blob/master/out/%s?raw=true" % gst_lib_zip
urllib.urlretrieve(gst_url, gst_lib_zip)
zip_ref = zipfile.ZipFile(gst_lib_zip, "r")
zip_ref.extractall(gst_dir)
os.remove(gst_lib_zip)
# Change pkgconfig info to make all GStreamer dependencies point
# to the libgstreamer_android.so bundle.
for each in os.listdir(pkg_config_path):
if each.endswith('.pc'):
print("Setting pkgconfig info for %s" % each)
pc = os.path.join(pkg_config_path, each)
expr = "s#libdir=.*#libdir=%s#g" % gst_lib_path
subprocess.call(["perl", "-i", "-pe", expr, pc])
if very_verbose:
print (["Calling", "cargo", "build"] + opts)