Commit 7453e5b0 authored by sletz's avatar sletz
Browse files

Dynamic choice of maximum port number.

git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@3828 0c269be4-1314-0410-8aa9-9f06e86f4224
parent dab4e344
......@@ -26,6 +26,10 @@ Peter L Jones
Jackdmp changes log
---------------------------
2009-11-24 Stephane Letz <letz@grame.fr>
* Dynamic choice of maximum port number.
2009-11-23 Stephane Letz <letz@grame.fr>
* Peter L Jones patch for NetJack1 compilation on Windows.
......
......@@ -251,7 +251,7 @@ extern "C"
static inline bool CheckPort(jack_port_id_t port_index)
{
return (port_index > 0 && port_index < PORT_NUM);
return (port_index > 0 && port_index < PORT_NUM_MAX);
}
static inline bool CheckBufferSize(jack_nframes_t buffer_size)
......
......@@ -33,7 +33,7 @@ JackConnectionManager::JackConnectionManager()
int i;
jack_log("JackConnectionManager::InitConnections size = %ld ", sizeof(JackConnectionManager));
for (i = 0; i < PORT_NUM; i++) {
for (i = 0; i < PORT_NUM_MAX; i++) {
fConnection[i].Init();
}
......
......@@ -353,11 +353,21 @@ struct JackClientTiming
jack_time_t fFinishedAt;
jack_client_state_t fStatus;
JackClientTiming(): fSignaledAt(0), fAwakeAt(0), fFinishedAt(0), fStatus(NotTriggered)
{}
JackClientTiming()
{
Init();
}
~JackClientTiming()
{}
void Init()
{
fSignaledAt = 0;
fAwakeAt = 0;
fFinishedAt = 0;
fStatus = NotTriggered;
}
} POST_PACKED_STRUCTURE;
/*!
......@@ -379,7 +389,7 @@ class SERVER_EXPORT JackConnectionManager
private:
JackFixedArray<CONNECTION_NUM_FOR_PORT> fConnection[PORT_NUM]; /*! Connection matrix: list of connected ports for a given port: needed to compute Mix buffer */
JackFixedArray<CONNECTION_NUM_FOR_PORT> fConnection[PORT_NUM_MAX]; /*! Connection matrix: list of connected ports for a given port: needed to compute Mix buffer */
JackFixedArray1<PORT_NUM_FOR_CLIENT> fInputPort[CLIENT_NUM]; /*! Table of input port per refnum : to find a refnum for a given port */
JackFixedArray<PORT_NUM_FOR_CLIENT> fOutputPort[CLIENT_NUM]; /*! Table of output port per refnum : to find a refnum for a given port */
JackFixedMatrix<CLIENT_NUM> fConnectionRef; /*! Table of port connections by (refnum , refnum) */
......
......@@ -38,6 +38,8 @@
#define PORT_NUM 2048
#endif
#define PORT_NUM_MAX 4096 // The "max" value for ports used in connection manager, although port number in graph manager is dynamic
#define DRIVER_PORT_NUM 256
#ifndef PORT_NUM_FOR_CLIENT
......
......@@ -82,7 +82,11 @@ struct jackctl_server
/* uint32_t, clock source type */
union jackctl_parameter_value clock_source;
union jackctl_parameter_value default_clock_source;
/* uint32_t, max port number */
union jackctl_parameter_value port_max;
union jackctl_parameter_value default_port_max;
/* bool */
union jackctl_parameter_value replace_registry;
union jackctl_parameter_value default_replace_registry;
......@@ -741,6 +745,20 @@ EXPORT jackctl_server_t * jackctl_server_create(
{
goto fail_free_parameters;
}
value.ui = PORT_NUM;
if (jackctl_add_parameter(
&server_ptr->parameters,
"port-max",
"Maximum number of ports.",
"",
JackParamUInt,
&server_ptr->port_max,
&server_ptr->default_port_max,
value) == NULL)
{
goto fail_free_parameters;
}
value.b = false;
if (jackctl_add_parameter(
......@@ -873,6 +891,7 @@ jackctl_server_start(
server_ptr->client_timeout.i,
server_ptr->realtime.b,
server_ptr->realtime_priority.i,
server_ptr->port_max.ui,
server_ptr->verbose.b,
(jack_timer_type_t)server_ptr->clock_source.ui,
server_ptr->name.str);
......
......@@ -29,13 +29,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
namespace Jack
{
static void AssertPort(jack_port_id_t port_index)
{
if (port_index >= PORT_NUM) {
jack_log("JackGraphManager::AssertPort port_index = %ld", port_index);
assert(port_index < PORT_NUM);
}
}
static void AssertBufferSize(jack_nframes_t buffer_size)
{
......@@ -44,7 +37,40 @@ static void AssertBufferSize(jack_nframes_t buffer_size)
assert(buffer_size <= BUFFER_SIZE_MAX);
}
}
void JackGraphManager::AssertPort(jack_port_id_t port_index)
{
if (port_index >= fPortMax) {
jack_log("JackGraphManager::AssertPort port_index = %ld", port_index);
assert(port_index < fPortMax);
}
}
JackGraphManager* JackGraphManager::Allocate(int port_max)
{
// Using "Placement" new
void* shared_ptr = JackShmMem::operator new(sizeof(JackGraphManager) + port_max * sizeof(JackPort));
return new(shared_ptr) JackGraphManager(port_max);
}
void JackGraphManager::Destroy(JackGraphManager* manager)
{
// "Placement" new was used
manager->~JackGraphManager();
JackShmMem::operator delete(manager);
}
JackGraphManager::JackGraphManager(int port_max)
{
assert(port_max <= PORT_NUM_MAX);
for (int i = 0; i < port_max; i++) {
fPortArray[i].Release();
}
fPortMax = port_max;
}
JackPort* JackGraphManager::GetPort(jack_port_id_t port_index)
{
AssertPort(port_index);
......@@ -262,7 +288,7 @@ int JackGraphManager::ComputeTotalLatency(jack_port_id_t port_index)
int JackGraphManager::ComputeTotalLatencies()
{
jack_port_id_t port_index;
for (port_index = FIRST_AVAILABLE_PORT; port_index < PORT_NUM; port_index++) {
for (port_index = FIRST_AVAILABLE_PORT; port_index < fPortMax; port_index++) {
JackPort* port = GetPort(port_index);
if (port->IsUsed())
ComputeTotalLatency(port_index);
......@@ -276,7 +302,7 @@ void JackGraphManager::SetBufferSize(jack_nframes_t buffer_size)
jack_log("JackGraphManager::SetBufferSize size = %ld", buffer_size);
jack_port_id_t port_index;
for (port_index = FIRST_AVAILABLE_PORT; port_index < PORT_NUM; port_index++) {
for (port_index = FIRST_AVAILABLE_PORT; port_index < fPortMax; port_index++) {
JackPort* port = GetPort(port_index);
if (port->IsUsed())
port->ClearBuffer(buffer_size);
......@@ -289,7 +315,7 @@ jack_port_id_t JackGraphManager::AllocatePortAux(int refnum, const char* port_na
jack_port_id_t port_index;
// Available ports start at FIRST_AVAILABLE_PORT (= 1), otherwise a port_index of 0 is "seen" as a NULL port by the external API...
for (port_index = FIRST_AVAILABLE_PORT; port_index < PORT_NUM; port_index++) {
for (port_index = FIRST_AVAILABLE_PORT; port_index < fPortMax; port_index++) {
JackPort* port = GetPort(port_index);
if (!port->IsUsed()) {
jack_log("JackGraphManager::AllocatePortAux port_index = %ld name = %s type = %s", port_index, port_name, port_type);
......@@ -299,7 +325,7 @@ jack_port_id_t JackGraphManager::AllocatePortAux(int refnum, const char* port_na
}
}
return (port_index < PORT_NUM) ? port_index : NO_PORT;
return (port_index < fPortMax) ? port_index : NO_PORT;
}
// Server
......@@ -424,7 +450,7 @@ void JackGraphManager::DisconnectAllInput(jack_port_id_t port_index)
jack_log("JackGraphManager::DisconnectAllInput port_index = %ld", port_index);
JackConnectionManager* manager = WriteNextStateStart();
for (int i = 0; i < PORT_NUM; i++) {
for (unsigned int i = 0; i < fPortMax; i++) {
if (manager->IsConnected(i, port_index)) {
jack_log("JackGraphManager::Disconnect i = %ld port_index = %ld", i, port_index);
Disconnect(i, port_index);
......@@ -661,7 +687,7 @@ int JackGraphManager::GetTwoPorts(const char* src_name, const char* dst_name, ja
// Client : port array
jack_port_id_t JackGraphManager::GetPort(const char* name)
{
for (int i = 0; i < PORT_NUM; i++) {
for (unsigned int i = 0; i < fPortMax; i++) {
JackPort* port = GetPort(i);
if (port->IsUsed() && port->NameEquals(name))
return i;
......@@ -734,9 +760,9 @@ void JackGraphManager::GetPortsAux(const char** matching_ports, const char* port
}
// Cleanup port array
memset(matching_ports, 0, sizeof(char*) * PORT_NUM);
memset(matching_ports, 0, sizeof(char*) * fPortMax);
for (int i = 0; i < PORT_NUM; i++) {
for (unsigned int i = 0; i < fPortMax; i++) {
bool matching = true;
JackPort* port = GetPort(i);
......@@ -783,7 +809,7 @@ void JackGraphManager::GetPortsAux(const char** matching_ports, const char* port
*/
const char** JackGraphManager::GetPorts(const char* port_name_pattern, const char* type_name_pattern, unsigned long flags)
{
const char** res = (const char**)malloc(sizeof(char*) * PORT_NUM);
const char** res = (const char**)malloc(sizeof(char*) * fPortMax);
UInt16 cur_index, next_index;
if (!res)
......
......@@ -42,9 +42,11 @@ class SERVER_EXPORT JackGraphManager : public JackShmMem, public JackAtomicState
private:
JackPort fPortArray[PORT_NUM];
unsigned int fPortMax;
JackClientTiming fClientTiming[CLIENT_NUM];
JackPort fPortArray[0]; // The actual size depends of port_max, it will be dynamically computed and allocated using "placement" new
void AssertPort(jack_port_id_t port_index);
jack_port_id_t AllocatePortAux(int refnum, const char* port_name, const char* port_type, JackPortFlags flags);
void GetConnectionsAux(JackConnectionManager* manager, const char** res, jack_port_id_t port_index);
void GetPortsAux(const char** matching_ports, const char* port_name_pattern, const char* type_name_pattern, unsigned long flags);
......@@ -54,8 +56,7 @@ class SERVER_EXPORT JackGraphManager : public JackShmMem, public JackAtomicState
public:
JackGraphManager()
{}
JackGraphManager(int port_max);
~JackGraphManager()
{}
......@@ -127,6 +128,9 @@ class SERVER_EXPORT JackGraphManager : public JackShmMem, public JackAtomicState
void Save(JackConnectionManager* dst);
void Restore(JackConnectionManager* src);
static JackGraphManager* Allocate(int port_max);
static void Destroy(JackGraphManager* manager);
} POST_PACKED_STRUCTURE;
......
......@@ -28,15 +28,9 @@ namespace Jack
{
JackPort::JackPort()
: fTypeId(0),
fFlags(JackPortIsInput),
fRefNum( -1),
fLatency(0),
fTotalLatency(0),
fMonitorRequests(0),
fInUse(false),
fTied(NO_PORT)
{}
{
Release();
}
bool JackPort::Allocate(int refnum, const char* port_name, const char* port_type, JackPortFlags flags)
{
......@@ -68,6 +62,7 @@ void JackPort::Release()
fInUse = false;
fLatency = 0;
fTotalLatency = 0;
fMonitorRequests = 0;
fTied = NO_PORT;
fAlias1[0] = '\0';
fAlias2[0] = '\0';
......
......@@ -38,15 +38,15 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
namespace Jack
{
JackServer::JackServer(bool sync, bool temporary, long timeout, bool rt, long priority, bool verbose, jack_timer_type_t clock, const char* server_name)
JackServer::JackServer(bool sync, bool temporary, int timeout, bool rt, int priority, int port_max, bool verbose, jack_timer_type_t clock, const char* server_name)
{
if (rt) {
jack_info("JACK server starting in realtime mode with priority %ld", priority);
} else {
jack_info("JACK server starting in non-realtime mode");
}
fGraphManager = new JackGraphManager();
fGraphManager = JackGraphManager::Allocate(port_max);
fEngineControl = new JackEngineControl(sync, temporary, timeout, rt, priority, verbose, clock, server_name);
fEngine = new JackLockedEngine(fGraphManager, GetSynchroTable(), fEngineControl);
fFreewheelDriver = new JackThreadedDriver(new JackFreewheelDriver(fEngine, GetSynchroTable()));
......@@ -60,7 +60,7 @@ JackServer::JackServer(bool sync, bool temporary, long timeout, bool rt, long pr
JackServer::~JackServer()
{
delete fGraphManager;
JackGraphManager::Destroy(fGraphManager);
delete fAudioDriver;
delete fDriverInfo;
delete fFreewheelDriver;
......
......@@ -62,7 +62,7 @@ class SERVER_EXPORT JackServer
public:
JackServer(bool sync, bool temporary, long timeout, bool rt, long priority, bool verbose, jack_timer_type_t clock, const char* server_name);
JackServer(bool sync, bool temporary, int timeout, bool rt, int priority, int port_max, bool verbose, jack_timer_type_t clock, const char* server_name);
~JackServer();
int Open(jack_driver_desc_t* driver_desc, JSList* driver_params);
......
......@@ -41,11 +41,12 @@ int JackServerGlobals::Start(const char* server_name,
int time_out_ms,
int rt,
int priority,
int port_max,
int verbose,
jack_timer_type_t clock)
{
jack_log("Jackdmp: sync = %ld timeout = %ld rt = %ld priority = %ld verbose = %ld ", sync, time_out_ms, rt, priority, verbose);
new JackServer(sync, temporary, time_out_ms, rt, priority, verbose, clock, server_name); // Will setup fInstance and fUserCount globals
new JackServer(sync, temporary, time_out_ms, rt, priority, port_max, verbose, clock, server_name); // Will setup fInstance and fUserCount globals
int res = fInstance->Open(driver_desc, driver_params);
return (res < 0) ? res : fInstance->Start();
}
......@@ -291,7 +292,7 @@ bool JackServerGlobals::Init()
free(argv[i]);
}
int res = Start(server_name, driver_desc, driver_params, sync, temporary, client_timeout, realtime, realtime_priority, verbose_aux, clock_source);
int res = Start(server_name, driver_desc, driver_params, sync, temporary, client_timeout, realtime, realtime_priority, port_max, verbose_aux, clock_source);
if (res < 0) {
jack_error("Cannot start server... exit");
Delete();
......
......@@ -54,6 +54,7 @@ struct SERVER_EXPORT JackServerGlobals
int time_out_ms,
int rt,
int priority,
int port_max,
int verbose,
jack_timer_type_t clock);
static void Stop();
......
......@@ -100,6 +100,7 @@ static void usage(FILE* file)
" [ --name OR -n server-name ]\n"
" [ --timeout OR -t client-timeout-in-msecs ]\n"
" [ --loopback OR -L loopback-port-number ]\n"
" [ --port-max OR -p maximum-number-of-ports]\n"
" [ --midi OR -X midi-driver ]\n"
" [ --verbose OR -v ]\n"
#ifdef __linux__
......@@ -220,7 +221,6 @@ int main(int argc, char* argv[])
char *midi_driver_name = NULL;
char **midi_driver_args = NULL;
int midi_driver_nargs = 1;
int port_max = 512;
int do_mlock = 1;
int do_unlock = 0;
int loopback = 0;
......@@ -291,7 +291,11 @@ int main(int argc, char* argv[])
break;
case 'p':
port_max = (unsigned int)atol(optarg);
param = jackctl_get_parameter(server_parameters, "port-max");
if (param != NULL) {
value.ui = atoi(optarg);
jackctl_parameter_set_value(param, &value);
}
break;
case 'm':
......
......@@ -68,8 +68,7 @@ def set_options(opt):
opt.add_option('--profile', action='store_true', default=False, help='Build with engine profiling')
opt.add_option('--mixed', action='store_true', default=False, help='Build with 32/64 bits mixed mode')
opt.add_option('--clients', default=64, type="int", dest="clients", help='Maximum number of JACK clients')
opt.add_option('--ports', default=2048, type="int", dest="ports", help='Maximum number of ports')
opt.add_option('--ports-per-application', default=512, type="int", dest="application_ports", help='Maximum number of ports per application')
opt.add_option('--ports-per-application', default=768, type="int", dest="application_ports", help='Maximum number of ports per application')
opt.sub_options('dbus')
def configure(conf):
......@@ -150,7 +149,6 @@ def configure(conf):
conf.env['LIBDIR'] = conf.env['PREFIX'] + '/lib'
conf.define('CLIENT_NUM', Options.options.clients)
conf.define('PORT_NUM', Options.options.ports)
conf.define('PORT_NUM_FOR_CLIENT', Options.options.application_ports)
conf.define('ADDON_DIR', os.path.normpath(os.path.join(conf.env['LIBDIR'], 'jack')))
......@@ -184,7 +182,6 @@ def configure(conf):
print version_msg
print "Build with a maximum of %d JACK clients" % conf.env['CLIENT_NUM']
print "Build with a maximum of %d ports" % conf.env['PORT_NUM']
print "Build with a maximum of %d ports per application" % conf.env['PORT_NUM_FOR_CLIENT']
display_msg("Install prefix", conf.env['PREFIX'], 'CYAN')
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment