gstreamer-java / gst1-java-core

Java bindings for GStreamer 1.x
GNU Lesser General Public License v3.0
194 stars 72 forks source link

Buffer creation from another buffer #132

Open hauges opened 5 years ago

hauges commented 5 years ago

I want to construct a new org.freedesktop.gstreamer.Buffer object with data from another Buffer. For example, with the python library, I could do something like this:

buffer = gst.Buffer(otherBuffer.data)

Is there any way I could do this using the java library?

neilcsmith-net commented 5 years ago

Is that copying the buffer data or creating a buffer that wraps the same data? Can you provide a link, ideally to the C API equivalent. You should be able to copy by creating a buffer and mapping the ByteBuffers, one with write, I think. You might also look at the GstBufferAPI in lowlevel to see if it provides anything extra you need.

hauges commented 5 years ago

I want to copy the buffer data and create a new buffer containing that data along with other data I pull from my system. I thinkGstBufferAPI.MapInfoStruct may be what I'm looking for (it has a data field), but I am too unfamiliar with the com.sun.jna.Pointer API to create a new GstBufferAPI.MapInfoStruct.

I couldn't find an equivalent C API, but this is the python documentation on buffer.data.

hauges commented 5 years ago

It also appears there is no way I can inject a MapInfoStruct into a Buffer.

neilcsmith-net commented 5 years ago

You don't need to use the structs, but we are missing low level mappings for copying.

You should be able to map the source buffer to get the ByteBuffer, create a new Buffer of that size, map the new buffer as writable, copy one ByteBuffer into the other, and unmap both. Not tried it though!

hauges commented 5 years ago

Thanks so much! Unfortunately my testing for this is now blocked by #133