From 816e9851d162a25bcbada84fbf4772043924a962 Mon Sep 17 00:00:00 2001 From: Martchus Date: Wed, 26 Dec 2018 03:52:24 +0100 Subject: [PATCH] Build essentia against libswresample Not tested whether it works at runtime, though --- ...skip-adding-debug-optimization-flags.patch | 2 +- .../git/0002-Allow-to-skip-msse-flags.patch | 2 +- ...bswresample-instead-of-libavresample.patch | 196 ++++++++++++++++++ essentia/git/PKGBUILD | 37 +++- 4 files changed, 224 insertions(+), 13 deletions(-) create mode 100644 essentia/git/0003-Use-libswresample-instead-of-libavresample.patch diff --git a/essentia/git/0001-Allow-to-skip-adding-debug-optimization-flags.patch b/essentia/git/0001-Allow-to-skip-adding-debug-optimization-flags.patch index 78d74a23..5dbe6ca6 100644 --- a/essentia/git/0001-Allow-to-skip-adding-debug-optimization-flags.patch +++ b/essentia/git/0001-Allow-to-skip-adding-debug-optimization-flags.patch @@ -1,7 +1,7 @@ From 26fcda33ac3864d2d5c9f307708881018f6b5c78 Mon Sep 17 00:00:00 2001 From: Martchus Date: Wed, 19 Dec 2018 10:28:03 +0100 -Subject: [PATCH 1/2] Allow to skip adding debug/optimization flags +Subject: [PATCH 1/3] Allow to skip adding debug/optimization flags --- wscript | 7 +++++-- diff --git a/essentia/git/0002-Allow-to-skip-msse-flags.patch b/essentia/git/0002-Allow-to-skip-msse-flags.patch index 7a246b20..3f2fc9a5 100644 --- a/essentia/git/0002-Allow-to-skip-msse-flags.patch +++ b/essentia/git/0002-Allow-to-skip-msse-flags.patch @@ -1,7 +1,7 @@ From 7a4520834d8a6dc69a54daef0bef3590e71681e3 Mon Sep 17 00:00:00 2001 From: Martchus Date: Wed, 19 Dec 2018 10:28:23 +0100 -Subject: [PATCH 2/2] Allow to skip msse flags +Subject: [PATCH 2/3] Allow to skip msse flags This makes sense when building for other platforms than x86. diff --git a/essentia/git/0003-Use-libswresample-instead-of-libavresample.patch b/essentia/git/0003-Use-libswresample-instead-of-libavresample.patch new file mode 100644 index 00000000..bf66531e --- /dev/null +++ b/essentia/git/0003-Use-libswresample-instead-of-libavresample.patch @@ -0,0 +1,196 @@ +From 06b7146a1db30ee8bd6b97af5a7500e14335ecdd Mon Sep 17 00:00:00 2001 +From: Martchus +Date: Wed, 26 Dec 2018 02:57:49 +0100 +Subject: [PATCH 3/3] Use libswresample instead of libavresample + +--- + src/algorithms/io/audioloader.cpp | 20 +++++++++----------- + src/algorithms/io/audioloader.h | 2 +- + src/essentia/utils/audiocontext.cpp | 20 +++++++++----------- + src/essentia/utils/audiocontext.h | 2 +- + src/essentia/utils/ffmpegapi.h | 4 ++-- + src/wscript | 4 ++-- + 6 files changed, 24 insertions(+), 28 deletions(-) + +diff --git a/src/algorithms/io/audioloader.cpp b/src/algorithms/io/audioloader.cpp +index d838b565..22cd27a2 100644 +--- a/src/algorithms/io/audioloader.cpp ++++ b/src/algorithms/io/audioloader.cpp +@@ -119,8 +119,8 @@ void AudioLoader::openAudioFile(const string& filename) { + E_DEBUG(EAlgorithm, "AudioLoader: converting from " << (fmt ? fmt : "unknown") << " to FLT"); + */ + +- E_DEBUG(EAlgorithm, "AudioLoader: using sample format conversion from libavresample"); +- _convertCtxAv = avresample_alloc_context(); ++ E_DEBUG(EAlgorithm, "AudioLoader: using sample format conversion from libswresample"); ++ _convertCtxAv = swr_alloc(); + + av_opt_set_int(_convertCtxAv, "in_channel_layout", layout, 0); + av_opt_set_int(_convertCtxAv, "out_channel_layout", layout, 0); +@@ -129,8 +129,8 @@ void AudioLoader::openAudioFile(const string& filename) { + av_opt_set_int(_convertCtxAv, "in_sample_fmt", _audioCtx->sample_fmt, 0); + av_opt_set_int(_convertCtxAv, "out_sample_fmt", AV_SAMPLE_FMT_FLT, 0); + +- if (avresample_open(_convertCtxAv) < 0) { +- throw EssentiaException("AudioLoader: Could not initialize avresample context"); ++ if (swr_init(_convertCtxAv) < 0) { ++ throw EssentiaException("AudioLoader: Could not initialize swresample context"); + } + + av_init_packet(&_packet); +@@ -150,8 +150,8 @@ void AudioLoader::closeAudioFile() { + } + + if (_convertCtxAv) { +- avresample_close(_convertCtxAv); +- avresample_free(&_convertCtxAv); ++ swr_close(_convertCtxAv); ++ swr_free(&_convertCtxAv); + } + + // Close the codec +@@ -286,17 +286,15 @@ int AudioLoader::decode_audio_frame(AVCodecContext* audioCtx, + memcpy(output, _decodedFrame->data[0], inputPlaneSize); + } + else { +- int samplesWrittern = avresample_convert(_convertCtxAv, ++ int samplesWrittern = swr_convert(_convertCtxAv, + (uint8_t**) &output, +- outputPlaneSize, + outputBufferSamples, +- (uint8_t**)_decodedFrame->data, +- inputPlaneSize, ++ (const uint8_t**)_decodedFrame->data, + inputSamples); + + if (samplesWrittern < inputSamples) { + // TODO: there may be data remaining in the internal FIFO buffer +- // to get this data: call avresample_convert() with NULL input ++ // to get this data: call swr_convert() with NULL input + // Test if this happens in practice + ostringstream msg; + msg << "AudioLoader: Incomplete format conversion (some samples missing)" +diff --git a/src/algorithms/io/audioloader.h b/src/algorithms/io/audioloader.h +index 08cfe88a..f2cd313b 100644 +--- a/src/algorithms/io/audioloader.h ++++ b/src/algorithms/io/audioloader.h +@@ -60,7 +60,7 @@ class AudioLoader : public Algorithm { + bool _computeMD5; + AVFrame* _decodedFrame; + +- struct AVAudioResampleContext* _convertCtxAv; ++ struct SwrContext* _convertCtxAv; + + int _streamIdx; // index of the audio stream among all the streams contained in the file + std::vector _streams; +diff --git a/src/essentia/utils/audiocontext.cpp b/src/essentia/utils/audiocontext.cpp +index 5390c9f4..729e2f6b 100644 +--- a/src/essentia/utils/audiocontext.cpp ++++ b/src/essentia/utils/audiocontext.cpp +@@ -145,8 +145,8 @@ int AudioContext::create(const std::string& filename, + strncpy(_muxCtx->filename, _filename.c_str(), sizeof(_muxCtx->filename)); + + // Configure sample format convertion +- E_DEBUG(EAlgorithm, "AudioContext: using sample format conversion from libavresample"); +- _convertCtxAv = avresample_alloc_context(); ++ E_DEBUG(EAlgorithm, "AudioContext: using sample format conversion from libswresample"); ++ _convertCtxAv = swr_alloc(); + + av_opt_set_int(_convertCtxAv, "in_channel_layout", _codecCtx->channel_layout, 0); + av_opt_set_int(_convertCtxAv, "out_channel_layout", _codecCtx->channel_layout, 0); +@@ -155,8 +155,8 @@ int AudioContext::create(const std::string& filename, + av_opt_set_int(_convertCtxAv, "in_sample_fmt", AV_SAMPLE_FMT_FLT, 0); + av_opt_set_int(_convertCtxAv, "out_sample_fmt", _codecCtx->sample_fmt, 0); + +- if (avresample_open(_convertCtxAv) < 0) { +- throw EssentiaException("AudioLoader: Could not initialize avresample context"); ++ if (swr_init(_convertCtxAv) < 0) { ++ throw EssentiaException("AudioLoader: Could not initialize swresample context"); + } + + return _codecCtx->frame_size; +@@ -206,8 +206,8 @@ void AudioContext::close() { + _buffer = 0; + + if (_convertCtxAv) { +- avresample_close(_convertCtxAv); +- avresample_free(&_convertCtxAv); ++ swr_close(_convertCtxAv); ++ swr_free(&_convertCtxAv); + } + + _isOpen = false; +@@ -284,17 +284,15 @@ void AudioContext::encodePacket(int size) { + throw EssentiaException("Could not allocate output buffer for sample format conversion"); + } + +- int written = avresample_convert(_convertCtxAv, ++ int written = swr_convert(_convertCtxAv, + &bufferFmt, +- outputPlaneSize, + size, +- (uint8_t**) &_buffer, +- inputPlaneSize, ++ (const uint8_t**) &_buffer, + size); + + if (written < size) { + // The same as in AudioLoader. There may be data remaining in the internal +- // FIFO buffer to get this data: call avresample_convert() with NULL input ++ // FIFO buffer to get this data: call swr_convert() with NULL input + // But we just throw exception instead. + ostringstream msg; + msg << "AudioLoader: Incomplete format conversion (some samples missing)" +diff --git a/src/essentia/utils/audiocontext.h b/src/essentia/utils/audiocontext.h +index ae58f949..55939c7d 100644 +--- a/src/essentia/utils/audiocontext.h ++++ b/src/essentia/utils/audiocontext.h +@@ -45,7 +45,7 @@ class AudioContext { + float* _buffer; // input FLT buffer interleaved + uint8_t* _buffer_test; // input buffer in converted to codec sample format + +- struct AVAudioResampleContext* _convertCtxAv; ++ struct SwrContext* _convertCtxAv; + + //const static int FFMPEG_BUFFER_SIZE = MAX_AUDIO_FRAME_SIZE * 2; + // MAX_AUDIO_FRAME_SIZE is in bytes, multiply it by 2 to get some margin +diff --git a/src/essentia/utils/ffmpegapi.h b/src/essentia/utils/ffmpegapi.h +index 20cf3a32..9e53302d 100644 +--- a/src/essentia/utils/ffmpegapi.h ++++ b/src/essentia/utils/ffmpegapi.h +@@ -24,8 +24,8 @@ extern "C" { + #include + #include + #include +-#include +-#include ++#include ++#include + } + + +diff --git a/src/wscript b/src/wscript +index c3c999d1..72bdf8e3 100644 +--- a/src/wscript ++++ b/src/wscript +@@ -130,7 +130,7 @@ def configure(ctx): + ctx.check_cfg(package='libavutil', uselib_store='AVUTIL', + args=check_cfg_args, mandatory=False) + +- ctx.check_cfg(package='libavresample', uselib_store='AVRESAMPLE', ++ ctx.check_cfg(package='libswresample', uselib_store='AVRESAMPLE', + args=check_cfg_args, mandatory=False) + + if 'libsamplerate' in ctx.env.WITH_LIBS_LIST: +@@ -476,7 +476,7 @@ def build(ctx): + + ctx(source='../essentia.pc.in', **ctx.env.pcfile_opts) + # TODO Ideally we should use the Requires.private field in the .pc file +- # Requires.private: gaia2 fftw3f yaml-0.1 libavcodec libavformat libavutil libavresample samplerate taglib libchromaprint ++ # Requires.private: gaia2 fftw3f yaml-0.1 libavcodec libavformat libavutil libswresample samplerate taglib libchromaprint + + ctx.add_group() + +-- +2.20.1 + diff --git a/essentia/git/PKGBUILD b/essentia/git/PKGBUILD index 9145815d..55c4d146 100644 --- a/essentia/git/PKGBUILD +++ b/essentia/git/PKGBUILD @@ -2,24 +2,31 @@ # Contributor: Martchus pkgname=essentia-git -pkgrel=1 +pkgrel=2 pkgver=r1956.c5ea2738 pkgdesc='Library and tools for audio and music analysis, description and synthesis' arch=('i686' 'x86_64' 'armv6h' 'armv7h' 'aarch64') url="http://essentia.upf.edu/documentation/" license=('AGPL') makedepends=('git' 'python' 'glibc') -depends=('fftw' 'ffmpeg' 'libsamplerate' 'taglib' 'libyaml' - 'python' 'python-numpy' 'python-yaml' 'chromaprint') +depends=('fftw' 'ffmpeg' 'libsamplerate' 'taglib' 'libyaml' 'chromaprint') +optdepends=('python-six: Python bindings' + 'python-numpy: Python bindings' + 'python-yaml: Python bindings') +makedepends=('git' 'python-numpy' 'python-yaml') +checkdepends=('python-six') provides=('essentia') conflicts=('essentia' 'essentia-acousticbrainz' 'lib32-essentia-acousticbrainz') source=('git+https://github.com/MTG/essentia.git#branch=master' + 'git+https://github.com/MTG/essentia-audio.git#branch=master' '0001-Allow-to-skip-adding-debug-optimization-flags.patch' - '0002-Allow-to-skip-msse-flags.patch') + '0002-Allow-to-skip-msse-flags.patch' + '0003-Use-libswresample-instead-of-libavresample.patch') sha256sums=('SKIP' - '25e29d35bee35a6229ed6e0736503ca8aefca13d022e3be4a9798342d01b2943' - 'b715673958026bc26e459c0dba4adc18fd287f095fa1afc2a6e880d4f4c17102') + '32bc137a3ba2c17e42f5c0b2f241d4ac423ca8f2d197b2a6fad318256d516f1d' + '71c11477bdfc61f07238d36c7d944f894bfc7f12fbafa5f62fd1f95543c46fb2' + '1e9373276022a4d2c5d59642acc2b5bbc1871e76ae61902bd952fce883230dce') pkgver() { cd "$srcdir/essentia" @@ -28,8 +35,15 @@ pkgver() { prepare() { cd "$srcdir/essentia" + patch -p1 -i ../0001-Allow-to-skip-adding-debug-optimization-flags.patch patch -p1 -i ../0002-Allow-to-skip-msse-flags.patch + patch -p1 -i ../0003-Use-libswresample-instead-of-libavresample.patch + + # symlink audio testfiles so they can be found by the testsuite + cd test + rm -r audio + ln -s "$srcdir/essentia-audio" audio } build() { @@ -50,11 +64,12 @@ build() { ./waf $MAKEFLAGS } -#check() { -# cd "$srcdir/$pkgname" -# ./waf run_tests -# ./waf run_python_tests -#} +check() { + cd "$srcdir/essentia" + export LD_LIBRARY_PATH="$srcdir/essentia/build/src" + ./waf run_tests + ./waf run_python_tests +} package() { cd "$srcdir/essentia"