[FFmpeg-devel] [PATCH 032/281] ast: convert to new channel layout API

James Almer jamrial at gmail.com
Thu Jan 13 03:49:54 EET 2022


From: Anton Khirnov <anton at khirnov.net>

Signed-off-by: James Almer <jamrial at gmail.com>
---
 libavformat/astdec.c | 18 ++++++++++--------
 libavformat/astenc.c |  4 ++--
 2 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/libavformat/astdec.c b/libavformat/astdec.c
index 629372acf1..3d460ce827 100644
--- a/libavformat/astdec.c
+++ b/libavformat/astdec.c
@@ -57,14 +57,15 @@ static int ast_read_header(AVFormatContext *s)
         return AVERROR_INVALIDDATA;
     }
 
-    st->codecpar->channels = avio_rb16(s->pb);
-    if (!st->codecpar->channels)
+    st->codecpar->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+    st->codecpar->ch_layout.nb_channels = avio_rb16(s->pb);
+    if (!st->codecpar->ch_layout.nb_channels)
         return AVERROR_INVALIDDATA;
 
-    if (st->codecpar->channels == 2)
-        st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO;
-    else if (st->codecpar->channels == 4)
-        st->codecpar->channel_layout = AV_CH_LAYOUT_4POINT0;
+    if (st->codecpar->ch_layout.nb_channels == 2)
+        st->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
+    else if (st->codecpar->ch_layout.nb_channels == 4)
+        st->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_4POINT0;
 
     avio_skip(s->pb, 2);
     st->codecpar->sample_rate = avio_rb32(s->pb);
@@ -90,10 +91,11 @@ static int ast_read_packet(AVFormatContext *s, AVPacket *pkt)
     pos  = avio_tell(s->pb);
     type = avio_rl32(s->pb);
     size = avio_rb32(s->pb);
-    if (!s->streams[0]->codecpar->channels || size > INT_MAX / s->streams[0]->codecpar->channels)
+    if (!s->streams[0]->codecpar->ch_layout.nb_channels ||
+        size > INT_MAX / s->streams[0]->codecpar->ch_layout.nb_channels)
         return AVERROR_INVALIDDATA;
 
-    size *= s->streams[0]->codecpar->channels;
+    size *= s->streams[0]->codecpar->ch_layout.nb_channels;
     if ((ret = avio_skip(s->pb, 24)) < 0) // padding
         return ret;
 
diff --git a/libavformat/astenc.c b/libavformat/astenc.c
index a5792e0b07..b29cfc4aaf 100644
--- a/libavformat/astenc.c
+++ b/libavformat/astenc.c
@@ -84,7 +84,7 @@ static int ast_write_header(AVFormatContext *s)
     avio_wb32(pb, 0); /* File size minus header */
     avio_wb16(pb, codec_tag);
     avio_wb16(pb, 16); /* Bit depth */
-    avio_wb16(pb, par->channels);
+    avio_wb16(pb, par->ch_layout.nb_channels);
     avio_wb16(pb, 0); /* Loop flag */
     avio_wb32(pb, par->sample_rate);
 
@@ -109,7 +109,7 @@ static int ast_write_packet(AVFormatContext *s, AVPacket *pkt)
     AVIOContext *pb = s->pb;
     ASTMuxContext *ast = s->priv_data;
     AVCodecParameters *par = s->streams[0]->codecpar;
-    int size = pkt->size / par->channels;
+    int size = pkt->size / par->ch_layout.nb_channels;
 
     if (s->streams[0]->nb_frames == 0)
         ast->fbs = size;
-- 
2.34.1



More information about the ffmpeg-devel mailing list