mirror of
https://github.com/go-gst/go-gst.git
synced 2025-10-06 08:27:03 +08:00
fix linting and add GstContext
This commit is contained in:
9
.golangci.yml
Normal file
9
.golangci.yml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
run:
|
||||||
|
timeout: 10m
|
||||||
|
|
||||||
|
skip-dirs:
|
||||||
|
- hack/
|
||||||
|
- cmd/
|
||||||
|
|
||||||
|
skip-files:
|
||||||
|
- hack/.*
|
2
Makefile
2
Makefile
@@ -17,4 +17,4 @@ $(GOLANGCI_LINT):
|
|||||||
ln -s golangci-lint-$(GOLANGCI_VERSION)-$(shell uname | tr A-Z a-z)-amd64/golangci-lint $(GOLANGCI_LINT)
|
ln -s golangci-lint-$(GOLANGCI_VERSION)-$(shell uname | tr A-Z a-z)-amd64/golangci-lint $(GOLANGCI_LINT)
|
||||||
|
|
||||||
lint: $(GOLANGCI_LINT)
|
lint: $(GOLANGCI_LINT)
|
||||||
$(GOLANGCI_LINT) run -v --timeout 300s --skip-dirs cmd/ --skip-files hack/*
|
$(GOLANGCI_LINT) run -v
|
13
gst/gst.go.h
13
gst/gst.go.h
@@ -16,6 +16,7 @@ inline GstBus * toGstBus (void *p) { return (GST_BUS
|
|||||||
inline GstCapsFeatures * toGstCapsFeatures (void *p) { return (GST_CAPS_FEATURES(p)); }
|
inline GstCapsFeatures * toGstCapsFeatures (void *p) { return (GST_CAPS_FEATURES(p)); }
|
||||||
inline GstCaps * toGstCaps (void *p) { return (GST_CAPS(p)); }
|
inline GstCaps * toGstCaps (void *p) { return (GST_CAPS(p)); }
|
||||||
inline GstClock * toGstClock (void *p) { return (GST_CLOCK(p)); }
|
inline GstClock * toGstClock (void *p) { return (GST_CLOCK(p)); }
|
||||||
|
inline GstContext * toGstContext (void *p) { return (GST_CONTEXT_CAST(p)); }
|
||||||
inline GstDevice * toGstDevice (void *p) { return (GST_DEVICE_CAST(p)); }
|
inline GstDevice * toGstDevice (void *p) { return (GST_DEVICE_CAST(p)); }
|
||||||
inline GstElementFactory * toGstElementFactory (void *p) { return (GST_ELEMENT_FACTORY(p)); }
|
inline GstElementFactory * toGstElementFactory (void *p) { return (GST_ELEMENT_FACTORY(p)); }
|
||||||
inline GstElement * toGstElement (void *p) { return (GST_ELEMENT(p)); }
|
inline GstElement * toGstElement (void *p) { return (GST_ELEMENT(p)); }
|
||||||
@@ -100,6 +101,18 @@ inline GType getCapsType ()
|
|||||||
return GST_TYPE_CAPS;
|
return GST_TYPE_CAPS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Context utilities */
|
||||||
|
|
||||||
|
inline gboolean contextIsWritable (GstContext * ctx)
|
||||||
|
{
|
||||||
|
return gst_context_is_writable(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline GstContext * makeContextWritable (GstContext * ctx)
|
||||||
|
{
|
||||||
|
return gst_context_make_writable(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
/* Object Utilities */
|
/* Object Utilities */
|
||||||
|
|
||||||
inline GObjectClass * getGObjectClass (void * p) { return (G_OBJECT_GET_CLASS(p)); }
|
inline GObjectClass * getGObjectClass (void * p) { return (G_OBJECT_GET_CLASS(p)); }
|
||||||
|
102
gst/gst_context.go
Normal file
102
gst/gst_context.go
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
package gst
|
||||||
|
|
||||||
|
// #include "gst.go.h"
|
||||||
|
import "C"
|
||||||
|
import "unsafe"
|
||||||
|
|
||||||
|
// Context wraps a GstContext object.
|
||||||
|
type Context struct {
|
||||||
|
ptr *C.GstContext
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewContext creates a new context.
|
||||||
|
//
|
||||||
|
// // Example
|
||||||
|
//
|
||||||
|
// ctx := gst.NewContext("test-context", false)
|
||||||
|
// fmt.Println(ctx.IsPersistent())
|
||||||
|
//
|
||||||
|
// ctx = gst.NewContext("test-context", true)
|
||||||
|
// fmt.Println(ctx.IsPersistent())
|
||||||
|
//
|
||||||
|
// // false
|
||||||
|
// // true
|
||||||
|
//
|
||||||
|
func NewContext(ctxType string, persistent bool) *Context {
|
||||||
|
cStr := C.CString(ctxType)
|
||||||
|
defer C.free(unsafe.Pointer(cStr))
|
||||||
|
ctx := C.gst_context_new((*C.gchar)(unsafe.Pointer(cStr)), gboolean(persistent))
|
||||||
|
if ctx == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return wrapContext(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Instance returns the underlying GstContext instance.
|
||||||
|
func (c *Context) Instance() *C.GstContext { return C.toGstContext(unsafe.Pointer(c.ptr)) }
|
||||||
|
|
||||||
|
// GetType returns the type of the context.
|
||||||
|
//
|
||||||
|
// // Example
|
||||||
|
//
|
||||||
|
// ctx := gst.NewContext("test-context", false)
|
||||||
|
// fmt.Println(ctx.GetType())
|
||||||
|
//
|
||||||
|
// // test-context
|
||||||
|
//
|
||||||
|
func (c *Context) GetType() string {
|
||||||
|
return C.GoString(C.gst_context_get_context_type(c.Instance()))
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetStructure returns the structure of the context. You should not modify or unref it.
|
||||||
|
func (c *Context) GetStructure() *Structure {
|
||||||
|
st := C.gst_context_get_structure(c.Instance())
|
||||||
|
if st == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return wrapStructure(st)
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasContextType checks if the context has the given type.
|
||||||
|
//
|
||||||
|
// // Example
|
||||||
|
//
|
||||||
|
// ctx := gst.NewContext("test-context", false)
|
||||||
|
// fmt.Println(ctx.HasContextType("test-context"))
|
||||||
|
// fmt.Println(ctx.HasContextType("another-context"))
|
||||||
|
//
|
||||||
|
// // true
|
||||||
|
// // false
|
||||||
|
//
|
||||||
|
func (c *Context) HasContextType(ctxType string) bool {
|
||||||
|
cStr := C.CString(ctxType)
|
||||||
|
defer C.free(unsafe.Pointer(cStr))
|
||||||
|
return gobool(C.gst_context_has_context_type(
|
||||||
|
c.Instance(),
|
||||||
|
(*C.gchar)(unsafe.Pointer(cStr)),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsPersistent checks if the context is persistent.
|
||||||
|
func (c *Context) IsPersistent() bool {
|
||||||
|
return gobool(C.gst_context_is_persistent(c.Instance()))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsWritable returns true if the context is writable.
|
||||||
|
func (c *Context) IsWritable() bool {
|
||||||
|
return gobool(C.contextIsWritable(c.Instance()))
|
||||||
|
}
|
||||||
|
|
||||||
|
// MakeWritable returns a writable version of the context.
|
||||||
|
func (c *Context) MakeWritable() *Context {
|
||||||
|
return wrapContext(C.makeContextWritable(c.Instance()))
|
||||||
|
}
|
||||||
|
|
||||||
|
// WritableStructure returns a writable version of the structure. You should still not unref it.
|
||||||
|
func (c *Context) WritableStructure() *Structure {
|
||||||
|
st := C.gst_context_writable_structure(c.Instance())
|
||||||
|
if st == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return wrapStructure(st)
|
||||||
|
}
|
@@ -115,6 +115,10 @@ func init() {
|
|||||||
T: glib.Type(C.GST_TYPE_CHILD_PROXY),
|
T: glib.Type(C.GST_TYPE_CHILD_PROXY),
|
||||||
F: marshalChildProxy,
|
F: marshalChildProxy,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
T: glib.Type(C.GST_TYPE_CONTEXT),
|
||||||
|
F: marshalContext,
|
||||||
|
},
|
||||||
|
|
||||||
// Boxed
|
// Boxed
|
||||||
{T: glib.Type(C.gst_message_get_type()), F: marshalMessage},
|
{T: glib.Type(C.gst_message_get_type()), F: marshalMessage},
|
||||||
@@ -134,6 +138,7 @@ func wrapBus(obj *glib.Object) *Bus { return &Bus{Object:
|
|||||||
func wrapCaps(caps *C.GstCaps) *Caps { return &Caps{native: caps} }
|
func wrapCaps(caps *C.GstCaps) *Caps { return &Caps{native: caps} }
|
||||||
func wrapChildProxy(c *C.GstChildProxy) *ChildProxy { return &ChildProxy{ptr: c} }
|
func wrapChildProxy(c *C.GstChildProxy) *ChildProxy { return &ChildProxy{ptr: c} }
|
||||||
func wrapClock(obj *glib.Object) *Clock { return &Clock{wrapObject(obj)} }
|
func wrapClock(obj *glib.Object) *Clock { return &Clock{wrapObject(obj)} }
|
||||||
|
func wrapContext(ctx *C.GstContext) *Context { return &Context{ptr: ctx} }
|
||||||
func wrapDevice(obj *glib.Object) *Device { return &Device{wrapObject(obj)} }
|
func wrapDevice(obj *glib.Object) *Device { return &Device{wrapObject(obj)} }
|
||||||
func wrapElement(obj *glib.Object) *Element { return &Element{wrapObject(obj)} }
|
func wrapElement(obj *glib.Object) *Element { return &Element{wrapObject(obj)} }
|
||||||
func wrapGhostPad(obj *glib.Object) *GhostPad { return &GhostPad{wrapPad(obj)} }
|
func wrapGhostPad(obj *glib.Object) *GhostPad { return &GhostPad{wrapPad(obj)} }
|
||||||
@@ -328,3 +333,9 @@ func marshalChildProxy(p uintptr) (interface{}, error) {
|
|||||||
obj := (*C.GstChildProxy)(unsafe.Pointer(c))
|
obj := (*C.GstChildProxy)(unsafe.Pointer(c))
|
||||||
return wrapChildProxy(obj), nil
|
return wrapChildProxy(obj), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func marshalContext(p uintptr) (interface{}, error) {
|
||||||
|
c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
|
||||||
|
obj := (*C.GstContext)(unsafe.Pointer(c))
|
||||||
|
return wrapContext(obj), nil
|
||||||
|
}
|
||||||
|
@@ -6,7 +6,7 @@ import (
|
|||||||
"github.com/tinyzimmer/go-gst/gst"
|
"github.com/tinyzimmer/go-gst/gst"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func capsWeirdness() {
|
||||||
gst.Init(nil)
|
gst.Init(nil)
|
||||||
|
|
||||||
caps := gst.NewCapsFromString("audio/x-raw")
|
caps := gst.NewCapsFromString("audio/x-raw")
|
@@ -7,7 +7,7 @@ import (
|
|||||||
"github.com/tinyzimmer/go-gst/gst"
|
"github.com/tinyzimmer/go-gst/gst"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func wait() {
|
||||||
gst.Init(nil)
|
gst.Init(nil)
|
||||||
|
|
||||||
clock := gst.ObtainSystemClock()
|
clock := gst.ObtainSystemClock()
|
||||||
|
@@ -7,7 +7,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func sleep() {
|
||||||
go func() {
|
go func() {
|
||||||
C.sleep(1000000000)
|
C.sleep(1000000000)
|
||||||
fmt.Println("I slept")
|
fmt.Println("I slept")
|
||||||
|
21
hack/test.c
21
hack/test.c
@@ -1,21 +0,0 @@
|
|||||||
#include <gst/gst.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
gboolean caps_map_func (GstCapsFeatures * features, GstStructure * structure, gpointer user_data)
|
|
||||||
{
|
|
||||||
printf(gst_caps_features_to_string(features));
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main () {
|
|
||||||
gst_init(NULL, NULL);
|
|
||||||
|
|
||||||
GstCaps * caps = gst_caps_from_string("audio/x-raw");
|
|
||||||
|
|
||||||
gst_caps_filter_and_map_in_place(caps, caps_map_func, NULL);
|
|
||||||
gst_caps_foreach(caps, caps_map_func, NULL);
|
|
||||||
|
|
||||||
gst_caps_unref(caps);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
Reference in New Issue
Block a user