JackNetTool.cpp 21.6 KB
Newer Older
1
/*
sletz's avatar
sletz committed
2
Copyright (C) 2008 Romain Moret at Grame
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

*/
sletz's avatar
sletz committed
19
20
21
22
23
24
25
26
27

#include "JackNetTool.h"

using namespace std;

namespace Jack
{
// NetMidiBuffer**********************************************************************************

28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
    NetMidiBuffer::NetMidiBuffer ( session_params_t* params, uint32_t nports, char* net_buffer )
    {
        fNPorts = nports;
        fMaxBufsize = fNPorts * sizeof ( sample_t ) * params->fPeriodSize ;
        fMaxPcktSize = params->fMtu - sizeof ( packet_header_t );
        fBuffer = new char[fMaxBufsize];
        fPortBuffer = new JackMidiBuffer* [fNPorts];
        for ( int port_index = 0; port_index < fNPorts; port_index++ )
            fPortBuffer[port_index] = NULL;
        fNetBuffer = net_buffer;
    }

    NetMidiBuffer::~NetMidiBuffer()
    {
        delete[] fBuffer;
        delete[] fPortBuffer;
    }

    size_t NetMidiBuffer::GetSize()
    {
        return fMaxBufsize;
    }
50

51
    void NetMidiBuffer::SetBuffer ( int index, JackMidiBuffer* buffer )
sletz's avatar
Cleanup    
sletz committed
52
53
54
    {
        fPortBuffer[index] = buffer;
    }
55

moret's avatar
moret committed
56
57
58
59
60
    JackMidiBuffer* NetMidiBuffer::GetBuffer ( int index )
    {
        return fPortBuffer[index];
    }

61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
    void NetMidiBuffer::DisplayEvents()
    {
        for ( int port_index = 0; port_index < fNPorts; port_index++ )
        {
            for ( uint event = 0; event < fPortBuffer[port_index]->event_count; event++ )
                if ( fPortBuffer[port_index]->IsValid() )
                    jack_info ( "port %d : midi event %u/%u -> time : %u, size : %u",
                                port_index + 1, event + 1, fPortBuffer[port_index]->event_count,
                                fPortBuffer[port_index]->events[event].time, fPortBuffer[port_index]->events[event].size );
        }
    }

    int NetMidiBuffer::RenderFromJackPorts()
    {
        int pos = 0;
        size_t copy_size;
        for ( int port_index = 0; port_index < fNPorts; port_index++ )
        {
79
80
            char* write_pos = fBuffer + pos;
            
81
82
83
84
85
86
            copy_size = sizeof ( JackMidiBuffer ) + fPortBuffer[port_index]->event_count * sizeof ( JackMidiEvent );
            memcpy ( fBuffer + pos, fPortBuffer[port_index], copy_size );
            pos += copy_size;
            memcpy ( fBuffer + pos, fPortBuffer[port_index] + ( fPortBuffer[port_index]->buffer_size - fPortBuffer[port_index]->write_pos ),
                     fPortBuffer[port_index]->write_pos );
            pos += fPortBuffer[port_index]->write_pos;
87
88
89
            
            JackMidiBuffer* midi_buffer = reinterpret_cast<JackMidiBuffer*>(write_pos);
            MidiBufferHToN(midi_buffer, midi_buffer);
90
91
92
93
94
95
96
97
98
99
        }
        return pos;
    }

    int NetMidiBuffer::RenderToJackPorts()
    {
        int pos = 0;
        int copy_size;
        for ( int port_index = 0; port_index < fNPorts; port_index++ )
        {
100
101
102
            JackMidiBuffer* midi_buffer = reinterpret_cast<JackMidiBuffer*>(fBuffer + pos);
            MidiBufferNToH(midi_buffer, midi_buffer);
            
103
104
105
106
107
108
109
110
111
            copy_size = sizeof ( JackMidiBuffer ) + reinterpret_cast<JackMidiBuffer*> ( fBuffer + pos )->event_count * sizeof ( JackMidiEvent );
            memcpy ( fPortBuffer[port_index], fBuffer + pos, copy_size );
            pos += copy_size;
            memcpy ( fPortBuffer[port_index] + ( fPortBuffer[port_index]->buffer_size - fPortBuffer[port_index]->write_pos ),
                     fBuffer + pos, fPortBuffer[port_index]->write_pos );
            pos += fPortBuffer[port_index]->write_pos;
        }
        return pos;
    }
112
    
113
114
115
116
117
118
119
120
121
122
123
124
125
    int NetMidiBuffer::RenderFromNetwork ( int subcycle, size_t copy_size )
    {
        memcpy ( fBuffer + subcycle * fMaxPcktSize, fNetBuffer, copy_size );
        return copy_size;
    }

