FFmpeg
Loading...
Searching...
No Matches
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
22#include "libavutil/mem.h"
23#include "libavutil/x86/cpu.h"
25
26#define D(type, simd) \
27mix_1_1_func_type ff_mix_1_1_a_## type ## _ ## simd;\
28mix_2_1_func_type ff_mix_2_1_a_## type ## _ ## simd;
29
30D(float, sse)
31D(float, avx)
32D(int16, sse2)
33
35 int mm_flags = av_get_cpu_flags();
36 int nb_in = s->used_ch_layout.nb_channels;
37 int nb_out = s->out.ch_count;
38 int num = nb_in * nb_out;
39 int i,j;
40
41 s->mix_1_1_simd = NULL;
42 s->mix_2_1_simd = NULL;
43
44 if (s->midbuf.fmt == AV_SAMPLE_FMT_S16P){
45 if(EXTERNAL_SSE2(mm_flags)) {
46 s->mix_1_1_simd = ff_mix_1_1_a_int16_sse2;
47 s->mix_2_1_simd = ff_mix_2_1_a_int16_sse2;
48 }
49 s->native_simd_matrix = av_calloc(num, 2 * sizeof(int16_t));
50 if (!s->native_simd_matrix)
51 return AVERROR(ENOMEM);
52
53 for(i=0; i<nb_out; i++){
54 int sh = 0;
55 for(j=0; j<nb_in; j++)
56 sh = FFMAX(sh, FFABS(((int*)s->native_matrix)[i * nb_in + j]));
57 sh = FFMAX(av_log2(sh) - 14, 0);
58 for(j=0; j<nb_in; j++) {
59 ((int16_t*)s->native_simd_matrix)[2*(i * nb_in + j)+1] = 15 - sh;
60 ((int16_t*)s->native_simd_matrix)[2*(i * nb_in + j)] =
61 ((((int*)s->native_matrix)[i * nb_in + j]) + (1<<sh>>1)) >> sh;
62 }
63 }
64 s->native_simd_one.i16[1] = 14;
65 s->native_simd_one.i16[0] = 16384;
66 } else if(s->midbuf.fmt == AV_SAMPLE_FMT_FLTP){
67 if(EXTERNAL_SSE(mm_flags)) {
68 s->mix_1_1_simd = ff_mix_1_1_a_float_sse;
69 s->mix_2_1_simd = ff_mix_2_1_a_float_sse;
70 }
71 if(EXTERNAL_AVX_FAST(mm_flags)) {
72 s->mix_1_1_simd = ff_mix_1_1_a_float_avx;
73 s->mix_2_1_simd = ff_mix_2_1_a_float_avx;
74 }
75 s->native_simd_matrix = av_calloc(num, sizeof(float));
76 if (!s->native_simd_matrix)
77 return AVERROR(ENOMEM);
78 memcpy(s->native_simd_matrix, s->native_matrix, num * sizeof(float));
79 s->native_simd_one.f = s->native_one.f;
80 }
81
82 return 0;
83}
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define s(width, name)
Definition cbs_vp9.c:198
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition common.h:74
#define NULL
Definition coverity.c:32
#define AVERROR(e)
Definition error.h:45
@ AV_SAMPLE_FMT_FLTP
float, planar
Definition samplefmt.h:66
@ AV_SAMPLE_FMT_S16P
signed 16 bits, planar
Definition samplefmt.h:64
#define av_log2
Definition intmath.h:84
Macro definitions for various function/variable attributes.
#define av_cold
Definition attributes.h:117
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
Definition cpu.c:109
#define EXTERNAL_SSE(flags)
Definition cpu.h:52
#define EXTERNAL_AVX_FAST(flags)
Definition cpu.h:65
#define EXTERNAL_SSE2(flags)
Definition cpu.h:53
#define FFMAX(a, b)
Definition macros.h:47
void * av_calloc(size_t nmemb, size_t size)
Definition mem.c:264
Memory handling functions.
static int sse(const MPVEncContext *const s, const uint8_t *src1, const uint8_t *src2, int w, int h, int stride)
#define D(type, simd)
The libswresample context.
int swri_rematrix_init_x86(struct SwrContext *s)