Beispiel #1
0
void testSpeedTester()
{
	DurationSamples samples;
	samples.push_back(std::make_pair((unsigned long long) 15, nanoseconds(1975700)));		// 0
	samples.push_back(std::make_pair((unsigned long long) 17, nanoseconds(4976700)));		// 0
	samples.push_back(std::make_pair((unsigned long long) 18, nanoseconds(11981400)));		// 0
	samples.push_back(std::make_pair((unsigned long long) 19, nanoseconds(34999300)));		// 0
	samples.push_back(std::make_pair((unsigned long long) 20, nanoseconds(99043200)));		// 0
	samples.push_back(std::make_pair((unsigned long long) 21, nanoseconds(292173300)));		// 0
	samples.push_back(std::make_pair((unsigned long long) 22, nanoseconds(892574500)));		// 0
	samples.push_back(std::make_pair((unsigned long long) 23, nanoseconds(2643745200)));	// 2
	samples.push_back(std::make_pair((unsigned long long) 24, nanoseconds(7937287000)));	// 7
	samples.push_back(std::make_pair((unsigned long long) 25, nanoseconds(23825904400)));	// 23
	samples.push_back(std::make_pair((unsigned long long) 26, nanoseconds(71674877300)));	// 71

	Puzzle p(2);
	HardwareSpeedTester hpt(1000, seconds(30), nanoseconds(50));
	long double stdev;
	auto func = hpt.testPuzzleComplexity(p, stdev, samples);

	cout << endl << "ESTIMATE: " << endl;
	for (size_t i = 1; i < 50; ++i)
		cout << i << ": " << func(i) / 1000000000.0 << endl;
	cout << "STDEV:" << stdev << endl;
}
Beispiel #2
0
/* Set up an RTP Library connection.
 * Return the maximum file descriptor number used, or -1 on error.
 * remote should contain the address to connect to in
 * host/port[/ttl] format.  (If ttl is not specified, '1' is used.)
 * cid will contain the context ID of the RTP session on sucessful return.
 * sock will contain the file descriptors of the RTP and RTCP ports.
 *
 * BUG: on failure, we should tear down the partially-completed
 * connections. */
