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, QString sistandard,
57  uint64_t frequency, QString modulation,
58  int transport_id = -1, int network_id = -1);
59 
60  static uint CreateMultiplex(
61  int sourceid, QString sistandard,
62  uint64_t frequency, 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  QString inner_FEC, QString constellation,
69  signed char hierarchy, QString hp_code_rate,
70  QString lp_code_rate, QString guard_interval,
71  QString mod_sys, 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  QString icon = QString(),
118  QString format = "Default",
119  QString xmltvid = QString(),
120  QString default_authority = QString());
121 
122  static bool UpdateChannel(uint db_mplexid,
123  uint source_id,
124  uint channel_id,
125  const QString &callsign,
126  const QString &service_name,
127  const QString &chan_num,
128  uint service_id,
129  uint atsc_major_channel,
130  uint atsc_minor_channel,
131  bool use_on_air_guide,
132  bool hidden,
133  bool hidden_in_guide,
134  const QString& freqid = QString(),
135  const QString& icon = QString(),
136  QString format = QString(),
137  const QString& xmltvid = QString(),
138  const QString& default_authority = QString());
139 
140  static bool CreateIPTVTuningData(
141  uint channel_id, const IPTVTuningData &tuning)
142  {
143  return UpdateIPTVTuningData(channel_id, tuning);
144  }
145 
146  static bool UpdateIPTVTuningData(
147  uint channel_id, const IPTVTuningData &tuning);
148 
149  static void UpdateInsertInfoFromDB(ChannelInsertInfo &chan);
150  static void UpdateChannelNumberFromDB(ChannelInsertInfo &chan);
151 
152  static bool DeleteChannel(uint channel_id);
153 
154  static bool SetVisible(uint channel_id, bool visible);
155 
156  static bool SetServiceVersion(int mplexid, int version);
157 
158  static int GetChanID(int db_mplexid, int service_transport_id,
159  int major_channel, int minor_channel,
160  int program_number);
161 
162  static int GetServiceVersion(int mplexid);
163 
164  // Misc gets
165  static QString GetDefaultAuthority(uint chanid);
166  static QString GetIcon(uint chanid);
167  static vector<uint> GetInputIDs(uint chanid);
168  static QString GetUnknownCallsign(void);
169  static uint FindChannel(uint sourceid, const QString &freqid);
170  static int GetChanID(uint sourceid, const QString &channum)
171  { return GetChannelValueInt("chanid", sourceid, channum); }
172  static bool GetChannelData(
173  uint sourceid,
174  uint &chanid, const QString &channum,
175  QString &tvformat, QString &modulation,
176  QString &freqtable, QString &freqid,
177  int &finetune, uint64_t &frequency,
178  QString &dtv_si_std, int &mpeg_prog_num,
179  uint &atsc_major, uint &atsc_minor,
180  uint &dvb_transportid, uint &dvb_networkid,
181  uint &mplexid, bool &commfree);
182  static int GetProgramNumber(uint sourceid, const QString &channum)
183  { return GetChannelValueInt("serviceid", sourceid, channum); }
184  static QString GetVideoFilters(uint sourceid, const QString &channum)
185  { return GetChannelValueStr("videofilters", sourceid, channum); }
186  static IPTVTuningData GetIPTVTuningData(uint chanid);
187 
188  // Are there any other possibly useful sort orders?
189  // e.g. Sorting by sourceid would probably be better done by two distinct
190  // calls to LoadChannels specifying the sourceid
191  enum OrderBy
192  {
196  };
197 
198  enum GroupBy
199  {
201  kChanGroupByChanid // Because of the nature of the query we always need to group
202  };
203 
220  static ChannelInfoList LoadChannels(uint startIndex, uint count,
221  uint &totalAvailable,
222  bool ignoreHidden = true,
223  OrderBy orderBy = kChanOrderByChanNum,
224  GroupBy groupBy = kChanGroupByChanid,
225  uint sourceID = 0,
226  uint channelGroupID = 0,
227  bool liveTVOnly = false,
228  const QString& callsign = "",
229  const QString& channum = "");
230 
235  uint sourceid, bool visible_only,
236  const QString &group_by = QString(), uint channel_groupid = 0)
237  {
238  return GetChannelsInternal(sourceid, visible_only, false,
239  group_by, channel_groupid);
240  }
241 
244 
248  {
249  return GetChannelsInternal(sourceid, false, true, QString(), 0);
250  }
251  static vector<uint> GetChanIDs(int sourceid = -1, bool onlyVisible = false);
252  static uint GetChannelCount(int sourceid = -1);
253  static void SortChannels(ChannelInfoList &list, const QString &order,
254  bool eliminate_duplicates = false);
255  static int GetNearestChannel(const ChannelInfoList &list,
256  const QString &channum);
257 
258  static uint GetNextChannel(const ChannelInfoList &sorted,
259  uint old_chanid,
260  uint mplexid_restriction,
261  uint chanid_restriction,
262  ChannelChangeDirection direction,
263  bool skip_non_visible = true,
264  bool skip_same_channum_and_callsign = false);
265 
266  static QString GetChannelValueStr(const QString &channel_field,
267  uint sourceid,
268  const QString &channum);
269 
270  static int GetChannelValueInt(const QString &channel_field,
271  uint sourceid,
272  const QString &channum);
273 
274  static bool IsOnSameMultiplex(uint srcid,
275  const QString &new_channum,
276  const QString &old_channum);
277 
278  static QStringList GetValidRecorderList(uint chanid,
279  const QString &channum);
280 
281  static bool IsConflicting(const QString &channum,
282  uint sourceid = 0, uint excluded_chanid = 0)
283  {
284  vector<uint> chanids = GetConflicting(channum, sourceid);
285  return (chanids.size() > 1) ||
286  ((1 == chanids.size()) && (chanids[0] != excluded_chanid));
287  }
288 
289  static vector<uint> GetConflicting(const QString &channum,
290  uint sourceid = 0);
291 
296  static QString GetChanNum(int chan_id);
297 
302  static int GetTimeOffset(int chan_id);
303  static int GetSourceID(int mplexid);
304  static uint GetSourceIDForChannel(uint chanid);
305 
306  static QStringList GetInputTypes(uint chanid);
307 
308  static bool GetCachedPids(uint chanid, pid_cache_t &pid_cache);
309 
310  // Misc sets
311  static bool SetChannelValue(const QString &field_name,
312  const QString& value,
313  uint sourceid,
314  const QString &channum);
315 
316  static bool SetChannelValue(const QString &field_name,
317  const QString& value,
318  int chanid);
319 
320  static bool SaveCachedPids(uint chanid,
321  const pid_cache_t &_pid_cache,
322  bool delete_all = false);
323 
324  static const QString kATSCSeparators;
325 
326  private:
330  static ChannelInfoList GetChannelsInternal(
331  uint sourceid, bool visible_only, bool include_disconnected,
332  const QString &group_by, uint channel_groupid);
333  static QString GetChannelStringField(int chan_id, const QString &field);
334 };
335 
336 #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:247
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:182
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:170
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:281
static QString GetVideoFilters(uint sourceid, const QString &channum)
Definition: channelutil.h:184
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:234
static bool CreateIPTVTuningData(uint channel_id, const IPTVTuningData &tuning)
Definition: channelutil.h:140
uint GetComposite(void) const
Definition: channelutil.h:38
vector< ChannelInfo > ChannelInfoList
Definition: channelinfo.h:120
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:324
uint GetStreamID(void) const
Definition: channelutil.h:31
uint GetPID(void) const
Definition: channelutil.h:30