[FFmpeg-devel] [PATCH] avutils/hwcontext: When deriving a hwdevice, search for existing device in both directions

Hendrik Leppkes h.leppkes at gmail.com
Sat Aug 7 09:52:06 EEST 2021


On Sat, Aug 7, 2021 at 3:46 AM Soft Works <softworkz at hotmail.com> wrote:
>
> The test /libavutil/tests/hwdevice checks that when deriving a device
> from a source device and then deriving back to the type of the source
> device, the result is matching the original source device, i.e. the
> derivation mechanism doesn't create a new device in this case.
>
> Previously, this test was usually passed, but only due to two different
> kind of flaws:
>
> 1. The test covers only a single level of derivation (and back)
>
> It derives device Y from device X and then Y back to the type of X and
> checks whether the result matches X.
>
> What it doesn't check for, are longer chains of derivation like:
>
> CUDA1 > OpenCL2 > CUDA3 and then back to OpenCL4
>
> In that case, the second derivation returns the first device (CUDA3 ==
> CUDA1), but when deriving OpenCL4, hwcontext.c was creating a new
> OpenCL4 context instead of returning OpenCL2, because there was no link
> from CUDA1 to OpenCL2 (only backwards from OpenCL2 to CUDA1)
>
> If the test would check for two levels of derivation, it would have
> failed.
>
> This patch fixes those (yet untested) cases by introducing forward
> references (derived_device) in addition to the existing back references
> (source_device).
>

I already see one problem here, if you have so many derived cases
happening, its also feasible to assume one source was used to derive
more then one device, which this cannot track, and in fact looks like
the code would just override and leak a reference.

How common would it be that such complex derived chains happen, when
you say even this one is untested?

- Hendrik


More information about the ffmpeg-devel mailing list