00001
00002 #ifndef _CARDUTIL_H_
00003 #define _CARDUTIL_H_
00004
00005
00006 #include <stdint.h>
00007
00008
00009 #include <vector>
00010 using namespace std;
00011
00012
00013 #include <QStringList>
00014 #include <QMap>
00015
00016
00017 #include "settings.h"
00018 #include "mythtvexp.h"
00019
00020 class InputInfo;
00021 class CardInput;
00022 typedef QMap<int,QString> InputNames;
00023
00024 MTV_PUBLIC QString get_on_cardid(const QString&, uint);
00025
00026 MTV_PUBLIC bool set_on_source(const QString&, uint, uint, const QString);
00027
00028 MTV_PUBLIC QString get_on_inputid(const QString&, uint);
00029
00030 MTV_PUBLIC bool set_on_input(const QString&, uint, const QString);
00031
00032 typedef enum
00033 {
00034 DVB_DEV_FRONTEND = 1,
00035 DVB_DEV_DVR,
00036 DVB_DEV_DEMUX,
00037 DVB_DEV_CA,
00038 DVB_DEV_AUDIO,
00039 DVB_DEV_VIDEO,
00040 } dvb_dev_type_t;
00041
00045 class MTV_PUBLIC CardUtil
00046 {
00047 public:
00049 enum CARD_TYPES
00050 {
00051 ERROR_OPEN = 0,
00052 ERROR_UNKNOWN = 1,
00053 ERROR_PROBE = 2,
00054 QPSK = 3, DVBS = 3,
00055 QAM = 4, DVBC = 4,
00056 OFDM = 5, DVBT = 5,
00057 ATSC = 6,
00058 V4L = 7,
00059 MPEG = 8,
00060 FIREWIRE = 9,
00061 HDHOMERUN = 10,
00062 FREEBOX = 11,
00063 HDPVR = 12,
00064 DVBS2 = 13,
00065 IMPORT = 14,
00066 DEMO = 15,
00067 ASI = 16,
00068 CETON = 17,
00069 };
00070
00071 static enum CARD_TYPES toCardType(const QString &name)
00072 {
00073 if ("ERROR_OPEN" == name)
00074 return ERROR_OPEN;
00075 if ("ERROR_UNKNOWN" == name)
00076 return ERROR_UNKNOWN;
00077 if ("ERROR_PROBE" == name)
00078 return ERROR_PROBE;
00079 if ("QPSK" == name)
00080 return QPSK;
00081 if ("QAM" == name)
00082 return QAM;
00083 if ("OFDM" == name)
00084 return OFDM;
00085 if ("ATSC" == name)
00086 return ATSC;
00087 if ("V4L" == name)
00088 return V4L;
00089 if ("MPEG" == name)
00090 return MPEG;
00091 if ("FIREWIRE" == name)
00092 return FIREWIRE;
00093 if ("HDHOMERUN" == name)
00094 return HDHOMERUN;
00095 if ("FREEBOX" == name)
00096 return FREEBOX;
00097 if ("HDPVR" == name)
00098 return HDPVR;
00099 if ("DVB_S2" == name)
00100 return DVBS2;
00101 if ("IMPORT" == name)
00102 return IMPORT;
00103 if ("DEMO" == name)
00104 return DEMO;
00105 if ("ASI" == name)
00106 return ASI;
00107 if ("CETON" == name)
00108 return CETON;
00109 return ERROR_UNKNOWN;
00110 }
00111
00112 static bool IsEncoder(const QString &rawtype)
00113 {
00114 return
00115 (rawtype != "DVB") && (rawtype != "FIREWIRE") &&
00116 (rawtype != "HDHOMERUN") && (rawtype != "FREEBOX") &&
00117 (rawtype != "IMPORT") && (rawtype != "DEMO") &&
00118 (rawtype != "ASI") && (rawtype != "CETON");
00119 }
00120
00121 static bool IsV4L(const QString &rawtype)
00122 {
00123 return (rawtype == "V4L" || rawtype == "MPEG" ||
00124 rawtype == "HDPVR" || rawtype == "GO7007" ||
00125 rawtype == "MJPEG");
00126 }
00127
00128 static bool IsChannelChangeDiscontinuous(const QString &rawtype)
00129 {
00130 return !IsEncoder(rawtype) || (rawtype == "HDPVR");
00131 }
00132
00133 static bool IsUnscanable(const QString &rawtype)
00134 {
00135 return
00136 (rawtype == "FIREWIRE") || (rawtype == "HDPVR") ||
00137 (rawtype == "IMPORT") || (rawtype == "DEMO") ||
00138 (rawtype == "GO7007") || (rawtype == "MJPEG");
00139 }
00140 static QString GetScanableCardTypes(void);
00141
00142 static bool IsCableCardPresent(uint cardid,
00143 const QString &cardType);
00144
00145 static bool IsEITCapable(const QString &rawtype)
00146 {
00147 return
00148 (rawtype == "DVB") || (rawtype == "HDHOMERUN");
00149 }
00150
00151 static bool IsTunerSharingCapable(const QString &rawtype)
00152 {
00153 return
00154 (rawtype == "DVB") || (rawtype == "HDHOMERUN") ||
00155 (rawtype == "ASI");
00156 }
00157
00158 static bool IsTunerShared(uint cardidA, uint cardidB);
00159
00160 static bool IsTuningDigital(const QString &rawtype)
00161 {
00162 return
00163 (rawtype == "DVB") || (rawtype == "HDHOMERUN") ||
00164 (rawtype == "ASI") || (rawtype == "CETON");
00165 }
00166
00167 static bool IsTuningAnalog(const QString &rawtype)
00168 {
00169 return
00170 (rawtype == "V4L") || (rawtype == "MPEG");
00171 }
00172
00173 static bool IsTuningVirtual(const QString &rawtype)
00174 {
00175 return
00176 (rawtype == "FIREWIRE") || (rawtype == "HDPVR");
00177 }
00178
00179 static bool IsSingleInputCard(const QString &rawtype)
00180 {
00181 return
00182 (rawtype == "FIREWIRE") || (rawtype == "HDHOMERUN") ||
00183 (rawtype == "FREEBOX") || (rawtype == "ASI") ||
00184 (rawtype == "IMPORT") || (rawtype == "DEMO") ||
00185 (rawtype == "CETON");
00186 }
00187
00188
00189
00190 static int CreateCaptureCard(const QString &videodevice,
00191 const QString &audiodevice,
00192 const QString &vbidevice,
00193 const QString &cardtype,
00194 const uint audioratelimit,
00195 const QString &hostname,
00196 const uint dvb_swfilter,
00197 const uint dvb_sat_type,
00198 bool dvb_wait_for_seqstart,
00199 bool skipbtaudio,
00200 bool dvb_on_demand,
00201 const uint dvb_diseqc_type,
00202 const uint firewire_speed,
00203 const QString &firewire_model,
00204 const uint firewire_connection,
00205 const uint signal_timeout,
00206 const uint channel_timeout,
00207 const uint dvb_tuning_delay,
00208 const uint contrast,
00209 const uint brightness,
00210 const uint colour,
00211 const uint hue,
00212 const uint diseqcid,
00213 bool dvb_eitscan);
00214
00215 static bool DeleteCard(uint cardid);
00216 static bool DeleteAllCards(void);
00217 static vector<uint> GetCardList(void);
00218
00220 static uint GetFirstCardID(const QString &videodevice)
00221 {
00222 vector<uint> list = GetCardIDs(videodevice);
00223 if (list.empty())
00224 return 0;
00225 return list[0];
00226 }
00227
00228 static vector<uint> GetCardIDs(QString videodevice = QString::null,
00229 QString rawtype = QString::null,
00230 QString hostname = QString::null);
00231
00232 static bool IsCardTypePresent(const QString &rawtype,
00233 QString hostname = QString::null);
00234 static QStringList GetCardTypes(void);
00235
00236 static QStringList GetVideoDevices(const QString &rawtype,
00237 QString hostname = QString::null);
00238
00239 static QString GetRawCardType(uint cardid)
00240 { return get_on_cardid("cardtype", cardid).toUpper(); }
00241 static QString GetVideoDevice(uint cardid)
00242 { return get_on_cardid("videodevice", cardid); }
00243 static QString GetAudioDevice(uint cardid)
00244 { return get_on_cardid("audiodevice", cardid); }
00245 static QString GetVBIDevice(uint cardid)
00246 { return get_on_cardid("vbidevice", cardid); }
00247
00248 static int GetValueInt(const QString &col, uint cid)
00249 { return get_on_cardid(col, cid).toInt(); }
00250 static bool SetValue(const QString &col, uint cid,
00251 uint sid, int val)
00252 { return set_on_source(col, cid, sid, QString::number(val)); }
00253 static bool SetValue(const QString &col, uint cid,
00254 uint sid, const QString &val)
00255 { return set_on_source(col, cid, sid, val); }
00256
00257 static int GetCardInputID(uint cardid, const QString &channum,
00258 QString &inputname);
00259 static bool SetStartChannel(uint cardinputid,
00260 const QString &channum);
00261
00262
00263 static int CreateCardInput(const uint cardid,
00264 const uint sourceid,
00265 const QString &inputname,
00266 const QString &externalcommand,
00267 const QString &changer_device,
00268 const QString &changer_model,
00269 const QString &hostname,
00270 const QString &tunechan,
00271 const QString &startchan,
00272 const QString &displayname,
00273 bool dishnet_eit,
00274 const uint recpriority,
00275 const uint quicktune,
00276 const uint schedorder,
00277 const uint livetvorder);
00278
00279 static bool DeleteInput(uint inputid);
00280
00281
00282
00283 static vector<uint> GetCardIDs(uint sourceid);
00284 static QString GetStartInput(uint cardid);
00285 static QStringList GetInputNames(uint cardid, uint sourceid = 0);
00286 static bool GetInputInfo(InputInfo &info,
00287 vector<uint> *groupids = NULL);
00288 static uint GetCardID(uint inputid);
00289 static QString GetInputName(uint inputid);
00290 static QString GetStartingChannel(uint inputid);
00291 static QString GetDisplayName(uint inputid);
00292 static QString GetDisplayName(uint cardid, const QString &inputname)
00293 { return GetDisplayName(GetInputID(cardid, inputname)); }
00294 static QString GetDisplayName(uint cardid, uint sourceid)
00295 { return GetDisplayName(GetInputID(cardid, sourceid)); }
00296 static vector<uint> GetAllInputIDs(void);
00297 static vector<uint> GetInputIDs(uint cardid);
00298 static uint GetInputID(uint cardid, const QString &inputname);
00299 static uint GetInputID(uint cardid, uint sourceid);
00300 static uint GetSourceID(uint inputid);
00301 static bool DeleteOrphanInputs(void);
00302
00303 static bool SetInputValue(const QString &col, uint iid,
00304 int val)
00305 { return set_on_input(col, iid, QString::number(val)); }
00306 static bool SetInputValue(const QString &col, uint iid,
00307 const QString &val)
00308 { return set_on_input(col, iid, val); }
00309
00310
00311 static uint CreateInputGroup(const QString &name);
00312 static bool CreateInputGroupIfNeeded(uint cardid);
00313 static bool LinkInputGroup(uint inputid, uint inputgroupid);
00314 static bool UnlinkInputGroup(uint inputid, uint inputgroupid);
00315 static vector<uint> GetInputGroups(uint inputid);
00316 static vector<uint> GetSharedInputGroups(uint cardid);
00317 static vector<uint> GetGroupCardIDs(uint inputgroupid);
00318 static vector<uint> GetConflictingCards(uint inputid, uint exclude_cardid);
00319
00320 static QString GetDeviceLabel(const QString &cardtype,
00321 const QString &videodevice);
00322 static QString GetDeviceLabel(uint cardid);
00323
00324 static QString ProbeSubTypeName(uint cardid);
00325
00326 static QStringList ProbeVideoInputs(QString device,
00327 QString cardtype = QString::null);
00328 static QStringList ProbeAudioInputs(QString device,
00329 QString cardtype = QString::null);
00330 static void GetCardInputs(uint cardid,
00331 const QString &device,
00332 const QString &cardtype,
00333 QStringList &inputLabels,
00334 vector<CardInput*> &cardInputs);
00335
00336
00337 static QStringList ProbeVideoDevices(const QString &rawtype);
00338
00339
00340 static bool CloneCard(uint src_cardid, uint dst_cardid);
00341 static vector<uint> GetCloneCardIDs(uint cardid);
00342 static QString GetFirewireChangerNode(uint inputid);
00343 static QString GetFirewireChangerModel(uint inputid);
00344
00345
00346 static bool GetTimeouts(uint cardid,
00347 uint &signal_timeout,
00348 uint &channel_timeout);
00349 static bool IgnoreEncrypted(uint cardid, const QString &inputname);
00350 static bool TVOnly(uint cardid, const QString &inputname);
00351 static bool IsInNeedOfExternalInputConf(uint cardid);
00352 static uint GetQuickTuning(uint cardid, const QString &inputname);
00353
00354
00356 static bool IsDVB(uint cardid)
00357 { return "DVB" == GetRawCardType(cardid); }
00358 static bool IsDVBCardType(const QString &card_type);
00359 static QString ProbeDVBFrontendName(const QString &device);
00360 static QString ProbeDVBType(const QString &device);
00361 static bool HasDVBCRCBug(const QString &device);
00362 static uint GetMinSignalMonitoringDelay(const QString &device);
00363 static QString GetDeviceName(dvb_dev_type_t, const QString &device);
00364 static InputNames GetConfiguredDVBInputs(uint cardid);
00365
00366
00367 static bool hasV4L2(int videofd);
00368 static bool GetV4LInfo(int videofd, QString &card, QString &driver,
00369 uint32_t &version, uint32_t &capabilities);
00370 static bool GetV4LInfo(int videofd, QString &card, QString &driver)
00371 { uint32_t d1,d2; return GetV4LInfo(videofd, card, driver, d1, d2); }
00372 static InputNames ProbeV4LVideoInputs(int videofd, bool &ok);
00373 static InputNames ProbeV4LAudioInputs(int videofd, bool &ok);
00374
00375
00376 static bool HDHRdoesDVB(const QString &device);
00377 static QString GetHDHRdesc(const QString &device);
00378
00379
00380 static int GetASIDeviceNumber(const QString &device,
00381 QString *error = NULL);
00382
00383 static uint GetASIBufferSize(uint device_num,
00384 QString *error = NULL);
00385 static int GetASIMode(uint device_num,
00386 QString *error = NULL);
00387 static bool SetASIMode(uint device_num, uint mode,
00388 QString *error = NULL);
00389
00390 private:
00391 static QStringList ProbeV4LVideoInputs(QString device);
00392 static QStringList ProbeV4LAudioInputs(QString device);
00393 static QStringList ProbeDVBInputs(QString device);
00394 };
00395
00396 #endif //_CARDUTIL_H_