lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-users] Problem receiving Multicast packet


From: seba . segura
Subject: [lwip-users] Problem receiving Multicast packet
Date: Mon, 1 Jul 2013 17:10:44 +0200 (CEST)

Hello Everybody

I have some trouble to receive RTP packet with Lwip 1.4.0 using FreeRtos.

I send audio streaming data with VLC and I want to read them with my board.

This is my recv thread I commented where is the issue :


static void
rtp_recv_thread(void *arg)
{
  int                sock;
  struct sockaddr_in local;
  struct sockaddr_in from;
  int                fromlen;
  struct ip_mreq     ipmreq;
  struct rtp_hdr*    rtphdr;
  u32_t              rtp_stream_address;
  int                timeout;
  int                result;
  int                recvrtppackets  = 0;
  int                lostrtppackets  = 0;
  u16_t              lastrtpseq = 0;

  LWIP_UNUSED_ARG(arg);

  /* initialize RTP stream address */
  rtp_stream_address = RTP_STREAM_ADDRESS;
 sys_msleep(15000);
  /* if we got a valid RTP stream address... */
  if (rtp_stream_address != 0) {
    /* create new socket */
    sock = socket(AF_INET, SOCK_DGRAM, 0);
    if (sock >= 0) {
      /* prepare local address */
      memset(&local, 0, sizeof(local));
      local.sin_family      = AF_INET;
      local.sin_port        = PP_HTONS(RTP_STREAM_PORT);
      local.sin_addr.s_addr = PP_HTONL(INADDR_ANY);

      /* bind to local address */
      if (bind(sock, (struct sockaddr *)&local, sizeof(local)) == 0) {
        /* set recv timeout */
        timeout = RTP_RECV_TIMEOUT;
        setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout, 
sizeof(timeout));

        /* prepare multicast "ip_mreq" struct */
        ipmreq.imr_multiaddr.s_addr = rtp_stream_address;
        ipmreq.imr_interface.s_addr = PP_HTONL(INADDR_ANY);

        /* join multicast group */
        if (setsockopt(sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, &ipmreq, 
sizeof(ipmreq)) == 0) {
          /* receive RTP packets */
          while(1) {
            fromlen = sizeof(from);
            result  = recvfrom(sock, rtp_recv_packet, sizeof(rtp_recv_packet), 
0,
              (struct sockaddr *)&from, (socklen_t *)&fromlen);

            // THE PROBLEM IS HERE result is ALWAYS = -1

            if (result >= sizeof(struct rtp_hdr)) {
              rtphdr = (struct rtp_hdr *)rtp_recv_packet;
              recvrtppackets++;
              if ((lastrtpseq == 0) || ((lastrtpseq + 1) == 
ntohs(rtphdr->seqNum))) {
                RTP_RECV_PROCESSING((rtp_recv_packet + 
sizeof(rtp_hdr)),(result-sizeof(rtp_hdr)));
              } else {
                lostrtppackets++;
              }
              lastrtpseq = ntohs(rtphdr->seqNum);
              if ((recvrtppackets % RTP_RECV_STATS) == 0) {
                LWIP_DEBUGF(RTP_DEBUG, ("rtp_recv_thread: recv %6i packet(s) / 
lost %4i packet(s) (%.4f%%)...\n", recvrtppackets, lostrtppackets, 
(lostrtppackets*100.0)/recvrtppackets));
              }
            } else {
              LWIP_DEBUGF(RTP_DEBUG, ("rtp_recv_thread: recv timeout...\n"));
            }
          }

          /* leave multicast group */
          setsockopt(sock, IPPROTO_IP, IP_DROP_MEMBERSHIP, &ipmreq, 
sizeof(ipmreq));
        }
      }

      /* close the socket */
      closesocket(sock);
    }
  }
}


My problem is that the var result  = recvfrom(sock, rtp_recv_packet, 
sizeof(rtp_recv_packet), 0,(struct sockaddr *)&from, (socklen_t 
*)&fromlen);return always -1... I don't understand why, it seems that the main 
thread is waiting for a semaphore which never come...

Any idea ?

Best regards,

Sébastien



reply via email to

[Prev in Thread] Current Thread [Next in Thread]