ImageRawPtr VaapiImageRaw::create(const DisplayPtr& display, const ImagePtr& image, VideoDataMemoryType memoryType) { ImageRawPtr raw; RealeaseCallback release; uintptr_t handle; VAStatus status; VAImagePtr& vaImage = image->m_image; if (memoryType == VIDEO_DATA_MEMORY_TYPE_RAW_POINTER || memoryType == VIDEO_DATA_MEMORY_TYPE_RAW_COPY) { void* data; status = vaMapBuffer(display->getID(), vaImage->buf, &data); release = vaUnmapBuffer; handle = (uintptr_t)data; } else { VABufferInfo bufferInfo; if (memoryType == VIDEO_DATA_MEMORY_TYPE_DRM_NAME) bufferInfo.mem_type = VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM; else if (memoryType == VIDEO_DATA_MEMORY_TYPE_DMA_BUF) bufferInfo.mem_type = VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME; else ASSERT(0); status = vaAcquireBufferHandle(display->getID(), vaImage->buf, &bufferInfo); release = vaReleaseBufferHandle; handle = (uintptr_t)bufferInfo.handle; } if (!checkVaapiStatus(status, "VaapiImageRaw::create()")) return raw; raw.reset(new VaapiImageRaw(display, image, memoryType, handle, release)); return raw; }
ImagePtr VaapiImage::create(const DisplayPtr& display, uint32_t format, uint32_t width, uint32_t height) { ImagePtr image; VAStatus status; if (!display || !width || !height) return image; DEBUG_FOURCC("create image with fourcc: ", format); const VAImageFormat *vaFormat = display->getVaFormat(format); if (!vaFormat) { ERROR("Create image failed, not supported fourcc"); return image; } VAImagePtr vaImage(new VAImage); status = vaCreateImage(display->getID(), vaFormat, width, height, vaImage.get()); if (status != VA_STATUS_SUCCESS || vaImage->format.fourcc != vaFormat->fourcc) { ERROR("fourcc mismatch wated = 0x%x, got = 0x%x", vaFormat->fourcc, vaImage->format.fourcc); return image; } image.reset(new VaapiImage(display, vaImage)); return image; }
ImagePtr VaapiImage::derive(const SurfacePtr& surface) { ImagePtr image; if (!surface) return image; DisplayPtr display = surface->getDisplay(); VAImagePtr vaImage(new VAImage); VAStatus status = vaDeriveImage(display->getID(), surface->getID(), vaImage.get()); if (!checkVaapiStatus(status, "vaDeriveImage()")) { return image; } image.reset(new VaapiImage(display, surface, vaImage)); return image; }
VaapiDecSurfacePool::VaapiDecSurfacePool(const DisplayPtr& display, std::vector<SurfacePtr> surfaces): m_cond(m_lock), m_flushing(false) { size_t size = surfaces.size(); m_surfaces.swap(surfaces); m_renderBuffers.resize(size); for (size_t i = 0; i < size; ++i) { const SurfacePtr& s = m_surfaces[i]; VASurfaceID id = m_surfaces[i]->getID(); m_renderBuffers[i].display = display->getID(); m_renderBuffers[i].surface = id; m_renderBuffers[i].timeStamp = 0; m_renderMap[id] = &m_renderBuffers[i]; m_surfaceMap[id] = s.get(); m_freed.push_back(id); } }
SurfacePtr VaapiSurface::create(const DisplayPtr& display, VaapiChromaType chromaType, uint32_t width, uint32_t height, void *surfAttribArray, uint32_t surfAttribNum) { VAStatus status; uint32_t format, i; VASurfaceAttrib *surfAttribs = (VASurfaceAttrib *) surfAttribArray; SurfacePtr surface; VASurfaceID id; assert((surfAttribs && surfAttribNum) || (!surfAttribs && !surfAttribNum)); format = vaapiChromaToVaChroma(chromaType); uint32_t externalBufHandle = 0; status = vaCreateSurfaces(display->getID(), format, width, height, &id, 1, surfAttribs, surfAttribNum); if (!checkVaapiStatus(status, "vaCreateSurfacesWithAttribute()")) return surface; for (int i = 0; i < surfAttribNum; i++) { if (surfAttribs[i].type == VASurfaceAttribExternalBufferDescriptor) { VASurfaceAttribExternalBuffers *surfAttribExtBuf = (VASurfaceAttribExternalBuffers *) surfAttribs[i].value. value.p; externalBufHandle = surfAttribExtBuf->buffers[0]; break; } } surface.reset(new VaapiSurface(display, id, chromaType, width, height,externalBufHandle)); return surface; }
BufObjectPtr VaapiBufObject::create(const ContextPtr& context, VABufferType bufType, uint32_t size, const void *data, void **mapped_data) { BufObjectPtr buf; if (size == 0) { ERROR("buffer size is zero"); return buf; } DisplayPtr display = context->getDisplay(); VABufferID bufID; if (!vaapiCreateBuffer(display->getID(), context->getID(), bufType, size, data, &bufID, mapped_data)) { ERROR("create buffer failed"); return buf; } void *mapped = mapped_data ? *mapped_data : NULL; buf.reset(new VaapiBufObject(display, bufID, mapped, size)); return buf; }