public IStreamSender Send(StreamPacket packet) { if (!IsRunning) throw new InvalidProgramException("This sender has not been started."); _queue.Enqueue(packet); _waiter.Set(); return this; }
public IStreamSender Send(StreamPacket packet) { if (!IsRunning) { throw new InvalidProgramException("This sender has not been started."); } _queue.Enqueue(packet); _waiter.Set(); return(this); }
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); } } } } }