mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-10 01:15:39 +00:00
audio: Add new gst_audio_reorder_channels_with_reorder_map()
This allows reordering the samples with a pre-calculated reorder map instead of calculating it again every time. Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/8171>
This commit is contained in:
parent
f39812dc8f
commit
9e3bb0a009
3 changed files with 105 additions and 17 deletions
|
@ -11616,6 +11616,12 @@ the @dither and @ns parameters.</doc>
|
|||
positions @to. @from and @to must contain the same number of
|
||||
positions and the same positions, only in a different order.
|
||||
|
||||
This function internally calls gst_audio_get_channel_reorder_map() and
|
||||
gst_audio_reorder_channels_with_reorder_map(). It is more efficient to call
|
||||
gst_audio_get_channel_reorder_map() once to retrieve the reorder map and
|
||||
then call gst_audio_reorder_channels_with_reorder_map() with the same
|
||||
reorder map until the channel positions change.
|
||||
|
||||
Note: this function assumes the audio data is in interleaved layout</doc>
|
||||
<source-position filename="../subprojects/gst-plugins-base/gst-libs/gst/audio/audio-channels.h"/>
|
||||
<return-value transfer-ownership="none">
|
||||
|
@ -11656,6 +11662,45 @@ Note: this function assumes the audio data is in interleaved layout</doc>
|
|||
</parameter>
|
||||
</parameters>
|
||||
</function>
|
||||
<function name="audio_reorder_channels_with_reorder_map" c:identifier="gst_audio_reorder_channels_with_reorder_map" version="1.26">
|
||||
<doc xml:space="preserve" filename="../subprojects/gst-plugins-base/gst-libs/gst/audio/audio-channels.c">Reorders @data with the given @reorder_map.
|
||||
|
||||
The reorder map can be retrieved for example with
|
||||
gst_audio_get_channel_reorder_map().
|
||||
|
||||
Note: this function assumes the audio data is in interleaved layout</doc>
|
||||
<source-position filename="../subprojects/gst-plugins-base/gst-libs/gst/audio/audio-channels.h"/>
|
||||
<return-value transfer-ownership="none">
|
||||
<type name="none" c:type="void"/>
|
||||
</return-value>
|
||||
<parameters>
|
||||
<parameter name="data" transfer-ownership="none">
|
||||
<doc xml:space="preserve" filename="../subprojects/gst-plugins-base/gst-libs/gst/audio/audio-channels.c">The pointer to
|
||||
the memory.</doc>
|
||||
<array length="1" zero-terminated="0" c:type="gpointer">
|
||||
<type name="guint8"/>
|
||||
</array>
|
||||
</parameter>
|
||||
<parameter name="size" transfer-ownership="none">
|
||||
<doc xml:space="preserve" filename="../subprojects/gst-plugins-base/gst-libs/gst/audio/audio-channels.c">The size of the memory.</doc>
|
||||
<type name="gsize" c:type="gsize"/>
|
||||
</parameter>
|
||||
<parameter name="bps" transfer-ownership="none">
|
||||
<doc xml:space="preserve" filename="../subprojects/gst-plugins-base/gst-libs/gst/audio/audio-channels.c">The number of bytes per sample.</doc>
|
||||
<type name="gint" c:type="gint"/>
|
||||
</parameter>
|
||||
<parameter name="channels" transfer-ownership="none">
|
||||
<doc xml:space="preserve" filename="../subprojects/gst-plugins-base/gst-libs/gst/audio/audio-channels.c">The number of channels.</doc>
|
||||
<type name="gint" c:type="gint"/>
|
||||
</parameter>
|
||||
<parameter name="reorder_map" transfer-ownership="none">
|
||||
<doc xml:space="preserve" filename="../subprojects/gst-plugins-base/gst-libs/gst/audio/audio-channels.c">The channel reorder map.</doc>
|
||||
<array length="3" zero-terminated="0" c:type="const gint*">
|
||||
<type name="gint" c:type="gint"/>
|
||||
</array>
|
||||
</parameter>
|
||||
</parameters>
|
||||
</function>
|
||||
<function name="audio_resampler_new" c:identifier="gst_audio_resampler_new" moved-to="AudioResampler.new">
|
||||
<doc xml:space="preserve" filename="../subprojects/gst-plugins-base/gst-libs/gst/audio/audio-resampler.c">Make a new resampler.</doc>
|
||||
<source-position filename="../subprojects/gst-plugins-base/gst-libs/gst/audio/audio-resampler.h"/>
|
||||
|
|
|
@ -182,6 +182,52 @@ check_valid_channel_positions (const GstAudioChannelPosition * position,
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_audio_reorder_channels_with_reorder_map:
|
||||
* @data: (array length=size) (element-type guint8): The pointer to
|
||||
* the memory.
|
||||
* @size: The size of the memory.
|
||||
* @bps: The number of bytes per sample.
|
||||
* @channels: The number of channels.
|
||||
* @reorder_map: (array length=channels): The channel reorder map.
|
||||
*
|
||||
* Reorders @data with the given @reorder_map.
|
||||
*
|
||||
* The reorder map can be retrieved for example with
|
||||
* gst_audio_get_channel_reorder_map().
|
||||
*
|
||||
* Note: this function assumes the audio data is in interleaved layout
|
||||
*
|
||||
* Since: 1.26
|
||||
*/
|
||||
void
|
||||
gst_audio_reorder_channels_with_reorder_map (gpointer data, gsize size,
|
||||
gint bps, gint channels, const gint * reorder_map)
|
||||
{
|
||||
gint bpf = bps * channels;
|
||||
guint8 *ptr = data;
|
||||
gsize n;
|
||||
|
||||
g_return_if_fail (data != NULL);
|
||||
g_return_if_fail (size % (bps * channels) == 0);
|
||||
g_return_if_fail (bps > 0);
|
||||
g_return_if_fail (bps <= 64);
|
||||
g_return_if_fail (channels > 0);
|
||||
g_return_if_fail (channels <= 64);
|
||||
g_return_if_fail (reorder_map != NULL);
|
||||
|
||||
n = size / bpf;
|
||||
for (gsize i = 0; i < n; i++) {
|
||||
guint8 tmp[64 * 8];
|
||||
|
||||
memcpy (tmp, ptr, bpf);
|
||||
for (gint j = 0; j < channels; j++)
|
||||
memcpy (ptr + reorder_map[j] * bps, tmp + j * bps, bps);
|
||||
|
||||
ptr += bpf;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_audio_reorder_channels:
|
||||
* @data: (array length=size) (element-type guint8): The pointer to
|
||||
|
@ -196,6 +242,12 @@ check_valid_channel_positions (const GstAudioChannelPosition * position,
|
|||
* positions @to. @from and @to must contain the same number of
|
||||
* positions and the same positions, only in a different order.
|
||||
*
|
||||
* This function internally calls gst_audio_get_channel_reorder_map() and
|
||||
* gst_audio_reorder_channels_with_reorder_map(). It is more efficient to call
|
||||
* gst_audio_get_channel_reorder_map() once to retrieve the reorder map and
|
||||
* then call gst_audio_reorder_channels_with_reorder_map() with the same
|
||||
* reorder map until the channel positions change.
|
||||
*
|
||||
* Note: this function assumes the audio data is in interleaved layout
|
||||
*
|
||||
* Returns: %TRUE if the reordering was possible.
|
||||
|
@ -206,11 +258,7 @@ gst_audio_reorder_channels (gpointer data, gsize size, GstAudioFormat format,
|
|||
const GstAudioChannelPosition * to)
|
||||
{
|
||||
const GstAudioFormatInfo *info;
|
||||
gint i, j, n;
|
||||
gint reorder_map[64] = { 0, };
|
||||
guint8 *ptr;
|
||||
gint bpf, bps;
|
||||
guint8 tmp[64 * 8];
|
||||
|
||||
info = gst_audio_format_get_info (format);
|
||||
|
||||
|
@ -234,19 +282,8 @@ gst_audio_reorder_channels (gpointer data, gsize size, GstAudioFormat format,
|
|||
if (!gst_audio_get_channel_reorder_map (channels, from, to, reorder_map))
|
||||
return FALSE;
|
||||
|
||||
bps = info->width / 8;
|
||||
bpf = bps * channels;
|
||||
ptr = data;
|
||||
|
||||
n = size / bpf;
|
||||
for (i = 0; i < n; i++) {
|
||||
|
||||
memcpy (tmp, ptr, bpf);
|
||||
for (j = 0; j < channels; j++)
|
||||
memcpy (ptr + reorder_map[j] * bps, tmp + j * bps, bps);
|
||||
|
||||
ptr += bpf;
|
||||
}
|
||||
gst_audio_reorder_channels_with_reorder_map (data, size, info->width / 8,
|
||||
channels, reorder_map);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
|
@ -145,6 +145,12 @@ gboolean gst_audio_reorder_channels (gpointer data, gsize size,
|
|||
const GstAudioChannelPosition * from,
|
||||
const GstAudioChannelPosition * to);
|
||||
|
||||
GST_AUDIO_API
|
||||
void gst_audio_reorder_channels_with_reorder_map (gpointer data, gsize size,
|
||||
gint bps,
|
||||
gint channels,
|
||||
const gint *reorder_map);
|
||||
|
||||
GST_AUDIO_API
|
||||
gboolean gst_audio_channel_positions_to_valid_order (GstAudioChannelPosition *position,
|
||||
gint channels);
|
||||
|
|
Loading…
Reference in a new issue