예제 #1
0
        static void CycleSendVideo()
        {
            long lastMemory    = 0;
            long currentMemory = 0;
            int  i             = 0;

            VideoCapability vc = null;

            FilterInfo[] cameras = VideoSource.Sources();
            if (cameras.Length > 0)
            {
                vc = new VideoCapability(cameras[0]);
                vc.ActivateCamera();
            }

            JoinVenue();
            while (vc != null)
            {
                Console.WriteLine(string.Format(CultureInfo.CurrentCulture, Strings.CycleSendVideoTestRun +
                                                "\n", ++i));

                vc.BeginSend(null, null);
                Thread.Sleep(15000);
                vc.BeginStopSending(null, null);
                Thread.Sleep(5000);

                currentMemory = GC.GetTotalMemory(true);
                Console.WriteLine(string.Format(CultureInfo.CurrentCulture, Strings.MemoryUsed, currentMemory,
                                                (currentMemory - lastMemory).ToString(CultureInfo.InvariantCulture)));
                lastMemory = currentMemory;
            }
        }
예제 #2
0
        private void RestoreLinkedCamera()
        {
            // List the selected cameras
            foreach (FilterInfo fi in VideoCapability.SelectedCameras())
            {
                cboLinkedCamera.Items.Add(fi);
            }

            // Read from registry and select camera, if in list
            string[] linkedCamera = AVReg.ValueNames(AVReg.LinkedCamera);
            if (linkedCamera != null && linkedCamera.Length > 0)
            {
                Debug.Assert(linkedCamera.Length == 1);

                for (int i = 0; i < cboLinkedCamera.Items.Count; i++)
                {
                    FilterInfo fi = (FilterInfo)cboLinkedCamera.Items[i];
                    if (fi.Moniker == linkedCamera[0])
                    {
                        cboLinkedCamera.SelectedItem = fi;
                    }
                }
            }

            if (cboLinkedCamera.SelectedIndex == -1 && cboLinkedCamera.Items.Count > 0)
            {
                cboLinkedCamera.SelectedIndex = 0;
            }

            cboLinkedCamera.Enabled = cboLinkedCamera.Items.Count > 1;
        }
예제 #3
0
        public void RenderAndRunVideo(VideoCaptureGraph vcg, bool playIt)
        {
            if (playIt)
            {
                Log("Playing video (render and run graph) - " + vcg.Source.FriendlyName);

                vcg.RenderLocal();

                VideoCapability.DisableDXVA(vcg.FilgraphManager);

                // Set device name in the video window and turn off the system menu
                IVideoWindow iVW = (IVideoWindow)vcg.FilgraphManager;
                iVW.Caption      = vcg.Source.FriendlyName;
                iVW.WindowStyle &= ~0x00080000; // WS_SYSMENU

                vcg.Run();
            }
            else
            {
                Log("Stop video (stop and unrender graph) - " + vcg.Source.FriendlyName);

                vcg.Stop();
                vcg.RemoveRenderer();

                // I have no idea why the video window stays up but this fixes it
                GC.Collect();
            }

            Log(FilterGraph.Debug(vcg.IFilterGraph));
        }
예제 #4
0
        private void InitVideoCapability(ICapability capability)
        {
            if (videoCapability == null)
            {
                videoCapability = (VideoCapability)capability;

                this.Text = videoCapability.Name;

                // Unintuitively causes us to look at the vidSrcRatio and use it if it's been set
                TrimBlackFromVideo(base.Size);

                // TODO: Add a condition to not call InitVideoUI() if isFormLoaded is false to prevent
                // the form to show to early
                InitVideoUI();

                videoCapability.VideoWindowHandle       = pbVideo.Handle;
                videoCapability.VideoWindowMessageDrain = pbVideo.Handle;
                videoCapability.ResizeVideoStream(pbVideo.Height, pbVideo.Width);
                //videoCapability.ResizeVideoStream(230, 200);

                // Set the UI borders so the video capability can calculate the
                // AV form size given some constrains due to the video ratio
                //videoCapability.UIBorderWidth = UIBorderWidth;
                //videoCapability.UIBorderHeight = UIBorderHeight;
            }
        }
