WavEnum.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /******************************************************************************
  2. |* THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  3. |* ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  4. |* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  5. |* PARTICULAR PURPOSE.
  6. |*
  7. |* Copyright 1995-2005 Nero AG. All Rights Reserved.
  8. |*-----------------------------------------------------------------------------
  9. |* PROJECT: Nero Plugin Manager Example
  10. |*
  11. |* FILE: WavEnum.cpp
  12. |*
  13. |* PURPOSE: Implementation of the factory enumerator class
  14. ******************************************************************************/
  15. #include "stdafx.h"
  16. #include "WavEnum.h"
  17. // wave target factory
  18. #include "WavTgtFactory.h"
  19. // wave source factory
  20. #include "WavSrcFactory.h"
  21. // globals, defined in the main module
  22. extern IAudioPluginMgr* g_pPluginMgr;
  23. extern CWavTgtFactory g_TgtFactory;
  24. extern CWavSrcFactory g_SrcFactory;
  25. // {D8E76911-E1D2-4560-8E28-F953D6E1BC56}
  26. EXTERN_GUID(COMPID_WavEnum, 0xd8e76911, 0xe1d2, 0x4560, 0x8e, 0x28, 0xf9, 0x53, 0xd6, 0xe1, 0xbc, 0x56);
  27. // QueryInterface returns either IUnknown, IAudioComponent or IComponentEnum
  28. STDMETHODIMP CWavEnum::QueryInterface(REFIID riid, void __RPC_FAR *__RPC_FAR *ppObj)
  29. {
  30. // ppObj must not be NULL
  31. if(NULL == ppObj)
  32. {
  33. ASSERT(FALSE);
  34. return E_INVALIDARG;
  35. }
  36. *ppObj = NULL;
  37. if(IsEqualIID(riid, IID_IUnknown))
  38. *ppObj = static_cast<IUnknown*>(static_cast<IAudioComponent*>(this));
  39. else
  40. if(IsEqualIID(riid, IID_IIdentifiable))
  41. *ppObj = static_cast<IIdentifiable*>(this);
  42. else
  43. if(IsEqualIID(riid, IID_IAudioComponent))
  44. *ppObj = static_cast<IAudioComponent*>(this);
  45. else
  46. if(IsEqualIID(riid, IID_IComponentEnum))
  47. *ppObj = static_cast<IComponentEnum*>(this);
  48. if(*ppObj)
  49. AddRef();
  50. if (NULL != *ppObj)
  51. {
  52. return S_OK;
  53. }
  54. else
  55. {
  56. return E_NOINTERFACE;
  57. }
  58. }
  59. // Increase the reference counter and return the number of references
  60. STDMETHODIMP_(ULONG) CWavEnum::AddRef()
  61. {
  62. InterlockedIncrement(&m_lRef);
  63. return m_lRef;
  64. }
  65. // Decrease the reference counter and return the number of references
  66. STDMETHODIMP_(ULONG) CWavEnum::Release()
  67. {
  68. InterlockedDecrement(&m_lRef);
  69. return m_lRef;
  70. }
  71. void CWavEnum::GetID(GUID *pGUID)
  72. {
  73. ASSERT(pGUID);
  74. if(pGUID)
  75. memcpy(pGUID, &COMPID_WavEnum, sizeof(GUID));
  76. }
  77. // IAudioComponent
  78. const char* CWavEnum::GetName()
  79. {
  80. return "wav enum";
  81. }
  82. EAudioComponentType CWavEnum::GetType()
  83. {
  84. return ACT_ComponentEnumerator;
  85. }
  86. bool CWavEnum::Init(IAudioPluginMgr* pMgr, IStatus** ppStatus)
  87. {
  88. if(ppStatus)
  89. {
  90. *ppStatus = NULL;
  91. }
  92. // set the global pointer to the Audio Plugin Manager
  93. g_pPluginMgr = pMgr;
  94. return true;
  95. }
  96. bool CWavEnum::Done()
  97. {
  98. return true;
  99. }
  100. // IComponentEnum
  101. // Return the number of supported components
  102. int CWavEnum::GetCount()
  103. {
  104. // PCM reader, ADPCM reader and PCM writer
  105. return 3;
  106. }
  107. // return a pointer to a factory object
  108. bool CWavEnum::GetComponent(int iNum, IAudioComponent** ppComp)
  109. {
  110. *ppComp = NULL;
  111. if(iNum == 0)
  112. {
  113. *ppComp = &g_SrcFactory;
  114. }
  115. else if(iNum == 1)
  116. {
  117. *ppComp = &g_TgtFactory;
  118. }
  119. else if(iNum == 2)
  120. {
  121. // not implemented
  122. // *ppComp = &g_ADPCMSrcFactory;
  123. }
  124. if(*ppComp)
  125. {
  126. (*ppComp)->AddRef();
  127. }
  128. if (NULL != *ppComp)
  129. {
  130. return true;
  131. }
  132. else
  133. {
  134. return false;
  135. }
  136. }
  137. long CWavEnum::GetRefCount()
  138. {
  139. return m_lRef;
  140. }