quartz: Try creating the file reader from the filter source first before falling back to the generic async file reader.

This commit is contained in:
Maarten Lankhorst 2008-04-07 22:28:15 -07:00 committed by Alexandre Julliard
parent 4bc4457109
commit 0117468754

View file

@ -29,6 +29,8 @@
#include "windef.h"
#include "winbase.h"
#include "winuser.h"
#include "winreg.h"
#include "shlwapi.h"
#include "dshow.h"
#include "wine/debug.h"
#include "quartz_private.h"
@ -1199,6 +1201,63 @@ static HRESULT WINAPI FilterGraph2_RenderFile(IFilterGraph2 *iface,
return hr;
}
/* Some filters implement their own asynchronous reader (Theoretically they all should, try to load it first */
static HRESULT GetFileSourceFilter(LPCOLESTR pszFileName, IBaseFilter **filter)
{
static const WCHAR wszReg[] = {'M','e','d','i','a',' ','T','y','p','e','\\','E','x','t','e','n','s','i','o','n','s',0};
HRESULT hr = S_OK;
HKEY extkey;
LONG lRet;
lRet = RegOpenKeyExW(HKEY_CLASSES_ROOT, wszReg, 0, KEY_READ, &extkey);
hr = HRESULT_FROM_WIN32(lRet);
if (SUCCEEDED(hr))
{
static const WCHAR filtersource[] = {'S','o','u','r','c','e',' ','F','i','l','t','e','r',0};
WCHAR *ext = PathFindExtensionW(pszFileName);
WCHAR clsid_key[39];
GUID clsid;
DWORD size = sizeof(clsid_key);
HKEY pathkey;
if (!ext)
{
CloseHandle(extkey);
return E_FAIL;
}
lRet = RegOpenKeyExW(extkey, ext, 0, KEY_READ, &pathkey);
hr = HRESULT_FROM_WIN32(lRet);
CloseHandle(extkey);
if (FAILED(hr))
return hr;
lRet = RegQueryValueExW(pathkey, filtersource, NULL, NULL, (LPBYTE)clsid_key, &size);
hr = HRESULT_FROM_WIN32(lRet);
CloseHandle(pathkey);
if (FAILED(hr))
return hr;
CLSIDFromString(clsid_key, &clsid);
TRACE("CLSID: %s\n", debugstr_guid(&clsid));
hr = CoCreateInstance(&clsid, NULL, CLSCTX_INPROC_SERVER, &IID_IBaseFilter, (LPVOID*)filter);
if (SUCCEEDED(hr))
{
IFileSourceFilter *source = NULL;
hr = IBaseFilter_QueryInterface(*filter, &IID_IFileSourceFilter, (LPVOID*)&source);
if (SUCCEEDED(hr))
IFileSourceFilter_Release(source);
else
IBaseFilter_Release(*filter);
}
}
if (FAILED(hr))
*filter = NULL;
return hr;
}
static HRESULT WINAPI FilterGraph2_AddSourceFilter(IFilterGraph2 *iface,
LPCWSTR lpcwstrFileName,
LPCWSTR lpcwstrFilterName,
@ -1212,8 +1271,11 @@ static HRESULT WINAPI FilterGraph2_AddSourceFilter(IFilterGraph2 *iface,
TRACE("(%p/%p)->(%s, %s, %p)\n", This, iface, debugstr_w(lpcwstrFileName), debugstr_w(lpcwstrFilterName), ppFilter);
/* Instantiate a file source filter */
hr = CoCreateInstance(&CLSID_AsyncReader, NULL, CLSCTX_INPROC_SERVER, &IID_IBaseFilter, (LPVOID*)&preader);
/* Try from file name first, then fall back to default asynchronous reader */
hr = GetFileSourceFilter(lpcwstrFileName, &preader);
if (FAILED(hr))
hr = CoCreateInstance(&CLSID_AsyncReader, NULL, CLSCTX_INPROC_SERVER, &IID_IBaseFilter, (LPVOID*)&preader);
if (FAILED(hr)) {
ERR("Unable to create file source filter (%x)\n", hr);
return hr;
@ -1238,12 +1300,13 @@ static HRESULT WINAPI FilterGraph2_AddSourceFilter(IFilterGraph2 *iface,
ERR("Load (%x)\n", hr);
goto error;
}
IFileSourceFilter_GetCurFile(pfile, &filename, &mt);
if (FAILED(hr)) {
ERR("GetCurFile (%x)\n", hr);
goto error;
}
TRACE("File %s\n", debugstr_w(filename));
TRACE("MajorType %s\n", debugstr_guid(&mt.majortype));
TRACE("SubType %s\n", debugstr_guid(&mt.subtype));