[FFmpeg-devel] [PATCH] Add the function libavcodec/utils.c:avcodec_type_string

Stefano Sabatini stefano.sabatini-lala
Fri Nov 9 15:26:22 CET 2007


On date Friday 2007-11-09 11:34:25 +0100, Stefano Sabatini encoded:
> On date Friday 2007-11-09 09:00:05 +0000, M?ns Rullg?rd encoded:
[...]
> > Why don't you declare the argument as type CodecType?  That should
> > make it abundantly clear what is expected.
> > 
> > Also, why do you use snprintf() here, when av_strlcpy() would do just
> > as well, or even simply returning the string constants.
> [...]
> 
> Yes, it looks like a simpler solution, which I prefer over the
> previous ones.
[...]
> Index: libavcodec/avcodec.h
> ===================================================================
> --- libavcodec/avcodec.h	(revision 10968)
> +++ libavcodec/avcodec.h	(working copy)
> @@ -33,8 +33,8 @@
>  #define AV_STRINGIFY(s)         AV_TOSTRING(s)
>  #define AV_TOSTRING(s) #s
>  
> -#define LIBAVCODEC_VERSION_INT  ((51<<16)+(48<<8)+0)
> -#define LIBAVCODEC_VERSION      51.48.0
> +#define LIBAVCODEC_VERSION_INT  ((51<<16)+(49<<8)+0)
> +#define LIBAVCODEC_VERSION      51.49.0
>  #define LIBAVCODEC_BUILD        LIBAVCODEC_VERSION_INT
>  
>  #define LIBAVCODEC_IDENT        "Lavc" AV_STRINGIFY(LIBAVCODEC_VERSION)
> @@ -2477,6 +2477,16 @@
>  void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode);
>  
>  /**
> + * Return a string corresponding to the codec type \p codec_type.
> + *
> + * @param codec_type[in] Codec type, currently supported are:
> + * CODEC_TYPE_VIDEO, CODEC_TYPE_AUDIO, CODEC_TYPE_DATA,
> + * CODEC_TYPE_SUBTITLE.
> + * @return Pointer to a static string representing the codec type.
> + */
> +char *avcodec_type_string (enum CodecType codec_type);
  ^^^^^^
I missed "const".

> +
> +/**
>   * Sets the fields of the given AVCodecContext to default values.
>   *
>   * @param s The AVCodecContext of which the fields should be set to default values.
> Index: libavcodec/utils.c
> ===================================================================
> --- libavcodec/utils.c	(revision 10968)
> +++ libavcodec/utils.c	(working copy)
> @@ -1230,6 +1230,21 @@
>      }
>  }
>  
> +static const char *codec_type_strings[] = {
> +    [CODEC_TYPE_VIDEO]    = "video",
> +    [CODEC_TYPE_AUDIO]    = "audio",
> +    [CODEC_TYPE_DATA]     = "data",
> +    [CODEC_TYPE_SUBTITLE] = "subtitle",
> +    [CODEC_TYPE_NB]       = "unknown"
> +};
> +
> +char *avcodec_type_string (enum CodecType codec_type)
  ^^^^^
Same here.

> +{
> +    if ((unsigned)codec_type>CODEC_TYPE_NB)
> +        codec_type = CODEC_TYPE_NB;
> +    return codec_type_strings[codec_type];
> +}
> +

I didn't noticed the compilation warning:
"return discards qualifiers from pointer target type"

caused by the fact that the expected returned type was "const char*" rather
than "char*".

Sorry for the noise.

Best regards.
-- 
Stefano Sabatini
Linux user number 337176 (see http://counter.li.org)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: add-avcodec-type-string-function-05.patch
Type: text/x-diff
Size: 1935 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20071109/57c96da5/attachment.patch>



More information about the ffmpeg-devel mailing list