appsrc.SetProperty

I’m trying to rewrite the example appsrc so I can build out the pipeline later, but I don’t think I’m doing it correctly as I get ERROR! couldn’t find Property. Please help me, so I can move on.

appsrc, err := gst.NewElement("appsrc")
if err != nil {
	return nil, err
}
videoInfo := video.NewInfo().WithFormat(video.FormatRGBA, width, height)
if err := appsrc.SetProperty("appsrc", videoInfo); err != nil {
	return nil, err
}
appsrc.SetProperty("callbacks", &app.SourceCallbacks{
    NeedDataFunc: func(self *app.Source, _ uint) {
        buffer := gst.NewBufferWithSize(videoInfo.Size())
        bytes := produceImageFrame()
        buffer.Map(gst.MapWrite).WriteData(bytes)
        buffer.Unmap()
        self.PushBuffer(buffer)
	},
})

There is no appsrc property in appsrc. I suspect you meant to set the caps property from the video info.

Exactly. Do you happen to know the correct name, or is this not the way to set the intended format?

@philn - by trial-and-error, this also doesn’t work

videoInfo := video.NewInfo().WithFormat(video.FormatRGBA, width, height)
if err := appsrc.Set("caps", videoInfo); err != nil {
    return nil, err
}

ERROR! invalid type gpointer for property caps

I would recommend using GstApp library API such as GstAppSrc.set_caps() instead.

Are suggesting Python instead of Go and the go-gst bindings?

Ah, sorry, no. I just picked the bindings that will look most like what it might look like in your case.

I assume go-gst has bindings for the the GstApp library from gst-plugins-base?

I assume go-gst has bindings for the the GstApp library from gst-plugins-base?

It does: app package - github.com/go-gst/go-gst/gst/app - Go Packages

Although heads up: some function signatures might change because I’m in the middle of reworking the bindings and generating them from the GIR files.

@ea7kir the caps property needs a GstCaps* as a value. The bound go type is the *gst.Caps object. You’ll need to call ToCaps() on the video info.

video package - github.com/go-gst/go-gst/gst/video - Go Packages Which wraps gst_video_info_to_caps

1 Like

Thank you @RSWillli, that part is now working, although I used .Set because there isn’t a .SetCaps function. Next problem is with setting gst.ClockTimeNone.

appsrc, err := gst.NewElement("appsrc")
if err != nil {
	fmt.Println("FAILED #1")
	return nil, err
}
videoInfo := video.NewInfo().WithFormat(video.FormatRGBA, width, height)
if err := appsrc.Set("caps", videoInfo.ToCaps()); err != nil {
	fmt.Println("FAILED #2")
	return nil, err
}
if err := appsrc.SetProperty("format", gst.ClockTimeNone); err != nil {
	fmt.Println("FAILED #3")
	return nil, err
}
if err := appsrc.SetProperty("callbacks", &app.SourceCallbacks{
	NeedDataFunc: func(self *app.Source, _ uint) {
		buffer := gst.NewBufferWithSize(videoInfo.Size())
		bytes := produceImageFrame()
		buffer.Map(gst.MapWrite).WriteData(bytes)
		buffer.Unmap()
		self.PushBuffer(buffer)
	},
}); err != nil {
	fmt.Println("FAILED #4")
	return nil, err
}

FAILED #3
ERROR! unable to perform type conversion: Type not implemented

To get started with a real world application, a few real world examples would help. So, after 3 weeks of getting nowhere, I have no choice but to abandon all hope and hand in the towel. I’m sorry, but Go was designed to be idiomatic - go-gst is not.