# HG changeset patch # User gb # Date 1238488382 0 # Node ID f0732d44f655c17fd0ffb6faaf7c28366f07c16b # Parent 6220870901f5652746324fadbbb13e9a8502aed8 Improve VA API buffers allocation logic. This also reduces struct vaapi_context down to ~60 bytes vs. a few KBs before, and gets rid of explicit VA data types. diff -r 6220870901f5 -r f0732d44f655 vaapi.c --- a/vaapi.c Tue Mar 31 07:37:55 2009 +0000 +++ b/vaapi.c Tue Mar 31 08:33:02 2009 +0000 @@ -45,31 +45,16 @@ VABufferID va_buffers[3]; unsigned int n_va_buffers = 0; - if (vaCreateBuffer(vactx->display, vactx->context_id, - VAPictureParameterBufferType, - vactx->pic_param_size, - 1, &vactx->pic_param, - &vactx->pic_param_buf_id) != VA_STATUS_SUCCESS) - return -1; + vaUnmapBuffer(vactx->display, vactx->pic_param_buf_id); va_buffers[n_va_buffers++] = vactx->pic_param_buf_id; - if (vactx->iq_matrix_present) { - if (vaCreateBuffer(vactx->display, vactx->context_id, - VAIQMatrixBufferType, - vactx->iq_matrix_size, - 1, &vactx->iq_matrix, - &vactx->iq_matrix_buf_id) != VA_STATUS_SUCCESS) - return -1; + if (vactx->iq_matrix_buf_id) { + vaUnmapBuffer(vactx->display, vactx->iq_matrix_buf_id); va_buffers[n_va_buffers++] = vactx->iq_matrix_buf_id; } - if (vactx->bitplane_buffer) { - if (vaCreateBuffer(vactx->display, vactx->context_id, - VABitPlaneBufferType, - vactx->bitplane_buffer_size, - 1, vactx->bitplane_buffer, - &vactx->bitplane_buf_id) != VA_STATUS_SUCCESS) - return -1; + if (vactx->bitplane_buf_id) { + vaUnmapBuffer(vactx->display, vactx->bitplane_buf_id); va_buffers[n_va_buffers++] = vactx->bitplane_buf_id; } @@ -132,6 +117,33 @@ return 0; } +static void *alloc_buffer(struct vaapi_context *vactx, int type, unsigned int size, uint32_t *buf_id) +{ + void *data = NULL; + + *buf_id = 0; + if (vaCreateBuffer(vactx->display, vactx->context_id, + type, size, 1, NULL, buf_id) == VA_STATUS_SUCCESS) + vaMapBuffer(vactx->display, *buf_id, &data); + + return data; +} + +void *ff_vaapi_alloc_picture(struct vaapi_context *vactx, unsigned int size) +{ + return alloc_buffer(vactx, VAPictureParameterBufferType, size, &vactx->pic_param_buf_id); +} + +void *ff_vaapi_alloc_iq_matrix(struct vaapi_context *vactx, unsigned int size) +{ + return alloc_buffer(vactx, VAIQMatrixBufferType, size, &vactx->iq_matrix_buf_id); +} + +uint8_t *ff_vaapi_alloc_bitplane(struct vaapi_context *vactx, uint32_t size) +{ + return alloc_buffer(vactx, VABitPlaneBufferType, size, &vactx->bitplane_buf_id); +} + VASliceParameterBufferBase *ff_vaapi_alloc_slice(struct vaapi_context *vactx, const uint8_t *buffer, uint32_t size) { uint8_t *slice_params; @@ -184,7 +196,6 @@ destroy_buffers(vactx->display, &vactx->iq_matrix_buf_id, 1); destroy_buffers(vactx->display, &vactx->bitplane_buf_id, 1); destroy_buffers(vactx->display, vactx->slice_buf_ids, vactx->n_slice_buf_ids); - av_freep(&vactx->bitplane_buffer); av_freep(&vactx->slice_buf_ids); av_freep(&vactx->slice_params); vactx->n_slice_buf_ids = 0; diff -r 6220870901f5 -r f0732d44f655 vaapi.h --- a/vaapi.h Tue Mar 31 07:37:55 2009 +0000 +++ b/vaapi.h Tue Mar 31 08:33:02 2009 +0000 @@ -73,7 +73,7 @@ * - encoding: unused * - decoding: Set by libavcodec */ - VABufferID pic_param_buf_id; + uint32_t pic_param_buf_id; /** * VAIQMatrixBuffer ID @@ -81,7 +81,7 @@ * - encoding: unused * - decoding: Set by libavcodec */ - VABufferID iq_matrix_buf_id; + uint32_t iq_matrix_buf_id; /** * VABitPlaneBuffer ID (for VC-1 decoding) @@ -89,7 +89,7 @@ * - encoding: unused * - decoding: Set by libavcodec */ - VABufferID bitplane_buf_id; + uint32_t bitplane_buf_id; /** * Slice parameter/data buffer IDs @@ -97,7 +97,7 @@ * - encoding: unused * - decoding: Set by libavcodec */ - VABufferID *slice_buf_ids; + uint32_t *slice_buf_ids; /** * Number of effective slice buffer IDs to send to the HW @@ -116,71 +116,6 @@ unsigned int slice_buf_ids_alloc; /** - * Picture parameter buffer - * - * - encoding: unused - * - decoding: Set by libavcodec - */ - union { - VAPictureParameterBufferMPEG2 mpeg2; - VAPictureParameterBufferMPEG4 mpeg4; - VAPictureParameterBufferH264 h264; - VAPictureParameterBufferVC1 vc1; - } pic_param; - - /** - * Size of a VAPictureParameterBuffer element - * - * - encoding: unused - * - decoding: Set by libavcodec - */ - unsigned int pic_param_size; - - /** - * Inverse quantization matrix buffer - * - * - encoding: unused - * - decoding: Set by libavcodec - */ - union { - VAIQMatrixBufferMPEG2 mpeg2; - VAIQMatrixBufferMPEG4 mpeg4; - VAIQMatrixBufferH264 h264; - } iq_matrix; - - /** - * Size of a VAIQMatrixBuffer element - * - * - encoding: unused - * - decoding: Set by libavcodec - */ - unsigned int iq_matrix_size; - - /** - * Flag: is quantization matrix present? - * - * - encoding: unused - * - decoding: Set by libavcodec - */ - uint8_t iq_matrix_present; - - /** - * VC-1 bitplane buffer - * - * - encoding: unused - * - decoding: Set by libavcodec - */ - uint8_t *bitplane_buffer; - - /** - * Size of VC-1 bitplane buffer - * - * - encoding: unused - * - decoding: Set by libavcodec - */ - unsigned int bitplane_buffer_size; - - /** * Pointer to VASliceParameterBuffers * * - encoding: unused diff -r 6220870901f5 -r f0732d44f655 vaapi_internal.h --- a/vaapi_internal.h Tue Mar 31 07:37:55 2009 +0000 +++ b/vaapi_internal.h Tue Mar 31 08:33:02 2009 +0000 @@ -44,6 +44,15 @@ /** Common AVHWAccel.end_frame() implementation */ int ff_vaapi_common_end_frame(MpegEncContext *s); +/** Allocate a new picture parameter buffer */ +void *ff_vaapi_alloc_picture(struct vaapi_context *vactx, unsigned int size); + +/** Allocate a new IQ matrix buffer */ +void *ff_vaapi_alloc_iq_matrix(struct vaapi_context *vactx, unsigned int size); + +/** Allocate a new bit-plane buffer */ +uint8_t *ff_vaapi_alloc_bitplane(struct vaapi_context *vactx, uint32_t size); + /** * Allocate a new slice descriptor for the input slice. * diff -r 6220870901f5 -r f0732d44f655 vaapi_mpeg2.c --- a/vaapi_mpeg2.c Tue Mar 31 07:37:55 2009 +0000 +++ b/vaapi_mpeg2.c Tue Mar 31 08:33:02 2009 +0000 @@ -46,12 +46,12 @@ dprintf(avctx, "vaapi_mpeg2_start_frame()\n"); - vactx->pic_param_size = sizeof(VAPictureParameterBufferMPEG2); - vactx->iq_matrix_size = sizeof(VAIQMatrixBufferMPEG2); vactx->slice_param_size = sizeof(VASliceParameterBufferMPEG2); /* Fill in VAPictureParameterBufferMPEG2 */ - pic_param = &vactx->pic_param.mpeg2; + pic_param = ff_vaapi_alloc_picture(vactx, sizeof(VAPictureParameterBufferMPEG2)); + if (!pic_param) + return -1; pic_param->horizontal_size = s->width; pic_param->vertical_size = s->height; pic_param->forward_reference_picture = 0xffffffff; @@ -81,12 +81,13 @@ } /* Fill in VAIQMatrixBufferMPEG2 */ - iq_matrix = &vactx->iq_matrix.mpeg2; + iq_matrix = ff_vaapi_alloc_iq_matrix(vactx, sizeof(VAIQMatrixBufferMPEG2)); + if (!iq_matrix) + return -1; iq_matrix->load_intra_quantiser_matrix = 1; iq_matrix->load_non_intra_quantiser_matrix = 1; iq_matrix->load_chroma_intra_quantiser_matrix = 1; iq_matrix->load_chroma_non_intra_quantiser_matrix = 1; - vactx->iq_matrix_present = 1; for (i = 0; i < 64; i++) { int n = s->dsp.idct_permutation[ff_zigzag_direct[i]];