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.

174 lines
5.5 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. #define DIRECTSOUND_VERSION 0x600
  13. #include "stdafx.h"
  14. #include "Direct.h"
  15. #include "dSound.h"
  16. #include "dms.h"
  17. #include "dSoundObj.h"
  18. #include "dSoundCaptureBufferObj.h"
  19. #include "dSoundCaptureObj.h"
  20. CONSTRUCTOR(_dxj_DirectSoundCaptureBuffer, {});
  21. DESTRUCTOR(_dxj_DirectSoundCaptureBuffer, {});
  22. GETSET_OBJECT(_dxj_DirectSoundCaptureBuffer);
  23. STDMETHODIMP C_dxj_DirectSoundCaptureBufferObject::getCaps(DSCBCaps *caps)
  24. {
  25. ((DSCBCAPS*)caps)->dwSize=sizeof(DSCBCAPS);
  26. return m__dxj_DirectSoundCaptureBuffer->GetCaps((DSCBCAPS*)caps);
  27. }
  28. STDMETHODIMP C_dxj_DirectSoundCaptureBufferObject::getCurrentPosition(DSCursors *desc)
  29. {
  30. /////////////////////////////////////////////////////////////////////////////
  31. if(!desc)
  32. return E_POINTER;
  33. return (m__dxj_DirectSoundCaptureBuffer->GetCurrentPosition((DWORD*)&desc->lPlay, (DWORD*)&desc->lWrite) );
  34. }
  35. STDMETHODIMP C_dxj_DirectSoundCaptureBufferObject::getStatus(long *stat)
  36. {
  37. return m__dxj_DirectSoundCaptureBuffer->GetStatus((DWORD*)stat);
  38. }
  39. STDMETHODIMP C_dxj_DirectSoundCaptureBufferObject::start(long flags)
  40. {
  41. return m__dxj_DirectSoundCaptureBuffer->Start((DWORD)flags);
  42. }
  43. STDMETHODIMP C_dxj_DirectSoundCaptureBufferObject::stop()
  44. {
  45. return m__dxj_DirectSoundCaptureBuffer->Stop();
  46. }
  47. STDMETHODIMP C_dxj_DirectSoundCaptureBufferObject::getFormat(WaveFormatex *format)
  48. {
  49. DWORD cb=0;
  50. return m__dxj_DirectSoundCaptureBuffer->GetFormat((WAVEFORMATEX*)format,sizeof(WaveFormatex),&cb);
  51. }
  52. STDMETHODIMP C_dxj_DirectSoundCaptureBufferObject::initialize(I_dxj_DirectSoundCaptureBuffer *buffer,DSCBufferDesc *desc)
  53. {
  54. ((DSCBUFFERDESC*)desc)->dwSize=sizeof(DSCBUFFERDESC);
  55. DO_GETOBJECT_NOTNULL(LPDIRECTSOUNDCAPTURE, lpref, buffer);
  56. return m__dxj_DirectSoundCaptureBuffer->Initialize(lpref,(DSCBUFFERDESC*)desc);
  57. }
  58. STDMETHODIMP C_dxj_DirectSoundCaptureBufferObject::setNotificationPositions (long nElements,SAFEARRAY **ppsa)
  59. {
  60. if (!ISSAFEARRAY1D(ppsa,(DWORD)nElements))
  61. return E_INVALIDARG;
  62. HRESULT hr;
  63. LPDIRECTSOUNDNOTIFY pDSN=NULL;
  64. hr=m__dxj_DirectSoundCaptureBuffer->QueryInterface(IID_IDirectSoundNotify,(void**)&pDSN);
  65. if FAILED(hr) return hr;
  66. hr=pDSN->SetNotificationPositions((DWORD)nElements,(LPCDSBPOSITIONNOTIFY)((SAFEARRAY*)*ppsa)->pvData);
  67. pDSN->Release();
  68. return hr;
  69. }
  70. /////////////////////////////////////////////////////////////////////////////
  71. //Java has no direct access to system memory, so it allocates it's own buffer
  72. //which is passed into WriteBuffer(). Because the environment is now double
  73. //buffered there is no need to Lock Java memory. WriteBuffer() calls
  74. //both lock and Unlock internally to write the result after the fact.
  75. /////////////////////////////////////////////////////////////////////////////
  76. STDMETHODIMP C_dxj_DirectSoundCaptureBufferObject::writeBuffer(long start, long totsz,
  77. void *buf, long flags)
  78. {
  79. #pragma message ("SoundBuffer writeBuffer ")
  80. byte *buffer=(byte*)buf; //(byte*)((SAFEARRAY*)*ppsa)->pvData;
  81. if(!buffer)
  82. return E_POINTER;
  83. LPVOID p1, p2;
  84. DWORD size1=0, size2=0;
  85. HRESULT val = E_FAIL;
  86. __try {
  87. if ((val = m__dxj_DirectSoundCaptureBuffer->Lock((DWORD)start, (DWORD)totsz, &p1, &size1, &p2, &size2,
  88. (DWORD)flags)) != DS_OK)
  89. return val;
  90. // Copy to buffer end, then do a wrapped portion if it exists, then unlock
  91. if (size1)
  92. memcpy (p1, &buffer[start], size1);
  93. if (size2)
  94. memcpy(p2, &buffer, size2);
  95. //docdoc: because Lock and Unlock are tied together within WriteBuffer,
  96. // DSBufferDesc no longer needs to save Lock's system pointers.
  97. val=m__dxj_DirectSoundCaptureBuffer->Unlock(p1, size1, p2, size2);
  98. }
  99. __except(0,0){
  100. return E_FAIL;
  101. }
  102. return val;
  103. }
  104. /////////////////////////////////////////////////////////////////////////////
  105. //Java has no direct access to system memory, so it allocates it's own buffer
  106. //which is passed into WriteBuffer(). Because the environment is now double
  107. //buffered there is no need to Lock Java memory. WriteBuffer() calls
  108. //both lock and Unlock internally to write the result after the fact.
  109. /////////////////////////////////////////////////////////////////////////////
  110. STDMETHODIMP C_dxj_DirectSoundCaptureBufferObject::readBuffer(long start, long totsz,
  111. void *buf, long flags)
  112. {
  113. //byte *buffer=(byte*)((SAFEARRAY*)*ppsa)->pvData;
  114. byte *buffer=(byte*)buf;
  115. if(!buffer)
  116. return E_POINTER;
  117. LPVOID p1, p2;
  118. DWORD size1=0, size2=0;
  119. HRESULT val = E_FAIL;
  120. __try {
  121. if ((val = m__dxj_DirectSoundCaptureBuffer->Lock((DWORD)start, (DWORD)totsz, &p1, &size1, &p2, &size2,
  122. (DWORD)flags)) != DS_OK)
  123. return val;
  124. // Copy to buffer end, then do a wrapped portion if it exists, then unlock
  125. if (size1)
  126. memcpy (&buffer[start],p1, size1);
  127. if (size2)
  128. memcpy(&buffer,p2, size2);
  129. //docdoc: because Lock and Unlock are tied together within WriteBuffer,
  130. // DSBufferDesc no longer needs to save Lock's system pointers.
  131. val= m__dxj_DirectSoundCaptureBuffer->Unlock(p1, size1, p2, size2);
  132. }
  133. __except(0,0){
  134. return E_FAIL;
  135. }
  136. return val;
  137. }