tinyzimmer / go-gst

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

Fix: replicate gst_sample_get_buffer{,list} returns NULL semantic #50

Open atishnazir opened 2 years ago

atishnazir commented 2 years ago

gst_sample_get_buffer{,list} returns NULL if a buffer{,list} has not been set. Previous go-gst behaviour wrapped this NULL pointer in the respective go-gst proxy object.

This causes a problem with AppSink when one needs to disambiguate between whether a GstSample contains a GstBufferList, a GstBuffer or indeed nothing at all. For example:

sink := app.SinkFromElement(element)
sink.SetBufferListSupport(true)
sink.SetCallbacks(&app.SinkCallbacks{
    NewSampleFunc: func(sink *app.Sink) gst.FlowReturn {
        if sample := sink.PullSample(); sample == nil {
            return gst.FlowEOS
        } else if bufferList := sample.GetBufferList(); bufferList != nil {
            // consume bufferlist
            return gst.FlowOK
        } else if buffer := sample.GetBuffer(); buffer != nil {
            // consume buffer
            return gst.FlowOK
        } else {
            return gst.FlowError
        }
    },
})
atishnazir commented 2 years ago

I debated whether a better fix would be to be to adjust the semantic of FromGstBufferUnsafeNone and FromGstBufferListUnsafeNone to return nil when called with C.NULL but felt the impact would be more far reaching.

RSWilli commented 1 year ago

@atishnazir please recreate this PR for https://github.com/go-gst/go-gst (where future development of the bindings will take place) if you think it is necessary.