Unified · Split
| @@ -29,7 +29,7 @@ typedef struct CrystalizerContext { · 28 unmodified lines | |||
| 29 | float mult; | 29 | float mult; |
| 30 | int clip; | 30 | int clip; |
| 31 | AVFrame *prev; | 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 | } CrystalizerContext; | 33 | } CrystalizerContext; |
| 34 | 34 | ||
| 35 | #define OFFSET(x) offsetof(CrystalizerContext, x) | 35 | #define OFFSET(x) offsetof(CrystalizerContext, x) |
| @@ -68,10 +68,11 @@ typedef struct ThreadData { · 32 unmodified lines | |||
| 68 | int nb_samples; | 68 | int nb_samples; |
| 69 | int channels; | 69 | int channels; |
| 70 | float mult; | 70 | float mult; |
| 71 | int clip; | ||
| 72 | } ThreadData; | 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 | ThreadData *td = arg; | 77 | ThreadData *td = arg; |
| 77 | void **d = td->d; | 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 | const int nb_samples = td->nb_samples; | 81 | const int nb_samples = td->nb_samples; |
| 81 | const int channels = td->channels; | 82 | const int channels = td->channels; |
| 82 | const float mult = td->mult; | 83 | const float mult = td->mult; |
| 83 | const int clip = td->clip; | 84 | const float scale = 1.f / (-mult + 1.f); |
| 84 | const int start = (channels * jobnr) / nb_jobs; | 85 | const int start = (channels * jobnr) / nb_jobs; |
| 85 | const int end = (channels * (jobnr+1)) / nb_jobs; | 86 | const int end = (channels * (jobnr+1)) / nb_jobs; |
| 86 | float *prv = p[0]; | 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 | for (n = 0; n < nb_samples; n++) { | 94 | for (n = 0; n < nb_samples; n++) { |
| 94 | float current = src[c]; | 95 | float current = src[c]; |
| 95 | dst[c] = current + (current - prv[c]) * mult; | 96 | |
| 96 | prv[c] = current; | 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 | if (clip) { | 104 | if (clip) { |
| 98 | dst[c] = av_clipf(dst[c], -1.f, 1.f); | 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 | return 0; | 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 | ThreadData *td = arg; | 120 | ThreadData *td = arg; |
| 112 | void **d = td->d; | 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 | const int nb_samples = td->nb_samples; | 124 | const int nb_samples = td->nb_samples; |
| 116 | const int channels = td->channels; | 125 | const int channels = td->channels; |
| 117 | const double mult = td->mult; | 126 | const double mult = td->mult; |
| 118 | const int clip = td->clip; | 127 | const double scale = 1.0 / (-mult + 1.0); |
| 119 | const int start = (channels * jobnr) / nb_jobs; | 128 | const int start = (channels * jobnr) / nb_jobs; |
| 120 | const int end = (channels * (jobnr+1)) / nb_jobs; | 129 | const int end = (channels * (jobnr+1)) / nb_jobs; |
| 121 | double *prv = p[0]; | 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 | for (n = 0; n < nb_samples; n++) { | 137 | for (n = 0; n < nb_samples; n++) { |
| 129 | double current = src[c]; | 138 | double current = src[c]; |
| 130 | 139 | ||
| 131 | dst[c] = current + (current - prv[c]) * mult; | 140 | if (inverse) { |
| 132 | prv[c] = current; | 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 | if (clip) { | 147 | if (clip) { |
| 134 | dst[c] = av_clipd(dst[c], -1., 1.); | 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 | return 0; | 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 | ThreadData *td = arg; | 163 | ThreadData *td = arg; |
| 148 | void **d = td->d; | 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 | const int nb_samples = td->nb_samples; | 167 | const int nb_samples = td->nb_samples; |
| 152 | const int channels = td->channels; | 168 | const int channels = td->channels; |
| 153 | const float mult = td->mult; | 169 | const float mult = td->mult; |
| 154 | const int clip = td->clip; | 170 | const float scale = 1.f / (-mult + 1.f); |
| 155 | const int start = (channels * jobnr) / nb_jobs; | 171 | const int start = (channels * jobnr) / nb_jobs; |
| 156 | const int end = (channels * (jobnr+1)) / nb_jobs; | 172 | const int end = (channels * (jobnr+1)) / nb_jobs; |
| 157 | int n, c; | 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 | for (n = 0; n < nb_samples; n++) { | 180 | for (n = 0; n < nb_samples; n++) { |
| 165 | float current = src[n]; | 181 | float current = src[n]; |
| 166 | 182 | ||
| 167 | dst[n] = current + (current - prv[0]) * mult; | 183 | if (inverse) { |
| 168 | prv[0] = current; | 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 | if (clip) { | 190 | if (clip) { |
| 170 | dst[n] = av_clipf(dst[n], -1.f, 1.f); | 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 | return 0; | 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 | ThreadData *td = arg; | 203 | ThreadData *td = arg; |
| 181 | void **d = td->d; | 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 | const int nb_samples = td->nb_samples; | 207 | const int nb_samples = td->nb_samples; |
| 185 | const int channels = td->channels; | 208 | const int channels = td->channels; |
| 186 | const double mult = td->mult; | 209 | const double mult = td->mult; |
| 187 | const int clip = td->clip; | 210 | const double scale = 1.0 / (-mult + 1.0); |
| 188 | const int start = (channels * jobnr) / nb_jobs; | 211 | const int start = (channels * jobnr) / nb_jobs; |
| 189 | const int end = (channels * (jobnr+1)) / nb_jobs; | 212 | const int end = (channels * (jobnr+1)) / nb_jobs; |
| 190 | int n, c; | 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 | for (n = 0; n < nb_samples; n++) { | 220 | for (n = 0; n < nb_samples; n++) { |
| 198 | double current = src[n]; | 221 | double current = src[n]; |
| 199 | 222 | ||
| 200 | dst[n] = current + (current - prv[0]) * mult; | 223 | if (inverse) { |
| 201 | prv[0] = current; | 224 | dst[n] = (current - prv[0] * mult) * scale; |
| 202 | if (clip) { | 225 | prv[0] = dst[n]; |
| 203 | dst[n] = av_clipd(dst[n], -1., 1.); | 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 | if (clip) { | 230 | if (clip) { |
| 236 | dst[c] = av_clipf(dst[c], -1.f, 1.f); | 231 | dst[n] = av_clipd(dst[n], -1., 1.); |
| 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.); | ||
| 274 | } | 232 | } |
| 275 | |||
| 276 | dst += channels; | ||
| 277 | src += channels; | ||
| 278 | } | 233 | } |
| 279 | } | 234 | } |
| 280 | 235 | ||
| 281 | return 0; | 236 | return 0; |
| 282 | } | 237 | } |
| 283 | 238 | ||
| 284 | static int ifilter_fltp(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) | 239 | #define filters(fmt, inverse, clip, i, c) \ |
| 285 | { | 240 | static int filter_## inverse ##_## fmt ##_## clip(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) \ |
| 286 | ThreadData *td = arg; | 241 | { \ |
| 287 | void **d = td->d; | 242 | return filter_## fmt(ctx, arg, jobnr, nb_jobs, i, c); \ |
| 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; | ||
| 316 | } | 243 | } |
| 317 | 244 | ||
| 318 | static int ifilter_dblp(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) | 245 | filters(flt, inverse, noclip, 1, 0) |
| 319 | { | 246 | filters(flt, inverse, clip, 1, 1) |
| 320 | ThreadData *td = arg; | 247 | filters(flt, noinverse, noclip, 0, 0) |
| 321 | void **d = td->d; | 248 | filters(flt, noinverse, clip, 0, 1) |
| 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; | ||
| 332 | 249 | ||
| 333 | for (c = start; c < end; c++) { | 250 | filters(fltp, inverse, noclip, 1, 0) |
| 334 | const double *src = s[c]; | 251 | filters(fltp, inverse, clip, 1, 1) |
| 335 | double *dst = d[c]; | 252 | filters(fltp, noinverse, noclip, 0, 0) |
| 336 | double *prv = p[c]; | 253 | filters(fltp, noinverse, clip, 0, 1) |
| 337 | |||
| 338 | for (n = 0; n < nb_samples; n++) { | ||
| 339 | double current = src[n]; | ||
| 340 | 254 | ||
| 341 | dst[n] = (current + prv[0] * mult) * scale; | 255 | filters(dbl, inverse, noclip, 1, 0) |
| 342 | prv[0] = dst[n]; | 256 | filters(dbl, inverse, clip, 1, 1) |
| 343 | if (clip) { | 257 | filters(dbl, noinverse, noclip, 0, 0) |
| 344 | dst[n] = av_clipd(dst[n], -1., 1.); | 258 | filters(dbl, noinverse, clip, 0, 1) |
| 345 | } | ||
| 346 | } | ||
| 347 | } | ||
| 348 | 259 | ||
| 349 | return 0; | 260 | filters(dblp, inverse, noclip, 1, 0) |
| 350 | } | 261 | filters(dblp, inverse, clip, 1, 1) |
| 262 | filters(dblp, noinverse, noclip, 0, 0) | ||
| 263 | filters(dblp, noinverse, clip, 0, 1) | ||
| 351 | 264 | ||
| 352 | static int config_input(AVFilterLink *inlink) | 265 | static int config_input(AVFilterLink *inlink) |
| 353 | { | 266 | { |
| @@ -355,10 +268,32 @@ static int config_input(AVFilterLink *inlink) · 1 unmodified line | |||
| 355 | CrystalizerContext *s = ctx->priv; | 268 | CrystalizerContext *s = ctx->priv; |
| 356 | 269 | ||
| 357 | switch (inlink->format) { | 270 | switch (inlink->format) { |
| 358 | case AV_SAMPLE_FMT_FLT: s->filter = s->mult >= 0.f ? filter_flt : ifilter_flt; break; | 271 | case AV_SAMPLE_FMT_FLT: |
| 359 | case AV_SAMPLE_FMT_DBL: s->filter = s->mult >= 0.f ? filter_dbl : ifilter_dbl; break; | 272 | s->filter[0][0] = filter_inverse_flt_noclip; |
| 360 | case AV_SAMPLE_FMT_FLTP: s->filter = s->mult >= 0.f ? filter_fltp : ifilter_fltp; break; | 273 | s->filter[1][0] = filter_noinverse_flt_noclip; |
| 361 | case AV_SAMPLE_FMT_DBLP: s->filter = s->mult >= 0.f ? filter_dblp : ifilter_dblp; break; | 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 | return 0; | 299 | return 0; |
| @@ -397,8 +332,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 32 unmodified lines | |||
| 397 | td.nb_samples = in->nb_samples; | 332 | td.nb_samples = in->nb_samples; |
| 398 | td.channels = in->channels; | 333 | td.channels = in->channels; |
| 399 | td.mult = ctx->is_disabled ? 0.f : s->mult; | 334 | td.mult = ctx->is_disabled ? 0.f : s->mult; |
| 400 | td.clip = s->clip; | 335 | ff_filter_execute(ctx, s->filter[td.mult >= 0.f][s->clip], &td, NULL, |
| 401 | ff_filter_execute(ctx, s->filter, &td, NULL, | ||
| 402 | FFMIN(inlink->channels, ff_filter_get_nb_threads(ctx))); | 336 | FFMIN(inlink->channels, ff_filter_get_nb_threads(ctx))); |
| 403 | 337 | ||
| 404 | if (out != in) | 338 | if (out != in) |