Commit graph

102 commits

Author SHA1 Message Date
Thibault Saunier 059cdecf7d webrtc: Unify the Codec structure between sink and source
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1194>
2023-06-06 15:31:45 +02:00
Thibault Saunier cf32d9d668 webrtc: Move make_element to the utils
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1194>
2023-06-06 15:31:45 +02:00
Thibault Saunier ce42723ad2 webrtc: Minor documentation enhancement
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1194>
2023-06-06 15:31:45 +02:00
Mathieu Duponchelle 80582923bb aws_kvs_signaller: don't force us-east-1 region
Instead use default region provider, with a fallback to us-east-1

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1228>
2023-05-30 16:04:27 +00:00
François Laignel 4cc2498c24 webrtcsink: use spawn_blocking instead of call_async
In `webrtcsink`, we terminate a session by setting the session's pipeline to
`Null` like this:

```rust
    pipeline.call_async(|pipeline| {
        [...]
        pipeline.set_state(gst::State::Null);
        [...]
        // the following cvar is awaited in unprepare()
        cvar.notify_one();
    });
```

However, `pipeline.call_async` keeps a ref on the pipeline until it's done,
which means the `cvar` is notified before `pipeline` is actually 'disposed',
which happens in a different thread than `unprepare`'s. [`gst_rtp_bin_dispose`]
releases some resources when the pipeline is unrefed. In some cases, those
resources are actually released after the main thread has returned, leading
various issues.

This commit uses tokio runtime's `spawn_blocking` instead, which allows owning
and disposing of the pipeline before the `cvar` is notified.

[`gst_rtp_bin_dispose`]: https://gitlab.freedesktop.org/gstreamer/gstreamer/-/blob/main/subprojects/gst-plugins-good/gst/rtpmanager/gstrtpbin.c#L3108

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1225>
2023-05-26 14:23:03 +02:00
Mathieu Duponchelle a20855dfd9 webrtcsink: expose consumer-pipeline-created signal
This signal is emitted as soon as the pipeline for each consumer
is created, and can be used by applications that require a greater
level of control over webrtcsink's internals.

An example is also provided to demonstrate usage

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1220>
2023-05-25 13:15:52 +02:00
Sebastian Dröge a27be7d054 net: Update to AWS SDK 0.28
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1224>
2023-05-25 13:23:49 +03:00
François Laignel e62e9f5bd4 webrtcsink: adapt commit "abort stats collection before stopping the Signaller"
Adapt a commit [1] that was introduced as part of the forward port of the MR
'add signal "request-encoded-filter"' [2].

The deadlock said commit was fixing doesn't happen on main branch due to
changes in the element design: the Sessions are no longer aborted with the
element `State` held. However, we want to ensure the stats collection task
is terminated when the `webrtcbin` element returns from the Ready to Null
transition, meaning that the related resources are released.

[1]: gstreamer/gst-plugins-rs!1176 (0e6b9df9)
[2]: gstreamer/gst-plugins-rs!1176

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1222>
2023-05-24 21:35:39 +02:00
Mathieu Duponchelle 44a395f134 webrtcsink: further refactor connection to stats signals
- Stop passing webrtcbin around without using it

- Stop using glib::closure as clippy complains when using a unit type
  default-return

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1217>
2023-05-24 13:35:26 +02:00
Mathieu Duponchelle e13124a426 webrtcsink: fix stats_sigid logic
First off, we just created the session, we know stats_sigid is None
at this point.

Second, don't first assign the result of connecting on-new-ssrc to the
field, then the result of connection twcc-stats, that simply doesn't
make sense.

Finally, actually check that stats_sigid *is* None before connecting
twcc-stats, as I understand it this must have been the original
intention / behavior.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1217>
2023-05-24 13:35:26 +02:00
Mathieu Duponchelle ccf076ed1e webrtcsink: don't panic in twcc-stats callback
If webrtcbin was disposed of at this point, simply return

Fixes: https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/issues/345
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1217>
2023-05-24 13:35:26 +02:00
François Laignel 9a59763df1 webrtcsink: wait for Sessions to end
`State::finalize_session()` asynchronously sets the Session pipeline to Null.
In some cases, sessions `webrtcbin` could terminate their transition to Null
after `webrtcsink` had reached Null.

This commit adds a set of `finalizing_sessions`. When the finalization process
starts, the session is added to the set. After `webrtcbin` has reached the Null
state, the session is removed from the set and a condvar is notified.

