private void Encoder_Data_Available(object sender, VideoEventArgs e) { frame++; framebytes = e.payload.outbytes; lastframe = e.payload.uncompressedFrame; lastframestride = e.payload.stride; lastframeheight = e.payload.height; lastframewidth = e.payload.width; if (isConnected) { VideoStream.Write(e.payload.result, 0, e.payload.outbytes); VideoStream.Flush(); VideoStream.WaitForPipeDrain(); video.ReturnWork(e.payload); } if (enableWriteToFile && binaryVideoWriter != null) { binaryVideoWriter.Write(e.payload.result, 0, e.payload.outbytes); binaryVideoWriter.Flush(); } }
private void Audio_RecordingStopped(object sender, StoppedEventArgs e) { if (isConnected) { AudioStream.Flush(); AudioStream.WaitForPipeDrain(); } if (enableWriteToFile && binaryAudioWriter != null) { binaryAudioWriter.Flush(); binaryAudioWriter.Close(); binaryAudioWriter.Dispose(); } }
/// <summary> /// Pipe the data from one graph to another graph. /// </summary> /// <param name="fromGraph">the graph to take data from</param> /// <param name="toGraph">the graph to take data to</param> public static void MigrateGraph(IGraph fromGraph, IGraph toGraph) { if (fromGraph == null) { throw new ArgumentNullException(nameof(fromGraph)); } if (toGraph == null) { throw new ArgumentNullException(nameof(toGraph)); } const int pipeSize = 1024; var outPipe = new AnonymousPipeServerStream(PipeDirection.Out, HandleInheritability.Inheritable, pipeSize); { using (var inPipe = new AnonymousPipeClientStream(PipeDirection.In, outPipe.ClientSafePipeHandle)) { Task.Factory.StartNew(() => { GraphMlWriter.OutputGraph(fromGraph, outPipe); outPipe.Flush(); outPipe.Close(); }); GraphMlReader.InputGraph(toGraph, inPipe); } } }
public static void ServerReadOnlyThrows() { using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.In)) { Assert.Throws <NotSupportedException>(() => server.Write(new byte[5], 0, 5)); Assert.Throws <NotSupportedException>(() => server.WriteByte(123)); Assert.Throws <NotSupportedException>(() => server.Flush()); Assert.Throws <NotSupportedException>(() => server.OutBufferSize); Assert.Throws <NotSupportedException>(() => server.WaitForPipeDrain()); } }
public static void ServerPInvokeChecks() { // calling every API related to server and client to detect any bad PInvokes using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.Out)) { Task clientTask = Task.Run(() => StartClient(PipeDirection.In, server.ClientSafePipeHandle)); Assert.False(server.CanRead); Assert.False(server.CanSeek); Assert.False(server.CanTimeout); Assert.True(server.CanWrite); Assert.False(string.IsNullOrWhiteSpace(server.GetClientHandleAsString())); Assert.False(server.IsAsync); Assert.True(server.IsConnected); Assert.Equal(0, server.OutBufferSize); Assert.Equal(PipeTransmissionMode.Byte, server.ReadMode); Assert.NotNull(server.SafePipeHandle); Assert.Equal(PipeTransmissionMode.Byte, server.TransmissionMode); server.Write(new byte[] { 123 }, 0, 1); server.WriteAsync(new byte[] { 124 }, 0, 1).Wait(); server.Flush(); server.WaitForPipeDrain(); clientTask.Wait(); server.DisposeLocalCopyOfClientHandle(); } using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.In)) { Task clientTask = Task.Run(() => StartClient(PipeDirection.Out, server.ClientSafePipeHandle)); Assert.Equal(4096, server.InBufferSize); byte[] readData = new byte[] { 0, 1 }; Assert.Equal(1, server.Read(readData, 0, 1)); Assert.Equal(1, server.ReadAsync(readData, 1, 1).Result); Assert.Equal(123, readData[0]); Assert.Equal(124, readData[1]); clientTask.Wait(); } }
public static void ServerPInvokeChecks() { // calling every API related to server and client to detect any bad PInvokes using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.Out)) { Task clientTask = StartClientAsync(PipeDirection.In, server.ClientSafePipeHandle); Console.WriteLine("server.CanRead = {0}", server.CanRead); Console.WriteLine("server.CanSeek = {0}", server.CanSeek); Console.WriteLine("server.CanTimeout = {0}", server.CanTimeout); Console.WriteLine("server.CanWrite = {0}", server.CanWrite); Console.WriteLine("server.GetClientHandleAsString() = {0}", server.GetClientHandleAsString()); Console.WriteLine("server.IsAsync = {0}", server.IsAsync); Console.WriteLine("server.IsConnected = {0}", server.IsConnected); Console.WriteLine("server.OutBufferSize = {0}", server.OutBufferSize); Console.WriteLine("server.ReadMode = {0}", server.ReadMode); Console.WriteLine("server.SafePipeHandle = {0}", server.SafePipeHandle); Console.WriteLine("server.TransmissionMode = {0}", server.TransmissionMode); server.Write(new byte[] { 123 }, 0, 1); server.WriteAsync(new byte[] { 124 }, 0, 1).Wait(); server.Flush(); Console.WriteLine("Waiting for Pipe Drain."); server.WaitForPipeDrain(); clientTask.Wait(); server.DisposeLocalCopyOfClientHandle(); } using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.In)) { Task clientTask = StartClientAsync(PipeDirection.Out, server.ClientSafePipeHandle); Console.WriteLine("server.InBufferSize = {0}", server.InBufferSize); byte[] readData = new byte[] { 0, 1 }; server.Read(readData, 0, 1); server.ReadAsync(readData, 1, 1).Wait(); Assert.Equal(123, readData[0]); Assert.Equal(124, readData[1]); } }
public static void Main() { AnonymousPipeServerStream pipeServer = new AnonymousPipeServerStream(PipeDirection.Out, HandleInheritability.Inheritable); var clientPipeHandle = pipeServer.GetClientHandleAsString(); Console.WriteLine(clientPipeHandle); Process pipeClient = new Process(); pipeClient.StartInfo.FileName = "client.exe"; pipeClient.StartInfo.Arguments = clientPipeHandle; pipeClient.StartInfo.UseShellExecute = false; pipeClient.Start(); pipeServer.DisposeLocalCopyOfClientHandle(); pipeServer.WriteByte(45); pipeServer.Flush(); Console.WriteLine("Press any key to quit"); Console.ReadKey(); pipeServer.Dispose(); }
public static async Task ServerPInvokeChecks() { // calling every API related to server and client to detect any bad PInvokes using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.Out, HandleInheritability.None, 4096)) { Task clientTask = Task.Run(() => StartClient(PipeDirection.In, server.ClientSafePipeHandle)); Assert.False(server.CanRead); Assert.False(server.CanSeek); Assert.False(server.CanTimeout); Assert.True(server.CanWrite); Assert.False(string.IsNullOrWhiteSpace(server.GetClientHandleAsString())); Assert.False(server.IsAsync); Assert.True(server.IsConnected); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { Assert.True(server.OutBufferSize > 0); } else { Assert.Throws <PlatformNotSupportedException>(() => server.OutBufferSize); } Assert.Equal(PipeTransmissionMode.Byte, server.ReadMode); Assert.NotNull(server.SafePipeHandle); Assert.Equal(PipeTransmissionMode.Byte, server.TransmissionMode); server.Write(new byte[] { 123 }, 0, 1); await server.WriteAsync(new byte[] { 124 }, 0, 1); server.Flush(); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { server.WaitForPipeDrain(); } else { Assert.Throws <PlatformNotSupportedException>(() => server.WaitForPipeDrain()); } await clientTask; server.DisposeLocalCopyOfClientHandle(); } using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.In)) { Task clientTask = Task.Run(() => StartClient(PipeDirection.Out, server.ClientSafePipeHandle)); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { Assert.Equal(4096, server.InBufferSize); } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { Assert.True(server.InBufferSize > 0); } else { Assert.Throws <PlatformNotSupportedException>(() => server.InBufferSize); } byte[] readData = new byte[] { 0, 1 }; Assert.Equal(1, server.Read(readData, 0, 1)); Assert.Equal(1, server.ReadAsync(readData, 1, 1).Result); Assert.Equal(123, readData[0]); Assert.Equal(124, readData[1]); await clientTask; } }
public static void ServerReadOnlyThrows() { using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.In)) { Assert.Throws<NotSupportedException>(() => server.Write(new byte[5], 0, 5)); Assert.Throws<NotSupportedException>(() => server.WriteByte(123)); Assert.Throws<NotSupportedException>(() => server.Flush()); Assert.Throws<NotSupportedException>(() => server.OutBufferSize); Assert.Throws<NotSupportedException>(() => server.WaitForPipeDrain()); Assert.Throws<NotSupportedException>(() => NotReachable(server.WriteAsync(new byte[5], 0, 5))); } }
private void flush(object state) { _outServer.Flush(); }