rtsp: fixup sdp media type returned by TP-LINK camera

Related: https://github.com/aler9/mediamtx/issues/990
This commit is contained in:
Yousong Zhou
2023-04-07 17:23:24 +08:00
parent af79e6054b
commit cf6a35d0c7
2 changed files with 13 additions and 6 deletions

View File

@@ -1,6 +1,10 @@
package rtsp package rtsp
import ( import (
"net"
"net/url"
"strings"
"github.com/AlexxIT/go2rtc/cmd/app" "github.com/AlexxIT/go2rtc/cmd/app"
"github.com/AlexxIT/go2rtc/cmd/streams" "github.com/AlexxIT/go2rtc/cmd/streams"
"github.com/AlexxIT/go2rtc/pkg/core" "github.com/AlexxIT/go2rtc/pkg/core"
@@ -8,9 +12,6 @@ import (
"github.com/AlexxIT/go2rtc/pkg/rtsp" "github.com/AlexxIT/go2rtc/pkg/rtsp"
"github.com/AlexxIT/go2rtc/pkg/tcp" "github.com/AlexxIT/go2rtc/pkg/tcp"
"github.com/rs/zerolog" "github.com/rs/zerolog"
"net"
"net/url"
"strings"
) )
func Init() { func Init() {
@@ -123,6 +124,7 @@ func rtspHandler(url string) (core.Producer, error) {
if !backchannel { if !backchannel {
return nil, err return nil, err
} }
log.Trace().Msgf("[rtsp] describe (backchannel=%t) err: %v", backchannel, err)
// second try without backchannel, we need to reconnect // second try without backchannel, we need to reconnect
conn.Backchannel = false conn.Backchannel = false

View File

@@ -2,14 +2,15 @@ package rtsp
import ( import (
"bytes" "bytes"
"github.com/AlexxIT/go2rtc/pkg/core"
"github.com/pion/rtcp"
"github.com/pion/sdp/v3"
"io" "io"
"net/url" "net/url"
"regexp" "regexp"
"strconv" "strconv"
"strings" "strings"
"github.com/AlexxIT/go2rtc/pkg/core"
"github.com/pion/rtcp"
"github.com/pion/sdp/v3"
) )
type RTCP struct { type RTCP struct {
@@ -35,6 +36,10 @@ func UnmarshalSDP(rawSDP []byte) ([]*core.Media, error) {
rawSDP = append([]byte(sdpHeader), rawSDP[i:]...) rawSDP = append([]byte(sdpHeader), rawSDP[i:]...)
} }
// Fix invalid media type (errSDPInvalidValue) caused by
// some TP-LINK IP camera, e.g. TL-IPC44GW
rawSDP = bytes.ReplaceAll(rawSDP, []byte("m=application/TP-LINK "), []byte("m=application "))
if err == io.EOF { if err == io.EOF {
rawSDP = append(rawSDP, '\n') rawSDP = append(rawSDP, '\n')
} }