static int setup_connection(char *remote, context *cid, int sock[2])
{
  /* Error values that the RTP library returns. */
  rtperror err;
  /* The port of the remote address */
  u_int16 port;
  /* The time-to-live value to set if we're talking to a multicast
   * address. */
  unsigned char ttl = 1;
  /* The sockaddr that hpt returns to us.  Note that we don't actually
   * pass this value to the library; it's just a convenient structure. */
  /* The type the library uses to keep track of sockets. */
  socktype sockt;
  /* The highest file descriptor we've dealt with. */
  int nfds = 0;

  /* Some values for creating the CNAME (see below). */
  char *username;
  char hostname[MAXHOSTNAMELEN];
  char cname[MAXHOSTNAMELEN+32];
  struct timeval tp;
  person uid, conid;
#ifdef WIN32
  WORD wVersionRequested;
  WSADATA wsaData;
  int err2;
 
  wVersionRequested = MAKEWORD( 2, 0 );
 
  err2 = WSAStartup( wVersionRequested, &wsaData );
  if ( err2 != 0 ) {
	  /* Tell the user that we couldn't find a usable */
	  /* WinSock DLL.                                  */
	  return(-1);
  }
#endif
  /* Translate host/port[/ttl] structure into sockaddr_in and ttl value. */
  if (hpt(remote, &port, &ttl) < 0) {
    fprintf(stderr, "%s: bad address\n", remote);
    return -1;
  }

  /* Create the RTP session -- allocate data structures.
   * This doesn't open any sockets. */
  err = RTPCreate(cid);
  if (err != RTP_OK) {
    fprintf(stderr, "%s\n", RTPStrError(err));
    return -1;
  }

  /* Set the RTP Session's host address to send to. */
  err = RTPSessionAddSendAddr(*cid, remote, port, ttl);
  if (err != RTP_OK) {
    fprintf(stderr, "%s\n", RTPStrError(err));
    return -1;
  }

  /* Set the RTP Session's local receive address */
  /* We set this to the dest for the following reason:
     - It's necessary if the dest is a multicast group, so we join the group
     - It's okay if the dest is unicast, since setting a dest which isn't a
       local address is ignored. */
  err = RTPSessionSetReceiveAddr(*cid, remote, port);


  /* Set up our CNAME (canonical name): should be of the form user@host */
  username = getenv("USER");
  if (gethostname(hostname, MAXHOSTNAMELEN) < 0) {
    perror("gethostname");
    return -1;
  }
  if (username) { sprintf(cname, "%s@%s", username, hostname); }
  else { strcpy(cname, hostname); }

  /* Member 0 is the local member (us) */
  err = RTPMemberInfoSetSDES(*cid, 0, RTP_MI_CNAME, cname);
  if (err != RTP_OK) {
    fprintf(stderr, "%s\n", RTPStrError(err));
    return -1;
  }

  /* Set up our NAME (standard display name) */
  err = RTPMemberInfoSetSDES(*cid, 0, RTP_MI_NAME, "RTP Example Server");
  if (err != RTP_OK) {
    fprintf(stderr, "%s\n", RTPStrError(err));
    return -1;
  }

  /* Add a single contributor */

  gettimeofday(&tp, NULL);
  srand(tp.tv_usec);
  conid = rand();
  err = RTPSessionAddToContributorList(*cid, (int) conid);
  if (err) {
    fprintf(stderr, "%s %s\n", RTPStrError(err), RTPDebugStr());
    return -1;
  }
  err = RTPSessionGetUniqueIDForCSRC(*cid,conid,&uid);
  if (err) {
    fprintf(stderr, "%s %s\n", RTPStrError(err), RTPDebugStr());
    return -1;
  }
  sprintf(cname, "Contributor %d", (int) conid);
  err = RTPMemberInfoSetSDES(*cid, uid, RTP_MI_CNAME, cname);
  if (err) {
    fprintf(stderr, "%s %s\n", RTPStrError(err), RTPDebugStr());
    return -1;
  }
  err = RTPMemberInfoSetSDES(*cid, uid, RTP_MI_NAME, cname);
  if (err) {
    fprintf(stderr, "%s %s\n", RTPStrError(err), RTPDebugStr());
    return -1;
  }


  /* Open the connection.  We're now live on the network. */
  err = RTPOpenConnection(*cid);
  if (err != RTP_OK) {
    fprintf(stderr, "%s\n", RTPStrError(err));
    return -1;
  }

  /* Get the socket that RTP data is transmitted on, so we can select() on
   * it. */
  /* Note that the value passed to it is a socktype *, not an int *. */
  err = RTPSessionGetRTPSocket(*cid, &sockt);
  if (err != RTP_OK) {
    fprintf(stderr, "%s\n", RTPStrError(err));
    return -1;
  }
  sock[0] = sockt;
  nfds = 0;
#ifdef __unix
  if (nfds < sockt) nfds = sockt;
#endif

  /* Get the socket that RTCP control information is transmitted on, so we
     can select() on it. */
  err = RTPSessionGetRTCPSocket(*cid, &sockt);
  if (err != RTP_OK) {
    fprintf(stderr, "%s\n", RTPStrError(err));
    return -1;
  }
  sock[1] = sockt;
#ifdef __unix
  if (nfds < sockt) nfds = sockt;
#endif

  return nfds;
}
Beispiel #3
0
/* Set up an RTP Library connection.
 * Return the maximum file descriptor number used, or -1 on error.
 * remote should contain the address to connect to in
 * host/port[/ttl] format.  (If ttl is not specified, '1' is used.)
 * cid will contain the context ID of the RTP session on sucessful return.
 * sock will contain the file descriptors of the RTP and RTCP ports.
 *
 * BUG: on failure, we should tear down the partially-completed
 * connections. */
