On 05/10/2011 08:00 PM, Aℓex Converse wrote:

> On Tue, May 10, 2011 at 4:01 PM, Alex Converse <aconve...@google.com> wrote:
>> > ---
>> >  libavcodec/resample.c |   83 
>> > ++++++++++++++++++++++++-------------------------
>> >  1 files changed, 41 insertions(+), 42 deletions(-)
>> >
> Updated to drop an obsoleted comment.
> 
> 
> 0002-Allow-resampling-with-no-channel-count-change-for-up.patch
> 
> 
> From 5bcc724fd3a3b69c37d0419626c7b17913a09c9d Mon Sep 17 00:00:00 2001
> From: Alex Converse <aconve...@google.com>
> Date: Tue, 10 May 2011 14:24:05 -0700
> Subject: [PATCH 2/3] Allow resampling with no channel count change for up to 
> 8 channels.
> 
> ---
>  libavcodec/resample.c |   84 
> ++++++++++++++++++++++++-------------------------
>  1 files changed, 41 insertions(+), 43 deletions(-)
> 
> diff --git a/libavcodec/resample.c b/libavcodec/resample.c
> index 8800098..2fe2e46 100644
> --- a/libavcodec/resample.c
> +++ b/libavcodec/resample.c
> @@ -29,6 +29,8 @@
>  #include "libavutil/opt.h"
>  #include "libavutil/samplefmt.h"
>  
> +#define MAX_CHANNELS 8


This could be increased to something like 256 or higher if we
dynamically allocate the pointers as well.  Just something to consider
later.  8 is fine for now.

