mirror of
https://github.com/pion/webrtc.git
synced 2025-12-24 11:51:03 +08:00
Move SDP code into dedicated file
Remove some duplication that makes re-negotiation harder. By splitting parsing of inbound SDP and creation of outbound it makes the next step a lot easier. Relates to #207
This commit is contained in:
@@ -52,3 +52,36 @@ func (t *RTPTransceiver) Stop() error {
|
||||
t.Direction = RTPTransceiverDirectionInactive
|
||||
return nil
|
||||
}
|
||||
|
||||
// Given a direction+type pluck a transceiver from the passed list
|
||||
// if no entry satisfies the requested type+direction return a inactive Transceiver
|
||||
func satisfyTypeAndDirection(remoteKind RTPCodecType, remoteDirection RTPTransceiverDirection, localTransceivers []*RTPTransceiver) (*RTPTransceiver, []*RTPTransceiver) {
|
||||
// Get direction order from most preferred to least
|
||||
getPreferredDirections := func() []RTPTransceiverDirection {
|
||||
switch remoteDirection {
|
||||
case RTPTransceiverDirectionSendrecv:
|
||||
return []RTPTransceiverDirection{RTPTransceiverDirectionRecvonly, RTPTransceiverDirectionSendrecv}
|
||||
case RTPTransceiverDirectionSendonly:
|
||||
return []RTPTransceiverDirection{RTPTransceiverDirectionRecvonly, RTPTransceiverDirectionSendrecv}
|
||||
case RTPTransceiverDirectionRecvonly:
|
||||
return []RTPTransceiverDirection{RTPTransceiverDirectionSendonly, RTPTransceiverDirectionSendrecv}
|
||||
}
|
||||
return []RTPTransceiverDirection{}
|
||||
}
|
||||
|
||||
for _, possibleDirection := range getPreferredDirections() {
|
||||
for i := range localTransceivers {
|
||||
t := localTransceivers[i]
|
||||
if t.kind != remoteKind || possibleDirection != t.Direction {
|
||||
continue
|
||||
}
|
||||
|
||||
return t, append(localTransceivers[:i], localTransceivers[i+1:]...)
|
||||
}
|
||||
}
|
||||
|
||||
return &RTPTransceiver{
|
||||
kind: remoteKind,
|
||||
Direction: RTPTransceiverDirectionInactive,
|
||||
}, localTransceivers
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user