Skip to content

Commit

Permalink
Video: GStreamer Plugin Improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
HTRamsey committed Oct 16, 2024
1 parent be1e2d4 commit 9686b0b
Show file tree
Hide file tree
Showing 40 changed files with 1,733 additions and 1,375 deletions.
1 change: 1 addition & 0 deletions .github/actions/gstreamer/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ runs:
run: git clone --depth 1 --branch ${{ inputs.gst_version }} https://github.com/GStreamer/gstreamer.git
shell: bash

# macos https://github.com/Homebrew/homebrew-core/blob/4e00e17ab49b90949c27cf43a873ca923f3735aa/Formula/g/gstreamer.rb
- name: Configure GStreamer
working-directory: ${{ inputs.working_directory }}/gstreamer
run: meson setup
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ jobs:
for package in *.pkg ;
do sudo installer -verbose -pkg "$package" -target /
done
echo "PKG_CONFIG_PATH=/Library/Frameworks/GStreamer.framework/lib/pkgconfig:${{ env.PKG_CONFIG_PATH }}" >> "$GITHUB_ENV"
- name: Set Up Cache
uses: hendrikmuhs/[email protected]
Expand Down
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,6 @@ endif()

set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)

if(CMAKE_BUILD_TYPE STREQUAL "Release")
add_compile_definitions(QGC_INSTALL_RELEASE)
endif()

#######################################################
# Qt6 Configuration
#######################################################
Expand Down Expand Up @@ -520,6 +516,10 @@ if(LINUX)
FILES ${CMAKE_BINARY_DIR}/metainfo/org.mavlink.qgroundcontrol.metainfo.xml
DESTINATION ${CMAKE_INSTALL_DATADIR}/metainfo/
)
install(
FILES ${CMAKE_SOURCE_DIR}/deploy/linux/AppRun
DESTINATION ${CMAKE_BINARY_DIR}
)
install(SCRIPT "${CMAKE_SOURCE_DIR}/cmake/CreateAppImage.cmake")
elseif(WIN32)
install(SCRIPT "${CMAKE_SOURCE_DIR}/cmake/CreateWinInstaller.cmake")
Expand Down
49 changes: 49 additions & 0 deletions android/libs/gstreamer_android-1.0.c.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include <gst/gst.h>
#include <gio/gio.h>

#define GST_G_IO_MODULE_DECLARE(name) \
extern void G_PASTE(g_io_, G_PASTE(name, _load)) (gpointer data)

#define GST_G_IO_MODULE_LOAD(name) \
G_PASTE(g_io_, G_PASTE(name, _load)) (NULL)

/* Declaration of static plugins */
@PLUGINS_DECLARATION@

/* Declaration of static gio modules */
@G_IO_MODULES_DECLARE@

/* Call this function to load GIO modules */
static void
gst_android_load_gio_modules (void)
{
GTlsBackend *backend;
const gchar *ca_certs;

@G_IO_MODULES_LOAD@

ca_certs = g_getenv ("CA_CERTIFICATES");

backend = g_tls_backend_get_default ();
if (backend && ca_certs) {
GTlsDatabase *db;
GError *error = NULL;

db = g_tls_file_database_new (ca_certs, &error);
if (db) {
g_tls_backend_set_default_database (backend, db);
g_object_unref (db);
} else {
g_warning ("Failed to create a database from file: %s",
error ? error->message : "Unknown");
}
}
}

/* This is called by gst_init() */
void
gst_init_static_plugins (void)
{
@PLUGINS_REGISTRATION@
gst_android_load_gio_modules ();
}
105 changes: 105 additions & 0 deletions android/src/org/freedesktop/gstreamer/GStreamer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/**
* Copy this file into your Android project and call init(). If your project
* contains fonts and/or certificates in assets, uncomment copyFonts() and/or
* copyCaCertificates() lines in init().
*/
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;
import android.system.Os;

