Exemplo n.º 1
0
void SocketReady() {
  kinet_packet packet;
  ssize_t data_read = sizeof(packet);
  struct sockaddr_in source;
  socklen_t src_size = sizeof(source);

  udp_socket.RecvFrom(reinterpret_cast<uint8_t*>(&packet),
                      &data_read,
                      source,
                      src_size);
  if (IsKiNet(&packet, data_read)) {
    uint16_t command = LittleEndianToHost(packet.header.type);
    switch (command) {
      case KINET_POLL:
        HandlePoll(source, packet, data_read);
        break;
      case KINET_DMX:
        HandleDmx(source, packet, data_read);
        break;
      default:
        OLA_WARN << "Unknown packet 0x" << std::hex << command;
    }
  } else {
    OLA_WARN << "Not a KiNet packet";
  }
}
Exemplo n.º 2
0
SInt64 ProxyTask::Run()
{
    const UInt32 kMaxRTCPPacketSize = 2048;
    char thePacketBuffer[kMaxRTCPPacketSize];
    QTSS_PacketStruct thePacketStruct;
    thePacketStruct.packetTransmitTime = QTSS_Milliseconds();
    thePacketStruct.packetData = thePacketBuffer;

    (void)this->GetEvents();    

    OSMutexLocker locker(sSocketPool->GetMutex());
    for (OSQueueIter iter(sSocketPool->GetSocketQueue()); !iter.IsDone(); iter.Next())
    {
        UInt32 theRemoteAddr = 0;
        UInt16 theRemotePort = 0;

        UDPSocketPair* thePair = (UDPSocketPair*)iter.GetCurrent()->GetEnclosingObject();
        Assert(thePair != NULL);
        
        for (UInt32 x = 0; x < 2; x++)
        {
            QTSS_WriteFlags theFlags = qtssWriteFlagsNoFlags;
            
            UDPSocket* theSocket = NULL;
            if (x == 0)
            {
                theFlags = qtssWriteFlagsIsRTP;
                theSocket = thePair->GetSocketA();
            }
            else
            {
                theFlags = qtssWriteFlagsIsRTCP;
                theSocket = thePair->GetSocketB();
            }
            
            Assert(theSocket->GetDemuxer() != NULL);
            OSMutexLocker locker(theSocket->GetDemuxer()->GetMutex());
            
            //get all the outstanding packets for this socket
            while (true)
            {
                UInt32 thePacketLen = 0;
                theSocket->RecvFrom(&theRemoteAddr, &theRemotePort, thePacketStruct.packetData, 
                                kMaxRTCPPacketSize, &thePacketLen);
                if (thePacketLen == 0)
                    break;//no more packets on this socket!
                    
                ProxyDemuxerTask* theDemuxerTask = (ProxyDemuxerTask*)theSocket->GetDemuxer()->GetTask(theRemoteAddr, 0);
                if (theDemuxerTask != NULL)
                {
                    QTSS_RTPStreamObject theStream = theDemuxerTask->GetStream();
                    (void)QTSS_Write(theStream, &thePacketStruct, thePacketLen, NULL, theFlags);
                }
            }
        }
    }
    return kProxyTaskPollIntervalMsec;
}
Exemplo n.º 3
0
/**
 * Called when data arrives on our UDP socket. We check that this data matches
 * the expected OSC packet
 */
void OSCNodeTest::UDPSocketReady() {
  uint8_t data[500];  // 500 bytes is more than enough
  ssize_t data_read = sizeof(data);
  // Read the received packet into 'data'.
  OLA_ASSERT_TRUE(m_udp_socket.RecvFrom(data, &data_read));
  // Verify it matches the expected packet
  ASSERT_DATA_EQUALS(__LINE__, OSC_BLOB_DATA,
                     sizeof(OSC_BLOB_DATA), data, data_read);
  // Stop the SelectServer
  m_ss.Terminate();
}
Exemplo n.º 4
0
SInt64 RTCPTask::Run()
{
    const UInt32 kMaxRTCPPacketSize = 2048;
    char thePacketBuffer[kMaxRTCPPacketSize];
    StrPtrLen thePacket(thePacketBuffer, 0);
    QTSServerInterface* theServer = QTSServerInterface::GetServer();
    
    //This task goes through all the UDPSockets in the RTPSocketPool, checking to see
    //if they have data. If they do, it demuxes the packets and sends the packet onto
    //the proper RTP session.
    EventFlags events = this->GetEvents(); // get and clear events
    
    if ( (events & Task::kReadEvent) || (events & Task::kIdleEvent) )
        {
                //Must be done atomically wrt the socket pool.
                
                OSMutexLocker locker(theServer->GetSocketPool()->GetMutex());
                for (OSQueueIter iter(theServer->GetSocketPool()->GetSocketQueue());
                                !iter.IsDone(); iter.Next())
                {
                        UInt32 theRemoteAddr = 0;
                        UInt16 theRemotePort = 0;
        
                        UDPSocketPair* thePair = (UDPSocketPair*)iter.GetCurrent()->GetEnclosingObject();
                        Assert(thePair != NULL);
                        
                        for (UInt32 x = 0; x < 2; x++)
                        {
                                UDPSocket* theSocket = NULL;
                                if (x == 0)
                                        theSocket = thePair->GetSocketA();
                                else
                                        theSocket = thePair->GetSocketB();
                                        
                                UDPDemuxer* theDemuxer = theSocket->GetDemuxer();
                        if (theDemuxer == NULL) 
                            continue;
                        else
                        {
                                        theDemuxer->GetMutex()->Lock();
                            while (true) //get all the outstanding packets for this socket
                                {
                                        thePacket.Len = 0;
                                        theSocket->RecvFrom(&theRemoteAddr, &theRemotePort, thePacket.Ptr,  
                                                                        kMaxRTCPPacketSize, &thePacket.Len);
                                        if (thePacket.Len == 0)
                                        {
                                                theSocket->RequestEvent(EV_RE);   
                                                break;//no more packets on this socket!
                                        }
                                        
                                        //if this socket has a demuxer, find the target RTPStream
                                        if (theDemuxer != NULL)
                                        {
                                                RTPStream* theStream = (RTPStream*)theDemuxer->GetTask(theRemoteAddr, theRemotePort);
                                                if (theStream != NULL)
                                                        theStream->ProcessIncomingRTCPPacket(&thePacket);
                                        }
                                }
                                        theDemuxer->GetMutex()->Unlock();
                        }
                }
        }
    }
     
    return 0; /* Fix for 4004432 */   
    /*
    SInt64 result = 0;
    if (theServer->GetNumRTPSessions() > 0)
        result =  theServer->GetPrefs()->GetRTCPPollIntervalInMsec();
    
   return result;
   */
}