mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-04-26 04:36:20 +00:00
audio-channels: map buffer read-write only if channels differ
gst_audio_buffer_reorder_channels() was always mapping the buffer read-write regardless whether any reordering was needed. If the from and to channel order is identical return immediately without remapping the buffer. Add a small helper function gst_audio_channel_positions_equal() which is used in both gst_audio_reorder_channels() and gst_audio_buffer_reorder_channels(). https://bugzilla.gnome.org/show_bug.cgi?id=773833
This commit is contained in:
parent
658ee6f0db
commit
54f4d3772c
1 changed files with 17 additions and 1 deletions
|
@ -121,6 +121,19 @@ static const GstAudioChannelPosition default_channel_order[64] = {
|
||||||
GST_AUDIO_CHANNEL_POSITION_INVALID
|
GST_AUDIO_CHANNEL_POSITION_INVALID
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Compares @channels audio channel positions @p1 and @p2 if they are equal.
|
||||||
|
* In other words, tells whether channel reordering is needed (unequal) or not (equal).
|
||||||
|
*
|
||||||
|
* Returns: %TRUE if the channel positions are equal, i.e. no reordering is needed.
|
||||||
|
*/
|
||||||
|
static gboolean
|
||||||
|
gst_audio_channel_positions_equal (const GstAudioChannelPosition * p1,
|
||||||
|
const GstAudioChannelPosition * p2, gint channels)
|
||||||
|
{
|
||||||
|
return memcmp (p1, p2, channels * sizeof (p1[0])) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
check_valid_channel_positions (const GstAudioChannelPosition * position,
|
check_valid_channel_positions (const GstAudioChannelPosition * position,
|
||||||
gint channels, gboolean enforce_order, guint64 * channel_mask_out)
|
gint channels, gboolean enforce_order, guint64 * channel_mask_out)
|
||||||
|
@ -211,7 +224,7 @@ gst_audio_reorder_channels (gpointer data, gsize size, GstAudioFormat format,
|
||||||
if (size == 0)
|
if (size == 0)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
if (memcmp (from, to, channels * sizeof (from[0])) == 0)
|
if (gst_audio_channel_positions_equal (from, to, channels))
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
if (!gst_audio_get_channel_reorder_map (channels, from, to, reorder_map))
|
if (!gst_audio_get_channel_reorder_map (channels, from, to, reorder_map))
|
||||||
|
@ -260,6 +273,9 @@ gst_audio_buffer_reorder_channels (GstBuffer * buffer,
|
||||||
g_return_val_if_fail (GST_IS_BUFFER (buffer), FALSE);
|
g_return_val_if_fail (GST_IS_BUFFER (buffer), FALSE);
|
||||||
g_return_val_if_fail (gst_buffer_is_writable (buffer), FALSE);
|
g_return_val_if_fail (gst_buffer_is_writable (buffer), FALSE);
|
||||||
|
|
||||||
|
if (gst_audio_channel_positions_equal (from, to, channels))
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
gst_buffer_map (buffer, &info, GST_MAP_READWRITE);
|
gst_buffer_map (buffer, &info, GST_MAP_READWRITE);
|
||||||
|
|
||||||
ret =
|
ret =
|
||||||
|
|
Loading…
Reference in a new issue