Ejemplo n.º 1
0
        /// <summary>
        /// Does the video job.
        /// </summary>
        private void DoVideoJob()
        {
            // TODO think if we must set ip address to something else than Any
            IPEndPoint orginalIPEndPoint = new IPEndPoint(IPAddress.Any, SourcePortVideo);

            _logger.Debug("Forward from {0} => {1}:{2}", ListenVideoPort, ForwardHostVideo, ForwardPortVideo);
            ForwardVUdpPort.Connect(ForwardHostVideo, ForwardPortVideo);
            byte[] frame;
            try
            {
                do
                {
                    IPEndPoint ipEndPoint = orginalIPEndPoint;
                    frame = _listenVUdpPort.Receive(ref ipEndPoint);
                    ForwardVUdpPort.BeginSend(frame, frame.Length, new AsyncCallback(EndSendVideo), frame);
                }while (true);
            }
            catch (ObjectDisposedException)
            {
                _logger.Debug("Forward video closed");
            }
            catch (SocketException)
            {
                _logger.Debug("Forward video closed");
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Ends the send video.
 /// </summary>
 /// <param name="result">The result.</param>
 private void EndSendVideo(IAsyncResult result)
 {
     try
     {
         int    nbOfByteSend = ForwardVUdpPort.EndSend(result);
         byte[] frame        = (byte[])result.AsyncState;
         VideoFrameSended(nbOfByteSend, frame);
     }
     catch (Exception error)
     {
         _logger.Error("Error during video forwarding", error);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Stops this instance.
        /// </summary>
        public override void Stop()
        {
            if (this.ToMulticast && ForwardInterleavedCommand >= 0)
            {
                IPAddress multicastAdress = IPAddress.Parse(this.ForwardHostVideo);
                ListenCUdpPort.DropMulticastGroup(multicastAdress);
            }

            ForwardCommand.DataReceived -= this.HandleDataReceive;

            ListenCUdpPort.Close();
            ForwardVUdpPort.Close();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Starts this instance.
        /// </summary>
        public override void Start()
        {
            _logger.Debug("Forward from TCP channel:{0} => {1}:{2}", SourceInterleavedVideo, ForwardHostVideo, ForwardPortVideo);
            ForwardVUdpPort.Connect(ForwardHostVideo, ForwardPortVideo);

            ForwardCommand.DataReceived += this.HandleDataReceive;

            if (ForwardInterleavedCommand >= 0)
            {
                _forwardCThread = new Thread(new ThreadStart(DoCommandJob));
                _forwardCThread.Start();
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Stops this instance.
        /// </summary>
        public override void Stop()
        {
            if (this.ToMulticast && ForwardPortCommand > 0)
            {
                IPAddress multicastAdress;
                if (IPAddress.TryParse(this.ForwardHostVideo, out multicastAdress))
                {
                    ListenCUdpPort.DropMulticastGroup(multicastAdress);
                }
            }

            _listenVUdpPort.Close();
            ListenCUdpPort.Close();
            ForwardVUdpPort.Close();
            _forwarCUdpPort.Close();
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Handles the data receive.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="e">The <see cref="RTSP.RTSPChunkEventArgs"/> instance containing the event data.</param>
 public void HandleDataReceive(object sender, RtspChunkEventArgs e)
 {
     if (e == null)
     {
         throw new ArgumentNullException("e");
     }
     Contract.EndContractBlock();
     try
     {
         RtspData data = e.Message as RtspData;
         if (data != null)
         {
             byte[] frame = data.Data;
             if (data.Channel == this.SourceInterleavedVideo)
             {
                 ForwardVUdpPort.BeginSend(frame, frame.Length, new AsyncCallback(EndSendVideo), frame);
             }
         }
     }
     catch (Exception error)
     {
         _logger.Warn("Error during frame forwarding", error);
     }
 }