Add currentDirection to RTPTransceiver

add currentDirection to RTPTransceiver, don't reuse
transceiver if its currentDirection is sendrecv or sendonly
This commit is contained in:
cnderrauber
2022-09-14 15:25:16 +08:00
committed by cnderrauber
parent 4e853582ca
commit 045df4c4bf
3 changed files with 125 additions and 10 deletions

View File

@@ -13,10 +13,11 @@ import (
// RTPTransceiver represents a combination of an RTPSender and an RTPReceiver that share a common mid.
type RTPTransceiver struct {
mid atomic.Value // string
sender atomic.Value // *RTPSender
receiver atomic.Value // *RTPReceiver
direction atomic.Value // RTPTransceiverDirection
mid atomic.Value // string
sender atomic.Value // *RTPSender
receiver atomic.Value // *RTPReceiver
direction atomic.Value // RTPTransceiverDirection
currentDirection atomic.Value // RTPTransceiverDirection
codecs []RTPCodecParameters // User provided codecs via SetCodecPreferences
@@ -38,6 +39,7 @@ func newRTPTransceiver(
t.setReceiver(receiver)
t.setSender(sender)
t.setDirection(direction)
t.setCurrentDirection(RTPTransceiverDirection(Unknown))
return t
}
@@ -160,6 +162,7 @@ func (t *RTPTransceiver) Stop() error {
}
t.setDirection(RTPTransceiverDirectionInactive)
t.setCurrentDirection(RTPTransceiverDirectionInactive)
return nil
}
@@ -179,6 +182,17 @@ func (t *RTPTransceiver) setDirection(d RTPTransceiverDirection) {
t.direction.Store(d)
}
func (t *RTPTransceiver) setCurrentDirection(d RTPTransceiverDirection) {
t.currentDirection.Store(d)
}
func (t *RTPTransceiver) getCurrentDirection() RTPTransceiverDirection {
if v, ok := t.currentDirection.Load().(RTPTransceiverDirection); ok {
return v
}
return RTPTransceiverDirection(Unknown)
}
func (t *RTPTransceiver) setSendingTrack(track TrackLocal) error {
if err := t.Sender().ReplaceTrack(track); err != nil {
return err