Esempio n. 1
0
        public static IMediaStreamTrack Create(MediaStreamTrackKind mediaStreamTrackKind, string id,
                                               MediaTrackConstraints constraints = null)
        {
            Webrtc.MediaStreamTrack nativeMediaStreamTrack = null;
            Webrtc.MediaSource      nativeMediaSource      = null;

            switch (mediaStreamTrackKind)
            {
            case MediaStreamTrackKind.Audio:
                var nativeAudioSource = WebRTCme.WebRtc.NativePeerConnectionFactory.CreateAudioSource(
                    (constraints ?? new MediaTrackConstraints
                {
                    EchoCancellation = new ConstrainBoolean {
                        Value = false
                    },
                    AutoGainControl = new ConstrainBoolean {
                        Value = false
                    },
                    NoiseSuppression = new ConstrainBoolean {
                        Value = false
                    }
                }).ToNative());
                nativeMediaSource      = nativeAudioSource;
                nativeMediaStreamTrack = WebRTCme.WebRtc.NativePeerConnectionFactory
                                         .CreateAudioTrack(id, nativeAudioSource);
                break;

            case MediaStreamTrackKind.Video:
                var nativeVideoSource = WebRTCme.WebRtc.NativePeerConnectionFactory.CreateVideoSource(false);
                nativeMediaSource      = nativeVideoSource;
                nativeMediaStreamTrack = WebRTCme.WebRtc.NativePeerConnectionFactory
                                         .CreateVideoTrack(id, nativeVideoSource);
                break;
            }

            var mediaStreamTrack = new MediaStreamTrack(nativeMediaStreamTrack);

            mediaStreamTrack.SetNativeMediaSource(nativeMediaSource);
            return(mediaStreamTrack);
        }
Esempio n. 2
0
        public static Webrtc.MediaConstraints ToNative(this MediaTrackConstraints constraints)
        {
            var mandatoryDictionary = new Dictionary <string, string>();
            var optionalDictionary  = new Dictionary <string, string>();

            mandatoryDictionary.Add("googEchoCancellation", constraints.EchoCancellation.ToBool() ? "true" : "false");
            mandatoryDictionary.Add("googAutoGainControl", constraints.AutoGainControl.ToBool() ? "true" : "false");
            mandatoryDictionary.Add("googHighpassFilter", "false");
            mandatoryDictionary.Add("googNoiseSuppression", constraints.NoiseSuppression.ToBool() ? "true" : "false");

            var mandatory = mandatoryDictionary.Select(
                pair => new Webrtc.MediaConstraints.KeyValuePair(pair.Key, pair.Value)).ToList();
            var optional = optionalDictionary.Select
                               (pair => new Webrtc.MediaConstraints.KeyValuePair(pair.Key, pair.Value)).ToList();

            var nativeConstrains = new Webrtc.MediaConstraints
            {
                Mandatory = mandatory,
                Optional  = optional
            };

            return(nativeConstrains);
        }
Esempio n. 3
0
        public static MediaStreamConstraints MakeConstraints(
            bool shouldDoThis,
            MediaStreamConstraints existingConstraints,
            MediaDeviceKind kind,
            MediaDevice device
            )
        {
            if (!shouldDoThis)
            {
                return(existingConstraints);
            }
            if (null == device)
            {
                return(existingConstraints);
            }

            if (null == existingConstraints)
            {
                existingConstraints = new MediaStreamConstraints();
            }
            IMediaTrackConstraints trackConstraints = null;

            switch (kind)
            {
            case MediaDeviceKind.AudioInput:
                trackConstraints = existingConstraints.Audio;
                break;

            case MediaDeviceKind.AudioOutput:
                trackConstraints = existingConstraints.Audio;
                break;

            case MediaDeviceKind.VideoInput:
                trackConstraints = existingConstraints.Video;
                break;
            }
            if (null == trackConstraints)
            {
                trackConstraints = new MediaTrackConstraints();
            }

            var newAdvancedList = new List <MediaTrackConstraintSet>();

            if (null == trackConstraints.Advanced)
            {
                trackConstraints.Advanced = newAdvancedList;
            }

            var constraintSet = new MediaTrackConstraintSet
            {
                DeviceId = new ConstrainString
                {
                    Parameters = new ConstrainStringParameters
                    {
                        Exact = new StringOrStringList {
                            Value = device.Id
                        }
                    },
                    Value = new StringOrStringList {
                        Value = device.Id
                    }
                }
            };

            newAdvancedList.Add(constraintSet);
            trackConstraints.Advanced = newAdvancedList;

            switch (kind)
            {
            case MediaDeviceKind.AudioInput:
                existingConstraints.Audio = trackConstraints;
                break;

            case MediaDeviceKind.AudioOutput:
                existingConstraints.Audio = trackConstraints;
                break;

            case MediaDeviceKind.VideoInput:
                existingConstraints.Video = trackConstraints;
                break;
            }
            return(existingConstraints);
        }