| 324 | } |
| 325 | |
| 326 | void VideoCache::updateSettings() |
| 327 | { |
| 328 | DEBUG_CACHING("VideoCache::updateSettings"); |
| 329 | |
| 330 | // Get if caching is enabled and how much memory we can use for the cache |
| 331 | QSettings settings; |
| 332 | settings.beginGroup("VideoCache"); |
| 333 | cachingEnabled = settings.value("Enabled", true).toBool(); |
| 334 | cacheLevelMax = (int64_t)settings.value("ThresholdValueMB", 49).toUInt() * 1000 * 1000; |
| 335 | |
| 336 | // See if the user changed the number of threads |
| 337 | int targetNrThreads = functions::getOptimalThreadCount(); |
| 338 | if (settings.value("SetNrThreads", false).toBool()) |
| 339 | targetNrThreads = settings.value("NrThreads", targetNrThreads).toInt(); |
| 340 | if (targetNrThreads <= 0) |
| 341 | targetNrThreads = 1; |
| 342 | if (!cachingEnabled) |
| 343 | targetNrThreads = 0; |
| 344 | |
| 345 | // How many threads should be used when playback is running? |
| 346 | if (settings.value("PlaybackCachingEnabled", false).toBool()) |
| 347 | nrThreadsPlayback = settings.value("PlaybackCachingThreadLimit", 1).toInt(); |
| 348 | else |
| 349 | nrThreadsPlayback = 0; |
| 350 | |
| 351 | if (targetNrThreads > cachingThreadList.count()) |
| 352 | // Create new threads |
| 353 | startWorkerThreads(targetNrThreads - cachingThreadList.count()); |
| 354 | else if (targetNrThreads < cachingThreadList.count()) |
| 355 | { |
| 356 | // Remove threads. We can only delete workers (and their threads) that are currently not |
| 357 | // working. |
| 358 | int nrThreadsToRemove = cachingThreadList.count() - targetNrThreads; |
| 359 | |
| 360 | for (int i = cachingThreadList.count() - 1; i >= 0 && nrThreadsToRemove > 0; i--) |
| 361 | { |
| 362 | if (!cachingThreadList[i]->worker()->isWorking()) |
| 363 | { |
| 364 | // Not working -> delete it now |
| 365 | QThread *t = cachingThreadList.takeAt(i); |
| 366 | t->exit(); |
| 367 | t->deleteLater(); |
| 368 | |
| 369 | DEBUG_CACHING("VideoCache::updateSettings Deleting thread %p with worker %d", t, i); |
| 370 | nrThreadsToRemove--; |
| 371 | } |
| 372 | } |
| 373 | |
| 374 | if (nrThreadsToRemove > 0) |
| 375 | { |
| 376 | // We need to remove more threads but the workers in these threads are still running. Do this |
| 377 | // when the workers finish. |
| 378 | DEBUG_CACHING("VideoCache::updateSettings Deleting %d threads later", nrThreadsToRemove); |
| 379 | deleteNrThreads = nrThreadsToRemove; |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | // Also update the cache status and schedule an update of the caching. |
nothing calls this directly
no test coverage detected