MythTV  master
channelutil.h
Go to the documentation of this file.
1 // -*- Mode: c++ -*-
2 #ifndef CHANUTIL_H
3 #define CHANUTIL_H
4 
5 // C++ headers
6 #include <cstdint>
7 #include <deque>
8 #include <vector>
9 using namespace std;
10 
11 // Qt headers
12 #include <QString>
13 #include <QCoreApplication>
14 
15 // MythTV headers
16 #include "mythtvexp.h"
17 #include "dtvmultiplex.h"
18 #include "channelinfo.h"
19 #include "iptvtuningdata.h"
20 #include "tv.h" // for CHANNEL_DIRECTION
21 
23 
25 {
26  public:
27  pid_cache_item_t() = default;
28  pid_cache_item_t(uint pid, uint sid_tid) :
29  m_pid(pid), m_sid_tid(sid_tid) {}
30  uint GetPID(void) const { return m_pid; }
31  uint GetStreamID(void) const
32  { return (m_sid_tid&0x100) ? GetID() : 0; }
33  uint GetTableID(void) const
34  { return (m_sid_tid&0x100) ? 0 : GetID(); }
35  uint GetID(void) const { return m_sid_tid & 0xff; }
36  bool IsPCRPID(void) const { return ( m_sid_tid&0x200 ) != 0; }
37  bool IsPermanent(void) const { return ( m_sid_tid&0x10000 ) != 0; }
38  uint GetComposite(void) const { return m_sid_tid; }
39  private:
40  uint m_pid {0};
41  uint m_sid_tid {0};
42 };
43 typedef vector<pid_cache_item_t> pid_cache_t;
44 
49 {
50  Q_DECLARE_TR_FUNCTIONS(ChannelUtil);
51 
52  public:
53  // Multiplex Stuff
54 
55  static uint CreateMultiplex(
56  int sourceid, const QString& sistandard,
57  uint64_t frequency, const QString& modulation,
58  int transport_id = -1, int network_id = -1);
59 
60  static uint CreateMultiplex(
61  int sourceid, const QString& sistandard,
62  uint64_t frequency, const QString& modulation,
63  // DVB specific
64  int transport_id, int network_id,
65  int symbol_rate, signed char bandwidth,
66  signed char polarity, signed char inversion,
67  signed char trans_mode,
68  const QString& inner_FEC, const QString& constellation,
69  signed char hierarchy, const QString& hp_code_rate,
70  const QString& lp_code_rate, const QString& guard_interval,
71  const QString& mod_sys, const QString& rolloff);
72 
73  static uint CreateMultiplex(uint sourceid, const DTVMultiplex&,
74  int transport_id, int network_id);
75 
76  static vector<uint> CreateMultiplexes(
77  int sourceid, const NetworkInformationTable *nit);
78 
79  static uint GetMplexID(uint sourceid, const QString &channum);
80  static int GetMplexID(uint sourceid, uint64_t frequency);
81  static int GetMplexID(uint sourceid, uint64_t frequency,
82  uint transport_id, uint network_id);
83  static int GetMplexID(uint sourceid,
84  uint transport_id, uint network_id);
85  static uint GetMplexID(uint chanid);
86  static int GetBetterMplexID(int current_mplexid,
87  int transport_id, int network_id);
88 
89  static bool GetTuningParams(uint mplexid,
90  QString &modulation,
91  uint64_t &frequency,
92  uint &dvb_transportid,
93  uint &dvb_networkid,
94  QString &si_std);
95 
96  static bool GetATSCChannel(uint sourceid, const QString &channum,
97  uint &major, uint &minor);
98  static bool IsATSCChannel(uint sourceid, const QString &channum)
99  { uint m1, m2; GetATSCChannel(sourceid, channum, m1,m2); return m2; }
100 
101  // Channel/Service Stuff
102  static int CreateChanID(uint sourceid, const QString &chan_num);
103 
104  static bool CreateChannel(uint db_mplexid,
105  uint db_sourceid,
106  uint new_channel_id,
107  const QString &callsign,
108  const QString &service_name,
109  const QString &chan_num,
110  uint service_id,
111  uint atsc_major_channel,
112  uint atsc_minor_channel,
113  bool use_on_air_guide,
114  bool hidden,
115  bool hidden_in_guide,
116  const QString &freqid,
117  const QString& icon = QString(),
118  QString format = "Default",
119  const QString& xmltvid = QString(),
120  const QString& default_authority = QString(),
121  uint service_type = 0);
122 
123  static bool UpdateChannel(uint db_mplexid,
124  uint source_id,
125  uint channel_id,
126  const QString &callsign,
127  const QString &service_name,
128  const QString &chan_num,
129  uint service_id,
130  uint atsc_major_channel,
131  uint atsc_minor_channel,
132  bool use_on_air_guide,
133  bool hidden,
134  bool hidden_in_guide,
135  const QString& freqid = QString(),
136  const QString& icon = QString(),
137  QString format = QString(),
138  const QString& xmltvid = QString(),
139  const QString& default_authority = QString(),
140  uint service_type = 0);
141 
142  static bool CreateIPTVTuningData(
143  uint channel_id, const IPTVTuningData &tuning)
144  {
145  return UpdateIPTVTuningData(channel_id, tuning);
146  }
147 
148  static bool UpdateIPTVTuningData(
149  uint channel_id, const IPTVTuningData &tuning);
150 
151  static void UpdateInsertInfoFromDB(ChannelInsertInfo &chan);
152  static void UpdateChannelNumberFromDB(ChannelInsertInfo &chan);
153 
154  static bool DeleteChannel(uint channel_id);
155 
156  static bool SetVisible(uint channel_id, bool visible);
157 
158  static bool SetServiceVersion(int mplexid, int version);
159 
160  static int GetChanID(int db_mplexid, int service_transport_id,
161  int major_channel, int minor_channel,
162  int program_number);
163 
164  static int GetServiceVersion(int mplexid);
165 
166  // Misc gets
167  static QString GetDefaultAuthority(uint chanid);
168  static QString GetIcon(uint chanid);
169  static vector<uint> GetInputIDs(uint chanid);
170  static QString GetUnknownCallsign(void);
171  static uint FindChannel(uint sourceid, const QString &freqid);
172  static int GetChanID(uint sourceid, const QString &channum)
173  { return GetChannelValueInt("chanid", sourceid, channum); }
174  static bool GetChannelData(
175  uint sourceid,
176  uint &chanid, const QString &channum,
177  QString &tvformat, QString &modulation,
178  QString &freqtable, QString &freqid,
179  int &finetune, uint64_t &frequency,
180  QString &dtv_si_std, int &mpeg_prog_num,
181  uint &atsc_major, uint &atsc_minor,
182  uint &dvb_transportid, uint &dvb_networkid,
183  uint &mplexid, bool &commfree);
184  static int GetProgramNumber(uint sourceid, const QString &channum)
185  { return GetChannelValueInt("serviceid", sourceid, channum); }
186  static QString GetVideoFilters(uint sourceid, const QString &channum)
187  { return GetChannelValueStr("videofilters", sourceid, channum); }
188  static IPTVTuningData GetIPTVTuningData(uint chanid);
189 
190  // Are there any other possibly useful sort orders?
191  // e.g. Sorting by sourceid would probably be better done by two distinct
192  // calls to LoadChannels specifying the sourceid
193  enum OrderBy
194  {
198  };
199 
200  enum GroupBy
201  {
203  kChanGroupByChanid // Because of the nature of the query we always need to group
204  };
205 
222  static ChannelInfoList LoadChannels(uint startIndex, uint count,
223  uint &totalAvailable,
224  bool ignoreHidden = true,
225  OrderBy orderBy = kChanOrderByChanNum,
226  GroupBy groupBy = kChanGroupByChanid,
227  uint sourceID = 0,
228  uint channelGroupID = 0,
229  bool liveTVOnly = false,
230  const QString& callsign = "",
231  const QString& channum = "",
232  bool ignoreUntunable = true);
233 
238  uint sourceid, bool visible_only,
239  const QString &group_by = QString(), uint channel_groupid = 0)
240  {
241  return GetChannelsInternal(sourceid, visible_only, false,
242  group_by, channel_groupid);
243  }
244 
247 
251  {
252  return GetChannelsInternal(sourceid, false, true, QString(), 0);
253  }
254  static vector<uint> GetChanIDs(int sourceid = -1, bool onlyVisible = false);
255  static uint GetChannelCount(int sourceid = -1);
256  static void SortChannels(ChannelInfoList &list, const QString &order,
257  bool eliminate_duplicates = false);
258  static int GetNearestChannel(const ChannelInfoList &list,
259  const QString &channum);
260 
261  static uint GetNextChannel(const ChannelInfoList &sorted,
262  uint old_chanid,
263  uint mplexid_restriction,
264  uint chanid_restriction,
265  ChannelChangeDirection direction,
266  bool skip_non_visible = true,
267  bool skip_same_channum_and_callsign = false);
268 
269  static QString GetChannelValueStr(const QString &channel_field,
270  uint sourceid,
271  const QString &channum);
272 
273  static int GetChannelValueInt(const QString &channel_field,
274  uint sourceid,
275  const QString &channum);
276 
277  static bool IsOnSameMultiplex(uint srcid,
278  const QString &new_channum,
279  const QString &old_channum);
280 
281  static QStringList GetValidRecorderList(uint chanid,
282  const QString &channum);
283 
284  static bool IsConflicting(const QString &channum,
285  uint sourceid = 0, uint excluded_chanid = 0)
286  {
287  vector<uint> chanids = GetConflicting(channum, sourceid);
288  return (chanids.size() > 1) ||
289  ((1 == chanids.size()) && (chanids[0] != excluded_chanid));
290  }
291 
292  static vector<uint> GetConflicting(const QString &channum,
293  uint sourceid = 0);
294 
299  static QString GetChanNum(int chan_id);
300 
305  static int GetTimeOffset(int chan_id);
306  static int GetSourceID(int mplexid);
307  static uint GetSourceIDForChannel(uint chanid);
308 
309  static QStringList GetInputTypes(uint chanid);
310 
311  static bool GetCachedPids(uint chanid, pid_cache_t &pid_cache);
312 
313  // Misc sets
314  static bool SetChannelValue(const QString &field_name,
315  const QString& value,
316  uint sourceid,
317  const QString &channum);
318 
319  static bool SetChannelValue(const QString &field_name,
320  const QString& value,
321  int chanid);
322 
323  static bool SaveCachedPids(uint chanid,
324  const pid_cache_t &_pid_cache,
325  bool delete_all = false);
326 
327  static const QString kATSCSeparators;
328 
329  private:
333  static ChannelInfoList GetChannelsInternal(
334  uint sourceid, bool visible_only, bool include_disconnected,
335  const QString &group_by, uint channel_groupid);
336  static QString GetChannelStringField(int chan_id, const QString &field);
337 };
338 
339 #endif // CHANUTIL_H
static ChannelInfoList GetAllChannels(uint sourceid)
Returns channels that are not connected to an input and channels that are not marked as visible.
Definition: channelutil.h:250
ChannelChangeDirection
ChannelChangeDirection is an enumeration of possible channel changing directions.
Definition: tv.h:28
Collection of helper utilities for channel DB use.
Definition: channelutil.h:48
vector< pid_cache_item_t > pid_cache_t
Definition: channelutil.h:43
static int GetProgramNumber(uint sourceid, const QString &channum)
Definition: channelutil.h:184
unsigned int uint
Definition: compat.h:140
pid_cache_item_t(uint pid, uint sid_tid)
Definition: channelutil.h:28
static int GetChanID(uint sourceid, const QString &channum)
Definition: channelutil.h:172
uint GetTableID(void) const
Definition: channelutil.h:33
bool IsPCRPID(void) const
Definition: channelutil.h:36
uint GetID(void) const
Definition: channelutil.h:35
#define MTV_PUBLIC
Definition: mythtvexp.h:15
static bool IsConflicting(const QString &channum, uint sourceid=0, uint excluded_chanid=0)
Definition: channelutil.h:284
static QString GetVideoFilters(uint sourceid, const QString &channum)
Definition: channelutil.h:186
static bool IsATSCChannel(uint sourceid, const QString &channum)
Definition: channelutil.h:98
#define minor(X)
Definition: compat.h:138
static ChannelInfoList GetChannels(uint sourceid, bool visible_only, const QString &group_by=QString(), uint channel_groupid=0)
Definition: channelutil.h:237
static bool CreateIPTVTuningData(uint channel_id, const IPTVTuningData &tuning)
Definition: channelutil.h:142
uint GetComposite(void) const
Definition: channelutil.h:38
vector< ChannelInfo > ChannelInfoList
Definition: channelinfo.h:121
bool IsPermanent(void) const
Definition: channelutil.h:37
This table tells the decoder on which PIDs to find other tables.
Definition: dvbtables.h:21
static const QString kATSCSeparators
Definition: channelutil.h:327
uint GetStreamID(void) const
Definition: channelutil.h:31
uint GetPID(void) const
Definition: channelutil.h:30