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 MythMediaBuffer;
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) const;
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) const;
71  void StopEmbedding(void) const;
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(MythMediaBuffer *Buffer);
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(bool Disallow = true) { m_nohardwaredecoders = Disallow; }
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 IsPiPOrSecondaryPBP(void) const
134  { return IsPIP() || (IsPBP() && !IsPrimaryPBP()); }
135  bool IsNullVideoDesired(void) const { return m_useNullVideo; }
136  bool IsPlayerChangingBuffers(void) const { return m_playerUnsafe; }
137  bool IsEmbedding(void) const;
138  bool HasPlayer(void) const;
139  bool IsPlayerErrored(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  MythMediaBuffer *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
PlayerContext::IsErrored
bool IsErrored(void) const
This is set if the player encountered some irrecoverable error.
Definition: playercontext.h:144
PlayerContext::m_lastSignalUIInfo
InfoMap m_lastSignalUIInfo
Definition: playercontext.h:196
PlayerContext::IsPiPOrSecondaryPBP
bool IsPiPOrSecondaryPBP(void) const
Definition: playercontext.h:133
PlayerContext::IsPrimaryPBP
bool IsPrimaryPBP(void) const
Definition: playercontext.h:129
tv.h
PlayerContext::IsPIP
bool IsPIP(void) const
Definition: playercontext.h:125
osdInfo
Definition: playercontext.h:33
PlayerContext::IsPlayerChangingBuffers
bool IsPlayerChangingBuffers(void) const
Definition: playercontext.h:136
PlayerContext::m_lastSignalMsg
QStringList m_lastSignalMsg
Definition: playercontext.h:194
MythTimer
A QElapsedTimer based timer to replace use of QTime as a timer.
Definition: mythtimer.h:13
kPIPonTV
@ kPIPonTV
Definition: videoouttypes.h:11
mythtvexp.h
PlayerContext::SetPlayerChangingBuffers
void SetPlayerChangingBuffers(bool val)
Definition: playercontext.h:107
MythMediaBuffer
Definition: mythmediabuffer.h:49
kPIPOff
@ kPIPOff
Definition: videoouttypes.h:10
kPseudoChangeChannel
@ kPseudoChangeChannel
Definition: playercontext.h:42
MythPlayer
Definition: mythplayer.h:164
build_compdb.file
file
Definition: build_compdb.py:55
PlayerContext::kMaxChannelHistory
static const uint kMaxChannelHistory
Definition: playercontext.h:213
mythdeque.h
RemoteEncoder
Definition: remoteencoder.h:25
InfoMap
QHash< QString, QString > InfoMap
Definition: mythtypes.h:15
PlayerContext::GetCardID
uint GetCardID(void) const
Definition: playercontext.h:116
kState_None
@ kState_None
None State, this is the initial state in both TV and TVRec, it indicates that we are ready to change ...
Definition: tv.h:58
PlayerContext::m_prevChan
StringDeque m_prevChan
Previous channels.
Definition: playercontext.h:171
mythdate.h
videoouttypes.h
hardwareprofile.config.p
p
Definition: config.py:33
osdInfo::values
QHash< QString, int > values
Definition: playercontext.h:36
PlayerContext::GetPIPState
PIPState GetPIPState(void) const
Definition: playercontext.h:112
osdInfo::text
InfoMap text
Definition: playercontext.h:35
mythtypes.h
PlayerContext::m_recUsage
QString m_recUsage
Definition: playercontext.h:150
kPseudoRecording
@ kPseudoRecording
Definition: playercontext.h:43
GetState
#define GetState(a, b)
Definition: audiooutputopensles.cpp:50
uint
unsigned int uint
Definition: compat.h:140
PlayerContext::IsNullVideoDesired
bool IsNullVideoDesired(void) const
Definition: playercontext.h:135
PlayerContext::m_lastSignalUIInfoTime
MythTimer m_lastSignalUIInfoTime
Definition: playercontext.h:197
PlayerContext::SetNullVideo
void SetNullVideo(bool setting)
Definition: playercontext.h:69
kPBPLeft
@ kPBPLeft
Definition: videoouttypes.h:13
MTV_PUBLIC
#define MTV_PUBLIC
Definition: mythtvexp.h:15
PlayerContext::kSMExitTimeout
static const uint kSMExitTimeout
Timeout after last Signal Monitor message for ignoring OSD when exiting.
Definition: playercontext.h:212
StringDeque
deque< QString > StringDeque
Definition: playercontext.h:46
kPIPStandAlone
@ kPIPStandAlone
Definition: videoouttypes.h:12
Buffer
Definition: MythExternControl.h:36
ProgramInfo
Holds information on recordings and videos.
Definition: programinfo.h:67
PlayerContext::IsValidLiveTV
bool IsValidLiveTV(void) const
Definition: playercontext.h:146
TVState
TVState
TVState is an enumeration of the states used by TV and TVRec.
Definition: tv.h:50
PlayerContext::m_lastSignalMsgTime
MythTimer m_lastSignalMsgTime
Definition: playercontext.h:195
MythDeque< TVState >
PIPState
PIPState
Definition: videoouttypes.h:8
PlayerContext::SetPIPLocation
void SetPIPLocation(int loc)
Definition: playercontext.h:105
PlayerContext::SetPIPState
void SetPIPState(PIPState change)
Definition: playercontext.h:106
PlayerContext
Definition: playercontext.h:48
PlayerContext::IsPBP
bool IsPBP(void) const
Definition: playercontext.h:127
mythtimer.h
PlayerContext::m_nextState
MythDeque< TVState > m_nextState
Definition: playercontext.h:200
PlayerContext::SetNoHardwareDecoders
void SetNoHardwareDecoders(bool Disallow=true)
Definition: playercontext.h:108
kPBPRight
@ kPBPRight
Definition: videoouttypes.h:14
kPseudoNormalLiveTV
@ kPseudoNormalLiveTV
Definition: playercontext.h:41
PseudoState
PseudoState
Definition: playercontext.h:39
PlayerContext::IsAudioNeeded
bool IsAudioNeeded(void) const
Definition: playercontext.h:131
LiveTVChain
Keeps track of recordings in a current LiveTV instance.
Definition: livetvchain.h:31
TV
Control TV playback.
Definition: tv_play.h:280