MythTV  master
playercontext.h
Go to the documentation of this file.
1 #ifndef _PLAYER_CONTEXT_H_
2 #define _PLAYER_CONTEXT_H_
3 
4 #include <vector>
5 #include <deque>
6 using namespace std;
7 
8 // Qt headers
9 #include <QWidget>
10 #include <QString>
11 #include <QMutex>
12 #include <QHash>
13 #include <QRect>
14 #include <QObject>
15 
16 // MythTV headers
17 #include "videoouttypes.h"
18 #include "mythtimer.h"
19 #include "mythtvexp.h"
20 #include "mythdeque.h"
21 #include "mythdate.h"
22 #include "mythtypes.h"
23 #include "tv.h"
24 
25 class TV;
26 class RemoteEncoder;
27 class MythPlayer;
28 class RingBuffer;
29 class ProgramInfo;
30 class LiveTVChain;
31 class QPainter;
32 
33 struct osdInfo
34 {
36  QHash<QString,int> values;
37 };
38 
40 {
44 };
45 
46 using StringDeque = deque<QString>;
47 
49 {
50  public:
51  explicit PlayerContext(QString inUseID = QString("Unknown"));
52  ~PlayerContext();
53 
54  // Actions
55  bool CreatePlayer(TV *tv, QWidget *widget,
56  TVState desiredState,
57  bool embed, const QRect &embedBounds = QRect(),
58  bool muted = false);
59  void TeardownPlayer(void);
60  bool StartPlaying(int maxWait = -1);
61  void StopPlaying(void);
62  void UpdateTVChain(const QStringList &data = QStringList());
63  bool ReloadTVChain(void);
64  void CreatePIPWindow(const QRect &rect, int pos = -1,
65  QWidget *widget = nullptr);
66  void ResizePIPWindow(const QRect &rect);
67  bool StartPIPPlayer(TV *tv, TVState desiredState);
68  void PIPTeardown(void);
69  void SetNullVideo(bool setting) { m_useNullVideo = setting; }
70  bool StartEmbedding(const QRect &rect);
71  void StopEmbedding(void);
72  void PushPreviousChannel(void);
73  QString PopPreviousChannel(void);
74 
75  void ChangeState(TVState newState);
76  void ForceNextStateNone(void);
77  TVState DequeueNextState(void);
78 
79  void ResizePIPWindow(void);
80  bool HandlePlayerSpeedChangeFFRew(void);
81  bool HandlePlayerSpeedChangeEOF(void);
82 
83  // Locking
84  void LockState(void) const;
85  void UnlockState(void) const;
86 
87  void LockPlayingInfo(const char *file, int line) const;
88  void UnlockPlayingInfo(const char *file, int line) const;
89 
90  void LockDeletePlayer(const char *file, int line) const;
91  void UnlockDeletePlayer(const char *file, int line) const;
92 
93  void LockOSD(void) const;
94  void UnlockOSD(void) const;
95 
96  // Sets
97  void SetInitialTVState(bool islivetv);
98  void SetPlayer(MythPlayer *newplayer);
99  void SetRecorder(RemoteEncoder *rec);
100  void SetTVChain(LiveTVChain *chain);
101  void SetRingBuffer(RingBuffer *buf);
102  void SetPlayingInfo(const ProgramInfo *info);
103  void SetPlayGroup(const QString &group);
104  void SetPseudoLiveTV(const ProgramInfo *pi, PseudoState new_state);
105  void SetPIPLocation(int loc) { m_pipLocation = loc; }
106  void SetPIPState(PIPState change) { m_pipState = change; }
107  void SetPlayerChangingBuffers(bool val) { m_playerUnsafe = val; }
108  void SetNoHardwareDecoders(void) { m_nohardwaredecoders = true; }
109 
110  // Gets
111  QRect GetStandAlonePIPRect(void);
112  PIPState GetPIPState(void) const { return m_pipState; }
113  QString GetPreviousChannel(void) const;
114  bool CalcPlayerSliderPosition(osdInfo &info,
115  bool paddedFields = false) const;
116  uint GetCardID(void) const { return m_lastCardid; }
117  QString GetFilters(const QString &baseFilters) const;
118  QString GetPlayMessage(void) const;
119  TVState GetState(void) const;
120  bool GetPlayingInfoMap(InfoMap &infoMap) const;
121 
122  // Boolean Gets
123  bool IsPIPSupported(void) const;
124  bool IsPBPSupported(void) const;
125  bool IsPIP(void) const
126  { return (kPIPonTV == m_pipState) || (kPIPStandAlone == m_pipState); }
127  bool IsPBP(void) const
128  { return (kPBPLeft == m_pipState) || (kPBPRight == m_pipState); }
129  bool IsPrimaryPBP(void) const
130  { return (kPBPLeft == m_pipState); }
131  bool IsAudioNeeded(void) const
132  { return (kPIPOff == m_pipState) || (kPBPLeft == m_pipState); }
133  bool IsNullVideoDesired(void) const { return m_useNullVideo; }
134  bool IsPlayerChangingBuffers(void) const { return m_playerUnsafe; }
135  bool IsEmbedding(void) const;
136  bool HasPlayer(void) const;
137  bool IsPlayerErrored(void) const;
138  bool IsPlayerPlaying(void) const;
139  bool IsRecorderErrored(void) const;
140  bool InStateChange(void) const;
142  bool IsErrored(void) const { return m_errored; }
143  bool IsSameProgram(const ProgramInfo &p) const;
144  bool IsValidLiveTV(void) const
145  { return m_player && m_tvchain && m_recorder && m_buffer; }
146 
147  public:
148  QString m_recUsage;
149  MythPlayer *m_player {nullptr};
150  volatile bool m_playerUnsafe {false};
151  RemoteEncoder *m_recorder {nullptr};
152  LiveTVChain *m_tvchain {nullptr};
153  RingBuffer *m_buffer {nullptr};
154  ProgramInfo *m_playingInfo {nullptr};
155  long long m_playingLen {0};
156  bool m_nohardwaredecoders {false}; // < Disable use of VDPAU decoding
157  int m_lastCardid {-1};
158  int m_ffRewState {0};
161  int m_ffRewIndex {0};
163  int m_ffRewSpeed {0};
164  TVState m_playingState {kState_None};
165 
166  bool m_errored {false};
167 
168  // Previous channel functionality state variables
170 
171  // Recording to play next, after LiveTV
172  ProgramInfo *m_pseudoLiveTVRec {nullptr};
173  PseudoState m_pseudoLiveTVState {kPseudoNormalLiveTV};
174 
175  int m_fftime {0};
176  int m_rewtime {0};
177  int m_jumptime {0};
184  float m_tsNormal {1.0F};
185  float m_tsAlt {1.5F};
186 
187  mutable QMutex m_playingInfoLock {QMutex::Recursive};
188  mutable QMutex m_deletePlayerLock {QMutex::Recursive};
189  mutable QMutex m_stateLock {QMutex::Recursive};
190 
191  // Signal info
192  mutable QStringList m_lastSignalMsg;
196 
197  // tv state related
199 
200  // Picture-in-Picture related
201  PIPState m_pipState {kPIPOff};
202  QRect m_pipRect {0,0,0,0};
203  QWidget *m_parentWidget {nullptr};
205  int m_pipLocation {0};
207  bool m_useNullVideo {false};
208 
210  static const uint kSMExitTimeout;
211  static const uint kMaxChannelHistory;
212 };
213 
214 #endif // _PLAYER_CONTEXT_H_
QStringList m_lastSignalMsg
A QElapsedTimer based timer to replace use of QTime as a timer.
Definition: mythtimer.h:13
bool IsNullVideoDesired(void) const
QHash< QString, QString > InfoMap
Definition: mythtypes.h:15
void SetNoHardwareDecoders(void)
bool IsPlayerChangingBuffers(void) const
InfoMap m_lastSignalUIInfo
TVState
TVState is an enumeration of the states used by TV and TVRec.
Definition: tv.h:50
StringDeque m_prevChan
Previous channels.
void SetPIPState(PIPState change)
PIPState GetPIPState(void) const
Holds information on recordings and videos.
Definition: programinfo.h:67
static const uint kMaxChannelHistory
#define MTV_PUBLIC
Definition: mythtvexp.h:15
bool IsPrimaryPBP(void) const
#define GetState(a, b)
bool IsAudioNeeded(void) const
QHash< QString, int > values
Definition: playercontext.h:36
Control TV playback.
Definition: tv_play.h:279
unsigned int uint
Definition: compat.h:140
static const uint kSMExitTimeout
Timeout after last Signal Monitor message for ignoring OSD when exiting.
None State, this is the initial state in both TV and TVRec, it indicates that we are ready to change ...
Definition: tv.h:58
void SetPlayerChangingBuffers(bool val)
bool IsErrored(void) const
This is set if the player encountered some irrecoverable error.
PIPState
Definition: videoouttypes.h:8
bool IsPIP(void) const
void SetNullVideo(bool setting)
Definition: playercontext.h:69
MythTimer m_lastSignalMsgTime
deque< QString > StringDeque
Definition: playercontext.h:46
bool IsValidLiveTV(void) const
PseudoState
Definition: playercontext.h:39
QString m_recUsage
uint GetCardID(void) const
Implements a file/stream reader/writer.
bool IsPBP(void) const
MythDeque< TVState > m_nextState
MythTimer m_lastSignalUIInfoTime
void SetPIPLocation(int loc)
Keeps track of recordings in a current LiveTV instance.
Definition: livetvchain.h:31
InfoMap text
Definition: playercontext.h:35