Update of /cvsroot/playerstage/code/player/utils/playerprint
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25380

Modified Files:
        playerprint.cc 
Log Message:
added maximum rate timing for playerprint


Index: playerprint.cc
===================================================================
RCS file: /cvsroot/playerstage/code/player/utils/playerprint/playerprint.cc,v
retrieving revision 1.23
retrieving revision 1.24
diff -C2 -d -r1.23 -r1.24
*** playerprint.cc      9 Jun 2007 03:51:37 -0000       1.23
--- playerprint.cc      31 Jul 2007 05:09:16 -0000      1.24
***************
*** 80,83 ****
--- 80,84 ----
  //#include <libplayerc/playerc.h>      // for libplayerc client stuff
  #include <libplayerc++/playerc++.h>  // for libplayerc++ client stuff
+ #include <sys/time.h>
  
  #include <assert.h>
***************
*** 93,97 ****
  int32_t g_port        = PlayerCc::PLAYER_PORTNUM;
  int16_t g_index       = 0;
! int16_t g_rate        = 10;
  uint32_t g_transport  = PLAYERC_TRANSPORT_TCP;
  
--- 94,98 ----
  int32_t g_port        = PlayerCc::PLAYER_PORTNUM;
  int16_t g_index       = 0;
! double g_rate        = 0;
  uint32_t g_transport  = PLAYERC_TRANSPORT_TCP;
  
***************
*** 130,135 ****
            break;
        case 'r':
!           std::cerr << "Data rate not yet implemented!" << std::endl;
!           g_rate = atoi(optarg);
            break;
        case 't':
--- 131,135 ----
            break;
        case 'r':
!           g_rate = strtod(optarg,NULL);
            break;
        case 't':
***************
*** 271,277 ****
    assert(cp);
  
    for(;;)
    {
!     /* this blocks until new data comes; 10Hz by default */
      client.Read();
  
--- 271,286 ----
    assert(cp);
  
+   // set up timing loop and replace rules
+   struct timeval now, then;
+   if (g_rate > 0)
+   {
+     client.SetDataMode(PLAYER_DATAMODE_PULL);
+     client.SetReplaceRule(0);
+     gettimeofday(&then,NULL);
+   }
+ 
    for(;;)
    {
!     /* this blocks until new data comes; */
      client.Read();
  
***************
*** 364,367 ****
--- 373,391 ----
  
      std::cout << std::endl;
+ 
+     /* delay if we are reading faster than rate */
+     if (g_rate > 0)
+     {
+       gettimeofday(&now,NULL);
+       int delta = (now.tv_sec - then.tv_sec)*1000000 + (now.tv_usec - 
then.tv_usec);
+       int period = static_cast<int> (1e6/g_rate);
+       if (delta < period)
+       {
+         usleep(period-delta);
+         gettimeofday(&now,NULL);
+       }
+ 
+       then = now;
+     }
    }
  }


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to