From patchwork Tue May 30 06:00:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: plevine457@gmail.com X-Patchwork-Id: 9753853 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3B5CF602BF for ; Tue, 30 May 2017 06:15:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2BBA11FFC9 for ; Tue, 30 May 2017 06:15:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 208EE27E63; Tue, 30 May 2017 06:15:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=no version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E22271FFC9 for ; Tue, 30 May 2017 06:15:14 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 36113266C9B; Tue, 30 May 2017 08:14:39 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id E200C266B02; Tue, 30 May 2017 08:01:14 +0200 (CEST) Received: from mail-qt0-f195.google.com (mail-qt0-f195.google.com [209.85.216.195]) by alsa0.perex.cz (Postfix) with ESMTP id 147EF26680F; Tue, 30 May 2017 08:01:08 +0200 (CEST) Received: by mail-qt0-f195.google.com with SMTP id a46so11296684qte.0; Mon, 29 May 2017 23:01:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:from:to:cc:subject:date; bh=Pykh2H2gzrrV3qI6ark2jEsQW5OjEsBqg6l0yJ+fnhU=; b=LHnkII0qt8iwkmyTVqz9SY8tcDKIbEsbMJnPzie1OP1VO5l+LxWMR033+LSbdAdlpo Tr+Z5nLJUINEFnAfXfEyG4thEZbnb16iUnshGndkw1T9ZNq9cT1xVmFVlwFTvMz1bioH 5eY1+c5OabTyxe5B1GCqOIs/twrwhVBPp48jtmpLEEvmiFfqrbLA/SuGtiULqKufSmnq eMStPZXkmFl8Xc22tF6iH00yTit2p1JTQVAjvK0VB6rryaf4QJwQNV0L9sXBEC4+HWs/ FF0RU5FpNn4kbAMlRXjAcIKpsCKMVfSA3aHn0CPYH/cRs4Hc4hCVijTwjMUE5v8zUI6k UmNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:from:to:cc:subject:date; bh=Pykh2H2gzrrV3qI6ark2jEsQW5OjEsBqg6l0yJ+fnhU=; b=uTkKK96yCi9FbT0LhDsh4stQtvmaTzZc9tmqriwlt3x/FnHVmiTHAsgztZQfx/nL7w K1j/xYOuQa06zPWd4vn92DMtBSgDi8Cxyi1A/r6JC9TF7sfrPucmOWdVM+zdnSMd0YFa YeNYddt6027wDKBQHcSMwXJAeq/7AGIW8XHouKsFgvOa+Zx71aBPpTGhAslZbTGzh3qD OqbDx/ktRHateFSiOiRfPphMlSxuk6Ac0XkKNF6IXl4PjC+0UjWrrdHVDmEBFOFS20lc m/bL1yl/jRJ6B8dnvakltPsd5hXV+/8cn6cS34JGDOC/425eCG7z6F4qxcy+yOLudR7a xqEw== X-Gm-Message-State: AODbwcBUTjD7tFV4xsHeMzIbbDTfnXPuUaa3UoewQhGbNGOh6xAP1gsI CWCEuKTG+7YmIflWCpA= X-Received: by 10.200.49.194 with SMTP id i2mr20547631qte.156.1496124067316; Mon, 29 May 2017 23:01:07 -0700 (PDT) Received: from localhost.localdomain (pool-108-5-228-204.nwrknj.fios.verizon.net. [108.5.228.204]) by smtp.gmail.com with ESMTPSA id c142sm7806127qkb.10.2017.05.29.23.01.05 (version=TLS1_2 cipher=AES128-GCM-SHA256 bits=128/128); Mon, 29 May 2017 23:01:06 -0700 (PDT) Message-ID: <592d0aa2.944e370a.89600.da6b@mx.google.com> X-Google-Original-Message-ID: <20170530060055.25605-1-me> From: plevine457@gmail.com X-Google-Original-From: me To: patch@alsa-project.org Date: Tue, 30 May 2017 02:00:55 -0400 X-Mailer: git-send-email 2.13.0 X-Mailman-Approved-At: Tue, 30 May 2017 08:14:30 +0200 Cc: alsa-devel@alsa-project.org, Peter Levine Subject: [alsa-devel] [PATCH - Fix building alsa-plugins against libav-10 1/1] Fix building alsa-plugins against libav-10 X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP From: Peter Levine Signed-off-by: Peter Levine diff --git a/Makefile.am b/Makefile.am index 69cfe0d..9195b56 100644 --- a/Makefile.am +++ b/Makefile.am @@ -9,8 +9,14 @@ if HAVE_SAMPLERATE SUBDIRS += rate endif if HAVE_AVCODEC +SUBDIRS += a52 +if !HAVE_AVRESAMPLE SUBDIRS += a52 rate-lavc endif +endif +if HAVE_AVRESAMPLE +SUBDIRS += rate-lavr +endif if HAVE_MAEMO_PLUGIN SUBDIRS += maemo endif diff --git a/configure.ac b/configure.ac index f42601c..0af5ec9 100644 --- a/configure.ac +++ b/configure.ac @@ -127,6 +127,10 @@ if test $HAVE_AVCODEC = yes; then if test -z "$AVCODEC_HEADER"; then HAVE_AVCODEC=no fi + SAVE_LIBS=$LIBS + LIBS="$LIBS $AVCODEC_LIBS" + AC_CHECK_FUNCS([av_resample_init]) + LIBS=$SAVE_LIBS CFLAGS="$CFLAGS_saved" fi @@ -135,6 +139,18 @@ AC_SUBST(AVCODEC_CFLAGS) AC_SUBST(AVCODEC_LIBS) AC_SUBST(AVCODEC_HEADER) +AC_ARG_ENABLE([avresample], + AS_HELP_STRING([--disable-avresample], [Do not build plugins depending on avcodec (lavrate)])) + +if test "x$enable_avresample" != "xno"; then + PKG_CHECK_MODULES(AVRESAMPLE, [libavresample libavutil], [HAVE_AVRESAMPLE=yes], [HAVE_AVRESAMPLE=no]) +fi + +AM_CONDITIONAL(HAVE_AVRESAMPLE, test x$HAVE_AVCODEC = xyes) +AC_SUBST(AVRESAMPLE_CFLAGS) +AC_SUBST(AVRESAMPLE_LIBS) +AC_SUBST(AVRESAMPLE_HEADER) + AC_ARG_ENABLE([speexdsp], AS_HELP_STRING([--disable-speexdsp], [Disable building of speexdsp plugin])) @@ -217,7 +233,7 @@ AC_OUTPUT([ mix/Makefile rate/Makefile a52/Makefile - rate-lavc/Makefile + rate-lavr/Makefile maemo/Makefile doc/Makefile usb_stream/Makefile diff --git a/rate-lavr/Makefile.am b/rate-lavr/Makefile.am new file mode 100644 index 0000000..a1dca35 --- /dev/null +++ b/rate-lavr/Makefile.am @@ -0,0 +1,22 @@ +asound_module_rate_lavr_LTLIBRARIES = libasound_module_rate_lavr.la + +asound_module_rate_lavrdir = @ALSA_PLUGIN_DIR@ + +AM_CFLAGS = -Wall -g @ALSA_CFLAGS@ @AVRESAMPLE_CFLAGS@ +AM_LDFLAGS = -module -avoid-version -export-dynamic -no-undefined $(LDFLAGS_NOUNDEFINED) + +libasound_module_rate_lavr_la_SOURCES = rate_lavr.c +libasound_module_rate_lavr_la_LIBADD = @ALSA_LIBS@ @AVRESAMPLE_LIBS@ + + +install-exec-hook: + rm -f $(DESTDIR)@ALSA_PLUGIN_DIR@/libasound_module_rate_lavcrate*.so + $(LN_S) libasound_module_rate_lavr.so $(DESTDIR)@ALSA_PLUGIN_DIR@/libasound_module_rate_lavcrate.so + $(LN_S) libasound_module_rate_lavr.so $(DESTDIR)@ALSA_PLUGIN_DIR@/libasound_module_rate_lavcrate_higher.so + $(LN_S) libasound_module_rate_lavr.so $(DESTDIR)@ALSA_PLUGIN_DIR@/libasound_module_rate_lavcrate_high.so + $(LN_S) libasound_module_rate_lavr.so $(DESTDIR)@ALSA_PLUGIN_DIR@/libasound_module_rate_lavcrate_fast.so + $(LN_S) libasound_module_rate_lavr.so $(DESTDIR)@ALSA_PLUGIN_DIR@/libasound_module_rate_lavcrate_faster.so + +uninstall-hook: + rm -f $(DESTDIR)@ALSA_PLUGIN_DIR@/libasound_module_rate_lavcrate*.so + rm -f $(DESTDIR)@ALSA_PLUGIN_DIR@/libasound_module_rate_lavr*.so diff --git a/rate-lavc/rate_lavcrate.c b/rate-lavr/rate_lavr.c similarity index 58% copy from rate-lavc/rate_lavcrate.c copy to rate-lavr/rate_lavr.c index 14a2198..fe3bf4b 100644 --- a/rate-lavc/rate_lavcrate.c +++ b/rate-lavr/rate_lavr.c @@ -1,9 +1,6 @@ /* - * Rate converter plugin using libavcodec's resampler - * Copyright (c) 2007 by Nicholas Kain - * - * based on rate converter that uses libsamplerate - * Copyright (c) 2006 by Takashi Iwai + * Rate converter plugin using libavresample + * Copyright (c) 2014 by Anton Khirnov * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -19,21 +16,23 @@ #include #include #include -#include AVCODEC_HEADER -#include "gcd.h" + +#include +#include +#include +#include +#include + static int filter_size = 16; static int phase_shift = 10; /* auto-adjusts */ static double cutoff = 0; /* auto-adjusts */ struct rate_src { - struct AVResampleContext *context; + AVAudioResampleContext *avr; + int in_rate; int out_rate; - int stored; - int point; - int16_t **out; - int16_t **in; unsigned int channels; }; @@ -50,26 +49,7 @@ static snd_pcm_uframes_t output_frames(void *obj, snd_pcm_uframes_t frames) static void pcm_src_free(void *obj) { struct rate_src *rate = obj; - int i; - - if (rate->out) { - for (i=0; ichannels; i++) { - free(rate->out[i]); - } - free(rate->out); - } - if (rate->in) { - for (i=0; ichannels; i++) { - free(rate->in[i]); - } - free(rate->in); - } - rate->out = rate->in = NULL; - - if (rate->context) { - av_resample_close(rate->context); - rate->context = NULL; - } + avresample_free(&rate->avr); } static int pcm_src_init(void *obj, snd_pcm_rate_info_t *info) @@ -77,12 +57,14 @@ static int pcm_src_init(void *obj, snd_pcm_rate_info_t *info) struct rate_src *rate = obj; int i, ir, or; - if (! rate->context || rate->channels != info->channels) { + if (!rate->avr || rate->channels != info->channels) { + int ret; + pcm_src_free(rate); rate->channels = info->channels; ir = rate->in_rate = info->in.rate; or = rate->out_rate = info->out.rate; - i = gcd(or, ir); + i = av_gcd(or, ir); if (or > ir) { phase_shift = or/i; } else { @@ -93,25 +75,27 @@ static int pcm_src_init(void *obj, snd_pcm_rate_info_t *info) if (cutoff < 0.80) cutoff = 0.80; } - rate->context = av_resample_init(info->out.rate, info->in.rate, - filter_size, phase_shift, - (info->out.rate >= info->in.rate ? 0 : 1), cutoff); - if (!rate->context) - return -EINVAL; - } - rate->out = malloc(rate->channels * sizeof(int16_t *)); - rate->in = malloc(rate->channels * sizeof(int16_t *)); - for (i=0; ichannels; i++) { - rate->out[i] = calloc(info->out.period_size * 2, - sizeof(int16_t)); - rate->in[i] = calloc(info->in.period_size * 2, - sizeof(int16_t)); - } - rate->point = info->in.period_size / 2; - if (!rate->out || !rate->in) { - pcm_src_free(rate); - return -ENOMEM; + rate->avr = avresample_alloc_context(); + if (!rate->avr) + return -ENOMEM; + + av_opt_set_int(rate->avr, "in_sample_rate", info->in.rate, 0); + av_opt_set_int(rate->avr, "out_sample_rate", info->out.rate, 0); + av_opt_set_int(rate->avr, "in_sample_format", AV_SAMPLE_FMT_S16, 0); + av_opt_set_int(rate->avr, "out_sample_format", AV_SAMPLE_FMT_S16, 0); + av_opt_set_int(rate->avr, "in_channel_layout", av_get_default_channel_layout(rate->channels), 0); + av_opt_set_int(rate->avr, "out_channel_layout", av_get_default_channel_layout(rate->channels), 0); + + av_opt_set_int(rate->avr, "filter_size", filter_size, 0); + av_opt_set_int(rate->avr, "phase_shift", phase_shift, 0); + av_opt_set_double(rate->avr, "cutoff", cutoff, 0); + + ret = avresample_open(rate->avr); + if (ret < 0) { + avresample_free(&rate->avr); + return -EINVAL; + } } return 0; @@ -129,48 +113,10 @@ static int pcm_src_adjust_pitch(void *obj, snd_pcm_rate_info_t *info) static void pcm_src_reset(void *obj) { struct rate_src *rate = obj; - rate->stored = 0; -} -static void deinterleave(const int16_t *src, int16_t **dst, unsigned int frames, - unsigned int chans, int overflow) -{ - int i, j; - - if (chans == 1) { - memcpy(dst + overflow, src, frames*sizeof(int16_t)); - } else if (chans == 2) { - for (j=overflow; j<(frames + overflow); j++) { - dst[0][j] = *(src++); - dst[1][j] = *(src++); - } - } else { - for (j=overflow; j<(frames + overflow); j++) { - for (i=0; iavr) { + avresample_close(rate->avr); + avresample_open(rate->avr); } } @@ -179,22 +125,13 @@ static void pcm_src_convert_s16(void *obj, int16_t *dst, unsigned int { struct rate_src *rate = obj; int consumed = 0, chans=rate->channels, ret=0, i; - int total_in = rate->stored + src_frames, new_stored; - - deinterleave(src, rate->in, src_frames, chans, rate->point); - for (i=0; icontext, rate->out[i], - rate->in[i]+rate->point-rate->stored, &consumed, - total_in, dst_frames, i == (chans - 1)); - new_stored = total_in-consumed; - memmove(rate->in[i]+rate->point-new_stored, - rate->in[i]+rate->point-rate->stored+consumed, - new_stored*sizeof(int16_t)); - } - av_resample_compensate(rate->context, - total_in-src_frames>filter_size?0:1, src_frames); - reinterleave(rate->out, dst, ret, chans); - rate->stored = total_in-consumed; + int total_in = avresample_get_delay(rate->avr) + src_frames; + + ret = avresample_convert(rate->avr, &dst, dst_frames * chans * 2, dst_frames, + &src, src_frames * chans * 2, src_frames); + + avresample_set_compensation(rate->avr, + total_in - src_frames > filter_size ? 0 : 1, src_frames); } static void pcm_src_close(void *obj) @@ -212,7 +149,7 @@ static int get_supported_rates(void *obj, unsigned int *rate_min, static void dump(void *obj, snd_output_t *out) { - snd_output_printf(out, "Converter: liblavc\n"); + snd_output_printf(out, "Converter: libavr\n"); } #endif @@ -220,7 +157,6 @@ static snd_pcm_rate_ops_t pcm_src_ops = { .close = pcm_src_close, .init = pcm_src_init, .free = pcm_src_free, - .reset = pcm_src_reset, .adjust_pitch = pcm_src_adjust_pitch, .convert_s16 = pcm_src_convert_s16, .input_frames = input_frames, @@ -248,7 +184,7 @@ int pcm_src_open(unsigned int version, void **objp, snd_pcm_rate_ops_t *ops) return -ENOMEM; *objp = rate; - rate->context = NULL; + rate->avr = NULL; #if SND_PCM_RATE_PLUGIN_VERSION >= 0x010002 if (version == 0x010001) memcpy(ops, &pcm_src_ops, sizeof(snd_pcm_rate_old_ops_t));