mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-30 21:51:09 +00:00
audio-channels: make method to get default channel-mask
Add a new method to get the default channel-mask. Use the new method on audiodecoder and audioconvert. API: gst_audio_channel_get_default_mask()
This commit is contained in:
parent
4a85438e5b
commit
f86ed8cdf6
5 changed files with 59 additions and 141 deletions
|
@ -459,3 +459,56 @@ gst_audio_channel_positions_to_valid_order (GstAudioChannelPosition * position,
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define _P(pos) (G_GUINT64_CONSTANT (1) << GST_AUDIO_CHANNEL_POSITION_ ##pos)
|
||||||
|
|
||||||
|
static const guint64 default_masks[] = {
|
||||||
|
/* 1 channel */
|
||||||
|
0,
|
||||||
|
/* 2 channels */
|
||||||
|
_P (FRONT_LEFT) | _P (FRONT_RIGHT),
|
||||||
|
/* 3 channels (2.1) */
|
||||||
|
_P (FRONT_LEFT) | _P (FRONT_RIGHT) | _P (LFE1),
|
||||||
|
/* 4 channels (4.0) */
|
||||||
|
_P (FRONT_LEFT) | _P (FRONT_RIGHT) | _P (REAR_LEFT) | _P (REAR_RIGHT),
|
||||||
|
/* 5 channels */
|
||||||
|
_P (FRONT_LEFT) | _P (FRONT_RIGHT) | _P (REAR_LEFT) | _P (REAR_RIGHT)
|
||||||
|
| _P (FRONT_CENTER),
|
||||||
|
/* 6 channels (5.1) */
|
||||||
|
_P (FRONT_LEFT) |
|
||||||
|
_P (FRONT_RIGHT) |
|
||||||
|
_P (REAR_LEFT) | _P (REAR_RIGHT) | _P (FRONT_CENTER) | _P (LFE1),
|
||||||
|
/* 7 channels (6.1) */
|
||||||
|
_P (FRONT_LEFT) |
|
||||||
|
_P (FRONT_RIGHT) |
|
||||||
|
_P (REAR_LEFT) |
|
||||||
|
_P (REAR_RIGHT) | _P (FRONT_CENTER) | _P (LFE1) | _P (REAR_CENTER),
|
||||||
|
/* 8 channels (7.1) */
|
||||||
|
_P (FRONT_LEFT) |
|
||||||
|
_P (FRONT_RIGHT) |
|
||||||
|
_P (REAR_LEFT) |
|
||||||
|
_P (REAR_RIGHT) |
|
||||||
|
_P (FRONT_CENTER) | _P (LFE1) | _P (SIDE_LEFT) | _P (SIDE_RIGHT),
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gst_audio_channel_get_default_mask:
|
||||||
|
* @channels: the number of channels
|
||||||
|
*
|
||||||
|
* Get the default channel-mask for the given number of channels.
|
||||||
|
*
|
||||||
|
* Returns: the default channel-mask for @channels or 0 when there is no default
|
||||||
|
* mask.
|
||||||
|
*
|
||||||
|
* Since: 1.8
|
||||||
|
*/
|
||||||
|
guint64
|
||||||
|
gst_audio_channel_get_default_mask (gint channels)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (channels > 0, 0);
|
||||||
|
|
||||||
|
if (channels > 8)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return default_masks[channels - 1];
|
||||||
|
}
|
||||||
|
|
|
@ -160,6 +160,7 @@ gboolean gst_audio_get_channel_reorder_map (gint channels,
|
||||||
const GstAudioChannelPosition * from,
|
const GstAudioChannelPosition * from,
|
||||||
const GstAudioChannelPosition * to,
|
const GstAudioChannelPosition * to,
|
||||||
gint *reorder_map);
|
gint *reorder_map);
|
||||||
|
guint64 gst_audio_channel_get_default_mask (gint channels);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
|
|
|
@ -290,70 +290,6 @@ struct _GstAudioDecoderPrivate
|
||||||
gboolean use_default_pad_acceptcaps;
|
gboolean use_default_pad_acceptcaps;
|
||||||
};
|
};
|
||||||
|
|
||||||
//* Default channel layouts taken from audioconvert */
|
|
||||||
static const GstAudioChannelPosition default_positions[8][8] = {
|
|
||||||
/* 1 channel */
|
|
||||||
{
|
|
||||||
GST_AUDIO_CHANNEL_POSITION_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_LFE1,
|
|
||||||
},
|
|
||||||
/* 4 channels (4.0) */
|
|
||||||
{
|
|
||||||
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 (5.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,
|
|
||||||
GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
|
|
||||||
GST_AUDIO_CHANNEL_POSITION_LFE1,
|
|
||||||
},
|
|
||||||
/* 7 channels (6.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,
|
|
||||||
GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
|
|
||||||
GST_AUDIO_CHANNEL_POSITION_LFE1,
|
|
||||||
GST_AUDIO_CHANNEL_POSITION_REAR_CENTER,
|
|
||||||
},
|
|
||||||
/* 8 channels (7.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,
|
|
||||||
GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
|
|
||||||
GST_AUDIO_CHANNEL_POSITION_LFE1,
|
|
||||||
GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT,
|
|
||||||
GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT,
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
static void gst_audio_decoder_finalize (GObject * object);
|
static void gst_audio_decoder_finalize (GObject * object);
|
||||||
static void gst_audio_decoder_set_property (GObject * object,
|
static void gst_audio_decoder_set_property (GObject * object,
|
||||||
guint prop_id, const GValue * value, GParamSpec * pspec);
|
guint prop_id, const GValue * value, GParamSpec * pspec);
|
||||||
|
@ -2069,12 +2005,8 @@ gst_audio_decoder_negotiate_default_caps (GstAudioDecoder * dec)
|
||||||
/* Need to add a channel-mask if channels > 2 */
|
/* Need to add a channel-mask if channels > 2 */
|
||||||
gst_structure_get_int (structure, "channels", &channels);
|
gst_structure_get_int (structure, "channels", &channels);
|
||||||
if (channels > 2 && !gst_structure_has_field (structure, "channel-mask")) {
|
if (channels > 2 && !gst_structure_has_field (structure, "channel-mask")) {
|
||||||
if (channels <= 8) {
|
channel_mask = gst_audio_channel_get_default_mask (channels);
|
||||||
channel_mask = 0;
|
if (channel_mask != 0) {
|
||||||
for (i = 0; i < channels; i++)
|
|
||||||
channel_mask |=
|
|
||||||
G_GUINT64_CONSTANT (1) << default_positions[channels - 1][i];
|
|
||||||
|
|
||||||
gst_structure_set (structure, "channel-mask",
|
gst_structure_set (structure, "channel-mask",
|
||||||
GST_TYPE_BITMASK, channel_mask, NULL);
|
GST_TYPE_BITMASK, channel_mask, NULL);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -346,69 +346,6 @@ gst_audio_convert_transform_caps (GstBaseTransform * btrans,
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const GstAudioChannelPosition default_positions[8][8] = {
|
|
||||||
/* 1 channel */
|
|
||||||
{
|
|
||||||
GST_AUDIO_CHANNEL_POSITION_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_LFE1,
|
|
||||||
},
|
|
||||||
/* 4 channels (4.0) */
|
|
||||||
{
|
|
||||||
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 (5.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,
|
|
||||||
GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
|
|
||||||
GST_AUDIO_CHANNEL_POSITION_LFE1,
|
|
||||||
},
|
|
||||||
/* 7 channels (6.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,
|
|
||||||
GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
|
|
||||||
GST_AUDIO_CHANNEL_POSITION_LFE1,
|
|
||||||
GST_AUDIO_CHANNEL_POSITION_REAR_CENTER,
|
|
||||||
},
|
|
||||||
/* 8 channels (7.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,
|
|
||||||
GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
|
|
||||||
GST_AUDIO_CHANNEL_POSITION_LFE1,
|
|
||||||
GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT,
|
|
||||||
GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT,
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
static gint
|
static gint
|
||||||
n_bits_set (guint64 x)
|
n_bits_set (guint64 x)
|
||||||
{
|
{
|
||||||
|
@ -683,15 +620,9 @@ gst_audio_convert_fixate_channels (GstBaseTransform * base, GstStructure * ins,
|
||||||
* and try to add/remove channels from the input layout, or pick a default
|
* and try to add/remove channels from the input layout, or pick a default
|
||||||
* layout based on LFE-presence in input layout, but let's save that for
|
* layout based on LFE-presence in input layout, but let's save that for
|
||||||
* another day) */
|
* another day) */
|
||||||
if (out_chans > 0 && out_chans <= G_N_ELEMENTS (default_positions[0])) {
|
if (out_chans > 0
|
||||||
gint i;
|
&& (out_mask = gst_audio_channel_get_default_mask (out_chans))) {
|
||||||
|
|
||||||
GST_DEBUG_OBJECT (base, "using default channel layout as fallback");
|
GST_DEBUG_OBJECT (base, "using default channel layout as fallback");
|
||||||
|
|
||||||
out_mask = 0;
|
|
||||||
for (i = 0; i < out_chans; i++)
|
|
||||||
out_mask |= G_GUINT64_CONSTANT (1) << default_positions[out_chans - 1][i];
|
|
||||||
|
|
||||||
gst_structure_set (outs, "channel-mask", GST_TYPE_BITMASK, out_mask, NULL);
|
gst_structure_set (outs, "channel-mask", GST_TYPE_BITMASK, out_mask, NULL);
|
||||||
} else {
|
} else {
|
||||||
GST_ERROR_OBJECT (base, "Have no default layout for %d channels",
|
GST_ERROR_OBJECT (base, "Have no default layout for %d channels",
|
||||||
|
|
|
@ -27,6 +27,7 @@ EXPORTS
|
||||||
gst_audio_cd_src_add_track
|
gst_audio_cd_src_add_track
|
||||||
gst_audio_cd_src_get_type
|
gst_audio_cd_src_get_type
|
||||||
gst_audio_cd_src_mode_get_type
|
gst_audio_cd_src_mode_get_type
|
||||||
|
gst_audio_channel_get_default_mask
|
||||||
gst_audio_channel_position_get_type
|
gst_audio_channel_position_get_type
|
||||||
gst_audio_channel_positions_from_mask
|
gst_audio_channel_positions_from_mask
|
||||||
gst_audio_channel_positions_to_mask
|
gst_audio_channel_positions_to_mask
|
||||||
|
|
Loading…
Reference in a new issue