jack2 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

511 lines
22KB

  1. /*
  2. Copyright (C) 2008 Romain Moret at Grame
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  14. */
  15. #include "JackNetTool.h"
  16. using namespace std;
  17. namespace Jack
  18. {
  19. // NetMidiBuffer**********************************************************************************
  20. NetMidiBuffer::NetMidiBuffer ( session_params_t* params, uint32_t nports, char* net_buffer )
  21. {
  22. fNPorts = nports;
  23. fMaxBufsize = fNPorts * sizeof ( sample_t ) * params->fPeriodSize ;
  24. fMaxPcktSize = params->fMtu - sizeof ( packet_header_t );
  25. fBuffer = new char[fMaxBufsize];
  26. fPortBuffer = new JackMidiBuffer* [fNPorts];
  27. for ( int port_index = 0; port_index < fNPorts; port_index++ )
  28. fPortBuffer[port_index] = NULL;
  29. fNetBuffer = net_buffer;
  30. }
  31. NetMidiBuffer::~NetMidiBuffer()
  32. {
  33. delete[] fBuffer;
  34. delete[] fPortBuffer;
  35. }
  36. size_t NetMidiBuffer::GetSize()
  37. {
  38. return fMaxBufsize;
  39. }
  40. void NetMidiBuffer::SetBuffer ( int index, JackMidiBuffer* buffer )
  41. {
  42. fPortBuffer[index] = buffer;
  43. }
  44. JackMidiBuffer* NetMidiBuffer::GetBuffer ( int index )
  45. {
  46. return fPortBuffer[index];
  47. }
  48. void NetMidiBuffer::DisplayEvents()
  49. {
  50. for ( int port_index = 0; port_index < fNPorts; port_index++ )
  51. {
  52. for ( uint event = 0; event < fPortBuffer[port_index]->event_count; event++ )
  53. if ( fPortBuffer[port_index]->IsValid() )
  54. jack_info ( "port %d : midi event %u/%u -> time : %u, size : %u",
  55. port_index + 1, event + 1, fPortBuffer[port_index]->event_count,
  56. fPortBuffer[port_index]->events[event].time, fPortBuffer[port_index]->events[event].size );
  57. }
  58. }
  59. int NetMidiBuffer::RenderFromJackPorts()
  60. {
  61. int pos = 0;
  62. size_t copy_size;
  63. for ( int port_index = 0; port_index < fNPorts; port_index++ )
  64. {
  65. char* write_pos = fBuffer + pos;
  66. copy_size = sizeof ( JackMidiBuffer ) + fPortBuffer[port_index]->event_count * sizeof ( JackMidiEvent );
  67. memcpy ( fBuffer + pos, fPortBuffer[port_index], copy_size );
  68. pos += copy_size;
  69. memcpy ( fBuffer + pos, fPortBuffer[port_index] + ( fPortBuffer[port_index]->buffer_size - fPortBuffer[port_index]->write_pos ),
  70. fPortBuffer[port_index]->write_pos );
  71. pos += fPortBuffer[port_index]->write_pos;
  72. JackMidiBuffer* midi_buffer = reinterpret_cast<JackMidiBuffer*>(write_pos);
  73. MidiBufferHToN(midi_buffer, midi_buffer);
  74. }
  75. return pos;
  76. }
  77. int NetMidiBuffer::RenderToJackPorts()
  78. {
  79. int pos = 0;
  80. int copy_size;
  81. for ( int port_index = 0; port_index < fNPorts; port_index++ )
  82. {
  83. JackMidiBuffer* midi_buffer = reinterpret_cast<JackMidiBuffer*>(fBuffer + pos);
  84. MidiBufferNToH(midi_buffer, midi_buffer);
  85. copy_size = sizeof ( JackMidiBuffer ) + reinterpret_cast<JackMidiBuffer*> ( fBuffer + pos )->event_count * sizeof ( JackMidiEvent );
  86. memcpy ( fPortBuffer[port_index], fBuffer + pos, copy_size );
  87. pos += copy_size;
  88. memcpy ( fPortBuffer[port_index] + ( fPortBuffer[port_index]->buffer_size - fPortBuffer[port_index]->write_pos ),
  89. fBuffer + pos, fPortBuffer[port_index]->write_pos );
  90. pos += fPortBuffer[port_index]->write_pos;
  91. }
  92. return pos;
  93. }
  94. int NetMidiBuffer::RenderFromNetwork ( int subcycle, size_t copy_size )
  95. {
  96. memcpy ( fBuffer + subcycle * fMaxPcktSize, fNetBuffer, copy_size );
  97. return copy_size;
  98. }
  99. int NetMidiBuffer::RenderToNetwork ( int subcycle, size_t total_size )
  100. {
  101. int size = total_size - subcycle * fMaxPcktSize;
  102. int copy_size = ( size <= fMaxPcktSize ) ? size : fMaxPcktSize;
  103. memcpy ( fNetBuffer, fBuffer + subcycle * fMaxPcktSize, copy_size );
  104. return copy_size;
  105. }
  106. // net audio buffer *********************************************************************************
  107. NetAudioBuffer::NetAudioBuffer ( session_params_t* params, uint32_t nports, char* net_buffer )
  108. {
  109. fNPorts = nports;
  110. fPeriodSize = params->fPeriodSize;
  111. fSubPeriodSize = params->fFramesPerPacket;
  112. fSubPeriodBytesSize = fSubPeriodSize * sizeof ( sample_t );
  113. fPortBuffer = new sample_t* [fNPorts];
  114. for ( int port_index = 0; port_index < fNPorts; port_index++ )
  115. fPortBuffer[port_index] = NULL;
  116. fNetBuffer = net_buffer;
  117. }
  118. NetAudioBuffer::~NetAudioBuffer()
  119. {
  120. delete[] fPortBuffer;
  121. }
  122. size_t NetAudioBuffer::GetSize()
  123. {
  124. return fNPorts * fSubPeriodBytesSize;
  125. }
  126. void NetAudioBuffer::SetBuffer ( int index, sample_t* buffer )
  127. {
  128. fPortBuffer[index] = buffer;
  129. }
  130. sample_t* NetAudioBuffer::GetBuffer ( int index )
  131. {
  132. return fPortBuffer[index];
  133. }
  134. #ifdef __BIG_ENDIAN__
  135. static inline float SwapFloat(float f)
  136. {
  137. union
  138. {
  139. float f;
  140. unsigned char b[4];
  141. } dat1, dat2;
  142. dat1.f = f;
  143. dat2.b[0] = dat1.b[3];
  144. dat2.b[1] = dat1.b[2];
  145. dat2.b[2] = dat1.b[1];
  146. dat2.b[3] = dat1.b[0];
  147. return dat2.f;
  148. }
  149. void NetAudioBuffer::RenderFromJackPorts ( int subcycle )
  150. {
  151. for ( int port_index = 0; port_index < fNPorts; port_index++ ) {
  152. float* src = (float*)(fPortBuffer[port_index] + subcycle * fSubPeriodSize);
  153. float* dst = (float*)(fNetBuffer + port_index * fSubPeriodBytesSize);
  154. for (unsigned int sample = 0; sample < fSubPeriodBytesSize / sizeof(float); sample++) {
  155. dst[sample] = SwapFloat(src[sample]);
  156. }
  157. }
  158. }
  159. void NetAudioBuffer::RenderToJackPorts ( int subcycle )
  160. {
  161. for ( int port_index = 0; port_index < fNPorts; port_index++ ) {
  162. float* src = (float*)(fNetBuffer + port_index * fSubPeriodBytesSize);
  163. float* dst = (float*)(fPortBuffer[port_index] + subcycle * fSubPeriodSize);
  164. for (unsigned int sample = 0; sample < fSubPeriodBytesSize / sizeof(float); sample++) {
  165. dst[sample] = SwapFloat(src[sample]);
  166. }
  167. }
  168. }
  169. #else
  170. void NetAudioBuffer::RenderFromJackPorts ( int subcycle )
  171. {
  172. for ( int port_index = 0; port_index < fNPorts; port_index++ )
  173. memcpy ( fNetBuffer + port_index * fSubPeriodBytesSize, fPortBuffer[port_index] + subcycle * fSubPeriodSize, fSubPeriodBytesSize );
  174. }
  175. void NetAudioBuffer::RenderToJackPorts ( int subcycle )
  176. {
  177. for ( int port_index = 0; port_index < fNPorts; port_index++ )
  178. memcpy ( fPortBuffer[port_index] + subcycle * fSubPeriodSize, fNetBuffer + port_index * fSubPeriodBytesSize, fSubPeriodBytesSize );
  179. }
  180. #endif
  181. // SessionParams ************************************************************************************
  182. SERVER_EXPORT void SessionParamsHToN ( session_params_t* src_params, session_params_t* dst_params )
  183. {
  184. memcpy(dst_params, src_params, sizeof(session_params_t));
  185. dst_params->fPacketID = htonl ( src_params->fPacketID );
  186. dst_params->fMtu = htonl ( src_params->fMtu );
  187. dst_params->fID = htonl ( src_params->fID );
  188. dst_params->fTransportSync = htonl ( src_params->fTransportSync );
  189. dst_params->fSendAudioChannels = htonl ( src_params->fSendAudioChannels );
  190. dst_params->fReturnAudioChannels = htonl ( src_params->fReturnAudioChannels );
  191. dst_params->fSendMidiChannels = htonl ( src_params->fSendMidiChannels );
  192. dst_params->fReturnMidiChannels = htonl ( src_params->fReturnMidiChannels );
  193. dst_params->fSampleRate = htonl ( src_params->fSampleRate );
  194. dst_params->fPeriodSize = htonl ( src_params->fPeriodSize );
  195. dst_params->fFramesPerPacket = htonl ( src_params->fFramesPerPacket );
  196. dst_params->fBitdepth = htonl ( src_params->fBitdepth );
  197. dst_params->fSlaveSyncMode = htonl ( src_params->fSlaveSyncMode );
  198. }
  199. SERVER_EXPORT void SessionParamsNToH ( session_params_t* src_params, session_params_t* dst_params )
  200. {
  201. memcpy(dst_params, src_params, sizeof(session_params_t));
  202. dst_params->fPacketID = ntohl ( src_params->fPacketID );
  203. dst_params->fMtu = ntohl ( src_params->fMtu );
  204. dst_params->fID = ntohl ( src_params->fID );
  205. dst_params->fTransportSync = ntohl ( src_params->fTransportSync );
  206. dst_params->fSendAudioChannels = ntohl ( src_params->fSendAudioChannels );
  207. dst_params->fReturnAudioChannels = ntohl ( src_params->fReturnAudioChannels );
  208. dst_params->fSendMidiChannels = ntohl ( src_params->fSendMidiChannels );
  209. dst_params->fReturnMidiChannels = ntohl ( src_params->fReturnMidiChannels );
  210. dst_params->fSampleRate = ntohl ( src_params->fSampleRate );
  211. dst_params->fPeriodSize = ntohl ( src_params->fPeriodSize );
  212. dst_params->fFramesPerPacket = ntohl ( src_params->fFramesPerPacket );
  213. dst_params->fBitdepth = ntohl ( src_params->fBitdepth );
  214. dst_params->fSlaveSyncMode = ntohl ( src_params->fSlaveSyncMode );
  215. }
  216. SERVER_EXPORT void SessionParamsDisplay ( session_params_t* params )
  217. {
  218. char bitdepth[16];
  219. ( params->fBitdepth ) ? sprintf ( bitdepth, "%u", params->fBitdepth ) : sprintf ( bitdepth, "%s", "float" );
  220. char mode[8];
  221. switch ( params->fNetworkMode )
  222. {
  223. case 's' :
  224. strcpy ( mode, "slow" );
  225. break;
  226. case 'n' :
  227. strcpy ( mode, "normal" );
  228. break;
  229. case 'f' :
  230. strcpy ( mode, "fast" );
  231. break;
  232. }
  233. jack_info ( "**************** Network parameters ****************" );
  234. jack_info ( "Name : %s", params->fName );
  235. jack_info ( "Protocol revision : %d", params->fProtocolVersion );
  236. jack_info ( "MTU : %u", params->fMtu );
  237. jack_info ( "Master name : %s", params->fMasterNetName );
  238. jack_info ( "Slave name : %s", params->fSlaveNetName );
  239. jack_info ( "ID : %u", params->fID );
  240. jack_info ( "Transport Sync : %s", ( params->fTransportSync ) ? "yes" : "no" );
  241. jack_info ( "Send channels (audio - midi) : %d - %d", params->fSendAudioChannels, params->fSendMidiChannels );
  242. jack_info ( "Return channels (audio - midi) : %d - %d", params->fReturnAudioChannels, params->fReturnMidiChannels );
  243. jack_info ( "Sample rate : %u frames per second", params->fSampleRate );
  244. jack_info ( "Period size : %u frames per period", params->fPeriodSize );
  245. jack_info ( "Frames per packet : %u", params->fFramesPerPacket );
  246. jack_info ( "Packet per period : %u", (params->fFramesPerPacket != 0) ? params->fPeriodSize / params->fFramesPerPacket : 0);
  247. jack_info ( "Bitdepth : %s", bitdepth );
  248. jack_info ( "Slave mode : %s", ( params->fSlaveSyncMode ) ? "sync" : "async" );
  249. jack_info ( "Network mode : %s", mode );
  250. jack_info ( "****************************************************" );
  251. }
  252. SERVER_EXPORT sync_packet_type_t GetPacketType ( session_params_t* params )
  253. {
  254. switch ( params->fPacketID )
  255. {
  256. case 0:
  257. return SLAVE_AVAILABLE;
  258. case 1:
  259. return SLAVE_SETUP;
  260. case 2:
  261. return START_MASTER;
  262. case 3:
  263. return START_SLAVE;
  264. case 4:
  265. return KILL_MASTER;
  266. }
  267. return INVALID;
  268. }
  269. SERVER_EXPORT int SetPacketType ( session_params_t* params, sync_packet_type_t packet_type )
  270. {
  271. switch ( packet_type )
  272. {
  273. case INVALID:
  274. return -1;
  275. case SLAVE_AVAILABLE:
  276. params->fPacketID = 0;
  277. break;
  278. case SLAVE_SETUP:
  279. params->fPacketID = 1;
  280. break;
  281. case START_MASTER:
  282. params->fPacketID = 2;
  283. break;
  284. case START_SLAVE:
  285. params->fPacketID = 3;
  286. break;
  287. case KILL_MASTER:
  288. params->fPacketID = 4;
  289. }
  290. return 0;
  291. }
  292. // Packet header **********************************************************************************
  293. SERVER_EXPORT void PacketHeaderHToN ( packet_header_t* src_header, packet_header_t* dst_header )
  294. {
  295. memcpy(dst_header, src_header, sizeof(packet_header_t));
  296. dst_header->fID = htonl ( src_header->fID );
  297. dst_header->fMidiDataSize = htonl ( src_header->fMidiDataSize );
  298. dst_header->fBitdepth = htonl ( src_header->fBitdepth );
  299. dst_header->fNMidiPckt = htonl ( src_header->fNMidiPckt );
  300. dst_header->fPacketSize = htonl ( src_header->fPacketSize );
  301. dst_header->fCycle = htonl ( src_header->fCycle );
  302. dst_header->fSubCycle = htonl ( src_header->fSubCycle );
  303. dst_header->fIsLastPckt = htonl ( src_header->fIsLastPckt );
  304. }
  305. SERVER_EXPORT void PacketHeaderNToH ( packet_header_t* src_header, packet_header_t* dst_header )
  306. {
  307. memcpy(dst_header, src_header, sizeof(packet_header_t));
  308. dst_header->fID = ntohl ( src_header->fID );
  309. dst_header->fMidiDataSize = ntohl ( src_header->fMidiDataSize );
  310. dst_header->fBitdepth = ntohl ( src_header->fBitdepth );
  311. dst_header->fNMidiPckt = ntohl ( src_header->fNMidiPckt );
  312. dst_header->fPacketSize = ntohl ( src_header->fPacketSize );
  313. dst_header->fCycle = ntohl ( src_header->fCycle );
  314. dst_header->fSubCycle = ntohl ( src_header->fSubCycle );
  315. dst_header->fIsLastPckt = ntohl ( src_header->fIsLastPckt );
  316. }
  317. SERVER_EXPORT void PacketHeaderDisplay ( packet_header_t* header )
  318. {
  319. char bitdepth[16];
  320. ( header->fBitdepth ) ? sprintf ( bitdepth, "%u", header->fBitdepth ) : sprintf ( bitdepth, "%s", "float" );
  321. jack_info ( "********************Header********************" );
  322. jack_info ( "Data type : %c", header->fDataType );
  323. jack_info ( "Data stream : %c", header->fDataStream );
  324. jack_info ( "ID : %u", header->fID );
  325. jack_info ( "Cycle : %u", header->fCycle );
  326. jack_info ( "SubCycle : %u", header->fSubCycle );
  327. jack_info ( "Midi packets : %u", header->fNMidiPckt );
  328. jack_info ( "Midi data size : %u", header->fMidiDataSize );
  329. jack_info ( "Last packet : '%s'", ( header->fIsLastPckt ) ? "yes" : "no" );
  330. jack_info ( "Bitdepth : %s", bitdepth );
  331. jack_info ( "**********************************************" );
  332. }
  333. SERVER_EXPORT void NetTransportDataDisplay ( net_transport_data_t* data )
  334. {
  335. jack_info ( "********************Network Transport********************" );
  336. jack_info ( "Transport new state : %u", data->fNewState );
  337. jack_info ( "Transport timebase master : %u", data->fTimebaseMaster );
  338. jack_info ( "Transport cycle state : %u", data->fState );
  339. jack_info ( "**********************************************" );
  340. }
  341. SERVER_EXPORT void MidiBufferHToN ( JackMidiBuffer* src_buffer, JackMidiBuffer* dst_buffer )
  342. {
  343. dst_buffer->magic = htonl(src_buffer->magic);
  344. dst_buffer->buffer_size = htonl(src_buffer->buffer_size);
  345. dst_buffer->nframes = htonl(src_buffer->nframes);
  346. dst_buffer->write_pos = htonl(src_buffer->write_pos);
  347. dst_buffer->event_count = htonl(src_buffer->event_count);
  348. dst_buffer->lost_events = htonl(src_buffer->lost_events);
  349. dst_buffer->mix_index = htonl(src_buffer->mix_index);
  350. }
  351. SERVER_EXPORT void MidiBufferNToH ( JackMidiBuffer* src_buffer, JackMidiBuffer* dst_buffer )
  352. {
  353. dst_buffer->magic = ntohl(src_buffer->magic);
  354. dst_buffer->buffer_size = ntohl(src_buffer->buffer_size);
  355. dst_buffer->nframes = ntohl(src_buffer->nframes);
  356. dst_buffer->write_pos = ntohl(src_buffer->write_pos);
  357. dst_buffer->event_count = ntohl(src_buffer->event_count);
  358. dst_buffer->lost_events = ntohl(src_buffer->lost_events);
  359. dst_buffer->mix_index = ntohl(src_buffer->mix_index);
  360. }
  361. SERVER_EXPORT void TransportDataHToN ( net_transport_data_t* src_params, net_transport_data_t* dst_params )
  362. {
  363. dst_params->fNewState = htonl(src_params->fNewState);
  364. dst_params->fTimebaseMaster = htonl(src_params->fTimebaseMaster);
  365. dst_params->fState = htonl(src_params->fState);
  366. dst_params->fPosition.unique_1 = htonll(src_params->fPosition.unique_1);
  367. dst_params->fPosition.usecs = htonl(src_params->fPosition.usecs);
  368. dst_params->fPosition.frame_rate = htonl(src_params->fPosition.frame_rate);
  369. dst_params->fPosition.frame = htonl(src_params->fPosition.frame);
  370. dst_params->fPosition.valid = (jack_position_bits_t)htonl((uint32_t)src_params->fPosition.valid);
  371. dst_params->fPosition.bar = htonl(src_params->fPosition.bar);
  372. dst_params->fPosition.beat = htonl(src_params->fPosition.beat);
  373. dst_params->fPosition.tick = htonl(src_params->fPosition.tick);
  374. dst_params->fPosition.bar_start_tick = htonll((uint64_t)src_params->fPosition.bar_start_tick);
  375. dst_params->fPosition.beats_per_bar = htonl((uint32_t)src_params->fPosition.beats_per_bar);
  376. dst_params->fPosition.beat_type = htonl((uint32_t)src_params->fPosition.beat_type);
  377. dst_params->fPosition.ticks_per_beat = htonll((uint64_t)src_params->fPosition.ticks_per_beat);
  378. dst_params->fPosition.beats_per_minute = htonll((uint64_t)src_params->fPosition.beats_per_minute);
  379. dst_params->fPosition.frame_time = htonll((uint64_t)src_params->fPosition.frame_time);
  380. dst_params->fPosition.next_time = htonll((uint64_t)src_params->fPosition.next_time);
  381. dst_params->fPosition.bbt_offset = htonl(src_params->fPosition.bbt_offset);
  382. dst_params->fPosition.audio_frames_per_video_frame = htonl((uint32_t)src_params->fPosition.audio_frames_per_video_frame);
  383. dst_params->fPosition.video_offset = htonl(src_params->fPosition.video_offset);
  384. dst_params->fPosition.unique_2 = htonll(src_params->fPosition.unique_2);
  385. }
  386. SERVER_EXPORT void TransportDataNToH ( net_transport_data_t* src_params, net_transport_data_t* dst_params )
  387. {
  388. dst_params->fNewState = ntohl(src_params->fNewState);
  389. dst_params->fTimebaseMaster = ntohl(src_params->fTimebaseMaster);
  390. dst_params->fState = ntohl(src_params->fState);
  391. dst_params->fPosition.unique_1 = ntohll(src_params->fPosition.unique_1);
  392. dst_params->fPosition.usecs = ntohl(src_params->fPosition.usecs);
  393. dst_params->fPosition.frame_rate = ntohl(src_params->fPosition.frame_rate);
  394. dst_params->fPosition.frame = ntohl(src_params->fPosition.frame);
  395. dst_params->fPosition.valid = (jack_position_bits_t)ntohl((uint32_t)src_params->fPosition.valid);
  396. dst_params->fPosition.bar = ntohl(src_params->fPosition.bar);
  397. dst_params->fPosition.beat = ntohl(src_params->fPosition.beat);
  398. dst_params->fPosition.tick = ntohl(src_params->fPosition.tick);
  399. dst_params->fPosition.bar_start_tick = ntohll((uint64_t)src_params->fPosition.bar_start_tick);
  400. dst_params->fPosition.beats_per_bar = ntohl((uint32_t)src_params->fPosition.beats_per_bar);
  401. dst_params->fPosition.beat_type = ntohl((uint32_t)src_params->fPosition.beat_type);
  402. dst_params->fPosition.ticks_per_beat = ntohll((uint64_t)src_params->fPosition.ticks_per_beat);
  403. dst_params->fPosition.beats_per_minute = ntohll((uint64_t)src_params->fPosition.beats_per_minute);
  404. dst_params->fPosition.frame_time = ntohll((uint64_t)src_params->fPosition.frame_time);
  405. dst_params->fPosition.next_time = ntohll((uint64_t)src_params->fPosition.next_time);
  406. dst_params->fPosition.bbt_offset = ntohl(src_params->fPosition.bbt_offset);
  407. dst_params->fPosition.audio_frames_per_video_frame = ntohl((uint32_t)src_params->fPosition.audio_frames_per_video_frame);
  408. dst_params->fPosition.video_offset = ntohl(src_params->fPosition.video_offset);
  409. dst_params->fPosition.unique_2 = ntohll(src_params->fPosition.unique_2);
  410. }
  411. // Utility *******************************************************************************************************
  412. SERVER_EXPORT int SocketAPIInit()
  413. {
  414. #ifdef WIN32
  415. WORD wVersionRequested = MAKEWORD ( 2, 2 );
  416. WSADATA wsaData;
  417. if ( WSAStartup ( wVersionRequested, &wsaData ) != 0 )
  418. {
  419. jack_error ( "WSAStartup error : %s", strerror ( NET_ERROR_CODE ) );
  420. return -1;
  421. }
  422. if ( LOBYTE ( wsaData.wVersion ) != 2 || HIBYTE ( wsaData.wVersion ) != 2 )
  423. {
  424. jack_error ( "Could not find a useable version of Winsock.dll\n" );
  425. WSACleanup();
  426. return -1;
  427. }
  428. #endif
  429. return 0;
  430. }
  431. SERVER_EXPORT int SocketAPIEnd()
  432. {
  433. #ifdef WIN32
  434. return WSACleanup();
  435. #endif
  436. return 0;
  437. }
  438. SERVER_EXPORT const char* GetTransportState ( int transport_state )
  439. {
  440. switch ( transport_state )
  441. {
  442. case JackTransportRolling:
  443. return "rolling";
  444. case JackTransportStarting:
  445. return "starting";
  446. case JackTransportStopped:
  447. return "stopped";
  448. case JackTransportNetStarting:
  449. return "netstarting";
  450. }
  451. return NULL;
  452. }
  453. }