00001 #ifndef _PLAYER_CONTEXT_H_
00002 #define _PLAYER_CONTEXT_H_
00003
00004 #include <vector>
00005 #include <deque>
00006 using namespace std;
00007
00008
00009 #include <QWidget>
00010 #include <QString>
00011 #include <QMutex>
00012 #include <QHash>
00013 #include <QRect>
00014 #include <QObject>
00015 #include "mythtvexp.h"
00016 #include "mythdeque.h"
00017 #include "tv.h"
00018 #include "videoouttypes.h"
00019 #include "mythmiscutil.h"
00020
00021 class TV;
00022 class RemoteEncoder;
00023 class MythPlayer;
00024 class RingBuffer;
00025 class ProgramInfo;
00026 class LiveTVChain;
00027 class MythDialog;
00028 class QPainter;
00029
00030 struct osdInfo
00031 {
00032 QHash<QString,QString> text;
00033 QHash<QString,int> values;
00034 };
00035
00036 typedef enum
00037 {
00038 kPseudoNormalLiveTV = 0,
00039 kPseudoChangeChannel = 1,
00040 kPseudoRecording = 2,
00041 } PseudoState;
00042
00043 typedef deque<QString> StringDeque;
00044 typedef QHash<QString,QString> InfoMap;
00045
00046 class MTV_PUBLIC PlayerContext : public QObject
00047 {
00048 Q_OBJECT
00049 public:
00050 PlayerContext(const QString &inUseID = QString("Unknown"));
00051 ~PlayerContext();
00052
00053
00054 bool CreatePlayer(TV *tv, QWidget *widget,
00055 TVState desiredState,
00056 bool embed, const QRect &embedBounds = QRect(),
00057 bool muted = false);
00058 void TeardownPlayer(void);
00059 bool StartPlaying(int maxWait = -1);
00060 void StopPlaying(void);
00061 void UpdateTVChain(void);
00062 bool ReloadTVChain(void);
00063 void CreatePIPWindow(const QRect&, int pos = -1,
00064 QWidget *widget = NULL);
00065 void ResizePIPWindow(const QRect&);
00066 bool StartPIPPlayer(TV *tv, TVState desiredState);
00067 void PIPTeardown(void);
00068 void SetNullVideo(bool setting) { useNullVideo = setting; }
00069 bool StartEmbedding(WId wid, const QRect&);
00070 void StopEmbedding(void);
00071 void PushPreviousChannel(void);
00072 QString PopPreviousChannel(void);
00073
00074 void ChangeState(TVState newState);
00075 void ForceNextStateNone(void);
00076 TVState DequeueNextState(void);
00077
00078 void ResizePIPWindow(void);
00079 bool HandlePlayerSpeedChangeFFRew(void);
00080 bool HandlePlayerSpeedChangeEOF(void);
00081
00082
00083 void LockState(void) const;
00084 void UnlockState(void) const;
00085
00086 void LockPlayingInfo(const char *file, int line) const;
00087 void UnlockPlayingInfo(const char *file, int line) const;
00088
00089 void LockDeletePlayer(const char *file, int line) const;
00090 void UnlockDeletePlayer(const char *file, int line) const;
00091
00092 void LockOSD(void) const;
00093 void UnlockOSD(void) const;
00094
00095
00096 void SetInitialTVState(bool islivetv);
00097 void SetPlayer(MythPlayer *new_player);
00098 void SetRecorder(RemoteEncoder *rec);
00099 void SetTVChain(LiveTVChain *chain);
00100 void SetRingBuffer(RingBuffer *buf);
00101 void SetPlayingInfo(const ProgramInfo *info);
00102 void SetPlayGroup(const QString &group);
00103 void SetPseudoLiveTV(const ProgramInfo *pi, PseudoState new_state);
00104 void SetPIPLocation(int loc) { pipLocation = loc; }
00105 void SetPIPState(PIPState change) { pipState = change; }
00106 void SetPlayerChangingBuffers(bool val) { playerUnsafe = val; }
00107 void SetNoHardwareDecoders(void) { nohardwaredecoders = true; }
00108
00109
00110 QRect GetStandAlonePIPRect(void);
00111 PIPState GetPIPState(void) const { return pipState; }
00112 QString GetPreviousChannel(void) const;
00113 bool CalcPlayerSliderPosition(osdInfo &info,
00114 bool paddedFields = false) const;
00115 uint GetCardID(void) const { return last_cardid; }
00116 QString GetFilters(const QString &baseFilters) const;
00117 QString GetPlayMessage(void) const;
00118 TVState GetState(void) const;
00119 bool GetPlayingInfoMap(InfoMap &infoMap) const;
00120
00121
00122 bool IsPIPSupported(void) const;
00123 bool IsPBPSupported(void) const;
00124 bool IsPIP(void) const
00125 { return (kPIPonTV == pipState) || (kPIPStandAlone == pipState); }
00126 bool IsPBP(void) const
00127 { return (kPBPLeft == pipState) || (kPBPRight == pipState); }
00128 bool IsPrimaryPBP(void) const
00129 { return (kPBPLeft == pipState); }
00130 bool IsAudioNeeded(void) const
00131 { return (kPIPOff == pipState) || (kPBPLeft == pipState); }
00132 bool IsNullVideoDesired(void) const { return useNullVideo; }
00133 bool IsPlayerChangingBuffers(void) const { return playerUnsafe; }
00134 bool IsEmbedding(void) const;
00135 bool HasPlayer(void) const;
00136 bool IsPlayerErrored(void) const;
00137 bool IsPlayerRecoverable(void) const;
00138 bool IsPlayerDecoderErrored(void) const;
00139 bool IsPlayerPlaying(void) const;
00140 bool IsRecorderErrored(void) const;
00141 bool InStateChange(void) const;
00143 bool IsErrored(void) const { return errored; }
00144 bool IsSameProgram(const ProgramInfo &p) const;
00145 bool IsValidLiveTV(void) const
00146 { return player && tvchain && recorder && buffer; }
00147
00148 public:
00149 QString recUsage;
00150 MythPlayer *player;
00151 volatile bool playerUnsafe;
00152 RemoteEncoder *recorder;
00153 LiveTVChain *tvchain;
00154 RingBuffer *buffer;
00155 ProgramInfo *playingInfo;
00156 long long playingLen;
00157 bool nohardwaredecoders;
00158 int last_cardid;
00159
00160 int ff_rew_state;
00162 int ff_rew_index;
00164 int ff_rew_speed;
00165 TVState playingState;
00166
00167 bool errored;
00168
00169
00170 StringDeque prevChan;
00171
00172
00173 ProgramInfo *pseudoLiveTVRec;
00174 PseudoState pseudoLiveTVState;
00175
00176 int fftime;
00177 int rewtime;
00178 int jumptime;
00185 float ts_normal;
00186 float ts_alt;
00187
00188 mutable QMutex playingInfoLock;
00189 mutable QMutex deletePlayerLock;
00190 mutable QMutex stateLock;
00191
00192
00193 mutable QStringList lastSignalMsg;
00194 mutable MythTimer lastSignalMsgTime;
00195 mutable InfoMap lastSignalUIInfo;
00196 mutable MythTimer lastSignalUIInfoTime;
00197
00198
00199 MythDeque<TVState> nextState;
00200
00201
00202 PIPState pipState;
00203 QRect pipRect;
00204 QWidget *parentWidget;
00206 int pipLocation;
00208 bool useNullVideo;
00209
00211 static const uint kSMExitTimeout;
00212 static const uint kMaxChannelHistory;
00213 };
00214
00215 #endif // _PLAYER_CONTEXT_H_