[FFmpeg-devel] [PATCH] provide AV_BASE64_SIZE() macro

Stefano Sabatini stefano.sabatini-lala
Fri Jun 4 00:01:01 CEST 2010


On date Thursday 2010-06-03 13:50:06 -0700, Howard Chu encoded:
> Just for convenience...
> -- 
>   -- Howard Chu
>   CTO, Symas Corp.           http://www.symas.com
>   Director, Highland Sun     http://highlandsun.com/hyc/
>   Chief Architect, OpenLDAP  http://www.openldap.org/project/

> Index: libavcodec/libtheoraenc.c
> ===================================================================
> --- libavcodec/libtheoraenc.c	(revision 23437)
> +++ libavcodec/libtheoraenc.c	(working copy)
> @@ -101,7 +101,7 @@
>          memcpy(h->stats + h->stats_offset, buf, bytes);
>          h->stats_offset += bytes;
>      } else {
> -        int b64_size = ((h->stats_offset + 2) / 3) * 4 + 1;
> +        int b64_size = AV_BASE64_SIZE(h->stats_offset);
>          // libtheora generates a summary header at the end
>          memcpy(h->stats, buf, bytes);
>          avctx->stats_out = av_malloc(b64_size);
> Index: libavformat/httpauth.c
> ===================================================================
> --- libavformat/httpauth.c	(revision 23447)
> +++ libavformat/httpauth.c	(working copy)
> @@ -294,7 +294,7 @@
>          return NULL;
>  
>      if (state->auth_type == HTTP_AUTH_BASIC) {
> -        int auth_b64_len = (strlen(auth) + 2) / 3 * 4 + 1;
> +        int auth_b64_len = AV_BASE64_SIZE(strlen(auth));
>          int len = auth_b64_len + 30;
>          char *ptr;
>          authstr = av_malloc(len);
> Index: libavutil/base64.c
> ===================================================================
> --- libavutil/base64.c	(revision 23448)
> +++ libavutil/base64.c	(working copy)
> @@ -79,7 +79,7 @@
>      int bytes_remaining = in_size;
>  
>      if (in_size >= UINT_MAX / 4 ||
> -        out_size < (in_size+2) / 3 * 4 + 1)
> +        out_size < AV_BASE64_SIZE(in_size))
>          return NULL;
>      ret = dst = out;
>      while (bytes_remaining) {
> Index: libavutil/base64.h
> ===================================================================
> --- libavutil/base64.h	(revision 23437)
> +++ libavutil/base64.h	(working copy)
> @@ -46,4 +46,9 @@
>   */
>  char *av_base64_encode(char *out, int out_size, const uint8_t *in, int in_size);
>  
> +/**
> + * Calculate the out_size needed to base64 encode an in_size

I suggest:
Calculates the output size in bytes needed to base64-encode x bytes.

> + */
> +#define AV_BASE64_SIZE(x)  (((x)+2) / 3 * 4 + 1)
> +
>  #endif /* AVUTIL_BASE64_H */

Regards.
-- 
FFmpeg = Free and Funny Marvellous Powered Exuberant Gem



More information about the ffmpeg-devel mailing list