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 
24 {
25  public:
26  pid_cache_item_t() = default;
27  pid_cache_item_t(uint pid, uint sid_tid) :
28  m_pid(pid), m_sidTid(sid_tid) {}
29  uint GetPID(void) const { return m_pid; }
30  uint GetStreamID(void) const
31  { return (m_sidTid&0x100) ? GetID() : 0; }
32  uint GetTableID(void) const
33  { return (m_sidTid&0x100) ? 0 : GetID(); }
34  uint GetID(void) const { return m_sidTid & 0xff; }
35  bool IsPCRPID(void) const { return ( m_sidTid&0x200 ) != 0; }
36  bool IsPermanent(void) const { return ( m_sidTid&0x10000 ) != 0; }
37  uint GetComposite(void) const { return m_sidTid; }
38  private:
39  uint m_pid {0};
41 };
42 using pid_cache_t = std::vector<pid_cache_item_t>;
43 
48 {
50 
51  public:
52  // Multiplex Stuff
53 
54  static uint CreateMultiplex(
55  int sourceid, const QString& sistandard,
56  uint64_t frequency, const QString& modulation,
57  int transport_id = -1, int network_id = -1);
58 
59  static uint CreateMultiplex(
60  int sourceid, const QString& sistandard,
61  uint64_t frequency, const QString& modulation,
62  // DVB specific
63  int transport_id, int network_id,
64  int symbol_rate, signed char bandwidth,
65  signed char polarity, signed char inversion,
66  signed char trans_mode,
67  const QString& inner_FEC, const QString& constellation,
68  signed char hierarchy, const QString& hp_code_rate,
69  const QString& lp_code_rate, const QString& guard_interval,
70  const QString& mod_sys, const QString& rolloff);
71 
72  static uint CreateMultiplex(uint sourceid, const DTVMultiplex &mux,
73  int transport_id, int network_id);
74 
75  static std::vector<uint> CreateMultiplexes(
76  int sourceid, const NetworkInformationTable *nit);
77 
78  static uint GetMplexID(uint sourceid, const QString &channum);
79  static int GetMplexID(uint sourceid, uint64_t frequency);
80  static int GetMplexID(uint sourceid, uint64_t frequency,
81  uint transport_id, uint network_id);
82  static int GetMplexID(uint sourceid,
83  uint transport_id, uint network_id);
84  static uint GetMplexID(uint chanid);
85  static int GetBetterMplexID(int current_mplexid,
86  int transport_id, int network_id);
87 
88  static bool GetTuningParams(uint mplexid,
89  QString &modulation,
90  uint64_t &frequency,
91  uint &dvb_transportid,
92  uint &dvb_networkid,
93  QString &si_std);
94 
95  static bool GetATSCChannel(uint sourceid, const QString &channum,
96  uint &major, uint &minor);
97  static bool IsATSCChannel(uint sourceid, const QString &channum)
98  {
99  uint m1 = 0;
100  uint m2 = 0;
101  GetATSCChannel(sourceid, channum, m1,m2);
102  return m2 != 0U;
103  }
104 
105  // Channel/Service Stuff
106  static int CreateChanID(uint sourceid, const QString &chan_num);
107 
108  static bool CreateChannel(uint db_mplexid,
109  uint db_sourceid,
110  uint new_channel_id,
111  const QString &callsign,
112  const QString &service_name,
113  const QString &chan_num,
114  uint service_id,
115  uint atsc_major_channel,
116  uint atsc_minor_channel,
117  bool use_on_air_guide,
118  ChannelVisibleType visible,
119  const QString &freqid,
120  const QString& icon = QString(),
121  QString format = "Default",
122  const QString& xmltvid = QString(),
123  const QString& default_authority = QString(),
124  uint service_type = 0);
125 
126  static bool UpdateChannel(uint db_mplexid,
127  uint source_id,
128  uint channel_id,
129  const QString &callsign,
130  const QString &service_name,
131  const QString &chan_num,
132  uint service_id,
133  uint atsc_major_channel,
134  uint atsc_minor_channel,
135  bool use_on_air_guide,
136  ChannelVisibleType visible,
137  const QString& freqid = QString(),
138  const QString& icon = QString(),
139  QString format = QString(),
140  const QString& xmltvid = QString(),
141  const QString& default_authority = QString(),
142  uint service_type = 0);
143 
144  static bool CreateIPTVTuningData(
145  uint channel_id, const IPTVTuningData &tuning)
146  {
147  return UpdateIPTVTuningData(channel_id, tuning);
148  }
149 
150  static bool UpdateIPTVTuningData(
151  uint channel_id, const IPTVTuningData &tuning);
152 
153  static void UpdateInsertInfoFromDB(ChannelInsertInfo &chan);
154  static void UpdateChannelNumberFromDB(ChannelInsertInfo &chan);
155 
156  static bool DeleteChannel(uint channel_id);
157 
158  static bool SetVisible(uint channel_id, ChannelVisibleType visible);
159 
160  static bool SetServiceVersion(int mplexid, int version);
161 
162  static int GetChanID(int db_mplexid, int service_transport_id,
163  int major_channel, int minor_channel,
164  int program_number);
165 
166  static int GetServiceVersion(int mplexid);
167 
168  // Misc gets
169  static QString GetDefaultAuthority(uint chanid);
170  static QString GetIcon(uint chanid);
171  static std::vector<uint> GetInputIDs(uint chanid);
172  static QString GetUnknownCallsign(void);
173  static uint FindChannel(uint sourceid, const QString &freqid);
174  static int GetChanID(uint sourceid, const QString &channum)
175  { return GetChannelValueInt("chanid", sourceid, channum); }
176  static bool GetChannelData(
177  uint sourceid,
178  uint &chanid, const QString &channum,
179  QString &tvformat, QString &modulation,
180  QString &freqtable, QString &freqid,
181  int &finetune, uint64_t &frequency,
182  QString &dtv_si_std, int &mpeg_prog_num,
183  uint &atsc_major, uint &atsc_minor,
184  uint &dvb_transportid, uint &dvb_networkid,
185  uint &mplexid, bool &commfree);
186  static int GetProgramNumber(uint sourceid, const QString &channum)
187  { return GetChannelValueInt("serviceid", sourceid, channum); }
188  static QString GetVideoFilters(uint sourceid, const QString &channum)
189  { return GetChannelValueStr("videofilters", sourceid, channum); }
190  static IPTVTuningData GetIPTVTuningData(uint chanid);
191 
192  // Are there any other possibly useful sort orders?
193  // e.g. Sorting by sourceid would probably be better done by two distinct
194  // calls to LoadChannels specifying the sourceid
195  enum OrderBy
196  {
200  };
201 
202  enum GroupBy
203  {
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 std::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  std::vector<uint> chanids = GetConflicting(channum, sourceid);
291  return (chanids.size() > 1) ||
292  ((1 == chanids.size()) && (chanids[0] != excluded_chanid));
293  }
294 
295  static std::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
DTVMultiplex
Definition: dtvmultiplex.h:25
tv.h
ChannelChangeDirection
ChannelChangeDirection
ChannelChangeDirection is an enumeration of possible channel changing directions.
Definition: tv.h:29
pid_cache_item_t
Definition: channelutil.h:24
ChannelUtil::OrderBy
OrderBy
Definition: channelutil.h:196
mythtvexp.h
ChannelUtil::GetProgramNumber
static int GetProgramNumber(uint sourceid, const QString &channum)
Definition: channelutil.h:186
pid_cache_item_t::pid_cache_item_t
pid_cache_item_t()=default
ChannelUtil::kChanOrderByLiveTV
@ kChanOrderByLiveTV
Definition: channelutil.h:199
ChannelUtil::kChanOrderByName
@ kChanOrderByName
Definition: channelutil.h:198
pid_cache_item_t::IsPCRPID
bool IsPCRPID(void) const
Definition: channelutil.h:35
dtvmultiplex.h
ChannelUtil::GetChanID
static int GetChanID(uint sourceid, const QString &channum)
Definition: channelutil.h:174
ChannelInsertInfo
Definition: channelinfo.h:134
minor
#define minor(X)
Definition: compat.h:139
pid_cache_item_t::GetTableID
uint GetTableID(void) const
Definition: channelutil.h:32
ChannelUtil::Q_DECLARE_TR_FUNCTIONS
Q_DECLARE_TR_FUNCTIONS(ChannelUtil)
ChannelUtil::IsATSCChannel
static bool IsATSCChannel(uint sourceid, const QString &channum)
Definition: channelutil.h:97
pid_cache_item_t::IsPermanent
bool IsPermanent(void) const
Definition: channelutil.h:36
pid_cache_t
std::vector< pid_cache_item_t > pid_cache_t
Definition: channelutil.h:42
pid_cache_item_t::GetID
uint GetID(void) const
Definition: channelutil.h:34
IPTVTuningData
Definition: iptvtuningdata.h:17
iptvtuningdata.h
ChannelVisibleType
ChannelVisibleType
Definition: channelinfo.h:21
ChannelUtil::GetChannels
static ChannelInfoList GetChannels(uint sourceid, bool visible_only, const QString &group_by=QString(), uint channel_groupid=0)
Definition: channelutil.h:240
uint
unsigned int uint
Definition: compat.h:141
pid_cache_item_t::GetComposite
uint GetComposite(void) const
Definition: channelutil.h:37
pid_cache_item_t::GetStreamID
uint GetStreamID(void) const
Definition: channelutil.h:30
ChannelUtil::IsConflicting
static bool IsConflicting(const QString &channum, uint sourceid=0, uint excluded_chanid=0)
Definition: channelutil.h:287
ChannelUtil::GetVideoFilters
static QString GetVideoFilters(uint sourceid, const QString &channum)
Definition: channelutil.h:188
MTV_PUBLIC
#define MTV_PUBLIC
Definition: mythtvexp.h:15
channelinfo.h
pid_cache_item_t::GetPID
uint GetPID(void) const
Definition: channelutil.h:29
ChannelUtil::GroupBy
GroupBy
Definition: channelutil.h:203
ChannelUtil::CreateIPTVTuningData
static bool CreateIPTVTuningData(uint channel_id, const IPTVTuningData &tuning)
Definition: channelutil.h:144
ChannelUtil::kChanGroupByCallsignAndChannum
@ kChanGroupByCallsignAndChannum
Definition: channelutil.h:205
ChannelUtil::GetInputIDs
static std::vector< uint > GetInputIDs(uint chanid)
pid_cache_item_t::m_pid
uint m_pid
Definition: channelutil.h:39
pid_cache_item_t::m_sidTid
uint m_sidTid
Definition: channelutil.h:40
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:253
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:27
ChannelUtil::kATSCSeparators
static const QString kATSCSeparators
Definition: channelutil.h:330
ChannelUtil::kChanOrderByChanNum
@ kChanOrderByChanNum
Definition: channelutil.h:197
ChannelUtil::kChanGroupByCallsign
@ kChanGroupByCallsign
Definition: channelutil.h:204
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:31
ChannelInfoList
std::vector< ChannelInfo > ChannelInfoList
Definition: channelinfo.h:131