MythTV  master
livetvchain.h
Go to the documentation of this file.
1 #ifndef LIVETVCHAIN_H
2 #define LIVETVCHAIN_H
3 
4 #include <climits>
5 
6 #include <QString>
7 #include <QStringList>
8 #include <QDateTime>
9 #include <QMutex>
10 #include <QList>
11 #if QT_VERSION >= QT_VERSION_CHECK(5,14,0)
12 #include <QRecursiveMutex>
13 #endif
14 
15 #include "mythtvexp.h"
17 
18 
19 class ProgramInfo;
20 class MythSocket;
21 
23 {
24  uint chanid {0};
25  QDateTime starttime;
26  QDateTime endtime;
27  bool discontinuity {false}; // if true, can't play smooth from last entry
28  QString hostprefix;
29  QString inputtype;
30  QString channum;
31  QString inputname;
32 };
33 
35 {
36  public:
37  LiveTVChain();
38  ~LiveTVChain() override;
39 
40  QString InitializeNewChain(const QString &seed);
41  void LoadFromExistingChain(const QString &id);
42 
43  void SetHostPrefix(const QString &prefix);
44  void SetInputType(const QString &type);
45 
46  void DestroyChain(void);
47 
48  void AppendNewProgram(ProgramInfo *pginfo, const QString& channum,
49  const QString& inputname, bool discont);
50  void FinishedRecording(ProgramInfo *pginfo);
51  void DeleteProgram(ProgramInfo *pginfo);
52 
53  void ReloadAll(const QStringList &data = QStringList());
54 
55  // const gets
56  QString GetID(void) const { return m_id; }
57  int GetCurPos(void) const { return m_curPos; }
58  int ProgramIsAt(uint chanid, const QDateTime &starttime) const;
59  int ProgramIsAt(const ProgramInfo &pginfo) const;
60  std::chrono::seconds GetLengthAtCurPos(void);
61  std::chrono::seconds GetLengthAtPos(int pos);
62  int TotalSize(void) const;
63  bool HasNext(void) const;
64  bool HasPrev(void) const { return (m_curPos > 0); }
65  ProgramInfo *GetProgramAt(int at) const;
68  bool NeedsToSwitch(void) const
69  { return (m_switchId >= 0 && m_jumpPos == std::chrono::seconds::max()); }
71  bool NeedsToJump(void) const
72  { return (m_switchId >= 0 && m_jumpPos != std::chrono::seconds::max()); }
73  QString GetChannelName(int pos = -1) const;
74  QString GetInputName(int pos = -1) const;
75  QString GetInputType(int pos = -1) const;
76 
77  // sets/gets program to switch to
78  void SetProgram(const ProgramInfo &pginfo);
79  void SwitchTo(int num);
80  void SwitchToNext(bool up);
81  void ClearSwitch(void);
82  ProgramInfo *GetSwitchProgram(bool &discont, bool &newtype, int &newid);
83 
84  // sets/gets program to jump to
85  void JumpTo(int num, std::chrono::seconds pos);
86  void JumpToNext(bool up, std::chrono::seconds pos);
87  std::chrono::seconds GetJumpPos(void);
88 
89  // socket stuff
90  void SetHostSocket(MythSocket *sock);
91  bool IsHostSocket(MythSocket *sock);
92  uint HostSocketCount(void) const;
93  void DelHostSocket(MythSocket *sock);
94 
95  QString toString() const;
96 
97  // serialize m_maxpos and m_chain to a stringlist
98  QStringList entriesToStringList() const;
99  // deserialize m_maxpos and m_chain from a stringlist
100  bool entriesFromStringList(const QStringList &items);
101 
102  private:
103  void BroadcastUpdate();
104  void GetEntryAt(int at, LiveTVChainEntry &entry) const;
105  static ProgramInfo *EntryToProgram(const LiveTVChainEntry &entry);
106  ProgramInfo *DoGetNextProgram(bool up, int curpos, int &newid,
107  bool &discont, bool &newtype);
108 
109  QString m_id;
110  QList<LiveTVChainEntry> m_chain;
111  int m_maxPos {0};
112 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
113  mutable QMutex m_lock {QMutex::Recursive};
114 #else
115  mutable QRecursiveMutex m_lock;
116 #endif
117 
118  QString m_hostPrefix;
119  QString m_inputType;
120 
121  int m_curPos {0};
122  uint m_curChanId {0};
123  QDateTime m_curStartTs;
124 
125  int m_switchId {-1};
127 
128  std::chrono::seconds m_jumpPos {std::chrono::seconds::max()};
129 
130  mutable QMutex m_sockLock;
131  QList<MythSocket*> m_inUseSocks;
132 };
133 
134 #endif // LIVETVCHAIN_H
LiveTVChain::GetCurPos
int GetCurPos(void) const
Definition: livetvchain.h:57
MythDate::toString
QString toString(const QDateTime &raw_dt, uint format)
Returns formatted string representing the time.
Definition: mythdate.cpp:84
mythtvexp.h
LiveTVChain::GetID
QString GetID(void) const
Definition: livetvchain.h:56
LiveTVChain::m_chain
QList< LiveTVChainEntry > m_chain
Definition: livetvchain.h:110
LiveTVChainEntry::channum
QString channum
Definition: livetvchain.h:30
LiveTVChain::m_curStartTs
QDateTime m_curStartTs
Definition: livetvchain.h:123
LiveTVChainEntry::endtime
QDateTime endtime
Definition: livetvchain.h:26
hardwareprofile.distros.mythtv_data.data_mythtv.prefix
string prefix
Definition: data_mythtv.py:40
LiveTVChainEntry::starttime
QDateTime starttime
Definition: livetvchain.h:25
LiveTVChain::NeedsToJump
bool NeedsToJump(void) const
Returns true iff a switch and jump are required.
Definition: livetvchain.h:71
MythSocket
Class for communcating between myth backends and frontends.
Definition: mythsocket.h:25
LiveTVChain::m_inUseSocks
QList< MythSocket * > m_inUseSocks
Definition: livetvchain.h:131
LiveTVChain::m_id
QString m_id
Definition: livetvchain.h:109
LiveTVChain::m_hostPrefix
QString m_hostPrefix
Definition: livetvchain.h:118
LiveTVChainEntry::inputtype
QString inputtype
Definition: livetvchain.h:29
LiveTVChain::m_inputType
QString m_inputType
Definition: livetvchain.h:119
LiveTVChain::m_lock
QRecursiveMutex m_lock
Definition: livetvchain.h:115
uint
unsigned int uint
Definition: compat.h:81
referencecounter.h
LiveTVChainEntry::hostprefix
QString hostprefix
Definition: livetvchain.h:28
MTV_PUBLIC
#define MTV_PUBLIC
Definition: mythtvexp.h:15
ProgramInfo
Holds information on recordings and videos.
Definition: programinfo.h:67
LiveTVChain::m_switchEntry
LiveTVChainEntry m_switchEntry
Definition: livetvchain.h:126
LiveTVChain::NeedsToSwitch
bool NeedsToSwitch(void) const
Returns true iff a switch is required but no jump is required m_jumppos sets to INT_MAX means not set...
Definition: livetvchain.h:68
LiveTVChain::m_sockLock
QMutex m_sockLock
Definition: livetvchain.h:130
LiveTVChainEntry::inputname
QString inputname
Definition: livetvchain.h:31
LiveTVChainEntry
Definition: livetvchain.h:22
LiveTVChain::HasPrev
bool HasPrev(void) const
Definition: livetvchain.h:64
ReferenceCounter
General purpose reference counter.
Definition: referencecounter.h:26
LiveTVChain
Keeps track of recordings in a current LiveTV instance.
Definition: livetvchain.h:34