Class AudioBuffer
- All Implemented Interfaces:
Proxy
planes array. For interleaved buffers, the planes array only contains
one item, which is the pointer to the beginning of the buffer, and nPlanes
equals 1.
The different channels in planes are always in the GStreamer channel order.
- Since:
- 1.16
-
Constructor Summary
ConstructorsConstructorDescriptionAllocate a new AudioBuffer.AudioBuffer(Arena arena) Allocate a new AudioBuffer.AudioBuffer(MemorySegment address) Create a AudioBuffer proxy instance for the provided memory address.AudioBuffer(AudioInfo info, long nSamples, int nPlanes, MemorySegment planes, Buffer buffer, MapInfo mapInfos, MemorySegment[] privPlanesArr, MapInfo[] privMapInfosArr) Allocate a new AudioBuffer with the fields set to the provided values.AudioBuffer(AudioInfo info, long nSamples, int nPlanes, MemorySegment planes, Buffer buffer, MapInfo mapInfos, MemorySegment[] privPlanesArr, MapInfo[] privMapInfosArr, Arena arena) Allocate a new AudioBuffer with the fields set to the provided values. -
Method Summary
Modifier and TypeMethodDescriptionstatic @Nullable BufferClip the buffer to the givenGstSegment.static MemoryLayoutThe memory layout of the native struct.static booleanmap(AudioBuffer buffer, AudioInfo info, Buffer gstbuffer, int flags) Maps an audiogstbufferso that it can be read or written and stores the result of the map operation inbuffer.Read the value of the fieldbuffer.@Nullable AudioInforeadInfo()Read the value of the fieldinfo.Read the value of the fieldmap_infos.intRead the value of the fieldn_planes.longRead the value of the fieldn_samples.Read the value of the fieldplanes.@Nullable MapInfo @Nullable []Read the value of the fieldpriv_map_infos_arr.@Nullable MemorySegment @Nullable []Read the value of the fieldpriv_planes_arr.static booleanreorderChannels(Buffer buffer, AudioFormat format, @Nullable AudioChannelPosition @Nullable [] from, @Nullable AudioChannelPosition @Nullable [] to) Reordersbufferfrom the channel positionsfromto the channel positionsto.fromandtomust contain the same number of positions and the same positions, only in a different order.static BufferTruncate the buffer to finally havesamplesnumber of samples, removing the necessary amount of samples from the end andtrimnumber of samples from the beginning.voidunmap()Unmaps an audio buffer that was previously mapped with gst_audio_buffer_map().voidwriteBuffer(Buffer buffer) Write a value in the fieldbuffer.voidWrite a value in the fieldinfo.voidwriteMapInfos(MapInfo mapInfos) Write a value in the fieldmap_infos.voidwriteNPlanes(int nPlanes) Write a value in the fieldn_planes.voidwriteNSamples(long nSamples) Write a value in the fieldn_samples.voidwritePlanes(MemorySegment planes) Write a value in the fieldplanes.voidwritePrivMapInfosArr(@Nullable MapInfo @Nullable [] privMapInfosArr, Arena _arena) Write a value in the fieldpriv_map_infos_arr.voidwritePrivPlanesArr(@Nullable MemorySegment @Nullable [] privPlanesArr, Arena _arena) Write a value in the fieldpriv_planes_arr.Methods inherited from class org.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
AudioBuffer
Create a AudioBuffer proxy instance for the provided memory address.- Parameters:
address- the memory address of the native object
-
AudioBuffer
Allocate a new AudioBuffer.- Parameters:
arena- to control the memory allocation scope
-
AudioBuffer
public AudioBuffer()Allocate a new AudioBuffer. The memory is allocated withArena.ofAuto(). -
AudioBuffer
public AudioBuffer(AudioInfo info, long nSamples, int nPlanes, MemorySegment planes, Buffer buffer, MapInfo mapInfos, MemorySegment[] privPlanesArr, MapInfo[] privMapInfosArr, Arena arena) Allocate a new AudioBuffer with the fields set to the provided values.- Parameters:
info- value for the fieldinfonSamples- value for the fieldnSamplesnPlanes- value for the fieldnPlanesplanes- value for the fieldplanesbuffer- value for the fieldbuffermapInfos- value for the fieldmapInfosprivPlanesArr- value for the fieldprivPlanesArrprivMapInfosArr- value for the fieldprivMapInfosArrarena- to control the memory allocation scope
-
AudioBuffer
public AudioBuffer(AudioInfo info, long nSamples, int nPlanes, MemorySegment planes, Buffer buffer, MapInfo mapInfos, MemorySegment[] privPlanesArr, MapInfo[] privMapInfosArr) Allocate a new AudioBuffer with the fields set to the provided values. The memory is allocated withArena.ofAuto().- Parameters:
info- value for the fieldinfonSamples- value for the fieldnSamplesnPlanes- value for the fieldnPlanesplanes- value for the fieldplanesbuffer- value for the fieldbuffermapInfos- value for the fieldmapInfosprivPlanesArr- value for the fieldprivPlanesArrprivMapInfosArr- value for the fieldprivMapInfosArr
-
-
Method Details
-
getMemoryLayout
The memory layout of the native struct.- Returns:
- the memory layout
-
readInfo
Read the value of the fieldinfo.- Returns:
- The value of the field
info
-
writeInfo
Write a value in the fieldinfo.- Parameters:
info- The new value for the fieldinfo
-
readNSamples
public long readNSamples()Read the value of the fieldn_samples.- Returns:
- The value of the field
n_samples
-
writeNSamples
public void writeNSamples(long nSamples) Write a value in the fieldn_samples.- Parameters:
nSamples- The new value for the fieldn_samples
-
readNPlanes
public int readNPlanes()Read the value of the fieldn_planes.- Returns:
- The value of the field
n_planes
-
writeNPlanes
public void writeNPlanes(int nPlanes) Write a value in the fieldn_planes.- Parameters:
nPlanes- The new value for the fieldn_planes
-
readPlanes
Read the value of the fieldplanes.- Returns:
- The value of the field
planes
-
writePlanes
Write a value in the fieldplanes.- Parameters:
planes- The new value for the fieldplanes
-
readBuffer
Read the value of the fieldbuffer.- Returns:
- The value of the field
buffer
-
writeBuffer
Write a value in the fieldbuffer.- Parameters:
buffer- The new value for the fieldbuffer
-
readMapInfos
Read the value of the fieldmap_infos.- Returns:
- The value of the field
map_infos
-
writeMapInfos
Write a value in the fieldmap_infos.- Parameters:
mapInfos- The new value for the fieldmap_infos
-
readPrivPlanesArr
Read the value of the fieldpriv_planes_arr.- Returns:
- The value of the field
priv_planes_arr
-
writePrivPlanesArr
Write a value in the fieldpriv_planes_arr.- Parameters:
privPlanesArr- The new value for the fieldpriv_planes_arr
-
readPrivMapInfosArr
Read the value of the fieldpriv_map_infos_arr.- Returns:
- The value of the field
priv_map_infos_arr
-
writePrivMapInfosArr
-
clip
Clip the buffer to the givenGstSegment.After calling this function the caller does not own a reference to
bufferanymore.- Parameters:
buffer- The buffer to clip.segment- Segment inFormat.TIMEorFormat.DEFAULTto which the buffer should be clipped.rate- sample rate.bpf- size of one audio frame in bytes. This is the size of one sample * number of channels.- Returns:
nullif the buffer is completely outside the configured segment, otherwise the clipped buffer is returned.If the buffer has no timestamp, it is assumed to be inside the segment and is not clipped
-
map
Maps an audiogstbufferso that it can be read or written and stores the result of the map operation inbuffer.This is especially useful when the
gstbufferis in non-interleaved (planar) layout, in which case this function will use the information in thegstbuffer'sattachedGstAudioMetain order to map each channel in a separate "plane" inGstAudioBuffer. If aGstAudioMetais not attached on thegstbuffer,then it must be in interleaved layout.If a
GstAudioMetais attached, then theGstAudioInfoon the meta is checked againstinfo.Normally, they should be equal, but in case they are not, a g_critical will be printed and theGstAudioInfofrom the meta will be used.In non-interleaved buffers, it is possible to have each channel on a separate
GstMemory. In this case, each memory will be mapped separately to avoid copying their contents in a larger memory area. Do note though that it is not supported to have a single channel spanning over two or more differentGstMemoryobjects. Although the map operation will likely succeed in this case, it will be highly sub-optimal and it is recommended to merge all the memories in the buffer before calling this function.Note: The actual
GstBufferis not ref'ed, but it is required to stay valid as long as it's mapped.- Parameters:
buffer- pointer to aGstAudioBufferinfo- the audio properties of the buffergstbuffer- theGstBufferto be mappedflags- the access mode for the memory- Returns:
trueif the map operation succeeded orfalseon failure- Since:
- 1.16
-
reorderChannels
public static boolean reorderChannels(Buffer buffer, AudioFormat format, @Nullable AudioChannelPosition @Nullable [] from, @Nullable AudioChannelPosition @Nullable [] to) Reordersbufferfrom the channel positionsfromto the channel positionsto.fromandtomust contain the same number of positions and the same positions, only in a different order.buffermust be writable.- Parameters:
buffer- The buffer to reorder.format- TheGstAudioFormatof the buffer.from- The channel positions in the buffer.to- The channel positions to convert to.- Returns:
trueif the reordering was possible.
-
truncate
Truncate the buffer to finally havesamplesnumber of samples, removing the necessary amount of samples from the end andtrimnumber of samples from the beginning.This function does not know the audio rate, therefore the caller is responsible for re-setting the correct timestamp and duration to the buffer. However, timestamp will be preserved if trim == 0, and duration will also be preserved if there is no trimming to be done. Offset and offset end will be preserved / updated.
After calling this function the caller does not own a reference to
bufferanymore.- Parameters:
buffer- The buffer to truncate.bpf- size of one audio frame in bytes. This is the size of one sample * number of channels.trim- the number of samples to remove from the beginning of the buffersamples- the final number of samples that should exist in this buffer or -1 to use all the remaining samples if you are only removing samples from the beginning.- Returns:
- the truncated buffer
- Since:
- 1.16
-
unmap
public void unmap()Unmaps an audio buffer that was previously mapped with gst_audio_buffer_map().- Since:
- 1.16
-