audio: add function to build audio format

This commit is contained in:
Wim Taymans 2011-08-19 16:00:33 +02:00
parent b657f5bce7
commit 7db6fa37b4
2 changed files with 52 additions and 6 deletions

View file

@ -101,6 +101,48 @@ static GstAudioFormatInfo formats[] = {
SILENT_0) SILENT_0)
}; };
/**
* gst_audio_format_build_int:
* @sign: signed or unsigned format
* @endianness: G_LITTLE_ENDIAN or G_BIG_ENDIAN
* @width: amount of bits used per sample
* @depth: amount of used bits in @width
*
* Construct a #GstAudioFormat with given parameters.
*
* Returns: a #GstAudioFormat or GST_AUDIO_FORMAT_UNKNOWN when no audio format
* exists with the given parameters.
*/
GstAudioFormat
gst_audio_format_build_int (gboolean sign, gint endianness,
gint width, gint depth)
{
gint i, e;
for (i = 0; i < G_N_ELEMENTS (formats); i++) {
GstAudioFormatInfo *finfo = &formats[i];
/* must be int */
if (!GST_AUDIO_FORMAT_INFO_IS_INT (finfo))
continue;
/* width and depth must match */
if (width != GST_AUDIO_FORMAT_INFO_WIDTH (finfo))
continue;
if (depth != GST_AUDIO_FORMAT_INFO_DEPTH (finfo))
continue;
/* if there is endianness, it must match */
e = GST_AUDIO_FORMAT_INFO_ENDIANNESS (finfo);
if (e && e != endianness)
continue;
/* check sign */
if (sign && !GST_AUDIO_FORMAT_INFO_IS_SIGNED (finfo))
continue;
return GST_AUDIO_FORMAT_INFO_FORMAT (finfo);
}
return GST_AUDIO_FORMAT_UNKNOWN;
}
/** /**
* gst_audio_format_from_string: * gst_audio_format_from_string:
* @format: a format string * @format: a format string

View file

@ -227,13 +227,17 @@ struct _GstAudioFormatInfo {
#define GST_AUDIO_FORMAT_INFO_WIDTH(info) ((info)->width) #define GST_AUDIO_FORMAT_INFO_WIDTH(info) ((info)->width)
#define GST_AUDIO_FORMAT_INFO_DEPTH(info) ((info)->depth) #define GST_AUDIO_FORMAT_INFO_DEPTH(info) ((info)->depth)
GstAudioFormat gst_audio_format_from_string (const gchar *format) G_GNUC_CONST;
const gchar * gst_audio_format_to_string (GstAudioFormat format) G_GNUC_CONST;
const GstAudioFormatInfo *
gst_audio_format_get_info (GstAudioFormat format) G_GNUC_CONST;
void gst_audio_format_fill_silence (const GstAudioFormatInfo *info, GstAudioFormat gst_audio_format_build_int (gboolean sign, gint endianness,
gpointer dest, gsize length); gint width, gint depth) G_GNUC_CONST;
GstAudioFormat gst_audio_format_from_string (const gchar *format) G_GNUC_CONST;
const gchar * gst_audio_format_to_string (GstAudioFormat format) G_GNUC_CONST;
const GstAudioFormatInfo *
gst_audio_format_get_info (GstAudioFormat format) G_GNUC_CONST;
void gst_audio_format_fill_silence (const GstAudioFormatInfo *info,
gpointer dest, gsize length);
/** /**
* GstAudioFlags: * GstAudioFlags:
* @GST_AUDIO_FLAG_NONE: no valid flag * @GST_AUDIO_FLAG_NONE: no valid flag