msxml3: Add a stub IXSLProcessor.
[wine/multimedia.git] / dlls / quartz / filesource.c
blobd45814418837228a03aae947b33a7bc8f87626fa
1 /*
2 * File Source Filter
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define NONAMELESSUNION
22 #define NONAMELESSSTRUCT
24 #include "quartz_private.h"
26 #include "wine/debug.h"
27 #include "wine/unicode.h"
28 #include "pin.h"
29 #include "uuids.h"
30 #include "vfwmsgs.h"
31 #include "winbase.h"
32 #include "winreg.h"
33 #include "shlwapi.h"
34 #include <assert.h>
36 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
38 static const WCHAR wszOutputPinName[] = { 'O','u','t','p','u','t',0 };
40 typedef struct AsyncReader
42 BaseFilter filter;
43 const IFileSourceFilterVtbl * lpVtblFSF;
44 const IAMFilterMiscFlagsVtbl * IAMFilterMiscFlags_vtbl;
46 IPin * pOutputPin;
47 LPOLESTR pszFileName;
48 AM_MEDIA_TYPE * pmt;
49 } AsyncReader;
51 static const IBaseFilterVtbl AsyncReader_Vtbl;
52 static const IFileSourceFilterVtbl FileSource_Vtbl;
53 static const IAsyncReaderVtbl FileAsyncReader_Vtbl;
54 static const IAMFilterMiscFlagsVtbl IAMFilterMiscFlags_Vtbl;
56 static HRESULT FileAsyncReader_Construct(HANDLE hFile, IBaseFilter * pBaseFilter, LPCRITICAL_SECTION pCritSec, IPin ** ppPin);
58 static inline AsyncReader *impl_from_IFileSourceFilter( IFileSourceFilter *iface )
60 return (AsyncReader *)((char*)iface - FIELD_OFFSET(AsyncReader, lpVtblFSF));
63 static WCHAR const mediatype_name[11] = {
64 'M', 'e', 'd', 'i', 'a', ' ', 'T', 'y', 'p', 'e', 0 };
65 static WCHAR const subtype_name[8] = {
66 'S', 'u', 'b', 't', 'y', 'p', 'e', 0 };
68 static HRESULT process_extensions(HKEY hkeyExtensions, LPCOLESTR pszFileName, GUID * majorType, GUID * minorType)
70 WCHAR *extension;
71 LONG l;
72 HKEY hsub;
73 WCHAR keying[39];
74 DWORD size;
76 if (!pszFileName)
77 return E_POINTER;
79 /* Get the part of the name that matters */
80 extension = PathFindExtensionW(pszFileName);
81 if (*extension != '.')
82 return E_FAIL;
84 l = RegOpenKeyExW(hkeyExtensions, extension, 0, KEY_READ, &hsub);
85 if (l)
86 return E_FAIL;
88 size = sizeof(keying);
89 l = RegQueryValueExW(hsub, mediatype_name, NULL, NULL, (LPBYTE)keying, &size);
90 if (!l)
91 CLSIDFromString(keying, majorType);
93 size = sizeof(keying);
94 if (!l)
95 l = RegQueryValueExW(hsub, subtype_name, NULL, NULL, (LPBYTE)keying, &size);
97 if (!l)
98 CLSIDFromString(keying, minorType);
100 RegCloseKey(hsub);
102 if (!l)
103 return S_OK;
104 return E_FAIL;
107 static unsigned char byte_from_hex_char(WCHAR wHex)
109 switch (tolowerW(wHex))
111 case '0':
112 case '1':
113 case '2':
114 case '3':
115 case '4':
116 case '5':
117 case '6':
118 case '7':
119 case '8':
120 case '9':
121 return (wHex - '0') & 0xf;
122 case 'a':
123 case 'b':
124 case 'c':
125 case 'd':
126 case 'e':
127 case 'f':
128 return (wHex - 'a' + 10) & 0xf;
129 default:
130 return 0;
134 static HRESULT process_pattern_string(LPCWSTR wszPatternString, IAsyncReader * pReader)
136 ULONG ulOffset;
137 ULONG ulBytes;
138 BYTE * pbMask;
139 BYTE * pbValue;
140 BYTE * pbFile;
141 HRESULT hr = S_OK;
142 ULONG strpos;
144 TRACE("\t\tPattern string: %s\n", debugstr_w(wszPatternString));
146 /* format: "offset, bytestocompare, mask, value" */
148 ulOffset = strtolW(wszPatternString, NULL, 10);
150 if (!(wszPatternString = strchrW(wszPatternString, ',')))
151 return E_INVALIDARG;
153 wszPatternString++; /* skip ',' */
155 ulBytes = strtolW(wszPatternString, NULL, 10);
157 pbMask = HeapAlloc(GetProcessHeap(), 0, ulBytes);
158 pbValue = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, ulBytes);
159 pbFile = HeapAlloc(GetProcessHeap(), 0, ulBytes);
161 /* default mask is match everything */
162 memset(pbMask, 0xFF, ulBytes);
164 if (!(wszPatternString = strchrW(wszPatternString, ',')))
165 hr = E_INVALIDARG;
167 if (hr == S_OK)
169 wszPatternString++; /* skip ',' */
170 while (!isxdigitW(*wszPatternString) && (*wszPatternString != ',')) wszPatternString++;
172 for (strpos = 0; isxdigitW(*wszPatternString) && (strpos/2 < ulBytes); wszPatternString++, strpos++)
174 if ((strpos % 2) == 1) /* odd numbered position */
175 pbMask[strpos / 2] |= byte_from_hex_char(*wszPatternString);
176 else
177 pbMask[strpos / 2] = byte_from_hex_char(*wszPatternString) << 4;
180 if (!(wszPatternString = strchrW(wszPatternString, ',')))
181 hr = E_INVALIDARG;
183 wszPatternString++; /* skip ',' */
186 if (hr == S_OK)
188 for ( ; !isxdigitW(*wszPatternString) && (*wszPatternString != ','); wszPatternString++)
191 for (strpos = 0; isxdigitW(*wszPatternString) && (strpos/2 < ulBytes); wszPatternString++, strpos++)
193 if ((strpos % 2) == 1) /* odd numbered position */
194 pbValue[strpos / 2] |= byte_from_hex_char(*wszPatternString);
195 else
196 pbValue[strpos / 2] = byte_from_hex_char(*wszPatternString) << 4;
200 if (hr == S_OK)
201 hr = IAsyncReader_SyncRead(pReader, ulOffset, ulBytes, pbFile);
203 if (hr == S_OK)
205 ULONG i;
206 for (i = 0; i < ulBytes; i++)
207 if ((pbFile[i] & pbMask[i]) != pbValue[i])
209 hr = S_FALSE;
210 break;
214 HeapFree(GetProcessHeap(), 0, pbMask);
215 HeapFree(GetProcessHeap(), 0, pbValue);
216 HeapFree(GetProcessHeap(), 0, pbFile);
218 /* if we encountered no errors with this string, and there is a following tuple, then we
219 * have to match that as well to succeed */
220 if ((hr == S_OK) && (wszPatternString = strchrW(wszPatternString, ',')))
221 return process_pattern_string(wszPatternString + 1, pReader);
222 else
223 return hr;
226 static HRESULT GetClassMediaFile(IAsyncReader * pReader, LPCOLESTR pszFileName, GUID * majorType, GUID * minorType)
228 HKEY hkeyMediaType = NULL;
229 LONG lRet;
230 HRESULT hr = S_OK;
231 BOOL bFound = FALSE;
232 static const WCHAR wszMediaType[] = {'M','e','d','i','a',' ','T','y','p','e',0};
234 TRACE("(%p, %s, %p, %p)\n", pReader, debugstr_w(pszFileName), majorType, minorType);
236 *majorType = GUID_NULL;
237 *minorType = GUID_NULL;
239 lRet = RegOpenKeyExW(HKEY_CLASSES_ROOT, wszMediaType, 0, KEY_READ, &hkeyMediaType);
240 hr = HRESULT_FROM_WIN32(lRet);
242 if (SUCCEEDED(hr))
244 DWORD indexMajor;
246 for (indexMajor = 0; !bFound; indexMajor++)
248 HKEY hkeyMajor;
249 WCHAR wszMajorKeyName[CHARS_IN_GUID];
250 DWORD dwKeyNameLength = sizeof(wszMajorKeyName) / sizeof(wszMajorKeyName[0]);
251 static const WCHAR wszExtensions[] = {'E','x','t','e','n','s','i','o','n','s',0};
253 if (RegEnumKeyExW(hkeyMediaType, indexMajor, wszMajorKeyName, &dwKeyNameLength, NULL, NULL, NULL, NULL) != ERROR_SUCCESS)
254 break;
255 if (RegOpenKeyExW(hkeyMediaType, wszMajorKeyName, 0, KEY_READ, &hkeyMajor) != ERROR_SUCCESS)
256 break;
257 TRACE("%s\n", debugstr_w(wszMajorKeyName));
258 if (!strcmpW(wszExtensions, wszMajorKeyName))
260 if (process_extensions(hkeyMajor, pszFileName, majorType, minorType) == S_OK)
261 bFound = TRUE;
263 else
265 DWORD indexMinor;
267 for (indexMinor = 0; !bFound; indexMinor++)
269 HKEY hkeyMinor;
270 WCHAR wszMinorKeyName[CHARS_IN_GUID];
271 DWORD dwMinorKeyNameLen = sizeof(wszMinorKeyName) / sizeof(wszMinorKeyName[0]);
272 DWORD maxValueLen;
273 DWORD indexValue;
275 if (RegEnumKeyExW(hkeyMajor, indexMinor, wszMinorKeyName, &dwMinorKeyNameLen, NULL, NULL, NULL, NULL) != ERROR_SUCCESS)
276 break;
278 if (RegOpenKeyExW(hkeyMajor, wszMinorKeyName, 0, KEY_READ, &hkeyMinor) != ERROR_SUCCESS)
279 break;
281 TRACE("\t%s\n", debugstr_w(wszMinorKeyName));
283 if (RegQueryInfoKeyW(hkeyMinor, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &maxValueLen, NULL, NULL) != ERROR_SUCCESS)
284 break;
286 for (indexValue = 0; !bFound; indexValue++)
288 DWORD dwType;
289 WCHAR wszValueName[14]; /* longest name we should encounter will be "Source Filter" */
290 LPWSTR wszPatternString = HeapAlloc(GetProcessHeap(), 0, maxValueLen);
291 DWORD dwValueNameLen = sizeof(wszValueName) / sizeof(wszValueName[0]); /* remember this is in chars */
292 DWORD dwDataLen = maxValueLen; /* remember this is in bytes */
293 static const WCHAR wszSourceFilter[] = {'S','o','u','r','c','e',' ','F','i','l','t','e','r',0};
294 LONG temp;
296 if ((temp = RegEnumValueW(hkeyMinor, indexValue, wszValueName, &dwValueNameLen, NULL, &dwType, (LPBYTE)wszPatternString, &dwDataLen)) != ERROR_SUCCESS)
298 HeapFree(GetProcessHeap(), 0, wszPatternString);
299 break;
302 /* if it is not the source filter value */
303 if (strcmpW(wszValueName, wszSourceFilter))
305 if (process_pattern_string(wszPatternString, pReader) == S_OK)
307 if (SUCCEEDED(CLSIDFromString(wszMajorKeyName, majorType)) &&
308 SUCCEEDED(CLSIDFromString(wszMinorKeyName, minorType)))
309 bFound = TRUE;
312 HeapFree(GetProcessHeap(), 0, wszPatternString);
314 CloseHandle(hkeyMinor);
317 CloseHandle(hkeyMajor);
320 CloseHandle(hkeyMediaType);
322 if (SUCCEEDED(hr) && !bFound)
324 ERR("Media class not found\n");
325 hr = E_FAIL;
327 else if (bFound)
328 TRACE("Found file's class: major = %s, subtype = %s\n", qzdebugstr_guid(majorType), qzdebugstr_guid(minorType));
330 return hr;
333 static IPin* WINAPI AsyncReader_GetPin(BaseFilter *iface, int pos)
335 AsyncReader *This = (AsyncReader *)iface;
337 if (pos >= 1 || !This->pOutputPin)
338 return NULL;
340 IPin_AddRef(This->pOutputPin);
341 return This->pOutputPin;
344 static LONG WINAPI AsyncReader_GetPinCount(BaseFilter *iface)
346 AsyncReader *This = (AsyncReader *)iface;
348 if (!This->pOutputPin)
349 return 0;
350 else
351 return 1;
354 static const BaseFilterFuncTable BaseFuncTable = {
355 AsyncReader_GetPin,
356 AsyncReader_GetPinCount
359 HRESULT AsyncReader_create(IUnknown * pUnkOuter, LPVOID * ppv)
361 AsyncReader *pAsyncRead;
363 if( pUnkOuter )
364 return CLASS_E_NOAGGREGATION;
366 pAsyncRead = CoTaskMemAlloc(sizeof(AsyncReader));
368 if (!pAsyncRead)
369 return E_OUTOFMEMORY;
371 BaseFilter_Init(&pAsyncRead->filter, &AsyncReader_Vtbl, &CLSID_AsyncReader, (DWORD_PTR)(__FILE__ ": AsyncReader.csFilter"), &BaseFuncTable);
373 pAsyncRead->lpVtblFSF = &FileSource_Vtbl;
374 pAsyncRead->IAMFilterMiscFlags_vtbl = &IAMFilterMiscFlags_Vtbl;
375 pAsyncRead->pOutputPin = NULL;
377 pAsyncRead->pszFileName = NULL;
378 pAsyncRead->pmt = NULL;
380 *ppv = pAsyncRead;
382 TRACE("-- created at %p\n", pAsyncRead);
384 return S_OK;
387 /** IUnknown methods **/
389 static HRESULT WINAPI AsyncReader_QueryInterface(IBaseFilter * iface, REFIID riid, LPVOID * ppv)
391 AsyncReader *This = (AsyncReader *)iface;
393 TRACE("(%s, %p)\n", qzdebugstr_guid(riid), ppv);
395 *ppv = NULL;
397 if (IsEqualIID(riid, &IID_IUnknown))
398 *ppv = This;
399 else if (IsEqualIID(riid, &IID_IPersist))
400 *ppv = This;
401 else if (IsEqualIID(riid, &IID_IMediaFilter))
402 *ppv = This;
403 else if (IsEqualIID(riid, &IID_IBaseFilter))
404 *ppv = This;
405 else if (IsEqualIID(riid, &IID_IFileSourceFilter))
406 *ppv = &This->lpVtblFSF;
407 else if (IsEqualIID(riid, &IID_IAMFilterMiscFlags))
408 *ppv = &This->IAMFilterMiscFlags_vtbl;
410 if (*ppv)
412 IUnknown_AddRef((IUnknown *)(*ppv));
413 return S_OK;
416 if (!IsEqualIID(riid, &IID_IPin) && !IsEqualIID(riid, &IID_IMediaSeeking) &&
417 !IsEqualIID(riid, &IID_IVideoWindow) && !IsEqualIID(riid, &IID_IBasicAudio))
418 FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
420 return E_NOINTERFACE;
423 static ULONG WINAPI AsyncReader_Release(IBaseFilter * iface)
425 AsyncReader *This = (AsyncReader *)iface;
426 ULONG refCount = BaseFilterImpl_Release(iface);
428 TRACE("(%p)->() Release from %d\n", This, refCount + 1);
430 if (!refCount)
432 if (This->pOutputPin)
434 IPin *pConnectedTo;
435 if(SUCCEEDED(IPin_ConnectedTo(This->pOutputPin, &pConnectedTo)))
437 IPin_Disconnect(pConnectedTo);
438 IPin_Release(pConnectedTo);
440 IPin_Disconnect(This->pOutputPin);
441 IPin_Release(This->pOutputPin);
443 CoTaskMemFree(This->pszFileName);
444 if (This->pmt)
445 FreeMediaType(This->pmt);
446 CoTaskMemFree(This);
447 return 0;
449 else
450 return refCount;
453 /** IMediaFilter methods **/
455 static HRESULT WINAPI AsyncReader_Stop(IBaseFilter * iface)
457 AsyncReader *This = (AsyncReader *)iface;
459 TRACE("()\n");
461 This->filter.state = State_Stopped;
463 return S_OK;
466 static HRESULT WINAPI AsyncReader_Pause(IBaseFilter * iface)
468 AsyncReader *This = (AsyncReader *)iface;
470 TRACE("()\n");
472 This->filter.state = State_Paused;
474 return S_OK;
477 static HRESULT WINAPI AsyncReader_Run(IBaseFilter * iface, REFERENCE_TIME tStart)
479 AsyncReader *This = (AsyncReader *)iface;
481 TRACE("(%x%08x)\n", (ULONG)(tStart >> 32), (ULONG)tStart);
483 This->filter.state = State_Running;
485 return S_OK;
488 /** IBaseFilter methods **/
490 static HRESULT WINAPI AsyncReader_FindPin(IBaseFilter * iface, LPCWSTR Id, IPin **ppPin)
492 AsyncReader *This = (AsyncReader *)iface;
493 TRACE("(%s, %p)\n", debugstr_w(Id), ppPin);
495 if (!Id || !ppPin)
496 return E_POINTER;
498 if (strcmpW(Id, wszOutputPinName))
500 *ppPin = NULL;
501 return VFW_E_NOT_FOUND;
504 *ppPin = (IPin*)This->pOutputPin;
505 IUnknown_AddRef(*ppPin);
506 return S_OK;
509 static const IBaseFilterVtbl AsyncReader_Vtbl =
511 AsyncReader_QueryInterface,
512 BaseFilterImpl_AddRef,
513 AsyncReader_Release,
514 BaseFilterImpl_GetClassID,
515 AsyncReader_Stop,
516 AsyncReader_Pause,
517 AsyncReader_Run,
518 BaseFilterImpl_GetState,
519 BaseFilterImpl_SetSyncSource,
520 BaseFilterImpl_GetSyncSource,
521 BaseFilterImpl_EnumPins,
522 AsyncReader_FindPin,
523 BaseFilterImpl_QueryFilterInfo,
524 BaseFilterImpl_JoinFilterGraph,
525 BaseFilterImpl_QueryVendorInfo
528 static HRESULT WINAPI FileSource_QueryInterface(IFileSourceFilter * iface, REFIID riid, LPVOID * ppv)
530 AsyncReader *This = impl_from_IFileSourceFilter(iface);
532 return IBaseFilter_QueryInterface((IFileSourceFilter*)&This->filter.lpVtbl, riid, ppv);
535 static ULONG WINAPI FileSource_AddRef(IFileSourceFilter * iface)
537 AsyncReader *This = impl_from_IFileSourceFilter(iface);
539 return IBaseFilter_AddRef((IFileSourceFilter*)&This->filter.lpVtbl);
542 static ULONG WINAPI FileSource_Release(IFileSourceFilter * iface)
544 AsyncReader *This = impl_from_IFileSourceFilter(iface);
546 return IBaseFilter_Release((IFileSourceFilter*)&This->filter.lpVtbl);
549 static HRESULT WINAPI FileSource_Load(IFileSourceFilter * iface, LPCOLESTR pszFileName, const AM_MEDIA_TYPE * pmt)
551 HRESULT hr;
552 HANDLE hFile;
553 IAsyncReader * pReader = NULL;
554 AsyncReader *This = impl_from_IFileSourceFilter(iface);
556 TRACE("(%s, %p)\n", debugstr_w(pszFileName), pmt);
558 /* open file */
559 /* FIXME: check the sharing values that native uses */
560 hFile = CreateFileW(pszFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);
562 if (hFile == INVALID_HANDLE_VALUE)
564 return HRESULT_FROM_WIN32(GetLastError());
567 /* create pin */
568 hr = FileAsyncReader_Construct(hFile, (IBaseFilter *)&This->filter.lpVtbl, &This->filter.csFilter, &This->pOutputPin);
569 BaseFilterImpl_IncrementPinVersion((BaseFilter *)&This->filter.lpVtbl);
571 if (SUCCEEDED(hr))
572 hr = IPin_QueryInterface(This->pOutputPin, &IID_IAsyncReader, (LPVOID *)&pReader);
574 /* store file name & media type */
575 if (SUCCEEDED(hr))
577 CoTaskMemFree(This->pszFileName);
578 if (This->pmt)
579 FreeMediaType(This->pmt);
581 This->pszFileName = CoTaskMemAlloc((strlenW(pszFileName) + 1) * sizeof(WCHAR));
582 strcpyW(This->pszFileName, pszFileName);
584 This->pmt = CoTaskMemAlloc(sizeof(AM_MEDIA_TYPE));
585 if (!pmt)
587 This->pmt->bFixedSizeSamples = TRUE;
588 This->pmt->bTemporalCompression = FALSE;
589 This->pmt->cbFormat = 0;
590 This->pmt->pbFormat = NULL;
591 This->pmt->pUnk = NULL;
592 This->pmt->lSampleSize = 0;
593 This->pmt->formattype = FORMAT_None;
594 hr = GetClassMediaFile(pReader, pszFileName, &This->pmt->majortype, &This->pmt->subtype);
595 if (FAILED(hr))
597 CoTaskMemFree(This->pmt);
598 This->pmt = NULL;
601 else
602 CopyMediaType(This->pmt, pmt);
605 if (pReader)
606 IAsyncReader_Release(pReader);
608 if (FAILED(hr))
610 if (This->pOutputPin)
612 IPin_Release(This->pOutputPin);
613 This->pOutputPin = NULL;
616 CoTaskMemFree(This->pszFileName);
617 if (This->pmt)
618 FreeMediaType(This->pmt);
619 This->pszFileName = NULL;
620 This->pmt = NULL;
622 CloseHandle(hFile);
625 /* FIXME: check return codes */
626 return hr;
629 static HRESULT WINAPI FileSource_GetCurFile(IFileSourceFilter * iface, LPOLESTR * ppszFileName, AM_MEDIA_TYPE * pmt)
631 AsyncReader *This = impl_from_IFileSourceFilter(iface);
633 TRACE("(%p, %p)\n", ppszFileName, pmt);
635 if (!ppszFileName)
636 return E_POINTER;
638 /* copy file name & media type if available, otherwise clear the outputs */
639 if (This->pszFileName)
641 *ppszFileName = CoTaskMemAlloc((strlenW(This->pszFileName) + 1) * sizeof(WCHAR));
642 strcpyW(*ppszFileName, This->pszFileName);
644 else
645 *ppszFileName = NULL;
647 if (pmt)
649 if (This->pmt)
650 CopyMediaType(pmt, This->pmt);
651 else
652 ZeroMemory(pmt, sizeof(*pmt));
655 return S_OK;
658 static const IFileSourceFilterVtbl FileSource_Vtbl =
660 FileSource_QueryInterface,
661 FileSource_AddRef,
662 FileSource_Release,
663 FileSource_Load,
664 FileSource_GetCurFile
668 /* the dwUserData passed back to user */
669 typedef struct DATAREQUEST
671 IMediaSample * pSample; /* sample passed to us by user */
672 DWORD_PTR dwUserData; /* user data passed to us */
673 OVERLAPPED ovl; /* our overlapped structure */
674 } DATAREQUEST;
676 typedef struct FileAsyncReader
678 BaseOutputPin pin;
679 const struct IAsyncReaderVtbl * lpVtblAR;
681 ALLOCATOR_PROPERTIES allocProps;
682 HANDLE hFile;
683 BOOL bFlushing;
684 /* Why would you need more? Every sample has its own handle */
685 LONG queued_number;
686 LONG samples;
687 LONG oldest_sample;
688 CRITICAL_SECTION csList; /* critical section to prevent concurrency issues */
689 DATAREQUEST *sample_list;
691 /* Have a handle for every sample, and then one more as flushing handle */
692 HANDLE *handle_list;
693 } FileAsyncReader;
695 static inline FileAsyncReader *impl_from_IAsyncReader( IAsyncReader *iface )
697 return (FileAsyncReader *)((char*)iface - FIELD_OFFSET(FileAsyncReader, lpVtblAR));
700 static HRESULT WINAPI FileAsyncReaderPin_QueryAccept(IPin *iface, const AM_MEDIA_TYPE *pmt)
702 FileAsyncReader *This = (FileAsyncReader *)iface;
703 AM_MEDIA_TYPE *pmt_filter = ((AsyncReader *)This->pin.pin.pinInfo.pFilter)->pmt;
705 FIXME("(%p, %p)\n", iface, pmt);
707 if (IsEqualGUID(&pmt->majortype, &pmt_filter->majortype) &&
708 IsEqualGUID(&pmt->subtype, &pmt_filter->subtype) &&
709 IsEqualGUID(&pmt->formattype, &FORMAT_None))
710 return S_OK;
712 return S_FALSE;
715 static HRESULT WINAPI FileAsyncReaderPin_GetMediaType(BasePin *iface, int iPosition, AM_MEDIA_TYPE *pmt)
717 FileAsyncReader *This = (FileAsyncReader *)iface;
718 if (iPosition < 0)
719 return E_INVALIDARG;
720 if (iPosition > 0)
721 return VFW_S_NO_MORE_ITEMS;
722 CopyMediaType(pmt, ((AsyncReader *)This->pin.pin.pinInfo.pFilter)->pmt);
723 return S_OK;
726 /* overridden pin functions */
728 static HRESULT WINAPI FileAsyncReaderPin_QueryInterface(IPin * iface, REFIID riid, LPVOID * ppv)
730 FileAsyncReader *This = (FileAsyncReader *)iface;
731 TRACE("(%s, %p)\n", qzdebugstr_guid(riid), ppv);
733 *ppv = NULL;
735 if (IsEqualIID(riid, &IID_IUnknown))
736 *ppv = This;
737 else if (IsEqualIID(riid, &IID_IPin))
738 *ppv = This;
739 else if (IsEqualIID(riid, &IID_IAsyncReader))
740 *ppv = &This->lpVtblAR;
742 if (*ppv)
744 IUnknown_AddRef((IUnknown *)(*ppv));
745 return S_OK;
748 if (!IsEqualIID(riid, &IID_IPin) && !IsEqualIID(riid, &IID_IMediaSeeking))
749 FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
751 return E_NOINTERFACE;
754 static ULONG WINAPI FileAsyncReaderPin_Release(IPin * iface)
756 FileAsyncReader *This = (FileAsyncReader *)iface;
757 ULONG refCount = InterlockedDecrement(&This->pin.pin.refCount);
758 int x;
760 TRACE("(%p)->() Release from %d\n", This, refCount + 1);
762 if (!refCount)
764 CoTaskMemFree(This->sample_list);
765 if (This->handle_list)
767 for (x = 0; x <= This->samples; ++x)
768 CloseHandle(This->handle_list[x]);
769 CoTaskMemFree(This->handle_list);
771 CloseHandle(This->hFile);
772 This->csList.DebugInfo->Spare[0] = 0;
773 DeleteCriticalSection(&This->csList);
774 CoTaskMemFree(This);
775 return 0;
777 return refCount;
780 static const IPinVtbl FileAsyncReaderPin_Vtbl =
782 FileAsyncReaderPin_QueryInterface,
783 BasePinImpl_AddRef,
784 FileAsyncReaderPin_Release,
785 BaseOutputPinImpl_Connect,
786 BaseOutputPinImpl_ReceiveConnection,
787 BasePinImpl_Disconnect,
788 BasePinImpl_ConnectedTo,
789 BasePinImpl_ConnectionMediaType,
790 BasePinImpl_QueryPinInfo,
791 BasePinImpl_QueryDirection,
792 BasePinImpl_QueryId,
793 FileAsyncReaderPin_QueryAccept,
794 BasePinImpl_EnumMediaTypes,
795 BasePinImpl_QueryInternalConnections,
796 BaseOutputPinImpl_EndOfStream,
797 BaseOutputPinImpl_BeginFlush,
798 BaseOutputPinImpl_EndFlush,
799 BasePinImpl_NewSegment
802 /* Function called as a helper to IPin_Connect */
803 /* specific AM_MEDIA_TYPE - it cannot be NULL */
804 /* this differs from standard OutputPin_AttemptConnection only in that it
805 * doesn't need the IMemInputPin interface on the receiving pin */
806 static HRESULT WINAPI FileAsyncReaderPin_AttemptConnection(BasePin * iface, IPin * pReceivePin, const AM_MEDIA_TYPE * pmt)
808 BaseOutputPin *This = (BaseOutputPin *)iface;
809 HRESULT hr;
811 TRACE("(%p, %p)\n", pReceivePin, pmt);
812 dump_AM_MEDIA_TYPE(pmt);
814 /* FIXME: call queryacceptproc */
816 This->pin.pConnectedTo = pReceivePin;
817 IPin_AddRef(pReceivePin);
818 CopyMediaType(&This->pin.mtCurrent, pmt);
820 hr = IPin_ReceiveConnection(pReceivePin, (IPin*)iface, pmt);
822 if (FAILED(hr))
824 IPin_Release(This->pin.pConnectedTo);
825 This->pin.pConnectedTo = NULL;
826 FreeMediaType(&This->pin.mtCurrent);
829 TRACE(" -- %x\n", hr);
830 return hr;
833 static HRESULT WINAPI FileAsyncReaderPin_DecideBufferSize(BaseOutputPin *iface, IMemAllocator *pAlloc, ALLOCATOR_PROPERTIES *ppropInputRequest)
835 FileAsyncReader *This = (FileAsyncReader *)iface;
836 ALLOCATOR_PROPERTIES actual;
838 if (ppropInputRequest->cbAlign && ppropInputRequest->cbAlign != This->allocProps.cbAlign)
839 FIXME("Requested Buffer cbAlign mismatch %i,%i\n",This->allocProps.cbAlign, ppropInputRequest->cbAlign);
840 if (ppropInputRequest->cbPrefix)
841 FIXME("Requested Buffer cbPrefix mismatch %i,%i\n",This->allocProps.cbPrefix, ppropInputRequest->cbPrefix);
842 if (ppropInputRequest->cbBuffer)
843 FIXME("Requested Buffer cbBuffer mismatch %i,%i\n",This->allocProps.cbBuffer, ppropInputRequest->cbBuffer);
844 if (ppropInputRequest->cBuffers)
845 FIXME("Requested Buffer cBuffers mismatch %i,%i\n",This->allocProps.cBuffers, ppropInputRequest->cBuffers);
847 return IMemAllocator_SetProperties(pAlloc, &This->allocProps, &actual);
850 static const BasePinFuncTable output_BaseFuncTable = {
851 NULL,
852 FileAsyncReaderPin_AttemptConnection,
853 BasePinImpl_GetMediaTypeVersion,
854 FileAsyncReaderPin_GetMediaType
857 static const BaseOutputPinFuncTable output_BaseOutputFuncTable = {
858 FileAsyncReaderPin_DecideBufferSize,
859 BaseOutputPinImpl_DecideAllocator,
860 BaseOutputPinImpl_BreakConnect
863 static HRESULT FileAsyncReader_Construct(HANDLE hFile, IBaseFilter * pBaseFilter, LPCRITICAL_SECTION pCritSec, IPin ** ppPin)
865 PIN_INFO piOutput;
866 HRESULT hr;
868 *ppPin = NULL;
869 piOutput.dir = PINDIR_OUTPUT;
870 piOutput.pFilter = pBaseFilter;
871 strcpyW(piOutput.achName, wszOutputPinName);
872 hr = BaseOutputPin_Construct(&FileAsyncReaderPin_Vtbl, sizeof(FileAsyncReader), &piOutput, &output_BaseFuncTable, &output_BaseOutputFuncTable, pCritSec, ppPin);
874 if (SUCCEEDED(hr))
876 FileAsyncReader *pPinImpl = (FileAsyncReader *)*ppPin;
877 pPinImpl->lpVtblAR = &FileAsyncReader_Vtbl;
878 pPinImpl->hFile = hFile;
879 pPinImpl->bFlushing = FALSE;
880 pPinImpl->sample_list = NULL;
881 pPinImpl->handle_list = NULL;
882 pPinImpl->queued_number = 0;
883 InitializeCriticalSection(&pPinImpl->csList);
884 pPinImpl->csList.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": FileAsyncReader.csList");
886 return hr;
889 /* IAsyncReader */
891 static HRESULT WINAPI FileAsyncReader_QueryInterface(IAsyncReader * iface, REFIID riid, LPVOID * ppv)
893 FileAsyncReader *This = impl_from_IAsyncReader(iface);
895 return IPin_QueryInterface((IPin *)This, riid, ppv);
898 static ULONG WINAPI FileAsyncReader_AddRef(IAsyncReader * iface)
900 FileAsyncReader *This = impl_from_IAsyncReader(iface);
902 return IPin_AddRef((IPin *)This);
905 static ULONG WINAPI FileAsyncReader_Release(IAsyncReader * iface)
907 FileAsyncReader *This = impl_from_IAsyncReader(iface);
909 return IPin_Release((IPin *)This);
912 #define DEF_ALIGNMENT 1
914 static HRESULT WINAPI FileAsyncReader_RequestAllocator(IAsyncReader * iface, IMemAllocator * pPreferred, ALLOCATOR_PROPERTIES * pProps, IMemAllocator ** ppActual)
916 FileAsyncReader *This = impl_from_IAsyncReader(iface);
918 HRESULT hr = S_OK;
920 TRACE("(%p, %p, %p)\n", pPreferred, pProps, ppActual);
922 if (!pProps->cbAlign || (pProps->cbAlign % DEF_ALIGNMENT) != 0)
923 pProps->cbAlign = DEF_ALIGNMENT;
925 if (pPreferred)
927 hr = IMemAllocator_SetProperties(pPreferred, pProps, pProps);
928 /* FIXME: check we are still aligned */
929 if (SUCCEEDED(hr))
931 IMemAllocator_AddRef(pPreferred);
932 *ppActual = pPreferred;
933 TRACE("FileAsyncReader_RequestAllocator -- %x\n", hr);
934 goto done;
938 pPreferred = NULL;
940 hr = CoCreateInstance(&CLSID_MemoryAllocator, NULL, CLSCTX_INPROC, &IID_IMemAllocator, (LPVOID *)&pPreferred);
942 if (SUCCEEDED(hr))
944 hr = IMemAllocator_SetProperties(pPreferred, pProps, pProps);
945 /* FIXME: check we are still aligned */
946 if (SUCCEEDED(hr))
948 *ppActual = pPreferred;
949 TRACE("FileAsyncReader_RequestAllocator -- %x\n", hr);
953 done:
954 if (SUCCEEDED(hr))
956 CoTaskMemFree(This->sample_list);
957 if (This->handle_list)
959 int x;
960 for (x = 0; x <= This->samples; ++x)
961 CloseHandle(This->handle_list[x]);
962 CoTaskMemFree(This->handle_list);
965 This->samples = pProps->cBuffers;
966 This->oldest_sample = 0;
967 TRACE("Samples: %u\n", This->samples);
968 This->sample_list = CoTaskMemAlloc(sizeof(This->sample_list[0]) * pProps->cBuffers);
969 This->handle_list = CoTaskMemAlloc(sizeof(HANDLE) * pProps->cBuffers * 2);
971 if (This->sample_list && This->handle_list)
973 int x;
974 ZeroMemory(This->sample_list, sizeof(This->sample_list[0]) * pProps->cBuffers);
975 for (x = 0; x < This->samples; ++x)
977 This->sample_list[x].ovl.hEvent = This->handle_list[x] = CreateEventW(NULL, 0, 0, NULL);
978 if (x + 1 < This->samples)
979 This->handle_list[This->samples + 1 + x] = This->handle_list[x];
981 This->handle_list[This->samples] = CreateEventW(NULL, 1, 0, NULL);
982 This->allocProps = *pProps;
984 else
986 hr = E_OUTOFMEMORY;
987 CoTaskMemFree(This->sample_list);
988 CoTaskMemFree(This->handle_list);
989 This->samples = 0;
990 This->sample_list = NULL;
991 This->handle_list = NULL;
995 if (FAILED(hr))
997 *ppActual = NULL;
998 if (pPreferred)
999 IMemAllocator_Release(pPreferred);
1002 TRACE("-- %x\n", hr);
1003 return hr;
1006 /* we could improve the Request/WaitForNext mechanism by allowing out of order samples.
1007 * however, this would be quite complicated to do and may be a bit error prone */
1008 static HRESULT WINAPI FileAsyncReader_Request(IAsyncReader * iface, IMediaSample * pSample, DWORD_PTR dwUser)
1010 HRESULT hr = S_OK;
1011 REFERENCE_TIME Start;
1012 REFERENCE_TIME Stop;
1013 FileAsyncReader *This = impl_from_IAsyncReader(iface);
1014 LPBYTE pBuffer = NULL;
1016 TRACE("(%p, %lx)\n", pSample, dwUser);
1018 if (!pSample)
1019 return E_POINTER;
1021 /* get start and stop positions in bytes */
1022 if (SUCCEEDED(hr))
1023 hr = IMediaSample_GetTime(pSample, &Start, &Stop);
1025 if (SUCCEEDED(hr))
1026 hr = IMediaSample_GetPointer(pSample, &pBuffer);
1028 EnterCriticalSection(&This->csList);
1029 if (This->bFlushing)
1031 LeaveCriticalSection(&This->csList);
1032 return VFW_E_WRONG_STATE;
1035 if (SUCCEEDED(hr))
1037 DWORD dwLength = (DWORD) BYTES_FROM_MEDIATIME(Stop - Start);
1038 DATAREQUEST *pDataRq;
1039 int x;
1041 /* Try to insert above the waiting sample if possible */
1042 for (x = This->oldest_sample; x < This->samples; ++x)
1044 if (!This->sample_list[x].pSample)
1045 break;
1048 if (x >= This->samples)
1049 for (x = 0; x < This->oldest_sample; ++x)
1051 if (!This->sample_list[x].pSample)
1052 break;
1055 /* There must be a sample we have found */
1056 assert(x < This->samples);
1057 ++This->queued_number;
1059 pDataRq = This->sample_list + x;
1061 pDataRq->ovl.u.s.Offset = (DWORD) BYTES_FROM_MEDIATIME(Start);
1062 pDataRq->ovl.u.s.OffsetHigh = (DWORD)(BYTES_FROM_MEDIATIME(Start) >> (sizeof(DWORD) * 8));
1063 pDataRq->dwUserData = dwUser;
1065 /* we violate traditional COM rules here by maintaining
1066 * a reference to the sample, but not calling AddRef, but
1067 * that's what MSDN says to do */
1068 pDataRq->pSample = pSample;
1070 /* this is definitely not how it is implemented on Win9x
1071 * as they do not support async reads on files, but it is
1072 * sooo much easier to use this than messing around with threads!
1074 if (!ReadFile(This->hFile, pBuffer, dwLength, NULL, &pDataRq->ovl))
1075 hr = HRESULT_FROM_WIN32(GetLastError());
1077 /* ERROR_IO_PENDING is not actually an error since this is what we want! */
1078 if (hr == HRESULT_FROM_WIN32(ERROR_IO_PENDING))
1079 hr = S_OK;
1082 LeaveCriticalSection(&This->csList);
1084 TRACE("-- %x\n", hr);
1085 return hr;
1088 static HRESULT WINAPI FileAsyncReader_WaitForNext(IAsyncReader * iface, DWORD dwTimeout, IMediaSample ** ppSample, DWORD_PTR * pdwUser)
1090 HRESULT hr = S_OK;
1091 FileAsyncReader *This = impl_from_IAsyncReader(iface);
1092 DWORD buffer = ~0;
1094 TRACE("(%u, %p, %p)\n", dwTimeout, ppSample, pdwUser);
1096 *ppSample = NULL;
1097 *pdwUser = 0;
1099 EnterCriticalSection(&This->csList);
1100 if (!This->bFlushing)
1102 LONG oldest = This->oldest_sample;
1104 if (!This->queued_number)
1106 /* It could be that nothing is queued right now, but that can be fixed */
1107 WARN("Called without samples in queue and not flushing!!\n");
1109 LeaveCriticalSection(&This->csList);
1111 /* wait for an object to read, or time out */
1112 buffer = WaitForMultipleObjectsEx(This->samples+1, This->handle_list + oldest, FALSE, dwTimeout, TRUE);
1114 EnterCriticalSection(&This->csList);
1115 if (buffer <= This->samples)
1117 /* Re-scale the buffer back to normal */
1118 buffer += oldest;
1120 /* Uh oh, we overshot the flusher handle, renormalize it back to 0..Samples-1 */
1121 if (buffer > This->samples)
1122 buffer -= This->samples + 1;
1123 assert(buffer <= This->samples);
1126 if (buffer >= This->samples)
1128 if (buffer != This->samples)
1130 FIXME("Returned: %u (%08x)\n", buffer, GetLastError());
1131 hr = VFW_E_TIMEOUT;
1133 else
1134 hr = VFW_E_WRONG_STATE;
1135 buffer = ~0;
1137 else
1138 --This->queued_number;
1141 if (This->bFlushing && buffer == ~0)
1143 for (buffer = 0; buffer < This->samples; ++buffer)
1145 if (This->sample_list[buffer].pSample)
1147 ResetEvent(This->handle_list[buffer]);
1148 break;
1151 if (buffer == This->samples)
1153 assert(!This->queued_number);
1154 hr = VFW_E_TIMEOUT;
1156 else
1158 --This->queued_number;
1159 hr = S_OK;
1163 if (SUCCEEDED(hr))
1165 REFERENCE_TIME rtStart, rtStop;
1166 REFERENCE_TIME rtSampleStart, rtSampleStop;
1167 DATAREQUEST *pDataRq = This->sample_list + buffer;
1168 DWORD dwBytes = 0;
1170 /* get any errors */
1171 if (!This->bFlushing && !GetOverlappedResult(This->hFile, &pDataRq->ovl, &dwBytes, FALSE))
1172 hr = HRESULT_FROM_WIN32(GetLastError());
1174 /* Return the sample no matter what so it can be destroyed */
1175 *ppSample = pDataRq->pSample;
1176 *pdwUser = pDataRq->dwUserData;
1178 if (This->bFlushing)
1179 hr = VFW_E_WRONG_STATE;
1181 if (FAILED(hr))
1182 dwBytes = 0;
1184 /* Set the time on the sample */
1185 IMediaSample_SetActualDataLength(pDataRq->pSample, dwBytes);
1187 rtStart = (DWORD64)pDataRq->ovl.u.s.Offset + ((DWORD64)pDataRq->ovl.u.s.OffsetHigh << 32);
1188 rtStart = MEDIATIME_FROM_BYTES(rtStart);
1189 rtStop = rtStart + MEDIATIME_FROM_BYTES(dwBytes);
1191 IMediaSample_GetTime(pDataRq->pSample, &rtSampleStart, &rtSampleStop);
1192 assert(rtStart == rtSampleStart);
1193 assert(rtStop <= rtSampleStop);
1195 IMediaSample_SetTime(pDataRq->pSample, &rtStart, &rtStop);
1196 assert(rtStart == rtSampleStart);
1197 if (hr == S_OK)
1198 assert(rtStop == rtSampleStop);
1199 else
1200 assert(rtStop == rtStart);
1202 This->sample_list[buffer].pSample = NULL;
1203 assert(This->oldest_sample < This->samples);
1205 if (buffer == This->oldest_sample)
1207 LONG x;
1208 for (x = This->oldest_sample + 1; x < This->samples; ++x)
1209 if (This->sample_list[x].pSample)
1210 break;
1211 if (x >= This->samples)
1212 for (x = 0; x < This->oldest_sample; ++x)
1213 if (This->sample_list[x].pSample)
1214 break;
1215 if (This->oldest_sample == x)
1216 /* No samples found, reset to 0 */
1217 x = 0;
1218 This->oldest_sample = x;
1221 LeaveCriticalSection(&This->csList);
1223 TRACE("-- %x\n", hr);
1224 return hr;
1227 static HRESULT WINAPI FileAsyncReader_SyncRead(IAsyncReader * iface, LONGLONG llPosition, LONG lLength, BYTE * pBuffer);
1229 static HRESULT WINAPI FileAsyncReader_SyncReadAligned(IAsyncReader * iface, IMediaSample * pSample)
1231 BYTE * pBuffer;
1232 REFERENCE_TIME tStart;
1233 REFERENCE_TIME tStop;
1234 HRESULT hr;
1236 TRACE("(%p)\n", pSample);
1238 hr = IMediaSample_GetTime(pSample, &tStart, &tStop);
1240 if (SUCCEEDED(hr))
1241 hr = IMediaSample_GetPointer(pSample, &pBuffer);
1243 if (SUCCEEDED(hr))
1244 hr = FileAsyncReader_SyncRead(iface,
1245 BYTES_FROM_MEDIATIME(tStart),
1246 (LONG) BYTES_FROM_MEDIATIME(tStop - tStart),
1247 pBuffer);
1249 TRACE("-- %x\n", hr);
1250 return hr;
1253 static HRESULT WINAPI FileAsyncReader_SyncRead(IAsyncReader * iface, LONGLONG llPosition, LONG lLength, BYTE * pBuffer)
1255 OVERLAPPED ovl;
1256 HRESULT hr = S_OK;
1257 FileAsyncReader *This = impl_from_IAsyncReader(iface);
1259 TRACE("(%x%08x, %d, %p)\n", (ULONG)(llPosition >> 32), (ULONG)llPosition, lLength, pBuffer);
1261 ZeroMemory(&ovl, sizeof(ovl));
1263 ovl.hEvent = CreateEventW(NULL, 0, 0, NULL);
1264 /* NOTE: llPosition is the actual byte position to start reading from */
1265 ovl.u.s.Offset = (DWORD) llPosition;
1266 ovl.u.s.OffsetHigh = (DWORD) (llPosition >> (sizeof(DWORD) * 8));
1268 if (!ReadFile(This->hFile, pBuffer, lLength, NULL, &ovl))
1269 hr = HRESULT_FROM_WIN32(GetLastError());
1271 if (hr == HRESULT_FROM_WIN32(ERROR_IO_PENDING))
1272 hr = S_OK;
1274 if (SUCCEEDED(hr))
1276 DWORD dwBytesRead;
1278 if (!GetOverlappedResult(This->hFile, &ovl, &dwBytesRead, TRUE))
1279 hr = HRESULT_FROM_WIN32(GetLastError());
1282 CloseHandle(ovl.hEvent);
1284 TRACE("-- %x\n", hr);
1285 return hr;
1288 static HRESULT WINAPI FileAsyncReader_Length(IAsyncReader * iface, LONGLONG * pTotal, LONGLONG * pAvailable)
1290 DWORD dwSizeLow;
1291 DWORD dwSizeHigh;
1292 FileAsyncReader *This = impl_from_IAsyncReader(iface);
1294 TRACE("(%p, %p)\n", pTotal, pAvailable);
1296 if (((dwSizeLow = GetFileSize(This->hFile, &dwSizeHigh)) == -1) &&
1297 (GetLastError() != NO_ERROR))
1298 return HRESULT_FROM_WIN32(GetLastError());
1300 *pTotal = (LONGLONG)dwSizeLow | (LONGLONG)dwSizeHigh << (sizeof(DWORD) * 8);
1302 *pAvailable = *pTotal;
1304 return S_OK;
1307 static HRESULT WINAPI FileAsyncReader_BeginFlush(IAsyncReader * iface)
1309 FileAsyncReader *This = impl_from_IAsyncReader(iface);
1311 TRACE("()\n");
1313 EnterCriticalSection(&This->csList);
1314 This->bFlushing = TRUE;
1315 CancelIo(This->hFile);
1316 SetEvent(This->handle_list[This->samples]);
1317 LeaveCriticalSection(&This->csList);
1319 return S_OK;
1322 static HRESULT WINAPI FileAsyncReader_EndFlush(IAsyncReader * iface)
1324 FileAsyncReader *This = impl_from_IAsyncReader(iface);
1325 int x;
1327 TRACE("()\n");
1329 EnterCriticalSection(&This->csList);
1330 ResetEvent(This->handle_list[This->samples]);
1331 This->bFlushing = FALSE;
1332 for (x = 0; x < This->samples; ++x)
1333 assert(!This->sample_list[x].pSample);
1335 LeaveCriticalSection(&This->csList);
1337 return S_OK;
1340 static const IAsyncReaderVtbl FileAsyncReader_Vtbl =
1342 FileAsyncReader_QueryInterface,
1343 FileAsyncReader_AddRef,
1344 FileAsyncReader_Release,
1345 FileAsyncReader_RequestAllocator,
1346 FileAsyncReader_Request,
1347 FileAsyncReader_WaitForNext,
1348 FileAsyncReader_SyncReadAligned,
1349 FileAsyncReader_SyncRead,
1350 FileAsyncReader_Length,
1351 FileAsyncReader_BeginFlush,
1352 FileAsyncReader_EndFlush,
1356 static AsyncReader *from_IAMFilterMiscFlags(IAMFilterMiscFlags *iface) {
1357 return (AsyncReader*)((char*)iface - offsetof(AsyncReader, IAMFilterMiscFlags_vtbl));
1360 static HRESULT WINAPI AMFilterMiscFlags_QueryInterface(IAMFilterMiscFlags *iface, const REFIID riid, void **ppv) {
1361 AsyncReader *This = from_IAMFilterMiscFlags(iface);
1362 return IUnknown_QueryInterface((IUnknown*)This, riid, ppv);
1365 static ULONG WINAPI AMFilterMiscFlags_AddRef(IAMFilterMiscFlags *iface) {
1366 AsyncReader *This = from_IAMFilterMiscFlags(iface);
1367 return IUnknown_AddRef((IUnknown*)This);
1370 static ULONG WINAPI AMFilterMiscFlags_Release(IAMFilterMiscFlags *iface) {
1371 AsyncReader *This = from_IAMFilterMiscFlags(iface);
1372 return IUnknown_Release((IUnknown*)This);
1375 static ULONG WINAPI AMFilterMiscFlags_GetMiscFlags(IAMFilterMiscFlags *iface) {
1376 return AM_FILTER_MISC_FLAGS_IS_SOURCE;
1379 static const IAMFilterMiscFlagsVtbl IAMFilterMiscFlags_Vtbl = {
1380 AMFilterMiscFlags_QueryInterface,
1381 AMFilterMiscFlags_AddRef,
1382 AMFilterMiscFlags_Release,
1383 AMFilterMiscFlags_GetMiscFlags