当视频显示在WPF控件的屏幕上时没有问题,除了CPU上的高负载。视频的输出是通过将像素从非托管代码复制到WritableBitmap
来进行的,解码是从事LIBVLC的。通过硬件加速的例子可以减少CPU负载吗?我不明白怎么可能这样做,而且有可能。
在此图像中,您可以在视频显示在屏幕上时看到CPU负载:
视频输出由以下代码输出:
void WpfMediaPlayer::OnRender(DrawingContext ^ drawingContext)
{
FrameworkElement^ parent = (FrameworkElement^)VisualTreeHelper::GetParent(this);
if (!parent)
return;
Matrix matrix = ((Transform^)TransformToVisual(parent))->Value;
drawingContext->DrawRectangle(System::Windows::Media::Brushes::Black,
gcnew System::Windows::Media::Pen(),
Rect(System::Windows::Point(0 - matrix.OffsetX, 0 - matrix.OffsetY), System::Windows::Size(RenderSize.Width + matrix.OffsetX * 2, RenderSize.Height + matrix.OffsetY * 2)));
bmWrite->WritePixels(Int32Rect(0, 0, bmWrite->PixelWidth, bmWrite->PixelHeight), IntPtr(ptr_image_), size_img_ptr, (width * bmWrite->Format.BitsPerPixel) / 8);
drawingContext->DrawImage(bmWrite, Rect(System::Windows::Point(), RenderSize));
}