mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-26 02:00:33 +00:00
audio: Add public functions to check channel positions validity and to get a reorder map
This commit is contained in:
parent
ee80a97a2a
commit
c9c12372a5
2 changed files with 58 additions and 26 deletions
|
@ -943,42 +943,28 @@ gst_audio_buffer_reorder_channels (GstBuffer * buffer,
|
|||
}
|
||||
|
||||
gboolean
|
||||
gst_audio_reorder_channels (gpointer data, gsize size, GstAudioFormat format,
|
||||
gint channels, const GstAudioChannelPosition * from,
|
||||
const GstAudioChannelPosition * to)
|
||||
gst_audio_check_valid_channel_positions (const GstAudioChannelPosition *
|
||||
position, gint channels, gboolean force_order)
|
||||
{
|
||||
const GstAudioFormatInfo *info;
|
||||
gint i, j, n;
|
||||
gint reorder_map[64] = { 0, };
|
||||
guint8 *ptr;
|
||||
gint bpf, bps;
|
||||
guint8 tmp[64 * 8];
|
||||
return check_valid_channel_positions (position, channels, force_order, NULL);
|
||||
}
|
||||
|
||||
info = gst_audio_format_get_info (format);
|
||||
gboolean
|
||||
gst_audio_get_channel_reorder_map (gint channels,
|
||||
const GstAudioChannelPosition * from, const GstAudioChannelPosition * to,
|
||||
gint * reorder_map)
|
||||
{
|
||||
gint i, j;
|
||||
|
||||
g_return_val_if_fail (data != NULL, FALSE);
|
||||
g_return_val_if_fail (from != NULL, FALSE);
|
||||
g_return_val_if_fail (info != NULL && info->width > 0, FALSE);
|
||||
g_return_val_if_fail (info->width > 0, FALSE);
|
||||
g_return_val_if_fail (info->width <= 8 * 64, FALSE);
|
||||
g_return_val_if_fail (size % ((info->width * channels) / 8) != 0, FALSE);
|
||||
g_return_val_if_fail (reorder_map != NULL, FALSE);
|
||||
g_return_val_if_fail (channels > 0, FALSE);
|
||||
g_return_val_if_fail (channels <= 64, FALSE);
|
||||
g_return_val_if_fail (from != NULL, FALSE);
|
||||
g_return_val_if_fail (to != NULL, FALSE);
|
||||
g_return_val_if_fail (check_valid_channel_positions (from, channels, FALSE,
|
||||
NULL), FALSE);
|
||||
g_return_val_if_fail (check_valid_channel_positions (to, channels, FALSE,
|
||||
NULL), FALSE);
|
||||
|
||||
if (size == 0)
|
||||
return TRUE;
|
||||
|
||||
if (memcmp (from, to, channels * sizeof (from[0])) == 0)
|
||||
return TRUE;
|
||||
|
||||
bps = info->width / 8;
|
||||
bpf = bps * channels;
|
||||
|
||||
/* Build reorder map and check compatibility */
|
||||
for (i = 0; i < channels; i++) {
|
||||
if (from[i] == GST_AUDIO_CHANNEL_POSITION_NONE
|
||||
|
@ -1003,6 +989,44 @@ gst_audio_reorder_channels (gpointer data, gsize size, GstAudioFormat format,
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gst_audio_reorder_channels (gpointer data, gsize size, GstAudioFormat format,
|
||||
gint channels, const GstAudioChannelPosition * from,
|
||||
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);
|
||||
|
||||
g_return_val_if_fail (data != NULL, FALSE);
|
||||
g_return_val_if_fail (from != NULL, FALSE);
|
||||
g_return_val_if_fail (to != NULL, FALSE);
|
||||
g_return_val_if_fail (info != NULL && info->width > 0, FALSE);
|
||||
g_return_val_if_fail (info->width > 0, FALSE);
|
||||
g_return_val_if_fail (info->width <= 8 * 64, FALSE);
|
||||
g_return_val_if_fail (size % ((info->width * channels) / 8) != 0, FALSE);
|
||||
g_return_val_if_fail (channels > 0, FALSE);
|
||||
g_return_val_if_fail (channels <= 64, FALSE);
|
||||
|
||||
if (size == 0)
|
||||
return TRUE;
|
||||
|
||||
if (memcmp (from, to, channels * sizeof (from[0])) == 0)
|
||||
return TRUE;
|
||||
|
||||
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;
|
||||
|
|
|
@ -532,6 +532,14 @@ gboolean gst_audio_reorder_channels (gpointer data, gsize size,
|
|||
const GstAudioChannelPosition * from,
|
||||
const GstAudioChannelPosition * to);
|
||||
|
||||
gboolean gst_audio_check_valid_channel_positions (const GstAudioChannelPosition *position,
|
||||
gint channels, gboolean force_order);
|
||||
|
||||
gboolean gst_audio_get_channel_reorder_map (gint channels,
|
||||
const GstAudioChannelPosition * from,
|
||||
const GstAudioChannelPosition * to,
|
||||
gint *reorder_map);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GST_AUDIO_AUDIO_H__ */
|
||||
|
|
Loading…
Reference in a new issue