mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-26 02:00:33 +00:00
audio: Add new channel positions and simplify channel expression in the caps
The available channel positions are all channels from SMPTE 2036-2-2008 (in that order) and DTS Coherent Acoustics, which are basically all 28 channels that currently can appear. The channels are now expressed in the caps as a channel-mask, which describes which of the channels are present, and an optional channel-reorder-map, which must only be used after negotiation for fixated caps. For negotiation only the channel-mask and the channel count is relevant and all elements are expected to handle all reorder maps. Elements that don't can use the new API to reorder an audio buffer from any order to another order. This simplifies negotiation a lot while still having as few reorderings necassary as possible and still allow all kinds of channel layouts.
This commit is contained in:
parent
db233aecf4
commit
c227f5e77e
5 changed files with 411 additions and 965 deletions
|
@ -1,6 +1,6 @@
|
|||
# variables used for enum/marshal generation
|
||||
glib_enum_headers= \
|
||||
multichannel.h \
|
||||
audio.h \
|
||||
gstaudioringbuffer.h
|
||||
|
||||
glib_enum_define = GST_AUDIO
|
||||
|
@ -27,7 +27,6 @@ libgstaudio_@GST_MAJORMINOR@_la_SOURCES = \
|
|||
mixeroptions.c \
|
||||
mixertrack.c \
|
||||
mixerutils.c \
|
||||
multichannel.c \
|
||||
gstaudiocdsrc.c \
|
||||
gstaudiodecoder.c \
|
||||
gstaudioencoder.c \
|
||||
|
@ -60,7 +59,6 @@ libgstaudio_@GST_MAJORMINOR@include_HEADERS = \
|
|||
mixeroptions.h \
|
||||
mixertrack.h \
|
||||
mixerutils.h \
|
||||
multichannel.h \
|
||||
streamvolume.h \
|
||||
gstaudioiec61937.h
|
||||
|
||||
|
|
|
@ -327,6 +327,124 @@ gst_audio_info_init (GstAudioInfo * info)
|
|||
memset (info, 0, sizeof (GstAudioInfo));
|
||||
|
||||
info->finfo = &formats[GST_AUDIO_FORMAT_UNKNOWN];
|
||||
|
||||
memset (&info->position, 0xff, sizeof (info->position));
|
||||
}
|
||||
|
||||
static const GstAudioChannelPosition default_channel_order[64] = {
|
||||
GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
|
||||
GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
|
||||
GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
|
||||
GST_AUDIO_CHANNEL_POSITION_LFE1,
|
||||
GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
|
||||
GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,
|
||||
GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER,
|
||||
GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER,
|
||||
GST_AUDIO_CHANNEL_POSITION_REAR_CENTER,
|
||||
GST_AUDIO_CHANNEL_POSITION_LFE2,
|
||||
GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT,
|
||||
GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT,
|
||||
GST_AUDIO_CHANNEL_POSITION_TOP_FRONT_LEFT,
|
||||
GST_AUDIO_CHANNEL_POSITION_TOP_FRONT_RIGHT,
|
||||
GST_AUDIO_CHANNEL_POSITION_TOP_FRONT_CENTER,
|
||||
GST_AUDIO_CHANNEL_POSITION_TOP_CENTER,
|
||||
GST_AUDIO_CHANNEL_POSITION_TOP_REAR_LEFT,
|
||||
GST_AUDIO_CHANNEL_POSITION_TOP_REAR_RIGHT,
|
||||
GST_AUDIO_CHANNEL_POSITION_TOP_SIDE_LEFT,
|
||||
GST_AUDIO_CHANNEL_POSITION_TOP_SIDE_RIGHT,
|
||||
GST_AUDIO_CHANNEL_POSITION_TOP_REAR_CENTER,
|
||||
GST_AUDIO_CHANNEL_POSITION_BOTTOM_FRONT_CENTER,
|
||||
GST_AUDIO_CHANNEL_POSITION_BOTTOM_FRONT_LEFT,
|
||||
GST_AUDIO_CHANNEL_POSITION_BOTTOM_FRONT_RIGHT,
|
||||
GST_AUDIO_CHANNEL_POSITION_WIDE_LEFT,
|
||||
GST_AUDIO_CHANNEL_POSITION_WIDE_RIGHT,
|
||||
GST_AUDIO_CHANNEL_POSITION_SURROUND_LEFT,
|
||||
GST_AUDIO_CHANNEL_POSITION_SURROUND_RIGHT,
|
||||
GST_AUDIO_CHANNEL_POSITION_INVALID,
|
||||
GST_AUDIO_CHANNEL_POSITION_INVALID,
|
||||
GST_AUDIO_CHANNEL_POSITION_INVALID,
|
||||
GST_AUDIO_CHANNEL_POSITION_INVALID,
|
||||
GST_AUDIO_CHANNEL_POSITION_INVALID,
|
||||
GST_AUDIO_CHANNEL_POSITION_INVALID,
|
||||
GST_AUDIO_CHANNEL_POSITION_INVALID,
|
||||
GST_AUDIO_CHANNEL_POSITION_INVALID,
|
||||
GST_AUDIO_CHANNEL_POSITION_INVALID,
|
||||
GST_AUDIO_CHANNEL_POSITION_INVALID,
|
||||
GST_AUDIO_CHANNEL_POSITION_INVALID,
|
||||
GST_AUDIO_CHANNEL_POSITION_INVALID,
|
||||
GST_AUDIO_CHANNEL_POSITION_INVALID,
|
||||
GST_AUDIO_CHANNEL_POSITION_INVALID,
|
||||
GST_AUDIO_CHANNEL_POSITION_INVALID,
|
||||
GST_AUDIO_CHANNEL_POSITION_INVALID,
|
||||
GST_AUDIO_CHANNEL_POSITION_INVALID,
|
||||
GST_AUDIO_CHANNEL_POSITION_INVALID,
|
||||
GST_AUDIO_CHANNEL_POSITION_INVALID,
|
||||
GST_AUDIO_CHANNEL_POSITION_INVALID,
|
||||
GST_AUDIO_CHANNEL_POSITION_INVALID,
|
||||
GST_AUDIO_CHANNEL_POSITION_INVALID,
|
||||
GST_AUDIO_CHANNEL_POSITION_INVALID,
|
||||
GST_AUDIO_CHANNEL_POSITION_INVALID,
|
||||
GST_AUDIO_CHANNEL_POSITION_INVALID,
|
||||
GST_AUDIO_CHANNEL_POSITION_INVALID,
|
||||
GST_AUDIO_CHANNEL_POSITION_INVALID,
|
||||
GST_AUDIO_CHANNEL_POSITION_INVALID,
|
||||
GST_AUDIO_CHANNEL_POSITION_INVALID,
|
||||
GST_AUDIO_CHANNEL_POSITION_INVALID,
|
||||
GST_AUDIO_CHANNEL_POSITION_INVALID,
|
||||
GST_AUDIO_CHANNEL_POSITION_INVALID,
|
||||
GST_AUDIO_CHANNEL_POSITION_INVALID,
|
||||
GST_AUDIO_CHANNEL_POSITION_INVALID,
|
||||
GST_AUDIO_CHANNEL_POSITION_INVALID,
|
||||
GST_AUDIO_CHANNEL_POSITION_INVALID
|
||||
};
|
||||
|
||||
static gboolean
|
||||
check_valid_channel_positions (const GstAudioChannelPosition * position,
|
||||
gint channels, gboolean enforce_order, guint64 * channel_mask_out)
|
||||
{
|
||||
gint i, j;
|
||||
guint64 channel_mask = 0;
|
||||
gboolean none_layout = FALSE;
|
||||
|
||||
if (channels == 1 && position[0] == GST_AUDIO_CHANNEL_POSITION_MONO) {
|
||||
if (channel_mask_out)
|
||||
*channel_mask_out = 0;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
j = 0;
|
||||
for (i = 0; i < channels; i++) {
|
||||
while (j < G_N_ELEMENTS (default_channel_order)
|
||||
&& default_channel_order[j] != position[i])
|
||||
j++;
|
||||
|
||||
if (position[i] == GST_AUDIO_CHANNEL_POSITION_INVALID ||
|
||||
position[i] == GST_AUDIO_CHANNEL_POSITION_MONO)
|
||||
return FALSE;
|
||||
|
||||
if (position[i] == GST_AUDIO_CHANNEL_POSITION_NONE) {
|
||||
none_layout = TRUE;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Is this in valid channel order? */
|
||||
if (enforce_order && j == G_N_ELEMENTS (default_channel_order))
|
||||
return FALSE;
|
||||
j++;
|
||||
|
||||
if ((channel_mask & (G_GUINT64_CONSTANT (1) << position[i])))
|
||||
return FALSE;
|
||||
|
||||
channel_mask |= (G_GUINT64_CONSTANT (1) << position[i]);
|
||||
}
|
||||
|
||||
if (none_layout && channel_mask != 0)
|
||||
return FALSE;
|
||||
|
||||
if (channel_mask_out)
|
||||
*channel_mask_out = channel_mask;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -335,17 +453,19 @@ gst_audio_info_init (GstAudioInfo * info)
|
|||
* @format: the format
|
||||
* @rate: the samplerate
|
||||
* @channels: the number of channels
|
||||
* @position: the channel positions
|
||||
*
|
||||
* Set the default info for the audio info of @format and @rate and @channels.
|
||||
*/
|
||||
void
|
||||
gst_audio_info_set_format (GstAudioInfo * info, GstAudioFormat format,
|
||||
gint rate, gint channels)
|
||||
gint rate, gint channels, const GstAudioChannelPosition * position)
|
||||
{
|
||||
const GstAudioFormatInfo *finfo;
|
||||
|
||||
g_return_if_fail (info != NULL);
|
||||
g_return_if_fail (format != GST_AUDIO_FORMAT_UNKNOWN);
|
||||
g_return_if_fail (channels <= 2 || position != NULL);
|
||||
|
||||
finfo = &formats[format];
|
||||
|
||||
|
@ -354,6 +474,22 @@ gst_audio_info_set_format (GstAudioInfo * info, GstAudioFormat format,
|
|||
info->rate = rate;
|
||||
info->channels = channels;
|
||||
info->bpf = (finfo->width * channels) / 8;
|
||||
|
||||
memset (&info->position, 0xff, sizeof (info->position));
|
||||
|
||||
if (!position && channels == 1) {
|
||||
info->position[0] = GST_AUDIO_CHANNEL_POSITION_MONO;
|
||||
} else if (!position && channels == 2) {
|
||||
info->position[0] = GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT;
|
||||
info->position[1] = GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT;
|
||||
} else {
|
||||
if (!check_valid_channel_positions (position, channels, TRUE, NULL)) {
|
||||
g_warning ("Invalid channel positions");
|
||||
} else {
|
||||
memcpy (&info->position, position,
|
||||
info->channels * sizeof (info->position[0]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -372,8 +508,9 @@ gst_audio_info_from_caps (GstAudioInfo * info, const GstCaps * caps)
|
|||
const gchar *s;
|
||||
GstAudioFormat format;
|
||||
gint rate, channels;
|
||||
const GValue *pos_val_arr, *pos_val_entry;
|
||||
guint64 channel_mask;
|
||||
gint i;
|
||||
GstAudioChannelPosition position[64];
|
||||
|
||||
g_return_val_if_fail (info != NULL, FALSE);
|
||||
g_return_val_if_fail (caps != NULL, FALSE);
|
||||
|
@ -398,42 +535,38 @@ gst_audio_info_from_caps (GstAudioInfo * info, const GstCaps * caps)
|
|||
if (!gst_structure_get_int (str, "channels", &channels))
|
||||
goto no_channels;
|
||||
|
||||
gst_audio_info_set_format (info, format, rate, channels);
|
||||
|
||||
pos_val_arr = gst_structure_get_value (str, "channel-positions");
|
||||
|
||||
if (pos_val_arr) {
|
||||
guint max_pos = MIN (channels, 64);
|
||||
|
||||
if (channels != gst_value_array_get_size (pos_val_arr))
|
||||
goto incoherent_channels;
|
||||
|
||||
/* FIXME : Detect if it's the default channel position */
|
||||
for (i = 0; i < max_pos; i++) {
|
||||
pos_val_entry = gst_value_array_get_value (pos_val_arr, i);
|
||||
info->position[i] = g_value_get_enum (pos_val_entry);
|
||||
|
||||
/* the unpositioned flag is set as soon as one of the channels has an
|
||||
* explicit NONE positioning */
|
||||
if (info->position[i] == GST_AUDIO_CHANNEL_POSITION_NONE)
|
||||
info->flags |= GST_AUDIO_FLAG_UNPOSITIONED;
|
||||
if (!gst_structure_get (str, "channel-mask", GST_TYPE_BITMASK, &channel_mask,
|
||||
NULL)) {
|
||||
if (channels == 1) {
|
||||
position[0] = GST_AUDIO_CHANNEL_POSITION_MONO;
|
||||
} else if (channels == 2) {
|
||||
position[0] = GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT;
|
||||
position[0] = GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT;
|
||||
} else {
|
||||
goto no_channel_mask;
|
||||
}
|
||||
} else if (channel_mask == 0) {
|
||||
for (i = 0; i < G_N_ELEMENTS (position); i++)
|
||||
position[i] = GST_AUDIO_CHANNEL_POSITION_NONE;
|
||||
} else {
|
||||
info->flags |= GST_AUDIO_FLAG_DEFAULT_POSITIONS;
|
||||
/* FIXME, set more default positions */
|
||||
switch (channels) {
|
||||
case 1:
|
||||
info->position[0] = GST_AUDIO_CHANNEL_POSITION_FRONT_MONO;
|
||||
break;
|
||||
case 2:
|
||||
info->position[0] = GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT;
|
||||
info->position[1] = GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
gint j;
|
||||
|
||||
j = 0;
|
||||
for (i = 0; i < 64; i++) {
|
||||
if ((channel_mask & (G_GUINT64_CONSTANT (1) << i))) {
|
||||
position[j] = default_channel_order[i];
|
||||
if (default_channel_order[i] == GST_AUDIO_CHANNEL_POSITION_INVALID)
|
||||
goto invalid_channel_mask;
|
||||
j++;
|
||||
}
|
||||
}
|
||||
|
||||
if (j != channels)
|
||||
goto invalid_channel_mask;
|
||||
}
|
||||
|
||||
gst_audio_info_set_format (info, format, rate, channels, position);
|
||||
|
||||
return TRUE;
|
||||
|
||||
/* ERROR */
|
||||
|
@ -462,11 +595,15 @@ no_channels:
|
|||
GST_ERROR ("no channels property given");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
incoherent_channels:
|
||||
no_channel_mask:
|
||||
{
|
||||
GST_ERROR ("There should be %d channels positions, but %d are present",
|
||||
channels, gst_value_array_get_size (pos_val_arr));
|
||||
GST_ERROR ("no channel-mask property given");
|
||||
return FALSE;
|
||||
}
|
||||
invalid_channel_mask:
|
||||
{
|
||||
GST_ERROR ("Invalid channel mask 0x%016" G_GINT64_MODIFIER
|
||||
"x for %d channels", channel_mask, channels);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
@ -498,30 +635,31 @@ gst_audio_info_to_caps (const GstAudioInfo * info)
|
|||
"rate", G_TYPE_INT, info->rate,
|
||||
"channels", G_TYPE_INT, info->channels, NULL);
|
||||
|
||||
if (info->channels > 2) {
|
||||
GValue pos_val_arr = { 0 }
|
||||
, pos_val_entry = {
|
||||
0};
|
||||
gint i, max_pos;
|
||||
GstStructure *str;
|
||||
if (info->channels > 1
|
||||
|| info->position[0] != GST_AUDIO_CHANNEL_POSITION_MONO) {
|
||||
guint64 channel_mask = 0;
|
||||
|
||||
/* build gvaluearray from positions */
|
||||
g_value_init (&pos_val_arr, GST_TYPE_ARRAY);
|
||||
g_value_init (&pos_val_entry, GST_TYPE_AUDIO_CHANNEL_POSITION);
|
||||
max_pos = MAX (info->channels, 64);
|
||||
for (i = 0; i < max_pos; i++) {
|
||||
g_value_set_enum (&pos_val_entry, info->position[i]);
|
||||
gst_value_array_append_value (&pos_val_arr, &pos_val_entry);
|
||||
if (!check_valid_channel_positions (info->position, info->channels,
|
||||
TRUE, &channel_mask))
|
||||
goto invalid_channel_positions;
|
||||
|
||||
if (info->channels == 1
|
||||
&& info->position[0] == GST_AUDIO_CHANNEL_POSITION_MONO) {
|
||||
/* Default mono special case */
|
||||
} else {
|
||||
gst_caps_set_simple (caps, "channel-mask", GST_TYPE_BITMASK, channel_mask,
|
||||
NULL);
|
||||
}
|
||||
g_value_unset (&pos_val_entry);
|
||||
|
||||
/* add to structure */
|
||||
str = gst_caps_get_structure (caps, 0);
|
||||
gst_structure_set_value (str, "channel-positions", &pos_val_arr);
|
||||
g_value_unset (&pos_val_arr);
|
||||
}
|
||||
|
||||
return caps;
|
||||
|
||||
invalid_channel_positions:
|
||||
{
|
||||
GST_ERROR ("Invalid channel positions");
|
||||
gst_caps_unref (caps);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -783,3 +921,99 @@ gst_audio_buffer_clip (GstBuffer * buffer, GstSegment * segment, gint rate,
|
|||
|
||||
return ret;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gst_audio_buffer_reorder_channels (GstBuffer * buffer,
|
||||
GstAudioFormat format, gint channels,
|
||||
const GstAudioChannelPosition * from, const GstAudioChannelPosition * to)
|
||||
{
|
||||
gsize size;
|
||||
guint8 *data;
|
||||
gboolean ret;
|
||||
|
||||
g_return_val_if_fail (GST_IS_BUFFER (buffer), FALSE);
|
||||
|
||||
data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ | GST_MAP_WRITE);
|
||||
|
||||
ret = gst_audio_reorder_channels (data, size, format, channels, from, to);
|
||||
|
||||
gst_buffer_unmap (buffer, data, size);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
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 (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);
|
||||
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
|
||||
|| to[i] == GST_AUDIO_CHANNEL_POSITION_NONE)
|
||||
return FALSE;
|
||||
if (from[i] == GST_AUDIO_CHANNEL_POSITION_INVALID
|
||||
|| to[i] == GST_AUDIO_CHANNEL_POSITION_INVALID)
|
||||
return FALSE;
|
||||
if (from[i] == GST_AUDIO_CHANNEL_POSITION_MONO
|
||||
|| to[i] == GST_AUDIO_CHANNEL_POSITION_MONO)
|
||||
return FALSE;
|
||||
|
||||
for (j = 0; j < channels; j++) {
|
||||
if (from[i] == to[j]) {
|
||||
reorder_map[i] = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Not all channels present in both */
|
||||
if (j == channels)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
|
@ -24,8 +24,6 @@
|
|||
#ifndef __GST_AUDIO_AUDIO_H__
|
||||
#define __GST_AUDIO_AUDIO_H__
|
||||
|
||||
#include <gst/audio/multichannel.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#if G_BYTE_ORDER == G_BIG_ENDIAN
|
||||
|
@ -252,11 +250,113 @@ const GstAudioFormatInfo *
|
|||
|
||||
void gst_audio_format_fill_silence (const GstAudioFormatInfo *info,
|
||||
gpointer dest, gsize length);
|
||||
|
||||
/**
|
||||
* GstAudioChannelPosition:
|
||||
* @GST_AUDIO_CHANNEL_POSITION_MONO: Mono without direction;
|
||||
* can only be used with 1 channel
|
||||
* @GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT: Front left
|
||||
* @GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT: Front right
|
||||
* @GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER: Front center
|
||||
* @GST_AUDIO_CHANNEL_POSITION_LFE1: Low-frequency effects 1 (subwoofer)
|
||||
* @GST_AUDIO_CHANNEL_POSITION_REAR_LEFT: Rear left
|
||||
* @GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT: Rear right
|
||||
* @GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER: Front left of center
|
||||
* @GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER: Front right of center
|
||||
* @GST_AUDIO_CHANNEL_POSITION_REAR_CENTER: Rear center
|
||||
* @GST_AUDIO_CHANNEL_POSITION_LFE2: Low-frequency effects 2 (subwoofer)
|
||||
* @GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT: Side left
|
||||
* @GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT: Side right
|
||||
* @GST_AUDIO_CHANNEL_POSITION_TOP_FRONT_LEFT: Top front left
|
||||
* @GST_AUDIO_CHANNEL_POSITION_TOP_FRONT_RIGHT: Top front right
|
||||
* @GST_AUDIO_CHANNEL_POSITION_TOP_FRONT_CENTER: Top front center
|
||||
* @GST_AUDIO_CHANNEL_POSITION_TOP_CENTER: Top center
|
||||
* @GST_AUDIO_CHANNEL_POSITION_TOP_REAR_LEFT: Top rear left
|
||||
* @GST_AUDIO_CHANNEL_POSITION_TOP_REAR_RIGHT: Top rear right
|
||||
* @GST_AUDIO_CHANNEL_POSITION_TOP_SIDE_LEFT: Top side right
|
||||
* @GST_AUDIO_CHANNEL_POSITION_TOP_SIDE_RIGHT: Top rear right
|
||||
* @GST_AUDIO_CHANNEL_POSITION_TOP_REAR_CENTER: Top rear center
|
||||
* @GST_AUDIO_CHANNEL_POSITION_BOTTOM_FRONT_CENTER: Bottom front center
|
||||
* @GST_AUDIO_CHANNEL_POSITION_BOTTOM_FRONT_LEFT: Bottom front left
|
||||
* @GST_AUDIO_CHANNEL_POSITION_BOTTOM_FRONT_RIGHT: Bottom front right
|
||||
* @GST_AUDIO_CHANNEL_POSITION_WIDE_LEFT: Wide left (between front left and side left)
|
||||
* @GST_AUDIO_CHANNEL_POSITION_WIDE_RIGHT: Wide right (between front right and side right)
|
||||
* @GST_AUDIO_CHANNEL_POSITION_SURROUND_LEFT: Surround left (between rear left and side left)
|
||||
* @GST_AUDIO_CHANNEL_POSITION_SURROUND_RIGHT: Surround right (between rear right and side right)
|
||||
* @GST_AUDIO_CHANNEL_POSITION_NONE: used for position-less channels, e.g.
|
||||
* from a sound card that records 1024 channels; mutually exclusive with
|
||||
* any other channel position
|
||||
* @GST_AUDIO_CHANNEL_POSITION_INVALID: invalid position
|
||||
*
|
||||
* Audio channel positions.
|
||||
*
|
||||
* These are the channels defined in SMPTE 2036-2-2008
|
||||
* Table 1 for 22.2 audio systems with the Surround and Wide channels from
|
||||
* DTS Coherent Acoustics (v.1.3.1) and 10.2 and 7.1 layouts. In the caps the
|
||||
* actual channel layout is expressed with a channel count and a channel mask,
|
||||
* which describes the existing channels. The positions in the bit mask correspond
|
||||
* to the enum values.
|
||||
* For negotiation it is allowed to have more bits set in the channel mask than
|
||||
* the number of channels to specify the allowed channel positions but this is
|
||||
* not allowed in negotiated caps. It is not allowed in any situation other
|
||||
* than the one mentioned below to have less bits set in the channel mask than
|
||||
* the number of channels.
|
||||
*
|
||||
* @GST_AUDIO_CHANNEL_POSITION_MONO can only be used with a single mono channel that
|
||||
* has no direction information and would be mixed into all directional channels.
|
||||
* This is expressed in caps by having a single channel and no channel mask.
|
||||
*
|
||||
* @GST_AUDIO_CHANNEL_POSITION_NONE can only be used if all channels have this position.
|
||||
* This is expressed in caps by having a channel mask with no bits set.
|
||||
*
|
||||
* As another special case it is allowed to have two channels without a channel mask.
|
||||
* This implicitely means that this is a stereo stream with a front left and front right
|
||||
* channel.
|
||||
*/
|
||||
typedef enum {
|
||||
/* These get negative indices to allow to use
|
||||
* the enum values of the normal cases for the
|
||||
* bit-mask position */
|
||||
GST_AUDIO_CHANNEL_POSITION_NONE = -3,
|
||||
GST_AUDIO_CHANNEL_POSITION_MONO = -2,
|
||||
GST_AUDIO_CHANNEL_POSITION_INVALID = -1,
|
||||
|
||||
/* Normal cases */
|
||||
GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT = 0,
|
||||
GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
|
||||
GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
|
||||
GST_AUDIO_CHANNEL_POSITION_LFE1,
|
||||
GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
|
||||
GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,
|
||||
GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER,
|
||||
GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER,
|
||||
GST_AUDIO_CHANNEL_POSITION_REAR_CENTER,
|
||||
GST_AUDIO_CHANNEL_POSITION_LFE2,
|
||||
GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT,
|
||||
GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT,
|
||||
GST_AUDIO_CHANNEL_POSITION_TOP_FRONT_LEFT,
|
||||
GST_AUDIO_CHANNEL_POSITION_TOP_FRONT_RIGHT,
|
||||
GST_AUDIO_CHANNEL_POSITION_TOP_FRONT_CENTER,
|
||||
GST_AUDIO_CHANNEL_POSITION_TOP_CENTER,
|
||||
GST_AUDIO_CHANNEL_POSITION_TOP_REAR_LEFT,
|
||||
GST_AUDIO_CHANNEL_POSITION_TOP_REAR_RIGHT,
|
||||
GST_AUDIO_CHANNEL_POSITION_TOP_SIDE_LEFT,
|
||||
GST_AUDIO_CHANNEL_POSITION_TOP_SIDE_RIGHT,
|
||||
GST_AUDIO_CHANNEL_POSITION_TOP_REAR_CENTER,
|
||||
GST_AUDIO_CHANNEL_POSITION_BOTTOM_FRONT_CENTER,
|
||||
GST_AUDIO_CHANNEL_POSITION_BOTTOM_FRONT_LEFT,
|
||||
GST_AUDIO_CHANNEL_POSITION_BOTTOM_FRONT_RIGHT,
|
||||
GST_AUDIO_CHANNEL_POSITION_WIDE_LEFT,
|
||||
GST_AUDIO_CHANNEL_POSITION_WIDE_RIGHT,
|
||||
GST_AUDIO_CHANNEL_POSITION_SURROUND_LEFT,
|
||||
GST_AUDIO_CHANNEL_POSITION_SURROUND_RIGHT
|
||||
} GstAudioChannelPosition;
|
||||
|
||||
#define GST_AUDIO_CHANNEL_POSITION_MASK(pos) (G_GUINT64_CONSTANT(1)<< GST_AUDIO_CHANNEL_POSITION ## pos)
|
||||
|
||||
/**
|
||||
* GstAudioFlags:
|
||||
* @GST_AUDIO_FLAG_NONE: no valid flag
|
||||
* @GST_AUDIO_FLAG_DEFAULT_POSITIONS: position array
|
||||
* contains the default layout for the number of channels.
|
||||
* @GST_AUDIO_FLAG_UNPOSITIONED: the position array explicitly
|
||||
* contains unpositioned channels.
|
||||
*
|
||||
|
@ -264,8 +364,7 @@ void gst_audio_format_fill_silence (const GstAudioFormatInfo *info
|
|||
*/
|
||||
typedef enum {
|
||||
GST_AUDIO_FLAG_NONE = 0,
|
||||
GST_AUDIO_FLAG_DEFAULT_POSITIONS = (1 << 0),
|
||||
GST_AUDIO_FLAG_UNPOSITIONED = (1 << 1)
|
||||
GST_AUDIO_FLAG_UNPOSITIONED = (1 << 0)
|
||||
} GstAudioFlags;
|
||||
|
||||
/**
|
||||
|
@ -314,7 +413,6 @@ GType gst_audio_info_get_type (void);
|
|||
#define GST_AUDIO_INFO_IS_BIG_ENDIAN(i) (GST_AUDIO_FORMAT_INFO_IS_BIG_ENDIAN((i)->finfo))
|
||||
|
||||
#define GST_AUDIO_INFO_FLAGS(info) ((info)->flags)
|
||||
#define GST_AUDIO_INFO_HAS_DEFAULT_POSITIONS(info) ((info)->flags & GST_AUDIO_FLAG_DEFAULT_POSITIONS)
|
||||
#define GST_AUDIO_INFO_IS_UNPOSITIONED(info) ((info)->flags & GST_AUDIO_FLAG_UNPOSITIONED)
|
||||
|
||||
#define GST_AUDIO_INFO_RATE(info) ((info)->rate)
|
||||
|
@ -328,7 +426,8 @@ GstAudioInfo * gst_audio_info_copy (const GstAudioInfo *info);
|
|||
void gst_audio_info_free (GstAudioInfo *info);
|
||||
|
||||
void gst_audio_info_set_format (GstAudioInfo *info, GstAudioFormat format,
|
||||
gint rate, gint channels);
|
||||
gint rate, gint channels,
|
||||
const GstAudioChannelPosition *position);
|
||||
|
||||
gboolean gst_audio_info_from_caps (GstAudioInfo *info, const GstCaps *caps);
|
||||
GstCaps * gst_audio_info_to_caps (const GstAudioInfo *info);
|
||||
|
@ -420,6 +519,19 @@ gboolean gst_audio_info_convert (const GstAudioInfo * info,
|
|||
GstBuffer * gst_audio_buffer_clip (GstBuffer *buffer, GstSegment *segment,
|
||||
gint rate, gint bpf);
|
||||
|
||||
|
||||
gboolean gst_audio_buffer_reorder_channels (GstBuffer * buffer,
|
||||
GstAudioFormat format,
|
||||
gint channels,
|
||||
const GstAudioChannelPosition * from,
|
||||
const GstAudioChannelPosition * to);
|
||||
|
||||
gboolean gst_audio_reorder_channels (gpointer data, gsize size,
|
||||
GstAudioFormat format,
|
||||
gint channels,
|
||||
const GstAudioChannelPosition * from,
|
||||
const GstAudioChannelPosition * to);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GST_AUDIO_AUDIO_H__ */
|
||||
|
|
|
@ -1,764 +0,0 @@
|
|||
/* GStreamer Multichannel-Audio helper functions
|
||||
* (c) 2004 Ronald Bultje <rbultje@ronald.bitfreak.net>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
/**
|
||||
* SECTION:gstmultichannel
|
||||
* @short_description: Support for multichannel audio elements
|
||||
*
|
||||
* This module contains some helper functions and a enum to work with
|
||||
* multichannel audio.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "multichannel.h"
|
||||
|
||||
#define GST_AUDIO_CHANNEL_POSITIONS_FIELD_NAME "channel-positions"
|
||||
|
||||
/**
|
||||
* gst_audio_check_channel_positions:
|
||||
* @pos: An array of #GstAudioChannelPosition.
|
||||
* @channels: The number of elements in @pos.
|
||||
*
|
||||
* This functions checks if the given channel positions are valid. Channel
|
||||
* positions are valid if:
|
||||
* <itemizedlist>
|
||||
* <listitem><para>No channel positions appears twice or all positions are %GST_AUDIO_CHANNEL_POSITION_NONE.
|
||||
* </para></listitem>
|
||||
* <listitem><para>Either all or none of the channel positions are %GST_AUDIO_CHANNEL_POSITION_NONE.
|
||||
* </para></listitem>
|
||||
* <listitem><para>%GST_AUDIO_CHANNEL_POSITION_FRONT_MONO and %GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT or %GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT don't appear together in the given positions.
|
||||
* </para></listitem>
|
||||
* </itemizedlist>
|
||||
*
|
||||
* Since: 0.10.20
|
||||
*
|
||||
* Returns: %TRUE if the given channel positions are valid
|
||||
* and %FALSE otherwise.
|
||||
*/
|
||||
gboolean
|
||||
gst_audio_check_channel_positions (const GstAudioChannelPosition * pos,
|
||||
guint channels)
|
||||
{
|
||||
gint i, n;
|
||||
|
||||
const struct
|
||||
{
|
||||
const GstAudioChannelPosition pos1[2];
|
||||
const GstAudioChannelPosition pos2[1];
|
||||
} conf[] = {
|
||||
/* front: mono <-> stereo */
|
||||
{ {
|
||||
GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
|
||||
GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT}, {
|
||||
GST_AUDIO_CHANNEL_POSITION_FRONT_MONO}}, { {
|
||||
GST_AUDIO_CHANNEL_POSITION_INVALID}}
|
||||
};
|
||||
|
||||
g_return_val_if_fail (pos != NULL, FALSE);
|
||||
g_return_val_if_fail (channels > 0, FALSE);
|
||||
|
||||
/* check for invalid channel positions */
|
||||
for (n = 0; n < channels; n++) {
|
||||
if (pos[n] <= GST_AUDIO_CHANNEL_POSITION_INVALID ||
|
||||
pos[n] >= GST_AUDIO_CHANNEL_POSITION_NUM) {
|
||||
GST_WARNING ("Channel position %d for channel %d is invalid", pos[n], n);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/* either all channel positions are NONE or all are defined,
|
||||
* but having only some channel positions NONE and others not
|
||||
* is not allowed */
|
||||
if (pos[0] == GST_AUDIO_CHANNEL_POSITION_NONE) {
|
||||
for (n = 1; n < channels; ++n) {
|
||||
if (pos[n] != GST_AUDIO_CHANNEL_POSITION_NONE) {
|
||||
GST_WARNING ("Either all channel positions must be defined, or all "
|
||||
"be set to NONE, having only some defined is not allowed");
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
/* all positions are NONE, we are done here */
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* check for multiple position occurrences */
|
||||
for (i = GST_AUDIO_CHANNEL_POSITION_INVALID + 1;
|
||||
i < GST_AUDIO_CHANNEL_POSITION_NUM; i++) {
|
||||
gint count = 0;
|
||||
|
||||
for (n = 0; n < channels; n++) {
|
||||
if (pos[n] == i)
|
||||
count++;
|
||||
}
|
||||
|
||||
/* NONE may not occur mixed with other channel positions */
|
||||
if (i == GST_AUDIO_CHANNEL_POSITION_NONE && count > 0) {
|
||||
GST_WARNING ("Either all channel positions must be defined, or all "
|
||||
"be set to NONE, having only some defined is not allowed");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (count > 1) {
|
||||
GST_WARNING ("Channel position %d occurred %d times, not allowed",
|
||||
i, count);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/* check for position conflicts */
|
||||
for (i = 0; conf[i].pos1[0] != GST_AUDIO_CHANNEL_POSITION_INVALID; i++) {
|
||||
gboolean found1 = FALSE, found2 = FALSE;
|
||||
|
||||
for (n = 0; n < channels; n++) {
|
||||
if (pos[n] == conf[i].pos1[0] || pos[n] == conf[i].pos1[1])
|
||||
found1 = TRUE;
|
||||
else if (pos[n] == conf[i].pos2[0])
|
||||
found2 = TRUE;
|
||||
}
|
||||
|
||||
if (found1 && found2) {
|
||||
GST_WARNING ("Found conflicting channel positions %d/%d and %d",
|
||||
conf[i].pos1[0], conf[i].pos1[1], conf[i].pos2[0]);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* FIXME: these default positions may or may not be correct. In any
|
||||
* case, they are mostly just a fallback for buggy plugins, so it
|
||||
* should not really matter too much */
|
||||
#define NUM_DEF_CHANS 8
|
||||
static const GstAudioChannelPosition
|
||||
default_positions[NUM_DEF_CHANS][NUM_DEF_CHANS] = {
|
||||
/* 1 channel */
|
||||
{
|
||||
GST_AUDIO_CHANNEL_POSITION_FRONT_MONO,
|
||||
},
|
||||
/* 2 channels */
|
||||
{
|
||||
GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
|
||||
GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
|
||||
},
|
||||
/* 3 channels (2.1) */
|
||||
{
|
||||
GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
|
||||
GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
|
||||
GST_AUDIO_CHANNEL_POSITION_LFE, /* or FRONT_CENTER for 3.0? */
|
||||
},
|
||||
/* 4 channels (4.0 or 3.1?) */
|
||||
{
|
||||
GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
|
||||
GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
|
||||
GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
|
||||
GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,
|
||||
},
|
||||
/* 5 channels */
|
||||
{
|
||||
GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
|
||||
GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
|
||||
GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
|
||||
GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,
|
||||
GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
|
||||
},
|
||||
/* 6 channels */
|
||||
{
|
||||
GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
|
||||
GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
|
||||
GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
|
||||
GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,
|
||||
GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
|
||||
GST_AUDIO_CHANNEL_POSITION_LFE,
|
||||
},
|
||||
/* 7 channels */
|
||||
{
|
||||
GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
|
||||
GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
|
||||
GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
|
||||
GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,
|
||||
GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
|
||||
GST_AUDIO_CHANNEL_POSITION_LFE,
|
||||
GST_AUDIO_CHANNEL_POSITION_REAR_CENTER,
|
||||
},
|
||||
/* 8 channels */
|
||||
{
|
||||
GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
|
||||
GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
|
||||
GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
|
||||
GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,
|
||||
GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
|
||||
GST_AUDIO_CHANNEL_POSITION_LFE,
|
||||
GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT,
|
||||
GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT,
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* gst_audio_get_channel_positions:
|
||||
* @str: A #GstStructure to retrieve channel positions from.
|
||||
*
|
||||
* Retrieves a number of (fixed!) audio channel positions from
|
||||
* the provided #GstStructure and returns it as a newly allocated
|
||||
* array. The caller should g_free () this array. The caller
|
||||
* should also check that the members in this #GstStructure are
|
||||
* indeed "fixed" before calling this function.
|
||||
*
|
||||
* Returns: a newly allocated array containing the channel
|
||||
* positions as provided in the given #GstStructure. Returns
|
||||
* NULL on error.
|
||||
*/
|
||||
|
||||
GstAudioChannelPosition *
|
||||
gst_audio_get_channel_positions (GstStructure * str)
|
||||
{
|
||||
GstAudioChannelPosition *pos;
|
||||
gint channels, n;
|
||||
const GValue *pos_val_arr, *pos_val_entry;
|
||||
gboolean res;
|
||||
GType t;
|
||||
|
||||
/* get number of channels, general type checkups */
|
||||
g_return_val_if_fail (str != NULL, NULL);
|
||||
res = gst_structure_get_int (str, "channels", &channels);
|
||||
g_return_val_if_fail (res, NULL);
|
||||
g_return_val_if_fail (channels > 0, NULL);
|
||||
pos_val_arr = gst_structure_get_value (str,
|
||||
GST_AUDIO_CHANNEL_POSITIONS_FIELD_NAME);
|
||||
|
||||
/* The following checks are here to retain compatibility for plugins not
|
||||
* implementing this field. They expect that channels=1 implies mono
|
||||
* and channels=2 implies stereo, so we follow that. */
|
||||
if (pos_val_arr == NULL) {
|
||||
/* channel layouts for 1 and 2 channels are implicit, don't warn */
|
||||
if (channels > 2) {
|
||||
g_warning ("Failed to retrieve channel layout from caps. This usually "
|
||||
"means there is a GStreamer element that does not implement "
|
||||
"multichannel audio correctly. Please file a bug.");
|
||||
}
|
||||
|
||||
/* just return some default channel layout if we have one */
|
||||
if (channels >= 1 && channels <= NUM_DEF_CHANS) {
|
||||
const GstAudioChannelPosition *p;
|
||||
|
||||
p = default_positions[channels - 1];
|
||||
return g_memdup (p, channels * sizeof (GstAudioChannelPosition));
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
g_return_val_if_fail (gst_value_array_get_size (pos_val_arr) == channels,
|
||||
NULL);
|
||||
for (n = 0; n < channels; n++) {
|
||||
t = G_VALUE_TYPE (gst_value_array_get_value (pos_val_arr, n));
|
||||
g_return_val_if_fail (t == GST_TYPE_AUDIO_CHANNEL_POSITION, NULL);
|
||||
}
|
||||
|
||||
/* ... and fill array */
|
||||
pos = g_new (GstAudioChannelPosition, channels);
|
||||
for (n = 0; n < channels; n++) {
|
||||
pos_val_entry = gst_value_array_get_value (pos_val_arr, n);
|
||||
pos[n] = g_value_get_enum (pos_val_entry);
|
||||
}
|
||||
|
||||
if (!gst_audio_check_channel_positions (pos, channels)) {
|
||||
g_free (pos);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
void priv_gst_audio_info_fill_default_channel_positions (GstAudioInfo * info);
|
||||
|
||||
void
|
||||
priv_gst_audio_info_fill_default_channel_positions (GstAudioInfo * info)
|
||||
{
|
||||
guint channels, i;
|
||||
|
||||
g_assert (info != NULL);
|
||||
|
||||
channels = GST_AUDIO_INFO_CHANNELS (info);
|
||||
|
||||
g_assert (channels > 0);
|
||||
|
||||
if (channels <= NUM_DEF_CHANS) {
|
||||
/* just return some default channel layout if we have one */
|
||||
for (i = 0; i < channels; ++i)
|
||||
info->position[i] = default_positions[channels - 1][i];
|
||||
} else {
|
||||
/* for many many channels, the positions are always NONE */
|
||||
for (i = 0; i < G_N_ELEMENTS (info->position); i++)
|
||||
info->position[i] = GST_AUDIO_CHANNEL_POSITION_NONE;
|
||||
}
|
||||
|
||||
info->flags |= GST_AUDIO_FLAG_DEFAULT_POSITIONS;
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_audio_set_channel_positions:
|
||||
* @str: A #GstStructure to set channel positions on.
|
||||
* @pos: an array of channel positions. The number of members
|
||||
* in this array should be equal to the (fixed!) number
|
||||
* of the "channels" field in the given #GstStructure.
|
||||
*
|
||||
* Adds a "channel-positions" field to the given #GstStructure,
|
||||
* which will represent the channel positions as given in the
|
||||
* provided #GstAudioChannelPosition array.
|
||||
*/
|
||||
|
||||
void
|
||||
gst_audio_set_channel_positions (GstStructure * str,
|
||||
const GstAudioChannelPosition * pos)
|
||||
{
|
||||
GValue pos_val_arr = { 0 }, pos_val_entry = {
|
||||
0};
|
||||
gint channels, n;
|
||||
|
||||
gboolean res;
|
||||
|
||||
/* get number of channels, checkups */
|
||||
g_return_if_fail (str != NULL);
|
||||
g_return_if_fail (pos != NULL);
|
||||
res = gst_structure_get_int (str, "channels", &channels);
|
||||
g_return_if_fail (res);
|
||||
g_return_if_fail (channels > 0);
|
||||
if (!gst_audio_check_channel_positions (pos, channels))
|
||||
return;
|
||||
|
||||
/* build gvaluearray from positions */
|
||||
g_value_init (&pos_val_entry, GST_TYPE_AUDIO_CHANNEL_POSITION);
|
||||
g_value_init (&pos_val_arr, GST_TYPE_ARRAY);
|
||||
for (n = 0; n < channels; n++) {
|
||||
g_value_set_enum (&pos_val_entry, pos[n]);
|
||||
gst_value_array_append_value (&pos_val_arr, &pos_val_entry);
|
||||
}
|
||||
g_value_unset (&pos_val_entry);
|
||||
|
||||
/* add to structure */
|
||||
gst_structure_set_value (str,
|
||||
GST_AUDIO_CHANNEL_POSITIONS_FIELD_NAME, &pos_val_arr);
|
||||
g_value_unset (&pos_val_arr);
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_audio_set_structure_channel_positions_list:
|
||||
* @str: #GstStructure to set the list of channel positions
|
||||
* on.
|
||||
* @pos: the array containing one or more possible audio
|
||||
* channel positions that we should add in each value
|
||||
* of the array in the given structure.
|
||||
* @num_positions: the number of values in pos.
|
||||
*
|
||||
* Sets a (possibly non-fixed) list of possible audio channel
|
||||
* positions (given in pos) on the given structure. The
|
||||
* structure, after this function has been called, will contain
|
||||
* a "channel-positions" field with an array of the size of
|
||||
* the "channels" field value in the given structure (note
|
||||
* that this means that the channels field in the provided
|
||||
* structure should be fixed!). Each value in the array will
|
||||
* contain each of the values given in the pos array.
|
||||
*/
|
||||
|
||||
void
|
||||
gst_audio_set_structure_channel_positions_list (GstStructure * str,
|
||||
const GstAudioChannelPosition * pos, gint num_positions)
|
||||
{
|
||||
gint channels, n, c;
|
||||
GValue pos_val_arr = { 0 }, pos_val_list = {
|
||||
0}, pos_val_entry = {
|
||||
0};
|
||||
gboolean res;
|
||||
|
||||
/* get number of channels, general type checkups */
|
||||
g_return_if_fail (str != NULL);
|
||||
g_return_if_fail (num_positions > 0);
|
||||
g_return_if_fail (pos != NULL);
|
||||
res = gst_structure_get_int (str, "channels", &channels);
|
||||
g_return_if_fail (res);
|
||||
g_return_if_fail (channels > 0);
|
||||
|
||||
/* create the array of lists */
|
||||
g_value_init (&pos_val_arr, GST_TYPE_ARRAY);
|
||||
g_value_init (&pos_val_entry, GST_TYPE_AUDIO_CHANNEL_POSITION);
|
||||
for (n = 0; n < channels; n++) {
|
||||
g_value_init (&pos_val_list, GST_TYPE_LIST);
|
||||
for (c = 0; c < num_positions; c++) {
|
||||
g_value_set_enum (&pos_val_entry, pos[c]);
|
||||
gst_value_list_append_value (&pos_val_list, &pos_val_entry);
|
||||
}
|
||||
gst_value_array_append_value (&pos_val_arr, &pos_val_list);
|
||||
g_value_unset (&pos_val_list);
|
||||
}
|
||||
g_value_unset (&pos_val_entry);
|
||||
gst_structure_set_value (str, GST_AUDIO_CHANNEL_POSITIONS_FIELD_NAME,
|
||||
&pos_val_arr);
|
||||
g_value_unset (&pos_val_arr);
|
||||
}
|
||||
|
||||
/*
|
||||
* Helper function for below. The structure will be conserved,
|
||||
* but might be cut down. Any additional structures that were
|
||||
* created will be stored in the returned caps.
|
||||
*/
|
||||
|
||||
static GstCaps *
|
||||
add_list_to_struct (GstStructure * str,
|
||||
const GstAudioChannelPosition * pos, gint num_positions)
|
||||
{
|
||||
GstCaps *caps = gst_caps_new_empty ();
|
||||
|
||||
const GValue *chan_val;
|
||||
|
||||
chan_val = gst_structure_get_value (str, "channels");
|
||||
if (G_VALUE_TYPE (chan_val) == G_TYPE_INT) {
|
||||
gst_audio_set_structure_channel_positions_list (str, pos, num_positions);
|
||||
} else if (G_VALUE_TYPE (chan_val) == GST_TYPE_LIST) {
|
||||
gint size;
|
||||
|
||||
const GValue *sub_val;
|
||||
|
||||
size = gst_value_list_get_size (chan_val);
|
||||
sub_val = gst_value_list_get_value (chan_val, 0);
|
||||
gst_structure_set_value (str, "channels", sub_val);
|
||||
gst_caps_append (caps, add_list_to_struct (str, pos, num_positions));
|
||||
while (--size > 0) {
|
||||
str = gst_structure_copy (str);
|
||||
sub_val = gst_value_list_get_value (chan_val, size);
|
||||
gst_structure_set_value (str, "channels", sub_val);
|
||||
gst_caps_append (caps, add_list_to_struct (str, pos, num_positions));
|
||||
gst_caps_append_structure (caps, str);
|
||||
}
|
||||
} else if (G_VALUE_TYPE (chan_val) == GST_TYPE_INT_RANGE) {
|
||||
gint min, max;
|
||||
|
||||
min = gst_value_get_int_range_min (chan_val);
|
||||
max = gst_value_get_int_range_max (chan_val);
|
||||
|
||||
gst_structure_set (str, "channels", G_TYPE_INT, min, NULL);
|
||||
gst_audio_set_structure_channel_positions_list (str, pos, num_positions);
|
||||
for (++min; min < max; min++) {
|
||||
str = gst_structure_copy (str);
|
||||
gst_structure_set (str, "channels", G_TYPE_INT, min, NULL);
|
||||
gst_audio_set_structure_channel_positions_list (str, pos, num_positions);
|
||||
gst_caps_append_structure (caps, str);
|
||||
}
|
||||
} else {
|
||||
g_warning ("Unexpected value type '%s' for channels field",
|
||||
GST_STR_NULL (g_type_name (G_VALUE_TYPE (chan_val))));
|
||||
}
|
||||
|
||||
return caps;
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_audio_set_caps_channel_positions_list:
|
||||
* @caps: #GstCaps to set the list of channel positions on.
|
||||
* @pos: the array containing one or more possible audio
|
||||
* channel positions that we should add in each value
|
||||
* of the array in the given structure.
|
||||
* @num_positions: the number of values in pos.
|
||||
*
|
||||
* Sets a (possibly non-fixed) list of possible audio channel
|
||||
* positions (given in pos) on the given caps. Each of the
|
||||
* structures of the caps, after this function has been called,
|
||||
* will contain a "channel-positions" field with an array.
|
||||
* Each value in the array will contain each of the values given
|
||||
* in the pos array. Note that the size of the caps might be
|
||||
* increased by this, since each structure with a "channel-
|
||||
* positions" field needs to have a fixed "channels" field.
|
||||
* The input caps is not required to have this.
|
||||
*/
|
||||
|
||||
void
|
||||
gst_audio_set_caps_channel_positions_list (GstCaps * caps,
|
||||
const GstAudioChannelPosition * pos, gint num_positions)
|
||||
{
|
||||
gint size, n;
|
||||
|
||||
/* get number of channels, general type checkups */
|
||||
g_return_if_fail (caps != NULL);
|
||||
g_return_if_fail (num_positions > 0);
|
||||
g_return_if_fail (pos != NULL);
|
||||
|
||||
size = gst_caps_get_size (caps);
|
||||
for (n = 0; n < size; n++) {
|
||||
gst_caps_append (caps, add_list_to_struct (gst_caps_get_structure (caps,
|
||||
n), pos, num_positions));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_audio_fixate_channel_positions:
|
||||
* @str: a #GstStructure containing a (possibly unfixed)
|
||||
* "channel-positions" field.
|
||||
*
|
||||
* Custom fixate function. Elements that implement some sort of
|
||||
* channel conversion algorithm should use this function for
|
||||
* fixating on GstAudioChannelPosition properties. It will take
|
||||
* care of equal channel positioning (left/right). Caller g_free()s
|
||||
* the return value. The input properties may be (and are supposed
|
||||
* to be) unfixed.
|
||||
* Note that this function is mostly a hack because we currently
|
||||
* have no way to add default fixation functions for new GTypes.
|
||||
*
|
||||
* Returns: fixed values that the caller could use as a fixed
|
||||
* set of #GstAudioChannelPosition values.
|
||||
*/
|
||||
|
||||
GstAudioChannelPosition *
|
||||
gst_audio_fixate_channel_positions (GstStructure * str)
|
||||
{
|
||||
GstAudioChannelPosition *pos;
|
||||
|
||||
gint channels, n, num_unfixed = 0, i, c;
|
||||
|
||||
const GValue *pos_val_arr, *pos_val_entry, *pos_val;
|
||||
|
||||
gboolean res, is_stereo = TRUE;
|
||||
|
||||
GType t;
|
||||
|
||||
/*
|
||||
* We're going to do this cluelessly. We'll make an array of values that
|
||||
* conflict with each other and, for each iteration in this array, pick
|
||||
* either one until all unknown values are filled. This might not work in
|
||||
* corner cases but should work OK for the general case.
|
||||
*/
|
||||
const struct
|
||||
{
|
||||
const GstAudioChannelPosition pos1[2];
|
||||
const GstAudioChannelPosition pos2[1];
|
||||
} conf[] = {
|
||||
/* front: mono <-> stereo */
|
||||
{
|
||||
{
|
||||
GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
|
||||
GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT}, {
|
||||
GST_AUDIO_CHANNEL_POSITION_FRONT_MONO}}, { {
|
||||
GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER,
|
||||
GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER}, {
|
||||
GST_AUDIO_CHANNEL_POSITION_INVALID}}, { {
|
||||
GST_AUDIO_CHANNEL_POSITION_INVALID, GST_AUDIO_CHANNEL_POSITION_INVALID}, {
|
||||
GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER}}, { {
|
||||
GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
|
||||
GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT}, {
|
||||
GST_AUDIO_CHANNEL_POSITION_INVALID}}, { {
|
||||
GST_AUDIO_CHANNEL_POSITION_INVALID, GST_AUDIO_CHANNEL_POSITION_INVALID}, {
|
||||
GST_AUDIO_CHANNEL_POSITION_REAR_CENTER}}, { {
|
||||
GST_AUDIO_CHANNEL_POSITION_INVALID, GST_AUDIO_CHANNEL_POSITION_INVALID}, {
|
||||
GST_AUDIO_CHANNEL_POSITION_LFE}}, { {
|
||||
GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT,
|
||||
GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT}, {
|
||||
GST_AUDIO_CHANNEL_POSITION_INVALID}}, { {
|
||||
GST_AUDIO_CHANNEL_POSITION_INVALID, GST_AUDIO_CHANNEL_POSITION_INVALID}, {
|
||||
GST_AUDIO_CHANNEL_POSITION_INVALID}}
|
||||
};
|
||||
struct
|
||||
{
|
||||
gint num_opt[3];
|
||||
guint num_opts[3];
|
||||
gboolean is_fixed[3];
|
||||
gint choice; /* -1 is none, 0 is the two, 1 is the one */
|
||||
} opt;
|
||||
|
||||
/* get number of channels, general type checkups */
|
||||
g_return_val_if_fail (str != NULL, NULL);
|
||||
res = gst_structure_get_int (str, "channels", &channels);
|
||||
g_return_val_if_fail (res, NULL);
|
||||
g_return_val_if_fail (channels > 0, NULL);
|
||||
|
||||
/* 0.8.x mono/stereo checks */
|
||||
pos_val_arr = gst_structure_get_value (str,
|
||||
GST_AUDIO_CHANNEL_POSITIONS_FIELD_NAME);
|
||||
if (!pos_val_arr && (channels == 1 || channels == 2)) {
|
||||
pos = g_new (GstAudioChannelPosition, channels);
|
||||
if (channels == 1) {
|
||||
pos[0] = GST_AUDIO_CHANNEL_POSITION_FRONT_MONO;
|
||||
} else {
|
||||
pos[0] = GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT;
|
||||
pos[1] = GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT;
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
g_return_val_if_fail (pos_val_arr != NULL, NULL);
|
||||
g_return_val_if_fail (gst_value_array_get_size (pos_val_arr) == channels,
|
||||
NULL);
|
||||
for (n = 0; n < channels; n++) {
|
||||
t = G_VALUE_TYPE (gst_value_array_get_value (pos_val_arr, n));
|
||||
g_return_val_if_fail (t == GST_TYPE_LIST ||
|
||||
t == GST_TYPE_AUDIO_CHANNEL_POSITION, NULL);
|
||||
}
|
||||
|
||||
/* all unknown, to start with */
|
||||
pos = g_new (GstAudioChannelPosition, channels);
|
||||
for (n = 0; n < channels; n++)
|
||||
pos[n] = GST_AUDIO_CHANNEL_POSITION_INVALID;
|
||||
num_unfixed = channels;
|
||||
|
||||
/* Iterate the array of conflicting values */
|
||||
for (i = 0; conf[i].pos1[0] != GST_AUDIO_CHANNEL_POSITION_INVALID ||
|
||||
conf[i].pos2[0] != GST_AUDIO_CHANNEL_POSITION_INVALID; i++) {
|
||||
/* front/center only important if not mono (obviously) */
|
||||
if (conf[i].pos1[0] == GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER &&
|
||||
!is_stereo)
|
||||
continue;
|
||||
|
||||
/* init values */
|
||||
for (n = 0; n < 3; n++) {
|
||||
opt.num_opt[n] = -1;
|
||||
opt.num_opts[n] = -1;
|
||||
opt.is_fixed[n] = FALSE;
|
||||
}
|
||||
|
||||
/* Now, we'll see for each channel if it allows for any of the values in
|
||||
* the set of conflicting audio channel positions and keep scores. */
|
||||
for (n = 0; n < channels; n++) {
|
||||
/* if the channel is already taken, don't bother */
|
||||
if (pos[n] != GST_AUDIO_CHANNEL_POSITION_INVALID)
|
||||
continue;
|
||||
|
||||
pos_val_entry = gst_value_array_get_value (pos_val_arr, n);
|
||||
t = G_VALUE_TYPE (pos_val_entry);
|
||||
if (t == GST_TYPE_LIST) {
|
||||
/* This algorhythm is suboptimal. */
|
||||
for (c = 0; c < gst_value_list_get_size (pos_val_entry); c++) {
|
||||
pos_val = gst_value_list_get_value (pos_val_entry, c);
|
||||
if (g_value_get_enum (pos_val) == conf[i].pos1[0] &&
|
||||
opt.num_opts[0] > gst_value_list_get_size (pos_val_entry) &&
|
||||
!opt.is_fixed[0]) {
|
||||
/* Now test if the old position of num_opt[0] also allows for
|
||||
* the other channel (which was skipped previously). If so,
|
||||
* keep score. */
|
||||
if (opt.num_opt[0] != -1) {
|
||||
gint c1;
|
||||
|
||||
pos_val_entry = gst_value_array_get_value (pos_val_arr,
|
||||
opt.num_opt[0]);
|
||||
if (G_VALUE_TYPE (pos_val_entry) == GST_TYPE_LIST) {
|
||||
for (c1 = 0; c1 < gst_value_list_get_size (pos_val_entry); c1++) {
|
||||
pos_val = gst_value_list_get_value (pos_val_entry, c1);
|
||||
if (g_value_get_enum (pos_val) == conf[i].pos1[1] &&
|
||||
opt.num_opts[1] > opt.num_opts[0] && !opt.is_fixed[1]) {
|
||||
opt.num_opts[1] = opt.num_opts[0];
|
||||
opt.num_opt[1] = opt.num_opt[0];
|
||||
}
|
||||
}
|
||||
pos_val = gst_value_list_get_value (pos_val_entry, c);
|
||||
}
|
||||
pos_val_entry = gst_value_array_get_value (pos_val_arr, n);
|
||||
}
|
||||
|
||||
/* and save values */
|
||||
opt.num_opts[0] = gst_value_list_get_size (pos_val_entry);
|
||||
opt.num_opt[0] = n;
|
||||
} else if (g_value_get_enum (pos_val) == conf[i].pos1[1] &&
|
||||
opt.num_opts[1] > gst_value_list_get_size (pos_val_entry) &&
|
||||
!opt.is_fixed[1] && n != opt.num_opt[0]) {
|
||||
opt.num_opts[1] = gst_value_list_get_size (pos_val_entry);
|
||||
opt.num_opt[1] = n;
|
||||
}
|
||||
|
||||
/* 2 goes separately, because 0/1 vs. 2 are separate */
|
||||
if (g_value_get_enum (pos_val) == conf[i].pos2[0] &&
|
||||
opt.num_opts[2] > gst_value_list_get_size (pos_val_entry) &&
|
||||
!opt.is_fixed[2]) {
|
||||
opt.num_opts[2] = gst_value_list_get_size (pos_val_entry);
|
||||
opt.num_opt[2] = n;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (g_value_get_enum (pos_val_entry) == conf[i].pos1[0]) {
|
||||
opt.num_opt[0] = n;
|
||||
opt.is_fixed[0] = TRUE;
|
||||
} else if (g_value_get_enum (pos_val_entry) == conf[i].pos1[1]) {
|
||||
opt.num_opt[1] = n;
|
||||
opt.is_fixed[1] = TRUE;
|
||||
} else if (g_value_get_enum (pos_val_entry) == conf[i].pos2[0]) {
|
||||
opt.num_opt[2] = n;
|
||||
opt.is_fixed[2] = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* check our results and choose either one */
|
||||
if ((opt.is_fixed[0] || opt.is_fixed[1]) && opt.is_fixed[2]) {
|
||||
g_warning ("Pre-fixated on both %d/%d and %d - conflict!",
|
||||
conf[i].pos1[0], conf[i].pos1[1], conf[i].pos2[0]);
|
||||
g_free (pos);
|
||||
return NULL;
|
||||
} else if ((opt.is_fixed[0] && opt.num_opt[1] == -1) ||
|
||||
(opt.is_fixed[1] && opt.num_opt[0] == -1)) {
|
||||
g_warning ("Pre-fixated one side, but other side n/a of %d/%d",
|
||||
conf[i].pos1[0], conf[i].pos1[1]);
|
||||
g_free (pos);
|
||||
return NULL;
|
||||
} else if (opt.is_fixed[0] || opt.is_fixed[1]) {
|
||||
opt.choice = 0;
|
||||
} else if (opt.is_fixed[2]) {
|
||||
opt.choice = 1;
|
||||
} else if (opt.num_opt[0] != -1 && opt.num_opt[1] != -1) {
|
||||
opt.choice = 0;
|
||||
} else if (opt.num_opt[2] != -1) {
|
||||
opt.choice = 1;
|
||||
} else {
|
||||
opt.choice = -1;
|
||||
}
|
||||
|
||||
/* stereo? Note that we keep is_stereo to TRUE if we didn't decide on
|
||||
* any arrangement. The mono/stereo channels might be handled elsewhere
|
||||
* which is clearly outside the scope of this element, so we cannot
|
||||
* know and expect the application to handle that then. */
|
||||
if (conf[i].pos2[0] == GST_AUDIO_CHANNEL_POSITION_FRONT_MONO &&
|
||||
opt.choice == 1) {
|
||||
is_stereo = FALSE;
|
||||
}
|
||||
|
||||
/* now actually decide what we'll do and fixate on that */
|
||||
if (opt.choice == 0) {
|
||||
g_assert (conf[i].pos1[0] != GST_AUDIO_CHANNEL_POSITION_INVALID &&
|
||||
conf[i].pos1[1] != GST_AUDIO_CHANNEL_POSITION_INVALID);
|
||||
pos[opt.num_opt[0]] = conf[i].pos1[0];
|
||||
pos[opt.num_opt[1]] = conf[i].pos1[1];
|
||||
num_unfixed -= 2;
|
||||
} else if (opt.choice == 1) {
|
||||
g_assert (conf[i].pos2[0] != GST_AUDIO_CHANNEL_POSITION_INVALID);
|
||||
pos[opt.num_opt[2]] = conf[i].pos2[0];
|
||||
num_unfixed--;
|
||||
}
|
||||
}
|
||||
|
||||
/* safety check */
|
||||
if (num_unfixed > 0) {
|
||||
g_warning ("%d unfixed channel positions left after fixation!",
|
||||
num_unfixed);
|
||||
g_free (pos);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!gst_audio_check_channel_positions (pos, channels)) {
|
||||
g_free (pos);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return pos;
|
||||
}
|
|
@ -1,134 +0,0 @@
|
|||
/* GStreamer Multichannel-Audio helper functions
|
||||
* (c) 2004 Ronald Bultje <rbultje@ronald.bitfreak.net>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <gst/audio/audio.h>
|
||||
#include <gst/audio/audio-enumtypes.h>
|
||||
|
||||
#ifndef __GST_AUDIO_MULTICHANNEL_H__
|
||||
#define __GST_AUDIO_MULTICHANNEL_H__
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/**
|
||||
* GstAudioChannelPosition:
|
||||
* @GST_AUDIO_CHANNEL_POSITION_FRONT_MONO: front mono
|
||||
* @GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT: front left
|
||||
* @GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT: front right
|
||||
* @GST_AUDIO_CHANNEL_POSITION_REAR_CENTER: rear center
|
||||
* @GST_AUDIO_CHANNEL_POSITION_REAR_LEFT: rear left
|
||||
* @GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT: rear right
|
||||
* @GST_AUDIO_CHANNEL_POSITION_LFE: subwoofer
|
||||
* @GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER: front center
|
||||
* @GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER: front left of center
|
||||
* @GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER: front right of center
|
||||
* @GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT: side left
|
||||
* @GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT: side right
|
||||
* @GST_AUDIO_CHANNEL_POSITION_TOP_CENTER: top center
|
||||
* @GST_AUDIO_CHANNEL_POSITION_TOP_FRONT_LEFT: top front left
|
||||
* @GST_AUDIO_CHANNEL_POSITION_TOP_FRONT_RIGHT: top front right
|
||||
* @GST_AUDIO_CHANNEL_POSITION_TOP_FRONT_CENTER: top front center
|
||||
* @GST_AUDIO_CHANNEL_POSITION_TOP_REAR_LEFT: top rear left
|
||||
* @GST_AUDIO_CHANNEL_POSITION_TOP_REAR_RIGHT: top rear right
|
||||
* @GST_AUDIO_CHANNEL_POSITION_TOP_REAR_CENTER: top rear center
|
||||
* @GST_AUDIO_CHANNEL_POSITION_NONE: used for position-less channels, e.g.
|
||||
* from a sound card that records 1024 channels; mutually exclusive with
|
||||
* any other channel position
|
||||
* @GST_AUDIO_CHANNEL_POSITION_INVALID: invalid position
|
||||
*
|
||||
* Audio channel positions.
|
||||
*/
|
||||
typedef enum {
|
||||
GST_AUDIO_CHANNEL_POSITION_INVALID = -1,
|
||||
|
||||
/* Main front speakers. Mono and left/right are mututally exclusive! */
|
||||
GST_AUDIO_CHANNEL_POSITION_FRONT_MONO,
|
||||
GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
|
||||
GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
|
||||
|
||||
/* rear. Left/right and center are mututally exclusive! */
|
||||
GST_AUDIO_CHANNEL_POSITION_REAR_CENTER,
|
||||
GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
|
||||
GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,
|
||||
|
||||
/* subwoofer/low-frequency */
|
||||
GST_AUDIO_CHANNEL_POSITION_LFE,
|
||||
|
||||
/* Center front speakers. Center and left/right_of_center cannot be
|
||||
* used together! */
|
||||
GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
|
||||
GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER,
|
||||
GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER,
|
||||
|
||||
/* sides */
|
||||
GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT,
|
||||
GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT,
|
||||
|
||||
GST_AUDIO_CHANNEL_POSITION_TOP_CENTER,
|
||||
GST_AUDIO_CHANNEL_POSITION_TOP_FRONT_LEFT,
|
||||
GST_AUDIO_CHANNEL_POSITION_TOP_FRONT_RIGHT,
|
||||
GST_AUDIO_CHANNEL_POSITION_TOP_FRONT_CENTER,
|
||||
GST_AUDIO_CHANNEL_POSITION_TOP_REAR_LEFT,
|
||||
GST_AUDIO_CHANNEL_POSITION_TOP_REAR_RIGHT,
|
||||
GST_AUDIO_CHANNEL_POSITION_TOP_REAR_CENTER,
|
||||
|
||||
/* for multi-channel input and output with more than 8 channels,
|
||||
* incompatible with all other positions, either all positions
|
||||
* are defined or all positions are undefined, but can't mix'n'match */
|
||||
GST_AUDIO_CHANNEL_POSITION_NONE,
|
||||
|
||||
/*< private >*/
|
||||
/* don't use - counter */
|
||||
GST_AUDIO_CHANNEL_POSITION_NUM
|
||||
} GstAudioChannelPosition;
|
||||
|
||||
/* Retrieves or sets the positions from/to a GstStructure. Only
|
||||
* works with fixed caps, caller should check for that! Caller
|
||||
* g_free()s result of the getter. */
|
||||
GstAudioChannelPosition *
|
||||
gst_audio_get_channel_positions (GstStructure *str);
|
||||
void gst_audio_set_channel_positions (GstStructure *str,
|
||||
const GstAudioChannelPosition *pos);
|
||||
|
||||
/* Sets a (non-fixed) list of possible audio channel positions
|
||||
* on a structure (this requires the "channels" property to
|
||||
* be fixed!) or on a caps (here, the "channels" property may be
|
||||
* unfixed and the caps may even contain multiple structures). */
|
||||
void gst_audio_set_structure_channel_positions_list
|
||||
(GstStructure *str,
|
||||
const GstAudioChannelPosition *pos,
|
||||
gint num_positions);
|
||||
void gst_audio_set_caps_channel_positions_list
|
||||
(GstCaps *caps,
|
||||
const GstAudioChannelPosition *pos,
|
||||
gint num_positions);
|
||||
|
||||
/* Custom fixate function. Elements that implement some sort of
|
||||
* channel conversion algorithm should use this function for
|
||||
* fixating on GstAudioChannelPosition properties. It will take
|
||||
* care of equal channel positioning (left/right). Caller g_free()s
|
||||
* the return value. The input properties may be (and are supposed
|
||||
* to be) unfixed. */
|
||||
GstAudioChannelPosition *
|
||||
gst_audio_fixate_channel_positions (GstStructure *str);
|
||||
|
||||
gboolean gst_audio_check_channel_positions (const GstAudioChannelPosition * pos, guint channels);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GST_AUDIO_MULTICHANNEL_H__ */
|
Loading…
Reference in a new issue