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; }
ImageRawPtr VaapiImage::map(VideoDataMemoryType memoryType) { ImageRawPtr raw = m_rawImage.lock(); if (raw) { if (raw->getMemoryType() != memoryType) { ERROR("map image to different memory type, wanted %d, mapped = %d", memoryType, raw->getMemoryType()); raw.reset(); } return raw; } raw = VaapiImageRaw::create(m_display, shared_from_this(), memoryType); m_rawImage = raw; return raw; }
ImageRawPtr mapVaapiImage(ImagePtr img, VideoDataMemoryType memoryType) { ImageRawPtr raw = img->m_rawImage.lock(); if (raw) { if (raw->getMemoryType() != memoryType) { ERROR("map image to different memory type, wanted %d, mapped = %d", memoryType, raw->getMemoryType()); raw.reset(); } return raw; } raw = VaapiImageRaw::create(img->m_display, img, memoryType); img->m_rawImage = raw; return raw; }