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.

205 lines
4.8 KiB

  1. //
  2. // tmutils.cpp : Utility functions
  3. //
  4. #include "stdafx.h"
  5. #include <fourcc.h>
  6. bool IsSameObject(IUnknown *pUnk1, IUnknown *pUnk2)
  7. {
  8. if (pUnk1 == pUnk2) {
  9. return TRUE;
  10. }
  11. //
  12. // NOTE: We can't use CComQIPtr here becuase it won't do the QueryInterface!
  13. //
  14. IUnknown *pRealUnk1;
  15. IUnknown *pRealUnk2;
  16. pUnk1->QueryInterface(IID_IUnknown, (void **)&pRealUnk1);
  17. pUnk2->QueryInterface(IID_IUnknown, (void **)&pRealUnk2);
  18. pRealUnk1->Release();
  19. pRealUnk2->Release();
  20. return (pRealUnk1 == pRealUnk2);
  21. }
  22. STDAPI_(void) TStringFromGUID(const GUID* pguid, LPTSTR pszBuf)
  23. {
  24. wsprintf(pszBuf, TEXT("{%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}"), pguid->Data1,
  25. pguid->Data2, pguid->Data3, pguid->Data4[0], pguid->Data4[1], pguid->Data4[2],
  26. pguid->Data4[3], pguid->Data4[4], pguid->Data4[5], pguid->Data4[6], pguid->Data4[7]);
  27. }
  28. #ifndef UNICODE
  29. STDAPI_(void) WStringFromGUID(const GUID* pguid, LPWSTR pszBuf)
  30. {
  31. char szAnsi[40];
  32. TStringFromGUID(pguid, szAnsi);
  33. MultiByteToWideChar(CP_ACP, 0, szAnsi, -1, pszBuf, sizeof(szAnsi));
  34. }
  35. #endif
  36. //
  37. // Media Type helpers
  38. //
  39. void InitMediaType(AM_MEDIA_TYPE * pmt)
  40. {
  41. ZeroMemory(pmt, sizeof(*pmt));
  42. pmt->lSampleSize = 1;
  43. pmt->bFixedSizeSamples = TRUE;
  44. }
  45. bool IsEqualMediaType(AM_MEDIA_TYPE const & mt1, AM_MEDIA_TYPE const & mt2)
  46. {
  47. return ((IsEqualGUID(mt1.majortype,mt2.majortype) == TRUE) &&
  48. (IsEqualGUID(mt1.subtype,mt2.subtype) == TRUE) &&
  49. (IsEqualGUID(mt1.formattype,mt2.formattype) == TRUE) &&
  50. (mt1.cbFormat == mt2.cbFormat) &&
  51. ( (mt1.cbFormat == 0) ||
  52. ( memcmp(mt1.pbFormat, mt2.pbFormat, mt1.cbFormat) == 0)));
  53. }
  54. //
  55. // Load string for this resource. Safe with respect to string size.
  56. // the caller is responsible for freeing returned memory by calling
  57. // SysFreeString
  58. //
  59. BSTR SafeLoadString( UINT uResourceID )
  60. {
  61. TCHAR *pszTempString = NULL;
  62. int nCurrentSizeInChars = 128;
  63. int nCharsCopied = 0;
  64. do
  65. {
  66. if ( NULL != pszTempString )
  67. {
  68. delete pszTempString;
  69. pszTempString = NULL;
  70. }
  71. nCurrentSizeInChars *= 2;
  72. pszTempString = new TCHAR[nCurrentSizeInChars];
  73. if (NULL == pszTempString)
  74. {
  75. return NULL;
  76. }
  77. nCharsCopied = ::LoadString( _Module.GetResourceInstance(),
  78. uResourceID,
  79. pszTempString,
  80. nCurrentSizeInChars
  81. );
  82. if ( 0 == nCharsCopied )
  83. {
  84. delete pszTempString;
  85. return NULL;
  86. }
  87. //
  88. // nCharsCopied does not include the null terminator
  89. // so compare it to the size of the buffer - 1
  90. // if the buffer was filled completely, retry with a bigger buffer
  91. //
  92. } while ( (nCharsCopied >= (nCurrentSizeInChars - 1) ) );
  93. //
  94. // allocate bstr and initialize it with the string we have
  95. //
  96. BSTR bstrReturnString = SysAllocString(pszTempString);
  97. //
  98. // no longer need this
  99. //
  100. delete pszTempString;
  101. pszTempString = NULL;
  102. return bstrReturnString;
  103. }
  104. ///////////////////////////////////////////////////////////////////////////////
  105. //
  106. // DumpAllocatorProperties
  107. //
  108. // helper function that dumps allocator properties preceeded by the argumen
  109. // string
  110. //
  111. void DumpAllocatorProperties(const char *szString,
  112. const ALLOCATOR_PROPERTIES *pAllocProps)
  113. {
  114. LOG((MSP_INFO,
  115. "%s - AllocatorProperties at [%p]\n"
  116. " cBuffers [%ld] \n"
  117. " cbBuffer [%ld] \n"
  118. " cbAlign [%ld] \n"
  119. " cbPrefix [%ld]",
  120. szString,
  121. pAllocProps,
  122. pAllocProps->cBuffers,
  123. pAllocProps->cbBuffer,
  124. pAllocProps->cbAlign,
  125. pAllocProps->cbPrefix
  126. ));
  127. }
  128. //
  129. // returns true if the media type structure is bad
  130. //
  131. BOOL IsBadMediaType(IN const AM_MEDIA_TYPE *pMediaType)
  132. {
  133. //
  134. // make sure the structure we got is good
  135. //
  136. if (IsBadReadPtr(pMediaType, sizeof(AM_MEDIA_TYPE)))
  137. {
  138. LOG((MSP_ERROR,
  139. "CBSourcePin::put_MediaTypeOnPin - bad media type stucture passed in"));
  140. return TRUE;
  141. }
  142. //
  143. // make sure format buffer is good, as advertized
  144. //
  145. if ( (pMediaType->cbFormat > 0) && IsBadReadPtr(pMediaType->pbFormat, pMediaType->cbFormat) )
  146. {
  147. LOG((MSP_ERROR,
  148. "CBSourcePin::put_MediaTypeOnPin - bad format field in media type structure passed in"));
  149. return TRUE;
  150. }
  151. return FALSE;
  152. }