File 0001-drop-support-for-libavresample.patch of Package aubio
From b6bf2334956f237b8a8ad7cbb76939d4ae2d6a69 Mon Sep 17 00:00:00 2001
From: Paul Brossier <piem@piem.org>
Date: Wed, 27 Dec 2023 18:09:23 +0100
Subject: [PATCH] drop support for libavresample
---
src/io/source_avcodec.c | 53 +----------------------------------------
1 file changed, 1 insertion(+), 52 deletions(-)
diff --git a/src/io/source_avcodec.c b/src/io/source_avcodec.c
index 1421bd9..011c3d7 100644
--- a/src/io/source_avcodec.c
+++ b/src/io/source_avcodec.c
@@ -24,11 +24,7 @@
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
-#if defined(HAVE_SWRESAMPLE)
#include <libswresample/swresample.h>
-#elif defined(HAVE_AVRESAMPLE)
-#include <libavresample/avresample.h>
-#endif
#include <libavutil/opt.h>
// determine whether we use libavformat from ffmpeg or from libav
@@ -91,11 +87,7 @@ struct _aubio_source_avcodec_t {
#else
AVPacket avPacket;
#endif
-#ifdef HAVE_AVRESAMPLE
- AVAudioResampleContext *avr;
-#elif defined(HAVE_SWRESAMPLE)
SwrContext *avr;
-#endif
smpl_t *output;
uint_t read_samples;
uint_t read_index;
@@ -336,13 +328,9 @@ void aubio_source_avcodec_reset_resampler(aubio_source_avcodec_t * s)
// create or reset resampler to/from mono/multi-channel
if ( s->avr == NULL ) {
int err;
+ SwrContext *avr = swr_alloc();
int64_t input_layout = av_get_default_channel_layout(s->input_channels);
int64_t output_layout = av_get_default_channel_layout(s->input_channels);
-#ifdef HAVE_AVRESAMPLE
- AVAudioResampleContext *avr = avresample_alloc_context();
-#elif defined(HAVE_SWRESAMPLE)
- SwrContext *avr = swr_alloc();
-#endif /* HAVE_AVRESAMPLE || HAVE_SWRESAMPLE */
av_opt_set_int(avr, "in_channel_layout", input_layout, 0);
av_opt_set_int(avr, "out_channel_layout", output_layout, 0);
@@ -356,11 +344,7 @@ void aubio_source_avcodec_reset_resampler(aubio_source_avcodec_t * s)
#endif
// TODO: use planar?
//av_opt_set_int(avr, "out_sample_fmt", AV_SAMPLE_FMT_FLTP, 0);
-#ifdef HAVE_AVRESAMPLE
- if ( ( err = avresample_open(avr) ) < 0)
-#elif defined(HAVE_SWRESAMPLE)
if ( ( err = swr_init(avr) ) < 0)
-#endif /* HAVE_AVRESAMPLE || HAVE_SWRESAMPLE */
{
char errorstr[256];
av_strerror (err, errorstr, sizeof(errorstr));
@@ -383,23 +367,11 @@ void aubio_source_avcodec_readframe(aubio_source_avcodec_t *s,
#else
AVPacket *avPacket = &s->avPacket;
#endif
-#ifdef HAVE_AVRESAMPLE
- AVAudioResampleContext *avr = s->avr;
-#elif defined(HAVE_SWRESAMPLE)
SwrContext *avr = s->avr;
-#endif /* HAVE_AVRESAMPLE || HAVE_SWRESAMPLE */
int got_frame = 0;
-#ifdef HAVE_AVRESAMPLE
- int in_linesize = 0;
- int in_samples = avFrame->nb_samples;
- int out_linesize = 0;
- int max_out_samples = AUBIO_AVCODEC_MAX_BUFFER_SIZE;
- int out_samples = 0;
-#elif defined(HAVE_SWRESAMPLE)
int in_samples = avFrame->nb_samples;
int max_out_samples = AUBIO_AVCODEC_MAX_BUFFER_SIZE / avCodecCtx->channels;
int out_samples = 0;
-#endif /* HAVE_AVRESAMPLE || HAVE_SWRESAMPLE */
smpl_t *output = s->output;
#ifndef FF_API_LAVF_AVCTX
int len = 0;
@@ -476,23 +448,11 @@ void aubio_source_avcodec_readframe(aubio_source_avcodec_t *s,
#warning "avutil < 53 is deprecated, crashes might occur on corrupt files"
#endif
-#ifdef HAVE_AVRESAMPLE
- in_linesize = 0;
- av_samples_get_buffer_size(&in_linesize, avCodecCtx->channels,
- avFrame->nb_samples, avCodecCtx->sample_fmt, 1);
- in_samples = avFrame->nb_samples;
- out_linesize = 0;
- max_out_samples = AUBIO_AVCODEC_MAX_BUFFER_SIZE;
- out_samples = avresample_convert ( avr,
- (uint8_t **)&output, out_linesize, max_out_samples,
- (uint8_t **)avFrame->data, in_linesize, in_samples);
-#elif defined(HAVE_SWRESAMPLE)
in_samples = avFrame->nb_samples;
max_out_samples = AUBIO_AVCODEC_MAX_BUFFER_SIZE / avCodecCtx->channels;
out_samples = swr_convert( avr,
(uint8_t **)&output, max_out_samples,
(const uint8_t **)avFrame->data, in_samples);
-#endif /* HAVE_AVRESAMPLE || HAVE_SWRESAMPLE */
if (out_samples < 0) {
AUBIO_WRN("source_avcodec: error while resampling %s (%d)\n",
s->path, out_samples);
@@ -626,14 +586,8 @@ uint_t aubio_source_avcodec_seek (aubio_source_avcodec_t * s, uint_t pos) {
s->eof = 0;
s->read_index = 0;
s->read_samples = 0;
-#ifdef HAVE_AVRESAMPLE
- // reset the AVAudioResampleContext
- avresample_close(s->avr);
- avresample_open(s->avr);
-#elif defined(HAVE_SWRESAMPLE)
swr_close(s->avr);
swr_init(s->avr);
-#endif
return ret;
}
@@ -647,13 +601,8 @@ uint_t aubio_source_avcodec_get_duration (aubio_source_avcodec_t * s) {
uint_t aubio_source_avcodec_close(aubio_source_avcodec_t * s) {
if (s->avr != NULL) {
-#ifdef HAVE_AVRESAMPLE
- avresample_close( s->avr );
- av_free ( s->avr );
-#elif defined(HAVE_SWRESAMPLE)
swr_close ( s->avr );
swr_free ( &s->avr );
-#endif
}
s->avr = NULL;
if (s->avCodecCtx != NULL) {
--
2.53.0