In `unprepare`, `webrtcsink` loops until the `finalizing_sessions` set is
empty, awaiting for the condvar to be notified when it's not.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1221>
2023-05-24 10:18:47 +02:00
François Laignel b68e2a1ed0 webrtcsink: remove unneeded mut
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1221>
2023-05-24 10:18:43 +02:00
Thibault Saunier 04e35e86d6 webrtcsrc: Do not pass raw caps in the transceiver
That was not making sense.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1214>
2023-05-18 18:23:56 +03:00
Thibault Saunier e73d7082a6 webrtcsrc: Fix caps used when creating transceiver
We used to pass all media keys and attributes to the caps which
incorrect. Instead we should be using only the keys from the map
and remove all information related to rtcp which is irrelevant
to create the transceiver.

This also simplifies the code.

New caps look like:

```
Caps(
    application/x-rtp(memory:SystemMemory) {
        media: (gchararray) "video",
        payload: (gint) 96,
        clock-rate: (gint) 90000,
        encoding-name: (gchararray) "VP8",
    },
    application/x-rtp(memory:SystemMemory) {
        media: (gchararray) "video",
        payload: (gint) 102,
        clock-rate: (gint) 90000,
        encoding-name: (gchararray) "H264",
        packetization-mode: (gchararray) "1",
        profile: (gchararray) "baseline",
    },
    application/x-rtp(memory:SystemMemory) {
        media: (gchararray) "video",
        payload: (gint) 104,
        clock-rate: (gint) 90000,
        encoding-name: (gchararray) "H264",
        packetization-mode: (gchararray) "0",
        profile: (gchararray) "baseline",
    },
    application/x-rtp(memory:SystemMemory) {
        media: (gchararray) "video",
        payload: (gint) 106,
        clock-rate: (gint) 90000,
        encoding-name: (gchararray) "H264",
        packetization-mode: (gchararray) "1",
        profile: (gchararray) "constrained-baseline",
    },
    application/x-rtp(memory:SystemMemory) {
        media: (gchararray) "video",
        payload: (gint) 108,
        clock-rate: (gint) 90000,
        encoding-name: (gchararray) "H264",
        packetization-mode: (gchararray) "0",
        profile: (gchararray) "constrained-baseline",
    },
    application/x-rtp(memory:SystemMemory) {
        media: (gchararray) "video",
        payload: (gint) 127,
        clock-rate: (gint) 90000,
        encoding-name: (gchararray) "H264",
        packetization-mode: (gchararray) "1",
        profile: (gchararray) "main",
    },
    application/x-rtp(memory:SystemMemory) {
        media: (gchararray) "video",
        payload: (gint) 39,
        clock-rate: (gint) 90000,
        encoding-name: (gchararray) "H264",
        packetization-mode: (gchararray) "0",
        profile: (gchararray) "main",
    },
    application/x-rtp(memory:SystemMemory) {
        media: (gchararray) "video",
        payload: (gint) 98,
        clock-rate: (gint) 90000,
        encoding-name: (gchararray) "VP9",
        profile-id: (gchararray) "0",
    },
    application/x-rtp(memory:SystemMemory) {
        media: (gchararray) "video",
        payload: (gint) 100,
        clock-rate: (gint) 90000,
        encoding-name: (gchararray) "VP9",
        profile-id: (gchararray) "2",
    },
)
```

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1214>
2023-05-18 18:23:56 +03:00
François Laignel 7ba0073052 use Pad builders for optional name definition
Also, apply 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.

See https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/issues/448
Auto-naming discussion: https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1255#note_1891181

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1197>
2023-05-12 12:55:31 +02:00
François Laignel 680d5221db net/webrtc: src: add signal "request-encoded-filter"
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1202>
2023-05-09 12:02:15 +02:00
François Laignel 092ae1fec8 net/webrtc: sink: add signal "request-encoded-filter"
The new "request-encoded-filter" signal is emitted when the encoder and related
elements are added to the pipeline. When defined, the element returned by the
signal is inserted between the encoder and the payloader.

The transformation can be reverted using the [insertable streams API] on the
receiver side.

