9 #include <QWaitCondition>
10 #include <QStringList>
16 #if QT_VERSION >= QT_VERSION_CHECK(5,14,0)
17 #include <QRecursiveMutex>
19 #include <QReadWriteLock>
24 #include "libmythbase/mythconfig.h"
146 Q_DECLARE_TR_FUNCTIONS(
TVRec)
149 friend class TVRecRecordThread;
152 explicit
TVRec(
int _inputid);
153 ~
TVRec(
void) override;
157 void RecordPending(const
ProgramInfo *rcinfo,
std::chrono::seconds secsleft,
bool hasLater);
159 RecStatus::Type GetRecordingStatus(
void) const;
161 void StopRecording(
bool killFile =
false);
163 void FinishRecording(
void) { SetFlags(kFlagFinishRecording,
164 __FILE__, __LINE__); }
167 __FILE__, __LINE__); }
168 void CancelNextRecording(
bool cancel);
172 bool IsRunning(
void)
const {
return HasFlags(kFlagRunMainLoop); }
174 void Stop(
void) { ClearFlags(kFlagRunMainLoop, __FILE__, __LINE__); }
178 bool IsPlaying(
void) {
return StateIsPlaying(m_internalState); }
181 bool IsRecording(
void) {
return StateIsRecording(m_internalState); }
183 bool SetVideoFiltersForChannel(
uint sourceid,
const QString &channum);
185 bool IsBusy(
InputInfo *busy_input =
nullptr, std::chrono::seconds time_buffer = 5s)
const;
186 bool IsReallyRecording(
void);
188 float GetFramerate(
void);
189 long long GetFramesWritten(
void);
190 long long GetFilePosition(
void);
191 long long GetMaxBitrate(
void)
const;
192 int64_t GetKeyframePosition(uint64_t desired)
const;
193 bool GetKeyframePositions(int64_t start, int64_t end,
frm_pos_map_t &map)
const;
194 bool GetKeyframeDurations(int64_t start, int64_t end,
frm_pos_map_t &map)
const;
195 void SpawnLiveTV(
LiveTVChain *newchain,
bool pip, QString startchan);
196 QString GetChainID(
void);
197 void StopLiveTV(
void);
198 void PauseRecorder(
void);
199 void ToggleChannelFavorite(
const QString &changroupname);
201 void SetLiveRecording(
int recording);
203 QString GetInput(
void)
const;
204 uint GetSourceID(
void)
const;
205 QString SetInput(QString input);
209 { SetChannel(QString(
"NextChannel %1").arg((
int)dir)); }
210 void SetChannel(
const QString& name,
uint requestType = kFlagDetect);
211 bool QueueEITChannelChange(
const QString &name);
213 std::chrono::milliseconds SetSignalMonitoringRate(std::chrono::milliseconds rate,
int notifyFrontend = 1);
217 bool CheckChannel(
const QString& name)
const;
218 bool ShouldSwitchToAnotherInput(
const QString& chanid)
const;
219 bool CheckChannelPrefix(
const QString &
prefix,
uint &complete_valid_channel_on_rec,
220 bool &is_extra_char_useful, QString &needed_spacer)
const;
222 QString &title, QString &subtitle,
223 QString &desc, QString &category,
224 QString &starttime, QString &endtime,
225 QString &callsign, QString &iconpath,
226 QString &channum,
uint &chanid,
227 QString &seriesid, QString &programid);
228 bool GetChannelInfo(
uint &chanid,
uint &sourceid,
229 QString &callsign, QString &channum,
230 QString &channame, QString &xmltvid)
const;
231 bool SetChannelInfo(
uint chanid,
uint sourceid,
const QString& oldchannum,
232 const QString& callsign,
const QString& channum,
233 const QString& channame,
const QString& xmltvid);
240 bool IsErrored(
void)
const {
return HasFlags(kFlagErrored); }
243 void RecorderPaused(
void);
245 void SetNextLiveTVDir(QString dir);
251 void AllGood(
void)
override { WakeEventLoop(); }
255 void EnableActiveScan(
bool enable);
258 void run(
void)
override;
259 bool WaitForEventThreadSleep(
bool wake =
true,
260 std::chrono::milliseconds time = std::chrono::milliseconds::max());
265 void TeardownAll(
void);
266 void WakeEventLoop(
void);
268 static bool GetDevices(
uint inputid,
274 void TeardownRecorder(
uint request_flags);
277 bool CreateChannel(
const QString &startchannel,
278 bool enter_power_save_mode);
279 void CloseChannel(
void);
283 bool SetupSignalMonitor(
284 bool tablemon,
bool EITscan,
bool notify);
285 bool SetupDTVSignalMonitor(
bool EITscan);
286 void TeardownSignalMonitor(
void);
290 void SetFlags(
uint f,
const QString &
file,
int line);
291 void ClearFlags(
uint f,
const QString &
file,
int line);
292 static QString FlagToString(
uint f);
294 void HandleTuning(
void);
300 void TuningRestartRecorder(
void);
301 QString TuningGetChanNum(
const TuningRequest &request, QString &input)
const;
304 void HandleStateChange(
void);
305 void ChangeState(
TVState nextState);
306 static bool StateIsRecording(
TVState state);
307 static bool StateIsPlaying(
TVState state);
311 void HandlePendingRecordings(
void);
313 bool WaitForNextLiveTVDir(
void);
315 const QString &channum);
316 bool CreateLiveTVRingBuffer(
const QString & channum);
317 bool SwitchLiveTVRingBuffer(
const QString & channum,
318 bool discont,
bool set_rec);
324 QDateTime GetRecordEndTime(
const ProgramInfo *pi)
const;
325 void CheckForRecGroupChange(
void);
331 void SetRecordingStatus(
344 bool m_signalEventCmdSent {
false};
348 uint m_signalMonitorCheckCnt {0};
349 bool m_reachedRecordingDeadline {
false};
351 bool m_reachedPreFail {
false};
360 bool m_transcodeFirst {
false};
361 bool m_earlyCommFlag {
false};
362 bool m_runJobOnHostOnly {
false};
363 std::chrono::seconds m_eitCrawlIdleStart {1min};
364 std::chrono::seconds m_eitTransportTimeout {5min};
365 int m_audioSampleRateDB {0};
366 std::chrono::seconds m_overRecordSecNrml {0s};
367 std::chrono::seconds m_overRecordSecCat {0s};
373 bool m_isPip {
false};
384 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
385 mutable QMutex m_stateChangeLock {QMutex::Recursive};
386 mutable QMutex m_pendingRecLock {QMutex::Recursive};
393 bool m_changeState {
false};
394 bool m_pauseNotify {
true};
401 bool m_triggerEventLoopSignal {
false};
404 bool m_triggerEventSleepSignal {
false};
405 volatile bool m_switchingBuffer {
false};
413 int m_overrecordseconds {0};
430 QString m_rbFileExt {
"ts"};
438 static constexpr std::chrono::milliseconds kSignalMonitoringRate { 50ms };
441 static const uint kFlagFrontendReady = 0x00000001;
442 static const uint kFlagRunMainLoop = 0x00000002;
443 static const uint kFlagExitPlayer = 0x00000004;
444 static const uint kFlagFinishRecording = 0x00000008;
445 static const uint kFlagErrored = 0x00000010;
446 static const uint kFlagCancelNextRecording = 0x00000020;
450 static const uint kFlagLiveTV = 0x00000100;
452 static const uint kFlagRecording = 0x00000200;
454 static const uint kFlagAntennaAdjust = 0x00000400;
455 static const uint kFlagRec = 0x00000F00;
459 static const uint kFlagEITScan = 0x00001000;
461 static const uint kFlagCloseRec = 0x00002000;
463 static const uint kFlagKillRec = 0x00004000;
465 static const uint kFlagNoRec = 0x0000F000;
466 static const uint kFlagKillRingBuffer = 0x00010000;
469 static const uint kFlagWaitingForRecPause = 0x00100000;
470 static const uint kFlagWaitingForSignal = 0x00200000;
471 static const uint kFlagNeedToStartRecorder = 0x00800000;
472 static const uint kFlagPendingActions = 0x00F00000;
475 static const uint kFlagSignalMonitorRunning = 0x01000000;
476 static const uint kFlagEITScannerRunning = 0x04000000;
478 static const uint kFlagDummyRecorderRunning = 0x10000000;
479 static const uint kFlagRecorderRunning = 0x20000000;
480 static const uint kFlagAnyRecRunning = 0x30000000;
481 static const uint kFlagAnyRunning = 0x3F000000;
484 static const uint kFlagRingBufferReady = 0x40000000;
485 static const uint kFlagDetect = 0x80000000;