[FFmpeg-devel] [PATCH 01/10] lavu: add av_fourcc_make_string() and av_4cc2str()

James Almer jamrial at gmail.com
Mon Mar 27 17:16:24 EEST 2017


On 3/27/2017 4:51 AM, Clément Bœsch wrote:
> ---
>  doc/APIchanges      |  4 ++++
>  libavutil/avutil.h  | 14 ++++++++++++++
>  libavutil/utils.c   | 21 +++++++++++++++++++++
>  libavutil/version.h |  2 +-
>  4 files changed, 40 insertions(+), 1 deletion(-)
> 
> diff --git a/doc/APIchanges b/doc/APIchanges
> index 6aaa9adceb..4736e3e6fc 100644
> --- a/doc/APIchanges
> +++ b/doc/APIchanges
> @@ -15,6 +15,10 @@ libavutil:     2015-08-28
>  
>  API changes, most recent first:
>  
> +2017-03-xx - xxxxxxx - lavu 55.52.100 - avutil.h
> +  add av_fourcc_make_string() function and av_4cc2str() macro to replace
> +  av_get_codec_tag_string() from lavc.
> +
>  2017-03-xx - xxxxxxx - lavc 57.85.101 - avcodec.h
>    vdpau hardware accelerated decoding now supports the new hwaccel API, which
>    can create the decoder context and allocate hardware frame automatically.
> diff --git a/libavutil/avutil.h b/libavutil/avutil.h
> index e9aaa03722..98100fdcc5 100644
> --- a/libavutil/avutil.h
> +++ b/libavutil/avutil.h
> @@ -343,6 +343,20 @@ FILE *av_fopen_utf8(const char *path, const char *mode);
>   */
>  AVRational av_get_time_base_q(void);
>  
> +#define AV_FOURCC_MAX_STRING_SIZE 32
> +
> +#define av_4cc2str(fourcc) av_fourcc_make_string((char[AV_FOURCC_MAX_STRING_SIZE]){0}, fourcc)
> +
> +/**
> + * Fill the provided buffer with a string containing a FourCC (four-character
> + * code) representation.
> + *
> + * @param buf    a buffer with size in bytes of at least AV_FOURCC_MAX_STRING_SIZE
> + * @param fourcc the fourcc to represent
> + * @return the buffer in input
> + */
> +char *av_fourcc_make_string(char *buf, uint32_t fourcc);

Maybe this could go in avstring.h instead.

> +
>  /**
>   * @}
>   * @}
> diff --git a/libavutil/utils.c b/libavutil/utils.c
> index 36e4dd5fdb..ba557b9252 100644
> --- a/libavutil/utils.c
> +++ b/libavutil/utils.c
> @@ -121,6 +121,27 @@ unsigned av_int_list_length_for_size(unsigned elsize,
>      return i;
>  }
>  
> +char *av_fourcc_make_string(char *buf, uint32_t fourcc)
> +{
> +    int i, len;
> +    char *orig_buf = buf;
> +    size_t buf_size = AV_FOURCC_MAX_STRING_SIZE;
> +
> +#define TAG_PRINT(x)                                              \
> +    (((x) >= '0' && (x) <= '9') ||                                \
> +     ((x) >= 'a' && (x) <= 'z') || ((x) >= 'A' && (x) <= 'Z') ||  \
> +     ((x) == '.' || (x) == ' ' || (x) == '-' || (x) == '_'))
> +
> +    for (i = 0; i < 4; i++) {
> +        len = snprintf(buf, buf_size,
> +                       TAG_PRINT(fourcc & 0xFF) ? "%c" : "[%d]", fourcc & 0xFF);
> +        buf       += len;
> +        buf_size   = buf_size > len ? buf_size - len : 0;
> +        fourcc   >>= 8;
> +    }
> +    return orig_buf;
> +}
> +
>  AVRational av_get_time_base_q(void)
>  {
>      return (AVRational){1, AV_TIME_BASE};
> diff --git a/libavutil/version.h b/libavutil/version.h
> index 3c86c26638..d6d78e7dc2 100644
> --- a/libavutil/version.h
> +++ b/libavutil/version.h
> @@ -79,7 +79,7 @@
>   */
>  
>  #define LIBAVUTIL_VERSION_MAJOR  55
> -#define LIBAVUTIL_VERSION_MINOR  51
> +#define LIBAVUTIL_VERSION_MINOR  52
>  #define LIBAVUTIL_VERSION_MICRO 100
>  
>  #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
> 



More information about the ffmpeg-devel mailing list