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_sidTid(sid_tid) {}
30  uint GetPID(void) const { return m_pid; }
31  uint GetStreamID(void) const
32  { return (m_sidTid&0x100) ? GetID() : 0; }
33  uint GetTableID(void) const
34  { return (m_sidTid&0x100) ? 0 : GetID(); }
35  uint GetID(void) const { return m_sidTid & 0xff; }
36  bool IsPCRPID(void) const { return ( m_sidTid&0x200 ) != 0; }
37  bool IsPermanent(void) const { return ( m_sidTid&0x10000 ) != 0; }
38  uint GetComposite(void) const { return m_sidTid; }
39  private:
40  uint m_pid {0};
41  uint m_sidTid {0};
42 };
43 using pid_cache_t = vector<pid_cache_item_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 &mux,
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  {
100  uint m1 = 0;
101  uint m2 = 0;
102  GetATSCChannel(sourceid, channum, m1,m2);
103  return m2 != 0U;
104  }
105 
106  // Channel/Service Stuff
107  static int CreateChanID(uint sourceid, const QString &chan_num);
108 
109  static bool CreateChannel(uint db_mplexid,
110  uint db_sourceid,
111  uint new_channel_id,
112  const QString &callsign,
113  const QString &service_name,
114  const QString &chan_num,
115  uint service_id,
116  uint atsc_major_channel,
117  uint atsc_minor_channel,
118  bool use_on_air_guide,
119  ChannelVisibleType visible,
120  const QString &freqid,
121  const QString& icon = QString(),
122  QString format = "Default",
123  const QString& xmltvid = QString(),
124  const QString& default_authority = QString(),
125  uint service_type = 0);
126 
127  static bool UpdateChannel(uint db_mplexid,
128  uint source_id,
129  uint channel_id,
130  const QString &callsign,
131  const QString &service_name,
132  const QString &chan_num,
133  uint service_id,
134  uint atsc_major_channel,
135  uint atsc_minor_channel,
136  bool use_on_air_guide,
137  ChannelVisibleType visible,
138  const QString& freqid = QString(),
139  const QString& icon = QString(),
140  QString format = QString(),
141  const QString& xmltvid = QString(),
142  const QString& default_authority = QString(),
143  uint service_type = 0);
144 
145  static bool CreateIPTVTuningData(
146  uint channel_id, const IPTVTuningData &tuning)
147  {
148  return UpdateIPTVTuningData(channel_id, tuning);
149  }
150 
151  static bool UpdateIPTVTuningData(
152  uint channel_id, const IPTVTuningData &tuning);
153 
154  static void UpdateInsertInfoFromDB(ChannelInsertInfo &chan);
155  static void UpdateChannelNumberFromDB(ChannelInsertInfo &chan);
156 
157  static bool DeleteChannel(uint channel_id);
158 
159  static bool SetVisible(uint channel_id, ChannelVisibleType visible);
160 
161  static bool SetServiceVersion(int mplexid, int version);
162 
163  static int GetChanID(int db_mplexid, int service_transport_id,
164  int major_channel, int minor_channel,
165  int program_number);
166 
167  static int GetServiceVersion(int mplexid);
168 
169  // Misc gets
170  static QString GetDefaultAuthority(uint chanid);
171  static QString GetIcon(uint chanid);
172  static vector<uint> GetInputIDs(uint chanid);
173  static QString GetUnknownCallsign(void);
174  static uint FindChannel(uint sourceid, const QString &freqid);
175  static int GetChanID(uint sourceid, const QString &channum)
176  { return GetChannelValueInt("chanid", sourceid, channum); }
177  static bool GetChannelData(
178  uint sourceid,
179  uint &chanid, const QString &channum,
180  QString &tvformat, QString &modulation,
181  QString &freqtable, QString &freqid,
182  int &finetune, uint64_t &frequency,
183  QString &dtv_si_std, int &mpeg_prog_num,
184  uint &atsc_major, uint &atsc_minor,
185  uint &dvb_transportid, uint &dvb_networkid,
186  uint &mplexid, bool &commfree);
187  static int GetProgramNumber(uint sourceid, const QString &channum)
188  { return GetChannelValueInt("serviceid", sourceid, channum); }
189  static QString GetVideoFilters(uint sourceid, const QString &channum)
190  { return GetChannelValueStr("videofilters", sourceid, channum); }
191  static IPTVTuningData GetIPTVTuningData(uint chanid);
192 
193  // Are there any other possibly useful sort orders?
194  // e.g. Sorting by sourceid would probably be better done by two distinct
195  // calls to LoadChannels specifying the sourceid
196  enum OrderBy
197  {
201  };
202 
203  enum GroupBy
204  {
206  kChanGroupByChanid // Because of the nature of the query we always need to group
207  };
208 
225  static ChannelInfoList LoadChannels(uint startIndex, uint count,
226  uint &totalAvailable,
227  bool ignoreHidden = true,
228  OrderBy orderBy = kChanOrderByChanNum,
229  GroupBy groupBy = kChanGroupByChanid,
230  uint sourceID = 0,
231  uint channelGroupID = 0,
232  bool liveTVOnly = false,
233  const QString& callsign = "",
234  const QString& channum = "",
235  bool ignoreUntunable = true);
236 
241  uint sourceid, bool visible_only,
242  const QString &group_by = QString(), uint channel_groupid = 0)
243  {
244  return GetChannelsInternal(sourceid, visible_only, false,
245  group_by, channel_groupid);
246  }
247 
250 
254  {
255  return GetChannelsInternal(sourceid, false, true, QString(), 0);
256  }
257  static vector<uint> GetChanIDs(int sourceid = -1, bool onlyVisible = false);
258  static uint GetChannelCount(int sourceid = -1);
259  static void SortChannels(ChannelInfoList &list, const QString &order,
260  bool eliminate_duplicates = false);
261  static int GetNearestChannel(const ChannelInfoList &list,
262  const QString &channum);
263 
264  static uint GetNextChannel(const ChannelInfoList &sorted,
265  uint old_chanid,
266  uint mplexid_restriction,
267  uint chanid_restriction,
268  ChannelChangeDirection direction,
269  bool skip_non_visible = true,
270  bool skip_same_channum_and_callsign = false);
271 
272  static QString GetChannelValueStr(const QString &channel_field,
273  uint sourceid,
274  const QString &channum);
275 
276  static int GetChannelValueInt(const QString &channel_field,
277  uint sourceid,
278  const QString &channum);
279 
280  static bool IsOnSameMultiplex(uint srcid,
281  const QString &new_channum,
282  const QString &old_channum);
283 
284  static QStringList GetValidRecorderList(uint chanid,
285  const QString &channum);
286 
287  static bool IsConflicting(const QString &channum,
288  uint sourceid = 0, uint excluded_chanid = 0)
289  {
290  vector<uint> chanids = GetConflicting(channum, sourceid);
291  return (chanids.size() > 1) ||
292  ((1 == chanids.size()) && (chanids[0] != excluded_chanid));
293  }
294 
295  static vector<uint> GetConflicting(const QString &channum,
296  uint sourceid = 0);
297 
302  static QString GetChanNum(int chan_id);
303 
308  static int GetTimeOffset(int chan_id);
309  static int GetSourceID(int mplexid);
310  static uint GetSourceIDForChannel(uint chanid);
311 
312  static QStringList GetInputTypes(uint chanid);
313 
314  static bool GetCachedPids(uint chanid, pid_cache_t &pid_cache);
315 
316  // Misc sets
317  static bool SetChannelValue(const QString &field_name,
318  const QString& value,
319  uint sourceid,
320  const QString &channum);
321 
322  static bool SetChannelValue(const QString &field_name,
323  const QString& value,
324  int chanid);
325 
326  static bool SaveCachedPids(uint chanid,
327  const pid_cache_t &_pid_cache,
328  bool delete_all = false);
329 
330  static const QString kATSCSeparators;
331 
332  private:
336  static ChannelInfoList GetChannelsInternal(
337  uint sourceid, bool visible_only, bool include_disconnected,
338  const QString &group_by, uint channel_groupid);
339  static QString GetChannelStringField(int chan_id, const QString &field);
340 };
341 
342 #endif // CHANUTIL_H
vector< pid_cache_item_t > pid_cache_t
Definition: channelutil.h:43
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:253
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
static int GetProgramNumber(uint sourceid, const QString &channum)
Definition: channelutil.h:187
pid_cache_item_t(uint pid, uint sid_tid)
Definition: channelutil.h:28
static int GetChanID(uint sourceid, const QString &channum)
Definition: channelutil.h:175
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:287
static QString GetVideoFilters(uint sourceid, const QString &channum)
Definition: channelutil.h:189
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:240
unsigned int uint
Definition: compat.h:140
static bool CreateIPTVTuningData(uint channel_id, const IPTVTuningData &tuning)
Definition: channelutil.h:145
uint GetComposite(void) const
Definition: channelutil.h:38
ChannelVisibleType
Definition: channelinfo.h:22
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:330
vector< ChannelInfo > ChannelInfoList
Definition: channelinfo.h:133
uint GetStreamID(void) const
Definition: channelutil.h:31
uint GetPID(void) const
Definition: channelutil.h:30