Return error from low level driver when necessary.
[wine.git] / dlls / quartz / control.c
blobb9d87903adb47bed9d04d95cdf8d96fd98566bcd
1 /*
2 * Filter Seeking and Control Interfaces
4 * Copyright 2003 Robert Shearman
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 /* FIXME: critical sections */
22 #include "quartz_private.h"
23 #include "control_private.h"
25 #include "uuids.h"
26 #include "wine/debug.h"
28 #include <assert.h>
30 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
32 HRESULT MediaSeekingImpl_Init(LPVOID pUserData, CHANGEPROC fnChangeStop, CHANGEPROC fnChangeStart, CHANGEPROC fnChangeRate, MediaSeekingImpl * pSeeking)
34 assert(fnChangeStop && fnChangeStart && fnChangeRate);
36 pSeeking->refCount = 1;
37 pSeeking->pUserData = pUserData;
38 pSeeking->fnChangeRate = fnChangeRate;
39 pSeeking->fnChangeStop = fnChangeStop;
40 pSeeking->fnChangeStart = fnChangeStart;
41 pSeeking->dwCapabilities = AM_SEEKING_CanSeekForwards |
42 AM_SEEKING_CanSeekBackwards |
43 AM_SEEKING_CanSeekAbsolute |
44 AM_SEEKING_CanGetStopPos |
45 AM_SEEKING_CanGetDuration;
46 pSeeking->llStart = 0;
47 pSeeking->llStop = ((ULONGLONG)0x80000000) << 32;
48 pSeeking->llDuration = pSeeking->llStop - pSeeking->llStart;
49 pSeeking->dRate = 1.0;
51 return S_OK;
55 HRESULT WINAPI MediaSeekingImpl_GetCapabilities(IMediaSeeking * iface, DWORD * pCapabilities)
57 MediaSeekingImpl *This = (MediaSeekingImpl *)iface;
59 TRACE("(%p)\n", pCapabilities);
61 *pCapabilities = This->dwCapabilities;
63 return S_OK;
66 HRESULT WINAPI MediaSeekingImpl_CheckCapabilities(IMediaSeeking * iface, DWORD * pCapabilities)
68 MediaSeekingImpl *This = (MediaSeekingImpl *)iface;
69 HRESULT hr;
70 DWORD dwCommonCaps;
72 TRACE("(%p)\n", pCapabilities);
74 dwCommonCaps = *pCapabilities & This->dwCapabilities;
76 if (!dwCommonCaps)
77 hr = E_FAIL;
78 else
79 hr = (*pCapabilities == dwCommonCaps) ? S_OK : S_FALSE;
80 *pCapabilities = dwCommonCaps;
82 return hr;
85 HRESULT WINAPI MediaSeekingImpl_IsFormatSupported(IMediaSeeking * iface, const GUID * pFormat)
87 TRACE("(%s)\n", qzdebugstr_guid(pFormat));
89 return (IsEqualIID(pFormat, &TIME_FORMAT_MEDIA_TIME) ? S_OK : S_FALSE);
92 HRESULT WINAPI MediaSeekingImpl_QueryPreferredFormat(IMediaSeeking * iface, GUID * pFormat)
94 TRACE("(%s)\n", qzdebugstr_guid(pFormat));
96 *pFormat = TIME_FORMAT_MEDIA_TIME;
97 return S_OK;
100 HRESULT WINAPI MediaSeekingImpl_GetTimeFormat(IMediaSeeking * iface, GUID * pFormat)
102 TRACE("(%s)\n", qzdebugstr_guid(pFormat));
104 *pFormat = TIME_FORMAT_MEDIA_TIME;
105 return S_OK;
108 HRESULT WINAPI MediaSeekingImpl_IsUsingTimeFormat(IMediaSeeking * iface, const GUID * pFormat)
110 TRACE("(%s)\n", qzdebugstr_guid(pFormat));
112 return (IsEqualIID(pFormat, &TIME_FORMAT_MEDIA_TIME) ? S_OK : S_FALSE);
115 HRESULT WINAPI MediaSeekingImpl_SetTimeFormat(IMediaSeeking * iface, const GUID * pFormat)
117 TRACE("(%s)\n", qzdebugstr_guid(pFormat));
119 return (IsEqualIID(pFormat, &TIME_FORMAT_MEDIA_TIME) ? S_OK : S_FALSE);
122 HRESULT WINAPI MediaSeekingImpl_GetDuration(IMediaSeeking * iface, LONGLONG * pDuration)
124 MediaSeekingImpl *This = (MediaSeekingImpl *)iface;
126 TRACE("(%p)\n", pDuration);
128 *pDuration = This->llDuration;
130 return S_OK;
133 HRESULT WINAPI MediaSeekingImpl_GetStopPosition(IMediaSeeking * iface, LONGLONG * pStop)
135 MediaSeekingImpl *This = (MediaSeekingImpl *)iface;
137 TRACE("(%p)\n", pStop);
139 *pStop = This->llStop;
141 return S_OK;
144 HRESULT WINAPI MediaSeekingImpl_GetCurrentPosition(IMediaSeeking * iface, LONGLONG * pCurrent)
146 MediaSeekingImpl *This = (MediaSeekingImpl *)iface;
148 TRACE("(%p)\n", pCurrent);
150 *pCurrent = This->llStart;
152 return S_OK;
155 HRESULT WINAPI MediaSeekingImpl_ConvertTimeFormat(IMediaSeeking * iface, LONGLONG * pTarget, const GUID * pTargetFormat, LONGLONG Source, const GUID * pSourceFormat)
157 if (IsEqualIID(pTargetFormat, &TIME_FORMAT_MEDIA_TIME) && IsEqualIID(pSourceFormat, &TIME_FORMAT_MEDIA_TIME))
159 *pTarget = Source;
160 return S_OK;
162 /* FIXME: clear pTarget? */
163 return E_INVALIDARG;
166 __inline LONGLONG Adjust(LONGLONG value, LONGLONG * pModifier, DWORD dwFlags)
168 switch (dwFlags & AM_SEEKING_PositioningBitsMask)
170 case AM_SEEKING_NoPositioning:
171 return value;
172 case AM_SEEKING_AbsolutePositioning:
173 return *pModifier;
174 case AM_SEEKING_RelativePositioning:
175 case AM_SEEKING_IncrementalPositioning:
176 return value + *pModifier;
177 default:
178 assert(FALSE);
179 return 0;
183 HRESULT WINAPI MediaSeekingImpl_SetPositions(IMediaSeeking * iface, LONGLONG * pCurrent, DWORD dwCurrentFlags, LONGLONG * pStop, DWORD dwStopFlags)
185 MediaSeekingImpl *This = (MediaSeekingImpl *)iface;
186 BOOL bChangeStart = FALSE, bChangeStop = FALSE;
187 LONGLONG llNewStart, llNewStop;
189 TRACE("(%p, %lx, %p, %lx)\n", pCurrent, dwCurrentFlags, pStop, dwStopFlags);
191 llNewStart = Adjust(This->llStart, pCurrent, dwCurrentFlags);
192 llNewStop = Adjust(This->llStop, pStop, dwStopFlags);
194 if (llNewStart != This->llStart)
195 bChangeStart = TRUE;
196 if (llNewStop != This->llStop)
197 bChangeStop = TRUE;
199 This->llStart = llNewStart;
200 This->llStop = llNewStop;
202 if (dwCurrentFlags & AM_SEEKING_ReturnTime)
203 *pCurrent = llNewStart;
204 if (dwStopFlags & AM_SEEKING_ReturnTime)
205 *pStop = llNewStop;
207 if (bChangeStart)
208 This->fnChangeStart(This->pUserData);
209 if (bChangeStop)
210 This->fnChangeStop(This->pUserData);
212 return S_OK;
215 HRESULT WINAPI MediaSeekingImpl_GetPositions(IMediaSeeking * iface, LONGLONG * pCurrent, LONGLONG * pStop)
217 MediaSeekingImpl *This = (MediaSeekingImpl *)iface;
219 TRACE("(%p, %p)\n", pCurrent, pStop);
221 *pCurrent = This->llStart;
222 *pStop = This->llStop;
224 return S_OK;
227 HRESULT WINAPI MediaSeekingImpl_GetAvailable(IMediaSeeking * iface, LONGLONG * pEarliest, LONGLONG * pLatest)
229 MediaSeekingImpl *This = (MediaSeekingImpl *)iface;
231 TRACE("(%p, %p)\n", pEarliest, pLatest);
233 *pEarliest = 0;
234 *pLatest = This->llDuration;
236 return S_OK;
239 HRESULT WINAPI MediaSeekingImpl_SetRate(IMediaSeeking * iface, double dRate)
241 MediaSeekingImpl *This = (MediaSeekingImpl *)iface;
242 BOOL bChangeRate = (dRate != This->dRate);
244 TRACE("(%e)\n", dRate);
246 This->dRate = dRate;
248 if (bChangeRate)
249 return This->fnChangeRate(This->pUserData);
250 else
251 return S_OK;
254 HRESULT WINAPI MediaSeekingImpl_GetRate(IMediaSeeking * iface, double * dRate)
256 MediaSeekingImpl *This = (MediaSeekingImpl *)iface;
258 TRACE("(%p)\n", dRate);
260 *dRate = This->dRate;
262 return S_OK;
265 HRESULT WINAPI MediaSeekingImpl_GetPreroll(IMediaSeeking * iface, LONGLONG * pPreroll)
267 TRACE("(%p)\n", pPreroll);
269 *pPreroll = 0;
270 return S_OK;