00001
00002 #include <qdeepcopy.h>
00003
00004
00005 #include "dtvmultiplex.h"
00006 #include "mythcontext.h"
00007 #include "mythdbcon.h"
00008
00009 #define LOC QString("DTVMux: ")
00010 #define LOC_ERR QString("DTVMux, Error: ")
00011 #define LOC_WARN QString("DTVMux, Warning: ")
00012
00013
00014 DTVMultiplex &DTVMultiplex::operator=(const DTVMultiplex &other)
00015 {
00016 frequency = other.frequency;
00017 symbolrate = other.symbolrate;
00018 inversion = other.inversion;
00019 bandwidth = other.bandwidth;
00020 hp_code_rate = other.hp_code_rate;
00021 lp_code_rate = other.lp_code_rate;
00022 modulation = other.modulation;
00023 trans_mode = other.trans_mode;
00024 guard_interval = other.guard_interval;
00025 hierarchy = other.hierarchy;
00026 polarity = other.polarity;
00027 fec = other.fec;
00028 mplex = other.mplex;
00029 sistandard = QDeepCopy<QString>(other.sistandard);
00030 return *this;
00031 }
00032
00033 bool DTVMultiplex::operator==(const DTVMultiplex &m) const
00034 {
00035 return ((frequency == m.frequency) &&
00036 (modulation == m.modulation) &&
00037 (inversion == m.inversion) &&
00038 (bandwidth == m.bandwidth) &&
00039 (hp_code_rate == m.hp_code_rate) &&
00040 (lp_code_rate == m.lp_code_rate) &&
00041 (trans_mode == m.trans_mode) &&
00042 (guard_interval == m.guard_interval) &&
00043 (fec == m.fec) &&
00044 (polarity == m.polarity) &&
00045 (hierarchy == m.hierarchy));
00046 }
00047
00049
00050
00051 QString DTVMultiplex::toString() const
00052 {
00053 QString ret = QString("%1 %2 %3 ")
00054 .arg(frequency).arg(modulation.toString()).arg(inversion.toString());
00055
00056 ret += QString("%1 %2 %3 %4 %5 %6 %7")
00057 .arg(hp_code_rate.toString()).arg(lp_code_rate.toString())
00058 .arg(bandwidth.toString()).arg(trans_mode.toString())
00059 .arg(guard_interval.toString()).arg(hierarchy.toString())
00060 .arg(polarity.toString());
00061
00062 return ret;
00063 }
00064
00065 bool DTVMultiplex::IsEqual(DTVTunerType type, const DTVMultiplex &other,
00066 uint freq_range) const
00067 {
00068 if ((frequency + freq_range < other.frequency ) ||
00069 (frequency > other.frequency + freq_range))
00070 {
00071 return false;
00072 }
00073
00074 if (DTVTunerType::kTunerTypeQAM == type)
00075 {
00076 return
00077 (inversion == other.inversion) &&
00078 (symbolrate == other.symbolrate) &&
00079 (fec == other.fec) &&
00080 (modulation == other.modulation);
00081 }
00082
00083 if (DTVTunerType::kTunerTypeOFDM == type)
00084 {
00085 return
00086 (inversion == other.inversion) &&
00087 (bandwidth == other.bandwidth) &&
00088 (hp_code_rate == other.hp_code_rate) &&
00089 (lp_code_rate == other.lp_code_rate) &&
00090 (modulation == other.modulation) &&
00091 (guard_interval == other.guard_interval) &&
00092 (trans_mode == other.trans_mode) &&
00093 (hierarchy == other.hierarchy);
00094 }
00095
00096 if (DTVTunerType::kTunerTypeATSC == type)
00097 {
00098 return (modulation == other.modulation);
00099 }
00100
00101 if ((DTVTunerType::kTunerTypeDVB_S2 == type) ||
00102 (DTVTunerType::kTunerTypeQPSK == type))
00103 {
00104 return
00105 (inversion == other.inversion) &&
00106 (symbolrate == other.symbolrate) &&
00107 (fec == other.fec);
00108 }
00109
00110 return false;
00111 }
00112
00114
00115
00116 bool DTVMultiplex::ParseATSC(const QString &_frequency,
00117 const QString &_modulation)
00118 {
00119 bool ok = true;
00120 frequency = _frequency.toUInt(&ok);
00121 return ok && modulation.Parse(_modulation);
00122 }
00123
00124 bool DTVMultiplex::ParseDVB_T(
00125 const QString &_frequency, const QString &_inversion,
00126 const QString &_bandwidth, const QString &_coderate_hp,
00127 const QString &_coderate_lp, const QString &_modulation,
00128 const QString &_trans_mode, const QString &_guard_interval,
00129 const QString &_hierarchy)
00130 {
00131 bool ok = inversion.Parse(_inversion);
00132 if (!ok)
00133 {
00134 VERBOSE(VB_GENERAL, LOC_WARN +
00135 "Invalid inversion, falling back to 'auto'.");
00136 ok = true;
00137 }
00138
00139 ok &= bandwidth.Parse(_bandwidth);
00140 ok &= hp_code_rate.Parse(_coderate_hp);
00141 ok &= lp_code_rate.Parse(_coderate_lp);
00142 ok &= modulation.Parse(_modulation);
00143 ok &= trans_mode.Parse(_trans_mode);
00144 ok &= hierarchy.Parse(_hierarchy);
00145 ok &= guard_interval.Parse(_guard_interval);
00146 if (ok)
00147 frequency = _frequency.toInt(&ok);
00148
00149 return ok;
00150 }
00151
00152 bool DTVMultiplex::ParseDVB_S_and_C(
00153 const QString &_frequency, const QString &_inversion,
00154 const QString &_symbol_rate, const QString &_fec_inner,
00155 const QString &_modulation, const QString &_polarity)
00156 {
00157 bool ok = inversion.Parse(_inversion);
00158 if (!ok)
00159 {
00160 VERBOSE(VB_GENERAL, LOC_WARN +
00161 "Invalid inversion, falling back to 'auto'");
00162
00163 ok = true;
00164 }
00165
00166 symbolrate = _symbol_rate.toInt();
00167 if (!symbolrate)
00168 {
00169 VERBOSE(VB_IMPORTANT, LOC_ERR + "Invalid symbol rate " +
00170 QString("parameter '%1', aborting.").arg(_symbol_rate));
00171
00172 return false;
00173 }
00174
00175 ok &= fec.Parse(_fec_inner);
00176 ok &= modulation.Parse(_modulation);
00177
00178 if (!_polarity.isEmpty())
00179 polarity.Parse(_polarity.lower());
00180
00181 if (ok)
00182 frequency = _frequency.toInt(&ok);
00183
00184 return ok;
00185 }
00186
00187 bool DTVMultiplex::ParseTuningParams(
00188 DTVTunerType type,
00189 QString _frequency, QString _inversion, QString _symbolrate,
00190 QString _fec, QString _polarity,
00191 QString _hp_code_rate, QString _lp_code_rate, QString _ofdm_modulation,
00192 QString _trans_mode, QString _guard_interval, QString _hierarchy,
00193 QString _modulation, QString _bandwidth)
00194 {
00195 if (DTVTunerType::kTunerTypeOFDM == type)
00196 {
00197 return ParseDVB_T(
00198 _frequency, _inversion, _bandwidth, _hp_code_rate,
00199 _lp_code_rate, _ofdm_modulation, _trans_mode, _guard_interval,
00200 _hierarchy);
00201 }
00202
00203 if ((DTVTunerType::kTunerTypeQPSK == type) ||
00204 (DTVTunerType::kTunerTypeDVB_S2 == type) ||
00205 (DTVTunerType::kTunerTypeQAM == type))
00206 {
00207 return ParseDVB_S_and_C(
00208 _frequency, _inversion, _symbolrate,
00209 _fec, _modulation, _polarity);
00210 }
00211
00212 if (DTVTunerType::kTunerTypeATSC == type)
00213 return ParseATSC(_frequency, _modulation);
00214
00215 return false;
00216 }
00217
00218 bool DTVMultiplex::FillFromDB(DTVTunerType type, uint mplexid)
00219 {
00220 Clear();
00221
00222 MSqlQuery query(MSqlQuery::InitCon());
00223 query.prepare(
00224 "SELECT frequency, inversion, symbolrate, "
00225 " fec, polarity, "
00226 " hp_code_rate, lp_code_rate, constellation, "
00227 " transmission_mode, guard_interval, hierarchy, "
00228 " modulation, bandwidth, sistandard "
00229 "FROM dtv_multiplex "
00230 "WHERE dtv_multiplex.mplexid = :MPLEXID");
00231 query.bindValue(":MPLEXID", mplexid);
00232
00233 if (!query.exec() || !query.isActive())
00234 {
00235 MythContext::DBError("DVBTuning::FillFromDB", query);
00236 return false;
00237 }
00238
00239 if (!query.next())
00240 {
00241 VERBOSE(VB_IMPORTANT, LOC_ERR +
00242 QString("Could not find tuning parameters for mplex %1")
00243 .arg(mplexid));
00244
00245 return false;
00246 }
00247
00248 mplex = mplexid;
00249 sistandard = QDeepCopy<QString>(query.value(13).toString());
00250
00251
00252 return ParseTuningParams(
00253 type,
00254 query.value(0).toString(), query.value(1).toString(),
00255 query.value(2).toString(), query.value(3).toString(),
00256 query.value(4).toString(), query.value(5).toString(),
00257 query.value(6).toString(), query.value(7).toString(),
00258 query.value(8).toString(), query.value(9).toString(),
00259 query.value(10).toString(), query.value(11).toString(),
00260 query.value(12).toString());
00261 }