Exemplo n.º 1
0
        /// <summary>
        /// Cleans up any resource being used.
        /// </summary>
        public void Dispose()
        {
            if(m_IsDisposed){
                return;
            }

            Stop();

            this.Error        = null;
            m_pAudioOutDevice = null;
            m_pRTP_Stream     = null;
            m_pAudioCodecs    = null;
            m_pActiveCodec    = null;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Cleans up any resources being used.
        /// </summary>
        public void Dispose()
        {
            if(m_IsDisposed){
                return;
            }

            Stop();

            m_IsDisposed = true;

            this.Error        = null;
            m_pAudioInDevice  = null;
            m_pAudioCodecs    = null;
            m_pRTP_Stream.Session.PayloadChanged -= new EventHandler(m_pRTP_Stream_PayloadChanged);
            m_pRTP_Stream     = null;
            m_pActiveCodec    = null;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Tworzy nową instancję klienta streamingu przez udp.
        /// </summary>
        /// <param name="video_window">Picturebox, w którym będzie wyświetlany obraz z kamery/streamu.</param>
        /// <param name="remote_ip">Zdalne IP serwera lub innego klienta.</param>
        public UdpStreamClient(PictureBox video_window, string remote_ip)
        {
            videoCapture = null;
            filters = new Filters();
            microphone = null;
            speaker = null;
            streaming = false;
            recieving = false;
            inColor = true;
            timeInterval = 1000;
            framesCount = 0;
            videoWindow = video_window;
            audioCodec = new PCMU();

            #region Wstępne ustawienia kompresji
            //#################################################
            encoderParams = new EncoderParameters(2);

            // Ustawiamy format kompresji na JPEG
            jpegEncoder = GetEncoder(ImageFormat.Jpeg);

            // Ustawiamy jakość obrazu
            this.SetImageQuality(20L);

            // Ustawiamy głębię kolorów
            this.SetImageColorDepth(8L);
            //#################################################
            #endregion // Wstępne ustawienia kompresji

            // Ustalanie lokalnego ip.
            strHostName = Dns.GetHostName();
            this.ipHostEntry = Dns.GetHostByName(strHostName);
            this.localEndPoint = new IPEndPoint(ipHostEntry.AddressList[0], localUdpPort);

            // Ustawianie zdalnego ip.
            try
            {
                this.remoteEndPoint = new IPEndPoint(IPAddress.Parse(remote_ip), remoteUdpPort);
            }
            catch(FormatException ex) { MessageBox.Show(ex.Message, "Streaming"); }
        }
Exemplo n.º 4
0
        /// <summary>
        /// This method is called when new RTP packet received.
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="e">Event data.</param>
        private void m_pRTP_Stream_PacketReceived(object sender,RTP_PacketEventArgs e)
        {
            if(m_IsDisposed){
                return;
            }

            try{
                AudioCodec codec = null;
                if(!m_pAudioCodecs.TryGetValue(e.Packet.PayloadType,out codec)){
                    // Unknown codec(payload value), skip it.

                    return;
                }
                m_pActiveCodec = codec;

                // Audio-out not created yet, create it.
                if(m_pAudioOut == null){
                    m_pAudioOut = new AudioOut(m_pAudioOutDevice,codec.AudioFormat);
                }
                // Audio-out audio format not compatible to codec, recreate it.
                else if(!m_pAudioOut.AudioFormat.Equals(codec.AudioFormat)){
                    m_pAudioOut.Dispose();
                    m_pAudioOut = new AudioOut(m_pAudioOutDevice,codec.AudioFormat);
                }

                // Decode RTP audio frame and queue it for play out.
                byte[] decodedData = codec.Decode(e.Packet.Data,0,e.Packet.Data.Length);
                m_pAudioOut.Write(decodedData,0,decodedData.Length);
            }
            catch(Exception x){
                if(!this.IsDisposed){
                    // Raise error event(We can't throw expection directly, we are on threadpool thread).
                    OnError(x);
                }
            }
        }
Exemplo n.º 5
0
        //CONSOLE
        /////////////
        public Robot1()
        {
            //ACCELEROMETER
            this.usrCtrlAxis2D = new UsrCtrlAxis2D();
            this.usrCtrlAxis2D.Size = new Size(350, 350);
            this.usrCtrlAxis2D.Location = new Point(0, 0);
            this.usrCtrlAxis2D.BackColor = Color.AliceBlue;
            //this.tabPage19.Controls.Add(this.usrCtrlAxis2D);

            InitializeComponent();

            batt.aktualne_nap = 0.1f; //initial value for battery monitor
            SetMap();
            Robot1.CheckForIllegalCrossThreadCalls = false;
            comboBox1.SelectedItem = "nothing";
            comboBox2.SelectedItem = "nothing";
            comboBox3.SelectedItem = "nothing";
            comboBox4.SelectedItem = "nothing";
            comboBox5.SelectedItem = "nothing";
            comboBox6.SelectedItem = "nothing";
            comboBox7.SelectedItem = "nothing";
            comboBox8.SelectedItem = "nothing";
            comboBox9.SelectedItem = "nothing";
            comboBox10.SelectedItem = "nothing";
            //Trajectory activation
            button12.Enabled = true;
            button14.Enabled = false;
            button17.Enabled = false;
            button13.Enabled = false;
            button18.Enabled = false;
            button15.Enabled = false;
            //Audio stream
            foreach (IPAddress ip in System.Net.Dns.GetHostAddresses(""))
            {
                m_pLocalIP.Items.Add(ip.ToString());
            }
            m_pLocalIP.SelectedIndex = m_pLocalIP.Items.Count-2;
            //m_pLocalIP.SelectedIndex = 0;
            m_pCodec.Items.Add("G711 a-law");
            m_pCodec.Items.Add("G711 u-law");
            m_pCodec.Enabled = false;
            LoadWaveDevices();
            m_pActiveCodec = new PCMA();
            //Bootloader
            comboBoxport.SelectedIndex = 0;
            comboBoxMCU.SelectedIndex = 0;
            //Inicialize TCP Client
            groupDirectionAndMotion.Enabled = false;
            groupCameraRotation.Enabled = false;
            groupCameraRot2.Enabled = false;
            groupComPortSettings.Enabled = false;
            groupComPortDefault.Enabled = false;
            groupTcpClientServerSettings.Enabled = true;
            groupTcpClientServerDefault.Enabled = true;
            textTCPClientServerIPAddress.ReadOnly = false;
            textTCPCommunicationType.Text = "CLIENT";
            labelCommunicationType.Text = "TCP Client";
            toolStripconnect.Enabled = true;
            ThreadCheckStat = new Thread(CheckStatus);
            ThreadCheckStat.Start();
            //Small Cam
            o = new Options();
            combo_streams.SelectedText = "1";
            //AUDIO DELEGATE
            m_DelegateAddString = new DelegateAddString(this.AddString);
            m_DelegateAddString1 = new DelegateAddString1(this.AddString1);

            //ACCELEROMETER
            //this.usrCtrlAxis3D = new UsrCtrlAxis3D();
            //this.usrCtrlAxis3D.Size = new Size(350, 350);
            //this.usrCtrlAxis3D.Location = new Point(0, 0);
            //this.Controls.Add(this.usrCtrlAxis3D);
            this.mySerialPort = new SerialPort("COM4", 9600, Parity.None, 8, StopBits.One);
            this.mySerialPort.Handshake = Handshake.None;
            this.mySerialPort.RtsEnable = true;
            this.mySerialPort.DataReceived += new SerialDataReceivedEventHandler(MySerialPort_DataReceived);
        }
Exemplo n.º 6
0
 private void m_pCodec_SelectedIndexChanged(object sender, EventArgs e)
 {
     // G711 a-law
     if (m_pCodec.SelectedIndex == 0)
     {
         m_pActiveCodec = new PCMA();
         m_pRtpSession.Sessions[0].Payload = 8;
     }
     // G711 u-law
     else
     {
         m_pActiveCodec = new PCMU();
         m_pRtpSession.Sessions[0].Payload = 0;
     }
 }
Exemplo n.º 7
0
        public Robot1()
        {
            //ACCELEROMETER
            this.usrCtrlAxis2D = new UsrCtrlAxis2D();
            this.usrCtrlAxis2D.Size = new Size(350, 350);
            this.usrCtrlAxis2D.Location = new Point(0, 0);
            this.usrCtrlAxis2D.BackColor = Color.AliceBlue;
            this.usrCtrlAxis3D = new UsrCtrlAxis3D();
            this.usrCtrlAxis3D.Size = new Size(350, 350);
            this.usrCtrlAxis3D.Location = new Point(0, 0);

            InitializeComponent();

            //VERSION UPDATE PUBLISH
            Version version2 = new Version();
            if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed)
            {
                System.Deployment.Application.ApplicationDeployment ad = System.Deployment.Application.ApplicationDeployment.CurrentDeployment;
                version2 = ad.CurrentVersion;
            }

            //VERSION UPDATE BUILD
            Version vrs = new Version(Application.ProductVersion);
            this.Text = "CONTROL APPLICATION  ORCS ROBOT G4 (SECURITY GUARD ROBOT) / AssemblyBuid " + vrs.Major + "." + vrs.Minor + "." + vrs.Build + "." + vrs.Revision + " / Publish Version ClickOnce " + PublishVersion().ToString() + " / RC" + version2.Revision.ToString(); //String.Format("ClickOnce Version {0}.{1}.{2}.{3}", version.Major, version.Minor, version.Revision, version.Build);

            //BATTERY
            batt.aktualne_nap = 0.1f; //initial value for battery monitor
            SetMap();
            Robot1.CheckForIllegalCrossThreadCalls = false;
            comboBox1.SelectedItem = "nothing";
            comboBox2.SelectedItem = "nothing";
            comboBox3.SelectedItem = "nothing";
            comboBox4.SelectedItem = "nothing";
            comboBox5.SelectedItem = "nothing";
            comboBox6.SelectedItem = "nothing";
            comboBox7.SelectedItem = "nothing";
            comboBox8.SelectedItem = "nothing";
            comboBox9.SelectedItem = "nothing";
            comboBox10.SelectedItem = "nothing";
            //Trajectory activation
            button12.Enabled = true;
            button14.Enabled = false;
            button17.Enabled = false;
            button13.Enabled = false;
            button18.Enabled = false;
            button15.Enabled = false;
            //Audio stream
            foreach (IPAddress ip in System.Net.Dns.GetHostAddresses(""))
            {
                m_pLocalIP.Items.Add(ip.ToString());
            }
            m_pLocalIP.SelectedIndex = m_pLocalIP.Items.Count-2;
            //m_pLocalIP.SelectedIndex = 0;
            m_pCodec.Items.Add("G711 a-law");
            m_pCodec.Items.Add("G711 u-law");
            m_pCodec.Enabled = false;
            LoadWaveDevices();
            m_pActiveCodec = new PCMA();
            //Bootloader
            comboBoxport.SelectedIndex = 0;
            comboBoxMCU.SelectedIndex = 0;
            //Inicialize TCP Client
            groupDirectionAndMotion.Enabled = false;
            groupCameraRotation.Enabled = false;
            groupCameraRot2.Enabled = false;
            textTCPClientServerIPAddress.ReadOnly = false;
            textTCPCommunicationType.Text = "CLIENT";
            labelCommunicationType.Text = "TCP Client";
            toolStripconnect.Enabled = true;
            ThreadCheckStat = new Thread(CheckStatus);
            ThreadCheckStat.Start();
            //Small Cam
            o = new Options();
            combo_streams.SelectedText = "1";
            //AUDIO DELEGATE
            m_DelegateAddString = new DelegateAddString(this.AddString);
            m_DelegateAddString1 = new DelegateAddString1(this.AddString1);

            //ACCELEROMETER
            //this.usrCtrlAxis3D = new UsrCtrlAxis3D();
            //this.usrCtrlAxis3D.Size = new Size(350, 350);
            //this.usrCtrlAxis3D.Location = new Point(0, 0);
            //this.Controls.Add(this.usrCtrlAxis3D);
            this.panelMEMS.Controls.Add(this.usrCtrlAxis2D);
            this.panelMEMS.Controls.Add(this.usrCtrlAxis3D);
            CreateGraph(); //MEMS Create Graph

            this.mySerialPort = new SerialPort("COM5", 9600, Parity.None, 8, StopBits.One);
            this.mySerialPort.Handshake = Handshake.None;
            this.mySerialPort.RtsEnable = true;
            this.mySerialPort.DataReceived += new SerialDataReceivedEventHandler(MySerialPort_DataReceived);

            //GPS
            GPS.GPSFileLogCreate();
        }
Exemplo n.º 8
0
        /// <summary>
        /// Is called when RTP session sending payload has changed.
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="e">Event data.</param>
        private void m_pRTP_Stream_PayloadChanged(object sender,EventArgs e)
        {
            if(m_IsRunning){
                Stop();

                m_pActiveCodec = null;
                m_pAudioCodecs.TryGetValue(m_pRTP_Stream.Session.Payload,out m_pActiveCodec);

                Start();
            }
        }
Exemplo n.º 9
0
        private void btnRestartConnection_Click_1(object sender, RoutedEventArgs e)
        {
            if (cbLocalIp.SelectedIndex < 0)
            {
                MessageBox.Show("Choose local IP");
                return;
            }

            IsConnected = true;
            InitializeClient();
            InitializeServer();
            /*InitializeSoundSender();
            InitializeSoundReceiver();*/
            if (m_IsRunning)
            {
                m_IsRunning = false;
                m_IsSendingTest = false;

                m_pRtpSession.Dispose();
                m_pRtpSession = null;

                m_pWaveOut.Dispose();
                m_pWaveOut = null;
            }
            else
            {
                m_IsRunning = true;

                switch (_selectedCodec)
                {
                    case "PCMU":
                        m_pActiveCodec = new PCMU();
                        break;
                    case "PCMA":
                    default:
                        m_pActiveCodec = new PCMA();
                        break;
                }

                var selectedOutDevice = cbAudioOutDevices.SelectedItem as AudioOutDevice;
                m_pWaveOut = new AudioOut(selectedOutDevice, _samplesPerSecond, _bitsPerSample, 1); // 1 - one channel (mono)
                m_pRtpSession = new RTP_MultimediaSession(RTP_Utils.GenerateCNAME());

                string localIp = cbLocalIp.SelectedItem.ToString();
                string partnerIp = tbxPartnerIp.Text;
                int k = string.Compare(localIp, partnerIp);

                m_pRtpSession.CreateSession(new RTP_Address(IPAddress.Parse(cbLocalIp.SelectedItem.ToString()), (int)10000 + k * 500/*m_pLocalPort.Value*/, (int)/*m_pLocalPort.Value*/10000 + k * 500 + 1), new RTP_Clock(0, _samplesPerSecond));
                m_pRtpSession.Sessions[0].AddTarget(new RTP_Address(IPAddress.Parse(tbxPartnerIp.Text), (int)/*m_pRemotePort.Value*/10000 - k * 500, (int)/*m_pRemotePort.Value*/10000 - k * 500 + 1));
                m_pRtpSession.Sessions[0].NewSendStream += new EventHandler<RTP_SendStreamEventArgs>(m_pRtpSession_NewSendStream);
                m_pRtpSession.Sessions[0].NewReceiveStream += new EventHandler<RTP_ReceiveStreamEventArgs>(m_pRtpSession_NewReceiveStream);
                m_pRtpSession.Sessions[0].Payload = 0;
                m_pRtpSession.Sessions[0].Start();

                m_pAudioCodecs = new Dictionary<int, AudioCodec>();
                m_pAudioCodecs.Add(0, new PCMU());
                m_pAudioCodecs.Add(8, new PCMA());
            }
        }