[vlc-devel] [PATCH 1/2] mmal: Add shared code for handling mmal pictures

Julian Scheel julian at jusst.de
Fri Aug 29 09:19:56 CEST 2014


Outsource some of the picture handling code from the mmal video_output into a
dedicated file. This is required as it will be used by the mmal filter plugin
later on as well.

Signed-off-by: Julian Scheel <julian at jusst.de>
---
 modules/hw/mmal/Makefile.am    |  2 +-
 modules/hw/mmal/mmal_picture.c | 78 ++++++++++++++++++++++++++++++++++++++++++
 modules/hw/mmal/mmal_picture.h | 37 ++++++++++++++++++++
 modules/hw/mmal/vout.c         | 70 +++++--------------------------------
 4 files changed, 125 insertions(+), 62 deletions(-)
 create mode 100644 modules/hw/mmal/mmal_picture.c
 create mode 100644 modules/hw/mmal/mmal_picture.h

diff --git a/modules/hw/mmal/Makefile.am b/modules/hw/mmal/Makefile.am
index 4f7f275..c01d654 100644
--- a/modules/hw/mmal/Makefile.am
+++ b/modules/hw/mmal/Makefile.am
@@ -4,7 +4,7 @@ mmaldir = $(pluginsdir)/mmal
 AM_CFLAGS += $(CFLAGS_mmal)
 AM_LDFLAGS += -rpath '$(mmaldir)' $(LDFLAGS_mmal)
 
-libmmal_vout_plugin_la_SOURCES = vout.c
+libmmal_vout_plugin_la_SOURCES = vout.c mmal_picture.c
 libmmal_vout_plugin_la_CFLAGS = $(AM_CFLAGS)
 libmmal_vout_plugin_la_LDFLAGS = $(AM_LDFLAGS) -lm
 libmmal_vout_plugin_la_LIBADD = $(LIBS_mmal)
diff --git a/modules/hw/mmal/mmal_picture.c b/modules/hw/mmal/mmal_picture.c
new file mode 100644
index 0000000..8df225b
--- /dev/null
+++ b/modules/hw/mmal/mmal_picture.c
@@ -0,0 +1,78 @@
+/*****************************************************************************
+ * mmal_picture.c: MMAL picture related shared functionality
+ *****************************************************************************
+ * Copyright © 2014 jusst technologies GmbH
+ * $Id$
+ *
+ * Authors: Julian Scheel <julian at jusst.de>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#include <vlc_common.h>
+#include <vlc_picture.h>
+#include <interface/mmal/mmal.h>
+
+#include "mmal_picture.h"
+
+vlc_mutex_t* get_mmal_opaque_mutex()
+{
+    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());
+
+    MMAL_BUFFER_HEADER_T *buffer = mmal_queue_wait(pic_sys->queue);
+    if (!buffer) {
+        ret = VLC_EGENERIC;
+        goto out;
+    }
+
+    mmal_buffer_header_reset(buffer);
+    buffer->user_data = picture;
+    picture->p[0].p_pixels = buffer->data;
+    picture->p[1].p_pixels += (ptrdiff_t)buffer->data;
+    picture->p[2].p_pixels += (ptrdiff_t)buffer->data;
+
+    pic_sys->buffer = buffer;
+
+    pic_sys->displayed = false;
+
+out:
+    vlc_mutex_unlock(get_mmal_opaque_mutex());
+    return ret;
+}
+
+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());
+
+    pic_sys->buffer = NULL;
+    if (buffer) {
+        buffer->user_data = NULL;
+        mmal_buffer_header_release(buffer);
+    }
+
+    vlc_mutex_unlock(get_mmal_opaque_mutex());
+}
diff --git a/modules/hw/mmal/mmal_picture.h b/modules/hw/mmal/mmal_picture.h
new file mode 100644
index 0000000..ed40694
--- /dev/null
+++ b/modules/hw/mmal/mmal_picture.h
@@ -0,0 +1,37 @@
+/*****************************************************************************
+ * mmal_picture.h: Shared header for MMAL pictures
+ *****************************************************************************
+ * Copyright © 2014 jusst technologies GmbH
+ * $Id$
+ *
+ * Authors: Julian Scheel <julian at jusst.de>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#include <vlc_common.h>
+#include <interface/mmal/mmal.h>
+
+struct picture_sys_t {
+    vlc_object_t *owner;
+
+    MMAL_BUFFER_HEADER_T *buffer;
+    MMAL_QUEUE_T *queue;
+    bool displayed;
+};
+
+vlc_mutex_t* get_mmal_opaque_mutex();
+int mmal_picture_lock(picture_t *picture);
+void mmal_picture_unlock(picture_t *picture);
diff --git a/modules/hw/mmal/vout.c b/modules/hw/mmal/vout.c
index 901f8bd..c58fd89 100644
--- a/modules/hw/mmal/vout.c
+++ b/modules/hw/mmal/vout.c
@@ -33,6 +33,8 @@
 #include <vlc_threads.h>
 #include <vlc_vout_display.h>
 
+#include "mmal_picture.h"
+
 #include <bcm_host.h>
 #include <interface/mmal/mmal.h>
 #include <interface/mmal/util/mmal_util.h>
@@ -111,12 +113,6 @@ struct vout_display_sys_t {
     bool opaque;
 };
 
-struct picture_sys_t {
-    vout_display_t *vd;
-    MMAL_BUFFER_HEADER_T *buffer;
-    bool displayed;
-};
-
 static const vlc_fourcc_t subpicture_chromas[] = {
     VLC_CODEC_RGBA,
     0
@@ -134,10 +130,6 @@ static void vd_display(vout_display_t *vd, picture_t *picture,
 static int vd_control(vout_display_t *vd, int query, va_list args);
 static void vd_manage(vout_display_t *vd);
 
-/* VLC picture pool */
-static int picture_lock(picture_t *picture);
-static void picture_unlock(picture_t *picture);
-
 /* MMAL callbacks */
 static void control_port_cb(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer);
 static void input_port_cb(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer);
@@ -472,9 +464,9 @@ static picture_pool_t *vd_pool(vout_display_t *vd, unsigned count)
     memset(&picture_res, 0, sizeof(picture_resource_t));
     sys->pictures = calloc(sys->num_buffers, sizeof(picture_t *));
     for (i = 0; i < sys->num_buffers; ++i) {
-        picture_res.p_sys = malloc(sizeof(picture_sys_t));
-        picture_res.p_sys->vd = vd;
-        picture_res.p_sys->buffer = NULL;
+        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;
 
         sys->pictures[i] = picture_NewFromResource(&fmt, &picture_res);
         if (!sys->pictures[i]) {
@@ -482,13 +474,15 @@ static picture_pool_t *vd_pool(vout_display_t *vd, unsigned count)
             free(picture_res.p_sys);
             goto out;
         }
+
+        memcpy(sys->pictures[i]->p, sys->planes, sizeof(sys->planes));
     }
 
     memset(&picture_pool_cfg, 0, sizeof(picture_pool_configuration_t));
     picture_pool_cfg.picture_count = sys->num_buffers;
     picture_pool_cfg.picture = sys->pictures;
-    picture_pool_cfg.lock = picture_lock;
-    picture_pool_cfg.unlock = picture_unlock;
+    picture_pool_cfg.lock = mmal_picture_lock;
+    picture_pool_cfg.unlock = mmal_picture_unlock;
 
     sys->picture_pool = picture_pool_NewExtended(&picture_pool_cfg);
     if (!sys->picture_pool) {
@@ -636,52 +630,6 @@ static void vd_manage(vout_display_t *vd)
     vlc_mutex_unlock(&sys->manage_mutex);
 }
 
-static int picture_lock(picture_t *picture)
-{
-    vout_display_t *vd = picture->p_sys->vd;
-    vout_display_sys_t *sys = vd->sys;
-    picture_sys_t *pic_sys = picture->p_sys;
-
-    MMAL_BUFFER_HEADER_T *buffer = mmal_queue_wait(sys->pool->queue);
-    if (!buffer)
-        return VLC_EGENERIC;
-
-    vlc_mutex_lock(&sys->buffer_mutex);
-
-    mmal_buffer_header_reset(buffer);
-    buffer->user_data = picture;
-    pic_sys->buffer = buffer;
-
-    memcpy(picture->p, sys->planes, sizeof(sys->planes));
-    picture->p[0].p_pixels = buffer->data;
-    picture->p[1].p_pixels += (ptrdiff_t)buffer->data;
-    picture->p[2].p_pixels += (ptrdiff_t)buffer->data;
-
-    pic_sys->displayed = false;
-
-    vlc_mutex_unlock(&sys->buffer_mutex);
-
-    return VLC_SUCCESS;
-}
-
-static void picture_unlock(picture_t *picture)
-{
-    picture_sys_t *pic_sys = picture->p_sys;
-    vout_display_t *vd = pic_sys->vd;
-    vout_display_sys_t *sys = vd->sys;
-    MMAL_BUFFER_HEADER_T *buffer = pic_sys->buffer;
-
-    vlc_mutex_lock(&sys->buffer_mutex);
-
-    pic_sys->buffer = NULL;
-    if (buffer) {
-        buffer->user_data = NULL;
-        mmal_buffer_header_release(buffer);
-    }
-
-    vlc_mutex_unlock(&sys->buffer_mutex);
-}
-
 static void control_port_cb(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer)
 {
     vout_display_t *vd = (vout_display_t *)port->userdata;
-- 
2.1.0




More information about the vlc-devel mailing list