Commit graph

52 commits

Author SHA1 Message Date
Ludvig Rappe
26263c194e webrtc: Fix memory leak in icestream
Since both g_value_set_object() and g_weak_ref_get() takes a reference
there will be two new references to the GstWebRTCICE object when there
should be only one. g_value_take_object() has the same functionality as
g_value_set_object() but does not take a reference.

Without this change, the GstWebRTCICE object will be leaked.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2333>
2022-04-29 21:52:43 +00:00
Sangchul Lee
c5b1eecb69 webrtcbin: Avoid access of freed memory
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2256>
2022-04-22 14:45:05 +00:00
Johan Sternerup
1842ffc906 webrtc: Improve robustness of nice agent signal handlers
NiceAgent and it's associated thread is alive for as long as
GstWebRTCICE is alive so make sure any signal handlers connected to
NiceAgent do not access data that is deleted earlier.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2073>
2022-04-04 02:10:35 +00:00
Xavier Claessens
b004464ac6 Remove glib and gobject dependencies everywhere
They are part of gst_dep already and we have to make sure to always have
gst_dep. The order in dependencies matters, because it is also the order
in which Meson will set -I args. We want gstreamer's config.h to take
precedence over glib's private config.h when it's a subproject.

While at it, remove useless fallback args for gmodule/gio dependencies,
only gstreamer core needs it.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2031>
2022-04-01 16:32:17 +00:00
Sangchul Lee
a801d6dd63 webrtcstats: Unify 'packets-lost' data type to int64
Previously, 'packets-lost' member of RTCReceivedRtpStreamStats had
a value of G_TYPE_INT from rtpsource or a value of G_TYPE_UINT64
from rtpjitterbuffer.
Because of the negative value of estimated amount of packets lost
in rtpsource as well as the description in
https://www.w3.org/TR/webrtc-stats/#dom-rtcreceivedrtpstreamstats
it is fixed to set this value with G_TYPE_INT64.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2049>
2022-03-31 05:37:39 +00:00
Matthew Waters
041eee6c2e webrtc: produce stats for all relevant streams
Instead of only using the last ssrc that was pushed into a sink pad.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1664>
2022-03-29 23:55:41 +00:00
Matthew Waters
04de1a161f webrtc: avoid different versions of gnu-indent always wanting to change !!
Add some sneaky parenthesis to avoid always having to use git commit -n
or revert out hunk of the change.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1664>
2022-03-29 23:55:41 +00:00
Matthew Waters
5bfe36746a webrtc: implement initial simulcast fec/rtx usage
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1664>
2022-03-29 23:55:41 +00:00
Matthew Waters
5741ee38e0 webrtc/datachannel: fix use-after-free in sctp state notification
g_signal_disconnect*() doesn't stop any existing callbacks from running
which means that if the notify::state callback is in progress in one
thread and the data channel object is finalize()ed in another thread,
then there could be a use-after-free trying lock the data channel
object.

We can't reasonably use a GWeakRef as we don't have a 'parent' object to
free the GWeakRef after the data channel is finalized.  This is also
complicated by the fact that the application can hold a reference to the
data channel object that would live beyond the lifetime of webrtcbin
itself.

We solve this by implementing a ghetto weak-ref solution internally with
a list of outstanding data channels.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1664>
2022-03-29 23:55:40 +00:00
Matthew Waters
2377f8b3f2 webrtcbin: initial support for sending and receiving simulcast streams
Input (sink pads) is the already-ssrc-muxed stream with the relevant rtp
sdes header extensions already applied:
  - mid
  - stream-id
  - repaired-stream-id

Output (src pads) have the pads separated into individual ssrc's as
that's what rtpbin gives us.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1664>
2022-03-29 23:55:40 +00:00
Matthew Waters
699739c130 webrtcbin: support multiple received streams for a single mline
Each rtpbin exposed recv_src pad is now exposed as webrtcbin src_%u pad
now with no meaining applied to the value of %u.  Previously this used
to mean the mline in the SDP.  If this is is still required, then the
transceiver can be retrieved from the pad and the "mlineindex" property
from the transciever.  The "mid" is also retrievable from the
transceiver.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1664>
2022-03-29 23:55:40 +00:00
Matthew Waters
e28c45fd05 webrtc: explicitly error out in a couple of renegotiation cases
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1664>
2022-03-29 23:55:40 +00:00
Matthew Waters
318a639e43 webrtc/transportstream: add debug category
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1664>
2022-03-29 23:55:40 +00:00
Matthew Waters
2aeca9ed84 webrtcbin: don't name src pads based on the mline specifically anymore
Naming based on the mline doesn't really work with e.g. simulcast
scenarios.

