Пример #1
0
        private async Task StopVideoStream()
        {
            if (VideoSource != null)
            {
                DoStopVideoStream();
                await VideoSource.Stop();

                VideoSource.Destroy();
                VideoSource = null;
            }
            if (VideoDepacketizer != null)
            {
                VideoDepacketizer.Destroy();
                VideoDepacketizer = null;
            }
            if (VideoDecoder != null)
            {
                VideoDecoder.Destroy();
                VideoDecoder = null;
            }
            if (ResetVideoPipe != null)
            {
                ResetVideoPipe.Destroy();
                ResetVideoPipe = null;
            }
            if (VideoConverter != null)
            {
                VideoConverter.Destroy();
                VideoConverter = null;
            }
            if (VideoEncoder != null)
            {
                VideoEncoder.Destroy();
                VideoEncoder = null;
            }
            if (VideoPacketizer != null)
            {
                VideoPacketizer.Destroy();
                VideoPacketizer = null;
            }
        }
Пример #2
0
 private Task StopVideoStream()
 {
     if (VideoDepacketizer != null)
     {
         VideoDepacketizer.Destroy();
         VideoDepacketizer = null;
     }
     if (VideoDecoder != null)
     {
         VideoDecoder.Destroy();
         VideoDecoder = null;
     }
     if (VideoConverter != null)
     {
         VideoConverter.Destroy();
         VideoConverter = null;
     }
     if (ResetVideoPipe != null)
     {
         ResetVideoPipe.Destroy();
         ResetVideoPipe = null;
     }
     if (VideoEncoder != null)
     {
         VideoEncoder.Destroy();
         VideoEncoder = null;
     }
     if (VideoPacketizer != null)
     {
         VideoPacketizer.Destroy();
         VideoPacketizer = null;
     }
     if (VideoSink != null)
     {
         VideoSink.Destroy();
         VideoSink = null;
     }
     return(Task.CompletedTask);
 }
Пример #3
0
        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);
        }
Пример #4
0
        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();
            }
        }