The standard Rtp packet TODO - we may need to re-add support for CSRCs and HeaderExtensions, although header extensions could just as easily be implemented as payload headers
Inheritance: PacketBase
Ejemplo n.º 1
0
        protected virtual void ResetDecodingState(RtpPacketBase packet)
        {
            if (packet.PayloadType == PayloadType)
            {
                RtpPacket rtpPacket = (RtpPacket)packet;
                minSeq = unchecked((ushort)(rtpPacket.Sequence - rtpPacket.FecIndex));
            }
            else
            {
                minSeq = ((RtpPacketFec)packet).DataRangeMin;
            }

            maxSeq = unchecked((ushort)(minSeq + dataPxExp - 1));
            rangeInitialized = true;
            recoveryIndex = 0;
        }
Ejemplo n.º 2
0
        protected override void ResetDecodingState(RtpPacketBase packet)
        {
            ushort packetsInFrame;

            if (packet.PayloadType == PayloadType)
            {
                packetsInFrame = ((RtpPacket)packet).PacketsInFrame;
            }
            else
            {
                packetsInFrame = ((RtpPacketFec)packet).PacketsInFrame;
            }

            if (dataPxExp != packetsInFrame)
            {
                // Resize data structures appropriately
                dataPxExp = packetsInFrame;

                fecPxExp = (ushort)(dataPxExp * fecPercent / 100);
                if (dataPxExp * fecPercent % 100 > 0)
                {
                    fecPxExp++;
                }

                fecPxExp = Math.Min(fecPxExp, RS_Fec.MaxChecksumPackets);

                SetDecoder();
                InitializeDCRStorage();
            }

            base.ResetDecodingState(packet);
        }
Ejemplo n.º 3
0
        internal override void ProcessPacket(RtpPacketBase packet)
        {
            // If any part of this code throws an exception we need to clean up what we have and
            // reset back to a default state so we can start over.
            try
            {
                PayloadType pt = packet.PayloadType;
                ValidatePayloadType(pt);

                // Process packet, depending on payload type
                if (pt == this.pt)
                {
                    ProcessPacketData((RtpPacket)packet);
                }
                else
                {
                    ProcessPacketFec((RtpPacketFec)packet);
                }

                // See if we have collected enough packets
                if (dataPxAct == dataPxExp)
                {
                    ForwardDataPacketsToBase();
                }
                else if (dataPxAct + fecPxAct == dataPxExp)
                {
                    Decode();
                    ForwardDataPacketsToBase();
                }
            }
            catch (ThreadAbortException) { } // Because we catch a generic exception next
            catch (Exception e)
            {
                //eventLog.WriteEntry(e.ToString(), EventLogEntryType.Error, (int)RtpEL.ID.Error);
                ForwardDataPacketsToBase();
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Create a packet from an existing packet
 /// </summary>
 /// <param name="packet"></param>
 internal RtpPacketBase(RtpPacketBase packet)
     :base(packet)
 {
     //buffer = packet.buffer;
 }
Ejemplo n.º 5
0
        /// <summary>
        /// DistributePackets turns packets that came from the listener thread 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();
                    object[] ao = null;
                    if (!receivedPackets.TryDequeue(out ao))
                        continue;

                    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);
                        }
                        
                        // 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);
                    }
                }
            }
        }
Ejemplo n.º 6
0
 public RtpPacket(RtpPacketBase packet) : base(packet){}
Ejemplo n.º 7
0
 internal RtpPacketFec(RtpPacketBase packet) : base(packet)
 {
     if(PayloadType != PayloadType.FEC)
     {
         throw new ArgumentException(Strings.PacketIsNotAnFECPacket);
     }
 }