MythTV  master
satiprecorder.cpp
Go to the documentation of this file.
1 // C++ includes
2 #include <chrono>
3 #include <thread>
4 
5 // MythTV includes
7 
8 #include "io/mythmediabuffer.h"
9 #include "mpeg/tsstreamdata.h"
10 #include "satipchannel.h"
11 #include "satiprecorder.h"
12 #include "satipstreamhandler.h"
13 #include "tv_rec.h"
14 
15 #define LOC QString("SatIPRec[%1]: ").arg(m_inputId)
16 
18  : DTVRecorder(rec)
19  , m_channel(channel)
20  , m_inputId(rec->GetInputId())
21 {
22  LOG(VB_RECORD, LOG_INFO, LOC + QString("ctor %1").arg(m_channel->GetDevice()));
23 }
24 
26 {
27  if (IsOpen())
28  {
29  LOG(VB_GENERAL, LOG_WARNING, LOC + "Card already open");
30  return true;
31  }
32 
34 
35  if (m_channel->GetFormat().compare("MPTS") == 0)
36  {
37  // MPTS only. Use TSStreamData to write out unfiltered data.
38  LOG(VB_RECORD, LOG_INFO, LOC + "Using TSStreamData");
40  m_recordMptsOnly = true;
41  m_recordMpts = false;
42  }
43 
45 
46  LOG(VB_RECORD, LOG_INFO, LOC + "SatIP opened successfully");
47 
48  return true;
49 }
50 
52 {
53  if (IsOpen())
54  {
56  }
57 }
58 
60 {
61  if (!m_recordMptsOnly)
62  {
63  if (m_recordMpts)
64  {
66  }
67 
68  // Make sure the first things in the file are a PAT & PMT
71  }
72 }
73 
75 {
76  LOG(VB_RECORD, LOG_INFO, LOC + "run -- begin");
77 
78  if (!Open())
79  {
80  m_error = "Failed to open SatIPRecorder device";
81  LOG(VB_GENERAL, LOG_ERR, LOC + m_error);
82  return;
83  }
84 
85  {
86  QMutexLocker locker(&m_pauseLock);
87  m_requestRecording = true;
88  m_recording = true;
89  m_recordingWait.wakeAll();
90  }
91 
92  // Listen for time table on DVB standard streams
93  if (m_channel && (m_channel->GetSIStandard() == "dvb"))
95  if (m_recordMptsOnly)
97 
98  StartNewFile();
99 
103  (m_recordMpts) ? m_ringBuffer->GetFilename() : QString());
104 
105  while (IsRecordingRequested() && !IsErrored())
106  {
107  if (PauseAndWait())
108  continue;
109 
110  if (!IsRecordingRequested())
111  break;
112 
113  // sleep 100 milliseconds unless StopRecording() or Unpause()
114  // is called, just to avoid running this too often.
115  {
116  QMutexLocker locker(&m_pauseLock);
118  continue;
119  m_unpauseWait.wait(&m_pauseLock, 100);
120  }
121 
122  if (!m_inputPmt && !m_recordMptsOnly)
123  {
124  LOG(VB_GENERAL, LOG_WARNING, LOC +
125  "Recording will not commence until a PMT is set.");
126  std::this_thread::sleep_for(5ms);
127  continue;
128  }
129 
130  if (!m_streamHandler->IsRunning())
131  {
132  m_error = "Stream handler died unexpectedly.";
133  LOG(VB_GENERAL, LOG_ERR, LOC + m_error);
134  }
135  }
136 
137  LOG(VB_RECORD, LOG_INFO, LOC + "run -- ending...");
138 
142 
143  Close();
144 
145  FinishRecording();
146 
147  QMutexLocker locker(&m_pauseLock);
148  m_recording = false;
149  m_recordingWait.wakeAll();
150 
151  LOG(VB_RECORD, LOG_INFO, LOC + "run -- end");
152  LOG(VB_GENERAL, LOG_INFO, LOC + QString("< %1").arg(__func__));
153 }
154 
155 bool SatIPRecorder::PauseAndWait(std::chrono::milliseconds timeout)
156 {
157  QMutexLocker locker(&m_pauseLock);
158  if (m_requestPause)
159  {
160  if (!IsPaused(true))
161  {
163 
164  m_paused = true;
165  m_pauseWait.wakeAll();
166  if (m_tvrec)
168  }
169 
170  m_unpauseWait.wait(&m_pauseLock, timeout.count());
171  }
172 
173  if (!m_requestPause && IsPaused(true))
174  {
175  m_paused = false;
177  m_unpauseWait.wakeAll();
178  }
179 
180  return IsPaused(true);
181 }
182 
183 QString SatIPRecorder::GetSIStandard(void) const
184 {
185  return m_channel->GetSIStandard();
186 }
DTVRecorder::HandleSingleProgramPMT
void HandleSingleProgramPMT(ProgramMapTable *pmt, bool insert) override
Definition: dtvrecorder.cpp:1405
hardwareprofile.smolt.timeout
float timeout
Definition: smolt.py:102
DTVRecorder::m_inputPmt
ProgramMapTable * m_inputPmt
PMT on input side.
Definition: dtvrecorder.h:173
DTVRecorder::ResetForNewFile
void ResetForNewFile(void) override
Definition: dtvrecorder.cpp:140
LOC
#define LOC
Definition: satiprecorder.cpp:15
DTVRecorder::SetStreamData
virtual void SetStreamData(MPEGStreamData *data)
Definition: dtvrecorder.cpp:218
RecorderBase::m_tvrec
TVRec * m_tvrec
Definition: recorderbase.h:315
DTVRecorder::IsErrored
bool IsErrored(void) override
Tells us whether an unrecoverable error has been encountered.
Definition: dtvrecorder.h:45
SatIPRecorder::PauseAndWait
bool PauseAndWait(std::chrono::milliseconds timeout=100ms) override
If m_requestPause is true, sets pause and blocks up to timeout milliseconds or until unpaused,...
Definition: satiprecorder.cpp:155
DTVChannel::GetFormat
QString GetFormat(void)
Definition: dtvchannel.h:46
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
StreamHandler::AddNamedOutputFile
virtual bool AddNamedOutputFile(const QString &filename)
Called with _listener_lock locked just after adding new output file.
Definition: streamhandler.cpp:362
DTVRecorder::FinishRecording
void FinishRecording(void) override
Flushes the ringbuffer, and if this is not a live LiveTV recording saves the position map and filesiz...
Definition: dtvrecorder.cpp:126
SatIPRecorder::m_channel
SatIPChannel * m_channel
Definition: satiprecorder.h:31
satipchannel.h
MPEGStreamData::PMTSingleProgram
const ProgramMapTable * PMTSingleProgram(void) const
Definition: mpegstreamdata.h:266
StreamHandler::RemoveListener
virtual void RemoveListener(MPEGStreamData *data)
Definition: streamhandler.cpp:80
RecorderBase::m_pauseLock
QMutex m_pauseLock
Definition: recorderbase.h:338
RecorderBase::m_requestPause
bool m_requestPause
Definition: recorderbase.h:339
RecorderBase::m_recordingWait
QWaitCondition m_recordingWait
Definition: recorderbase.h:347
SatIPRecorder::Close
void Close(void)
Definition: satiprecorder.cpp:51
SatIPChannel
Definition: satipchannel.h:12
TVRec::RecorderPaused
void RecorderPaused(void)
This is a callback, called by the "recorder" instance when it has actually paused.
Definition: tv_rec.cpp:2984
PID::DVB_TDT_PID
@ DVB_TDT_PID
Definition: mpegtables.h:219
MythMediaBuffer::GetFilename
QString GetFilename(void) const
Definition: mythmediabuffer.cpp:1740
RecorderBase::m_paused
bool m_paused
Definition: recorderbase.h:340
MPEGStreamData::PATSingleProgram
const ProgramAssociationTable * PATSingleProgram(void) const
Definition: mpegstreamdata.h:264
DTVRecorder::HandleSingleProgramPAT
void HandleSingleProgramPAT(ProgramAssociationTable *pat, bool insert) override
Definition: dtvrecorder.cpp:1385
SatIPRecorder::Open
bool Open(void)
Definition: satiprecorder.cpp:25
mythlogging.h
DTVRecorder::m_recordMptsOnly
bool m_recordMptsOnly
Definition: dtvrecorder.h:178
SatIPStreamHandler::Return
static void Return(SatIPStreamHandler *&ref, int inputid)
Definition: satipstreamhandler.cpp:63
SatIPRecorder::GetSIStandard
QString GetSIStandard(void) const override
Definition: satiprecorder.cpp:183
SatIPRecorder::m_inputId
int m_inputId
Definition: satiprecorder.h:33
MPEGStreamData::RemoveWritingListener
void RemoveWritingListener(TSPacketListener *val)
Definition: mpegstreamdata.cpp:1660
RecorderBase::IsRecordingRequested
virtual bool IsRecordingRequested(void)
Tells us if StopRecording() has been called.
Definition: recorderbase.cpp:250
SatIPRecorder::SatIPRecorder
SatIPRecorder(TVRec *rec, SatIPChannel *channel)
Definition: satiprecorder.cpp:17
DTVRecorder
This is a specialization of RecorderBase used to handle MPEG-2, MPEG-4, MPEG-4 AVC,...
Definition: dtvrecorder.h:25
satiprecorder.h
SatIPRecorder::StartNewFile
void StartNewFile(void) override
Definition: satiprecorder.cpp:59
mythmediabuffer.h
DTVChannel::GetSIStandard
QString GetSIStandard(void) const
Returns PSIP table standard: MPEG, DVB, ATSC, or OpenCable.
Definition: dtvchannel.cpp:45
SatIPStreamHandler::AddListener
void AddListener(MPEGStreamData *data, bool=false, bool=false, const QString &output_file=QString()) override
Definition: satipstreamhandler.h:30
RecorderBase::m_pauseWait
QWaitCondition m_pauseWait
Definition: recorderbase.h:341
RecorderBase::m_ringBuffer
MythMediaBuffer * m_ringBuffer
Definition: recorderbase.h:316
MPEGStreamData::AddAVListener
void AddAVListener(TSPacketListenerAV *val)
Definition: mpegstreamdata.cpp:1674
DTVRecorder::m_streamData
MPEGStreamData * m_streamData
Definition: dtvrecorder.h:162
MPEGStreamData::AddWritingListener
void AddWritingListener(TSPacketListener *val)
Definition: mpegstreamdata.cpp:1649
SatIPRecorder::IsOpen
bool IsOpen(void) const
Definition: satiprecorder.h:21
DTVRecorder::m_error
QString m_error
non-empty iff irrecoverable recording error detected
Definition: dtvrecorder.h:160
DTVRecorder::m_recordMpts
bool m_recordMpts
Definition: dtvrecorder.h:177
TVRec
This is the coordinating class of the Recorder Subsystem.
Definition: tv_rec.h:142
SatIPRecorder::run
void run(void) override
run() starts the recording process, and does not exit until the recording is complete.
Definition: satiprecorder.cpp:74
RecorderBase::m_recording
bool m_recording
True while recording is actually being performed.
Definition: recorderbase.h:346
tv_rec.h
satipstreamhandler.h
SatIPChannel::GetDevice
QString GetDevice(void) const override
Returns String representing device, useful for debugging.
Definition: satipchannel.h:29
SatIPStreamHandler::Get
static SatIPStreamHandler * Get(const QString &devname, int inputid)
Definition: satipstreamhandler.cpp:32
MPEGStreamData::AddListeningPID
virtual void AddListeningPID(uint pid, PIDPriority priority=kPIDPriorityNormal)
Definition: mpegstreamdata.h:120
StreamHandler::IsRunning
bool IsRunning(void) const
Definition: streamhandler.cpp:163
RecorderBase::m_unpauseWait
QWaitCondition m_unpauseWait
Definition: recorderbase.h:342
TSStreamData
Specialized version of MPEGStreamData which is used to 'blindly' record the entire MPTS transport fro...
Definition: tsstreamdata.h:11
MPEGStreamData::RemoveAVListener
void RemoveAVListener(TSPacketListenerAV *val)
Definition: mpegstreamdata.cpp:1695
RecorderBase::IsPaused
virtual bool IsPaused(bool holding_lock=false) const
Returns true iff recorder is paused.
Definition: recorderbase.cpp:281
tsstreamdata.h
RecorderBase::m_requestRecording
bool m_requestRecording
True if API call has requested a recording be [re]started.
Definition: recorderbase.h:344
SatIPRecorder::m_streamHandler
SatIPStreamHandler * m_streamHandler
Definition: satiprecorder.h:32