It adds unnecessary complication for insignificant usability improvement.
The user really should know if they'll need resampling compensation before
opening the context.

Note that only the documentation has changed. The current functionality will
still work until the next major bump.
---
 libavresample/avresample.h |    9 ++++-----
 libavresample/resample.c   |    9 +++++++--
 libavresample/version.h    |    4 ++++
 3 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/libavresample/avresample.h b/libavresample/avresample.h
index 8c27bfc..3adb37c 100644
--- a/libavresample/avresample.h
+++ b/libavresample/avresample.h
@@ -283,11 +283,10 @@ int avresample_set_channel_mapping(AVAudioResampleContext 
*avr,
 /**
  * Set compensation for resampling.
  *
- * This can be called anytime after avresample_open(). If resampling was not
- * being done previously, the AVAudioResampleContext is closed and reopened
- * with resampling enabled. In this case, any samples remaining in the output
- * FIFO and the current channel mixing matrix will be restored after reopening
- * the context.
+ * This can be called anytime after avresample_open(). If resampling is not
+ * automatically enabled because of a sample rate conversion, the
+ * "force_resampling" option must have been set to 1 when opening the context
+ * in order to use resampling compensation.
  *
  * @param avr                    audio resample context
  * @param sample_delta           compensation delta, in samples
diff --git a/libavresample/resample.c b/libavresample/resample.c
index 2cd9b7d..1010cd5 100644
--- a/libavresample/resample.c
+++ b/libavresample/resample.c
@@ -255,9 +255,10 @@ int avresample_set_compensation(AVAudioResampleContext 
*avr, int sample_delta,
     if (!compensation_distance && sample_delta)
         return AVERROR(EINVAL);
 
-    /* if resampling was not enabled previously, re-initialize the
-       AVAudioResampleContext and force resampling */
     if (!avr->resample_needed) {
+#if FF_API_RESAMPLE_CLOSE_OPEN
+        /* if resampling was not enabled previously, re-initialize the
+           AVAudioResampleContext and force resampling */
         int fifo_samples;
         int save_matrix = 0;
         double matrix[AVRESAMPLE_MAX_CHANNELS * AVRESAMPLE_MAX_CHANNELS] = { 0 
};
@@ -307,6 +308,10 @@ int avresample_set_compensation(AVAudioResampleContext 
*avr, int sample_delta,
                 goto reinit_fail;
             ff_audio_data_free(&fifo_buf);
         }
+#else
+        av_log(avr, AV_LOG_ERROR, "Unable to set resampling compensation\n");
+        return AVERROR(EINVAL);
+#endif
     }
     c = avr->resample;
     c->compensation_distance = compensation_distance;
diff --git a/libavresample/version.h b/libavresample/version.h
index 2e57c22..387d097 100644
--- a/libavresample/version.h
+++ b/libavresample/version.h
@@ -39,4 +39,8 @@
  * the public API and may change, break or disappear at any time.
  */
 
+#ifndef FF_API_RESAMPLE_CLOSE_OPEN
+#define FF_API_RESAMPLE_CLOSE_OPEN (LIBAVRESAMPLE_VERSION_MAJOR < 2)
+#endif
+
 #endif /* AVRESAMPLE_VERSION_H */
-- 
1.7.1

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to