Commit Graph

320 Commits

Author SHA1 Message Date
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
digitalix
06a5a14197 Fixes issue 1822
Previously we could have situations where during
first condition like `transceiver.Sender() != nil`
there would be another condition like
`transceiver.Sender().isNegotiated()` where
`.Sender()` could become nil if changed in
a different goroutine.
2021-08-03 11:39:46 -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
aggresss
7b7183eb5a Fix RTPSender's streamInfo miss headerExtensions
Fix transceiver.Sender().Send() not contain HeaderExtensions.
2021-07-01 10:14:06 -04:00
digitalix
f524fea32a Implement SetCodecPreferences in RTPTransceiver
This allows to set supported codecs per transceiver.

Resolves #1847
2021-06-28 10:54:31 -04:00
digitalix
f8a8c09949 Support PayloadTypes changing a TrackRemote
If the PayloadType changes for a SSRC update the codec on the
TrackRemote.

Resolves #1850
2021-06-27 14:44:02 -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
b6ca48ea6d PeerConnection: more thread-safe
now proctected by lock:
	- CreateOffer
	- CreateAnswer
	- AddTransceiverFromKind
	- AddTransceiverFromTrack

newRTPTransceiver is no longer a PeerConnection method;
pc.addRTPTransceiver would fire onNegotiationNeeded;
pc.AddTrack, pc.RemoveTrack now hold lock for the entire function;

Fixes TestNegotiationNeededStressOneSided() by waiting til all
tracks added to pcA and the negotiation completed
2021-04-23 11:12:48 +08:00
Sean DuBois
91a12e8cfb Hold lock when accessing remote description
CurrentRemoteDescription and PendingRemoteDescription both access
members of the PeerConnection that should be protected by a lock.

Co-authored-by: Markus Tzoe <chou.marcus@gmail.com>
2021-04-17 11:32:30 +08:00
Markus Tzoe
a1380456a8 Fixes peerconnection: potential deadlock
in CurrentLocalDescription() or PendingLocalDescription():
when gathering local candidates in populateLocalCandidates(),
agent would try submitting a task via run():

	a.chanTask <- task

the chanTask is consumed by a bg routine using taskLoop():

	for {
		select {
		case <-a.done:
			return
		case t := <-a.chanTask:
			t.fn(a.context(), a)
			close(t.done)
			after()
		}
	}

while there're other routines using the agent, e.g. calling
`agent.updateConnectionState()`

	a.afterRun(func(ctx context.Context) {
		a.chanState <- newState
	})

and the submitted task would be run by the `after()` func in
`taskLoop()`, where the `a.chanState` is handled by
`agent.startOnConnectionStateChangeRoutine()`

this `after()` task may block the bg routine when there's ongoing
event handler `agent.onConnectionStateChange()`, which would
eventually call PeerConnection's onICEConnectionStateChange():

	pc.mu.Lock()
	pc.iceConnectionState = cs
	handler := pc.onICEConnectionStateChangeHandler
	pc.mu.Unlock()

which would try to hold the PeerConnection lock, causing deadlock
2021-04-16 20:00:35 -07: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
Tomek
9b859870c0 Implement WASM Media methods
Add AddTransceiverFromKind and GetTransceivers. This doesn't support
everything, but enough to at least build a recvonly experience.

Resolves #500
2021-04-12 18:55:56 -07:00
Markus Tzoe
56ef4b73c5 PeerConnection: make AddTrack thread-safe
Use fine granularity rw-mutex to protect rtpTransceivers and for
exclusively accessing AddTrack and RemoveTrack

Fixes `shouldAddCandidates` typo in sdp.go
2021-04-03 10:51:19 -07:00
OrlandoCo
e1c6662934 Add WriteRTCP method to DTLSTransport
This will make possible to WriteRTCP using ORTC API
2021-03-31 20:56:09 -07:00
Jerko Steiner
6465248f1e Fixes for pre-added recvonly transceivers
Which were previously unable to:

1. have a sending track set to them, or
2. receive a track after renegotiation.

I'm not 100% sure if this covers all cases where a track is added and
removed and then added again. BUT IIRC there was a change that did not
allow transceiver reuse after a track was removed from it. Again, not
100% sure.

Fixes #1722.
2021-03-21 11:50:52 +01: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
donotanswer
8e8567040c Update ice-lite remote check to ignore whitespace
When parsing SDP, ice-lite attributes with whitespaces
were parsed incorrectly. This fix trims whitespaces.
2021-02-19 09:10:28 -08:00
Sean DuBois
8902641f91 Fix MediaEngine Copy
Copy the entire API. Since the MediaEngine is a pointer that would
destroy the MediaEngine that is used by other PeerConnections

Relates to #1662
2021-02-09 22:39:13 -08:00
Sean DuBois
c8b7aa386a Disable MediaEngine Copy by Default
If an API is shared between PeerConnections they would use the same
MediaEngine. A MediaEngine contains negotiated PayloadTypes so if the
PeerConnections were answering you would end up in invalid states.

Add DisableMediaEngineCopy to SettingEngine in case user needs old
behavior.

Resolves #1662
2021-02-09 21:31:57 -08:00
Juliusz Chroboczek
16407672bd Avoid infinite loop in CreateOffer
If the local description keeps getting changed, or in case of a but
in Pion, CreateOffer never terminates, which could cause client software
to hang.  Set an arbitrary bound on the number of iterations.

Relates to #1656
2021-02-03 08:50:38 -08:00
decanus
e3ec4024ba Expose NewSDPType
Allows a user to easily marshal a string to SDPType
2021-01-09 14:51:22 -08:00
Juliusz Chroboczek
de913a99a8 Improve documentation of NewPeerConnection
It is important to mention that, unlike API.NewPeerConnection, this
registers default interceptors.
2020-12-23 17:41:20 -08:00
tarrencev
a54b74cdb7 Update pion/interceptor for NACKs
Generate + Respond interceptors
2020-12-14 21:40:09 -08:00
Sean DuBois
67826b1914 Update Interceptors to use []byte based API
Also update test to assert Attributes get passed all the way through

Resolves pion/interceptor#14
2020-12-13 18:40:33 -08:00
ZHENK
3eb51d8a09 Pass nil candidate into pion/ice
Pass empty string candidate.Candidate into pion/ice to handle.

Co-authored-by: JooYoung <qkdlql@naver.com>

Resolves #1212
2020-12-09 16:17:17 -08:00
Sean DuBois
63401a8837 Store Accepted Simulcast in routine
pion/srtp requires that all incoming streams are accepted. You
can't close if you have unaccepted streams. At the same time
storeSimulcastStream blocks on taking the DTLSTransport lock.

Move `storeSimulcastStream` into a routine so that all streams can
be accepted and aren't blocked on taking the DTLSTransport lock.

Resolves #1586
2020-12-08 18:33:48 -08:00
Sean DuBois
70fb90c7fd Fix Simulcast routine leak
When a new SSRC is seen we start a Read loop for the packets. However if
we only see one packet this loop will just sit forever. If a user
doesn't send us enough packets to finish probing it will prevent any
subsequent streams from being probed.

Relates to #1345
2020-12-07 09:18:15 -08:00
Juliusz Chroboczek
0dea1f91e0 Fix RTPSendParameters
RTPSendParameters contains an array of encodings.
RTPSender.GetParameters returns RTPSendParameters.
2020-12-05 23:02:27 -08:00
Sean DuBois
3d9a7ede1a Allow extensions to be configured with direction
RegisterHeaderExtension now allows users to enable headers depending on
the type of transceiver that was created.

Also expose GetParameters on RTPSender and RTPReceiver

Co-authored-by: OrlandoCo <luisorlando.co@gmail.com>

Resolves #1554
2020-12-04 11:52:48 -08:00
Sean DuBois
9715626a0c Revert "Read/Write RTP/RTCP packets with context"
This change caused a ~24% performance decrease

