Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/libs/strmbase/seeking.c
4388 views
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
22
#include "strmbase_private.h"
23
24
WINE_DEFAULT_DEBUG_CHANNEL(quartz);
25
26
static inline SourceSeeking *impl_from_IMediaSeeking(IMediaSeeking *iface)
27
{
28
return CONTAINING_RECORD(iface, SourceSeeking, IMediaSeeking_iface);
29
}
30
31
HRESULT strmbase_seeking_init(SourceSeeking *pSeeking, const IMediaSeekingVtbl *Vtbl,
32
SourceSeeking_ChangeStop fnChangeStop, SourceSeeking_ChangeStart fnChangeStart,
33
SourceSeeking_ChangeRate fnChangeRate)
34
{
35
assert(fnChangeStop && fnChangeStart && fnChangeRate);
36
37
pSeeking->IMediaSeeking_iface.lpVtbl = Vtbl;
38
pSeeking->refCount = 1;
39
pSeeking->fnChangeRate = fnChangeRate;
40
pSeeking->fnChangeStop = fnChangeStop;
41
pSeeking->fnChangeStart = fnChangeStart;
42
pSeeking->dwCapabilities = AM_SEEKING_CanSeekForwards |
43
AM_SEEKING_CanSeekBackwards |
44
AM_SEEKING_CanSeekAbsolute |
45
AM_SEEKING_CanGetStopPos |
46
AM_SEEKING_CanGetDuration;
47
pSeeking->llCurrent = 0;
48
pSeeking->llStop = ((ULONGLONG)0x80000000) << 32;
49
pSeeking->llDuration = pSeeking->llStop;
50
pSeeking->dRate = 1.0;
51
pSeeking->timeformat = TIME_FORMAT_MEDIA_TIME;
52
if (!InitializeCriticalSectionEx(&pSeeking->cs, 0, RTL_CRITICAL_SECTION_FLAG_FORCE_DEBUG_INFO))
53
InitializeCriticalSection(&pSeeking->cs);
54
pSeeking->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": SourceSeeking.cs");
55
return S_OK;
56
}
57
58
void strmbase_seeking_cleanup(SourceSeeking *seeking)
59
{
60
seeking->cs.DebugInfo->Spare[0] = 0;
61
DeleteCriticalSection(&seeking->cs);
62
}
63
64
HRESULT WINAPI SourceSeekingImpl_GetCapabilities(IMediaSeeking * iface, DWORD * pCapabilities)
65
{
66
SourceSeeking *This = impl_from_IMediaSeeking(iface);
67
68
TRACE("(%p)\n", pCapabilities);
69
70
*pCapabilities = This->dwCapabilities;
71
72
return S_OK;
73
}
74
75
HRESULT WINAPI SourceSeekingImpl_CheckCapabilities(IMediaSeeking * iface, DWORD * pCapabilities)
76
{
77
SourceSeeking *This = impl_from_IMediaSeeking(iface);
78
HRESULT hr;
79
DWORD dwCommonCaps;
80
81
TRACE("(%p)\n", pCapabilities);
82
83
if (!pCapabilities)
84
return E_POINTER;
85
86
dwCommonCaps = *pCapabilities & This->dwCapabilities;
87
88
if (!dwCommonCaps)
89
hr = E_FAIL;
90
else
91
hr = (*pCapabilities == dwCommonCaps) ? S_OK : S_FALSE;
92
*pCapabilities = dwCommonCaps;
93
return hr;
94
}
95
96
HRESULT WINAPI SourceSeekingImpl_IsFormatSupported(IMediaSeeking * iface, const GUID * pFormat)
97
{
98
TRACE("(%s)\n", debugstr_guid(pFormat));
99
100
return (IsEqualIID(pFormat, &TIME_FORMAT_MEDIA_TIME) ? S_OK : S_FALSE);
101
}
102
103
HRESULT WINAPI SourceSeekingImpl_QueryPreferredFormat(IMediaSeeking * iface, GUID * pFormat)
104
{
105
TRACE("(%s)\n", debugstr_guid(pFormat));
106
107
*pFormat = TIME_FORMAT_MEDIA_TIME;
108
return S_OK;
109
}
110
111
HRESULT WINAPI SourceSeekingImpl_GetTimeFormat(IMediaSeeking * iface, GUID * pFormat)
112
{
113
SourceSeeking *This = impl_from_IMediaSeeking(iface);
114
TRACE("(%s)\n", debugstr_guid(pFormat));
115
116
EnterCriticalSection(&This->cs);
117
*pFormat = This->timeformat;
118
LeaveCriticalSection(&This->cs);
119
120
return S_OK;
121
}
122
123
HRESULT WINAPI SourceSeekingImpl_IsUsingTimeFormat(IMediaSeeking * iface, const GUID * pFormat)
124
{
125
SourceSeeking *This = impl_from_IMediaSeeking(iface);
126
HRESULT hr = S_OK;
127
128
TRACE("(%s)\n", debugstr_guid(pFormat));
129
130
EnterCriticalSection(&This->cs);
131
if (!IsEqualIID(pFormat, &This->timeformat))
132
hr = S_FALSE;
133
LeaveCriticalSection(&This->cs);
134
135
return hr;
136
}
137
138
HRESULT WINAPI SourceSeekingImpl_SetTimeFormat(IMediaSeeking * iface, const GUID * pFormat)
139
{
140
SourceSeeking *This = impl_from_IMediaSeeking(iface);
141
TRACE("%p %s\n", This, debugstr_guid(pFormat));
142
return (IsEqualIID(pFormat, &TIME_FORMAT_MEDIA_TIME) ? S_OK : E_INVALIDARG);
143
}
144
145
146
HRESULT WINAPI SourceSeekingImpl_GetDuration(IMediaSeeking * iface, LONGLONG * pDuration)
147
{
148
SourceSeeking *This = impl_from_IMediaSeeking(iface);
149
150
TRACE("(%p)\n", pDuration);
151
152
EnterCriticalSection(&This->cs);
153
*pDuration = This->llDuration;
154
LeaveCriticalSection(&This->cs);
155
156
return S_OK;
157
}
158
159
HRESULT WINAPI SourceSeekingImpl_GetStopPosition(IMediaSeeking * iface, LONGLONG * pStop)
160
{
161
SourceSeeking *This = impl_from_IMediaSeeking(iface);
162
163
TRACE("(%p)\n", pStop);
164
165
EnterCriticalSection(&This->cs);
166
*pStop = This->llStop;
167
LeaveCriticalSection(&This->cs);
168
169
return S_OK;
170
}
171
172
/* FIXME: Make use of the info the filter should expose */
173
HRESULT WINAPI SourceSeekingImpl_GetCurrentPosition(IMediaSeeking * iface, LONGLONG * pCurrent)
174
{
175
SourceSeeking *This = impl_from_IMediaSeeking(iface);
176
177
TRACE("(%p)\n", pCurrent);
178
179
EnterCriticalSection(&This->cs);
180
*pCurrent = This->llCurrent;
181
LeaveCriticalSection(&This->cs);
182
183
return S_OK;
184
}
185
186
HRESULT WINAPI SourceSeekingImpl_ConvertTimeFormat(IMediaSeeking * iface, LONGLONG * pTarget, const GUID * pTargetFormat, LONGLONG Source, const GUID * pSourceFormat)
187
{
188
SourceSeeking *This = impl_from_IMediaSeeking(iface);
189
if (!pTargetFormat)
190
pTargetFormat = &This->timeformat;
191
if (!pSourceFormat)
192
pSourceFormat = &This->timeformat;
193
if (IsEqualIID(pTargetFormat, &TIME_FORMAT_MEDIA_TIME) && IsEqualIID(pSourceFormat, &TIME_FORMAT_MEDIA_TIME))
194
{
195
*pTarget = Source;
196
return S_OK;
197
}
198
/* FIXME: clear pTarget? */
199
return E_INVALIDARG;
200
}
201
202
static inline LONGLONG Adjust(LONGLONG value, const LONGLONG * pModifier, DWORD dwFlags)
203
{
204
switch (dwFlags & AM_SEEKING_PositioningBitsMask)
205
{
206
case AM_SEEKING_NoPositioning:
207
return value;
208
case AM_SEEKING_AbsolutePositioning:
209
return *pModifier;
210
case AM_SEEKING_RelativePositioning:
211
case AM_SEEKING_IncrementalPositioning:
212
return value + *pModifier;
213
default:
214
assert(FALSE);
215
return 0;
216
}
217
}
218
219
HRESULT WINAPI SourceSeekingImpl_SetPositions(IMediaSeeking * iface, LONGLONG * pCurrent, DWORD dwCurrentFlags, LONGLONG * pStop, DWORD dwStopFlags)
220
{
221
SourceSeeking *This = impl_from_IMediaSeeking(iface);
222
BOOL bChangeCurrent = FALSE, bChangeStop = FALSE;
223
LONGLONG llNewCurrent, llNewStop;
224
225
TRACE("iface %p, current %s, current_flags %#lx, stop %s, stop_flags %#lx.\n", iface,
226
pCurrent ? debugstr_time(*pCurrent) : "<null>", dwCurrentFlags,
227
pStop ? debugstr_time(*pStop): "<null>", dwStopFlags);
228
229
EnterCriticalSection(&This->cs);
230
231
llNewCurrent = Adjust(This->llCurrent, pCurrent, dwCurrentFlags);
232
llNewStop = Adjust(This->llStop, pStop, dwStopFlags);
233
234
if (pCurrent)
235
bChangeCurrent = TRUE;
236
if (llNewStop != This->llStop)
237
bChangeStop = TRUE;
238
239
TRACE("Seeking from %s to %s.\n", debugstr_time(This->llCurrent), debugstr_time(llNewCurrent));
240
241
This->llCurrent = llNewCurrent;
242
This->llStop = llNewStop;
243
244
if (pCurrent && (dwCurrentFlags & AM_SEEKING_ReturnTime))
245
*pCurrent = llNewCurrent;
246
if (pStop && (dwStopFlags & AM_SEEKING_ReturnTime))
247
*pStop = llNewStop;
248
LeaveCriticalSection(&This->cs);
249
250
if (bChangeCurrent)
251
This->fnChangeStart(iface);
252
if (bChangeStop)
253
This->fnChangeStop(iface);
254
255
return S_OK;
256
}
257
258
HRESULT WINAPI SourceSeekingImpl_GetPositions(IMediaSeeking * iface, LONGLONG * pCurrent, LONGLONG * pStop)
259
{
260
SourceSeeking *This = impl_from_IMediaSeeking(iface);
261
262
TRACE("(%p, %p)\n", pCurrent, pStop);
263
264
EnterCriticalSection(&This->cs);
265
IMediaSeeking_GetCurrentPosition(iface, pCurrent);
266
IMediaSeeking_GetStopPosition(iface, pStop);
267
LeaveCriticalSection(&This->cs);
268
269
return S_OK;
270
}
271
272
HRESULT WINAPI SourceSeekingImpl_GetAvailable(IMediaSeeking * iface, LONGLONG * pEarliest, LONGLONG * pLatest)
273
{
274
SourceSeeking *This = impl_from_IMediaSeeking(iface);
275
276
TRACE("(%p, %p)\n", pEarliest, pLatest);
277
278
EnterCriticalSection(&This->cs);
279
*pEarliest = 0;
280
*pLatest = This->llDuration;
281
LeaveCriticalSection(&This->cs);
282
283
return S_OK;
284
}
285
286
HRESULT WINAPI SourceSeekingImpl_SetRate(IMediaSeeking * iface, double dRate)
287
{
288
SourceSeeking *This = impl_from_IMediaSeeking(iface);
289
BOOL bChangeRate = (dRate != This->dRate);
290
HRESULT hr = S_OK;
291
292
TRACE("(%e)\n", dRate);
293
294
if (dRate > 100 || dRate < .001)
295
{
296
FIXME("Excessive rate %e, ignoring\n", dRate);
297
return VFW_E_UNSUPPORTED_AUDIO;
298
}
299
300
EnterCriticalSection(&This->cs);
301
This->dRate = dRate;
302
if (bChangeRate)
303
hr = This->fnChangeRate(iface);
304
LeaveCriticalSection(&This->cs);
305
306
return hr;
307
}
308
309
HRESULT WINAPI SourceSeekingImpl_GetRate(IMediaSeeking * iface, double * dRate)
310
{
311
SourceSeeking *This = impl_from_IMediaSeeking(iface);
312
313
TRACE("(%p)\n", dRate);
314
315
EnterCriticalSection(&This->cs);
316
/* Forward? */
317
*dRate = This->dRate;
318
LeaveCriticalSection(&This->cs);
319
320
return S_OK;
321
}
322
323
HRESULT WINAPI SourceSeekingImpl_GetPreroll(IMediaSeeking * iface, LONGLONG * pPreroll)
324
{
325
TRACE("(%p)\n", pPreroll);
326
327
*pPreroll = 0;
328
return S_OK;
329
}
330
331