MythTV master
asirecorder.cpp
Go to the documentation of this file.
1/* -*- Mode: c++ -*-
2 * Class ASIRecorder
3 *
4 * Copyright (C) Daniel Kristjansson 2010
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21// Qt includes
22#include <QString>
23
24// MythTV includes
27
28#include "asichannel.h"
29#include "asirecorder.h"
30#include "asistreamhandler.h"
31#include "io/mythmediabuffer.h"
32#include "mpeg/tsstreamdata.h"
33#include "tv_rec.h"
34
35#define LOC QString("ASIRec[%1](%2): ") \
36 .arg(m_tvrec ? m_tvrec->GetInputId() : -1) \
37 .arg(m_channel->GetDevice())
38
40 DTVRecorder(rec), m_channel(channel)
41{
42 if (channel->GetFormat().compare("MPTS") == 0)
43 {
44 // MPTS only. Use TSStreamData to write out unfiltered data
45 LOG(VB_RECORD, LOG_INFO, LOC + "Using TSStreamData");
47 m_recordMptsOnly = true;
48 m_recordMpts = false;
49 }
50 else
51 {
52 LOG(VB_RECORD, LOG_INFO, LOC + "Using MPEGStreamData");
53 SetStreamData(new MPEGStreamData(-1, rec ? rec->GetInputId() : -1,
54 false));
55 if (channel->GetProgramNumber() < 0 || !channel->GetMinorChannel())
57 }
58}
59
61 const QString &videodev,
62 const QString &/*audiodev*/,
63 const QString &/*vbidev*/)
64{
65 // We don't want to call DTVRecorder::SetOptionsFromProfile() since
66 // we do not have a "recordingtype" in our profile.
67 DTVRecorder::SetOption("videodevice", videodev);
68 DTVRecorder::SetOption("tvformat", gCoreContext->GetSetting("TVFormat"));
69 SetIntOption(profile, "recordmpts");
70}
71
73{
75 {
76 if (m_recordMpts)
78
79 // Make sure the first things in the file are a PAT & PMT
82 }
83}
84
85
87{
88 if (!Open())
89 {
90 m_error = "Failed to open device";
91 LOG(VB_GENERAL, LOG_ERR, LOC + m_error);
92 return;
93 }
94
95 if (!m_streamData)
96 {
97 m_error = "MPEGStreamData pointer has not been set";
98 LOG(VB_GENERAL, LOG_ERR, LOC + m_error);
99 Close();
100 return;
101 }
102
103 {
104 QMutexLocker locker(&m_pauseLock);
105 m_requestRecording = true;
106 m_recording = true;
107 m_recordingWait.wakeAll();
108 }
109
111 {
116 m_streamData->HandleTables(pat->ProgramPID(0), *pmt);
117 }
118
119 // Listen for time table on DVB standard streams
120 if (m_channel && (m_channel->GetSIStandard() == "dvb"))
122
123 StartNewFile();
124
128 m_streamData, false, true,
129 (m_recordMpts) ? m_ringBuffer->GetFilename() : QString());
130
131 while (IsRecordingRequested() && !IsErrored())
132 {
133 if (PauseAndWait())
134 continue;
135
136 { // sleep 100 milliseconds unless StopRecording() or Unpause()
137 // is called, just to avoid running this too often.
138 QMutexLocker locker(&m_pauseLock);
140 continue;
141 m_unpauseWait.wait(&m_pauseLock, 100);
142 }
143
145 {
146 LOG(VB_GENERAL, LOG_WARNING, LOC +
147 "Recording will not commence until a PMT is set.");
148 usleep(5000);
149 continue;
150 }
151
153 {
154 m_error = "Stream handler died unexpectedly.";
155 LOG(VB_GENERAL, LOG_ERR, LOC + m_error);
156 }
157 }
158
162
163 Close();
164
166
167 QMutexLocker locker(&m_pauseLock);
168 m_recording = false;
169 m_recordingWait.wakeAll();
170}
171
173{
174 if (IsOpen())
175 {
176 LOG(VB_GENERAL, LOG_WARNING, LOC + "Card already open");
177 return true;
178 }
179
181
183 m_tvrec ? m_tvrec->GetInputId() : -1);
184
185
186 LOG(VB_RECORD, LOG_INFO, LOC + "Opened successfully");
187
188 return true;
189}
190
191bool ASIRecorder::IsOpen(void) const
192{
193 return m_streamHandler;
194}
195
197{
198 LOG(VB_RECORD, LOG_INFO, LOC + "Close() -- begin");
199
200 if (IsOpen())
202 m_tvrec ? m_tvrec->GetInputId() : -1);
203
204 LOG(VB_RECORD, LOG_INFO, LOC + "Close() -- end");
205}
#define LOC
Definition: asirecorder.cpp:35
-*- Mode: c++ -*-
Definition: asichannel.h:15
QString GetDevice(void) const override
Returns String representing device, useful for debugging.
Definition: asichannel.h:34
void StartNewFile(void) override
Definition: asirecorder.cpp:72
bool IsOpen(void) const
void SetOptionsFromProfile(RecordingProfile *profile, const QString &videodev, const QString &audiodev, const QString &vbidev) override
Sets basic recorder options.
Definition: asirecorder.cpp:60
ASIChannel * m_channel
Definition: asirecorder.h:73
bool Open(void)
void Close(void)
ASIStreamHandler * m_streamHandler
Definition: asirecorder.h:74
ASIRecorder(TVRec *rec, ASIChannel *channel)
Definition: asirecorder.cpp:39
void run(void) override
run() starts the recording process, and does not exit until the recording is complete.
Definition: asirecorder.cpp:86
static ASIStreamHandler * Get(const QString &devname, int inputid)
void AddListener(MPEGStreamData *data, bool=false, bool=false, const QString &output_file=QString()) override
static void Return(ASIStreamHandler *&ref, int inputid)
int GetProgramNumber(void) const
Returns program number in PAT, -1 if unknown.
Definition: dtvchannel.h:89
QString GetSIStandard(void) const
Returns PSIP table standard: MPEG, DVB, ATSC, or OpenCable.
Definition: dtvchannel.cpp:45
QString GetFormat(void)
Definition: dtvchannel.h:46
uint GetMinorChannel(void) const
Returns minor channel, 0 if unknown.
Definition: dtvchannel.h:97
bool HasGeneratedPAT(void) const
Definition: dtvchannel.h:135
const ProgramMapTable * GetGeneratedPMT(void) const
Definition: dtvchannel.h:138
const ProgramAssociationTable * GetGeneratedPAT(void) const
Definition: dtvchannel.h:137
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
void SetOption(const QString &name, const QString &value) override
Set an specific option.
Definition: dtvrecorder.cpp:92
bool m_recordMptsOnly
Definition: dtvrecorder.h:179
bool m_recordMpts
Definition: dtvrecorder.h:178
virtual void SetStreamData(MPEGStreamData *data)
void HandleSingleProgramPMT(ProgramMapTable *pmt, bool insert) override
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
virtual void Reset(void)
void RemoveAVListener(TSPacketListenerAV *val)
virtual void AddListeningPID(uint pid, PIDPriority priority=kPIDPriorityNormal)
void SetListeningDisabled(bool lt)
virtual bool HandleTables(uint pid, const PSIPTable &psip)
Process PSIP packets.
void AddAVListener(TSPacketListenerAV *val)
QString GetSetting(const QString &key, const QString &defaultval="")
QString GetFilename(void) const
@ DVB_TDT_PID
Definition: mpegtables.h:219
@ MPEG_PAT_PID
Definition: mpegtables.h:211
The Program Association Table lists all the programs in a stream, and is always found on PID 0.
Definition: mpegtables.h:599
uint ProgramNumber(uint i) const
Definition: mpegtables.h:626
uint ProgramPID(uint i) const
Definition: mpegtables.h:629
A PMT table maps a program described in the ProgramAssociationTable to various PID's which describe t...
Definition: mpegtables.h:676
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.
virtual bool PauseAndWait(std::chrono::milliseconds timeout=100ms)
If m_requestPause is true, sets pause and blocks up to timeout milliseconds or until unpaused,...
bool m_recording
True while recording is actually being performed.
Definition: recorderbase.h:321
MythMediaBuffer * m_ringBuffer
Definition: recorderbase.h:291
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
void SetIntOption(RecordingProfile *profile, const QString &name)
Convenience function used to set integer options from a profile.
virtual bool AddNamedOutputFile(const QString &filename)
Called with _listener_lock locked just after adding new output file.
bool IsRunning(void) const
virtual void RemoveListener(MPEGStreamData *data)
Specialized version of MPEGStreamData which is used to 'blindly' record the entire MPTS transport fro...
Definition: tsstreamdata.h:12
This is the coordinating class of the Recorder Subsystem.
Definition: tv_rec.h:143
uint GetInputId(void) const
Returns the inputid.
Definition: tv_rec.h:234
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39