rasapi32: Added some more tests for RasEnumDevicesA, fix Wine not to crash on the...
[wine/multimedia.git] / dlls / quartz / filesource.c
blob99f8852fff0ae67dd017ab3de9db42df0940b5d4
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 const IBaseFilterVtbl * lpVtbl;
43 const IFileSourceFilterVtbl * lpVtblFSF;
45 LONG refCount;
46 FILTER_INFO filterInfo;
47 FILTER_STATE state;
48 CRITICAL_SECTION csFilter;
49 DWORD lastpinchange;
51 IPin * pOutputPin;
52 LPOLESTR pszFileName;
53 AM_MEDIA_TYPE * pmt;
54 } AsyncReader;
56 static const IBaseFilterVtbl AsyncReader_Vtbl;
57 static const IFileSourceFilterVtbl FileSource_Vtbl;
58 static const IAsyncReaderVtbl FileAsyncReader_Vtbl;
60 static HRESULT FileAsyncReader_Construct(HANDLE hFile, IBaseFilter * pBaseFilter, LPCRITICAL_SECTION pCritSec, IPin ** ppPin);
62 static inline AsyncReader *impl_from_IFileSourceFilter( IFileSourceFilter *iface )
64 return (AsyncReader *)((char*)iface - FIELD_OFFSET(AsyncReader, lpVtblFSF));
67 static WCHAR const mediatype_name[11] = {
68 'M', 'e', 'd', 'i', 'a', ' ', 'T', 'y', 'p', 'e', 0 };
69 static WCHAR const subtype_name[8] = {
70 'S', 'u', 'b', 't', 'y', 'p', 'e', 0 };
72 static HRESULT process_extensions(HKEY hkeyExtensions, LPCOLESTR pszFileName, GUID * majorType, GUID * minorType)
74 WCHAR *extension;
75 LONG l;
76 HKEY hsub;
77 WCHAR keying[39];
78 DWORD size;
80 if (!pszFileName)
81 return E_POINTER;
83 /* Get the part of the name that matters */
84 extension = PathFindExtensionW(pszFileName);
85 if (*extension != '.')
86 return E_FAIL;
88 l = RegOpenKeyExW(hkeyExtensions, extension, 0, KEY_READ, &hsub);
89 if (l)
90 return E_FAIL;
92 size = sizeof(keying);
93 l = RegQueryValueExW(hsub, mediatype_name, NULL, NULL, (LPBYTE)keying, &size);
94 if (!l)
95 CLSIDFromString(keying, majorType);
97 size = sizeof(keying);
98 if (!l)
99 l = RegQueryValueExW(hsub, subtype_name, NULL, NULL, (LPBYTE)keying, &size);
101 if (!l)
102 CLSIDFromString(keying, minorType);
104 RegCloseKey(hsub);
106 if (!l)
107 return S_OK;
108 return E_FAIL;
111 static unsigned char byte_from_hex_char(WCHAR wHex)
113 switch (tolowerW(wHex))
115 case '0':
116 case '1':
117 case '2':
118 case '3':
119 case '4':
120 case '5':
121 case '6':
122 case '7':
123 case '8':
124 case '9':
125 return (wHex - '0') & 0xf;
126 case 'a':
127 case 'b':
128 case 'c':
129 case 'd':
130 case 'e':
131 case 'f':
132 return (wHex - 'a' + 10) & 0xf;
133 default:
134 return 0;
138 static HRESULT process_pattern_string(LPCWSTR wszPatternString, IAsyncReader * pReader)
140 ULONG ulOffset;
141 ULONG ulBytes;
142 BYTE * pbMask;
143 BYTE * pbValue;
144 BYTE * pbFile;
145 HRESULT hr = S_OK;
146 ULONG strpos;
148 TRACE("\t\tPattern string: %s\n", debugstr_w(wszPatternString));
150 /* format: "offset, bytestocompare, mask, value" */
152 ulOffset = strtolW(wszPatternString, NULL, 10);
154 if (!(wszPatternString = strchrW(wszPatternString, ',')))
155 return E_INVALIDARG;
157 wszPatternString++; /* skip ',' */
159 ulBytes = strtolW(wszPatternString, NULL, 10);
161 pbMask = HeapAlloc(GetProcessHeap(), 0, ulBytes);
162 pbValue = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, ulBytes);
163 pbFile = HeapAlloc(GetProcessHeap(), 0, ulBytes);
165 /* default mask is match everything */
166 memset(pbMask, 0xFF, ulBytes);
168 if (!(wszPatternString = strchrW(wszPatternString, ',')))
169 hr = E_INVALIDARG;
171 wszPatternString++; /* skip ',' */
173 if (hr == S_OK)
175 for ( ; !isxdigitW(*wszPatternString) && (*wszPatternString != ','); wszPatternString++)
178 for (strpos = 0; isxdigitW(*wszPatternString) && (strpos/2 < ulBytes); wszPatternString++, strpos++)
180 if ((strpos % 2) == 1) /* odd numbered position */
181 pbMask[strpos / 2] |= byte_from_hex_char(*wszPatternString);
182 else
183 pbMask[strpos / 2] = byte_from_hex_char(*wszPatternString) << 4;
186 if (!(wszPatternString = strchrW(wszPatternString, ',')))
187 hr = E_INVALIDARG;
189 wszPatternString++; /* skip ',' */
192 if (hr == S_OK)
194 for ( ; !isxdigitW(*wszPatternString) && (*wszPatternString != ','); wszPatternString++)
197 for (strpos = 0; isxdigitW(*wszPatternString) && (strpos/2 < ulBytes); wszPatternString++, strpos++)
199 if ((strpos % 2) == 1) /* odd numbered position */
200 pbValue[strpos / 2] |= byte_from_hex_char(*wszPatternString);
201 else
202 pbValue[strpos / 2] = byte_from_hex_char(*wszPatternString) << 4;
206 if (hr == S_OK)
207 hr = IAsyncReader_SyncRead(pReader, ulOffset, ulBytes, pbFile);
209 if (hr == S_OK)
211 ULONG i;
212 for (i = 0; i < ulBytes; i++)
213 if ((pbFile[i] & pbMask[i]) != pbValue[i])
215 hr = S_FALSE;
216 break;
220 HeapFree(GetProcessHeap(), 0, pbMask);
221 HeapFree(GetProcessHeap(), 0, pbValue);
222 HeapFree(GetProcessHeap(), 0, pbFile);
224 /* if we encountered no errors with this string, and there is a following tuple, then we
225 * have to match that as well to succeed */
226 if ((hr == S_OK) && (wszPatternString = strchrW(wszPatternString, ',')))
227 return process_pattern_string(wszPatternString + 1, pReader);
228 else
229 return hr;
232 static HRESULT GetClassMediaFile(IAsyncReader * pReader, LPCOLESTR pszFileName, GUID * majorType, GUID * minorType)
234 HKEY hkeyMediaType = NULL;
235 LONG lRet;
236 HRESULT hr = S_OK;
237 BOOL bFound = FALSE;
238 static const WCHAR wszMediaType[] = {'M','e','d','i','a',' ','T','y','p','e',0};
240 TRACE("(%p, %s, %p, %p)\n", pReader, debugstr_w(pszFileName), majorType, minorType);
242 *majorType = GUID_NULL;
243 *minorType = GUID_NULL;
245 lRet = RegOpenKeyExW(HKEY_CLASSES_ROOT, wszMediaType, 0, KEY_READ, &hkeyMediaType);
246 hr = HRESULT_FROM_WIN32(lRet);
248 if (SUCCEEDED(hr))
250 DWORD indexMajor;
252 for (indexMajor = 0; !bFound; indexMajor++)
254 HKEY hkeyMajor;
255 WCHAR wszMajorKeyName[CHARS_IN_GUID];
256 DWORD dwKeyNameLength = sizeof(wszMajorKeyName) / sizeof(wszMajorKeyName[0]);
257 static const WCHAR wszExtensions[] = {'E','x','t','e','n','s','i','o','n','s',0};
259 if (RegEnumKeyExW(hkeyMediaType, indexMajor, wszMajorKeyName, &dwKeyNameLength, NULL, NULL, NULL, NULL) != ERROR_SUCCESS)
260 break;
261 if (RegOpenKeyExW(hkeyMediaType, wszMajorKeyName, 0, KEY_READ, &hkeyMajor) != ERROR_SUCCESS)
262 break;
263 TRACE("%s\n", debugstr_w(wszMajorKeyName));
264 if (!strcmpW(wszExtensions, wszMajorKeyName))
266 if (process_extensions(hkeyMajor, pszFileName, majorType, minorType) == S_OK)
267 bFound = TRUE;
269 else
271 DWORD indexMinor;
273 for (indexMinor = 0; !bFound; indexMinor++)
275 HKEY hkeyMinor;
276 WCHAR wszMinorKeyName[CHARS_IN_GUID];
277 DWORD dwMinorKeyNameLen = sizeof(wszMinorKeyName) / sizeof(wszMinorKeyName[0]);
278 DWORD maxValueLen;
279 DWORD indexValue;
281 if (RegEnumKeyExW(hkeyMajor, indexMinor, wszMinorKeyName, &dwMinorKeyNameLen, NULL, NULL, NULL, NULL) != ERROR_SUCCESS)
282 break;
284 if (RegOpenKeyExW(hkeyMajor, wszMinorKeyName, 0, KEY_READ, &hkeyMinor) != ERROR_SUCCESS)
285 break;
287 TRACE("\t%s\n", debugstr_w(wszMinorKeyName));
289 if (RegQueryInfoKeyW(hkeyMinor, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &maxValueLen, NULL, NULL) != ERROR_SUCCESS)
290 break;
292 for (indexValue = 0; !bFound; indexValue++)
294 DWORD dwType;
295 WCHAR wszValueName[14]; /* longest name we should encounter will be "Source Filter" */
296 LPWSTR wszPatternString = HeapAlloc(GetProcessHeap(), 0, maxValueLen);
297 DWORD dwValueNameLen = sizeof(wszValueName) / sizeof(wszValueName[0]); /* remember this is in chars */
298 DWORD dwDataLen = maxValueLen; /* remember this is in bytes */
299 static const WCHAR wszSourceFilter[] = {'S','o','u','r','c','e',' ','F','i','l','t','e','r',0};
300 LONG temp;
302 if ((temp = RegEnumValueW(hkeyMinor, indexValue, wszValueName, &dwValueNameLen, NULL, &dwType, (LPBYTE)wszPatternString, &dwDataLen)) != ERROR_SUCCESS)
304 HeapFree(GetProcessHeap(), 0, wszPatternString);
305 break;
308 /* if it is not the source filter value */
309 if (strcmpW(wszValueName, wszSourceFilter))
311 if (process_pattern_string(wszPatternString, pReader) == S_OK)
313 if (SUCCEEDED(CLSIDFromString(wszMajorKeyName, majorType)) &&
314 SUCCEEDED(CLSIDFromString(wszMinorKeyName, minorType)))
315 bFound = TRUE;
318 HeapFree(GetProcessHeap(), 0, wszPatternString);
320 CloseHandle(hkeyMinor);
323 CloseHandle(hkeyMajor);
326 CloseHandle(hkeyMediaType);
328 if (SUCCEEDED(hr) && !bFound)
330 ERR("Media class not found\n");
331 hr = E_FAIL;
333 else if (bFound)
334 TRACE("Found file's class: major = %s, subtype = %s\n", qzdebugstr_guid(majorType), qzdebugstr_guid(minorType));
336 return hr;
339 HRESULT AsyncReader_create(IUnknown * pUnkOuter, LPVOID * ppv)
341 AsyncReader *pAsyncRead;
343 if( pUnkOuter )
344 return CLASS_E_NOAGGREGATION;
346 pAsyncRead = CoTaskMemAlloc(sizeof(AsyncReader));
348 if (!pAsyncRead)
349 return E_OUTOFMEMORY;
351 pAsyncRead->lpVtbl = &AsyncReader_Vtbl;
352 pAsyncRead->lpVtblFSF = &FileSource_Vtbl;
353 pAsyncRead->refCount = 1;
354 pAsyncRead->filterInfo.achName[0] = '\0';
355 pAsyncRead->filterInfo.pGraph = NULL;
356 pAsyncRead->pOutputPin = NULL;
357 pAsyncRead->lastpinchange = GetTickCount();
358 pAsyncRead->state = State_Stopped;
360 InitializeCriticalSection(&pAsyncRead->csFilter);
361 pAsyncRead->csFilter.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": AsyncReader.csFilter");
363 pAsyncRead->pszFileName = NULL;
364 pAsyncRead->pmt = NULL;
366 *ppv = (LPVOID)pAsyncRead;
368 TRACE("-- created at %p\n", pAsyncRead);
370 return S_OK;
373 /** IUnknown methods **/
375 static HRESULT WINAPI AsyncReader_QueryInterface(IBaseFilter * iface, REFIID riid, LPVOID * ppv)
377 AsyncReader *This = (AsyncReader *)iface;
379 TRACE("(%s, %p)\n", qzdebugstr_guid(riid), ppv);
381 *ppv = NULL;
383 if (IsEqualIID(riid, &IID_IUnknown))
384 *ppv = (LPVOID)This;
385 else if (IsEqualIID(riid, &IID_IPersist))
386 *ppv = (LPVOID)This;
387 else if (IsEqualIID(riid, &IID_IMediaFilter))
388 *ppv = (LPVOID)This;
389 else if (IsEqualIID(riid, &IID_IBaseFilter))
390 *ppv = (LPVOID)This;
391 else if (IsEqualIID(riid, &IID_IFileSourceFilter))
392 *ppv = (LPVOID)(&This->lpVtblFSF);
394 if (*ppv)
396 IUnknown_AddRef((IUnknown *)(*ppv));
397 return S_OK;
400 if (!IsEqualIID(riid, &IID_IPin) && !IsEqualIID(riid, &IID_IMediaSeeking) && !IsEqualIID(riid, &IID_IVideoWindow))
401 FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
403 return E_NOINTERFACE;
406 static ULONG WINAPI AsyncReader_AddRef(IBaseFilter * iface)
408 AsyncReader *This = (AsyncReader *)iface;
409 ULONG refCount = InterlockedIncrement(&This->refCount);
411 TRACE("(%p)->() AddRef from %d\n", This, refCount - 1);
413 return refCount;
416 static ULONG WINAPI AsyncReader_Release(IBaseFilter * iface)
418 AsyncReader *This = (AsyncReader *)iface;
419 ULONG refCount = InterlockedDecrement(&This->refCount);
421 TRACE("(%p)->() Release from %d\n", This, refCount + 1);
423 if (!refCount)
425 if (This->pOutputPin)
427 IPin *pConnectedTo;
428 if(SUCCEEDED(IPin_ConnectedTo(This->pOutputPin, &pConnectedTo)))
430 IPin_Disconnect(pConnectedTo);
431 IPin_Release(pConnectedTo);
433 IPin_Disconnect(This->pOutputPin);
434 IPin_Release(This->pOutputPin);
436 This->csFilter.DebugInfo->Spare[0] = 0;
437 DeleteCriticalSection(&This->csFilter);
438 This->lpVtbl = NULL;
439 CoTaskMemFree(This->pszFileName);
440 if (This->pmt)
441 FreeMediaType(This->pmt);
442 CoTaskMemFree(This);
443 return 0;
445 else
446 return refCount;
449 /** IPersist methods **/
451 static HRESULT WINAPI AsyncReader_GetClassID(IBaseFilter * iface, CLSID * pClsid)
453 TRACE("(%p)\n", pClsid);
455 *pClsid = CLSID_AsyncReader;
457 return S_OK;
460 /** IMediaFilter methods **/
462 static HRESULT WINAPI AsyncReader_Stop(IBaseFilter * iface)
464 AsyncReader *This = (AsyncReader *)iface;
466 TRACE("()\n");
468 This->state = State_Stopped;
470 return S_OK;
473 static HRESULT WINAPI AsyncReader_Pause(IBaseFilter * iface)
475 AsyncReader *This = (AsyncReader *)iface;
477 TRACE("()\n");
479 This->state = State_Paused;
481 return S_OK;
484 static HRESULT WINAPI AsyncReader_Run(IBaseFilter * iface, REFERENCE_TIME tStart)
486 AsyncReader *This = (AsyncReader *)iface;
488 TRACE("(%x%08x)\n", (ULONG)(tStart >> 32), (ULONG)tStart);
490 This->state = State_Running;
492 return S_OK;
495 static HRESULT WINAPI AsyncReader_GetState(IBaseFilter * iface, DWORD dwMilliSecsTimeout, FILTER_STATE *pState)
497 AsyncReader *This = (AsyncReader *)iface;
499 TRACE("(%u, %p)\n", dwMilliSecsTimeout, pState);
501 *pState = This->state;
503 return S_OK;
506 static HRESULT WINAPI AsyncReader_SetSyncSource(IBaseFilter * iface, IReferenceClock *pClock)
508 /* AsyncReader *This = (AsyncReader *)iface;*/
510 TRACE("(%p)\n", pClock);
512 return S_OK;
515 static HRESULT WINAPI AsyncReader_GetSyncSource(IBaseFilter * iface, IReferenceClock **ppClock)
517 /* AsyncReader *This = (AsyncReader *)iface;*/
519 TRACE("(%p)\n", ppClock);
521 return S_OK;
524 /** IBaseFilter methods **/
526 static HRESULT AsyncReader_GetPin(IBaseFilter *iface, ULONG pos, IPin **pin, DWORD *lastsynctick)
528 AsyncReader *This = (AsyncReader *)iface;
530 /* Our pins are almost static, not changing so setting static tick count is ok */
531 *lastsynctick = This->lastpinchange;
533 if (pos >= 1 || !This->pOutputPin)
534 return S_FALSE;
536 *pin = (IPin *)This->pOutputPin;
537 IPin_AddRef(*pin);
538 return S_OK;
541 static HRESULT WINAPI AsyncReader_EnumPins(IBaseFilter * iface, IEnumPins **ppEnum)
543 AsyncReader *This = (AsyncReader *)iface;
545 TRACE("(%p/%p)->(%p)\n", This, iface, ppEnum);
547 return IEnumPinsImpl_Construct(ppEnum, AsyncReader_GetPin, iface);
550 static HRESULT WINAPI AsyncReader_FindPin(IBaseFilter * iface, LPCWSTR Id, IPin **ppPin)
552 FIXME("(%s, %p)\n", debugstr_w(Id), ppPin);
554 return E_NOTIMPL;
557 static HRESULT WINAPI AsyncReader_QueryFilterInfo(IBaseFilter * iface, FILTER_INFO *pInfo)
559 AsyncReader *This = (AsyncReader *)iface;
561 TRACE("(%p)\n", pInfo);
563 strcpyW(pInfo->achName, This->filterInfo.achName);
564 pInfo->pGraph = This->filterInfo.pGraph;
566 if (pInfo->pGraph)
567 IFilterGraph_AddRef(pInfo->pGraph);
569 return S_OK;
572 static HRESULT WINAPI AsyncReader_JoinFilterGraph(IBaseFilter * iface, IFilterGraph *pGraph, LPCWSTR pName)
574 AsyncReader *This = (AsyncReader *)iface;
576 TRACE("(%p, %s)\n", pGraph, debugstr_w(pName));
578 if (pName)
579 strcpyW(This->filterInfo.achName, pName);
580 else
581 *This->filterInfo.achName = 0;
582 This->filterInfo.pGraph = pGraph; /* NOTE: do NOT increase ref. count */
584 return S_OK;
587 static HRESULT WINAPI AsyncReader_QueryVendorInfo(IBaseFilter * iface, LPWSTR *pVendorInfo)
589 FIXME("(%p)\n", pVendorInfo);
591 return E_NOTIMPL;
594 static const IBaseFilterVtbl AsyncReader_Vtbl =
596 AsyncReader_QueryInterface,
597 AsyncReader_AddRef,
598 AsyncReader_Release,
599 AsyncReader_GetClassID,
600 AsyncReader_Stop,
601 AsyncReader_Pause,
602 AsyncReader_Run,
603 AsyncReader_GetState,
604 AsyncReader_SetSyncSource,
605 AsyncReader_GetSyncSource,
606 AsyncReader_EnumPins,
607 AsyncReader_FindPin,
608 AsyncReader_QueryFilterInfo,
609 AsyncReader_JoinFilterGraph,
610 AsyncReader_QueryVendorInfo
613 static HRESULT WINAPI FileSource_QueryInterface(IFileSourceFilter * iface, REFIID riid, LPVOID * ppv)
615 AsyncReader *This = impl_from_IFileSourceFilter(iface);
617 return IBaseFilter_QueryInterface((IFileSourceFilter*)&This->lpVtbl, riid, ppv);
620 static ULONG WINAPI FileSource_AddRef(IFileSourceFilter * iface)
622 AsyncReader *This = impl_from_IFileSourceFilter(iface);
624 return IBaseFilter_AddRef((IFileSourceFilter*)&This->lpVtbl);
627 static ULONG WINAPI FileSource_Release(IFileSourceFilter * iface)
629 AsyncReader *This = impl_from_IFileSourceFilter(iface);
631 return IBaseFilter_Release((IFileSourceFilter*)&This->lpVtbl);
634 static HRESULT WINAPI FileSource_Load(IFileSourceFilter * iface, LPCOLESTR pszFileName, const AM_MEDIA_TYPE * pmt)
636 HRESULT hr;
637 HANDLE hFile;
638 IAsyncReader * pReader = NULL;
639 AsyncReader *This = impl_from_IFileSourceFilter(iface);
641 TRACE("(%s, %p)\n", debugstr_w(pszFileName), pmt);
643 /* open file */
644 /* FIXME: check the sharing values that native uses */
645 hFile = CreateFileW(pszFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);
647 if (hFile == INVALID_HANDLE_VALUE)
649 return HRESULT_FROM_WIN32(GetLastError());
652 /* create pin */
653 hr = FileAsyncReader_Construct(hFile, (IBaseFilter *)&This->lpVtbl, &This->csFilter, &This->pOutputPin);
654 This->lastpinchange = GetTickCount();
656 if (SUCCEEDED(hr))
657 hr = IPin_QueryInterface(This->pOutputPin, &IID_IAsyncReader, (LPVOID *)&pReader);
659 /* store file name & media type */
660 if (SUCCEEDED(hr))
662 CoTaskMemFree(This->pszFileName);
663 if (This->pmt)
664 FreeMediaType(This->pmt);
666 This->pszFileName = CoTaskMemAlloc((strlenW(pszFileName) + 1) * sizeof(WCHAR));
667 strcpyW(This->pszFileName, pszFileName);
669 This->pmt = CoTaskMemAlloc(sizeof(AM_MEDIA_TYPE));
670 if (!pmt)
672 This->pmt->bFixedSizeSamples = TRUE;
673 This->pmt->bTemporalCompression = FALSE;
674 This->pmt->cbFormat = 0;
675 This->pmt->pbFormat = NULL;
676 This->pmt->pUnk = NULL;
677 This->pmt->lSampleSize = 0;
678 This->pmt->formattype = FORMAT_None;
679 hr = GetClassMediaFile(pReader, pszFileName, &This->pmt->majortype, &This->pmt->subtype);
680 if (FAILED(hr))
682 CoTaskMemFree(This->pmt);
683 This->pmt = NULL;
686 else
687 CopyMediaType(This->pmt, pmt);
690 if (pReader)
691 IAsyncReader_Release(pReader);
693 if (FAILED(hr))
695 if (This->pOutputPin)
697 IPin_Release(This->pOutputPin);
698 This->pOutputPin = NULL;
701 CoTaskMemFree(This->pszFileName);
702 if (This->pmt)
703 FreeMediaType(This->pmt);
704 This->pszFileName = NULL;
705 This->pmt = NULL;
707 CloseHandle(hFile);
710 /* FIXME: check return codes */
711 return hr;
714 static HRESULT WINAPI FileSource_GetCurFile(IFileSourceFilter * iface, LPOLESTR * ppszFileName, AM_MEDIA_TYPE * pmt)
716 AsyncReader *This = impl_from_IFileSourceFilter(iface);
718 TRACE("(%p, %p)\n", ppszFileName, pmt);
720 if (!ppszFileName)
721 return E_POINTER;
723 /* copy file name & media type if available, otherwise clear the outputs */
724 if (This->pszFileName)
726 *ppszFileName = CoTaskMemAlloc((strlenW(This->pszFileName) + 1) * sizeof(WCHAR));
727 strcpyW(*ppszFileName, This->pszFileName);
729 else
730 *ppszFileName = NULL;
732 if (pmt)
734 if (This->pmt)
735 CopyMediaType(pmt, This->pmt);
736 else
737 ZeroMemory(pmt, sizeof(*pmt));
740 return S_OK;
743 static const IFileSourceFilterVtbl FileSource_Vtbl =
745 FileSource_QueryInterface,
746 FileSource_AddRef,
747 FileSource_Release,
748 FileSource_Load,
749 FileSource_GetCurFile
753 /* the dwUserData passed back to user */
754 typedef struct DATAREQUEST
756 IMediaSample * pSample; /* sample passed to us by user */
757 DWORD_PTR dwUserData; /* user data passed to us */
758 OVERLAPPED ovl; /* our overlapped structure */
759 } DATAREQUEST;
761 typedef struct FileAsyncReader
763 OutputPin pin;
764 const struct IAsyncReaderVtbl * lpVtblAR;
766 HANDLE hFile;
767 BOOL bFlushing;
768 /* Why would you need more? Every sample has its own handle */
769 LONG queued_number;
770 LONG samples;
771 CRITICAL_SECTION csList; /* critical section to prevent concurrency issues */
772 DATAREQUEST *sample_list;
774 /* Have a handle for every sample, and then one more as flushing handle */
775 HANDLE *handle_list;
776 } FileAsyncReader;
778 static inline FileAsyncReader *impl_from_IAsyncReader( IAsyncReader *iface )
780 return (FileAsyncReader *)((char*)iface - FIELD_OFFSET(FileAsyncReader, lpVtblAR));
783 static HRESULT AcceptProcAFR(LPVOID iface, const AM_MEDIA_TYPE *pmt)
785 AsyncReader *This = (AsyncReader *)iface;
787 FIXME("(%p, %p)\n", iface, pmt);
789 if (IsEqualGUID(&pmt->majortype, &This->pmt->majortype) &&
790 IsEqualGUID(&pmt->subtype, &This->pmt->subtype) &&
791 IsEqualGUID(&pmt->formattype, &FORMAT_None))
792 return S_OK;
794 return S_FALSE;
797 /* overridden pin functions */
799 static HRESULT WINAPI FileAsyncReaderPin_QueryInterface(IPin * iface, REFIID riid, LPVOID * ppv)
801 FileAsyncReader *This = (FileAsyncReader *)iface;
802 TRACE("(%s, %p)\n", qzdebugstr_guid(riid), ppv);
804 *ppv = NULL;
806 if (IsEqualIID(riid, &IID_IUnknown))
807 *ppv = (LPVOID)This;
808 else if (IsEqualIID(riid, &IID_IPin))
809 *ppv = (LPVOID)This;
810 else if (IsEqualIID(riid, &IID_IAsyncReader))
811 *ppv = (LPVOID)&This->lpVtblAR;
813 if (*ppv)
815 IUnknown_AddRef((IUnknown *)(*ppv));
816 return S_OK;
819 if (!IsEqualIID(riid, &IID_IPin) && !IsEqualIID(riid, &IID_IMediaSeeking))
820 FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
822 return E_NOINTERFACE;
825 static ULONG WINAPI FileAsyncReaderPin_Release(IPin * iface)
827 FileAsyncReader *This = (FileAsyncReader *)iface;
828 ULONG refCount = InterlockedDecrement(&This->pin.pin.refCount);
829 int x;
831 TRACE("(%p)->() Release from %d\n", This, refCount + 1);
833 if (!refCount)
835 CoTaskMemFree(This->sample_list);
836 if (This->handle_list)
838 for (x = 0; x <= This->samples; ++x)
839 CloseHandle(This->handle_list[x]);
840 CoTaskMemFree(This->handle_list);
842 CloseHandle(This->hFile);
843 This->csList.DebugInfo->Spare[0] = 0;
844 DeleteCriticalSection(&This->csList);
845 CoTaskMemFree(This);
846 return 0;
848 return refCount;
851 static HRESULT WINAPI FileAsyncReaderPin_EnumMediaTypes(IPin * iface, IEnumMediaTypes ** ppEnum)
853 ENUMMEDIADETAILS emd;
854 FileAsyncReader *This = (FileAsyncReader *)iface;
856 TRACE("(%p)\n", ppEnum);
858 emd.cMediaTypes = 1;
859 emd.pMediaTypes = ((AsyncReader *)This->pin.pin.pinInfo.pFilter)->pmt;
861 return IEnumMediaTypesImpl_Construct(&emd, ppEnum);
864 static const IPinVtbl FileAsyncReaderPin_Vtbl =
866 FileAsyncReaderPin_QueryInterface,
867 IPinImpl_AddRef,
868 FileAsyncReaderPin_Release,
869 OutputPin_Connect,
870 OutputPin_ReceiveConnection,
871 IPinImpl_Disconnect,
872 IPinImpl_ConnectedTo,
873 IPinImpl_ConnectionMediaType,
874 IPinImpl_QueryPinInfo,
875 IPinImpl_QueryDirection,
876 IPinImpl_QueryId,
877 IPinImpl_QueryAccept,
878 FileAsyncReaderPin_EnumMediaTypes,
879 IPinImpl_QueryInternalConnections,
880 OutputPin_EndOfStream,
881 OutputPin_BeginFlush,
882 OutputPin_EndFlush,
883 OutputPin_NewSegment
886 /* Function called as a helper to IPin_Connect */
887 /* specific AM_MEDIA_TYPE - it cannot be NULL */
888 /* this differs from standard OutputPin_ConnectSpecific only in that it
889 * doesn't need the IMemInputPin interface on the receiving pin */
890 static HRESULT FileAsyncReaderPin_ConnectSpecific(IPin * iface, IPin * pReceivePin, const AM_MEDIA_TYPE * pmt)
892 OutputPin *This = (OutputPin *)iface;
893 HRESULT hr;
895 TRACE("(%p, %p)\n", pReceivePin, pmt);
896 dump_AM_MEDIA_TYPE(pmt);
898 /* FIXME: call queryacceptproc */
900 This->pin.pConnectedTo = pReceivePin;
901 IPin_AddRef(pReceivePin);
902 CopyMediaType(&This->pin.mtCurrent, pmt);
904 hr = IPin_ReceiveConnection(pReceivePin, iface, pmt);
906 if (FAILED(hr))
908 IPin_Release(This->pin.pConnectedTo);
909 This->pin.pConnectedTo = NULL;
910 FreeMediaType(&This->pin.mtCurrent);
913 TRACE(" -- %x\n", hr);
914 return hr;
917 static HRESULT FileAsyncReader_Construct(HANDLE hFile, IBaseFilter * pBaseFilter, LPCRITICAL_SECTION pCritSec, IPin ** ppPin)
919 PIN_INFO piOutput;
920 HRESULT hr;
922 *ppPin = NULL;
923 piOutput.dir = PINDIR_OUTPUT;
924 piOutput.pFilter = pBaseFilter;
925 strcpyW(piOutput.achName, wszOutputPinName);
926 hr = OutputPin_Construct(&FileAsyncReaderPin_Vtbl, sizeof(FileAsyncReader), &piOutput, NULL, pBaseFilter, AcceptProcAFR, pCritSec, ppPin);
928 if (SUCCEEDED(hr))
930 FileAsyncReader *pPinImpl = (FileAsyncReader *)*ppPin;
931 pPinImpl->lpVtblAR = &FileAsyncReader_Vtbl;
932 pPinImpl->hFile = hFile;
933 pPinImpl->bFlushing = FALSE;
934 pPinImpl->sample_list = NULL;
935 pPinImpl->handle_list = NULL;
936 pPinImpl->queued_number = 0;
937 pPinImpl->pin.pConnectSpecific = FileAsyncReaderPin_ConnectSpecific;
938 InitializeCriticalSection(&pPinImpl->csList);
939 pPinImpl->csList.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": FileAsyncReader.csList");
941 return hr;
944 /* IAsyncReader */
946 static HRESULT WINAPI FileAsyncReader_QueryInterface(IAsyncReader * iface, REFIID riid, LPVOID * ppv)
948 FileAsyncReader *This = impl_from_IAsyncReader(iface);
950 return IPin_QueryInterface((IPin *)This, riid, ppv);
953 static ULONG WINAPI FileAsyncReader_AddRef(IAsyncReader * iface)
955 FileAsyncReader *This = impl_from_IAsyncReader(iface);
957 return IPin_AddRef((IPin *)This);
960 static ULONG WINAPI FileAsyncReader_Release(IAsyncReader * iface)
962 FileAsyncReader *This = impl_from_IAsyncReader(iface);
964 return IPin_Release((IPin *)This);
967 #define DEF_ALIGNMENT 1
969 static HRESULT WINAPI FileAsyncReader_RequestAllocator(IAsyncReader * iface, IMemAllocator * pPreferred, ALLOCATOR_PROPERTIES * pProps, IMemAllocator ** ppActual)
971 FileAsyncReader *This = impl_from_IAsyncReader(iface);
973 HRESULT hr = S_OK;
975 TRACE("(%p, %p, %p)\n", pPreferred, pProps, ppActual);
977 if (!pProps->cbAlign || (pProps->cbAlign % DEF_ALIGNMENT) != 0)
978 pProps->cbAlign = DEF_ALIGNMENT;
980 if (pPreferred)
982 hr = IMemAllocator_SetProperties(pPreferred, pProps, pProps);
983 /* FIXME: check we are still aligned */
984 if (SUCCEEDED(hr))
986 IMemAllocator_AddRef(pPreferred);
987 *ppActual = pPreferred;
988 TRACE("FileAsyncReader_RequestAllocator -- %x\n", hr);
989 goto done;
993 pPreferred = NULL;
995 hr = CoCreateInstance(&CLSID_MemoryAllocator, NULL, CLSCTX_INPROC, &IID_IMemAllocator, (LPVOID *)&pPreferred);
997 if (SUCCEEDED(hr))
999 hr = IMemAllocator_SetProperties(pPreferred, pProps, pProps);
1000 /* FIXME: check we are still aligned */
1001 if (SUCCEEDED(hr))
1003 *ppActual = pPreferred;
1004 TRACE("FileAsyncReader_RequestAllocator -- %x\n", hr);
1008 done:
1009 if (SUCCEEDED(hr))
1011 CoTaskMemFree(This->sample_list);
1012 if (This->handle_list)
1014 int x;
1015 for (x = 0; x <= This->samples; ++x)
1016 CloseHandle(This->handle_list[x]);
1017 CoTaskMemFree(This->handle_list);
1020 This->samples = pProps->cBuffers;
1021 TRACE("Samples: %u\n", This->samples);
1022 This->sample_list = CoTaskMemAlloc(sizeof(This->sample_list[0]) * pProps->cBuffers);
1023 This->handle_list = CoTaskMemAlloc(sizeof(HANDLE) * (pProps->cBuffers + 1));
1025 if (This->sample_list && This->handle_list)
1027 int x;
1028 ZeroMemory(This->sample_list, sizeof(This->sample_list[0]) * pProps->cBuffers);
1029 for (x = 0; x < This->samples; ++x)
1031 This->sample_list[x].ovl.hEvent = This->handle_list[x] = CreateEventW(NULL, 0, 0, NULL);
1033 This->handle_list[This->samples] = CreateEventW(NULL, 1, 0, NULL);
1034 This->pin.allocProps = *pProps;
1036 else
1038 hr = E_OUTOFMEMORY;
1039 CoTaskMemFree(This->sample_list);
1040 CoTaskMemFree(This->handle_list);
1041 This->samples = 0;
1042 This->sample_list = NULL;
1043 This->handle_list = NULL;
1047 if (FAILED(hr))
1049 *ppActual = NULL;
1050 if (pPreferred)
1051 IMemAllocator_Release(pPreferred);
1054 TRACE("-- %x\n", hr);
1055 return hr;
1058 /* we could improve the Request/WaitForNext mechanism by allowing out of order samples.
1059 * however, this would be quite complicated to do and may be a bit error prone */
1060 static HRESULT WINAPI FileAsyncReader_Request(IAsyncReader * iface, IMediaSample * pSample, DWORD_PTR dwUser)
1062 HRESULT hr = S_OK;
1063 REFERENCE_TIME Start;
1064 REFERENCE_TIME Stop;
1065 FileAsyncReader *This = impl_from_IAsyncReader(iface);
1066 LPBYTE pBuffer = NULL;
1067 DWORD wait;
1069 TRACE("(%p, %lx)\n", pSample, dwUser);
1071 if (!pSample)
1072 return E_POINTER;
1074 /* get start and stop positions in bytes */
1075 if (SUCCEEDED(hr))
1076 hr = IMediaSample_GetTime(pSample, &Start, &Stop);
1078 if (SUCCEEDED(hr))
1079 hr = IMediaSample_GetPointer(pSample, &pBuffer);
1081 EnterCriticalSection(&This->csList);
1082 if (This->bFlushing)
1084 LeaveCriticalSection(&This->csList);
1085 return VFW_E_WRONG_STATE;
1088 wait = WaitForMultipleObjectsEx(This->samples, This->handle_list, FALSE, 0, FALSE);
1089 if (wait < This->samples - 1)
1090 SetEvent(This->handle_list[wait]);
1091 else
1092 wait = This->samples;
1094 if (SUCCEEDED(hr))
1096 DWORD dwLength = (DWORD) BYTES_FROM_MEDIATIME(Stop - Start);
1097 DATAREQUEST *pDataRq;
1098 int x;
1100 /* Try to insert above the waiting sample if possible */
1101 for (x = wait + 1; x < This->samples; ++x)
1103 if (!This->sample_list[x].pSample)
1104 break;
1107 if (x >= This->samples)
1108 for (x = 0; x < This->samples; ++x)
1110 if (!This->sample_list[x].pSample)
1111 break;
1114 assert(x < This->samples);
1115 InterlockedIncrement(&This->queued_number);
1117 pDataRq = This->sample_list + x;
1119 pDataRq->ovl.u.s.Offset = (DWORD) BYTES_FROM_MEDIATIME(Start);
1120 pDataRq->ovl.u.s.OffsetHigh = (DWORD)(BYTES_FROM_MEDIATIME(Start) >> (sizeof(DWORD) * 8));
1121 pDataRq->dwUserData = dwUser;
1123 /* we violate traditional COM rules here by maintaining
1124 * a reference to the sample, but not calling AddRef, but
1125 * that's what MSDN says to do */
1126 pDataRq->pSample = pSample;
1128 /* this is definitely not how it is implemented on Win9x
1129 * as they do not support async reads on files, but it is
1130 * sooo much easier to use this than messing around with threads!
1132 if (!ReadFile(This->hFile, pBuffer, dwLength, NULL, &pDataRq->ovl))
1133 hr = HRESULT_FROM_WIN32(GetLastError());
1135 /* ERROR_IO_PENDING is not actually an error since this is what we want! */
1136 if (hr == HRESULT_FROM_WIN32(ERROR_IO_PENDING))
1137 hr = S_OK;
1140 LeaveCriticalSection(&This->csList);
1142 TRACE("-- %x\n", hr);
1143 return hr;
1146 static HRESULT WINAPI FileAsyncReader_WaitForNext(IAsyncReader * iface, DWORD dwTimeout, IMediaSample ** ppSample, DWORD_PTR * pdwUser)
1148 HRESULT hr = S_OK;
1149 FileAsyncReader *This = impl_from_IAsyncReader(iface);
1150 DWORD buffer = ~0;
1152 TRACE("(%u, %p, %p)\n", dwTimeout, ppSample, pdwUser);
1154 *ppSample = NULL;
1155 *pdwUser = 0;
1157 if (!This->bFlushing)
1159 if (!This->queued_number)
1161 /* It could be that nothing is queued right now, but that can be fixed */
1162 WARN("Called without samples in queue and not flushing!!\n");
1165 /* wait for an object to read, or time out */
1166 buffer = WaitForMultipleObjectsEx(This->samples+1, This->handle_list, FALSE, dwTimeout, TRUE);
1168 if (buffer >= This->samples)
1170 if (buffer != This->samples)
1171 FIXME("Returned: %u (%08x)\n", buffer, GetLastError());
1172 hr = VFW_E_TIMEOUT;
1173 buffer = ~0;
1175 else if (buffer < This->samples)
1176 InterlockedDecrement(&This->queued_number);
1179 EnterCriticalSection(&This->csList);
1180 if (This->bFlushing && buffer == ~0)
1182 for (buffer = 0; buffer < This->samples; ++buffer)
1184 if (This->sample_list[buffer].pSample)
1186 ResetEvent(This->handle_list[buffer]);
1187 break;
1190 if (buffer == This->samples)
1192 assert(!This->queued_number);
1193 hr = VFW_E_TIMEOUT;
1195 else
1197 InterlockedDecrement(&This->queued_number);
1198 hr = S_OK;
1202 if (SUCCEEDED(hr))
1204 REFERENCE_TIME rtStart, rtStop;
1205 REFERENCE_TIME rtSampleStart, rtSampleStop;
1206 DATAREQUEST *pDataRq = This->sample_list + buffer;
1207 DWORD dwBytes = 0;
1209 /* get any errors */
1210 if (!This->bFlushing && !GetOverlappedResult(This->hFile, &pDataRq->ovl, &dwBytes, FALSE))
1211 hr = HRESULT_FROM_WIN32(GetLastError());
1213 /* Return the sample no matter what so it can be destroyed */
1214 *ppSample = pDataRq->pSample;
1215 *pdwUser = pDataRq->dwUserData;
1217 if (This->bFlushing)
1218 hr = VFW_E_WRONG_STATE;
1220 if (FAILED(hr))
1221 dwBytes = 0;
1223 /* Set the time on the sample */
1224 IMediaSample_SetActualDataLength(pDataRq->pSample, dwBytes);
1226 rtStart = (DWORD64)pDataRq->ovl.u.s.Offset + ((DWORD64)pDataRq->ovl.u.s.OffsetHigh << 32);
1227 rtStart = MEDIATIME_FROM_BYTES(rtStart);
1228 rtStop = rtStart + MEDIATIME_FROM_BYTES(dwBytes);
1230 IMediaSample_GetTime(pDataRq->pSample, &rtSampleStart, &rtSampleStop);
1231 assert(rtStart == rtSampleStart);
1232 assert(rtStop <= rtSampleStop);
1234 IMediaSample_SetTime(pDataRq->pSample, &rtStart, &rtStop);
1235 assert(rtStart == rtSampleStart);
1236 if (hr == S_OK)
1237 assert(rtStop == rtSampleStop);
1238 else
1239 assert(rtStop == rtStart);
1241 This->sample_list[buffer].pSample = NULL;
1243 LeaveCriticalSection(&This->csList);
1245 TRACE("-- %x\n", hr);
1246 return hr;
1249 static HRESULT WINAPI FileAsyncReader_SyncRead(IAsyncReader * iface, LONGLONG llPosition, LONG lLength, BYTE * pBuffer);
1251 static HRESULT WINAPI FileAsyncReader_SyncReadAligned(IAsyncReader * iface, IMediaSample * pSample)
1253 BYTE * pBuffer;
1254 REFERENCE_TIME tStart;
1255 REFERENCE_TIME tStop;
1256 HRESULT hr;
1258 TRACE("(%p)\n", pSample);
1260 hr = IMediaSample_GetTime(pSample, &tStart, &tStop);
1262 if (SUCCEEDED(hr))
1263 hr = IMediaSample_GetPointer(pSample, &pBuffer);
1265 if (SUCCEEDED(hr))
1266 hr = FileAsyncReader_SyncRead(iface,
1267 BYTES_FROM_MEDIATIME(tStart),
1268 (LONG) BYTES_FROM_MEDIATIME(tStop - tStart),
1269 pBuffer);
1271 TRACE("-- %x\n", hr);
1272 return hr;
1275 static HRESULT WINAPI FileAsyncReader_SyncRead(IAsyncReader * iface, LONGLONG llPosition, LONG lLength, BYTE * pBuffer)
1277 OVERLAPPED ovl;
1278 HRESULT hr = S_OK;
1279 FileAsyncReader *This = impl_from_IAsyncReader(iface);
1281 TRACE("(%x%08x, %d, %p)\n", (ULONG)(llPosition >> 32), (ULONG)llPosition, lLength, pBuffer);
1283 ZeroMemory(&ovl, sizeof(ovl));
1285 ovl.hEvent = CreateEventW(NULL, 0, 0, NULL);
1286 /* NOTE: llPosition is the actual byte position to start reading from */
1287 ovl.u.s.Offset = (DWORD) llPosition;
1288 ovl.u.s.OffsetHigh = (DWORD) (llPosition >> (sizeof(DWORD) * 8));
1290 if (!ReadFile(This->hFile, pBuffer, lLength, NULL, &ovl))
1291 hr = HRESULT_FROM_WIN32(GetLastError());
1293 if (hr == HRESULT_FROM_WIN32(ERROR_IO_PENDING))
1294 hr = S_OK;
1296 if (SUCCEEDED(hr))
1298 DWORD dwBytesRead;
1300 if (!GetOverlappedResult(This->hFile, &ovl, &dwBytesRead, TRUE))
1301 hr = HRESULT_FROM_WIN32(GetLastError());
1304 CloseHandle(ovl.hEvent);
1306 TRACE("-- %x\n", hr);
1307 return hr;
1310 static HRESULT WINAPI FileAsyncReader_Length(IAsyncReader * iface, LONGLONG * pTotal, LONGLONG * pAvailable)
1312 DWORD dwSizeLow;
1313 DWORD dwSizeHigh;
1314 FileAsyncReader *This = impl_from_IAsyncReader(iface);
1316 TRACE("(%p, %p)\n", pTotal, pAvailable);
1318 if (((dwSizeLow = GetFileSize(This->hFile, &dwSizeHigh)) == -1) &&
1319 (GetLastError() != NO_ERROR))
1320 return HRESULT_FROM_WIN32(GetLastError());
1322 *pTotal = (LONGLONG)dwSizeLow | (LONGLONG)dwSizeHigh << (sizeof(DWORD) * 8);
1324 *pAvailable = *pTotal;
1326 return S_OK;
1329 static HRESULT WINAPI FileAsyncReader_BeginFlush(IAsyncReader * iface)
1331 FileAsyncReader *This = impl_from_IAsyncReader(iface);
1333 TRACE("()\n");
1335 EnterCriticalSection(&This->csList);
1336 This->bFlushing = TRUE;
1337 CancelIo(This->hFile);
1338 SetEvent(This->handle_list[This->samples]);
1339 LeaveCriticalSection(&This->csList);
1341 return S_OK;
1344 static HRESULT WINAPI FileAsyncReader_EndFlush(IAsyncReader * iface)
1346 FileAsyncReader *This = impl_from_IAsyncReader(iface);
1347 int x;
1349 TRACE("()\n");
1351 EnterCriticalSection(&This->csList);
1352 ResetEvent(This->handle_list[This->samples]);
1353 This->bFlushing = FALSE;
1354 for (x = 0; x < This->samples; ++x)
1355 assert(!This->sample_list[x].pSample);
1357 LeaveCriticalSection(&This->csList);
1359 return S_OK;
1362 static const IAsyncReaderVtbl FileAsyncReader_Vtbl =
1364 FileAsyncReader_QueryInterface,
1365 FileAsyncReader_AddRef,
1366 FileAsyncReader_Release,
1367 FileAsyncReader_RequestAllocator,
1368 FileAsyncReader_Request,
1369 FileAsyncReader_WaitForNext,
1370 FileAsyncReader_SyncReadAligned,
1371 FileAsyncReader_SyncRead,
1372 FileAsyncReader_Length,
1373 FileAsyncReader_BeginFlush,
1374 FileAsyncReader_EndFlush,