D3D11NV12Rendering
D3D11NV12Rendering copied to clipboard
When the height of the nv12 file is greater than the height of the window, a segmentation fault will occur!
D3D11_TEXTURE2D_DESC const texDesc = CD3D11_TEXTURE2D_DESC(
DXGI_FORMAT_NV12, // HoloLens PV camera format, common for video sources
m_width, // Width of the video frames
m_height, // Height of the video frames
1, // Number of textures in the array
1, // Number of miplevels in each texture
D3D11_BIND_SHADER_RESOURCE, // We read from this texture in the shader
D3D11_USAGE_DYNAMIC, // Because we'll be copying from CPU memory
D3D11_CPU_ACCESS_WRITE // We only need to write into the texture
);
void WriteNV12ToTexture(NV12Frame *nv12Frame)
{
// Copy from CPU access texture to bitmap buffer
D3D11_MAPPED_SUBRESOURCE resource;
UINT subresource = D3D11CalcSubresource(0, 0, 0);
OutMgr.m_DeviceContext->Map(OutMgr.m_texture, subresource, D3D11_MAP_WRITE_DISCARD, 0, &resource);
BYTE* dptr = reinterpret_cast<BYTE*>(resource.pData);
for (int i = 0; i < nv12Frame->height; i++)
{
memcpy(dptr + resource.RowPitch * i, nv12Frame->Y + nv12Frame->pitch * i, nv12Frame->pitch);
}
for (int i = 0; i < nv12Frame->height / 2; i++)
{
memcpy(dptr + resource.RowPitch *(nv12Frame->height + i), nv12Frame->UV + nv12Frame->pitch * i, nv12Frame->pitch);
}
OutMgr.m_DeviceContext->Unmap(OutMgr.m_texture, subresource);
}
if nv12Frame->height
is greater than m_height
, it will coredump.