fix(tracker): do not close Broker but rather just close the detector

This commit is contained in:
5684185+vsariola@users.noreply.github.com 2024-11-02 20:45:10 +02:00
parent 943073d0cc
commit 94058c2603
6 changed files with 12 additions and 8 deletions

View File

@ -70,6 +70,7 @@ func main() {
go func() {
trackerUi.Main()
audioCloser.Close()
detector.Close()
if *cpuprofile != "" {
pprof.StopCPUProfile()
f.Close()

View File

@ -135,6 +135,7 @@ func init() {
CloseFunc: func() {
t.Exec() <- func() { t.ForceQuit().Do() }
t.WaitQuitted()
detector.Close()
},
GetChunkFunc: func(isPreset bool) []byte {
retChn := make(chan []byte)

View File

@ -49,6 +49,7 @@ type (
// which gets executed in the detector goroutine.
MsgToDetector struct {
Reset bool
Quit bool
Data any // TODO: consider using a sum type here, for a bit more type safety. See: https://www.jerf.org/iri/post/2917/
}
)
@ -62,12 +63,6 @@ func NewBroker() *Broker {
}
}
func (b *Broker) Close() {
close(b.ToPlayer)
close(b.ToModel)
close(b.ToDetector)
}
// GetAudioBuffer returns an audio buffer from the buffer pool. The buffer is
// guaranteed to be empty. After using the buffer, it should be returned to the
// pool with PutAudioBuffer.

View File

@ -106,6 +106,9 @@ func (s *Detector) Run() {
s.loudnessDetector.reset()
s.peakDetector.reset()
}
if msg.Quit {
return
}
switch data := msg.Data.(type) {
case *sointu.AudioBuffer:
buf := *data
@ -144,6 +147,11 @@ func (s *Detector) Run() {
}
}
// Close may theoretically block if the broker is full, but it should not happen in practice
func (s *Detector) Close() {
s.broker.ToDetector <- MsgToDetector{Quit: true}
}
func makeLoudnessDetector(weighting WeightingType) loudnessDetector {
return loudnessDetector{
weighting: weightings[weighting],

View File

@ -166,7 +166,6 @@ func (t *Tracker) Main() {
w.Perform(system.ActionClose)
t.SaveRecovery()
t.quitWG.Done()
t.Broker().Close()
}
func eventLoop(w *app.Window, events chan<- event.Event, acks <-chan struct{}) {

View File

@ -265,7 +265,6 @@ func FuzzModel(f *testing.F) {
reader := bytes.NewReader(slice)
synther := vm.GoSynther{}
broker := tracker.NewBroker()
defer broker.Close()
model, player := tracker.NewModelPlayer(broker, synther, NullContext{}, "")
buf := make([][2]float32, 2048)
closeChan := make(chan struct{})
@ -309,5 +308,6 @@ func FuzzModel(f *testing.F) {
}
}
closeChan <- struct{}{}
broker.ToDetector <- tracker.MsgToDetector{Quit: true}
})
}