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(tvrec ? tvrec->GetInputId() : -1)
17 
19  DTVRecorder(rec), _channel(channel), _stream_handler(nullptr)
20 {
21 }
22 
24 {
25  if (IsOpen())
26  {
27  LOG(VB_GENERAL, LOG_WARNING, LOC + "Card already open");
28  return true;
29  }
30 
32 
34  tvrec ? tvrec->GetInputId() : -1);
35 
36  LOG(VB_RECORD, LOG_INFO, LOC + "Ceton opened successfully");
37 
38  return true;
39 }
40 
42 {
43  LOG(VB_RECORD, LOG_INFO, LOC + "Close() -- begin");
44 
45  if (IsOpen())
47  tvrec ? tvrec->GetInputId() : -1);
48 
49  LOG(VB_RECORD, LOG_INFO, LOC + "Close() -- end");
50 }
51 
53 {
54  // Make sure the first things in the file are a PAT & PMT
57 }
58 
60 {
61  LOG(VB_RECORD, LOG_INFO, LOC + "run -- begin");
62 
63  /* Create video socket. */
64  if (!Open())
65  {
66  _error = "Failed to open CetonRecorder device";
67  LOG(VB_GENERAL, LOG_ERR, LOC + _error);
68  return;
69  }
70 
71  {
72  QMutexLocker locker(&pauseLock);
73  request_recording = true;
74  recording = true;
75  recordingWait.wakeAll();
76  }
77 
78  StartNewFile();
79 
83 
84  while (IsRecordingRequested() && !IsErrored())
85  {
86  if (PauseAndWait())
87  continue;
88 
89  if (!IsRecordingRequested())
90  break;
91 
92  { // sleep 100 milliseconds unless StopRecording() or Unpause()
93  // is called, just to avoid running this too often.
94  QMutexLocker locker(&pauseLock);
96  continue;
97  unpauseWait.wait(&pauseLock, 100);
98  }
99 
100  if (!_input_pmt)
101  {
102  LOG(VB_GENERAL, LOG_WARNING, LOC +
103  "Recording will not commence until a PMT is set.");
104  usleep(5000);
105  continue;
106  }
107 
108  if (!_stream_handler->IsRunning())
109  {
110  _error = "Stream handler died unexpectedly.";
111  LOG(VB_GENERAL, LOG_ERR, LOC + _error);
112  }
113  }
114 
115  LOG(VB_RECORD, LOG_INFO, LOC + "run -- ending...");
116 
120 
121  Close();
122 
123  FinishRecording();
124 
125  QMutexLocker locker(&pauseLock);
126  recording = false;
127  recordingWait.wakeAll();
128 
129  LOG(VB_RECORD, LOG_INFO, LOC + "run -- end");
130 }
131 
133 {
134  QMutexLocker locker(&pauseLock);
135  if (request_pause)
136  {
137  if (!IsPaused(true))
138  {
140 
141  paused = true;
142  pauseWait.wakeAll();
143  if (tvrec)
145  }
146 
147  unpauseWait.wait(&pauseLock, timeout);
148  }
149 
150  if (!request_pause && IsPaused(true))
151  {
152  paused = false;
154  unpauseWait.wakeAll();
155  }
156 
157  return IsPaused(true);
158 }
159 
160 QString CetonRecorder::GetSIStandard(void) const
161 {
162  return _channel->GetSIStandard();
163 }
164 
165 /* vim: set expandtab tabstop=4 shiftwidth=4: */
QString _error
non-empty iff irrecoverable recording error detected
Definition: dtvrecorder.h:162
const ProgramAssociationTable * PATSingleProgram(void) const
This is a specialization of RecorderBase used to handle MPEG-2, MPEG-4, MPEG-4 AVC,...
Definition: dtvrecorder.h:28
QWaitCondition unpauseWait
Definition: recorderbase.h:323
uint GetInputId(void)
Returns the inputid.
Definition: tv_rec.h:241
QMutex pauseLock
Definition: recorderbase.h:319
bool PauseAndWait(int timeout=100) override
If request_pause is true, sets pause and blocks up to timeout milliseconds or until unpaused,...
void ResetForNewFile(void) override
QWaitCondition pauseWait
Definition: recorderbase.h:322
virtual void RemoveListener(MPEGStreamData *data)
QWaitCondition recordingWait
Definition: recorderbase.h:328
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)
MPEGStreamData * _stream_data
Definition: dtvrecorder.h:164
virtual bool IsPaused(bool holding_lock=false) const
Returns true iff recorder is paused.
void FinishRecording(void) override
Flushes the ringbuffer, and if this is not a live LiveTV recording saves the position map and filesiz...
TVRec * tvrec
Definition: recorderbase.h:296
bool recording
True while recording is actually being performed.
Definition: recorderbase.h:327
void StartNewFile(void) override
This is the coordinating class of the Recorder Subsystem.
Definition: tv_rec.h:150
bool request_recording
True if API call has requested a recording be [re]started.
Definition: recorderbase.h:325
void RemoveWritingListener(TSPacketListener *)
void RecorderPaused(void)
This is a callback, called by the "recorder" instance when it has actually paused.
Definition: tv_rec.cpp:2966
void AddAVListener(TSPacketListenerAV *)
bool IsOpen(void) const
Definition: cetonrecorder.h:31
QString GetSIStandard(void) const override
void Close(void)
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
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.
ProgramMapTable * _input_pmt
PMT on input side.
Definition: dtvrecorder.h:173
CetonStreamHandler * _stream_handler
Definition: cetonrecorder.h:41
static CetonStreamHandler * Get(const QString &devicename, int inputid)
QString GetSIStandard(void) const
Returns PSIP table standard: MPEG, DVB, ATSC, or OpenCable.
Definition: dtvchannel.cpp:55
void RemoveAVListener(TSPacketListenerAV *)
CetonChannel * _channel
Definition: cetonrecorder.h:40
QString GetDevice(void) const override
Returns String representing device, useful for debugging.
Definition: cetonchannel.h:35
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...
CetonRecorder(TVRec *rec, CetonChannel *channel)
static void Return(CetonStreamHandler *&ref, int inputid)
void AddListener(MPEGStreamData *data, bool=false, bool=false, QString output_file=QString()) override
bool request_pause
Definition: recorderbase.h:320
virtual bool IsRecordingRequested(void)
Tells us if StopRecording() has been called.