73 lines
1.6 KiB
Go
73 lines
1.6 KiB
Go
|
package gstreamer
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"github.com/rs/zerolog"
|
||
|
"github.com/tinyzimmer/go-gst/gst"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
func (o *ImageOverlay) create(log zerolog.Logger) (*gst.Element, error) {
|
||
|
element, err := gst.NewElementWithName("gdkpixbufoverlay", o.Name)
|
||
|
if err != nil {
|
||
|
log.Error().Msgf("could not create image overlay %s: %v\n", o.Name, err)
|
||
|
return nil, fmt.Errorf("could not create image overlay %s", o.Name)
|
||
|
}
|
||
|
setPropertyWrapper(element, "positioning-mode", 1) // pixels-absolute
|
||
|
setPropertyWrapper(element, "location", o.Path)
|
||
|
|
||
|
o.update(log)
|
||
|
o.element = element
|
||
|
|
||
|
return element, err
|
||
|
}
|
||
|
|
||
|
func (o *ImageOverlay) update(_ zerolog.Logger) {
|
||
|
setPropertyWrapper(o.element, "offset-x", o.X)
|
||
|
setPropertyWrapper(o.element, "offset-y", o.Y)
|
||
|
|
||
|
if o.Display {
|
||
|
o.show()
|
||
|
} else {
|
||
|
o.hide()
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (o *ImageOverlay) show() gst.ClockCallback {
|
||
|
return func(clock *gst.Clock, clockTime time.Duration) bool {
|
||
|
setPropertyWrapper(o.element, "alpha", 1)
|
||
|
return true
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (o *ImageOverlay) hide() gst.ClockCallback {
|
||
|
return func(clock *gst.Clock, clockTime time.Duration) bool {
|
||
|
setPropertyWrapper(o.element, "alpha", 0)
|
||
|
return true
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (o *ImageOverlay) getName() string {
|
||
|
return o.Name
|
||
|
}
|
||
|
|
||
|
func (o *ImageOverlay) getBlendInTime() time.Duration {
|
||
|
return o.BlendIn
|
||
|
}
|
||
|
|
||
|
func (o *ImageOverlay) getBlendOutTime() time.Duration {
|
||
|
return o.BlendOut
|
||
|
}
|
||
|
|
||
|
func (o *ImageOverlay) getElement() *gst.Element {
|
||
|
return o.element
|
||
|
}
|
||
|
|
||
|
func (o *ImageOverlay) setElement(element *gst.Element) {
|
||
|
o.element = element
|
||
|
}
|
||
|
|
||
|
func (o *ImageOverlay) getType() string {
|
||
|
return "imageoverlay"
|
||
|
}
|