    int NetMidiBuffer::RenderToNetwork ( int subcycle, size_t total_size )
    {
        int size = total_size - subcycle * fMaxPcktSize;
        int copy_size = ( size <= fMaxPcktSize ) ? size : fMaxPcktSize;
        memcpy ( fNetBuffer, fBuffer + subcycle * fMaxPcktSize, copy_size );
        return copy_size;
    }
sletz's avatar
sletz committed
126

127

sletz's avatar
sletz committed
128
129
// net audio buffer *********************************************************************************

130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
    NetAudioBuffer::NetAudioBuffer ( session_params_t* params, uint32_t nports, char* net_buffer )
    {
        fNPorts = nports;
        fPeriodSize = params->fPeriodSize;
        fSubPeriodSize = params->fFramesPerPacket;
        fSubPeriodBytesSize = fSubPeriodSize * sizeof ( sample_t );
        fPortBuffer = new sample_t* [fNPorts];
        for ( int port_index = 0; port_index < fNPorts; port_index++ )
            fPortBuffer[port_index] = NULL;
        fNetBuffer = net_buffer;
    }

    NetAudioBuffer::~NetAudioBuffer()
    {
        delete[] fPortBuffer;
    }

    size_t NetAudioBuffer::GetSize()
    {
        return fNPorts * fSubPeriodBytesSize;
    }
151

moret's avatar
moret committed
152
    void NetAudioBuffer::SetBuffer ( int index, sample_t* buffer )
sletz's avatar
Cleanup    
sletz committed
153
154
155
    {
        fPortBuffer[index] = buffer;
    }
156

moret's avatar
moret committed
157
158
159
160
161
    sample_t* NetAudioBuffer::GetBuffer ( int index )
    {
        return fPortBuffer[index];
    }

162
#ifdef __BIG_ENDIAN__
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203

    static inline float SwapFloat(float f)
    {
          union
          {
            float f;
            unsigned char b[4];
          } dat1, dat2;

          dat1.f = f;
          dat2.b[0] = dat1.b[3];
          dat2.b[1] = dat1.b[2];
          dat2.b[2] = dat1.b[1];
          dat2.b[3] = dat1.b[0];
          return dat2.f;
    }

    void NetAudioBuffer::RenderFromJackPorts ( int subcycle )
    {
        for ( int port_index = 0; port_index < fNPorts; port_index++ ) {
            float* src = (float*)(fPortBuffer[port_index] + subcycle * fSubPeriodSize);
            float* dst = (float*)(fNetBuffer + port_index * fSubPeriodBytesSize);
            for (unsigned int sample = 0; sample < fSubPeriodBytesSize / sizeof(float); sample++) {
                dst[sample] = SwapFloat(src[sample]);
            }
        }
    }

    void NetAudioBuffer::RenderToJackPorts ( int subcycle )
    {
        for ( int port_index = 0; port_index < fNPorts; port_index++ ) {
            float* src = (float*)(fNetBuffer + port_index * fSubPeriodBytesSize);
            float* dst = (float*)(fPortBuffer[port_index] + subcycle * fSubPeriodSize);
            for (unsigned int sample = 0; sample < fSubPeriodBytesSize / sizeof(float); sample++) {
                dst[sample] = SwapFloat(src[sample]);
            }
        }    
    }
    
#else

204
205
206
207
208
209
210
211
212
213
214
    void NetAudioBuffer::RenderFromJackPorts ( int subcycle )
    {
        for ( int port_index = 0; port_index < fNPorts; port_index++ )
            memcpy ( fNetBuffer + port_index * fSubPeriodBytesSize, fPortBuffer[port_index] + subcycle * fSubPeriodSize, fSubPeriodBytesSize );
    }

