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