protected override NullVideoSink CreateVideoSink() { var sink = new NullVideoSink(VideoFormat); sink.OnProcessFrame += (frame) => { Console.WriteLine(ProcessVideoLog(Options.VideoLog, frame, VideoFormat.ToEncoding(), RemoteConnectionInfo)); }; return(sink); }
protected override NullVideoSink CreateVideoSink() { var socket = GetSocket(TransportAddress.IsIPv6(Options.VideoIPAddress)); var remoteEndPoint = new IPEndPoint(IPAddress.Parse(Options.VideoIPAddress), Options.VideoPort); var sink = VideoFormat.ToEncoding().CreateNullSink(true); sink.OnProcessFrame += (frame) => { var buffer = frame.LastBuffer; if (buffer != null) { var dataBuffer = buffer.DataBuffer; if (dataBuffer != null) { socket.SendTo(dataBuffer.Data, dataBuffer.Index, dataBuffer.Length, SocketFlags.None, remoteEndPoint); } } }; return(sink); }
private Task StartVideoStream() { if (VideoStream != null) { var outputFormat = VideoStream.OutputFormat; if (outputFormat == null) { throw new NegotiateException("Could not negotiate an video codec with the server."); } VideoFormat = outputFormat.Clone(); VideoSink = CreateVideoSink(); var currentInput = (IVideoInput)VideoSink; if (Options.VideoTranscode) { if (currentInput.InputFormat.IsPacketized) { VideoPacketizer = currentInput.InputFormat.ToEncoding().CreatePacketizer(); currentInput.AddInput(VideoPacketizer); currentInput = VideoPacketizer; } if (currentInput.InputFormat.IsCompressed) { VideoEncoder = currentInput.InputFormat.ToEncoding().CreateEncoder(); currentInput.AddInput(VideoEncoder); currentInput = VideoEncoder; } ResetVideoPipe = new ResetVideoPipe(currentInput.InputFormat); currentInput.AddInput(ResetVideoPipe); currentInput = ResetVideoPipe; } if (!currentInput.InputFormat.IsCompressed) { VideoDecoder = VideoFormat.ToEncoding().CreateDecoder(); VideoConverter = new ImageConverter(VideoDecoder.OutputFormat, currentInput.InputFormat); currentInput.AddInput(VideoConverter); currentInput = VideoConverter; currentInput.AddInput(VideoDecoder); currentInput = VideoDecoder; } if (!currentInput.InputFormat.IsPacketized) { VideoDepacketizer = VideoFormat.ToEncoding().CreateDepacketizer(); currentInput.AddInput(VideoDepacketizer); currentInput = VideoDepacketizer; } var streamOutput = null as VideoPipe; foreach (var output in VideoStream.Outputs) { if (output.InputFormat.IsEquivalent(VideoFormat, true)) { streamOutput = output as VideoPipe; } } currentInput.AddInput(streamOutput); if (VideoEncoder != null && !VideoEncoder.OutputFormat.IsFixedBitrate && Options.VideoBitrate.HasValue) { VideoEncoder.TargetBitrate = Options.VideoBitrate.Value; } } return(Task.CompletedTask); }
private async Task StartVideoStream() { if (VideoStream != null) { var inputFormat = VideoStream.InputFormat; if (inputFormat == null) { throw new NegotiateException("Could not negotiate a video codec with the server."); } VideoFormat = inputFormat.Clone(); VideoSource = CreateVideoSource(); VideoSource.SynchronizationSource = VideoSynchronizationSource; var currentOutput = (IVideoOutput)VideoSource; if (Options.VideoTranscode) { if (currentOutput.OutputFormat.IsPacketized) { VideoDepacketizer = currentOutput.OutputFormat.ToEncoding().CreateDepacketizer(); currentOutput.AddOutput(VideoDepacketizer); currentOutput = VideoDepacketizer; } if (currentOutput.OutputFormat.IsCompressed) { VideoDecoder = currentOutput.OutputFormat.ToEncoding().CreateDecoder(); currentOutput.AddOutput(VideoDecoder); currentOutput = VideoDecoder; } ResetVideoPipe = new ResetVideoPipe(currentOutput.OutputFormat); currentOutput.AddOutput(ResetVideoPipe); currentOutput = ResetVideoPipe; } if (!currentOutput.OutputFormat.IsCompressed) { VideoEncoder = VideoFormat.ToEncoding().CreateEncoder(); VideoConverter = new ImageConverter(currentOutput.OutputFormat, VideoEncoder.InputFormat); currentOutput.AddOutput(VideoConverter); currentOutput = VideoConverter; currentOutput.AddOutput(VideoEncoder); currentOutput = VideoEncoder; } if (!currentOutput.OutputFormat.IsPacketized) { VideoPacketizer = VideoFormat.ToEncoding().CreatePacketizer(); currentOutput.AddOutput(VideoPacketizer); currentOutput = VideoPacketizer; } var streamInput = null as VideoPipe; foreach (var input in VideoStream.Inputs) { if (input.OutputFormat.IsEquivalent(VideoFormat, true)) { streamInput = input as VideoPipe; } } currentOutput.AddOutput(streamInput); if (VideoEncoder != null && !VideoEncoder.OutputFormat.IsFixedBitrate && Options.VideoBitrate.HasValue) { VideoEncoder.TargetBitrate = Options.VideoBitrate.Value; } await VideoSource.Start(); DoStartVideoStream(); } }