Commit f4fa01f3 authored by sletz's avatar sletz
Browse files

More cleanup.

git-svn-id: http://subversion.jackaudio.org/jack/jack2/branches/libjacknet@3950 0c269be4-1314-0410-8aa9-9f06e86f4224
parent 5b8e976b
......@@ -751,7 +751,7 @@ struct JackNetAdapter : public JackAudioAdapterInterface {
fCaptureRingBuffer = new JackResampler*[fCaptureChannels];
fPlaybackRingBuffer = new JackResampler*[fPlaybackChannels];
if (fAdaptative) {
if (fAdaptative) {
AdaptRingBufferSize();
jack_info("Ringbuffer automatic adaptative mode size = %d frames", fRingbufferCurSize);
} else {
......
......@@ -39,33 +39,24 @@ namespace Jack
JackNetInterface::JackNetInterface() : fSocket()
{
fTxBuffer = NULL;
fRxBuffer = NULL;
fNetAudioCaptureBuffer = NULL;
fNetAudioPlaybackBuffer = NULL;
fNetMidiCaptureBuffer = NULL;
fNetMidiPlaybackBuffer = NULL;
memset(&fSendTransportData, 0, sizeof(net_transport_data_t));
memset(&fReturnTransportData, 0, sizeof(net_transport_data_t));
Initialize();
}
JackNetInterface::JackNetInterface ( const char* multicast_ip, int port ) : fSocket ( multicast_ip, port )
{
strcpy(fMulticastIP, multicast_ip);
fTxBuffer = NULL;
fRxBuffer = NULL;
fNetAudioCaptureBuffer = NULL;
fNetAudioPlaybackBuffer = NULL;
fNetMidiCaptureBuffer = NULL;
fNetMidiPlaybackBuffer = NULL;
memset(&fSendTransportData, 0, sizeof(net_transport_data_t));
memset(&fReturnTransportData, 0, sizeof(net_transport_data_t));
Initialize();
}
JackNetInterface::JackNetInterface ( session_params_t& params, JackNetSocket& socket, const char* multicast_ip ) : fSocket ( socket )
{
fParams = params;
strcpy(fMulticastIP, multicast_ip);
Initialize();
}
void JackNetInterface::Initialize()
{
fTxBuffer = NULL;
fRxBuffer = NULL;
fNetAudioCaptureBuffer = NULL;
......@@ -75,7 +66,7 @@ namespace Jack
memset(&fSendTransportData, 0, sizeof(net_transport_data_t));
memset(&fReturnTransportData, 0, sizeof(net_transport_data_t));
}
JackNetInterface::~JackNetInterface()
{
jack_log ( "JackNetInterface::~JackNetInterface" );
......@@ -95,19 +86,16 @@ namespace Jack
float audio_size = (fNetAudioCaptureBuffer)
? fNetAudioCaptureBuffer->GetCycleSize()
: (fNetAudioPlaybackBuffer) ? fNetAudioPlaybackBuffer->GetCycleSize() : 0;
jack_log ("audio_size %f", audio_size);
//midi
float midi_size = (fNetMidiCaptureBuffer)
? fNetMidiCaptureBuffer->GetCycleSize()
: (fNetMidiPlaybackBuffer) ? fNetMidiPlaybackBuffer->GetCycleSize() : 0;
jack_log ("midi_size %f", midi_size);
//bufsize = sync + audio + midi
int bufsize = MAX_LATENCY * (fParams.fMtu + (int)audio_size + (int) midi_size);
jack_log("SetNetBufferSize bufsize = %d", bufsize);
//tx buffer
......@@ -190,8 +178,8 @@ namespace Jack
if ( fSocket.Send ( &net_params, sizeof ( session_params_t ), 0 ) == SOCKET_ERROR )
jack_error ( "Error in send : ", StrError ( NET_ERROR_CODE ) );
memset(&net_params, 0, sizeof ( session_params_t ));
if ( ( ( rx_bytes = fSocket.Recv ( &net_params, sizeof ( session_params_t ), 0 ) ) == SOCKET_ERROR ) && ( fSocket.GetError() != NET_NO_DATA ) )
memset(&net_params, 0, sizeof (session_params_t));
if (((rx_bytes = fSocket.Recv(&net_params, sizeof(session_params_t), 0)) == SOCKET_ERROR) && (fSocket.GetError() != NET_NO_DATA))
{
jack_error ( "Problem with network." );
return false;
......@@ -260,18 +248,18 @@ namespace Jack
//fNetAudioCaptureBuffer = new NetBufferedAudioBuffer ( &fParams, fParams.fSendAudioChannels, fTxData );
//fNetAudioPlaybackBuffer = new NetBufferedAudioBuffer ( &fParams, fParams.fReturnAudioChannels, fRxData );
assert ( fNetAudioCaptureBuffer );
assert ( fNetAudioPlaybackBuffer );
assert(fNetAudioCaptureBuffer);
assert(fNetAudioPlaybackBuffer);
//set the new timeout for the socket
if ( SetRxTimeout() == SOCKET_ERROR ) {
jack_error ( "Can't set rx timeout : %s", StrError ( NET_ERROR_CODE ) );
if (SetRxTimeout() == SOCKET_ERROR) {
jack_error("Can't set rx timeout : %s", StrError(NET_ERROR_CODE));
goto error;
}
//set the new rx buffer size
if ( SetNetBufferSize() == SOCKET_ERROR ) {
jack_error ( "Can't set net buffer sizes : %s", StrError ( NET_ERROR_CODE ) );
if (SetNetBufferSize() == SOCKET_ERROR) {
jack_error("Can't set net buffer sizes : %s", StrError(NET_ERROR_CODE));
goto error;
}
......@@ -310,7 +298,7 @@ namespace Jack
mcast_socket.Close();
}
int JackNetMasterInterface::Recv ( size_t size, int flags )
int JackNetMasterInterface::Recv(size_t size, int flags)
{
int rx_bytes;
......@@ -337,7 +325,7 @@ namespace Jack
return rx_bytes;
}
int JackNetMasterInterface::Send ( size_t size, int flags )
int JackNetMasterInterface::Send(size_t size, int flags)
{
int tx_bytes;
packet_header_t* header = reinterpret_cast<packet_header_t*>(fTxBuffer);
......@@ -373,7 +361,7 @@ namespace Jack
fTxHeader.fCycle++;
fTxHeader.fSubCycle = 0;
fTxHeader.fDataType = 's';
fTxHeader.fIsLastPckt = ( fParams.fSendMidiChannels == 0 && fParams.fSendAudioChannels == 0) ? 1 : 0;
fTxHeader.fIsLastPckt = (fParams.fSendMidiChannels == 0 && fParams.fSendAudioChannels == 0) ? 1 : 0;
fTxHeader.fPacketSize = HEADER_SIZE;
memcpy(fTxBuffer, &fTxHeader, HEADER_SIZE);
......@@ -386,7 +374,7 @@ namespace Jack
uint data_size;
//midi
if ( fParams.fSendMidiChannels > 0)
if (fParams.fSendMidiChannels > 0)
{
//set global header fields and get the number of midi packets
fTxHeader.fDataType = 'm';
......@@ -405,7 +393,7 @@ namespace Jack
}
//audio
if ( fParams.fSendAudioChannels > 0)
if (fParams.fSendAudioChannels > 0)
{
fTxHeader.fDataType = 'a';
data_size = fNetAudioCaptureBuffer->RenderFromJackPorts();
......@@ -424,7 +412,7 @@ namespace Jack
return 0;
}
int JackNetMasterInterface::SyncRecv()
{
packet_header_t* rx_head = reinterpret_cast<packet_header_t*> ( fRxBuffer );
......@@ -443,15 +431,18 @@ 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 < CYCLE_OFFSET_SLOW) {
return 0;
} else {
rx_bytes = Recv ( rx_head->fPacketSize, 0 );
}
if (fCycleOffset > CYCLE_OFFSET_SLOW) {
//rx_bytes = Recv ( rx_head->fPacketSize, 0 );
if (fCycleOffset != fLastfCycleOffset)
jack_info("Warning : '%s' runs in slow network mode, but data received too late (%d cycle(s) offset)", fParams.fName, fCycleOffset);
}
fLastfCycleOffset = fCycleOffset;
break;
case 'n' :
......@@ -533,6 +524,7 @@ namespace Jack
case 's': //sync
jack_info("NetMaster : overloaded, skipping receive from '%s'", fParams.fName);
// TODO : finish midi and audio rendering ?
fNetAudioPlaybackBuffer->RenderToJackPorts();
return 0;
}
}
......@@ -783,9 +775,9 @@ namespace Jack
return false;
}
int JackNetSlaveInterface::Recv ( size_t size, int flags )
int JackNetSlaveInterface::Recv(size_t size, int flags)
{
int rx_bytes = fSocket.Recv ( fRxBuffer, size, flags );
int rx_bytes = fSocket.Recv(fRxBuffer, size, flags);
//handle errors
if ( rx_bytes == SOCKET_ERROR )
{
......@@ -807,7 +799,7 @@ namespace Jack
return rx_bytes;
}
int JackNetSlaveInterface::Send ( size_t size, int flags )
int JackNetSlaveInterface::Send(size_t size, int flags)
{
packet_header_t* header = reinterpret_cast<packet_header_t*>(fTxBuffer);
PacketHeaderHToN(header, header);
......@@ -892,6 +884,7 @@ namespace Jack
case 's': //sync
jack_info ( "NetSlave : overloaded, skipping receive." );
// TODO : finish midi and audio rendering ?
fNetAudioCaptureBuffer->RenderToJackPorts();
return 0;
}
}
......
......@@ -31,7 +31,12 @@ namespace Jack
class SERVER_EXPORT JackNetInterface
{
private:
void Initialize();
protected:
session_params_t fParams;
JackNetSocket fSocket;
char fMulticastIP[32];
......@@ -96,6 +101,7 @@ namespace Jack
protected:
bool fRunning;
int fCycleOffset;
int fLastfCycleOffset;
bool Init();
int SetRxTimeout();
......@@ -119,7 +125,7 @@ namespace Jack
bool IsSynched();
public:
JackNetMasterInterface() : JackNetInterface(), fRunning(false), fCycleOffset(0)
JackNetMasterInterface() : JackNetInterface(), fRunning(false), fCycleOffset(0), fLastfCycleOffset(0)
{}
JackNetMasterInterface ( session_params_t& params, JackNetSocket& socket, const char* multicast_ip )
: JackNetInterface ( params, socket, multicast_ip )
......@@ -205,7 +211,7 @@ namespace Jack
#define CYCLE_OFFSET_FAST 0
#define CYCLE_OFFSET_NORMAL 1
#define CYCLE_OFFSET_SLOW 3
#define CYCLE_OFFSET_SLOW 30
#define MAX_LATENCY CYCLE_OFFSET_SLOW * 4
#endif
......@@ -284,12 +284,12 @@ namespace Jack
fCeltEncoder[i] = celt_encoder_create(fCeltMode[i], 1, &error);
if (error != CELT_OK)
goto error;
celt_encoder_ctl(fCeltEncoder[i], CELT_SET_COMPLEXITY(0));
celt_encoder_ctl(fCeltEncoder[i], CELT_SET_COMPLEXITY(1));
fCeltDecoder[i] = celt_decoder_create(fCeltMode[i], 1, &error);
if (error != CELT_OK)
goto error;
celt_decoder_ctl(fCeltDecoder[i], CELT_SET_COMPLEXITY(0));
celt_decoder_ctl(fCeltDecoder[i], CELT_SET_COMPLEXITY(1));
}
fPortBuffer = new sample_t* [fNPorts];
......@@ -318,7 +318,8 @@ namespace Jack
fNumPackets = (res1) ? (res2 + 1) : res2;
fSubPeriodBytesSize = fCompressedSizeByte / fNumPackets;
fLastSubPeriodBytesSize = fSubPeriodBytesSize + (fCompressedSizeByte - (fSubPeriodBytesSize * fNumPackets));
//fLastSubPeriodBytesSize = fSubPeriodBytesSize + (fCompressedSizeByte - (fSubPeriodBytesSize * fNumPackets));
fLastSubPeriodBytesSize = fSubPeriodBytesSize + fCompressedSizeByte % fNumPackets;
jack_log("fNumPackets = %d fSubPeriodBytesSize = %d, fLastSubPeriodBytesSize = %d", fNumPackets, fSubPeriodBytesSize, fLastSubPeriodBytesSize);
......
......@@ -153,7 +153,7 @@
/* Begin PBXFileReference section */
1D30AB110D05D00D00671497 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
1D6058910D05DD3D006BFB54 /* NetJackSlave.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = NetJackSlave.app; sourceTree = BUILT_PRODUCTS_DIR; };
1D6058910D05DD3D006BFB54 /* NetJack.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = NetJack.app; sourceTree = BUILT_PRODUCTS_DIR; };
1DF5F4DF0D08C38300B7A737 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
288765FC0DF74451002DB57D /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
28AD733E0D9D9553002E5188 /* MainWindow.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MainWindow.xib; sourceTree = "<group>"; };
......@@ -290,7 +290,7 @@
19C28FACFE9D520D11CA2CBB /* Products */ = {
isa = PBXGroup;
children = (
1D6058910D05DD3D006BFB54 /* NetJackSlave.app */,
1D6058910D05DD3D006BFB54 /* NetJack.app */,
4BFF45120F4D59DB00106083 /* libjacknet.a */,
4BFF45770F4D5D9700106083 /* iPhoneFaustNet.app */,
4B0772380F54018C000DC657 /* iPhoneNetMaster.app */,
......@@ -404,7 +404,7 @@
);
name = iPhoneNetSlave;
productName = iPhoneNet;
productReference = 1D6058910D05DD3D006BFB54 /* NetJackSlave.app */;
productReference = 1D6058910D05DD3D006BFB54 /* NetJack.app */;
productType = "com.apple.product-type.application";
};
4B07721F0F54018C000DC657 /* iPhoneNetMaster */ = {
......@@ -822,7 +822,7 @@
"\"$(SRCROOT)/build/Debug-iphonesimulator\"",
);
OTHER_LDFLAGS = libcelt.a;
PRODUCT_NAME = NetJackSlave;
PRODUCT_NAME = NetJack;
SDKROOT = iphoneos3.1.3;
};
name = Release;
......
......@@ -18,8 +18,7 @@ jack_net_slave_t* net;
jack_adapter_t* adapter;
int buffer_size;
int sample_rate ;
int sample_rate;
static int net_process(jack_nframes_t buffer_size,
int audio_input,
......@@ -54,7 +53,6 @@ static void SlaveAudioCallback(int frames, float** inputs, float** outputs, void
#define WIFI_MTU 1500
int main(int argc, char *argv[]) {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
......@@ -62,12 +60,11 @@ int main(int argc, char *argv[]) {
jack_slave_t request = { NUM_INPUT, NUM_OUTPUT, 0, 0, WIFI_MTU, -1, JackSlowMode };
jack_master_t result;
if ((net = jack_net_slave_open("169.254.126.231", DEFAULT_PORT, "iPhone", &request, &result)) == 0) {
//if ((net = jack_net_slave_open(DEFAULT_MULTICAST_IP, DEFAULT_PORT, "iPhone", &request, &result)) == 0) {
//if ((net = jack_net_slave_open("169.254.112.119", DEFAULT_PORT, "iPhone", &request, &result)) == 0) {
if ((net = jack_net_slave_open(DEFAULT_MULTICAST_IP, DEFAULT_PORT, "iPod", &request, &result)) == 0) {
return -1;
}
if ((adapter = jack_create_adapter(NUM_INPUT,
NUM_OUTPUT,
result.buffer_size,
......@@ -77,7 +74,6 @@ int main(int argc, char *argv[]) {
return -1;
}
TiPhoneCoreAudioRenderer audio_device(NUM_INPUT, NUM_OUTPUT);
jack_set_net_slave_process_callback(net, net_process, NULL);
......@@ -85,7 +81,6 @@ int main(int argc, char *argv[]) {
return -1;
}
if (audio_device.Open(result.buffer_size, result.sample_rate) < 0) {
return -1;
}
......@@ -96,7 +91,6 @@ int main(int argc, char *argv[]) {
return -1;
}
int retVal = UIApplicationMain(argc, argv, nil, nil);
[pool release];
......
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