tinyzimmer / go-gst

Gstreamer bindings and utilities for golang
GNU Lesser General Public License v2.1
130 stars 37 forks source link

I get error when try SetPropery "muxer" for the "splitmuxsink" plugin. #30

Open artofey opened 2 years ago

artofey commented 2 years ago

Gstreamer's documentation allowed set property "muxer' for elelment "splitmuxsink". But I got error in this code example:

pipeline, _ := gst.NewPipeline("")
splitMux, _ := gst.NewElement("splitmuxsink")
mux, _ := gst.NewElement("mp4mux")
splitMux.Set("muxer", mux)

err: fatal error: checkptr: pointer arithmetic result points to invalid allocation

I have tried other uses as well: splitMux.Set("muxer", mux.GObject()) splitMux.Set("muxer", *mux) but I also get errors (but different ones)

Does this library allow me to do what I want? When using the C language, I can do this easily.

Medina312 commented 2 years ago

Hi, I don’t know

artofey commented 2 years ago

I think the proplem is here

For different runs of the same code, C.g_object_class_find_property function returns with random paramSpec.value_type values...

Function GetPropertyType return not valide Type. GetPropertyType function returns wrong type. So this condition is true and we get an error

clintlombard commented 2 years ago

I'm having a similar issue with setting the active-pad property (requires *GstPad) of an input-selector element.

package main

import (
    "fmt"
    "log"
    "time"

    "github.com/tinyzimmer/go-gst/gst"
)

func main(){
    gst.Init(nil)
    pipeline, _ := gst.NewPipeline("")
    src0, _ := gst.NewElement("videotestsrc")
    src1, _ := gst.NewElement("videotestsrc")
    inputSelector, _ := gst.NewElement("input-selector")
    fakesink, _ := gst.NewElement("fakesink")

    pipeline.AddMany(
        src0,
        src1,
        inputSelector,
        fakesink,
    )
    src0.LinkFiltered(inputSelector, gst.NewCapsFromString("video/x-raw, framerate=16/1"))
    src1.LinkFiltered(inputSelector, gst.NewCapsFromString("video/x-raw, framerate=16/1"))
    inputSelector.Link(fakesink)
    pipeline.SetState(gst.StatePlaying)

    if inputSelector.GetState() != gst.StatePlaying {
        time.Sleep(10*time.Millisecond)
    }

    // Check the current active pad
    prop, _ := inputSelector.GetProperty("active-pad")
    fmt.Println("active-pad:", prop.(*gst.Pad).GetName())

    // Change the active pad
    pad := inputSelector.GetStaticPad("sink_1")

    err := inputSelector.SetProperty("active-pad", pad)
    if err != nil {
        log.Fatalf("Input selector failed to change inputs: %v\n", err)
    }
}

Output:

active-pad: sink_0
panic: runtime error: cgo argument has Go pointer to Go pointer

goroutine 1 [running]:
github.com/tinyzimmer/go-glib/glib.(*Value).SetPointer.func1(0xc000010060, 0x16)
        go/pkg/mod/github.com/tinyzimmer/go-glib@v0.0.24/glib/gvalue.go:557 +0x32
github.com/tinyzimmer/go-glib/glib.(*Value).SetPointer(0x55c720, 0xc000010058)
        go/pkg/mod/github.com/tinyzimmer/go-glib@v0.0.24/glib/gvalue.go:557 +0x19
github.com/tinyzimmer/go-glib/glib.gValue({0x55c720, 0xc000010058})
        go/pkg/mod/github.com/tinyzimmer/go-glib@v0.0.24/glib/gvalue.go:284 +0xa08
github.com/tinyzimmer/go-glib/glib.(*Object).SetProperty(0x587440, {0x55fed7, 0xa}, {0x55c720, 0xc000010058})
        go/pkg/mod/github.com/tinyzimmer/go-glib@v0.0.24/glib/gobject.go:211 +0x4f
main.main()

Seems like the issues is in go-glib. I've narrowed it down to gValue that can't handle *GObject derivatives like *GstObject so instead you must use .GObject(), i.e.

err := inputSelector.SetProperty("active-pad", pad.GObject())

This, however, opens another can of worms, because in SetPropertyValue it checks if the property type matches the value type, and this fails. The output now being

active-pad: sink_0
2022/03/17 13:57:29 Input selector failed to change inputs: Invalid type GObject for property active-pad

To fix this I think a simple solution would be to adjust the check in SetPropertyValue from

    if valType != propType {

to

    if !(valType.IsA(propType) || propType.IsA(valType)) {

@tinyzimmer how do you feel about this?

normen commented 2 years ago

+1

RSWilli commented 1 year ago

@artofey move this issue to https://github.com/go-gst/go-gst (where future development of the bindings will take place) if you think it is necessary.

Alternatively move the linked PR to https://github.com/go-gst/go-glib