Example #1
0
 public static void SetNativeMediaSource(this IMediaStreamTrack track, Webrtc.MediaSource nativeSource)
 {
     if (_mediaSourceStore.ContainsKey(track.Id))
     {
         _mediaSourceStore[track.Id] = nativeSource;
     }
     else
     {
         _mediaSourceStore.Add(track.Id, nativeSource);
     }
 }
Example #2
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);
        }