/// <summary> /// Closes this source, sends BYE to remote party. /// </summary> /// <param name="closeReason">Stream closing reason text what is reported to the remote party. Value null means not specified.</param> /// <exception cref="ObjectDisposedException">Is raised when this class is Disposed and this method is accessed.</exception> internal override void Close(string closeReason) { if (this.State == RTP_SourceState.Disposed) { throw new ObjectDisposedException(this.GetType().Name); } RTCP_CompoundPacket packet = new RTCP_CompoundPacket(); RTCP_Packet_RR rr = new RTCP_Packet_RR(); rr.SSRC = this.SSRC; packet.Packets.Add(rr); RTCP_Packet_BYE bye = new RTCP_Packet_BYE(); bye.Sources = new uint[] { this.SSRC }; if (!string.IsNullOrEmpty(closeReason)) { bye.LeavingReason = closeReason; } packet.Packets.Add(bye); // Send packet. this.Session.SendRtcpPacket(packet); base.Close(closeReason); }
/// <summary> /// Parses 1 RTCP packet from the specified buffer. /// </summary> /// <param name="buffer">Buffer which contains RTCP packet.</param> /// <param name="offset">Offset in buffer.</param> /// <param name="noException">If true and parsing failed, no exception is raised.</param> /// <returns>Returns parsed RTCP packet or null if parsing is failed and <b>noException=true</b>.</returns> /// <exception cref="ArgumentNullException">Is raised when <b>buffer</b> is null.</exception> /// <exception cref="ArgumentException">Is raised when any of the arguments has invalid value.</exception> public static RTCP_Packet Parse(byte[] buffer, ref int offset, bool noException) { if (buffer == null) { throw new ArgumentNullException("buffer"); } if (offset < 0) { throw new ArgumentException("Argument 'offset' value must be >= 0."); } /* RFC 3550 RTCP header. * 0 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * header |V=2|P| XX | type | length | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ int type = buffer[offset + 1]; // SR if (type == RTCP_PacketType.SR) { RTCP_Packet_SR packet = new RTCP_Packet_SR(); packet.ParseInternal(buffer, ref offset); return(packet); } // RR else if (type == RTCP_PacketType.RR) { RTCP_Packet_RR packet = new RTCP_Packet_RR(); packet.ParseInternal(buffer, ref offset); return(packet); } // SDES else if (type == RTCP_PacketType.SDES) { RTCP_Packet_SDES packet = new RTCP_Packet_SDES(); packet.ParseInternal(buffer, ref offset); return(packet); } // BYE else if (type == RTCP_PacketType.BYE) { RTCP_Packet_BYE packet = new RTCP_Packet_BYE(); packet.ParseInternal(buffer, ref offset); return(packet); } // APP else if (type == RTCP_PacketType.APP) { RTCP_Packet_APP packet = new RTCP_Packet_APP(); packet.ParseInternal(buffer, ref offset); return(packet); } else { // We need to move offset. offset += 2; int length = buffer[offset++] << 8 | buffer[offset++]; offset += length; if (noException) { return(null); } else { throw new ArgumentException("Unknown RTCP packet type '" + type + "'."); } } }