bool DVBChannel::Open(DVBChannel *who) { LOG(VB_CHANNEL, LOG_INFO, LOC + "Opening DVB channel"); QMutexLocker locker(&hw_lock); if (fd_frontend >= 0) { is_open[who] = true; return true; } DVBChannel *master = GetMasterLock(); if (master != this) { if (!master->Open(who)) { ReturnMasterLock(master); return false; } fd_frontend = master->fd_frontend; frontend_name = master->frontend_name; tunerType = master->tunerType; capabilities = master->capabilities; ext_modulations = master->ext_modulations; frequency_minimum = master->frequency_minimum; frequency_maximum = master->frequency_maximum; symbol_rate_minimum = master->symbol_rate_minimum; symbol_rate_maximum = master->symbol_rate_maximum; is_open[who] = true; if (!InitializeInputs()) { Close(); ReturnMasterLock(master); return false; } ReturnMasterLock(master); return true; } ReturnMasterLock(master); // if we're the master we don't need this lock.. QString devname = CardUtil::GetDeviceName(DVB_DEV_FRONTEND, device); QByteArray devn = devname.toAscii(); for (int tries = 1; ; ++tries) { fd_frontend = open(devn.constData(), O_RDWR | O_NONBLOCK); if (fd_frontend >= 0) break; LOG(VB_GENERAL, LOG_WARNING, LOC + "Opening DVB frontend device failed." + ENO); if (tries >= 20 || (errno != EBUSY && errno != EAGAIN)) { LOG(VB_GENERAL, LOG_ERR, LOC + QString("Failed to open DVB frontend device due to " "fatal error or too many attempts.")); return false; } usleep(50000); } dvb_frontend_info info; memset(&info, 0, sizeof(info)); if (ioctl(fd_frontend, FE_GET_INFO, &info) < 0) { LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to get frontend information." + ENO); close(fd_frontend); fd_frontend = -1; return false; } frontend_name = info.name; tunerType = info.type; #if HAVE_FE_CAN_2G_MODULATION if (tunerType == DTVTunerType::kTunerTypeDVBS1 && (info.caps & FE_CAN_2G_MODULATION)) tunerType = DTVTunerType::kTunerTypeDVBS2; #endif // HAVE_FE_CAN_2G_MODULATION capabilities = info.caps; frequency_minimum = info.frequency_min; frequency_maximum = info.frequency_max; symbol_rate_minimum = info.symbol_rate_min; symbol_rate_maximum = info.symbol_rate_max; LOG(VB_RECORD, LOG_INFO, LOC + QString("Using DVB card %1, with frontend '%2'.") .arg(device).arg(frontend_name)); // Turn on the power to the LNB if (tunerType.IsDiSEqCSupported()) { diseqc_tree = diseqc_dev.FindTree(GetCardID()); if (diseqc_tree) diseqc_tree->Open(fd_frontend); } dvbcam->Start(); first_tune = true; if (!InitializeInputs()) { Close(); return false; } if (fd_frontend >= 0) is_open[who] = true; return (fd_frontend >= 0); }
bool DVBChannel::Open(DVBChannel *who) { LOG(VB_CHANNEL, LOG_INFO, LOC + "Opening DVB channel"); if (!m_inputid) { if (!InitializeInput()) return false; } QMutexLocker locker(&m_hw_lock); if (m_fd_frontend >= 0) { m_is_open[who] = true; return true; } DVBChannel *master = GetMasterLock(); if (master != this) { if (!master->Open(who)) { ReturnMasterLock(master); return false; } m_fd_frontend = master->m_fd_frontend; m_frontend_name = master->m_frontend_name; m_tunerType = master->m_tunerType; m_capabilities = master->m_capabilities; m_ext_modulations = master->m_ext_modulations; m_frequency_minimum = master->m_frequency_minimum; m_frequency_maximum = master->m_frequency_maximum; m_symbol_rate_minimum = master->m_symbol_rate_minimum; m_symbol_rate_maximum = master->m_symbol_rate_maximum; m_is_open[who] = true; if (!InitializeInput()) { Close(); ReturnMasterLock(master); return false; } ReturnMasterLock(master); return true; } ReturnMasterLock(master); // if we're the master we don't need this lock.. QString devname = CardUtil::GetDeviceName(DVB_DEV_FRONTEND, m_device); QByteArray devn = devname.toLatin1(); for (int tries = 1; ; ++tries) { m_fd_frontend = open(devn.constData(), O_RDWR | O_NONBLOCK); if (m_fd_frontend >= 0) break; LOG(VB_GENERAL, LOG_WARNING, LOC + "Opening DVB frontend device failed." + ENO); if (tries >= 20 || (errno != EBUSY && errno != EAGAIN)) { LOG(VB_GENERAL, LOG_ERR, LOC + QString("Failed to open DVB frontend device due to " "fatal error or too many attempts.")); return false; } usleep(50000); } dvb_frontend_info info; memset(&info, 0, sizeof(info)); if (ioctl(m_fd_frontend, FE_GET_INFO, &info) < 0) { LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to get frontend information." + ENO); close(m_fd_frontend); m_fd_frontend = -1; return false; } m_frontend_name = info.name; m_tunerType = info.type; #if HAVE_FE_CAN_2G_MODULATION if (info.caps & FE_CAN_2G_MODULATION) { if (m_tunerType == DTVTunerType::kTunerTypeDVBS1) m_tunerType = DTVTunerType::kTunerTypeDVBS2; else if (m_tunerType == DTVTunerType::kTunerTypeDVBT) m_tunerType = DTVTunerType::kTunerTypeDVBT2; } #endif // HAVE_FE_CAN_2G_MODULATION m_capabilities = info.caps; m_frequency_minimum = info.frequency_min; m_frequency_maximum = info.frequency_max; m_symbol_rate_minimum = info.symbol_rate_min; m_symbol_rate_maximum = info.symbol_rate_max; #if DVB_API_VERSION >=5 unsigned int i; struct dtv_property prop; struct dtv_properties cmd; memset(&prop, 0, sizeof(prop)); prop.cmd = DTV_API_VERSION; cmd.num = 1; cmd.props = ∝ if (ioctl(m_fd_frontend, FE_GET_PROPERTY, &cmd) == 0) { LOG(VB_RECORD, LOG_INFO, LOC + QString("dvb api version %1.%2").arg((prop.u.data>>8)&0xff).arg((prop.u.data)&0xff)); }