Exemplo n.º 1
0
        /// <summary>
        /// Writes a RtcpPacket to the dump.
        /// If written in Binary the packet will contain an 8 Byte overhead. If written in Payload or Header the Rtcp Packet is silently ignored.
        /// </summary>
        /// <param name="packet">The packet to write</param>
        /// <param name="timeOffset">The optional time the packet was recieved relative to the beginning of the file. If the packet has a Created time that will be used otherwise DateTime.UtcNow.</param>
        public void WritePacket(Rtcp.RtcpPacket packet, TimeSpan?timeOffset = null, System.Net.IPEndPoint source = null)
        {
            if (timeOffset < TimeSpan.Zero)
            {
                throw new ArgumentOutOfRangeException("timeOffset cannot be less than the start of the file which is defined in the header. ");
            }

            //Use the tool entry so it is disposed immediately
            using (var entry = new RtpToolEntry(m_Start, source ?? m_Source, packet))
            {
                //If given a specific timeoffset use it

                /* start of recording (GMT) */
                if (timeOffset.HasValue)
                {
                    entry.Offset = (int)timeOffset.Value.TotalMilliseconds;
                }
                else
                {
                    entry.Offset = (int)(DateTime.UtcNow - m_Start).TotalMilliseconds;  //otherwise calulcate it
                }
                //entry.Offset = /* milliseconds since the start of recording */

                //Write the item
                WriteToolEntry(entry);
            }
        }
Exemplo n.º 2
0
        //WritePackets(RtcpPacket[])

        //WritePackets(RtpFrame frame)

        /// <summary>
        /// Writes a DumpItem to the underlying stream
        /// </summary>
        /// <param name="item">The DumpItem to write</param>
        internal void WriteToolEntry(RtpToolEntry entry)
        {
            //If already written nothing occurs
            WriteFileHeader();

            //Write non text format entry
            if (m_Format < FileFormat.Text)
            {
                //This is a header style
                if (m_Format == FileFormat.Header)
                {
                    if (entry.IsRtcp)
                    {
                        //Indicate only the header is kept
                        entry.Length = (short)(entry.BlobLength = Media.Rtcp.RtcpHeader.Length + +RtpToolEntry.sizeOf_RD_packet_T);

                        //Write the data from the blob
                        using (Rtcp.RtcpPacket rtcp = new Rtcp.RtcpPacket(entry.Blob, entry.Pointer + RtpToolEntry.sizeOf_RD_packet_T)) m_Writer.Write(entry.Blob, 0, entry.BlobLength);
                    }
                    else if (m_Format != FileFormat.Rtcp)
                    {
                        using (Rtp.RtpPacket rtp = new Rtp.RtpPacket(entry.Blob, entry.Pointer + RtpToolEntry.sizeOf_RD_packet_T))
                        {
                            //Indicate only the header is kept
                            entry.Length = (short)(entry.BlobLength = Media.Rtp.RtpHeader.Length + RtpToolEntry.sizeOf_RD_packet_T);

                            //Write the data from the blob
                            m_Writer.Write(entry.Blob, 0, entry.BlobLength);
                        }
                    }
                }
                else if (m_Format == FileFormat.Binary)
                {
                    //Nothing to change
                    m_Writer.Write(entry.Blob);
                }
                else if (m_Format == FileFormat.Payload)
                {
                    if (entry.IsRtcp)
                    {
                        using (Rtcp.RtcpPacket rtcp = new Rtcp.RtcpPacket(entry.Blob, entry.Pointer + RtpToolEntry.sizeOf_RD_packet_T))
                        {
                            entry.Length = (short)(entry.BlobLength = rtcp.Payload.Count() + +RtpToolEntry.sizeOf_RD_packet_T);
                            m_Writer.Write(rtcp.Payload.ToArray());
                        }
                    }
                    else
                    {
                        using (Rtp.RtpPacket rtp = new Rtp.RtpPacket(entry.Blob, entry.Pointer + RtpToolEntry.sizeOf_RD_packet_T))
                        {
                            entry.Length = (short)(entry.BlobLength = rtp.PayloadData.Count() + RtpToolEntry.sizeOf_RD_packet_T);
                            m_Writer.Write(entry.Blob, 0, entry.BlobLength);
                        }
                    }
                }
            }
            else
            {
                //Write the textual version of the entry
                m_Writer.Write(System.Text.Encoding.ASCII.GetBytes(entry.ToString(m_Format)));
            }

            //Increment for the entry written
            ++m_ItemsWritten;
        }