    void NetAudioBuffer::RenderToJackPorts ( int subcycle )
    {
        for ( int port_index = 0; port_index < fNPorts; port_index++ )
            memcpy ( fPortBuffer[port_index] + subcycle * fSubPeriodSize, fNetBuffer + port_index * fSubPeriodBytesSize, fSubPeriodBytesSize );
    }
sletz's avatar
sletz committed
215

216
217
#endif

sletz's avatar
sletz committed
218
219
// SessionParams ************************************************************************************

220
    SERVER_EXPORT void SessionParamsHToN ( session_params_t* src_params, session_params_t* dst_params )
221
    {
222
223
224
225
226
227
228
229
230
231
232
233
234
235
        memcpy(dst_params, src_params, sizeof(session_params_t));
        dst_params->fPacketID = htonl ( src_params->fPacketID );
        dst_params->fMtu = htonl ( src_params->fMtu );
        dst_params->fID = htonl ( src_params->fID );
        dst_params->fTransportSync = htonl ( src_params->fTransportSync );
        dst_params->fSendAudioChannels = htonl ( src_params->fSendAudioChannels );
        dst_params->fReturnAudioChannels = htonl ( src_params->fReturnAudioChannels );
        dst_params->fSendMidiChannels = htonl ( src_params->fSendMidiChannels );
        dst_params->fReturnMidiChannels = htonl ( src_params->fReturnMidiChannels );
        dst_params->fSampleRate = htonl ( src_params->fSampleRate );
        dst_params->fPeriodSize = htonl ( src_params->fPeriodSize );
        dst_params->fFramesPerPacket = htonl ( src_params->fFramesPerPacket );
        dst_params->fBitdepth = htonl ( src_params->fBitdepth );
        dst_params->fSlaveSyncMode = htonl ( src_params->fSlaveSyncMode );
236
237
    }

238
    SERVER_EXPORT void SessionParamsNToH (  session_params_t* src_params, session_params_t* dst_params )
239
    {
240
241
242
243
244
245
246
247
248
249
250
251
252
253
        memcpy(dst_params, src_params, sizeof(session_params_t));
        dst_params->fPacketID = ntohl ( src_params->fPacketID );
        dst_params->fMtu = ntohl ( src_params->fMtu );
        dst_params->fID = ntohl ( src_params->fID );
        dst_params->fTransportSync = ntohl ( src_params->fTransportSync );
        dst_params->fSendAudioChannels = ntohl ( src_params->fSendAudioChannels );
        dst_params->fReturnAudioChannels = ntohl ( src_params->fReturnAudioChannels );
        dst_params->fSendMidiChannels = ntohl ( src_params->fSendMidiChannels );
        dst_params->fReturnMidiChannels = ntohl ( src_params->fReturnMidiChannels );
        dst_params->fSampleRate = ntohl ( src_params->fSampleRate );
        dst_params->fPeriodSize = ntohl ( src_params->fPeriodSize );
        dst_params->fFramesPerPacket = ntohl ( src_params->fFramesPerPacket );
        dst_params->fBitdepth = ntohl ( src_params->fBitdepth );
        dst_params->fSlaveSyncMode = ntohl ( src_params->fSlaveSyncMode );
254
255
    }

256
    SERVER_EXPORT void SessionParamsDisplay ( session_params_t* params )
257
    {
moret's avatar
moret committed
258
259
        char bitdepth[16];
        ( params->fBitdepth ) ? sprintf ( bitdepth, "%u", params->fBitdepth ) : sprintf ( bitdepth, "%s", "float" );
moret's avatar
moret committed
260
261
262
        char mode[8];
        switch ( params->fNetworkMode )
        {
moret's avatar
moret committed
263
264
265
266
267
268
269
270
271
            case 's' :
                strcpy ( mode, "slow" );
                break;
            case 'n' :
                strcpy ( mode, "normal" );
                break;
            case 'f' :
                strcpy ( mode, "fast" );
                break;
moret's avatar
moret committed
272
        }
273
274
        jack_info ( "**************** Network parameters ****************" );
        jack_info ( "Name : %s", params->fName );
275
        jack_info ( "Protocol revision : %d", params->fProtocolVersion );
276
277
278
279
        jack_info ( "MTU : %u", params->fMtu );
        jack_info ( "Master name : %s", params->fMasterNetName );
        jack_info ( "Slave name : %s", params->fSlaveNetName );
        jack_info ( "ID : %u", params->fID );
moret's avatar
moret committed
280
        jack_info ( "Transport Sync : %s", ( params->fTransportSync ) ? "yes" : "no" );
281
282
283
284
285
286
        jack_info ( "Send channels (audio - midi) : %d - %d", params->fSendAudioChannels, params->fSendMidiChannels );
        jack_info ( "Return channels (audio - midi) : %d - %d", params->fReturnAudioChannels, params->fReturnMidiChannels );
        jack_info ( "Sample rate : %u frames per second", params->fSampleRate );
        jack_info ( "Period size : %u frames per period", params->fPeriodSize );
        jack_info ( "Frames per packet : %u", params->fFramesPerPacket );
        jack_info ( "Packet per period : %u", params->fPeriodSize / params->fFramesPerPacket );
287
        jack_info ( "Bitdepth : %s", bitdepth );
moret's avatar
moret committed
288
        jack_info ( "Slave mode : %s", ( params->fSlaveSyncMode ) ? "sync" : "async" );
moret's avatar
moret committed
289
        jack_info ( "Network mode : %s", mode );
290
        jack_info ( "****************************************************" );
291
292
    }

293
    SERVER_EXPORT sync_packet_type_t GetPacketType ( session_params_t* params )
294
295
296
    {
        switch ( params->fPacketID )
        {
297
298
299
300
301
302
303
304
305
306
            case 0:
                return SLAVE_AVAILABLE;
            case 1:
                return SLAVE_SETUP;
            case 2:
                return START_MASTER;
            case 3:
                return START_SLAVE;
            case 4:
                return KILL_MASTER;
307
308
309
310
        }
        return INVALID;
    }

311
    SERVER_EXPORT int SetPacketType ( session_params_t* params, sync_packet_type_t packet_type )
312
313
314
    {
        switch ( packet_type )
        {
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
            case INVALID:
                return -1;
            case SLAVE_AVAILABLE:
                params->fPacketID = 0;
                break;
            case SLAVE_SETUP:
                params->fPacketID = 1;
                break;
            case START_MASTER:
                params->fPacketID = 2;
                break;
            case START_SLAVE:
                params->fPacketID = 3;
                break;
            case KILL_MASTER:
                params->fPacketID = 4;
331
332
333
        }
        return 0;
    }
sletz's avatar
sletz committed
334
335
336

// Packet header **********************************************************************************

337
    SERVER_EXPORT void PacketHeaderHToN ( packet_header_t* src_header, packet_header_t* dst_header )
338
    {
339
340
341
342
343
344
345
346
347
        memcpy(dst_header, src_header, sizeof(packet_header_t));
        dst_header->fID = htonl ( src_header->fID );
        dst_header->fMidiDataSize = htonl ( src_header->fMidiDataSize );
        dst_header->fBitdepth = htonl ( src_header->fBitdepth );
        dst_header->fNMidiPckt = htonl ( src_header->fNMidiPckt );
        dst_header->fPacketSize = htonl ( src_header->fPacketSize );
        dst_header->fCycle = htonl ( src_header->fCycle );
        dst_header->fSubCycle = htonl ( src_header->fSubCycle );
        dst_header->fIsLastPckt = htonl ( src_header->fIsLastPckt );
348
349
    }

350
    SERVER_EXPORT void PacketHeaderNToH ( packet_header_t* src_header, packet_header_t* dst_header )
351
    {
352
353
354
355
356
357
358
359
360
        memcpy(dst_header, src_header, sizeof(packet_header_t));
        dst_header->fID = ntohl ( src_header->fID );
        dst_header->fMidiDataSize = ntohl ( src_header->fMidiDataSize );
        dst_header->fBitdepth = ntohl ( src_header->fBitdepth );
        dst_header->fNMidiPckt = ntohl ( src_header->fNMidiPckt );
        dst_header->fPacketSize = ntohl ( src_header->fPacketSize );
        dst_header->fCycle = ntohl ( src_header->fCycle );
        dst_header->fSubCycle = ntohl ( src_header->fSubCycle );
        dst_header->fIsLastPckt = ntohl ( src_header->fIsLastPckt );
361
362
    }

363
    SERVER_EXPORT void PacketHeaderDisplay ( packet_header_t* header )
364
    {
moret's avatar
moret committed
365
366
        char bitdepth[16];
        ( header->fBitdepth ) ? sprintf ( bitdepth, "%u", header->fBitdepth ) : sprintf ( bitdepth, "%s", "float" );
367
368
369
370
371
372
373
374
        jack_info ( "********************Header********************" );
        jack_info ( "Data type : %c", header->fDataType );
        jack_info ( "Data stream : %c", header->fDataStream );
        jack_info ( "ID : %u", header->fID );
        jack_info ( "Cycle : %u", header->fCycle );
        jack_info ( "SubCycle : %u", header->fSubCycle );
        jack_info ( "Midi packets : %u", header->fNMidiPckt );
        jack_info ( "Midi data size : %u", header->fMidiDataSize );
moret's avatar
moret committed
375
        jack_info ( "Last packet : '%s'", ( header->fIsLastPckt ) ? "yes" : "no" );
376
        jack_info ( "Bitdepth : %s", bitdepth );
377
378
        jack_info ( "**********************************************" );
    }
379
    
sletz's avatar
sletz committed
380
381
382
383
384
385
386
387
388
    SERVER_EXPORT void NetTransportDataDisplay ( net_transport_data_t* data )
    {
        jack_info ( "********************Network Transport********************" );
        jack_info ( "Transport new state : %u", data->fNewState );
        jack_info ( "Transport timebase master : %u", data->fTimebaseMaster );
        jack_info ( "Transport cycle state : %u", data->fState );
        jack_info ( "**********************************************" );
    }
   
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
    SERVER_EXPORT void MidiBufferHToN ( JackMidiBuffer* src_buffer, JackMidiBuffer* dst_buffer )
    {
        dst_buffer->magic = htonl(src_buffer->magic);
        dst_buffer->buffer_size = htonl(src_buffer->buffer_size);
        dst_buffer->nframes = htonl(src_buffer->nframes);
        dst_buffer->write_pos = htonl(src_buffer->write_pos);
        dst_buffer->event_count = htonl(src_buffer->event_count);
        dst_buffer->lost_events = htonl(src_buffer->lost_events);
        dst_buffer->mix_index = htonl(src_buffer->mix_index);
    }
    
