Source code of Windows XP (NT5)
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.

204 lines
5.7 KiB

  1. /*----------------------------------------------------------------------------
  2. * File: RTCPMEM.C
  3. * Product: RTP/RTCP implementation
  4. * Description: Provides memory operations 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 PRTP_CONTEXT pRTPContext;
  20. #ifdef _DEBUG
  21. extern char debug_string[];
  22. #endif
  23. /*----------------------------------------------------------------------------
  24. * Function : allocateRTCPContextHeaps
  25. * Description: Allocates RTCP context heaps
  26. *
  27. * Input : pRTCPcntxt: -> to the RTCP context information
  28. *
  29. * Return: OK: RRCM_NoError
  30. * !0: Error code (see RRCM.H)
  31. ---------------------------------------------------------------------------*/
  32. DWORD allocateRTCPContextHeaps (PRTCP_CONTEXT pRTCPcntxt)
  33. {
  34. IN_OUT_STR ("RTCP: Enter allocateRTCPContextHeaps()\n");
  35. pRTCPcntxt->hHeapRTCPSes = HeapCreate (
  36. 0,
  37. (pRTPContext->registry.NumSessions*sizeof(RTCP_SESSION)),
  38. 0);
  39. if (pRTCPcntxt->hHeapRTCPSes == NULL)
  40. {
  41. IN_OUT_STR ("RTCP: Exit allocateRTCPContextHeaps()\n");
  42. return (RRCMError_RTCPResources);
  43. }
  44. pRTCPcntxt->hHeapRRCMStat = HeapCreate (
  45. 0,
  46. pRTCPcntxt->dwInitNumFreeRRCMStat*sizeof(SSRC_ENTRY),
  47. 0);
  48. if (pRTCPcntxt->hHeapRRCMStat == NULL)
  49. {
  50. IN_OUT_STR ("RTCP: Exit allocateRTCPContextHeaps()\n");
  51. return (RRCMError_RTCPResources);
  52. }
  53. IN_OUT_STR ("RTCP: Exit allocateRTCPContextHeaps()\n");
  54. return (RRCM_NoError);
  55. }
  56. /*----------------------------------------------------------------------------
  57. * Function : allocateRTCPSessionHeaps
  58. * Description: Allocates RTCP session heaps
  59. *
  60. * Input : *pRTCPses: ->(->) to the RTCP session's information
  61. *
  62. * Return: OK: RRCM_NoError
  63. * !0: Erro code (see RRCM.H)
  64. ---------------------------------------------------------------------------*/
  65. DWORD allocateRTCPSessionHeaps (PRTCP_SESSION *pRTCPses)
  66. {
  67. DWORD heapSize;
  68. DWORD dwStatus = RRCM_NoError;
  69. IN_OUT_STR ("RTCP: Enter allocateRTCPSessionHeaps()\n");
  70. heapSize = NUM_FREE_RCV_BFR*pRTPContext->registry.RTCPrcvBfrSize;
  71. (*pRTCPses)->hHeapRcvBfr = HeapCreate (0,
  72. heapSize,
  73. 0);
  74. if ((*pRTCPses)->hHeapRcvBfr == NULL)
  75. dwStatus = RRCMError_RTCPResources;
  76. if (dwStatus == RRCM_NoError)
  77. {
  78. (*pRTCPses)->hHeapRcvBfrList = HeapCreate (0,
  79. RCV_BFR_LIST_HEAP_SIZE,
  80. 0);
  81. if ((*pRTCPses)->hHeapRcvBfrList == NULL)
  82. dwStatus = RRCMError_RTCPResources;
  83. }
  84. if (dwStatus != RRCM_NoError)
  85. {
  86. // destroy allocated heaps
  87. if ((*pRTCPses)->hHeapRcvBfr)
  88. {
  89. HeapDestroy ((*pRTCPses)->hHeapRcvBfr);
  90. (*pRTCPses)->hHeapRcvBfr = NULL;
  91. }
  92. if ((*pRTCPses)->hHeapRcvBfrList)
  93. {
  94. HeapDestroy ((*pRTCPses)->hHeapRcvBfrList);
  95. (*pRTCPses)->hHeapRcvBfrList = NULL;
  96. }
  97. }
  98. IN_OUT_STR ("RTCP: Exit allocateRTCPSessionHeaps()\n");
  99. return (dwStatus);
  100. }
  101. /*----------------------------------------------------------------------------
  102. * Function : allocateRTCPBfrList
  103. * Description: Allocates link list of buffers for RTCP (xmit/rcv/...).
  104. *
  105. * Input : ptr: -> to the link list to add buffer to
  106. * hHeapList: Handle to the heap list
  107. * hHeapBfr: Handle to the heap buffer
  108. * *numBfr: -> to the number of buffers to allocate
  109. * bfrSize: Individual buffer size
  110. *
  111. * Return: OK: RRCM_NoError
  112. * !0: Error code (see RRCM.H)
  113. ---------------------------------------------------------------------------*/
  114. DWORD allocateRTCPBfrList (PLINK_LIST ptr,
  115. HANDLE hHeapList,
  116. HANDLE hHeapBfr,
  117. DWORD *numBfr,
  118. DWORD bfrSize,
  119. CRITICAL_SECTION *pCritSect)
  120. {
  121. PRTCP_BFR_LIST bfrPtr;
  122. PLINK_LIST tmpPtr;
  123. #ifdef IN_OUT_CHK
  124. OutputDebugString ("RTCP: Enter allocateRTCPBfrList()\n");
  125. #endif
  126. ASSERT (ptr);
  127. ASSERT (hHeapList);
  128. ASSERT (hHeapBfr);
  129. // make sure at least one buffer is requested
  130. if (*numBfr == 0)
  131. return (RRCMError_RTCPInvalidRequest);
  132. // allocate link list on the data structure's heap
  133. if (allocateLinkedList (ptr, hHeapList, numBfr,
  134. sizeof(RTCP_BFR_LIST), pCritSect))
  135. return (RRCMError_RTCPResources);
  136. // allocate buffer pool resources starting from the tail
  137. tmpPtr = ptr->prev;
  138. while (tmpPtr != NULL)
  139. {
  140. // points to buffer structure
  141. bfrPtr = (PRTCP_BFR_LIST)tmpPtr;
  142. ASSERT (bfrPtr);
  143. // initialize the WSABUF structure on its own heap
  144. bfrPtr->bfr.buf = (char *)HeapAlloc (hHeapBfr,
  145. HEAP_ZERO_MEMORY,
  146. bfrSize);
  147. if (bfrPtr->bfr.buf == NULL)
  148. {
  149. RRCM_DBG_MSG ("RTCP: Error - Cannot Allocate Xmt/Rcv Bfr",
  150. 0, __FILE__, __LINE__, DBG_ERROR);
  151. // !!! TODO !!!
  152. // update head/tail pointers
  153. // delete remaining cells until end of list
  154. break;
  155. }
  156. // buffer length
  157. bfrPtr->bfr.len = bfrSize;
  158. // buffer attributes
  159. bfrPtr->dwBufferCount = 1;
  160. // new head pointer
  161. tmpPtr = bfrPtr->bfrList.next;
  162. }
  163. #ifdef IN_OUT_CHK
  164. OutputDebugString ("RTCP: Exit allocateRTCPBfrList()\n");
  165. #endif
  166. return (RRCM_NoError);
  167. }
  168. // [EOF]