Hi everyone,
I’m trying to use the “draw” signal of the element “overlaycomposition”, but it leaks in every call.
func BuildPipeline() (gst.Pipeline, error) {
gst.Init()
pipelineStr := fmt.Sprintf(`
input-selector name=vsel sync-streams=false sync-mode=clock ! videoconvert ! avenc_mpeg2video bitrate=4000000 field-order=tt max-bframes=0 !
atscmux name=mux alignment=7 ! queue max-size-time=0 max-size-buffers=0 max-size-bytes=134217728 !
udpsink host=%s port=%d multicast-iface=eno1 auto-multicast=true buffer-size=33554423 sync=true async=false
input-selector name=asel sync-streams=false sync-mode=clock ! audioconvert ! audioresample ! avenc_ac3 ! ac3parse ! mux.
udpsrc multicast-group=%s multicast-iface=eno1 auto-multicast=true port=%d buffer-size=33554432 caps="video/mpegts,systemstream=(boolean)true,packetsize=(int)188" !
queue max-size-time=0 max-size-buffers=0 max-size-bytes=134217728 ! tsparse ! tsdemux program-number=%d name=demux
demux. ! queue max-size-time=0 max-size-buffers=0 max-size-bytes=33554432 ! mpegvideoparse ! avdec_mpeg2video ! videoconvert ! videorate ! video/x-raw,framerate=30000/1001 !
gdkpixbufoverlay name=siglas_nacional alpha=0 location=%s ! overlaycomposition name=overlay_udp ! vsel.sink_0
demux. ! queue max-size-time=0 max-size-buffers=0 max-size-bytes=33554432 ! decodebin ! audioconvert ! audioresample ! asel.sink_0
decklinkvideosrc device-number=%d mode=1080i5994 buffer-size=60 ! videoconvert ! video/x-raw,format=UYVY,width=1920,height=1080,framerate=30000/1001,interlace-mode=interleaved !
gdkpixbufoverlay name=siglas_vivo alpha=0 location=%s ! vsel.sink_1
decklinkaudiosrc device-number=%d buffer-size=60 ! audioconvert ! audio/x-raw,format=S16LE,rate=48000,channels=2,layout=interleaved ! asel.sink_1
`,
conf.Config.StreamSalida.UDP_Host,
conf.Config.StreamSalida.UDP_Port,
conf.Config.StreamsEntrada.UDP_MulticastGroup,
conf.Config.StreamsEntrada.UDP_Port,
conf.Config.StreamsEntrada.UDP_ProgramNumber,
conf.Config.Rutas.PNGSiglas, conf.Config.Decklink.Entrada, conf.Config.Rutas.PNGSiglas, conf.Config.Decklink.Entrada)
pipeline_elem, err_pipeline := gst.ParseLaunch(pipelineStr)
if err_pipeline != nil {
log.Printf("Error al crear pipeline: %v", err_pipeline)
return nil, err_pipeline
}
pipeline_main = pipeline_elem.(gst.Pipeline)
pipeline_main.SetName("pipeline_main")
overlay_udp := pipeline_main.GetByName("overlay_udp")
/*
OTHER LINES, DOESN'T MATTER
*/
//Connect "draw" signal of "overlaycomposition" element
overlay_udp.Connect("draw", draw)
return pipeline_main, nil
}
func draw(self gst.Element, _ *gst.Sample) *gstvideo.VideoOverlayComposition {
if !active {
log.Println("there's no overlay active")
return nil
}
size := 1920 * 1080 * 4
buf := gst.NewBufferAllocate(nil, uint(size), nil)
_ = gstvideo.BufferAddVideoMeta(buf, gstvideo.VideoFrameFlagNone, gstvideo.VideoFormatAyuv, 1920, 1080)
if mapInfo, ok := buf.Map(gst.MapWrite); ok {
copy(mapInfo.Data(), frameOverlay) //global frameOverlay of type []byte, which I get from another pipeline, for each frame of the overlay .webm file
mapInfo.Unmap()
}
rect := gstvideo.NewVideoOverlayRectangleRaw(buf, 0, 0, 1920, 1080, gstvideo.VideoOverlayFormatFlagNone)
return gstvideo.NewVideoOverlayComposition(rect)
}
Even if I use:
func draw(self gst.Element, _ *gst.Sample) *gstvideo.VideoOverlayComposition {
return nil
}
The memory still leaking. But, on the other way, if I do not connect the signal, but keep the “overlaycomposition” in my pipelineStr, works fine and the memory doesn’t leak. Also, the terminal prints:
WARNING: not attaching a finalizer to VideoMeta because no cgo ref function or copy method is available. This may leak memory. Please file an issue.
So, I see two problems here. The memory leaks even if I do nothing on the callback, and leaks even more when I use it. I don’t know what’s going on. Any help and suggestions will be appreciated.
Additional context
GStreamer 1.28.2
Ubuntu 26.04
Binding package version: github.com/go-gst/go-gst@v0.0.2