338 Commits

Author SHA1 Message Date
Joe Turki
d8828d6df0 Advertise ICE renomination option 2025-12-20 19:35:08 +02:00
boks1971
f3177f8486 Option to ignore rid pause in a=simulcast:recv
Before this change, if the SDP offer has paused rids,
SDP answer echoed it back. That causes issues where enabling/disabling
of layers is signalled via the signalling channel. The following
scenario breaks
1. PeerB signals PeerA to disable all simulcast layers.
2. PeerA sends an SDP offer with RIDs disabled.
   a. NOTE: A renegotiation is not needed, but happens for a different
      reason.
3. PeerB signals again to PeerA to re-enable layers.
4. PeerB sends answer for the offer in Step 2 with paused rids.
5. PeerA keeps layers paused.

Adding a setting engine option to not change existing behaviour. Pause
state of a rid will be ignored if setting is enabled.
2025-12-05 15:41:40 +05:30
Joe Turki
210cd958d5 Add CanTrickleICECandidates
w3c CanTrickleICECandidates.
2025-12-04 19:36:05 +02:00
Srayan Jana
4b59cf9986 Support advertising ICE trickling (#3097)
As defined in [RFC8839], when an ICE restart occurs, a new SDP offer/answer exchange is triggered. However, as WHIP does not support renegotiation of non-ICE-related SDP information, a WHIP client will not send a new offer when an ICE restart occurs. Instead, the WHIP client and WHIP session will only exchange the relevant ICE information via an HTTP PATCH request as defined in Section 4.3.1 and MUST assume that the previously negotiated non-ICE-related SDP information still applies after the ICE restart.

When performing an ICE restart, the WHIP client MUST include the updated "ice-pwd" and "ice-ufrag" in the SDP fragment of the HTTP PATCH request body as well as the new set of gathered ICE candidates as defined in [RFC8840]. Similar to what is defined in Section 4.3.2, as per [RFC9429], only "m=" sections not marked as bundle-only can gather ICE candidates, so given that the "max-bundle" policy is being used, the SDP fragment will contain only the offerer-tagged "m=" line of the bundle group. A WHIP client sending a PATCH request for performing ICE restart MUST contain an If-Match header field with a field-value of "*" as per Section 13.1.1 of [RFC9110].



Co-authored-by: Joe Turki <git@joeturki.com>
2025-12-03 02:25:07 +02:00
Sean DuBois
71b8a13dc9 Don't drop packets when probing Simulcast
Before any packets that we read during the probe would get lost

Co-authored-by: cptpcrd <31829097+cptpcrd@users.noreply.github.com>
2025-11-29 07:42:50 -05:00
Joe Turki
e710dae6fe Refactor streamsForSSRC to return struct 2025-11-18 09:49:11 +02:00
Kostya Vasilyev
e7e3b36fce Consider first packet when reading Simulcast IDs (#3144)
The code currently ignores the first packet when reading Simulcast IDs
from a new SSRC, and probes only subsequent packets. This commit makes
it so that we consider the first packet as well (which we already have
read). Helps if the publisher only sends Simulcast IDs on the first
packet.
2025-11-18 04:11:03 +02:00
Mathis Engelbart
49a4074cc6 Expose stats ID for use in interceptor factories 2025-10-27 21:33:55 +01:00
Joe Turki
5a0e56e105 Prefer makezero with a cap 2025-09-19 06:19:21 +03:00
Joe Turki
9acbc661f6 Cleanup statsGetter after peer is closed 2025-09-19 05:42:41 +03:00
Shreyas Jaganmohan
4c1261ff83 Add inbound-rtp stats
Remove comments

Add collectStats test

Fix linter issues

Remove comment

Fix tests

Address comments

Fix comment

Fix function comment
2025-09-18 23:25:24 +02:00
philipch07
39d1b3cb9d Apply go modernize suggestions 2025-09-14 18:20:19 -04:00
boks1971
c376d0edf9 Match codec order of remote peer
Done when creating a transceiver from remote description to respect
codec order preference of remote peer.

There was a recent change to include partial matches which overwrote
same codecs and also rtx was getting magled.

Change it by removing codecs from search space as matches are found so
that a codec match is applied only once.

Also, move RTX matching to separate block to ensure proper RTXes ar
matched.
2025-08-28 10:15:58 +05:30
boks1971
6424d85a10 Consider remote direction in add track
A follow on to https://github.com/pion/webrtc/pull/3200.
This removes the setting engine flag and uses knowledge
of remote direction to decide if a transceiver can be
re-used for sending.

Refactored the code a bit and moved the check into
RTPTransceiver.isSendAllowed.

Re-did the UT to check for re-use cases.
2025-08-25 10:15:56 -06:00
boks1971
2299a71701 Add opt control transceiver re-use in recvonly
SetDisableTransceiverReuseInRecvonly controls if a
transceiver is re-used when its current direction is `recvonly`.

This is useful for the following scenario
  - Remote side sends `offer` with `sendonly` media section.
  - Local side creates transceiver in `SetRemoteDescription`
    and sets direction to `recvonly.
  - Local side calls `AddTrack`.
  - As the current direction is `recvonly`, the transceiver added
    above will be re-used. That will set the direction to `sendrecv`
    and the generated `answer` will have `sendrecv` for that
    media section.
  - That answer becomes incompatible as the offerer is using
    `sendonly`.

Note that local transceiver will be in `recvonly` for both `sendrecv`
and `sendonly` directions in the media section. If the `offer` did use
`sendrecv`, it is possible to re-use that transceiver for sending.
So, disabling re-use will prohibit re-use in the `sendrecv` case also
and hence is slightly wasteful.
2025-08-24 21:38:59 +05:30
cnderrauber
3e84081c87 Add partialMatch codecs to transceiver from remote
When a recvonly transceiver is created from remote
offer, skip partial matched codec will cause the
receiver can't be reused to send the codec.
2025-08-24 16:47:00 +08:00
boks1971
8efd17e592 Do not create receiver for ealy media in offerer
For offerer, if the remote side sends early media
before the remote description (answer) is received,
the undeclared SSRC processor can create a receiver
and that receiver could be left dangling as
transceiver `mid` is not updated from remote
description answer.

Still leaving the simulcast probe path and only
avoiding creating a receiver for non-simulcast path.

Add a flag `handleUndeclaredSSRCWithoutAnswer` to control handling
of early media without SDP answer for non-simulcast tracks.
The default behaviour is to not process early media without SDP answer.
2025-08-21 18:36:58 +05:30
Joe Turki
22cf05c358 Upgrade to golangci-lint@v2 2025-08-16 18:31:44 +03:00
Xiaobo Liu
4f67c90d22 Replace custom atomicBool with sync/atomic.Bool
- Remove custom atomicBool implementation
- Replace all atomicBool usages with standard library sync/atomic.Bool

Signed-off-by: Xiaobo Liu <cppcoffee@gmail.com>
2025-06-25 18:05:03 +08:00
3DRX
4742d1fd54 Fix trackDetailsFromSDP not handling fec ssrc 2025-05-27 15:18:12 +06:00
Nils Ohlmeier
716beb568e Use space after WMS. Fixes #3128 2025-05-22 11:16:35 -06:00
Joe Turki
465d8bd950 Reject candidates from old generation
Return an error if a candidate with a username fragment that does
not match the username fragment in the remote description is added.
This usually indicates that the candidate was generated before the
renegotiation.
2025-04-27 18:34:45 +03:00
Nils Ohlmeier
5676fa4d38 Don't expose new MediaEngine functions 2025-04-15 11:54:34 -06:00
Nils Ohlmeier
a561371028 Made multi codec the default 2025-04-15 11:54:34 -06:00
Nils Ohlmeier
be8800d522 Implemented alternative proposal via SettingEngine 2025-04-15 11:54:34 -06:00
sirzooro
77fc1cb069 Added missing lock 2025-04-12 20:40:54 +02:00
Joe Turki
5ce8e05d22 Resolve undeclared SSRC using the payload type
Introduces a fallback mechanism to handle undeclared SSRCs from multiple
sections using the RTP stream's payload type. For legacy clients
without MID extension support, it documents the existing behavior for
handling undeclared SSRCs in single media sections.
2025-03-19 07:50:16 +02:00
Sean DuBois
e4ff415b2b Support DataChannel messages larger then MaxUint16
SCTP now internally can handle larger messages

Resolves #2712
2025-03-04 18:22:14 -08:00
Joe Turki
feeeebf251 Upgrade golangci-lint, more linters
Introduces new linters, upgrade golangci-lint to version (v1.63.4)
2025-01-18 07:16:06 -06:00
Juliusz Chroboczek
f2191fbfa7 Finish moving SDESRTPStreamIDURI (#3000)
Finish moving SDESRTPStreamIDURI from here to pion/sdp.
2025-01-13 09:25:13 -05:00
Joe Turk
5edce958fd Include sdpMid and sdpMLineIndex for ICECandidates returned by OneICECandidate (#2990)
#### Description
Currently, Pion returns an empty `sdpMid` and a 0 `sdpMLineIndex`. This
PR ensures Pion returns the corresponding `sdpMid` and `sdpMLineIndex`
for ICE candidates for clients that expects it. Fixes trickle issues.

#### Changes

1. `ICECandidates`: New fields `SDPMid` and `SDPMLineIndex`.
2. `ICEGatherer`: `SetMediaStreamIdentification` and return the correct
`SDPMid` and `SDPMLineIndex`.
3. `extractICEDetails`: Return a struct instead of multiple values.
4. `extractICEDetails` refactored the media description selection to a
different function.
5. Added new tests.

#### Reference issue
Fixes https://github.com/pion/webrtc/issues/2690
Fixes https://github.com/pion/webrtc/issues/1833
2025-01-08 19:08:44 -06:00
Aleksandr Alekseev
3f246fdad2 Close interceptor after PeerConnection is closed 2024-12-24 23:12:04 +03:00
boks1971
9eee2cc038 Remove stopped member from RTPTransceiver
It is unused. If needed in the future we can add it back
2024-12-14 20:07:11 -05:00
Juliusz Chroboczek
2585a2fd03 Improve the documentation of NewPeerConnection 2024-12-14 19:43:44 -05:00
cnderrauber
8e2c8682de Add option to disable close by dtls
Close peerconnection on DTLS.CloseNotify
could break ice restart with dtls restart,
when the dtls finger-print changed, the
browser could teardown the old dtlstransport
and establish new one then pion could close
the peerconnection and restart failed. So
browser don't do this and spec also don't
say peerconnection should close when dtls
is closed.
2024-11-29 08:09:21 -05:00
Eric Daniels
76634b143a Add SetFireOnTrackBeforeFirstRTP 2024-10-15 12:10:07 -04:00
Sean DuBois
32f7063f1a Send FEC and RTX PayloadType into interceptor
New fields added to interceptor.StreamInfo
2024-10-04 21:33:10 -04:00
Sean DuBois
4541b73b1a Add Retransmission and FEC to TrackLocal
If the MediaEngine contains support for them a SSRC will be generated
appropriately

Co-authored-by: aggresss <aggresss@163.com>
Co-authored-by: Kevin Wang <kevmo314@gmail.com>

Resolves #1989
Resolves #1675
2024-10-03 20:44:49 -07:00
cnderrauber
e6a86e74b9 Don't reuse transceiver in one round negotiation
Should not reuse transceiver (remove & add track)
in one round negotiation, it cause the transceiver
changes ssrc/id without transit to inactive and the
remote peer connection can't fire track close and
OnTrack event.
2024-09-06 14:55:33 +00:00
Eric Daniels
9a61d68237 Fix concurrent pc.GracefulClose 2024-08-26 10:50:45 -04:00
Eric Daniels
48a2e5a0cc Revert "Run ops.GracefulClose earlier in pc.Close"
This reverts commit ec6b6f1d54.
2024-08-14 14:36:04 -04:00
Eric Daniels
ec6b6f1d54 Run ops.GracefulClose earlier in pc.Close 2024-08-13 09:29:11 -04:00
Sean DuBois
3aab0355e0 Upgrade dtls, ice, stun and turn
New major version of all packages caused by DTLS upgrade
2024-08-12 13:45:35 -04:00
Eric Daniels
78c8a2e07c Add PeerConnection.GracefulClose 2024-08-06 09:51:54 -04:00
Juan Navarro
cbbb1c29e5 Fix disordered RIDs in SDP
Map iteration order is not guaranteed by Go, so it's an error to iterate
over a map in places where maintaining the same ordering is important.

This change replaces the map of simulcastRid{} with an array of the same
type. The simulcastRid{} type is extended to hold the rid-id which
previously was used as the key in the map.

Accesses to the map are replaced with range loops to find the desired
rid-id for each case.

Fixes #2838
2024-08-01 10:56:45 -04:00
Eric Daniels
05cafb3d03 Close unhandled rtcp simulcast streams
handleIncomingSSRC will call streamsForSSRC which
opens rtp/rtcp streams that if unhandled can be
leaked resources. Now we will proactively open
them before calling handleIncomingSSRC and close
then later. In the future it would be better to
do this inside handleIncomingSSRC to protect other
callers.
2024-07-23 00:03:17 -04:00
Sean DuBois
c85269bee3 Properly handle non-media probes
libwebrtc has started sending media probes on an unannounced SSRC(0).
Currently Pion will ignore this as the SSRC hasn't been declared
explicitly and no RID/MID RTP Headers.

This adds a special case to accept SSRC 0 and Read the RTP packets. This
allows the TWCC reports to properly be generated.
2024-07-20 22:16:22 -04:00
Eric Daniels
17d3e97b59 Hold pc.mu while populating local candidates 2024-07-19 12:05:41 -04:00
cnderrauber
287d10638d Match header extensions to remote media sections
Firefox would send updated header extension
in renegotiation, e.g. publish a track without
simucalst then renegotiate second track with
simucalst, the two media secontions will have
different rtp header extensions in offer. Need
to match remote header extentions for each
media sections to avoid second track publish
failed.
2024-07-18 12:30:19 +08:00
Sean DuBois
e17ce04589 Revert 7c8bfbd44a and add test
Don't block Close on spawned goroutines
2024-07-15 11:26:21 -04:00