Commit a2e4a085 authored by Rafaël Carré's avatar Rafaël Carré

xcb/xvideo.c: makes Pool() slightly more readable

split allocation into a separate function to remove one level of indentation
split some overly long statements
factorize some bits

green line is still present at bottom of output
parent 86c01d64
...@@ -600,46 +600,43 @@ static void Close (vlc_object_t *obj) ...@@ -600,46 +600,43 @@ static void Close (vlc_object_t *obj)
free (p_sys); free (p_sys);
} }
/** static void PoolAlloc (vout_display_t *vd, unsigned requested_count)
* Return a direct buffer
*/
static picture_pool_t *Pool (vout_display_t *vd, unsigned requested_count)
{ {
vout_display_sys_t *p_sys = vd->sys; vout_display_sys_t *p_sys = vd->sys;
if (!p_sys->pool)
{
memset (p_sys->resource, 0, sizeof(p_sys->resource)); memset (p_sys->resource, 0, sizeof(p_sys->resource));
const uint32_t *pitches = const uint32_t *pitches= xcb_xv_query_image_attributes_pitches (p_sys->att);
xcb_xv_query_image_attributes_pitches (p_sys->att); const uint32_t *offsets= xcb_xv_query_image_attributes_offsets (p_sys->att);
const uint32_t *offsets = const unsigned num_planes= __MIN(p_sys->att->num_planes, PICTURE_PLANE_MAX);
xcb_xv_query_image_attributes_offsets (p_sys->att);
p_sys->data_size = p_sys->att->data_size; p_sys->data_size = p_sys->att->data_size;
unsigned count;
picture_t *pic_array[MAX_PICTURES]; picture_t *pic_array[MAX_PICTURES];
requested_count = __MIN(requested_count, MAX_PICTURES);
unsigned count;
for (count = 0; count < requested_count; count++) for (count = 0; count < requested_count; count++)
{ {
if (count >= MAX_PICTURES)
break;
picture_resource_t *res = &p_sys->resource[count]; picture_resource_t *res = &p_sys->resource[count];
for (int i = 0; i < __MIN (p_sys->att->num_planes, PICTURE_PLANE_MAX); i++) for (unsigned i = 0; i < num_planes; i++)
{ {
res->p[i].i_lines = uint32_t data_size;
((i + 1 < p_sys->att->num_planes ? offsets[i+1] : data_size = (i < num_planes - 1) ? offsets[i+1] : p_sys->data_size;
p_sys->data_size) - offsets[i]) / pitches[i];
res->p[i].i_lines = (data_size - offsets[i]) / pitches[i];
res->p[i].i_pitch = pitches[i]; res->p[i].i_pitch = pitches[i];
} }
if (PictureResourceAlloc (vd, res, p_sys->att->data_size, if (PictureResourceAlloc (vd, res, p_sys->att->data_size,
p_sys->conn, p_sys->shm)) p_sys->conn, p_sys->shm))
break; break;
/* Allocate further planes as specified by XVideo */ /* Allocate further planes as specified by XVideo */
/* We assume that offsets[0] is zero */ /* We assume that offsets[0] is zero */
for (int i = 1; i < __MIN (p_sys->att->num_planes, PICTURE_PLANE_MAX); i++) for (unsigned i = 1; i < num_planes; i++)
res->p[i].p_pixels = res->p[0].p_pixels + offsets[i]; res->p[i].p_pixels = res->p[0].p_pixels + offsets[i];
if (p_sys->swap_uv) if (p_sys->swap_uv)
{ /* YVU: swap U and V planes */ { /* YVU: swap U and V planes */
uint8_t *buf = res->p[2].p_pixels; uint8_t *buf = res->p[2].p_pixels;
...@@ -657,12 +654,22 @@ static picture_pool_t *Pool (vout_display_t *vd, unsigned requested_count) ...@@ -657,12 +654,22 @@ static picture_pool_t *Pool (vout_display_t *vd, unsigned requested_count)
} }
if (count == 0) if (count == 0)
return NULL; return;
p_sys->pool = picture_pool_New (count, pic_array); p_sys->pool = picture_pool_New (count, pic_array);
/* TODO release picture resources if NULL */ /* TODO release picture resources if NULL */
xcb_flush (p_sys->conn); xcb_flush (p_sys->conn);
} }
/**
* Return a direct buffer
*/
static picture_pool_t *Pool (vout_display_t *vd, unsigned requested_count)
{
vout_display_sys_t *p_sys = vd->sys;
if (!p_sys->pool)
PoolAlloc (vd, requested_count);
return p_sys->pool; return p_sys->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