コード例 #1
0
        /// <summary>
        /// On Win10 in a background task, WebRTC initialization has to be done
        /// when we have access to the resources.  That's inside an active
        /// voip call.
        /// This function must be called after VoipCoordinator.StartVoipTask()
        /// </summary>
        /// <returns></returns>
        public void InitializeRTC()
        {
            if (Media == null)
            {
                WebRTC.Initialize(_dispatcher);
                Media = WebRTCMedia.CreateMedia();
                WebRTCMedia.SetDisplayOrientation(_displayOrientation);

                // Uncomment the following line to enable WebRTC logging.
                // Logs are:
                //  - Saved to local storage. Log folder location can be obtained using WebRTC.LogFolder()
                //  - Sent over network if client is connected to TCP port 47003
                //WebRTC.EnableLogging(LogLevel.LOGLVL_INFO);
            }

            if (DisplayOrientations.None != _displayOrientation)
            {
                WebRTCMedia.SetDisplayOrientation(_displayOrientation);
            }

            string videoDeviceId = string.Empty;

            if (_localSettings.Values.ContainsKey(MediaSettingsIds.VideoDeviceSettings))
            {
                videoDeviceId = (string)_localSettings.Values[MediaSettingsIds.VideoDeviceSettings];
            }
            var videoDevices        = Media.GetVideoCaptureDevices();
            var selectedVideoDevice = videoDevices.FirstOrDefault(d => d.Id.Equals(videoDeviceId));

            selectedVideoDevice = selectedVideoDevice ?? videoDevices.FirstOrDefault();
            if (selectedVideoDevice != null)
            {
                Media.SelectVideoDevice(selectedVideoDevice);
            }

            string audioDeviceId = string.Empty;

            if (_localSettings.Values.ContainsKey(MediaSettingsIds.AudioDeviceSettings))
            {
                audioDeviceId = (string)_localSettings.Values[MediaSettingsIds.AudioDeviceSettings];
            }
            var audioDevices        = Media.GetAudioCaptureDevices();
            var selectedAudioDevice = audioDevices.FirstOrDefault(d => d.Id.Equals(audioDeviceId));

            selectedAudioDevice = selectedAudioDevice ?? audioDevices.FirstOrDefault();
            if (selectedAudioDevice != null)
            {
                Media.SelectAudioDevice(selectedAudioDevice);
            }

            string audioPlayoutDeviceId = string.Empty;

            if (_localSettings.Values.ContainsKey(MediaSettingsIds.AudioPlayoutDeviceSettings))
            {
                audioPlayoutDeviceId = (string)_localSettings.Values[MediaSettingsIds.AudioPlayoutDeviceSettings];
            }
            var audioPlayoutDevices        = Media.GetAudioPlayoutDevices();
            var selectedAudioPlayoutDevice = audioPlayoutDevices.FirstOrDefault(d => d.Id.Equals(audioPlayoutDeviceId));

            selectedAudioPlayoutDevice = selectedAudioPlayoutDevice ?? audioPlayoutDevices.FirstOrDefault();
            if (selectedAudioPlayoutDevice != null)
            {
                Media.SelectAudioPlayoutDevice(selectedAudioPlayoutDevice);
            }

            int videoCodecId = int.MinValue;

            if (_localSettings.Values.ContainsKey(MediaSettingsIds.VideoCodecSettings))
            {
                videoCodecId = (int)_localSettings.Values[MediaSettingsIds.VideoCodecSettings];
            }
            var videoCodecs        = WebRTC.GetVideoCodecs();
            var selectedVideoCodec = videoCodecs.FirstOrDefault(c => c.Id.Equals(videoCodecId));

            SetVideoCodec(DtoExtensions.ToDto(selectedVideoCodec ?? videoCodecs.FirstOrDefault()));

            int audioCodecId = int.MinValue;

            if (_localSettings.Values.ContainsKey(MediaSettingsIds.AudioCodecSettings))
            {
                audioCodecId = (int)_localSettings.Values[MediaSettingsIds.AudioCodecSettings];
            }
            var audioCodecs        = WebRTC.GetAudioCodecs();
            var selectedAudioCodec = audioCodecs.FirstOrDefault(c => c.Id.Equals(audioCodecId));

            SetAudioCodec(DtoExtensions.ToDto(selectedAudioCodec ?? audioCodecs.FirstOrDefault()));

            if (_localSettings.Values.ContainsKey(MediaSettingsIds.PreferredVideoCaptureWidth) &&
                _localSettings.Values.ContainsKey(MediaSettingsIds.PreferredVideoCaptureHeight) &&
                _localSettings.Values.ContainsKey(MediaSettingsIds.PreferredVideoCaptureFrameRate))
            {
                WebRTC.SetPreferredVideoCaptureFormat((int)_localSettings.Values[MediaSettingsIds.PreferredVideoCaptureWidth],
                                                      (int)_localSettings.Values[MediaSettingsIds.PreferredVideoCaptureHeight],
                                                      (int)_localSettings.Values[MediaSettingsIds.PreferredVideoCaptureFrameRate]);
            }

            ResolutionHelper.ResolutionChanged += (id, width, height) =>
            {
                if (id == LocalMediaStreamId)
                {
                    LocalVideoRenderer.ResolutionChanged(width, height);
                }
                else if (id == PeerMediaStreamId)
                {
                    RemoteVideoRenderer.ResolutionChanged(width, height);
                }
            };

            FrameCounterHelper.FramesPerSecondChanged += (id, frameRate) =>
            {
                if (id == LocalMediaStreamId)
                {
                    LocalVideo_FrameRateUpdate(frameRate);
                }
                else if (id == PeerMediaStreamId)
                {
                    RemoteVideo_FrameRateUpdate(frameRate);
                }
            };
        }
コード例 #2
0
 public void ReleaseDevices()
 {
     WebRTCMedia.OnAppSuspending();
 }