Skip to content

Commit

Permalink
Merge pull request #28 from castaneai/caps-structure
Browse files Browse the repository at this point in the history
Add gstCaps.GetStructure
  • Loading branch information
notedit authored Feb 20, 2021
2 parents 5412675 + 72080a7 commit 4c7f44b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
9 changes: 9 additions & 0 deletions caps.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 35 additions & 0 deletions caps_test.go
Original file line number Diff line number Diff line change
@@ -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
}
}
}

0 comments on commit 4c7f44b

Please sign in to comment.