[FFmpeg-devel] [RFC] lavc add const, code cleanup

Michael Niedermayer michaelni
Sun Aug 24 21:50:40 CEST 2008


On Sun, Aug 24, 2008 at 09:10:12PM +0200, Reimar D?ffinger wrote:
> Hello,
> it started out as adding a few consts, but there was some IMO ugly code
> I noticed.
> I know it should be split, and I will before applying, but after looking
> at such a load of code I do not have the motivation.

> I would be glad if the respective maintainers would apply whatever they
> like.

i have a bad feeling about this going to work out

anyway, parts iam ok with below


[...]
> diff --git a/libavcodec/adxenc.c b/libavcodec/adxenc.c
> index 6bce31a..cc1eff5 100644
> --- a/libavcodec/adxenc.c
> +++ b/libavcodec/adxenc.c
> @@ -190,6 +190,6 @@ AVCodec adpcm_adx_encoder = {
>      adx_encode_frame,
>      adx_encode_close,
>      NULL,
> -    .sample_fmts = (enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE},
> +    .sample_fmts = (const enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE},
>      .long_name = NULL_IF_CONFIG_SMALL("SEGA CRI ADX"),
>  };

ok


[...]
> diff --git a/libavcodec/asv1.c b/libavcodec/asv1.c
> index f7ef68e..60eec46 100644
> --- a/libavcodec/asv1.c
> +++ b/libavcodec/asv1.c
> @@ -641,7 +641,7 @@ AVCodec asv1_encoder = {
>      encode_init,
>      encode_frame,
>      //encode_end,
> -    .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
> +    .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
>      .long_name= NULL_IF_CONFIG_SMALL("ASUS V1"),
>  };
>  
> @@ -653,7 +653,7 @@ AVCodec asv2_encoder = {
>      encode_init,
>      encode_frame,
>      //encode_end,
> -    .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
> +    .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
>      .long_name= NULL_IF_CONFIG_SMALL("ASUS V2"),
>  };
>  

ok, also all similar changes to other files


[...]

