mirror of
https://github.com/go-gst/go-gst.git
synced 2025-10-06 00:17:00 +08:00
change emit docs, add tests for signal emits
This commit is contained in:
@@ -200,12 +200,14 @@ func (e *Element) ContinueState(ret StateChangeReturn) StateChangeReturn {
|
|||||||
return StateChangeReturn(C.gst_element_continue_state(e.Instance(), C.GstStateChangeReturn(ret)))
|
return StateChangeReturn(C.gst_element_continue_state(e.Instance(), C.GstStateChangeReturn(ret)))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Emit is a wrapper around g_signal_emitv() and emits the signal specified by the string s to an Object. Arguments to
|
// Emit is a wrapper around g_signal_emitv() and emits the signal
|
||||||
// callback functions connected to this signal must be specified in args. Emit() returns an interface{} which must be
|
// specified by the string s to an Object. This means that it performs identically to
|
||||||
// type asserted as the Go equivalent type to the return value for native C callback.
|
// g_signal_emit_by_name. Arguments to callback functions connected to this signal must
|
||||||
|
// be specified in args. Emit() returns an interface{} which contains the go equivalent of the C return value.
|
||||||
//
|
//
|
||||||
// Note that this code is unsafe in that the types of values in args are not checked against whether they are suitable
|
// Make sure that the Types are known to go-glib. Special types need to be registered with
|
||||||
// for the callback.
|
// RegisterGValueMarshalers before calling Emit. Sub libraries of go-gst (sdp, rtp, webrtc, base, etc.)
|
||||||
|
// register their types when they are imported via init() functions.
|
||||||
func (e *Element) Emit(signal string, args ...interface{}) (interface{}, error) {
|
func (e *Element) Emit(signal string, args ...interface{}) (interface{}, error) {
|
||||||
// We are wrapping this for the same reason as Connect.
|
// We are wrapping this for the same reason as Connect.
|
||||||
if e.TypeFromInstance() != glib.Type(C.GST_TYPE_ELEMENT) {
|
if e.TypeFromInstance() != glib.Type(C.GST_TYPE_ELEMENT) {
|
||||||
|
95
gst/gst_element_emit_test.go
Normal file
95
gst/gst_element_emit_test.go
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
package gst_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/go-gst/go-glib/glib"
|
||||||
|
"github.com/go-gst/go-gst/gst"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestSignalEmitSimpleReturnValue(t *testing.T) {
|
||||||
|
gst.Init(nil)
|
||||||
|
webrtcbin, err := gst.NewElement("webrtcbin")
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
okI, err := webrtcbin.Emit("add-turn-server", "turn://user:password@host:1234")
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
ok := okI.(bool)
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
t.Fatal("Failed to add turn server")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSignalEmitGObjectReturnValue(t *testing.T) {
|
||||||
|
gst.Init(nil)
|
||||||
|
|
||||||
|
elements := []string{
|
||||||
|
"rtpbin", "name=rtpbin",
|
||||||
|
|
||||||
|
"videotestsrc", "!", "videoconvert", "!", "queue", "!",
|
||||||
|
"x264enc", "bframes=0", "speed-preset=ultrafast", "tune=zerolatency", "name=encoder", "!", "queue", "!", "rtph264pay", "config-interval=1", "!", "rtpbin.send_rtp_sink_0", "rtpbin.send_rtp_src_0", "!",
|
||||||
|
|
||||||
|
"udpsink", "host=127.0.0.1", "port=5510", "sync=false", "async=false", "rtpbin.send_rtcp_src_0", "!",
|
||||||
|
|
||||||
|
"udpsink", "host=127.0.0.1", "port=5511", "sync=false", "async=false",
|
||||||
|
|
||||||
|
"udpsrc", "port=5511", "caps=\"application/x-rtcp\"", "!", "rtpbin.recv_rtcp_sink_0",
|
||||||
|
}
|
||||||
|
|
||||||
|
pipeline, err := gst.NewPipelineFromString(strings.Join(elements, " "))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
rtpbin, err := pipeline.GetElementByName("rtpbin")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
errchan := make(chan error)
|
||||||
|
|
||||||
|
rtpbin.Connect("on-new-ssrc", func(bin *gst.Element, sessionID uint, ssrc uint32) {
|
||||||
|
retI, err := rtpbin.Emit("get-internal-session", sessionID)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
errchan <- err
|
||||||
|
}
|
||||||
|
|
||||||
|
rtpSession, ok := retI.(*glib.Object)
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
errchan <- errors.New("could not cast return value to *glib.Object")
|
||||||
|
}
|
||||||
|
|
||||||
|
bw, err := rtpSession.GetProperty("bandwidth")
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
errchan <- err
|
||||||
|
}
|
||||||
|
|
||||||
|
_ = bw
|
||||||
|
|
||||||
|
close(errchan)
|
||||||
|
})
|
||||||
|
|
||||||
|
pipeline.SetState(gst.StatePlaying)
|
||||||
|
|
||||||
|
err = <-errchan
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
pipeline.SetState(gst.StateNull)
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user