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.

545 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. fCycleSize = params->fMtu * (max(params->fSendMidiChannels, params->fReturnMidiChannels) *
  31. params->fPeriodSize * sizeof(sample_t) / (params->fMtu - sizeof(packet_header_t)));
  32. }
  33. NetMidiBuffer::~NetMidiBuffer()
  34. {
  35. delete[] fBuffer;
  36. delete[] fPortBuffer;
  37. }
  38. size_t NetMidiBuffer::GetSize()
  39. {
  40. return fMaxBufsize;
  41. }
  42. size_t NetMidiBuffer::GetCycleSize()
  43. {
  44. return fCycleSize;
  45. }
  46. int NetMidiBuffer::GetNumPackets()
  47. {
  48. /*
  49. return (data_size % PACKET_AVAILABLE_SIZE)
  50. ? (data_size / PACKET_AVAILABLE_SIZE + 1)
  51. : data_size / PACKET_AVAILABLE_SIZE;
  52. */
  53. //TODO
  54. return 0;
  55. }
  56. void NetMidiBuffer::SetBuffer ( int index, JackMidiBuffer* buffer )
  57. {
  58. fPortBuffer[index] = buffer;
  59. }
  60. JackMidiBuffer* NetMidiBuffer::GetBuffer ( int index )
  61. {
  62. return fPortBuffer[index];
  63. }
  64. void NetMidiBuffer::DisplayEvents()
  65. {
  66. for ( int port_index = 0; port_index < fNPorts; port_index++ )
  67. {
  68. for ( uint event = 0; event < fPortBuffer[port_index]->event_count; event++ )
  69. if ( fPortBuffer[port_index]->IsValid() )
  70. jack_info ( "port %d : midi event %u/%u -> time : %u, size : %u",
  71. port_index + 1, event + 1, fPortBuffer[port_index]->event_count,
  72. fPortBuffer[port_index]->events[event].time, fPortBuffer[port_index]->events[event].size );
  73. }
  74. }
  75. int NetMidiBuffer::RenderFromJackPorts()
  76. {
  77. int pos = 0;
  78. size_t copy_size;
  79. for ( int port_index = 0; port_index < fNPorts; port_index++ )
  80. {
  81. char* write_pos = fBuffer + pos;
  82. copy_size = sizeof ( JackMidiBuffer ) + fPortBuffer[port_index]->event_count * sizeof ( JackMidiEvent );
  83. memcpy ( fBuffer + pos, fPortBuffer[port_index], copy_size );
  84. pos += copy_size;
  85. memcpy ( fBuffer + pos, fPortBuffer[port_index] + ( fPortBuffer[port_index]->buffer_size - fPortBuffer[port_index]->write_pos ),
  86. fPortBuffer[port_index]->write_pos );
  87. pos += fPortBuffer[port_index]->write_pos;
  88. JackMidiBuffer* midi_buffer = reinterpret_cast<JackMidiBuffer*>(write_pos);
  89. MidiBufferHToN(midi_buffer, midi_buffer);
  90. }
  91. return pos;
  92. }
  93. int NetMidiBuffer::RenderToJackPorts()
  94. {
  95. int pos = 0;
  96. int copy_size;
  97. for ( int port_index = 0; port_index < fNPorts; port_index++ )
  98. {
  99. JackMidiBuffer* midi_buffer = reinterpret_cast<JackMidiBuffer*>(fBuffer + pos);
  100. MidiBufferNToH(midi_buffer, midi_buffer);
  101. copy_size = sizeof ( JackMidiBuffer ) + reinterpret_cast<JackMidiBuffer*> ( fBuffer + pos )->event_count * sizeof ( JackMidiEvent );
  102. memcpy ( fPortBuffer[port_index], fBuffer + pos, copy_size );
  103. pos += copy_size;
  104. memcpy ( fPortBuffer[port_index] + ( fPortBuffer[port_index]->buffer_size - fPortBuffer[port_index]->write_pos ),
  105. fBuffer + pos, fPortBuffer[port_index]->write_pos );
  106. pos += fPortBuffer[port_index]->write_pos;
  107. }
  108. return pos;
  109. }
  110. int NetMidiBuffer::RenderFromNetwork ( int subcycle, size_t copy_size )
  111. {
  112. memcpy ( fBuffer + subcycle * fMaxPcktSize, fNetBuffer, copy_size );
  113. return copy_size;
  114. }
  115. int NetMidiBuffer::RenderToNetwork ( int subcycle, size_t total_size )
  116. {
  117. int size = total_size - subcycle * fMaxPcktSize;
  118. int copy_size = ( size <= fMaxPcktSize ) ? size : fMaxPcktSize;
  119. memcpy ( fNetBuffer, fBuffer + subcycle * fMaxPcktSize, copy_size );
  120. return copy_size;
  121. }
  122. // net audio buffer *********************************************************************************
  123. NetSingleAudioBuffer::NetSingleAudioBuffer ( session_params_t* params, uint32_t nports, char* net_buffer )
  124. : fPortBuffer(params, nports), fNetBuffer(net_buffer)
  125. {}
  126. NetSingleAudioBuffer::~NetSingleAudioBuffer()
  127. {}
  128. size_t NetSingleAudioBuffer::GetSize()
  129. {
  130. return fPortBuffer.GetSize();
  131. }
  132. size_t NetSingleAudioBuffer::GetCycleSize()
  133. {
  134. return fPortBuffer.GetCycleSize();
  135. }
  136. void NetSingleAudioBuffer::SetBuffer ( int index, sample_t* buffer )
  137. {
  138. fPortBuffer.SetBuffer(index, buffer);
  139. }
  140. sample_t* NetSingleAudioBuffer::GetBuffer ( int index )
  141. {
  142. return fPortBuffer.GetBuffer(index);
  143. }
  144. int NetSingleAudioBuffer::RenderFromJackPorts ()
  145. {
  146. return fPortBuffer.RenderFromJackPorts();
  147. }
  148. int NetSingleAudioBuffer::RenderToJackPorts ()
  149. {
  150. return fPortBuffer.RenderToJackPorts();
  151. }
  152. //network<->buffer
  153. int NetSingleAudioBuffer::RenderFromNetwork ( int cycle, int subcycle, size_t copy_size )
  154. {
  155. return fPortBuffer.RenderFromNetwork(fNetBuffer, cycle, subcycle, copy_size);
  156. }
  157. int NetSingleAudioBuffer::RenderToNetwork (int subcycle, size_t total_size )
  158. {
  159. return fPortBuffer.RenderToNetwork(fNetBuffer, subcycle, total_size);
  160. }
  161. // Buffered
  162. /*
  163. NetBufferedAudioBuffer::NetBufferedAudioBuffer ( session_params_t* params, uint32_t nports, char* net_buffer )
  164. {
  165. fMaxCycle = 0;
  166. fNetBuffer = net_buffer;
  167. for (int i = 0; i < AUDIO_BUFFER_SIZE; i++) {
  168. fPortBuffer[i].Init(params, nports);
  169. }
  170. fJackPortBuffer = new sample_t* [nports];
  171. for ( uint32_t port_index = 0; port_index < nports; port_index++ )
  172. fJackPortBuffer[port_index] = NULL;
  173. }
  174. NetBufferedAudioBuffer::~NetBufferedAudioBuffer()
  175. {
  176. delete [] fJackPortBuffer;
  177. }
  178. size_t NetBufferedAudioBuffer::GetSize()
  179. {
  180. return fPortBuffer[0].GetSize();
  181. }
  182. size_t NetBufferedAudioBuffer::GetCycleSize()
  183. {
  184. return fPortBuffer[0].GetCycleSize();
  185. }
  186. void NetBufferedAudioBuffer::SetBuffer ( int index, sample_t* buffer )
  187. {
  188. fJackPortBuffer[index] = buffer;
  189. }
  190. sample_t* NetBufferedAudioBuffer::GetBuffer ( int index )
  191. {
  192. return fJackPortBuffer[index];
  193. }
  194. void NetBufferedAudioBuffer::RenderFromJackPorts (int subcycle )
  195. {
  196. fPortBuffer[0].RenderFromJackPorts(fNetBuffer, subcycle); // Always use first buffer...
  197. }
  198. void NetBufferedAudioBuffer::RenderToJackPorts (int cycle, int subcycle)
  199. {
  200. if (cycle < fMaxCycle) {
  201. jack_info("Wrong order fCycle %d subcycle %d fMaxCycle %d", cycle, subcycle, fMaxCycle);
  202. }
  203. fPortBuffer[cycle % AUDIO_BUFFER_SIZE].RenderToJackPorts(fNetBuffer, subcycle);
  204. }
  205. void NetBufferedAudioBuffer::FinishRenderToJackPorts (int cycle)
  206. {
  207. fMaxCycle = std::max(fMaxCycle, cycle);
  208. fPortBuffer[(cycle + 1) % AUDIO_BUFFER_SIZE].Copy(fJackPortBuffer); // Copy internal buffer in JACK ports
  209. }
  210. */
  211. // SessionParams ************************************************************************************
  212. SERVER_EXPORT void SessionParamsHToN ( session_params_t* src_params, session_params_t* dst_params )
  213. {
  214. memcpy(dst_params, src_params, sizeof(session_params_t));
  215. dst_params->fPacketID = htonl ( src_params->fPacketID );
  216. dst_params->fMtu = htonl ( src_params->fMtu );
  217. dst_params->fID = htonl ( src_params->fID );
  218. dst_params->fTransportSync = htonl ( src_params->fTransportSync );
  219. dst_params->fSendAudioChannels = htonl ( src_params->fSendAudioChannels );
  220. dst_params->fReturnAudioChannels = htonl ( src_params->fReturnAudioChannels );
  221. dst_params->fSendMidiChannels = htonl ( src_params->fSendMidiChannels );
  222. dst_params->fReturnMidiChannels = htonl ( src_params->fReturnMidiChannels );
  223. dst_params->fSampleRate = htonl ( src_params->fSampleRate );
  224. dst_params->fPeriodSize = htonl ( src_params->fPeriodSize );
  225. dst_params->fBitdepth = htonl ( src_params->fBitdepth );
  226. dst_params->fSlaveSyncMode = htonl ( src_params->fSlaveSyncMode );
  227. }
  228. SERVER_EXPORT void SessionParamsNToH ( session_params_t* src_params, session_params_t* dst_params )
  229. {
  230. memcpy(dst_params, src_params, sizeof(session_params_t));
  231. dst_params->fPacketID = ntohl ( src_params->fPacketID );
  232. dst_params->fMtu = ntohl ( src_params->fMtu );
  233. dst_params->fID = ntohl ( src_params->fID );
  234. dst_params->fTransportSync = ntohl ( src_params->fTransportSync );
  235. dst_params->fSendAudioChannels = ntohl ( src_params->fSendAudioChannels );
  236. dst_params->fReturnAudioChannels = ntohl ( src_params->fReturnAudioChannels );
  237. dst_params->fSendMidiChannels = ntohl ( src_params->fSendMidiChannels );
  238. dst_params->fReturnMidiChannels = ntohl ( src_params->fReturnMidiChannels );
  239. dst_params->fSampleRate = ntohl ( src_params->fSampleRate );
  240. dst_params->fPeriodSize = ntohl ( src_params->fPeriodSize );
  241. dst_params->fBitdepth = ntohl ( src_params->fBitdepth );
  242. dst_params->fSlaveSyncMode = ntohl ( src_params->fSlaveSyncMode );
  243. }
  244. SERVER_EXPORT void SessionParamsDisplay ( session_params_t* params )
  245. {
  246. char bitdepth[16];
  247. ( params->fBitdepth ) ? sprintf ( bitdepth, "%u", params->fBitdepth ) : sprintf ( bitdepth, "%s", "float" );
  248. char mode[8];
  249. switch ( params->fNetworkMode )
  250. {
  251. case 's' :
  252. strcpy ( mode, "slow" );
  253. break;
  254. case 'n' :
  255. strcpy ( mode, "normal" );
  256. break;
  257. case 'f' :
  258. strcpy ( mode, "fast" );
  259. break;
  260. }
  261. jack_info ( "**************** Network parameters ****************" );
  262. jack_info ( "Name : %s", params->fName );
  263. jack_info ( "Protocol revision : %d", params->fProtocolVersion );
  264. jack_info ( "MTU : %u", params->fMtu );
  265. jack_info ( "Master name : %s", params->fMasterNetName );
  266. jack_info ( "Slave name : %s", params->fSlaveNetName );
  267. jack_info ( "ID : %u", params->fID );
  268. jack_info ( "Transport Sync : %s", ( params->fTransportSync ) ? "yes" : "no" );
  269. jack_info ( "Send channels (audio - midi) : %d - %d", params->fSendAudioChannels, params->fSendMidiChannels );
  270. jack_info ( "Return channels (audio - midi) : %d - %d", params->fReturnAudioChannels, params->fReturnMidiChannels );
  271. jack_info ( "Sample rate : %u frames per second", params->fSampleRate );
  272. jack_info ( "Period size : %u frames per period", params->fPeriodSize );
  273. jack_info ( "Bitdepth : %s", bitdepth );
  274. jack_info ( "Slave mode : %s", ( params->fSlaveSyncMode ) ? "sync" : "async" );
  275. jack_info ( "Network mode : %s", mode );
  276. jack_info ( "****************************************************" );
  277. }
  278. SERVER_EXPORT sync_packet_type_t GetPacketType ( session_params_t* params )
  279. {
  280. switch ( params->fPacketID )
  281. {
  282. case 0:
  283. return SLAVE_AVAILABLE;
  284. case 1:
  285. return SLAVE_SETUP;
  286. case 2:
  287. return START_MASTER;
  288. case 3:
  289. return START_SLAVE;
  290. case 4:
  291. return KILL_MASTER;
  292. }
  293. return INVALID;
  294. }
  295. SERVER_EXPORT int SetPacketType ( session_params_t* params, sync_packet_type_t packet_type )
  296. {
  297. switch ( packet_type )
  298. {
  299. case INVALID:
  300. return -1;
  301. case SLAVE_AVAILABLE:
  302. params->fPacketID = 0;
  303. break;
  304. case SLAVE_SETUP:
  305. params->fPacketID = 1;
  306. break;
  307. case START_MASTER:
  308. params->fPacketID = 2;
  309. break;
  310. case START_SLAVE:
  311. params->fPacketID = 3;
  312. break;
  313. case KILL_MASTER:
  314. params->fPacketID = 4;
  315. }
  316. return 0;
  317. }
  318. // Packet header **********************************************************************************
  319. SERVER_EXPORT void PacketHeaderHToN ( packet_header_t* src_header, packet_header_t* dst_header )
  320. {
  321. memcpy(dst_header, src_header, sizeof(packet_header_t));
  322. dst_header->fID = htonl ( src_header->fID );
  323. dst_header->fBitdepth = htonl ( src_header->fBitdepth );
  324. dst_header->fNumPacket = htonl ( src_header->fNumPacket );
  325. dst_header->fPacketSize = htonl ( src_header->fPacketSize );
  326. dst_header->fCycle = htonl ( src_header->fCycle );
  327. dst_header->fSubCycle = htonl ( src_header->fSubCycle );
  328. dst_header->fIsLastPckt = htonl ( src_header->fIsLastPckt );
  329. }
  330. SERVER_EXPORT void PacketHeaderNToH ( packet_header_t* src_header, packet_header_t* dst_header )
  331. {
  332. memcpy(dst_header, src_header, sizeof(packet_header_t));
  333. dst_header->fID = ntohl ( src_header->fID );
  334. dst_header->fBitdepth = ntohl ( src_header->fBitdepth );
  335. dst_header->fNumPacket = ntohl ( src_header->fNumPacket );
  336. dst_header->fPacketSize = ntohl ( src_header->fPacketSize );
  337. dst_header->fCycle = ntohl ( src_header->fCycle );
  338. dst_header->fSubCycle = ntohl ( src_header->fSubCycle );
  339. dst_header->fIsLastPckt = ntohl ( src_header->fIsLastPckt );
  340. }
  341. SERVER_EXPORT void PacketHeaderDisplay ( packet_header_t* header )
  342. {
  343. char bitdepth[16];
  344. ( header->fBitdepth ) ? sprintf ( bitdepth, "%u", header->fBitdepth ) : sprintf ( bitdepth, "%s", "float" );
  345. jack_info ( "********************Header********************" );
  346. jack_info ( "Data type : %c", header->fDataType );
  347. jack_info ( "Data stream : %c", header->fDataStream );
  348. jack_info ( "ID : %u", header->fID );
  349. jack_info ( "Cycle : %u", header->fCycle );
  350. jack_info ( "SubCycle : %u", header->fSubCycle );
  351. jack_info ( "Midi packets : %u", header->fNumPacket );
  352. jack_info ( "Last packet : '%s'", ( header->fIsLastPckt ) ? "yes" : "no" );
  353. jack_info ( "Bitdepth : %s", bitdepth );
  354. jack_info ( "**********************************************" );
  355. }
  356. SERVER_EXPORT void NetTransportDataDisplay ( net_transport_data_t* data )
  357. {
  358. jack_info ( "********************Network Transport********************" );
  359. jack_info ( "Transport new state : %u", data->fNewState );
  360. jack_info ( "Transport timebase master : %u", data->fTimebaseMaster );
  361. jack_info ( "Transport cycle state : %u", data->fState );
  362. jack_info ( "**********************************************" );
  363. }
  364. SERVER_EXPORT void MidiBufferHToN ( JackMidiBuffer* src_buffer, JackMidiBuffer* dst_buffer )
  365. {
  366. dst_buffer->magic = htonl(src_buffer->magic);
  367. dst_buffer->buffer_size = htonl(src_buffer->buffer_size);
  368. dst_buffer->nframes = htonl(src_buffer->nframes);
  369. dst_buffer->write_pos = htonl(src_buffer->write_pos);
  370. dst_buffer->event_count = htonl(src_buffer->event_count);
  371. dst_buffer->lost_events = htonl(src_buffer->lost_events);
  372. dst_buffer->mix_index = htonl(src_buffer->mix_index);
  373. }
  374. SERVER_EXPORT void MidiBufferNToH ( JackMidiBuffer* src_buffer, JackMidiBuffer* dst_buffer )
  375. {
  376. dst_buffer->magic = ntohl(src_buffer->magic);
  377. dst_buffer->buffer_size = ntohl(src_buffer->buffer_size);
  378. dst_buffer->nframes = ntohl(src_buffer->nframes);
  379. dst_buffer->write_pos = ntohl(src_buffer->write_pos);
  380. dst_buffer->event_count = ntohl(src_buffer->event_count);
  381. dst_buffer->lost_events = ntohl(src_buffer->lost_events);
  382. dst_buffer->mix_index = ntohl(src_buffer->mix_index);
  383. }
  384. SERVER_EXPORT void TransportDataHToN ( net_transport_data_t* src_params, net_transport_data_t* dst_params )
  385. {
  386. dst_params->fNewState = htonl(src_params->fNewState);
  387. dst_params->fTimebaseMaster = htonl(src_params->fTimebaseMaster);
  388. dst_params->fState = htonl(src_params->fState);
  389. dst_params->fPosition.unique_1 = htonll(src_params->fPosition.unique_1);
  390. dst_params->fPosition.usecs = htonl(src_params->fPosition.usecs);
  391. dst_params->fPosition.frame_rate = htonl(src_params->fPosition.frame_rate);
  392. dst_params->fPosition.frame = htonl(src_params->fPosition.frame);
  393. dst_params->fPosition.valid = (jack_position_bits_t)htonl((uint32_t)src_params->fPosition.valid);
  394. dst_params->fPosition.bar = htonl(src_params->fPosition.bar);
  395. dst_params->fPosition.beat = htonl(src_params->fPosition.beat);
  396. dst_params->fPosition.tick = htonl(src_params->fPosition.tick);
  397. dst_params->fPosition.bar_start_tick = htonll((uint64_t)src_params->fPosition.bar_start_tick);
  398. dst_params->fPosition.beats_per_bar = htonl((uint32_t)src_params->fPosition.beats_per_bar);
  399. dst_params->fPosition.beat_type = htonl((uint32_t)src_params->fPosition.beat_type);
  400. dst_params->fPosition.ticks_per_beat = htonll((uint64_t)src_params->fPosition.ticks_per_beat);
  401. dst_params->fPosition.beats_per_minute = htonll((uint64_t)src_params->fPosition.beats_per_minute);
  402. dst_params->fPosition.frame_time = htonll((uint64_t)src_params->fPosition.frame_time);
  403. dst_params->fPosition.next_time = htonll((uint64_t)src_params->fPosition.next_time);
  404. dst_params->fPosition.bbt_offset = htonl(src_params->fPosition.bbt_offset);
  405. dst_params->fPosition.audio_frames_per_video_frame = htonl((uint32_t)src_params->fPosition.audio_frames_per_video_frame);
  406. dst_params->fPosition.video_offset = htonl(src_params->fPosition.video_offset);
  407. dst_params->fPosition.unique_2 = htonll(src_params->fPosition.unique_2);
  408. }
  409. SERVER_EXPORT void TransportDataNToH ( net_transport_data_t* src_params, net_transport_data_t* dst_params )
  410. {
  411. dst_params->fNewState = ntohl(src_params->fNewState);
  412. dst_params->fTimebaseMaster = ntohl(src_params->fTimebaseMaster);
  413. dst_params->fState = ntohl(src_params->fState);
  414. dst_params->fPosition.unique_1 = ntohll(src_params->fPosition.unique_1);
  415. dst_params->fPosition.usecs = ntohl(src_params->fPosition.usecs);
  416. dst_params->fPosition.frame_rate = ntohl(src_params->fPosition.frame_rate);
  417. dst_params->fPosition.frame = ntohl(src_params->fPosition.frame);
  418. dst_params->fPosition.valid = (jack_position_bits_t)ntohl((uint32_t)src_params->fPosition.valid);
  419. dst_params->fPosition.bar = ntohl(src_params->fPosition.bar);
  420. dst_params->fPosition.beat = ntohl(src_params->fPosition.beat);
  421. dst_params->fPosition.tick = ntohl(src_params->fPosition.tick);
  422. dst_params->fPosition.bar_start_tick = ntohll((uint64_t)src_params->fPosition.bar_start_tick);
  423. dst_params->fPosition.beats_per_bar = ntohl((uint32_t)src_params->fPosition.beats_per_bar);
  424. dst_params->fPosition.beat_type = ntohl((uint32_t)src_params->fPosition.beat_type);
  425. dst_params->fPosition.ticks_per_beat = ntohll((uint64_t)src_params->fPosition.ticks_per_beat);
  426. dst_params->fPosition.beats_per_minute = ntohll((uint64_t)src_params->fPosition.beats_per_minute);
  427. dst_params->fPosition.frame_time = ntohll((uint64_t)src_params->fPosition.frame_time);
  428. dst_params->fPosition.next_time = ntohll((uint64_t)src_params->fPosition.next_time);
  429. dst_params->fPosition.bbt_offset = ntohl(src_params->fPosition.bbt_offset);
  430. dst_params->fPosition.audio_frames_per_video_frame = ntohl((uint32_t)src_params->fPosition.audio_frames_per_video_frame);
  431. dst_params->fPosition.video_offset = ntohl(src_params->fPosition.video_offset);
  432. dst_params->fPosition.unique_2 = ntohll(src_params->fPosition.unique_2);
  433. }
  434. // Utility *******************************************************************************************************
  435. SERVER_EXPORT int SocketAPIInit()
  436. {
  437. #ifdef WIN32
  438. WORD wVersionRequested = MAKEWORD ( 2, 2 );
  439. WSADATA wsaData;
  440. if ( WSAStartup ( wVersionRequested, &wsaData ) != 0 )
  441. {
  442. jack_error ( "WSAStartup error : %s", strerror ( NET_ERROR_CODE ) );
  443. return -1;
  444. }
  445. if ( LOBYTE ( wsaData.wVersion ) != 2 || HIBYTE ( wsaData.wVersion ) != 2 )
  446. {
  447. jack_error ( "Could not find a useable version of Winsock.dll\n" );
  448. WSACleanup();
  449. return -1;
  450. }
  451. #endif
  452. return 0;
  453. }
  454. SERVER_EXPORT int SocketAPIEnd()
  455. {
  456. #ifdef WIN32
  457. return WSACleanup();
  458. #endif
  459. return 0;
  460. }
  461. SERVER_EXPORT const char* GetTransportState ( int transport_state )
  462. {
  463. switch ( transport_state )
  464. {
  465. case JackTransportRolling:
  466. return "rolling";
  467. case JackTransportStarting:
  468. return "starting";
  469. case JackTransportStopped:
  470. return "stopped";
  471. case JackTransportNetStarting:
  472. return "netstarting";
  473. }
  474. return NULL;
  475. }
  476. }