|
|
|
@ -6,7 +6,6 @@ import ( |
|
|
|
"net" |
|
|
|
"net" |
|
|
|
"strings" |
|
|
|
"strings" |
|
|
|
"sync" |
|
|
|
"sync" |
|
|
|
"sync/atomic" |
|
|
|
|
|
|
|
"time" |
|
|
|
"time" |
|
|
|
|
|
|
|
|
|
|
|
"github.com/aler9/gortsplib" |
|
|
|
"github.com/aler9/gortsplib" |
|
|
|
@ -190,7 +189,6 @@ type path struct { |
|
|
|
conf *conf.PathConf |
|
|
|
conf *conf.PathConf |
|
|
|
name string |
|
|
|
name string |
|
|
|
wg *sync.WaitGroup |
|
|
|
wg *sync.WaitGroup |
|
|
|
stats *stats |
|
|
|
|
|
|
|
parent pathParent |
|
|
|
parent pathParent |
|
|
|
|
|
|
|
|
|
|
|
ctx context.Context |
|
|
|
ctx context.Context |
|
|
|
@ -234,7 +232,6 @@ func newPath( |
|
|
|
conf *conf.PathConf, |
|
|
|
conf *conf.PathConf, |
|
|
|
name string, |
|
|
|
name string, |
|
|
|
wg *sync.WaitGroup, |
|
|
|
wg *sync.WaitGroup, |
|
|
|
stats *stats, |
|
|
|
|
|
|
|
parent pathParent) *path { |
|
|
|
parent pathParent) *path { |
|
|
|
ctx, ctxCancel := context.WithCancel(parentCtx) |
|
|
|
ctx, ctxCancel := context.WithCancel(parentCtx) |
|
|
|
|
|
|
|
|
|
|
|
@ -248,7 +245,6 @@ func newPath( |
|
|
|
conf: conf, |
|
|
|
conf: conf, |
|
|
|
name: name, |
|
|
|
name: name, |
|
|
|
wg: wg, |
|
|
|
wg: wg, |
|
|
|
stats: stats, |
|
|
|
|
|
|
|
parent: parent, |
|
|
|
parent: parent, |
|
|
|
ctx: ctx, |
|
|
|
ctx: ctx, |
|
|
|
ctxCancel: ctxCancel, |
|
|
|
ctxCancel: ctxCancel, |
|
|
|
@ -431,10 +427,7 @@ outer: |
|
|
|
req.Res <- pathReaderSetupPlayRes{Err: fmt.Errorf("terminated")} |
|
|
|
req.Res <- pathReaderSetupPlayRes{Err: fmt.Errorf("terminated")} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for rp, state := range pa.readers { |
|
|
|
for rp := range pa.readers { |
|
|
|
if state == pathReaderStatePlay { |
|
|
|
|
|
|
|
atomic.AddInt64(pa.stats.CountReaders, -1) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
rp.close() |
|
|
|
rp.close() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -447,9 +440,6 @@ outer: |
|
|
|
source.close() |
|
|
|
source.close() |
|
|
|
pa.sourceStaticWg.Wait() |
|
|
|
pa.sourceStaticWg.Wait() |
|
|
|
} else if source, ok := pa.source.(publisher); ok { |
|
|
|
} else if source, ok := pa.source.(publisher); ok { |
|
|
|
if pa.sourceReady { |
|
|
|
|
|
|
|
atomic.AddInt64(pa.stats.CountPublishers, -1) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
source.close() |
|
|
|
source.close() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -634,7 +624,6 @@ func (pa *path) doReaderRemove(r reader) { |
|
|
|
state := pa.readers[r] |
|
|
|
state := pa.readers[r] |
|
|
|
|
|
|
|
|
|
|
|
if state == pathReaderStatePlay { |
|
|
|
if state == pathReaderStatePlay { |
|
|
|
atomic.AddInt64(pa.stats.CountReaders, -1) |
|
|
|
|
|
|
|
pa.stream.readerRemove(r) |
|
|
|
pa.stream.readerRemove(r) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -643,8 +632,6 @@ func (pa *path) doReaderRemove(r reader) { |
|
|
|
|
|
|
|
|
|
|
|
func (pa *path) doPublisherRemove() { |
|
|
|
func (pa *path) doPublisherRemove() { |
|
|
|
if pa.sourceReady { |
|
|
|
if pa.sourceReady { |
|
|
|
atomic.AddInt64(pa.stats.CountPublishers, -1) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if pa.isOnDemand() && pa.onDemandState != pathOnDemandStateInitial { |
|
|
|
if pa.isOnDemand() && pa.onDemandState != pathOnDemandStateInitial { |
|
|
|
pa.onDemandCloseSource() |
|
|
|
pa.onDemandCloseSource() |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
@ -738,8 +725,6 @@ func (pa *path) handlePublisherRecord(req pathPublisherRecordReq) { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
atomic.AddInt64(pa.stats.CountPublishers, 1) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
req.Author.onPublisherAccepted(len(req.Tracks)) |
|
|
|
req.Author.onPublisherAccepted(len(req.Tracks)) |
|
|
|
|
|
|
|
|
|
|
|
pa.sourceSetReady(req.Tracks) |
|
|
|
pa.sourceSetReady(req.Tracks) |
|
|
|
@ -758,8 +743,6 @@ func (pa *path) handlePublisherRecord(req pathPublisherRecordReq) { |
|
|
|
|
|
|
|
|
|
|
|
func (pa *path) handlePublisherPause(req pathPublisherPauseReq) { |
|
|
|
func (pa *path) handlePublisherPause(req pathPublisherPauseReq) { |
|
|
|
if req.Author == pa.source && pa.sourceReady { |
|
|
|
if req.Author == pa.source && pa.sourceReady { |
|
|
|
atomic.AddInt64(pa.stats.CountPublishers, -1) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if pa.isOnDemand() && pa.onDemandState != pathOnDemandStateInitial { |
|
|
|
if pa.isOnDemand() && pa.onDemandState != pathOnDemandStateInitial { |
|
|
|
pa.onDemandCloseSource() |
|
|
|
pa.onDemandCloseSource() |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
@ -815,7 +798,6 @@ func (pa *path) handleReaderSetupPlayPost(req pathReaderSetupPlayReq) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (pa *path) handleReaderPlay(req pathReaderPlayReq) { |
|
|
|
func (pa *path) handleReaderPlay(req pathReaderPlayReq) { |
|
|
|
atomic.AddInt64(pa.stats.CountReaders, 1) |
|
|
|
|
|
|
|
pa.readers[req.Author] = pathReaderStatePlay |
|
|
|
pa.readers[req.Author] = pathReaderStatePlay |
|
|
|
|
|
|
|
|
|
|
|
pa.stream.readerAdd(req.Author) |
|
|
|
pa.stream.readerAdd(req.Author) |
|
|
|
@ -827,7 +809,6 @@ func (pa *path) handleReaderPlay(req pathReaderPlayReq) { |
|
|
|
|
|
|
|
|
|
|
|
func (pa *path) handleReaderPause(req pathReaderPauseReq) { |
|
|
|
func (pa *path) handleReaderPause(req pathReaderPauseReq) { |
|
|
|
if state, ok := pa.readers[req.Author]; ok && state == pathReaderStatePlay { |
|
|
|
if state, ok := pa.readers[req.Author]; ok && state == pathReaderStatePlay { |
|
|
|
atomic.AddInt64(pa.stats.CountReaders, -1) |
|
|
|
|
|
|
|
pa.readers[req.Author] = pathReaderStatePrePlay |
|
|
|
pa.readers[req.Author] = pathReaderStatePrePlay |
|
|
|
pa.stream.readerRemove(req.Author) |
|
|
|
pa.stream.readerRemove(req.Author) |
|
|
|
} |
|
|
|
} |
|
|
|
|