Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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