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  QStringList list = line.split(":", QString::SkipEmptyParts);
86 
87  if (list.empty())
88  continue;
89 
90  QString str = list[0];
91  int channelNo = -1;
92 
93  if ((str.length() >= 1) && (str.at(0) == '@'))
94  {
95  channelNo = str.mid(1).toInt();
96  line = stream.readLine();
97  list = line.split(":", QString::SkipEmptyParts);
98  }
99 
100  if (list.size() < 4)
101  continue;
102 
103  str = list[3];
104 
105  if ((str == "T") || (str == "C") || (str == "S"))
106  {
107  if ((m_type == OFDM) && (str == "T"))
108  ok &= ParseVDR(list, channelNo);
109  else if ((m_type == QPSK || m_type == DVBS2) && (str == "S"))
110  ok &= ParseVDR(list, channelNo);
111  else if ((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);
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_hp_code_rate.ParseVDR(params);
250  break;
251  case 'D':
252  mux.m_lp_code_rate.ParseVDR(params);
253  break;
254  case 'M':
255  mux.m_modulation.ParseVDR(params);
256  break;
257  case 'T':
258  mux.m_trans_mode.ParseVDR(params);
259  break;
260  case 'G':
261  mux.m_guard_interval.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_mod_sys.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 (size_t i = 0; i < m_channels.size(); i++)
296  {
297  if (m_channels[i] == mux)
298  {
299  m_channels[i].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.push_back(DTVTransport(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 }
uint64_t m_symbolrate
Definition: dtvmultiplex.h:95
cardtype_t m_type
Definition: dtvconfparser.h:98
DTVGuardInterval m_guard_interval
Definition: dtvmultiplex.h:102
bool ParseConfQPSK(const QStringList &tokens)
DTVBandwidth m_bandwidth
Definition: dtvmultiplex.h:97
DTVHierarchy m_hierarchy
Definition: dtvmultiplex.h:103
#define PARSE_SKIP(VAR)
DTVPolarity m_polarity
Definition: dtvmultiplex.h:104
bool ParseVDR(const QString &_value)
bool ParseVDR(const QString &_value)
return_t Parse(void)
bool ParseVDR(const QString &_value)
bool ParseConfQAM(const QStringList &tokens)
unsigned int uint
Definition: compat.h:140
DTVInversion m_inversion
Definition: dtvmultiplex.h:96
DTVCodeRate m_lp_code_rate
Low Priority FEC rate.
Definition: dtvmultiplex.h:99
bool ParseConfATSC(const QStringList &tokens)
bool ParseConfOFDM(const QStringList &tokens)
QString toString() const
DTVCodeRate m_fec
Inner Forward Error Correction rate.
Definition: dtvmultiplex.h:105
#define PARSE_STR(VAR)
DTVCodeRate m_hp_code_rate
High Priority FEC rate.
Definition: dtvmultiplex.h:98
DTVModulation m_modulation
Definition: dtvmultiplex.h:100
QString m_filename
bool ParseVDR(const QString &_value)
bool ParseVDR(const QString &_value)
bool ParseVDR(const QString &_value)
DTVRollOff m_rolloff
Definition: dtvmultiplex.h:107
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
#define PARSE_CONF(VAR)
#define PARSE_UINT(VAR)
void AddChannel(const DTVMultiplex &mux, DTVChannelInfo &chan)
#define PARSE_UINT_1000(VAR)
bool ParseVDR(const QStringList &tokens, int channelNo=-1)
bool ParseVDR(const QString &_value)
bool ParseVDR(const QString &_value)
QString toString() const
DTVModulationSystem m_mod_sys
Modulation system.
Definition: dtvmultiplex.h:106
DTVChannelList m_channels
uint64_t m_frequency
Definition: dtvmultiplex.h:94
DTVTransmitMode m_trans_mode
Definition: dtvmultiplex.h:101
bool ParseVDR(const QString &_value)
bool ParseVDR(const QString &_value)