From e1f1b0c275401c96c5ce776d74aff144359e6495 Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 14 Apr 2014 20:49:14 +0200 Subject: vf_vapoursynth: handle destruction more gracefully We were relying on vsscript_freeScript() to take care of proper termination. But it doesn't do that: it doesn't wait for the filters to finish and exit at all. Instead, it just destroys all objects, which causes the worker threads to crash sometimes. Also, we're supposed to wait for the frame callback to finish before freeing the associated node. Handle this by explicitly waiting as far as we can. Probably fixes crashes on seeking, although VapourSynth itself might also need some work to make this case completely stable. --- video/filter/vf_vapoursynth.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'video') diff --git a/video/filter/vf_vapoursynth.c b/video/filter/vf_vapoursynth.c index bb3faed28a..4acea8e056 100644 --- a/video/filter/vf_vapoursynth.c +++ b/video/filter/vf_vapoursynth.c @@ -307,18 +307,20 @@ static void destroy_vs(struct vf_instance *vf) { struct vf_priv_s *p = vf->priv; + // Wait until our frame callback returns. + pthread_mutex_lock(&p->lock); + p->shutdown = true; + pthread_cond_broadcast(&p->wakeup); + while (p->getting_frame) + pthread_cond_wait(&p->wakeup, &p->lock); + pthread_mutex_unlock(&p->lock); + if (p->in_node) p->vsapi->freeNode(p->in_node); if (p->out_node) p->vsapi->freeNode(p->out_node); p->in_node = p->out_node = NULL; - pthread_mutex_lock(&p->lock); - p->shutdown = true; - pthread_cond_broadcast(&p->wakeup); - pthread_mutex_unlock(&p->lock); - - // Expect that this properly waits until all filters return etc. if (p->se) vsscript_freeScript(p->se); @@ -326,7 +328,6 @@ static void destroy_vs(struct vf_instance *vf) p->vsapi = NULL; p->vscore = NULL; - assert(!p->getting_frame); assert(!p->in_node_active); p->shutdown = false; -- cgit v1.2.3