summaryrefslogtreecommitdiffstats
path: root/gst/audioresample/resample.c
diff options
context:
space:
mode:
authorThomas Vander Stichele <thomas@apestaart.org>2005-08-25 12:31:31 +0000
committerThomas Vander Stichele <thomas@apestaart.org>2005-08-25 12:31:31 +0000
commit0daade2ce6042d380bf513b8c95760c432f3e939 (patch)
treecfe6a51ce30b5729e0b15a12c7b68701a919ac13 /gst/audioresample/resample.c
parentf488ccf221c9695d6820fefc31ed01f79e665408 (diff)
downloadgst-plugins-bad-0daade2ce6042d380bf513b8c95760c432f3e939.tar.gz
gst-plugins-bad-0daade2ce6042d380bf513b8c95760c432f3e939.tar.bz2
gst-plugins-bad-0daade2ce6042d380bf513b8c95760c432f3e939.zip
gst/audioresample/: add room for extra overlap samples when asked to transform size protect against possible mem corr...
Original commit message from CVS: * gst/audioresample/debug.c: * gst/audioresample/gstaudioresample.c: add room for extra overlap samples when asked to transform size protect against possible mem corruption and check for discrepancies between written size and outbuffer's size so we can warn for potential problems * gst/audioresample/resample.c: (resample_init), (resample_get_output_size_for_input), (resample_get_output_size), (resample_set_n_channels), (resample_set_format): set debug level based on RESAMPLE_DEBUG env var make sure that get_output_size* returns a whole number of sample_size set sample_size each time either channel or format is set * gst/audioresample/resample_chunk.c: (resample_scale_chunk): * gst/audioresample/resample_functable.c: (resample_scale_functable): * gst/audioresample/resample_ref.c: (resample_scale_ref): remove r->sample_size, it's done in resample.c now add some debugging to the ref implementation make sure we only give back bytes that are wholes of the sample size
Diffstat (limited to 'gst/audioresample/resample.c')
-rw-r--r--gst/audioresample/resample.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/gst/audioresample/resample.c b/gst/audioresample/resample.c
index e8ec45fb..8e759da2 100644
--- a/gst/audioresample/resample.c
+++ b/gst/audioresample/resample.c
@@ -42,11 +42,16 @@ void
resample_init (void)
{
static int inited = 0;
+ const char *debug;
if (!inited) {
oil_init ();
inited = 1;
}
+
+ if ((debug = g_getenv ("RESAMPLE_DEBUG"))) {
+ resample_debug_set_level (atoi (debug));
+ }
}
ResampleState *
@@ -141,14 +146,24 @@ resample_input_eos (ResampleState * r)
int
resample_get_output_size_for_input (ResampleState * r, int size)
{
- return floor (size * r->o_rate / r->i_rate);
+ int outsize;
+ double outd;
+
+ g_return_val_if_fail (r->sample_size != 0, 0);
+
+ RESAMPLE_DEBUG ("size %d, o_rate %f, i_rate %f", size, r->o_rate, r->i_rate);
+ outd = (double) size / r->i_rate * r->o_rate;
+ outsize = (int) floor (outd);
+
+ /* round off for sample size */
+ return outsize - (outsize % r->sample_size);
}
int
resample_get_output_size (ResampleState * r)
{
- return floor (audioresample_buffer_queue_get_depth (r->queue) * r->o_rate /
- r->i_rate);
+ return resample_get_output_size_for_input (r,
+ audioresample_buffer_queue_get_depth (r->queue));
}
int
@@ -196,6 +211,7 @@ void
resample_set_n_channels (ResampleState * r, int n_channels)
{
r->n_channels = n_channels;
+ r->sample_size = r->n_channels * resample_format_size (r->format);
r->need_reinit = 1;
}
@@ -203,6 +219,7 @@ void
resample_set_format (ResampleState * r, ResampleFormat format)
{
r->format = format;
+ r->sample_size = r->n_channels * resample_format_size (r->format);
r->need_reinit = 1;
}