Skip to content

Commit

Permalink
Merge pull request #1 from kira1928/pr-675
Browse files Browse the repository at this point in the history
  • Loading branch information
Joftal authored Feb 18, 2024
2 parents 3ebb602 + 9bef94a commit a0ea72a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
19 changes: 13 additions & 6 deletions src/pkg/parser/ffmpeg/ffmpeg.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bufio"
"bytes"
"context"
"fmt"
"io"
"net/url"
"os"
Expand Down Expand Up @@ -187,13 +188,19 @@ func (p *Parser) ParseLiveStream(ctx context.Context, url *url.URL, live live.Li
return nil
}

func (p *Parser) Stop() error {
func (p *Parser) Stop() (err error) {
p.closeOnce.Do(func() {
if p.cmdStdIn != nil && p.cmd.Process != nil && p.cmd.ProcessState == nil {
if _, err := p.cmdStdIn.Write([]byte("q")); err != nil {
log.Printf("Error sending stop command to ffmpeg: %v", err)
}
if p.cmd.ProcessState == nil {
if p.cmdStdIn != nil && p.cmd.Process != nil {
if _, err = p.cmdStdIn.Write([]byte("q")); err != nil {
err = fmt.Errorf("error sending stop command to ffmpeg: %v", err)
}
} else if p.cmdStdIn == nil {
err = fmt.Errorf("p.cmdStdIn == nil")
} else if p.cmd.Process == nil {
err = fmt.Errorf("p.cmd.Process == nil")
}
}
})
return nil
return err
}
8 changes: 6 additions & 2 deletions src/recorders/recorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,9 @@ func (r *recorder) setAndCloseParser(p parser.Parser) {
r.parserLock.Lock()
defer r.parserLock.Unlock()
if r.parser != nil {
r.parser.Stop()
if err := r.parser.Stop(); err != nil {
r.getLogger().WithError(err).Warn("failed to end recorder")
}
}
r.parser = p
}
Expand All @@ -279,7 +281,9 @@ func (r *recorder) Close() {
}
close(r.stop)
if p := r.getParser(); p != nil {
p.Stop()
if err := p.Stop(); err != nil {
r.getLogger().WithError(err).Warn("failed to end recorder")
}
}
r.getLogger().Info("Record End")
r.ed.DispatchEvent(events.NewEvent(RecorderStop, r.Live))
Expand Down

0 comments on commit a0ea72a

Please sign in to comment.