Relates to pion/webrtc#1564

This reverts commit 47a7a64898.
2020-12-02 20:11:06 -08:00
Atsushi Watanabe
47a7a64898 Read/Write RTP/RTCP packets with context
Control cancel/timeout by context.
2020-12-01 11:08:48 +09:00
Sean DuBois
e32d766199 Improve TrackLocal error handling
* Return error to user when remote doesn't support codecs
* Assert that bindings are properly incremented/decremented
* Assert that a added track doesn't error even when disconnected

Relates to #1526
2020-11-27 23:07:29 -08:00
Adam Kiss
5bbc84e404 Implement Interceptors
Provide API so that handling around RTP can be easily defined by the
user. See the design doc here[0]

[0] https://github.com/pion/webrtc-v3-design/issues/34
2020-11-26 11:23:19 -08:00
Sean DuBois
00ec48af63 Don't run OnNegotiationNeeded if handler not set
Reduce the amount of code that is running if we don't need this.

Relates to #1494
2020-11-23 10:06:04 -08:00
Sidney San Martín
e1efa5d6f4 Compute an MSID to compare with the SDP
The MSID won't match the track's StreamID() on its own.
2020-11-22 22:35:51 -08:00
OrlandoCo
3333b65c01 Make WithMediaEngine to receive a pointer
These change will allow to use the MediaEngine outside Pion context
2020-11-18 10:56:29 -08:00
Sean DuBois
5498e93083 Fix dataChannelsRequested race
Take pc.sctpTransport lock before accessing
2020-11-16 14:27:51 -08:00
Sean DuBois
7edfb701e0 New Track API
The Pion WebRTC API has been dramatically redesigned. The design docs
are located here [0]

You can also read the release notes [1] on how to migrate your
application.

[0] https://github.com/pion/webrtc-v3-design
[1] https://github.com/pion/webrtc/wiki/Release-WebRTC@v3.0.0
2020-11-15 09:20:47 -08:00
tarrencev
78f7c978fe Safely mutate local description
adding candidates races with negotiation check
2020-11-03 00:22:41 -05:00
tarrencev
60db5090fc Fix: onnegotiationneeded handler race
Setting and calling the handler can race
2020-10-30 16:56:02 -04:00
OrlandoCo
3412dc6d95 Add SessionDescription Unmarshal helper
This will allow to re-use the internally parsed sdp, and prevent parsing multiple times and save some cpu cycles.
2020-10-25 00:33:08 -04:00
tarrencev
ebf2648686 hold lock for checkNegotiationNeeded transceiver checks 2020-10-23 17:47:50 -04:00
tarrencev
b97c9b436d fix(pc): set track on new transceiver 2020-10-23 17:47:50 -04:00
OrlandoCo
be1723bb9c Fix sender nil on negotiation check step 5.3.1 2020-10-20 18:26:54 -04:00
Sean DuBois
7fc6f5435b Stop discarding errors in setDescription
SetRemoteDescription was not properly returning errors. Fix and add test
to make sure we don't regress again in the future.

Resolves #1210
Resolves #1473
2020-10-15 22:23:09 -07:00
Sean DuBois
7b72d684e5 Handle Remote offer with inactive media section
If a remote Offer stops a mid make sure we
also stop the corresponding mid locally.

Resolves #1470
2020-10-08 15:58:34 -07:00
Sean DuBois
6970c88e2b Add SCTPTransport getter to PeerConnection
This is needed so users can use OnSelectedCandidatePairChange
for DataChannel use cases.

Resolves #713
2020-10-07 08:13:22 -07:00
Sean DuBois
804a12fed3 Update CI configs to v0.4.7
Update lint scripts and CI configs.
2020-09-30 09:06:34 -07:00
tarrencev
a0cc7bda99 Fix: Flakey OnNegotiationNeeded tests 2020-09-27 16:54:04 -07:00