public class GStreamer {
private static native void nativeInit(Context context) throws Exception;

public static void init(Context context) throws Exception {
//copyFonts(context);
//copyCaCertificates(context);
nativeInit(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 = null;
OutputStream out = null;
IOException exception = null;

if (outFile.exists())
outFile.delete();

try {
in = assetManager.open(assetPath);
out = new FileOutputStream(outFile);

byte[] buffer = new byte[1024];
int read;
while ((read = in.read(buffer)) != -1) {
out.write(buffer, 0, read);
}
out.flush();
} catch (IOException e) {
exception = e;
} finally {
if (in != null)
try {
in.close();
} catch (IOException e) {
if (exception == null)
exception = e;
}
if (out != null)
try {
out.close();
} catch (IOException e) {
if (exception == null)
exception = e;
}
if (exception != null)
throw exception;
}
}
}
10 changes: 9 additions & 1 deletion android/src/org/mavlink/qgroundcontrol/QGCActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import android.util.Log;
import android.view.WindowManager;

// import org.freedesktop.gstreamer.GStreamer;

import com.hoho.android.usbserial.driver.*;
import com.hoho.android.usbserial.util.*;

Expand Down Expand Up @@ -144,7 +146,7 @@ public QGCActivity()

public void onInit(int status)
{

// System.loadLibrary("gstreamer_android");
}

@Override
Expand All @@ -160,6 +162,12 @@ public void onCreate(Bundle savedInstanceState)
_setupUsbPermissionIntent();

m_usbManager = (UsbManager) m_instance.getSystemService(Context.USB_SERVICE);

// try {
// GStreamer.init(this);
// } catch (final Exception ex) {
// Log.e(TAG, "Exception GStreamer.init(this)", ex);
// }
}

@Override
Expand Down
17 changes: 11 additions & 6 deletions cmake/CreateAppImage.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ message(STATUS "Creating AppImage")
# TODO: https://github.com/AppImageCommunity/AppImageUpdate

set(APPDIR_PATH "${CMAKE_BINARY_DIR}/AppDir")
# set(APPIMAGETOOL_PATH "${CMAKE_BINARY_DIR}/appimagetool-x86_64.AppImage")
set(LD_PATH "${CMAKE_BINARY_DIR}/linuxdeploy-x86_64.AppImage")
set(LD_APPIMAGEPLUGIN_PATH "${CMAKE_BINARY_DIR}/linuxdeploy-plugin-appimage-x86_64.AppImage")
set(LD_QTPLUGIN_PATH "${CMAKE_BINARY_DIR}/linuxdeploy-plugin-qt-x86_64.AppImage")
# set(LD_QTPLUGIN_PATH "${CMAKE_BINARY_DIR}/linuxdeploy-plugin-qt-x86_64.AppImage")
# set(LD_GSTPLUGIN_PATH "${CMAKE_BINARY_DIR}/linuxdeploy-plugin-gstreamer.sh")
# set(LD_GTKPLUGIN_PATH "${CMAKE_BINARY_DIR}/linuxdeploy-plugin-gtk.sh")

