Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore muxer errors for hls #1554

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apidocs/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ components:
type: array
items:
type: string
hlsIgnoreMuxerErrors:
type: boolean

# WebRTC
webrtcDisable:
Expand Down
27 changes: 14 additions & 13 deletions internal/conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,19 +209,20 @@ type Conf struct {
RTMPServerCert string `json:"rtmpServerCert"`

// HLS
HLSDisable bool `json:"hlsDisable"`
HLSAddress string `json:"hlsAddress"`
HLSEncryption bool `json:"hlsEncryption"`
HLSServerKey string `json:"hlsServerKey"`
HLSServerCert string `json:"hlsServerCert"`
HLSAlwaysRemux bool `json:"hlsAlwaysRemux"`
HLSVariant HLSVariant `json:"hlsVariant"`
HLSSegmentCount int `json:"hlsSegmentCount"`
HLSSegmentDuration StringDuration `json:"hlsSegmentDuration"`
HLSPartDuration StringDuration `json:"hlsPartDuration"`
HLSSegmentMaxSize StringSize `json:"hlsSegmentMaxSize"`
HLSAllowOrigin string `json:"hlsAllowOrigin"`
HLSTrustedProxies IPsOrCIDRs `json:"hlsTrustedProxies"`
HLSDisable bool `json:"hlsDisable"`
HLSAddress string `json:"hlsAddress"`
HLSEncryption bool `json:"hlsEncryption"`
HLSServerKey string `json:"hlsServerKey"`
HLSServerCert string `json:"hlsServerCert"`
HLSAlwaysRemux bool `json:"hlsAlwaysRemux"`
HLSVariant HLSVariant `json:"hlsVariant"`
HLSSegmentCount int `json:"hlsSegmentCount"`
HLSSegmentDuration StringDuration `json:"hlsSegmentDuration"`
HLSPartDuration StringDuration `json:"hlsPartDuration"`
HLSSegmentMaxSize StringSize `json:"hlsSegmentMaxSize"`
HLSAllowOrigin string `json:"hlsAllowOrigin"`
HLSTrustedProxies IPsOrCIDRs `json:"hlsTrustedProxies"`
HLSIgnoreMuxerErrors bool `json:"hlsIgnoreMuxerErrors"`

// WebRTC
WebRTCDisable bool `json:"webrtcDisable"`
Expand Down
2 changes: 2 additions & 0 deletions internal/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ func (p *Core) createResources(initial bool) error {
p.conf.HLSSegmentMaxSize,
p.conf.HLSAllowOrigin,
p.conf.HLSTrustedProxies,
p.conf.HLSIgnoreMuxerErrors,
p.conf.ReadBufferCount,
p.pathManager,
p.metrics,
Expand Down Expand Up @@ -574,6 +575,7 @@ func (p *Core) closeResources(newConf *conf.Conf, calledByAPI bool) {
newConf.HLSPartDuration != p.conf.HLSPartDuration ||
newConf.HLSSegmentMaxSize != p.conf.HLSSegmentMaxSize ||
newConf.HLSAllowOrigin != p.conf.HLSAllowOrigin ||
newConf.HLSIgnoreMuxerErrors != p.conf.HLSIgnoreMuxerErrors ||
!reflect.DeepEqual(newConf.HLSTrustedProxies, p.conf.HLSTrustedProxies) ||
newConf.ReadBufferCount != p.conf.ReadBufferCount ||
closePathManager ||
Expand Down
28 changes: 24 additions & 4 deletions internal/core/hls_muxer.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type hlsMuxer struct {
segmentDuration conf.StringDuration
partDuration conf.StringDuration
segmentMaxSize conf.StringSize
ignoreMuxerErrors bool
readBufferCount int
wg *sync.WaitGroup
pathName string
Expand Down Expand Up @@ -96,6 +97,7 @@ func newHLSMuxer(
segmentDuration conf.StringDuration,
partDuration conf.StringDuration,
segmentMaxSize conf.StringSize,
ignoreMuxerErrors bool,
readBufferCount int,
req *hlsMuxerRequest,
wg *sync.WaitGroup,
Expand All @@ -115,6 +117,7 @@ func newHLSMuxer(
segmentDuration: segmentDuration,
partDuration: partDuration,
segmentMaxSize: segmentMaxSize,
ignoreMuxerErrors: ignoreMuxerErrors,
readBufferCount: readBufferCount,
wg: wg,
pathName: pathName,
Expand Down Expand Up @@ -371,7 +374,11 @@ func (m *hlsMuxer) setupVideoMedia(stream *stream) (*media.Media, format.Format)

err := m.muxer.WriteH26x(tdata.NTP, pts, tdata.AU)
if err != nil {
return fmt.Errorf("muxer error: %v", err)
if m.ignoreMuxerErrors {
m.log(logger.Error, "write h26x muxer error: %s", err)
} else {
return fmt.Errorf("muxer error: %v", err)
}
}

return nil
Expand Down Expand Up @@ -404,7 +411,11 @@ func (m *hlsMuxer) setupVideoMedia(stream *stream) (*media.Media, format.Format)

err := m.muxer.WriteH26x(tdata.NTP, pts, tdata.AU)
if err != nil {
return fmt.Errorf("muxer error: %v", err)
if m.ignoreMuxerErrors {
m.log(logger.Error, "write h26x muxer error: %s", err)
} else {
return fmt.Errorf("muxer error: %v", err)
}
}

return nil
Expand Down Expand Up @@ -446,7 +457,12 @@ func (m *hlsMuxer) setupAudioMedia(stream *stream) (*media.Media, format.Format)
time.Second/time.Duration(audioFormatMPEG4Audio.ClockRate()),
au)
if err != nil {
return fmt.Errorf("muxer error: %v", err)
if m.ignoreMuxerErrors {
m.log(logger.Error, "write audio muxer error: %s", err)
break
} else {
return fmt.Errorf("muxer error: %v", err)
}
}
}

Expand Down Expand Up @@ -479,7 +495,11 @@ func (m *hlsMuxer) setupAudioMedia(stream *stream) (*media.Media, format.Format)
pts,
tdata.Frame)
if err != nil {
return fmt.Errorf("muxer error: %v", err)
if m.ignoreMuxerErrors {
m.log(logger.Error, "muxer write audio error: %s", err)
} else {
return fmt.Errorf("muxer error: %v", err)
}
}

return nil
Expand Down
4 changes: 4 additions & 0 deletions internal/core/hls_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type hlsServer struct {
segmentMaxSize conf.StringSize
allowOrigin string
trustedProxies conf.IPsOrCIDRs
ignoreMuxerErrors bool
readBufferCount int
pathManager *pathManager
metrics *metrics
Expand Down Expand Up @@ -99,6 +100,7 @@ func newHLSServer(
segmentMaxSize conf.StringSize,
allowOrigin string,
trustedProxies conf.IPsOrCIDRs,
ignoreMuxerErrors bool,
readBufferCount int,
pathManager *pathManager,
metrics *metrics,
Expand Down Expand Up @@ -134,6 +136,7 @@ func newHLSServer(
segmentMaxSize: segmentMaxSize,
allowOrigin: allowOrigin,
trustedProxies: trustedProxies,
ignoreMuxerErrors: ignoreMuxerErrors,
readBufferCount: readBufferCount,
pathManager: pathManager,
parent: parent,
Expand Down Expand Up @@ -352,6 +355,7 @@ func (s *hlsServer) createMuxer(pathName string, remoteAddr string, req *hlsMuxe
s.segmentDuration,
s.partDuration,
s.segmentMaxSize,
s.ignoreMuxerErrors,
s.readBufferCount,
req,
&s.wg,
Expand Down
2 changes: 2 additions & 0 deletions rtsp-simple-server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ hlsAllowOrigin: '*'
# If the server receives a request from one of these entries, IP in logs
# will be taken from the X-Forwarded-For header.
hlsTrustedProxies: []
# instead of resetting the hls stream ignores packets where the muxer fails
hlsIgnoreMuxerErrors: no

###############################################
# WebRTC parameters
Expand Down