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

Transceivers state change from inactive to active #2426

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion peerconnection.go
Original file line number Diff line number Diff line change
Expand Up @@ -1104,7 +1104,10 @@ func (pc *PeerConnection) SetRemoteDescription(desc SessionDescription) error {
}
_ = t.SetCodecPreferences(filteredCodecs)
}

case direction == RTPTransceiverDirectionSendonly:
if t.Direction() == RTPTransceiverDirectionInactive {
t.setDirection(RTPTransceiverDirectionRecvonly)
}
case direction == RTPTransceiverDirectionRecvonly:
if t.Direction() == RTPTransceiverDirectionSendrecv {
t.setDirection(RTPTransceiverDirectionSendonly)
Expand Down Expand Up @@ -1894,6 +1897,44 @@ func (pc *PeerConnection) AddTransceiverFromKind(kind RTPCodecType, init ...RTPT
return t, nil
}

// ReuseTransceiverFromTrack Reuse old RtpTransceiver or Create a new RtpTransceiver and adds it to the set of transceivers.
func (pc *PeerConnection) ReuseTransceiverFromTrack(track TrackLocal, init ...RTPTransceiverInit) (t *RTPTransceiver, err error) {
if pc.isClosed.get() {
return nil, &rtcerr.InvalidStateError{Err: ErrConnectionClosed}
}
pc.mu.Lock()
defer pc.mu.Unlock()
for _, t := range pc.rtpTransceivers {
currentDirection := t.getCurrentDirection()
if !t.stopped && t.kind == track.Kind() && currentDirection == RTPTransceiverDirectionInactive {
sender, err := pc.api.NewRTPSender(track, pc.dtlsTransport)
if err == nil {
err = t.SetSender(sender, track)
if err != nil {
_ = sender.Stop()
t.setSender(nil)
}
} else {
return nil, err
}
pc.onNegotiationNeeded()
return t, nil
}
}
direction := RTPTransceiverDirectionSendrecv
if len(init) > 1 {
return nil, errPeerConnAddTransceiverFromTrackOnlyAcceptsOne
} else if len(init) == 1 {
direction = init[0].Direction
}
t, err = pc.newTransceiverFromTrack(direction, track)
if err != nil {
return nil, err
}
pc.addRTPTransceiver(t)
return
}

// AddTransceiverFromTrack Create a new RtpTransceiver(SendRecv or SendOnly) and add it to the set of transceivers.
func (pc *PeerConnection) AddTransceiverFromTrack(track TrackLocal, init ...RTPTransceiverInit) (t *RTPTransceiver, err error) {
if pc.isClosed.get() {
Expand Down