clean up a bit morer

This commit is contained in:
tinyzimmer
2020-10-03 16:14:29 +03:00
parent f98bb0642e
commit c172f1e663

View File

@@ -81,6 +81,19 @@ func createPipeline() (*gst.Pipeline, error) {
return pipeline, nil return pipeline, nil
} }
func handleMessage(msg *gst.Message) error {
defer msg.Unref() // Messages are a good candidate for trying out runtime finalizers
switch msg.Type() {
case gst.MessageEOS:
return app.ErrEOS
case gst.MessageError:
return msg.ParseError()
}
return nil
}
func mainLoop(pipeline *gst.Pipeline) error { func mainLoop(pipeline *gst.Pipeline) error {
defer pipeline.Destroy() // Will stop and unref the pipeline when this function returns defer pipeline.Destroy() // Will stop and unref the pipeline when this function returns
@@ -97,16 +110,9 @@ func mainLoop(pipeline *gst.Pipeline) error {
if msg == nil { if msg == nil {
break break
} }
switch msg.Type() { if err := handleMessage(msg); err != nil {
case gst.MessageEOS:
msg.Unref() // Messsages are a good candidate for trying out runtime finalizers
break
case gst.MessageError:
err := msg.ParseError()
msg.Unref()
return err return err
} }
msg.Unref()
} }
return nil return nil