Unified · Split
| @@ -29,7 +29,7 @@ typedef struct CrystalizerContext { · 28 unmodified lines | ||
| 29 | 29 | float mult; |
| 30 | 30 | int clip; |
| 31 | 31 | AVFrame *prev; |
| 32 | − int (*filter)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs); | |
| 32 | + int (*filter[2][2])(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs); | |
| 33 | 33 | } CrystalizerContext; |
| 34 | 34 | |
| 35 | 35 | #define OFFSET(x) offsetof(CrystalizerContext, x) |
| @@ -68,10 +68,11 @@ typedef struct ThreadData { · 32 unmodified lines | ||
| 68 | 68 | int nb_samples; |
| 69 | 69 | int channels; |
| 70 | 70 | float mult; |
| 71 | − int clip; | |
| 72 | 71 | } ThreadData; |
| 73 | 72 | |
| 74 | −static int filter_flt(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) | |
| 73 | +static av_always_inline int filter_flt(AVFilterContext *ctx, void *arg, | |
| 74 | + int jobnr, int nb_jobs, | |
| 75 | + int inverse, int clip) | |
| 75 | 76 | { |
| 76 | 77 | ThreadData *td = arg; |
| 77 | 78 | void **d = td->d; |
| @@ -80,7 +81,7 @@ static int filter_flt(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) · 2 unmodified lines | ||
| 80 | 81 | const int nb_samples = td->nb_samples; |
| 81 | 82 | const int channels = td->channels; |
| 82 | 83 | const float mult = td->mult; |
| 83 | − const int clip = td->clip; | |
| 84 | + const float scale = 1.f / (-mult + 1.f); | |
| 84 | 85 | const int start = (channels * jobnr) / nb_jobs; |
| 85 | 86 | const int end = (channels * (jobnr+1)) / nb_jobs; |
| 86 | 87 | float *prv = p[0]; |
| @@ -92,8 +93,14 @@ static int filter_flt(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) · 5 unmodified lines | ||
| 92 | 93 | |
| 93 | 94 | for (n = 0; n < nb_samples; n++) { |
| 94 | 95 | float current = src[c]; |
| 95 | − dst[c] = current + (current - prv[c]) * mult; | |
| 96 | − prv[c] = current; | |
| 96 | + | |
| 97 | + if (inverse) { | |
| 98 | + dst[c] = (current - prv[c] * mult) * scale; | |
| 99 | + prv[c] = dst[c]; | |
| 100 | + } else { | |
| 101 | + dst[c] = current + (current - prv[c]) * mult; | |
| 102 | + prv[c] = current; | |
| 103 | + } | |
| 97 | 104 | if (clip) { |
| 98 | 105 | dst[c] = av_clipf(dst[c], -1.f, 1.f); |
| 99 | 106 | } |
| @@ -106,7 +113,9 @@ static int filter_flt(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) · 6 unmodified lines | ||
| 106 | 113 | return 0; |
| 107 | 114 | } |
| 108 | 115 | |
| 109 | −static int filter_dbl(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) | |
| 116 | +static av_always_inline int filter_dbl(AVFilterContext *ctx, void *arg, | |
| 117 | + int jobnr, int nb_jobs, | |
| 118 | + int inverse, int clip) | |
| 110 | 119 | { |
| 111 | 120 | ThreadData *td = arg; |
| 112 | 121 | void **d = td->d; |
| @@ -115,7 +124,7 @@ static int filter_dbl(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) · 2 unmodified lines | ||
| 115 | 124 | const int nb_samples = td->nb_samples; |
| 116 | 125 | const int channels = td->channels; |
| 117 | 126 | const double mult = td->mult; |
| 118 | − const int clip = td->clip; | |
| 127 | + const double scale = 1.0 / (-mult + 1.0); | |
| 119 | 128 | const int start = (channels * jobnr) / nb_jobs; |
| 120 | 129 | const int end = (channels * (jobnr+1)) / nb_jobs; |
| 121 | 130 | double *prv = p[0]; |
| @@ -128,8 +137,13 @@ static int filter_dbl(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) · 6 unmodified lines | ||
| 128 | 137 | for (n = 0; n < nb_samples; n++) { |
| 129 | 138 | double current = src[c]; |
| 130 | 139 | |
| 131 | − dst[c] = current + (current - prv[c]) * mult; | |
| 132 | − prv[c] = current; | |
| 140 | + if (inverse) { | |
| 141 | + dst[c] = (current - prv[c] * mult) * scale; | |
| 142 | + prv[c] = dst[c]; | |
| 143 | + } else { | |
| 144 | + dst[c] = current + (current - prv[c]) * mult; | |
| 145 | + prv[c] = current; | |
| 146 | + } | |
| 133 | 147 | if (clip) { |
| 134 | 148 | dst[c] = av_clipd(dst[c], -1., 1.); |
| 135 | 149 | } |
| @@ -142,7 +156,9 @@ static int filter_dbl(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) · 6 unmodified lines | ||
| 142 | 156 | return 0; |
| 143 | 157 | } |
| 144 | 158 | |
| 145 | −static int filter_fltp(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) | |
| 159 | +static av_always_inline int filter_fltp(AVFilterContext *ctx, void *arg, | |
| 160 | + int jobnr, int nb_jobs, | |
| 161 | + int inverse, int clip) | |
| 146 | 162 | { |
| 147 | 163 | ThreadData *td = arg; |
| 148 | 164 | void **d = td->d; |
| @@ -151,7 +167,7 @@ static int filter_fltp(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) · 2 unmodified lines | ||
| 151 | 167 | const int nb_samples = td->nb_samples; |
| 152 | 168 | const int channels = td->channels; |
| 153 | 169 | const float mult = td->mult; |
| 154 | − const int clip = td->clip; | |
| 170 | + const float scale = 1.f / (-mult + 1.f); | |
| 155 | 171 | const int start = (channels * jobnr) / nb_jobs; |
| 156 | 172 | const int end = (channels * (jobnr+1)) / nb_jobs; |
| 157 | 173 | int n, c; |
| @@ -164,8 +180,13 @@ static int filter_fltp(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) · 6 unmodified lines | ||
| 164 | 180 | for (n = 0; n < nb_samples; n++) { |
| 165 | 181 | float current = src[n]; |
| 166 | 182 | |
| 167 | − dst[n] = current + (current - prv[0]) * mult; | |
| 168 | − prv[0] = current; | |
| 183 | + if (inverse) { | |
| 184 | + dst[n] = (current - prv[0] * mult) * scale; | |
| 185 | + prv[0] = dst[n]; | |
| 186 | + } else { | |
| 187 | + dst[n] = current + (current - prv[0]) * mult; | |
| 188 | + prv[0] = current; | |
| 189 | + } | |
| 169 | 190 | if (clip) { |
| 170 | 191 | dst[n] = av_clipf(dst[n], -1.f, 1.f); |
| 171 | 192 | } |
| @@ -175,7 +196,9 @@ static int filter_fltp(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) · 3 unmodified lines | ||
| 175 | 196 | return 0; |
| 176 | 197 | } |
| 177 | 198 | |
| 178 | −static int filter_dblp(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) | |
| 199 | +static av_always_inline int filter_dblp(AVFilterContext *ctx, void *arg, | |
| 200 | + int jobnr, int nb_jobs, | |
| 201 | + int inverse, int clip) | |
| 179 | 202 | { |
| 180 | 203 | ThreadData *td = arg; |
| 181 | 204 | void **d = td->d; |
| @@ -184,7 +207,7 @@ static int filter_dblp(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) · 2 unmodified lines | ||
| 184 | 207 | const int nb_samples = td->nb_samples; |
| 185 | 208 | const int channels = td->channels; |
| 186 | 209 | const double mult = td->mult; |
| 187 | − const int clip = td->clip; | |
| 210 | + const double scale = 1.0 / (-mult + 1.0); | |
| 188 | 211 | const int start = (channels * jobnr) / nb_jobs; |
| 189 | 212 | const int end = (channels * (jobnr+1)) / nb_jobs; |
| 190 | 213 | int n, c; |
| @@ -197,157 +220,47 @@ static int filter_dblp(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) · 6 unmodified lines | ||
| 197 | 220 | for (n = 0; n < nb_samples; n++) { |
| 198 | 221 | double current = src[n]; |
| 199 | 222 | |
| 200 | − dst[n] = current + (current - prv[0]) * mult; | |
| 201 | − prv[0] = current; | |
| 202 | − if (clip) { | |
| 203 | − dst[n] = av_clipd(dst[n], -1., 1.); | |
| 223 | + if (inverse) { | |
| 224 | + dst[n] = (current - prv[0] * mult) * scale; | |
| 225 | + prv[0] = dst[n]; | |
| 226 | + } else { | |
| 227 | + dst[n] = current + (current - prv[0]) * mult; | |
| 228 | + prv[0] = current; | |
| 204 | 229 | } |
| 205 | − } | |
| 206 | − } | |
| 207 | − | |
| 208 | − return 0; | |
| 209 | −} | |
| 210 | − | |
| 211 | −static int ifilter_flt(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) | |
| 212 | −{ | |
| 213 | − ThreadData *td = arg; | |
| 214 | − void **d = td->d; | |
| 215 | − void **p = td->p; | |
| 216 | − const void **s = td->s; | |
| 217 | − const int nb_samples = td->nb_samples; | |
| 218 | − const int channels = td->channels; | |
| 219 | − const float mult = -td->mult; | |
| 220 | − const float scale = 1.f / (mult + 1.f); | |
| 221 | − const int clip = td->clip; | |
| 222 | − const int start = (channels * jobnr) / nb_jobs; | |
| 223 | − const int end = (channels * (jobnr+1)) / nb_jobs; | |
| 224 | − float *prv = p[0]; | |
| 225 | − int n, c; | |
| 226 | − | |
| 227 | − for (c = start; c < end; c++) { | |
| 228 | − const float *src = s[0]; | |
| 229 | − float *dst = d[0]; | |
| 230 | − | |
| 231 | − for (n = 0; n < nb_samples; n++) { | |
| 232 | − float current = src[c]; | |
| 233 | − dst[c] = (current + prv[c] * mult) * scale; | |
| 234 | − prv[c] = dst[c]; | |
| 235 | 230 | if (clip) { |
| 236 | − dst[c] = av_clipf(dst[c], -1.f, 1.f); | |
| 237 | − } | |
| 238 | − | |
| 239 | − dst += channels; | |
| 240 | − src += channels; | |
| 241 | − } | |
| 242 | − } | |
| 243 | − | |
| 244 | − return 0; | |
| 245 | −} | |
| 246 | − | |
| 247 | −static int ifilter_dbl(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) | |
| 248 | −{ | |
| 249 | − ThreadData *td = arg; | |
| 250 | − void **d = td->d; | |
| 251 | − void **p = td->p; | |
| 252 | − const void **s = td->s; | |
| 253 | − const int nb_samples = td->nb_samples; | |
| 254 | − const int channels = td->channels; | |
| 255 | − const double mult = -td->mult; | |
| 256 | − const double scale = 1.0 / (mult + 1.0); | |
| 257 | − const int clip = td->clip; | |
| 258 | − const int start = (channels * jobnr) / nb_jobs; | |
| 259 | − const int end = (channels * (jobnr+1)) / nb_jobs; | |
| 260 | − double *prv = p[0]; | |
| 261 | − int n, c; | |
| 262 | − | |
| 263 | − for (c = start; c < end; c++) { | |
| 264 | − const double *src = s[0]; | |
| 265 | − double *dst = d[0]; | |
| 266 | − | |
| 267 | − for (n = 0; n < nb_samples; n++) { | |
| 268 | − double current = src[c]; | |
| 269 | − | |
| 270 | − dst[c] = (current + prv[c] * mult) * scale; | |
| 271 | − prv[c] = dst[c]; | |
| 272 | − if (clip) { | |
| 273 | − dst[c] = av_clipd(dst[c], -1., 1.); | |
| 231 | + dst[n] = av_clipd(dst[n], -1., 1.); | |
| 274 | 232 | } |
| 275 | − | |
| 276 | − dst += channels; | |
| 277 | − src += channels; | |
| 278 | 233 | } |
| 279 | 234 | } |
| 280 | 235 | |
| 281 | 236 | return 0; |
| 282 | 237 | } |
| 283 | 238 | |
| 284 | −static int ifilter_fltp(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) | |
| 285 | −{ | |
| 286 | − ThreadData *td = arg; | |
| 287 | − void **d = td->d; | |
| 288 | − void **p = td->p; | |
| 289 | − const void **s = td->s; | |
| 290 | − const int nb_samples = td->nb_samples; | |
| 291 | − const int channels = td->channels; | |
| 292 | − const float mult = -td->mult; | |
| 293 | − const float scale = 1.f / (mult + 1.f); | |
| 294 | − const int clip = td->clip; | |
| 295 | − const int start = (channels * jobnr) / nb_jobs; | |
| 296 | − const int end = (channels * (jobnr+1)) / nb_jobs; | |
| 297 | − int n, c; | |
| 298 | − | |
| 299 | − for (c = start; c < end; c++) { | |
| 300 | − const float *src = s[c]; | |
| 301 | − float *dst = d[c]; | |
| 302 | − float *prv = p[c]; | |
| 303 | − | |
| 304 | − for (n = 0; n < nb_samples; n++) { | |
| 305 | − float current = src[n]; | |
| 306 | − | |
| 307 | − dst[n] = (current + prv[0] * mult) * scale; | |
| 308 | − prv[0] = dst[n]; | |
| 309 | − if (clip) { | |
| 310 | − dst[n] = av_clipf(dst[n], -1.f, 1.f); | |
| 311 | − } | |
| 312 | − } | |
| 313 | − } | |
| 314 | − | |
| 315 | − return 0; | |
| 239 | +#define filters(fmt, inverse, clip, i, c) \ | |
| 240 | +static int filter_## inverse ##_## fmt ##_## clip(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) \ | |
| 241 | +{ \ | |
| 242 | + return filter_## fmt(ctx, arg, jobnr, nb_jobs, i, c); \ | |
| 316 | 243 | } |
| 317 | 244 | |
| 318 | −static int ifilter_dblp(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) | |
| 319 | −{ | |
| 320 | − ThreadData *td = arg; | |
| 321 | − void **d = td->d; | |
| 322 | − void **p = td->p; | |
| 323 | − const void **s = td->s; | |
| 324 | − const int nb_samples = td->nb_samples; | |
| 325 | − const int channels = td->channels; | |
| 326 | − const double mult = -td->mult; | |
| 327 | − const double scale = 1.0 / (mult + 1.0); | |
| 328 | − const int clip = td->clip; | |
| 329 | − const int start = (channels * jobnr) / nb_jobs; | |
| 330 | − const int end = (channels * (jobnr+1)) / nb_jobs; | |
| 331 | − int n, c; | |
| 245 | +filters(flt, inverse, noclip, 1, 0) | |
| 246 | +filters(flt, inverse, clip, 1, 1) | |
| 247 | +filters(flt, noinverse, noclip, 0, 0) | |
| 248 | +filters(flt, noinverse, clip, 0, 1) | |
| 332 | 249 | |
| 333 | − for (c = start; c < end; c++) { | |
| 334 | − const double *src = s[c]; | |
| 335 | − double *dst = d[c]; | |
| 336 | − double *prv = p[c]; | |
| 337 | − | |
| 338 | − for (n = 0; n < nb_samples; n++) { | |
| 339 | − double current = src[n]; | |
| 250 | +filters(fltp, inverse, noclip, 1, 0) | |
| 251 | +filters(fltp, inverse, clip, 1, 1) | |
| 252 | +filters(fltp, noinverse, noclip, 0, 0) | |
| 253 | +filters(fltp, noinverse, clip, 0, 1) | |
| 340 | 254 | |
| 341 | − dst[n] = (current + prv[0] * mult) * scale; | |
| 342 | − prv[0] = dst[n]; | |
| 343 | − if (clip) { | |
| 344 | − dst[n] = av_clipd(dst[n], -1., 1.); | |
| 345 | − } | |
| 346 | − } | |
| 347 | − } | |
| 255 | +filters(dbl, inverse, noclip, 1, 0) | |
| 256 | +filters(dbl, inverse, clip, 1, 1) | |
| 257 | +filters(dbl, noinverse, noclip, 0, 0) | |
| 258 | +filters(dbl, noinverse, clip, 0, 1) | |
| 348 | 259 | |
| 349 | − return 0; | |
| 350 | −} | |
| 260 | +filters(dblp, inverse, noclip, 1, 0) | |
| 261 | +filters(dblp, inverse, clip, 1, 1) | |
| 262 | +filters(dblp, noinverse, noclip, 0, 0) | |
| 263 | +filters(dblp, noinverse, clip, 0, 1) | |
| 351 | 264 | |
| 352 | 265 | static int config_input(AVFilterLink *inlink) |
| 353 | 266 | { |
| @@ -355,10 +268,32 @@ static int config_input(AVFilterLink *inlink) · 1 unmodified line | ||
| 355 | 268 | CrystalizerContext *s = ctx->priv; |
| 356 | 269 | |
| 357 | 270 | switch (inlink->format) { |
| 358 | − case AV_SAMPLE_FMT_FLT: s->filter = s->mult >= 0.f ? filter_flt : ifilter_flt; break; | |
| 359 | − case AV_SAMPLE_FMT_DBL: s->filter = s->mult >= 0.f ? filter_dbl : ifilter_dbl; break; | |
| 360 | − case AV_SAMPLE_FMT_FLTP: s->filter = s->mult >= 0.f ? filter_fltp : ifilter_fltp; break; | |
| 361 | − case AV_SAMPLE_FMT_DBLP: s->filter = s->mult >= 0.f ? filter_dblp : ifilter_dblp; break; | |
| 271 | + case AV_SAMPLE_FMT_FLT: | |
| 272 | + s->filter[0][0] = filter_inverse_flt_noclip; | |
| 273 | + s->filter[1][0] = filter_noinverse_flt_noclip; | |
| 274 | + s->filter[0][1] = filter_inverse_flt_clip; | |
| 275 | + s->filter[1][1] = filter_noinverse_flt_clip; | |
| 276 | + break; | |
| 277 | + case AV_SAMPLE_FMT_FLTP: | |
| 278 | + s->filter[0][0] = filter_inverse_fltp_noclip; | |
| 279 | + s->filter[1][0] = filter_noinverse_fltp_noclip; | |
| 280 | + s->filter[0][1] = filter_inverse_fltp_clip; | |
| 281 | + s->filter[1][1] = filter_noinverse_fltp_clip; | |
| 282 | + break; | |
| 283 | + case AV_SAMPLE_FMT_DBL: | |
| 284 | + s->filter[0][0] = filter_inverse_dbl_noclip; | |
| 285 | + s->filter[1][0] = filter_noinverse_dbl_noclip; | |
| 286 | + s->filter[0][1] = filter_inverse_dbl_clip; | |
| 287 | + s->filter[1][1] = filter_noinverse_dbl_clip; | |
| 288 | + break; | |
| 289 | + case AV_SAMPLE_FMT_DBLP: | |
| 290 | + s->filter[0][0] = filter_inverse_dblp_noclip; | |
| 291 | + s->filter[1][0] = filter_noinverse_dblp_noclip; | |
| 292 | + s->filter[0][1] = filter_inverse_dblp_clip; | |
| 293 | + s->filter[1][1] = filter_noinverse_dblp_clip; | |
| 294 | + break; | |
| 295 | + default: | |
| 296 | + return AVERROR_BUG; | |
| 362 | 297 | } |
| 363 | 298 | |
| 364 | 299 | return 0; |
| @@ -397,8 +332,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 32 unmodified lines | ||
| 397 | 332 | td.nb_samples = in->nb_samples; |
| 398 | 333 | td.channels = in->channels; |
| 399 | 334 | td.mult = ctx->is_disabled ? 0.f : s->mult; |
| 400 | − td.clip = s->clip; | |
| 401 | − ff_filter_execute(ctx, s->filter, &td, NULL, | |
| 335 | + ff_filter_execute(ctx, s->filter[td.mult >= 0.f][s->clip], &td, NULL, | |
| 402 | 336 | FFMIN(inlink->channels, ff_filter_get_nb_threads(ctx))); |
| 403 | 337 | |
| 404 | 338 | if (out != in) |