public void Start(VideoChat videoChat, Action<string> callback)
        {
            // WebRTC audio and video streams require us to first get access to
            // the local media (microphone, camera, or both).
            UserMedia.GetMedia(new GetMediaArgs(Audio, Video)
            {
                // Specify an audio capture provider, a video
                // capture provider, an audio render provider,
                // and a video render provider. The IceLink
                // SDK comes bundled with video support for
                // WinForms and WPF, and uses NAudio for audio
                // support. For lower latency audio, use ASIO.
                AudioCaptureProvider = new NAudioCaptureProvider(),
                VideoCaptureProvider = new VideoCaptureProvider(),
                CreateAudioRenderProvider = (e) =>
                {
                    return new NAudioRenderProvider();
                },
                CreateVideoRenderProvider = (e) =>
                {
                    return new VideoRenderProvider(LayoutScale.Contain);
                },
                VideoWidth = VideoWidth,     // optional
                VideoHeight = VideoHeight,    // optional
                VideoFrameRate = VideoFrameRate, // optional
                OnFailure = (e) =>
                {
                    callback(string.Format("Could not get media. {0}", e.Exception.Message));
                },
                OnSuccess = (e) =>
                {
                    // We have successfully acquired access to the local
                    // audio/video device! Grab a reference to the media.
                    // Internally, it maintains access to the local audio
                    // and video feeds coming from the device hardware.
                    LocalMediaStream = e.LocalStream;

                    // Wire up the UI.
                    VideoChat = videoChat;
                    Win8LayoutManager.SafeInvoke(() =>
                    {
                        VideoChat.GetAudioDevices().ItemsSource = LocalMediaStream.GetAudioDeviceNames();
                        VideoChat.GetVideoDevices().ItemsSource = LocalMediaStream.GetVideoDeviceNames();
                        VideoChat.GetAudioDevices().SelectionChanged += SwitchAudioDevice;
                        VideoChat.GetVideoDevices().SelectionChanged += SwitchVideoDevice;
                        VideoChat.GetAudioDevices().SelectedIndex = LocalMediaStream.GetAudioDeviceNumber();
                        VideoChat.GetVideoDevices().SelectedIndex = LocalMediaStream.GetVideoDeviceNumber();
                    });

                    // Keep the UI updated if devices are switched.
                    LocalMediaStream.OnAudioDeviceNumberChanged += UpdateSelectedAudioDevice;
                    LocalMediaStream.OnVideoDeviceNumberChanged += UpdateSelectedVideoDevice;

                    // This is our local video control, a WinForms control
                    // that displays video coming from the capture source.
                    var localVideoControl = (FrameworkElement)e.LocalVideoControl;

                    // Create an IceLink layout manager, which makes the task
                    // of arranging video controls easy. Give it a reference
                    // to a WinForms control that can be filled with video feeds.
                    // Use WpfLayoutManager for WPF-based applications.
                    LayoutManager = new Win8LayoutManager(VideoChat.GetContainer());

                    // Display the local video control.
                    LayoutManager.SetLocalVideoControl(localVideoControl);

                    callback(null);
                }
            });
        }
Example #2
0
        public void Stop(Action <string> callback)
        {
            // Clear out the layout manager.
            if (LayoutManager != null)
            {
                LayoutManager.RemoveRemoteVideoControls();
                LayoutManager.UnsetLocalVideoControl();
                LayoutManager = null;
            }

            if (LocalMediaStream != null)
            {
                LocalMediaStream.OnAudioDeviceNumberChanged -= UpdateSelectedAudioDevice;
                LocalMediaStream.OnVideoDeviceNumberChanged -= UpdateSelectedVideoDevice;
            }

            if (VideoChat != null)
            {
                VideoChat.GetAudioDevices().SelectionChanged -= SwitchAudioDevice;
                VideoChat.GetVideoDevices().SelectionChanged -= SwitchVideoDevice;
                VideoChat = null;
            }

            // Stop the local media stream.
            if (LocalMediaStream != null)
            {
                LocalMediaStream.Stop();
                LocalMediaStream = null;
            }

            callback(null);
        }
Example #3
0
 private void UpdateSelectedVideoDevice(VideoDeviceNumberChangedArgs e)
 {
     Win8LayoutManager.SafeInvoke(() =>
     {
         VideoChat.GetVideoDevices().SelectedIndex = e.DeviceNumber;
     });
 }
