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.

513 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. assert(fPortBuffer);
  129. fPortBuffer[index] = buffer;
  130. }
  131. sample_t* NetAudioBuffer::GetBuffer ( int index )
  132. {
  133. assert(fPortBuffer);
  134. return fPortBuffer[index];
  135. }
  136. #ifdef __BIG_ENDIAN__
  137. static inline jack_default_audio_sample_t SwapFloat(jack_default_audio_sample_t f)
  138. {
  139. union
  140. {
  141. jack_default_audio_sample_t f;
  142. unsigned char b[4];
  143. } dat1, dat2;
  144. dat1.f = f;
  145. dat2.b[0] = dat1.b[3];
  146. dat2.b[1] = dat1.b[2];
  147. dat2.b[2] = dat1.b[1];
  148. dat2.b[3] = dat1.b[0];
  149. return dat2.f;
  150. }
  151. void NetAudioBuffer::RenderFromJackPorts ( int subcycle )
  152. {
  153. for ( int port_index = 0; port_index < fNPorts; port_index++ ) {
  154. jack_default_audio_sample_t* src = (jack_default_audio_sample_t*)(fPortBuffer[port_index] + subcycle * fSubPeriodSize);
  155. jack_default_audio_sample_t* dst = (jack_default_audio_sample_t*)(fNetBuffer + port_index * fSubPeriodBytesSize);
  156. for (unsigned int sample = 0; sample < fSubPeriodBytesSize / sizeof(jack_default_audio_sample_t); sample++) {
  157. dst[sample] = SwapFloat(src[sample]);
  158. }
  159. }
  160. }
  161. void NetAudioBuffer::RenderToJackPorts ( int subcycle )
  162. {
  163. for ( int port_index = 0; port_index < fNPorts; port_index++ ) {
  164. jack_default_audio_sample_t* src = (jack_default_audio_sample_t*)(fNetBuffer + port_index * fSubPeriodBytesSize);
  165. jack_default_audio_sample_t* dst = (jack_default_audio_sample_t*)(fPortBuffer[port_index] + subcycle * fSubPeriodSize);
  166. for (unsigned int sample = 0; sample < fSubPeriodBytesSize / sizeof(jack_default_audio_sample_t); sample++) {
  167. dst[sample] = SwapFloat(src[sample]);
  168. }
  169. }
  170. }
  171. #else
  172. void NetAudioBuffer::RenderFromJackPorts ( int subcycle )
  173. {
  174. for ( int port_index = 0; port_index < fNPorts; port_index++ )
  175. memcpy ( fNetBuffer + port_index * fSubPeriodBytesSize, fPortBuffer[port_index] + subcycle * fSubPeriodSize, fSubPeriodBytesSize );
  176. }
  177. void NetAudioBuffer::RenderToJackPorts ( int subcycle )
  178. {
  179. for ( int port_index = 0; port_index < fNPorts; port_index++ )
  180. memcpy ( fPortBuffer[port_index] + subcycle * fSubPeriodSize, fNetBuffer + port_index * fSubPeriodBytesSize, fSubPeriodBytesSize );
  181. }
  182. #endif
  183. // SessionParams ************************************************************************************
  184. SERVER_EXPORT void SessionParamsHToN ( session_params_t* src_params, session_params_t* dst_params )
  185. {
  186. memcpy(dst_params, src_params, sizeof(session_params_t));
  187. dst_params->fPacketID = htonl ( src_params->fPacketID );
  188. dst_params->fMtu = htonl ( src_params->fMtu );
  189. dst_params->fID = htonl ( src_params->fID );
  190. dst_params->fTransportSync = htonl ( src_params->fTransportSync );
  191. dst_params->fSendAudioChannels = htonl ( src_params->fSendAudioChannels );
  192. dst_params->fReturnAudioChannels = htonl ( src_params->fReturnAudioChannels );
  193. dst_params->fSendMidiChannels = htonl ( src_params->fSendMidiChannels );
  194. dst_params->fReturnMidiChannels = htonl ( src_params->fReturnMidiChannels );
  195. dst_params->fSampleRate = htonl ( src_params->fSampleRate );
  196. dst_params->fPeriodSize = htonl ( src_params->fPeriodSize );
  197. dst_params->fFramesPerPacket = htonl ( src_params->fFramesPerPacket );
  198. dst_params->fBitdepth = htonl ( src_params->fBitdepth );
  199. dst_params->fSlaveSyncMode = htonl ( src_params->fSlaveSyncMode );
  200. }
  201. SERVER_EXPORT void SessionParamsNToH ( session_params_t* src_params, session_params_t* dst_params )
  202. {
  203. memcpy(dst_params, src_params, sizeof(session_params_t));
  204. dst_params->fPacketID = ntohl ( src_params->fPacketID );
  205. dst_params->fMtu = ntohl ( src_params->fMtu );
  206. dst_params->fID = ntohl ( src_params->fID );
  207. dst_params->fTransportSync = ntohl ( src_params->fTransportSync );
  208. dst_params->fSendAudioChannels = ntohl ( src_params->fSendAudioChannels );
  209. dst_params->fReturnAudioChannels = ntohl ( src_params->fReturnAudioChannels );
  210. dst_params->fSendMidiChannels = ntohl ( src_params->fSendMidiChannels );
  211. dst_params->fReturnMidiChannels = ntohl ( src_params->fReturnMidiChannels );
  212. dst_params->fSampleRate = ntohl ( src_params->fSampleRate );
  213. dst_params->fPeriodSize = ntohl ( src_params->fPeriodSize );
  214. dst_params->fFramesPerPacket = ntohl ( src_params->fFramesPerPacket );
  215. dst_params->fBitdepth = ntohl ( src_params->fBitdepth );
  216. dst_params->fSlaveSyncMode = ntohl ( src_params->fSlaveSyncMode );
  217. }
  218. SERVER_EXPORT void SessionParamsDisplay ( session_params_t* params )
  219. {
  220. char bitdepth[16];
  221. ( params->fBitdepth ) ? sprintf ( bitdepth, "%u", params->fBitdepth ) : sprintf ( bitdepth, "%s", "float" );
  222. char mode[8];
  223. switch ( params->fNetworkMode )
  224. {
  225. case 's' :
  226. strcpy ( mode, "slow" );
  227. break;
  228. case 'n' :
  229. strcpy ( mode, "normal" );
  230. break;
  231. case 'f' :
  232. strcpy ( mode, "fast" );
  233. break;
  234. }
  235. jack_info ( "**************** Network parameters ****************" );
  236. jack_info ( "Name : %s", params->fName );
  237. jack_info ( "Protocol revision : %d", params->fProtocolVersion );
  238. jack_info ( "MTU : %u", params->fMtu );
  239. jack_info ( "Master name : %s", params->fMasterNetName );
  240. jack_info ( "Slave name : %s", params->fSlaveNetName );
  241. jack_info ( "ID : %u", params->fID );
  242. jack_info ( "Transport Sync : %s", ( params->fTransportSync ) ? "yes" : "no" );
  243. jack_info ( "Send channels (audio - midi) : %d - %d", params->fSendAudioChannels, params->fSendMidiChannels );
  244. jack_info ( "Return channels (audio - midi) : %d - %d", params->fReturnAudioChannels, params->fReturnMidiChannels );
  245. jack_info ( "Sample rate : %u frames per second", params->fSampleRate );
  246. jack_info ( "Period size : %u frames per period", params->fPeriodSize );
  247. jack_info ( "Frames per packet : %u", params->fFramesPerPacket );
  248. jack_info ( "Packet per period : %u", (params->fFramesPerPacket != 0) ? params->fPeriodSize / params->fFramesPerPacket : 0);
  249. jack_info ( "Bitdepth : %s", bitdepth );
  250. jack_info ( "Slave mode : %s", ( params->fSlaveSyncMode ) ? "sync" : "async" );
  251. jack_info ( "Network mode : %s", mode );
  252. jack_info ( "****************************************************" );
  253. }
  254. SERVER_EXPORT sync_packet_type_t GetPacketType ( session_params_t* params )
  255. {
  256. switch ( params->fPacketID )
  257. {
  258. case 0:
  259. return SLAVE_AVAILABLE;
  260. case 1:
  261. return SLAVE_SETUP;
  262. case 2:
  263. return START_MASTER;
  264. case 3:
  265. return START_SLAVE;
  266. case 4:
  267. return KILL_MASTER;
  268. }
  269. return INVALID;
  270. }
  271. SERVER_EXPORT int SetPacketType ( session_params_t* params, sync_packet_type_t packet_type )
  272. {
  273. switch ( packet_type )
  274. {
  275. case INVALID:
  276. return -1;
  277. case SLAVE_AVAILABLE:
  278. params->fPacketID = 0;
  279. break;
  280. case SLAVE_SETUP:
  281. params->fPacketID = 1;
  282. break;
  283. case START_MASTER:
  284. params->fPacketID = 2;
  285. break;
  286. case START_SLAVE:
  287. params->fPacketID = 3;
  288. break;
  289. case KILL_MASTER:
  290. params->fPacketID = 4;
  291. }
  292. return 0;
  293. }
  294. // Packet header **********************************************************************************
  295. SERVER_EXPORT void PacketHeaderHToN ( packet_header_t* src_header, packet_header_t* dst_header )
  296. {
  297. memcpy(dst_header, src_header, sizeof(packet_header_t));
  298. dst_header->fID = htonl ( src_header->fID );
  299. dst_header->fMidiDataSize = htonl ( src_header->fMidiDataSize );
  300. dst_header->fBitdepth = htonl ( src_header->fBitdepth );
  301. dst_header->fNMidiPckt = htonl ( src_header->fNMidiPckt );
  302. dst_header->fPacketSize = htonl ( src_header->fPacketSize );
  303. dst_header->fCycle = htonl ( src_header->fCycle );
  304. dst_header->fSubCycle = htonl ( src_header->fSubCycle );
  305. dst_header->fIsLastPckt = htonl ( src_header->fIsLastPckt );
  306. }
  307. SERVER_EXPORT void PacketHeaderNToH ( packet_header_t* src_header, packet_header_t* dst_header )
  308. {
  309. memcpy(dst_header, src_header, sizeof(packet_header_t));
  310. dst_header->fID = ntohl ( src_header->fID );
  311. dst_header->fMidiDataSize = ntohl ( src_header->fMidiDataSize );
  312. dst_header->fBitdepth = ntohl ( src_header->fBitdepth );
  313. dst_header->fNMidiPckt = ntohl ( src_header->fNMidiPckt );
  314. dst_header->fPacketSize = ntohl ( src_header->fPacketSize );
  315. dst_header->fCycle = ntohl ( src_header->fCycle );
  316. dst_header->fSubCycle = ntohl ( src_header->fSubCycle );
  317. dst_header->fIsLastPckt = ntohl ( src_header->fIsLastPckt );
  318. }
  319. SERVER_EXPORT void PacketHeaderDisplay ( packet_header_t* header )
  320. {
  321. char bitdepth[16];
  322. ( header->fBitdepth ) ? sprintf ( bitdepth, "%u", header->fBitdepth ) : sprintf ( bitdepth, "%s", "float" );
  323. jack_info ( "********************Header********************" );
  324. jack_info ( "Data type : %c", header->fDataType );
  325. jack_info ( "Data stream : %c", header->fDataStream );
  326. jack_info ( "ID : %u", header->fID );
  327. jack_info ( "Cycle : %u", header->fCycle );
  328. jack_info ( "SubCycle : %u", header->fSubCycle );
  329. jack_info ( "Midi packets : %u", header->fNMidiPckt );
  330. jack_info ( "Midi data size : %u", header->fMidiDataSize );
  331. jack_info ( "Last packet : '%s'", ( header->fIsLastPckt ) ? "yes" : "no" );
  332. jack_info ( "Bitdepth : %s", bitdepth );
  333. jack_info ( "**********************************************" );
  334. }
  335. SERVER_EXPORT void NetTransportDataDisplay ( net_transport_data_t* data )
  336. {
  337. jack_info ( "********************Network Transport********************" );
  338. jack_info ( "Transport new state : %u", data->fNewState );
  339. jack_info ( "Transport timebase master : %u", data->fTimebaseMaster );
  340. jack_info ( "Transport cycle state : %u", data->fState );
  341. jack_info ( "**********************************************" );
  342. }
  343. SERVER_EXPORT void MidiBufferHToN ( JackMidiBuffer* src_buffer, JackMidiBuffer* dst_buffer )
  344. {
  345. dst_buffer->magic = htonl(src_buffer->magic);
  346. dst_buffer->buffer_size = htonl(src_buffer->buffer_size);
  347. dst_buffer->nframes = htonl(src_buffer->nframes);
  348. dst_buffer->write_pos = htonl(src_buffer->write_pos);
  349. dst_buffer->event_count = htonl(src_buffer->event_count);
  350. dst_buffer->lost_events = htonl(src_buffer->lost_events);
  351. dst_buffer->mix_index = htonl(src_buffer->mix_index);
  352. }
  353. SERVER_EXPORT void MidiBufferNToH ( JackMidiBuffer* src_buffer, JackMidiBuffer* dst_buffer )
  354. {
  355. dst_buffer->magic = ntohl(src_buffer->magic);
  356. dst_buffer->buffer_size = ntohl(src_buffer->buffer_size);
  357. dst_buffer->nframes = ntohl(src_buffer->nframes);
  358. dst_buffer->write_pos = ntohl(src_buffer->write_pos);
  359. dst_buffer->event_count = ntohl(src_buffer->event_count);
  360. dst_buffer->lost_events = ntohl(src_buffer->lost_events);
  361. dst_buffer->mix_index = ntohl(src_buffer->mix_index);
  362. }
  363. SERVER_EXPORT void TransportDataHToN ( net_transport_data_t* src_params, net_transport_data_t* dst_params )
  364. {
  365. dst_params->fNewState = htonl(src_params->fNewState);
  366. dst_params->fTimebaseMaster = htonl(src_params->fTimebaseMaster);
  367. dst_params->fState = htonl(src_params->fState);
  368. dst_params->fPosition.unique_1 = htonll(src_params->fPosition.unique_1);
  369. dst_params->fPosition.usecs = htonl(src_params->fPosition.usecs);
  370. dst_params->fPosition.frame_rate = htonl(src_params->fPosition.frame_rate);
  371. dst_params->fPosition.frame = htonl(src_params->fPosition.frame);
  372. dst_params->fPosition.valid = (jack_position_bits_t)htonl((uint32_t)src_params->fPosition.valid);
  373. dst_params->fPosition.bar = htonl(src_params->fPosition.bar);
  374. dst_params->fPosition.beat = htonl(src_params->fPosition.beat);
  375. dst_params->fPosition.tick = htonl(src_params->fPosition.tick);
  376. dst_params->fPosition.bar_start_tick = htonll((uint64_t)src_params->fPosition.bar_start_tick);
  377. dst_params->fPosition.beats_per_bar = htonl((uint32_t)src_params->fPosition.beats_per_bar);
  378. dst_params->fPosition.beat_type = htonl((uint32_t)src_params->fPosition.beat_type);
  379. dst_params->fPosition.ticks_per_beat = htonll((uint64_t)src_params->fPosition.ticks_per_beat);
  380. dst_params->fPosition.beats_per_minute = htonll((uint64_t)src_params->fPosition.beats_per_minute);
  381. dst_params->fPosition.frame_time = htonll((uint64_t)src_params->fPosition.frame_time);
  382. dst_params->fPosition.next_time = htonll((uint64_t)src_params->fPosition.next_time);
  383. dst_params->fPosition.bbt_offset = htonl(src_params->fPosition.bbt_offset);
  384. dst_params->fPosition.audio_frames_per_video_frame = htonl((uint32_t)src_params->fPosition.audio_frames_per_video_frame);
  385. dst_params->fPosition.video_offset = htonl(src_params->fPosition.video_offset);
  386. dst_params->fPosition.unique_2 = htonll(src_params->fPosition.unique_2);
  387. }
  388. SERVER_EXPORT void TransportDataNToH ( net_transport_data_t* src_params, net_transport_data_t* dst_params )
  389. {
  390. dst_params->fNewState = ntohl(src_params->fNewState);
  391. dst_params->fTimebaseMaster = ntohl(src_params->fTimebaseMaster);
  392. dst_params->fState = ntohl(src_params->fState);
  393. dst_params->fPosition.unique_1 = ntohll(src_params->fPosition.unique_1);
  394. dst_params->fPosition.usecs = ntohl(src_params->fPosition.usecs);
  395. dst_params->fPosition.frame_rate = ntohl(src_params->fPosition.frame_rate);
  396. dst_params->fPosition.frame = ntohl(src_params->fPosition.frame);
  397. dst_params->fPosition.valid = (jack_position_bits_t)ntohl((uint32_t)src_params->fPosition.valid);
  398. dst_params->fPosition.bar = ntohl(src_params->fPosition.bar);
  399. dst_params->fPosition.beat = ntohl(src_params->fPosition.beat);
  400. dst_params->fPosition.tick = ntohl(src_params->fPosition.tick);
  401. dst_params->fPosition.bar_start_tick = ntohll((uint64_t)src_params->fPosition.bar_start_tick);
  402. dst_params->fPosition.beats_per_bar = ntohl((uint32_t)src_params->fPosition.beats_per_bar);
  403. dst_params->fPosition.beat_type = ntohl((uint32_t)src_params->fPosition.beat_type);
  404. dst_params->fPosition.ticks_per_beat = ntohll((uint64_t)src_params->fPosition.ticks_per_beat);
  405. dst_params->fPosition.beats_per_minute = ntohll((uint64_t)src_params->fPosition.beats_per_minute);
  406. dst_params->fPosition.frame_time = ntohll((uint64_t)src_params->fPosition.frame_time);
  407. dst_params->fPosition.next_time = ntohll((uint64_t)src_params->fPosition.next_time);
  408. dst_params->fPosition.bbt_offset = ntohl(src_params->fPosition.bbt_offset);
  409. dst_params->fPosition.audio_frames_per_video_frame = ntohl((uint32_t)src_params->fPosition.audio_frames_per_video_frame);
  410. dst_params->fPosition.video_offset = ntohl(src_params->fPosition.video_offset);
  411. dst_params->fPosition.unique_2 = ntohll(src_params->fPosition.unique_2);
  412. }
  413. // Utility *******************************************************************************************************
  414. SERVER_EXPORT int SocketAPIInit()
  415. {
  416. #ifdef WIN32
  417. WORD wVersionRequested = MAKEWORD ( 2, 2 );
  418. WSADATA wsaData;
  419. if ( WSAStartup ( wVersionRequested, &wsaData ) != 0 )
  420. {
  421. jack_error ( "WSAStartup error : %s", strerror ( NET_ERROR_CODE ) );
  422. return -1;
  423. }
  424. if ( LOBYTE ( wsaData.wVersion ) != 2 || HIBYTE ( wsaData.wVersion ) != 2 )
  425. {
  426. jack_error ( "Could not find a useable version of Winsock.dll\n" );
  427. WSACleanup();
  428. return -1;
  429. }
  430. #endif
  431. return 0;
  432. }
  433. SERVER_EXPORT int SocketAPIEnd()
  434. {
  435. #ifdef WIN32
  436. return WSACleanup();
  437. #endif
  438. return 0;
  439. }
  440. SERVER_EXPORT const char* GetTransportState ( int transport_state )
  441. {
  442. switch ( transport_state )
  443. {
  444. case JackTransportRolling:
  445. return "rolling";
  446. case JackTransportStarting:
  447. return "starting";
  448. case JackTransportStopped:
  449. return "stopped";
  450. case JackTransportNetStarting:
  451. return "netstarting";
  452. }
  453. return NULL;
  454. }
  455. }