Пример #1
0
/**
 * RTP send thread
 */
static void
rtp_send_thread(void *arg)
{
  int                sock;
  struct sockaddr_in local;
  struct sockaddr_in to;
  u32_t              rtp_stream_address;

  LWIP_UNUSED_ARG(arg);

  /* initialize RTP stream address */
  rtp_stream_address = RTP_STREAM_ADDRESS;

  /* 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(INADDR_ANY);
      local.sin_addr.s_addr = PP_HTONL(INADDR_ANY);

      /* bind to local address */
      if (bind(sock, (struct sockaddr *)&local, sizeof(local)) == 0) {
        /* prepare RTP stream address */
        memset(&to, 0, sizeof(to));
        to.sin_family      = AF_INET;
        to.sin_port        = PP_HTONS(RTP_STREAM_PORT);
        to.sin_addr.s_addr = rtp_stream_address;

        /* send RTP packets */
        memset(rtp_send_packet, 0, sizeof(rtp_send_packet));
        while (1) {
          rtp_send_packets( sock, &to);
          sys_msleep(RTP_SEND_DELAY);
        }
      }

      /* close the socket */
      closesocket(sock);
    }
  }
}
Пример #2
0
int main(int argc, const char * argv[])
{
    int                 sock, ch;
    struct sockaddr_in  local;
    struct sockaddr_in  to;

    /***added***/
    struct image_header ih;
    unsigned long data_size;


    ///



    u_int32             rtp_stream_address;
    unsigned long       data_length;
    char                *data = malloc(DATA_SIZE);

    if (argc != 3)
    {
        printf("\nUsage: %s <ip> <port>\n", argv[0]);
        exit(1);
    }



    data = readImage(argv[1], &data_size, &ih);
        rgb2ycbcr(data, ih.cols, ih.rows);



    //printf("Enter data to send: ");
    data_length = 0;
    while ((ch = getchar()) != EOF)
    { // reading data
        data[data_length] = (unsigned char) ch;
        data_length++;
    }
    // initialize RTP stream address */
    rtp_stream_address = inet_addr(argv[1]);

    // if we got a valid RTP stream address... */
    if (rtp_stream_address != 0) {
        sock = socket(AF_INET, SOCK_DGRAM, 0); // create new socket for sending datagrams
        if (sock >= 0) {
            // prepare local address
            memset(&local, 0, sizeof(local));
            local.sin_family      = AF_INET;
            local.sin_port        = htons(INADDR_ANY);
            local.sin_addr.s_addr = htonl(INADDR_ANY);
            // bind to local address
            if (bind(sock, (struct sockaddr *)&local, sizeof(local)) == 0) {
                // prepare RTP stream address
                memset(&to, 0, sizeof(to));
                to.sin_family      = AF_INET;
                to.sin_port        = htons(atoi(argv[2]));
                to.sin_addr.s_addr = rtp_stream_address;
                // send RTP packets
                rtp_send_packets( sock, &to, data, data_length, PAYLOAD_SIZE);
            }
            close(sock);
        }
    }
    free(data);
    return 0;
}