VBAN incoming packet process example: (general algorithm base)
Code: Select all
PROCESS_UDP_PACKET(void * packet, long packetsize, SOCKADDR_IN from);
{
   LPT_VBAN_HEADER lpHeader = (LPT_VBAN_HEADER)packet;
   //Detect a VBAN packet in a single 32 bit instruction
   if (lpHeader->vban == 'NABV')
   {
      //check the IP-From and Stream Name (different stream can come in)
      fOk=CheckIfWeProcessThisStream(lpHeader, from);
      if (fOk)
      {
         //get datasize (ater header) and protocol/codec index
         Datasize = packetsize - sizeof(T_VBAN_HEADER);
         protocol = lpHeader->format_SR & VBAN_PROTOCOL_MASK;
         codec = lpHeader->format_bit & VBAN_CODEC_MASK;
         //protocol selector
         if (protocol == VBAN_PROTOCOL_AUDIO)
         {
            //codec selector
            switch (codec)
            {
            case VBAN_CODEC_PCM:
               //get audio stream information
               SR =VBAN_SRList[lpHeader->format_SR & VBAN_SR_MASK];
               nbChannel =((long)lpHeader->format_nbc)+1;
               fReserved =lpHeader->format_bit & 0x08;
               BitResolution = lpHeader->format_bit & VBAN_DATATYPE_MASK;
               sampleSize = VBAN_SampleSize[BitResolution];
               nbSample =((long)lpHeader->format_nbs)+1;
               nbByte = sampleSize * nbChannel * nbSample;
               //Push Data in Audio Stack (to be sent to audio device output for
               //example) NOTE that waiting cycles are not allowed in this thread.
               if (fReserved == 0)
               {
                  if (nbByte == datasize)
                  {
                     MyStream_PushSignal(pStreamObj, lpHeader+1, nbByte,
                     SR, nbChannel, BitResolution);
                  }
                  else nError_corrupt++
               }
            }
         }
      }
   }
}
get full source code example of a VBAN-Receptor app for linux on github: https://github.com/quiniouben/vban_receptor

