mirror of
https://github.com/go-gst/go-gst.git
synced 2025-09-26 20:11:18 +08:00
some staticcheck fixes
This commit is contained in:
@@ -26,12 +26,16 @@ func createPipeline() (*gst.Pipeline, error) {
|
|||||||
"audiotestsrc name=src ! queue max-size-time=2000000000 ! fakesink name=sink sync=true",
|
"audiotestsrc name=src ! queue max-size-time=2000000000 ! fakesink name=sink sync=true",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
// Retrieve the sink element
|
// Retrieve the sink element
|
||||||
sinks, err := pipeline.GetSinkElements()
|
sinks, err := pipeline.GetSinkElements()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
} else if len(sinks) != 1 {
|
} else if len(sinks) != 1 {
|
||||||
return nil, errors.New("Expected one sink back")
|
return nil, errors.New("expected one sink back")
|
||||||
}
|
}
|
||||||
sink := sinks[0]
|
sink := sinks[0]
|
||||||
|
|
||||||
|
@@ -90,7 +90,7 @@ func buildPipeline() (*gst.Pipeline, error) {
|
|||||||
fmt.Printf("New pad added, is_audio=%v, is_video=%v\n", isAudio, isVideo)
|
fmt.Printf("New pad added, is_audio=%v, is_video=%v\n", isAudio, isVideo)
|
||||||
|
|
||||||
if !isAudio && !isVideo {
|
if !isAudio && !isVideo {
|
||||||
err := errors.New("Could not detect media stream type")
|
err := errors.New("could not detect media stream type")
|
||||||
// We can send errors directly to the pipeline bus if they occur.
|
// We can send errors directly to the pipeline bus if they occur.
|
||||||
// These will be handled downstream.
|
// These will be handled downstream.
|
||||||
msg := gst.NewErrorMessage(self, gst.NewGError(1, err), fmt.Sprintf("Received caps: %s", caps.String()), nil)
|
msg := gst.NewErrorMessage(self, gst.NewGError(1, err), fmt.Sprintf("Received caps: %s", caps.String()), nil)
|
||||||
|
@@ -16,7 +16,7 @@ import (
|
|||||||
|
|
||||||
func runPipeline(mainLoop *glib.MainLoop) error {
|
func runPipeline(mainLoop *glib.MainLoop) error {
|
||||||
if len(os.Args) == 1 {
|
if len(os.Args) == 1 {
|
||||||
return errors.New("Pipeline string cannot be empty")
|
return errors.New("pipeline string cannot be empty")
|
||||||
}
|
}
|
||||||
|
|
||||||
gst.Init(&os.Args)
|
gst.Init(&os.Args)
|
||||||
|
@@ -29,6 +29,10 @@ func padProbes(mainLoop *glib.MainLoop) error {
|
|||||||
"audiotestsrc name=src ! audio/x-raw,format=S16LE,channels=1 ! fakesink",
|
"audiotestsrc name=src ! audio/x-raw,format=S16LE,channels=1 ! fakesink",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// Get the audiotestsrc element from the pipeline that GStreamer
|
// Get the audiotestsrc element from the pipeline that GStreamer
|
||||||
// created for us while parsing the launch syntax above.
|
// created for us while parsing the launch syntax above.
|
||||||
//
|
//
|
||||||
|
@@ -21,11 +21,9 @@ import (
|
|||||||
"github.com/go-gst/go-gst/gst"
|
"github.com/go-gst/go-gst/gst"
|
||||||
)
|
)
|
||||||
|
|
||||||
var srcURI string
|
|
||||||
|
|
||||||
func playbin(mainLoop *glib.MainLoop) error {
|
func playbin(mainLoop *glib.MainLoop) error {
|
||||||
if len(os.Args) < 2 {
|
if len(os.Args) < 2 {
|
||||||
return errors.New("Usage: playbin <uri>")
|
return errors.New("usage: playbin <uri>")
|
||||||
}
|
}
|
||||||
|
|
||||||
gst.Init(nil)
|
gst.Init(nil)
|
||||||
|
@@ -88,7 +88,7 @@ type settings struct {
|
|||||||
// Finally a structure is defined that implements (at a minimum) the glib.GoObject interface.
|
// Finally a structure is defined that implements (at a minimum) the glib.GoObject interface.
|
||||||
// It is possible to signal to the bindings to inherit from other classes or implement other
|
// It is possible to signal to the bindings to inherit from other classes or implement other
|
||||||
// interfaces via the registration and TypeInit processes.
|
// interfaces via the registration and TypeInit processes.
|
||||||
type fileSink struct {
|
type FileSink struct {
|
||||||
// The settings for the element
|
// The settings for the element
|
||||||
settings *settings
|
settings *settings
|
||||||
// The current state of the element
|
// The current state of the element
|
||||||
@@ -97,9 +97,9 @@ type fileSink struct {
|
|||||||
|
|
||||||
// setLocation is a simple method to check the validity of a provided file path and set the
|
// setLocation is a simple method to check the validity of a provided file path and set the
|
||||||
// local value with it.
|
// local value with it.
|
||||||
func (f *fileSink) setLocation(path string) error {
|
func (f *FileSink) setLocation(path string) error {
|
||||||
if f.state.started {
|
if f.state.started {
|
||||||
return errors.New("Changing the `location` property on a started `GoFileSink` is not supported")
|
return errors.New("changing the `location` property on a started `GoFileSink` is not supported")
|
||||||
}
|
}
|
||||||
f.settings.location = strings.TrimPrefix(path, "file://") // should obviously use url.URL and do actual parsing
|
f.settings.location = strings.TrimPrefix(path, "file://") // should obviously use url.URL and do actual parsing
|
||||||
return nil
|
return nil
|
||||||
@@ -111,9 +111,9 @@ func (f *fileSink) setLocation(path string) error {
|
|||||||
|
|
||||||
// Every element needs to provide its own constructor that returns an initialized glib.GoObjectSubclass
|
// Every element needs to provide its own constructor that returns an initialized glib.GoObjectSubclass
|
||||||
// implementation. Here we simply create a new fileSink with zeroed settings and state objects.
|
// implementation. Here we simply create a new fileSink with zeroed settings and state objects.
|
||||||
func (f *fileSink) New() glib.GoObjectSubclass {
|
func (f *FileSink) New() glib.GoObjectSubclass {
|
||||||
CAT.Log(gst.LevelLog, "Initializing new fileSink object")
|
CAT.Log(gst.LevelLog, "Initializing new fileSink object")
|
||||||
return &fileSink{
|
return &FileSink{
|
||||||
settings: &settings{},
|
settings: &settings{},
|
||||||
state: &state{},
|
state: &state{},
|
||||||
}
|
}
|
||||||
@@ -121,7 +121,7 @@ func (f *fileSink) New() glib.GoObjectSubclass {
|
|||||||
|
|
||||||
// The ClassInit method should specify the metadata for this element and add any pad templates
|
// The ClassInit method should specify the metadata for this element and add any pad templates
|
||||||
// and properties.
|
// and properties.
|
||||||
func (f *fileSink) ClassInit(klass *glib.ObjectClass) {
|
func (f *FileSink) ClassInit(klass *glib.ObjectClass) {
|
||||||
CAT.Log(gst.LevelLog, "Initializing gofilesink class")
|
CAT.Log(gst.LevelLog, "Initializing gofilesink class")
|
||||||
class := gst.ToElementClass(klass)
|
class := gst.ToElementClass(klass)
|
||||||
class.SetMetadata(
|
class.SetMetadata(
|
||||||
@@ -150,7 +150,7 @@ func (f *fileSink) ClassInit(klass *glib.ObjectClass) {
|
|||||||
// SetProperty is called when a `value` is set to the property at index `id` in the
|
// SetProperty is called when a `value` is set to the property at index `id` in the
|
||||||
// properties slice that we installed during ClassInit. It should attempt to register
|
// properties slice that we installed during ClassInit. It should attempt to register
|
||||||
// the value locally or signal any errors that occur in the process.
|
// the value locally or signal any errors that occur in the process.
|
||||||
func (f *fileSink) SetProperty(self *glib.Object, id uint, value *glib.Value) {
|
func (f *FileSink) SetProperty(self *glib.Object, id uint, value *glib.Value) {
|
||||||
param := properties[id]
|
param := properties[id]
|
||||||
switch param.Name() {
|
switch param.Name() {
|
||||||
case "location":
|
case "location":
|
||||||
@@ -173,7 +173,7 @@ func (f *fileSink) SetProperty(self *glib.Object, id uint, value *glib.Value) {
|
|||||||
|
|
||||||
// GetProperty is called to retrieve the value of the property at index `id` in the properties
|
// GetProperty is called to retrieve the value of the property at index `id` in the properties
|
||||||
// slice provided at ClassInit.
|
// slice provided at ClassInit.
|
||||||
func (f *fileSink) GetProperty(self *glib.Object, id uint) *glib.Value {
|
func (f *FileSink) GetProperty(self *glib.Object, id uint) *glib.Value {
|
||||||
param := properties[id]
|
param := properties[id]
|
||||||
switch param.Name() {
|
switch param.Name() {
|
||||||
case "location":
|
case "location":
|
||||||
@@ -196,7 +196,7 @@ func (f *fileSink) GetProperty(self *glib.Object, id uint) *glib.Value {
|
|||||||
// If the method is not overridden by the implementing struct, it will be inherited from the parent class.
|
// If the method is not overridden by the implementing struct, it will be inherited from the parent class.
|
||||||
|
|
||||||
// Start is called to start the filesink. Open the file for writing and set the internal state.
|
// Start is called to start the filesink. Open the file for writing and set the internal state.
|
||||||
func (f *fileSink) Start(self *base.GstBaseSink) bool {
|
func (f *FileSink) Start(self *base.GstBaseSink) bool {
|
||||||
if f.state.started {
|
if f.state.started {
|
||||||
self.ErrorMessage(gst.DomainResource, gst.ResourceErrorSettings, "GoFileSink is already started", "")
|
self.ErrorMessage(gst.DomainResource, gst.ResourceErrorSettings, "GoFileSink is already started", "")
|
||||||
return false
|
return false
|
||||||
@@ -225,7 +225,7 @@ func (f *fileSink) Start(self *base.GstBaseSink) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Stop is called to stop the element. Set the internal state and close the file.
|
// Stop is called to stop the element. Set the internal state and close the file.
|
||||||
func (f *fileSink) Stop(self *base.GstBaseSink) bool {
|
func (f *FileSink) Stop(self *base.GstBaseSink) bool {
|
||||||
if !f.state.started {
|
if !f.state.started {
|
||||||
self.ErrorMessage(gst.DomainResource, gst.ResourceErrorSettings, "GoFileSink is not started", "")
|
self.ErrorMessage(gst.DomainResource, gst.ResourceErrorSettings, "GoFileSink is not started", "")
|
||||||
return false
|
return false
|
||||||
@@ -241,7 +241,7 @@ func (f *fileSink) Stop(self *base.GstBaseSink) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Render is called when a buffer is ready to be written to the file.
|
// Render is called when a buffer is ready to be written to the file.
|
||||||
func (f *fileSink) Render(self *base.GstBaseSink, buffer *gst.Buffer) gst.FlowReturn {
|
func (f *FileSink) Render(self *base.GstBaseSink, buffer *gst.Buffer) gst.FlowReturn {
|
||||||
if !f.state.started {
|
if !f.state.started {
|
||||||
self.ErrorMessage(gst.DomainResource, gst.ResourceErrorSettings, "GoFileSink is not started", "")
|
self.ErrorMessage(gst.DomainResource, gst.ResourceErrorSettings, "GoFileSink is not started", "")
|
||||||
return gst.FlowError
|
return gst.FlowError
|
||||||
@@ -263,16 +263,16 @@ func (f *fileSink) Render(self *base.GstBaseSink, buffer *gst.Buffer) gst.FlowRe
|
|||||||
// URIHandler implementations are the methods required by the GstURIHandler interface.
|
// URIHandler implementations are the methods required by the GstURIHandler interface.
|
||||||
|
|
||||||
// GetURI returns the currently configured URI
|
// GetURI returns the currently configured URI
|
||||||
func (f *fileSink) GetURI() string { return fmt.Sprintf("file://%s", f.settings.location) }
|
func (f *FileSink) GetURI() string { return fmt.Sprintf("file://%s", f.settings.location) }
|
||||||
|
|
||||||
// GetURIType returns the types of URI this element supports.
|
// GetURIType returns the types of URI this element supports.
|
||||||
func (f *fileSink) GetURIType() gst.URIType { return gst.URISource }
|
func (f *FileSink) GetURIType() gst.URIType { return gst.URISource }
|
||||||
|
|
||||||
// GetProtocols returns the protcols this element supports.
|
// GetProtocols returns the protcols this element supports.
|
||||||
func (f *fileSink) GetProtocols() []string { return []string{"file"} }
|
func (f *FileSink) GetProtocols() []string { return []string{"file"} }
|
||||||
|
|
||||||
// SetURI should set the URI that this element is working on.
|
// SetURI should set the URI that this element is working on.
|
||||||
func (f *fileSink) SetURI(uri string) (bool, error) {
|
func (f *FileSink) SetURI(uri string) (bool, error) {
|
||||||
if uri == "file://" {
|
if uri == "file://" {
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
@@ -90,7 +90,7 @@ type settings struct {
|
|||||||
// Finally a structure is defined that implements (at a minimum) the gst.GoElement interface.
|
// Finally a structure is defined that implements (at a minimum) the gst.GoElement interface.
|
||||||
// It is possible to signal to the bindings to inherit from other classes or implement other
|
// It is possible to signal to the bindings to inherit from other classes or implement other
|
||||||
// interfaces via the registration and TypeInit processes.
|
// interfaces via the registration and TypeInit processes.
|
||||||
type fileSrc struct {
|
type FileSrc struct {
|
||||||
// The settings for the element
|
// The settings for the element
|
||||||
settings *settings
|
settings *settings
|
||||||
// The current state of the element
|
// The current state of the element
|
||||||
@@ -101,9 +101,9 @@ type fileSrc struct {
|
|||||||
|
|
||||||
// setLocation is a simple method to check the validity of a provided file path and set the
|
// setLocation is a simple method to check the validity of a provided file path and set the
|
||||||
// local value with it.
|
// local value with it.
|
||||||
func (f *fileSrc) setLocation(path string) error {
|
func (f *FileSrc) setLocation(path string) error {
|
||||||
if f.state.started {
|
if f.state.started {
|
||||||
return errors.New("Changing the `location` property on a started `GoFileSrc` is not supported")
|
return errors.New("changing the `location` property on a started `GoFileSrc` is not supported")
|
||||||
}
|
}
|
||||||
f.settings.location = strings.TrimPrefix(path, "file://") // should obviously use url.URL and do actual parsing
|
f.settings.location = strings.TrimPrefix(path, "file://") // should obviously use url.URL and do actual parsing
|
||||||
return nil
|
return nil
|
||||||
@@ -115,9 +115,9 @@ func (f *fileSrc) setLocation(path string) error {
|
|||||||
|
|
||||||
// Every element needs to provide its own constructor that returns an initialized
|
// Every element needs to provide its own constructor that returns an initialized
|
||||||
// glib.GoObjectSubclass and state objects.
|
// glib.GoObjectSubclass and state objects.
|
||||||
func (f *fileSrc) New() glib.GoObjectSubclass {
|
func (f *FileSrc) New() glib.GoObjectSubclass {
|
||||||
CAT.Log(gst.LevelLog, "Initializing new fileSrc object")
|
CAT.Log(gst.LevelLog, "Initializing new fileSrc object")
|
||||||
return &fileSrc{
|
return &FileSrc{
|
||||||
settings: &settings{},
|
settings: &settings{},
|
||||||
state: &state{},
|
state: &state{},
|
||||||
}
|
}
|
||||||
@@ -125,7 +125,7 @@ func (f *fileSrc) New() glib.GoObjectSubclass {
|
|||||||
|
|
||||||
// The ClassInit method should specify the metadata for this element and add any pad templates
|
// The ClassInit method should specify the metadata for this element and add any pad templates
|
||||||
// and properties.
|
// and properties.
|
||||||
func (f *fileSrc) ClassInit(klass *glib.ObjectClass) {
|
func (f *FileSrc) ClassInit(klass *glib.ObjectClass) {
|
||||||
CAT.Log(gst.LevelLog, "Initializing gofilesrc class")
|
CAT.Log(gst.LevelLog, "Initializing gofilesrc class")
|
||||||
class := gst.ToElementClass(klass)
|
class := gst.ToElementClass(klass)
|
||||||
class.SetMetadata(
|
class.SetMetadata(
|
||||||
@@ -154,7 +154,7 @@ func (f *fileSrc) ClassInit(klass *glib.ObjectClass) {
|
|||||||
// SetProperty is called when a `value` is set to the property at index `id` in the
|
// SetProperty is called when a `value` is set to the property at index `id` in the
|
||||||
// properties slice that we installed during ClassInit. It should attempt to register
|
// properties slice that we installed during ClassInit. It should attempt to register
|
||||||
// the value locally or signal any errors that occur in the process.
|
// the value locally or signal any errors that occur in the process.
|
||||||
func (f *fileSrc) SetProperty(self *glib.Object, id uint, value *glib.Value) {
|
func (f *FileSrc) SetProperty(self *glib.Object, id uint, value *glib.Value) {
|
||||||
param := properties[id]
|
param := properties[id]
|
||||||
switch param.Name() {
|
switch param.Name() {
|
||||||
case "location":
|
case "location":
|
||||||
@@ -177,7 +177,7 @@ func (f *fileSrc) SetProperty(self *glib.Object, id uint, value *glib.Value) {
|
|||||||
|
|
||||||
// GetProperty is called to retrieve the value of the property at index `id` in the properties
|
// GetProperty is called to retrieve the value of the property at index `id` in the properties
|
||||||
// slice provided at ClassInit.
|
// slice provided at ClassInit.
|
||||||
func (f *fileSrc) GetProperty(self *glib.Object, id uint) *glib.Value {
|
func (f *FileSrc) GetProperty(self *glib.Object, id uint) *glib.Value {
|
||||||
param := properties[id]
|
param := properties[id]
|
||||||
switch param.Name() {
|
switch param.Name() {
|
||||||
case "location":
|
case "location":
|
||||||
@@ -199,7 +199,7 @@ func (f *fileSrc) GetProperty(self *glib.Object, id uint) *glib.Value {
|
|||||||
// Constructed is called when the type system is done constructing the object. Any finalizations required
|
// Constructed is called when the type system is done constructing the object. Any finalizations required
|
||||||
// during the initialization process can be performed here. In this example, we set the format on our
|
// during the initialization process can be performed here. In this example, we set the format on our
|
||||||
// underlying GstBaseSrc to bytes.
|
// underlying GstBaseSrc to bytes.
|
||||||
func (f *fileSrc) Constructed(self *glib.Object) {
|
func (f *FileSrc) Constructed(self *glib.Object) {
|
||||||
base.ToGstBaseSrc(self).Log(CAT, gst.LevelLog, "Setting format of GstBaseSrc to bytes")
|
base.ToGstBaseSrc(self).Log(CAT, gst.LevelLog, "Setting format of GstBaseSrc to bytes")
|
||||||
base.ToGstBaseSrc(self).SetFormat(gst.FormatBytes)
|
base.ToGstBaseSrc(self).SetFormat(gst.FormatBytes)
|
||||||
}
|
}
|
||||||
@@ -208,10 +208,10 @@ func (f *fileSrc) Constructed(self *glib.Object) {
|
|||||||
// If the method is not overridden by the implementing struct, it will be inherited from the parent class.
|
// If the method is not overridden by the implementing struct, it will be inherited from the parent class.
|
||||||
|
|
||||||
// IsSeekable returns that we are, in fact, seekable.
|
// IsSeekable returns that we are, in fact, seekable.
|
||||||
func (f *fileSrc) IsSeekable(*base.GstBaseSrc) bool { return true }
|
func (f *FileSrc) IsSeekable(*base.GstBaseSrc) bool { return true }
|
||||||
|
|
||||||
// GetSize will return the total size of the file at the configured location.
|
// GetSize will return the total size of the file at the configured location.
|
||||||
func (f *fileSrc) GetSize(self *base.GstBaseSrc) (bool, int64) {
|
func (f *FileSrc) GetSize(self *base.GstBaseSrc) (bool, int64) {
|
||||||
if !f.state.started {
|
if !f.state.started {
|
||||||
return false, 0
|
return false, 0
|
||||||
}
|
}
|
||||||
@@ -220,7 +220,7 @@ func (f *fileSrc) GetSize(self *base.GstBaseSrc) (bool, int64) {
|
|||||||
|
|
||||||
// Start is called to start this element. In this example, the configured file is opened for reading,
|
// Start is called to start this element. In this example, the configured file is opened for reading,
|
||||||
// and any error encountered in the process is posted to the pipeline.
|
// and any error encountered in the process is posted to the pipeline.
|
||||||
func (f *fileSrc) Start(self *base.GstBaseSrc) bool {
|
func (f *FileSrc) Start(self *base.GstBaseSrc) bool {
|
||||||
if f.state.started {
|
if f.state.started {
|
||||||
self.ErrorMessage(gst.DomainResource, gst.ResourceErrorSettings, "GoFileSrc is already started", "")
|
self.ErrorMessage(gst.DomainResource, gst.ResourceErrorSettings, "GoFileSrc is already started", "")
|
||||||
return false
|
return false
|
||||||
@@ -268,7 +268,7 @@ func (f *fileSrc) Start(self *base.GstBaseSrc) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Stop is called to stop the element. The file is closed and the local values are zeroed out.
|
// Stop is called to stop the element. The file is closed and the local values are zeroed out.
|
||||||
func (f *fileSrc) Stop(self *base.GstBaseSrc) bool {
|
func (f *FileSrc) Stop(self *base.GstBaseSrc) bool {
|
||||||
if !f.state.started {
|
if !f.state.started {
|
||||||
self.ErrorMessage(gst.DomainResource, gst.ResourceErrorSettings, "FileSrc is not started", "")
|
self.ErrorMessage(gst.DomainResource, gst.ResourceErrorSettings, "FileSrc is not started", "")
|
||||||
return false
|
return false
|
||||||
@@ -290,7 +290,7 @@ func (f *fileSrc) Stop(self *base.GstBaseSrc) bool {
|
|||||||
// Fill is called to fill a pre-allocated buffer with the data at offset up to the given size.
|
// Fill is called to fill a pre-allocated buffer with the data at offset up to the given size.
|
||||||
// Since we declared that we are seekable, we need to support the provided offset not necessarily matching
|
// Since we declared that we are seekable, we need to support the provided offset not necessarily matching
|
||||||
// where we currently are in the file. This is why we store the position in the file locally.
|
// where we currently are in the file. This is why we store the position in the file locally.
|
||||||
func (f *fileSrc) Fill(self *base.GstBaseSrc, offset uint64, size uint, buffer *gst.Buffer) gst.FlowReturn {
|
func (f *FileSrc) Fill(self *base.GstBaseSrc, offset uint64, size uint, buffer *gst.Buffer) gst.FlowReturn {
|
||||||
if !f.state.started || f.state.file == nil {
|
if !f.state.started || f.state.file == nil {
|
||||||
self.ErrorMessage(gst.DomainCore, gst.CoreErrorFailed, "Not started yet", "")
|
self.ErrorMessage(gst.DomainCore, gst.CoreErrorFailed, "Not started yet", "")
|
||||||
return gst.FlowError
|
return gst.FlowError
|
||||||
@@ -332,16 +332,16 @@ func (f *fileSrc) Fill(self *base.GstBaseSrc, offset uint64, size uint, buffer *
|
|||||||
// URIHandler implementations are the methods required by the GstURIHandler interface.
|
// URIHandler implementations are the methods required by the GstURIHandler interface.
|
||||||
|
|
||||||
// GetURI returns the currently configured URI
|
// GetURI returns the currently configured URI
|
||||||
func (f *fileSrc) GetURI() string { return fmt.Sprintf("file://%s", f.settings.location) }
|
func (f *FileSrc) GetURI() string { return fmt.Sprintf("file://%s", f.settings.location) }
|
||||||
|
|
||||||
// GetURIType returns the types of URI this element supports.
|
// GetURIType returns the types of URI this element supports.
|
||||||
func (f *fileSrc) GetURIType() gst.URIType { return gst.URISource }
|
func (f *FileSrc) GetURIType() gst.URIType { return gst.URISource }
|
||||||
|
|
||||||
// GetProtocols returns the protcols this element supports.
|
// GetProtocols returns the protcols this element supports.
|
||||||
func (f *fileSrc) GetProtocols() []string { return []string{"file"} }
|
func (f *FileSrc) GetProtocols() []string { return []string{"file"} }
|
||||||
|
|
||||||
// SetURI should set the URI that this element is working on.
|
// SetURI should set the URI that this element is working on.
|
||||||
func (f *fileSrc) SetURI(uri string) (bool, error) {
|
func (f *FileSrc) SetURI(uri string) (bool, error) {
|
||||||
if uri == "file://" {
|
if uri == "file://" {
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
@@ -26,7 +26,7 @@ func tagsetter(mainLoop *glib.MainLoop) error {
|
|||||||
gst.Init(nil)
|
gst.Init(nil)
|
||||||
|
|
||||||
if len(os.Args) < 2 {
|
if len(os.Args) < 2 {
|
||||||
return errors.New("Usage: toc <file>")
|
return errors.New("usage: toc <file>")
|
||||||
}
|
}
|
||||||
|
|
||||||
pipeline, err := gst.NewPipeline("")
|
pipeline, err := gst.NewPipeline("")
|
||||||
@@ -99,7 +99,6 @@ func tagsetter(mainLoop *glib.MainLoop) error {
|
|||||||
// End of stream
|
// End of stream
|
||||||
case gst.MessageEOS:
|
case gst.MessageEOS:
|
||||||
msg.Unref()
|
msg.Unref()
|
||||||
break
|
|
||||||
|
|
||||||
// Errors from any elements
|
// Errors from any elements
|
||||||
case gst.MessageError:
|
case gst.MessageError:
|
||||||
|
@@ -35,7 +35,7 @@ type SinkCallbacks struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ErrEOS represents that the stream has ended.
|
// ErrEOS represents that the stream has ended.
|
||||||
var ErrEOS = errors.New("Pipeline has reached end-of-stream")
|
var ErrEOS = errors.New("pipeline has reached end-of-stream")
|
||||||
|
|
||||||
// Sink wraps an Element made with the appsink plugin with additional methods for pulling samples.
|
// Sink wraps an Element made with the appsink plugin with additional methods for pulling samples.
|
||||||
type Sink struct{ *base.GstBaseSink }
|
type Sink struct{ *base.GstBaseSink }
|
||||||
|
@@ -31,9 +31,8 @@ func gboolean(b bool) C.gboolean {
|
|||||||
|
|
||||||
// gdateToTime converts a GDate to a time object.
|
// gdateToTime converts a GDate to a time object.
|
||||||
func gdateToTime(gdate *C.GDate) time.Time {
|
func gdateToTime(gdate *C.GDate) time.Time {
|
||||||
tm := time.Time{}
|
// should this really be local time?
|
||||||
tm.AddDate(int(C.g_date_get_year(gdate)), int(C.g_date_get_month(gdate)), int(C.g_date_get_day(gdate)))
|
return time.Date(int(C.g_date_get_year(gdate)), time.Month(C.g_date_get_month(gdate)), int(C.g_date_get_day(gdate)), 0, 0, 0, 0, time.Local)
|
||||||
return tm
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// gstDateTimeToTime converts a GstDateTime to a time object. If the datetime object could not be parsed,
|
// gstDateTimeToTime converts a GstDateTime to a time object. If the datetime object could not be parsed,
|
||||||
|
@@ -128,7 +128,7 @@ func (b *Bin) GetElementByName(name string) (*Element, error) {
|
|||||||
defer C.free(unsafe.Pointer(cName))
|
defer C.free(unsafe.Pointer(cName))
|
||||||
elem := C.gst_bin_get_by_name((*C.GstBin)(b.Instance()), (*C.gchar)(cName))
|
elem := C.gst_bin_get_by_name((*C.GstBin)(b.Instance()), (*C.gchar)(cName))
|
||||||
if elem == nil {
|
if elem == nil {
|
||||||
return nil, fmt.Errorf("Could not find element with name %s", name)
|
return nil, fmt.Errorf("could not find element with name %s", name)
|
||||||
}
|
}
|
||||||
return wrapElement(glib.TransferFull(unsafe.Pointer(elem))), nil
|
return wrapElement(glib.TransferFull(unsafe.Pointer(elem))), nil
|
||||||
}
|
}
|
||||||
@@ -140,7 +140,7 @@ func (b *Bin) GetElementByNameRecursive(name string) (*Element, error) {
|
|||||||
defer C.free(unsafe.Pointer(cName))
|
defer C.free(unsafe.Pointer(cName))
|
||||||
elem := C.gst_bin_get_by_name_recurse_up((*C.GstBin)(b.Instance()), (*C.gchar)(cName))
|
elem := C.gst_bin_get_by_name_recurse_up((*C.GstBin)(b.Instance()), (*C.gchar)(cName))
|
||||||
if elem == nil {
|
if elem == nil {
|
||||||
return nil, fmt.Errorf("Could not find element with name %s", name)
|
return nil, fmt.Errorf("could not find element with name %s", name)
|
||||||
}
|
}
|
||||||
return wrapElement(glib.TransferFull(unsafe.Pointer(elem))), nil
|
return wrapElement(glib.TransferFull(unsafe.Pointer(elem))), nil
|
||||||
}
|
}
|
||||||
@@ -185,7 +185,7 @@ func (b *Bin) GetElementsSorted() ([]*Element, error) {
|
|||||||
func (b *Bin) GetByInterface(iface glib.Interface) (*Element, error) {
|
func (b *Bin) GetByInterface(iface glib.Interface) (*Element, error) {
|
||||||
elem := C.gst_bin_get_by_interface(b.Instance(), C.GType(iface.Type()))
|
elem := C.gst_bin_get_by_interface(b.Instance(), C.GType(iface.Type()))
|
||||||
if elem == nil {
|
if elem == nil {
|
||||||
return nil, fmt.Errorf("Could not find any elements implementing %s", iface.Type().Name())
|
return nil, fmt.Errorf("could not find any elements implementing %s", iface.Type().Name())
|
||||||
}
|
}
|
||||||
return wrapElement(glib.TransferFull(unsafe.Pointer(elem))), nil
|
return wrapElement(glib.TransferFull(unsafe.Pointer(elem))), nil
|
||||||
}
|
}
|
||||||
@@ -210,7 +210,7 @@ func (b *Bin) GetAllByInterface(iface glib.Interface) ([]*Element, error) {
|
|||||||
// Add adds an element to the bin.
|
// Add adds an element to the bin.
|
||||||
func (b *Bin) Add(elem *Element) error {
|
func (b *Bin) Add(elem *Element) error {
|
||||||
if ok := C.gst_bin_add((*C.GstBin)(b.Instance()), (*C.GstElement)(elem.Instance())); !gobool(ok) {
|
if ok := C.gst_bin_add((*C.GstBin)(b.Instance()), (*C.GstElement)(elem.Instance())); !gobool(ok) {
|
||||||
return fmt.Errorf("Failed to add element to pipeline: %s", elem.GetName())
|
return fmt.Errorf("failed to add element to pipeline: %s", elem.GetName())
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -228,7 +228,7 @@ func (b *Bin) AddMany(elems ...*Element) error {
|
|||||||
// Remove removes an element from the Bin.
|
// Remove removes an element from the Bin.
|
||||||
func (b *Bin) Remove(elem *Element) error {
|
func (b *Bin) Remove(elem *Element) error {
|
||||||
if ok := C.gst_bin_remove((*C.GstBin)(b.Instance()), (*C.GstElement)(elem.Instance())); !gobool(ok) {
|
if ok := C.gst_bin_remove((*C.GstBin)(b.Instance()), (*C.GstElement)(elem.Instance())); !gobool(ok) {
|
||||||
return fmt.Errorf("Failed to remove element from pipeline: %s", elem.GetName())
|
return fmt.Errorf("failed to remove element from pipeline: %s", elem.GetName())
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -340,7 +340,7 @@ func iteratorToElementSlice(iterator *C.GstIterator) ([]*Element, error) {
|
|||||||
elems = append(elems, wrapElement(glib.TransferNone(unsafe.Pointer(cElem))))
|
elems = append(elems, wrapElement(glib.TransferNone(unsafe.Pointer(cElem))))
|
||||||
C.g_value_unset((*C.GValue)(gval))
|
C.g_value_unset((*C.GValue)(gval))
|
||||||
default:
|
default:
|
||||||
return nil, errors.New("Element iterator failed")
|
return nil, errors.New("element iterator failed")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -22,7 +22,6 @@ import "C"
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"runtime"
|
"runtime"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
@@ -104,7 +103,7 @@ func NewBufferFromBytes(b []byte) *Buffer {
|
|||||||
|
|
||||||
// NewBufferFromReader returns a new buffer from the given io.Reader.
|
// NewBufferFromReader returns a new buffer from the given io.Reader.
|
||||||
func NewBufferFromReader(rdr io.Reader) (*Buffer, error) {
|
func NewBufferFromReader(rdr io.Reader) (*Buffer, error) {
|
||||||
out, err := ioutil.ReadAll(rdr)
|
out, err := io.ReadAll(rdr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@@ -91,7 +91,7 @@ func (d *Device) HasClasses(classes []string) bool {
|
|||||||
// while in the PLAYING state.
|
// while in the PLAYING state.
|
||||||
func (d *Device) ReconfigureElement(elem *Element) error {
|
func (d *Device) ReconfigureElement(elem *Element) error {
|
||||||
if ok := gobool(C.gst_device_reconfigure_element(d.Instance(), elem.Instance())); !ok {
|
if ok := gobool(C.gst_device_reconfigure_element(d.Instance(), elem.Instance())); !ok {
|
||||||
return fmt.Errorf("Failed to reconfigure element %s", elem.GetName())
|
return fmt.Errorf("failed to reconfigure element %s", elem.GetName())
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@@ -365,7 +365,7 @@ func (e *Element) IsURIHandler() bool {
|
|||||||
// Link wraps gst_element_link and links this element to the given one.
|
// Link wraps gst_element_link and links this element to the given one.
|
||||||
func (e *Element) Link(elem *Element) error {
|
func (e *Element) Link(elem *Element) error {
|
||||||
if ok := C.gst_element_link((*C.GstElement)(e.Instance()), (*C.GstElement)(elem.Instance())); !gobool(ok) {
|
if ok := C.gst_element_link((*C.GstElement)(e.Instance()), (*C.GstElement)(elem.Instance())); !gobool(ok) {
|
||||||
return fmt.Errorf("Failed to link %s to %s", e.GetName(), elem.GetName())
|
return fmt.Errorf("failed to link %s to %s", e.GetName(), elem.GetName())
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -379,12 +379,12 @@ func (e *Element) Unlink(elem *Element) {
|
|||||||
func (e *Element) LinkFiltered(elem *Element, filter *Caps) error {
|
func (e *Element) LinkFiltered(elem *Element, filter *Caps) error {
|
||||||
if filter == nil {
|
if filter == nil {
|
||||||
if ok := C.gst_element_link_filtered(e.Instance(), elem.Instance(), nil); !gobool(ok) {
|
if ok := C.gst_element_link_filtered(e.Instance(), elem.Instance(), nil); !gobool(ok) {
|
||||||
return fmt.Errorf("Failed to link %s to %s with provided caps", e.GetName(), elem.GetName())
|
return fmt.Errorf("failed to link %s to %s with provided caps", e.GetName(), elem.GetName())
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if ok := C.gst_element_link_filtered(e.Instance(), elem.Instance(), filter.Instance()); !gobool(ok) {
|
if ok := C.gst_element_link_filtered(e.Instance(), elem.Instance(), filter.Instance()); !gobool(ok) {
|
||||||
return fmt.Errorf("Failed to link %s to %s with provided caps", e.GetName(), elem.GetName())
|
return fmt.Errorf("failed to link %s to %s with provided caps", e.GetName(), elem.GetName())
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -454,7 +454,7 @@ func (e *Element) SendEvent(ev *Event) bool {
|
|||||||
func (e *Element) SetState(state State) error {
|
func (e *Element) SetState(state State) error {
|
||||||
stateRet := C.gst_element_set_state((*C.GstElement)(e.Instance()), C.GstState(state))
|
stateRet := C.gst_element_set_state((*C.GstElement)(e.Instance()), C.GstState(state))
|
||||||
if stateRet == C.GST_STATE_CHANGE_FAILURE {
|
if stateRet == C.GST_STATE_CHANGE_FAILURE {
|
||||||
return fmt.Errorf("Failed to change state to %s", state.String())
|
return fmt.Errorf("failed to change state to %s", state.String())
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@@ -55,7 +55,7 @@ type mapInfoWriter struct {
|
|||||||
|
|
||||||
func (m *mapInfoWriter) Write(p []byte) (int, error) {
|
func (m *mapInfoWriter) Write(p []byte) (int, error) {
|
||||||
if m.wsize+len(p) > int(m.mapInfo.Size()) {
|
if m.wsize+len(p) > int(m.mapInfo.Size()) {
|
||||||
return 0, errors.New("Attempt to write more data than allocated to MapInfo")
|
return 0, errors.New("attempt to write more data than allocated to MapInfo")
|
||||||
}
|
}
|
||||||
m.mapInfo.WriteAt(m.wsize, p)
|
m.mapInfo.WriteAt(m.wsize, p)
|
||||||
m.wsize += len(p)
|
m.wsize += len(p)
|
||||||
|
@@ -1136,7 +1136,7 @@ func iteratorToPadSlice(iterator *C.GstIterator) ([]*Pad, error) {
|
|||||||
pads = append(pads, FromGstPadUnsafeNone(unsafe.Pointer(cPad)))
|
pads = append(pads, FromGstPadUnsafeNone(unsafe.Pointer(cPad)))
|
||||||
C.g_value_unset((*C.GValue)(gval))
|
C.g_value_unset((*C.GValue)(gval))
|
||||||
default:
|
default:
|
||||||
return nil, errors.New("Pad iterator failed")
|
return nil, errors.New("pad iterator failed")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -38,7 +38,7 @@ func NewPipeline(name string) (*Pipeline, error) {
|
|||||||
}
|
}
|
||||||
pipeline := C.gst_pipeline_new((*C.gchar)(cChar))
|
pipeline := C.gst_pipeline_new((*C.gchar)(cChar))
|
||||||
if pipeline == nil {
|
if pipeline == nil {
|
||||||
return nil, errors.New("Could not create new pipeline")
|
return nil, errors.New("could not create new pipeline")
|
||||||
}
|
}
|
||||||
return FromGstPipelineUnsafeNone(unsafe.Pointer(pipeline)), nil
|
return FromGstPipelineUnsafeNone(unsafe.Pointer(pipeline)), nil
|
||||||
}
|
}
|
||||||
@@ -46,7 +46,7 @@ func NewPipeline(name string) (*Pipeline, error) {
|
|||||||
// NewPipelineFromString creates a new gstreamer pipeline from the given launch string.
|
// NewPipelineFromString creates a new gstreamer pipeline from the given launch string.
|
||||||
func NewPipelineFromString(launchv string) (*Pipeline, error) {
|
func NewPipelineFromString(launchv string) (*Pipeline, error) {
|
||||||
if len(strings.Split(launchv, "!")) < 2 {
|
if len(strings.Split(launchv, "!")) < 2 {
|
||||||
return nil, fmt.Errorf("Given string is too short for a pipeline: %s", launchv)
|
return nil, fmt.Errorf("given string is too short for a pipeline: %s", launchv)
|
||||||
}
|
}
|
||||||
cLaunchv := C.CString(launchv)
|
cLaunchv := C.CString(launchv)
|
||||||
defer C.free(unsafe.Pointer(cLaunchv))
|
defer C.free(unsafe.Pointer(cLaunchv))
|
||||||
|
@@ -38,7 +38,7 @@ func (r *Registry) FindPlugin(name string) (*Plugin, error) {
|
|||||||
defer C.free(unsafe.Pointer(cName))
|
defer C.free(unsafe.Pointer(cName))
|
||||||
plugin := C.gst_registry_find_plugin((*C.GstRegistry)(r.Instance()), (*C.gchar)(cName))
|
plugin := C.gst_registry_find_plugin((*C.GstRegistry)(r.Instance()), (*C.gchar)(cName))
|
||||||
if plugin == nil {
|
if plugin == nil {
|
||||||
return nil, fmt.Errorf("No plugin named %s found", name)
|
return nil, fmt.Errorf("no plugin named %s found", name)
|
||||||
}
|
}
|
||||||
return FromGstPluginUnsafeFull(unsafe.Pointer(plugin)), nil
|
return FromGstPluginUnsafeFull(unsafe.Pointer(plugin)), nil
|
||||||
}
|
}
|
||||||
@@ -49,7 +49,7 @@ func (r *Registry) LookupFeature(name string) (*PluginFeature, error) {
|
|||||||
defer C.free(unsafe.Pointer(cName))
|
defer C.free(unsafe.Pointer(cName))
|
||||||
feat := C.gst_registry_lookup_feature((*C.GstRegistry)(r.Instance()), (*C.gchar)(cName))
|
feat := C.gst_registry_lookup_feature((*C.GstRegistry)(r.Instance()), (*C.gchar)(cName))
|
||||||
if feat == nil {
|
if feat == nil {
|
||||||
return nil, fmt.Errorf("No feature named %s found", name)
|
return nil, fmt.Errorf("no feature named %s found", name)
|
||||||
}
|
}
|
||||||
return wrapPluginFeature(glib.TransferFull(unsafe.Pointer(feat))), nil
|
return wrapPluginFeature(glib.TransferFull(unsafe.Pointer(feat))), nil
|
||||||
}
|
}
|
||||||
|
@@ -40,7 +40,7 @@ func (s *StreamCollection) Instance() *C.GstStreamCollection {
|
|||||||
// AddStream adds the given stream to this collection.
|
// AddStream adds the given stream to this collection.
|
||||||
func (s *StreamCollection) AddStream(stream *Stream) error {
|
func (s *StreamCollection) AddStream(stream *Stream) error {
|
||||||
if ok := gobool(C.gst_stream_collection_add_stream(s.Instance(), stream.Instance())); !ok {
|
if ok := gobool(C.gst_stream_collection_add_stream(s.Instance(), stream.Instance())); !ok {
|
||||||
return fmt.Errorf("Failed to add stream %s to collection", stream.StreamID())
|
return fmt.Errorf("failed to add stream %s to collection", stream.StreamID())
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@@ -76,7 +76,7 @@ func FromGstStructureUnsafe(st unsafe.Pointer) *Structure {
|
|||||||
func (s *Structure) UnmarshalInto(data interface{}) error {
|
func (s *Structure) UnmarshalInto(data interface{}) error {
|
||||||
rv := reflect.ValueOf(data)
|
rv := reflect.ValueOf(data)
|
||||||
if rv.Kind() != reflect.Ptr || rv.IsNil() {
|
if rv.Kind() != reflect.Ptr || rv.IsNil() {
|
||||||
return errors.New("Data is invalid (nil or non-pointer)")
|
return errors.New("data is invalid (nil or non-pointer)")
|
||||||
}
|
}
|
||||||
|
|
||||||
val := reflect.ValueOf(data).Elem()
|
val := reflect.ValueOf(data).Elem()
|
||||||
@@ -134,7 +134,7 @@ func (s *Structure) GetValue(key string) (interface{}, error) {
|
|||||||
defer C.free(unsafe.Pointer(cKey))
|
defer C.free(unsafe.Pointer(cKey))
|
||||||
gVal := C.gst_structure_get_value(s.Instance(), cKey)
|
gVal := C.gst_structure_get_value(s.Instance(), cKey)
|
||||||
if gVal == nil {
|
if gVal == nil {
|
||||||
return nil, fmt.Errorf("No value exists at %s", key)
|
return nil, fmt.Errorf("no value exists at %s", key)
|
||||||
}
|
}
|
||||||
return glib.ValueFromNative(unsafe.Pointer(gVal)).GoValue()
|
return glib.ValueFromNative(unsafe.Pointer(gVal)).GoValue()
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user