예제 #5
0
        static void CycleSendVideo()
        {
            long lastMemory = 0;
            long currentMemory = 0;
            int i = 0;

            VideoCapability vc = null;

            FilterInfo[] cameras = VideoSource.Sources();
            if (cameras.Length > 0)
            {
                vc = new VideoCapability(cameras[0]);
                vc.ActivateCamera();
            }

            JoinVenue();
            while (vc != null)
            {
                Console.WriteLine("CycleSendVideo Test Run #" + ++i + ":\n");

                vc.BeginSend(null, null);
                Thread.Sleep(15000);
                vc.BeginStopSending(null, null);
                Thread.Sleep(5000);

                currentMemory = GC.GetTotalMemory(true);
                Console.WriteLine("Memory Used: " + currentMemory + ", Diff: " + (currentMemory - lastMemory).ToString());
                lastMemory = currentMemory;
            }
        }
예제 #6
0
        private void FHelloCXP_Load(object sender, System.EventArgs e)
        {
            // ConferenceAPI to autoplay any incoming streams
            Conference.AutoPlayLocal = true;
            Conference.AutoPlayRemote = true;

            // Tell ConferenceApi who the calling form is so it knows how to send events to the form on the correct thread
            Conference.CallingForm = this;

            // ConferenceAPI to autoposition any new windows
            Conference.AutoPosition = Conference.AutoPositionMode.Tiled;

            // Don't connect to a Venue Service; create a local venue and join it.
            Conference.VenueServiceWrapper.VenueServiceUrl = null;
            Venue localVenue = Conference.VenueServiceWrapper.CreateRandomMulticastVenue("Local Venue", null);
            Conference.JoinVenue( localVenue );

            // Send audio and video streams
            FilterInfo[] cameras = VideoSource.Sources();

            if (cameras.Length > 0)
            {
                VideoCapability vc = new VideoCapability(cameras[0]);
                vc.ActivateCamera();
                vc.Send();
            }
        }
예제 #7
0
 private void updateOnClose()
 {
     frmAV.UpdateVideoBox(vc.CaptureGraph);
     if ((disposeCapability) && (vc != null))
     {
         vc.Dispose();
         vc = null;
         disposeCapability = false;
     }
 }
예제 #8
0
        private void DeactivateVideoCapability(FilterInfo fi)
        {
            RenderAndRunVideo(vcg, false);
            vcg = null;

            VideoCapability vc = (VideoCapability)vcs[fi];

            vcs.Remove(fi);
            vc.DeactivateCamera();
        }
예제 #9
0
        private void ActivateVideoCapability(FilterInfo fi)
        {
            Debug.Assert(!vcs.Contains(fi));
            vc = new VideoCapability(fi);
            vcs.Add(fi, vc);

            vc.SetLogger(new AVLogger(Log));
            vc.ActivateCamera();
            vcg = vc.VideoCaptureGraph;

            RenderAndRunVideo(vcg);
        }
예제 #10
0
        public frmVideoSettings(VideoCapability vc, frmAVDevices frmAV)
        {
            InitializeComponent();

            Debug.Assert(vc != null);
            Debug.Assert(vc.VideoCaptureGraph != null);
            Debug.Assert(frmAV != null);

            this.vc = vc;
            this.vcg = vc.VideoCaptureGraph;
            this.frmAV = frmAV;
        }
예제 #11
0
        private void RestoreVideo()
        {
            // Get the UI set up correctly in the event there are no selected cameras
            ClearVideoBox();

            foreach (FilterInfo fi in VideoCapability.SelectedCameras())
            {
                int idx = clbCameras.Items.IndexOf(fi);
                clbCameras.SetItemChecked(idx, true);
                clbCameras.SetSelected(idx, true);
            }
        }
예제 #12
0
        public frmVideoSettings(VideoCapability vc, frmAVDevices frmAV)
        {
            InitializeComponent();

            Debug.Assert(vc != null);
            Debug.Assert(vc.VideoCaptureGraph != null);
            Debug.Assert(frmAV != null);

            this.vc    = vc;
            this.vcg   = vc.VideoCaptureGraph;
            this.frmAV = frmAV;
        }
