예제 #1
0
        /// <summary>
        /// DistributePackets is responsible for receiving all incoming packets on the Rtp Listener,
        /// casting them into RtpPackets, creating new RtpStreams if one doesn't exist for the RtpPacket's SSRC,
        /// then calling RtpStream.newPacket(rtpPacket) to place the RtpPacket into the RtpStream's Queue for processing.
        /// </summary>
        private void DistributePackets()
        {
            while (newPacket.WaitOne())
            {
                while (receivedPackets.Count > 0)
                {
                    object[] ao = (object[])receivedPackets.Dequeue();

                    BufferChunk bc = (BufferChunk)ao[0];
                    IPEndPoint  ep = (IPEndPoint)ao[1];

                    try
                    {
                        //Turn the raw UDP packet data into an Rtp packet
                        RtpPacketBase packet = new RtpPacketBase(bc);

                        // For now, we support 2 types of packets - RtpPacket and RtpPacketFec.  If
                        // the number of packet types grows, we may need to push the casting onto
                        // the streams, since they know what type of packets they expect.  For now
                        // we will handle the casting here. JVE 6/17/2004
                        if (packet.PayloadType == PayloadType.FEC)
                        {
                            packet = new RtpPacketFec(packet);
                        }
                        else
                        {
                            packet = new RtpPacket(packet);
                        }


                        #region Fault Injection
                        #if FaultInjection
                        if (rtpSession.DropPacketsPercent > 0)
                        {
                            if (rtpSession.Rnd.Next(1, 100) <= rtpSession.DropPacketsPercent)
                            {
                                if (packet.PayloadType == PayloadType.FEC)
                                {
                                    RtpPacketFec fecPacket = (RtpPacketFec)packet;

                                    string msg = string.Format(
                                        "Dropping fec packet: {0}, FecIndex: {1}, DataRangeMin: {2}",
                                        fecPacket.Sequence, fecPacket.FecIndex, fecPacket.DataRangeMin);

                                    Trace.WriteLine(msg);

                                    pcDroppedFecPackets++;
                                    pcDroppedFecBytes += packet.PayloadSize;
                                }
                                else
                                {
                                    RtpPacket dataPacket = (RtpPacket)packet;

                                    string msg = string.Format(
                                        "Dropping data packet: {0}, FecIndex: {1}, FrameIndex: {2}, TS: {3}",
                                        dataPacket.Sequence, dataPacket.FecIndex, dataPacket.FrameIndex, dataPacket.TimeStamp);

                                    Trace.WriteLine(msg);

                                    pcDroppedDataPackets++;
                                    pcDroppedDataBytes += packet.PayloadSize;
                                }

                                ReturnBuffer(bc);
                                continue;
                            }
                        }
                        #endif
                        #endregion Fault Injection

                        // Get the stream if it exists
                        RtpStream stream = rtpSession.GetStream(packet.SSRC, ep.Address);

                        if (stream != null)
                        {
                            stream.ProcessPacket(packet);
                        }
                        else
                        {
                            // Otherwise return the packet to the pool
                            ReturnBuffer(bc);
                            unchecked { pcStreamlessPackets++; }
                        }
                    }
                    catch (ThreadAbortException) {}
                    catch (InvalidRtpPacketException e)
                    {
                        HandleInvalidPacket(bc, ep, e.ToString());
                        ReturnBuffer(bc);
                    }
                    catch (PoolExhaustedException e)
                    {
                        LogEvent(e.ToString(), EventLogEntryType.Error, (int)RtpEL.ID.UnboundedGrowth);
                        return; // Exit the thread gracefully
                    }
                    catch (Exception e)
                    {
                        ReturnBuffer(bc);
                        LogEvent(e.ToString(), EventLogEntryType.Error, (int)RtpEL.ID.Error);
                    }
                }
            }
        }
예제 #2
0
파일: RtpStream.cs 프로젝트: tdhieu/openvss
 public FrameReceivedEventArgs(RtpStream rtpStream, BufferChunk frame)
 {
     RtpStream = rtpStream;
     Frame = frame;
 }
예제 #3
0
        internal void RaiseRtpStreamTimeoutEvent(RtpStream stream)
        {
            rtpStreamTimeoutEvents++;

            object[] args = {this, new RtpEvents.RtpStreamEventArgs(stream)};
            EventThrower.QueueUserWorkItem(new RtpEvents.RaiseEvent(RtpEvents.RaiseRtpStreamTimeoutEvent), args);
        }
예제 #4
0
 public bool ContainsStream(RtpStream stream)
 {
     return (streamsAndIPs.GetStream(stream.SSRC) != null);
 }
예제 #5
0
파일: Events.cs 프로젝트: tdhieu/openvss
 public InvalidPacketInFrameEventArgs(RtpStream rtpStream, string reason)
 {
     RtpStream = rtpStream;
     Reason = reason;
 }
예제 #6
0
 public static void FrameIncomplete(RtpStream rtpStream, int framesLost)
 {
     // Event logging and perf counting are done in called method
     rtpStream.RaiseFrameOutOfSequenceEvent(framesLost, "Incomplete Frame Received -- Frame Lost");
 }
예제 #7
0
파일: Events.cs 프로젝트: tmpkus/openvss
 public PacketOutOfSequenceEventArgs(RtpStream rtpStream, int lostPackets, string message)
 {
     RtpStream   = rtpStream;
     LostPackets = lostPackets;
     Message     = message;
 }
