Skip to content

Commit

Permalink
Refactor SDP offer/answer.
Browse files Browse the repository at this point in the history
  • Loading branch information
dennwc committed Nov 18, 2024
1 parent 5a05221 commit 82e85df
Show file tree
Hide file tree
Showing 8 changed files with 346 additions and 246 deletions.
45 changes: 45 additions & 0 deletions pkg/media/sdp/helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright 2024 LiveKit, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package sdp

import (
"net/netip"

"github.com/pion/sdp/v3"
)

func GetAudio(s *sdp.SessionDescription) *sdp.MediaDescription {
for _, m := range s.MediaDescriptions {
if m.MediaName.Media == "audio" {
return m
}
}
return nil
}

func GetAudioDest(s *sdp.SessionDescription, audio *sdp.MediaDescription) netip.AddrPort {
if audio == nil || s == nil {
return netip.AddrPort{}
}
ci := s.ConnectionInformation
if ci == nil || ci.NetworkType != "IN" {
return netip.AddrPort{}
}
ip, err := netip.ParseAddr(ci.Address.Address)
if err != nil {
return netip.AddrPort{}
}
return netip.AddrPortFrom(ip, uint16(audio.MediaName.Port.Value))
}
Loading

0 comments on commit 82e85df

Please sign in to comment.