예제 #13
0
        /// <summary>
        /// Remove a capability object to the list of capability objects referring to this shared form
        /// </summary>
        /// <param name="capability">The capability object to remove</param>
        /// <returns>true if there is no more capability of this type, false otherwise</returns>
        public override bool RemoveCapability(ICapability capability)
        {
            bool lastCapability = base.RemoveCapability(capability);

            if (lastCapability)
            {
                // TODO - we need to keep track of how many instances of a capability are in use
                // so that we shut down when the last instance goes away, not the first
                if (capability is VideoCapability)
                {
                    UninitVideoUI();
                    videoCapability = null;
                }
                else if (capability is AudioCapability)
                {
                    UninitAudioUI();
                    audioCapability = null;
                }
            }

            return(lastCapability);
        }
예제 #14
0
        public frmVideoSettings(FilterInfo fi, frmAVDevices frmAV)
        {
            InitializeComponent();

            Debug.Assert(frmAV != null);

            this.fi    = fi;
            this.frmAV = frmAV;

            if (!frmAV.videoCapabilities.ContainsKey(fi))
            {
                vc = new VideoCapability(fi);
                vc.SetLogger(new AVLogger(Log));
                vc.ActivateCamera();
                disposeCapability = true;
            }
            else
            {
                vc = frmAV.videoCapabilities[fi];
                disposeCapability = false;
            }
        }
예제 #15
0
        private void clbCameras_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            try
            {
                ClearVideoBox();

                vc  = (VideoCapability)vcs[(FilterInfo)clbCameras.SelectedItem];
                vcg = vc != null ? vc.VideoCaptureGraph : null;

                if (clbCameras.GetItemChecked(clbCameras.SelectedIndex))
                {
                    UpdateVideoBox();
                }
            }
            catch (COMException ex)
            {
                Log(DShowError._AMGetErrorText(ex.ErrorCode));
                Log(ex.ToString());
            }
            catch (Exception ex)
            {
                Log(ex.ToString());
            }
        }
예제 #16
0
        private void InitVideoCapability(ICapability capability)
        {
            if (videoCapability == null)
            {
                videoCapability = (VideoCapability)capability;

                this.Text = videoCapability.Name;

                // Unintuitively causes us to look at the vidSrcRatio and use it if it's been set
                TrimBlackFromVideo(base.Size);

                // TODO: Add a condition to not call InitVideoUI() if isFormLoaded is false to prevent
                // the form to show to early
                InitVideoUI();

                videoCapability.VideoWindowHandle = pbVideo.Handle;
                videoCapability.ResizeVideoStream(pbVideo.Height, pbVideo.Width);

                // Set the UI borders so the video capability can calculate the
                // AV form size given some constrains due to the video ratio
                videoCapability.UIBorderWidth = UIBorderWidth;
                videoCapability.UIBorderHeight = UIBorderHeight;
            }
        }
예제 #17
0
        private void ActivateVideoCapability(FilterInfo fi)
        {
            Debug.Assert(!vcs.Contains(fi));
            vc = new VideoCapability(fi);
            vcs.Add(fi, vc);

            vc.SetLogger(new AVLogger(Log));
            vc.ActivateCamera();
            vcg = vc.VideoCaptureGraph;

            RenderAndRunVideo(vcg);
        }
예제 #18
0
        private void clbCameras_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            try
            {
                ClearVideoBox();

                vc = (VideoCapability)vcs[(FilterInfo)clbCameras.SelectedItem];
                vcg = vc != null ? vc.VideoCaptureGraph : null;

                if(clbCameras.GetItemChecked(clbCameras.SelectedIndex))
                {
                    UpdateVideoBox();
                }
            }
            catch(COMException ex)
            {
                Log(DShowError._AMGetErrorText(ex.ErrorCode));
                Log(ex.ToString());
            }
            catch(Exception ex)
            {
                Log(ex.ToString());
            }
        }
