Mercurial > libavcodec.hg
comparison vaapi.c @ 9292:f0732d44f655 libavcodec
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.
| author | gb |
|---|---|
| date | Tue, 31 Mar 2009 08:33:02 +0000 |
| parents | 85c7a028316d |
| children | 3f08c340020f |
comparison
equal
deleted
inserted
replaced
| 9291:6220870901f5 | 9292:f0732d44f655 |
|---|---|
| 43 static int render_picture(struct vaapi_context *vactx, VASurfaceID surface) | 43 static int render_picture(struct vaapi_context *vactx, VASurfaceID surface) |
| 44 { | 44 { |
| 45 VABufferID va_buffers[3]; | 45 VABufferID va_buffers[3]; |
| 46 unsigned int n_va_buffers = 0; | 46 unsigned int n_va_buffers = 0; |
| 47 | 47 |
| 48 if (vaCreateBuffer(vactx->display, vactx->context_id, | 48 vaUnmapBuffer(vactx->display, vactx->pic_param_buf_id); |
| 49 VAPictureParameterBufferType, | |
| 50 vactx->pic_param_size, | |
| 51 1, &vactx->pic_param, | |
| 52 &vactx->pic_param_buf_id) != VA_STATUS_SUCCESS) | |
| 53 return -1; | |
| 54 va_buffers[n_va_buffers++] = vactx->pic_param_buf_id; | 49 va_buffers[n_va_buffers++] = vactx->pic_param_buf_id; |
| 55 | 50 |
| 56 if (vactx->iq_matrix_present) { | 51 if (vactx->iq_matrix_buf_id) { |
| 57 if (vaCreateBuffer(vactx->display, vactx->context_id, | 52 vaUnmapBuffer(vactx->display, vactx->iq_matrix_buf_id); |
| 58 VAIQMatrixBufferType, | |
| 59 vactx->iq_matrix_size, | |
| 60 1, &vactx->iq_matrix, | |
| 61 &vactx->iq_matrix_buf_id) != VA_STATUS_SUCCESS) | |
| 62 return -1; | |
| 63 va_buffers[n_va_buffers++] = vactx->iq_matrix_buf_id; | 53 va_buffers[n_va_buffers++] = vactx->iq_matrix_buf_id; |
| 64 } | 54 } |
| 65 | 55 |
| 66 if (vactx->bitplane_buffer) { | 56 if (vactx->bitplane_buf_id) { |
| 67 if (vaCreateBuffer(vactx->display, vactx->context_id, | 57 vaUnmapBuffer(vactx->display, vactx->bitplane_buf_id); |
| 68 VABitPlaneBufferType, | |
| 69 vactx->bitplane_buffer_size, | |
| 70 1, vactx->bitplane_buffer, | |
| 71 &vactx->bitplane_buf_id) != VA_STATUS_SUCCESS) | |
| 72 return -1; | |
| 73 va_buffers[n_va_buffers++] = vactx->bitplane_buf_id; | 58 va_buffers[n_va_buffers++] = vactx->bitplane_buf_id; |
| 74 } | 59 } |
| 75 | 60 |
| 76 if (vaBeginPicture(vactx->display, vactx->context_id, | 61 if (vaBeginPicture(vactx->display, vactx->context_id, |
| 77 surface) != VA_STATUS_SUCCESS) | 62 surface) != VA_STATUS_SUCCESS) |
| 128 vactx->slice_data_size = 0; | 113 vactx->slice_data_size = 0; |
| 129 | 114 |
| 130 slice_buf_ids[vactx->n_slice_buf_ids++] = slice_param_buf_id; | 115 slice_buf_ids[vactx->n_slice_buf_ids++] = slice_param_buf_id; |
| 131 slice_buf_ids[vactx->n_slice_buf_ids++] = slice_data_buf_id; | 116 slice_buf_ids[vactx->n_slice_buf_ids++] = slice_data_buf_id; |
| 132 return 0; | 117 return 0; |
| 118 } | |
| 119 | |
| 120 static void *alloc_buffer(struct vaapi_context *vactx, int type, unsigned int size, uint32_t *buf_id) | |
| 121 { | |
| 122 void *data = NULL; | |
| 123 | |
| 124 *buf_id = 0; | |
| 125 if (vaCreateBuffer(vactx->display, vactx->context_id, | |
| 126 type, size, 1, NULL, buf_id) == VA_STATUS_SUCCESS) | |
| 127 vaMapBuffer(vactx->display, *buf_id, &data); | |
| 128 | |
| 129 return data; | |
| 130 } | |
| 131 | |
| 132 void *ff_vaapi_alloc_picture(struct vaapi_context *vactx, unsigned int size) | |
| 133 { | |
| 134 return alloc_buffer(vactx, VAPictureParameterBufferType, size, &vactx->pic_param_buf_id); | |
| 135 } | |
| 136 | |
| 137 void *ff_vaapi_alloc_iq_matrix(struct vaapi_context *vactx, unsigned int size) | |
| 138 { | |
| 139 return alloc_buffer(vactx, VAIQMatrixBufferType, size, &vactx->iq_matrix_buf_id); | |
| 140 } | |
| 141 | |
| 142 uint8_t *ff_vaapi_alloc_bitplane(struct vaapi_context *vactx, uint32_t size) | |
| 143 { | |
| 144 return alloc_buffer(vactx, VABitPlaneBufferType, size, &vactx->bitplane_buf_id); | |
| 133 } | 145 } |
| 134 | 146 |
| 135 VASliceParameterBufferBase *ff_vaapi_alloc_slice(struct vaapi_context *vactx, const uint8_t *buffer, uint32_t size) | 147 VASliceParameterBufferBase *ff_vaapi_alloc_slice(struct vaapi_context *vactx, const uint8_t *buffer, uint32_t size) |
| 136 { | 148 { |
| 137 uint8_t *slice_params; | 149 uint8_t *slice_params; |
| 182 done: | 194 done: |
| 183 destroy_buffers(vactx->display, &vactx->pic_param_buf_id, 1); | 195 destroy_buffers(vactx->display, &vactx->pic_param_buf_id, 1); |
| 184 destroy_buffers(vactx->display, &vactx->iq_matrix_buf_id, 1); | 196 destroy_buffers(vactx->display, &vactx->iq_matrix_buf_id, 1); |
| 185 destroy_buffers(vactx->display, &vactx->bitplane_buf_id, 1); | 197 destroy_buffers(vactx->display, &vactx->bitplane_buf_id, 1); |
| 186 destroy_buffers(vactx->display, vactx->slice_buf_ids, vactx->n_slice_buf_ids); | 198 destroy_buffers(vactx->display, vactx->slice_buf_ids, vactx->n_slice_buf_ids); |
| 187 av_freep(&vactx->bitplane_buffer); | |
| 188 av_freep(&vactx->slice_buf_ids); | 199 av_freep(&vactx->slice_buf_ids); |
| 189 av_freep(&vactx->slice_params); | 200 av_freep(&vactx->slice_params); |
| 190 vactx->n_slice_buf_ids = 0; | 201 vactx->n_slice_buf_ids = 0; |
| 191 vactx->slice_buf_ids_alloc = 0; | 202 vactx->slice_buf_ids_alloc = 0; |
| 192 vactx->slice_count = 0; | 203 vactx->slice_count = 0; |
