quartz: Use file APIs directly in get_media_type().

Signed-off-by: Zebediah Figura <z.figura12@gmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Zebediah Figura 2019-08-06 14:58:35 -05:00 committed by Alexandre Julliard
parent 4555da1d7f
commit 26ac991c69
3 changed files with 24 additions and 71 deletions

View File

@ -129,10 +129,10 @@ static unsigned char byte_from_hex_char(WCHAR wHex)
}
}
static BOOL process_pattern_string(const WCHAR *pattern, IAsyncReader *reader)
static BOOL process_pattern_string(const WCHAR *pattern, HANDLE file)
{
ULONG size, offset, i, ret_size;
BYTE *mask, *expect, *actual;
ULONG size, offset, i;
BOOL ret = TRUE;
/* format: "offset, size, mask, value" */
@ -181,7 +181,8 @@ static BOOL process_pattern_string(const WCHAR *pattern, IAsyncReader *reader)
}
actual = heap_alloc(size);
if (FAILED(IAsyncReader_SyncRead(reader, offset, size, actual)))
SetFilePointer(file, offset, NULL, FILE_BEGIN);
if (!ReadFile(file, actual, size, &ret_size, NULL) || ret_size != size)
{
heap_free(actual);
heap_free(expect);
@ -204,13 +205,12 @@ static BOOL process_pattern_string(const WCHAR *pattern, IAsyncReader *reader)
/* If there is a following tuple, then we must match that as well. */
if (ret && (pattern = wcschr(pattern, ',')))
return process_pattern_string(pattern + 1, reader);
return process_pattern_string(pattern + 1, file);
return ret;
}
BOOL get_media_type(IAsyncReader *reader, const WCHAR *filename, GUID *majortype,
GUID *subtype, GUID *source_clsid)
BOOL get_media_type(const WCHAR *filename, GUID *majortype, GUID *subtype, GUID *source_clsid)
{
WCHAR extensions_path[278] = {'M','e','d','i','a',' ','T','y','p','e','\\','E','x','t','e','n','s','i','o','n','s','\\',0};
static const WCHAR wszExtensions[] = {'E','x','t','e','n','s','i','o','n','s',0};
@ -218,6 +218,7 @@ BOOL get_media_type(IAsyncReader *reader, const WCHAR *filename, GUID *majortype
DWORD majortype_idx, size;
const WCHAR *ext;
HKEY parent_key;
HANDLE file;
if ((ext = wcsrchr(filename, '.')))
{
@ -244,11 +245,18 @@ BOOL get_media_type(IAsyncReader *reader, const WCHAR *filename, GUID *majortype
}
}
if (!reader)
if ((file = CreateFileW(filename, GENERIC_READ, FILE_SHARE_READ, NULL,
OPEN_EXISTING, 0, NULL)) == INVALID_HANDLE_VALUE)
{
WARN("Failed to open file %s, error %u.\n", debugstr_w(filename), GetLastError());
return FALSE;
}
if (RegOpenKeyExW(HKEY_CLASSES_ROOT, wszMediaType, 0, KEY_READ, &parent_key))
{
CloseHandle(file);
return FALSE;
}
for (majortype_idx = 0; ; ++majortype_idx)
{
@ -298,7 +306,7 @@ BOOL get_media_type(IAsyncReader *reader, const WCHAR *filename, GUID *majortype
if (!wcscmp(value_name, source_filter_name))
continue;
if (!process_pattern_string(pattern, reader))
if (!process_pattern_string(pattern, file))
continue;
if (majortype)
@ -314,6 +322,7 @@ BOOL get_media_type(IAsyncReader *reader, const WCHAR *filename, GUID *majortype
RegCloseKey(subtype_key);
RegCloseKey(majortype_key);
RegCloseKey(parent_key);
CloseHandle(file);
return TRUE;
}
@ -325,6 +334,7 @@ BOOL get_media_type(IAsyncReader *reader, const WCHAR *filename, GUID *majortype
}
RegCloseKey(parent_key);
CloseHandle(file);
return FALSE;
}
@ -503,7 +513,7 @@ static HRESULT WINAPI FileSource_Load(IFileSourceFilter * iface, LPCOLESTR pszFi
if (!pmt)
{
CopyMediaType(This->pmt, &default_mt);
if (get_media_type(&This->IAsyncReader_iface, pszFileName, &This->pmt->majortype, &This->pmt->subtype, NULL))
if (get_media_type(pszFileName, &This->pmt->majortype, &This->pmt->subtype, NULL))
{
TRACE("Found major type %s, subtype %s.\n",
debugstr_guid(&This->pmt->majortype), debugstr_guid(&This->pmt->subtype));

View File

@ -1683,69 +1683,12 @@ static HRESULT CreateFilterInstanceAndLoadFile(GUID* clsid, LPCOLESTR pszFileNam
}
/* Some filters implement their own asynchronous reader (Theoretically they all should, try to load it first */
static HRESULT GetFileSourceFilter(LPCOLESTR pszFileName, IBaseFilter **filter)
static HRESULT GetFileSourceFilter(const WCHAR *filename, IBaseFilter **filter)
{
HRESULT hr;
GUID clsid;
IAsyncReader * pReader = NULL;
IFileSourceFilter* pSource = NULL;
IPin * pOutputPin = NULL;
static const WCHAR wszOutputPinName[] = { 'O','u','t','p','u','t',0 };
BOOL ret;
/* Try to find a match without reading the file first */
if (get_media_type(NULL, pszFileName, NULL, NULL, &clsid))
return CreateFilterInstanceAndLoadFile(&clsid, pszFileName, filter);
/* Now create a AyncReader instance, to check for signature bytes in the file */
hr = CoCreateInstance(&CLSID_AsyncReader, NULL, CLSCTX_INPROC_SERVER, &IID_IBaseFilter, (LPVOID*)filter);
if (FAILED(hr))
return hr;
hr = IBaseFilter_QueryInterface(*filter, &IID_IFileSourceFilter, (LPVOID *)&pSource);
if (FAILED(hr))
{
IBaseFilter_Release(*filter);
return hr;
}
hr = IFileSourceFilter_Load(pSource, pszFileName, NULL);
IFileSourceFilter_Release(pSource);
if (FAILED(hr))
{
IBaseFilter_Release(*filter);
return hr;
}
hr = IBaseFilter_FindPin(*filter, wszOutputPinName, &pOutputPin);
if (FAILED(hr))
{
IBaseFilter_Release(*filter);
return hr;
}
hr = IPin_QueryInterface(pOutputPin, &IID_IAsyncReader, (LPVOID *)&pReader);
IPin_Release(pOutputPin);
if (FAILED(hr))
{
IBaseFilter_Release(*filter);
return hr;
}
/* Try again find a match */
ret = get_media_type(pReader, pszFileName, NULL, NULL, &clsid);
IAsyncReader_Release(pReader);
if (ret)
{
TRACE("Found source filter %s.\n", debugstr_guid(&clsid));
/* Release the AsyncReader filter and create the matching one */
IBaseFilter_Release(*filter);
return CreateFilterInstanceAndLoadFile(&clsid, pszFileName, filter);
}
/* Return the AsyncReader filter */
return S_OK;
if (!get_media_type(filename, NULL, NULL, &clsid))
clsid = CLSID_AsyncReader;
return CreateFilterInstanceAndLoadFile(&clsid, filename, filter);
}
static HRESULT WINAPI FilterGraph2_AddSourceFilter(IFilterGraph2 *iface, LPCWSTR lpcwstrFileName,

View File

@ -77,6 +77,6 @@ extern void video_unregister_windowclass(void) DECLSPEC_HIDDEN;
BOOL CompareMediaTypes(const AM_MEDIA_TYPE * pmt1, const AM_MEDIA_TYPE * pmt2, BOOL bWildcards);
void dump_AM_MEDIA_TYPE(const AM_MEDIA_TYPE * pmt) DECLSPEC_HIDDEN;
BOOL get_media_type(IAsyncReader *reader, const WCHAR *filename, GUID *majortype, GUID *subtype, GUID *source_clsid) DECLSPEC_HIDDEN;
BOOL get_media_type(const WCHAR *filename, GUID *majortype, GUID *subtype, GUID *source_clsid) DECLSPEC_HIDDEN;
#endif /* __QUARTZ_PRIVATE_INCLUDED__ */