public void Dispose() { IsVideoReady = false; if (m_mediaControl != null) { m_mediaControl.Stop(); Marshal.ReleaseComObject(m_mediaControl); m_mediaControl = null; } if (m_graph != null) { Marshal.ReleaseComObject(m_graph); m_graph = null; } if(m_internalBitmap != null) { m_internalBitmap.Dispose(); m_internalBitmap = null; } if(m_sharedSurface != null) { m_sharedSurface.Dispose(); m_sharedSurface = null; } }
private void OnNewAllocatorSurfaceCallback(object sender, IntPtr pSurface, IntPtr sharedHandle, Misc.Size size) { /* Reset our fields */ IsVideoReady = false; NaturalSize = new Size(0, 0); /* Free any resources that may be in use */ if(m_internalBitmap != null) { m_internalBitmap.Dispose(); m_internalBitmap = null; } if(m_sharedSurface != null) { m_sharedSurface.Dispose(); m_sharedSurface = null; } Texture2D sharedTexture2D = null; var device = m_directCanvasFactory.DeviceContext.Device; if (sharedHandle == IntPtr.Zero) return; try { /* Open up the shared surface using the passed shared handle */ sharedTexture2D = device.OpenSharedResource<Texture2D>(sharedHandle); } catch (Exception) { } if(sharedTexture2D == null) { return; } /* Wrap our Texture2D in our Texture class */ m_sharedSurface = new Texture(sharedTexture2D); var props = new BitmapProperties(); props.PixelFormat = new PixelFormat(Format.Unknown, AlphaMode.Premultiplied); /* Create a Direct2D bitmap, using the shared surface provided by * our custom allocator */ m_internalBitmap = new Bitmap(ResourceOwner.InternalRenderTarget, m_sharedSurface.InternalDxgiSurface, props); NaturalSize = new Size(m_sharedSurface.Description.Width, m_sharedSurface.Description.Height); IsVideoReady = true; }