git-svn-id: http://subversion.jackaudio.org/jack/jack2/branches/libjacknet@3926 0c269be4-1314-0410-8aa9-9f06e86f4224tags/1.9.8
@@ -181,8 +181,6 @@ namespace Jack | |||
{ | |||
if (fRingbufferCurSize > DEFAULT_RB_SIZE) | |||
fRingbufferCurSize = DEFAULT_RB_SIZE; | |||
jack_log("JackAudioAdapterInterface::ResetRingBuffers new_size = %ld", fRingbufferCurSize); | |||
for (int i = 0; i < fCaptureChannels; i++) | |||
fCaptureRingBuffer[i]->Reset(fRingbufferCurSize); | |||
@@ -24,6 +24,8 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |||
using namespace std; | |||
#define PACKET_AVAILABLE_SIZE (fParams.fMtu - sizeof(packet_header_t)) | |||
/* | |||
TODO : since midi buffers now uses up to BUFFER_SIZE_MAX frames, | |||
probably also use BUFFER_SIZE_MAX in everything related to MIDI events | |||
@@ -61,6 +63,7 @@ namespace Jack | |||
JackNetInterface::JackNetInterface ( session_params_t& params, JackNetSocket& socket, const char* multicast_ip ) : fSocket ( socket ) | |||
{ | |||
jack_log("JackNetInterface ( session_params_t& params...)"); | |||
fParams = params; | |||
strcpy(fMulticastIP, multicast_ip); | |||
fTxBuffer = NULL; | |||
@@ -93,7 +96,7 @@ namespace Jack | |||
if (fParams.fSendAudioChannels == 0 && fParams.fReturnAudioChannels == 0) { | |||
fParams.fFramesPerPacket = fParams.fPeriodSize; | |||
} else { | |||
jack_nframes_t period = ( int ) powf ( 2.f, ( int ) ( log (float ( fParams.fMtu - sizeof ( packet_header_t ) ) | |||
jack_nframes_t period = ( int ) powf ( 2.f, ( int ) ( log (float (PACKET_AVAILABLE_SIZE) | |||
/ ( max ( fParams.fReturnAudioChannels, fParams.fSendAudioChannels ) * sizeof ( sample_t ) ) ) / log ( 2. ) ) ); | |||
fParams.fFramesPerPacket = ( period > fParams.fPeriodSize ) ? fParams.fPeriodSize : period; | |||
} | |||
@@ -109,7 +112,7 @@ namespace Jack | |||
audio_size = fParams.fMtu * ( fParams.fPeriodSize / fParams.fFramesPerPacket ); | |||
//midi | |||
midi_size = fParams.fMtu * ( max ( fParams.fSendMidiChannels, fParams.fReturnMidiChannels ) * | |||
fParams.fPeriodSize * sizeof ( sample_t ) / ( fParams.fMtu - sizeof ( packet_header_t ) ) ); | |||
fParams.fPeriodSize * sizeof(sample_t) / PACKET_AVAILABLE_SIZE); | |||
//bufsize = sync + audio + midi | |||
bufsize = MAX_LATENCY * (fParams.fMtu + ( int ) audio_size + ( int ) midi_size); | |||
@@ -128,13 +131,14 @@ namespace Jack | |||
{ | |||
//even if there is no midi data, jack need an empty buffer to know there is no event to read | |||
//99% of the cases : all data in one packet | |||
if ( fTxHeader.fMidiDataSize <= ( fParams.fMtu - sizeof ( packet_header_t ) ) ) | |||
if (fTxHeader.fMidiDataSize <= PACKET_AVAILABLE_SIZE) { | |||
return 1; | |||
//else, get the number of needed packets (simply slice the biiig buffer) | |||
int npckt = fTxHeader.fMidiDataSize / ( fParams.fMtu - sizeof ( packet_header_t ) ); | |||
if ( fTxHeader.fMidiDataSize % ( fParams.fMtu - sizeof ( packet_header_t ) ) ) | |||
return ++npckt; | |||
return npckt; | |||
} else { //get the number of needed packets (simply slice the biiig buffer) | |||
return (fTxHeader.fMidiDataSize % PACKET_AVAILABLE_SIZE) | |||
? (fTxHeader.fMidiDataSize / PACKET_AVAILABLE_SIZE + 1) | |||
: fTxHeader.fMidiDataSize / PACKET_AVAILABLE_SIZE; | |||
} | |||
} | |||
bool JackNetInterface::IsNextPacket() | |||
@@ -162,7 +166,7 @@ namespace Jack | |||
fNSubProcess = fParams.fPeriodSize / fParams.fFramesPerPacket; | |||
//payload size | |||
fPayloadSize = fParams.fMtu - sizeof ( packet_header_t ); | |||
fPayloadSize = PACKET_AVAILABLE_SIZE; | |||
//TX header init | |||
strcpy ( fTxHeader.fPacketType, "header" ); | |||
@@ -460,10 +464,11 @@ namespace Jack | |||
// - if the network is two fast, just wait the next cycle, this mode allows a shorter cycle duration for the master | |||
// - this mode will skip the two first cycles, thus it lets time for data to be processed and queued on the socket rx buffer | |||
//the slow mode is the safest mode because it wait twice the bandwidth relative time (send/return + process) | |||
if (fCycleOffset < 2) | |||
return 0; | |||
else | |||
if (fCycleOffset < 2) { | |||
return 0; | |||
} else { | |||
rx_bytes = Recv ( rx_head->fPacketSize, 0 ); | |||
} | |||
if (fCycleOffset > 2) { | |||
jack_info("Warning : '%s' runs in slow network mode, but data received too late (%d cycle(s) offset)", fParams.fName, fCycleOffset); | |||
@@ -475,13 +480,15 @@ namespace Jack | |||
// - extra latency is set to one cycle, what is the time needed to receive streams using full network bandwidth | |||
// - if the network is too fast, just wait the next cycle, the benefit here is the master's cycle is shorter | |||
// - indeed, data is supposed to be on the network rx buffer, so we don't have to wait for it | |||
if (fCycleOffset < 1) | |||
if (fCycleOffset < 1) { | |||
return 0; | |||
else | |||
} else { | |||
rx_bytes = Recv ( rx_head->fPacketSize, 0 ); | |||
} | |||
if (fCycleOffset != 1) | |||
if (fCycleOffset != 1) { | |||
jack_info("'%s' can't run in normal network mode, data received too late (%d cycle(s) offset)", fParams.fName, fCycleOffset); | |||
} | |||
break; | |||
case 'f' : | |||
@@ -491,8 +498,9 @@ namespace Jack | |||
// - but if there is a cycle offset, tell the user, that means we're not in fast mode anymore, network is too slow | |||
rx_bytes = Recv ( rx_head->fPacketSize, 0 ); | |||
if (fCycleOffset != 0) | |||
if (fCycleOffset != 0) { | |||
jack_info("'%s' can't run in fast network mode, data received too late (%d cycle(s) offset)", fParams.fName, fCycleOffset); | |||
} | |||
break; | |||
} | |||
@@ -539,9 +547,6 @@ namespace Jack | |||
case 'a': //audio | |||
rx_bytes = Recv ( rx_head->fPacketSize, 0 ); | |||
// SL: 25/01/09 | |||
// if ( !IsNextPacket() ) | |||
// jack_error ( "Packet(s) missing from '%s'...", fParams.fName ); | |||
if (recvd_audio_pckt++ != rx_head->fSubCycle) { | |||
jack_error("Packet(s) missing from '%s'...", fParams.fSlaveNetName); | |||
} | |||
@@ -553,10 +558,6 @@ namespace Jack | |||
break; | |||
case 's': //sync | |||
/* SL: 25/01/09 | |||
if ( rx_head->fCycle == fTxHeader.fCycle ) | |||
return 0; | |||
*/ | |||
jack_info("NetMaster : overloaded, skipping receive from '%s'", fParams.fName); | |||
return 0; | |||
} | |||
@@ -805,16 +806,15 @@ namespace Jack | |||
{ | |||
net_error_t error = fSocket.GetError(); | |||
//no data isn't really an error in realtime processing, so just return 0 | |||
if ( error == NET_NO_DATA ) | |||
if ( error == NET_NO_DATA ) { | |||
jack_error ( "No data, is the master still running ?" ); | |||
//if a network error occurs, this exception will restart the driver | |||
else if ( error == NET_CONN_ERROR ) | |||
{ | |||
} else if ( error == NET_CONN_ERROR ) { | |||
jack_error ( "Connection lost." ); | |||
throw JackNetException(); | |||
} | |||
else | |||
} else { | |||
jack_error ( "Fatal error in slave receive : %s", StrError ( NET_ERROR_CODE ) ); | |||
} | |||
} | |||
packet_header_t* header = reinterpret_cast<packet_header_t*>(fRxBuffer); | |||
@@ -833,13 +833,12 @@ namespace Jack | |||
{ | |||
net_error_t error = fSocket.GetError(); | |||
//if a network error occurs, this exception will restart the driver | |||
if ( error == NET_CONN_ERROR ) | |||
{ | |||
if ( error == NET_CONN_ERROR ) { | |||
jack_error ( "Connection lost." ); | |||
throw JackNetException(); | |||
} | |||
else | |||
} else { | |||
jack_error ( "Fatal error in slave send : %s", StrError ( NET_ERROR_CODE ) ); | |||
} | |||
} | |||
return tx_bytes; | |||
} | |||
@@ -848,6 +847,7 @@ namespace Jack | |||
{ | |||
int rx_bytes = 0; | |||
packet_header_t* rx_head = reinterpret_cast<packet_header_t*> ( fRxBuffer ); | |||
//receive sync (launch the cycle) | |||
do | |||
{ | |||
@@ -885,17 +885,16 @@ namespace Jack | |||
fRxHeader.fCycle = rx_head->fCycle; | |||
fRxHeader.fIsLastPckt = rx_head->fIsLastPckt; | |||
fNetMidiCaptureBuffer->RenderFromNetwork ( rx_head->fSubCycle, rx_bytes - sizeof ( packet_header_t ) ); | |||
// Last midi packet is received, so finish rendering... | |||
if ( ++recvd_midi_pckt == rx_head->fNMidiPckt ) | |||
fNetMidiCaptureBuffer->RenderToJackPorts(); | |||
break; | |||
case 'a': //audio | |||
rx_bytes = Recv ( rx_head->fPacketSize, 0 ); | |||
//SL: 25/01/09 | |||
// if ( !IsNextPacket() ) | |||
// jack_error ( "Packet(s) missing..." ); | |||
if (recvd_audio_pckt++ != rx_head->fSubCycle) { | |||
jack_error("Packet(s) missing from '%s'...", fParams.fMasterNetName); | |||
//jack_error("Packet(s) missing from '%s'...", fParams.fMasterNetName); | |||
jack_error("Packet(s) missing from '%s'... %d %d %d", fParams.fMasterNetName, rx_head->fCycle, recvd_audio_pckt, rx_head->fSubCycle); | |||
} | |||
fRxHeader.fCycle = rx_head->fCycle; | |||
fRxHeader.fSubCycle = rx_head->fSubCycle; | |||
@@ -71,6 +71,12 @@ | |||
4B4146AA10BD3C4300C12F0C /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1DF5F4DF0D08C38300B7A737 /* UIKit.framework */; }; | |||
4B4146AB10BD3C4300C12F0C /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 288765FC0DF74451002DB57D /* CoreGraphics.framework */; }; | |||
4B4146AC10BD3C4300C12F0C /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4B1A95750F49CEAB00D3626B /* AudioToolbox.framework */; }; | |||
4B9CB1371136CA99007DE01A /* icon.png in Resources */ = {isa = PBXBuildFile; fileRef = 4B9CB1361136CA99007DE01A /* icon.png */; }; | |||
4B9CB1381136CA99007DE01A /* icon.png in Resources */ = {isa = PBXBuildFile; fileRef = 4B9CB1361136CA99007DE01A /* icon.png */; }; | |||
4B9CB1391136CA99007DE01A /* icon.png in Resources */ = {isa = PBXBuildFile; fileRef = 4B9CB1361136CA99007DE01A /* icon.png */; }; | |||
4B9CB13A1136CA99007DE01A /* icon.png in Resources */ = {isa = PBXBuildFile; fileRef = 4B9CB1361136CA99007DE01A /* icon.png */; }; | |||
4B9CB13B1136CA99007DE01A /* icon.png in Resources */ = {isa = PBXBuildFile; fileRef = 4B9CB1361136CA99007DE01A /* icon.png */; }; | |||
4B9CB13C1136CA99007DE01A /* icon.png in Resources */ = {isa = PBXBuildFile; fileRef = 4B9CB1361136CA99007DE01A /* icon.png */; }; | |||
4BBDC8FA0F5420C000465F9C /* freeverb.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4BBDC8F90F5420C000465F9C /* freeverb.mm */; }; | |||
4BC9C1F71135AB2800D22670 /* main_master.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4B0772500F54022D000DC657 /* main_master.mm */; }; | |||
4BCB37B6112D647C008C7BC1 /* MainWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 28AD733E0D9D9553002E5188 /* MainWindow.xib */; }; | |||
@@ -160,12 +166,13 @@ | |||
4B1A95750F49CEAB00D3626B /* AudioToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.2.1.sdk/System/Library/Frameworks/AudioToolbox.framework; sourceTree = "<absolute>"; }; | |||
4B2791870F72570C000536B7 /* JackGlobals.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = JackGlobals.cpp; path = ../../common/JackGlobals.cpp; sourceTree = SOURCE_ROOT; }; | |||
4B4146B010BD3C4300C12F0C /* iPhoneFaustNet.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = iPhoneFaustNet.app; sourceTree = BUILT_PRODUCTS_DIR; }; | |||
4B9CB1361136CA99007DE01A /* icon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = icon.png; sourceTree = SOURCE_ROOT; }; | |||
4BBDC8F90F5420C000465F9C /* freeverb.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = freeverb.mm; sourceTree = SOURCE_ROOT; }; | |||
4BC9C1D31135AA1800D22670 /* iPhoneNetMasterAppl-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "iPhoneNetMasterAppl-Info.plist"; sourceTree = "<group>"; }; | |||
4BCB37CE112D647C008C7BC1 /* iPhoneFaust.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = iPhoneFaust.app; sourceTree = BUILT_PRODUCTS_DIR; }; | |||
4BCB37D5112D64B4008C7BC1 /* HardwareClock.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HardwareClock.cpp; sourceTree = SOURCE_ROOT; }; | |||
4BCB37D8112D64D8008C7BC1 /* iphone-faust.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "iphone-faust.mm"; sourceTree = SOURCE_ROOT; }; | |||
4BCF75F210BC2FD90082C526 /* iPhoneFaustNet.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = iPhoneFaustNet.app; sourceTree = BUILT_PRODUCTS_DIR; }; | |||
4BCF75F210BC2FD90082C526 /* iPhoneThruNet.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = iPhoneThruNet.app; sourceTree = BUILT_PRODUCTS_DIR; }; | |||
4BCF75F610BC30140082C526 /* audio_thru.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = audio_thru.mm; sourceTree = SOURCE_ROOT; }; | |||
4BF1360E0F4B0B4C00218A3F /* JackAudioAdapterInterface.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = JackAudioAdapterInterface.cpp; path = ../../common/JackAudioAdapterInterface.cpp; sourceTree = SOURCE_ROOT; }; | |||
4BF136120F4B0B5E00218A3F /* JackAudioAdapterInterface.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = JackAudioAdapterInterface.h; path = ../../common/JackAudioAdapterInterface.h; sourceTree = SOURCE_ROOT; }; | |||
@@ -263,7 +270,7 @@ | |||
4BFF45120F4D59DB00106083 /* libjacknet.a */, | |||
4BFF45770F4D5D9700106083 /* iPhoneFaustNet.app */, | |||
4B0772380F54018C000DC657 /* iPhoneNetMaster.app */, | |||
4BCF75F210BC2FD90082C526 /* iPhoneFaustNet.app */, | |||
4BCF75F210BC2FD90082C526 /* iPhoneThruNet.app */, | |||
4B4146B010BD3C4300C12F0C /* iPhoneFaustNet.app */, | |||
4BCB37CE112D647C008C7BC1 /* iPhoneFaust.app */, | |||
); | |||
@@ -318,6 +325,7 @@ | |||
29B97317FDCFA39411CA2CEA /* Resources */ = { | |||
isa = PBXGroup; | |||
children = ( | |||
4B9CB1361136CA99007DE01A /* icon.png */, | |||
28AD733E0D9D9553002E5188 /* MainWindow.xib */, | |||
8D1107310486CEB800E47090 /* Info.plist */, | |||
4BC9C1D31135AA1800D22670 /* iPhoneNetMasterAppl-Info.plist */, | |||
@@ -389,9 +397,9 @@ | |||
productReference = 4B0772380F54018C000DC657 /* iPhoneNetMaster.app */; | |||
productType = "com.apple.product-type.application"; | |||
}; | |||
4B1A940F0F49BDE000D3626B /* jacknet */ = { | |||
4B1A940F0F49BDE000D3626B /* libjacknet */ = { | |||
isa = PBXNativeTarget; | |||
buildConfigurationList = 4B1A94130F49BDFF00D3626B /* Build configuration list for PBXNativeTarget "jacknet" */; | |||
buildConfigurationList = 4B1A94130F49BDFF00D3626B /* Build configuration list for PBXNativeTarget "libjacknet" */; | |||
buildPhases = ( | |||
4B1A940C0F49BDE000D3626B /* Headers */, | |||
4B1A940D0F49BDE000D3626B /* Sources */, | |||
@@ -401,7 +409,7 @@ | |||
); | |||
dependencies = ( | |||
); | |||
name = jacknet; | |||
name = libjacknet; | |||
productName = jacknet; | |||
productReference = 4BFF45120F4D59DB00106083 /* libjacknet.a */; | |||
productType = "com.apple.product-type.library.static"; | |||
@@ -454,7 +462,7 @@ | |||
); | |||
name = iPhoneThruNet; | |||
productName = iPhoneNet; | |||
productReference = 4BCF75F210BC2FD90082C526 /* iPhoneFaustNet.app */; | |||
productReference = 4BCF75F210BC2FD90082C526 /* iPhoneThruNet.app */; | |||
productType = "com.apple.product-type.application"; | |||
}; | |||
4BFF455E0F4D5D9700106083 /* iPhoneFaustNet */ = { | |||
@@ -492,7 +500,7 @@ | |||
4BCF75D810BC2FD90082C526 /* iPhoneThruNet */, | |||
4B41469610BD3C4300C12F0C /* iPhoneFaustNet Distribution */, | |||
4BCB37B4112D647C008C7BC1 /* iPhoneFaust */, | |||
4B1A940F0F49BDE000D3626B /* jacknet */, | |||
4B1A940F0F49BDE000D3626B /* libjacknet */, | |||
); | |||
}; | |||
/* End PBXProject section */ | |||
@@ -503,6 +511,7 @@ | |||
buildActionMask = 2147483647; | |||
files = ( | |||
28AD733F0D9D9553002E5188 /* MainWindow.xib in Resources */, | |||
4B9CB1381136CA99007DE01A /* icon.png in Resources */, | |||
); | |||
runOnlyForDeploymentPostprocessing = 0; | |||
}; | |||
@@ -511,6 +520,7 @@ | |||
buildActionMask = 2147483647; | |||
files = ( | |||
4B0772210F54018C000DC657 /* MainWindow.xib in Resources */, | |||
4B9CB1371136CA99007DE01A /* icon.png in Resources */, | |||
); | |||
runOnlyForDeploymentPostprocessing = 0; | |||
}; | |||
@@ -519,6 +529,7 @@ | |||
buildActionMask = 2147483647; | |||
files = ( | |||
4B41469810BD3C4300C12F0C /* MainWindow.xib in Resources */, | |||
4B9CB13B1136CA99007DE01A /* icon.png in Resources */, | |||
); | |||
runOnlyForDeploymentPostprocessing = 0; | |||
}; | |||
@@ -527,6 +538,7 @@ | |||
buildActionMask = 2147483647; | |||
files = ( | |||
4BCB37B6112D647C008C7BC1 /* MainWindow.xib in Resources */, | |||
4B9CB13C1136CA99007DE01A /* icon.png in Resources */, | |||
); | |||
runOnlyForDeploymentPostprocessing = 0; | |||
}; | |||
@@ -535,6 +547,7 @@ | |||
buildActionMask = 2147483647; | |||
files = ( | |||
4BCF75DA10BC2FD90082C526 /* MainWindow.xib in Resources */, | |||
4B9CB13A1136CA99007DE01A /* icon.png in Resources */, | |||
); | |||
runOnlyForDeploymentPostprocessing = 0; | |||
}; | |||
@@ -543,6 +556,7 @@ | |||
buildActionMask = 2147483647; | |||
files = ( | |||
4BFF45600F4D5D9700106083 /* MainWindow.xib in Resources */, | |||
4B9CB1391136CA99007DE01A /* icon.png in Resources */, | |||
); | |||
runOnlyForDeploymentPostprocessing = 0; | |||
}; | |||
@@ -737,7 +751,7 @@ | |||
"$(inherited)", | |||
"\"$(SRCROOT)/build/Debug-iphonesimulator\"", | |||
); | |||
PRODUCT_NAME = iPhoneNetSlave; | |||
PRODUCT_NAME = NetJackSlave; | |||
}; | |||
name = Release; | |||
}; | |||
@@ -808,6 +822,7 @@ | |||
MACH_O_TYPE = staticlib; | |||
PREBINDING = NO; | |||
PRODUCT_NAME = jacknet; | |||
SDKROOT = iphoneos3.1.3; | |||
STANDARD_C_PLUS_PLUS_LIBRARY_TYPE = static; | |||
}; | |||
name = Debug; | |||
@@ -828,6 +843,7 @@ | |||
); | |||
PREBINDING = NO; | |||
PRODUCT_NAME = jacknet; | |||
SDKROOT = iphoneos3.1.3; | |||
ZERO_LINK = NO; | |||
}; | |||
name = Release; | |||
@@ -1083,7 +1099,7 @@ | |||
defaultConfigurationIsVisible = 0; | |||
defaultConfigurationName = Release; | |||
}; | |||
4B1A94130F49BDFF00D3626B /* Build configuration list for PBXNativeTarget "jacknet" */ = { | |||
4B1A94130F49BDFF00D3626B /* Build configuration list for PBXNativeTarget "libjacknet" */ = { | |||
isa = XCConfigurationList; | |||
buildConfigurations = ( | |||
4B1A94110F49BDE100D3626B /* Debug */, | |||