Play stream audio from DatagramSocket


#1

I'm having difficulty playing audio stream (in my case it's wav file from another pc) from udp socket aka DatagramSocket. What I can't understand is which class should I use to transfer my data to AudioIODevice.

I think I should create my own class inherited from AudioSource (in which I'll do all the work required to wrap char* data) and transfer it to AudioSourcePlayer, but I'm not shure if this is right way to go. Also I don't know how exactly do this work in my own class.

Here's the code reading data to char* buffer from udp socket in run() method of class inherited from Thread. In current stage it does nothing with buffer after writing to it data from socket.

while (! threadShouldExit())
{            
     DatagramSocket d_sock(0);
     if (!d_sock.bindToPort(port))
     {
         printf("failed to bind to port %d\n", port);
         signalThreadShouldExit();
     }
     else
     {
         switch (d_sock.waitUntilReady(true, 20000))
         {
         case 1:  
         {
             while (1)
             {
                  Logger::outputDebugString("socket ready");
                  int bytes_readed = d_sock.read((void*)buffer, packet_size, true);
             }
             break;
         }
         case 0:  
         {
             Logger::outputDebugString("socket timed out");  
             signalThreadShouldExit();
             break;
         }
         case -1:  
         {
             Logger::outputDebugString("socket error");  
             signalThreadShouldExit();
             break;
         }
         }
     }   
}

And sorry for my english (it's not my native language), I hope I've written undertandable post)