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_request_recording = 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_input_pmt)
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_stream_handler->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_request_pause)
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_request_pause && 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: */
const ProgramAssociationTable * PATSingleProgram(void) const
uint GetInputId(void)
Returns the inputid.
Definition: tv_rec.h:241
bool PauseAndWait(int timeout=100) override
If m_request_pause is true, sets pause and blocks up to timeout milliseconds or until unpaused,...
QMutex m_pauseLock
Definition: recorderbase.h:326
void ResetForNewFile(void) override
virtual void RemoveListener(MPEGStreamData *data)
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 Open(void)
bool m_request_recording
True if API call has requested a recording be [re]started.
Definition: recorderbase.h:332
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
static CetonStreamHandler * Get(const QString &devname, int inputid)
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
void StartNewFile(void) override
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 *)
bool IsOpen(void) const
Definition: cetonrecorder.h:32
QWaitCondition m_recordingWait
Definition: recorderbase.h:335
bool m_recording
True while recording is actually being performed.
Definition: recorderbase.h:334
QString GetSIStandard(void) const override
void Close(void)
bool m_request_pause
Definition: recorderbase.h:327
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
TVRec * m_tvrec
Definition: recorderbase.h:303
const ProgramMapTable * PMTSingleProgram(void) const
void AddWritingListener(TSPacketListener *)
void run(void) override
run() starts the recording process, and does not exit until the recording is complete.
CetonChannel * m_channel
Definition: cetonrecorder.h:41
QString m_error
non-empty iff irrecoverable recording error detected
Definition: dtvrecorder.h:162
QString GetSIStandard(void) const
Returns PSIP table standard: MPEG, DVB, ATSC, or OpenCable.
Definition: dtvchannel.cpp:44
void RemoveAVListener(TSPacketListenerAV *)
CetonStreamHandler * m_stream_handler
Definition: cetonrecorder.h:42
QString GetDevice(void) const override
Returns String representing device, useful for debugging.
Definition: cetonchannel.h:36
bool IsRunning(void) const
void HandleSingleProgramPMT(ProgramMapTable *pmt, bool insert) override
#define LOC
-*- Mode: c++ -*- CetonRecorder Copyright (c) 2011 Ronald Frazier Copyright (c) 2006-2009 by Silicond...
static void Return(CetonStreamHandler *&ref, int inputid)
void AddListener(MPEGStreamData *data, bool=false, bool=false, QString output_file=QString()) override
virtual bool IsRecordingRequested(void)
Tells us if StopRecording() has been called.