예제 #8
0
 public IPStreamPair(IPAddress ip, RtpStream rtp)
 { senderIP = ip; stream = rtp; }
예제 #9
0
파일: Events.cs 프로젝트: tmpkus/openvss
 public FrameOutOfSequenceEventArgs(RtpStream rtpStream, int lostFrames, string message)
 {
     RtpStream  = rtpStream;
     LostFrames = lostFrames;
     Message    = message;
 }
예제 #10
0
파일: Events.cs 프로젝트: tmpkus/openvss
 public InvalidPacketInFrameEventArgs(RtpStream rtpStream, string reason)
 {
     RtpStream = rtpStream;
     Reason    = reason;
 }
예제 #11
0
파일: RtpStream.cs 프로젝트: tmpkus/openvss
 public FrameReceivedEventArgs(RtpStream rtpStream, BufferChunk frame)
 {
     RtpStream = rtpStream;
     Frame     = frame;
 }
예제 #12
0
파일: Events.cs 프로젝트: tdhieu/openvss
 public RtpStreamEventArgs(RtpStream rtpStream)
 {
     RtpStream = rtpStream;
 }
예제 #13
0
파일: Events.cs 프로젝트: tdhieu/openvss
 public PacketOutOfSequenceEventArgs ( RtpStream rtpStream, int lostPackets, string message )
 {
     RtpStream = rtpStream;
     LostPackets = lostPackets;
     Message = message;
 }
예제 #14
0
        private void FrameReceived(object sender, RtpStream.FrameReceivedEventArgs ea)
        {
            try
            {    
                if (firstFrame)
                {
                    Bitmap DrawImage = new Bitmap(video_width, video_height);

                    EncoderParameter epQuality = new EncoderParameter(Encoder.Quality, video_quality);
                    // Store the quality parameter in the list of encoder parameters
                    EncoderParameters epParameters = new EncoderParameters(1);
                    epParameters.Param[0] = epQuality;

                    MemoryStream ms = new MemoryStream();
                    DrawImage.Save(ms, GetImageCodecInfo(ImageFormat.Jpeg), epParameters);

                    Array.Copy(ms.GetBuffer(), 0, JpegHeader, 0, offset);
                    firstFrame = false;
                }

                byte[] data = new byte[ea.Frame.Buffer.Length + offset];
                Array.Copy(JpegHeader, data, JpegHeader.Length);
                Array.Copy(ea.Frame.Buffer, 0, data, offset, ea.Frame.Buffer.Length);
                System.IO.MemoryStream msImage = new MemoryStream(data);

                VsImage img = new VsImage((Bitmap)Image.FromStream(msImage));
                int index =  GetIndex(ea.RtpStream.IPAddress);

                if (index!= -1 && vsRtpStream[index] != null && vsRtpStream[index].FrameOut != null)
                {
                    vsRtpStream[index].FrameOut(this, new VsImageEventArgs(img));
                }
                img.Dispose();
                img = null;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
예제 #15
0
파일: Events.cs 프로젝트: tmpkus/openvss
 public RtpStreamEventArgs(RtpStream rtpStream)
 {
     RtpStream = rtpStream;
 }
예제 #16
0
 public void Add(uint ssrc, RtpStream rtpStream)
 {
     Dictionary.Add(ssrc, rtpStream);
 }
예제 #17
0
 public static void FrameIncomplete(RtpStream rtpStream, int framesLost)
 {
     // Event logging and perf counting are done in called method
     rtpStream.RaiseFrameOutOfSequenceEvent(framesLost, "Incomplete Frame Received -- Frame Lost");
 }
예제 #18
0
        private void FrameReceived(object sender, RtpStream.FrameReceivedEventArgs ea)
        {
            try
            {
                if (firstFrame)
                {
                    Console.WriteLine("First Frame");
                    Bitmap DrawImage = new Bitmap(ImgWidth, ImgHeight);

                    EncoderParameter epQuality = new EncoderParameter(Encoder.Quality, Quality);
                    // Store the quality parameter in the list of encoder parameters
                    EncoderParameters epParameters = new EncoderParameters(1);
                    epParameters.Param[0] = epQuality;

                    MemoryStream ms = new MemoryStream();
                    DrawImage.Save(ms, GetImageCodecInfo(ImageFormat.Jpeg), epParameters);

                    offset = search_jpegoffset(ms);
                    JpegHeader = new byte[offset];
                    Array.Copy(ms.GetBuffer(), 0, JpegHeader, 0, offset);
                    firstFrame = false;
                }

                byte[] data = new byte[ea.Frame.Buffer.Length + offset];
                Array.Copy(JpegHeader, data, JpegHeader.Length);
                Array.Copy(ea.Frame.Buffer, 0, data, offset, ea.Frame.Buffer.Length);
                System.IO.MemoryStream msImage = new MemoryStream(data);

                Console.WriteLine("Received New Frame");

                pictureBox1.Image = Image.FromStream(msImage);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Received Error :" + ex.Message);
            }
        }
예제 #19
0
파일: Events.cs 프로젝트: tdhieu/openvss
 public FrameOutOfSequenceEventArgs(RtpStream rtpStream, int lostFrames, string message)
 {
     RtpStream = rtpStream;
     LostFrames = lostFrames;
     Message = message;
 }