static int setup_connection(char *remote, context *cid, int sock[2])
{
  /* Error values that the RTP library returns. */
  rtperror err;
  /* The port of the remote address */
  u_int16 port;
  /* The time-to-live value to set if we're talking to a multicast
   * address. */
  unsigned char ttl = 1;
  /* The sockaddr that hpt returns to us.  Note that we don't actually
   * pass this value to the library; it's just a convenient structure. */
  /* The type the library uses to keep track of sockets. */
  socktype sockt;
  /* The highest file descriptor we've dealt with. */
  int nfds = 0;

  /* Some values for creating the CNAME (see below). */
  char *username;

#ifndef MAXHOSTNAMELEN
#define MAXHOSTNAMELEN 50
#endif

  char hostname[MAXHOSTNAMELEN];
  char cname[MAXHOSTNAMELEN+32];

  /* Translate host/port[/ttl] structure into sockaddr_in and ttl value. */
  if (hpt(remote, &port, &ttl) < 0) {
    fprintf(stderr, "%s: bad address\n", remote);
    return -1;
  }

  /* Create the RTP session -- allocate data structures.
   * This doesn't open any sockets. */
  err = RTPCreate(cid);
  if (err != RTP_OK) {
    fprintf(stderr, "%s\n", RTPStrError(err));
    return -1;
  }

  /* Tell the library to use our callbacks. */
  /* UpdateMember: */
  err = RTPSetUpdateMemberCallBack(*cid, &update_member_callback);
  if (err != RTP_OK) {
    fprintf(stderr, "%s\n", RTPStrError(err));
    return -1;
  }
  /* ChangedMemberInfo: */
  err = RTPSetChangedMemberInfoCallBack(*cid, &changed_memberinfo_callback);
  if (err != RTP_OK) {
    fprintf(stderr, "%s\n", RTPStrError(err));
    return -1;
  }
  /* RevertingID: */
  err = RTPSetRevertingIDCallBack(*cid, &reverting_id_callback);
  if (err != RTP_OK) {
    fprintf(stderr, "%s\n", RTPStrError(err));
    return -1;
  }
  /* ChangedMemberAddress: */
  err = RTPSetChangedMemberAddressCallBack(*cid, &changed_member_address_callback);
  if (err != RTP_OK) {
    fprintf(stderr, "%s\n", RTPStrError(err));
    return -1;
  }
  /* SendError: */
  err = RTPSetSendErrorCallBack(*cid, &send_error_callback);
  if (err != RTP_OK) {
    fprintf(stderr, "%s\n", RTPStrError(err));
    return -1;
  }

  /* Set the RTP Session's host address to send to. */
  err = RTPSessionAddSendAddr(*cid, remote, port, ttl);
  if (err != RTP_OK) {
    fprintf(stderr, "%s\n", RTPStrError(err));
    return -1;
  }

  /* Set the RTP Session's local receive address */
  /* We set this to the dest for the following reason:
     - It's necessary if the dest is a multicast group, so we join the group
     - It's okay if the dest is unicast, since setting a dest which isn't a
       local address is ignored. */
  err = RTPSessionSetReceiveAddr(*cid, remote, port);
  if (err != RTP_OK) {
    fprintf(stderr, "%s\n", RTPStrError(err));
    return -1;
  }

  /* Set up our CNAME (canonical name): should be of the form user@host */
  username = getenv("USER");
  if (gethostname(hostname, MAXHOSTNAMELEN) < 0) {
    perror("gethostname");
    return -1;
  }
  if (username) { sprintf(cname, "%s@%s", username, hostname); }
  else { strcpy(cname, hostname); }

  /* Member 0 is the local member (us) */
  err = RTPMemberInfoSetSDES(*cid, 0, RTP_MI_CNAME, cname);
  if (err != RTP_OK) {
    fprintf(stderr, "%s\n", RTPStrError(err));
    return -1;
  }

  /* Set up our NAME (standard display name) */
  err = RTPMemberInfoSetSDES(*cid, 0, RTP_MI_NAME, "RTP Example Listener");
  if (err != RTP_OK) {
    fprintf(stderr, "%s\n", RTPStrError(err));
    return -1;
  }

  /* Open the connection.  We're now live on the network. */
  err = RTPOpenConnection(*cid);
  if (err != RTP_OK) {
    fprintf(stderr, "%s\n", RTPStrError(err));
    return -1;
  }

  /* Get the socket that RTP data is transmitted on, so we can select() on
   * it. */
  /* Note that the value passed to it is a socktype *, not an int *. */
  err = RTPSessionGetRTPSocket(*cid, &sockt);
  if (err != RTP_OK) {
    fprintf(stderr, "%s\n", RTPStrError(err));
    return -1;
  }
  sock[0] = sockt;
  nfds = 0;
#ifdef __unix
  if (nfds < sockt) nfds = sockt;
#endif

  /* Get the socket that RTCP control information is transmitted on, so we
     can select() on it. */
  err = RTPSessionGetRTCPSocket(*cid, &sockt);
  if (err != RTP_OK) {
    fprintf(stderr, "%s\n", RTPStrError(err));
    return -1;
  }
  sock[1] = sockt;

#ifdef __unix
  if (nfds < sockt) nfds = sockt;
#endif

  return nfds;
}