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.
-
Constructor Summary
ConstructorDescriptionAllocate 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 Buffer
Clip the buffer to the givenGstSegment
.static MemoryLayout
The memory layout of the native struct.static boolean
Maps an audiogstbuffer
so that it can be read or written and stores the result of the map operation inbuffer
.static boolean
map
(AudioBuffer buffer, AudioInfo info, Buffer gstbuffer, MapFlags... flags) Maps an audiogstbuffer
so that it can be read or written and stores the result of the map operation inbuffer
.Read the value of the fieldbuffer
.readInfo()
Read the value of the fieldinfo
.Read the value of the fieldmap_infos
.int
Read the value of the fieldn_planes
.long
Read the value of the fieldn_samples
.Read the value of the fieldplanes
.MapInfo[]
Read the value of the fieldpriv_map_infos_arr
.Read the value of the fieldpriv_planes_arr
.static boolean
reorderChannels
(Buffer buffer, AudioFormat format, AudioChannelPosition[] from, AudioChannelPosition[] to) Reordersbuffer
from the channel positionsfrom
to the channel positionsto
.static Buffer
Truncate the buffer to finally havesamples
number of samples, removing the necessary amount of samples from the end andtrim
number of samples from the beginning.void
unmap()
Unmaps an audio buffer that was previously mapped with gst_audio_buffer_map().void
writeBuffer
(Buffer buffer) Write a value in the fieldbuffer
.void
Write a value in the fieldinfo
.void
writeMapInfos
(MapInfo mapInfos) Write a value in the fieldmap_infos
.void
writeNPlanes
(int nPlanes) Write a value in the fieldn_planes
.void
writeNSamples
(long nSamples) Write a value in the fieldn_samples
.void
writePlanes
(MemorySegment planes) Write a value in the fieldplanes
.void
writePrivMapInfosArr
(MapInfo[] privMapInfosArr, Arena _arena) Write a value in the fieldpriv_map_infos_arr
.void
writePrivPlanesArr
(MemorySegment[] privPlanesArr, Arena _arena) Write a value in the fieldpriv_planes_arr
.Methods inherited from class io.github.jwharm.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 fieldinfo
nSamples
- value for the fieldnSamples
nPlanes
- value for the fieldnPlanes
planes
- value for the fieldplanes
buffer
- value for the fieldbuffer
mapInfos
- value for the fieldmapInfos
privPlanesArr
- value for the fieldprivPlanesArr
privMapInfosArr
- value for the fieldprivMapInfosArr
arena
- 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 fieldinfo
nSamples
- value for the fieldnSamples
nPlanes
- value for the fieldnPlanes
planes
- value for the fieldplanes
buffer
- value for the fieldbuffer
mapInfos
- value for the fieldmapInfos
privPlanesArr
- value for the fieldprivPlanesArr
privMapInfosArr
- value for the fieldprivMapInfosArr
-
-
Method Details
-
getMemoryLayout
The memory layout of the native struct.- Returns:
- the memory layout
-
readInfo
-
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
_arena
- to control the memory allocation scope
-
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
buffer
anymore.- Parameters:
buffer
- The buffer to clip.segment
- Segment inFormat.TIME
orFormat.DEFAULT
to 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:
null
if 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
public static boolean map(AudioBuffer buffer, AudioInfo info, Buffer gstbuffer, Set<MapFlags> flags) Maps an audiogstbuffer
so that it can be read or written and stores the result of the map operation inbuffer
.This is especially useful when the
gstbuffer
is in non-interleaved (planar) layout, in which case this function will use the information in thegstbuffer
's attachedGstAudioMeta
in order to map each channel in a separate "plane" inGstAudioBuffer
. If aGstAudioMeta
is not attached on thegstbuffer
, then it must be in interleaved layout.If a
GstAudioMeta
is attached, then theGstAudioInfo
on the meta is checked againstinfo
. Normally, they should be equal, but in case they are not, a g_critical will be printed and theGstAudioInfo
from 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 differentGstMemory
objects. 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
GstBuffer
is not ref'ed, but it is required to stay valid as long as it's mapped.- Parameters:
buffer
- pointer to aGstAudioBuffer
info
- the audio properties of the buffergstbuffer
- theGstBuffer
to be mappedflags
- the access mode for the memory- Returns:
true
if the map operation succeeded orfalse
on failure
-
map
Maps an audiogstbuffer
so that it can be read or written and stores the result of the map operation inbuffer
.This is especially useful when the
gstbuffer
is in non-interleaved (planar) layout, in which case this function will use the information in thegstbuffer
's attachedGstAudioMeta
in order to map each channel in a separate "plane" inGstAudioBuffer
. If aGstAudioMeta
is not attached on thegstbuffer
, then it must be in interleaved layout.If a
GstAudioMeta
is attached, then theGstAudioInfo
on the meta is checked againstinfo
. Normally, they should be equal, but in case they are not, a g_critical will be printed and theGstAudioInfo
from 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 differentGstMemory
objects. 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
GstBuffer
is not ref'ed, but it is required to stay valid as long as it's mapped.- Parameters:
buffer
- pointer to aGstAudioBuffer
info
- the audio properties of the buffergstbuffer
- theGstBuffer
to be mappedflags
- the access mode for the memory- Returns:
true
if the map operation succeeded orfalse
on failure
-
reorderChannels
public static boolean reorderChannels(Buffer buffer, AudioFormat format, AudioChannelPosition[] from, AudioChannelPosition[] to) Reordersbuffer
from the channel positionsfrom
to the channel positionsto
.from
andto
must contain the same number of positions and the same positions, only in a different order.buffer
must be writable.- Parameters:
buffer
- The buffer to reorder.format
- TheGstAudioFormat
of the buffer.from
- The channel positions in the buffer.to
- The channel positions to convert to.- Returns:
true
if the reordering was possible.
-
truncate
Truncate the buffer to finally havesamples
number of samples, removing the necessary amount of samples from the end andtrim
number 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
buffer
anymore.- 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
-
unmap
public void unmap()Unmaps an audio buffer that was previously mapped with gst_audio_buffer_map().
-