Signed-off-by: Derek Lesho dlesho@codeweavers.com --- v2: Reorganize function to avoid having a conditionally initialized variable. --- dlls/winegstreamer/colorconvert.c | 82 ++++++++++++++++++++++++++++++- 1 file changed, 80 insertions(+), 2 deletions(-)
diff --git a/dlls/winegstreamer/colorconvert.c b/dlls/winegstreamer/colorconvert.c index 9a1d2880234..a7660453766 100644 --- a/dlls/winegstreamer/colorconvert.c +++ b/dlls/winegstreamer/colorconvert.c @@ -52,6 +52,8 @@ struct color_converter { IMFTransform IMFTransform_iface; LONG refcount; + IMFMediaType *input_type; + CRITICAL_SECTION cs; };
static struct color_converter *impl_color_converter_from_IMFTransform(IMFTransform *iface) @@ -95,6 +97,8 @@ static ULONG WINAPI color_converter_Release(IMFTransform *iface)
if (!refcount) { + transform->cs.DebugInfo->Spare[0] = 0; + DeleteCriticalSection(&transform->cs); heap_free(transform); }
@@ -223,9 +227,80 @@ static HRESULT WINAPI color_converter_GetOutputAvailableType(IMFTransform *iface
static HRESULT WINAPI color_converter_SetInputType(IMFTransform *iface, DWORD id, IMFMediaType *type, DWORD flags) { - FIXME("%p, %u, %p, %#x.\n", iface, id, type, flags); + GUID major_type, subtype; + GstCaps *input_caps; + unsigned int i; + HRESULT hr;
- return E_NOTIMPL; + struct color_converter *converter = impl_color_converter_from_IMFTransform(iface); + + TRACE("%p, %u, %p, %#x.\n", iface, id, type, flags); + + if (id != 0) + return MF_E_INVALIDSTREAMNUMBER; + + if (!type) + { + if (flags & MFT_SET_TYPE_TEST_ONLY) + return S_OK; + + EnterCriticalSection(&converter->cs); + + if (converter->input_type) + { + IMFMediaType_Release(converter->input_type); + converter->input_type = NULL; + } + + LeaveCriticalSection(&converter->cs); + + return S_OK; + } + + if (FAILED(IMFMediaType_GetGUID(type, &MF_MT_MAJOR_TYPE, &major_type))) + return MF_E_INVALIDTYPE; + if (FAILED(IMFMediaType_GetGUID(type, &MF_MT_SUBTYPE, &subtype))) + return MF_E_INVALIDTYPE; + + if (!(IsEqualGUID(&major_type, &MFMediaType_Video))) + return MF_E_INVALIDTYPE; + + for (i = 0; i < ARRAY_SIZE(raw_types); i++) + { + if (IsEqualGUID(&subtype, raw_types[i])) + break; + } + + if (i == ARRAY_SIZE(raw_types)) + return MF_E_INVALIDTYPE; + + if (!(input_caps = caps_from_mf_media_type(type))) + return MF_E_INVALIDTYPE; + + gst_caps_unref(input_caps); + + if (flags & MFT_SET_TYPE_TEST_ONLY) + return S_OK; + + EnterCriticalSection(&converter->cs); + + hr = S_OK; + + if (!converter->input_type) + hr = MFCreateMediaType(&converter->input_type); + + if (SUCCEEDED(hr)) + hr = IMFMediaType_CopyAllItems(type, (IMFAttributes *) converter->input_type); + + if (FAILED(hr)) + { + IMFMediaType_Release(converter->input_type); + converter->input_type = NULL; + } + + LeaveCriticalSection(&converter->cs); + + return hr; }
static HRESULT WINAPI color_converter_SetOutputType(IMFTransform *iface, DWORD id, IMFMediaType *type, DWORD flags) @@ -341,6 +416,9 @@ HRESULT color_converter_create(REFIID riid, void **ret) object->IMFTransform_iface.lpVtbl = &color_converter_vtbl; object->refcount = 1;
+ InitializeCriticalSection(&object->cs); + object->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": color_converter_lock"); + *ret = &object->IMFTransform_iface; return S_OK; }