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
13 #include "mpegstreamdata.h"
14 #include "iptvrecorder.h"
15 #include "iptvchannel.h"
16 #include "tv_rec.h"
17 
18 #define LOC QString("IPTVRec: ")
19 
21  DTVRecorder(rec), m_channel(channel)
22 {
23 }
24 
26 {
27  StopRecording();
28  Close();
29 }
30 
32 {
33  if (IsOpen())
34  {
35  LOG(VB_GENERAL, LOG_INFO, LOC + "Stream already open");
36  return true;
37  }
38 
40 
41  if (!m_channel->Open())
42  LOG(VB_GENERAL, LOG_ERR, LOC + "Open: Open channel failed");
43 
44  LOG(VB_RECORD, LOG_INFO, LOC + "opened successfully");
45 
46  if (m_stream_data)
48 
49  return m_stream_data;
50 }
51 
52 bool IPTVRecorder::IsOpen(void) const
53 {
54  if (!m_channel)
55  return false;
56  return m_channel->IsOpen();
57 }
58 
60 {
61  LOG(VB_RECORD, LOG_INFO, LOC + "Close()");
62 
63  m_channel->Close();
64 }
65 
67 {
69  if (IsOpen() && !IsPaused())
71 }
72 
74 {
75  QMutexLocker locker(&m_pauseLock);
76  if (m_request_pause)
77  {
78  if (!IsPaused(true))
79  {
80  m_channel->SetStreamData(nullptr);
81  m_paused = true;
82  m_pauseWait.wakeAll();
83  if (m_tvrec)
85  }
86 
88  }
89 
90  if (!m_request_pause && IsPaused(true))
91  {
93  m_paused = false;
94  m_unpauseWait.wakeAll();
95  }
96 
97  return IsPaused(true);
98 }
99 
101 {
102  // Make sure the first things in the file are a PAT & PMT
105 }
106 
108 {
109  LOG(VB_RECORD, LOG_INFO, LOC + "run -- begin");
110 
111  if (!Open())
112  {
113  m_error = "Failed to open IPTVRecorder device";
114  LOG(VB_GENERAL, LOG_ERR, LOC + m_error);
115  return;
116  }
117 
118  {
119  QMutexLocker locker(&m_pauseLock);
120  m_request_recording = true;
121  m_recording = true;
122  m_recordingWait.wakeAll();
123  }
124 
125  StartNewFile();
126 
129 
130  while (IsRecordingRequested() && !IsErrored())
131  {
132  if (PauseAndWait())
133  continue;
134 
135  if (!IsRecordingRequested())
136  break;
137 
138  { // sleep 100 milliseconds unless StopRecording() or Unpause()
139  // is called, just to avoid running this too often.
140  QMutexLocker locker(&m_pauseLock);
142  continue;
143  m_unpauseWait.wait(&m_pauseLock, 100);
144  }
145 
146  if (!m_input_pmt)
147  {
148  LOG(VB_GENERAL, LOG_WARNING, LOC +
149  "Recording will not commence until a PMT is set.");
150  std::this_thread::sleep_for(std::chrono::milliseconds(5));
151  continue;
152  }
153  }
154 
155  LOG(VB_RECORD, LOG_INFO, LOC + "run -- ending...");
156 
159 
160  Close();
161 
162  FinishRecording();
163 
164  QMutexLocker locker(&m_pauseLock);
165  m_recording = false;
166  m_recordingWait.wakeAll();
167 
168  LOG(VB_RECORD, LOG_INFO, LOC + "run -- end");
169 }
170 
171 /* vim: set expandtab tabstop=4 shiftwidth=4: */
const ProgramAssociationTable * PATSingleProgram(void) const
void run(void) override
run() starts the recording process, and does not exit until the recording is complete.
This is a specialization of RecorderBase used to handle MPEG-2, MPEG-4, MPEG-4 AVC,...
Definition: dtvrecorder.h:28
QMutex m_pauseLock
Definition: recorderbase.h:326
void ResetForNewFile(void) override
bool Open(void)
void HandleSingleProgramPAT(ProgramAssociationTable *pat, bool insert) override
bool IsErrored(void) override
Tells us whether an unrecoverable error has been encountered.
Definition: dtvrecorder.h:48
bool IsOpen(void) const
void SetStreamData(MPEGStreamData *) override
bool m_request_recording
True if API call has requested a recording be [re]started.
Definition: recorderbase.h:332
IPTVChannel * m_channel
Definition: iptvrecorder.h:35
bool PauseAndWait(int timeout=100) override
If m_request_pause is true, sets pause and blocks up to timeout milliseconds or until unpaused,...
virtual void SetStreamData(MPEGStreamData *data)
virtual bool IsPaused(bool holding_lock=false) const
Returns true iff recorder is paused.
QWaitCondition m_unpauseWait
Definition: recorderbase.h:330
ProgramMapTable * m_input_pmt
PMT on input side.
Definition: dtvrecorder.h:175
void FinishRecording(void) override
Flushes the ringbuffer, and if this is not a live LiveTV recording saves the position map and filesiz...
QWaitCondition m_pauseWait
Definition: recorderbase.h:329
This is the coordinating class of the Recorder Subsystem.
Definition: tv_rec.h:150
bool IsOpen(void) const override
Reports whether channel is already open.
MPEGStreamData * m_stream_data
Definition: dtvrecorder.h:164
void RemoveWritingListener(TSPacketListener *)
void RecorderPaused(void)
This is a callback, called by the "recorder" instance when it has actually paused.
Definition: tv_rec.cpp:2929
void AddAVListener(TSPacketListenerAV *)
QWaitCondition m_recordingWait
Definition: recorderbase.h:335
bool m_recording
True while recording is actually being performed.
Definition: recorderbase.h:334
void Close(void)
IPTVRecorder(TVRec *, IPTVChannel *)
bool m_request_pause
Definition: recorderbase.h:327
void SetStreamData(MPEGStreamData *)
Definition: iptvchannel.cpp:57
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
TVRec * m_tvrec
Definition: recorderbase.h:303
const ProgramMapTable * PMTSingleProgram(void) const
#define LOC
-*- Mode: c++ -*- IPTVRecorder Copyright (c) 2006-2009 Silicondust Engineering Ltd,...
bool Open(void) override
Opens the channel changing hardware for use.
Definition: iptvchannel.cpp:36
void Close(void) override
Closes the channel changing hardware to use.
Definition: iptvchannel.cpp:85
void AddWritingListener(TSPacketListener *)
virtual void StopRecording(void)
StopRecording() signals to the recorder that it should stop recording and exit cleanly.
QString m_error
non-empty iff irrecoverable recording error detected
Definition: dtvrecorder.h:162
void RemoveAVListener(TSPacketListenerAV *)
Encapsulates data about MPEG stream and emits events for each table.
void HandleSingleProgramPMT(ProgramMapTable *pmt, bool insert) override
void StartNewFile(void) override
virtual bool IsRecordingRequested(void)
Tells us if StopRecording() has been called.