TT#33700 migrate from avresample to swresample

closes #465

Change-Id: Ib23ea0dbaf151182360db8ae8e0bc94c93a1743a
changes/19/20019/4
Richard Fuchs 8 years ago
parent 760488703e
commit 33b262af78

@ -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

@ -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)

2
debian/control vendored

@ -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 <!pkg.ngcp-rtpengine.nobcg729>,
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,

@ -10,7 +10,7 @@ typedef struct codec_def_s codec_def_t;
#include <libavresample/avresample.h>
#include <libswresample/swresample.h>
#include <libavcodec/avcodec.h>
#include <libavutil/audio_fifo.h>
#ifdef HAVE_BCG729
@ -102,7 +102,7 @@ struct format_s {
};
struct resample_s {
AVAudioResampleContext *avresample;
SwrContext *swresample;
};
struct decoder_s {

@ -6,7 +6,7 @@
#include <libavutil/channel_layout.h>
#include <libavutil/mathematics.h>
#include <inttypes.h>
#include <libavresample/avresample.h>
#include <libswresample/swresample.h>
#include <libavutil/opt.h>
#include <libavutil/frame.h>
#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);
}

@ -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)

@ -7,7 +7,6 @@
#include <libavutil/samplefmt.h>
#include <glib.h>
#include <stdint.h>
#include <libavresample/avresample.h>
#include <libavutil/opt.h>
#include "types.h"
#include "log.h"

@ -6,7 +6,6 @@
#include <libavutil/channel_layout.h>
#include <libavutil/mathematics.h>
#include <inttypes.h>
#include <libavresample/avresample.h>
#include <libavutil/opt.h>
#include "types.h"
#include "log.h"

Loading…
Cancel
Save