seeking.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. /*
  2. * Filter Seeking and Control Interfaces
  3. *
  4. * Copyright 2003 Robert Shearman
  5. * Copyright 2010 Aric Stewart, CodeWeavers
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  20. */
  21. #include "strmbase_private.h"
  22. WINE_DEFAULT_DEBUG_CHANNEL(quartz);
  23. static inline SourceSeeking *impl_from_IMediaSeeking(IMediaSeeking *iface)
  24. {
  25. return CONTAINING_RECORD(iface, SourceSeeking, IMediaSeeking_iface);
  26. }
  27. HRESULT strmbase_seeking_init(SourceSeeking *pSeeking, const IMediaSeekingVtbl *Vtbl,
  28. SourceSeeking_ChangeStop fnChangeStop, SourceSeeking_ChangeStart fnChangeStart,
  29. SourceSeeking_ChangeRate fnChangeRate)
  30. {
  31. assert(fnChangeStop && fnChangeStart && fnChangeRate);
  32. pSeeking->IMediaSeeking_iface.lpVtbl = Vtbl;
  33. pSeeking->refCount = 1;
  34. pSeeking->fnChangeRate = fnChangeRate;
  35. pSeeking->fnChangeStop = fnChangeStop;
  36. pSeeking->fnChangeStart = fnChangeStart;
  37. pSeeking->dwCapabilities = AM_SEEKING_CanSeekForwards |
  38. AM_SEEKING_CanSeekBackwards |
  39. AM_SEEKING_CanSeekAbsolute |
  40. AM_SEEKING_CanGetStopPos |
  41. AM_SEEKING_CanGetDuration;
  42. pSeeking->llCurrent = 0;
  43. pSeeking->llStop = ((ULONGLONG)0x80000000) << 32;
  44. pSeeking->llDuration = pSeeking->llStop;
  45. pSeeking->dRate = 1.0;
  46. pSeeking->timeformat = TIME_FORMAT_MEDIA_TIME;
  47. InitializeCriticalSection(&pSeeking->cs);
  48. pSeeking->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": SourceSeeking.cs");
  49. return S_OK;
  50. }
  51. void strmbase_seeking_cleanup(SourceSeeking *seeking)
  52. {
  53. DeleteCriticalSection(&seeking->cs);
  54. }
  55. HRESULT WINAPI SourceSeekingImpl_GetCapabilities(IMediaSeeking * iface, DWORD * pCapabilities)
  56. {
  57. SourceSeeking *This = impl_from_IMediaSeeking(iface);
  58. TRACE("(%p)\n", pCapabilities);
  59. *pCapabilities = This->dwCapabilities;
  60. return S_OK;
  61. }
  62. HRESULT WINAPI SourceSeekingImpl_CheckCapabilities(IMediaSeeking * iface, DWORD * pCapabilities)
  63. {
  64. SourceSeeking *This = impl_from_IMediaSeeking(iface);
  65. HRESULT hr;
  66. DWORD dwCommonCaps;
  67. TRACE("(%p)\n", pCapabilities);
  68. if (!pCapabilities)
  69. return E_POINTER;
  70. dwCommonCaps = *pCapabilities & This->dwCapabilities;
  71. if (!dwCommonCaps)
  72. hr = E_FAIL;
  73. else
  74. hr = (*pCapabilities == dwCommonCaps) ? S_OK : S_FALSE;
  75. *pCapabilities = dwCommonCaps;
  76. return hr;
  77. }
  78. HRESULT WINAPI SourceSeekingImpl_IsFormatSupported(IMediaSeeking * iface, const GUID * pFormat)
  79. {
  80. TRACE("(%s)\n", debugstr_guid(pFormat));
  81. return (IsEqualIID(pFormat, &TIME_FORMAT_MEDIA_TIME) ? S_OK : S_FALSE);
  82. }
  83. HRESULT WINAPI SourceSeekingImpl_QueryPreferredFormat(IMediaSeeking * iface, GUID * pFormat)
  84. {
  85. TRACE("(%s)\n", debugstr_guid(pFormat));
  86. *pFormat = TIME_FORMAT_MEDIA_TIME;
  87. return S_OK;
  88. }
  89. HRESULT WINAPI SourceSeekingImpl_GetTimeFormat(IMediaSeeking * iface, GUID * pFormat)
  90. {
  91. SourceSeeking *This = impl_from_IMediaSeeking(iface);
  92. TRACE("(%s)\n", debugstr_guid(pFormat));
  93. EnterCriticalSection(&This->cs);
  94. *pFormat = This->timeformat;
  95. LeaveCriticalSection(&This->cs);
  96. return S_OK;
  97. }
  98. HRESULT WINAPI SourceSeekingImpl_IsUsingTimeFormat(IMediaSeeking * iface, const GUID * pFormat)
  99. {
  100. SourceSeeking *This = impl_from_IMediaSeeking(iface);
  101. HRESULT hr = S_OK;
  102. TRACE("(%s)\n", debugstr_guid(pFormat));
  103. EnterCriticalSection(&This->cs);
  104. if (!IsEqualIID(pFormat, &This->timeformat))
  105. hr = S_FALSE;
  106. LeaveCriticalSection(&This->cs);
  107. return hr;
  108. }
  109. HRESULT WINAPI SourceSeekingImpl_SetTimeFormat(IMediaSeeking * iface, const GUID * pFormat)
  110. {
  111. SourceSeeking *This = impl_from_IMediaSeeking(iface);
  112. TRACE("%p %s\n", This, debugstr_guid(pFormat));
  113. return (IsEqualIID(pFormat, &TIME_FORMAT_MEDIA_TIME) ? S_OK : E_INVALIDARG);
  114. }
  115. HRESULT WINAPI SourceSeekingImpl_GetDuration(IMediaSeeking * iface, LONGLONG * pDuration)
  116. {
  117. SourceSeeking *This = impl_from_IMediaSeeking(iface);
  118. TRACE("(%p)\n", pDuration);
  119. EnterCriticalSection(&This->cs);
  120. *pDuration = This->llDuration;
  121. LeaveCriticalSection(&This->cs);
  122. return S_OK;
  123. }
  124. HRESULT WINAPI SourceSeekingImpl_GetStopPosition(IMediaSeeking * iface, LONGLONG * pStop)
  125. {
  126. SourceSeeking *This = impl_from_IMediaSeeking(iface);
  127. TRACE("(%p)\n", pStop);
  128. EnterCriticalSection(&This->cs);
  129. *pStop = This->llStop;
  130. LeaveCriticalSection(&This->cs);
  131. return S_OK;
  132. }
  133. /* FIXME: Make use of the info the filter should expose */
  134. HRESULT WINAPI SourceSeekingImpl_GetCurrentPosition(IMediaSeeking * iface, LONGLONG * pCurrent)
  135. {
  136. SourceSeeking *This = impl_from_IMediaSeeking(iface);
  137. TRACE("(%p)\n", pCurrent);
  138. EnterCriticalSection(&This->cs);
  139. *pCurrent = This->llCurrent;
  140. LeaveCriticalSection(&This->cs);
  141. return S_OK;
  142. }
  143. HRESULT WINAPI SourceSeekingImpl_ConvertTimeFormat(IMediaSeeking * iface, LONGLONG * pTarget, const GUID * pTargetFormat, LONGLONG Source, const GUID * pSourceFormat)
  144. {
  145. SourceSeeking *This = impl_from_IMediaSeeking(iface);
  146. if (!pTargetFormat)
  147. pTargetFormat = &This->timeformat;
  148. if (!pSourceFormat)
  149. pSourceFormat = &This->timeformat;
  150. if (IsEqualIID(pTargetFormat, &TIME_FORMAT_MEDIA_TIME) && IsEqualIID(pSourceFormat, &TIME_FORMAT_MEDIA_TIME))
  151. {
  152. *pTarget = Source;
  153. return S_OK;
  154. }
  155. /* FIXME: clear pTarget? */
  156. return E_INVALIDARG;
  157. }
  158. static inline LONGLONG Adjust(LONGLONG value, const LONGLONG * pModifier, DWORD dwFlags)
  159. {
  160. switch (dwFlags & AM_SEEKING_PositioningBitsMask)
  161. {
  162. case AM_SEEKING_NoPositioning:
  163. return value;
  164. case AM_SEEKING_AbsolutePositioning:
  165. return *pModifier;
  166. case AM_SEEKING_RelativePositioning:
  167. case AM_SEEKING_IncrementalPositioning:
  168. return value + *pModifier;
  169. default:
  170. assert(FALSE);
  171. return 0;
  172. }
  173. }
  174. HRESULT WINAPI SourceSeekingImpl_SetPositions(IMediaSeeking * iface, LONGLONG * pCurrent, DWORD dwCurrentFlags, LONGLONG * pStop, DWORD dwStopFlags)
  175. {
  176. SourceSeeking *This = impl_from_IMediaSeeking(iface);
  177. BOOL bChangeCurrent = FALSE, bChangeStop = FALSE;
  178. LONGLONG llNewCurrent, llNewStop;
  179. TRACE("iface %p, current %s, current_flags %#lx, stop %s, stop_flags %#lx.\n", iface,
  180. pCurrent ? debugstr_time(*pCurrent) : "<null>", dwCurrentFlags,
  181. pStop ? debugstr_time(*pStop): "<null>", dwStopFlags);
  182. EnterCriticalSection(&This->cs);
  183. llNewCurrent = Adjust(This->llCurrent, pCurrent, dwCurrentFlags);
  184. llNewStop = Adjust(This->llStop, pStop, dwStopFlags);
  185. if (pCurrent)
  186. bChangeCurrent = TRUE;
  187. if (llNewStop != This->llStop)
  188. bChangeStop = TRUE;
  189. TRACE("Seeking from %s to %s.\n", debugstr_time(This->llCurrent), debugstr_time(llNewCurrent));
  190. This->llCurrent = llNewCurrent;
  191. This->llStop = llNewStop;
  192. if (pCurrent && (dwCurrentFlags & AM_SEEKING_ReturnTime))
  193. *pCurrent = llNewCurrent;
  194. if (pStop && (dwStopFlags & AM_SEEKING_ReturnTime))
  195. *pStop = llNewStop;
  196. LeaveCriticalSection(&This->cs);
  197. if (bChangeCurrent)
  198. This->fnChangeStart(iface);
  199. if (bChangeStop)
  200. This->fnChangeStop(iface);
  201. return S_OK;
  202. }
  203. HRESULT WINAPI SourceSeekingImpl_GetPositions(IMediaSeeking * iface, LONGLONG * pCurrent, LONGLONG * pStop)
  204. {
  205. SourceSeeking *This = impl_from_IMediaSeeking(iface);
  206. TRACE("(%p, %p)\n", pCurrent, pStop);
  207. EnterCriticalSection(&This->cs);
  208. IMediaSeeking_GetCurrentPosition(iface, pCurrent);
  209. IMediaSeeking_GetStopPosition(iface, pStop);
  210. LeaveCriticalSection(&This->cs);
  211. return S_OK;
  212. }
  213. HRESULT WINAPI SourceSeekingImpl_GetAvailable(IMediaSeeking * iface, LONGLONG * pEarliest, LONGLONG * pLatest)
  214. {
  215. SourceSeeking *This = impl_from_IMediaSeeking(iface);
  216. TRACE("(%p, %p)\n", pEarliest, pLatest);
  217. EnterCriticalSection(&This->cs);
  218. *pEarliest = 0;
  219. *pLatest = This->llDuration;
  220. LeaveCriticalSection(&This->cs);
  221. return S_OK;
  222. }
  223. HRESULT WINAPI SourceSeekingImpl_SetRate(IMediaSeeking * iface, double dRate)
  224. {
  225. SourceSeeking *This = impl_from_IMediaSeeking(iface);
  226. BOOL bChangeRate = (dRate != This->dRate);
  227. HRESULT hr = S_OK;
  228. TRACE("(%e)\n", dRate);
  229. if (dRate > 100 || dRate < .001)
  230. {
  231. FIXME("Excessive rate %e, ignoring\n", dRate);
  232. return VFW_E_UNSUPPORTED_AUDIO;
  233. }
  234. EnterCriticalSection(&This->cs);
  235. This->dRate = dRate;
  236. if (bChangeRate)
  237. hr = This->fnChangeRate(iface);
  238. LeaveCriticalSection(&This->cs);
  239. return hr;
  240. }
  241. HRESULT WINAPI SourceSeekingImpl_GetRate(IMediaSeeking * iface, double * dRate)
  242. {
  243. SourceSeeking *This = impl_from_IMediaSeeking(iface);
  244. TRACE("(%p)\n", dRate);
  245. EnterCriticalSection(&This->cs);
  246. /* Forward? */
  247. *dRate = This->dRate;
  248. LeaveCriticalSection(&This->cs);
  249. return S_OK;
  250. }
  251. HRESULT WINAPI SourceSeekingImpl_GetPreroll(IMediaSeeking * iface, LONGLONG * pPreroll)
  252. {
  253. TRACE("(%p)\n", pPreroll);
  254. *pPreroll = 0;
  255. return S_OK;
  256. }