private static ByteBuffer EncodeBytesRead(RtmpContext context, BytesRead bytesRead) { ByteBuffer buffer = ByteBuffer.Allocate(4); buffer.PutInt(bytesRead.Bytes); return(buffer); }
static ByteBuffer EncodeBytesRead(RtmpContext context, BytesRead bytesRead) { ByteBuffer output = ByteBuffer.Allocate(4); output.PutInt(bytesRead.Bytes); return(output); }
protected void UpdateBytesRead() { long readBytes = this.ReadBytes; if (readBytes >= this._nextBytesRead) { BytesRead message = new BytesRead((int)readBytes); this.GetChannel(2).Write(message); this._nextBytesRead += this._bytesReadInterval; } }
/// <summary> /// Called when bytes are read. /// </summary> /// <param name="bytesMoved">int with the number of bytes</param> protected virtual void OnBytesRead(int bytesMoved) { if (bytesMoved != 0 && BytesRead != null) { long length = 0; long position = 0; if (_innerStream.CanSeek) { length = _innerStream.Length; position = _innerStream.Position; } var args = new ProgressStreamReport(bytesMoved, length, position, true); BytesRead?.Invoke(this, args); } }
internal static bool ReadFile_Hooked( IntPtr hFile, IntPtr lpBuffer, UInt32 nNumberOfBytesToRead, /*ref UInt32*/ IntPtr lpNumberOfBytesRead, /*ref OVERLAPPED*/ IntPtr lpOverlapped) { BytesRead br = new BytesRead(lpNumberOfBytesRead); return(new HookContext <bool>( func => ((ReadFile_Delegate)func)(hFile, lpBuffer, nNumberOfBytesToRead, lpNumberOfBytesRead, lpOverlapped), helper => FileEncryptionLayer.ReadFile(hFile, lpBuffer, nNumberOfBytesToRead, lpNumberOfBytesRead, lpOverlapped), errorCode => { SetLastError(unchecked ((uint)errorCode)); return false; }, HookLogging.DefaultLogging, "[hFile]: {0} [toRead]: {1} [Read]: {2}", hFile.ToString(), nNumberOfBytesToRead, br).Call()); }
/// <summary> /// This method supports the infrastructure and is not intended to be used directly from your code. /// </summary> /// <param name="connection"></param> /// <param name="channel"></param> /// <param name="source"></param> /// <param name="streamBytesRead"></param> protected void OnStreamBytesRead(RtmpConnection connection, RtmpChannel channel, RtmpHeader source, BytesRead streamBytesRead) { connection.ReceivedBytesRead(streamBytesRead.Bytes); }
static void Main(string[] args) { Device device = new Device("TUNTEST"); device.setMediaStatusAsConnected(); device.setTunMode("10.111.111.1", "255.0.0.0"); var mtu = device.getMTU(); logger.Debug("MTU: {0}", mtu); Tap = device.getStream(); var udpForwarder = new UDPForwarder(Tap); var tcpForwarder = new TCPForwarder(Tap); object state = new int(); WaitObject = new EventWaitHandle(false, EventResetMode.AutoReset); IAsyncResult res; while (true) { byte[] buf = new byte[mtu]; BytesRead = Tap.Read(buf, 0, buf.Length); if (BytesRead <= 0) { break; } logger.Debug("Read " + BytesRead.ToString()); try { var frame = IPFrame.Create(buf.Take(BytesRead).ToArray()); logger.Debug("Version: " + frame.Version); logger.Debug("Protocol Type: " + frame.Protocol); logger.Debug("Source Address: " + frame.SourceAddress.ToString()); logger.Debug("Dest Address: " + frame.DestinationAddress.ToString()); var parser = new ProtocolParser(); parser.ParseCompleteFrame(frame); if (frame.EncapsulatedFrame.FrameType == FrameTypes.UDP) { udpForwarder.forwardFrame(frame); } else if (frame.EncapsulatedFrame.FrameType == FrameTypes.TCP) { tcpForwarder.forwardFrame(frame); } } catch (Exception e) { logger.Error(e); } // // Reverse IPv4 addresses and send back to tun // //for (int i = 0; i< 4; ++i) //{ // byte tmp = buf[12+i]; buf[12+i] = buf[16+i]; buf[16+i] = tmp; //} //res2 = Tap.BeginWrite(buf, 0, BytesRead, ar => { // Tap.EndWrite(ar); // WaitObject2.Set(); //}, state2); //WaitObject2.WaitOne(); } }
public void Report(int bytesRead) { BytesRead?.Invoke(bytesRead); }
private void OnBytesRead(IntEventArgs e) { BytesRead?.Invoke(this, e); }
public void PushMessage(IPipe pipe, IMessage message) { if (message is ResetMessage) { _timeStamper.Reset(); } else if (message is StatusMessage) { StatusMessage statusMsg = message as StatusMessage; _data.SendStatus(statusMsg.body as StatusASO); } else if (message is RtmpMessage) { // Make sure chunk size has been sent if (!_chunkSizeSent) { SendChunkSize(); } RtmpMessage rtmpMsg = message as RtmpMessage; IRtmpEvent msg = rtmpMsg.body; int eventTime = msg.Timestamp; #if !SILVERLIGHT if (log.IsDebugEnabled) { log.Debug(string.Format("Message timestamp: {0}", eventTime)); } #endif if (eventTime < 0) { #if !SILVERLIGHT if (log.IsDebugEnabled) { log.Debug(string.Format("Message has negative timestamp: {0}", eventTime)); } #endif return; } byte dataType = msg.DataType; // Create a new header for the consumer RtmpHeader header = _timeStamper.GetTimeStamp(dataType, eventTime); switch (msg.DataType) { case Constants.TypeStreamMetadata: Notify notify = new Notify((msg as Notify).Data); notify.Header = header; notify.Timestamp = header.Timer; _data.Write(notify); break; case Constants.TypeFlexStreamEnd: // TODO: okay to send this also to AMF0 clients? FlexStreamSend send = new FlexStreamSend((msg as Notify).Data); send.Header = header; send.Timestamp = header.Timer; _data.Write(send); break; case Constants.TypeVideoData: VideoData videoData = new VideoData((msg as VideoData).Data); videoData.Header = header; videoData.Timestamp = header.Timer; _video.Write(videoData); break; case Constants.TypeAudioData: AudioData audioData = new AudioData((msg as AudioData).Data); audioData.Header = header; audioData.Timestamp = header.Timer; _audio.Write(audioData); break; case Constants.TypePing: Ping ping = new Ping((msg as Ping).PingType, (msg as Ping).Value2, (msg as Ping).Value3, (msg as Ping).Value4); ping.Header = header; _connection.Ping(ping); break; case Constants.TypeBytesRead: BytesRead bytesRead = new BytesRead((msg as BytesRead).Bytes); bytesRead.Header = header; bytesRead.Timestamp = header.Timer; _connection.GetChannel((byte)2).Write(bytesRead); break; default: _data.Write(msg); break; } } }
static void ListenTest(GpioPin pin) { PinPulse(pin, 2000); using (Socket soc = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IPv4)) { IPEndPoint ep = new IPEndPoint(IPAddress.Any, 6501); soc.Bind(ep); soc.Listen(1); while (true) { Socket client = null; int BytesRead; try { Console.WriteLine(DateTime.UtcNow.ToString() + "Accept client"); client = soc.Accept(); Console.WriteLine(DateTime.UtcNow.ToString() + "Accepted"); PinPulse(pin, 500); client.ReceiveTimeout = 10000; NetworkStream stream = new NetworkStream(client); byte[] buffer = new byte[100]; // Echo back everything we receive and toggle Led while ((BytesRead = stream.Read(buffer, 0, buffer.Length)) != 0) { stream.Write(buffer, 0, BytesRead); Console.WriteLine(DateTime.UtcNow.ToString() + "Read/Write " + BytesRead.ToString()); pin.Toggle(); } Console.WriteLine(DateTime.UtcNow.ToString() + "connection ending"); } catch (Exception ex) { Console.WriteLine(DateTime.UtcNow.ToString() + "Ex " + ex.Message); }; if (client != null) { client.Close(); } break; } } }
private void RaiseBytesReadEvent(int byteCount) { BytesRead?.Invoke(byteCount); }
public void PushMessage(IPipe pipe, IMessage message) { if (message is ResetMessage) { this._streamTracker.Reset(); } else if (message is StatusMessage) { StatusMessage message2 = message as StatusMessage; this._data.SendStatus(message2.body as StatusASO); } else if (message is RtmpMessage) { RtmpMessage message3 = message as RtmpMessage; IRtmpEvent body = message3.body; RtmpHeader header = new RtmpHeader(); int num = this._streamTracker.Add(body); if (num < 0) { log.Warn("Skipping message with negative timestamp."); } else { header.IsTimerRelative = this._streamTracker.IsRelative; header.Timer = num; switch (body.DataType) { case 3: { BytesRead read = new BytesRead((body as BytesRead).Bytes); header.IsTimerRelative = false; header.Timer = 0; read.Header = header; read.Timestamp = header.Timer; this._connection.GetChannel(2).Write(read); return; } case 4: { Ping ping = new Ping((body as Ping).Value1, (body as Ping).Value2, (body as Ping).Value3, (body as Ping).Value4); header.IsTimerRelative = false; header.Timer = 0; ping.Header = header; ping.Timestamp = header.Timer; this._connection.Ping(ping); return; } case 8: { AudioData data2 = new AudioData((body as AudioData).Data) { Header = header, Timestamp = header.Timer }; this._audio.Write(data2); return; } case 9: { VideoData data = new VideoData((body as VideoData).Data) { Header = header, Timestamp = header.Timer }; this._video.Write(data); return; } case 15: { FlexStreamSend send = new FlexStreamSend((body as Notify).Data) { Header = header, Timestamp = header.Timer }; this._data.Write(send); return; } case 0x12: { Notify notify = new Notify((body as Notify).Data) { Header = header, Timestamp = header.Timer }; this._data.Write(notify); return; } } this._data.Write(body); } } }