Commit 7b0df083 authored by Niklas Haas's avatar Niklas Haas
Browse files

utils/libav: improve robustness of asynchronous uploads

1. Use callbacks only if they're actually supported.
2. Allow asynchronous transfers for all planes, not just the ones that
   happen to be the same plane as allocated buffers.
3. Avoid making any assumptions about the association between planes and
   buffers, since in practice this is completely false anyway.
parent e3899778
......@@ -602,10 +602,10 @@ static inline bool pl_frame_recreate_from_avframe(const struct pl_gpu *gpu,
return true;
static void pl_avbuffer_free(void *priv)
static void pl_avframe_free(void *priv)
AVBufferRef *buf = priv;
AVFrame *frame = priv;
static inline bool pl_upload_avframe(const struct pl_gpu *gpu,
......@@ -633,15 +633,16 @@ static inline bool pl_upload_avframe(const struct pl_gpu *gpu,
data[p].row_stride = frame->linesize[p];
data[p].pixels = frame->data[p];
// Try using an asynchronous upload if possible, by taking a new ref to
// the plane data
if (frame->buf[p]) {
data[p].callback = pl_avbuffer_free;
data[p].priv = av_buffer_ref(frame->buf[p]);
if (gpu->caps & PL_GPU_CAP_CALLBACKS) {
// Use asynchronous upload if possible
data[p].callback = pl_avframe_free;
data[p].priv = av_frame_clone(frame);
if (!pl_upload_plane(gpu, &out->planes[p], &tex[p], &data[p]))
if (!pl_upload_plane(gpu, &out->planes[p], &tex[p], &data[p])) {
return false;
return true;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment