Skip to content

Conversation

@atishnazir
Copy link

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
		}
	},
})

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
Copy link
Author

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
Copy link

RSWilli commented Aug 24, 2023

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants