/// <summary>
        ///     Refresh audio playout devices list.
        /// </summary>
        private async Task RefreshAudioPlayoutDevicesAsync()
        {
            var selectedAudioPlayoutId = SelectedAudioPlayoutDevice?.Id;
            var oldAudioPlayoutDevices = AudioPlayoutDevices;

            AudioPlayoutDevices = await GetAudioPlayoutDevicesAsync();

            var preferredAudioPlayoutDevice = AudioPlayoutDevices.FirstOrDefault(c => c.IsPreferred);

            SelectedAudioPlayoutDevice = (selectedAudioPlayoutId != null
                ? AudioPlayoutDevices.FirstOrDefault(c => c.Id == selectedAudioPlayoutId)
                : preferredAudioPlayoutDevice) ?? AudioPlayoutDevices.First();
            if (!EtwStatsEnabled)
            {
                return;
            }
            var addedPlayoutDevicesInfo =
                AudioPlayoutDevices.Where(
                    playoutDevice => oldAudioPlayoutDevices.FirstOrDefault(x => x.Id == playoutDevice.Id) == null)
                .Aggregate("",
                           (current, playoutDevice) =>
                           string.Format("{0}id = {1} name = {2}\n", current, playoutDevice.Id, playoutDevice.Name));

            if (addedPlayoutDevicesInfo != "")
            {
                ETWEventLogger.Instance.LogEvent("Audio Playout Device(s) Added", addedPlayoutDevicesInfo,
                                                 DateTimeOffset.Now.ToUnixTimeMilliseconds().ToString());
            }

            var removedPlayoutDevicesInfo =
                oldAudioPlayoutDevices.Where(
                    playoutDevice => _audioPlayoutDevices.FirstOrDefault(x => x.Id == playoutDevice.Id) == null)
                .Aggregate("",
                           (current, playoutDevice) =>
                           string.Format("{0}id = {1} name = {2}\n", current, playoutDevice.Id, playoutDevice.Name));

            if (removedPlayoutDevicesInfo != "")
            {
                ETWEventLogger.Instance.LogEvent("Audio Playout Device(s) Removed", removedPlayoutDevicesInfo,
                                                 DateTimeOffset.Now.ToUnixTimeMilliseconds().ToString());
            }
        }
Esempio n. 2
0
 private void RefreshAudioPlayoutDevices(IList <MediaDevice> audioPlayoutDevices)
 {
     RunOnUiThread(() => {
         var selectedPlayoutDeviceId = SelectedAudioPlayoutDevice?.Id;
         SelectedAudioPlayoutDevice  = null;
         AudioPlayoutDevices.Clear();
         foreach (MediaDevice audioPlayoutDevice in audioPlayoutDevices)
         {
             AudioPlayoutDevices.Add(audioPlayoutDevice);
             if (audioPlayoutDevice.Id == selectedPlayoutDeviceId)
             {
                 SelectedAudioPlayoutDevice = audioPlayoutDevice;
             }
         }
         if (SelectedAudioPlayoutDevice == null)
         {
             SelectedAudioPlayoutDevice = AudioPlayoutDevices.FirstOrDefault();
         }
     });
 }
        private async void LoadSettings()
        {
            await _callChannel.InitializeRtcAsync();

            SignalingServerPort = int.Parse(SignalingSettings.SignalingServerPort);
            SignalingServerHost = SignalingSettings.SignalingServerHost;
            Domain             = RegistrationSettings.Domain;
            AppInsightsEnabled = SignalingSettings.AppInsightsEnabled;
            RegisteredUserName = RegistrationSettings.Name;

            if (_localSettings.Values[nameof(NtpServerIp)] != null)
            {
                NtpServerIp = (string)_localSettings.Values[nameof(NtpServerIp)];
            }

            Cameras        = new ObservableCollection <MediaDevice>((await _mediaSettings.GetVideoCaptureDevicesAsync()).Devices);
            SelectedCamera = Cameras.FirstOrDefault(c => c.IsPreferred) ?? Cameras.FirstOrDefault();

            Microphones = await GetAudioCaptureDevicesAsync();

            SelectedMicrophone = Microphones.FirstOrDefault(c => c.IsPreferred);
            if (SelectedMicrophone == null)
            {
                SelectedMicrophone = Microphones.First();
                await _mediaSettings.SetAudioDeviceAsync(SelectedMicrophone.Id == DefaultAudioDeviceId
                                                         ?null
                                                         : SelectedMicrophone);
            }

            AudioPlayoutDevices = await GetAudioPlayoutDevicesAsync();

            SelectedAudioPlayoutDevice = AudioPlayoutDevices.FirstOrDefault(c => c.IsPreferred);
            if (SelectedAudioPlayoutDevice == null)
            {
                SelectedAudioPlayoutDevice = AudioPlayoutDevices.First();
                await _mediaSettings.SetAudioPlayoutDeviceAsync(SelectedAudioPlayoutDevice.Id == DefaultAudioDeviceId
                                                                ?null
                                                                : SelectedAudioPlayoutDevice);
            }

            AudioCodecs = new ObservableCollection <CodecInfo>();
            var audioCodecList = await _mediaSettings.GetAudioCodecsAsync();

            foreach (var audioCodec in audioCodecList.Codecs)
            {
                if (!_incompatibleAudioCodecs.Contains(audioCodec.Name + audioCodec.ClockRate))
                {
                    AudioCodecs.Add(audioCodec);
                }
            }
            SelectedAudioCodec = null;
            if (_localSettings.Values[nameof(SelectedAudioCodec)] != null)
            {
                var audioCodecId = (int)_localSettings.Values[nameof(SelectedAudioCodec)];
                var audioCodec   = AudioCodecs.SingleOrDefault(a => a.Id.Equals(audioCodecId));
                if (audioCodec != null)
                {
                    SelectedAudioCodec = audioCodec;
                }
            }
            if (SelectedAudioCodec == null && AudioCodecs.Count > 0)
            {
                SelectedAudioCodec = AudioCodecs.First();
            }
            await _mediaSettings.SetAudioCodecAsync(SelectedAudioCodec);

            var videoCodecList = (await _mediaSettings.GetVideoCodecsAsync()).Codecs.OrderBy(codec =>
            {
                switch (codec.Name)
                {
                case "VP8":
                    return(1);

                case "VP9":
                    return(2);

                case "H264":
                    return(3);

                default:
                    return(99);
                }
            });

            VideoCodecs        = new ObservableCollection <CodecInfo>(videoCodecList);
            SelectedVideoCodec = null;
            if (_localSettings.Values[nameof(SelectedVideoCodec)] != null)
            {
                var videoCodecId = (int)_localSettings.Values[nameof(SelectedVideoCodec)];
                var videoCodec   = VideoCodecs.SingleOrDefault(v => v.Id.Equals(videoCodecId));
                if (videoCodec != null)
                {
                    SelectedVideoCodec = videoCodec;
                }
            }
            if (SelectedVideoCodec == null && VideoCodecs.Count > 0)
            {
                SelectedVideoCodec = VideoCodecs.First();
            }
            await _mediaSettings.SetVideoCodecAsync(SelectedVideoCodec);

            IceServers = new ObservableCollection <IceServerViewModel>(
                IceServerSettings.IceServers.Select(ices => new IceServerViewModel(ices)));

            if (_localSettings.Values[nameof(StatsServerPort)] != null)
            {
                StatsServerPort = (int)_localSettings.Values[nameof(StatsServerPort)];
            }
            else
            {
                StatsServerPort = 47005;
            }

            if (_localSettings.Values[nameof(StatsServerHost)] != null)
            {
                StatsServerHost = (string)_localSettings.Values[nameof(StatsServerHost)];
            }
            else
            {
                StatsServerHost = "localhost";
            }
        }