예제 #19
0
 /// <summary>
 /// Create a VideoCapability for the specified camera, grab the data from the 
 /// capture graph, then dispose the capability.
 /// </summary>
 /// <param name="fi"></param>
 private void UpdateVideoBox(FilterInfo fi)
 {
     if (videoCapabilities.ContainsKey(fi)) {
         //The capability might exist if there is a video test underway.
         UpdateVideoBox(videoCapabilities[fi].CaptureGraph);
     }
     else {
         VideoCapability vc = new VideoCapability(fi);
         vc.SetLogger(new AVLogger(Log));
         vc.ActivateCamera();
         UpdateVideoBox(vc.CaptureGraph);
         vc.Dispose();
     }
 }
예제 #20
0
 /// <summary>
 /// Turn the specified video test on or off
 /// </summary>
 /// <param name="fi"></param>
 /// <param name="start"></param>
 private void TestVideo(FilterInfo fi, bool start)
 {
     if (start) {
         VideoCapability vc = new VideoCapability(fi);
         videoCapabilities.Add(fi, vc);
         vc.SetLogger(new AVLogger(Log));
         vc.ActivateCamera();
         RenderAndRunVideo(vc.CaptureGraph);
     }
     else {
         if (videoCapabilities.ContainsKey(fi)) {
             VideoCapability vc = videoCapabilities[fi];
             videoCapabilities.Remove(fi);
             RenderAndRunVideo(vc.CaptureGraph, false);
             vc.Dispose();
         }
     }
 }
예제 #21
0
        static void CycleSendVideo()
        {
            long lastMemory = 0;
            long currentMemory = 0;
            int i = 0;

            VideoCapability vc = null;
            
            FilterInfo[] cameras = VideoSource.Sources();
            if (cameras.Length > 0)
            {
                vc = new VideoCapability(cameras[0]);
                vc.ActivateCamera();
            }

            JoinVenue();
            while (vc != null)
            {
                Console.WriteLine(string.Format(CultureInfo.CurrentCulture, Strings.CycleSendVideoTestRun + 
                    "\n", ++i));

                vc.BeginSend(null, null);
                Thread.Sleep(15000);
                vc.BeginStopSending(null, null);
                Thread.Sleep(5000);
                
                currentMemory = GC.GetTotalMemory(true);
                Console.WriteLine(string.Format(CultureInfo.CurrentCulture, Strings.MemoryUsed, currentMemory,
                    (currentMemory - lastMemory).ToString(CultureInfo.InvariantCulture)));
                lastMemory = currentMemory;
            }
        }
예제 #22
0
        public frmVideoSettings(FilterInfo fi, frmAVDevices frmAV)
        {
            InitializeComponent();

            Debug.Assert(frmAV != null);

            this.fi = fi;
            this.frmAV = frmAV;

            if (!frmAV.videoCapabilities.ContainsKey(fi)) {
                vc = new VideoCapability(fi);
                vc.SetLogger(new AVLogger(Log));
                vc.ActivateCamera();
                disposeCapability = true;
            }
            else {
                vc = frmAV.videoCapabilities[fi];
                disposeCapability = false;
            }
        }
예제 #23
0
        /// <summary>
        /// Remove a capability object to the list of capability objects referring to this shared form
        /// </summary>
        /// <param name="capability">The capability object to remove</param>
        /// <returns>true if there is no more capability of this type, false otherwise</returns>
        public override bool RemoveCapability(ICapability capability)
        {
            bool lastCapability = base.RemoveCapability(capability);

            if(lastCapability)
            {

                // TODO - we need to keep track of how many instances of a capability are in use
                // so that we shut down when the last instance goes away, not the first
                if (capability is VideoCapability)
                {
                    UninitVideoUI();
                    videoCapability = null;
                }
                else if (capability is AudioCapability)
                {
                    UninitAudioUI();
                    audioCapability = null;
                }
            }

            return lastCapability;
        }
예제 #24
0
 private void updateOnClose() {
     frmAV.UpdateVideoBox(vc.CaptureGraph);
     if ((disposeCapability) && (vc != null)) {
         vc.Dispose();
         vc = null;
         disposeCapability = false;
     }
 }
