[FFmpeg-devel] [PATCH] rl.h: Allocate temporary VLC tables instead of having them static.

Michael Niedermayer michaelni at gmx.at
Mon Sep 1 02:35:11 CEST 2014


On Sun, Aug 31, 2014 at 08:27:17PM +0200, Reimar Döffinger wrote:
> Signed-off-by: Reimar Döffinger <Reimar.Doeffinger at gmx.de>
> ---
>  libavcodec/mpeg12.c    | 23 ++++++++++++-----------
>  libavcodec/mpegvideo.c | 14 ++++++++++----
>  libavcodec/rl.h        |  8 ++------
>  3 files changed, 24 insertions(+), 21 deletions(-)
> 
> diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c
> index cb00baf..769bed7 100644
> --- a/libavcodec/mpeg12.c
> +++ b/libavcodec/mpeg12.c
> @@ -70,22 +70,22 @@ static const uint8_t table_mb_btype[11][2] = {
>  #define INIT_2D_VLC_RL(rl, static_size)\
>  {\
>      static RL_VLC_ELEM rl_vlc_table[static_size];\
> -    VLC tmp_vlc;\
> -    INIT_VLC_STATIC(&tmp_vlc, TEX_VLC_BITS, rl.n + 2,\
> -                    &rl.table_vlc[0][1], 4, 2,\
> -                    &rl.table_vlc[0][0], 4, 2, static_size);\
> -\
>      rl.rl_vlc[0] = rl_vlc_table;\
> -    init_2d_vlc_rl(&rl, &tmp_vlc);\
> +    init_2d_vlc_rl(&rl, static_size);\
>  }
>  
> -static av_cold void init_2d_vlc_rl(RLTable *rl, const VLC *vlc)
> +static av_cold void init_2d_vlc_rl(RLTable *rl, unsigned static_size)
>  {
>      int i;
> -
> -    for (i = 0; i < vlc->table_size; i++) {
> -        int code = vlc->table[i][0];
> -        int len  = vlc->table[i][1];
> +    VLC vlc;

> +    init_vlc(&vlc, TEX_VLC_BITS, rl->n + 2, &rl->table_vlc[0][1], 4, 2, &rl->table_vlc[0][0], 4, 2, 0);

this can fail with memory allocation failure and would require
handling that in all callers


> +    av_assert0(vlc.table_size <= static_size);
> +    if (vlc.table_size != static_size)
> +        av_log(NULL, AV_LOG_ERROR, "needed %d had %d\n", vlc.table_size, static_size);
> +
> +    for (i = 0; i < vlc.table_size; i++) {
> +        int code = vlc.table[i][0];
> +        int len  = vlc.table[i][1];
>          int level, run;
>  
>          if (len == 0) { // illegal code
> @@ -110,6 +110,7 @@ static av_cold void init_2d_vlc_rl(RLTable *rl, const VLC *vlc)
>          rl->rl_vlc[0][i].level = level;
>          rl->rl_vlc[0][i].run   = run;
>      }
> +    ff_free_vlc(&vlc);
>  }
>  
>  av_cold void ff_mpeg12_common_init(MpegEncContext *s)
> diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
> index 748dbc8..94e000f 100644
> --- a/libavcodec/mpegvideo.c
> +++ b/libavcodec/mpegvideo.c
> @@ -1618,9 +1618,14 @@ av_cold void ff_init_rl(RLTable *rl,
>      }
>  }
>  
> -av_cold void ff_init_vlc_rl(RLTable *rl, const VLC *vlc)
> +av_cold void ff_init_vlc_rl(RLTable *rl, unsigned static_size)
>  {
>      int i, q;
> +    VLC vlc;

> +    init_vlc(&vlc, 9, rl->n + 1, &rl->table_vlc[0][1], 4, 2, &rl->table_vlc[0][0], 4, 2, 0);

same issue here

why do you change the code to dynamically allocate ?


[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

What does censorship reveal? It reveals fear. -- Julian Assange
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20140901/9df3edf6/attachment.asc>


More information about the ffmpeg-devel mailing list