FFmpeg
flacdsp_init.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 James Almer
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (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 GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include "libavutil/attributes.h"
22 #include "libavcodec/flacdsp.h"
23 #include "libavutil/x86/cpu.h"
24 #include "config.h"
25 #include "config_components.h"
26 
27 void ff_flac_lpc_32_sse4(int32_t *samples, const int coeffs[32], int order,
28  int qlevel, int len);
29 void ff_flac_lpc_32_xop(int32_t *samples, const int coeffs[32], int order,
30  int qlevel, int len);
31 
32 void ff_flac_enc_lpc_16_sse4(int32_t *, const int32_t *, int, int, const int32_t *,int);
33 
34 #define DECORRELATE_FUNCS(fmt, opt) \
35 void ff_flac_decorrelate_ls_##fmt##_##opt(uint8_t **out, int32_t **in, int channels, \
36  int len, int shift); \
37 void ff_flac_decorrelate_rs_##fmt##_##opt(uint8_t **out, int32_t **in, int channels, \
38  int len, int shift); \
39 void ff_flac_decorrelate_ms_##fmt##_##opt(uint8_t **out, int32_t **in, int channels, \
40  int len, int shift); \
41 void ff_flac_decorrelate_indep2_##fmt##_##opt(uint8_t **out, int32_t **in, int channels, \
42  int len, int shift); \
43 void ff_flac_decorrelate_indep4_##fmt##_##opt(uint8_t **out, int32_t **in, int channels, \
44  int len, int shift); \
45 void ff_flac_decorrelate_indep6_##fmt##_##opt(uint8_t **out, int32_t **in, int channels, \
46  int len, int shift); \
47 void ff_flac_decorrelate_indep8_##fmt##_##opt(uint8_t **out, int32_t **in, int channels, \
48  int len, int shift)
49 
50 DECORRELATE_FUNCS(16, sse2);
51 DECORRELATE_FUNCS(16, avx);
52 DECORRELATE_FUNCS(32, sse2);
53 DECORRELATE_FUNCS(32, avx);
54 
56  int bps)
57 {
58 #if HAVE_X86ASM
60 
61 #if CONFIG_FLAC_DECODER
62  if (EXTERNAL_SSE2(cpu_flags)) {
63  if (fmt == AV_SAMPLE_FMT_S16) {
64  if (channels == 2)
65  c->decorrelate[0] = ff_flac_decorrelate_indep2_16_sse2;
66  else if (channels == 4)
67  c->decorrelate[0] = ff_flac_decorrelate_indep4_16_sse2;
68  else if (channels == 6)
69  c->decorrelate[0] = ff_flac_decorrelate_indep6_16_sse2;
70  else if (ARCH_X86_64 && channels == 8)
71  c->decorrelate[0] = ff_flac_decorrelate_indep8_16_sse2;
72  c->decorrelate[1] = ff_flac_decorrelate_ls_16_sse2;
73  c->decorrelate[2] = ff_flac_decorrelate_rs_16_sse2;
74  c->decorrelate[3] = ff_flac_decorrelate_ms_16_sse2;
75  } else if (fmt == AV_SAMPLE_FMT_S32) {
76  if (channels == 2)
77  c->decorrelate[0] = ff_flac_decorrelate_indep2_32_sse2;
78  else if (channels == 4)
79  c->decorrelate[0] = ff_flac_decorrelate_indep4_32_sse2;
80  else if (channels == 6)
81  c->decorrelate[0] = ff_flac_decorrelate_indep6_32_sse2;
82  else if (ARCH_X86_64 && channels == 8)
83  c->decorrelate[0] = ff_flac_decorrelate_indep8_32_sse2;
84  c->decorrelate[1] = ff_flac_decorrelate_ls_32_sse2;
85  c->decorrelate[2] = ff_flac_decorrelate_rs_32_sse2;
86  c->decorrelate[3] = ff_flac_decorrelate_ms_32_sse2;
87  }
88  }
89  if (EXTERNAL_SSE4(cpu_flags)) {
90  c->lpc32 = ff_flac_lpc_32_sse4;
91  }
92  if (EXTERNAL_AVX(cpu_flags)) {
93  if (fmt == AV_SAMPLE_FMT_S16) {
94  if (ARCH_X86_64 && channels == 8)
95  c->decorrelate[0] = ff_flac_decorrelate_indep8_16_avx;
96  } else if (fmt == AV_SAMPLE_FMT_S32) {
97  if (channels == 4)
98  c->decorrelate[0] = ff_flac_decorrelate_indep4_32_avx;
99  else if (channels == 6)
100  c->decorrelate[0] = ff_flac_decorrelate_indep6_32_avx;
101  else if (ARCH_X86_64 && channels == 8)
102  c->decorrelate[0] = ff_flac_decorrelate_indep8_32_avx;
103  }
104  }
105  if (EXTERNAL_XOP(cpu_flags)) {
106  c->lpc32 = ff_flac_lpc_32_xop;
107  }
108 #endif
109 
110 #if CONFIG_FLAC_ENCODER
111  if (EXTERNAL_SSE4(cpu_flags)) {
112  if (CONFIG_GPL)
113  c->lpc16_encode = ff_flac_enc_lpc_16_sse4;
114  }
115 #endif
116 #endif /* HAVE_X86ASM */
117 }
cpu.h
ff_flac_lpc_32_xop
void ff_flac_lpc_32_xop(int32_t *samples, const int coeffs[32], int order, int qlevel, int len)
av_get_cpu_flags
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
Definition: cpu.c:101
flacdsp.h
cpu_flags
static atomic_int cpu_flags
Definition: cpu.c:52
av_cold
#define av_cold
Definition: attributes.h:90
ff_flac_lpc_32_sse4
void ff_flac_lpc_32_sse4(int32_t *samples, const int coeffs[32], int order, int qlevel, int len)
ff_flac_enc_lpc_16_sse4
void ff_flac_enc_lpc_16_sse4(int32_t *, const int32_t *, int, int, const int32_t *, int)
channels
channels
Definition: aptx.h:32
EXTERNAL_XOP
#define EXTERNAL_XOP(flags)
Definition: cpu.h:73
DECORRELATE_FUNCS
#define DECORRELATE_FUNCS(fmt, opt)
Definition: flacdsp_init.c:34
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
bps
unsigned bps
Definition: movenc.c:1647
attributes.h
EXTERNAL_SSE2
#define EXTERNAL_SSE2(flags)
Definition: cpu.h:59
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:55
AV_SAMPLE_FMT_S16
@ AV_SAMPLE_FMT_S16
signed 16 bits
Definition: samplefmt.h:58
len
int len
Definition: vorbis_enc_data.h:426
EXTERNAL_AVX
#define EXTERNAL_AVX(flags)
Definition: cpu.h:70
EXTERNAL_SSE4
#define EXTERNAL_SSE4(flags)
Definition: cpu.h:68
ff_flacdsp_init_x86
av_cold void ff_flacdsp_init_x86(FLACDSPContext *c, enum AVSampleFormat fmt, int channels, int bps)
Definition: flacdsp_init.c:55
samples
Filter the word “frame” indicates either a video frame or a group of audio samples
Definition: filter_design.txt:8
int32_t
int32_t
Definition: audioconvert.c:56
AV_SAMPLE_FMT_S32
@ AV_SAMPLE_FMT_S32
signed 32 bits
Definition: samplefmt.h:59
FLACDSPContext
Definition: flacdsp.h:26