Class AudioBuffer

java.lang.Object
org.javagi.base.ProxyInstance
org.freedesktop.gstreamer.audio.AudioBuffer
All Implemented Interfaces:
Proxy

@Generated("org.javagi.JavaGI") public class AudioBuffer extends ProxyInstance

A structure containing the result of an audio buffer map operation, which is executed with gst_audio_buffer_map(). For non-interleaved (planar) buffers, the beginning of each channel in the buffer has its own pointer in the 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 Details

    • AudioBuffer

      public AudioBuffer(MemorySegment address)
      Create a AudioBuffer proxy instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • AudioBuffer

      public AudioBuffer(Arena arena)
      Allocate a new AudioBuffer.
      Parameters:
      arena - to control the memory allocation scope
    • AudioBuffer

      public AudioBuffer()
      Allocate a new AudioBuffer. The memory is allocated with Arena.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 field info
      nSamples - value for the field nSamples
      nPlanes - value for the field nPlanes
      planes - value for the field planes
      buffer - value for the field buffer
      mapInfos - value for the field mapInfos
      privPlanesArr - value for the field privPlanesArr
      privMapInfosArr - value for the field privMapInfosArr
      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 with Arena.ofAuto().
      Parameters:
      info - value for the field info
      nSamples - value for the field nSamples
      nPlanes - value for the field nPlanes
      planes - value for the field planes
      buffer - value for the field buffer
      mapInfos - value for the field mapInfos
      privPlanesArr - value for the field privPlanesArr
      privMapInfosArr - value for the field privMapInfosArr
  • Method Details

    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • readInfo

      public @Nullable AudioInfo readInfo()
      Read the value of the field info.
      Returns:
      The value of the field info
    • writeInfo

      public void writeInfo(@Nullable AudioInfo info)
      Write a value in the field info.
      Parameters:
      info - The new value for the field info
    • readNSamples

      public long readNSamples()
      Read the value of the field n_samples.
      Returns:
      The value of the field n_samples
    • writeNSamples

      public void writeNSamples(long nSamples)
      Write a value in the field n_samples.
      Parameters:
      nSamples - The new value for the field n_samples
    • readNPlanes

      public int readNPlanes()
      Read the value of the field n_planes.
      Returns:
      The value of the field n_planes
    • writeNPlanes

      public void writeNPlanes(int nPlanes)
      Write a value in the field n_planes.
      Parameters:
      nPlanes - The new value for the field n_planes
    • readPlanes

      public MemorySegment readPlanes()
      Read the value of the field planes.
      Returns:
      The value of the field planes
    • writePlanes

      public void writePlanes(MemorySegment planes)
      Write a value in the field planes.
      Parameters:
      planes - The new value for the field planes
    • readBuffer

      public Buffer readBuffer()
      Read the value of the field buffer.
      Returns:
      The value of the field buffer
    • writeBuffer

      public void writeBuffer(Buffer buffer)
      Write a value in the field buffer.
      Parameters:
      buffer - The new value for the field buffer
    • readMapInfos

      public MapInfo readMapInfos()
      Read the value of the field map_infos.
      Returns:
      The value of the field map_infos
    • writeMapInfos

      public void writeMapInfos(MapInfo mapInfos)
      Write a value in the field map_infos.
      Parameters:
      mapInfos - The new value for the field map_infos
    • readPrivPlanesArr

      public @Nullable MemorySegment @Nullable [] readPrivPlanesArr()
      Read the value of the field priv_planes_arr.
      Returns:
      The value of the field priv_planes_arr
    • writePrivPlanesArr

      public void writePrivPlanesArr(@Nullable MemorySegment @Nullable [] privPlanesArr, Arena _arena)
      Write a value in the field priv_planes_arr.
      Parameters:
      privPlanesArr - The new value for the field priv_planes_arr
    • readPrivMapInfosArr

      public @Nullable MapInfo @Nullable [] readPrivMapInfosArr()
      Read the value of the field priv_map_infos_arr.
      Returns:
      The value of the field priv_map_infos_arr
    • writePrivMapInfosArr

      public void writePrivMapInfosArr(@Nullable MapInfo @Nullable [] privMapInfosArr, Arena _arena)
      Write a value in the field priv_map_infos_arr.
      Parameters:
      privMapInfosArr - The new value for the field priv_map_infos_arr
    • clip

      public static @Nullable Buffer clip(Buffer buffer, Segment segment, int rate, int bpf)

      Clip the buffer to the given GstSegment.

      After calling this function the caller does not own a reference to buffer anymore.

      Parameters:
      buffer - The buffer to clip.
      segment - Segment in Format.TIME or Format.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, int flags)

      Maps an audio gstbuffer so that it can be read or written and stores the result of the map operation in buffer.

      This is especially useful when the gstbuffer is in non-interleaved (planar) layout, in which case this function will use the information in the gstbuffer's attached GstAudioMeta in order to map each channel in a separate "plane" in GstAudioBuffer. If a GstAudioMeta is not attached on the gstbuffer, then it must be in interleaved layout.

      If a GstAudioMeta is attached, then the GstAudioInfo on the meta is checked against info. Normally, they should be equal, but in case they are not, a g_critical will be printed and the GstAudioInfo 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 different GstMemory 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 a GstAudioBuffer
      info - the audio properties of the buffer
      gstbuffer - the GstBuffer to be mapped
      flags - the access mode for the memory
      Returns:
      true if the map operation succeeded or false on failure
      Since:
      1.16
    • reorderChannels

      public static boolean reorderChannels(Buffer buffer, AudioFormat format, @Nullable AudioChannelPosition @Nullable [] from, @Nullable AudioChannelPosition @Nullable [] to)
      Reorders buffer from the channel positions from to the channel positions to. from and to 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 - The GstAudioFormat 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

      public static Buffer truncate(Buffer buffer, int bpf, long trim, long samples)

      Truncate the buffer to finally have samples number of samples, removing the necessary amount of samples from the end and trim 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 buffer
      samples - 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