Ejemplo n.º 1
0
        private void StopTalk()
        {
            if (_bTalking)
            {
                lock (_obj)
                {
                    if (_bTalking)
                    {
                        _bTalking = false;
                    }
                    if (_client != null)
                    {
                        _client.Close();
                        _client = null;
                    }

                    if (_avstream != null)
                    {
                        _avstream.Close();
                        _avstream.Dispose();
                        _avstream = null;
                    }

                    if (_muLawCodec != null)
                    {
                        _muLawCodec.Dispose();
                        _muLawCodec = null;
                    }

                    _audioSource.DataAvailable -= AudioSourceDataAvailable;
                    TalkStopped?.Invoke(this, EventArgs.Empty);
                }
            }
        }
Ejemplo n.º 2
0
        private void StopTalk(bool becauseOfException)
        {
            if (_bTalking)
            {
                lock (_obj)
                {
                    _stopEvent.Set();
                    _audioSource.DataAvailable -= AudioSourceDataAvailable;

                    if (!becauseOfException)
                    {
                        byte[] cmd = SInit(OprSpeakEnd, MoIPOprFlag);
                        Send(cmd);
                    }

                    if (_avstream != null)
                    {
                        _avstream.Close();
                        _avstream.Dispose();
                        _avstream = null;
                    }

                    if (_bTalking)
                    {
                        _bTalking    = false;
                        _talkDatalen = 0;
                    }
                    TalkStopped?.Invoke(this, EventArgs.Empty);
                }
            }
        }
Ejemplo n.º 3
0
        public void Stop()
        {
            if (_bTalking)
            {
                lock (_obj)
                {
                    if (_bTalking)
                    {
                        _bTalking = false;
                    }
                    TalkStopped?.Invoke(this, EventArgs.Empty);
                }
            }
            if (_audioSource != null)
            {
                _audioSource.Listening      = false;
                _audioSource.DataAvailable -= AudioSourceDataAvailable;
                _audioSource.DataAvailable -= _audioSource_DataAvailablePipe;
            }

            if (_waveOut != null)
            {
                _waveOut.Stop();
                _waveOut.Dispose();
            }
        }
Ejemplo n.º 4
0
 public void Start()
 {
     try
     {
         StartTalk();
     }
     catch (Exception ex)
     {
         Logger.LogExceptionToFile(ex, "TalkAxis");
         TalkStopped?.Invoke(this, EventArgs.Empty);
     }
 }
Ejemplo n.º 5
0
        public void Start()
        {
            try
            {
                var tcp = new TcpClient(_server, _port);
                lock (_obj)
                {
                    _avstream = tcp.GetStream();
                    _avstream.Write(System.Text.Encoding.ASCII.GetBytes(Hdr), 0, Hdr.Length);
                }

                StartTalk();
            }
            catch (Exception ex)
            {
                Logger.LogException(ex, "TalkiSpyServer");
                TalkStopped?.Invoke(this, EventArgs.Empty);
            }
        }
Ejemplo n.º 6
0
        public void Start()
        {
            try
            {
                var    tcp = new TcpClient(_server, _port);
                string hdr = "POST /cgi-bin/audio.cgi?action=postAudio&httptype=singlepart&channel=1 HTTP/1.1\r\nHost: " + _server + ":" + _port.ToString() + "\r\nContent-Type: Audio/G.711A\r\nContent-Length: 2147483637\r\n\r\n";
                lock (_obj)
                {
                    _avstream = tcp.GetStream();
                    _avstream.Write(System.Text.Encoding.UTF8.GetBytes(hdr), 0, hdr.Length);
                }

                StartTalk();
            }
            catch (Exception ex)
            {
                Logger.LogException(ex, "Talk (Amcrest)");
                TalkStopped?.Invoke(this, EventArgs.Empty);
            }
        }
