down to ~60 bytes vs. a few KBs before, and gets rid of explicit VA data types. Originally committed as revision 18256 to svn://svn.ffmpeg.org/ffmpeg/trunktags/v0.6
@@ -45,31 +45,16 @@ static int render_picture(struct vaapi_context *vactx, VASurfaceID surface) | |||
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 @@ static int commit_slices(struct vaapi_context *vactx) | |||
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 @@ done: | |||
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; | |||
@@ -73,7 +73,7 @@ struct vaapi_context { | |||
* - encoding: unused | |||
* - decoding: Set by libavcodec | |||
*/ | |||
VABufferID pic_param_buf_id; | |||
uint32_t pic_param_buf_id; | |||
/** | |||
* VAIQMatrixBuffer ID | |||
@@ -81,7 +81,7 @@ struct vaapi_context { | |||
* - 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 @@ struct vaapi_context { | |||
* - encoding: unused | |||
* - decoding: Set by libavcodec | |||
*/ | |||
VABufferID bitplane_buf_id; | |||
uint32_t bitplane_buf_id; | |||
/** | |||
* Slice parameter/data buffer IDs | |||
@@ -97,7 +97,7 @@ struct vaapi_context { | |||
* - 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 | |||
@@ -115,71 +115,6 @@ struct vaapi_context { | |||
*/ | |||
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 | |||
* | |||
@@ -44,6 +44,15 @@ static inline VASurfaceID ff_vaapi_get_surface(Picture *pic) | |||
/** 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. | |||
* | |||
@@ -46,12 +46,12 @@ static int vaapi_mpeg2_start_frame(AVCodecContext *avctx, av_unused const uint8_ | |||
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 @@ static int vaapi_mpeg2_start_frame(AVCodecContext *avctx, av_unused const uint8_ | |||
} | |||
/* 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]]; | |||