Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DRAFT] Multi server by same client support #597

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
254 changes: 131 additions & 123 deletions common/JackAPI.cpp

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion common/JackAudioAdapterFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,15 @@ extern "C"
jack_nframes_t buffer_size = jack_get_buffer_size(jack_client);
jack_nframes_t sample_rate = jack_get_sample_rate(jack_client);


if (jack_client == NULL) {
jack_error("jack_internal_initialize called with NULL jack_client");
return 1;
}

try {

adapter = new Jack::JackAudioAdapter(jack_client, new Jack::JackPlatformAdapter(buffer_size, sample_rate, params), params);
adapter = new Jack::JackAudioAdapter(jack_client, new Jack::JackPlatformAdapter(*((JackClient*) jack_client), buffer_size, sample_rate, params), params);
assert(adapter);

if (adapter->Open() == 0) {
Expand Down
4 changes: 2 additions & 2 deletions common/JackAudioPort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ static void AudioBufferMixdown(void* mixbuffer, void** src_buffers, int src_coun
}
}

static size_t AudioBufferSize()
static size_t AudioBufferSize(JackGlobals *global)
{
return GetEngineControl()->fBufferSize * sizeof(jack_default_audio_sample_t);
return global->GetEngineControl()->fBufferSize * sizeof(jack_default_audio_sample_t);
}

const JackPortType gAudioPortType =
Expand Down
15 changes: 8 additions & 7 deletions common/JackClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ namespace Jack

#define IsRealTime() ((fProcess != NULL) | (fThreadFun != NULL) | (fSync != NULL) | (fTimebase != NULL))

JackClient::JackClient(JackSynchro* table):fThread(this)
JackClient::JackClient(JackGlobals* globals):JackGlobalsInterface(globals),
fThread(this)
{
fSynchroTable = table;
fSynchroTable = globals->GetSynchroTable();
fProcess = NULL;
fGraphOrder = NULL;
fXrun = NULL;
Expand Down Expand Up @@ -114,11 +115,12 @@ int JackClient::Close()
fChannel->ClientClose(GetClientControl()->fRefNum, &result);

fChannel->Close();
assert(JackGlobals::fSynchroMutex);
JackGlobals::fSynchroMutex->Lock();
assert(GetGlobal());
assert(GetGlobal()->fSynchroMutex);
GetGlobal()->fSynchroMutex->Lock();
fSynchroTable[GetClientControl()->fRefNum].Disconnect();
JackGlobals::fSynchroMutex->Unlock();
JackGlobals::fClientTable[GetClientControl()->fRefNum] = NULL;
GetGlobal()->fSynchroMutex->Unlock();
GetGlobal()->fClientTable[GetClientControl()->fRefNum] = nullptr;
return result;
}

Expand Down Expand Up @@ -1345,6 +1347,5 @@ int JackClient::PropertyChangeNotify(jack_uuid_t subject, const char* key, jack_
return result;
}


} // end of namespace

5 changes: 3 additions & 2 deletions common/JackClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "JackChannel.h"
#include "JackRequest.h"
#include "JackMetadata.h"
#include "JackGlobals.h"
#include "varargs.h"
#include <list>

Expand All @@ -45,7 +46,7 @@ struct JackEngineControl;
\brief The base class for clients: share part of the implementation for JackInternalClient and JackLibClient.
*/

