summaryrefslogtreecommitdiffstats
path: root/video
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2018-03-01 14:11:42 +0100
committerJan Ekström <jeebjp@gmail.com>2018-03-03 02:38:01 +0200
commit39e03f60724510a70570302bdaddb7bee43cd9f5 (patch)
tree5511e57e0358f0b252580c342a5866b4bafa5dfa /video
parent55c88fdb8f1a9269f1a2010e7f108a4b76e42016 (diff)
downloadmpv-39e03f60724510a70570302bdaddb7bee43cd9f5.tar.bz2
mpv-39e03f60724510a70570302bdaddb7bee43cd9f5.tar.xz
mp_image: make ref error handling slightly readable
I think this is slightly more readable than this repeated "fail |= !".
Diffstat (limited to 'video')
-rw-r--r--video/mp_image.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/video/mp_image.c b/video/mp_image.c
index ecf4be7768..3511246b5b 100644
--- a/video/mp_image.c
+++ b/video/mp_image.c
@@ -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) {
*dst = av_buffer_ref(*dst);
if (!*dst)
- return false;
+ ok = false;
}
- return true;
}
// 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);
*new = *img;
- bool fail = false;
+ bool ok = true;
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);
- fail |= !ref_buffer(&new->icc_profile);
- fail |= !ref_buffer(&new->a53_cc);
+ ref_buffer(&ok, &new->hwctx);
+ ref_buffer(&ok, &new->icc_profile);
+ ref_buffer(&ok, &new->a53_cc);
new->ff_side_data = talloc_memdup(NULL, new->ff_side_data,
new->num_ff_side_data * sizeof(new->ff_side_data[0]));
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;
// Do this after _all_ bufs were changed; we don't want it to free bufs