15 static struct timeval then, now;
16 static long timeVals, thisSec, timeSum;
23 unsigned waitTime = (unsigned) (1000000.0f * (
float) bufSize / (float) CGestalt::sample_rate());
30 if (WSAStartup(MAKEWORD(1,1),&localWSA)!= 0)
31 perror(
"Couldn't do WSAStartup");
34 for (
int i = 0; i < 2; i++) {
46 perror(
"RFS: sem_open");
50 for (
unsigned i = 0; i < 2; i++) {
60 perror(
"Close mSocket");
71 perror(
"RemoteStream: sem_open");
74 logMsg(
"Open RemoteStream output socket");
78 perror(
"RemoteStream: socket");
81 if ((he = gethostbyname(serverName)) == NULL) {
82 perror(
"\tRemoteStream: gethostbyname");
88 mServerAddr.sin_addr = *((
struct in_addr *) he->h_addr);
89 logMsg(
"RemoteStream open output socket to %s:%d (= %d) (sz = %d)",
97 unsigned char * bString;
102 for (
int i = 0; i < 2; i++) {
116 perror(
"\tRemoteStream connect");
121 perror(
"\tRemoteStream intro packet write");
127 perror(
"RemoteStream connect");
131 command = packetHeader->
magic;
133 logMsg(
kLogError,
"RemoteStream: bad request magic number: %x\n", command);
136 logMsg(
"RemoteStream received server confirmation");
147 perror(
"RemoteStream: close _sock");
153 unsigned char * out, * buf;
154 unsigned frames = outputBuffer.mNumFrames;
159 if ((mCurrentFrame + frames) <= mBufferSize) {
161 toCopy = frames *
sizeof(
sample);
164 toCopy = (mBufferSize - mCurrentFrame) *
sizeof(
sample);
167 for (
unsigned i = 0; i < outputBuffer.mNumChannels; i++) {
168 out = (
unsigned char *) outputBuffer.buffer(i];
170 + (i * mBufferSize *
sizeof(
sample));
171 buf = ((
unsigned char *) (mIoBuffers[mCurrentBuffer])) + offset;
174 mCurrentFrame += frames;
175 if (mCurrentFrame >= mBufferSize) {
176 mCurrentBuffer = 1 - mCurrentBuffer;
178 sem_post(mServerSemaphore);
181 toCopy = (frames *
sizeof(
sample)) - toCopy;
182 for (
unsigned i = 0; i < outputBuffer.mNumChannels; i++) {
183 out = (
unsigned char *) outputBuffer.buffer(i];
185 buf = ((
unsigned char *) (mIoBuffers[mCurrentBuffer])) + offset;
188 mCurrentFrame = toCopy /
sizeof(
sample);
198 unsigned command, packet_size;
199 unsigned _numChannels = rfs->channels();
200 unsigned which, _bufferSize;
201 unsigned char * b_str;
202 CSL_RFS_MSG * pkt_header;
203 int sock = rfs->get_sock();
205 thisSec = timeVals = timeSum = 0L;
208 logMsg(
"\tRemoteStream starting read_loop");
210 sem_wait(rfs->get_semaphore());
212 which = rfs->get_buffer_switch();
213 _bufferSize = rfs->get_buffer_size();
214 b_str = (
unsigned char *) ((rfs->get_io_buffers())[1 - which]);
215 pkt_header = (CSL_RFS_MSG *) b_str;
217 pkt_header->frames = _bufferSize;
218 pkt_header->channels = _numChannels;
221 #endif // Send a request packet
222 if (write(sock, (
char *) b_str, RFS_PACKET_SIZE) != (
int) RFS_PACKET_SIZE) {
227 packet_size = RFS_RESPONSE_PACKET_SIZE;
228 bytes_xfer = read(sock, (
char *) b_str, packet_size);
229 if (bytes_xfer != (
int) packet_size) {
236 rfs->print_time_statistics(&now, &then, &thisSec, &timeSum, &timeVals);
237 #endif // Now process the response buffer
238 command = pkt_header->magic;
239 if ((command & 0xffffff00) != RFS_PACKET_MAGIC) {
240 logMsg(
kLogError,
"RemoteStream: bad response magic number: %x", command);
243 memcpy(& command, & b_str[packet_size - 4], 4);
244 if (command != RFS_PACKET_MAGIC) {
258 pthread_attr_init(&attr);
259 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
260 pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
262 ret = pthread_create(&tid, &attr, pfnThreadProc, pvParam);