FFmpeg
rematrix_init.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Michael Niedermayer (michaelni@gmx.at)
3  *
4  * This file is part of libswresample
5  *
6  * libswresample 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  * libswresample 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 libswresample; 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 "libavutil/x86/cpu.h"
24 
25 #define D(type, simd) \
26 mix_1_1_func_type ff_mix_1_1_a_## type ## _ ## simd;\
27 mix_2_1_func_type ff_mix_2_1_a_## type ## _ ## simd;
28 
29 D(float, sse)
30 D(float, avx)
31 D(int16, mmx)
32 D(int16, sse2)
33 
35 #if HAVE_X86ASM
36  int mm_flags = av_get_cpu_flags();
37  int nb_in = s->used_ch_count;
38  int nb_out = s->out.ch_count;
39  int num = nb_in * nb_out;
40  int i,j;
41 
42  s->mix_1_1_simd = NULL;
43  s->mix_2_1_simd = NULL;
44 
45  if (s->midbuf.fmt == AV_SAMPLE_FMT_S16P){
46  if(EXTERNAL_MMX(mm_flags)) {
47  s->mix_1_1_simd = ff_mix_1_1_a_int16_mmx;
48  s->mix_2_1_simd = ff_mix_2_1_a_int16_mmx;
49  }
50  if(EXTERNAL_SSE2(mm_flags)) {
51  s->mix_1_1_simd = ff_mix_1_1_a_int16_sse2;
52  s->mix_2_1_simd = ff_mix_2_1_a_int16_sse2;
53  }
54  s->native_simd_matrix = av_calloc(num, 2 * sizeof(int16_t));
55  s->native_simd_one = av_mallocz(2 * sizeof(int16_t));
56  if (!s->native_simd_matrix || !s->native_simd_one)
57  return AVERROR(ENOMEM);
58 
59  for(i=0; i<nb_out; i++){
60  int sh = 0;
61  for(j=0; j<nb_in; j++)
62  sh = FFMAX(sh, FFABS(((int*)s->native_matrix)[i * nb_in + j]));
63  sh = FFMAX(av_log2(sh) - 14, 0);
64  for(j=0; j<nb_in; j++) {
65  ((int16_t*)s->native_simd_matrix)[2*(i * nb_in + j)+1] = 15 - sh;
66  ((int16_t*)s->native_simd_matrix)[2*(i * nb_in + j)] =
67  ((((int*)s->native_matrix)[i * nb_in + j]) + (1<<sh>>1)) >> sh;
68  }
69  }
70  ((int16_t*)s->native_simd_one)[1] = 14;
71  ((int16_t*)s->native_simd_one)[0] = 16384;
72  } else if(s->midbuf.fmt == AV_SAMPLE_FMT_FLTP){
73  if(EXTERNAL_SSE(mm_flags)) {
74  s->mix_1_1_simd = ff_mix_1_1_a_float_sse;
75  s->mix_2_1_simd = ff_mix_2_1_a_float_sse;
76  }
77  if(EXTERNAL_AVX_FAST(mm_flags)) {
78  s->mix_1_1_simd = ff_mix_1_1_a_float_avx;
79  s->mix_2_1_simd = ff_mix_2_1_a_float_avx;
80  }
81  s->native_simd_matrix = av_calloc(num, sizeof(float));
82  s->native_simd_one = av_mallocz(sizeof(float));
83  if (!s->native_simd_matrix || !s->native_simd_one)
84  return AVERROR(ENOMEM);
85  memcpy(s->native_simd_matrix, s->native_matrix, num * sizeof(float));
86  memcpy(s->native_simd_one, s->native_one, sizeof(float));
87  }
88 #endif
89 
90  return 0;
91 }
AV_SAMPLE_FMT_FLTP
@ AV_SAMPLE_FMT_FLTP
float, planar
Definition: samplefmt.h:69
cpu.h
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
swri_rematrix_init_x86
int swri_rematrix_init_x86(struct SwrContext *s)
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
av_get_cpu_flags
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
Definition: cpu.c:98
D
#define D(type, simd)
Definition: rematrix_init.c:25
av_cold
#define av_cold
Definition: attributes.h:90
s
#define s(width, name)
Definition: cbs_vp9.c:257
EXTERNAL_SSE
#define EXTERNAL_SSE(flags)
Definition: cpu.h:58
sse
static int sse(MpegEncContext *s, uint8_t *src1, uint8_t *src2, int w, int h, int stride)
Definition: mpegvideo_enc.c:2571
EXTERNAL_AVX_FAST
#define EXTERNAL_AVX_FAST(flags)
Definition: cpu.h:71
SwrContext
The libswresample context.
Definition: swresample_internal.h:95
FFABS
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:65
NULL
#define NULL
Definition: coverity.c:32
swresample_internal.h
attributes.h
EXTERNAL_SSE2
#define EXTERNAL_SSE2(flags)
Definition: cpu.h:59
AV_SAMPLE_FMT_S16P
@ AV_SAMPLE_FMT_S16P
signed 16 bits, planar
Definition: samplefmt.h:67
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:271
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:263
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:271
EXTERNAL_MMX
#define EXTERNAL_MMX(flags)
Definition: cpu.h:56
av_log2
int av_log2(unsigned v)
Definition: intmath.c:26