[insertable streams API]: https://developer.mozilla.org/en-US/docs/Web/API/Insertable_Streams_for_MediaStreamTrack_API

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1202>
2023-05-09 11:17:32 +02:00
François Laignel dc5ddd3022 net/webrtc: sink: abort stats collection before stopping the Signaller
In some rare cases, the webrtc-test entered a deadlock while executing
`WebRTCSink::unprepare`. Attaching gdb to a blocked instance showed:

* `gstrswebrtc::signaller:👿:Signaller::stop()` parked, waiting for a
  `Condvar` in `Signaller::stop()`. This was most likely awaiting for the
  receive task to complete while it was locked in `element.end_session()`.
  This code path is triggered from `unprepare` with the `State` `Mutex` locked.
* `webrtcsink:👿:WebRtcSink::process_stats` waiting for a contended `Mutex`,
  which is also the `State` `Mutex`. This prevented completion of the signal
  `gst_webrtc_bin_get_stats`.

This commit aborts the task in charge of periodically collecting stats and
ensures any remaining iteration completes before requesting the Signaller to
stop.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1202>
2023-05-09 10:26:11 +02:00
François Laignel eca269cbf2 net/webrtc: src: don't set stun-server on webrtcbin when our property is None
... otherwise an error occurs about the stun-server address being an empty
string which doesn't comply with the expected address format.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1202>
2023-05-09 10:26:07 +02:00
Sebastian Dröge cb5b527d74 Update to AWS SDK 0.27 and async-tungstenite 0.22
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1199>
2023-05-02 15:30:00 +03:00
Sebastian Dröge 5451035215 Update async-tungstenite and AWS SDK dependencies
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1187>
2023-04-21 10:48:10 +00:00
Sebastian Dröge cc3646640e Fix a couple of new Rust 1.69 clippy warnings
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1186>
2023-04-20 16:47:45 +03:00
Mathieu Duponchelle dbdb9bc164 webrtcsink: fix navigation data channel
At some point, presumably recently, the data channel stopped being
requested in Ready, making webrtcbin refuse to create it.

There was quite a lot of churn recently so I couldn't pinpoint the
breaking commit easily.

Fix by simply restoring the correct behavior of requesting the channel
after going to the Ready state

Fixes https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/issues/341

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1180>
2023-04-14 14:26:22 +02:00
Mathieu Duponchelle f1fd8d84c3 webrtc: extract a BaseWebRTCSink
For documentation purposes, AwsKVSWebRTCSink should not inherit from
another element.

+ Mark base class as plugin API and update plugin cache

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1178>
2023-04-13 15:06:59 +00:00
Loïc Le Page dba91bceca webrtc: fix documentation after signaller interface changes
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1175>
2023-04-12 20:19:22 +02:00
Thibault Saunier 8f2273328b webrtcsrc: Return bool en 'end-session' as required
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1172>
2023-04-12 12:17:56 +00:00
Guillaume Desmottes 403004a85e fix typos
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1170>
2023-04-10 13:35:32 +02:00
Mathieu Duponchelle a455819871 webrtcsink: fix tracking of signaller state
For the signaller to get stopped, we need to remember that we started it
in the first place.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1167>
2023-04-10 07:58:10 +03:00
Mathieu Duponchelle 3368f55a88 webrtcsink: don't return value from error closure
the signal doesn't expect a return value, which meant we were panicking
as soon as the signaller tried to report an error.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1167>
2023-04-10 07:58:10 +03:00
Mathieu Duponchelle 58c8c0edc7 webrtc: signaller iface: fix session-ended vs end-session confusion
Session ending is bidirectional: the signaller can tell the sink that a
session was ended, and the sink can tell the signaller to end a session.

As such, two signals are needed, before this patch the second case was
not working as in essence the sink was telling itself that a session was
ended, and obviously failing to even find it when trying to end it again.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1167>
2023-04-10 07:58:10 +03:00
Tim-Philipp Müller 7c30430320 webrtc-api: replace LICENSE file symlink with copy
As in !1157

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1169>
2023-04-08 17:22:37 +01:00
Matthew Waters e69b4b7f45 webrtc/signaller/iface: give variables appropriate names
Rather than arg0, arg1, etc.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1141>
2023-04-07 09:58:13 +10:00
Matthew Waters 4f4e5f0d75 webrtcsink/signaller: don't call signals while having state/settings locked
It is a recipe for deadlocks if the signal callback calls back into
webrtcsink in some way.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1141>
2023-04-07 09:58:13 +10:00
Matthew Waters 1c61e46f37 webrtcsink: privatise signalling functions
The functionality is now access through the relevant signals instead.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1141>
2023-04-07 09:58:13 +10:00
Matthew Waters 2ac560975c webrtc/signaller: emit the relevant signals instead of the interface vtable
In order to support the use case of an external user providing their own
signalling mechanism, we want the signals to be used and only if nothing
is connected, fallback to the default handling.  Calling the interface
vtable directly will bypass the signal emission entirely.

