path: root/video/mp_image.h
diff options
authorwm4 <wm4@nowhere>2015-07-05 23:56:00 +0200
committerwm4 <wm4@nowhere>2015-07-05 23:56:00 +0200
commit7b9d72658898574f4b001bcc496bf3532d4b3cc5 (patch)
tree9feae56717daaf423375a21ff6af29915655b895 /video/mp_image.h
parent34b223d730c97225accae4107a032c9b7ebf2194 (diff)
video: replace our own refcounting with libavutil's
mpv had refcounted frames before libav*, so we were not using libavutil's facilities. Change this and drop our own code. Since AVFrames are not actually refcounted, and only the image data they reference, the semantics change a bit. This affects mainly mp_image_pool, which was operating on whole images instead of buffers. While we could work on AVBufferRefs instead (and use AVBufferPool), this doesn't work for use with hardware decoding, which doesn't map cleanly to FFmpeg's reference counting. But it worked out. One weird consequence is that we still need our custom image data allocation function (for normal image data), because AVFrame's uses multiple buffers. There also seems to be a timing-dependent problem with vaapi (the pool appears to be "leaking" surfaces). I don't know if this is a new problem, or whether the code changes just happened to cause it more often. Raising the number of reserved surfaces seemed to fix it, but since it appears to be timing dependent, and I couldn't find anything wrong with the code, I'm just going to assume it's not a new bug.
Diffstat (limited to 'video/mp_image.h')
1 files changed, 9 insertions, 2 deletions
diff --git a/video/mp_image.h b/video/mp_image.h
index b0110c1376..f5759205f4 100644
--- a/video/mp_image.h
+++ b/video/mp_image.h
@@ -90,10 +90,16 @@ typedef struct mp_image {
/* only inside filter chain */
double pts;
- /* memory management */
- struct m_refcount *refcount;
/* for private use */
void* priv;
+ // Reference-counted data references.
+ // These do not necessarily map directly to planes[]. They can have
+ // different order or count. There shouldn't be more buffers than planes.
+ // If bufs[n] is NULL, bufs[n+1] must also be NULL.
+ // All mp_* functions manage this automatically; do not mess with it.
+ // (See also AVFrame.buf.)
+ struct AVBufferRef *bufs[MP_MAX_PLANES];
} mp_image_t;
int mp_chroma_div_up(int size, int shift);
@@ -120,6 +126,7 @@ int mp_image_plane_h(struct mp_image *mpi, int plane);
void mp_image_setfmt(mp_image_t* mpi, int out_fmt);
void mp_image_steal_data(struct mp_image *dst, struct mp_image *src);
+struct mp_image *mp_image_new_dummy_ref(struct mp_image *img);
struct mp_image *mp_image_new_custom_ref(struct mp_image *img, void *arg,
void (*free)(void *arg));