private void EventProc() { logger.Debug("EventProc() BEGIN"); MediaEventGenerator eventGen = null; try { eventGen = encoder.QueryInterface <MediaEventGenerator>(); while (!closing) { MediaEvent mediaEvent = null; try { mediaEvent = eventGen.GetEvent(true); if (closing) { break; } HandleMediaEvent(mediaEvent); } catch (Exception ex) { logger.Error(ex); Thread.Sleep(10); } finally { if (mediaEvent != null) { mediaEvent.Dispose(); mediaEvent = null; } } } } finally { using (var shutdown = eventGen.QueryInterface <Shutdownable>()) { shutdown.Shutdown(); } eventGen?.Dispose(); Close(); } logger.Debug("EventProc() END"); }
public void Close() { logger.Debug("MfEncoderAsync::Close()"); closing = true; if (InputMediaType != null) { InputMediaType.Dispose(); InputMediaType = null; } if (OutputMediaType != null) { OutputMediaType.Dispose(); OutputMediaType = null; } if (encoder != null) { //using (var shutdown = encoder.QueryInterface<Shutdownable>()) //{ // shutdown.Shutdown(); // //while(shutdown.ShutdownStatus != ShutdownStatus.Completed) // //{ // // logger.Warn("shutdown.ShutdownStatus " + shutdown.ShutdownStatus); // // Thread.Sleep(100); // //} //} encoder.Dispose(); encoder = null; } if (bufSample != null) { bufSample.Dispose(); bufSample = null; } if (bufTexture != null) { bufTexture.Dispose(); bufTexture = null; } if (eventHandler != null) { eventHandler.EventReceived -= HandleMediaEvent; eventHandler.Dispose(); eventHandler = null; } if (mediaEventGenerator != null) { mediaEventGenerator.Dispose(); mediaEventGenerator = null; } // logger.Info(SharpDX.Diagnostics.ObjectTracker.ReportActiveObjects()); }