WriteableBitmap imageSource = new WriteableBitmap(videoWidth, videoHeight, DPI_X, DPI_Y, System.Windows.Media.PixelFormats.Bgr32, null); ... int rgbSize = width * height * 4; // bgr32 IntPtr rgbPtr = Marshal.AllocHGlobal(rgbSize); YV12ToRgb(yv12Ptr, rgbPtr, width, height); // 更新图像 imageSource.Lock(); Interop.Memcpy(this.imageSource.BackBuffer, rgbPtr, rgbSize); imageSource.AddDirtyRect(this.imageSourceRect); imageSource.Unlock(); Marshal.FreeHGlobal(rgbPtr);
private VideoMixingRenderer9 CreateRenderer() {
var result = new VideoMixingRenderer9();
var cfg = result as IVMRFilterConfig9;
cfg.SetNumberOfStreams(1);
cfg.SetRenderingMode(VMR9Mode.Renderless);
var notify = result as IVMRSurfaceAllocatorNotify9;
var allocator = new Vmr9Allocator();
notify.AdviseSurfaceAllocator(m_userId, allocator);
allocator.AdviseNotify(notify);
// 在构建VMR9 Render时,注册新视频帧渲染完成事件
allocator.NewAllocatorFrame += new Action(allocator_NewAllocatorFrame);
// 注册接收新D3DSurface被创建的事件
allocator.NewAllocatorSurface += new NewAllocatorSurfaceDelegate(allocator_NewAllocatorSurface);
return result;
}
void allocator_NewAllocatorSurface(object sender, IntPtr pSurface)
{
// 为了方便理解,只保留核心部分。省略改写了其他部分
...
// 将pSurface设置为D3DImage的BackBuffer
this.m_d3dImage.Lock();
this.m_d3dImage.SetBackBuffer(D3DResourceType.IDirect3DSurface9, pSurface);
this.m_d3dImage.Unlock();
...
}
void allocator_NewAllocatorFrame()
{
...
// 重绘
this.m_d3dImage.Lock();
this.m_d3dImage.AddDirtyRect(new Int32Rect(0, /* Left */
0, /* Top */
this.m_d3dImage.PixelWidth, /* Width */
this.m_d3dImage.PixelHeight /* Height */));
this.m_d3dImage.Unlock();
...
}
public void StretchRectangle( Surface sourceSurface, Rectangle sourceRectangle, Surface destSurface, Rectangle destRectangle, TextureFilter filter );
public void Render(IntPtr imgBuffer)
{
lock (this.renderLock)
{
// 将图像数据填充进offscreen surface
this.FillBuffer(imgBuffer);
// 调用StrentchRectangle把原始图像数据Copy到TextureSurface中
this.StretchSurface();
// 执行渲染操作
this.CreateScene();
}
// 通知D3DImage刷新图像
this.InvalidateImage();
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有