Skip to content

Commit

Permalink
Add a gstreamer servosrc plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Jeffrey committed Nov 25, 2019
1 parent a562808 commit 69acec1
Show file tree
Hide file tree
Showing 11 changed files with 1,079 additions and 6 deletions.
96 changes: 90 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[workspace]
members = [
"ports/glutin",
"ports/gstplugin",
"ports/libsimpleservo/capi/",
"ports/libsimpleservo/jniapi/",
"ports/libmlservo/",
Expand Down
3 changes: 3 additions & 0 deletions etc/taskcluster/decision_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ def linux_tidy_unit():
./mach build --dev --features canvas2d-raqote
./mach build --dev --features layout-2020
./mach build --dev --libsimpleservo
./mach build --dev -p servo-gst-plugin
./mach test-tidy --no-progress --self-test
./etc/memory_reports_over_time.py --test
Expand Down Expand Up @@ -485,6 +486,8 @@ def windows_unit(cached=True):
"mach smoketest --angle",
"mach package --dev",
"mach build --dev --libsimpleservo",
"mach build --dev -p servo-gst-plugin",

)
.with_artifacts("repo/target/debug/msi/Servo.exe",
"repo/target/debug/msi/Servo.zip")
Expand Down
38 changes: 38 additions & 0 deletions ports/gstplugin/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[package]
name = "servo-gst-plugin"
description = "A GStreamer plugin that provides servosrc"
version = "0.0.1"
authors = ["The Servo Project Developers"]
license = "MPL-2.0"
edition = "2018"
build = "build.rs"
repository = "https://github.com/servo/servo/"
publish = false

[lib]
name = "gstservoplugin"
crate-type = ["cdylib"]
path = "lib.rs"

[dependencies]
crossbeam-channel = "0.3"
euclid = "0.20"
gleam = "0.6"
glib = { version = "0.8", features = ["subclassing"] }
gstreamer = { version = "0.14", features = ["subclassing"] }
gstreamer-base = { version = "0.14", features = ["subclassing"] }
gstreamer-gl = { version = "0.14", features = ["v1_16"] }
gstreamer-video = { version = "0.14", features = ["subclassing"] }
log = "0.4"
lazy_static = "1.4"
libservo = {path = "../../components/servo"}
servo-media = {git = "https://github.com/servo/media"}
sparkle = "0.1"
# NOTE: the sm-angle-default feature only enables angle on windows, not other platforms!
surfman = { version = "0.1", features = ["sm-angle-default", "sm-osmesa"] }
surfman-chains-api = "0.2"
surfman-chains = "0.2.1"

[build-dependencies]
gst-plugin-version-helper = "0.1"

131 changes: 131 additions & 0 deletions ports/gstplugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# A GStreamer plugin which runs servo

## Build

```
./mach build -r -p servo-gst-plugin
```

## Install

By default, gstreamer's plugin finder will complain about any libraries it finds that aren't
gstreamer plugins, so we need to have a directory just for plugins:
```
mkdir target/gstplugins
```

To install:
```
cp target/release/libgstservoplugin.* target/gstplugins
```
## Run

To run locally:
```
GST_PLUGIN_PATH=target/gstplugins \
gst-launch-1.0 servosrc \
! queue \
! video/x-raw,framerate=25/1,width=512,height=512 \
! videoflip video-direction=vert \
! autovideosink
```

To stream over the network:
```
GST_PLUGIN_PATH=target/gstplugins \
gst-launch-1.0 servosrc \
! queue \
! video/x-raw,framerate=25/1,width=512,height=512 \
! videoconvert \
! videoflip video-direction=vert \
! theoraenc \
! oggmux \
! tcpserversink host=127.0.0.1 port=8080
```

To save to a file:
```
GST_PLUGIN_PATH=target/gstplugins \
gst-launch-1.0 servosrc num-buffers=2000 \
! queue \
! video/x-raw,framerate=25/1,width=512,height=512 \
! videoconvert \
! videoflip video-direction=vert \
! theoraenc \
! oggmux \
! filesink location=test.ogg
```

*Note*: killing the gstreamer pipeline with control-C sometimes locks up macOS to the point
of needing a power cycle. Killing the pipeline by closing the window seems to work.

## Troubleshooting building the plugin

You may need to make sure rust picks up the right gstreamer, for example:
```
PKG_CONFIG_PATH=$PWD/support/linux/gstreamer/gst/lib \
LD_LIBRARY_PATH=$PWD/support/linux/gstreamer/gst/lib \
./mach build -r -p servo-gst-plugin
```

## Troubleshooting running the plugin

*Currently x11 support is broken!*

First try:
```
GST_PLUGIN_PATH=target/gstplugins \
gst-inspect-1.0 servosrc
```

If that doesn't work, try:
```
GST_PLUGIN_PATH=target/gstplugins \
gst-in2spect-1.0 target/gstplugins/libgstservoplugin.so
```

If you get reports about the plugin being blacklisted, remove the (global!) gstreamer cache, e.g. under Linux:
```
rm -r ~/.cache/gstreamer-1.0
```

If you get complaints about not being able to find libraries, set `LD_LIBRARY_PATH`, e.g. to use Servo's Linux gstreamer:
```
LD_LIBRARY_PATH=$PWD/support/linux/gstreamer/gst/lib
```

If you get complaints `cannot allocate memory in static TLS block` this is caused by gstreamer initializing threads using
the system alloc, which causes problems if those threads run Rust code that uses jemalloc. The fix is to preload the plugin:
```
LD_PRELOAD=$PWD/target/gstplugins/libgstservoplugin.so
```

You may need to set `GST_PLUGIN_SCANNER`, e.g. to use Servo's:
```
GST_PLUGIN_SCANNER=$PWD/support/linux/gstreamer/gst/libexec/gstreamer-1.0/gst-plugin-scanner
```

You may need to include other directories on the plugin search path, e.g. Servo's gstreamer:
```
GST_PLUGIN_PATH=$PWD/target/gstplugins/:$PWD/support/linux/gstreamer/gst/lib
```

Under X11 you may get complaints about X11 threads not being initialized:
```
GST_GL_XINITTHREADS=1
```

Under x11 you may get a frozen display from `autovideosink`, try `ximagesink` instead.

Putting that all together:
```
GST_GL_XINITTHREADS=1 \
GST_PLUGIN_PATH=$PWD/target/gstplugins/:$PWD/support/linux/gstreamer/gst/lib \
GST_PLUGIN_SCANNER=$PWD/support/linux/gstreamer/gst/libexec/gstreamer-1.0/gst-plugin-scanner \
LD_LIBRARY_PATH=$PWD/support/linux/gstreamer/gst/lib \
LD_PRELOAD=$PWD/target/gstplugins/libgstservoplugin.so \
gst-launch-1.0 servosrc \
! queue \
! videoflip video-direction=vert \
! ximagesink
```
7 changes: 7 additions & 0 deletions ports/gstplugin/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

fn main() {
gst_plugin_version_helper::get_info()
}
Loading

0 comments on commit 69acec1

Please sign in to comment.