ref: 24c207f23ec4eb69f5f92af98896e56def59af19
parent: 59be50dfa19e13f55ac5be918b9b6505cf679c14
parent: 91fa88d3c702a0a38a3a75d842f3cecf823b25e1
author: Paul Brossier <piem@piem.org>
date: Thu Mar 23 11:46:07 EDT 2017
Merge branch 'master' into gitshaversion
--- a/Makefile
+++ b/Makefile
@@ -10,7 +10,6 @@
# $ make test_python
WAFCMD=python waf
-WAFURL=https://waf.io/waf-1.9.6
#WAFOPTS:=
# turn on verbose mode
--- /dev/null
+++ b/circle.yml
@@ -1,0 +1,9 @@
+dependencies:
+ pre:
+ - sudo apt-get update; sudo apt-get install make sox pkg-config libavcodec-dev libavformat-dev libavresample-dev libavutil-dev libsndfile1-dev libsamplerate-dev
+
+test:
+ pre:
+ - make create_test_sounds
+ override:
+ - nose2 -v
--- a/python/lib/moresetuptools.py
+++ b/python/lib/moresetuptools.py
@@ -74,9 +74,8 @@
def add_external_deps(ext, usedouble = False):
# loof for additional packages
print("Info: looking for *optional* additional packages")
- packages = ['libavcodec', 'libavformat', 'libavutil', 'libavresample',
- 'jack',
- 'jack',
+ packages = ['libavcodec', 'libavformat', 'libavutil',
+ 'libswresample', 'libavresample',
'sndfile',
#'fftw3f',
]
@@ -88,11 +87,13 @@
add_packages(packages, ext=ext)
if 'avcodec' in ext.libraries \
and 'avformat' in ext.libraries \
- and 'avutil' in ext.libraries \
- and 'avresample' in ext.libraries:
- ext.define_macros += [('HAVE_LIBAV', 1)]
- if 'jack' in ext.libraries:
- ext.define_macros += [('HAVE_JACK', 1)]
+ and 'avutil' in ext.libraries:
+ if 'swresample' in ext.libraries:
+ ext.define_macros += [('HAVE_SWRESAMPLE', 1)]
+ elif 'avresample' in ext.libraries:
+ ext.define_macros += [('HAVE_AVRESAMPLE', 1)]
+ if 'swresample' in ext.libraries or 'avresample' in ext.libraries:
+ ext.define_macros += [('HAVE_LIBAV', 1)]
if 'sndfile' in ext.libraries:
ext.define_macros += [('HAVE_SNDFILE', 1)]
if 'samplerate' in ext.libraries:
--- a/scripts/build_mingw
+++ b/scripts/build_mingw
@@ -1,28 +1,115 @@
#! /bin/bash
-# This script cross compiles aubio for windows using mingw, both for 32 and 64
-# bits. Built binaries will be placed in ./dist-win32 and ./dist-win64.
-
+# This script cross compiles aubio for windows using mingw, four times:
+#
+# - 32 and 64 bits with no external dependencies
+# - 32 and 64 bits against ffmpeg
+#
# On debian or ubuntu, you will want to 'apt-get install gcc-mingw-w64'
set -e
set -x
-WAFOPTS="-v --disable-avcodec --disable-samplerate --disable-jack --disable-sndfile"
+source VERSION
+VERSION="$AUBIO_MAJOR_VERSION.$AUBIO_MINOR_VERSION.$AUBIO_PATCH_VERSION"
+VERSION+="$AUBIO_VERSION_STATUS"
-[ -d dist-win32 ] && rm -rf dist-win32
-[ -d dist-win64 ] && rm -rf dist-win64
+FFMPEG_BUILDS_URL="https://ffmpeg.zeranoe.com/builds"
+FFMPEG_DEFAULT="20170315-6c4665d"
-CFLAGS="-Os" \
- LDFLAGS="" \
- CC=x86_64-w64-mingw32-gcc \
- ./waf distclean configure build install --destdir=$PWD/dist-win64 \
- --testcmd="echo %s" \
- $WAFOPTS --with-target-platform=win64
+# define some default CFLAGS
+DEF_CFLAGS="-Os -I/usr/share/mingw-w64"
+DEF_LDFLAGS=""
-CFLAGS="-Os" \
- LDFLAGS="" \
- CC=i686-w64-mingw32-gcc \
- ./waf distclean configure build install --destdir=$PWD/dist-win32 \
- --testcmd="echo %s" \
- $WAFOPTS --with-target-platform=win32
+WAFOPTS=""
+# disable external deps to make sure we don't try to use the host package
+WAFOPTS+=" --disable-samplerate --disable-jack --disable-sndfile"
+# enable ffmpeg build
+WAFOPTS+=" --disable-avcodec"
+# install without a prefix
+WAFOPTS+=" --prefix=/"
+# compile the tests, but fake running them
+# passing this option WAFOPTS fails (escaping?), added in actual waf call below
+#WAFOPTS+=" --testcmd='echo %s'"
+
+# debugging
+#WAFOPTS+=" -v"
+#WAFOPTS+=" -j1"
+#WAFOPTS+=" --notests"
+
+function fetch_ffpmeg() {
+ ## manually add ffmpeg (no pkg-config .pc files in bins)
+ [ -n "$FFMPEG_VERSION" ] || FFMPEG_VERSION=$FFMPEG_DEFAULT
+ FFMPEG_TARBALL="$PWD/ffmpeg-$FFMPEG_VERSION-$TARGET-dev.zip"
+ FFMPEG_BINARIES="${FFMPEG_TARBALL%%.zip}"
+ if [ ! -d "$FFMPEG_BINARIES" ]
+ then
+ if [ ! -f "$FFMPEG_TARBALL" ]
+ then
+ curl -O $FFMPEG_BUILDS_URL/$TARGET/dev/ffmpeg-$FFMPEG_VERSION-$TARGET-dev.zip
+ else
+ echo "using $FFMPEG_TARBALL"
+ fi
+ unzip -x $FFMPEG_TARBALL
+ else
+ echo "using $FFMPEG_BINARIES"
+ fi
+}
+
+function get_cflags() {
+ CFLAGS="$DEF_CFLAGS"
+ LDFLAGS="$DEF_LDFLAGS"
+ if [ -n "$WITH_FFMEG" ]
+ then
+ fetch_ffpmeg
+ CFLAGS+=" -DHAVE_LIBAV=1 -DHAVE_SWRESAMPLE=1"
+ CFLAGS+=" -I$FFMPEG_BINARIES/include"
+ LDFLAGS+=" -lavcodec -lavformat -lavutil -lswresample"
+ LDFLAGS+=" -L$FFMPEG_BINARIES/lib"
+ fi
+}
+
+function build_mingw() {
+ DESTDIR="$PWD/aubio-$VERSION-$TARGET"
+ [ -n "$WITH_FFMEG" ] && DESTDIR+="-ffmpeg"
+ [ -f $DESTDIR.zip ] && echo "Remove existing $DESTDIR.zip first" && exit 1
+ [ -d $DESTDIR ] && rm -rf $DESTDIR
+ WAFOPTS_TGT="$WAFOPTS --destdir=$DESTDIR"
+ WAFOPTS_TGT+=" --with-target-platform=$TARGET"
+ get_cflags
+ CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" \
+ ./waf distclean configure build install $WAFOPTS_TGT --testcmd='echo %s'
+ zip -r $DESTDIR.zip `basename $DESTDIR`
+ rm -rf $DESTDIR
+ sha256sum $DESTDIR.zip > $DESTDIR.zip.sha256
+}
+
+function build_mingw32() {
+ TARGET=win32
+ export CC=i686-w64-mingw32-gcc
+ build_mingw
+}
+
+function build_mingw64() {
+ TARGET=win64
+ export CC=x86_64-w64-mingw32-gcc
+ build_mingw
+}
+
+# fetch waf if needed
+[ -f "waf" ] || make getwaf
+
+# first build without ffmpeg
+build_mingw32
+build_mingw64
+
+# then build against ffmpeg
+WITH_FFMEG=1
+build_mingw32
+build_mingw64
+
+set +x
+echo ""
+echo "All done! The following files were generated:"
+echo ""
+ls -lart aubio*.zip*
--- a/scripts/get_waf.sh
+++ b/scripts/get_waf.sh
@@ -3,7 +3,7 @@
set -e
set -x
-WAFURL=https://waf.io/waf-1.8.22
+WAFURL=https://waf.io/waf-1.9.6
( which wget > /dev/null && wget -qO waf $WAFURL ) || ( which curl > /dev/null && curl $WAFURL > waf )
--- a/src/io/source_avcodec.c
+++ b/src/io/source_avcodec.c
@@ -24,7 +24,11 @@
#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>
#include <stdlib.h>
@@ -68,7 +72,11 @@
AVCodecContext *avCodecCtx;
AVFrame *avFrame;
AVPacket avPacket;
+#ifdef HAVE_AVRESAMPLE
AVAudioResampleContext *avr;
+#elif defined(HAVE_SWRESAMPLE)
+ SwrContext *avr;
+#endif
smpl_t *output;
uint_t read_samples;
uint_t read_index;
@@ -276,8 +284,13 @@
int64_t input_layout = av_get_default_channel_layout(s->input_channels);
uint_t output_channels = multi ? s->input_channels : 1;
int64_t output_layout = av_get_default_channel_layout(output_channels);
+#ifdef HAVE_AVRESAMPLE
AVAudioResampleContext *avr = avresample_alloc_context();
AVAudioResampleContext *oldavr = s->avr;
+#elif defined(HAVE_SWRESAMPLE)
+ SwrContext *avr = swr_alloc();
+ SwrContext *oldavr = s->avr;
+#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);
@@ -292,7 +305,11 @@
// TODO: use planar?
//av_opt_set_int(avr, "out_sample_fmt", AV_SAMPLE_FMT_FLTP, 0);
int err;
+#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));
AUBIO_ERR("source_avcodec: Could not open AVAudioResampleContext for %s (%s)\n",
@@ -302,7 +319,11 @@
}
s->avr = avr;
if (oldavr != NULL) {
+#ifdef HAVE_AVRESAMPLE
avresample_close( oldavr );
+#elif defined(HAVE_SWRESAMPLE)
+ swr_close ( oldavr );
+#endif /* HAVE_AVRESAMPLE || HAVE_SWRESAMPLE */
av_free ( oldavr );
oldavr = NULL;
}
@@ -316,7 +337,11 @@
AVFrame *avFrame = s->avFrame;
AVPacket avPacket = s->avPacket;
av_init_packet (&avPacket);
+#ifdef HAVE_AVRESAMPLE
AVAudioResampleContext *avr = s->avr;
+#elif defined(HAVE_SWRESAMPLE)
+ SwrContext *avr = s->avr;
+#endif /* HAVE_AVRESAMPLE || HAVE_SWRESAMPLE */
smpl_t *output = s->output;
*read_samples = 0;
@@ -331,6 +356,7 @@
char errorstr[256];
av_strerror (err, errorstr, sizeof(errorstr));
AUBIO_ERR("source_avcodec: could not read frame in %s (%s)\n", s->path, errorstr);
+ s->eof = 1;
goto beach;
}
} while (avPacket.stream_index != s->selected_stream);
@@ -369,6 +395,7 @@
goto beach;
}
+#ifdef HAVE_AVRESAMPLE
int in_linesize = 0;
av_samples_get_buffer_size(&in_linesize, avCodecCtx->channels,
avFrame->nb_samples, avCodecCtx->sample_fmt, 1);
@@ -378,6 +405,13 @@
int 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)
+ int in_samples = avFrame->nb_samples;
+ int max_out_samples = AUBIO_AVCODEC_MAX_BUFFER_SIZE / avCodecCtx->channels;
+ int 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: no sample found while converting frame (%s)\n", s->path);
goto beach;
@@ -389,7 +423,9 @@
s->avFormatCtx = avFormatCtx;
s->avCodecCtx = avCodecCtx;
s->avFrame = avFrame;
+#if defined(HAVE_AVRESAMPLE) || defined(HAVE_SWRESAMPLE)
s->avr = avr;
+#endif /* HAVE_AVRESAMPLE || HAVE_SWRESAMPLE */
s->output = output;
av_packet_unref(&avPacket);
@@ -498,9 +534,14 @@
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;
}
@@ -514,12 +555,20 @@
uint_t aubio_source_avcodec_close(aubio_source_avcodec_t * s) {
if (s->avr != NULL) {
+#ifdef HAVE_AVRESAMPLE
avresample_close( s->avr );
+#elif defined(HAVE_SWRESAMPLE)
+ swr_close ( s->avr );
+#endif
av_free ( s->avr );
}
s->avr = NULL;
if (s->avCodecCtx != NULL) {
+#ifndef HAVE_AUBIO_LIBAVCODEC_DEPRECATED
+ avcodec_free_context( &s->avCodecCtx );
+#else
avcodec_close ( s->avCodecCtx );
+#endif
}
s->avCodecCtx = NULL;
if (s->avFormatCtx != NULL) {
--- a/src/utils/windll.c
+++ b/src/utils/windll.c
@@ -41,9 +41,9 @@
#include "aubio.h"
-BOOL APIENTRY DllMain( HMODULE hModule,
+BOOL APIENTRY DllMain( HMODULE hModule UNUSED,
DWORD ul_reason_for_call,
- LPVOID lpReserved )
+ LPVOID lpReserved UNUSED)
{
switch (ul_reason_for_call)
{
--- a/src/wscript_build
+++ b/src/wscript_build
@@ -7,6 +7,7 @@
uselib += ['SNDFILE']
uselib += ['AVCODEC']
uselib += ['AVFORMAT']
+uselib += ['SWRESAMPLE']
uselib += ['AVRESAMPLE']
uselib += ['AVUTIL']
uselib += ['BLAS']
--- a/wscript
+++ b/wscript
@@ -322,15 +322,31 @@
ctx.check_cfg(package = 'libavutil', atleast_version = '52.3.0',
args = '--cflags --libs', uselib_store = 'AVUTIL',
mandatory = ctx.options.enable_avcodec)
- ctx.check_cfg(package = 'libavresample', atleast_version = '1.0.1',
- args = '--cflags --libs', uselib_store = 'AVRESAMPLE',
- mandatory = ctx.options.enable_avcodec)
- if all ( 'HAVE_' + i in ctx.env
- for i in ['AVCODEC', 'AVFORMAT', 'AVUTIL', 'AVRESAMPLE'] ):
- ctx.define('HAVE_LIBAV', 1)
- ctx.msg('Checking for all libav libraries', 'yes')
+ ctx.check_cfg(package = 'libswresample', atleast_version = '2.3.0',
+ args = '--cflags --libs', uselib_store = 'SWRESAMPLE',
+ mandatory = False)
+ if 'HAVE_SWRESAMPLE' not in ctx.env:
+ ctx.check_cfg(package = 'libavresample', atleast_version = '1.0.1',
+ args = '--cflags --libs', uselib_store = 'AVRESAMPLE',
+ mandatory = False)
+
+ msg_check = 'Checking for all libav libraries'
+ if 'HAVE_AVCODEC' not in ctx.env:
+ ctx.msg(msg_check, 'not found (missing avcodec)', color = 'YELLOW')
+ elif 'HAVE_AVFORMAT' not in ctx.env:
+ ctx.msg(msg_check, 'not found (missing avformat)', color = 'YELLOW')
+ elif 'HAVE_AVUTIL' not in ctx.env:
+ ctx.msg(msg_check, 'not found (missing avutil)', color = 'YELLOW')
+ elif 'HAVE_SWRESAMPLE' not in ctx.env and 'HAVE_AVRESAMPLE' not in ctx.env:
+ resample_missing = 'not found (avresample or swresample required)'
+ ctx.msg(msg_check, resample_missing, color = 'YELLOW')
else:
- ctx.msg('Checking for all libav libraries', 'not found', color = 'YELLOW')
+ ctx.msg(msg_check, 'yes')
+ if 'HAVE_SWRESAMPLE' in ctx.env:
+ ctx.define('HAVE_SWRESAMPLE', 1)
+ elif 'HAVE_AVRESAMPLE' in ctx.env:
+ ctx.define('HAVE_AVRESAMPLE', 1)
+ ctx.define('HAVE_LIBAV', 1)
if (ctx.options.enable_wavread != False):
ctx.define('HAVE_WAVREAD', 1)