2003-08-07 01:00:14 +02:00
|
|
|
/*
|
|
|
|
* File Source Filter
|
|
|
|
*
|
|
|
|
* Copyright 2003 Robert Shearman
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2003-08-07 01:00:14 +02:00
|
|
|
*/
|
|
|
|
|
2005-03-17 20:00:08 +01:00
|
|
|
#define NONAMELESSUNION
|
|
|
|
#define NONAMELESSSTRUCT
|
|
|
|
|
2003-08-07 01:00:14 +02:00
|
|
|
#include "quartz_private.h"
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
#include "wine/unicode.h"
|
|
|
|
#include "pin.h"
|
|
|
|
#include "uuids.h"
|
|
|
|
#include "vfwmsgs.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winreg.h"
|
2008-03-14 04:28:09 +01:00
|
|
|
#include "shlwapi.h"
|
2003-08-07 01:00:14 +02:00
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(quartz);
|
|
|
|
|
|
|
|
static const WCHAR wszOutputPinName[] = { 'O','u','t','p','u','t',0 };
|
|
|
|
|
|
|
|
typedef struct AsyncReader
|
|
|
|
{
|
2010-10-07 21:47:33 +02:00
|
|
|
BaseFilter filter;
|
2012-03-31 03:09:49 +02:00
|
|
|
IFileSourceFilter IFileSourceFilter_iface;
|
2003-08-07 01:00:14 +02:00
|
|
|
|
|
|
|
IPin * pOutputPin;
|
|
|
|
LPOLESTR pszFileName;
|
|
|
|
AM_MEDIA_TYPE * pmt;
|
|
|
|
} AsyncReader;
|
|
|
|
|
2012-03-31 03:09:49 +02:00
|
|
|
static inline AsyncReader *impl_from_BaseFilter(BaseFilter *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, AsyncReader, filter);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline AsyncReader *impl_from_IBaseFilter(IBaseFilter *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, AsyncReader, filter.IBaseFilter_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline AsyncReader *impl_from_IFileSourceFilter(IFileSourceFilter *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, AsyncReader, IFileSourceFilter_iface);
|
|
|
|
}
|
|
|
|
|
2005-06-06 21:50:35 +02:00
|
|
|
static const IBaseFilterVtbl AsyncReader_Vtbl;
|
|
|
|
static const IFileSourceFilterVtbl FileSource_Vtbl;
|
|
|
|
static const IAsyncReaderVtbl FileAsyncReader_Vtbl;
|
2003-08-07 01:00:14 +02:00
|
|
|
|
|
|
|
static HRESULT FileAsyncReader_Construct(HANDLE hFile, IBaseFilter * pBaseFilter, LPCRITICAL_SECTION pCritSec, IPin ** ppPin);
|
|
|
|
|
2011-12-20 09:12:07 +01:00
|
|
|
static const WCHAR mediatype_name[] = {
|
2008-03-14 04:28:09 +01:00
|
|
|
'M', 'e', 'd', 'i', 'a', ' ', 'T', 'y', 'p', 'e', 0 };
|
2011-12-20 09:12:07 +01:00
|
|
|
static const WCHAR subtype_name[] = {
|
2008-03-14 04:28:09 +01:00
|
|
|
'S', 'u', 'b', 't', 'y', 'p', 'e', 0 };
|
2013-02-21 16:28:50 +01:00
|
|
|
static const WCHAR source_filter_name[] = {
|
|
|
|
'S','o','u','r','c','e',' ','F','i','l','t','e','r',0};
|
2008-03-14 04:28:09 +01:00
|
|
|
|
2013-02-21 16:28:50 +01:00
|
|
|
static HRESULT process_extensions(HKEY hkeyExtensions, LPCOLESTR pszFileName, GUID * majorType, GUID * minorType, GUID * sourceFilter)
|
2003-08-07 01:00:14 +02:00
|
|
|
{
|
2008-03-14 04:28:09 +01:00
|
|
|
WCHAR *extension;
|
|
|
|
LONG l;
|
|
|
|
HKEY hsub;
|
|
|
|
WCHAR keying[39];
|
|
|
|
DWORD size;
|
|
|
|
|
|
|
|
if (!pszFileName)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
/* Get the part of the name that matters */
|
|
|
|
extension = PathFindExtensionW(pszFileName);
|
|
|
|
if (*extension != '.')
|
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
l = RegOpenKeyExW(hkeyExtensions, extension, 0, KEY_READ, &hsub);
|
|
|
|
if (l)
|
|
|
|
return E_FAIL;
|
|
|
|
|
2013-02-21 16:28:50 +01:00
|
|
|
if (majorType)
|
|
|
|
{
|
|
|
|
size = sizeof(keying);
|
|
|
|
l = RegQueryValueExW(hsub, mediatype_name, NULL, NULL, (LPBYTE)keying, &size);
|
|
|
|
if (!l)
|
|
|
|
CLSIDFromString(keying, majorType);
|
|
|
|
}
|
2008-03-14 04:28:09 +01:00
|
|
|
|
2013-02-21 16:28:50 +01:00
|
|
|
if (minorType)
|
|
|
|
{
|
|
|
|
size = sizeof(keying);
|
|
|
|
if (!l)
|
|
|
|
l = RegQueryValueExW(hsub, subtype_name, NULL, NULL, (LPBYTE)keying, &size);
|
|
|
|
if (!l)
|
|
|
|
CLSIDFromString(keying, minorType);
|
|
|
|
}
|
2008-04-08 07:31:15 +02:00
|
|
|
|
2013-02-21 16:28:50 +01:00
|
|
|
if (sourceFilter)
|
|
|
|
{
|
|
|
|
size = sizeof(keying);
|
|
|
|
if (!l)
|
|
|
|
l = RegQueryValueExW(hsub, source_filter_name, NULL, NULL, (LPBYTE)keying, &size);
|
|
|
|
if (!l)
|
|
|
|
CLSIDFromString(keying, sourceFilter);
|
|
|
|
}
|
2008-03-14 04:28:09 +01:00
|
|
|
|
|
|
|
RegCloseKey(hsub);
|
|
|
|
|
|
|
|
if (!l)
|
|
|
|
return S_OK;
|
|
|
|
return E_FAIL;
|
2003-08-07 01:00:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned char byte_from_hex_char(WCHAR wHex)
|
|
|
|
{
|
|
|
|
switch (tolowerW(wHex))
|
|
|
|
{
|
|
|
|
case '0':
|
|
|
|
case '1':
|
|
|
|
case '2':
|
|
|
|
case '3':
|
|
|
|
case '4':
|
|
|
|
case '5':
|
|
|
|
case '6':
|
|
|
|
case '7':
|
|
|
|
case '8':
|
|
|
|
case '9':
|
2006-06-21 22:49:35 +02:00
|
|
|
return (wHex - '0') & 0xf;
|
2003-08-07 01:00:14 +02:00
|
|
|
case 'a':
|
|
|
|
case 'b':
|
|
|
|
case 'c':
|
|
|
|
case 'd':
|
|
|
|
case 'e':
|
|
|
|
case 'f':
|
2006-06-21 22:49:35 +02:00
|
|
|
return (wHex - 'a' + 10) & 0xf;
|
2003-08-07 01:00:14 +02:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT process_pattern_string(LPCWSTR wszPatternString, IAsyncReader * pReader)
|
|
|
|
{
|
|
|
|
ULONG ulOffset;
|
|
|
|
ULONG ulBytes;
|
|
|
|
BYTE * pbMask;
|
|
|
|
BYTE * pbValue;
|
|
|
|
BYTE * pbFile;
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
ULONG strpos;
|
|
|
|
|
|
|
|
TRACE("\t\tPattern string: %s\n", debugstr_w(wszPatternString));
|
|
|
|
|
|
|
|
/* format: "offset, bytestocompare, mask, value" */
|
|
|
|
|
|
|
|
ulOffset = strtolW(wszPatternString, NULL, 10);
|
|
|
|
|
|
|
|
if (!(wszPatternString = strchrW(wszPatternString, ',')))
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
wszPatternString++; /* skip ',' */
|
|
|
|
|
|
|
|
ulBytes = strtolW(wszPatternString, NULL, 10);
|
|
|
|
|
|
|
|
pbMask = HeapAlloc(GetProcessHeap(), 0, ulBytes);
|
|
|
|
pbValue = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, ulBytes);
|
|
|
|
pbFile = HeapAlloc(GetProcessHeap(), 0, ulBytes);
|
|
|
|
|
|
|
|
/* default mask is match everything */
|
|
|
|
memset(pbMask, 0xFF, ulBytes);
|
|
|
|
|
|
|
|
if (!(wszPatternString = strchrW(wszPatternString, ',')))
|
|
|
|
hr = E_INVALIDARG;
|
|
|
|
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
2008-10-06 14:44:29 +02:00
|
|
|
wszPatternString++; /* skip ',' */
|
|
|
|
while (!isxdigitW(*wszPatternString) && (*wszPatternString != ',')) wszPatternString++;
|
2003-08-07 01:00:14 +02:00
|
|
|
|
|
|
|
for (strpos = 0; isxdigitW(*wszPatternString) && (strpos/2 < ulBytes); wszPatternString++, strpos++)
|
|
|
|
{
|
|
|
|
if ((strpos % 2) == 1) /* odd numbered position */
|
|
|
|
pbMask[strpos / 2] |= byte_from_hex_char(*wszPatternString);
|
|
|
|
else
|
|
|
|
pbMask[strpos / 2] = byte_from_hex_char(*wszPatternString) << 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(wszPatternString = strchrW(wszPatternString, ',')))
|
|
|
|
hr = E_INVALIDARG;
|
2011-05-03 16:19:02 +02:00
|
|
|
else
|
|
|
|
wszPatternString++; /* skip ',' */
|
2003-08-07 01:00:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
for ( ; !isxdigitW(*wszPatternString) && (*wszPatternString != ','); wszPatternString++)
|
|
|
|
;
|
|
|
|
|
|
|
|
for (strpos = 0; isxdigitW(*wszPatternString) && (strpos/2 < ulBytes); wszPatternString++, strpos++)
|
|
|
|
{
|
|
|
|
if ((strpos % 2) == 1) /* odd numbered position */
|
|
|
|
pbValue[strpos / 2] |= byte_from_hex_char(*wszPatternString);
|
|
|
|
else
|
|
|
|
pbValue[strpos / 2] = byte_from_hex_char(*wszPatternString) << 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hr == S_OK)
|
|
|
|
hr = IAsyncReader_SyncRead(pReader, ulOffset, ulBytes, pbFile);
|
|
|
|
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
ULONG i;
|
|
|
|
for (i = 0; i < ulBytes; i++)
|
|
|
|
if ((pbFile[i] & pbMask[i]) != pbValue[i])
|
|
|
|
{
|
|
|
|
hr = S_FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, pbMask);
|
|
|
|
HeapFree(GetProcessHeap(), 0, pbValue);
|
|
|
|
HeapFree(GetProcessHeap(), 0, pbFile);
|
|
|
|
|
|
|
|
/* if we encountered no errors with this string, and there is a following tuple, then we
|
|
|
|
* have to match that as well to succeed */
|
|
|
|
if ((hr == S_OK) && (wszPatternString = strchrW(wszPatternString, ',')))
|
|
|
|
return process_pattern_string(wszPatternString + 1, pReader);
|
|
|
|
else
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2013-02-21 16:29:55 +01:00
|
|
|
HRESULT GetClassMediaFile(IAsyncReader * pReader, LPCOLESTR pszFileName, GUID * majorType, GUID * minorType, GUID * sourceFilter)
|
2003-08-07 01:00:14 +02:00
|
|
|
{
|
|
|
|
HKEY hkeyMediaType = NULL;
|
2005-12-09 11:21:51 +01:00
|
|
|
LONG lRet;
|
2003-08-07 01:00:14 +02:00
|
|
|
HRESULT hr = S_OK;
|
|
|
|
BOOL bFound = FALSE;
|
2004-04-20 03:12:17 +02:00
|
|
|
static const WCHAR wszMediaType[] = {'M','e','d','i','a',' ','T','y','p','e',0};
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2008-03-14 04:28:09 +01:00
|
|
|
TRACE("(%p, %s, %p, %p)\n", pReader, debugstr_w(pszFileName), majorType, minorType);
|
|
|
|
|
2013-02-21 16:28:50 +01:00
|
|
|
if(majorType)
|
|
|
|
*majorType = GUID_NULL;
|
|
|
|
if(minorType)
|
|
|
|
*minorType = GUID_NULL;
|
|
|
|
if(sourceFilter)
|
|
|
|
*sourceFilter = GUID_NULL;
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2005-12-09 11:21:51 +01:00
|
|
|
lRet = RegOpenKeyExW(HKEY_CLASSES_ROOT, wszMediaType, 0, KEY_READ, &hkeyMediaType);
|
|
|
|
hr = HRESULT_FROM_WIN32(lRet);
|
2003-08-07 01:00:14 +02:00
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
DWORD indexMajor;
|
|
|
|
|
|
|
|
for (indexMajor = 0; !bFound; indexMajor++)
|
|
|
|
{
|
|
|
|
HKEY hkeyMajor;
|
|
|
|
WCHAR wszMajorKeyName[CHARS_IN_GUID];
|
2018-07-17 21:20:08 +02:00
|
|
|
DWORD dwKeyNameLength = ARRAY_SIZE(wszMajorKeyName);
|
2004-04-19 22:12:14 +02:00
|
|
|
static const WCHAR wszExtensions[] = {'E','x','t','e','n','s','i','o','n','s',0};
|
2008-03-14 04:28:09 +01:00
|
|
|
|
2003-08-07 01:00:14 +02:00
|
|
|
if (RegEnumKeyExW(hkeyMediaType, indexMajor, wszMajorKeyName, &dwKeyNameLength, NULL, NULL, NULL, NULL) != ERROR_SUCCESS)
|
|
|
|
break;
|
|
|
|
if (RegOpenKeyExW(hkeyMediaType, wszMajorKeyName, 0, KEY_READ, &hkeyMajor) != ERROR_SUCCESS)
|
|
|
|
break;
|
|
|
|
TRACE("%s\n", debugstr_w(wszMajorKeyName));
|
|
|
|
if (!strcmpW(wszExtensions, wszMajorKeyName))
|
|
|
|
{
|
2013-02-21 16:28:50 +01:00
|
|
|
if (process_extensions(hkeyMajor, pszFileName, majorType, minorType, sourceFilter) == S_OK)
|
2003-08-07 01:00:14 +02:00
|
|
|
bFound = TRUE;
|
|
|
|
}
|
2013-02-21 16:57:50 +01:00
|
|
|
/* We need a reader interface to check bytes */
|
|
|
|
else if (pReader)
|
2003-08-07 01:00:14 +02:00
|
|
|
{
|
|
|
|
DWORD indexMinor;
|
|
|
|
|
|
|
|
for (indexMinor = 0; !bFound; indexMinor++)
|
|
|
|
{
|
|
|
|
HKEY hkeyMinor;
|
|
|
|
WCHAR wszMinorKeyName[CHARS_IN_GUID];
|
2018-07-17 21:20:08 +02:00
|
|
|
DWORD dwMinorKeyNameLen = ARRAY_SIZE(wszMinorKeyName);
|
2013-02-21 16:28:50 +01:00
|
|
|
WCHAR wszSourceFilterKeyName[CHARS_IN_GUID];
|
2013-02-21 16:57:50 +01:00
|
|
|
DWORD dwSourceFilterKeyNameLen = sizeof(wszSourceFilterKeyName);
|
2003-08-07 01:00:14 +02:00
|
|
|
DWORD maxValueLen;
|
|
|
|
DWORD indexValue;
|
|
|
|
|
|
|
|
if (RegEnumKeyExW(hkeyMajor, indexMinor, wszMinorKeyName, &dwMinorKeyNameLen, NULL, NULL, NULL, NULL) != ERROR_SUCCESS)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (RegOpenKeyExW(hkeyMajor, wszMinorKeyName, 0, KEY_READ, &hkeyMinor) != ERROR_SUCCESS)
|
|
|
|
break;
|
|
|
|
|
|
|
|
TRACE("\t%s\n", debugstr_w(wszMinorKeyName));
|
|
|
|
|
|
|
|
if (RegQueryInfoKeyW(hkeyMinor, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &maxValueLen, NULL, NULL) != ERROR_SUCCESS)
|
|
|
|
break;
|
|
|
|
|
|
|
|
for (indexValue = 0; !bFound; indexValue++)
|
|
|
|
{
|
|
|
|
DWORD dwType;
|
|
|
|
WCHAR wszValueName[14]; /* longest name we should encounter will be "Source Filter" */
|
|
|
|
LPWSTR wszPatternString = HeapAlloc(GetProcessHeap(), 0, maxValueLen);
|
2018-07-17 21:20:08 +02:00
|
|
|
DWORD dwValueNameLen = ARRAY_SIZE(wszValueName);
|
2003-08-07 01:00:14 +02:00
|
|
|
DWORD dwDataLen = maxValueLen; /* remember this is in bytes */
|
|
|
|
|
2012-11-21 22:16:59 +01:00
|
|
|
if (RegEnumValueW(hkeyMinor, indexValue, wszValueName, &dwValueNameLen, NULL, &dwType, (LPBYTE)wszPatternString, &dwDataLen) != ERROR_SUCCESS)
|
2003-08-07 01:00:14 +02:00
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, wszPatternString);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-03-14 22:11:47 +01:00
|
|
|
if (strcmpW(wszValueName, source_filter_name)==0) {
|
|
|
|
HeapFree(GetProcessHeap(), 0, wszPatternString);
|
2013-02-21 16:28:50 +01:00
|
|
|
continue;
|
2013-03-14 22:11:47 +01:00
|
|
|
}
|
2013-02-21 16:28:50 +01:00
|
|
|
|
2003-08-07 01:00:14 +02:00
|
|
|
/* if it is not the source filter value */
|
2013-02-21 16:28:50 +01:00
|
|
|
if (process_pattern_string(wszPatternString, pReader) == S_OK)
|
2003-08-07 01:00:14 +02:00
|
|
|
{
|
2013-03-14 22:11:47 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, wszPatternString);
|
2013-02-21 16:28:50 +01:00
|
|
|
if (majorType && FAILED(CLSIDFromString(wszMajorKeyName, majorType)))
|
|
|
|
break;
|
|
|
|
if (minorType && FAILED(CLSIDFromString(wszMinorKeyName, minorType)))
|
|
|
|
break;
|
|
|
|
if (sourceFilter)
|
2003-08-07 01:00:14 +02:00
|
|
|
{
|
2013-02-21 16:28:50 +01:00
|
|
|
/* Look up the source filter key */
|
|
|
|
if (RegQueryValueExW(hkeyMinor, source_filter_name, NULL, NULL, (LPBYTE)wszSourceFilterKeyName, &dwSourceFilterKeyNameLen))
|
|
|
|
break;
|
|
|
|
if (FAILED(CLSIDFromString(wszSourceFilterKeyName, sourceFilter)))
|
|
|
|
break;
|
2003-08-07 01:00:14 +02:00
|
|
|
}
|
2013-02-21 16:28:50 +01:00
|
|
|
bFound = TRUE;
|
2013-03-14 22:11:47 +01:00
|
|
|
} else
|
|
|
|
HeapFree(GetProcessHeap(), 0, wszPatternString);
|
2003-08-07 01:00:14 +02:00
|
|
|
}
|
|
|
|
CloseHandle(hkeyMinor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CloseHandle(hkeyMajor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CloseHandle(hkeyMediaType);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr) && !bFound)
|
|
|
|
{
|
|
|
|
ERR("Media class not found\n");
|
2004-12-27 18:15:58 +01:00
|
|
|
hr = E_FAIL;
|
2003-08-07 01:00:14 +02:00
|
|
|
}
|
|
|
|
else if (bFound)
|
2013-02-21 16:57:50 +01:00
|
|
|
{
|
|
|
|
TRACE("Found file's class:\n");
|
|
|
|
if(majorType)
|
|
|
|
TRACE("\tmajor = %s\n", qzdebugstr_guid(majorType));
|
|
|
|
if(minorType)
|
|
|
|
TRACE("\tsubtype = %s\n", qzdebugstr_guid(minorType));
|
|
|
|
if(sourceFilter)
|
|
|
|
TRACE("\tsource filter = %s\n", qzdebugstr_guid(sourceFilter));
|
|
|
|
}
|
2003-08-07 01:00:14 +02:00
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2010-10-13 18:02:01 +02:00
|
|
|
static IPin* WINAPI AsyncReader_GetPin(BaseFilter *iface, int pos)
|
2010-10-07 21:48:01 +02:00
|
|
|
{
|
2012-03-31 03:09:49 +02:00
|
|
|
AsyncReader *This = impl_from_BaseFilter(iface);
|
2010-10-07 21:48:01 +02:00
|
|
|
|
2017-11-09 01:12:20 +01:00
|
|
|
TRACE("%p->(%d)\n", This, pos);
|
|
|
|
|
2010-10-07 21:48:01 +02:00
|
|
|
if (pos >= 1 || !This->pOutputPin)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
IPin_AddRef(This->pOutputPin);
|
|
|
|
return This->pOutputPin;
|
|
|
|
}
|
|
|
|
|
2010-10-13 18:02:01 +02:00
|
|
|
static LONG WINAPI AsyncReader_GetPinCount(BaseFilter *iface)
|
2010-10-07 21:48:01 +02:00
|
|
|
{
|
2012-03-31 03:09:49 +02:00
|
|
|
AsyncReader *This = impl_from_BaseFilter(iface);
|
2010-10-07 21:48:01 +02:00
|
|
|
|
2017-11-09 01:12:20 +01:00
|
|
|
TRACE("%p->()\n", This);
|
|
|
|
|
2010-10-07 21:48:01 +02:00
|
|
|
if (!This->pOutputPin)
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2010-10-13 18:02:01 +02:00
|
|
|
static const BaseFilterFuncTable BaseFuncTable = {
|
|
|
|
AsyncReader_GetPin,
|
|
|
|
AsyncReader_GetPinCount
|
|
|
|
};
|
|
|
|
|
2003-08-07 01:00:14 +02:00
|
|
|
HRESULT AsyncReader_create(IUnknown * pUnkOuter, LPVOID * ppv)
|
|
|
|
{
|
2004-10-18 23:21:19 +02:00
|
|
|
AsyncReader *pAsyncRead;
|
|
|
|
|
|
|
|
if( pUnkOuter )
|
|
|
|
return CLASS_E_NOAGGREGATION;
|
|
|
|
|
|
|
|
pAsyncRead = CoTaskMemAlloc(sizeof(AsyncReader));
|
2003-08-07 01:00:14 +02:00
|
|
|
|
|
|
|
if (!pAsyncRead)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2010-10-13 18:02:01 +02:00
|
|
|
BaseFilter_Init(&pAsyncRead->filter, &AsyncReader_Vtbl, &CLSID_AsyncReader, (DWORD_PTR)(__FILE__ ": AsyncReader.csFilter"), &BaseFuncTable);
|
2010-10-07 21:47:33 +02:00
|
|
|
|
2012-03-31 03:09:49 +02:00
|
|
|
pAsyncRead->IFileSourceFilter_iface.lpVtbl = &FileSource_Vtbl;
|
2003-08-07 01:00:14 +02:00
|
|
|
pAsyncRead->pOutputPin = NULL;
|
|
|
|
|
|
|
|
pAsyncRead->pszFileName = NULL;
|
|
|
|
pAsyncRead->pmt = NULL;
|
|
|
|
|
2009-01-29 11:14:55 +01:00
|
|
|
*ppv = pAsyncRead;
|
2003-08-07 01:00:14 +02:00
|
|
|
|
|
|
|
TRACE("-- created at %p\n", pAsyncRead);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2005-11-23 20:14:43 +01:00
|
|
|
/** IUnknown methods **/
|
2003-08-07 01:00:14 +02:00
|
|
|
|
|
|
|
static HRESULT WINAPI AsyncReader_QueryInterface(IBaseFilter * iface, REFIID riid, LPVOID * ppv)
|
|
|
|
{
|
2012-03-31 03:09:49 +02:00
|
|
|
AsyncReader *This = impl_from_IBaseFilter(iface);
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2017-11-09 01:12:20 +01:00
|
|
|
TRACE("%p->(%s, %p)\n", This, qzdebugstr_guid(riid), ppv);
|
2003-08-07 01:00:14 +02:00
|
|
|
|
|
|
|
*ppv = NULL;
|
|
|
|
|
|
|
|
if (IsEqualIID(riid, &IID_IUnknown))
|
2015-06-26 05:52:42 +02:00
|
|
|
*ppv = &This->filter.IBaseFilter_iface;
|
2003-08-07 01:00:14 +02:00
|
|
|
else if (IsEqualIID(riid, &IID_IPersist))
|
2015-06-26 05:52:42 +02:00
|
|
|
*ppv = &This->filter.IBaseFilter_iface;
|
2003-08-07 01:00:14 +02:00
|
|
|
else if (IsEqualIID(riid, &IID_IMediaFilter))
|
2015-06-26 05:52:42 +02:00
|
|
|
*ppv = &This->filter.IBaseFilter_iface;
|
2003-08-07 01:00:14 +02:00
|
|
|
else if (IsEqualIID(riid, &IID_IBaseFilter))
|
2015-06-26 05:52:42 +02:00
|
|
|
*ppv = &This->filter.IBaseFilter_iface;
|
2003-08-07 01:00:14 +02:00
|
|
|
else if (IsEqualIID(riid, &IID_IFileSourceFilter))
|
2012-03-31 03:09:49 +02:00
|
|
|
*ppv = &This->IFileSourceFilter_iface;
|
2003-08-07 01:00:14 +02:00
|
|
|
|
|
|
|
if (*ppv)
|
|
|
|
{
|
|
|
|
IUnknown_AddRef((IUnknown *)(*ppv));
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2010-03-02 20:46:43 +01:00
|
|
|
if (!IsEqualIID(riid, &IID_IPin) && !IsEqualIID(riid, &IID_IMediaSeeking) &&
|
|
|
|
!IsEqualIID(riid, &IID_IVideoWindow) && !IsEqualIID(riid, &IID_IBasicAudio))
|
2008-03-21 23:36:51 +01:00
|
|
|
FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
|
2003-08-07 01:00:14 +02:00
|
|
|
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI AsyncReader_Release(IBaseFilter * iface)
|
|
|
|
{
|
2012-03-31 03:09:49 +02:00
|
|
|
AsyncReader *This = impl_from_IBaseFilter(iface);
|
2014-07-19 10:29:54 +02:00
|
|
|
ULONG refCount = InterlockedDecrement(&This->filter.refCount);
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2017-11-09 01:12:20 +01:00
|
|
|
TRACE("%p->() Release from %d\n", This, refCount + 1);
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2005-01-06 20:36:47 +01:00
|
|
|
if (!refCount)
|
2003-08-07 01:00:14 +02:00
|
|
|
{
|
|
|
|
if (This->pOutputPin)
|
2007-03-19 21:28:32 +01:00
|
|
|
{
|
|
|
|
IPin *pConnectedTo;
|
|
|
|
if(SUCCEEDED(IPin_ConnectedTo(This->pOutputPin, &pConnectedTo)))
|
|
|
|
{
|
|
|
|
IPin_Disconnect(pConnectedTo);
|
|
|
|
IPin_Release(pConnectedTo);
|
|
|
|
}
|
|
|
|
IPin_Disconnect(This->pOutputPin);
|
2003-08-07 01:00:14 +02:00
|
|
|
IPin_Release(This->pOutputPin);
|
2007-03-19 21:28:32 +01:00
|
|
|
}
|
2008-04-04 23:32:09 +02:00
|
|
|
CoTaskMemFree(This->pszFileName);
|
2008-04-08 07:31:15 +02:00
|
|
|
if (This->pmt)
|
|
|
|
FreeMediaType(This->pmt);
|
2014-07-19 10:29:54 +02:00
|
|
|
BaseFilter_Destroy(&This->filter);
|
2003-08-07 01:00:14 +02:00
|
|
|
CoTaskMemFree(This);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
2005-01-06 20:36:47 +01:00
|
|
|
return refCount;
|
2003-08-07 01:00:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/** IMediaFilter methods **/
|
|
|
|
|
|
|
|
static HRESULT WINAPI AsyncReader_Stop(IBaseFilter * iface)
|
|
|
|
{
|
2012-03-31 03:09:49 +02:00
|
|
|
AsyncReader *This = impl_from_IBaseFilter(iface);
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2017-11-09 01:12:20 +01:00
|
|
|
TRACE("%p->()\n", This);
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2010-10-07 21:47:33 +02:00
|
|
|
This->filter.state = State_Stopped;
|
2003-08-07 01:00:14 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI AsyncReader_Pause(IBaseFilter * iface)
|
|
|
|
{
|
2012-03-31 03:09:49 +02:00
|
|
|
AsyncReader *This = impl_from_IBaseFilter(iface);
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2017-11-09 01:12:20 +01:00
|
|
|
TRACE("%p->()\n", This);
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2010-10-07 21:47:33 +02:00
|
|
|
This->filter.state = State_Paused;
|
2003-08-07 01:00:14 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI AsyncReader_Run(IBaseFilter * iface, REFERENCE_TIME tStart)
|
|
|
|
{
|
2012-03-31 03:09:49 +02:00
|
|
|
AsyncReader *This = impl_from_IBaseFilter(iface);
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2017-11-09 01:12:20 +01:00
|
|
|
TRACE("%p->(%s)\n", This, wine_dbgstr_longlong(tStart));
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2010-10-07 21:47:33 +02:00
|
|
|
This->filter.state = State_Running;
|
2003-08-07 01:00:14 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IBaseFilterVtbl AsyncReader_Vtbl =
|
|
|
|
{
|
|
|
|
AsyncReader_QueryInterface,
|
2010-10-07 21:47:33 +02:00
|
|
|
BaseFilterImpl_AddRef,
|
2003-08-07 01:00:14 +02:00
|
|
|
AsyncReader_Release,
|
2010-10-07 21:47:33 +02:00
|
|
|
BaseFilterImpl_GetClassID,
|
2003-08-07 01:00:14 +02:00
|
|
|
AsyncReader_Stop,
|
|
|
|
AsyncReader_Pause,
|
|
|
|
AsyncReader_Run,
|
2010-10-07 21:47:33 +02:00
|
|
|
BaseFilterImpl_GetState,
|
|
|
|
BaseFilterImpl_SetSyncSource,
|
|
|
|
BaseFilterImpl_GetSyncSource,
|
2010-10-07 21:48:01 +02:00
|
|
|
BaseFilterImpl_EnumPins,
|
2018-07-05 00:34:41 +02:00
|
|
|
BaseFilterImpl_FindPin,
|
2010-10-07 21:47:33 +02:00
|
|
|
BaseFilterImpl_QueryFilterInfo,
|
|
|
|
BaseFilterImpl_JoinFilterGraph,
|
|
|
|
BaseFilterImpl_QueryVendorInfo
|
2003-08-07 01:00:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static HRESULT WINAPI FileSource_QueryInterface(IFileSourceFilter * iface, REFIID riid, LPVOID * ppv)
|
|
|
|
{
|
2005-07-27 17:14:18 +02:00
|
|
|
AsyncReader *This = impl_from_IFileSourceFilter(iface);
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2012-03-24 17:42:27 +01:00
|
|
|
return IBaseFilter_QueryInterface(&This->filter.IBaseFilter_iface, riid, ppv);
|
2003-08-07 01:00:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI FileSource_AddRef(IFileSourceFilter * iface)
|
|
|
|
{
|
2005-07-27 17:14:18 +02:00
|
|
|
AsyncReader *This = impl_from_IFileSourceFilter(iface);
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2012-03-24 17:42:27 +01:00
|
|
|
return IBaseFilter_AddRef(&This->filter.IBaseFilter_iface);
|
2003-08-07 01:00:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI FileSource_Release(IFileSourceFilter * iface)
|
|
|
|
{
|
2005-07-27 17:14:18 +02:00
|
|
|
AsyncReader *This = impl_from_IFileSourceFilter(iface);
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2012-03-24 17:42:27 +01:00
|
|
|
return IBaseFilter_Release(&This->filter.IBaseFilter_iface);
|
2003-08-07 01:00:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI FileSource_Load(IFileSourceFilter * iface, LPCOLESTR pszFileName, const AM_MEDIA_TYPE * pmt)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
HANDLE hFile;
|
|
|
|
IAsyncReader * pReader = NULL;
|
2005-07-27 17:14:18 +02:00
|
|
|
AsyncReader *This = impl_from_IFileSourceFilter(iface);
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2017-11-09 01:12:20 +01:00
|
|
|
TRACE("%p->(%s, %p)\n", This, debugstr_w(pszFileName), pmt);
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2016-04-28 21:56:50 +02:00
|
|
|
if (!pszFileName)
|
|
|
|
return E_POINTER;
|
|
|
|
|
2003-08-07 01:00:14 +02:00
|
|
|
/* open file */
|
|
|
|
/* FIXME: check the sharing values that native uses */
|
|
|
|
hFile = CreateFileW(pszFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);
|
|
|
|
|
|
|
|
if (hFile == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
return HRESULT_FROM_WIN32(GetLastError());
|
|
|
|
}
|
|
|
|
|
|
|
|
/* create pin */
|
2012-03-24 17:42:27 +01:00
|
|
|
hr = FileAsyncReader_Construct(hFile, &This->filter.IBaseFilter_iface, &This->filter.csFilter, &This->pOutputPin);
|
|
|
|
BaseFilterImpl_IncrementPinVersion(&This->filter);
|
2003-08-07 01:00:14 +02:00
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
hr = IPin_QueryInterface(This->pOutputPin, &IID_IAsyncReader, (LPVOID *)&pReader);
|
|
|
|
|
|
|
|
/* store file name & media type */
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
2008-04-04 23:32:09 +02:00
|
|
|
CoTaskMemFree(This->pszFileName);
|
|
|
|
if (This->pmt)
|
|
|
|
FreeMediaType(This->pmt);
|
|
|
|
|
2003-08-07 01:00:14 +02:00
|
|
|
This->pszFileName = CoTaskMemAlloc((strlenW(pszFileName) + 1) * sizeof(WCHAR));
|
|
|
|
strcpyW(This->pszFileName, pszFileName);
|
2008-04-04 23:32:09 +02:00
|
|
|
|
2003-08-07 01:00:14 +02:00
|
|
|
This->pmt = CoTaskMemAlloc(sizeof(AM_MEDIA_TYPE));
|
|
|
|
if (!pmt)
|
|
|
|
{
|
|
|
|
This->pmt->bFixedSizeSamples = TRUE;
|
|
|
|
This->pmt->bTemporalCompression = FALSE;
|
|
|
|
This->pmt->cbFormat = 0;
|
|
|
|
This->pmt->pbFormat = NULL;
|
|
|
|
This->pmt->pUnk = NULL;
|
|
|
|
This->pmt->lSampleSize = 0;
|
2008-03-12 21:32:07 +01:00
|
|
|
This->pmt->formattype = FORMAT_None;
|
2013-02-21 16:28:50 +01:00
|
|
|
hr = GetClassMediaFile(pReader, pszFileName, &This->pmt->majortype, &This->pmt->subtype, NULL);
|
2003-08-07 01:00:14 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2016-04-29 22:13:35 +02:00
|
|
|
This->pmt->majortype = MEDIATYPE_Stream;
|
|
|
|
This->pmt->subtype = MEDIASUBTYPE_NULL;
|
|
|
|
hr = S_OK;
|
2003-08-07 01:00:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
CopyMediaType(This->pmt, pmt);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pReader)
|
|
|
|
IAsyncReader_Release(pReader);
|
|
|
|
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
if (This->pOutputPin)
|
|
|
|
{
|
|
|
|
IPin_Release(This->pOutputPin);
|
|
|
|
This->pOutputPin = NULL;
|
|
|
|
}
|
2006-10-07 03:05:08 +02:00
|
|
|
|
|
|
|
CoTaskMemFree(This->pszFileName);
|
2008-04-08 07:31:15 +02:00
|
|
|
if (This->pmt)
|
|
|
|
FreeMediaType(This->pmt);
|
2006-10-07 03:05:08 +02:00
|
|
|
This->pszFileName = NULL;
|
2008-04-04 23:32:09 +02:00
|
|
|
This->pmt = NULL;
|
2006-10-07 03:05:08 +02:00
|
|
|
|
2003-08-07 01:00:14 +02:00
|
|
|
CloseHandle(hFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: check return codes */
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI FileSource_GetCurFile(IFileSourceFilter * iface, LPOLESTR * ppszFileName, AM_MEDIA_TYPE * pmt)
|
|
|
|
{
|
2005-07-27 17:14:18 +02:00
|
|
|
AsyncReader *This = impl_from_IFileSourceFilter(iface);
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2017-11-09 01:12:20 +01:00
|
|
|
TRACE("%p->(%p, %p)\n", This, ppszFileName, pmt);
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2007-02-13 23:28:02 +01:00
|
|
|
if (!ppszFileName)
|
|
|
|
return E_POINTER;
|
|
|
|
|
2003-08-07 01:00:14 +02:00
|
|
|
/* copy file name & media type if available, otherwise clear the outputs */
|
|
|
|
if (This->pszFileName)
|
|
|
|
{
|
|
|
|
*ppszFileName = CoTaskMemAlloc((strlenW(This->pszFileName) + 1) * sizeof(WCHAR));
|
|
|
|
strcpyW(*ppszFileName, This->pszFileName);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*ppszFileName = NULL;
|
|
|
|
|
2007-02-13 23:28:02 +01:00
|
|
|
if (pmt)
|
2003-08-07 01:00:14 +02:00
|
|
|
{
|
2007-02-13 23:28:02 +01:00
|
|
|
if (This->pmt)
|
|
|
|
CopyMediaType(pmt, This->pmt);
|
|
|
|
else
|
|
|
|
ZeroMemory(pmt, sizeof(*pmt));
|
2003-08-07 01:00:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IFileSourceFilterVtbl FileSource_Vtbl =
|
|
|
|
{
|
|
|
|
FileSource_QueryInterface,
|
|
|
|
FileSource_AddRef,
|
|
|
|
FileSource_Release,
|
|
|
|
FileSource_Load,
|
|
|
|
FileSource_GetCurFile
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* the dwUserData passed back to user */
|
|
|
|
typedef struct DATAREQUEST
|
|
|
|
{
|
|
|
|
IMediaSample * pSample; /* sample passed to us by user */
|
|
|
|
DWORD_PTR dwUserData; /* user data passed to us */
|
|
|
|
OVERLAPPED ovl; /* our overlapped structure */
|
|
|
|
} DATAREQUEST;
|
|
|
|
|
|
|
|
typedef struct FileAsyncReader
|
|
|
|
{
|
2010-10-05 21:37:56 +02:00
|
|
|
BaseOutputPin pin;
|
2012-03-31 03:09:49 +02:00
|
|
|
IAsyncReader IAsyncReader_iface;
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2010-10-13 17:46:27 +02:00
|
|
|
ALLOCATOR_PROPERTIES allocProps;
|
2003-08-07 01:00:14 +02:00
|
|
|
HANDLE hFile;
|
|
|
|
BOOL bFlushing;
|
2008-04-23 01:54:28 +02:00
|
|
|
/* Why would you need more? Every sample has its own handle */
|
|
|
|
LONG queued_number;
|
|
|
|
LONG samples;
|
2008-07-10 23:33:53 +02:00
|
|
|
LONG oldest_sample;
|
2008-04-23 01:54:28 +02:00
|
|
|
CRITICAL_SECTION csList; /* critical section to prevent concurrency issues */
|
|
|
|
DATAREQUEST *sample_list;
|
2008-04-25 23:33:15 +02:00
|
|
|
|
|
|
|
/* Have a handle for every sample, and then one more as flushing handle */
|
2008-04-23 01:54:28 +02:00
|
|
|
HANDLE *handle_list;
|
2003-08-07 01:00:14 +02:00
|
|
|
} FileAsyncReader;
|
|
|
|
|
2012-03-31 03:09:49 +02:00
|
|
|
static inline FileAsyncReader *impl_from_IPin(IPin *iface)
|
2005-07-27 17:14:18 +02:00
|
|
|
{
|
2012-03-31 03:09:49 +02:00
|
|
|
return CONTAINING_RECORD(iface, FileAsyncReader, pin.pin.IPin_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline FileAsyncReader *impl_from_BasePin(BasePin *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, FileAsyncReader, pin.pin);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline FileAsyncReader *impl_from_BaseOutputPin(BaseOutputPin *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, FileAsyncReader, pin);
|
|
|
|
}
|
|
|
|
|
2016-04-13 11:28:56 +02:00
|
|
|
static inline BaseOutputPin *impl_BaseOutputPin_from_BasePin(BasePin *iface)
|
2012-03-31 03:09:49 +02:00
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, BaseOutputPin, pin);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline FileAsyncReader *impl_from_IAsyncReader(IAsyncReader *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, FileAsyncReader, IAsyncReader_iface);
|
2005-07-27 17:14:18 +02:00
|
|
|
}
|
|
|
|
|
2018-05-04 06:47:13 +02:00
|
|
|
static HRESULT WINAPI FileAsyncReaderPin_CheckMediaType(BasePin *pin, const AM_MEDIA_TYPE *pmt)
|
2003-08-07 01:00:14 +02:00
|
|
|
{
|
2018-05-04 06:47:13 +02:00
|
|
|
AM_MEDIA_TYPE *pmt_filter = impl_from_IBaseFilter(pin->pinInfo.pFilter)->pmt;
|
2009-01-29 11:14:55 +01:00
|
|
|
|
2018-05-04 06:47:13 +02:00
|
|
|
FIXME("(%p, %p)\n", pin, pmt);
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2010-10-05 21:37:42 +02:00
|
|
|
if (IsEqualGUID(&pmt->majortype, &pmt_filter->majortype) &&
|
|
|
|
IsEqualGUID(&pmt->subtype, &pmt_filter->subtype) &&
|
2003-08-07 01:00:14 +02:00
|
|
|
IsEqualGUID(&pmt->formattype, &FORMAT_None))
|
|
|
|
return S_OK;
|
2010-10-05 21:37:42 +02:00
|
|
|
|
2003-08-07 01:00:14 +02:00
|
|
|
return S_FALSE;
|
|
|
|
}
|
|
|
|
|
2010-10-13 18:02:01 +02:00
|
|
|
static HRESULT WINAPI FileAsyncReaderPin_GetMediaType(BasePin *iface, int iPosition, AM_MEDIA_TYPE *pmt)
|
2010-10-05 21:37:30 +02:00
|
|
|
{
|
2012-03-31 03:09:49 +02:00
|
|
|
FileAsyncReader *This = impl_from_BasePin(iface);
|
2010-10-05 21:37:30 +02:00
|
|
|
if (iPosition < 0)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
if (iPosition > 0)
|
|
|
|
return VFW_S_NO_MORE_ITEMS;
|
2012-03-31 03:09:49 +02:00
|
|
|
CopyMediaType(pmt, impl_from_IBaseFilter(This->pin.pin.pinInfo.pFilter)->pmt);
|
2010-10-05 21:37:30 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2008-04-11 04:17:14 +02:00
|
|
|
/* overridden pin functions */
|
2003-08-07 01:00:14 +02:00
|
|
|
|
|
|
|
static HRESULT WINAPI FileAsyncReaderPin_QueryInterface(IPin * iface, REFIID riid, LPVOID * ppv)
|
|
|
|
{
|
2012-03-31 03:09:49 +02:00
|
|
|
FileAsyncReader *This = impl_from_IPin(iface);
|
2003-08-07 01:00:14 +02:00
|
|
|
TRACE("(%s, %p)\n", qzdebugstr_guid(riid), ppv);
|
|
|
|
|
|
|
|
*ppv = NULL;
|
|
|
|
|
2015-10-21 13:31:49 +02:00
|
|
|
if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IPin))
|
|
|
|
*ppv = &This->pin.pin.IPin_iface;
|
2003-08-07 01:00:14 +02:00
|
|
|
else if (IsEqualIID(riid, &IID_IAsyncReader))
|
2012-03-31 03:09:49 +02:00
|
|
|
*ppv = &This->IAsyncReader_iface;
|
2003-08-07 01:00:14 +02:00
|
|
|
|
|
|
|
if (*ppv)
|
|
|
|
{
|
2015-10-21 13:31:49 +02:00
|
|
|
IUnknown_AddRef((IUnknown *)*ppv);
|
2003-08-07 01:00:14 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2015-10-21 13:31:49 +02:00
|
|
|
if (!IsEqualIID(riid, &IID_IMediaSeeking))
|
2008-03-21 23:36:51 +01:00
|
|
|
FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
|
2003-08-07 01:00:14 +02:00
|
|
|
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI FileAsyncReaderPin_Release(IPin * iface)
|
|
|
|
{
|
2012-03-31 03:09:49 +02:00
|
|
|
FileAsyncReader *This = impl_from_IPin(iface);
|
2005-01-06 20:36:47 +01:00
|
|
|
ULONG refCount = InterlockedDecrement(&This->pin.pin.refCount);
|
2008-04-23 01:54:28 +02:00
|
|
|
int x;
|
|
|
|
|
2007-03-05 15:11:37 +01:00
|
|
|
TRACE("(%p)->() Release from %d\n", This, refCount + 1);
|
2008-04-23 01:54:28 +02:00
|
|
|
|
2005-01-06 20:36:47 +01:00
|
|
|
if (!refCount)
|
2003-08-07 01:00:14 +02:00
|
|
|
{
|
2008-04-23 01:54:28 +02:00
|
|
|
CoTaskMemFree(This->sample_list);
|
|
|
|
if (This->handle_list)
|
2003-08-07 01:00:14 +02:00
|
|
|
{
|
2008-04-25 23:33:15 +02:00
|
|
|
for (x = 0; x <= This->samples; ++x)
|
2008-04-23 01:54:28 +02:00
|
|
|
CloseHandle(This->handle_list[x]);
|
|
|
|
CoTaskMemFree(This->handle_list);
|
2003-08-07 01:00:14 +02:00
|
|
|
}
|
|
|
|
CloseHandle(This->hFile);
|
2007-03-10 22:10:20 +01:00
|
|
|
This->csList.DebugInfo->Spare[0] = 0;
|
|
|
|
DeleteCriticalSection(&This->csList);
|
2014-07-27 11:39:55 +02:00
|
|
|
BaseOutputPin_Destroy(&This->pin);
|
2003-08-07 01:00:14 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2005-01-06 20:36:47 +01:00
|
|
|
return refCount;
|
2003-08-07 01:00:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const IPinVtbl FileAsyncReaderPin_Vtbl =
|
|
|
|
{
|
|
|
|
FileAsyncReaderPin_QueryInterface,
|
2010-10-05 21:37:42 +02:00
|
|
|
BasePinImpl_AddRef,
|
2003-08-07 01:00:14 +02:00
|
|
|
FileAsyncReaderPin_Release,
|
2010-10-05 21:37:56 +02:00
|
|
|
BaseOutputPinImpl_Connect,
|
|
|
|
BaseOutputPinImpl_ReceiveConnection,
|
2010-10-05 21:37:42 +02:00
|
|
|
BasePinImpl_Disconnect,
|
|
|
|
BasePinImpl_ConnectedTo,
|
|
|
|
BasePinImpl_ConnectionMediaType,
|
|
|
|
BasePinImpl_QueryPinInfo,
|
|
|
|
BasePinImpl_QueryDirection,
|
|
|
|
BasePinImpl_QueryId,
|
2018-05-04 06:47:13 +02:00
|
|
|
BasePinImpl_QueryAccept,
|
2010-10-13 18:02:08 +02:00
|
|
|
BasePinImpl_EnumMediaTypes,
|
2010-10-05 21:37:42 +02:00
|
|
|
BasePinImpl_QueryInternalConnections,
|
2010-10-05 21:37:56 +02:00
|
|
|
BaseOutputPinImpl_EndOfStream,
|
|
|
|
BaseOutputPinImpl_BeginFlush,
|
|
|
|
BaseOutputPinImpl_EndFlush,
|
2010-11-01 13:42:14 +01:00
|
|
|
BasePinImpl_NewSegment
|
2003-08-07 01:00:14 +02:00
|
|
|
};
|
|
|
|
|
2004-08-19 04:33:00 +02:00
|
|
|
/* Function called as a helper to IPin_Connect */
|
|
|
|
/* specific AM_MEDIA_TYPE - it cannot be NULL */
|
2010-10-05 21:37:56 +02:00
|
|
|
/* this differs from standard OutputPin_AttemptConnection only in that it
|
2004-08-19 04:33:00 +02:00
|
|
|
* doesn't need the IMemInputPin interface on the receiving pin */
|
2010-10-13 18:02:01 +02:00
|
|
|
static HRESULT WINAPI FileAsyncReaderPin_AttemptConnection(BasePin * iface, IPin * pReceivePin, const AM_MEDIA_TYPE * pmt)
|
2004-08-19 04:33:00 +02:00
|
|
|
{
|
2016-04-13 11:28:56 +02:00
|
|
|
BaseOutputPin *This = impl_BaseOutputPin_from_BasePin(iface);
|
2004-08-19 04:33:00 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
2017-11-09 01:12:20 +01:00
|
|
|
TRACE("%p->(%p, %p)\n", This, pReceivePin, pmt);
|
2004-08-19 04:33:00 +02:00
|
|
|
dump_AM_MEDIA_TYPE(pmt);
|
|
|
|
|
|
|
|
/* FIXME: call queryacceptproc */
|
|
|
|
|
|
|
|
This->pin.pConnectedTo = pReceivePin;
|
|
|
|
IPin_AddRef(pReceivePin);
|
|
|
|
CopyMediaType(&This->pin.mtCurrent, pmt);
|
|
|
|
|
2012-03-31 03:09:49 +02:00
|
|
|
hr = IPin_ReceiveConnection(pReceivePin, &iface->IPin_iface, pmt);
|
2004-08-19 04:33:00 +02:00
|
|
|
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
IPin_Release(This->pin.pConnectedTo);
|
|
|
|
This->pin.pConnectedTo = NULL;
|
2005-06-05 21:18:34 +02:00
|
|
|
FreeMediaType(&This->pin.mtCurrent);
|
2004-08-19 04:33:00 +02:00
|
|
|
}
|
|
|
|
|
2006-10-12 20:57:23 +02:00
|
|
|
TRACE(" -- %x\n", hr);
|
2004-08-19 04:33:00 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2010-10-13 18:02:01 +02:00
|
|
|
static HRESULT WINAPI FileAsyncReaderPin_DecideBufferSize(BaseOutputPin *iface, IMemAllocator *pAlloc, ALLOCATOR_PROPERTIES *ppropInputRequest)
|
2010-10-13 17:46:27 +02:00
|
|
|
{
|
2012-03-31 03:09:49 +02:00
|
|
|
FileAsyncReader *This = impl_from_BaseOutputPin(iface);
|
2010-10-13 17:46:27 +02:00
|
|
|
ALLOCATOR_PROPERTIES actual;
|
|
|
|
|
|
|
|
if (ppropInputRequest->cbAlign && ppropInputRequest->cbAlign != This->allocProps.cbAlign)
|
|
|
|
FIXME("Requested Buffer cbAlign mismatch %i,%i\n",This->allocProps.cbAlign, ppropInputRequest->cbAlign);
|
|
|
|
if (ppropInputRequest->cbPrefix)
|
|
|
|
FIXME("Requested Buffer cbPrefix mismatch %i,%i\n",This->allocProps.cbPrefix, ppropInputRequest->cbPrefix);
|
|
|
|
if (ppropInputRequest->cbBuffer)
|
|
|
|
FIXME("Requested Buffer cbBuffer mismatch %i,%i\n",This->allocProps.cbBuffer, ppropInputRequest->cbBuffer);
|
|
|
|
if (ppropInputRequest->cBuffers)
|
|
|
|
FIXME("Requested Buffer cBuffers mismatch %i,%i\n",This->allocProps.cBuffers, ppropInputRequest->cBuffers);
|
|
|
|
|
|
|
|
return IMemAllocator_SetProperties(pAlloc, &This->allocProps, &actual);
|
|
|
|
}
|
|
|
|
|
2010-10-13 18:02:01 +02:00
|
|
|
static const BaseOutputPinFuncTable output_BaseOutputFuncTable = {
|
2014-01-06 17:54:13 +01:00
|
|
|
{
|
2018-05-04 06:47:13 +02:00
|
|
|
FileAsyncReaderPin_CheckMediaType,
|
2014-01-06 17:54:13 +01:00
|
|
|
FileAsyncReaderPin_AttemptConnection,
|
|
|
|
BasePinImpl_GetMediaTypeVersion,
|
|
|
|
FileAsyncReaderPin_GetMediaType
|
|
|
|
},
|
2010-10-13 18:02:14 +02:00
|
|
|
FileAsyncReaderPin_DecideBufferSize,
|
|
|
|
BaseOutputPinImpl_DecideAllocator,
|
|
|
|
BaseOutputPinImpl_BreakConnect
|
2010-10-13 18:02:01 +02:00
|
|
|
};
|
2010-10-13 17:46:27 +02:00
|
|
|
|
2003-08-07 01:00:14 +02:00
|
|
|
static HRESULT FileAsyncReader_Construct(HANDLE hFile, IBaseFilter * pBaseFilter, LPCRITICAL_SECTION pCritSec, IPin ** ppPin)
|
|
|
|
{
|
|
|
|
PIN_INFO piOutput;
|
2008-04-04 23:29:21 +02:00
|
|
|
HRESULT hr;
|
2003-08-07 01:00:14 +02:00
|
|
|
|
|
|
|
*ppPin = NULL;
|
|
|
|
piOutput.dir = PINDIR_OUTPUT;
|
|
|
|
piOutput.pFilter = pBaseFilter;
|
|
|
|
strcpyW(piOutput.achName, wszOutputPinName);
|
2014-01-06 17:54:13 +01:00
|
|
|
hr = BaseOutputPin_Construct(&FileAsyncReaderPin_Vtbl, sizeof(FileAsyncReader), &piOutput, &output_BaseOutputFuncTable, pCritSec, ppPin);
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2008-04-04 23:29:21 +02:00
|
|
|
if (SUCCEEDED(hr))
|
2003-08-07 01:00:14 +02:00
|
|
|
{
|
2008-04-04 23:29:21 +02:00
|
|
|
FileAsyncReader *pPinImpl = (FileAsyncReader *)*ppPin;
|
2012-03-31 03:09:49 +02:00
|
|
|
pPinImpl->IAsyncReader_iface.lpVtbl = &FileAsyncReader_Vtbl;
|
2003-08-07 01:00:14 +02:00
|
|
|
pPinImpl->hFile = hFile;
|
|
|
|
pPinImpl->bFlushing = FALSE;
|
2008-04-23 01:54:28 +02:00
|
|
|
pPinImpl->sample_list = NULL;
|
|
|
|
pPinImpl->handle_list = NULL;
|
|
|
|
pPinImpl->queued_number = 0;
|
2004-08-13 21:49:16 +02:00
|
|
|
InitializeCriticalSection(&pPinImpl->csList);
|
2007-03-10 22:10:20 +01:00
|
|
|
pPinImpl->csList.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": FileAsyncReader.csList");
|
2003-08-07 01:00:14 +02:00
|
|
|
}
|
2008-04-04 23:29:21 +02:00
|
|
|
return hr;
|
2003-08-07 01:00:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* IAsyncReader */
|
|
|
|
|
|
|
|
static HRESULT WINAPI FileAsyncReader_QueryInterface(IAsyncReader * iface, REFIID riid, LPVOID * ppv)
|
|
|
|
{
|
2005-07-27 17:14:18 +02:00
|
|
|
FileAsyncReader *This = impl_from_IAsyncReader(iface);
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2012-03-31 03:09:49 +02:00
|
|
|
return IPin_QueryInterface(&This->pin.pin.IPin_iface, riid, ppv);
|
2003-08-07 01:00:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI FileAsyncReader_AddRef(IAsyncReader * iface)
|
|
|
|
{
|
2005-07-27 17:14:18 +02:00
|
|
|
FileAsyncReader *This = impl_from_IAsyncReader(iface);
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2012-03-31 03:09:49 +02:00
|
|
|
return IPin_AddRef(&This->pin.pin.IPin_iface);
|
2003-08-07 01:00:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI FileAsyncReader_Release(IAsyncReader * iface)
|
|
|
|
{
|
2005-07-27 17:14:18 +02:00
|
|
|
FileAsyncReader *This = impl_from_IAsyncReader(iface);
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2012-03-31 03:09:49 +02:00
|
|
|
return IPin_Release(&This->pin.pin.IPin_iface);
|
2003-08-07 01:00:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#define DEF_ALIGNMENT 1
|
|
|
|
|
|
|
|
static HRESULT WINAPI FileAsyncReader_RequestAllocator(IAsyncReader * iface, IMemAllocator * pPreferred, ALLOCATOR_PROPERTIES * pProps, IMemAllocator ** ppActual)
|
|
|
|
{
|
2008-04-23 01:54:28 +02:00
|
|
|
FileAsyncReader *This = impl_from_IAsyncReader(iface);
|
|
|
|
|
2003-08-07 01:00:14 +02:00
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
2017-11-09 01:12:20 +01:00
|
|
|
TRACE("%p->(%p, %p, %p)\n", This, pPreferred, pProps, ppActual);
|
2003-08-07 01:00:14 +02:00
|
|
|
|
|
|
|
if (!pProps->cbAlign || (pProps->cbAlign % DEF_ALIGNMENT) != 0)
|
|
|
|
pProps->cbAlign = DEF_ALIGNMENT;
|
|
|
|
|
|
|
|
if (pPreferred)
|
|
|
|
{
|
2008-04-23 01:54:28 +02:00
|
|
|
hr = IMemAllocator_SetProperties(pPreferred, pProps, pProps);
|
2003-08-07 01:00:14 +02:00
|
|
|
/* FIXME: check we are still aligned */
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
IMemAllocator_AddRef(pPreferred);
|
|
|
|
*ppActual = pPreferred;
|
2006-10-12 20:57:23 +02:00
|
|
|
TRACE("FileAsyncReader_RequestAllocator -- %x\n", hr);
|
2008-04-23 01:54:28 +02:00
|
|
|
goto done;
|
2003-08-07 01:00:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pPreferred = NULL;
|
|
|
|
|
|
|
|
hr = CoCreateInstance(&CLSID_MemoryAllocator, NULL, CLSCTX_INPROC, &IID_IMemAllocator, (LPVOID *)&pPreferred);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
2008-04-23 01:54:28 +02:00
|
|
|
hr = IMemAllocator_SetProperties(pPreferred, pProps, pProps);
|
2003-08-07 01:00:14 +02:00
|
|
|
/* FIXME: check we are still aligned */
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
*ppActual = pPreferred;
|
2006-10-12 20:57:23 +02:00
|
|
|
TRACE("FileAsyncReader_RequestAllocator -- %x\n", hr);
|
2008-04-23 01:54:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
CoTaskMemFree(This->sample_list);
|
|
|
|
if (This->handle_list)
|
|
|
|
{
|
|
|
|
int x;
|
2008-04-25 23:33:15 +02:00
|
|
|
for (x = 0; x <= This->samples; ++x)
|
2008-04-23 01:54:28 +02:00
|
|
|
CloseHandle(This->handle_list[x]);
|
|
|
|
CoTaskMemFree(This->handle_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
This->samples = pProps->cBuffers;
|
2008-07-10 23:33:53 +02:00
|
|
|
This->oldest_sample = 0;
|
2008-04-23 01:54:28 +02:00
|
|
|
TRACE("Samples: %u\n", This->samples);
|
|
|
|
This->sample_list = CoTaskMemAlloc(sizeof(This->sample_list[0]) * pProps->cBuffers);
|
2008-07-10 23:33:53 +02:00
|
|
|
This->handle_list = CoTaskMemAlloc(sizeof(HANDLE) * pProps->cBuffers * 2);
|
2008-04-23 01:54:28 +02:00
|
|
|
|
|
|
|
if (This->sample_list && This->handle_list)
|
|
|
|
{
|
|
|
|
int x;
|
|
|
|
ZeroMemory(This->sample_list, sizeof(This->sample_list[0]) * pProps->cBuffers);
|
|
|
|
for (x = 0; x < This->samples; ++x)
|
|
|
|
{
|
|
|
|
This->sample_list[x].ovl.hEvent = This->handle_list[x] = CreateEventW(NULL, 0, 0, NULL);
|
2008-07-10 23:33:53 +02:00
|
|
|
if (x + 1 < This->samples)
|
|
|
|
This->handle_list[This->samples + 1 + x] = This->handle_list[x];
|
2008-04-23 01:54:28 +02:00
|
|
|
}
|
2008-04-25 23:33:15 +02:00
|
|
|
This->handle_list[This->samples] = CreateEventW(NULL, 1, 0, NULL);
|
2010-10-13 17:46:27 +02:00
|
|
|
This->allocProps = *pProps;
|
2008-04-23 01:54:28 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hr = E_OUTOFMEMORY;
|
|
|
|
CoTaskMemFree(This->sample_list);
|
|
|
|
CoTaskMemFree(This->handle_list);
|
|
|
|
This->samples = 0;
|
|
|
|
This->sample_list = NULL;
|
|
|
|
This->handle_list = NULL;
|
2003-08-07 01:00:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
*ppActual = NULL;
|
|
|
|
if (pPreferred)
|
|
|
|
IMemAllocator_Release(pPreferred);
|
|
|
|
}
|
|
|
|
|
2006-10-12 20:57:23 +02:00
|
|
|
TRACE("-- %x\n", hr);
|
2003-08-07 01:00:14 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we could improve the Request/WaitForNext mechanism by allowing out of order samples.
|
|
|
|
* however, this would be quite complicated to do and may be a bit error prone */
|
|
|
|
static HRESULT WINAPI FileAsyncReader_Request(IAsyncReader * iface, IMediaSample * pSample, DWORD_PTR dwUser)
|
|
|
|
{
|
2008-04-23 01:54:28 +02:00
|
|
|
HRESULT hr = S_OK;
|
2003-08-07 01:00:14 +02:00
|
|
|
REFERENCE_TIME Start;
|
|
|
|
REFERENCE_TIME Stop;
|
2005-07-27 17:14:18 +02:00
|
|
|
FileAsyncReader *This = impl_from_IAsyncReader(iface);
|
2008-04-23 01:54:28 +02:00
|
|
|
LPBYTE pBuffer = NULL;
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2017-11-09 01:12:20 +01:00
|
|
|
TRACE("%p->(%p, %lx)\n", This, pSample, dwUser);
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2008-04-23 01:54:28 +02:00
|
|
|
if (!pSample)
|
|
|
|
return E_POINTER;
|
2003-08-07 01:00:14 +02:00
|
|
|
|
|
|
|
/* get start and stop positions in bytes */
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
hr = IMediaSample_GetTime(pSample, &Start, &Stop);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
hr = IMediaSample_GetPointer(pSample, &pBuffer);
|
|
|
|
|
2008-04-23 01:54:28 +02:00
|
|
|
EnterCriticalSection(&This->csList);
|
|
|
|
if (This->bFlushing)
|
|
|
|
{
|
|
|
|
LeaveCriticalSection(&This->csList);
|
|
|
|
return VFW_E_WRONG_STATE;
|
|
|
|
}
|
|
|
|
|
2003-08-07 01:00:14 +02:00
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
DWORD dwLength = (DWORD) BYTES_FROM_MEDIATIME(Stop - Start);
|
2008-04-23 01:54:28 +02:00
|
|
|
DATAREQUEST *pDataRq;
|
|
|
|
int x;
|
|
|
|
|
2008-04-25 23:33:15 +02:00
|
|
|
/* Try to insert above the waiting sample if possible */
|
2008-07-10 23:33:53 +02:00
|
|
|
for (x = This->oldest_sample; x < This->samples; ++x)
|
2008-04-23 01:54:28 +02:00
|
|
|
{
|
|
|
|
if (!This->sample_list[x].pSample)
|
|
|
|
break;
|
|
|
|
}
|
2008-04-25 23:33:15 +02:00
|
|
|
|
|
|
|
if (x >= This->samples)
|
2008-07-10 23:33:53 +02:00
|
|
|
for (x = 0; x < This->oldest_sample; ++x)
|
2008-04-25 23:33:15 +02:00
|
|
|
{
|
|
|
|
if (!This->sample_list[x].pSample)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-07-10 23:33:53 +02:00
|
|
|
/* There must be a sample we have found */
|
2008-04-23 01:54:28 +02:00
|
|
|
assert(x < This->samples);
|
2008-07-10 23:33:53 +02:00
|
|
|
++This->queued_number;
|
2008-04-23 01:54:28 +02:00
|
|
|
|
|
|
|
pDataRq = This->sample_list + x;
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2005-03-17 20:00:08 +01:00
|
|
|
pDataRq->ovl.u.s.Offset = (DWORD) BYTES_FROM_MEDIATIME(Start);
|
|
|
|
pDataRq->ovl.u.s.OffsetHigh = (DWORD)(BYTES_FROM_MEDIATIME(Start) >> (sizeof(DWORD) * 8));
|
2003-08-07 01:00:14 +02:00
|
|
|
pDataRq->dwUserData = dwUser;
|
2008-04-23 01:54:28 +02:00
|
|
|
|
2003-08-07 01:00:14 +02:00
|
|
|
/* we violate traditional COM rules here by maintaining
|
|
|
|
* a reference to the sample, but not calling AddRef, but
|
|
|
|
* that's what MSDN says to do */
|
|
|
|
pDataRq->pSample = pSample;
|
|
|
|
|
|
|
|
/* this is definitely not how it is implemented on Win9x
|
|
|
|
* as they do not support async reads on files, but it is
|
|
|
|
* sooo much easier to use this than messing around with threads!
|
|
|
|
*/
|
|
|
|
if (!ReadFile(This->hFile, pBuffer, dwLength, NULL, &pDataRq->ovl))
|
|
|
|
hr = HRESULT_FROM_WIN32(GetLastError());
|
|
|
|
|
|
|
|
/* ERROR_IO_PENDING is not actually an error since this is what we want! */
|
|
|
|
if (hr == HRESULT_FROM_WIN32(ERROR_IO_PENDING))
|
|
|
|
hr = S_OK;
|
|
|
|
}
|
|
|
|
|
2008-04-23 01:54:28 +02:00
|
|
|
LeaveCriticalSection(&This->csList);
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2006-10-12 20:57:23 +02:00
|
|
|
TRACE("-- %x\n", hr);
|
2003-08-07 01:00:14 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI FileAsyncReader_WaitForNext(IAsyncReader * iface, DWORD dwTimeout, IMediaSample ** ppSample, DWORD_PTR * pdwUser)
|
|
|
|
{
|
|
|
|
HRESULT hr = S_OK;
|
2005-07-27 17:14:18 +02:00
|
|
|
FileAsyncReader *This = impl_from_IAsyncReader(iface);
|
2008-04-23 01:54:28 +02:00
|
|
|
DWORD buffer = ~0;
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2017-11-09 01:12:20 +01:00
|
|
|
TRACE("%p->(%u, %p, %p)\n", This, dwTimeout, ppSample, pdwUser);
|
2003-08-07 01:00:14 +02:00
|
|
|
|
|
|
|
*ppSample = NULL;
|
|
|
|
*pdwUser = 0;
|
|
|
|
|
2008-07-10 23:33:53 +02:00
|
|
|
EnterCriticalSection(&This->csList);
|
2008-04-04 23:30:21 +02:00
|
|
|
if (!This->bFlushing)
|
2003-08-07 01:00:14 +02:00
|
|
|
{
|
2008-07-10 23:33:53 +02:00
|
|
|
LONG oldest = This->oldest_sample;
|
|
|
|
|
2008-04-23 01:54:28 +02:00
|
|
|
if (!This->queued_number)
|
|
|
|
{
|
2008-04-25 23:33:15 +02:00
|
|
|
/* It could be that nothing is queued right now, but that can be fixed */
|
|
|
|
WARN("Called without samples in queue and not flushing!!\n");
|
2008-04-23 01:54:28 +02:00
|
|
|
}
|
2008-07-10 23:33:53 +02:00
|
|
|
LeaveCriticalSection(&This->csList);
|
2008-04-23 01:54:28 +02:00
|
|
|
|
|
|
|
/* wait for an object to read, or time out */
|
2008-07-10 23:33:53 +02:00
|
|
|
buffer = WaitForMultipleObjectsEx(This->samples+1, This->handle_list + oldest, FALSE, dwTimeout, TRUE);
|
|
|
|
|
|
|
|
EnterCriticalSection(&This->csList);
|
|
|
|
if (buffer <= This->samples)
|
|
|
|
{
|
|
|
|
/* Re-scale the buffer back to normal */
|
|
|
|
buffer += oldest;
|
|
|
|
|
|
|
|
/* Uh oh, we overshot the flusher handle, renormalize it back to 0..Samples-1 */
|
|
|
|
if (buffer > This->samples)
|
|
|
|
buffer -= This->samples + 1;
|
|
|
|
assert(buffer <= This->samples);
|
|
|
|
}
|
2008-04-22 22:44:33 +02:00
|
|
|
|
2008-04-25 23:33:15 +02:00
|
|
|
if (buffer >= This->samples)
|
2008-04-23 01:54:28 +02:00
|
|
|
{
|
2008-04-30 23:27:51 +02:00
|
|
|
if (buffer != This->samples)
|
2008-09-18 17:55:36 +02:00
|
|
|
{
|
2008-04-30 23:27:51 +02:00
|
|
|
FIXME("Returned: %u (%08x)\n", buffer, GetLastError());
|
2008-09-18 17:55:36 +02:00
|
|
|
hr = VFW_E_TIMEOUT;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
hr = VFW_E_WRONG_STATE;
|
2008-04-23 01:54:28 +02:00
|
|
|
buffer = ~0;
|
|
|
|
}
|
2008-07-10 23:33:53 +02:00
|
|
|
else
|
|
|
|
--This->queued_number;
|
2003-08-07 01:00:14 +02:00
|
|
|
}
|
2008-04-04 23:30:21 +02:00
|
|
|
|
2008-04-23 01:54:28 +02:00
|
|
|
if (This->bFlushing && buffer == ~0)
|
2003-08-07 01:00:14 +02:00
|
|
|
{
|
2008-04-23 01:54:28 +02:00
|
|
|
for (buffer = 0; buffer < This->samples; ++buffer)
|
2003-08-07 01:00:14 +02:00
|
|
|
{
|
2008-04-23 01:54:28 +02:00
|
|
|
if (This->sample_list[buffer].pSample)
|
2008-04-25 23:33:15 +02:00
|
|
|
{
|
|
|
|
ResetEvent(This->handle_list[buffer]);
|
2008-04-23 01:54:28 +02:00
|
|
|
break;
|
2008-04-25 23:33:15 +02:00
|
|
|
}
|
2008-04-23 01:54:28 +02:00
|
|
|
}
|
|
|
|
if (buffer == This->samples)
|
|
|
|
{
|
|
|
|
assert(!This->queued_number);
|
2008-04-30 23:27:51 +02:00
|
|
|
hr = VFW_E_TIMEOUT;
|
2008-04-23 01:54:28 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-07-10 23:33:53 +02:00
|
|
|
--This->queued_number;
|
2008-04-23 01:54:28 +02:00
|
|
|
hr = S_OK;
|
2003-08-07 01:00:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-17 22:11:05 +02:00
|
|
|
if (SUCCEEDED(hr))
|
2003-08-07 01:00:14 +02:00
|
|
|
{
|
2008-04-19 01:07:40 +02:00
|
|
|
REFERENCE_TIME rtStart, rtStop;
|
|
|
|
REFERENCE_TIME rtSampleStart, rtSampleStop;
|
2008-04-23 01:54:28 +02:00
|
|
|
DATAREQUEST *pDataRq = This->sample_list + buffer;
|
|
|
|
DWORD dwBytes = 0;
|
2008-04-19 01:07:40 +02:00
|
|
|
|
2003-08-07 01:00:14 +02:00
|
|
|
/* get any errors */
|
2008-04-17 22:11:05 +02:00
|
|
|
if (!This->bFlushing && !GetOverlappedResult(This->hFile, &pDataRq->ovl, &dwBytes, FALSE))
|
2003-08-07 01:00:14 +02:00
|
|
|
hr = HRESULT_FROM_WIN32(GetLastError());
|
|
|
|
|
2008-04-17 22:11:05 +02:00
|
|
|
/* Return the sample no matter what so it can be destroyed */
|
2003-08-07 01:00:14 +02:00
|
|
|
*ppSample = pDataRq->pSample;
|
|
|
|
*pdwUser = pDataRq->dwUserData;
|
2008-04-17 22:11:05 +02:00
|
|
|
|
|
|
|
if (This->bFlushing)
|
|
|
|
hr = VFW_E_WRONG_STATE;
|
2008-04-22 22:44:33 +02:00
|
|
|
|
|
|
|
if (FAILED(hr))
|
2008-04-17 22:11:05 +02:00
|
|
|
dwBytes = 0;
|
|
|
|
|
2008-04-19 01:07:40 +02:00
|
|
|
/* Set the time on the sample */
|
2008-04-17 22:11:05 +02:00
|
|
|
IMediaSample_SetActualDataLength(pDataRq->pSample, dwBytes);
|
2008-04-19 01:07:40 +02:00
|
|
|
|
|
|
|
rtStart = (DWORD64)pDataRq->ovl.u.s.Offset + ((DWORD64)pDataRq->ovl.u.s.OffsetHigh << 32);
|
|
|
|
rtStart = MEDIATIME_FROM_BYTES(rtStart);
|
|
|
|
rtStop = rtStart + MEDIATIME_FROM_BYTES(dwBytes);
|
|
|
|
|
|
|
|
IMediaSample_GetTime(pDataRq->pSample, &rtSampleStart, &rtSampleStop);
|
|
|
|
assert(rtStart == rtSampleStart);
|
|
|
|
assert(rtStop <= rtSampleStop);
|
|
|
|
|
|
|
|
IMediaSample_SetTime(pDataRq->pSample, &rtStart, &rtStop);
|
2008-04-22 22:44:33 +02:00
|
|
|
assert(rtStart == rtSampleStart);
|
|
|
|
if (hr == S_OK)
|
|
|
|
assert(rtStop == rtSampleStop);
|
|
|
|
else
|
|
|
|
assert(rtStop == rtStart);
|
|
|
|
|
2008-04-23 01:54:28 +02:00
|
|
|
This->sample_list[buffer].pSample = NULL;
|
2008-07-10 23:33:53 +02:00
|
|
|
assert(This->oldest_sample < This->samples);
|
|
|
|
|
|
|
|
if (buffer == This->oldest_sample)
|
|
|
|
{
|
|
|
|
LONG x;
|
|
|
|
for (x = This->oldest_sample + 1; x < This->samples; ++x)
|
|
|
|
if (This->sample_list[x].pSample)
|
|
|
|
break;
|
|
|
|
if (x >= This->samples)
|
|
|
|
for (x = 0; x < This->oldest_sample; ++x)
|
|
|
|
if (This->sample_list[x].pSample)
|
|
|
|
break;
|
|
|
|
if (This->oldest_sample == x)
|
|
|
|
/* No samples found, reset to 0 */
|
|
|
|
x = 0;
|
|
|
|
This->oldest_sample = x;
|
|
|
|
}
|
2003-08-07 01:00:14 +02:00
|
|
|
}
|
2008-04-23 01:54:28 +02:00
|
|
|
LeaveCriticalSection(&This->csList);
|
2008-04-04 23:30:21 +02:00
|
|
|
|
2006-10-12 20:57:23 +02:00
|
|
|
TRACE("-- %x\n", hr);
|
2003-08-07 01:00:14 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI FileAsyncReader_SyncRead(IAsyncReader * iface, LONGLONG llPosition, LONG lLength, BYTE * pBuffer);
|
|
|
|
|
|
|
|
static HRESULT WINAPI FileAsyncReader_SyncReadAligned(IAsyncReader * iface, IMediaSample * pSample)
|
|
|
|
{
|
|
|
|
BYTE * pBuffer;
|
|
|
|
REFERENCE_TIME tStart;
|
|
|
|
REFERENCE_TIME tStop;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("(%p)\n", pSample);
|
|
|
|
|
|
|
|
hr = IMediaSample_GetTime(pSample, &tStart, &tStop);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
hr = IMediaSample_GetPointer(pSample, &pBuffer);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
hr = FileAsyncReader_SyncRead(iface,
|
|
|
|
BYTES_FROM_MEDIATIME(tStart),
|
|
|
|
(LONG) BYTES_FROM_MEDIATIME(tStop - tStart),
|
|
|
|
pBuffer);
|
|
|
|
|
2006-10-12 20:57:23 +02:00
|
|
|
TRACE("-- %x\n", hr);
|
2003-08-07 01:00:14 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI FileAsyncReader_SyncRead(IAsyncReader * iface, LONGLONG llPosition, LONG lLength, BYTE * pBuffer)
|
|
|
|
{
|
|
|
|
OVERLAPPED ovl;
|
|
|
|
HRESULT hr = S_OK;
|
2005-07-27 17:14:18 +02:00
|
|
|
FileAsyncReader *This = impl_from_IAsyncReader(iface);
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2017-11-09 01:12:20 +01:00
|
|
|
TRACE("%p->(%s, %d, %p)\n", This, wine_dbgstr_longlong(llPosition), lLength, pBuffer);
|
2003-08-07 01:00:14 +02:00
|
|
|
|
|
|
|
ZeroMemory(&ovl, sizeof(ovl));
|
|
|
|
|
|
|
|
ovl.hEvent = CreateEventW(NULL, 0, 0, NULL);
|
|
|
|
/* NOTE: llPosition is the actual byte position to start reading from */
|
2005-03-17 20:00:08 +01:00
|
|
|
ovl.u.s.Offset = (DWORD) llPosition;
|
|
|
|
ovl.u.s.OffsetHigh = (DWORD) (llPosition >> (sizeof(DWORD) * 8));
|
2003-08-07 01:00:14 +02:00
|
|
|
|
|
|
|
if (!ReadFile(This->hFile, pBuffer, lLength, NULL, &ovl))
|
|
|
|
hr = HRESULT_FROM_WIN32(GetLastError());
|
|
|
|
|
|
|
|
if (hr == HRESULT_FROM_WIN32(ERROR_IO_PENDING))
|
|
|
|
hr = S_OK;
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
DWORD dwBytesRead;
|
|
|
|
|
|
|
|
if (!GetOverlappedResult(This->hFile, &ovl, &dwBytesRead, TRUE))
|
|
|
|
hr = HRESULT_FROM_WIN32(GetLastError());
|
|
|
|
}
|
|
|
|
|
|
|
|
CloseHandle(ovl.hEvent);
|
|
|
|
|
2006-10-12 20:57:23 +02:00
|
|
|
TRACE("-- %x\n", hr);
|
2003-08-07 01:00:14 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI FileAsyncReader_Length(IAsyncReader * iface, LONGLONG * pTotal, LONGLONG * pAvailable)
|
|
|
|
{
|
|
|
|
DWORD dwSizeLow;
|
|
|
|
DWORD dwSizeHigh;
|
2005-07-27 17:14:18 +02:00
|
|
|
FileAsyncReader *This = impl_from_IAsyncReader(iface);
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2017-11-09 01:12:20 +01:00
|
|
|
TRACE("%p->(%p, %p)\n", This, pTotal, pAvailable);
|
2003-08-07 01:00:14 +02:00
|
|
|
|
|
|
|
if (((dwSizeLow = GetFileSize(This->hFile, &dwSizeHigh)) == -1) &&
|
|
|
|
(GetLastError() != NO_ERROR))
|
|
|
|
return HRESULT_FROM_WIN32(GetLastError());
|
|
|
|
|
|
|
|
*pTotal = (LONGLONG)dwSizeLow | (LONGLONG)dwSizeHigh << (sizeof(DWORD) * 8);
|
|
|
|
|
|
|
|
*pAvailable = *pTotal;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI FileAsyncReader_BeginFlush(IAsyncReader * iface)
|
|
|
|
{
|
2005-07-27 17:14:18 +02:00
|
|
|
FileAsyncReader *This = impl_from_IAsyncReader(iface);
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2017-11-09 01:12:20 +01:00
|
|
|
TRACE("%p->()\n", This);
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2008-04-23 01:54:28 +02:00
|
|
|
EnterCriticalSection(&This->csList);
|
2003-08-07 01:00:14 +02:00
|
|
|
This->bFlushing = TRUE;
|
|
|
|
CancelIo(This->hFile);
|
2008-04-25 23:33:15 +02:00
|
|
|
SetEvent(This->handle_list[This->samples]);
|
2008-04-23 01:54:28 +02:00
|
|
|
LeaveCriticalSection(&This->csList);
|
2003-08-07 01:00:14 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI FileAsyncReader_EndFlush(IAsyncReader * iface)
|
|
|
|
{
|
2005-07-27 17:14:18 +02:00
|
|
|
FileAsyncReader *This = impl_from_IAsyncReader(iface);
|
2008-04-30 23:27:51 +02:00
|
|
|
int x;
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2017-11-09 01:12:20 +01:00
|
|
|
TRACE("%p->()\n", This);
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2008-04-23 01:54:28 +02:00
|
|
|
EnterCriticalSection(&This->csList);
|
2008-04-25 23:33:15 +02:00
|
|
|
ResetEvent(This->handle_list[This->samples]);
|
2003-08-07 01:00:14 +02:00
|
|
|
This->bFlushing = FALSE;
|
2008-04-30 23:27:51 +02:00
|
|
|
for (x = 0; x < This->samples; ++x)
|
|
|
|
assert(!This->sample_list[x].pSample);
|
|
|
|
|
2008-04-23 01:54:28 +02:00
|
|
|
LeaveCriticalSection(&This->csList);
|
2003-08-07 01:00:14 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IAsyncReaderVtbl FileAsyncReader_Vtbl =
|
|
|
|
{
|
|
|
|
FileAsyncReader_QueryInterface,
|
|
|
|
FileAsyncReader_AddRef,
|
|
|
|
FileAsyncReader_Release,
|
|
|
|
FileAsyncReader_RequestAllocator,
|
|
|
|
FileAsyncReader_Request,
|
|
|
|
FileAsyncReader_WaitForNext,
|
|
|
|
FileAsyncReader_SyncReadAligned,
|
|
|
|
FileAsyncReader_SyncRead,
|
|
|
|
FileAsyncReader_Length,
|
|
|
|
FileAsyncReader_BeginFlush,
|
|
|
|
FileAsyncReader_EndFlush,
|
|
|
|
};
|