Ejemplo n.º 7
0
        public void Start()
        {
            try
            {
                var    tcp = new TcpClient(_server.Host, _server.Port);
                string hdr = "POST /audioin.alaw HTTP/1.1\r\nHost: " + _server.Host + "\r\nContent-Length: 2147483637\r\n\r\n";
                lock (_obj)
                {
                    _avstream = tcp.GetStream();
                    _avstream.Write(System.Text.Encoding.UTF8.GetBytes(hdr), 0, hdr.Length);
                }

                StartTalk();
            }
            catch (Exception ex)
            {
                Logger.LogExceptionToFile(ex, "Talk (Android)");
                TalkStopped?.Invoke(this, EventArgs.Empty);
            }
        }
Ejemplo n.º 8
0
        private void CommsThread()
        {
            _needsencodeinit = true;
            try
            {
                var tcp = new TcpClient(_server, _port);
                _stream = tcp.GetStream();
            }
            catch (Exception ex)
            {
                Logger.LogException(ex, "TalkFoscam");
                return;
            }


            byte[] cmd = SInit(OprLoginReq, MoIPOprFlag);
            Send(cmd);

            DateTime dtref = DateTime.UtcNow;

            bool bConnected = false;

            try
            {
                while (true)
                {
                    if (_bTalking)
                    {
                        Thread.Sleep(100);
                    }
                    if (bConnected)
                    {
                        if (DateTime.UtcNow - dtref > TimeSpan.FromSeconds(120))
                        {
                            byte[] ka = SInit(OprKeepAlive, MoIPOprFlag);
                            Send(ka);
                            dtref = DateTime.UtcNow;
                        }
                    }
                    if (_stream.DataAvailable)
                    {
                        var data     = new byte[256];
                        int iReceive = _stream.Read(data, 0, data.Length);

                        if (iReceive > 5)
                        {
                            string r = "";
                            for (int j = 0; j < 5; j++)
                            {
                                r += (char)data[j];
                            }

                            if (r.StartsWith(MoIPOprFlag) && data.Length >= 23)
                            {
                                string code = (data[4] + data[5]).ToString(CultureInfo.InvariantCulture);

                                switch (code)
                                {
                                case "1":     //OPR_LOGIN_RESP
                                    //login required
                                    cmd = SInit(OprVerifyReq, MoIPOprFlag);
                                    cmd = AddNext(cmd, _username, 13);
                                    cmd = AddNext(cmd, _password, 13);
                                    Send(cmd);
                                    break;

                                case "3":     //OPR_VERIFY_RESP
                                    if (data[25] == 0x2)
                                    {
                                        bConnected = true;
                                    }
                                    else
                                    {
                                        Logger.LogError("Login to foscam camera failed", "TalkFoscam");
                                        _stopEvent.Set();
                                        break;
                                    }

                                    cmd = SInit(OprParamsFetchReq, MoIPOprFlag);
                                    Send(cmd);

                                    // start talking
                                    StartTalk();
                                    break;

                                case "12":     //ON_START_SPEAK_RESP
                                    int iDataLength = BitConverter.ToInt32(data, 15);
                                    if (iDataLength == 0)
                                    {
                                        Logger.LogError("Foscam start speak request failed", "TalkFoscam");
                                        _stopEvent.Set();
                                        break;
                                    }
                                    var resp = new byte[iDataLength];
                                    for (int j = 0; j < iDataLength; j++)
                                    {
                                        resp[j] = data[HeadLength + j];
                                    }

                                    int err = BitConverter.ToInt16(resp, 0);
                                    if (err != 0)
                                    {
                                        Logger.LogError("Foscam AV Port request failed", "TalkFoscam");
                                        _stopEvent.Set();
                                        break;
                                    }

                                    int dwAvConnId = BitConverter.ToInt32(resp, 2);

                                    var av = new TcpClient(_server, _port)
                                    {
                                        NoDelay = true
                                    };
                                    _avstream = av.GetStream();

                                    cmd = SInit(AvLoginReq, MoIPAvFlag);
                                    cmd = AddNext(cmd, dwAvConnId);
                                    SendAv(cmd);

                                    _bTalking    = true;
                                    _talkDatalen = 0;
                                    break;

                                case "255":     //OPR_KEEP_ALIVE
                                    break;
                                }
                            }
                        }
                    }
                    if (_stopEvent.WaitOne(0, true))
                    {
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.LogException(ex, "TalkFoscam");
            }
            TalkStopped?.Invoke(this, EventArgs.Empty);
        }