Unified · Split
| @@ -52,197 +52,91 @@ typedef struct ThreadData { · 51 unmodified lines | |||
| 52 | float mult; | 52 | float mult; |
| 53 | } ThreadData; | 53 | } ThreadData; |
| 54 | 54 | ||
| 55 | static av_always_inline int filter_flt(AVFilterContext *ctx, void *arg, | 55 | #define filters(fmt, type, inverse, clp, inverset, clip, one, clip_fn, packed) \ |
| 56 | int jobnr, int nb_jobs, | 56 | static int filter_## inverse ##_## fmt ##_## clp(AVFilterContext *ctx, \ |
| 57 | int inverse, int clip) | 57 | void *arg, int jobnr,\ |
| 58 | { | 58 | int nb_jobs) \ |
| 59 | ThreadData *td = arg; | 59 | { \ |
| 60 | void **d = td->d; | 60 | ThreadData *td = arg; \ |
| 61 | void **p = td->p; | 61 | void **d = td->d; \ |
| 62 | const void **s = td->s; | 62 | void **p = td->p; \ |
| 63 | const int nb_samples = td->nb_samples; | 63 | const void **s = td->s; \ |
| 64 | const int channels = td->channels; | 64 | const int nb_samples = td->nb_samples; \ |
| 65 | const float mult = td->mult; | 65 | const int channels = td->channels; \ |
| 66 | const float scale = 1.f / (-mult + 1.f); | 66 | const type mult = td->mult; \ |
| 67 | const int start = (channels * jobnr) / nb_jobs; | 67 | const type scale = one / (-mult + one); \ |
| 68 | const int end = (channels * (jobnr+1)) / nb_jobs; | 68 | const int start = (channels * jobnr) / nb_jobs; \ |
| 69 | float *prv = p[0]; | 69 | const int end = (channels * (jobnr+1)) / nb_jobs; \ |
| 70 | int n, c; | 70 | \ |
| 71 | 71 | if (packed) { \ | |
| 72 | for (c = start; c < end; c++) { | 72 | type *prv = p[0]; \ |
| 73 | const float *src = s[0]; | 73 | for (int c = start; c < end; c++) { \ |
| 74 | float *dst = d[0]; | 74 | const type *src = s[0]; \ |
| 75 | 75 | type *dst = d[0]; \ | |
| 76 | for (n = 0; n < nb_samples; n++) { | 76 | \ |
| 77 | float current = src[c]; | 77 | for (int n = 0; n < nb_samples; n++) { \ |
| 78 | 78 | type current = src[c]; \ | |
| 79 | if (inverse) { | 79 | \ |
| 80 | dst[c] = (current - prv[c] * mult) * scale; | 80 | if (inverset) { \ |
| 81 | prv[c] = dst[c]; | 81 | dst[c] = (current - prv[c] * mult) * scale; \ |
| 82 | } else { | 82 | prv[c] = dst[c]; \ |
| 83 | dst[c] = current + (current - prv[c]) * mult; | 83 | } else { \ |
| 84 | prv[c] = current; | 84 | dst[c] = current + (current - prv[c]) * mult; \ |
| 85 | } | 85 | prv[c] = current; \ |
| 86 | if (clip) { | 86 | } \ |
| 87 | dst[c] = av_clipf(dst[c], -1.f, 1.f); | 87 | if (clip) { \ |
| 88 | } | 88 | dst[c] = clip_fn(dst[c], -one, one); \ |
| 89 | 89 | } \ | |
| 90 | dst += channels; | 90 | \ |
| 91 | src += channels; | 91 | dst += channels; \ |
| 92 | } | 92 | src += channels; \ |
| 93 | } | 93 | } \ |
| 94 | 94 | } \ | |
| 95 | return 0; | 95 | } else { \ |
| 96 | for (int c = start; c < end; c++) { \ | ||
| 97 | const type *src = s[c]; \ | ||
| 98 | type *dst = d[c]; \ | ||
| 99 | type *prv = p[c]; \ | ||
| 100 | \ | ||
| 101 | for (int n = 0; n < nb_samples; n++) { \ | ||
| 102 | type current = src[n]; \ | ||
| 103 | \ | ||
| 104 | if (inverset) { \ | ||
| 105 | dst[n] = (current - prv[0] * mult) * scale; \ | ||
| 106 | prv[0] = dst[n]; \ | ||
| 107 | } else { \ | ||
| 108 | dst[n] = current + (current - prv[0]) * mult; \ | ||
| 109 | prv[0] = current; \ | ||
| 110 | } \ | ||
| 111 | if (clip) { \ | ||
| 112 | dst[n] = clip_fn(dst[n], -one, one); \ | ||
| 113 | } \ | ||
| 114 | } \ | ||
| 115 | } \ | ||
| 116 | } \ | ||
| 117 | \ | ||
| 118 | return 0; \ | ||
| 96 | } | 119 | } |
| 97 | 120 | ||
| 98 | static av_always_inline int filter_dbl(AVFilterContext *ctx, void *arg, | 121 | filters(flt, float, inverse, noclip, 1, 0, 1.f, av_clipf, 1) |
| 99 | int jobnr, int nb_jobs, | 122 | filters(flt, float, inverse, clip, 1, 1, 1.f, av_clipf, 1) |
| 100 | int inverse, int clip) | 123 | filters(flt, float, noinverse, noclip, 0, 0, 1.f, av_clipf, 1) |
| 101 | { | 124 | filters(flt, float, noinverse, clip, 0, 1, 1.f, av_clipf, 1) |
| 102 | ThreadData *td = arg; | 125 | |
| 103 | void **d = td->d; | 126 | filters(fltp, float, inverse, noclip, 1, 0, 1.f, av_clipf, 0) |
| 104 | void **p = td->p; | 127 | filters(fltp, float, inverse, clip, 1, 1, 1.f, av_clipf, 0) |
| 105 | const void **s = td->s; | 128 | filters(fltp, float, noinverse, noclip, 0, 0, 1.f, av_clipf, 0) |
| 106 | const int nb_samples = td->nb_samples; | 129 | filters(fltp, float, noinverse, clip, 0, 1, 1.f, av_clipf, 0) |
| 107 | const int channels = td->channels; | 130 | |
| 108 | const double mult = td->mult; | 131 | filters(dbl, double, inverse, noclip, 1, 0, 1.0, av_clipd, 1) |
| 109 | const double scale = 1.0 / (-mult + 1.0); | 132 | filters(dbl, double, inverse, clip, 1, 1, 1.0, av_clipd, 1) |
| 110 | const int start = (channels * jobnr) / nb_jobs; | 133 | filters(dbl, double, noinverse, noclip, 0, 0, 1.0, av_clipd, 1) |
| 111 | const int end = (channels * (jobnr+1)) / nb_jobs; | 134 | filters(dbl, double, noinverse, clip, 0, 1, 1.0, av_clipd, 1) |
| 112 | double *prv = p[0]; | 135 | |
| 113 | int n, c; | 136 | filters(dblp, double, inverse, noclip, 1, 0, 1.0, av_clipd, 0) |
| 114 | 137 | filters(dblp, double, inverse, clip, 1, 1, 1.0, av_clipd, 0) | |
| 115 | for (c = start; c < end; c++) { | 138 | filters(dblp, double, noinverse, noclip, 0, 0, 1.0, av_clipd, 0) |
| 116 | const double *src = s[0]; | 139 | filters(dblp, double, noinverse, clip, 0, 1, 1.0, av_clipd, 0) |
| 117 | double *dst = d[0]; | ||
| 118 | |||
| 119 | for (n = 0; n < nb_samples; n++) { | ||
| 120 | double current = src[c]; | ||
| 121 | |||
| 122 | if (inverse) { | ||
| 123 | dst[c] = (current - prv[c] * mult) * scale; | ||
| 124 | prv[c] = dst[c]; | ||
| 125 | } else { | ||
| 126 | dst[c] = current + (current - prv[c]) * mult; | ||
| 127 | prv[c] = current; | ||
| 128 | } | ||
| 129 | if (clip) { | ||
| 130 | dst[c] = av_clipd(dst[c], -1., 1.); | ||
| 131 | } | ||
| 132 | |||
| 133 | dst += channels; | ||
| 134 | src += channels; | ||
| 135 | } | ||
| 136 | } | ||
| 137 | |||
| 138 | return 0; | ||
| 139 | } | ||
| 140 | |||
| 141 | static av_always_inline int filter_fltp(AVFilterContext *ctx, void *arg, | ||
| 142 | int jobnr, int nb_jobs, | ||
| 143 | int inverse, int clip) | ||
| 144 | { | ||
| 145 | ThreadData *td = arg; | ||
| 146 | void **d = td->d; | ||
| 147 | void **p = td->p; | ||
| 148 | const void **s = td->s; | ||
| 149 | const int nb_samples = td->nb_samples; | ||
| 150 | const int channels = td->channels; | ||
| 151 | const float mult = td->mult; | ||
| 152 | const float scale = 1.f / (-mult + 1.f); | ||
| 153 | const int start = (channels * jobnr) / nb_jobs; | ||
| 154 | const int end = (channels * (jobnr+1)) / nb_jobs; | ||
| 155 | int n, c; | ||
| 156 | |||
| 157 | for (c = start; c < end; c++) { | ||
| 158 | const float *src = s[c]; | ||
| 159 | float *dst = d[c]; | ||
| 160 | float *prv = p[c]; | ||
| 161 | |||
| 162 | for (n = 0; n < nb_samples; n++) { | ||
| 163 | float current = src[n]; | ||
| 164 | |||
| 165 | if (inverse) { | ||
| 166 | dst[n] = (current - prv[0] * mult) * scale; | ||
| 167 | prv[0] = dst[n]; | ||
| 168 | } else { | ||
| 169 | dst[n] = current + (current - prv[0]) * mult; | ||
| 170 | prv[0] = current; | ||
| 171 | } | ||
| 172 | if (clip) { | ||
| 173 | dst[n] = av_clipf(dst[n], -1.f, 1.f); | ||
| 174 | } | ||
| 175 | } | ||
| 176 | } | ||
| 177 | |||
| 178 | return 0; | ||
| 179 | } | ||
| 180 | |||
| 181 | static av_always_inline int filter_dblp(AVFilterContext *ctx, void *arg, | ||
| 182 | int jobnr, int nb_jobs, | ||
| 183 | int inverse, int clip) | ||
| 184 | { | ||
| 185 | ThreadData *td = arg; | ||
| 186 | void **d = td->d; | ||
| 187 | void **p = td->p; | ||
| 188 | const void **s = td->s; | ||
| 189 | const int nb_samples = td->nb_samples; | ||
| 190 | const int channels = td->channels; | ||
| 191 | const double mult = td->mult; | ||
| 192 | const double scale = 1.0 / (-mult + 1.0); | ||
| 193 | const int start = (channels * jobnr) / nb_jobs; | ||
| 194 | const int end = (channels * (jobnr+1)) / nb_jobs; | ||
| 195 | int n, c; | ||
| 196 | |||
| 197 | for (c = start; c < end; c++) { | ||
| 198 | const double *src = s[c]; | ||
| 199 | double *dst = d[c]; | ||
| 200 | double *prv = p[c]; | ||
| 201 | |||
| 202 | for (n = 0; n < nb_samples; n++) { | ||
| 203 | double current = src[n]; | ||
| 204 | |||
| 205 | if (inverse) { | ||
| 206 | dst[n] = (current - prv[0] * mult) * scale; | ||
| 207 | prv[0] = dst[n]; | ||
| 208 | } else { | ||
| 209 | dst[n] = current + (current - prv[0]) * mult; | ||
| 210 | prv[0] = current; | ||
| 211 | } | ||
| 212 | if (clip) { | ||
| 213 | dst[n] = av_clipd(dst[n], -1., 1.); | ||
| 214 | } | ||
| 215 | } | ||
| 216 | } | ||
| 217 | |||
| 218 | return 0; | ||
| 219 | } | ||
| 220 | |||
| 221 | #define filters(fmt, inverse, clip, i, c) \ | ||
| 222 | static int filter_## inverse ##_## fmt ##_## clip(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) \ | ||
| 223 | { \ | ||
| 224 | return filter_## fmt(ctx, arg, jobnr, nb_jobs, i, c); \ | ||
| 225 | } | ||
| 226 | |||
| 227 | filters(flt, inverse, noclip, 1, 0) | ||
| 228 | filters(flt, inverse, clip, 1, 1) | ||
| 229 | filters(flt, noinverse, noclip, 0, 0) | ||
| 230 | filters(flt, noinverse, clip, 0, 1) | ||
| 231 | |||
| 232 | filters(fltp, inverse, noclip, 1, 0) | ||
| 233 | filters(fltp, inverse, clip, 1, 1) | ||
| 234 | filters(fltp, noinverse, noclip, 0, 0) | ||
| 235 | filters(fltp, noinverse, clip, 0, 1) | ||
| 236 | |||
| 237 | filters(dbl, inverse, noclip, 1, 0) | ||
| 238 | filters(dbl, inverse, clip, 1, 1) | ||
| 239 | filters(dbl, noinverse, noclip, 0, 0) | ||
| 240 | filters(dbl, noinverse, clip, 0, 1) | ||
| 241 | |||
| 242 | filters(dblp, inverse, noclip, 1, 0) | ||
| 243 | filters(dblp, inverse, clip, 1, 1) | ||
| 244 | filters(dblp, noinverse, noclip, 0, 0) | ||
| 245 | filters(dblp, noinverse, clip, 0, 1) | ||
| 246 | 140 | ||
| 247 | static int config_input(AVFilterLink *inlink) | 141 | static int config_input(AVFilterLink *inlink) |
| 248 | { | 142 | { |