audio: rename INT -> INTEGER

Spell INTEGER fully instead of using the int abreviation.
Remove some old functions.
This commit is contained in:
Wim Taymans 2011-08-20 10:49:17 +02:00
parent 8023f49d19
commit 0213407fbc
6 changed files with 50 additions and 195 deletions

View file

@ -34,8 +34,8 @@
#include <gst/gststructure.h> #include <gst/gststructure.h>
#define SINT (GST_AUDIO_FORMAT_FLAG_INT | GST_AUDIO_FORMAT_FLAG_SIGNED) #define SINT (GST_AUDIO_FORMAT_FLAG_INTEGER | GST_AUDIO_FORMAT_FLAG_SIGNED)
#define UINT (GST_AUDIO_FORMAT_FLAG_INT) #define UINT (GST_AUDIO_FORMAT_FLAG_INTEGER)
#define MAKE_FORMAT(str,flags,end,width,depth,silent) \ #define MAKE_FORMAT(str,flags,end,width,depth,silent) \
{ GST_AUDIO_FORMAT_ ##str, G_STRINGIFY(str), flags, end, width, depth, silent } { GST_AUDIO_FORMAT_ ##str, G_STRINGIFY(str), flags, end, width, depth, silent }
@ -114,7 +114,7 @@ static GstAudioFormatInfo formats[] = {
* exists with the given parameters. * exists with the given parameters.
*/ */
GstAudioFormat GstAudioFormat
gst_audio_format_build_int (gboolean sign, gint endianness, gst_audio_format_build_integer (gboolean sign, gint endianness,
gint width, gint depth) gint width, gint depth)
{ {
gint i, e; gint i, e;
@ -123,7 +123,7 @@ gst_audio_format_build_int (gboolean sign, gint endianness,
GstAudioFormatInfo *finfo = &formats[i]; GstAudioFormatInfo *finfo = &formats[i];
/* must be int */ /* must be int */
if (!GST_AUDIO_FORMAT_INFO_IS_INT (finfo)) if (!GST_AUDIO_FORMAT_INFO_IS_INTEGER (finfo))
continue; continue;
/* width and depth must match */ /* width and depth must match */
if (width != GST_AUDIO_FORMAT_INFO_WIDTH (finfo)) if (width != GST_AUDIO_FORMAT_INFO_WIDTH (finfo))
@ -196,7 +196,7 @@ gst_audio_format_get_info (GstAudioFormat format)
* gst_audio_format_fill_silence: * gst_audio_format_fill_silence:
* @info: a #GstAudioFormatInfo * @info: a #GstAudioFormatInfo
* @dest: a destination to fill * @dest: a destination to fill
* @lenfth: the length to fill * @length: the length to fill
* *
* Fill @length bytes in @dest with silence samples for @info. * Fill @length bytes in @dest with silence samples for @info.
*/ */
@ -363,7 +363,8 @@ no_channels:
* *
* Convert the values of @info into a #GstCaps. * Convert the values of @info into a #GstCaps.
* *
* Returns: a new #GstCaps containing the info of @info. * Returns: (transfer full): the new #GstCaps containing the
* info of @info.
*/ */
GstCaps * GstCaps *
gst_audio_info_to_caps (GstAudioInfo * info) gst_audio_info_to_caps (GstAudioInfo * info)
@ -409,170 +410,31 @@ gst_audio_info_to_caps (GstAudioInfo * info)
return caps; return caps;
} }
/**
* gst_audio_frame_byte_size:
* @pad: the #GstPad to get the caps from
*
* Calculate byte size of an audio frame.
*
* Returns: the byte size, or 0 if there was an error
*/
int
gst_audio_frame_byte_size (GstPad * pad)
{
/* FIXME: this should be moved closer to the gstreamer core
* and be implemented for every mime type IMO
*/
int width = 0;
int channels = 0;
GstCaps *caps;
GstStructure *structure;
/* get caps of pad */
caps = gst_pad_get_current_caps (pad);
if (caps == NULL)
goto no_caps;
structure = gst_caps_get_structure (caps, 0);
gst_structure_get_int (structure, "width", &width);
gst_structure_get_int (structure, "channels", &channels);
gst_caps_unref (caps);
return (width / 8) * channels;
/* ERRORS */
no_caps:
{
/* ERROR: could not get caps of pad */
g_warning ("gstaudio: could not get caps of pad %s:%s\n",
GST_DEBUG_PAD_NAME (pad));
return 0;
}
}
/**
* gst_audio_frame_length:
* @pad: the #GstPad to get the caps from
* @buf: the #GstBuffer
*
* Calculate length of buffer in frames.
*
* Returns: 0 if there's an error, or the number of frames if everything's ok
*/
long
gst_audio_frame_length (GstPad * pad, GstBuffer * buf)
{
/* FIXME: this should be moved closer to the gstreamer core
* and be implemented for every mime type IMO
*/
int frame_byte_size = 0;
frame_byte_size = gst_audio_frame_byte_size (pad);
if (frame_byte_size == 0)
/* error */
return 0;
/* FIXME: this function assumes the buffer size to be a whole multiple
* of the frame byte size
*/
return gst_buffer_get_size (buf) / frame_byte_size;
}
/**
* gst_audio_duration_from_pad_buffer:
* @pad: the #GstPad to get the caps from
* @buf: the #GstBuffer
*
* Calculate length in nanoseconds of audio buffer @buf based on capabilities of
* @pad.
*
* Returns: the length.
*/
GstClockTime
gst_audio_duration_from_pad_buffer (GstPad * pad, GstBuffer * buf)
{
long bytes = 0;
int width = 0;
int channels = 0;
int rate = 0;
GstCaps *caps;
GstStructure *structure;
g_assert (GST_IS_BUFFER (buf));
/* get caps of pad */
caps = gst_pad_get_current_caps (pad);
if (caps == NULL)
goto no_caps;
structure = gst_caps_get_structure (caps, 0);
bytes = gst_buffer_get_size (buf);
gst_structure_get_int (structure, "width", &width);
gst_structure_get_int (structure, "channels", &channels);
gst_structure_get_int (structure, "rate", &rate);
gst_caps_unref (caps);
g_assert (bytes != 0);
g_assert (width != 0);
g_assert (channels != 0);
g_assert (rate != 0);
return (bytes * 8 * GST_SECOND) / (rate * channels * width);
/* ERRORS */
no_caps:
{
/* ERROR: could not get caps of pad */
g_warning ("gstaudio: could not get caps of pad %s:%s\n",
GST_DEBUG_PAD_NAME (pad));
return GST_CLOCK_TIME_NONE;
}
}
/**
* gst_audio_is_buffer_framed:
* @pad: the #GstPad to get the caps from
* @buf: the #GstBuffer
*
* Check if the buffer size is a whole multiple of the frame size.
*
* Returns: %TRUE if buffer size is multiple.
*/
gboolean
gst_audio_is_buffer_framed (GstPad * pad, GstBuffer * buf)
{
if (gst_buffer_get_size (buf) % gst_audio_frame_byte_size (pad) == 0)
return TRUE;
else
return FALSE;
}
/** /**
* gst_audio_buffer_clip: * gst_audio_buffer_clip:
* @buffer: The buffer to clip. * @buffer: The buffer to clip.
* @segment: Segment in %GST_FORMAT_TIME or %GST_FORMAT_DEFAULT to which the buffer should be clipped. * @segment: Segment in %GST_FORMAT_TIME or %GST_FORMAT_DEFAULT to which
* the buffer should be clipped.
* @rate: sample rate. * @rate: sample rate.
* @frame_size: size of one audio frame in bytes. * @bpf: size of one audio frame in bytes. This is the size of one sample
* * channels.
* *
* Clip the the buffer to the given %GstSegment. * Clip the the buffer to the given %GstSegment.
* *
* After calling this function the caller does not own a reference to * After calling this function the caller does not own a reference to
* @buffer anymore. * @buffer anymore.
* *
* Returns: %NULL if the buffer is completely outside the configured segment, * Returns: %NULL if the buffer is completely outside the configured segment,
* otherwise the clipped buffer is returned. * otherwise the clipped buffer is returned.
* *
* If the buffer has no timestamp, it is assumed to be inside the segment and * If the buffer has no timestamp, it is assumed to be inside the segment and
* is not clipped * is not clipped
* *
* Since: 0.10.14 * Since: 0.10.14
*/ */
GstBuffer * GstBuffer *
gst_audio_buffer_clip (GstBuffer * buffer, GstSegment * segment, gint rate, gst_audio_buffer_clip (GstBuffer * buffer, GstSegment * segment, gint rate,
gint frame_size) gint bpf)
{ {
GstBuffer *ret; GstBuffer *ret;
GstClockTime timestamp = GST_CLOCK_TIME_NONE, duration = GST_CLOCK_TIME_NONE; GstClockTime timestamp = GST_CLOCK_TIME_NONE, duration = GST_CLOCK_TIME_NONE;
@ -602,7 +464,7 @@ gst_audio_buffer_clip (GstBuffer * buffer, GstSegment * segment, gint rate,
duration = GST_BUFFER_DURATION (buffer); duration = GST_BUFFER_DURATION (buffer);
} else { } else {
change_duration = FALSE; change_duration = FALSE;
duration = gst_util_uint64_scale (size / frame_size, GST_SECOND, rate); duration = gst_util_uint64_scale (size / bpf, GST_SECOND, rate);
} }
if (GST_BUFFER_OFFSET_IS_VALID (buffer)) { if (GST_BUFFER_OFFSET_IS_VALID (buffer)) {
@ -616,7 +478,7 @@ gst_audio_buffer_clip (GstBuffer * buffer, GstSegment * segment, gint rate,
offset_end = GST_BUFFER_OFFSET_END (buffer); offset_end = GST_BUFFER_OFFSET_END (buffer);
} else { } else {
change_offset_end = FALSE; change_offset_end = FALSE;
offset_end = offset + size / frame_size; offset_end = offset + size / bpf;
} }
if (segment->format == GST_FORMAT_TIME) { if (segment->format == GST_FORMAT_TIME) {
@ -640,8 +502,8 @@ gst_audio_buffer_clip (GstBuffer * buffer, GstSegment * segment, gint rate,
diff = gst_util_uint64_scale (diff, rate, GST_SECOND); diff = gst_util_uint64_scale (diff, rate, GST_SECOND);
if (change_offset) if (change_offset)
offset += diff; offset += diff;
trim += diff * frame_size; trim += diff * bpf;
size -= diff * frame_size; size -= diff * bpf;
} }
diff = stop - cstop; diff = stop - cstop;
@ -652,7 +514,7 @@ gst_audio_buffer_clip (GstBuffer * buffer, GstSegment * segment, gint rate,
diff = gst_util_uint64_scale (diff, rate, GST_SECOND); diff = gst_util_uint64_scale (diff, rate, GST_SECOND);
if (change_offset_end) if (change_offset_end)
offset_end -= diff; offset_end -= diff;
size -= diff * frame_size; size -= diff * bpf;
} }
} else { } else {
gst_buffer_unref (buffer); gst_buffer_unref (buffer);
@ -679,8 +541,8 @@ gst_audio_buffer_clip (GstBuffer * buffer, GstSegment * segment, gint rate,
if (change_duration) if (change_duration)
duration -= gst_util_uint64_scale (diff, GST_SECOND, rate); duration -= gst_util_uint64_scale (diff, GST_SECOND, rate);
trim += diff * frame_size; trim += diff * bpf;
size -= diff * frame_size; size -= diff * bpf;
} }
diff = stop - cstop; diff = stop - cstop;
@ -690,7 +552,7 @@ gst_audio_buffer_clip (GstBuffer * buffer, GstSegment * segment, gint rate,
if (change_duration) if (change_duration)
duration -= gst_util_uint64_scale (diff, GST_SECOND, rate); duration -= gst_util_uint64_scale (diff, GST_SECOND, rate);
size -= diff * frame_size; size -= diff * bpf;
} }
} else { } else {
gst_buffer_unref (buffer); gst_buffer_unref (buffer);

View file

@ -142,7 +142,7 @@ typedef struct _GstAudioInfo GstAudioInfo;
/** /**
* GstAudioFormatFlags: * GstAudioFormatFlags:
* @GST_AUDIO_FORMAT_FLAG_INT: int samples * @GST_AUDIO_FORMAT_FLAG_INTEGER: integer samples
* @GST_AUDIO_FORMAT_FLAG_FLOAT: float samples * @GST_AUDIO_FORMAT_FLAG_FLOAT: float samples
* @GST_AUDIO_FORMAT_FLAG_SIGNED: signed samples * @GST_AUDIO_FORMAT_FLAG_SIGNED: signed samples
* @GST_AUDIO_FORMAT_FLAG_COMPLEX: complex layout * @GST_AUDIO_FORMAT_FLAG_COMPLEX: complex layout
@ -151,7 +151,7 @@ typedef struct _GstAudioInfo GstAudioInfo;
*/ */
typedef enum typedef enum
{ {
GST_AUDIO_FORMAT_FLAG_INT = (1 << 0), GST_AUDIO_FORMAT_FLAG_INTEGER = (1 << 0),
GST_AUDIO_FORMAT_FLAG_FLOAT = (1 << 1), GST_AUDIO_FORMAT_FLAG_FLOAT = (1 << 1),
GST_AUDIO_FORMAT_FLAG_SIGNED = (1 << 2), GST_AUDIO_FORMAT_FLAG_SIGNED = (1 << 2),
GST_AUDIO_FORMAT_FLAG_COMPLEX = (1 << 4) GST_AUDIO_FORMAT_FLAG_COMPLEX = (1 << 4)
@ -217,7 +217,7 @@ struct _GstAudioFormatInfo {
#define GST_AUDIO_FORMAT_INFO_NAME(info) ((info)->name) #define GST_AUDIO_FORMAT_INFO_NAME(info) ((info)->name)
#define GST_AUDIO_FORMAT_INFO_FLAGS(info) ((info)->flags) #define GST_AUDIO_FORMAT_INFO_FLAGS(info) ((info)->flags)
#define GST_AUDIO_FORMAT_INFO_IS_INT(info) ((info)->flags & GST_AUDIO_FORMAT_FLAG_INT) #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_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_IS_SIGNED(info) ((info)->flags & GST_AUDIO_FORMAT_FLAG_SIGNED)
@ -228,16 +228,17 @@ struct _GstAudioFormatInfo {
#define GST_AUDIO_FORMAT_INFO_DEPTH(info) ((info)->depth) #define GST_AUDIO_FORMAT_INFO_DEPTH(info) ((info)->depth)
GstAudioFormat gst_audio_format_build_int (gboolean sign, gint endianness, GstAudioFormat gst_audio_format_build_integer (gboolean sign, gint endianness,
gint width, gint depth) G_GNUC_CONST; 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;
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 * const GstAudioFormatInfo *
gst_audio_format_get_info (GstAudioFormat format) G_GNUC_CONST; gst_audio_format_get_info (GstAudioFormat format) G_GNUC_CONST;
void gst_audio_format_fill_silence (const GstAudioFormatInfo *info, void gst_audio_format_fill_silence (const GstAudioFormatInfo *info,
gpointer dest, gsize length); gpointer dest, gsize length);
/** /**
* GstAudioFlags: * GstAudioFlags:
* @GST_AUDIO_FLAG_NONE: no valid flag * @GST_AUDIO_FLAG_NONE: no valid flag
@ -375,18 +376,8 @@ GstCaps * gst_audio_info_to_caps (GstAudioInfo *info);
* handling * handling
*/ */
/* get byte size of audio frame (based on caps of pad */ GstBuffer * gst_audio_buffer_clip (GstBuffer *buffer, GstSegment *segment,
int gst_audio_frame_byte_size (GstPad* pad); gint rate, gint bpf);
/* get length in frames of buffer */
long gst_audio_frame_length (GstPad* pad, GstBuffer* buf);
GstClockTime gst_audio_duration_from_pad_buffer (GstPad * pad, GstBuffer * buf);
/* check if the buffer size is a whole multiple of the frame size */
gboolean gst_audio_is_buffer_framed (GstPad* pad, GstBuffer* buf);
GstBuffer *gst_audio_buffer_clip (GstBuffer *buffer, GstSegment *segment, gint rate, gint frame_size);
G_END_DECLS G_END_DECLS

View file

@ -1153,7 +1153,8 @@ gst_riff_create_audio_caps (guint16 codec_id,
/* For reference, the actual depth is in strf->size */ /* For reference, the actual depth is in strf->size */
ws = wd; ws = wd;
format = gst_audio_format_build_int (wd != 8, G_LITTLE_ENDIAN, wd, ws); format =
gst_audio_format_build_integer (wd != 8, G_LITTLE_ENDIAN, wd, ws);
caps = gst_caps_new_simple ("audio/x-raw", caps = gst_caps_new_simple ("audio/x-raw",
"format", G_TYPE_STRING, gst_audio_format_to_string (format), "format", G_TYPE_STRING, gst_audio_format_to_string (format),
@ -1516,7 +1517,8 @@ gst_riff_create_audio_caps (guint16 codec_id,
* ws = valid_bits_per_sample; */ * ws = valid_bits_per_sample; */
format = format =
gst_audio_format_build_int (wd != 8, G_LITTLE_ENDIAN, wd, ws); gst_audio_format_build_integer (wd != 8, G_LITTLE_ENDIAN, wd,
ws);
caps = gst_caps_new_simple ("audio/x-raw", caps = gst_caps_new_simple ("audio/x-raw",
"format", G_TYPE_STRING, gst_audio_format_to_string (format), "format", G_TYPE_STRING, gst_audio_format_to_string (format),

View file

@ -557,8 +557,8 @@ static AudioConvertPack pack_funcs[] = {
}; };
#define DOUBLE_INTERMEDIATE_FORMAT(ctx) \ #define DOUBLE_INTERMEDIATE_FORMAT(ctx) \
((!GST_AUDIO_FORMAT_INFO_IS_INT (ctx->in.finfo) && \ ((!GST_AUDIO_FORMAT_INFO_IS_INTEGER (ctx->in.finfo) && \
!GST_AUDIO_FORMAT_INFO_IS_INT (ctx->out.finfo)) || \ !GST_AUDIO_FORMAT_INFO_IS_INTEGER (ctx->out.finfo)) || \
(ctx->ns != NOISE_SHAPING_NONE)) (ctx->ns != NOISE_SHAPING_NONE))
static gint static gint
@ -567,7 +567,7 @@ audio_convert_get_func_index (AudioConvertCtx * ctx,
{ {
gint index = 0; gint index = 0;
if (GST_AUDIO_FORMAT_INFO_IS_INT (fmt)) { if (GST_AUDIO_FORMAT_INFO_IS_INTEGER (fmt)) {
index += (GST_AUDIO_FORMAT_INFO_WIDTH (fmt) / 8 - 1) * 4; index += (GST_AUDIO_FORMAT_INFO_WIDTH (fmt) / 8 - 1) * 4;
index += GST_AUDIO_FORMAT_INFO_IS_LE (fmt) ? 0 : 2; index += GST_AUDIO_FORMAT_INFO_IS_LE (fmt) ? 0 : 2;
index += GST_AUDIO_FORMAT_INFO_IS_SIGNED (fmt) ? 1 : 0; index += GST_AUDIO_FORMAT_INFO_IS_SIGNED (fmt) ? 1 : 0;
@ -621,7 +621,7 @@ audio_convert_prepare_context (AudioConvertCtx * ctx, GstAudioInfo * in,
* as DA converters only can do a SNR up to 20 bits in reality. * as DA converters only can do a SNR up to 20 bits in reality.
* Also don't dither or apply noise shaping if target depth is larger than * Also don't dither or apply noise shaping if target depth is larger than
* source depth. */ * source depth. */
if (out_depth <= 20 && (!GST_AUDIO_FORMAT_INFO_IS_INT (in->finfo) if (out_depth <= 20 && (!GST_AUDIO_FORMAT_INFO_IS_INTEGER (in->finfo)
|| in_depth >= out_depth)) { || in_depth >= out_depth)) {
ctx->dither = dither; ctx->dither = dither;
ctx->ns = ns; ctx->ns = ns;
@ -665,9 +665,9 @@ audio_convert_prepare_context (AudioConvertCtx * ctx, GstAudioInfo * in,
ctx->in_default, ctx->mix_passthrough, ctx->out_default); ctx->in_default, ctx->mix_passthrough, ctx->out_default);
ctx->in_scale = ctx->in_scale =
GST_AUDIO_FORMAT_INFO_IS_INT (in->finfo) ? (32 - in_depth) : 0; GST_AUDIO_FORMAT_INFO_IS_INTEGER (in->finfo) ? (32 - in_depth) : 0;
ctx->out_scale = ctx->out_scale =
GST_AUDIO_FORMAT_INFO_IS_INT (out->finfo) ? (32 - out_depth) : 0; GST_AUDIO_FORMAT_INFO_IS_INTEGER (out->finfo) ? (32 - out_depth) : 0;
gst_audio_quantize_setup (ctx); gst_audio_quantize_setup (ctx);
@ -779,7 +779,7 @@ audio_convert_convert (AudioConvertCtx * ctx, gpointer src,
} }
/* we only need to quantize if output format is int */ /* we only need to quantize if output format is int */
if (GST_AUDIO_FORMAT_INFO_IS_INT (ctx->out.finfo)) { if (GST_AUDIO_FORMAT_INFO_IS_INTEGER (ctx->out.finfo)) {
if (ctx->out_default) if (ctx->out_default)
outbuf = dst; outbuf = dst;
else else

View file

@ -439,7 +439,7 @@ gst_audio_quantize_setup_dither (AudioConvertCtx * ctx)
{ {
switch (ctx->dither) { switch (ctx->dither) {
case DITHER_TPDF_HF: case DITHER_TPDF_HF:
if (GST_AUDIO_FORMAT_INFO_IS_INT (ctx->out.finfo)) if (GST_AUDIO_FORMAT_INFO_IS_INTEGER (ctx->out.finfo))
ctx->last_random = g_new0 (gint32, ctx->out.channels); ctx->last_random = g_new0 (gint32, ctx->out.channels);
else else
ctx->last_random = g_new0 (gdouble, ctx->out.channels); ctx->last_random = g_new0 (gdouble, ctx->out.channels);
@ -469,7 +469,7 @@ gst_audio_quantize_setup_quantize_func (AudioConvertCtx * ctx)
{ {
gint index = 0; gint index = 0;
if (!GST_AUDIO_FORMAT_INFO_IS_INT (ctx->out.finfo)) { if (!GST_AUDIO_FORMAT_INFO_IS_INTEGER (ctx->out.finfo)) {
ctx->quantize = NULL; ctx->quantize = NULL;
return; return;
} }

View file

@ -601,8 +601,8 @@ gst_channel_mix_setup_matrix (AudioConvertCtx * this)
gst_channel_mix_unset_matrix (this); gst_channel_mix_unset_matrix (this);
/* temp storage */ /* temp storage */
if (GST_AUDIO_FORMAT_INFO_IS_INT (this->in.finfo) || if (GST_AUDIO_FORMAT_INFO_IS_INTEGER (this->in.finfo) ||
GST_AUDIO_FORMAT_INFO_IS_INT (this->out.finfo)) { GST_AUDIO_FORMAT_INFO_IS_INTEGER (this->out.finfo)) {
this->tmp = (gpointer) g_new (gint32, this->out.channels); this->tmp = (gpointer) g_new (gint32, this->out.channels);
} else { } else {
this->tmp = (gpointer) g_new (gdouble, this->out.channels); this->tmp = (gpointer) g_new (gdouble, this->out.channels);