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