@@ -847,7 +847,31 @@ func (pc *PeerConnection) CreateAnswer(*AnswerOptions) (SessionDescription, erro
847847 if err != nil {
848848 return SessionDescription {}, err
849849 }
850-
850+ // remove inactive media sections
851+ var inactiveMidValue []string
852+ for _ , media := range d .MediaDescriptions {
853+ if media .MediaName .Media == mediaSectionApplication {
854+ continue
855+ }
856+ if media .MediaName .Port .Value == 0 {
857+ var midValue string
858+ var inactive bool
859+ for _ , attr := range media .Attributes {
860+ if attr .Key == sdp .AttrKeyInactive {
861+ inactive = true
862+ }
863+ if attr .Key == sdp .AttrKeyMID {
864+ midValue = attr .Value
865+ }
866+ }
867+ if inactive {
868+ inactiveMidValue = append (inactiveMidValue , midValue )
869+ }
870+ }
871+ }
872+ pc .mu .Lock ()
873+ pc .removeRTPTransceiver (inactiveMidValue )
874+ pc .mu .Unlock ()
851875 desc := SessionDescription {
852876 Type : SDPTypeAnswer ,
853877 SDP : string (sdpBytes ),
@@ -2264,6 +2288,31 @@ func (pc *PeerConnection) addRTPTransceiver(t *RTPTransceiver) {
22642288 pc .onNegotiationNeeded ()
22652289}
22662290
2291+ // removeRTPTransceiver remove inactive
2292+ // and fires onNegotiationNeeded;
2293+ // caller of this method should hold `pc.mu` lock
2294+ func (pc * PeerConnection ) removeRTPTransceiver (mids []string ) {
2295+ if len (mids ) == 0 {
2296+ return
2297+ }
2298+ n := 0
2299+ for _ , transceiver := range pc .rtpTransceivers {
2300+ needDelete := false
2301+ for _ , mid := range mids {
2302+ if transceiver .Mid () == mid {
2303+ transceiver .Stop ()
2304+ needDelete = true
2305+ }
2306+ }
2307+ if ! needDelete {
2308+ pc .rtpTransceivers [n ] = transceiver
2309+ n ++
2310+ }
2311+ }
2312+ pc .rtpTransceivers = pc .rtpTransceivers [:n ]
2313+ pc .onNegotiationNeeded ()
2314+ }
2315+
22672316// CurrentLocalDescription represents the local description that was
22682317// successfully negotiated the last time the PeerConnection transitioned
22692318// into the stable state plus any local candidates that have been generated
@@ -2628,7 +2677,16 @@ func (pc *PeerConnection) generateMatchedSDP(transceivers []*RTPTransceiver, use
26282677 mediaTransceivers := []* RTPTransceiver {t }
26292678
26302679 extensions , _ := rtpExtensionsFromMediaDescription (media )
2631- mediaSections = append (mediaSections , mediaSection {id : midValue , transceivers : mediaTransceivers , matchExtensions : extensions , rids : getRids (media )})
2680+ rejected := false
2681+ if media .MediaName .Port .Value == 0 {
2682+ for _ , attr := range media .Attributes {
2683+ if attr .Key == sdp .AttrKeyInactive {
2684+ rejected = true
2685+ break
2686+ }
2687+ }
2688+ }
2689+ mediaSections = append (mediaSections , mediaSection {id : midValue , transceivers : mediaTransceivers , matchExtensions : extensions , rids : getRids (media ), rejected : rejected })
26322690 }
26332691 }
26342692
0 commit comments