st/va: added internal storage for VAImage and BGRA format

When calling vaCreateImage() an internal copy of VAImage is maintained
since the allocation of "image" may not be guaranteed to live long enough.

Signed-off-by: Michael Varga <Michael.Varga@amd.com>
This commit is contained in:
Michael Varga 2014-11-03 10:35:28 -06:00 committed by Leo Liu
parent 7b4f233c1f
commit 05e225b558
2 changed files with 48 additions and 26 deletions

View file

@ -44,6 +44,7 @@ static const VAImageFormat formats[VL_VA_MAX_IMAGE_FORMATS] =
{VA_FOURCC('Y','V','1','2')}, {VA_FOURCC('Y','V','1','2')},
{VA_FOURCC('Y','U','Y','V')}, {VA_FOURCC('Y','U','Y','V')},
{VA_FOURCC('U','Y','V','Y')}, {VA_FOURCC('U','Y','V','Y')},
{VA_FOURCC('B','G','R','A')}
}; };
static void static void
@ -93,7 +94,9 @@ vlVaQueryImageFormats(VADriverContextP ctx, VAImageFormat *format_list, int *num
VAStatus VAStatus
vlVaCreateImage(VADriverContextP ctx, VAImageFormat *format, int width, int height, VAImage *image) vlVaCreateImage(VADriverContextP ctx, VAImageFormat *format, int width, int height, VAImage *image)
{ {
VAStatus status;
vlVaDriver *drv; vlVaDriver *drv;
VAImage *img;
int w, h; int w, h;
if (!ctx) if (!ctx)
@ -104,50 +107,66 @@ vlVaCreateImage(VADriverContextP ctx, VAImageFormat *format, int width, int heig
drv = VL_VA_DRIVER(ctx); drv = VL_VA_DRIVER(ctx);
image->image_id = handle_table_add(drv->htab, image); img = CALLOC(1, sizeof(VAImage));
image->format = *format; if (!img)
image->width = width; return VA_STATUS_ERROR_ALLOCATION_FAILED;
image->height = height; img->image_id = handle_table_add(drv->htab, img);
img->format = *format;
img->width = width;
img->height = height;
w = align(width, 2); w = align(width, 2);
h = align(width, 2); h = align(width, 2);
switch (format->fourcc) { switch (format->fourcc) {
case VA_FOURCC('N','V','1','2'): case VA_FOURCC('N','V','1','2'):
image->num_planes = 2; img->num_planes = 2;
image->pitches[0] = w; img->pitches[0] = w;
image->offsets[0] = 0; img->offsets[0] = 0;
image->pitches[1] = w; img->pitches[1] = w;
image->offsets[1] = w * h; img->offsets[1] = w * h;
image->data_size = w * h * 3 / 2; img->data_size = w * h * 3 / 2;
break; break;
case VA_FOURCC('I','4','2','0'): case VA_FOURCC('I','4','2','0'):
case VA_FOURCC('Y','V','1','2'): case VA_FOURCC('Y','V','1','2'):
image->num_planes = 3; img->num_planes = 3;
image->pitches[0] = w; img->pitches[0] = w;
image->offsets[0] = 0; img->offsets[0] = 0;
image->pitches[1] = w / 2; img->pitches[1] = w / 2;
image->offsets[1] = w * h; img->offsets[1] = w * h;
image->pitches[2] = w / 2; img->pitches[2] = w / 2;
image->offsets[2] = w * h * 5 / 4; img->offsets[2] = w * h * 5 / 4;
image->data_size = w * h * 3 / 2; img->data_size = w * h * 3 / 2;
break; break;
case VA_FOURCC('U','Y','V','Y'): case VA_FOURCC('U','Y','V','Y'):
case VA_FOURCC('Y','U','Y','V'): case VA_FOURCC('Y','U','Y','V'):
image->num_planes = 1; img->num_planes = 1;
image->pitches[0] = w * 2; img->pitches[0] = w * 2;
image->offsets[0] = 0; img->offsets[0] = 0;
image->data_size = w * h * 2; img->data_size = w * h * 2;
break;
case VA_FOURCC('B','G','R','A'):
img->num_planes = 1;
img->pitches[0] = w * 4;
img->offsets[0] = 0;
img->data_size = w * h * 4;
break; break;
default: default:
return VA_STATUS_ERROR_INVALID_IMAGE_FORMAT; return VA_STATUS_ERROR_INVALID_IMAGE_FORMAT;
} }
return vlVaCreateBuffer(ctx, 0, VAImageBufferType, status = vlVaCreateBuffer(ctx, 0, VAImageBufferType,
align(image->data_size, 16), align(img->data_size, 16),
1, NULL, &image->buf); 1, NULL, &img->buf);
if (status != VA_STATUS_SUCCESS)
return status;
*image = *img;
return status;
} }
VAStatus VAStatus
@ -172,6 +191,7 @@ vlVaDestroyImage(VADriverContextP ctx, VAImageID image)
return VA_STATUS_ERROR_INVALID_IMAGE; return VA_STATUS_ERROR_INVALID_IMAGE;
handle_table_remove(VL_VA_DRIVER(ctx)->htab, image); handle_table_remove(VL_VA_DRIVER(ctx)->htab, image);
FREE(vaimage);
return vlVaDestroyBuffer(ctx, vaimage->buf); return vlVaDestroyBuffer(ctx, vaimage->buf);
} }

View file

@ -44,7 +44,7 @@
#define VL_VA_DRIVER(ctx) ((vlVaDriver *)ctx->pDriverData) #define VL_VA_DRIVER(ctx) ((vlVaDriver *)ctx->pDriverData)
#define VL_VA_PSCREEN(ctx) (VL_VA_DRIVER(ctx)->vscreen->pscreen) #define VL_VA_PSCREEN(ctx) (VL_VA_DRIVER(ctx)->vscreen->pscreen)
#define VL_VA_MAX_IMAGE_FORMATS 5 #define VL_VA_MAX_IMAGE_FORMATS 6
static inline enum pipe_video_chroma_format static inline enum pipe_video_chroma_format
ChromaToPipe(int format) ChromaToPipe(int format)
@ -76,6 +76,8 @@ YCbCrToPipe(unsigned format)
return PIPE_FORMAT_YUYV; return PIPE_FORMAT_YUYV;
case VA_FOURCC('U','Y','V','Y'): case VA_FOURCC('U','Y','V','Y'):
return PIPE_FORMAT_UYVY; return PIPE_FORMAT_UYVY;
case VA_FOURCC('B','G','R','A'):
return PIPE_FORMAT_B8G8R8A8_UNORM;
default: default:
assert(0); assert(0);
return PIPE_FORMAT_NONE; return PIPE_FORMAT_NONE;