summaryrefslogtreecommitdiffstats
path: root/video/filter
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-03-17 18:22:25 +0100
committerwm4 <wm4@nowhere>2014-03-17 18:22:25 +0100
commit31fc5e85636f8e7b3bec5f133cb82b78e3c86ddb (patch)
tree702027b802cb1d2f00b266280faac3de1b5b13f2 /video/filter
parent88aa3b8c986e0fdb74ae805b6a09d43789fb903e (diff)
downloadmpv-31fc5e85636f8e7b3bec5f133cb82b78e3c86ddb.tar.bz2
mpv-31fc5e85636f8e7b3bec5f133cb82b78e3c86ddb.tar.xz
vaapi: replace image pool implementation with mp_image_pool
Although I at first thought it would be better to have a separate implementation for hwaccels because the difference to software images are too large, it turns out you can actually save some code with it. Note that the old implementation had a small memory management bug. This got painted over in commit 269c1e1, but is hereby solved properly. Also note that I couldn't test vf_vavpp.c (due to lack of hardware), and I hope I didn't accidentally break it.
Diffstat (limited to 'video/filter')
-rw-r--r--video/filter/vf_vavpp.c43
1 files changed, 26 insertions, 17 deletions
diff --git a/video/filter/vf_vavpp.c b/video/filter/vf_vavpp.c
index 7ebb8f3eb0..a1a7d3adf0 100644
--- a/video/filter/vf_vavpp.c
+++ b/video/filter/vf_vavpp.c
@@ -23,6 +23,7 @@
#include "vf.h"
#include "video/vaapi.h"
#include "video/hwdec.h"
+#include "video/mp_image_pool.h"
static bool check_error(struct vf_instance *vf, VAStatus status, const char *msg)
{
@@ -59,7 +60,8 @@ struct vf_priv_s {
VADisplay display;
struct mp_vaapi_ctx *va;
struct pipeline pipe;
- struct va_surface_pool *pool;
+ struct mp_image_pool *pool;
+ int current_rt_format;
};
static const struct vf_priv_s vf_priv_default = {
@@ -127,13 +129,16 @@ static struct mp_image *render(struct vf_instance *vf, struct va_surface *in,
struct vf_priv_s *p = vf->priv;
if (!p->pipe.filters || !in)
return NULL;
- struct va_surface *out = va_surface_pool_get(p->pool, in->w, in->h);
- if (!out)
+ struct mp_image *img = mp_image_pool_get(p->pool, IMGFMT_VAAPI, in->w, in->h);
+ if (!img)
return NULL;
enum {Begun = 1, Rendered = 2};
int state = 0;
do { // not a loop, just for break
- VAStatus status = vaBeginPicture(p->display, p->context, out->id);
+ VASurfaceID id = va_surface_id_in_mp_image(img);
+ if (id == VA_INVALID_ID)
+ break;
+ VAStatus status = vaBeginPicture(p->display, p->context, id);
if (!check_error(vf, status, "vaBeginPicture()"))
break;
state |= Begun;
@@ -167,8 +172,8 @@ static struct mp_image *render(struct vf_instance *vf, struct va_surface *in,
if (state & Begun)
vaEndPicture(p->display, p->context);
if (state & Rendered)
- return va_surface_wrap(out);
- va_surface_release(out);
+ return img;
+ talloc_free(img);
return NULL;
}
@@ -203,13 +208,13 @@ static int process(struct vf_instance *vf, struct mp_image *in,
static struct mp_image *upload(struct vf_instance *vf, struct mp_image *in)
{
struct vf_priv_s *p = vf->priv;
- struct va_surface *surface =
- va_surface_pool_get_by_imgfmt(p->pool, in->imgfmt, in->w, in->h);
- if (!surface)
- surface = va_surface_pool_get(p->pool, in->w, in->h); // dummy
- else
- va_surface_upload(surface, in);
- struct mp_image *out = va_surface_wrap(surface);
+ struct mp_image *out = mp_image_pool_get(p->pool, IMGFMT_VAAPI, in->w, in->h);
+ if (!out)
+ return NULL;
+ if (va_surface_upload_image(out, in) < 0) {
+ talloc_free(out);
+ return NULL;
+ }
mp_image_copy_attributes(out, in);
return out;
}
@@ -219,14 +224,18 @@ static int filter_ext(struct vf_instance *vf, struct mp_image *in)
struct vf_priv_s *p = vf->priv;
struct va_surface *surface = va_surface_in_mp_image(in);
const int rt_format = surface ? surface->rt_format : VA_RT_FORMAT_YUV420;
- if (!p->pool || va_surface_pool_rt_format(p->pool) != rt_format) {
- va_surface_pool_release(p->pool);
- p->pool = va_surface_pool_alloc(p->va, rt_format);
+ if (!p->pool || p->current_rt_format != rt_format) {
+ talloc_free(p->pool);
+ p->pool = mp_image_pool_new(20);
+ va_pool_set_allocator(p->pool, p->va, rt_format);
+ p->current_rt_format = rt_format;
}
if (!surface) {
struct mp_image *tmp = upload(vf, in);
talloc_free(in);
in = tmp;
+ if (!in)
+ return -1;
}
struct mp_image *out1, *out2;
@@ -267,7 +276,7 @@ static void uninit(struct vf_instance *vf)
vaDestroyConfig(p->display, p->config);
free(p->pipe.forward.surfaces);
free(p->pipe.backward.surfaces);
- va_surface_pool_release(p->pool);
+ talloc_free(p->pool);
}
static int query_format(struct vf_instance *vf, unsigned int imgfmt)