cleanup: Don't use a pointer for Video.pipe, it's an interface
Interfaces can already store nil, so we don't need a pointer to distinguish between unset and set.
This commit is contained in:
parent
68fe8618c6
commit
2e92f00374
1 changed files with 5 additions and 5 deletions
10
video.go
10
video.go
|
@ -24,7 +24,7 @@ type Video struct {
|
||||||
hasstreams bool // Flag storing whether file has additional data streams.
|
hasstreams bool // Flag storing whether file has additional data streams.
|
||||||
framebuffer []byte // Raw frame data.
|
framebuffer []byte // Raw frame data.
|
||||||
metadata map[string]string // Video metadata.
|
metadata map[string]string // Video metadata.
|
||||||
pipe *io.ReadCloser // Stdout pipe for ffmpeg process.
|
pipe io.ReadCloser // Stdout pipe for ffmpeg process.
|
||||||
cmd *exec.Cmd // ffmpeg command.
|
cmd *exec.Cmd // ffmpeg command.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,7 +209,7 @@ func (video *Video) init() error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
video.pipe = &pipe
|
video.pipe = pipe
|
||||||
|
|
||||||
if err := cmd.Start(); err != nil {
|
if err := cmd.Start(); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -234,7 +234,7 @@ func (video *Video) Read() bool {
|
||||||
|
|
||||||
total := 0
|
total := 0
|
||||||
for total < video.width*video.height*video.depth {
|
for total < video.width*video.height*video.depth {
|
||||||
n, err := (*video.pipe).Read(video.framebuffer[total:])
|
n, err := video.pipe.Read(video.framebuffer[total:])
|
||||||
if err == io.EOF {
|
if err == io.EOF {
|
||||||
video.Close()
|
video.Close()
|
||||||
return false
|
return false
|
||||||
|
@ -248,7 +248,7 @@ func (video *Video) Read() bool {
|
||||||
// Closes the pipe and stops the ffmpeg process.
|
// Closes the pipe and stops the ffmpeg process.
|
||||||
func (video *Video) Close() {
|
func (video *Video) Close() {
|
||||||
if video.pipe != nil {
|
if video.pipe != nil {
|
||||||
(*video.pipe).Close()
|
video.pipe.Close()
|
||||||
}
|
}
|
||||||
if video.cmd != nil {
|
if video.cmd != nil {
|
||||||
video.cmd.Wait()
|
video.cmd.Wait()
|
||||||
|
@ -263,7 +263,7 @@ func (video *Video) cleanup() {
|
||||||
go func() {
|
go func() {
|
||||||
<-c
|
<-c
|
||||||
if video.pipe != nil {
|
if video.pipe != nil {
|
||||||
(*video.pipe).Close()
|
video.pipe.Close()
|
||||||
}
|
}
|
||||||
if video.cmd != nil {
|
if video.cmd != nil {
|
||||||
video.cmd.Process.Kill()
|
video.cmd.Process.Kill()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue