[vlc-commits] mmal: Replace global mutex by module-owned mutex

Julian Scheel git at videolan.org
Tue Jan 20 07:08:04 CET 2015


vlc | branch: master | Julian Scheel <julian at jusst.de> | Mon Jan 19 11:30:23 2015 +0100| [fc5204e32cf1d761220749eba69f23559ec968f4] | committer: 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: Julian Scheel <julian at jusst.de>
Signed-off-by: Rémi Denis-Courmont <remi at remlab.net>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=fc5204e32cf1d761220749eba69f23559ec968f4
---

 modules/hw/mmal/deinterlace.c  |    1 +
 modules/hw/mmal/mmal_picture.c |   14 ++++----------
 modules/hw/mmal/mmal_picture.h |    1 +
 modules/hw/mmal/vout.c         |    1 +
 4 files changed, 7 insertions(+), 10 deletions(-)

diff --git a/modules/hw/mmal/deinterlace.c b/modules/hw/mmal/deinterlace.c
index c290cf0..dc908aa 100644
--- a/modules/hw/mmal/deinterlace.c
+++ b/modules/hw/mmal/deinterlace.c
@@ -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->queue = sys->output_pool->queue;
+        picture_res.p_sys->mutex = &sys->mutex;
 
         sys->pictures[i] = picture_NewFromResource(&filter->fmt_out.video,
                 &picture_res);
diff --git a/modules/hw/mmal/mmal_picture.c b/modules/hw/mmal/mmal_picture.c
index 9348a70..50ca6d4 100644
--- a/modules/hw/mmal/mmal_picture.c
+++ b/modules/hw/mmal/mmal_picture.c
@@ -27,18 +27,12 @@
 
 #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)
 {
     picture_sys_t *pic_sys = picture->p_sys;
     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);
     if (!buffer) {
@@ -57,7 +51,7 @@ int mmal_picture_lock(picture_t *picture)
     pic_sys->displayed = false;
 
 out:
-    vlc_mutex_unlock(get_mmal_opaque_mutex());
+    vlc_mutex_unlock(pic_sys->mutex);
     return ret;
 }
 
@@ -66,7 +60,7 @@ void mmal_picture_unlock(picture_t *picture)
     picture_sys_t *pic_sys = picture->p_sys;
     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;
     if (buffer) {
@@ -74,5 +68,5 @@ void mmal_picture_unlock(picture_t *picture)
         mmal_buffer_header_release(buffer);
     }
 
-    vlc_mutex_unlock(get_mmal_opaque_mutex());
+    vlc_mutex_unlock(pic_sys->mutex);
 }
diff --git a/modules/hw/mmal/mmal_picture.h b/modules/hw/mmal/mmal_picture.h
index 47fbd3e..e5276af 100644
--- a/modules/hw/mmal/mmal_picture.h
+++ b/modules/hw/mmal/mmal_picture.h
@@ -32,6 +32,7 @@ struct picture_sys_t {
 
     MMAL_BUFFER_HEADER_T *buffer;
     MMAL_QUEUE_T *queue;
+    vlc_mutex_t *mutex;
     bool displayed;
 };
 
diff --git a/modules/hw/mmal/vout.c b/modules/hw/mmal/vout.c
index adc151d..0e67525 100644
--- a/modules/hw/mmal/vout.c
+++ b/modules/hw/mmal/vout.c
@@ -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->owner = (vlc_object_t *)vd;
         picture_res.p_sys->queue = sys->pool->queue;
+        picture_res.p_sys->mutex = &sys->buffer_mutex;
 
         sys->pictures[i] = picture_NewFromResource(&fmt, &picture_res);
         if (!sys->pictures[i]) {



More information about the vlc-commits mailing list