Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions .github/homebrew/Formula/moq-gst.rb.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@ class MoqGst < Formula
end

def install
lib.install Dir["lib/libgstmoq.*"]
plugin = OS.mac? ? "libgstmoq.dylib" : "libgstmoq.so"
(lib/"gstreamer-1.0").install "lib/gstreamer-1.0/#{plugin}"
end

def caveats
<<~EOS
The moq GStreamer plugin is installed at:
#{opt_lib}/libgstmoq.#{OS.mac? ? "dylib" : "so"}
#{opt_lib}/gstreamer-1.0/libgstmoq.#{OS.mac? ? "dylib" : "so"}

For GStreamer to discover it, add this prefix to GST_PLUGIN_PATH:
export GST_PLUGIN_PATH="#{opt_lib}:$GST_PLUGIN_PATH"
For GStreamer to discover it, add this directory to GST_PLUGIN_PATH_1_0:
export GST_PLUGIN_PATH_1_0="#{opt_lib}/gstreamer-1.0:$GST_PLUGIN_PATH_1_0"

Then verify with:
gst-inspect-1.0 moq
Expand All @@ -43,8 +44,11 @@ class MoqGst < Formula

test do
plugin = OS.mac? ? "libgstmoq.dylib" : "libgstmoq.so"
assert_predicate lib/plugin, :exist?
ENV["GST_PLUGIN_PATH"] = lib
system Formula["gstreamer"].opt_bin/"gst-inspect-1.0", "moq"
assert_predicate lib/"gstreamer-1.0"/plugin, :exist?
ENV["GST_REGISTRY"] = (testpath/"registry.bin").to_s
ENV["GST_PLUGIN_PATH_1_0"] = (lib/"gstreamer-1.0").to_s
ENV["GST_PLUGIN_SYSTEM_PATH_1_0"] = ""
output = shell_output("#{Formula["gstreamer"].opt_bin}/gst-inspect-1.0 moq")
assert_match (lib/"gstreamer-1.0"/plugin).to_s, output
end
end
6 changes: 6 additions & 0 deletions .github/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ check:

# Tests of the release tooling itself; nightly, not on every pull request.
test:
python3 sh/gh/gst-formula.test.py
python3 sh/gh/install-formula.test.py
sh/gh/release.test.sh
python3 sh/gh/ffi.test.py
Expand Down Expand Up @@ -45,3 +46,8 @@ trigger-repo-publish *args:
[positional-arguments]
ffi *args:
python3 sh/gh/ffi.py "$@"

# Install the rendered GStreamer formula against the current macOS tarball.
[positional-arguments]
gst-formula *args:
python3 sh/gh/gst-formula.py "$@"
7 changes: 7 additions & 0 deletions .github/workflows/moq-gst.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ jobs:
tar -xzf "dist/moq-gst-v${VERSION}-${TARGET}.tar.gz" -C dist/
just rs gst-smoke "dist/moq-gst-v${VERSION}-${TARGET}/lib/gstreamer-1.0"

- name: Test Homebrew formula against tarball
if: runner.os == 'macOS'
env:
TARGET: ${{ matrix.target }}
VERSION: ${{ steps.parse.outputs.version }}
run: just gh gst-formula "$VERSION" "$TARGET" dist

