From 33b262af787a43acbd57dd761c0bbefa818bca59 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Tue, 27 Mar 2018 10:32:47 -0400 Subject: [PATCH] TT#33700 migrate from avresample to swresample closes #465 Change-Id: Ib23ea0dbaf151182360db8ae8e0bc94c93a1743a --- README.md | 2 +- daemon/Makefile | 4 +-- debian/control | 2 +- lib/codeclib.h | 4 +-- lib/resample.c | 53 ++++++++++++++------------------------ recording-daemon/Makefile | 4 +-- recording-daemon/decoder.c | 1 - recording-daemon/mix.c | 1 - 8 files changed, 27 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index 068148173..bf5e88a38 100644 --- a/README.md +++ b/README.md @@ -130,7 +130,7 @@ There's 3 parts to *rtpengine*, which can be found in the respective subdirector - *XMLRPC-C* version 1.16.08 or higher - *hiredis* library - *libiptc* library for iptables management (optional) - - *ffmpeg* codec libraries for transcoding (optional) such as *libavcodec*, *libavfilter*, *libavresample* + - *ffmpeg* codec libraries for transcoding (optional) such as *libavcodec*, *libavfilter*, *libswresample* - *bcg729* for full G.729 transcoding support (optional) The `Makefile` contains a few Debian-specific flags, which may have to removed for compilation to diff --git a/daemon/Makefile b/daemon/Makefile index 91d723479..418854e74 100644 --- a/daemon/Makefile +++ b/daemon/Makefile @@ -66,7 +66,7 @@ ifeq ($(with_transcoding),yes) CFLAGS+= $(shell pkg-config --cflags libavcodec) CFLAGS+= $(shell pkg-config --cflags libavformat) CFLAGS+= $(shell pkg-config --cflags libavutil) -CFLAGS+= $(shell pkg-config --cflags libavresample) +CFLAGS+= $(shell pkg-config --cflags libswresample) CFLAGS+= $(shell pkg-config --cflags libavfilter) CFLAGS+= -DWITH_TRANSCODING else @@ -106,7 +106,7 @@ ifeq ($(with_transcoding),yes) LDFLAGS+= $(shell pkg-config --libs libavcodec) LDFLAGS+= $(shell pkg-config --libs libavformat) LDFLAGS+= $(shell pkg-config --libs libavutil) -LDFLAGS+= $(shell pkg-config --libs libavresample) +LDFLAGS+= $(shell pkg-config --libs libswresample) LDFLAGS+= $(shell pkg-config --libs libavfilter) endif ifeq ($(have_bcg729),yes) diff --git a/debian/control b/debian/control index 63cab66c5..dc3ad345b 100644 --- a/debian/control +++ b/debian/control @@ -11,7 +11,6 @@ Build-Depends: libavcodec-dev (>= 6:10), libavfilter-dev (>= 6:10), libavformat-dev (>= 6:10), - libavresample-dev (>= 6:10), libavutil-dev (>= 6:10), libbcg729-dev , libcurl4-openssl-dev | libcurl4-gnutls-dev | libcurl3-openssl-dev | libcurl3-gnutls-dev, @@ -23,6 +22,7 @@ Build-Depends: libpcap0.8-dev | libpcap-dev, libpcre3-dev, libssl-dev (>= 1.0.1), + libswresample-dev (>= 6:10), libxmlrpc-c3-dev (>= 1.16.07) | libxmlrpc-core-c3-dev (>= 1.16.07), markdown, zlib1g-dev, diff --git a/lib/codeclib.h b/lib/codeclib.h index bcc6969ad..bf059e29c 100644 --- a/lib/codeclib.h +++ b/lib/codeclib.h @@ -10,7 +10,7 @@ typedef struct codec_def_s codec_def_t; -#include +#include #include #include #ifdef HAVE_BCG729 @@ -102,7 +102,7 @@ struct format_s { }; struct resample_s { - AVAudioResampleContext *avresample; + SwrContext *swresample; }; struct decoder_s { diff --git a/lib/resample.c b/lib/resample.c index a01451c9d..b728285fa 100644 --- a/lib/resample.c +++ b/lib/resample.c @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include #include "log.h" @@ -34,42 +34,28 @@ AVFrame *resample_frame(resample_t *resample, AVFrame *frame, const format_t *to resample: - if (G_UNLIKELY(!resample->avresample)) { - resample->avresample = avresample_alloc_context(); + if (G_UNLIKELY(!resample->swresample)) { + resample->swresample = swr_alloc_set_opts(NULL, + to_channel_layout, + to_format->format, + to_format->clockrate, + frame->channel_layout, + frame->format, + frame->sample_rate, + 0, NULL); err = "failed to alloc resample context"; - if (!resample->avresample) + if (!resample->swresample) goto err; - err = "failed to set resample option"; - if ((errcode = av_opt_set_int(resample->avresample, "in_channel_layout", - frame->channel_layout, 0))) - goto err; - if ((errcode = av_opt_set_int(resample->avresample, "in_sample_fmt", - frame->format, 0))) - goto err; - if ((errcode = av_opt_set_int(resample->avresample, "in_sample_rate", - frame->sample_rate, 0))) - goto err; - if ((errcode = av_opt_set_int(resample->avresample, "out_channel_layout", - to_channel_layout, 0))) - goto err; - if ((errcode = av_opt_set_int(resample->avresample, "out_sample_fmt", - to_format->format, 0))) - goto err; - if ((errcode = av_opt_set_int(resample->avresample, "out_sample_rate", - to_format->clockrate, 0))) - goto err; - // av_opt_set_int(dec->avresample, "internal_sample_fmt", AV_SAMPLE_FMT_FLTP, 0); // ? - err = "failed to init resample context"; - if ((errcode = avresample_open(resample->avresample)) < 0) + if ((errcode = swr_init(resample->swresample)) < 0) goto err; } // get a large enough buffer for resampled audio - this should be enough so we don't // have to loop - int dst_samples = avresample_available(resample->avresample) + - av_rescale_rnd(avresample_get_delay(resample->avresample) + frame->nb_samples, + int dst_samples = av_rescale_rnd(swr_get_delay(resample->swresample, to_format->clockrate) + + frame->nb_samples, to_format->clockrate, frame->sample_rate, AV_ROUND_UP); AVFrame *swr_frame = av_frame_alloc(); @@ -86,11 +72,10 @@ resample: if ((errcode = av_frame_get_buffer(swr_frame, 0)) < 0) goto err; - swr_frame->nb_samples = dst_samples; - int ret_samples = avresample_convert(resample->avresample, swr_frame->extended_data, - swr_frame->linesize[0], dst_samples, - frame->extended_data, - frame->linesize[0], frame->nb_samples); + int ret_samples = swr_convert(resample->swresample, swr_frame->extended_data, + dst_samples, + (const uint8_t **) frame->extended_data, + frame->nb_samples); err = "failed to resample audio"; if ((errcode = ret_samples) < 0) goto err; @@ -107,5 +92,5 @@ err: void resample_shutdown(resample_t *resample) { - avresample_free(&resample->avresample); + swr_free(&resample->swresample); } diff --git a/recording-daemon/Makefile b/recording-daemon/Makefile index 536b26810..200636eb7 100644 --- a/recording-daemon/Makefile +++ b/recording-daemon/Makefile @@ -8,7 +8,7 @@ CFLAGS+= $(shell pkg-config --cflags gthread-2.0) CFLAGS+= $(shell pkg-config --cflags libavcodec) CFLAGS+= $(shell pkg-config --cflags libavformat) CFLAGS+= $(shell pkg-config --cflags libavutil) -CFLAGS+= $(shell pkg-config --cflags libavresample) +CFLAGS+= $(shell pkg-config --cflags libswresample) CFLAGS+= $(shell pkg-config --cflags libavfilter) CFLAGS+= $(shell mysql_config --cflags) CFLAGS+= $(shell pkg-config --cflags openssl) @@ -19,7 +19,7 @@ LDFLAGS+= $(shell pkg-config --libs gthread-2.0) LDFLAGS+= $(shell pkg-config --libs libavcodec) LDFLAGS+= $(shell pkg-config --libs libavformat) LDFLAGS+= $(shell pkg-config --libs libavutil) -LDFLAGS+= $(shell pkg-config --libs libavresample) +LDFLAGS+= $(shell pkg-config --libs libswresample) LDFLAGS+= $(shell pkg-config --libs libavfilter) LDFLAGS+= $(shell mysql_config --libs) LDFLAGS+= $(shell pkg-config --libs openssl) diff --git a/recording-daemon/decoder.c b/recording-daemon/decoder.c index 0be517d4c..603683fef 100644 --- a/recording-daemon/decoder.c +++ b/recording-daemon/decoder.c @@ -7,7 +7,6 @@ #include #include #include -#include #include #include "types.h" #include "log.h" diff --git a/recording-daemon/mix.c b/recording-daemon/mix.c index a751b6740..58677cacd 100644 --- a/recording-daemon/mix.c +++ b/recording-daemon/mix.c @@ -6,7 +6,6 @@ #include #include #include -#include #include #include "types.h" #include "log.h"