diff --git a/libswscale/ops_chain.c b/libswscale/ops_chain.c index dedc5f3026..092133426e 100644 --- a/libswscale/ops_chain.c +++ b/libswscale/ops_chain.c @@ -212,34 +212,38 @@ int ff_sws_op_compile_tables(SwsContext *ctx, const SwsOpTable *const tables[], const SwsOp *op = &ops->ops[0]; int ret, best_score = 0; + SwsImplParams params = { + .ctx = ctx, + .op = op + }; + for (int n = 0; n < num_tables; n++) { const SwsOpTable *table = tables[n]; if (table->block_size && table->block_size != block_size || table->cpu_flags & ~cpu_flags) continue; + params.table = table; for (int i = 0; table->entries[i]; i++) { const SwsOpEntry *entry = table->entries[i]; int score = op_match(op, entry, next->comps); - if (score > best_score) { - best_score = score; - best_table = table; - best = entry; - } + if (score <= best_score) + continue; + if (entry->check && !entry->check(¶ms)) + continue; + best_score = score; + best_table = table; + best = entry; } } if (!best) return AVERROR(ENOTSUP); + params.table = best_table; + SwsImplResult res = {0}; if (best->setup) { - const SwsImplParams params = { - .ctx = ctx, - .op = op, - .table = best_table, - }; - ret = best->setup(¶ms, &res); if (ret < 0) return ret; diff --git a/libswscale/ops_chain.h b/libswscale/ops_chain.h index ffdcc577dd..0dbab689f5 100644 --- a/libswscale/ops_chain.h +++ b/libswscale/ops_chain.h @@ -137,6 +137,7 @@ typedef struct SwsOpEntry { /* Kernel implementation */ SwsFuncPtr func; int (*setup)(const SwsImplParams *params, SwsImplResult *out); /* optional */ + bool (*check)(const SwsImplParams *params); /* optional, return true if supported */ } SwsOpEntry; /* Setup helpers */