mirror of
https://github.com/go-gst/go-gst.git
synced 2025-09-28 21:02:23 +08:00
fix appsrc example
This commit is contained in:
@@ -43,10 +43,11 @@ func createPipeline() (gst.Pipeline, error) {
|
|||||||
|
|
||||||
videoInfo.SetFramerate(2, 1)
|
videoInfo.SetFramerate(2, 1)
|
||||||
|
|
||||||
ok = src.SetCaps(videoInfo.ToCaps())
|
caps := videoInfo.ToCaps()
|
||||||
if !ok {
|
|
||||||
return nil, fmt.Errorf("failed to set caps on appsrc")
|
fmt.Println("Caps:", caps.String())
|
||||||
}
|
|
||||||
|
src.SetObjectProperty("caps", caps)
|
||||||
src.SetObjectProperty("format", gst.FormatTime)
|
src.SetObjectProperty("format", gst.FormatTime)
|
||||||
|
|
||||||
// Initialize a frame counter
|
// Initialize a frame counter
|
||||||
|
278
generator.go
278
generator.go
@@ -12,7 +12,6 @@ import (
|
|||||||
"github.com/diamondburned/gotk4/gir"
|
"github.com/diamondburned/gotk4/gir"
|
||||||
"github.com/diamondburned/gotk4/gir/cmd/gir-generate/gendata"
|
"github.com/diamondburned/gotk4/gir/cmd/gir-generate/gendata"
|
||||||
"github.com/diamondburned/gotk4/gir/cmd/gir-generate/genmain"
|
"github.com/diamondburned/gotk4/gir/cmd/gir-generate/genmain"
|
||||||
"github.com/diamondburned/gotk4/gir/girgen"
|
|
||||||
"github.com/diamondburned/gotk4/gir/girgen/file"
|
"github.com/diamondburned/gotk4/gir/girgen/file"
|
||||||
"github.com/diamondburned/gotk4/gir/girgen/generators"
|
"github.com/diamondburned/gotk4/gir/girgen/generators"
|
||||||
"github.com/diamondburned/gotk4/gir/girgen/strcases"
|
"github.com/diamondburned/gotk4/gir/girgen/strcases"
|
||||||
@@ -103,6 +102,9 @@ var Data = genmain.Overlay(
|
|||||||
// during init
|
// during init
|
||||||
t.GLibGetType = ""
|
t.GLibGetType = ""
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
// String() is more go like than ToString()
|
||||||
|
types.RenameCallable("Gst-1.Caps.to_string", "string"),
|
||||||
},
|
},
|
||||||
Config: typesystem.Config{
|
Config: typesystem.Config{
|
||||||
Namespaces: map[string]typesystem.NamespaceConfig{
|
Namespaces: map[string]typesystem.NamespaceConfig{
|
||||||
@@ -317,277 +319,3 @@ func (g *GstUseUnstableAPI) Generate(w *file.Package) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var _ generators.Generator = &GstUseUnstableAPI{}
|
var _ generators.Generator = &GstUseUnstableAPI{}
|
||||||
|
|
||||||
func FixWebrtcPkgConfig(nsgen *girgen.NamespaceGenerator) error {
|
|
||||||
// see: https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/8433, remove after release
|
|
||||||
nsgen.Namespace().Repository.Packages = append(nsgen.Namespace().Repository.Packages, gir.Package{
|
|
||||||
Name: "gstreamer-sdp-1.0",
|
|
||||||
})
|
|
||||||
|
|
||||||
for _, f := range nsgen.Files {
|
|
||||||
// see https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/8470 , remove after release
|
|
||||||
f.Header().IncludeC("gst/webrtc/sctptransport.h")
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func IteratorValues(nsgen *girgen.NamespaceGenerator) error {
|
|
||||||
fg := nsgen.MakeFile("iteratorvalues.go")
|
|
||||||
|
|
||||||
p := fg.Pen()
|
|
||||||
|
|
||||||
fg.Header().Import("iter")
|
|
||||||
|
|
||||||
p.Line(`
|
|
||||||
// Values allows you to access the values from the iterator in a go for loop via function iterators
|
|
||||||
func (it *Iterator) Values() iter.Seq[any] {
|
|
||||||
return func(yield func(any) bool) {
|
|
||||||
for {
|
|
||||||
v, ret := it.Next()
|
|
||||||
switch ret {
|
|
||||||
case IteratorDone:
|
|
||||||
return
|
|
||||||
case IteratorResync:
|
|
||||||
it.Resync()
|
|
||||||
case IteratorOK:
|
|
||||||
if !yield(v.GoValue()) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
case IteratorError:
|
|
||||||
panic("iterator values failed")
|
|
||||||
default:
|
|
||||||
panic("iterator values returned unknown state")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func StructureGoMarshal(nsgen *girgen.NamespaceGenerator) error {
|
|
||||||
fg := nsgen.MakeFile("structuremarshal.go")
|
|
||||||
|
|
||||||
p := fg.Pen()
|
|
||||||
|
|
||||||
fg.Header().NeedsExternGLib()
|
|
||||||
fg.Header().Import("reflect")
|
|
||||||
|
|
||||||
p.Line(`
|
|
||||||
// MarshalStructure will convert the given go struct into a GstStructure. Currently nested
|
|
||||||
// structs are not supported. You can control the mapping of the field names via the tags of the go struct.
|
|
||||||
func MarshalStructure(data interface{}) *Structure {
|
|
||||||
typeOf := reflect.TypeOf(data)
|
|
||||||
valsOf := reflect.ValueOf(data)
|
|
||||||
st := NewStructureEmpty(typeOf.Name())
|
|
||||||
for i := 0; i < valsOf.NumField(); i++ {
|
|
||||||
gval := valsOf.Field(i).Interface()
|
|
||||||
|
|
||||||
fieldName, ok := typeOf.Field(i).Tag.Lookup("gst")
|
|
||||||
|
|
||||||
if !ok {
|
|
||||||
fieldName = typeOf.Field(i).Name
|
|
||||||
}
|
|
||||||
|
|
||||||
st.SetValue(fieldName, coreglib.NewValue(gval))
|
|
||||||
}
|
|
||||||
return st
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnmarshalInto will unmarshal this structure into the given pointer. The object
|
|
||||||
// reflected by the pointer must be non-nil. You can control the mapping of the field names via the tags of the go struct.
|
|
||||||
func (s *Structure) UnmarshalInto(data interface{}) error {
|
|
||||||
rv := reflect.ValueOf(data)
|
|
||||||
if rv.Kind() != reflect.Ptr || rv.IsNil() {
|
|
||||||
return fmt.Errorf("data is invalid (nil or non-pointer)")
|
|
||||||
}
|
|
||||||
|
|
||||||
val := reflect.ValueOf(data).Elem()
|
|
||||||
nVal := rv.Elem()
|
|
||||||
for i := 0; i < val.NumField(); i++ {
|
|
||||||
nvField := nVal.Field(i)
|
|
||||||
|
|
||||||
fieldName, ok := val.Type().Field(i).Tag.Lookup("gst")
|
|
||||||
|
|
||||||
if !ok {
|
|
||||||
fieldName = val.Type().Field(i).Name
|
|
||||||
}
|
|
||||||
|
|
||||||
val := s.Value(fieldName)
|
|
||||||
|
|
||||||
nvField.Set(reflect.ValueOf(val))
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
`)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func BinAddMany(nsgen *girgen.NamespaceGenerator) error {
|
|
||||||
fg := nsgen.MakeFile("binaddmany.go")
|
|
||||||
|
|
||||||
p := fg.Pen()
|
|
||||||
|
|
||||||
p.Line(`
|
|
||||||
// AddMany repeatedly calls Add for each param
|
|
||||||
func (bin *Bin) AddMany(elements... Elementer) bool {
|
|
||||||
for _, el := range elements {
|
|
||||||
if !bin.Add(el) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
`)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func ElementLinkMany(nsgen *girgen.NamespaceGenerator) error {
|
|
||||||
fg := nsgen.MakeFile("elementlinkmany.go")
|
|
||||||
|
|
||||||
p := fg.Pen()
|
|
||||||
|
|
||||||
p.Line(`
|
|
||||||
// LinkMany links the given elements in the order passed
|
|
||||||
func LinkMany(elements... Elementer) bool {
|
|
||||||
if len(elements) == 0 {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
current := elements[0].(*Element)
|
|
||||||
|
|
||||||
for _, next := range elements[1:] {
|
|
||||||
if ! current.Link(next) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
current = next.(*Element)
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
`)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func ElementBlockSetState(nsgen *girgen.NamespaceGenerator) error {
|
|
||||||
fg := nsgen.MakeFile("elementblocksetstate.go")
|
|
||||||
|
|
||||||
p := fg.Pen()
|
|
||||||
|
|
||||||
p.Line(`
|
|
||||||
// BlockSetState is a convenience wrapper around calling SetState and State to wait for async state changes. See State for more info.
|
|
||||||
func (el *Element) BlockSetState(state State, timeout ClockTime) StateChangeReturn {
|
|
||||||
ret := el.SetState(state)
|
|
||||||
|
|
||||||
if ret == StateChangeAsync {
|
|
||||||
_, _, ret = el.State(timeout)
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret
|
|
||||||
}
|
|
||||||
`)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func ElementFactoryMakeWithProperties(nsgen *girgen.NamespaceGenerator) error {
|
|
||||||
fg := nsgen.MakeFile("elementfactory.go")
|
|
||||||
fg.Header().NeedsExternGLib()
|
|
||||||
|
|
||||||
p := fg.Pen()
|
|
||||||
|
|
||||||
// this is adapted from the autogenerated code and the coreglib.NewObjectWithProperties
|
|
||||||
p.Line(`
|
|
||||||
// ElementFactoryMakeWithProperties: create a new element of the type defined by
|
|
||||||
// the given elementfactory. The supplied list of properties, will be passed at
|
|
||||||
// object construction.
|
|
||||||
//
|
|
||||||
// The function takes the following parameters:
|
|
||||||
//
|
|
||||||
// - factoryname: named factory to instantiate.
|
|
||||||
// - names (optional): array of properties names.
|
|
||||||
// - values (optional): array of associated properties values.
|
|
||||||
//
|
|
||||||
// The function returns the following values:
|
|
||||||
//
|
|
||||||
// - element (optional): new Element or NULL if the element couldn't be
|
|
||||||
// created.
|
|
||||||
func ElementFactoryMakeWithProperties(factoryname string, properties map[string]any) Elementer {
|
|
||||||
var _arg1 *C.gchar // out
|
|
||||||
var _arg2 C.guint
|
|
||||||
var _cret *C.GstElement // in
|
|
||||||
|
|
||||||
_arg1 = (*C.gchar)(unsafe.Pointer(C.CString(factoryname)))
|
|
||||||
defer C.free(unsafe.Pointer(_arg1))
|
|
||||||
|
|
||||||
var names_ **C.gchar
|
|
||||||
var values_ *C.GValue
|
|
||||||
|
|
||||||
if len(properties) > 0 {
|
|
||||||
names := make([]*C.char, 0, len(properties))
|
|
||||||
values := make([]C.GValue, 0, len(properties))
|
|
||||||
|
|
||||||
for name, value := range properties {
|
|
||||||
cname := (*C.char)(C.CString(name))
|
|
||||||
defer C.free(unsafe.Pointer(cname))
|
|
||||||
|
|
||||||
gvalue := coreglib.NewValue(value)
|
|
||||||
defer runtime.KeepAlive(gvalue)
|
|
||||||
|
|
||||||
names = append(names, cname)
|
|
||||||
values = append(values, *(*C.GValue)(unsafe.Pointer(gvalue.Native())))
|
|
||||||
}
|
|
||||||
|
|
||||||
names_ = &names[0]
|
|
||||||
values_ = &values[0]
|
|
||||||
}
|
|
||||||
|
|
||||||
_cret = C.gst_element_factory_make_with_properties(_arg1, _arg2, names_, values_)
|
|
||||||
runtime.KeepAlive(factoryname)
|
|
||||||
|
|
||||||
var _element Elementer // out
|
|
||||||
|
|
||||||
if _cret != nil {
|
|
||||||
{
|
|
||||||
objptr := unsafe.Pointer(_cret)
|
|
||||||
|
|
||||||
object := coreglib.Take(objptr)
|
|
||||||
casted := object.WalkCast(func(obj coreglib.Objector) bool {
|
|
||||||
_, ok := obj.(Elementer)
|
|
||||||
return ok
|
|
||||||
})
|
|
||||||
rv, ok := casted.(Elementer)
|
|
||||||
if !ok {
|
|
||||||
panic("no marshaler for " + object.TypeFromInstance().String() + " matching gst.Elementer")
|
|
||||||
}
|
|
||||||
_element = rv
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return _element
|
|
||||||
}`)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
var ExtraGoContents = map[string]string{
|
|
||||||
"gst/gst.go": `
|
|
||||||
// Init binds to the gst_init() function. Argument parsing is not
|
|
||||||
// supported.
|
|
||||||
func Init() {
|
|
||||||
C.gst_init(nil, nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ClockTimeNone means infinite timeout or an empty value
|
|
||||||
const ClockTimeNone ClockTime = 0xffffffffffffffff // Ideally this would be set to C.GST_CLOCK_TIME_NONE but this causes issues on MacOS and Windows
|
|
||||||
`,
|
|
||||||
}
|
|
||||||
|
@@ -40830,7 +40830,7 @@ func (minuend *Caps) Subtract(subtrahend *Caps) *Caps {
|
|||||||
return goret
|
return goret
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToString wraps gst_caps_to_string
|
// String wraps gst_caps_to_string
|
||||||
//
|
//
|
||||||
// The function returns the following values:
|
// The function returns the following values:
|
||||||
//
|
//
|
||||||
@@ -40849,7 +40849,7 @@ func (minuend *Caps) Subtract(subtrahend *Caps) *Caps {
|
|||||||
//
|
//
|
||||||
// The implementation of serialization up to 1.20 would lead to unexpected results
|
// The implementation of serialization up to 1.20 would lead to unexpected results
|
||||||
// when there were nested #GstCaps / #GstStructure deeper than one level.
|
// when there were nested #GstCaps / #GstStructure deeper than one level.
|
||||||
func (caps *Caps) ToString() string {
|
func (caps *Caps) String() string {
|
||||||
var carg0 *C.GstCaps // in, none, converted
|
var carg0 *C.GstCaps // in, none, converted
|
||||||
var cret *C.gchar // return, full, string
|
var cret *C.gchar // return, full, string
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user