class SERVER_EXPORT JackClient : public JackClientInterface, public JackRunnableInterface
class SERVER_EXPORT JackClient : public JackClientInterface, public JackRunnableInterface, public JackGlobalsInterface
{
friend class JackDebugClient;

Expand Down Expand Up @@ -128,7 +129,7 @@ class SERVER_EXPORT JackClient : public JackClientInterface, public JackRunnable

public:

JackClient(JackSynchro* table);
JackClient(JackGlobals* globals);
virtual ~JackClient();

char* GetServerName() { return fServerName; }
Expand Down
2 changes: 1 addition & 1 deletion common/JackConnectionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ bool JackConnectionManager::IsLoopPathAux(int ref1, int ref2) const
{
jack_log("JackConnectionManager::IsLoopPathAux ref1 = %ld ref2 = %ld", ref1, ref2);

if (ref1 < GetEngineControl()->fDriverNum || ref2 < GetEngineControl()->fDriverNum) {
if (ref1 < GetGlobal()->GetEngineControl()->fDriverNum || ref2 < GetGlobal()->GetEngineControl()->fDriverNum) {
return false;
} else if (ref1 == ref2) { // Same refnum
return true;
Expand Down
3 changes: 2 additions & 1 deletion common/JackConnectionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "JackConstants.h"
#include "JackActivationCount.h"
#include "JackError.h"
#include "JackGlobals.h"
#include "JackCompilerDeps.h"
#include <vector>
#include <assert.h>
Expand Down Expand Up @@ -408,7 +409,7 @@ struct JackClientTiming
*/

PRE_PACKED_STRUCTURE
class SERVER_EXPORT JackConnectionManager
class SERVER_EXPORT JackConnectionManager : public JackGlobalsInterface
{

private:
Expand Down
6 changes: 6 additions & 0 deletions common/JackConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@
#define PORT_NUM_FOR_CLIENT 768
#endif

// used by JackLib when process has mulitple clients connecting to different Jack Servers
#define PORT_SERVER_CONTEXT_BITS (8)
#define PORT_SERVER_CONTEXT_MAX ((1 << PORT_SERVER_CONTEXT_BITS) - 1)
#define PORT_SERVER_CONTEXT_SHIFT (sizeof(jack_port_id_t) * 8 - PORT_SERVER_CONTEXT_BITS)
#define PORT_SERVER_CONTEXT_MASK (PORT_SERVER_CONTEXT_MAX << PORT_SERVER_CONTEXT_SHIFT)

#define FIRST_AVAILABLE_PORT 1

#define CONNECTION_NUM_FOR_PORT PORT_NUM_FOR_CLIENT
Expand Down
9 changes: 8 additions & 1 deletion common/JackControlAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,12 @@ jackctl_server_open(
goto fail;
}

JackServerGlobals *global = JackGlobalsManager::Instance()->CreateGlobal<JackServerGlobals>(server_ptr->name.str);
if (global == nullptr) {
jack_error("Failed to create global context");
goto fail;
}

/* get the engine/driver started */
server_ptr->engine = new JackServer(
server_ptr->sync.b,
Expand All @@ -1063,7 +1069,8 @@ jackctl_server_open(
server_ptr->verbose.b,
(jack_timer_type_t)server_ptr->clock_source.ui,
server_ptr->self_connect_mode.c,
server_ptr->name.str);
server_ptr->name.str,
global);
if (server_ptr->engine == NULL)
{
jack_error("Failed to create new JackServer object");
Expand Down
2 changes: 1 addition & 1 deletion common/JackDebugClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace Jack
{

JackDebugClient::JackDebugClient(JackClient * client)
: JackClient(client->fSynchroTable)
: JackClient(client->GetGlobal())
{
fTotalPortNumber = 1; // The total number of port opened and maybe closed. Historical view.
fOpenPortNumber = 0; // The current number of opened port.
Expand Down
1 change: 1 addition & 0 deletions common/JackDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ typedef std::list<std::pair<std::string, std::pair<std::string, std::string> > >

class SERVER_EXPORT JackDriver : public JackDriverClientInterface
{
friend class JackThreadedDriver;

protected:

Expand Down
6 changes: 5 additions & 1 deletion common/JackEngineControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ struct SERVER_EXPORT JackEngineControl : public JackShmMem
JackEngineProfiling fProfiler;
#endif

JackEngineControl(bool sync, bool temporary, long timeout, bool rt, long priority, bool verbose, jack_timer_type_t clock, const char* server_name)
JackEngineControl(bool sync, bool temporary, long timeout, bool rt, long priority, bool verbose, jack_timer_type_t clock, const char* server_name, JackGlobals *global)
: fTransport(global)
#ifdef JACK_MONITOR
, fProfiler(global)
#endif
{
fBufferSize = 512;
fSampleRate = 48000;
Expand Down
4 changes: 2 additions & 2 deletions common/JackEngineProfiling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
namespace Jack
{

JackEngineProfiling::JackEngineProfiling():fAudioCycle(0),fMeasuredClient(0)
JackEngineProfiling::JackEngineProfiling(JackGlobals *global):fGlobal(global), fAudioCycle(0),fMeasuredClient(0)
{
jack_info("Engine profiling activated, beware %ld MBytes are needed to record profiling points...", sizeof(fProfileTable) / (1024 * 1024));

Expand Down Expand Up @@ -354,7 +354,7 @@ void JackEngineProfiling::Profile(JackClientInterface** table,
fProfileTable[fAudioCycle].fPrevCycleEnd = prev_cycle_end;
fProfileTable[fAudioCycle].fAudioCycle = fAudioCycle;

for (int i = GetEngineControl()->fDriverNum; i < CLIENT_NUM; i++) {
for (int i = fGlobal->GetEngineControl()->fDriverNum; i < CLIENT_NUM; i++) {
JackClientInterface* client = table[i];
JackClientTiming* timing = manager->GetClientTiming(i);
if (client && client->GetClientControl()->fActive && client->GetClientControl()->fCallback[kRealTimeCallback]) {
Expand Down
5 changes: 4 additions & 1 deletion common/JackEngineProfiling.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "JackTypes.h"
#include "JackConstants.h"
#include "JackShmMem.h"
#include "JackGlobals.h"

namespace Jack
{
Expand Down Expand Up @@ -111,6 +112,8 @@ class SERVER_EXPORT JackEngineProfiling

private:

JackGlobals* fGlobal;

JackTimingMeasure fProfileTable[TIME_POINTS];
JackTimingClientInterval fIntervalTable[MEASURED_CLIENTS];

Expand All @@ -121,7 +124,7 @@ class SERVER_EXPORT JackEngineProfiling

public:

JackEngineProfiling();
JackEngineProfiling(JackGlobals *global);
~JackEngineProfiling();

void Profile(JackClientInterface** table,
Expand Down
12 changes: 7 additions & 5 deletions common/JackGenericClientChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
namespace Jack
{

JackGenericClientChannel::JackGenericClientChannel()
{}
JackGenericClientChannel::JackGenericClientChannel(JackGlobals *global)
{
fGlobals = global;
}

JackGenericClientChannel::~JackGenericClientChannel()
{}
Expand All @@ -52,8 +54,8 @@ void JackGenericClientChannel::ServerSyncCall(JackRequest* req, JackResult* res,
*result = -1;
return;
}
if (!JackGlobals::fServerRunning) {

if (!fGlobals->fServerRunning) {
jack_error("Server is not running");
*result = -1;
return;
Expand Down Expand Up @@ -83,7 +85,7 @@ void JackGenericClientChannel::ServerAsyncCall(JackRequest* req, JackResult* res
return;
}

if (!JackGlobals::fServerRunning) {
if (!fGlobals->fServerRunning) {
jack_error("Server is not running");
*result = -1;
return;
Expand Down
5 changes: 4 additions & 1 deletion common/JackGenericClientChannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace Jack

struct JackRequest;
struct JackResult;
class JackGlobals;

/*!
\brief Generic JackClientChannel class.
Expand All @@ -37,14 +38,16 @@ class JackGenericClientChannel : public detail::JackClientChannelInterface

protected:

JackGlobals *fGlobals;

detail::JackClientRequestInterface* fRequest;

void ServerSyncCall(JackRequest* req, JackResult* res, int* result);
void ServerAsyncCall(JackRequest* req, JackResult* res, int* result);

public:

JackGenericClientChannel();
JackGenericClientChannel(JackGlobals *global);
virtual ~JackGenericClientChannel();

virtual int Open(const char* server_name, const char* name, jack_uuid_t uuid, char* name_res, JackClient* obj, jack_options_t options, jack_status_t* status) { return -1; }
Expand Down
17 changes: 14 additions & 3 deletions common/JackGlobals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ jack_tls_key JackGlobals::fKeyLogFunction;
static bool fKeyLogFunctionInitialized = jack_tls_allocate_key(&JackGlobals::fKeyLogFunction);

JackMutex* JackGlobals::fOpenMutex = new JackMutex();
JackMutex* JackGlobals::fSynchroMutex = new JackMutex();
volatile bool JackGlobals::fServerRunning = false;
JackClient* JackGlobals::fClientTable[CLIENT_NUM] = {};

JackGlobalsManager JackGlobalsManager::fInstance;

#ifndef WIN32
jack_thread_creator_t JackGlobals::fJackThreadCreator = pthread_create;
Expand Down Expand Up @@ -78,4 +77,16 @@ void JackGlobals::CheckContext(const char* name)

#endif

JackGlobals::JackGlobals(const std::string &server_name)
: fServerRunning(false)
, fSynchroMutex(new JackMutex)
, fServerName(server_name)
{
}

JackGlobals::~JackGlobals()
{
delete fSynchroMutex;
}

} // end of namespace
Loading