quartz: Fix discontinuities in wave parser.
[wine] / dlls / quartz / filesource.c
1 /*
2  * File Source Filter
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
21 #define NONAMELESSUNION
22 #define NONAMELESSSTRUCT
23
24 #include "quartz_private.h"
25
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>
35
36 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
37
38 static const WCHAR wszOutputPinName[] = { 'O','u','t','p','u','t',0 };
39
40 typedef struct AsyncReader
41 {
42     const IBaseFilterVtbl * lpVtbl;
43     const IFileSourceFilterVtbl * lpVtblFSF;
44
45     LONG refCount;
46     FILTER_INFO filterInfo;
47     FILTER_STATE state;
48     CRITICAL_SECTION csFilter;
49
50     IPin * pOutputPin;
51     LPOLESTR pszFileName;
52     AM_MEDIA_TYPE * pmt;
53 } AsyncReader;
54
55 static const IBaseFilterVtbl AsyncReader_Vtbl;
56 static const IFileSourceFilterVtbl FileSource_Vtbl;
57 static const IAsyncReaderVtbl FileAsyncReader_Vtbl;
58
59 static HRESULT FileAsyncReader_Construct(HANDLE hFile, IBaseFilter * pBaseFilter, LPCRITICAL_SECTION pCritSec, IPin ** ppPin);
60
61 static inline AsyncReader *impl_from_IFileSourceFilter( IFileSourceFilter *iface )
62 {
63     return (AsyncReader *)((char*)iface - FIELD_OFFSET(AsyncReader, lpVtblFSF));
64 }
65
66 static WCHAR const mediatype_name[11] = {
67     'M', 'e', 'd', 'i', 'a', ' ', 'T', 'y', 'p', 'e', 0 };
68 static WCHAR const subtype_name[8] = {
69     'S', 'u', 'b', 't', 'y', 'p', 'e', 0 };
70
71 static HRESULT process_extensions(HKEY hkeyExtensions, LPCOLESTR pszFileName, GUID * majorType, GUID * minorType)
72 {
73     WCHAR *extension;
74     LONG l;
75     HKEY hsub;
76     WCHAR keying[39];
77     DWORD size;
78
79     if (!pszFileName)
80         return E_POINTER;
81
82     /* Get the part of the name that matters */
83     extension = PathFindExtensionW(pszFileName);
84     if (*extension != '.')
85         return E_FAIL;
86
87     l = RegOpenKeyExW(hkeyExtensions, extension, 0, KEY_READ, &hsub);
88     if (l)
89         return E_FAIL;
90
91     size = sizeof(keying);
92     l = RegQueryValueExW(hsub, mediatype_name, NULL, NULL, (LPBYTE)keying, &size);
93     if (!l)
94         CLSIDFromString(keying, majorType);
95
96     size = sizeof(keying);
97     if (!l)
98         l = RegQueryValueExW(hsub, subtype_name, NULL, NULL, (LPBYTE)keying, &size);
99
100     if (!l)
101         CLSIDFromString(keying, minorType);
102
103     RegCloseKey(hsub);
104
105     if (!l)
106         return S_OK;
107     return E_FAIL;
108 }
109
110 static unsigned char byte_from_hex_char(WCHAR wHex)
111 {
112     switch (tolowerW(wHex))
113     {
114     case '0':
115     case '1':
116     case '2':
117     case '3':
118     case '4':
119     case '5':
120     case '6':
121     case '7':
122     case '8':
123     case '9':
124         return (wHex - '0') & 0xf;
125     case 'a':
126     case 'b':
127     case 'c':
128     case 'd':
129     case 'e':
130     case 'f':
131         return (wHex - 'a' + 10) & 0xf;
132     default:
133         return 0;
134     }
135 }
136
137 static HRESULT process_pattern_string(LPCWSTR wszPatternString, IAsyncReader * pReader)
138 {
139     ULONG ulOffset;
140     ULONG ulBytes;
141     BYTE * pbMask;
142     BYTE * pbValue;
143     BYTE * pbFile;
144     HRESULT hr = S_OK;
145     ULONG strpos;
146
147     TRACE("\t\tPattern string: %s\n", debugstr_w(wszPatternString));
148     
149     /* format: "offset, bytestocompare, mask, value" */
150
151     ulOffset = strtolW(wszPatternString, NULL, 10);
152
153     if (!(wszPatternString = strchrW(wszPatternString, ',')))
154         return E_INVALIDARG;
155
156     wszPatternString++; /* skip ',' */
157
158     ulBytes = strtolW(wszPatternString, NULL, 10);
159
160     pbMask = HeapAlloc(GetProcessHeap(), 0, ulBytes);
161     pbValue = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, ulBytes);
162     pbFile = HeapAlloc(GetProcessHeap(), 0, ulBytes);
163
164     /* default mask is match everything */
165     memset(pbMask, 0xFF, ulBytes);
166
167     if (!(wszPatternString = strchrW(wszPatternString, ',')))
168         hr = E_INVALIDARG;
169
170     wszPatternString++; /* skip ',' */
171
172     if (hr == S_OK)
173     {
174         for ( ; !isxdigitW(*wszPatternString) && (*wszPatternString != ','); wszPatternString++)
175             ;
176
177         for (strpos = 0; isxdigitW(*wszPatternString) && (strpos/2 < ulBytes); wszPatternString++, strpos++)
178         {
179             if ((strpos % 2) == 1) /* odd numbered position */
180                 pbMask[strpos / 2] |= byte_from_hex_char(*wszPatternString);
181             else
182                 pbMask[strpos / 2] = byte_from_hex_char(*wszPatternString) << 4;
183         }
184
185         if (!(wszPatternString = strchrW(wszPatternString, ',')))
186             hr = E_INVALIDARG;
187     
188         wszPatternString++; /* skip ',' */
189     }
190
191     if (hr == S_OK)
192     {
193         for ( ; !isxdigitW(*wszPatternString) && (*wszPatternString != ','); wszPatternString++)
194             ;
195
196         for (strpos = 0; isxdigitW(*wszPatternString) && (strpos/2 < ulBytes); wszPatternString++, strpos++)
197         {
198             if ((strpos % 2) == 1) /* odd numbered position */
199                 pbValue[strpos / 2] |= byte_from_hex_char(*wszPatternString);
200             else
201                 pbValue[strpos / 2] = byte_from_hex_char(*wszPatternString) << 4;
202         }
203     }
204
205     if (hr == S_OK)
206         hr = IAsyncReader_SyncRead(pReader, ulOffset, ulBytes, pbFile);
207
208     if (hr == S_OK)
209     {
210         ULONG i;
211         for (i = 0; i < ulBytes; i++)
212             if ((pbFile[i] & pbMask[i]) != pbValue[i])
213             {
214                 hr = S_FALSE;
215                 break;
216             }
217     }
218
219     HeapFree(GetProcessHeap(), 0, pbMask);
220     HeapFree(GetProcessHeap(), 0, pbValue);
221     HeapFree(GetProcessHeap(), 0, pbFile);
222
223     /* if we encountered no errors with this string, and there is a following tuple, then we
224      * have to match that as well to succeed */
225     if ((hr == S_OK) && (wszPatternString = strchrW(wszPatternString, ',')))
226         return process_pattern_string(wszPatternString + 1, pReader);
227     else
228         return hr;
229 }
230
231 static HRESULT GetClassMediaFile(IAsyncReader * pReader, LPCOLESTR pszFileName, GUID * majorType, GUID * minorType)
232 {
233     HKEY hkeyMediaType = NULL;
234     LONG lRet;
235     HRESULT hr = S_OK;
236     BOOL bFound = FALSE;
237     static const WCHAR wszMediaType[] = {'M','e','d','i','a',' ','T','y','p','e',0};
238
239     TRACE("(%p, %s, %p, %p)\n", pReader, debugstr_w(pszFileName), majorType, minorType);
240
241     *majorType = GUID_NULL;
242     *minorType = GUID_NULL;
243
244     lRet = RegOpenKeyExW(HKEY_CLASSES_ROOT, wszMediaType, 0, KEY_READ, &hkeyMediaType);
245     hr = HRESULT_FROM_WIN32(lRet);
246
247     if (SUCCEEDED(hr))
248     {
249         DWORD indexMajor;
250
251         for (indexMajor = 0; !bFound; indexMajor++)
252         {
253             HKEY hkeyMajor;
254             WCHAR wszMajorKeyName[CHARS_IN_GUID];
255             DWORD dwKeyNameLength = sizeof(wszMajorKeyName) / sizeof(wszMajorKeyName[0]);
256             static const WCHAR wszExtensions[] = {'E','x','t','e','n','s','i','o','n','s',0};
257
258             if (RegEnumKeyExW(hkeyMediaType, indexMajor, wszMajorKeyName, &dwKeyNameLength, NULL, NULL, NULL, NULL) != ERROR_SUCCESS)
259                 break;
260             if (RegOpenKeyExW(hkeyMediaType, wszMajorKeyName, 0, KEY_READ, &hkeyMajor) != ERROR_SUCCESS)
261                 break;
262             TRACE("%s\n", debugstr_w(wszMajorKeyName));
263             if (!strcmpW(wszExtensions, wszMajorKeyName))
264             {
265                 if (process_extensions(hkeyMajor, pszFileName, majorType, minorType) == S_OK)
266                     bFound = TRUE;
267             }
268             else
269             {
270                 DWORD indexMinor;
271
272                 for (indexMinor = 0; !bFound; indexMinor++)
273                 {
274                     HKEY hkeyMinor;
275                     WCHAR wszMinorKeyName[CHARS_IN_GUID];
276                     DWORD dwMinorKeyNameLen = sizeof(wszMinorKeyName) / sizeof(wszMinorKeyName[0]);
277                     DWORD maxValueLen;
278                     DWORD indexValue;
279
280                     if (RegEnumKeyExW(hkeyMajor, indexMinor, wszMinorKeyName, &dwMinorKeyNameLen, NULL, NULL, NULL, NULL) != ERROR_SUCCESS)
281                         break;
282
283                     if (RegOpenKeyExW(hkeyMajor, wszMinorKeyName, 0, KEY_READ, &hkeyMinor) != ERROR_SUCCESS)
284                         break;
285
286                     TRACE("\t%s\n", debugstr_w(wszMinorKeyName));
287         
288                     if (RegQueryInfoKeyW(hkeyMinor, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &maxValueLen, NULL, NULL) != ERROR_SUCCESS)
289                         break;
290
291                     for (indexValue = 0; !bFound; indexValue++)
292                     {
293                         DWORD dwType;
294                         WCHAR wszValueName[14]; /* longest name we should encounter will be "Source Filter" */
295                         LPWSTR wszPatternString = HeapAlloc(GetProcessHeap(), 0, maxValueLen);
296                         DWORD dwValueNameLen = sizeof(wszValueName) / sizeof(wszValueName[0]); /* remember this is in chars */
297                         DWORD dwDataLen = maxValueLen; /* remember this is in bytes */
298                         static const WCHAR wszSourceFilter[] = {'S','o','u','r','c','e',' ','F','i','l','t','e','r',0};
299                         LONG temp;
300
301                         if ((temp = RegEnumValueW(hkeyMinor, indexValue, wszValueName, &dwValueNameLen, NULL, &dwType, (LPBYTE)wszPatternString, &dwDataLen)) != ERROR_SUCCESS)
302                         {
303                             HeapFree(GetProcessHeap(), 0, wszPatternString);
304                             break;
305                         }
306
307                         /* if it is not the source filter value */
308                         if (strcmpW(wszValueName, wszSourceFilter))
309                         {
310                             if (process_pattern_string(wszPatternString, pReader) == S_OK)
311                             {
312                                 if (SUCCEEDED(CLSIDFromString(wszMajorKeyName, majorType)) &&
313                                     SUCCEEDED(CLSIDFromString(wszMinorKeyName, minorType)))
314                                     bFound = TRUE;
315                             }
316                         }
317                         HeapFree(GetProcessHeap(), 0, wszPatternString);
318                     }
319                     CloseHandle(hkeyMinor);
320                 }
321             }
322             CloseHandle(hkeyMajor);
323         }
324     }
325     CloseHandle(hkeyMediaType);
326
327     if (SUCCEEDED(hr) && !bFound)
328     {
329         ERR("Media class not found\n");
330         hr = E_FAIL;
331     }
332     else if (bFound)
333         TRACE("Found file's class: major = %s, subtype = %s\n", qzdebugstr_guid(majorType), qzdebugstr_guid(minorType));
334
335     return hr;
336 }
337
338 HRESULT AsyncReader_create(IUnknown * pUnkOuter, LPVOID * ppv)
339 {
340     AsyncReader *pAsyncRead;
341     
342     if( pUnkOuter )
343         return CLASS_E_NOAGGREGATION;
344     
345     pAsyncRead = CoTaskMemAlloc(sizeof(AsyncReader));
346
347     if (!pAsyncRead)
348         return E_OUTOFMEMORY;
349
350     pAsyncRead->lpVtbl = &AsyncReader_Vtbl;
351     pAsyncRead->lpVtblFSF = &FileSource_Vtbl;
352     pAsyncRead->refCount = 1;
353     pAsyncRead->filterInfo.achName[0] = '\0';
354     pAsyncRead->filterInfo.pGraph = NULL;
355     pAsyncRead->pOutputPin = NULL;
356
357     InitializeCriticalSection(&pAsyncRead->csFilter);
358     pAsyncRead->csFilter.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": AsyncReader.csFilter");
359
360     pAsyncRead->pszFileName = NULL;
361     pAsyncRead->pmt = NULL;
362
363     *ppv = (LPVOID)pAsyncRead;
364
365     TRACE("-- created at %p\n", pAsyncRead);
366
367     return S_OK;
368 }
369
370 /** IUnknown methods **/
371
372 static HRESULT WINAPI AsyncReader_QueryInterface(IBaseFilter * iface, REFIID riid, LPVOID * ppv)
373 {
374     AsyncReader *This = (AsyncReader *)iface;
375
376     TRACE("(%s, %p)\n", qzdebugstr_guid(riid), ppv);
377
378     *ppv = NULL;
379
380     if (IsEqualIID(riid, &IID_IUnknown))
381         *ppv = (LPVOID)This;
382     else if (IsEqualIID(riid, &IID_IPersist))
383         *ppv = (LPVOID)This;
384     else if (IsEqualIID(riid, &IID_IMediaFilter))
385         *ppv = (LPVOID)This;
386     else if (IsEqualIID(riid, &IID_IBaseFilter))
387         *ppv = (LPVOID)This;
388     else if (IsEqualIID(riid, &IID_IFileSourceFilter))
389         *ppv = (LPVOID)(&This->lpVtblFSF);
390
391     if (*ppv)
392     {
393         IUnknown_AddRef((IUnknown *)(*ppv));
394         return S_OK;
395     }
396
397     if (!IsEqualIID(riid, &IID_IPin) && !IsEqualIID(riid, &IID_IMediaSeeking) && !IsEqualIID(riid, &IID_IVideoWindow))
398         FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
399
400     return E_NOINTERFACE;
401 }
402
403 static ULONG WINAPI AsyncReader_AddRef(IBaseFilter * iface)
404 {
405     AsyncReader *This = (AsyncReader *)iface;
406     ULONG refCount = InterlockedIncrement(&This->refCount);
407     
408     TRACE("(%p)->() AddRef from %d\n", This, refCount - 1);
409     
410     return refCount;
411 }
412
413 static ULONG WINAPI AsyncReader_Release(IBaseFilter * iface)
414 {
415     AsyncReader *This = (AsyncReader *)iface;
416     ULONG refCount = InterlockedDecrement(&This->refCount);
417     
418     TRACE("(%p)->() Release from %d\n", This, refCount + 1);
419     
420     if (!refCount)
421     {
422         if (This->pOutputPin)
423         {
424             IPin *pConnectedTo;
425             if(SUCCEEDED(IPin_ConnectedTo(This->pOutputPin, &pConnectedTo)))
426             {
427                 IPin_Disconnect(pConnectedTo);
428                 IPin_Release(pConnectedTo);
429             }
430             IPin_Disconnect(This->pOutputPin);
431             IPin_Release(This->pOutputPin);
432         }
433         This->csFilter.DebugInfo->Spare[0] = 0;
434         DeleteCriticalSection(&This->csFilter);
435         This->lpVtbl = NULL;
436         CoTaskMemFree(This->pszFileName);
437         if (This->pmt)
438             FreeMediaType(This->pmt);
439         CoTaskMemFree(This);
440         return 0;
441     }
442     else
443         return refCount;
444 }
445
446 /** IPersist methods **/
447
448 static HRESULT WINAPI AsyncReader_GetClassID(IBaseFilter * iface, CLSID * pClsid)
449 {
450     TRACE("(%p)\n", pClsid);
451
452     *pClsid = CLSID_AsyncReader;
453
454     return S_OK;
455 }
456
457 /** IMediaFilter methods **/
458
459 static HRESULT WINAPI AsyncReader_Stop(IBaseFilter * iface)
460 {
461     AsyncReader *This = (AsyncReader *)iface;
462
463     TRACE("()\n");
464
465     This->state = State_Stopped;
466     
467     return S_OK;
468 }
469
470 static HRESULT WINAPI AsyncReader_Pause(IBaseFilter * iface)
471 {
472     AsyncReader *This = (AsyncReader *)iface;
473
474     TRACE("()\n");
475
476     This->state = State_Paused;
477
478     return S_OK;
479 }
480
481 static HRESULT WINAPI AsyncReader_Run(IBaseFilter * iface, REFERENCE_TIME tStart)
482 {
483     AsyncReader *This = (AsyncReader *)iface;
484
485     TRACE("(%x%08x)\n", (ULONG)(tStart >> 32), (ULONG)tStart);
486
487     This->state = State_Running;
488
489     return S_OK;
490 }
491
492 static HRESULT WINAPI AsyncReader_GetState(IBaseFilter * iface, DWORD dwMilliSecsTimeout, FILTER_STATE *pState)
493 {
494     AsyncReader *This = (AsyncReader *)iface;
495
496     TRACE("(%u, %p)\n", dwMilliSecsTimeout, pState);
497
498     *pState = This->state;
499     
500     return S_OK;
501 }
502
503 static HRESULT WINAPI AsyncReader_SetSyncSource(IBaseFilter * iface, IReferenceClock *pClock)
504 {
505 /*    AsyncReader *This = (AsyncReader *)iface;*/
506
507     TRACE("(%p)\n", pClock);
508
509     return S_OK;
510 }
511
512 static HRESULT WINAPI AsyncReader_GetSyncSource(IBaseFilter * iface, IReferenceClock **ppClock)
513 {
514 /*    AsyncReader *This = (AsyncReader *)iface;*/
515
516     TRACE("(%p)\n", ppClock);
517
518     return S_OK;
519 }
520
521 /** IBaseFilter methods **/
522
523 static HRESULT WINAPI AsyncReader_EnumPins(IBaseFilter * iface, IEnumPins **ppEnum)
524 {
525     ENUMPINDETAILS epd;
526     AsyncReader *This = (AsyncReader *)iface;
527
528     TRACE("(%p)\n", ppEnum);
529
530     epd.cPins = This->pOutputPin ? 1 : 0;
531     epd.ppPins = &This->pOutputPin;
532     return IEnumPinsImpl_Construct(&epd, ppEnum);
533 }
534
535 static HRESULT WINAPI AsyncReader_FindPin(IBaseFilter * iface, LPCWSTR Id, IPin **ppPin)
536 {
537     FIXME("(%s, %p)\n", debugstr_w(Id), ppPin);
538
539     return E_NOTIMPL;
540 }
541
542 static HRESULT WINAPI AsyncReader_QueryFilterInfo(IBaseFilter * iface, FILTER_INFO *pInfo)
543 {
544     AsyncReader *This = (AsyncReader *)iface;
545
546     TRACE("(%p)\n", pInfo);
547
548     strcpyW(pInfo->achName, This->filterInfo.achName);
549     pInfo->pGraph = This->filterInfo.pGraph;
550
551     if (pInfo->pGraph)
552         IFilterGraph_AddRef(pInfo->pGraph);
553     
554     return S_OK;
555 }
556
557 static HRESULT WINAPI AsyncReader_JoinFilterGraph(IBaseFilter * iface, IFilterGraph *pGraph, LPCWSTR pName)
558 {
559     AsyncReader *This = (AsyncReader *)iface;
560
561     TRACE("(%p, %s)\n", pGraph, debugstr_w(pName));
562
563     if (pName)
564         strcpyW(This->filterInfo.achName, pName);
565     else
566         *This->filterInfo.achName = 0;
567     This->filterInfo.pGraph = pGraph; /* NOTE: do NOT increase ref. count */
568
569     return S_OK;
570 }
571
572 static HRESULT WINAPI AsyncReader_QueryVendorInfo(IBaseFilter * iface, LPWSTR *pVendorInfo)
573 {
574     FIXME("(%p)\n", pVendorInfo);
575
576     return E_NOTIMPL;
577 }
578
579 static const IBaseFilterVtbl AsyncReader_Vtbl =
580 {
581     AsyncReader_QueryInterface,
582     AsyncReader_AddRef,
583     AsyncReader_Release,
584     AsyncReader_GetClassID,
585     AsyncReader_Stop,
586     AsyncReader_Pause,
587     AsyncReader_Run,
588     AsyncReader_GetState,
589     AsyncReader_SetSyncSource,
590     AsyncReader_GetSyncSource,
591     AsyncReader_EnumPins,
592     AsyncReader_FindPin,
593     AsyncReader_QueryFilterInfo,
594     AsyncReader_JoinFilterGraph,
595     AsyncReader_QueryVendorInfo
596 };
597
598 static HRESULT WINAPI FileSource_QueryInterface(IFileSourceFilter * iface, REFIID riid, LPVOID * ppv)
599 {
600     AsyncReader *This = impl_from_IFileSourceFilter(iface);
601
602     return IBaseFilter_QueryInterface((IFileSourceFilter*)&This->lpVtbl, riid, ppv);
603 }
604
605 static ULONG WINAPI FileSource_AddRef(IFileSourceFilter * iface)
606 {
607     AsyncReader *This = impl_from_IFileSourceFilter(iface);
608
609     return IBaseFilter_AddRef((IFileSourceFilter*)&This->lpVtbl);
610 }
611
612 static ULONG WINAPI FileSource_Release(IFileSourceFilter * iface)
613 {
614     AsyncReader *This = impl_from_IFileSourceFilter(iface);
615
616     return IBaseFilter_Release((IFileSourceFilter*)&This->lpVtbl);
617 }
618
619 static HRESULT WINAPI FileSource_Load(IFileSourceFilter * iface, LPCOLESTR pszFileName, const AM_MEDIA_TYPE * pmt)
620 {
621     HRESULT hr;
622     HANDLE hFile;
623     IAsyncReader * pReader = NULL;
624     AsyncReader *This = impl_from_IFileSourceFilter(iface);
625
626     TRACE("(%s, %p)\n", debugstr_w(pszFileName), pmt);
627
628     /* open file */
629     /* FIXME: check the sharing values that native uses */
630     hFile = CreateFileW(pszFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);
631
632     if (hFile == INVALID_HANDLE_VALUE)
633     {
634         return HRESULT_FROM_WIN32(GetLastError());
635     }
636
637     /* create pin */
638     hr = FileAsyncReader_Construct(hFile, (IBaseFilter *)&This->lpVtbl, &This->csFilter, &This->pOutputPin);
639
640     if (SUCCEEDED(hr))
641         hr = IPin_QueryInterface(This->pOutputPin, &IID_IAsyncReader, (LPVOID *)&pReader);
642
643     /* store file name & media type */
644     if (SUCCEEDED(hr))
645     {
646         CoTaskMemFree(This->pszFileName);
647         if (This->pmt)
648             FreeMediaType(This->pmt);
649
650         This->pszFileName = CoTaskMemAlloc((strlenW(pszFileName) + 1) * sizeof(WCHAR));
651         strcpyW(This->pszFileName, pszFileName);
652
653         This->pmt = CoTaskMemAlloc(sizeof(AM_MEDIA_TYPE));
654         if (!pmt)
655         {
656             This->pmt->bFixedSizeSamples = TRUE;
657             This->pmt->bTemporalCompression = FALSE;
658             This->pmt->cbFormat = 0;
659             This->pmt->pbFormat = NULL;
660             This->pmt->pUnk = NULL;
661             This->pmt->lSampleSize = 0;
662             This->pmt->formattype = FORMAT_None;
663             hr = GetClassMediaFile(pReader, pszFileName, &This->pmt->majortype, &This->pmt->subtype);
664             if (FAILED(hr))
665             {
666                 CoTaskMemFree(This->pmt);
667                 This->pmt = NULL;
668             }
669         }
670         else
671             CopyMediaType(This->pmt, pmt);
672     }
673
674     if (pReader)
675         IAsyncReader_Release(pReader);
676
677     if (FAILED(hr))
678     {
679         if (This->pOutputPin)
680         {
681             IPin_Release(This->pOutputPin);
682             This->pOutputPin = NULL;
683         }
684
685         CoTaskMemFree(This->pszFileName);
686         if (This->pmt)
687             FreeMediaType(This->pmt);
688         This->pszFileName = NULL;
689         This->pmt = NULL;
690
691         CloseHandle(hFile);
692     }
693
694     /* FIXME: check return codes */
695     return hr;
696 }
697
698 static HRESULT WINAPI FileSource_GetCurFile(IFileSourceFilter * iface, LPOLESTR * ppszFileName, AM_MEDIA_TYPE * pmt)
699 {
700     AsyncReader *This = impl_from_IFileSourceFilter(iface);
701     
702     TRACE("(%p, %p)\n", ppszFileName, pmt);
703
704     if (!ppszFileName)
705         return E_POINTER;
706
707     /* copy file name & media type if available, otherwise clear the outputs */
708     if (This->pszFileName)
709     {
710         *ppszFileName = CoTaskMemAlloc((strlenW(This->pszFileName) + 1) * sizeof(WCHAR));
711         strcpyW(*ppszFileName, This->pszFileName);
712     }
713     else
714         *ppszFileName = NULL;
715
716     if (pmt)
717     {
718         if (This->pmt)
719             CopyMediaType(pmt, This->pmt);
720         else
721             ZeroMemory(pmt, sizeof(*pmt));
722     }
723
724     return S_OK;
725 }
726
727 static const IFileSourceFilterVtbl FileSource_Vtbl = 
728 {
729     FileSource_QueryInterface,
730     FileSource_AddRef,
731     FileSource_Release,
732     FileSource_Load,
733     FileSource_GetCurFile
734 };
735
736
737 /* the dwUserData passed back to user */
738 typedef struct DATAREQUEST
739 {
740     IMediaSample * pSample; /* sample passed to us by user */
741     DWORD_PTR dwUserData; /* user data passed to us */
742     OVERLAPPED ovl; /* our overlapped structure */
743
744     struct DATAREQUEST * pNext; /* next data request in list */
745 } DATAREQUEST;
746
747 static void queue(DATAREQUEST * pHead, DATAREQUEST * pItem)
748 {
749     DATAREQUEST * pCurrent;
750     for (pCurrent = pHead; pCurrent->pNext; pCurrent = pCurrent->pNext)
751         ;
752     pCurrent->pNext = pItem;
753 }
754
755 typedef struct FileAsyncReader
756 {
757     OutputPin pin;
758     const struct IAsyncReaderVtbl * lpVtblAR;
759
760     HANDLE hFile;
761     HANDLE hEvent;
762     BOOL bFlushing;
763     DATAREQUEST * pHead; /* head of data request list */
764     CRITICAL_SECTION csList; /* critical section to protect operations on list */
765 } FileAsyncReader;
766
767 static inline FileAsyncReader *impl_from_IAsyncReader( IAsyncReader *iface )
768 {
769     return (FileAsyncReader *)((char*)iface - FIELD_OFFSET(FileAsyncReader, lpVtblAR));
770 }
771
772 static HRESULT AcceptProcAFR(LPVOID iface, const AM_MEDIA_TYPE *pmt)
773 {
774     AsyncReader *This = (AsyncReader *)iface;
775     
776     FIXME("(%p, %p)\n", iface, pmt);
777
778     if (IsEqualGUID(&pmt->majortype, &This->pmt->majortype) &&
779         IsEqualGUID(&pmt->subtype, &This->pmt->subtype) &&
780         IsEqualGUID(&pmt->formattype, &FORMAT_None))
781         return S_OK;
782     
783     return S_FALSE;
784 }
785
786 /* overriden pin functions */
787
788 static HRESULT WINAPI FileAsyncReaderPin_QueryInterface(IPin * iface, REFIID riid, LPVOID * ppv)
789 {
790     FileAsyncReader *This = (FileAsyncReader *)iface;
791     TRACE("(%s, %p)\n", qzdebugstr_guid(riid), ppv);
792
793     *ppv = NULL;
794
795     if (IsEqualIID(riid, &IID_IUnknown))
796         *ppv = (LPVOID)This;
797     else if (IsEqualIID(riid, &IID_IPin))
798         *ppv = (LPVOID)This;
799     else if (IsEqualIID(riid, &IID_IAsyncReader))
800         *ppv = (LPVOID)&This->lpVtblAR;
801
802     if (*ppv)
803     {
804         IUnknown_AddRef((IUnknown *)(*ppv));
805         return S_OK;
806     }
807
808     if (!IsEqualIID(riid, &IID_IPin) && !IsEqualIID(riid, &IID_IMediaSeeking))
809         FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
810
811     return E_NOINTERFACE;
812 }
813
814 static ULONG WINAPI FileAsyncReaderPin_Release(IPin * iface)
815 {
816     FileAsyncReader *This = (FileAsyncReader *)iface;
817     ULONG refCount = InterlockedDecrement(&This->pin.pin.refCount);
818     
819     TRACE("(%p)->() Release from %d\n", This, refCount + 1);
820     
821     if (!refCount)
822     {
823         DATAREQUEST * pCurrent;
824         DATAREQUEST * pNext;
825         for (pCurrent = This->pHead; pCurrent; pCurrent = pNext)
826         {
827             pNext = pCurrent->pNext;
828             CoTaskMemFree(pCurrent);
829         }
830         CloseHandle(This->hFile);
831         CloseHandle(This->hEvent);
832         This->csList.DebugInfo->Spare[0] = 0;
833         DeleteCriticalSection(&This->csList);
834         CoTaskMemFree(This);
835         return 0;
836     }
837     return refCount;
838 }
839
840 static HRESULT WINAPI FileAsyncReaderPin_EnumMediaTypes(IPin * iface, IEnumMediaTypes ** ppEnum)
841 {
842     ENUMMEDIADETAILS emd;
843     FileAsyncReader *This = (FileAsyncReader *)iface;
844
845     TRACE("(%p)\n", ppEnum);
846
847     emd.cMediaTypes = 1;
848     emd.pMediaTypes = ((AsyncReader *)This->pin.pin.pinInfo.pFilter)->pmt;
849
850     return IEnumMediaTypesImpl_Construct(&emd, ppEnum);
851 }
852
853 static const IPinVtbl FileAsyncReaderPin_Vtbl = 
854 {
855     FileAsyncReaderPin_QueryInterface,
856     IPinImpl_AddRef,
857     FileAsyncReaderPin_Release,
858     OutputPin_Connect,
859     OutputPin_ReceiveConnection,
860     IPinImpl_Disconnect,
861     IPinImpl_ConnectedTo,
862     IPinImpl_ConnectionMediaType,
863     IPinImpl_QueryPinInfo,
864     IPinImpl_QueryDirection,
865     IPinImpl_QueryId,
866     IPinImpl_QueryAccept,
867     FileAsyncReaderPin_EnumMediaTypes,
868     IPinImpl_QueryInternalConnections,
869     OutputPin_EndOfStream,
870     OutputPin_BeginFlush,
871     OutputPin_EndFlush,
872     OutputPin_NewSegment
873 };
874
875 /* Function called as a helper to IPin_Connect */
876 /* specific AM_MEDIA_TYPE - it cannot be NULL */
877 /* this differs from standard OutputPin_ConnectSpecific only in that it
878  * doesn't need the IMemInputPin interface on the receiving pin */
879 static HRESULT FileAsyncReaderPin_ConnectSpecific(IPin * iface, IPin * pReceivePin, const AM_MEDIA_TYPE * pmt)
880 {
881     OutputPin *This = (OutputPin *)iface;
882     HRESULT hr;
883
884     TRACE("(%p, %p)\n", pReceivePin, pmt);
885     dump_AM_MEDIA_TYPE(pmt);
886
887     /* FIXME: call queryacceptproc */
888
889     This->pin.pConnectedTo = pReceivePin;
890     IPin_AddRef(pReceivePin);
891     CopyMediaType(&This->pin.mtCurrent, pmt);
892
893     hr = IPin_ReceiveConnection(pReceivePin, iface, pmt);
894
895     if (FAILED(hr))
896     {
897         IPin_Release(This->pin.pConnectedTo);
898         This->pin.pConnectedTo = NULL;
899         FreeMediaType(&This->pin.mtCurrent);
900     }
901
902     TRACE(" -- %x\n", hr);
903     return hr;
904 }
905
906 static HRESULT FileAsyncReader_Construct(HANDLE hFile, IBaseFilter * pBaseFilter, LPCRITICAL_SECTION pCritSec, IPin ** ppPin)
907 {
908     PIN_INFO piOutput;
909     HRESULT hr;
910
911     *ppPin = NULL;
912     piOutput.dir = PINDIR_OUTPUT;
913     piOutput.pFilter = pBaseFilter;
914     strcpyW(piOutput.achName, wszOutputPinName);
915     hr = OutputPin_Construct(&FileAsyncReaderPin_Vtbl, sizeof(FileAsyncReader), &piOutput, NULL, pBaseFilter, AcceptProcAFR, pCritSec, ppPin);
916
917     if (SUCCEEDED(hr))
918     {
919         FileAsyncReader *pPinImpl =  (FileAsyncReader *)*ppPin;
920         pPinImpl->lpVtblAR = &FileAsyncReader_Vtbl;
921         pPinImpl->hFile = hFile;
922         pPinImpl->hEvent = CreateEventW(NULL, 0, 0, NULL);
923         pPinImpl->bFlushing = FALSE;
924         pPinImpl->pHead = NULL;
925         pPinImpl->pin.pConnectSpecific = FileAsyncReaderPin_ConnectSpecific;
926         InitializeCriticalSection(&pPinImpl->csList);
927         pPinImpl->csList.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": FileAsyncReader.csList");
928     }
929     return hr;
930 }
931
932 /* IAsyncReader */
933
934 static HRESULT WINAPI FileAsyncReader_QueryInterface(IAsyncReader * iface, REFIID riid, LPVOID * ppv)
935 {
936     FileAsyncReader *This = impl_from_IAsyncReader(iface);
937
938     return IPin_QueryInterface((IPin *)This, riid, ppv);
939 }
940
941 static ULONG WINAPI FileAsyncReader_AddRef(IAsyncReader * iface)
942 {
943     FileAsyncReader *This = impl_from_IAsyncReader(iface);
944
945     return IPin_AddRef((IPin *)This);
946 }
947
948 static ULONG WINAPI FileAsyncReader_Release(IAsyncReader * iface)
949 {
950     FileAsyncReader *This = impl_from_IAsyncReader(iface);
951
952     return IPin_Release((IPin *)This);
953 }
954
955 #define DEF_ALIGNMENT 1
956
957 static HRESULT WINAPI FileAsyncReader_RequestAllocator(IAsyncReader * iface, IMemAllocator * pPreferred, ALLOCATOR_PROPERTIES * pProps, IMemAllocator ** ppActual)
958 {
959     HRESULT hr = S_OK;
960
961     TRACE("(%p, %p, %p)\n", pPreferred, pProps, ppActual);
962
963     if (!pProps->cbAlign || (pProps->cbAlign % DEF_ALIGNMENT) != 0)
964         pProps->cbAlign = DEF_ALIGNMENT;
965
966     if (pPreferred)
967     {
968         ALLOCATOR_PROPERTIES PropsActual;
969         hr = IMemAllocator_SetProperties(pPreferred, pProps, &PropsActual);
970         /* FIXME: check we are still aligned */
971         if (SUCCEEDED(hr))
972         {
973             IMemAllocator_AddRef(pPreferred);
974             *ppActual = pPreferred;
975             TRACE("FileAsyncReader_RequestAllocator -- %x\n", hr);
976             return S_OK;
977         }
978     }
979
980     pPreferred = NULL;
981
982     hr = CoCreateInstance(&CLSID_MemoryAllocator, NULL, CLSCTX_INPROC, &IID_IMemAllocator, (LPVOID *)&pPreferred);
983
984     if (SUCCEEDED(hr))
985     {
986         ALLOCATOR_PROPERTIES PropsActual;
987         hr = IMemAllocator_SetProperties(pPreferred, pProps, &PropsActual);
988         /* FIXME: check we are still aligned */
989         if (SUCCEEDED(hr))
990         {
991             *ppActual = pPreferred;
992             TRACE("FileAsyncReader_RequestAllocator -- %x\n", hr);
993             return S_OK;
994         }
995     }
996
997     if (FAILED(hr))
998     {
999         *ppActual = NULL;
1000         if (pPreferred)
1001             IMemAllocator_Release(pPreferred);
1002     }
1003
1004     TRACE("-- %x\n", hr);
1005     return hr;
1006 }
1007
1008 /* we could improve the Request/WaitForNext mechanism by allowing out of order samples.
1009  * however, this would be quite complicated to do and may be a bit error prone */
1010 static HRESULT WINAPI FileAsyncReader_Request(IAsyncReader * iface, IMediaSample * pSample, DWORD_PTR dwUser)
1011 {
1012     REFERENCE_TIME Start;
1013     REFERENCE_TIME Stop;
1014     DATAREQUEST * pDataRq;
1015     BYTE * pBuffer;
1016     HRESULT hr = S_OK;
1017     FileAsyncReader *This = impl_from_IAsyncReader(iface);
1018
1019     TRACE("(%p, %lx)\n", pSample, dwUser);
1020
1021     /* check flushing state */
1022     if (This->bFlushing)
1023         return VFW_E_WRONG_STATE;
1024
1025     if (!(pDataRq = CoTaskMemAlloc(sizeof(*pDataRq))))
1026         hr = E_OUTOFMEMORY;
1027
1028     /* get start and stop positions in bytes */
1029     if (SUCCEEDED(hr))
1030         hr = IMediaSample_GetTime(pSample, &Start, &Stop);
1031
1032     if (SUCCEEDED(hr))
1033         hr = IMediaSample_GetPointer(pSample, &pBuffer);
1034
1035     if (SUCCEEDED(hr))
1036     {
1037         DWORD dwLength = (DWORD) BYTES_FROM_MEDIATIME(Stop - Start);
1038
1039         pDataRq->ovl.u.s.Offset = (DWORD) BYTES_FROM_MEDIATIME(Start);
1040         pDataRq->ovl.u.s.OffsetHigh = (DWORD)(BYTES_FROM_MEDIATIME(Start) >> (sizeof(DWORD) * 8));
1041         pDataRq->ovl.hEvent = This->hEvent;
1042         pDataRq->dwUserData = dwUser;
1043         pDataRq->pNext = NULL;
1044         /* we violate traditional COM rules here by maintaining
1045          * a reference to the sample, but not calling AddRef, but
1046          * that's what MSDN says to do */
1047         pDataRq->pSample = pSample;
1048
1049         EnterCriticalSection(&This->csList);
1050         {
1051             if (This->pHead)
1052                 /* adds data request to end of list */
1053                 queue(This->pHead, pDataRq);
1054             else
1055                 This->pHead = pDataRq;
1056         }
1057         LeaveCriticalSection(&This->csList);
1058
1059         /* this is definitely not how it is implemented on Win9x
1060          * as they do not support async reads on files, but it is
1061          * sooo much easier to use this than messing around with threads!
1062          */
1063         if (!ReadFile(This->hFile, pBuffer, dwLength, NULL, &pDataRq->ovl))
1064             hr = HRESULT_FROM_WIN32(GetLastError());
1065
1066         /* ERROR_IO_PENDING is not actually an error since this is what we want! */
1067         if (hr == HRESULT_FROM_WIN32(ERROR_IO_PENDING))
1068             hr = S_OK;
1069     }
1070
1071     if (FAILED(hr) && pDataRq)
1072     {
1073         EnterCriticalSection(&This->csList);
1074         {
1075             DATAREQUEST * pCurrent;
1076             for (pCurrent = This->pHead; pCurrent && pCurrent->pNext; pCurrent = pCurrent->pNext)
1077                 if (pCurrent->pNext == pDataRq)
1078                 {
1079                     pCurrent->pNext = pDataRq->pNext;
1080                     break;
1081                 }
1082         }
1083         LeaveCriticalSection(&This->csList);
1084         CoTaskMemFree(pDataRq);
1085     }
1086
1087     TRACE("-- %x\n", hr);
1088     return hr;
1089 }
1090
1091 static HRESULT WINAPI FileAsyncReader_WaitForNext(IAsyncReader * iface, DWORD dwTimeout, IMediaSample ** ppSample, DWORD_PTR * pdwUser)
1092 {
1093     HRESULT hr = S_OK;
1094     DWORD dwBytes = 0;
1095     DATAREQUEST * pDataRq = NULL;
1096     FileAsyncReader *This = impl_from_IAsyncReader(iface);
1097
1098     TRACE("(%u, %p, %p)\n", dwTimeout, ppSample, pdwUser);
1099
1100     /* FIXME: we could do with improving this by waiting for an array of event handles
1101      * and then determining which one finished and removing that from the list, otherwise
1102      * we will end up waiting for longer than we should do, if a later request finishes
1103      * before an earlier one */
1104
1105     *ppSample = NULL;
1106     *pdwUser = 0;
1107
1108     if (!This->bFlushing)
1109     {
1110         /* wait for the read to finish or timeout */
1111         if (WaitForSingleObject(This->hEvent, dwTimeout) == WAIT_TIMEOUT)
1112             hr = VFW_E_TIMEOUT;
1113     }
1114
1115     if (SUCCEEDED(hr))
1116     {
1117         EnterCriticalSection(&This->csList);
1118         {
1119             pDataRq = This->pHead;
1120             if (pDataRq == NULL)
1121                 hr = E_FAIL;
1122             else
1123                 This->pHead = pDataRq->pNext;
1124         }
1125         LeaveCriticalSection(&This->csList);
1126     }
1127
1128     if (SUCCEEDED(hr) && !This->bFlushing)
1129     {
1130         /* get any errors */
1131         if (!GetOverlappedResult(This->hFile, &pDataRq->ovl, &dwBytes, FALSE))
1132             hr = HRESULT_FROM_WIN32(GetLastError());
1133     }
1134
1135     if (SUCCEEDED(hr))
1136     {
1137         IMediaSample_SetActualDataLength(pDataRq->pSample, dwBytes);
1138         *ppSample = pDataRq->pSample;
1139         *pdwUser = pDataRq->dwUserData;
1140     }
1141
1142     /* no need to close event handle since we will close it when the pin is destroyed */
1143     CoTaskMemFree(pDataRq);
1144
1145     /* Return the sample if flushing so it can be destroyed */
1146     if (This->bFlushing && SUCCEEDED(hr))
1147     {
1148         hr = VFW_E_WRONG_STATE;
1149         IMediaSample_SetActualDataLength(pDataRq->pSample, 0);
1150     }
1151
1152     TRACE("-- %x\n", hr);
1153     return hr;
1154 }
1155
1156 static HRESULT WINAPI FileAsyncReader_SyncRead(IAsyncReader * iface, LONGLONG llPosition, LONG lLength, BYTE * pBuffer);
1157
1158 static HRESULT WINAPI FileAsyncReader_SyncReadAligned(IAsyncReader * iface, IMediaSample * pSample)
1159 {
1160     BYTE * pBuffer;
1161     REFERENCE_TIME tStart;
1162     REFERENCE_TIME tStop;
1163     HRESULT hr;
1164
1165     TRACE("(%p)\n", pSample);
1166
1167     hr = IMediaSample_GetTime(pSample, &tStart, &tStop);
1168
1169     if (SUCCEEDED(hr))
1170         hr = IMediaSample_GetPointer(pSample, &pBuffer);
1171
1172     if (SUCCEEDED(hr))
1173         hr = FileAsyncReader_SyncRead(iface, 
1174             BYTES_FROM_MEDIATIME(tStart),
1175             (LONG) BYTES_FROM_MEDIATIME(tStop - tStart),
1176             pBuffer);
1177
1178     TRACE("-- %x\n", hr);
1179     return hr;
1180 }
1181
1182 static HRESULT WINAPI FileAsyncReader_SyncRead(IAsyncReader * iface, LONGLONG llPosition, LONG lLength, BYTE * pBuffer)
1183 {
1184     OVERLAPPED ovl;
1185     HRESULT hr = S_OK;
1186     FileAsyncReader *This = impl_from_IAsyncReader(iface);
1187
1188     TRACE("(%x%08x, %d, %p)\n", (ULONG)(llPosition >> 32), (ULONG)llPosition, lLength, pBuffer);
1189
1190     ZeroMemory(&ovl, sizeof(ovl));
1191
1192     ovl.hEvent = CreateEventW(NULL, 0, 0, NULL);
1193     /* NOTE: llPosition is the actual byte position to start reading from */
1194     ovl.u.s.Offset = (DWORD) llPosition;
1195     ovl.u.s.OffsetHigh = (DWORD) (llPosition >> (sizeof(DWORD) * 8));
1196
1197     if (!ReadFile(This->hFile, pBuffer, lLength, NULL, &ovl))
1198         hr = HRESULT_FROM_WIN32(GetLastError());
1199
1200     if (hr == HRESULT_FROM_WIN32(ERROR_IO_PENDING))
1201         hr = S_OK;
1202
1203     if (SUCCEEDED(hr))
1204     {
1205         DWORD dwBytesRead;
1206
1207         if (!GetOverlappedResult(This->hFile, &ovl, &dwBytesRead, TRUE))
1208             hr = HRESULT_FROM_WIN32(GetLastError());
1209     }
1210
1211     CloseHandle(ovl.hEvent);
1212
1213     TRACE("-- %x\n", hr);
1214     return hr;
1215 }
1216
1217 static HRESULT WINAPI FileAsyncReader_Length(IAsyncReader * iface, LONGLONG * pTotal, LONGLONG * pAvailable)
1218 {
1219     DWORD dwSizeLow;
1220     DWORD dwSizeHigh;
1221     FileAsyncReader *This = impl_from_IAsyncReader(iface);
1222
1223     TRACE("(%p, %p)\n", pTotal, pAvailable);
1224
1225     if (((dwSizeLow = GetFileSize(This->hFile, &dwSizeHigh)) == -1) &&
1226         (GetLastError() != NO_ERROR))
1227         return HRESULT_FROM_WIN32(GetLastError());
1228
1229     *pTotal = (LONGLONG)dwSizeLow | (LONGLONG)dwSizeHigh << (sizeof(DWORD) * 8);
1230
1231     *pAvailable = *pTotal;
1232
1233     return S_OK;
1234 }
1235
1236 static HRESULT WINAPI FileAsyncReader_BeginFlush(IAsyncReader * iface)
1237 {
1238     FileAsyncReader *This = impl_from_IAsyncReader(iface);
1239
1240     TRACE("()\n");
1241
1242     This->bFlushing = TRUE;
1243     CancelIo(This->hFile);
1244     SetEvent(This->hEvent);
1245     
1246     /* FIXME: free list */
1247
1248     return S_OK;
1249 }
1250
1251 static HRESULT WINAPI FileAsyncReader_EndFlush(IAsyncReader * iface)
1252 {
1253     FileAsyncReader *This = impl_from_IAsyncReader(iface);
1254
1255     TRACE("()\n");
1256
1257     This->bFlushing = FALSE;
1258
1259     return S_OK;
1260 }
1261
1262 static const IAsyncReaderVtbl FileAsyncReader_Vtbl = 
1263 {
1264     FileAsyncReader_QueryInterface,
1265     FileAsyncReader_AddRef,
1266     FileAsyncReader_Release,
1267     FileAsyncReader_RequestAllocator,
1268     FileAsyncReader_Request,
1269     FileAsyncReader_WaitForNext,
1270     FileAsyncReader_SyncReadAligned,
1271     FileAsyncReader_SyncRead,
1272     FileAsyncReader_Length,
1273     FileAsyncReader_BeginFlush,
1274     FileAsyncReader_EndFlush,
1275 };