Example #1
0
        public void Stop(Action <string> callback)
        {
            LayoutManager.UnsetLocalVideoControl();
            LayoutManager.RemoveRemoteVideoControls();
            LayoutManager = null;

            LocalMediaStream.Stop();
            LocalMediaStream = null;

            LocalVideoControl = null;

            callback(null);
        }
        private void StartMedia()
        {
            // Get a video-based local media stream. This
            // conference will be send-only.
            // ทำการ Get user media ของเครื่อง (Audio and Video Device)
            UserMedia.GetMedia(new GetMediaArgs(true, true)
            {
                AudioCaptureProvider = new NAudioCaptureProvider(),
                VideoCaptureProvider = new WpfAForgeVideoCaptureProvider(Dispatcher),

                CreateAudioRenderProvider = (e) =>
                {
                    return(new NAudioRenderProvider());
                },
                CreateVideoRenderProvider = (e) =>
                {
                    return(new ImageVideoRenderProvider(Dispatcher, LayoutScale.Contain));
                },

                // กำหนดขนาด Video ที่จะแสดงพร้อมทั้ง Frame rate ของ Video
                VideoWidth     = 352, // optional
                VideoHeight    = 288, // optional
                VideoFrameRate = 30,  // optional

                // เมื่อไม่สามารถ Access user media ของเครื่องได้ จะแสดง message error
                OnFailure = (e) =>
                {
                    Alert("Could not get media. {0}", e.Exception.Message);
                },

                // เมื่อสามารถ Access user media ของเครื่องได้
                OnSuccess = (e) =>
                {
                    // พิมพ์แสดงผลลัพธ์ว่าสามารถ Access user media ของเครื่องได้
                    Console.WriteLine("Get User media ok...");

                    // กำหนด localmedia audio and video ที่ใช้งาน
                    LocalMediaReceiver = e.LocalStream;

                    // Create a WebRTC audio stream description (requires a
                    // reference to the local audio feed).
                    // กำหนด Audio ในการสนทนา
                    audioStream_Receiver = new AudioStream(LocalMediaReceiver);

                    // Create a WebRTC video stream description (requires a
                    // reference to the local video feed). Whenever a P2P link
                    // initializes using this description, position and display
                    // the remote video control on-screen by passing it to the
                    // layout manager created above. Whenever a P2P link goes
                    // down, remove it.
                    // กำหนด Video ในการสนทนา
                    videoStream_Receiver = new VideoStream(LocalMediaReceiver);

                    // กำหนดแสดง Video เมื่อมีการสนทนากับเลิกสนทนา
                    videoStream_Receiver.OnLinkInit += AddRemoteVideoControl;
                    videoStream_Receiver.OnLinkDown += RemoveRemoteVideoControl;

                    // แสดงรายชื่อ Audio และ Video Device ที่สามารถ Access ได้โดยแสดงใน ComboBox
                    AudioDevices.ItemsSource = LocalMediaReceiver.GetAudioDeviceNames();
                    VideoDevices.ItemsSource = LocalMediaReceiver.GetVideoDeviceNames();

                    // เลือก Audio and Video อันแรกของอุปกรณ์เพื่อใช้งาน
                    AudioDevices.SelectedIndex = LocalMediaReceiver.GetAudioDeviceNumber();
                    VideoDevices.SelectedIndex = LocalMediaReceiver.GetVideoDeviceNumber();

                    // เปลี่ยน Localmedia เมื่อมีการเปลี่ยน Audio and Video Device
                    AudioDevices.SelectionChanged += SwitchAudioDevice;
                    VideoDevices.SelectionChanged += SwitchVideoDevice;

                    // อัพเดตแสดง Video Device เมื่อมีการเลือกหรือเปลี่ยนอุปกรณ์การใช้งาน
                    LocalMediaReceiver.OnAudioDeviceNumberChanged += UpdateSelectedAudioDevice;
                    LocalMediaReceiver.OnVideoDeviceNumberChanged += UpdateSelectedVideoDevice;

                    // This is our local video control, a WinForms control
                    // that displays video coming from the capture source.
                    // กำหนดการ capture source ของ Video device
                    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.
                    // กำหนดให้ Video แสดงผลที่ canvas ใน UI ของ Sender
                    LayoutManager = new WpfLayoutManager(containerLocal);

                    // แสดงผล Video ที่ได้จากการ capture source
                    LayoutManager.SetLocalVideoControl(localVideoControl);

                    // เริ่มทำการ Conference
                    StartConference();
                }
            });
        }
