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{
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
54bool 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
66}
67
69{
71 if (IsOpen() && !IsPaused())
73}
74
75bool IPTVRecorder::PauseAndWait(std::chrono::milliseconds timeout)
76{
77 QMutexLocker locker(&m_pauseLock);
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
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
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: */
This is a specialization of RecorderBase used to handle MPEG-2, MPEG-4, MPEG-4 AVC,...
Definition: dtvrecorder.h:35
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
virtual void SetStreamData(MPEGStreamData *data)
void HandleSingleProgramPMT(ProgramMapTable *pmt, bool insert) override
void Close(void) override
Closes the channel changing hardware to use.
Definition: iptvchannel.cpp:89
void SetStreamData(MPEGStreamData *sd)
Definition: iptvchannel.cpp:61
bool Open(void) override
Opens the channel changing hardware for use.
Definition: iptvchannel.cpp:40
bool IsOpen(void) const override
Reports whether channel is already open.
IPTVChannel * m_channel
Definition: iptvrecorder.h:35
void SetStreamData(MPEGStreamData *data) override
IPTVRecorder(TVRec *rec, IPTVChannel *channel)
~IPTVRecorder() override
bool IsOpen(void) const
bool Open(void)
void Close(void)
void StartNewFile(void) override
void run(void) override
run() starts the recording process, and does not exit until the recording is complete.
bool PauseAndWait(std::chrono::milliseconds timeout=100ms) override
If m_requestPause is true, sets pause and blocks up to timeout milliseconds or until unpaused,...
Encapsulates data about MPEG stream and emits events for each table.
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.
virtual void StopRecording(void)
StopRecording() signals to the recorder that it should stop recording and exit cleanly.
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
This is the coordinating class of the Recorder Subsystem.
Definition: tv_rec.h:143
void RecorderPaused(void)
This is a callback, called by the "recorder" instance when it has actually paused.
Definition: tv_rec.cpp:2995
#define LOC
-*- Mode: c++ -*- IPTVRecorder Copyright (c) 2006-2009 Silicondust Engineering Ltd,...
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39