Hello I’m using h264 encoding, at the moment it only works with video surfaces created with NVM_SURF_ATTR_CPU_ACCESS_UNMAPPED flag (please see the code below), NvMediaVideoSurfacePutBits takes around 14ms (which is slow!). When I’m trying to use NVM_SURF_ATTR_CPU_ACCESS_UNCACHED or NVM_SURF_ATTR_CPU_ACCESS_CACHED the encoded image is completely corrupted, NvMediaVideoSurfacePutBits takes around 8ms though. Could you please point me the way how to solve this?
SDK 5.0.5.0b
NVM_SURF_FMT_DEFINE_ATTR(surfaceFormatAttributes);
NVM_SURF_FMT_SET_ATTR_YUV(
surfaceFormatAttributes, YUV, 420, SEMI_PLANAR, UINT, 8, BL);
NvMediaSurfaceType surfaceType = NvMediaSurfaceFormatGetType(
surfaceFormatAttributes, NVM_SURF_FMT_ATTR_MAX);
if (surfaceType == NvMediaSurfaceType_Unsupported)
ERROR("NvMediaSurfaceFormatGetType() failed");
NvMediaSurfAllocAttr surfAllocAttrs[] = {
{ NVM_SURF_ATTR_WIDTH, IMAGE_WIDTH },
{ NVM_SURF_ATTR_HEIGHT, IMAGE_HEIGHT },
{ NVM_SURF_ATTR_CPU_ACCESS, NVM_SURF_ATTR_CPU_ACCESS_UNMAPPED }
};
const int numSurfAllocAttrs =
sizeof(surfAllocAttrs) / sizeof(surfAllocAttrs[0]);
DEBUG("Creating video surface ...");
mVideoSurface = std::shared_ptr<NvMediaVideoSurface>(
NvMediaVideoSurfaceCreateNew(
mDevice.get(), surfaceType, surfAllocAttrs, numSurfAllocAttrs, 0
),
[] (NvMediaVideoSurface * surface) {
if (surface != nullptr)
{
DEBUG("Destroying video surface ...");
NvMediaVideoSurfaceDestroy(surface);
}
});
…then later…
NvMediaVideoSurfaceMap surfaceMap;
NvMediaStatus status = NvMediaVideoSurfaceLock(
mVideoSurface.get(), &surfaceMap);
if (status != NVMEDIA_STATUS_OK)
ERROR("NvMediaVideoSurfaceLock() failed");
void * buffers[3];
uint32_t pitches[3];
buffers[0] = imageYUV.data;
pitches[0] = IMAGE_WIDTH;
buffers[1] = imageYUV.data + IMAGE_WIDTH * IMAGE_HEIGHT;
pitches[1] = IMAGE_WIDTH / 2u;
buffers[2] = static_cast<uint8_t*>(buffers[1]) +
IMAGE_WIDTH * IMAGE_HEIGHT / 4u;
pitches[2] = IMAGE_WIDTH / 2u;
status = NvMediaVideoSurfacePutBits(
mVideoSurface.get(), nullptr, buffers, pitches);
if (status != NVMEDIA_STATUS_OK)
ERROR("NvMediaVideoSurfacePutBits() failed");
NvMediaVideoSurfaceUnlock(mVideoSurface.get());