Compare commits

...

1060 commits
0.18.4 ... main

Author SHA1 Message Date
Sebastian Dröge 413a6baa8c Update CHANGELOG.md for 0.22.5 2024-05-23 16:06:42 +03:00
Sebastian Dröge 9e2c6268cb gstreamer: Use usize instead of u32 for various indices
This affects buffers, caps, caps features, structures and tag lists and
makes it easier to use them with other Rust APIs that use usize-based
indicing.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1445>
2024-05-22 08:15:08 +00:00
Tim-Philipp Müller 4cda565a39 gstreamer: bufferlist: add another test for foreach_mut
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1446>
2024-05-22 06:59:40 +00:00
Sebastian Dröge 805cd6c591 gstreamer: bufferlist: Change remove function to take a range instead of index + length
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1444>
2024-05-21 08:21:17 +03:00
Sebastian Dröge a0e58ec359 gstreamer: bufferlist: Check index/length when removing a buffer
Out of range values give assertions in the C function.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1444>
2024-05-21 08:19:30 +03:00
Sebastian Dröge 9f151466b7 gstreamer: bufferlist: Check for out of range indices before trying to get buffer
Passing an index bigger than the length will cause an assertion in the C
function.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1444>
2024-05-21 08:11:41 +03:00
Sebastian Dröge 1b537c17c8 Update Cargo.lock
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1443>
2024-05-20 14:06:30 +03:00
Sebastian Dröge c3619b45aa Update to itertools 0.13
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1443>
2024-05-20 14:03:58 +03:00
Seungha Yang f59029b57c event: Fix leak in SelectStreamsBuilder
gst_event_new_select_streams() does not take ownership of GList

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1442>
2024-05-16 14:30:52 +00:00
Sebastian Dröge b468280353 Improve code generation with panic=abort around panic handling code
None of that can ever be called in that case but the compiler can't know
that in more complicated cases like these. Handling it explicitly allows
no handling code to be generated at all here, like would already happen
everywhere else.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1441>
2024-05-16 16:38:15 +03:00
Mathieu Duponchelle 0ef80c4fe7 streamproducer: expose set_forward_preroll() API
This is useful to decide whether the preroll sample should be forwarded
to consumers when prerolling or only once it is time to render it.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1439>
2024-05-10 22:46:16 +00:00
Sebastian Dröge 455996c60b rtsp-server: Fix compilation after from_glib_ptr_borrow() API improvements
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1440>
2024-05-10 10:35:19 +03:00
Sebastian Dröge 83fe420466 Update Cargo.lock
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1440>
2024-05-10 10:09:10 +03:00
Sebastian Dröge 5af4a262b8 Regenerate with latest GStreamer gir files
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1440>
2024-05-10 10:09:10 +03:00
Sebastian Dröge b8dbfc66ca pbutils: Remove unnecessary nullable override and add override for new API
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1440>
2024-05-10 10:09:10 +03:00
Sebastian Dröge b15e0e1633 Update GStreamer gir files
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1440>
2024-05-10 10:09:10 +03:00
Sebastian Dröge a430291725 Update gir-files
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1440>
2024-05-10 10:09:10 +03:00
Sebastian Dröge 0ee36ea4b5 ci: Update to rustup 1.27.1
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1440>
2024-05-10 10:09:07 +03:00
Sebastian Dröge a7a0bf226d ci: Update image version to rebuild it
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1440>
2024-05-10 10:09:07 +03:00
Naglis Jonaitis 19ea814a09 examples: Update playbin flag handling snippet
Closes #512

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1438>
2024-05-09 11:45:00 +03:00
Sebastian Dröge 2a9d0d035f Fix various new 1.78 clippy warnings
Quite a bit of API was accidentally not exported but apparently nobody
was using it.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1437>
2024-05-02 18:13:27 +03:00
Sebastian Dröge 1e293e5cb8 ci: Update to Rust 1.78.0
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1437>
2024-05-02 16:34:15 +03:00
Sebastian Dröge fe1fe5b114 gstreamer: Use a reference to a pointer of correct mutability for from_glib_ptr_borrow()
This hopefully makes it easier to use and harder to get the returned
lifetime wrong.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1436>
2024-04-30 15:39:15 +03:00
Sebastian Dröge 238768f525 Update Cargo.lock
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1435>
2024-04-30 12:36:37 +03:00
Sebastian Dröge 2f99c4c560 rtp: Only use glib::translate if 1.24 APIs are enabled
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1435>
2024-04-30 12:36:37 +03:00
Sebastian Dröge 9fca740851 ci: Run Linux clippy build with 1.26 APIs enabled
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1435>
2024-04-30 12:36:37 +03:00
Sebastian Dröge 9490735655 ci: Enable gstreamer-mpegts and gstreamer-tag on Windows
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1435>
2024-04-30 12:36:37 +03:00
Sebastian Dröge 81b20b9329 ci: Enable allocators, analytics, play, rtp and validate sys tests
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1435>
2024-04-30 12:36:37 +03:00
Sebastian Dröge ba4bd5c631 Add 1.26 version features and update 1.24 requirement from 1.23 to 1.24
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1435>
2024-04-30 12:36:37 +03:00
Sebastian Dröge 4b79dddc14 video: Remove some unnecessary #[cfg] attributes
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1435>
2024-04-30 12:36:37 +03:00
Sebastian Dröge 01b32ce143 video: Add double click mouse event
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1435>
2024-04-30 12:36:37 +03:00
Sebastian Dröge 873aeff133 Regenerate with latest GStreamer gir files
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1435>
2024-04-30 12:36:37 +03:00
Sebastian Dröge 87cc9fe6e4 Fix or update various overrides in Gir.toml
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1435>
2024-04-30 12:36:37 +03:00
Sebastian Dröge bac0828260 ci: Rebuild image to get latest GStreamer
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1435>
2024-04-30 12:29:04 +03:00
Sebastian Dröge 200d8b1c0c Update GStreamer gir files
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1435>
2024-04-30 12:29:04 +03:00
François Laignel dc04a53207 ci: test gstreamer-editing-services/sys
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1434>
2024-04-30 09:52:14 +02:00
François Laignel 0bb334e14c regen
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1434>
2024-04-30 09:52:12 +02:00
François Laignel 46226106b4 ges: ignore deprecated PitiviFormatter & PitiviFormatterClass
... they cause ABI tests failures and should be ignored.

See https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1425#note_2380648

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1434>
2024-04-30 09:51:35 +02:00
Nick Steel b7b5352353 log: Log trait adapter around the GStreamer debug system
Allows usage of normal `log` crate macros, and for other crates
using those macros to have their log messages go to the GStreamer
debug logs.

This implementation is based on the one found in Servo.

Fixes #187

DebugCategoryLogger is optional via 'log' feature
check category above threshold
skip_assert_initialized for constructor and helper

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1426>
2024-04-29 16:16:47 +01:00
Jordan Petridis 88a6977777 ci: Bump the image tag to rebuild
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1433>
2024-04-28 10:40:00 +03:00
Jordan Petridis cb560e59a3 ci: Move GST_UPSTREAM_BRANCH into the images_template.yml
Used for determining which version of gstreamer we will build
in the docker images. Move it along ther other variables so
it will be easier to update.

Also change ci/install-gst.sh to avoid hardoding the version
and instead use the variable like the windows build does.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1433>
2024-04-28 10:29:37 +03:00
Sebastian Dröge 241338f43c audio: video: Improve Display trait impl test for AudioFormat and Video a bit
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1432>
2024-04-27 16:10:49 +00:00
Sebastian Dröge 5c8a989029 video: Remove nonsensical test
Printing an unknown video format returns NULL, and with latest git main
this actually causes a critical warning in addition.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1432>
2024-04-27 16:10:49 +00:00
Sebastian Dröge 57050f66c6 Regenerate with latest gir / gir-files
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1429>
2024-04-27 11:31:11 +03:00
Sebastian Dröge 63654c67da Update gir-files
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1429>
2024-04-27 11:30:29 +03:00
Sebastian Dröge 70a15e8dbe Update gir
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1429>
2024-04-27 11:30:25 +03:00
François Laignel 953e3747f2 Pad: allow building a Pad with an automatically generated name
For convenience, the `Pad` builder checks a name is provided when a wildcard-
named template is used. For `GhostPad`s, the builder tries to assign the name of
the target `Pad` making sure the provided `name` conforms to the `PadTemplate`.

This commit adds a function to optionally keep the `gst::Object` automatically
generated unique `Pad` name (such as `ghostpad4`) and reorganises name handling
so it is processed when `build` is invoked.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1428>
2024-04-26 09:57:28 +00:00
Sebastian Dröge e117010bc0 Update Cargo.lock
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1427>
2024-04-25 12:05:49 +03:00
Sebastian Dröge 694d1fd39b examples: Update to windows 0.56
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1427>
2024-04-25 12:05:49 +03:00
François Laignel db03c8edd1 Add field_if_some setter for builder ClockTime fields
Optional `ClockTime` fields already implemented their setters in such a way
that they could accept either `Option<ClockTime>` or `ClockTime`. This commit
adds `field_if_some()` setter variants for builder `ClockTime` builder fields
for consistency with other builder fields.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1424>
2024-04-17 17:15:41 +02:00
François Laignel ea25c9262b Add field_if_some setter for builders
This commit adds `_if_some()` variants for builder field setters.
The variants aim at improving usability when setting optional fields.
E.g. currently, we need to write something like:

```rust
let opt_value = ...;
let mut sb = gst::Structure::builder("test")
    .field("mandatory_field", "mandatory");

if let Some(value) = opt_value
    sb = sb.field("optional_field", value);
}

let s = sb.build();
```

With `_if_some()`, this can be written like this:

```rust
let opt_value = ...;
let s = gst::Structure::builder("test")
    .field("mandatory_field", "mandatory")
    .field_if_some("optional_field", opt_value)
    .build();
```

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1424>
2024-04-17 17:15:39 +02:00
Sebastian Dröge 0d872ae6f8 ci: Update to Rust 1.77.2
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1422>
2024-04-10 09:00:24 +03:00
Sebastian Dröge 7433ea79c9 ci: Update image version to get a working libvpx on Windows 2024-04-09 12:19:14 +03:00
Sebastian Dröge 46be4a0b1e examples: Use safe RTSPMediaFactory role API
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1421>
2024-04-09 06:27:14 +00:00
Sebastian Dröge 43c82da25a rtsp-server: Add builder API for RTSPToken for consistency with Structure
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1421>
2024-04-09 06:27:14 +00:00
Sebastian Dröge da1f53f4c7 ci: tag linter and sanity check jobs as a "placeholder" jobs
They hardly use any resources and almost finish immediately.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1420>
2024-04-09 09:09:51 +03:00
Sebastian Dröge 0524435190 Update CHANGELOG.md for 0.22.4 2024-04-08 16:11:10 +03:00
Sebastian Dröge 917c458a86 ci: Rebuild image to get the flac plugin included on Windows too
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1418>
2024-04-08 08:58:28 +03:00
Sebastian Dröge 5eaa0ca46d Update Cargo.lock
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1418>
2024-04-08 08:58:10 +03:00
Jordan Petridis 5400979e28 ci: Pin typos-cli to 1.19.0
New version includes false positives

https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1417#note_2358711

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1417>
2024-04-05 12:02:47 +03:00
Jordan Petridis c43c08804a typos.toml: Ignore anc and sys/tests
The tests are autogenerated

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1417>
2024-04-05 11:59:08 +03:00
Jordan Petridis a7ebe45ff3 ci: Add libflac in the debian image
So we can build flac elements.

Related: https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1401
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1417>
2024-04-04 15:37:42 +03:00
Sebastian Dröge 2b53c55ee6 ci: Update to Rust 1.77.1
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1416>
2024-03-29 09:52:23 +02:00
Sebastian Dröge 04c840a1d9 mpegts: Always re-export the contents of the auto module
Pre-1.20 it currently has nothing to re-export and would cause clippy
warnings, but like this it won't be forgotten to update the conditions
if new API is added that is available from older versions.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1414>
2024-03-24 11:21:45 +02:00
Piotr Brzeziński 6111663e26 audio: Implement From/ToValue in Audio/VideoConverterConfig
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1408>
2024-03-22 17:16:48 +00:00
Piotr Brzeziński 7cea7ba6f1 examples: Add audiomixer example with mixing 4 stereo tracks into 8ch output
Will be useful to show how to create and set the mix-matrix via our bindings.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1408>
2024-03-22 17:16:48 +00:00
Philippe Normand e2e38d9494 Fix build warnings after update to Rust 1.77
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1413>
2024-03-21 15:44:46 +00:00
Philippe Normand 676e41064b Update Cargo.lock
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1413>
2024-03-21 13:41:23 +00:00
Philippe Normand 4524af89ee ci: Update to Rust 1.77
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1413>
2024-03-21 13:40:49 +00:00
Philippe Normand e5830c2ea9 ci: Update to dav1d >= 1.3.0
This is going to be needed for:
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1507

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1413>
2024-03-21 13:40:29 +00:00
Sebastian Dröge d7fe0709a5 ci: Rebuild image to get fixes for the Windows gst-plugins-rs CI
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1412>
2024-03-20 10:49:09 +02:00
Sebastian Dröge 983e8b3308 Update CHANGELOG.md for 0.22.3 2024-03-19 18:13:28 +02:00
Olivier Crête 6aff1773bd video_meta: Rename transformation to scale
This transformation is really only for scaling for now, so let's
make it clearer in the bindings.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1397>
2024-03-19 14:44:57 +00:00
Sebastian Dröge ebc06257b5 ci: Rebuild image to pull in the GES fixes
And follow the 1.24 branch of GStreamer for now.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1410>
2024-03-19 09:57:38 +02:00
Sebastian Dröge 86d02890ca Regenerate with latest gir / gir files
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1410>
2024-03-19 09:57:38 +02:00
Sebastian Dröge 29c82cd54d Update GStreamer gir files
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1410>
2024-03-19 09:57:38 +02:00
Michiel Westerbeek c05563d22e ges: framepositioner: Make positioning properties doubles
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1410>
2024-03-19 09:57:37 +02:00
Sebastian Dröge 9e80250b49 Use 0.19 branches of gir / gir-files
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1410>
2024-03-19 09:57:37 +02:00
Sebastian Dröge 0b027c853b Update Cargo.lock
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1410>
2024-03-19 09:57:37 +02:00
Olivier Crête 3246f4fb5b analytics: Allow empty object type
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1407>
2024-03-13 13:52:37 +00:00
François Laignel 82f6accc31 webrtc: SessionDescription: access the inner SDPMessage as & or &mut
`WebRTCSessionDescription` owns its `SDPMessage`. The `sdp()` accessor used to
return a copy of the `SDPMessage` which prevented the user from getting a ref
and by extension from getting a mutable ref for in-place modification.

This commit makes the accessor return a reference to the inner `SDPMessage` and
adds a mutable accessor.

Previous behaviour (getting an owned copy of the `SDPMessage`) is available by
calling `to_owned()` on the reference returned by `sdp()`.

Users who wish to change the type of `WebRTCSessionDescription` can call
`set_type()`.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1406>
2024-03-11 13:03:26 +01:00
François Laignel ffad1188b9 net: fix faillible PtpClock::new()
`PtpClock::new()` can fail in which case it panicked due to an assertion
failure. This commit makes it return a `Result` instead.

Also sets the `name` argument optional, similar to what is done for `NtpClock`.

See also: https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/6251

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1405>
2024-03-01 17:39:39 +01:00
Dave Patrick Caberto 353e3d1611 fraction: refer to numer and denom more consistently
This also lessens the tendency to confuse num with number.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1404>
2024-03-01 18:30:19 +08:00
Dave Patrick Caberto b5cb4ae831 fraction: add const new_raw and from_integer methods
These are direct counterparts to their respective Rational32 constructors.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1404>
2024-03-01 18:28:39 +08:00
Sebastian Dröge 14576fdf26 Update Cargo.lock
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1403>
2024-02-29 11:32:12 +02:00
Sebastian Dröge 70045a36fb examples: Update to windows 0.54
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1403>
2024-02-29 11:31:26 +02:00
Sebastian Dröge 28451435a4 Update CHANGELOG.md for 0.22.2 2024-02-26 14:50:48 +02:00
Sebastian Dröge fcc7ab6b88 Update CHANGELOG.md for 0.22.1 2024-02-26 14:08:30 +02:00
Sebastian Dröge 18a02f6d34 gstreamer: Update serde flags tests for new ObjectFlags
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1401>
2024-02-26 11:29:19 +00:00
Sebastian Dröge c5111ddcc2 Update Cargo.lock
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1401>
2024-02-26 11:29:19 +00:00
Sebastian Dröge d5917be045 Regenerate with latest GStreamer gir files
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1401>
2024-02-26 11:29:19 +00:00
Sebastian Dröge 4e6ddf6663 rtp: Add bindings for new RTPBaseDepayload::extensions() property
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1401>
2024-02-26 11:29:19 +00:00
Sebastian Dröge ab0a29b765 Update GStreamer gir files
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1401>
2024-02-26 11:29:19 +00:00
Guillaume Desmottes 8062a8748f ci: rebuild images to update GStreamer
Pick GStreamer 1.23.90 as it requires to build the new uriplaylistbin
version, see https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1471

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1400>
2024-02-26 09:09:00 +01:00
Sebastian Dröge 28fe70f479 rtpheaderextension: Don't pass a mutable output buffer reference to write()
The extension is only supposed to use it for potentially reading metas
from it, and `GstRTPBasePay` is currently passing the same buffer as the
one that owns the data so we currently end up with the possibility to
e.g. resize the buffer which would invalidate the data.

This change prevents at least the biggest problems, but would still
allow getting an immutable and mutable reference to the same data with a
bit of effort.

See also https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/issues/375

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1399>
2024-02-22 12:17:13 +02:00
Sebastian Dröge c8b98dde8c gstreamer: bus: Handle all previously queued messages too in the BusStream
Before the stream was created, some messages might've been queued on the
bus. For more similar behaviour with the bus watch, first pop all the
queued messages before handling new messages.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1398>
2024-02-21 12:09:14 +02:00
Olivier Crête b47aba1837 video_meta: Add a safe wrapper for the VIDEO_TRANSFORM of metas
With a test

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1388>
2024-02-16 14:28:26 -05:00
Olivier Crête 28931e2f09 meta: Make a generic transform method with a specific trait for each transform
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1388>
2024-02-16 14:28:26 -05:00
Sebastian Dröge 1649e268c5 rtp: Add gst::Object as parent class to the various types
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1396>
2024-02-16 19:49:16 +02:00
Sebastian Dröge d575cd1f95 Update Cargo.lock
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1395>
2024-02-16 14:24:32 +02:00
Sebastian Dröge ac275fe10e Remove Cargo.lock from .gitignore
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1395>
2024-02-16 14:24:32 +02:00
Olivier Crête b10f395c2c meta: Add modules containing the tags
Export the tags as both quark or string

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1387>
2024-02-16 08:59:36 +00:00
Benjamin Gaignard 22796cee0c meta: Add is_registered function for CustomMeta
Test if a Meta type is already registered.
It is useful to know if a custom metadata type has already
been registed to avoid registererd twice and get asserts.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1391>
2024-02-13 08:21:38 +00:00
Sebastian Dröge 7f9dd58718 video: Add AncillaryMeta bindings
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1393>
2024-02-12 16:54:19 +02:00
Sebastian Dröge 798ee29b98 structure: Call _full() serialize function for GST_SERIALIZE_FLAG_STRICT
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1393>
2024-02-12 16:10:24 +02:00
Sebastian Dröge 040a194700 tags: Add new ContainerSpecificTrackId tag
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1393>
2024-02-12 16:09:28 +02:00
Sebastian Dröge b69fee9abe Regenerate with new GStreamer gir files
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1393>
2024-02-12 16:06:44 +02:00
Sebastian Dröge a87a844604 ci: Rebuild image to get new GStreamer version
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1393>
2024-02-12 16:05:41 +02:00
Sebastian Dröge 5d19b26974 Update GStreamer gir files
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1393>
2024-02-12 16:05:14 +02:00
Benjamin Gaignard 2613c57739 analytics: Make AnalyticsODLocation members public
Get access to AnalyticsODLocation structure members outside
the module is useful if other elements need them.
For example it can be used to draw objects location.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1389>
2024-02-09 15:35:32 +00:00
Sebastian Dröge f82b9cc197 meta: Add support for 1.24 Meta clear function
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1390>
2024-02-09 10:25:32 +02:00
Sebastian Dröge 12c9ada9e0 meta: Fix MetaRefMut::upcast_mut() to return a mutable reference
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1390>
2024-02-09 10:24:40 +02:00
Sebastian Dröge a784ea2d0b ci: Update to Rust 1.76
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1386>
2024-02-08 17:46:08 +02:00
Sebastian Dröge 90e6108ed7 gstreamer-tag: Reduce number of keywords 2024-02-08 15:37:44 +02:00
Sebastian Dröge 77b2800caf Publish docs for 0.22 release 2024-02-08 15:24:21 +02:00
Sebastian Dröge c4636fc0cd Update Cargo.lock 2024-02-08 15:01:11 +02:00
Sebastian Dröge 6a1441203d Update versions to 0.23.0 2024-02-08 14:47:20 +02:00
Sebastian Dröge 811e564ff9 examples: Move some more gtk-rs-core dependencies to the workspace 2024-02-08 14:39:58 +02:00
Sebastian Dröge 0eacca7102 Use workspace features for crates metadata in remaining crates 2024-02-08 14:30:43 +02:00
Sebastian Dröge aab36d9745 Update CHANGELOG.md for 0.22.0 2024-02-08 14:27:28 +02:00
Sebastian Dröge d96dbef08c ci: Update image version
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1358>
2024-02-07 18:26:46 +02:00
Olivier Crête 7ec3c8713a analytics: Add bindings for apps/plugins
The whole API to use the Analytics meta is implemented.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1358>
2024-02-07 12:21:54 +02:00
Sebastian Dröge 36792404a9 ci: Don't install cargo-c with --locked on nightly for now
Otherwise a version of ahash is used that doesn't build on nightly anymore.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1385>
2024-02-06 10:39:23 +02:00
Sebastian Dröge ebc18ea0b8 deny: Add override for duplicated toml_edit dependency
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1385>
2024-02-06 10:29:12 +02:00
Sebastian Dröge 9cf270611f Update Cargo.lock
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1385>
2024-02-06 10:28:23 +02:00
Sebastian Dröge 79846af1e6 ci: Rebuild image to update GStreamer
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1385>
2024-02-06 09:55:43 +02:00
Sebastian Dröge 90bb9182c2 Regenerate with latest gir / gir-files
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1385>
2024-02-06 09:55:42 +02:00
Sebastian Dröge a3b3017d75 gstreamer: Re-export / manually implement new standalone functions
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1385>
2024-02-06 09:55:42 +02:00
Sebastian Dröge e16832a2a8 gstreamer: Update configuration for new standalone functions
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1385>
2024-02-06 09:52:57 +02:00
Sebastian Dröge a165f1aa96 Update gir files
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1385>
2024-02-06 09:45:02 +02:00
Sebastian Dröge e192eac554 Update gir
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1385>
2024-02-06 09:44:51 +02:00
Sebastian Dröge a31940a916 Update GStreamer gir files
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1385>
2024-02-06 09:44:16 +02:00
Martin Robinson 230c906626 Make use of feature(doc_cfg) conditional on docsrs consistently
`feature(doc_cfg)` is turned on conditionally if `docsrs` is true in
most of the source code, but in some cases this isn't the case. This
change makes that consistent everywhere, fixing the doc build on stable
Rust.

Fixes #506.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1381>
2024-02-05 10:57:59 +00:00
Sebastian Dröge fde0c061c2 Switch git dependencies to explicitly name branch
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1384>
2024-02-05 12:29:46 +02:00
Sebastian Dröge a51b5bdfd3 Fix a new clippy warning
warning: this bound is already specified as the supertrait of `FusedStream`
   --> gstreamer/src/bus.rs:314:15
    |
314 |     ) -> impl Stream<Item = Message> + Unpin + FusedStream + Send + 'a {
    |               ^^^^^^^^^^^^^^^^^^^^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#implied_bounds_in_impls
    = note: `#[warn(clippy::implied_bounds_in_impls)]` on by default
help: try removing this bound
    |
314 -     ) -> impl Stream<Item = Message> + Unpin + FusedStream + Send + 'a {
314 +     ) -> impl Unpin + FusedStream<Item = Message> + Send + 'a {
    |

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1383>
2024-02-05 12:07:15 +02:00
Sebastian Dröge 8230a7ccba Update Cargo.lock
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1383>
2024-02-05 12:04:39 +02:00
Bilal Elmoussaoui 2dff5b8ae2 Use workspace features for common deps
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1382>
2024-02-03 10:48:37 +01:00
Bilal Elmoussaoui 14ffbfbe83 Use workspace features for crates metadata
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1382>
2024-02-03 10:48:37 +01:00
Bilal Elmoussaoui 771dbb4ed5 webrtc: Add missing gst dependency
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1382>
2024-02-03 10:48:37 +01:00
Bilal Elmoussaoui aaea288abf Adapt to no longer re-exported traits
Some of the traits were moved to prelude or translate
and no longer in the main scope of the crate

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1382>
2024-02-03 10:48:37 +01:00
Bilal Elmoussaoui cfc1aed3c3 Adapt to renamed ffi crates
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1382>
2024-02-03 08:56:45 +01:00
Bilal Elmoussaoui ba91648bd5 Regenerate with latest gir
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1382>
2024-02-03 08:48:44 +01:00
Bilal Elmoussaoui 95c00c4a5c Update gir submodule
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1382>
2024-02-03 08:47:01 +01:00
Sebastian Dröge 193bcbf055 Switch from once_cell to std::sync::OnceLock where it makes sense
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1379>
2024-01-31 14:59:54 +02:00
Sebastian Dröge ce5dca918d examples: Update to termion 3
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1379>
2024-01-31 14:48:32 +02:00
Sebastian Dröge e6ce8e4f71 deny: Remove unnecessary overrides
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1379>
2024-01-31 14:48:32 +02:00
Sebastian Dröge a83680ffeb Update Cargo.lock
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1379>
2024-01-31 14:48:32 +02:00
Olivier Crête e13e9a7a7f Regenerate with updated generator
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1380>
2024-01-29 18:30:49 -05:00
Piotr Brzeziński 446bb7ec3e examples/tutorials: fix macOS run() wrapper terminating too early
Using terminate() kills the whole process instead of just stopping the event loop, so we're back to the 'old' way.
However, if the provided function finishes too early, that can also fail (will call stop() on a not-yet-running NSApp).
Creating a delegate and waiting for the callback makes sure NSApp is running before the actual main() is called.

Also, for whatever reason only tutorials were changed to use terminate(). Now both tutorials and examples are
using identical code.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1378>
2024-01-29 14:15:19 +00:00
Piotr Brzeziński 047f4a3f75 gstreamer: add gst_macos_main()
Unlike the C version, this allows for any arbitrary type of return value.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1377>
2024-01-29 13:55:16 +01:00
Sebastian Dröge c376bfac4d rtp: Add RTPSourceMeta bindings
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1376>
2024-01-15 19:04:09 +02:00
Jonas K Danielsson 6cea21617c gstreamer-video: Add VideoSeiUserDataUnregisteredMeta
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1375>
2024-01-08 13:11:55 +02:00
Sebastian Dröge c5357064cf ci: Update to Rust 1.75
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1371>
2024-01-07 11:17:47 +02:00
Sebastian Dröge b5c7c402b9 Add MiniObject::from_glib_ptr_borrow()
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1374>
2024-01-05 22:29:43 +02:00
Sebastian Dröge e35782a3a4 Add accessor for owned Buffer to read-mapped AudioBuffer / MappedBuffer
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1374>
2024-01-05 22:29:37 +02:00
Sebastian Dröge 92064a0c41 Remove &mut BufferRef getter from write-mapped AudioBuffer / VideoFrame
This allows invalidating the buffer map.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1374>
2024-01-05 22:27:07 +02:00
Sebastian Dröge c66fc90566 Add accessors for various base class fields
And fix some other existing accessors to use the correct mutex.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1373>
2024-01-05 15:56:19 +02:00
Sebastian Dröge 0b4c602c6f Provide a more convenient function for setting other fields on message/event builders
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1372>
2023-12-31 15:53:10 +02:00
Sebastian Dröge 3b3c3baee5 Fix / work around a few new clippy 1.75 warnings
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1370>
2023-12-22 16:33:41 +02:00
Sebastian Dröge 5fe76aa785 Update Cargo.lock
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1369>
2023-12-22 15:10:36 +02:00
Sebastian Dröge 5f01bcf8f4 buffer: Fix range end calculations
And add various tests to cover for this.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1369>
2023-12-22 15:09:31 +02:00
olivierbabasse 60e8c44abb rtsp server: allow custom authentication
Enables subclassing gst_rtsp_server::RTSPAuth and overriding its
authenticate/check/generate_authenticate_header methods

Also add new methods in RTSPContext to retrieve RTSP request/response, and to
get/replace tokens.

Additionally, added RTSPMessage with methods to add an authentication
header to a request / retrieve authentication parameters from a
response.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1359>
2023-12-22 12:12:17 +02:00
Sebastian Dröge 08fa853c7e ci: Update image version again
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1368>
2023-12-21 14:10:41 +02:00
Nirbheek Chauhan 52c764b986 ci: Fix pwsh scripts not exiting on error
We all know that external utilities returning a non-zero exit code do
not terminate a powershell script. However, most do not know (and
neither did I) that it is impossible to promote error exit codes to
script-terminating errors with ErrorActionPreference.

Explicitly check the return codes and Exit.

https://github.com/MicrosoftDocs/PowerShell-Docs/issues/1583

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1368>
2023-12-21 14:10:41 +02:00
Sebastian Dröge b5f4246445 ci: Use cargo install --locked to make sure to not use too new dependency versions
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1368>
2023-12-21 14:10:41 +02:00
Sebastian Dröge ea002e2e11 ci: Update to Rust 1.74.1
And rebuild image for newer GStreamer version.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1368>
2023-12-21 14:10:41 +02:00
Sebastian Dröge dae3d30fae play: Add bindings for new pipeline-dump-in-error-details config
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1368>
2023-12-21 14:10:41 +02:00
Sebastian Dröge 52bd716a80 meta: Add support for (de)serializing metas
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1368>
2023-12-21 13:47:11 +02:00
Sebastian Dröge 26611a66bd Regenerate with latest GStreamer gir files
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1368>
2023-12-21 13:47:11 +02:00
Sebastian Dröge 003ebbdf1c structure: Manually bind GST_SERIALIZE_FLAG_STRICT
As the flag changes the nullability of `gst_structure_serialize()` and
adding a new C function is apparently too much of a hassle for C
developers, add a new `serialize_strict()` function here that always
sets this flag and can fail.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1368>
2023-12-21 13:47:11 +02:00
Sebastian Dröge 0533160d94 rtp: Add support for new RTPBasePayload::extensions property
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1368>
2023-12-21 13:47:11 +02:00
Sebastian Dröge dff595193d Update GStreamer gir files
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1368>
2023-12-21 13:47:11 +02:00
Sebastian Dröge 86cf7a7d81 audio: Add array-based accessor for all audio buffer planes' data at once
This is mostly useful for getting mutable access to all planes at once.

Using `plane_data_mut()` for this is not possible as it would require
borrowing the frame mutably multiple times.

As each plane's data is not overlapping with any other plane we can
still provide such functionality safely.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1367>
2023-12-19 10:29:01 +02:00
Sebastian Dröge 38a9b7a242 video: Add array-based accessor for all video frame planes' data at once
This is mostly useful for getting mutable access to all planes at once.

Using `plane_data_mut()` for this is not possible as it would require
borrowing the frame mutably multiple times.

As each plane's data is not overlapping with any other plane we can
still provide such functionality safely.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1367>
2023-12-19 10:14:23 +02:00
Sebastian Dröge 2fb93e1c12 Update CHANGELOG.md for 0.21.3 2023-12-18 11:07:55 +02:00
Sebastian Dröge 8b9862052b gstreamer: memory: Simplify and correct offset/size calculations in mem_share()
This is all supposed to do unsigned wrapping arithmetic to calculate the
new offsets and sizes, despite input parameters being signed integers.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1363>
2023-12-17 13:15:55 +02:00
Sebastian Dröge 5c88bd0b5f gstreamer: memory: Use ranges instead of offset/size parameter pairs
Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/issues/497

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1363>
2023-12-17 13:15:38 +02:00
Sebastian Dröge 96de51a7b7 gstreamer: buffer: Use ranges instead of offset/length parameter pairs
Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/issues/497

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1363>
2023-12-17 11:41:01 +02:00
Sebastian Dröge cd30854c2b gstreamer: memory: Fix assertions for copy_range/resize/share functions
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1363>
2023-12-17 11:37:58 +02:00
Sebastian Dröge 33e3e25b49 gstreamer: buffer: Add bindings for Buffer::map_range_readable() and _writable()
Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/issues/496

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1363>
2023-12-17 11:37:56 +02:00
Olivier Crête 248b6d2f31 gstreamer: meta: Implement Clone trait on MetaRef
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1365>
2023-12-13 18:05:27 -05:00
Sebastian Dröge 2139f368e9 gstreamer: buffer: Add Buffer::dump() and Buffer::dump_range()
Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/issues/495

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1362>
2023-12-11 18:34:13 +02:00
Sebastian Dröge e72a3bfc8d gstreamer: Improve support for dumping memories and add same functionality to byte slices
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1362>
2023-12-11 16:05:34 +00:00
Sebastian Dröge 34fee6b691 gstreamer: formatted values: Implement ClockTime::absdiff() and on related types
Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/issues/494

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1364>
2023-12-10 20:49:17 +02:00
Sebastian Dröge fddeacc358 Update Cargo.lock
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1361>
2023-12-09 12:14:28 +02:00
Sebastian Dröge 5d8652e872 Update to pretty-hex 0.4
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1361>
2023-12-09 12:13:42 +02:00
Sebastian Dröge 3daab0112d examples: Add a few more docs/comments to the subclass/virtual methods example
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1360>
2023-12-09 11:58:14 +02:00
Sebastian Dröge 0ec7b2608c examples: Add an example that shows how to write subclasses with virtual methods
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1356>
2023-12-05 11:20:24 +02:00
Sebastian Dröge 84ca72a833 gstreamer: audiofilter: Add parent_allowed_caps()
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1356>
2023-12-05 11:20:24 +02:00
Sebastian Dröge ceed45cfd7 gstreamer: Optimize Buffer / Memory from_slice() to have fewer allocations
Instead of using `gst_memory_new_wrapped_full()` and boxing the data,
create an GstAllocator subclass that allows allocating memories that
store the data inline.

By avoiding the box, one additional heap allocation per memory is
avoided.

Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/issues/498

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1357>
2023-12-05 10:51:28 +02:00
Guillaume Desmottes a29d7c0e19 gstreamer: rename util_get_timestamp() to get_timestamp()
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1355>
2023-12-04 17:07:21 +01:00
Guillaume Desmottes f055c113ac streamer: do not publicly import functions
All the functions are re-exported in the root crate.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1355>
2023-12-04 16:15:51 +01:00
Guillaume Desmottes 9bcf48050b gstreamer: move update_registry() as Registry method
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1355>
2023-12-04 16:15:51 +01:00
Guillaume Desmottes a649e7dead gstreamer: move parse_* functions to their own module
Better namespacing so the API is more Rust-y.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1355>
2023-12-04 16:15:51 +01:00
Guillaume Desmottes f255b82b55 gstreamer: move debug_* functions to their own module
Better namespacing so the API is more Rust-y.

Fix #500

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1355>
2023-12-04 12:46:59 +01:00
Dave Patrick Caberto 7f234c88ac pbutils: make element_properties mod public
This makes the builders accessible/nameable.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1354>
2023-11-29 19:32:44 +08:00
Sebastian Dröge 59420b1590 Regenerate with latest gir
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1353>
2023-11-29 11:59:03 +02:00
Sebastian Dröge a05e3fed14 Update gir
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1353>
2023-11-29 11:58:35 +02:00
Sebastian Dröge ca8309a5dd Simplify various raw pointer casts everywhere
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1353>
2023-11-29 11:24:47 +02:00
Sebastian Dröge 897c7dfd39 gstreamer: Remove deprecated APIs
They were deprecated in the previous release or even older releases.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1352>
2023-11-23 13:38:16 +02:00
Sebastian Dröge c82ba6ffe0 Update Cargo.lock
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1351>
2023-11-17 10:58:50 +02:00
Sebastian Dröge e56061c25e examples: Update to windows 0.52
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1351>
2023-11-17 10:58:40 +02:00
Sebastian Dröge 4c3de8b80e Update versions of all autogenerated files
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1348>
2023-11-16 20:53:08 +02:00
Sebastian Dröge db2028c4c5 net: Add new PtpClock::init_full() function
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1348>
2023-11-16 20:53:08 +02:00
Philippe Normand 9ab8dee59c gstreamer-editing-services: Add bindings for FrameCompositionMeta
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1348>
2023-11-16 20:53:08 +02:00
Philippe Normand 6371b82c48 gst-gir-files: Update submodule for GES FrameCompositionMeta
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1348>
2023-11-16 19:47:58 +02:00
Bilal Elmoussaoui 9617731206 ci/docs: Add missing cfg docsrs
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1350>
2023-11-16 17:29:36 +00:00
Sebastian Dröge 53f1ab938e ci: Update to Rust 1.74
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1349>
2023-11-16 16:42:08 +02:00
Sebastian Dröge 6cb371d3e5 Update Cargo.lock
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1347>
2023-11-15 17:17:52 +02:00
Sebastian Dröge 1946973c25 Update to itertool 0.12
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1347>
2023-11-15 16:53:20 +02:00
Sebastian Dröge c4413f1db7 examples: play: Set message bus to flushing before dropping the Play reference
Otherwise there might be pending messages on the bus that keep a
reference to the `Play` instance alive, and neither the bus nor the
`Play` are ever going to be freed then.

See also https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/issues/489
and https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/3107.

Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/issues/493

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1346>
2023-11-14 09:36:58 +02:00
Sebastian Dröge 3ac254d34c gstreamer: pad: Remove "caps" property getter
Only only leave the notify signal connection function. The property
getter is the same as `current_caps()`, which is more lightweight.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1345>
2023-11-11 19:21:20 +02:00
Sebastian Dröge 30d8a7893b Update CHANGELOG.md for 0.21.2 2023-11-11 15:57:11 +02:00
Sebastian Dröge 4c6bb9eefa allocators: Ignore init_once() function correctly 2023-11-11 11:43:17 +02:00
Sebastian Dröge 39b472ce8b gl: Update serde serialization tests for new flags/enum variants
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1343>
2023-11-10 17:19:20 +02:00
Sebastian Dröge 9bc2a3dbf5 ci: Update image version for rebuild
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1343>
2023-11-10 16:51:05 +02:00
Sebastian Dröge 9419730ea4 video: Add VIDEO_FORMATS_ANY and iterator over the formats
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1343>
2023-11-10 16:51:05 +02:00
Sebastian Dröge ec3a3610d3 allocator: Generate new ShmAllocator
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1343>
2023-11-10 16:51:05 +02:00
Sebastian Dröge 6403d3c0ee Regenerate with latest gir
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1343>
2023-11-10 16:51:04 +02:00
Sebastian Dröge b8fff2d6fc Update some Gir.toml configuration
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1343>
2023-11-10 16:50:55 +02:00
Sebastian Dröge 7cabb4f22c Update GStreamer gir files
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1343>
2023-11-10 16:50:43 +02:00
Marijn Suijten bf568714b6 examples/glupload: Upgrade to glutin 0.31
Glutin completely detached from `winit` in the `0.30` upgrade, concerning
itself exclusively with OpenGL and WSI APIs around it and leaving any
windowing system interop to the `raw-window-handle` crate specifically
designed for this purpose.

This untanglement massively cleans up and simplifies the `glutin`
codebase, and expands on surfaceless rendering as well as drawing to
simple views (textures) on the screen as is common on Android, without
having control over the entire "window" and event loop.

Some winit boilerplate is however still provided as part of the
`glutin-winit` crate.  Most of the `glutin`+`winit` flow in this
`glupload` example is adopted from `glutin`'s example, following
platform-specific initialization sequences that heavily clutter the code
(only creating a window upfront on Windows, only forcing transparency on
macOS, and trying various fallback attributes to create a context).

At the same time `winit`'s `Event::Resumed` and `Event::Suspended`
event strategy is adopted: this event was previously for Android and
iOS exclusively - where window handles come and go at the merit of
the OS, rather than existing for the lifetime of the application -
but is now emitted on all platforms for consistency.  A `Surface` (via
`RawWindowHandle`) is only available and usable after `Event::Resumed`,
where we can create a GL surface and "current" the context on that
surface for rendering.  This is where the `GstPipeline` will be set
to `Playing` so that data starts flowing.  The inverse should happen in
`Event::Suspended` where the `Surface` has to be given up again after
un-currenting, before giving control back to the OS to free the rest of
the resources.  This will however be implemented when Android is brought
online for these examples.

Finally, now that the `gst-gl-egl` and `gst-gl-x11` features turn on
the relevant features in `glutin` and `winit`, it is now possible to
easily test `x11` on Wayland (over XWayland) without even unsetting
`WAYLAND_DISPLAY`, by simply compiling the whole stack without EGL/
Wayland support (on the previous example `winit` would always default to
a Wayland handle, while `glupload` could only create `GstGLDisplayX11`).

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1336>
2023-11-10 15:47:20 +02:00
Marijn Suijten 73180e530b examples/glupload: Pass actual program handle to glGetProgramiv()
This is what you get with an untyped API.  `glGetError()` further down
the line was returning `GL_INVALID_OPERATION` and failing other calls
after `load()` in the `glutin 0.31` upgrade.  This turns out to be
[returned by `glGetProgramiv`] when the `program` that is passed in
does not refer to a program object.  Which was the case here, where the
fragment shader identifier was passed in instead.

Just in case we insert a few extra asserts that check the result of
`glGetError()` to catch such issues earlier on in the chain, instead of
postponing them and falsely accusing code that runs later.

[returned by `glGetProgramiv`]: https://registry.khronos.org/OpenGL-Refpages/es2.0/xhtml/glGetProgramiv.xml#errors

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1336>
2023-11-10 12:57:16 +01:00
Marijn Suijten 5fdd56747f examples/glupload: Remove Wayland display integration
`GstGLDisplayWayland` calls GstGLDisplayEGL::from_gl_display()` under
the hood (which calls `GstGLDisplayEGL::from_native()`, which calls
`eglGetPlatformDisplay()`) to retrieve the underlying `EGLDisplay`
handle, which thus far seems to be the same value as `glutin`.  However,
newer `glutin 0.31` passes attributes to this function resulting in a
different handle, causing all kinds of trouble further down the line
when sharing resources between `glutin` and `gstreamer-rs` that both
operate on a distinct `EGLDisplay`.

Furthermore `GstGLDisplayEGL` thinks that it uniquely owns the
handle returned by `eglGetPlatformDisplay()` and _does not_ set
`.foreign_display = TRUE` (which `GstGLDisplayEGL::with_egl_display()`
would), causing it to call `eglTerminate()` as soon as the
`GstGLDisplay` is destroyed, leaving `glutin` dysfunctional.

To solve all of this, simply remove this wrongly-behaving class from the
example as it is not suitable for sharing an `EGLDisplay` with `glutin`.

It might however be interesting to create a different example that
showcases how to use raw window handles instead of EGL/GLX handles,
however only Wayland and any platform on EGL like Android, via
`GstGLDisplayEGL::from_native()`, support this.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1336>
2023-11-10 12:57:16 +01:00
Marijn Suijten 0f3d2d6d09 examples/glupload: Sanity-check that the EGL display via Wayland equals glutin
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1336>
2023-11-10 12:53:08 +01:00
Marijn Suijten ce98a4755e examples: Return anyhow::Result out of main()
It is annoying to see only a single line of error when debugging a chain
of (e.g. `anyhow::Context::context()`-created) errors, and have a
zero exit-code while at it.

Instead Rust supports returning a `Result` type straight from main which
is `Debug`- instead of `Display`-printed, so that - in the case of
`anyhow::Error` - all nested (via `.source()`) `Error`s are printed in
backtrace-like form, and the exit code is appropriately non-zero.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1336>
2023-11-10 12:53:08 +01:00
Marijn Suijten 1ec4560b62 gl/egl: Appropriately mark display functions as manual
Two functions were manually implemented but not marked as such, leaving
unneeded "TODO call ffi:xxx" markers in the codebase.  Also improve the
aliases on the manual implementations.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1336>
2023-11-10 12:53:08 +01:00
Marijn Suijten 5741b6a52e gl: Provide raw handle() getter function on GLDisplay
Having access to the raw handle is useful when sharing the display
and context with an existing application.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1336>
2023-11-10 12:53:08 +01:00
Sebastian Dröge 5ee8ee8545 utils: streamproducer: Don't use gst_element_send_event() in another place
It can cause deadlocks thanks to taking the state lock.
2023-11-10 09:45:09 +02:00
Sebastian Dröge 754b6487d4 ci: Run cargo update as part of the cargo deny / cargo outdated jobs 2023-11-10 08:56:32 +02:00
Sebastian Dröge 41519511aa Add Cargo.lock to the repository
This makes sure that any broken dependency updates are not breaking our
build, at the cost of requiring us to update the lock file regularly.

See also https://blog.rust-lang.org/2023/08/29/committing-lockfiles.html

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1340>
2023-11-09 10:07:47 +02:00
Sebastian Dröge 3051401aa4 deny: Add override for duplicated toml_edit dependency
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1340>
2023-11-09 10:03:23 +02:00
Sebastian Dröge 4b3d9f586e element: Add catch_panic_future() helper function for subclasses
This allows wrapping a future in a way that panics are converted to
error messages on the object.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1339>
2023-11-07 10:43:20 +02:00
Sebastian Dröge f471501df5 gstreamer: meta: Add MetaRef::copy() for copying a meta between buffers
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1338>
2023-11-03 11:55:20 +02:00
Sebastian Dröge eb6d3a6c6c gstreamer: meta: Add as_meta_ref() to MetaRefMut
This reduces code duplication between `MetaRef` and `MetaRefMut`.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1338>
2023-11-03 11:49:41 +02:00
Sebastian Dröge 86d470e82c gstreamer: meta: Give returned tags array an arbitrary lifetime
The tags are statically stored.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1338>
2023-11-03 11:48:23 +02:00
Sebastian Dröge e84af103a1 Regenerate with latest gir / gir-files
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1335>
2023-11-02 15:09:20 +02:00
Sebastian Dröge 339bec6aef Update gir / gir-files
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1335>
2023-11-02 15:08:17 +02:00
Fabian Orccon b901322c46 gstreamer: rank: Do not implement gst::Rank as enum
Rank is not limited to known types like GST_RANK_NONE,
GST_RANK_MARGINAL, GST_RANK_SECONDARY and GST_RANK_PRIMARY, but it
can be whatever arbitrary number.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1327>
2023-11-02 13:32:00 +02:00
Sebastian Dröge 4a015d94af Use let-else instead of match for weak reference upgrades
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1333>
2023-10-30 11:00:58 +02:00
Sebastian Dröge fc4a0d29c6 tutorials: Use async-channel instead of the glib MainContext channel
The latter will be removed in favour of using async code in the future,
and async code generally allows for more flexible message handling than the
callback based MainContext channel.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1333>
2023-10-30 11:00:58 +02:00
Marc Wiblishauser 130dc49b22 gstreamer-tag: Introduce gstreamer-tag
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1330>
2023-10-27 13:27:26 +03:00
Sebastian Dröge bd4122e334 gstreamer: error: Allow using variable expansion in loggable_error! macro
Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/issues/490

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1332>
2023-10-26 11:49:58 +00:00
Sebastian Dröge bd9b1d6e38 gstreamer: meta: Move has_tag() and tags() getters to MetaRef
On `MetaAPI` only the static meta API type is known and based on that
it's not possible to work with the tags of a specific meta instance's
API.

As the methods take a `&self` anyway they would be expected to check the
value at hand instead.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1331>
2023-10-26 13:41:50 +03:00
Sebastian Dröge a26fcaf0ad gstreamer: meta: Add upcast_ref() function to go from a specific to a generic meta
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1331>
2023-10-26 13:41:50 +03:00
Sebastian Dröge 16acea71d4 gstreamer: meta: Remove useless API on Meta that can't be called anyway
`Meta` only exists inside a `MetaRef` / `MetaRefMut` and that already
provides exactly the same functions for all meta types.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1331>
2023-10-26 13:41:47 +03:00
Sebastian Dröge d5ba6c1336 gstreamer: meta: Add some more AsRef and AsMut impls
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1331>
2023-10-26 13:38:07 +03:00
Sebastian Dröge 4d19d7b0b6 gstreamer: format: Implement some more conversion traits
Specifically, `From<$formatted_type> for $inner` and
`TryFrom<$formatted_type> for usize` for some types.

Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/issues/492

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1329>
2023-10-25 12:09:45 +03:00
Sebastian Dröge 414019af21 gstreamer: Implement Default trait for AllocationParams
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1328>
2023-10-24 15:04:14 +00:00
François Laignel a41dc25eba video: fix big endian video format order
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1326>
2023-10-22 18:24:39 +02:00
Sebastian Dröge a04ed127af gstreamer: Fix API typo in owned ReferenceTimestampMeta reference getter
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1325>
2023-10-16 15:45:12 +03:00
Sebastian Dröge 5312131069 gstreamer: Simplify MetaAPIExt trait implementation
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1325>
2023-10-16 15:19:52 +03:00
Sebastian Dröge 62f58620b7 gstreamer: Add accessors for PadProbeDatas on PadProbeInfo
And make use of it in examples and other code.

This allows to simplify usage a bit in most cases.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1324>
2023-10-16 11:28:18 +03:00
François Laignel 4c8d16d09e video: fix visibility for VideoVBIEncoder::try_new
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1323>
2023-10-11 17:53:43 +02:00
Sebastian Dröge 547cfb44e2 gstreamer: Simplify Element::element_class() implementation a bit
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1322>
2023-10-11 16:06:20 +03:00
Sebastian Dröge 3f16233a01 gstreamer: Add DeviceProviderClassExt extension trait for class methods
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1322>
2023-10-11 16:06:16 +03:00
Bilal Elmoussaoui 27a0bc5af0 docs/gstreamer: Embed docs for ElementClass functions
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1322>
2023-10-11 12:49:51 +00:00
François Laignel abdd4df415 gst-video: bindings for VideoVBIEncoder & VideoVBIParser
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1319>
2023-10-09 18:21:16 +00:00
François Laignel b158ca83f9 gst-video: generate vertical blanking interval related bindings
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1319>
2023-10-09 18:21:16 +00:00
Sebastian Dröge a2387d1f84 examples: Updates to memmap2 0.9
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1321>
2023-10-06 09:08:29 +03:00
Sebastian Dröge 8df470b85c ci: Update to Rust 1.73
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1320>
2023-10-06 00:15:45 +03:00
Sebastian Dröge b42b01ba86 Update CHANGELOG.md for 0.21.1 2023-10-04 13:30:40 +03:00
Sebastian Dröge 3a5f69b64c gl: Don't autogenerate GL buffer pool configuration functions
These need manual bindings.
2023-10-04 10:22:03 +03:00
Sebastian Dröge a6470f13c9 Fix various new 1.73 clippy warnings
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1317>
2023-10-03 17:44:12 +03:00
Guillaume Desmottes 7bde0285ff gst-utils: prevent dead lock when requesting key unit
Sending the UpstreamForceKeyUnitEvent using gst_element_send_event()
internally takes the state lock. If appsink is pre-rolling we are also
holding the preroll lock.

This may result in a dead lock with the thread doing the state change as
this one takes the state lock and then the pre-roll lock.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1316>
2023-10-03 11:45:51 +02:00
Sebastian Dröge d7494bf1db gst: Add CustomMeta::register_simple()
As a wrapper around the 1.20 `gst_meta_register_custom()` instead of the
new 1.24 convenience function to make it available to more versions.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1310>
2023-10-02 19:50:41 +03:00
Sebastian Dröge fa3ce573d7 app: Add max-bytes and max-time setters to the AppSink builder
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1310>
2023-10-02 19:49:10 +03:00
Sebastian Dröge 44602238d9 Regenerate with latest GStreamer gir files
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1310>
2023-10-02 19:44:35 +03:00
Sebastian Dröge c0696d872d Update GStreamer gir files
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1310>
2023-10-02 19:43:18 +03:00
Sebastian Dröge 635b31614c video: Fix ordering of video formats according to latest libgstvideo
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1310>
2023-10-02 19:39:46 +03:00
Sebastian Dröge 72a5b1bdb9 ci: Update to Rust 1.72.1
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1310>
2023-10-02 19:39:46 +03:00
Anders Hellerup Madsen 3e5316c869 gl: implement Debug for GL video frames
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1312>
2023-10-02 11:33:57 +02:00
Anders Hellerup Madsen f8effdda61 gl: export GLMemory getter methods on GLVideoFrame
also change `as_non_null_ptr()` to `as_raw()`

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1312>
2023-10-02 11:33:57 +02:00
Anders Hellerup Madsen 6eb01dc916 video_frame: refactor traits
this adds an IsVideoFrame trait that makes it easier to provide all the
shared methods between VideoFrame, VideoFrameRef, GLVideoFrame and
GLVideoFrameRef. Now only a single method, `as_non_null_ptr()` has to be
implemented and the rest of the shared methods will be provided by the
`VideoFrameExt` trait.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1312>
2023-10-02 11:33:57 +02:00
Anders Hellerup Madsen 61d559521b gl: add memory access functions to GLVideoFrame
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1312>
2023-10-02 11:33:57 +02:00
Anders Hellerup Madsen e8387bf4cf gl: support for writable GLVideoFrame
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1312>
2023-10-02 11:33:57 +02:00
Anders Hellerup Madsen 4957921cfa gl: reimplement gl video frame support
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1312>
2023-10-02 11:33:57 +02:00
Anders Hellerup Madsen 2a00236a1f video: extract common videoframe methods to trait
In preparation to make a more specialized VideoFrameGL this extracts
common helper functions valid for all VideoFrames into a trait that can
be implemented without too much code duplication.

Note that this is a breaking change, now VideoFrame and VideoFrameRef
cannot really be used without include the gst_video prelude.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1312>
2023-10-02 11:33:54 +02:00
Anders Hellerup Madsen 8e3994f641 gl: wrapper for gst_gl_framebuffer_draw_to_texture
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1314>
2023-09-29 07:07:43 +00:00
Anders Hellerup Madsen c071d8cba7 gl: wrapper for the gst_gl_context_thread_add function
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1313>
2023-09-29 06:55:47 +00:00
Kalev Lember a60cb26c27 Add COPYRIGHT and LICENSE files as links into all gstreamer-gl crates
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1315>
2023-09-28 23:22:12 +02:00
Sebastian Dröge 51075c71f6 examples: Update to memmap2 0.8
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1311>
2023-09-25 13:31:46 +03:00
Arun Raghavan b80a723de8 Minor copy-pasto fix for gstreamer-validate description
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1309>
2023-09-13 08:50:09 -04:00
Sebastian Dröge b93113c4c6 ci: Run cargo-deny on the whole workspace with all features enabled
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1308>
2023-09-07 15:20:43 +03:00
Sebastian Dröge 3988df8463 deny: Update and skip examples / tutorials
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1308>
2023-09-07 15:19:56 +03:00
Sebastian Dröge 7167fb78ce ci: Regenerate images to get new version of cargo-deny
The new version denies dependencies that include binary executables /
libraries.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1308>
2023-09-07 15:19:23 +03:00
Bilal Elmoussaoui 3228c36ef7 Adapt to no longer re-exported auto functions
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1307>
2023-08-29 06:36:38 +00:00
Bilal Elmoussaoui 54979d859d Regenerate with latest gir
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1307>
2023-08-29 06:36:38 +00:00
Bilal Elmoussaoui ba202a5f87 Update gir submodule
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1307>
2023-08-29 06:36:38 +00:00
Sebastian Dröge 0306dd6b53 Regenerate with latest GStreamer gir files
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1306>
2023-08-28 21:45:31 +03:00
Sebastian Dröge 5e32d2efbf Update GStreamer gir files
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1306>
2023-08-28 21:45:31 +03:00
Sebastian Dröge c7662ce15a Update indentation for rustfmt 1.72
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1306>
2023-08-28 21:45:31 +03:00
Sebastian Dröge 4b87796c92 ci: Update to Rust 1.72
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1306>
2023-08-28 21:45:31 +03:00
Sebastian Dröge 83a562e227 Fix/silence various 1.72 clippy warnings
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1306>
2023-08-28 16:50:41 +00:00
Sebastian Dröge f4486f5d61 Drop 0.20 docs to reduce disk usage requirements
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/issues/482
2023-08-22 11:14:11 +03:00
Sebastian Dröge 4976e4ac4b examples: Update to windows 0.51
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1305>
2023-08-16 20:02:24 +09:00
Sebastian Dröge 13835a9f03 examples: Update to uds 0.4
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1305>
2023-08-16 12:35:19 +03:00
Tim-Philipp Müller db16dca822 tutorials: update old gstreamer-sdk media links
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1304>
2023-08-14 11:07:00 +03:00
Sebastian Dröge 277cb517cd Switch to resolver = "2" for the workspace
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1303>
2023-08-09 09:50:00 +03:00
Sebastian Dröge 76b8281709 ci: Build 0.21 docs and drop 0.19 docs 2023-08-08 19:48:54 +03:00
Sebastian Dröge a7be931474 Update versions to 0.22.0 2023-08-08 19:47:55 +03:00
Sebastian Dröge faf03c73ca Update CHANGELOG.md for 0.21.0 2023-08-08 19:47:27 +03:00
Sebastian Dröge 9c6e48119c Use all-features = true instead of all-features = "true" 2023-08-08 17:46:20 +03:00
Sebastian Dröge 7a7b2c7b21 Regenerate with latest gir 2023-08-08 17:45:57 +03:00
Sebastian Dröge af100377ed gir: Update 2023-08-08 17:45:29 +03:00
Sebastian Dröge e95e62d871 Fix build on docs.rs and document all features
Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/issues/478

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1302>
2023-08-08 10:50:12 +03:00
Sebastian Dröge 03417068dc base: Remove last occurence of nowadays unused dox feature
Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/issues/477

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1302>
2023-08-08 10:40:11 +03:00
Guillaume Desmottes 63852b3b19 streamproducer: forward selected sticky events when adding consumers
The consumer pipeline may rely on some sticky events (Tag in my case)
which may have already been sent.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1299>
2023-08-07 20:26:28 +00:00
Sebastian Dröge 783b95884d Regenerate with latest gir / gir-files
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1301>
2023-08-07 11:09:48 +03:00
Sebastian Dröge 03b614372d Update gir-files
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1301>
2023-08-07 11:09:48 +03:00
Sebastian Dröge ab153de47f Update gir
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1301>
2023-08-07 11:09:48 +03:00
Sebastian Dröge bac88e88b8 Update GStreamer gir files
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1301>
2023-08-07 11:09:48 +03:00
Sebastian Dröge 00e42854fa gl: Manually implement swizzle array functions
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1301>
2023-08-07 11:09:48 +03:00
Sebastian Dröge e4d7748241 video: Add some more constants to the ignore list
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1301>
2023-08-07 11:05:39 +03:00
Sebastian Dröge 7a79fc89d6 ci: Update to Rust 1.71.1
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1301>
2023-08-07 09:29:18 +03:00
Sebastian Dröge cdd548acba ci: Update to cargo-c 0.9.22
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1301>
2023-08-07 09:28:56 +03:00
Kourosh Firoozbakht 1e2e57836f examples: fix typo
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1300>
2023-07-26 01:42:02 +00:00
Sebastian Dröge c0f9551fc4 ci: Install GTK from the GStreamer monorepo
Force-build the gtk subproject when building gstreamer

This subproject is only pulled in when -Drs=enabled by gst-plugins-rs,
so we need to force-enable it here.

Co-authored-by: Nirbheek Chauhan <nirbheek@centricular.com>
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1298>
2023-07-19 17:58:37 +05:30
Nirbheek Chauhan 16e1f92489 ci: Use meson --vsenv instead of invoking VsDevCmd.bat
This is simpler, easier to use, and less likely to break.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1298>
2023-07-19 17:58:37 +05:30
Nirbheek Chauhan 0d7555bed0 ci: Switch install_gst powershell script to error by default
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1298>
2023-07-19 17:58:37 +05:30
Sebastian Dröge d96d164c8d ci: Update Windows base docker image
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1298>
2023-07-19 10:53:22 +03:00
Sebastian Dröge f8bb992aaf ci: Don't install pango separately on Windows
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1298>
2023-07-19 10:03:37 +03:00
Sebastian Dröge a53069208b ci: Move extra packages from gst-plugins-rs CI images here
No need to have two layers of CI images for these few additional
packages. It only complicates the whole setup.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1298>
2023-07-19 09:39:25 +03:00
Sebastian Dröge 2abf75122d Update minimum supported Rust version to 1.70
gtk-rs will update soonish too.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1298>
2023-07-19 09:24:10 +03:00
Guillaume Gomez 8fba09e1ed Use --generate-link-to-definition option when generating documentation
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1297>
2023-07-17 18:06:40 +02:00
Guillaume Gomez 75f4c66f14 Add --generate-link-to-definition option when building on docs.rs
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1297>
2023-07-17 18:06:26 +02:00
Sebastian Dröge 92327be3b1 ci: Add various missing dependencies to the Linux image
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1295>
2023-07-17 10:29:20 +03:00
Jordan Petridis 63c79d377f ci: Update ci-templates ref
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1295>
2023-07-14 02:54:43 +03:00
Sebastian Dröge 29ffd10b35 ci: Update to Rust 1.71
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1295>
2023-07-13 17:16:27 +03:00
Sebastian Dröge 8b6c99a84e pbutils: Remove unnecessary mut 2023-07-11 10:05:32 +03:00
Mathieu Duponchelle 88c21505d2 streamproducer: forward preroll sample from new_preroll callback
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1280>
2023-07-07 17:06:54 +02:00
Mathieu Duponchelle a4247d5199 streamproducer: extract process_sample function
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1280>
2023-07-07 14:09:35 +02:00
Sebastian Dröge 214f61abc5 deny: Allow bitflags 1 for the time being 2023-07-07 09:09:58 +03:00
Bilal Elmoussaoui 19cf78d85f Adapt to glib::Continue changing it's module
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1294>
2023-07-06 22:22:43 +02:00
Bilal Elmoussaoui 2fe62d3107 Regenerate with latest gir
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1294>
2023-07-06 22:22:24 +02:00
Bilal Elmoussaoui 387c51f860 Update gir submodule
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1294>
2023-07-06 21:59:16 +02:00
Sebastian Dröge 89ab9d09c8 Remove GTK3 examples/tutorials
GTK3 is deprecated and the GTK videooverlay example does not even work
on modern systems with Wayland anymore.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1293>
2023-07-06 17:25:28 +03:00
Bilal Elmoussaoui f9fa7f55fc Use re-exported once_cell
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1293>
2023-07-06 16:50:35 +03:00
Bilal Elmoussaoui b156ba2c59 Adapt to glib::Continue rename
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1293>
2023-07-06 16:50:35 +03:00
Bilal Elmoussaoui 7cf66dbc61 Adapt to bitflags update
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1293>
2023-07-06 15:17:32 +02:00
Bilal Elmoussaoui 9eacba1569 Use bitflags from re-exported glib crates
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1293>
2023-07-06 15:06:47 +02:00
Bilal Elmoussaoui c2cda2c067 Regenerate with latest gir
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1293>
2023-07-06 15:05:38 +02:00
Bilal Elmoussaoui 4ec5f99142 Update gir submodule
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1293>
2023-07-06 15:04:50 +02:00
Sebastian Dröge 7ac1a2b753 Regenerate with latest gir-files
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1292>
2023-07-06 14:21:45 +03:00
Bilal Elmoussaoui 8cf099f0ab Seal manual traits
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1292>
2023-07-06 14:21:45 +03:00
Bilal Elmoussaoui 6a703508bc Update gir-files submodule
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1292>
2023-07-06 14:08:32 +03:00
Bilal Elmoussaoui 2740c38cdd Regenerate with latest gir
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1292>
2023-07-06 14:08:32 +03:00
Bilal Elmoussaoui 617652dce0 Update gir submodule
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1292>
2023-07-06 14:08:32 +03:00
Sebastian Dröge 80abcf6ca3 Regenerate with latest GStreamer gir files
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1286>
2023-07-06 08:46:06 +03:00
Sebastian Dröge 67b8c29274 video: Add conversions between VideoInfo and VideoInfoDmaDrm
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1286>
2023-07-06 08:46:06 +03:00
Sebastian Dröge bc979b7ce9 audio: Add version to AudioRingBufferFormatType::Dsd
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1286>
2023-07-06 08:40:36 +03:00
Sebastian Dröge 354f072ff3 gstreamer: Add new Fraction::simplify() bindings
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1286>
2023-07-06 08:40:36 +03:00
Sebastian Dröge f806967a2e Update GStreamer gir files
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1286>
2023-07-06 08:40:36 +03:00
Sebastian Dröge c6015043f5 Regenerate with updated gir
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1286>
2023-07-06 08:40:36 +03:00
Sebastian Dröge a913a895c0 Temporarily switch to a gir branch with updated dependencies
Updating to latest gir requires various manual code changes and needs to
be done separately, but this unbreaks the CI for now.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1286>
2023-07-06 08:40:36 +03:00
Sebastian Dröge 90aad36c34 ci: typoes: Fix some typos and add subtiles to the word list
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1286>

fixup
2023-07-06 08:40:30 +03:00
Tim-Philipp Müller 42fe22301b ci: update gstreamer build
Need https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4951
to fix some gst-plugins-rs unit tests.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1286>
2023-07-06 08:08:39 +03:00
Sebastian Dröge 296a12d1ea Update CHANGELOG.md for 0.20.7 2023-07-05 12:29:02 +03:00
Sebastian Dröge 96c7eb9563 basetransform: Don't leak any output buffer if prepare_output_buffer fails
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1285>
2023-06-30 10:33:30 +03:00
Sebastian Dröge eff6b4c952 basetransform: Fix memory leak when dropping buffers from the transform function
Also add a basic test for a basetransform subclass.

Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/issues/472

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1285>
2023-06-30 10:24:55 +03:00
Sebastian Dröge 12bed29738 gstreamer: Move various MetaAPI methods to an extension trait
These don't make sense to implement any different than the default.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1284>
2023-06-30 08:50:03 +03:00
Thibault Saunier af57f6f17b gstreamer: meta Add API to list/check tags
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1284>
2023-06-30 08:43:45 +03:00
Li Yuanheng 1bc197db79 appsink: property should use hyphen not underscore
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1283>
2023-06-28 13:53:38 +08:00
Thibault Saunier a66fc95d2a ges: Mark asset APIs as Send+sync
Those objects are MT. safe

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1278>
2023-06-26 12:37:34 +00:00
Thibault Saunier 7f7c7a4165 ges: Allow subclassing GESFormatter
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1278>
2023-06-26 12:37:34 +00:00
Sebastian Dröge 7c67375d99 examples: Reduce dependencies of the thumbnail example
Instead of depending on libraries for every possible image format,
depend only on the JPEG and PNG libraries.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1281>
2023-06-26 14:14:45 +03:00
Sebastian Dröge b59680f437 Update to cocoa 0.25
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1281>
2023-06-26 14:00:54 +03:00
Sebastian Dröge e2c1dad0d5 Update to itertools 0.11
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1281>
2023-06-26 13:59:47 +03:00
Thibault Saunier 49bf604276 ges: Bind the new object
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1258>
2023-06-16 13:41:33 -04:00
Stéphane Cerveau 750206067c gitlab: add issue template
Use the same bug template as in gstreamer repository

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1277>
2023-06-15 11:37:18 +00:00
Guillaume Desmottes 1df5b0d028 pbutils: implement debug() method on DiscovererInfo related structs
The default Debug implementation is not very useful but unfortunately
cannot be overridden.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1276>
2023-06-14 14:33:59 +02:00
Sebastian Dröge 827cb31bac deny: Remove obsolete duplicated Windows dependencies
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1275>
2023-06-12 13:22:37 +03:00
Sebastian Dröge d72884685a examples: Update to memmap2 0.7
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1275>
2023-06-12 13:22:28 +03:00
Sebastian Dröge df67a2d860 Update CHANGELOG.md for 0.20.6 2023-06-06 17:16:18 +03:00
Sebastian Dröge b89b135c93 pbutils: Move DiscovererStreamInfo iterators to an extension trait
This way it can also be called directly on subclasses.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1273>
2023-06-06 14:09:48 +03:00
Daniel Pendse 2becc79dfb rtsp-server: Add RTSPContext uri getter
Add uri getter from RTSPContext

Fix #469

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1271>
2023-06-05 10:41:59 +02:00
Sebastian Dröge 5f8aaed96b ci: Update to GTK 4.10.3
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1272>
2023-06-01 20:12:51 +03:00
Sebastian Dröge 093bc9b9cc ci: Update to rustup 1.26.0
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1272>
2023-06-01 20:11:05 +03:00
Sebastian Dröge a5fa1dab79 ci: Update to meson 1.1.1
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1272>
2023-06-01 20:10:38 +03:00
Sebastian Dröge f75aa5f1f8 ci: Update to Rust 1.70
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1272>
2023-06-01 20:10:19 +03:00
Sebastian Dröge 130805fc50 Ignore various endianness-dependent constants/enum values in the sys bindings
They can't be used verbatim and need special handling depending on the
target platform's endianness.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1270>
2023-05-29 16:45:29 +03:00
Sebastian Dröge 5f16254059 deny: Update for cocoa crates being in the middle of updates 2023-05-29 12:50:01 +03:00
Sebastian Dröge 2290262c2e gstreamer: Add fmt::Debug impls for owned Event/Query/Message too
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1269>
2023-05-24 10:36:08 +03:00
Guillaume Desmottes fadca54d51 gstreamer: event: manually implement Debug
Allow us to display more useful information.

Fix #467

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1268>
2023-05-23 15:28:29 +02:00
Guillaume Desmottes 53173eb46c gstreamer: query: manually implement Debug
Allow us to display more useful information.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1268>
2023-05-23 15:28:29 +02:00
Guillaume Desmottes 71b77c513d gstreamer: message: add structure to Debug views
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1268>
2023-05-23 15:24:19 +02:00
Guillaume Desmottes 3ffba2453d gstreamer: message: manually implement Debug
Allow us to display more useful information.

Fix #466

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1267>
2023-05-23 10:32:42 +02:00
Guillaume Desmottes 041a1f2a8e gstreamer: message: implement Display on Error, Warning and Info
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1267>
2023-05-23 08:36:13 +02:00
Sebastian Dröge b6919d7c99 examples: Update for DiscovererStreamInfo::stream_id() being nullable
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1266>
2023-05-22 12:17:13 +03:00
Sebastian Dröge a13dcad033 ci: Update image version for building newer GStreamer
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1266>
2023-05-22 12:15:46 +03:00
Sebastian Dröge 6ab34e1656 Regenerate with latest GStreamer gir files
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1266>
2023-05-22 12:15:07 +03:00
Sebastian Dröge 4d7809424f Update GStreamer gir files
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1266>
2023-05-22 12:13:31 +03:00
Jordan Petridis 2f75087830 ci: add openssl into the windows-image
Useful to build a couple of plugins, including dtls.

Related to gstreamer/gst-plugins-rs#346

Originally gstreamer/gstreamer!4607 but can't be merged yet
due to x86 issue.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1264>
2023-05-16 10:50:12 +00:00
Sebastian Dröge adea2428af gstreamer: Only retrieve the debug category once per log call
Each retrieval would go through the one-time-initialization check, i.e.
yet another branch, so let's avoid that.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1263>
2023-05-13 20:44:42 +03:00
Sebastian Dröge 4f8862e15b gstreamer: Remove unnecessary clone() in debug logging macros
The macro called from them is already doing the `clone()` itself.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1263>
2023-05-13 20:44:42 +03:00
Sebastian Dröge 074a2b1578 gstreamer: Use temporary GStr for the debug category constructors
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1263>
2023-05-13 20:44:42 +03:00
Sebastian Dröge 4384934b32 gstreamer: Mark DebugCategory as repr(transparent)
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1263>
2023-05-13 14:06:58 +03:00
François Laignel 9453d63631 gst/pad: [Ghost]PadBuilder: inherit name from template or target when possible
This commit adds convenience auto naming in the following cases:

* When building from a non wildcard-named template, the name of the template is
  automatically assigned to the Pad. User can override with a specific name by
  calling `name()` on the `PadBuilder`.
* When building with a target and no name was provided via the above, the
  GhostPad is named after the target.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1255>
2023-05-12 10:55:46 +00:00
François Laignel 7cb5473ba6 gst: Pad move name definition to builders
Also apply consistent naming for builder/non-builder constructors.

See discussion in:
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/issues/448#note_1799092

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1255>
2023-05-12 10:55:46 +00:00
François Laignel 13f0483a44 gst: Manually impl Bin & Pipeline constructors
Set `Bin` & `Pipeline` constructors to manual implementation to remove
optional `name` argument (use builder to specify name).

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1255>
2023-05-12 10:55:46 +00:00
Sebastian Dröge ccf3b57a8b examples: Update to memmap2
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1262>
2023-05-12 09:44:03 +03:00
Sebastian Dröge 33d4969493 gstreamer: Get function name for logging outside the internal closure
Otherwise the function name will include the name of the closure.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1260>
2023-05-10 11:14:21 +03:00
Jordan Petridis 13f4085456 ci: Build again with --all-features when possible
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1259>
2023-05-08 23:39:31 +03:00
Sebastian Dröge 9d61e39ed2 ci: Pass --all-features to the documentation build
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1257>
2023-05-04 10:02:57 +03:00
Sebastian Dröge 3d82f9cb65 gstreamer-app: appsink: Remove duplicated and misnamed callbacks builder function
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1257>
2023-05-04 10:00:58 +03:00
Sebastian Dröge 3699da7314 Remove dox feature and replace by docsrs configuration
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1256>
2023-05-04 09:19:29 +03:00
Sebastian Dröge 5c331e7e77 ci: Update docs generation for new configuration mechanism
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1256>
2023-05-04 09:19:29 +03:00
Sebastian Dröge 40578ae7e9 Regenerate with latest gir
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1256>
2023-05-04 09:19:29 +03:00
Sebastian Dröge 5a24f2d9db Update gir
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1256>
2023-05-04 09:19:29 +03:00
Sebastian Dröge 0585476687 gstreamer: serde: Update for glib::FlagsClass API changes
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1253>
2023-04-24 09:57:26 +03:00
Sebastian Dröge b1577af7cf Update CHANGELOG.md for 0.20.5 2023-04-22 11:53:29 +03:00
Sebastian Dröge 5dd1decd6a ci: Update to Rust 1.69
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1251>
2023-04-20 18:06:03 +03:00
Sebastian Dröge 86eb6c2bd8 Fix a couple of new Rust 1.69 clippy warnings
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1250>
2023-04-20 16:42:39 +03:00
Thibault Saunier 145664ec0d miniobject: Implement the HasParamSpec trait in the macro
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1249>
2023-04-17 11:00:49 -04:00
Johan Sternerup e026d922e4 gstreamr: bus: Add BusWatchGuard to automatically remove watch
Previously, with add_watch()/add_watch_local() you had to remember
calling remove_watch() in order not to leak the bus, the watch source
and two associated file descriptors. Now these methods instead return an
object of type BusWatchGuard that will automatically remove the bus
watch when the object is dropped.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1248>
2023-04-14 11:53:41 +03:00
Bilal Elmoussaoui 5c156737a4 gst-player: Implement Default for Player
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1231>
2023-04-11 09:42:40 +00:00
Guillaume Desmottes e108a908dc gstreamer: CHANGELOG: fix typo
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1247>
2023-04-10 11:19:00 +02:00
Guillaume Desmottes 98a8b75646 gstreamer: fix unused import in test
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1246>
2023-04-10 08:04:12 +02:00
Guillaume Desmottes 68e0ae9a9c ci: check for typos
https://github.com/crate-ci/typos is quite nice, and is even written in Rust.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1246>
2023-04-07 17:09:48 +02:00
Guillaume Desmottes 6fc969932b CHANGELOG: fix typos
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1246>
2023-04-07 17:09:48 +02:00
Guillaume Desmottes e75391139c fix typos in comments
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1246>
2023-04-07 17:09:48 +02:00
Guillaume Desmottes 3cb2454fd3 gstreamer: fix typo in GeoLocationLongitude tag
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1246>
2023-04-07 17:09:48 +02:00
Sebastian Dröge 341ac517d1 Update CHANGELOG.md for 0.20.4 2023-04-07 13:07:06 +03:00
Sebastian Dröge 2dbd99bd18 webrtc: Add missing prelude re-export of WebRTCICEExtManual 2023-04-07 11:57:01 +03:00
Sebastian Dröge 03d046daba Regenerate with latest GStreamer gir files
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1244>
2023-04-06 21:31:39 +03:00
Sebastian Dröge a11e5cfd75 Add manual changes for the new/changed 1.24 APIs
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1244>
2023-04-06 21:31:39 +03:00
Sebastian Dröge 4d787df819 ci: Run tests with v1_24 feature
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1244>
2023-04-06 21:08:51 +03:00
Sebastian Dröge ca2fd54230 Add v1_24 feature flag everywhere
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1244>
2023-04-06 21:08:51 +03:00
Sebastian Dröge fdbef66c24 Update GStreamer gir files
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1244>
2023-04-06 21:08:51 +03:00
Sebastian Dröge ce0ddc7be0 Regenerate with latest gir
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1244>
2023-04-06 21:08:51 +03:00
Sebastian Dröge 8b0398aa32 Update gir
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1244>
2023-04-06 21:08:51 +03:00
Sebastian Dröge a88b06f73e Update gir files
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1244>
2023-04-06 21:08:51 +03:00
Sebastian Dröge a252de69b1 audio: Don't store a copy of the AudioInfo in AudioFrame
Instead just reference the one inside the FFI struct directly by making
sure that the memory representation of the FFI and Rust type are the
same.

This reduces the size of `AudioFrame` by about half.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1244>
2023-04-06 21:08:51 +03:00
Sebastian Dröge e584fdb17b video: Don't store a copy of the VideoInfo in VideoFrame
Instead just reference the one inside the FFI struct directly by making
sure that the memory representation of the FFI and Rust type are the
same.

This reduces the size of `VideoFrame` by about half.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1244>
2023-04-06 21:08:51 +03:00
Sebastian Dröge ca9d822042 deny: Update for older versions of the windows bindings 2023-04-05 12:03:13 +03:00
Thibault Saunier 98db1b546e validate: Expose gst_validate::print_action_types
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1227>
2023-04-04 11:50:49 -04:00
Thibault Saunier 9647ce8895 validate: reporter: Add a report_action() method
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1227>
2023-04-04 11:50:49 -04:00
Thibault Saunier b34718697c validate: init_debug and setup_test_file is meant to be called before init
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1227>
2023-04-04 11:50:49 -04:00
Thibault Saunier 8eae37c525 validate: Implement action types registration support
This is implemented mostly manually because the API is a bit weird
and we need to do some extra work to make it work properly.
Also basing it on a Builder makes it much nicer to user.

This commit also includes required new types either generated with `gir`
or manually implemented when required.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1227>
2023-04-04 11:50:49 -04:00
Thibault Saunier 68db910bc8 Update gir-files
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1227>
2023-04-04 11:50:49 -04:00
Seungha Yang 6cb19c1f18 examples: Add Direct2D/DirectWrite text rendering example
Similar to overlay-composition example but for Direct2D/DirectWrite

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1206>
2023-04-04 09:09:18 +00:00
Jimmi Holst Christensen 85e427345e Forward tag events to consumers in StreamProducer
Fix #386

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1045>
2023-04-04 07:31:58 +00:00
Sebastian Dröge 0ab72911ee ci: Update to GTK4 4.10.1
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1242>
2023-04-01 18:53:28 +03:00
Sebastian Dröge 954d88154c ci: Update to Rust 1.68.2
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1242>
2023-04-01 13:53:46 +03:00
Sebastian Dröge 81a5f25f81 examples: Update to windows 0.48
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1241>
2023-04-01 12:00:53 +03:00
Sebastian Dröge a7131fc051 examples: Update to windows 0.47
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1240>
2023-03-31 11:50:51 +03:00
Sebastian Dröge bc81e5a6a2 deny: Update to allow multiple versions of syn for now 2023-03-19 17:47:09 +02:00
Sebastian Dröge 6d3c9d931b examples: Update to windows 0.46
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1239>
2023-03-14 11:24:08 +00:00
Sebastian Dröge d2ef4023f7 Update CHANGELOG.md for 0.20.3 2023-03-14 13:23:51 +02:00
Sebastian Dröge 7344e4bab2 tutorials: Update for glib::Priority API changes
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1237>
2023-03-12 10:26:06 +02:00
Arun Raghavan 273f084c06 aggregator: Mark src_pad() return type as an AggregatorPad
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1236>
2023-03-09 23:18:04 -05:00
Jordan Petridis 368e1cacb6 ci: Update base image to debian 12 bookworm
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1234>
2023-03-09 21:03:28 +02:00
Sebastian Dröge fe038b7a14 rtsp-server: Work around GstRTSPClientClass ABI breakage in 1.18
Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/issues/455

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1233>
2023-03-09 16:23:29 +00:00
Sebastian Dröge 43b5cffc85 ci: Update to gtk 4.10.0
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1232>
2023-03-09 17:10:37 +02:00
Sebastian Dröge ce0fab9cf9 ci: Update to meson 1.0.1
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1232>
2023-03-09 17:09:31 +02:00
Sebastian Dröge b243ba1577 ci: Update to Rust 1.68
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1232>
2023-03-09 17:09:26 +02:00
Guillaume Desmottes 01d3cef73e gstreamer: element: more generic (un)link_many() API
No longer enforces to pass an array of references.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1230>
2023-03-09 14:27:25 +00:00
Guillaume Desmottes c4a968a403 gstreamer: bin: more generic {add,remove}_many() API
No longer enforces to pass an array of references.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1230>
2023-03-09 14:27:25 +00:00
Marc Wiblishauser 0bd6e07346 ParamSpecArray: fix type_ from fraction to array
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1229>
2023-03-09 10:29:37 +01:00
Sebastian Dröge 4b112a9bb8 video: Fix two new clippy warnings
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1228>
2023-03-07 10:41:19 +02:00
Sebastian Dröge 37785b222a deny: Allow older windows-sys 0.42 for now 2023-03-01 14:02:48 +02:00
Guillaume Desmottes 32a02b51e1 utils: streamproducer: document forward_eos default value
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1226>
2023-02-28 09:48:36 +01:00
Ruben Gonzalez 0b922b0e89 examples: zoom effect with compositor and navigations events
Use can change the video player zoom using the next keys:

  * +: Zoom in
  * -: Zoom out
  * Up/Down/Right/Left: Move the frame
  * r: reset the zoom

Also mouse navigation events can be used for a better UX.

Furthermore, it works with an pipeline using other video compositor
filters like glvideomixer. For instance:

  glvideomixer \
    name=mix background=1 \
    sink_0::xpos=0 sink_0::ypos=0 sink_0::zorder=0 \
    sink_0::width={WIDTH} sink_0::height={HEIGHT} \
  ! glimagesinkelement \
  gltestsrc pattern=mandelbrot name=src \
  ! video/x-raw(memory:GLMemory),framerate=30/1,width={WIDTH},height={HEIGHT},pixel-aspect-ratio=1/1 \
  ! queue \
  ! mix.sink_0

Probe was added in the sink pad to get direct navigation events w/o
transformation done by the mixer. More info about it in the PR [1].

[1] https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1495

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1217>
2023-02-22 20:41:06 +01:00
Sebastian Dröge 0056c62cec Update CHANGELOG.md for 0.20.2 2023-02-21 17:03:54 +02:00
François Laignel 58475f4a25 {Audio,Video}CapsBuilder: add for_encoding constructor
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1222>
2023-02-20 09:05:51 +00:00
Sebastian Dröge 8b6bf18bb0 ci: Update to rustup 1.25.2
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1223>
2023-02-20 10:42:07 +02:00
Sebastian Dröge b6e253acbf Update minimum supported Rust version to 1.66
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1223>
2023-02-20 10:42:07 +02:00
Sebastian Dröge de01403658 ci: windows: Update to dav1d 1.1.0
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1223>
2023-02-20 10:42:07 +02:00
Sebastian Dröge b3980b389d ci: Build GStreamer from the main branch again
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1223>
2023-02-20 10:42:07 +02:00
SeaDve 862f4d014c gstreamer: Add seconds_f32 & seconds_f64 methods and from_seconds_f32 & from_seconds_f64 constructor for ClockTime and Signed<ClockTime>
Closes #443

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1223>
2023-02-20 10:42:07 +02:00
SeaDve cd8e8cea5a gstreamer-play: impl default for Play
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1224>
2023-02-19 10:28:48 +08:00
SeaDve 12b4a9a03d gstreamer: implement HasParamSpec for ClockTime
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1221>
2023-02-14 23:40:28 +08:00
Sebastian Dröge 70b42a4846 Update CHANGELOG.md for 0.20.1 2023-02-13 15:02:49 +02:00
Sebastian Dröge f0bb4e5bef video: Don't leak the gst::Buffer when converting a VideoFrame into an ffi::GstVideoFrame
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1219>
2023-02-13 14:29:10 +02:00
Sebastian Dröge 6ffb1db482 video: Don't forget to unmap the VideoFrame when converting into a gst::Buffer
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1219>
2023-02-13 14:28:47 +02:00
Sebastian Dröge 2ac85cd8de audio: Don't forget to unmap the AudioBuffer and drop the Box when converting into a gst::Buffer
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1219>
2023-02-13 14:27:10 +02:00
Sebastian Dröge 60ad9b5038 gstreamer: Add a test for various combinations of element_error! string formatting 2023-02-13 11:40:41 +02:00
Sebastian Dröge 6f06a26327 Add support for inline variable names in error/warning/info message creation macros
Simply by removing the special-casing of string literals, which doesn't
really bring any improvements here.

Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/issues/442

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1216>
2023-02-12 13:27:59 +02:00
Sebastian Dröge 7d9c12f8d1 ci: Build 0.20 docs and drop 0.18 docs 2023-02-10 00:16:13 +02:00
Sebastian Dröge 13140d8b8a Update versions to 0.21.0 2023-02-09 23:42:32 +02:00
Sebastian Dröge d284fcdca0 Update CHANGELOG.md for 0.20.0 2023-02-09 23:41:58 +02:00
Sebastian Dröge b9f36c1b42 Update CHANGELOG.md for 0.19.8 2023-02-09 21:38:00 +02:00
Sebastian Dröge f6f0465655 Remove various unnecessary clippy allow attributes
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1214>
2023-02-07 21:13:19 +02:00
Sebastian Dröge 9155d6eb7b Regenerate with latest gir
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1214>
2023-02-07 21:00:46 +02:00
Sebastian Dröge c2dd69dfac Update gir-files
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1214>
2023-02-07 20:59:41 +02:00
Sebastian Dröge 8692caa0a6 Update gir
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1214>
2023-02-07 20:59:31 +02:00
Sebastian Dröge 172e22c4b3 gstreamer: Implement glib::HasParamSpec for our custom pspecs
This allows using `gst::Fraction` / `gst::Array` properties via the new
properties macro.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1213>
2023-02-06 15:21:02 +02:00
Sebastian Dröge 91eec7a33f Migrate everything to object lock API instead of custom GMutex handling
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1212>
2023-02-06 10:50:33 +02:00
Anders Hellerup Madsen 3ddbdbd383 gstreamer-gl: Require object lock in GLDisplay
The methods `gst_gl_display_get_gl_context_for_thread()`,
`gst_gl_display_create_context()`, `gst_gl_display_add_context()` and
`gst_gl_display_remove_context()` now require the display's object lock
to be held when called.

This is required by the C API.

Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/issues/439

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1212>
2023-02-06 10:10:18 +02:00
Anders Hellerup Madsen a021aaa3ce gstreamer: Add object_lock method to gst::Object
See https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/issues/439

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1212>
2023-02-06 10:10:18 +02:00
Christian Meissl 77866a52df gstreamer-allocators: allow to subclass fd memory allocators
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1186>
2023-02-04 19:49:44 +01:00
Sebastian Dröge 00281e98f0 gstreamer: Rename TagSetter::add() to TagSetter::add_tag() to not conflict with Bin::add()
Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/issues/440

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1211>
2023-02-04 16:44:40 +02:00
Jordan Petridis c4dc549a5e ci: Make the plugin update jobs depend on the image builds
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1210>
2023-02-02 14:04:10 +02:00
Sebastian Dröge 478606e44c Use glib::Object::new() instead of new_default()
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1209>
2023-01-31 12:05:53 +02:00
Sebastian Dröge c62530e181 Regenerate with latest gir
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1209>
2023-01-31 10:49:39 +02:00
Sebastian Dröge f1db72dab2 Update gir-files
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1209>
2023-01-31 10:47:04 +02:00
Sebastian Dröge 51611ba779 Update gir
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1209>
2023-01-31 10:46:51 +02:00
Sebastian Dröge a7f670df7a Return exit code from gio::Application::run() from main()
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1208>
2023-01-27 19:02:03 +02:00
Sebastian Dröge 5f05f7ec05 gl: Mark other_context in GLDisplay::create_context() as nullable
Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/issues/438

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1207>
2023-01-27 16:29:49 +02:00
Sebastian Dröge 01bbb07744 ci: Update to Rust 1.67
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1205>
2023-01-26 18:56:35 +02:00
Sebastian Dröge 5cea810820 gstreamer: Add bindings for Message::structure_mut()
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1204>
2023-01-26 15:28:42 +02:00
Sebastian Dröge f24b38470b Fix various new clippy warnings
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1203>
2023-01-25 10:18:33 +02:00
Sebastian Dröge 7efc22ebc9 Require GStreamer 1.22.0 instead of 1.21.0 when selecting v1_22
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1201>
2023-01-24 13:01:05 +02:00
Sebastian Dröge ecfb10649a Add 1.22 to extra_versions
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1201>
2023-01-24 13:00:53 +02:00
Sebastian Dröge 4b99aae824 gstreamer: Create plugins for version 1.22 if selected
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1201>
2023-01-24 12:58:32 +02:00
Sebastian Dröge e82a1d0eb8 gstreamer: Mark MessageType enum as non-exhaustive
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1201>
2023-01-24 12:57:05 +02:00
Sebastian Dröge 8585158880 ci: Update gtk4 to 4.8.3
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1201>
2023-01-24 12:53:50 +02:00
Sebastian Dröge 848ed9c1e5 ci: Update to meson 1.0.0
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1201>
2023-01-24 12:53:06 +02:00
Sebastian Dröge f56febfd35 ci: Rebuild image for 1.22.0
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1201>
2023-01-24 12:52:44 +02:00
Sebastian Dröge 0f1c937465 Regenerate with latest gir files
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1201>
2023-01-24 12:50:26 +02:00
Sebastian Dröge 73a9a5b3a3 Update GStreamer gir files
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1201>
2023-01-24 12:49:36 +02:00
Sebastian Dröge 72d1f72edc Update gir-files
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1201>
2023-01-24 12:49:36 +02:00
Sebastian Dröge c33fb38ca1 gstreamer: Mark various enums as exhaustive
This reduces their size to 4 bytes instead of 5 bytes, and as such makes
it possible to store them in a register on 32 bit platforms too.
Additionally it makes it possible for enums like
`Result<FlowSuccess, FlowReturn>` to be stored in a single register on
64 bit platforms.

Also the conversions between the C and Rust type is a simple copy of the
value now instead of a mapping.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1200>
2023-01-24 11:07:33 +02:00
Sebastian Dröge 2c2a6c3871 Regenerate with latest gir
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1200>
2023-01-24 10:40:31 +02:00
Sebastian Dröge d6bf3e1c3b Update gir
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1200>
2023-01-24 10:39:01 +02:00
Sebastian Dröge 36f89e19fc gstreamer: Deprecate ElementFactory::create_with_properties() and make_with_properties()
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1199>
2023-01-23 13:06:54 +00:00
Sebastian Dröge dc5e408c2d gstreamer: Add various convenience From impls for Caps, BufferList, CapsFeatures, Buffer and VideoOverlayComposition
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1199>
2023-01-23 13:06:54 +00:00
Sebastian Dröge eadb3c6db2 audio: Reduce size of AudioInfo from 832 to 320 bytes and make audio channel position handling more efficient
Assume that there are never more than 64 named channel positions and by
that provide an 1:1 mapping between the C and Rust types.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1198>
2023-01-23 12:58:16 +02:00
Sebastian Dröge 0f859b9029 Get README.md in sync again
Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/issues/437
2023-01-23 12:01:07 +02:00
Seungha Yang 8ef4420257 examples: d3d11videosink: Update for windows crate v0.44
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1197>
2023-01-23 03:01:17 +09:00
Sebastian Dröge d5e24b9fbd Update various object construction functions to more efficient approaches
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1196>
2023-01-22 09:48:51 +02:00
Sebastian Dröge 38dd1f462b gstreamer: Use obj() instead of instance() in the remaining places
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1196>
2023-01-22 09:14:50 +02:00
Sebastian Dröge 257a049673 gstreamer: Mark ParamSpec constructors as deprecated in favour of the builders
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1196>
2023-01-22 09:14:50 +02:00
Sebastian Dröge 24a16a43b6 Update CHANGELOG.md for 0.19.7 2023-01-19 19:05:17 +02:00
Sebastian Dröge d6e9cd33c0 gstreamer: Make allocation query caps optional
See also https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3752

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1194>
2023-01-19 16:08:16 +02:00
Sebastian Dröge 56498aa856 Fix version links in CHANGELOG.md 2023-01-18 16:53:08 +02:00
Sebastian Dröge a6abe15678 Update CHANGELOG.md for 0.19.6 release 2023-01-18 16:53:05 +02:00
Sebastian Dröge 82cf6e7842 Update for glib::Boxed ToGlibPtr<*mut _> trait impl addition
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1192>
2023-01-17 09:59:02 +02:00
Sebastian Dröge c2e7abd128 utils: streamproducer: Persist ConsumptionLink state when changing producers
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1189>
2023-01-16 16:16:15 +02:00
Sebastian Dröge 094d74e391 utils: streamproducer: Add ConsumptionLink::appsrc() getter
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1189>
2023-01-16 14:41:06 +02:00
Sebastian Dröge 0a6ed3c717 utils: streamproducer: Add new ConsumptionLink::disconnected() constructor
This allows constructing a new consumption link from an `appsrc` without
having it connected from the very beginning.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1189>
2023-01-16 14:41:06 +02:00
Sebastian Dröge dd284a80ea utils: streamproducer: Add ConsumptionLink::set_discard() to stop forwarding buffers for a while
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1189>
2023-01-16 14:41:06 +02:00
Sebastian Dröge a68c37e4eb utils: streamproducer: Remove StreamProducer::forward()
Most applications forget to call `forward()` in the beginning and then
nothing works.

Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/issues/433

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1189>
2023-01-16 14:41:06 +02:00
Sebastian Dröge f8d17555c5 utils: streamproducer: Add #[must_use] attribute to add_consumer()
Simply discarding the result will immediately disconnect it again, which
was likely not intended and can easily lead to bugs.

Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/issues/432

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1189>
2023-01-16 14:41:06 +02:00
Sebastian Dröge 8aa3e4417c gstreamer: Fix another typo in macro 2023-01-16 11:30:56 +02:00
Sebastian Dröge 2a11b9d2cf gstreamer: Fix typo in macro 2023-01-16 11:30:08 +02:00
Sebastian Dröge 64abf69987 Use glib::function_name! instead of module_path! macro in more places
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1191>
2023-01-16 11:10:21 +02:00
Sebastian Dröge 3e2eb6e652 gstreamer: Reduce code bloat in panic handling
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1191>
2023-01-16 11:08:02 +02:00
Sebastian Dröge 3a340d0a89 gstreamer: Implement Structure::from_iter() more generically 2023-01-15 23:06:45 +02:00
Sebastian Dröge 003554876c Update various APIs to use glib::GStr
Currently only covers what is needed to keep code compiling, plus
everything caps/structure/tags related.

This avoids unnecessary heap allocations for adding the NUL-terminator
of C strings, and especially makes caps/structure handling as efficient
as in C.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1190>
2023-01-15 21:05:57 +02:00
Sebastian Dröge ea136515cf Regenerate with latest gir
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1190>
2023-01-15 20:17:11 +02:00
Sebastian Dröge 6152dd7e3b Update gir
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1190>
2023-01-15 20:17:10 +02:00
Sebastian Dröge aa23ddbbdb gstreamer: Simplify element subclass panic catching functions
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1188>
2023-01-14 17:13:53 +02:00
Sebastian Dröge 37bfb78fdc Change some assertions to debug assertions
These assertions can only trigger because of bugs in the bindings
implementation or in the C code and not because of bugs in calling code,
so using debug assertions is perfectly fine for them and reduces the
number of assertions inlined everywhere in release builds.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1188>
2023-01-14 17:13:46 +02:00
Sebastian Dröge f235dc987d Inline various trivial functions
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1177>
2023-01-11 11:33:54 +02:00
Sebastian Dröge 0fccb73eb6 gstreamer: Remove unnecessary cast in gst::element_imp_error! and others
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1187>
2023-01-11 09:06:38 +00:00
Sebastian Dröge 608cae3703 gstreamer: Register only a single type instead of per return value for the gst::Iterator::filter() GValue
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1187>
2023-01-11 09:06:38 +00:00
Sebastian Dröge f07727ee6d Use uninitialized stack memory for out parameters instead of zeroed memory if applicable
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1187>
2023-01-11 09:06:38 +00:00
Sebastian Dröge 1b022a6b7c Get rid of unnecessary option wrapping
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1187>
2023-01-11 09:06:38 +00:00
Christian Meissl da2eb50dd3 gstreamer-video: implement VideoBufferPoolConfig for BufferPoolConfigRef
implementing VideoBufferPoolConfig for BufferPoolConfigRef
instead of BufferPoolConfig allows to retrieve the VideoAlignment
from within buffer pool set_config

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1185>
2023-01-08 19:15:46 +01:00
Sebastian Dröge 84720eee66 gstreamer: Use Value::from_type_unchecked() where applicable
Gets rid of some unnecessary assertions.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1184>
2023-01-06 10:41:55 +02:00
Sebastian Dröge 89326c7e7c Compile out GStreamer version checks if a high enough version is configured at build time
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1184>
2023-01-06 10:41:55 +02:00
Sebastian Dröge 277d63601c gstreamer: Return glib::GString for the error/warning/info message debug string
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1184>
2023-01-06 10:41:55 +02:00
Sebastian Dröge ba1d8c5ce6 gstreamer: Move initialization panic into a separate function
This keeps the number of duplicated panics all over the codebase lower
and reduces generated code size.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1184>
2023-01-05 21:33:14 +02:00
Sebastian Dröge 7b279b9d6c gstreamer-app: Assert that GStreamer is initialized before creating instances
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1184>
2023-01-05 21:33:14 +02:00
Sebastian Dröge 8d30bcbf4b Use IntoGlibPtr trait instead of to_glib_full() where appropriate to reduce unnecessary refcounting/copying
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1183>
2023-01-05 12:09:57 +02:00
Sebastian Dröge 5e852fa0ff gstreamer-video: Autogenerate part of the VideoDecoder subframe API
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1183>
2023-01-05 12:09:57 +02:00
Sebastian Dröge 315704fe67 gstreamer-check: Simplify borrowing of sink/src harnesses
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1183>
2023-01-05 12:09:57 +02:00
Sebastian Dröge 1e793f3b65 gstreamer: Return some values by reference instead
Less refcounting.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1183>
2023-01-05 12:09:57 +02:00
Sebastian Dröge 32a608b76b examples: Fix for API changes
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1182>
2023-01-04 13:26:07 +02:00
Sebastian Dröge b94bfe1613 gstreamer: Remove useless GstPluginExtManual trait
`Plugin` is a final type.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1182>
2023-01-04 13:25:17 +02:00
Sebastian Dröge a028e807df gstreamer: Autogenerate some more API
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1182>
2023-01-04 13:25:17 +02:00
Sebastian Dröge 7490846309 Fix compilation due to changes in autogenerated code
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1182>
2023-01-04 13:25:17 +02:00
Sebastian Dröge 567ce0a3bf Group and merge imports in all manual code
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1182>
2023-01-04 13:25:17 +02:00
Sebastian Dröge 45c145ad50 Regenerate with latest gir
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1182>
2023-01-04 13:25:17 +02:00
Sebastian Dröge dce54ee237 Update gir
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1182>
2023-01-04 13:22:39 +02:00
Sebastian Dröge 0e51e70c5a Update GStreamer gir files
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1182>
2023-01-04 13:22:39 +02:00
Sebastian Dröge 6ff5f89832 gstreamer: Fix memory leak in buffer pool subclassing test
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1180>
2023-01-03 10:41:35 +00:00
Sebastian Dröge 0ed3d95c60 gstreamer: Use glib::StrV internally instead of a custom version of it
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1180>
2023-01-03 10:41:35 +00:00
Sebastian Dröge 81bcf5c8dd gstreamer-video: Implement VideoTimeCode via glib::wrapper!
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1180>
2023-01-03 10:41:35 +00:00
Sebastian Dröge 30838b6549 gstreamer-video: Implement VideoTimeCodeInterval via glib::wrapper!
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1180>
2023-01-03 10:41:35 +00:00
Sebastian Dröge cbd3035a5b gstreamer: Implement gst::Segment via glib::wrapper!
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1180>
2023-01-03 10:41:35 +00:00
Sebastian Dröge 8ed150c853 gstreamer: Add missing doc alias
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1180>
2023-01-03 10:41:35 +00:00
Sebastian Dröge ae688406f8 gstreamer: Allocate debug messages up to 256 bytes on the stack and only then spill over into the heap
With this, debug logging from Rust is completely allocation-less for
short messages and string literals.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1179>
2023-01-03 10:28:43 +00:00
Sebastian Dröge 06a0dbacba gstreamer: Don't inline debug logging function
It's relatively big and increases code size and stack usage quite a bit,
and having a function call for logging is not going to make much of a
difference as it happens *after* filtering for the debug level
threshold.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1179>
2023-01-03 10:28:43 +00:00
Sebastian Dröge 036a020b62 gstreamer: Optimize various from/to Vec FFI translation functions
Use memcpys if possible instead of manual loops, and directly write into
the `Vec` memory and set the length afterwards to avoid having the
reallocate logic at every step.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1181>
2023-01-03 12:06:29 +02:00
Sebastian Dröge 882513d33a Make use of the new TransparentType / TransparentPtrType traits
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1178>
2023-01-02 19:07:24 +02:00
Jordan Petridis aeca82c095 ci: Update examples features on windows
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1089>
2022-12-28 14:37:24 +02:00
Seungha Yang b4d3bf297e examples: Add d3d11videosink example with Direct2D/DirectWrite interop
Demonstartes the use of d3d11videosink's present signal
introduced in
https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2923
with Direct2D/DirectWrite API interop using the windows crate.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1089>
2022-12-28 11:20:51 +00:00
Sebastian Dröge e6e5d25e48 Update CHANGELOG.md for 0.19.5 2022-12-27 12:53:30 +02:00
Jordan Petridis e9ecdcdd72 ci/windows: Update base image
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1175>
2022-12-26 16:17:19 +02:00
Sebastian Dröge 3d0f563111 Update minimum supported Rust version to 1.64
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1175>
2022-12-25 14:54:38 +02:00
Jordan Petridis 141a71d69e ci: Avoid building examples with --all-features
--all-features ends up enabling the windows and trying to compile
the d3d example, which can't be built on linux.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1175>
2022-12-25 13:25:30 +02:00
Jordan Petridis dfc6344f59 ci: move tests scripts to individual files
Instead of inling bash scripts in yaml

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1175>
2022-12-25 13:25:30 +02:00
Sebastian Dröge 146b4fc08e gstreamer: Fix glib::GStr API changes 2022-12-25 00:25:42 +02:00
Sebastian Dröge cdc7aa4846 gstreamer: Allow returning Handled from BufferList pad probes
This is handled exactly the same way as buffers.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1174>
2022-12-23 12:21:18 +00:00
Sebastian Dröge dcfea9c35a gl: Reset video frame size/stride/offset to 0 for GL mapped frames
The memory pointers are actually the GL texture IDs, and accessing them
like raw video memory will read random memory areas.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1173>
2022-12-22 19:25:54 +00:00
Sebastian Dröge d6cc452cf3 Use PhantomData as Stash::Storage if nothing has to be stored except for a lifetime
This reduces the size of all stashes from two pointers to one.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1171>
2022-12-20 17:07:39 +00:00
Sebastian Dröge f166e80a79 gstreamer: Only use a single temporary Vec for [T]::to_glib_none() for miniobjects
The value itself is already kept alive via the stash and we only need a
temporary `Vec` to be able to append the terminating `NULL` pointer.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1171>
2022-12-20 17:07:39 +00:00
Sebastian Dröge e70536f6b2 ci: Rebuild CI images another time to get latest GStreamer version
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1169>
2022-12-18 11:50:23 +00:00
Jordan Petridis f7b848b3cd ci/install-{gst,gtk}.sh: run ldconfig after meson install
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1169>
2022-12-18 11:50:23 +00:00
Jordan Petridis cd49019941 ci/install-{gst, gtk}: update meson command usage
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1169>
2022-12-18 11:50:23 +00:00
Jordan Petridis 7ecc11564d ci/install-{gst, rust}.sh: add shebangs to the scripts
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1169>
2022-12-18 11:50:23 +00:00
Jordan Petridis 7b3b4f56ee ci/install-{gst, gtk}.sh: reformat to make it more readable
Split commands and strings to multiple lines

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1169>
2022-12-18 11:50:23 +00:00
Jordan Petridis bed4b8644b ci: Include x264 in the gst build
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1169>
2022-12-18 11:50:23 +00:00
Jordan Petridis 6c7196732e ci: Include gpl plugins when building gst
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1169>
2022-12-18 11:50:23 +00:00
Jordan Petridis 8344cbc829 ci: use a multiline string for FDO_DISTRIBUTION_PACKAGES
Makes it easier to read and change

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1169>
2022-12-18 11:50:23 +00:00
Sebastian Dröge 3764bf75f8 Regenerate with latest GStreamer gir files
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1170>
2022-12-16 22:09:29 +02:00
Sebastian Dröge d7a292ec00 video: Update for NavigationModifierType flags value rename
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1170>
2022-12-16 22:09:29 +02:00
Sebastian Dröge 7113458128 ci: Rebuild the image for getting newer GStreamer
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1170>
2022-12-16 18:47:06 +02:00
Sebastian Dröge 2e2b572215 Update GStreamer gir files
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1170>
2022-12-16 18:46:51 +02:00
Sebastian Dröge 8c22ba25f8 Update CHANGELOG.md for 0.19.4 2022-12-16 11:56:04 +02:00
Sebastian Dröge 857f3740e2 Fix some more new clippy warnings
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1167>
2022-12-15 18:35:49 +02:00
Sebastian Dröge c32607a010 ci: Update to Rust 1.66 and meson 0.64.1
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1167>
2022-12-15 18:16:57 +02:00
Jordan Petridis 9deb507286 ci: Only check default and latest feature version build
Testing all the version makes the job slower for not that much
gain. Disable some of them for now.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1166>
2022-12-13 21:18:12 +02:00
Jordan Petridis d867077c3a ci: Combine windows features builds
Part of gstreamer/gstreamer-rs#417

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1166>
2022-12-13 20:43:24 +02:00
Arun Raghavan c3a950f207 audio: Add bindings for GstAudioFilter
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1165>
2022-12-13 12:27:05 -05:00
Sebastian Dröge e3ad1918dc Fix various new clippy warnings
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1164>
2022-12-13 11:29:45 +02:00
Piotr Brzeziński e579eb5d84 examples/tutorials: Use NSApp terminate() instead of sending an event
Has the same effect while being much more concise.
Unfortunately the cocoa crate doesn't (yet?) have bindings for this
function, so objc::msg_send! had to be used directly.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1162>
2022-12-11 22:09:54 +01:00
Sebastian Dröge 0fa8d0d62f gstreamer: Fix formatting if a string literal needs formatting
E.g. "blabla {some_variable}" is a string literal but needs formatting,
so we can't just pass it as a literal to the logger.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1161>
2022-12-11 12:20:35 +02:00
Sebastian Dröge 2a935320e7 gstreamer: Replace some generic function parameters with impl trait
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1160>
2022-12-10 20:18:11 +02:00
Sebastian Dröge ef5d5f50e4 gstreamer: Actually log the function name instead of the module name
As there is no way to get the function name as a string literal
currently, we have to copy locally into a NUL-terminated array.
Up to 256 bytes this is managed on the stack, otherwise a heap
allocation is necessary.

For the <256 bytes case the compiler is optimizing most of this away.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1160>
2022-12-10 20:18:11 +02:00
Sebastian Dröge 355ebc243f gstreamer: Add DebugCategory::above_threshold() to check if the category's threshold is above the given level
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1160>
2022-12-10 20:18:11 +02:00
Sebastian Dröge b58d518aa3 gstreamer: Use glib::GStr for DebugMessage string API too
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1160>
2022-12-10 20:18:11 +02:00
Sebastian Dröge de04e3f827 gstreamer: Reduce allocations in custom logging functions for the file/function strings
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1160>
2022-12-10 20:18:11 +02:00
Sebastian Dröge 0e7f5a19df gstreamer: Require using a NUL-terminated UTF-8 string or a string literal for the logging ID
Otherwise each log will involve a new allocation just for the ID.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1160>
2022-12-10 20:18:11 +02:00
Sebastian Dröge 2be477b753 gstreamer: Make logging of messages from a string literal allocation-free if using GStreamer 1.20 or newer
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1160>
2022-12-10 20:18:11 +02:00
Sebastian Dröge 3a61276cdd gstreamer: Reduce some allocations for passing the filename/module name to the logging functions
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1160>
2022-12-10 20:18:11 +02:00
Sebastian Dröge 750422d8eb gstreamer: Reduce some code duplication in the logging code
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1160>
2022-12-10 15:48:02 +02:00
Jordan Petridis 1935e04dd8 ci: Fix DAG deps for contianer build jobs
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1159>
2022-12-09 17:37:01 +02:00
Sebastian Dröge 3ab7bc7648 gstreamer: Add bindings for new 1.22 debug log ID API
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1159>
2022-12-09 17:37:01 +02:00
Sebastian Dröge a54c234fc6 gstreamer: Directly use fields for DebugCategory getters
This allows for better optimizations as it doesn't go through an opaque
FFI function.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1159>
2022-12-09 17:37:01 +02:00
Sebastian Dröge e8859951d3 gstreamer: Ignore EventType::to_sticky_ordering
This is handled manually via the `PartialOrd` impl.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1159>
2022-12-09 17:37:01 +02:00
Sebastian Dröge 7012fa638e Regenerate with latest gir/gir-files/gst-gir-files
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1159>
2022-12-09 17:37:01 +02:00
Sebastian Dröge 40a5a9edaa ci: Update Windows docker base image
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1159>
2022-12-09 17:37:01 +02:00
Sebastian Dröge 6a5d16d817 ci: Update image version to get newer GStreamer
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1159>
2022-12-08 20:03:54 +02:00
Sebastian Dröge 73ac98218f Update gst-gir-files
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1159>
2022-12-08 20:03:54 +02:00
Sebastian Dröge 407f03af0c Update gir-files
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1159>
2022-12-08 20:03:54 +02:00
Sebastian Dröge 9d1cc19162 Update gir
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1159>
2022-12-08 20:03:54 +02:00
Sebastian Dröge b89b98b6e9 Update CHANGELOG.md for 0.19.3 2022-11-28 10:16:21 +02:00
Sebastian Dröge b5fcbc9657 gstreamer: Get rid of some unnecessary unsafe API usage
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1157>
2022-11-27 00:59:38 +02:00
Sebastian Dröge 0bc16c65f0 gstreamer: Add some API for add new items to a gst::Array and gst::List
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1157>
2022-11-27 00:59:38 +02:00
Sebastian Dröge ae4dd88f3d Update for GLib Into<Value> changes
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1156>
2022-11-26 15:19:35 +02:00
Sebastian Dröge 0b013001b7 Regenerate with latest gir
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1156>
2022-11-26 15:01:10 +02:00
Sebastian Dröge 92d8df4ac3 Update gir
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1156>
2022-11-26 15:01:10 +02:00
Jordan Petridis e87de384e1 ci: avoid always running build/test jobs
Introduce a trigger job with rules that will allow it to always
run when the MR is assigned to Marge and the final tests will be
run before being merge.

This means that Post-merge pipelines and MR pipelines that are
not assigned to Marge, will require a manual run of the trigger
job before the build/test will execute.

This should help easy the load on the gitlab runners.

Related to gstreamer/gstreamer-rs#417

Close gstreamer/gstreamer-rs#401

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1155>
2022-11-23 18:44:12 +02:00
Sebastian Dröge 3da927a856 gstreamer: Fix sticky event ordering for instant-rate-change
The event type for instant-rate-change events was poorly chosen, leading
to them being re-sent too late and even after EOS.

See https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3387

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1154>
2022-11-21 13:43:22 +02:00
Sebastian Dröge cbfc19ccfc Regenerate with latest GStreamer gir files
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1153>
2022-11-21 13:29:38 +02:00
Sebastian Dröge 1ee4845544 video: Remove gst_video_format_info_get_tile_sizes() bindings and bind new VideoTileInfo API
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1153>
2022-11-21 13:29:38 +02:00
Sebastian Dröge 1fb531bba2 base: Add manual bindings for new 1.22 typefind helper API
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1153>
2022-11-21 13:23:38 +02:00
Sebastian Dröge e763e4fdde audio/video: Hide force-live property of Audio/VideoAggregator
The base class already provides a getter/setter for this.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1153>
2022-11-21 13:04:49 +02:00
Sebastian Dröge d388cbda13 ci: Rebuild for new GStreamer version
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1153>
2022-11-21 13:04:49 +02:00
Sebastian Dröge b482ef4af5 Update GStreamer gir files
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1153>
2022-11-21 13:04:49 +02:00
Sebastian Dröge fa5491e6b3 Use borrowed miniobject/structure types in more places
When the function does not keep around an additional reference of the
value this is correct and more flexible for callers.

https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/issues/420

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1152>
2022-11-21 12:40:37 +02:00
Sebastian Dröge 5a0152b469 gstreamer: tracer: Pass &QueryRef instead of &Query to the functions
To make it impossible for implementor to keep around a reference to the
query as that would break element code that actually tries to answer the
query.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1152>
2022-11-21 12:40:37 +02:00
Sebastian Dröge 1264eb10ac gstreamer: Add PartialEq impls between owned/borrowed miniobjects/structures
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1152>
2022-11-21 12:40:37 +02:00
Sebastian Dröge 56b9b66027 gstreamer: Implement FromIterator<Caps> and Extend<Caps> for Caps
This allows easily generating new/extending existing caps from an
iterator.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1151>
2022-11-21 10:10:04 +02:00
Sebastian Dröge 774fafd987 gstreamer: Implement From<T> for Signed<T>
This makes usage simpler in a few places.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1150>
2022-11-18 12:07:13 +02:00
Edward Hervey 77fd187986 format: Add Signed<T> <=> signed integer conversions
Co-authored-by: Sebastian Dröge <sebastian@centricular.com>
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1149>
2022-11-16 16:32:24 +02:00
Sebastian Dröge 88791294a5 Update CHANGELOG.md for 0.19.2 2022-11-13 20:13:29 +02:00
Sebastian Dröge 9ba448427d Regenerate with latest gir
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1148>
2022-11-12 17:40:16 +02:00
Sebastian Dröge a6ef6dd1ec Update gir
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1148>
2022-11-12 17:39:12 +02:00
Sebastian Dröge c69ff617f5 ges: Don't generate version constants in the -sys crate
They will change with every new version and make the tests fail if
running against a different version.

See https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/issues/422

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1146>
2022-11-12 16:48:33 +02:00
Elie Génard f1c8869447 gstreamer: Add gst::Allocator subclassing support 2022-11-08 19:28:42 +00:00
Sebastian Dröge 58e51417c0 ci: Rebuild image to get updated GStreamer version 2022-11-08 19:07:48 +02:00
Sebastian Dröge d3543efec2 gstreamer: Manually implement Allocator::register()
Due to a bug it causes use-after-free in versions < 1.20.5, so work
around that here.
2022-11-08 19:07:48 +02:00
Sebastian Dröge 32c432655f Regenerate with latest GStreamer gir files 2022-11-08 18:15:34 +02:00
Sebastian Dröge 220da7f1e0 Update GStreamer gir files 2022-11-08 18:13:10 +02:00
Sebastian Dröge e2b38774cf ci: Update to gtk 4.8.2 2022-11-03 17:06:53 +02:00
Sebastian Dröge 7079768dd7 ci: Update to meson 0.63.3 2022-11-03 17:06:53 +02:00
Sebastian Dröge 19949fa2c9 ci: Update to Rust 1.65 2022-11-03 17:06:44 +02:00
Sebastian Dröge efb85f416e ci: Only warn about unknown lints instead of denying 2022-11-01 11:14:31 +02:00
Sebastian Dröge 01e24d2018 Fix various new clippy warnings 2022-11-01 11:10:57 +02:00
Sebastian Dröge 951f000622 examples: glupload: Set sync point on the GL buffer as soon as possible
And also add API for getting the GL context from a `GLBaseMemory`.
2022-10-25 06:51:39 +00:00
Sebastian Dröge c6cbf86012 examples: glupload: Fix iterating over elements inside glsinkbin
Some elements might not have a factory so handle this gracefully instead
of erroring out.
2022-10-25 06:51:39 +00:00
Sebastian Dröge 2cad43cd0f ci: Remove 0.16 and 0.17 docs
Otherwise the pages are too big.
2022-10-24 20:09:15 +03:00
Sebastian Dröge 2bffc4e5ec Fix 0.19.1 release date in the changelog 2022-10-24 12:34:21 +03:00
Sebastian Dröge 708ad14422 Update CHANGELOG.md for 0.19.1 2022-10-24 12:32:45 +03:00
Sebastian Dröge 90b8ee2022 Move from imp.instance() to imp.obj()
It's doing the same thing and is shorter.
2022-10-23 23:06:44 +03:00
François Laignel 87ea535bc1 gst/log: accept non-ref obj in macros 2022-10-23 20:44:38 +02:00
Sebastian Dröge 67ecf0823d ci: Add 0.19 release to the docs job 2022-10-22 21:12:40 +03:00
Sebastian Dröge 92215f4a63 Add missing README.md to new crates 2022-10-22 21:12:23 +03:00
Sebastian Dröge 031133c179 Update versions to 0.20.0 2022-10-22 20:27:42 +03:00
Sebastian Dröge 7331dbc440 Update CHANGELOG.md for 0.19.0 2022-10-22 20:22:10 +03:00
Sebastian Dröge 47394a437f tutorials: Update to termion 2 2022-10-22 20:22:10 +03:00
Sebastian Dröge bf7c770457 Regenerate with latest gir files 2022-10-22 20:22:10 +03:00
Sebastian Dröge f439a0ab85 Update GStreamer gir files 2022-10-22 20:22:10 +03:00
Sebastian Dröge a1165a7456 gstreamer: Add bin/pipeline builders
And also implement the Default trait for them.
2022-10-22 17:36:36 +03:00
Sebastian Dröge 2a4e1069a1 app: Add an AppSrc/AppSink builder
These allows to construct these elements explicitly together with all the
properties instead of going via gst::ElementFactory::make().
2022-10-22 10:19:49 +03:00
François Laignel 0e5a4f05f8 gst: fix Element::request_new_pad signature
See:

https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1133#note_1600152
2022-10-21 11:30:02 +02:00
François Laignel 4ebdfb8602 Use impl Into<Option<_>> for functions impacted by nullability fixes
This commit addresses the functions which signatures changed in
commit f9690817 so that users can still use e.g.
`query.set_result(val)` instead of `query.set_result(Some(val))`.

See [1] for an attempt at generalizing this approach.

[1]: https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1133
2022-10-21 11:30:02 +02:00
Tim-Philipp Müller bfbcdb5925 ci: make windows msrv job manual to reduce load on windows runners
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/issues/417
2022-10-20 13:56:41 +01:00
Sebastian Dröge 130cc9d63b element: Implement linking functions manually for better error reporting
Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/issues/318
2022-10-19 17:59:04 +03:00
Sebastian Dröge 7423b1dea6 elementfactory: Change make() / create() to builders and keep the old variants as create_with_name() / make_with_name()
As a side-effect, this also now includes the element factory name in the
error messages instead of giving the same error string for every
factory.

Partially fixes https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/issues/318

Also let them all go through the same, single object construction code.
2022-10-19 17:48:39 +03:00
Sebastian Dröge 7ad75d4b1f elementfactory: ElementFactory::create_with_properties() is available in any GStreamer version
As it's re-implemented here now instead of calling into the C function.
2022-10-19 13:53:06 +03:00
Sebastian Dröge 9c282ec7c3 gstreamer: Implement ElementFactory::create_with_properties() manually
This way we can get the same property checks as normal object
construction would provide.

Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/issues/402
2022-10-18 16:27:10 +00:00
Sebastian Dröge 5495acf77d rtp: Export functions 2022-10-18 19:21:39 +03:00
Sebastian Dröge 67e3183922 Regenerate with latest gir and gir-files 2022-10-18 18:16:51 +03:00
Sebastian Dröge 19f7aaf413 Generate only a single versions file for sys crates too 2022-10-18 18:15:01 +03:00
Sebastian Dröge 9a9ce252a4 Fix usage of dox feature 2022-10-18 18:15:01 +03:00
Sebastian Dröge d80227e566 Trust nullability annotations everywhere 2022-10-18 18:15:01 +03:00
Sebastian Dröge f9690817ad Fix nullability handling in some functions in manual code 2022-10-18 18:15:01 +03:00
Sebastian Dröge 935609ad6c Update GStreamer gir files 2022-10-18 18:15:01 +03:00
Sebastian Dröge cc59067811 Update gir files 2022-10-18 18:15:01 +03:00
Sebastian Dröge 77252708a4 Update gir 2022-10-18 18:15:01 +03:00
Rafael Caricio 20a493ee49 Implement MpegTs safe bindings
Adds safe bindings generated from Gir for the MpegTS library. Not all
object bindings are generated. This contains a subset of the
library that allows to use it's basic functionality.

Part of the API is written manually to add some extra methods like
setting struct field values and other useful features.
2022-10-18 13:55:09 +00:00
Vivia Nikolaidou 8d3ada5d89 pad: Catch panics in pad task functions
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/issues/246
2022-10-18 10:38:12 +00:00
François Laignel 49faa03c98 gst/format: make from_u64 constructors const
This commit makes the formatted values' main constructors `const`,
so that they can be used in constant definitions.

`from_usize` constructors can't be made const because `try_into`
can't be used in `const` functions as of rustc 1.64.0. Same for
`Percent::from_ratio`: floating point arithmetic is not allowed.
2022-10-18 11:24:57 +02:00
François Laignel 384783b242 gst/format: introduce Constructor traits
Introduce a set of Constructor traits which are implemented on
integer of float depending on the formatted values. This traits
allows building formatted values using expressions such as:

```rust
let buffer_nb = 20.buffers();
let size = 42.k_bytes();
let duration = 15.minutes() + 30.seconds();
let quantity = 42.default_format();
let progress = 20.percent();
let progress = 0.2.percent_ratio();
```
2022-10-18 11:24:08 +02:00
Sebastian Dröge f5a902ba49 example: Update for pango API changes 2022-10-17 19:55:42 +03:00
Sebastian Dröge 7721030c15 Add some more information about setup on Windows/macOS to the README.md 2022-10-14 21:26:12 +05:30
Sebastian Dröge 4bdbe0022b examples: Fix compilation after pangocairo API changes 2022-10-14 18:11:42 +03:00
Vivia Nikolaidou 6f51444c1f audio: Add channel_mask() and default_channel_mask() to AudioCapsBuilder
Also use default_channel_mask() where applicable
2022-10-14 16:58:19 +03:00
Vivia Nikolaidou b230d8aab6 examples, video: Use .into() instead of gst::Fraction::new()
Simplifies the code
2022-10-14 16:26:00 +03:00
Vivia Nikolaidou 39bb9abc3c caps: Add .structure() to CapsBuilder
Allows us to get the structure, to read fields after adding them to the
builder.
2022-10-14 16:24:51 +03:00
Vivia Nikolaidou 6d4ad712c7 examples, audio, pbutils, video: Use AudioCapsBuilder and VideoCapsBuilder
Simplify caps creation code
2022-10-14 13:59:51 +03:00
Sebastian Dröge 734afa998b gstreamer: Implement pad default functions as associated functions
Making them associated functions clearer that special care is required
and avoid conflicts with the same functions in ghostpad/proxypad.
2022-10-12 18:29:52 +03:00
Sebastian Dröge 69f05a1577 ci: Update image version 2022-10-12 15:21:24 +03:00
Sebastian Dröge b9e4b91a3d rtsp-server: Add bindings for new RTSPClientImpl::adjust_error_code() 2022-10-12 15:09:47 +03:00
Sebastian Dröge 7d10f9f4c8 Regenerate with latest gir/gir-files 2022-10-12 15:05:07 +03:00
Sebastian Dröge 8aa1634902 Update GStreamer gir files 2022-10-12 15:01:45 +03:00
Sebastian Dröge 5cdf98b76d Update gir files 2022-10-12 15:01:45 +03:00
Sebastian Dröge 344026a178 Update gir 2022-10-12 15:01:43 +03:00
Sebastian Dröge 08cac646be examples: Fix formatting 2022-10-12 14:33:13 +03:00
Sebastian Dröge b89a285178 Use correct gobject-sys::GObject type in the examples/tutorials 2022-10-12 14:30:19 +03:00
François Laignel dcf6d16496 gst/format: new panicking constructors and some Percent fixes
Previous proposition for constructing specific formatted values was
to use an operation such as `42 * Default::ONE` which, in retrospect,
doesn't seem idiomatic.

This commit adds `from_u64` and `from_usize` constructors for most
formatted values. Having `from_usize` is convenient when dealing with
quantities related to containers indices or length.

This also fixes the `Percent` from float constructors from which was
derived the `ONE` constant as well as previous display implementation.

Also removed the `pub` specifier for `Undefined` inner value. It wasn't
removed in a previous commit as `Undefined` can use the full range of
the inner type. But now, it seems preferable not to expose the inner
value for proper encapsulation and so as to reduce the differences with
other formatted values (kind of least astonishment principle).
2022-10-11 13:25:53 +02:00
François Laignel 08551bb1bc format/specific: don't expose inner as pub
... users would be able to bypass the range checks and build a
defined Rust value which would be interpreted as `None` in C code.

Added format module examples for formatted values constructions.
2022-10-10 19:23:35 +02:00
François Laignel f6336b1be3 gst/format: fix Percent Display impl
- The `GST_FORMAT_PERCENT_SCALE` was not used to compute the value
  to display.
- Added `Display` examples in the format module documentation.
- Simplified `glib_newtype_display` macro.
2022-10-10 18:44:59 +02:00
François Laignel 8e2c621a9f gst/lib: cleanup format re-exports 2022-10-10 15:10:10 +02:00
Sebastian Dröge a4d901ee63 gstreamer: Add an gst::element_error! variant that works on element implementations 2022-10-10 15:01:07 +03:00
Sebastian Dröge 7bd4d770ff gstreamer: Remove unnecessary trait bounds 2022-10-10 15:01:07 +03:00
Sebastian Dröge f17781e188 Change *Impl trait methods to only take &self and not Self::Type in addition 2022-10-10 15:01:07 +03:00
Sebastian Dröge 25c53c4276 gstreamer: Implement new logging variants that work ObjectSubclass values 2022-10-10 15:01:07 +03:00
François Laignel 274a5bd020 gst/format: implement GenericSignedFormattedValue
The `Signed` version for `GenericFormattedValue` was implemented as
`Signed<GenericFormattedValue>`, which failed to represent properly
the `None` variants when applicable and could represent inconsistent
`Signed` variant combined with `GenericFormattedValue` formats which
are internaly represented as signed integers.
2022-10-09 20:00:40 +02:00
François Laignel 04b6710f84 format/Other: use u64 internally instead of i64 2022-10-09 20:00:38 +02:00
François Laignel 8a7813d04c gst: move format_serde.rs under format module 2022-10-09 18:53:57 +02:00
Sebastian Dröge dac3cf67f4 Update for additional translation trait impls in gtk-rs-core 2022-10-08 15:35:37 +03:00
Sebastian Dröge 3cd902513d Update for glib::Object::new() API changes 2022-10-07 21:45:01 +03:00
Sebastian Dröge dcd53bd16e Regenerate with latest gir 2022-10-07 20:30:24 +03:00
Sebastian Dröge 6300c39998 Update gir 2022-10-07 20:28:51 +03:00
SeaDve d8a57e6d4a pbutils/encoding_profile: Prevent copies by taking data by value 2022-10-03 12:21:44 +00:00
SeaDve 238f9baee5 pbutils/element-properties: Add ElementPropertiesMapItem
Also add `field_value` counterpart on both ElementPropertiesGeneralBuilder and ElementPropertiesMapBuilder.
2022-10-03 12:21:44 +00:00
Sebastian Dröge c64b6ac68b tracer: Use Results instead of plain success/failure enums
This makes it more convenient to handle the success/failure cases in
tracer implementations and is more consistent.
2022-10-02 10:45:14 +03:00
Sebastian Dröge ade0aad6b0 tracer: Make buffer in pull-range-post function optional
Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/issues/410
2022-10-02 10:36:05 +03:00
François Laignel bff1354b74 gst/format: module doc 2022-10-01 13:16:06 +02:00
François Laignel e2fe1d6371 gst/format: macros minor cleanups 2022-10-01 13:16:06 +02:00
François Laignel 57d8d46ab6 gst/format: fix some ops and add others
Some operations were implemented on types that wouldn't result in
the expected physical unit. E.g.:

- `ClockTime / ClockTime` results in a unit-less factor.
- `u64 / ClockTime` would result in a `1 / ClockTime`. Since we don't
  use any `Frequency` type, this operation is removed. Users should
  use the `ClockTime` accessors to compute the expected value.

This commit also adds:

- multiplications with integers as the left hand side operands.
- `Partial{Eq,Ord} for `Signed<T>` with `T` as left hand side operand.
- `opt_add` / `opt_sub` for `Signed<T>` with `T` as left or right hand
   side operands.
- missing tests for `Partial{Eq,Ord}` and `OptionOrd`.

This implementation can interfere with unrelated code and was removed:

- `Signed<usize>.` `PartialOrd` makes existing code computing the len
  of slices needing type annotation because the len is later used in
  a comparison for which the compiler is unable to determine if
  the len is `Signed<usize>` or `usize`.
2022-10-01 13:15:11 +02:00
François Laignel eb4d997f0a gst/format: shuffle types and traits 2022-10-01 00:49:42 +02:00
François Laignel 79377337a4 gst/format: move related modules under a directory 2022-10-01 00:49:39 +02:00
Rafael Caricio 69ea30dbda
gstreamer: meta: Allow to register custom meta without transform function 2022-09-29 14:05:35 +02:00
Jordan Petridis 4f2d974aa6 ci/windows: Install pango explicitly
Instead of relying on the subproject

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1110>
2022-09-29 05:01:05 +03:00
Jordan Petridis 21e342c947 ci/windows: Update base windows image tag
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1110>
2022-09-29 05:01:05 +03:00
Jordan Petridis ccb9e3a7f8 ci: Update gtk to 4.8.1
And follow release tags instead of branches.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1110>
2022-09-29 05:01:05 +03:00
Sebastian Dröge e294bb9713 ci: Update to meson 0.63.2 for the image
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1110>
2022-09-29 05:01:05 +03:00
Sebastian Dröge a2150b8368 ci: Update to Rust 1.64
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1110>
2022-09-29 05:01:05 +03:00
Sebastian Dröge 92c6eefadd audio: Ignore ignore-inactive-pads property in AudioAggregator
getters/setters are already generated for the `Aggregator` base class
and the property in the subclass is not really needed here. It also
causes problems with trait resolution as the getter/setter functions
will exist twice.
2022-09-23 17:01:06 +03:00
François Laignel 99e344af4d gst/format: simplify some ops impl
The `SpecificFormattedValue` types are newtypes of `u64` or `u32`
and they all implement `Copy`. It shouldn't be needed to implement
operations on `&Type` nor `&inner_type`.
2022-09-22 00:05:28 +02:00
François Laignel 86549dc06e gst/Segment: return immediately from some functions...
... if the input `is_none`.
2022-09-21 17:20:43 +00:00
François Laignel 8595b67218 gst/Signed: impl option-operations traits 2022-09-21 17:20:43 +00:00
François Laignel 183a399d1d gst/Signed: impl MulDiv 2022-09-21 17:20:43 +00:00
François Laignel 2b4fcb131e gst/Signed: impl div & mul 2022-09-21 17:20:43 +00:00
François Laignel 1411c9e35e gst/Signed: use a new trait for into_{signed,positive,negative}
The functions `into_{signed,positive,negative}` used to be implemented
on the `FormattedValue` trait for convenience. This was wrong for the
following reasons:

- They aren't specific to `FormattedValue`s: they can also be
  implemented for regular unsigned integers such as `u64`, `usize` or
  `u32`.
- They were implemented for `format::Undefined` and all variants of
  `GenericFormattedValue`, some of which are already signed.

This commit introduces the new trait `UnsignedIntoSigned`, which makes
it possible to fix both of the above problems.

Users can build a `Signed` from an `Undefined`, an `i64`, `isize` or
`i32` thanks to the `From` trait implementations.
2022-09-21 17:20:43 +00:00
François Laignel 960befb2f5 gst/Signed: move signed ops macro to macro.rs
This will help with the implementation of Signed muls & divs for
`FormattedValue`s since we need to know about the inner types.
2022-09-21 17:20:43 +00:00
François Laignel 0d229b4c69 gst/format: separate non trait ops format macros from common ops 2022-09-21 17:20:43 +00:00
François Laignel 432cb36611 gst/Signed: add tests and fix some ops impl 2022-09-21 17:20:43 +00:00
François Laignel 8e6afe147e gst/Signed: impl Display and Displayable 2022-09-21 17:20:43 +00:00
François Laignel a1dbc7a0ee gst/format: use fmt::Display whenever possible
Previous implementation for the glib format new types built a
`String` for the displayable value. This commit uses `fmt`
mechanisms so as to limit useless allocations.
2022-09-21 17:20:43 +00:00
François Laignel e0d9f886e3 gst/format: add Signed::{positive, negative}
It's more convenient to use than:

```rust
    signed_val.positive_or(()).ok()
```
2022-09-21 17:20:43 +00:00
François Laignel 55ef309b16 gst/ClockTime: panic building from GST_CLOCK_TIME_NONE
Using `ClockTime::from_nseconds` it was possible to build a valid
`ClockTime` which would match `GST_CLOCK_TIME_NONE` when passed to
the C API, leading to unexpected behaviour as `GST_CLOCK_TIME_NONE`
is represented as an `Option::<ClockTime>::None` in Rust.

This commit panics when this function is called with
`GST_CLOCK_TIME_NONE` (defined as `u64::MAX`). This is similar to
what happens when calling other `ClockTime` constructors (e.g.
`from_seconds`) with too large a value: the internal multiplication
overflows leading to a panic.
2022-09-21 17:20:43 +00:00
François Laignel b8e1c25c85 gst/log: log arg eval fix non regression test 2022-09-21 17:20:43 +00:00
Jordan Petridis 253ba03a7a ci: Use correct variable for the upstream image repo 2022-09-20 17:47:43 +03:00
Jordan Petridis a75d881272 ci: Don't filter out scheduled pipelines
Close #370

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1105>
2022-09-16 16:18:55 +03:00
Sebastian Dröge 64829ac47a gstreamer: Use type parameters instead of trait objects for TypeFindFactory::call_function()
No need to do dynamic dispatch here.
2022-09-16 11:26:24 +03:00
Sebastian Dröge 1b10c5324d gstreamer: Add BinImpl::do_latency() 2022-09-16 06:54:55 +00:00
SeaDve 59efe09fe5 pbutils/encoding_profile: Add support for 1.20 element-properties API 2022-09-15 16:36:44 +03:00
Sebastian Dröge 8a6de3ca4f gstreamer: Implement various operations on Signed for working with it more easily 2022-09-14 12:20:47 +03:00
François Laignel f294339240 log: differ formatted args evaluation
When the `format_args!` macro is used, formatted args are evaluated
in order to form the argument collection that ends up being formatted
when requested to do so.

For the log macro, this means that any argument that is an expression
was evaluated even if the log level was below current threshold. This
can be examplified by the following code:

```rust
    gst::debug!(CAT, "{}", {
        println!("fmt arg executed");
        "A debug log"
    });
```

This used to print "fmt arg executed" even when the log threshold for
`CAT` was filtering `debug` out.

Note that this could break existing code that would incorrectly rely
on the side effect.
2022-09-13 19:25:14 +02:00
Sebastian Dröge 7fa76eac1b ci: Update image template version for a rebuild 2022-09-13 12:13:30 +03:00
Sebastian Dröge dec112d0a8 Regenerate with latest gir/gir-files/gst-gir-files 2022-09-13 12:13:07 +03:00
Sebastian Dröge 77029602ae Update GStreamer gir files 2022-09-13 12:12:57 +03:00
Sebastian Dröge eb798fb83b Update gir-files 2022-09-13 11:49:22 +03:00
Sebastian Dröge 97e8913cb9 Update gir 2022-09-13 11:49:10 +03:00
François Laignel f014505e1c regen: rename feature 'ser_de' as 'serde' 2022-09-12 19:36:32 +02:00
François Laignel 069c6a2c01 Rename feature 'ser_de' as 'serde'
When I introduced the 'ser_de' feature, I couldn't find a way to
name it 'serde' while also make it pull the optional 'serde'
crate together with the other related dependencies.

With rustc >= 1.60 we can use 'dep:serde' to refer to the 'serde'
dependency as part of the 'serde' feature.
2022-09-12 19:36:30 +02:00
Sebastian Dröge 879d6a4548 audio: Use new 1.63 std::array::from_fn instead of the external array-init crate 2022-09-05 18:10:17 +03:00
Sebastian Dröge 099ffdc4b4 examples: Change cairo-compositor example to use ParamSpec builders 2022-09-05 11:48:37 +03:00
Sebastian Dröge 8d982d8b51 ci: Checkout git submodules before running gir checks 2022-09-04 22:46:57 +03:00
Sebastian Dröge efe13948cc ci: Update gst-gir-files and bring autogenerated code in sync 2022-09-04 20:51:07 +03:00
Sebastian Dröge 5163e212ed ci: Install rustfmt in the nightly toolchain for generator.py 2022-09-04 20:49:19 +03:00
Sebastian Dröge a7618aecc2 ci: Add job that checks that all generated files and submodules are in the correct version
Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/issues/400
2022-09-04 10:42:29 +03:00
Sebastian Dröge e5a785c9a5 ci: Embed docs before removing them to check more completely that there are no leftover docs 2022-09-04 10:41:57 +03:00
Sebastian Dröge d00b289621 Don't checkout submodules by default
This makes sure that cargo does not clone and checkout all the
submodules if pointing to this repository as a git dependency.

To checkout the submodules `git submodule update --checkout` can be
used.
2022-09-04 10:39:18 +03:00
Sebastian Dröge 35c6af424d Update minimum supported Rust version to 1.63 2022-09-04 10:37:13 +03:00
Sebastian Dröge 201eed8400 gstreamer: Sync param spec API with glib 2022-09-04 10:34:05 +03:00
Arun Raghavan 6c594b4c38 ci: Bump Rust MSRV to 1.61
This is needed by recent bytes-utils (see
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/847#note_1536032)
2022-09-02 12:45:31 -04:00
Arun Raghavan b6c8938f1a ci: Enable libnice while building GStreamer
This enables webrtcbin as well, which is needed for the whipsink plugin
in gst-plugins-rs.
2022-09-02 12:22:00 -04:00
Thibault Saunier 5227af5935 validate: Update from fixed gir 2022-08-31 22:02:22 +00:00
Jordan Petridis 8ca9692924 windows: Install dav1d in the docker image
Also to be used in the gst-plugins-rs CI

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1084>
2022-08-31 23:08:14 +03:00
Jordan Petridis 29bc304c88 ci: Set the PATH var in the docker image rather than scripts
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1084>
2022-08-31 23:05:08 +03:00
Jordan Petridis be356dbf08 ci: Use a prefix for the meson build in the windows image
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1084>
2022-08-31 23:05:08 +03:00
Jordan Petridis 9a9b7bc5ce ci: Install gtk on the windows image
So we can use it in gst-plugins-rs CI.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1084>
2022-08-31 23:05:08 +03:00
Jordan Petridis f7248408cb ci: Update the docker windows base image
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1084>
2022-08-31 23:05:07 +03:00
Rafael Caricio 6163914605
pbutils: Add bindings for the AudioVisualizer base class 2022-08-31 14:03:58 +02:00
Sebastian Dröge 44d899a0eb Regenerate with latest gir / gir-files / gst-gir-files 2022-08-31 11:13:08 +03:00
Sebastian Dröge 8a89be67f7 ci: Update image template version to update GStreamer 2022-08-31 11:02:14 +03:00
Sebastian Dröge 870ad5e4d7 Update gst-gir-files 2022-08-31 11:02:00 +03:00
Sebastian Dröge a207765e36 Update gir-files 2022-08-31 11:01:55 +03:00
Sebastian Dröge ebab45d7b0 Update gir 2022-08-31 11:01:45 +03:00
Guillaume Desmottes e229288ecd gstreamer: manually implement Debug on PromiseReply
The default implementation was not very useful:

PromiseReply(
    Promise {
        inner: Shared {
            inner: 0x00007ff108001090,
        },
    },
)
2022-08-29 08:59:21 +00:00
Thibault Saunier a341b4972f validate: Do not check if initialized when initializing
🤦
2022-08-26 11:27:23 -04:00
Guillaume Desmottes 1e24e2d133 gstreamer: caps: improve Debug implementation 2022-08-25 10:54:16 +02:00
Guillaume Desmottes 0c9158f404 gstreamer: taglist: improve Debug implementation 2022-08-25 10:54:16 +02:00
Guillaume Desmottes 64c09353b7 gstreamer: structure: improve Debug implementation
g_strdup_value_contents() output is not easily readable with nested
structures
2022-08-25 10:54:16 +02:00
Thibault Saunier e9d95eda59 gstreamer: Add extension trait to mark API as plugins API
This adds an extension trait implemented for GType so we can
add and check plugins API status.
Required so we can document plugins written in rust.
2022-08-24 10:38:06 -04:00
Philippe Normand 70d95dca4c validate: New crate for GstValidate bindings
Co-authored-by: Thibault Saunier <tsaunier@igalia.com>
2022-08-23 12:04:05 -04:00
Sebastian Dröge f65d410fc5 gstreamer-video: Add bindings for VideoInfo::in_info() / out_info() 2022-08-19 19:45:30 +03:00
Sebastian Dröge ffa6d67868 webrtc: Add accessors for WebRTCICECandidateStats 2022-08-19 19:45:30 +03:00
Sebastian Dröge 76f01516e3 Regenerate with latest GStreamer gir files 2022-08-19 19:42:05 +03:00
Sebastian Dröge 4c7581ab03 ci: Update image version to build newer GStreamer 2022-08-19 19:40:51 +03:00
Sebastian Dröge 0e72d934e1 Update GStreamer gir files 2022-08-19 19:40:33 +03:00
Sebastian Dröge 8d9abb935b gstreamer: Update to ron 0.8 2022-08-16 13:09:49 +03:00
François Laignel be2de21602 Update option-operations to 0.5.0
This fixes the trait `OptionEq` not being exported in `prelude`.
2022-08-15 22:44:53 +02:00
Sebastian Dröge fbad0fd0bc Regenerate with latest gir / gir-files / gst-gir-files 2022-08-14 14:02:50 +03:00
Sebastian Dröge 0921028507 Update GStreamer gir files 2022-08-14 12:29:19 +03:00
Sebastian Dröge 212099c55f Update gir-files 2022-08-14 12:01:52 +03:00
Sebastian Dröge fad06dd47d Update gir 2022-08-14 12:01:33 +03:00
Guillaume Desmottes c5d19e7c80 miniobject: implement ptr_eq() on ref type 2022-08-12 11:15:08 +02:00
Guillaume Desmottes c0fd8a8aad gstreamer: add BufferRef::ptr_eq() 2022-08-12 08:29:49 +02:00
Guillaume Desmottes 2dcd5cf9eb as_ptr() and as_mut_ptr() accessors are safe
Nothing unsafe about getting a pointer, deferencing it is unsafe.
2022-08-12 08:29:49 +02:00
Sebastian Dröge 4e221c1b48 ci: Update to Rust 1.63 2022-08-11 18:18:51 +03:00
Sebastian Dröge b06a692dea Fix a new beta clippy warning
warning: unused return value of `std::boxed::Box::<T>::from_raw` that must be used
  --> gstreamer-rtsp-server/src/rtsp_session_pool.rs:23:5
   |
23 |     Box::<F>::from_raw(ptr as *mut _);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: `#[warn(unused_must_use)]` on by default
   = note: call `drop(from_raw(ptr))` if you intend to drop the `Box`
2022-08-10 10:27:27 +00:00
Vivia Nikolaidou 583ef0395d audio: Add new_interleaved() to AudioCapsBuilder
Because it's very common that elements support only interleaved audio.
2022-08-10 09:50:01 +00:00
Sebastian Dröge 2cb7fc8122 gstreamer: Add GstParamSpecBuilderExt trait to easily allow setting controllable, mutable-ready and other extension flags 2022-08-10 12:28:05 +03:00
Sebastian Dröge 446f09fec6 gstreamer: Implement new ParamSpecBuilderExt trait from glib 2022-08-10 12:03:51 +03:00
Sebastian Dröge 8a50bbcaa3 audiobuffer: Remove unnecessary ref/deref
warning: deref on an immutable reference
   --> gstreamer-audio/src/audio_buffer.rs:255:35
    |
255 |             Self::Owned(ref b) => &*b,
    |                                   ^^^
    |
    = note: `#[warn(clippy::borrow_deref_ref)]` on by default
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#borrow_deref_ref
2022-08-09 21:08:22 +00:00
Sebastian Dröge 9018d1e3ac examples: Update to glutin 0.29 2022-08-09 18:46:00 +00:00
Vivia Nikolaidou 7a9537c0fd audio, video: Default values in caps builders
AudioCapsBuilder::new() will have the default values for
rate/channels/layout/format. Similarly, VideoCapsBuilder::new() will
have the default values for format/width/height/framerate.
2022-08-09 15:00:54 +03:00
Vivia Nikolaidou 751a5b4788 gstreamer-video: Add tests for previous/next fraction 2022-07-20 11:06:21 +00:00
Vivia Nikolaidou 138bc71051 gstreamer-audio: Add AudioCapsBuilder 2022-07-20 11:06:21 +00:00
Vivia Nikolaidou 32fbb04fa4 gstreamer-video: Add VideoCapsBuilder 2022-07-20 11:06:21 +00:00
Sebastian Dröge 95b541cf82 ci: Update to Rust 1.62.1 2022-07-19 16:51:18 +03:00
François Laignel 2d17d46c50 gst: use Signed where applicable 2022-07-18 23:26:20 +02:00
François Laignel 414222aa99 gst/format: Signed wrapper
Functions such as Segment::to_running_time_full replicate the C
signature for the return type: an integer indicates whether the
resulting value must be interpreted as positive or negative.
In Rust, alternatives are usually represented using an enum.

This commit implements an enum wrapper to represent the sign
and adds functions to FormattedValue to ease Signed handling.
2022-07-18 23:26:20 +02:00
Sebastian Dröge dccd0f9e01 ci: Update rustup to 1.25.1 2022-07-18 13:26:17 +03:00
Sebastian Dröge 8cb13ac752 video: Add new Colorimetry::is_equivalent() 2022-07-18 13:25:48 +03:00
Sebastian Dröge b5920ee729 Regenerate with latest gir 2022-07-18 13:25:36 +03:00
Sebastian Dröge 16655828ab Update GStreamer gir files 2022-07-18 13:20:45 +03:00
Sebastian Dröge afe594089b Update gir-files 2022-07-18 13:14:34 +03:00
Sebastian Dröge 4201727769 Update gir 2022-07-18 13:14:23 +03:00
Sebastian Dröge cf1a64ecf8 gstreamer: Hide some useless enum variants that only make sense in C 2022-07-18 13:13:48 +03:00
François Laignel 99fb9423d2 regen: optional return type for TestClock::next_entry_type 2022-07-15 13:38:23 +02:00
François Laignel 8720c9c386 check: fix optional return type for TestClock::next_entry_type 2022-07-15 13:38:23 +02:00
Tomasz Andrzejak 2090452e3d Update minimum supported rust version 2022-07-14 15:23:34 +02:00
Sebastian Dröge 538eb95e51 ci: Update to rustup 1.25.0 and meson 0.63.0 2022-07-12 10:26:44 +03:00
François Laignel a787197254 Use CompatibleFormattedValue where applicable
See https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1059
2022-07-11 19:45:52 +02:00
François Laignel 865df62f8d gst/format: add CompatibleFormattedValue
The trait CompatibleFormattedValue can be used to check argument
compatibility to a certain Format. This is convenient to define
function which accept several FormattedValues which must hold
values of the same Format.

This trait enforces format compatibility at compilation time for
SpecificFormattedValues and at runtime when a GenericFormattedValue
is provided.

See https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1059
2022-07-11 19:45:52 +02:00
François Laignel fe319af598 Implement FormattedValue on any candidate type
The trait FormattedValue was only implemented on types which
could implement the full range of values for a Format. In order
to declare a function which could take both the intrinsic type
of any Format (e.g. `ClockTime`) as well the full range of values
(e.g. `Option<ClockTime>`), the argument was declared:

```rust
    impl Into<GenericFormattedValue>,
```

This commit implements `FormattedValue` for any type representing
a format. E.g.: both `ClockTime` and `Option<ClockTime>` will now
implement `FormattedValue`. The trait `FormattedValueFullRange`
is implemented on types which can be built from any raw value.

These changes are intended to help for the implementation of a
means to enforce format conformity at compilation time for
functions with multiple formatted value arguments.

The following signatures were found to be incorrect and are fixed:

- `message::StepDone`: forced the type for `amount` and `duration`
  to be of the same type, when `duration` is expected to be of the
  `Time` format.
- `query::Convert::set`: the two arguments were forced to the same
  type, so potentialy the same format, unless a
  `GenericFormattedValue` was used.

See https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1059
2022-07-11 19:45:52 +02:00
Guillaume Desmottes fbceaab941 utils: streamproducer: add API to retrieve last sample from producer
This may be used for example to easily generate thumbnails from video
producers.
2022-07-11 11:32:06 +02:00
Guillaume Desmottes 0e17878bed utils: streamproducer: add API to retrieve pushed and dropped buffers
This may be used by applications to compute statistics about the overall
pipeline health, like the ratio of buffers dropped.
2022-07-11 09:10:52 +02:00
Paolo Borelli f2a2e6702c caps: add new_empty_simple constructor 2022-07-05 14:49:21 +02:00
Sebastian Dröge 17005f220b ci: Update to Rust 1.62 2022-07-01 00:04:33 +03:00
Sebastian Dröge 4dade30f0d Fix/silence a couple new clippy warnings 2022-06-30 13:08:33 +00:00
Sebastian Dröge f30fcbcf9a pbutils: Fix PbUtilsCapsDescriptionFlags serde (de)serialization tests 2022-06-30 12:42:37 +03:00
Sebastian Dröge 65629426cb tracer: Add bindings for new pad chain hooks 2022-06-30 08:46:06 +03:00
Sebastian Dröge 07562c592f video: Add bindings for is_common_aspect_ratio() 2022-06-30 08:46:06 +03:00
Sebastian Dröge 90aaa32957 Regenerate 2022-06-30 08:46:06 +03:00
Sebastian Dröge fb724aedeb Update gst-gir-files 2022-06-30 08:46:06 +03:00
Sebastian Dröge 8e9e135128 Update gir-files 2022-06-30 08:46:06 +03:00
Sebastian Dröge 542bb130f4 Update gir 2022-06-30 08:46:06 +03:00
Sebastian Dröge f333991a5a ci: Update image 2022-06-30 08:46:06 +03:00
Sebastian Dröge c61d913ec6 tracer: Add support for the 1.20 "plugin-feature-loaded" hook 2022-06-29 10:13:59 +03:00
Sebastian Dröge 9e77ab3212 tracer: Re-order trait functions slightly for the order to make more sense 2022-06-29 10:13:36 +03:00
Sebastian Dröge 14f485d0b1 bus: Take ownership of the message in post() 2022-06-28 23:36:08 +03:00
Sebastian Dröge 20ac231146 gstreamer: Allow borrowing Segments from Values without copying 2022-06-27 22:28:49 +03:00
Sebastian Dröge c9d07219c8 Store whether GStreamer was initialized in an AtomicBool
Avoids a function call in the normal case.
2022-06-27 10:28:28 +03:00
Sebastian Dröge 7754b8dd70 allocators: Reduce number of initialization check macros 2022-06-27 10:07:58 +03:00
Sebastian Dröge 310ff531fb base: Fix memory leak if BaseSrc/PushSrc parent class is not filling the provided buffer as it should 2022-06-24 11:13:06 +03:00
Sebastian Dröge b28664ccbd gstreamer: Fix serde serialization tests
ron serialization is now writing `1.0` instead of just `1`.
2022-06-24 11:13:06 +03:00
Sebastian Dröge 6b47d646c0 base: Add support for returning buffer lists from BaseSrc/PushSrc subclasses 2022-06-24 11:13:06 +03:00
Sebastian Dröge 5e3ace0ecc ci: Fix syntax for coverage reports to the new format 2022-06-07 09:04:40 +03:00
Sebastian Dröge 2c373f5d24 examples: Update to memfd 0.6 2022-06-06 11:18:40 +03:00
Sebastian Dröge 50f3eee8eb play: Mark play_message module as private
The only type that is defined in it is re-exported at the crate root.
2022-05-24 11:02:27 +03:00
Philippe Renon 01b8279bc1 examples: add GstPlay example 2022-05-24 06:55:12 +00:00
Philippe Renon 35aff36c61 Introduce gstreamer-play 2022-05-24 06:55:12 +00:00
Philippe Renon f35baffb52 Update gst-gir-files 2022-05-24 06:55:12 +00:00
Stephan Seitz c254c5fd1a gstreamer: add PadProbeId::as_raw()
This allows to convert PadProbeId to numberic values without
taking them by value (like `into_glib`).

See https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/issues/382#note_1391236
2022-05-23 08:19:47 +00:00
Sebastian Dröge cb1f08a425 gstreamer: Implement FusedFuture for PromiseFuture 2022-05-22 12:42:42 +03:00
Sebastian Dröge aaf601831e gstreamer: Index structures/taglist more safely
Accessing after the length will lead to a critical warning and should
not happen.
2022-05-22 12:42:42 +03:00
Sebastian Dröge d4430ecc6a Implement more iterator functions / traits in custom iterators for efficiency reasons 2022-05-22 12:42:42 +03:00
Philippe Renon 8f1c94f45d Regenerate with latest gir 2022-05-20 17:48:40 +02:00
Philippe Renon 5ed8416717 Update gir 2022-05-20 17:48:40 +02:00
Sebastian Dröge e76ae3f434 gstreamer: Fix a few new clippy warnings 2022-05-20 11:19:07 +03:00
Sebastian Dröge 0055399471 ci: Update to Rust 1.61 2022-05-19 18:10:24 +03:00
Jordan Petridis 7283fe69b2 ci: Build gstreamer-gl on windows
This was disabled since DirectX wasn't available, but its working
now on the server2022 image that provides the required headers
and dlls.
2022-05-19 13:26:34 +03:00
Jordan Petridis 9d873d6755 ci: define the dependencies between jobs
This means that jobs can start the moment they are ready, instead
of waiting for the previous stage to finish.

Also define their interruptibility so new pipelines can automatically
cancel the previous ones.

https://docs.gitlab.com/ee/ci/yaml/index.html#needs
2022-05-18 22:21:08 +03:00
Jordan Petridis 7075a4b3ea ptp_clock: fix build on windows
c_ulong/gulong can be 32bit or 64bit depending on the platform.
Always cast it to u64 so the compiler will be happy.
2022-05-18 22:20:37 +03:00
Jordan Petridis 4d7bd9bfcb ci: use rules instead of only/except
only/except has got deprecated in favour of rules

maybe it fixes #370 ?

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/701>
2022-05-18 19:51:49 +03:00
Jordan Petridis d53dfcf94e ci: use a custom powershell script to run windows tests
There are a couple things going on here.

First, we need to avoid building egl/wayalnd/x11 crates on windows
as they can't be built.

Then we need to avoid running -sys tests as they don't succeed
currently. See [1]

Finally use a matrix:parallel job to tests multiple build
configurations.

[1] https://github.com/gtk-rs/gtk3-rs/issues/54

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/701>
2022-05-18 19:51:49 +03:00
Jordan Petridis 5e27da5a1c ci: add an msvc 2017 test
Tests disabled for now, till some quirks are worked out.
Thi should be good enough to at least not break the build though.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/701>
2022-05-18 19:51:49 +03:00
Jordan Petridis 842dad3fa5 Cargo.toml: add cross-platform crates to default-members
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/701>
2022-05-18 13:12:47 +03:00
Philippe Renon 5d2f36fac3 gstreamer: implement FromGlibPtrBorrow trait for gst::Structure
needed for callbacks that pass GstStructure by reference
for example: the PlaySignalAdapter error and warning signals

needed by https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1036
2022-05-17 23:19:35 +02:00
Philippe Renon 268e351dde examples: fix clippy errors 2022-05-17 21:47:34 +02:00
Thibault Saunier 8c69388eff utils: Re export AddConsumerError 2022-05-17 20:19:12 +03:00
Guillaume Desmottes 5349822962 utils/streamproducer: add ConsumptionLink
Having an explicit link object makes it much easier to build complex
producers/consumers dynamics graphs.
It provides helper to switch producers and prevent accidentally keeping
broken links around as they are disconnected on Drop.
2022-05-17 11:04:35 +03:00
Guillaume Desmottes f68efd0cab utils/streamproducer: add API to not forward eos to consumers
User may want to plug another producer when one is eos, in such case we
don't want to propagate eos to consumers.
2022-05-17 11:04:35 +03:00
Guillaume Desmottes 351f070c8e utils/streamproducer: reset callbacks when removing consumer 2022-05-12 14:56:55 +02:00
Sebastian Dröge 98cc289bcc utils/streamproducer: Add StreamProducer::error() to signal an error message to all consumers 2022-05-12 10:51:56 +03:00
Sebastian Dröge e263bd8945 utils/streamproducer: Request keyframes without a lock held and also after an appsrc has dropped some data 2022-05-12 10:44:59 +03:00
Sebastian Dröge d6095900e9 utils/streamproducer: Improve debug output a bit 2022-05-12 10:37:14 +03:00
Sebastian Dröge e82d388410 utils/streamproducer: Index hashmap by appsrc instance instead of pointer
This behaves the same but requires a little bit less code.
2022-05-12 10:34:11 +03:00
Sebastian Dröge a51235048d utils/streamproducer: Add StreamProducer::configure_consumer()
This allows configuring an `appsrc` before actually adding it as
consumer at a later time, and can be useful if the pipeline with the
source should be started earlier than adding it to a consumer.

Also use strongly-typed property API for the `appsrc` properties.
2022-05-12 10:34:06 +03:00
Thibault Saunier f3bba21faa Introduce StreamProducer
Introduce a new `gstreamer-utils` crate where we implement a
`StreamProducer` structure that allows "producing" pipeline (Producers)
pushing their data to 0 or several "consuming" pipelines. The Producer
needs to push their data to an `appsink` which the `StreamProducer` controls
and the "consumer" pipelines need to have an AppSrc which the same
StreamProducer controls.

It allows similare behavior as a `tee` element but with a simpler to
handle addition and removal of "consumers" as well as a total decoupling
of the various consumer, both between each others and the producer
pipeline.

This has simply been extracted from
[webrtcsink](https://github.com/centricular/webrtcsink/blob/main/plugins/src/webrtcsink/utils.rs)
2022-05-11 10:14:54 -04:00
Thibault Saunier 56a46fc6fd ci: Re-implement the gi-checker in python
To cleanup and ignore the gstreamer-utils crate
2022-05-11 10:14:54 -04:00
Sebastian Dröge 081d42ac86 net: Add various static PTP clock API
This allows initializing the PTP clock infrastructure, deinitializing
it, checking the current status and adding statistics callbacks.
2022-05-11 14:19:50 +03:00
Jordan Petridis b62d22852e ci: cleanup the checkouts in the docker image after install 2022-05-10 10:11:47 +03:00
Sebastian Dröge 45e16f7753 gstreamer: Add #[must_use] annotation to PadTemplateBuilder 2022-05-08 11:41:54 +03:00
Guillaume Gomez c1d3ed5eac Use IntoGlibPtr trait instead of implementing into_ptr 2022-05-07 13:38:11 +02:00
Sebastian Dröge cd49659fae gstreamer: Add a PadTemplateBuilder
And only allow setting documentation caps via that. It's not actually
allowed to update the documentation caps at random times as it is not
thread-safe.
2022-05-06 16:57:06 +03:00
Sebastian Dröge 0aa59be45c gstreamer: Improve accessors to various pad template fields 2022-05-06 16:22:40 +03:00
Sebastian Dröge 45856ac35b gstreamer: Return a glib::List instead of a Vec for the pad template list
Avoids an unnecessary allocation for the `Vec`.
2022-05-06 12:42:52 +03:00
Vivienne Watermeier 1b22be2e15 Add De/Serialization for most bitflag types
Represents combinations of flags with a '+' separated string of nicks,
or an empty string for no flags set.

Note that most flag types will ignore any flags using multiple bits when
serializing, since in most cases these flags cover all used bits.
2022-05-06 09:05:52 +00:00
Vivienne Watermeier 94b5a13f4b Regenerate with Gir.toml changes 2022-05-06 09:05:52 +00:00
Vivienne Watermeier fec2718aef Remove generated serde derives from all bitflags types 2022-05-06 09:05:52 +00:00
Sebastian Dröge a34bc85ca1 video: Don't change the VideoOverlayComposition constructor API based on feature flags
Feature flags are additive and a higher feature might be enabled by some
other dependency, which then can cause code that assumes the other API
fail to compile.

Still implement the constructor separately per version to make it clear
to the compiler that the constructor can't fail at all in newer
versions.
2022-05-06 11:01:02 +03:00
Mathieu Duponchelle d83faa044e rtp_buffer: buffer() does not need to return an Option
When a RTP buffer is mapped, its buffer field always holds a
non-null pointer.
2022-05-05 14:36:43 +02:00
Sebastian Dröge a16c3888e5 Return base class pads by reference instead of strong reference
Avoids unnecessary reference counting and the caller can get a strong
reference easily by calling clone().
2022-05-05 14:18:03 +03:00
Mathieu Duponchelle 80b0b378fc base classes: expose accessors for static pads
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1023>
2022-05-04 17:15:07 +02:00
Sebastian Dröge ba955a22bd ci: Update image version for including a newer GStreamer build 2022-05-03 15:42:18 +03:00
Sebastian Dröge b50a7993de video: Add bindings for VideoFormatInfo::tile_sizes() 2022-05-03 15:41:54 +03:00
Sebastian Dröge 4a28a188d9 Regenerate with latest gir/gir-files 2022-05-03 15:37:25 +03:00
Sebastian Dröge 90ac00a6f6 Update GStreamer gir files 2022-05-03 15:36:05 +03:00
Sebastian Dröge d3eb9db8ce Update gir-files 2022-05-03 15:36:00 +03:00
Sebastian Dröge 0f89be2751 Update gir 2022-05-03 15:35:54 +03:00
Sebastian Dröge 2b7a63fc8e gstreamer: Implement FusedStream for the Bus stream 2022-04-30 21:10:59 +03:00
Sebastian Dröge e04bb8b524 Update CHANGELOG.md for 0.18.8 2022-04-26 14:06:28 +03:00
Mathieu Duponchelle 7fa0b4e84d rtpbuffer: bind length calculation API
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1014>
2022-04-23 01:12:16 +00:00
Sebastian Dröge 0e0d9f532b gstreamer: Update to pretty-hex 0.3 2022-04-22 13:57:24 +03:00
Sebastian Dröge 7420a72831 gstreamer: Add error/warning/info message constructors from a pre-existing glib::Error 2022-04-21 15:33:51 +03:00
Sebastian Dröge 40dcdcbf5c gstreamer: Simplify error/warning/info message builders 2022-04-21 15:03:50 +03:00
Vivienne Watermeier 61a3f5296c video: Fix de/serialization for empty modifier states
Empty modifier states are now de/serialized from/to the empty string;
This also adds more thorough testing for deserializing.
2022-04-14 18:19:56 +02:00
Mathieu Duponchelle f095b6f0ba rtp_buffer: bind buffer getters
* Expose the buffer field, useful to look up flags and meta

* Expose the payload_buffer API, useful to avoid copies, for instance
  when storing in an adapter

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1008>
2022-04-14 13:31:28 +00:00
Mathieu Duponchelle af89799e06 rtp: add bindings for RTPBaseDepayload
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1008>
2022-04-14 13:31:28 +00:00
Mathieu Duponchelle 062ceaa00a rtp: add bindings for RTPBasePayload
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1008>
2022-04-14 13:31:28 +00:00
Vivienne Watermeier 3b18f10342 video: Implement De/Serialization for NavigationModifierType
Modifier state is represented by a "+" separated list of lowercase flag
names, or "empty" for no flags.
2022-04-13 14:29:45 +02:00
Sebastian Dröge 8d001d8b16 Stop using glib::SendUnique
It is being removed because it does not add a lot of value.
2022-04-09 11:37:53 +03:00
Jan Alexander Steffens (heftig) 7d2ab1450e gstreamer: Export subclass::TaskPoolFunction
This must be accessible in order to subclass TaskPool.
2022-04-07 17:57:59 +00:00
Sebastian Dröge c82aefd2a4 ci: Run coverage job on the stable image 2022-04-07 18:51:20 +03:00
Sebastian Dröge 680d4af732 ci: Update to Rust 1.60 2022-04-07 18:48:59 +03:00
Sebastian Dröge 4651c9db4d Update minimum supported version to 1.14
This is the version that is available in Ubuntu 18.04.
2022-04-07 12:45:47 +03:00
Sebastian Dröge 5052a93ee3 Fix macOS instructions in other READMEs too 2022-04-07 11:35:40 +03:00
Sebastian Dröge a90aed0d41 examples: Update to memfd 0.5 2022-04-06 11:05:05 +03:00
Vivia Nikolaidou 60a192d525 rustfmt.toml: Add file
This will automatically run `cargo fmt` when a file is saved.
2022-04-06 07:46:29 +00:00
Sebastian Dröge 9a8ca0cadd gstreamer: Add bindings for the new 1.22 selectable query 2022-04-06 10:18:48 +03:00
Sebastian Dröge 627f4d798e gstreamer: Get rid of some duplicated feature cfg attributes 2022-04-06 10:18:48 +03:00
Sebastian Dröge bcf4f63ac6 gstreamer: Don't make the bitrate query available at all with v1_16 2022-04-06 09:51:19 +03:00
Sebastian Dröge d92e49a797 ci: Update image version 2022-04-06 09:39:25 +03:00
Sebastian Dröge b36b63c60a Regenerate with latest gir files 2022-04-06 09:38:34 +03:00
Sebastian Dröge 8dd2af610f Update gir files 2022-04-06 09:37:27 +03:00
Sebastian Dröge 3532c9adb2 Update GStreamer gir files 2022-04-06 09:36:55 +03:00
Vivienne Watermeier d5e4705605 video: Add builders for navigation events 2022-04-05 19:49:05 +00:00
Vivienne Watermeier 1274a59472 video: update navigation API for recent changes
Add support for the new send_event_simple and event_get/set_coordinates
functions, as well as touchscreen events and modifier state. See:
https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1633
https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2010
2022-04-05 19:49:05 +00:00
Sebastian Dröge 23e4d1efa8 Regenerate with latest GStreamer gir files 2022-04-05 19:49:05 +00:00
Sebastian Dröge 72027a6d60 ci: Update image version 2022-04-05 19:49:05 +00:00
Sebastian Dröge 89837f0757 Update GStreamer gir files 2022-04-05 19:49:05 +00:00
Sebastian Dröge 8d03a0d032 gstreamer: Complete the Task bindings 2022-04-04 18:56:25 +03:00
Sebastian Dröge 715f7cd6c2 Update CHANGELOG.md for 0.18.7 2022-04-04 16:57:39 +03:00
Sebastian Dröge eed648831d video: Add various VideoFormatInfo/VideoInfo/VideoFrame helper API 2022-04-04 15:50:09 +03:00
Sebastian Dröge 4d002786ec gstreamer: Don't re-export traits from the crate root 2022-04-04 08:51:04 +00:00
Sebastian Dröge 73ab9054c4 Don't use unnecessary RefCell wrappers for FnMut callbacks
They don't add any safety as this is via unsafe code anyway and are not
needed to get mutable references in this context anyway, while adding a
bit of runtime overhead.
2022-04-03 11:15:19 +03:00
Sebastian Dröge 8908d4bc98 video: Add subclassing bindings for VideoAggregatorConvertPad 2022-04-01 11:04:08 +03:00
Sebastian Dröge 5c14350079 audio: Add subclassing bindings for audioaggregator 2022-04-01 11:04:08 +03:00
Sebastian Dröge e31e2ad9bd audio: Add audioaggregator bindings 2022-04-01 11:04:08 +03:00
Jan Alexander Steffens (heftig) b7afdd4dd0
gstreamer: Add TaskPool bindings and subclassing
Fixes: https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/issues/14
2022-03-30 23:01:21 +02:00
Jan Alexander Steffens (heftig) 44b2eba600
Update gir 2022-03-30 22:36:53 +02:00
Sebastian Dröge ae234bb01e examples: Implement gst::ChildProxy interface in cairo compositor example 2022-03-30 21:41:28 +03:00
Vivia Nikolaidou 2c7c46e153 .gitlab-ci.yml: Fix deprecated -Zinstrument-coverage switch 2022-03-30 16:39:16 +03:00
Alejandro González 69599e90d4 Fix macOS PKG_CONFIG_PATH in readme for GStreamer Binaries
I've just installed the latest 1.20.1 GStreamer .pkg on a macOS GitHub
Actions CI runner and it turns out that no
/Library/Frameworks/GStreamer.framework/Versions directory exists. A
/Library/Frameworks/GStreamer.framework/1.0 directory is installed
instead, which is more consistent with the GStreamer distributions for
other OSes, and works well enough to get pkg-config working.
2022-03-28 11:47:47 +02:00
Sebastian Dröge 07be60a22f Don't unnecessarily borrow dereferenced values explicitly
warning: this expression borrows a value the compiler would automatically borrow
  --> gstreamer-rtsp-server/src/rtsp_session_pool.rs:16:5
   |
16 |     (&mut *func.borrow_mut())(&from_glib_borrow(pool)).into_glib()
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^ help: change this to: `(*func.borrow_mut())`
   |
   = note: `#[warn(clippy::needless_borrow)]` on by default
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
2022-03-24 12:40:52 +02:00
Sebastian Dröge 208e1ef7a4 examples: Simplify cairo compositor example a bit and improve/add comments. 2022-03-23 10:27:08 +02:00
Sebastian Dröge 21dbe86c8e examples: Add a Cairo-based compositor example based on VideoAggregator 2022-03-22 19:00:32 +02:00
Sebastian Dröge c251ca5bc3 video: Add subclass bindings for VideoAggregator 2022-03-22 19:00:32 +02:00
Sebastian Dröge fbe0728da5 video: Add bindings for VideoAggregator 2022-03-22 19:00:32 +02:00
Sebastian Dröge 215cdfd548 video: Allow converting a VideoFrame into an FFI GstVideoFrame 2022-03-22 19:00:32 +02:00
Sebastian Dröge 2943c310cd base: Fix signature of Aggregator::connect_samples_selected()
The first argument is not a random aggregator type but the type that was
used to connect to the signal.
2022-03-22 19:00:32 +02:00
Philippe Normand cd2e3aa7f1 allocators: Fix manual ABI test
Fixing this build error:
In file included from tests/layout.c:6:
tests/manual.h:3:10: fatal error: gst/base/base.h: No such file or directory
    3 | #include <gst/base/base.h>
      |          ^~~~~~~~~~~~~~~~~
compilation terminated.
test cross_validate_layout_with_c ... FAILED
In file included from tests/constant.c:6:
tests/manual.h:3:10: fatal error: gst/base/base.h: No such file or directory
    3 | #include <gst/base/base.h>
      |          ^~~~~~~~~~~~~~~~~
2022-03-21 16:48:42 +00:00
Jordan Petridis e6dc3f5b3e ci: Patch the gtk4 build in the CI image so it builds
wayland-protocols 1.25 subproject fails to build on
debian 11, but in general switch subprojects to stable
branches.

Upstream MR:
https://gitlab.gnome.org/GNOME/gtk/-/merge_requests/4580
2022-03-17 18:05:13 +02:00
Sebastian Dröge 609a744d6c Regenerate autogenerated bindings 2022-03-17 18:05:13 +02:00
Sebastian Dröge 3fbe37a2ec video: Add VideoFormatInfo::extrapolate_stride() 2022-03-17 18:05:13 +02:00
Sebastian Dröge faa1311fcd video: Add VideoFormatInfo::has_subtiles() 2022-03-17 11:06:26 +02:00
Sebastian Dröge fe7850720c audio: Add new dither-threshold converter configuration 2022-03-17 11:06:26 +02:00
Sebastian Dröge 3080c37897 video: Ignore new navigation event constructors
And add doc aliases for the already existing manual implementations of
them.
2022-03-17 11:06:26 +02:00
Sebastian Dröge 1a11fda103 ci: Build crates with v1_22 2022-03-17 11:06:26 +02:00
Sebastian Dröge 12f1483d43 gstreamer: Create plugins with version 1.21 if v1_22 is selected 2022-03-17 11:06:26 +02:00
Sebastian Dröge 54440e47df Add v1_22 Cargo feature and map to the correct pkg-config version 2022-03-17 11:06:26 +02:00
Sebastian Dröge 2f55ffe419 Update GStreamer gir files 2022-03-17 11:06:26 +02:00
Sebastian Dröge 39e90b603b Update gir-files 2022-03-15 15:46:30 +02:00
Sebastian Dröge 6f2cd17232 Update gir 2022-03-15 15:46:30 +02:00
Sebastian Dröge a3b95d60ae ci: Update to meson 0.61.3, GTK 4.6 branch and rebuild GStreamer 2022-03-15 15:46:11 +02:00
Sebastian Dröge 4b3362039e Use SPDX license format in Cargo.toml 2022-03-14 10:21:49 +02:00
Christian Meissl 3234a18677 Use new memory type infrastructure in gstreamer-gl 2022-03-12 14:19:40 +00:00
Christian Meissl 389d406e73 Remove usage of _get_type in gstreamer-gl GLMemory
see: https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1764
2022-03-12 14:19:40 +00:00
Christian Meissl 163130cad7 Extend examples to showcase the use of the FdMemoryAllocator 2022-03-12 14:19:40 +00:00
Christian Meissl a8dc789ef8 Add crates for gstreamer-allocators 2022-03-12 14:19:40 +00:00
Christian Meissl 44d39f8824 Add infrastructure for casting from/to memory subtypes 2022-03-12 14:19:40 +00:00
Christian Meissl 240da14042 Drop extraneous extra_versions that already fall under min_cfg_version 2022-03-12 14:19:40 +00:00
Sebastian Dröge beb3ad2010 Update CHANGELOG.md for 0.18.6 2022-03-08 19:24:10 +02:00
Sebastian Dröge b69043d462 gstreamer: Require Send and not Sync for the values of an Array / List
`Sync` is more than required here: only sending of the values to another
thread is required.
2022-03-08 14:46:13 +02:00
Sebastian Dröge 1f7a0f29d9 gstreamer: Update for optional glib::Value type refactoring 2022-03-07 13:20:08 +02:00
Sebastian Dröge 0f22eb7633 Remove now unnecessary Send+Sync impls for element/etc subclasses
This is now automatically implemented.
2022-02-28 18:25:15 +02:00
Sebastian Dröge 319f1c68a5 gstreamer: Simplify and speed up log message string construction
For pre-1.20 simply use `%s` as format string instead of escaping the
`%` inline while writing. This allows a simpler implementation and is
also faster, see https://github.com/gtk-rs/gtk-rs-core/pull/583.
2022-02-26 13:33:00 +02:00
Sebastian Dröge ab04715dc7 ci: Update to Rust 1.59 2022-02-24 19:41:19 +02:00
Sebastian Dröge bf660cf22a Update minimum supported Rust version to 1.57 2022-02-22 00:00:39 +02:00
Sebastian Dröge fc1185b951 gstreamer: Add builders for the fraction/array paramspecs 2022-02-22 00:00:39 +02:00
François Laignel 972c4e75ac remove gst_ prefix for log macros
It's quite quite common to use similar macros in the form `log::debug!`
or `glib::clone!`. This MR renames the gst log macros so that we can
`gst::debug!` instead of `gst_debug!` and whithout the need for
`use gst::gst_debug`.
2022-02-21 18:56:06 +01:00
Sebastian Dröge ad1c2d83a4 Revert "rtsp-server: Add bindings for Onvif-specific client/media/media-factory/server"
This reverts commit bdac7cb99c.

This was applied twice.
2022-02-20 20:55:15 +02:00
Sebastian Dröge 40be06d5f6 Update CHANGELOG.md for 0.18.5 2022-02-20 20:27:56 +02:00
Sebastian Dröge bdac7cb99c rtsp-server: Add bindings for Onvif-specific client/media/media-factory/server
Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/issues/373
2022-02-18 17:00:02 +02:00
Sebastian Dröge b451f692cf rtsp-server: Add subclassing support for Onvif-specific client/media/media-factory/server 2022-02-18 14:00:52 +02:00
Sebastian Dröge 586fc75ffc rtsp-server: Add bindings for Onvif-specific client/media/media-factory/server
Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/issues/373
2022-02-18 14:00:52 +02:00
Marijn Suijten 462e19dee9 gstreamer/plugin_1_14: Use minor version 20 instead of 19 for v1_20
Now that gstreamer 1.20 is out all v1_20 plugins will be linked against
the 1.20 stable release, not the unstable 1.19 development release.
2022-02-18 11:33:17 +01:00
Marijn Suijten 2426d7ce8c Revert "sys: Link all v1_20 sys crates against library 1.19" - use 1.20
This reverts commit 8226c94110.

Now that GStreamer 1.20 is out, the v1_20 feature can and should link
directly to the stable release instead of the unstable 1.19 development
release.
2022-02-18 11:30:08 +01:00
Marijn Suijten 7ad71949d7 gstreamer/sys: Move v1_18_3 system-deps metadata above v1_20
Keep the versions sorted numerically.
2022-02-18 11:30:00 +01:00
Sebastian Dröge d68c359db5 gstreamer: Fix downcast_ref() / downcast_mut() impls on MiniObjectRef
They have to return the `Ref` type and not the owned type.
2022-02-16 12:13:19 +02:00
Sebastian Dröge a1fed48e8c gstreamer: Add Debug impl for MiniObject / MiniObjectRef 2022-02-16 12:13:03 +02:00
Sebastian Dröge d1f978f9f1 gstreamer: Improve StreamsSelectedBuilder::streams()
It's much easier to use if it takes any kind of iterator instead of a
slice of references.
2022-02-14 13:44:19 +02:00
Sebastian Dröge 98e12e835a examples: Update to image 0.24 2022-02-09 13:15:13 +02:00
Christian Meissl 033dac2270 support for subclassing buffer pool 2022-02-08 15:59:55 +01:00
Sebastian Dröge 0173b73170 Handle empty slices correctly
Passing `NULL` to `slice::from_raw_parts` is invalid.
2022-02-07 12:50:37 +02:00
Sebastian Dröge ddd4e3a79a Update README.md for 0.18.4 2022-02-04 18:44:51 +02:00
Christian Meissl 8ae97b8c64 fix readme doc links 2022-02-04 14:22:17 +01:00
Sebastian Dröge 47ae1c8658 Regenerate with latest gir files 2022-02-04 12:35:01 +02:00
Sebastian Dröge 899703fb8e Update GStreamer gir files 2022-02-04 12:33:29 +02:00
Sebastian Dröge 2176e17add Update gir-files 2022-02-04 12:30:15 +02:00
Sebastian Dröge 70e95d4576 ci: Update to get GStreamer 1.20.0 release 2022-02-04 12:24:09 +02:00
Sebastian Dröge 4956346b23 video: Allow getting an owned reference to the input buffer from a video codec frame 2022-02-02 00:54:06 +02:00
Sebastian Dröge 74557132e1 deny: Remove heck override as all dependencies are up to date now 2022-01-31 15:06:31 +02:00
Sebastian Dröge 7d1e7478ac Update CHANGELOG.md for 0.18.3 2022-01-31 15:01:41 +02:00
Sebastian Dröge 23565c8723 ci: Update GStreamer version 2022-01-29 18:18:13 +02:00
Sebastian Dröge deced8b3b8 Regenerate with latest GStreamer gir files 2022-01-29 18:17:26 +02:00
Sebastian Dröge cb5edb1e5b webrtc: Generate WebRTCError type 2022-01-29 18:17:26 +02:00
Sebastian Dröge fb49d26b11 Update gst-gir-files 2022-01-29 18:17:26 +02:00
Sebastian Dröge 0dc1ee439f rtp: Add subclass bindings for RTPHeaderExtension 2022-01-27 15:32:44 +02:00
Sebastian Dröge 0403fd9aa4 rtp: Re-export standalone functions from crate root 2022-01-27 14:33:46 +02:00
Sebastian Dröge 7ccab6cc8b rtp: Add gst::Element as parent class for RTPHeaderExtension 2022-01-27 14:33:21 +02:00
Sebastian Dröge 60cd874db7 video: Add VideoOverlayComposition::add_rectangle() to add new rectangles after construction
Usually it is more convenient to provide them all via an iterator during
construction but in some cases this might be nicer.
2022-01-26 13:04:08 +02:00
Sebastian Dröge 52e09fd83d video: Implement Default for VideoOverlayComposition in 1.20 2022-01-26 13:04:08 +02:00
Sebastian Dröge a734f38ee6 ci: Update image to get newer GStreamer build 2022-01-25 13:20:58 +02:00
Sebastian Dröge 26f2ed30ae Regenerate with latest gst-gir-files 2022-01-25 13:10:58 +02:00
Sebastian Dröge 15763a941b Update gst-gir-files 2022-01-25 13:10:35 +02:00
Sebastian Dröge 06cf5de45f Get rid of fragile dependency and use GLib API instead 2022-01-24 19:33:15 +02:00
Sebastian Dröge 13eb483444 Regenerate everything with latest gir 2022-01-24 19:29:18 +02:00
Sebastian Dröge 03ad59f006 Update gir 2022-01-24 19:27:56 +02:00
Sebastian Dröge bb94064e11 Update CHANGELOG.md for 0.18.2 2022-01-24 16:47:36 +02:00
Sebastian Dröge 1ebfaee644 examples: Make use of glib::closure! for the overlay-composition example 2022-01-24 13:13:24 +00:00
Sebastian Dröge eecce101da gstreamer: Implement FromValue for mini object references 2022-01-24 13:13:24 +00:00
Sebastian Dröge b66a00ed07 gstreamer: Minor cleanup 2022-01-24 14:48:36 +02:00
Sebastian Dröge ab0eb8a1a4 gstreamer: Add bindings for gst_debug_log_get_line() 2022-01-24 14:48:21 +02:00
Sebastian Dröge 5e2249d368 message/query/event: Implement views in a more consistent way
Co-authored-by: Jan Alexander Steffens (heftig) <jan.steffens@ltnglobal.com>
2022-01-19 13:29:59 +02:00
Sebastian Dröge 65c833bc80 Update CHANGELOG.md for 0.18.1 2022-01-18 16:54:57 +02:00
Sebastian Dröge 68d492bb33 gstreamer: Mark Structure and CapsFeatures as #[repr(transparent)] too 2022-01-17 19:42:20 +00:00
Jan Alexander Steffens (heftig) fb56bbda6e gstreamer: Split parsers for owned and borrowed views
When we have a view like `Caps<&EventRef>`, we can return a `CapsRef`
borrowing from the wrapped `EventRef`. This way, the `CapsRef` we return
can outlive the view itself.

This is in contrast to a `Caps<Event>` view which owns the `Event`.
Here, the `CapsRef` we return cannot outlive the view.

gstreamer-rs 0.18 consolidated code and treated everything like the
latter case. Fix this by duplicating the accessors for each case.

Fixes: https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/issues/367
2022-01-17 19:13:47 +00:00
Sebastian Dröge ee9157a239 video: Mark VideoTimeCode as #[repr(transparent)] 2022-01-17 18:04:40 +00:00
Sebastian Dröge 8f5e373882 gstreamer: Mark miniobject wrapper types as #[repr(transparent)]
That way they're treated everywhere exactly like a raw pointer.
2022-01-17 18:04:40 +00:00
Sebastian Dröge 8fa1076dfa Replace Foo::from_instance(foo) with foo.imp() 2022-01-17 19:34:06 +02:00
Sebastian Dröge 971f35754c Change default branch from master to main
Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/issues/364
2022-01-16 16:15:48 +02:00
Sebastian Dröge 8b09a84bf1 Update CHANGELOG.md for 0.18.0 2022-01-16 13:36:18 +02:00
Sebastian Dröge 22a86a66b4 Update CHANGELOG.md for 0.17.4 2022-01-16 12:17:18 +02:00
Sebastian Dröge 5a9b103f93 docs: Add 0.18 release 2022-01-15 21:40:51 +02:00
Sebastian Dröge 7444975421 Update versions to 0.19.0 2022-01-15 20:21:53 +02:00
Sebastian Dröge ce1a25a128 examples: overlay-composition: Use cairo's new ImageSurfaceDataOwned to get rid of unsafe code 2022-01-14 21:47:08 +02:00
1171 changed files with 97478 additions and 42117 deletions

1
.gitignore vendored
View file

@ -1,3 +1,2 @@
target/
**/*.rs.bk
Cargo.lock

View file

@ -17,7 +17,7 @@
# Updating the nightly image should be done by simply running a scheduled ci
# pipeline on the upstream repo with the $UPDATE_NIGHTLY variable defined.
.templates_sha: &templates_sha 567700e483aabed992d0a4fea84994a0472deff6
.templates_sha: &templates_sha b2e24205598dc1d80b5f2c88cf7618051e30e9fd
include:
- project: 'freedesktop/ci-templates'
@ -28,6 +28,7 @@ include:
workflow:
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
- if: $CI_MERGE_REQUEST_IID
# don't create a pipeline if its a commit pipeline, on a branch and that branch has
# open merge requests (bc we will get a MR build instead)
@ -36,19 +37,29 @@ workflow:
- if: $CI_COMMIT_TAG
- if: $CI_COMMIT_BRANCH
default:
interruptible: true
variables:
FDO_UPSTREAM_REPO: gstreamer/gstreamer-rs
RUST_DOCS_FLAGS: "--extern-html-root-url=muldiv=https://docs.rs/muldiv/1.0.0/muldiv/ -Z unstable-options"
# DIY CI-templates like setup for windows
WINDOWS_RUST_MINIMUM_IMAGE: "$CI_REGISTRY_IMAGE/windows:$GST_RS_IMG_TAG-main-$GST_RS_MSRV"
WINDOWS_RUST_MINIMUM_UPSTREAM_IMAGE: "$CI_REGISTRY/$FDO_UPSTREAM_REPO/windows:$GST_RS_IMG_TAG-main-$GST_RS_MSRV"
WINDOWS_RUST_STABLE_IMAGE: "$CI_REGISTRY_IMAGE/windows:$GST_RS_IMG_TAG-main-$GST_RS_STABLE"
WINDOWS_RUST_STABLE_UPSTREAM_IMAGE: "$CI_REGISTRY/$FDO_UPSTREAM_REPO/windows:$GST_RS_IMG_TAG-main-$GST_RS_STABLE"
RUST_DOCS_FLAGS: "--cfg docsrs --extern-html-root-url=muldiv=https://docs.rs/muldiv/1.0.0/muldiv/ -Z unstable-options --generate-link-to-definition"
NAMESPACE: gstreamer
# format is <branch>=<name>
# the name is used in the URL
# latest release must be at the top
# (only relevant on master branch)
# (only relevant on main branch)
RELEASES:
0.17=0.17
0.16=0.16
0.22=0.22
stages:
- "trigger"
- "container-base"
- "container-final"
- "lint"
@ -56,41 +67,56 @@ stages:
- "extras"
- "deploy"
.debian:11:
# This is an empty job that is used to trigger the pipeline.
trigger:
image: alpine:latest
stage: 'trigger'
variables:
FDO_DISTRIBUTION_VERSION: 'bullseye-slim'
GIT_STRATEGY: none
tags: [ 'placeholder-job' ]
script:
- echo "Trigger job done, now running the pipeline."
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
# If the MR is assigned to the Merge bot, trigger the pipeline automatically
- if: '$CI_MERGE_REQUEST_ASSIGNEES == "gstreamer-merge-bot"'
# Require explicit action to trigger tests post merge
- if: '$CI_PROJECT_NAMESPACE == "gstreamer" && $CI_COMMIT_BRANCH == "main"'
when: 'manual'
# When the assignee isn't the merge bot, require an explicit action to trigger the pipeline
# to avoid wasting CI resources
- if: '$CI_MERGE_REQUEST_ASSIGNEES != "gstreamer-merge-bot"'
when: 'manual'
allow_failure: false
.debian:12:
needs: []
variables:
FDO_DISTRIBUTION_VERSION: 'bookworm-slim'
before_script:
- source ./ci/env.sh
- mkdir .cargo && echo -e "[net]\ngit-fetch-with-cli = true" > .cargo/config
# If cargo exists assume we probably will want to update
# the lockfile
- |
if command -v cargo; then
cargo generate-lockfile --color=always
cargo update --color=always
fi
.debian:11-base:
extends: .debian:11
.debian:12-base:
extends: .debian:12
variables:
FDO_DISTRIBUTION_TAG: 'base-$GST_RS_IMG_TAG'
.debian:11-stable:
extends: .debian:11
.debian:12-stable:
extends: .debian:12
variables:
RUST_IMAGE_FULL: "1"
FDO_DISTRIBUTION_TAG: '$GST_RS_STABLE-$GST_RS_IMG_TAG'
FDO_DISTRIBUTION_EXEC: 'bash ci/install-rust.sh $GST_RS_STABLE $RUST_IMAGE_FULL'
.debian:11-msrv:
extends: .debian:11
.debian:12-msrv:
extends: .debian:12
variables:
FDO_DISTRIBUTION_TAG: '$GST_RS_MSRV-$GST_RS_IMG_TAG'
FDO_DISTRIBUTION_EXEC: 'bash ci/install-rust.sh $GST_RS_MSRV $RUST_IMAGE_FULL'
.debian:11-nightly:
extends: .debian:11
.debian:12-nightly:
extends: .debian:12
variables:
FDO_DISTRIBUTION_TAG: 'nightly-$GST_RS_IMG_TAG'
FDO_DISTRIBUTION_EXEC: 'bash ci/install-rust.sh nightly $RUST_IMAGE_FULL'
@ -100,44 +126,63 @@ stages:
- .fdo.container-build@debian
stage: container-base
variables:
FDO_DISTRIBUTION_PACKAGES: "build-essential curl python3-setuptools liborc-0.4-dev libglib2.0-dev libxml2-dev libgtk-3-dev libegl1-mesa libgles2-mesa libgl1-mesa-dri libgl1-mesa-glx libwayland-egl1-mesa xz-utils libssl-dev git wget ca-certificates ninja-build python3-pip flex bison libglib2.0-dev libx11-dev libx11-xcb-dev libsoup2.4-dev libvorbis-dev libogg-dev libtheora-dev libmatroska-dev libvpx-dev libopus-dev libgraphene-1.0-dev"
FDO_DISTRIBUTION_PACKAGES: >-
build-essential curl python3-setuptools libglib2.0-dev libxml2-dev
libdrm-dev libegl1-mesa-dev libgl1-mesa-dev libgbm-dev libgles2-mesa-dev
libgl1-mesa-dri libegl-dev libgl1-mesa-glx libwayland-egl1-mesa xz-utils
libssl-dev git wget ca-certificates ninja-build python3-pip flex bison
libglib2.0-dev libx11-dev libx11-xcb-dev libsoup2.4-dev libvorbis-dev
libogg-dev libtheora-dev libmatroska-dev libvpx-dev libopus-dev
libgraphene-1.0-dev libjpeg-dev libwayland-dev wayland-protocols
python3-gi libavcodec-dev libavformat-dev libavutil-dev libavfilter-dev
libswscale-dev yasm libx264-dev libfontconfig-dev libfreetype-dev
libxkbcommon-dev libxi-dev libxcb-render0-dev libxcb-shm0-dev
libxcb1-dev libxext-dev libxrender-dev libxrandr-dev libxcursor-dev
libxdamage-dev libxfixes-dev libxinerama-dev libgudev-1.0-dev
libpango1.0-dev libcairo2-dev libjson-glib-dev libgdk-pixbuf-2.0-dev
libtiff-dev libpng-dev libjpeg-dev libepoxy-dev libsass-dev sassc
libcsound64-dev llvm clang nasm libsodium-dev libwebp-dev
libflac-dev
FDO_DISTRIBUTION_EXEC: >-
bash ci/install-gst.sh &&
bash ci/install-gtk4.sh &&
pip3 install git+http://gitlab.freedesktop.org/freedesktop/ci-templates
bash ci/install-dav1d.sh &&
pip3 install --break-system-packages git+http://gitlab.freedesktop.org/freedesktop/ci-templates &&
pip3 install --break-system-packages tomli
.build-final-image:
extends:
- .fdo.container-build@debian
stage: container-final
variables:
FDO_BASE_IMAGE: '$CI_REGISTRY_IMAGE/debian/bullseye-slim:base-$GST_RS_IMG_TAG'
FDO_BASE_IMAGE: '$CI_REGISTRY_IMAGE/debian/bookworm-slim:base-$GST_RS_IMG_TAG'
build-base:
extends:
- .build-base-image
- .debian:11-base
- .debian:12-base
build-stable:
needs: ["build-base"]
extends:
- .build-final-image
- .debian:11-stable
- .debian:12-stable
build-msrv:
needs: ["build-base"]
extends:
- .build-final-image
- .debian:11-msrv
- .debian:12-msrv
build-nightly:
needs: ["build-base"]
extends:
- .build-final-image
- .debian:11-nightly
- .debian:12-nightly
update-nightly:
extends: build-nightly
only:
variables:
- $UPDATE_NIGHTLY == "1"
rules:
- if: $UPDATE_NIGHTLY == "1"
variables:
FDO_FORCE_REBUILD: 1
@ -149,103 +194,21 @@ update-nightly:
.img-stable:
extends:
- .debian:11-stable
- .debian:12-stable
- .dist-debian-container
.img-msrv:
extends:
- .debian:11-msrv
- .debian:12-msrv
- .dist-debian-container
.img-nightly:
extends:
- .debian:11-nightly
- .debian:12-nightly
- .dist-debian-container
# GST_PLUGINS_RS_TOKEN is a variable of type 'Var' defined in gstreamer-rs CI
# settings and containing a gst-plugins-rs pipeline trigger token
.plugins-update:
stage: deploy
script:
- |
# FDO_DISTRIBUTION_IMAGE still has indirections
- echo $FDO_DISTRIBUTION_IMAGE
- DISTRO_IMAGE=$(eval echo ${FDO_DISTRIBUTION_IMAGE})
- echo $DISTRO_IMAGE
# retrieve the infos from the registry
- JSON_IMAGE=$(skopeo inspect docker://$DISTRO_IMAGE)
- IMAGE_PIPELINE_ID=$(echo $JSON_IMAGE | jq -r '.Labels["fdo.pipeline_id"]')
- echo $IMAGE_PIPELINE_ID
- echo $CI_PIPELINE_ID
- |
if [[ x"$IMAGE_PIPELINE_ID" == x"$CI_PIPELINE_ID" ]]; then
echo "Image has been updated, notify gst-plugins-rs"
curl -X POST -F "token=$GST_PLUGINS_RS_TOKEN" -F "ref=master" -F "variables[UPDATE_IMG]=$UPDATE_IMG" https://gitlab.freedesktop.org/api/v4/projects/1400/trigger/pipeline
else
echo "Image has not been updated, ignore"
fi
rules:
- if: '$CI_COMMIT_REF_NAME == "master" && $CI_PROJECT_PATH == "gstreamer/gstreamer-rs"'
# Those jobs need to use another image as ours doesn't have 'skopeo'
# and it's not easily installable in Debian stable for now.
plugins-update-stable:
extends:
- .plugins-update
- .img-stable
image: quay.io/freedesktop.org/ci-templates:container-build-base-2021-07-29.0
variables:
UPDATE_IMG: "stable"
plugins-update-msrv:
extends:
- .plugins-update
- .img-msrv
image: quay.io/freedesktop.org/ci-templates:container-build-base-2021-07-29.0
variables:
UPDATE_IMG: "msrv"
plugins-update-nightly:
extends:
- .plugins-update
- .img-nightly
image: quay.io/freedesktop.org/ci-templates:container-build-base-2021-07-29.0
variables:
UPDATE_IMG: "nightly"
.cargo_test_var: &cargo_test
- rustc --version
# First build and test all the crates with their relevant features
# Keep features in sync with below
- |
get_features() {
crate=$1
if [ "$crate" = "gstreamer" ]; then
echo "--features=ser_de,v1_20"
else
echo "--features=v1_20"
fi
}
for crate in gstreamer* gstreamer-gl/{egl,wayland,x11}; do
if [ -e $crate/Cargo.toml ]; then
if [ -n "$ALL_FEATURES" ]; then
FEATURES="$(get_features $crate)"
else
FEATURES=""
fi
echo "Building and testing $crate with $FEATURES"
cargo build --locked --color=always --manifest-path $crate/Cargo.toml $FEATURES
G_DEBUG=fatal_warnings cargo test --color=always --manifest-path $crate/Cargo.toml $FEATURES
fi
done
- |
if [ -n "$EXAMPLES_TUTORIALS" ]; then
cargo build --locked --color=always --manifest-path examples/Cargo.toml --bins --examples --all-features
cargo build --locked --color=always --manifest-path tutorials/Cargo.toml --bins --examples --all-features
fi
- ./ci/run-cargo-test.sh
.cargo test:
stage: "test"
@ -256,11 +219,21 @@ test msrv:
extends:
- '.cargo test'
- .img-msrv
needs:
- job: 'trigger'
artifacts: false
- job: 'build-msrv'
artifacts: false
test stable:
extends:
- '.cargo test'
- .img-stable
needs:
- job: 'trigger'
artifacts: false
- job: 'build-stable'
artifacts: false
test stable all-features:
variables:
@ -269,12 +242,24 @@ test stable all-features:
extends:
- '.cargo test'
- .img-stable
needs:
- job: 'trigger'
artifacts: false
- job: 'build-stable'
artifacts: false
test nightly:
allow_failure: true
extends:
- '.cargo test'
- .img-nightly
needs:
- job: 'trigger'
artifacts: false
- job: 'build-nightly'
artifacts: false
test nightly all-features:
allow_failure: true
@ -284,166 +269,142 @@ test nightly all-features:
extends:
- '.cargo test'
- .img-nightly
needs:
- job: 'trigger'
artifacts: false
- job: 'build-nightly'
artifacts: false
.cargo test sys:
stage: "test"
script:
- rustc --version
- |
get_features() {
module=${1%%/sys}
echo "--features=v1_20"
}
# First build and test all the crates with their relevant features
# Keep features in sync with below
for crate in gstreamer*/sys gstreamer-gl/*/sys; do
if [ -e $crate/Cargo.toml ]; then
echo "Building $crate with $(get_features $crate)"
cargo build --locked --color=always --manifest-path $crate/Cargo.toml $(get_features $crate)
fi
done
# Run tests for crates we can currently run.
# Other tests are broken currently.
for crate in gstreamer/sys \
gstreamer-app/sys \
gstreamer-audio/sys \
gstreamer-base/sys \
gstreamer-check/sys \
gstreamer-controller/sys \
gstreamer-gl/sys \
gstreamer-gl/egl/sys \
gstreamer-gl/wayland/sys \
gstreamer-gl/x11/sys \
gstreamer-mpegts/sys \
gstreamer-net/sys \
gstreamer-pbutils/sys \
gstreamer-player/sys \
gstreamer-rtsp-server/sys \
gstreamer-rtsp/sys \
gstreamer-sdp/sys \
gstreamer-tag/sys \
gstreamer-video/sys \
gstreamer-webrtc/sys; do
echo "Testing $crate with $(get_features $crate)"
cargo test --locked --color=always --manifest-path $crate/Cargo.toml $(get_features $crate)
done
- ./ci/run-sys-cargo-test.sh
test stable sys:
extends:
- '.cargo test sys'
- .img-stable
needs:
- job: 'trigger'
artifacts: false
- job: 'build-stable'
artifacts: false
test msrv sys:
extends:
- '.cargo test sys'
- .img-msrv
needs:
- job: 'trigger'
artifacts: false
- job: 'build-msrv'
artifacts: false
test nightly sys:
extends:
- '.cargo test sys'
- .img-nightly
needs:
- job: 'trigger'
artifacts: false
- job: 'build-nightly'
artifacts: false
rustfmt:
extends: .img-stable
stage: "lint"
tags: [ 'placeholder-job' ]
script:
- cargo fmt --version
- cargo fmt -- --color=always --check
needs:
- job: 'build-stable'
artifacts: false
check commits:
extends: .img-stable
stage: "lint"
tags: [ 'placeholder-job' ]
script:
- ci-fairy check-commits --textwidth 0 --no-signed-off-by
needs:
- job: 'build-stable'
artifacts: false
typos:
extends: .img-stable
stage: "lint"
tags: [ 'placeholder-job' ]
script:
- typos
needs:
- job: 'build-stable'
artifacts: false
clippy:
extends: .img-stable
stage: 'extras'
variables:
CLIPPY_LINTS: -D warnings
CLIPPY_LINTS: -D warnings -W unknown-lints
needs:
- job: 'trigger'
artifacts: false
- job: 'build-stable'
artifacts: false
script:
- cargo clippy --version
# Keep features in sync with above
- |
get_features() {
crate=$1
if [ "$crate" = "gstreamer" ]; then
echo "--features=ser_de,v1_20"
else
echo "--features=v1_20"
fi
}
for crate in gstreamer* gstreamer-gl/{egl,wayland,x11}; do
if [ -e $crate/Cargo.toml ]; then
FEATURES=$(get_features $crate)
echo "Running clippy on $crate with $FEATURES"
cargo clippy --locked --color=always --manifest-path $crate/Cargo.toml $FEATURES --all-targets -- $CLIPPY_LINTS
fi
done
# And also run over all the examples/tutorials
- |
cargo clippy --locked --color=always --manifest-path examples/Cargo.toml --all-targets --all-features -- $CLIPPY_LINTS
cargo clippy --locked --color=always --manifest-path tutorials/Cargo.toml --all-targets --all-features -- $CLIPPY_LINTS
- ./ci/run-clippy.sh
deny:
extends: .img-stable
stage: 'extras'
only:
- schedules
needs:
- job: 'build-stable'
artifacts: false
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
script:
- cargo deny --color=always check
- cargo update --color=always
- cargo deny --color=always --workspace --all-features check all
gir-checks:
variables:
GIT_SUBMODULE_STRATEGY: recursive
extends: .img-stable
stage: 'extras'
tags: [ 'placeholder-job' ]
needs:
- job: 'build-stable'
artifacts: false
script:
- git diff --exit-code
- git clone --depth 1 https://github.com/gtk-rs/checker
- git diff --exit-code
- cd checker && echo '[workspace]' >> Cargo.toml
- cd .. && git diff --exit-code && cd checker
- cargo build --locked --color=always --release
- cd .. && git diff --exit-code && cd checker
- |
cargo run --color=always --release -- ../gstreamer* ../gstreamer-gl/{egl,wayland,x11}
- cd .. && git diff --exit-code && cd checker
# Check doc aliases
- |
for crate in ../gstreamer* ../gstreamer-gl/{egl,wayland,x11}; do
echo '--> Checking doc aliases in ' $crate
python3 doc_aliases.py $crate
done
- cd ..
# To ensure that there was no missing #[doc(alias = "...")]
- git diff --exit-code
- |
for crate in gstreamer* gstreamer-gl/{egl,wayland,x11}; do
echo '-->' $crate
./checker/check_init_asserts $crate
done
- git diff --exit-code
- git submodule update --checkout
- python3 ci/gir-checks.py
outdated:
extends: .img-stable
stage: 'extras'
only:
- schedules
needs:
- job: 'build-stable'
artifacts: false
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
script:
- cargo update --color=always
- cargo outdated --color=always --root-deps-only --exit-code 1 -v
coverage:
allow_failure: true
extends:
- '.cargo test'
- .img-nightly
- .img-stable
stage: 'extras'
needs:
- job: 'trigger'
artifacts: false
- job: 'build-stable'
artifacts: false
variables:
ALL_FEATURES: 'yes'
RUSTFLAGS: "-Zinstrument-coverage"
RUSTFLAGS: "-Cinstrument-coverage"
LLVM_PROFILE_FILE: "gstreamer-rs-%p-%m.profraw"
script:
- *cargo_test
@ -458,31 +419,56 @@ coverage:
paths:
- 'coverage'
reports:
cobertura: coverage.xml
coverage_report:
coverage_format: cobertura
path: coverage.xml
doc-stripping:
variables:
GIT_SUBMODULE_STRATEGY: recursive
extends: .img-nightly
stage: 'extras'
needs:
- job: 'build-nightly'
artifacts: false
script:
- PATH=~/.cargo/bin/:$PATH ./generator.py --gir-files-directories gir-files gst-gir-files --strip-docs --no-fmt
- git submodule update --checkout
- PATH=~/.cargo/bin/:$PATH ./generator.py --gir-files-directories gir-files gst-gir-files --embed-docs
- PATH=~/.cargo/bin/:$PATH ./generator.py --gir-files-directories gir-files gst-gir-files --strip-docs
- git diff --quiet || (echo 'Files changed after running `rustdoc-stripper -s`, make sure all documentation is protected with `// rustdoc-stripper-ignore-next`!'; git diff; false)
regen-check:
variables:
GIT_SUBMODULE_STRATEGY: recursive
extends: .img-nightly
stage: 'extras'
needs:
- job: 'build-nightly'
artifacts: false
script:
- git submodule update --checkout
- PATH=~/.cargo/bin/:$PATH ./generator.py --gir-files-directories gir-files gst-gir-files --yes
- git diff --quiet || (echo 'Files changed after running `generator.py`, make sure all submodules and generated files are in the correct version!'; git diff; false)
docs:
variables:
GIT_SUBMODULE_STRATEGY: recursive
extends: .img-nightly
stage: 'extras'
needs:
- job: 'build-nightly'
artifacts: false
script:
- git submodule update --checkout
- curl --proto '=https' --tlsv1.2 -sSf -o gir-rustdoc.py
https://gitlab.gnome.org/World/Rust/gir-rustdoc/-/raw/main/gir-rustdoc.py
- chmod +x gir-rustdoc.py
- PATH=~/.cargo/bin/:$PATH ./generator.py --gir-files-directories gir-files gst-gir-files --embed-docs --no-fmt
- |
RUSTDOCFLAGS="$RUST_DOCS_FLAGS"
RUSTFLAGS="--cfg docsrs"
eval $(./gir-rustdoc.py pre-docs)
cargo +nightly doc --workspace --exclude examples --exclude tutorials --color=always --features=dox --no-deps
cargo +nightly doc --workspace --exclude examples --exclude tutorials --all-features --color=always --no-deps
- mv target/doc docs
artifacts:
paths:
@ -495,8 +481,8 @@ docs:
pages:
extends: .img-nightly
stage: 'deploy'
dependencies:
- docs
needs: [ 'docs' ]
interruptible: false
script:
- curl --proto '=https' --tlsv1.2 -sSf -o gir-rustdoc.py
https://gitlab.gnome.org/World/Rust/gir-rustdoc/-/raw/main/gir-rustdoc.py
@ -514,3 +500,84 @@ pages:
rules:
- if: ($CI_DEFAULT_BRANCH == $CI_COMMIT_BRANCH) && ($CI_PROJECT_NAMESPACE == $NAMESPACE)
when: 'manual'
.windows rust docker build:
stage: 'container-final'
timeout: '2h'
needs: []
variables:
# Unlike the buildah/linux jobs, this file
# needs to be relative to windows-docker/ subdir
# as it makes life easier in the powershell script
#
# We also don't need a CONTEXT_DIR var as its also
# hardcoded to be windows-docker/
DOCKERFILE: 'ci/windows-docker/Dockerfile'
tags:
- 'windows'
- 'shell'
- '2022'
script:
# We need to pass an array and to resolve the env vars, so we can't use a variable:
- $DOCKER_BUILD_ARGS = @("--build-arg", "DEFAULT_BRANCH=$GST_UPSTREAM_BRANCH", "--build-arg", "RUST_VERSION=$RUST_VERSION")
- "& ci/windows-docker/container.ps1 $CI_REGISTRY $CI_REGISTRY_USER $CI_REGISTRY_PASSWORD $RUST_IMAGE $RUST_UPSTREAM_IMAGE $DOCKERFILE"
- |
if (!($?)) {
echo "Failed to build the image"
Exit 1
}
windows rust docker stable:
extends: '.windows rust docker build'
variables:
RUST_IMAGE: !reference [variables, "WINDOWS_RUST_STABLE_IMAGE"]
RUST_UPSTREAM_IMAGE: !reference [variables, "WINDOWS_RUST_STABLE_UPSTREAM_IMAGE"]
RUST_VERSION: !reference [variables, "GST_RS_STABLE"]
windows rust docker msrv:
extends: '.windows rust docker build'
when: 'manual'
variables:
RUST_IMAGE: !reference [variables, "WINDOWS_RUST_MINIMUM_IMAGE"]
RUST_UPSTREAM_IMAGE: !reference [variables, "WINDOWS_RUST_MINIMUM_UPSTREAM_IMAGE"]
RUST_VERSION: !reference [variables, "GST_RS_MSRV"]
.msvc2019 build:
stage: 'test'
tags:
- 'docker'
- 'windows'
- '2022'
script:
# Skip -sys tests as they don't work
# https://github.com/gtk-rs/gtk3-rs/issues/54
#
# We need to build each crate separately to avoid crates like -egl,-wayland etc on windows
- cmd.exe /C "C:\BuildTools\Common7\Tools\VsDevCmd.bat -host_arch=amd64 -arch=amd64 &&
powershell ./ci/run_windows_tests.ps1"
- |
if (!$?) {
Write-Host "Tests Failed!"
Exit 1
}
test windows msrv:
image: $WINDOWS_RUST_MINIMUM_IMAGE
needs:
- job: 'trigger'
artifacts: false
- job: 'windows rust docker msrv'
artifacts: false
extends: '.msvc2019 build'
test windows stable:
needs:
- job: 'trigger'
artifacts: false
- job: 'windows rust docker stable'
artifacts: false
image: "$WINDOWS_RUST_STABLE_IMAGE"
extends: '.msvc2019 build'

View file

@ -0,0 +1,33 @@
### Describe your issue
<!-- a clear and concise summary of the bug. -->
<!-- For any GStreamer usage question, please contact the community using the #gstreamer channel on IRC https://www.oftc.net/ or the mailing list on https://gstreamer.freedesktop.org/lists/ -->
#### Expected Behavior
<!-- What did you expect to happen -->
#### Observed Behavior
<!-- What actually happened -->
#### Setup
- **Operating System:**
- **Device:** Computer / Tablet / Mobile / Virtual Machine <!-- Delete as appropriate !-->
- **gstreamer-rs Version:**
- **GStreamer Version:**
- **Command line:**
### Steps to reproduce the bug
<!-- please fill in exact steps which reproduce the bug on your system, for example: -->
1. open terminal
2. type `command`
### How reproducible is the bug?
<!-- The reproducibility of the bug is Always/Intermittent/Only once after doing a very specific set of steps-->
### Screenshots if relevant
### Solutions you have tried
### Related non-duplicate issues
### Additional Information
<!-- Any other information such as logs. Make use of <details> for long output -->

3
.gitmodules vendored
View file

@ -1,9 +1,12 @@
[submodule "gir"]
path = gir
url = https://github.com/gtk-rs/gir
update = none
[submodule "gir-files"]
path = gir-files
url = https://github.com/gtk-rs/gir-files
update = none
[submodule "gst-gir-files"]
path = gst-gir-files
url = https://gitlab.freedesktop.org/gstreamer/gir-files-rs.git
update = none

3067
Cargo.lock generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -1,7 +1,55 @@
[workspace]
resolver = "2"
default-members = [
"gstreamer/sys",
"gstreamer-analytics/sys",
"gstreamer-app/sys",
"gstreamer-audio/sys",
"gstreamer-base/sys",
"gstreamer-check/sys",
"gstreamer-controller/sys",
"gstreamer-editing-services/sys",
"gstreamer-mpegts/sys",
"gstreamer-net/sys",
"gstreamer-pbutils/sys",
"gstreamer-play/sys",
"gstreamer-player/sys",
"gstreamer-rtp/sys",
"gstreamer-rtsp/sys",
"gstreamer-rtsp-server/sys",
"gstreamer-sdp/sys",
"gstreamer-tag/sys",
"gstreamer-video/sys",
"gstreamer-webrtc/sys",
"gstreamer",
"gstreamer-analytics",
"gstreamer-app",
"gstreamer-audio",
"gstreamer-base",
"gstreamer-check",
"gstreamer-controller",
"gstreamer-editing-services",
"gstreamer-mpegts",
"gstreamer-net",
"gstreamer-pbutils",
"gstreamer-play",
"gstreamer-player",
"gstreamer-rtp",
"gstreamer-rtsp",
"gstreamer-rtsp-server",
"gstreamer-sdp",
"gstreamer-tag",
"gstreamer-validate",
"gstreamer-video",
"gstreamer-webrtc",
"examples",
"tutorials",
]
members = [
"gstreamer/sys",
"gstreamer-analytics/sys",
"gstreamer-app/sys",
"gstreamer-audio/sys",
"gstreamer-base/sys",
@ -15,6 +63,7 @@ members = [
"gstreamer-mpegts/sys",
"gstreamer-net/sys",
"gstreamer-pbutils/sys",
"gstreamer-play/sys",
"gstreamer-player/sys",
"gstreamer-rtp/sys",
"gstreamer-rtsp/sys",
@ -23,7 +72,9 @@ members = [
"gstreamer-tag/sys",
"gstreamer-video/sys",
"gstreamer-webrtc/sys",
"gstreamer-allocators/sys",
"gstreamer",
"gstreamer-analytics",
"gstreamer-app",
"gstreamer-audio",
"gstreamer-base",
@ -34,17 +85,68 @@ members = [
"gstreamer-gl/egl",
"gstreamer-gl/wayland",
"gstreamer-gl/x11",
"gstreamer-mpegts",
"gstreamer-net",
"gstreamer-pbutils",
"gstreamer-play",
"gstreamer-player",
"gstreamer-rtp",
"gstreamer-rtsp",
"gstreamer-rtsp-server",
"gstreamer-sdp",
"gstreamer-tag",
"gstreamer-validate",
"gstreamer-video",
"gstreamer-webrtc",
"gstreamer-allocators",
"gstreamer-utils",
"examples",
"tutorials",
]
exclude = ["gir"]
[workspace.package]
version = "0.23.0"
categories = ["api-bindings", "multimedia"]
repository = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs"
homepage = "https://gstreamer.freedesktop.org"
edition = "2021"
rust-version = "1.70"
[workspace.dependencies]
gio = { git = "https://github.com/gtk-rs/gtk-rs-core", branch = "master" }
gio-sys = { git = "https://github.com/gtk-rs/gtk-rs-core", branch = "master" }
glib = { git = "https://github.com/gtk-rs/gtk-rs-core", branch = "master" }
glib-sys = { git = "https://github.com/gtk-rs/gtk-rs-core", branch = "master" }
gobject-sys = { git = "https://github.com/gtk-rs/gtk-rs-core", branch = "master" }
cairo-rs = { git = "https://github.com/gtk-rs/gtk-rs-core", branch = "master" }
pango = { git = "https://github.com/gtk-rs/gtk-rs-core", branch = "master" }
pangocairo = { git = "https://github.com/gtk-rs/gtk-rs-core", branch = "master" }
gstreamer-audio-sys = { path = "./gstreamer-audio/sys"}
gstreamer-base-sys = { path = "./gstreamer-base/sys"}
gstreamer-gl-sys = { path = "./gstreamer-gl/sys"}
gstreamer-net-sys = { path = "./gstreamer-net/sys"}
gstreamer-pbutils-sys = { path = "./gstreamer-pbutils/sys"}
gstreamer-rtsp-sys = { path = "./gstreamer-rtsp/sys"}
gstreamer-sdp-sys = { path = "./gstreamer-sdp/sys"}
gstreamer-sys = { path = "./gstreamer/sys"}
gstreamer-video-sys = { path = "./gstreamer-video/sys"}
ges = { package = "gstreamer-editing-services", path = "./gstreamer-editing-services" }
gst = { package = "gstreamer", path = "./gstreamer" }
gst-allocators = { package = "gstreamer-allocators", path = "./gstreamer-allocators" }
gst-app = { package = "gstreamer-app", path = "./gstreamer-app" }
gst-audio = { package = "gstreamer-audio", path = "./gstreamer-audio" }
gst-base = { package = "gstreamer-base", path = "./gstreamer-base" }
gst-check = { package = "gstreamer-check", path = "./gstreamer-check" }
gst-gl = { package = "gstreamer-gl", path = "./gstreamer-gl" }
gst-gl-egl = { package = "gstreamer-gl-egl", path = "./gstreamer-gl/egl" }
gst-gl-x11 = { package = "gstreamer-gl-x11", path = "./gstreamer-gl/x11" }
gst-net = { package = "gstreamer-net", path = "./gstreamer-net" }
gst-pbutils = { package = "gstreamer-pbutils", path = "./gstreamer-pbutils" }
gst-play = { package = "gstreamer-play", path = "./gstreamer-play" }
gst-player = { package = "gstreamer-player", path = "./gstreamer-player" }
gst-rtsp = { package = "gstreamer-rtsp", path = "./gstreamer-rtsp" }
gst-rtsp-server = { package = "gstreamer-rtsp-server", path = "./gstreamer-rtsp-server" }
gst-sdp = { package = "gstreamer-sdp", path = "./gstreamer-sdp" }
gst-video = { package = "gstreamer-video", path = "./gstreamer-video" }

100
README.md
View file

@ -1,4 +1,4 @@
# gstreamer-rs [![crates.io](https://img.shields.io/crates/v/gstreamer.svg)](https://crates.io/crates/gstreamer) [![pipeline status](https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/badges/master/pipeline.svg)](https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/commits/master)
# gstreamer-rs [![crates.io](https://img.shields.io/crates/v/gstreamer.svg)](https://crates.io/crates/gstreamer) [![pipeline status](https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/badges/main/pipeline.svg)](https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/commits/main)
[GStreamer](https://gstreamer.freedesktop.org/) bindings for Rust.
Documentation can be found [here](https://gstreamer.pages.freedesktop.org/gstreamer-rs/stable/latest/docs/gstreamer/).
@ -24,7 +24,7 @@ API metadata provided by the GStreamer project.
## Installation
To build the GStreamer bindings or anything depending on them, you need to
have at least GStreamer 1.8 and gst-plugins-base 1.8 installed. In addition,
have at least GStreamer 1.14 and gst-plugins-base 1.14 installed. In addition,
some of the examples/tutorials require various GStreamer plugins to be
available, which can be found in gst-plugins-base, gst-plugins-good,
gst-plugins-bad, gst-plugins-ugly and/or gst-libav.
@ -45,16 +45,13 @@ $ apt-get install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev \
gstreamer1.0-libav libgstrtspserver-1.0-dev libges-1.0-dev
```
The minimum required version of the above libraries is >= 1.8. If you
The minimum required version of the above libraries is >= 1.14. If you
build the gstreamer-player sub-crate, or any of the examples that
depend on gstreamer-player, you must ensure that in addition to the
above packages, `libgstreamer-plugins-bad1.0-dev` is installed and
that the version is >= 1.12. See the `Cargo.toml` files for the full
details,
depend on gstreamer-player, you must ensure that in addition to the above
packages, `libgstreamer-plugins-bad1.0-dev` is installed. See the `Cargo.toml`
files for the full details,
```console
$ # Only if you wish to install gstreamer-player, make sure the version
$ # of this package is >= 1.12.
$ apt-get install libgstreamer-plugins-bad1.0-dev
```
@ -69,6 +66,26 @@ You can install GStreamer and the plugins via [Homebrew](https://brew.sh/) or
by installing the [binaries](https://gstreamer.freedesktop.org/data/pkg/osx/)
provided by the GStreamer project.
We recommend using the official GStreamer binaries over Homebrew, especially
as GStreamer in Homebrew is [currently broken](https://github.com/orgs/Homebrew/discussions/3740#discussioncomment-3804964).
#### GStreamer Binaries
You need to download the *two* `.pkg` files from the GStreamer website and
install them, e.g. `gstreamer-1.0-1.20.4-universal.pkg` and
`gstreamer-1.0-devel-1.20.4-universal.pkg`.
After installation, you also need to set the `PATH` environment variable as
follows
```console
$ export PATH="/Library/Frameworks/GStreamer.framework/Versions/1.0/bin${PATH:+:$PATH}"
```
Also note that the `pkg-config` from GStreamer should be the first one in
the `PATH` as other versions have all kinds of quirks that will cause
problems.
#### Homebrew
Homebrew only installs various plugins if explicitly enabled, so some extra
@ -82,22 +99,7 @@ $ brew install gstreamer gst-plugins-base gst-plugins-good \
--enable-gtk3
```
If you wish to install the gstreamer-player sub-crate, make sure the
version of these libraries is >= 1.12. Otherwise, a version >= 1.8 is
sufficient.
#### GStreamer Binaries
You need to download the *two* `.pkg` files from the GStreamer website and
install them, e.g. `gstreamer-1.0-1.12.3-x86_64.pkg` and
`gstreamer-1.0-devel-1.12.3-x86_64.pkg`.
After installation, you also need to install `pkg-config` (e.g. via Homebrew)
and set the `PKG_CONFIG_PATH` environment variable
```console
$ export PKG_CONFIG_PATH="/Library/Frameworks/GStreamer.framework/Versions/Current/lib/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}"
```
Make sure the version of these libraries is >= 1.14.
<a name="installation-windows"/>
@ -108,6 +110,32 @@ with `pacman` or by installing the
[binaries](https://gstreamer.freedesktop.org/data/pkg/windows/) provided by
the GStreamer project.
We recommend using the official GStreamer binaries over MSYS2.
#### GStreamer Binaries
You need to download the *two* `.msi` files for your platform from the
GStreamer website and install them, e.g. `gstreamer-1.0-x86_64-1.20.4.msi` and
`gstreamer-1.0-devel-x86_64-1.20.4.msi`. Make sure to select the version that
matches your Rust toolchain, i.e. MinGW or MSVC.
After installation set the ``PATH` environment variable as follows:
```console
# For a UNIX-style shell:
$ export PATH="c:/gstreamer/1.0/msvc_x86_64/bin${PATH:+:$PATH}"
# For cmd.exe:
$ set PATH=C:\gstreamer\1.0\msvc_x86_64\bin;%PATH%
```
Make sure to update the path to where you have actually installed GStreamer
and for the corresponding toolchain.
Also note that the `pkg-config.exe` from GStreamer should be the first one in
the `PATH` as other versions have all kinds of quirks that will cause
problems.
#### MSYS2 / pacman
```console
@ -118,29 +146,13 @@ $ pacman -S glib2-devel pkg-config \
mingw-w64-x86_64-gst-rtsp-server
```
If you wish to install the gstreamer-player sub-crate, make sure the
version of these libraries is >= 1.12. Otherwise, a version >= 1.8 is
sufficient.
Make sure the version of these libraries is >= 1.14.
Note that the version of `pkg-config` included in `MSYS2` is
[known to have problems](https://github.com/rust-lang/pkg-config-rs/issues/51#issuecomment-346300858)
compiling GStreamer, so you may need to install another version. One option
would be [`pkg-config-lite`](https://sourceforge.net/projects/pkgconfiglite/).
#### GStreamer Binaries
You need to download the *two* `.msi` files for your platform from the
GStreamer website and install them, e.g. `gstreamer-1.0-x86_64-1.12.3.msi` and
`gstreamer-1.0-devel-x86_64-1.12.3.msi`.
After installation, you also need to install `pkg-config` (e.g. via MSYS2 or
from [here](https://sourceforge.net/projects/pkgconfiglite/))
and set the `PKG_CONFIG_PATH` environment variable
```console
$ export PKG_CONFIG_PATH="c:\\gstreamer\\1.0\\x86_64\\lib\\pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}"
```
<a name="getting-started"/>
## Getting Started
@ -162,12 +174,12 @@ In addition there are
[tutorials](https://gstreamer.freedesktop.org/documentation/tutorials/) on the
GStreamer website. Many of them were ported to Rust already and the code can
be found in the
[tutorials](https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/tree/master/tutorials)
[tutorials](https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/tree/main/tutorials)
directory.
Some further examples for various aspects of GStreamer and how to use it from
Rust can be found in the
[examples](https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/tree/master/examples)
[examples](https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/tree/main/examples)
directory.
Various GStreamer plugins written in Rust can be found in the

42
ci/gir-checks.py Normal file
View file

@ -0,0 +1,42 @@
from itertools import chain
import os
import sys
from pathlib import Path as P
from subprocess import check_call as exec
NATIVE_CRATES = ["gstreamer-utils"]
def git(*args):
exec(["git"] + list(args))
def check_no_git_diff():
git("diff", "--exit-code")
check_no_git_diff()
git("clone", "--depth", "1", "https://github.com/gtk-rs/checker")
check_no_git_diff()
rootdir = P(".")
checker_dir = P("checker")
with (checker_dir / "Cargo.toml").open("a") as f:
f.write("[workspace]\n")
check_no_git_diff()
exec(['cargo', 'build', '--locked', '--color=always', '--release'], cwd=checker_dir)
check_no_git_diff()
exec('cargo run --color=always --release -- ../gstreamer* ../gstreamer-gl/{egl,wayland,x11}', cwd=checker_dir, shell=True)
gl_dir = rootdir / 'gstreamer-gl'
for crate in chain(rootdir.glob('gstreamer*'), [gl_dir / 'egl', gl_dir / 'wayland', gl_dir / 'x11']):
# Ignore "native" crates
if crate.name in NATIVE_CRATES:
continue
print(f'--> Checking doc aliases in {crate.absolute()}')
exec(['python3', 'doc_aliases.py', crate.absolute()], cwd=checker_dir)
print(f'--> {crate.absolute()}')
exec(['./checker/check_init_asserts', crate.absolute()])
check_no_git_diff()

View file

@ -1,4 +1,7 @@
variables:
GST_RS_IMG_TAG: '2022-01-13.0'
GST_RS_STABLE: '1.58.0'
GST_RS_MSRV: '1.56.0'
GST_RS_IMG_TAG: "2024-05-10.0"
GST_RS_STABLE: "1.78.0"
GST_RS_MSRV: "1.70.0"
# The branch we use to build GStreamer from in the docker images
# Ex. main, 1.24, my-test-branch
GST_UPSTREAM_BRANCH: 'main'

11
ci/install-dav1d.sh Normal file
View file

@ -0,0 +1,11 @@
set -e
RELEASE=1.4.1
git clone https://code.videolan.org/videolan/dav1d.git --branch $RELEASE
cd dav1d
meson build -D prefix=/usr/local
ninja -C build
ninja -C build install
cd ..
rm -rf dav1d

View file

@ -1,18 +1,49 @@
#! /bin/bash
set -e
pip3 install meson==0.60.3
DEFAULT_BRANCH="$GST_UPSTREAM_BRANCH"
pip3 install meson==1.1.1 --break-system-packages
# gstreamer-rs already has a 'gstreamer' directory so don't clone there
pushd .
cd ..
git clone --depth 1 https://gitlab.freedesktop.org/gstreamer/gstreamer.git --branch main
git clone https://gitlab.freedesktop.org/gstreamer/gstreamer.git \
--depth 1 \
--branch "$DEFAULT_BRANCH"
cd gstreamer
# plugins required by tests
PLUGINS="-D gst-plugins-base:ogg=enabled -D gst-plugins-base:vorbis=enabled -D gst-plugins-base:theora=enabled -D gst-plugins-good:matroska=enabled -D gst-plugins-good:vpx=enabled -D gst-plugins-bad:opus=enabled"
PLUGINS="-D gst-plugins-base:ogg=enabled \
-D gst-plugins-base:vorbis=enabled \
-D gst-plugins-base:theora=enabled \
-D gst-plugins-good:matroska=enabled \
-D gst-plugins-good:vpx=enabled \
-D gst-plugins-bad:opus=enabled \
-D gst-plugins-ugly:x264=enabled"
meson build -D prefix=/usr/local -D devtools=disabled -D examples=disabled -D gtk_doc=disabled -D introspection=disabled -D libav=disabled -D libnice=disabled -D python=disabled -D ugly=disabled -D vaapi=disabled $PLUGINS
ninja -C build
ninja -C build install
echo "subproject('gtk')" >> meson.build
meson setup build \
-D prefix=/usr/local \
-D gpl=enabled \
-D ugly=enabled \
-D examples=disabled \
-D gtk_doc=disabled \
-D introspection=disabled \
-D libav=disabled \
-D python=disabled \
-D vaapi=disabled \
$PLUGINS
meson compile -C build
meson install -C build
ldconfig
cd ..
rm -rf gstreamer/
# Check what plugins we installed
gst-inspect-1.0
popd

View file

@ -1,10 +0,0 @@
set -eux
BRANCH=gtk-4-4
git clone https://gitlab.gnome.org/GNOME/gtk.git --branch $BRANCH --depth=1
cd gtk
meson build -D prefix=/usr/local
ninja -C build
ninja -C build install
cd ..

View file

@ -1,9 +1,11 @@
#! /bin/bash
source ./ci/env.sh
set -e
export CARGO_HOME='/usr/local/cargo'
RUSTUP_VERSION=1.24.3
RUSTUP_VERSION=1.27.1
RUST_VERSION=$1
RUST_IMAGE_FULL=$2
RUST_ARCH="x86_64-unknown-linux-gnu"
@ -23,15 +25,27 @@ rustc --version
if [ "$RUST_IMAGE_FULL" = "1" ]; then
rustup component add clippy-preview
rustup component add rustfmt
cargo install --force cargo-deny
cargo install --force cargo-outdated
cargo install --locked --force cargo-deny
cargo install --locked --force cargo-outdated
cargo install --locked --force typos-cli --version "1.19.0"
# Coverage tools
rustup component add llvm-tools-preview
cargo install --locked --force grcov
fi
if [ "$RUST_VERSION" = "nightly" ]; then
# Coverage tools
cargo install grcov
rustup component add llvm-tools-preview
# FIXME: Don't build cargo-c with --locked for now because otherwise a
# version of ahash is used that doesn't build on nightly anymore
cargo install cargo-c --version 0.9.22+cargo-0.72
else
cargo install --locked cargo-c --version 0.9.22+cargo-0.72
fi
if [ "$RUST_VERSION" = "nightly" ]; then
rustup component add rustfmt --toolchain nightly
# Documentation tools
cargo install --force rustdoc-stripper
cargo install --locked --force rustdoc-stripper
fi

30
ci/run-cargo-test.sh Executable file
View file

@ -0,0 +1,30 @@
#! /bin/bash
set -ex
rustc --version
cargo --version
for crate in gstreamer* gstreamer-gl/{egl,wayland,x11}; do
if [ -e "$crate/Cargo.toml" ]; then
if [ -n "$ALL_FEATURES" ]; then
FEATURES="--all-features"
else
FEATURES=""
fi
echo "Building and testing $crate with $FEATURES"
cargo build --locked --color=always --manifest-path "$crate/Cargo.toml" $FEATURES
G_DEBUG=fatal_warnings cargo test --color=always --manifest-path "$crate/Cargo.toml" $FEATURES
fi
done
if [ -n "$EXAMPLES_TUTORIALS" ]; then
# Keep in sync with examples/Cargo.toml
# List all features except windows/win32
EXAMPLES_FEATURES="--features=rtsp-server,rtsp-server-record,pango-cairo,overlay-composition,gl,gst-gl-x11,gst-gl-egl,allocators,gst-play,gst-player,ges,image,cairo-rs,gst-video/v1_18"
cargo build --locked --color=always --manifest-path examples/Cargo.toml --bins --examples "$EXAMPLES_FEATURES"
cargo build --locked --color=always --manifest-path tutorials/Cargo.toml --bins --examples --all-features
fi

38
ci/run-clippy.sh Executable file
View file

@ -0,0 +1,38 @@
#! /bin/bash
set -ex
rustc --version
cargo --version
cargo clippy --version
# Keep features in sync with run-cargo-test.sh
get_features() {
crate=$1
case "$crate" in
gstreamer-audio|gstreamer-editing-services|gstreamer-gl|gstreamer-pbutils|gstreamer-rtp|gstreamer-rtsp|gstreamer-video|gstreamer)
echo "--features=serde,v1_26"
;;
*)
echo "--features=v1_26"
;;
esac
}
for crate in gstreamer* gstreamer-gl/{egl,wayland,x11}; do
if [ -e "$crate/Cargo.toml" ]; then
FEATURES=$(get_features "$crate")
echo "Running clippy on $crate with $FEATURES"
cargo clippy --locked --color=always --manifest-path "$crate/Cargo.toml" $FEATURES --all-targets -- $CLIPPY_LINTS
fi
done
# Keep in sync with examples/Cargo.toml
# List all features except windows/win32
EXAMPLES_FEATURES="--features=rtsp-server,rtsp-server-record,pango-cairo,overlay-composition,gl,gst-gl-x11,gst-gl-egl,allocators,gst-play,gst-player,ges,image,cairo-rs,gst-video/v1_18"
# And also run over all the examples/tutorials
cargo clippy --locked --color=always --manifest-path examples/Cargo.toml --all-targets "$EXAMPLES_FEATURES" -- $CLIPPY_LINTS
cargo clippy --locked --color=always --manifest-path tutorials/Cargo.toml --all-targets --all-features -- $CLIPPY_LINTS

43
ci/run-sys-cargo-test.sh Executable file
View file

@ -0,0 +1,43 @@
#! /bin/bash
set -ex
rustc --version
cargo --version
for crate in gstreamer*/sys gstreamer-gl/*/sys; do
if [ -e "$crate/Cargo.toml" ]; then
echo "Building $crate with --all-features"
cargo build --locked --color=always --manifest-path "$crate/Cargo.toml" --all-features
fi
done
for crate in gstreamer/sys \
gstreamer-allocators/sys \
gstreamer-analytics/sys \
gstreamer-app/sys \
gstreamer-audio/sys \
gstreamer-base/sys \
gstreamer-check/sys \
gstreamer-controller/sys \
gstreamer-editing-services/sys \
gstreamer-gl/sys \
gstreamer-gl/egl/sys \
gstreamer-gl/wayland/sys \
gstreamer-gl/x11/sys \
gstreamer-mpegts/sys \
gstreamer-net/sys \
gstreamer-pbutils/sys \
gstreamer-play/sys \
gstreamer-player/sys \
gstreamer-rtp/sys \
gstreamer-rtsp-server/sys \
gstreamer-rtsp/sys \
gstreamer-sdp/sys \
gstreamer-tag/sys \
gstreamer-validate/sys \
gstreamer-video/sys \
gstreamer-webrtc/sys; do
echo "Testing $crate with --all-features)"
cargo test --locked --color=always --manifest-path $crate/Cargo.toml --all-features
done

86
ci/run_windows_tests.ps1 Normal file
View file

@ -0,0 +1,86 @@
# List of all the crates we want to build
# We need to do this manually to avoid trying
# to build egl,wayland,x11 etc, which can't
# work on windows
[string[]] $crates = @(
'gstreamer',
# Unix specific atm
# 'gstreamer-allocators'
'gstreamer-app',
'gstreamer-audio',
'gstreamer-base',
'gstreamer-check',
'gstreamer-controller',
'gstreamer-editing-services',
'gstreamer-gl',
# 'gstreamer-gl/egl',
# 'gstreamer-gl/wayland',
# 'gstreamer-gl/x11',
'gstreamer-mpegts',
'gstreamer-mpegts/sys',
'gstreamer-net',
'gstreamer-pbutils',
'gstreamer-player',
'gstreamer-rtp',
'gstreamer-rtsp',
'gstreamer-rtsp-server',
'gstreamer-sdp',
'gstreamer-tag',
'gstreamer-tag/sys',
'gstreamer-video',
'gstreamer-webrtc',
'tutorials',
'examples'
)
# "" is the default build, no flags appended
[string[]] $features_matrix = @(
# "--no-default-features",
# "--features=v1_18",
# "--features=v1_20",
"",
"--all-features"
)
foreach($features in $features_matrix) {
foreach($crate in $crates)
{
Write-Host "Building crate: $crate"
Write-Host "Features: $features"
$env:LocalFeatures = $features
# Don't append feature flags if the string is null/empty
# Or when we want to build without default features
if ($env:LocalFeatures -and ($env:LocalFeatures -ne '--no-default-features')) {
if ($crate -eq 'examples') {
# FIXME: We can do --all-features for examples once we have gtk3 installed in the image
$env:LocalFeatures = "--features=rtsp-server,rtsp-server-record,pango-cairo,overlay-composition,gst-play,gst-player,ges,image,cairo-rs,gst-video/v1_18,windows"
}
if ($crate -eq 'tutorials') {
$env:LocalFeatures = ''
}
}
Write-Host "with features: $env:LocalFeatures"
cargo build --color=always --manifest-path $crate/Cargo.toml --all-targets $env:LocalFeatures
if (!$?) {
Write-Host "Failed to build crate: $crate"
Exit 1
}
if (($crate -eq "gstreamer-tag/sys") -or ($crate -eq "gstreamer-mpegts/sys")) {
Write-Host "Skipping tests for $crate"
continue
}
$env:G_DEBUG="fatal_warnings"
cargo test --no-fail-fast --color=always --manifest-path $crate/Cargo.toml $env:LocalFeatures
if (!$?) {
Write-Host "Tests failed to for crate: $crate"
Exit 1
}
}
}

View file

@ -0,0 +1,22 @@
# escape=`
FROM "registry.freedesktop.org/gstreamer/gstreamer/amd64/windows:2023-07-17.0-main"
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
ARG DEFAULT_BRANCH="1.24"
ARG RUST_VERSION="invalid"
RUN choco install -y pkgconfiglite nasm llvm openssl
# https://stackoverflow.com/a/50716450
RUN setx PATH '%PATH%;C:\Program Files\NASM;C:\gst-install\bin'
ENV PKG_CONFIG_PATH="C:\gst-install\lib\pkgconfig"
COPY install_gst.ps1 install_dav1d.ps1 C:\
RUN C:\install_gst.ps1
RUN C:\install_dav1d.ps1
RUN Invoke-WebRequest -Uri https://win.rustup.rs/x86_64 -OutFile C:\rustup-init.exe
RUN C:\rustup-init.exe -y --profile minimal --default-toolchain $env:RUST_VERSION
RUN cargo install --locked cargo-c --version 0.9.22+cargo-0.72

View file

@ -0,0 +1,60 @@
# Copied from mesa, big kudos
#
# https://gitlab.freedesktop.org/mesa/mesa/-/blob/master/.gitlab-ci/windows/mesa_container.ps1
# https://gitlab.freedesktop.org/mesa/mesa/-/blob/34e3e164936d1d3cef267da7780e87f062fedf39/.gitlab-ci/windows/mesa_container.ps1
# Implements the equivalent of ci-templates container-ifnot-exists, using
# Docker directly as we don't have buildah/podman/skopeo available under
# Windows, nor can we execute Docker-in-Docker
$registry_uri = $args[0]
$registry_username = $args[1]
$registry_password = $args[2]
$registry_user_image = $args[3]
$registry_central_image = $args[4]
$dockerfile = $args[5]
docker --config "windows-docker.conf" login -u "$registry_username" -p "$registry_password" "$registry_uri"
if (!$?) {
Write-Host "docker login failed to $registry_uri"
Exit 1
}
# if the image already exists, don't rebuild it
docker --config "windows-docker.conf" pull "$registry_user_image"
if ($?) {
Write-Host "User image $registry_user_image already exists; not rebuilding"
docker --config "windows-docker.conf" logout "$registry_uri"
Exit 0
}
# if the image already exists upstream, copy it
docker --config "windows-docker.conf" pull "$registry_central_image"
if ($?) {
Write-Host "Copying central image $registry_central_image to user image $registry_user_image"
docker --config "windows-docker.conf" tag "$registry_central_image" "$registry_user_image"
docker --config "windows-docker.conf" push "$registry_user_image"
$pushstatus = $?
docker --config "windows-docker.conf" logout "$registry_uri"
if (!$pushstatus) {
Write-Host "Pushing image to $registry_user_image failed"
Exit 1
}
Exit 0
}
Write-Host "No image found at $registry_user_image or $registry_central_image; rebuilding"
docker --config "windows-docker.conf" build $DOCKER_BUILD_ARGS --no-cache -t "$registry_user_image" -f "$dockerfile" "./ci/windows-docker"
if (!$?) {
Write-Host "Container build failed"
docker --config "windows-docker.conf" logout "$registry_uri"
Exit 1
}
Get-Date
docker --config "windows-docker.conf" push "$registry_user_image"
$pushstatus = $?
docker --config "windows-docker.conf" logout "$registry_uri"
if (!$pushstatus) {
Write-Host "Pushing image to $registry_user_image failed"
Exit 1
}

View file

@ -0,0 +1,28 @@
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12;
# Download gstreamer and all its subprojects
git clone -b 1.4.1 --depth 1 https://code.videolan.org/videolan/dav1d.git C:\dav1d
if (!$?) {
Write-Host "Failed to clone dav1d"
Exit 1
}
Set-Location C:\dav1d
# This is fine, we are not going to use the GtkMedia* apis
$env:MESON_ARGS = "--prefix=C:\gst-install\"
Write-Output "Building dav1d"
cmd.exe /C "C:\BuildTools\Common7\Tools\VsDevCmd.bat -host_arch=amd64 -arch=amd64 && meson _build $env:MESON_ARGS && meson compile -C _build && ninja -C _build install"
if (!$?) {
Write-Host "Failed to build and install dav1d"
Exit 1
}
cd C:\
cmd /c rmdir /s /q C:\dav1d
if (!$?) {
Write-Host "Failed to remove dav1d checkout"
Exit 1
}

View file

@ -0,0 +1,71 @@
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12;
# Download gstreamer and all its subprojects
git clone -b $env:DEFAULT_BRANCH --depth 1 https://gitlab.freedesktop.org/gstreamer/gstreamer.git C:\gstreamer
if (!$?) {
Write-Host "Failed to clone gstreamer"
Exit 1
}
Set-Location C:\gstreamer
# Copy the cache we already have in the image to avoid massive redownloads
Move-Item C:/subprojects/* C:\gstreamer\subprojects
# Update the subprojects cache
Write-Output "Running meson subproject reset"
meson subprojects update --reset
if (!$?) {
Write-Host "Failed to update gstreamer subprojects"
Exit 1
}
$MESON_ARGS = @(`
"--prefix=C:\gst-install", `
"-Dglib:installed_tests=false", `
"-Dlibnice:tests=disabled", `
"-Dlibnice:examples=disabled", `
"-Dffmpeg:tests=disabled", `
"-Dopenh264:tests=disabled", `
"-Dpygobject:tests=false", `
"-Dgpl=enabled", `
"-Dugly=enabled", `
"-Dbad=enabled", `
"-Dges=enabled", `
"-Drtsp_server=enabled", `
"-Ddevtools=enabled", `
"-Dsharp=disabled", `
"-Dpython=disabled", `
"-Dlibav=disabled", `
"-Dvaapi=disabled", `
"-Dgst-plugins-base:pango=enabled", `
"-Dgst-plugins-good:cairo=enabled", `
"-Dgst-plugins-good:lame=disabled"
)
$PSDefaultParameterValues['Out-File:Encoding'] = 'utf8'
echo "subproject('gtk')" >> meson.build
Write-Output "Building gstreamer"
meson setup --vsenv $MESON_ARGS _build
if (!$?) {
type "_build\meson-logs\meson-log.txt"
Write-Host "Failed to run meson setup, see log above"
Exit 1
}
Write-Output "Compiling gstreamer"
meson compile -C _build
if (!$?) {
Write-Host "Failed to run meson compile"
Exit 1
}
# meson install does a spurious rebuild sometimes that then fails
meson install --no-rebuild -C _build
if (!$?) {
Write-Host "Failed to run meson install"
Exit 1
}
cd c:\
Remove-Item -LiteralPath "C:\gstreamer" -Force -Recurse

View file

@ -1,3 +1,8 @@
exclude = [
"examples",
"tutorials",
]
[advisories]
db-path = "~/.cargo/advisory-db"
db-urls = ["https://github.com/rustsec/advisory-db"]
@ -8,16 +13,7 @@ ignore = []
[licenses]
unlicensed = "deny"
allow = [
"Apache-2.0",
]
deny = [
"GPL-1.0",
"GPL-2.0",
"GPL-3.0",
"AGPL-1.0",
"AGPL-3.0",
]
default = "deny"
copyleft = "deny"
allow-osi-fsf-free = "either"
confidence-threshold = 0.8
@ -27,14 +23,15 @@ multiple-versions = "deny"
wildcards = "allow"
highlight = "all"
# proc-macro-crate depends on an older version of toml_edit
# https://github.com/bkchr/proc-macro-crate/pull/50
[[bans.skip]]
name = "toml_edit"
version = "0.21"
[sources]
unknown-registry = "deny"
unknown-git = "deny"
allow-git = [
"https://github.com/gtk-rs/gtk-rs-core",
]
# ignore duplicated heck dependency because various crates depend on an old version
[[bans.skip]]
name = "heck"
version = "0.3"

View file

@ -1,61 +1,73 @@
[package]
name = "examples"
version = "0.18.0"
version.workspace = true
license = "MIT"
authors = ["Sebastian Dröge <sebastian@centricular.com>"]
edition = "2021"
rust-version = "1.56"
edition.workspace = true
rust-version.workspace = true
[dependencies]
glib = { git = "https://github.com/gtk-rs/gtk-rs-core" }
gst = { package = "gstreamer", path = "../gstreamer" }
gst-gl = { package = "gstreamer-gl", path = "../gstreamer-gl", optional = true }
gst-gl-egl = { package = "gstreamer-gl-egl", path = "../gstreamer-gl/egl", optional = true }
gst-gl-wayland = { package = "gstreamer-gl-wayland", path = "../gstreamer-gl/wayland", optional = true }
gst-gl-x11 = { package = "gstreamer-gl-x11", path = "../gstreamer-gl/x11", optional = true }
gst-app = { package = "gstreamer-app", path = "../gstreamer-app" }
gst-audio = { package = "gstreamer-audio", path = "../gstreamer-audio" }
gst-base = { package = "gstreamer-base", path = "../gstreamer-base" }
gst-video = { package = "gstreamer-video", path = "../gstreamer-video" }
gst-pbutils = { package = "gstreamer-pbutils", path = "../gstreamer-pbutils" }
gst-player = { package = "gstreamer-player", path = "../gstreamer-player", optional = true }
ges = { package = "gstreamer-editing-services", path = "../gstreamer-editing-services", optional = true }
gst-sdp = { package = "gstreamer-sdp", path = "../gstreamer-sdp", optional = true }
gst-rtsp = { package = "gstreamer-rtsp", path = "../gstreamer-rtsp", optional = true }
gst-rtsp-server = { package = "gstreamer-rtsp-server", path = "../gstreamer-rtsp-server", optional = true }
gtk = { git = "https://github.com/gtk-rs/gtk3-rs", optional = true }
gdk = { git = "https://github.com/gtk-rs/gtk3-rs", optional = true }
gio = { git = "https://github.com/gtk-rs/gtk-rs-core" , optional = true }
glib.workspace = true
gst.workspace = true
gst-gl = { workspace = true, optional = true }
gst-gl-egl = { workspace = true, optional = true }
gst-gl-x11 = { workspace = true, optional = true }
gst-app.workspace = true
gst-audio.workspace = true
gst-base.workspace = true
gst-video.workspace = true
gst-pbutils.workspace = true
gst-play = { workspace = true, optional = true }
gst-player = { workspace = true, optional = true }
ges = { workspace = true, optional = true }
gst-sdp = { workspace = true, optional = true }
gst-rtsp = { workspace = true, optional = true }
gst-rtsp-server = { workspace = true, optional = true }
gst-allocators = { workspace = true, optional = true }
gio = { workspace = true, optional = true }
anyhow = "1.0"
byte-slice-cast = "1"
cairo-rs = { workspace = true, features=["use_glib"], optional = true }
derive_more = "0.99.5"
futures = "0.3"
byte-slice-cast = "1"
cairo-rs = { git = "https://github.com/gtk-rs/gtk-rs-core" , features=["use_glib"], optional = true }
pango = { git = "https://github.com/gtk-rs/gtk-rs-core" , optional = true }
pangocairo = { git = "https://github.com/gtk-rs/gtk-rs-core" , optional = true }
glutin = { version = "0.28", optional = true }
once_cell = "1.0"
image = { version="0.23", optional = true }
glutin = { version = "0.31", optional = true, default-features = false }
glutin-winit = { version = "0.4", optional = true, default-features = false }
image = { version = "0.24", optional = true, default-features = false, features = ["png", "jpeg"] }
memfd = { version = "0.6", optional = true }
memmap2 = { version = "0.9", optional = true }
pango = { workspace = true, optional = true }
pangocairo = { workspace = true, optional = true }
raw-window-handle = { version = "0.5", optional = true }
uds = { version = "0.4", optional = true }
winit = { version = "0.29", optional = true, default-features = false, features = ["rwh_05"] }
atomic_refcell = "0.1"
data-encoding = "2.0"
once_cell = "1"
[target.'cfg(windows)'.dependencies]
windows = { version = "0.56", features=["Win32_Graphics_Direct3D11",
"Win32_Foundation", "Win32_Graphics_Direct3D", "Win32_Graphics_Dxgi",
"Win32_Graphics_Dxgi_Common", "Win32_Graphics_Direct2D",
"Win32_Graphics_Direct2D_Common", "Win32_Graphics_DirectWrite",
"Win32_Graphics_Imaging", "Win32_System_Com", "Foundation_Numerics"], optional = true }
[target.'cfg(target_os = "macos")'.dependencies]
cocoa = "0.24"
cocoa = "0.25"
objc = "0.2.7"
[build-dependencies]
gl_generator = { version = "0.14", optional = true }
[features]
default = []
gtksink = ["gtk", "gio"]
gtkvideooverlay = ["gtk", "gdk", "gio"]
gtkvideooverlay-x11 = ["gtkvideooverlay"]
gtkvideooverlay-quartz = ["gtkvideooverlay"]
rtsp-server = ["gst-rtsp-server", "gst-rtsp", "gst-sdp"]
rtsp-server-record = ["gst-rtsp-server", "gst-rtsp", "gio"]
v1_10 = ["gst/v1_10"]
v1_14 = ["gst/v1_14"]
pango-cairo = ["pango", "pangocairo", "cairo-rs"]
overlay-composition = ["pango", "pangocairo", "cairo-rs"]
gl = ["gst-gl", "gl_generator", "glutin"]
gl = ["dep:gst-gl", "dep:gl_generator", "dep:glutin", "dep:glutin-winit", "dep:winit", "dep:raw-window-handle"]
gst-gl-x11 = ["dep:gst-gl-x11", "glutin-winit?/glx"] # glx turns on x11
gst-gl-egl = ["dep:gst-gl-egl", "glutin-winit?/egl", "glutin-winit?/x11", "glutin-winit?/wayland"] # Use X11 or Wayland via EGL
allocators = ["gst-allocators", "memmap2", "memfd", "uds"]
[[bin]]
name = "appsink"
@ -65,7 +77,6 @@ name = "appsrc"
[[bin]]
name = "custom_events"
required-features = ["v1_10"]
[[bin]]
name = "custom_meta"
@ -75,7 +86,6 @@ name = "decodebin"
[[bin]]
name = "debug_ringbuffer"
required-features = ["v1_14"]
[[bin]]
name = "encodebin"
@ -83,14 +93,6 @@ name = "encodebin"
[[bin]]
name = "events"
[[bin]]
name = "gtksink"
required-features = ["gtksink"]
[[bin]]
name = "gtkvideooverlay"
required-features = ["gtkvideooverlay"]
[[bin]]
name = "iterator"
@ -106,6 +108,10 @@ name = "transmux"
[[bin]]
name = "pad_probes"
[[bin]]
name = "play"
required-features = ["gst-play"]
[[bin]]
name = "playbin"
@ -130,6 +136,10 @@ required-features = ["rtsp-server"]
name = "rtsp-server-subclass"
required-features = ["rtsp-server"]
[[bin]]
name = "rtsp-server-custom-auth"
required-features = ["rtsp-server", "gst-rtsp-server/v1_22"]
[[bin]]
name = "tagsetter"
@ -157,6 +167,10 @@ required-features = ["pango-cairo"]
name = "overlay-composition"
required-features = ["overlay-composition"]
[[bin]]
name = "overlay-composition-d2d"
required-features = ["windows"]
[[bin]]
name = "ges"
required-features = ["ges"]
@ -178,3 +192,18 @@ name = "video_converter"
[[bin]]
name = "thumbnail"
required-features = ["image"]
[[bin]]
name = "fd_allocator"
required-features = ["allocators"]
[[bin]]
name = "cairo_compositor"
required-features = ["cairo-rs", "gst-video/v1_18"]
[[bin]]
name = "d3d11videosink"
required-features = ["windows"]
[[bin]]
name = "audio_multichannel_interleave"

View file

@ -1,7 +1,7 @@
#[cfg(feature = "gl")]
fn generate_gl_bindings() {
let dest = std::path::PathBuf::from(&std::env::var("OUT_DIR").unwrap());
let mut file = std::fs::File::create(&dest.join("test_gl_bindings.rs")).unwrap();
let mut file = std::fs::File::create(dest.join("test_gl_bindings.rs")).unwrap();
gl_generator::Registry::new(
gl_generator::Api::Gles2,
(3, 0),

View file

@ -10,60 +10,44 @@
// This is the format we request:
// Audio / Signed 16bit / 1 channel / arbitrary sample rate
use gst::element_error;
use gst::prelude::*;
use byte_slice_cast::*;
use std::i16;
use std::i32;
use anyhow::Error;
use byte_slice_cast::*;
use derive_more::{Display, Error};
use gst::{element_error, prelude::*};
#[path = "../examples-common.rs"]
mod examples_common;
#[derive(Debug, Display, Error)]
#[display(fmt = "Missing element {}", _0)]
struct MissingElement(#[error(not(source))] &'static str);
#[derive(Debug, Display, Error)]
#[display(fmt = "Received error from {}: {} (debug: {:?})", src, error, debug)]
#[display(fmt = "Received error from {src}: {error} (debug: {debug:?})")]
struct ErrorMessage {
src: String,
error: String,
debug: Option<String>,
source: glib::Error,
src: glib::GString,
error: glib::Error,
debug: Option<glib::GString>,
}
fn create_pipeline() -> Result<gst::Pipeline, Error> {
gst::init()?;
let pipeline = gst::Pipeline::new(None);
let src = gst::ElementFactory::make("audiotestsrc", None)
.map_err(|_| MissingElement("audiotestsrc"))?;
let sink = gst::ElementFactory::make("appsink", None).map_err(|_| MissingElement("appsink"))?;
let pipeline = gst::Pipeline::default();
let src = gst::ElementFactory::make("audiotestsrc").build()?;
let appsink = gst_app::AppSink::builder()
// Tell the appsink what format we want. It will then be the audiotestsrc's job to
// provide the format we request.
// This can be set after linking the two objects, because format negotiation between
// both elements will happen during pre-rolling of the pipeline.
.caps(
&gst_audio::AudioCapsBuilder::new_interleaved()
.format(gst_audio::AUDIO_FORMAT_S16)
.channels(1)
.build(),
)
.build();
pipeline.add_many(&[&src, &sink])?;
src.link(&sink)?;
let appsink = sink
.dynamic_cast::<gst_app::AppSink>()
.expect("Sink element is expected to be an appsink!");
// Tell the appsink what format we want. It will then be the audiotestsrc's job to
// provide the format we request.
// This can be set after linking the two objects, because format negotiation between
// both elements will happen during pre-rolling of the pipeline.
appsink.set_caps(Some(
&gst::Caps::builder("audio/x-raw")
.field("format", gst_audio::AUDIO_FORMAT_S16.to_str())
.field("layout", "interleaved")
.field("channels", 1i32)
.field("rate", gst::IntRange::<i32>::new(1, i32::MAX))
.build(),
));
pipeline.add_many([&src, appsink.upcast_ref()])?;
src.link(&appsink)?;
// Getting data out of the appsink is done by setting callbacks on it.
// The appsink will then call those handlers, as soon as data is available.
@ -107,7 +91,7 @@ fn create_pipeline() -> Result<gst::Pipeline, Error> {
element_error!(
appsink,
gst::ResourceError::Failed,
("Failed to interprete buffer as S16 PCM")
("Failed to interpret buffer as S16 PCM")
);
gst::FlowError::Error
@ -123,7 +107,7 @@ fn create_pipeline() -> Result<gst::Pipeline, Error> {
})
.sum();
let rms = (sum / (samples.len() as f64)).sqrt();
println!("rms: {}", rms);
println!("rms: {rms}");
Ok(gst::FlowSuccess::Ok)
})
@ -150,11 +134,10 @@ fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> {
return Err(ErrorMessage {
src: msg
.src()
.map(|s| String::from(s.path_string()))
.unwrap_or_else(|| String::from("None")),
error: err.error().to_string(),
.map(|s| s.path_string())
.unwrap_or_else(|| glib::GString::from("UNKNOWN")),
error: err.error(),
debug: err.debug(),
source: err.error(),
}
.into());
}
@ -170,7 +153,7 @@ fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> {
fn example_main() {
match create_pipeline().and_then(main_loop) {
Ok(r) => r,
Err(e) => eprintln!("Error! {}", e),
Err(e) => eprintln!("Error! {e}"),
}
}

View file

@ -10,25 +10,20 @@
// The application provides data of the following format:
// Video / BGRx (4 bytes) / 2 fps
use gst::prelude::*;
use anyhow::Error;
use derive_more::{Display, Error};
use gst::prelude::*;
use gst_video::prelude::*;
#[path = "../examples-common.rs"]
mod examples_common;
#[derive(Debug, Display, Error)]
#[display(fmt = "Missing element {}", _0)]
struct MissingElement(#[error(not(source))] &'static str);
#[derive(Debug, Display, Error)]
#[display(fmt = "Received error from {}: {} (debug: {:?})", src, error, debug)]
#[display(fmt = "Received error from {src}: {error} (debug: {debug:?})")]
struct ErrorMessage {
src: String,
error: String,
debug: Option<String>,
source: glib::Error,
src: glib::GString,
error: glib::Error,
debug: Option<glib::GString>,
}
const WIDTH: usize = 320;
@ -37,19 +32,7 @@ const HEIGHT: usize = 240;
fn create_pipeline() -> Result<gst::Pipeline, Error> {
gst::init()?;
let pipeline = gst::Pipeline::new(None);
let src = gst::ElementFactory::make("appsrc", None).map_err(|_| MissingElement("appsrc"))?;
let videoconvert = gst::ElementFactory::make("videoconvert", None)
.map_err(|_| MissingElement("videoconvert"))?;
let sink = gst::ElementFactory::make("autovideosink", None)
.map_err(|_| MissingElement("autovideosink"))?;
pipeline.add_many(&[&src, &videoconvert, &sink])?;
gst::Element::link_many(&[&src, &videoconvert, &sink])?;
let appsrc = src
.dynamic_cast::<gst_app::AppSrc>()
.expect("Source element is expected to be an appsrc!");
let pipeline = gst::Pipeline::default();
// Specify the format we want to provide as application into the pipeline
// by creating a video info with the given format and creating caps from it for the appsrc element.
@ -59,8 +42,16 @@ fn create_pipeline() -> Result<gst::Pipeline, Error> {
.build()
.expect("Failed to create video info");
appsrc.set_caps(Some(&video_info.to_caps().unwrap()));
appsrc.set_format(gst::Format::Time);
let appsrc = gst_app::AppSrc::builder()
.caps(&video_info.to_caps().unwrap())
.format(gst::Format::Time)
.build();
let videoconvert = gst::ElementFactory::make("videoconvert").build()?;
let sink = gst::ElementFactory::make("autovideosink").build()?;
pipeline.add_many([appsrc.upcast_ref(), &videoconvert, &sink])?;
gst::Element::link_many([appsrc.upcast_ref(), &videoconvert, &sink])?;
// Our frame counter, that is stored in the mutable environment
// of the closure of the need-data callback
@ -85,7 +76,7 @@ fn create_pipeline() -> Result<gst::Pipeline, Error> {
return;
}
println!("Producing frame {}", i);
println!("Producing frame {i}");
let r = if i % 2 == 0 { 0 } else { 255 };
let g = if i % 3 == 0 { 0 } else { 255 };
@ -160,11 +151,10 @@ fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> {
return Err(ErrorMessage {
src: msg
.src()
.map(|s| String::from(s.path_string()))
.unwrap_or_else(|| String::from("None")),
error: err.error().to_string(),
.map(|s| s.path_string())
.unwrap_or_else(|| glib::GString::from("UNKNOWN")),
error: err.error(),
debug: err.debug(),
source: err.error(),
}
.into());
}
@ -180,7 +170,7 @@ fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> {
fn example_main() {
match create_pipeline().and_then(main_loop) {
Ok(r) => r,
Err(e) => eprintln!("Error! {}", e),
Err(e) => eprintln!("Error! {e}"),
}
}

View file

@ -0,0 +1,153 @@
// This example demonstrates how to mix multiple audio
// streams into a single output using the audiomixer element.
// In this case, we're mixing 4 stereo streams into a single 8 channel output.
use gst::prelude::*;
use std::env;
#[path = "../examples-common.rs"]
mod examples_common;
const TRACKS: i32 = 4;
fn create_source_and_link(pipeline: &gst::Pipeline, mixer: &gst::Element, track_number: i32) {
let freq = ((track_number + 1) * 1000) as f64;
let audiosrc = gst::ElementFactory::make("audiotestsrc")
.property("freq", freq)
.property("num-buffers", 2000)
.build()
.unwrap();
let caps = gst_audio::AudioCapsBuilder::new().channels(2).build();
let capsfilter = gst::ElementFactory::make("capsfilter")
.property("caps", &caps)
.build()
.unwrap();
pipeline.add_many([&audiosrc, &capsfilter]).unwrap();
gst::Element::link_many([&audiosrc, &capsfilter]).unwrap();
let src_pad = capsfilter.static_pad("src").unwrap();
let mixer_pad = mixer.request_pad_simple("sink_%u").unwrap();
// audiomixer expects a mix-matrix set on each input pad,
// indicating which output channels our input should appear in.
// Rows => input channels, columns => output channels.
// Here each input channel will appear in exactly one output channel.
let mut mix_matrix: Vec<Vec<f32>> = vec![];
for i in 0..TRACKS {
if i == track_number {
mix_matrix.push(vec![1.0, 0.0]);
mix_matrix.push(vec![0.0, 1.0]);
} else {
mix_matrix.push(vec![0.0, 0.0]);
mix_matrix.push(vec![0.0, 0.0]);
}
}
let mut audiomixer_config = gst_audio::AudioConverterConfig::new();
audiomixer_config.set_mix_matrix(&mix_matrix);
mixer_pad.set_property("converter-config", audiomixer_config);
src_pad.link(&mixer_pad).unwrap();
}
fn example_main() {
gst::init().unwrap();
let args: Vec<_> = env::args().collect();
let output_file = if args.len() == 2 {
&args[1]
} else {
println!("Usage: audiomixer <output file>");
std::process::exit(-1);
};
let pipeline = gst::Pipeline::new();
let audiomixer = gst::ElementFactory::make("audiomixer").build().unwrap();
// Using an arbitrary layout of 4 stereo pairs.
let positions = [
gst_audio::AudioChannelPosition::FrontLeft,
gst_audio::AudioChannelPosition::FrontRight,
gst_audio::AudioChannelPosition::RearLeft,
gst_audio::AudioChannelPosition::RearRight,
gst_audio::AudioChannelPosition::SideLeft,
gst_audio::AudioChannelPosition::SideRight,
gst_audio::AudioChannelPosition::TopFrontLeft,
gst_audio::AudioChannelPosition::TopFrontRight,
];
let mask = gst_audio::AudioChannelPosition::positions_to_mask(&positions, true).unwrap();
let caps = gst_audio::AudioCapsBuilder::new()
.channels(positions.len() as i32)
.channel_mask(mask)
.build();
let capsfilter = gst::ElementFactory::make("capsfilter")
.property("caps", &caps)
.build()
.unwrap();
let audioconvert = gst::ElementFactory::make("audioconvert").build().unwrap();
let audioresample = gst::ElementFactory::make("audioresample").build().unwrap();
let wavenc = gst::ElementFactory::make("wavenc").build().unwrap();
let sink = gst::ElementFactory::make("filesink")
.property("location", output_file)
.build()
.unwrap();
pipeline
.add_many([
&audiomixer,
&capsfilter,
&audioconvert,
&audioresample,
&wavenc,
&sink,
])
.unwrap();
gst::Element::link_many([
&audiomixer,
&capsfilter,
&audioconvert,
&audioresample,
&wavenc,
&sink,
])
.unwrap();
for i in 0..TRACKS {
create_source_and_link(&pipeline, &audiomixer, i);
}
let bus = pipeline.bus().expect("Pipeline without bus");
pipeline
.set_state(gst::State::Playing)
.expect("Unable to start pipeline");
for msg in bus.iter_timed(gst::ClockTime::NONE) {
use gst::MessageView;
match msg.view() {
MessageView::Eos(..) => break,
MessageView::Error(err) => {
eprintln!(
"Error from {:?}: {} ({:?})",
msg.src().map(|s| s.path_string()),
err.error(),
err.debug()
);
break;
}
_ => (),
}
}
pipeline
.set_state(gst::State::Null)
.expect("Unable to change pipeline state to NULL");
}
fn main() {
// tutorials_common::run is only required to set up the application environment on macOS
// (but not necessary in normal Cocoa applications where this is set up automatically)
examples_common::run(example_main);
}

View file

@ -0,0 +1,719 @@
// This example demonstrates how to implement a custom compositor based on cairo.
#![allow(clippy::non_send_fields_in_send_ty)]
use anyhow::{Context, Error};
use gst::prelude::*;
use gst_base::prelude::*;
#[path = "../examples-common.rs"]
mod examples_common;
// Our custom compositor element is defined in this module.
mod cairo_compositor {
use gst_base::subclass::prelude::*;
use gst_video::{prelude::*, subclass::prelude::*};
// In the imp submodule we include the actual implementation of the compositor.
mod imp {
use std::sync::Mutex;
use super::*;
// Settings of the compositor.
#[derive(Clone)]
struct Settings {
background_color: u32,
}
impl Default for Settings {
fn default() -> Self {
Self {
background_color: 0xff_00_00_00,
}
}
}
// This is the private data of our compositor.
#[derive(Default)]
pub struct CairoCompositor {
settings: Mutex<Settings>,
}
// This trait registers our type with the GObject object system and
// provides the entry points for creating a new instance and setting
// up the class data.
#[glib::object_subclass]
impl ObjectSubclass for CairoCompositor {
const NAME: &'static str = "CairoCompositor";
type Type = super::CairoCompositor;
type ParentType = gst_video::VideoAggregator;
type Interfaces = (gst::ChildProxy,);
}
// Implementation of glib::Object virtual methods.
impl ObjectImpl for CairoCompositor {
// Specification of the compositor properties.
// In this case a single property for configuring the background color of the
// composition.
fn properties() -> &'static [glib::ParamSpec] {
static PROPERTIES: std::sync::OnceLock<Vec<glib::ParamSpec>> =
std::sync::OnceLock::new();
PROPERTIES.get_or_init(|| {
vec![glib::ParamSpecUInt::builder("background-color")
.nick("Background Color")
.blurb("Background color as 0xRRGGBB")
.default_value(Settings::default().background_color)
.build()]
})
}
// Called by the application whenever the value of a property should be changed.
fn set_property(&self, _id: usize, value: &glib::Value, pspec: &glib::ParamSpec) {
let mut settings = self.settings.lock().unwrap();
match pspec.name() {
"background-color" => {
settings.background_color = value.get().unwrap();
}
_ => unimplemented!(),
};
}
// Called by the application whenever the value of a property should be retrieved.
fn property(&self, _id: usize, pspec: &glib::ParamSpec) -> glib::Value {
let settings = self.settings.lock().unwrap();
match pspec.name() {
"background-color" => settings.background_color.to_value(),
_ => unimplemented!(),
}
}
}
// Implementation of gst::Object virtual methods.
impl GstObjectImpl for CairoCompositor {}
// Implementation of gst::Element virtual methods.
impl ElementImpl for CairoCompositor {
// The element specific metadata. This information is what is visible from
// gst-inspect-1.0 and can also be programmatically retrieved from the gst::Registry
// after initial registration without having to load the plugin in memory.
fn metadata() -> Option<&'static gst::subclass::ElementMetadata> {
static ELEMENT_METADATA: std::sync::OnceLock<gst::subclass::ElementMetadata> =
std::sync::OnceLock::new();
Some(ELEMENT_METADATA.get_or_init(|| {
gst::subclass::ElementMetadata::new(
"Cairo Compositor",
"Compositor/Video",
"Cairo based compositor",
"Sebastian Dröge <sebastian@centricular.com>",
)
}))
}
fn pad_templates() -> &'static [gst::PadTemplate] {
static PAD_TEMPLATES: std::sync::OnceLock<Vec<gst::PadTemplate>> =
std::sync::OnceLock::new();
PAD_TEMPLATES.get_or_init(|| {
// Create pad templates for our sink and source pad. These are later used for
// actually creating the pads and beforehand already provide information to
// GStreamer about all possible pads that could exist for this type.
// On all pads we can only handle BGRx.
let caps = gst_video::VideoCapsBuilder::new()
.format(gst_video::VideoFormat::Bgrx)
.pixel_aspect_ratio((1, 1).into())
.build();
vec![
// The src pad template must be named "src" for aggregator
// and always be there.
gst::PadTemplate::new(
"src",
gst::PadDirection::Src,
gst::PadPresence::Always,
&caps,
)
.unwrap(),
// The sink pad template must be named "sink_%u" by default for aggregator
// and be requested by the application.
//
// Also declare here that it should be a pad with our custom compositor pad
// type that is defined further below.
gst::PadTemplate::with_gtype(
"sink_%u",
gst::PadDirection::Sink,
gst::PadPresence::Request,
&caps,
super::CairoCompositorPad::static_type(),
)
.unwrap(),
]
})
}
// Notify via the child proxy interface whenever a new pad is added or removed.
fn request_new_pad(
&self,
templ: &gst::PadTemplate,
name: Option<&str>,
caps: Option<&gst::Caps>,
) -> Option<gst::Pad> {
let element = self.obj();
let pad = self.parent_request_new_pad(templ, name, caps)?;
element.child_added(&pad, &pad.name());
Some(pad)
}
fn release_pad(&self, pad: &gst::Pad) {
let element = self.obj();
element.child_removed(pad, &pad.name());
self.parent_release_pad(pad);
}
}
// Implementation of gst_base::Aggregator virtual methods.
impl AggregatorImpl for CairoCompositor {
// Called whenever a query arrives at the given sink pad of the compositor.
fn sink_query(
&self,
aggregator_pad: &gst_base::AggregatorPad,
query: &mut gst::QueryRef,
) -> bool {
use gst::QueryViewMut;
// We can accept any input caps that match the pad template. By default
// videoaggregator only allows caps that have the same format as the output.
match query.view_mut() {
QueryViewMut::Caps(q) => {
let caps = aggregator_pad.pad_template_caps();
let filter = q.filter();
let caps = if let Some(filter) = filter {
filter.intersect_with_mode(&caps, gst::CapsIntersectMode::First)
} else {
caps
};
q.set_result(&caps);
true
}
QueryViewMut::AcceptCaps(q) => {
let caps = q.caps();
let template_caps = aggregator_pad.pad_template_caps();
let res = caps.is_subset(&template_caps);
q.set_result(res);
true
}
_ => self.parent_sink_query(aggregator_pad, query),
}
}
}
// Implementation of gst_video::VideoAggregator virtual methods.
impl VideoAggregatorImpl for CairoCompositor {
// Called by videoaggregator whenever the output format should be determined.
fn find_best_format(
&self,
_downstream_caps: &gst::Caps,
) -> Option<(gst_video::VideoInfo, bool)> {
// Let videoaggregator select whatever format downstream wants.
//
// By default videoaggregator doesn't allow a different format than the input
// format.
None
}
// Called whenever a new output frame should be produced. At this point, each pad has
// either no frame queued up at all or the frame that should be used for this output
// time.
fn aggregate_frames(
&self,
token: &gst_video::subclass::AggregateFramesToken,
outbuf: &mut gst::BufferRef,
) -> Result<gst::FlowSuccess, gst::FlowError> {
let element = self.obj();
let pads = element.sink_pads();
// Map the output frame writable.
let out_info = element.video_info().unwrap();
let mut out_frame =
gst_video::VideoFrameRef::from_buffer_ref_writable(outbuf, &out_info).unwrap();
// And then create a cairo context for drawing on the output frame.
with_frame(&mut out_frame, |ctx| {
let settings = self.settings.lock().unwrap().clone();
// First of all, clear the background.
let bg = (
((settings.background_color >> 16) & 0xff) as f64 / 255.0,
((settings.background_color >> 8) & 0xff) as f64 / 255.0,
(settings.background_color & 0xff) as f64 / 255.0,
);
ctx.set_operator(cairo::Operator::Source);
ctx.set_source_rgb(bg.0, bg.1, bg.2);
ctx.paint().unwrap();
ctx.set_operator(cairo::Operator::Over);
// Then for each pad (in zorder), draw it according to the current settings.
for pad in pads {
let pad = pad.downcast_ref::<CairoCompositorPad>().unwrap();
let settings = pad.imp().settings.lock().unwrap().clone();
if settings.alpha <= 0.0 || settings.scale <= 0.0 {
continue;
}
let frame = match pad.prepared_frame(token) {
Some(frame) => frame,
None => continue,
};
ctx.save().unwrap();
ctx.translate(settings.xpos, settings.ypos);
ctx.scale(settings.scale, settings.scale);
ctx.translate(frame.width() as f64 / 2.0, frame.height() as f64 / 2.0);
ctx.rotate(settings.rotate / 360.0 * 2.0 * std::f64::consts::PI);
ctx.translate(
-(frame.width() as f64 / 2.0),
-(frame.height() as f64 / 2.0),
);
paint_frame(ctx, &frame, settings.alpha);
ctx.restore().unwrap();
}
});
Ok(gst::FlowSuccess::Ok)
}
}
// Implementation of gst::ChildProxy virtual methods.
//
// This allows accessing the pads and their properties from e.g. gst-launch.
impl ChildProxyImpl for CairoCompositor {
fn children_count(&self) -> u32 {
let object = self.obj();
object.num_pads() as u32
}
fn child_by_name(&self, name: &str) -> Option<glib::Object> {
let object = self.obj();
object
.pads()
.into_iter()
.find(|p| p.name() == name)
.map(|p| p.upcast())
}
fn child_by_index(&self, index: u32) -> Option<glib::Object> {
let object = self.obj();
object
.pads()
.into_iter()
.nth(index as usize)
.map(|p| p.upcast())
}
}
}
// Creates a cairo context around the given video frame and then calls the closure to operate
// on the cairo context. Ensures that no references to the video frame stay inside cairo.
fn with_frame<F: FnOnce(&cairo::Context)>(
frame: &mut gst_video::VideoFrameRef<&mut gst::BufferRef>,
func: F,
) {
// SAFETY: This is the one and only surface reference and it is dropped at the end, meaning
// nothing from cairo is referencing the frame data anymore.
unsafe {
use glib::translate::*;
let surface = cairo::ImageSurface::create_for_data_unsafe(
frame.plane_data_mut(0).unwrap().as_mut_ptr(),
cairo::Format::Rgb24,
frame.width() as i32,
frame.height() as i32,
frame.plane_stride()[0],
)
.unwrap();
let ctx = cairo::Context::new(&surface).unwrap();
func(&ctx);
drop(ctx);
surface.finish();
assert_eq!(
cairo::ffi::cairo_surface_get_reference_count(surface.to_glib_none().0),
1,
);
}
}
// Paints the frame with the given alpha on the cairo context at the current origin.
// Ensures that no references to the video frame stay inside cairo.
fn paint_frame(
ctx: &cairo::Context,
frame: &gst_video::VideoFrameRef<&gst::BufferRef>,
alpha: f64,
) {
// SAFETY: This is the one and only surface reference and it is dropped at the end, meaning
// nothing from cairo is referencing the frame data anymore.
//
// Also nothing is ever writing to the surface from here.
unsafe {
use glib::translate::*;
let surface = cairo::ImageSurface::create_for_data_unsafe(
frame.plane_data(0).unwrap().as_ptr() as *mut u8,
cairo::Format::Rgb24,
frame.width() as i32,
frame.height() as i32,
frame.plane_stride()[0],
)
.unwrap();
ctx.set_source_surface(&surface, 0.0, 0.0).unwrap();
ctx.paint_with_alpha(alpha).unwrap();
ctx.set_source_rgb(0.0, 0.0, 0.0);
assert_eq!(
cairo::ffi::cairo_surface_get_reference_count(surface.to_glib_none().0),
1,
);
}
}
// This here defines the public interface of our element and implements
// the corresponding traits so that it behaves like any other gst::Element.
glib::wrapper! {
pub struct CairoCompositor(ObjectSubclass<imp::CairoCompositor>) @extends gst_video::VideoAggregator, gst_base::Aggregator, gst::Element, gst::Object, @implements gst::ChildProxy;
}
impl CairoCompositor {
// Creates a new instance of our compositor with the given name.
pub fn new(name: Option<&str>) -> Self {
glib::Object::builder().property("name", name).build()
}
}
// In the imp submodule we include the implementation of the pad subclass.
//
// This doesn't implement any additional logic but only provides properties for configuring the
// appearance of the stream corresponding to this pad and the storage of the property values.
mod imp_pad {
use std::sync::Mutex;
use super::*;
// Settings of our pad.
#[derive(Clone)]
pub(super) struct Settings {
pub(super) alpha: f64,
pub(super) scale: f64,
pub(super) rotate: f64,
pub(super) xpos: f64,
pub(super) ypos: f64,
}
impl Default for Settings {
fn default() -> Self {
Self {
alpha: 1.0,
scale: 1.0,
rotate: 0.0,
xpos: 0.0,
ypos: 0.0,
}
}
}
// This is the private data of our pad.
#[derive(Default)]
pub struct CairoCompositorPad {
pub(super) settings: Mutex<Settings>,
}
// This trait registers our type with the GObject object system and
// provides the entry points for creating a new instance and setting
// up the class data.
#[glib::object_subclass]
impl ObjectSubclass for CairoCompositorPad {
const NAME: &'static str = "CairoCompositorPad";
type Type = super::CairoCompositorPad;
type ParentType = gst_video::VideoAggregatorPad;
}
// Implementation of glib::Object virtual methods.
impl ObjectImpl for CairoCompositorPad {
// Specification of the compositor pad properties.
// In this case there are various properties for defining the position and otherwise
// the appearance of the stream corresponding to this pad.
fn properties() -> &'static [glib::ParamSpec] {
static PROPERTIES: std::sync::OnceLock<Vec<glib::ParamSpec>> =
std::sync::OnceLock::new();
PROPERTIES.get_or_init(|| {
vec![
glib::ParamSpecDouble::builder("alpha")
.nick("Alpha")
.blurb("Alpha value of the input")
.minimum(0.0)
.maximum(1.0)
.default_value(Settings::default().alpha)
.build(),
glib::ParamSpecDouble::builder("scale")
.nick("Scale")
.blurb("Scale factor of the input")
.minimum(0.0)
.maximum(f64::MAX)
.default_value(Settings::default().scale)
.build(),
glib::ParamSpecDouble::builder("rotate")
.nick("Rotate")
.blurb("Rotation of the input")
.minimum(0.0)
.maximum(360.0)
.default_value(Settings::default().rotate)
.build(),
glib::ParamSpecDouble::builder("xpos")
.nick("X Position")
.blurb("Horizontal position of the input")
.minimum(0.0)
.maximum(f64::MAX)
.default_value(Settings::default().xpos)
.build(),
glib::ParamSpecDouble::builder("ypos")
.nick("Y Position")
.blurb("Vertical position of the input")
.minimum(0.0)
.maximum(f64::MAX)
.default_value(Settings::default().ypos)
.build(),
]
})
}
// Called by the application whenever the value of a property should be changed.
fn set_property(&self, _id: usize, value: &glib::Value, pspec: &glib::ParamSpec) {
let mut settings = self.settings.lock().unwrap();
match pspec.name() {
"alpha" => {
settings.alpha = value.get().unwrap();
}
"scale" => {
settings.scale = value.get().unwrap();
}
"rotate" => {
settings.rotate = value.get().unwrap();
}
"xpos" => {
settings.xpos = value.get().unwrap();
}
"ypos" => {
settings.ypos = value.get().unwrap();
}
_ => unimplemented!(),
};
}
// Called by the application whenever the value of a property should be retrieved.
fn property(&self, _id: usize, pspec: &glib::ParamSpec) -> glib::Value {
let settings = self.settings.lock().unwrap();
match pspec.name() {
"alpha" => settings.alpha.to_value(),
"scale" => settings.scale.to_value(),
"rotate" => settings.rotate.to_value(),
"xpos" => settings.xpos.to_value(),
"ypos" => settings.ypos.to_value(),
_ => unimplemented!(),
}
}
}
// Implementation of gst::Object virtual methods.
impl GstObjectImpl for CairoCompositorPad {}
// Implementation of gst::Pad virtual methods.
impl PadImpl for CairoCompositorPad {}
// Implementation of gst_base::AggregatorPad virtual methods.
impl AggregatorPadImpl for CairoCompositorPad {}
// Implementation of gst_video::VideoAggregatorPad virtual methods.
impl VideoAggregatorPadImpl for CairoCompositorPad {}
}
// This here defines the public interface of our element and implements
// the corresponding traits so that it behaves like any other gst::Pad.
glib::wrapper! {
pub struct CairoCompositorPad(ObjectSubclass<imp_pad::CairoCompositorPad>) @extends gst_video::VideoAggregatorPad, gst_base::AggregatorPad, gst::Pad, gst::Object;
}
}
fn create_pipeline() -> Result<gst::Pipeline, Error> {
gst::init()?;
// Create our pipeline with the compositor and two input streams.
let pipeline = gst::Pipeline::default();
let src1 = gst::ElementFactory::make("videotestsrc")
.property_from_str("pattern", "ball")
.build()?;
let src2 = gst::ElementFactory::make("videotestsrc")
.property_from_str("pattern", "smpte")
.build()?;
let comp = cairo_compositor::CairoCompositor::new(None);
let conv = gst::ElementFactory::make("videoconvert").build()?;
let sink = gst::ElementFactory::make("autovideosink").build()?;
comp.set_property("background-color", 0xff_33_33_33u32);
pipeline.add_many([&src1, &src2, comp.upcast_ref(), &conv, &sink])?;
// Link everything together.
src1.link_filtered(
&comp,
&gst::Caps::builder("video/x-raw")
.field("width", 320i32)
.field("height", 240i32)
.build(),
)
.context("Linking source 1")?;
src2.link_filtered(
&comp,
&gst::Caps::builder("video/x-raw")
.field("width", 320i32)
.field("height", 240i32)
.build(),
)
.context("Linking source 2")?;
comp.link_filtered(
&conv,
&gst::Caps::builder("video/x-raw")
.field("width", 1280i32)
.field("height", 720i32)
.build(),
)
.context("Linking converter")?;
conv.link(&sink).context("Linking sink")?;
// Change positions etc of both inputs based on a timer
let xmax = 1280.0 - 320.0f64;
let ymax = 720.0 - 240.0f64;
let sink_0 = comp.static_pad("sink_0").unwrap();
sink_0.set_property("xpos", 0.0f64);
sink_0.set_property("ypos", 0.0f64);
let sink_1 = comp.static_pad("sink_1").unwrap();
sink_1.set_property("xpos", xmax);
sink_1.set_property("ypos", ymax);
comp.set_emit_signals(true);
comp.connect_samples_selected(move |_agg, _seg, pts, _dts, _dur, _info| {
// Position and rotation period is 10s.
let pos = (pts.unwrap().nseconds() % gst::ClockTime::from_seconds(10).nseconds()) as f64
/ gst::ClockTime::from_seconds(10).nseconds() as f64;
let xpos = (1.0 + f64::sin(2.0 * std::f64::consts::PI * pos)) * xmax / 2.0;
let ypos = (1.0 + f64::cos(2.0 * std::f64::consts::PI * pos)) * ymax / 2.0;
sink_0.set_property("xpos", xpos);
sink_0.set_property("ypos", ypos);
let xpos = (1.0 + f64::cos(2.0 * std::f64::consts::PI * pos)) * xmax / 2.0;
let ypos = (1.0 + f64::sin(2.0 * std::f64::consts::PI * pos)) * ymax / 2.0;
sink_1.set_property("xpos", xpos);
sink_1.set_property("ypos", ypos);
sink_0.set_property("rotate", pos * 360.0);
sink_1.set_property("rotate", 360.0 - pos * 360.0);
// Alpha period is 2s.
let pos = (pts.unwrap().nseconds() % gst::ClockTime::from_seconds(2).nseconds()) as f64
/ gst::ClockTime::from_seconds(2).nseconds() as f64;
sink_0.set_property(
"alpha",
(1.0 + f64::sin(2.0 * std::f64::consts::PI * pos)) / 2.0,
);
sink_1.set_property(
"alpha",
(1.0 + f64::cos(2.0 * std::f64::consts::PI * pos)) / 2.0,
);
// Scale period is 20s.
let pos = (pts.unwrap().nseconds() % gst::ClockTime::from_seconds(20).nseconds()) as f64
/ gst::ClockTime::from_seconds(20).nseconds() as f64;
sink_0.set_property("scale", pos);
sink_1.set_property("scale", 1.0 - pos);
});
Ok(pipeline)
}
// Start the pipeline and collect messages from the bus until an error or EOS.
fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> {
pipeline.set_state(gst::State::Playing)?;
let bus = pipeline
.bus()
.expect("Pipeline without bus. Shouldn't happen!");
let mut bus_stream = bus.stream();
let main_context = glib::MainContext::default();
// Storage for any error so we can report it later.
let mut error = None;
main_context.block_on(async {
use futures::prelude::*;
while let Some(msg) = bus_stream.next().await {
use gst::MessageView;
match msg.view() {
MessageView::Eos(..) => break,
MessageView::Error(err) => {
error = Some(anyhow::anyhow!(
"Error from {:?}: {} ({:?})",
err.src().map(|s| s.path_string()),
err.error(),
err.debug()
));
break;
}
_ => (),
}
}
});
// In case of error, report to the caller.
if let Some(error) = error {
let _ = pipeline.set_state(gst::State::Null);
return Err(error);
}
pipeline.set_state(gst::State::Null)?;
Ok(())
}
fn example_main() -> Result<(), Error> {
create_pipeline().and_then(main_loop)
}
fn main() -> Result<(), Error> {
// tutorials_common::run is only required to set up the application environment on macOS
// (but not necessary in normal Cocoa applications where this is set up automatically).
examples_common::run(example_main)
}

View file

@ -21,7 +21,7 @@ impl ExampleCustomEvent {
#[allow(clippy::new_ret_no_self)]
pub fn new(send_eos: bool) -> gst::Event {
let s = gst::Structure::builder(Self::EVENT_NAME)
.field("send_eos", &send_eos)
.field("send_eos", send_eos)
.build();
gst::event::CustomDownstream::new(s)
}
@ -48,7 +48,7 @@ fn example_main() {
let main_loop = glib::MainLoop::new(None, false);
// This creates a pipeline by parsing the gst-launch pipeline syntax.
let pipeline = gst::parse_launch(
let pipeline = gst::parse::launch(
"audiotestsrc name=src ! queue max-size-time=2000000000 ! fakesink name=sink sync=true",
)
.unwrap();
@ -75,31 +75,33 @@ fn example_main() {
// Add a pad probe on the sink pad and catch the custom event we sent, then send
// an EOS event on the pipeline.
sinkpad.add_probe(gst::PadProbeType::EVENT_DOWNSTREAM, move |_, probe_info| {
match probe_info.data {
Some(gst::PadProbeData::Event(ref ev))
if ev.type_() == gst::EventType::CustomDownstream =>
{
if let Some(custom_event) = ExampleCustomEvent::parse(ev) {
if let Some(pipeline) = pipeline_weak.upgrade() {
if custom_event.send_eos {
/* Send EOS event to shut down the pipeline, but from an async callback, as we're
* in a pad probe blocking the stream thread here... */
println!("Got custom event with send_eos=true. Sending EOS");
let ev = gst::event::Eos::new();
let pipeline_weak = pipeline_weak.clone();
pipeline.call_async(move |_| {
if let Some(pipeline) = pipeline_weak.upgrade() {
pipeline.send_event(ev);
}
});
} else {
println!("Got custom event, with send_eos=false. Ignoring");
}
}
let Some(event) = probe_info.event() else {
return gst::PadProbeReturn::Ok;
};
let Some(custom_event) = ExampleCustomEvent::parse(event) else {
return gst::PadProbeReturn::Ok;
};
let Some(pipeline) = pipeline_weak.upgrade() else {
return gst::PadProbeReturn::Ok;
};
if custom_event.send_eos {
/* Send EOS event to shut down the pipeline, but from an async callback, as we're
* in a pad probe blocking the stream thread here... */
println!("Got custom event with send_eos=true. Sending EOS");
let ev = gst::event::Eos::new();
let pipeline_weak = pipeline_weak.clone();
pipeline.call_async(move |_| {
if let Some(pipeline) = pipeline_weak.upgrade() {
pipeline.send_event(ev);
}
}
_ => (),
});
} else {
println!("Got custom event, with send_eos=false. Ignoring");
}
gst::PadProbeReturn::Ok
});
@ -113,56 +115,53 @@ fn example_main() {
glib::timeout_add_seconds(2 + i as u32, move || {
// Here we temporarily retrieve a strong reference on the pipeline from the weak one
// we moved into this callback.
let pipeline = match pipeline_weak.upgrade() {
Some(pipeline) => pipeline,
None => return glib::Continue(false),
let Some(pipeline) = pipeline_weak.upgrade() else {
return glib::ControlFlow::Break;
};
println!(
"Sending custom event to the pipeline with send_eos={}",
send_eos
);
println!("Sending custom event to the pipeline with send_eos={send_eos}");
let ev = ExampleCustomEvent::new(*send_eos);
if !pipeline.send_event(ev) {
println!("Warning: Failed to send custom event");
}
// Remove this handler, the pipeline will shutdown once our pad probe catches the custom
// event and sends EOS
glib::Continue(false)
glib::ControlFlow::Break
});
}
let main_loop_clone = main_loop.clone();
// This sets the bus's signal handler (don't be mislead by the "add", there can only be one).
// Every message from the bus is passed through this function. Its returnvalue determines
// whether the handler wants to be called again. If glib::Continue(false) is returned, the
// whether the handler wants to be called again. If glib::ControlFlow::Break is returned, the
// handler is removed and will never be called again. The mainloop still runs though.
bus.add_watch(move |_, msg| {
use gst::MessageView;
let _bus_watch = bus
.add_watch(move |_, msg| {
use gst::MessageView;
let main_loop = &main_loop_clone;
match msg.view() {
MessageView::Eos(..) => {
println!("received eos");
// An EndOfStream event was sent to the pipeline, so we tell our main loop
// to stop execution here.
main_loop.quit()
}
MessageView::Error(err) => {
println!(
"Error from {:?}: {} ({:?})",
err.src().map(|s| s.path_string()),
err.error(),
err.debug()
);
main_loop.quit();
}
_ => (),
};
let main_loop = &main_loop_clone;
match msg.view() {
MessageView::Eos(..) => {
println!("received eos");
// An EndOfStream event was sent to the pipeline, so we tell our main loop
// to stop execution here.
main_loop.quit()
}
MessageView::Error(err) => {
println!(
"Error from {:?}: {} ({:?})",
err.src().map(|s| s.path_string()),
err.error(),
err.debug()
);
main_loop.quit();
}
_ => (),
};
// Tell the mainloop to continue executing this callback.
glib::Continue(true)
})
.expect("Failed to add bus watch");
// Tell the mainloop to continue executing this callback.
glib::ControlFlow::Continue
})
.expect("Failed to add bus watch");
// Operate GStreamer's bus, facilitating GLib's mainloop here.
// This function call will block until you tell the mainloop to quit
@ -172,11 +171,6 @@ fn example_main() {
pipeline
.set_state(gst::State::Null)
.expect("Unable to set the pipeline to the `Null` state");
// Remove the watch function from the bus.
// Again: There can always only be one watch function.
// Thus we don't have to tell him which function to remove.
bus.remove_watch().unwrap();
}
fn main() {

View file

@ -4,16 +4,15 @@
// an appsrc and retrieves them again from an appsink.
#![allow(clippy::non_send_fields_in_send_ty)]
use gst::element_error;
use gst::prelude::*;
use gst::{element_error, prelude::*};
#[path = "../examples-common.rs"]
mod examples_common;
mod custom_meta {
use std::{fmt, mem};
use gst::prelude::*;
use std::fmt;
use std::mem;
// Public Rust type for the custom meta.
#[repr(transparent)]
@ -46,7 +45,6 @@ mod custom_meta {
}
// Retrieve the stored label.
#[doc(alias = "get_label")]
pub fn label(&self) -> &str {
self.0.label.as_str()
}
@ -71,10 +69,9 @@ mod custom_meta {
// Actual unsafe implementation of the meta.
mod imp {
use std::{mem, ptr};
use glib::translate::*;
use once_cell::sync::Lazy;
use std::mem;
use std::ptr;
pub(super) struct CustomMetaParams {
pub label: String,
@ -89,8 +86,10 @@ mod custom_meta {
// Function to register the meta API and get a type back.
pub(super) fn custom_meta_api_get_type() -> glib::Type {
static TYPE: Lazy<glib::Type> = Lazy::new(|| unsafe {
let t = from_glib(gst::ffi::gst_meta_api_type_register(
static TYPE: std::sync::OnceLock<glib::Type> = std::sync::OnceLock::new();
*TYPE.get_or_init(|| unsafe {
let t = glib::Type::from_glib(gst::ffi::gst_meta_api_type_register(
b"MyCustomMetaAPI\0".as_ptr() as *const _,
// We provide no tags here as our meta is just a label and does
// not refer to any specific aspect of the buffer.
@ -100,9 +99,7 @@ mod custom_meta {
assert_ne!(t, glib::Type::INVALID);
t
});
*TYPE
})
}
// Initialization function for our meta. This needs to ensure all fields are correctly
@ -159,21 +156,24 @@ mod custom_meta {
unsafe impl Send for MetaInfo {}
unsafe impl Sync for MetaInfo {}
static META_INFO: Lazy<MetaInfo> = Lazy::new(|| unsafe {
MetaInfo(
ptr::NonNull::new(gst::ffi::gst_meta_register(
custom_meta_api_get_type().into_glib(),
b"MyCustomMeta\0".as_ptr() as *const _,
mem::size_of::<CustomMeta>(),
Some(custom_meta_init),
Some(custom_meta_free),
Some(custom_meta_transform),
) as *mut gst::ffi::GstMetaInfo)
.expect("Failed to register meta API"),
)
});
static META_INFO: std::sync::OnceLock<MetaInfo> = std::sync::OnceLock::new();
META_INFO.0.as_ptr()
META_INFO
.get_or_init(|| unsafe {
MetaInfo(
ptr::NonNull::new(gst::ffi::gst_meta_register(
custom_meta_api_get_type().into_glib(),
b"MyCustomMeta\0".as_ptr() as *const _,
mem::size_of::<CustomMeta>(),
Some(custom_meta_init),
Some(custom_meta_free),
Some(custom_meta_transform),
) as *mut gst::ffi::GstMetaInfo)
.expect("Failed to register meta API"),
)
})
.0
.as_ptr()
}
}
}
@ -182,15 +182,9 @@ fn example_main() {
gst::init().unwrap();
// This creates a pipeline with appsrc and appsink.
let pipeline = gst::Pipeline::new(None);
let appsrc = gst::ElementFactory::make("appsrc", None)
.unwrap()
.downcast::<gst_app::AppSrc>()
.unwrap();
let appsink = gst::ElementFactory::make("appsink", None)
.unwrap()
.downcast::<gst_app::AppSink>()
.unwrap();
let pipeline = gst::Pipeline::default();
let appsrc = gst_app::AppSrc::builder().build();
let appsink = gst_app::AppSink::builder().build();
pipeline.add(&appsrc).unwrap();
pipeline.add(&appsink).unwrap();
@ -208,13 +202,13 @@ fn example_main() {
return;
}
println!("Producing buffer {}", i);
println!("Producing buffer {i}");
// Add a custom meta with a label to this buffer.
let mut buffer = gst::Buffer::new();
{
let buffer = buffer.get_mut().unwrap();
custom_meta::CustomMeta::add(buffer, format!("This is buffer {}", i));
custom_meta::CustomMeta::add(buffer, format!("This is buffer {i}"));
}
i += 1;

View file

@ -0,0 +1,364 @@
// This example demonstrates the use of the d3d11videosink's "present"
// signal and the use of Direct2D/DirectWrite APIs in Rust.
//
// Application can perform various hardware-accelerated 2D graphics operation
// (e.g., like cairo can support) and text rendering via the Windows APIs.
// In this example, 2D graphics operation and text rendering will happen
// directly to the on the DXGI swapchain's backbuffer via Windows API in
// strictly zero-copy manner
use std::{
collections::VecDeque,
sync::{Arc, Mutex},
time::SystemTime,
};
use gst::{glib, prelude::*};
use windows::{
core::*,
Win32::Graphics::{
Direct2D::{Common::*, *},
Direct3D11::*,
DirectWrite::*,
Dxgi::{Common::*, *},
},
};
struct OverlayContext {
d2d_factory: ID2D1Factory,
dwrite_factory: IDWriteFactory,
text_format: IDWriteTextFormat,
texture_desc: D3D11_TEXTURE2D_DESC,
text_layout: Option<IDWriteTextLayout>,
timestamp_queue: VecDeque<SystemTime>,
avg_fps: f32,
display_fps: f32,
font_size: f32,
}
fn create_overlay_context() -> Arc<Mutex<OverlayContext>> {
// Lots of DirectX APIs are marked as unsafe but the below operations
// are not expected to be failed unless GPU hang or device remove condition
// happens
let d2d_factory = unsafe {
D2D1CreateFactory::<ID2D1Factory>(D2D1_FACTORY_TYPE_MULTI_THREADED, None).unwrap()
};
let dwrite_factory =
unsafe { DWriteCreateFactory::<IDWriteFactory>(DWRITE_FACTORY_TYPE_SHARED).unwrap() };
// Font size can be updated later
let text_format = unsafe {
dwrite_factory
.CreateTextFormat(
w!("Consolas"),
None,
DWRITE_FONT_WEIGHT_REGULAR,
DWRITE_FONT_STYLE_NORMAL,
DWRITE_FONT_STRETCH_NORMAL,
12f32,
w!("en-us"),
)
.unwrap()
};
Arc::new(Mutex::new(OverlayContext {
d2d_factory,
dwrite_factory,
text_format,
texture_desc: D3D11_TEXTURE2D_DESC::default(),
text_layout: None,
timestamp_queue: VecDeque::with_capacity(10),
avg_fps: 0f32,
display_fps: 0f32,
font_size: 12f32,
}))
}
fn main() -> Result<()> {
gst::init().unwrap();
let args: Vec<String> = std::env::args().collect();
if args.len() != 2 {
println!("URI must be specified");
return Ok(());
}
let main_loop = glib::MainLoop::new(None, false);
let overlay_context = create_overlay_context();
let overlay_context_weak = Arc::downgrade(&overlay_context);
// Needs BGRA or RGBA swapchain for D2D interop,
// and "present" signal must be explicitly enabled
let videosink = gst::ElementFactory::make("d3d11videosink")
.property("emit-present", true)
.property_from_str("display-format", "DXGI_FORMAT_B8G8R8A8_UNORM")
.build()
.unwrap();
// Listen "present" signal and draw overlay from the callback
// Required operations here:
// 1) Gets IDXGISurface and ID3D11Texture2D interface from
// given ID3D11RenderTargetView COM object
// - ID3D11Texture2D: To get texture resolution
// - IDXGISurface: To create Direct2D render target
// 2) Creates or reuses IDWriteTextLayout interface
// - This object represents text layout we want to draw on render target
// 3) Draw rectangle (overlay background) and text on render target
//
// NOTE: ID2D1Factory, IDWriteFactory, IDWriteTextFormat, and
// IDWriteTextLayout objects are device-independent. Which can be created
// earlier instead of creating them in the callback.
// But ID2D1RenderTarget is a device-dependent resource.
// The client should not hold the d2d render target object outside of
// this callback scope because the resource must be cleared before
// releasing/resizing DXGI swapchain.
videosink.connect_closure(
"present",
false,
glib::closure!(move |_sink: &gst::Element,
_device: &gst::Object,
rtv_raw: glib::Pointer| {
let overlay_context = overlay_context_weak.upgrade().unwrap();
let mut context = overlay_context.lock().unwrap();
let dwrite_factory = context.dwrite_factory.clone();
let d2d_factory = context.d2d_factory.clone();
// SAFETY: transmute() below is clearly unsafe operation here.
// Regarding the other part of the below block, all DirectX
// APIs are marked as unsafe, except for cast.
//
// In theory, all the Direct3D/Direct2D APIs could fail for
// some reasons (it's hardware!), but in practice, it's very unexpected
// situation and any of failure below would mean we are doing
// something in wrong way or driver bug or so.
unsafe {
let rtv = ID3D11RenderTargetView::from_raw_borrowed(&rtv_raw).unwrap();
let resource = rtv.GetResource().unwrap();
let texture = resource.cast::<ID3D11Texture2D>().unwrap();
let desc = {
let mut desc = D3D11_TEXTURE2D_DESC::default();
texture.GetDesc(&mut desc);
desc
};
// Window size was updated, creates new text layout
let calculate_font_size = if desc != context.texture_desc {
context.texture_desc = desc;
context.text_layout = None;
true
} else {
false
};
// New fps, creates new layout
if context.avg_fps != context.display_fps {
context.display_fps = context.avg_fps;
context.text_layout = None;
}
if context.text_layout.is_none() {
let overlay_string = format!("TextOverlay, Fps {:.1}", context.display_fps);
let overlay_wstring = overlay_string.encode_utf16().collect::<Vec<_>>();
let layout = dwrite_factory
.CreateTextLayout(
&overlay_wstring,
&context.text_format,
desc.Width as f32,
desc.Height as f32 / 5f32,
)
.unwrap();
// Adjust alignment
layout
.SetTextAlignment(DWRITE_TEXT_ALIGNMENT_CENTER)
.unwrap();
layout
.SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_CENTER)
.unwrap();
// XXX: This is not an efficient approach.
// The font size can be pre-calculated for a pre-defined
// window size and string length
let mut range = DWRITE_TEXT_RANGE {
startPosition: 0u32,
length: overlay_wstring.len() as u32,
};
if calculate_font_size {
let mut font_size = 12f32;
let mut was_decreased = false;
loop {
let mut metrics = DWRITE_TEXT_METRICS::default();
layout.GetMetrics(&mut metrics).unwrap();
layout
.GetFontSize(0, &mut font_size, Some(&mut range))
.unwrap();
if metrics.widthIncludingTrailingWhitespace >= desc.Width as f32 {
if font_size > 1f32 {
font_size -= 0.5f32;
was_decreased = true;
layout.SetFontSize(font_size, range).unwrap();
continue;
}
break;
}
if was_decreased {
break;
}
if metrics.widthIncludingTrailingWhitespace < desc.Width as f32 {
if metrics.widthIncludingTrailingWhitespace
>= desc.Width as f32 * 0.7f32
{
break;
}
font_size += 0.5f32;
layout.SetFontSize(font_size, range).unwrap();
}
}
context.font_size = font_size;
} else {
layout.SetFontSize(context.font_size, range).unwrap();
}
context.text_layout = Some(layout);
};
let dxgi_surf = resource.cast::<IDXGISurface>().unwrap();
let render_target = d2d_factory
.CreateDxgiSurfaceRenderTarget(
&dxgi_surf,
&D2D1_RENDER_TARGET_PROPERTIES {
r#type: D2D1_RENDER_TARGET_TYPE_DEFAULT,
pixelFormat: D2D1_PIXEL_FORMAT {
format: DXGI_FORMAT_B8G8R8A8_UNORM,
alphaMode: D2D1_ALPHA_MODE_PREMULTIPLIED,
},
// zero means default DPI
dpiX: 0f32,
dpiY: 0f32,
usage: D2D1_RENDER_TARGET_USAGE_NONE,
minLevel: D2D1_FEATURE_LEVEL_DEFAULT,
},
)
.unwrap();
let text_brush = render_target
.CreateSolidColorBrush(
&D2D1_COLOR_F {
r: 0f32,
g: 0f32,
b: 0f32,
a: 1f32,
},
None,
)
.unwrap();
let overlay_brush = render_target
.CreateSolidColorBrush(
&D2D1_COLOR_F {
r: 0f32,
g: 0.5f32,
b: 0.5f32,
a: 0.3f32,
},
None,
)
.unwrap();
render_target.BeginDraw();
// Draws overlay background. It will blend overlay's background
// color with already rendred video frame
render_target.FillRectangle(
&D2D_RECT_F {
left: 0f32,
top: 0f32,
right: desc.Width as f32,
bottom: desc.Height as f32 / 5f32,
},
&overlay_brush,
);
// Then, renders text
render_target.DrawTextLayout(
D2D_POINT_2F { x: 0f32, y: 0f32 },
context.text_layout.as_ref(),
&text_brush,
D2D1_DRAW_TEXT_OPTIONS_NONE,
);
// EndDraw may not be successful for some reasons.
// Ignores any error in this example
let _ = render_target.EndDraw(None, None);
}
}),
);
// Add pad probe to calculate framerate
let sinkpad = videosink.static_pad("sink").unwrap();
let overlay_context_weak = Arc::downgrade(&overlay_context);
sinkpad.add_probe(gst::PadProbeType::BUFFER, move |_, probe_info| {
let overlay_context = overlay_context_weak.upgrade().unwrap();
let mut context = overlay_context.lock().unwrap();
context.timestamp_queue.push_back(SystemTime::now());
// Updates framerate per 10 frames
if context.timestamp_queue.len() >= 10 {
let now = context.timestamp_queue.back().unwrap();
let front = context.timestamp_queue.front().unwrap();
let duration = now.duration_since(*front).unwrap().as_millis() as f32;
context.avg_fps = 1000f32 * (context.timestamp_queue.len() - 1) as f32 / duration;
context.timestamp_queue.clear();
}
gst::PadProbeReturn::Ok
});
let playbin = gst::ElementFactory::make("playbin")
.property("uri", &args[1])
.property("video-sink", &videosink)
.build()
.unwrap();
let main_loop_clone = main_loop.clone();
let bus = playbin.bus().unwrap();
let _bus_watch = bus
.add_watch(move |_, msg| {
use gst::MessageView;
let main_loop = &main_loop_clone;
match msg.view() {
MessageView::Eos(..) => {
println!("received eos");
main_loop.quit()
}
MessageView::Error(err) => {
println!(
"Error from {:?}: {} ({:?})",
err.src().map(|s| s.path_string()),
err.error(),
err.debug()
);
main_loop.quit();
}
_ => (),
};
glib::ControlFlow::Continue
})
.unwrap();
playbin.set_state(gst::State::Playing).unwrap();
main_loop.run();
playbin.set_state(gst::State::Null).unwrap();
Ok(())
}

View file

@ -5,11 +5,10 @@
//
// It's possible to dump the logs at any time in an application,
// not just on exit like is done here.
use gst::gst_error;
use gst::prelude::*;
use std::process;
use gst::prelude::*;
#[path = "../examples-common.rs"]
mod examples_common;
@ -20,21 +19,21 @@ fn example_main() {
/* Disable stdout debug, then configure the debug ringbuffer and enable
* all debug */
gst::debug_remove_default_log_function();
gst::log::remove_default_log_function();
/* Keep 1KB of logs per thread, removing old threads after 10 seconds */
gst::debug_add_ring_buffer_logger(1024, 10);
gst::log::add_ring_buffer_logger(1024, 10);
/* Enable all debug categories */
gst::debug_set_default_threshold(gst::DebugLevel::Log);
gst::log::set_default_threshold(gst::DebugLevel::Log);
let mut context = gst::ParseContext::new();
let pipeline =
match gst::parse_launch_full(pipeline_str, Some(&mut context), gst::ParseFlags::empty()) {
match gst::parse::launch_full(pipeline_str, Some(&mut context), gst::ParseFlags::empty()) {
Ok(pipeline) => pipeline,
Err(err) => {
if let Some(gst::ParseError::NoSuchElement) = err.kind::<gst::ParseError>() {
println!("Missing element(s): {:?}", context.missing_elements());
} else {
println!("Failed to parse pipeline: {}", err);
println!("Failed to parse pipeline: {err}");
}
process::exit(-1)
@ -71,11 +70,11 @@ fn example_main() {
.expect("Unable to set the pipeline to the `Null` state");
/* Insert a message into the debug log */
gst_error!(gst::CAT_DEFAULT, "Hi from the debug log ringbuffer example");
gst::error!(gst::CAT_DEFAULT, "Hi from the debug log ringbuffer example");
println!("Dumping debug logs\n");
for s in gst::debug_ring_buffer_logger_get_logs().iter() {
println!("{}\n------------------", s);
for s in gst::log::ring_buffer_logger_get_logs().iter() {
println!("{s}\n------------------");
}
}

View file

@ -29,34 +29,26 @@
// Especially Windows APIs tend to be quite picky about samplerate and sample-format.
// The same applies to videostreams.
use gst::element_error;
use gst::element_warning;
use gst::prelude::*;
use std::env;
#[cfg(feature = "v1_10")]
use std::sync::{Arc, Mutex};
use std::{
env,
sync::{Arc, Mutex},
};
use anyhow::Error;
use derive_more::{Display, Error};
use gst::{element_error, element_warning, prelude::*};
#[path = "../examples-common.rs"]
mod examples_common;
#[derive(Debug, Display, Error)]
#[display(fmt = "Missing element {}", _0)]
struct MissingElement(#[error(not(source))] &'static str);
#[derive(Debug, Display, Error)]
#[display(fmt = "Received error from {}: {} (debug: {:?})", src, error, debug)]
#[display(fmt = "Received error from {src}: {error} (debug: {debug:?})")]
struct ErrorMessage {
src: String,
error: String,
debug: Option<String>,
source: glib::Error,
src: glib::GString,
error: glib::Error,
debug: Option<glib::GString>,
}
#[cfg(feature = "v1_10")]
#[derive(Clone, Debug, glib::Boxed)]
#[boxed_type(name = "ErrorValue")]
struct ErrorValue(Arc<Mutex<Option<Error>>>);
@ -72,16 +64,14 @@ fn example_main() -> Result<(), Error> {
std::process::exit(-1)
};
let pipeline = gst::Pipeline::new(None);
let src = gst::ElementFactory::make("filesrc", None).map_err(|_| MissingElement("filesrc"))?;
let decodebin =
gst::ElementFactory::make("decodebin", None).map_err(|_| MissingElement("decodebin"))?;
let pipeline = gst::Pipeline::default();
let src = gst::ElementFactory::make("filesrc")
.property("location", uri)
.build()?;
let decodebin = gst::ElementFactory::make("decodebin").build()?;
// Tell the filesrc what file to load
src.set_property("location", uri);
pipeline.add_many(&[&src, &decodebin])?;
gst::Element::link_many(&[&src, &decodebin])?;
pipeline.add_many([&src, &decodebin])?;
gst::Element::link_many([&src, &decodebin])?;
// Need to move a new reference into the closure.
// !!ATTENTION!!:
@ -100,9 +90,8 @@ fn example_main() -> Result<(), Error> {
decodebin.connect_pad_added(move |dbin, src_pad| {
// Here we temporarily retrieve a strong reference on the pipeline from the weak one
// we moved into this callback.
let pipeline = match pipeline_weak.upgrade() {
Some(pipeline) => pipeline,
None => return,
let Some(pipeline) = pipeline_weak.upgrade() else {
return;
};
// Try to detect whether the raw stream decodebin provided us with
@ -137,14 +126,10 @@ fn example_main() -> Result<(), Error> {
if is_audio {
// decodebin found a raw audiostream, so we build the follow-up pipeline to
// play it on the default audio playback device (using autoaudiosink).
let queue = gst::ElementFactory::make("queue", None)
.map_err(|_| MissingElement("queue"))?;
let convert = gst::ElementFactory::make("audioconvert", None)
.map_err(|_| MissingElement("audioconvert"))?;
let resample = gst::ElementFactory::make("audioresample", None)
.map_err(|_| MissingElement("audioresample"))?;
let sink = gst::ElementFactory::make("autoaudiosink", None)
.map_err(|_| MissingElement("autoaudiosink"))?;
let queue = gst::ElementFactory::make("queue").build()?;
let convert = gst::ElementFactory::make("audioconvert").build()?;
let resample = gst::ElementFactory::make("audioresample").build()?;
let sink = gst::ElementFactory::make("autoaudiosink").build()?;
let elements = &[&queue, &convert, &resample, &sink];
pipeline.add_many(elements)?;
@ -165,14 +150,10 @@ fn example_main() -> Result<(), Error> {
} else if is_video {
// decodebin found a raw videostream, so we build the follow-up pipeline to
// display it using the autovideosink.
let queue = gst::ElementFactory::make("queue", None)
.map_err(|_| MissingElement("queue"))?;
let convert = gst::ElementFactory::make("videoconvert", None)
.map_err(|_| MissingElement("videoconvert"))?;
let scale = gst::ElementFactory::make("videoscale", None)
.map_err(|_| MissingElement("videoscale"))?;
let sink = gst::ElementFactory::make("autovideosink", None)
.map_err(|_| MissingElement("autovideosink"))?;
let queue = gst::ElementFactory::make("queue").build()?;
let convert = gst::ElementFactory::make("videoconvert").build()?;
let scale = gst::ElementFactory::make("videoscale").build()?;
let sink = gst::ElementFactory::make("autovideosink").build()?;
let elements = &[&queue, &convert, &scale, &sink];
pipeline.add_many(elements)?;
@ -202,7 +183,6 @@ fn example_main() -> Result<(), Error> {
if let Err(err) = insert_sink(is_audio, is_video) {
// The following sends a message of type Error on the bus, containing our detailed
// error information.
#[cfg(feature = "v1_10")]
element_error!(
dbin,
gst::LibraryError::Failed,
@ -212,14 +192,6 @@ fn example_main() -> Result<(), Error> {
&ErrorValue(Arc::new(Mutex::new(Some(err)))))
.build()
);
#[cfg(not(feature = "v1_10"))]
element_error!(
dbin,
gst::LibraryError::Failed,
("Failed to insert sink"),
["{}", err]
);
}
});
@ -241,49 +213,32 @@ fn example_main() -> Result<(), Error> {
MessageView::Error(err) => {
pipeline.set_state(gst::State::Null)?;
#[cfg(feature = "v1_10")]
{
match err.details() {
// This bus-message of type error contained our custom error-details struct
// that we sent in the pad-added callback above. So we unpack it and log
// the detailed error information here. details contains a glib::SendValue.
// The unpacked error is the converted to a Result::Err, stopping the
// application's execution.
Some(details) if details.name() == "error-details" => details
.get::<&ErrorValue>("error")
.unwrap()
.clone()
.0
.lock()
.unwrap()
.take()
.map(Result::Err)
.expect("error-details message without actual error"),
_ => Err(ErrorMessage {
src: msg
.src()
.map(|s| String::from(s.path_string()))
.unwrap_or_else(|| String::from("None")),
error: err.error().to_string(),
debug: err.debug(),
source: err.error(),
}
.into()),
}?;
}
#[cfg(not(feature = "v1_10"))]
{
return Err(ErrorMessage {
match err.details() {
// This bus-message of type error contained our custom error-details struct
// that we sent in the pad-added callback above. So we unpack it and log
// the detailed error information here. details contains a glib::SendValue.
// The unpacked error is the converted to a Result::Err, stopping the
// application's execution.
Some(details) if details.name() == "error-details" => details
.get::<&ErrorValue>("error")
.unwrap()
.clone()
.0
.lock()
.unwrap()
.take()
.map(Result::Err)
.expect("error-details message without actual error"),
_ => Err(ErrorMessage {
src: msg
.src()
.map(|s| String::from(s.path_string()))
.unwrap_or_else(|| String::from("None")),
error: err.error().to_string(),
.map(|s| s.path_string())
.unwrap_or_else(|| glib::GString::from("UNKNOWN")),
error: err.error(),
debug: err.debug(),
source: err.error(),
}
.into());
}
.into()),
}?;
}
MessageView::StateChanged(s) => {
println!(
@ -308,6 +263,6 @@ fn main() {
// (but not necessary in normal Cocoa applications where this is set up automatically)
match examples_common::run(example_main) {
Ok(r) => r,
Err(e) => eprintln!("Error! {}", e),
Err(e) => eprintln!("Error! {e}"),
}
}

View file

@ -8,21 +8,17 @@
// Discovered information could for example contain the stream's duration or whether it is
// seekable (filesystem) or not (some http servers).
use gst_pbutils::prelude::*;
use gst_pbutils::DiscovererInfo;
use gst_pbutils::DiscovererStreamInfo;
use std::env;
use anyhow::Error;
use derive_more::{Display, Error};
use std::env;
use gst_pbutils::{prelude::*, DiscovererInfo, DiscovererStreamInfo};
#[path = "../examples-common.rs"]
mod examples_common;
#[derive(Debug, Display, Error)]
#[display(fmt = "Discoverer error {}", _0)]
#[display(fmt = "Discoverer error {_0}")]
struct DiscovererError(#[error(not(source))] &'static str);
fn print_tags(info: &DiscovererInfo) {
@ -31,7 +27,7 @@ fn print_tags(info: &DiscovererInfo) {
let tags = info.tags();
match tags {
Some(taglist) => {
println!(" {}", taglist); // FIXME use an iterator
println!(" {taglist}"); // FIXME use an iterator
}
None => {
println!(" no tags");
@ -41,21 +37,20 @@ fn print_tags(info: &DiscovererInfo) {
fn print_stream_info(stream: &DiscovererStreamInfo) {
println!("Stream: ");
if let Some(id) = stream.stream_id() {
println!(" Stream id: {}", id);
if let Some(stream_id) = stream.stream_id() {
println!(" Stream id: {}", stream_id);
}
let caps_str = match stream.caps() {
Some(caps) => caps.to_string(),
None => String::from("--"),
};
println!(" Format: {}", caps_str);
println!(" Format: {caps_str}");
}
fn print_discoverer_info(info: &DiscovererInfo) -> Result<(), Error> {
let uri = info
.uri()
.ok_or(DiscovererError("URI should not be null"))?;
println!("URI: {}", uri);
println!("URI: {}", info.uri());
println!("Duration: {}", info.duration().display());
print_tags(info);
print_stream_info(
@ -94,7 +89,7 @@ fn run_discoverer() -> Result<(), Error> {
fn example_main() {
match run_discoverer() {
Ok(_) => (),
Err(e) => eprintln!("Error: {}", e),
Err(e) => eprintln!("Error: {e}"),
}
}

View file

@ -12,35 +12,27 @@
// {uridecodebin} -| {encodebin}-{filesink}
// \-{queue}-{videoconvert}-{videoscale}----/
use gst::element_error;
use gst::element_warning;
use gst_pbutils::prelude::*;
use std::env;
#[cfg(feature = "v1_10")]
use std::sync::{Arc, Mutex};
use std::{
env,
sync::{Arc, Mutex},
};
use anyhow::Error;
use derive_more::{Display, Error};
use gst::{element_error, element_warning};
use gst_pbutils::prelude::*;
#[path = "../examples-common.rs"]
mod examples_common;
#[derive(Debug, Display, Error)]
#[display(fmt = "Missing element {}", _0)]
struct MissingElement(#[error(not(source))] &'static str);
#[derive(Debug, Display, Error)]
#[display(fmt = "Received error from {}: {} (debug: {:?})", src, error, debug)]
#[display(fmt = "Received error from {src}: {error} (debug: {debug:?})")]
struct ErrorMessage {
src: String,
error: String,
debug: Option<String>,
source: glib::Error,
src: glib::GString,
error: glib::Error,
debug: Option<glib::GString>,
}
#[cfg(feature = "v1_10")]
#[derive(Clone, Debug, glib::Boxed)]
#[boxed_type(name = "ErrorValue")]
struct ErrorValue(Arc<Mutex<Option<Error>>>);
@ -68,8 +60,8 @@ fn configure_encodebin(encodebin: &gst::Element) {
&gst::Caps::builder("video/x-matroska").build(),
)
.name("container")
.add_profile(&(video_profile))
.add_profile(&(audio_profile))
.add_profile(video_profile)
.add_profile(audio_profile)
.build();
// Finally, apply the EncodingProfile onto our encodebin element.
@ -91,29 +83,27 @@ fn example_main() -> Result<(), Error> {
std::process::exit(-1)
};
let pipeline = gst::Pipeline::new(None);
let src = gst::ElementFactory::make("uridecodebin", None)
.map_err(|_| MissingElement("uridecodebin"))?;
let encodebin =
gst::ElementFactory::make("encodebin", None).map_err(|_| MissingElement("encodebin"))?;
let sink =
gst::ElementFactory::make("filesink", None).map_err(|_| MissingElement("filesink"))?;
src.set_property("uri", uri);
sink.set_property("location", output_file);
let pipeline = gst::Pipeline::default();
let src = gst::ElementFactory::make("uridecodebin")
.property("uri", uri)
.build()?;
let encodebin = gst::ElementFactory::make("encodebin").build()?;
let sink = gst::ElementFactory::make("filesink")
.property("location", output_file)
.build()?;
// Configure the encodebin.
// Here we tell the bin what format we expect it to create at its output.
configure_encodebin(&encodebin);
pipeline
.add_many(&[&src, &encodebin, &sink])
.add_many([&src, &encodebin, &sink])
.expect("failed to add elements to pipeline");
// It is clear from the start, that encodebin has only one src pad, so we can
// directly link it to our filesink without problems.
// The caps of encodebin's src-pad are set after we configured the encoding-profile.
// (But filesink doesn't really care about the caps at its input anyway)
gst::Element::link_many(&[&encodebin, &sink])?;
gst::Element::link_many([&encodebin, &sink])?;
// Need to move a new reference into the closure.
// !!ATTENTION!!:
@ -130,9 +120,8 @@ fn example_main() -> Result<(), Error> {
src.connect_pad_added(move |dbin, dbin_src_pad| {
// Here we temporarily retrieve a strong reference on the pipeline from the weak one
// we moved into this callback.
let pipeline = match pipeline_weak.upgrade() {
Some(pipeline) => pipeline,
None => return,
let Some(pipeline) = pipeline_weak.upgrade() else {
return;
};
let (is_audio, is_video) = {
@ -159,12 +148,9 @@ fn example_main() -> Result<(), Error> {
let link_to_encodebin = |is_audio, is_video| -> Result<(), Error> {
if is_audio {
let queue = gst::ElementFactory::make("queue", None)
.map_err(|_| MissingElement("queue"))?;
let convert = gst::ElementFactory::make("audioconvert", None)
.map_err(|_| MissingElement("audioconvert"))?;
let resample = gst::ElementFactory::make("audioresample", None)
.map_err(|_| MissingElement("audioresample"))?;
let queue = gst::ElementFactory::make("queue").build()?;
let convert = gst::ElementFactory::make("audioconvert").build()?;
let resample = gst::ElementFactory::make("audioresample").build()?;
let elements = &[&queue, &convert, &resample];
pipeline
@ -190,12 +176,9 @@ fn example_main() -> Result<(), Error> {
let sink_pad = queue.static_pad("sink").expect("queue has no sinkpad");
dbin_src_pad.link(&sink_pad)?;
} else if is_video {
let queue = gst::ElementFactory::make("queue", None)
.map_err(|_| MissingElement("queue"))?;
let convert = gst::ElementFactory::make("videoconvert", None)
.map_err(|_| MissingElement("videoconvert"))?;
let scale = gst::ElementFactory::make("videoscale", None)
.map_err(|_| MissingElement("videoscale"))?;
let queue = gst::ElementFactory::make("queue").build()?;
let convert = gst::ElementFactory::make("videoconvert").build()?;
let scale = gst::ElementFactory::make("videoscale").build()?;
let elements = &[&queue, &convert, &scale];
pipeline
@ -205,7 +188,7 @@ fn example_main() -> Result<(), Error> {
// Request a sink pad from our encodebin, that can handle a raw videostream.
// The encodebin will then automatically create an internal pipeline, that encodes
// the audio stream in the format we specified in the EncodingProfile.
// the video stream in the format we specified in the EncodingProfile.
let enc_sink_pad = encodebin
.request_pad_simple("video_%u")
.expect("Could not get video pad from encodebin");
@ -226,7 +209,6 @@ fn example_main() -> Result<(), Error> {
};
if let Err(err) = link_to_encodebin(is_audio, is_video) {
#[cfg(feature = "v1_10")]
element_error!(
dbin,
gst::LibraryError::Failed,
@ -236,14 +218,6 @@ fn example_main() -> Result<(), Error> {
&ErrorValue(Arc::new(Mutex::new(Some(err)))))
.build()
);
#[cfg(not(feature = "v1_10"))]
element_error!(
dbin,
gst::LibraryError::Failed,
("Failed to insert sink"),
["{}", err]
);
}
});
@ -261,44 +235,27 @@ fn example_main() -> Result<(), Error> {
MessageView::Error(err) => {
pipeline.set_state(gst::State::Null)?;
#[cfg(feature = "v1_10")]
{
match err.details() {
Some(details) if details.name() == "error-details" => details
.get::<&ErrorValue>("error")
.unwrap()
.clone()
.0
.lock()
.unwrap()
.take()
.map(Result::Err)
.expect("error-details message without actual error"),
_ => Err(ErrorMessage {
src: msg
.src()
.map(|s| String::from(s.path_string()))
.unwrap_or_else(|| String::from("None")),
error: err.error().to_string(),
debug: err.debug(),
source: err.error(),
}
.into()),
}?;
}
#[cfg(not(feature = "v1_10"))]
{
return Err(ErrorMessage {
match err.details() {
Some(details) if details.name() == "error-details" => details
.get::<&ErrorValue>("error")
.unwrap()
.clone()
.0
.lock()
.unwrap()
.take()
.map(Result::Err)
.expect("error-details message without actual error"),
_ => Err(ErrorMessage {
src: msg
.src()
.map(|s| String::from(s.path_string()))
.unwrap_or_else(|| String::from("None")),
error: err.error().to_string(),
.map(|s| s.path_string())
.unwrap_or_else(|| glib::GString::from("UNKNOWN")),
error: err.error(),
debug: err.debug(),
source: err.error(),
}
.into());
}
.into()),
}?;
}
MessageView::StateChanged(s) => {
println!(
@ -323,6 +280,6 @@ fn main() {
// (but not necessary in normal Cocoa applications where this is set up automatically)
match examples_common::run(example_main) {
Ok(r) => r,
Err(e) => eprintln!("Error! {}", e),
Err(e) => eprintln!("Error! {e}"),
}
}

View file

@ -30,7 +30,7 @@ fn example_main() {
let main_loop = glib::MainLoop::new(None, false);
// This creates a pipeline by parsing the gst-launch pipeline syntax.
let pipeline = gst::parse_launch("audiotestsrc ! fakesink").unwrap();
let pipeline = gst::parse::launch("audiotestsrc ! fakesink").unwrap();
let bus = pipeline.bus().unwrap();
pipeline
@ -50,14 +50,13 @@ fn example_main() {
// Add a timeout to the main loop. This closure will be executed
// in an interval of 5 seconds. The return value of the handler function
// determines whether the handler still wants to be called:
// - glib::Continue(false) - stop calling this handler, remove timeout
// - glib::Continue(true) - continue calling this handler
// - glib::ControlFlow::Break - stop calling this handler, remove timeout
// - glib::ControlFlow::Continue- continue calling this handler
glib::timeout_add_seconds(5, move || {
// Here we temporarily retrieve a strong reference on the pipeline from the weak one
// we moved into this callback.
let pipeline = match pipeline_weak.upgrade() {
Some(pipeline) => pipeline,
None => return glib::Continue(false),
let Some(pipeline) = pipeline_weak.upgrade() else {
return glib::ControlFlow::Break;
};
println!("sending eos");
@ -77,7 +76,7 @@ fn example_main() {
// Remove this handler, the pipeline will shutdown anyway, now that we
// sent the EOS event.
glib::Continue(false)
glib::ControlFlow::Break
});
//bus.add_signal_watch();
@ -85,35 +84,36 @@ fn example_main() {
let main_loop_clone = main_loop.clone();
// This sets the bus's signal handler (don't be mislead by the "add", there can only be one).
// Every message from the bus is passed through this function. Its returnvalue determines
// whether the handler wants to be called again. If glib::Continue(false) is returned, the
// whether the handler wants to be called again. If glib::ControlFlow::Break is returned, the
// handler is removed and will never be called again. The mainloop still runs though.
bus.add_watch(move |_, msg| {
use gst::MessageView;
let _bus_watch = bus
.add_watch(move |_, msg| {
use gst::MessageView;
let main_loop = &main_loop_clone;
match msg.view() {
MessageView::Eos(..) => {
println!("received eos");
// An EndOfStream event was sent to the pipeline, so we tell our main loop
// to stop execution here.
main_loop.quit()
}
MessageView::Error(err) => {
println!(
"Error from {:?}: {} ({:?})",
err.src().map(|s| s.path_string()),
err.error(),
err.debug()
);
main_loop.quit();
}
_ => (),
};
let main_loop = &main_loop_clone;
match msg.view() {
MessageView::Eos(..) => {
println!("received eos");
// An EndOfStream event was sent to the pipeline, so we tell our main loop
// to stop execution here.
main_loop.quit()
}
MessageView::Error(err) => {
println!(
"Error from {:?}: {} ({:?})",
err.src().map(|s| s.path_string()),
err.error(),
err.debug()
);
main_loop.quit();
}
_ => (),
};
// Tell the mainloop to continue executing this callback.
glib::Continue(true)
})
.expect("Failed to add bus watch");
// Tell the mainloop to continue executing this callback.
glib::ControlFlow::Continue
})
.expect("Failed to add bus watch");
// Operate GStreamer's bus, facilliating GLib's mainloop here.
// This function call will block until you tell the mainloop to quit
@ -123,11 +123,6 @@ fn example_main() {
pipeline
.set_state(gst::State::Null)
.expect("Unable to set the pipeline to the `Null` state");
// Remove the watch function from the bus.
// Again: There can always only be one watch function.
// Thus we don't have to tell him which function to remove.
bus.remove_watch().unwrap();
}
fn main() {

View file

@ -0,0 +1,481 @@
// This example demonstrates the use of the FdMemory allocator.
// It operates the following two pipelines:
// sender: {videotestsrc} - {appsink}
// receiver: {appsrc} - {FdMemoryVideoFilter} - {videoconvert} - {queue} - {autovideosink}
// The sender creates shared memory files from the appsink which are sent
// to the receiver using a unix domain socket.
// The receiver creates buffers in the appsrc using the FdMemoryAllocator from
// the received file descriptors.
// Additional to demonstrating how the FdMemoryAllocator can be used to share
// file descriptors the example implements a custom VideoFilter demonstrating
// how the file descriptor of FdMemory can be accessed in a pipeline.
// Note that instead of manual mapping the file descriptor it is also possible
// to use map_writable, which will also map the file descriptor.
use std::{
os::unix::{net::UnixStream, prelude::AsRawFd},
sync::{Arc, Mutex},
};
use anyhow::Error;
use futures::StreamExt;
use gst::{element_error, prelude::*};
use memmap2::MmapMut;
use uds::UnixStreamExt;
#[path = "../examples-common.rs"]
mod examples_common;
fn create_receiver_pipeline(
video_info: &gst_video::VideoInfo,
receiver: UnixStream,
) -> Result<gst::Pipeline, Error> {
let caps = video_info.to_caps()?;
let pipeline = gst::Pipeline::default();
let src = gst_app::AppSrc::builder()
.caps(&caps)
.do_timestamp(true)
.is_live(true)
.build();
let filter = video_filter::FdMemoryFadeInVideoFilter::default().upcast::<gst::Element>();
let convert = gst::ElementFactory::make("videoconvert").build()?;
let queue = gst::ElementFactory::make("queue").build()?;
let sink = gst::ElementFactory::make("autovideosink").build()?;
pipeline.add_many([src.upcast_ref(), &filter, &convert, &queue, &sink])?;
gst::Element::link_many([src.upcast_ref(), &filter, &convert, &queue, &sink])?;
let fd_allocator = gst_allocators::FdAllocator::new();
let video_info = video_info.clone();
let mut fd_buf = [-1; 253];
src.set_callbacks(
gst_app::AppSrcCallbacks::builder()
.need_data(move |appsrc, _| {
// Read the next fds from the socket, if 0
// is returned the sender has closed the stream
// which is handled as EOS here.
let fds = match receiver.recv_fds(&mut [0u8; 1], &mut fd_buf) {
Ok((_, 0)) => {
let _ = appsrc.end_of_stream();
return;
}
Ok((_, fds)) => fds,
Err(err) => {
gst::error_msg!(
gst::StreamError::Failed,
("failed to receive fds: {}", err)
);
return;
}
};
for fd in &fd_buf[0..fds] {
// Allocate a new FdMemory for the received file descriptor.
// It is important that the size matches the size of the
// actual backing storage. In this example we just use the
// same video info in both sides, sending and receiving.
// Pass FdMemoryFlags::NONE to make the FdMemory take
// ownership of the passed file descriptor. The file descriptor
// will be closed when the memory is released.
let memory = unsafe {
fd_allocator
.alloc(*fd, video_info.size(), gst_allocators::FdMemoryFlags::NONE)
.unwrap()
};
let mut buffer = gst::Buffer::new();
let buffer_mut = buffer.make_mut();
buffer_mut.append_memory(memory);
let _ = appsrc.push_buffer(buffer);
}
})
.build(),
);
Ok(pipeline)
}
fn create_sender_pipeline(
video_info: &gst_video::VideoInfo,
sender: UnixStream,
) -> Result<gst::Pipeline, Error> {
let sender = Arc::new(Mutex::new(sender));
let caps = video_info.to_caps()?;
let pipeline = gst::Pipeline::default();
let src = gst::ElementFactory::make("videotestsrc")
.property("num-buffers", 250i32)
.build()?;
let sink = gst::ElementFactory::make("appsink").build()?;
sink.downcast_ref::<gst_app::AppSink>()
.ok_or_else(|| anyhow::anyhow!("is not a appsink"))?
.set_caps(Some(&caps));
pipeline.add_many([&src, &sink])?;
gst::Element::link_many([&src, &sink])?;
let appsink = sink
.downcast::<gst_app::AppSink>()
.map_err(|_| anyhow::anyhow!("is not a appsink"))?;
appsink.set_callbacks(
gst_app::AppSinkCallbacks::builder()
// Add a handler to the "eos" signal
.eos({
let sender = sender.clone();
move |_| {
// Close the sender part of the UnixSocket pair, this will automatically
// create a eos in the receiving part.
let _ = sender.lock().unwrap().shutdown(std::net::Shutdown::Write);
}
})
// Add a handler to the "new-sample" signal.
.new_sample(move |appsink| {
// Pull the sample in question out of the appsink's buffer.
let sample = appsink.pull_sample().map_err(|_| gst::FlowError::Eos)?;
let buffer = sample.buffer().ok_or_else(|| {
element_error!(
appsink,
gst::ResourceError::Failed,
("Failed to get buffer from appsink")
);
gst::FlowError::Error
})?;
if buffer.n_memory() != 1 {
element_error!(
appsink,
gst::ResourceError::Failed,
("Expected buffer with single memory")
);
return Err(gst::FlowError::Error);
}
let mem = buffer.peek_memory(0);
// We can use downcast_memory_ref to check if the provided
// memory is allocated by FdMemoryAllocator or a subtype of it.
// Note: This is not used in the example, we will always copy
// the memory to a new shared memory file.
if let Some(fd_memory) = mem.downcast_memory_ref::<gst_allocators::FdMemory>() {
// As we already got a fd we can just directly send it over the socket.
// NOTE: Synchronization is left out of this example, in a real world
// application access to the memory should be synchronized.
// For example wayland provides a release callback to signal that
// the memory is no longer in use.
sender
.lock()
.unwrap()
.send_fds(&[0u8; 1], &[fd_memory.fd()])
.map_err(|_| {
element_error!(
appsink,
gst::ResourceError::Failed,
("Failed to send fd over unix stream")
);
gst::FlowError::Error
})?;
} else {
// At this point, buffer is only a reference to an existing memory region somewhere.
// When we want to access its content, we have to map it while requesting the required
// mode of access (read, read/write).
// This type of abstraction is necessary, because the buffer in question might not be
// on the machine's main memory itself, but rather in the GPU's memory.
// So mapping the buffer makes the underlying memory region accessible to us.
// See: https://gstreamer.freedesktop.org/documentation/plugin-development/advanced/allocation.html
let map = buffer.map_readable().map_err(|_| {
element_error!(
appsink,
gst::ResourceError::Failed,
("Failed to map buffer readable")
);
gst::FlowError::Error
})?;
// Note: To simplify this example we always create a new shared memory file instead
// of using a pool of buffers. When using a pool we need to make sure access to the
// file is synchronized.
let opts = memfd::MemfdOptions::default().allow_sealing(true);
let mfd = opts.create("gst-examples").map_err(|err| {
element_error!(
appsink,
gst::ResourceError::Failed,
("Failed to allocated fd: {}", err)
);
gst::FlowError::Error
})?;
mfd.as_file().set_len(map.size() as u64).map_err(|err| {
element_error!(
appsink,
gst::ResourceError::Failed,
("Failed to resize fd memory: {}", err)
);
gst::FlowError::Error
})?;
let mut seals = memfd::SealsHashSet::new();
seals.insert(memfd::FileSeal::SealShrink);
seals.insert(memfd::FileSeal::SealGrow);
mfd.add_seals(&seals).map_err(|err| {
element_error!(
appsink,
gst::ResourceError::Failed,
("Failed to add fd seals: {}", err)
);
gst::FlowError::Error
})?;
mfd.add_seal(memfd::FileSeal::SealSeal).map_err(|err| {
element_error!(
appsink,
gst::ResourceError::Failed,
("Failed to add fd seals: {}", err)
);
gst::FlowError::Error
})?;
unsafe {
let mut mmap = MmapMut::map_mut(mfd.as_file()).map_err(|_| {
element_error!(
appsink,
gst::ResourceError::Failed,
("Failed to mmap fd")
);
gst::FlowError::Error
})?;
mmap.copy_from_slice(map.as_slice());
};
sender
.lock()
.unwrap()
.send_fds(&[0u8; 1], &[mfd.as_raw_fd()])
.map_err(|_| {
element_error!(
appsink,
gst::ResourceError::Failed,
("Failed to send fd over unix stream")
);
gst::FlowError::Error
})?;
};
Ok(gst::FlowSuccess::Ok)
})
.build(),
);
Ok(pipeline)
}
async fn message_loop(bus: gst::Bus) {
let mut messages = bus.stream();
while let Some(msg) = messages.next().await {
use gst::MessageView;
// Determine whether we want to quit: on EOS or error message
// we quit, otherwise simply continue.
match msg.view() {
MessageView::Eos(..) => break,
MessageView::Error(err) => {
println!(
"Error from {:?}: {} ({:?})",
err.src().map(|s| s.path_string()),
err.error(),
err.debug()
);
break;
}
_ => (),
};
}
}
fn example_main() -> Result<(), Error> {
gst::init()?;
let video_info = gst_video::VideoInfo::builder(gst_video::VideoFormat::Bgra, 1920, 1080)
.fps(gst::Fraction::new(30, 1))
.build()?;
let (sender, receiver) = std::os::unix::net::UnixStream::pair()?;
let sender_pipeline = create_sender_pipeline(&video_info, sender)?;
let receiver_pipeline = create_receiver_pipeline(&video_info, receiver)?;
let receiver_bus = receiver_pipeline.bus().expect("pipeline without bus");
receiver_pipeline.set_state(gst::State::Playing)?;
let sender_bus = sender_pipeline.bus().expect("pipeline without bus");
sender_pipeline.set_state(gst::State::Playing)?;
futures::executor::block_on(futures::future::join(
message_loop(sender_bus),
message_loop(receiver_bus),
));
sender_pipeline.set_state(gst::State::Null)?;
receiver_pipeline.set_state(gst::State::Null)?;
Ok(())
}
fn main() {
// tutorials_common::run is only required to set up the application environment on macOS
// (but not necessary in normal Cocoa applications where this is set up automatically)
match examples_common::run(example_main) {
Ok(r) => r,
Err(e) => eprintln!("Error! {e}"),
}
}
// The purpose of this custom video filter is to demonstrate how
// the file descriptor of a FdMemory can be accessed.
mod video_filter {
glib::wrapper! {
pub struct FdMemoryFadeInVideoFilter(ObjectSubclass<imp::FdMemoryFadeInVideoFilter>) @extends gst_video::VideoFilter, gst_base::BaseTransform, gst::Element, gst::Object;
}
impl Default for FdMemoryFadeInVideoFilter {
fn default() -> Self {
glib::Object::builder().build()
}
}
mod imp {
use std::{mem::ManuallyDrop, os::unix::prelude::FromRawFd};
use anyhow::Error;
use gst::{subclass::prelude::*, PadDirection, PadPresence, PadTemplate};
use gst_app::gst_base::subclass::BaseTransformMode;
use gst_video::{prelude::*, subclass::prelude::*, VideoFrameRef};
use memmap2::MmapMut;
use once_cell::sync::Lazy;
static CAT: Lazy<gst::DebugCategory> = Lazy::new(|| {
gst::DebugCategory::new(
"fdmemoryfilter",
gst::DebugColorFlags::empty(),
Some("Example FdMemory filter"),
)
});
#[derive(Debug, Default)]
pub struct FdMemoryFadeInVideoFilter;
impl FdMemoryFadeInVideoFilter {
fn transform_fd_mem_ip(
&self,
frame: &mut VideoFrameRef<&mut gst::BufferRef>,
) -> Result<(), Error> {
let buffer = frame.buffer();
if buffer.n_memory() != 1 {
return Err(anyhow::anyhow!(
"only buffers with single memory are supported"
));
}
let mem = buffer.peek_memory(0);
if !mem.is_memory_type::<gst_allocators::FdMemory>() {
return Err(anyhow::anyhow!("only fd memory is supported"));
}
let timestamp = buffer.pts().unwrap();
let factor = (timestamp.nseconds() as f64
/ (5 * gst::ClockTime::SECOND).nseconds() as f64)
.min(1.0f64);
// If the fade-in has finished return early
if factor >= 1.0f64 {
return Ok(());
}
let fd = mem
.downcast_memory_ref::<gst_allocators::FdMemory>()
.unwrap()
.fd();
unsafe {
// We wrap the Memmfd in ManuallyDrop here because from_raw_fd takes ownership of
// the file descriptor which would close it on drop
//
// see: https://github.com/lucab/memfd-rs/issues/29
let mfd = ManuallyDrop::new(memfd::Memfd::from_raw_fd(fd));
let mut mmap = MmapMut::map_mut(mfd.as_file())?;
for pixel in mmap.chunks_exact_mut(4) {
pixel[0] = (pixel[0] as f64 * factor).clamp(0.0, 255.0) as u8;
pixel[1] = (pixel[1] as f64 * factor).clamp(0.0, 255.0) as u8;
pixel[2] = (pixel[2] as f64 * factor).clamp(0.0, 255.0) as u8;
}
}
Ok(())
}
}
impl ElementImpl for FdMemoryFadeInVideoFilter {
fn pad_templates() -> &'static [PadTemplate] {
static PAD_TEMPLATES: std::sync::OnceLock<Vec<PadTemplate>> =
std::sync::OnceLock::new();
PAD_TEMPLATES.get_or_init(|| {
let caps = gst_video::VideoCapsBuilder::new()
.format(gst_video::VideoFormat::Bgra)
.build();
vec![
PadTemplate::new("sink", PadDirection::Sink, PadPresence::Always, &caps)
.unwrap(),
PadTemplate::new("src", PadDirection::Src, PadPresence::Always, &caps)
.unwrap(),
]
})
}
}
impl BaseTransformImpl for FdMemoryFadeInVideoFilter {
const MODE: BaseTransformMode = BaseTransformMode::AlwaysInPlace;
const PASSTHROUGH_ON_SAME_CAPS: bool = false;
const TRANSFORM_IP_ON_PASSTHROUGH: bool = true;
}
impl VideoFilterImpl for FdMemoryFadeInVideoFilter {
fn transform_frame_ip(
&self,
frame: &mut VideoFrameRef<&mut gst::BufferRef>,
) -> Result<gst::FlowSuccess, gst::FlowError> {
self.transform_fd_mem_ip(frame).map_err(|err| {
gst::error!(CAT, imp: self, "Failed to transform frame`: {}", err);
gst::FlowError::Error
})?;
Ok(gst::FlowSuccess::Ok)
}
}
impl ObjectImpl for FdMemoryFadeInVideoFilter {}
impl GstObjectImpl for FdMemoryFadeInVideoFilter {}
#[glib::object_subclass]
impl ObjectSubclass for FdMemoryFadeInVideoFilter {
const NAME: &'static str = "FdMemoryVideoFilter";
type Type = super::FdMemoryFadeInVideoFilter;
type ParentType = gst_video::VideoFilter;
}
}
}

View file

@ -3,13 +3,11 @@
// or for an EOS message. When a message notifying about either of both
// is received, the future is resolved.
use gst::prelude::*;
use futures::executor::LocalPool;
use futures::prelude::*;
use std::env;
use futures::{executor::LocalPool, prelude::*};
use gst::prelude::*;
#[path = "../examples-common.rs"]
mod examples_common;
@ -44,7 +42,7 @@ fn example_main() {
gst::init().unwrap();
// Create a pipeline from the launch-syntax given on the cli.
let pipeline = gst::parse_launch(&pipeline_str).unwrap();
let pipeline = gst::parse::launch(&pipeline_str).unwrap();
let bus = pipeline.bus().unwrap();
pipeline

View file

@ -35,12 +35,10 @@
// those with lowers (higher number). Thus, Layers with higher priority are "in the front".
// - The timeline is the enclosing element, grouping all layers and providing a timeframe.
use gst::prelude::*;
use std::env;
use ges::prelude::*;
use std::env;
#[allow(unused_imports)]
#[path = "../examples-common.rs"]
mod examples_common;
@ -60,12 +58,12 @@ fn configure_pipeline(pipeline: &ges::Pipeline, output_name: &str) {
let container_profile =
gst_pbutils::EncodingContainerProfile::builder(&gst::Caps::builder("video/webm").build())
.name("container")
.add_profile(&video_profile)
.add_profile(&audio_profile)
.add_profile(video_profile)
.add_profile(audio_profile)
.build();
// Apply the EncodingProfile to the pipeline, and set it to render mode
let output_uri = format!("{}.webm", output_name);
let output_uri = format!("{output_name}.webm");
pipeline
.set_render_settings(&output_uri, &container_profile)
.expect("Failed to set render settings");
@ -170,7 +168,7 @@ fn example_main() {
match main_loop(input_uri, output) {
Ok(r) => r,
Err(e) => eprintln!("Error! {}", e),
Err(e) => eprintln!("Error! {e}"),
}
}

View file

@ -1,5 +1,7 @@
#![allow(clippy::non_send_fields_in_send_ty)]
use anyhow::Result;
#[path = "../glupload.rs"]
mod glupload;
use glupload::*;
@ -28,16 +30,18 @@ void main () {
"#;
mod mirror {
use super::{gl, FRAGMENT_SHADER};
use gst_base::subclass::BaseTransformMode;
use gst_gl::prelude::*;
use gst_gl::subclass::prelude::*;
use gst_gl::subclass::GLFilterMode;
use gst_gl::*;
use once_cell::sync::Lazy;
use std::sync::Mutex;
use gst_base::subclass::BaseTransformMode;
use gst_gl::{
prelude::*,
subclass::{prelude::*, GLFilterMode},
*,
};
use once_cell::sync::Lazy;
use super::{gl, FRAGMENT_SHADER};
pub static CAT: Lazy<gst::DebugCategory> = Lazy::new(|| {
gst::DebugCategory::new(
"rsglmirrorfilter",
@ -52,7 +56,7 @@ mod mirror {
impl GLMirrorFilter {
pub fn new(name: Option<&str>) -> Self {
glib::Object::new(&[("name", &name)]).expect("Failed to create GL Mirror Filter Object")
glib::Object::builder().property("name", name).build()
}
}
@ -67,20 +71,16 @@ mod mirror {
}
impl GLMirrorFilter {
fn create_shader(
&self,
filter: &<Self as ObjectSubclass>::Type,
context: &GLContext,
) -> Result<(), gst::LoggableError> {
fn create_shader(&self, context: &GLContext) -> Result<(), gst::LoggableError> {
let shader = GLShader::new(context);
let vertex = GLSLStage::new_default_vertex(context);
vertex.compile().unwrap();
shader.attach_unlocked(&vertex)?;
gst::gst_debug!(
gst::debug!(
CAT,
obj: filter,
imp: self,
"Compiling fragment shader {}",
FRAGMENT_SHADER
);
@ -97,9 +97,9 @@ mod mirror {
shader.attach_unlocked(&fragment)?;
shader.link().unwrap();
gst::gst_debug!(
gst::debug!(
CAT,
obj: filter,
imp: self,
"Successfully compiled and linked {:?}",
shader
);
@ -127,12 +127,14 @@ mod mirror {
const TRANSFORM_IP_ON_PASSTHROUGH: bool = false;
}
impl GLBaseFilterImpl for GLMirrorFilter {
fn gl_start(&self, filter: &Self::Type) -> Result<(), gst::LoggableError> {
fn gl_start(&self) -> Result<(), gst::LoggableError> {
let filter = self.obj();
// Create a shader when GL is started, knowing that the OpenGL context is
// available.
let context = GLBaseFilterExt::context(filter).unwrap();
self.create_shader(filter, &context)?;
self.parent_gl_start(filter)
let context = GLBaseFilterExt::context(&*filter).unwrap();
self.create_shader(&context)?;
self.parent_gl_start()
}
}
impl GLFilterImpl for GLMirrorFilter {
@ -140,10 +142,11 @@ mod mirror {
fn filter_texture(
&self,
filter: &Self::Type,
input: &gst_gl::GLMemory,
output: &gst_gl::GLMemory,
) -> Result<(), gst::LoggableError> {
let filter = self.obj();
let shader = self.shader.lock().unwrap();
// Use the underlying filter implementation to transform the input texture into
// an output texture with the shader.
@ -154,20 +157,18 @@ mod mirror {
.as_ref()
.expect("No shader, call `create_shader` first!"),
);
self.parent_filter_texture(filter, input, output)
self.parent_filter_texture(input, output)
}
}
}
}
fn example_main() {
fn example_main() -> Result<()> {
gst::init().unwrap();
let glfilter = mirror::GLMirrorFilter::new(Some("foo"));
App::new(Some(glfilter.as_ref()))
.and_then(main_loop)
.unwrap_or_else(|e| eprintln!("Error! {}", e))
let glfilter = mirror::GLMirrorFilter::new(Some("Mirror filter"));
App::new(Some(glfilter.as_ref())).and_then(main_loop)
}
fn main() {
examples_common::run(example_main);
fn main() -> Result<()> {
examples_common::run(example_main)
}

View file

@ -1,8 +1,7 @@
use gst::prelude::*;
use std::env;
use futures::prelude::*;
use std::env;
use gst::prelude::*;
#[path = "../examples-common.rs"]
mod examples_common;
@ -43,7 +42,7 @@ fn example_main() {
gst::init().unwrap();
// Create a pipeline from the launch-syntax given on the cli.
let pipeline = gst::parse_launch(&pipeline_str).unwrap();
let pipeline = gst::parse::launch(&pipeline_str).unwrap();
let bus = pipeline.bus().unwrap();
pipeline

View file

@ -1,5 +1,7 @@
#![allow(clippy::non_send_fields_in_send_ty)]
use anyhow::Result;
#[path = "../glupload.rs"]
mod glupload;
use glupload::*;
@ -7,12 +9,10 @@ use glupload::*;
#[path = "../examples-common.rs"]
pub mod examples_common;
fn example_main() {
App::new(None)
.and_then(main_loop)
.unwrap_or_else(|e| eprintln!("Error! {}", e))
fn example_main() -> Result<()> {
App::new(None).and_then(main_loop)
}
fn main() {
examples_common::run(example_main);
fn main() -> Result<()> {
examples_common::run(example_main)
}

View file

@ -1,177 +0,0 @@
// This example demonstrates how to use gstreamer in conjunction with the gtk widget toolkit.
// This example shows the video produced by a videotestsrc within a small gtk gui.
// For this, the gtkglsink is used, which creates a gtk widget one can embed the gtk gui.
// For this, there multiple types of widgets. gtkglsink uses OpenGL to render frames, and
// gtksink uses the CPU to render the frames (which is way slower).
// So the example application first tries to use OpenGL, and when that fails, fall back.
// The pipeline looks like the following:
// gtk-gui: {gtkglsink}-widget
// (|)
// {videotestsrc} - {glsinkbin}
use gst::prelude::*;
use gio::prelude::*;
use gtk::prelude::*;
use std::cell::RefCell;
fn create_ui(app: &gtk::Application) {
let pipeline = gst::Pipeline::new(None);
let src = gst::ElementFactory::make("videotestsrc", None).unwrap();
// Create the gtk sink and retrieve the widget from it. The sink element will be used
// in the pipeline, and the widget will be embedded in our gui.
// Gstreamer then displays frames in the gtk widget.
// First, we try to use the OpenGL version - and if that fails, we fall back to non-OpenGL.
let (sink, widget) = if let Ok(gtkglsink) = gst::ElementFactory::make("gtkglsink", None) {
// Using the OpenGL widget succeeded, so we are in for a nice playback experience with
// low cpu usage. :)
// The gtkglsink essentially allocates an OpenGL texture on the GPU, that it will display.
// Now we create the glsinkbin element, which is responsible for conversions and for uploading
// video frames to our texture (if they are not already in the GPU). Now we tell the OpenGL-sink
// about our gtkglsink element, form where it will retrieve the OpenGL texture to fill.
let glsinkbin = gst::ElementFactory::make("glsinkbin", None).unwrap();
glsinkbin.set_property("sink", &gtkglsink);
// The gtkglsink creates the gtk widget for us. This is accessible through a property.
// So we get it and use it later to add it to our gui.
let widget = gtkglsink.property::<gtk::Widget>("widget");
(glsinkbin, widget)
} else {
// Unfortunately, using the OpenGL widget didn't work out, so we will have to render
// our frames manually, using the CPU. An example why this may fail is, when
// the PC doesn't have proper graphics drivers installed.
let sink = gst::ElementFactory::make("gtksink", None).unwrap();
// The gtksink creates the gtk widget for us. This is accessible through a property.
// So we get it and use it later to add it to our gui.
let widget = sink.property::<gtk::Widget>("widget");
(sink, widget)
};
pipeline.add_many(&[&src, &sink]).unwrap();
src.link(&sink).unwrap();
// Create a simple gtk gui window to place our widget into.
let window = gtk::Window::new(gtk::WindowType::Toplevel);
window.set_default_size(320, 240);
let vbox = gtk::Box::new(gtk::Orientation::Vertical, 0);
// Add our widget to the gui
vbox.pack_start(&widget, true, true, 0);
let label = gtk::Label::new(Some("Position: 00:00:00"));
vbox.pack_start(&label, true, true, 5);
window.add(&vbox);
window.show_all();
app.add_window(&window);
// Need to move a new reference into the closure.
// !!ATTENTION!!:
// It might seem appealing to use pipeline.clone() here, because that greatly
// simplifies the code within the callback. What this actually does, however, is creating
// a memory leak. The clone of a pipeline is a new strong reference on the pipeline.
// Storing this strong reference of the pipeline within the callback (we are moving it in!),
// which is in turn stored in another strong reference on the pipeline is creating a
// reference cycle.
// DO NOT USE pipeline.clone() TO USE THE PIPELINE WITHIN A CALLBACK
let pipeline_weak = pipeline.downgrade();
// Add a timeout to the main loop that will periodically (every 500ms) be
// executed. This will query the current position within the stream from
// the underlying pipeline, and display it in our gui.
// Since this closure is called by the mainloop thread, we are allowed
// to modify the gui widgets here.
let timeout_id = glib::timeout_add_local(std::time::Duration::from_millis(500), move || {
// Here we temporarily retrieve a strong reference on the pipeline from the weak one
// we moved into this callback.
let pipeline = match pipeline_weak.upgrade() {
Some(pipeline) => pipeline,
None => return glib::Continue(true),
};
// Query the current playing position from the underlying pipeline.
let position = pipeline.query_position::<gst::ClockTime>();
// Display the playing position in the gui.
label.set_text(&format!("Position: {:.0}", position.display()));
// Tell the callback to continue calling this closure.
glib::Continue(true)
});
let bus = pipeline.bus().unwrap();
pipeline
.set_state(gst::State::Playing)
.expect("Unable to set the pipeline to the `Playing` state");
let app_weak = app.downgrade();
bus.add_watch_local(move |_, msg| {
use gst::MessageView;
let app = match app_weak.upgrade() {
Some(app) => app,
None => return glib::Continue(false),
};
match msg.view() {
MessageView::Eos(..) => app.quit(),
MessageView::Error(err) => {
println!(
"Error from {:?}: {} ({:?})",
err.src().map(|s| s.path_string()),
err.error(),
err.debug()
);
app.quit();
}
_ => (),
};
glib::Continue(true)
})
.expect("Failed to add bus watch");
// Pipeline reference is owned by the closure below, so will be
// destroyed once the app is destroyed
let timeout_id = RefCell::new(Some(timeout_id));
let pipeline = RefCell::new(Some(pipeline));
app.connect_shutdown(move |_| {
// Optional, by manually destroying the window here we ensure that
// the gst element is destroyed when shutting down instead of having to wait
// for the process to terminate, allowing us to use the leaks tracer.
unsafe {
window.destroy();
}
// GTK will keep the Application alive for the whole process lifetime.
// Wrapping the pipeline in a RefCell<Option<_>> and removing it from it here
// ensures the pipeline is actually destroyed when shutting down, allowing us
// to use the leaks tracer for example.
if let Some(pipeline) = pipeline.borrow_mut().take() {
pipeline
.set_state(gst::State::Null)
.expect("Unable to set the pipeline to the `Null` state");
pipeline.bus().unwrap().remove_watch().unwrap();
}
if let Some(timeout_id) = timeout_id.borrow_mut().take() {
timeout_id.remove();
}
});
}
fn main() {
// Initialize gstreamer and the gtk widget toolkit libraries.
gst::init().unwrap();
gtk::init().unwrap();
{
let app = gtk::Application::new(None, gio::ApplicationFlags::FLAGS_NONE);
app.connect_activate(create_ui);
app.run();
}
// Optional, can be used to detect leaks using the leaks tracer
unsafe {
gst::deinit();
}
}

View file

@ -1,288 +0,0 @@
// This example demonstrates another type of combination of gtk and gstreamer,
// in comparision to the gtksink example.
// This example uses regions that are managed by the window system, and uses
// the window system's api to insert a videostream into these regions.
// So essentially, the window system of the system overlays our gui with
// the video frames - within the region that we tell it to use.
// Disadvantage of this method is, that it's highly platform specific, since
// the big platforms all have their own window system. Thus, this example
// has special code to handle differences between platforms.
// Windows could theoretically be supported by this example, but is not yet implemented.
// One of the very few (if not the single one) platform, that can not provide the API
// needed for this are Linux desktops using Wayland.
// TODO: Add Windows support
// In this case, a testvideo is displayed within our gui, using the
// following pipeline:
// {videotestsrc} - {xvimagesink(on linux)}
// {videotestsrc} - {glimagesink(on mac)}
use gst_video::prelude::*;
use gio::prelude::*;
use gtk::prelude::*;
use std::os::raw::c_void;
use std::cell::RefCell;
use std::process;
#[cfg(all(target_os = "linux", feature = "gtkvideooverlay-x11"))]
fn create_video_sink() -> gst::Element {
// When we are on linux with the Xorg display server, we use the
// X11 protocol's XV extension, which allows to overlay regions
// with video streams. For this, we use the xvimagesink element.
gst::ElementFactory::make("xvimagesink", None).unwrap()
}
#[cfg(all(target_os = "linux", feature = "gtkvideooverlay-x11"))]
fn set_window_handle(video_overlay: &gst_video::VideoOverlay, gdk_window: &gdk::Window) {
let display_type_name = gdk_window.display().type_().name();
// Check if we're using X11 or ...
if display_type_name == "GdkX11Display" {
extern "C" {
pub fn gdk_x11_window_get_xid(window: *mut glib::object::GObject) -> *mut c_void;
}
// This is unsafe because the "window handle" we pass here is basically like a raw pointer.
// If a wrong value were to be passed here (and you can pass any integer), then the window
// system will most likely cause the application to crash.
#[allow(clippy::cast_ptr_alignment)]
unsafe {
// Here we ask gdk what native window handle we got assigned for
// our video region from the window system, and then we will
// pass this unique identifier to the overlay provided by our
// sink - so the sink can then arrange the overlay.
let xid = gdk_x11_window_get_xid(gdk_window.as_ptr() as *mut _);
video_overlay.set_window_handle(xid as usize);
}
} else {
println!("Add support for display type '{}'", display_type_name);
process::exit(-1);
}
}
#[cfg(all(target_os = "macos", feature = "gtkvideooverlay-quartz"))]
fn create_video_sink() -> gst::Element {
// On Mac, this is done by overlaying a window region with an
// OpenGL-texture, using the glimagesink element.
gst::ElementFactory::make("glimagesink", None).unwrap()
}
#[cfg(all(target_os = "macos", feature = "gtkvideooverlay-quartz"))]
fn set_window_handle(video_overlay: &gst_video::VideoOverlay, gdk_window: &gdk::Window) {
let display_type_name = gdk_window.display().type_().name();
if display_type_name == "GdkQuartzDisplay" {
extern "C" {
pub fn gdk_quartz_window_get_nsview(window: *mut glib::object::GObject) -> *mut c_void;
}
// This is unsafe because the "window handle" we pass here is basically like a raw pointer.
// If a wrong value were to be passed here (and you can pass any integer), then the window
// system will most likely cause the application to crash.
#[allow(clippy::cast_ptr_alignment)]
unsafe {
// Here we ask gdk what native window handle we got assigned for
// our video region from the windowing system, and then we will
// pass this unique identifier to the overlay provided by our
// sink - so the sink can then arrange the overlay.
let window = gdk_quartz_window_get_nsview(gdk_window.as_ptr() as *mut _);
video_overlay.set_window_handle(window as usize);
}
} else {
println!("Unsupported display type '{}", display_type_name);
process::exit(-1);
}
}
fn create_ui(app: &gtk::Application) {
let pipeline = gst::Pipeline::new(None);
let src = gst::ElementFactory::make("videotestsrc", None).unwrap();
// Since using the window system to overlay our gui window is making
// direct contact with the windowing system, this is highly platform-
// specific. This example supports Linux and Mac (using X11 and Quartz).
let sink = create_video_sink();
pipeline.add_many(&[&src, &sink]).unwrap();
src.link(&sink).unwrap();
// First, we create our gtk window - which will contain a region where
// our overlayed video will be displayed in.
let window = gtk::Window::new(gtk::WindowType::Toplevel);
window.set_default_size(320, 240);
let vbox = gtk::Box::new(gtk::Orientation::Vertical, 0);
// This creates the widget we will display our overlay in.
// Later, we will try to tell our window system about this region, so
// it can overlay it with our video stream.
let video_window = gtk::DrawingArea::new();
video_window.set_size_request(320, 240);
// Use the platform-specific sink to create our overlay.
// Since we only use the video_overlay in the closure below, we need a weak reference.
// !!ATTENTION!!:
// It might seem appealing to use .clone() here, because that greatly
// simplifies the code within the callback. What this actually does, however, is creating
// a memory leak.
let video_overlay = sink
.dynamic_cast::<gst_video::VideoOverlay>()
.unwrap()
.downgrade();
// Connect to this widget's realize signal, which will be emitted
// after its display has been initialized. This is neccessary, because
// the window system doesn't know about our region until it was initialized.
video_window.connect_realize(move |video_window| {
// Here we temporarily retrieve a strong reference on the video-overlay from the
// weak reference that we moved into the closure.
let video_overlay = match video_overlay.upgrade() {
Some(video_overlay) => video_overlay,
None => return,
};
// Gtk uses gdk under the hood, to handle its drawing. Drawing regions are
// called gdk windows. We request this underlying drawing region from the
// widget we will overlay with our video.
let gdk_window = video_window.window().unwrap();
// This is where we tell our window system about the drawing-region we
// want it to overlay. Most often, the window system would only know
// about our most outer region (or: our window).
if !gdk_window.ensure_native() {
println!("Can't create native window for widget");
process::exit(-1);
}
set_window_handle(&video_overlay, &gdk_window);
});
vbox.pack_start(&video_window, true, true, 0);
let label = gtk::Label::new(Some("Position: 00:00:00"));
vbox.pack_start(&label, true, true, 5);
window.add(&vbox);
window.show_all();
app.add_window(&window);
// Need to move a new reference into the closure.
// !!ATTENTION!!:
// It might seem appealing to use pipeline.clone() here, because that greatly
// simplifies the code within the callback. What this actually does, however, is creating
// a memory leak. The clone of a pipeline is a new strong reference on the pipeline.
// Storing this strong reference of the pipeline within the callback (we are moving it in!),
// which is in turn stored in another strong reference on the pipeline is creating a
// reference cycle.
// DO NOT USE pipeline.clone() TO USE THE PIPELINE WITHIN A CALLBACK
let pipeline_weak = pipeline.downgrade();
// Add a timeout to the main loop that will periodically (every 500ms) be
// executed. This will query the current position within the stream from
// the underlying pipeline, and display it in our gui.
// Since this closure is called by the mainloop thread, we are allowed
// to modify the gui widgets here.
let timeout_id = glib::timeout_add_local(std::time::Duration::from_millis(500), move || {
// Here we temporarily retrieve a strong reference on the pipeline from the weak one
// we moved into this callback.
let pipeline = match pipeline_weak.upgrade() {
Some(pipeline) => pipeline,
None => return glib::Continue(false),
};
// Query the current playing position from the underlying pipeline.
let position = pipeline.query_position::<gst::ClockTime>();
// Display the playing position in the gui.
label.set_text(&format!("Position: {:.0}", position.display()));
// Tell the timeout to continue calling this callback.
glib::Continue(true)
});
let bus = pipeline.bus().unwrap();
pipeline
.set_state(gst::State::Playing)
.expect("Unable to set the pipeline to the `Playing` state");
let app_weak = app.downgrade();
bus.add_watch_local(move |_, msg| {
use gst::MessageView;
let app = match app_weak.upgrade() {
Some(app) => app,
None => return glib::Continue(false),
};
match msg.view() {
MessageView::Eos(..) => app.quit(),
MessageView::Error(err) => {
println!(
"Error from {:?}: {} ({:?})",
err.src().map(|s| s.path_string()),
err.error(),
err.debug()
);
app.quit();
}
_ => (),
};
glib::Continue(true)
})
.expect("Failed to add bus watch");
// Pipeline reference is owned by the closure below, so will be
// destroyed once the app is destroyed
let timeout_id = RefCell::new(Some(timeout_id));
let pipeline = RefCell::new(Some(pipeline));
app.connect_shutdown(move |_| {
// Optional, by manually destroying the window here we ensure that
// the gst element is destroyed when shutting down instead of having to wait
// for the process to terminate, allowing us to use the leaks tracer.
unsafe {
window.destroy();
}
// GTK will keep the Application alive for the whole process lifetime.
// Wrapping the pipeline in a RefCell<Option<_>> and removing it from it here
// ensures the pipeline is actually destroyed when shutting down, allowing us
// to use the leaks tracer for example.
if let Some(pipeline) = pipeline.borrow_mut().take() {
pipeline
.set_state(gst::State::Null)
.expect("Unable to set the pipeline to the `Null` state");
pipeline.bus().unwrap().remove_watch().unwrap();
}
if let Some(timeout_id) = timeout_id.borrow_mut().take() {
timeout_id.remove();
}
});
}
fn main() {
#[cfg(not(unix))]
{
println!("Add support for target platform");
process::exit(-1);
}
// Initialize gstreamer and the gtk widget toolkit libraries.
gst::init().unwrap();
gtk::init().unwrap();
{
let app = gtk::Application::new(None, gio::ApplicationFlags::FLAGS_NONE);
app.connect_activate(create_ui);
app.run();
}
// Optional, can be used to detect leaks using the leaks tracer
unsafe {
gst::deinit();
}
}

View file

@ -1,5 +1,5 @@
// This example demonstrates how to use GStreamer's iteration APIs.
// This is used at multiple occassions - for example to iterate an
// This is used at multiple occasions - for example to iterate an
// element's pads.
use gst::prelude::*;
@ -13,7 +13,7 @@ fn example_main() {
// Create and use an identity element here.
// This element does nothing, really. We also never add it to a pipeline.
// We just want to iterate the identity element's pads.
let identity = gst::ElementFactory::make("identity", None).unwrap();
let identity = gst::ElementFactory::make("identity").build().unwrap();
// Get an iterator over all pads of the identity-element.
let mut iter = identity.iterate_pads();
loop {

View file

@ -3,10 +3,9 @@
// as launch syntax.
// When the parsing succeeded, the pipeline is run until the stream ends or an error happens.
use gst::prelude::*;
use std::{env, process};
use std::env;
use std::process;
use gst::prelude::*;
#[path = "../examples-common.rs"]
mod examples_common;
@ -18,7 +17,7 @@ fn example_main() {
gst::init().unwrap();
// Let GStreamer create a pipeline from the parsed launch syntax on the cli.
// In comparision to the launch_glib_main example, this is using the advanced launch syntax
// In comparison to the launch_glib_main example, this is using the advanced launch syntax
// parsing API of GStreamer. The function returns a Result, handing us the pipeline if
// parsing and creating succeeded, and hands us detailed error information if something
// went wrong. The error is passed as gst::ParseError. In this example, we separately
@ -27,19 +26,22 @@ fn example_main() {
// Especially GUIs should probably handle this case, to tell users that they need to
// install the corresponding gstreamer plugins.
let mut context = gst::ParseContext::new();
let pipeline =
match gst::parse_launch_full(&pipeline_str, Some(&mut context), gst::ParseFlags::empty()) {
Ok(pipeline) => pipeline,
Err(err) => {
if let Some(gst::ParseError::NoSuchElement) = err.kind::<gst::ParseError>() {
println!("Missing element(s): {:?}", context.missing_elements());
} else {
println!("Failed to parse pipeline: {}", err);
}
process::exit(-1)
let pipeline = match gst::parse::launch_full(
&pipeline_str,
Some(&mut context),
gst::ParseFlags::empty(),
) {
Ok(pipeline) => pipeline,
Err(err) => {
if let Some(gst::ParseError::NoSuchElement) = err.kind::<gst::ParseError>() {
println!("Missing element(s): {:?}", context.missing_elements());
} else {
println!("Failed to parse pipeline: {err}");
}
};
process::exit(-1)
}
};
let bus = pipeline.bus().unwrap();
pipeline

View file

@ -7,10 +7,10 @@
// things from the main loop (timeouts, UI events, socket events, ...) instead
// of just handling messages from GStreamer's bus.
use gst::prelude::*;
use std::env;
use gst::prelude::*;
#[path = "../examples-common.rs"]
mod examples_common;
@ -24,7 +24,7 @@ fn example_main() {
let main_loop = glib::MainLoop::new(None, false);
// Let GStreamer create a pipeline from the parsed launch syntax on the cli.
let pipeline = gst::parse_launch(&pipeline_str).unwrap();
let pipeline = gst::parse::launch(&pipeline_str).unwrap();
let bus = pipeline.bus().unwrap();
pipeline
@ -35,38 +35,34 @@ fn example_main() {
//bus.add_signal_watch();
//bus.connect_message(None, move |_, msg| {
bus.add_watch(move |_, msg| {
use gst::MessageView;
let _bus_watch = bus
.add_watch(move |_, msg| {
use gst::MessageView;
let main_loop = &main_loop_clone;
match msg.view() {
MessageView::Eos(..) => main_loop.quit(),
MessageView::Error(err) => {
println!(
"Error from {:?}: {} ({:?})",
err.src().map(|s| s.path_string()),
err.error(),
err.debug()
);
main_loop.quit();
}
_ => (),
};
let main_loop = &main_loop_clone;
match msg.view() {
MessageView::Eos(..) => main_loop.quit(),
MessageView::Error(err) => {
println!(
"Error from {:?}: {} ({:?})",
err.src().map(|s| s.path_string()),
err.error(),
err.debug()
);
main_loop.quit();
}
_ => (),
};
glib::Continue(true)
})
.expect("Failed to add bus watch");
glib::ControlFlow::Continue
})
.expect("Failed to add bus watch");
main_loop.run();
pipeline
.set_state(gst::State::Null)
.expect("Unable to set the pipeline to the `Null` state");
// Here we remove the bus watch we added above. This avoids a memory leak, that might
// otherwise happen because we moved a strong reference (clone of main_loop) into the
// callback closure above.
bus.remove_watch().unwrap();
}
fn main() {

View file

@ -0,0 +1,359 @@
// This example demonstrates how to draw an overlay on a video stream using
// Direct2D/DirectWrite/WIC and the overlay composition element.
// {videotestsrc} - {overlaycomposition} - {capsfilter} - {videoconvert} - {autovideosink}
// The capsfilter element allows us to dictate the video resolution we want for the
// videotestsrc and the overlaycomposition element.
use std::sync::{Arc, Mutex};
use byte_slice_cast::*;
use anyhow::Error;
use derive_more::{Display, Error};
use gst::prelude::*;
use windows::{
Foundation::Numerics::*,
Win32::{
Graphics::{
Direct2D::{Common::*, *},
DirectWrite::*,
Dxgi::Common::*,
Imaging::*,
},
System::Com::*,
},
};
#[derive(Debug, Display, Error)]
#[display(fmt = "Received error from {}: {} (debug: {:?})", src, error, debug)]
struct ErrorMessage {
src: glib::GString,
error: glib::Error,
debug: Option<glib::GString>,
}
struct DrawingContext {
// Factory for creating render target
d2d_factory: ID2D1Factory,
// Used to create WIC bitmap surface
wic_factory: IWICImagingFactory,
// text layout holding text information (string, font, size, etc)
text_layout: IDWriteTextLayout,
// Holding rendred image
bitmap: Option<IWICBitmap>,
// Bound to bitmap and used to actual Direct2D rendering
render_target: Option<ID2D1RenderTarget>,
info: Option<gst_video::VideoInfo>,
}
// Required for IWICBitmap
unsafe impl Send for DrawingContext {}
fn create_pipeline() -> Result<gst::Pipeline, Error> {
gst::init()?;
let pipeline = gst::Pipeline::default();
// The videotestsrc supports multiple test patterns. In this example, we will use the
// pattern with a white ball moving around the video's center point.
let src = gst::ElementFactory::make("videotestsrc")
.property_from_str("pattern", "ball")
.build()?;
let overlay = gst::ElementFactory::make("overlaycomposition").build()?;
let caps = gst_video::VideoCapsBuilder::new()
.width(800)
.height(800)
.framerate((30, 1).into())
.build();
let capsfilter = gst::ElementFactory::make("capsfilter")
.property("caps", &caps)
.build()?;
let videoconvert = gst::ElementFactory::make("videoconvert").build()?;
let sink = gst::ElementFactory::make("autovideosink").build()?;
pipeline.add_many(&[&src, &overlay, &capsfilter, &videoconvert, &sink])?;
gst::Element::link_many(&[&src, &overlay, &capsfilter, &videoconvert, &sink])?;
// Most Direct2D/DirectWrite APIs (including factory methods) are marked as
// "unsafe", but they shouldn't fail in practice
let drawer = unsafe {
let d2d_factory =
D2D1CreateFactory::<ID2D1Factory>(D2D1_FACTORY_TYPE_MULTI_THREADED, None).unwrap();
let dwrite_factory =
DWriteCreateFactory::<IDWriteFactory>(DWRITE_FACTORY_TYPE_SHARED).unwrap();
let text_format = dwrite_factory
.CreateTextFormat(
windows::core::w!("Arial"),
None,
DWRITE_FONT_WEIGHT_BOLD,
DWRITE_FONT_STYLE_NORMAL,
DWRITE_FONT_STRETCH_NORMAL,
32f32,
windows::core::w!("en-us"),
)
.unwrap();
let text_layout = dwrite_factory
.CreateTextLayout(
windows::core::w!("GStreamer").as_wide(),
&text_format,
// Size will be updated later on "caps-changed" signal
800f32,
800f32,
)
.unwrap();
// Top (default) and center alignment
text_layout
.SetTextAlignment(DWRITE_TEXT_ALIGNMENT_CENTER)
.unwrap();
let wic_factory: IWICImagingFactory =
CoCreateInstance(&CLSID_WICImagingFactory, None, CLSCTX_ALL).unwrap();
Arc::new(Mutex::new(DrawingContext {
d2d_factory,
wic_factory,
text_layout,
bitmap: None,
render_target: None,
info: None,
}))
};
overlay.connect_closure(
"draw",
false,
glib::closure!(@strong drawer => move |_overlay: &gst::Element,
sample: &gst::Sample| {
use std::f64::consts::PI;
let drawer = drawer.lock().unwrap();
let buffer = sample.buffer().unwrap();
let timestamp = buffer.pts().unwrap();
let info = drawer.info.as_ref().unwrap();
let text_layout = &drawer.text_layout;
let bitmap = drawer.bitmap.as_ref().unwrap();
let render_target = drawer.render_target.as_ref().unwrap();
let global_angle = 360. * (timestamp % (10 * gst::ClockTime::SECOND)).nseconds() as f64
/ (10.0 * gst::ClockTime::SECOND.nseconds() as f64);
let center_x = (info.width() / 2) as f32;
let center_y = (info.height() / 2) as f32;
let top_margin = (info.height() / 20) as f32;
unsafe {
// Begin drawing
render_target.BeginDraw();
// Clear background
render_target.Clear(Some(&D2D1_COLOR_F {
r: 0f32,
g: 0f32,
b: 0f32,
a: 0f32,
}));
// This loop will render 10 times the string "GStreamer" in a circle
for i in 0..10 {
let angle = (360. * f64::from(i)) / 10.0;
let red = ((1.0 + f64::cos((angle - 60.0) * PI / 180.0)) / 2.0) as f32;
let text_brush = render_target
.CreateSolidColorBrush(
&D2D1_COLOR_F {
r: red,
g: 0f32,
b: 1f32 - red,
a: 1f32,
},
None,
)
.unwrap();
let angle = (angle + global_angle) as f32;
let matrix = Matrix3x2::rotation(angle, center_x, center_y);
render_target.SetTransform(&matrix);
render_target.DrawTextLayout(
D2D_POINT_2F { x: 0f32, y: top_margin },
text_layout,
&text_brush,
D2D1_DRAW_TEXT_OPTIONS_NONE,
);
}
// EndDraw may not be successful for some reasons.
// Ignores any error in this example
let _ = render_target.EndDraw(None, None);
// Make sure all operations is completed before copying
// bitmap to buffer
let _ = render_target.Flush(None::<*mut u64>, None::<*mut u64>);
}
let mut buffer = gst::Buffer::with_size((info.width() * info.height() * 4) as usize).unwrap();
{
let buffer_mut = buffer.get_mut().unwrap();
let mut map = buffer_mut.map_writable().unwrap();
let dst = map.as_mut_slice_of::<u8>().unwrap();
unsafe {
// Bitmap size is equal to the background image size.
// Copy entire memory
bitmap.CopyPixels(std::ptr::null(), info.width() * 4, dst).unwrap();
}
}
gst_video::VideoMeta::add_full(
buffer.get_mut().unwrap(),
gst_video::VideoFrameFlags::empty(),
gst_video::VideoFormat::Bgra,
info.width(),
info.height(),
&[0],
&[(info.width() * 4) as i32],
)
.unwrap();
// Turn the buffer into a VideoOverlayRectangle, then place
// that into a VideoOverlayComposition and return it.
//
// A VideoOverlayComposition can take a Vec of such rectangles
// spaced around the video frame, but we're just outputting 1
// here
let rect = gst_video::VideoOverlayRectangle::new_raw(
&buffer,
0,
0,
info.width(),
info.height(),
gst_video::VideoOverlayFormatFlags::PREMULTIPLIED_ALPHA,
);
gst_video::VideoOverlayComposition::new(Some(&rect))
.unwrap()
}),
);
// Add a signal handler to the overlay's "caps-changed" signal. This could e.g.
// be called when the sink that we render to does not support resizing the image
// itself - but the user just changed the window-size. The element after the overlay
// will then change its caps and we use the notification about this change to
// resize our canvas's size.
// Another possibility for when this might happen is, when our video is a network
// stream that dynamically changes resolution when enough bandwidth is available.
overlay.connect_closure(
"caps-changed",
false,
glib::closure!(move |_overlay: &gst::Element,
caps: &gst::Caps,
_width: u32,
_height: u32| {
let mut drawer = drawer.lock().unwrap();
let info = gst_video::VideoInfo::from_caps(caps).unwrap();
unsafe {
// Update text layout to be identical to new video resolution
drawer.text_layout.SetMaxWidth(info.width() as f32).unwrap();
drawer
.text_layout
.SetMaxHeight(info.height() as f32)
.unwrap();
// Create new WIC bitmap with PBGRA format (pre-multiplied BGRA)
let bitmap = drawer
.wic_factory
.CreateBitmap(
info.width(),
info.height(),
&GUID_WICPixelFormat32bppPBGRA,
WICBitmapCacheOnDemand,
)
.unwrap();
let render_target = drawer
.d2d_factory
.CreateWicBitmapRenderTarget(
&bitmap,
&D2D1_RENDER_TARGET_PROPERTIES {
r#type: D2D1_RENDER_TARGET_TYPE_DEFAULT,
pixelFormat: D2D1_PIXEL_FORMAT {
format: DXGI_FORMAT_B8G8R8A8_UNORM,
alphaMode: D2D1_ALPHA_MODE_PREMULTIPLIED,
},
// zero means default DPI
dpiX: 0f32,
dpiY: 0f32,
usage: D2D1_RENDER_TARGET_USAGE_NONE,
minLevel: D2D1_FEATURE_LEVEL_DEFAULT,
},
)
.unwrap();
drawer.render_target = Some(render_target);
drawer.bitmap = Some(bitmap);
}
drawer.info = Some(info);
}),
);
Ok(pipeline)
}
fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> {
pipeline.set_state(gst::State::Playing)?;
let bus = pipeline
.bus()
.expect("Pipeline without bus. Shouldn't happen!");
for msg in bus.iter_timed(gst::ClockTime::NONE) {
use gst::MessageView;
match msg.view() {
MessageView::Eos(..) => break,
MessageView::Error(err) => {
pipeline.set_state(gst::State::Null)?;
return Err(ErrorMessage {
src: msg
.src()
.map(|s| s.path_string())
.unwrap_or_else(|| glib::GString::from("UNKNOWN")),
error: err.error(),
debug: err.debug(),
}
.into());
}
_ => (),
}
}
pipeline.set_state(gst::State::Null)?;
Ok(())
}
fn main() {
// WIC requires COM initialization
unsafe {
CoInitializeEx(None, COINIT_MULTITHREADED).unwrap();
}
match create_pipeline().and_then(main_loop) {
Ok(r) => r,
Err(e) => eprintln!("Error! {}", e),
}
unsafe {
CoUninitialize();
}
}

View file

@ -7,39 +7,30 @@
// {videotestsrc} - {overlaycomposition} - {capsfilter} - {videoconvert} - {autovideosink}
// The capsfilter element allows us to dictate the video resolution we want for the
// videotestsrc and the overlaycomposition element.
//
// There is a small amount of unsafe code that demonstrates how to work around
// Cairo's internal refcounting of the target buffer surface
#![allow(clippy::non_send_fields_in_send_ty)]
use gst::prelude::*;
use pango::prelude::*;
use std::ops;
use std::sync::{Arc, Mutex};
use std::{
ops,
sync::{Arc, Mutex},
};
use anyhow::Error;
use derive_more::{Display, Error};
use gst::prelude::*;
use pango::prelude::*;
#[path = "../examples-common.rs"]
mod examples_common;
#[derive(Debug, Display, Error)]
#[display(fmt = "Missing element {}", _0)]
struct MissingElement(#[error(not(source))] &'static str);
#[derive(Debug, Display, Error)]
#[display(fmt = "Received error from {}: {} (debug: {:?})", src, error, debug)]
#[display(fmt = "Received error from {src}: {error} (debug: {debug:?})")]
struct ErrorMessage {
src: String,
error: String,
debug: Option<String>,
source: glib::Error,
src: glib::GString,
error: glib::Error,
debug: Option<glib::GString>,
}
struct DrawingContext {
layout: glib::SendUniqueCell<LayoutWrapper>,
layout: LayoutWrapper,
info: Option<gst_video::VideoInfo>,
}
@ -50,52 +41,49 @@ impl ops::Deref for LayoutWrapper {
type Target = pango::Layout;
fn deref(&self) -> &pango::Layout {
assert_eq!(self.0.ref_count(), 1);
&self.0
}
}
unsafe impl glib::SendUnique for LayoutWrapper {
fn is_unique(&self) -> bool {
self.0.ref_count() == 1
}
}
// SAFETY: We ensure that there are never multiple references to the layout.
unsafe impl Send for LayoutWrapper {}
fn create_pipeline() -> Result<gst::Pipeline, Error> {
gst::init()?;
let pipeline = gst::Pipeline::new(None);
let src = gst::ElementFactory::make("videotestsrc", None)
.map_err(|_| MissingElement("videotestsrc"))?;
let overlay = gst::ElementFactory::make("overlaycomposition", None)
.map_err(|_| MissingElement("overlaycomposition"))?;
let capsfilter =
gst::ElementFactory::make("capsfilter", None).map_err(|_| MissingElement("capsfilter"))?;
let videoconvert = gst::ElementFactory::make("videoconvert", None)
.map_err(|_| MissingElement("videoconvert"))?;
let sink = gst::ElementFactory::make("autovideosink", None)
.map_err(|_| MissingElement("autovideosink"))?;
let pipeline = gst::Pipeline::default();
pipeline.add_many(&[&src, &overlay, &capsfilter, &videoconvert, &sink])?;
gst::Element::link_many(&[&src, &overlay, &capsfilter, &videoconvert, &sink])?;
// The videotestsrc supports multiple test patterns. In this example, we will use the
// pattern with a white ball moving around the video's center point.
let src = gst::ElementFactory::make("videotestsrc")
.property_from_str("pattern", "ball")
.build()?;
let overlay = gst::ElementFactory::make("overlaycomposition").build()?;
// Plug in a capsfilter element that will force the videotestsrc and the overlay to work
// with images of the size 800x800, and framerate of 15 fps, since my laptop struggles
// rendering it at the default 30 fps
let caps = gst::Caps::builder("video/x-raw")
.field("width", 800i32)
.field("height", 800i32)
.field("framerate", gst::Fraction::new(15, 1))
let caps = gst_video::VideoCapsBuilder::new()
.width(800)
.height(800)
.framerate((15, 1).into())
.build();
capsfilter.set_property("caps", &caps);
let capsfilter = gst::ElementFactory::make("capsfilter")
.property("caps", &caps)
.build()?;
// The videotestsrc supports multiple test patterns. In this example, we will use the
// pattern with a white ball moving around the video's center point.
src.set_property_from_str("pattern", "ball");
let videoconvert = gst::ElementFactory::make("videoconvert").build()?;
let sink = gst::ElementFactory::make("autovideosink").build()?;
pipeline.add_many([&src, &overlay, &capsfilter, &videoconvert, &sink])?;
gst::Element::link_many([&src, &overlay, &capsfilter, &videoconvert, &sink])?;
// The PangoFontMap represents the set of fonts available for a particular rendering system.
let fontmap = pangocairo::FontMap::new().unwrap();
let fontmap = pangocairo::FontMap::new();
// Create a new pango layouting context for the fontmap.
let context = fontmap.create_context().unwrap();
let context = fontmap.create_context();
// Create a pango layout object. This object is a string of text we want to layout.
// It is wrapped in a LayoutWrapper (defined above) to be able to send it across threads.
let layout = LayoutWrapper(pango::Layout::new(&context));
@ -115,12 +103,8 @@ fn create_pipeline() -> Result<gst::Pipeline, Error> {
// interior mutability (see Rust docs). Via this we can get a mutable reference to the contained
// data which is checked at runtime for uniqueness (blocking in case of mutex, panic in case
// of refcell) instead of compile-time (like with normal references).
let drawer = Arc::new(Mutex::new(DrawingContext {
layout: glib::SendUniqueCell::new(layout).unwrap(),
info: None,
}));
let drawer = Arc::new(Mutex::new(DrawingContext { layout, info: None }));
let drawer_clone = drawer.clone();
// Connect to the overlaycomposition element's "draw" signal, which is emitted for
// each videoframe piped through the element. The signal handler needs to
// return a gst_video::VideoOverlayComposition to be drawn on the frame
@ -132,54 +116,31 @@ fn create_pipeline() -> Result<gst::Pipeline, Error> {
//
// In this case, the signal passes the gst::Element and a gst::Sample with
// the current buffer
overlay.connect("draw", false, move |args| {
use std::f64::consts::PI;
overlay.connect_closure(
"draw",
false,
glib::closure!(@strong drawer => move |_overlay: &gst::Element,
sample: &gst::Sample| {
use std::f64::consts::PI;
let drawer = &drawer_clone;
let drawer = drawer.lock().unwrap();
let drawer = drawer.lock().unwrap();
// Get the signal's arguments
let _overlay = args[0].get::<gst::Element>().unwrap();
let sample = args[1].get::<gst::Sample>().unwrap();
let buffer = sample.buffer().unwrap();
let timestamp = buffer.pts().unwrap();
let buffer = sample.buffer().unwrap();
let timestamp = buffer.pts().unwrap();
let info = drawer.info.as_ref().unwrap();
let layout = drawer.layout.borrow();
let info = drawer.info.as_ref().unwrap();
let layout = &drawer.layout;
let angle = 2.0 * PI * (timestamp % (10 * gst::ClockTime::SECOND)).nseconds() as f64
/ (10.0 * gst::ClockTime::SECOND.nseconds() as f64);
let angle = 2.0 * PI * (timestamp % (10 * gst::ClockTime::SECOND)).nseconds() as f64
/ (10.0 * gst::ClockTime::SECOND.nseconds() as f64);
/* Create a gst::Buffer for Cairo to draw into */
let frame_width = info.width() as usize;
let frame_height = info.height() as usize;
let stride = 4 * frame_width;
let frame_size = stride * frame_height;
/* Create an RGBA buffer, and add a video meta that the videooverlaycomposition expects */
let mut buffer = gst::Buffer::with_size(frame_size).unwrap();
gst_video::VideoMeta::add(
buffer.get_mut().unwrap(),
gst_video::VideoFrameFlags::empty(),
gst_video::VideoFormat::Bgra,
frame_width as u32,
frame_height as u32,
)
.unwrap();
let buffer = buffer.into_mapped_buffer_writable().unwrap();
let buffer = {
let buffer_ptr = unsafe { buffer.buffer().as_ptr() };
let surface = cairo::ImageSurface::create_for_data(
buffer,
/* Create a Cairo image surface to draw into and the context around it. */
let surface = cairo::ImageSurface::create(
cairo::Format::ARgb32,
frame_width as i32,
frame_height as i32,
stride as i32,
info.width() as i32,
info.height() as i32,
)
.unwrap();
let cr = cairo::Context::new(&surface).expect("Failed to create cairo context");
cr.save().expect("Failed to save state");
@ -189,7 +150,7 @@ fn create_pipeline() -> Result<gst::Pipeline, Error> {
// The image we draw (the text) will be static, but we will change the
// transformation on the drawing context, which rotates and shifts everything
// that we draw afterwards. Like this, we have no complicated calulations
// that we draw afterwards. Like this, we have no complicated calculations
// in the actual drawing below.
// Calling multiple transformation methods after each other will apply the
// new transformation on top. If you repeat the cr.rotate(angle) line below
@ -216,9 +177,9 @@ fn create_pipeline() -> Result<gst::Pipeline, Error> {
// Update the text layout. This function is only updating pango's internal state.
// So e.g. that after a 90 degree rotation it knows that what was previously going
// to end up as a 200x100 rectangle would now be 100x200.
pangocairo::functions::update_layout(&cr, &**layout);
pangocairo::functions::update_layout(&cr, layout);
let (width, _height) = layout.size();
// Using width and height of the text, we can properly possition it within
// Using width and height of the text, we can properly position it within
// our canvas.
cr.move_to(
-(f64::from(width) / f64::from(pango::SCALE)) / 2.0,
@ -226,51 +187,53 @@ fn create_pipeline() -> Result<gst::Pipeline, Error> {
);
// After telling the layout object where to draw itself, we actually tell
// it to draw itself into our cairo context.
pangocairo::functions::show_layout(&cr, &**layout);
pangocairo::functions::show_layout(&cr, layout);
// Here we go one step up in our stack of transformations, removing any
// changes we did to them since the last call to cr.save();
cr.restore().expect("Failed to restore state");
}
// Safety: The surface still owns a mutable reference to the buffer but our reference
// to the surface here is the last one. After dropping the surface the buffer would be
// freed, so we keep an additional strong reference here before dropping the surface,
// which is then returned. As such it's guaranteed that nothing is using the buffer
// anymore mutably.
/* Drop the Cairo context to release the additional reference to the data and
* then take ownership of the data. This only works if we have the one and only
* reference to the image surface */
drop(cr);
unsafe {
assert_eq!(
cairo::ffi::cairo_surface_get_reference_count(surface.to_raw_none()),
1
);
let buffer = glib::translate::from_glib_none(buffer_ptr);
drop(surface);
buffer
}
};
let stride = surface.stride();
let data = surface.take_data().unwrap();
/* Turn the buffer into a VideoOverlayRectangle, then place
* that into a VideoOverlayComposition and return it.
*
* A VideoOverlayComposition can take a Vec of such rectangles
* spaced around the video frame, but we're just outputting 1
* here */
let rect = gst_video::VideoOverlayRectangle::new_raw(
&buffer,
0,
0,
frame_width as u32,
frame_height as u32,
gst_video::VideoOverlayFormatFlags::PREMULTIPLIED_ALPHA,
);
/* Create an RGBA buffer, and add a video meta that the videooverlaycomposition expects */
let mut buffer = gst::Buffer::from_mut_slice(data);
gst_video::VideoMeta::add_full(
buffer.get_mut().unwrap(),
gst_video::VideoFrameFlags::empty(),
gst_video::VideoFormat::Bgra,
info.width(),
info.height(),
&[0],
&[stride],
)
.unwrap();
/* Turn the buffer into a VideoOverlayRectangle, then place
* that into a VideoOverlayComposition and return it.
*
* A VideoOverlayComposition can take a Vec of such rectangles
* spaced around the video frame, but we're just outputting 1
* here */
let rect = gst_video::VideoOverlayRectangle::new_raw(
&buffer,
0,
0,
info.width(),
info.height(),
gst_video::VideoOverlayFormatFlags::PREMULTIPLIED_ALPHA,
);
Some(
gst_video::VideoOverlayComposition::new(Some(&rect))
.unwrap()
.to_value(),
)
});
}),
);
// Add a signal handler to the overlay's "caps-changed" signal. This could e.g.
// be called when the sink that we render to does not support resizing the image
@ -278,16 +241,18 @@ fn create_pipeline() -> Result<gst::Pipeline, Error> {
// will then change its caps and we use the notification about this change to
// resize our canvas's size.
// Another possibility for when this might happen is, when our video is a network
// stream that dynamically changes resolution when enough bandwith is available.
overlay.connect("caps-changed", false, move |args| {
let _overlay = args[0].get::<gst::Element>().unwrap();
let caps = args[1].get::<gst::Caps>().unwrap();
let mut drawer = drawer.lock().unwrap();
drawer.info = Some(gst_video::VideoInfo::from_caps(&caps).unwrap());
None
});
// stream that dynamically changes resolution when enough bandwidth is available.
overlay.connect_closure(
"caps-changed",
false,
glib::closure!(move |_overlay: &gst::Element,
caps: &gst::Caps,
_width: u32,
_height: u32| {
let mut drawer = drawer.lock().unwrap();
drawer.info = Some(gst_video::VideoInfo::from_caps(caps).unwrap());
}),
);
Ok(pipeline)
}
@ -309,11 +274,10 @@ fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> {
return Err(ErrorMessage {
src: msg
.src()
.map(|s| String::from(s.path_string()))
.unwrap_or_else(|| String::from("None")),
error: err.error().to_string(),
.map(|s| s.path_string())
.unwrap_or_else(|| glib::GString::from("UNKNOWN")),
error: err.error(),
debug: err.debug(),
source: err.error(),
}
.into());
}
@ -329,7 +293,7 @@ fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> {
fn example_main() {
match create_pipeline().and_then(main_loop) {
Ok(r) => r,
Err(e) => eprintln!("Error! {}", e),
Err(e) => eprintln!("Error! {e}"),
}
}

View file

@ -8,11 +8,10 @@
// {audiotestsrc} - {fakesink}
#![allow(clippy::question_mark)]
use gst::prelude::*;
use std::i16;
use byte_slice_cast::*;
use std::i16;
use gst::prelude::*;
#[path = "../examples-common.rs"]
mod examples_common;
@ -23,7 +22,7 @@ fn example_main() {
// Parse the pipeline we want to probe from a static in-line string.
// Here we give our audiotestsrc a name, so we can retrieve that element
// from the resulting pipeline.
let pipeline = gst::parse_launch(&format!(
let pipeline = gst::parse::launch(&format!(
"audiotestsrc name=src ! audio/x-raw,format={},channels=1 ! fakesink",
gst_audio::AUDIO_FORMAT_S16
))
@ -39,36 +38,38 @@ fn example_main() {
// This handler gets called for every buffer that passes the pad we probe.
src_pad.add_probe(gst::PadProbeType::BUFFER, |_, probe_info| {
// Interpret the data sent over the pad as one buffer
if let Some(gst::PadProbeData::Buffer(ref buffer)) = probe_info.data {
// At this point, buffer is only a reference to an existing memory region somewhere.
// When we want to access its content, we have to map it while requesting the required
// mode of access (read, read/write).
// This type of abstraction is necessary, because the buffer in question might not be
// on the machine's main memory itself, but rather in the GPU's memory.
// So mapping the buffer makes the underlying memory region accessible to us.
// See: https://gstreamer.freedesktop.org/documentation/plugin-development/advanced/allocation.html
let map = buffer.map_readable().unwrap();
let Some(buffer) = probe_info.buffer() else {
return gst::PadProbeReturn::Ok;
};
// We know what format the data in the memory region has, since we requested
// it by setting the appsink's caps. So what we do here is interpret the
// memory region we mapped as an array of signed 16 bit integers.
let samples = if let Ok(samples) = map.as_slice_of::<i16>() {
samples
} else {
return gst::PadProbeReturn::Ok;
};
// At this point, buffer is only a reference to an existing memory region somewhere.
// When we want to access its content, we have to map it while requesting the required
// mode of access (read, read/write).
// This type of abstraction is necessary, because the buffer in question might not be
// on the machine's main memory itself, but rather in the GPU's memory.
// So mapping the buffer makes the underlying memory region accessible to us.
// See: https://gstreamer.freedesktop.org/documentation/plugin-development/advanced/allocation.html
let map = buffer.map_readable().unwrap();
// For buffer (= chunk of samples), we calculate the root mean square:
let sum: f64 = samples
.iter()
.map(|sample| {
let f = f64::from(*sample) / f64::from(i16::MAX);
f * f
})
.sum();
let rms = (sum / (samples.len() as f64)).sqrt();
println!("rms: {}", rms);
}
// We know what format the data in the memory region has, since we requested
// it by setting the appsink's caps. So what we do here is interpret the
// memory region we mapped as an array of signed 16 bit integers.
let samples = if let Ok(samples) = map.as_slice_of::<i16>() {
samples
} else {
return gst::PadProbeReturn::Ok;
};
// For buffer (= chunk of samples), we calculate the root mean square:
let sum: f64 = samples
.iter()
.map(|sample| {
let f = f64::from(*sample) / f64::from(i16::MAX);
f * f
})
.sum();
let rms = (sum / (samples.len() as f64)).sqrt();
println!("rms: {rms}");
gst::PadProbeReturn::Ok
});

View file

@ -10,36 +10,30 @@
// {videotestsrc} - {cairooverlay} - {capsfilter} - {videoconvert} - {autovideosink}
// The capsfilter element allows us to dictate the video resolution we want for the
// videotestsrc and the cairooverlay element.
#![allow(clippy::non_send_fields_in_send_ty)]
use gst::prelude::*;
use pango::prelude::*;
use std::ops;
use std::sync::{Arc, Mutex};
use std::{
ops,
sync::{Arc, Mutex},
};
use anyhow::Error;
use derive_more::{Display, Error};
use gst::prelude::*;
use pango::prelude::*;
#[path = "../examples-common.rs"]
mod examples_common;
#[derive(Debug, Display, Error)]
#[display(fmt = "Missing element {}", _0)]
struct MissingElement(#[error(not(source))] &'static str);
#[derive(Debug, Display, Error)]
#[display(fmt = "Received error from {}: {} (debug: {:?})", src, error, debug)]
#[display(fmt = "Received error from {src}: {error} (debug: {debug:?})")]
struct ErrorMessage {
src: String,
error: String,
debug: Option<String>,
source: glib::Error,
src: glib::GString,
error: glib::Error,
debug: Option<glib::GString>,
}
struct DrawingContext {
layout: glib::SendUniqueCell<LayoutWrapper>,
layout: LayoutWrapper,
info: Option<gst_video::VideoInfo>,
}
@ -50,50 +44,45 @@ impl ops::Deref for LayoutWrapper {
type Target = pango::Layout;
fn deref(&self) -> &pango::Layout {
assert_eq!(self.0.ref_count(), 1);
&self.0
}
}
unsafe impl glib::SendUnique for LayoutWrapper {
fn is_unique(&self) -> bool {
self.0.ref_count() == 1
}
}
// SAFETY: We ensure that there are never multiple references to the layout.
unsafe impl Send for LayoutWrapper {}
fn create_pipeline() -> Result<gst::Pipeline, Error> {
gst::init()?;
let pipeline = gst::Pipeline::new(None);
let src = gst::ElementFactory::make("videotestsrc", None)
.map_err(|_| MissingElement("videotestsrc"))?;
let overlay = gst::ElementFactory::make("cairooverlay", None)
.map_err(|_| MissingElement("cairooverlay"))?;
let capsfilter =
gst::ElementFactory::make("capsfilter", None).map_err(|_| MissingElement("capsfilter"))?;
let videoconvert = gst::ElementFactory::make("videoconvert", None)
.map_err(|_| MissingElement("videoconvert"))?;
let sink = gst::ElementFactory::make("autovideosink", None)
.map_err(|_| MissingElement("autovideosink"))?;
pipeline.add_many(&[&src, &overlay, &capsfilter, &videoconvert, &sink])?;
gst::Element::link_many(&[&src, &overlay, &capsfilter, &videoconvert, &sink])?;
let pipeline = gst::Pipeline::default();
let src = gst::ElementFactory::make("videotestsrc")
// The videotestsrc supports multiple test patterns. In this example, we will use the
// pattern with a white ball moving around the video's center point.
.property_from_str("pattern", "ball")
.build()?;
let overlay = gst::ElementFactory::make("cairooverlay").build()?;
// Plug in a capsfilter element that will force the videotestsrc and the cairooverlay to work
// with images of the size 800x800.
let caps = gst::Caps::builder("video/x-raw")
.field("width", 800i32)
.field("height", 800i32)
let caps = gst_video::VideoCapsBuilder::new()
.width(800)
.height(800)
.build();
capsfilter.set_property("caps", &caps);
let capsfilter = gst::ElementFactory::make("capsfilter")
.property("caps", &caps)
.build()?;
// The videotestsrc supports multiple test patterns. In this example, we will use the
// pattern with a white ball moving around the video's center point.
src.set_property_from_str("pattern", "ball");
let videoconvert = gst::ElementFactory::make("videoconvert").build()?;
let sink = gst::ElementFactory::make("autovideosink").build()?;
pipeline.add_many([&src, &overlay, &capsfilter, &videoconvert, &sink])?;
gst::Element::link_many([&src, &overlay, &capsfilter, &videoconvert, &sink])?;
// The PangoFontMap represents the set of fonts available for a particular rendering system.
let fontmap = pangocairo::FontMap::new().unwrap();
let fontmap = pangocairo::FontMap::new();
// Create a new pango layouting context for the fontmap.
let context = fontmap.create_context().unwrap();
let context = fontmap.create_context();
// Create a pango layout object. This object is a string of text we want to layout.
// It is wrapped in a LayoutWrapper (defined above) to be able to send it across threads.
let layout = LayoutWrapper(pango::Layout::new(&context));
@ -113,10 +102,7 @@ fn create_pipeline() -> Result<gst::Pipeline, Error> {
// interior mutability (see Rust docs). Via this we can get a mutable reference to the contained
// data which is checked at runtime for uniqueness (blocking in case of mutex, panic in case
// of refcell) instead of compile-time (like with normal references).
let drawer = Arc::new(Mutex::new(DrawingContext {
layout: glib::SendUniqueCell::new(layout).unwrap(),
info: None,
}));
let drawer = Arc::new(Mutex::new(DrawingContext { layout, info: None }));
let drawer_clone = drawer.clone();
// Connect to the cairooverlay element's "draw" signal, which is emitted for
@ -141,14 +127,14 @@ fn create_pipeline() -> Result<gst::Pipeline, Error> {
let _duration = args[3].get::<gst::ClockTime>().unwrap();
let info = drawer.info.as_ref().unwrap();
let layout = drawer.layout.borrow();
let layout = &drawer.layout;
let angle = 2.0 * PI * (timestamp % (10 * gst::ClockTime::SECOND)).nseconds() as f64
/ (10.0 * gst::ClockTime::SECOND.nseconds() as f64);
// The image we draw (the text) will be static, but we will change the
// transformation on the drawing context, which rotates and shifts everything
// that we draw afterwards. Like this, we have no complicated calulations
// that we draw afterwards. Like this, we have no complicated calculations
// in the actual drawing below.
// Calling multiple transformation methods after each other will apply the
// new transformation on top. If you repeat the cr.rotate(angle) line below
@ -175,9 +161,9 @@ fn create_pipeline() -> Result<gst::Pipeline, Error> {
// Update the text layout. This function is only updating pango's internal state.
// So e.g. that after a 90 degree rotation it knows that what was previously going
// to end up as a 200x100 rectangle would now be 100x200.
pangocairo::functions::update_layout(&cr, &**layout);
pangocairo::functions::update_layout(&cr, layout);
let (width, _height) = layout.size();
// Using width and height of the text, we can properly possition it within
// Using width and height of the text, we can properly position it within
// our canvas.
cr.move_to(
-(f64::from(width) / f64::from(pango::SCALE)) / 2.0,
@ -185,7 +171,7 @@ fn create_pipeline() -> Result<gst::Pipeline, Error> {
);
// After telling the layout object where to draw itself, we actually tell
// it to draw itself into our cairo context.
pangocairo::functions::show_layout(&cr, &**layout);
pangocairo::functions::show_layout(&cr, layout);
// Here we go one step up in our stack of transformations, removing any
// changes we did to them since the last call to cr.save();
@ -201,7 +187,7 @@ fn create_pipeline() -> Result<gst::Pipeline, Error> {
// will then change its caps and we use the notification about this change to
// resize our canvas's size.
// Another possibility for when this might happen is, when our video is a network
// stream that dynamically changes resolution when enough bandwith is available.
// stream that dynamically changes resolution when enough bandwidth is available.
overlay.connect("caps-changed", false, move |args| {
let _overlay = args[0].get::<gst::Element>().unwrap();
let caps = args[1].get::<gst::Caps>().unwrap();
@ -232,11 +218,10 @@ fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> {
return Err(ErrorMessage {
src: msg
.src()
.map(|s| String::from(s.path_string()))
.unwrap_or_else(|| String::from("None")),
error: err.error().to_string(),
.map(|s| s.path_string())
.unwrap_or_else(|| glib::GString::from("UNKNOWN")),
error: err.error(),
debug: err.debug(),
source: err.error(),
}
.into());
}
@ -252,7 +237,7 @@ fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> {
fn example_main() {
match create_pipeline().and_then(main_loop) {
Ok(r) => r,
Err(e) => eprintln!("Error! {}", e),
Err(e) => eprintln!("Error! {e}"),
}
}

67
examples/src/bin/play.rs Normal file
View file

@ -0,0 +1,67 @@
// This example shows how to use the GstPlay API.
// The GstPlay API is a convenience API to allow implement playback applications
// without having to write too much code.
// Most of the tasks a play needs to support (such as seeking and switching
// audio / subtitle streams or changing the volume) are all supported by simple
// one-line function calls on the GstPlay.
use std::env;
use anyhow::Error;
#[path = "../examples-common.rs"]
mod examples_common;
use gst_play::{Play, PlayMessage, PlayVideoRenderer};
fn main_loop(uri: &str) -> Result<(), Error> {
gst::init()?;
let play = Play::new(None::<PlayVideoRenderer>);
play.set_uri(Some(uri));
play.play();
let mut result = Ok(());
for msg in play.message_bus().iter_timed(gst::ClockTime::NONE) {
match PlayMessage::parse(&msg) {
Ok(PlayMessage::EndOfStream) => {
play.stop();
break;
}
Ok(PlayMessage::Error { error, details: _ }) => {
result = Err(error);
play.stop();
break;
}
Ok(_) => (),
Err(_) => unreachable!(),
}
}
// Set the message bus to flushing to ensure that all pending messages are dropped and there
// are no further references to the play instance.
play.message_bus().set_flushing(true);
result.map_err(|e| e.into())
}
fn example_main() {
let args: Vec<_> = env::args().collect();
let uri: &str = if args.len() == 2 {
args[1].as_ref()
} else {
println!("Usage: play uri");
std::process::exit(-1)
};
match main_loop(uri) {
Ok(r) => r,
Err(e) => eprintln!("Error! {e}"),
}
}
fn main() {
// tutorials_common::run is only required to set up the application environment on macOS
// (but not necessary in normal Cocoa applications where this is set up automatically)
examples_common::run(example_main);
}

View file

@ -9,10 +9,10 @@
// Much of the playbin's behavior can be controlled by so-called flags, as well
// as the playbin's properties and signals.
use gst::prelude::*;
use std::env;
use gst::prelude::*;
#[path = "../examples-common.rs"]
mod examples_common;
@ -28,20 +28,22 @@ fn example_main() {
};
// Create a new playbin element, and tell it what uri to play back.
let playbin = gst::ElementFactory::make("playbin", None).unwrap();
playbin.set_property("uri", uri);
let playbin = gst::ElementFactory::make("playbin")
.property("uri", uri)
.build()
.unwrap();
// For flags handling
// With flags, one can configure playbin's behavior such as whether it
// should play back contained video streams, or if it should render subtitles.
// let flags = playbin.get_property("flags").unwrap();
// let flags_class = FlagsClass::new(flags.type_()).unwrap();
// let flags = playbin.property_value("flags");
// let flags_class = FlagsClass::with_type(flags.type_()).unwrap();
// let flags = flags_class.builder_with_value(flags).unwrap()
// .unset_by_nick("text")
// .unset_by_nick("video")
// .build()
// .unwrap();
// playbin.set_property_from_value("flags", &flags).unwrap();
// playbin.set_property_from_value("flags", &flags);
// The playbin also provides any kind of metadata that it found in the played stream.
// For this, the playbin provides signals notifying about changes in the metadata.
@ -57,13 +59,13 @@ fn example_main() {
let playbin = values[0]
.get::<glib::Object>()
.expect("playbin \"audio-tags-changed\" signal values[1]");
// This gets the index of the stream that changed. This is neccessary, since
// This gets the index of the stream that changed. This is necessary, since
// there could e.g. be multiple audio streams (english, spanish, ...).
let idx = values[1]
.get::<i32>()
.expect("playbin \"audio-tags-changed\" signal values[1]");
println!("audio tags of audio stream {} changed:", idx);
println!("audio tags of audio stream {idx} changed:");
// HELP: is this correct?
// We were only notified about the change of metadata. If we want to do
@ -119,7 +121,7 @@ fn example_main() {
MessageView::StateChanged(state_changed) =>
// We are only interested in state-changed messages from playbin
{
if state_changed.src().map(|s| s == playbin).unwrap_or(false)
if state_changed.src().map(|s| s == &playbin).unwrap_or(false)
&& state_changed.current() == gst::State::Playing
{
// Generate a dot graph of the pipeline to GST_DEBUG_DUMP_DOT_DIR if defined

View file

@ -5,12 +5,13 @@
// audio / subtitle streams or changing the volume) are all supported by simple
// one-line function calls on the GstPlayer.
use gst::prelude::*;
use std::env;
use std::sync::{Arc, Mutex};
use std::{
env,
sync::{Arc, Mutex},
};
use anyhow::Error;
use gst::prelude::*;
#[allow(unused_imports)]
#[path = "../examples-common.rs"]
@ -23,8 +24,8 @@ fn main_loop(uri: &str) -> Result<(), Error> {
let dispatcher = gst_player::PlayerGMainContextSignalDispatcher::new(None);
let player = gst_player::Player::new(
None,
Some(&dispatcher.upcast::<gst_player::PlayerSignalDispatcher>()),
None::<gst_player::PlayerVideoRenderer>,
Some(dispatcher.upcast::<gst_player::PlayerSignalDispatcher>()),
);
// Tell the player what uri to play.
@ -75,7 +76,7 @@ fn example_main() {
match main_loop(uri) {
Ok(r) => r,
Err(e) => eprintln!("Error! {}", e),
Err(e) => eprintln!("Error! {e}"),
}
}

View file

@ -12,10 +12,10 @@
// For convenience, the API has a set of pre-defined queries, but also
// allows custom queries (which can be defined and used by your own elements).
use gst::prelude::*;
use std::env;
use gst::prelude::*;
#[path = "../examples-common.rs"]
mod examples_common;
@ -28,7 +28,7 @@ fn example_main() {
let main_loop = glib::MainLoop::new(None, false);
// Let GStreamer create a pipeline from the parsed launch syntax on the cli.
let pipeline = gst::parse_launch(&pipeline_str).unwrap();
let pipeline = gst::parse::launch(&pipeline_str).unwrap();
let bus = pipeline.bus().unwrap();
pipeline
@ -50,9 +50,8 @@ fn example_main() {
let timeout_id = glib::timeout_add_seconds(1, move || {
// Here we temporarily retrieve a strong reference on the pipeline from the weak one
// we moved into this callback.
let pipeline = match pipeline_weak.upgrade() {
Some(pipeline) => pipeline,
None => return glib::Continue(true),
let Some(pipeline) = pipeline_weak.upgrade() else {
return glib::ControlFlow::Break;
};
//let pos = pipeline.query_position(gst::Format::Time).unwrap_or(-1);
@ -87,34 +86,35 @@ fn example_main() {
println!("{} / {}", pos.display(), dur.display());
glib::Continue(true)
glib::ControlFlow::Continue
});
// Need to move a new reference into the closure.
let main_loop_clone = main_loop.clone();
//bus.add_signal_watch();
//bus.connect_message(None, move |_, msg| {
bus.add_watch(move |_, msg| {
use gst::MessageView;
let _bus_watch = bus
.add_watch(move |_, msg| {
use gst::MessageView;
let main_loop = &main_loop_clone;
match msg.view() {
MessageView::Eos(..) => main_loop.quit(),
MessageView::Error(err) => {
println!(
"Error from {:?}: {} ({:?})",
err.src().map(|s| s.path_string()),
err.error(),
err.debug()
);
main_loop.quit();
}
_ => (),
};
let main_loop = &main_loop_clone;
match msg.view() {
MessageView::Eos(..) => main_loop.quit(),
MessageView::Error(err) => {
println!(
"Error from {:?}: {} ({:?})",
err.src().map(|s| s.path_string()),
err.error(),
err.debug()
);
main_loop.quit();
}
_ => (),
};
glib::Continue(true)
})
.expect("Failed to add bus watch");
glib::ControlFlow::Continue
})
.expect("Failed to add bus watch");
main_loop.run();
@ -122,7 +122,6 @@ fn example_main() {
.set_state(gst::State::Null)
.expect("Unable to set the pipeline to the `Null` state");
bus.remove_watch().unwrap();
timeout_id.remove();
}

View file

@ -1,8 +1,7 @@
use gst::element_error;
use gst::prelude::*;
use std::env;
use gst::{element_error, prelude::*};
#[path = "../examples-common.rs"]
mod examples_common;
@ -10,41 +9,25 @@ use anyhow::Error;
use derive_more::{Display, Error};
#[derive(Debug, Display, Error)]
#[display(fmt = "Missing element {}", _0)]
struct MissingElement(#[error(not(source))] &'static str);
#[derive(Debug, Display, Error)]
#[display(fmt = "No such pad {} in {}", _0, _1)]
#[display(fmt = "No such pad {_0} in {_1}")]
struct NoSuchPad(#[error(not(source))] &'static str, String);
#[derive(Debug, Display, Error)]
#[display(fmt = "Unknown payload type {}", _0)]
#[display(fmt = "Unknown payload type {_0}")]
struct UnknownPT(#[error(not(source))] u32);
#[derive(Debug, Display, Error)]
#[display(fmt = "Usage: {} (play | record) DROP_PROBABILITY", _0)]
#[display(fmt = "Usage: {_0} (play | record) DROP_PROBABILITY")]
struct UsageError(#[error(not(source))] String);
#[derive(Debug, Display, Error)]
#[display(fmt = "Received error from {}: {} (debug: {:?})", src, error, debug)]
#[display(fmt = "Received error from {src}: {error} (debug: {debug:?})")]
struct ErrorMessage {
src: String,
error: String,
debug: Option<String>,
source: glib::Error,
src: glib::GString,
error: glib::Error,
debug: Option<glib::GString>,
}
fn make_element(
factory_name: &'static str,
element_name: Option<&str>,
) -> Result<gst::Element, Error> {
match gst::ElementFactory::make(factory_name, element_name) {
Ok(elem) => Ok(elem),
Err(_) => Err(Error::from(MissingElement(factory_name))),
}
}
#[doc(alias = "get_static_pad")]
fn static_pad(element: &gst::Element, pad_name: &'static str) -> Result<gst::Pad, Error> {
match element.static_pad(pad_name) {
Some(pad) => Ok(pad),
@ -55,7 +38,6 @@ fn static_pad(element: &gst::Element, pad_name: &'static str) -> Result<gst::Pad
}
}
#[doc(alias = "get_request_pad")]
fn request_pad(element: &gst::Element, pad_name: &'static str) -> Result<gst::Pad, Error> {
match element.request_pad_simple(pad_name) {
Some(pad) => Ok(pad),
@ -83,11 +65,11 @@ fn connect_rtpbin_srcpad(src_pad: &gst::Pad, sink: &gst::Element) -> Result<(),
}
fn make_fec_decoder(rtpbin: &gst::Element, sess_id: u32) -> Result<gst::Element, Error> {
let fecdec = make_element("rtpulpfecdec", None)?;
let internal_storage = rtpbin.emit_by_name::<glib::Object>("get-internal-storage", &[&sess_id]);
fecdec.set_property("storage", &internal_storage);
fecdec.set_property("pt", 100u32);
let fecdec = gst::ElementFactory::make("rtpulpfecdec")
.property("storage", &internal_storage)
.property("pt", 100u32)
.build()?;
Ok(fecdec)
}
@ -103,34 +85,55 @@ fn example_main() -> Result<(), Error> {
let drop_probability = args[2].parse::<f32>()?;
let pipeline = gst::Pipeline::new(None);
let src = make_element("udpsrc", None)?;
let netsim = make_element("netsim", None)?;
let rtpbin = make_element("rtpbin", None)?;
let depay = make_element("rtpvp8depay", None)?;
let dec = make_element("vp8dec", None)?;
let conv = make_element("videoconvert", None)?;
let scale = make_element("videoscale", None)?;
let filter = make_element("capsfilter", None)?;
let pipeline = gst::Pipeline::default();
pipeline.add_many(&[&src, &netsim, &rtpbin, &depay, &dec, &conv, &scale, &filter])?;
gst::Element::link_many(&[&depay, &dec, &conv, &scale, &filter])?;
let rtp_caps = gst::Caps::builder("application/x-rtp")
.field("clock-rate", 90000i32)
.build();
let video_caps = gst_video::VideoCapsBuilder::new()
.width(1920)
.height(1080)
.build();
let src = gst::ElementFactory::make("udpsrc")
.property("address", "127.0.0.1")
.property("caps", &rtp_caps)
.build()?;
let netsim = gst::ElementFactory::make("netsim")
.property("drop-probability", drop_probability)
.build()?;
let rtpbin = gst::ElementFactory::make("rtpbin")
.property("do-lost", true)
.build()?;
let depay = gst::ElementFactory::make("rtpvp8depay").build()?;
let dec = gst::ElementFactory::make("vp8dec").build()?;
let conv = gst::ElementFactory::make("videoconvert").build()?;
let scale = gst::ElementFactory::make("videoscale").build()?;
let filter = gst::ElementFactory::make("capsfilter")
.property("caps", &video_caps)
.build()?;
pipeline.add_many([&src, &netsim, &rtpbin, &depay, &dec, &conv, &scale, &filter])?;
gst::Element::link_many([&depay, &dec, &conv, &scale, &filter])?;
match args[1].as_str() {
"play" => {
let sink = make_element("autovideosink", None)?;
let sink = gst::ElementFactory::make("autovideosink").build()?;
pipeline.add(&sink)?;
filter.link(&sink)?;
}
"record" => {
let enc = make_element("x264enc", None)?;
let mux = make_element("matroskamux", None)?;
let sink = make_element("filesink", None)?;
let enc = gst::ElementFactory::make("x264enc")
.property_from_str("tune", "zerolatency")
.build()?;
let mux = gst::ElementFactory::make("matroskamux").build()?;
let sink = gst::ElementFactory::make("filesink")
.property("location", "out.mkv")
.build()?;
pipeline.add_many(&[&enc, &mux, &sink])?;
gst::Element::link_many(&[&filter, &enc, &mux, &sink])?;
sink.set_property("location", "out.mkv");
enc.set_property_from_str("tune", "zerolatency");
pipeline.add_many([&enc, &mux, &sink])?;
gst::Element::link_many([&filter, &enc, &mux, &sink])?;
eprintln!("Recording to out.mkv");
}
_ => return Err(Error::from(UsageError(args[0].clone()))),
@ -200,9 +203,8 @@ fn example_main() -> Result<(), Error> {
let depay_weak = depay.downgrade();
rtpbin.connect_pad_added(move |rtpbin, src_pad| {
let depay = match depay_weak.upgrade() {
Some(depay) => depay,
None => return,
let Some(depay) = depay_weak.upgrade() else {
return;
};
match connect_rtpbin_srcpad(src_pad, &depay) {
@ -218,21 +220,6 @@ fn example_main() -> Result<(), Error> {
}
});
let rtp_caps = gst::Caps::builder("application/x-rtp")
.field("clock-rate", 90000i32)
.build();
let video_caps = gst::Caps::builder("video/x-raw")
.field("width", 1920i32)
.field("height", 1080i32)
.build();
src.set_property("address", "127.0.0.1");
src.set_property("caps", &rtp_caps);
netsim.set_property("drop-probability", drop_probability);
rtpbin.set_property("do-lost", true);
filter.set_property("caps", &video_caps);
let bus = pipeline
.bus()
.expect("Pipeline without bus. Shouldn't happen!");
@ -254,23 +241,18 @@ fn example_main() -> Result<(), Error> {
return Err(ErrorMessage {
src: msg
.src()
.map(|s| String::from(s.path_string()))
.unwrap_or_else(|| String::from("None")),
error: err.error().to_string(),
.map(|s| s.path_string())
.unwrap_or_else(|| glib::GString::from("UNKNOWN")),
error: err.error(),
debug: err.debug(),
source: err.error(),
}
.into());
}
MessageView::StateChanged(s) => {
if let Some(element) = msg.src() {
if element == pipeline && s.current() == gst::State::Playing {
if element == &pipeline && s.current() == gst::State::Playing {
eprintln!("PLAYING");
gst::debug_bin_to_dot_file(
&pipeline,
gst::DebugGraphDetails::all(),
"client-playing",
);
pipeline.debug_to_dot_file(gst::DebugGraphDetails::all(), "client-playing");
}
}
}
@ -288,6 +270,6 @@ fn example_main() -> Result<(), Error> {
fn main() {
match examples_common::run(example_main) {
Ok(r) => r,
Err(e) => eprintln!("Error! {}", e),
Err(e) => eprintln!("Error! {e}"),
}
}

View file

@ -1,5 +1,4 @@
use gst::element_error;
use gst::prelude::*;
use gst::{element_error, prelude::*};
#[path = "../examples-common.rs"]
mod examples_common;
@ -10,37 +9,21 @@ use anyhow::Error;
use derive_more::{Display, Error};
#[derive(Debug, Display, Error)]
#[display(fmt = "Missing element {}", _0)]
struct MissingElement(#[error(not(source))] &'static str);
#[derive(Debug, Display, Error)]
#[display(fmt = "No such pad {} in {}", _0, _1)]
#[display(fmt = "No such pad {_0} in {_1}")]
struct NoSuchPad(&'static str, String);
#[derive(Debug, Display, Error)]
#[display(fmt = "Usage: {} URI FEC_PERCENTAGE", _0)]
#[display(fmt = "Usage: {_0} URI FEC_PERCENTAGE")]
struct UsageError(#[error(not(source))] String);
#[derive(Debug, Display, Error)]
#[display(fmt = "Received error from {}: {} (debug: {:?})", src, error, debug)]
#[display(fmt = "Received error from {src}: {error} (debug: {debug:?})")]
struct ErrorMessage {
src: String,
error: String,
debug: Option<String>,
source: glib::Error,
src: glib::GString,
error: glib::Error,
debug: Option<glib::GString>,
}
fn make_element(
factory_name: &'static str,
element_name: Option<&str>,
) -> Result<gst::Element, Error> {
match gst::ElementFactory::make(factory_name, element_name) {
Ok(elem) => Ok(elem),
Err(_) => Err(Error::from(MissingElement(factory_name))),
}
}
#[doc(alias = "get_static_pad")]
fn static_pad(element: &gst::Element, pad_name: &'static str) -> Result<gst::Pad, Error> {
match element.static_pad(pad_name) {
Some(pad) => Ok(pad),
@ -51,7 +34,6 @@ fn static_pad(element: &gst::Element, pad_name: &'static str) -> Result<gst::Pad
}
}
#[doc(alias = "get_request_pad")]
fn request_pad(element: &gst::Element, pad_name: &'static str) -> Result<gst::Pad, Error> {
match element.request_pad_simple(pad_name) {
Some(pad) => Ok(pad),
@ -70,11 +52,11 @@ fn connect_decodebin_pad(src_pad: &gst::Pad, sink: &gst::Element) -> Result<(),
}
fn make_fec_encoder(fec_percentage: u32) -> Result<gst::Element, Error> {
let fecenc = make_element("rtpulpfecenc", None)?;
fecenc.set_property("pt", 100u32);
fecenc.set_property("multipacket", true);
fecenc.set_property("percentage", fec_percentage);
let fecenc = gst::ElementFactory::make("rtpulpfecenc")
.property("pt", 100u32)
.property("multipacket", true)
.property("percentage", fec_percentage)
.build()?;
Ok(fecenc)
}
@ -91,17 +73,33 @@ fn example_main() -> Result<(), Error> {
let uri = &args[1];
let fec_percentage = args[2].parse::<u32>()?;
let pipeline = gst::Pipeline::new(None);
let src = make_element("uridecodebin", None)?;
let conv = make_element("videoconvert", None)?;
let q1 = make_element("queue", None)?;
let enc = make_element("vp8enc", None)?;
let q2 = make_element("queue", None)?;
let pay = make_element("rtpvp8pay", None)?;
let rtpbin = make_element("rtpbin", None)?;
let sink = make_element("udpsink", None)?;
let video_caps = gst::Caps::builder("video/x-raw").build();
pipeline.add_many(&[&src, &conv, &q1, &enc, &q2, &pay, &rtpbin, &sink])?;
let pipeline = gst::Pipeline::default();
let src = gst::ElementFactory::make("uridecodebin")
.property_from_str("pattern", "ball")
.property("expose-all-streams", false)
.property("caps", video_caps)
.property("uri", uri)
.build()?;
let conv = gst::ElementFactory::make("videoconvert").build()?;
let q1 = gst::ElementFactory::make("queue").build()?;
let enc = gst::ElementFactory::make("vp8enc")
.property("keyframe-max-dist", 30i32)
.property("threads", 12i32)
.property("cpu-used", -16i32)
.property("deadline", 1i64)
.property_from_str("error-resilient", "default")
.build()?;
let q2 = gst::ElementFactory::make("queue").build()?;
let pay = gst::ElementFactory::make("rtpvp8pay").build()?;
let rtpbin = gst::ElementFactory::make("rtpbin").build()?;
let sink = gst::ElementFactory::make("udpsink")
.property("host", "127.0.0.1")
.property("sync", true)
.build()?;
pipeline.add_many([&src, &conv, &q1, &enc, &q2, &pay, &rtpbin, &sink])?;
conv.link(&q1)?;
q1.link(&enc)?;
@ -149,20 +147,6 @@ fn example_main() -> Result<(), Error> {
},
);
let video_caps = gst::Caps::builder("video/x-raw").build();
src.set_property_from_str("pattern", "ball");
sink.set_property("host", "127.0.0.1");
sink.set_property("sync", true);
enc.set_property("keyframe-max-dist", 30i32);
enc.set_property("threads", 12i32);
enc.set_property("cpu-used", -16i32);
enc.set_property("deadline", 1i64);
enc.set_property_from_str("error-resilient", "default");
src.set_property("expose-all-streams", false);
src.set_property("caps", video_caps);
src.set_property("uri", uri);
let bus = pipeline
.bus()
.expect("Pipeline without bus. Shouldn't happen!");
@ -184,23 +168,18 @@ fn example_main() -> Result<(), Error> {
return Err(ErrorMessage {
src: msg
.src()
.map(|s| String::from(s.path_string()))
.unwrap_or_else(|| String::from("None")),
error: err.error().to_string(),
.map(|s| s.path_string())
.unwrap_or_else(|| glib::GString::from("UNKNOWN")),
error: err.error(),
debug: err.debug(),
source: err.error(),
}
.into());
}
MessageView::StateChanged(s) => {
if let Some(element) = msg.src() {
if element == pipeline && s.current() == gst::State::Playing {
if element == &pipeline && s.current() == gst::State::Playing {
eprintln!("PLAYING");
gst::debug_bin_to_dot_file(
&pipeline,
gst::DebugGraphDetails::all(),
"server-playing",
);
pipeline.debug_to_dot_file(gst::DebugGraphDetails::all(), "server-playing");
}
}
}
@ -218,6 +197,6 @@ fn example_main() -> Result<(), Error> {
fn main() {
match examples_common::run(example_main) {
Ok(r) => r,
Err(e) => eprintln!("Error! {}", e),
Err(e) => eprintln!("Error! {e}"),
}
}

View file

@ -0,0 +1,223 @@
// This example demonstrates how to set up a rtsp server using GStreamer
// and extending the default auth module behaviour by subclassing RTSPAuth
// For this, the example creates a videotestsrc pipeline manually to be used
// by the RTSP server for providing data
#![allow(clippy::non_send_fields_in_send_ty)]
use anyhow::Error;
use derive_more::{Display, Error};
use gst_rtsp_server::prelude::*;
#[path = "../examples-common.rs"]
mod examples_common;
#[derive(Debug, Display, Error)]
#[display(fmt = "Could not get mount points")]
struct NoMountPoints;
fn main_loop() -> Result<(), Error> {
let main_loop = glib::MainLoop::new(None, false);
let server = gst_rtsp_server::RTSPServer::new();
// We create our custom auth module.
// The job of the auth module is to authenticate users and authorize
// factories access/construction.
let auth = auth::Auth::default();
server.set_auth(Some(&auth));
// Much like HTTP servers, RTSP servers have multiple endpoints that
// provide different streams. Here, we ask our server to give
// us a reference to his list of endpoints, so we can add our
// test endpoint, providing the pipeline from the cli.
let mounts = server.mount_points().ok_or(NoMountPoints)?;
// Next, we create a factory for the endpoint we want to create.
// The job of the factory is to create a new pipeline for each client that
// connects, or (if configured to do so) to reuse an existing pipeline.
let factory = gst_rtsp_server::RTSPMediaFactory::new();
// Here we tell the media factory the media we want to serve.
// This is done in the launch syntax. When the first client connects,
// the factory will use this syntax to create a new pipeline instance.
factory.set_launch("( videotestsrc ! vp8enc ! rtpvp8pay name=pay0 )");
// This setting specifies whether each connecting client gets the output
// of a new instance of the pipeline, or whether all connected clients share
// the output of the same pipeline.
// If you want to stream a fixed video you have stored on the server to any
// client, you would not set this to shared here (since every client wants
// to start at the beginning of the video). But if you want to distribute
// a live source, you will probably want to set this to shared, to save
// computing and memory capacity on the server.
factory.set_shared(true);
// Now we add a new mount-point and tell the RTSP server to serve the content
// provided by the factory we configured above, when a client connects to
// this specific path.
mounts.add_factory("/test", factory);
// Attach the server to our main context.
// A main context is the thing where other stuff is registering itself for its
// events (e.g. sockets, GStreamer bus, ...) and the main loop is something that
// polls the main context for its events and dispatches them to whoever is
// interested in them. In this example, we only do have one, so we can
// leave the context parameter empty, it will automatically select
// the default one.
let id = server.attach(None)?;
println!(
"Stream ready at rtsp://127.0.0.1:{}/test",
server.bound_port()
);
println!("user admin/password can access stream");
println!("user demo/demo passes authentication but receives 404");
println!("other users do not pass pass authentication and receive 401");
// Start the mainloop. From this point on, the server will start to serve
// our quality content to connecting clients.
main_loop.run();
id.remove();
Ok(())
}
// Our custom auth module
mod auth {
// In the imp submodule we include the actual implementation
mod imp {
use gst_rtsp::{RTSPHeaderField, RTSPStatusCode};
use gst_rtsp_server::{prelude::*, subclass::prelude::*, RTSPContext};
// This is the private data of our auth
#[derive(Default)]
pub struct Auth;
impl Auth {
// Simulate external auth validation and user extraction
// authorized users are admin/password and demo/demo
fn external_auth(&self, auth: &str) -> Option<String> {
if let Ok(decoded) = data_encoding::BASE64.decode(auth.as_bytes()) {
if let Ok(decoded) = std::str::from_utf8(&decoded) {
let tokens = decoded.split(':').collect::<Vec<_>>();
if tokens == vec!["admin", "password"] || tokens == vec!["demo", "demo"] {
return Some(tokens[0].into());
}
}
}
None
}
// Simulate external role check
// admin user can construct and access media factory
fn external_access_check(&self, user: &str) -> bool {
user == "admin"
}
}
// This trait registers our type with the GObject object system and
// provides the entry points for creating a new instance and setting
// up the class data
#[glib::object_subclass]
impl ObjectSubclass for Auth {
const NAME: &'static str = "RsRTSPAuth";
type Type = super::Auth;
type ParentType = gst_rtsp_server::RTSPAuth;
}
// Implementation of glib::Object virtual methods
impl ObjectImpl for Auth {}
// Implementation of gst_rtsp_server::RTSPAuth virtual methods
impl RTSPAuthImpl for Auth {
fn authenticate(&self, ctx: &RTSPContext) -> bool {
// authenticate should always be called with a valid context request
let req = ctx
.request()
.expect("Context without request. Should not happen !");
if let Some(auth_credentials) = req.parse_auth_credentials().first() {
if let Some(authorization) = auth_credentials.authorization() {
if let Some(user) = self.external_auth(authorization) {
// Update context token with authenticated username
ctx.set_token(
gst_rtsp_server::RTSPToken::builder()
.field("user", user)
.build(),
);
return true;
}
}
}
false
}
fn check(&self, ctx: &RTSPContext, role: &glib::GString) -> bool {
// We only check media factory access
if !role.starts_with("auth.check.media.factory") {
return true;
}
if ctx.token().is_none() {
// If we do not have a context token yet, check if there are any auth credentials in request
if !self.authenticate(ctx) {
// If there were no credentials, send a "401 Unauthorized" response
if let Some(resp) = ctx.response() {
resp.init_response(RTSPStatusCode::Unauthorized, ctx.request());
resp.add_header(
RTSPHeaderField::WwwAuthenticate,
"Basic realm=\"CustomRealm\"",
);
if let Some(client) = ctx.client() {
client.send_message(resp, ctx.session());
}
}
return false;
}
}
if let Some(token) = ctx.token() {
// If we already have a user token...
if self.external_access_check(&token.string("user").unwrap_or_default()) {
// grant access if user may access factory
return true;
} else {
// send a "404 Not Found" response if user may not access factory
if let Some(resp) = ctx.response() {
resp.init_response(RTSPStatusCode::NotFound, ctx.request());
if let Some(client) = ctx.client() {
client.send_message(resp, ctx.session());
}
}
}
}
false
}
}
}
// This here defines the public interface of our auth and implements
// the corresponding traits so that it behaves like any other RTSPAuth
glib::wrapper! {
pub struct Auth(ObjectSubclass<imp::Auth>) @extends gst_rtsp_server::RTSPAuth;
}
impl Default for Auth {
// Creates a new instance of our auth
fn default() -> Self {
glib::Object::new()
}
}
}
fn example_main() -> Result<(), Error> {
gst::init()?;
main_loop()
}
fn main() {
match examples_common::run(example_main) {
Ok(r) => r,
Err(e) => eprintln!("Error! {e}"),
}
}

View file

@ -5,13 +5,10 @@
// to this example's cli is spawned and the client's media is streamed into it.
use std::env;
use std::ptr;
use glib::translate::*;
use gst_rtsp_server::prelude::*;
use anyhow::Error;
use derive_more::{Display, Error};
use gst_rtsp_server::prelude::*;
#[path = "../examples-common.rs"]
mod examples_common;
@ -21,7 +18,7 @@ mod examples_common;
struct NoMountPoints;
#[derive(Debug, Display, Error)]
#[display(fmt = "Usage: {} LAUNCH_LINE", _0)]
#[display(fmt = "Usage: {_0} LAUNCH_LINE")]
struct UsageError(#[error(not(source))] String);
fn main_loop() -> Result<(), Error> {
@ -47,12 +44,11 @@ fn main_loop() -> Result<(), Error> {
// Here we configure a method of authentication that we want the
// server to require from clients.
let auth = gst_rtsp_server::RTSPAuth::new();
let token = gst_rtsp_server::RTSPToken::new(&[(
*gst_rtsp_server::RTSP_TOKEN_MEDIA_FACTORY_ROLE,
&"user",
)]);
let token = gst_rtsp_server::RTSPToken::builder()
.field(gst_rtsp_server::RTSP_TOKEN_MEDIA_FACTORY_ROLE, "user")
.build();
let basic = gst_rtsp_server::RTSPAuth::make_basic("user", "password");
// For propery authentication, we want to use encryption. And there's no
// For proper authentication, we want to use encryption. And there's no
// encryption without a certificate!
let cert = gio::TlsCertificate::from_pem(
"-----BEGIN CERTIFICATE-----\
@ -80,24 +76,14 @@ fn main_loop() -> Result<(), Error> {
W535W8UBbEg=-----END PRIVATE KEY-----",
)?;
// Bindable versions were added in b1f515178a363df0322d7adbd5754e1f6e2083c9
// This declares that the user "user" (once authenticated) has a role that
// allows them to access and construct media factories.
unsafe {
gst_rtsp_server::ffi::gst_rtsp_media_factory_add_role(
factory.to_glib_none().0,
"user".to_glib_none().0,
gst_rtsp_server::RTSP_PERM_MEDIA_FACTORY_ACCESS
.to_glib_none()
.0,
<bool as StaticType>::static_type().into_glib() as *const u8,
true.into_glib() as *const u8,
gst_rtsp_server::RTSP_PERM_MEDIA_FACTORY_CONSTRUCT.as_ptr() as *const u8,
<bool as StaticType>::static_type().into_glib() as *const u8,
true.into_glib() as *const u8,
ptr::null_mut::<u8>(),
);
}
factory.add_role_from_structure(
&gst::Structure::builder("user")
.field(gst_rtsp_server::RTSP_PERM_MEDIA_FACTORY_ACCESS, true)
.field(gst_rtsp_server::RTSP_PERM_MEDIA_FACTORY_CONSTRUCT, true)
.build(),
);
auth.set_tls_certificate(Some(&cert));
auth.add_basic(basic.as_str(), &token);
@ -121,7 +107,7 @@ fn main_loop() -> Result<(), Error> {
// Now we add a new mount-point and tell the RTSP server to use the factory
// we configured beforehand. This factory will take on the job of creating
// a pipeline, which will take on the incoming data of connected clients.
mounts.add_factory("/test", &factory);
mounts.add_factory("/test", factory);
// Attach the server to our main context.
// A main context is the thing where other stuff is registering itself for its
@ -154,6 +140,6 @@ fn example_main() -> Result<(), Error> {
fn main() {
match examples_common::run(example_main) {
Ok(r) => r,
Err(e) => eprintln!("Error! {}", e),
Err(e) => eprintln!("Error! {e}"),
}
}

View file

@ -8,10 +8,9 @@
// the client machinery and printing some status.
#![allow(clippy::non_send_fields_in_send_ty)]
use gst_rtsp_server::prelude::*;
use anyhow::Error;
use derive_more::{Display, Error};
use gst_rtsp_server::prelude::*;
#[path = "../examples-common.rs"]
mod examples_common;
@ -20,10 +19,6 @@ mod examples_common;
#[display(fmt = "Could not get mount points")]
struct NoMountPoints;
#[derive(Debug, Display, Error)]
#[display(fmt = "Usage: {} LAUNCH_LINE", _0)]
struct UsageError(#[error(not(source))] String);
fn main_loop() -> Result<(), Error> {
let main_loop = glib::MainLoop::new(None, false);
let server = server::Server::default();
@ -54,7 +49,7 @@ fn main_loop() -> Result<(), Error> {
// Now we add a new mount-point and tell the RTSP server to serve the content
// provided by the factory we configured above, when a client connects to
// this specific path.
mounts.add_factory("/test", &factory);
mounts.add_factory("/test", factory);
// Attach the server to our main context.
// A main context is the thing where other stuff is registering itself for its
@ -81,10 +76,10 @@ fn main_loop() -> Result<(), Error> {
// Our custom media factory that creates a media input manually
mod media_factory {
use super::*;
use gst_rtsp_server::subclass::prelude::*;
use super::*;
// In the imp submodule we include the actual implementation
mod imp {
use super::*;
@ -105,9 +100,10 @@ mod media_factory {
// Implementation of glib::Object virtual methods
impl ObjectImpl for Factory {
fn constructed(&self, factory: &Self::Type) {
self.parent_constructed(factory);
fn constructed(&self) {
self.parent_constructed();
let factory = self.obj();
// All media created by this factory are our custom media type. This would
// not require a media factory subclass and can also be called on the normal
// RTSPMediaFactory.
@ -117,27 +113,28 @@ mod media_factory {
// Implementation of gst_rtsp_server::RTSPMediaFactory virtual methods
impl RTSPMediaFactoryImpl for Factory {
fn create_element(
&self,
_factory: &Self::Type,
_url: &gst_rtsp::RTSPUrl,
) -> Option<gst::Element> {
fn create_element(&self, _url: &gst_rtsp::RTSPUrl) -> Option<gst::Element> {
// Create a simple VP8 videotestsrc input
let bin = gst::Bin::new(None);
let src = gst::ElementFactory::make("videotestsrc", None).unwrap();
let enc = gst::ElementFactory::make("vp8enc", None).unwrap();
let bin = gst::Bin::default();
let src = gst::ElementFactory::make("videotestsrc")
// Configure the videotestsrc live
.property("is-live", true)
.build()
.unwrap();
let enc = gst::ElementFactory::make("vp8enc")
// Produce encoded data as fast as possible
.property("deadline", 1i64)
.build()
.unwrap();
// The names of the payloaders must be payX
let pay = gst::ElementFactory::make("rtpvp8pay", Some("pay0")).unwrap();
let pay = gst::ElementFactory::make("rtpvp8pay")
.name("pay0")
.build()
.unwrap();
// Configure the videotestsrc live
src.set_property("is-live", true);
// Produce encoded data as fast as possible
enc.set_property("deadline", 1i64);
bin.add_many(&[&src, &enc, &pay]).unwrap();
gst::Element::link_many(&[&src, &enc, &pay]).unwrap();
bin.add_many([&src, &enc, &pay]).unwrap();
gst::Element::link_many([&src, &enc, &pay]).unwrap();
Some(bin.upcast())
}
@ -150,14 +147,10 @@ mod media_factory {
pub struct Factory(ObjectSubclass<imp::Factory>) @extends gst_rtsp_server::RTSPMediaFactory;
}
// Factories must be Send+Sync, and ours is
unsafe impl Send for Factory {}
unsafe impl Sync for Factory {}
impl Default for Factory {
// Creates a new instance of our factory
fn default() -> Factory {
glib::Object::new(&[]).expect("Failed to create factory")
glib::Object::new()
}
}
}
@ -191,11 +184,10 @@ mod media {
impl RTSPMediaImpl for Media {
fn setup_sdp(
&self,
media: &Self::Type,
sdp: &mut gst_sdp::SDPMessageRef,
info: &gst_rtsp_server::subclass::SDPInfo,
) -> Result<(), gst::LoggableError> {
self.parent_setup_sdp(media, sdp, info)?;
self.parent_setup_sdp(sdp, info)?;
sdp.add_attribute("my-custom-attribute", Some("has-a-value"));
@ -209,19 +201,15 @@ mod media {
glib::wrapper! {
pub struct Media(ObjectSubclass<imp::Media>) @extends gst_rtsp_server::RTSPMedia;
}
// Medias must be Send+Sync, and ours is
unsafe impl Send for Media {}
unsafe impl Sync for Media {}
}
// Our custom RTSP server subclass that reports when clients are connecting and uses
// our custom RTSP client subclass for each client
mod server {
use super::*;
use gst_rtsp_server::subclass::prelude::*;
use super::*;
// In the imp submodule we include the actual implementation
mod imp {
use super::*;
@ -245,7 +233,8 @@ mod server {
// Implementation of gst_rtsp_server::RTSPServer virtual methods
impl RTSPServerImpl for Server {
fn create_client(&self, server: &Self::Type) -> Option<gst_rtsp_server::RTSPClient> {
fn create_client(&self) -> Option<gst_rtsp_server::RTSPClient> {
let server = self.obj();
let client = super::client::Client::default();
// Duplicated from the default implementation
@ -257,9 +246,9 @@ mod server {
Some(client.upcast())
}
fn client_connected(&self, server: &Self::Type, client: &gst_rtsp_server::RTSPClient) {
self.parent_client_connected(server, client);
println!("Client {:?} connected", client);
fn client_connected(&self, client: &gst_rtsp_server::RTSPClient) {
self.parent_client_connected(client);
println!("Client {client:?} connected");
}
}
}
@ -270,14 +259,10 @@ mod server {
pub struct Server(ObjectSubclass<imp::Server>) @extends gst_rtsp_server::RTSPServer;
}
// Servers must be Send+Sync, and ours is
unsafe impl Send for Server {}
unsafe impl Sync for Server {}
impl Default for Server {
// Creates a new instance of our factory
fn default() -> Server {
glib::Object::new(&[]).expect("Failed to create server")
glib::Object::new()
}
}
}
@ -309,9 +294,16 @@ mod client {
// Implementation of gst_rtsp_server::RTSPClient virtual methods
impl RTSPClientImpl for Client {
fn closed(&self, client: &Self::Type) {
self.parent_closed(client);
println!("Client {:?} closed", client);
fn closed(&self) {
let client = self.obj();
self.parent_closed();
println!("Client {client:?} closed");
}
fn describe_request(&self, ctx: &gst_rtsp_server::RTSPContext) {
self.parent_describe_request(ctx);
let request_uri = ctx.uri().unwrap().request_uri();
println!("Describe request for uri: {request_uri:?}");
}
}
}
@ -322,14 +314,10 @@ mod client {
pub struct Client(ObjectSubclass<imp::Client>) @extends gst_rtsp_server::RTSPClient;
}
// Clients must be Send+Sync, and ours is
unsafe impl Send for Client {}
unsafe impl Sync for Client {}
impl Default for Client {
// Creates a new instance of our factory
fn default() -> Client {
glib::Object::new(&[]).expect("Failed to create client")
glib::Object::new()
}
}
}
@ -359,13 +347,9 @@ mod mount_points {
// Implementation of gst_rtsp_server::RTSPClient virtual methods
impl RTSPMountPointsImpl for MountPoints {
fn make_path(
&self,
mount_points: &Self::Type,
url: &gst_rtsp::RTSPUrl,
) -> Option<glib::GString> {
println!("Make path called for {:?} ", url);
self.parent_make_path(mount_points, url)
fn make_path(&self, url: &gst_rtsp::RTSPUrl) -> Option<glib::GString> {
println!("Make path called for {url:?} ");
self.parent_make_path(url)
}
}
}
@ -374,14 +358,10 @@ mod mount_points {
pub struct MountPoints(ObjectSubclass<imp::MountPoints>) @extends gst_rtsp_server::RTSPMountPoints;
}
// MountPoints must be Send+Sync, and ours is
unsafe impl Send for MountPoints {}
unsafe impl Sync for MountPoints {}
impl Default for MountPoints {
// Creates a new instance of our factory
fn default() -> Self {
glib::Object::new(&[]).expect("Failed to create mount points")
glib::Object::new()
}
}
}
@ -394,6 +374,6 @@ fn example_main() -> Result<(), Error> {
fn main() {
match examples_common::run(example_main) {
Ok(r) => r,
Err(e) => eprintln!("Error! {}", e),
Err(e) => eprintln!("Error! {e}"),
}
}

View file

@ -5,10 +5,9 @@
use std::env;
use gst_rtsp_server::prelude::*;
use anyhow::Error;
use derive_more::{Display, Error};
use gst_rtsp_server::prelude::*;
#[path = "../examples-common.rs"]
mod examples_common;
@ -18,7 +17,7 @@ mod examples_common;
struct NoMountPoints;
#[derive(Debug, Display, Error)]
#[display(fmt = "Usage: {} LAUNCH_LINE", _0)]
#[display(fmt = "Usage: {_0} LAUNCH_LINE")]
struct UsageError(#[error(not(source))] String);
fn main_loop() -> Result<(), Error> {
@ -57,7 +56,7 @@ fn main_loop() -> Result<(), Error> {
// Now we add a new mount-point and tell the RTSP server to serve the content
// provided by the factory we configured above, when a client connects to
// this specific path.
mounts.add_factory("/test", &factory);
mounts.add_factory("/test", factory);
// Attach the server to our main context.
// A main context is the thing where other stuff is registering itself for its
@ -90,6 +89,6 @@ fn example_main() -> Result<(), Error> {
fn main() {
match examples_common::run(example_main) {
Ok(r) => r,
Err(e) => eprintln!("Error! {}", e),
Err(e) => eprintln!("Error! {e}"),
}
}

View file

@ -7,23 +7,17 @@
// coefficients are provided via Rust API on the filter as a Vec<f32>.
#![allow(clippy::non_send_fields_in_send_ty)]
use gst::prelude::*;
use gst::{element_error, gst_info, gst_trace};
use anyhow::Error;
use derive_more::{Display, Error};
use gst::prelude::*;
#[path = "../examples-common.rs"]
mod examples_common;
// Our custom FIR filter element is defined in this module
mod fir_filter {
use super::*;
use gst_base::subclass::prelude::*;
use byte_slice_cast::*;
use gst_base::subclass::prelude::*;
use once_cell::sync::Lazy;
// The debug category we use below for our filter
@ -37,10 +31,9 @@ mod fir_filter {
// In the imp submodule we include the actual implementation
mod imp {
use std::{collections::VecDeque, sync::Mutex};
use super::*;
use std::collections::VecDeque;
use std::i32;
use std::sync::Mutex;
// This is the private data of our filter
#[derive(Default)]
@ -67,33 +60,35 @@ mod fir_filter {
// Implementation of gst::Element virtual methods
impl ElementImpl for FirFilter {
// The element specific metadata. This information is what is visible from
// gst-inspect-1.0 and can also be programatically retrieved from the gst::Registry
// gst-inspect-1.0 and can also be programmatically retrieved from the gst::Registry
// after initial registration without having to load the plugin in memory.
fn metadata() -> Option<&'static gst::subclass::ElementMetadata> {
static ELEMENT_METADATA: Lazy<gst::subclass::ElementMetadata> = Lazy::new(|| {
static ELEMENT_METADATA: std::sync::OnceLock<gst::subclass::ElementMetadata> =
std::sync::OnceLock::new();
Some(ELEMENT_METADATA.get_or_init(|| {
gst::subclass::ElementMetadata::new(
"FIR Filter",
"Filter/Effect/Audio",
"A FIR audio filter",
"Sebastian Dröge <sebastian@centricular.com>",
)
});
Some(&*ELEMENT_METADATA)
}))
}
fn pad_templates() -> &'static [gst::PadTemplate] {
static PAD_TEMPLATES: Lazy<Vec<gst::PadTemplate>> = Lazy::new(|| {
static PAD_TEMPLATES: std::sync::OnceLock<Vec<gst::PadTemplate>> =
std::sync::OnceLock::new();
PAD_TEMPLATES.get_or_init(|| {
// Create pad templates for our sink and source pad. These are later used for
// actually creating the pads and beforehand already provide information to
// GStreamer about all possible pads that could exist for this type.
// On both of pads we can only handle F32 mono at any sample rate.
let caps = gst::Caps::builder("audio/x-raw")
.field("format", gst_audio::AUDIO_FORMAT_F32.to_str())
.field("rate", gst::IntRange::<i32>::new(1, i32::MAX))
.field("channels", 1i32)
.field("layout", "interleaved")
let caps = gst_audio::AudioCapsBuilder::new_interleaved()
.format(gst_audio::AUDIO_FORMAT_F32)
.channels(1)
.build();
vec![
@ -116,9 +111,7 @@ mod fir_filter {
)
.unwrap(),
]
});
PAD_TEMPLATES.as_ref()
})
}
}
@ -138,18 +131,18 @@ mod fir_filter {
// Returns the size of one processing unit (i.e. a frame in our case) corresponding
// to the given caps. This is used for allocating a big enough output buffer and
// sanity checking the input buffer size, among other things.
fn unit_size(&self, _element: &Self::Type, caps: &gst::Caps) -> Option<usize> {
fn unit_size(&self, caps: &gst::Caps) -> Option<usize> {
let audio_info = gst_audio::AudioInfo::from_caps(caps).ok();
audio_info.map(|info| info.bpf() as usize)
}
// Called when shutting down the element so we can release all stream-related state
// There's also start(), which is called whenever starting the element again
fn stop(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> {
fn stop(&self) -> Result<(), gst::ErrorMessage> {
// Drop state
self.history.lock().unwrap().clear();
gst_info!(CAT, obj: element, "Stopped");
gst::info!(CAT, imp: self, "Stopped");
Ok(())
}
@ -157,20 +150,19 @@ mod fir_filter {
// Does the actual transformation of the input buffer to the output buffer
fn transform_ip(
&self,
element: &Self::Type,
buf: &mut gst::BufferRef,
) -> Result<gst::FlowSuccess, gst::FlowError> {
// Get coefficients and return directly if we have none
let coeffs = self.coeffs.lock().unwrap();
if coeffs.is_empty() {
gst_trace!(CAT, obj: element, "No coefficients set -- passthrough");
gst::trace!(CAT, imp: self, "No coefficients set -- passthrough");
return Ok(gst::FlowSuccess::Ok);
}
// Try mapping the input buffer as writable
let mut data = buf.map_writable().map_err(|_| {
element_error!(
element,
gst::element_imp_error!(
self,
gst::CoreError::Failed,
["Failed to map input buffer readable"]
);
@ -179,8 +171,8 @@ mod fir_filter {
// And reinterprete it as a slice of f32
let samples = data.as_mut_slice_of::<f32>().map_err(|err| {
element_error!(
element,
gst::element_imp_error!(
self,
gst::CoreError::Failed,
["Failed to cast input buffer as f32 slice: {}", err]
);
@ -189,9 +181,9 @@ mod fir_filter {
let mut history = self.history.lock().unwrap();
gst_trace!(
gst::trace!(
CAT,
obj: element,
imp: self,
"Transforming {} samples with filter of length {}",
samples.len(),
coeffs.len()
@ -223,58 +215,46 @@ mod fir_filter {
pub struct FirFilter(ObjectSubclass<imp::FirFilter>) @extends gst_base::BaseTransform, gst::Element, gst::Object;
}
// GStreamer elements must be Send+Sync, and ours is
unsafe impl Send for FirFilter {}
unsafe impl Sync for FirFilter {}
impl FirFilter {
// Creates a new instance of our filter with the given name
pub fn new(name: Option<&str>) -> FirFilter {
glib::Object::new(&[("name", &name)]).expect("Failed to create fir filter")
glib::Object::builder().property("name", name).build()
}
// Sets the coefficients by getting access to the private
// struct and simply setting them
pub fn set_coeffs(&self, coeffs: Vec<f32>) {
let imp = imp::FirFilter::from_instance(self);
let imp = self.imp();
*imp.coeffs.lock().unwrap() = coeffs;
}
}
}
#[derive(Debug, Display, Error)]
#[display(fmt = "Missing element {}", _0)]
struct MissingElement(#[error(not(source))] &'static str);
#[derive(Debug, Display, Error)]
#[display(fmt = "Received error from {}: {} (debug: {:?})", src, error, debug)]
#[display(fmt = "Received error from {src}: {error} (debug: {debug:?})")]
struct ErrorMessage {
src: String,
error: String,
debug: Option<String>,
source: glib::Error,
src: glib::GString,
error: glib::Error,
debug: Option<glib::GString>,
}
fn create_pipeline() -> Result<gst::Pipeline, Error> {
gst::init()?;
// Create our pipeline with the custom element
let pipeline = gst::Pipeline::new(None);
let src = gst::ElementFactory::make("audiotestsrc", None)
.map_err(|_| MissingElement("audiotestsrc"))?;
let pipeline = gst::Pipeline::default();
let src = gst::ElementFactory::make("audiotestsrc")
.property_from_str("wave", "white-noise")
.build()?;
let filter = fir_filter::FirFilter::new(None);
let conv = gst::ElementFactory::make("audioconvert", None)
.map_err(|_| MissingElement("audioconvert"))?;
let sink = gst::ElementFactory::make("autoaudiosink", None)
.map_err(|_| MissingElement("autoaudiosink"))?;
let conv = gst::ElementFactory::make("audioconvert").build()?;
let sink = gst::ElementFactory::make("autoaudiosink").build()?;
pipeline.add_many(&[&src, filter.upcast_ref(), &conv, &sink])?;
pipeline.add_many([&src, filter.upcast_ref(), &conv, &sink])?;
src.link(&filter)?;
filter.link(&conv)?;
conv.link(&sink)?;
src.set_property_from_str("wave", "white-noise");
// Create a windowed sinc lowpass filter at 1/64 sample rate,
// i.e. 689Hz for 44.1kHz sample rate
let w = 2.0 * std::f32::consts::PI / 64.0;
@ -324,11 +304,10 @@ fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> {
return Err(ErrorMessage {
src: msg
.src()
.map(|s| String::from(s.path_string()))
.unwrap_or_else(|| String::from("None")),
error: err.error().to_string(),
.map(|s| s.path_string())
.unwrap_or_else(|| glib::GString::from("UNKNOWN")),
error: err.error(),
debug: err.debug(),
source: err.error(),
}
.into());
}
@ -344,7 +323,7 @@ fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> {
fn example_main() {
match create_pipeline().and_then(main_loop) {
Ok(r) => r,
Err(e) => eprintln!("Error! {}", e),
Err(e) => eprintln!("Error! {e}"),
}
}

View file

@ -0,0 +1,188 @@
// In the imp submodule we include the actual implementation
use std::{collections::VecDeque, sync::Mutex};
use glib::prelude::*;
use gst_audio::subclass::prelude::*;
use once_cell::sync::Lazy;
use byte_slice_cast::*;
use atomic_refcell::AtomicRefCell;
// The debug category we use below for our filter
pub static CAT: Lazy<gst::DebugCategory> = Lazy::new(|| {
gst::DebugCategory::new(
"rsiirfilter",
gst::DebugColorFlags::empty(),
Some("Rust IIR Filter"),
)
});
#[derive(Default)]
// This is the state of our filter
struct State {
a: Vec<f64>,
b: Vec<f64>,
x: VecDeque<f64>,
y: VecDeque<f64>,
}
// This is the private data of our filter
#[derive(Default)]
pub struct IirFilter {
coeffs: Mutex<Option<(Vec<f64>, Vec<f64>)>>,
state: AtomicRefCell<State>,
}
// This trait registers our type with the GObject object system and
// provides the entry points for creating a new instance and setting
// up the class data
#[glib::object_subclass]
impl ObjectSubclass for IirFilter {
const NAME: &'static str = "RsIirFilter";
const ABSTRACT: bool = true;
type Type = super::IirFilter;
type ParentType = gst_audio::AudioFilter;
type Class = super::Class;
// Here we set default implementations for all the virtual methods.
// This is mandatory for all virtual methods that are not `Option`s.
fn class_init(class: &mut Self::Class) {
class.set_rate = |obj, rate| obj.imp().set_rate_default(rate);
}
}
// Implementation of glib::Object virtual methods
impl ObjectImpl for IirFilter {}
impl GstObjectImpl for IirFilter {}
// Implementation of gst::Element virtual methods
impl ElementImpl for IirFilter {}
// Implementation of gst_base::BaseTransform virtual methods
impl BaseTransformImpl for IirFilter {
// Configure basetransform so that we are always running in-place,
// don't passthrough on same caps and also never call transform_ip
// in passthrough mode (which does not matter for us here).
//
// The way how our processing is implemented, in-place transformation
// is simpler.
const MODE: gst_base::subclass::BaseTransformMode =
gst_base::subclass::BaseTransformMode::AlwaysInPlace;
const PASSTHROUGH_ON_SAME_CAPS: bool = false;
const TRANSFORM_IP_ON_PASSTHROUGH: bool = false;
fn start(&self) -> Result<(), gst::ErrorMessage> {
self.parent_start()?;
*self.state.borrow_mut() = State::default();
Ok(())
}
fn stop(&self) -> Result<(), gst::ErrorMessage> {
self.parent_stop()?;
*self.state.borrow_mut() = State::default();
Ok(())
}
fn transform_ip(&self, buf: &mut gst::BufferRef) -> Result<gst::FlowSuccess, gst::FlowError> {
let mut state = self.state.borrow_mut();
// Update coefficients if new coefficients were set
{
let mut coeffs = self.coeffs.lock().unwrap();
if let Some((a, b)) = coeffs.take() {
state.x.clear();
state.y.clear();
if !a.is_empty() {
state.y.resize(a.len() - 1, 0.0);
}
if !b.is_empty() {
state.x.resize(b.len() - 1, 0.0);
}
state.a = a;
state.b = b;
}
}
if state.a.is_empty() | state.b.is_empty() {
return Ok(gst::FlowSuccess::Ok);
}
let mut map = buf.map_writable().map_err(|_| {
gst::error!(CAT, imp: self, "Failed to map buffer writable");
gst::FlowError::Error
})?;
let samples = map.as_mut_slice_of::<f32>().unwrap();
assert!(state.b.len() - 1 == state.x.len());
assert!(state.a.len() - 1 == state.y.len());
for sample in samples.iter_mut() {
let mut val = state.b[0] * *sample as f64;
for (b, x) in Iterator::zip(state.b.iter().skip(1), state.x.iter()) {
val += b * x;
}
for (a, y) in Iterator::zip(state.a.iter().skip(1), state.y.iter()) {
val -= a * y;
}
val /= state.a[0];
let _ = state.x.pop_back().unwrap();
state.x.push_front(*sample as f64);
let _ = state.y.pop_back().unwrap();
state.y.push_front(val);
*sample = val as f32;
}
Ok(gst::FlowSuccess::Ok)
}
}
impl AudioFilterImpl for IirFilter {
fn allowed_caps() -> &'static gst::Caps {
static CAPS: std::sync::OnceLock<gst::Caps> = std::sync::OnceLock::new();
CAPS.get_or_init(|| {
// On both of pads we can only handle F32 mono at any sample rate.
gst_audio::AudioCapsBuilder::new_interleaved()
.format(gst_audio::AUDIO_FORMAT_F32)
.channels(1)
.build()
})
}
fn setup(&self, info: &gst_audio::AudioInfo) -> Result<(), gst::LoggableError> {
self.parent_setup(info)?;
gst::debug!(CAT, imp: self, "Rate changed to {}", info.rate());
let obj = self.obj();
(obj.class().as_ref().set_rate)(&obj, info.rate());
Ok(())
}
}
/// Wrappers for public methods and associated helper functions.
impl IirFilter {
pub(super) fn set_coeffs(&self, a: Vec<f64>, b: Vec<f64>) {
gst::debug!(CAT, imp: self, "Setting coefficients a: {a:?}, b: {b:?}");
*self.coeffs.lock().unwrap() = Some((a, b));
}
}
/// Default virtual method implementations.
impl IirFilter {
fn set_rate_default(&self, _rate: u32) {}
}

View file

@ -0,0 +1,86 @@
use gst::{prelude::*, subclass::prelude::*};
use gst_audio::subclass::prelude::*;
mod imp;
// This here defines the public interface of our element and implements
// the corresponding traits so that it behaves like any other gst::Element
//
// GObject
// ╰──GstObject
// ╰──GstElement
// ╰──GstBaseTransform
// ╰──GstAudioFilter
// ╰──IirFilter
glib::wrapper! {
pub struct IirFilter(ObjectSubclass<imp::IirFilter>) @extends gst_audio::AudioFilter, gst_base::BaseTransform, gst::Element, gst::Object;
}
/// Trait containing extension methods for `IirFilter`.
pub trait IirFilterExt: IsA<IirFilter> {
// Sets the coefficients by getting access to the private struct and simply setting them
fn set_coeffs(&self, a: Vec<f64>, b: Vec<f64>) {
self.upcast_ref::<IirFilter>().imp().set_coeffs(a, b)
}
}
impl<O: IsA<IirFilter>> IirFilterExt for O {}
/// Trait to implement in `IirFilter` subclasses.
pub trait IirFilterImpl: AudioFilterImpl {
/// Called whenever the sample rate is changing.
fn set_rate(&self, rate: u32) {
self.parent_set_rate(rate);
}
}
/// Trait containing extension methods for `IirFilterImpl`, specifically methods for chaining
/// up to the parent implementation of virtual methods.
pub trait IirFilterImplExt: IirFilterImpl {
fn parent_set_rate(&self, rate: u32) {
unsafe {
let data = Self::type_data();
let parent_class = &*(data.as_ref().parent_class() as *mut Class);
(parent_class.set_rate)(self.obj().unsafe_cast_ref(), rate)
}
}
}
impl<T: IirFilterImpl> IirFilterImplExt for T {}
/// Class struct for `IirFilter`.
#[repr(C)]
pub struct Class {
parent: <<imp::IirFilter as ObjectSubclass>::ParentType as ObjectType>::GlibClassType,
set_rate: fn(&IirFilter, rate: u32),
}
unsafe impl ClassStruct for Class {
type Type = imp::IirFilter;
}
/// This allows directly using `Class` as e.g. `gst_audio::AudioFilterClass` or
/// `gst_base::BaseTransformClass` without having to cast.
impl std::ops::Deref for Class {
type Target = glib::Class<<<Self as ClassStruct>::Type as ObjectSubclass>::ParentType>;
fn deref(&self) -> &Self::Target {
unsafe { &*(&self.parent as *const _ as *const _) }
}
}
/// Overrides the virtual methods with the actual implementation of the subclass as is provided by
/// the subclass' implementation of the `Impl` trait.
unsafe impl<T: IirFilterImpl> IsSubclassable<T> for IirFilter {
fn class_init(class: &mut glib::Class<Self>) {
Self::parent_class_init::<T>(class);
let class = class.as_mut();
class.set_rate = |obj, rate| unsafe {
let imp = obj.unsafe_cast_ref::<T::Type>().imp();
imp.set_rate(rate);
};
}
}

View file

@ -0,0 +1,170 @@
// In the imp submodule we include the actual implementation
use std::sync::Mutex;
use glib::prelude::*;
use gst::prelude::*;
use gst_audio::subclass::prelude::*;
use crate::iirfilter::{IirFilterExt, IirFilterImpl};
// These are the property values of our filter
pub struct Settings {
cutoff: f32,
}
impl Default for Settings {
fn default() -> Self {
Settings { cutoff: 0.0 }
}
}
// This is the state of our filter
#[derive(Default)]
pub struct State {
rate: Option<u32>,
}
// This is the private data of our filter
#[derive(Default)]
pub struct Lowpass {
settings: Mutex<Settings>,
state: Mutex<State>,
}
// This trait registers our type with the GObject object system and
// provides the entry points for creating a new instance and setting
// up the class data
#[glib::object_subclass]
impl ObjectSubclass for Lowpass {
const NAME: &'static str = "RsLowpass";
type Type = super::Lowpass;
type ParentType = crate::iirfilter::IirFilter;
}
// Implementation of glib::Object virtual methods
impl ObjectImpl for Lowpass {
fn properties() -> &'static [glib::ParamSpec] {
static PROPERTIES: std::sync::OnceLock<Vec<glib::ParamSpec>> = std::sync::OnceLock::new();
PROPERTIES.get_or_init(|| {
vec![glib::ParamSpecFloat::builder("cutoff")
.nick("Cutoff")
.blurb("Cutoff frequency in Hz")
.default_value(Settings::default().cutoff)
.minimum(0.0)
.mutable_playing()
.build()]
})
}
fn set_property(&self, _id: usize, value: &glib::Value, pspec: &glib::ParamSpec) {
match pspec.name() {
"cutoff" => {
self.settings.lock().unwrap().cutoff = value.get().unwrap();
self.calculate_coeffs();
}
_ => unimplemented!(),
};
}
fn property(&self, _id: usize, pspec: &glib::ParamSpec) -> glib::Value {
match pspec.name() {
"cutoff" => self.settings.lock().unwrap().cutoff.to_value(),
_ => unimplemented!(),
}
}
}
impl GstObjectImpl for Lowpass {}
// Implementation of gst::Element virtual methods
impl ElementImpl for Lowpass {
// The element specific metadata. This information is what is visible from
// gst-inspect-1.0 and can also be programmatically retrieved from the gst::Registry
// after initial registration without having to load the plugin in memory.
fn metadata() -> Option<&'static gst::subclass::ElementMetadata> {
static ELEMENT_METADATA: std::sync::OnceLock<gst::subclass::ElementMetadata> =
std::sync::OnceLock::new();
Some(ELEMENT_METADATA.get_or_init(|| {
gst::subclass::ElementMetadata::new(
"Lowpass Filter",
"Filter/Effect/Audio",
"A Lowpass audio filter",
"Sebastian Dröge <sebastian@centricular.com>",
)
}))
}
}
// Implementation of gst_base::BaseTransform virtual methods
impl BaseTransformImpl for Lowpass {
const MODE: gst_base::subclass::BaseTransformMode =
<<crate::iirfilter::IirFilter as glib::object::ObjectSubclassIs>::Subclass>::MODE;
const PASSTHROUGH_ON_SAME_CAPS: bool =
<<crate::iirfilter::IirFilter as glib::object::ObjectSubclassIs>::Subclass>::PASSTHROUGH_ON_SAME_CAPS;
const TRANSFORM_IP_ON_PASSTHROUGH: bool =
<<crate::iirfilter::IirFilter as glib::object::ObjectSubclassIs>::Subclass>::TRANSFORM_IP_ON_PASSTHROUGH;
fn start(&self) -> Result<(), gst::ErrorMessage> {
self.parent_start()?;
*self.state.lock().unwrap() = State::default();
Ok(())
}
}
// Implement of gst_audio::AudioFilter virtual methods
impl AudioFilterImpl for Lowpass {}
// Implement of IirFilter virtual methods
impl IirFilterImpl for Lowpass {
fn set_rate(&self, rate: u32) {
// Could call
// self.parent_set_rate(rate);
// here but chaining up is not necessary if the base class doesn't require that
// or if the behaviour of the parent class should be completely overridden.
self.state.lock().unwrap().rate = Some(rate);
self.calculate_coeffs();
}
}
impl Lowpass {
fn calculate_coeffs(&self) {
use std::f64;
let Some(rate) = self.state.lock().unwrap().rate else {
return;
};
let cutoff = self.settings.lock().unwrap().cutoff;
// See Audio EQ Cookbook
// https://www.w3.org/TR/audio-eq-cookbook
let cutoff = cutoff as f64 / rate as f64;
let omega = 2.0 * f64::consts::PI * cutoff;
let q = 1.0;
let alpha = f64::sin(omega) / (2.0 * q);
let mut b = vec![
(1.0 - f64::cos(omega)) / 2.0,
1.0 - f64::cos(omega),
(1.0 - f64::cos(omega) / 2.0),
];
let mut a = vec![1.0 + alpha, -2.0 * f64::cos(omega), 1.0 - alpha];
let a0 = a[0];
for a in &mut a {
*a /= a0;
}
for b in &mut b {
*b /= a0;
}
self.obj().set_coeffs(a, b);
}
}

View file

@ -0,0 +1,15 @@
mod imp;
// This here defines the public interface of our element and implements
// the corresponding traits so that it behaves like any other gst::Element
//
// GObject
// ╰──GstObject
// ╰──GstElement
// ╰──GstBaseTransform
// ╰──GstAudioFilter
// ╰──IirFilter
// ╰──Lowpass
glib::wrapper! {
pub struct Lowpass(ObjectSubclass<imp::Lowpass>) @extends crate::iirfilter::IirFilter, gst_audio::AudioFilter, gst_base::BaseTransform, gst::Element, gst::Object;
}

View file

@ -0,0 +1,66 @@
// This example implements a baseclass IirFilter, and a subclass Lowpass of that.
//
// The example shows how to provide and implement virtual methods, and how to provide non-virtual
// methods on the base class.
use gst::prelude::*;
mod iirfilter;
mod lowpass;
#[path = "../../examples-common.rs"]
mod examples_common;
fn example_main() {
gst::init().unwrap();
let pipeline = gst::Pipeline::new();
let src = gst::ElementFactory::make("audiotestsrc")
.property_from_str("wave", "white-noise")
.build()
.unwrap();
let filter = glib::Object::builder::<lowpass::Lowpass>()
.property("cutoff", 4000.0f32)
.build();
let conv = gst::ElementFactory::make("audioconvert").build().unwrap();
let sink = gst::ElementFactory::make("autoaudiosink").build().unwrap();
pipeline
.add_many([&src, filter.as_ref(), &conv, &sink])
.unwrap();
gst::Element::link_many([&src, filter.as_ref(), &conv, &sink]).unwrap();
let bus = pipeline.bus().unwrap();
pipeline
.set_state(gst::State::Playing)
.expect("Unable to set the pipeline to the `Playing` state");
for msg in bus.iter_timed(gst::ClockTime::NONE) {
use gst::MessageView;
match msg.view() {
MessageView::Eos(..) => break,
MessageView::Error(err) => {
println!(
"Error from {:?}: {} ({:?})",
err.src().map(|s| s.path_string()),
err.error(),
err.debug()
);
break;
}
_ => (),
}
}
pipeline
.set_state(gst::State::Null)
.expect("Unable to set the pipeline to the `Null` state");
}
fn main() {
// tutorials_common::run is only required to set up the application environment on macOS
// (but not necessary in normal Cocoa applications where this is set up automatically)
examples_common::run(example_main);
}

View file

@ -18,26 +18,23 @@
// (More modes of operation are possible, see: gst::TagMergeMode)
// This merge-mode can also be supplied to any method that adds new tags.
use gst::prelude::*;
use anyhow::anyhow;
use anyhow::Error;
use anyhow::{anyhow, Error};
use derive_more::{Display, Error};
use gst::prelude::*;
#[path = "../examples-common.rs"]
mod examples_common;
#[derive(Debug, Display, Error)]
#[display(fmt = "Missing element {}", _0)]
#[display(fmt = "Missing element {_0}")]
struct MissingElement(#[error(not(source))] String);
#[derive(Debug, Display, Error)]
#[display(fmt = "Received error from {}: {} (debug: {:?})", src, error, debug)]
#[display(fmt = "Received error from {src}: {error} (debug: {debug:?})")]
struct ErrorMessage {
src: String,
error: String,
debug: Option<String>,
source: glib::Error,
src: glib::GString,
error: glib::Error,
debug: Option<glib::GString>,
}
fn example_main() -> Result<(), Error> {
@ -45,7 +42,7 @@ fn example_main() -> Result<(), Error> {
// Parse the pipeline we want to probe from a static in-line string.
let mut context = gst::ParseContext::new();
let pipeline = match gst::parse_launch_full(
let pipeline = match gst::parse::launch_full(
"audiotestsrc wave=white-noise num-buffers=100 ! flacenc ! filesink location=test.flac",
Some(&mut context),
gst::ParseFlags::empty(),
@ -79,7 +76,8 @@ fn example_main() -> Result<(), Error> {
// Set the "title" tag to "Special randomized white-noise".
// The second parameter gst::TagMergeMode::Append tells the tagsetter to append this title
// if there already is one.
tagsetter.add::<gst::tags::Title>(&"Special randomized white-noise", gst::TagMergeMode::Append);
tagsetter
.add_tag::<gst::tags::Title>(&"Special randomized white-noise", gst::TagMergeMode::Append);
let bus = pipeline.bus().unwrap();
@ -92,14 +90,12 @@ fn example_main() -> Result<(), Error> {
MessageView::Eos(..) => break,
MessageView::Error(err) => {
return Err(ErrorMessage {
src: err
src: msg
.src()
.map(|s| s.path_string())
.unwrap_or_else(|| "None".into())
.to_string(),
error: err.error().to_string(),
.unwrap_or_else(|| glib::GString::from("UNKNOWN")),
error: err.error(),
debug: err.debug(),
source: err.error(),
}
.into());
}
@ -117,6 +113,6 @@ fn main() {
// (but not necessary in normal Cocoa applications where this is set up automatically)
match examples_common::run(example_main) {
Ok(r) => r,
Err(e) => eprintln!("Error! {}", e),
Err(e) => eprintln!("Error! {e}"),
}
}

View file

@ -7,35 +7,28 @@
// with the correct stride from GStreamer to the image crate as GStreamer does not necessarily
// produce tightly packed pixels, and in case of RGBx never.
use gst::element_error;
use gst::prelude::*;
use anyhow::Error;
use derive_more::{Display, Error};
use gst::{element_error, prelude::*};
use gst_video::prelude::*;
#[path = "../examples-common.rs"]
mod examples_common;
#[derive(Debug, Display, Error)]
#[display(fmt = "Missing element {}", _0)]
struct MissingElement(#[error(not(source))] &'static str);
#[derive(Debug, Display, Error)]
#[display(fmt = "Received error from {}: {} (debug: {:?})", src, error, debug)]
#[display(fmt = "Received error from {src}: {error} (debug: {debug:?})")]
struct ErrorMessage {
src: String,
error: String,
debug: Option<String>,
source: glib::Error,
src: glib::GString,
error: glib::Error,
debug: Option<glib::GString>,
}
fn create_pipeline(uri: String, out_path: std::path::PathBuf) -> Result<gst::Pipeline, Error> {
gst::init()?;
// Create our pipeline from a pipeline description string.
let pipeline = gst::parse_launch(&format!(
"uridecodebin uri={} ! videoconvert ! appsink name=sink",
uri
let pipeline = gst::parse::launch(&format!(
"uridecodebin uri={uri} ! videoconvert ! appsink name=sink"
))?
.downcast::<gst::Pipeline>()
.expect("Expected a gst::Pipeline");
@ -54,8 +47,8 @@ fn create_pipeline(uri: String, out_path: std::path::PathBuf) -> Result<gst::Pip
// This can be set after linking the two objects, because format negotiation between
// both elements will happen during pre-rolling of the pipeline.
appsink.set_caps(Some(
&gst::Caps::builder("video/x-raw")
.field("format", gst_video::VideoFormat::Rgbx.to_str())
&gst_video::VideoCapsBuilder::new()
.format(gst_video::VideoFormat::Rgbx)
.build(),
));
@ -181,7 +174,7 @@ fn main_loop(pipeline: gst::Pipeline, position: u64) -> Result<(), Error> {
MessageView::AsyncDone(..) => {
if !seeked {
// AsyncDone means that the pipeline has started now and that we can seek
println!("Got AsyncDone message, seeking to {}s", position);
println!("Got AsyncDone message, seeking to {position}s");
if pipeline
.seek_simple(gst::SeekFlags::FLUSH, position * gst::ClockTime::SECOND)
@ -208,11 +201,10 @@ fn main_loop(pipeline: gst::Pipeline, position: u64) -> Result<(), Error> {
return Err(ErrorMessage {
src: msg
.src()
.map(|s| String::from(s.path_string()))
.unwrap_or_else(|| String::from("None")),
error: err.error().to_string(),
.map(|s| s.path_string())
.unwrap_or_else(|| glib::GString::from("UNKNOWN")),
error: err.error(),
debug: err.debug(),
source: err.error(),
}
.into());
}
@ -248,7 +240,7 @@ fn example_main() {
match create_pipeline(uri, out_path).and_then(|pipeline| main_loop(pipeline, position)) {
Ok(r) => r,
Err(e) => eprintln!("Error! {}", e),
Err(e) => eprintln!("Error! {e}"),
}
}

View file

@ -9,10 +9,10 @@
// {filesrc} - {decodebin} - {queue} - {fakesink}
// \- ...
use gst::prelude::*;
use std::env;
use gst::prelude::*;
#[path = "../examples-common.rs"]
mod examples_common;
@ -27,14 +27,15 @@ fn example_main() {
std::process::exit(-1)
};
let pipeline = gst::Pipeline::new(None);
let src = gst::ElementFactory::make("filesrc", None).unwrap();
let decodebin = gst::ElementFactory::make("decodebin", None).unwrap();
let pipeline = gst::Pipeline::default();
let src = gst::ElementFactory::make("filesrc")
.property("location", uri)
.build()
.unwrap();
let decodebin = gst::ElementFactory::make("decodebin").build().unwrap();
src.set_property("location", uri);
pipeline.add_many(&[&src, &decodebin]).unwrap();
gst::Element::link_many(&[&src, &decodebin]).unwrap();
pipeline.add_many([&src, &decodebin]).unwrap();
gst::Element::link_many([&src, &decodebin]).unwrap();
// Need to move a new reference into the closure.
// !!ATTENTION!!:
@ -51,16 +52,15 @@ fn example_main() {
decodebin.connect_pad_added(move |_, src_pad| {
// Here we temporarily retrieve a strong reference on the pipeline from the weak one
// we moved into this callback.
let pipeline = match pipeline_weak.upgrade() {
Some(pipeline) => pipeline,
None => return,
let Some(pipeline) = pipeline_weak.upgrade() else {
return;
};
// In this example, we are only interested about parsing the ToC, so
// we simply pipe every encountered stream into a fakesink, essentially
// throwing away the data.
let queue = gst::ElementFactory::make("queue", None).unwrap();
let sink = gst::ElementFactory::make("fakesink", None).unwrap();
let queue = gst::ElementFactory::make("queue").build().unwrap();
let sink = gst::ElementFactory::make("fakesink").build().unwrap();
let elements = &[&queue, &sink];
pipeline.add_many(elements).unwrap();
@ -108,7 +108,7 @@ fn example_main() {
println!("\nReceived toc: {:?} - updated: {}", toc.scope(), updated);
// Get a list of tags that are ToC specific.
if let Some(tags) = toc.tags() {
println!("- tags: {}", tags);
println!("- tags: {tags}");
}
// ToCs do not have a fixed structure. Depending on the format that
// they were parsed from, they might have different tree-like structures,
@ -123,11 +123,11 @@ fn example_main() {
println!("\t{:?} - {}", toc_entry.entry_type(), toc_entry.uid());
// Every ToC entry can have a set of timestamps (start, stop).
if let Some((start, stop)) = toc_entry.start_stop_times() {
println!("\t- start: {}, stop: {}", start, stop);
println!("\t- start: {start}, stop: {stop}");
}
// Every ToC entry can have tags to it.
if let Some(tags) = toc_entry.tags() {
println!("\t- tags: {}", tags);
println!("\t- tags: {tags}");
}
// Every ToC entry can have a set of child entries.
// With this structure, you can create trees of arbitrary depth.
@ -138,10 +138,10 @@ fn example_main() {
toc_sub_entry.uid()
);
if let Some((start, stop)) = toc_sub_entry.start_stop_times() {
println!("\t\t- start: {}, stop: {}", start, stop);
println!("\t\t- start: {start}, stop: {stop}");
}
if let Some(tags) = toc_sub_entry.tags() {
println!("\t\t- tags: {}", tags);
println!("\t\t- tags: {tags}");
}
}
}

View file

@ -17,28 +17,21 @@
// {src} - {typefind} - {demuxer} -| {multiqueue} - {matroskamux} - {filesink}
// \-[video]-/
use gst::element_error;
use gst::prelude::*;
use std::env;
use anyhow::Error;
use derive_more::{Display, Error};
use gst::{element_error, prelude::*};
#[path = "../examples-common.rs"]
mod examples_common;
#[derive(Debug, Display, Error)]
#[display(fmt = "Missing element {}", _0)]
struct MissingElement(#[error(not(source))] &'static str);
#[derive(Debug, Display, Error)]
#[display(fmt = "Received error from {}: {} (debug: {:?})", src, error, debug)]
#[display(fmt = "Received error from {src}: {error} (debug: {debug:?})")]
struct ErrorMessage {
src: String,
error: String,
debug: Option<String>,
source: glib::Error,
src: glib::GString,
error: glib::Error,
debug: Option<glib::GString>,
}
fn example_main() -> Result<(), Error> {
@ -56,26 +49,24 @@ fn example_main() -> Result<(), Error> {
std::process::exit(-1)
};
let pipeline = gst::Pipeline::new(None);
let pipeline = gst::Pipeline::default();
let src = gst::Element::make_from_uri(gst::URIType::Src, uri, None)
.expect("We do not seem to support this uri");
let typefinder =
gst::ElementFactory::make("typefind", None).map_err(|_| MissingElement("typefind"))?;
let queue =
gst::ElementFactory::make("multiqueue", None).map_err(|_| MissingElement("multiqueue"))?;
let muxer = gst::ElementFactory::make("matroskamux", None)
.map_err(|_| MissingElement("matroskamux"))?;
let sink =
gst::ElementFactory::make("filesink", None).map_err(|_| MissingElement("filesink"))?;
let typefinder = gst::ElementFactory::make("typefind").build()?;
let queue = gst::ElementFactory::make("multiqueue")
.property("max-size-buffers", 0u32)
.property("max-size-time", 0u64)
.property("max-size-bytes", 1024u32 * 1024 * 100)
.build()?;
let muxer = gst::ElementFactory::make("matroskamux").build()?;
let sink = gst::ElementFactory::make("filesink")
.property("location", output_file)
.build()?;
sink.set_property("location", output_file);
// Increase the queue capacity to 100MB to avoid a stalling pipeline
queue.set_property("max-size-buffers", 0u32);
queue.set_property("max-size-time", 0u64);
queue.set_property("max-size-bytes", 1024u32 * 1024 * 100);
pipeline
.add_many(&[&src, &typefinder, &queue, &muxer, &sink])
.add_many([&src, &typefinder, &queue, &muxer, &sink])
.expect("failed to add elements to pipeline");
src.link(&typefinder)?;
@ -95,13 +86,13 @@ fn example_main() -> Result<(), Error> {
.expect("typefinder \"have-type\" signal values[2]");
let format_name = caps.structure(0).expect("Failed to get format name").name();
let demuxer = match format_name {
"video/x-matroska" | "video/webm" => {
gst::ElementFactory::make("matroskademux", None).expect("matroskademux missing")
}
"video/quicktime" => {
gst::ElementFactory::make("qtdemux", None).expect("qtdemux missing")
}
let demuxer = match format_name.as_str() {
"video/x-matroska" | "video/webm" => gst::ElementFactory::make("matroskademux")
.build()
.expect("matroskademux missing"),
"video/quicktime" => gst::ElementFactory::make("qtdemux")
.build()
.expect("qtdemux missing"),
_ => {
eprintln!("Sorry, this format is not supported by this example.");
std::process::exit(-1);
@ -148,11 +139,10 @@ fn example_main() -> Result<(), Error> {
return Err(ErrorMessage {
src: msg
.src()
.map(|s| String::from(s.path_string()))
.unwrap_or_else(|| String::from("None")),
error: err.error().to_string(),
.map(|s| s.path_string())
.unwrap_or_else(|| glib::GString::from("UNKNOWN")),
error: err.error(),
debug: err.debug(),
source: err.error(),
}
.into());
}
@ -222,6 +212,6 @@ fn main() {
// (but not necessary in normal Cocoa applications where this is set up automatically)
match examples_common::run(example_main) {
Ok(r) => r,
Err(e) => eprintln!("Error! {}", e),
Err(e) => eprintln!("Error! {e}"),
}
}

View file

@ -11,7 +11,7 @@ fn example_main() {
gst::init().unwrap();
// This creates a pipeline by parsing the gst-launch pipeline syntax.
let pipeline = gst::parse_launch(
let pipeline = gst::parse::launch(
"videotestsrc name=src ! video/x-raw,width=640,height=480 ! compositor0.sink_0 \
compositor ! video/x-raw,width=1280,height=720 ! videoconvert ! autovideosink",
)

229
examples/src/bin/zoom.rs Normal file
View file

@ -0,0 +1,229 @@
// Zoom example using navigation events and a compositor
// Use can change the video player zoom using the next keys:
// * +: Zoom in
// * -: Zoom out
// * Up/Down/Right/Left: Move the frame
// * r: reset the zoom
// Also mouse navigation events can be used for a better UX.
use gst::prelude::*;
use gst_video::video_event::NavigationEvent;
use std::sync::Mutex;
#[path = "../examples-common.rs"]
mod examples_common;
const WIDTH: i32 = 1280;
const HEIGHT: i32 = 720;
#[derive(Default)]
struct MouseState {
clicked: bool,
clicked_x: f64,
clicked_y: f64,
clicked_xpos: i32,
clicked_ypos: i32,
}
fn zoom(mixer_sink_pad: gst::Pad, x: i32, y: i32, zoom_in: bool) {
let xpos = mixer_sink_pad.property::<i32>("xpos");
let ypos = mixer_sink_pad.property::<i32>("ypos");
let width = mixer_sink_pad.property::<i32>("width");
let height = mixer_sink_pad.property::<i32>("height");
let (width_offset, height_offset) = if zoom_in {
(WIDTH / 10, HEIGHT / 10)
} else {
(-WIDTH / 10, -HEIGHT / 10)
};
if width_offset + width <= 0 {
return;
}
mixer_sink_pad.set_property("width", width + width_offset);
mixer_sink_pad.set_property("height", height + height_offset);
let xpos_offset = ((x as f32 / WIDTH as f32) * width_offset as f32) as i32;
let new_xpos = xpos - xpos_offset;
let ypos_offset = ((y as f32 / HEIGHT as f32) * height_offset as f32) as i32;
let new_ypos = ypos - ypos_offset;
if new_xpos != xpos {
mixer_sink_pad.set_property("xpos", new_xpos);
}
if new_ypos != ypos {
mixer_sink_pad.set_property("ypos", new_ypos);
}
}
fn reset_zoom(mixer_sink_pad: gst::Pad) {
let xpos = mixer_sink_pad.property::<i32>("xpos");
let ypos = mixer_sink_pad.property::<i32>("ypos");
let width = mixer_sink_pad.property::<i32>("width");
let height = mixer_sink_pad.property::<i32>("height");
if 0 != xpos {
mixer_sink_pad.set_property("xpos", 0);
}
if 0 != ypos {
mixer_sink_pad.set_property("ypos", 0);
}
if WIDTH != width {
mixer_sink_pad.set_property("width", WIDTH);
}
if HEIGHT != height {
mixer_sink_pad.set_property("height", HEIGHT);
}
}
fn example_main() {
let clicked = Mutex::new(MouseState::default());
gst::init().unwrap();
let pipeline = gst::parse::launch(&format!(
"compositor name=mix background=1 sink_0::xpos=0 sink_0::ypos=0 sink_0::zorder=0 sink_0::width={WIDTH} sink_0::height={HEIGHT} ! xvimagesink \
videotestsrc name=src ! video/x-raw,framerate=30/1,width={WIDTH},height={HEIGHT},pixel-aspect-ratio=1/1 ! queue ! mix.sink_0"
)).unwrap().downcast::<gst::Pipeline>().unwrap();
let mixer = pipeline.by_name("mix").unwrap();
let mixer_src_pad = mixer.static_pad("src").unwrap();
let mixer_sink_pad_weak = mixer.static_pad("sink_0").unwrap().downgrade();
// Probe added in the sink pad to get direct navigation events w/o transformation done by the mixer
mixer_src_pad.add_probe(gst::PadProbeType::EVENT_UPSTREAM, move |_, probe_info| {
let mixer_sink_pad = mixer_sink_pad_weak.upgrade().unwrap();
let Some(ev) = probe_info.event() else {
return gst::PadProbeReturn::Ok;
};
if ev.type_() != gst::EventType::Navigation {
return gst::PadProbeReturn::Ok;
};
let Ok(nav_event) = NavigationEvent::parse(ev) else {
return gst::PadProbeReturn::Ok;
};
match nav_event {
NavigationEvent::KeyPress { key, .. } => match key.as_str() {
"Left" => {
let xpos = mixer_sink_pad.property::<i32>("xpos");
mixer_sink_pad.set_property("xpos", xpos - 10);
}
"Right" => {
let xpos = mixer_sink_pad.property::<i32>("xpos");
mixer_sink_pad.set_property("xpos", xpos + 10);
}
"Up" => {
let ypos = mixer_sink_pad.property::<i32>("ypos");
mixer_sink_pad.set_property("ypos", ypos - 10);
}
"Down" => {
let ypos = mixer_sink_pad.property::<i32>("ypos");
mixer_sink_pad.set_property("ypos", ypos + 10);
}
"plus" => {
zoom(mixer_sink_pad, WIDTH / 2, HEIGHT / 2, true);
}
"minus" => {
zoom(mixer_sink_pad, WIDTH / 2, HEIGHT / 2, false);
}
"r" => {
reset_zoom(mixer_sink_pad);
}
_ => (),
},
NavigationEvent::MouseMove { x, y, .. } => {
let state = clicked.lock().unwrap();
if state.clicked {
let xpos = mixer_sink_pad.property::<i32>("xpos");
let ypos = mixer_sink_pad.property::<i32>("ypos");
let new_xpos = state.clicked_xpos + (x - state.clicked_x) as i32;
let new_ypos = state.clicked_ypos + (y - state.clicked_y) as i32;
if new_xpos != xpos {
mixer_sink_pad.set_property("xpos", new_xpos);
}
if new_ypos != ypos {
mixer_sink_pad.set_property("ypos", new_ypos);
}
}
}
NavigationEvent::MouseButtonPress { button, x, y, .. } => {
if button == 1 || button == 272 {
let mut state = clicked.lock().unwrap();
state.clicked = true;
state.clicked_x = x;
state.clicked_y = y;
state.clicked_xpos = mixer_sink_pad.property("xpos");
state.clicked_ypos = mixer_sink_pad.property("ypos");
} else if button == 2 || button == 3 || button == 274 || button == 273 {
reset_zoom(mixer_sink_pad);
} else if button == 4 {
zoom(mixer_sink_pad, x as i32, y as i32, true);
} else if button == 5 {
zoom(mixer_sink_pad, x as i32, y as i32, false);
}
}
NavigationEvent::MouseButtonRelease { button, .. } => {
if button == 1 || button == 272 {
let mut state = clicked.lock().unwrap();
state.clicked = false;
}
}
#[cfg(feature = "v1_18")]
NavigationEvent::MouseScroll { x, y, delta_y, .. } => {
if delta_y > 0.0 {
zoom(mixer_sink_pad, x as i32, y as i32, true);
} else if delta_y < 0.0 {
zoom(mixer_sink_pad, x as i32, y as i32, false);
}
}
_ => (),
}
gst::PadProbeReturn::Ok
});
pipeline
.set_state(gst::State::Playing)
.expect("Unable to set the pipeline to the `Playing` state");
let bus = pipeline.bus().unwrap();
for msg in bus.iter_timed(gst::ClockTime::NONE) {
use gst::MessageView;
match msg.view() {
MessageView::Eos(..) => {
println!("received eos");
break;
}
MessageView::Error(err) => {
println!(
"Error from {:?}: {} ({:?})",
err.src().map(|s| s.path_string()),
err.error(),
err.debug()
);
break;
}
_ => (),
};
}
pipeline
.set_state(gst::State::Null)
.expect("Unable to set the pipeline to the `Null` state");
}
fn main() {
// tutorials_common::run is only required to set up the application environment on macOS
// (but not necessary in normal Cocoa applications where this is set up automatically)
examples_common::run(example_main);
}

View file

@ -17,13 +17,47 @@ pub fn run<T, F: FnOnce() -> T + Send + 'static>(main: F) -> T
where
T: Send + 'static,
{
use cocoa::appkit::NSApplication;
use std::{
ffi::c_void,
sync::mpsc::{channel, Sender},
thread,
};
use std::thread;
use cocoa::{
appkit::{NSApplication, NSWindow},
base::id,
delegate,
};
use objc::{
class, msg_send,
runtime::{Object, Sel},
sel, sel_impl,
};
unsafe {
let app = cocoa::appkit::NSApp();
let t = thread::spawn(|| {
let (send, recv) = channel::<()>();
extern "C" fn on_finish_launching(this: &Object, _cmd: Sel, _notification: id) {
let send = unsafe {
let send_pointer = *this.get_ivar::<*const c_void>("send");
let boxed = Box::from_raw(send_pointer as *mut Sender<()>);
*boxed
};
send.send(()).unwrap();
}
let delegate = delegate!("AppDelegate", {
app: id = app,
send: *const c_void = Box::into_raw(Box::new(send)) as *const c_void,
(applicationDidFinishLaunching:) => on_finish_launching as extern fn(&Object, Sel, id)
});
app.setDelegate_(delegate);
let t = thread::spawn(move || {
// Wait for the NSApp to launch to avoid possibly calling stop_() too early
recv.recv().unwrap();
let res = main();
let app = cocoa::appkit::NSApp();

View file

@ -1,32 +1,37 @@
// This example demonstrates how to output GL textures, within an
// EGL/X11 context provided by the application, and render those
// textures in the GL application.
//! This example demonstrates how to output GL textures, within an EGL/X11 context provided by the
//! application, and render those textures in the GL application.
//!
//! This example follow common patterns from `glutin`:
//! <https://github.com/rust-windowing/glutin/blob/master/glutin_examples/src/lib.rs>
// {videotestsrc} - { glsinkbin }
use gst::element_error;
use std::{
ffi::{CStr, CString},
mem,
num::NonZeroU32,
ptr,
};
use gst_gl::prelude::*;
use std::ffi::CStr;
use std::mem;
use std::ptr;
use std::sync;
use anyhow::Error;
use anyhow::{Context, Result};
use derive_more::{Display, Error};
use glutin::{
config::GetGlConfig as _,
context::AsRawContext as _,
display::{AsRawDisplay as _, GetGlDisplay as _},
prelude::*,
};
use glutin_winit::GlWindow as _;
use gst::element_error;
use gst_gl::prelude::*;
use raw_window_handle::HasRawWindowHandle as _;
#[derive(Debug, Display, Error)]
#[display(fmt = "Missing element {}", _0)]
struct MissingElement(#[error(not(source))] &'static str);
#[derive(Debug, Display, Error)]
#[display(fmt = "Received error from {}: {} (debug: {:?})", src, error, debug)]
#[display(fmt = "Received error from {src}: {error} (debug: {debug:?})")]
struct ErrorMessage {
src: String,
error: String,
debug: Option<String>,
source: glib::Error,
src: glib::GString,
error: glib::Error,
debug: Option<glib::GString>,
}
#[rustfmt::skip]
@ -181,7 +186,7 @@ impl Gl {
}
}
fn resize(&self, size: glutin::dpi::PhysicalSize<u32>) {
fn resize(&self, size: winit::dpi::PhysicalSize<u32>) {
unsafe {
self.gl
.Viewport(0, 0, size.width as i32, size.height as i32);
@ -189,17 +194,20 @@ impl Gl {
}
}
fn load(gl_context: &glutin::WindowedContext<glutin::PossiblyCurrent>) -> Gl {
let gl = gl::Gl::load_with(|ptr| gl_context.get_proc_address(ptr) as *const _);
fn load(gl_display: &impl glutin::display::GlDisplay) -> Gl {
let gl = gl::Gl::load_with(|symbol| {
let symbol = CString::new(symbol).unwrap();
gl_display.get_proc_address(&symbol).cast()
});
let version = unsafe {
let data = CStr::from_ptr(gl.GetString(gl::VERSION) as *const _)
.to_bytes()
.to_vec();
String::from_utf8(data).unwrap()
let version = gl.GetString(gl::VERSION);
assert!(!version.is_null());
let version = CStr::from_ptr(version.cast());
version.to_string_lossy()
};
println!("OpenGL version {}", version);
println!("OpenGL version {version}");
let (program, attr_position, attr_texture, vao, vertex_buffer, vbo_indices) = unsafe {
let vs = gl.CreateShader(gl::VERTEX_SHADER);
@ -216,9 +224,10 @@ fn load(gl_context: &glutin::WindowedContext<glutin::PossiblyCurrent>) -> Gl {
gl.LinkProgram(program);
{
let mut success: gl::types::GLint = 1;
gl.GetProgramiv(fs, gl::LINK_STATUS, &mut success);
assert!(success != 0);
let mut success = 1;
gl.GetProgramiv(program, gl::LINK_STATUS, &mut success);
assert_ne!(success, 0);
assert_eq!(gl.GetError(), 0);
}
let attr_position = gl.GetAttribLocation(program, b"a_position\0".as_ptr() as *const _);
@ -289,6 +298,8 @@ fn load(gl_context: &glutin::WindowedContext<glutin::PossiblyCurrent>) -> Gl {
gl.BindBuffer(gl::ELEMENT_ARRAY_BUFFER, 0);
gl.BindBuffer(gl::ARRAY_BUFFER, 0);
assert_eq!(gl.GetError(), 0);
(
program,
attr_position,
@ -312,198 +323,256 @@ fn load(gl_context: &glutin::WindowedContext<glutin::PossiblyCurrent>) -> Gl {
#[derive(Debug)]
enum Message {
Sample(gst::Sample),
Frame(gst_video::VideoInfo, gst::Buffer),
BusEvent,
}
pub(crate) struct App {
pipeline: gst::Pipeline,
appsink: gst_app::AppSink,
glupload: gst::Element,
bus: gst::Bus,
event_loop: glutin::event_loop::EventLoop<Message>,
windowed_context: glutin::WindowedContext<glutin::PossiblyCurrent>,
event_loop: winit::event_loop::EventLoop<Message>,
window: Option<winit::window::Window>,
not_current_gl_context: Option<glutin::context::NotCurrentContext>,
shared_context: gst_gl::GLContext,
}
impl App {
pub(crate) fn new(gl_element: Option<&gst::Element>) -> Result<App, Error> {
pub(crate) fn new(gl_element: Option<&gst::Element>) -> Result<App> {
gst::init()?;
let (pipeline, appsink, glupload) = App::create_pipeline(gl_element)?;
let (pipeline, appsink) = App::create_pipeline(gl_element)?;
let bus = pipeline
.bus()
.expect("Pipeline without bus. Shouldn't happen!");
.context("Pipeline without bus. Shouldn't happen!")?;
let event_loop = glutin::event_loop::EventLoop::with_user_event();
let window = glutin::window::WindowBuilder::new().with_title("GL rendering");
let windowed_context = glutin::ContextBuilder::new()
.with_vsync(true)
.build_windowed(window, &event_loop)?;
let event_loop = winit::event_loop::EventLoopBuilder::with_user_event().build()?;
let windowed_context = unsafe { windowed_context.make_current().map_err(|(_, err)| err)? };
// Only Windows requires the window to be present before creating a `glutin::Display`. Other
// platforms don't really need one (and on Android, none exists until `Event::Resumed`).
let window_builder = cfg!(windows).then(|| {
winit::window::WindowBuilder::new()
.with_transparent(true)
.with_title("GL rendering")
});
#[cfg(any(feature = "gst-gl-x11", feature = "gst-gl-wayland"))]
let inner_window = windowed_context.window();
let display_builder =
glutin_winit::DisplayBuilder::new().with_window_builder(window_builder);
// XXX on macOS/cgl only one config can be queried at a time. If transparency is needed,
// add .with_transparency(true) to ConfigTemplateBuilder. EGL on X11 doesn't support
// transparency at all.
let template = glutin::config::ConfigTemplateBuilder::new().with_alpha_size(8);
let (window, gl_config) = display_builder
.build(&event_loop, template, |configs| {
configs
.reduce(|current, new_config| {
let prefer_transparency =
new_config.supports_transparency().unwrap_or(false)
& !current.supports_transparency().unwrap_or(false);
let shared_context: gst_gl::GLContext;
if cfg!(target_os = "linux") {
use glutin::platform::unix::RawHandle;
#[cfg(any(feature = "gst-gl-x11", feature = "gst-gl-wayland"))]
use glutin::platform::unix::WindowExtUnix;
use glutin::platform::ContextTraitExt;
let api = App::map_gl_api(windowed_context.get_api());
let (gl_context, gl_display, platform) = match unsafe { windowed_context.raw_handle() }
{
#[cfg(any(feature = "gst-gl-egl", feature = "gst-gl-wayland"))]
RawHandle::Egl(egl_context) => {
let mut gl_display = None;
#[cfg(feature = "gst-gl-egl")]
if let Some(display) = unsafe { windowed_context.get_egl_display() } {
gl_display = Some(
unsafe { gst_gl_egl::GLDisplayEGL::with_egl_display(display as usize) }
.unwrap()
.upcast::<gst_gl::GLDisplay>(),
)
};
#[cfg(feature = "gst-gl-wayland")]
if let Some(display) = inner_window.wayland_display() {
gl_display = Some(
unsafe {
gst_gl_wayland::GLDisplayWayland::with_display(display as usize)
}
.unwrap()
.upcast::<gst_gl::GLDisplay>(),
)
};
(
egl_context as usize,
gl_display.expect("Could not retrieve GLDisplay through EGL context and/or Wayland display"),
gst_gl::GLPlatform::EGL,
)
}
#[cfg(feature = "gst-gl-x11")]
RawHandle::Glx(glx_context) => {
let gl_display = if let Some(display) = inner_window.xlib_display() {
unsafe { gst_gl_x11::GLDisplayX11::with_display(display as usize) }.unwrap()
} else {
panic!("X11 window without X Display");
};
(
glx_context as usize,
gl_display.upcast::<gst_gl::GLDisplay>(),
gst_gl::GLPlatform::GLX,
)
}
#[allow(unreachable_patterns)]
handler => panic!("Unsupported platform: {:?}.", handler),
};
shared_context =
unsafe { gst_gl::GLContext::new_wrapped(&gl_display, gl_context, platform, api) }
.unwrap();
shared_context
.activate(true)
.expect("Couldn't activate wrapped GL context");
shared_context.fill_info()?;
let gl_context = shared_context.clone();
let event_proxy = sync::Mutex::new(event_loop.create_proxy());
#[allow(clippy::single_match)]
bus.set_sync_handler(move |_, msg| {
match msg.view() {
gst::MessageView::NeedContext(ctxt) => {
let context_type = ctxt.context_type();
if context_type == *gst_gl::GL_DISPLAY_CONTEXT_TYPE {
if let Some(el) =
msg.src().map(|s| s.downcast::<gst::Element>().unwrap())
{
let context = gst::Context::new(context_type, true);
context.set_gl_display(&gl_display);
el.set_context(&context);
}
if prefer_transparency || new_config.num_samples() > current.num_samples() {
new_config
} else {
current
}
if context_type == "gst.gl.app_context" {
if let Some(el) =
msg.src().map(|s| s.downcast::<gst::Element>().unwrap())
{
let mut context = gst::Context::new(context_type, true);
{
let context = context.get_mut().unwrap();
let s = context.structure_mut();
s.set("context", &gl_context);
}
el.set_context(&context);
}
})
.unwrap()
})
.expect("Failed to build display");
println!(
"Picked a config with {} samples and transparency {}. Pixel format: {:?}",
gl_config.num_samples(),
gl_config.supports_transparency().unwrap_or(false),
gl_config.color_buffer_type()
);
println!("Config supports GL API(s) {:?}", gl_config.api());
// XXX The display could be obtained from any object created by it, so we can query it from
// the config.
let gl_display = gl_config.display();
let raw_gl_display = gl_display.raw_display();
println!("Using raw display connection {:?}", raw_gl_display);
let raw_window_handle = window.as_ref().map(|window| window.raw_window_handle());
// The context creation part. It can be created before surface and that's how
// it's expected in multithreaded + multiwindow operation mode, since you
// can send NotCurrentContext, but not Surface.
let context_attributes =
glutin::context::ContextAttributesBuilder::new().build(raw_window_handle);
// Since glutin by default tries to create OpenGL core context, which may not be
// present we should try gles.
let fallback_context_attributes = glutin::context::ContextAttributesBuilder::new()
.with_context_api(glutin::context::ContextApi::Gles(None))
.build(raw_window_handle);
// There are also some old devices that support neither modern OpenGL nor GLES.
// To support these we can try and create a 2.1 context.
let legacy_context_attributes = glutin::context::ContextAttributesBuilder::new()
.with_context_api(glutin::context::ContextApi::OpenGl(Some(
glutin::context::Version::new(2, 1),
)))
.build(raw_window_handle);
let not_current_gl_context = unsafe {
gl_display
.create_context(&gl_config, &context_attributes)
.or_else(|_| {
gl_display
.create_context(&gl_config, &fallback_context_attributes)
.or_else(|_| {
gl_display.create_context(&gl_config, &legacy_context_attributes)
})
})
}
.context("failed to create context")?;
let raw_gl_context = not_current_gl_context.raw_context();
println!("Using raw GL context {:?}", raw_gl_context);
#[cfg(not(target_os = "linux"))]
compile_error!("This example only has Linux support");
let api = App::map_gl_api(gl_config.api());
let (raw_gl_context, gst_gl_display, platform) = match (raw_gl_display, raw_gl_context) {
#[cfg(feature = "gst-gl-egl")]
(
glutin::display::RawDisplay::Egl(egl_display),
glutin::context::RawContext::Egl(egl_context),
) => {
let gl_display =
unsafe { gst_gl_egl::GLDisplayEGL::with_egl_display(egl_display as usize) }
.context("Failed to create GLDisplayEGL from raw `EGLDisplay`")?
.upcast::<gst_gl::GLDisplay>();
(egl_context as usize, gl_display, gst_gl::GLPlatform::EGL)
}
#[cfg(feature = "gst-gl-x11")]
(
glutin::display::RawDisplay::Glx(glx_display),
glutin::context::RawContext::Glx(glx_context),
) => {
let gl_display =
unsafe { gst_gl_x11::GLDisplayX11::with_display(glx_display as usize) }
.context("Failed to create GLDisplayX11 from raw X11 `Display`")?
.upcast::<gst_gl::GLDisplay>();
(glx_context as usize, gl_display, gst_gl::GLPlatform::GLX)
}
#[allow(unreachable_patterns)]
handler => anyhow::bail!("Unsupported platform: {handler:?}."),
};
let shared_context = unsafe {
gst_gl::GLContext::new_wrapped(&gst_gl_display, raw_gl_context, platform, api)
}
.context("Couldn't wrap GL context")?;
let gl_context = shared_context.clone();
let event_proxy = event_loop.create_proxy();
#[allow(clippy::single_match)]
bus.set_sync_handler(move |_, msg| {
match msg.view() {
gst::MessageView::NeedContext(ctxt) => {
let context_type = ctxt.context_type();
if context_type == *gst_gl::GL_DISPLAY_CONTEXT_TYPE {
if let Some(el) =
msg.src().map(|s| s.downcast_ref::<gst::Element>().unwrap())
{
let context = gst::Context::new(context_type, true);
context.set_gl_display(&gst_gl_display);
el.set_context(&context);
}
}
if context_type == "gst.gl.app_context" {
if let Some(el) =
msg.src().map(|s| s.downcast_ref::<gst::Element>().unwrap())
{
let mut context = gst::Context::new(context_type, true);
{
let context = context.get_mut().unwrap();
let s = context.structure_mut();
s.set("context", &gl_context);
}
el.set_context(&context);
}
}
_ => (),
}
_ => (),
}
if let Err(e) = event_proxy.lock().unwrap().send_event(Message::BusEvent) {
eprintln!("Failed to send BusEvent to event proxy: {}", e)
}
if let Err(e) = event_proxy.send_event(Message::BusEvent) {
eprintln!("Failed to send BusEvent to event proxy: {e}")
}
gst::BusSyncReply::Pass
});
} else {
panic!("This example only has Linux support");
}
gst::BusSyncReply::Pass
});
Ok(App {
pipeline,
appsink,
glupload,
bus,
event_loop,
windowed_context,
window,
not_current_gl_context: Some(not_current_gl_context),
shared_context,
})
}
fn setup(&self, event_loop: &glutin::event_loop::EventLoop<Message>) -> Result<(), Error> {
fn setup(&self, event_loop: &winit::event_loop::EventLoop<Message>) -> Result<()> {
let event_proxy = event_loop.create_proxy();
self.appsink.set_callbacks(
gst_app::AppSinkCallbacks::builder()
.new_sample(move |appsink| {
let sample = appsink.pull_sample().map_err(|_| gst::FlowError::Eos)?;
{
let _buffer = sample.buffer().ok_or_else(|| {
let info = sample
.caps()
.and_then(|caps| gst_video::VideoInfo::from_caps(caps).ok())
.ok_or_else(|| {
element_error!(
appsink,
gst::ResourceError::Failed,
("Failed to get buffer from appsink")
("Failed to get video info from sample")
);
gst::FlowError::Error
gst::FlowError::NotNegotiated
})?;
let _info = sample
.caps()
.and_then(|caps| gst_video::VideoInfo::from_caps(caps).ok())
.ok_or_else(|| {
let mut buffer = sample.buffer_owned().unwrap();
{
let context = match (buffer.n_memory() > 0)
.then(|| buffer.peek_memory(0))
.and_then(|m| m.downcast_memory_ref::<gst_gl::GLBaseMemory>())
.map(|m| m.context())
{
Some(context) => context.clone(),
None => {
element_error!(
appsink,
gst::ResourceError::Failed,
("Failed to get video info from sample")
("Failed to get GL context from buffer")
);
gst::FlowError::Error
})?;
return Err(gst::FlowError::Error);
}
};
if let Some(meta) = buffer.meta::<gst_gl::GLSyncMeta>() {
meta.set_sync_point(&context);
} else {
let buffer = buffer.make_mut();
let meta = gst_gl::GLSyncMeta::add(buffer, &context);
meta.set_sync_point(&context);
}
}
event_proxy
.send_event(Message::Sample(sample))
.send_event(Message::Frame(info, buffer))
.map(|()| gst::FlowSuccess::Ok)
.map_err(|e| {
element_error!(
@ -518,47 +587,52 @@ impl App {
.build(),
);
self.pipeline.set_state(gst::State::Playing)?;
Ok(())
}
fn map_gl_api(api: glutin::Api) -> gst_gl::GLAPI {
match api {
glutin::Api::OpenGl => gst_gl::GLAPI::OPENGL3,
glutin::Api::OpenGlEs => gst_gl::GLAPI::GLES2,
_ => gst_gl::GLAPI::empty(),
}
/// Converts from <https://docs.rs/glutin/latest/glutin/config/struct.Api.html> to
/// <https://gstreamer.freedesktop.org/documentation/gl/gstglapi.html?gi-language=c#GstGLAPI>.
fn map_gl_api(api: glutin::config::Api) -> gst_gl::GLAPI {
use glutin::config::Api;
use gst_gl::GLAPI;
let mut gst_gl_api = GLAPI::empty();
// In gstreamer:
// GLAPI::OPENGL: Desktop OpenGL up to and including 3.1. The compatibility profile when the OpenGL version is >= 3.2
// GLAPI::OPENGL3: Desktop OpenGL >= 3.2 core profile
// In glutin, API::OPENGL is set for every context API, except EGL where it is set based on
// EGL_RENDERABLE_TYPE containing EGL_OPENGL_BIT:
// https://registry.khronos.org/EGL/sdk/docs/man/html/eglChooseConfig.xhtml
gst_gl_api.set(GLAPI::OPENGL | GLAPI::OPENGL3, api.contains(Api::OPENGL));
gst_gl_api.set(GLAPI::GLES1, api.contains(Api::GLES1));
// OpenGL ES 2.x and 3.x
gst_gl_api.set(GLAPI::GLES2, api.intersects(Api::GLES2 | Api::GLES3));
gst_gl_api
}
fn create_pipeline(
gl_element: Option<&gst::Element>,
) -> Result<(gst::Pipeline, gst_app::AppSink, gst::Element), Error> {
let pipeline = gst::Pipeline::new(None);
let src = gst::ElementFactory::make("videotestsrc", None)
.map_err(|_| MissingElement("videotestsrc"))?;
) -> Result<(gst::Pipeline, gst_app::AppSink)> {
let pipeline = gst::Pipeline::default();
let src = gst::ElementFactory::make("videotestsrc").build()?;
let appsink = gst::ElementFactory::make("appsink", None)
.map_err(|_| MissingElement("appsink"))?
.dynamic_cast::<gst_app::AppSink>()
.expect("Sink element is expected to be an appsink!");
appsink.set_property("enable-last-sample", false);
appsink.set_property("emit-signals", false);
appsink.set_property("max-buffers", 1u32);
let caps = gst::Caps::builder("video/x-raw")
.features(&[&gst_gl::CAPS_FEATURE_MEMORY_GL_MEMORY])
.field("format", gst_video::VideoFormat::Rgba.to_str())
let caps = gst_video::VideoCapsBuilder::new()
.features([gst_gl::CAPS_FEATURE_MEMORY_GL_MEMORY])
.format(gst_video::VideoFormat::Rgba)
.field("texture-target", "2D")
.build();
appsink.set_caps(Some(&caps));
let appsink = gst_app::AppSink::builder()
.enable_last_sample(true)
.max_buffers(1)
.caps(&caps)
.build();
if let Some(gl_element) = gl_element {
let glupload = gst::ElementFactory::make("glupload", None)
.map_err(|_| MissingElement("glupload"))?;
let glupload = gst::ElementFactory::make("glupload").build()?;
pipeline.add_many(&[&src, &glupload])?;
pipeline.add_many([&src, &glupload])?;
pipeline.add(gl_element)?;
pipeline.add(&appsink)?;
@ -566,35 +640,20 @@ impl App {
glupload.link(gl_element)?;
gl_element.link(&appsink)?;
Ok((pipeline, appsink, glupload))
Ok((pipeline, appsink))
} else {
let sink = gst::ElementFactory::make("glsinkbin", None)
.map_err(|_| MissingElement("glsinkbin"))?;
let sink = gst::ElementFactory::make("glsinkbin")
.property("sink", &appsink)
.build()?;
sink.set_property("sink", &appsink);
pipeline.add_many(&[&src, &sink])?;
pipeline.add_many([&src, &sink])?;
src.link(&sink)?;
// get the glupload element to extract later the used context in it
let mut iter = sink.dynamic_cast::<gst::Bin>().unwrap().iterate_elements();
let glupload = loop {
match iter.next() {
Ok(Some(element)) => {
if "glupload" == element.factory().unwrap().name() {
break Some(element);
}
}
Err(gst::IteratorError::Resync) => iter.resync(),
_ => break None,
}
};
Ok((pipeline, appsink, glupload.unwrap()))
Ok((pipeline, appsink))
}
}
fn handle_messages(bus: &gst::Bus) -> Result<(), Error> {
fn handle_messages(bus: &gst::Bus) -> Result<()> {
use gst::MessageView;
for msg in bus.iter() {
@ -604,11 +663,10 @@ impl App {
return Err(ErrorMessage {
src: msg
.src()
.map(|s| String::from(s.path_string()))
.unwrap_or_else(|| String::from("None")),
error: err.error().to_string(),
.map(|s| s.path_string())
.unwrap_or_else(|| glib::GString::from("UNKNOWN")),
error: err.error(),
debug: err.debug(),
source: err.error(),
}
.into());
}
@ -620,94 +678,143 @@ impl App {
}
}
pub(crate) fn main_loop(app: App) -> Result<(), Error> {
pub(crate) fn main_loop(app: App) -> Result<()> {
app.setup(&app.event_loop)?;
println!(
"Pixel format of the window's GL context {:?}",
app.windowed_context.get_pixel_format()
);
let gl = load(&app.windowed_context);
let mut curr_frame: Option<gst_video::VideoFrame<gst_video::video_frame::Readable>> = None;
let mut gst_gl_context: Option<gst_gl::GLContext> = None;
let App {
pipeline,
bus,
event_loop,
glupload,
pipeline,
mut window,
mut not_current_gl_context,
shared_context,
windowed_context,
..
} = app;
event_loop.run(move |event, _, cf| {
*cf = glutin::event_loop::ControlFlow::Wait;
let mut curr_frame: Option<gst_gl::GLVideoFrame<gst_gl::gl_video_frame::Readable>> = None;
let mut running_state = None::<(
Gl,
glutin::context::PossiblyCurrentContext,
glutin::surface::Surface<glutin::surface::WindowSurface>,
)>;
Ok(event_loop.run(move |event, window_target| {
window_target.set_control_flow(winit::event_loop::ControlFlow::Wait);
let mut needs_redraw = false;
match event {
glutin::event::Event::LoopDestroyed => {
winit::event::Event::LoopExiting => {
pipeline.send_event(gst::event::Eos::new());
pipeline.set_state(gst::State::Null).unwrap();
}
glutin::event::Event::WindowEvent { event, .. } => match event {
glutin::event::WindowEvent::CloseRequested
| glutin::event::WindowEvent::KeyboardInput {
input:
glutin::event::KeyboardInput {
state: glutin::event::ElementState::Released,
virtual_keycode: Some(glutin::event::VirtualKeyCode::Escape),
winit::event::Event::WindowEvent { event, .. } => match event {
winit::event::WindowEvent::CloseRequested
| winit::event::WindowEvent::KeyboardInput {
event:
winit::event::KeyEvent {
state: winit::event::ElementState::Released,
logical_key:
winit::keyboard::Key::Named(winit::keyboard::NamedKey::Escape),
..
},
..
} => *cf = glutin::event_loop::ControlFlow::Exit,
glutin::event::WindowEvent::Resized(physical_size) => {
windowed_context.resize(physical_size);
gl.resize(physical_size);
} => window_target.exit(),
winit::event::WindowEvent::Resized(size) => {
// Some platforms like EGL require resizing GL surface to update the size
// Notable platforms here are Wayland and macOS, other don't require it
// and the function is no-op, but it's wise to resize it for portability
// reasons.
if let Some((gl, gl_context, gl_surface)) = &running_state {
gl_surface.resize(
gl_context,
// XXX Ignore minimizing
NonZeroU32::new(size.width).unwrap(),
NonZeroU32::new(size.height).unwrap(),
);
gl.resize(size);
}
}
winit::event::WindowEvent::RedrawRequested => needs_redraw = true,
_ => (),
},
glutin::event::Event::RedrawRequested(_) => needs_redraw = true,
// Receive a frame
glutin::event::Event::UserEvent(Message::Sample(sample)) => {
let buffer = sample.buffer_owned().unwrap();
let info = sample
.caps()
.and_then(|caps| gst_video::VideoInfo::from_caps(caps).ok())
.unwrap();
{
if gst_gl_context.is_none() {
gst_gl_context = glupload.property::<Option<gst_gl::GLContext>>("context");
}
let sync_meta = buffer.meta::<gst_gl::GLSyncMeta>().unwrap();
sync_meta.set_sync_point(gst_gl_context.as_ref().unwrap());
}
if let Ok(frame) = gst_video::VideoFrame::from_buffer_readable_gl(buffer, &info) {
winit::event::Event::UserEvent(Message::Frame(info, buffer)) => {
if let Ok(frame) = gst_gl::GLVideoFrame::from_buffer_readable(buffer, &info) {
curr_frame = Some(frame);
needs_redraw = true;
}
}
// Handle all pending messages when we are awaken by set_sync_handler
glutin::event::Event::UserEvent(Message::BusEvent) => {
winit::event::Event::UserEvent(Message::BusEvent) => {
App::handle_messages(&bus).unwrap();
}
winit::event::Event::Resumed => {
let not_current_gl_context = not_current_gl_context
.take()
.expect("There must be a NotCurrentContext prior to Event::Resumed");
let gl_config = not_current_gl_context.config();
let gl_display = gl_config.display();
let window = window.get_or_insert_with(|| {
let window_builder = winit::window::WindowBuilder::new().with_transparent(true);
glutin_winit::finalize_window(window_target, window_builder, &gl_config)
.unwrap()
});
let attrs = window.build_surface_attributes(<_>::default());
let gl_surface = unsafe {
gl_config
.display()
.create_window_surface(&gl_config, &attrs)
.unwrap()
};
// Make it current.
let gl_context = not_current_gl_context.make_current(&gl_surface).unwrap();
// Tell GStreamer that the context has been made current (for borrowed contexts,
// this does not try to make it current again)
shared_context.activate(true).unwrap();
shared_context
.fill_info()
.expect("Couldn't fill context info");
// The context needs to be current for the Renderer to set up shaders and buffers.
// It also performs function loading, which needs a current context on WGL.
let gl = load(&gl_display);
// Try setting vsync.
if let Err(res) = gl_surface.set_swap_interval(
&gl_context,
glutin::surface::SwapInterval::Wait(std::num::NonZeroU32::new(1).unwrap()),
) {
eprintln!("Error setting vsync: {res:?}");
}
pipeline.set_state(gst::State::Playing).unwrap();
assert!(running_state
.replace((gl, gl_context, gl_surface))
.is_none());
}
_ => (),
}
if needs_redraw {
if let Some(frame) = curr_frame.as_ref() {
let sync_meta = frame.buffer().meta::<gst_gl::GLSyncMeta>().unwrap();
sync_meta.wait(&shared_context);
if let Some(texture) = frame.texture_id(0) {
gl.draw_frame(texture as gl::types::GLuint);
if let Some((gl, gl_context, gl_surface)) = &running_state {
if let Some(frame) = curr_frame.as_ref() {
let sync_meta = frame.buffer().meta::<gst_gl::GLSyncMeta>().unwrap();
sync_meta.wait(&shared_context);
if let Ok(texture) = frame.texture_id(0) {
gl.draw_frame(texture as gl::types::GLuint);
}
}
gl_surface.swap_buffers(gl_context).unwrap();
}
windowed_context.swap_buffers().unwrap();
}
})
})?)
}

2
gir

@ -1 +1 @@
Subproject commit ee37253c10af159268f76cc9852d2d2a3c09ecc0
Subproject commit 5223ce91b97a833b09d6cbd04bbeab1bf18112b7

@ -1 +1 @@
Subproject commit 5502d32880f5b02b8bd124b9df58826ecbd540d0
Subproject commit 6cd7b656acd61172ab7f125a7059e4d0ecfc9637

@ -1 +1 @@
Subproject commit f05404723520e67ad2e0054b45ce245438c88473
Subproject commit c988e03b5e99349efb8ffb6f502879ad4ddbc248

View file

@ -0,0 +1 @@
../gstreamer/CHANGELOG.md

View file

@ -0,0 +1 @@
../COPYRIGHT

View file

@ -0,0 +1,38 @@
[package]
name = "gstreamer-allocators"
authors = ["Sebastian Dröge <sebastian@centricular.com>"]
description = "Rust bindings for GStreamer Allocators library"
license = "MIT OR Apache-2.0"
readme = "README.md"
documentation = "https://gstreamer.pages.freedesktop.org/gstreamer-rs/stable/latest/docs/gstreamer_allocators/"
keywords = ["gstreamer", "multimedia", "audio", "video", "gnome"]
version.workspace = true
categories.workspace = true
repository.workspace = true
homepage.workspace = true
edition.workspace = true
rust-version.workspace = true
[dependencies]
libc = "0.2"
ffi = { package = "gstreamer-allocators-sys", path = "sys" }
glib.workspace = true
gst.workspace = true
once_cell = "1"
[dev-dependencies]
gir-format-check = "0.1"
[features]
default = []
v1_16 = ["gst/v1_16", "ffi/v1_16"]
v1_18 = ["gst/v1_18", "ffi/v1_18", "v1_16"]
v1_20 = ["gst/v1_20", "ffi/v1_20", "v1_18"]
v1_22 = ["gst/v1_22", "ffi/v1_22", "v1_20"]
v1_24 = ["gst/v1_24", "ffi/v1_24", "v1_22"]
v1_26 = ["gst/v1_26", "ffi/v1_26", "v1_24"]
[package.metadata.docs.rs]
all-features = true
rustc-args = ["--cfg", "docsrs"]
rustdoc-args = ["--cfg", "docsrs", "--generate-link-to-definition"]

View file

@ -0,0 +1,108 @@
[options]
concurrency = "send+sync"
generate_display_trait = false
generate_safety_asserts = true
girs_directories = ["../gir-files", "../gst-gir-files"]
library = "GstAllocators"
min_cfg_version = "1.14"
single_version_file = true
trust_return_value_nullability = true
version = "1.0"
work_mode = "normal"
external_libraries = [
"GLib",
"GObject",
"Gst",
]
generate = [
"GstAllocators.FdMemoryFlags",
"GstAllocators.PhysMemoryAllocator",
]
manual = [
"Gst.Allocator",
"Gst.Memory",
]
[[object]]
name = "Gst.Buffer"
ref_mode = "ref"
status = "manual"
[[object]]
name = "GstAllocators.*"
status = "generate"
[[object.function]]
name = "dmabuf_memory_get_fd"
manual = true
[[object.function]]
name = "fd_memory_get_fd"
manual = true
[[object.function]]
name = "is_dmabuf_memory"
manual = true
[[object.function]]
name = "is_fd_memory"
manual = true
[[object.function]]
name = "is_phys_memory"
manual = true
[[object.function]]
name = "phys_memory_get_phys_addr"
manual = true
[[object.function]]
name = "is_drm_dumb_memory"
manual = true
[[object.function]]
name = "drm_dumb_memory_get_handle"
manual = true
[[object.function]]
name = "drm_dumb_memory_export_dmabuf"
manual = true
[[object]]
name = "GstAllocators.DmaBufAllocator"
status = "generate"
cfg_condition = "target_os = \"linux\""
[[object.function]]
name = "alloc"
manual = true
[[object.function]]
name = "alloc_with_flags"
manual = true
[[object]]
name = "GstAllocators.DRMDumbAllocator"
status = "generate"
cfg_condition = "target_os = \"linux\""
[[object.function]]
name = "alloc"
manual = true
[[object.function]]
name = "new_with_fd"
manual = true
[[object.function]]
name = "new_with_device_path"
[object.function.return]
nullable_return_is_error = "Failed to create allocator"
[[object]]
name = "GstAllocators.FdAllocator"
status = "generate"
[[object.function]]
name = "alloc"
manual = true
[[object]]
name = "GstAllocators.ShmAllocator"
status = "generate"
cfg_condition = "unix"
[[object.function]]
name = "get"
manual = true
[[object.function]]
name = "init_once"
manual = true

View file

@ -0,0 +1 @@
../LICENSE-APACHE

View file

@ -0,0 +1 @@
../LICENSE-MIT

View file

@ -0,0 +1,214 @@
# gstreamer-rs [![crates.io](https://img.shields.io/crates/v/gstreamer-allocators.svg)](https://crates.io/crates/gstreamer-allocators) [![pipeline status](https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/badges/main/pipeline.svg)](https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/commits/main)
[GStreamer](https://gstreamer.freedesktop.org/) (Allocators library) bindings for Rust.
Documentation can be found [here](https://gstreamer.pages.freedesktop.org/gstreamer-rs/stable/latest/docs/gstreamer_allocators/).
These bindings are providing a safe API that can be used to interface with
GStreamer, e.g. for writing GStreamer-based applications and GStreamer plugins.
The bindings are mostly autogenerated with [gir](https://github.com/gtk-rs/gir/)
based on the [GObject-Introspection](https://wiki.gnome.org/Projects/GObjectIntrospection/)
API metadata provided by the GStreamer project.
## Table of Contents
1. [Installation](#installation)
1. [Linux/BSDs](#installation-linux)
1. [macOS](#installation-macos)
1. [Windows](#installation-windows)
1. [Getting Started](#getting-started)
1. [License](#license)
1. [Contribution](#contribution)
<a name="installation"/>
## Installation
To build the GStreamer bindings or anything depending on them, you need to
have at least GStreamer 1.14 and gst-plugins-base 1.14 installed. In addition,
some of the examples/tutorials require various GStreamer plugins to be
available, which can be found in gst-plugins-base, gst-plugins-good,
gst-plugins-bad, gst-plugins-ugly and/or gst-libav.
<a name="installation-linux"/>
### Linux/BSDs
You need to install the above mentioned packages with your distributions
package manager, or build them from source.
On Debian/Ubuntu they can be installed with
```console
$ apt-get install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev \
gstreamer1.0-plugins-base gstreamer1.0-plugins-good \
gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly \
gstreamer1.0-libav libgstrtspserver-1.0-dev libges-1.0-dev
```
The minimum required version of the above libraries is >= 1.14. If you
build the gstreamer-player sub-crate, or any of the examples that
depend on gstreamer-player, you must ensure that in addition to the above
packages, `libgstreamer-plugins-bad1.0-dev` is installed. See the `Cargo.toml`
files for the full details,
```console
$ apt-get install libgstreamer-plugins-bad1.0-dev
```
Package names on other distributions should be similar.
Please submit a pull request with instructions for yours.
<a name="installation-macos"/>
### macOS
You can install GStreamer and the plugins via [Homebrew](https://brew.sh/) or
by installing the [binaries](https://gstreamer.freedesktop.org/data/pkg/osx/)
provided by the GStreamer project.
We recommend using the official GStreamer binaries over Homebrew, especially
as GStreamer in Homebrew is [currently broken](https://github.com/orgs/Homebrew/discussions/3740#discussioncomment-3804964).
#### GStreamer Binaries
You need to download the *two* `.pkg` files from the GStreamer website and
install them, e.g. `gstreamer-1.0-1.20.4-universal.pkg` and
`gstreamer-1.0-devel-1.20.4-universal.pkg`.
After installation, you also need to set the `PATH` environment variable as
follows
```console
$ export PATH="/Library/Frameworks/GStreamer.framework/Versions/1.0/bin${PATH:+:$PATH}"
```
Also note that the `pkg-config` from GStreamer should be the first one in
the `PATH` as other versions have all kinds of quirks that will cause
problems.
#### Homebrew
Homebrew only installs various plugins if explicitly enabled, so some extra
`--with-*` flags may be required.
```console
$ brew install gstreamer gst-plugins-base gst-plugins-good \
gst-plugins-bad gst-plugins-ugly gst-libav gst-rtsp-server \
gst-editing-services --with-orc --with-libogg --with-opus \
--with-pango --with-theora --with-libvorbis --with-libvpx \
--enable-gtk3
```
Make sure the version of these libraries is >= 1.14.
<a name="installation-windows"/>
### Windows
You can install GStreamer and the plugins via [MSYS2](http://www.msys2.org/)
with `pacman` or by installing the
[binaries](https://gstreamer.freedesktop.org/data/pkg/windows/) provided by
the GStreamer project.
We recommend using the official GStreamer binaries over MSYS2.
#### GStreamer Binaries
You need to download the *two* `.msi` files for your platform from the
GStreamer website and install them, e.g. `gstreamer-1.0-x86_64-1.20.4.msi` and
`gstreamer-1.0-devel-x86_64-1.20.4.msi`. Make sure to select the version that
matches your Rust toolchain, i.e. MinGW or MSVC.
After installation set the ``PATH` environment variable as follows:
```console
# For a UNIX-style shell:
$ export PATH="c:/gstreamer/1.0/msvc_x86_64/bin${PATH:+:$PATH}"
# For cmd.exe:
$ set PATH=C:\gstreamer\1.0\msvc_x86_64\bin;%PATH%
```
Make sure to update the path to where you have actually installed GStreamer
and for the corresponding toolchain.
Also note that the `pkg-config.exe` from GStreamer should be the first one in
the `PATH` as other versions have all kinds of quirks that will cause
problems.
#### MSYS2 / pacman
```console
$ pacman -S glib2-devel pkg-config \
mingw-w64-x86_64-gstreamer mingw-w64-x86_64-gst-plugins-base \
mingw-w64-x86_64-gst-plugins-good mingw-w64-x86_64-gst-plugins-bad \
mingw-w64-x86_64-gst-plugins-ugly mingw-w64-x86_64-gst-libav \
mingw-w64-x86_64-gst-rtsp-server
```
Make sure the version of these libraries is >= 1.14.
Note that the version of `pkg-config` included in `MSYS2` is
[known to have problems](https://github.com/rust-lang/pkg-config-rs/issues/51#issuecomment-346300858)
compiling GStreamer, so you may need to install another version. One option
would be [`pkg-config-lite`](https://sourceforge.net/projects/pkgconfiglite/).
<a name="getting-started"/>
## Getting Started
The API reference can be found
[here](https://gstreamer.pages.freedesktop.org/gstreamer-rs/stable/latest/docs/gstreamer/), however it is
only the Rust API reference and does not explain any of the concepts.
For getting started with GStreamer development, the best would be to follow
the [documentation](https://gstreamer.freedesktop.org/documentation/) on the
GStreamer website, especially the [Application Development
Manual](https://gstreamer.freedesktop.org/documentation/application-development/).
While being C-centric, it explains all the fundamental concepts of GStreamer
and the code examples should be relatively easily translatable to Rust. The
API is basically the same, function/struct names are the same and everything
is only more convenient (hopefully) and safer.
In addition there are
[tutorials](https://gstreamer.freedesktop.org/documentation/tutorials/) on the
GStreamer website. Many of them were ported to Rust already and the code can
be found in the
[tutorials](https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/tree/main/tutorials)
directory.
Some further examples for various aspects of GStreamer and how to use it from
Rust can be found in the
[examples](https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/tree/main/examples)
directory.
Various GStreamer plugins written in Rust can be found in the
[gst-plugins-rs](https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs)
repository.
<a name="license"/>
## LICENSE
gstreamer-rs and all crates contained in here are licensed under either of
* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
http://www.apache.org/licenses/LICENSE-2.0)
* MIT license ([LICENSE-MIT](LICENSE-MIT) or
http://opensource.org/licenses/MIT)
at your option.
GStreamer itself is licensed under the Lesser General Public License version
2.1 or (at your option) any later version:
https://www.gnu.org/licenses/lgpl-2.1.html
<a name="contribution"/>
## Contribution
Any kinds of contributions are welcome as a pull request.
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in gstreamer-rs by you, as defined in the Apache-2.0 license, shall be
dual licensed as above, without any additional terms or conditions.

View file

@ -0,0 +1,21 @@
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// from gst-gir-files (https://gitlab.freedesktop.org/gstreamer/gir-files-rs.git)
// DO NOT EDIT
use glib::GStr;
#[doc(alias = "GST_ALLOCATOR_DMABUF")]
pub static ALLOCATOR_DMABUF: &GStr =
unsafe { GStr::from_utf8_with_nul_unchecked(ffi::GST_ALLOCATOR_DMABUF) };
#[doc(alias = "GST_ALLOCATOR_FD")]
pub static ALLOCATOR_FD: &GStr =
unsafe { GStr::from_utf8_with_nul_unchecked(ffi::GST_ALLOCATOR_FD) };
#[cfg(feature = "v1_24")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
#[doc(alias = "GST_ALLOCATOR_SHM")]
pub static ALLOCATOR_SHM: &GStr =
unsafe { GStr::from_utf8_with_nul_unchecked(ffi::GST_ALLOCATOR_SHM) };
#[doc(alias = "GST_CAPS_FEATURE_MEMORY_DMABUF")]
pub static CAPS_FEATURE_MEMORY_DMABUF: &GStr =
unsafe { GStr::from_utf8_with_nul_unchecked(ffi::GST_CAPS_FEATURE_MEMORY_DMABUF) };

View file

@ -0,0 +1,35 @@
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// from gst-gir-files (https://gitlab.freedesktop.org/gstreamer/gir-files-rs.git)
// DO NOT EDIT
use crate::FdAllocator;
use glib::{prelude::*, translate::*};
glib::wrapper! {
#[doc(alias = "GstDmaBufAllocator")]
pub struct DmaBufAllocator(Object<ffi::GstDmaBufAllocator, ffi::GstDmaBufAllocatorClass>) @extends FdAllocator, gst::Allocator;
match fn {
type_ => || ffi::gst_dmabuf_allocator_get_type(),
}
}
impl DmaBufAllocator {
pub const NONE: Option<&'static DmaBufAllocator> = None;
#[doc(alias = "gst_dmabuf_allocator_new")]
pub fn new() -> DmaBufAllocator {
assert_initialized_main_thread!();
unsafe { gst::Allocator::from_glib_full(ffi::gst_dmabuf_allocator_new()).unsafe_cast() }
}
}
impl Default for DmaBufAllocator {
fn default() -> Self {
Self::new()
}
}
unsafe impl Send for DmaBufAllocator {}
unsafe impl Sync for DmaBufAllocator {}

View file

@ -0,0 +1,60 @@
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// from gst-gir-files (https://gitlab.freedesktop.org/gstreamer/gir-files-rs.git)
// DO NOT EDIT
use glib::{prelude::*, translate::*};
glib::wrapper! {
#[doc(alias = "GstDRMDumbAllocator")]
pub struct DRMDumbAllocator(Object<ffi::GstDRMDumbAllocator, ffi::GstDRMDumbAllocatorClass>) @extends gst::Allocator;
match fn {
type_ => || ffi::gst_drm_dumb_allocator_get_type(),
}
}
impl DRMDumbAllocator {
#[doc(alias = "gst_drm_dumb_allocator_new_with_device_path")]
#[doc(alias = "new_with_device_path")]
pub fn with_device_path(
drm_device_path: impl AsRef<std::path::Path>,
) -> Result<DRMDumbAllocator, glib::BoolError> {
assert_initialized_main_thread!();
unsafe {
Option::<gst::Allocator>::from_glib_full(
ffi::gst_drm_dumb_allocator_new_with_device_path(
drm_device_path.as_ref().to_glib_none().0,
),
)
.map(|o| o.unsafe_cast())
.ok_or_else(|| glib::bool_error!("Failed to create allocator"))
}
}
#[doc(alias = "gst_drm_dumb_allocator_has_prime_export")]
pub fn has_prime_export(&self) -> bool {
unsafe {
from_glib(ffi::gst_drm_dumb_allocator_has_prime_export(
self.to_glib_none().0,
))
}
}
#[cfg(feature = "v1_24")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
#[doc(alias = "drm-device-path")]
pub fn drm_device_path(&self) -> Option<std::path::PathBuf> {
ObjectExt::property(self, "drm-device-path")
}
#[cfg(feature = "v1_24")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
#[doc(alias = "drm-fd")]
pub fn drm_fd(&self) -> i32 {
ObjectExt::property(self, "drm-fd")
}
}
unsafe impl Send for DRMDumbAllocator {}
unsafe impl Sync for DRMDumbAllocator {}

View file

@ -0,0 +1,34 @@
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// from gst-gir-files (https://gitlab.freedesktop.org/gstreamer/gir-files-rs.git)
// DO NOT EDIT
use glib::{prelude::*, translate::*};
glib::wrapper! {
#[doc(alias = "GstFdAllocator")]
pub struct FdAllocator(Object<ffi::GstFdAllocator, ffi::GstFdAllocatorClass>) @extends gst::Allocator;
match fn {
type_ => || ffi::gst_fd_allocator_get_type(),
}
}
impl FdAllocator {
pub const NONE: Option<&'static FdAllocator> = None;
#[doc(alias = "gst_fd_allocator_new")]
pub fn new() -> FdAllocator {
assert_initialized_main_thread!();
unsafe { gst::Allocator::from_glib_full(ffi::gst_fd_allocator_new()).unsafe_cast() }
}
}
impl Default for FdAllocator {
fn default() -> Self {
Self::new()
}
}
unsafe impl Send for FdAllocator {}
unsafe impl Sync for FdAllocator {}

View file

@ -0,0 +1,40 @@
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// from gst-gir-files (https://gitlab.freedesktop.org/gstreamer/gir-files-rs.git)
// DO NOT EDIT
use glib::{bitflags::bitflags, translate::*};
bitflags! {
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[doc(alias = "GstFdMemoryFlags")]
pub struct FdMemoryFlags: u32 {
#[doc(alias = "GST_FD_MEMORY_FLAG_NONE")]
const NONE = ffi::GST_FD_MEMORY_FLAG_NONE as _;
#[doc(alias = "GST_FD_MEMORY_FLAG_KEEP_MAPPED")]
const KEEP_MAPPED = ffi::GST_FD_MEMORY_FLAG_KEEP_MAPPED as _;
#[doc(alias = "GST_FD_MEMORY_FLAG_MAP_PRIVATE")]
const MAP_PRIVATE = ffi::GST_FD_MEMORY_FLAG_MAP_PRIVATE as _;
#[doc(alias = "GST_FD_MEMORY_FLAG_DONT_CLOSE")]
const DONT_CLOSE = ffi::GST_FD_MEMORY_FLAG_DONT_CLOSE as _;
}
}
#[doc(hidden)]
impl IntoGlib for FdMemoryFlags {
type GlibType = ffi::GstFdMemoryFlags;
#[inline]
fn into_glib(self) -> ffi::GstFdMemoryFlags {
self.bits()
}
}
#[doc(hidden)]
impl FromGlib<ffi::GstFdMemoryFlags> for FdMemoryFlags {
#[inline]
unsafe fn from_glib(value: ffi::GstFdMemoryFlags) -> Self {
skip_assert_initialized!();
Self::from_bits_truncate(value)
}
}

View file

@ -0,0 +1,6 @@
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// from gst-gir-files (https://gitlab.freedesktop.org/gstreamer/gir-files-rs.git)
// DO NOT EDIT
use glib::translate::*;

View file

@ -0,0 +1,56 @@
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// from gst-gir-files (https://gitlab.freedesktop.org/gstreamer/gir-files-rs.git)
// DO NOT EDIT
#[cfg(target_os = "linux")]
#[cfg_attr(docsrs, doc(cfg(target_os = "linux")))]
#[cfg(feature = "v1_24")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
mod drm_dumb_allocator;
#[cfg(target_os = "linux")]
#[cfg_attr(docsrs, doc(cfg(target_os = "linux")))]
#[cfg(feature = "v1_24")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
pub use self::drm_dumb_allocator::DRMDumbAllocator;
#[cfg(target_os = "linux")]
#[cfg_attr(docsrs, doc(cfg(target_os = "linux")))]
mod dma_buf_allocator;
#[cfg(target_os = "linux")]
#[cfg_attr(docsrs, doc(cfg(target_os = "linux")))]
pub use self::dma_buf_allocator::DmaBufAllocator;
mod fd_allocator;
pub use self::fd_allocator::FdAllocator;
mod phys_memory_allocator;
pub use self::phys_memory_allocator::PhysMemoryAllocator;
#[cfg(unix)]
#[cfg_attr(docsrs, doc(cfg(unix)))]
#[cfg(feature = "v1_24")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
mod shm_allocator;
#[cfg(unix)]
#[cfg_attr(docsrs, doc(cfg(unix)))]
#[cfg(feature = "v1_24")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
pub use self::shm_allocator::ShmAllocator;
mod flags;
pub use self::flags::FdMemoryFlags;
pub(crate) mod functions;
mod constants;
pub use self::constants::ALLOCATOR_DMABUF;
pub use self::constants::ALLOCATOR_FD;
#[cfg(feature = "v1_24")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
pub use self::constants::ALLOCATOR_SHM;
pub use self::constants::CAPS_FEATURE_MEMORY_DMABUF;
pub(crate) mod traits {
pub use super::phys_memory_allocator::PhysMemoryAllocatorExt;
}

View file

@ -0,0 +1,31 @@
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// from gst-gir-files (https://gitlab.freedesktop.org/gstreamer/gir-files-rs.git)
// DO NOT EDIT
use glib::prelude::*;
glib::wrapper! {
#[doc(alias = "GstPhysMemoryAllocator")]
pub struct PhysMemoryAllocator(Interface<ffi::GstPhysMemoryAllocator, ffi::GstPhysMemoryAllocatorInterface>) @requires gst::Allocator;
match fn {
type_ => || ffi::gst_phys_memory_allocator_get_type(),
}
}
impl PhysMemoryAllocator {
pub const NONE: Option<&'static PhysMemoryAllocator> = None;
}
unsafe impl Send for PhysMemoryAllocator {}
unsafe impl Sync for PhysMemoryAllocator {}
mod sealed {
pub trait Sealed {}
impl<T: super::IsA<super::PhysMemoryAllocator>> Sealed for T {}
}
pub trait PhysMemoryAllocatorExt: IsA<PhysMemoryAllocator> + sealed::Sealed + 'static {}
impl<O: IsA<PhysMemoryAllocator>> PhysMemoryAllocatorExt for O {}

View file

@ -0,0 +1,20 @@
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// from gst-gir-files (https://gitlab.freedesktop.org/gstreamer/gir-files-rs.git)
// DO NOT EDIT
use crate::FdAllocator;
glib::wrapper! {
#[doc(alias = "GstShmAllocator")]
pub struct ShmAllocator(Object<ffi::GstShmAllocator, ffi::GstShmAllocatorClass>) @extends FdAllocator, gst::Allocator;
match fn {
type_ => || ffi::gst_shm_allocator_get_type(),
}
}
impl ShmAllocator {}
unsafe impl Send for ShmAllocator {}
unsafe impl Sync for ShmAllocator {}

View file

@ -0,0 +1,3 @@
Generated by gir (https://github.com/gtk-rs/gir @ 5223ce91b97a)
from gir-files (https://github.com/gtk-rs/gir-files @ 6cd7b656acd6)
from gst-gir-files (https://gitlab.freedesktop.org/gstreamer/gir-files-rs.git @ c988e03b5e99)

View file

@ -0,0 +1,7 @@
// Take a look at the license at the top of the repository in the LICENSE file.
use gst::CapsFeatures;
use once_cell::sync::Lazy;
pub static CAPS_FEATURES_MEMORY_DMABUF: Lazy<CapsFeatures> =
Lazy::new(|| CapsFeatures::new([crate::CAPS_FEATURE_MEMORY_DMABUF]));

View file

@ -0,0 +1,79 @@
use std::{
fmt,
os::unix::prelude::{IntoRawFd, RawFd},
};
use glib::{prelude::*, translate::*};
use gst::{Memory, MemoryRef};
#[cfg(feature = "v1_16")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
use crate::FdMemoryFlags;
use crate::{DmaBufAllocator, FdMemory, FdMemoryRef};
gst::memory_object_wrapper!(
DmaBufMemory,
DmaBufMemoryRef,
gst::ffi::GstMemory,
|mem: &gst::MemoryRef| { unsafe { from_glib(ffi::gst_is_dmabuf_memory(mem.as_mut_ptr())) } },
FdMemory,
FdMemoryRef,
Memory,
MemoryRef
);
impl fmt::Debug for DmaBufMemory {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
DmaBufMemoryRef::fmt(self, f)
}
}
impl fmt::Debug for DmaBufMemoryRef {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
MemoryRef::fmt(self, f)
}
}
impl DmaBufMemoryRef {
#[doc(alias = "gst_dmabuf_memory_get_fd")]
pub fn fd(&self) -> RawFd {
skip_assert_initialized!();
unsafe { ffi::gst_dmabuf_memory_get_fd(self.as_mut_ptr()) }
}
}
impl DmaBufAllocator {
#[doc(alias = "gst_dmabuf_allocator_alloc")]
pub unsafe fn alloc<A: IntoRawFd>(
&self,
fd: A,
size: usize,
) -> Result<gst::Memory, glib::BoolError> {
skip_assert_initialized!();
Option::<_>::from_glib_full(ffi::gst_dmabuf_allocator_alloc(
self.unsafe_cast_ref::<gst::Allocator>().to_glib_none().0,
fd.into_raw_fd(),
size,
))
.ok_or_else(|| glib::bool_error!("Failed to allocate memory"))
}
#[cfg(feature = "v1_16")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
#[doc(alias = "gst_dmabuf_allocator_alloc_with_flags")]
pub unsafe fn alloc_with_flags(
&self,
fd: RawFd,
size: usize,
flags: FdMemoryFlags,
) -> Result<gst::Memory, glib::BoolError> {
skip_assert_initialized!();
Option::<_>::from_glib_full(ffi::gst_dmabuf_allocator_alloc_with_flags(
self.unsafe_cast_ref::<gst::Allocator>().to_glib_none().0,
fd,
size,
flags.into_glib(),
))
.ok_or_else(|| glib::bool_error!("Failed to allocate memory"))
}
}

View file

@ -0,0 +1,81 @@
use std::{fmt, mem, os::unix::prelude::IntoRawFd};
use glib::{prelude::*, translate::*};
use gst::{Memory, MemoryRef};
use crate::{DRMDumbAllocator, DmaBufMemory};
gst::memory_object_wrapper!(
DRMDumbMemory,
DRMDumbMemoryRef,
gst::ffi::GstMemory,
|mem: &gst::MemoryRef| { unsafe { from_glib(ffi::gst_is_drm_dumb_memory(mem.as_mut_ptr())) } },
Memory,
MemoryRef
);
impl fmt::Debug for DRMDumbMemory {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
DRMDumbMemoryRef::fmt(self, f)
}
}
impl fmt::Debug for DRMDumbMemoryRef {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
MemoryRef::fmt(self, f)
}
}
impl DRMDumbMemoryRef {
#[doc(alias = "gst_drm_dumb_memory_get_handle")]
pub fn fd(&self) -> u32 {
skip_assert_initialized!();
unsafe { ffi::gst_drm_dumb_memory_get_handle(self.as_mut_ptr()) }
}
#[doc(alias = "gst_drm_dumb_memory_export_dmabuf")]
pub fn export_dmabuf(&self) -> Result<DmaBufMemory, glib::BoolError> {
skip_assert_initialized!();
unsafe {
Option::<DmaBufMemory>::from_glib_full(ffi::gst_drm_dumb_memory_export_dmabuf(
self.as_mut_ptr(),
))
.ok_or_else(|| glib::bool_error!("Failed to export as dmabuf"))
}
}
}
impl DRMDumbAllocator {
#[doc(alias = "gst_drm_dumb_allocator_new_with_fd")]
#[doc(alias = "new_with_fd")]
pub fn with_fd<A: IntoRawFd>(drm_fd: A) -> Result<DRMDumbAllocator, glib::BoolError> {
assert_initialized_main_thread!();
unsafe {
Option::<gst::Allocator>::from_glib_full(ffi::gst_drm_dumb_allocator_new_with_fd(
drm_fd.into_raw_fd(),
))
.map(|o| o.unsafe_cast())
.ok_or_else(|| glib::bool_error!("Failed to create allocator"))
}
}
#[doc(alias = "gst_drm_dumb_allocator_alloc")]
pub unsafe fn alloc(
&self,
drm_fourcc: u32,
width: u32,
height: u32,
) -> Result<(gst::Memory, u32), glib::BoolError> {
skip_assert_initialized!();
let mut out_pitch = mem::MaybeUninit::uninit();
Option::<_>::from_glib_full(ffi::gst_drm_dumb_allocator_alloc(
self.to_glib_none().0,
drm_fourcc,
width,
height,
out_pitch.as_mut_ptr(),
))
.ok_or_else(|| glib::bool_error!("Failed to allocate memory"))
.map(|mem| (mem, unsafe { out_pitch.assume_init() }))
}
}

View file

@ -0,0 +1,64 @@
use std::{fmt, os::unix::prelude::RawFd};
use glib::{prelude::*, translate::*};
use gst::{Memory, MemoryRef};
use crate::{FdAllocator, FdMemoryFlags};
gst::memory_object_wrapper!(
FdMemory,
FdMemoryRef,
gst::ffi::GstMemory,
|mem: &gst::MemoryRef| { unsafe { from_glib(ffi::gst_is_fd_memory(mem.as_mut_ptr())) } },
Memory,
MemoryRef,
);
impl fmt::Debug for FdMemory {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
FdMemoryRef::fmt(self, f)
}
}
impl fmt::Debug for FdMemoryRef {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("FdMemory")
.field("ptr", &self.as_ptr())
.field("allocator", &self.allocator())
.field("parent", &self.parent())
.field("maxsize", &self.maxsize())
.field("align", &self.align())
.field("offset", &self.offset())
.field("size", &self.size())
.field("flags", &self.flags())
.field("fd", &self.fd())
.finish()
}
}
impl FdMemoryRef {
#[doc(alias = "gst_fd_memory_get_fd")]
pub fn fd(&self) -> RawFd {
skip_assert_initialized!();
unsafe { ffi::gst_fd_memory_get_fd(self.as_mut_ptr()) }
}
}
impl FdAllocator {
#[doc(alias = "gst_fd_allocator_alloc")]
pub unsafe fn alloc(
&self,
fd: RawFd,
size: usize,
flags: FdMemoryFlags,
) -> Result<gst::Memory, glib::BoolError> {
skip_assert_initialized!();
Option::<_>::from_glib_full(ffi::gst_fd_allocator_alloc(
self.unsafe_cast_ref::<gst::Allocator>().to_glib_none().0,
fd,
size,
flags.into_glib(),
))
.ok_or_else(|| glib::bool_error!("Failed to allocate memory"))
}
}

View file

@ -0,0 +1,63 @@
// Take a look at the license at the top of the repository in the LICENSE file.
#![cfg_attr(docsrs, feature(doc_cfg))]
#![allow(clippy::missing_safety_doc)]
#![doc = include_str!("../README.md")]
pub use ffi;
pub use glib;
pub use gst;
macro_rules! assert_initialized_main_thread {
() => {
if !gst::INITIALIZED.load(std::sync::atomic::Ordering::SeqCst) {
gst::assert_initialized();
}
};
}
macro_rules! skip_assert_initialized {
() => {};
}
#[allow(unused_imports)]
mod auto;
pub use crate::auto::*;
mod caps_features;
pub use crate::caps_features::CAPS_FEATURES_MEMORY_DMABUF;
mod fd_allocator;
pub use fd_allocator::*;
#[cfg(any(target_os = "linux", docsrs))]
#[cfg_attr(docsrs, doc(cfg(target_os = "linux")))]
mod dma_buf_allocator;
#[cfg(any(target_os = "linux", docsrs))]
#[cfg_attr(docsrs, doc(cfg(target_os = "linux")))]
pub use dma_buf_allocator::*;
#[cfg(any(all(feature = "v1_24", target_os = "linux"), docsrs))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "v1_24", target_os = "linux"))))]
mod drm_dumb_allocator;
#[cfg(any(all(feature = "v1_24", target_os = "linux"), docsrs))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "v1_24", target_os = "linux"))))]
pub use drm_dumb_allocator::*;
#[cfg(any(all(feature = "v1_24", unix), docsrs))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "v1_24", unix))))]
mod shm_allocator;
mod phys_memory;
pub use phys_memory::*;
// Re-export all the traits in a prelude module, so that applications
// can always "use gst_base::prelude::*" without getting conflicts
pub mod prelude {
#[doc(hidden)]
pub use gst::prelude::*;
pub use crate::auto::traits::*;
}
pub mod subclass;

Some files were not shown because too many files have changed in this diff Show more