예제 #1
0
        private void SendPacketAsync()
        {
            try
            {
                byte[] packet = { };

                if (!outboundPacketsQueue.TryDequeue(out packet))
                {
                    return;
                }
                ResetWriteTimer();
                isWriting = true;
                var state = new System.Object();
                sslStream?.BeginWrite(packet, 0, packet.Length, OnSendMessage, state);
            }
            catch (SocketException exception)
            {
                // Log as regular message because servers do shut down sometimes
                Debug.LogError($"SendPacketAsync: stream.Write SocketException error code; {exception.ErrorCode}, exception: {exception}");
                throw exception;
            }
            catch (Exception exception)
            {
                // Log as regular message because servers do shut down sometimes
                Debug.LogError($"SendPacketAsync: stream.Write exception: {exception}");
                throw exception;
            }
        }
예제 #2
0
        /// <summary>
        /// Thread processing the audio queue
        /// </summary>
        protected virtual void doWork()
        {
            if (udp != null)
            {
                udp.Connect(ip);
                ip.Port    = udpPort;
                ip.Address = udpIPAddress;

                logger.Info(string.Format("UDP connected to: {0}:{1}", ip.Address, ip.Port));
            }
            samplesQ = new SafeQueue <byte[]>((uint)Thread.CurrentThread.ManagedThreadId); // q ident

            logger.Debug(string.Format("Starting wavOut {0}, entering endless loop", threadName));

            play(); //virtual

            while (true)
            {
                eWaitHandle handle = (eWaitHandle)WaitHandle.WaitAny(eventHandles);
                if (handle == eWaitHandle.WAIT_TERMINATE)
                {
                    break;
                }
                //else if (handle == eWaitHandle.WAIT_QUEUE) //no other possibilty left

                byte[] buf;
                while (samplesQ.TryDequeue(out buf))
                {
                    try
                    {
                        {
                            int count = buf.Length;
                            //Possible UDP Consumers
                            //http://gqrx.dk/doc/streaming-audio-over-udp
                            //nc -l -u -p 8765 | aplay -r 48000 -f S16_LE -t raw -c 1
                            //vlc --demux=rawaud --rawaud-channels=2 --rawaud-samplerate=48000 udp://@:8765
                            if (udpFlag)
                            {
                                udp.Send(buf, buf.Length);
                            }

                            if (muted)
                            {
                                Array.Clear(buf, 0, buf.Length);
                            }
                            writeSamples(buf);
                        }
                    }
                    catch (Exception ex)
                    {
                        logger.Exception(ex);
                    }
                }
                qEvent.Reset();
            }
            Dispose();
            logger.Debug(string.Format("Terminating thread {0} ... ", threadName));
        }
예제 #3
0
 /// <summary>
 /// Gets the next Flat Buffer packet received from the game server.
 /// </summary>
 /// <param name="data">The received Flat Buffer formatted packet.</param>
 /// <returns><c>true</c> if there was a packet present</returns>
 public bool GetNextPacket(out byte[] data)
 {
     return(receivePacketsQueue.TryDequeue(out data));
 }