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.

379 lines
9.0 KiB

  1. /*
  2. Copyright (c) 1998-1999 Microsoft Corporation
  3. Module Name:
  4. blbmedia.cpp
  5. Abstract:
  6. Implementation of CSdpblbApp and DLL registration.
  7. Author:
  8. */
  9. #include "stdafx.h"
  10. #include "blbgen.h"
  11. #include "sdpblb.h"
  12. #include "blbmedia.h"
  13. #include "blbreg.h"
  14. #include "addrgen.h"
  15. // audio string with a trailing blank for the audio media blob
  16. const TCHAR AUDIO_TSTR[] = _T("audio ");
  17. const USHORT AUDIO_TSTRLEN = (sizeof(AUDIO_TSTR)/sizeof(TCHAR) -1);
  18. // static variables
  19. const IID &MEDIA::ELEM_IF_ID = IID_ITMedia;
  20. // uses GetElement() to access the sdp media instance - calls ENUM_ELEMENT::GetElement()
  21. CSdpConferenceBlob *
  22. MEDIA::GetConfBlob(
  23. )
  24. {
  25. return m_ConfBlob;
  26. }
  27. HRESULT
  28. MEDIA::Init(
  29. IN CSdpConferenceBlob &ConfBlob
  30. )
  31. {
  32. // check if the registry entries were read without errors
  33. if ( !SDP_REG_READER::IsValid() )
  34. {
  35. return HRESULT_FROM_ERROR_CODE(SDP_REG_READER::GetErrorCode());
  36. }
  37. // allocate an audio port
  38. // using random values for lease period since its not being interpreted
  39. MSA_PORT_GROUP PortGroup;
  40. PortGroup.PortType = AUDIO_PORT;
  41. WORD FirstAudioPort;
  42. // allocate video port
  43. if ( !MSAAllocatePorts(&PortGroup, FALSE, 1, &FirstAudioPort) )
  44. {
  45. return HRESULT_FROM_ERROR_CODE(GetLastError());
  46. }
  47. // create a defalt sdp media instance
  48. SDP_MEDIA *SdpMedia;
  49. try
  50. {
  51. SdpMedia = new SDP_MEDIA();
  52. }
  53. catch(...)
  54. {
  55. SdpMedia = NULL;
  56. }
  57. BAIL_IF_NULL(SdpMedia, E_OUTOFMEMORY);
  58. // allocate memory for the audio media blob
  59. TCHAR *SdpMediaBlob;
  60. try
  61. {
  62. SdpMediaBlob = new TCHAR[
  63. SDP_REG_READER::GetMediaTemplateLen() +
  64. AUDIO_TSTRLEN +
  65. MAX_PORT_STRLEN
  66. ];
  67. }
  68. catch(...)
  69. {
  70. SdpMediaBlob = NULL;
  71. }
  72. if ( NULL == SdpMediaBlob )
  73. {
  74. delete SdpMedia;
  75. return E_OUTOFMEMORY;
  76. }
  77. // copy AUDIO_TSTR into the sdp media blob
  78. lstrcpy(SdpMediaBlob, AUDIO_TSTR);
  79. TCHAR *BlobPtr = SdpMediaBlob;
  80. // use the media template to create a media blob
  81. // parse the media blob to initialize the sdp media instance
  82. // if not successful, delete the sdp media instance and return error
  83. if ( (0 == _stprintf(SdpMediaBlob+AUDIO_TSTRLEN, SDP_REG_READER::GetMediaTemplate(), FirstAudioPort)) ||
  84. (!SdpMedia->ParseLine(BlobPtr)) )
  85. {
  86. delete SdpMedia;
  87. delete SdpMediaBlob;
  88. return HRESULT_FROM_ERROR_CODE(GetLastError());
  89. }
  90. delete SdpMediaBlob;
  91. m_ConfBlob = &ConfBlob;
  92. ENUM_ELEMENT<SDP_MEDIA>::SuccessInit(*SdpMedia, TRUE);
  93. ITConnectionImpl::SuccessInit(*SdpMedia);
  94. ITAttributeListImpl::SuccessInit(SdpMedia->GetAttributeList());
  95. return S_OK;
  96. }
  97. STDMETHODIMP MEDIA::get_MediaName(BSTR * pVal)
  98. {
  99. CLock Lock(g_DllLock);
  100. ASSERT(GetElement().IsValid());
  101. return GetElement().GetName().GetBstrCopy(pVal);
  102. }
  103. STDMETHODIMP MEDIA::put_MediaName(BSTR newVal)
  104. {
  105. CLock Lock(g_DllLock);
  106. ASSERT(GetElement().IsValid());
  107. return GetElement().GetName().SetBstr(newVal);
  108. }
  109. STDMETHODIMP MEDIA::get_StartPort(LONG * pVal)
  110. {
  111. BAIL_IF_NULL(pVal, E_INVALIDARG);
  112. CLock Lock(g_DllLock);
  113. ASSERT(GetElement().IsValid());
  114. // vb doesn't take a USHORT (16bit unsigned value)
  115. *pVal = (LONG)GetElement().GetStartPort().GetValue();
  116. return S_OK;
  117. }
  118. STDMETHODIMP MEDIA::get_NumPorts(LONG * pVal)
  119. {
  120. BAIL_IF_NULL(pVal, E_INVALIDARG);
  121. CLock Lock(g_DllLock);
  122. ASSERT(GetElement().IsValid());
  123. // vb doesn't take a USHORT (16bit unsigned value)
  124. *pVal = (LONG)(GetElement().GetNumPorts().IsValid() ? GetElement().GetNumPorts().GetValue() : 1);
  125. return S_OK;
  126. }
  127. STDMETHODIMP MEDIA::SetPortInfo(LONG StartPort, LONG NumPorts)
  128. {
  129. CLock Lock(g_DllLock);
  130. ASSERT(GetElement().IsValid());
  131. // validate the start port and num ports value - they should be USHORT values [0..2**16-1]
  132. if ( !((0 <= StartPort) && (USHORT(-1) > StartPort) && (0 <= NumPorts) && (USHORT(-1) > NumPorts)) )
  133. {
  134. return E_INVALIDARG;
  135. }
  136. return GetElement().SetPortInfo((USHORT)StartPort, (USHORT)NumPorts);
  137. }
  138. STDMETHODIMP MEDIA::get_TransportProtocol(BSTR * pVal)
  139. {
  140. CLock Lock(g_DllLock);
  141. ASSERT(GetElement().IsValid());
  142. return GetElement().GetProtocol().GetBstrCopy(pVal);
  143. }
  144. STDMETHODIMP MEDIA::put_TransportProtocol(BSTR newVal)
  145. {
  146. CLock Lock(g_DllLock);
  147. ASSERT(GetElement().IsValid());
  148. return GetElement().GetProtocol().SetBstr(newVal);
  149. }
  150. STDMETHODIMP MEDIA::get_FormatCodes(VARIANT /*SAFEARRAY (BSTR)*/ * pVal)
  151. {
  152. CLock Lock(g_DllLock);
  153. ASSERT(GetElement().IsValid());
  154. return GetElement().GetFormatCodeList().GetSafeArray(pVal);
  155. }
  156. STDMETHODIMP MEDIA::put_FormatCodes(VARIANT /*SAFEARRAY (BSTR)*/ newVal)
  157. {
  158. CLock Lock(g_DllLock);
  159. ASSERT(GetElement().IsValid());
  160. return GetElement().GetFormatCodeList().SetSafeArray(newVal);
  161. }
  162. STDMETHODIMP MEDIA::get_MediaTitle(BSTR * pVal)
  163. {
  164. CLock Lock(g_DllLock);
  165. ASSERT(GetElement().IsValid());
  166. return GetElement().GetTitle().GetBstrCopy(pVal);
  167. }
  168. STDMETHODIMP MEDIA::put_MediaTitle(BSTR newVal)
  169. {
  170. CLock Lock(g_DllLock);
  171. ASSERT(GetElement().IsValid());
  172. return GetElement().GetTitle().SetBstr(newVal);
  173. }
  174. #define INTERFACEMASK (0xff0000)
  175. typedef IDispatchImpl<ITMediaVtbl<MEDIA>, &IID_ITMedia, &LIBID_SDPBLBLib> CMedia;
  176. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  177. //
  178. // MEDIA::GetIDsOfNames
  179. //
  180. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  181. STDMETHODIMP MEDIA::GetIDsOfNames(REFIID riid,
  182. LPOLESTR* rgszNames,
  183. UINT cNames,
  184. LCID lcid,
  185. DISPID* rgdispid
  186. )
  187. {
  188. HRESULT hr = DISP_E_UNKNOWNNAME;
  189. //
  190. // See if the requsted method belongs to the default interface
  191. //
  192. hr = CMedia::GetIDsOfNames(riid, rgszNames, cNames, lcid, rgdispid);
  193. if (SUCCEEDED(hr))
  194. {
  195. rgdispid[0] |= IDISPMEDIA;
  196. return hr;
  197. }
  198. //
  199. // If not, then try the ITConnection base class
  200. //
  201. hr = ITConnectionImpl::GetIDsOfNames(riid, rgszNames, cNames, lcid, rgdispid);
  202. if (SUCCEEDED(hr))
  203. {
  204. rgdispid[0] |= IDISPCONNECTION;
  205. return hr;
  206. }
  207. //
  208. // If not, then try the ITAttributeList base class
  209. //
  210. hr = ITAttributeListImpl::GetIDsOfNames(riid, rgszNames, cNames, lcid, rgdispid);
  211. if (SUCCEEDED(hr))
  212. {
  213. rgdispid[0] |= IDISPATTRLIST;
  214. return hr;
  215. }
  216. return hr;
  217. }
  218. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  219. //
  220. // MEDIA::Invoke
  221. //
  222. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  223. STDMETHODIMP MEDIA::Invoke(DISPID dispidMember,
  224. REFIID riid,
  225. LCID lcid,
  226. WORD wFlags,
  227. DISPPARAMS* pdispparams,
  228. VARIANT* pvarResult,
  229. EXCEPINFO* pexcepinfo,
  230. UINT* puArgErr
  231. )
  232. {
  233. HRESULT hr = DISP_E_MEMBERNOTFOUND;
  234. DWORD dwInterface = (dispidMember & INTERFACEMASK);
  235. //
  236. // Call invoke for the required interface
  237. //
  238. switch (dwInterface)
  239. {
  240. case IDISPMEDIA:
  241. {
  242. hr = CMedia::Invoke(dispidMember,
  243. riid,
  244. lcid,
  245. wFlags,
  246. pdispparams,
  247. pvarResult,
  248. pexcepinfo,
  249. puArgErr
  250. );
  251. break;
  252. }
  253. case IDISPCONNECTION:
  254. {
  255. hr = ITConnectionImpl::Invoke(dispidMember,
  256. riid,
  257. lcid,
  258. wFlags,
  259. pdispparams,
  260. pvarResult,
  261. pexcepinfo,
  262. puArgErr
  263. );
  264. break;
  265. }
  266. case IDISPATTRLIST:
  267. {
  268. hr = ITAttributeListImpl::Invoke(dispidMember,
  269. riid,
  270. lcid,
  271. wFlags,
  272. pdispparams,
  273. pvarResult,
  274. pexcepinfo,
  275. puArgErr
  276. );
  277. break;
  278. }
  279. } // end switch (dwInterface)
  280. return hr;
  281. }