Skip to content

Commit

Permalink
Dynamic shm port
Browse files Browse the repository at this point in the history
Signed-off-by: falkTX <[email protected]>
  • Loading branch information
falkTX committed Mar 17, 2024
1 parent 1066a0b commit 540f2c0
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions common/JackModDesktopDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class ModDesktopAudioDriver : public JackAudioDriver
static constexpr const size_t kDataSize = sizeof(Data) + sizeof(float) * 128 * 2;

Data* fShmData;
const unsigned int fShmPort;

#ifdef _WIN32
HANDLE fShm;
Expand Down Expand Up @@ -179,9 +180,10 @@ class ModDesktopAudioDriver : public JackAudioDriver
}

public:
ModDesktopAudioDriver(const char* name, const char* alias, JackLockedEngine* engine, JackSynchro* table)
ModDesktopAudioDriver(const char* name, const char* alias, JackLockedEngine* engine, JackSynchro* table, unsigned int shmport)
: JackAudioDriver(name, alias, engine, table),
fShmData(nullptr),
fShmPort(shmport),
#ifdef _WIN32
fShm(nullptr),
#else
Expand Down Expand Up @@ -222,9 +224,12 @@ class ModDesktopAudioDriver : public JackAudioDriver
}

void* ptr;
char shmName[32] = {};

#ifdef _WIN32
fShm = OpenFileMappingA(FILE_MAP_ALL_ACCESS, FALSE, "/mod-desktop-test1");
std::snprintf(shmName, 31, "Local\\mod-desktop-shm-%d", fShmPort);

fShm = OpenFileMappingA(FILE_MAP_ALL_ACCESS, FALSE, shmName);
if (fShm == nullptr)
{
Close();
Expand All @@ -242,7 +247,9 @@ class ModDesktopAudioDriver : public JackAudioDriver

VirtualLock(ptr, kDataSize);
#else
fShmFd = shm_open("/mod-desktop-test1", O_RDWR, 0);
std::snprintf(shmName, 31, "/mod-desktop-shm-%d", fShmPort);

fShmFd = shm_open(shmName, O_RDWR, 0);
if (fShmFd < 0)
{
Close();
Expand Down Expand Up @@ -521,13 +528,17 @@ SERVER_EXPORT jack_driver_desc_t* driver_get_descriptor()
value.ui = 128;
jack_driver_descriptor_add_parameter(desc, &filler, "period", 'p', JackDriverParamUInt, &value, nullptr, "Frames per period", nullptr);

value.ui = 0;
jack_driver_descriptor_add_parameter(desc, &filler, "shmport", 's', JackDriverParamUInt, &value, nullptr, "Shared memory port number", nullptr);

return desc;
}

SERVER_EXPORT Jack::JackDriverClientInterface* driver_initialize(Jack::JackLockedEngine* engine, Jack::JackSynchro* table, const JSList* params)
{
jack_nframes_t rate = 48000;
jack_nframes_t period = 128;
unsigned int shmport = 0;

for (const JSList* node = params; node; node = jack_slist_next(node))
{
Expand All @@ -541,10 +552,19 @@ SERVER_EXPORT Jack::JackDriverClientInterface* driver_initialize(Jack::JackLocke
case 'p':
period = param->value.ui;
break;
case 's':
shmport = param->value.ui;
break;
}
}

Jack::JackDriverClientInterface* driver = new Jack::ModDesktopAudioDriver("system", "mod-desktop", engine, table);
if (shmport == 0)
{
jack_error("Missing or invalid shared memory port number");
return nullptr;
}

Jack::JackDriverClientInterface* driver = new Jack::ModDesktopAudioDriver("system", "mod-desktop", engine, table, shmport);

if (driver->Open(period, rate, true, true, 2, 2, false, "", "", 0, 0) == 0)
{
Expand Down

0 comments on commit 540f2c0

Please sign in to comment.