9 #include <QWaitCondition>
10 #include <QStringList>
16 #include <QRecursiveMutex>
17 #include <QReadWriteLock>
22 #include "libmythbase/mythconfig.h"
144 Q_DECLARE_TR_FUNCTIONS(
TVRec)
147 friend class TVRecRecordThread;
150 explicit
TVRec(
int _inputid);
151 ~
TVRec(
void) override;
155 void RecordPending(const
ProgramInfo *rcinfo, std::chrono::seconds secsleft,
bool hasLater);
157 RecStatus::Type GetRecordingStatus(
void) const;
159 void StopRecording(
bool killFile =
false);
161 void FinishRecording(
void) { SetFlags(kFlagFinishRecording,
162 __FILE__, __LINE__); }
165 __FILE__, __LINE__); }
166 void CancelNextRecording(
bool cancel);
170 bool IsRunning(
void)
const {
return HasFlags(kFlagRunMainLoop); }
172 void Stop(
void) { ClearFlags(kFlagRunMainLoop, __FILE__, __LINE__); }
176 bool IsPlaying(
void) {
return StateIsPlaying(m_internalState); }
179 bool IsRecording(
void) {
return StateIsRecording(m_internalState); }
181 bool SetVideoFiltersForChannel(
uint sourceid,
const QString &channum);
183 bool IsBusy(
InputInfo *busy_input =
nullptr, std::chrono::seconds time_buffer = 5s)
const;
184 bool IsReallyRecording(
void);
186 float GetFramerate(
void);
187 long long GetFramesWritten(
void);
188 long long GetFilePosition(
void);
189 long long GetMaxBitrate(
void)
const;
190 int64_t GetKeyframePosition(uint64_t desired)
const;
191 bool GetKeyframePositions(int64_t start, int64_t end,
frm_pos_map_t &map)
const;
192 bool GetKeyframeDurations(int64_t start, int64_t end,
frm_pos_map_t &map)
const;
193 void SpawnLiveTV(
LiveTVChain *newchain,
bool pip, QString startchan);
194 QString GetChainID(
void);
195 void StopLiveTV(
void);
196 void PauseRecorder(
void);
197 void ToggleChannelFavorite(
const QString &changroupname);
199 void SetLiveRecording(
int recording);
201 QString GetInput(
void)
const;
202 uint GetSourceID(
void)
const;
203 QString SetInput(QString input);
207 { SetChannel(QString(
"NextChannel %1").arg((
int)dir)); }
208 void SetChannel(
const QString& name,
uint requestType = kFlagDetect);
209 bool QueueEITChannelChange(
const QString &name);
211 std::chrono::milliseconds SetSignalMonitoringRate(std::chrono::milliseconds rate,
int notifyFrontend = 1);
215 bool CheckChannel(
const QString& name)
const;
216 bool ShouldSwitchToAnotherInput(
const QString& chanid)
const;
217 bool CheckChannelPrefix(
const QString &
prefix,
uint &complete_valid_channel_on_rec,
218 bool &is_extra_char_useful, QString &needed_spacer)
const;
220 QString &title, QString &subtitle,
221 QString &desc, QString &category,
222 QString &starttime, QString &endtime,
223 QString &callsign, QString &iconpath,
224 QString &channum,
uint &chanid,
225 QString &seriesid, QString &programid);
226 bool GetChannelInfo(
uint &chanid,
uint &sourceid,
227 QString &callsign, QString &channum,
228 QString &channame, QString &xmltvid)
const;
229 bool SetChannelInfo(
uint chanid,
uint sourceid,
const QString& oldchannum,
230 const QString& callsign,
const QString& channum,
231 const QString& channame,
const QString& xmltvid);
238 bool IsErrored(
void)
const {
return HasFlags(kFlagErrored); }
241 void RecorderPaused(
void);
243 void SetNextLiveTVDir(QString dir);
249 void AllGood(
void)
override { WakeEventLoop(); }
253 void EnableActiveScan(
bool enable);
256 void run(
void)
override;
257 bool WaitForEventThreadSleep(
bool wake =
true,
258 std::chrono::milliseconds time = std::chrono::milliseconds::max());
263 void TeardownAll(
void);
264 void WakeEventLoop(
void);
266 static bool GetDevices(
uint inputid,
272 void TeardownRecorder(
uint request_flags);
275 bool CreateChannel(
const QString &startchannel,
276 bool enter_power_save_mode);
277 void CloseChannel(
void);
281 bool SetupSignalMonitor(
282 bool tablemon,
bool EITscan,
bool notify);
283 bool SetupDTVSignalMonitor(
bool EITscan);
284 void TeardownSignalMonitor(
void);
288 void SetFlags(
uint f,
const QString &
file,
int line);
289 void ClearFlags(
uint f,
const QString &
file,
int line);
290 static QString FlagToString(
uint f);
292 void HandleTuning(
void);
298 void TuningRestartRecorder(
void);
299 QString TuningGetChanNum(
const TuningRequest &request, QString &input)
const;
302 void HandleStateChange(
void);
303 void ChangeState(
TVState nextState);
304 static bool StateIsRecording(
TVState state);
305 static bool StateIsPlaying(
TVState state);
309 void HandlePendingRecordings(
void);
311 bool WaitForNextLiveTVDir(
void);
313 const QString &channum);
314 bool CreateLiveTVRingBuffer(
const QString & channum);
315 bool SwitchLiveTVRingBuffer(
const QString & channum,
316 bool discont,
bool set_rec);
322 QDateTime GetRecordEndTime(
const ProgramInfo *pi)
const;
323 void CheckForRecGroupChange(
void);
329 void SetRecordingStatus(
342 bool m_signalEventCmdSent {
false};
346 uint m_signalMonitorCheckCnt {0};
347 bool m_reachedRecordingDeadline {
false};
349 bool m_reachedPreFail {
false};
358 bool m_transcodeFirst {
false};
359 bool m_earlyCommFlag {
false};
360 bool m_runJobOnHostOnly {
false};
361 std::chrono::seconds m_eitCrawlIdleStart {1min};
362 std::chrono::seconds m_eitTransportTimeout {5min};
363 std::chrono::seconds m_eitScanPeriod {15min};
364 int m_audioSampleRateDB {0};
365 std::chrono::seconds m_overRecordSecNrml {0s};
366 std::chrono::seconds m_overRecordSecCat {0s};
372 bool m_isPip {
false};
391 bool m_changeState {
false};
392 bool m_pauseNotify {
true};
400 bool m_triggerEventLoopSignal {
false};
403 bool m_triggerEventSleepSignal {
false};
404 volatile bool m_switchingBuffer {
false};
412 int m_overrecordseconds {0};
429 QString m_rbFileExt {
"ts"};
437 static constexpr std::chrono::milliseconds kSignalMonitoringRate { 50ms };
440 static const uint kFlagFrontendReady = 0x00000001;
441 static const uint kFlagRunMainLoop = 0x00000002;
442 static const uint kFlagExitPlayer = 0x00000004;
443 static const uint kFlagFinishRecording = 0x00000008;
444 static const uint kFlagErrored = 0x00000010;
445 static const uint kFlagCancelNextRecording = 0x00000020;
449 static const uint kFlagLiveTV = 0x00000100;
451 static const uint kFlagRecording = 0x00000200;
453 static const uint kFlagAntennaAdjust = 0x00000400;
454 static const uint kFlagRec = 0x00000F00;
458 static const uint kFlagEITScan = 0x00001000;
460 static const uint kFlagCloseRec = 0x00002000;
462 static const uint kFlagKillRec = 0x00004000;
464 static const uint kFlagNoRec = 0x0000F000;
465 static const uint kFlagKillRingBuffer = 0x00010000;
468 static const uint kFlagWaitingForRecPause = 0x00100000;
469 static const uint kFlagWaitingForSignal = 0x00200000;
470 static const uint kFlagNeedToStartRecorder = 0x00800000;
471 static const uint kFlagPendingActions = 0x00F00000;
474 static const uint kFlagSignalMonitorRunning = 0x01000000;
475 static const uint kFlagEITScannerRunning = 0x04000000;
477 static const uint kFlagDummyRecorderRunning = 0x10000000;
478 static const uint kFlagRecorderRunning = 0x20000000;
479 static const uint kFlagAnyRecRunning = 0x30000000;
480 static const uint kFlagAnyRunning = 0x3F000000;
483 static const uint kFlagRingBufferReady = 0x40000000;
484 static const uint kFlagDetect = 0x80000000;