    SERVER_EXPORT void MidiBufferNToH ( JackMidiBuffer* src_buffer, JackMidiBuffer* dst_buffer )
    {
        dst_buffer->magic = ntohl(src_buffer->magic);
        dst_buffer->buffer_size = ntohl(src_buffer->buffer_size);
        dst_buffer->nframes = ntohl(src_buffer->nframes);
        dst_buffer->write_pos = ntohl(src_buffer->write_pos);
        dst_buffer->event_count = ntohl(src_buffer->event_count);
        dst_buffer->lost_events = ntohl(src_buffer->lost_events);
        dst_buffer->mix_index = ntohl(src_buffer->mix_index);
    }
sletz's avatar
sletz committed
410
411
412
413
414
415
416
417
418
419
420
421
422
423
    
    SERVER_EXPORT void TransportDataHToN ( net_transport_data_t* src_params, net_transport_data_t* dst_params )
    {
        dst_params->fNewState = htonl(src_params->fNewState);
        dst_params->fTimebaseMaster = htonl(src_params->fTimebaseMaster);
        dst_params->fState = htonl(src_params->fState);
        dst_params->fPosition.unique_1 = htonll(src_params->fPosition.unique_1);
        dst_params->fPosition.usecs = htonl(src_params->fPosition.usecs);
        dst_params->fPosition.frame_rate = htonl(src_params->fPosition.frame_rate);
        dst_params->fPosition.frame = htonl(src_params->fPosition.frame);
        dst_params->fPosition.bar = htonl(src_params->fPosition.bar);
        dst_params->fPosition.beat = htonl(src_params->fPosition.beat);
        dst_params->fPosition.tick = htonl(src_params->fPosition.tick);
        dst_params->fPosition.bar_start_tick = htonll((uint64_t)src_params->fPosition.bar_start_tick);
sletz's avatar
sletz committed
424
425
        dst_params->fPosition.beats_per_bar = htonl((uint32_t)src_params->fPosition.beats_per_bar);
        dst_params->fPosition.beat_type = htonl((uint32_t)src_params->fPosition.beat_type);
sletz's avatar
sletz committed
426
427
428
429
430
        dst_params->fPosition.ticks_per_beat = htonll((uint64_t)src_params->fPosition.ticks_per_beat);
        dst_params->fPosition.beats_per_minute = htonll((uint64_t)src_params->fPosition.beats_per_minute);
        dst_params->fPosition.frame_time = htonll((uint64_t)src_params->fPosition.frame_time);
        dst_params->fPosition.next_time = htonll((uint64_t)src_params->fPosition.next_time);
        dst_params->fPosition.bbt_offset = htonl(src_params->fPosition.bbt_offset);
sletz's avatar
sletz committed
431
        dst_params->fPosition.audio_frames_per_video_frame = htonl((uint32_t)src_params->fPosition.audio_frames_per_video_frame);
sletz's avatar
sletz committed
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
        dst_params->fPosition.video_offset = htonl(src_params->fPosition.video_offset);
        dst_params->fPosition.unique_2 = htonll(src_params->fPosition.unique_2);
    }
    
