Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix AddTrack transceiver reuse per W3C specs #1861

Open
wants to merge 1 commit into
base: v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion peerconnection.go
Expand Up @@ -1197,7 +1197,7 @@ func (pc *PeerConnection) AddTrack(track *Track) (*RTPSender, error) {

var transceiver *RTPTransceiver
for _, t := range pc.GetTransceivers() {
if !t.stopped && t.kind == track.Kind() && t.Sender() == nil {
if !t.stopped && t.kind == track.Kind() && t.Sender() == nil && t.usedToSend.Load() != true {
transceiver = t
break
}
Expand Down
5 changes: 5 additions & 0 deletions rtptransceiver.go
Expand Up @@ -14,6 +14,8 @@ type RTPTransceiver struct {
receiver atomic.Value // *RTPReceiver
direction atomic.Value // RTPTransceiverDirection

usedToSend atomic.Value // track if direction has never had a value of "sendrecv" or "sendonly"

stopped bool
kind RTPCodecType
}
Expand Down Expand Up @@ -89,6 +91,9 @@ func (t *RTPTransceiver) setReceiver(r *RTPReceiver) {
}

func (t *RTPTransceiver) setDirection(d RTPTransceiverDirection) {
if d == RTPTransceiverDirectionSendrecv || d == RTPTransceiverDirectionSendonly {
t.usedToSend.Store(true)
}
t.direction.Store(d)
}

Expand Down