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.

256 lines
5.2 KiB

  1. #include "precomp.h"
  2. #include "medialst.h"
  3. CMediaList::CMediaList() :
  4. m_pResolvedFormatIDs (NULL),
  5. m_pSendMediaGuids (NULL),
  6. m_pSendMediaList (NULL),
  7. m_pRecvMediaList (NULL),
  8. m_uNumSendMedia (0),
  9. m_uNumRecvMedia (0),
  10. m_uNumResolvedMedia (0)
  11. {
  12. }
  13. CMediaList::~CMediaList()
  14. {
  15. if(m_pResolvedFormatIDs)
  16. LocalFree(m_pResolvedFormatIDs);
  17. if(m_pSendMediaGuids)
  18. LocalFree(m_pSendMediaGuids);
  19. if(m_pSendMediaList)
  20. {
  21. PGUIDLIST pNext, pThis;
  22. pThis = m_pSendMediaList;
  23. while(pThis)
  24. {
  25. pNext = pThis->pnext;
  26. delete pThis;
  27. pThis = pNext;
  28. }
  29. }
  30. if(m_pRecvMediaList)
  31. {
  32. PGUIDLIST pNext, pThis;
  33. pThis = m_pRecvMediaList;
  34. while(pThis)
  35. {
  36. pNext = pThis->pnext;
  37. delete pThis;
  38. pThis = pNext;
  39. }
  40. }
  41. }
  42. VOID CMediaList::AddSendMedia(LPGUID pMediaTypeGuid)
  43. {
  44. PGUIDLIST pGLThis;
  45. pGLThis = new GUIDLIST;
  46. ASSERT(pGLThis);
  47. pGLThis->pnext = m_pSendMediaList;
  48. m_pSendMediaList = pGLThis;
  49. pGLThis->guid = *pMediaTypeGuid;
  50. m_uNumSendMedia++;
  51. }
  52. VOID CMediaList::RemoveSendMedia(LPGUID pMediaTypeGuid)
  53. {
  54. PGUIDLIST pGLThis, pGLToast = m_pSendMediaList;
  55. while(pGLToast)
  56. {
  57. if(pGLToast->guid == *pMediaTypeGuid)
  58. {
  59. // check head case
  60. if(pGLToast == m_pSendMediaList)
  61. {
  62. m_pSendMediaList = pGLToast->pnext;
  63. }
  64. else
  65. {
  66. pGLThis->pnext = pGLToast->pnext;
  67. }
  68. delete pGLToast;
  69. m_uNumSendMedia--;
  70. break;
  71. }
  72. pGLThis = pGLToast;
  73. pGLToast = pGLToast->pnext;
  74. }
  75. }
  76. VOID CMediaList::AddRecvMedia(LPGUID pMediaTypeGuid)
  77. {
  78. PGUIDLIST pGLThis;
  79. pGLThis = new GUIDLIST;
  80. ASSERT(pGLThis);
  81. pGLThis->pnext = m_pRecvMediaList;
  82. m_pRecvMediaList = pGLThis;
  83. pGLThis->guid = *pMediaTypeGuid;
  84. m_uNumRecvMedia++;
  85. }
  86. VOID CMediaList::RemoveRecvMedia(LPGUID pMediaTypeGuid)
  87. {
  88. PGUIDLIST pGLThis, pGLToast = m_pRecvMediaList;
  89. while(pGLToast)
  90. {
  91. if(pGLToast->guid == *pMediaTypeGuid)
  92. {
  93. // check head case
  94. if(pGLToast == m_pRecvMediaList)
  95. {
  96. m_pSendMediaList = pGLToast->pnext;
  97. }
  98. else
  99. {
  100. pGLThis->pnext = pGLToast->pnext;
  101. }
  102. delete pGLToast;
  103. m_uNumRecvMedia--;
  104. break;
  105. }
  106. pGLThis = pGLToast;
  107. pGLToast = pGLToast->pnext;
  108. }
  109. }
  110. VOID CMediaList::EnableMedia(LPGUID pMediaTypeGuid, BOOL fSendDirection, BOOL fEnabled)
  111. {
  112. // two bits of info: Send = 1, enable = 2
  113. // 0 - disable receive
  114. // 1 - disable send
  115. // 2 - enable receive
  116. // 3 - enable send
  117. int the_case;
  118. the_case = (fSendDirection)?1:0;
  119. the_case |= (fEnabled)? 2:0;
  120. switch(the_case)
  121. {
  122. case 0:
  123. RemoveRecvMedia(pMediaTypeGuid);
  124. break;
  125. case 1:
  126. RemoveSendMedia(pMediaTypeGuid);
  127. break;
  128. case 2:
  129. AddRecvMedia(pMediaTypeGuid);
  130. break;
  131. case 3:
  132. AddSendMedia(pMediaTypeGuid);
  133. break;
  134. }
  135. }
  136. BOOL CMediaList::IsInList(LPGUID pMediaTypeGuid, PGUIDLIST pList)
  137. {
  138. PGUIDLIST pGLThis = pList;
  139. while(pGLThis)
  140. {
  141. if(pGLThis->guid == *pMediaTypeGuid)
  142. {
  143. return TRUE;
  144. }
  145. //else
  146. pGLThis = pGLThis->pnext;
  147. }
  148. return FALSE;
  149. }
  150. HRESULT CMediaList::ResolveSendFormats(IH323Endpoint* pConnection)
  151. {
  152. UINT ui;
  153. PGUIDLIST pGLThis;
  154. ASSERT(NULL == m_pSendMediaGuids);
  155. ASSERT((0 != m_uNumSendMedia) && (NULL != m_pSendMediaList));
  156. m_pSendMediaGuids = (GUID *)LocalAlloc(LMEM_FIXED, m_uNumSendMedia*sizeof(GUID));
  157. ASSERT(NULL != m_pSendMediaGuids);
  158. for(ui=0, pGLThis = m_pSendMediaList; ui<m_uNumSendMedia; ui++)
  159. {
  160. ASSERT(NULL != pGLThis);
  161. *(m_pSendMediaGuids+ui) = pGLThis->guid;
  162. pGLThis = pGLThis->pnext;
  163. }
  164. // alloc space for resolved format IDs.
  165. ASSERT(NULL == m_pResolvedFormatIDs);
  166. m_pResolvedFormatIDs =
  167. (RES_PAIR *)LocalAlloc(LMEM_FIXED, m_uNumSendMedia*sizeof(RES_PAIR));
  168. ASSERT(NULL != m_pResolvedFormatIDs);
  169. // and set m_uNumResolvedMedia
  170. m_uNumResolvedMedia = m_uNumSendMedia;
  171. // resolve capabilities
  172. return pConnection->ResolveFormats(m_pSendMediaGuids, m_uNumResolvedMedia,
  173. m_pResolvedFormatIDs);
  174. }
  175. BOOL CMediaList::GetSendFormatLocalID(REFGUID guidMedia, MEDIA_FORMAT_ID* pId)
  176. {
  177. UINT ui;
  178. PGUIDLIST pGLThis;
  179. // find the index of the appropriate media type. Need to do this because
  180. // the order of media types in the list is unknown and there isn't a
  181. // table that relates the types with the resolved ID's. Need to
  182. // add such a table when decentralized media is supported.
  183. for(ui=0, pGLThis = m_pSendMediaList; ui<m_uNumSendMedia; ui++)
  184. {
  185. ASSERT(NULL != pGLThis);
  186. if (pGLThis->guid == guidMedia)
  187. {
  188. *pId = m_pResolvedFormatIDs[ui].idLocal;
  189. return TRUE;
  190. }
  191. pGLThis = pGLThis->pnext;
  192. }
  193. return FALSE;
  194. }
  195. VOID CMediaList::Clear()
  196. {
  197. if(m_pResolvedFormatIDs)
  198. {
  199. LocalFree(m_pResolvedFormatIDs);
  200. m_pResolvedFormatIDs = NULL;
  201. }
  202. if(m_pSendMediaGuids)
  203. {
  204. LocalFree(m_pSendMediaGuids);
  205. m_pSendMediaGuids = NULL;
  206. }
  207. if(m_pSendMediaList)
  208. {
  209. PGUIDLIST pNext, pThis;
  210. pThis = m_pSendMediaList;
  211. while(pThis)
  212. {
  213. pNext = pThis->pnext;
  214. delete pThis;
  215. pThis = pNext;
  216. }
  217. m_pSendMediaList = NULL;
  218. }
  219. if(m_pRecvMediaList)
  220. {
  221. PGUIDLIST pNext, pThis;
  222. pThis = m_pRecvMediaList;
  223. while(pThis)
  224. {
  225. pNext = pThis->pnext;
  226. delete pThis;
  227. pThis = pNext;
  228. }
  229. m_pRecvMediaList = NULL;
  230. }
  231. m_uNumSendMedia = 0;
  232. m_uNumRecvMedia = 0;
  233. }