    SERVER_EXPORT void TransportDataNToH ( net_transport_data_t* src_params, net_transport_data_t* dst_params )
    {
        dst_params->fNewState = ntohl(src_params->fNewState);
        dst_params->fTimebaseMaster =  ntohl(src_params->fTimebaseMaster);
        dst_params->fState = ntohl(src_params->fState);
        dst_params->fPosition.unique_1 = ntohll(src_params->fPosition.unique_1);
        dst_params->fPosition.usecs = ntohl(src_params->fPosition.usecs);
        dst_params->fPosition.frame_rate = ntohl(src_params->fPosition.frame_rate);
        dst_params->fPosition.frame = ntohl(src_params->fPosition.frame);
        dst_params->fPosition.bar = ntohl(src_params->fPosition.bar);
        dst_params->fPosition.beat = ntohl(src_params->fPosition.beat);
        dst_params->fPosition.tick = ntohl(src_params->fPosition.tick);
        dst_params->fPosition.bar_start_tick = ntohll((uint64_t)src_params->fPosition.bar_start_tick);
sletz's avatar
sletz committed
449
450
        dst_params->fPosition.beats_per_bar = ntohl((uint32_t)src_params->fPosition.beats_per_bar);
        dst_params->fPosition.beat_type = ntohl((uint32_t)src_params->fPosition.beat_type);
sletz's avatar
sletz committed
451
452
453
454
455
        dst_params->fPosition.ticks_per_beat = ntohll((uint64_t)src_params->fPosition.ticks_per_beat);
        dst_params->fPosition.beats_per_minute = ntohll((uint64_t)src_params->fPosition.beats_per_minute);
        dst_params->fPosition.frame_time = ntohll((uint64_t)src_params->fPosition.frame_time);
        dst_params->fPosition.next_time = ntohll((uint64_t)src_params->fPosition.next_time);
        dst_params->fPosition.bbt_offset = ntohl(src_params->fPosition.bbt_offset);
sletz's avatar
sletz committed
456
        dst_params->fPosition.audio_frames_per_video_frame = ntohl((uint32_t)src_params->fPosition.audio_frames_per_video_frame);
sletz's avatar
sletz committed
457
458
459
        dst_params->fPosition.video_offset = ntohl(src_params->fPosition.video_offset);
        dst_params->fPosition.unique_2 = ntohll(src_params->fPosition.unique_2);
    }
sletz's avatar
sletz committed
460
461

// Utility *******************************************************************************************************
462

463
    SERVER_EXPORT int SocketAPIInit()
464
465
466
467
468
    {
#ifdef WIN32
        WORD wVersionRequested = MAKEWORD ( 2, 2 );
        WSADATA wsaData;

469
        if ( WSAStartup ( wVersionRequested, &wsaData ) != 0 )
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
        {
            jack_error ( "WSAStartup error : %s", strerror ( NET_ERROR_CODE ) );
            return -1;
        }

        if ( LOBYTE ( wsaData.wVersion ) != 2 || HIBYTE ( wsaData.wVersion ) != 2 )
        {
            jack_error ( "Could not find a useable version of Winsock.dll\n" );
            WSACleanup();
            return -1;
        }
#endif
        return 0;
    }

485
    SERVER_EXPORT int SocketAPIEnd()
486
487
488
489
490
491
    {
#ifdef WIN32
        return WSACleanup();
#endif
        return 0;
    }
492

493
    SERVER_EXPORT const char* GetTransportState ( int transport_state )
494
495
496
    {
        switch ( transport_state )
        {
sletz's avatar
sletz committed
497
            case JackTransportRolling:
498
                return "rolling";
sletz's avatar
sletz committed
499
            case JackTransportStarting:
500
                return "starting";
sletz's avatar
sletz committed
501
            case JackTransportStopped:
502
                return "stopped";
sletz's avatar
sletz committed
503
            case JackTransportNetStarting:
504
505
506
507
                return "netstarting";
        }
        return NULL;
    }
sletz's avatar
sletz committed
508
}