[FFmpeg-devel] [PATCH 3/5] audioconvert: implement av_bprint_channel_layout().

Stefano Sabatini stefasab at gmail.com
Tue Jun 5 13:13:00 CEST 2012


On date Sunday 2012-06-03 21:44:48 +0200, Nicolas George encoded:
> And reimplement av_get_channel_layout_string() on top of it.
> 
> Signed-off-by: Nicolas George <nicolas.george at normalesup.org>
> ---
>  libavutil/audioconvert.c |   26 ++++++++++++++++++--------
>  libavutil/audioconvert.h |    6 ++++++
>  2 files changed, 24 insertions(+), 8 deletions(-)
> 
> diff --git a/libavutil/audioconvert.c b/libavutil/audioconvert.c
> index 877027f..7dc7e9f 100644
> --- a/libavutil/audioconvert.c
> +++ b/libavutil/audioconvert.c
> @@ -26,6 +26,7 @@
>  #include "avstring.h"
>  #include "avutil.h"
>  #include "audioconvert.h"
> +#include "bprint.h"
>  
>  static const char * const channel_names[] = {
>      [0]  = "FL",        /* front left */
> @@ -136,8 +137,8 @@ uint64_t av_get_channel_layout(const char *name)
>      return layout;
>  }
>  
> -void av_get_channel_layout_string(char *buf, int buf_size,
> -                                  int nb_channels, uint64_t channel_layout)
> +void av_bprint_channel_layout(struct AVBPrint *bp,
> +                              int nb_channels, uint64_t channel_layout)
>  {
>      int i;
>  
> @@ -147,29 +148,38 @@ void av_get_channel_layout_string(char *buf, int buf_size,
>      for (i = 0; i < FF_ARRAY_ELEMS(channel_layout_map); i++)
>          if (nb_channels    == channel_layout_map[i].nb_channels &&
>              channel_layout == channel_layout_map[i].layout) {
> -            av_strlcpy(buf, channel_layout_map[i].name, buf_size);
> +            av_bprintf(bp, "%s", channel_layout_map[i].name);
>              return;
>          }
>  
> -    snprintf(buf, buf_size, "%d channels", nb_channels);
> +    av_bprintf(bp, "%d channels", nb_channels);
>      if (channel_layout) {
>          int i, ch;
> -        av_strlcat(buf, " (", buf_size);
> +        av_bprintf(bp, " (");
>          for (i = 0, ch = 0; i < 64; i++) {
>              if ((channel_layout & (UINT64_C(1) << i))) {
>                  const char *name = get_channel_name(i);
>                  if (name) {
>                      if (ch > 0)
> -                        av_strlcat(buf, "+", buf_size);
> -                    av_strlcat(buf, name, buf_size);
> +                        av_bprintf(bp, "+");
> +                    av_bprintf(bp, "%s", name);
>                  }
>                  ch++;
>              }
>          }
> -        av_strlcat(buf, ")", buf_size);
> +        av_bprintf(bp, ")");
>      }
>  }
>  
> +void av_get_channel_layout_string(char *buf, int buf_size,
> +                                  int nb_channels, uint64_t channel_layout)
> +{
> +    AVBPrint bp;
> +
> +    av_bprint_init_for_buffer(&bp, buf, buf_size);
> +    av_bprint_channel_layout(&bp, nb_channels, channel_layout);
> +}
> +
>  int av_get_channel_layout_nb_channels(uint64_t channel_layout)
>  {
>      int count;
> diff --git a/libavutil/audioconvert.h b/libavutil/audioconvert.h
> index f402b62..c1be203 100644
> --- a/libavutil/audioconvert.h
> +++ b/libavutil/audioconvert.h
> @@ -134,6 +134,12 @@ uint64_t av_get_channel_layout(const char *name);
>  void av_get_channel_layout_string(char *buf, int buf_size, int nb_channels, uint64_t channel_layout);
>  

>  /**
> + * Append a description of a channel layout to a bprint buffer.
> + */
> +struct AVBPrint;
> +void av_bprint_channel_layout(struct AVBPrint *bp, int nb_channels, uint64_t channel_layout);

Move struct AVBprint up the doxy, so doxygen (and human reader as
well) won't get confused.

[...]

Looks fine otherwise.

What's the use case?
-- 
FFmpeg = Formidable Fabulous Minimalistic Pitiful ExchanGer


More information about the ffmpeg-devel mailing list