[Libva] encode surfaces created from prime fd (backed by OpenGL 2D texture)
Yuan, Shengquan
shengquan.yuan at intel.com
Wed May 25 08:46:33 UTC 2016
For vaCreateContext, I think render_targets/num_render_targets are optional (it depends on driver implementation), and the surface of vaBeginPicture can a brand-new surface
VAStatus vaCreateContext (
VADisplay dpy,
VAConfigID config_id,
int picture_width,
int picture_height,
int flag,
VASurfaceID *render_targets,
int num_render_targets,
VAContextID *context /* out */
);
DMA buffer can be imported through VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME, e.g.
VASurfaceAttribExternalBuffers buf;
VASurfaceAttribType type,
VASurfaceAttrib attrib_list[2]
unsigned long prime_fd; /* an input variable, it is the imported prime fd from other process */
int stride = frame_width_aligned, height_aligned = frame_height_aligned;
if (stride == 0)
stride = frame_width_mbaligned;
if (height_aligned == 0)
height_aligned = frame_height_mbaligned;
buf.pixel_format = VA_FOURCC_NV12;
buf.width = frame_width_mbaligned;
buf.height = frame_height_mbaligned;
buf.data_size = stride * height_aligned * 1.5;
buf.num_buffers = 1; /* import only 1 buffer */
buf.num_planes = 3;
buf.pitches[0] = stride;
buf.pitches[1] = stride;
buf.pitches[2] = stride;
buf.pitches[3] = 0;
buf.offsets[0] = 0;
buf.offsets[1] = stride * height_aligned;
buf.offsets[2] = buf.offsets[1];
buf.offsets[3] = 0;
buf.buffers = &prime_fd;
buf.flags = 0;
buf.private_data = NULL;
attrib_list[0].type = (VASurfaceAttribType)VASurfaceAttribMemoryType;
attrib_list[0].flags = VA_SURFACE_ATTRIB_SETTABLE;
attrib_list[0].value.type = VAGenericValueTypeInteger;
attrib_list[0].value.value.i = VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME
attrib_list[1].type = (VASurfaceAttribType)VASurfaceAttribExternalBufferDescriptor;
attrib_list[1].flags = VA_SURFACE_ATTRIB_SETTABLE;
attrib_list[1].value.type = VAGenericValueTypePointer;
attrib_list[1].value.value.p = (void *)buf;
vaCreateSurfaces(
va_dpy,
VA_RT_FORMAT_YUV420,
frame_width_mbaligned, frame_height_mbaligned,
&surface_id, 1,
&attrib_list, 2);
From: Libva [mailto:libva-bounces at lists.freedesktop.org] On Behalf Of Anon
Sent: Wednesday, May 25, 2016 2:23 PM
To: libva at lists.freedesktop.org
Subject: [Libva] encode surfaces created from prime fd (backed by OpenGL 2D texture)
Hi All,
I want to implement the following use case on Intel Haswell CPU with HD graphics:
offscreen OpenGL rendering to OpenGL 2D texture -> use EGL_MESA_image_dma_buf_export to export the texture as prime fd -> vaCreateSurfaces from the prime fd -> use vaapi to hw acclerate h264 encoding
Is this supported by the latest va-api and libva-intel-driver release (i.e., 1.7.0)? If so, is there any example I can start with?
I did read the sample application h264encode.c and thought it might be a good starting point. However, the first major issue I encountered is when creating context through vaCreateContext, a number of pre-allocated va surfaces are required and thus statically associated with the new va context. However, with prime fd, the fd will change so a new va surface is created with every new prime fd. I don't see any API can be used to dynamically add/remove va surfaces after the context is created. Can you please give me some suggestions?
Best,
Kristine
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/libva/attachments/20160525/62df4189/attachment-0001.html>
More information about the Libva
mailing list