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 "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);
|
|
|
|
|
2019-02-22 01:42:58 +01:00
|
|
|
static const AM_MEDIA_TYPE default_mt =
|
|
|
|
{
|
|
|
|
{0xe436eb83,0x524f,0x11ce,{0x9f,0x53,0x00,0x20,0xaf,0x0b,0xa7,0x70}}, /* MEDIATYPE_Stream */
|
|
|
|
{0,0,0,{0,0,0,0,0,0,0,0}},
|
|
|
|
TRUE,
|
|
|
|
FALSE,
|
|
|
|
1,
|
|
|
|
{0,0,0,{0,0,0,0,0,0,0,0}},
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2020-01-30 02:56:59 +01:00
|
|
|
struct request
|
2019-06-17 02:35:00 +02:00
|
|
|
{
|
2020-01-30 02:56:59 +01:00
|
|
|
IMediaSample *sample;
|
|
|
|
DWORD_PTR cookie;
|
2019-06-17 02:35:00 +02:00
|
|
|
OVERLAPPED ovl;
|
2020-01-30 02:56:59 +01:00
|
|
|
};
|
2019-06-17 02:35:00 +02:00
|
|
|
|
2020-04-02 06:01:00 +02:00
|
|
|
struct async_reader
|
2019-06-17 02:35:00 +02:00
|
|
|
{
|
2019-08-29 03:24:30 +02:00
|
|
|
struct strmbase_filter filter;
|
2019-06-20 03:16:12 +02:00
|
|
|
IFileSourceFilter IFileSourceFilter_iface;
|
|
|
|
|
2019-09-12 21:28:25 +02:00
|
|
|
struct strmbase_source source;
|
2019-06-17 02:35:00 +02:00
|
|
|
IAsyncReader IAsyncReader_iface;
|
|
|
|
|
2019-06-20 03:16:12 +02:00
|
|
|
LPOLESTR pszFileName;
|
2020-01-30 02:57:01 +01:00
|
|
|
AM_MEDIA_TYPE mt;
|
2020-01-30 02:56:59 +01:00
|
|
|
HANDLE file, port, io_thread;
|
2020-04-20 02:53:20 +02:00
|
|
|
LARGE_INTEGER file_size;
|
2019-06-20 03:16:12 +02:00
|
|
|
CRITICAL_SECTION sample_cs;
|
2020-01-30 02:56:59 +01:00
|
|
|
BOOL flushing;
|
|
|
|
struct request *requests;
|
|
|
|
unsigned int max_requests;
|
|
|
|
CONDITION_VARIABLE sample_cv;
|
2020-04-02 06:01:00 +02:00
|
|
|
};
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2019-09-12 21:28:26 +02:00
|
|
|
static const struct strmbase_source_ops source_ops;
|
2019-06-20 03:16:12 +02:00
|
|
|
|
2020-04-02 06:01:00 +02:00
|
|
|
static inline struct async_reader *impl_from_strmbase_filter(struct strmbase_filter *iface)
|
2012-03-31 03:09:49 +02:00
|
|
|
{
|
2020-04-02 06:01:00 +02:00
|
|
|
return CONTAINING_RECORD(iface, struct async_reader, filter);
|
2012-03-31 03:09:49 +02:00
|
|
|
}
|
|
|
|
|
2020-04-02 06:01:00 +02:00
|
|
|
static inline struct async_reader *impl_from_IFileSourceFilter(IFileSourceFilter *iface)
|
2012-03-31 03:09:49 +02:00
|
|
|
{
|
2020-04-02 06:01:00 +02:00
|
|
|
return CONTAINING_RECORD(iface, struct async_reader, IFileSourceFilter_iface);
|
2012-03-31 03:09:49 +02:00
|
|
|
}
|
|
|
|
|
2005-06-06 21:50:35 +02:00
|
|
|
static const IFileSourceFilterVtbl FileSource_Vtbl;
|
|
|
|
static const IAsyncReaderVtbl FileAsyncReader_Vtbl;
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2020-02-06 14:00:29 +01:00
|
|
|
static int byte_from_hex_char(WCHAR c)
|
2003-08-07 01:00:14 +02:00
|
|
|
{
|
2020-02-06 14:00:29 +01:00
|
|
|
if ('0' <= c && c <= '9') return c - '0';
|
|
|
|
if ('a' <= c && c <= 'f') return c - 'a' + 10;
|
|
|
|
if ('A' <= c && c <= 'F') return c - 'A' + 10;
|
|
|
|
return -1;
|
2003-08-07 01:00:14 +02:00
|
|
|
}
|
|
|
|
|
2019-08-06 21:58:35 +02:00
|
|
|
static BOOL process_pattern_string(const WCHAR *pattern, HANDLE file)
|
2003-08-07 01:00:14 +02:00
|
|
|
{
|
2019-08-06 21:58:35 +02:00
|
|
|
ULONG size, offset, i, ret_size;
|
2019-08-06 21:58:34 +02:00
|
|
|
BYTE *mask, *expect, *actual;
|
2020-02-06 14:00:29 +01:00
|
|
|
int d;
|
2019-08-06 21:58:34 +02:00
|
|
|
BOOL ret = TRUE;
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2019-08-06 21:58:34 +02:00
|
|
|
/* format: "offset, size, mask, value" */
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2019-08-06 21:58:34 +02:00
|
|
|
offset = wcstol(pattern, NULL, 10);
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2019-08-06 21:58:34 +02:00
|
|
|
if (!(pattern = wcschr(pattern, ',')))
|
|
|
|
return FALSE;
|
|
|
|
pattern++;
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2019-08-06 21:58:34 +02:00
|
|
|
size = wcstol(pattern, NULL, 10);
|
|
|
|
mask = heap_alloc(size);
|
|
|
|
expect = heap_alloc(size);
|
|
|
|
memset(mask, 0xff, size);
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2019-08-06 21:58:34 +02:00
|
|
|
if (!(pattern = wcschr(pattern, ',')))
|
2019-09-06 17:29:49 +02:00
|
|
|
{
|
|
|
|
heap_free(mask);
|
|
|
|
heap_free(expect);
|
2019-08-06 21:58:34 +02:00
|
|
|
return FALSE;
|
2019-09-06 17:29:49 +02:00
|
|
|
}
|
2019-08-06 21:58:34 +02:00
|
|
|
pattern++;
|
2020-02-06 14:00:29 +01:00
|
|
|
while (byte_from_hex_char(*pattern) == -1 && (*pattern != ','))
|
2019-08-06 21:58:34 +02:00
|
|
|
pattern++;
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2020-02-06 14:00:29 +01:00
|
|
|
for (i = 0; (d = byte_from_hex_char(*pattern)) != -1 && (i/2 < size); pattern++, i++)
|
2003-08-07 01:00:14 +02:00
|
|
|
{
|
2019-08-06 21:58:34 +02:00
|
|
|
if (i % 2)
|
2020-02-06 14:00:29 +01:00
|
|
|
mask[i / 2] |= d;
|
2019-08-06 21:58:34 +02:00
|
|
|
else
|
2020-02-06 14:00:29 +01:00
|
|
|
mask[i / 2] = d << 4;
|
2019-08-06 21:58:34 +02:00
|
|
|
}
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2019-08-06 21:58:34 +02:00
|
|
|
if (!(pattern = wcschr(pattern, ',')))
|
|
|
|
{
|
|
|
|
heap_free(mask);
|
|
|
|
heap_free(expect);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
pattern++;
|
2020-02-06 14:00:29 +01:00
|
|
|
while (byte_from_hex_char(*pattern) == -1 && (*pattern != ','))
|
2019-08-06 21:58:34 +02:00
|
|
|
pattern++;
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2020-02-06 14:00:29 +01:00
|
|
|
for (i = 0; (d = byte_from_hex_char(*pattern)) != -1 && (i/2 < size); pattern++, i++)
|
2019-08-06 21:58:34 +02:00
|
|
|
{
|
|
|
|
if (i % 2)
|
2020-02-06 14:00:29 +01:00
|
|
|
expect[i / 2] |= d;
|
2011-05-03 16:19:02 +02:00
|
|
|
else
|
2020-02-06 14:00:29 +01:00
|
|
|
expect[i / 2] = d << 4;
|
2003-08-07 01:00:14 +02:00
|
|
|
}
|
|
|
|
|
2019-08-06 21:58:34 +02:00
|
|
|
actual = heap_alloc(size);
|
2019-08-06 21:58:35 +02:00
|
|
|
SetFilePointer(file, offset, NULL, FILE_BEGIN);
|
|
|
|
if (!ReadFile(file, actual, size, &ret_size, NULL) || ret_size != size)
|
2003-08-07 01:00:14 +02:00
|
|
|
{
|
2019-08-06 21:58:34 +02:00
|
|
|
heap_free(actual);
|
|
|
|
heap_free(expect);
|
|
|
|
heap_free(mask);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2019-08-06 21:58:34 +02:00
|
|
|
for (i = 0; i < size; ++i)
|
|
|
|
{
|
|
|
|
if ((actual[i] & mask[i]) != expect[i])
|
2003-08-07 01:00:14 +02:00
|
|
|
{
|
2019-08-06 21:58:34 +02:00
|
|
|
ret = FALSE;
|
|
|
|
break;
|
2003-08-07 01:00:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-06 21:58:34 +02:00
|
|
|
heap_free(actual);
|
|
|
|
heap_free(expect);
|
|
|
|
heap_free(mask);
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2019-08-06 21:58:34 +02:00
|
|
|
/* If there is a following tuple, then we must match that as well. */
|
|
|
|
if (ret && (pattern = wcschr(pattern, ',')))
|
2019-08-06 21:58:35 +02:00
|
|
|
return process_pattern_string(pattern + 1, file);
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2019-08-06 21:58:34 +02:00
|
|
|
return ret;
|
2003-08-07 01:00:14 +02:00
|
|
|
}
|
|
|
|
|
2019-08-06 21:58:35 +02:00
|
|
|
BOOL get_media_type(const WCHAR *filename, GUID *majortype, GUID *subtype, GUID *source_clsid)
|
2003-08-07 01:00:14 +02:00
|
|
|
{
|
2019-08-06 21:58:32 +02:00
|
|
|
WCHAR extensions_path[278] = {'M','e','d','i','a',' ','T','y','p','e','\\','E','x','t','e','n','s','i','o','n','s','\\',0};
|
2019-08-06 21:58:33 +02:00
|
|
|
static const WCHAR wszExtensions[] = {'E','x','t','e','n','s','i','o','n','s',0};
|
|
|
|
static const WCHAR wszMediaType[] = {'M','e','d','i','a',' ','T','y','p','e',0};
|
|
|
|
DWORD majortype_idx, size;
|
2019-08-06 21:58:32 +02:00
|
|
|
const WCHAR *ext;
|
2019-08-06 21:58:33 +02:00
|
|
|
HKEY parent_key;
|
2019-08-06 21:58:35 +02:00
|
|
|
HANDLE file;
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2019-08-06 21:58:33 +02:00
|
|
|
if ((ext = wcsrchr(filename, '.')))
|
2019-08-06 21:58:32 +02:00
|
|
|
{
|
|
|
|
WCHAR guidstr[39];
|
|
|
|
HKEY key;
|
|
|
|
|
|
|
|
wcscat(extensions_path, ext);
|
|
|
|
if (!RegOpenKeyExW(HKEY_CLASSES_ROOT, extensions_path, 0, KEY_READ, &key))
|
|
|
|
{
|
|
|
|
size = sizeof(guidstr);
|
2020-01-22 23:30:53 +01:00
|
|
|
if (majortype && !RegQueryValueExW(key, L"Media Type", NULL, NULL, (BYTE *)guidstr, &size))
|
2019-08-06 21:58:33 +02:00
|
|
|
CLSIDFromString(guidstr, majortype);
|
2019-08-06 21:58:32 +02:00
|
|
|
|
|
|
|
size = sizeof(guidstr);
|
2020-01-22 23:30:53 +01:00
|
|
|
if (subtype && !RegQueryValueExW(key, L"Subtype", NULL, NULL, (BYTE *)guidstr, &size))
|
2019-08-06 21:58:33 +02:00
|
|
|
CLSIDFromString(guidstr, subtype);
|
2019-08-06 21:58:32 +02:00
|
|
|
|
|
|
|
size = sizeof(guidstr);
|
2020-01-22 23:30:53 +01:00
|
|
|
if (source_clsid && !RegQueryValueExW(key, L"Source Filter", NULL, NULL, (BYTE *)guidstr, &size))
|
2019-08-06 21:58:33 +02:00
|
|
|
CLSIDFromString(guidstr, source_clsid);
|
2019-08-06 21:58:32 +02:00
|
|
|
|
|
|
|
RegCloseKey(key);
|
2019-08-06 21:58:33 +02:00
|
|
|
return FALSE;
|
2019-08-06 21:58:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-06 21:58:35 +02:00
|
|
|
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());
|
2019-08-06 21:58:33 +02:00
|
|
|
return FALSE;
|
2019-08-06 21:58:35 +02:00
|
|
|
}
|
2019-08-06 21:58:33 +02:00
|
|
|
|
|
|
|
if (RegOpenKeyExW(HKEY_CLASSES_ROOT, wszMediaType, 0, KEY_READ, &parent_key))
|
2019-08-06 21:58:35 +02:00
|
|
|
{
|
|
|
|
CloseHandle(file);
|
2019-08-06 21:58:33 +02:00
|
|
|
return FALSE;
|
2019-08-06 21:58:35 +02:00
|
|
|
}
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2019-08-06 21:58:33 +02:00
|
|
|
for (majortype_idx = 0; ; ++majortype_idx)
|
2003-08-07 01:00:14 +02:00
|
|
|
{
|
2019-08-06 21:58:33 +02:00
|
|
|
WCHAR majortype_str[39];
|
|
|
|
HKEY majortype_key;
|
|
|
|
DWORD subtype_idx;
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2019-08-06 21:58:33 +02:00
|
|
|
size = ARRAY_SIZE(majortype_str);
|
|
|
|
if (RegEnumKeyExW(parent_key, majortype_idx, majortype_str, &size, NULL, NULL, NULL, NULL))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (!wcscmp(majortype_str, wszExtensions))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (RegOpenKeyExW(parent_key, majortype_str, 0, KEY_READ, &majortype_key))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (subtype_idx = 0; ; ++subtype_idx)
|
2003-08-07 01:00:14 +02:00
|
|
|
{
|
2019-08-06 21:58:33 +02:00
|
|
|
WCHAR subtype_str[39], *pattern;
|
|
|
|
DWORD value_idx, max_size;
|
|
|
|
HKEY subtype_key;
|
2008-03-14 04:28:09 +01:00
|
|
|
|
2019-08-06 21:58:33 +02:00
|
|
|
size = ARRAY_SIZE(subtype_str);
|
|
|
|
if (RegEnumKeyExW(majortype_key, subtype_idx, subtype_str, &size, NULL, NULL, NULL, NULL))
|
2003-08-07 01:00:14 +02:00
|
|
|
break;
|
2019-08-06 21:58:33 +02:00
|
|
|
|
|
|
|
if (RegOpenKeyExW(majortype_key, subtype_str, 0, KEY_READ, &subtype_key))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (RegQueryInfoKeyW(subtype_key, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &max_size, NULL, NULL))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
pattern = heap_alloc(max_size);
|
|
|
|
|
|
|
|
for (value_idx = 0; ; ++value_idx)
|
2003-08-07 01:00:14 +02:00
|
|
|
{
|
2019-08-06 21:58:33 +02:00
|
|
|
/* The longest name we should encounter is "Source Filter". */
|
|
|
|
WCHAR value_name[14], source_clsid_str[39];
|
|
|
|
DWORD value_len = ARRAY_SIZE(value_name);
|
|
|
|
|
|
|
|
size = max_size;
|
|
|
|
if (RegEnumValueW(subtype_key, value_idx, value_name, &value_len,
|
|
|
|
NULL, NULL, (BYTE *)pattern, &max_size))
|
|
|
|
break;
|
|
|
|
|
2020-01-22 23:30:53 +01:00
|
|
|
if (!wcscmp(value_name, L"Source Filter"))
|
2019-08-06 21:58:33 +02:00
|
|
|
continue;
|
|
|
|
|
2019-08-06 21:58:35 +02:00
|
|
|
if (!process_pattern_string(pattern, file))
|
2019-08-06 21:58:33 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (majortype)
|
|
|
|
CLSIDFromString(majortype_str, majortype);
|
|
|
|
if (subtype)
|
|
|
|
CLSIDFromString(subtype_str, subtype);
|
|
|
|
size = sizeof(source_clsid_str);
|
2020-01-22 23:30:53 +01:00
|
|
|
if (source_clsid && !RegQueryValueExW(subtype_key, L"Source Filter",
|
2019-08-06 21:58:33 +02:00
|
|
|
NULL, NULL, (BYTE *)source_clsid_str, &size))
|
|
|
|
CLSIDFromString(source_clsid_str, source_clsid);
|
|
|
|
|
|
|
|
heap_free(pattern);
|
|
|
|
RegCloseKey(subtype_key);
|
|
|
|
RegCloseKey(majortype_key);
|
|
|
|
RegCloseKey(parent_key);
|
2019-08-06 21:58:35 +02:00
|
|
|
CloseHandle(file);
|
2019-08-06 21:58:33 +02:00
|
|
|
return TRUE;
|
2003-08-07 01:00:14 +02:00
|
|
|
}
|
2019-08-06 21:58:33 +02:00
|
|
|
|
|
|
|
heap_free(pattern);
|
|
|
|
RegCloseKey(subtype_key);
|
2003-08-07 01:00:14 +02:00
|
|
|
}
|
2019-08-06 21:58:33 +02:00
|
|
|
|
|
|
|
RegCloseKey(majortype_key);
|
2003-08-07 01:00:14 +02:00
|
|
|
}
|
|
|
|
|
2019-08-06 21:58:33 +02:00
|
|
|
RegCloseKey(parent_key);
|
2019-08-06 21:58:35 +02:00
|
|
|
CloseHandle(file);
|
2019-08-06 21:58:33 +02:00
|
|
|
return FALSE;
|
2003-08-07 01:00:14 +02:00
|
|
|
}
|
|
|
|
|
2019-11-23 04:13:59 +01:00
|
|
|
static struct strmbase_pin *async_reader_get_pin(struct strmbase_filter *iface, unsigned int index)
|
2010-10-07 21:48:01 +02:00
|
|
|
{
|
2020-04-02 06:01:00 +02:00
|
|
|
struct async_reader *filter = impl_from_strmbase_filter(iface);
|
2010-10-07 21:48:01 +02:00
|
|
|
|
2019-06-20 03:16:12 +02:00
|
|
|
if (!index && filter->pszFileName)
|
2019-11-23 04:13:59 +01:00
|
|
|
return &filter->source.pin;
|
2019-06-11 16:42:16 +02:00
|
|
|
return NULL;
|
2010-10-07 21:48:01 +02:00
|
|
|
}
|
|
|
|
|
2019-08-29 03:24:30 +02:00
|
|
|
static void async_reader_destroy(struct strmbase_filter *iface)
|
2019-05-24 00:06:34 +02:00
|
|
|
{
|
2020-04-02 06:01:00 +02:00
|
|
|
struct async_reader *filter = impl_from_strmbase_filter(iface);
|
2019-05-24 00:06:34 +02:00
|
|
|
|
2019-06-20 03:16:12 +02:00
|
|
|
if (filter->pszFileName)
|
2019-05-24 00:06:34 +02:00
|
|
|
{
|
2019-06-17 02:35:00 +02:00
|
|
|
unsigned int i;
|
|
|
|
|
2019-09-27 04:40:53 +02:00
|
|
|
if (filter->source.pin.peer)
|
|
|
|
IPin_Disconnect(filter->source.pin.peer);
|
2019-06-20 03:16:12 +02:00
|
|
|
|
|
|
|
IPin_Disconnect(&filter->source.pin.IPin_iface);
|
2019-06-17 02:35:00 +02:00
|
|
|
|
2020-01-30 02:56:59 +01:00
|
|
|
if (filter->requests)
|
2019-06-17 02:35:00 +02:00
|
|
|
{
|
2020-01-30 02:56:59 +01:00
|
|
|
for (i = 0; i < filter->max_requests; ++i)
|
|
|
|
CloseHandle(filter->requests[i].ovl.hEvent);
|
2020-01-30 02:57:00 +01:00
|
|
|
free(filter->requests);
|
2019-06-17 02:35:00 +02:00
|
|
|
}
|
2019-06-20 03:16:12 +02:00
|
|
|
CloseHandle(filter->file);
|
|
|
|
filter->sample_cs.DebugInfo->Spare[0] = 0;
|
|
|
|
DeleteCriticalSection(&filter->sample_cs);
|
|
|
|
strmbase_source_cleanup(&filter->source);
|
2020-01-30 02:57:01 +01:00
|
|
|
|
|
|
|
CoTaskMemFree(filter->pszFileName);
|
|
|
|
FreeMediaType(&filter->mt);
|
2019-05-24 00:06:34 +02:00
|
|
|
}
|
2020-01-30 02:56:59 +01:00
|
|
|
|
|
|
|
PostQueuedCompletionStatus(filter->port, 0, 1, NULL);
|
|
|
|
WaitForSingleObject(filter->io_thread, INFINITE);
|
|
|
|
CloseHandle(filter->io_thread);
|
|
|
|
CloseHandle(filter->port);
|
|
|
|
|
2019-05-24 00:06:34 +02:00
|
|
|
strmbase_filter_cleanup(&filter->filter);
|
2020-02-14 05:55:54 +01:00
|
|
|
free(filter);
|
2020-03-13 03:34:12 +01:00
|
|
|
|
|
|
|
InterlockedDecrement(&object_locks);
|
2019-05-24 00:06:34 +02:00
|
|
|
}
|
|
|
|
|
2019-08-29 03:24:30 +02:00
|
|
|
static HRESULT async_reader_query_interface(struct strmbase_filter *iface, REFIID iid, void **out)
|
2019-05-30 03:52:57 +02:00
|
|
|
{
|
2020-04-02 06:01:00 +02:00
|
|
|
struct async_reader *filter = impl_from_strmbase_filter(iface);
|
2019-05-30 03:52:57 +02:00
|
|
|
|
|
|
|
if (IsEqualGUID(iid, &IID_IFileSourceFilter))
|
|
|
|
{
|
|
|
|
*out = &filter->IFileSourceFilter_iface;
|
|
|
|
IUnknown_AddRef((IUnknown *)*out);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
2019-08-29 03:24:29 +02:00
|
|
|
static const struct strmbase_filter_ops filter_ops =
|
2019-05-24 00:06:34 +02:00
|
|
|
{
|
2019-05-24 00:06:31 +02:00
|
|
|
.filter_get_pin = async_reader_get_pin,
|
2019-05-24 00:06:34 +02:00
|
|
|
.filter_destroy = async_reader_destroy,
|
2019-05-30 03:52:57 +02:00
|
|
|
.filter_query_interface = async_reader_query_interface,
|
2010-10-13 18:02:01 +02:00
|
|
|
};
|
|
|
|
|
2020-01-30 02:56:59 +01:00
|
|
|
static DWORD CALLBACK io_thread(void *arg)
|
|
|
|
{
|
2020-04-02 06:01:00 +02:00
|
|
|
struct async_reader *filter = arg;
|
2020-01-30 02:56:59 +01:00
|
|
|
struct request *req;
|
|
|
|
OVERLAPPED *ovl;
|
|
|
|
ULONG_PTR key;
|
|
|
|
DWORD size;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
ret = GetQueuedCompletionStatus(filter->port, &size, &key, &ovl, INFINITE);
|
|
|
|
|
|
|
|
if (ret && key)
|
|
|
|
break;
|
|
|
|
|
|
|
|
EnterCriticalSection(&filter->sample_cs);
|
|
|
|
|
|
|
|
req = CONTAINING_RECORD(ovl, struct request, ovl);
|
|
|
|
TRACE("Got sample %u.\n", req - filter->requests);
|
|
|
|
assert(req >= filter->requests && req < filter->requests + filter->max_requests);
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
WakeConditionVariable(&filter->sample_cv);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ERR("GetQueuedCompletionStatus() returned failure, error %u.\n", GetLastError());
|
|
|
|
req->sample = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
LeaveCriticalSection(&filter->sample_cs);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-03-12 03:10:10 +01:00
|
|
|
HRESULT async_reader_create(IUnknown *outer, IUnknown **out)
|
2003-08-07 01:00:14 +02:00
|
|
|
{
|
2020-04-02 06:01:00 +02:00
|
|
|
struct async_reader *object;
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2020-02-14 05:55:54 +01:00
|
|
|
if (!(object = calloc(1, sizeof(*object))))
|
2003-08-07 01:00:14 +02:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2020-02-14 05:55:54 +01:00
|
|
|
strmbase_filter_init(&object->filter, outer, &CLSID_AsyncReader, &filter_ops);
|
2010-10-07 21:47:33 +02:00
|
|
|
|
2020-02-14 05:55:54 +01:00
|
|
|
object->IFileSourceFilter_iface.lpVtbl = &FileSource_Vtbl;
|
|
|
|
object->IAsyncReader_iface.lpVtbl = &FileAsyncReader_Vtbl;
|
2019-06-20 03:16:12 +02:00
|
|
|
|
2020-02-14 05:55:54 +01:00
|
|
|
InitializeCriticalSection(&object->sample_cs);
|
|
|
|
object->sample_cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": FileAsyncReader.sample_cs");
|
|
|
|
InitializeConditionVariable(&object->sample_cv);
|
|
|
|
object->port = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, 0, 0);
|
|
|
|
object->io_thread = CreateThread(NULL, 0, io_thread, object, 0, NULL);
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2020-02-14 05:55:54 +01:00
|
|
|
TRACE("Created file source %p.\n", object);
|
|
|
|
*out = &object->filter.IUnknown_inner;
|
2003-08-07 01:00:14 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI FileSource_QueryInterface(IFileSourceFilter * iface, REFIID riid, LPVOID * ppv)
|
|
|
|
{
|
2020-04-02 06:01:00 +02:00
|
|
|
struct async_reader *filter = impl_from_IFileSourceFilter(iface);
|
|
|
|
return IBaseFilter_QueryInterface(&filter->filter.IBaseFilter_iface, riid, ppv);
|
2003-08-07 01:00:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI FileSource_AddRef(IFileSourceFilter * iface)
|
|
|
|
{
|
2020-04-02 06:01:00 +02:00
|
|
|
struct async_reader *filter = impl_from_IFileSourceFilter(iface);
|
|
|
|
return IBaseFilter_AddRef(&filter->filter.IBaseFilter_iface);
|
2003-08-07 01:00:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI FileSource_Release(IFileSourceFilter * iface)
|
|
|
|
{
|
2020-04-02 06:01:00 +02:00
|
|
|
struct async_reader *filter = impl_from_IFileSourceFilter(iface);
|
|
|
|
return IBaseFilter_Release(&filter->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)
|
|
|
|
{
|
2020-04-02 06:01:00 +02:00
|
|
|
struct async_reader *This = impl_from_IFileSourceFilter(iface);
|
2003-08-07 01:00:14 +02:00
|
|
|
HANDLE hFile;
|
|
|
|
|
2017-11-09 01:12:20 +01:00
|
|
|
TRACE("%p->(%s, %p)\n", This, debugstr_w(pszFileName), pmt);
|
2019-10-06 02:18:51 +02:00
|
|
|
strmbase_dump_media_type(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());
|
|
|
|
}
|
|
|
|
|
2020-04-20 02:53:20 +02:00
|
|
|
if (!GetFileSizeEx(hFile, &This->file_size))
|
|
|
|
{
|
|
|
|
WARN("Could not get file size.\n");
|
2020-08-20 15:08:20 +02:00
|
|
|
CloseHandle(hFile);
|
2020-04-20 02:53:20 +02:00
|
|
|
return HRESULT_FROM_WIN32(GetLastError());
|
|
|
|
}
|
|
|
|
|
2020-01-30 02:57:01 +01:00
|
|
|
if (This->pszFileName)
|
|
|
|
{
|
|
|
|
free(This->pszFileName);
|
|
|
|
FreeMediaType(&This->mt);
|
|
|
|
}
|
|
|
|
|
2020-01-22 23:30:53 +01:00
|
|
|
if (!(This->pszFileName = wcsdup(pszFileName)))
|
|
|
|
{
|
|
|
|
CloseHandle(hFile);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
strmbase_source_init(&This->source, &This->filter, L"Output", &source_ops);
|
2012-03-24 17:42:27 +01:00
|
|
|
BaseFilterImpl_IncrementPinVersion(&This->filter);
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2019-06-20 03:16:12 +02:00
|
|
|
This->file = hFile;
|
|
|
|
This->flushing = FALSE;
|
2020-01-30 02:56:59 +01:00
|
|
|
This->requests = NULL;
|
2008-04-04 23:32:09 +02:00
|
|
|
|
2019-06-20 03:16:12 +02:00
|
|
|
if (!pmt)
|
2003-08-07 01:00:14 +02:00
|
|
|
{
|
2020-01-30 02:57:01 +01:00
|
|
|
CopyMediaType(&This->mt, &default_mt);
|
|
|
|
if (get_media_type(pszFileName, &This->mt.majortype, &This->mt.subtype, NULL))
|
2019-08-06 21:58:31 +02:00
|
|
|
{
|
|
|
|
TRACE("Found major type %s, subtype %s.\n",
|
2020-01-30 02:57:01 +01:00
|
|
|
debugstr_guid(&This->mt.majortype), debugstr_guid(&This->mt.subtype));
|
2019-08-06 21:58:31 +02:00
|
|
|
}
|
2003-08-07 01:00:14 +02:00
|
|
|
}
|
2019-06-20 03:16:12 +02:00
|
|
|
else
|
2020-01-30 02:57:01 +01:00
|
|
|
CopyMediaType(&This->mt, pmt);
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2019-06-20 03:16:12 +02:00
|
|
|
return S_OK;
|
2003-08-07 01:00:14 +02:00
|
|
|
}
|
|
|
|
|
2020-01-30 02:57:01 +01:00
|
|
|
static HRESULT WINAPI FileSource_GetCurFile(IFileSourceFilter *iface, LPOLESTR *ppszFileName, AM_MEDIA_TYPE *mt)
|
2003-08-07 01:00:14 +02:00
|
|
|
{
|
2020-04-02 06:01:00 +02:00
|
|
|
struct async_reader *This = impl_from_IFileSourceFilter(iface);
|
2020-01-30 02:57:01 +01:00
|
|
|
|
|
|
|
TRACE("filter %p, filename %p, mt %p.\n", This, ppszFileName, mt);
|
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)
|
|
|
|
{
|
2020-01-22 23:30:53 +01:00
|
|
|
*ppszFileName = CoTaskMemAlloc((wcslen(This->pszFileName) + 1) * sizeof(WCHAR));
|
|
|
|
wcscpy(*ppszFileName, This->pszFileName);
|
2020-01-30 02:57:01 +01:00
|
|
|
if (mt)
|
|
|
|
CopyMediaType(mt, &This->mt);
|
2003-08-07 01:00:14 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-01-30 02:57:01 +01:00
|
|
|
*ppszFileName = NULL;
|
|
|
|
if (mt)
|
|
|
|
memset(mt, 0, sizeof(AM_MEDIA_TYPE));
|
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
|
|
|
|
};
|
|
|
|
|
2020-04-02 06:01:00 +02:00
|
|
|
static inline struct async_reader *impl_from_strmbase_pin(struct strmbase_pin *iface)
|
2012-03-31 03:09:49 +02:00
|
|
|
{
|
2020-04-02 06:01:00 +02:00
|
|
|
return CONTAINING_RECORD(iface, struct async_reader, source.pin);
|
2012-03-31 03:09:49 +02:00
|
|
|
}
|
|
|
|
|
2020-04-02 06:01:00 +02:00
|
|
|
static inline struct async_reader *impl_from_IAsyncReader(IAsyncReader *iface)
|
2012-03-31 03:09:49 +02:00
|
|
|
{
|
2020-04-02 06:01:00 +02:00
|
|
|
return CONTAINING_RECORD(iface, struct async_reader, IAsyncReader_iface);
|
2005-07-27 17:14:18 +02:00
|
|
|
}
|
|
|
|
|
2020-01-30 02:57:01 +01:00
|
|
|
static HRESULT source_query_accept(struct strmbase_pin *iface, const AM_MEDIA_TYPE *mt)
|
2003-08-07 01:00:14 +02:00
|
|
|
{
|
2020-04-02 06:01:00 +02:00
|
|
|
struct async_reader *filter = impl_from_strmbase_pin(iface);
|
2009-01-29 11:14:55 +01:00
|
|
|
|
2020-01-30 02:57:01 +01:00
|
|
|
if (IsEqualGUID(&mt->majortype, &filter->mt.majortype)
|
2020-02-03 21:15:51 +01:00
|
|
|
&& (!IsEqualGUID(&mt->subtype, &GUID_NULL)
|
|
|
|
|| IsEqualGUID(&filter->mt.subtype, &GUID_NULL)))
|
2003-08-07 01:00:14 +02:00
|
|
|
return S_OK;
|
2010-10-05 21:37:42 +02:00
|
|
|
|
2003-08-07 01:00:14 +02:00
|
|
|
return S_FALSE;
|
|
|
|
}
|
|
|
|
|
2019-09-25 02:10:12 +02:00
|
|
|
static HRESULT source_get_media_type(struct strmbase_pin *iface, unsigned int index, AM_MEDIA_TYPE *mt)
|
2010-10-05 21:37:30 +02:00
|
|
|
{
|
2020-04-02 06:01:00 +02:00
|
|
|
struct async_reader *filter = impl_from_strmbase_pin(iface);
|
2019-02-22 01:42:58 +01:00
|
|
|
|
2019-09-25 02:10:12 +02:00
|
|
|
if (index > 1)
|
2010-10-05 21:37:30 +02:00
|
|
|
return VFW_S_NO_MORE_ITEMS;
|
2019-02-22 01:42:58 +01:00
|
|
|
|
|
|
|
if (index == 0)
|
2020-01-30 02:57:01 +01:00
|
|
|
CopyMediaType(mt, &filter->mt);
|
2019-02-22 01:42:58 +01:00
|
|
|
else if (index == 1)
|
|
|
|
CopyMediaType(mt, &default_mt);
|
2010-10-05 21:37:30 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2019-09-26 05:36:24 +02:00
|
|
|
static HRESULT source_query_interface(struct strmbase_pin *iface, REFIID iid, void **out)
|
2003-08-07 01:00:14 +02:00
|
|
|
{
|
2020-04-02 06:01:00 +02:00
|
|
|
struct async_reader *filter = impl_from_strmbase_pin(iface);
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2019-09-26 05:36:24 +02:00
|
|
|
if (IsEqualGUID(iid, &IID_IAsyncReader))
|
2019-06-20 03:16:12 +02:00
|
|
|
*out = &filter->IAsyncReader_iface;
|
|
|
|
else
|
|
|
|
return E_NOINTERFACE;
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2019-06-20 03:16:12 +02:00
|
|
|
IUnknown_AddRef((IUnknown *)*out);
|
|
|
|
return S_OK;
|
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 */
|
2019-09-12 21:28:25 +02:00
|
|
|
static HRESULT WINAPI FileAsyncReaderPin_AttemptConnection(struct strmbase_source *This,
|
2019-05-09 17:12:33 +02:00
|
|
|
IPin *pReceivePin, const AM_MEDIA_TYPE *pmt)
|
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
|
|
|
|
2020-03-06 03:04:35 +01:00
|
|
|
if (This->pin.ops->pin_query_accept(&This->pin, pmt) != S_OK)
|
|
|
|
return VFW_E_TYPE_NOT_ACCEPTED;
|
2004-08-19 04:33:00 +02:00
|
|
|
|
2019-09-27 04:40:53 +02:00
|
|
|
This->pin.peer = pReceivePin;
|
2004-08-19 04:33:00 +02:00
|
|
|
IPin_AddRef(pReceivePin);
|
2019-11-19 01:51:20 +01:00
|
|
|
CopyMediaType(&This->pin.mt, pmt);
|
2004-08-19 04:33:00 +02:00
|
|
|
|
2019-05-09 17:12:33 +02:00
|
|
|
hr = IPin_ReceiveConnection(pReceivePin, &This->pin.IPin_iface, pmt);
|
2004-08-19 04:33:00 +02:00
|
|
|
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2019-09-27 04:40:53 +02:00
|
|
|
IPin_Release(This->pin.peer);
|
|
|
|
This->pin.peer = NULL;
|
2019-11-19 01:51:20 +01:00
|
|
|
FreeMediaType(&This->pin.mt);
|
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;
|
|
|
|
}
|
|
|
|
|
2019-09-12 21:28:26 +02:00
|
|
|
static const struct strmbase_source_ops source_ops =
|
|
|
|
{
|
2019-09-25 02:10:10 +02:00
|
|
|
.base.pin_query_accept = source_query_accept,
|
2019-09-25 02:10:11 +02:00
|
|
|
.base.pin_get_media_type = source_get_media_type,
|
2019-09-26 05:36:24 +02:00
|
|
|
.base.pin_query_interface = source_query_interface,
|
2019-09-25 02:10:10 +02:00
|
|
|
.pfnAttemptConnection = FileAsyncReaderPin_AttemptConnection,
|
2010-10-13 18:02:01 +02:00
|
|
|
};
|
2010-10-13 17:46:27 +02:00
|
|
|
|
2019-06-20 03:16:12 +02:00
|
|
|
static HRESULT WINAPI FileAsyncReader_QueryInterface(IAsyncReader *iface, REFIID iid, void **out)
|
2003-08-07 01:00:14 +02:00
|
|
|
{
|
2020-04-02 06:01:00 +02:00
|
|
|
struct async_reader *filter = impl_from_IAsyncReader(iface);
|
2019-06-20 03:16:12 +02:00
|
|
|
return IPin_QueryInterface(&filter->source.pin.IPin_iface, iid, out);
|
2003-08-07 01:00:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI FileAsyncReader_AddRef(IAsyncReader * iface)
|
|
|
|
{
|
2020-04-02 06:01:00 +02:00
|
|
|
struct async_reader *filter = impl_from_IAsyncReader(iface);
|
2019-06-20 03:16:12 +02:00
|
|
|
return IPin_AddRef(&filter->source.pin.IPin_iface);
|
2003-08-07 01:00:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI FileAsyncReader_Release(IAsyncReader * iface)
|
|
|
|
{
|
2020-04-02 06:01:00 +02:00
|
|
|
struct async_reader *filter = impl_from_IAsyncReader(iface);
|
2019-06-20 03:16:12 +02:00
|
|
|
return IPin_Release(&filter->source.pin.IPin_iface);
|
2003-08-07 01:00:14 +02:00
|
|
|
}
|
|
|
|
|
2020-01-30 02:57:00 +01:00
|
|
|
static HRESULT WINAPI FileAsyncReader_RequestAllocator(IAsyncReader *iface,
|
|
|
|
IMemAllocator *preferred, ALLOCATOR_PROPERTIES *props, IMemAllocator **ret_allocator)
|
2003-08-07 01:00:14 +02:00
|
|
|
{
|
2020-04-02 06:01:00 +02:00
|
|
|
struct async_reader *filter = impl_from_IAsyncReader(iface);
|
2020-01-30 02:57:00 +01:00
|
|
|
IMemAllocator *allocator;
|
|
|
|
unsigned int i;
|
|
|
|
HRESULT hr;
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2020-01-30 02:57:00 +01:00
|
|
|
TRACE("filter %p, preferred %p, props %p, ret_allocator %p.\n", filter, preferred, props, ret_allocator);
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2020-01-30 02:57:00 +01:00
|
|
|
if (!props->cbAlign)
|
|
|
|
props->cbAlign = 1;
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2020-01-30 02:57:00 +01:00
|
|
|
*ret_allocator = NULL;
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2020-01-30 02:57:00 +01:00
|
|
|
if (preferred)
|
|
|
|
IMemAllocator_AddRef(allocator = preferred);
|
|
|
|
else if (FAILED(hr = CoCreateInstance(&CLSID_MemoryAllocator, NULL,
|
|
|
|
CLSCTX_INPROC, &IID_IMemAllocator, (void **)&allocator)))
|
|
|
|
return hr;
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2020-01-30 02:57:00 +01:00
|
|
|
if (FAILED(hr = IMemAllocator_SetProperties(allocator, props, props)))
|
2003-08-07 01:00:14 +02:00
|
|
|
{
|
2020-01-30 02:57:00 +01:00
|
|
|
IMemAllocator_Release(allocator);
|
|
|
|
return hr;
|
2008-04-23 01:54:28 +02:00
|
|
|
}
|
|
|
|
|
2020-01-30 02:57:00 +01:00
|
|
|
if (filter->requests)
|
2008-04-23 01:54:28 +02:00
|
|
|
{
|
2020-01-30 02:57:00 +01:00
|
|
|
for (i = 0; i < filter->max_requests; ++i)
|
|
|
|
CloseHandle(filter->requests[i].ovl.hEvent);
|
|
|
|
free(filter->requests);
|
2003-08-07 01:00:14 +02:00
|
|
|
}
|
|
|
|
|
2020-01-30 02:57:00 +01:00
|
|
|
filter->max_requests = props->cBuffers;
|
|
|
|
TRACE("Maximum request count: %u.\n", filter->max_requests);
|
|
|
|
if (!(filter->requests = calloc(filter->max_requests, sizeof(filter->requests[0]))))
|
2003-08-07 01:00:14 +02:00
|
|
|
{
|
2020-01-30 02:57:00 +01:00
|
|
|
IMemAllocator_Release(allocator);
|
|
|
|
return E_OUTOFMEMORY;
|
2003-08-07 01:00:14 +02:00
|
|
|
}
|
|
|
|
|
2020-01-30 02:57:00 +01:00
|
|
|
for (i = 0; i < filter->max_requests; ++i)
|
|
|
|
filter->requests[i].ovl.hEvent = CreateEventW(NULL, TRUE, FALSE, NULL);
|
|
|
|
|
|
|
|
*ret_allocator = allocator;
|
|
|
|
return S_OK;
|
2003-08-07 01:00:14 +02:00
|
|
|
}
|
|
|
|
|
2020-01-30 02:56:59 +01:00
|
|
|
static HRESULT WINAPI FileAsyncReader_Request(IAsyncReader *iface, IMediaSample *sample, DWORD_PTR cookie)
|
2003-08-07 01:00:14 +02:00
|
|
|
{
|
2020-04-02 06:01:00 +02:00
|
|
|
struct async_reader *filter = impl_from_IAsyncReader(iface);
|
2020-01-30 02:56:59 +01:00
|
|
|
REFERENCE_TIME start, end;
|
|
|
|
struct request *req;
|
|
|
|
unsigned int i;
|
|
|
|
HRESULT hr;
|
|
|
|
BYTE *data;
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2020-01-30 02:56:59 +01:00
|
|
|
TRACE("filter %p, sample %p, cookie %#lx.\n", filter, sample, cookie);
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2020-01-30 02:56:59 +01:00
|
|
|
if (!sample)
|
2008-04-23 01:54:28 +02:00
|
|
|
return E_POINTER;
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2020-01-30 02:56:59 +01:00
|
|
|
if (FAILED(hr = IMediaSample_GetTime(sample, &start, &end)))
|
|
|
|
return hr;
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2020-04-20 01:05:59 +02:00
|
|
|
if (BYTES_FROM_MEDIATIME(start) >= filter->file_size.QuadPart)
|
|
|
|
return HRESULT_FROM_WIN32(ERROR_HANDLE_EOF);
|
|
|
|
|
2020-01-30 02:56:59 +01:00
|
|
|
if (FAILED(hr = IMediaSample_GetPointer(sample, &data)))
|
|
|
|
return hr;
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2020-01-30 02:56:59 +01:00
|
|
|
EnterCriticalSection(&filter->sample_cs);
|
|
|
|
if (filter->flushing)
|
2008-04-23 01:54:28 +02:00
|
|
|
{
|
2020-01-30 02:56:59 +01:00
|
|
|
LeaveCriticalSection(&filter->sample_cs);
|
2008-04-23 01:54:28 +02:00
|
|
|
return VFW_E_WRONG_STATE;
|
|
|
|
}
|
|
|
|
|
2020-01-30 02:56:59 +01:00
|
|
|
for (i = 0; i < filter->max_requests; ++i)
|
2003-08-07 01:00:14 +02:00
|
|
|
{
|
2020-01-30 02:56:59 +01:00
|
|
|
if (!filter->requests[i].sample)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
assert(i < filter->max_requests);
|
|
|
|
req = &filter->requests[i];
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2020-01-30 02:56:59 +01:00
|
|
|
req->ovl.u.s.Offset = BYTES_FROM_MEDIATIME(start);
|
|
|
|
req->ovl.u.s.OffsetHigh = BYTES_FROM_MEDIATIME(start) >> 32;
|
|
|
|
/* No reference is taken. */
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2020-01-30 02:56:59 +01:00
|
|
|
if (ReadFile(filter->file, data, BYTES_FROM_MEDIATIME(end - start), NULL, &req->ovl)
|
|
|
|
|| GetLastError() == ERROR_IO_PENDING)
|
|
|
|
{
|
|
|
|
hr = S_OK;
|
|
|
|
req->sample = sample;
|
|
|
|
req->cookie = cookie;
|
2003-08-07 01:00:14 +02:00
|
|
|
}
|
2020-01-30 02:56:59 +01:00
|
|
|
else
|
|
|
|
hr = HRESULT_FROM_WIN32(GetLastError());
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2020-01-30 02:56:59 +01:00
|
|
|
LeaveCriticalSection(&filter->sample_cs);
|
2003-08-07 01:00:14 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2020-01-30 02:56:59 +01:00
|
|
|
static HRESULT WINAPI FileAsyncReader_WaitForNext(IAsyncReader *iface,
|
|
|
|
DWORD timeout, IMediaSample **sample, DWORD_PTR *cookie)
|
2003-08-07 01:00:14 +02:00
|
|
|
{
|
2020-04-02 06:01:00 +02:00
|
|
|
struct async_reader *filter = impl_from_IAsyncReader(iface);
|
2020-01-30 02:56:59 +01:00
|
|
|
unsigned int i;
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2020-01-30 02:56:59 +01:00
|
|
|
TRACE("filter %p, timeout %u, sample %p, cookie %p.\n", filter, timeout, sample, cookie);
|
2008-07-10 23:33:53 +02:00
|
|
|
|
2020-01-30 02:56:59 +01:00
|
|
|
*sample = NULL;
|
|
|
|
*cookie = 0;
|
2008-04-23 01:54:28 +02:00
|
|
|
|
2020-01-30 02:56:59 +01:00
|
|
|
EnterCriticalSection(&filter->sample_cs);
|
2008-07-10 23:33:53 +02:00
|
|
|
|
2020-01-30 02:56:59 +01:00
|
|
|
do
|
|
|
|
{
|
|
|
|
if (filter->flushing)
|
2008-07-10 23:33:53 +02:00
|
|
|
{
|
2020-01-30 02:56:59 +01:00
|
|
|
LeaveCriticalSection(&filter->sample_cs);
|
|
|
|
return VFW_E_WRONG_STATE;
|
2008-07-10 23:33:53 +02:00
|
|
|
}
|
2008-04-22 22:44:33 +02:00
|
|
|
|
2020-01-30 02:56:59 +01:00
|
|
|
for (i = 0; i < filter->max_requests; ++i)
|
2008-04-23 01:54:28 +02:00
|
|
|
{
|
2020-01-30 02:56:59 +01:00
|
|
|
struct request *req = &filter->requests[i];
|
|
|
|
DWORD size;
|
2008-04-04 23:30:21 +02:00
|
|
|
|
2020-01-30 02:56:59 +01:00
|
|
|
if (req->sample && GetOverlappedResult(filter->file, &req->ovl, &size, FALSE))
|
2008-04-25 23:33:15 +02:00
|
|
|
{
|
2020-01-30 02:56:59 +01:00
|
|
|
REFERENCE_TIME start, end;
|
2008-04-17 22:11:05 +02:00
|
|
|
|
2020-01-30 02:56:59 +01:00
|
|
|
IMediaSample_SetActualDataLength(req->sample, size);
|
|
|
|
start = MEDIATIME_FROM_BYTES(((ULONGLONG)req->ovl.u.s.OffsetHigh << 32) + req->ovl.u.s.Offset);
|
|
|
|
end = start + MEDIATIME_FROM_BYTES(size);
|
|
|
|
IMediaSample_SetTime(req->sample, &start, &end);
|
2008-04-19 01:07:40 +02:00
|
|
|
|
2020-01-30 02:56:59 +01:00
|
|
|
*sample = req->sample;
|
|
|
|
*cookie = req->cookie;
|
|
|
|
req->sample = NULL;
|
2008-04-19 01:07:40 +02:00
|
|
|
|
2020-01-30 02:56:59 +01:00
|
|
|
LeaveCriticalSection(&filter->sample_cs);
|
|
|
|
TRACE("Returning sample %u.\n", i);
|
|
|
|
return S_OK;
|
|
|
|
}
|
2008-07-10 23:33:53 +02:00
|
|
|
}
|
2020-01-30 02:56:59 +01:00
|
|
|
} while (SleepConditionVariableCS(&filter->sample_cv, &filter->sample_cs, timeout));
|
2008-04-04 23:30:21 +02:00
|
|
|
|
2020-01-30 02:56:59 +01:00
|
|
|
LeaveCriticalSection(&filter->sample_cs);
|
|
|
|
return VFW_E_TIMEOUT;
|
2003-08-07 01:00:14 +02:00
|
|
|
}
|
|
|
|
|
2019-02-23 02:27:04 +01:00
|
|
|
static BOOL sync_read(HANDLE file, LONGLONG offset, LONG length, BYTE *buffer, DWORD *read_len)
|
|
|
|
{
|
|
|
|
OVERLAPPED ovl = {0};
|
|
|
|
BOOL ret;
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2020-01-30 02:56:59 +01:00
|
|
|
ovl.hEvent = (HANDLE)((ULONG_PTR)CreateEventW(NULL, TRUE, FALSE, NULL) | 1);
|
2019-02-23 02:27:04 +01:00
|
|
|
ovl.u.s.Offset = (DWORD)offset;
|
|
|
|
ovl.u.s.OffsetHigh = offset >> 32;
|
|
|
|
|
2019-02-26 04:39:44 +01:00
|
|
|
*read_len = 0;
|
|
|
|
|
2019-02-23 02:27:04 +01:00
|
|
|
ret = ReadFile(file, buffer, length, NULL, &ovl);
|
|
|
|
if (ret || GetLastError() == ERROR_IO_PENDING)
|
|
|
|
ret = GetOverlappedResult(file, &ovl, read_len, TRUE);
|
|
|
|
|
|
|
|
TRACE("Returning %u bytes.\n", *read_len);
|
|
|
|
|
|
|
|
CloseHandle(ovl.hEvent);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI FileAsyncReader_SyncReadAligned(IAsyncReader *iface, IMediaSample *sample)
|
2003-08-07 01:00:14 +02:00
|
|
|
{
|
2020-04-02 06:01:00 +02:00
|
|
|
struct async_reader *filter = impl_from_IAsyncReader(iface);
|
2019-02-23 02:27:04 +01:00
|
|
|
REFERENCE_TIME start_time, end_time;
|
|
|
|
DWORD read_len;
|
|
|
|
BYTE *buffer;
|
|
|
|
LONG length;
|
2003-08-07 01:00:14 +02:00
|
|
|
HRESULT hr;
|
2019-02-23 02:27:04 +01:00
|
|
|
BOOL ret;
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2019-02-23 02:27:04 +01:00
|
|
|
TRACE("filter %p, sample %p.\n", filter, sample);
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2019-02-23 02:27:04 +01:00
|
|
|
hr = IMediaSample_GetTime(sample, &start_time, &end_time);
|
2003-08-07 01:00:14 +02:00
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
2019-02-23 02:27:04 +01:00
|
|
|
hr = IMediaSample_GetPointer(sample, &buffer);
|
2003-08-07 01:00:14 +02:00
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
2019-02-23 02:27:04 +01:00
|
|
|
{
|
|
|
|
length = BYTES_FROM_MEDIATIME(end_time - start_time);
|
2019-06-20 03:16:12 +02:00
|
|
|
ret = sync_read(filter->file, BYTES_FROM_MEDIATIME(start_time), length, buffer, &read_len);
|
2019-02-23 02:27:04 +01:00
|
|
|
if (ret)
|
|
|
|
hr = (read_len == length) ? S_OK : S_FALSE;
|
|
|
|
else if (GetLastError() == ERROR_HANDLE_EOF)
|
|
|
|
hr = S_OK;
|
|
|
|
else
|
|
|
|
hr = HRESULT_FROM_WIN32(GetLastError());
|
|
|
|
}
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2019-02-26 04:39:44 +01:00
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
IMediaSample_SetActualDataLength(sample, read_len);
|
|
|
|
|
2003-08-07 01:00:14 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2019-02-23 02:27:00 +01:00
|
|
|
static HRESULT WINAPI FileAsyncReader_SyncRead(IAsyncReader *iface,
|
|
|
|
LONGLONG offset, LONG length, BYTE *buffer)
|
2003-08-07 01:00:14 +02:00
|
|
|
{
|
2020-04-02 06:01:00 +02:00
|
|
|
struct async_reader *filter = impl_from_IAsyncReader(iface);
|
2019-02-23 02:27:00 +01:00
|
|
|
DWORD read_len;
|
|
|
|
HRESULT hr;
|
|
|
|
BOOL ret;
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2019-02-23 02:27:00 +01:00
|
|
|
TRACE("filter %p, offset %s, length %d, buffer %p.\n",
|
|
|
|
filter, wine_dbgstr_longlong(offset), length, buffer);
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2019-06-20 03:16:12 +02:00
|
|
|
ret = sync_read(filter->file, offset, length, buffer, &read_len);
|
2019-02-23 02:27:04 +01:00
|
|
|
if (ret)
|
|
|
|
hr = (read_len == length) ? S_OK : S_FALSE;
|
2019-02-23 02:27:00 +01:00
|
|
|
else if (GetLastError() == ERROR_HANDLE_EOF)
|
|
|
|
hr = S_FALSE;
|
|
|
|
else
|
|
|
|
hr = HRESULT_FROM_WIN32(GetLastError());
|
2003-08-07 01:00:14 +02:00
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2019-06-20 03:16:12 +02:00
|
|
|
static HRESULT WINAPI FileAsyncReader_Length(IAsyncReader *iface, LONGLONG *total, LONGLONG *available)
|
2003-08-07 01:00:14 +02:00
|
|
|
{
|
2020-04-02 06:01:00 +02:00
|
|
|
struct async_reader *filter = impl_from_IAsyncReader(iface);
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2019-06-20 03:16:12 +02:00
|
|
|
TRACE("iface %p, total %p, available %p.\n", iface, total, available);
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2020-04-20 02:53:20 +02:00
|
|
|
*available = *total = filter->file_size.QuadPart;
|
2003-08-07 01:00:14 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI FileAsyncReader_BeginFlush(IAsyncReader * iface)
|
|
|
|
{
|
2020-04-02 06:01:00 +02:00
|
|
|
struct async_reader *filter = impl_from_IAsyncReader(iface);
|
2020-01-30 02:56:59 +01:00
|
|
|
unsigned int i;
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2019-06-20 03:16:12 +02:00
|
|
|
TRACE("iface %p.\n", iface);
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2019-06-20 03:16:12 +02:00
|
|
|
EnterCriticalSection(&filter->sample_cs);
|
|
|
|
|
|
|
|
filter->flushing = TRUE;
|
2020-01-30 02:56:59 +01:00
|
|
|
for (i = 0; i < filter->max_requests; ++i)
|
|
|
|
filter->requests[i].sample = NULL;
|
2019-06-20 03:16:13 +02:00
|
|
|
CancelIoEx(filter->file, NULL);
|
2020-01-30 02:56:59 +01:00
|
|
|
WakeAllConditionVariable(&filter->sample_cv);
|
2019-06-20 03:16:12 +02:00
|
|
|
|
|
|
|
LeaveCriticalSection(&filter->sample_cs);
|
2003-08-07 01:00:14 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI FileAsyncReader_EndFlush(IAsyncReader * iface)
|
|
|
|
{
|
2020-04-02 06:01:00 +02:00
|
|
|
struct async_reader *filter = impl_from_IAsyncReader(iface);
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2019-06-20 03:16:12 +02:00
|
|
|
TRACE("iface %p.\n", iface);
|
|
|
|
|
|
|
|
EnterCriticalSection(&filter->sample_cs);
|
2003-08-07 01:00:14 +02:00
|
|
|
|
2019-06-20 03:16:12 +02:00
|
|
|
filter->flushing = FALSE;
|
2008-04-30 23:27:51 +02:00
|
|
|
|
2019-06-20 03:16:12 +02:00
|
|
|
LeaveCriticalSection(&filter->sample_cs);
|
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,
|
|
|
|
};
|