# if(NOT EXISTS "${APPIMAGETOOL_PATH}")
# file(DOWNLOAD https://github.com/AppImage/appimagetool/releases/download/continuous/appimagetool-x86_64.AppImage "${APPIMAGETOOL_PATH}")
# execute_process(COMMAND chmod a+x "${APPIMAGETOOL_PATH}")
# endif()
if(NOT EXISTS "${LD_PATH}")
file(DOWNLOAD https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage "${LD_PATH}")
execute_process(COMMAND chmod a+x "${LD_PATH}")
Expand All @@ -16,10 +21,10 @@ if(NOT EXISTS "${LD_APPIMAGEPLUGIN_PATH}")
file(DOWNLOAD https://github.com/linuxdeploy/linuxdeploy-plugin-appimage/releases/download/continuous/linuxdeploy-plugin-appimage-x86_64.AppImage "${LD_APPIMAGEPLUGIN_PATH}")
execute_process(COMMAND chmod a+x "${LD_APPIMAGEPLUGIN_PATH}")
endif()
if(NOT EXISTS "${LD_QTPLUGIN_PATH}")
file(DOWNLOAD https://github.com/linuxdeploy/linuxdeploy-plugin-qt/releases/download/continuous/linuxdeploy-plugin-qt-x86_64.AppImage "${LD_QTPLUGIN_PATH}")
execute_process(COMMAND chmod a+x "${LD_QTPLUGIN_PATH}")
endif()
# if(NOT EXISTS "${LD_QTPLUGIN_PATH}")
# file(DOWNLOAD https://github.com/linuxdeploy/linuxdeploy-plugin-qt/releases/download/continuous/linuxdeploy-plugin-qt-x86_64.AppImage "${LD_QTPLUGIN_PATH}")
# execute_process(COMMAND chmod a+x "${LD_QTPLUGIN_PATH}")
# endif()
# if(NOT EXISTS "${LD_GTKPLUGIN_PATH}")
# file(DOWNLOAD https://raw.githubusercontent.com/linuxdeploy/linuxdeploy-plugin-gtk/master/linuxdeploy-plugin-gtk.sh "${LD_GTKPLUGIN_PATH}")
# execute_process(COMMAND chmod a+x "${LD_GTKPLUGIN_PATH}")
Expand All @@ -29,7 +34,7 @@ endif()
# execute_process(COMMAND chmod a+x "${LD_GSTPLUGIN_PATH}")
# endif()

execute_process(COMMAND ${LD_PATH} --appdir ${APPDIR_PATH} --output appimage)
execute_process(COMMAND ${LD_PATH} --appdir ${APPDIR_PATH} --output appimage --custom-apprun ${CMAKE_BINARY_DIR}/AppRun)
# --exclude-library "libX*"
# --exclude-library "libglib*"
# --exclude-library "libgobject*"
Expand Down
4 changes: 2 additions & 2 deletions cmake/CreateMacDMG.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# include(BundleUtilities)

message(STATUS "Copy GStreamer framework into bundle")
# message(STATUS "Copy GStreamer framework into bundle")
file(COPY /Library/Frameworks/GStreamer.framework DESTINATION staging/QGroundControl.app/Contents/Frameworks)
file(REMOVE_RECURSE staging/QGroundControl.app/Contents/Frameworks/GStreamer.framework/Versions/1.0/bin)
file(REMOVE_RECURSE staging/QGroundControl.app/Contents/Frameworks/GStreamer.framework/Versions/1.0/etc)
Expand All @@ -23,7 +23,7 @@ file(REMOVE ${REMOVE_LIB_FILES})
file(REMOVE_RECURSE staging/QGroundControl.app/Contents/Frameworks/GStreamer.framework/Versions/1.0/lib/gstreamer-1.0/include)
file(REMOVE_RECURSE staging/QGroundControl.app/Contents/Frameworks/GStreamer.framework/Versions/1.0/lib/gstreamer-1.0/pkgconfig)

# Fix up library paths to point into bundle
# # Fix up library paths to point into bundle
execute_process(COMMAND install_name_tool -change @rpath/libgstgl-1.0.0.dylib @executable_path/../Frameworks/GStreamer.framework/Libraries/libgstgl-1.0.0.dylib staging/QGroundControl.app/Contents/MacOS/QGroundControl)
execute_process(COMMAND install_name_tool -change @rpath/libgstvideo-1.0.0.dylib @executable_path/../Frameworks/GStreamer.framework/Libraries/libgstvideo-1.0.0.dylib staging/QGroundControl.app/Contents/MacOS/QGroundControl)
execute_process(COMMAND install_name_tool -change @rpath/libgstbase-1.0.0.dylib @executable_path/../Frameworks/GStreamer.framework/Libraries/libgstbase-1.0.0.dylib staging/QGroundControl.app/Contents/MacOS/QGroundControl)
Expand Down
1 change: 1 addition & 0 deletions cmake/Qt6QGCConfiguration.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@ cmake_print_variables(QT_VERSION QT_MKSPEC QT_LIBRARY_HINTS)

# if(ANDROID)
# set(ENV{PKG_CONFIG_SYSROOT_DIR} ${CMAKE_SYSROOT})
# message(STATUS "PKG_CONFIG_SYSROOT_DIR $ENV{PKG_CONFIG_SYSROOT_DIR}")
# endif()
Loading

0 comments on commit 9686b0b

Please sign in to comment.