110 Commits

Author SHA1 Message Date
Sean DuBois
e0181e91e1 Update TestPeerConnection_SessionID to run on WASM
Relates to #2714
2025-09-19 16:56:07 -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
4b37165dcc Tests to ensure proper direction in SDP
Per @Sean-Der's comments in this PR
(https://github.com/pion/webrtc/pull/3198), adding a couple of more
tests to ensure that direction in SDP is correct when remote offer is
processed and transceivers are matched up against existing ones using
type and direction.

Test flow
- AddTrack first on answer side. This should create a transceiver with
  `sendrecv`
- Receive remote description offer
- First time, it will try to match using type and direction.
  o If the remote offer had a media section with `sendonly`, the above
    should fail to find a match. In this case, a new transceiver will
    be created. So, there should be 2 transceivers (one from this +
    one from AddTrack in Step 1). In this case, the answer will have
    only one media section as the offer had only one slot. And the
    directions should be `remote = sendonly` and `local = recvonly`.
  o If the remote offer is `sendrecv`, it should find a match. So, there
    should be only one transceiver (the one created with AddTrack gets
    used for receive).  In this case, the answer will have
    only one media section as the offer had only one slot. And the
    directions should be `remote = sendrecv` and `local = sendrecv`.
- Then the remote track is removed from offer. Processing that remote
  decription will find a transceiver by `mid`, but directions are
  checked in the SDP to ensure they have correct values.
2025-08-25 21:55:55 +05:30
boks1971
469ca2cf1b Disallow incompatible transceiver directions
This effectively reverts part of
https://github.com/pion/webrtc/pull/2412.

The answer was incorrect under the following conditions
- Answer side added a track, it created a new transceicer with Sendrecv
  direction.
- When the remote offer comes in later, SetRemoteDescription tries to
  find an existing tranceiver by type and direction. It ends up picking
  what was added above even if the remote side is using `sendonly`.
- That results in answer marking the section as `sendrecv` which is
  incompatible with the offer.
2025-08-24 21:44:41 +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
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
Joe Turki
22dd7b733b Replace interface{} with any 2025-06-19 23:44:08 +03: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
Sean DuBois
924dd092b6 Add IPv6 Test
If IPv6 is supported assert that Pion can connect via it.

Resolves #1315
2025-04-09 12:11:46 -04:00
Joe Turki
740e5166c5 Update lint rules, force testify/assert for tests
Use testify's assert package instead of the standard library's testing
package.
2025-03-27 12:08:37 +02:00
Sean DuBois
46565ffd95 Cleanup PeerConnection in WriteRTCP Test
Relates to #3032
2025-02-11 14:21:32 -05:00
Sean DuBois
ae260d4eeb Assert that WriteRTCP works before connected
Resolves #3032
2025-02-11 14:10:45 -05: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
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
Nils Ohlmeier
2fd3640fa3 Only collect single fingerprints/ICE credentials
The way currently DTLS fingerprints and ICE credentials
are picked is causing interop issues as described in #2621

Peers which don't use Bundle can use different fingerprints
and credentials in each media section. Even though is
not (yet) supported by Pion, receiving an SDP offer from
such a peer is valid.

Additionally if Bundle is being used the group attribute
determines which media section is the master bundle section,
which establishes the transport. Currently Pion always
just uses the first credentials/fingerprint it can find
in the SDP, which results in not spec compliant behavior.

This PR attempts to fix the above issues and make
Pion more spec compliant and interoperable.

Fixes #2621
2024-11-13 23:44:00 -05:00
Sean DuBois
ae89317088 Test that NULL Protection Profile is disabled
Resolves pion/srtp#297
2024-10-27 23:13:43 -04:00
Sean DuBois
5637661fef Add E2E Test for RTX
Assert that generation of NACKs and sending of RTX operates as expected.
2024-10-05 01:05:12 -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
Sean DuBois
9c6604df0a Drop calls to RegisterDefaultCodecs in tests
Not needed anymore
2024-07-18 16:14:23 -04:00
Sean DuBois
e17ce04589 Revert 7c8bfbd44a and add test
Don't block Close on spawned goroutines
2024-07-15 11:26:21 -04:00
Eric Daniels
1bb9fa9020 Make onNegotiationNeeded conform to spec
- Removes non-canon logic
2024-06-24 11:03:40 -04:00
Eric Daniels
ca05618c7f Reset state machine after negotiationNeededOp
- Fixes #2774
2024-06-11 13:49:06 -04:00
Sean DuBois
fda6c4f836 Fix linter errors
golangci-lint upgrade to v1.56.2 added more checks

Relates to pion/.goassets#201
2024-03-16 21:09:38 -04:00
Sean DuBois
5cf4168432 Fix OnICEGatheringStateChange Signature
Return ICEGatheringState not ICEGathererState

Relates to #2557
2023-09-11 14:32:23 -04:00
Sean DuBois
dc4b591c4d Start pion/webrtc/v4
60eea43 is a breaking change
2023-09-05 11:48:14 -04:00
renovate[bot]
ea23dec2b9 Update module transport, srtp, ice and turn
ReplayDetector introduced a breaking change
2023-09-03 23:59:43 -04:00
Pouget-Abadie
1210046255 Upgrading pion/ice dependency 2023-05-14 21:42:24 -04:00
Steffen Vogel
683fc837d0 Make repo REUSE compliant 2023-05-05 11:58:49 -04:00
cnderrauber
220b1f37ee Refine updateConnectionState
Make updateConnectionState consistent with
https://www.w3.org/TR/webrtc/#rtcpeerconnectionstate-enum
2023-03-03 15:35:49 +08:00
Sean DuBois
43d0c5b9b0 Make Transceiver Negotation more consistent
Today a remote `recvonly` transceiver can be satisfied by a `sendonly`
or `sendrecv` transceiver. However a remote `sendonly` transceiver can
only be satisfied by a `recvonly` transceiver.

This PR updates the answer handling code to be more consistent.
2023-02-09 21:39:18 -05:00
Steffen Vogel
eafdc7742a Use new pion/transport Net interface
This change adapts pion/ice to use a new interface for most network
related operations. The interface was formerly a simple struct vnet.Net
which was originally intended to facilicate testing. By replacing it
with an interface we have greater flexibility and allow users to hook
into the networking stack by providing their own implementation of
the interface.
2023-02-09 09:39:33 +01:00
Pion
c1467e4871 Update CI configs to v0.7.2
Update lint scripts and CI configs.
2022-04-27 23:00:19 -04:00
boks1971
8796a5c5a7 Use ICE role to set DTLS role in answer
When creating answer, check ICE role while determining DTLS role.
ORTC thread on how roles are set
https://github.com/w3c/ortc/issues/167#issuecomment-69409953

When remote is ice-lite and there is no answering role set,
the answer uses the default which is DTLS client. So 'setup'
is set as 'active' and answer sent.

But, when DTLS transport is started, it checks the ICE role
and sets itself as DTLS server (because remote is lite
and hence local agent becomes controlling ICE agent).

So, both sides end up being DTLS server and nobody sends
client hello.
2022-02-02 12:33:59 -05:00
Sean DuBois
157220e800 Run gofmt to add new build constraints
Also remove some 1.13 specific WASM code
2022-01-17 22:36:01 -05:00
Len
425f5c6cef Handle implicitly created inactive transceiver
If SetRemoteDescription is called with offer SDP which
has a=invalid, PeerConnection sets its transceiver direction
as recvonly. Fix direction recvonly to invalid.

Resolves #2050
2021-12-28 20:22:36 -05:00
Sean DuBois
6160e8033f Handle unknown ICE Candidate Transport
rfc8839#section-5.1 specifies that a WebRTC Agent MUST
ignore any name/value pairs it doesn't understand. When
we parse a candidate and it fails because we don't understand
the type we now log and continue.

Resolves pion/webrtc#1949
2021-12-15 15:58:48 -05:00
Sean DuBois
2699584e9a Handle unknown ICE Candidate Type
rfc8839#section-5.1 specifies that a WebRTC Agent MUST
ignore any name/value pairs it doesn't understand. When
we parse a candidate and it fails because we don't understand
the type we now log and continue.

Resolves pion/webrtc#1949
2021-12-15 13:37:34 -05:00
Renovate Bot
99452111ba Update module github.com/pion/ice/v2 to v2.1.14
Generated by renovateBot
2021-11-16 12:55:40 -05:00
cnderrauber
635bfd9cad Set prefer codec created by remote sdp
If a transceiver is created by remote sdp, then set
prefer codec same as offer peer.
For pion's codec match, it will use exact match
first, and then partial match. If patial match
only, the partial match codecs will become
negotiated codes. So it will be set prefer codec
when only exist partial match. And has same payload.

Add test cast for this.

refer to https://www.w3.org/TR/webrtc/#bib-rfc8829
2021-11-12 14:05:33 +08:00
digitalix
f93ea80d85 Revert "Make RTPTransceiver Stopped an atomic"
This reverts commit 6c3620093d.
This commit would cause sender.ReadRTCP() to never return
even when pc associated with this sender was closed.
The aftermath is leaked goroutines that will never stop.
2021-09-24 18:46:42 +01:00
Sean DuBois
6c3620093d Make RTPTransceiver Stopped an atomic
Add an accessor to make getting value easy. Also add
TestPeerConnection_SkipStoppedTransceiver. This commit also cleans
up RTPTransceiver creation. We used a helper function, when we should
have just used the provide constructor
2021-09-04 15:15:36 -04:00
Sean DuBois
8cbcb571c2 Use constants for MimeType
Replace VP8/H264/Opus string usage
2021-08-25 21:41:49 -04:00
Sean DuBois
0735efd344 Throw error earlier for RTPSender with no codecs
It isn't possible to send media if a MediaEngine has no codecs. This
catches a common misconfiguration issues that users find themselves in.

Resolves #1702
2021-08-15 07:54:53 -04:00
Sean DuBois
cffa6afc34 Rollback pion/rtp to v0
Resolves #1908
2021-08-02 18:05:45 -04:00
Sean DuBois
a67c66a0c5 Upgrade pion/rtp to v2
Also updates interceptor and srtp
2021-07-29 11:18:41 -04:00
Juliusz Chroboczek
ee255e8956 Avoid crash after a PC callback has been reset
We used to crash if a PC callback was reset, due to confusion
between a nil interface and an interface whose value is nil.

Fixes #1871
2021-07-07 10:28:26 -04:00
digitalix
7948437b0b Fixed deadlock in peerconnection.go
In some rare cases during ice connection stage
change may result in deadlock. This fix makes
iceConnectionState and connectionState atomic
which should prevent deadlock.
2021-06-20 14:50:43 -04:00
Markus Tzoe
fb4b5826ae Fixes SDP session id
SDP session id should stay unchanged for subsequent offers/answers
2021-04-15 06:19:26 +08:00
Markus Tzoe
a0b3117680 RtpTransceiverInit => RTPTransceiverInit
since RtpTransceiverInit is deprecated
2021-04-15 06:19:26 +08:00
aler9
ae0f74edff Set answer as sendonly in case of a recvonly offer
When a local peer connection has a single transceiver with a sendrecv
direction, and the remote has a transceiver with a recvonly direction,
the local peer connection must change the transceiver direction to
sendonly.

When a local peer connection has a single transceiver with a recvonly
direction, and the remote has a transceiver with a recvonly direction,
the local peer connection must create another transceiver with a
sendonly direction.

A unit test is added to cover all possible cases.
2021-02-22 15:23:27 -08:00