common.h
Upload User: geng8029
Upload Date: 2021-01-30
Package Size: 187k
Code Size: 3k
Category:

Audio program

Development Platform:

Visual C++

  1. #pragma once
  2. #include "logging.h"
  3. // Common macros
  4. // SAFE_RELEASE template.
  5. // Releases a COM pointer if the pointer is not NULL, and sets the pointer to NULL.
  6. #ifndef SAFE_RELEASE
  7. template <class T>
  8. inline void SAFE_RELEASE(T*& p)
  9. {
  10.     if (p)
  11.     {
  12.         p->Release();
  13.         p = NULL;
  14.     }
  15. }
  16. #endif
  17. // SAFE_ADDREF macro.
  18. // AddRef's a COM pointer if the pointer is not NULL.
  19. #ifndef SAFE_ADDREF
  20. #define SAFE_ADDREF(x) if (x) { x->AddRef(); }
  21. #endif
  22. // SAFE_DELETE macro.
  23. // Deletes a pointer allocated with new.
  24. #ifndef SAFE_DELETE
  25. #define SAFE_DELETE(x) if (x) { delete x; x = NULL; }
  26. #endif
  27. // CopyComPointer
  28. // Assigns a COM pointer to another COM pointer.
  29. template <class T>
  30. void CopyComPointer(T* &dest, T *src)
  31. {
  32.     if (dest)
  33.     {
  34.         dest->Release();
  35.     }
  36.     dest = src;
  37.     if (dest)
  38.     {
  39.         dest->AddRef();
  40.     }
  41. }
  42. // SAFE_ARRAY_DELETE macro.
  43. // Deletes an array allocated with new [].
  44. #ifndef SAFE_ARRAY_DELETE
  45. #define SAFE_ARRAY_DELETE(x) if (x) { delete [] x; x = NULL; }
  46. #endif
  47. // ARRAY_SIZE macro.
  48. // Returns the size of an array (on the stack only)
  49. #ifndef ARRAY_SIZE
  50. #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]) )
  51. #endif
  52. // IF_FAILED_GOTO macro.
  53. // Jumps to 'label' on failure.
  54. #ifndef IF_FAILED_GOTO
  55. #define IF_FAILED_GOTO(hr, label) if (FAILED(hr)) { goto label; }
  56. #endif
  57. // CheckPointer macro.
  58. // Returns 'hr' if pointer 'x' is NULL.
  59. #ifndef CheckPointer
  60. #define CheckPointer(x, hr) if (x == NULL) { return hr; }
  61. #endif
  62. ///////////////////////////////////////////////////////////////////////
  63. // Name: AreCOMObjectsEqual [template]
  64. // Desc: Tests two COM pointers for equality.
  65. ///////////////////////////////////////////////////////////////////////
  66. template <class T1, class T2>
  67. bool AreComObjectsEqual(T1 *p1, T2 *p2)
  68. {
  69.     bool bResult = false;
  70.     if (p1 == NULL && p2 == NULL)
  71.     {
  72.         // Both are NULL
  73.         bResult = true;
  74.     }
  75.     else if (p1 == NULL || p2 == NULL)
  76.     {
  77.         // One is NULL and one is not
  78.         bResult = false;
  79.     }
  80.     else 
  81.     {
  82.         // Both are not NULL. Compare IUnknowns.
  83.         IUnknown *pUnk1 = NULL;
  84.         IUnknown *pUnk2 = NULL;
  85.         if (SUCCEEDED(p1->QueryInterface(IID_IUnknown, (void**)&pUnk1)))
  86.         {
  87.             if (SUCCEEDED(p2->QueryInterface(IID_IUnknown, (void**)&pUnk2)))
  88.             {
  89.                 bResult = (pUnk1 == pUnk2);
  90.                 pUnk2->Release();
  91.             }
  92.             pUnk1->Release();
  93.         }
  94.     }
  95.     return bResult;
  96. }
  97. #include <assert.h>
  98. #include "mfutils.h"
  99. #include "asyncCB.h"
  100. #include "BufferLock.h"
  101. #include "ClassFactory.h"
  102. #include "critsec.h"
  103. #include "GrowArray.h"
  104. #include "linklist.h"
  105. #include "mediatype.h"
  106. #include "propvar.h"
  107. #include "TinyMap.h"
  108. #include "trace.h"