[FFmpeg-devel] [PATCH v2] examples: add flac_test

Michael Niedermayer michaelni at gmx.at
Tue Apr 14 21:35:23 CEST 2015


On Tue, Apr 14, 2015 at 04:03:40AM +0300, Ludmila Glinskih wrote:
> This is a simple test for the FLAC codec.
> It generates an increasing tone, encodes it, decodes it back and
> compares with the original one byte-by-byte.
> ---
>  configure                |   2 +
>  doc/Makefile             |   1 +
>  doc/examples/Makefile    |   1 +
>  doc/examples/flac_test.c | 295 +++++++++++++++++++++++++++++++++++++++++++++++
>  4 files changed, 299 insertions(+)
>  create mode 100644 doc/examples/flac_test.c
> 
> diff --git a/configure b/configure
> index bc59271..5650ef8 100755
> --- a/configure
> +++ b/configure
> @@ -1329,6 +1329,7 @@ EXAMPLE_LIST="
>      filter_audio_example
>      filtering_audio_example
>      filtering_video_example
> +    flac_test_example
>      metadata_example
>      muxing_example
>      qsvdec_example
> @@ -2679,6 +2680,7 @@ extract_mvs_example_deps="avcodec avformat avutil"
>  filter_audio_example_deps="avfilter avutil"
>  filtering_audio_example_deps="avfilter avcodec avformat avutil"
>  filtering_video_example_deps="avfilter avcodec avformat avutil"
> +flac_test_example_deps="avcodec avutil"
>  metadata_example_deps="avformat avutil"
>  muxing_example_deps="avcodec avformat avutil swscale"
>  qsvdec_example_deps="avcodec avutil libmfx h264_qsv_decoder vaapi_x11"
> diff --git a/doc/Makefile b/doc/Makefile
> index 4573531..f462acc 100644
> --- a/doc/Makefile
> +++ b/doc/Makefile
> @@ -45,6 +45,7 @@ DOC_EXAMPLES-$(CONFIG_EXTRACT_MVS_EXAMPLE)       += extract_mvs
>  DOC_EXAMPLES-$(CONFIG_FILTER_AUDIO_EXAMPLE)      += filter_audio
>  DOC_EXAMPLES-$(CONFIG_FILTERING_AUDIO_EXAMPLE)   += filtering_audio
>  DOC_EXAMPLES-$(CONFIG_FILTERING_VIDEO_EXAMPLE)   += filtering_video
> +DOC_EXAMPLES-$(CONFIG_FLAC_TEST_EXAMPLE)         += flac_test
>  DOC_EXAMPLES-$(CONFIG_METADATA_EXAMPLE)          += metadata
>  DOC_EXAMPLES-$(CONFIG_MUXING_EXAMPLE)            += muxing
>  DOC_EXAMPLES-$(CONFIG_QSVDEC_EXAMPLE)            += qsvdec
> diff --git a/doc/examples/Makefile b/doc/examples/Makefile
> index 9699f11..72a2fb6 100644
> --- a/doc/examples/Makefile
> +++ b/doc/examples/Makefile
> @@ -18,6 +18,7 @@ EXAMPLES=       avio_list_dir                      \
>                  extract_mvs                        \
>                  filtering_video                    \
>                  filtering_audio                    \
> +                flac_test                          \
>                  metadata                           \
>                  muxing                             \
>                  remuxing                           \
> diff --git a/doc/examples/flac_test.c b/doc/examples/flac_test.c
> new file mode 100644
> index 0000000..392c50c
> --- /dev/null
> +++ b/doc/examples/flac_test.c
> @@ -0,0 +1,295 @@
> +/*
> + * Copyright (c) 2015 Ludmila Glinskih
> + * Copyright (c) 2001 Fabrice Bellard
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a copy
> + * of this software and associated documentation files (the "Software"), to deal
> + * in the Software without restriction, including without limitation the rights
> + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> + * copies of the Software, and to permit persons to whom the Software is
> + * furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
> + * THE SOFTWARE.
> + */
> +
> +/*
> + * FLAC codec test.
> + * Encodes raw data to FLAC format and decodes it back to raw. Compares raw-data
> + * after that.
> + */
> +
> +#include <libavcodec/avcodec.h>
> +#include <libavutil/common.h>
> +#include <libavutil/samplefmt.h>
> +

> +#define NUMBER_OF_FRAMES 200
> +#define NAME_BUFF_SIZE 100
> +
> +/* generate i-th frame of test audio */
> +static int generate_raw_frame(uint16_t *frame_data, int i, int sample_rate,
> +                              int channels, int frame_size)
> +{
> +    double t, tincr, tincr2;
> +    int j, k;
> +
> +    t = 0.0;
> +    tincr = 2 * M_PI * 440.0 / sample_rate;
> +    tincr2 = tincr / sample_rate;
> +    for (j = 0; j < frame_size; j++)
> +    {
> +        frame_data[channels * j] = (int)(sin(t) * 10000);
> +        for (k = 1; k < channels; k++)
> +            frame_data[channels * j + k] = frame_data[channels * j] * 2;
> +        t = i * tincr + (i * (i + 1) / 2.0 * tincr2);
> +    }
> +    return 0;
> +}

please avoid float/double
see tests/audiogen.c as an example or maybe better use tests/audiogen
so no code is duplicated

also the test should be used/be tested in make fate

Thanks

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Freedom in capitalist society always remains about the same as it was in
ancient Greek republics: Freedom for slave owners. -- Vladimir Lenin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20150414/d8d9a514/attachment.asc>


More information about the ffmpeg-devel mailing list