Ticket #10076: make_EIT_start_at_time.patch
File make_EIT_start_at_time.patch, 13.1 KB (added by , 13 years ago) |
---|
-
mythtv/libs/libmythtv/tv_rec.cpp
diff -Naur mythtv-master-20111004-g51c8ce1-old/mythtv/libs/libmythtv/tv_rec.cpp mythtv-master-20111004-g51c8ce1-new/mythtv/libs/libmythtv/tv_rec.cpp
old new 88 88 // Configuration variables from database 89 89 transcodeFirst(false), 90 90 earlyCommFlag(false), runJobOnHostOnly(false), 91 eitCrawlIdleStart(60), eitTransportTimeout(5*60), 91 eitCrawlIdleStart(60), eitTransportTimeout(5*60), eitCrawlDuration(240), 92 92 audioSampleRateDB(0), 93 93 overRecordSecNrml(0), overRecordSecCat(0), 94 94 overRecordCategory(""), … … 164 164 runJobOnHostOnly = gCoreContext->GetNumSetting("JobsRunOnRecordHost", 0); 165 165 eitTransportTimeout=gCoreContext->GetNumSetting("EITTransportTimeout", 5) * 60; 166 166 eitCrawlIdleStart = gCoreContext->GetNumSetting("EITCrawIdleStart", 60); 167 // eitCrawlDuration currently hardcoded to 240min as I don't want to change DB schema 168 // by introdution of new setting. 169 // eitCrawlDuration = gCoreContext->GetNumSetting("EITCrawDuration", 240); 170 eitCrawlDuration = 240; 167 171 audioSampleRateDB = gCoreContext->GetNumSetting("AudioSampleRate"); 168 172 overRecordSecNrml = gCoreContext->GetNumSetting("RecordOverTime"); 169 173 overRecordSecCat = gCoreContext->GetNumSetting("CategoryOverTime") * 60; … … 919 923 } 920 924 } 921 925 926 static int no_capturecards(uint cardid) 927 { 928 MSqlQuery query(MSqlQuery::InitCon()); 929 930 QString str = 931 "SELECT COUNT(cardid) " 932 "FROM capturecard "; 933 934 if (cardid) 935 str += "WHERE cardid < :CARDID"; 936 937 query.prepare(str); 938 939 if (cardid) 940 query.bindValue(":CARDID", cardid); 941 942 if (!query.exec() || !query.isActive()) 943 { 944 MythDB::DBError("no_capturecards", query); 945 return -1; 946 } 947 else if (query.next()) 948 return query.value(0).toInt(); 949 return -1; 950 } 951 922 952 #define TRANSITION(ASTATE,BSTATE) \ 923 953 ((internalState == ASTATE) && (desiredNextState == BSTATE)) 924 954 #define SET_NEXT() do { nextState = desiredNextState; changed = true; } while(0) … … 955 985 { 956 986 scanner->StopActiveScan(); 957 987 ClearFlags(kFlagEITScannerRunning); 988 LOG(VB_GENERAL, LOG_INFO, LOC + 989 "EIT active scanner stopped by Recording or LiveTV"); 958 990 } 959 991 960 992 // Handle different state transitions … … 997 1029 998 1030 eitScanStartTime = QDateTime::currentDateTime(); 999 1031 if (scanner && (internalState == kState_None)) 1000 eitScanStartTime = eitScanStartTime.addSecs(eitCrawlIdleStart); 1032 { 1033 // If eitCrawlIdleStart is above 3600 then we enter schedulled mode. 1034 // For values 3600 and below we have old behaviour. 1035 if (eitCrawlIdleStart <= 3600) 1036 { 1037 eitScanStartTime = eitScanStartTime.addSecs(eitCrawlIdleStart); 1038 eitScanEndAT = eitScanStartTime.addYears(1); 1039 LOG(VB_GENERAL, LOG_INFO, LOC + 1040 QString("EIT active scan will resume after %1 sec.").arg(eitCrawlIdleStart)); 1041 } 1042 else 1043 { 1044 // Check is current event within active EIT scan window. If it is, 1045 // then scanner will be resumed after 60sec. 1046 // If not, set start/end times to next nearest scan window. 1047 if ((QDateTime::currentDateTime() < eitScanStartAT) || 1048 (QDateTime::currentDateTime() > eitScanEndAT)) 1049 { 1050 eitScanStartTime.setTime(QTime(0, 0)); 1051 eitScanStartTime = eitScanStartTime.addSecs(eitCrawlIdleStart); 1052 eitScanEndAT = eitScanStartTime.addSecs(eitCrawlDuration*60); 1053 // distribute resume time evenly over eitTransportTimeout 1054 int card_pos = no_capturecards(cardid); 1055 int no_cards = no_capturecards(0); 1056 uint timeout = 0; 1057 if (no_cards > 0 && card_pos >= 0) 1058 timeout += eitTransportTimeout * card_pos / no_cards; 1059 else 1060 timeout += random() % eitTransportTimeout; 1061 eitScanStartTime = eitScanStartTime.addSecs(timeout); 1062 eitScanStartAT = eitScanStartTime; 1063 // IF we started after window, move start & end 1064 // time to next day 1065 if (QDateTime::currentDateTime() > eitScanEndAT) 1066 { 1067 eitScanStartTime = eitScanStartTime.addDays(1); 1068 eitScanStartAT = eitScanStartAT.addDays(1); 1069 eitScanEndAT = eitScanEndAT.addDays(1); 1070 } 1071 LOG(VB_GENERAL, LOG_INFO, LOC + 1072 QString("EIT active scan will resume at:%1").arg(eitScanStartTime.toString(Qt::ISODate))); 1073 } 1074 else 1075 { 1076 eitScanStartTime = eitScanStartTime.addSecs(60); 1077 LOG(VB_GENERAL, LOG_INFO, LOC + 1078 QString("EIT active scan is in %1min. window. If enabled, will (re)start after 60 sec.").arg(eitCrawlDuration)); 1079 } 1080 } 1081 } 1001 1082 else 1002 1083 eitScanStartTime = eitScanStartTime.addYears(1); 1003 1084 } … … 1142 1223 return false; 1143 1224 } 1144 1225 1145 static int no_capturecards(uint cardid)1146 {1147 MSqlQuery query(MSqlQuery::InitCon());1148 1149 QString str =1150 "SELECT COUNT(cardid) "1151 "FROM capturecard ";1152 1153 if (cardid)1154 str += "WHERE cardid < :CARDID";1155 1156 query.prepare(str);1157 1158 if (cardid)1159 query.bindValue(":CARDID", cardid);1160 1161 if (!query.exec() || !query.isActive())1162 {1163 MythDB::DBError("no_capturecards", query);1164 return -1;1165 }1166 else if (query.next())1167 return query.value(0).toInt();1168 return -1;1169 }1170 1171 1226 /// \brief Event handling method, contains event loop. 1172 1227 void TVRec::run(void) 1173 1228 { … … 1182 1237 (dvbOpt.dvb_eitscan || get_use_eit(cardid))) 1183 1238 { 1184 1239 scanner = new EITScanner(cardid); 1185 uint timeout = eitCrawlIdleStart;1186 1240 // get the number of capture cards and the position of the current card 1187 // to distribute the the scan startevenly over eitTransportTimeout1241 // to help distribute scan start time evenly over eitTransportTimeout 1188 1242 int card_pos = no_capturecards(cardid); 1189 1243 int no_cards = no_capturecards(0); 1190 if (no_cards > 0 && card_pos >= 0) 1191 timeout += eitTransportTimeout * card_pos / no_cards; 1244 1245 // If eitCrawlIdleStart is above 3600 then we enter schedulled mode for 1246 // EIT active scan. For values 3600 and below we have old behaviour. 1247 if (eitCrawlIdleStart <= 3600) 1248 { 1249 uint timeout = eitCrawlIdleStart; 1250 if (no_cards > 0 && card_pos >= 0) 1251 timeout += eitTransportTimeout * card_pos / no_cards; 1252 else 1253 timeout += random() % eitTransportTimeout; 1254 eitScanStartTime = eitScanStartTime.addSecs(timeout); 1255 eitScanEndAT = eitScanStartTime.addYears(1); 1256 LOG(VB_GENERAL, LOG_INFO, LOC + 1257 QString("EIT active scan start after %1 sec.").arg(timeout)); 1258 } 1192 1259 else 1193 timeout += random() % eitTransportTimeout; 1260 { 1261 // Set initial scan start/end time to 1262 // 0:00+eitCrawlIdleStart/eitCrawlIdleStart+eitCrawlDuration respectively 1263 eitScanStartTime.setTime(QTime(0, 0)); 1264 eitScanStartTime = eitScanStartTime.addSecs(eitCrawlIdleStart); 1265 eitScanEndAT = eitScanStartTime.addSecs(eitCrawlDuration*60); 1266 // Distribute scan start time evenly over eitTransportTimeout 1267 uint timeout = 0; 1268 if (no_cards > 0 && card_pos >= 0) 1269 timeout += eitTransportTimeout * card_pos / no_cards; 1270 else 1271 timeout += random() % eitTransportTimeout; 1272 eitScanStartTime = eitScanStartTime.addSecs(timeout); 1194 1273 1195 eitScanStartTime = eitScanStartTime.addSecs(timeout); 1274 eitScanStartAT = eitScanStartTime; 1275 // If we started after window, move start & end 1276 // time to next day 1277 if (QDateTime::currentDateTime() > eitScanEndAT) 1278 { 1279 eitScanStartTime = eitScanStartTime.addDays(1); 1280 eitScanStartAT = eitScanStartAT.addDays(1); 1281 eitScanEndAT = eitScanEndAT.addDays(1); 1282 } 1283 LOG(VB_GENERAL, LOG_INFO, LOC + 1284 QString("EIT active scan window: %1").arg(eitScanStartAT.toString(Qt::ISODate)) + 1285 QString(" <--> %1").arg(eitScanEndAT.toString(Qt::ISODate))); 1286 } 1196 1287 } 1197 1288 else 1289 { 1198 1290 eitScanStartTime = eitScanStartTime.addYears(1); 1291 eitScanEndAT = eitScanStartTime; 1292 } 1199 1293 1200 1294 while (HasFlags(kFlagRunMainLoop)) 1201 1295 { … … 1327 1421 ClearFlags(kFlagExitPlayer); 1328 1422 } 1329 1423 1424 // Check should we start or stop active scan on this card 1330 1425 if (scanner && channel && 1331 QDateTime::currentDateTime() > eitScanStartTime)1426 (QDateTime::currentDateTime() > eitScanStartTime || QDateTime::currentDateTime() > eitScanEndAT)) 1332 1427 { 1333 1428 if (!dvbOpt.dvb_eitscan) 1334 1429 { 1335 1430 LOG(VB_EIT, LOG_INFO, LOC + 1336 1431 "EIT scanning disabled for this card."); 1337 1432 eitScanStartTime = eitScanStartTime.addYears(1); 1433 eitScanEndAT = eitScanEndAT.addYears(1); 1338 1434 } 1339 1435 else if (!get_use_eit(GetCaptureCardNum())) 1340 1436 { 1341 1437 LOG(VB_EIT, LOG_INFO, LOC + 1342 1438 "EIT scanning disabled for all sources on this card."); 1343 1439 eitScanStartTime = eitScanStartTime.addYears(1); 1440 eitScanEndAT = eitScanEndAT.addYears(1); 1344 1441 } 1345 1442 else 1346 1443 { 1347 scanner->StartActiveScan(this, eitTransportTimeout); 1348 SetFlags(kFlagEITScannerRunning); 1349 eitScanStartTime = QDateTime::currentDateTime().addYears(1); 1444 if (QDateTime::currentDateTime() > eitScanStartTime && QDateTime::currentDateTime() < eitScanEndAT) 1445 { 1446 scanner->StartActiveScan(this, eitTransportTimeout); 1447 SetFlags(kFlagEITScannerRunning); 1448 eitScanStartTime = QDateTime::currentDateTime().addYears(1); 1449 LOG(VB_GENERAL, LOG_INFO, LOC + 1450 "EIT active scan started."); 1451 } 1452 else if (QDateTime::currentDateTime() > eitScanEndAT && HasFlags(kFlagEITScannerRunning)) 1453 { 1454 scanner->StopActiveScan(); 1455 ClearFlags(kFlagEITScannerRunning); 1456 LOG(VB_GENERAL, LOG_INFO, LOC + 1457 "EIT active scan stopped by reaching time window."); 1458 } 1350 1459 } 1351 1460 } 1352 1461 -
mythtv/libs/libmythtv/tv_rec.h
diff -Naur mythtv-master-20111004-g51c8ce1-old/mythtv/libs/libmythtv/tv_rec.h mythtv-master-20111004-g51c8ce1-new/mythtv/libs/libmythtv/tv_rec.h
old new 329 329 bool runJobOnHostOnly; 330 330 int eitCrawlIdleStart; 331 331 int eitTransportTimeout; 332 int eitCrawlDuration; 332 333 int audioSampleRateDB; 333 334 int overRecordSecNrml; 334 335 int overRecordSecCat; … … 355 356 TuningQueue tuningRequests; 356 357 TuningRequest lastTuningRequest; 357 358 QDateTime eitScanStartTime; 359 QDateTime eitScanStartAT; 360 QDateTime eitScanEndAT; 358 361 mutable QMutex triggerEventLoopLock; 359 362 QWaitCondition triggerEventLoopWait; 360 363 bool triggerEventLoopSignal; -
mythtv/programs/mythtv-setup/backendsettings.cpp
diff -Naur mythtv-master-20111004-g51c8ce1-old/mythtv/programs/mythtv-setup/backendsettings.cpp mythtv-master-20111004-g51c8ce1-new/mythtv/programs/mythtv-setup/backendsettings.cpp
old new 330 330 331 331 static GlobalSpinBox *EITCrawIdleStart() 332 332 { 333 GlobalSpinBox *gc = new GlobalSpinBox("EITCrawIdleStart", 30, 7200, 30);333 GlobalSpinBox *gc = new GlobalSpinBox("EITCrawIdleStart", 30, 86400, 20); 334 334 gc->setLabel(QObject::tr("Backend idle before EIT crawl (secs)")); 335 335 gc->setValue(60); 336 336 QString help = QObject::tr( 337 "The minimum number of seconds after a recorder becomes idle " 338 "to wait before MythTV begins collecting EIT listings data."); 337 "The number of seconds for idle recorders when collecting EIT listings begins. " 338 "If this value is higher than 3600 sec, MythTV will switch to schedulled mode" 339 " where collecting starts this number of seconds after midnight and will go" 340 " for 4h time window." 341 ); 339 342 gc->setHelpText(help); 340 343 return gc; 341 344 }