Also ensure that the signals are defined properly for this case. i.e.
1. Signals the the application/external code is expected to emit are
   marked as an action signal.
2. Add accumulators to avoid calling the default class handler if
   another signal handler is connected.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1141>
2023-04-07 09:58:13 +10:00
Matthew Waters 343b659755 webrtc/signaller: remove SignallableImplExt
This pattern is used for subclassing and calling parent class/interface functions.
However that is not useful for the signaller object.
1. The signals are the API contract and should instead be used by
   webrtcsrc/sink to ask or provide outside for/with information.
2. The default case (no signal attached)is instead handled by default class
   handlers that call directly using the relevant rust trait.  No parent
   (GObject) vfuncs necessary.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1141>
2023-04-07 09:58:13 +10:00
Matthew Waters b6e78b5f04 webrtcsink: expose signaller as a property
in the process move the signaller field to the settings struct

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1141>
2023-04-07 09:58:13 +10:00
Thibault Saunier 8236f3e5e7 webrtcsink: Port to the 'webrtcsrc' signaller object/interface
With contributions from:
Matthew Waters <matthew@centricular.com>

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1141>
2023-04-07 09:03:47 +10:00
Loïc Le Page f17622a1e1 webrtc: Add gstwebrtc-api subproject in net/webrtc plugin
This subproject adds a high-level web API compatible with GStreamer
webrtcsrc and webrtcsink elements and the corresponding signaling
server. It allows a perfect bidirectional communication between HTML5
WebRTC API and native GStreamer.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/946>
2023-04-04 16:29:44 +02:00
Tim-Philipp Müller 8845f6a4c6 git: replace LICENSE file symlinks with copies
Git will de-duplicate the contents for us anyway, and
symlinks can cause problems with some versions of git
and also on Windows.

https://github.com/mesonbuild/meson/issues/11646
https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4326

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1157>
2023-04-04 14:26:37 +01:00
Mathieu Duponchelle 15e1844956 webrtcsink: fix calculation of fec_ratio with multiple encoders
In this context, the bitrate variable is for all encoders, but the
max_bitrate field is per encoder. To calculate a proper FEC ratio, we
need to scale max_bitrate to the number of encoders.

+ Also clamp the fec-percentage that we set on the transceiver for extra
  safety

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1151>
2023-03-31 12:19:07 +00:00
Sebastian Dröge 315e53f064 webrtc: Update to AWS SDK 0.55/0.25
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1152>
2023-03-31 09:12:26 +00:00
David Revay 002a70a2a4 chore(webrtcsink): fix max-bitrate blurb and nick
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1150>
2023-03-28 16:11:05 +11:00
Vivia Nikolaidou 7a1b2d97d4 webrtcsink: Add ice-transport-policy option
Can be used to force relay ICE candidates, ensuring TURN server is used.
Proxy to the corresponding setting in webrtcbin,

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1143>
2023-03-27 16:12:13 +03:00
Sebastian Dröge c1bac30694 webrtc: Update to aws 0.54/0.24
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1131>
2023-03-11 09:37:14 +02:00
Mathieu Duponchelle 584392049c net/webrtc: implement AWS KVS signaller
And expose a wrapper webrtcsink variant, aws-kvs-webrtcsink.

This adds support in webrtcsink for processing a consumer offer, instead
of producing one.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1114>
2023-03-09 15:39:09 +00:00
Sebastian Dröge fc5ed15af5 Update for gst::Element::link_many() and related API generalization
Specifically, get rid of now unneeded `&`.
2023-03-09 16:46:52 +02:00
Thibault Saunier ce3bb2f1d4 Add a webrtcsrc element
Updating the docker image to include:
https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3236

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/932>
2023-02-28 20:50:15 -03:00
Thibault Saunier 0ae637f531 webrtcsink: Move RUNTIME to the crate so it can be reused
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/932>
2023-02-28 17:57:14 -03:00