Commit 8ce4a056 authored by sletz's avatar sletz
Browse files

Correct JackNetManager thread management.

git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@2791 0c269be4-1314-0410-8aa9-9f06e86f4224
parent 1ba7d7d5
......@@ -96,7 +96,9 @@ class JackAudioAdapterInterface
public:
JackAudioAdapterInterface(jack_nframes_t buffer_size, jack_nframes_t sample_rate)
:fBufferSize(buffer_size),
:fCaptureChannels(0),
fPlaybackChannels(0),
fBufferSize(buffer_size),
fSampleRate(sample_rate),
fProducerDLL(buffer_size, sample_rate),
fConsumerDLL(buffer_size, sample_rate),
......
......@@ -19,6 +19,8 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include "JackNetAdapter.h"
#include "JackException.h"
#include "JackServer.h"
#include "JackEngineControl.h"
#define DEFAULT_MULTICAST_IP "225.3.19.154"
#define DEFAULT_PORT 19000
......@@ -110,30 +112,60 @@ namespace Jack
JackNetAdapter::~JackNetAdapter()
{
jack_log ( "JackNetAdapter::~JackNetAdapter" );
int port_index;
for ( port_index = 0; port_index < fCaptureChannels; port_index++ )
delete[] fSoftCaptureBuffer[port_index];
delete[] fSoftCaptureBuffer;
for ( port_index = 0; port_index < fPlaybackChannels; port_index++ )
delete[] fSoftPlaybackBuffer[port_index];
delete[] fSoftPlaybackBuffer;
if (fSoftCaptureBuffer) {
for ( port_index = 0; port_index < fCaptureChannels; port_index++ )
delete[] fSoftCaptureBuffer[port_index];
delete[] fSoftCaptureBuffer;
}
if (fSoftPlaybackBuffer) {
for ( port_index = 0; port_index < fPlaybackChannels; port_index++ )
delete[] fSoftPlaybackBuffer[port_index];
delete[] fSoftPlaybackBuffer;
}
}
int JackNetAdapter::Open()
{
jack_log ( "JackNetAdapter::Open" );
jack_info ( "Net adapter started in %s mode %s Master's transport sync.",
( fParams.fSlaveSyncMode ) ? "sync" : "async", ( fParams.fTransportSync ) ? "with" : "without" );
fThread.AcquireRealTime ( 85 );
return fThread.StartSync();
}
if (fThread.StartSync() < 0) {
jack_error("Cannot start netadapter thread");
return -1;
}
fThread.AcquireRealTime(JackServer::fInstance->GetEngineControl()->fPriority);
return 0;
}
int JackNetAdapter::Close()
{
fThread.Stop();
switch (fThread.GetStatus()) {
// Kill the thread in Init phase
case JackThread::kStarting:
case JackThread::kIniting:
if (fThread.Kill() < 0) {
jack_error("Cannot kill thread");
return -1;
}
break;
// Stop when the thread cycle is finished
case JackThread::kRunning:
if (fThread.Stop() < 0) {
jack_error("Cannot stop thread");
return -1;
}
break;
default:
break;
}
fSocket.Close();
return 0;
}
......
......@@ -30,21 +30,43 @@ namespace Jack
{
// JackNetInterface*******************************************
JackNetInterface::JackNetInterface() : fSocket()
{
fMulticastIP = NULL;
fTxBuffer = NULL;
fRxBuffer = NULL;
fNetAudioCaptureBuffer = NULL;
fNetAudioPlaybackBuffer = NULL;
fNetMidiCaptureBuffer = NULL;
fNetMidiPlaybackBuffer = NULL;
}
JackNetInterface::JackNetInterface ( const char* multicast_ip, int port ) : fSocket ( multicast_ip, port )
{
fMulticastIP = strdup ( multicast_ip );
fTxBuffer = NULL;
fRxBuffer = NULL;
fNetAudioCaptureBuffer = NULL;
fNetAudioPlaybackBuffer = NULL;
fNetMidiCaptureBuffer = NULL;
fNetMidiPlaybackBuffer = NULL;
}
JackNetInterface::JackNetInterface ( session_params_t& params, JackNetSocket& socket, const char* multicast_ip ) : fSocket ( socket )
{
fParams = params;
fMulticastIP = strdup ( multicast_ip );
fTxBuffer = NULL;
fRxBuffer = NULL;
fNetAudioCaptureBuffer = NULL;
fNetAudioPlaybackBuffer = NULL;
fNetMidiCaptureBuffer = NULL;
fNetMidiPlaybackBuffer = NULL;
}
JackNetInterface::~JackNetInterface()
{
jack_log ( "JackNetInterface::~JackNetInterface" );
fSocket.Close();
delete[] fTxBuffer;
delete[] fRxBuffer;
......
......@@ -76,8 +76,7 @@ namespace Jack
virtual int Send ( size_t size, int flags ) = 0;
virtual int Recv ( size_t size, int flags ) = 0;
JackNetInterface() : fSocket()
{}
JackNetInterface();
JackNetInterface ( const char* multicast_ip, int port );
JackNetInterface ( session_params_t& params, JackNetSocket& socket, const char* multicast_ip );
......
......@@ -22,6 +22,8 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#endif
#include "JackAlsaAdapter.h"
#include "JackServer.h"
#include "JackEngineControl.h"
namespace Jack
{
......@@ -75,13 +77,17 @@ namespace Jack
int JackAlsaAdapter::Open()
{
if (fAudioInterface.open() == 0) {
fAudioInterface.longinfo();
fThread.AcquireRealTime(85);
return fThread.StartSync();
} else {
if (fAudioInterface.open() != 0)
return -1;
if (fThread.StartSync() < 0) {
jack_error("Cannot start audioadapter thread");
return -1;
}
fAudioInterface.longinfo();
fThread.AcquireRealTime(JackServer::fInstance->GetEngineControl()->fPriority);
return 0;
}
int JackAlsaAdapter::Close()
......@@ -89,7 +95,28 @@ int JackAlsaAdapter::Close()
#ifdef JACK_MONITOR
fTable.Save();
#endif
fThread.Stop();
switch (fThread.GetStatus()) {
// Kill the thread in Init phase
case JackThread::kStarting:
case JackThread::kIniting:
if (fThread.Kill() < 0) {
jack_error("Cannot kill thread");
return -1;
}
break;
// Stop when the thread cycle is finished
case JackThread::kRunning:
if (fThread.Stop() < 0) {
jack_error("Cannot stop thread");
return -1;
}
break;
default:
break;
}
return fAudioInterface.close();
}
......
......@@ -173,7 +173,7 @@ class AudioInterface : public AudioParam
jack_info("inputs : %ud, outputs : %ud", fCardInputs, fCardOutputs);
// enregistrement des parametres d'entree-sortie
err = snd_pcm_hw_params(fInputDevice, fInputParams); check_error (err);
err = snd_pcm_hw_params(fInputDevice, fInputParams); check_error (err);
err = snd_pcm_hw_params(fOutputDevice, fOutputParams); check_error (err);
// allocation of alsa buffers
......
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