Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unseal gumbleffmpeg.Source #56

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions gumbleffmpeg/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
// Source is a Stream source.
type Source interface {
// must include the -i <filename>
arguments() []string
start(*exec.Cmd) error
done()
Arguments() []string
Start(*exec.Cmd) error
Done()
}

// sourceFile
Expand All @@ -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
Expand All @@ -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()
}

Expand All @@ -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 {
Expand All @@ -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()
Expand Down
8 changes: 4 additions & 4 deletions gumbleffmpeg/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
}
Expand All @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down