diff mbox series

[FFmpeg-devel,027/281] apc: convert to new channel layout API

Message ID 20220113015101.4-28-jamrial@gmail.com
State New
Headers show
Series New channel layout API | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished
andriy/make_aarch64_jetson success Make finished
andriy/make_fate_aarch64_jetson success Make fate finished
andriy/make_armv7_RPi4 success Make finished
andriy/make_fate_armv7_RPi4 success Make fate finished

Commit Message

James Almer Jan. 13, 2022, 1:49 a.m. UTC
From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/apc.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

Comments

Anton Khirnov Jan. 26, 2022, 1:41 p.m. UTC | #1
Quoting James Almer (2022-01-13 02:49:49)
> From: Vittorio Giovara <vittorio.giovara@gmail.com>
> 
> Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libavformat/apc.c | 12 ++++--------
>  1 file changed, 4 insertions(+), 8 deletions(-)
> 
> diff --git a/libavformat/apc.c b/libavformat/apc.c
> index 56151bb59a..192e115278 100644
> --- a/libavformat/apc.c
> +++ b/libavformat/apc.c
> @@ -38,6 +38,7 @@ static int apc_read_header(AVFormatContext *s)
>      AVIOContext *pb = s->pb;
>      AVStream *st;
>      int ret;
> +    int channels;
>  
>      avio_rl32(pb); /* CRYO */
>      avio_rl32(pb); /* _APC */
> @@ -57,16 +58,11 @@ static int apc_read_header(AVFormatContext *s)
>      if ((ret = ff_get_extradata(s, st->codecpar, pb, 2 * 4)) < 0)
>          return ret;
>  
> -    if (avio_rl32(pb)) {
> -        st->codecpar->channels       = 2;
> -        st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO;
> -    } else {
> -        st->codecpar->channels       = 1;
> -        st->codecpar->channel_layout = AV_CH_LAYOUT_MONO;
> -    }
> +    channels = avio_rl32(pb) + 1;

This changes behavior in case the value read is > 1. No idea if that
ever happens, but still better make it !!avio_rl32.
diff mbox series

Patch

diff --git a/libavformat/apc.c b/libavformat/apc.c
index 56151bb59a..192e115278 100644
--- a/libavformat/apc.c
+++ b/libavformat/apc.c
@@ -38,6 +38,7 @@  static int apc_read_header(AVFormatContext *s)
     AVIOContext *pb = s->pb;
     AVStream *st;
     int ret;
+    int channels;
 
     avio_rl32(pb); /* CRYO */
     avio_rl32(pb); /* _APC */
@@ -57,16 +58,11 @@  static int apc_read_header(AVFormatContext *s)
     if ((ret = ff_get_extradata(s, st->codecpar, pb, 2 * 4)) < 0)
         return ret;
 
-    if (avio_rl32(pb)) {
-        st->codecpar->channels       = 2;
-        st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO;
-    } else {
-        st->codecpar->channels       = 1;
-        st->codecpar->channel_layout = AV_CH_LAYOUT_MONO;
-    }
+    channels = avio_rl32(pb) + 1;
+    av_channel_layout_default(&st->codecpar->ch_layout, channels);
 
     st->codecpar->bits_per_coded_sample = 4;
-    st->codecpar->bit_rate = (int64_t)st->codecpar->bits_per_coded_sample * st->codecpar->channels
+    st->codecpar->bit_rate = (int64_t)st->codecpar->bits_per_coded_sample * channels
                           * st->codecpar->sample_rate;
     st->codecpar->block_align = 1;