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.

153 lines
4.7 KiB

  1. /*----------------------------------------------------------------------------
  2. * File: RTCPINIT.C
  3. * Product: RTP/RTCP implementation
  4. * Description: Provides RTCP initialization functions.
  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. PRTCP_CONTEXT pRTCPContext = NULL;
  17. /*---------------------------------------------------------------------------
  18. / External Variables
  19. /--------------------------------------------------------------------------*/
  20. extern PRTP_CONTEXT pRTPContext;
  21. /*----------------------------------------------------------------------------
  22. * Function : initRTCP
  23. * Description: RTCP initialization procedures. Creates the initial RTCP
  24. * session and allocates all initial memory resources.
  25. *
  26. * Input : None.
  27. *
  28. * Return: OK: RRCM_NoError
  29. * !0: Error code (see RRCM.H)
  30. ---------------------------------------------------------------------------*/
  31. DWORD initRTCP (void)
  32. {
  33. DWORD dwStatus = RRCM_NoError;
  34. IN_OUT_STR ("RTCP: Enter initRTCP()\n");
  35. // If RTCP has already been initialized, exit and report the error
  36. if (pRTCPContext != NULL)
  37. {
  38. RRCM_DBG_MSG ("RTCP: ERROR - Multiple RTCP Instances", 0,
  39. __FILE__, __LINE__, DBG_CRITICAL);
  40. IN_OUT_STR ("RTCP: Exit initRTCP()\n");
  41. return (RRCMError_RTCPReInit);
  42. }
  43. // Obtain RTCP context
  44. pRTCPContext = (PRTCP_CONTEXT)GlobalAlloc (GMEM_FIXED | GMEM_ZEROINIT,
  45. sizeof(RTCP_CONTEXT));
  46. if (pRTCPContext == NULL)
  47. {
  48. RRCM_DBG_MSG ("RTCP: ERROR - Resource allocation failed", 0,
  49. __FILE__, __LINE__, DBG_CRITICAL);
  50. IN_OUT_STR ("RTCP: Exit initRTCP()\n");
  51. return RRCMError_RTCPResources;
  52. }
  53. // initialize the context critical section
  54. InitializeCriticalSection(&pRTCPContext->critSect);
  55. // Initialize number of desired free cells
  56. pRTCPContext->dwInitNumFreeRRCMStat = pRTPContext->registry.NumFreeSSRC;
  57. // allocate heaps
  58. dwStatus = allocateRTCPContextHeaps (pRTCPContext);
  59. if (dwStatus == RRCM_NoError)
  60. {
  61. // allocate free list of SSRCs statistic entries
  62. dwStatus = allocateLinkedList (&pRTCPContext->RRCMFreeStat,
  63. pRTCPContext->hHeapRRCMStat,
  64. &pRTCPContext->dwInitNumFreeRRCMStat,
  65. sizeof(SSRC_ENTRY),
  66. &pRTCPContext->critSect);
  67. }
  68. // initialize the pseudo-random number generator, for later MD5 use
  69. RRCMsrand ((unsigned int)timeGetTime());
  70. // If initialation failed return all resourses allocated
  71. if (dwStatus != RRCM_NoError)
  72. deleteRTCP ();
  73. IN_OUT_STR ("RTCP: Exit initRTCP()\n");
  74. return (dwStatus);
  75. }
  76. /*----------------------------------------------------------------------------
  77. * Function : deleteRTCP
  78. * Description: RTCP delete procedures. All RTCP sessions have been deleted
  79. * at this point, so just delete what's needed.
  80. *
  81. * Input : None.
  82. *
  83. * Return: FALSE : OK.
  84. * TRUE : Error code. RTCP couldn't be initialized.
  85. ---------------------------------------------------------------------------*/
  86. DWORD deleteRTCP (void)
  87. {
  88. IN_OUT_STR ("RTCP: Enter deleteRTCP()\n");
  89. ASSERT (pRTCPContext);
  90. // protect everything from the top
  91. EnterCriticalSection (&pRTCPContext->critSect);
  92. // delete all heaps
  93. if (pRTCPContext->hHeapRRCMStat)
  94. {
  95. if (HeapDestroy (pRTCPContext->hHeapRRCMStat) == FALSE)
  96. {
  97. RRCM_DBG_MSG ("RTCP: ERROR - HeapDestroy", GetLastError(),
  98. __FILE__, __LINE__, DBG_ERROR);
  99. }
  100. }
  101. if (pRTCPContext->hHeapRTCPSes)
  102. {
  103. if (HeapDestroy (pRTCPContext->hHeapRTCPSes) == FALSE)
  104. {
  105. RRCM_DBG_MSG ("RTCP: ERROR - HeapDestroy", GetLastError(),
  106. __FILE__, __LINE__, DBG_ERROR);
  107. }
  108. }
  109. // protect everything from the top
  110. LeaveCriticalSection (&pRTCPContext->critSect);
  111. DeleteCriticalSection (&pRTCPContext->critSect);
  112. // Clean up our context resources
  113. GlobalFree (pRTCPContext);
  114. IN_OUT_STR ("RTCP: Exit deleteRTCP()\n");
  115. return (TRUE);
  116. }
  117. // [EOF]