mirror of
https://github.com/bluenviron/mediamtx
synced 2025-03-05 20:07:40 +00:00
add read timeout to RTMP sources
This commit is contained in:
parent
da9d6df706
commit
f03ff73ef3
@ -432,6 +432,7 @@ func (pa *Path) startExternalSource() {
|
|||||||
} else if strings.HasPrefix(pa.conf.Source, "rtmp://") {
|
} else if strings.HasPrefix(pa.conf.Source, "rtmp://") {
|
||||||
pa.source = sourcertmp.New(
|
pa.source = sourcertmp.New(
|
||||||
pa.conf.Source,
|
pa.conf.Source,
|
||||||
|
pa.readTimeout,
|
||||||
&pa.sourceWg,
|
&pa.sourceWg,
|
||||||
pa.stats,
|
pa.stats,
|
||||||
pa)
|
pa)
|
||||||
|
@ -38,6 +38,7 @@ type Parent interface {
|
|||||||
// Source is a RTMP source.
|
// Source is a RTMP source.
|
||||||
type Source struct {
|
type Source struct {
|
||||||
ur string
|
ur string
|
||||||
|
readTimeout time.Duration
|
||||||
wg *sync.WaitGroup
|
wg *sync.WaitGroup
|
||||||
stats *stats.Stats
|
stats *stats.Stats
|
||||||
parent Parent
|
parent Parent
|
||||||
@ -48,11 +49,13 @@ type Source struct {
|
|||||||
|
|
||||||
// New allocates a Source.
|
// New allocates a Source.
|
||||||
func New(ur string,
|
func New(ur string,
|
||||||
|
readTimeout time.Duration,
|
||||||
wg *sync.WaitGroup,
|
wg *sync.WaitGroup,
|
||||||
stats *stats.Stats,
|
stats *stats.Stats,
|
||||||
parent Parent) *Source {
|
parent Parent) *Source {
|
||||||
s := &Source{
|
s := &Source{
|
||||||
ur: ur,
|
ur: ur,
|
||||||
|
readTimeout: readTimeout,
|
||||||
wg: wg,
|
wg: wg,
|
||||||
stats: stats,
|
stats: stats,
|
||||||
parent: parent,
|
parent: parent,
|
||||||
@ -170,6 +173,9 @@ func (s *Source) runInner() bool {
|
|||||||
var audioRTCPSender *rtcpsender.RTCPSender
|
var audioRTCPSender *rtcpsender.RTCPSender
|
||||||
var aacEncoder *rtpaac.Encoder
|
var aacEncoder *rtpaac.Encoder
|
||||||
|
|
||||||
|
// configuration must be completed within readTimeout
|
||||||
|
nconn.SetReadDeadline(time.Now().Add(s.readTimeout))
|
||||||
|
|
||||||
confDone := make(chan error)
|
confDone := make(chan error)
|
||||||
go func() {
|
go func() {
|
||||||
confDone <- func() error {
|
confDone <- func() error {
|
||||||
@ -331,6 +337,7 @@ func (s *Source) runInner() bool {
|
|||||||
go func() {
|
go func() {
|
||||||
readerDone <- func() error {
|
readerDone <- func() error {
|
||||||
for {
|
for {
|
||||||
|
nconn.SetReadDeadline(time.Now().Add(s.readTimeout))
|
||||||
pkt, err := conn.ReadPacket()
|
pkt, err := conn.ReadPacket()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
Loading…
Reference in New Issue
Block a user