/// <inheritdoc /> public void Dispose() { if (m_IsDisposed == true) { return; } m_IsDisposed.Value = true; // Dispose of commands. This closes the // Media automatically and signals an exit // This also causes the Container to get disposed. Commands.Dispose(); // Reset the RTC ResetPosition(); // Dispose the Wait Event objects as they are // backed by unmanaged code PacketReadingCycle.Dispose(); FrameDecodingCycle.Dispose(); BlockRenderingCycle.Dispose(); BufferChangedEvent.Dispose(); }
/// <summary> /// Runs the read task which keeps a packet buffer as full as possible. /// It reports on DownloadProgress by enqueueing an update to the property /// in order to avoid any kind of disruption to this thread caused by the UI thread. /// </summary> internal void RunPacketReadingWorker() { var delay = TimeSpan.FromMilliseconds(10); var needsMorePackets = false; IsSyncBuffering = false; try { // Worker logic begins here while (Commands.IsStopWorkersPending == false) { // Determine what to do on a priority command if (Commands.IsExecutingDirectCommand) { if (Commands.IsClosing) { break; } if (Commands.IsChanging) { Commands.WaitForDirectCommand(); } } // Wait for seeking or changing to be done. Commands.WaitForActiveSeekCommand(); // Enter a packet reading cycle PacketReadingCycle.Begin(); // Perform a packet read. t will hold the packet type. if (ShouldWorkerReadPackets) { try { Container.Read(); } catch (MediaContainerException) { break; } } else { // Give it a break until there are packet changes // this prevent pegging the cpu core BufferChangedEvent.Begin(); while (IsWorkerInterruptRequested == false) { needsMorePackets = ShouldWorkerReadPackets; // We now need more packets, we need to stop waiting if (needsMorePackets) { break; } // we are sync-buffering but we don't need more packets if (IsSyncBuffering && needsMorePackets == false) { break; } // We detected a change in buffered packets if (BufferChangedEvent.Wait(delay)) { break; } } } // No more sync-buffering if we have enough data if (CanExitSyncBuffering) { IsSyncBuffering = false; } // finish the reading cycle. PacketReadingCycle.Complete(); } } catch { throw; } finally { // Always exit notifying the reading cycle is done. PacketReadingCycle.Complete(); IsSyncBuffering = false; } }