Example #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ImageVideoRenderProvider"/> class.
 /// </summary>
 /// <param name="image">The Image to target.</param>
 /// <param name="disableContextMenu">Whether or not to disable the context menu.</param>
 /// <param name="scale">The scaling algorithm to use.</param>
 public VideoRenderProvider(Image image, bool disableContextMenu, LayoutScale scale)
 {
     Win8LayoutManager.SafeInvoke(() =>
     {
         Image = image;
         Initialize(disableContextMenu, scale);
     }, true);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ImageVideoRenderProvider"/> class.
 /// </summary>
 /// <param name="disableContextMenu">Whether or not to disable the context menu.</param>
 /// <param name="scale">The scaling algorithm to use.</param>
 public VideoRenderProvider(bool disableContextMenu, LayoutScale scale)
 {
     Win8LayoutManager.SafeInvoke(() =>
     {
         Image = new Windows.UI.Xaml.Controls.Image();
         Initialize(disableContextMenu, scale);
     }, true);
 }
Example #6
0
 public override void Destroy()
 {
     Win8LayoutManager.SafeInvoke(() =>
     {
         if (ContextMenu != null)
         {
             ContextMenu.Detach();
         }
     }, true);
 }
Example #7
0
 public override void Initialize(VideoRenderInitializeArgs renderArgs)
 {
     Win8LayoutManager.SafeInvoke(() =>
     {
         if (ContextMenu != null)
         {
             var mediaStream = renderArgs.RemoteStream == null ? renderArgs.LocalStream : renderArgs.RemoteStream;
             ContextMenu.Attach(Image, mediaStream);
         }
     }, true);
 }
Example #8
0
        public void Stop(Action <string> callback)
        {
            // Clear out the layout manager.
            if (LayoutManager != null)
            {
                LayoutManager.UnsetLocalVideoControl();
                LayoutManager.RemoveRemoteVideoControls();
                LayoutManager = null;
            }

            // Stop the local media stream.
            if (LocalMediaStream != null)
            {
                LocalMediaStream.Stop();
                LocalMediaStream = null;
            }

            callback(null);
        }
Example #9
0
        public override async void Render(VideoBuffer frame)
        {
            if (!Rendering)
            {
                Rendering = true;
                var stream  = new InMemoryRandomAccessStream();
                var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.BmpEncoderId, stream);

                encoder.SetPixelData(BitmapPixelFormat.Rgba8, BitmapAlphaMode.Ignore, (uint)frame.Width, (uint)frame.Height, 96, 96, frame.Plane.Data);
                await encoder.FlushAsync();

                stream.Seek(0);

                Win8LayoutManager.SafeInvoke(async() =>
                {
                    await Bitmap.SetSourceAsync(stream);
                    Rendering = false;
                });
            }
        }
Example #10
0
        public void Start(VideoChat videoChat, Action <string> callback)
        {
            // WebRTC audio and video streams require us to first get access to
            // the local media (microphone, camera, or both).
            UserMedia.GetMedia(new GetMediaArgs(Audio, Video)
            {
                // Specify an audio capture provider, a video
                // capture provider, an audio render provider,
                // and a video render provider. The IceLink
                // SDK comes bundled with video support for
                // WinForms and WPF, and uses NAudio for audio
                // support. For lower latency audio, use ASIO.
                AudioCaptureProvider      = new NAudioCaptureProvider(),
                VideoCaptureProvider      = new VideoCaptureProvider(),
                CreateAudioRenderProvider = (e) =>
                {
                    return(new NAudioRenderProvider());
                },
                CreateVideoRenderProvider = (e) =>
                {
                    return(new VideoRenderProvider(LayoutScale.Contain));
                },
                VideoWidth     = VideoWidth,     // optional
                VideoHeight    = VideoHeight,    // optional
                VideoFrameRate = VideoFrameRate, // optional
                OnFailure      = (e) =>
                {
                    callback(string.Format("Could not get media. {0}", e.Exception.Message));
                },
                OnSuccess = (e) =>
                {
                    // We have successfully acquired access to the local
                    // audio/video device! Grab a reference to the media.
                    // Internally, it maintains access to the local audio
                    // and video feeds coming from the device hardware.
                    LocalMediaStream = e.LocalStream;

                    // Wire up the UI.
                    VideoChat = videoChat;
                    Win8LayoutManager.SafeInvoke(() =>
                    {
                        VideoChat.GetAudioDevices().ItemsSource       = LocalMediaStream.GetAudioDeviceNames();
                        VideoChat.GetVideoDevices().ItemsSource       = LocalMediaStream.GetVideoDeviceNames();
                        VideoChat.GetAudioDevices().SelectionChanged += SwitchAudioDevice;
                        VideoChat.GetVideoDevices().SelectionChanged += SwitchVideoDevice;
                        VideoChat.GetAudioDevices().SelectedIndex     = LocalMediaStream.GetAudioDeviceNumber();
                        VideoChat.GetVideoDevices().SelectedIndex     = LocalMediaStream.GetVideoDeviceNumber();
                    });

                    // Keep the UI updated if devices are switched.
                    LocalMediaStream.OnAudioDeviceNumberChanged += UpdateSelectedAudioDevice;
                    LocalMediaStream.OnVideoDeviceNumberChanged += UpdateSelectedVideoDevice;

                    // This is our local video control, a WinForms control
                    // that displays video coming from the capture source.
                    var localVideoControl = (FrameworkElement)e.LocalVideoControl;

                    // Create an IceLink layout manager, which makes the task
                    // of arranging video controls easy. Give it a reference
                    // to a WinForms control that can be filled with video feeds.
                    // Use WpfLayoutManager for WPF-based applications.
                    LayoutManager = new Win8LayoutManager(VideoChat.GetContainer());

                    // Display the local video control.
                    LayoutManager.SetLocalVideoControl(localVideoControl);

                    callback(null);
                }
            });
        }
