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.

219 lines
5.8 KiB

  1. //
  2. // Copyright (c) 1999-2001 Microsoft Corporation. All rights reserved.
  3. //
  4. // Base classes that implement aspects of a standard DirectMusic track.
  5. // Implementations for CBasicTrack.
  6. //
  7. #include "trackhelp.h"
  8. #include "validate.h"
  9. //////////////////////////////////////////////////////////////////////
  10. // Creation
  11. CBasicTrack::CBasicTrack(long *plModuleLockCounter, const CLSID &rclsid)
  12. : m_cRef(0),
  13. m_plModuleLockCounter(plModuleLockCounter),
  14. m_rclsid(rclsid)
  15. {
  16. InitializeCriticalSection(&m_CriticalSection);
  17. // Note: on pre-Blackcomb OS's, this call can raise an exception; if it
  18. // ever pops in stress, we can add an exception handler and retry loop.
  19. InterlockedIncrement(plModuleLockCounter);
  20. }
  21. //////////////////////////////////////////////////////////////////////
  22. // IUnknown
  23. STDMETHODIMP
  24. CBasicTrack::QueryInterface(const IID &iid, void **ppv)
  25. {
  26. V_INAME(CBasicTrack::QueryInterface);
  27. V_PTRPTR_WRITE(ppv);
  28. V_REFGUID(iid);
  29. if (iid == IID_IUnknown || iid == IID_IDirectMusicTrack || iid == IID_IDirectMusicTrack8)
  30. *ppv = static_cast<IDirectMusicTrack8*>(this);
  31. else if (iid == IID_IPersistStream)
  32. *ppv = static_cast<IPersistStream*>(this);
  33. else if (iid == IID_IPersist)
  34. *ppv = static_cast<IPersist*>(this);
  35. else
  36. {
  37. *ppv = NULL;
  38. Trace(4,"Warning: Request to query unknown interface on Track\n");
  39. return E_NOINTERFACE;
  40. }
  41. reinterpret_cast<IUnknown*>(this)->AddRef();
  42. return S_OK;
  43. }
  44. STDMETHODIMP_(ULONG)
  45. CBasicTrack::AddRef()
  46. {
  47. return InterlockedIncrement(&m_cRef);
  48. }
  49. STDMETHODIMP_(ULONG)
  50. CBasicTrack::Release()
  51. {
  52. if (!InterlockedDecrement(&m_cRef))
  53. {
  54. DeleteCriticalSection(&m_CriticalSection);
  55. delete this;
  56. return 0;
  57. }
  58. return m_cRef;
  59. }
  60. //////////////////////////////////////////////////////////////////////
  61. // IUnknown
  62. STDMETHODIMP
  63. CBasicTrack::GetClassID(CLSID* pClassID)
  64. {
  65. V_INAME(CBasicTrack::GetClassID);
  66. V_PTR_WRITE(pClassID, sizeof(pClassID));
  67. *pClassID = m_rclsid;
  68. return S_OK;
  69. }
  70. //////////////////////////////////////////////////////////////////////
  71. // IDirectMusicTrack
  72. STDMETHODIMP
  73. CBasicTrack::Init(IDirectMusicSegment *pSegment)
  74. {
  75. V_INAME(CBasicTrack::Init);
  76. V_INTERFACE(pSegment);
  77. return S_OK;
  78. }
  79. STDMETHODIMP
  80. CBasicTrack::Play(
  81. void *pStateData,
  82. MUSIC_TIME mtStart,
  83. MUSIC_TIME mtEnd,
  84. MUSIC_TIME mtOffset,
  85. DWORD dwFlags,
  86. IDirectMusicPerformance* pPerf,
  87. IDirectMusicSegmentState* pSegSt,
  88. DWORD dwVirtualID)
  89. {
  90. return this->PlayMusicOrClock(
  91. pStateData,
  92. mtStart,
  93. mtEnd,
  94. mtOffset,
  95. 0,
  96. dwFlags,
  97. pPerf,
  98. pSegSt,
  99. dwVirtualID,
  100. false);
  101. }
  102. //////////////////////////////////////////////////////////////////////
  103. // IDirectMusicTrack8
  104. STDMETHODIMP CBasicTrack::PlayEx(
  105. void* pStateData,
  106. REFERENCE_TIME rtStart,
  107. REFERENCE_TIME rtEnd,
  108. REFERENCE_TIME rtOffset,
  109. DWORD dwFlags,
  110. IDirectMusicPerformance* pPerf,
  111. IDirectMusicSegmentState* pSegSt,
  112. DWORD dwVirtualID)
  113. {
  114. if (dwFlags & DMUS_TRACKF_CLOCK)
  115. {
  116. // Convert all reference times to millisecond times and then just use them as if this were MUSIC_TIME.
  117. return this->PlayMusicOrClock(
  118. pStateData,
  119. static_cast<MUSIC_TIME>(rtStart / gc_RefPerMil),
  120. static_cast<MUSIC_TIME>(rtEnd / gc_RefPerMil),
  121. static_cast<MUSIC_TIME>(rtOffset / gc_RefPerMil),
  122. rtOffset,
  123. dwFlags,
  124. pPerf,
  125. pSegSt,
  126. dwVirtualID,
  127. true);
  128. }
  129. else
  130. {
  131. return this->PlayMusicOrClock(
  132. pStateData,
  133. static_cast<MUSIC_TIME>(rtStart),
  134. static_cast<MUSIC_TIME>(rtEnd),
  135. static_cast<MUSIC_TIME>(rtOffset),
  136. 0,
  137. dwFlags,
  138. pPerf,
  139. pSegSt,
  140. dwVirtualID,
  141. false);
  142. }
  143. }
  144. STDMETHODIMP CBasicTrack::GetParamEx(
  145. REFGUID rguidType,
  146. REFERENCE_TIME rtTime,
  147. REFERENCE_TIME* prtNext,
  148. void* pParam,
  149. void * pStateData,
  150. DWORD dwFlags)
  151. {
  152. HRESULT hr;
  153. MUSIC_TIME mtNext;
  154. if (dwFlags & DMUS_TRACK_PARAMF_CLOCK)
  155. {
  156. hr = GetParam(rguidType, static_cast<MUSIC_TIME>(rtTime / gc_RefPerMil), &mtNext, pParam);
  157. if (prtNext)
  158. {
  159. *prtNext = mtNext * gc_RefPerMil;
  160. }
  161. }
  162. else
  163. {
  164. hr = GetParam(rguidType, static_cast<MUSIC_TIME>(rtTime), &mtNext, pParam);
  165. if (prtNext)
  166. {
  167. *prtNext = mtNext;
  168. }
  169. }
  170. return hr;
  171. }
  172. STDMETHODIMP CBasicTrack::SetParamEx(
  173. REFGUID rguidType,
  174. REFERENCE_TIME rtTime,
  175. void* pParam, void * pStateData, DWORD dwFlags)
  176. {
  177. if (dwFlags & DMUS_TRACK_PARAMF_CLOCK)
  178. {
  179. rtTime /= gc_RefPerMil;
  180. }
  181. return SetParam(rguidType, static_cast<MUSIC_TIME>(rtTime ), pParam);
  182. }
  183. STDMETHODIMP CBasicTrack::Compose(
  184. IUnknown* pContext,
  185. DWORD dwTrackGroup,
  186. IDirectMusicTrack** ppResultTrack)
  187. {
  188. return E_NOTIMPL;
  189. }
  190. STDMETHODIMP CBasicTrack::Join(
  191. IDirectMusicTrack* pNewTrack,
  192. MUSIC_TIME mtJoin,
  193. IUnknown* pContext,
  194. DWORD dwTrackGroup,
  195. IDirectMusicTrack** ppResultTrack)
  196. {
  197. return E_NOTIMPL;
  198. }