Example #1
0
        //Event raised whenever the timer runs out
        private void getRTPPacket(Object source, ElapsedEventArgs e)
        {
            //Gets the most recent packet
            RTPPacketStuff rtpPacketStuff = _rtpModel.getRTPPacket();

            //Checks to make sure a packet was returned
            if (rtpPacketStuff != null)
            {
                //Get packet information
                string packetReport   = rtpPacketStuff.getPacketReport();
                byte[] packetHeader   = rtpPacketStuff.getPacketHeader();
                byte[] packetContents = rtpPacketStuff.getPacketContents();

                //Print packet report
                if (_view.printPacketReport())
                {
                    _view.updateClientStatusText(packetReport);
                }

                //Print header
                if (_view.printHeader())
                {
                    string byteString = "";
                    foreach (byte b in packetHeader)
                    {
                        byteString += Convert.ToString(b, 2).PadLeft(8, '0');
                        byteString += " ";
                    }

                    _view.updateClientStatusText(byteString);
                }

                //Get image and resize
                int            maxwidth       = 450;
                int            maxheight      = 230;
                ImageConverter imageConverter = new ImageConverter();
                Image          image          = (Image)(imageConverter.ConvertFrom(packetContents));
                if (image.Width > maxwidth | image.Height > maxheight)
                {
                    Bitmap bitmap = new Bitmap(maxwidth, maxheight);
                    using (Graphics graphics = Graphics.FromImage((Image)bitmap))
                        graphics.DrawImage(image, 0, 0, maxwidth, maxheight);
                    image = bitmap;
                }

                //Print packet contents to screen in view
                _view.updatePictureBox(image);
            }
        }
Example #2
0
        //Listen loop to listen for new RTP packets
        public void listen(EventHandler callback, ref bool paused)
        {
            //Loop to listen for rtp packets
            while (true)
            {
                byte[] receiveBytes = new byte[100000];

                try {
                    if (!paused)
                    {
                        //Receive rtp packets
                        int numBytes = _rtpSocket.Receive(receiveBytes);
                        Console.WriteLine(numBytes);

                        //Parse packet
                        RTP_Packet rtpPacket      = new RTP_Packet(receiveBytes, numBytes);
                        string     packetReport   = rtpPacket.getPacketReport();
                        byte[]     packetHeader   = rtpPacket.getPacketHeader();
                        byte[]     packetContents = rtpPacket.getPacketContents();

                        //Add packet stuff to queue
                        RTPPacketStuff rtpPacketStuff = new RTPPacketStuff(packetReport, packetHeader, packetContents);
                        _rtpPacketQueue.Enqueue(rtpPacketStuff);
                    }
                    else
                    {
                        // Paused, give up time slice
                        System.Threading.Thread.Sleep(30);
                    }
                } catch (Exception e) {
                    Console.WriteLine(e.Message);
                    Console.WriteLine(paused);
                    if (!paused)
                    {
                        Console.WriteLine("Paused");
                        callback(null, new EventArgs());
                        break;
                    }
                }
            }
        }