MythTV  master
satiprecorder.cpp
Go to the documentation of this file.
1 // C++ includes
2 #include <chrono>
3 #include <thread>
4 
5 // MythTV includes
6 #include "tsstreamdata.h"
7 #include "satipstreamhandler.h"
8 #include "satiprecorder.h"
9 #include "satipchannel.h"
10 #include "io/mythmediabuffer.h"
11 #include "tv_rec.h"
12 #include "mythlogging.h"
13 
14 #define LOC QString("SatIPRec[%1]: ").arg(m_inputId)
15 
17  : DTVRecorder(rec)
18  , m_channel(channel)
19  , m_inputId(rec->GetInputId())
20 {
21 }
22 
24 {
25  if (IsOpen())
26  {
27  LOG(VB_GENERAL, LOG_WARNING, LOC + "Card already open");
28  return true;
29  }
30 
32 
33  if (m_channel->GetFormat().compare("MPTS") == 0)
34  {
35  // MPTS only. Use TSStreamData to write out unfiltered data.
36  LOG(VB_RECORD, LOG_INFO, LOC + "Using TSStreamData");
38  m_recordMptsOnly = true;
39  m_recordMpts = false;
40  }
41 
43 
44  LOG(VB_RECORD, LOG_INFO, LOC + "SatIP opened successfully");
45 
46  return true;
47 }
48 
50 {
51  if (IsOpen())
52  {
54  }
55 }
56 
58 {
59  if (!m_recordMptsOnly)
60  {
61  if (m_recordMpts)
62  {
64  }
65 
66  // Make sure the first things in the file are a PAT & PMT
69  }
70 }
71 
73 {
74  LOG(VB_RECORD, LOG_INFO, LOC + "run -- begin");
75 
76  /* Create video socket. */
77  if (!Open())
78  {
79  m_error = "Failed to open SatIPRecorder device";
80  LOG(VB_GENERAL, LOG_ERR, LOC + m_error);
81  return;
82  }
83 
84  {
85  QMutexLocker locker(&m_pauseLock);
86  m_requestRecording = true;
87  m_recording = true;
88  m_recordingWait.wakeAll();
89  }
90 
91  // Listen for time table on DVB standard streams
92  if (m_channel && (m_channel->GetSIStandard() == "dvb"))
94  if (m_recordMptsOnly)
96 
97  StartNewFile();
98 
102  (m_recordMpts) ? m_ringBuffer->GetFilename() : QString());
103 
104  while (IsRecordingRequested() && !IsErrored())
105  {
106  if (PauseAndWait())
107  continue;
108 
109  if (!IsRecordingRequested())
110  break;
111 
112  // sleep 100 milliseconds unless StopRecording() or Unpause()
113  // is called, just to avoid running this too often.
114  {
115  QMutexLocker locker(&m_pauseLock);
117  continue;
118  m_unpauseWait.wait(&m_pauseLock, 100);
119  }
120 
121  if (!m_inputPmt && !m_recordMptsOnly)
122  {
123  LOG(VB_GENERAL, LOG_WARNING, LOC +
124  "Recording will not commence until a PMT is set.");
125  std::this_thread::sleep_for(5ms);
126  continue;
127  }
128 
129  if (!m_streamHandler->IsRunning())
130  {
131  m_error = "Stream handler died unexpectedly.";
132  LOG(VB_GENERAL, LOG_ERR, LOC + m_error);
133  }
134  }
135 
136  LOG(VB_RECORD, LOG_INFO, LOC + "run -- ending...");
137 
141 
142  Close();
143 
144  FinishRecording();
145 
146  QMutexLocker locker(&m_pauseLock);
147  m_recording = false;
148  m_recordingWait.wakeAll();
149 
150  LOG(VB_RECORD, LOG_INFO, LOC + "run -- end");
151 }
152 
153 bool SatIPRecorder::PauseAndWait(std::chrono::milliseconds timeout)
154 {
155  QMutexLocker locker(&m_pauseLock);
156  if (m_requestPause)
157  {
158  if (!IsPaused(true))
159  {
161 
162  m_paused = true;
163  m_pauseWait.wakeAll();
164  if (m_tvrec)
166  }
167 
168  m_unpauseWait.wait(&m_pauseLock, timeout.count());
169  }
170 
171  if (!m_requestPause && IsPaused(true))
172  {
173  m_paused = false;
175  m_unpauseWait.wakeAll();
176  }
177 
178  return IsPaused(true);
179 }
180 
181 QString SatIPRecorder::GetSIStandard(void) const
182 {
183  return m_channel->GetSIStandard();
184 }
DTVRecorder::HandleSingleProgramPMT
void HandleSingleProgramPMT(ProgramMapTable *pmt, bool insert) override
Definition: dtvrecorder.cpp:1346
hardwareprofile.smolt.timeout
float timeout
Definition: smolt.py:103
DTVRecorder::m_inputPmt
ProgramMapTable * m_inputPmt
PMT on input side.
Definition: dtvrecorder.h:177
DTVRecorder::ResetForNewFile
void ResetForNewFile(void) override
Definition: dtvrecorder.cpp:138
LOC
#define LOC
Definition: satiprecorder.cpp:14
DTVRecorder::SetStreamData
virtual void SetStreamData(MPEGStreamData *data)
Definition: dtvrecorder.cpp:216
RecorderBase::m_tvrec
TVRec * m_tvrec
Definition: recorderbase.h:314
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:153
DTVChannel::GetFormat
QString GetFormat(void)
Definition: dtvchannel.h:46
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
StreamHandler::AddNamedOutputFile
virtual bool AddNamedOutputFile(const QString &filename)
Called with _listener_lock locked just after adding new output file.
Definition: streamhandler.cpp:356
PID::DVB_TDT_PID
@ DVB_TDT_PID
Definition: mpegtables.h:219
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:124
SatIPRecorder::m_channel
SatIPChannel * m_channel
Definition: satiprecorder.h:31
satipchannel.h
MPEGStreamData::PMTSingleProgram
const ProgramMapTable * PMTSingleProgram(void) const
Definition: mpegstreamdata.h:265
StreamHandler::RemoveListener
virtual void RemoveListener(MPEGStreamData *data)
Definition: streamhandler.cpp:78
RecorderBase::m_pauseLock
QMutex m_pauseLock
Definition: recorderbase.h:337
RecorderBase::m_requestPause
bool m_requestPause
Definition: recorderbase.h:338
RecorderBase::m_recordingWait
QWaitCondition m_recordingWait
Definition: recorderbase.h:346
SatIPRecorder::Close
void Close(void)
Definition: satiprecorder.cpp:49
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:2951
MythMediaBuffer::GetFilename
QString GetFilename(void) const
Definition: mythmediabuffer.cpp:1739
RecorderBase::m_paused
bool m_paused
Definition: recorderbase.h:339
MPEGStreamData::PATSingleProgram
const ProgramAssociationTable * PATSingleProgram(void) const
Definition: mpegstreamdata.h:263
DTVRecorder::HandleSingleProgramPAT
void HandleSingleProgramPAT(ProgramAssociationTable *pat, bool insert) override
Definition: dtvrecorder.cpp:1326
SatIPRecorder::Open
bool Open(void)
Definition: satiprecorder.cpp:23
mythlogging.h
DTVRecorder::m_recordMptsOnly
bool m_recordMptsOnly
Definition: dtvrecorder.h:182
SatIPStreamHandler::Return
static void Return(SatIPStreamHandler *&ref, int inputid)
Definition: satipstreamhandler.cpp:61
SatIPRecorder::GetSIStandard
QString GetSIStandard(void) const override
Definition: satiprecorder.cpp:181
SatIPRecorder::m_inputId
int m_inputId
Definition: satiprecorder.h:33
MPEGStreamData::RemoveWritingListener
void RemoveWritingListener(TSPacketListener *val)
Definition: mpegstreamdata.cpp:1648
RecorderBase::IsRecordingRequested
virtual bool IsRecordingRequested(void)
Tells us if StopRecording() has been called.
Definition: recorderbase.cpp:249
SatIPRecorder::SatIPRecorder
SatIPRecorder(TVRec *rec, SatIPChannel *channel)
Definition: satiprecorder.cpp:16
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:57
mythmediabuffer.h
DTVChannel::GetSIStandard
QString GetSIStandard(void) const
Returns PSIP table standard: MPEG, DVB, ATSC, or OpenCable.
Definition: dtvchannel.cpp:44
SatIPStreamHandler::AddListener
void AddListener(MPEGStreamData *data, bool=false, bool=false, const QString &output_file=QString()) override
Definition: satipstreamhandler.h:38
RecorderBase::m_pauseWait
QWaitCondition m_pauseWait
Definition: recorderbase.h:340
RecorderBase::m_ringBuffer
MythMediaBuffer * m_ringBuffer
Definition: recorderbase.h:315
MPEGStreamData::AddAVListener
void AddAVListener(TSPacketListenerAV *val)
Definition: mpegstreamdata.cpp:1662
DTVRecorder::m_streamData
MPEGStreamData * m_streamData
Definition: dtvrecorder.h:162
MPEGStreamData::AddWritingListener
void AddWritingListener(TSPacketListener *val)
Definition: mpegstreamdata.cpp:1637
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:181
TVRec
This is the coordinating class of the Recorder Subsystem.
Definition: tv_rec.h:145
SatIPRecorder::run
void run(void) override
run() starts the recording process, and does not exit until the recording is complete.
Definition: satiprecorder.cpp:72
RecorderBase::m_recording
bool m_recording
True while recording is actually being performed.
Definition: recorderbase.h:345
tv_rec.h
satipstreamhandler.h
SatIPChannel::GetDevice
QString GetDevice(void) const override
Returns String representing device, useful for debugging.
Definition: satipchannel.h:28
SatIPStreamHandler::Get
static SatIPStreamHandler * Get(const QString &devname, int inputid)
Definition: satipstreamhandler.cpp:30
MPEGStreamData::AddListeningPID
virtual void AddListeningPID(uint pid, PIDPriority priority=kPIDPriorityNormal)
Definition: mpegstreamdata.h:119
StreamHandler::IsRunning
bool IsRunning(void) const
Definition: streamhandler.cpp:161
RecorderBase::m_unpauseWait
QWaitCondition m_unpauseWait
Definition: recorderbase.h:341
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:1673
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:343
SatIPRecorder::m_streamHandler
SatIPStreamHandler * m_streamHandler
Definition: satiprecorder.h:32