> +
>  struct AVResampleContext;
>  
>  static const char *context_to_name(void *ptr)
> @@ -41,7 +43,7 @@ static const AVClass audioresample_context_class = { 
> "ReSampleContext", context_
>  
>  struct ReSampleContext {
>      struct AVResampleContext *resample_context;
> -    short *temp[2];
> +    short *temp[MAX_CHANNELS];
>      int temp_len;
>      float ratio;
>      /* channel convert */
> @@ -104,24 +106,25 @@ static void mono_to_stereo(short *output, short *input, 
> int n1)
>      }
>  }
>  
> -/* XXX: should use more abstract 'N' channels system */
> -static void stereo_split(short *output1, short *output2, short *input, int n)
> +static void deinterleave(short **output, short *input, int channels, int 
> samples)
>  {
> -    int i;
> +    int i, j;
>  
> -    for(i=0;i<n;i++) {
> -        *output1++ = *input++;
> -        *output2++ = *input++;
> +    for (i = 0; i < samples; i++) {
> +        for (j = 0; j < channels; j++) {
> +            *output[j]++ = *input++;
> +        }
>      }
>  }
>  
> -static void stereo_mux(short *output, short *input1, short *input2, int n)
> +static void interleave(short *output, short **input, int channels, int 
> samples)
>  {
> -    int i;
> +    int i, j;
>  
> -    for(i=0;i<n;i++) {
> -        *output++ = *input1++;
> -        *output++ = *input2++;
> +    for (i = 0; i < samples; i++) {
> +        for (j = 0; j < channels; j++) {
> +            *output++ = *input[j]++;
> +        }
>      }
>  }

ok.

> @@ -151,14 +154,18 @@ ReSampleContext *av_audio_resample_init(int 
> output_channels, int input_channels,
>  {
>      ReSampleContext *s;
>  
> -    if ( input_channels > 2)
> +    if (input_channels > MAX_CHANNELS)
>        {
> -        av_log(NULL, AV_LOG_ERROR, "Resampling with input channels greater 
> than 2 unsupported.\n");
> +        av_log(NULL, AV_LOG_ERROR,
> +               "Resampling with input channels greater than %d 
> unsupported.\n",
> +               MAX_CHANNELS);


add "is" before "unsupported" to make it a complete sentence.

>          return NULL;
>        }
> -    if (output_channels > 2 && !(output_channels == 6 && input_channels == 
> 2)) {
> +    if (  output_channels > 2 &&
> +        !(output_channels == 6 && input_channels == 2) &&
> +          output_channels != input_channels) {
>          av_log(NULL, AV_LOG_ERROR,
> -               "Resampling output channel count must 1 or 2 for mono input 
> and 1, 2 or 6 for stereo input.\n");
> +               "Resampling output channel count must 1 or 2 for mono input; 
> 1, 2 or 6 for stereo input; or N for N channel input.\n");
>          return NULL;
>      }

"...channel count must be 1 or 2..."

> @@ -206,14 +213,6 @@ ReSampleContext *av_audio_resample_init(int 
> output_channels, int input_channels,
>          }
>      }
>  
> -/*
> - * AC-3 output is the only case where filter_channels could be greater than 
> 2.
> - * input channels can't be greater than 2, so resample the 2 channels and 
> then
> - * expand to 6 channels after the resampling.
> - */
> -    if(s->filter_channels>2)
> -      s->filter_channels = 2;
> -
>  #define TAPS 16
>      s->resample_context= av_resample_init(output_rate, input_rate,
>                           filter_length, log2_phase_count, linear, cutoff);
> @@ -228,9 +227,9 @@ ReSampleContext *av_audio_resample_init(int 
> output_channels, int input_channels,
>  int audio_resample(ReSampleContext *s, short *output, short *input, int 
> nb_samples)
>  {
>      int i, nb_samples1;
> -    short *bufin[2];
> -    short *bufout[2];
> -    short *buftmp2[2], *buftmp3[2];
> +    short *bufin[MAX_CHANNELS];
> +    short *bufout[MAX_CHANNELS];
> +    short *buftmp2[MAX_CHANNELS], *buftmp3[MAX_CHANNELS];
>      short *output_bak = NULL;
>      int lenout;
>  
> @@ -291,12 +290,9 @@ int audio_resample(ReSampleContext *s, short *output, 
> short *input, int nb_sampl
>          bufin[i]= av_malloc( (nb_samples + s->temp_len) * sizeof(short) );
>          memcpy(bufin[i], s->temp[i], s->temp_len * sizeof(short));
>          buftmp2[i] = bufin[i] + s->temp_len;
> +        bufout[i] = av_malloc( lenout * sizeof(short) );


remove the extra spaces inside the (). unless you're just matching style
which is then corrected by your style patch...

>      }
>  
> -    /* make some zoom to avoid round pb */
> -    bufout[0]= av_malloc( lenout * sizeof(short) );
> -    bufout[1]= av_malloc( lenout * sizeof(short) );
> -
>      if (s->input_channels == 2 &&
>          s->output_channels == 1) {
>          buftmp3[0] = output;
> @@ -304,10 +300,11 @@ int audio_resample(ReSampleContext *s, short *output, 
> short *input, int nb_sampl
>      } else if (s->output_channels >= 2 && s->input_channels == 1) {
>          buftmp3[0] = bufout[0];
>          memcpy(buftmp2[0], input, nb_samples*sizeof(short));
> -    } else if (s->output_channels >= 2) {
> -        buftmp3[0] = bufout[0];
> -        buftmp3[1] = bufout[1];
> -        stereo_split(buftmp2[0], buftmp2[1], input, nb_samples);
> +    } else if (s->output_channels >= s->input_channels && s->input_channels 
> >= 2) {
> +        for (i = 0; i < s->input_channels; i++) {
> +            buftmp3[i] = bufout[i];
> +        }
> +        deinterleave(buftmp2, input, s->input_channels, nb_samples);
>      } else {
>          buftmp3[0] = output;
>          memcpy(buftmp2[0], input, nb_samples*sizeof(short));
> @@ -329,10 +326,10 @@ int audio_resample(ReSampleContext *s, short *output, 
> short *input, int nb_sampl
>  
>      if (s->output_channels == 2 && s->input_channels == 1) {
>          mono_to_stereo(output, buftmp3[0], nb_samples1);
> -    } else if (s->output_channels == 2) {
> -        stereo_mux(output, buftmp3[0], buftmp3[1], nb_samples1);
> -    } else if (s->output_channels == 6) {
> +    } else if (s->output_channels == 6 && s->input_channels == 2) {
>          ac3_5p1_mux(output, buftmp3[0], buftmp3[1], nb_samples1);
> +    } else if (s->output_channels == s->input_channels && s->input_channels 
> >= 2) {
> +        interleave(output, buftmp3, s->output_channels, nb_samples1);
>      }
>  
>      if (s->sample_fmt[1] != AV_SAMPLE_FMT_S16) {
> @@ -348,19 +345,20 @@ int audio_resample(ReSampleContext *s, short *output, 
> short *input, int nb_sampl
>          }
>      }
>  
> -    for(i=0; i<s->filter_channels; i++)
> +    for (i = 0; i < s->filter_channels; i++) {
>          av_free(bufin[i]);
> +        av_free(bufout[i]);
> +    }
>  
> -    av_free(bufout[0]);
> -    av_free(bufout[1]);
>      return nb_samples1;
>  }
>  
>  void audio_resample_close(ReSampleContext *s)
>  {
> +    int i;
>      av_resample_close(s->resample_context);
> -    av_freep(&s->temp[0]);
> -    av_freep(&s->temp[1]);
> +    for (i = 0; i < s->filter_channels; i++)
> +        av_freep(&s->temp[i]);
>      av_freep(&s->buffer[0]);
>      av_freep(&s->buffer[1]);
>      av_audio_convert_free(s->convert_ctx[0]);


rest looks ok.

Thanks,
Justin
_______________________________________________
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to