Exemplo n.º 1
0
        public WebCamInfo[] ListWebCams()
        {
            WebCamInfo[] result = null;

            fForm.Invoke
            (
                new Action
                (
                    delegate
            {
                lock (ActiveWebCams.fDictionary)
                {
                    int count = ActiveWebCams.fDictionary.Count;
                    int index = -1;
                    result    = new WebCamInfo[count];
                    foreach (var form in ActiveWebCams.fDictionary.Values)
                    {
                        index++;
                        result[index] = new WebCamInfo(form.DisplayName, form.MonikerName);
                    }
                }
            }
                )
            );

            return(result);
        }
Exemplo n.º 2
0
        internal static IFastEnumerator <byte[]> GetWebCamEnumerator(WebCamInfo webCamInfo)
        {
            lock (fDictionary)
            {
                FormWebCam form;
                if (!fDictionary.TryGetValue(webCamInfo.InternalName, out form))
                {
                    return(null);
                }

                var result = form.Distributor.CreateClient();
                return(result);
            }
        }
Exemplo n.º 3
0
        public IFastEnumerator <byte[]> ReceiveWebCam(string fromNickName, WebCamInfo webCamInfo)
        {
            if (fromNickName == null)
            {
                return(null);
            }

            var server = Server.GetInstance();

            while (true)
            {
                try
                {
                    ServerClient webCamSenderClient;
                    lock (server.fClients)
                        server.fClients.TryGetValue(fromNickName, out webCamSenderClient);

                    if (webCamSenderClient == null)
                    {
                        return(null);
                    }

                    EnumeratorDistributor <byte[]> result;
                    lock (fWebCamDistributors)
                    {
                        result = fWebCamDistributors.GetValueOrDefault(webCamInfo);
                        if (result == null || result.WasDisposed)
                        {
                            var enumeratorResult = webCamSenderClient.fClient.GetWebCamEnumerator(webCamInfo);
                            if (enumeratorResult == null)
                            {
                                return(null);
                            }

                            result = new EnumeratorDistributor <byte[]>(enumeratorResult);
                            fWebCamDistributors[webCamInfo] = result;
                        }
                    }

                    return(result.CreateClient());
                }
                catch (ObjectDisposedException)
                {
                }
            }
        }
Exemplo n.º 4
0
        public static WebCamInfo[] ListAllWebCams()
        {
            var videoInputDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);

            int count = videoInputDevices.Count;

            WebCamInfo[] result = new WebCamInfo[count + 2];
            for (int i = 0; i < count; i++)
            {
                var videoInputDevice = videoInputDevices[i];
                result[i] = new WebCamInfo(videoInputDevice.Name, videoInputDevice.MonikerString);
            }
            result[count]     = new WebCamInfo("Fake WebCam - Only generates a frame count for testing - Black background", "Fake_Black");
            result[count + 1] = new WebCamInfo("Fake WebCam - Only generates a frame count for testing - Blue background", "Fake_Blue");

            return(result);
        }
Exemplo n.º 5
0
        public static EnumeratorDistributorClient <byte[]> Start(WebCamInfo webCamInfo)
        {
            string monikerName = webCamInfo.InternalName;

            EnumeratorDistributor <byte[]> distributor;

            lock (fDictionary)
            {
                FormWebCam form;
                if (fDictionary.TryGetValue(monikerName, out form))
                {
                    distributor = form.Distributor;
                }
                else
                {
                    IFastEnumerator <byte[]> realEnumerator;

                    switch (monikerName)
                    {
                    case "Fake_Black":
                        realEnumerator = new FakeWebCamEnumerator(Color.Black);
                        break;

                    case "Fake_Blue":
                        realEnumerator = new FakeWebCamEnumerator(Color.Blue);
                        break;

                    default:
                        realEnumerator = new WebCamEnumerator(monikerName);
                        break;
                    }

                    distributor = new EnumeratorDistributor <byte[]>(realEnumerator);
                    form        = new FormWebCam(FormMain.fNickName, webCamInfo.DisplayName, monikerName, distributor);
                    fDictionary.Add(monikerName, form);
                    form.Show();
                }
            }

            return(distributor.CreateClient());
        }
Exemplo n.º 6
0
 public IFastEnumerator <byte[]> GetWebCamEnumerator(WebCamInfo webCamInfo)
 {
     return(ActiveWebCams.GetWebCamEnumerator(webCamInfo));
 }
Exemplo n.º 7
0
 private void buttonOk_Click(object sender, EventArgs e)
 {
     Result       = AvailableWebCams[comboWebCams.SelectedIndex];
     DialogResult = DialogResult.OK;
 }