audio: add GstAudioFormat, GstAudioFormatInfo and GstAudioInfo

Same as in 0.11, but with caps parsing/serialising for 0.10 style
caps. Add setting default channel positions.
This commit is contained in:
Tim-Philipp Müller 2011-08-22 20:15:15 +01:00
parent bf4a28f420
commit 63a3d360dc
4 changed files with 686 additions and 3 deletions

View file

@ -32,6 +32,8 @@
#include <gst/gststructure.h>
#include <string.h>
/**
* gst_audio_frame_byte_size:
* @pad: the #GstPad to get the caps from
@ -268,6 +270,412 @@ gst_audio_structure_set_int (GstStructure * structure, GstAudioFieldFlag flag)
}
#endif /* GST_REMOVE_DEPRECATED */
#define SINT (GST_AUDIO_FORMAT_FLAG_INTEGER | GST_AUDIO_FORMAT_FLAG_SIGNED)
#define UINT (GST_AUDIO_FORMAT_FLAG_INTEGER)
#define MAKE_FORMAT(str,flags,end,width,depth,silent) \
{ GST_AUDIO_FORMAT_ ##str, G_STRINGIFY(str), flags, end, width, depth, silent }
#define SILENT_0 { 0, 0, 0, 0, 0, 0, 0, 0 }
#define SILENT_U8 { 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80 }
#define SILENT_U16_LE { 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80 }
#define SILENT_U16_BE { 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00 }
#define SILENT_U24_LE { 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00 }
#define SILENT_U24_BE { 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00 }
#define SILENT_U32_LE { 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80 }
#define SILENT_U32_BE { 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00 }
#define SILENT_U24_3LE { 0x00, 0x00, 0x80, 0x00, 0x00, 0x80 }
#define SILENT_U24_3BE { 0x80, 0x00, 0x00, 0x80, 0x00, 0x00 }
#define SILENT_U20_3LE { 0x00, 0x00, 0x08, 0x00, 0x00, 0x08 }
#define SILENT_U20_3BE { 0x08, 0x00, 0x00, 0x08, 0x00, 0x00 }
#define SILENT_U18_3LE { 0x00, 0x00, 0x02, 0x00, 0x00, 0x02 }
#define SILENT_U18_3BE { 0x02, 0x00, 0x00, 0x02, 0x00, 0x00 }
static GstAudioFormatInfo formats[] = {
{GST_AUDIO_FORMAT_UNKNOWN, "UNKNOWN", 0, 0, 0, 0},
/* 8 bit */
MAKE_FORMAT (S8, SINT, 0, 8, 8, SILENT_0),
MAKE_FORMAT (U8, UINT, 0, 8, 8, SILENT_U8),
/* 16 bit */
MAKE_FORMAT (S16_LE, SINT, G_LITTLE_ENDIAN, 16, 16, SILENT_0),
MAKE_FORMAT (S16_BE, SINT, G_BIG_ENDIAN, 16, 16, SILENT_0),
MAKE_FORMAT (U16_LE, UINT, G_LITTLE_ENDIAN, 16, 16, SILENT_U16_LE),
MAKE_FORMAT (U16_BE, UINT, G_BIG_ENDIAN, 16, 16, SILENT_U16_BE),
/* 24 bit in low 3 bytes of 32 bits */
MAKE_FORMAT (S24_LE, SINT, G_LITTLE_ENDIAN, 32, 24, SILENT_0),
MAKE_FORMAT (S24_BE, SINT, G_BIG_ENDIAN, 32, 24, SILENT_0),
MAKE_FORMAT (U24_LE, UINT, G_LITTLE_ENDIAN, 32, 24, SILENT_U24_LE),
MAKE_FORMAT (U24_BE, UINT, G_BIG_ENDIAN, 32, 24, SILENT_U24_BE),
/* 32 bit */
MAKE_FORMAT (S32_LE, SINT, G_LITTLE_ENDIAN, 32, 32, SILENT_0),
MAKE_FORMAT (S32_BE, SINT, G_BIG_ENDIAN, 32, 32, SILENT_0),
MAKE_FORMAT (U32_LE, UINT, G_LITTLE_ENDIAN, 32, 32, SILENT_U32_LE),
MAKE_FORMAT (U32_BE, UINT, G_BIG_ENDIAN, 32, 32, SILENT_U32_BE),
/* 24 bit in 3 bytes */
MAKE_FORMAT (S24_3LE, SINT, G_LITTLE_ENDIAN, 24, 24, SILENT_0),
MAKE_FORMAT (S24_3BE, SINT, G_BIG_ENDIAN, 24, 24, SILENT_0),
MAKE_FORMAT (U24_3LE, UINT, G_LITTLE_ENDIAN, 24, 24, SILENT_U24_3LE),
MAKE_FORMAT (U24_3BE, UINT, G_BIG_ENDIAN, 24, 24, SILENT_U24_3BE),
/* 20 bit in 3 bytes */
MAKE_FORMAT (S20_3LE, SINT, G_LITTLE_ENDIAN, 24, 20, SILENT_0),
MAKE_FORMAT (S20_3BE, SINT, G_BIG_ENDIAN, 24, 20, SILENT_0),
MAKE_FORMAT (U20_3LE, UINT, G_LITTLE_ENDIAN, 24, 20, SILENT_U20_3LE),
MAKE_FORMAT (U20_3BE, UINT, G_BIG_ENDIAN, 24, 20, SILENT_U20_3BE),
/* 18 bit in 3 bytes */
MAKE_FORMAT (S18_3LE, SINT, G_LITTLE_ENDIAN, 24, 18, SILENT_0),
MAKE_FORMAT (S18_3BE, SINT, G_BIG_ENDIAN, 24, 18, SILENT_0),
MAKE_FORMAT (U18_3LE, UINT, G_LITTLE_ENDIAN, 24, 18, SILENT_U18_3LE),
MAKE_FORMAT (U18_3BE, UINT, G_BIG_ENDIAN, 24, 18, SILENT_U18_3BE),
/* float */
MAKE_FORMAT (F32_LE, GST_AUDIO_FORMAT_FLAG_FLOAT, G_LITTLE_ENDIAN, 32, 32,
SILENT_0),
MAKE_FORMAT (F32_BE, GST_AUDIO_FORMAT_FLAG_FLOAT, G_BIG_ENDIAN, 32, 32,
SILENT_0),
MAKE_FORMAT (F64_LE, GST_AUDIO_FORMAT_FLAG_FLOAT, G_LITTLE_ENDIAN, 64, 64,
SILENT_0),
MAKE_FORMAT (F64_BE, GST_AUDIO_FORMAT_FLAG_FLOAT, G_BIG_ENDIAN, 64, 64,
SILENT_0)
};
static GstAudioFormat
gst_audio_format_from_caps_structure (const GstStructure * s)
{
gint endianness, width, depth;
guint i;
if (gst_structure_has_name (s, "audio/x-raw-int")) {
gboolean sign;
if (!gst_structure_get_boolean (s, "signed", &sign))
goto missing_field_signed;
if (!gst_structure_get_int (s, "endianness", &endianness))
goto missing_field_endianness;
if (!gst_structure_get_int (s, "width", &width))
goto missing_field_width;
if (!gst_structure_get_int (s, "depth", &depth))
goto missing_field_depth;
for (i = 0; i < G_N_ELEMENTS (formats); i++) {
if (GST_AUDIO_FORMAT_INFO_IS_INTEGER (&formats[i]) &&
sign == GST_AUDIO_FORMAT_INFO_IS_SIGNED (&formats[i]) &&
GST_AUDIO_FORMAT_INFO_ENDIANNESS (&formats[i]) == endianness &&
GST_AUDIO_FORMAT_INFO_WIDTH (&formats[i]) == width &&
GST_AUDIO_FORMAT_INFO_DEPTH (&formats[i]) == depth) {
return GST_AUDIO_FORMAT_INFO_FORMAT (&formats[i]);
}
}
} else if (gst_structure_has_name (s, "audio/x-raw-float")) {
/* fallbacks are for backwards compatibility (is this needed at all?) */
if (!gst_structure_get_int (s, "endianness", &endianness)) {
GST_WARNING ("float audio caps without endianness %" GST_PTR_FORMAT, s);
endianness = G_BYTE_ORDER;
}
if (!gst_structure_get_int (s, "width", &width)) {
GST_WARNING ("float audio caps without width %" GST_PTR_FORMAT, s);
width = 32;
}
for (i = 0; i < G_N_ELEMENTS (formats); i++) {
if (GST_AUDIO_FORMAT_INFO_IS_FLOAT (&formats[i]) &&
GST_AUDIO_FORMAT_INFO_ENDIANNESS (&formats[i]) == endianness &&
GST_AUDIO_FORMAT_INFO_WIDTH (&formats[i]) == width) {
return GST_AUDIO_FORMAT_INFO_FORMAT (&formats[i]);
}
}
}
/* no match */
return GST_AUDIO_FORMAT_UNKNOWN;
missing_field_signed:
{
GST_ERROR ("missing 'signed' field in audio caps %" GST_PTR_FORMAT, s);
return GST_AUDIO_FORMAT_UNKNOWN;
}
missing_field_endianness:
{
GST_ERROR ("missing 'endianness' field in audio caps %" GST_PTR_FORMAT, s);
return GST_AUDIO_FORMAT_UNKNOWN;
}
missing_field_depth:
{
GST_ERROR ("missing 'depth' field in audio caps %" GST_PTR_FORMAT, s);
return GST_AUDIO_FORMAT_UNKNOWN;
}
missing_field_width:
{
GST_ERROR ("missing 'width' field in audio caps %" GST_PTR_FORMAT, s);
return GST_AUDIO_FORMAT_UNKNOWN;
}
}
static void
gst_audio_info_set_format (GstAudioInfo * info, GstAudioFormat format,
gint rate, gint channels)
{
const GstAudioFormatInfo *finfo;
g_return_if_fail (info != NULL);
g_return_if_fail (format != GST_AUDIO_FORMAT_UNKNOWN);
finfo = &formats[format];
info->flags = 0;
info->finfo = finfo;
info->rate = rate;
info->channels = channels;
info->bpf = (finfo->width * channels) / 8;
}
/* from multichannel.c */
void priv_gst_audio_info_fill_default_channel_positions (GstAudioInfo * info);
/**
* gst_audio_info_from_caps:
* @info: a #GstAudioInfo
* @caps: a #GstCaps
*
* Parse @caps and update @info.
*
* Returns: TRUE if @caps could be parsed
*
* Since: 0.10.36
*/
gboolean
gst_audio_info_from_caps (GstAudioInfo * info, const GstCaps * caps)
{
GstStructure *str;
GstAudioFormat format;
gint rate, channels;
const GValue *pos_val_arr, *pos_val_entry;
gint i;
g_return_val_if_fail (info != NULL, FALSE);
g_return_val_if_fail (caps != NULL, FALSE);
g_return_val_if_fail (gst_caps_is_fixed (caps), FALSE);
GST_DEBUG ("parsing caps %" GST_PTR_FORMAT, caps);
str = gst_caps_get_structure (caps, 0);
format = gst_audio_format_from_caps_structure (str);
if (format == GST_AUDIO_FORMAT_UNKNOWN)
goto unknown_format;
if (!gst_structure_get_int (str, "rate", &rate))
goto no_rate;
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) {
if (channels <= G_N_ELEMENTS (info->position)) {
for (i = 0; i < channels; i++) {
pos_val_entry = gst_value_array_get_value (pos_val_arr, i);
info->position[i] = g_value_get_enum (pos_val_entry);
}
} else {
/* for that 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;
}
} else {
info->flags |= GST_AUDIO_FLAG_DEFAULT_POSITIONS;
priv_gst_audio_info_fill_default_channel_positions (info);
}
return TRUE;
/* ERROR */
unknown_format:
{
GST_ERROR ("unknown format given");
return FALSE;
}
no_rate:
{
GST_ERROR ("no rate property given");
return FALSE;
}
no_channels:
{
GST_ERROR ("no channels property given");
return FALSE;
}
}
/**
* gst_audio_info_to_caps:
* @info: a #GstAudioInfo
*
* Convert the values of @info into a #GstCaps.
*
* Returns: (transfer full): the new #GstCaps containing the
* info of @info.
*
* Since: 0.10.36
*/
GstCaps *
gst_audio_info_to_caps (GstAudioInfo * info)
{
GstCaps *caps;
g_return_val_if_fail (info != NULL, NULL);
g_return_val_if_fail (info->finfo != NULL, NULL);
g_return_val_if_fail (info->finfo->format != GST_AUDIO_FORMAT_UNKNOWN, NULL);
if (GST_AUDIO_FORMAT_INFO_IS_INTEGER (info->finfo)) {
caps = gst_caps_new_simple ("audio/x-raw-int",
"width", G_TYPE_INT, GST_AUDIO_INFO_WIDTH (info),
"depth", G_TYPE_INT, GST_AUDIO_INFO_DEPTH (info),
"endianness", G_TYPE_INT,
GST_AUDIO_FORMAT_INFO_ENDIANNESS (info->finfo), "signed",
G_TYPE_BOOLEAN, GST_AUDIO_FORMAT_INFO_IS_SIGNED (info->finfo), "rate",
G_TYPE_INT, GST_AUDIO_INFO_RATE (info), "channels", G_TYPE_INT,
GST_AUDIO_INFO_CHANNELS (info), NULL);
} else if (GST_AUDIO_FORMAT_INFO_IS_FLOAT (info->finfo)) {
caps = gst_caps_new_simple ("audio/x-raw-float",
"width", G_TYPE_INT, GST_AUDIO_INFO_WIDTH (info),
"endianness", G_TYPE_INT,
GST_AUDIO_FORMAT_INFO_ENDIANNESS (info->finfo), "rate", G_TYPE_INT,
GST_AUDIO_INFO_RATE (info), "channels", G_TYPE_INT,
GST_AUDIO_INFO_CHANNELS (info), NULL);
} else {
GST_ERROR ("unknown audio format, neither integer nor float");
return NULL;
}
if (info->channels > 2) {
GValue pos_val_arr = { 0 }
, pos_val_entry = {
0};
GstStructure *str;
gint i;
/* build gvaluearray from positions */
g_value_init (&pos_val_arr, GST_TYPE_ARRAY);
g_value_init (&pos_val_entry, GST_TYPE_AUDIO_CHANNEL_POSITION);
for (i = 0; i < info->channels; i++) {
/* if we have many many channels, all positions are NONE */
if (info->channels <= 64)
g_value_set_enum (&pos_val_entry, info->position[i]);
else
g_value_set_enum (&pos_val_entry, GST_AUDIO_CHANNEL_POSITION_NONE);
gst_value_array_append_value (&pos_val_arr, &pos_val_entry);
}
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;
}
/**
* gst_audio_format_convert:
* @info: a #GstAudioInfo
* @src_format: #GstFormat of the @src_value
* @src_value: value to convert
* @dest_format: #GstFormat of the @dest_value
* @dest_value: pointer to destination value
*
* Converts among various #GstFormat types. This function handles
* GST_FORMAT_BYTES, GST_FORMAT_TIME, and GST_FORMAT_DEFAULT. For
* raw audio, GST_FORMAT_DEFAULT corresponds to audio frames. This
* function can be used to handle pad queries of the type GST_QUERY_CONVERT.
*
* Returns: TRUE if the conversion was successful.
*
* Since: 0.10.36
*/
gboolean
gst_audio_info_convert (GstAudioInfo * info,
GstFormat src_fmt, gint64 src_val, GstFormat dest_fmt, gint64 * dest_val)
{
gboolean res = TRUE;
gint bpf, rate;
GST_DEBUG ("converting value %" G_GINT64_FORMAT " from %s (%d) to %s (%d)",
src_val, gst_format_get_name (src_fmt), src_fmt,
gst_format_get_name (dest_fmt), dest_fmt);
if (src_fmt == dest_fmt || src_val == -1) {
*dest_val = src_val;
goto done;
}
/* get important info */
bpf = GST_AUDIO_INFO_BPF (info);
rate = GST_AUDIO_INFO_RATE (info);
if (bpf == 0 || rate == 0) {
GST_DEBUG ("no rate or bpf configured");
res = FALSE;
goto done;
}
switch (src_fmt) {
case GST_FORMAT_BYTES:
switch (dest_fmt) {
case GST_FORMAT_TIME:
*dest_val = GST_FRAMES_TO_CLOCK_TIME (src_val / bpf, rate);
break;
case GST_FORMAT_DEFAULT:
*dest_val = src_val / bpf;
break;
default:
res = FALSE;
break;
}
break;
case GST_FORMAT_DEFAULT:
switch (dest_fmt) {
case GST_FORMAT_TIME:
*dest_val = GST_FRAMES_TO_CLOCK_TIME (src_val, rate);
break;
case GST_FORMAT_BYTES:
*dest_val = src_val * bpf;
break;
default:
res = FALSE;
break;
}
break;
case GST_FORMAT_TIME:
switch (dest_fmt) {
case GST_FORMAT_DEFAULT:
*dest_val = GST_CLOCK_TIME_TO_FRAMES (src_val, rate);
break;
case GST_FORMAT_BYTES:
*dest_val = GST_CLOCK_TIME_TO_FRAMES (src_val, rate);
*dest_val *= bpf;
break;
default:
res = FALSE;
break;
}
break;
default:
res = FALSE;
break;
}
done:
GST_DEBUG ("ret=%d result %" G_GINT64_FORMAT, res, *dest_val);
return res;
}
/**
* gst_audio_buffer_clip:
* @buffer: The buffer to clip.

View file

@ -23,8 +23,257 @@
#ifndef __GST_AUDIO_AUDIO_H__
#define __GST_AUDIO_AUDIO_H__
#include <gst/audio/multichannel.h>
G_BEGIN_DECLS
/**
* GstAudioFormat:
* @GST_AUDIO_FORMAT_UNKNOWN: unknown audio format
* @GST_AUDIO_FORMAT_S8: sample
* @GST_AUDIO_FORMAT_U8: sample
* @GST_AUDIO_FORMAT_S16_LE: sample
* @GST_AUDIO_FORMAT_S16_BE: sample
* @GST_AUDIO_FORMAT_U16_LE: sample
* @GST_AUDIO_FORMAT_U16_BE: sample
* @GST_AUDIO_FORMAT_S24_LE: sample
* @GST_AUDIO_FORMAT_S24_BE: sample
* @GST_AUDIO_FORMAT_U24_LE: sample
* @GST_AUDIO_FORMAT_U24_BE: sample
* @GST_AUDIO_FORMAT_S32_LE: sample
* @GST_AUDIO_FORMAT_S32_BE: sample
* @GST_AUDIO_FORMAT_U32_LE: sample
* @GST_AUDIO_FORMAT_U32_BE: sample
* @GST_AUDIO_FORMAT_S24_3LE: sample
* @GST_AUDIO_FORMAT_S24_3BE: sample
* @GST_AUDIO_FORMAT_U24_3LE: sample
* @GST_AUDIO_FORMAT_U24_3BE: sample
* @GST_AUDIO_FORMAT_S20_3LE: sample
* @GST_AUDIO_FORMAT_S20_3BE: sample
* @GST_AUDIO_FORMAT_U20_3LE: sample
* @GST_AUDIO_FORMAT_U20_3BE: sample
* @GST_AUDIO_FORMAT_S18_3LE: sample
* @GST_AUDIO_FORMAT_S18_3BE: sample
* @GST_AUDIO_FORMAT_U18_3LE: sample
* @GST_AUDIO_FORMAT_U18_3BE: sample
* @GST_AUDIO_FORMAT_F32_LE: sample
* @GST_AUDIO_FORMAT_F32_BE: sample
* @GST_AUDIO_FORMAT_F64_LE: sample
* @GST_AUDIO_FORMAT_F64_BE: sample
*
* Enum value describing the most common audio formats.
*
* Since: 0.10.36
*/
typedef enum {
GST_AUDIO_FORMAT_UNKNOWN,
/* 8 bit */
GST_AUDIO_FORMAT_S8,
GST_AUDIO_FORMAT_U8,
/* 16 bit */
GST_AUDIO_FORMAT_S16_LE,
GST_AUDIO_FORMAT_S16_BE,
GST_AUDIO_FORMAT_U16_LE,
GST_AUDIO_FORMAT_U16_BE,
/* 24 bit in low 3 bytes of 32 bits*/
GST_AUDIO_FORMAT_S24_LE,
GST_AUDIO_FORMAT_S24_BE,
GST_AUDIO_FORMAT_U24_LE,
GST_AUDIO_FORMAT_U24_BE,
/* 32 bit */
GST_AUDIO_FORMAT_S32_LE,
GST_AUDIO_FORMAT_S32_BE,
GST_AUDIO_FORMAT_U32_LE,
GST_AUDIO_FORMAT_U32_BE,
/* 24 bit in 3 bytes*/
GST_AUDIO_FORMAT_S24_3LE,
GST_AUDIO_FORMAT_S24_3BE,
GST_AUDIO_FORMAT_U24_3LE,
GST_AUDIO_FORMAT_U24_3BE,
/* 20 bit in 3 bytes*/
GST_AUDIO_FORMAT_S20_3LE,
GST_AUDIO_FORMAT_S20_3BE,
GST_AUDIO_FORMAT_U20_3LE,
GST_AUDIO_FORMAT_U20_3BE,
/* 18 bit in 3 bytes*/
GST_AUDIO_FORMAT_S18_3LE,
GST_AUDIO_FORMAT_S18_3BE,
GST_AUDIO_FORMAT_U18_3LE,
GST_AUDIO_FORMAT_U18_3BE,
/* float */
GST_AUDIO_FORMAT_F32_LE,
GST_AUDIO_FORMAT_F32_BE,
GST_AUDIO_FORMAT_F64_LE,
GST_AUDIO_FORMAT_F64_BE,
#if G_BYTE_ORDER == G_BIG_ENDIAN
GST_AUDIO_FORMAT_S16 = GST_AUDIO_FORMAT_S16_BE,
GST_AUDIO_FORMAT_U16 = GST_AUDIO_FORMAT_U16_BE,
GST_AUDIO_FORMAT_S24 = GST_AUDIO_FORMAT_S24_BE,
GST_AUDIO_FORMAT_U24 = GST_AUDIO_FORMAT_U24_BE,
GST_AUDIO_FORMAT_S32 = GST_AUDIO_FORMAT_S32_BE,
GST_AUDIO_FORMAT_U32 = GST_AUDIO_FORMAT_U32_BE,
GST_AUDIO_FORMAT_S24_3 = GST_AUDIO_FORMAT_S24_3BE,
GST_AUDIO_FORMAT_U24_3 = GST_AUDIO_FORMAT_U24_3BE,
GST_AUDIO_FORMAT_S20_3 = GST_AUDIO_FORMAT_S20_3BE,
GST_AUDIO_FORMAT_U20_3 = GST_AUDIO_FORMAT_U20_3BE,
GST_AUDIO_FORMAT_S18_3 = GST_AUDIO_FORMAT_S18_3BE,
GST_AUDIO_FORMAT_U18_3 = GST_AUDIO_FORMAT_U18_3BE,
GST_AUDIO_FORMAT_F32 = GST_AUDIO_FORMAT_F32_BE,
GST_AUDIO_FORMAT_F64 = GST_AUDIO_FORMAT_F64_BE
#elif G_BYTE_ORDER == G_LITTLE_ENDIAN
GST_AUDIO_FORMAT_S16 = GST_AUDIO_FORMAT_S16_LE,
GST_AUDIO_FORMAT_U16 = GST_AUDIO_FORMAT_U16_LE,
GST_AUDIO_FORMAT_S24 = GST_AUDIO_FORMAT_S24_LE,
GST_AUDIO_FORMAT_U24 = GST_AUDIO_FORMAT_U24_LE,
GST_AUDIO_FORMAT_S32 = GST_AUDIO_FORMAT_S32_LE,
GST_AUDIO_FORMAT_U32 = GST_AUDIO_FORMAT_U32_LE,
GST_AUDIO_FORMAT_S24_3 = GST_AUDIO_FORMAT_S24_3LE,
GST_AUDIO_FORMAT_U24_3 = GST_AUDIO_FORMAT_U24_3LE,
GST_AUDIO_FORMAT_S20_3 = GST_AUDIO_FORMAT_S20_3LE,
GST_AUDIO_FORMAT_U20_3 = GST_AUDIO_FORMAT_U20_3LE,
GST_AUDIO_FORMAT_S18_3 = GST_AUDIO_FORMAT_S18_3LE,
GST_AUDIO_FORMAT_U18_3 = GST_AUDIO_FORMAT_U18_3LE,
GST_AUDIO_FORMAT_F32 = GST_AUDIO_FORMAT_F32_LE,
GST_AUDIO_FORMAT_F64 = GST_AUDIO_FORMAT_F64_LE
#endif
} GstAudioFormat;
/* FIXME: need GTypes */
typedef struct _GstAudioFormatInfo GstAudioFormatInfo;
typedef struct _GstAudioInfo GstAudioInfo;
/**
* GstAudioFormatFlags:
* @GST_AUDIO_FORMAT_FLAG_INTEGER: integer samples
* @GST_AUDIO_FORMAT_FLAG_FLOAT: float samples
* @GST_AUDIO_FORMAT_FLAG_SIGNED: signed samples
* @GST_AUDIO_FORMAT_FLAG_COMPLEX: complex layout
*
* The different audio flags that a format info can have.
*
* Since: 0.10.36
*/
typedef enum
{
GST_AUDIO_FORMAT_FLAG_INTEGER = (1 << 0),
GST_AUDIO_FORMAT_FLAG_FLOAT = (1 << 1),
GST_AUDIO_FORMAT_FLAG_SIGNED = (1 << 2),
GST_AUDIO_FORMAT_FLAG_COMPLEX = (1 << 4)
} GstAudioFormatFlags;
/**
* GstAudioFormatInfo:
* @format: #GstAudioFormat
* @name: string representation of the format
* @flags: #GstAudioFormatFlags
* @endianness: the endianness
* @width: amount of bits used for one sample
* @depth: amount of valid bits in @width
* @silence: @width/8 bytes with 1 silent sample
*
* Information for an audio format.
*
* Since: 0.10.36
*/
struct _GstAudioFormatInfo {
GstAudioFormat format;
const gchar * name;
GstAudioFormatFlags flags;
gint endianness;
gint width;
gint depth;
guint8 silence[8];
/*< private >*/
guint padding_i[4];
gpointer padding_p[4];
};
#define GST_AUDIO_FORMAT_INFO_FORMAT(info) ((info)->format)
#define GST_AUDIO_FORMAT_INFO_NAME(info) ((info)->name)
#define GST_AUDIO_FORMAT_INFO_FLAGS(info) ((info)->flags)
// FIXME: fix IS macros (make boolean)
#define GST_AUDIO_FORMAT_INFO_IS_INTEGER(info) ((info)->flags & GST_AUDIO_FORMAT_FLAG_INTEGER)
#define GST_AUDIO_FORMAT_INFO_IS_FLOAT(info) ((info)->flags & GST_AUDIO_FORMAT_FLAG_FLOAT)
#define GST_AUDIO_FORMAT_INFO_IS_SIGNED(info) ((info)->flags & GST_AUDIO_FORMAT_FLAG_SIGNED)
#define GST_AUDIO_FORMAT_INFO_ENDIANNESS(info) ((info)->endianness)
#define GST_AUDIO_FORMAT_INFO_IS_LE(info) ((info)->endianness == G_LITTLE_ENDIAN)
#define GST_AUDIO_FORMAT_INFO_IS_BE(info) ((info)->endianness == G_BIG_ENDIAN)
#define GST_AUDIO_FORMAT_INFO_WIDTH(info) ((info)->width)
#define GST_AUDIO_FORMAT_INFO_DEPTH(info) ((info)->depth)
const GstAudioFormatInfo * gst_audio_format_get_info (GstAudioFormat format) G_GNUC_CONST;
/**
* GstAudioFlags:
* @GST_AUDIO_FLAG_NONE: no valid flag
* @GST_AUDIO_FLAG_DEFAULT_POSITIONS: unpositioned audio layout, position array
* contains the default layout (meaning that the channel layout was not
* explicitly specified in the caps)
*
* Extra audio flags
*
* Since: 0.10.36
*/
typedef enum {
GST_AUDIO_FLAG_NONE = 0,
GST_AUDIO_FLAG_DEFAULT_POSITIONS = (1 << 0)
} GstAudioFlags;
/**
* GstAudioInfo:
* @finfo: the format info of the audio
* @flags: additional audio flags
* @rate: the audio sample rate
* @channels: the number of channels
* @bpf: the number of bytes for one frame, this is the size of one
* sample * @channels
* @positions: the positions for each channel
*
* Information describing audio properties. This information can be filled
* in from GstCaps with gst_audio_info_from_caps().
*
* Use the provided macros to access the info in this structure.
*
* Since: 0.10.36
*/
struct _GstAudioInfo {
const GstAudioFormatInfo *finfo;
GstAudioFlags flags;
gint rate;
gint channels;
gint bpf;
GstAudioChannelPosition position[64];
};
#define GST_AUDIO_INFO_FORMAT(i) (GST_AUDIO_FORMAT_INFO_FORMAT((i)->finfo))
#define GST_AUDIO_INFO_NAME(i) (GST_AUDIO_FORMAT_INFO_NAME((i)->finfo))
#define GST_AUDIO_INFO_WIDTH(i) (GST_AUDIO_FORMAT_INFO_WIDTH((i)->finfo))
#define GST_AUDIO_INFO_DEPTH(i) (GST_AUDIO_FORMAT_INFO_DEPTH((i)->finfo))
#define GST_AUDIO_INFO_BPS(info) (GST_AUDIO_INFO_DEPTH(info) >> 3)
#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_RATE(info) ((info)->rate)
#define GST_AUDIO_INFO_CHANNELS(info) ((info)->channels)
#define GST_AUDIO_INFO_BPF(info) ((info)->bpf)
#define GST_AUDIO_INFO_POSITION(info,c) ((info)->position[c])
#if 0
void gst_audio_info_init (GstAudioInfo *info);
void gst_audio_info_set_format (GstAudioInfo *info, GstAudioFormat format,
gint rate, gint channels);
#endif
/* FIXME: need alloc/free for GstAudioInfo */
gboolean gst_audio_info_from_caps (GstAudioInfo *info, const GstCaps *caps);
GstCaps * gst_audio_info_to_caps (GstAudioInfo *info);
gboolean gst_audio_info_convert (GstAudioInfo * info,
GstFormat src_fmt, gint64 src_val,
GstFormat dest_fmt, gint64 * dest_val);
/* For people that are looking at this source: the purpose of these defines is
* to make GstCaps a bit easier, in that you don't have to know all of the
* properties that need to be defined. you can just use these macros. currently

View file

@ -292,6 +292,32 @@ gst_audio_get_channel_positions (GstStructure * str)
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.

View file

@ -17,12 +17,12 @@
* Boston, MA 02111-1307, USA.
*/
#ifndef __GST_AUDIO_MULTICHANNEL_H__
#define __GST_AUDIO_MULTICHANNEL_H__
#include <gst/audio/audio.h>
#include <gst/audio/audio-enumtypes.h>
#ifndef __GST_AUDIO_MULTICHANNEL_H__
#define __GST_AUDIO_MULTICHANNEL_H__
G_BEGIN_DECLS
/**