tinyzimmer / go-gst

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

Invalid type guint for property flags #28

Closed jwmwalrus closed 2 years ago

jwmwalrus commented 2 years ago

Hi.

I'm trying to follow this tutorial using go-gst.

When I try to set the playbin flags, I always get "Invalid type guint for property flags".

Is there a workaround to the type restriction set by the SetProperty method, or is a proper enum for GstPlayFlags needed here?

A minimal example of my issue follows:

package main

import (
    "fmt"

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

func main() {
    gst.Init(nil)

    mainLoop := glib.NewMainLoop(glib.MainContextDefault(), false)

    playbin, err := gst.NewElementWithName("playbin", "my-playbin")
    if err != nil {
        panic(err)
    }

    if playbin == nil {
        panic("Not all elements could be created")
    }

    flags, err := playbin.GetProperty("flags")
    if err != nil {
        panic(err)
    }
    flagstype, err := playbin.GetPropertyType("flags")
    if err != nil {
        panic(err)
    }
    fmt.Println("flags type:", flagstype.Name())
    fmt.Println("flags value:", flags)
    iflags := flags.(uint)
    iflags = iflags &^ (1 << 0) // no video
    iflags = iflags | (1 << 1)  // yes audio
    iflags = iflags &^ (1 << 2) // no text
    fmt.Println("new flags value:", iflags)
    err = playbin.Set("flags", iflags)
    if err != nil {
        panic(err)
    }

    playbin.Set("uri", "https://www.freedesktop.org/software/gstreamer-sdk/data/media/sintel_trailer-480p.ogv")

    bus := playbin.GetBus()

    state := gst.StatePlaying
    if err := playbin.SetState(state); err != nil {
        panic(err)
    }

    bus.AddWatch(func(msg *gst.Message) bool {
        return true
    })

    mainLoop.Run()

    bus.RemoveWatch()

    state = gst.StateNull
    playbin.SetState(state)
}
tinyzimmer commented 2 years ago

Sorry for the late reply, you can try SetArg instead. It lets Gstreamer do the type casting internally.

jwmwalrus commented 2 years ago

Hmm... Using SetArg works. Thanks a lot for the tip.