[FFmpeg-devel] [OPW] OPW Project Proposal

Michael Niedermayer michael at niedermayer.cc
Fri Nov 4 11:59:21 EET 2016


On Fri, Nov 04, 2016 at 07:46:34AM +0530, Pallavi Kumari wrote:
> Updated patch attached. PFA
[...]

>  Makefile        |    1 
>  af_peakpoints.c |  263 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  allfilters.c    |    1 
>  version.h       |    2 
>  4 files changed, 266 insertions(+), 1 deletion(-)
> 7f6affa8dcb632cdea162553a18ab1489f0783ce  0001-avfilter-added-peakpoints-filter.patch
> From 46be941c87713f8afee686eed0262ca59a2896fd Mon Sep 17 00:00:00 2001
> From: Atana <atana at openmailbox.org>
> Date: Fri, 4 Nov 2016 07:43:29 +0530
> Subject: [PATCH] avfilter: added peakpoints filter
> 
> ---
>  libavfilter/Makefile        |   1 +
>  libavfilter/af_peakpoints.c | 263 ++++++++++++++++++++++++++++++++++++++++++++
>  libavfilter/allfilters.c    |   1 +
>  libavfilter/version.h       |   2 +-
>  4 files changed, 266 insertions(+), 1 deletion(-)
>  create mode 100644 libavfilter/af_peakpoints.c
> 
> diff --git a/libavfilter/Makefile b/libavfilter/Makefile
> index 7ed4696..1a18902 100644
> --- a/libavfilter/Makefile
> +++ b/libavfilter/Makefile
> @@ -96,6 +96,7 @@ OBJS-$(CONFIG_LADSPA_FILTER)                 += af_ladspa.o
>  OBJS-$(CONFIG_LOUDNORM_FILTER)               += af_loudnorm.o
>  OBJS-$(CONFIG_LOWPASS_FILTER)                += af_biquads.o
>  OBJS-$(CONFIG_PAN_FILTER)                    += af_pan.o
> +OBJS-$(CONFIG_PEAKPOINTS_FILTER)             += af_peakpoints.o
>  OBJS-$(CONFIG_REPLAYGAIN_FILTER)             += af_replaygain.o
>  OBJS-$(CONFIG_RESAMPLE_FILTER)               += af_resample.o
>  OBJS-$(CONFIG_RUBBERBAND_FILTER)             += af_rubberband.o
> diff --git a/libavfilter/af_peakpoints.c b/libavfilter/af_peakpoints.c
> new file mode 100644
> index 0000000..da108ca
> --- /dev/null
> +++ b/libavfilter/af_peakpoints.c
> @@ -0,0 +1,263 @@
> +/*
> + * Copyright (c) 2016 Atana
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> + */
> +
> +#include "libavcodec/avcodec.h"
> +#include "libavcodec/avfft.h"
> +#include "libavformat/avformat.h"
> +#include "libswscale/swscale.h"
> +#include "avfilter.h"
> +#include "audio.h"
> +#include "libavutil/opt.h"
> +
> +#define SIZECHECK 4096
> +
> +/* Structure to contain peak points context */
> +typedef struct {
> +    const AVClass *class;
> +    double *data;
> +    int nsamples;
> +    int index;
> +    int isOnce;
> +    int buffFlag;
> +    double *peaks;
> +    int size; // number of peaks
> +    int windowSize;
> +    //char *inputFile;
> +} PeakPointsContext;
> +
> +/* returns maximum value from an array conditioned on start and end index */
> +static double getMax(double *res_arr, int startIndex, int endIndex) {
> +    int i;
> +    double max = res_arr[startIndex];
> +    for (i = startIndex; i <= endIndex; i++) {
> +	    if (res_arr[i] > max) {
> +	        max = res_arr[i];
> +	    }
> +    }

tabs are forbidden in ffmpeg git


> +    return max;
> +}
> +
> +/* Stores peak frequency for each window(of chunkSize) in peaks array */
> +static void getPeakPointInChunk(int chunkSize, double *res_arr, int size, double *peaks) {
> +    int i = 0, peakIndex = 0;
> +    int startIndex = 0;
> +    double max;
> +    // get a chunk and find max value in it
> +    while (i < size) {
> +	    if (i % chunkSize-1 == 0) {
> +            max = getMax(res_arr, startIndex, i);
> +	        peaks[peakIndex++] = max;
> +	        startIndex = startIndex + chunkSize;
> +	    }
> +        i += 1;
> +    }
> +}
> +
> +/* Get peaks points from windowed frequency domain data*/
> +static int getPeakPoints(PeakPointsContext *ppc) {
> +    int i, m, k, size, chunkSize, pSize, chunkSampleSize, resSize;
> +    double *fft_res;
> +    void *avc;
> +    RDFTContext *rdftC;
> +    FFTSample *data;
> +
> +    size = ppc->index;
> +    m = log2(ppc->windowSize);
> +    chunkSize = ppc->windowSize;
> +    chunkSampleSize = size/chunkSize;
> +    resSize = chunkSize * chunkSampleSize;
> +

> +    fft_res = av_malloc_array(resSize, sizeof(double));

This seems never freed


> +
> +    if (!fft_res) {
> +        av_log(avc, AV_LOG_ERROR, "Cann't allocate memmory for storing fft data\n");
> +        return 0;
> +    }
> +
> +
> +    rdftC = av_rdft_init(m, DFT_R2C);
> +    data = av_malloc_array(chunkSize, sizeof(FFTSample));
> +
> +    if (!data) {
> +        av_log(avc, AV_LOG_ERROR, "Cann't allocate memmory for chunk fft data\n");
> +        return 0;
> +    }
> +    // FFT transform for windowed time domain data
> +    // window is of size chunkSize
> +    k = 0;
> +    while (k < resSize) {
> +        //copy data
> +        for (i = 0; i < chunkSize; i++) {
> +            data[i] = ppc->data[i+k];
> +        }
> +        //calculate FFT
> +        av_rdft_calc(rdftC, data);
> +        for (i = 0; i < chunkSize; i++) {
> +	    fft_res[i+k] = data[i];
> +        }
> +        k = k + chunkSize;
> +    }
> +
> +    av_rdft_end(rdftC);
> +    pSize = resSize/chunkSize;
> +    ppc->size = pSize;

> +    ppc->peaks = av_malloc_array(pSize, sizeof(double));

This is allocated potentially durng each filter_frame
but only deallocated once at the end, all except the last thus leak


[...]
> +static int filter_frame(AVFilterLink *inlink, AVFrame *samples)
> +{
> +    AVFilterContext *ctx = inlink->dst;
> +    PeakPointsContext *p = ctx->priv;
> +    int i, nb_samples = samples->nb_samples;
> +
> +    // store audio data
> +    for (i = 0; i < nb_samples; i++) {

> +        p->data[p->index] = (double)samples->data[0][i];

This reads the double values as 8bit integers, you have to cast to
a pointer to double and dereference it to read the double values


[...]


-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Breaking DRM is a little like attempting to break through a door even
though the window is wide open and the only thing in the house is a bunch
of things you dont want and which you would get tomorrow for free anyway
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20161104/1234d55c/attachment.sig>


More information about the ffmpeg-devel mailing list