Skip to content

Commit 7e011a0

Browse files
authored
Create a source plugin too. (#19)
1 parent bec1307 commit 7e011a0

11 files changed

Lines changed: 437 additions & 58 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
target/
33
*.mp4
44
*.fmp4
5-
debug/
5+
debug/

Cargo.lock

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ moq-karp = "0.14"
1919

2020
gst = { package = "gstreamer", version = "0.23" }
2121
gst-base = { package = "gstreamer-base", version = "0.23" }
22+
gst-app = { package = "gstreamer-app", version = "0.23", features = ["v1_20"] }
23+
2224
once_cell = "1"
2325
tokio = { version = "1", features = ["full"] }
2426
env_logger = "0.9"

README.md

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,39 @@
1+
<p align="center">
2+
<img height="128px" src="https://github.com/kixelated/moq-rs/blob/main/.github/logo.svg" alt="Media over QUIC">
3+
</p>
4+
15
A gstreamer plugin utilizing [moq-rs](https://github.com/kixelated/moq-rs).
26

37
# Usage
4-
Check out the `dev/pub` script for an example pipeline.
8+
## Requirements
9+
- [Rustup](https://www.rust-lang.org/tools/install)
10+
- [Just](https://github.com/casey/just?tab=readme-ov-file#installation)
11+
12+
## Setup
13+
We use `just` to simplify the development process.
14+
Check out the [Justfile](justfile) or run `just` to see the available commands.
515

6-
```bash
7-
./dev/pub
16+
Install any other required tools:
17+
```sh
18+
just setup
819
```
920

10-
By default this uses a localhost relay.
11-
You can change the ENV args if you want to make it watchable on production instead:
21+
## Development
22+
First make sure you have a local moq-relay server running:
23+
```sh
24+
# In github.com/kixelated/moq-rs
25+
just relay
26+
```
27+
28+
Now you can publish and subscribe to a video:
29+
```sh
30+
# In github.com/kixelated/moq-gst
31+
32+
# Publish to a localhost moq-relay server
33+
just pub
1234

13-
```bash
14-
ADDR=relay.quic.video NAME=something ./dev/pub
35+
# Subscribe from a localhost moq-relay server
36+
just sub
1537
```
1638

1739
# License

dev/pub

Lines changed: 0 additions & 48 deletions
This file was deleted.

justfile

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/usr/bin/env just --justfile
2+
3+
# Using Just: https://github.com/casey/just?tab=readme-ov-file#installation
4+
5+
export RUST_BACKTRACE := "1"
6+
export RUST_LOG := "info"
7+
export URL := "http://localhost:4443"
8+
#export GST_DEBUG:="*:4"
9+
10+
# List all of the available commands.
11+
default:
12+
just --list
13+
14+
# Install any required dependencies.
15+
setup:
16+
# Upgrade Rust
17+
rustup update
18+
19+
# Make sure the right components are installed.
20+
rustup component add rustfmt clippy
21+
22+
# Install cargo binstall if needed.
23+
cargo install cargo-binstall
24+
25+
# Install cargo shear if needed.
26+
cargo binstall --no-confirm cargo-shear
27+
28+
# Download the video and convert it to a fragmented MP4 that we can stream
29+
download name url:
30+
if [ ! -f dev/{{name}}.mp4 ]; then \
31+
wget {{url}} -O dev/{{name}}.mp4; \
32+
fi
33+
34+
if [ ! -f dev/{{name}}.fmp4 ]; then \
35+
ffmpeg -i dev/{{name}}.mp4 \
36+
-c copy \
37+
-f mp4 -movflags cmaf+separate_moof+delay_moov+skip_trailer+frag_every_frame \
38+
dev/{{name}}.fmp4; \
39+
fi
40+
41+
# Publish a video using ffmpeg to the localhost relay server
42+
pub: (download "bbb" "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4")
43+
# Build the plugins
44+
cargo build
45+
46+
# Run gstreamer and pipe the output to our plugin
47+
GST_PLUGIN_PATH="${PWD}/target/debug${GST_PLUGIN_PATH:+:$GST_PLUGIN_PATH}" \
48+
gst-launch-1.0 -v -e multifilesrc location="dev/bbb.fmp4" loop=true ! qtdemux name=demux \
49+
demux.video_0 ! h264parse ! queue ! identity sync=true ! isofmp4mux name=mux chunk-duration=1 fragment-duration=1 ! moqsink url="$URL/demo/bbb" tls-disable-verify=true \
50+
demux.audio_0 ! aacparse ! queue ! mux.
51+
52+
# Subscribe to a video using gstreamer
53+
sub:
54+
# Build the plugins
55+
cargo build
56+
57+
# Run gstreamer and pipe the output to our plugin
58+
# This will render the video to the screen
59+
GST_PLUGIN_PATH="${PWD}/target/debug${GST_PLUGIN_PATH:+:$GST_PLUGIN_PATH}" \
60+
gst-launch-1.0 -v -e moqsrc url="$URL/demo/bbb" tls-disable-verify=true ! decodebin ! videoconvert ! autovideosink
61+
62+
# Run the CI checks
63+
check $RUSTFLAGS="-D warnings":
64+
cargo check --all-targets
65+
cargo clippy --all-targets -- -D warnings
66+
cargo fmt -- --check
67+
cargo shear # requires: cargo binstall cargo-shear
68+
69+
# Run any CI tests
70+
test $RUSTFLAGS="-D warnings":
71+
cargo test
72+
73+
# Automatically fix some issues.
74+
fix:
75+
cargo fix --allow-staged --all-targets --all-features
76+
cargo clippy --fix --allow-staged --all-targets --all-features
77+
cargo fmt --all
78+
cargo shear --fix
79+
80+
# Upgrade any tooling
81+
upgrade:
82+
rustup upgrade
83+
84+
# Install cargo-upgrades if needed.
85+
cargo install cargo-upgrades cargo-edit
86+
cargo upgrade
87+
88+
# Build the plugins
89+
build:
90+
cargo build

src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
use gst::glib;
22

33
mod sink;
4+
mod source;
45

56
pub fn plugin_init(plugin: &gst::Plugin) -> Result<(), glib::BoolError> {
7+
env_logger::init();
68
sink::register(plugin)?;
9+
source::register(plugin)?;
10+
711
Ok(())
812
}
913

src/sink/imp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl ElementImpl for MoqSink {
9494
static ELEMENT_METADATA: Lazy<gst::subclass::ElementMetadata> = Lazy::new(|| {
9595
gst::subclass::ElementMetadata::new(
9696
"MoQ Sink",
97-
"Sink",
97+
"Sink/Network/MoQ",
9898
"Transmits media over the network via MoQ",
9999
"Luke Curley <kixelated@gmail.com>",
100100
)

src/sink/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,5 @@ glib::wrapper! {
88
}
99

1010
pub fn register(plugin: &gst::Plugin) -> Result<(), glib::BoolError> {
11-
env_logger::init();
1211
gst::Element::register(Some(plugin), "moqsink", gst::Rank::NONE, MoqSink::static_type())
1312
}

0 commit comments

Comments
 (0)