diff options
author | wm4 <wm4@nowhere> | 2014-06-17 22:43:43 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2014-06-17 22:43:43 +0200 |
commit | 72aac9ae8a0053e7c30199044cc2c9493a39b793 (patch) | |
tree | 90c61f53e20aac949fd4c513267d080814ebf4a8 /video/mp_image_pool.c | |
parent | 973c1fa5701366eed3752666d6035454ae37712c (diff) | |
download | mpv-72aac9ae8a0053e7c30199044cc2c9493a39b793.tar.bz2 mpv-72aac9ae8a0053e7c30199044cc2c9493a39b793.tar.xz |
video: introduce failure path for image allocations
Until now, failure to allocate image data resulted in a crash (i.e.
abort() was called). This was intentional, because it's pretty silly to
degrade playback, and in almost all situations, the OOM will probably
kill you anyway. (And then there's the standard Linux overcommit
behavior, which also will kill you at some point.)
But I changed my opinion, so here we go. This change does not affect
_all_ memory allocations, just image data. Now in most failure cases,
the output will just be skipped. For video filters, this coincidentally
means that failure is treated as EOF (because the playback core assumes
EOF if nothing comes out of the video filter chain). In other
situations, output might be in some way degraded, like skipping frames,
not scaling OSD, and such.
Functions whose return values changed semantics:
mp_image_alloc
mp_image_new_copy
mp_image_new_ref
mp_image_make_writeable
mp_image_setrefp
mp_image_to_av_frame_and_unref
mp_image_from_av_frame
mp_image_new_external_ref
mp_image_new_custom_ref
mp_image_pool_make_writeable
mp_image_pool_get
mp_image_pool_new_copy
mp_vdpau_mixed_frame_create
vf_alloc_out_image
vf_make_out_image_writeable
glGetWindowScreenshot
Diffstat (limited to 'video/mp_image_pool.c')
-rw-r--r-- | video/mp_image_pool.c | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/video/mp_image_pool.c b/video/mp_image_pool.c index c2d1fca080..62d55cc372 100644 --- a/video/mp_image_pool.c +++ b/video/mp_image_pool.c @@ -147,6 +147,7 @@ struct mp_image *mp_image_pool_get_no_alloc(struct mp_image_pool *pool, int fmt, // mp_image_alloc() is that there is a transparent mechanism to recycle image // data allocations through this pool. // The image can be free'd with talloc_free(). +// Returns NULL on OOM. struct mp_image *mp_image_pool_get(struct mp_image_pool *pool, int fmt, int w, int h) { @@ -171,24 +172,35 @@ struct mp_image *mp_image_pool_get(struct mp_image_pool *pool, int fmt, } // Like mp_image_new_copy(), but allocate the image out of the pool. +// Returns NULL on OOM. struct mp_image *mp_image_pool_new_copy(struct mp_image_pool *pool, struct mp_image *img) { struct mp_image *new = mp_image_pool_get(pool, img->imgfmt, img->w, img->h); - mp_image_copy(new, img); - mp_image_copy_attributes(new, img); + if (new) { + mp_image_copy(new, img); + mp_image_copy_attributes(new, img); + } return new; } // Like mp_image_make_writeable(), but if a copy has to be made, allocate it // out of the pool. -void mp_image_pool_make_writeable(struct mp_image_pool *pool, +// If pool==NULL, mp_image_make_writeable() is called (for convenience). +// Returns false on failure (see mp_image_make_writeable()). +bool mp_image_pool_make_writeable(struct mp_image_pool *pool, struct mp_image *img) { if (mp_image_is_writeable(img)) - return; - mp_image_steal_data(img, mp_image_pool_new_copy(pool, img)); + return true; + if (!pool) + return mp_image_make_writeable(img); + struct mp_image *new = mp_image_pool_new_copy(pool, img); + if (!new) + return false; + mp_image_steal_data(img, new); assert(mp_image_is_writeable(img)); + return true; } void mp_image_pool_set_allocator(struct mp_image_pool *pool, |