- name: Upload artifact
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
Expand Down
4 changes: 3 additions & 1 deletion doc/bin/gstreamer.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ gst-launch-1.0 -e videotestsrc is-live=true ! x264enc tune=zerolatency ! h264par
```

Install via `apt install gstreamer1.0-moq` or `dnf install gstreamer1-moq`
([Install](/setup/install)), or build with `cargo build -p moq-gst` and point
([Install](/setup/install)). With Homebrew, run `brew install moq-dev/tap/moq-gst`
and add `$(brew --prefix moq-gst)/lib/gstreamer-1.0` to `GST_PLUGIN_PATH_1_0`.
For a source build, run `cargo build -p moq-gst` and point
`GST_PLUGIN_PATH_1_0` at the output. `http://` URLs pin the relay's
certificate fingerprint automatically, so local development needs no TLS setup.
That scheme is for localhost only: the fingerprint is fetched unauthenticated
Expand Down
8 changes: 7 additions & 1 deletion nix/overlay.nix
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ in
# User-facing flake output. Bundles the plugin with wrapped gstreamer
# tools so a single `nix shell .#moq-gst` gives you gst-inspect-1.0 /
# gst-launch-1.0 that already know about the moq plugin plus the usual
# base/good/bad plugin set, matching the "install a plugin and the
# base/good/bad/ugly/libav plugin set, matching the "install a plugin and the
# standard tools find it" UX. `nix shell` (unlike nix-shell / nix
# develop) doesn't run nixpkgs setup-hooks, so a bare lib/gstreamer-1.0
# directory in $out isn't enough on its own.
Expand All @@ -340,6 +340,8 @@ in
"${final.gst_all_1.gst-plugins-base}/lib/gstreamer-1.0"
"${final.gst_all_1.gst-plugins-good}/lib/gstreamer-1.0"
"${final.gst_all_1.gst-plugins-bad}/lib/gstreamer-1.0"
"${final.gst_all_1.gst-plugins-ugly}/lib/gstreamer-1.0"
"${final.gst_all_1.gst-libav}/lib/gstreamer-1.0"
];
in
final.symlinkJoin {
Expand All @@ -353,6 +355,10 @@ in
makeWrapper "${final.gst_all_1.gstreamer.bin}/bin/$tool" "$out/bin/$tool" \
--suffix GST_PLUGIN_SYSTEM_PATH_1_0 : "${pluginPaths}"
done
export GST_REGISTRY="$TMPDIR/gst-registry.bin"
for element in moq x264enc avenc_aac avdec_h264; do
$out/bin/gst-inspect-1.0 "$element" > /dev/null
done
'';
meta.mainProgram = "gst-inspect-1.0";
};
Expand Down
2 changes: 1 addition & 1 deletion rs/moq-gst/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ sudo dnf install gstreamer1-moq

### Nix (Linux or Apple Silicon macOS)

The `moq-gst` flake output bundles the plugin with wrappers around `gst-inspect-1.0` / `gst-launch-1.0` that preload moq + the standard `gst-plugins-{base,good,bad}` set, so no `GST_PLUGIN_PATH` setup is needed.
The `moq-gst` flake output bundles the plugin with wrappers around `gst-inspect-1.0` / `gst-launch-1.0` that preload moq + the standard `gst-plugins-{base,good,bad,ugly}` and `gst-libav` sets, so no `GST_PLUGIN_PATH` setup is needed.

```bash
# Inspect: list moqsink + moqsrc. (Or one-shot: `nix run github:moq-dev/moq/release#moq-gst -- moq`.)
Expand Down
34 changes: 34 additions & 0 deletions sh/gh/gst-formula.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env python3
"""Install and test the GStreamer formula with the just-built macOS tarball."""

import hashlib
import os
from pathlib import Path
import subprocess
import sys

