ziutek / gst

Go bindings for GStreamer (retired: currently I don't use/develop this package)
Other
169 stars 48 forks source link

parse_launch implementation ? #1

Open metal3d opened 11 years ago

metal3d commented 11 years ago

Hi, thanks for this module.

Have you planned to integrate parse_launch function ?

Thanks

ziutek commented 11 years ago

I've just added ParseLaunch method, but have no time to test it.

metal3d commented 11 years ago

That's cool, I will try and give you feedback. Thanks a lot

metal3d commented 11 years ago

Ok, it seems to work. There is only a little "feature" that doesn't work (or maybe I'm doing it wrong).

I want to get an element that I gave name => "... ! plugins name=foo ! ..."

How to get "foo" element ? GetPad isn't ok (because foo is not a pad). The goal is to get events from selected elements... for example from "vader" element that send "vader_start" and "vader_stop" when microphone detects sound.

Just to be sure: Is it normal that ParseLaunch return gst.Element and not Pipeline ?

But, I can confirm that ParseLaunch is working :)

ziutek commented 11 years ago

How to get "foo" element ?

Hmm... I always build pipeline from individual elements using Add and Link* methods, so I've never had such problem. There is C.gst_bin_get_by_name function that returns element by name. I'll try to add this function to the gst.

Just to be sure: Is it normal that ParseLaunch return gst.Element and not Pipeline ? See: http://gstreamer.freedesktop.org/data/doc/gstreamer/head/gstreamer/html/gstreamer-GstParse.html

ziutek commented 11 years ago

I've just added Bin.GetByName method but haven't tested it yet. Try it and report if it works.

metal3d commented 11 years ago

I just tried. I used to work with python-gst and parse_launch returns a pipeline object, that's why I was wrong. You're right, C implementation returns Element.

Ok so I just tried this:

package main

import "github.com/ziutek/gst"
import "github.com/ziutek/glib"
import "fmt"

func vader_start(arg0 uint64) {
    fmt.Println("Sound detected")
}

func vader_stop(arg0 uint64) {
    fmt.Println("Sound stopped")
}

func main() {
    b := gst.NewBin("mybin")
    g,_ := gst.ParseLaunch("autoaudiosrc ! vader name=v auto_threshold=true ! fakesink ")
    b.Add(g)

    vader := b.GetByName("v")
    vader.ConnectNoi("vader_start", vader_start, nil)
    vader.ConnectNoi("vader_stop", vader_stop, nil)

    g.SetState(gst.STATE_PLAYING)
    glib.NewMainLoop(nil).Run()
}

When microphone detect sound, I see "Sound detected"... and nothing append afterward.

If you try:

gst-launch -v autoaudiosrc ! vader name=v auto_threshold=true ! fakesink

you will see that it works... events on sound start/stop are well captured. Did I do something wrong ?

Thanks a lot for you answers, implementation and help :)

metal3d commented 11 years ago

PS: note that GetByName works like a charm

ziutek commented 11 years ago

I've modified ParseLaunch to return Pipeline. Now you can use GetByName directly on it. I don't known how dose Pipeline work when embed in Bin, like in your example code.

metal3d commented 11 years ago

That's very cool. I'll try tonight (it's 17:26 in France) and I'll give you some feedback as soon as I tested.

metal3d commented 11 years ago

Everything is now ok ! I see "Sound detected" and "Sound stopped" as expected. This is my test code :

package main

import "github.com/ziutek/gst"
import "github.com/ziutek/glib"
import "fmt"

func vader_start(arg0 uint64) {
    fmt.Println("Sound detected")
}

func vader_stop(arg0 uint64) {
    fmt.Println("Sound stopped")
}

func main() {
    g,_ := gst.ParseLaunch("autoaudiosrc ! vader name=v auto_threshold=true ! fakesink ")

    vader := g.GetByName("v")
    vader.ConnectNoi("vader_start", vader_start, nil)
    vader.ConnectNoi("vader_stop", vader_stop, nil)

    g.SetState(gst.STATE_PLAYING)
    glib.NewMainLoop(nil).Run()
}

Once again: thanks !