| 1215 | } |
| 1216 | |
| 1217 | bool VideoCache::pushNextJobToCachingThread(loadingThread *thread) |
| 1218 | { |
| 1219 | if ((cacheQueue.isEmpty() && !testMode) || thread->isQuitting()) |
| 1220 | // No more jobs in the cache queue or the thread does not accept new jobs. |
| 1221 | return false; |
| 1222 | |
| 1223 | if (testMode) |
| 1224 | { |
| 1225 | Q_ASSERT_X(testItem, Q_FUNC_INFO, "Test item invalid"); |
| 1226 | auto range = testItem->properties().startEndRange; |
| 1227 | int frameNr = |
| 1228 | functions::clip((1000 - testLoopCount) % (range.second - range.first) + range.first, |
| 1229 | range.first, |
| 1230 | range.second); |
| 1231 | if (frameNr < 0) |
| 1232 | frameNr = 0; |
| 1233 | thread->worker()->setJob(testItem, frameNr, true); |
| 1234 | thread->worker()->setWorking(true); |
| 1235 | thread->worker()->processCacheJob(); |
| 1236 | DEBUG_CACHING_DETAIL("VideoCache::pushNextJobToCachingThread - %d of %s", |
| 1237 | frameNr, |
| 1238 | testItem->getName().toStdString().c_str()); |
| 1239 | testLoopCount--; |
| 1240 | return true; |
| 1241 | } |
| 1242 | |
| 1243 | // If playback is running and playback is not waiting for a specific item to cache, |
| 1244 | // only start caching of a new job if caching is enabled while playback is running. |
| 1245 | if (playback->playing() && watchingItem == nullptr) |
| 1246 | { |
| 1247 | auto selection = playlist->getSelectedItems(); |
| 1248 | if (selection[0] && selection[0]->properties().isIndexedByFrame()) |
| 1249 | { |
| 1250 | // Playback is running and the item that is currently being shown is indexed by frame. |
| 1251 | // In this case, obey the restriction on nr threads while playback is running. |
| 1252 | |
| 1253 | if (nrThreadsPlayback == 0) |
| 1254 | { |
| 1255 | // No caching while playback is running |
| 1256 | DEBUG_CACHING_DETAIL( |
| 1257 | "VideoCache::pushNextJobToCachingThread no new job started nrThreadsPlayback=0"); |
| 1258 | return false; |
| 1259 | } |
| 1260 | |
| 1261 | // Check if there is a limit on the number of threads to use while playback is running. |
| 1262 | int threadsWorking = 0; |
| 1263 | for (loadingThread *t : cachingThreadList) |
| 1264 | { |
| 1265 | if (t->worker()->isWorking()) |
| 1266 | threadsWorking++; |
| 1267 | } |
| 1268 | |
| 1269 | if (nrThreadsPlayback <= threadsWorking) |
| 1270 | { |
| 1271 | // The maximum number (or more) of threads are already working. |
| 1272 | // Do not start another one. |
| 1273 | DEBUG_CACHING_DETAIL("VideoCache::pushNextJobToCachingThread no new job started " |
| 1274 | "nrThreadsPlayback=%d threadsWorking=%d", |
nothing calls this directly
no test coverage detected