Mercurial > hg > beaglert
diff core/ReceiveAudioThread.cpp @ 131:ff28e56e5b7e scope-refactoring
Updated Network files to match Udpioplugin 18:fb5a61b10223
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Wed, 26 Aug 2015 02:02:10 +0100 |
parents | 2696a7f00053 |
children | e24c531220ee |
line wrap: on
line diff
--- a/core/ReceiveAudioThread.cpp Tue Aug 25 11:14:25 2015 +0100 +++ b/core/ReceiveAudioThread.cpp Wed Aug 26 02:02:10 2015 +0100 @@ -80,21 +80,19 @@ // printf("I am channel %d, but I received data for channel %d\n", channel, (int)buffer[writePointer]); return -5; } - //TODO: do something else with the data in the header (e.g.: check that timestamp is sequential) + static int timestamp=0; + if(buffer[writePointer+1]!=timestamp+1) + printf("missing a timestamp: %d\n",timestamp+1); + timestamp=buffer[writePointer+1]; // rt_printf("Received a message of length %d, it was on channel %d and timestamp %d\n", numBytes, (int)buffer[writePointer], (int)buffer[writePointer+1]); + popPayload(writePointer); //restore headerLength payload samples. This could be skipped if writePointer==0 - //even though we just wrote (payloadLength+headerLength) samples in the buffer, //we only increment by payloadLength. This way, next time a socket.read is performed, we will //backup the last headerLength samples that we just wrote and we will overwrite them with //the header from the new read. After parsing the header we will then restore the backed up samples. //This way we guarantee that, apart from the first headerLength samples, buffer is a circular buffer! -// printf("writepointer:%d\n", writePointer); writePointer+=payloadLength; - - if(writePointer>lastValidPointer){ - // lastValidPointer=writePointer+headerLength; - } wrapWritePointer(); return numBytes; } @@ -125,6 +123,7 @@ #ifdef USE_JUCE stopThread(1000); #else + stopThread(); while(threadRunning){ usleep(sleepTime*2); //wait for thread to stop std::cout<< "Waiting for receiveAudioTask to stop" << std::endl; @@ -247,6 +246,31 @@ // fd2=fopen("buffer.m","w"); //DEBUG // fprintf(fd2, "buf=["); //DEBUG threadRunning=true; + int maxCount=10; + int count=0; + // Clean the socket from anything that is currently in it. +#ifdef USE_JUCE + // this is borrowed from BeagleRT's UdpServer class. + int n; + do { + float waste; + if(socket.waitUntilReady(true, 0)==0) + break; + n=socket.read((void*)&waste, sizeof(float), false); + count++; + if(n<0){ + printf("error\n"); + break; + } + printf("n: %d\n",n); + } while (n>0 && (maxCount<=0 || count<maxCount)); +#else + for(unsigned int n=0; n<objAddrs.size(); n++){ + count=objAddrs[n]->socket.empty(maxCount); + } +#endif /* USE_JUCE */ + printf("socket emptied with %d reads\n", count); + while(!threadShouldExit()){ //TODO: check that the socket buffer is empty before starting #ifdef USE_JUCE readUdpToBuffer(); // read into the oldBuffer