Пример #1
0
        public void StartAudioStream(
            [MidgeParameter("port", true)] int port,
            [MidgeParameter("sample_rate", false)] int?sampleRate    = null,
            [MidgeParameter("bit_depth", false)] int?bitDepth        = null,
            [MidgeParameter("channel", false)]  AudioChannel?channel = null)
        {
            if (sampleRate == null)
            {
                sampleRate = 44100;
            }

            if (bitDepth == null)
            {
                bitDepth = 16;
            }

            if (channel == null)
            {
                channel = AudioChannel.Mono;
            }

            var settings = new BroadcastSettings(sampleRate.Value, channel.Value, bitDepth.Value);


            IAudioSource audioSource = _audioStreamService.CreateSource(settings);

            IEncrypter encrypter = AesEncrypter.Create();

            BroadcastPoint point = new BroadcastPoint(audioSource, encrypter, Context.CurrentConnection.Ip, port);

            Context.AudioBroadcaster.Register(point);

            string base64Key = Convert.ToBase64String(encrypter.Key);
            string base64Iv  = Convert.ToBase64String(encrypter.IV);

            Response = new JObject(
                new JProperty("crypt_key", base64Key),
                new JProperty("crypt_iv", base64Iv),
                new JProperty("sample_rate", settings.SampleRate),
                new JProperty("channel", (int)settings.Channel),
                new JProperty("alg", "aes32"));
        }