Functions¶
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Details¶
- GstAudio.audio_buffer_clip(buffer, segment, rate, bpf)[source]¶
- Parameters:
buffer (
Gst.Buffer
) – The buffer to clip.segment (
Gst.Segment
) – Segment inGst.Format.TIME
orGst.Format.DEFAULT
to which the buffer should be clipped.rate (
int
) – sample rate.bpf (
int
) – size of one audio frame in bytes. This is the size of one sample * number of channels.
- Returns:
None
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
- Return type:
Gst.Buffer
orNone
Clip the buffer to the given
Gst.Segment
.After calling this function the caller does not own a reference to buffer anymore.
- GstAudio.audio_buffer_map(info, gstbuffer, flags)[source]¶
- Parameters:
info (
GstAudio.AudioInfo
) – the audio properties of the buffergstbuffer (
Gst.Buffer
) – theGst.Buffer
to be mappedflags (
Gst.MapFlags
) – the access mode for the memory
- Returns:
True
if the map operation succeeded orFalse
on failure- buffer:
pointer to a
GstAudio.AudioBuffer
- Return type:
(
bool
, buffer:GstAudio.AudioBuffer
)
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
GstAudio.AudioMeta
in order to map each channel in a separate “plane” inGstAudio.AudioBuffer
. If aGstAudio.AudioMeta
is not attached on the gstbuffer, then it must be in interleaved layout.If a
GstAudio.AudioMeta
is attached, then theGstAudio.AudioInfo
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 theGstAudio.AudioInfo
from the meta will be used.In non-interleaved buffers, it is possible to have each channel on a separate
Gst.Memory
. 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 differentGst.Memory
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
Gst.Buffer
is not ref’ed, but it is required to stay valid as long as it’s mapped.New in version 1.16.
- GstAudio.audio_buffer_reorder_channels(buffer, format, from_, to)[source]¶
- Parameters:
buffer (
Gst.Buffer
) – The buffer to reorder.format (
GstAudio.AudioFormat
) – TheGstAudio.AudioFormat
of the buffer.from ([
GstAudio.AudioChannelPosition
]) – The channel positions in the buffer.to ([
GstAudio.AudioChannelPosition
]) – The channel positions to convert to.
- Returns:
True
if the reordering was possible.- Return type:
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.
- GstAudio.audio_buffer_truncate(buffer, bpf, trim, samples)[source]¶
- Parameters:
buffer (
Gst.Buffer
) – The buffer to truncate.bpf (
int
) – size of one audio frame in bytes. This is the size of one sample * number of channels.trim (
int
) – the number of samples to remove from the beginning of the buffersamples (
int
) – 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
- Return type:
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.
New in version 1.16.
- GstAudio.audio_channel_get_fallback_mask(channels)[source]¶
- Parameters:
channels (
int
) – the number of channels- Returns:
a fallback channel-mask for channels or 0 when there is no mask and mono.
- Return type:
Get the fallback channel-mask for the given number of channels.
This function returns a reasonable fallback channel-mask and should be called as a last resort when the specific channel map is unknown.
New in version 1.8.
- GstAudio.audio_channel_positions_from_mask(channel_mask, position)[source]¶
- Parameters:
channel_mask (
int
) – The input channel_maskposition ([
GstAudio.AudioChannelPosition
]) – TheGstAudio.AudioChannelPosition
s
- Returns:
True
if channel and channel mask are valid and could be converted- Return type:
Convert the channels present in channel_mask to a position array (which should have at least channels entries ensured by caller). If channel_mask is set to 0, it is considered as ‘not present’ for purpose of conversion. A partially valid channel_mask with less bits set than the number of channels is considered valid.
- GstAudio.audio_channel_positions_to_mask(position, force_order)[source]¶
- Parameters:
position ([
GstAudio.AudioChannelPosition
]) – TheGstAudio.AudioChannelPositions
force_order (
bool
) – Only consider the GStreamer channel order.
- Returns:
True
if the channel positions are valid and could be converted.- channel_mask:
the output channel mask
- Return type:
Convert the position array of channels channels to a bitmask.
If force_order is
True
it additionally checks if the channels are in the order required by GStreamer.
- GstAudio.audio_channel_positions_to_string(position)[source]¶
- Parameters:
position ([
GstAudio.AudioChannelPosition
]) – TheGstAudio.AudioChannelPositions
to convert.- Returns:
a newly allocated string representing position
- Return type:
Converts position to a human-readable string representation for debugging purposes.
New in version 1.10.
- GstAudio.audio_channel_positions_to_valid_order(position)[source]¶
- Parameters:
position ([
GstAudio.AudioChannelPosition
]) – The channel positions to reorder to.- Returns:
True
if the channel positions are valid and reordering was successful.- Return type:
Reorders the channel positions in position from any order to the GStreamer channel order.
- GstAudio.audio_check_valid_channel_positions(position, force_order)[source]¶
- Parameters:
position ([
GstAudio.AudioChannelPosition
]) – TheGstAudio.AudioChannelPositions
to check.force_order (
bool
) – Only consider the GStreamer channel order.
- Returns:
True
if the channel positions are valid.- Return type:
Checks if position contains valid channel positions for channels channels. If force_order is
True
it additionally checks if the channels are in the order required by GStreamer.
- GstAudio.audio_format_build_integer(sign, endianness, width, depth)[source]¶
- Parameters:
sign (
bool
) – signed or unsigned formatendianness (
int
) –GLib.LITTLE_ENDIAN
orGLib.BIG_ENDIAN
width (
int
) – amount of bits used per sampledepth (
int
) – amount of used bits in width
- Returns:
a
GstAudio.AudioFormat
orGstAudio.AudioFormat.UNKNOWN
when no audio format exists with the given parameters.- Return type:
Construct a
GstAudio.AudioFormat
with given parameters.
- GstAudio.audio_format_fill_silence(info, dest)[source]¶
- Parameters:
info (
GstAudio.AudioFormatInfo
) – aGstAudio.AudioFormatInfo
dest (
bytes
) – a destination to fill
Fill length bytes in dest with silence samples for info.
Deprecated since version 1.20: Use
GstAudio.AudioFormatInfo.fill_silence
() instead.
- GstAudio.audio_format_from_string(format)[source]¶
- Parameters:
format (
str
) – a format string- Returns:
the
GstAudio.AudioFormat
for format orGstAudio.AudioFormat.UNKNOWN
when the string is not a known format.- Return type:
Convert the format string to its
GstAudio.AudioFormat
.
- GstAudio.audio_format_get_info(format)[source]¶
- Parameters:
format (
GstAudio.AudioFormat
) – aGstAudio.AudioFormat
- Returns:
The
GstAudio.AudioFormatInfo
for format.- Return type:
Get the
GstAudio.AudioFormatInfo
for format
- GstAudio.audio_format_to_string(format)[source]¶
- Parameters:
format (
GstAudio.AudioFormat
) –- Return type:
- GstAudio.audio_formats_raw()[source]¶
- Returns:
an array of
GstAudio.AudioFormat
- Return type:
Return all the raw audio formats supported by GStreamer.
New in version 1.18.
- GstAudio.audio_get_channel_reorder_map(from_, to, reorder_map)[source]¶
- Parameters:
from ([
GstAudio.AudioChannelPosition
]) – The channel positions to reorder from.to ([
GstAudio.AudioChannelPosition
]) – The channel positions to reorder to.reorder_map ([
int
]) – Pointer to the reorder map.
- Returns:
True
if the channel positions are valid and reordering is possible.- Return type:
Returns a reorder map for from to to that can be used in custom channel reordering code, e.g. to convert from or to the GStreamer channel order. from and to must contain the same number of positions and the same positions, only in a different order.
The resulting reorder_map can be used for reordering by assigning channel i of the input to channel reorder_map[i] of the output.
- GstAudio.audio_iec61937_frame_size(spec)[source]¶
- Parameters:
spec (
GstAudio.AudioRingBufferSpec
) – the ringbufer spec- Returns:
the size or 0 if the given type is not supported or cannot be payloaded.
- Return type:
Calculated the size of the buffer expected by
GstAudio.audio_iec61937_payload
() for payloading type from spec.
- GstAudio.audio_iec61937_payload(src, dst, spec, endianness)[source]¶
- Parameters:
src (
bytes
) – a buffer containing the data to payloaddst (
bytes
) – the destination buffer to store the payloaded contents in. Should not overlap with srcspec (
GstAudio.AudioRingBufferSpec
) – the ringbufer spec for srcendianness (
int
) – the expected byte order of the payloaded data
- Returns:
transfer-full:
True
if the payloading was successful,False
otherwise.- Return type:
Payloads src in the form specified by IEC 61937 for the type from spec and stores the result in dst. src must contain exactly one frame of data and the frame is not checked for errors.
- GstAudio.audio_info_from_caps(caps)[source]¶
- Parameters:
- Returns:
True
if caps could be parsed- info:
- Return type:
(
bool
, info:GstAudio.AudioInfo
)
Parse caps and update info.
- GstAudio.audio_info_init()[source]¶
- Returns:
- Return type:
info:
GstAudio.AudioInfo
Initialize info with default values.
- GstAudio.audio_level_meta_api_get_type()[source]¶
- Returns:
- Return type:
Return the
GObject.GType
associated withGstAudio.AudioLevelMeta
.New in version 1.20.
- GstAudio.audio_level_meta_get_info()[source]¶
- Returns:
- Return type:
Return the
Gst.MetaInfo
associated withGstAudio.AudioLevelMeta
.New in version 1.20.
- GstAudio.audio_make_raw_caps(formats, layout)[source]¶
- Parameters:
formats ([
GstAudio.AudioFormat
] orNone
) – an array of rawGstAudio.AudioFormat
, orNone
layout (
GstAudio.AudioLayout
) – the layout of audio samples
- Returns:
an audio GstCaps
- Return type:
Return a generic raw audio caps for formats defined in formats. If formats is
None
returns a caps for all the supported raw audio formats, seeGstAudio.audio_formats_raw
().New in version 1.18.
- GstAudio.audio_reorder_channels(data, format, from_, to)[source]¶
- Parameters:
data (
bytes
) – The pointer to the memory.format (
GstAudio.AudioFormat
) – TheGstAudio.AudioFormat
of the buffer.from ([
GstAudio.AudioChannelPosition
]) – The channel positions in the buffer.to ([
GstAudio.AudioChannelPosition
]) – The channel positions to convert to.
- Returns:
True
if the reordering was possible.- Return type:
Reorders data 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.
Note: this function assumes the audio data is in interleaved layout
- GstAudio.audio_resampler_new(method, flags, format, channels, in_rate, out_rate, options)[source]¶
- Parameters:
method (
GstAudio.AudioResamplerMethod
) – aGstAudio.AudioResamplerMethod
flags (
GstAudio.AudioResamplerFlags
) –GstAudio.AudioResamplerFlags
format (
GstAudio.AudioFormat
) – theGstAudio.AudioFormat
channels (
int
) – the number of channelsin_rate (
int
) – input rateout_rate (
int
) – output rateoptions (
Gst.Structure
) – extra options
- Returns:
The new
GstAudio.AudioResampler
.- Return type:
Make a new resampler.
- GstAudio.audio_resampler_options_set_quality(method, quality, in_rate, out_rate, options)[source]¶
- Parameters:
method (
GstAudio.AudioResamplerMethod
) – aGstAudio.AudioResamplerMethod
quality (
int
) – the qualityin_rate (
int
) – the input rateout_rate (
int
) – the output rateoptions (
Gst.Structure
) – aGst.Structure
Set the parameters for resampling from in_rate to out_rate using method for quality in options.
- GstAudio.buffer_add_audio_clipping_meta(buffer, format, start, end)[source]¶
- Parameters:
buffer (
Gst.Buffer
) – aGst.Buffer
format (
Gst.Format
) –Gst.Format
of start and stop,Gst.Format.DEFAULT
is samplesstart (
int
) – Amount of audio to clip from start of bufferend (
int
) – Amount of to clip from end of buffer
- Returns:
the
GstAudio.AudioClippingMeta
on buffer.- Return type:
Attaches
GstAudio.AudioClippingMeta
metadata to buffer with the given parameters.New in version 1.8.
- GstAudio.buffer_add_audio_downmix_meta(buffer, from_position, to_position, matrix)[source]¶
- Parameters:
buffer (
Gst.Buffer
) – aGst.Buffer
from_position ([
GstAudio.AudioChannelPosition
]) – the channel positions of the sourceto_position ([
GstAudio.AudioChannelPosition
]) – the channel positions of the destinationmatrix (
float
) – The matrix coefficients.
- Returns:
the
GstAudio.AudioDownmixMeta
on buffer.- Return type:
Attaches
GstAudio.AudioDownmixMeta
metadata to buffer with the given parameters.matrix is an two-dimensional array of to_channels times from_channels coefficients, i.e. the i-th output channels is constructed by multiplicating the input channels with the coefficients in matrix[i] and taking the sum of the results.
- GstAudio.buffer_add_audio_level_meta(buffer, level, voice_activity)[source]¶
- Parameters:
buffer (
Gst.Buffer
) – aGst.Buffer
level (
int
) – the -dBov from 0-127 (127 is silence).voice_activity (
bool
) – whether the buffer contains voice activity.
- Returns:
the
GstAudio.AudioLevelMeta
on buffer.- Return type:
Attaches audio level information to buffer. (RFC 6464)
New in version 1.20.
- GstAudio.buffer_add_audio_meta(buffer, info, samples, offsets)[source]¶
- Parameters:
buffer (
Gst.Buffer
) – aGst.Buffer
info (
GstAudio.AudioInfo
) – the audio properties of the buffersamples (
int
) – the number of valid samples in the bufferoffsets (
int
orNone
) – the offsets (in bytes) where each channel plane starts in the buffer orNone
to calculate it (see below); must beNone
also when info->layout isGstAudio.AudioLayout.INTERLEAVED
- Returns:
the
GstAudio.AudioMeta
that was attached on the buffer- Return type:
Allocates and attaches a
GstAudio.AudioMeta
on buffer, which must be writable for that purpose. The fields of theGstAudio.AudioMeta
are directly populated from the arguments of this function.When info->layout is
GstAudio.AudioLayout.NON_INTERLEAVED
and offsets isNone
, the offsets are calculated with a formula that assumes the planes are tightly packed and in sequence: offsets[channel] = channel * samples * sample_strideIt is not allowed for channels to overlap in memory, i.e. for each i in [0, channels), the range [offsets[i], offsets[i] + samples * sample_stride) must not overlap with any other such range. This function will assert if the parameters specified cause this restriction to be violated.
It is, obviously, also not allowed to specify parameters that would cause out-of-bounds memory access on buffer. This is also checked, which means that you must add enough memory on the buffer before adding this meta.
New in version 1.16.
- GstAudio.buffer_add_dsd_plane_offset_meta(buffer, num_channels, num_bytes_per_channel, offsets)[source]¶
- Parameters:
buffer (
Gst.Buffer
) – aGst.Buffer
num_channels (
int
) – Number of channels in the DSD datanum_bytes_per_channel (
int
) – Number of bytes per channeloffsets (
int
orNone
) – the offsets (in bytes) where each channel plane starts in the buffer
- Returns:
the
GstAudio.DsdPlaneOffsetMeta
that was attached on the buffer- Return type:
Allocates and attaches a
GstAudio.DsdPlaneOffsetMeta
on buffer, which must be writable for that purpose. The fields of theGstAudio.DsdPlaneOffsetMeta
are directly populated from the arguments of this function.If offsets is
None
, then the meta’s offsets field is left uninitialized. This is useful if for example offset values are to be calculated in the meta’s offsets field in-place. Similarly, num_bytes_per_channel can be set to 0, but only if offsets isNone
. This is useful if the number of bytes per channel is known only later.It is not allowed for channels to overlap in memory, i.e. for each i in [0, channels), the range [offsets[i], offsets[i] + num_bytes_per_channel) must not overlap with any other such range. This function will assert if the parameters specified cause this restriction to be violated.
It is, obviously, also not allowed to specify parameters that would cause out-of-bounds memory access on buffer. This is also checked, which means that you must add enough memory on the buffer before adding this meta.
This meta is only needed for non-interleaved (= planar) DSD data.
New in version 1.24.
- GstAudio.buffer_get_audio_downmix_meta_for_channels(buffer, to_position)[source]¶
- Parameters:
buffer (
Gst.Buffer
) – aGst.Buffer
to_position ([
GstAudio.AudioChannelPosition
]) – the channel positions of the destination
- Returns:
the
GstAudio.AudioDownmixMeta
on buffer.- Return type:
Find the
GstAudio.AudioDownmixMeta
on buffer for the given destination channel positions.
- GstAudio.buffer_get_audio_level_meta(buffer)[source]¶
- Parameters:
buffer (
Gst.Buffer
) – aGst.Buffer
- Returns:
the
GstAudio.AudioLevelMeta
orNone
when there is no such metadata on buffer.- Return type:
Find the
GstAudio.AudioLevelMeta
on buffer.New in version 1.20.
- GstAudio.dsd_convert(input_data, output_data, input_format, output_format, input_layout, output_layout, input_plane_offsets, output_plane_offsets, num_dsd_bytes, num_channels, reverse_byte_bits)[source]¶
- Parameters:
input_data (
int
) – the DSD format conversion’s input sourceoutput_data (
int
) – the DSD format conversion’s output destinationinput_format (
GstAudio.DsdFormat
) – DSD format of the input data to convert fromoutput_format (
GstAudio.DsdFormat
) – DSD format of the output data to convert toinput_layout (
GstAudio.AudioLayout
) – Input data layoutoutput_layout (
GstAudio.AudioLayout
) – Output data layoutinput_plane_offsets (
int
) – Plane offsets for non-interleaved input dataoutput_plane_offsets (
int
) – Plane offsets for non-interleaved output datanum_dsd_bytes (
int
) – How many bytes with DSD data to convertnum_channels (
int
) – Number of channels (must be at least 1)reverse_byte_bits (
bool
) – IfTrue
, reverse the bits in each DSD byte
Converts DSD data from one layout and grouping format to another. num_bytes must be an integer multiple of the width of both input and output format. For example, if the input format is
GstAudio.DsdFormat.DSD_FORMAT_U32LE
, and the output format isGstAudio.DsdFormat.DSD_FORMAT_U16BE
, then num_bytes must be an integer multiple of both 4 (U32LE width) and 2 (U16BE width).reverse_byte_bits is necessary if the bit order within the DSD bytes needs to be reversed. This is rarely necessary, and is not to be confused with the endianness of formats (which determines the ordering of *bytes*).
input_plane_offsets must not be
None
if input_layout is set toGstAudio.AudioLayout.NON_INTERLEAVED
. The same applies to output_plane_offsets. These plane offsets define the starting offset of the planes (there is exactly one plane per channel) within input_data and output_data respectively. IfGstAudio.AudioLayout.INTERLEAVED
is used, the plane offsets are ignored.New in version 1.24.
- GstAudio.dsd_format_from_string(str)[source]¶
- Parameters:
str (
str
) – a DSD format string- Returns:
the
GstAudio.DsdFormat
for format orGstAudio.DsdFormat.DSD_FORMAT_UNKNOWN
when the string is not a known format.- Return type:
Convert the DSD format string str to its
GstAudio.DsdFormat
.New in version 1.24.
- GstAudio.dsd_format_get_width(format)[source]¶
- Parameters:
format (
GstAudio.DsdFormat
) – aGstAudio.DsdFormat
- Returns:
Number of bytes in this DSD grouping format.
- Return type:
New in version 1.24.
- GstAudio.dsd_format_to_string(format)[source]¶
- Parameters:
format (
GstAudio.DsdFormat
) – aGstAudio.DsdFormat
- Returns:
the name corresponding to format
- Return type:
Returns a string containing a descriptive name for the
GstAudio.DsdFormat
if there is one, orNone
otherwise.New in version 1.24.
- GstAudio.dsd_info_from_caps(caps)[source]¶
- Parameters:
- Returns:
True
if caps could be parsed- info:
- Return type:
(
bool
, info:GstAudio.DsdInfo
)
Parse caps and update info.
New in version 1.24.
- GstAudio.dsd_info_init()[source]¶
- Returns:
- Return type:
info:
GstAudio.DsdInfo
Initialize info with default values.
New in version 1.24.
- GstAudio.stream_volume_convert_volume(from_, to, val)[source]¶
- Parameters:
from (
GstAudio.StreamVolumeFormat
) –GstAudio.StreamVolumeFormat
to convert fromto (
GstAudio.StreamVolumeFormat
) –GstAudio.StreamVolumeFormat
to convert toval (
float
) – Volume in from format that should be converted
- Returns:
the converted volume
- Return type: