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.

202 lines
6.7 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: dsoundcapturebufferobj.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. // dSoundCaptureBufferObj.cpp : Implementation of CDirectApp and DLL registration.
  11. // DHF_DS entire file
  12. #include "stdafx.h"
  13. #include "Direct.h"
  14. #include "dSound.h"
  15. #include "dms.h"
  16. #include "dSoundObj.h"
  17. #include "dSoundCaptureBufferObj.h"
  18. #include "dSoundCaptureObj.h"
  19. CONSTRUCTOR(_dxj_DirectSoundCaptureBuffer, {});
  20. DESTRUCTOR(_dxj_DirectSoundCaptureBuffer, {});
  21. GETSET_OBJECT(_dxj_DirectSoundCaptureBuffer);
  22. STDMETHODIMP C_dxj_DirectSoundCaptureBufferObject::getCaps(DSCBCAPS_CDESC *caps)
  23. {
  24. ((DSCBCAPS*)caps)->dwSize=sizeof(DSCBCAPS);
  25. return m__dxj_DirectSoundCaptureBuffer->GetCaps((DSCBCAPS*)caps);
  26. }
  27. STDMETHODIMP C_dxj_DirectSoundCaptureBufferObject::getCurrentPosition(DSCURSORS_CDESC *desc)
  28. {
  29. /////////////////////////////////////////////////////////////////////////////
  30. if(!desc)
  31. return E_POINTER;
  32. return (m__dxj_DirectSoundCaptureBuffer->GetCurrentPosition((DWORD*)&desc->lPlay, (DWORD*)&desc->lWrite) );
  33. }
  34. STDMETHODIMP C_dxj_DirectSoundCaptureBufferObject::getStatus(long *stat)
  35. {
  36. return m__dxj_DirectSoundCaptureBuffer->GetStatus((DWORD*)stat);
  37. }
  38. STDMETHODIMP C_dxj_DirectSoundCaptureBufferObject::start(long flags)
  39. {
  40. return m__dxj_DirectSoundCaptureBuffer->Start((DWORD)flags);
  41. }
  42. STDMETHODIMP C_dxj_DirectSoundCaptureBufferObject::stop()
  43. {
  44. return m__dxj_DirectSoundCaptureBuffer->Stop();
  45. }
  46. STDMETHODIMP C_dxj_DirectSoundCaptureBufferObject::getFormat(WAVEFORMATEX_CDESC *format)
  47. {
  48. DWORD cb=0;
  49. return m__dxj_DirectSoundCaptureBuffer->GetFormat((WAVEFORMATEX*)format,sizeof(WAVEFORMATEX_CDESC),&cb);
  50. }
  51. STDMETHODIMP C_dxj_DirectSoundCaptureBufferObject::initialize(I_dxj_DirectSoundCaptureBuffer *buffer,DSCBUFFERDESC_CDESC *desc)
  52. {
  53. ((DSCBUFFERDESC*)desc)->dwSize=sizeof(DSCBUFFERDESC);
  54. DO_GETOBJECT_NOTNULL(LPDIRECTSOUNDCAPTURE, lpref, buffer);
  55. return m__dxj_DirectSoundCaptureBuffer->Initialize(lpref,(DSCBUFFERDESC*)desc);
  56. }
  57. STDMETHODIMP C_dxj_DirectSoundCaptureBufferObject::setNotificationPositions (long nElements,SAFEARRAY **ppsa)
  58. {
  59. if (!ISSAFEARRAY1D(ppsa,(DWORD)nElements))
  60. return E_INVALIDARG;
  61. HRESULT hr;
  62. LPDIRECTSOUNDNOTIFY pDSN=NULL;
  63. if (nElements == 0)
  64. {
  65. // There is absolutely nothing to do if we want to set 0 notification positions
  66. return S_OK;
  67. }
  68. hr=m__dxj_DirectSoundCaptureBuffer->QueryInterface(IID_IDirectSoundNotify,(void**)&pDSN);
  69. if FAILED(hr) return hr;
  70. hr=pDSN->SetNotificationPositions((DWORD)nElements,(LPCDSBPOSITIONNOTIFY)((SAFEARRAY*)*ppsa)->pvData);
  71. pDSN->Release();
  72. return hr;
  73. }
  74. /////////////////////////////////////////////////////////////////////////////
  75. //Java has no direct access to system memory, so it allocates it's own buffer
  76. //which is passed into WriteBuffer(). Because the environment is now double
  77. //buffered there is no need to Lock Java memory. WriteBuffer() calls
  78. //both lock and Unlock internally to write the result after the fact.
  79. /////////////////////////////////////////////////////////////////////////////
  80. STDMETHODIMP C_dxj_DirectSoundCaptureBufferObject::writeBuffer(long start, long totsz,
  81. void *buf, long flags)
  82. {
  83. #pragma message ("SoundBuffer writeBuffer ")
  84. byte *buffer=(byte*)buf; //(byte*)((SAFEARRAY*)*ppsa)->pvData;
  85. if(!buffer)
  86. return E_POINTER;
  87. LPVOID p1, p2;
  88. DWORD size1=0, size2=0;
  89. HRESULT val = E_FAIL;
  90. __try {
  91. DPF1(1,"----- DXVB: DSoundCaptureBuffer (WriteBuffer) Lock buffer (Total size = %d )\n",totsz);
  92. if ((val = m__dxj_DirectSoundCaptureBuffer->Lock((DWORD)start, (DWORD)totsz, &p1, &size1, &p2, &size2,
  93. (DWORD)flags)) != DS_OK)
  94. return val;
  95. // Copy to buffer end, then do a wrapped portion if it exists, then unlock
  96. DPF1(1,"----- DXVB: DSoundCaptureBuffer (WriteBuffer) about to copy to buffer (size1 = %d )\n",size1);
  97. if (p1)
  98. {
  99. DPF1(1,"----- DXVB: DSoundCaptureBuffer (WriteBuffer) about to copy to buffer (size1 = %d )\n",size1);
  100. memcpy (p1, buffer, size1);
  101. }
  102. if (p2) //There was wrapping
  103. {
  104. DPF1(1,"----- DXVB: DSoundCaptureBuffer (WriteBuffer) about to copy to buffer (size2 = %d )\n",size2);
  105. memcpy(p2, &buffer[size1], size2);
  106. }
  107. //docdoc: because Lock and Unlock are tied together within WriteBuffer,
  108. // DSBufferDesc no longer needs to save Lock's system pointers.
  109. DPF(1,"----- DXVB: DSoundCaptureBuffer (WriteBuffer) Unlocking buffer.\n");
  110. val= m__dxj_DirectSoundCaptureBuffer->Unlock(p1, size1, p2, size2);
  111. }
  112. __except(EXCEPTION_EXECUTE_HANDLER)
  113. {
  114. DPF(1,"----- DXVB: (WriteBuffer) Exception.\n");
  115. return E_FAIL;
  116. }
  117. return val;
  118. }
  119. /////////////////////////////////////////////////////////////////////////////
  120. //Java has no direct access to system memory, so it allocates it's own buffer
  121. //which is passed into WriteBuffer(). Because the environment is now double
  122. //buffered there is no need to Lock Java memory. WriteBuffer() calls
  123. //both lock and Unlock internally to write the result after the fact.
  124. /////////////////////////////////////////////////////////////////////////////
  125. STDMETHODIMP C_dxj_DirectSoundCaptureBufferObject::readBuffer(long start, long totsz,
  126. void *buf, long flags)
  127. {
  128. //byte *buffer=(byte*)((SAFEARRAY*)*ppsa)->pvData;
  129. byte *buffer=(byte*)buf;
  130. if(!buffer)
  131. return E_POINTER;
  132. LPVOID p1 = NULL, p2 = NULL;
  133. DWORD size1=0, size2=0;
  134. HRESULT val = E_FAIL;
  135. __try {
  136. DPF1(1,"----- DXVB: DSoundCaptureBuffer (ReadBuffer) Lock buffer (Total size = %d )\n",totsz);
  137. if ((val = m__dxj_DirectSoundCaptureBuffer->Lock((DWORD)start, (DWORD)totsz, &p1, &size1, &p2, &size2,
  138. (DWORD)flags)) != DS_OK)
  139. return val;
  140. // Copy to buffer end, then do a wrapped portion if it exists, then unlock
  141. if (p1)
  142. {
  143. DPF1(1,"----- DXVB: DSoundCaptureBuffer (ReadBuffer) about to copy to buffer (size1 = %d )\n",size1);
  144. memcpy (buffer,p1, size1);
  145. }
  146. if (p2) //There was wrapping
  147. {
  148. DPF1(1,"----- DXVB: DSoundCaptureBuffer (ReadBuffer) about to copy to buffer (size2 = %d )\n",size2);
  149. memcpy(&buffer[size1],p2, size2);
  150. }
  151. //docdoc: because Lock and Unlock are tied together within WriteBuffer,
  152. // DSBufferDesc no longer needs to save Lock's system pointers.
  153. DPF(1,"----- DXVB: DSoundCaptureBuffer (ReadBuffer) Unlocking buffer.\n");
  154. val= m__dxj_DirectSoundCaptureBuffer->Unlock(p1, size1, p2, size2);
  155. }
  156. __except(EXCEPTION_EXECUTE_HANDLER)
  157. {
  158. DPF(1,"----- DXVB: (ReadBuffer) Exception.\n");
  159. return E_FAIL;
  160. }
  161. return val;
  162. }