MythTV  master
iptvrecorder.cpp
Go to the documentation of this file.
1 
9 #include <chrono> // for milliseconds
10 #include <thread> // for sleep_for
11 
12 // MythTV headers
14 
15 #include "iptvchannel.h"
16 #include "iptvrecorder.h"
17 #include "mpeg/mpegstreamdata.h"
18 #include "tv_rec.h"
19 
20 #define LOC QString("IPTVRec: ")
21 
23  DTVRecorder(rec), m_channel(channel)
24 {
25 }
26 
28 {
29  StopRecording();
30  Close();
31 }
32 
34 {
35  if (IsOpen())
36  {
37  LOG(VB_GENERAL, LOG_INFO, LOC + "Stream already open");
38  return true;
39  }
40 
42 
43  if (!m_channel->Open())
44  LOG(VB_GENERAL, LOG_ERR, LOC + "Open: Open channel failed");
45 
46  LOG(VB_RECORD, LOG_INFO, LOC + "opened successfully");
47 
48  if (m_streamData)
50 
51  return m_streamData;
52 }
53 
54 bool IPTVRecorder::IsOpen(void) const
55 {
56  if (!m_channel)
57  return false;
58  return m_channel->IsOpen();
59 }
60 
62 {
63  LOG(VB_RECORD, LOG_INFO, LOC + "Close()");
64 
65  m_channel->Close();
66 }
67 
69 {
71  if (IsOpen() && !IsPaused())
73 }
74 
75 bool IPTVRecorder::PauseAndWait(std::chrono::milliseconds timeout)
76 {
77  QMutexLocker locker(&m_pauseLock);
78  if (m_requestPause)
79  {
80  if (!IsPaused(true))
81  {
82  m_channel->SetStreamData(nullptr);
83  m_paused = true;
84  m_pauseWait.wakeAll();
85  if (m_tvrec)
87  }
88 
89  m_unpauseWait.wait(&m_pauseLock, timeout.count());
90  }
91 
92  if (!m_requestPause && IsPaused(true))
93  {
95  m_paused = false;
96  m_unpauseWait.wakeAll();
97  }
98 
99  return IsPaused(true);
100 }
101 
103 {
104  // Make sure the first things in the file are a PAT & PMT
107 }
108 
110 {
111  LOG(VB_RECORD, LOG_INFO, LOC + "run -- begin");
112 
113  if (!Open())
114  {
115  m_error = "Failed to open IPTVRecorder device";
116  LOG(VB_GENERAL, LOG_ERR, LOC + m_error);
117  return;
118  }
119 
120  {
121  QMutexLocker locker(&m_pauseLock);
122  m_requestRecording = true;
123  m_recording = true;
124  m_recordingWait.wakeAll();
125  }
126 
127  StartNewFile();
128 
131 
132  while (IsRecordingRequested() && !IsErrored())
133  {
134  if (PauseAndWait())
135  continue;
136 
137  if (!IsRecordingRequested())
138  break;
139 
140  { // sleep 100 milliseconds unless StopRecording() or Unpause()
141  // is called, just to avoid running this too often.
142  QMutexLocker locker(&m_pauseLock);
144  continue;
145  m_unpauseWait.wait(&m_pauseLock, 100);
146  }
147 
148  if (!m_inputPmt)
149  {
150  LOG(VB_GENERAL, LOG_WARNING, LOC +
151  "Recording will not commence until a PMT is set.");
152  std::this_thread::sleep_for(5ms);
153  continue;
154  }
155  }
156 
157  LOG(VB_RECORD, LOG_INFO, LOC + "run -- ending...");
158 
161 
162  Close();
163 
164  FinishRecording();
165 
166  QMutexLocker locker(&m_pauseLock);
167  m_recording = false;
168  m_recordingWait.wakeAll();
169 
170  LOG(VB_RECORD, LOG_INFO, LOC + "run -- end");
171 }
172 
173 /* vim: set expandtab tabstop=4 shiftwidth=4: */
DTVRecorder::HandleSingleProgramPMT
void HandleSingleProgramPMT(ProgramMapTable *pmt, bool insert) override
Definition: dtvrecorder.cpp:1410
hardwareprofile.smolt.timeout
float timeout
Definition: smolt.py:101
LOC
#define LOC
-*- Mode: c++ -*- IPTVRecorder Copyright (c) 2006-2009 Silicondust Engineering Ltd,...
Definition: iptvrecorder.cpp:20
DTVRecorder::m_inputPmt
ProgramMapTable * m_inputPmt
PMT on input side.
Definition: dtvrecorder.h:174
DTVRecorder::ResetForNewFile
void ResetForNewFile(void) override
Definition: dtvrecorder.cpp:141
DTVRecorder::SetStreamData
virtual void SetStreamData(MPEGStreamData *data)
Definition: dtvrecorder.cpp:219
RecorderBase::m_tvrec
TVRec * m_tvrec
Definition: recorderbase.h:290
DTVRecorder::IsErrored
bool IsErrored(void) override
Tells us whether an unrecoverable error has been encountered.
Definition: dtvrecorder.h:46
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
IPTVRecorder::~IPTVRecorder
~IPTVRecorder() override
Definition: iptvrecorder.cpp:27
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:127
MPEGStreamData::PMTSingleProgram
const ProgramMapTable * PMTSingleProgram(void) const
Definition: mpegstreamdata.h:266
RecorderBase::m_pauseLock
QMutex m_pauseLock
Definition: recorderbase.h:313
RecorderBase::m_requestPause
bool m_requestPause
Definition: recorderbase.h:314
RecorderBase::m_recordingWait
QWaitCondition m_recordingWait
Definition: recorderbase.h:322
TVRec::RecorderPaused
void RecorderPaused(void)
This is a callback, called by the "recorder" instance when it has actually paused.
Definition: tv_rec.cpp:3000
RecorderBase::m_paused
bool m_paused
Definition: recorderbase.h:315
MPEGStreamData::PATSingleProgram
const ProgramAssociationTable * PATSingleProgram(void) const
Definition: mpegstreamdata.h:264
DTVRecorder::HandleSingleProgramPAT
void HandleSingleProgramPAT(ProgramAssociationTable *pat, bool insert) override
Definition: dtvrecorder.cpp:1390
mythlogging.h
IPTVRecorder::Open
bool Open(void)
Definition: iptvrecorder.cpp:33
IPTVRecorder::Close
void Close(void)
Definition: iptvrecorder.cpp:61
IPTVRecorder::m_channel
IPTVChannel * m_channel
Definition: iptvrecorder.h:35
MPEGStreamData
Encapsulates data about MPEG stream and emits events for each table.
Definition: mpegstreamdata.h:85
IPTVRecorder::IsOpen
bool IsOpen(void) const
Definition: iptvrecorder.cpp:54
MPEGStreamData::RemoveWritingListener
void RemoveWritingListener(TSPacketListener *val)
Definition: mpegstreamdata.cpp:1666
RecorderBase::IsRecordingRequested
virtual bool IsRecordingRequested(void)
Tells us if StopRecording() has been called.
Definition: recorderbase.cpp:254
IPTVChannel
Definition: iptvchannel.h:24
IPTVRecorder::IPTVRecorder
IPTVRecorder(TVRec *rec, IPTVChannel *channel)
Definition: iptvrecorder.cpp:22
DTVRecorder
This is a specialization of RecorderBase used to handle MPEG-2, MPEG-4, MPEG-4 AVC,...
Definition: dtvrecorder.h:26
IPTVChannel::IsOpen
bool IsOpen(void) const override
Reports whether channel is already open.
Definition: iptvchannel.cpp:154
IPTVChannel::SetStreamData
void SetStreamData(MPEGStreamData *sd)
Definition: iptvchannel.cpp:61
mpegstreamdata.h
RecorderBase::StopRecording
virtual void StopRecording(void)
StopRecording() signals to the recorder that it should stop recording and exit cleanly.
Definition: recorderbase.cpp:228
iptvchannel.h
RecorderBase::m_pauseWait
QWaitCondition m_pauseWait
Definition: recorderbase.h:316
MPEGStreamData::AddAVListener
void AddAVListener(TSPacketListenerAV *val)
Definition: mpegstreamdata.cpp:1680
IPTVRecorder::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: iptvrecorder.cpp:75
IPTVChannel::Close
void Close(void) override
Closes the channel changing hardware to use.
Definition: iptvchannel.cpp:89
IPTVRecorder::SetStreamData
void SetStreamData(MPEGStreamData *data) override
Definition: iptvrecorder.cpp:68
DTVRecorder::m_streamData
MPEGStreamData * m_streamData
Definition: dtvrecorder.h:163
MPEGStreamData::AddWritingListener
void AddWritingListener(TSPacketListener *val)
Definition: mpegstreamdata.cpp:1655
DTVRecorder::m_error
QString m_error
non-empty iff irrecoverable recording error detected
Definition: dtvrecorder.h:161
TVRec
This is the coordinating class of the Recorder Subsystem.
Definition: tv_rec.h:142
RecorderBase::m_recording
bool m_recording
True while recording is actually being performed.
Definition: recorderbase.h:321
tv_rec.h
IPTVRecorder::run
void run(void) override
run() starts the recording process, and does not exit until the recording is complete.
Definition: iptvrecorder.cpp:109
IPTVRecorder::StartNewFile
void StartNewFile(void) override
Definition: iptvrecorder.cpp:102
iptvrecorder.h
IPTVChannel::Open
bool Open(void) override
Opens the channel changing hardware for use.
Definition: iptvchannel.cpp:40
RecorderBase::m_unpauseWait
QWaitCondition m_unpauseWait
Definition: recorderbase.h:317
MPEGStreamData::RemoveAVListener
void RemoveAVListener(TSPacketListenerAV *val)
Definition: mpegstreamdata.cpp:1701
RecorderBase::IsPaused
virtual bool IsPaused(bool holding_lock=false) const
Returns true iff recorder is paused.
Definition: recorderbase.cpp:285
RecorderBase::m_requestRecording
bool m_requestRecording
True if API call has requested a recording be [re]started.
Definition: recorderbase.h:319