It is entirely possible to retrieve the transceiver and then the mline
from that if that is so required.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1664>
2022-03-29 23:55:40 +00:00
Matthew Waters
cda81bdb1e webrtcbin: improve some debugging output
- Put human readable names into debug strings.
- Demote some frequent rtpbin signal logging
- Don't use GST_PTR_FORMAT in g_set_error()

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1664>
2022-03-29 23:55:40 +00:00
Matthew Waters
533d4937fe webrtcbin: add a specific find_transceiver_by_mid function
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1664>
2022-03-29 23:55:40 +00:00
Matthew Waters
79d58200c9 webrtcbin: explicitly use a variable for the rtp session idx
Slightly clearer in meaning.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1664>
2022-03-29 23:55:40 +00:00
Matthew Waters
9a758d78a9 webrtcbin: support using an a=mid value from the sink/transceiver caps
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1664>
2022-03-29 23:55:40 +00:00
Sangchul Lee
952c1194f3 webrtcbin: Update documentation of 'get-stats' action signal
Some stats fields are updated according to the current implementation.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2005>
2022-03-25 07:01:40 +00:00
Mathieu Duponchelle
29de0e8e1d Revert "webrtcbin: fix msid line and allow customization"
This reverts commit 3cad3455377d5a22faa138d9df840257059776c8.

That commit was breaking the association between an audio and
a video track in the standard case.

In practice, to support carrying separate MediaStream, we are
going a way to map what MediaStreamTrack belong to what MediaStream,
but that will require some thinking about the API.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2023>
2022-03-25 00:31:58 +01:00
Mathieu Duponchelle
06fec40f45 webrtcbin: fix msid line and allow customization
From https://datatracker.ietf.org/doc/html/draft-ietf-mmusic-msid-16:

> Multiple media descriptions with the same value for msid-id and
> msid-appdata are not permitted.

Our previous implementation of simply using the CNAME as the msid
identifier and the name of the transceiver as the msid appdata was
misguided and incorrect, and created issues when bundling multiple
video streams together: the ontrack event was emitted with the same
streams for the two bundled medias, at least in Firefox.

Instead, use the transceiver name as the identifier, and expose
a msid-appdata property on transceivers to allow for further
customization by the application. When the property is not set,
msid-appdata can be left empty as it is specified as optional.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2003>
2022-03-24 16:43:29 +00:00
Nirbheek Chauhan
253ee75a72 webrtcbin: Warn when offer didn't intersect with transceiver caps
We were silently falling back to creating a recvonly offer if the caps
didn't intersect.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1864>
2022-03-18 08:16:46 +00:00
Mathieu Duponchelle
30d028317b webrtcbin: fix deadlock when setting up FEC encoder
We bind transceivers' fec_percentage property to the FEC encoder
percentage property, and with the binding bidirectional a deadlock
was introduced by the latest changes from !1762:

We take hold of the transceiver's object lock, then add the binding
and set the property to its initial value on the encoder, which causes
set_property to deadlock in the transceiver when the binding kicks in.

Changing the binding type to DEFAULT (source to target) is enough
to address the deadlock and still serves the original intent.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1967>
2022-03-16 06:06:39 +00:00
Sangchul Lee
2f7c843f2b webrtcbin: Check data channel transport for notifying 'ice-gathering-state'
Previously, it did not care about data channel's. It is fixed by adding
some conditions.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1957>
2022-03-16 03:31:08 +00:00
Matthew Waters
ccd1b76625 webrtcbin: fix ulpfecenc passthrough pt
ulpfecenc uses a value of pt=255 for passthrough.

Fixes: https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/1075
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1914>
2022-03-10 16:20:03 +00:00
Matthew Waters
b7d0ddd1a4 webrtc: support renegotiating adding/removing RTX
We need to always add the RTX/RED/ULPFEC elements as rtpbin will only
call us once to request aux/fec senders/receivers.

We also need to regenerate the media section of the SDP instead of
blindly copying from the previous offer.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1762>
2022-03-04 19:21:59 +11:00
Sangchul Lee
dcff37722d webrtcice: Fix memory leaks in gst_webrtc_ice_add_candidate()
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1646>
2022-02-09 09:00:25 +00:00
Philippe Normand
4254920b72 webrtc: Expose RTCError enum
The error codes not complying with the spec are now notified with the
GST_WEBRTC_ERROR_INTERNAL_FAILURE code.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1485>
2022-01-29 14:42:22 +00:00
Jakub Adam
bea8cba5e6 webrtcbin: Chain up to parent constructed method
Failing to do so makes GstWebRTCBin invisible to the leaks tracer.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1587>
2022-01-27 17:43:18 +00:00
Sangchul Lee
5cedf017f5 webrtc: Fix memory leaks
Redundant condition and unreachable codes are also removed.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1544>
2022-01-22 11:21:18 +00:00
Dave Piché
574cbbf0b5 webrtc: fix log error message in function gst_webrtc_bin_set_local_description
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1511>
2022-01-13 15:11:35 +00:00
Philippe Normand
f0e6959bba webrtcdatachannel: Notify buffered-amount property updates
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1484>
2022-01-02 10:18:35 +00:00
Philippe Normand
43856a0735 webrtcstats: Fix null pointer dereference
If there is no jitterbuffer stats we should not attempt to store them in the
global stats structure.

