[FFmpeg-devel] [PATCH 151/281] sox: convert to new channel layout API
James Almer
jamrial at gmail.com
Thu Jan 13 03:59:58 EET 2022
From: Vittorio Giovara <vittorio.giovara at gmail.com>
Signed-off-by: Vittorio Giovara <vittorio.giovara at gmail.com>
Signed-off-by: James Almer <jamrial at gmail.com>
---
libavformat/soxdec.c | 14 +++++++++-----
libavformat/soxenc.c | 4 ++--
2 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/libavformat/soxdec.c b/libavformat/soxdec.c
index 83fb5e3758..c747cdb9eb 100644
--- a/libavformat/soxdec.c
+++ b/libavformat/soxdec.c
@@ -49,6 +49,7 @@ static int sox_read_header(AVFormatContext *s)
AVIOContext *pb = s->pb;
unsigned header_size, comment_size;
double sample_rate, sample_rate_frac;
+ int channels;
AVStream *st;
st = avformat_new_stream(s, NULL);
@@ -62,17 +63,20 @@ static int sox_read_header(AVFormatContext *s)
header_size = avio_rl32(pb);
avio_skip(pb, 8); /* sample count */
sample_rate = av_int2double(avio_rl64(pb));
- st->codecpar->channels = avio_rl32(pb);
+ channels = avio_rl32(pb);
comment_size = avio_rl32(pb);
} else {
st->codecpar->codec_id = AV_CODEC_ID_PCM_S32BE;
header_size = avio_rb32(pb);
avio_skip(pb, 8); /* sample count */
sample_rate = av_int2double(avio_rb64(pb));
- st->codecpar->channels = avio_rb32(pb);
+ channels = avio_rb32(pb);
comment_size = avio_rb32(pb);
}
+ st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+ st->codecpar->ch_layout.nb_channels = channels;
+
if (comment_size > 0xFFFFFFFFU - SOX_FIXED_HDR - 4U) {
av_log(s, AV_LOG_ERROR, "invalid comment size (%u)\n", comment_size);
return AVERROR_INVALIDDATA;
@@ -90,7 +94,7 @@ static int sox_read_header(AVFormatContext *s)
sample_rate_frac);
if ((header_size + 4) & 7 || header_size < SOX_FIXED_HDR + comment_size
- || st->codecpar->channels > 65535 || st->codecpar->channels <= 0) /* Reserve top 16 bits */ {
+ || channels > 65535 || channels <= 0) /* Reserve top 16 bits */ {
av_log(s, AV_LOG_ERROR, "invalid header\n");
return AVERROR_INVALIDDATA;
}
@@ -115,9 +119,9 @@ static int sox_read_header(AVFormatContext *s)
st->codecpar->bits_per_coded_sample = 32;
st->codecpar->bit_rate = (int64_t)st->codecpar->sample_rate *
st->codecpar->bits_per_coded_sample *
- st->codecpar->channels;
+ channels;
st->codecpar->block_align = st->codecpar->bits_per_coded_sample *
- st->codecpar->channels / 8;
+ channels / 8;
avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
diff --git a/libavformat/soxenc.c b/libavformat/soxenc.c
index e24501bacd..ac01f97df5 100644
--- a/libavformat/soxenc.c
+++ b/libavformat/soxenc.c
@@ -61,14 +61,14 @@ static int sox_write_header(AVFormatContext *s)
avio_wl32(pb, sox->header_size);
avio_wl64(pb, 0); /* number of samples */
avio_wl64(pb, av_double2int(par->sample_rate));
- avio_wl32(pb, par->channels);
+ avio_wl32(pb, par->ch_layout.nb_channels);
avio_wl32(pb, comment_size);
} else if (par->codec_id == AV_CODEC_ID_PCM_S32BE) {
ffio_wfourcc(pb, "XoS.");
avio_wb32(pb, sox->header_size);
avio_wb64(pb, 0); /* number of samples */
avio_wb64(pb, av_double2int(par->sample_rate));
- avio_wb32(pb, par->channels);
+ avio_wb32(pb, par->ch_layout.nb_channels);
avio_wb32(pb, comment_size);
} else {
av_log(s, AV_LOG_ERROR, "invalid codec; use pcm_s32le or pcm_s32be\n");
--
2.34.1
More information about the ffmpeg-devel
mailing list