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 
39 typedef enum
40 {
44 } PseudoState;
45 
46 typedef deque<QString> StringDeque;
47 
49 {
50  public:
51  explicit PlayerContext(const 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&, int pos = -1,
65  QWidget *widget = nullptr);
66  void ResizePIPWindow(const QRect&);
67  bool StartPIPPlayer(TV *tv, TVState desiredState);
68  void PIPTeardown(void);
69  void SetNullVideo(bool setting) { m_useNullVideo = setting; }
70  bool StartEmbedding(const QRect&);
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 IsPlayerRecoverable(void) const;
139  bool IsPlayerDecoderErrored(void) const;
140  bool IsPlayerPlaying(void) const;
141  bool IsRecorderErrored(void) const;
142  bool InStateChange(void) const;
144  bool IsErrored(void) const { return m_errored; }
145  bool IsSameProgram(const ProgramInfo &p) const;
146  bool IsValidLiveTV(void) const
147  { return m_player && m_tvchain && m_recorder && m_buffer; }
148 
149  public:
150  QString m_recUsage;
151  MythPlayer *m_player {nullptr};
152  volatile bool m_playerUnsafe {false};
153  RemoteEncoder *m_recorder {nullptr};
154  LiveTVChain *m_tvchain {nullptr};
155  RingBuffer *m_buffer {nullptr};
156  ProgramInfo *m_playingInfo {nullptr};
157  long long m_playingLen {0};
158  bool m_nohardwaredecoders {false}; // < Disable use of VDPAU decoding
159  int m_lastCardid {-1};
160  int m_ffRewState {0};
163  int m_ffRewIndex {0};
165  int m_ffRewSpeed {0};
166  TVState m_playingState {kState_None};
167 
168  bool m_errored {false};
169 
170  // Previous channel functionality state variables
172 
173  // Recording to play next, after LiveTV
174  ProgramInfo *m_pseudoLiveTVRec {nullptr};
175  PseudoState m_pseudoLiveTVState {kPseudoNormalLiveTV};
176 
177  int m_fftime {0};
178  int m_rewtime {0};
179  int m_jumptime {0};
186  float m_tsNormal {1.0F};
187  float m_tsAlt {1.5F};
188 
189  mutable QMutex m_playingInfoLock {QMutex::Recursive};
190  mutable QMutex m_deletePlayerLock {QMutex::Recursive};
191  mutable QMutex m_stateLock {QMutex::Recursive};
192 
193  // Signal info
194  mutable QStringList m_lastSignalMsg;
198 
199  // tv state related
201 
202  // Picture-in-Picture related
203  PIPState m_pipState {kPIPOff};
204  QRect m_pipRect {0,0,0,0};
205  QWidget *m_parentWidget {nullptr};
207  int m_pipLocation {0};
209  bool m_useNullVideo {false};
210 
212  static const uint kSMExitTimeout;
213  static const uint kMaxChannelHistory;
214 };
215 
216 #endif // _PLAYER_CONTEXT_H_
deque< QString > StringDeque
Definition: playercontext.h:46
QStringList m_lastSignalMsg
A QElapsedTimer based timer to replace use of QTime as a timer.
Definition: mythtimer.h:13
bool IsNullVideoDesired(void) const
void SetNoHardwareDecoders(void)
bool IsPlayerChangingBuffers(void) const
unsigned int uint
Definition: compat.h:140
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:66
static const uint kMaxChannelHistory
#define MTV_PUBLIC
Definition: mythtvexp.h:15
bool IsPrimaryPBP(void) const
QHash< QString, QString > InfoMap
Definition: mythtypes.h:15
#define GetState(a, b)
bool IsAudioNeeded(void) const
QHash< QString, int > values
Definition: playercontext.h:36
Control TV playback.
Definition: tv_play.h:284
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:10
bool IsPIP(void) const
void SetNullVideo(bool setting)
Definition: playercontext.h:69
MythTimer m_lastSignalMsgTime
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