Skip to content

Commit

Permalink
Code refactoring for UnmarshalSDP
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Nov 1, 2024
1 parent 3f5f132 commit 1d1bcb0
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions pkg/rtsp/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ func UnmarshalSDP(rawSDP []byte) ([]*core.Media, error) {
sd := &sdp.SessionDescription{}
if err := sd.Unmarshal(rawSDP); err != nil {
// fix multiple `s=` https://github.com/AlexxIT/WebRTC/issues/417
re, _ := regexp.Compile("\ns=[^\n]+")
rawSDP = re.ReplaceAll(rawSDP, nil)
rawSDP = regexp.MustCompile("\ns=[^\n]+").ReplaceAll(rawSDP, nil)

// fix SDP header for some cameras
if i := bytes.Index(rawSDP, []byte("\nm=")); i > 0 {
Expand All @@ -38,12 +37,11 @@ func UnmarshalSDP(rawSDP []byte) ([]*core.Media, error) {

// Fix invalid media type (errSDPInvalidValue) caused by
// some TP-LINK IP camera, e.g. TL-IPC44GW
m := regexp.MustCompile("m=[^ ]+ ")
for _, i := range m.FindAll(rawSDP, -1) {
switch string(i[2 : len(i)-1]) {
for _, b := range regexp.MustCompile("m=[^ ]+ ").FindAll(rawSDP, -1) {
switch string(b[2 : len(b)-1]) {
case "audio", "video", "application":
default:
rawSDP = bytes.Replace(rawSDP, i, []byte("m=application "), 1)
rawSDP = bytes.Replace(rawSDP, b, []byte("m=application "), 1)
}
}

Expand Down

0 comments on commit 1d1bcb0

Please sign in to comment.