Fixes: abac070387f908f853f38eddc67206ff7c657ae2 Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/quartz/filesource.c | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-)
diff --git a/dlls/quartz/filesource.c b/dlls/quartz/filesource.c index 11cc438be29..c1f7f69d5e2 100644 --- a/dlls/quartz/filesource.c +++ b/dlls/quartz/filesource.c @@ -352,7 +352,7 @@ static void async_reader_destroy(struct strmbase_filter *iface) CloseHandle(filter->port);
strmbase_filter_cleanup(&filter->filter); - CoTaskMemFree(filter); + free(filter); }
static HRESULT async_reader_query_interface(struct strmbase_filter *iface, REFIID iid, void **out) @@ -414,31 +414,24 @@ static DWORD CALLBACK io_thread(void *arg)
HRESULT AsyncReader_create(IUnknown *outer, void **out) { - AsyncReader *pAsyncRead; - - pAsyncRead = CoTaskMemAlloc(sizeof(AsyncReader)); + AsyncReader *object;
- if (!pAsyncRead) + if (!(object = calloc(1, sizeof(*object)))) return E_OUTOFMEMORY;
- strmbase_filter_init(&pAsyncRead->filter, outer, &CLSID_AsyncReader, &filter_ops); + strmbase_filter_init(&object->filter, outer, &CLSID_AsyncReader, &filter_ops);
- pAsyncRead->IFileSourceFilter_iface.lpVtbl = &FileSource_Vtbl; + object->IFileSourceFilter_iface.lpVtbl = &FileSource_Vtbl; + object->IAsyncReader_iface.lpVtbl = &FileAsyncReader_Vtbl;
- pAsyncRead->IAsyncReader_iface.lpVtbl = &FileAsyncReader_Vtbl; - - pAsyncRead->pszFileName = NULL; - - InitializeCriticalSection(&pAsyncRead->sample_cs); - pAsyncRead->sample_cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": FileAsyncReader.sample_cs"); - InitializeConditionVariable(&pAsyncRead->sample_cv); - pAsyncRead->port = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, 0, 0); - pAsyncRead->io_thread = CreateThread(NULL, 0, io_thread, pAsyncRead, 0, NULL); - - *out = &pAsyncRead->filter.IUnknown_inner; - - TRACE("-- created at %p\n", pAsyncRead); + 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);
+ TRACE("Created file source %p.\n", object); + *out = &object->filter.IUnknown_inner; return S_OK; }
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/winegstreamer/gst_cbs.c | 9 ---- dlls/winegstreamer/gst_cbs.h | 5 --- dlls/winegstreamer/gstdemux.c | 81 ++++++++++------------------------- 3 files changed, 23 insertions(+), 72 deletions(-)
diff --git a/dlls/winegstreamer/gst_cbs.c b/dlls/winegstreamer/gst_cbs.c index e7a4b41d55f..679d87c52f5 100644 --- a/dlls/winegstreamer/gst_cbs.c +++ b/dlls/winegstreamer/gst_cbs.c @@ -227,15 +227,6 @@ void unknown_type_wrapper(GstElement *bin, GstPad *pad, GstCaps *caps, gpointer call_cb(&cbdata); }
-void release_sample_wrapper(gpointer data) -{ - struct cb_data cbdata = { RELEASE_SAMPLE }; - - cbdata.u.release_sample_data.data = data; - - call_cb(&cbdata); -} - gboolean query_sink_wrapper(GstPad *pad, GstObject *parent, GstQuery *query) { struct cb_data cbdata = { QUERY_SINK }; diff --git a/dlls/winegstreamer/gst_cbs.h b/dlls/winegstreamer/gst_cbs.h index 46f8add57c4..a425671da76 100644 --- a/dlls/winegstreamer/gst_cbs.h +++ b/dlls/winegstreamer/gst_cbs.h @@ -42,7 +42,6 @@ enum CB_TYPE { REMOVED_DECODED_PAD, AUTOPLUG_BLACKLIST, UNKNOWN_TYPE, - RELEASE_SAMPLE, QUERY_SINK };
@@ -122,9 +121,6 @@ struct cb_data { GstCaps *caps; gpointer user; } unknown_type_data; - struct release_sample_data { - gpointer data; - } release_sample_data; struct query_sink_data { GstPad *pad; GstObject *parent; @@ -159,7 +155,6 @@ GstFlowReturn got_data_wrapper(GstPad *pad, GstObject *parent, GstBuffer *buf) D void removed_decoded_pad_wrapper(GstElement *bin, GstPad *pad, gpointer user) DECLSPEC_HIDDEN; GstAutoplugSelectResult autoplug_blacklist_wrapper(GstElement *bin, GstPad *pad, GstCaps *caps, GstElementFactory *fact, gpointer user) DECLSPEC_HIDDEN; void unknown_type_wrapper(GstElement *bin, GstPad *pad, GstCaps *caps, gpointer user) DECLSPEC_HIDDEN; -void release_sample_wrapper(gpointer data) DECLSPEC_HIDDEN; void Gstreamer_transform_pad_added_wrapper(GstElement *filter, GstPad *pad, gpointer user) DECLSPEC_HIDDEN; gboolean query_sink_wrapper(GstPad *pad, GstObject *parent, GstQuery *query) DECLSPEC_HIDDEN;
diff --git a/dlls/winegstreamer/gstdemux.c b/dlls/winegstreamer/gstdemux.c index 0b5fee30273..b62f44b6a13 100644 --- a/dlls/winegstreamer/gstdemux.c +++ b/dlls/winegstreamer/gstdemux.c @@ -97,8 +97,6 @@ static inline struct gstdemux *impl_from_strmbase_filter(struct strmbase_filter return CONTAINING_RECORD(iface, struct gstdemux, filter); }
-static const char *media_quark_string = "media-sample"; - static const WCHAR wcsInputPinName[] = {'i','n','p','u','t',' ','p','i','n',0}; static const IMediaSeekingVtbl GST_Seeking_Vtbl; static const IQualityControlVtbl GSTOutPin_QualityControl_Vtbl; @@ -744,21 +742,20 @@ static gboolean event_sink(GstPad *pad, GstObject *parent, GstEvent *event) } }
-static void release_sample(void *data) -{ - ULONG ret; - ret = IMediaSample_Release((IMediaSample *)data); - TRACE("Releasing %p returns %u\n", data, ret); -} - static DWORD CALLBACK push_data(LPVOID iface) { LONGLONG maxlen, curlen; struct gstdemux *This = iface; - IMediaSample *buf; - DWORD_PTR user; + GstMapInfo mapping; + GstBuffer *buffer; HRESULT hr;
+ if (!(buffer = gst_buffer_new_allocate(NULL, 16384, NULL))) + { + ERR("Failed to allocate memory.\n"); + return 0; + } + IBaseFilter_AddRef(&This->filter.IBaseFilter_iface);
if (!This->stop) @@ -768,51 +765,30 @@ static DWORD CALLBACK push_data(LPVOID iface)
TRACE("Starting..\n"); for (;;) { - REFERENCE_TIME tStart, tStop; ULONG len; - GstBuffer *gstbuf; - gsize bufsize; - BYTE *data; int ret;
- hr = IMemAllocator_GetBuffer(This->alloc, &buf, NULL, NULL, 0); - if (FAILED(hr)) - break; - if (This->nextofs >= maxlen) break; - len = IMediaSample_GetSize(buf); - if (This->nextofs + len > maxlen) - len = maxlen - This->nextofs; - - tStart = MEDIATIME_FROM_BYTES(This->nextofs); - tStop = tStart + MEDIATIME_FROM_BYTES(len); - IMediaSample_SetTime(buf, &tStart, &tStop); + len = min(16384, maxlen - This->nextofs);
- hr = IAsyncReader_Request(This->reader, buf, 0); - if (FAILED(hr)) { - IMediaSample_Release(buf); + if (!gst_buffer_map_range(buffer, -1, len, &mapping, GST_MAP_WRITE)) + { + ERR("Failed to map buffer.\n"); break; } - This->nextofs += len; - hr = IAsyncReader_WaitForNext(This->reader, -1, &buf, &user); - if (FAILED(hr) || !buf) { - if (buf) - IMediaSample_Release(buf); + hr = IAsyncReader_SyncRead(This->reader, This->nextofs, len, mapping.data); + gst_buffer_unmap(buffer, &mapping); + if (hr != S_OK) + { + ERR("Failed to read data, hr %#x.\n", hr); break; }
- IMediaSample_GetPointer(buf, &data); - bufsize = IMediaSample_GetActualDataLength(buf); - gstbuf = gst_buffer_new_wrapped_full(0, data, bufsize, 0, bufsize, buf, release_sample_wrapper); - IMediaSample_AddRef(buf); - gst_mini_object_set_qdata(GST_MINI_OBJECT(gstbuf), g_quark_from_static_string(media_quark_string), buf, release_sample_wrapper); - if (!gstbuf) { - IMediaSample_Release(buf); - break; - } - gstbuf->duration = gstbuf->pts = -1; - ret = gst_pad_push(This->my_src, gstbuf); + This->nextofs += len; + + buffer->duration = buffer->pts = -1; + ret = gst_pad_push(This->my_src, buffer); if (ret >= 0) hr = S_OK; else @@ -825,14 +801,9 @@ static DWORD CALLBACK push_data(LPVOID iface) break; }
- gst_pad_push_event(This->my_src, gst_event_new_eos()); + gst_buffer_unref(buffer);
- TRACE("Almost stopping.. %08x\n", hr); - do { - IAsyncReader_WaitForNext(This->reader, 0, &buf, &user); - if (buf) - IMediaSample_Release(buf); - } while (buf); + gst_pad_push_event(This->my_src, gst_event_new_eos());
TRACE("Stopping.. %08x\n", hr);
@@ -2332,12 +2303,6 @@ void CALLBACK perform_cb(TP_CALLBACK_INSTANCE *instance, void *user) unknown_type(data->bin, data->pad, data->caps, data->user); break; } - case RELEASE_SAMPLE: - { - struct release_sample_data *data = &cbdata->u.release_sample_data; - release_sample(data->data); - break; - } case QUERY_SINK: { struct query_sink_data *data = &cbdata->u.query_sink_data;
In particular, pass the correct buffer size for the format we have chosen.
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=48570 Fixes: f5a1e2bd87754a2822f2eb0e84291d787936d115 Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/winegstreamer/gstdemux.c | 91 ++++++++--------------------------- 1 file changed, 19 insertions(+), 72 deletions(-)
diff --git a/dlls/winegstreamer/gstdemux.c b/dlls/winegstreamer/gstdemux.c index b62f44b6a13..1337cd0a81c 100644 --- a/dlls/winegstreamer/gstdemux.c +++ b/dlls/winegstreamer/gstdemux.c @@ -57,7 +57,6 @@ struct gstdemux
struct strmbase_sink sink; IAsyncReader *reader; - IMemAllocator *alloc;
struct gstdemux_source **sources; unsigned int source_count; @@ -70,7 +69,6 @@ struct gstdemux GstPad *my_src, *their_sink; GstBus *bus; guint64 start, nextofs, nextpullofs, stop; - ALLOCATOR_PROPERTIES props; HANDLE no_more_pads_event, duration_event, error_event;
HANDLE push_thread; @@ -486,11 +484,6 @@ static gboolean setcaps_sink(GstPad *pad, GstCaps *caps) if (!amt_from_gst_caps(caps, &pin->mt)) return FALSE;
- if (IsEqualGUID(&pin->mt.formattype, &FORMAT_VideoInfo)) - { - VIDEOINFOHEADER *vih = (VIDEOINFOHEADER *)pin->mt.pbFormat; - filter->props.cbBuffer = max(filter->props.cbBuffer, vih->bmiHeader.biSizeImage); - } SetEvent(pin->caps_event); return TRUE; } @@ -1295,7 +1288,7 @@ static void unknown_type(GstElement *bin, GstPad *pad, GstCaps *caps, gpointer u g_free(strcaps); }
-static HRESULT GST_Connect(struct gstdemux *This, IPin *pConnectPin, ALLOCATOR_PROPERTIES *props) +static HRESULT GST_Connect(struct gstdemux *This, IPin *pConnectPin) { LONGLONG avail; GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE( @@ -1304,7 +1297,6 @@ static HRESULT GST_Connect(struct gstdemux *This, IPin *pConnectPin, ALLOCATOR_P GST_PAD_ALWAYS, GST_STATIC_CAPS_ANY);
- This->props = *props; IAsyncReader_Length(This->reader, &This->filesize, &avail);
if (!This->bus) { @@ -1329,7 +1321,6 @@ static HRESULT GST_Connect(struct gstdemux *This, IPin *pConnectPin, ALLOCATOR_P return E_FAIL; This->initial = FALSE;
- *props = This->props; This->nextofs = This->nextpullofs = 0; return S_OK; } @@ -1378,9 +1369,6 @@ static void gstdemux_destroy(struct strmbase_filter *iface) assert(hr == S_OK); }
- if (filter->alloc) - IMemAllocator_Release(filter->alloc); - filter->alloc = NULL; if (filter->reader) IAsyncReader_Release(filter->reader); filter->reader = NULL; @@ -1529,46 +1517,16 @@ static HRESULT sink_query_accept(struct strmbase_pin *iface, const AM_MEDIA_TYPE static HRESULT gstdemux_sink_connect(struct strmbase_sink *iface, IPin *peer, const AM_MEDIA_TYPE *pmt) { struct gstdemux *filter = impl_from_strmbase_sink(iface); - IMemAllocator *allocator = NULL; - ALLOCATOR_PROPERTIES props; HRESULT hr = S_OK;
mark_wine_thread();
- props.cBuffers = 8; - props.cbBuffer = 16384; - props.cbAlign = 1; - props.cbPrefix = 0; - filter->reader = NULL; - filter->alloc = NULL; if (FAILED(hr = IPin_QueryInterface(peer, &IID_IAsyncReader, (void **)&filter->reader))) return hr;
- if (FAILED(hr = GST_Connect(filter, peer, &props))) - goto err; - - /* Some applications depend on IAsyncReader::RequestAllocator() passing a - * non-NULL preferred allocator. */ - hr = CoCreateInstance(&CLSID_MemoryAllocator, NULL, CLSCTX_INPROC, - &IID_IMemAllocator, (void **)&allocator); - if (FAILED(hr)) - goto err; - hr = IAsyncReader_RequestAllocator(filter->reader, allocator, &props, &filter->alloc); - IMemAllocator_Release(allocator); - if (FAILED(hr)) - { - WARN("Failed to get allocator, hr %#x.\n", hr); - goto err; - } - - if (FAILED(hr = IMemAllocator_Commit(filter->alloc))) - { - WARN("Failed to commit allocator, hr %#x.\n", hr); - IMemAllocator_Release(filter->alloc); - filter->alloc = NULL; + if (FAILED(hr = GST_Connect(filter, peer))) goto err; - }
return S_OK; err: @@ -1584,7 +1542,6 @@ static void gstdemux_sink_disconnect(struct strmbase_sink *iface)
mark_wine_thread();
- IMemAllocator_Decommit(filter->alloc); GST_RemoveOutputPins(filter); }
@@ -2083,37 +2040,27 @@ static HRESULT source_get_media_type(struct strmbase_pin *iface, unsigned int in }
static HRESULT WINAPI GSTOutPin_DecideBufferSize(struct strmbase_source *iface, - IMemAllocator *pAlloc, ALLOCATOR_PROPERTIES *ppropInputRequest) + IMemAllocator *allocator, ALLOCATOR_PROPERTIES *props) { - struct gstdemux_source *This = impl_source_from_IPin(&iface->pin.IPin_iface); - TRACE("(%p)->(%p, %p)\n", This, pAlloc, ppropInputRequest); - /* Unused */ - return S_OK; -} - -static HRESULT WINAPI GSTOutPin_DecideAllocator(struct strmbase_source *base, - IMemInputPin *pPin, IMemAllocator **pAlloc) -{ - struct gstdemux_source *pin = impl_source_from_IPin(&base->pin.IPin_iface); - struct gstdemux *filter = impl_from_strmbase_filter(pin->pin.pin.filter); - HRESULT hr; - - TRACE("pin %p, peer %p, allocator %p.\n", pin, pPin, pAlloc); + struct gstdemux_source *pin = impl_source_from_IPin(&iface->pin.IPin_iface); + unsigned int buffer_size = 16384; + ALLOCATOR_PROPERTIES ret_props;
- *pAlloc = NULL; - if (filter->alloc) + if (IsEqualGUID(&pin->pin.pin.mt.formattype, &FORMAT_VideoInfo)) { - hr = IMemInputPin_NotifyAllocator(pPin, filter->alloc, FALSE); - if (SUCCEEDED(hr)) - { - *pAlloc = filter->alloc; - IMemAllocator_AddRef(*pAlloc); - } + VIDEOINFOHEADER *format = (VIDEOINFOHEADER *)pin->pin.pin.mt.pbFormat; + buffer_size = format->bmiHeader.biSizeImage; + } + else if (IsEqualGUID(&pin->pin.pin.mt.formattype, &FORMAT_WaveFormatEx)) + { + WAVEFORMATEX *format = (WAVEFORMATEX *)pin->pin.pin.mt.pbFormat; + buffer_size = format->nAvgBytesPerSec; } - else - hr = VFW_E_NO_ALLOCATOR;
- return hr; + props->cBuffers = max(props->cBuffers, 1); + props->cbBuffer = max(props->cbBuffer, buffer_size); + props->cbAlign = max(props->cbAlign, 1); + return IMemAllocator_SetProperties(allocator, props, &ret_props); }
static void free_source_pin(struct gstdemux_source *pin) @@ -2155,8 +2102,8 @@ static const struct strmbase_source_ops source_ops = .base.pin_query_accept = source_query_accept, .base.pin_get_media_type = source_get_media_type, .pfnAttemptConnection = BaseOutputPinImpl_AttemptConnection, + .pfnDecideAllocator = BaseOutputPinImpl_DecideAllocator, .pfnDecideBufferSize = GSTOutPin_DecideBufferSize, - .pfnDecideAllocator = GSTOutPin_DecideAllocator, };
static struct gstdemux_source *create_pin(struct gstdemux *filter, const WCHAR *name)