From 59ad6c26aa6e46ff75615ce4e7b5bdb1dffec25c Mon Sep 17 00:00:00 2001 From: Carlos Rafael Giani Date: Mon, 28 Nov 2022 18:01:09 +0100 Subject: [PATCH] pw-cat: Add fallback for the older libavcodec channel layout API Signed-off-by: Carlos Rafael Giani --- src/tools/pw-cat.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/tools/pw-cat.c b/src/tools/pw-cat.c index fb5db0860..068fac19a 100644 --- a/src/tools/pw-cat.c +++ b/src/tools/pw-cat.c @@ -1278,6 +1278,7 @@ static int setup_encodedfile(struct data *data) { int ret; int bits_per_sample; + int num_channels; char path[256] = { 0 }; /* We do not support record with encoded media */ @@ -1317,14 +1318,22 @@ static int setup_encodedfile(struct data *data) printf("Number of streams: %d Codec id: %x\n", data->fmt_context->nb_streams, data->ctx->codec_id); + /* FFmpeg 5.1 (which contains libavcodec 59.37.100) introduced + * a new channel layout API and deprecated the old one. */ +#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(59, 37, 100) + num_channels = data->ctx->ch_layout.nb_channels; +#else + num_channels = data->ctx->channels; +#endif + data->rate = data->ctx->sample_rate; - data->channels = data->ctx->ch_layout.nb_channels; + data->channels = num_channels; data->sfmt = data->ctx->sample_fmt; data->stride = 1; // Don't care bits_per_sample = av_get_bits_per_sample(data->ctx->codec_id); data->bitrate = bits_per_sample ? - data->ctx->sample_rate * data->ctx->ch_layout.nb_channels * bits_per_sample : data->ctx->bit_rate; + data->ctx->sample_rate * num_channels * bits_per_sample : data->ctx->bit_rate; data->spa_format = SPA_AUDIO_FORMAT_ENCODED; data->fill = playback_fill_fn(data->spa_format);