decoder: optimize slice data buffers initialization.

VA drivers may have a faster means to transfer user buffers to GPU
buffers than using memcpy(). In particular, on Intel Gen graphics, we
can use pwrite(). This provides for faster upload of bitstream and can
help higher bitrates.

vaapi_create_buffer() helper function was also updated to allow for
un-mapped buffers and pre-initialized data for buffers.
This commit is contained in:
Gwenole Beauchesne 2012-01-30 10:15:32 +01:00
parent 5cd0242bbb
commit a79c7f9fa6
4 changed files with 59 additions and 52 deletions

View file

@ -150,16 +150,13 @@ gst_vaapi_iq_matrix_create(
const GstVaapiCodecObjectConstructorArgs *args
)
{
iq_matrix->param = vaapi_create_buffer(
GET_VA_DISPLAY(iq_matrix),
GET_VA_CONTEXT(iq_matrix),
VAIQMatrixBufferType,
args->param_size,
&iq_matrix->param_id
);
if (!iq_matrix->param)
return FALSE;
return TRUE;
return vaapi_create_buffer(GET_VA_DISPLAY(iq_matrix),
GET_VA_CONTEXT(iq_matrix),
VAIQMatrixBufferType,
args->param_size,
args->param,
&iq_matrix->param_id,
&iq_matrix->param);
}
static void
@ -212,16 +209,13 @@ gst_vaapi_bitplane_create(
const GstVaapiCodecObjectConstructorArgs *args
)
{
bitplane->data = vaapi_create_buffer(
GET_VA_DISPLAY(bitplane),
GET_VA_CONTEXT(bitplane),
VABitPlaneBufferType,
args->param_size,
&bitplane->data_id
);
if (!bitplane->data)
return FALSE;
return TRUE;
return vaapi_create_buffer(GET_VA_DISPLAY(bitplane),
GET_VA_CONTEXT(bitplane),
VABitPlaneBufferType,
args->param_size,
args->param,
&bitplane->data_id,
&bitplane->data);
}
static void

View file

@ -89,19 +89,23 @@ gst_vaapi_picture_create(
const GstVaapiCodecObjectConstructorArgs *args
)
{
gboolean success;
picture->surface = gst_vaapi_context_get_surface(GET_CONTEXT(picture));
if (!picture->surface)
return FALSE;
picture->surface_id = gst_vaapi_surface_get_id(picture->surface);
picture->param = vaapi_create_buffer(
success = vaapi_create_buffer(
GET_VA_DISPLAY(picture),
GET_VA_CONTEXT(picture),
VAPictureParameterBufferType,
args->param_size,
&picture->param_id
args->param,
&picture->param_id,
&picture->param
);
if (!picture->param)
if (!success)
return FALSE;
picture->slices = g_ptr_array_new();
@ -274,28 +278,30 @@ gst_vaapi_slice_create(
)
{
VASliceParameterBufferBase *slice_param;
guint8 *data;
gboolean success;
data = vaapi_create_buffer(
success = vaapi_create_buffer(
GET_VA_DISPLAY(slice),
GET_VA_CONTEXT(slice),
VASliceDataBufferType,
args->data_size,
&slice->data_id
args->data,
&slice->data_id,
NULL
);
if (!data)
if (!success)
return FALSE;
memcpy(data, args->data, args->data_size);
vaapi_unmap_buffer(GET_VA_DISPLAY(slice), slice->data_id, NULL);
slice->param = vaapi_create_buffer(
success = vaapi_create_buffer(
GET_VA_DISPLAY(slice),
GET_VA_CONTEXT(slice),
VASliceParameterBufferType,
args->param_size,
&slice->param_id
args->param,
&slice->param_id,
&slice->param
);
if (!slice->param)
if (!success)
return FALSE;
slice_param = slice->param;

View file

@ -76,33 +76,38 @@ vaapi_unmap_buffer(VADisplay dpy, VABufferID buf_id, void **pbuf)
}
/* Creates and maps VA buffer */
void *
gboolean
vaapi_create_buffer(
VADisplay dpy,
VAContextID ctx,
int type,
unsigned int size,
VABufferID *buf_id_ptr
VADisplay dpy,
VAContextID ctx,
int type,
unsigned int size,
gconstpointer buf,
VABufferID *buf_id_ptr,
gpointer *mapped_data
)
{
VABufferID buf_id;
VAStatus status;
void *data;
gpointer data = (gpointer)buf;
status = vaCreateBuffer(dpy, ctx, type, size, 1, NULL, &buf_id);
status = vaCreateBuffer(dpy, ctx, type, size, 1, data, &buf_id);
if (!vaapi_check_status(status, "vaCreateBuffer()"))
return NULL;
return FALSE;
data = vaapi_map_buffer(dpy, buf_id);
if (!data)
goto error;
if (mapped_data) {
data = vaapi_map_buffer(dpy, buf_id);
if (!data)
goto error;
*mapped_data = data;
}
*buf_id_ptr = buf_id;
return data;
return TRUE;
error:
vaapi_destroy_buffer(dpy, &buf_id);
return NULL;
return FALSE;
}
/* Destroy VA buffer */

View file

@ -48,13 +48,15 @@ vaapi_unmap_buffer(VADisplay dpy, VABufferID buf_id, void **pbuf)
attribute_hidden;
/** Creates and maps VA buffer */
void *
gboolean
vaapi_create_buffer(
VADisplay dpy,
VAContextID ctx,
int type,
unsigned int size,
VABufferID *buf_id
VADisplay dpy,
VAContextID ctx,
int type,
unsigned int size,
gconstpointer data,
VABufferID *buf_id,
gpointer *mapped_data
) attribute_hidden;
/** Destroy VA buffer */