From cefca79700bdadd32d759ce65ba3805552a4d312 Mon Sep 17 00:00:00 2001 From: Alessandro Toppi Date: Fri, 3 May 2024 15:24:31 +0200 Subject: [PATCH] postprocessing: use ffmpeg new channel layout API when available --- src/postprocessing/pp-avformat.c | 4 ++++ src/postprocessing/pp-avformat.h | 5 +++++ src/postprocessing/pp-g722.c | 7 ++++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/postprocessing/pp-avformat.c b/src/postprocessing/pp-avformat.c index 0067f49661..8e97c84b33 100644 --- a/src/postprocessing/pp-avformat.c +++ b/src/postprocessing/pp-avformat.c @@ -64,7 +64,11 @@ AVStream *janus_pp_new_audio_avstream(AVFormatContext *fctx, int codec_id, int s c->codec_id = codec_id; c->codec_type = AVMEDIA_TYPE_AUDIO; c->sample_rate = samplerate; +#ifdef NEW_CHANNEL_LAYOUT + c->ch_layout.nb_channels = channels; +#else c->channels = channels; +#endif if(extradata) { c->extradata_size = size; c->extradata = av_memdup(extradata, size); diff --git a/src/postprocessing/pp-avformat.h b/src/postprocessing/pp-avformat.h index 375c153ca9..1314f1e8fe 100644 --- a/src/postprocessing/pp-avformat.h +++ b/src/postprocessing/pp-avformat.h @@ -40,6 +40,11 @@ #define USE_CODECPAR #endif +/* https://github.com/FFmpeg/FFmpeg/commit/cdba98bb80e2ab73d34659c610771b020afc6a77 */ +#if LIBAVCODEC_VER_AT_LEAST(59, 24) +#define NEW_CHANNEL_LAYOUT +#endif + void janus_pp_setup_avformat(void); AVFormatContext *janus_pp_create_avformatcontext(const char *format, const char *metadata, const char *destination); diff --git a/src/postprocessing/pp-g722.c b/src/postprocessing/pp-g722.c index fe315c69f2..116f1508fb 100644 --- a/src/postprocessing/pp-g722.c +++ b/src/postprocessing/pp-g722.c @@ -211,7 +211,12 @@ int janus_pp_g722_process(FILE *file, janus_pp_frame_packet *list, int *working) int data_size = av_get_bytes_per_sample(dec_ctx->sample_fmt); int i=0, ch=0; for(i=0; inb_samples; i++) { - for(ch=0; chchannels; ch++) { +#ifdef NEW_CHANNEL_LAYOUT + int channels = dec_ctx->ch_layout.nb_channels; +#else + int channels = dec_ctx->channels; +#endif + for(ch=0; chdata[ch] + data_size*i, 1, data_size, wav_file); } }