[FFmpeg-devel] [PATCH 18/24] fftools/ffmpeg: add thread-aware transcode scheduling infrastructure

James Almer jamrial at gmail.com
Sat Nov 4 15:53:25 EET 2023


On 11/4/2023 4:56 AM, Anton Khirnov wrote:
> +static void *task_wrapper(void *arg)
> +{
> +    SchTask  *task = arg;
> +    Scheduler *sch = task->parent;
> +    int ret;
> +    int err = 0;
> +
> +    ret = (intptr_t)task->func(task->func_arg);
> +    if (ret < 0)
> +        av_log(task->func_arg, AV_LOG_ERROR,
> +               "Task finished with error code: %d (%s)\n", ret, av_err2str(ret));
> +
> +    switch (task->node.type) {
> +    case SCH_NODE_TYPE_DEMUX:       err = demux_done (sch, task->node.idx); break;
> +    case SCH_NODE_TYPE_MUX:         err = mux_done   (sch, task->node.idx); break;
> +    case SCH_NODE_TYPE_DEC:         err = dec_done   (sch, task->node.idx); break;
> +    case SCH_NODE_TYPE_ENC:         err = enc_done   (sch, task->node.idx); break;
> +    case SCH_NODE_TYPE_FILTER_IN:   err = filter_done(sch, task->node.idx); break;

task->node.type seems to be constant, so wouldn't it be faster, or at 
least cleaner looking here, to use a function pointer assigned in 
task_init()?

> +    default: av_assert0(0);
> +    }
> +
> +    ret = err_merge(ret, err);
> +
> +    // EOF is considered normal termination
> +    if (ret == AVERROR_EOF)
> +        ret = 0;
> +    if (ret < 0)
> +        atomic_store(&sch->task_failed, 1);
> +
> +    av_log(task->func_arg, ret < 0 ? AV_LOG_ERROR : AV_LOG_VERBOSE,
> +           "Terminating thread with return code %d (%s)\n", ret,
> +           ret < 0 ? av_err2str(ret) : "success");
> +
> +    return (void*)(intptr_t)ret;
> +}


More information about the ffmpeg-devel mailing list