Commit 243c5854 authored by Julian Scheel's avatar Julian Scheel Committed by Jean-Baptiste Kempf

mmal: Add shared code for handling mmal pictures

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: default avatarJulian Scheel <julian@jusst.de>
Signed-off-by: default avatarJean-Baptiste Kempf <jb@videolan.org>
parent 26e73f0f
...@@ -4,7 +4,7 @@ mmaldir = $(pluginsdir)/mmal ...@@ -4,7 +4,7 @@ mmaldir = $(pluginsdir)/mmal
AM_CFLAGS += $(CFLAGS_mmal) AM_CFLAGS += $(CFLAGS_mmal)
AM_LDFLAGS += -rpath '$(mmaldir)' $(LDFLAGS_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_CFLAGS = $(AM_CFLAGS)
libmmal_vout_plugin_la_LDFLAGS = $(AM_LDFLAGS) -lm libmmal_vout_plugin_la_LDFLAGS = $(AM_LDFLAGS) -lm
libmmal_vout_plugin_la_LIBADD = $(LIBS_mmal) libmmal_vout_plugin_la_LIBADD = $(LIBS_mmal)
......
/*****************************************************************************
* mmal_picture.c: MMAL picture related shared functionality
*****************************************************************************
* Copyright © 2014 jusst technologies GmbH
* $Id$
*
* Authors: Julian Scheel <julian@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(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());
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());
}
/*****************************************************************************
* mmal_picture.h: Shared header for MMAL pictures
*****************************************************************************
* Copyright © 2014 jusst technologies GmbH
* $Id$
*
* Authors: Julian Scheel <julian@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(void);
int mmal_picture_lock(picture_t *picture);
void mmal_picture_unlock(picture_t *picture);
...@@ -33,6 +33,8 @@ ...@@ -33,6 +33,8 @@
#include <vlc_threads.h> #include <vlc_threads.h>
#include <vlc_vout_display.h> #include <vlc_vout_display.h>
#include "mmal_picture.h"
#include <bcm_host.h> #include <bcm_host.h>
#include <interface/mmal/mmal.h> #include <interface/mmal/mmal.h>
#include <interface/mmal/util/mmal_util.h> #include <interface/mmal/util/mmal_util.h>
...@@ -111,12 +113,6 @@ struct vout_display_sys_t { ...@@ -111,12 +113,6 @@ struct vout_display_sys_t {
bool opaque; bool opaque;
}; };
struct picture_sys_t {
vout_display_t *vd;
MMAL_BUFFER_HEADER_T *buffer;
bool displayed;
};
static const vlc_fourcc_t subpicture_chromas[] = { static const vlc_fourcc_t subpicture_chromas[] = {
VLC_CODEC_RGBA, VLC_CODEC_RGBA,
0 0
...@@ -134,10 +130,6 @@ static void vd_display(vout_display_t *vd, picture_t *picture, ...@@ -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 int vd_control(vout_display_t *vd, int query, va_list args);
static void vd_manage(vout_display_t *vd); 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 */ /* MMAL callbacks */
static void control_port_cb(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer); 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); 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) ...@@ -472,9 +464,9 @@ static picture_pool_t *vd_pool(vout_display_t *vd, unsigned count)
memset(&picture_res, 0, sizeof(picture_resource_t)); memset(&picture_res, 0, sizeof(picture_resource_t));
sys->pictures = calloc(sys->num_buffers, sizeof(picture_t *)); sys->pictures = calloc(sys->num_buffers, sizeof(picture_t *));
for (i = 0; i < sys->num_buffers; ++i) { for (i = 0; i < sys->num_buffers; ++i) {
picture_res.p_sys = malloc(sizeof(picture_sys_t)); picture_res.p_sys = calloc(1, sizeof(picture_sys_t));
picture_res.p_sys->vd = vd; picture_res.p_sys->owner = (vlc_object_t *)vd;
picture_res.p_sys->buffer = NULL; picture_res.p_sys->queue = sys->pool->queue;
sys->pictures[i] = picture_NewFromResource(&fmt, &picture_res); sys->pictures[i] = picture_NewFromResource(&fmt, &picture_res);
if (!sys->pictures[i]) { if (!sys->pictures[i]) {
...@@ -482,13 +474,15 @@ static picture_pool_t *vd_pool(vout_display_t *vd, unsigned count) ...@@ -482,13 +474,15 @@ static picture_pool_t *vd_pool(vout_display_t *vd, unsigned count)
free(picture_res.p_sys); free(picture_res.p_sys);
goto out; goto out;
} }
memcpy(sys->pictures[i]->p, sys->planes, sizeof(sys->planes));
} }
memset(&picture_pool_cfg, 0, sizeof(picture_pool_configuration_t)); memset(&picture_pool_cfg, 0, sizeof(picture_pool_configuration_t));
picture_pool_cfg.picture_count = sys->num_buffers; picture_pool_cfg.picture_count = sys->num_buffers;
picture_pool_cfg.picture = sys->pictures; picture_pool_cfg.picture = sys->pictures;
picture_pool_cfg.lock = picture_lock; picture_pool_cfg.lock = mmal_picture_lock;
picture_pool_cfg.unlock = picture_unlock; picture_pool_cfg.unlock = mmal_picture_unlock;
sys->picture_pool = picture_pool_NewExtended(&picture_pool_cfg); sys->picture_pool = picture_pool_NewExtended(&picture_pool_cfg);
if (!sys->picture_pool) { if (!sys->picture_pool) {
...@@ -636,52 +630,6 @@ static void vd_manage(vout_display_t *vd) ...@@ -636,52 +630,6 @@ static void vd_manage(vout_display_t *vd)
vlc_mutex_unlock(&sys->manage_mutex); 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) static void control_port_cb(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer)
{ {
vout_display_t *vd = (vout_display_t *)port->userdata; vout_display_t *vd = (vout_display_t *)port->userdata;
......
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