MythTV  master
cetonrecorder.cpp
Go to the documentation of this file.
1 
8 // MythTV includes
9 #include "cetonstreamhandler.h"
10 #include "cetonrecorder.h"
11 #include "cetonchannel.h"
12 #include "mythlogging.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 
73  StartNewFile();
74 
78 
79  while (IsRecordingRequested() && !IsErrored())
80  {
81  if (PauseAndWait())
82  continue;
83 
84  if (!IsRecordingRequested())
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 
103  if (!m_streamHandler->IsRunning())
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 
118  FinishRecording();
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 
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 
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 
155 QString CetonRecorder::GetSIStandard(void) const
156 {
157  return m_channel->GetSIStandard();
158 }
159 
160 /* vim: set expandtab tabstop=4 shiftwidth=4: */
DTVRecorder::HandleSingleProgramPMT
void HandleSingleProgramPMT(ProgramMapTable *pmt, bool insert) override
Definition: dtvrecorder.cpp:1334
IPTVStreamHandler::AddListener
void AddListener(MPEGStreamData *data, bool=false, bool=false, QString output_file=QString()) override
Definition: iptvstreamhandler.h:89
hardwareprofile.smolt.timeout
float timeout
Definition: smolt.py:103
DTVRecorder::m_inputPmt
ProgramMapTable * m_inputPmt
PMT on input side.
Definition: dtvrecorder.h:174
DTVRecorder::ResetForNewFile
void ResetForNewFile(void) override
Definition: dtvrecorder.cpp:138
CetonRecorder::Close
void Close(void)
Definition: cetonrecorder.cpp:36
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:47
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
CetonRecorder::IsOpen
bool IsOpen(void) const
Definition: cetonrecorder.h:32
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
MPEGStreamData::PMTSingleProgram
const ProgramMapTable * PMTSingleProgram(void) const
Definition: mpegstreamdata.h:262
StreamHandler::RemoveListener
virtual void RemoveListener(MPEGStreamData *data)
Definition: streamhandler.cpp:78
RecorderBase::m_pauseLock
QMutex m_pauseLock
Definition: recorderbase.h:337
CetonRecorder::GetSIStandard
QString GetSIStandard(void) const override
Definition: cetonrecorder.cpp:155
RecorderBase::m_requestPause
bool m_requestPause
Definition: recorderbase.h:338
RecorderBase::m_recordingWait
QWaitCondition m_recordingWait
Definition: recorderbase.h:346
TVRec::RecorderPaused
void RecorderPaused(void)
This is a callback, called by the "recorder" instance when it has actually paused.
Definition: tv_rec.cpp:2947
CetonRecorder::m_channel
CetonChannel * m_channel
Definition: cetonrecorder.h:41
TVRec::GetInputId
uint GetInputId(void) const
Returns the inputid.
Definition: tv_rec.h:234
RecorderBase::m_paused
bool m_paused
Definition: recorderbase.h:339
cetonchannel.h
MPEGStreamData::PATSingleProgram
const ProgramAssociationTable * PATSingleProgram(void) const
Definition: mpegstreamdata.h:260
DTVRecorder::HandleSingleProgramPAT
void HandleSingleProgramPAT(ProgramAssociationTable *pat, bool insert) override
Definition: dtvrecorder.cpp:1314
mythlogging.h
MPEGStreamData::RemoveWritingListener
void RemoveWritingListener(TSPacketListener *val)
Definition: mpegstreamdata.cpp:1629
RecorderBase::IsRecordingRequested
virtual bool IsRecordingRequested(void)
Tells us if StopRecording() has been called.
Definition: recorderbase.cpp:252
cetonstreamhandler.h
CetonRecorder::m_streamHandler
CetonStreamHandler * m_streamHandler
Definition: cetonrecorder.h:42
cetonrecorder.h
DTVChannel::GetSIStandard
QString GetSIStandard(void) const
Returns PSIP table standard: MPEG, DVB, ATSC, or OpenCable.
Definition: dtvchannel.cpp:44
RecorderBase::m_pauseWait
QWaitCondition m_pauseWait
Definition: recorderbase.h:340
CetonRecorder::run
void run(void) override
run() starts the recording process, and does not exit until the recording is complete.
Definition: cetonrecorder.cpp:54
CetonRecorder::PauseAndWait
bool PauseAndWait(int timeout=100) override
If m_requestPause is true, sets pause and blocks up to timeout milliseconds or until unpaused,...
Definition: cetonrecorder.cpp:127
MPEGStreamData::AddAVListener
void AddAVListener(TSPacketListenerAV *val)
Definition: mpegstreamdata.cpp:1643
LOC
#define LOC
-*- Mode: c++ -*- CetonRecorder Copyright (c) 2011 Ronald Frazier Copyright (c) 2006-2009 by Silicond...
Definition: cetonrecorder.cpp:15
CetonChannel::GetDevice
QString GetDevice(void) const override
Returns String representing device, useful for debugging.
Definition: cetonchannel.h:38
CetonStreamHandler::Return
static void Return(CetonStreamHandler *&ref, int inputid)
Definition: cetonstreamhandler.cpp:70
DTVRecorder::m_streamData
MPEGStreamData * m_streamData
Definition: dtvrecorder.h:163
MPEGStreamData::AddWritingListener
void AddWritingListener(TSPacketListener *val)
Definition: mpegstreamdata.cpp:1618
DTVRecorder::m_error
QString m_error
non-empty iff irrecoverable recording error detected
Definition: dtvrecorder.h:161
CetonStreamHandler::Get
static CetonStreamHandler * Get(const QString &devname, int inputid)
Definition: cetonstreamhandler.cpp:37
CetonRecorder::StartNewFile
void StartNewFile(void) override
Definition: cetonrecorder.cpp:47
RecorderBase::m_recording
bool m_recording
True while recording is actually being performed.
Definition: recorderbase.h:345
tv_rec.h
StreamHandler::IsRunning
bool IsRunning(void) const
Definition: streamhandler.cpp:161
RecorderBase::m_unpauseWait
QWaitCondition m_unpauseWait
Definition: recorderbase.h:341
MPEGStreamData::RemoveAVListener
void RemoveAVListener(TSPacketListenerAV *val)
Definition: mpegstreamdata.cpp:1654
RecorderBase::IsPaused
virtual bool IsPaused(bool holding_lock=false) const
Returns true iff recorder is paused.
Definition: recorderbase.cpp:284
RecorderBase::m_requestRecording
bool m_requestRecording
True if API call has requested a recording be [re]started.
Definition: recorderbase.h:343
CetonRecorder::Open
bool Open(void)
Definition: cetonrecorder.cpp:18