mirror of https://bitbucket.org/ausocean/av.git
Return from Noop lex routine
In the Noop lexer we start a routine that's responsible for output of the written frames at a consistent rate (to make certain destinations happy i.e. youtube). We weren't however returning from this in the case that the lexing function is returned, we'd therefore then be left with a hanging routine (this would eventually keep happening until stack overflow if had long enough runtime for the service; not a big deal for systemd services, but still crappy). So, now we create a context which is cancelled when when the lex function returns and can detect this in the output routine.
This commit is contained in:
parent
391db6b210
commit
b06969b6b6
|
@ -30,6 +30,7 @@ import (
|
|||
"io"
|
||||
"math"
|
||||
"time"
|
||||
"context"
|
||||
)
|
||||
|
||||
// ByteLexer is used to lex bytes using a buffer size which is configured upon construction.
|
||||
|
@ -127,13 +128,20 @@ func Noop(dst io.Writer, src io.Reader, d time.Duration) error {
|
|||
defer delay.Stop()
|
||||
|
||||
// This routine is responsible for frame output to rest of the pipeline.
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
go func() {
|
||||
for {
|
||||
err := rb.writeTo(dst)
|
||||
if err != nil && !errors.Is(err, errBuffChanReceiveTimeout) {
|
||||
errCh <- fmt.Errorf("could not write to dst: %w", err)
|
||||
}
|
||||
<-delay.C
|
||||
|
||||
select {
|
||||
case <-delay.C:
|
||||
case <-ctx.Done():
|
||||
return
|
||||
}
|
||||
|
||||
// Adjust delay using proportional controller.
|
||||
adj := coef * float64(target-rb.len())
|
||||
|
|
Loading…
Reference in New Issue