Browse Source

remove LADSPA dependency on SHM

master
aj_genius 21 years ago
parent
commit
c1e5e43274
4 changed files with 15 additions and 179 deletions
  1. +11
    -118
      SpiralSound/Plugins/LADSPAPlugin/LADSPAPlugin.C
  2. +3
    -25
      SpiralSound/Plugins/LADSPAPlugin/LADSPAPlugin.h
  3. +1
    -1
      SpiralSound/Plugins/LADSPAPlugin/Makefile.in
  4. +0
    -35
      configure.in

+ 11
- 118
SpiralSound/Plugins/LADSPAPlugin/LADSPAPlugin.C View File

@@ -24,14 +24,6 @@
#include <cstring>
#include <cmath>

#ifdef USE_POSIX_SHM
// All this, just for SHM
#include <sys/types.h>
#include <sys/mman.h> // shm_*
#include <unistd.h> // For ftruncate
#include <fcntl.h> // For O_CREAT, O_RDONLY etc
#endif

#include "SpiralIcon.xpm"
#include "LADSPAPlugin.h"
#include "LADSPAPluginGUI.h"
@@ -39,6 +31,8 @@

using namespace std;

LADSPAInfo * LADSPAPlugin::m_LADSPAInfo= NULL;
int LADSPAPlugin::InstanceCount=0;
////////////////////////////////////////////////////

