コード例 #1
0
ファイル: UdpStreamSender.cs プロジェクト: sclcwwl/Gimela
        public IStreamSender Send(StreamPacket packet)
        {
            if (!IsRunning)
            throw new InvalidProgramException("This sender has not been started.");

              _queue.Enqueue(packet);
              _waiter.Set();

              return this;
        }
コード例 #2
0
        public IStreamSender Send(StreamPacket packet)
        {
            if (!IsRunning)
            {
                throw new InvalidProgramException("This sender has not been started.");
            }

            _queue.Enqueue(packet);
            _waiter.Set();

            return(this);
        }
コード例 #3
0
        private void WorkThread()
        {
            while (IsRunning)
            {
                _waiter.WaitOne();
                _waiter.Reset();

                while (_queue.Count > 0)
                {
                    StreamPacket packet = null;
                    if (_queue.TryDequeue(out packet))
                    {
                        RtpPacket rtpPacket = RtpPacket.FromImage(
                            RtpPayloadType.JPEG,
                            packet.SequenceNumber,
                            (long)Epoch.GetDateTimeTotalMillisecondsByYesterday(packet.Timestamp),
                            packet.Frame);

                        byte[] datagram = rtpPacket.ToArray(); // max UDP packet length limited to 65,535 bytes
                        packet.Frame.Dispose();

                        // split udp packet to many packets for reduce the size to 65507 limit by underlying IPv4 protocol
                        ICollection <UdpPacket> udpPackets = UdpPacketSplitter.Split(packet.SequenceNumber, datagram, 65507 - UdpPacket.HeaderSize);
                        foreach (var udpPacket in udpPackets)
                        {
                            byte[] udpPacketDatagram = udpPacket.ToArray();
                            // async sending
                            _udpClient.BeginSend(
                                udpPacketDatagram, udpPacketDatagram.Length,
                                packet.Destination.Address,
                                packet.Destination.Port,
                                SendCompleted, _udpClient);
                        }
                    }
                }
            }
        }