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