diff --git a/libswscale/ops_backend.c b/libswscale/ops_backend.c index cbc7eba1b4..e7aaeda9d4 100644 --- a/libswscale/ops_backend.c +++ b/libswscale/ops_backend.c @@ -66,20 +66,14 @@ static int compile(SwsContext *ctx, SwsOpList *ops, SwsCompiledOp *out) av_assert0(ops->num_ops > 0); const SwsPixelType read_type = ops->ops[0].type; - /* Make on-stack copy of `ops` to iterate over */ - SwsOpList rest = *ops; - do { + for (int i = 0; i < ops->num_ops; i++) { ret = ff_sws_op_compile_tables(ctx, tables, FF_ARRAY_ELEMS(tables), - &rest, SWS_BLOCK_SIZE, chain); - } while (ret == AVERROR(EAGAIN)); - - if (ret < 0) { - ff_sws_op_chain_free(chain); - if (rest.num_ops < ops->num_ops) { - av_log(ctx, AV_LOG_TRACE, "Uncompiled remainder:\n"); - ff_sws_op_list_print(ctx, AV_LOG_TRACE, AV_LOG_TRACE, &rest); + ops, i, SWS_BLOCK_SIZE, chain); + if (ret < 0) { + av_log(ctx, AV_LOG_TRACE, "Failed to compile op %d\n", i); + ff_sws_op_chain_free(chain); + return ret; } - return ret; } *out = (SwsCompiledOp) { diff --git a/libswscale/ops_chain.c b/libswscale/ops_chain.c index 7a5706a525..df7867c248 100644 --- a/libswscale/ops_chain.c +++ b/libswscale/ops_chain.c @@ -201,13 +201,13 @@ static int op_match(const SwsOp *op, const SwsOpEntry *entry) } int ff_sws_op_compile_tables(SwsContext *ctx, const SwsOpTable *const tables[], - int num_tables, SwsOpList *ops, const int block_size, - SwsOpChain *chain) + int num_tables, SwsOpList *ops, int ops_index, + const int block_size, SwsOpChain *chain) { + const SwsOp *op = &ops->ops[ops_index]; const unsigned cpu_flags = av_get_cpu_flags(); const SwsOpEntry *best = NULL; const SwsOpTable *best_table = NULL; - const SwsOp *op = &ops->ops[0]; int ret, best_score = 0; SwsImplParams params = { @@ -258,10 +258,7 @@ int ff_sws_op_compile_tables(SwsContext *ctx, const SwsOpTable *const tables[], chain->cpu_flags |= best_table->cpu_flags; chain->over_read = FFMAX(chain->over_read, res.over_read); chain->over_write = FFMAX(chain->over_write, res.over_write); - - ops->ops++; - ops->num_ops--; - return ops->num_ops ? AVERROR(EAGAIN) : 0; + return 0; } #define q2pixel(type, q) ((q).den ? (type) (q).num / (q).den : 0) diff --git a/libswscale/ops_chain.h b/libswscale/ops_chain.h index 0dbab689f5..60c83e6e9e 100644 --- a/libswscale/ops_chain.h +++ b/libswscale/ops_chain.h @@ -166,10 +166,10 @@ struct SwsOpTable { * "Compile" a single op by looking it up in a list of fixed size op tables. * See `op_match` in `ops_chain.c` for details on how the matching works. * - * Returns 0, AVERROR(EAGAIN), or a negative error code. + * Returns 0 or a negative error code. */ int ff_sws_op_compile_tables(SwsContext *ctx, const SwsOpTable *const tables[], - int num_tables, SwsOpList *ops, const int block_size, - SwsOpChain *chain); + int num_tables, SwsOpList *ops, int ops_index, + const int block_size, SwsOpChain *chain); #endif diff --git a/libswscale/x86/ops.c b/libswscale/x86/ops.c index 8f03472e2e..51c65c8ebb 100644 --- a/libswscale/x86/ops.c +++ b/libswscale/x86/ops.c @@ -983,11 +983,9 @@ static int compile(SwsContext *ctx, SwsOpList *ops, SwsCompiledOp *out) .block_size = 2 * FFMIN(mmsize, 32) / ff_sws_op_list_max_size(ops), }; - /* Make on-stack copy of `ops` to iterate over */ - SwsOpList rest = *ops; - do { + for (int i = 0; i < ops->num_ops; i++) { int op_block_size = out->block_size; - SwsOp *op = &rest.ops[0]; + SwsOp *op = &ops->ops[i]; if (op_is_type_invariant(op)) { if (op->op == SWS_OP_CLEAR) @@ -997,16 +995,12 @@ static int compile(SwsContext *ctx, SwsOpList *ops, SwsCompiledOp *out) } ret = ff_sws_op_compile_tables(ctx, tables, FF_ARRAY_ELEMS(tables), - &rest, op_block_size, chain); - } while (ret == AVERROR(EAGAIN)); - - if (ret < 0) { - ff_sws_op_chain_free(chain); - if (rest.num_ops < ops->num_ops) { - av_log(ctx, AV_LOG_TRACE, "Uncompiled remainder:\n"); - ff_sws_op_list_print(ctx, AV_LOG_TRACE, AV_LOG_TRACE, &rest); + ops, i, op_block_size, chain); + if (ret < 0) { + av_log(ctx, AV_LOG_TRACE, "Failed to compile op %d\n", i); + ff_sws_op_chain_free(chain); + return ret; } - return ret; } #define ASSIGN_PROCESS_FUNC(NAME) \