Skip to content

Commit

Permalink
Add option for skipping RTP header size insufficient for extension er…
Browse files Browse the repository at this point in the history
…ror (#4)

Add option for skipping RTSP insufficient header error
  • Loading branch information
dnjooiopa authored Mar 18, 2024
1 parent 34d150f commit d18980b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
5 changes: 5 additions & 0 deletions internal/rtsp/custom.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package rtsp

var (
skipErrorRTPHeaderSizeInsufficient bool
)
20 changes: 15 additions & 5 deletions internal/rtsp/rtsp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
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"`
SkipErrorRTPHeaderSizeInsufficient *bool `yaml:"skip_error_rtp_header_size_insufficient"` // default to true
} `yaml:"rtsp"`
}

Expand All @@ -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)
Expand Down Expand Up @@ -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"
Expand Down
17 changes: 16 additions & 1 deletion pkg/rtsp/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net"
"net/url"
"strconv"
"strings"
"sync"
"time"

Expand All @@ -33,6 +34,9 @@ type Conn struct {
UserAgent string
URL *url.URL

// public custom
SkipErrorRTPHeaderSizeInsufficient bool

// internal

auth *tcp.Auth
Expand Down Expand Up @@ -70,6 +74,10 @@ const (
MethodRecord = "RECORD"
)

const (
errRTPHeaderSizeInsufficientForExtensionStr = "RTP header size insufficient for extension"
)

type State byte

func (s State) String() string {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit d18980b

Please sign in to comment.