[FFmpeg-cvslog] r18256 - in trunk/libavcodec: vaapi.c vaapi.h vaapi_internal.h vaapi_mpeg2.c

gb subversion
Tue Mar 31 10:33:03 CEST 2009


Author: gb
Date: Tue Mar 31 10:33:02 2009
New Revision: 18256

Log:
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.

Modified:
   trunk/libavcodec/vaapi.c
   trunk/libavcodec/vaapi.h
   trunk/libavcodec/vaapi_internal.h
   trunk/libavcodec/vaapi_mpeg2.c

Modified: trunk/libavcodec/vaapi.c
==============================================================================
--- trunk/libavcodec/vaapi.c	Tue Mar 31 09:37:55 2009	(r18255)
+++ trunk/libavcodec/vaapi.c	Tue Mar 31 10:33:02 2009	(r18256)
@@ -45,31 +45,16 @@ static int render_picture(struct vaapi_c
     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_co
     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;

Modified: trunk/libavcodec/vaapi.h
==============================================================================
--- trunk/libavcodec/vaapi.h	Tue Mar 31 09:37:55 2009	(r18255)
+++ trunk/libavcodec/vaapi.h	Tue Mar 31 10:33:02 2009	(r18256)
@@ -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
@@ -116,71 +116,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
      *
      * - encoding: unused

Modified: trunk/libavcodec/vaapi_internal.h
==============================================================================
--- trunk/libavcodec/vaapi_internal.h	Tue Mar 31 09:37:55 2009	(r18255)
+++ trunk/libavcodec/vaapi_internal.h	Tue Mar 31 10:33:02 2009	(r18256)
@@ -44,6 +44,15 @@ static inline VASurfaceID ff_vaapi_get_s
 /** 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.
  *

Modified: trunk/libavcodec/vaapi_mpeg2.c
==============================================================================
--- trunk/libavcodec/vaapi_mpeg2.c	Tue Mar 31 09:37:55 2009	(r18255)
+++ trunk/libavcodec/vaapi_mpeg2.c	Tue Mar 31 10:33:02 2009	(r18256)
@@ -46,12 +46,12 @@ static int vaapi_mpeg2_start_frame(AVCod
 
     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(AVCod
     }
 
     /* 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]];



More information about the ffmpeg-cvslog mailing list