Example #11
0
        public void Start(object videoContainer, Action <string> callback)
        {
#if __IOS__
            AVAudioSession.SharedInstance().SetCategory(AVAudioSessionCategory.PlayAndRecord,
                                                        AVAudioSessionCategoryOptions.AllowBluetooth |
                                                        AVAudioSessionCategoryOptions.DefaultToSpeaker);
#endif

            UserMedia.GetMedia(new GetMediaArgs(Audio, Video)
            {
#if __IOS__ || __ANDROID__
#elif WINDOWS_APP
                AudioCaptureProvider      = new NAudioCaptureProvider(),
                VideoCaptureProvider      = new VideoCaptureProvider(),
                CreateAudioRenderProvider = (e) =>
                {
                    return(new NAudioRenderProvider());
                },
                CreateVideoRenderProvider = (e) =>
                {
                    return(new VideoRenderProvider(LayoutScale.Contain));
                },
#endif

                VideoWidth               = VideoWidth,          // optional
                VideoHeight              = VideoHeight,         // optional
                VideoFrameRate           = VideoFrameRate,      // optional
                DefaultVideoPreviewScale = LayoutScale.Contain, // optional
                DefaultVideoScale        = LayoutScale.Contain, // optional
                OnFailure = (e) =>
                {
                    callback(string.Format("Could not get media. {0}", e.Exception.Message));
                },
                OnSuccess = (e) =>
                {
                    // We have successfully acquired access to the local
                    // audio/video device! Grab a reference to the media.
                    // Internally, it maintains access to the local audio
                    // and video feeds coming from the device hardware.
                    LocalMediaStream = e.LocalStream;

                    // This is our local video control, a UIView (iOS) or
                    // and NSView (Mac). It is constantly updated with our
                    // live video feed since we requested video above. Add
                    // it directly to the UI or use the IceLink layout manager,
                    // which we do below.
                    var localVideoControl = e.LocalVideoControl;

#if __IOS__ || __ANDROID__
                    // Create an IceLink layout manager, which makes the task
                    // of arranging video controls easy. Give it a reference
                    // to a UIView that can be filled with video feeds.
                    LayoutManager = new FormsLayoutManager((AbsoluteLayout)videoContainer);

                    // Position and display the local video control on-screen
                    // by passing it to the layout manager created above.
                    LayoutManager.SetLocalVideoControl(new FormsVideoControl(localVideoControl));
#elif WINDOWS_APP
                    var content = Windows.UI.Xaml.Window.Current.Content as Windows.UI.Xaml.Controls.Frame;
                    var list    = new List <Windows.UI.Xaml.Controls.Canvas>();
                    FindChildren <Windows.UI.Xaml.Controls.Canvas>(list, content.Content as Windows.UI.Xaml.DependencyObject);

                    // Create an IceLink layout manager, which makes the task
                    // of arranging video controls easy. Give it a reference
                    // to a WinForms control that can be filled with video feeds.
                    // Use WpfLayoutManager for WPF-based applications.
                    LayoutManager = new Win8LayoutManager(list.Last());

                    // Position and display the local video control on-screen
                    // by passing it to the layout manager created above.
                    LayoutManager.SetLocalVideoControl(localVideoControl);
#endif



                    callback(null);
                }
            });
        }
        public void Stop(Action<string> callback)
        {
            // Clear out the layout manager.
            if (LayoutManager != null)
            {
                LayoutManager.RemoveRemoteVideoControls();
                LayoutManager.UnsetLocalVideoControl();
                LayoutManager = null;
            }

            if (LocalMediaStream != null)
            {
                LocalMediaStream.OnAudioDeviceNumberChanged -= UpdateSelectedAudioDevice;
                LocalMediaStream.OnVideoDeviceNumberChanged -= UpdateSelectedVideoDevice;
            }

            if (VideoChat != null)
            {
                VideoChat.GetAudioDevices().SelectionChanged -= SwitchAudioDevice;
                VideoChat.GetVideoDevices().SelectionChanged -= SwitchVideoDevice;
                VideoChat = null;
            }

            // Stop the local media stream.
            if (LocalMediaStream != null)
            {
                LocalMediaStream.Stop();
                LocalMediaStream = null;
            }

            callback(null);
        }