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.

214 lines
4.0 KiB

  1. /****************************************************************************
  2. *
  3. * FILE: Audio.cpp
  4. *
  5. * CREATED: Mike VanBuskirk (MikeV) 3-02-98
  6. *
  7. * CONTENTS: Audio control object
  8. *
  9. ****************************************************************************/
  10. #include "precomp.h"
  11. #include "avdefs.h"
  12. #include "audio.h"
  13. #include "h323.h"
  14. #include <nacguids.h>
  15. #include "audio.h"
  16. CAudioControl::CAudioControl(BOOL fLocal)
  17. : m_fPaused(FALSE),
  18. m_fLocal(fLocal),
  19. m_fChannelOpen(FALSE),
  20. m_fOpenPending(FALSE),
  21. m_fReopenPending(FALSE),
  22. m_fClosePending(FALSE),
  23. m_pCommChannel(NULL),
  24. m_pConnection(NULL),
  25. m_pMediaStream(NULL),
  26. m_NewFormat(INVALID_MEDIA_FORMAT)
  27. {
  28. }
  29. CAudioControl::~CAudioControl()
  30. {
  31. if (NULL != m_pCommChannel)
  32. {
  33. m_pCommChannel->Release();
  34. }
  35. }
  36. BOOL CAudioControl::ChanInitialize(ICommChannel* pCommChannel)
  37. {
  38. ASSERT(m_pCommChannel == NULL);
  39. m_pCommChannel = pCommChannel;
  40. m_pCommChannel->AddRef();
  41. return TRUE;
  42. }
  43. VOID CAudioControl::Open(MEDIA_FORMAT_ID format_id)
  44. {
  45. if(!m_pCommChannel)
  46. {
  47. return;
  48. }
  49. m_pCommChannel->PauseNetworkStream(FALSE);
  50. m_pCommChannel->EnableOpen(TRUE);
  51. if (m_fLocal)
  52. {
  53. HRESULT hr;
  54. // if the channel is not open and a call is in progress, now is the time
  55. if(m_pConnection && m_pCommChannel)
  56. {
  57. // a call is in progress
  58. if(!IsChannelOpen()
  59. && !m_fOpenPending)
  60. {
  61. // so, the channel is not open
  62. if(format_id != INVALID_MEDIA_FORMAT)
  63. {
  64. // try to open a channel using specified format
  65. m_fOpenPending = TRUE; // do this first (callbacks!)
  66. hr = m_pCommChannel->Open(format_id, m_pConnection);
  67. if(FAILED(hr))
  68. m_fOpenPending = FALSE;
  69. }
  70. }
  71. else if (m_fClosePending)
  72. {
  73. m_NewFormat = format_id;
  74. if(format_id != INVALID_MEDIA_FORMAT)
  75. {
  76. m_fClosePending = FALSE;
  77. m_fReopenPending = TRUE;
  78. hr = m_pCommChannel->Close();
  79. }
  80. }
  81. }
  82. }
  83. }
  84. VOID CAudioControl::Close()
  85. {
  86. HRESULT hr;
  87. hr = m_pCommChannel->Close();
  88. // what to do about an error?
  89. }
  90. VOID CAudioControl::EnableXfer(BOOL fEnable)
  91. {
  92. m_fXfer = fEnable;
  93. if(m_pCommChannel)
  94. {
  95. BOOL bPause = (fEnable)? FALSE :TRUE;
  96. m_pCommChannel->PauseNetworkStream(bPause);
  97. m_pCommChannel->EnableOpen(fEnable);
  98. }
  99. }
  100. BOOL CAudioControl::IsXferEnabled()
  101. {
  102. return m_fXfer;
  103. }
  104. VOID CAudioControl::Pause(BOOL fPause)
  105. {
  106. m_fPaused = fPause;
  107. if (m_fPaused)
  108. {
  109. EnableXfer(FALSE);
  110. }
  111. else
  112. {
  113. EnableXfer(TRUE);
  114. }
  115. }
  116. BOOL CAudioControl::Initialize(IH323CallControl *pNac, IMediaChannel *,
  117. DWORD dwUser)
  118. {
  119. HRESULT hr;
  120. m_fChannelOpen = FALSE;
  121. m_fOpenPending = m_fReopenPending = FALSE;
  122. m_fPaused = TRUE;
  123. EnableXfer(FALSE); // need to store state locally, set it in OnChannelOpen
  124. return TRUE;
  125. }
  126. VOID CAudioControl::OnConnected(IH323Endpoint * lpConnection, ICommChannel *pIChannel)
  127. {
  128. m_pConnection = lpConnection;
  129. m_fOpenPending = m_fReopenPending = m_fClosePending = FALSE;
  130. ChanInitialize(pIChannel);
  131. }
  132. VOID CAudioControl::OnChannelOpened(ICommChannel *pIChannel)
  133. {
  134. m_fChannelOpen = TRUE;
  135. m_fOpenPending = m_fReopenPending = FALSE;
  136. if(!m_pMediaStream)
  137. {
  138. m_pMediaStream = m_pCommChannel->GetMediaChannel();
  139. ASSERT(m_pMediaStream);
  140. }
  141. if (m_fLocal || m_fXfer) // start streams always if sending, or if transfer is enabled
  142. {
  143. EnableXfer(TRUE);
  144. }
  145. else
  146. {
  147. EnableXfer(FALSE);
  148. }
  149. }
  150. VOID CAudioControl::OnChannelError()
  151. {
  152. m_fOpenPending = FALSE;
  153. }
  154. VOID CAudioControl::OnChannelClosed()
  155. {
  156. HRESULT hr;
  157. m_fChannelOpen = FALSE;
  158. if(m_fLocal && m_fReopenPending)
  159. {
  160. m_fReopenPending = FALSE;
  161. if(m_NewFormat != INVALID_MEDIA_FORMAT )
  162. {
  163. m_fOpenPending = TRUE;
  164. hr = m_pCommChannel->Open(m_NewFormat, m_pConnection);
  165. if(FAILED(hr))
  166. m_fOpenPending = FALSE;
  167. }
  168. }
  169. else
  170. {
  171. if(m_pCommChannel)
  172. {
  173. m_pCommChannel->Release();
  174. m_pCommChannel = NULL;
  175. }
  176. }
  177. }
  178. VOID CAudioControl::OnDisconnected()
  179. {
  180. m_pConnection = NULL;
  181. }