MythTV master
cetonrecorder.cpp
Go to the documentation of this file.
1
8// MythTV includes
10#include "cetonstreamhandler.h"
11#include "cetonrecorder.h"
12#include "cetonchannel.h"
13#include "tv_rec.h"
14
15#define LOC QString("CetonRec[%1]: ") \
16 .arg(m_tvrec ? m_tvrec->GetInputId() : -1)
17
19{
20 if (IsOpen())
21 {
22 LOG(VB_GENERAL, LOG_WARNING, LOC + "Card already open");
23 return true;
24 }
25
27
29 m_tvrec ? m_tvrec->GetInputId() : -1);
30
31 LOG(VB_RECORD, LOG_INFO, LOC + "Ceton opened successfully");
32
33 return true;
34}
35
37{
38 LOG(VB_RECORD, LOG_INFO, LOC + "Close() -- begin");
39
40 if (IsOpen())
42 m_tvrec ? m_tvrec->GetInputId() : -1);
43
44 LOG(VB_RECORD, LOG_INFO, LOC + "Close() -- end");
45}
46
48{
49 // Make sure the first things in the file are a PAT & PMT
52}
53
55{
56 LOG(VB_RECORD, LOG_INFO, LOC + "run -- begin");
57
58 /* Create video socket. */
59 if (!Open())
60 {
61 m_error = "Failed to open CetonRecorder device";
62 LOG(VB_GENERAL, LOG_ERR, LOC + m_error);
63 return;
64 }
65
66 {
67 QMutexLocker locker(&m_pauseLock);
68 m_requestRecording = true;
69 m_recording = true;
70 m_recordingWait.wakeAll();
71 }
72
74
78
79 while (IsRecordingRequested() && !IsErrored())
80 {
81 if (PauseAndWait())
82 continue;
83
85 break;
86
87 { // sleep 100 milliseconds unless StopRecording() or Unpause()
88 // is called, just to avoid running this too often.
89 QMutexLocker locker(&m_pauseLock);
91 continue;
92 m_unpauseWait.wait(&m_pauseLock, 100);
93 }
94
95 if (!m_inputPmt)
96 {
97 LOG(VB_GENERAL, LOG_WARNING, LOC +
98 "Recording will not commence until a PMT is set.");
99 usleep(5000);
100 continue;
101 }
102
104 {
105 m_error = "Stream handler died unexpectedly.";
106 LOG(VB_GENERAL, LOG_ERR, LOC + m_error);
107 }
108 }
109
110 LOG(VB_RECORD, LOG_INFO, LOC + "run -- ending...");
111
115
116 Close();
117
119
120 QMutexLocker locker(&m_pauseLock);
121 m_recording = false;
122 m_recordingWait.wakeAll();
123
124 LOG(VB_RECORD, LOG_INFO, LOC + "run -- end");
125}
126
127bool CetonRecorder::PauseAndWait(std::chrono::milliseconds timeout)
128{
129 QMutexLocker locker(&m_pauseLock);
130 if (m_requestPause)
131 {
132 if (!IsPaused(true))
133 {
135
136 m_paused = true;
137 m_pauseWait.wakeAll();
138 if (m_tvrec)
140 }
141
142 m_unpauseWait.wait(&m_pauseLock, timeout.count());
143 }
144
145 if (!m_requestPause && IsPaused(true))
146 {
147 m_paused = false;
149 m_unpauseWait.wakeAll();
150 }
151
152 return IsPaused(true);
153}
154
156{
157 return m_channel->GetSIStandard();
158}
159
160/* vim: set expandtab tabstop=4 shiftwidth=4: */
#define LOC
-*- Mode: c++ -*- CetonRecorder Copyright (c) 2011 Ronald Frazier Copyright (c) 2006-2009 by Silicond...
QString GetDevice(void) const override
Returns String representing device, useful for debugging.
Definition: cetonchannel.h:38
void StartNewFile(void) override
CetonStreamHandler * m_streamHandler
Definition: cetonrecorder.h:42
void Close(void)
CetonChannel * m_channel
Definition: cetonrecorder.h:41
bool Open(void)
bool IsOpen(void) const
Definition: cetonrecorder.h:32
void run(void) override
run() starts the recording process, and does not exit until the recording is complete.
QString GetSIStandard(void) const override
bool PauseAndWait(std::chrono::milliseconds timeout=100ms) override
If m_requestPause is true, sets pause and blocks up to timeout milliseconds or until unpaused,...
static void Return(CetonStreamHandler *&ref, int inputid)
static CetonStreamHandler * Get(const QString &devname, int inputid)
QString GetSIStandard(void) const
Returns PSIP table standard: MPEG, DVB, ATSC, or OpenCable.
Definition: dtvchannel.cpp:45
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
void HandleSingleProgramPMT(ProgramMapTable *pmt, bool insert) override
void AddListener(MPEGStreamData *data, bool=false, bool=false, const QString &output_file=QString()) override
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:313
bool m_requestPause
Definition: recorderbase.h:314
TVRec * m_tvrec
Definition: recorderbase.h:290
virtual bool IsRecordingRequested(void)
Tells us if StopRecording() has been called.
bool m_recording
True while recording is actually being performed.
Definition: recorderbase.h:321
QWaitCondition m_pauseWait
Definition: recorderbase.h:316
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:319
QWaitCondition m_unpauseWait
Definition: recorderbase.h:317
QWaitCondition m_recordingWait
Definition: recorderbase.h:322
bool IsRunning(void) const
virtual void RemoveListener(MPEGStreamData *data)
void RecorderPaused(void)
This is a callback, called by the "recorder" instance when it has actually paused.
Definition: tv_rec.cpp:2996
uint GetInputId(void) const
Returns the inputid.
Definition: tv_rec.h:234
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39