Esempio n. 1
0
        public Chatroom(string name)
        {
            InitializeComponent();

            this.txtListenOn.Text  = Ozeki.Network.NetworkAddressHelper.GetLocalIP().ToString() + ":2048";
            this.Video_but.Enabled = false;
            this.user_name.Text    = name;
            this.LOCK        = new object();
            this.IsConnected = false;
            this.AdjustUi();
            this.txtIpAddress.Text = "500";
            this.audio_port.Text   = "555";
            string path = FigureOutFilePath("ringing.wav");

            ringing = new SoundPlayer(path);

            cbCameras.Items.Clear();
            foreach (var info in WebCameraFactory.GetDevices())
            {
                cbCameras.Items.Add(info.Name);
            }

            cbCameras.SelectedIndex = 0;
            Helper.PopulateInputDevicesCombo(this.cmbInputs);
            Helper.PopulateCodecsCombo(Helper.AvailableCodecs, this.cmbCodecs);
        }
        /// <summary>
        /// Initializes the video handlers (camera, image providers etc.).
        /// </summary>
        private void InitVideo()
        {
            // ----- CREATE -----
            WebCamera = WebCameraFactory.GetDefaultDevice();

            LocalImageProvider  = new DrawingImageProvider();
            RemoteImageProvider = new DrawingImageProvider();

            _phoneCallVideoReceiver = new PhoneCallVideoReceiver();
            _phoneCallVideoSender   = new PhoneCallVideoSender();

            // ----- CONNECT -----
            _videoConnector.Connect(_phoneCallVideoReceiver, RemoteImageProvider);
            if (WebCamera != null)
            {
                _videoConnector.Connect(WebCamera.VideoChannel, LocalImageProvider);
                _videoConnector.Connect(WebCamera.VideoChannel, _phoneCallVideoSender);
            }
        }
        /// <summary>
        /// Changes the camera device.
        /// </summary>
        public void ChangeCamera(int deviceID)
        {
            if (!_initialized)
            {
                return;
            }

            // same device
            if (WebCamera != null && WebCamera.DeviceID == deviceID)
            {
                return;
            }

            // find the proper info
            VideoDeviceInfo newDeviceInfo = null;

            foreach (var info in Cameras)
            {
                if (info.DeviceID != deviceID)
                {
                    continue;
                }

                newDeviceInfo = info;
                break;
            }

            if (newDeviceInfo == null)
            {
                return;
            }


            // begin change device
            bool capturing = false;

            if (WebCamera != null)
            {
                // disconnect
                if (LocalImageProvider != null)
                {
                    _audioConnector.Disconnect(WebCamera.VideoChannel, LocalImageProvider);
                }
                _audioConnector.Disconnect(WebCamera.VideoChannel, _phoneCallVideoSender);

                // dispose previous device
                capturing = WebCamera.Capturing;
                WebCamera.Stop();
                WebCamera.Dispose();
            }

            // create new
            WebCamera = WebCameraFactory.GetDevice(newDeviceInfo);

            if (WebCamera != null)
            {
                _audioConnector.Connect(WebCamera.VideoChannel, LocalImageProvider);
                _audioConnector.Connect(WebCamera.VideoChannel, _phoneCallVideoSender);

                if (capturing)
                {
                    WebCamera.Start();
                }
            }

            OnPropertyChanged("WebCamera");
        }
Esempio n. 4
0
        public video_chat_room(string myListening, string videop, string aup, string vclient_n, string vclient_ipadd, string client_videop, string client_aup, string camn, string audioinputn, string audiooutputn)
        {
            try
            {
                InitializeComponent();

                string[] splitmessage = myListening.Split(':');
                myListeningUrl         = splitmessage[0];
                videoport              = videop;
                auport                 = aup;
                vclient_name           = vclient_n;
                splitmessage           = vclient_ipadd.Split(':');
                vclient_ipaddress      = splitmessage[0];
                client_videoport       = client_videop;
                client_auport          = client_aup;
                camName                = camn;
                audioinputname         = audioinputn;
                audiooutputname        = audiooutputn;
                close_button.Enabled   = false;
                this.client_label.Text = vclient_name;

                //client
                vconnector      = new MediaConnector();
                mjpegConnection = new MJPEGConnection();
                vprovider       = new DrawingImageProvider();
                this.zoom       = new Zoom();

                videoViewer = new VideoViewerWF()
                {
                    Name      = "Video Preview",
                    Size      = new Size(300, 210),
                    Location  = new Point(20, 20),
                    BackColor = Color.Black
                };

                vvideoViewer = new VideoViewerWF()
                {
                    Name      = "Video Preview",
                    Size      = new Size(300, 210),
                    Location  = new Point(20, 20),
                    BackColor = Color.Black
                };



                connector = new MediaConnector();
                provider  = new DrawingImageProvider();
                videoViewer.SetImageProvider(provider);



                vvideoViewer.SetImageProvider(vprovider);

                groupBox1.Controls.Add(videoViewer);

                webCamera = null;

                foreach (var info in WebCameraFactory.GetDevices())
                {
                    if (info.Name == camName)
                    {
                        webCamera = WebCameraFactory.GetDevice(info);

                        break;
                    }
                }

                if (webCamera == null)
                {
                    MessageBox.Show("Couldn't connect to the camera");
                    return;
                }
                connector.Connect(webCamera.VideoChannel, provider);
                videoSender = webCamera.VideoChannel;

                webCamera.Start();
                videoViewer.Start();
                streamer = new MJPEGStreamer(myListeningUrl, int.Parse(videoport));


                if (!connector.Connect(videoSender, streamer.VideoChannel))
                {
                    MessageBox.Show("Failed to create connection..");
                }
                streamer.ClientConnected    += ClientConnected;
                streamer.ClientDisconnected += ClientDisconnected;

                streamer.Start();



                if (!this.vconnected)
                {
                    IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse(this.myListeningUrl), int.Parse(this.auport));



                    this.selectedCodec = new AcmMuLawChatCodec();

                    this.ServerConnect(endPoint, int.Parse(audioinputn), selectedCodec);
                }
                else
                {
                    this.ServerDisconnect();
                }


                this.lblStatus.Text = "Server & camera started\n" + lblStatus.Text;
            }
            catch (Exception ex)
            {
                lblStatus.Text = ex.ToString() + "\n" + lblStatus.Text;
            }
        }