Cleanup of backend stack.

git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@4645 0c269be4-1314-0410-8aa9-9f06e86f4224
This commit is contained in:
sletz 2011-12-15 10:08:10 +00:00
parent 9f9f682ab2
commit 4f60f19c2f
12 changed files with 136 additions and 130 deletions

View File

@ -226,16 +226,6 @@ int JackAudioDriver::Process()
return (fEngineControl->fSyncMode) ? ProcessSync() : ProcessAsync();
}
void JackAudioDriver::ProcessGraphAsync()
{
// Process graph
if (fIsMaster) {
ProcessGraphAsyncMaster();
} else {
ProcessGraphAsyncSlave();
}
}
/*
The driver ASYNC mode: output buffers computed at the *previous cycle* are used, the server does not
synchronize to the end of client graph execution.
@ -263,22 +253,43 @@ int JackAudioDriver::ProcessAsync()
return 0;
}
void JackAudioDriver::ProcessGraphSync()
void JackAudioDriver::ProcessGraphAsync()
{
// Process graph
if (fIsMaster) {
if (ProcessGraphSyncMaster() < 0) {
//jack_error("JackAudioDriver::ProcessSync: process error, skip cycle...");
//goto end;
}
ProcessGraphAsyncMaster();
} else {
if (ProcessGraphSyncSlave() < 0) {
//jack_error("JackAudioDriver::ProcessSync: process error, skip cycle...");
//goto end;
}
ProcessGraphAsyncSlave();
}
}
void JackAudioDriver::ProcessGraphAsyncMaster()
{
// fBeginDateUst is set in the "low level" layer, fEndDateUst is from previous cycle
if (!fEngine->Process(fBeginDateUst, fEndDateUst)) {
jack_error("JackAudioDriver::ProcessGraphAsyncMaster: Process error");
}
if (fGraphManager->ResumeRefNum(&fClientControl, fSynchroTable) < 0) {
jack_error("JackAudioDriver::ProcessGraphAsyncMaster: ResumeRefNum error");
}
if (ProcessReadSlaves() < 0) {
jack_error("JackAudioDriver::ProcessGraphAsyncMaster: ProcessReadSlaves error");
}
if (ProcessWriteSlaves() < 0) {
jack_error("JackAudioDriver::ProcessGraphAsyncMaster: ProcessWriteSlaves error");
}
// Does not wait on graph execution end
}
void JackAudioDriver::ProcessGraphAsyncSlave()
{
if (fGraphManager->ResumeRefNum(&fClientControl, fSynchroTable) < 0)
jack_error("JackAudioDriver::ProcessGraphAsyncSlave: ResumeRefNum error");
}
/*
The driver SYNC mode: the server does synchronize to the end of client graph execution,
@ -307,85 +318,48 @@ int JackAudioDriver::ProcessSync()
return 0;
}
void JackAudioDriver::ProcessGraphAsyncMaster()
void JackAudioDriver::ProcessGraphSync()
{
// fBeginDateUst is set in the "low level" layer, fEndDateUst is from previous cycle
if (!fEngine->Process(fBeginDateUst, fEndDateUst))
jack_error("JackAudioDriver::ProcessGraphAsyncMaster: Process error");
if (fGraphManager->ResumeRefNum(&fClientControl, fSynchroTable) < 0)
jack_error("JackAudioDriver::ProcessGraphAsyncMaster: ResumeRefNum error");
if (ProcessReadSlaves() < 0)
jack_error("JackAudioDriver::ProcessGraphAsyncMaster: ProcessReadSlaves error");
if (ProcessWriteSlaves() < 0)
jack_error("JackAudioDriver::ProcessGraphAsyncMaster: ProcessWriteSlaves error");
// Process graph
if (fIsMaster) {
ProcessGraphSyncMaster();
} else {
ProcessGraphSyncSlave();
}
}
void JackAudioDriver::ProcessGraphAsyncSlave()
void JackAudioDriver::ProcessGraphSyncMaster()
{
if (fGraphManager->ResumeRefNum(&fClientControl, fSynchroTable) < 0)
jack_error("JackAudioDriver::ProcessGraphAsyncSlave: ResumeRefNum error");
}
int JackAudioDriver::ProcessGraphSyncMaster()
{
int res = 0;
// fBeginDateUst is set in the "low level" layer, fEndDateUst is from previous cycle
if (fEngine->Process(fBeginDateUst, fEndDateUst)) {
if (fGraphManager->ResumeRefNum(&fClientControl, fSynchroTable) < 0) {
jack_error("JackAudioDriver::ProcessGraphSyncMaster: ResumeRefNum error");
res = -1;
}
if (ProcessReadSlaves() < 0) {
jack_error("JackAudioDriver::ProcessGraphSync: ProcessReadSlaves error, engine may now behave abnormally!!");
res = -1;
}
if (ProcessWriteSlaves() < 0) {
jack_error("JackAudioDriver::ProcessGraphSync: ProcessWriteSlaves error, engine may now behave abnormally!!");
res = -1;
}
// Waits for graph execution end
if (fGraphManager->SuspendRefNum(&fClientControl, fSynchroTable, DRIVER_TIMEOUT_FACTOR * fEngineControl->fTimeOutUsecs) < 0) {
jack_error("JackAudioDriver::ProcessGraphSync: SuspendRefNum error, engine may now behave abnormally!!");
res = -1;
}
} else { // Graph not finished: do not activate it
jack_error("JackAudioDriver::ProcessGraphSync: Process error");
res = -1;
}
return res;
}
int JackAudioDriver::ProcessGraphSyncSlave()
void JackAudioDriver::ProcessGraphSyncSlave()
{
return fGraphManager->ResumeRefNum(&fClientControl, fSynchroTable);
}
int JackAudioDriver::Start()
{
int res = JackDriver::Start();
if ((res >= 0) && fIsMaster) {
res = StartSlaves();
if (fGraphManager->ResumeRefNum(&fClientControl, fSynchroTable) < 0) {
jack_error("JackAudioDriver::ProcessGraphSyncSlave: ResumeRefNum error");
}
return res;
}
int JackAudioDriver::Stop()
{
int res = JackDriver::Stop();
if (fIsMaster) {
if (StopSlaves() < 0) {
res = -1;
}
}
return res;
}
jack_default_audio_sample_t* JackAudioDriver::GetInputBuffer(int port_index)

View File

@ -49,8 +49,8 @@ class SERVER_EXPORT JackAudioDriver : public JackDriver
int ProcessSync();
void ProcessGraphSync();
int ProcessGraphSyncMaster();
int ProcessGraphSyncSlave();
void ProcessGraphSyncMaster();
void ProcessGraphSyncSlave();
public:
@ -84,9 +84,6 @@ class SERVER_EXPORT JackAudioDriver : public JackDriver
virtual int Attach();
virtual int Detach();
virtual int Start();
virtual int Stop();
virtual int Write();
virtual int SetBufferSize(jack_nframes_t buffer_size);

View File

@ -343,10 +343,30 @@ int JackDriver::ProcessWriteSlaves()
int JackDriver::ProcessRead()
{
return 0;
return (fEngineControl->fSyncMode) ? ProcessReadSync() : ProcessReadAsync();
}
int JackDriver::ProcessWrite()
{
return (fEngineControl->fSyncMode) ? ProcessWriteSync() : ProcessWriteAsync();
}
int JackDriver::ProcessReadSync()
{
return 0;
}
int JackDriver::ProcessWriteSync()
{
return 0;
}
int JackDriver::ProcessReadAsync()
{
return 0;
}
int JackDriver::ProcessWriteAsync()
{
return 0;
}
@ -382,13 +402,13 @@ int JackDriver::Start()
fEngineControl->InitFrameTime();
}
fIsRunning = true;
return 0;
return StartSlaves();
}
int JackDriver::Stop()
{
fIsRunning = false;
return 0;
return StopSlaves();
}
int JackDriver::StartSlaves()

View File

@ -97,12 +97,20 @@ class SERVER_EXPORT JackDriverInterface
virtual std::list<JackDriverInterface*> GetSlaves() = 0;
// For "master" driver
virtual int ProcessReadSlaves() = 0;
virtual int ProcessWriteSlaves() = 0;
// For "slave" driver
virtual int ProcessRead() = 0;
virtual int ProcessWrite() = 0;
virtual int ProcessReadSync() = 0;
virtual int ProcessWriteSync() = 0;
virtual int ProcessReadAsync() = 0;
virtual int ProcessWriteAsync() = 0;
virtual bool IsRealTime() const = 0;
virtual bool IsRunning() const = 0;
};
@ -172,6 +180,12 @@ class SERVER_EXPORT JackDriver : public JackDriverClientInterface
void NotifySampleRate(jack_nframes_t sample_rate); // SampleRate notification sent by the driver
void NotifyFailure(int code, const char* reason); // Failure notification sent by the driver
virtual void SaveConnections();
virtual void RestoreConnections();
virtual int StartSlaves();
virtual int StopSlaves();
public:
JackDriver(const char* name, const char* alias, JackLockedEngine* engine, JackSynchro* table);
@ -191,7 +205,7 @@ class SERVER_EXPORT JackDriver : public JackDriverClientInterface
virtual int Open();
virtual int Open (bool capturing,
virtual int Open(bool capturing,
bool playing,
int inchannels,
int outchannels,
@ -212,6 +226,7 @@ class SERVER_EXPORT JackDriver : public JackDriverClientInterface
const char* playback_driver_name,
jack_nframes_t capture_latency,
jack_nframes_t playback_latency);
virtual int Close();
virtual int Process();
@ -225,17 +240,19 @@ class SERVER_EXPORT JackDriver : public JackDriverClientInterface
virtual int Start();
virtual int Stop();
virtual int StartSlaves();
virtual int StopSlaves();
// For "master" driver
int ProcessReadSlaves();
int ProcessWriteSlaves();
// For "slave" driver
int ProcessRead();
int ProcessWrite();
virtual void SaveConnections();
virtual void RestoreConnections();
int ProcessReadSync();
int ProcessWriteSync();
int ProcessReadAsync();
int ProcessWriteAsync();
virtual bool IsFixedBufferSize();
virtual int SetBufferSize(jack_nframes_t buffer_size);

View File

@ -26,6 +26,8 @@
namespace Jack
{
// When used in "master" mode
int JackFreewheelDriver::Process()
{
int res = 0;
@ -54,15 +56,7 @@ int JackFreewheelDriver::Process()
return res;
}
int JackFreewheelDriver::ProcessRead()
{
return (fEngineControl->fSyncMode) ? ProcessReadSync() : ProcessReadAsync();
}
int JackFreewheelDriver::ProcessWrite()
{
return (fEngineControl->fSyncMode) ? ProcessWriteSync() : ProcessWriteAsync();
}
// When used in "slave" mode
int JackFreewheelDriver::ProcessReadSync()
{

View File

@ -47,9 +47,6 @@ class JackFreewheelDriver : public JackDriver
int Process();
int ProcessRead();
int ProcessWrite();
int ProcessReadSync();
int ProcessWriteSync();

View File

@ -30,15 +30,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
namespace Jack
{
int JackLoopbackDriver::ProcessRead()
{
return (fEngineControl->fSyncMode) ? ProcessReadSync() : ProcessReadAsync();
}
int JackLoopbackDriver::ProcessWrite()
{
return (fEngineControl->fSyncMode) ? ProcessWriteSync() : ProcessWriteAsync();
}
// When used in "slave" mode
int JackLoopbackDriver::ProcessReadSync()
{

View File

@ -48,9 +48,6 @@ class JackLoopbackDriver : public JackAudioDriver
{}
virtual ~JackLoopbackDriver()
{}
virtual int ProcessRead();
virtual int ProcessWrite();
};
} // end of namespace

View File

@ -133,16 +133,6 @@ int JackMidiDriver::SetBufferSize(jack_nframes_t buffer_size)
return 0;
}
int JackMidiDriver::ProcessRead()
{
return (fEngineControl->fSyncMode) ? ProcessReadSync() : ProcessReadAsync();
}
int JackMidiDriver::ProcessWrite()
{
return (fEngineControl->fSyncMode) ? ProcessWriteSync() : ProcessWriteAsync();
}
int JackMidiDriver::ProcessReadSync()
{
int res = 0;

View File

@ -65,9 +65,6 @@ class SERVER_EXPORT JackMidiDriver : public JackDriver
virtual int SetBufferSize(jack_nframes_t buffer_size);
virtual int ProcessRead();
virtual int ProcessWrite();
virtual int Attach();
virtual int Detach();

View File

@ -55,7 +55,12 @@ int JackThreadedDriver::Open(jack_nframes_t buffer_size,
jack_nframes_t capture_latency,
jack_nframes_t playback_latency)
{
return fDriver->Open(buffer_size, samplerate, capturing, playing, inchannels, outchannels, monitor, capture_driver_name, playback_driver_name, capture_latency, playback_latency);
return fDriver->Open(buffer_size,
samplerate, capturing,
playing, inchannels,
outchannels, monitor,
capture_driver_name, playback_driver_name,
capture_latency, playback_latency);
}
int JackThreadedDriver::Close()
@ -143,6 +148,26 @@ int JackThreadedDriver::ProcessWrite()
return fDriver->ProcessWrite();
}
int JackThreadedDriver::ProcessReadSync()
{
return fDriver->ProcessReadSync();
}
int JackThreadedDriver::ProcessWriteSync()
{
return fDriver->ProcessWriteSync();
}
int JackThreadedDriver::ProcessReadAsync()
{
return fDriver->ProcessReadAsync();
}
int JackThreadedDriver::ProcessWriteAsync()
{
return fDriver->ProcessWriteAsync();
}
std::list<JackDriverInterface*> JackThreadedDriver::GetSlaves()
{
return fDriver->GetSlaves();

View File

@ -28,7 +28,7 @@ namespace Jack
{
/*!
\brief The base class for threaded drivers. Threaded drivers are used with blocking devices.
\brief The base class for threaded drivers using a "decorator" pattern. Threaded drivers are used with blocking devices.
*/
class SERVER_EXPORT JackThreadedDriver : public JackDriverClientInterface, public JackRunnableInterface
@ -49,14 +49,14 @@ class SERVER_EXPORT JackThreadedDriver : public JackDriverClientInterface, publi
virtual int Open();
virtual int Open (bool capturing,
bool playing,
int inchannels,
int outchannels,
bool monitor,
const char* capture_driver_name,
const char* playback_driver_name,
jack_nframes_t capture_latency,
jack_nframes_t playback_latency)
bool playing,
int inchannels,
int outchannels,
bool monitor,
const char* capture_driver_name,
const char* playback_driver_name,
jack_nframes_t capture_latency,
jack_nframes_t playback_latency)
{
return -1;
}
@ -102,6 +102,12 @@ class SERVER_EXPORT JackThreadedDriver : public JackDriverClientInterface, publi
virtual int ProcessRead();
virtual int ProcessWrite();
virtual int ProcessReadSync();
virtual int ProcessWriteSync();
virtual int ProcessReadAsync();
virtual int ProcessWriteAsync();
virtual int ClientNotify(int refnum, const char* name, int notify, int sync, const char* message, int value1, int value2);
virtual JackClientControl* GetClientControl() const;
virtual bool IsRealTime() const;