Commit 88f9688b authored by Julian Scheel's avatar Julian Scheel Committed by Jean-Baptiste Kempf

mmal/vout: Use fixed binding of mmal buffer to picture

Instead of dynamically allocating a mmal buffer from the mmal buffer pool use
a fixed binding, where the same mmal buffer is used for the whole pictures
lifecycle. This avoids some overhead on picture allocation and simplifies the
code. As the mmal buffer pool is allocated in exactly the same size as the vlc
picture pool there is no drawback doing it this way.
Signed-off-by: default avatarJulian Scheel <julian@jusst.de>
Signed-off-by: default avatarJean-Baptiste Kempf <jb@videolan.org>
parent e1424097
...@@ -30,43 +30,14 @@ ...@@ -30,43 +30,14 @@
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; MMAL_BUFFER_HEADER_T *buffer = pic_sys->buffer;
vlc_mutex_lock(pic_sys->mutex);
MMAL_BUFFER_HEADER_T *buffer = mmal_queue_timedwait(pic_sys->queue, 2);
if (!buffer) {
ret = VLC_EGENERIC;
goto out;
}
mmal_buffer_header_reset(buffer);
buffer->user_data = picture; buffer->user_data = picture;
picture->p[0].p_pixels = buffer->data; picture->p[0].p_pixels = buffer->data;
picture->p[1].p_pixels += (ptrdiff_t)buffer->data; picture->p[1].p_pixels += (ptrdiff_t)buffer->data;
picture->p[2].p_pixels += (ptrdiff_t)buffer->data; picture->p[2].p_pixels += (ptrdiff_t)buffer->data;
pic_sys->buffer = buffer;
pic_sys->displayed = false; pic_sys->displayed = false;
out: return VLC_SUCCESS;
vlc_mutex_unlock(pic_sys->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(pic_sys->mutex);
pic_sys->buffer = NULL;
if (buffer) {
buffer->user_data = NULL;
mmal_buffer_header_release(buffer);
}
vlc_mutex_unlock(pic_sys->mutex);
} }
...@@ -34,13 +34,9 @@ struct picture_sys_t { ...@@ -34,13 +34,9 @@ struct picture_sys_t {
vlc_object_t *owner; vlc_object_t *owner;
MMAL_BUFFER_HEADER_T *buffer; MMAL_BUFFER_HEADER_T *buffer;
MMAL_QUEUE_T *queue;
vlc_mutex_t *mutex;
bool displayed; bool displayed;
}; };
vlc_mutex_t* get_mmal_opaque_mutex(void);
int mmal_picture_lock(picture_t *picture); int mmal_picture_lock(picture_t *picture);
void mmal_picture_unlock(picture_t *picture);
#endif #endif
...@@ -351,8 +351,10 @@ static void Close(vlc_object_t *object) ...@@ -351,8 +351,10 @@ static void Close(vlc_object_t *object)
picture_pool_Release(sys->picture_pool); picture_pool_Release(sys->picture_pool);
else else
for (i = 0; i < sys->num_buffers; ++i) for (i = 0; i < sys->num_buffers; ++i)
if (sys->pictures[i]) if (sys->pictures[i]) {
mmal_buffer_header_release(sys->pictures[i]->p_sys->buffer);
picture_Release(sys->pictures[i]); picture_Release(sys->pictures[i]);
}
vlc_mutex_destroy(&sys->buffer_mutex); vlc_mutex_destroy(&sys->buffer_mutex);
vlc_cond_destroy(&sys->buffer_cond); vlc_cond_destroy(&sys->buffer_cond);
...@@ -497,8 +499,7 @@ static picture_pool_t *vd_pool(vout_display_t *vd, unsigned count) ...@@ -497,8 +499,7 @@ static picture_pool_t *vd_pool(vout_display_t *vd, unsigned count)
for (i = 0; i < sys->num_buffers; ++i) { for (i = 0; i < sys->num_buffers; ++i) {
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->buffer = mmal_queue_get(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]) {
...@@ -515,7 +516,6 @@ static picture_pool_t *vd_pool(vout_display_t *vd, unsigned count) ...@@ -515,7 +516,6 @@ static picture_pool_t *vd_pool(vout_display_t *vd, unsigned count)
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 = mmal_picture_lock; picture_pool_cfg.lock = mmal_picture_lock;
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) {
......
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