summaryrefslogtreecommitdiff
path: root/gst/audioresample
diff options
context:
space:
mode:
authorWim Taymans <wtaymans@redhat.com>2016-01-15 11:20:29 +0100
committerWim Taymans <wtaymans@redhat.com>2016-03-28 13:25:50 +0200
commitd348fbb9b98eaf045604195abe43f85ddb2340a5 (patch)
treedab1fa8e7494e11d27292b32651a6085dfeca9d4 /gst/audioresample
parent23531bdc93bbcaec774d989ac4496c2a829ca292 (diff)
downloadgstreamer-plugins-base-d348fbb9b98eaf045604195abe43f85ddb2340a5.tar.gz
audio-converter: make some optimized functions
Make an optimized function that just calls the resampler when possible. Optimize the resampler transform_size function a little.
Diffstat (limited to 'gst/audioresample')
-rw-r--r--gst/audioresample/gstaudioresample.c45
1 files changed, 6 insertions, 39 deletions
diff --git a/gst/audioresample/gstaudioresample.c b/gst/audioresample/gstaudioresample.c
index 2faf6752b..45d4cdf10 100644
--- a/gst/audioresample/gstaudioresample.c
+++ b/gst/audioresample/gstaudioresample.c
@@ -431,61 +431,32 @@ gst_audio_resample_reset_state (GstAudioResample * resample)
{
}
-static gint
-_gcd (gint a, gint b)
-{
- while (b != 0) {
- int temp = a;
-
- a = b;
- b = temp % b;
- }
-
- return ABS (a);
-}
-
static gboolean
gst_audio_resample_transform_size (GstBaseTransform * base,
GstPadDirection direction, GstCaps * caps, gsize size, GstCaps * othercaps,
gsize * othersize)
{
+ GstAudioResample *resample = GST_AUDIO_RESAMPLE (base);
gboolean ret = TRUE;
- GstAudioInfo in, out;
- guint32 ratio_den, ratio_num;
- gint inrate, outrate, gcd;
gint bpf;
GST_LOG_OBJECT (base, "asked to transform size %" G_GSIZE_FORMAT
" in direction %s", size, direction == GST_PAD_SINK ? "SINK" : "SRC");
- /* Get sample width -> bytes_per_samp, channels, inrate, outrate */
- ret = gst_audio_info_from_caps (&in, caps);
- ret &= gst_audio_info_from_caps (&out, othercaps);
- if (G_UNLIKELY (!ret)) {
- GST_ERROR_OBJECT (base, "Wrong caps");
- return FALSE;
- }
/* Number of samples in either buffer is size / (width*channels) ->
* calculate the factor */
- bpf = GST_AUDIO_INFO_BPF (&in);
- inrate = GST_AUDIO_INFO_RATE (&in);
- outrate = GST_AUDIO_INFO_RATE (&out);
+ bpf = GST_AUDIO_INFO_BPF (&resample->in);
/* Convert source buffer size to samples */
size /= bpf;
- /* Simplify the conversion ratio factors */
- gcd = _gcd (inrate, outrate);
- ratio_num = inrate / gcd;
- ratio_den = outrate / gcd;
-
if (direction == GST_PAD_SINK) {
- /* asked to convert size of an incoming buffer. Round up the output size */
- *othersize = gst_util_uint64_scale_int_ceil (size, ratio_den, ratio_num);
+ /* asked to convert size of an incoming buffer */
+ *othersize = gst_audio_converter_get_out_frames (resample->converter, size);
*othersize *= bpf;
} else {
- /* asked to convert size of an outgoing buffer. Round down the input size */
- *othersize = gst_util_uint64_scale_int (size, ratio_num, ratio_den);
+ /* asked to convert size of an outgoing buffer */
+ *othersize = gst_audio_converter_get_in_frames (resample->converter, size);
*othersize *= bpf;
}
@@ -810,9 +781,6 @@ gst_audio_resample_process (GstAudioResample * resample, GstBuffer * inbuf,
gpointer in[1], out[1];
GstAudioConverterFlags flags;
- out_len =
- gst_audio_converter_get_out_frames (resample->converter, in_len);
-
flags = 0;
if (inbuf_writable)
flags |= GST_AUDIO_CONVERTER_FLAG_IN_WRITABLE;
@@ -853,7 +821,6 @@ gst_audio_resample_process (GstAudioResample * resample, GstBuffer * inbuf,
gst_buffer_unmap (outbuf, &out_map);
outsize = out_len * resample->in.bpf;
- gst_buffer_resize (outbuf, 0, outsize);
GST_LOG_OBJECT (resample,
"Converted to buffer of %" G_GUINT32_FORMAT