> diff --git a/libavcodec/cyuv.c b/libavcodec/cyuv.c
> index d64f6df..2cfe7b3 100644
> --- a/libavcodec/cyuv.c
> +++ b/libavcodec/cyuv.c
> @@ -163,13 +163,6 @@ static int cyuv_decode_frame(AVCodecContext *avctx,
>      return buf_size;
>  }
>  
> -static av_cold int cyuv_decode_end(AVCodecContext *avctx)
> -{
> -/*    CyuvDecodeContext *s = avctx->priv_data;*/
> -
> -    return 0;
> -}
> -
>  AVCodec cyuv_decoder = {
>      "cyuv",
>      CODEC_TYPE_VIDEO,
> @@ -177,7 +170,7 @@ AVCodec cyuv_decoder = {
>      sizeof(CyuvDecodeContext),
>      cyuv_decode_init,
>      NULL,
> -    cyuv_decode_end,
> +    NULL,
>      cyuv_decode_frame,
>      CODEC_CAP_DR1,
>      NULL,

ok


> diff --git a/libavcodec/dct-test.c b/libavcodec/dct-test.c
> index f3f9408..8a4eb44 100644
> --- a/libavcodec/dct-test.c
> +++ b/libavcodec/dct-test.c
> @@ -42,8 +42,6 @@
>  #undef printf
>  #undef random
>  
> -void *fast_memcpy(void *a, const void *b, size_t c){return memcpy(a,b,c);};
> -
>  /* reference fdct/idct */
>  extern void fdct(DCTELEM *block);
>  extern void idct(DCTELEM *block);
> @@ -80,7 +78,7 @@ struct algo {
>  
>  static int cpu_flags;
>  
> -struct algo algos[] = {
> +static const struct algo algos[] = {
>    {"REF-DBL",         0, fdct,               fdct, NO_PERM},
>    {"FAAN",            0, ff_faandct,         fdct, FAAN_SCALE},
>    {"FAANI",           1, ff_faanidct,        idct, NO_PERM},

ok


[...]
> diff --git a/libavcodec/fdctref.c b/libavcodec/fdctref.c
> index c6a057b..bf6b85c 100644
> --- a/libavcodec/fdctref.c
> +++ b/libavcodec/fdctref.c
> @@ -29,15 +29,7 @@
>   * design.
>   */
>  
> -#include <math.h>
> -
> -#ifndef PI
> -# ifdef M_PI
> -#  define PI M_PI
> -# else
> -#  define PI 3.14159265358979323846
> -# endif
> -#endif

> +#include "mathematics.h"

libavutil/mathematics.h


>  
>  /* global declarations */
>  void init_fdct (void);
> @@ -56,7 +48,7 @@ void init_fdct()
>      s = (i==0) ? sqrt(0.125) : 0.5;
>  
>      for (j=0; j<8; j++)
> -      c[i][j] = s * cos((PI/8.0)*i*(j+0.5));
> +      c[i][j] = s * cos((M_PI/8.0)*i*(j+0.5));
>    }
>  }
>  
[...]
> diff --git a/libavcodec/libamr.c b/libavcodec/libamr.c
> index 4f56e4d..9b1cb68 100644
> --- a/libavcodec/libamr.c
> +++ b/libavcodec/libamr.c
> @@ -97,7 +97,8 @@ typedef struct AMR_bitrates
>  static int getBitrateMode(int bitrate)
>  {
>      /* make the correspondance between bitrate and mode */
> -    AMR_bitrates rates[]={ {4750,MR475},
> +    static const AMR_bitrates rates[]={
> +                           {4750,MR475},
>                             {5150,MR515},
>                             {5900,MR59},
>                             {6700,MR67},
> @@ -517,7 +518,7 @@ AVCodec libamr_nb_encoder =
>      amr_nb_encode_frame,
>      amr_nb_encode_close,
>      NULL,
> -    .sample_fmts = (enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE},
> +    .sample_fmts = (const enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE},
>      .long_name = NULL_IF_CONFIG_SMALL("libamr-nb Adaptive Multi-Rate (AMR) Narrow-Band"),
>  };
>  
> @@ -545,7 +546,8 @@ typedef struct AMRWB_bitrates
>  static int getWBBitrateMode(int bitrate)
>  {
>      /* make the correspondance between bitrate and mode */
> -    AMRWB_bitrates rates[]={ {6600,0},
> +    static const AMRWB_bitrates rates[]={
> +                           {6600,0},
>                             {8850,1},
>                             {12650,2},
>                             {14250,3},
> @@ -712,7 +714,7 @@ AVCodec libamr_wb_encoder =
>      amr_wb_encode_frame,
>      amr_wb_encode_close,
>      NULL,
> -    .sample_fmts = (enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE},
> +    .sample_fmts = (const enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE},
>      .long_name = NULL_IF_CONFIG_SMALL("libamr-wb Adaptive Multi-Rate (AMR) Wide-Band"),
>  };
>  

ok

[...]
> diff --git a/libavcodec/libtheoraenc.c b/libavcodec/libtheoraenc.c
> index d7f635c..e2f365f 100644
> --- a/libavcodec/libtheoraenc.c
> +++ b/libavcodec/libtheoraenc.c
> @@ -264,8 +264,6 @@ static int encode_close(AVCodecContext* avc_context)
>      return -1;
>  }
>  
> -static const enum PixelFormat supported_pixel_formats[] = { PIX_FMT_YUV420P, PIX_FMT_NONE };
> -
>  /*! AVCodec struct exposed to libavcodec */
>  AVCodec libtheora_encoder =
>  {
> @@ -276,6 +274,6 @@ AVCodec libtheora_encoder =
>      .init = encode_init,
>      .close = encode_close,
>      .encode = encode_frame,
> -    .pix_fmts = supported_pixel_formats,
> +    .pix_fmts = (const enum PixelFormat[]){ PIX_FMT_YUV420P, PIX_FMT_NONE },
>      .long_name = NULL_IF_CONFIG_SMALL("libtheora Theora"),
>  };

ok

[...]
> diff --git a/libavcodec/msmpeg4data.c b/libavcodec/msmpeg4data.c
> index c0bb953..2b6e670 100644
> --- a/libavcodec/msmpeg4data.c
> +++ b/libavcodec/msmpeg4data.c
> @@ -1979,7 +1979,7 @@ static const uint32_t table_mb_non_intra4[128][2] = {
>  {0x000011,  5}, {0x0001AC,  9}, {0x0000F3,  8}, {0x000439, 11},
>  };
>  
> -const uint32_t (*wmv2_inter_table[WMV2_INTER_CBP_TABLE_COUNT])[2]={
> +const uint32_t (* const wmv2_inter_table[WMV2_INTER_CBP_TABLE_COUNT])[2]={
>      table_mb_non_intra2,
>      table_mb_non_intra3,
>      table_mb_non_intra4,
> diff --git a/libavcodec/msmpeg4data.h b/libavcodec/msmpeg4data.h
> index 0234027..1d36057 100644
> --- a/libavcodec/msmpeg4data.h
> +++ b/libavcodec/msmpeg4data.h
> @@ -91,7 +91,7 @@ extern const uint32_t ff_table0_dc_chroma[120][2];
>  extern const uint32_t ff_table1_dc_chroma[120][2];
>  
>  #define WMV2_INTER_CBP_TABLE_COUNT 4
> -extern const uint32_t (*wmv2_inter_table[WMV2_INTER_CBP_TABLE_COUNT])[2];
> +extern const uint32_t (* const wmv2_inter_table[WMV2_INTER_CBP_TABLE_COUNT])[2];
>  
>  extern const uint8_t wmv2_scantableA[64];
>  extern const uint8_t wmv2_scantableB[64];

ok

[...]
> diff --git a/libavcodec/ulti.c b/libavcodec/ulti.c
> index d2608d5..986fd09 100644
> --- a/libavcodec/ulti.c
> +++ b/libavcodec/ulti.c
> @@ -393,13 +393,6 @@ static int ulti_decode_frame(AVCodecContext *avctx,
>      return buf_size;
>  }
>  
> -static av_cold int ulti_decode_end(AVCodecContext *avctx)
> -{
> -/*    UltimotionDecodeContext *s = avctx->priv_data;*/
> -
> -    return 0;
> -}
> -
>  AVCodec ulti_decoder = {
>      "ultimotion",
>      CODEC_TYPE_VIDEO,
> @@ -407,7 +400,7 @@ AVCodec ulti_decoder = {
>      sizeof(UltimotionDecodeContext),
>      ulti_decode_init,
>      NULL,
> -    ulti_decode_end,
> +    NULL,
>      ulti_decode_frame,
>      CODEC_CAP_DR1,
>      NULL,

ok


[...]

> diff --git a/libavcodec/vp3.c b/libavcodec/vp3.c
> index 3c06fe4..0d5b7f8 100644
> --- a/libavcodec/vp3.c
> +++ b/libavcodec/vp3.c
> @@ -354,25 +354,25 @@ static int init_block_mapping(Vp3DecodeContext *s)
>      int current_macroblock;
>      int c_fragment;
>  
> -    signed char travel_width[16] = {
> +    static const int8_t travel_width[16] = {
>           1,  1,  0, -1,
>           0,  0,  1,  0,
>           1,  0,  1,  0,
>           0, -1,  0,  1
>      };
>  
> -    signed char travel_height[16] = {
> +    static const int8_t travel_height[16] = {
>           0,  0,  1,  0,
>           1,  1,  0, -1,
>           0,  1,  0, -1,
>          -1,  0, -1,  0
>      };
>  
> -    signed char travel_width_mb[4] = {
> +    static const int8_t travel_width_mb[4] = {
>           1,  0,  1,  0
>      };
>  
> -    signed char travel_height_mb[4] = {
> +    static const int8_t travel_height_mb[4] = {
>           0,  1,  0, -1
>      };
>  
> @@ -1348,7 +1348,7 @@ static void reverse_dc_prediction(Vp3DecodeContext *s,
>       *   2: up-right multiplier
>       *   3: left multiplier
>       */
> -    int predictor_transform[16][4] = {
> +    static const int predictor_transform[16][4] = {
>          {  0,  0,  0,  0},
>          {  0,  0,  0,128},        // PL
>          {  0,  0,128,  0},        // PUR
> @@ -1373,7 +1373,7 @@ static void reverse_dc_prediction(Vp3DecodeContext *s,
>       * from other INTRA blocks. There are 2 golden frame coding types;
>       * blocks encoding in these modes can only predict from other blocks
>       * that were encoded with these 1 of these 2 modes. */
> -    unsigned char compatible_frame[8] = {
> +    static const uint8_t compatible_frame[8] = {
>          1,    /* MODE_INTER_NO_MV */
>          0,    /* MODE_INTRA */
>          1,    /* MODE_INTER_PLUS_MV */

this is ok if the code never writes into these tables ...


[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Republics decline into democracies and democracies degenerate into
despotisms. -- Aristotle
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20080824/c2ea665f/attachment.pgp>



More information about the ffmpeg-devel mailing list