diff mbox series

[FFmpeg-devel,3/4] avutil/channel_layout: do not copy alloc new map for extra channel layout

Message ID 20220315203013.14304-3-cus@passwd.hu
State New
Headers show
Series [FFmpeg-devel,1/4] avutil/channel_layout: print channels using av_channel_name_bprint in av_channel_layout_describe_bprint | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 fail Make fate failed
andriy/make_x86 success Make finished
andriy/make_fate_x86 fail Make fate failed

Commit Message

Marton Balint March 15, 2022, 8:30 p.m. UTC
Also use av_channel_layout_bprint directly for describing channel layout for
extra channels.

Signed-off-by: Marton Balint <cus@passwd.hu>
---
 libavutil/channel_layout.c | 16 +++-------------
 1 file changed, 3 insertions(+), 13 deletions(-)

Comments

James Almer March 15, 2022, 8:39 p.m. UTC | #1
On 3/15/2022 5:30 PM, Marton Balint wrote:
> Also use av_channel_layout_bprint directly for describing channel layout for
> extra channels.
> 
> Signed-off-by: Marton Balint <cus@passwd.hu>
> ---
>   libavutil/channel_layout.c | 16 +++-------------
>   1 file changed, 3 insertions(+), 13 deletions(-)
> 
> diff --git a/libavutil/channel_layout.c b/libavutil/channel_layout.c
> index fb2335a334..8406089fe0 100644
> --- a/libavutil/channel_layout.c
> +++ b/libavutil/channel_layout.c
> @@ -702,29 +702,19 @@ static int try_describe_ambisonic(AVBPrint *bp, const AVChannelLayout *channel_l
>       nb_ambi_channels = (order + 1) * (order + 1);
>       if (nb_ambi_channels < channel_layout->nb_channels) {
>           AVChannelLayout extra = { 0 };
> -        char buf[128];
>   
>           if (channel_layout->order == AV_CHANNEL_ORDER_AMBISONIC) {
>               extra.order       = AV_CHANNEL_ORDER_NATIVE;
>               extra.nb_channels = av_popcount64(channel_layout->u.mask);
>               extra.u.mask      = channel_layout->u.mask;
>           } else {
> -            const AVChannelCustom *map = channel_layout->u.map;
> -
>               extra.order       = AV_CHANNEL_ORDER_CUSTOM;
>               extra.nb_channels = channel_layout->nb_channels - nb_ambi_channels;
> -            extra.u.map       = av_calloc(extra.nb_channels, sizeof(*extra.u.map));
> -            if (!extra.u.map)
> -                return AVERROR(ENOMEM);
> -
> -            memcpy(extra.u.map, &map[nb_ambi_channels],
> -                   sizeof(*extra.u.map) * extra.nb_channels);
> +            extra.u.map       = channel_layout->u.map + nb_ambi_channels;
>           }
>   
> -        av_channel_layout_describe(&extra, buf, sizeof(buf));
> -        av_channel_layout_uninit(&extra);

Maybe add a comment that you're not calling uninit on extra because it 
doesn't own its AVChannelMap pointer.

> -
> -        av_bprintf(bp, "+%s", buf);
> +        av_bprint_chars(bp, '+', 1);
> +        av_channel_layout_describe_bprint(&extra, bp);
>       }
>   
>       return 0;
diff mbox series

Patch

diff --git a/libavutil/channel_layout.c b/libavutil/channel_layout.c
index fb2335a334..8406089fe0 100644
--- a/libavutil/channel_layout.c
+++ b/libavutil/channel_layout.c
@@ -702,29 +702,19 @@  static int try_describe_ambisonic(AVBPrint *bp, const AVChannelLayout *channel_l
     nb_ambi_channels = (order + 1) * (order + 1);
     if (nb_ambi_channels < channel_layout->nb_channels) {
         AVChannelLayout extra = { 0 };
-        char buf[128];
 
         if (channel_layout->order == AV_CHANNEL_ORDER_AMBISONIC) {
             extra.order       = AV_CHANNEL_ORDER_NATIVE;
             extra.nb_channels = av_popcount64(channel_layout->u.mask);
             extra.u.mask      = channel_layout->u.mask;
         } else {
-            const AVChannelCustom *map = channel_layout->u.map;
-
             extra.order       = AV_CHANNEL_ORDER_CUSTOM;
             extra.nb_channels = channel_layout->nb_channels - nb_ambi_channels;
-            extra.u.map       = av_calloc(extra.nb_channels, sizeof(*extra.u.map));
-            if (!extra.u.map)
-                return AVERROR(ENOMEM);
-
-            memcpy(extra.u.map, &map[nb_ambi_channels],
-                   sizeof(*extra.u.map) * extra.nb_channels);
+            extra.u.map       = channel_layout->u.map + nb_ambi_channels;
         }
 
-        av_channel_layout_describe(&extra, buf, sizeof(buf));
-        av_channel_layout_uninit(&extra);
-
-        av_bprintf(bp, "+%s", buf);
+        av_bprint_chars(bp, '+', 1);
+        av_channel_layout_describe_bprint(&extra, bp);
     }
 
     return 0;