Commit fc5204e3 authored by Julian Scheel's avatar Julian Scheel Committed by Rémi Denis-Courmont

mmal: Replace global mutex by module-owned mutex

The mutex held within mmal_pictures is used to lock access of mmal
picture/buffer pools between vlc main thread and mmal callback threads. This
is only required to be locked per pool and not globally for all mmal modules.
Thus using a global mutex caused a slight performance hit when using mmal vout
and deinterlace simultaneously which operate on independent picture pools. Now
the pool owner provides the mutex handle when allocating the pictures, so
that independent locking can be used.
Signed-off-by: default avatarJulian Scheel <julian@jusst.de>
Signed-off-by: default avatarRémi Denis-Courmont <remi@remlab.net>
parent 572e1eb6
...@@ -98,6 +98,7 @@ static int create_picture_pool(filter_t *filter) ...@@ -98,6 +98,7 @@ static int create_picture_pool(filter_t *filter)
picture_res.p_sys->owner = (vlc_object_t *)filter; picture_res.p_sys->owner = (vlc_object_t *)filter;
picture_res.p_sys->queue = sys->output_pool->queue; picture_res.p_sys->queue = sys->output_pool->queue;
picture_res.p_sys->mutex = &sys->mutex;
sys->pictures[i] = picture_NewFromResource(&filter->fmt_out.video, sys->pictures[i] = picture_NewFromResource(&filter->fmt_out.video,
&picture_res); &picture_res);
......
...@@ -27,18 +27,12 @@ ...@@ -27,18 +27,12 @@
#include "mmal_picture.h" #include "mmal_picture.h"
vlc_mutex_t* get_mmal_opaque_mutex(void)
{
static vlc_mutex_t mmal_mutex = VLC_STATIC_MUTEX;
return &mmal_mutex;
}
int mmal_picture_lock(picture_t *picture) int mmal_picture_lock(picture_t *picture)
{ {
picture_sys_t *pic_sys = picture->p_sys; picture_sys_t *pic_sys = picture->p_sys;
int ret = VLC_SUCCESS; int ret = VLC_SUCCESS;
vlc_mutex_lock(get_mmal_opaque_mutex()); vlc_mutex_lock(pic_sys->mutex);
MMAL_BUFFER_HEADER_T *buffer = mmal_queue_timedwait(pic_sys->queue, 2); MMAL_BUFFER_HEADER_T *buffer = mmal_queue_timedwait(pic_sys->queue, 2);
if (!buffer) { if (!buffer) {
...@@ -57,7 +51,7 @@ int mmal_picture_lock(picture_t *picture) ...@@ -57,7 +51,7 @@ int mmal_picture_lock(picture_t *picture)
pic_sys->displayed = false; pic_sys->displayed = false;
out: out:
vlc_mutex_unlock(get_mmal_opaque_mutex()); vlc_mutex_unlock(pic_sys->mutex);
return ret; return ret;
} }
...@@ -66,7 +60,7 @@ void mmal_picture_unlock(picture_t *picture) ...@@ -66,7 +60,7 @@ void mmal_picture_unlock(picture_t *picture)
picture_sys_t *pic_sys = picture->p_sys; picture_sys_t *pic_sys = picture->p_sys;
MMAL_BUFFER_HEADER_T *buffer = pic_sys->buffer; MMAL_BUFFER_HEADER_T *buffer = pic_sys->buffer;
vlc_mutex_lock(get_mmal_opaque_mutex()); vlc_mutex_lock(pic_sys->mutex);
pic_sys->buffer = NULL; pic_sys->buffer = NULL;
if (buffer) { if (buffer) {
...@@ -74,5 +68,5 @@ void mmal_picture_unlock(picture_t *picture) ...@@ -74,5 +68,5 @@ void mmal_picture_unlock(picture_t *picture)
mmal_buffer_header_release(buffer); mmal_buffer_header_release(buffer);
} }
vlc_mutex_unlock(get_mmal_opaque_mutex()); vlc_mutex_unlock(pic_sys->mutex);
} }
...@@ -32,6 +32,7 @@ struct picture_sys_t { ...@@ -32,6 +32,7 @@ struct picture_sys_t {
MMAL_BUFFER_HEADER_T *buffer; MMAL_BUFFER_HEADER_T *buffer;
MMAL_QUEUE_T *queue; MMAL_QUEUE_T *queue;
vlc_mutex_t *mutex;
bool displayed; bool displayed;
}; };
......
...@@ -498,6 +498,7 @@ static picture_pool_t *vd_pool(vout_display_t *vd, unsigned count) ...@@ -498,6 +498,7 @@ static picture_pool_t *vd_pool(vout_display_t *vd, unsigned count)
picture_res.p_sys = calloc(1, sizeof(picture_sys_t)); picture_res.p_sys = calloc(1, sizeof(picture_sys_t));
picture_res.p_sys->owner = (vlc_object_t *)vd; picture_res.p_sys->owner = (vlc_object_t *)vd;
picture_res.p_sys->queue = sys->pool->queue; picture_res.p_sys->queue = sys->pool->queue;
picture_res.p_sys->mutex = &sys->buffer_mutex;
sys->pictures[i] = picture_NewFromResource(&fmt, &picture_res); sys->pictures[i] = picture_NewFromResource(&fmt, &picture_res);
if (!sys->pictures[i]) { if (!sys->pictures[i]) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment