tinyzimmer / go-gst

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

Implement gst_element_get_parent or gst_element_get_parent #58

Closed db-tech closed 1 year ago

db-tech commented 1 year ago

Hi, I really would like to contribute to this project, but I am fairly new to using cgo and to contributing on Github in general.

I am trying to implement the function gst_element_get_parent or gst_element_get_parent. The reason is the following. I have added an event probe to the pipeline and want to update a table with all the elements and the states. The content of the table should look like this:

type GstElementState struct {
    Pipeline  string `json:"pipeline"`
    ParentBin   string `json:"parentBin"`
    Element   string `json:"element"`
    OldState  string `json:"oldState"`
    NewState  string `json:"newState"`
    Timestamp string `json:"timestamp"`
}

parentBin should be the name of the parent of the element (if there is one).

For that matter, I've already added a Src method in gst_message.go

func (m *Message) Src() *Object { return wrapObject(toGObject(unsafe.Pointer(m.Instance().src))) }

This seems to work, although I am not sure if this is the right way to do it.

Then I tried to implement the gst_element_get_parent but failed with:

 could not determine kind of name for C.gst_element_get_parent

I guess this has something to do with the fact that this is c macro?

Then I tried to implement C.gst_object_get_parent like this:

func (e *Element) GetParent() *Element {
    elem := C.gst_object_get_parent(e.Instance())
    if elem == nil {
        return nil
    }
    return FromGstElementUnsafeFull(unsafe.Pointer(elem))
}

But it seems there are type issues.

Some help would be much appreciated, even if it's just some links where to best learn more about this stuff. Thanks!

brucekim commented 1 year ago

I will check soon

brucekim commented 1 year ago

As you mentioned, I checked gst_element_get_parent is a macro of gst_object_get_parent. I simply added your code in my go-gst and compiled without any error. Where did you face such error? It would be more easier to understand if you leave a sample code.

https://gstreamer.freedesktop.org/documentation/gstreamer/gstelement.html?gi-language=c#gst_element_get_parent