Example #3
0
        public void Start(VideoPage videoPage, 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 AudioCaptureProvider(),
                VideoCaptureProvider      = new VideoCaptureProvider(videoPage),
                CreateAudioRenderProvider = (e) =>
                {
                    return(new AudioRenderProvider());
                },
                CreateVideoRenderProvider = (e) =>
                {
                    return(new Direct3DRenderProvider());
                },
                VideoWidth     = VideoWidth,     // optional
                VideoHeight    = VideoHeight,    // optional
                VideoFrameRate = VideoFrameRate, // optional
                OnFailure      = (e) =>
                {
                    callback(string.Format("Could not get media. {0}", e.Exception.Message));
                },
                OnSuccess = (ea) =>
                {
                    // 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 = ea.LocalStream;

                    // This is our local video control, a WinForms Control or
                    // WPF FrameworkElement. 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.
                    LocalVideoControl = (FrameworkElement)ea.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.
                    // For WPF users, the WebRTC extension includes
                    // WpfLayoutManager, which accepts a Canvas.
                    LayoutManager = new WpfLayoutManager(videoPage.Container);

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

                    // When double-clicked, mute/unmute the local video.
                    videoPage.Dispatcher.BeginInvoke(() =>
                    {
                        LocalVideoControl.DoubleTap += (sender, ce) =>
                        {
                            LocalMediaStream.ToggleVideoMute();
                        };
                    });

                    //call back of null will let the app know to continue on to the signalling stage
                    callback(null);
                }
            });
        }
        public void Stop(Action<string> callback)
        {
            LayoutManager.UnsetLocalVideoControl();
            LayoutManager.RemoveRemoteVideoControls();
            LayoutManager = null;

            LocalMediaStream.Stop();
            LocalMediaStream = null;
            
            LocalVideoControl = null;
            
            callback(null);
        }
        public void Start(VideoPage videoPage, 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 AudioCaptureProvider(),
                VideoCaptureProvider = new VideoCaptureProvider(videoPage),
                CreateAudioRenderProvider = (e) =>
                {
                    return new AudioRenderProvider();
                },
                CreateVideoRenderProvider = (e) =>
                {
                    return new Direct3DRenderProvider();
                },
                VideoWidth = VideoWidth,    // optional
                VideoHeight = VideoHeight,   // optional
                VideoFrameRate = VideoFrameRate, // optional
                OnFailure = (e) =>
                {
                    callback(string.Format("Could not get media. {0}", e.Exception.Message));
                },
                OnSuccess = (ea) =>
                {
                    // 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 = ea.LocalStream;

                    // This is our local video control, a WinForms Control or
                    // WPF FrameworkElement. 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.
                    LocalVideoControl = (FrameworkElement)ea.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.
                    // For WPF users, the WebRTC extension includes
                    // WpfLayoutManager, which accepts a Canvas.
                    LayoutManager = new WpfLayoutManager(videoPage.Container);

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

                    // When double-clicked, mute/unmute the local video.
                    videoPage.Dispatcher.BeginInvoke(() =>
                    {
                        LocalVideoControl.DoubleTap += (sender, ce) =>
                        {
                            LocalMediaStream.ToggleVideoMute();
                        };
                    });

                    //call back of null will let the app know to continue on to the signalling stage
                    callback(null);
                }
            });
        }