MythTV master
cetonrecorder.cpp
Go to the documentation of this file.
1
7#include <thread>
8
9// MythTV includes
11#include "cetonstreamhandler.h"
12#include "cetonrecorder.h"
13#include "cetonchannel.h"
14#include "tv_rec.h"
15
16#define LOC QString("CetonRec[%1]: ") \
17 .arg(m_tvrec ? m_tvrec->GetInputId() : -1)
18
20{
21 if (IsOpen())
22 {
23 LOG(VB_GENERAL, LOG_WARNING, LOC + "Card already open");
24 return true;
25 }
26
28
30 m_tvrec ? m_tvrec->GetInputId() : -1);
31
32 LOG(VB_RECORD, LOG_INFO, LOC + "Ceton opened successfully");
33
34 return true;
35}
36
38{
39 LOG(VB_RECORD, LOG_INFO, LOC + "Close() -- begin");
40
41 if (IsOpen())
43 m_tvrec ? m_tvrec->GetInputId() : -1);
44
45 LOG(VB_RECORD, LOG_INFO, LOC + "Close() -- end");
46}
47
49{
50 // Make sure the first things in the file are a PAT & PMT
53}
54
56{
57 LOG(VB_RECORD, LOG_INFO, LOC + "run -- begin");
58
59 /* Create video socket. */
60 if (!Open())
61 {
62 m_error = "Failed to open CetonRecorder device";
63 LOG(VB_GENERAL, LOG_ERR, LOC + m_error);
64 return;
65 }
66
67 {
68 QMutexLocker locker(&m_pauseLock);
69 m_requestRecording = true;
70 m_recording = true;
71 m_recordingWait.wakeAll();
72 }
73
75
79
80 while (IsRecordingRequested() && !IsErrored())
81 {
82 if (PauseAndWait())
83 continue;
84
86 break;
87
88 { // sleep 100 milliseconds unless StopRecording() or Unpause()
89 // is called, just to avoid running this too often.
90 QMutexLocker locker(&m_pauseLock);
92 continue;
93 m_unpauseWait.wait(&m_pauseLock, 100);
94 }
95
96 if (!m_inputPmt)
97 {
98 LOG(VB_GENERAL, LOG_WARNING, LOC +
99 "Recording will not commence until a PMT is set.");
100 std::this_thread::sleep_for(5ms);
101 continue;
102 }
103
105 {
106 m_error = "Stream handler died unexpectedly.";
107 LOG(VB_GENERAL, LOG_ERR, LOC + m_error);
108 }
109 }
110
111 LOG(VB_RECORD, LOG_INFO, LOC + "run -- ending...");
112
116
117 Close();
118
120
121 QMutexLocker locker(&m_pauseLock);
122 m_recording = false;
123 m_recordingWait.wakeAll();
124
125 LOG(VB_RECORD, LOG_INFO, LOC + "run -- end");
126}
127
128bool CetonRecorder::PauseAndWait(std::chrono::milliseconds timeout)
129{
130 QMutexLocker locker(&m_pauseLock);
131 if (m_requestPause)
132 {
133 if (!IsPaused(true))
134 {
136
137 m_paused = true;
138 m_pauseWait.wakeAll();
139 if (m_tvrec)
141 }
142
143 m_unpauseWait.wait(&m_pauseLock, timeout.count());
144 }
145
146 if (!m_requestPause && IsPaused(true))
147 {
148 m_paused = false;
150 m_unpauseWait.wakeAll();
151 }
152
153 return IsPaused(true);
154}
155
157{
158 return m_channel->GetSIStandard();
159}
160
161/* vim: set expandtab tabstop=4 shiftwidth=4: */
#define LOC
-*- Mode: c++ -*- CetonRecorder Copyright (c) 2011 Ronald Frazier Copyright (c) 2006-2009 by Silicond...
QString GetDevice(void) const override
Returns String representing device, useful for debugging.
Definition: cetonchannel.h:38
void StartNewFile(void) override
CetonStreamHandler * m_streamHandler
Definition: cetonrecorder.h:42
void Close(void)
CetonChannel * m_channel
Definition: cetonrecorder.h:41
bool Open(void)
bool IsOpen(void) const
Definition: cetonrecorder.h:32
void run(void) override
run() starts the recording process, and does not exit until the recording is complete.
QString GetSIStandard(void) const override
bool PauseAndWait(std::chrono::milliseconds timeout=100ms) override
If m_requestPause is true, sets pause and blocks up to timeout milliseconds or until unpaused,...
static void Return(CetonStreamHandler *&ref, int inputid)
static CetonStreamHandler * Get(const QString &devname, int inputid)
QString GetSIStandard(void) const
Returns PSIP table standard: MPEG, DVB, ATSC, or OpenCable.
Definition: dtvchannel.cpp:45
QString m_error
non-empty iff irrecoverable recording error detected
Definition: dtvrecorder.h:161
void FinishRecording(void) override
Flushes the ringbuffer, and if this is not a live LiveTV recording saves the position map and filesiz...
ProgramMapTable * m_inputPmt
PMT on input side.
Definition: dtvrecorder.h:174
bool IsErrored(void) override
Tells us whether an unrecoverable error has been encountered.
Definition: dtvrecorder.h:46
void ResetForNewFile(void) override
void HandleSingleProgramPAT(ProgramAssociationTable *pat, bool insert) override
MPEGStreamData * m_streamData
Definition: dtvrecorder.h:163
void HandleSingleProgramPMT(ProgramMapTable *pmt, bool insert) override
void AddListener(MPEGStreamData *data, bool=false, bool=false, const QString &output_file=QString()) override
const ProgramMapTable * PMTSingleProgram(void) const
void AddWritingListener(TSPacketListener *val)
void RemoveWritingListener(TSPacketListener *val)
const ProgramAssociationTable * PATSingleProgram(void) const
void RemoveAVListener(TSPacketListenerAV *val)
void AddAVListener(TSPacketListenerAV *val)
QMutex m_pauseLock
Definition: recorderbase.h:314
bool m_requestPause
Definition: recorderbase.h:315
TVRec * m_tvrec
Definition: recorderbase.h:291
virtual bool IsRecordingRequested(void)
Tells us if StopRecording() has been called.
bool m_recording
True while recording is actually being performed.
Definition: recorderbase.h:322
QWaitCondition m_pauseWait
Definition: recorderbase.h:317
virtual bool IsPaused(bool holding_lock=false) const
Returns true iff recorder is paused.
bool m_requestRecording
True if API call has requested a recording be [re]started.
Definition: recorderbase.h:320
QWaitCondition m_unpauseWait
Definition: recorderbase.h:318
QWaitCondition m_recordingWait
Definition: recorderbase.h:323
bool IsRunning(void) const
virtual void RemoveListener(MPEGStreamData *data)
void RecorderPaused(void)
This is a callback, called by the "recorder" instance when it has actually paused.
Definition: tv_rec.cpp:2995
uint GetInputId(void) const
Returns the inputid.
Definition: tv_rec.h:233
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39