]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/resample.c
x86: h264qpel: Move stray comment to the right spot and clarify it
[ffmpeg] / libavcodec / resample.c
index fce6272e78dff6c76ef96f3e889c8f072968ebbd..1b3bb834f3b73c82c48e76f3e251025284572f26 100644 (file)
  * samplerate conversion for both audio and video
  */
 
+#include <string.h>
+
 #include "avcodec.h"
 #include "audioconvert.h"
 #include "libavutil/opt.h"
+#include "libavutil/mem.h"
 #include "libavutil/samplefmt.h"
 
+#if FF_API_AVCODEC_RESAMPLE
+
 #define MAX_CHANNELS 8
 
 struct AVResampleContext;
@@ -162,9 +167,10 @@ ReSampleContext *av_audio_resample_init(int output_channels, int input_channels,
                MAX_CHANNELS);
         return NULL;
     }
-    if (output_channels > 2 &&
-        !(output_channels == 6 && input_channels == 2) &&
-        output_channels != input_channels) {
+    if (output_channels != input_channels &&
+        (input_channels  > 2 ||
+         output_channels > 2 &&
+         !(output_channels == 6 && input_channels == 2))) {
         av_log(NULL, AV_LOG_ERROR,
                "Resampling output channel count must be 1 or 2 for mono input; 1, 2 or 6 for stereo input; or N for N channel input.\n");
         return NULL;
@@ -271,11 +277,13 @@ int audio_resample(ReSampleContext *s, short *output, short *input, int nb_sampl
     lenout = 4 * nb_samples * s->ratio + 16;
 
     if (s->sample_fmt[1] != AV_SAMPLE_FMT_S16) {
+        int out_size = lenout * av_get_bytes_per_sample(s->sample_fmt[1]) *
+                       s->output_channels;
         output_bak = output;
 
-        if (!s->buffer_size[1] || s->buffer_size[1] < lenout) {
+        if (!s->buffer_size[1] || s->buffer_size[1] < out_size) {
             av_free(s->buffer[1]);
-            s->buffer_size[1] = lenout;
+            s->buffer_size[1] = out_size;
             s->buffer[1] = av_malloc(s->buffer_size[1]);
             if (!s->buffer[1]) {
                 av_log(s->resample_context, AV_LOG_ERROR, "Could not allocate buffer\n");
@@ -342,7 +350,7 @@ int audio_resample(ReSampleContext *s, short *output, short *input, int nb_sampl
         if (av_audio_convert(s->convert_ctx[1], obuf, ostride,
                              ibuf, istride, nb_samples1 * s->output_channels) < 0) {
             av_log(s->resample_context, AV_LOG_ERROR,
-                   "Audio sample format convertion failed\n");
+                   "Audio sample format conversion failed\n");
             return 0;
         }
     }
@@ -367,3 +375,5 @@ void audio_resample_close(ReSampleContext *s)
     av_audio_convert_free(s->convert_ctx[1]);
     av_free(s);
 }
+
+#endif