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.

227 lines
5.3 KiB

  1. /*++
  2. Copyright (c) 1997-2000 Microsoft Corporation All Rights Reserved
  3. Module Name:
  4. kshelper.cpp
  5. Abstract:
  6. Helper functions for msvad
  7. --*/
  8. #include "kshelper.h"
  9. //-----------------------------------------------------------------------------
  10. PWAVEFORMATEX
  11. GetWaveFormatEx
  12. (
  13. IN PKSDATAFORMAT pDataFormat
  14. )
  15. /*++
  16. Routine Description:
  17. Returns the waveformatex for known formats.
  18. Arguments:
  19. pDataFormat - data format.
  20. Return Value:
  21. waveformatex in DataFormat.
  22. NULL for unknown data formats.
  23. --*/
  24. {
  25. PWAVEFORMATEX pWfx = NULL;
  26. // If this is a known dataformat extract the waveformat info.
  27. //
  28. if
  29. (
  30. pDataFormat &&
  31. ( IsEqualGUIDAligned(pDataFormat->MajorFormat,
  32. KSDATAFORMAT_TYPE_AUDIO) &&
  33. ( IsEqualGUIDAligned(pDataFormat->Specifier,
  34. KSDATAFORMAT_SPECIFIER_WAVEFORMATEX) ||
  35. IsEqualGUIDAligned(pDataFormat->Specifier,
  36. KSDATAFORMAT_SPECIFIER_DSOUND) ) )
  37. )
  38. {
  39. pWfx = PWAVEFORMATEX(pDataFormat + 1);
  40. if (IsEqualGUIDAligned(pDataFormat->Specifier,
  41. KSDATAFORMAT_SPECIFIER_DSOUND))
  42. {
  43. PKSDSOUND_BUFFERDESC pwfxds;
  44. pwfxds = PKSDSOUND_BUFFERDESC(pDataFormat + 1);
  45. pWfx = &pwfxds->WaveFormatEx;
  46. }
  47. }
  48. return pWfx;
  49. } // GetWaveFormatEx
  50. //-----------------------------------------------------------------------------
  51. NTSTATUS
  52. PropertyHandler_BasicSupport
  53. (
  54. IN PPCPROPERTY_REQUEST PropertyRequest,
  55. IN ULONG Flags,
  56. IN DWORD PropTypeSetId
  57. )
  58. /*++
  59. Routine Description:
  60. Default basic support handler. Basic processing depends on the size of data.
  61. For ULONG it only returns Flags. For KSPROPERTY_DESCRIPTION, the structure
  62. is filled.
  63. Arguments:
  64. PropertyRequest -
  65. Flags - Support flags.
  66. PropTypeSetId - PropTypeSetId
  67. Return Value:
  68. NT status code.
  69. --*/
  70. {
  71. PAGED_CODE();
  72. ASSERT(Flags & KSPROPERTY_TYPE_BASICSUPPORT);
  73. NTSTATUS ntStatus = STATUS_INVALID_PARAMETER;
  74. if (PropertyRequest->ValueSize >= (sizeof(KSPROPERTY_DESCRIPTION)) &&
  75. VT_ILLEGAL != PropTypeSetId)
  76. {
  77. // if return buffer can hold a KSPROPERTY_DESCRIPTION, return it
  78. //
  79. PKSPROPERTY_DESCRIPTION PropDesc =
  80. PKSPROPERTY_DESCRIPTION(PropertyRequest->Value);
  81. PropDesc->AccessFlags = Flags;
  82. PropDesc->DescriptionSize = sizeof(KSPROPERTY_DESCRIPTION);
  83. PropDesc->PropTypeSet.Set = KSPROPTYPESETID_General;
  84. PropDesc->PropTypeSet.Id = PropTypeSetId;
  85. PropDesc->PropTypeSet.Flags = 0;
  86. PropDesc->MembersListCount = 0;
  87. PropDesc->Reserved = 0;
  88. PropertyRequest->ValueSize = sizeof(KSPROPERTY_DESCRIPTION);
  89. ntStatus = STATUS_SUCCESS;
  90. }
  91. else if (PropertyRequest->ValueSize >= sizeof(ULONG))
  92. {
  93. // if return buffer can hold a ULONG, return the access flags
  94. //
  95. *(PULONG(PropertyRequest->Value)) = Flags;
  96. PropertyRequest->ValueSize = sizeof(ULONG);
  97. ntStatus = STATUS_SUCCESS;
  98. }
  99. else if (0 == PropertyRequest->ValueSize)
  100. {
  101. // Send the caller required value size.
  102. PropertyRequest->ValueSize = sizeof(KSPROPERTY_DESCRIPTION);
  103. ntStatus = STATUS_BUFFER_OVERFLOW;
  104. }
  105. else
  106. {
  107. PropertyRequest->ValueSize = 0;
  108. ntStatus = STATUS_BUFFER_TOO_SMALL;
  109. }
  110. return ntStatus;
  111. } // PropertyHandler_BasicSupport
  112. //-----------------------------------------------------------------------------
  113. NTSTATUS
  114. ValidatePropertyParams
  115. (
  116. IN PPCPROPERTY_REQUEST PropertyRequest,
  117. IN ULONG cbSize,
  118. IN ULONG cbInstanceSize /* = 0 */
  119. )
  120. /*++
  121. Routine Description:
  122. Validates property parameters.
  123. Arguments:
  124. PropertyRequest -
  125. cbSize -
  126. cbInstanceSize -
  127. Return Value:
  128. NT status code.
  129. --*/
  130. {
  131. NTSTATUS ntStatus = STATUS_UNSUCCESSFUL;
  132. if (PropertyRequest && cbSize)
  133. {
  134. // If the caller is asking for ValueSize.
  135. //
  136. if (0 == PropertyRequest->ValueSize)
  137. {
  138. PropertyRequest->ValueSize = cbSize;
  139. ntStatus = STATUS_BUFFER_OVERFLOW;
  140. }
  141. // If the caller passed an invalid ValueSize.
  142. //
  143. else if (PropertyRequest->ValueSize < cbSize)
  144. {
  145. ntStatus = STATUS_BUFFER_TOO_SMALL;
  146. }
  147. else if (PropertyRequest->InstanceSize < cbInstanceSize)
  148. {
  149. ntStatus = STATUS_BUFFER_TOO_SMALL;
  150. }
  151. // If all parameters are OK.
  152. //
  153. else if (PropertyRequest->ValueSize == cbSize)
  154. {
  155. if (PropertyRequest->Value)
  156. {
  157. ntStatus = STATUS_SUCCESS;
  158. //
  159. // Caller should set ValueSize, if the property
  160. // call is successful.
  161. //
  162. }
  163. }
  164. }
  165. else
  166. {
  167. ntStatus = STATUS_INVALID_PARAMETER;
  168. }
  169. // Clear the ValueSize if unsuccessful.
  170. //
  171. if (PropertyRequest &&
  172. STATUS_SUCCESS != ntStatus &&
  173. STATUS_BUFFER_OVERFLOW != ntStatus)
  174. {
  175. PropertyRequest->ValueSize = 0;
  176. }
  177. return ntStatus;
  178. } // ValidatePropertyParams