Esempio n. 1
0
bool cServerConnection::ProvidesChannel(const cChannel *Channel, int Priority) 
{
	cDevice *device = CheckDevice(Channel, Priority, false);
	if (!device || (StreamdevServerSetup.SuspendMode != smAlways
			&& !device->IsTunedToTransponder(Channel)
			&& UsedByLiveTV(device))) {
		// no device available or the device is in use for live TV and suspend mode doesn't allow us to switch it:
		// maybe a device would be free if THIS connection did turn off its streams?
		Detach();
		device = CheckDevice(Channel, Priority, false);
		Attach();
		if (device && StreamdevServerSetup.SuspendMode != smAlways
				&& !device->IsTunedToTransponder(Channel)
				&& UsedByLiveTV(device)) {
			// now we would have to switch away live tv...let's see if live tv
			// can be handled by another device
			const cChannel *current = Channels.GetByNumber(cDevice::CurrentChannel());
			cDevice *newdev = current ? CheckDevice(current, 0, true, device) : NULL;
			if (newdev) {
				dsyslog("streamdev: Providing channel %d (%s) at priority %d requires moving live TV to device %d (PrimaryDevice=%d, ActualDevice=%d)", Channel->Number(), Channel->Name(), Priority, newdev->CardIndex(), cDevice::PrimaryDevice()->CardIndex(), cDevice::ActualDevice()->CardIndex());
			}
			else {
				device = NULL;
				dsyslog("streamdev: Not providing channel %d (%s) at priority %d - live TV not suspended", Channel->Number(), Channel->Name(), Priority);
			}
		}
		else if (!device)
			dsyslog("streamdev: No device provides channel %d (%s) at priority %d", Channel->Number(), Channel->Name(), Priority);
	}
	return device;
}
Esempio n. 2
0
/*
 * Check for hot plugged devices.
 */
void CLinuxInputDevices::CheckHotplugged()
{
  CSingleLock lock(m_devicesListLock);

  int deviceId = m_devices.size();

  /* No devices specified. Try to guess some. */
  for (int i = 0; i < MAX_LINUX_INPUT_DEVICES; i++)
  {
    char buf[32];
    bool ispresent = false;

    snprintf(buf, 32, "/dev/input/event%d", i);

    for (size_t j = 0; j < m_devices.size(); j++)
    {
      if (m_devices[j]->GetFileName().compare(buf) == 0)
      {
        ispresent = true;
        break;
      }
    }

    if (!ispresent && CheckDevice(buf))
    {
      CLog::Log(LOGINFO, "Found input device %s", buf);
      m_devices.push_back(new CLinuxInputDevice(buf, deviceId));
      ++deviceId;
    }
  }
}
Esempio n. 3
0
/*
 * Return the number of available devices.
 * Called once during initialization of DirectFB.
 */
