Skip to content

Commit

Permalink
Fix async requests to Producer
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Aug 22, 2022
1 parent f251129 commit a9af245
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions cmd/streams/producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package streams

import (
"github.com/AlexxIT/go2rtc/pkg/streamer"
"sync"
)

type state byte
Expand All @@ -21,9 +22,13 @@ type Producer struct {
tracks []*streamer.Track

state state
mx sync.Mutex
}

func (p *Producer) GetMedias() []*streamer.Media {
p.mx.Lock()
defer p.mx.Unlock()

if p.state == stateNone {
log.Debug().Str("url", p.url).Msg("[streams] probe producer")

Expand All @@ -41,6 +46,9 @@ func (p *Producer) GetMedias() []*streamer.Media {
}

func (p *Producer) GetTrack(media *streamer.Media, codec *streamer.Codec) *streamer.Track {
p.mx.Lock()
defer p.mx.Unlock()

if p.state == stateMedias {
p.state = stateTracks
}
Expand All @@ -61,6 +69,9 @@ func (p *Producer) GetTrack(media *streamer.Media, codec *streamer.Codec) *strea
// internals

func (p *Producer) start() {
p.mx.Lock()
defer p.mx.Unlock()

if p.state != stateTracks {
return
}
Expand All @@ -72,6 +83,8 @@ func (p *Producer) start() {
}

func (p *Producer) stop() {
p.mx.Lock()

log.Debug().Str("url", p.url).Msg("[streams] stop producer")

if p.element != nil {
Expand All @@ -82,4 +95,6 @@ func (p *Producer) stop() {
}
p.tracks = nil
p.state = stateNone

p.mx.Unlock()
}

0 comments on commit a9af245

Please sign in to comment.