1
0
mirror of https://git.ffmpeg.org/ffmpeg.git synced 2026-10-24 02:09:03 +03:00

avfilter: add ff_slice_pos() helper for slice boundaries

Slice based filter workers compute their per-thread row/sample/channel
boundaries as total * jobnr / nb_jobs. The total * jobnr product is
evaluated in int and overflows signed int for large dimensions and many
slice threads, before the division by nb_jobs brings it back in range.

(cherry picked from commit 218b4771a3)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
This commit is contained in:
Michael Niedermayer
2026-06-07 21:38:20 +02:00
parent bd2b35068f
commit 02e44beef7

View File

@@ -266,4 +266,19 @@ static inline void ff_outlink_set_status(AVFilterLink *link, int status, int64_t
*/
int ff_inoutlink_check_flow(AVFilterLink *inlink, AVFilterLink *outlink);
/**
* Compute the boundary index for a slice when work of size total is split
* into nb_jobs slices. Returns the first index of slice jobnr, so the slice
* jobnr covers [ff_slice_pos(total, jobnr, nb_jobs),
* ff_slice_pos(total, jobnr + 1, nb_jobs)).
*
* The multiplication is performed in 64bit to avoid signed overflow of the
* total * jobnr intermediate that would occur for large dimensions and many
* slice threads.
*/
static inline int ff_slice_pos(int total, int jobnr, int nb_jobs)
{
return (int)((int64_t)total * jobnr / nb_jobs);
}
#endif /* AVFILTER_FILTERS_H */