MythTV  0.26-pre
capture.cpp
Go to the documentation of this file.
00001 
00002 // Program Name: capture.cpp
00003 // Created     : Sep. 21, 2011
00004 //
00005 // Copyright (c) 2011 Robert McNamara <rmcnamara@mythtv.org>
00006 //
00007 // This library is free software; you can redistribute it and/or
00008 // modify it under the terms of the GNU Lesser General Public
00009 // License as published by the Free Software Foundation; either
00010 // version 2.1 of the License, or at your option any later version of the LGPL.
00011 //
00012 // This library is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015 // Lesser General Public License for more details.
00016 //
00017 // You should have received a copy of the GNU Lesser General Public
00018 // License along with this library.  If not, see <http://www.gnu.org/licenses/>.
00019 //
00021 
00022 #include <QList>
00023 #include <QFile>
00024 #include <QMutex>
00025 
00026 #include "capture.h"
00027 
00028 #include "cardutil.h"
00029 
00030 #include "compat.h"
00031 #include "mythversion.h"
00032 #include "mythcorecontext.h"
00033 #include "mythmiscutil.h"
00034 #include "serviceUtil.h"
00035 
00037 //
00039 
00040 DTC::CaptureCardList* Capture::GetCaptureCardList( const QString &sHostName,
00041                                                    const QString &sCardType )
00042 {
00043     MSqlQuery query(MSqlQuery::InitCon());
00044 
00045     if (!query.isConnected())
00046         throw( QString("Database not open while trying to list "
00047                        "Capture Cards."));
00048 
00049     QString str = "SELECT cardid, videodevice, audiodevice, vbidevice, "
00050                   "cardtype, audioratelimit, hostname, "
00051                   "dvb_swfilter, dvb_sat_type, dvb_wait_for_seqstart, "
00052                   "skipbtaudio, dvb_on_demand, dvb_diseqc_type, "
00053                   "firewire_speed, firewire_model, firewire_connection, "
00054                   "signal_timeout, channel_timeout, dvb_tuning_delay, "
00055                   "contrast, brightness, colour, hue, diseqcid, dvb_eitscan "
00056                   "from capturecard";
00057 
00058     if (!sHostName.isEmpty())
00059         str += " WHERE hostname = :HOSTNAME";
00060     else if (!sCardType.isEmpty())
00061         str += " WHERE cardtype = :CARDTYPE";
00062 
00063     if (!sHostName.isEmpty() && !sCardType.isEmpty())
00064         str += " AND cardtype = :CARDTYPE";
00065 
00066     query.prepare(str);
00067 
00068     if (!sHostName.isEmpty())
00069         query.bindValue(":HOSTNAME", sHostName);
00070     if (!sCardType.isEmpty())
00071         query.bindValue(":CARDTYPE", sCardType);
00072 
00073     if (!query.exec())
00074     {
00075         MythDB::DBError("MythAPI::GetCaptureCardList()", query);
00076         throw( QString( "Database Error executing query." ));
00077     }
00078 
00079     // ----------------------------------------------------------------------
00080     // return the results of the query
00081     // ----------------------------------------------------------------------
00082 
00083     DTC::CaptureCardList* pList = new DTC::CaptureCardList();
00084 
00085     while (query.next())
00086     {
00087 
00088         DTC::CaptureCard *pCaptureCard = pList->AddNewCaptureCard();
00089 
00090         pCaptureCard->setCardId            ( query.value(0).toInt()       );
00091         pCaptureCard->setVideoDevice       ( query.value(1).toString()    );
00092         pCaptureCard->setAudioDevice       ( query.value(2).toString()    );
00093         pCaptureCard->setVBIDevice         ( query.value(3).toString()    );
00094         pCaptureCard->setCardType          ( query.value(4).toString()    );
00095         pCaptureCard->setAudioRateLimit    ( query.value(5).toUInt()      );
00096         pCaptureCard->setHostName          ( query.value(6).toString()    );
00097         pCaptureCard->setDVBSWFilter       ( query.value(7).toUInt()      );
00098         pCaptureCard->setDVBSatType        ( query.value(8).toUInt()      );
00099         pCaptureCard->setDVBWaitForSeqStart( query.value(9).toBool()     );
00100         pCaptureCard->setSkipBTAudio       ( query.value(10).toBool()     );
00101         pCaptureCard->setDVBOnDemand       ( query.value(11).toBool()     );
00102         pCaptureCard->setDVBDiSEqCType     ( query.value(12).toUInt()     );
00103         pCaptureCard->setFirewireSpeed     ( query.value(13).toUInt()     );
00104         pCaptureCard->setFirewireModel     ( query.value(14).toString()   );
00105         pCaptureCard->setFirewireConnection( query.value(15).toUInt()     );
00106         pCaptureCard->setSignalTimeout     ( query.value(16).toUInt()     );
00107         pCaptureCard->setChannelTimeout    ( query.value(17).toUInt()     );
00108         pCaptureCard->setDVBTuningDelay    ( query.value(18).toUInt()     );
00109         pCaptureCard->setContrast          ( query.value(19).toUInt()     );
00110         pCaptureCard->setBrightness        ( query.value(20).toUInt()     );
00111         pCaptureCard->setColour            ( query.value(21).toUInt()     );
00112         pCaptureCard->setHue               ( query.value(22).toUInt()     );
00113         pCaptureCard->setDiSEqCId          ( query.value(23).toUInt()     );
00114         pCaptureCard->setDVBEITScan        ( query.value(24).toBool()     );
00115     }
00116 
00117     return pList;
00118 }
00119 
00121 //
00123 
00124 DTC::CaptureCard* Capture::GetCaptureCard( int nCardId )
00125 {
00126     if ( nCardId < 1 )
00127         throw( QString( "The Card ID is invalid."));
00128 
00129     MSqlQuery query(MSqlQuery::InitCon());
00130 
00131     if (!query.isConnected())
00132         throw( QString("Database not open while trying to list "
00133                        "Capture Cards."));
00134 
00135     QString str = "SELECT cardid, videodevice, audiodevice, vbidevice, "
00136                   "cardtype, audioratelimit, hostname, "
00137                   "dvb_swfilter, dvb_sat_type, dvb_wait_for_seqstart, "
00138                   "skipbtaudio, dvb_on_demand, dvb_diseqc_type, "
00139                   "firewire_speed, firewire_model, firewire_connection, "
00140                   "signal_timeout, channel_timeout, dvb_tuning_delay, "
00141                   "contrast, brightness, colour, hue, diseqcid, dvb_eitscan "
00142                   "from capturecard WHERE cardid = :CARDID";
00143 
00144     query.prepare(str);
00145     query.bindValue(":CARDID", nCardId);
00146 
00147     if (!query.exec())
00148     {
00149         MythDB::DBError("MythAPI::GetCaptureCard()", query);
00150         throw( QString( "Database Error executing query." ));
00151     }
00152 
00153     DTC::CaptureCard* pCaptureCard = new DTC::CaptureCard();
00154 
00155     if (query.next())
00156     {
00157         pCaptureCard->setCardId            ( query.value(0).toInt()       );
00158         pCaptureCard->setVideoDevice       ( query.value(1).toString()    );
00159         pCaptureCard->setAudioDevice       ( query.value(2).toString()    );
00160         pCaptureCard->setVBIDevice         ( query.value(3).toString()    );
00161         pCaptureCard->setCardType          ( query.value(4).toString()    );
00162         pCaptureCard->setAudioRateLimit    ( query.value(5).toUInt()      );
00163         pCaptureCard->setHostName          ( query.value(6).toString()    );
00164         pCaptureCard->setDVBSWFilter       ( query.value(7).toUInt()      );
00165         pCaptureCard->setDVBSatType        ( query.value(8).toUInt()      );
00166         pCaptureCard->setDVBWaitForSeqStart( query.value(9).toBool()     );
00167         pCaptureCard->setSkipBTAudio       ( query.value(10).toBool()     );
00168         pCaptureCard->setDVBOnDemand       ( query.value(11).toBool()     );
00169         pCaptureCard->setDVBDiSEqCType     ( query.value(12).toUInt()     );
00170         pCaptureCard->setFirewireSpeed     ( query.value(13).toUInt()     );
00171         pCaptureCard->setFirewireModel     ( query.value(14).toString()   );
00172         pCaptureCard->setFirewireConnection( query.value(15).toUInt()     );
00173         pCaptureCard->setSignalTimeout     ( query.value(16).toUInt()     );
00174         pCaptureCard->setChannelTimeout    ( query.value(17).toUInt()     );
00175         pCaptureCard->setDVBTuningDelay    ( query.value(18).toUInt()     );
00176         pCaptureCard->setContrast          ( query.value(19).toUInt()     );
00177         pCaptureCard->setBrightness        ( query.value(20).toUInt()     );
00178         pCaptureCard->setColour            ( query.value(21).toUInt()     );
00179         pCaptureCard->setHue               ( query.value(22).toUInt()     );
00180         pCaptureCard->setDiSEqCId          ( query.value(23).toUInt()     );
00181         pCaptureCard->setDVBEITScan        ( query.value(24).toBool()     );
00182     }
00183 
00184     return pCaptureCard;
00185 }
00186 
00188 //
00190 
00191 bool Capture::RemoveCaptureCard( int nCardId )
00192 {
00193     if ( nCardId < 1 )
00194         throw( QString( "The Card ID is invalid."));
00195 
00196     bool bResult = CardUtil::DeleteCard(nCardId);
00197 
00198     return bResult;
00199 }
00200 
00202 //
00204 
00205 int Capture::AddCaptureCard     ( const QString    &sVideoDevice,
00206                                   const QString    &sAudioDevice,
00207                                   const QString    &sVBIDevice,
00208                                   const QString    &sCardType,
00209                                   const uint       nAudioRateLimit,
00210                                   const QString    &sHostName,
00211                                   const uint       nDVBSWFilter,
00212                                   const uint       nDVBSatType,
00213                                   bool             bDVBWaitForSeqStart,
00214                                   bool             bSkipBTAudio,
00215                                   bool             bDVBOnDemand,
00216                                   const uint       nDVBDiSEqCType,
00217                                   const uint       nFirewireSpeed,
00218                                   const QString    &sFirewireModel,
00219                                   const uint       nFirewireConnection,
00220                                   const uint       nSignalTimeout,
00221                                   const uint       nChannelTimeout,
00222                                   const uint       nDVBTuningDelay,
00223                                   const uint       nContrast,
00224                                   const uint       nBrightness,
00225                                   const uint       nColour,
00226                                   const uint       nHue,
00227                                   const uint       nDiSEqCId,
00228                                   bool             bDVBEITScan)
00229 {
00230     if ( sVideoDevice.isEmpty() || sCardType.isEmpty() || sHostName.isEmpty() )
00231         throw( QString( "This API requires at least a video device node, a card type, "
00232                         "and a hostname." ));
00233 
00234     int nResult = CardUtil::CreateCaptureCard(sVideoDevice, sAudioDevice,
00235                       sVBIDevice, sCardType, nAudioRateLimit,
00236                       sHostName, nDVBSWFilter, nDVBSatType, bDVBWaitForSeqStart,
00237                       bSkipBTAudio, bDVBOnDemand, nDVBDiSEqCType, nFirewireSpeed,
00238                       sFirewireModel, nFirewireConnection, nSignalTimeout,
00239                       nChannelTimeout, nDVBTuningDelay, nContrast, nBrightness,
00240                       nColour, nHue, nDiSEqCId, bDVBEITScan);
00241 
00242     if ( nResult < 1 )
00243         throw( QString( "Unable to create capture device." ));
00244 
00245     return nResult;
00246 }
00247 
00248 bool Capture::UpdateCaptureCard  ( int              nCardId,
00249                                    const QString    &sSetting,
00250                                    const QString    &sValue )
00251 {
00252     if ( nCardId < 1 || sSetting.isEmpty() || sValue.isEmpty() )
00253         throw( QString( "Card ID, Setting Name, and Value are required." ));
00254 
00255     return set_on_source(sSetting, nCardId, 0, sValue);
00256 }
00257 
00258 // Card Inputs
00259 
00260 bool Capture::RemoveCardInput( int nCardInputId )
00261 {
00262     if ( nCardInputId < 1 )
00263         throw( QString( "The Input ID is invalid."));
00264 
00265     bool bResult = CardUtil::DeleteInput(nCardInputId);
00266 
00267     return bResult;
00268 }
00269 
00270 int Capture::AddCardInput       ( const uint nCardId,
00271                                   const uint nSourceId,
00272                                   const QString &sInputName,
00273                                   const QString &sExternalCommand,
00274                                   const QString &sChangerDevice,
00275                                   const QString &sChangerModel,
00276                                   const QString &sHostName,
00277                                   const QString &sTuneChan,
00278                                   const QString &sStartChan,
00279                                   const QString &sDisplayName,
00280                                   bool          bDishnetEIT,
00281                                   const uint nRecPriority,
00282                                   const uint nQuicktune,
00283                                   const uint nSchedOrder,
00284                                   const uint nLiveTVOrder)
00285 {
00286     if ( nCardId < 1 || nSourceId < 1 || sInputName.isEmpty() )
00287         throw( QString( "This API requires at least a card ID, a source ID, "
00288                         "and an input name." ));
00289 
00290     int nResult = CardUtil::CreateCardInput(nCardId, nSourceId, sInputName,
00291                       sExternalCommand, sChangerDevice, sChangerModel,
00292                       sHostName, sTuneChan, sStartChan, sDisplayName,
00293                       bDishnetEIT, nRecPriority, nQuicktune, nSchedOrder, 
00294                       nLiveTVOrder);
00295 
00296     return nResult;
00297 }
00298 
00299 bool Capture::UpdateCardInput    ( int              nCardInputId,
00300                                    const QString    &sSetting,
00301                                    const QString    &sValue )
00302 {
00303     if ( nCardInputId < 1 || sSetting.isEmpty() || sValue.isEmpty() )
00304         throw( QString( "Input ID, Setting Name, and Value are required." ));
00305 
00306     return set_on_input(sSetting, nCardInputId, sValue);
00307 }
00308 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends