MythTV  master
capture.cpp
Go to the documentation of this file.
1 // Program Name: capture.cpp
3 // Created : Sep. 21, 2011
4 //
5 // Copyright (c) 2011 Robert McNamara <rmcnamara@mythtv.org>
6 //
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 2 of the License, or
10 // (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program. If not, see <http://www.gnu.org/licenses/>.
23 //
25 
26 #include <QList>
27 #include <QFile>
28 #include <QMutex>
29 
30 #include "capture.h"
31 
32 #include "cardutil.h"
33 
34 #include "compat.h"
35 #include "mythversion.h"
36 #include "mythcorecontext.h"
37 #include "mythdate.h"
38 #include "serviceUtil.h"
39 
41 //
43 
45  const QString &sCardType )
46 {
48 
49  if (!query.isConnected())
50  throw( QString("Database not open while trying to list "
51  "Capture Cards."));
52 
53  QString str = "SELECT cardid, parentid, videodevice, audiodevice, vbidevice, "
54  "cardtype, defaultinput, audioratelimit, hostname, "
55  "dvb_swfilter, dvb_sat_type, dvb_wait_for_seqstart, "
56  "skipbtaudio, dvb_on_demand, dvb_diseqc_type, "
57  "firewire_speed, firewire_model, firewire_connection, "
58  "signal_timeout, channel_timeout, dvb_tuning_delay, "
59  "contrast, brightness, colour, hue, diseqcid, dvb_eitscan, "
60  "inputname, sourceid, externalcommand, changer_device, "
61  "changer_model, tunechan, startchan, displayname, "
62  "dishnet_eit, recpriority, quicktune, schedorder, "
63  "livetvorder, reclimit, schedgroup "
64  "from capturecard";
65 
66  if (!sHostName.isEmpty())
67  str += " WHERE hostname = :HOSTNAME";
68  else if (!sCardType.isEmpty())
69  str += " WHERE cardtype = :CARDTYPE";
70 
71  if (!sHostName.isEmpty() && !sCardType.isEmpty())
72  str += " AND cardtype = :CARDTYPE";
73 
74  query.prepare(str);
75 
76  if (!sHostName.isEmpty())
77  query.bindValue(":HOSTNAME", sHostName);
78  if (!sCardType.isEmpty())
79  query.bindValue(":CARDTYPE", sCardType);
80 
81  if (!query.exec())
82  {
83  MythDB::DBError("MythAPI::GetCaptureCardList()", query);
84  throw( QString( "Database Error executing query." ));
85  }
86 
87  // ----------------------------------------------------------------------
88  // return the results of the query
89  // ----------------------------------------------------------------------
90 
92 
93  while (query.next())
94  {
95 
96  DTC::CaptureCard *pCaptureCard = pList->AddNewCaptureCard();
97 
98  pCaptureCard->setCardId ( query.value(0).toInt() );
99  pCaptureCard->setParentId ( query.value(1).toInt() );
100  pCaptureCard->setVideoDevice ( query.value(2).toString() );
101  pCaptureCard->setAudioDevice ( query.value(3).toString() );
102  pCaptureCard->setVBIDevice ( query.value(4).toString() );
103  pCaptureCard->setCardType ( query.value(5).toString() );
104  pCaptureCard->setDefaultInput ( query.value(6).toString() );
105  pCaptureCard->setAudioRateLimit ( query.value(7).toUInt() );
106  pCaptureCard->setHostName ( query.value(8).toString() );
107  pCaptureCard->setDVBSWFilter ( query.value(9).toUInt() );
108  pCaptureCard->setDVBSatType ( query.value(10).toUInt() );
109  pCaptureCard->setDVBWaitForSeqStart( query.value(11).toBool() );
110  pCaptureCard->setSkipBTAudio ( query.value(12).toBool() );
111  pCaptureCard->setDVBOnDemand ( query.value(13).toBool() );
112  pCaptureCard->setDVBDiSEqCType ( query.value(14).toUInt() );
113  pCaptureCard->setFirewireSpeed ( query.value(15).toUInt() );
114  pCaptureCard->setFirewireModel ( query.value(16).toString() );
115  pCaptureCard->setFirewireConnection( query.value(17).toUInt() );
116  pCaptureCard->setSignalTimeout ( query.value(18).toUInt() );
117  pCaptureCard->setChannelTimeout ( query.value(19).toUInt() );
118  pCaptureCard->setDVBTuningDelay ( query.value(20).toUInt() );
119  pCaptureCard->setContrast ( query.value(21).toUInt() );
120  pCaptureCard->setBrightness ( query.value(22).toUInt() );
121  pCaptureCard->setColour ( query.value(23).toUInt() );
122  pCaptureCard->setHue ( query.value(24).toUInt() );
123  pCaptureCard->setDiSEqCId ( query.value(25).toUInt() );
124  pCaptureCard->setDVBEITScan ( query.value(26).toBool() );
125  pCaptureCard->setInputName ( query.value(27).toString() );
126  pCaptureCard->setSourceId ( query.value(28).toInt() );
127  pCaptureCard->setExternalCommand ( query.value(29).toString() );
128  pCaptureCard->setChangerDevice ( query.value(30).toString() );
129  pCaptureCard->setChangerModel ( query.value(31).toString() );
130  pCaptureCard->setTuneChannel ( query.value(32).toString() );
131  pCaptureCard->setStartChannel ( query.value(33).toString() );
132  pCaptureCard->setDisplayName ( query.value(34).toString() );
133  pCaptureCard->setDishnetEit ( query.value(35).toBool() );
134  pCaptureCard->setRecPriority ( query.value(36).toInt() );
135  pCaptureCard->setQuickTune ( query.value(37).toBool() );
136  pCaptureCard->setSchedOrder ( query.value(38).toUInt() );
137  pCaptureCard->setLiveTVOrder ( query.value(39).toUInt() );
138  pCaptureCard->setRecLimit ( query.value(40).toUInt() );
139  pCaptureCard->setSchedGroup ( query.value(41).toBool() );
140  }
141 
142  return pList;
143 }
144 
146 //
148 
150 {
151  if ( nCardId < 1 )
152  throw( QString( "The Card ID is invalid."));
153 
154  MSqlQuery query(MSqlQuery::InitCon());
155 
156  if (!query.isConnected())
157  throw( QString("Database not open while trying to list "
158  "Capture Cards."));
159 
160  QString str = "SELECT cardid, parentid, videodevice, audiodevice, vbidevice, "
161  "cardtype, defaultinput, audioratelimit, hostname, "
162  "dvb_swfilter, dvb_sat_type, dvb_wait_for_seqstart, "
163  "skipbtaudio, dvb_on_demand, dvb_diseqc_type, "
164  "firewire_speed, firewire_model, firewire_connection, "
165  "signal_timeout, channel_timeout, dvb_tuning_delay, "
166  "contrast, brightness, colour, hue, diseqcid, dvb_eitscan, "
167  "inputname, sourceid, externalcommand, changer_device, "
168  "changer_model, tunechan, startchan, displayname, "
169  "dishnet_eit, recpriority, quicktune, schedorder, "
170  "livetvorder, reclimit, schedgroup "
171  "from capturecard WHERE cardid = :CARDID";
172 
173  query.prepare(str);
174  query.bindValue(":CARDID", nCardId);
175 
176  if (!query.exec())
177  {
178  MythDB::DBError("MythAPI::GetCaptureCard()", query);
179  throw( QString( "Database Error executing query." ));
180  }
181 
182  DTC::CaptureCard* pCaptureCard = new DTC::CaptureCard();
183 
184  if (query.next())
185  {
186  pCaptureCard->setCardId ( query.value(0).toInt() );
187  pCaptureCard->setParentId ( query.value(1).toInt() );
188  pCaptureCard->setVideoDevice ( query.value(2).toString() );
189  pCaptureCard->setAudioDevice ( query.value(3).toString() );
190  pCaptureCard->setVBIDevice ( query.value(4).toString() );
191  pCaptureCard->setCardType ( query.value(5).toString() );
192  pCaptureCard->setDefaultInput ( query.value(6).toString() );
193  pCaptureCard->setAudioRateLimit ( query.value(7).toUInt() );
194  pCaptureCard->setHostName ( query.value(8).toString() );
195  pCaptureCard->setDVBSWFilter ( query.value(9).toUInt() );
196  pCaptureCard->setDVBSatType ( query.value(10).toUInt() );
197  pCaptureCard->setDVBWaitForSeqStart( query.value(11).toBool() );
198  pCaptureCard->setSkipBTAudio ( query.value(12).toBool() );
199  pCaptureCard->setDVBOnDemand ( query.value(13).toBool() );
200  pCaptureCard->setDVBDiSEqCType ( query.value(14).toUInt() );
201  pCaptureCard->setFirewireSpeed ( query.value(15).toUInt() );
202  pCaptureCard->setFirewireModel ( query.value(16).toString() );
203  pCaptureCard->setFirewireConnection( query.value(17).toUInt() );
204  pCaptureCard->setSignalTimeout ( query.value(18).toUInt() );
205  pCaptureCard->setChannelTimeout ( query.value(19).toUInt() );
206  pCaptureCard->setDVBTuningDelay ( query.value(20).toUInt() );
207  pCaptureCard->setContrast ( query.value(21).toUInt() );
208  pCaptureCard->setBrightness ( query.value(22).toUInt() );
209  pCaptureCard->setColour ( query.value(23).toUInt() );
210  pCaptureCard->setHue ( query.value(24).toUInt() );
211  pCaptureCard->setDiSEqCId ( query.value(25).toUInt() );
212  pCaptureCard->setDVBEITScan ( query.value(26).toBool() );
213  pCaptureCard->setInputName ( query.value(27).toString() );
214  pCaptureCard->setSourceId ( query.value(28).toInt() );
215  pCaptureCard->setExternalCommand ( query.value(29).toString() );
216  pCaptureCard->setChangerDevice ( query.value(30).toString() );
217  pCaptureCard->setChangerModel ( query.value(31).toString() );
218  pCaptureCard->setTuneChannel ( query.value(32).toString() );
219  pCaptureCard->setStartChannel ( query.value(33).toString() );
220  pCaptureCard->setDisplayName ( query.value(34).toString() );
221  pCaptureCard->setDishnetEit ( query.value(35).toBool() );
222  pCaptureCard->setRecPriority ( query.value(36).toInt() );
223  pCaptureCard->setQuickTune ( query.value(37).toBool() );
224  pCaptureCard->setSchedOrder ( query.value(38).toUInt() );
225  pCaptureCard->setLiveTVOrder ( query.value(39).toUInt() );
226  pCaptureCard->setRecLimit ( query.value(40).toUInt() );
227  pCaptureCard->setSchedGroup ( query.value(41).toBool() );
228  }
229 
230  return pCaptureCard;
231 }
232 
234 //
236 
237 bool Capture::RemoveCaptureCard( int nCardId )
238 {
239  if ( nCardId < 1 )
240  throw( QString( "The Card ID is invalid."));
241 
242  bool bResult = CardUtil::DeleteInput(nCardId);
243 
244  return bResult;
245 }
246 
248 //
250 
251 int Capture::AddCaptureCard ( const QString &sVideoDevice,
252  const QString &sAudioDevice,
253  const QString &sVBIDevice,
254  const QString &sCardType,
255  const uint nAudioRateLimit,
256  const QString &sHostName,
257  const uint nDVBSWFilter,
258  const uint nDVBSatType,
259  bool bDVBWaitForSeqStart,
260  bool bSkipBTAudio,
261  bool bDVBOnDemand,
262  const uint nDVBDiSEqCType,
263  const uint nFirewireSpeed,
264  const QString &sFirewireModel,
265  const uint nFirewireConnection,
266  const uint nSignalTimeout,
267  const uint nChannelTimeout,
268  const uint nDVBTuningDelay,
269  const uint nContrast,
270  const uint nBrightness,
271  const uint nColour,
272  const uint nHue,
273  const uint nDiSEqCId,
274  bool bDVBEITScan)
275 {
276  if ( sVideoDevice.isEmpty() || sCardType.isEmpty() || sHostName.isEmpty() )
277  throw( QString( "This API requires at least a video device node, a card type, "
278  "and a hostname." ));
279 
280  int nResult = CardUtil::CreateCaptureCard(sVideoDevice, sAudioDevice,
281  sVBIDevice, sCardType, nAudioRateLimit,
282  sHostName, nDVBSWFilter, nDVBSatType, bDVBWaitForSeqStart,
283  bSkipBTAudio, bDVBOnDemand, nDVBDiSEqCType, nFirewireSpeed,
284  sFirewireModel, nFirewireConnection, nSignalTimeout,
285  nChannelTimeout, nDVBTuningDelay, nContrast, nBrightness,
286  nColour, nHue, nDiSEqCId, bDVBEITScan);
287 
288  if ( nResult < 1 )
289  throw( QString( "Unable to create capture device." ));
290 
291  return nResult;
292 }
293 
294 bool Capture::UpdateCaptureCard ( int nCardId,
295  const QString &sSetting,
296  const QString &sValue )
297 {
298  if ( nCardId < 1 || sSetting.isEmpty() || sValue.isEmpty() )
299  throw( QString( "Card ID, Setting Name, and Value are required." ));
300 
301  return set_on_input(sSetting, nCardId, sValue);
302 }
303 
304 // Card Inputs
305 
306 bool Capture::RemoveCardInput( int nCardInputId )
307 {
308  if ( nCardInputId < 1 )
309  throw( QString( "The Input ID is invalid."));
310 
311  bool bResult = CardUtil::DeleteInput(nCardInputId);
312 
313  return bResult;
314 }
315 
316 int Capture::AddCardInput ( const uint nCardId,
317  const uint nSourceId,
318  const QString &sInputName,
319  const QString &sExternalCommand,
320  const QString &sChangerDevice,
321  const QString &sChangerModel,
322  const QString &sHostName,
323  const QString &sTuneChan,
324  const QString &sStartChan,
325  const QString &sDisplayName,
326  bool bDishnetEIT,
327  const uint nRecPriority,
328  const uint nQuicktune,
329  const uint nSchedOrder,
330  const uint nLiveTVOrder)
331 {
332  if ( nCardId < 1 || nSourceId < 1 ||
333  sInputName.isEmpty() || sInputName == "None" )
334  throw( QString( "This API requires at least a card ID, a source ID, "
335  "and an input name." ));
336 
337  int nResult = CardUtil::CreateCardInput(nCardId, nSourceId, sInputName,
338  sExternalCommand, sChangerDevice, sChangerModel,
339  sHostName, sTuneChan, sStartChan, sDisplayName,
340  bDishnetEIT, nRecPriority, nQuicktune, nSchedOrder,
341  nLiveTVOrder);
342 
343  return nResult;
344 }
345 
346 bool Capture::UpdateCardInput ( int nCardInputId,
347  const QString &sSetting,
348  const QString &sValue )
349 {
350  if ( nCardInputId < 1 || sSetting.isEmpty() || sValue.isEmpty() )
351  throw( QString( "Input ID, Setting Name, and Value are required." ));
352 
353  return set_on_input(sSetting, nCardInputId, sValue);
354 }
bool next(void)
Wrap QSqlQuery::next() so we can display the query results.
Definition: mythdbcon.cpp:782
void bindValue(const QString &placeholder, const QVariant &val)
Add a single binding.
Definition: mythdbcon.cpp:863
CaptureCard * AddNewCaptureCard()
bool UpdateCaptureCard(int CardId, const QString &Setting, const QString &Value) override
Definition: capture.cpp:294
QSqlQuery wrapper that fetches a DB connection from the connection pool.
Definition: mythdbcon.h:125
DTC::CaptureCardList * GetCaptureCardList(const QString &HostName, const QString &CardType) override
Definition: capture.cpp:44
bool isConnected(void)
Only updated once during object creation.
Definition: mythdbcon.h:135
unsigned int uint
Definition: compat.h:140
bool set_on_input(const QString &to_set, uint inputid, const QString &value)
Definition: cardutil.cpp:1220
bool UpdateCardInput(int CardInputId, const QString &Setting, const QString &Value) override
Definition: capture.cpp:346
QVariant value(int i) const
Definition: mythdbcon.h:198
bool RemoveCardInput(int CardInputId) override
Definition: capture.cpp:306
static bool DeleteInput(uint inputid)
static MSqlQueryInfo InitCon(ConnectionReuse=kNormalConnection)
Only use this in combination with MSqlQuery constructor.
Definition: mythdbcon.cpp:535
bool RemoveCaptureCard(int CardId) override
Definition: capture.cpp:237
int AddCaptureCard(const QString &VideoDevice, const QString &AudioDevice, const QString &VBIDevice, const QString &CardType, uint AudioRateLimit, const QString &HostName, uint DVBSWFilter, uint DVBSatType, bool DVBWaitForSeqStart, bool SkipBTAudio, bool DVBOnDemand, uint DVBDiSEqCType, uint FirewireSpeed, const QString &FirewireModel, uint FirewireConnection, uint SignalTimeout, uint ChannelTimeout, uint DVBTuningDelay, uint Contrast, uint Brightness, uint Colour, uint Hue, uint DiSEqCId, bool DVBEITScan) override
Definition: capture.cpp:251
bool prepare(const QString &query)
QSqlQuery::prepare() is not thread safe in Qt <= 3.3.2.
Definition: mythdbcon.cpp:807
static int CreateCaptureCard(const QString &videodevice, const QString &audiodevice, const QString &vbidevice, const QString &inputtype, const uint audioratelimit, const QString &hostname, const uint dvb_swfilter, const uint dvb_sat_type, bool dvb_wait_for_seqstart, bool skipbtaudio, bool dvb_on_demand, const uint dvb_diseqc_type, const uint firewire_speed, const QString &firewire_model, const uint firewire_connection, const uint signal_timeout, const uint channel_timeout, const uint dvb_tuning_delay, const uint contrast, const uint brightness, const uint colour, const uint hue, const uint diseqcid, bool dvb_eitscan)
DTC::CaptureCard * GetCaptureCard(int CardId) override
Definition: capture.cpp:149
static int CreateCardInput(const uint inputid, const uint sourceid, const QString &inputname, const QString &externalcommand, const QString &changer_device, const QString &changer_model, const QString &hostname, const QString &tunechan, const QString &startchan, const QString &displayname, bool dishnet_eit, const uint recpriority, const uint quicktune, const uint schedorder, const uint livetvorder)
Definition: cardutil.cpp:1750
bool exec(void)
Wrap QSqlQuery::exec() so we can display SQL.
Definition: mythdbcon.cpp:603
static void DBError(const QString &where, const MSqlQuery &query)
Definition: mythdb.cpp:179
int AddCardInput(uint CardId, uint SourceId, const QString &InputName, const QString &ExternalCommand, const QString &ChangerDevice, const QString &ChangerModel, const QString &HostName, const QString &TuneChan, const QString &StartChan, const QString &DisplayName, bool DishnetEIT, uint RecPriority, uint Quicktune, uint SchedOrder, uint LiveTVOrder) override
Definition: capture.cpp:316