From: Rémi Bernon rbernon@codeweavers.com
--- dlls/winegstreamer/media_source.c | 138 +++++++++++++++--------------- 1 file changed, 69 insertions(+), 69 deletions(-)
diff --git a/dlls/winegstreamer/media_source.c b/dlls/winegstreamer/media_source.c index 55b1cd6e98d..ef359dff8c9 100644 --- a/dlls/winegstreamer/media_source.c +++ b/dlls/winegstreamer/media_source.c @@ -27,6 +27,72 @@
WINE_DEFAULT_DEBUG_CHANNEL(mfplat);
+struct object_context +{ + IUnknown IUnknown_iface; + LONG refcount; + + IMFAsyncResult *result; + IMFByteStream *stream; + WCHAR *url; +}; + +static struct object_context *impl_from_IUnknown(IUnknown *iface) +{ + return CONTAINING_RECORD(iface, struct object_context, IUnknown_iface); +} + +static HRESULT WINAPI object_context_QueryInterface(IUnknown *iface, REFIID riid, void **obj) +{ + TRACE("%p, %s, %p.\n", iface, debugstr_guid(riid), obj); + + if (IsEqualIID(riid, &IID_IUnknown)) + { + *obj = iface; + IUnknown_AddRef(iface); + return S_OK; + } + + WARN("Unsupported %s.\n", debugstr_guid(riid)); + *obj = NULL; + return E_NOINTERFACE; +} + +static ULONG WINAPI object_context_AddRef(IUnknown *iface) +{ + struct object_context *context = impl_from_IUnknown(iface); + ULONG refcount = InterlockedIncrement(&context->refcount); + + TRACE("%p, refcount %lu.\n", iface, refcount); + + return refcount; +} + +static ULONG WINAPI object_context_Release(IUnknown *iface) +{ + struct object_context *context = impl_from_IUnknown(iface); + ULONG refcount = InterlockedDecrement(&context->refcount); + + TRACE("%p, refcount %lu.\n", iface, refcount); + + if (!refcount) + { + IMFAsyncResult_Release(context->result); + IMFByteStream_Release(context->stream); + free(context->url); + free(context); + } + + return refcount; +} + +static const IUnknownVtbl object_context_vtbl = +{ + object_context_QueryInterface, + object_context_AddRef, + object_context_Release, +}; + struct media_stream { IMFMediaStream IMFMediaStream_iface; @@ -1773,77 +1839,11 @@ static ULONG WINAPI stream_handler_Release(IMFByteStreamHandler *iface) return refcount; }
-struct create_object_context -{ - IUnknown IUnknown_iface; - LONG refcount; - - IMFAsyncResult *result; - IMFByteStream *stream; - WCHAR *url; -}; - -static struct create_object_context *impl_from_IUnknown(IUnknown *iface) -{ - return CONTAINING_RECORD(iface, struct create_object_context, IUnknown_iface); -} - -static HRESULT WINAPI create_object_context_QueryInterface(IUnknown *iface, REFIID riid, void **obj) -{ - TRACE("%p, %s, %p.\n", iface, debugstr_guid(riid), obj); - - if (IsEqualIID(riid, &IID_IUnknown)) - { - *obj = iface; - IUnknown_AddRef(iface); - return S_OK; - } - - WARN("Unsupported %s.\n", debugstr_guid(riid)); - *obj = NULL; - return E_NOINTERFACE; -} - -static ULONG WINAPI create_object_context_AddRef(IUnknown *iface) -{ - struct create_object_context *context = impl_from_IUnknown(iface); - ULONG refcount = InterlockedIncrement(&context->refcount); - - TRACE("%p, refcount %lu.\n", iface, refcount); - - return refcount; -} - -static ULONG WINAPI create_object_context_Release(IUnknown *iface) -{ - struct create_object_context *context = impl_from_IUnknown(iface); - ULONG refcount = InterlockedDecrement(&context->refcount); - - TRACE("%p, refcount %lu.\n", iface, refcount); - - if (!refcount) - { - IMFAsyncResult_Release(context->result); - IMFByteStream_Release(context->stream); - free(context->url); - free(context); - } - - return refcount; -} - -static const IUnknownVtbl create_object_context_vtbl = -{ - create_object_context_QueryInterface, - create_object_context_AddRef, - create_object_context_Release, -}; - static HRESULT WINAPI stream_handler_BeginCreateObject(IMFByteStreamHandler *iface, IMFByteStream *stream, const WCHAR *url, DWORD flags, IPropertyStore *props, IUnknown **cancel_cookie, IMFAsyncCallback *callback, IUnknown *state) { struct stream_handler *handler = impl_from_IMFByteStreamHandler(iface); - struct create_object_context *context; + struct object_context *context; IMFAsyncResult *result; HRESULT hr;
@@ -1866,7 +1866,7 @@ static HRESULT WINAPI stream_handler_BeginCreateObject(IMFByteStreamHandler *ifa return E_OUTOFMEMORY; }
- context->IUnknown_iface.lpVtbl = &create_object_context_vtbl; + context->IUnknown_iface.lpVtbl = &object_context_vtbl; context->refcount = 1; context->stream = stream; IMFByteStream_AddRef(context->stream); @@ -1981,7 +1981,7 @@ static HRESULT WINAPI stream_handler_callback_Invoke(IMFAsyncCallback *iface, IM { struct stream_handler *handler = impl_from_IMFAsyncCallback(iface); IUnknown *object, *state = IMFAsyncResult_GetStateNoAddRef(result); - struct create_object_context *context; + struct object_context *context; struct result_entry *entry; HRESULT hr;
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/winegstreamer/media_source.c | 43 +++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 14 deletions(-)
diff --git a/dlls/winegstreamer/media_source.c b/dlls/winegstreamer/media_source.c index ef359dff8c9..a6c48b7e297 100644 --- a/dlls/winegstreamer/media_source.c +++ b/dlls/winegstreamer/media_source.c @@ -93,6 +93,30 @@ static const IUnknownVtbl object_context_vtbl = object_context_Release, };
+static HRESULT object_context_create(DWORD flags, IMFByteStream *stream, const WCHAR *url, + IMFAsyncResult *result, IUnknown **out) +{ + WCHAR *tmp_url = url ? wcsdup(url) : NULL; + struct object_context *context; + + if (!(context = calloc(1, sizeof(*context)))) + { + free(tmp_url); + return E_OUTOFMEMORY; + } + + context->IUnknown_iface.lpVtbl = &object_context_vtbl; + context->refcount = 1; + context->stream = stream; + IMFByteStream_AddRef(context->stream); + context->url = tmp_url; + context->result = result; + IMFAsyncResult_AddRef(context->result); + + *out = &context->IUnknown_iface; + return S_OK; +} + struct media_stream { IMFMediaStream IMFMediaStream_iface; @@ -1843,8 +1867,8 @@ static HRESULT WINAPI stream_handler_BeginCreateObject(IMFByteStreamHandler *ifa IPropertyStore *props, IUnknown **cancel_cookie, IMFAsyncCallback *callback, IUnknown *state) { struct stream_handler *handler = impl_from_IMFByteStreamHandler(iface); - struct object_context *context; IMFAsyncResult *result; + IUnknown *context; HRESULT hr;
TRACE("%p, %s, %#lx, %p, %p, %p, %p.\n", iface, debugstr_w(url), flags, props, cancel_cookie, callback, state); @@ -1860,23 +1884,14 @@ static HRESULT WINAPI stream_handler_BeginCreateObject(IMFByteStreamHandler *ifa if (FAILED(hr = MFCreateAsyncResult(NULL, callback, state, &result))) return hr;
- if (!(context = calloc(1, sizeof(*context)))) + if (FAILED(hr = object_context_create(flags, stream, url, result, &context))) { IMFAsyncResult_Release(result); - return E_OUTOFMEMORY; + return hr; }
- context->IUnknown_iface.lpVtbl = &object_context_vtbl; - context->refcount = 1; - context->stream = stream; - IMFByteStream_AddRef(context->stream); - context->result = result; - IMFAsyncResult_AddRef(context->result); - if (url) - context->url = wcsdup(url); - - hr = MFPutWorkItem(MFASYNC_CALLBACK_QUEUE_IO, &handler->IMFAsyncCallback_iface, &context->IUnknown_iface); - IUnknown_Release(&context->IUnknown_iface); + hr = MFPutWorkItem(MFASYNC_CALLBACK_QUEUE_IO, &handler->IMFAsyncCallback_iface, context); + IUnknown_Release(context);
if (SUCCEEDED(hr) && cancel_cookie) {
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/winegstreamer/media_source.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/dlls/winegstreamer/media_source.c b/dlls/winegstreamer/media_source.c index a6c48b7e297..3ba305b897a 100644 --- a/dlls/winegstreamer/media_source.c +++ b/dlls/winegstreamer/media_source.c @@ -1610,7 +1610,7 @@ static void media_source_init_descriptors(struct media_source *source) } }
-static HRESULT media_source_create(IMFByteStream *bytestream, IMFMediaSource **out) +static HRESULT media_source_create(struct object_context *context, IMFMediaSource **out) { unsigned int stream_count = UINT_MAX; struct media_source *object; @@ -1620,7 +1620,7 @@ static HRESULT media_source_create(IMFByteStream *bytestream, IMFMediaSource **o unsigned int i; HRESULT hr;
- if (FAILED(hr = IMFByteStream_GetCapabilities(bytestream, &bytestream_caps))) + if (FAILED(hr = IMFByteStream_GetCapabilities(context->stream, &bytestream_caps))) return hr;
if (!(bytestream_caps & MFBYTESTREAM_IS_SEEKABLE)) @@ -1629,7 +1629,7 @@ static HRESULT media_source_create(IMFByteStream *bytestream, IMFMediaSource **o return MF_E_BYTESTREAM_NOT_SEEKABLE; }
- if (FAILED(hr = IMFByteStream_GetLength(bytestream, &file_size))) + if (FAILED(hr = IMFByteStream_GetLength(context->stream, &file_size))) { FIXME("Failed to get byte stream length, hr %#lx.\n", hr); return hr; @@ -1644,8 +1644,8 @@ static HRESULT media_source_create(IMFByteStream *bytestream, IMFMediaSource **o object->IMFRateControl_iface.lpVtbl = &media_source_rate_control_vtbl; object->async_commands_callback.lpVtbl = &source_async_commands_callback_vtbl; object->ref = 1; - object->byte_stream = bytestream; - IMFByteStream_AddRef(bytestream); + object->byte_stream = context->stream; + IMFByteStream_AddRef(context->stream); object->rate = 1.0f; InitializeCriticalSection(&object->cs); object->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": cs"); @@ -2003,7 +2003,7 @@ static HRESULT WINAPI stream_handler_callback_Invoke(IMFAsyncCallback *iface, IM if (!state || !(context = impl_from_IUnknown(state))) return E_INVALIDARG;
- if (FAILED(hr = media_source_create(context->stream, (IMFMediaSource **)&object))) + if (FAILED(hr = media_source_create(context, (IMFMediaSource **)&object))) WARN("Failed to create media source, hr %#lx\n", hr); else {
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/winegstreamer/media_source.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)
diff --git a/dlls/winegstreamer/media_source.c b/dlls/winegstreamer/media_source.c index 3ba305b897a..ca1c9c445f4 100644 --- a/dlls/winegstreamer/media_source.c +++ b/dlls/winegstreamer/media_source.c @@ -1615,20 +1615,10 @@ static HRESULT media_source_create(struct object_context *context, IMFMediaSourc unsigned int stream_count = UINT_MAX; struct media_source *object; struct wg_parser *parser; - DWORD bytestream_caps; QWORD file_size; unsigned int i; HRESULT hr;
- if (FAILED(hr = IMFByteStream_GetCapabilities(context->stream, &bytestream_caps))) - return hr; - - if (!(bytestream_caps & MFBYTESTREAM_IS_SEEKABLE)) - { - FIXME("Non-seekable bytestreams not supported.\n"); - return MF_E_BYTESTREAM_NOT_SEEKABLE; - } - if (FAILED(hr = IMFByteStream_GetLength(context->stream, &file_size))) { FIXME("Failed to get byte stream length, hr %#lx.\n", hr); @@ -1870,6 +1860,7 @@ static HRESULT WINAPI stream_handler_BeginCreateObject(IMFByteStreamHandler *ifa IMFAsyncResult *result; IUnknown *context; HRESULT hr; + DWORD caps;
TRACE("%p, %s, %#lx, %p, %p, %p, %p.\n", iface, debugstr_w(url), flags, props, cancel_cookie, callback, state);
@@ -1881,6 +1872,14 @@ static HRESULT WINAPI stream_handler_BeginCreateObject(IMFByteStreamHandler *ifa if (flags != MF_RESOLUTION_MEDIASOURCE) FIXME("Unimplemented flags %#lx\n", flags);
+ if (FAILED(hr = IMFByteStream_GetCapabilities(stream, &caps))) + return hr; + if (!(caps & MFBYTESTREAM_IS_SEEKABLE)) + { + FIXME("Non-seekable bytestreams not supported.\n"); + return MF_E_BYTESTREAM_NOT_SEEKABLE; + } + if (FAILED(hr = MFCreateAsyncResult(NULL, callback, state, &result))) return hr;
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/winegstreamer/media_source.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-)
diff --git a/dlls/winegstreamer/media_source.c b/dlls/winegstreamer/media_source.c index ca1c9c445f4..010f6d27b94 100644 --- a/dlls/winegstreamer/media_source.c +++ b/dlls/winegstreamer/media_source.c @@ -34,6 +34,7 @@ struct object_context
IMFAsyncResult *result; IMFByteStream *stream; + UINT64 file_size; WCHAR *url; };
@@ -94,7 +95,7 @@ static const IUnknownVtbl object_context_vtbl = };
static HRESULT object_context_create(DWORD flags, IMFByteStream *stream, const WCHAR *url, - IMFAsyncResult *result, IUnknown **out) + QWORD file_size, IMFAsyncResult *result, IUnknown **out) { WCHAR *tmp_url = url ? wcsdup(url) : NULL; struct object_context *context; @@ -109,6 +110,7 @@ static HRESULT object_context_create(DWORD flags, IMFByteStream *stream, const W context->refcount = 1; context->stream = stream; IMFByteStream_AddRef(context->stream); + context->file_size = file_size; context->url = tmp_url; context->result = result; IMFAsyncResult_AddRef(context->result); @@ -181,6 +183,7 @@ struct media_source CRITICAL_SECTION cs;
struct wg_parser *wg_parser; + UINT64 file_size; UINT64 duration;
IMFStreamDescriptor **descriptors; @@ -1615,16 +1618,9 @@ static HRESULT media_source_create(struct object_context *context, IMFMediaSourc unsigned int stream_count = UINT_MAX; struct media_source *object; struct wg_parser *parser; - QWORD file_size; unsigned int i; HRESULT hr;
- if (FAILED(hr = IMFByteStream_GetLength(context->stream, &file_size))) - { - FIXME("Failed to get byte stream length, hr %#lx.\n", hr); - return hr; - } - if (!(object = calloc(1, sizeof(*object)))) return E_OUTOFMEMORY;
@@ -1636,6 +1632,7 @@ static HRESULT media_source_create(struct object_context *context, IMFMediaSourc object->ref = 1; object->byte_stream = context->stream; IMFByteStream_AddRef(context->stream); + object->file_size = context->file_size; object->rate = 1.0f; InitializeCriticalSection(&object->cs); object->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": cs"); @@ -1663,7 +1660,7 @@ static HRESULT media_source_create(struct object_context *context, IMFMediaSourc
object->state = SOURCE_OPENING;
- if (FAILED(hr = wg_parser_connect(parser, file_size))) + if (FAILED(hr = wg_parser_connect(parser, object->file_size))) goto fail;
stream_count = wg_parser_get_stream_count(parser); @@ -1859,6 +1856,7 @@ static HRESULT WINAPI stream_handler_BeginCreateObject(IMFByteStreamHandler *ifa struct stream_handler *handler = impl_from_IMFByteStreamHandler(iface); IMFAsyncResult *result; IUnknown *context; + QWORD file_size; HRESULT hr; DWORD caps;
@@ -1879,11 +1877,15 @@ static HRESULT WINAPI stream_handler_BeginCreateObject(IMFByteStreamHandler *ifa FIXME("Non-seekable bytestreams not supported.\n"); return MF_E_BYTESTREAM_NOT_SEEKABLE; } + if (FAILED(hr = IMFByteStream_GetLength(stream, &file_size))) + { + FIXME("Failed to get byte stream length, hr %#lx.\n", hr); + return hr; + }
if (FAILED(hr = MFCreateAsyncResult(NULL, callback, state, &result))) return hr; - - if (FAILED(hr = object_context_create(flags, stream, url, result, &context))) + if (FAILED(hr = object_context_create(flags, stream, url, file_size, result, &context))) { IMFAsyncResult_Release(result); return hr;