[FFmpeg-devel] [PATCH] Initialize PCM conversion tables just once.

Måns Rullgård mans
Wed Jan 9 02:23:11 CET 2008


flameeyes at gmail.com (Diego 'Flameeyes' Petten?) writes:

> flameeyes at gmail.com (Diego 'Flameeyes' Petten?) writes:
>
>> This should also reduce the size of the PCMDecode structures hanging
>> around.
>
> Sigh. The right patch this time.
>
> Share the tables used to convert from alaw and ulaw to linear.
>
> From: Diego 'Flameeyes' Petten?? <flameeyes at gmail.com>
>
>
> ---
>
>  libavcodec/pcm.c |   17 ++++++++++++-----
>  1 files changed, 12 insertions(+), 5 deletions(-)
>
>
> diff --git a/libavcodec/pcm.c b/libavcodec/pcm.c
> index c7a7e82..ffc9eac 100644
> --- a/libavcodec/pcm.c
> +++ b/libavcodec/pcm.c
> @@ -321,8 +321,11 @@ static int pcm_encode_frame(AVCodecContext *avctx,
>      return dst - frame;
>  }
>  
> +static short alaw2linear_table[256];
> +static short ulaw2linear_table[256];
> +
>  typedef struct PCMDecode {
> -    short table[256];
> +    short *table;
>  } PCMDecode;
>  
>  static int pcm_decode_init(AVCodecContext * avctx)
> @@ -332,12 +335,16 @@ static int pcm_decode_init(AVCodecContext * avctx)
>  
>      switch(avctx->codec->id) {
>      case CODEC_ID_PCM_ALAW:
> -        for(i=0;i<256;i++)
> -            s->table[i] = alaw2linear(i);
> +        if ( alaw2linear_table[255] == 0 )

if (!alaw2linear_table[255])

Mind those spaces.  You all (should) know I hate them.

> +            for(i=0;i<256;i++)
> +                alaw2linear_table[i] = alaw2linear(i);
> +	s->table = alaw2linear_table;
>          break;
>      case CODEC_ID_PCM_MULAW:
> -        for(i=0;i<256;i++)
> -            s->table[i] = ulaw2linear(i);
> +        if ( ulaw2linear_table[255] == 0 )

Same.

> +  	    for(i=0;i<256;i++)
> +                ulaw2linear_table[i] = ulaw2linear(i);
> +	s->table = ulaw2linear_table;
>          break;
>      default:
>          break;

-- 
M?ns Rullg?rd
mans at mansr.com




More information about the ffmpeg-devel mailing list