00001 #ifndef TVPLAY_H
00002 #define TVPLAY_H
00003
00004 #include <qstring.h>
00005 #include <qmap.h>
00006 #include <qdatetime.h>
00007 #include <pthread.h>
00008 #include <qvaluevector.h>
00009 #include <qvaluelist.h>
00010 #include <qptrlist.h>
00011 #include <qmutex.h>
00012 #include <qstringlist.h>
00013 #include <qregexp.h>
00014 #include <qwaitcondition.h>
00015
00016 #include "mythdeque.h"
00017 #include "tv.h"
00018 #include "util.h"
00019 #include "programinfo.h"
00020 #include "channelutil.h"
00021 #include "videoouttypes.h"
00022 #include "inputinfo.h"
00023
00024 #include <qobject.h>
00025
00026 #include <vector>
00027 using namespace std;
00028
00029 class QDateTime;
00030 class OSD;
00031 class RemoteEncoder;
00032 class NuppelVideoPlayer;
00033 class RingBuffer;
00034 class ProgramInfo;
00035 class MythDialog;
00036 class UDPNotify;
00037 class OSDListTreeType;
00038 class OSDGenericTree;
00039 class LiveTVChain;
00040
00041 typedef QValueVector<QString> str_vec_t;
00042 typedef QMap<QString,QString> InfoMap;
00043 typedef QMap<QString,InfoMap> DDValueMap;
00044 typedef QMap<QString,DDValueMap> DDKeyMap;
00045 typedef ProgramInfo * (*RUNPLAYBACKBOX)(void *, bool);
00046 typedef void (*RUNVIEWSCHEDULED) (void *, bool);
00047
00048 class VBIMode
00049 {
00050 public:
00051 typedef enum
00052 {
00053 None = 0,
00054 PAL_TT = 1,
00055 NTSC_CC = 2,
00056 } vbimode_t;
00057
00058 static uint Parse(QString vbiformat)
00059 {
00060 QString fmt = vbiformat.lower().left(4);
00061 vbimode_t mode;
00062 mode = (fmt == "pal ") ? PAL_TT : ((fmt == "ntsc") ? NTSC_CC : None);
00063 return (uint) mode;
00064 }
00065 };
00066
00067 typedef enum
00068 {
00069 kPseudoNormalLiveTV = 0,
00070 kPseudoChangeChannel = 1,
00071 kPseudoRecording = 2,
00072 } PseudoState;
00073
00074 enum scheduleEditTypes {
00075 kScheduleProgramGuide = 0,
00076 kScheduleProgramFinder,
00077 kScheduledRecording,
00078 kViewSchedule,
00079 kPlaybackBox
00080 };
00081
00082 typedef enum
00083 {
00084 kAskAllowCancel,
00085 kAskAllowOneRec,
00086 kAskAllowMultiRec,
00087 } AskAllowType;
00088
00089 class AskProgramInfo
00090 {
00091 public:
00092 AskProgramInfo() : info(NULL) {}
00093 AskProgramInfo(const QDateTime &e, bool r, bool l, ProgramInfo *i) :
00094 expiry(e), has_rec(r), has_later(l),
00095 is_in_same_input_group(false), is_conflicting(false),
00096 info(i) {}
00097
00098 QDateTime expiry;
00099 bool has_rec;
00100 bool has_later;
00101 bool is_in_same_input_group;
00102 bool is_conflicting;
00103 ProgramInfo *info;
00104 };
00105
00106 class MPUBLIC TV : public QObject
00107 {
00108 Q_OBJECT
00109 public:
00111 class SleepTimerInfo
00112 {
00113 public:
00114 SleepTimerInfo(QString str, unsigned long secs)
00115 : dispString(str), seconds(secs) { ; }
00116 QString dispString;
00117 unsigned long seconds;
00118 };
00119
00120 TV(void);
00121 ~TV();
00122
00123 bool Init(bool createWindow = true);
00124
00125
00126 void ProcessKeypress(QKeyEvent *e);
00127 void ProcessNetworkControlCommand(const QString &command);
00128 void customEvent(QCustomEvent *e);
00129 bool HandleTrackAction(const QString &action);
00130
00131
00132 int LiveTV(bool showDialogs = true, bool startInGuide = false);
00135 void StopLiveTV(void) { exitPlayer = true; }
00136 void AddPreviousChannel(void);
00137 void PreviousChannel(void);
00138
00139
00140 void EmbedOutput(WId wid, int x, int y, int w, int h);
00141 void StopEmbeddingOutput(void);
00142 bool IsEmbedding(void);
00143 bool IsTunable(uint chanid, bool use_cache = false);
00144 void ClearTunableCache(void);
00145 void ChangeChannel(const DBChanList &options);
00146
00147 void DrawUnusedRects(bool sync);
00148
00149
00150 int PlayFromRecorder(int recordernum);
00151 int Playback(ProgramInfo *rcinfo);
00152
00153
00154 void setLastProgram(ProgramInfo *rcinfo);
00155 ProgramInfo *getLastProgram(void) { return lastProgram; }
00156 ProgramInfo *getCurrentProgram(void) { return playbackinfo; }
00157 void setInPlayList(bool setting) { inPlaylist = setting; }
00158 void setUnderNetworkControl(bool setting) { underNetworkControl = setting; }
00159 bool IsSameProgram(ProgramInfo *p);
00160
00161 void ShowNoRecorderDialog(void);
00162 void FinishRecording(void);
00163 void AskAllowRecording(const QStringList&, int, bool, bool);
00164 void PromptStopWatchingRecording(void);
00165 void PromptDeleteRecording(QString title);
00166 bool PromptRecGroupPassword(void);
00167 bool BookmarkAllowed(void);
00168 bool DeleteAllowed(void);
00169
00170
00172 bool IsPlaying(void) const { return StateIsPlaying(GetState()); }
00174 bool IsRecording(void) const { return StateIsRecording(GetState()); }
00176 bool IsMenuRunning(void) const { return menurunning; }
00178 bool IsSwitchingCards(void) const { return switchToRec; }
00181 bool IsRunning(void) const { return runMainLoop; }
00184 bool WantsToQuit(void) const { return wantsToQuit; }
00187 bool getRequestDelete(void) const { return requestDelete; }
00189 bool getAllowRerecord(void) const { return allowRerecord; }
00192 bool getEndOfRecording(void) const { return endOfRecording; }
00195 bool getJumpToProgram(void) const { return jumpToProgram; }
00197 bool IsErrored(void) const { return errored; }
00199 bool IsVideoExitDialog(void);
00201 bool IsNearEnd(void) const { return isnearend; }
00202
00203
00204 int GetLastRecorderNum(void) const;
00205 TVState GetState(void) const;
00206
00207
00208 OSD *GetOSD(void);
00209
00210 void SetCurrentlyPlaying(ProgramInfo *pginfo);
00211
00212 void GetNextProgram(RemoteEncoder *enc, int direction,
00213 InfoMap &infoMap);
00214
00215
00216 static void InitKeys(void);
00217 static bool StartTV(ProgramInfo *tvrec = NULL, bool startInGuide = false,
00218 bool inPlaylist = false, bool initByNetworkCommand = false);
00219 static void SetFuncPtr(const char *, void *);
00220
00221 void SetIgnoreKeys(bool ignore) { ignoreKeys = ignore; }
00222
00223
00224 void ChangeVolume(bool up);
00225 void ToggleMute(void);
00226
00227 public slots:
00228 void HandleOSDClosed(int osdType);
00229
00230 protected slots:
00231 void SetPreviousChannel(void);
00232 void UnMute(void);
00233 void KeyRepeatOK(void);
00234 void BrowseEndTimer(void) { BrowseEnd(false); }
00235 void SleepEndTimer(void);
00236 void IdleDialog(void);
00237 void TreeMenuEntered(OSDListTreeType *tree, OSDGenericTree *item);
00238 void TreeMenuSelected(OSDListTreeType *tree, OSDGenericTree *item);
00239
00240 protected:
00241 void doEditSchedule(int editType = kScheduleProgramGuide);
00242 static void *RecordedShowMenuHandler(void *param);
00243 static void *ViewScheduledMenuHandler(void *param);
00244
00245 void RunTV(void);
00246 static void *EventThread(void *param);
00247 void SetMuteTimer(int timeout);
00248
00249 bool eventFilter(QObject *o, QEvent *e);
00250 static QStringList lastProgramStringList;
00251 static RUNPLAYBACKBOX RunPlaybackBoxPtr;
00252 static RUNVIEWSCHEDULED RunViewScheduledPtr;
00253
00254 private:
00255 bool RequestNextRecorder(bool showDialogs);
00256 void DeleteRecorder();
00257
00258 bool StartRecorder(RemoteEncoder *rec, int maxWait=-1);
00259 bool StartPlayer(bool isWatchingRecording, int maxWait=-1);
00260 void StartOSD(void);
00261 void StopStuff(bool stopRingbuffers, bool stopPlayers, bool stopRecorders);
00262
00263 void ToggleChannelFavorite(void);
00264 void ChangeChannel(int direction);
00265 void ChangeChannel(uint chanid, const QString &channum);
00266 void PauseLiveTV(void);
00267 void UnpauseLiveTV(void);
00268
00269 void ToggleAspectOverride(AspectOverrideMode aspectMode = kAspect_Toggle);
00270 void ToggleAdjustFill(AdjustFillMode adjustfillMode = kAdjustFill_Toggle);
00271
00272 bool FillMenuTracks(OSDGenericTree*, uint type);
00273 void ChangeTrack(uint type, int dir);
00274 void SetTrack(uint type, int trackNo);
00275
00276
00277 void AddKeyToInputQueue(char key);
00278 void ClearInputQueues(bool hideosd = false);
00279 bool CommitQueuedInput(void);
00280 bool ProcessSmartChannel(QString&);
00281
00282
00283 bool HasQueuedInput(void) const
00284 { return !GetQueuedInput().isEmpty(); }
00285 bool HasQueuedChannel(void) const
00286 { return queuedChanID || !GetQueuedChanNum().isEmpty(); }
00287
00288
00289 QString GetQueuedInput(void) const;
00290 int GetQueuedInputAsInt(bool *ok = NULL, int base = 10) const;
00291 QString GetQueuedChanNum(void) const;
00292 uint GetQueuedChanID(void) const { return queuedChanID; }
00293
00294 void SwitchSource(uint source_direction);
00295 void SwitchInputs(uint inputid);
00296 void ToggleInputs(uint inputid = 0);
00297 void SwitchCards(uint chanid = 0, QString channum = "", uint inputid = 0);
00298
00299 void ToggleSleepTimer(void);
00300 void ToggleSleepTimer(const QString);
00301
00302 void DoPlay(void);
00303 void DoPause(bool showOSD = true);
00304 void DoSeek(float time, const QString &mesg);
00305 bool DoNVPSeek(float time);
00306 enum ArbSeekWhence {
00307 ARBSEEK_SET = 0,
00308 ARBSEEK_REWIND,
00309 ARBSEEK_FORWARD,
00310 ARBSEEK_END
00311 };
00312 void DoArbSeek(ArbSeekWhence whence);
00313 void NormalSpeed(void);
00314 void ChangeSpeed(int direction);
00315 void ToggleTimeStretch(void);
00316 void ChangeTimeStretch(int dir, bool allowEdit = true);
00317 void ChangeAudioSync(int dir, bool allowEdit = true);
00318 float StopFFRew(void);
00319 void ChangeFFRew(int direction);
00320 void SetFFRew(int index);
00321 void DoSkipCommercials(int direction);
00322 void StartProgramEditMode(void);
00323
00324
00325 void StartChannelEditMode(void);
00326 void ChannelEditKey(const QKeyEvent*);
00327 void ChannelEditAutoFill(InfoMap&) const;
00328 void ChannelEditAutoFill(InfoMap&, const QMap<QString,bool>&) const;
00329 void ChannelEditXDSFill(InfoMap&) const;
00330 void ChannelEditDDFill(InfoMap&, const QMap<QString,bool>&, bool) const;
00331 QString GetDataDirect(QString key, QString value,
00332 QString field, bool allow_partial = false) const;
00333 bool LoadDDMap(uint sourceid);
00334 void RunLoadDDMap(uint sourceid);
00335 static void *load_dd_map_thunk(void*);
00336 static void *load_dd_map_post_thunk(void*);
00337
00338 void DoQueueTranscode(QString profile);
00339
00340 enum commSkipMode {
00341 CommSkipOff = 0,
00342 CommSkipOn = 1,
00343 CommSkipNotify = 2,
00344 CommSkipModes = 3,
00345 };
00346 void SetAutoCommercialSkip(enum commSkipMode skipMode = CommSkipOff);
00347 void SetManualZoom(bool zoomON = false);
00348
00349 void DoDisplayJumpMenu(void);
00350 void SetJumpToProgram(QString progKey = "", int progIndex = 0);
00351
00352 bool ClearOSD(void);
00353 void ToggleOSD(bool includeStatusOSD);
00354 void UpdateOSDProgInfo(const char *whichInfo);
00355 void UpdateOSDSeekMessage(const QString &mesg, int disptime);
00356 void UpdateOSDInput(QString inputname = QString::null);
00357 void UpdateOSDTextEntry(const QString &message);
00358 void UpdateOSDSignal(const QStringList& strlist);
00359 void UpdateOSDTimeoutMessage(void);
00360 void UpdateOSDAskAllowDialog(void);
00361 void HandleOSDAskAllowResponse(void);
00362
00363 void EditSchedule(int editType = kScheduleProgramGuide);
00364 void EmbedWithNewThread(int editType);
00365
00366 void SetupPlayer(bool isWatchingRecording);
00367 void TeardownPlayer(void);
00368 void SetupPipPlayer(void);
00369 void TeardownPipPlayer(void);
00370
00371 void HandleStateChange(void);
00372 bool InStateChange(void) const;
00373 void ChangeState(TVState nextState);
00374 void ForceNextStateNone(void);
00375
00376 void TogglePIPView(void);
00377 void ToggleActiveWindow(void);
00378 void SwapPIP(void);
00379 void SwapPIPSoon(void) { needToSwapPIP = true; }
00380
00381 void DisplayJumpMenuSoon(void) { needToJumpMenu = true; }
00382
00383 void ToggleAutoExpire(void);
00384
00385 void BrowseStart(void);
00386 void BrowseEnd(bool change);
00387 void BrowseDispInfo(int direction);
00388 void ToggleRecord(void);
00389 void BrowseChannel(const QString &channum);
00390
00391 void DoTogglePictureAttribute(PictureAdjustType type);
00392 void DoChangePictureAttribute(
00393 PictureAdjustType type, PictureAttribute attr, bool up);
00394
00395 void BuildOSDTreeMenu(void);
00396 void ShowOSDTreeMenu(void);
00397 void FillMenuLiveTV(OSDGenericTree *treeMenu);
00398 void FillMenuPlaying(OSDGenericTree *treeMenu);
00399
00400 void UpdateLCD(void);
00401 void ShowLCDChannelInfo(void);
00402 void ShowLCDDVDInfo(void);
00403
00404 QString PlayMesg(void);
00405
00406 void GetPlayGroupSettings(const QString &group);
00407
00408 void SetPseudoLiveTV(uint, const ProgramInfo*, PseudoState);
00409
00410 void ITVRestart(bool isLive);
00411
00412 bool ScreenShot(long long frameNumber);
00413
00414 bool VideoThemeCheck(QString str, bool stayPaused = false);
00415
00416
00417 void DVDJumpBack(void);
00418 void DVDJumpForward(void);
00419
00420 static bool LoadExternalSubtitles(NuppelVideoPlayer *nvp,
00421 const QString &videoFile);
00422
00423 static QStringList GetValidRecorderList(uint chanid);
00424 static QStringList GetValidRecorderList(const QString &channum);
00425 static QStringList GetValidRecorderList(uint, const QString&);
00426
00427 static bool StateIsRecording(TVState state);
00428 static bool StateIsPlaying(TVState state);
00429 static bool StateIsLiveTV(TVState state);
00430 static TVState RemovePlaying(TVState state);
00431 static TVState RemoveRecording(TVState state);
00432
00433 private:
00434
00435 QString baseFilters;
00436 QString db_channel_format;
00437 QString db_time_format;
00438 QString db_short_date_format;
00439 int fftime;
00440 int rewtime;
00441 int jumptime;
00442 bool smartChannelChange;
00443 bool MuteIndividualChannels;
00444 bool arrowAccel;
00445 int osd_general_timeout;
00446 int osd_prog_info_timeout;
00447
00448 enum commSkipMode autoCommercialSkip;
00449 bool tryUnflaggedSkip;
00450
00451 bool smartForward;
00452 int stickykeys;
00453 float ff_rew_repos;
00454 bool ff_rew_reverse;
00455 bool jumped_back;
00456 vector<int> ff_rew_speeds;
00457
00458 uint vbimode;
00459
00460
00461 MythDeque<TVState> nextStates;
00462 mutable QMutex stateLock;
00463 TVState internalState;
00464
00465 uint switchToInputId;
00466 bool menurunning;
00467 bool runMainLoop;
00468 bool wantsToQuit;
00469 bool exitPlayer;
00470 bool paused;
00471 bool errored;
00472 bool stretchAdjustment;
00473 bool audiosyncAdjustment;
00474 long long audiosyncBaseline;
00475 bool editmode;
00476 bool zoomMode;
00477 bool sigMonMode;
00478 bool update_osd_pos;
00479 bool endOfRecording;
00480 bool requestDelete;
00481 bool allowRerecord;
00482 bool doSmartForward;
00483 bool queuedTranscode;
00484 bool getRecorderPlaybackInfo;
00485
00486 PictureAdjustType adjustingPicture;
00488 PictureAttribute adjustingPictureAttribute;
00489
00490
00491 AskAllowType askAllowType;
00492 QMap<QString,AskProgramInfo> askAllowPrograms;
00493 QMutex askAllowLock;
00494
00495 bool ignoreKeys;
00496 bool needToSwapPIP;
00497 bool needToJumpMenu;
00498 QMap<QString,ProgramList> progLists;
00499
00500 mutable QMutex chanEditMapLock;
00501 InfoMap chanEditMap;
00502 DDKeyMap ddMap;
00503 uint ddMapSourceId;
00504 bool ddMapLoaderRunning;
00505 pthread_t ddMapLoader;
00506
00509 vector<SleepTimerInfo> sleep_times;
00510 uint sleep_index;
00511 QTimer *sleepTimer;
00512 QTimer *idleTimer;
00513
00515 QPtrList<QKeyEvent> keyList;
00517 QMutex keyListLock;
00518 bool keyRepeat;
00519 QTimer *keyrepeatTimer;
00520
00521 int doing_ff_rew;
00522 int ff_rew_index;
00523 int speed_index;
00524
00531 float normal_speed;
00532 float prev_speed;
00533
00534 float frameRate;
00535
00536
00538 bool ccInputMode;
00540 QTime ccInputModeExpires;
00541
00542
00544 bool asInputMode;
00546 QTime asInputModeExpires;
00547
00548
00550 QString queuedInput;
00552 mutable QString queuedChanNum;
00554 uint queuedChanID;
00557 mutable QMutex queuedInputLock;
00558
00559 QTimer *muteTimer;
00560
00561
00562 QTime lockTimer;
00563 bool lockTimerOn;
00564 QDateTime lastLockSeenTime;
00565
00566
00567 str_vec_t prevChan;
00568 uint prevChanKeyCnt;
00569 QTimer *prevChanTimer;
00570
00571
00572 bool browsemode;
00573 bool persistentbrowsemode;
00574 QTimer *browseTimer;
00575 QString browsechannum;
00576 QString browsechanid;
00577 QString browsestarttime;
00578
00579
00580
00581 ProgramInfo *recorderPlaybackInfo;
00582 ProgramInfo *playbackinfo;
00583 QMutex pbinfoLock;
00584 int playbackLen;
00585 ProgramInfo *lastProgram;
00586 bool jumpToProgram;
00587
00588 bool inPlaylist;
00589 bool underNetworkControl;
00590 bool isnearend;
00591
00592
00593 ProgramInfo *pseudoLiveTVRec[2];
00594 PseudoState pseudoLiveTVState[2];
00595
00596
00597 NuppelVideoPlayer *nvp;
00598 NuppelVideoPlayer *pipnvp;
00599 NuppelVideoPlayer *activenvp;
00600
00601
00603 RemoteEncoder *recorder;
00605 RemoteEncoder *piprecorder;
00607 RemoteEncoder *activerecorder;
00609 RemoteEncoder *switchToRec;
00611 int lastrecordernum;
00612
00613
00614 LiveTVChain *tvchain;
00615 LiveTVChain *piptvchain;
00616 QStringList tvchainUpdate;
00617 QMutex tvchainUpdateLock;
00618
00619
00620 RingBuffer *prbuffer;
00621 RingBuffer *piprbuffer;
00622 RingBuffer *activerbuffer;
00623
00624
00625 QString dialogname;
00626 OSDGenericTree *treeMenu;
00627 MythTimer dialogboxTimer;
00628
00631 UDPNotify *udpnotify;
00632 QStringList lastSignalMsg;
00633 MythTimer lastSignalMsgTime;
00634 InfoMap lastSignalUIInfo;
00635 MythTimer lastSignalUIInfoTime;
00636 QMutex osdlock;
00637
00638
00639 QDateTime lastLcdUpdate;
00640 QString lcdTitle;
00641 QString lcdSubtitle;
00642 QString lcdCallsign;
00643
00644
00645 MythDialog *myWindow;
00646 WId embedWinID;
00647 QRect embedBounds;
00648
00649 QRect player_bounds;
00651 QRect saved_gui_bounds;
00652
00653
00654 mutable QMutex is_tunable_cache_lock;
00655 QMap< uint,vector<InputInfo> > is_tunable_cache_inputs;
00656
00657
00659 pthread_t event;
00661 pthread_t decode;
00664 pthread_t pipdecode;
00665
00667 QWaitCondition mainLoopCond;
00668 QMutex mainLoopCondLock;
00669
00670
00671 static const int kInitFFRWSpeed;
00672 static const int kMuteTimeout;
00673 static const int kLCDTimeout;
00674 static const int kBrowseTimeout;
00675
00676 static const int kSMExitTimeout;
00677 static const int kInputKeysMax;
00678 static const int kInputModeTimeout;
00679
00680 static const uint kNextSource;
00681 static const uint kPreviousSource;
00682
00683
00684 QValueList<QString> networkControlCommands;
00685 QMutex ncLock;
00686 };
00687
00688 #endif