Skip to content

Commit

Permalink
some staticcheck fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
RSWilli committed Sep 1, 2023
1 parent c139270 commit 095e65c
Show file tree
Hide file tree
Showing 20 changed files with 70 additions and 67 deletions.
6 changes: 5 additions & 1 deletion examples/custom_events/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,16 @@ func createPipeline() (*gst.Pipeline, error) {
"audiotestsrc name=src ! queue max-size-time=2000000000 ! fakesink name=sink sync=true",
)

if err != nil {
return nil, err
}

// Retrieve the sink element
sinks, err := pipeline.GetSinkElements()
if err != nil {
return nil, err
} else if len(sinks) != 1 {
return nil, errors.New("Expected one sink back")
return nil, errors.New("expected one sink back")
}
sink := sinks[0]

Expand Down
2 changes: 1 addition & 1 deletion examples/decodebin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func buildPipeline() (*gst.Pipeline, error) {
fmt.Printf("New pad added, is_audio=%v, is_video=%v\n", 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.
// These will be handled downstream.
msg := gst.NewErrorMessage(self, gst.NewGError(1, err), fmt.Sprintf("Received caps: %s", caps.String()), nil)
Expand Down
2 changes: 1 addition & 1 deletion examples/launch/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

func runPipeline(mainLoop *glib.MainLoop) error {
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)
Expand Down
4 changes: 4 additions & 0 deletions examples/pad-probes/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ func padProbes(mainLoop *glib.MainLoop) error {
"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
// created for us while parsing the launch syntax above.
//
Expand Down
4 changes: 1 addition & 3 deletions examples/playbin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ import (
"github.com/go-gst/go-gst/gst"
)

var srcURI string

func playbin(mainLoop *glib.MainLoop) error {
if len(os.Args) < 2 {
return errors.New("Usage: playbin <uri>")
return errors.New("usage: playbin <uri>")
}

gst.Init(nil)
Expand Down
30 changes: 15 additions & 15 deletions examples/plugins/gofilesink/filesink.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ type settings struct {
// 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
// interfaces via the registration and TypeInit processes.
type fileSink struct {
type FileSink struct {
// The settings for the element
settings *settings
// The current state of the element
Expand All @@ -97,9 +97,9 @@ type fileSink struct {

// setLocation is a simple method to check the validity of a provided file path and set the
// local value with it.
func (f *fileSink) setLocation(path string) error {
func (f *FileSink) setLocation(path string) error {
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
return nil
Expand All @@ -111,17 +111,17 @@ func (f *fileSink) setLocation(path string) error {

// 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.
func (f *fileSink) New() glib.GoObjectSubclass {
func (f *FileSink) New() glib.GoObjectSubclass {
CAT.Log(gst.LevelLog, "Initializing new fileSink object")
return &fileSink{
return &FileSink{
settings: &settings{},
state: &state{},
}
}

// The ClassInit method should specify the metadata for this element and add any pad templates
// and properties.
func (f *fileSink) ClassInit(klass *glib.ObjectClass) {
func (f *FileSink) ClassInit(klass *glib.ObjectClass) {
CAT.Log(gst.LevelLog, "Initializing gofilesink class")
class := gst.ToElementClass(klass)
class.SetMetadata(
Expand Down Expand Up @@ -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
// properties slice that we installed during ClassInit. It should attempt to register
// 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]
switch param.Name() {
case "location":
Expand All @@ -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
// 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]
switch param.Name() {
case "location":
Expand All @@ -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.

// 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 {
self.ErrorMessage(gst.DomainResource, gst.ResourceErrorSettings, "GoFileSink is already started", "")
return false
Expand Down Expand Up @@ -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.
func (f *fileSink) Stop(self *base.GstBaseSink) bool {
func (f *FileSink) Stop(self *base.GstBaseSink) bool {
if !f.state.started {
self.ErrorMessage(gst.DomainResource, gst.ResourceErrorSettings, "GoFileSink is not started", "")
return false
Expand All @@ -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.
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 {
self.ErrorMessage(gst.DomainResource, gst.ResourceErrorSettings, "GoFileSink is not started", "")
return gst.FlowError
Expand All @@ -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.

// 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.
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.
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.
func (f *fileSink) SetURI(uri string) (bool, error) {
func (f *FileSink) SetURI(uri string) (bool, error) {
if uri == "file://" {
return true, nil
}
Expand Down
36 changes: 18 additions & 18 deletions examples/plugins/gofilesrc/filesrc.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ type settings struct {
// 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
// interfaces via the registration and TypeInit processes.
type fileSrc struct {
type FileSrc struct {
// The settings for the element
settings *settings
// The current state of the element
Expand All @@ -101,9 +101,9 @@ type fileSrc struct {

// setLocation is a simple method to check the validity of a provided file path and set the
// local value with it.
func (f *fileSrc) setLocation(path string) error {
func (f *FileSrc) setLocation(path string) error {
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
return nil
Expand All @@ -115,17 +115,17 @@ func (f *fileSrc) setLocation(path string) error {

// Every element needs to provide its own constructor that returns an initialized
// 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")
return &fileSrc{
return &FileSrc{
settings: &settings{},
state: &state{},
}
}

// The ClassInit method should specify the metadata for this element and add any pad templates
// and properties.
func (f *fileSrc) ClassInit(klass *glib.ObjectClass) {
func (f *FileSrc) ClassInit(klass *glib.ObjectClass) {
CAT.Log(gst.LevelLog, "Initializing gofilesrc class")
class := gst.ToElementClass(klass)
class.SetMetadata(
Expand Down Expand Up @@ -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
// properties slice that we installed during ClassInit. It should attempt to register
// 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]
switch param.Name() {
case "location":
Expand All @@ -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
// 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]
switch param.Name() {
case "location":
Expand All @@ -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
// during the initialization process can be performed here. In this example, we set the format on our
// 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).SetFormat(gst.FormatBytes)
}
Expand All @@ -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.

// 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.
func (f *fileSrc) GetSize(self *base.GstBaseSrc) (bool, int64) {
func (f *FileSrc) GetSize(self *base.GstBaseSrc) (bool, int64) {
if !f.state.started {
return false, 0
}
Expand All @@ -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,
// 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 {
self.ErrorMessage(gst.DomainResource, gst.ResourceErrorSettings, "GoFileSrc is already started", "")
return false
Expand Down Expand Up @@ -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.
func (f *fileSrc) Stop(self *base.GstBaseSrc) bool {
func (f *FileSrc) Stop(self *base.GstBaseSrc) bool {
if !f.state.started {
self.ErrorMessage(gst.DomainResource, gst.ResourceErrorSettings, "FileSrc is not started", "")
return false
Expand All @@ -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.
// 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.
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 {
self.ErrorMessage(gst.DomainCore, gst.CoreErrorFailed, "Not started yet", "")
return gst.FlowError
Expand Down Expand Up @@ -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.

// 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.
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.
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.
func (f *fileSrc) SetURI(uri string) (bool, error) {
func (f *FileSrc) SetURI(uri string) (bool, error) {
if uri == "file://" {
return true, nil
}
Expand Down
3 changes: 1 addition & 2 deletions examples/toc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func tagsetter(mainLoop *glib.MainLoop) error {
gst.Init(nil)

if len(os.Args) < 2 {
return errors.New("Usage: toc <file>")
return errors.New("usage: toc <file>")
}

pipeline, err := gst.NewPipeline("")
Expand Down Expand Up @@ -99,7 +99,6 @@ func tagsetter(mainLoop *glib.MainLoop) error {
// End of stream
case gst.MessageEOS:
msg.Unref()
break

// Errors from any elements
case gst.MessageError:
Expand Down
2 changes: 1 addition & 1 deletion gst/app/gst_app_sink.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type SinkCallbacks struct {
}

// 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.
type Sink struct{ *base.GstBaseSink }
Expand Down
5 changes: 2 additions & 3 deletions gst/c_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ func gboolean(b bool) C.gboolean {

// gdateToTime converts a GDate to a time object.
func gdateToTime(gdate *C.GDate) time.Time {
tm := time.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 tm
// should this really be local time?
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)
}

// gstDateTimeToTime converts a GstDateTime to a time object. If the datetime object could not be parsed,
Expand Down
12 changes: 6 additions & 6 deletions gst/gst_bin.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (b *Bin) GetElementByName(name string) (*Element, error) {
defer C.free(unsafe.Pointer(cName))
elem := C.gst_bin_get_by_name((*C.GstBin)(b.Instance()), (*C.gchar)(cName))
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
}
Expand All @@ -140,7 +140,7 @@ func (b *Bin) GetElementByNameRecursive(name string) (*Element, error) {
defer C.free(unsafe.Pointer(cName))
elem := C.gst_bin_get_by_name_recurse_up((*C.GstBin)(b.Instance()), (*C.gchar)(cName))
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
}
Expand Down Expand Up @@ -185,7 +185,7 @@ func (b *Bin) GetElementsSorted() ([]*Element, error) {
func (b *Bin) GetByInterface(iface glib.Interface) (*Element, error) {
elem := C.gst_bin_get_by_interface(b.Instance(), C.GType(iface.Type()))
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
}
Expand All @@ -210,7 +210,7 @@ func (b *Bin) GetAllByInterface(iface glib.Interface) ([]*Element, error) {
// Add adds an element to the bin.
func (b *Bin) Add(elem *Element) error {
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
}
Expand All @@ -228,7 +228,7 @@ func (b *Bin) AddMany(elems ...*Element) error {
// Remove removes an element from the Bin.
func (b *Bin) Remove(elem *Element) error {
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
}
Expand Down Expand Up @@ -340,7 +340,7 @@ func iteratorToElementSlice(iterator *C.GstIterator) ([]*Element, error) {
elems = append(elems, wrapElement(glib.TransferNone(unsafe.Pointer(cElem))))
C.g_value_unset((*C.GValue)(gval))
default:
return nil, errors.New("Element iterator failed")
return nil, errors.New("element iterator failed")
}
}
}
Expand Down
Loading

0 comments on commit 095e65c

Please sign in to comment.