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.

309 lines
7.8 KiB

  1. /*++
  2. Copyright (c) 1998-1999 Microsoft Corporation
  3. Module Name:
  4. waveaddr.cpp
  5. Abstract:
  6. This module contains implementation of CRCAMSP.
  7. Author:
  8. Zoltan Szilagyi (zoltans) September 7, 1998
  9. --*/
  10. #include "stdafx.h"
  11. ///////////////////////////////////////////////////////////////////////////////
  12. ///////////////////////////////////////////////////////////////////////////////
  13. //
  14. CRCAMSP::CRCAMSP()
  15. {
  16. LOG((MSP_TRACE, "CRCAMSP::CRCAMSP entered."));
  17. m_fUseMulaw = DecideEncodingType();
  18. LOG((MSP_TRACE, "CRCAMSP::CRCAMSP exited."));
  19. }
  20. ///////////////////////////////////////////////////////////////////////////////
  21. ///////////////////////////////////////////////////////////////////////////////
  22. //
  23. CRCAMSP::~CRCAMSP()
  24. {
  25. LOG((MSP_TRACE, "CRCAMSP::~CRCAMSP entered."));
  26. LOG((MSP_TRACE, "CRCAMSP::~CRCAMSP exited."));
  27. }
  28. ///////////////////////////////////////////////////////////////////////////////
  29. ///////////////////////////////////////////////////////////////////////////////
  30. //
  31. ULONG CRCAMSP::MSPAddressAddRef(void)
  32. {
  33. return MSPAddRefHelper(this);
  34. }
  35. ULONG CRCAMSP::MSPAddressRelease(void)
  36. {
  37. return MSPReleaseHelper(this);
  38. }
  39. ///////////////////////////////////////////////////////////////////////////////
  40. ///////////////////////////////////////////////////////////////////////////////
  41. //
  42. STDMETHODIMP CRCAMSP::CreateMSPCall(
  43. IN MSP_HANDLE htCall,
  44. IN DWORD dwReserved,
  45. IN DWORD dwMediaType,
  46. IN IUnknown * pOuterUnknown,
  47. OUT IUnknown ** ppMSPCall
  48. )
  49. {
  50. LOG((MSP_TRACE, "CRCAMSP::CreateMSPCall - enter"));
  51. CRCAMSPCall * pCRCAMSPCall;
  52. HRESULT hr = CreateMSPCallHelper<CRCAMSPCall>(this,
  53. htCall,
  54. dwReserved,
  55. dwMediaType,
  56. pOuterUnknown,
  57. ppMSPCall,
  58. &pCRCAMSPCall);
  59. //
  60. // pCRCAMSPCall is not addrefed; no need to release.
  61. //
  62. if ( FAILED(hr) )
  63. {
  64. LOG((MSP_ERROR, "CRCAMSP::CreateMSPCall - template helper returned"
  65. "0x%08x", hr));
  66. return hr;
  67. }
  68. LOG((MSP_TRACE, "CRCAMSP::CreateMSPCall - exit S_OK"));
  69. return S_OK;
  70. }
  71. ///////////////////////////////////////////////////////////////////////////////
  72. ///////////////////////////////////////////////////////////////////////////////
  73. //
  74. STDMETHODIMP CRCAMSP::ShutdownMSPCall (
  75. IN IUnknown * pMSPCall
  76. )
  77. {
  78. LOG((MSP_TRACE, "CRCAMSP::ShutdownMSPCall - enter"));
  79. CRCAMSPCall * pCRCAMSPCall;
  80. HRESULT hr = ShutdownMSPCallHelper<CRCAMSPCall>(pMSPCall,
  81. &pCRCAMSPCall);
  82. //
  83. // pCRCAMSPCall is not addrefed; no need to release.
  84. //
  85. if ( FAILED(hr) )
  86. {
  87. LOG((MSP_ERROR, "CRCAMSP::ShutdownMSPCall - template helper returned"
  88. "0x%08x", hr));
  89. return hr;
  90. }
  91. LOG((MSP_TRACE, "CRCAMSP::ShutdownMSPCall - exit S_OK"));
  92. return S_OK;
  93. }
  94. ///////////////////////////////////////////////////////////////////////////////
  95. ///////////////////////////////////////////////////////////////////////////////
  96. //
  97. // CreateTerminal: overriden to set specific format on creation of MST.
  98. //
  99. STDMETHODIMP CRCAMSP::CreateTerminal (
  100. IN BSTR pTerminalClass,
  101. IN long lMediaType,
  102. IN TERMINAL_DIRECTION Direction,
  103. OUT ITTerminal ** ppTerminal
  104. )
  105. {
  106. LOG((MSP_TRACE, "CRCAMSP::CreateTerminal - enter"));
  107. //
  108. // Call the base class method to create the terminal.
  109. //
  110. HRESULT hr = CMSPAddress::CreateTerminal ( pTerminalClass,
  111. lMediaType,
  112. Direction,
  113. ppTerminal );
  114. if ( FAILED(hr) )
  115. {
  116. LOG((MSP_ERROR, "CRCAMSP::CreateTerminal - "
  117. "base class method failed - exit 0x%08x", hr));
  118. return hr;
  119. }
  120. //
  121. // Get the IID for the terminal class from the BSTR representation that
  122. // was passed in.
  123. //
  124. IID iidTerminalClass;
  125. hr = CLSIDFromString(pTerminalClass, &iidTerminalClass);
  126. if ( FAILED(hr) )
  127. {
  128. LOG((MSP_ERROR, "CRCAMSP::CreateTerminal - "
  129. "cannot convert CLSID string - returning E_INVALIDARG"));
  130. (*ppTerminal)->Release();
  131. *ppTerminal = NULL;
  132. return E_INVALIDARG;
  133. }
  134. //
  135. // If this is not an audio MST, then do nothing.
  136. //
  137. if ( ( iidTerminalClass != CLSID_MediaStreamTerminal ) ||
  138. ( lMediaType != TAPIMEDIATYPE_AUDIO ) )
  139. {
  140. LOG((MSP_TRACE, "CRCAMSP::CreateTerminal - "
  141. "this is not an MST - exit S_OK"));
  142. return S_OK;
  143. }
  144. //
  145. // This is an audio MST. Set the audio format on the MST.
  146. //
  147. LOG((MSP_TRACE, "CRCAMSP::CreateTerminal - this is an audio MST"));
  148. hr = ::SetAudioFormat(*ppTerminal,
  149. BITS_PER_SAMPLE_AT_TERMINAL,
  150. SAMPLE_RATE_AT_TERMINAL);
  151. if ( FAILED(hr) )
  152. {
  153. LOG((MSP_ERROR, "CRCAMSP::CreateTerminal - "
  154. "failed to set audio format on audio MST - exit 0x%08x", hr));
  155. (*ppTerminal)->Release();
  156. *ppTerminal = NULL;
  157. return hr;
  158. }
  159. LOG((MSP_TRACE, "CRCAMSP::CreateTerminal - "
  160. "successfully set audio format on audio MST - exit S_OK"));
  161. return S_OK;
  162. }
  163. ///////////////////////////////////////////////////////////////////////////////
  164. ///////////////////////////////////////////////////////////////////////////////
  165. //
  166. // Mandatory CMSPAddress override. This indicates the media types that
  167. // we support.
  168. //
  169. DWORD CRCAMSP::GetCallMediaTypes(void)
  170. {
  171. return (DWORD) TAPIMEDIATYPE_AUDIO;
  172. }
  173. ///////////////////////////////////////////////////////////////////////////////
  174. ///////////////////////////////////////////////////////////////////////////////
  175. //
  176. // DecideEncodingType
  177. //
  178. // Private helper function. We use this to determine whether to use Mulaw on
  179. // the wire, based on the location info in the tapi dialing rules.
  180. //
  181. // Return values: TRUE == Mulaw, FALSE = Alaw
  182. //
  183. BOOL CRCAMSP::DecideEncodingType(void)
  184. {
  185. LOG((MSP_TRACE, "CRCAMSP::DecideEncodingType - enter"));
  186. //
  187. // Find out where we are.
  188. //
  189. char szCountryCode[8];
  190. char szCityCode[8];
  191. long lResult;
  192. lResult = tapiGetLocationInfoA(
  193. szCountryCode,
  194. szCityCode
  195. );
  196. //
  197. // If the user has no location set up, or if there is some other
  198. // error, we assume Mulaw. Otherwise, we use Mulaw for country code
  199. // 1 (USA, Canada, Caribbean) and Alaw for everywhere else.
  200. //
  201. if ( lResult != NOERROR )
  202. {
  203. LOG((MSP_WARN, "CRCAMSP::DecideEncodingType - "
  204. "tapiGetLocationInfoA returned %d - assuming Mulaw", lResult));
  205. return TRUE;
  206. }
  207. else if ( ! strcmp( "1", szCountryCode) )
  208. {
  209. LOG((MSP_TRACE, "CRCAMSP::DecideEncodingType - "
  210. "country code %s == 1 - using Mulaw", szCountryCode));
  211. return TRUE;
  212. }
  213. else
  214. {
  215. LOG((MSP_TRACE, "CRCAMSP::DecideEncodingType - "
  216. "country code %s != 1 - using Alaw", szCountryCode));
  217. return FALSE;
  218. }
  219. }
  220. ///////////////////////////////////////////////////////////////////////////////
  221. ///////////////////////////////////////////////////////////////////////////////
  222. //
  223. // UseMulaw
  224. //
  225. // Private helper function. We use this to determine whether to use Mulaw on
  226. // the wire, based on the info saved in the address constructor from
  227. // DecideEncodingType.
  228. //
  229. // Return values: TRUE == Mulaw, FALSE = Alaw
  230. //
  231. BOOL CRCAMSP::UseMulaw( void )
  232. {
  233. return m_fUseMulaw;
  234. }
  235. // eof