2014-12-11 00:51:07 +01:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Copyright 2014 Austin English
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
2017-07-06 04:38:10 +02:00
|
|
|
#define COBJMACROS
|
2019-03-13 07:29:35 +01:00
|
|
|
#define NONAMELESSUNION
|
2017-07-06 04:38:10 +02:00
|
|
|
|
2014-12-11 00:51:07 +01:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
2019-01-31 08:53:50 +01:00
|
|
|
#include "ole2.h"
|
|
|
|
#include "rpcproxy.h"
|
2019-03-11 11:28:07 +01:00
|
|
|
|
|
|
|
#undef INITGUID
|
|
|
|
#include <guiddef.h>
|
2019-03-19 09:17:34 +01:00
|
|
|
#include "mfapi.h"
|
|
|
|
#include "mferror.h"
|
2019-02-22 08:36:49 +01:00
|
|
|
#include "mfidl.h"
|
2019-02-25 09:33:55 +01:00
|
|
|
#include "mfreadwrite.h"
|
2017-02-23 08:17:24 +01:00
|
|
|
|
|
|
|
#include "wine/debug.h"
|
2019-02-22 08:36:49 +01:00
|
|
|
#include "wine/heap.h"
|
2017-02-23 08:17:24 +01:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(mfplat);
|
2014-12-11 00:51:07 +01:00
|
|
|
|
2019-01-31 08:53:50 +01:00
|
|
|
static HINSTANCE mfinstance;
|
|
|
|
|
2014-12-11 00:51:07 +01:00
|
|
|
BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved)
|
|
|
|
{
|
|
|
|
switch (reason)
|
|
|
|
{
|
|
|
|
case DLL_WINE_PREATTACH:
|
|
|
|
return FALSE; /* prefer native version */
|
|
|
|
case DLL_PROCESS_ATTACH:
|
2019-01-31 08:53:50 +01:00
|
|
|
mfinstance = instance;
|
2014-12-11 00:51:07 +01:00
|
|
|
DisableThreadLibraryCalls(instance);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2017-02-23 08:17:24 +01:00
|
|
|
|
2019-01-31 08:53:49 +01:00
|
|
|
HRESULT WINAPI DllCanUnloadNow(void)
|
|
|
|
{
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
|
|
|
|
2019-01-31 08:53:50 +01:00
|
|
|
HRESULT WINAPI DllRegisterServer(void)
|
|
|
|
{
|
|
|
|
return __wine_register_resources( mfinstance );
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI DllUnregisterServer(void)
|
|
|
|
{
|
|
|
|
return __wine_unregister_resources( mfinstance );
|
|
|
|
}
|
|
|
|
|
2019-04-01 12:24:04 +02:00
|
|
|
struct media_stream
|
|
|
|
{
|
|
|
|
IMFMediaType *current;
|
|
|
|
};
|
|
|
|
|
2019-03-13 07:29:34 +01:00
|
|
|
typedef struct source_reader
|
2017-07-06 04:38:10 +02:00
|
|
|
{
|
|
|
|
IMFSourceReader IMFSourceReader_iface;
|
2019-03-19 09:17:30 +01:00
|
|
|
IMFAsyncCallback source_events_callback;
|
2019-03-13 07:29:34 +01:00
|
|
|
LONG refcount;
|
|
|
|
IMFMediaSource *source;
|
2019-03-18 11:01:01 +01:00
|
|
|
IMFPresentationDescriptor *descriptor;
|
2019-03-19 09:17:34 +01:00
|
|
|
DWORD first_audio_stream_index;
|
|
|
|
DWORD first_video_stream_index;
|
2019-03-20 06:35:39 +01:00
|
|
|
IMFSourceReaderCallback *async_callback;
|
2019-03-20 06:35:40 +01:00
|
|
|
BOOL shutdown_on_release;
|
2019-04-01 12:24:04 +02:00
|
|
|
struct media_stream *streams;
|
|
|
|
DWORD stream_count;
|
|
|
|
CRITICAL_SECTION cs;
|
2017-07-06 04:38:10 +02:00
|
|
|
} srcreader;
|
|
|
|
|
2019-02-25 09:33:55 +01:00
|
|
|
struct sink_writer
|
|
|
|
{
|
|
|
|
IMFSinkWriter IMFSinkWriter_iface;
|
|
|
|
LONG refcount;
|
|
|
|
};
|
|
|
|
|
2017-07-06 04:38:10 +02:00
|
|
|
static inline srcreader *impl_from_IMFSourceReader(IMFSourceReader *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, srcreader, IMFSourceReader_iface);
|
|
|
|
}
|
|
|
|
|
2019-03-19 09:17:30 +01:00
|
|
|
static struct source_reader *impl_from_source_callback_IMFAsyncCallback(IMFAsyncCallback *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, struct source_reader, source_events_callback);
|
|
|
|
}
|
|
|
|
|
2019-02-25 09:33:55 +01:00
|
|
|
static inline struct sink_writer *impl_from_IMFSinkWriter(IMFSinkWriter *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, struct sink_writer, IMFSinkWriter_iface);
|
|
|
|
}
|
|
|
|
|
2019-03-19 09:17:30 +01:00
|
|
|
static HRESULT WINAPI source_reader_source_events_callback_QueryInterface(IMFAsyncCallback *iface,
|
|
|
|
REFIID riid, void **obj)
|
|
|
|
{
|
|
|
|
TRACE("%p, %s, %p.\n", iface, debugstr_guid(riid), obj);
|
|
|
|
|
|
|
|
if (IsEqualIID(riid, &IID_IMFAsyncCallback) ||
|
|
|
|
IsEqualIID(riid, &IID_IUnknown))
|
|
|
|
{
|
|
|
|
*obj = iface;
|
|
|
|
IMFAsyncCallback_AddRef(iface);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN("Unsupported %s.\n", debugstr_guid(riid));
|
|
|
|
*obj = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI source_reader_source_events_callback_AddRef(IMFAsyncCallback *iface)
|
|
|
|
{
|
|
|
|
struct source_reader *reader = impl_from_source_callback_IMFAsyncCallback(iface);
|
|
|
|
return IMFSourceReader_AddRef(&reader->IMFSourceReader_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI source_reader_source_events_callback_Release(IMFAsyncCallback *iface)
|
|
|
|
{
|
|
|
|
struct source_reader *reader = impl_from_source_callback_IMFAsyncCallback(iface);
|
|
|
|
return IMFSourceReader_Release(&reader->IMFSourceReader_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI source_reader_source_events_callback_GetParameters(IMFAsyncCallback *iface,
|
|
|
|
DWORD *flags, DWORD *queue)
|
|
|
|
{
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI source_reader_source_events_callback_Invoke(IMFAsyncCallback *iface, IMFAsyncResult *result)
|
|
|
|
{
|
|
|
|
struct source_reader *reader = impl_from_source_callback_IMFAsyncCallback(iface);
|
|
|
|
MediaEventType event_type;
|
|
|
|
IMFMediaSource *source;
|
|
|
|
IMFMediaEvent *event;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("%p, %p.\n", iface, result);
|
|
|
|
|
|
|
|
source = (IMFMediaSource *)IMFAsyncResult_GetStateNoAddRef(result);
|
|
|
|
|
|
|
|
if (FAILED(hr = IMFMediaSource_EndGetEvent(source, result, &event)))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
IMFMediaEvent_GetType(event, &event_type);
|
|
|
|
|
|
|
|
TRACE("Got event %u.\n", event_type);
|
|
|
|
|
|
|
|
IMFMediaEvent_Release(event);
|
|
|
|
|
|
|
|
IMFMediaSource_BeginGetEvent(source, &reader->source_events_callback,
|
|
|
|
(IUnknown *)source);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IMFAsyncCallbackVtbl source_events_callback_vtbl =
|
|
|
|
{
|
|
|
|
source_reader_source_events_callback_QueryInterface,
|
|
|
|
source_reader_source_events_callback_AddRef,
|
|
|
|
source_reader_source_events_callback_Release,
|
|
|
|
source_reader_source_events_callback_GetParameters,
|
|
|
|
source_reader_source_events_callback_Invoke,
|
|
|
|
};
|
|
|
|
|
2017-07-06 04:38:10 +02:00
|
|
|
static HRESULT WINAPI src_reader_QueryInterface(IMFSourceReader *iface, REFIID riid, void **out)
|
|
|
|
{
|
|
|
|
srcreader *This = impl_from_IMFSourceReader(iface);
|
|
|
|
|
|
|
|
TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), out);
|
|
|
|
|
|
|
|
if(IsEqualGUID(riid, &IID_IUnknown) ||
|
|
|
|
IsEqualGUID(riid, &IID_IMFSourceReader))
|
|
|
|
{
|
|
|
|
*out = &This->IMFSourceReader_iface;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FIXME("(%s, %p)\n", debugstr_guid(riid), out);
|
|
|
|
*out = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
IUnknown_AddRef((IUnknown*)*out);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI src_reader_AddRef(IMFSourceReader *iface)
|
|
|
|
{
|
|
|
|
srcreader *This = impl_from_IMFSourceReader(iface);
|
2019-03-13 07:29:34 +01:00
|
|
|
ULONG ref = InterlockedIncrement(&This->refcount);
|
2017-07-06 04:38:10 +02:00
|
|
|
|
|
|
|
TRACE("(%p) ref=%u\n", This, ref);
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI src_reader_Release(IMFSourceReader *iface)
|
|
|
|
{
|
2019-03-13 07:29:34 +01:00
|
|
|
struct source_reader *reader = impl_from_IMFSourceReader(iface);
|
|
|
|
ULONG refcount = InterlockedDecrement(&reader->refcount);
|
2019-04-01 12:24:04 +02:00
|
|
|
unsigned int i;
|
2017-07-06 04:38:10 +02:00
|
|
|
|
2019-03-13 07:29:34 +01:00
|
|
|
TRACE("%p, refcount %d.\n", iface, refcount);
|
2017-07-06 04:38:10 +02:00
|
|
|
|
2019-03-13 07:29:34 +01:00
|
|
|
if (!refcount)
|
2017-07-06 04:38:10 +02:00
|
|
|
{
|
2019-03-20 06:35:39 +01:00
|
|
|
if (reader->async_callback)
|
|
|
|
IMFSourceReaderCallback_Release(reader->async_callback);
|
2019-03-20 06:35:40 +01:00
|
|
|
if (reader->shutdown_on_release)
|
|
|
|
IMFMediaSource_Shutdown(reader->source);
|
2019-03-18 11:01:01 +01:00
|
|
|
if (reader->descriptor)
|
|
|
|
IMFPresentationDescriptor_Release(reader->descriptor);
|
2019-03-13 07:29:34 +01:00
|
|
|
IMFMediaSource_Release(reader->source);
|
2019-04-01 12:24:04 +02:00
|
|
|
|
|
|
|
for (i = 0; i < reader->stream_count; ++i)
|
|
|
|
{
|
|
|
|
if (reader->streams[i].current)
|
|
|
|
IMFMediaType_Release(reader->streams[i].current);
|
|
|
|
}
|
|
|
|
heap_free(reader->streams);
|
|
|
|
DeleteCriticalSection(&reader->cs);
|
2019-03-13 07:29:34 +01:00
|
|
|
heap_free(reader);
|
2017-07-06 04:38:10 +02:00
|
|
|
}
|
|
|
|
|
2019-03-13 07:29:34 +01:00
|
|
|
return refcount;
|
2017-07-06 04:38:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI src_reader_GetStreamSelection(IMFSourceReader *iface, DWORD index, BOOL *selected)
|
|
|
|
{
|
2019-03-19 09:17:35 +01:00
|
|
|
struct source_reader *reader = impl_from_IMFSourceReader(iface);
|
|
|
|
IMFStreamDescriptor *sd;
|
|
|
|
|
|
|
|
TRACE("%p, %#x, %p.\n", iface, index, selected);
|
|
|
|
|
|
|
|
switch (index)
|
|
|
|
{
|
|
|
|
case MF_SOURCE_READER_FIRST_VIDEO_STREAM:
|
|
|
|
index = reader->first_video_stream_index;
|
|
|
|
break;
|
|
|
|
case MF_SOURCE_READER_FIRST_AUDIO_STREAM:
|
|
|
|
index = reader->first_audio_stream_index;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FAILED(IMFPresentationDescriptor_GetStreamDescriptorByIndex(reader->descriptor, index, selected, &sd)))
|
|
|
|
return MF_E_INVALIDSTREAMNUMBER;
|
|
|
|
IMFStreamDescriptor_Release(sd);
|
|
|
|
|
|
|
|
return S_OK;
|
2017-07-06 04:38:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI src_reader_SetStreamSelection(IMFSourceReader *iface, DWORD index, BOOL selected)
|
|
|
|
{
|
2019-03-19 09:17:35 +01:00
|
|
|
struct source_reader *reader = impl_from_IMFSourceReader(iface);
|
|
|
|
unsigned int count;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("%p, %#x, %d.\n", iface, index, selected);
|
|
|
|
|
|
|
|
switch (index)
|
|
|
|
{
|
|
|
|
case MF_SOURCE_READER_FIRST_VIDEO_STREAM:
|
|
|
|
index = reader->first_video_stream_index;
|
|
|
|
break;
|
|
|
|
case MF_SOURCE_READER_FIRST_AUDIO_STREAM:
|
|
|
|
index = reader->first_audio_stream_index;
|
|
|
|
break;
|
|
|
|
case MF_SOURCE_READER_ALL_STREAMS:
|
|
|
|
if (FAILED(hr = IMFPresentationDescriptor_GetStreamDescriptorCount(reader->descriptor, &count)))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
for (index = 0; index < count; ++index)
|
|
|
|
{
|
|
|
|
if (selected)
|
|
|
|
IMFPresentationDescriptor_SelectStream(reader->descriptor, index);
|
|
|
|
else
|
|
|
|
IMFPresentationDescriptor_DeselectStream(reader->descriptor, index);
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
default:
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (selected)
|
|
|
|
hr = IMFPresentationDescriptor_SelectStream(reader->descriptor, index);
|
|
|
|
else
|
|
|
|
hr = IMFPresentationDescriptor_DeselectStream(reader->descriptor, index);
|
|
|
|
|
|
|
|
if (FAILED(hr))
|
|
|
|
return MF_E_INVALIDSTREAMNUMBER;
|
|
|
|
|
|
|
|
return S_OK;
|
2017-07-06 04:38:10 +02:00
|
|
|
}
|
|
|
|
|
2019-03-19 09:17:36 +01:00
|
|
|
static HRESULT WINAPI src_reader_GetNativeMediaType(IMFSourceReader *iface, DWORD index, DWORD type_index,
|
2017-07-06 04:38:10 +02:00
|
|
|
IMFMediaType **type)
|
|
|
|
{
|
2019-03-19 09:17:36 +01:00
|
|
|
struct source_reader *reader = impl_from_IMFSourceReader(iface);
|
|
|
|
IMFMediaTypeHandler *handler;
|
|
|
|
IMFStreamDescriptor *sd;
|
|
|
|
BOOL selected;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("%p, %#x, %#x, %p.\n", iface, index, type_index, type);
|
|
|
|
|
|
|
|
switch (index)
|
|
|
|
{
|
|
|
|
case MF_SOURCE_READER_FIRST_VIDEO_STREAM:
|
|
|
|
index = reader->first_video_stream_index;
|
|
|
|
break;
|
|
|
|
case MF_SOURCE_READER_FIRST_AUDIO_STREAM:
|
|
|
|
index = reader->first_audio_stream_index;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FAILED(IMFPresentationDescriptor_GetStreamDescriptorByIndex(reader->descriptor, index, &selected, &sd)))
|
|
|
|
return MF_E_INVALIDSTREAMNUMBER;
|
|
|
|
|
|
|
|
hr = IMFStreamDescriptor_GetMediaTypeHandler(sd, &handler);
|
|
|
|
IMFStreamDescriptor_Release(sd);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
if (type_index == MF_SOURCE_READER_CURRENT_TYPE_INDEX)
|
|
|
|
hr = IMFMediaTypeHandler_GetCurrentMediaType(handler, type);
|
|
|
|
else
|
|
|
|
hr = IMFMediaTypeHandler_GetMediaTypeByIndex(handler, type_index, type);
|
|
|
|
IMFMediaTypeHandler_Release(handler);
|
|
|
|
|
|
|
|
return hr;
|
2017-07-06 04:38:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI src_reader_GetCurrentMediaType(IMFSourceReader *iface, DWORD index, IMFMediaType **type)
|
|
|
|
{
|
2019-04-01 12:24:04 +02:00
|
|
|
struct source_reader *reader = impl_from_IMFSourceReader(iface);
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("%p, %#x, %p.\n", iface, index, type);
|
|
|
|
|
|
|
|
switch (index)
|
|
|
|
{
|
|
|
|
case MF_SOURCE_READER_FIRST_VIDEO_STREAM:
|
|
|
|
index = reader->first_video_stream_index;
|
|
|
|
break;
|
|
|
|
case MF_SOURCE_READER_FIRST_AUDIO_STREAM:
|
|
|
|
index = reader->first_audio_stream_index;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (index >= reader->stream_count)
|
|
|
|
return MF_E_INVALIDSTREAMNUMBER;
|
|
|
|
|
|
|
|
if (FAILED(hr = MFCreateMediaType(type)))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
EnterCriticalSection(&reader->cs);
|
|
|
|
|
|
|
|
hr = IMFMediaType_CopyAllItems(reader->streams[index].current, (IMFAttributes *)*type);
|
|
|
|
|
|
|
|
LeaveCriticalSection(&reader->cs);
|
|
|
|
|
|
|
|
return hr;
|
2017-07-06 04:38:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI src_reader_SetCurrentMediaType(IMFSourceReader *iface, DWORD index, DWORD *reserved,
|
|
|
|
IMFMediaType *type)
|
|
|
|
{
|
2019-04-01 12:24:04 +02:00
|
|
|
struct source_reader *reader = impl_from_IMFSourceReader(iface);
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("%p, %#x, %p, %p.\n", iface, index, reserved, type);
|
|
|
|
|
|
|
|
switch (index)
|
|
|
|
{
|
|
|
|
case MF_SOURCE_READER_FIRST_VIDEO_STREAM:
|
|
|
|
index = reader->first_video_stream_index;
|
|
|
|
break;
|
|
|
|
case MF_SOURCE_READER_FIRST_AUDIO_STREAM:
|
|
|
|
index = reader->first_audio_stream_index;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (index >= reader->stream_count)
|
|
|
|
return MF_E_INVALIDSTREAMNUMBER;
|
|
|
|
|
|
|
|
/* FIXME: validate passed type and current presentation state. */
|
|
|
|
|
|
|
|
EnterCriticalSection(&reader->cs);
|
|
|
|
|
|
|
|
hr = IMFMediaType_CopyAllItems(type, (IMFAttributes *)reader->streams[index].current);
|
|
|
|
|
|
|
|
LeaveCriticalSection(&reader->cs);
|
|
|
|
|
|
|
|
return hr;
|
2017-07-06 04:38:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI src_reader_SetCurrentPosition(IMFSourceReader *iface, REFGUID format, REFPROPVARIANT position)
|
|
|
|
{
|
2019-03-20 06:35:43 +01:00
|
|
|
struct source_reader *reader = impl_from_IMFSourceReader(iface);
|
|
|
|
DWORD flags;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("%p, %s, %p.\n", iface, debugstr_guid(format), position);
|
|
|
|
|
|
|
|
/* FIXME: fail if we got pending samples. */
|
|
|
|
|
|
|
|
if (FAILED(hr = IMFMediaSource_GetCharacteristics(reader->source, &flags)))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
if (!(flags & MFMEDIASOURCE_CAN_SEEK))
|
|
|
|
return MF_E_INVALIDREQUEST;
|
|
|
|
|
|
|
|
return IMFMediaSource_Start(reader->source, reader->descriptor, format, position);
|
2017-07-06 04:38:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI src_reader_ReadSample(IMFSourceReader *iface, DWORD index,
|
|
|
|
DWORD flags, DWORD *actualindex, DWORD *sampleflags, LONGLONG *timestamp,
|
|
|
|
IMFSample **sample)
|
|
|
|
{
|
|
|
|
srcreader *This = impl_from_IMFSourceReader(iface);
|
|
|
|
FIXME("%p, 0x%08x, 0x%08x, %p, %p, %p, %p\n", This, index, flags, actualindex,
|
|
|
|
sampleflags, timestamp, sample);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI src_reader_Flush(IMFSourceReader *iface, DWORD index)
|
|
|
|
{
|
|
|
|
srcreader *This = impl_from_IMFSourceReader(iface);
|
|
|
|
FIXME("%p, 0x%08x\n", This, index);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI src_reader_GetServiceForStream(IMFSourceReader *iface, DWORD index, REFGUID service,
|
|
|
|
REFIID riid, void **object)
|
|
|
|
{
|
2019-03-19 09:17:33 +01:00
|
|
|
struct source_reader *reader = impl_from_IMFSourceReader(iface);
|
|
|
|
IUnknown *obj = NULL;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("%p, %#x, %s, %s, %p\n", iface, index, debugstr_guid(service), debugstr_guid(riid), object);
|
|
|
|
|
|
|
|
switch (index)
|
|
|
|
{
|
|
|
|
case MF_SOURCE_READER_MEDIASOURCE:
|
|
|
|
obj = (IUnknown *)reader->source;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FIXME("Unsupported index %#x.\n", index);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsEqualGUID(service, &GUID_NULL))
|
|
|
|
{
|
|
|
|
hr = IUnknown_QueryInterface(obj, riid, object);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
IMFGetService *gs;
|
|
|
|
|
|
|
|
hr = IUnknown_QueryInterface(obj, &IID_IMFGetService, (void **)&gs);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
hr = IMFGetService_GetService(gs, service, riid, object);
|
|
|
|
IMFGetService_Release(gs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
2017-07-06 04:38:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI src_reader_GetPresentationAttribute(IMFSourceReader *iface, DWORD index,
|
2019-03-13 07:29:35 +01:00
|
|
|
REFGUID guid, PROPVARIANT *value)
|
2017-07-06 04:38:10 +02:00
|
|
|
{
|
2019-03-13 07:29:35 +01:00
|
|
|
struct source_reader *reader = impl_from_IMFSourceReader(iface);
|
2019-03-20 06:35:42 +01:00
|
|
|
IMFStreamDescriptor *sd;
|
|
|
|
BOOL selected;
|
2019-03-13 07:29:35 +01:00
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("%p, %#x, %s, %p.\n", iface, index, debugstr_guid(guid), value);
|
|
|
|
|
|
|
|
switch (index)
|
|
|
|
{
|
|
|
|
case MF_SOURCE_READER_MEDIASOURCE:
|
|
|
|
if (IsEqualGUID(guid, &MF_SOURCE_READER_MEDIASOURCE_CHARACTERISTICS))
|
|
|
|
{
|
|
|
|
DWORD flags;
|
|
|
|
|
|
|
|
if (FAILED(hr = IMFMediaSource_GetCharacteristics(reader->source, &flags)))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
value->vt = VT_UI4;
|
|
|
|
value->u.ulVal = flags;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-03-19 09:17:32 +01:00
|
|
|
return IMFPresentationDescriptor_GetItem(reader->descriptor, guid, value);
|
2019-03-13 07:29:35 +01:00
|
|
|
}
|
|
|
|
break;
|
2019-03-20 06:35:42 +01:00
|
|
|
case MF_SOURCE_READER_FIRST_VIDEO_STREAM:
|
|
|
|
index = reader->first_video_stream_index;
|
|
|
|
break;
|
|
|
|
case MF_SOURCE_READER_FIRST_AUDIO_STREAM:
|
|
|
|
index = reader->first_audio_stream_index;
|
|
|
|
break;
|
2019-03-13 07:29:35 +01:00
|
|
|
default:
|
2019-03-20 06:35:42 +01:00
|
|
|
;
|
2019-03-13 07:29:35 +01:00
|
|
|
}
|
|
|
|
|
2019-03-20 06:35:42 +01:00
|
|
|
if (FAILED(hr = IMFPresentationDescriptor_GetStreamDescriptorByIndex(reader->descriptor, index, &selected, &sd)))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
hr = IMFStreamDescriptor_GetItem(sd, guid, value);
|
|
|
|
IMFStreamDescriptor_Release(sd);
|
|
|
|
|
|
|
|
return hr;
|
2017-07-06 04:38:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
struct IMFSourceReaderVtbl srcreader_vtbl =
|
|
|
|
{
|
|
|
|
src_reader_QueryInterface,
|
|
|
|
src_reader_AddRef,
|
|
|
|
src_reader_Release,
|
|
|
|
src_reader_GetStreamSelection,
|
|
|
|
src_reader_SetStreamSelection,
|
|
|
|
src_reader_GetNativeMediaType,
|
|
|
|
src_reader_GetCurrentMediaType,
|
|
|
|
src_reader_SetCurrentMediaType,
|
|
|
|
src_reader_SetCurrentPosition,
|
|
|
|
src_reader_ReadSample,
|
|
|
|
src_reader_Flush,
|
|
|
|
src_reader_GetServiceForStream,
|
|
|
|
src_reader_GetPresentationAttribute
|
|
|
|
};
|
|
|
|
|
2019-03-19 09:17:34 +01:00
|
|
|
static DWORD reader_get_first_stream_index(IMFPresentationDescriptor *descriptor, const GUID *major)
|
|
|
|
{
|
|
|
|
unsigned int count, i;
|
|
|
|
BOOL selected;
|
|
|
|
HRESULT hr;
|
|
|
|
GUID guid;
|
|
|
|
|
|
|
|
if (FAILED(IMFPresentationDescriptor_GetStreamDescriptorCount(descriptor, &count)))
|
|
|
|
return MF_SOURCE_READER_INVALID_STREAM_INDEX;
|
|
|
|
|
|
|
|
for (i = 0; i < count; ++i)
|
|
|
|
{
|
|
|
|
IMFMediaTypeHandler *handler;
|
|
|
|
IMFStreamDescriptor *sd;
|
|
|
|
|
|
|
|
if (SUCCEEDED(IMFPresentationDescriptor_GetStreamDescriptorByIndex(descriptor, i, &selected, &sd)))
|
|
|
|
{
|
|
|
|
hr = IMFStreamDescriptor_GetMediaTypeHandler(sd, &handler);
|
|
|
|
IMFStreamDescriptor_Release(sd);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
hr = IMFMediaTypeHandler_GetMajorType(handler, &guid);
|
|
|
|
IMFMediaTypeHandler_Release(handler);
|
|
|
|
if (SUCCEEDED(hr) && IsEqualGUID(&guid, major))
|
|
|
|
{
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return MF_SOURCE_READER_INVALID_STREAM_INDEX;
|
|
|
|
}
|
|
|
|
|
2019-02-22 08:36:49 +01:00
|
|
|
static HRESULT create_source_reader_from_source(IMFMediaSource *source, IMFAttributes *attributes,
|
2019-03-20 06:35:40 +01:00
|
|
|
BOOL shutdown_on_release, REFIID riid, void **out)
|
2017-07-06 04:38:10 +02:00
|
|
|
{
|
2019-04-01 12:24:04 +02:00
|
|
|
struct source_reader *object;
|
|
|
|
unsigned int i;
|
2019-02-22 08:36:49 +01:00
|
|
|
HRESULT hr;
|
2017-07-06 04:38:10 +02:00
|
|
|
|
2019-03-19 09:17:30 +01:00
|
|
|
object = heap_alloc_zero(sizeof(*object));
|
2019-02-22 08:36:49 +01:00
|
|
|
if (!object)
|
2017-07-06 04:38:10 +02:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
object->IMFSourceReader_iface.lpVtbl = &srcreader_vtbl;
|
2019-03-19 09:17:30 +01:00
|
|
|
object->source_events_callback.lpVtbl = &source_events_callback_vtbl;
|
2019-03-13 07:29:34 +01:00
|
|
|
object->refcount = 1;
|
|
|
|
object->source = source;
|
|
|
|
IMFMediaSource_AddRef(object->source);
|
2019-04-01 12:24:04 +02:00
|
|
|
InitializeCriticalSection(&object->cs);
|
2017-07-06 04:38:10 +02:00
|
|
|
|
2019-03-18 11:01:01 +01:00
|
|
|
if (FAILED(hr = IMFMediaSource_CreatePresentationDescriptor(object->source, &object->descriptor)))
|
|
|
|
goto failed;
|
|
|
|
|
2019-04-01 12:24:04 +02:00
|
|
|
if (FAILED(hr = IMFPresentationDescriptor_GetStreamDescriptorCount(object->descriptor, &object->stream_count)))
|
|
|
|
goto failed;
|
|
|
|
|
|
|
|
if (!(object->streams = heap_alloc_zero(object->stream_count * sizeof(*object->streams))))
|
|
|
|
{
|
|
|
|
hr = E_OUTOFMEMORY;
|
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set initial current media types. */
|
|
|
|
for (i = 0; i < object->stream_count; ++i)
|
|
|
|
{
|
|
|
|
IMFMediaTypeHandler *handler;
|
|
|
|
IMFStreamDescriptor *sd;
|
|
|
|
IMFMediaType *src_type;
|
|
|
|
BOOL selected;
|
|
|
|
|
|
|
|
if (FAILED(hr = MFCreateMediaType(&object->streams[i].current)))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (FAILED(hr = IMFPresentationDescriptor_GetStreamDescriptorByIndex(object->descriptor, i, &selected, &sd)))
|
|
|
|
break;
|
|
|
|
|
|
|
|
hr = IMFStreamDescriptor_GetMediaTypeHandler(sd, &handler);
|
|
|
|
IMFStreamDescriptor_Release(sd);
|
|
|
|
if (FAILED(hr))
|
|
|
|
break;
|
|
|
|
|
|
|
|
hr = IMFMediaTypeHandler_GetMediaTypeByIndex(handler, 0, &src_type);
|
|
|
|
IMFMediaTypeHandler_Release(handler);
|
|
|
|
if (FAILED(hr))
|
|
|
|
break;
|
|
|
|
|
|
|
|
hr = IMFMediaType_CopyAllItems(src_type, (IMFAttributes *)object->streams[i].current);
|
|
|
|
IMFMediaType_Release(src_type);
|
|
|
|
if (FAILED(hr))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FAILED(hr))
|
|
|
|
goto failed;
|
|
|
|
|
2019-03-19 09:17:34 +01:00
|
|
|
/* At least one major type has to be set. */
|
|
|
|
object->first_audio_stream_index = reader_get_first_stream_index(object->descriptor, &MFMediaType_Audio);
|
|
|
|
object->first_video_stream_index = reader_get_first_stream_index(object->descriptor, &MFMediaType_Video);
|
|
|
|
|
|
|
|
if (object->first_audio_stream_index == MF_SOURCE_READER_INVALID_STREAM_INDEX &&
|
|
|
|
object->first_video_stream_index == MF_SOURCE_READER_INVALID_STREAM_INDEX)
|
|
|
|
{
|
|
|
|
hr = MF_E_ATTRIBUTENOTFOUND;
|
|
|
|
}
|
|
|
|
|
2019-03-19 09:17:30 +01:00
|
|
|
if (FAILED(hr = IMFMediaSource_BeginGetEvent(object->source, &object->source_events_callback,
|
|
|
|
(IUnknown *)object->source)))
|
|
|
|
{
|
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
|
2019-03-20 06:35:39 +01:00
|
|
|
if (attributes)
|
2019-04-01 12:24:05 +02:00
|
|
|
{
|
2019-03-20 06:35:39 +01:00
|
|
|
IMFAttributes_GetUnknown(attributes, &MF_SOURCE_READER_ASYNC_CALLBACK, &IID_IMFSourceReaderCallback,
|
|
|
|
(void **)&object->async_callback);
|
2019-04-01 12:24:05 +02:00
|
|
|
if (object->async_callback)
|
|
|
|
TRACE("Using async callback %p.\n", object->async_callback);
|
|
|
|
}
|
2019-03-20 06:35:39 +01:00
|
|
|
|
2019-02-22 08:36:49 +01:00
|
|
|
hr = IMFSourceReader_QueryInterface(&object->IMFSourceReader_iface, riid, out);
|
2019-03-18 11:01:01 +01:00
|
|
|
|
|
|
|
failed:
|
2019-02-22 08:36:49 +01:00
|
|
|
IMFSourceReader_Release(&object->IMFSourceReader_iface);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2019-03-25 08:45:17 +01:00
|
|
|
static HRESULT bytestream_get_url_hint(IMFByteStream *stream, WCHAR const **url)
|
|
|
|
{
|
|
|
|
static const UINT8 asfmagic[] = {0x30,0x26,0xb2,0x75,0x8e,0x66,0xcf,0x11,0xa6,0xd9,0x00,0xaa,0x00,0x62,0xce,0x6c};
|
|
|
|
static const WCHAR asfW[] = {'.','a','s','f',0};
|
|
|
|
static const struct stream_content_url_hint
|
|
|
|
{
|
|
|
|
const UINT8 *magic;
|
|
|
|
UINT32 magic_len;
|
|
|
|
const WCHAR *url;
|
|
|
|
}
|
|
|
|
url_hints[] =
|
|
|
|
{
|
|
|
|
{ asfmagic, sizeof(asfmagic), asfW },
|
|
|
|
};
|
|
|
|
IMFAttributes *attributes;
|
|
|
|
UINT32 length = 0;
|
|
|
|
UINT8 buffer[16];
|
|
|
|
DWORD caps = 0;
|
|
|
|
QWORD position;
|
|
|
|
unsigned int i;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
*url = NULL;
|
|
|
|
|
|
|
|
if (SUCCEEDED(IMFByteStream_QueryInterface(stream, &IID_IMFAttributes, (void **)&attributes)))
|
|
|
|
{
|
|
|
|
IMFAttributes_GetStringLength(attributes, &MF_BYTESTREAM_CONTENT_TYPE, &length);
|
|
|
|
IMFAttributes_Release(attributes);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (length)
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
if (FAILED(hr = IMFByteStream_GetCapabilities(stream, &caps)))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
if (!(caps & MFBYTESTREAM_IS_SEEKABLE))
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
if (FAILED(hr = IMFByteStream_GetCurrentPosition(stream, &position)))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
hr = IMFByteStream_Read(stream, buffer, sizeof(buffer), &length);
|
|
|
|
IMFByteStream_SetCurrentPosition(stream, position);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
if (length < sizeof(buffer))
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(url_hints); ++i)
|
|
|
|
{
|
|
|
|
if (!memcmp(buffer, url_hints[i].magic, min(url_hints[i].magic_len, length)))
|
|
|
|
{
|
|
|
|
*url = url_hints[i].url;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!*url)
|
|
|
|
WARN("Unrecognized content type %s.\n", debugstr_an((char *)buffer, length));
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2019-02-22 08:36:49 +01:00
|
|
|
static HRESULT create_source_reader_from_stream(IMFByteStream *stream, IMFAttributes *attributes,
|
|
|
|
REFIID riid, void **out)
|
|
|
|
{
|
2019-03-20 06:35:38 +01:00
|
|
|
IPropertyStore *props = NULL;
|
2019-03-12 07:07:45 +01:00
|
|
|
IMFSourceResolver *resolver;
|
|
|
|
MF_OBJECT_TYPE obj_type;
|
|
|
|
IMFMediaSource *source;
|
2019-03-25 08:45:17 +01:00
|
|
|
const WCHAR *url;
|
2019-03-12 07:07:45 +01:00
|
|
|
HRESULT hr;
|
|
|
|
|
2019-03-25 08:45:17 +01:00
|
|
|
/* If stream does not have content type set, try to guess from starting byte sequence. */
|
|
|
|
if (FAILED(hr = bytestream_get_url_hint(stream, &url)))
|
|
|
|
return hr;
|
|
|
|
|
2019-03-12 07:07:45 +01:00
|
|
|
if (FAILED(hr = MFCreateSourceResolver(&resolver)))
|
|
|
|
return hr;
|
2019-02-22 08:36:49 +01:00
|
|
|
|
2019-03-20 06:35:38 +01:00
|
|
|
if (attributes)
|
|
|
|
IMFAttributes_GetUnknown(attributes, &MF_SOURCE_READER_MEDIASOURCE_CONFIG, &IID_IPropertyStore,
|
|
|
|
(void **)&props);
|
|
|
|
|
2019-03-25 08:45:17 +01:00
|
|
|
hr = IMFSourceResolver_CreateObjectFromByteStream(resolver, stream, url, MF_RESOLUTION_MEDIASOURCE, props,
|
2019-03-12 07:07:45 +01:00
|
|
|
&obj_type, (IUnknown **)&source);
|
|
|
|
IMFSourceResolver_Release(resolver);
|
2019-03-20 06:35:38 +01:00
|
|
|
if (props)
|
|
|
|
IPropertyStore_Release(props);
|
2019-03-12 07:07:45 +01:00
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
2019-03-20 06:35:40 +01:00
|
|
|
hr = create_source_reader_from_source(source, attributes, TRUE, riid, out);
|
2019-03-12 07:07:45 +01:00
|
|
|
IMFMediaSource_Release(source);
|
|
|
|
return hr;
|
2019-02-22 08:36:49 +01:00
|
|
|
}
|
|
|
|
|
2019-03-12 07:07:46 +01:00
|
|
|
static HRESULT create_source_reader_from_url(const WCHAR *url, IMFAttributes *attributes, REFIID riid, void **out)
|
|
|
|
{
|
2019-03-20 06:35:38 +01:00
|
|
|
IPropertyStore *props = NULL;
|
2019-03-12 07:07:46 +01:00
|
|
|
IMFSourceResolver *resolver;
|
|
|
|
IUnknown *object = NULL;
|
|
|
|
MF_OBJECT_TYPE obj_type;
|
|
|
|
IMFMediaSource *source;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (FAILED(hr = MFCreateSourceResolver(&resolver)))
|
|
|
|
return hr;
|
|
|
|
|
2019-03-20 06:35:38 +01:00
|
|
|
if (attributes)
|
|
|
|
IMFAttributes_GetUnknown(attributes, &MF_SOURCE_READER_MEDIASOURCE_CONFIG, &IID_IPropertyStore,
|
|
|
|
(void **)&props);
|
|
|
|
|
|
|
|
hr = IMFSourceResolver_CreateObjectFromURL(resolver, url, MF_RESOLUTION_MEDIASOURCE, props, &obj_type,
|
2019-03-14 20:39:39 +01:00
|
|
|
&object);
|
2019-03-12 07:07:46 +01:00
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
switch (obj_type)
|
|
|
|
{
|
|
|
|
case MF_OBJECT_BYTESTREAM:
|
|
|
|
hr = IMFSourceResolver_CreateObjectFromByteStream(resolver, (IMFByteStream *)object, NULL,
|
2019-03-20 06:35:38 +01:00
|
|
|
MF_RESOLUTION_MEDIASOURCE, props, &obj_type, (IUnknown **)&source);
|
2019-03-12 07:07:46 +01:00
|
|
|
break;
|
|
|
|
case MF_OBJECT_MEDIASOURCE:
|
|
|
|
source = (IMFMediaSource *)object;
|
|
|
|
IMFMediaSource_AddRef(source);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
WARN("Unknown object type %d.\n", obj_type);
|
|
|
|
hr = E_UNEXPECTED;
|
|
|
|
}
|
|
|
|
IUnknown_Release(object);
|
|
|
|
}
|
|
|
|
|
|
|
|
IMFSourceResolver_Release(resolver);
|
2019-03-20 06:35:38 +01:00
|
|
|
if (props)
|
|
|
|
IPropertyStore_Release(props);
|
2019-03-12 07:07:46 +01:00
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
2019-03-20 06:35:40 +01:00
|
|
|
hr = create_source_reader_from_source(source, attributes, TRUE, riid, out);
|
2019-03-12 07:07:46 +01:00
|
|
|
IMFMediaSource_Release(source);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2019-02-25 09:33:55 +01:00
|
|
|
static HRESULT WINAPI sink_writer_QueryInterface(IMFSinkWriter *iface, REFIID riid, void **out)
|
|
|
|
{
|
|
|
|
TRACE("%p, %s, %p.\n", iface, debugstr_guid(riid), out);
|
|
|
|
|
|
|
|
if (IsEqualIID(riid, &IID_IMFSinkWriter) ||
|
|
|
|
IsEqualIID(riid, &IID_IUnknown))
|
|
|
|
{
|
|
|
|
*out = iface;
|
|
|
|
IMFSinkWriter_AddRef(iface);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN("Unsupported %s.\n", debugstr_guid(riid));
|
|
|
|
*out = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI sink_writer_AddRef(IMFSinkWriter *iface)
|
|
|
|
{
|
|
|
|
struct sink_writer *writer = impl_from_IMFSinkWriter(iface);
|
|
|
|
ULONG refcount = InterlockedIncrement(&writer->refcount);
|
|
|
|
|
|
|
|
TRACE("%p, %u.\n", iface, refcount);
|
|
|
|
|
|
|
|
return refcount;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI sink_writer_Release(IMFSinkWriter *iface)
|
|
|
|
{
|
|
|
|
struct sink_writer *writer = impl_from_IMFSinkWriter(iface);
|
|
|
|
ULONG refcount = InterlockedDecrement(&writer->refcount);
|
|
|
|
|
|
|
|
TRACE("%p, %u.\n", iface, refcount);
|
|
|
|
|
|
|
|
if (!refcount)
|
|
|
|
{
|
|
|
|
heap_free(writer);
|
|
|
|
}
|
|
|
|
|
|
|
|
return refcount;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI sink_writer_AddStream(IMFSinkWriter *iface, IMFMediaType *type, DWORD *index)
|
|
|
|
{
|
|
|
|
FIXME("%p, %p, %p.\n", iface, type, index);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI sink_writer_SetInputMediaType(IMFSinkWriter *iface, DWORD index, IMFMediaType *type,
|
|
|
|
IMFAttributes *parameters)
|
|
|
|
{
|
|
|
|
FIXME("%p, %u, %p, %p.\n", iface, index, type, parameters);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI sink_writer_BeginWriting(IMFSinkWriter *iface)
|
|
|
|
{
|
|
|
|
FIXME("%p.\n", iface);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI sink_writer_WriteSample(IMFSinkWriter *iface, DWORD index, IMFSample *sample)
|
|
|
|
{
|
|
|
|
FIXME("%p, %u, %p.\n", iface, index, sample);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI sink_writer_SendStreamTick(IMFSinkWriter *iface, DWORD index, LONGLONG timestamp)
|
|
|
|
{
|
|
|
|
FIXME("%p, %u, %s.\n", iface, index, wine_dbgstr_longlong(timestamp));
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI sink_writer_PlaceMarker(IMFSinkWriter *iface, DWORD index, void *context)
|
|
|
|
{
|
|
|
|
FIXME("%p, %u, %p.\n", iface, index, context);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI sink_writer_NotifyEndOfSegment(IMFSinkWriter *iface, DWORD index)
|
|
|
|
{
|
|
|
|
FIXME("%p, %u.\n", iface, index);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI sink_writer_Flush(IMFSinkWriter *iface, DWORD index)
|
|
|
|
{
|
|
|
|
FIXME("%p, %u.\n", iface, index);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI sink_writer_Finalize(IMFSinkWriter *iface)
|
|
|
|
{
|
|
|
|
FIXME("%p.\n", iface);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI sink_writer_GetServiceForStream(IMFSinkWriter *iface, DWORD index, REFGUID service,
|
|
|
|
REFIID riid, void **object)
|
|
|
|
{
|
|
|
|
FIXME("%p, %u, %s, %s, %p.\n", iface, index, debugstr_guid(service), debugstr_guid(riid), object);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI sink_writer_GetStatistics(IMFSinkWriter *iface, DWORD index, MF_SINK_WRITER_STATISTICS *stats)
|
|
|
|
{
|
|
|
|
FIXME("%p, %u, %p.\n", iface, index, stats);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IMFSinkWriterVtbl sink_writer_vtbl =
|
|
|
|
{
|
|
|
|
sink_writer_QueryInterface,
|
|
|
|
sink_writer_AddRef,
|
|
|
|
sink_writer_Release,
|
|
|
|
sink_writer_AddStream,
|
|
|
|
sink_writer_SetInputMediaType,
|
|
|
|
sink_writer_BeginWriting,
|
|
|
|
sink_writer_WriteSample,
|
|
|
|
sink_writer_SendStreamTick,
|
|
|
|
sink_writer_PlaceMarker,
|
|
|
|
sink_writer_NotifyEndOfSegment,
|
|
|
|
sink_writer_Flush,
|
|
|
|
sink_writer_Finalize,
|
|
|
|
sink_writer_GetServiceForStream,
|
|
|
|
sink_writer_GetStatistics,
|
|
|
|
};
|
|
|
|
|
|
|
|
static HRESULT create_sink_writer_from_sink(IMFMediaSink *sink, IMFAttributes *attributes,
|
|
|
|
REFIID riid, void **out)
|
|
|
|
{
|
|
|
|
struct sink_writer *object;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
object = heap_alloc(sizeof(*object));
|
|
|
|
if (!object)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
object->IMFSinkWriter_iface.lpVtbl = &sink_writer_vtbl;
|
|
|
|
object->refcount = 1;
|
|
|
|
|
|
|
|
hr = IMFSinkWriter_QueryInterface(&object->IMFSinkWriter_iface, riid, out);
|
|
|
|
IMFSinkWriter_Release(&object->IMFSinkWriter_iface);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT create_sink_writer_from_stream(IMFByteStream *stream, IMFAttributes *attributes,
|
|
|
|
REFIID riid, void **out)
|
|
|
|
{
|
|
|
|
struct sink_writer *object;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
object = heap_alloc(sizeof(*object));
|
|
|
|
if (!object)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
object->IMFSinkWriter_iface.lpVtbl = &sink_writer_vtbl;
|
|
|
|
object->refcount = 1;
|
|
|
|
|
|
|
|
hr = IMFSinkWriter_QueryInterface(&object->IMFSinkWriter_iface, riid, out);
|
|
|
|
IMFSinkWriter_Release(&object->IMFSinkWriter_iface);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* MFCreateSinkWriterFromMediaSink (mfreadwrite.@)
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI MFCreateSinkWriterFromMediaSink(IMFMediaSink *sink, IMFAttributes *attributes, IMFSinkWriter **writer)
|
|
|
|
{
|
|
|
|
TRACE("%p, %p, %p.\n", sink, attributes, writer);
|
|
|
|
|
|
|
|
return create_sink_writer_from_sink(sink, attributes, &IID_IMFSinkWriter, (void **)writer);
|
|
|
|
}
|
|
|
|
|
2019-03-25 08:45:16 +01:00
|
|
|
static HRESULT create_source_reader_from_object(IUnknown *unk, IMFAttributes *attributes, REFIID riid, void **out)
|
|
|
|
{
|
|
|
|
IMFMediaSource *source = NULL;
|
|
|
|
IMFByteStream *stream = NULL;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = IUnknown_QueryInterface(unk, &IID_IMFMediaSource, (void **)&source);
|
|
|
|
if (FAILED(hr))
|
|
|
|
hr = IUnknown_QueryInterface(unk, &IID_IMFByteStream, (void **)&stream);
|
|
|
|
|
|
|
|
if (source)
|
|
|
|
{
|
|
|
|
UINT32 disconnect = 0;
|
|
|
|
|
|
|
|
if (attributes)
|
|
|
|
IMFAttributes_GetUINT32(attributes, &MF_SOURCE_READER_DISCONNECT_MEDIASOURCE_ON_SHUTDOWN, &disconnect);
|
|
|
|
hr = create_source_reader_from_source(source, attributes, !disconnect, riid, out);
|
|
|
|
}
|
|
|
|
else if (stream)
|
|
|
|
hr = create_source_reader_from_stream(stream, attributes, riid, out);
|
|
|
|
|
|
|
|
if (source)
|
|
|
|
IMFMediaSource_Release(source);
|
|
|
|
if (stream)
|
|
|
|
IMFByteStream_Release(stream);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2019-02-22 08:36:49 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* MFCreateSourceReaderFromByteStream (mfreadwrite.@)
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI MFCreateSourceReaderFromByteStream(IMFByteStream *stream, IMFAttributes *attributes,
|
|
|
|
IMFSourceReader **reader)
|
|
|
|
{
|
|
|
|
TRACE("%p, %p, %p.\n", stream, attributes, reader);
|
|
|
|
|
2019-03-25 08:45:16 +01:00
|
|
|
return create_source_reader_from_object((IUnknown *)stream, attributes, &IID_IMFSourceReader, (void **)reader);
|
2019-02-22 08:36:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* MFCreateSourceReaderFromMediaSource (mfreadwrite.@)
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI MFCreateSourceReaderFromMediaSource(IMFMediaSource *source, IMFAttributes *attributes,
|
2019-03-25 08:45:16 +01:00
|
|
|
IMFSourceReader **reader)
|
2019-02-22 08:36:49 +01:00
|
|
|
{
|
|
|
|
TRACE("%p, %p, %p.\n", source, attributes, reader);
|
|
|
|
|
2019-03-25 08:45:16 +01:00
|
|
|
return create_source_reader_from_object((IUnknown *)source, attributes, &IID_IMFSourceReader, (void **)reader);
|
2017-07-06 04:38:10 +02:00
|
|
|
}
|
2019-02-21 13:34:57 +01:00
|
|
|
|
2019-03-12 07:07:46 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* MFCreateSourceReaderFromURL (mfreadwrite.@)
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI MFCreateSourceReaderFromURL(const WCHAR *url, IMFAttributes *attributes, IMFSourceReader **reader)
|
|
|
|
{
|
|
|
|
TRACE("%s, %p, %p.\n", debugstr_w(url), attributes, reader);
|
|
|
|
|
|
|
|
return create_source_reader_from_url(url, attributes, &IID_IMFSourceReader, (void **)reader);
|
|
|
|
}
|
|
|
|
|
2019-02-21 13:34:57 +01:00
|
|
|
static HRESULT WINAPI readwrite_factory_QueryInterface(IMFReadWriteClassFactory *iface, REFIID riid, void **out)
|
|
|
|
{
|
|
|
|
if (IsEqualIID(riid, &IID_IMFReadWriteClassFactory) ||
|
|
|
|
IsEqualIID(riid, &IID_IUnknown))
|
|
|
|
{
|
|
|
|
*out = iface;
|
|
|
|
IMFReadWriteClassFactory_AddRef(iface);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN("Unsupported interface %s.\n", debugstr_guid(riid));
|
|
|
|
*out = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI readwrite_factory_AddRef(IMFReadWriteClassFactory *iface)
|
|
|
|
{
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI readwrite_factory_Release(IMFReadWriteClassFactory *iface)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI readwrite_factory_CreateInstanceFromURL(IMFReadWriteClassFactory *iface, REFCLSID clsid,
|
|
|
|
const WCHAR *url, IMFAttributes *attributes, REFIID riid, void **out)
|
|
|
|
{
|
2019-03-12 07:07:46 +01:00
|
|
|
TRACE("%s, %s, %p, %s, %p.\n", debugstr_guid(clsid), debugstr_w(url), attributes, debugstr_guid(riid), out);
|
|
|
|
|
|
|
|
if (IsEqualGUID(clsid, &CLSID_MFSourceReader))
|
|
|
|
{
|
|
|
|
return create_source_reader_from_url(url, attributes, &IID_IMFSourceReader, out);
|
|
|
|
}
|
|
|
|
|
|
|
|
FIXME("Unsupported %s.\n", debugstr_guid(clsid));
|
2019-02-21 13:34:57 +01:00
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI readwrite_factory_CreateInstanceFromObject(IMFReadWriteClassFactory *iface, REFCLSID clsid,
|
|
|
|
IUnknown *unk, IMFAttributes *attributes, REFIID riid, void **out)
|
|
|
|
{
|
2019-02-22 08:36:49 +01:00
|
|
|
HRESULT hr;
|
2019-02-21 13:34:57 +01:00
|
|
|
|
2019-02-22 08:36:49 +01:00
|
|
|
TRACE("%s, %p, %p, %s, %p.\n", debugstr_guid(clsid), unk, attributes, debugstr_guid(riid), out);
|
|
|
|
|
|
|
|
if (IsEqualGUID(clsid, &CLSID_MFSourceReader))
|
|
|
|
{
|
2019-03-25 08:45:16 +01:00
|
|
|
return create_source_reader_from_object(unk, attributes, riid, out);
|
2019-02-22 08:36:49 +01:00
|
|
|
}
|
|
|
|
else if (IsEqualGUID(clsid, &CLSID_MFSinkWriter))
|
|
|
|
{
|
2019-02-25 09:33:55 +01:00
|
|
|
IMFByteStream *stream = NULL;
|
|
|
|
IMFMediaSink *sink = NULL;
|
|
|
|
|
|
|
|
hr = IUnknown_QueryInterface(unk, &IID_IMFByteStream, (void **)&stream);
|
|
|
|
if (FAILED(hr))
|
|
|
|
hr = IUnknown_QueryInterface(unk, &IID_IMFMediaSink, (void **)&sink);
|
|
|
|
|
|
|
|
if (stream)
|
|
|
|
hr = create_sink_writer_from_stream(stream, attributes, riid, out);
|
|
|
|
else if (sink)
|
|
|
|
hr = create_sink_writer_from_sink(sink, attributes, riid, out);
|
|
|
|
|
|
|
|
if (sink)
|
|
|
|
IMFMediaSink_Release(sink);
|
|
|
|
if (stream)
|
|
|
|
IMFByteStream_Release(stream);
|
|
|
|
|
|
|
|
return hr;
|
2019-02-22 08:36:49 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WARN("Unsupported class %s.\n", debugstr_guid(clsid));
|
|
|
|
*out = NULL;
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
2019-02-21 13:34:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static const IMFReadWriteClassFactoryVtbl readwrite_factory_vtbl =
|
|
|
|
{
|
|
|
|
readwrite_factory_QueryInterface,
|
|
|
|
readwrite_factory_AddRef,
|
|
|
|
readwrite_factory_Release,
|
|
|
|
readwrite_factory_CreateInstanceFromURL,
|
|
|
|
readwrite_factory_CreateInstanceFromObject,
|
|
|
|
};
|
|
|
|
|
|
|
|
static IMFReadWriteClassFactory readwrite_factory = { &readwrite_factory_vtbl };
|
|
|
|
|
|
|
|
static HRESULT WINAPI classfactory_QueryInterface(IClassFactory *iface, REFIID riid, void **out)
|
|
|
|
{
|
|
|
|
TRACE("%s, %p.\n", debugstr_guid(riid), out);
|
|
|
|
|
|
|
|
if (IsEqualGUID(riid, &IID_IClassFactory) ||
|
|
|
|
IsEqualGUID(riid, &IID_IUnknown))
|
|
|
|
{
|
|
|
|
IClassFactory_AddRef(iface);
|
|
|
|
*out = iface;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN("interface %s not implemented\n", debugstr_guid(riid));
|
|
|
|
*out = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI classfactory_AddRef(IClassFactory *iface)
|
|
|
|
{
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI classfactory_Release(IClassFactory *iface)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI classfactory_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **out)
|
|
|
|
{
|
|
|
|
TRACE("%p, %s, %p.\n", outer, debugstr_guid(riid), out);
|
|
|
|
|
|
|
|
*out = NULL;
|
|
|
|
|
|
|
|
if (outer)
|
|
|
|
return CLASS_E_NOAGGREGATION;
|
|
|
|
|
|
|
|
return IMFReadWriteClassFactory_QueryInterface(&readwrite_factory, riid, out);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI classfactory_LockServer(IClassFactory *iface, BOOL dolock)
|
|
|
|
{
|
|
|
|
FIXME("%d.\n", dolock);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct IClassFactoryVtbl classfactoryvtbl =
|
|
|
|
{
|
|
|
|
classfactory_QueryInterface,
|
|
|
|
classfactory_AddRef,
|
|
|
|
classfactory_Release,
|
|
|
|
classfactory_CreateInstance,
|
|
|
|
classfactory_LockServer,
|
|
|
|
};
|
|
|
|
|
|
|
|
static IClassFactory classfactory = { &classfactoryvtbl };
|
|
|
|
|
|
|
|
HRESULT WINAPI DllGetClassObject(REFCLSID clsid, REFIID riid, void **out)
|
|
|
|
{
|
|
|
|
TRACE("%s, %s, %p.\n", debugstr_guid(clsid), debugstr_guid(riid), out);
|
|
|
|
|
|
|
|
if (IsEqualGUID(clsid, &CLSID_MFReadWriteClassFactory))
|
|
|
|
return IClassFactory_QueryInterface(&classfactory, riid, out);
|
|
|
|
|
|
|
|
WARN("Unsupported class %s.\n", debugstr_guid(clsid));
|
|
|
|
*out = NULL;
|
|
|
|
return CLASS_E_CLASSNOTAVAILABLE;
|
|
|
|
}
|