Exemplo n.º 1
0
        public override void NegociateDevice()
        {
            if(!m_bIsConnected)
            {
                log.Debug("Try to connect to a Capture Device.");

                m_iConnectionsAttempts++;

                //----------------------------------------------------------------------------------------
                // TODO: Proper device negociation.
                // Apparently there's no way to know if a device is already used by an application.
                // Let's try to connect to the first device if any.
                // If the device is already streaming to another application, we will connect successfully,
                // but the NewFrame event will never be raised for us.
                //----------------------------------------------------------------------------------------

                FilterInfoCollection videoDevices = new FilterInfoCollection( FilterCategory.VideoInputDevice );

                if(videoDevices.Count > 0)
                {
                    ConnectToDevice(videoDevices, 0);
                }

                if(!m_bIsConnected && m_iConnectionsAttempts == 2)
                {
                    m_Container.AlertCannotConnect();
                }
            }
        }
Exemplo n.º 2
0
		public override void NegociateDevice()
		{
			if(!m_bIsConnected)
			{
				log.Debug("Trying to connect to a Capture source.");
				
				m_iConnectionsAttempts++;
				
				// TODO: Detect if a device is already in use 
				// (by an other app or even just by the other screen).
	        	List<DeviceDescriptor> devices = ListDevices();
	        	if(devices.Count > 0)
	        	{
	        		bool bSuccess = false;
	        		
	        		// Check if we were already connected to a device.
		        	// In that case we try to reconnect to the same one instead of defaulting to the first of the list.
		        	// Unless that was the empty device placeholder. (This might happen if we start with 0 device and plug one afterwards)
		        	// The network placeholder device is not subject to the disconnection/reconnection mechanism either.
		        	if(m_CurrentVideoDevice != null && !m_CurrentVideoDevice.Empty && !m_CurrentVideoDevice.Network)
		        	{
		        		// Look for the device we were previously connected to.
		        		bool bFoundCurrentDevice = false;
		        		for(int i = 0; i < devices.Count - 1; i++)
		        		{
		        			if(devices[i].Identification == m_CurrentVideoDevice.Identification)
		        			{
		        				bFoundCurrentDevice = true;
		        				log.DebugFormat("Trying to reconnect to {0}.", m_CurrentVideoDevice.Name);
		        				bSuccess = ConnectToDevice(devices[i]);
		        			}
		        		}
		        		
		        		// If not found, default to the first one anyway.
		        		if(!bFoundCurrentDevice && !devices[0].Empty)
		        		{
		        			log.DebugFormat("Current device not found (has been physically unplugged) - connect to first one ({0})", devices[0].Name);
		        			bSuccess = ConnectToDevice(devices[0]);
		        		}
		        	}
		        	else
		        	{
		        		// We were not connected to any device, or we were connected to a special device.
		        		// Connect to the first one (Capture device).
		        		if(!devices[0].Empty)
						{
		        			log.DebugFormat("First attempt, default to first device ({0})", devices[0].Name);
							bSuccess = ConnectToDevice(devices[0]);
						}
		        	}
		        	
		        	if(bSuccess)
		        		m_Container.Connected();	
	        	}
	        	
	        	m_iGrabbedSinceLastCheck = 0;
	        	
	        	if(m_bIsConnected)
	        		m_iConnectionsWithoutFrames++;
	        	
	        	if(!m_bIsConnected && m_iConnectionsAttempts == 2)
	        		m_Container.AlertCannotConnect();
			}
		}