[vlc-commits] vmem: fix callback usage (fixes #17187)
Rémi Denis-Courmont
git at videolan.org
Thu Sep 15 12:40:58 CEST 2016
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu Sep 15 13:38:47 2016 +0300| [489835e12c124a421ccb3cb7c0a5e38155ad7a55] | committer: Rémi Denis-Courmont
vmem: fix callback usage (fixes #17187)
This matches the documentation and behaviour expected by some existing
applications, but it is inefficient.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=489835e12c124a421ccb3cb7c0a5e38155ad7a55
---
modules/video_output/vmem.c | 91 ++++++++++++++-------------------------------
1 file changed, 28 insertions(+), 63 deletions(-)
diff --git a/modules/video_output/vmem.c b/modules/video_output/vmem.c
index 64aefa1..25d8a86 100644
--- a/modules/video_output/vmem.c
+++ b/modules/video_output/vmem.c
@@ -88,9 +88,9 @@ struct picture_sys_t {
/* NOTE: the callback prototypes must match those of LibVLC */
struct vout_display_sys_t {
picture_pool_t *pool;
- unsigned count;
void *opaque;
+ void *pic_opaque;
void *(*lock)(void *sys, void **plane);
void (*unlock)(void *sys, void *id, void *const *plane);
void (*display)(void *sys, void *id);
@@ -104,23 +104,10 @@ typedef unsigned (*vlc_format_cb)(void **, char *, unsigned *, unsigned *,
unsigned *, unsigned *);
static picture_pool_t *Pool (vout_display_t *, unsigned);
+static void Prepare(vout_display_t *, picture_t *, subpicture_t *);
static void Display(vout_display_t *, picture_t *, subpicture_t *);
static int Control(vout_display_t *, int, va_list);
-static void Unlock(void *data, picture_t *pic)
-{
- vout_display_sys_t *sys = data;
- picture_sys_t *picsys = pic->p_sys;
- void *planes[PICTURE_PLANE_MAX];
-
- assert(!picture_IsReferenced(pic));
-
- for (int i = 0; i < pic->i_planes; i++)
- planes[i] = pic->p[i].p_pixels;
-
- sys->unlock(sys->opaque, picsys->id, planes);
-}
-
/*****************************************************************************
* Open: allocates video thread
*****************************************************************************
@@ -160,9 +147,8 @@ static int Open(vlc_object_t *object)
memset(sys->pitches, 0, sizeof(sys->pitches));
memset(sys->lines, 0, sizeof(sys->lines));
- sys->count = setup(&sys->opaque, chroma, &fmt.i_width, &fmt.i_height,
- sys->pitches, sys->lines);
- if (sys->count == 0) {
+ if (setup(&sys->opaque, chroma, &fmt.i_width, &fmt.i_height,
+ sys->pitches, sys->lines) == 0) {
msg_Err(vd, "video format setup failure (no pictures)");
free(sys);
return VLC_EGENERIC;
@@ -183,7 +169,6 @@ static int Open(vlc_object_t *object)
sys->pitches[i] = sys->pitches[0];
sys->lines[i] = sys->lines[0];
}
- sys->count = 1;
sys->cleanup = NULL;
}
fmt.i_x_offset = fmt.i_y_offset = 0;
@@ -231,7 +216,7 @@ static int Open(vlc_object_t *object)
vd->fmt = fmt;
vd->info = info;
vd->pool = Pool;
- vd->prepare = NULL;
+ vd->prepare = Prepare;
vd->display = Display;
vd->control = Control;
vd->manage = NULL;
@@ -250,13 +235,8 @@ static void Close(vlc_object_t *object)
if (sys->cleanup)
sys->cleanup(sys->opaque);
-
if (sys->pool)
- {
- if (sys->unlock != NULL)
- picture_pool_Enum(sys->pool, Unlock, sys);
picture_pool_Release(sys->pool);
- }
free(sys);
}
@@ -264,50 +244,35 @@ static picture_pool_t *Pool(vout_display_t *vd, unsigned count)
{
vout_display_sys_t *sys = vd->sys;
- if (sys->pool)
- return sys->pool;
-
- if (count > sys->count)
- count = sys->count;
-
- picture_t *pictures[count];
-
- for (unsigned i = 0; i < count; i++) {
- picture_sys_t *picsys = malloc(sizeof (*picsys));
- if (unlikely(picsys == NULL))
- {
- count = i;
- break;
- }
- picsys->id = NULL;
-
- picture_resource_t rsc = { .p_sys = picsys };
- void *planes[PICTURE_PLANE_MAX];
+ if (sys->pool == NULL)
+ sys->pool = picture_pool_NewFromFormat(&vd->fmt, count);
+ return sys->pool;
+}
- picsys->id = sys->lock(sys->opaque, planes);
+static void Prepare(vout_display_t *vd, picture_t *pic, subpicture_t *subpic)
+{
+ vout_display_sys_t *sys = vd->sys;
+ picture_resource_t rsc = { .p_sys = NULL };
+ void *planes[PICTURE_PLANE_MAX];
- for (unsigned i = 0; i < PICTURE_PLANE_MAX; i++) {
- rsc.p[i].p_pixels = planes[i];
- rsc.p[i].i_lines = sys->lines[i];
- rsc.p[i].i_pitch = sys->pitches[i];
- }
+ sys->pic_opaque = sys->lock(sys->opaque, planes);
- pictures[i] = picture_NewFromResource(&vd->fmt, &rsc);
- if (!pictures[i]) {
- free(rsc.p_sys);
- count = i;
- break;
- }
+ for (unsigned i = 0; i < PICTURE_PLANE_MAX; i++) {
+ rsc.p[i].p_pixels = planes[i];
+ rsc.p[i].i_lines = sys->lines[i];
+ rsc.p[i].i_pitch = sys->pitches[i];
}
- /* */
- sys->pool = picture_pool_New(count, pictures);
- if (!sys->pool) {
- for (unsigned i = 0; i < count; i++)
- picture_Release(pictures[i]);
+ picture_t *locked = picture_NewFromResource(&vd->fmt, &rsc);
+ if (likely(locked != NULL)) {
+ picture_CopyPixels(locked, pic);
+ picture_Release(locked);
}
- return sys->pool;
+ if (sys->unlock != NULL)
+ sys->unlock(sys->opaque, sys->pic_opaque, planes);
+
+ (void) subpic;
}
static void Display(vout_display_t *vd, picture_t *pic, subpicture_t *subpic)
@@ -315,7 +280,7 @@ static void Display(vout_display_t *vd, picture_t *pic, subpicture_t *subpic)
vout_display_sys_t *sys = vd->sys;
if (sys->display != NULL)
- sys->display(sys->opaque, pic->p_sys->id);
+ sys->display(sys->opaque, sys->pic_opaque);
picture_Release(pic);
VLC_UNUSED(subpic);
More information about the vlc-commits
mailing list