audio: Add "layout" field to the raw audio caps

This can be used to differentiate between interleaved
and non-interleaved audio and whatever comes in the future.
This commit is contained in:
Sebastian Dröge 2011-12-31 13:46:53 +01:00
parent e2c6b8ec4d
commit 810bfec656
2 changed files with 44 additions and 0 deletions

View file

@ -470,6 +470,7 @@ gst_audio_info_set_format (GstAudioInfo * info, GstAudioFormat format,
finfo = &formats[format]; finfo = &formats[format];
info->flags = 0; info->flags = 0;
info->layout = GST_AUDIO_LAYOUT_INTERLEAVED;
info->finfo = finfo; info->finfo = finfo;
info->rate = rate; info->rate = rate;
info->channels = channels; info->channels = channels;
@ -530,6 +531,15 @@ gst_audio_info_from_caps (GstAudioInfo * info, const GstCaps * caps)
if (format == GST_AUDIO_FORMAT_UNKNOWN) if (format == GST_AUDIO_FORMAT_UNKNOWN)
goto unknown_format; goto unknown_format;
if (!(s = gst_structure_get_string (str, "layout")))
goto no_layout;
if (g_str_equal (s, "interleaved"))
info->layout = GST_AUDIO_LAYOUT_INTERLEAVED;
else if (g_str_equal (s, "non-interleaved"))
info->layout = GST_AUDIO_LAYOUT_NON_INTERLEAVED;
else
goto unknown_layout;
if (!gst_structure_get_int (str, "rate", &rate)) if (!gst_structure_get_int (str, "rate", &rate))
goto no_rate; goto no_rate;
if (!gst_structure_get_int (str, "channels", &channels)) if (!gst_structure_get_int (str, "channels", &channels))
@ -585,6 +595,16 @@ unknown_format:
GST_ERROR ("unknown format given"); GST_ERROR ("unknown format given");
return FALSE; return FALSE;
} }
no_layout:
{
GST_ERROR ("no layout given");
return FALSE;
}
unknown_layout:
{
GST_ERROR ("unknown layout given");
return FALSE;
}
no_rate: no_rate:
{ {
GST_ERROR ("no rate property given"); GST_ERROR ("no rate property given");
@ -622,6 +642,7 @@ gst_audio_info_to_caps (const GstAudioInfo * info)
{ {
GstCaps *caps; GstCaps *caps;
const gchar *format; const gchar *format;
const gchar *layout;
g_return_val_if_fail (info != NULL, NULL); g_return_val_if_fail (info != NULL, NULL);
g_return_val_if_fail (info->finfo != NULL, NULL); g_return_val_if_fail (info->finfo != NULL, NULL);
@ -630,8 +651,16 @@ gst_audio_info_to_caps (const GstAudioInfo * info)
format = gst_audio_format_to_string (info->finfo->format); format = gst_audio_format_to_string (info->finfo->format);
g_return_val_if_fail (format != NULL, NULL); g_return_val_if_fail (format != NULL, NULL);
if (info->layout == GST_AUDIO_LAYOUT_INTERLEAVED)
layout = "interleaved";
else if (info->layout == GST_AUDIO_LAYOUT_NON_INTERLEAVED)
layout = "non-interleaved";
else
g_return_val_if_reached (NULL);
caps = gst_caps_new_simple ("audio/x-raw", caps = gst_caps_new_simple ("audio/x-raw",
"format", G_TYPE_STRING, format, "format", G_TYPE_STRING, format,
"layout", G_TYPE_STRING, layout,
"rate", G_TYPE_INT, info->rate, "rate", G_TYPE_INT, info->rate,
"channels", G_TYPE_INT, info->channels, NULL); "channels", G_TYPE_INT, info->channels, NULL);

View file

@ -367,10 +367,23 @@ typedef enum {
GST_AUDIO_FLAG_UNPOSITIONED = (1 << 0) GST_AUDIO_FLAG_UNPOSITIONED = (1 << 0)
} GstAudioFlags; } GstAudioFlags;
/**
* GstAudioLayout:
* @GST_AUDIO_LAYOUT_INTERLEAVED: interleaved audio
* @GST_AUDIO_LAYOUT_NON_INTERLEAVED: non-interleaved audio
*
* Layout of the audio samples for the different channels.
*/
typedef enum {
GST_AUDIO_LAYOUT_INTERLEAVED = 0,
GST_AUDIO_LAYOUT_NON_INTERLEAVED
} GstAudioLayout;
/** /**
* GstAudioInfo: * GstAudioInfo:
* @finfo: the format info of the audio * @finfo: the format info of the audio
* @flags: additional audio flags * @flags: additional audio flags
* @layout: audio layout
* @rate: the audio sample rate * @rate: the audio sample rate
* @channels: the number of channels * @channels: the number of channels
* @bpf: the number of bytes for one frame, this is the size of one * @bpf: the number of bytes for one frame, this is the size of one
@ -385,6 +398,7 @@ typedef enum {
struct _GstAudioInfo { struct _GstAudioInfo {
const GstAudioFormatInfo *finfo; const GstAudioFormatInfo *finfo;
GstAudioFlags flags; GstAudioFlags flags;
GstAudioLayout layout;
gint rate; gint rate;
gint channels; gint channels;
gint bpf; gint bpf;
@ -414,6 +428,7 @@ GType gst_audio_info_get_type (void);
#define GST_AUDIO_INFO_FLAGS(info) ((info)->flags) #define GST_AUDIO_INFO_FLAGS(info) ((info)->flags)
#define GST_AUDIO_INFO_IS_UNPOSITIONED(info) ((info)->flags & GST_AUDIO_FLAG_UNPOSITIONED) #define GST_AUDIO_INFO_IS_UNPOSITIONED(info) ((info)->flags & GST_AUDIO_FLAG_UNPOSITIONED)
#define GST_AUDIO_INFO_LAYOUT(info) ((info)->layout)
#define GST_AUDIO_INFO_RATE(info) ((info)->rate) #define GST_AUDIO_INFO_RATE(info) ((info)->rate)
#define GST_AUDIO_INFO_CHANNELS(info) ((info)->channels) #define GST_AUDIO_INFO_CHANNELS(info) ((info)->channels)