예제 #25
0
        private void AutoSendAV()
        {
            // Determine if the form is shared
            string[] linkedCamera = AVReg.ValueNames(AVReg.LinkedCamera);
            if (linkedCamera != null)
            {
                Debug.Assert(linkedCamera.Length <= 1);
            }

            // Create the audio capability
            FilterInfo[] mics = AudioCapability.SelectedMicrophones();
            Debug.Assert(mics.Length <= 1);  // For now we only support 1

            AudioCapability ac = null;
            foreach (FilterInfo fi in mics)
            {
                ac = new AudioCapability(fi);
            }

            // Create the video capabilities and start sending their data
            foreach (FilterInfo fi in VideoCapability.SelectedCameras())
            {
                VideoCapability vc = new VideoCapability(fi);

                // Set the shared form ID
                if (ac != null && linkedCamera != null && linkedCamera.Length > 0)
                {
                    if (fi.Moniker == linkedCamera[0])
                    {
                        Guid sharedFormID = Guid.NewGuid();
                        ac.SharedFormID = sharedFormID;
                        vc.SharedFormID = sharedFormID;
                    }
                }

                try
                {
                    vc.ActivateCamera();
                    vc.Send();
                }
                catch (Exception)
                {
                    vc.Dispose();

                    MessageBox.Show(string.Format("ConferenceXP was unable to send video from " +
                        "the device - {0}.  See the ConferenceAPI Event Log for details.", vc.Name),
                        "Unable to send video", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            // Start sending the audio data
            try
            {
                if (ac != null)
                {
                    ac.ActivateMicrophone();
                    ac.Send();
                }
            }
            catch (Exception)
            {
                ac.Dispose();

                MessageBox.Show(string.Format("ConferenceXP was unable to send audio from " +
                    "the device - {0}.  See the ConferenceAPI Event Log for details.", ac.Name),
                    "Unable to send audio", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #26
0
        private void AutoSendAV()
        {
            // Determine if the form is shared
            string[] linkedCamera = AVReg.ValueNames(AVReg.LinkedCamera);
            if (linkedCamera != null)
            {
                Debug.Assert(linkedCamera.Length <= 1);
            }

            // Create the audio capability
            FilterInfo[] mics = AudioCapability.SelectedMicrophones();
            Debug.Assert(mics.Length <= 1);  // For now we only support 1

            AudioCapability ac = null;
            foreach (FilterInfo fi in mics)
            {
                ac = new AudioCapability(fi);
                ac.FecEnabled = enableAudioFec;
            }

            // Create the video capabilities and start sending their data
            foreach (FilterInfo fi in VideoCapability.SelectedCameras())
            {
                VideoCapability vc = new VideoCapability(fi);
                vc.FecEnabled = enableVideoFec;

                // Set the shared form ID
                if (ac != null && linkedCamera != null && linkedCamera.Length > 0)
                {
                    if (fi.Moniker == linkedCamera[0])
                    {
                        Guid sharedFormID = Guid.NewGuid();
                        ac.SharedFormID = sharedFormID;
                        vc.SharedFormID = sharedFormID;
                    }
                }

                try
                {
                    vc.ActivateCamera();
                    vc.Send();
                }
                catch (Exception)
                {
                    vc.Dispose();

                    RtlAwareMessageBox.Show(this, string.Format(CultureInfo.CurrentCulture,
                        Strings.SendVideoErrorText, vc.Name), Strings.SendVideoErrorTitle, MessageBoxButtons.OK,
                        MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0);
                }
            }

            // Start sending the audio data
            try
            {
                if (ac != null)
                {
                    ac.ActivateMicrophone();
                    ac.Send();
                }
            }
            catch (Exception)
            {
                ac.Dispose();

                RtlAwareMessageBox.Show(this, string.Format(CultureInfo.CurrentCulture, Strings.SendAudioErrorText,
                    ac.Name), Strings.SendAudioErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error,
                    MessageBoxDefaultButton.Button1, (MessageBoxOptions)0);
            }
        }