mirror of https://github.com/mpv-player/mpv
mp_image: make ref error handling slightly readable
I think this is slightly more readable than this repeated "fail |= !".
This commit is contained in:
parent
55c88fdb8f
commit
39e03f6072
|
@ -300,14 +300,13 @@ void mp_image_unref_data(struct mp_image *img)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool ref_buffer(AVBufferRef **dst)
|
static void ref_buffer(bool *ok, AVBufferRef **dst)
|
||||||
{
|
{
|
||||||
if (*dst) {
|
if (*dst) {
|
||||||
*dst = av_buffer_ref(*dst);
|
*dst = av_buffer_ref(*dst);
|
||||||
if (!*dst)
|
if (!*dst)
|
||||||
return false;
|
ok = false;
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return a new reference to img. The returned reference is owned by the caller,
|
// Return a new reference to img. The returned reference is owned by the caller,
|
||||||
|
@ -324,20 +323,20 @@ struct mp_image *mp_image_new_ref(struct mp_image *img)
|
||||||
talloc_set_destructor(new, mp_image_destructor);
|
talloc_set_destructor(new, mp_image_destructor);
|
||||||
*new = *img;
|
*new = *img;
|
||||||
|
|
||||||
bool fail = false;
|
bool ok = true;
|
||||||
for (int p = 0; p < MP_MAX_PLANES; p++)
|
for (int p = 0; p < MP_MAX_PLANES; p++)
|
||||||
fail |= !ref_buffer(&new->bufs[p]);
|
ref_buffer(&ok, &new->bufs[p]);
|
||||||
|
|
||||||
fail |= !ref_buffer(&new->hwctx);
|
ref_buffer(&ok, &new->hwctx);
|
||||||
fail |= !ref_buffer(&new->icc_profile);
|
ref_buffer(&ok, &new->icc_profile);
|
||||||
fail |= !ref_buffer(&new->a53_cc);
|
ref_buffer(&ok, &new->a53_cc);
|
||||||
|
|
||||||
new->ff_side_data = talloc_memdup(NULL, new->ff_side_data,
|
new->ff_side_data = talloc_memdup(NULL, new->ff_side_data,
|
||||||
new->num_ff_side_data * sizeof(new->ff_side_data[0]));
|
new->num_ff_side_data * sizeof(new->ff_side_data[0]));
|
||||||
for (int n = 0; n < new->num_ff_side_data; n++)
|
for (int n = 0; n < new->num_ff_side_data; n++)
|
||||||
fail |= !ref_buffer(&new->ff_side_data[n].buf);
|
ref_buffer(&ok, &new->ff_side_data[n].buf);
|
||||||
|
|
||||||
if (!fail)
|
if (ok)
|
||||||
return new;
|
return new;
|
||||||
|
|
||||||
// Do this after _all_ bufs were changed; we don't want it to free bufs
|
// Do this after _all_ bufs were changed; we don't want it to free bufs
|
||||||
|
|
Loading…
Reference in New Issue