Add gstCaps.GetStructure

This commit is contained in:
castaneai
2021-02-20 05:59:13 +09:00
parent 541267549d
commit 72080a7aae
2 changed files with 44 additions and 0 deletions

View File

@@ -43,3 +43,12 @@ func (c *Caps) String() (str string) {
str = C.GoString((*C.char)(unsafe.Pointer(CStr)))
return
}
func (c *Caps) GetStructure(index int) (structure *Structure) {
Cstructure := C.gst_caps_get_structure(c.caps, C.uint(index))
structure = &Structure{
C: Cstructure,
}
return
}

35
caps_test.go Normal file
View File

@@ -0,0 +1,35 @@
package gst
import "testing"
func TestCaps_GetStructure(t *testing.T) {
pipeline, err := ParseLaunch("videotestsrc name=src ! video/x-raw,width=640,height=480 ! fakesink")
if err != nil {
t.Fatal(err)
}
src := pipeline.GetByName("src")
if src == nil {
t.Fatal("element 'src' not found")
}
pipeline.SetState(StatePlaying)
bus := pipeline.GetBus()
for {
msg := bus.Pull(MessageStateChanged)
_, newState, _ := msg.ParseStateChanged()
if newState == StatePlaying {
structure := src.GetStaticPad("src").GetCurrentCaps().GetStructure(0)
width, err := structure.GetInt("width")
if err != nil {
t.Fatal(err)
}
height, err := structure.GetInt("height")
if err != nil {
t.Fatal(err)
}
if width != 640 || height != 480 {
t.Fatal(err)
}
break
}
}
}