Skip to content

Commit

Permalink
feat: generate gstreamer registry if gst-launch-1.0 is present
Browse files Browse the repository at this point in the history
closes #158
  • Loading branch information
azubieta committed Oct 15, 2021
1 parent e8c8031 commit a643d86
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions appimagebuilder/modules/setup/helpers/gstreamer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
import logging
import os
import shutil
import subprocess

from appimagebuilder.utils.finder import Finder
from .base_helper import BaseHelper
Expand All @@ -21,6 +24,7 @@ def configure(self, env: Environment):
self._set_gst_plugins_path(env)
self._set_gst_plugins_scanner_path(env)
self._set_ptp_helper_path(env)
self._generate_gst_registry(env)

def _set_gst_plugins_path(self, env):
gst_1_lib_path = self.finder.find_one(
Expand All @@ -47,3 +51,32 @@ def _set_ptp_helper_path(self, app_run):
)
if gst_ptp_helper_path:
app_run.set("GST_PTP_HELPER", gst_ptp_helper_path)

def _generate_gst_registry(self, env):
gst_launch_bin = shutil.which("gst-launch-1.0")
if gst_launch_bin and "GST_PLUGIN_PATH" in env:
env.set("GST_REGISTRY", env["GST_PLUGIN_PATH"] + "/registry.bin")

gst_launch_env = self._prepare_gst_launch_env(env)
# run gst "diagnostic" to force registry generation
# https://gstreamer.freedesktop.org/documentation/tools/gst-launch.html?gi-language=c#diagnostic
proc = subprocess.run(
[gst_launch_bin, "fakesrc", "num-buffers=16", "!", "fakesink"],
env=gst_launch_env,
)
if proc.returncode == 0:
env.set("GST_REGISTRY_UPDATE", "no")
logging.info(f"GST_REGISTRY generated at: {env['GST_REGISTRY']}")
else:
logging.warning(f"GST_REGISTRY generation failed!")
del env["GST_REGISTRY"]
else:
logging.warning(f"gst-launch-1.0 not found! It is required to generate gstreamer registry")

def _prepare_gst_launch_env(self, env):
gst_launch_env = os.environ
for key in env.keys():
if key.startswith("GST"):
gst_launch_env[key] = env[key].__str__()

return gst_launch_env

0 comments on commit a643d86

Please sign in to comment.