void CLinuxInputDevices::InitAvailable()
{
  CSingleLock lock(m_devicesListLock);

  /* Close any devices that may have been initialized previously */
  for (size_t i = 0; i < m_devices.size(); i++)
  {
    delete m_devices[i];
  }
  m_devices.clear();

  int deviceId = 0;

  /* No devices specified. Try to guess some. */
  for (int i = 0; i < MAX_LINUX_INPUT_DEVICES; i++)
  {
    char buf[32];

    snprintf(buf, 32, "/dev/input/event%d", i);
    if (CheckDevice(buf))
    {
      CLog::Log(LOGINFO, "Found input device %s", buf);
      m_devices.push_back(new CLinuxInputDevice(buf, deviceId));
      ++deviceId;
    }
  }
}
Esempio n. 4
0
void CDeviceSelDlg::OnBnClickedBdevsearchdir()
{
	// TODO:  选择搜索路径
	CFileOper oper;
	m_strSearchDir = oper.DirectorySelect(this->GetSafeHwnd());
	UPDATAVALTOCONTROL;
	CheckDevice();
}
Esempio n. 5
0
int Caffe::FindDevice(const int start_id) {
  // This function finds the first available device by checking devices with
  // ordinal from start_id to the highest available value. In the
  // EXCLUSIVE_PROCESS or EXCLUSIVE_THREAD mode, if it succeeds, it also
  // claims the device due to the initialization of the context.
  int count = 0;
  CUDA_CHECK(cudaGetDeviceCount(&count));
  for (int i = start_id; i < count; i++) {
    if (CheckDevice(i)) return i;
  }
  return -1;
}
Esempio n. 6
0
cDevice *cServerConnection::GetDevice(const cChannel *Channel, int Priority) 
{
	// turn off the streams of this connection
	Detach();
	// This call may detach receivers of the device it returns
	cDevice *device = cDevice::GetDevice(Channel, Priority, false);

 	if (device && !device->IsTunedToTransponder(Channel)
			&& UsedByLiveTV(device)) {
		// now we would have to switch away live tv...let's see if live tv
		// can be handled by another device
#if VDRVERSNUM >= 10516
		cDevice::SetAvoidDevice(device);
		if (!Channels.SwitchTo(cDevice::CurrentChannel())) {
			if (StreamdevServerSetup.SuspendMode == smAlways) {
				Channels.SwitchTo(Channel->Number());
				Skins.QueueMessage(mtInfo, tr("Streaming active"));
			}
			else {
				dsyslog("streamdev: GetDevice: Live TV not suspended");
				device = NULL;
			}
		}
#else
		const cChannel *current = Channels.GetByNumber(cDevice::CurrentChannel());
		cDevice *newdev = current ? CheckDevice(current, 0, true, device) : NULL;
		if (newdev) {
			dsyslog("streamdev: GetDevice: Trying to move live TV to device %d", newdev->CardIndex());
			newdev->SwitchChannel(current, true);
		}
		else if (StreamdevServerSetup.SuspendMode == smAlways) {
			Channels.SwitchTo(Channel->Number());
			Skins.QueueMessage(mtInfo, tr("Streaming active"));
		}
		else {
			dsyslog("streamdev: GetDevice: Live TV not suspended");
			device = NULL;
		}
#endif
	}

	if (!device) {
		// can't switch - continue the current stream
		Attach();
		dsyslog("streamdev: GetDevice failed for channel %d (%s) at priority %d (PrimaryDevice=%d, ActualDevice=%d)", Channel->Number(), Channel->Name(), Priority, cDevice::PrimaryDevice()->CardIndex(), cDevice::ActualDevice()->CardIndex());
	}
	return device;
}
Esempio n. 7
0
bool CheckNetworkDevices(ZString& strDriverURL)
{
    int  index = 0;
    bool bValid;

    while (CheckDevice(index, bValid, strDriverURL))
    {
        if (!bValid) {
            return false;
        }

        index++;
    }

    return true;
}
Esempio n. 8
0
// CDeviceSelDlg 消息处理程序
BOOL CDeviceSelDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	if (m_strUserPath.GetLength() <= 0)
		return FALSE;

	CFileOper foper;
	if (!foper.FileExist(m_strUserPath))
		return FALSE;

	m_strSearchDir = foper.GetExeFilePath();
	CheckDevice();

	m_comSampleRate.AddString(L"64");
	m_comSampleRate.AddString(L"128");
	m_comSampleRate.AddString(L"256");
	m_comSampleRate.AddString(L"512");
	m_comSampleRate.AddString(L"1024");
	Stringoper oper;
	CDeviceConfig config(m_strUserPath);
	config.LoadFileMsg();

	m_nBufSize = (size_t)config.GetBuffersize();
	m_comSampleRate.SetCurSel(config.GetSamplerate() / 64 - 1);
	m_LParam = oper.tocstring(config.GetParam());                 //hwh_add
	m_strDllPath = config.GetDevicePath();

	if (config.GetMode() == 0)
		((CButton*)GetDlgItem(IDC_RDEVNORMAL))->SetCheck(1);
	else
		((CButton*)GetDlgItem(IDC_RDEVIMP))->SetCheck(1);

	UCHAR *pchan = new UCHAR[config.GetChannum()];
	config.GetChans(pchan, config.GetChannum());
	m_strChannels = L"";
	for (int i = 0; i < config.GetChannum();i++)
	{
		m_strChannels += oper.tocstring(oper.inttostring((int)pchan[i]))+L" ";
	}
	delete pchan;

	UPDATAVALTOCONTROL;
	return TRUE;  // return TRUE unless you set the focus to a control
	// 异常:  OCX 属性页应返回 FALSE
}
HRESULT D3D9RenderImpl::Display(BYTE* pYplane, BYTE* pVplane, BYTE* pUplane)
{
    if(!pYplane)
    {
        return E_POINTER;
    }

    if(m_format == D3DFMT_NV12 && !pVplane)
    {
        return E_POINTER;
    }

    if(m_format == D3DFMT_YV12 && (!pVplane || !pUplane))
    {
        return E_POINTER;
    }

    HR(CheckDevice());
    HR(FillBuffer(pYplane, pVplane, pUplane));
    HR(CreateScene());
    return Present();
}
  //----------------------------------------------------------------------------
  long MediaFoundationVideoDevice::InitDevice()
  {
    HRESULT hr = S_OK;
    IMFAttributes *pAttributes = NULL;
    IMFActivate * vd_pActivate = NULL;
    CoInitialize(NULL);

    if (SUCCEEDED(hr))
    {
      hr = MFCreateAttributes(&pAttributes, 1);
    }
    if (SUCCEEDED(hr))
    {
      hr = pAttributes->SetGUID(MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE,MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_GUID);
      if (!SUCCEEDED(hr))
      {
        LOG_ERROR("MediaFoundationVideoDevice::InitDevice failed: device  " << this->DeviceIndex << ": The attribute of the capture device cannot be retrieved");
      }
    }
    if (SUCCEEDED(hr))
    {
      hr = CheckDevice(pAttributes, &vd_pActivate);
      if (SUCCEEDED(hr) && vd_pActivate)
      {
        SafeRelease(&this->Source);
        hr = vd_pActivate->ActivateObject(__uuidof(IMFMediaSource), (void**)&this->Source);
        SafeRelease(&vd_pActivate);
      }
      else
      {
        LOG_ERROR("MediaFoundationVideoDevice::InitDevice failed: device  " << this->DeviceIndex << ": Cannot activate device");
      }
    }
    SafeRelease(&pAttributes);
    return hr;
  }
