MythTV  master
dtvconfparser.cpp
Go to the documentation of this file.
1 /*
2  * vim: set expandtab tabstop=4 shiftwidth=4:
3  *
4  * Original Project
5  * MythTV http://www.mythtv.org
6  *
7  * Author(s):
8  * John Pullan (john@pullan.org)
9  *
10  * Description:
11  * Collection of classes to provide dvb channel scanning
12  * functionallity
13  *
14  *
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License
17  * as published by the Free Software Foundation; either version 2
18  * of the License, or (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program; if not, write to the Free Software
27  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
28  * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
29  *
30  */
31 
32 // Qt headers
33 #include <QTextStream>
34 #include <QFile>
35 
36 // MythTV headers
37 #include "mythcontext.h"
38 #include "mythdbcon.h"
39 #include "mythlogging.h"
40 #include "dtvconfparser.h"
41 #include "channelutil.h"
42 
43 #define PARSE_SKIP(VAR) do { \
44  if (it == tokens.end()) return false; ++it; } while(false)
45 
46 #define PARSE_CONF(VAR) do { \
47  if (it == tokens.end() || !(VAR).ParseConf(*it++)) \
48  return false; } while(false)
49 
50 #define PARSE_STR(VAR) do { \
51  if (it != tokens.end()) (VAR) = *it++; else return false; } while(false)
52 
53 #define PARSE_UINT(VAR) do { \
54  if (it != tokens.end()) \
55  (VAR) = (*it++).toUInt(); else return false; } while(false)
56 
57 #define PARSE_UINT_1000(VAR) do { \
58  if (it != tokens.end()) \
59  (VAR) = (*it++).toUInt() * 1000ULL; else return false; } while(false)
60 
61 
62 QString DTVChannelInfo::toString() const
63 {
64  return QString("%1 %2 %3 ").arg(m_name).arg(m_serviceid).arg(m_lcn);
65 }
66 
68 {
69  m_channels.clear();
70 
71  QFile file(m_filename);
72  if (!file.open(QIODevice::ReadOnly))
73  return ERROR_OPEN;
74 
75  bool ok = true;
76  QTextStream stream(&file);
77  QString line;
78  while (!stream.atEnd())
79  {
80  line = stream.readLine(); // line of text excluding '\n'
81  line = line.trimmed();
82  if (line.startsWith("#"))
83  continue;
84 
85 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
86  QStringList list = line.split(":", QString::SkipEmptyParts);
87 #else
88  QStringList list = line.split(":", Qt::SkipEmptyParts);
89 #endif
90 
91  if (list.empty())
92  continue;
93 
94  QString str = list[0];
95  int channelNo = -1;
96 
97  if ((str.length() >= 1) && (str.at(0) == '@'))
98  {
99  channelNo = str.mid(1).toInt();
100  line = stream.readLine();
101 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
102  list = line.split(":", QString::SkipEmptyParts);
103 #else
104  list = line.split(":", Qt::SkipEmptyParts);
105 #endif
106  }
107 
108  if (list.size() < 4)
109  continue;
110 
111  str = list[3];
112 
113  if ((str == "T") || (str == "C") || (str == "S"))
114  {
115  if (((m_type == OFDM) && (str == "T")) ||
116  ((m_type == QPSK || m_type == DVBS2) && (str == "S")) ||
117  ((m_type == QAM) && (str == "C")))
118  ok &= ParseVDR(list, channelNo);
119  }
120  else if (m_type == OFDM)
121  ok &= ParseConfOFDM(list);
122  else if (m_type == ATSC)
123  ok &= ParseConfATSC(list);
124  else if (m_type == QPSK || m_type == DVBS2)
125  ok &= ParseConfQPSK(list);
126  else if (m_type == QAM)
127  ok &= ParseConfQAM(list);
128  }
129  file.close();
130 
131  return (ok) ? OK : ERROR_PARSE;
132 }
133 
134 bool DTVConfParser::ParseConfOFDM(const QStringList &tokens)
135 {
136  DTVChannelInfo chan;
137  DTVMultiplex mux;
138 
139  QStringList::const_iterator it = tokens.begin();
140 
141  PARSE_SKIP(unknown);
142  PARSE_UINT(mux.m_frequency);
143  PARSE_CONF(mux.m_inversion);
144  PARSE_CONF(mux.m_bandwidth);
148  PARSE_CONF(mux.m_transMode);
150  PARSE_CONF(mux.m_hierarchy);
151  PARSE_SKIP(unknown);
152  PARSE_SKIP(unknown);
153  PARSE_UINT(chan.m_serviceid);
154 
155  AddChannel(mux, chan);
156 
157  return true;
158 }
159 
160 bool DTVConfParser::ParseConfATSC(const QStringList &tokens)
161 {
162  DTVChannelInfo chan;
163  DTVMultiplex mux;
164 
165  QStringList::const_iterator it = tokens.begin();
166 
167  PARSE_STR(chan.m_name);
168  PARSE_UINT(mux.m_frequency);
170  PARSE_SKIP(Ignore_Video_PID);
171  PARSE_SKIP(Ignore_Audio_PID);
172  PARSE_UINT(chan.m_serviceid);
173 
174  AddChannel(mux, chan);
175 
176  return true;
177 }
178 
179 bool DTVConfParser::ParseConfQAM(const QStringList &tokens)
180 {
181  DTVChannelInfo chan;
182  DTVMultiplex mux;
183 
184  QStringList::const_iterator it = tokens.begin();
185 
186  PARSE_SKIP(unknown);
187  PARSE_UINT(mux.m_frequency);
188  PARSE_CONF(mux.m_inversion);
190  PARSE_CONF(mux.m_fec);
192  PARSE_SKIP(unknown);
193  PARSE_SKIP(unknown);
194  PARSE_UINT(chan.m_serviceid);
195 
196  AddChannel(mux, chan);
197 
198  return true;
199 }
200 
201 bool DTVConfParser::ParseConfQPSK(const QStringList &tokens)
202 {
203  DTVChannelInfo chan;
204  DTVMultiplex mux;
205 
206  QStringList::const_iterator it = tokens.begin();
207 
208  PARSE_STR(chan.m_name);
210  PARSE_CONF(mux.m_polarity);
211  PARSE_SKIP(Satelite_Number);
213  PARSE_SKIP(unknown);
214  PARSE_SKIP(unknown);
215  PARSE_UINT(chan.m_serviceid);
216 
217  AddChannel(mux, chan);
218 
219  return true;
220 }
221 
222 bool DTVConfParser::ParseVDR(const QStringList &tokens, int channelNo)
223 {
224  DTVChannelInfo chan;
225  DTVMultiplex mux;
226 
227  QStringList::const_iterator it = tokens.begin();
228 
229  chan.m_lcn = channelNo;
230 
231 // BBC ONE:754166:I999B8C34D34M16T2G32Y0:T:27500:600:601, 602:0:0:4168:0:0:0
232 
233  PARSE_SKIP(unknown);
234 
236 
237  if (it == tokens.end())
238  return false;
239 
240  QString params = (*it++);
241  while (!params.isEmpty())
242  {
243  QString ori = params;
244  int s = (int) (params.toLatin1().constData()[0]);
245  params = params.mid(1);
246  switch (s)
247  {
248  case 'I':
249  mux.m_inversion.ParseVDR(params);
250  break;
251  case 'B':
252  mux.m_bandwidth.ParseVDR(params);
253  break;
254  case 'C':
255  mux.m_hpCodeRate.ParseVDR(params);
256  break;
257  case 'D':
258  mux.m_lpCodeRate.ParseVDR(params);
259  break;
260  case 'M':
261  mux.m_modulation.ParseVDR(params);
262  break;
263  case 'T':
264  mux.m_transMode.ParseVDR(params);
265  break;
266  case 'G':
267  mux.m_guardInterval.ParseVDR(params);
268  break;
269  case 'Y':
270  mux.m_hierarchy.ParseVDR(params);
271  break;
272  case 'V':
273  case 'H':
274  case 'R':
275  case 'L':
276  mux.m_polarity.ParseVDR(ori);
277  break;
278  case 'S':
279  mux.m_modSys.ParseVDR(params);
280  break;
281  case 'O':
282  mux.m_rolloff.ParseVDR(params);
283  break;
284  default:
285  return false;
286  }
287  }
288 
289  for (uint i = 0; i < 6; i++)
290  PARSE_SKIP(unknown);
291 
292  PARSE_UINT(chan.m_serviceid);
293 
294  AddChannel(mux, chan);
295 
296  return true;
297 }
298 
300 {
301  for (auto & channel : m_channels)
302  {
303  if (channel == mux)
304  {
305  channel.channels.push_back(chan);
306 
307  LOG(VB_GENERAL, LOG_INFO, "Imported channel: " + chan.toString() +
308  " on " + mux.toString());
309  return;
310  }
311  }
312 
313  m_channels.push_back(DTVTransport(mux));
314  m_channels.back().channels.push_back(chan);
315 
316  LOG(VB_GENERAL, LOG_INFO, "Imported channel: " + chan.toString() +
317  " on " + mux.toString());
318 }
DTVInversion::ParseVDR
bool ParseVDR(const QString &_value)
Definition: dtvconfparserhelpers.h:198
DTVMultiplex::m_frequency
uint64_t m_frequency
Definition: dtvmultiplex.h:94
DTVMultiplex
Definition: dtvmultiplex.h:25
channel
QDomElement channel
Definition: mythplugins/mytharchive/mytharchivehelper/main.cpp:498
DTVRollOff::ParseVDR
bool ParseVDR(const QString &_value)
Definition: dtvconfparserhelpers.h:763
DTVMultiplex::m_rolloff
DTVRollOff m_rolloff
Definition: dtvmultiplex.h:107
DTVModulationSystem::ParseVDR
bool ParseVDR(const QString &_value)
Definition: dtvconfparserhelpers.h:714
DTVConfParser::ParseConfATSC
bool ParseConfATSC(const QStringList &tokens)
Definition: dtvconfparser.cpp:160
DTVConfParser::ERROR_OPEN
@ ERROR_OPEN
Definition: dtvconfparser.h:79
mythdbcon.h
DTVChannelInfo::toString
QString toString() const
Definition: dtvconfparser.cpp:62
DTVConfParser::ATSC
@ ATSC
Definition: dtvconfparser.h:80
DTVMultiplex::m_hierarchy
DTVHierarchy m_hierarchy
Definition: dtvmultiplex.h:103
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
DTVPolarity::ParseVDR
bool ParseVDR(const QString &_value)
Definition: dtvconfparserhelpers.h:625
DTVMultiplex::m_bandwidth
DTVBandwidth m_bandwidth
Definition: dtvmultiplex.h:97
build_compdb.file
file
Definition: build_compdb.py:55
DTVConfParser::QAM
@ QAM
Definition: dtvconfparser.h:80
DTVMultiplex::m_inversion
DTVInversion m_inversion
Definition: dtvmultiplex.h:96
DTVConfParser::DVBS2
@ DVBS2
Definition: dtvconfparser.h:80
DTVConfParser::ParseConfQPSK
bool ParseConfQPSK(const QStringList &tokens)
Definition: dtvconfparser.cpp:201
mythlogging.h
DTVMultiplex::m_guardInterval
DTVGuardInterval m_guardInterval
Definition: dtvmultiplex.h:102
DTVGuardInterval::ParseVDR
bool ParseVDR(const QString &_value)
Definition: dtvconfparserhelpers.h:533
DTVChannelInfo::m_name
QString m_name
Definition: dtvconfparser.h:57
DTVChannelInfo::m_serviceid
uint m_serviceid
Definition: dtvconfparser.h:58
DTVConfParser::OK
@ OK
Definition: dtvconfparser.h:79
DTVConfParser::m_filename
QString m_filename
Definition: dtvconfparser.h:101
DTVMultiplex::m_hpCodeRate
DTVCodeRate m_hpCodeRate
High Priority FEC rate.
Definition: dtvmultiplex.h:98
DTVBandwidth::ParseVDR
bool ParseVDR(const QString &_value)
Definition: dtvconfparserhelpers.h:261
PARSE_STR
#define PARSE_STR(VAR)
Definition: dtvconfparser.cpp:50
DTVConfParser::ERROR_PARSE
@ ERROR_PARSE
Definition: dtvconfparser.h:79
DTVModulation::ParseVDR
bool ParseVDR(const QString &_value)
Definition: dtvconfparserhelpers.h:405
DTVMultiplex::m_modSys
DTVModulationSystem m_modSys
Modulation system.
Definition: dtvmultiplex.h:106
DTVConfParser::m_type
cardtype_t m_type
Definition: dtvconfparser.h:99
DTVMultiplex::m_fec
DTVCodeRate m_fec
Inner Forward Error Correction rate.
Definition: dtvmultiplex.h:105
DTVMultiplex::toString
QString toString() const
Definition: dtvmultiplex.cpp:34
uint
unsigned int uint
Definition: compat.h:140
DTVConfParser::OFDM
@ OFDM
Definition: dtvconfparser.h:80
channelutil.h
DTVConfParser::QPSK
@ QPSK
Definition: dtvconfparser.h:80
DTVTransmitMode::ParseVDR
bool ParseVDR(const QString &_value)
Definition: dtvconfparserhelpers.h:468
DTVMultiplex::m_symbolRate
uint64_t m_symbolRate
Definition: dtvmultiplex.h:95
PARSE_UINT_1000
#define PARSE_UINT_1000(VAR)
Definition: dtvconfparser.cpp:57
DTVConfParser::AddChannel
void AddChannel(const DTVMultiplex &mux, DTVChannelInfo &chan)
Definition: dtvconfparser.cpp:299
DTVHierarchy::ParseVDR
bool ParseVDR(const QString &_value)
Definition: dtvconfparserhelpers.h:586
DTVConfParser::Parse
return_t Parse(void)
Definition: dtvconfparser.cpp:67
DTVCodeRate::ParseVDR
bool ParseVDR(const QString &_value)
Definition: dtvconfparserhelpers.h:334
DTVConfParser::m_channels
DTVChannelList m_channels
Definition: dtvconfparser.h:105
mythcontext.h
DTVTransport
Definition: dtvconfparser.h:64
DTVMultiplex::m_modulation
DTVModulation m_modulation
Definition: dtvmultiplex.h:100
PARSE_CONF
#define PARSE_CONF(VAR)
Definition: dtvconfparser.cpp:46
DTVMultiplex::m_polarity
DTVPolarity m_polarity
Definition: dtvmultiplex.h:104
DTVConfParser::return_t
return_t
Definition: dtvconfparser.h:79
DTVChannelInfo::m_lcn
int m_lcn
Definition: dtvconfparser.h:59
dtvconfparser.h
PARSE_UINT
#define PARSE_UINT(VAR)
Definition: dtvconfparser.cpp:53
DTVConfParser::ParseConfQAM
bool ParseConfQAM(const QStringList &tokens)
Definition: dtvconfparser.cpp:179
DTVMultiplex::m_transMode
DTVTransmitMode m_transMode
Definition: dtvmultiplex.h:101
DTVChannelInfo
Definition: dtvconfparser.h:51
PARSE_SKIP
#define PARSE_SKIP(VAR)
Definition: dtvconfparser.cpp:43
DTVConfParser::ParseVDR
bool ParseVDR(const QStringList &tokens, int channelNo=-1)
Definition: dtvconfparser.cpp:222
DTVConfParser::ParseConfOFDM
bool ParseConfOFDM(const QStringList &tokens)
Definition: dtvconfparser.cpp:134
DTVMultiplex::m_lpCodeRate
DTVCodeRate m_lpCodeRate
Low Priority FEC rate.
Definition: dtvmultiplex.h:99