version, target, release_dir = sys.argv[1:]
if target != "aarch64-apple-darwin":
raise ValueError("the Homebrew smoke test requires the macOS arm64 archive")
archive = (Path(release_dir) / f"moq-gst-v{version}-{target}.tar.gz").resolve(strict=True)
template = Path(".github/homebrew/Formula/moq-gst.rb.tmpl").read_text()
sha = hashlib.sha256(archive.read_bytes()).hexdigest()
formula = template.replace("__VERSION__", version)
for platform in ["AARCH64_APPLE_DARWIN", "AARCH64_UNKNOWN_LINUX_GNU", "X86_64_UNKNOWN_LINUX_GNU"]:
formula = formula.replace(f"__SHA256_{platform}__", sha)
remote = f"https://github.com/moq-dev/moq/releases/download/moq-gst-v#{{version}}/moq-gst-v#{{version}}-{target}.tar.gz"
formula = formula.replace(remote, archive.as_uri())
environment = dict(os.environ, HOMEBREW_NO_AUTO_UPDATE="1")
installed = subprocess.run(["brew", "list", "--formula", "--versions"], capture_output=True, text=True, env=environment, check=True)
if any(line.split()[0].split("/")[-1] == "moq-gst" for line in installed.stdout.splitlines() if line.strip()):
raise ValueError("moq-gst is already installed; run this test in a clean Homebrew environment")
subprocess.run(["brew", "tap-new", "moq-dev/ci-gst"], check=True, env=environment)
try:
tap = subprocess.check_output(["brew", "--repository", "moq-dev/ci-gst"], text=True, env=environment).strip()
output = Path(tap) / "Formula/moq-gst.rb"
output.write_text(formula)
subprocess.run(["brew", "install", "--build-from-source", "moq-dev/ci-gst/moq-gst"], check=True, env=environment)
subprocess.run(["brew", "test", "moq-dev/ci-gst/moq-gst"], check=True, env=environment)
finally:
subprocess.run(["brew", "uninstall", "--force", "moq-dev/ci-gst/moq-gst"], check=False, env=environment)
subprocess.run(["brew", "untap", "moq-dev/ci-gst"], check=True, env=environment)
52 changes: 52 additions & 0 deletions sh/gh/gst-formula.test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"""Exercise the CI installer's ownership boundary without changing Homebrew."""
import runpy
import subprocess
import sys
import tempfile
import unittest
from pathlib import Path
from unittest.mock import patch

SCRIPT = Path(__file__).with_name('gst-formula.py')


class Installer(unittest.TestCase):
def invoke(self, directory, target='aarch64-apple-darwin'):
archive = directory / f'moq-gst-v1.2.3-{target}.tar.gz'
archive.write_bytes(b'archive fixture')
with patch.object(sys, 'argv', [str(SCRIPT), '1.2.3', target, str(directory)]):
runpy.run_path(str(SCRIPT), run_name='__main__')

def test_existing_install_is_not_owned_or_removed(self):
with tempfile.TemporaryDirectory() as tmp, patch('subprocess.run', return_value=subprocess.CompletedProcess([], 0, 'moq-gst 1.0\n', '')) as run, patch('subprocess.check_output', return_value=tmp):
(Path(tmp) / 'Formula').mkdir()
with self.assertRaisesRegex(ValueError, 'already installed'):
self.invoke(Path(tmp))
self.assertEqual([call.args[0] for call in run.call_args_list], [['brew', 'list', '--formula', '--versions']])

def test_other_target_refused_before_brew(self):
with tempfile.TemporaryDirectory() as tmp, patch('subprocess.run') as run:
with self.assertRaisesRegex(ValueError, 'macOS'):
self.invoke(Path(tmp), 'x86_64-unknown-linux-gnu')
run.assert_not_called()

def test_failed_test_cleans_only_created_tap_and_install(self):
with tempfile.TemporaryDirectory() as tmp:
root = Path(tmp)
(root / 'Formula').mkdir()
def brew(command, **kwargs):
if command[1] == 'test':
raise subprocess.CalledProcessError(1, command)
return subprocess.CompletedProcess(command, 0, '', '')
with patch('subprocess.run', side_effect=brew) as run, patch('subprocess.check_output', return_value=str(root)):
with self.assertRaises(subprocess.CalledProcessError):
self.invoke(root)
commands = [call.args[0] for call in run.call_args_list]
self.assertEqual(commands[-2:], [['brew', 'uninstall', '--force', 'moq-dev/ci-gst/moq-gst'], ['brew', 'untap', 'moq-dev/ci-gst']])
formula = (root / 'Formula/moq-gst.rb').read_text()
self.assertIn((root / 'moq-gst-v1.2.3-aarch64-apple-darwin.tar.gz').as_uri(), formula)
self.assertNotIn('__VERSION__', formula)


if __name__ == '__main__':
unittest.main()
Loading