/// <summary> /// Configures the transport and forwarder. /// </summary> /// <param name="aMessage">A message.</param> /// <param name="forwarder">The preset forwarder.</param> /// <returns>The configured forwarder.</returns> private static Forwarder ConfigureTransportAndForwarder(RtspMessage aMessage, UDPForwarder forwarder) { RtspTransport transport = RtspTransport.Parse(aMessage.Headers[RtspHeaderNames.Transport]); Forwarder resultForwarder; if (transport.LowerTransport == RtspTransport.LowerTransportType.UDP) { if (transport.ServerPort != null) { forwarder.SourcePortVideo = transport.ServerPort.First; forwarder.ForwardPortCommand = transport.ServerPort.Second; } resultForwarder = forwarder; } else { TCPtoUDPForwader TCPForwarder = new TCPtoUDPForwader(); TCPForwarder.ForwardCommand = aMessage.SourcePort; TCPForwarder.SourceInterleavedVideo = transport.Interleaved.First; TCPForwarder.ForwardInterleavedCommand = transport.Interleaved.Second; // we need to transfer already getted values TCPForwarder.ForwardHostVideo = forwarder.ForwardHostVideo; TCPForwarder.ForwardPortVideo = forwarder.ForwardPortVideo; TCPForwarder.SourcePortCommand = forwarder.SourcePortCommand; TCPForwarder.ToMulticast = forwarder.ToMulticast; resultForwarder = TCPForwarder; } if (resultForwarder.ToMulticast) { // Setup port and destination multicast. resultForwarder.ForwardHostVideo = CreateNextMulticastAddress(); resultForwarder.ForwardPortVideo = forwarder.FromForwardVideoPort; RtspTransport newTransport = new RtspTransport() { IsMulticast = true, Destination = resultForwarder.ForwardHostVideo, Port = new PortCouple(resultForwarder.ForwardPortVideo, resultForwarder.ListenCommandPort) }; if ((resultForwarder is UDPForwarder && forwarder.ForwardPortCommand == 0) || (resultForwarder is TCPtoUDPForwader && (resultForwarder as TCPtoUDPForwader).ForwardInterleavedCommand == 0)) { newTransport.Port = null; } aMessage.Headers[RtspHeaderNames.Transport] = newTransport.ToString(); } else { RtspTransport newTransport = new RtspTransport() { IsMulticast = false, Destination = forwarder.ForwardHostVideo, ClientPort = new PortCouple(resultForwarder.ForwardPortVideo, resultForwarder.SourcePortCommand), ServerPort = new PortCouple(resultForwarder.FromForwardVideoPort, resultForwarder.ListenCommandPort) }; if ((resultForwarder is UDPForwarder && forwarder.ForwardPortCommand == 0) || (resultForwarder is TCPtoUDPForwader && (resultForwarder as TCPtoUDPForwader).ForwardInterleavedCommand == 0)) { newTransport.ServerPort = null; } aMessage.Headers[RtspHeaderNames.Transport] = newTransport.ToString(); } return resultForwarder; }
/// <summary> /// Configures the transport and forwarder. /// </summary> /// <param name="aMessage">A message.</param> /// <param name="forwarder">The preset forwarder.</param> /// <returns>The configured forwarder.</returns> private static Forwarder ConfigureTransportAndForwarder(RtspMessage aMessage, UDPForwarder forwarder) { RtspTransport transport = RtspTransport.Parse(aMessage.Headers[RtspHeaderNames.Transport]); Forwarder resultForwarder; if (transport.LowerTransport == RtspTransport.LowerTransportType.UDP) { if (transport.ServerPort != null) { forwarder.SourcePortVideo = transport.ServerPort.First; forwarder.ForwardPortCommand = transport.ServerPort.Second; } resultForwarder = forwarder; } else { TCPtoUDPForwader TCPForwarder = new TCPtoUDPForwader(); TCPForwarder.ForwardCommand = aMessage.SourcePort; TCPForwarder.SourceInterleavedVideo = transport.Interleaved.First; TCPForwarder.ForwardInterleavedCommand = transport.Interleaved.Second; // we need to transfer already getted values TCPForwarder.ForwardHostVideo = forwarder.ForwardHostVideo; TCPForwarder.ForwardPortVideo = forwarder.ForwardPortVideo; TCPForwarder.SourcePortCommand = forwarder.SourcePortCommand; TCPForwarder.ToMulticast = forwarder.ToMulticast; resultForwarder = TCPForwarder; } if (resultForwarder.ToMulticast) { // Setup port and destination multicast. resultForwarder.ForwardHostVideo = CreateNextMulticastAddress(); resultForwarder.ForwardPortVideo = forwarder.FromForwardVideoPort; RtspTransport newTransport = new RtspTransport() { IsMulticast = true, Destination = resultForwarder.ForwardHostVideo, Port = new PortCouple(resultForwarder.ForwardPortVideo, resultForwarder.ListenCommandPort) }; if ((resultForwarder is UDPForwarder && forwarder.ForwardPortCommand == 0) || (resultForwarder is TCPtoUDPForwader && (resultForwarder as TCPtoUDPForwader).ForwardInterleavedCommand == 0)) { newTransport.Port = null; } aMessage.Headers[RtspHeaderNames.Transport] = newTransport.ToString(); } else { RtspTransport newTransport = new RtspTransport() { IsMulticast = false, Destination = forwarder.ForwardHostVideo, ClientPort = new PortCouple(resultForwarder.ForwardPortVideo, resultForwarder.SourcePortCommand), ServerPort = new PortCouple(resultForwarder.FromForwardVideoPort, resultForwarder.ListenCommandPort) }; if ((resultForwarder is UDPForwarder && forwarder.ForwardPortCommand == 0) || (resultForwarder is TCPtoUDPForwader && (resultForwarder as TCPtoUDPForwader).ForwardInterleavedCommand == 0)) { newTransport.ServerPort = null; } aMessage.Headers[RtspHeaderNames.Transport] = newTransport.ToString(); } return(resultForwarder); }