Also add a g_return_if_fail in _gst_structure_take_structure() about this
because it is a programmer error to pass an invalid pointer address there.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1479>
2021-12-29 15:55:57 +00:00
Olivier Crête
818a185b5d webrtcstats: Fall back to last packet ssrc if caps dont provide it
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1448>
2021-12-23 23:48:17 -05:00
Olivier Crête
4e32d6bf3e webrtcstats: Use our own caps instead of the sticky event
The sticky event seems to get cleared sometimes.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1448>
2021-12-23 23:48:17 -05:00
Olivier Crête
29befed685 webrtcbin: Store the ssrc of the last received packet
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1448>
2021-12-23 23:48:17 -05:00
Olivier Crête
fc7e7f5ccc webrtc stats: Remove duplicate structure get
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1448>
2021-12-23 23:48:17 -05:00
Olivier Crête
f35435f1f7 webrtc stats: Add more details about codecs into the stats
This makes the output a little closer to what the upstream stats are.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1448>
2021-12-23 23:48:17 -05:00
Mathieu Duponchelle
abd61732bf webrtcbin: bind transceiver's fec-percentage to encoder percentage
Allows for dynamic control of the applied FEC overhead

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1429>
2021-12-14 17:34:53 +00:00
Mathieu Duponchelle
06893b8b5e webrtcbin: fix ulpfec / red for the BUNDLE case
* Add fec / red encoders as direct children of webrtcbin, instead
  of providing them to rtpbin through the request-fec-encoder signal.

  That is because they need to be placed before the rtpfunnel, which
  is placed upstream of rtpbin.

* Update configuration of red decoders to set a list of RED payloads
  on them, instead of setting the pt property.

  That is because there may be one RED pt per media in the same session.

* Connect to request-fec-decoder-full instead of request-fec-decoder,
  in order to instantiate FEC decoders according to the payload type
  of the stream.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1429>
2021-12-14 17:34:53 +00:00
Mathieu Duponchelle
e90859f4d8 webrtcbin: deduplicate extmaps
When an extmap is defined twice for the same ID, firefox complains and
errors out (chrome is smart enough to accept strict duplicates).

To work around this, we deduplicate extmap attributes, and also error
out when a different extmap is defined for the same ID.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1383>
2021-11-25 18:38:22 +00:00
Sebastian Dröge
f9a97efbe1 webrtcbin: Clear errors from finding codec preferences before the next iteration
The media is just skipped and the error is not propagated to the caller,
so keeping it around here would cause assertions a bit later when trying
to set a new error over the old one.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1291>
2021-11-04 10:51:15 +00:00
Sebastian Dröge
30153f1591 webrtcbin: Move addition of attributes to the caps after making sure they're not empty or any
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1291>
2021-11-04 10:51:15 +00:00
Sebastian Dröge
d628ccf0e5 webrtcbin: Don't require fixed caps when querying caps for a transceiver pad to match it with a media
Upstream caps might for example be
  application/x-rtp,media=audio,encoding-name={OPUS, X-GST-OPUS-DRAFT-SPITTKA-00, multiopus}
and while that is not fixed caps it is enough to match it with a media.

Only caps structures that have the correct structure name and that have
the media and encoding-name field are preserved, but if both are present
then these caps are used as "codec preferences".

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1291>
2021-11-04 10:51:15 +00:00
Mathieu Duponchelle
303c8025c6 webrtcbin: fix check_negotiation computing on caps event
It seems logical that check_negotiation be true if received_caps
is *not* equal to the new caps.

Also clean up handling of transceivers' ssrc events, as this
patch triggered a leaky code path.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1233>
2021-10-28 19:05:59 +00:00
Mathieu Duponchelle
be0b5c54fd webrtcbin: connect input stream when receiving caps
.. if a current direction has already been set

When `webrtcbin` has created an offer based on codec_preferences,
it might not have received caps on its sinkpads by the time a
remote description is set, in which case we want to connect the
input stream upon actual reception of the caps instead.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1233>
2021-10-28 19:05:59 +00:00
Mathieu Duponchelle
a9506f20d3 webrtcbin: consider pads with trans->codec_preferences ready
.. when determining whether we can emit on-negotiation-needed

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1233>
2021-10-28 19:05:59 +00:00
Rob Agar
641b319fd6 webrtcbin: Also check data channel transport when collating connection state
https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/838

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1224>
2021-10-28 05:05:44 +00:00
Rob Agar
66a24023c0 webrtcbin: fix prevention of webrtcbin deletion due to ref held by probe callback
https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/810

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1150>
2021-10-18 10:42:12 +01:00
Sebastian Dröge
3011fa7ddd webrtcbin: Use the same promise reply structure name everywhere
This was an inconsistent mix of different names in the past. The name
has no meaning at all so let's set all to "application/x-gst-promise".

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1099>
2021-10-09 11:45:46 +03:00