From 25dd673c5759f7c29b8cb9cc660ea74f0d8eb0f7 Mon Sep 17 00:00:00 2001 From: Kittisak Phormraksa Date: Mon, 18 Mar 2024 14:54:27 +0700 Subject: [PATCH] Add option for skipping RTP header size insufficient for extension error (#4) Add option for skipping RTSP insufficient header error --- internal/rtsp/custom.go | 5 +++++ internal/rtsp/rtsp.go | 20 +++++++++++++++----- pkg/rtsp/conn.go | 17 ++++++++++++++++- 3 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 internal/rtsp/custom.go diff --git a/internal/rtsp/custom.go b/internal/rtsp/custom.go new file mode 100644 index 00000000..3adb840f --- /dev/null +++ b/internal/rtsp/custom.go @@ -0,0 +1,5 @@ +package rtsp + +var ( + skipErrorRTPHeaderSizeInsufficient bool +) diff --git a/internal/rtsp/rtsp.go b/internal/rtsp/rtsp.go index c5e21678..2d19f75a 100644 --- a/internal/rtsp/rtsp.go +++ b/internal/rtsp/rtsp.go @@ -17,11 +17,12 @@ import ( func Init() { var conf struct { Mod struct { - Listen string `yaml:"listen" json:"listen"` - Username string `yaml:"username" json:"-"` - Password string `yaml:"password" json:"-"` - DefaultQuery string `yaml:"default_query" json:"default_query"` - PacketSize uint16 `yaml:"pkt_size" json:"pkt_size,omitempty"` + Listen string `yaml:"listen" json:"listen"` + Username string `yaml:"username" json:"-"` + Password string `yaml:"password" json:"-"` + DefaultQuery string `yaml:"default_query" json:"default_query"` + PacketSize uint16 `yaml:"pkt_size" json:"pkt_size,omitempty"` + SkipErrorRTPHeaderSizeInsufficient *bool `yaml:"skip_error_rtp_header_size_insufficient"` // default to true } `yaml:"rtsp"` } @@ -34,6 +35,12 @@ func Init() { log = app.GetLogger("rtsp") + // Custom + skipErrorRTPHeaderSizeInsufficient = true + if conf.Mod.SkipErrorRTPHeaderSizeInsufficient != nil { + skipErrorRTPHeaderSizeInsufficient = *conf.Mod.SkipErrorRTPHeaderSizeInsufficient + } + // RTSP client support streams.HandleFunc("rtsp", rtspHandler) streams.HandleFunc("rtsps", rtspHandler) @@ -98,6 +105,9 @@ func rtspHandler(rawURL string) (core.Producer, error) { conn.Backchannel = true conn.UserAgent = app.UserAgent + // custom + conn.SkipErrorRTPHeaderSizeInsufficient = skipErrorRTPHeaderSizeInsufficient + if rawQuery != "" { query := streams.ParseQuery(rawQuery) conn.Backchannel = query.Get("backchannel") == "1" diff --git a/pkg/rtsp/conn.go b/pkg/rtsp/conn.go index e801b7e4..66317abb 100644 --- a/pkg/rtsp/conn.go +++ b/pkg/rtsp/conn.go @@ -8,6 +8,7 @@ import ( "net" "net/url" "strconv" + "strings" "sync" "time" @@ -33,6 +34,9 @@ type Conn struct { UserAgent string URL *url.URL + // public custom + SkipErrorRTPHeaderSizeInsufficient bool + // internal auth *tcp.Auth @@ -70,6 +74,10 @@ const ( MethodRecord = "RECORD" ) +const ( + errRTPHeaderSizeInsufficientForExtensionStr = "RTP header size insufficient for extension" +) + type State byte func (s State) String() string { @@ -239,7 +247,14 @@ func (c *Conn) Handle() (err error) { if channelID&1 == 0 { packet := &rtp.Packet{} if err = packet.Unmarshal(buf); err != nil { - return + // Skip for error RTP header size insufficient for extension + if c.SkipErrorRTPHeaderSizeInsufficient { + if !strings.Contains(err.Error(), errRTPHeaderSizeInsufficientForExtensionStr) { + return + } + } else { + return + } } for _, receiver := range c.receivers {