From 8aa109bf5be3e76b2c9cc3afe3be670de99eef3c Mon Sep 17 00:00:00 2001 From: Francisco Demartino Date: Thu, 24 Jun 2021 04:51:04 -0300 Subject: [PATCH] unseal gumbleffmpeg.Source --- gumbleffmpeg/source.go | 24 ++++++++++++------------ gumbleffmpeg/stream.go | 8 ++++---- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/gumbleffmpeg/source.go b/gumbleffmpeg/source.go index b892677..d56bbf6 100644 --- a/gumbleffmpeg/source.go +++ b/gumbleffmpeg/source.go @@ -8,9 +8,9 @@ import ( // Source is a Stream source. type Source interface { // must include the -i - arguments() []string - start(*exec.Cmd) error - done() + Arguments() []string + Start(*exec.Cmd) error + Done() } // sourceFile @@ -22,15 +22,15 @@ func SourceFile(filename string) Source { return sourceFile(filename) } -func (s sourceFile) arguments() []string { +func (s sourceFile) Arguments() []string { return []string{"-i", string(s)} } -func (sourceFile) start(*exec.Cmd) error { +func (sourceFile) Start(*exec.Cmd) error { return nil } -func (sourceFile) done() { +func (sourceFile) Done() { } // sourceReader @@ -44,16 +44,16 @@ func SourceReader(r io.ReadCloser) Source { return &sourceReader{r} } -func (*sourceReader) arguments() []string { +func (*sourceReader) Arguments() []string { return []string{"-i", "-"} } -func (s *sourceReader) start(cmd *exec.Cmd) error { +func (s *sourceReader) Start(cmd *exec.Cmd) error { cmd.Stdin = s.r return nil } -func (s *sourceReader) done() { +func (s *sourceReader) Done() { s.r.Close() } @@ -75,11 +75,11 @@ func SourceExec(name string, arg ...string) Source { } } -func (*sourceExec) arguments() []string { +func (*sourceExec) Arguments() []string { return []string{"-i", "-"} } -func (s *sourceExec) start(cmd *exec.Cmd) error { +func (s *sourceExec) Start(cmd *exec.Cmd) error { s.cmd = exec.Command(s.name, s.arg...) r, err := s.cmd.StdoutPipe() if err != nil { @@ -93,7 +93,7 @@ func (s *sourceExec) start(cmd *exec.Cmd) error { return nil } -func (s *sourceExec) done() { +func (s *sourceExec) Done() { if s.cmd != nil { if p := s.cmd.Process; p != nil { p.Kill() diff --git a/gumbleffmpeg/stream.go b/gumbleffmpeg/stream.go index 55a83bf..a7d919b 100644 --- a/gumbleffmpeg/stream.go +++ b/gumbleffmpeg/stream.go @@ -83,7 +83,7 @@ func (s *Stream) Play() error { return errors.New("gumbleffmpeg: nil source") } - args := s.Source.arguments() + args := s.Source.Arguments() if s.Offset > 0 { args = append([]string{"-ss", strconv.FormatFloat(s.Offset.Seconds(), 'f', -1, 64)}, args...) } @@ -94,11 +94,11 @@ func (s *Stream) Play() error { if err != nil { return err } - if err := s.Source.start(cmd); err != nil { + if err := s.Source.Start(cmd); err != nil { return err } if err := cmd.Start(); err != nil { - s.Source.done() + s.Source.Done() return err } s.wg.Add(1) @@ -194,7 +194,7 @@ func (s *Stream) cleanup() { } s.cmd.Process.Kill() s.cmd.Wait() - s.Source.done() + s.Source.Done() for len(s.pause) > 0 { <-s.pause }