With the previous change, it is possible that the mp_hwdec_ctx contains a list of known supported hwuploads. Take this into account when adding to the p->fmts list. We want to be sure to select only something that is actually possible to use. If the hwdec does not implement supported_hwupload_formats, then all are assumed to work.
Unified · Split
| @@ -392,6 +392,7 @@ static bool probe_formats(struct mp_filter *f, int hw_imgfmt, bool use_conversio · 391 unmodified lines | ||
| 392 | 392 | ctx->conversion_config); |
| 393 | 393 | } |
| 394 | 394 | |
| 395 | + int hw_transfer_index = 0; | |
| 395 | 396 | for (int n = 0; cstr->valid_sw_formats && |
| 396 | 397 | cstr->valid_sw_formats[n] != AV_PIX_FMT_NONE; n++) |
| 397 | 398 | { |
| @@ -489,8 +490,19 @@ static bool probe_formats(struct mp_filter *f, int hw_imgfmt, bool use_conversio · 91 unmodified lines | ||
| 489 | 490 | AV_HWFRAME_TRANSFER_DIRECTION_TO, &fmts, 0) >= 0 && |
| 490 | 491 | fmts[0] != AV_PIX_FMT_NONE) |
| 491 | 492 | { |
| 492 | − int index = p->num_fmts; | |
| 493 | − MP_TARRAY_APPEND(p, p->fmts, p->num_fmts, imgfmt); | |
| 493 | + // Don't add the format to p->fmts if we know it cannot be used. | |
| 494 | + if (ctx->supported_hwupload_formats) { | |
| 495 | + for (int i = 0; ctx->supported_hwupload_formats[i]; i++) { | |
| 496 | + if (ctx->supported_hwupload_formats[i] == imgfmt) | |
| 497 | + MP_TARRAY_APPEND(p, p->fmts, p->num_fmts, imgfmt); | |
| 498 | + } | |
| 499 | + } else { | |
| 500 | + MP_TARRAY_APPEND(p, p->fmts, p->num_fmts, imgfmt); | |
| 501 | + } | |
| 502 | + | |
| 503 | + int index = hw_transfer_index; | |
| 504 | + hw_transfer_index++; | |
| 505 | + | |
| 494 | 506 | MP_TARRAY_GROW(p, p->fmt_upload_index, index); |
| 495 | 507 | MP_TARRAY_GROW(p, p->fmt_upload_num, index); |
| 496 | 508 | |