Ejemplo n.º 1
0
        private async Task StopAudioStream()
        {
            if (AudioSource != null)
            {
                DoStopAudioStream();
                await AudioSource.Stop();

                AudioSource.Destroy();
                AudioSource = null;
            }
            if (AudioDepacketizer != null)
            {
                AudioDepacketizer.Destroy();
                AudioDepacketizer = null;
            }
            if (AudioDecoder != null)
            {
                AudioDecoder.Destroy();
                AudioDecoder = null;
            }
            if (ResetAudioPipe != null)
            {
                ResetAudioPipe.Destroy();
                ResetAudioPipe = null;
            }
            if (AudioConverter != null)
            {
                AudioConverter.Destroy();
                AudioConverter = null;
            }
            if (AudioEncoder != null)
            {
                AudioEncoder.Destroy();
                AudioEncoder = null;
            }
            if (AudioPacketizer != null)
            {
                AudioPacketizer.Destroy();
                AudioPacketizer = null;
            }
        }
Ejemplo n.º 2
0
 private Task StopAudioStream()
 {
     if (AudioDepacketizer != null)
     {
         AudioDepacketizer.Destroy();
         AudioDepacketizer = null;
     }
     if (AudioDecoder != null)
     {
         AudioDecoder.Destroy();
         AudioDecoder = null;
     }
     if (AudioConverter != null)
     {
         AudioConverter.Destroy();
         AudioConverter = null;
     }
     if (ResetAudioPipe != null)
     {
         ResetAudioPipe.Destroy();
         ResetAudioPipe = null;
     }
     if (AudioEncoder != null)
     {
         AudioEncoder.Destroy();
         AudioEncoder = null;
     }
     if (AudioPacketizer != null)
     {
         AudioPacketizer.Destroy();
         AudioPacketizer = null;
     }
     if (AudioSink != null)
     {
         AudioSink.Destroy();
         AudioSink = null;
     }
     return(Task.CompletedTask);
 }
Ejemplo n.º 3
0
        private Task StartAudioStream()
        {
            if (AudioStream != null)
            {
                var outputFormat = AudioStream.OutputFormat;
                if (outputFormat == null)
                {
                    throw new NegotiateException("Could not negotiate an audio codec with the server.");
                }
                AudioFormat = outputFormat.Clone();

                AudioSink = CreateAudioSink();

                var currentInput = (IAudioInput)AudioSink;

                if (Options.AudioTranscode)
                {
                    if (currentInput.InputFormat.IsPacketized)
                    {
                        AudioPacketizer = currentInput.InputFormat.ToEncoding().CreatePacketizer();

                        currentInput.AddInput(AudioPacketizer);
                        currentInput = AudioPacketizer;
                    }

                    if (currentInput.InputFormat.IsCompressed)
                    {
                        AudioEncoder = currentInput.InputFormat.ToEncoding().CreateEncoder();

                        currentInput.AddInput(AudioEncoder);
                        currentInput = AudioEncoder;
                    }

                    ResetAudioPipe = new ResetAudioPipe(currentInput.InputFormat);
                    currentInput.AddInput(ResetAudioPipe);
                    currentInput = ResetAudioPipe;
                }

                if (!currentInput.InputFormat.IsCompressed)
                {
                    AudioDecoder = AudioFormat.ToEncoding().CreateDecoder();

                    AudioConverter = new SoundConverter(AudioDecoder.OutputConfig, currentInput.Config);

                    var frameDuration = GetAudioFrameDuration();
                    if (frameDuration != -1)
                    {
                        AudioReframer = new SoundReframer(currentInput.Config, frameDuration);
                        currentInput.AddInput(AudioReframer);
                        currentInput = AudioReframer;
                    }

                    currentInput.AddInput(AudioConverter);
                    currentInput = AudioConverter;

                    currentInput.AddInput(AudioDecoder);
                    currentInput = AudioDecoder;
                }

                if (!currentInput.InputFormat.IsPacketized)
                {
                    AudioDepacketizer = AudioFormat.ToEncoding().CreateDepacketizer();

                    currentInput.AddInput(AudioDepacketizer);
                    currentInput = AudioDepacketizer;
                }

                var streamOutput = null as AudioPipe;
                foreach (var output in AudioStream.Outputs)
                {
                    if (output.InputFormat.IsEquivalent(AudioFormat, true))
                    {
                        streamOutput = output as AudioPipe;
                    }
                }

                currentInput.AddInput(streamOutput);

                if (AudioEncoder != null && !AudioEncoder.OutputFormat.IsFixedBitrate && Options.AudioBitrate.HasValue)
                {
                    AudioEncoder.TargetBitrate = Options.AudioBitrate.Value;
                }
            }
            return(Task.CompletedTask);
        }
Ejemplo n.º 4
0
        private async Task StartAudioStream()
        {
            if (AudioStream != null)
            {
                var inputFormat = AudioStream.InputFormat;
                if (inputFormat == null)
                {
                    throw new NegotiateException("Could not negotiate an audio codec with the server.");
                }
                AudioFormat = inputFormat.Clone();

                AudioSource = CreateAudioSource();
                AudioSource.SynchronizationSource = AudioSynchronizationSource;

                var currentOutput = (IAudioOutput)AudioSource;

                if (Options.AudioTranscode)
                {
                    if (currentOutput.OutputFormat.IsPacketized)
                    {
                        AudioDepacketizer = currentOutput.OutputFormat.ToEncoding().CreateDepacketizer();

                        currentOutput.AddOutput(AudioDepacketizer);
                        currentOutput = AudioDepacketizer;
                    }

                    if (currentOutput.OutputFormat.IsCompressed)
                    {
                        AudioDecoder = currentOutput.OutputFormat.ToEncoding().CreateDecoder();

                        currentOutput.AddOutput(AudioDecoder);
                        currentOutput = AudioDecoder;
                    }

                    ResetAudioPipe = new ResetAudioPipe(currentOutput.OutputFormat);
                    currentOutput.AddOutput(ResetAudioPipe);
                    currentOutput = ResetAudioPipe;
                }

                if (!currentOutput.OutputFormat.IsCompressed)
                {
                    AudioEncoder = AudioFormat.ToEncoding().CreateEncoder();

                    AudioConverter = new SoundConverter(currentOutput.Config, AudioEncoder.InputConfig);

                    currentOutput.AddOutput(AudioConverter);
                    currentOutput = AudioConverter;

                    currentOutput.AddOutput(AudioEncoder);
                    currentOutput = AudioEncoder;
                }

                if (!currentOutput.OutputFormat.IsPacketized)
                {
                    AudioPacketizer = AudioFormat.ToEncoding().CreatePacketizer();

                    currentOutput.AddOutput(AudioPacketizer);
                    currentOutput = AudioPacketizer;
                }

                var streamInput = null as AudioPipe;
                foreach (var input in AudioStream.Inputs)
                {
                    if (input.OutputFormat.IsEquivalent(AudioFormat, true))
                    {
                        streamInput = input as AudioPipe;
                    }
                }

                currentOutput.AddOutput(streamInput);

                if (AudioEncoder != null && !AudioEncoder.OutputFormat.IsFixedBitrate && Options.AudioBitrate.HasValue)
                {
                    AudioEncoder.TargetBitrate = Options.AudioBitrate.Value;
                }

                await AudioSource.Start();

                DoStartAudioStream();
            }
        }