Example #1
0
        public void Start(ViewGroup videoContainer, Action <string> callback)
        {
            /*
             * Demonstration of how to record local audio/video to disk while the media stream is active.
             *
             * OpusCodec opus = new OpusCodec();
             * Vp8Codec vp8 = new Vp8Codec();
             *
             * opus.Initialize(CodecUsage.Encoder, "opus", 48000, 2);
             * vp8.Initialize(CodecUsage.Encoder, "VP8");
             *
             * var oggPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments), "audio.ogg");
             * var ivfPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments), "video.ivf");
             *
             * var audioCaptureProvider = new OggAudioCaptureProvider(oggPath, opus);
             * var videoCaptureProvider = new IvfVideoCaptureProvider(ivfPath, vp8);
             */

            UserMedia.GetMedia(new GetMediaArgs(Audio, Video)
            {
                // Uncomment this line to do in-app screen capture.
                //VideoCaptureProvider = new AndroidScreenCaptureProvider(videoContainer.RootView),
                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 View. 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 = (View)e.LocalVideoControl;

                    // Create an IceLink layout manager, which makes the task
                    // of arranging video controls easy. Give it a reference
                    // to a View that can be filled with video feeds.
                    if (localVideoControl != null)
                    {
                        LayoutManager = new AndroidLayoutManager(videoContainer);
                        // Position and display the local video control on-screen
                        // by passing it to the layout manager created above.
                        LayoutManager.SetLocalVideoControl(localVideoControl);
                    }

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

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

            callback(null);
        }
        public void GetUserMedia(Context context, ViewGroup videoContainer)
        {
            DefaultProviders.AndroidContext = context;

            UserMedia.GetMedia(new GetMediaArgs(true, true)
            {
                DefaultVideoPreviewScale = LayoutScale.Contain,
                DefaultVideoScale        = LayoutScale.Contain,
                VideoWidth     = 640,
                VideoHeight    = 480,
                VideoFrameRate = 15,
                OnSuccess      = (result) =>
                {
                    _localMedia                    = result.LocalStream;
                    _layoutManager                 = new AndroidLayoutManager(videoContainer);
                    _senderLocalVideoControl       = (View)result.LocalVideoControl;
                    var localVideoStream           = new VideoStream(result.LocalStream);
                    _conference                    = new Conference(STUN_TURN_URL, new Stream[] { new AudioStream(result.LocalStream), localVideoStream });
                    _conference.RelayUsername      = "******";
                    _conference.RelayPassword      = "******";
                    _conference.DtlsCertificate    = Certificate.GenerateCertificate();
                    _conference.OnLinkCandidate   += Conference_OnLinkCandidate;
                    _conference.OnLinkOfferAnswer += Conference_OnLinkOfferAnswer;

                    localVideoStream.OnLinkInit += LocalVideoStream_OnLinkInit;
                    localVideoStream.OnLinkDown += LocalVideoStream_OnLinkDown;
                    _layoutManager.SetLocalVideoControl(_senderLocalVideoControl);
                    _opusEchoCanceller = new OpusEchoCanceller(4800, 2);
                    _opusEchoCanceller.Start();
                },
                OnFailure = (error) =>
                {
                    Console.WriteLine(error);
                }
            });
        }
		public void StartConference(ViewGroup videoContainer, Action<Exception> callback)
		{           
			try {                   
				var localVideoControl = LocalMedia.LocalVideoControl;
				var layoutManager = new AndroidLayoutManager (videoContainer);					                   
				layoutManager.SetLocalVideoControl (localVideoControl);					                   
				var videoStream = new VideoStream (LocalMedia.LocalStream);
				videoStream.OnLinkInit += (e) => {
					var remoteVideoControl = e.Link.GetRemoteVideoControl ();
					layoutManager.AddRemoteVideoControl (e.PeerId, remoteVideoControl);
				};
				videoStream.OnLinkDown += (e) => {
					layoutManager.RemoveRemoteVideoControl (e.PeerId);
				};

				// Create a conference using our stream descriptions.
				Conference = new FM.IceLink.Conference (videoStream);                
				Conference.MaxLinks = 1;

				Signalling.Attach (Conference, (ex) => {
					if (ex != null) {
						ex = new Exception ("Could not attach signalling to conference.", ex);
						LastStartConferenceException = ex;
					}

					callback (ex);
				});
			} catch (Exception ex) {
				LastStartConferenceException = ex;
				callback (ex);
			}          
        
		}
Example #5
0
        public void Start(ViewGroup videoContainer, Action<string> callback)
        {
            /*
             * Demonstration of how to record local audio/video to disk while the media stream is active.
             *
            OpusCodec opus = new OpusCodec();
            Vp8Codec vp8 = new Vp8Codec();

            opus.Initialize(CodecUsage.Encoder, "opus", 48000, 2);
            vp8.Initialize(CodecUsage.Encoder, "VP8");

            var oggPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments), "audio.ogg");
            var ivfPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments), "video.ivf");

            var audioCaptureProvider = new OggAudioCaptureProvider(oggPath, opus);
            var videoCaptureProvider = new IvfVideoCaptureProvider(ivfPath, vp8);
            */

            UserMedia.GetMedia(new GetMediaArgs(Audio, Video)
            {
                // Uncomment this line to do in-app screen capture.
                //VideoCaptureProvider = new AndroidVideoCaptureProvider(videoContainer.RootView),
                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 View. 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 = (View)e.LocalVideoControl;

                    // Create an IceLink layout manager, which makes the task
                    // of arranging video controls easy. Give it a reference
                    // to a View that can be filled with video feeds.
                    LayoutManager = new AndroidLayoutManager(videoContainer);

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

                    callback(null);
                }
            });
        }