我正在为UWP应用程序中的硬件加速H264解码和渲染实现解决方案。我想避免从GPU复制到CPU。解决方案包括两部分:
我在C#应用程序中接收编码的数据,并将其发送到C库以使用pinvoke进行解码并获得指向帧的指针。
C部分到目前为止看起来不错。我设法在C库中的GPU中接收到指向解码帧的指针:
// ffmpeg decoding logic
ID3D11Texture2D* texturePointer = (ID3D11Texture2D*)context->frame->data[0];
我设法用C#代码接收此指针,并从中创建SharpDX纹理。
var texturePointer = decoder.Decode(...data...); // pinvoke
if (texturePointer != IntPtr.Zero)
{
var texture = new Texture2D(texturePointer); // works just perfect
}
现在我需要在屏幕上渲染它。我的理解是,我可以创建扩展SurfaceImageSource
的类,以便可以将其分配为XAML Source
对象的Image
。可能是这样的:
public class RemoteMediaImageSource : SurfaceImageSource
{
public void BeginDraw(IntPtr texturePointer)
{
var texture = new Texture2D(texturePointer);
// What to do to render texture in GPU to the screen?
}
}
我的假设正确吗?如果是,我该如何准确地进行渲染(代码示例将不胜感激)?