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; \
45  ++it; } while(false)
46 
47 #define PARSE_CONF(VAR) do { \
48  if (it == tokens.end() || !(VAR).ParseConf(*it++)) \
49  return false; } while(false)
50 
51 #define PARSE_STR(VAR) do { \
52  if (it != tokens.end()) (VAR) = *it++; else return false; } while(false)
53 
54 #define PARSE_UINT(VAR) do { \
55  if (it != tokens.end()) \
56  (VAR) = (*it++).toUInt(); else return false; } while(false)
57 
58 #define PARSE_UINT_1000(VAR) do { \
59  if (it != tokens.end()) \
60  (VAR) = (*it++).toUInt() * 1000ULL; else return false; } while(false)
61 
62 
63 QString DTVChannelInfo::toString() const
64 {
65  return QString("%1 %2 %3 ").arg(m_name).arg(m_serviceid).arg(m_lcn);
66 }
67 
69 {
70  m_channels.clear();
71 
72  QFile file(m_filename);
73  if (!file.open(QIODevice::ReadOnly))
74  return ERROR_OPEN;
75 
76  bool ok = true;
77  QTextStream stream(&file);
78  QString line;
79  while (!stream.atEnd())
80  {
81  line = stream.readLine(); // line of text excluding '\n'
82  line = line.trimmed();
83  if (line.startsWith("#"))
84  continue;
85 
86 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
87  QStringList list = line.split(":", QString::SkipEmptyParts);
88 #else
89  QStringList list = line.split(":", Qt::SkipEmptyParts);
90 #endif
91 
92  if (list.empty())
93  continue;
94 
95  QString str = list[0];
96  int channelNo = -1;
97 
98  if ((str.length() >= 1) && (str.at(0) == '@'))
99  {
100  channelNo = str.mid(1).toInt();
101  line = stream.readLine();
102 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
103  list = line.split(":", QString::SkipEmptyParts);
104 #else
105  list = line.split(":", Qt::SkipEmptyParts);
106 #endif
107  }
108 
109  if (list.size() < 4)
110  continue;
111 
112  str = list[3];
113 
114  if ((str == "T") || (str == "C") || (str == "S"))
115  {
116  if (((m_type == OFDM) && (str == "T")) ||
117  ((m_type == QPSK || m_type == DVBS2) && (str == "S")) ||
118  ((m_type == QAM) && (str == "C")))
119  ok &= ParseVDR(list, channelNo);
120  }
121  else if (m_type == OFDM)
122  ok &= ParseConfOFDM(list);
123  else if (m_type == ATSC)
124  ok &= ParseConfATSC(list);
125  else if (m_type == QPSK || m_type == DVBS2)
126  ok &= ParseConfQPSK(list);
127  else if (m_type == QAM)
128  ok &= ParseConfQAM(list);
129  }
130  file.close();
131 
132  return (ok) ? OK : ERROR_PARSE;
133 }
134 
135 bool DTVConfParser::ParseConfOFDM(const QStringList &tokens)
136 {
137  DTVChannelInfo chan;
138  DTVMultiplex mux;
139 
140  QStringList::const_iterator it = tokens.begin();
141 
142  PARSE_SKIP(unknown);
143  PARSE_UINT(mux.m_frequency);
144  PARSE_CONF(mux.m_inversion);
145  PARSE_CONF(mux.m_bandwidth);
149  PARSE_CONF(mux.m_transMode);
151  PARSE_CONF(mux.m_hierarchy);
152  PARSE_SKIP(unknown);
153  PARSE_SKIP(unknown);
154  PARSE_UINT(chan.m_serviceid);
155 
156  AddChannel(mux, chan);
157 
158  return true;
159 }
160 
161 bool DTVConfParser::ParseConfATSC(const QStringList &tokens)
162 {
163  DTVChannelInfo chan;
164  DTVMultiplex mux;
165 
166  QStringList::const_iterator it = tokens.begin();
167 
168  PARSE_STR(chan.m_name);
169  PARSE_UINT(mux.m_frequency);
171  PARSE_SKIP(Ignore_Video_PID);
172  PARSE_SKIP(Ignore_Audio_PID);
173  PARSE_UINT(chan.m_serviceid);
174 
175  AddChannel(mux, chan);
176 
177  return true;
178 }
179 
180 bool DTVConfParser::ParseConfQAM(const QStringList &tokens)
181 {
182  DTVChannelInfo chan;
183  DTVMultiplex mux;
184 
185  QStringList::const_iterator it = tokens.begin();
186 
187  PARSE_SKIP(unknown);
188  PARSE_UINT(mux.m_frequency);
189  PARSE_CONF(mux.m_inversion);
191  PARSE_CONF(mux.m_fec);
193  PARSE_SKIP(unknown);
194  PARSE_SKIP(unknown);
195  PARSE_UINT(chan.m_serviceid);
196 
197  AddChannel(mux, chan);
198 
199  return true;
200 }
201 
202 bool DTVConfParser::ParseConfQPSK(const QStringList &tokens)
203 {
204  DTVChannelInfo chan;
205  DTVMultiplex mux;
206 
207  QStringList::const_iterator it = tokens.begin();
208 
209  PARSE_STR(chan.m_name);
211  PARSE_CONF(mux.m_polarity);
212  PARSE_SKIP(Satelite_Number);
214  PARSE_SKIP(unknown);
215  PARSE_SKIP(unknown);
216  PARSE_UINT(chan.m_serviceid);
217 
218  AddChannel(mux, chan);
219 
220  return true;
221 }
222 
223 bool DTVConfParser::ParseVDR(const QStringList &tokens, int channelNo)
224 {
225  DTVChannelInfo chan;
226  DTVMultiplex mux;
227 
228  QStringList::const_iterator it = tokens.begin();
229 
230  chan.m_lcn = channelNo;
231 
232 // BBC ONE:754166:I999B8C34D34M16T2G32Y0:T:27500:600:601, 602:0:0:4168:0:0:0
233 
234  PARSE_SKIP(unknown);
235 
237 
238  if (it == tokens.end())
239  return false;
240 
241  QString params = (*it++);
242  while (!params.isEmpty())
243  {
244  QString ori = params;
245  int s = (int) (params.toLatin1().constData()[0]);
246  params = params.mid(1);
247  switch (s)
248  {
249  case 'I':
250  mux.m_inversion.ParseVDR(params);
251  break;
252  case 'B':
253  mux.m_bandwidth.ParseVDR(params);
254  break;
255  case 'C':
256  mux.m_hpCodeRate.ParseVDR(params);
257  break;
258  case 'D':
259  mux.m_lpCodeRate.ParseVDR(params);
260  break;
261  case 'M':
262  mux.m_modulation.ParseVDR(params);
263  break;
264  case 'T':
265  mux.m_transMode.ParseVDR(params);
266  break;
267  case 'G':
268  mux.m_guardInterval.ParseVDR(params);
269  break;
270  case 'Y':
271  mux.m_hierarchy.ParseVDR(params);
272  break;
273  case 'V':
274  case 'H':
275  case 'R':
276  case 'L':
277  mux.m_polarity.ParseVDR(ori);
278  break;
279  case 'S':
280  mux.m_modSys.ParseVDR(params);
281  break;
282  case 'O':
283  mux.m_rolloff.ParseVDR(params);
284  break;
285  default:
286  return false;
287  }
288  }
289 
290  for (uint i = 0; i < 6; i++)
291  PARSE_SKIP(unknown);
292 
293  PARSE_UINT(chan.m_serviceid);
294 
295  AddChannel(mux, chan);
296 
297  return true;
298 }
299 
301 {
302  for (auto & channel : m_channels)
303  {
304  if (channel == mux)
305  {
306  channel.channels.push_back(chan);
307 
308  LOG(VB_GENERAL, LOG_INFO, "Imported channel: " + chan.toString() +
309  " on " + mux.toString());
310  return;
311  }
312  }
313 
314  m_channels.push_back(DTVTransport(mux));
315  m_channels.back().channels.push_back(chan);
316 
317  LOG(VB_GENERAL, LOG_INFO, "Imported channel: " + chan.toString() +
318  " on " + mux.toString());
319 }
DTVInversion::ParseVDR
bool ParseVDR(const QString &_value)
Definition: dtvconfparserhelpers.h:200
DTVMultiplex::m_frequency
uint64_t m_frequency
Definition: dtvmultiplex.h:94
DTVMultiplex
Definition: dtvmultiplex.h:24
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:161
DTVConfParser::ERROR_OPEN
@ ERROR_OPEN
Definition: dtvconfparser.h:76
mythdbcon.h
DTVChannelInfo::toString
QString toString() const
Definition: dtvconfparser.cpp:63
DTVConfParser::ATSC
@ ATSC
Definition: dtvconfparser.h:77
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:627
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:77
DTVMultiplex::m_inversion
DTVInversion m_inversion
Definition: dtvmultiplex.h:96
DTVConfParser::DVBS2
@ DVBS2
Definition: dtvconfparser.h:77
DTVConfParser::ParseConfQPSK
bool ParseConfQPSK(const QStringList &tokens)
Definition: dtvconfparser.cpp:202
mythlogging.h
DTVMultiplex::m_guardInterval
DTVGuardInterval m_guardInterval
Definition: dtvmultiplex.h:102
DTVGuardInterval::ParseVDR
bool ParseVDR(const QString &_value)
Definition: dtvconfparserhelpers.h:535
DTVChannelInfo::m_name
QString m_name
Definition: dtvconfparser.h:54
DTVChannelInfo::m_serviceid
uint m_serviceid
Definition: dtvconfparser.h:55
DTVConfParser::OK
@ OK
Definition: dtvconfparser.h:76
DTVConfParser::m_filename
QString m_filename
Definition: dtvconfparser.h:98
DTVMultiplex::m_hpCodeRate
DTVCodeRate m_hpCodeRate
Definition: dtvmultiplex.h:98
DTVBandwidth::ParseVDR
bool ParseVDR(const QString &_value)
Definition: dtvconfparserhelpers.h:263
PARSE_STR
#define PARSE_STR(VAR)
Definition: dtvconfparser.cpp:51
DTVConfParser::ERROR_PARSE
@ ERROR_PARSE
Definition: dtvconfparser.h:76
DTVModulation::ParseVDR
bool ParseVDR(const QString &_value)
Definition: dtvconfparserhelpers.h:407
DTVMultiplex::m_modSys
DTVModulationSystem m_modSys
Definition: dtvmultiplex.h:106
DTVConfParser::m_type
cardtype_t m_type
Definition: dtvconfparser.h:96
DTVMultiplex::m_fec
DTVCodeRate m_fec
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:77
channelutil.h
DTVConfParser::QPSK
@ QPSK
Definition: dtvconfparser.h:77
DTVTransmitMode::ParseVDR
bool ParseVDR(const QString &_value)
Definition: dtvconfparserhelpers.h:470
DTVMultiplex::m_symbolRate
uint64_t m_symbolRate
Definition: dtvmultiplex.h:95
PARSE_UINT_1000
#define PARSE_UINT_1000(VAR)
Definition: dtvconfparser.cpp:58
DTVConfParser::AddChannel
void AddChannel(const DTVMultiplex &mux, DTVChannelInfo &chan)
Definition: dtvconfparser.cpp:300
DTVHierarchy::ParseVDR
bool ParseVDR(const QString &_value)
Definition: dtvconfparserhelpers.h:588
DTVConfParser::Parse
return_t Parse(void)
Definition: dtvconfparser.cpp:68
DTVCodeRate::ParseVDR
bool ParseVDR(const QString &_value)
Definition: dtvconfparserhelpers.h:336
DTVConfParser::m_channels
DTVChannelList m_channels
Definition: dtvconfparser.h:102
mythcontext.h
DTVTransport
Definition: dtvconfparser.h:60
DTVMultiplex::m_modulation
DTVModulation m_modulation
Definition: dtvmultiplex.h:100
PARSE_CONF
#define PARSE_CONF(VAR)
Definition: dtvconfparser.cpp:47
DTVMultiplex::m_polarity
DTVPolarity m_polarity
Definition: dtvmultiplex.h:104
DTVConfParser::return_t
return_t
Definition: dtvconfparser.h:76
DTVChannelInfo::m_lcn
int m_lcn
Definition: dtvconfparser.h:56
dtvconfparser.h
PARSE_UINT
#define PARSE_UINT(VAR)
Definition: dtvconfparser.cpp:54
DTVConfParser::ParseConfQAM
bool ParseConfQAM(const QStringList &tokens)
Definition: dtvconfparser.cpp:180
DTVMultiplex::m_transMode
DTVTransmitMode m_transMode
Definition: dtvmultiplex.h:101
DTVChannelInfo
Definition: dtvconfparser.h:47
PARSE_SKIP
#define PARSE_SKIP(VAR)
Definition: dtvconfparser.cpp:43
DTVConfParser::ParseVDR
bool ParseVDR(const QStringList &tokens, int channelNo=-1)
Definition: dtvconfparser.cpp:223
DTVConfParser::ParseConfOFDM
bool ParseConfOFDM(const QStringList &tokens)
Definition: dtvconfparser.cpp:135
DTVMultiplex::m_lpCodeRate
DTVCodeRate m_lpCodeRate
Definition: dtvmultiplex.h:99