Esempio n. 11
0
void CRemoteControl::Update()
{
  if (!m_bInitialized || !m_used )
    return;

  if (!CheckDevice())
    return;

  uint32_t now = XbmcThreads::SystemClockMillis();

  // Read a line from the socket
  while (fgets(m_buf, sizeof(m_buf), m_file) != NULL)
  {
    // Remove the \n
    m_buf[strlen(m_buf)-1] = '\0';

    // Parse the result. Sample line:
    // 000000037ff07bdd 00 OK mceusb
    char scanCode[128];
    char buttonName[128];
    char repeatStr[4];
    char deviceName[128];
    sscanf(m_buf, "%s %s %s %s", &scanCode[0], &repeatStr[0], &buttonName[0], &deviceName[0]);

    //beginning of lirc reply packet
    //we get one when lirc is done sending something
    if (!m_inReply && strcmp("BEGIN", scanCode) == 0)
    {
      m_inReply = true;
      continue;
    }
    else if (m_inReply && strcmp("END", scanCode) == 0) //end of lirc reply packet
    {
      m_inReply = false;
      if (m_nrSending > 0)
        m_nrSending--;
      continue;
    }

    if (m_inReply)
      continue;

    // Some template LIRC configuration have button names in apostrophes or quotes.
    // If we got a quoted button name, strip 'em
    unsigned int buttonNameLen = strlen(buttonName);
    if ( buttonNameLen > 2
    && ( (buttonName[0] == '\'' && buttonName[buttonNameLen-1] == '\'')
         || ((buttonName[0] == '"' && buttonName[buttonNameLen-1] == '"') ) ) )
    {
      memmove( buttonName, buttonName + 1, buttonNameLen - 2 );
      buttonName[ buttonNameLen - 2 ] = '\0';
    }

    m_button = CButtonTranslator::GetInstance().TranslateLircRemoteString(deviceName, buttonName);

    char *end = NULL;
    long repeat = strtol(repeatStr, &end, 16);
    if (!end || *end != 0)
      CLog::Log(LOGERROR, "LIRC: invalid non-numeric character in expression %s", repeatStr);
    if (repeat == 0)
    {
      CLog::Log(LOGDEBUG, "LIRC: %s - NEW at %d:%s (%s)", __FUNCTION__, now, m_buf, buttonName);
      m_firstClickTime = now;
      m_holdTime = 0;
      return;
    }
    else if (repeat > g_advancedSettings.m_remoteDelay)
    {
      m_holdTime = now - m_firstClickTime;
    }
    else
    {
      m_holdTime = 0;
      m_button = 0;
    }
  }

  //drop commands when already sending
  //because keypresses come in faster than lirc can send we risk hammering the daemon with commands
  if (m_nrSending > 0)
  {
    m_sendData.clear();
  }
  else if (!m_sendData.empty())
  {
    fputs(m_sendData.c_str(), m_file);
    fflush(m_file);

    //nr of newlines equals nr of commands
    for (int i = 0; i < (int)m_sendData.size(); i++)
      if (m_sendData[i] == '\n')
        m_nrSending++;

    m_sendData.clear();
  }

  if (feof(m_file) != 0)
    Disconnect();
}
Esempio n. 12
0
int mmp_o_init() { // open device

        int i;
        WAVEOUTCAPS caps;
        int numdev=waveOutGetNumDevs();
        int bestdev;
        unsigned int bestformat=0;

	UseDevice=(unsigned int)-1;
        if (numdev==0) return 1;
        for (i=0;i<numdev;i++)
        {
                waveOutGetDevCaps(i,&caps,sizeof(caps));
#ifdef MMPDEBUG
				printf("%d: %s\n",i,caps.szPname);
#endif
                if ((caps.dwFormats>bestformat)&&(caps.dwFormats&0xfff))
                {
                      bestformat=caps.dwFormats;
                      bestdev=i;
                }
        }
        UseDevice=bestdev;
#ifdef MMPDEBUG
		printf("using device: %X, bestformat: %X\n",UseDevice,bestformat);
#endif

        DEV_Type=0;
        if (bestformat&WAVE_FORMAT_4S16)
        {
                DEV_Freq=44100;
                DEV_Mode=DM_16bit+DM_Stereo+DM_Mixed+DM_Signed;
                return CheckDevice(UseDevice,44100,2,16);
        }
        else
        if (bestformat&WAVE_FORMAT_4S08)
        {
                DEV_Freq=44100;
                DEV_Mode=DM_8bit+DM_Stereo+DM_Mixed;
                return CheckDevice(UseDevice,44100,2,8);
        }
        else
        if (bestformat&WAVE_FORMAT_4M16)
        {
                DEV_Freq=44100;
                DEV_Mode=DM_16bit+DM_Mono+DM_Mixed+DM_Signed;
                return CheckDevice(UseDevice,44100,1,16);
        }
        else
        if (bestformat&WAVE_FORMAT_4M08)
        {
                DEV_Freq=44100;
                DEV_Mode=DM_8bit+DM_Mono+DM_Mixed;
                return CheckDevice(UseDevice,44100,1,8);
        }
        else
        if (bestformat&WAVE_FORMAT_2S16)
        {
                DEV_Freq=22050;
                DEV_Mode=DM_16bit+DM_Stereo+DM_Mixed+DM_Signed;
                return CheckDevice(UseDevice,22050,2,16);
        }
        else
        if (bestformat&WAVE_FORMAT_2S08)
        {
                DEV_Freq=22050;
                DEV_Mode=DM_8bit+DM_Stereo+DM_Mixed;
                return CheckDevice(UseDevice,22050,2,8);
        }
        else
        if (bestformat&WAVE_FORMAT_2M16)
        {
                DEV_Freq=22050;
                DEV_Mode=DM_16bit+DM_Mono+DM_Mixed+DM_Signed;
                return CheckDevice(UseDevice,22050,1,16);
        }
        else
        if (bestformat&WAVE_FORMAT_2M08)
        {
                DEV_Freq=22050;
                DEV_Mode=DM_8bit+DM_Mono+DM_Mixed;
                return CheckDevice(UseDevice,22050,1,8);
        }
        else
        if (bestformat&WAVE_FORMAT_1S16)
        {
                DEV_Freq=11025;
                DEV_Mode=DM_16bit+DM_Stereo+DM_Mixed+DM_Signed;
                return CheckDevice(UseDevice,11025,2,16);
        }
        else
        if (bestformat&WAVE_FORMAT_1S08)
        {
                DEV_Freq=11025;
                DEV_Mode=DM_8bit+DM_Stereo+DM_Mixed;
                return CheckDevice(UseDevice,11025,2,8);
        }
        else
        if (bestformat&WAVE_FORMAT_1M16)
        {
                DEV_Freq=11025;
                DEV_Mode=DM_16bit+DM_Mono+DM_Mixed+DM_Signed;
                return CheckDevice(UseDevice,11025,1,16);
        }
        else
        if (bestformat&WAVE_FORMAT_1M08)
        {
                DEV_Freq=11025;
                DEV_Mode=DM_8bit+DM_Mono+DM_Mixed;
                return CheckDevice(UseDevice,11025,1,8);
        }
		UseDevice=(unsigned int)-1;
	return 1;
};
Esempio n. 13
0
HRESULT KG3DGraphicsEngine::SetDeviceSettings(KG3DDeviceSettings* pSettings)
{
	HRESULT hr = E_FAIL;
    HRESULT hrResult = E_FAIL;
    UINT uAdapter = D3DADAPTER_DEFAULT;
    D3DDEVTYPE DeviceType = D3DDEVTYPE_HAL;
    KG3DDeviceSettings Settings;

    KGLOG_PROCESS_ERROR(pSettings);

	pSettings->nMultiSampleType = min(4,pSettings->nMultiSampleType);

    memcpy(&Settings, pSettings, sizeof(KG3DDeviceSettings));

    hr = GetAdapater(&uAdapter, &DeviceType);
    KGLOG_COM_PROCESS_ERROR(hr);

    hr = g_cEngineOptionCaps.GetAdaperModeCaps(uAdapter, m_DisplayMode.Format);
    KGLOG_COM_PROCESS_ERROR(hr);

    hr = SetPresentParam(uAdapter, DeviceType, &m_PresentParam, &Settings);
    KGLOG_COM_PROCESS_ERROR(hr);

	memcpy(&m_DeviceSettings, &Settings, sizeof(m_DeviceSettings));
	g_cEngineOption.bUseRenderTarget_DepthTexture = g_cGraphicsEngine.m_PresentParam.MultiSampleType != D3DMULTISAMPLE_NONE;
	
	//Testing Packing Type;
	g_nDepthTexturePackingType = 0;
	if (g_cEngineOption.bUseRenderTarget_DepthTexture)
	{
		g_nDepthTexturePackingType = CheckDepthTexturePackingType(uAdapter,DeviceType);
		LPCTSTR strPackType = NULL;
		switch (g_nDepthTexturePackingType)
		{
		case 0:
			strPackType = _T("0");
			break;
		case 1:
			strPackType = _T("1");
			break;
		default:
			strPackType = _T("0");
			break;
		}
		D3DXMACRO macroPackType[] = {
			{_T("PACKTYPE"), strPackType},	
			{NULL, NULL},
		};
		D3DXMACRO_ARRAY macroArray = {macroPackType, _countof(macroPackType)};
		g_GetDefaultShaderGroup().ModifyGlobalMacro(macroArray);
	}

	//要求原来的设备还在。虽然是在创建设备前,但是因为改变了抗锯齿,而抗锯齿和其他postrender会有冲突,所以,先检查。
	g_cEngineManager.SetEngineOption(&g_cEngineOption);

    hr = Reset();
    if (hr == D3DERR_DEVICELOST)
    {
        do
        {
            hr = CheckDevice();
        }
        while (hr == D3DERR_DEVICELOST);
    }
    KG_COM_PROCESS_ERROR(hr);

	//////////////////
//	DWORD dwHeight = 0,dwWidth = 0;
	IEKG3DScene* pScene = g_cGraphicsTool.GetScene();
	if (pScene)
	{
		IEKG3DSceneOutputWnd* pOutputWindow = NULL;
		pScene->GetCurOutputWnd(&pOutputWindow);
		if (pOutputWindow)
		{
			KG3DSceneOutputWnd* pWnd = static_cast<KG3DSceneOutputWnd*>(pOutputWindow);
			pWnd->OnResizeWindow(&(pWnd->m_Rect));
		}
	}
	/////////////////
    if (m_PresentParam.MultiSampleType == D3DMULTISAMPLE_NONE && !g_b3DVision)
    {
        hr = g_pd3dDevice->SetDialogBoxMode(!m_PresentParam.Windowed);
        KGLOG_COM_PROCESS_ERROR(hr);
    }

    hrResult = S_OK;
Exit0:
    if (FAILED(hrResult))
    {
        if (hr == D3DERR_DEVICELOST)
            m_bDeviceLost = true;
        else
            KGLOG_COM_CHECK_ERROR(hr);

        hrResult = hr;
    }
	if (pSettings)
		memcpy(pSettings, &m_DeviceSettings, sizeof(m_DeviceSettings));
	return hrResult;
}
Esempio n. 14
0
static int SynoddOne(char *szDev, BOOL blRead)
{
	int err = -1;
	int fd = -1;
	int counts = 0;
	ssize_t lProgressBytes = 0;
	unsigned long long ullProgTotalBytes = 0;
	unsigned long long ullTotalBytes = 0;
	FILE *fp = NULL;

	if (!szDev) {
		return -1;
	}
	
	if (0 > (fd = OpenDevice(szDev, blRead, 0))){
		err = errno;
		goto END;
	}

	if (0 > CheckDevice(fd, &ullTotalBytes)){
		err = errno;
		syslog(LOG_ERR, "%s(%d) failed to check [%s].", __FILE__, __LINE__, szDev);
		goto END;
	}

	//Open Progress File
	if (NULL == (fp = OpenProgress(szDev))) {
		goto END;
	}

	err = 0;
	while(1) {
		if (COUNTS_TO_CHECK == counts) {
			counts = 0;
			
			if (fd >= 0) {
				close(fd);
			}
			if (0 > (fd = OpenDevice(szDev, blRead, ullProgTotalBytes))){
				err = errno;
				goto END;
			}
		}
		if (blRead) {
			lProgressBytes = read(fd, gszBuf, sizeof(gszBuf));
		} else {
			lProgressBytes = write(fd, gszBuf, sizeof(gszBuf));
		}
		if (0 > lProgressBytes) {
			if (ENOSPC != errno) {
				syslog(LOG_ERR, "(%s/%d) %s [%s] failed, errno=%m"
					   ,__FILE__ ,__LINE__ , blRead?"read":"write", szDev);
				err = errno;
			}
			goto END;
		}
		ullProgTotalBytes += lProgressBytes;

		WriteProgress(fp, ullProgTotalBytes, ullTotalBytes);
		if (ullTotalBytes <= ullProgTotalBytes) {
			break;
		}

		counts++;
	}
END:
	if (0 <= fd) close(fd);
	if (NULL != fp) fclose(fp);
	return err;
}