[QUARTZ]
[reactos.git] / reactos / dll / directx / quartz / control.c
1 /*
2 * Filter Seeking and Control Interfaces
3 *
4 * Copyright 2003 Robert Shearman
5 *
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.
10 *
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.
15 *
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20 /* FIXME: critical sections */
21
22 #include "quartz_private.h"
23 #include "control_private.h"
24
25 #include "uuids.h"
26 #include "wine/debug.h"
27
28 #include <assert.h>
29
30 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
31
32 static const IMediaSeekingVtbl IMediaSeekingPassThru_Vtbl;
33
34 typedef struct PassThruImpl {
35 const ISeekingPassThruVtbl *IPassThru_vtbl;
36 const IUnknownVtbl *IInner_vtbl;
37 const IMediaSeekingVtbl *IMediaSeeking_vtbl;
38
39 LONG ref;
40 IUnknown * pUnkOuter;
41 IPin * pin;
42 BOOL bUnkOuterValid;
43 BOOL bAggregatable;
44 BOOL renderer;
45 } PassThruImpl;
46
47 static HRESULT WINAPI SeekInner_QueryInterface(IUnknown * iface,
48 REFIID riid,
49 LPVOID *ppvObj) {
50 ICOM_THIS_MULTI(PassThruImpl, IInner_vtbl, iface);
51 TRACE("(%p)->(%s (%p), %p)\n", This, debugstr_guid(riid), riid, ppvObj);
52
53 if (This->bAggregatable)
54 This->bUnkOuterValid = TRUE;
55
56 if (IsEqualGUID(&IID_IUnknown, riid))
57 {
58 *ppvObj = &(This->IInner_vtbl);
59 TRACE(" returning IUnknown interface (%p)\n", *ppvObj);
60 } else if (IsEqualGUID(&IID_ISeekingPassThru, riid)) {
61 *ppvObj = &(This->IPassThru_vtbl);
62 TRACE(" returning ISeekingPassThru interface (%p)\n", *ppvObj);
63 } else if (IsEqualGUID(&IID_IMediaSeeking, riid)) {
64 *ppvObj = &(This->IMediaSeeking_vtbl);
65 TRACE(" returning IMediaSeeking interface (%p)\n", *ppvObj);
66 } else {
67 *ppvObj = NULL;
68 FIXME("unknown interface %s\n", debugstr_guid(riid));
69 return E_NOINTERFACE;
70 }
71
72 IUnknown_AddRef((IUnknown *)(*ppvObj));
73 return S_OK;
74 }
75
76 static ULONG WINAPI SeekInner_AddRef(IUnknown * iface) {
77 ICOM_THIS_MULTI(PassThruImpl, IInner_vtbl, iface);
78 ULONG ref = InterlockedIncrement(&This->ref);
79
80 TRACE("(%p)->(): new ref = %d\n", This, ref);
81
82 return ref;
83 }
84
85 static ULONG WINAPI SeekInner_Release(IUnknown * iface) {
86 ICOM_THIS_MULTI(PassThruImpl, IInner_vtbl, iface);
87 ULONG ref = InterlockedDecrement(&This->ref);
88
89 TRACE("(%p)->(): new ref = %d\n", This, ref);
90
91 if (ref == 0)
92 {
93 CoTaskMemFree(This);
94 }
95 return ref;
96 }
97
98 static const IUnknownVtbl IInner_VTable =
99 {
100 SeekInner_QueryInterface,
101 SeekInner_AddRef,
102 SeekInner_Release
103 };
104
105 /* Generic functions for aggregation */
106 static HRESULT SeekOuter_QueryInterface(PassThruImpl *This, REFIID riid, LPVOID *ppv)
107 {
108 if (This->bAggregatable)
109 This->bUnkOuterValid = TRUE;
110
111 if (This->pUnkOuter)
112 {
113 if (This->bAggregatable)
114 return IUnknown_QueryInterface(This->pUnkOuter, riid, ppv);
115
116 if (IsEqualIID(riid, &IID_IUnknown))
117 {
118 HRESULT hr;
119
120 IUnknown_AddRef((IUnknown *)&(This->IInner_vtbl));
121 hr = IUnknown_QueryInterface((IUnknown *)&(This->IInner_vtbl), riid, ppv);
122 IUnknown_Release((IUnknown *)&(This->IInner_vtbl));
123 This->bAggregatable = TRUE;
124 return hr;
125 }
126
127 *ppv = NULL;
128 return E_NOINTERFACE;
129 }
130
131 return IUnknown_QueryInterface((IUnknown *)&(This->IInner_vtbl), riid, ppv);
132 }
133
134 static ULONG SeekOuter_AddRef(PassThruImpl *This)
135 {
136 if (This->pUnkOuter && This->bUnkOuterValid)
137 return IUnknown_AddRef(This->pUnkOuter);
138 return IUnknown_AddRef((IUnknown *)&(This->IInner_vtbl));
139 }
140
141 static ULONG SeekOuter_Release(PassThruImpl *This)
142 {
143 if (This->pUnkOuter && This->bUnkOuterValid)
144 return IUnknown_Release(This->pUnkOuter);
145 return IUnknown_Release((IUnknown *)&(This->IInner_vtbl));
146 }
147
148 static HRESULT WINAPI SeekingPassThru_QueryInterface(ISeekingPassThru *iface, REFIID riid, LPVOID *ppvObj)
149 {
150 ICOM_THIS_MULTI(PassThruImpl, IPassThru_vtbl, iface);
151
152 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
153
154 return SeekOuter_QueryInterface(This, riid, ppvObj);
155 }
156
157 static ULONG WINAPI SeekingPassThru_AddRef(ISeekingPassThru *iface)
158 {
159 ICOM_THIS_MULTI(PassThruImpl, IPassThru_vtbl, iface);
160
161 TRACE("(%p/%p)->()\n", This, iface);
162
163 return SeekOuter_AddRef(This);
164 }
165
166 static ULONG WINAPI SeekingPassThru_Release(ISeekingPassThru *iface)
167 {
168 ICOM_THIS_MULTI(PassThruImpl, IPassThru_vtbl, iface);
169
170 TRACE("(%p/%p)->()\n", This, iface);
171
172 return SeekOuter_Release(This);
173 }
174
175 static HRESULT WINAPI SeekingPassThru_Init(ISeekingPassThru *iface, BOOL renderer, IPin *pin)
176 {
177 ICOM_THIS_MULTI(PassThruImpl, IPassThru_vtbl, iface);
178
179 TRACE("(%p/%p)->(%d, %p)\n", This, iface, renderer, pin);
180
181 if (This->pin)
182 FIXME("Re-initializing?\n");
183
184 This->renderer = renderer;
185 This->pin = pin;
186
187 return S_OK;
188 }
189
190 static const ISeekingPassThruVtbl ISeekingPassThru_Vtbl =
191 {
192 SeekingPassThru_QueryInterface,
193 SeekingPassThru_AddRef,
194 SeekingPassThru_Release,
195 SeekingPassThru_Init
196 };
197
198 HRESULT SeekingPassThru_create(IUnknown *pUnkOuter, LPVOID *ppObj)
199 {
200 PassThruImpl *fimpl;
201
202 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
203
204 *ppObj = fimpl = CoTaskMemAlloc(sizeof(*fimpl));
205 if (!fimpl)
206 return E_OUTOFMEMORY;
207
208 fimpl->pUnkOuter = pUnkOuter;
209 fimpl->bUnkOuterValid = FALSE;
210 fimpl->bAggregatable = FALSE;
211 fimpl->IInner_vtbl = &IInner_VTable;
212 fimpl->IPassThru_vtbl = &ISeekingPassThru_Vtbl;
213 fimpl->IMediaSeeking_vtbl = &IMediaSeekingPassThru_Vtbl;
214 fimpl->ref = 1;
215 fimpl->pin = NULL;
216 return S_OK;
217 }
218
219 typedef HRESULT (*SeekFunc)( IMediaSeeking *to, LPVOID arg );
220
221 static HRESULT ForwardCmdSeek( PCRITICAL_SECTION crit_sect, IBaseFilter* from, SeekFunc fnSeek, LPVOID arg )
222 {
223 HRESULT hr = S_OK;
224 HRESULT hr_return = S_OK;
225 IEnumPins *enumpins = NULL;
226 BOOL foundend = FALSE, allnotimpl = TRUE;
227
228 hr = IBaseFilter_EnumPins( from, &enumpins );
229 if (FAILED(hr))
230 goto out;
231
232 hr = IEnumPins_Reset( enumpins );
233 while (hr == S_OK) {
234 IPin *pin = NULL;
235 hr = IEnumPins_Next( enumpins, 1, &pin, NULL );
236 if (hr == VFW_E_ENUM_OUT_OF_SYNC)
237 {
238 hr = IEnumPins_Reset( enumpins );
239 continue;
240 }
241 if (pin)
242 {
243 PIN_DIRECTION dir;
244
245 IPin_QueryDirection( pin, &dir );
246 if (dir == PINDIR_INPUT)
247 {
248 IPin *connected = NULL;
249
250 IPin_ConnectedTo( pin, &connected );
251 if (connected)
252 {
253 HRESULT hr_local;
254 IMediaSeeking *seek = NULL;
255
256 hr_local = IPin_QueryInterface( connected, &IID_IMediaSeeking, (void**)&seek );
257 if (hr_local == S_OK)
258 {
259 foundend = TRUE;
260 if (crit_sect)
261 {
262 LeaveCriticalSection( crit_sect );
263 hr_local = fnSeek( seek , arg );
264 EnterCriticalSection( crit_sect );
265 }
266 else
267 hr_local = fnSeek( seek , arg );
268
269 if (hr_local != E_NOTIMPL)
270 allnotimpl = FALSE;
271
272 hr_return = updatehres( hr_return, hr_local );
273 IMediaSeeking_Release( seek );
274 }
275 IPin_Release(connected);
276 }
277 }
278 IPin_Release( pin );
279 }
280 }
281 IEnumPins_Release( enumpins );
282
283 if (foundend && allnotimpl)
284 hr = E_NOTIMPL;
285 else
286 hr = hr_return;
287
288 out:
289 TRACE("Returning: %08x\n", hr);
290 return hr;
291 }
292
293
294 HRESULT MediaSeekingImpl_Init(IBaseFilter *pUserData, CHANGEPROC fnChangeStop, CHANGEPROC fnChangeCurrent, CHANGEPROC fnChangeRate, MediaSeekingImpl * pSeeking, PCRITICAL_SECTION crit_sect)
295 {
296 assert(fnChangeStop && fnChangeCurrent && fnChangeRate);
297
298 pSeeking->refCount = 1;
299 pSeeking->pUserData = pUserData;
300 pSeeking->fnChangeRate = fnChangeRate;
301 pSeeking->fnChangeStop = fnChangeStop;
302 pSeeking->fnChangeCurrent = fnChangeCurrent;
303 pSeeking->dwCapabilities = AM_SEEKING_CanSeekForwards |
304 AM_SEEKING_CanSeekBackwards |
305 AM_SEEKING_CanSeekAbsolute |
306 AM_SEEKING_CanGetStopPos |
307 AM_SEEKING_CanGetDuration;
308 pSeeking->llCurrent = 0;
309 pSeeking->llStop = ((ULONGLONG)0x80000000) << 32;
310 pSeeking->llDuration = pSeeking->llStop;
311 pSeeking->dRate = 1.0;
312 pSeeking->timeformat = TIME_FORMAT_MEDIA_TIME;
313 pSeeking->crst = crit_sect;
314
315 return S_OK;
316 }
317
318 struct pos_args {
319 LONGLONG* current, *stop;
320 DWORD curflags, stopflags;
321 };
322
323 static HRESULT fwd_setposition(IMediaSeeking *seek, LPVOID pargs)
324 {
325 struct pos_args *args = (void*)pargs;
326
327 return IMediaSeeking_SetPositions(seek, args->current, args->curflags, args->stop, args->stopflags);
328 }
329
330 static HRESULT fwd_checkcaps(IMediaSeeking *iface, LPVOID pcaps)
331 {
332 DWORD *caps = pcaps;
333 return IMediaSeeking_CheckCapabilities(iface, caps);
334 }
335
336 static HRESULT fwd_settimeformat(IMediaSeeking *iface, LPVOID pformat)
337 {
338 const GUID *format = pformat;
339 return IMediaSeeking_SetTimeFormat(iface, format);
340 }
341
342 static HRESULT fwd_getduration(IMediaSeeking *iface, LPVOID pdur)
343 {
344 LONGLONG *duration = pdur;
345 LONGLONG mydur = *duration;
346 HRESULT hr;
347
348 hr = IMediaSeeking_GetDuration(iface, &mydur);
349 if (FAILED(hr))
350 return hr;
351
352 if ((mydur < *duration) || (*duration < 0 && mydur > 0))
353 *duration = mydur;
354 return hr;
355 }
356
357 static HRESULT fwd_getstopposition(IMediaSeeking *iface, LPVOID pdur)
358 {
359 LONGLONG *duration = pdur;
360 LONGLONG mydur = *duration;
361 HRESULT hr;
362
363 hr = IMediaSeeking_GetStopPosition(iface, &mydur);
364 if (FAILED(hr))
365 return hr;
366
367 if ((mydur < *duration) || (*duration < 0 && mydur > 0))
368 *duration = mydur;
369 return hr;
370 }
371
372 static HRESULT fwd_getcurposition(IMediaSeeking *iface, LPVOID pdur)
373 {
374 LONGLONG *duration = pdur;
375 LONGLONG mydur = *duration;
376 HRESULT hr;
377
378 hr = IMediaSeeking_GetCurrentPosition(iface, &mydur);
379 if (FAILED(hr))
380 return hr;
381
382 if ((mydur < *duration) || (*duration < 0 && mydur > 0))
383 *duration = mydur;
384 return hr;
385 }
386
387 static HRESULT fwd_setrate(IMediaSeeking *iface, LPVOID prate)
388 {
389 double *rate = prate;
390
391 HRESULT hr;
392
393 hr = IMediaSeeking_SetRate(iface, *rate);
394 if (FAILED(hr))
395 return hr;
396
397 return hr;
398 }
399
400
401 HRESULT WINAPI MediaSeekingImpl_GetCapabilities(IMediaSeeking * iface, DWORD * pCapabilities)
402 {
403 MediaSeekingImpl *This = (MediaSeekingImpl *)iface;
404
405 TRACE("(%p)\n", pCapabilities);
406
407 *pCapabilities = This->dwCapabilities;
408
409 return S_OK;
410 }
411
412 HRESULT WINAPI MediaSeekingImpl_CheckCapabilities(IMediaSeeking * iface, DWORD * pCapabilities)
413 {
414 MediaSeekingImpl *This = (MediaSeekingImpl *)iface;
415 HRESULT hr;
416 DWORD dwCommonCaps;
417
418 TRACE("(%p)\n", pCapabilities);
419
420 if (!pCapabilities)
421 return E_POINTER;
422
423 EnterCriticalSection(This->crst);
424 hr = ForwardCmdSeek(This->crst, This->pUserData, fwd_checkcaps, pCapabilities);
425 LeaveCriticalSection(This->crst);
426 if (FAILED(hr) && hr != E_NOTIMPL)
427 return hr;
428
429 dwCommonCaps = *pCapabilities & This->dwCapabilities;
430
431 if (!dwCommonCaps)
432 hr = E_FAIL;
433 else
434 hr = (*pCapabilities == dwCommonCaps) ? S_OK : S_FALSE;
435 *pCapabilities = dwCommonCaps;
436
437 return hr;
438 }
439
440 HRESULT WINAPI MediaSeekingImpl_IsFormatSupported(IMediaSeeking * iface, const GUID * pFormat)
441 {
442 TRACE("(%s)\n", qzdebugstr_guid(pFormat));
443
444 return (IsEqualIID(pFormat, &TIME_FORMAT_MEDIA_TIME) ? S_OK : S_FALSE);
445 }
446
447 HRESULT WINAPI MediaSeekingImpl_QueryPreferredFormat(IMediaSeeking * iface, GUID * pFormat)
448 {
449 TRACE("(%s)\n", qzdebugstr_guid(pFormat));
450
451 *pFormat = TIME_FORMAT_MEDIA_TIME;
452 return S_OK;
453 }
454
455 HRESULT WINAPI MediaSeekingImpl_GetTimeFormat(IMediaSeeking * iface, GUID * pFormat)
456 {
457 MediaSeekingImpl *This = (MediaSeekingImpl *)iface;
458 TRACE("(%s)\n", qzdebugstr_guid(pFormat));
459
460 EnterCriticalSection(This->crst);
461 *pFormat = This->timeformat;
462 LeaveCriticalSection(This->crst);
463
464 return S_OK;
465 }
466
467 HRESULT WINAPI MediaSeekingImpl_IsUsingTimeFormat(IMediaSeeking * iface, const GUID * pFormat)
468 {
469 MediaSeekingImpl *This = (MediaSeekingImpl *)iface;
470 HRESULT hr = S_OK;
471
472 TRACE("(%s)\n", qzdebugstr_guid(pFormat));
473
474 EnterCriticalSection(This->crst);
475 if (!IsEqualIID(pFormat, &This->timeformat))
476 hr = S_FALSE;
477 LeaveCriticalSection(This->crst);
478
479 return hr;
480 }
481
482
483 HRESULT WINAPI MediaSeekingImpl_SetTimeFormat(IMediaSeeking * iface, const GUID * pFormat)
484 {
485 MediaSeekingImpl *This = (MediaSeekingImpl *)iface;
486 TRACE("(%s)\n", qzdebugstr_guid(pFormat));
487
488 EnterCriticalSection(This->crst);
489 ForwardCmdSeek(This->crst, This->pUserData, fwd_settimeformat, (LPVOID)pFormat);
490 LeaveCriticalSection(This->crst);
491
492 return (IsEqualIID(pFormat, &TIME_FORMAT_MEDIA_TIME) ? S_OK : S_FALSE);
493 }
494
495
496 HRESULT WINAPI MediaSeekingImpl_GetDuration(IMediaSeeking * iface, LONGLONG * pDuration)
497 {
498 MediaSeekingImpl *This = (MediaSeekingImpl *)iface;
499
500 TRACE("(%p)\n", pDuration);
501
502 EnterCriticalSection(This->crst);
503 *pDuration = This->llDuration;
504 ForwardCmdSeek(This->crst, This->pUserData, fwd_getduration, pDuration);
505 LeaveCriticalSection(This->crst);
506
507 return S_OK;
508 }
509
510 HRESULT WINAPI MediaSeekingImpl_GetStopPosition(IMediaSeeking * iface, LONGLONG * pStop)
511 {
512 MediaSeekingImpl *This = (MediaSeekingImpl *)iface;
513
514 TRACE("(%p)\n", pStop);
515
516 EnterCriticalSection(This->crst);
517 *pStop = This->llStop;
518 ForwardCmdSeek(This->crst, This->pUserData, fwd_getstopposition, pStop);
519 LeaveCriticalSection(This->crst);
520
521 return S_OK;
522 }
523
524 /* FIXME: Make use of the info the filter should expose */
525 HRESULT WINAPI MediaSeekingImpl_GetCurrentPosition(IMediaSeeking * iface, LONGLONG * pCurrent)
526 {
527 MediaSeekingImpl *This = (MediaSeekingImpl *)iface;
528
529 TRACE("(%p)\n", pCurrent);
530
531 EnterCriticalSection(This->crst);
532 *pCurrent = This->llCurrent;
533 ForwardCmdSeek(This->crst, This->pUserData, fwd_getcurposition, pCurrent);
534 LeaveCriticalSection(This->crst);
535
536 return S_OK;
537 }
538
539 HRESULT WINAPI MediaSeekingImpl_ConvertTimeFormat(IMediaSeeking * iface, LONGLONG * pTarget, const GUID * pTargetFormat, LONGLONG Source, const GUID * pSourceFormat)
540 {
541 if (IsEqualIID(pTargetFormat, &TIME_FORMAT_MEDIA_TIME) && IsEqualIID(pSourceFormat, &TIME_FORMAT_MEDIA_TIME))
542 {
543 *pTarget = Source;
544 return S_OK;
545 }
546 /* FIXME: clear pTarget? */
547 return E_INVALIDARG;
548 }
549
550 static inline LONGLONG Adjust(LONGLONG value, const LONGLONG * pModifier, DWORD dwFlags)
551 {
552 switch (dwFlags & AM_SEEKING_PositioningBitsMask)
553 {
554 case AM_SEEKING_NoPositioning:
555 return value;
556 case AM_SEEKING_AbsolutePositioning:
557 return *pModifier;
558 case AM_SEEKING_RelativePositioning:
559 case AM_SEEKING_IncrementalPositioning:
560 return value + *pModifier;
561 default:
562 assert(FALSE);
563 return 0;
564 }
565 }
566
567 HRESULT WINAPI MediaSeekingImpl_SetPositions(IMediaSeeking * iface, LONGLONG * pCurrent, DWORD dwCurrentFlags, LONGLONG * pStop, DWORD dwStopFlags)
568 {
569 MediaSeekingImpl *This = (MediaSeekingImpl *)iface;
570 BOOL bChangeCurrent = FALSE, bChangeStop = FALSE;
571 LONGLONG llNewCurrent, llNewStop;
572 struct pos_args args;
573
574 TRACE("(%p, %x, %p, %x)\n", pCurrent, dwCurrentFlags, pStop, dwStopFlags);
575
576 args.current = pCurrent;
577 args.stop = pStop;
578 args.curflags = dwCurrentFlags;
579 args.stopflags = dwStopFlags;
580
581 EnterCriticalSection(This->crst);
582
583 llNewCurrent = Adjust(This->llCurrent, pCurrent, dwCurrentFlags);
584 llNewStop = Adjust(This->llStop, pStop, dwStopFlags);
585
586 if (pCurrent)
587 bChangeCurrent = TRUE;
588 if (llNewStop != This->llStop)
589 bChangeStop = TRUE;
590
591 TRACE("Old: %u, New: %u\n", (DWORD)(This->llCurrent/10000000), (DWORD)(llNewCurrent/10000000));
592
593 This->llCurrent = llNewCurrent;
594 This->llStop = llNewStop;
595
596 if (pCurrent && (dwCurrentFlags & AM_SEEKING_ReturnTime))
597 *pCurrent = llNewCurrent;
598 if (pStop && (dwStopFlags & AM_SEEKING_ReturnTime))
599 *pStop = llNewStop;
600
601 ForwardCmdSeek(This->crst, This->pUserData, fwd_setposition, &args);
602 LeaveCriticalSection(This->crst);
603
604 if (bChangeCurrent)
605 This->fnChangeCurrent(This->pUserData);
606 if (bChangeStop)
607 This->fnChangeStop(This->pUserData);
608
609 return S_OK;
610 }
611
612 HRESULT WINAPI MediaSeekingImpl_GetPositions(IMediaSeeking * iface, LONGLONG * pCurrent, LONGLONG * pStop)
613 {
614 MediaSeekingImpl *This = (MediaSeekingImpl *)iface;
615
616 TRACE("(%p, %p)\n", pCurrent, pStop);
617
618 EnterCriticalSection(This->crst);
619 *pCurrent = This->llCurrent;
620 *pStop = This->llStop;
621 LeaveCriticalSection(This->crst);
622
623 return S_OK;
624 }
625
626 HRESULT WINAPI MediaSeekingImpl_GetAvailable(IMediaSeeking * iface, LONGLONG * pEarliest, LONGLONG * pLatest)
627 {
628 MediaSeekingImpl *This = (MediaSeekingImpl *)iface;
629
630 TRACE("(%p, %p)\n", pEarliest, pLatest);
631
632 EnterCriticalSection(This->crst);
633 *pEarliest = 0;
634 *pLatest = This->llDuration;
635 LeaveCriticalSection(This->crst);
636
637 return S_OK;
638 }
639
640 HRESULT WINAPI MediaSeekingImpl_SetRate(IMediaSeeking * iface, double dRate)
641 {
642 MediaSeekingImpl *This = (MediaSeekingImpl *)iface;
643 BOOL bChangeRate = (dRate != This->dRate);
644 HRESULT hr = S_OK;
645
646 TRACE("(%e)\n", dRate);
647
648 if (dRate > 100 || dRate < .001)
649 {
650 FIXME("Excessive rate %e, ignoring\n", dRate);
651 return VFW_E_UNSUPPORTED_AUDIO;
652 }
653
654 EnterCriticalSection(This->crst);
655 This->dRate = dRate;
656 if (bChangeRate)
657 hr = This->fnChangeRate(This->pUserData);
658 ForwardCmdSeek(This->crst, This->pUserData, fwd_setrate, &dRate);
659 LeaveCriticalSection(This->crst);
660
661 return hr;
662 }
663
664 HRESULT WINAPI MediaSeekingImpl_GetRate(IMediaSeeking * iface, double * dRate)
665 {
666 MediaSeekingImpl *This = (MediaSeekingImpl *)iface;
667
668 TRACE("(%p)\n", dRate);
669
670 EnterCriticalSection(This->crst);
671 /* Forward? */
672 *dRate = This->dRate;
673 LeaveCriticalSection(This->crst);
674
675 return S_OK;
676 }
677
678 HRESULT WINAPI MediaSeekingImpl_GetPreroll(IMediaSeeking * iface, LONGLONG * pPreroll)
679 {
680 TRACE("(%p)\n", pPreroll);
681
682 *pPreroll = 0;
683 return S_OK;
684 }
685
686 static HRESULT WINAPI MediaSeekingPassThru_QueryInterface(IMediaSeeking *iface, REFIID riid, LPVOID *ppvObj)
687 {
688 ICOM_THIS_MULTI(PassThruImpl, IMediaSeeking_vtbl, iface);
689
690 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
691
692 return SeekOuter_QueryInterface(This, riid, ppvObj);
693 }
694
695 static ULONG WINAPI MediaSeekingPassThru_AddRef(IMediaSeeking *iface)
696 {
697 ICOM_THIS_MULTI(PassThruImpl, IMediaSeeking_vtbl, iface);
698
699 TRACE("(%p/%p)->()\n", iface, This);
700
701 return SeekOuter_AddRef(This);
702 }
703
704 static ULONG WINAPI MediaSeekingPassThru_Release(IMediaSeeking *iface)
705 {
706 ICOM_THIS_MULTI(PassThruImpl, IMediaSeeking_vtbl, iface);
707
708 TRACE("(%p/%p)->()\n", iface, This);
709
710 return SeekOuter_Release(This);
711 }
712
713 static HRESULT WINAPI MediaSeekingPassThru_GetCapabilities(IMediaSeeking * iface, DWORD * pCapabilities)
714 {
715 ICOM_THIS_MULTI(PassThruImpl, IMediaSeeking_vtbl, iface);
716
717 TRACE("(%p/%p)->(%p)\n", iface, This, pCapabilities);
718
719 FIXME("stub\n");
720 return E_NOTIMPL;
721 }
722
723 static HRESULT WINAPI MediaSeekingPassThru_CheckCapabilities(IMediaSeeking * iface, DWORD * pCapabilities)
724 {
725 ICOM_THIS_MULTI(PassThruImpl, IMediaSeeking_vtbl, iface);
726
727 TRACE("(%p/%p)->(%p)\n", iface, This, pCapabilities);
728
729 if (!pCapabilities)
730 return E_POINTER;
731
732 FIXME("stub\n");
733 return E_NOTIMPL;
734 }
735
736 static HRESULT WINAPI MediaSeekingPassThru_IsFormatSupported(IMediaSeeking * iface, const GUID * pFormat)
737 {
738 ICOM_THIS_MULTI(PassThruImpl, IMediaSeeking_vtbl, iface);
739 TRACE("(%p/%p)->(%s)\n", iface, This, qzdebugstr_guid(pFormat));
740
741 FIXME("stub\n");
742 return E_NOTIMPL;
743 }
744
745 static HRESULT WINAPI MediaSeekingPassThru_QueryPreferredFormat(IMediaSeeking * iface, GUID * pFormat)
746 {
747 ICOM_THIS_MULTI(PassThruImpl, IMediaSeeking_vtbl, iface);
748 TRACE("(%p/%p)->(%p)\n", iface, This, pFormat);
749
750 FIXME("stub\n");
751 return E_NOTIMPL;
752 }
753
754 static HRESULT WINAPI MediaSeekingPassThru_GetTimeFormat(IMediaSeeking * iface, GUID * pFormat)
755 {
756 ICOM_THIS_MULTI(PassThruImpl, IMediaSeeking_vtbl, iface);
757 TRACE("(%p/%p)->(%p)\n", iface, This, pFormat);
758
759 FIXME("stub\n");
760 return E_NOTIMPL;
761 }
762
763 static HRESULT WINAPI MediaSeekingPassThru_IsUsingTimeFormat(IMediaSeeking * iface, const GUID * pFormat)
764 {
765 ICOM_THIS_MULTI(PassThruImpl, IMediaSeeking_vtbl, iface);
766
767 TRACE("(%p/%p)->(%s)\n", iface, This, qzdebugstr_guid(pFormat));
768
769 FIXME("stub\n");
770 return E_NOTIMPL;
771 }
772
773
774 static HRESULT WINAPI MediaSeekingPassThru_SetTimeFormat(IMediaSeeking * iface, const GUID * pFormat)
775 {
776 ICOM_THIS_MULTI(PassThruImpl, IMediaSeeking_vtbl, iface);
777 TRACE("(%p/%p)->(%s)\n", iface, This, qzdebugstr_guid(pFormat));
778
779 FIXME("stub\n");
780 return E_NOTIMPL;
781 }
782
783
784 static HRESULT WINAPI MediaSeekingPassThru_GetDuration(IMediaSeeking * iface, LONGLONG * pDuration)
785 {
786 ICOM_THIS_MULTI(PassThruImpl, IMediaSeeking_vtbl, iface);
787 PIN_INFO info;
788 HRESULT hr;
789
790 TRACE("(%p/%p)->(%p)\n", iface, This, pDuration);
791
792 IPin_QueryPinInfo(This->pin, &info);
793
794 hr = ForwardCmdSeek(NULL, info.pFilter, fwd_getduration, pDuration);
795 IBaseFilter_Release(info.pFilter);
796
797 return hr;
798 }
799
800 static HRESULT WINAPI MediaSeekingPassThru_GetStopPosition(IMediaSeeking * iface, LONGLONG * pStop)
801 {
802 ICOM_THIS_MULTI(PassThruImpl, IMediaSeeking_vtbl, iface);
803
804 TRACE("(%p/%p)->(%p)\n", iface, This, pStop);
805
806 FIXME("stub\n");
807 return E_NOTIMPL;
808 }
809
810 /* FIXME: Make use of the info the filter should expose */
811 static HRESULT WINAPI MediaSeekingPassThru_GetCurrentPosition(IMediaSeeking * iface, LONGLONG * pCurrent)
812 {
813 ICOM_THIS_MULTI(PassThruImpl, IMediaSeeking_vtbl, iface);
814
815 TRACE("(%p/%p)->(%p)\n", iface, This, pCurrent);
816
817 FIXME("stub\n");
818 return E_NOTIMPL;
819 }
820
821 static HRESULT WINAPI MediaSeekingPassThru_ConvertTimeFormat(IMediaSeeking * iface, LONGLONG * pTarget, const GUID * pTargetFormat, LONGLONG Source, const GUID * pSourceFormat)
822 {
823 ICOM_THIS_MULTI(PassThruImpl, IMediaSeeking_vtbl, iface);
824
825 TRACE("(%p/%p)->(%p,%s,%x%08x,%s)\n", iface, This, pTarget, debugstr_guid(pTargetFormat), (DWORD)(Source>>32), (DWORD)Source, debugstr_guid(pSourceFormat));
826
827 FIXME("stub\n");
828 return E_NOTIMPL;
829 }
830
831 static HRESULT WINAPI MediaSeekingPassThru_SetPositions(IMediaSeeking * iface, LONGLONG * pCurrent, DWORD dwCurrentFlags, LONGLONG * pStop, DWORD dwStopFlags)
832 {
833 ICOM_THIS_MULTI(PassThruImpl, IMediaSeeking_vtbl, iface);
834 struct pos_args args;
835 PIN_INFO info;
836 HRESULT hr;
837
838 TRACE("(%p/%p)->(%p, %p)\n", iface, This, pCurrent, pStop);
839 args.current = pCurrent;
840 args.stop = pStop;
841 args.curflags = dwCurrentFlags;
842 args.stopflags = dwStopFlags;
843
844 IPin_QueryPinInfo(This->pin, &info);
845
846 hr = ForwardCmdSeek(NULL, info.pFilter, fwd_setposition, &args);
847 IBaseFilter_Release(info.pFilter);
848 return hr;
849 }
850
851 static HRESULT WINAPI MediaSeekingPassThru_GetPositions(IMediaSeeking * iface, LONGLONG * pCurrent, LONGLONG * pStop)
852 {
853 ICOM_THIS_MULTI(PassThruImpl, IMediaSeeking_vtbl, iface);
854
855 TRACE("(%p/%p)->(%p, %p)\n", iface, This, pCurrent, pStop);
856
857 FIXME("stub\n");
858 return E_NOTIMPL;
859 }
860
861 static HRESULT WINAPI MediaSeekingPassThru_GetAvailable(IMediaSeeking * iface, LONGLONG * pEarliest, LONGLONG * pLatest)
862 {
863 ICOM_THIS_MULTI(PassThruImpl, IMediaSeeking_vtbl, iface);
864
865 TRACE("(%p/%p)->(%p,%p)\n", iface, This, pEarliest, pLatest);
866
867 FIXME("stub\n");
868 return E_NOTIMPL;
869 }
870
871 static HRESULT WINAPI MediaSeekingPassThru_SetRate(IMediaSeeking * iface, double dRate)
872 {
873 ICOM_THIS_MULTI(PassThruImpl, IMediaSeeking_vtbl, iface);
874
875 TRACE("(%p/%p)->(%e)\n", iface, This, dRate);
876
877 FIXME("stub\n");
878 return E_NOTIMPL;
879 }
880
881 static HRESULT WINAPI MediaSeekingPassThru_GetRate(IMediaSeeking * iface, double * dRate)
882 {
883 ICOM_THIS_MULTI(PassThruImpl, IMediaSeeking_vtbl, iface);
884
885 TRACE("(%p/%p)->(%p)\n", iface, This, dRate);
886
887 FIXME("stub\n");
888 return E_NOTIMPL;
889 }
890
891 static HRESULT WINAPI MediaSeekingPassThru_GetPreroll(IMediaSeeking * iface, LONGLONG * pPreroll)
892 {
893 TRACE("(%p)\n", pPreroll);
894
895 FIXME("stub\n");
896 return E_NOTIMPL;
897 }
898
899 static const IMediaSeekingVtbl IMediaSeekingPassThru_Vtbl =
900 {
901 MediaSeekingPassThru_QueryInterface,
902 MediaSeekingPassThru_AddRef,
903 MediaSeekingPassThru_Release,
904 MediaSeekingPassThru_GetCapabilities,
905 MediaSeekingPassThru_CheckCapabilities,
906 MediaSeekingPassThru_IsFormatSupported,
907 MediaSeekingPassThru_QueryPreferredFormat,
908 MediaSeekingPassThru_GetTimeFormat,
909 MediaSeekingPassThru_IsUsingTimeFormat,
910 MediaSeekingPassThru_SetTimeFormat,
911 MediaSeekingPassThru_GetDuration,
912 MediaSeekingPassThru_GetStopPosition,
913 MediaSeekingPassThru_GetCurrentPosition,
914 MediaSeekingPassThru_ConvertTimeFormat,
915 MediaSeekingPassThru_SetPositions,
916 MediaSeekingPassThru_GetPositions,
917 MediaSeekingPassThru_GetAvailable,
918 MediaSeekingPassThru_SetRate,
919 MediaSeekingPassThru_GetRate,
920 MediaSeekingPassThru_GetPreroll
921 };