/// <summary> /// Calls <see cref="Disconnect"/> and disposes all contained <see cref="RtpClient.TransportContext"/>. /// Stops the raising of any events. /// Removes the Logger /// </summary> public override void Dispose() { if (IsDisposed) return; Disconnect(); base.Dispose(); if (false == ShouldDispose) return; //Dispose contexts foreach (TransportContext tc in TransportContexts) tc.Dispose(); //Counters go away with the transportChannels TransportContexts.Clear(); //Remove my handler (should be done when set to null anyway) RtpPacketSent -= new RtpPacketHandler(HandleOutgoingRtpPacket); RtcpPacketSent -= new RtcpPacketHandler(HandleOutgoingRtcpPacket); //Stop raising events RtpPacketSent = null; RtcpPacketSent = null; RtpPacketReceieved = null; RtcpPacketReceieved = null; InterleavedData = null; //Send abort signal Media.Common.Extensions.Thread.ThreadExtensions.TryAbort(ref m_WorkerThread); //Send abort signal to all threads contained. //Delegate AbortDelegate //Media.Common.IThreadReferenceExtensions.AbortAll(this); DisableFeedbackReports(this); //Empty packet buffers m_OutgoingRtpPackets.Clear(); m_OutgoingRtcpPackets.Clear(); //Remove the buffer m_Buffer.Dispose(); m_Buffer = null; //Unset the logger Logger = null; }
/// <summary> /// Assigns the events necessary for operation and creates or assigns memory to use as well as inactivtyTimout. /// </summary> /// <param name="memory">The optional memory segment to use</param> /// <param name="incomingPacketEventsEnabled"><see cref="IncomingPacketEventsEnabled"/></param> /// <param name="frameChangedEventsEnabled"><see cref="FrameChangedEventsEnabled"/></param> public RtpClient(Common.MemorySegment memory = null, bool incomingPacketEventsEnabled = true, bool frameChangedEventsEnabled = true, bool outgoingPacketEvents = true) : this() { if (memory == null) { //Determine a good size based on the MTU (this should cover most applications) //Need an IP or the default IP to ensure the MTU Matches. m_Buffer = new Common.MemorySegment(1500); } else { m_Buffer = memory; if (m_Buffer.Count < RtpHeader.Length) throw new ArgumentOutOfRangeException("memory", "memory.Count must contain enough space for a RtpHeader"); } //RtpPacketReceieved += new RtpPacketHandler(HandleIncomingRtpPacket); //RtcpPacketReceieved += new RtcpPacketHandler(HandleIncomingRtcpPacket); RtpPacketSent += new RtpPacketHandler(HandleOutgoingRtpPacket); RtcpPacketSent += new RtcpPacketHandler(HandleOutgoingRtcpPacket); //InterleavedData += new InterleaveHandler(HandleInterleavedData); //Allow events to be raised HandleIncomingRtpPackets = HandleIncomingRtcpPackets = IncomingRtpPacketEventsEnabled = IncomingRtcpPacketEventsEnabled = incomingPacketEventsEnabled; //Fire events for packets received and Allow events to be raised HandleOutgoingRtpPackets = HandleOutgoingRtcpPackets = OutgoingRtpPacketEventsEnabled = OutgoingRtcpPacketEventsEnabled = outgoingPacketEvents; //Handle frame changes and Allow frame change events to be raised HandleFrameChanges = FrameChangedEventsEnabled = frameChangedEventsEnabled; }