LCOV - code coverage report
Current view: top level - tests/checkasm - flacdsp.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 29 30 96.7 %
Date: 2017-12-16 01:21:47 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2015 James Almer
       3             :  *
       4             :  * This file is part of FFmpeg.
       5             :  *
       6             :  * FFmpeg is free software; you can redistribute it and/or modify
       7             :  * it under the terms of the GNU General Public License as published by
       8             :  * the Free Software Foundation; either version 2 of the License, or
       9             :  * (at your option) any later version.
      10             :  *
      11             :  * FFmpeg is distributed in the hope that it will be useful,
      12             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14             :  * GNU General Public License for more details.
      15             :  *
      16             :  * You should have received a copy of the GNU General Public License along
      17             :  * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
      18             :  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
      19             :  */
      20             : 
      21             : #include <string.h>
      22             : #include "checkasm.h"
      23             : #include "libavcodec/flacdsp.h"
      24             : #include "libavutil/common.h"
      25             : #include "libavutil/internal.h"
      26             : #include "libavutil/intreadwrite.h"
      27             : 
      28             : #define BUF_SIZE 256
      29             : #define MAX_CHANNELS 8
      30             : 
      31             : #define randomize_buffers()                                 \
      32             :     do {                                                    \
      33             :         int i, j;                                           \
      34             :         for (i = 0; i < BUF_SIZE; i += 4) {                 \
      35             :             for (j = 0; j < channels; j++) {                \
      36             :                 uint32_t r = rnd() & (1 << (bits - 2)) - 1; \
      37             :                 AV_WN32A(ref_src[j] + i, r);                \
      38             :                 AV_WN32A(new_src[j] + i, r);                \
      39             :             }                                               \
      40             :         }                                                   \
      41             :     } while (0)
      42             : 
      43          32 : static void check_decorrelate(uint8_t **ref_dst, uint8_t **ref_src, uint8_t **new_dst, uint8_t **new_src,
      44             :                               int channels, int bits) {
      45          32 :     declare_func(void, uint8_t **out, int32_t **in, int channels, int len, int shift);
      46             : 
      47          32 :     randomize_buffers();
      48          32 :     call_ref(ref_dst, (int32_t **)ref_src, channels, BUF_SIZE / sizeof(int32_t), 8);
      49          32 :     call_new(new_dst, (int32_t **)new_src, channels, BUF_SIZE / sizeof(int32_t), 8);
      50          64 :     if (memcmp(*ref_dst, *new_dst, bits == 16 ? BUF_SIZE * (channels/2) : BUF_SIZE * channels) ||
      51          32 :         memcmp(*ref_src, *new_src, BUF_SIZE * channels))
      52           0 :         fail();
      53          32 :     bench_new(new_dst, (int32_t **)new_src, channels, BUF_SIZE / sizeof(int32_t), 8);
      54          32 : }
      55             : 
      56          13 : void checkasm_check_flacdsp(void)
      57             : {
      58          13 :     LOCAL_ALIGNED_16(uint8_t, ref_dst, [BUF_SIZE*MAX_CHANNELS]);
      59          13 :     LOCAL_ALIGNED_16(uint8_t, ref_buf, [BUF_SIZE*MAX_CHANNELS]);
      60          13 :     LOCAL_ALIGNED_16(uint8_t, new_dst, [BUF_SIZE*MAX_CHANNELS]);
      61          13 :     LOCAL_ALIGNED_16(uint8_t, new_buf, [BUF_SIZE*MAX_CHANNELS]);
      62          65 :     uint8_t *ref_src[] = { &ref_buf[BUF_SIZE*0], &ref_buf[BUF_SIZE*1], &ref_buf[BUF_SIZE*2], &ref_buf[BUF_SIZE*3],
      63          52 :                            &ref_buf[BUF_SIZE*4], &ref_buf[BUF_SIZE*5], &ref_buf[BUF_SIZE*6], &ref_buf[BUF_SIZE*7] };
      64          65 :     uint8_t *new_src[] = { &new_buf[BUF_SIZE*0], &new_buf[BUF_SIZE*1], &new_buf[BUF_SIZE*2], &new_buf[BUF_SIZE*3],
      65          52 :                            &new_buf[BUF_SIZE*4], &new_buf[BUF_SIZE*5], &new_buf[BUF_SIZE*6], &new_buf[BUF_SIZE*7] };
      66             :     static const char * const names[3] = { "ls", "rs", "ms" };
      67             :     static const struct {
      68             :         enum AVSampleFormat fmt;
      69             :         int bits;
      70             :     } fmts[] = {
      71             :         { AV_SAMPLE_FMT_S16, 16 },
      72             :         { AV_SAMPLE_FMT_S32, 32 },
      73             :     };
      74             :     FLACDSPContext h;
      75             :     int i, j;
      76             : 
      77          39 :     for (i = 0; i < 2; i++) {
      78          26 :         ff_flacdsp_init(&h, fmts[i].fmt, 2, 0);
      79         104 :         for (j = 0; j < 3; j++)
      80          78 :             if (check_func(h.decorrelate[j], "flac_decorrelate_%s_%d", names[j], fmts[i].bits))
      81          12 :                 check_decorrelate(&ref_dst, ref_src, &new_dst, new_src, 2, fmts[i].bits);
      82         130 :         for (j = 2; j <= MAX_CHANNELS; j += 2) {
      83         104 :             ff_flacdsp_init(&h, fmts[i].fmt, j, 0);
      84         104 :             if (check_func(h.decorrelate[0], "flac_decorrelate_indep%d_%d", j, fmts[i].bits))
      85          20 :                 check_decorrelate(&ref_dst, ref_src, &new_dst, new_src, j, fmts[i].bits);
      86             :         }
      87             :     }
      88             : 
      89          13 :     report("decorrelate");
      90          13 : }

Generated by: LCOV version 1.13