Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

101 lignes
2.9KB

  1. // RFC3550 A.7 Computing the RTCP Transmission Interval (p74)
  2. #define _CRT_RAND_S
  3. #include <stdlib.h>
  4. #if defined(OS_WINDOWS)
  5. #include <limits.h>
  6. double drand48(void)
  7. {
  8. unsigned int v = 0;
  9. rand_s(&v);
  10. return (v * 1.0) / UINT_MAX;
  11. }
  12. #endif
  13. double rtcp_interval(int members,
  14. int senders,
  15. double rtcp_bw,
  16. int we_sent,
  17. double avg_rtcp_size,
  18. int initial)
  19. {
  20. /*
  21. * Minimum average time between RTCP packets from this site (in
  22. * seconds). This time prevents the reports from `clumping' when
  23. * sessions are small and the law of large numbers isn't helping
  24. * to smooth out the traffic. It also keeps the report interval
  25. * from becoming ridiculously small during transient outages like
  26. * a network partition.
  27. */
  28. double const RTCP_MIN_TIME = 5.0;
  29. /*
  30. * Fraction of the RTCP bandwidth to be shared among active
  31. * senders. (This fraction was chosen so that in a typical
  32. * session with one or two active senders, the computed report
  33. * time would be roughly equal to the minimum report time so that
  34. * we don't unnecessarily slow down receiver reports.) The
  35. * receiver fraction must be 1 - the sender fraction.
  36. */
  37. double const RTCP_SENDER_BW_FRACTION = 0.25;
  38. double const RTCP_RCVR_BW_FRACTION = (1-RTCP_SENDER_BW_FRACTION);
  39. /*
  40. * To compensate for "timer reconsideration" converging to a
  41. * value below the intended average.
  42. */
  43. double const COMPENSATION = 2.71828 - 1.5;
  44. double t; /* interval */
  45. double rtcp_min_time = RTCP_MIN_TIME;
  46. int n; /* no. of members for computation */
  47. /*
  48. * Very first call at application start-up uses half the min
  49. * delay for quicker notification while still allowing some time
  50. * before reporting for randomization and to learn about other
  51. * sources so the report interval will converge to the correct
  52. * interval more quickly.
  53. */
  54. if (initial) {
  55. rtcp_min_time /= 2;
  56. }
  57. /*
  58. * Dedicate a fraction of the RTCP bandwidth to senders unless
  59. * the number of senders is large enough that their share is
  60. * more than that fraction.
  61. */
  62. n = members;
  63. if (senders <= members * RTCP_SENDER_BW_FRACTION) {
  64. if (we_sent) {
  65. rtcp_bw *= RTCP_SENDER_BW_FRACTION;
  66. n = senders;
  67. } else {
  68. rtcp_bw *= RTCP_RCVR_BW_FRACTION;
  69. n -= senders;
  70. }
  71. }
  72. /*
  73. * The effective number of sites times the average packet size is
  74. * the total number of octets sent when each site sends a report.
  75. * Dividing this by the effective bandwidth gives the time
  76. * interval over which those packets must be sent in order to
  77. * meet the bandwidth target, with a minimum enforced. In that
  78. * time interval we send one report so this time is also our
  79. * average time between reports.
  80. */
  81. t = avg_rtcp_size * n / rtcp_bw;
  82. if (t < rtcp_min_time) t = rtcp_min_time;
  83. /*
  84. * To avoid traffic bursts from unintended synchronization with
  85. * other sites, we then pick our actual next report interval as a
  86. * random number uniformly distributed between 0.5*t and 1.5*t.
  87. */
  88. t = t * (drand48() + 0.5);
  89. t = t / COMPENSATION;
  90. return t;
  91. }