/// <summary>
        /// Handles the Media.PacketRead event writing the packet to the output context.
        /// </summary>
        /// <param name="sender">the media element that sent this event.</param>
        /// <param name="e">The event arguments containing the packet data.</param>
        private void OnMediaPacketRead(object sender, PacketReadEventArgs e)
        {
            lock (SyncLock)
            {
                const AVRounding RoundingMode = AVRounding.AV_ROUND_NEAR_INF | AVRounding.AV_ROUND_PASS_MINMAX;

                if (HasClosed)
                {
                    return;
                }

                if (!HasInitialized)
                {
                    Initialize(e.InputContext);
                }

                var inputStreamIndex  = e.Packet->stream_index;
                var outputStreamIndex = StreamMappings[inputStreamIndex];

                var inputTimeBase  = e.InputContext->streams[inputStreamIndex]->time_base;
                var outputTimeBase = OutputContext->streams[outputStreamIndex]->time_base;

                var packet = ffmpeg.av_packet_clone(e.Packet);
                packet->stream_index = outputStreamIndex;
                packet->pos          = -1;
                packet->pts          = ffmpeg.av_rescale_q_rnd(packet->pts, inputTimeBase, outputTimeBase, RoundingMode);
                packet->dts          = ffmpeg.av_rescale_q_rnd(packet->dts, inputTimeBase, outputTimeBase, RoundingMode);
                packet->duration     = ffmpeg.av_rescale_q(packet->duration, inputTimeBase, outputTimeBase);

                ffmpeg.av_interleaved_write_frame(OutputContext, packet);
                ffmpeg.av_packet_unref(packet);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Event raised when a network packet is read from the file.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Parser_PacketRead(object sender, PacketReadEventArgs e)
        {
            var packet = e.PacketRecord;

            recordCount++;
            try
            {
                var etherPacket = packet.EthernetPacket;
                if (etherPacket != null && etherPacket.Proto == EtherType.IPv4)
                {
                    var ipPacket = etherPacket.Data as IPv4Packet;

                    // Ignore loopback traffic. We can't distinguish direction if both sides are local.
                    // TODO create a more complex algoritm that allows this, but uses port instead.  Would require client to not use server port range though.
                    if (ipPacket.SrcAddr.IsLocal && ipPacket.DestAddr.IsLocal)
                    {
                        return;
                    }

                    if (ipPacket != null && ipPacket.Proto == IPProtocolType.UDP)
                    {
                        var udpPacket = ipPacket.Data as UdpPacket;

                        // Only process udp packets inwhich one direction is within our server port range
                        if (
                            udpPacket != null &&
                            ((udpPacket.SrcPort >= serverPortStart && udpPacket.SrcPort <= serverPortEnd) ||
                             (udpPacket.DestPort >= serverPortStart && udpPacket.DestPort <= serverPortEnd))
                            )
                        {
                            var sourceIP = new System.Net.IPEndPoint(ipPacket.SrcAddr.LongAddress, udpPacket.SrcPort);
                            // Create an Packet using byte data.  Packet parses AC headers and fragments from the data.
#if NETWORKDEBUG
                            // Packet number for reference in UI
                            var ACPacket = new Packets.Packet(udpPacket.Data, sourceIP, packet.PacketNum);
#else
                            var ACPacket = new Packets.Packet(udpPacket.Data, sourceIP);
#endif
                            // Pass packet to defragmenter to extract messages
                            if (ipPacket.SrcAddr.IsLocal)
                            {
                                c2sDefragmenter.ProcessPacket(ACPacket);
                            }
                            else
                            {
                                s2cDefragmenter.ProcessPacket(ACPacket);
                            }
                        }
                    }
                }
            }
            catch (Exception ex2)
            {
                string error = "Exception at packet " + packet.PacketNum + " of file " + FilePath.FullName;
                var    newEx = new Exception(error, ex2);
                exceptions.Add(newEx);
            }
        }
Exemplo n.º 3
0
 private void File_PacketRead(object sender, PacketReadEventArgs e)
 {
     PacketRead?.Invoke(this, e);
 }