extern "C" {
@@ -67,99 +61,11 @@ string SpiralPlugin_GetGroupName()

LADSPAPlugin::LADSPAPlugin()
{
#ifdef USE_POSIX_SHM
// Share the LADSPA Database via SHM
// We keep two things:
// 1. A reference counter, counting LADSPAPlugin instances
// 2. A pointer to the database. We can get away with just a pointer as
// all instances are in the same address space (SSM audio thread)

unsigned long pid;
int len;
char pidstr[21]; // Enough to store 64 bit number as text
int bplen;
int rplen;
int dplen;

// Get our process id
pid = (unsigned long)getpid();
len = snprintf(pidstr,21,"%ld",pid);
bplen = strlen(m_SHMPath);
rplen = strlen(m_SHMPathRC);
dplen = strlen(m_SHMPathDB);

m_SHMRefCountPath = (char *)malloc(bplen+len+rplen+1);
m_SHMDatabasePath = (char *)malloc(bplen+len+dplen+1);

if (m_SHMRefCountPath && m_SHMDatabasePath) {
// Got paths - concatenate to form full paths
strncpy(m_SHMRefCountPath, m_SHMPath, bplen);
strncpy(m_SHMRefCountPath + bplen, pidstr, len);
strncpy(m_SHMRefCountPath + bplen + len, m_SHMPathRC, rplen);
m_SHMRefCountPath[bplen + len + rplen] = '\0';

strncpy(m_SHMDatabasePath, m_SHMPath, bplen);
strncpy(m_SHMDatabasePath + bplen, pidstr, len);
strncpy(m_SHMDatabasePath + bplen + len, m_SHMPathDB, dplen);
m_SHMDatabasePath[bplen + len + dplen] = '\0';

int shm_rc_fd = shm_open((const char *)m_SHMRefCountPath, O_RDWR, 0644);
if (shm_rc_fd > 0) {
// Got an existing refcount
m_SHMRefCount = (unsigned long *)mmap(0, sizeof(unsigned long), PROT_READ | PROT_WRITE, MAP_SHARED,
shm_rc_fd, 0);

(*m_SHMRefCount)++;

int shm_db_fd = shm_open((const char *)m_SHMDatabasePath, O_RDONLY, 0644);
if (shm_db_fd > 0) {
// Got LADSPA Database
m_SHMDatabase = (LADSPAInfo **)mmap(0, sizeof(LADSPAInfo *), PROT_READ, MAP_SHARED,
shm_db_fd, 0);

m_LADSPAInfo = *m_SHMDatabase;
} else {
std::cerr << "LADSPAPlugin: ERROR: Could not open SHM file '" << m_SHMDatabasePath << std::cerr;
m_LADSPAInfo = new LADSPAInfo(false, "");
}
} else {
// Create LADSPA Plugin Database
m_LADSPAInfo = new LADSPAInfo(false, "");

// Need to create a new SHM file for ref counter
shm_rc_fd = shm_open((const char *)m_SHMRefCountPath, O_CREAT | O_RDWR, 0644);
if (shm_rc_fd > 0) {
ftruncate(shm_rc_fd, sizeof(unsigned long));
m_SHMRefCount = (unsigned long *)mmap(0, sizeof(unsigned long), PROT_READ | PROT_WRITE, MAP_SHARED,
shm_rc_fd, 0);

// Initilise to 1 (this instance)
*m_SHMRefCount = 1;

int shm_db_fd = shm_open((const char *)m_SHMDatabasePath, O_CREAT | O_RDWR, 0644);
if (shm_db_fd > 0) {
// Share database via pointer
ftruncate(shm_db_fd, sizeof(LADSPAInfo *));
m_SHMDatabase = (LADSPAInfo **)mmap(0, sizeof(LADSPAInfo *), PROT_READ | PROT_WRITE, MAP_SHARED,
shm_db_fd, 0);

*m_SHMDatabase = m_LADSPAInfo;
} else {
std::cerr << "LADSPAPlugin: ERROR: Could not create SHM file '" << m_SHMDatabasePath << "'" << std::endl;
}
} else {
std::cerr << "LADSPAPlugin: ERROR: Could not create SHM file '" << m_SHMRefCountPath << "'" << std::endl;
}
}
} else {
// Dang. Just create new database
InstanceCount++;
if (!m_LADSPAInfo)
{
m_LADSPAInfo = new LADSPAInfo(false, "");
}

#else
// No POSIX SHM, just create a new database
m_LADSPAInfo = new LADSPAInfo(false, "");
#endif
}

m_PlugDesc = NULL;

@@ -222,25 +128,12 @@ LADSPAPlugin::~LADSPAPlugin()
if (m_OutData.InputPortValues) free(m_OutData.InputPortValues);
if (m_OutData.InputPortDefaults) free(m_OutData.InputPortDefaults);

#ifdef USE_POSIX_SHM
// Clean up SHM things
(*m_SHMRefCount)--;
if ((*m_SHMRefCount) == 0) {
// Last instance, so unmap and unlink
munmap(m_SHMRefCount, sizeof(unsigned long));
shm_unlink(m_SHMRefCountPath);
munmap(m_SHMDatabase, sizeof(LADSPAInfo *));
shm_unlink(m_SHMDatabasePath);
// Delete the database itself
InstanceCount--;
if (m_LADSPAInfo && InstanceCount<=0)
{
delete m_LADSPAInfo;
} else {
// Other instances still out there, so just unmap
munmap(m_SHMRefCount, sizeof(unsigned long));
munmap(m_SHMDatabase, sizeof(LADSPAInfo *));
}
#else
delete m_LADSPAInfo;
#endif
m_LADSPAInfo = NULL;
}
}

PluginInfo &LADSPAPlugin::Initialise(const HostInfo *Host)


+ 3
- 25
SpiralSound/Plugins/LADSPAPlugin/LADSPAPlugin.h View File

@@ -29,11 +29,6 @@
#include "../SpiralPlugin.h"
#include "LADSPAInfo.h"

#ifdef USE_POSIX_SHM
#include <sys/types.h> // For pid_t data member
#include <unistd.h>
#endif

struct PortSetting
{
float Min;
@@ -117,9 +112,9 @@ private:

int m_Version;

// our database of ladspa plugins
LADSPAInfo *m_LADSPAInfo;
static LADSPAInfo *m_LADSPAInfo;
static int InstanceCount;
unsigned long m_PluginIndex;
unsigned long m_UniqueID;
int m_Page;
@@ -159,23 +154,6 @@ private:

OutputChannelData m_OutData;
InputChannelData m_InData;

#ifdef USE_POSIX_SHM
// SHM stuff - for sharing the LADSPA Plugin database
// The actual paths are combined with the Process ID for the current SSM audio thread
// to allow multiple instances of SSM to run, and to avoid picking up stale SHMs
// from crashed instances.
static const char * const m_SHMPath = "/SSM-LADSPAPlugin-";
static const char * const m_SHMPathRC = "-RefCount";
static const char * const m_SHMPathDB = "-Database";

char *m_SHMRefCountPath;
char *m_SHMDatabasePath;

pid_t *m_SHMPID;
unsigned long *m_SHMRefCount;
LADSPAInfo **m_SHMDatabase;
#endif
};

#endif // __ladspa_plugin_h__

+ 1
- 1
SpiralSound/Plugins/LADSPAPlugin/Makefile.in View File

@@ -11,7 +11,7 @@ CXXFLAGS= @CXXFLAGS@ @FLTK_CXXFLAGS@
INCPATH = -I../../../ -I/usr/X11R6/include
LINK = g++ -shared
LFLAGS =
LIBS = @FLTK_LIBS@ @SHMLIBS@ @LRDFLIBS@
LIBS = @FLTK_LIBS@ @LRDFLIBS@
MOC = moc
UIC =



+ 0
- 35
configure.in View File

@@ -109,35 +109,6 @@ if test "$use_liblrdf" = "y"; then
AC_SUBST(LRDFLIBS)
fi

dnl Check if POSIX SHM is present or has been disabled
shm_message=""
AC_ARG_ENABLE(
posix-shm,
[ --disable-posix-shm Disable POSIX SHM for LADSPA Plugin],
[use_posix_shm="n" ; shm_message="manually disabled"],
[use_posix_shm="y"]
)
if test "$build_ladspa" = "n" ; then
use_posix_shm="n"
shm_message="LADSPAPlugin not used"
elif test "$use_liblrdf" = "n" ; then
use_posix_shm="n"
shm_message="liblrdf not used"
fi
if test "$use_posix_shm" = "y"; then
AC_MSG_CHECKING([POSIX SHM support ])
if test -d /dev/shm -a -w /dev/shm ; then
AC_DEFINE(USE_POSIX_SHM, ,[Enable POSIX SHM support for LADSPA Plugin])
AC_MSG_RESULT(found.)
SHMLIBS="-lrt"
AC_SUBST(SHMLIBS)
else
AC_MSG_RESULT(not found.)
use_posix_shm="n"
shm_message="/dev/shm not found";
fi
fi

dnl Check whether alsa-midi is present or has been disabled
amidi_message=""
AC_ARG_ENABLE(
@@ -326,10 +297,4 @@ if test "$use_liblrdf" = "y"; then
else
echo "Disabled - $lrdf_message"
fi
echo -n " POSIX SHM support for LADSPAPlugin - "
if test "$use_posix_shm" = "y"; then
echo "Enabled"
else
echo "Disabled - $shm_message"
fi
echo ""

Loading…
Cancel
Save