summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOwen Williams <owilliams@mixxx.org>2019-12-30 15:52:23 -0500
committerOwen Williams <owilliams@mixxx.org>2019-12-30 15:52:23 -0500
commitbcf5f7d9911beb66d75ebd0a5756b6ef869fb3e4 (patch)
treef12717ddffc7459ea4d8d2b55a7b4bf4bca8a48a
parent7d4a6bd043e0aec7cb36d05b49ae7d3589bee867 (diff)
Master Sync: preallocate buffers in engine thread func.
pickMaster gets called from the engine thread so we have to be careful to avoid memory allocation. Preallocating a constant number fixes this. Also make kMaxNumberOfDecks a proper mixxx-global value, and check against it when we add decks. If someone one day invents a skin that uses 6 or 8 decks, this warning will get tripped (but shouldn't break anything fundamental in Mixxx).
-rw-r--r--src/engine/sync/enginesync.cpp4
-rw-r--r--src/mixer/playermanager.cpp7
-rw-r--r--src/util/defs.h2
-rw-r--r--src/vinylcontrol/vinylcontrolmanager.h6
4 files changed, 14 insertions, 5 deletions
diff --git a/src/engine/sync/enginesync.cpp b/src/engine/sync/enginesync.cpp
index 18c22be226..8b18a0a261 100644
--- a/src/engine/sync/enginesync.cpp
+++ b/src/engine/sync/enginesync.cpp
@@ -24,6 +24,7 @@
#include "engine/channels/enginechannel.h"
#include "engine/sync/internalclock.h"
#include "util/assert.h"
+#include "util/defs.h"
const bool SYNC_DEBUG = false;
@@ -38,6 +39,9 @@ Syncable* EngineSync::pickMaster(Syncable* enabling_syncable) {
std::vector<Syncable*> stopped_sync_decks;
std::vector<Syncable*> playing_sync_decks;
+ stopped_sync_decks.reserve(kMaxNumberOfDecks);
+ playing_sync_decks.reserve(kMaxNumberOfDecks);
+
if (enabling_syncable != nullptr && enabling_syncable->getBaseBpm() != 0.0) {
if (enabling_syncable->isPlaying()) {
playing_sync_decks.push_back(enabling_syncable);
diff --git a/src/mixer/playermanager.cpp b/src/mixer/playermanager.cpp
index 5240f71210..d377a9538a 100644
--- a/src/mixer/playermanager.cpp
+++ b/src/mixer/playermanager.cpp
@@ -20,6 +20,7 @@
#include "soundio/soundmanager.h"
#include "track/track.h"
#include "util/assert.h"
+#include "util/defs.h"
#include "util/logger.h"
#include "util/stat.h"
#include "util/sleepableqthread.h"
@@ -268,6 +269,12 @@ void PlayerManager::slotChangeNumDecks(double v) {
QMutexLocker locker(&m_mutex);
int num = (int)v;
+ VERIFY_OR_DEBUG_ASSERT(num <= kMaxNumberOfDecks) {
+ qWarning() << "Number of decks exceeds the maximum we expect."
+ << num << "vs" << kMaxNumberOfDecks
+ << " Please update util/defs.h";
+ }
+
// Update the soundmanager config even if the number of decks has been
// reduced.
m_pSoundManager->setConfiguredDeckCount(num);
diff --git a/src/util/defs.h b/src/util/defs.h
index 0b151a6260..f34bf34f99 100644
--- a/src/util/defs.h
+++ b/src/util/defs.h
@@ -5,4 +5,6 @@
//TODO: Replace this with mixxx::AudioParameters::bufferSize()
const unsigned int MAX_BUFFER_LEN = 160000;
+const int kMaxNumberOfDecks = 4;
+
#endif /* DEFS_H */
diff --git a/src/vinylcontrol/vinylcontrolmanager.h b/src/vinylcontrol/vinylcontrolmanager.h
index 6002330499..4bf975331b 100644
--- a/src/vinylcontrol/vinylcontrolmanager.h
+++ b/src/vinylcontrol/vinylcontrolmanager.h
@@ -15,6 +15,7 @@
#include "soundio/soundmanagerutil.h"
#include "preferences/usersettings.h"
#include "vinylcontrol/vinylsignalquality.h"
+#include "util/defs.h"
class ControlProxy;
class ControlPushButton;
@@ -23,11 +24,6 @@ class VinylControl;
class VinylControlProcessor;
-const int kMaxNumberOfDecks = 4; // set to 4 because it will ideally not be more
-// or less than the number of vinyl-controlled decks but will probably be
-// forgotten in any 2->4 deck switchover. Only real consequence is
-// sizeof(void*)*2 bytes of wasted memory if we're only using 2 decks -bkgood
-
// VinylControlManager is the main-thread interface that other parts of Mixxx
// use to interact with the vinyl control subsystem (other than controls exposed
// by vinyl control to the rest of Mixxx). VinylControlManager starts a