Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

248 lines
8.8 KiB

  1. /*----------------------------------------------------------------------------
  2. * File: RTCPTIME.C
  3. * Product: RTP/RTCP implementation
  4. * Description: Provides timers related functions for RTCP.
  5. *
  6. * INTEL Corporation Proprietary Information
  7. * This listing is supplied under the terms of a license agreement with
  8. * Intel Corporation and may not be copied nor disclosed except in
  9. * accordance with the terms of that agreement.
  10. * Copyright (c) 1995 Intel Corporation.
  11. *--------------------------------------------------------------------------*/
  12. #include "rrcm.h"
  13. /*---------------------------------------------------------------------------
  14. / Global Variables
  15. /--------------------------------------------------------------------------*/
  16. /*---------------------------------------------------------------------------
  17. / External Variables
  18. /--------------------------------------------------------------------------*/
  19. extern PRTCP_CONTEXT pRTCPContext;
  20. #ifdef _DEBUG
  21. extern char debug_string[];
  22. #endif
  23. /*----------------------------------------------------------------------------
  24. * Function : RTCPxmitInterval
  25. * Description: Calculate the RTCP transmission interval
  26. *
  27. * Input : members: Estimated number of session members including
  28. * ourselves. On the initial call, should be 1.
  29. *
  30. * senders: Number of active senders since last report, known from
  31. * construction of receiver reports for this packet.
  32. * Includes ourselves if we sent.
  33. *
  34. * rtcpBw: The target RTCP bandwidth, ie, the total Bw that will
  35. * be used by RTCP by all members of this session, in
  36. * bytes per seconds. Should be 5% of the session Bw.
  37. *
  38. * weSent: True if we've sent data during the last two RTCP
  39. * intervals. If TRUE, the compound RTCP packet just
  40. * sent contained an SR packet.
  41. *
  42. * packetSize: Size of the RTCP packet just sent, in bytes, including
  43. * network encapsulation, eg 28 bytes for UDP over IP.
  44. *
  45. * *avgRtcpSize: Estimator to RTCP packet size, initialized and
  46. * updated by this function for the packet just sent.
  47. *
  48. * initial: Initial transmission flag.
  49. *
  50. * Return: Interval time before the next transmission in msec.
  51. ---------------------------------------------------------------------------*/
  52. DWORD RTCPxmitInterval (DWORD members,
  53. DWORD senders,
  54. DWORD rtcpBw,
  55. DWORD weSent,
  56. DWORD packetSize,
  57. int *avgRtcpSize,
  58. DWORD initial)
  59. {
  60. #ifdef ENABLE_FLOATING_POINT
  61. // // Minimum time between RTCP packets from this site in seconds. This time
  62. // // prevents the reports from clumping when sessions are small and the law
  63. // // of large numbers isn't helping to smooth out the traffic. It also keeps
  64. // // the report intervals from becoming ridiculously small during transient
  65. // // outages like a network partition.
  66. // double const RTCP_MinTime = 5.;
  67. //
  68. // // Fraction of the RTCP bandwidth to be shared among active senders. This
  69. // // fraction was chosen so that in a typical session with one or two active
  70. // // senders, the computed report time would be roughly equal to the minimum
  71. // // report time so that we don't unnecessarily slow down receiver reports.
  72. // // The receiver fraction must be 1 - the sender fraction.
  73. // double const RTCP_SenderBwFraction = 0.25;
  74. // double const RTCP_RcvrBwFraction = (1 - RTCP_SenderBwFraction);
  75. //
  76. // // Gain (smoothing constant) for the low-pass filter that estimates the
  77. // // average RTCP packet size.
  78. // double const RTCP_sizeGain = RTCP_SIZE_GAIN;
  79. //
  80. // // Interval
  81. // double t = 0;
  82. // double rtcp_min_time = RTCP_MinTime;
  83. //
  84. // // Number of member for computation
  85. // unsigned int n;
  86. // int tmpSize;
  87. //
  88. // // Random number
  89. // double randNum;
  90. //
  91. // // Very first call at application start-up uses half the min delay for
  92. // // quicker notification while still allowing some time before reporting
  93. // // for randomization and to learn about other sources so the report
  94. // // interval will converge to the correct interval more quickly. The
  95. // // average RTCP size is initialized to 128 octects which is conservative.
  96. // // It assumes everyone else is generating SRs instead of RRs:
  97. // // 20 IP + 8 UDP + 52 SR + 48 SDES CNAME
  98. // if (initial)
  99. // {
  100. // rtcp_min_time /= 2;
  101. // *avgRtcpSize = 128;
  102. // }
  103. //
  104. // // If there were active senders, give them at least a minimum share of the
  105. // // RTCP bandwidth. Otherwise all participants share the RTCP Bw equally.
  106. // n = members;
  107. // if (senders > 0 && (senders < (members * RTCP_SenderBwFraction)))
  108. // {
  109. // if (weSent)
  110. // {
  111. // rtcpBw *= RTCP_SenderBwFraction;
  112. // n = senders;
  113. // }
  114. // else
  115. // {
  116. // rtcpBw *= RTCP_RcvrBwFraction;
  117. // n -= senders;
  118. // }
  119. // }
  120. //
  121. // // Update the average size estimate by the size of the report packet we
  122. // // just sent out.
  123. // tmpSize = packetSize - *avgRtcpSize;
  124. // tmpSize = (int)(tmpSize * RTCP_sizeGain);
  125. // *avgRtcpSize += tmpSize;
  126. //
  127. // // The effective number of sites times the average packet size is the
  128. // // total number of octets sent when each site sends a report. Dividing
  129. // // this by the effective bandwidth gives the time interval over which
  130. // // those packets must be sent in order to meet the bandwidth target,
  131. // // with a minimum enforced. In that time interval we send one report so
  132. // // this time is also our average time between reports.
  133. // t = (*avgRtcpSize) * n / rtcpBw;
  134. //
  135. // if (t < rtcp_min_time)
  136. // t = rtcp_min_time;
  137. //
  138. // // To avoid traffic burst from unintended synchronization with other sites
  139. // // we then pick our actual next report interval as a random number
  140. // // uniformely distributed between 0.5*t and 1.5*t.
  141. //
  142. // // Get a random number between 0 and 1
  143. // // rand() gives a number between 0-32767.
  144. // randNum = RRCMrand() % 32767;
  145. // randNum /= 32767.0;
  146. //
  147. // // return timeout in msec
  148. // return (t * (randNum + 0.5) * 1000);
  149. #else
  150. // Minimum time between RTCP packets from this site in Msec. This time
  151. // prevents the reports from clumping when sessions are small and the law
  152. // of large numbers isn't helping to smooth out the traffic. It also keeps
  153. // the report intervals from becoming ridiculously small during transient
  154. // outages like a network partition.
  155. int RTCP_MinTime = 5000;
  156. // Interval
  157. int t = 0;
  158. int rtcp_min_time = RTCP_MinTime;
  159. // Number of member for computation
  160. unsigned int n;
  161. int tmpSize;
  162. // Random number
  163. int randNum;
  164. // Very first call at application start-up uses half the min delay for
  165. // quicker notification while still allowing some time before reporting
  166. // for randomization and to learn about other sources so the report
  167. // interval will converge to the correct interval more quickly. The
  168. // average RTCP size is initialized to 128 octects which is conservative.
  169. // It assumes everyone else is generating SRs instead of RRs:
  170. // 20 IP + 8 UDP + 52 SR + 48 SDES CNAME
  171. if (initial)
  172. {
  173. rtcp_min_time /= 2;
  174. *avgRtcpSize = 128;
  175. }
  176. // If there were active senders, give them at least a minimum share of the
  177. // RTCP bandwidth. Otherwise all participants share the RTCP Bw equally.
  178. n = members;
  179. // Only a quart of the bandwidth (=> /4). Check above with floatting point
  180. if (senders > 0 && (senders < (members / 4)))
  181. {
  182. if (weSent)
  183. {
  184. // Only a quart of the bandwidth for the sender
  185. rtcpBw /= 4;
  186. n = senders;
  187. }
  188. else
  189. {
  190. // 3/4 of the bandwidth for the receiver
  191. rtcpBw = (3*rtcpBw)/4;
  192. n -= senders;
  193. }
  194. }
  195. // Update the average size estimate by the size of the report packet we
  196. // just sent out.
  197. tmpSize = packetSize - *avgRtcpSize;
  198. tmpSize = (tmpSize+8) / 16;
  199. *avgRtcpSize += tmpSize;
  200. // The effective number of sites times the average packet size is the
  201. // total number of octets sent when each site sends a report. Dividing
  202. // this by the effective bandwidth gives the time interval over which
  203. // those packets must be sent in order to meet the bandwidth target,
  204. // with a minimum enforced. In that time interval we send one report so
  205. // this time is also our average time between reports.
  206. if (rtcpBw)
  207. t = (*avgRtcpSize) * n / rtcpBw;
  208. if (t < rtcp_min_time)
  209. t = rtcp_min_time;
  210. // To avoid traffic burst from unintended synchronization with other sites
  211. // we then pick our actual next report interval as a random number
  212. // uniformely distributed between 0.5*t and 1.5*t.
  213. // Get a random number between 0 and 1
  214. // In order to avoid floating point operation, get a number between
  215. // 0 and 1000, i.e. converted in Msec already. Add 500 Msec instead of
  216. // 0.5 to the random number
  217. randNum = RRCMrand() % 1000;
  218. return ((t * (randNum + 500))/1000);
  219. #endif
  220. }
  221. // [EOF]