summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Dröge <slomo@circular-chaos.org>2007-11-20 07:30:30 +0000
committerSebastian Dröge <slomo@circular-chaos.org>2007-11-20 07:30:30 +0000
commita6a91b4ff893f1765310cde34fa168db26a9c65b (patch)
treec328beb89fa8a0dd9db09b67b019040998e00723
parent644432907c659f4fdc64bef9cf13d54f6e30b60c (diff)
downloadgst-plugins-bad-a6a91b4ff893f1765310cde34fa168db26a9c65b.tar.gz
gst-plugins-bad-a6a91b4ff893f1765310cde34fa168db26a9c65b.tar.bz2
gst-plugins-bad-a6a91b4ff893f1765310cde34fa168db26a9c65b.zip
gst/speexresample/gstspeexresample.c: If the resampler gives less output samples than expected adjust the output buff...
Original commit message from CVS: * gst/speexresample/gstspeexresample.c: (gst_speex_fix_output_buffer), (gst_speex_resample_process): If the resampler gives less output samples than expected adjust the output buffer and print a warning.
-rw-r--r--ChangeLog7
-rw-r--r--gst/speexresample/gstspeexresample.c36
2 files changed, 40 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index a77f8c7c..6a76c845 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
2007-11-20 Sebastian Dröge <slomo@circular-chaos.org>
+ * gst/speexresample/gstspeexresample.c:
+ (gst_speex_fix_output_buffer), (gst_speex_resample_process):
+ If the resampler gives less output samples than expected
+ adjust the output buffer and print a warning.
+
+2007-11-20 Sebastian Dröge <slomo@circular-chaos.org>
+
* configure.ac:
* gst/speexresample/arch.h:
* gst/speexresample/fixed_generic.h:
diff --git a/gst/speexresample/gstspeexresample.c b/gst/speexresample/gstspeexresample.c
index 307b8180..71df1fa8 100644
--- a/gst/speexresample/gstspeexresample.c
+++ b/gst/speexresample/gstspeexresample.c
@@ -534,6 +534,28 @@ gst_speex_resample_check_discont (GstSpeexResample * resample,
return FALSE;
}
+static void
+gst_speex_fix_output_buffer (GstSpeexResample * resample, GstBuffer * outbuf,
+ guint diff)
+{
+ GstClockTime timediff =
+ gst_util_uint64_scale (diff, GST_SECOND, resample->outrate);
+
+ GST_LOG ("Adjusting buffer by %d samples", diff);
+
+ GST_BUFFER_DURATION (outbuf) -= timediff;
+ GST_BUFFER_SIZE (outbuf) -= diff * ((resample->fp) ? 4 : 2);
+
+ if (resample->ts_offset != -1) {
+ GST_BUFFER_OFFSET_END (outbuf) -= diff;
+ resample->offset -= diff;
+ resample->ts_offset -= diff;
+ resample->next_ts =
+ gst_util_uint64_scale_int (resample->ts_offset, GST_SECOND,
+ resample->outrate);
+ }
+}
+
static GstFlowReturn
gst_speex_resample_process (GstSpeexResample * resample, GstBuffer * inbuf,
GstBuffer * outbuf)
@@ -568,9 +590,17 @@ gst_speex_resample_process (GstSpeexResample * resample, GstBuffer * inbuf,
if (in_len != in_processed)
GST_WARNING ("Converted %d of %d input samples", in_processed, in_len);
- if (out_len != out_processed)
- GST_WARNING ("Converted to %d instead of %d output samples", out_processed,
- out_len);
+ if (out_len != out_processed) {
+ /* One sample difference is allowed as this will happen
+ * because of rounding errors */
+ if (out_len - out_processed != 1)
+ GST_WARNING ("Converted to %d instead of %d output samples",
+ out_processed, out_len);
+ if (out_len > out_processed)
+ gst_speex_fix_output_buffer (resample, outbuf, out_len - out_processed);
+ else
+ g_error ("Wrote more output then allocated!");
+ }
if (err != RESAMPLER_ERR_SUCCESS) {
GST_ERROR ("Failed to convert data: %s", resample_resampler_strerror (err));