Jack2 1.9.6

JackNetTool.cpp

00001 /*
00002 Copyright (C) 2008 Romain Moret at Grame
00003 
00004 This program is free software; you can redistribute it and/or modify
00005 it under the terms of the GNU General Public License as published by
00006 the Free Software Foundation; either version 2 of the License, or
00007 (at your option) any later version.
00008 
00009 This program is distributed in the hope that it will be useful,
00010 but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 GNU General Public License for more details.
00013 
00014 You should have received a copy of the GNU General Public License
00015 along with this program; if not, write to the Free Software
00016 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00017 
00018 */
00019 
00020 #include "JackNetTool.h"
00021 
00022 using namespace std;
00023 
00024 namespace Jack
00025 {
00026 // NetMidiBuffer**********************************************************************************
00027 
00028     NetMidiBuffer::NetMidiBuffer ( session_params_t* params, uint32_t nports, char* net_buffer )
00029     {
00030         fNPorts = nports;
00031         fMaxBufsize = fNPorts * sizeof ( sample_t ) * params->fPeriodSize ;
00032         fMaxPcktSize = params->fMtu - sizeof ( packet_header_t );
00033         fBuffer = new char[fMaxBufsize];
00034         fPortBuffer = new JackMidiBuffer* [fNPorts];
00035         for ( int port_index = 0; port_index < fNPorts; port_index++ )
00036             fPortBuffer[port_index] = NULL;
00037         fNetBuffer = net_buffer;
00038     }
00039 
00040     NetMidiBuffer::~NetMidiBuffer()
00041     {
00042         delete[] fBuffer;
00043         delete[] fPortBuffer;
00044     }
00045 
00046     size_t NetMidiBuffer::GetSize()
00047     {
00048         return fMaxBufsize;
00049     }
00050 
00051     void NetMidiBuffer::SetBuffer ( int index, JackMidiBuffer* buffer )
00052     {
00053         fPortBuffer[index] = buffer;
00054     }
00055 
00056     JackMidiBuffer* NetMidiBuffer::GetBuffer ( int index )
00057     {
00058         return fPortBuffer[index];
00059     }
00060 
00061     void NetMidiBuffer::DisplayEvents()
00062     {
00063         for ( int port_index = 0; port_index < fNPorts; port_index++ )
00064         {
00065             for ( uint event = 0; event < fPortBuffer[port_index]->event_count; event++ )
00066                 if ( fPortBuffer[port_index]->IsValid() )
00067                     jack_info ( "port %d : midi event %u/%u -> time : %u, size : %u",
00068                                 port_index + 1, event + 1, fPortBuffer[port_index]->event_count,
00069                                 fPortBuffer[port_index]->events[event].time, fPortBuffer[port_index]->events[event].size );
00070         }
00071     }
00072 
00073     int NetMidiBuffer::RenderFromJackPorts()
00074     {
00075         int pos = 0;
00076         size_t copy_size;
00077         for ( int port_index = 0; port_index < fNPorts; port_index++ )
00078         {
00079             char* write_pos = fBuffer + pos;
00080             
00081             copy_size = sizeof ( JackMidiBuffer ) + fPortBuffer[port_index]->event_count * sizeof ( JackMidiEvent );
00082             memcpy ( fBuffer + pos, fPortBuffer[port_index], copy_size );
00083             pos += copy_size;
00084             memcpy ( fBuffer + pos, fPortBuffer[port_index] + ( fPortBuffer[port_index]->buffer_size - fPortBuffer[port_index]->write_pos ),
00085                      fPortBuffer[port_index]->write_pos );
00086             pos += fPortBuffer[port_index]->write_pos;
00087             
00088             JackMidiBuffer* midi_buffer = reinterpret_cast<JackMidiBuffer*>(write_pos);
00089             MidiBufferHToN(midi_buffer, midi_buffer);
00090         }
00091         return pos;
00092     }
00093 
00094     int NetMidiBuffer::RenderToJackPorts()
00095     {
00096         int pos = 0;
00097         int copy_size;
00098         for ( int port_index = 0; port_index < fNPorts; port_index++ )
00099         {
00100             JackMidiBuffer* midi_buffer = reinterpret_cast<JackMidiBuffer*>(fBuffer + pos);
00101             MidiBufferNToH(midi_buffer, midi_buffer);
00102             
00103             copy_size = sizeof ( JackMidiBuffer ) + reinterpret_cast<JackMidiBuffer*> ( fBuffer + pos )->event_count * sizeof ( JackMidiEvent );
00104             memcpy ( fPortBuffer[port_index], fBuffer + pos, copy_size );
00105             pos += copy_size;
00106             memcpy ( fPortBuffer[port_index] + ( fPortBuffer[port_index]->buffer_size - fPortBuffer[port_index]->write_pos ),
00107                      fBuffer + pos, fPortBuffer[port_index]->write_pos );
00108             pos += fPortBuffer[port_index]->write_pos;
00109         }
00110         return pos;
00111     }
00112     
00113     int NetMidiBuffer::RenderFromNetwork ( int subcycle, size_t copy_size )
00114     {
00115         memcpy ( fBuffer + subcycle * fMaxPcktSize, fNetBuffer, copy_size );
00116         return copy_size;
00117     }
00118 
00119     int NetMidiBuffer::RenderToNetwork ( int subcycle, size_t total_size )
00120     {
00121         int size = total_size - subcycle * fMaxPcktSize;
00122         int copy_size = ( size <= fMaxPcktSize ) ? size : fMaxPcktSize;
00123         memcpy ( fNetBuffer, fBuffer + subcycle * fMaxPcktSize, copy_size );
00124         return copy_size;
00125     }
00126 
00127 
00128 // net audio buffer *********************************************************************************
00129 
00130     NetAudioBuffer::NetAudioBuffer ( session_params_t* params, uint32_t nports, char* net_buffer )
00131     {
00132         fNPorts = nports;
00133         fPeriodSize = params->fPeriodSize;
00134         fSubPeriodSize = params->fFramesPerPacket;
00135         fSubPeriodBytesSize = fSubPeriodSize * sizeof ( sample_t );
00136         fPortBuffer = new sample_t* [fNPorts];
00137         for ( int port_index = 0; port_index < fNPorts; port_index++ )
00138             fPortBuffer[port_index] = NULL;
00139         fNetBuffer = net_buffer;
00140     }
00141 
00142     NetAudioBuffer::~NetAudioBuffer()
00143     {
00144         delete[] fPortBuffer;
00145     }
00146 
00147     size_t NetAudioBuffer::GetSize()
00148     {
00149         return fNPorts * fSubPeriodBytesSize;
00150     }
00151 
00152     void NetAudioBuffer::SetBuffer ( int index, sample_t* buffer )
00153     {
00154         fPortBuffer[index] = buffer;
00155     }
00156 
00157     sample_t* NetAudioBuffer::GetBuffer ( int index )
00158     {
00159         return fPortBuffer[index];
00160     }
00161 
00162 #ifdef __BIG_ENDIAN__
00163 
00164     static inline float SwapFloat(float f)
00165     {
00166           union
00167           {
00168             float f;
00169             unsigned char b[4];
00170           } dat1, dat2;
00171 
00172           dat1.f = f;
00173           dat2.b[0] = dat1.b[3];
00174           dat2.b[1] = dat1.b[2];
00175           dat2.b[2] = dat1.b[1];
00176           dat2.b[3] = dat1.b[0];
00177           return dat2.f;
00178     }
00179 
00180     void NetAudioBuffer::RenderFromJackPorts ( int subcycle )
00181     {
00182         for ( int port_index = 0; port_index < fNPorts; port_index++ ) {
00183             float* src = (float*)(fPortBuffer[port_index] + subcycle * fSubPeriodSize);
00184             float* dst = (float*)(fNetBuffer + port_index * fSubPeriodBytesSize);
00185             for (unsigned int sample = 0; sample < fSubPeriodBytesSize / sizeof(float); sample++) {
00186                 dst[sample] = SwapFloat(src[sample]);
00187             }
00188         }
00189     }
00190 
00191     void NetAudioBuffer::RenderToJackPorts ( int subcycle )
00192     {
00193         for ( int port_index = 0; port_index < fNPorts; port_index++ ) {
00194             float* src = (float*)(fNetBuffer + port_index * fSubPeriodBytesSize);
00195             float* dst = (float*)(fPortBuffer[port_index] + subcycle * fSubPeriodSize);
00196             for (unsigned int sample = 0; sample < fSubPeriodBytesSize / sizeof(float); sample++) {
00197                 dst[sample] = SwapFloat(src[sample]);
00198             }
00199         }    
00200     }
00201     
00202 #else
00203 
00204     void NetAudioBuffer::RenderFromJackPorts ( int subcycle )
00205     {
00206         for ( int port_index = 0; port_index < fNPorts; port_index++ )
00207             memcpy ( fNetBuffer + port_index * fSubPeriodBytesSize, fPortBuffer[port_index] + subcycle * fSubPeriodSize, fSubPeriodBytesSize );
00208     }
00209 
00210     void NetAudioBuffer::RenderToJackPorts ( int subcycle )
00211     {
00212         for ( int port_index = 0; port_index < fNPorts; port_index++ )
00213             memcpy ( fPortBuffer[port_index] + subcycle * fSubPeriodSize, fNetBuffer + port_index * fSubPeriodBytesSize, fSubPeriodBytesSize );
00214     }
00215 
00216 #endif
00217 
00218 // SessionParams ************************************************************************************
00219 
00220     SERVER_EXPORT void SessionParamsHToN ( session_params_t* src_params, session_params_t* dst_params )
00221     {
00222         memcpy(dst_params, src_params, sizeof(session_params_t));
00223         dst_params->fPacketID = htonl ( src_params->fPacketID );
00224         dst_params->fMtu = htonl ( src_params->fMtu );
00225         dst_params->fID = htonl ( src_params->fID );
00226         dst_params->fTransportSync = htonl ( src_params->fTransportSync );
00227         dst_params->fSendAudioChannels = htonl ( src_params->fSendAudioChannels );
00228         dst_params->fReturnAudioChannels = htonl ( src_params->fReturnAudioChannels );
00229         dst_params->fSendMidiChannels = htonl ( src_params->fSendMidiChannels );
00230         dst_params->fReturnMidiChannels = htonl ( src_params->fReturnMidiChannels );
00231         dst_params->fSampleRate = htonl ( src_params->fSampleRate );
00232         dst_params->fPeriodSize = htonl ( src_params->fPeriodSize );
00233         dst_params->fFramesPerPacket = htonl ( src_params->fFramesPerPacket );
00234         dst_params->fBitdepth = htonl ( src_params->fBitdepth );
00235         dst_params->fSlaveSyncMode = htonl ( src_params->fSlaveSyncMode );
00236     }
00237 
00238     SERVER_EXPORT void SessionParamsNToH (  session_params_t* src_params, session_params_t* dst_params )
00239     {
00240         memcpy(dst_params, src_params, sizeof(session_params_t));
00241         dst_params->fPacketID = ntohl ( src_params->fPacketID );
00242         dst_params->fMtu = ntohl ( src_params->fMtu );
00243         dst_params->fID = ntohl ( src_params->fID );
00244         dst_params->fTransportSync = ntohl ( src_params->fTransportSync );
00245         dst_params->fSendAudioChannels = ntohl ( src_params->fSendAudioChannels );
00246         dst_params->fReturnAudioChannels = ntohl ( src_params->fReturnAudioChannels );
00247         dst_params->fSendMidiChannels = ntohl ( src_params->fSendMidiChannels );
00248         dst_params->fReturnMidiChannels = ntohl ( src_params->fReturnMidiChannels );
00249         dst_params->fSampleRate = ntohl ( src_params->fSampleRate );
00250         dst_params->fPeriodSize = ntohl ( src_params->fPeriodSize );
00251         dst_params->fFramesPerPacket = ntohl ( src_params->fFramesPerPacket );
00252         dst_params->fBitdepth = ntohl ( src_params->fBitdepth );
00253         dst_params->fSlaveSyncMode = ntohl ( src_params->fSlaveSyncMode );
00254     }
00255 
00256     SERVER_EXPORT void SessionParamsDisplay ( session_params_t* params )
00257     {
00258         char bitdepth[16];
00259         ( params->fBitdepth ) ? sprintf ( bitdepth, "%u", params->fBitdepth ) : sprintf ( bitdepth, "%s", "float" );
00260         char mode[8];
00261         switch ( params->fNetworkMode )
00262         {
00263             case 's' :
00264                 strcpy ( mode, "slow" );
00265                 break;
00266             case 'n' :
00267                 strcpy ( mode, "normal" );
00268                 break;
00269             case 'f' :
00270                 strcpy ( mode, "fast" );
00271                 break;
00272         }
00273         jack_info ( "**************** Network parameters ****************" );
00274         jack_info ( "Name : %s", params->fName );
00275         jack_info ( "Protocol revision : %d", params->fProtocolVersion );
00276         jack_info ( "MTU : %u", params->fMtu );
00277         jack_info ( "Master name : %s", params->fMasterNetName );
00278         jack_info ( "Slave name : %s", params->fSlaveNetName );
00279         jack_info ( "ID : %u", params->fID );
00280         jack_info ( "Transport Sync : %s", ( params->fTransportSync ) ? "yes" : "no" );
00281         jack_info ( "Send channels (audio - midi) : %d - %d", params->fSendAudioChannels, params->fSendMidiChannels );
00282         jack_info ( "Return channels (audio - midi) : %d - %d", params->fReturnAudioChannels, params->fReturnMidiChannels );
00283         jack_info ( "Sample rate : %u frames per second", params->fSampleRate );
00284         jack_info ( "Period size : %u frames per period", params->fPeriodSize );
00285         jack_info ( "Frames per packet : %u", params->fFramesPerPacket );
00286         jack_info ( "Packet per period : %u", (params->fFramesPerPacket != 0) ? params->fPeriodSize / params->fFramesPerPacket : 0);
00287         jack_info ( "Bitdepth : %s", bitdepth );
00288         jack_info ( "Slave mode : %s", ( params->fSlaveSyncMode ) ? "sync" : "async" );
00289         jack_info ( "Network mode : %s", mode );
00290         jack_info ( "****************************************************" );
00291     }
00292 
00293     SERVER_EXPORT sync_packet_type_t GetPacketType ( session_params_t* params )
00294     {
00295         switch ( params->fPacketID )
00296         {
00297             case 0:
00298                 return SLAVE_AVAILABLE;
00299             case 1:
00300                 return SLAVE_SETUP;
00301             case 2:
00302                 return START_MASTER;
00303             case 3:
00304                 return START_SLAVE;
00305             case 4:
00306                 return KILL_MASTER;
00307         }
00308         return INVALID;
00309     }
00310 
00311     SERVER_EXPORT int SetPacketType ( session_params_t* params, sync_packet_type_t packet_type )
00312     {
00313         switch ( packet_type )
00314         {
00315             case INVALID:
00316                 return -1;
00317             case SLAVE_AVAILABLE:
00318                 params->fPacketID = 0;
00319                 break;
00320             case SLAVE_SETUP:
00321                 params->fPacketID = 1;
00322                 break;
00323             case START_MASTER:
00324                 params->fPacketID = 2;
00325                 break;
00326             case START_SLAVE:
00327                 params->fPacketID = 3;
00328                 break;
00329             case KILL_MASTER:
00330                 params->fPacketID = 4;
00331         }
00332         return 0;
00333     }
00334 
00335 // Packet header **********************************************************************************
00336 
00337     SERVER_EXPORT void PacketHeaderHToN ( packet_header_t* src_header, packet_header_t* dst_header )
00338     {
00339         memcpy(dst_header, src_header, sizeof(packet_header_t));
00340         dst_header->fID = htonl ( src_header->fID );
00341         dst_header->fMidiDataSize = htonl ( src_header->fMidiDataSize );
00342         dst_header->fBitdepth = htonl ( src_header->fBitdepth );
00343         dst_header->fNMidiPckt = htonl ( src_header->fNMidiPckt );
00344         dst_header->fPacketSize = htonl ( src_header->fPacketSize );
00345         dst_header->fCycle = htonl ( src_header->fCycle );
00346         dst_header->fSubCycle = htonl ( src_header->fSubCycle );
00347         dst_header->fIsLastPckt = htonl ( src_header->fIsLastPckt );
00348     }
00349 
00350     SERVER_EXPORT void PacketHeaderNToH ( packet_header_t* src_header, packet_header_t* dst_header )
00351     {
00352         memcpy(dst_header, src_header, sizeof(packet_header_t));
00353         dst_header->fID = ntohl ( src_header->fID );
00354         dst_header->fMidiDataSize = ntohl ( src_header->fMidiDataSize );
00355         dst_header->fBitdepth = ntohl ( src_header->fBitdepth );
00356         dst_header->fNMidiPckt = ntohl ( src_header->fNMidiPckt );
00357         dst_header->fPacketSize = ntohl ( src_header->fPacketSize );
00358         dst_header->fCycle = ntohl ( src_header->fCycle );
00359         dst_header->fSubCycle = ntohl ( src_header->fSubCycle );
00360         dst_header->fIsLastPckt = ntohl ( src_header->fIsLastPckt );
00361     }
00362 
00363     SERVER_EXPORT void PacketHeaderDisplay ( packet_header_t* header )
00364     {
00365         char bitdepth[16];
00366         ( header->fBitdepth ) ? sprintf ( bitdepth, "%u", header->fBitdepth ) : sprintf ( bitdepth, "%s", "float" );
00367         jack_info ( "********************Header********************" );
00368         jack_info ( "Data type : %c", header->fDataType );
00369         jack_info ( "Data stream : %c", header->fDataStream );
00370         jack_info ( "ID : %u", header->fID );
00371         jack_info ( "Cycle : %u", header->fCycle );
00372         jack_info ( "SubCycle : %u", header->fSubCycle );
00373         jack_info ( "Midi packets : %u", header->fNMidiPckt );
00374         jack_info ( "Midi data size : %u", header->fMidiDataSize );
00375         jack_info ( "Last packet : '%s'", ( header->fIsLastPckt ) ? "yes" : "no" );
00376         jack_info ( "Bitdepth : %s", bitdepth );
00377         jack_info ( "**********************************************" );
00378     }
00379     
00380     SERVER_EXPORT void NetTransportDataDisplay ( net_transport_data_t* data )
00381     {
00382         jack_info ( "********************Network Transport********************" );
00383         jack_info ( "Transport new state : %u", data->fNewState );
00384         jack_info ( "Transport timebase master : %u", data->fTimebaseMaster );
00385         jack_info ( "Transport cycle state : %u", data->fState );
00386         jack_info ( "**********************************************" );
00387     }
00388    
00389     SERVER_EXPORT void MidiBufferHToN ( JackMidiBuffer* src_buffer, JackMidiBuffer* dst_buffer )
00390     {
00391         dst_buffer->magic = htonl(src_buffer->magic);
00392         dst_buffer->buffer_size = htonl(src_buffer->buffer_size);
00393         dst_buffer->nframes = htonl(src_buffer->nframes);
00394         dst_buffer->write_pos = htonl(src_buffer->write_pos);
00395         dst_buffer->event_count = htonl(src_buffer->event_count);
00396         dst_buffer->lost_events = htonl(src_buffer->lost_events);
00397         dst_buffer->mix_index = htonl(src_buffer->mix_index);
00398     }
00399     
00400     SERVER_EXPORT void MidiBufferNToH ( JackMidiBuffer* src_buffer, JackMidiBuffer* dst_buffer )
00401     {
00402         dst_buffer->magic = ntohl(src_buffer->magic);
00403         dst_buffer->buffer_size = ntohl(src_buffer->buffer_size);
00404         dst_buffer->nframes = ntohl(src_buffer->nframes);
00405         dst_buffer->write_pos = ntohl(src_buffer->write_pos);
00406         dst_buffer->event_count = ntohl(src_buffer->event_count);
00407         dst_buffer->lost_events = ntohl(src_buffer->lost_events);
00408         dst_buffer->mix_index = ntohl(src_buffer->mix_index);
00409     }
00410     
00411     SERVER_EXPORT void TransportDataHToN ( net_transport_data_t* src_params, net_transport_data_t* dst_params )
00412     {
00413         dst_params->fNewState = htonl(src_params->fNewState);
00414         dst_params->fTimebaseMaster = htonl(src_params->fTimebaseMaster);
00415         dst_params->fState = htonl(src_params->fState);
00416         dst_params->fPosition.unique_1 = htonll(src_params->fPosition.unique_1);
00417         dst_params->fPosition.usecs = htonl(src_params->fPosition.usecs);
00418         dst_params->fPosition.frame_rate = htonl(src_params->fPosition.frame_rate);
00419         dst_params->fPosition.frame = htonl(src_params->fPosition.frame);
00420         dst_params->fPosition.valid = (jack_position_bits_t)htonl((uint32_t)src_params->fPosition.valid);
00421         dst_params->fPosition.bar = htonl(src_params->fPosition.bar);
00422         dst_params->fPosition.beat = htonl(src_params->fPosition.beat);
00423         dst_params->fPosition.tick = htonl(src_params->fPosition.tick);
00424         dst_params->fPosition.bar_start_tick = htonll((uint64_t)src_params->fPosition.bar_start_tick);
00425         dst_params->fPosition.beats_per_bar = htonl((uint32_t)src_params->fPosition.beats_per_bar);
00426         dst_params->fPosition.beat_type = htonl((uint32_t)src_params->fPosition.beat_type);
00427         dst_params->fPosition.ticks_per_beat = htonll((uint64_t)src_params->fPosition.ticks_per_beat);
00428         dst_params->fPosition.beats_per_minute = htonll((uint64_t)src_params->fPosition.beats_per_minute);
00429         dst_params->fPosition.frame_time = htonll((uint64_t)src_params->fPosition.frame_time);
00430         dst_params->fPosition.next_time = htonll((uint64_t)src_params->fPosition.next_time);
00431         dst_params->fPosition.bbt_offset = htonl(src_params->fPosition.bbt_offset);
00432         dst_params->fPosition.audio_frames_per_video_frame = htonl((uint32_t)src_params->fPosition.audio_frames_per_video_frame);
00433         dst_params->fPosition.video_offset = htonl(src_params->fPosition.video_offset);
00434         dst_params->fPosition.unique_2 = htonll(src_params->fPosition.unique_2);
00435     }
00436     
00437     SERVER_EXPORT void TransportDataNToH ( net_transport_data_t* src_params, net_transport_data_t* dst_params )
00438     {
00439         dst_params->fNewState = ntohl(src_params->fNewState);
00440         dst_params->fTimebaseMaster =  ntohl(src_params->fTimebaseMaster);
00441         dst_params->fState = ntohl(src_params->fState);
00442         dst_params->fPosition.unique_1 = ntohll(src_params->fPosition.unique_1);
00443         dst_params->fPosition.usecs = ntohl(src_params->fPosition.usecs);
00444         dst_params->fPosition.frame_rate = ntohl(src_params->fPosition.frame_rate);
00445         dst_params->fPosition.frame = ntohl(src_params->fPosition.frame);
00446         dst_params->fPosition.valid = (jack_position_bits_t)ntohl((uint32_t)src_params->fPosition.valid);
00447         dst_params->fPosition.bar = ntohl(src_params->fPosition.bar);
00448         dst_params->fPosition.beat = ntohl(src_params->fPosition.beat);
00449         dst_params->fPosition.tick = ntohl(src_params->fPosition.tick);
00450         dst_params->fPosition.bar_start_tick = ntohll((uint64_t)src_params->fPosition.bar_start_tick);
00451         dst_params->fPosition.beats_per_bar = ntohl((uint32_t)src_params->fPosition.beats_per_bar);
00452         dst_params->fPosition.beat_type = ntohl((uint32_t)src_params->fPosition.beat_type);
00453         dst_params->fPosition.ticks_per_beat = ntohll((uint64_t)src_params->fPosition.ticks_per_beat);
00454         dst_params->fPosition.beats_per_minute = ntohll((uint64_t)src_params->fPosition.beats_per_minute);
00455         dst_params->fPosition.frame_time = ntohll((uint64_t)src_params->fPosition.frame_time);
00456         dst_params->fPosition.next_time = ntohll((uint64_t)src_params->fPosition.next_time);
00457         dst_params->fPosition.bbt_offset = ntohl(src_params->fPosition.bbt_offset);
00458         dst_params->fPosition.audio_frames_per_video_frame = ntohl((uint32_t)src_params->fPosition.audio_frames_per_video_frame);
00459         dst_params->fPosition.video_offset = ntohl(src_params->fPosition.video_offset);
00460         dst_params->fPosition.unique_2 = ntohll(src_params->fPosition.unique_2);
00461     }
00462 
00463 // Utility *******************************************************************************************************
00464 
00465     SERVER_EXPORT int SocketAPIInit()
00466     {
00467 #ifdef WIN32
00468         WORD wVersionRequested = MAKEWORD ( 2, 2 );
00469         WSADATA wsaData;
00470 
00471         if ( WSAStartup ( wVersionRequested, &wsaData ) != 0 )
00472         {
00473             jack_error ( "WSAStartup error : %s", strerror ( NET_ERROR_CODE ) );
00474             return -1;
00475         }
00476 
00477         if ( LOBYTE ( wsaData.wVersion ) != 2 || HIBYTE ( wsaData.wVersion ) != 2 )
00478         {
00479             jack_error ( "Could not find a useable version of Winsock.dll\n" );
00480             WSACleanup();
00481             return -1;
00482         }
00483 #endif
00484         return 0;
00485     }
00486 
00487     SERVER_EXPORT int SocketAPIEnd()
00488     {
00489 #ifdef WIN32
00490         return WSACleanup();
00491 #endif
00492         return 0;
00493     }
00494 
00495     SERVER_EXPORT const char* GetTransportState ( int transport_state )
00496     {
00497         switch ( transport_state )
00498         {
00499             case JackTransportRolling:
00500                 return "rolling";
00501             case JackTransportStarting:
00502                 return "starting";
00503             case JackTransportStopped:
00504                 return "stopped";
00505             case JackTransportNetStarting:
00506                 return "netstarting";
00507         }
00508         return NULL;
00509     }
00510 }