/
videosource.cpp
3867 lines (3303 loc) · 117 KB
/
videosource.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// -*- Mode: c++ -*-
// Standard UNIX C headers
#include <unistd.h>
#include <fcntl.h>
#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__OpenBSD__) || defined(_WIN32)
#include <sys/types.h>
#else
#include <sys/sysmacros.h>
#endif
#include <sys/stat.h>
// C++ headers
#include <algorithm>
using namespace std;
// Qt headers
#include <QCoreApplication>
#include <QCursor>
#include <QDateTime>
#include <QDir>
#include <QFile>
#include <QLayout>
#include <QMap>
#include <QStringList>
#include <QTextStream>
#include <utility>
// MythTV headers
#include "mythconfig.h"
#include "mythcorecontext.h"
#include "videosource.h"
#include "scanwizard.h"
#include "cardutil.h"
#include "sourceutil.h"
#include "channelinfo.h"
#include "channelutil.h"
#include "frequencies.h"
#include "diseqcsettings.h"
#include "firewiredevice.h"
#include "compat.h"
#include "mythdb.h"
#include "mythdirs.h"
#include "mythlogging.h"
#include "libmythupnp/httprequest.h" // for TestMimeType()
#include "mythsystemlegacy.h"
#include "exitcodes.h"
#include "v4l2util.h"
#include "mythnotification.h"
#include "mythterminal.h"
#ifdef USING_DVB
#include "dvbtypes.h"
#endif
#ifdef USING_VBOX
#include "vboxutils.h"
#endif
#ifdef USING_HDHOMERUN
#include HDHOMERUN_HEADERFILE
#endif
static const uint kDefaultMultirecCount = 2;
VideoSourceSelector::VideoSourceSelector(uint _initial_sourceid,
const QString &_card_types,
bool _must_have_mplexid) :
m_initialSourceId(_initial_sourceid),
m_cardTypes(_card_types),
m_mustHaveMplexId(_must_have_mplexid)
{
setLabel(tr("Video Source"));
}
void VideoSourceSelector::Load(void)
{
MSqlQuery query(MSqlQuery::InitCon());
QString querystr =
"SELECT DISTINCT videosource.name, videosource.sourceid "
"FROM capturecard, videosource";
querystr += (m_mustHaveMplexId) ? ", channel " : " ";
querystr +=
"WHERE capturecard.sourceid = videosource.sourceid AND "
" capturecard.hostname = :HOSTNAME ";
if (!m_cardTypes.isEmpty())
{
querystr += QString(" AND capturecard.cardtype in %1 ")
.arg(m_cardTypes);
}
if (m_mustHaveMplexId)
{
querystr +=
" AND channel.sourceid = videosource.sourceid "
" AND channel.mplexid != 32767 "
" AND channel.mplexid != 0 ";
}
query.prepare(querystr);
query.bindValue(":HOSTNAME", gCoreContext->GetHostName());
if (!query.exec() || !query.isActive() || query.size() <= 0)
return;
uint sel = 0, cnt = 0;
for (; query.next(); cnt++)
{
addSelection(query.value(0).toString(),
query.value(1).toString());
sel = (query.value(1).toUInt() == m_initialSourceId) ? cnt : sel;
}
if (m_initialSourceId)
{
if (cnt)
setValue(sel);
setEnabled(false);
}
TransMythUIComboBoxSetting::Load();
}
class InstanceCount : public MythUISpinBoxSetting
{
public:
InstanceCount(const CardInput &parent, int _initValue) :
MythUISpinBoxSetting(new CardInputDBStorage(this, parent, "reclimit"),
1, 10, 1)
{
setLabel(QObject::tr("Max recordings"));
setValue(_initValue);
setHelpText(
QObject::tr(
"Maximum number of simultaneous recordings MythTV will "
"attempt using this device. If set to a value other than "
"1, MythTV can sometimes record multiple programs on "
"the same multiplex or overlapping copies of the same "
"program on a single channel."
));
};
};
class SchedGroup : public MythUICheckBoxSetting
{
public:
explicit SchedGroup(const CardInput &parent) :
MythUICheckBoxSetting(new CardInputDBStorage(this, parent, "schedgroup"))
{
setLabel(QObject::tr("Schedule as group"));
setValue(true);
setHelpText(
QObject::tr(
"Schedule all virtual inputs on this device as a group. "
"This is more efficient than scheduling each input "
"individually. Additional, virtual inputs will be "
"automatically added as needed to fulfill the recording "
"load."
));
};
};
QString VideoSourceDBStorage::GetWhereClause(MSqlBindings &bindings) const
{
QString sourceidTag(":WHERESOURCEID");
QString query("sourceid = " + sourceidTag);
bindings.insert(sourceidTag, m_parent.getSourceID());
return query;
}
QString VideoSourceDBStorage::GetSetClause(MSqlBindings& bindings) const
{
QString sourceidTag(":SETSOURCEID");
QString colTag(":SET" + GetColumnName().toUpper());
QString query("sourceid = " + sourceidTag + ", " +
GetColumnName() + " = " + colTag);
bindings.insert(sourceidTag, m_parent.getSourceID());
bindings.insert(colTag, m_user->GetDBValue());
return query;
}
QString CaptureCardDBStorage::GetWhereClause(MSqlBindings& bindings) const
{
QString cardidTag(":WHERECARDID");
QString query("cardid = " + cardidTag);
bindings.insert(cardidTag, m_parent.getCardID());
return query;
}
QString CaptureCardDBStorage::GetSetClause(MSqlBindings& bindings) const
{
QString cardidTag(":SETCARDID");
QString colTag(":SET" + GetColumnName().toUpper());
QString query("cardid = " + cardidTag + ", " +
GetColumnName() + " = " + colTag);
bindings.insert(cardidTag, m_parent.getCardID());
bindings.insert(colTag, m_user->GetDBValue());
return query;
}
class XMLTVGrabber : public MythUIComboBoxSetting
{
public:
explicit XMLTVGrabber(const VideoSource &parent) :
MythUIComboBoxSetting(new VideoSourceDBStorage(this, parent,
"xmltvgrabber")),
m_parent(parent)
{
setLabel(QObject::tr("Listings grabber"));
};
void Load(void) override // StandardSetting
{
addTargetedChild("eitonly", new EITOnly_config(m_parent, this));
addTargetedChild("/bin/true", new NoGrabber_config(m_parent));
addSelection(
QObject::tr("Transmitted guide only (EIT)"), "eitonly");
addSelection(QObject::tr("No grabber"), "/bin/true");
QString gname, d1, d2, d3;
SourceUtil::GetListingsLoginData(m_parent.getSourceID(), gname, d1, d2, d3);
#ifdef _MSC_VER
#pragma message( "tv_find_grabbers is not supported yet on windows." )
//-=>TODO:Screen doesn't show up if the call to MythSysemLegacy is executed
#else
QString loc = "XMLTVGrabber::Load: ";
QString loc_err = "XMLTVGrabber::Load, Error: ";
QStringList name_list;
QStringList prog_list;
QStringList args;
args += "baseline";
MythSystemLegacy find_grabber_proc("tv_find_grabbers", args,
kMSStdOut | kMSRunShell);
find_grabber_proc.Run(25);
LOG(VB_GENERAL, LOG_INFO,
loc + "Running 'tv_find_grabbers " + args.join(" ") + "'.");
uint status = find_grabber_proc.Wait();
if (status == GENERIC_EXIT_OK)
{
QTextStream ostream(find_grabber_proc.ReadAll());
while (!ostream.atEnd())
{
QString grabber_list(ostream.readLine());
QStringList grabber_split =
grabber_list.split("|", QString::SkipEmptyParts);
QString grabber_name = grabber_split[1] + " (xmltv)";
QFileInfo grabber_file(grabber_split[0]);
name_list.push_back(grabber_name);
prog_list.push_back(grabber_file.fileName());
LOG(VB_GENERAL, LOG_DEBUG, "Found " + grabber_split[0]);
}
LOG(VB_GENERAL, LOG_INFO, loc + "Finished running tv_find_grabbers");
}
else
LOG(VB_GENERAL, LOG_ERR, loc + "Failed to run tv_find_grabbers");
LoadXMLTVGrabbers(name_list, prog_list);
MythUIComboBoxSetting::Load();
#endif
}
void Save(void) override // StandardSetting
{
MythUIComboBoxSetting::Save();
MSqlQuery query(MSqlQuery::InitCon());
query.prepare(
"UPDATE videosource "
"SET userid=NULL, password=NULL "
"WHERE xmltvgrabber NOT IN ( 'technovera' )");
if (!query.exec())
MythDB::DBError("XMLTVGrabber::Save", query);
}
void LoadXMLTVGrabbers(QStringList name_list, QStringList prog_list)
{
if (name_list.size() != prog_list.size())
return;
QString selValue = getValue();
int selIndex = getValueIndex(selValue);
setValue(0);
for (uint i = 0; i < (uint) name_list.size(); i++)
{
addTargetedChild(prog_list[i],
new XMLTV_generic_config(m_parent, prog_list[i],
this));
addSelection(name_list[i], prog_list[i]);
}
if (!selValue.isEmpty())
selIndex = getValueIndex(selValue);
if (selIndex >= 0)
setValue(selIndex);
}
private:
const VideoSource &m_parent;
};
class CaptureCardSpinBoxSetting : public MythUISpinBoxSetting
{
public:
CaptureCardSpinBoxSetting(const CaptureCard &parent,
uint min_val, uint max_val, uint step,
const QString &setting) :
MythUISpinBoxSetting(new CaptureCardDBStorage(this, parent, setting),
min_val, max_val, step)
{
}
};
class CaptureCardTextEditSetting : public MythUITextEditSetting
{
public:
CaptureCardTextEditSetting(const CaptureCard &parent,
const QString &setting) :
MythUITextEditSetting(new CaptureCardDBStorage(this, parent, setting))
{
}
};
class DVBNetID : public MythUISpinBoxSetting
{
public:
DVBNetID(const VideoSource &parent, signed int value, signed int min_val) :
MythUISpinBoxSetting(new VideoSourceDBStorage(this, parent, "dvb_nit_id"),
min_val, 0xffff, 1)
{
setLabel(QObject::tr("Network ID"));
//: Network_ID is the name of an identifier in the DVB's Service
//: Information standard specification.
setHelpText(QObject::tr("If your provider has asked you to configure a "
"specific network identifier (Network_ID), "
"enter it here. Leave it at -1 otherwise."));
setValue(value);
};
};
FreqTableSelector::FreqTableSelector(const VideoSource &parent) :
MythUIComboBoxSetting(new VideoSourceDBStorage(this, parent, "freqtable"))
{
setLabel(QObject::tr("Channel frequency table"));
addSelection("default");
for (uint i = 0; chanlists[i].name; i++)
addSelection(chanlists[i].name);
setHelpText(QObject::tr("Use default unless this source uses a "
"different frequency table than the system wide table "
"defined in the General settings."));
}
TransFreqTableSelector::TransFreqTableSelector(uint _sourceid) :
m_sourceId(_sourceid)
{
setLabel(QObject::tr("Channel frequency table"));
for (uint i = 0; chanlists[i].name; i++)
addSelection(chanlists[i].name);
}
void TransFreqTableSelector::Load(void)
{
int idx1 = getValueIndex(gCoreContext->GetSetting("FreqTable"));
if (idx1 >= 0)
setValue(idx1);
if (!m_sourceId)
return;
MSqlQuery query(MSqlQuery::InitCon());
query.prepare(
"SELECT freqtable "
"FROM videosource "
"WHERE sourceid = :SOURCEID");
query.bindValue(":SOURCEID", m_sourceId);
if (!query.exec() || !query.isActive())
{
MythDB::DBError("TransFreqTableSelector::load", query);
return;
}
m_LoadedFreqTable.clear();
if (query.next())
{
m_LoadedFreqTable = query.value(0).toString();
if (!m_LoadedFreqTable.isEmpty() &&
(m_LoadedFreqTable.toLower() != "default"))
{
int idx2 = getValueIndex(m_LoadedFreqTable);
if (idx2 >= 0)
setValue(idx2);
}
}
}
void TransFreqTableSelector::Save(void)
{
LOG(VB_GENERAL, LOG_INFO, "TransFreqTableSelector::Save(void)");
if ((m_LoadedFreqTable == getValue()) ||
((m_LoadedFreqTable.toLower() == "default") &&
(getValue() == gCoreContext->GetSetting("FreqTable"))))
{
return;
}
MSqlQuery query(MSqlQuery::InitCon());
query.prepare(
"UPDATE videosource "
"SET freqtable = :FREQTABLE "
"WHERE sourceid = :SOURCEID");
query.bindValue(":FREQTABLE", getValue());
query.bindValue(":SOURCEID", m_sourceId);
if (!query.exec() || !query.isActive())
{
MythDB::DBError("TransFreqTableSelector::load", query);
return;
}
}
void TransFreqTableSelector::SetSourceID(uint _sourceid)
{
m_sourceId = _sourceid;
Load();
}
class UseEIT : public MythUICheckBoxSetting
{
public:
explicit UseEIT(const VideoSource &parent) :
MythUICheckBoxSetting(new VideoSourceDBStorage(this, parent, "useeit"))
{
setLabel(QObject::tr("Perform EIT scan"));
setHelpText(QObject::tr(
"If enabled, program guide data for channels on this "
"source will be updated with data provided by the "
"channels themselves 'Over-the-Air'."));
}
};
XMLTV_generic_config::XMLTV_generic_config(const VideoSource& _parent,
const QString& _grabber,
StandardSetting *_setting) :
m_parent(_parent), m_grabber(_grabber)
{
setVisible(false);
QString filename = QString("%1/%2.xmltv")
.arg(GetConfDir()).arg(m_parent.getSourceName());
m_grabberArgs.push_back("--config-file");
m_grabberArgs.push_back(filename);
m_grabberArgs.push_back("--configure");
_setting->addTargetedChild(_grabber, new UseEIT(m_parent));
ButtonStandardSetting *config = new ButtonStandardSetting(tr("Configure"));
config->setHelpText(tr("Run XMLTV configure command."));
_setting->addTargetedChild(_grabber, config);
connect(config, SIGNAL(clicked()), SLOT(RunConfig()));
}
void XMLTV_generic_config::Save()
{
GroupSetting::Save();
#if 0
QString err_msg = QObject::tr(
"You MUST run 'mythfilldatabase --manual' the first time,\n"
"instead of just 'mythfilldatabase'.\nYour grabber does not provide "
"channel numbers, so you have to set them manually.");
if (is_grabber_external(m_grabber))
{
LOG(VB_GENERAL, LOG_ERR, err_msg);
ShowOkPopup(err_msg);
}
#endif
}
void XMLTV_generic_config::RunConfig(void)
{
MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
MythScreenType *ssd =
new MythTerminal(mainStack, m_grabber, m_grabberArgs);
if (ssd->Create())
mainStack->AddScreen(ssd);
else
delete ssd;
}
EITOnly_config::EITOnly_config(const VideoSource& _parent, StandardSetting *_setting)
{
setVisible(false);
m_useeit = new UseEIT(_parent);
m_useeit->setValue(true);
m_useeit->setVisible(false);
addChild(m_useeit);
TransTextEditSetting *label;
label=new TransTextEditSetting();
label->setValue(QObject::tr("Use only the transmitted guide data."));
label->setHelpText(
QObject::tr("This will usually only work with ATSC or DVB channels, "
"and generally provides data only for the next few days."));
_setting->addTargetedChild("eitonly", label);
}
void EITOnly_config::Save(void)
{
// Force this value on
m_useeit->setValue(true);
m_useeit->Save();
}
NoGrabber_config::NoGrabber_config(const VideoSource& _parent)
{
m_useeit = new UseEIT(_parent);
m_useeit->setValue(false);
m_useeit->setVisible(false);
addChild(m_useeit);
TransTextEditSetting *label = new TransTextEditSetting();
label->setValue(QObject::tr("Do not configure a grabber"));
addTargetedChild("/bin/true", label);
}
void NoGrabber_config::Save(void)
{
m_useeit->setValue(false);
m_useeit->Save();
}
VideoSource::VideoSource()
{
// must be first
m_id = new ID();
addChild(m_id = new ID());
setLabel(QObject::tr("Video Source Setup"));
addChild(m_name = new Name(*this));
addChild(new XMLTVGrabber(*this));
addChild(new FreqTableSelector(*this));
addChild(new DVBNetID(*this, -1, -1));
}
bool VideoSource::canDelete(void)
{
return true;
}
void VideoSource::deleteEntry(void)
{
SourceUtil::DeleteSource(getSourceID());
}
bool VideoSourceEditor::cardTypesInclude(const int &sourceID,
const QString &thecardtype)
{
MSqlQuery query(MSqlQuery::InitCon());
query.prepare("SELECT count(cardtype)"
" FROM capturecard "
" WHERE capturecard.sourceid = :SOURCEID "
" AND capturecard.cardtype = :CARDTYPE ;");
query.bindValue(":SOURCEID", sourceID);
query.bindValue(":CARDTYPE", thecardtype);
if (query.exec() && query.next())
{
int count = query.value(0).toInt();
if (count > 0)
return true;
}
return false;
}
void VideoSource::fillSelections(GroupSetting* setting)
{
MSqlQuery result(MSqlQuery::InitCon());
result.prepare("SELECT name, sourceid FROM videosource;");
if (result.exec() && result.isActive() && result.size() > 0)
{
while (result.next())
{
VideoSource* source = new VideoSource();
source->setLabel(result.value(0).toString());
source->loadByID(result.value(1).toInt());
setting->addChild(source);
}
}
}
void VideoSource::fillSelections(MythUIComboBoxSetting* setting)
{
MSqlQuery result(MSqlQuery::InitCon());
result.prepare("SELECT name, sourceid FROM videosource;");
if (result.exec() && result.isActive() && result.size() > 0)
{
while (result.next())
{
setting->addSelection(result.value(0).toString(),
result.value(1).toString());
}
}
}
void VideoSource::loadByID(int sourceid)
{
m_id->setValue(sourceid);
}
class VideoDevice : public CaptureCardComboBoxSetting
{
public:
VideoDevice(const CaptureCard &parent,
uint minor_min = 0,
uint minor_max = UINT_MAX,
const QString& card = QString(),
const QString& driver = QString()) :
CaptureCardComboBoxSetting(parent, true, "videodevice")
{
setLabel(QObject::tr("Video device"));
// /dev/v4l/video*
QDir dev("/dev/v4l", "video*", QDir::Name, QDir::System);
fillSelectionsFromDir(dev, minor_min, minor_max,
card, driver, false);
// /dev/video*
dev.setPath("/dev");
fillSelectionsFromDir(dev, minor_min, minor_max,
card, driver, false);
// /dev/dtv/video*
dev.setPath("/dev/dtv");
fillSelectionsFromDir(dev, minor_min, minor_max,
card, driver, false);
// /dev/dtv*
dev.setPath("/dev");
dev.setNameFilters(QStringList("dtv*"));
fillSelectionsFromDir(dev, minor_min, minor_max,
card, driver, false);
};
/**
* \param dir The directory to open and search for devices.
* \param absPath Ignored. The function always uses absolute paths.
*/
void fillSelectionsFromDir(const QDir &dir, bool absPath = true)
{
// Needed to make both compiler and doxygen happy.
(void) absPath;
fillSelectionsFromDir(dir, 0, 255, QString(), QString(), false);
}
uint fillSelectionsFromDir(const QDir& dir,
uint minor_min, uint minor_max,
const QString& card, const QString& driver,
bool allow_duplicates)
{
uint cnt = 0;
QFileInfoList il = dir.entryInfoList();
QRegExp *driverExp = nullptr;
if (!driver.isEmpty())
driverExp = new QRegExp(driver);
for( QFileInfoList::iterator it = il.begin();
it != il.end();
++it )
{
QFileInfo &fi = *it;
struct stat st;
QString filepath = fi.absoluteFilePath();
int err = lstat(filepath.toLocal8Bit().constData(), &st);
if (err)
{
LOG(VB_GENERAL, LOG_ERR,
QString("Could not stat file: %1").arg(filepath));
continue;
}
// is this is a character device?
if (!S_ISCHR(st.st_mode))
continue;
// is this device is in our minor range?
uint minor_num = minor(st.st_rdev);
if (minor_min > minor_num || minor_max < minor_num)
continue;
// ignore duplicates if allow_duplicates not set
if (!allow_duplicates && m_minorList[minor_num])
continue;
// if the driver returns any info add this device to our list
QByteArray tmp = filepath.toLatin1();
int videofd = open(tmp.constData(), O_RDWR);
if (videofd >= 0)
{
QString card_name, driver_name;
if (CardUtil::GetV4LInfo(videofd, card_name, driver_name) &&
(!driverExp || (driverExp->exactMatch(driver_name))) &&
(card.isEmpty() || (card_name == card)))
{
addSelection(filepath);
cnt++;
}
close(videofd);
}
// add to list of minors discovered to avoid duplicates
m_minorList[minor_num] = 1;
}
delete driverExp;
return cnt;
}
QString Driver(void) const { return m_driverName; }
QString Card(void) const { return m_cardName; }
private:
QMap<uint, uint> m_minorList;
QString m_cardName;
QString m_driverName;
};
class VBIDevice : public CaptureCardComboBoxSetting
{
public:
explicit VBIDevice(const CaptureCard &parent) :
CaptureCardComboBoxSetting(parent, true /*, mustexist true */,
"vbidevice")
{
setLabel(QObject::tr("VBI device"));
setFilter(QString(), QString());
setHelpText(QObject::tr("Device to read VBI (captions) from."));
};
uint setFilter(const QString &card, const QString &driver)
{
uint count = 0;
clearSelections();
QDir dev("/dev/v4l", "vbi*", QDir::Name, QDir::System);
if (!(count = fillSelectionsFromDir(dev, card, driver)))
{
dev.setPath("/dev");
if (!(count = fillSelectionsFromDir(dev, card, driver)) &&
!getValue().isEmpty())
{
addSelection(getValue(),getValue(),true);
}
}
return count;
}
/**
* \param dir The directory to open and search for devices.
* \param absPath Ignored. The function always uses absolute paths.
*/
void fillSelectionsFromDir(const QDir &dir, bool absPath = true)
{
// Needed to make both compiler and doxygen happy.
(void) absPath;
fillSelectionsFromDir(dir, QString(), QString());
}
uint fillSelectionsFromDir(const QDir &dir, const QString &card,
const QString &driver)
{
QStringList devices;
QFileInfoList il = dir.entryInfoList();
for( QFileInfoList::iterator it = il.begin();
it != il.end();
++it )
{
QFileInfo &fi = *it;
QString device = fi.absoluteFilePath();
QByteArray adevice = device.toLatin1();
int vbifd = open(adevice.constData(), O_RDWR);
if (vbifd < 0)
continue;
QString cn, dn;
if (CardUtil::GetV4LInfo(vbifd, cn, dn) &&
(driver.isEmpty() || (dn == driver)) &&
(card.isEmpty() || (cn == card)))
{
devices.push_back(device);
}
close(vbifd);
}
QString sel = getValue();
for (uint i = 0; i < (uint) devices.size(); i++)
addSelection(devices[i], devices[i], devices[i] == sel);
return (uint) devices.size();
}
};
class CommandPath : public MythUITextEditSetting
{
public:
explicit CommandPath(const CaptureCard &parent) :
MythUITextEditSetting(new CaptureCardDBStorage(this, parent,
"videodevice"))
{
setLabel(QObject::tr(""));
setValue("");
setHelpText(QObject::tr("Specify the command to run, with any "
"needed arguments."));
};
};
class FileDevice : public MythUIFileBrowserSetting
{
public:
explicit FileDevice(const CaptureCard &parent) :
MythUIFileBrowserSetting(
new CaptureCardDBStorage(this, parent, "videodevice")
/* mustexist, false */)
{
setLabel(QObject::tr("File path"));
};
};
class AudioDevice : public CaptureCardComboBoxSetting
{
public:
explicit AudioDevice(const CaptureCard &parent) :
CaptureCardComboBoxSetting(parent, true /* mustexist false */,
"audiodevice")
{
setLabel(QObject::tr("Audio device"));
#if USING_OSS
QDir dev("/dev", "dsp*", QDir::Name, QDir::System);
fillSelectionsFromDir(dev);
dev.setPath("/dev/sound");
fillSelectionsFromDir(dev);
#endif
#if USING_ALSA
addSelection("ALSA:default", "ALSA:default");
#endif
addSelection(QObject::tr("(None)"), "NULL");
setHelpText(QObject::tr("Device to read audio from, "
"if audio is separate from the video."));
};
};
class SignalTimeout : public CaptureCardSpinBoxSetting
{
public:
SignalTimeout(const CaptureCard &parent, uint value, uint min_val) :
CaptureCardSpinBoxSetting(parent, min_val, 60000, 250, "signal_timeout")
{
setLabel(QObject::tr("Signal timeout (ms)"));
setValue(QString::number(value));
setHelpText(QObject::tr(
"Maximum time (in milliseconds) MythTV waits for "
"a signal when scanning for channels."));
};
};
class ChannelTimeout : public CaptureCardSpinBoxSetting
{
public:
ChannelTimeout(const CaptureCard &parent, uint value, uint min_val) :
CaptureCardSpinBoxSetting(parent, min_val, 65000, 250,
"channel_timeout")
{
setLabel(QObject::tr("Tuning timeout (ms)"));
setValue(value);
setHelpText(QObject::tr(
"Maximum time (in milliseconds) MythTV waits for "
"a channel lock. For recordings, if this time is "
"exceeded, the recording will be marked as failed."));
};
};
class AudioRateLimit : public CaptureCardComboBoxSetting
{
public:
explicit AudioRateLimit(const CaptureCard &parent) :
CaptureCardComboBoxSetting(parent, false, "audioratelimit")
{
setLabel(QObject::tr("Force audio sampling rate"));
setHelpText(
QObject::tr("If non-zero, override the audio sampling "
"rate in the recording profile when this card is "
"used. Use this if your capture card does not "
"support all of the standard rates."));
addSelection(QObject::tr("(None)"), "0");
addSelection("32000");
addSelection("44100");
addSelection("48000");
};
};
class SkipBtAudio : public MythUICheckBoxSetting
{
public:
explicit SkipBtAudio(const CaptureCard &parent) :
MythUICheckBoxSetting(new CaptureCardDBStorage(this, parent,
"skipbtaudio"))
{
setLabel(QObject::tr("Do not adjust volume"));
setHelpText(
QObject::tr("Enable this option for budget BT878 based "
"DVB-T cards such as the AverTV DVB-T which "
"require the audio volume to be left alone."));
};
};
class DVBCardNum : public CaptureCardComboBoxSetting
{
public:
explicit DVBCardNum(const CaptureCard &parent) :
CaptureCardComboBoxSetting(parent, true, "videodevice")
{
setLabel(QObject::tr("DVB device"));
setHelpText(
QObject::tr("When you change this setting, the text below "
"should change to the name and type of your card. "
"If the card cannot be opened, an error message "
"will be displayed."));
fillSelections(QString());
};
/// \brief Adds all available cards to list
/// If current is >= 0 it will be considered available even
/// if no device exists for it in /dev/dvb/adapter*
void fillSelections(const QString ¤t)
{
clearSelections();
// Get devices from filesystem
QStringList sdevs = CardUtil::ProbeVideoDevices("DVB");
// Add current if needed
if (!current.isEmpty() &&
(find(sdevs.begin(), sdevs.end(), current) == sdevs.end()))
{
stable_sort(sdevs.begin(), sdevs.end());
}
QStringList db = CardUtil::GetVideoDevices("DVB");
QMap<QString,bool> in_use;
QString sel = current;
for (uint i = 0; i < (uint)sdevs.size(); i++)