win32u: Don't report cloned monitors in EnumDisplayMonitors().
[wine.git] / dlls / winegstreamer / color_convert.c
blob66a86aa46029b1a3ccd835aebf207b6e77e0c837
1 /* Copyright 2022 RĂ©mi Bernon for CodeWeavers
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or (at your option) any later version.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18 #include "gst_private.h"
20 #include "mfapi.h"
21 #include "mferror.h"
22 #include "mfobjects.h"
23 #include "mftransform.h"
24 #include "wmcodecdsp.h"
26 #include "wine/debug.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(mfplat);
29 WINE_DECLARE_DEBUG_CHANNEL(winediag);
31 static const GUID *const input_types[] =
33 &MFVideoFormat_YV12,
34 &MFVideoFormat_YUY2,
35 &MFVideoFormat_UYVY,
36 &MFVideoFormat_AYUV,
37 &MFVideoFormat_NV12,
38 &MFVideoFormat_RGB32,
39 &MFVideoFormat_RGB565,
40 &MFVideoFormat_I420,
41 &MFVideoFormat_IYUV,
42 &MFVideoFormat_YVYU,
43 &MFVideoFormat_RGB24,
44 &MFVideoFormat_RGB555,
45 &MEDIASUBTYPE_RGB8,
46 &MEDIASUBTYPE_V216,
47 &MEDIASUBTYPE_V410,
48 &MFVideoFormat_NV11,
49 &MFVideoFormat_Y41P,
50 &MFVideoFormat_Y41T,
51 &MFVideoFormat_Y42T,
52 &MFVideoFormat_YVU9,
54 static const GUID *const output_types[] =
56 &MFVideoFormat_YV12,
57 &MFVideoFormat_YUY2,
58 &MFVideoFormat_UYVY,
59 &MFVideoFormat_AYUV,
60 &MFVideoFormat_NV12,
61 &MFVideoFormat_RGB32,
62 &MFVideoFormat_RGB565,
63 &MFVideoFormat_I420,
64 &MFVideoFormat_IYUV,
65 &MFVideoFormat_YVYU,
66 &MFVideoFormat_RGB24,
67 &MFVideoFormat_RGB555,
68 &MEDIASUBTYPE_RGB8,
69 &MEDIASUBTYPE_V216,
70 &MEDIASUBTYPE_V410,
71 &MFVideoFormat_NV11,
74 struct color_convert
76 IUnknown IUnknown_inner;
77 IMFTransform IMFTransform_iface;
78 IMediaObject IMediaObject_iface;
79 IPropertyBag IPropertyBag_iface;
80 IPropertyStore IPropertyStore_iface;
81 IUnknown *outer;
82 LONG refcount;
83 IMFMediaType *input_type;
84 IMFMediaType *output_type;
86 struct wg_transform *wg_transform;
87 struct wg_sample_queue *wg_sample_queue;
90 static inline struct color_convert *impl_from_IUnknown(IUnknown *iface)
92 return CONTAINING_RECORD(iface, struct color_convert, IUnknown_inner);
95 static HRESULT try_create_wg_transform(struct color_convert *impl)
97 struct wg_format input_format, output_format;
99 if (impl->wg_transform)
100 wg_transform_destroy(impl->wg_transform);
101 impl->wg_transform = NULL;
103 mf_media_type_to_wg_format(impl->input_type, &input_format);
104 if (input_format.major_type == WG_MAJOR_TYPE_UNKNOWN)
105 return MF_E_INVALIDMEDIATYPE;
107 mf_media_type_to_wg_format(impl->output_type, &output_format);
108 if (output_format.major_type == WG_MAJOR_TYPE_UNKNOWN)
109 return MF_E_INVALIDMEDIATYPE;
111 if (!(impl->wg_transform = wg_transform_create(&input_format, &output_format)))
112 return E_FAIL;
114 return S_OK;
117 static HRESULT WINAPI unknown_QueryInterface(IUnknown *iface, REFIID iid, void **out)
119 struct color_convert *impl = impl_from_IUnknown(iface);
121 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
123 if (IsEqualGUID(iid, &IID_IUnknown))
124 *out = &impl->IUnknown_inner;
125 else if (IsEqualGUID(iid, &IID_IMFTransform))
126 *out = &impl->IMFTransform_iface;
127 else if (IsEqualGUID(iid, &IID_IMediaObject))
128 *out = &impl->IMediaObject_iface;
129 else if (IsEqualIID(iid, &IID_IPropertyBag))
130 *out = &impl->IPropertyBag_iface;
131 else if (IsEqualIID(iid, &IID_IPropertyStore))
132 *out = &impl->IPropertyStore_iface;
133 else
135 *out = NULL;
136 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
137 return E_NOINTERFACE;
140 IUnknown_AddRef((IUnknown *)*out);
141 return S_OK;
144 static ULONG WINAPI unknown_AddRef(IUnknown *iface)
146 struct color_convert *impl = impl_from_IUnknown(iface);
147 ULONG refcount = InterlockedIncrement(&impl->refcount);
149 TRACE("iface %p increasing refcount to %lu.\n", iface, refcount);
151 return refcount;
154 static ULONG WINAPI unknown_Release(IUnknown *iface)
156 struct color_convert *impl = impl_from_IUnknown(iface);
157 ULONG refcount = InterlockedDecrement(&impl->refcount);
159 TRACE("iface %p decreasing refcount to %lu.\n", iface, refcount);
161 if (!refcount)
163 if (impl->wg_transform)
164 wg_transform_destroy(impl->wg_transform);
165 if (impl->input_type)
166 IMFMediaType_Release(impl->input_type);
167 if (impl->output_type)
168 IMFMediaType_Release(impl->output_type);
170 wg_sample_queue_destroy(impl->wg_sample_queue);
171 free(impl);
174 return refcount;
177 static const IUnknownVtbl unknown_vtbl =
179 unknown_QueryInterface,
180 unknown_AddRef,
181 unknown_Release,
184 static struct color_convert *impl_from_IMFTransform(IMFTransform *iface)
186 return CONTAINING_RECORD(iface, struct color_convert, IMFTransform_iface);
189 static HRESULT WINAPI transform_QueryInterface(IMFTransform *iface, REFIID iid, void **out)
191 return IUnknown_QueryInterface(impl_from_IMFTransform(iface)->outer, iid, out);
194 static ULONG WINAPI transform_AddRef(IMFTransform *iface)
196 return IUnknown_AddRef(impl_from_IMFTransform(iface)->outer);
199 static ULONG WINAPI transform_Release(IMFTransform *iface)
201 return IUnknown_Release(impl_from_IMFTransform(iface)->outer);
204 static HRESULT WINAPI transform_GetStreamLimits(IMFTransform *iface, DWORD *input_minimum,
205 DWORD *input_maximum, DWORD *output_minimum, DWORD *output_maximum)
207 TRACE("iface %p, input_minimum %p, input_maximum %p, output_minimum %p, output_maximum %p.\n",
208 iface, input_minimum, input_maximum, output_minimum, output_maximum);
209 *input_minimum = *input_maximum = *output_minimum = *output_maximum = 1;
210 return S_OK;
213 static HRESULT WINAPI transform_GetStreamCount(IMFTransform *iface, DWORD *inputs, DWORD *outputs)
215 TRACE("iface %p, inputs %p, outputs %p.\n", iface, inputs, outputs);
216 *inputs = *outputs = 1;
217 return S_OK;
220 static HRESULT WINAPI transform_GetStreamIDs(IMFTransform *iface, DWORD input_size, DWORD *inputs,
221 DWORD output_size, DWORD *outputs)
223 FIXME("iface %p, input_size %lu, inputs %p, output_size %lu, outputs %p stub!\n", iface,
224 input_size, inputs, output_size, outputs);
225 return E_NOTIMPL;
228 static HRESULT WINAPI transform_GetInputStreamInfo(IMFTransform *iface, DWORD id, MFT_INPUT_STREAM_INFO *info)
230 struct color_convert *impl = impl_from_IMFTransform(iface);
231 UINT32 sample_size;
232 UINT64 framesize;
233 GUID subtype;
234 HRESULT hr;
236 TRACE("iface %p, id %#lx, info %p.\n", iface, id, info);
238 if (!impl->input_type || !impl->output_type)
239 return MF_E_TRANSFORM_TYPE_NOT_SET;
241 if (SUCCEEDED(hr = IMFMediaType_GetGUID(impl->input_type, &MF_MT_SUBTYPE, &subtype)) &&
242 SUCCEEDED(hr = IMFMediaType_GetUINT64(impl->input_type, &MF_MT_FRAME_SIZE, &framesize)))
243 MFCalculateImageSize(&subtype, framesize >> 32, (UINT32)framesize, &sample_size);
244 else
245 sample_size = 0;
247 info->dwFlags = 0;
248 info->cbSize = sample_size;
249 info->cbAlignment = 1;
250 info->hnsMaxLatency = 0;
251 info->cbMaxLookahead = 0;
253 return S_OK;
256 static HRESULT WINAPI transform_GetOutputStreamInfo(IMFTransform *iface, DWORD id, MFT_OUTPUT_STREAM_INFO *info)
258 struct color_convert *impl = impl_from_IMFTransform(iface);
259 UINT32 sample_size;
260 UINT64 framesize;
261 GUID subtype;
262 HRESULT hr;
264 TRACE("iface %p, id %#lx, info %p.\n", iface, id, info);
266 if (!impl->input_type || !impl->output_type)
267 return MF_E_TRANSFORM_TYPE_NOT_SET;
269 if (SUCCEEDED(hr = IMFMediaType_GetGUID(impl->output_type, &MF_MT_SUBTYPE, &subtype)) &&
270 SUCCEEDED(hr = IMFMediaType_GetUINT64(impl->output_type, &MF_MT_FRAME_SIZE, &framesize)))
271 MFCalculateImageSize(&subtype, framesize >> 32, (UINT32)framesize, &sample_size);
272 else
273 sample_size = 0;
275 info->dwFlags = 0;
276 info->cbSize = sample_size;
277 info->cbAlignment = 1;
279 return S_OK;
282 static HRESULT WINAPI transform_GetAttributes(IMFTransform *iface, IMFAttributes **attributes)
284 FIXME("iface %p, attributes %p stub!\n", iface, attributes);
285 return E_NOTIMPL;
288 static HRESULT WINAPI transform_GetInputStreamAttributes(IMFTransform *iface, DWORD id, IMFAttributes **attributes)
290 FIXME("iface %p, id %#lx, attributes %p stub!\n", iface, id, attributes);
291 return MFCreateAttributes(attributes, 0);
294 static HRESULT WINAPI transform_GetOutputStreamAttributes(IMFTransform *iface, DWORD id, IMFAttributes **attributes)
296 FIXME("iface %p, id %#lx, attributes %p stub!\n", iface, id, attributes);
297 return E_NOTIMPL;
300 static HRESULT WINAPI transform_DeleteInputStream(IMFTransform *iface, DWORD id)
302 FIXME("iface %p, id %#lx stub!\n", iface, id);
303 return E_NOTIMPL;
306 static HRESULT WINAPI transform_AddInputStreams(IMFTransform *iface, DWORD streams, DWORD *ids)
308 FIXME("iface %p, streams %lu, ids %p stub!\n", iface, streams, ids);
309 return E_NOTIMPL;
312 static HRESULT WINAPI transform_GetInputAvailableType(IMFTransform *iface, DWORD id, DWORD index,
313 IMFMediaType **type)
315 IMFMediaType *media_type;
316 const GUID *subtype;
317 HRESULT hr;
319 TRACE("iface %p, id %#lx, index %#lx, type %p.\n", iface, id, index, type);
321 *type = NULL;
323 if (index >= ARRAY_SIZE(input_types))
324 return MF_E_NO_MORE_TYPES;
325 subtype = input_types[index];
327 if (FAILED(hr = MFCreateMediaType(&media_type)))
328 return hr;
330 if (FAILED(hr = IMFMediaType_SetGUID(media_type, &MF_MT_MAJOR_TYPE, &MFMediaType_Video)))
331 goto done;
332 if (FAILED(hr = IMFMediaType_SetGUID(media_type, &MF_MT_SUBTYPE, subtype)))
333 goto done;
334 if (FAILED(hr = IMFMediaType_SetUINT32(media_type, &MF_MT_FIXED_SIZE_SAMPLES, 1)))
335 goto done;
336 if (FAILED(hr = IMFMediaType_SetUINT32(media_type, &MF_MT_ALL_SAMPLES_INDEPENDENT, 1)))
337 goto done;
339 IMFMediaType_AddRef((*type = media_type));
341 done:
342 IMFMediaType_Release(media_type);
343 return hr;
346 static HRESULT WINAPI transform_GetOutputAvailableType(IMFTransform *iface, DWORD id, DWORD index,
347 IMFMediaType **type)
349 IMFMediaType *media_type;
350 const GUID *subtype;
351 HRESULT hr;
353 TRACE("iface %p, id %#lx, index %#lx, type %p.\n", iface, id, index, type);
355 *type = NULL;
357 if (index >= ARRAY_SIZE(output_types))
358 return MF_E_NO_MORE_TYPES;
359 subtype = output_types[index];
361 if (FAILED(hr = MFCreateMediaType(&media_type)))
362 return hr;
364 if (FAILED(hr = IMFMediaType_SetGUID(media_type, &MF_MT_MAJOR_TYPE, &MFMediaType_Video)))
365 goto done;
366 if (FAILED(hr = IMFMediaType_SetGUID(media_type, &MF_MT_SUBTYPE, subtype)))
367 goto done;
368 if (FAILED(hr = IMFMediaType_SetUINT32(media_type, &MF_MT_FIXED_SIZE_SAMPLES, 1)))
369 goto done;
370 if (FAILED(hr = IMFMediaType_SetUINT32(media_type, &MF_MT_ALL_SAMPLES_INDEPENDENT, 1)))
371 goto done;
373 IMFMediaType_AddRef((*type = media_type));
375 done:
376 IMFMediaType_Release(media_type);
377 return hr;
380 static HRESULT WINAPI transform_SetInputType(IMFTransform *iface, DWORD id, IMFMediaType *type, DWORD flags)
382 struct color_convert *impl = impl_from_IMFTransform(iface);
383 MF_ATTRIBUTE_TYPE item_type;
384 GUID major, subtype;
385 HRESULT hr;
386 ULONG i;
388 TRACE("iface %p, id %#lx, type %p, flags %#lx.\n", iface, id, type, flags);
390 if (FAILED(hr = IMFMediaType_GetGUID(type, &MF_MT_MAJOR_TYPE, &major)) ||
391 FAILED(hr = IMFMediaType_GetGUID(type, &MF_MT_SUBTYPE, &subtype)))
392 return MF_E_ATTRIBUTENOTFOUND;
394 if (!IsEqualGUID(&major, &MFMediaType_Video)
395 || FAILED(IMFMediaType_GetItemType(type, &MF_MT_FRAME_SIZE, &item_type))
396 || item_type != MF_ATTRIBUTE_UINT64)
397 return E_INVALIDARG;
399 for (i = 0; i < ARRAY_SIZE(input_types); ++i)
400 if (IsEqualGUID(&subtype, input_types[i]))
401 break;
402 if (i == ARRAY_SIZE(input_types))
403 return MF_E_INVALIDMEDIATYPE;
405 if (!impl->input_type && FAILED(hr = MFCreateMediaType(&impl->input_type)))
406 return hr;
408 if (FAILED(hr = IMFMediaType_CopyAllItems(type, (IMFAttributes *)impl->input_type)))
410 IMFMediaType_Release(impl->input_type);
411 impl->input_type = NULL;
414 if (impl->output_type && FAILED(hr = try_create_wg_transform(impl)))
416 IMFMediaType_Release(impl->input_type);
417 impl->input_type = NULL;
420 return hr;
423 static HRESULT WINAPI transform_SetOutputType(IMFTransform *iface, DWORD id, IMFMediaType *type, DWORD flags)
425 struct color_convert *impl = impl_from_IMFTransform(iface);
426 MF_ATTRIBUTE_TYPE item_type;
427 GUID major, subtype;
428 HRESULT hr;
429 ULONG i;
431 TRACE("iface %p, id %#lx, type %p, flags %#lx.\n", iface, id, type, flags);
433 if (FAILED(hr = IMFMediaType_GetGUID(type, &MF_MT_MAJOR_TYPE, &major)) ||
434 FAILED(hr = IMFMediaType_GetGUID(type, &MF_MT_SUBTYPE, &subtype)))
435 return MF_E_ATTRIBUTENOTFOUND;
437 if (!IsEqualGUID(&major, &MFMediaType_Video)
438 || FAILED(IMFMediaType_GetItemType(type, &MF_MT_FRAME_SIZE, &item_type))
439 || item_type != MF_ATTRIBUTE_UINT64)
440 return E_INVALIDARG;
442 for (i = 0; i < ARRAY_SIZE(output_types); ++i)
443 if (IsEqualGUID(&subtype, output_types[i]))
444 break;
445 if (i == ARRAY_SIZE(output_types))
446 return MF_E_INVALIDMEDIATYPE;
448 if (!impl->output_type && FAILED(hr = MFCreateMediaType(&impl->output_type)))
449 return hr;
451 if (FAILED(hr = IMFMediaType_CopyAllItems(type, (IMFAttributes *)impl->output_type)))
453 IMFMediaType_Release(impl->output_type);
454 impl->output_type = NULL;
457 if (impl->input_type && FAILED(hr = try_create_wg_transform(impl)))
459 IMFMediaType_Release(impl->output_type);
460 impl->output_type = NULL;
463 return hr;
466 static HRESULT WINAPI transform_GetInputCurrentType(IMFTransform *iface, DWORD id, IMFMediaType **type)
468 struct color_convert *impl = impl_from_IMFTransform(iface);
469 IMFMediaType *ret;
470 HRESULT hr;
472 TRACE("iface %p, id %#lx, type %p.\n", iface, id, type);
474 if (id != 0)
475 return MF_E_INVALIDSTREAMNUMBER;
477 if (!impl->input_type)
478 return MF_E_TRANSFORM_TYPE_NOT_SET;
480 if (FAILED(hr = MFCreateMediaType(&ret)))
481 return hr;
483 return IMFMediaType_CopyAllItems(impl->input_type, (IMFAttributes *)ret);
486 static HRESULT WINAPI transform_GetOutputCurrentType(IMFTransform *iface, DWORD id, IMFMediaType **type)
488 struct color_convert *impl = impl_from_IMFTransform(iface);
489 IMFMediaType *ret;
490 HRESULT hr;
492 TRACE("iface %p, id %#lx, type %p.\n", iface, id, type);
494 if (id != 0)
495 return MF_E_INVALIDSTREAMNUMBER;
497 if (!impl->output_type)
498 return MF_E_TRANSFORM_TYPE_NOT_SET;
500 if (FAILED(hr = MFCreateMediaType(&ret)))
501 return hr;
503 return IMFMediaType_CopyAllItems(impl->output_type, (IMFAttributes *)ret);
506 static HRESULT WINAPI transform_GetInputStatus(IMFTransform *iface, DWORD id, DWORD *flags)
508 FIXME("iface %p, id %#lx, flags %p stub!\n", iface, id, flags);
509 return E_NOTIMPL;
512 static HRESULT WINAPI transform_GetOutputStatus(IMFTransform *iface, DWORD *flags)
514 FIXME("iface %p, flags %p stub!\n", iface, flags);
515 return E_NOTIMPL;
518 static HRESULT WINAPI transform_SetOutputBounds(IMFTransform *iface, LONGLONG lower, LONGLONG upper)
520 FIXME("iface %p, lower %I64d, upper %I64d stub!\n", iface, lower, upper);
521 return E_NOTIMPL;
524 static HRESULT WINAPI transform_ProcessEvent(IMFTransform *iface, DWORD id, IMFMediaEvent *event)
526 FIXME("iface %p, id %#lx, event %p stub!\n", iface, id, event);
527 return E_NOTIMPL;
530 static HRESULT WINAPI transform_ProcessMessage(IMFTransform *iface, MFT_MESSAGE_TYPE message, ULONG_PTR param)
532 FIXME("iface %p, message %#x, param %#Ix stub!\n", iface, message, param);
533 return S_OK;
536 static HRESULT WINAPI transform_ProcessInput(IMFTransform *iface, DWORD id, IMFSample *sample, DWORD flags)
538 struct color_convert *impl = impl_from_IMFTransform(iface);
539 struct wg_sample *wg_sample;
540 MFT_INPUT_STREAM_INFO info;
541 HRESULT hr;
543 TRACE("iface %p, id %#lx, sample %p, flags %#lx.\n", iface, id, sample, flags);
545 if (FAILED(hr = IMFTransform_GetInputStreamInfo(iface, 0, &info)))
546 return hr;
548 if (!impl->wg_transform)
549 return MF_E_TRANSFORM_TYPE_NOT_SET;
551 if (FAILED(hr = wg_sample_create_mf(sample, &wg_sample)))
552 return hr;
554 return wg_transform_push_mf(impl->wg_transform, wg_sample,
555 impl->wg_sample_queue);
558 static HRESULT WINAPI transform_ProcessOutput(IMFTransform *iface, DWORD flags, DWORD count,
559 MFT_OUTPUT_DATA_BUFFER *samples, DWORD *status)
561 struct color_convert *impl = impl_from_IMFTransform(iface);
562 MFT_OUTPUT_STREAM_INFO info;
563 struct wg_sample *wg_sample;
564 HRESULT hr;
566 TRACE("iface %p, flags %#lx, count %lu, samples %p, status %p.\n", iface, flags, count, samples, status);
568 if (count != 1)
569 return E_INVALIDARG;
571 if (FAILED(hr = IMFTransform_GetOutputStreamInfo(iface, 0, &info)))
572 return hr;
574 if (!impl->wg_transform)
575 return MF_E_TRANSFORM_TYPE_NOT_SET;
577 *status = 0;
578 samples[0].dwStatus = 0;
579 if (!samples[0].pSample) return E_INVALIDARG;
581 if (FAILED(hr = wg_sample_create_mf(samples[0].pSample, &wg_sample)))
582 return hr;
584 if (wg_sample->max_size < info.cbSize)
586 wg_sample_release(wg_sample);
587 return MF_E_BUFFERTOOSMALL;
590 if (SUCCEEDED(hr = wg_transform_read_mf(impl->wg_transform, wg_sample, NULL)))
591 wg_sample_queue_flush(impl->wg_sample_queue, false);
592 wg_sample_release(wg_sample);
594 if (hr == MF_E_TRANSFORM_STREAM_CHANGE)
596 FIXME("Unexpected stream format change!\n");
597 samples[0].dwStatus |= MFT_OUTPUT_DATA_BUFFER_FORMAT_CHANGE;
598 *status |= MFT_OUTPUT_DATA_BUFFER_FORMAT_CHANGE;
601 return hr;
604 static const IMFTransformVtbl transform_vtbl =
606 transform_QueryInterface,
607 transform_AddRef,
608 transform_Release,
609 transform_GetStreamLimits,
610 transform_GetStreamCount,
611 transform_GetStreamIDs,
612 transform_GetInputStreamInfo,
613 transform_GetOutputStreamInfo,
614 transform_GetAttributes,
615 transform_GetInputStreamAttributes,
616 transform_GetOutputStreamAttributes,
617 transform_DeleteInputStream,
618 transform_AddInputStreams,
619 transform_GetInputAvailableType,
620 transform_GetOutputAvailableType,
621 transform_SetInputType,
622 transform_SetOutputType,
623 transform_GetInputCurrentType,
624 transform_GetOutputCurrentType,
625 transform_GetInputStatus,
626 transform_GetOutputStatus,
627 transform_SetOutputBounds,
628 transform_ProcessEvent,
629 transform_ProcessMessage,
630 transform_ProcessInput,
631 transform_ProcessOutput,
634 static inline struct color_convert *impl_from_IMediaObject(IMediaObject *iface)
636 return CONTAINING_RECORD(iface, struct color_convert, IMediaObject_iface);
639 static HRESULT WINAPI media_object_QueryInterface(IMediaObject *iface, REFIID iid, void **obj)
641 return IUnknown_QueryInterface(impl_from_IMediaObject(iface)->outer, iid, obj);
644 static ULONG WINAPI media_object_AddRef(IMediaObject *iface)
646 return IUnknown_AddRef(impl_from_IMediaObject(iface)->outer);
649 static ULONG WINAPI media_object_Release(IMediaObject *iface)
651 return IUnknown_Release(impl_from_IMediaObject(iface)->outer);
654 static HRESULT WINAPI media_object_GetStreamCount(IMediaObject *iface, DWORD *input, DWORD *output)
656 FIXME("iface %p, input %p, output %p stub!\n", iface, input, output);
657 return E_NOTIMPL;
660 static HRESULT WINAPI media_object_GetInputStreamInfo(IMediaObject *iface, DWORD index, DWORD *flags)
662 FIXME("iface %p, index %lu, flags %p stub!\n", iface, index, flags);
663 return E_NOTIMPL;
666 static HRESULT WINAPI media_object_GetOutputStreamInfo(IMediaObject *iface, DWORD index, DWORD *flags)
668 FIXME("iface %p, index %lu, flags %p stub!\n", iface, index, flags);
669 return E_NOTIMPL;
672 static HRESULT WINAPI media_object_GetInputType(IMediaObject *iface, DWORD index, DWORD type_index,
673 DMO_MEDIA_TYPE *type)
675 FIXME("iface %p, index %lu, type_index %lu, type %p stub!\n", iface, index, type_index, type);
676 return E_NOTIMPL;
679 static HRESULT WINAPI media_object_GetOutputType(IMediaObject *iface, DWORD index, DWORD type_index,
680 DMO_MEDIA_TYPE *type)
682 FIXME("iface %p, index %lu, type_index %lu, type %p stub!\n", iface, index, type_index, type);
683 return E_NOTIMPL;
686 static HRESULT WINAPI media_object_SetInputType(IMediaObject *iface, DWORD index,
687 const DMO_MEDIA_TYPE *type, DWORD flags)
689 FIXME("iface %p, index %lu, type %p, flags %#lx stub!\n", iface, index, type, flags);
690 return E_NOTIMPL;
693 static HRESULT WINAPI media_object_SetOutputType(IMediaObject *iface, DWORD index,
694 const DMO_MEDIA_TYPE *type, DWORD flags)
696 FIXME("iface %p, index %lu, type %p, flags %#lx stub!\n", iface, index, type, flags);
697 return E_NOTIMPL;
700 static HRESULT WINAPI media_object_GetInputCurrentType(IMediaObject *iface, DWORD index, DMO_MEDIA_TYPE *type)
702 FIXME("iface %p, index %lu, type %p stub!\n", iface, index, type);
703 return E_NOTIMPL;
706 static HRESULT WINAPI media_object_GetOutputCurrentType(IMediaObject *iface, DWORD index, DMO_MEDIA_TYPE *type)
708 FIXME("iface %p, index %lu, type %p stub!\n", iface, index, type);
709 return E_NOTIMPL;
712 static HRESULT WINAPI media_object_GetInputSizeInfo(IMediaObject *iface, DWORD index, DWORD *size,
713 DWORD *lookahead, DWORD *alignment)
715 FIXME("iface %p, index %lu, size %p, lookahead %p, alignment %p stub!\n", iface, index, size,
716 lookahead, alignment);
717 return E_NOTIMPL;
720 static HRESULT WINAPI media_object_GetOutputSizeInfo(IMediaObject *iface, DWORD index, DWORD *size, DWORD *alignment)
722 FIXME("iface %p, index %lu, size %p, alignment %p stub!\n", iface, index, size, alignment);
723 return E_NOTIMPL;
726 static HRESULT WINAPI media_object_GetInputMaxLatency(IMediaObject *iface, DWORD index, REFERENCE_TIME *latency)
728 FIXME("iface %p, index %lu, latency %p stub!\n", iface, index, latency);
729 return E_NOTIMPL;
732 static HRESULT WINAPI media_object_SetInputMaxLatency(IMediaObject *iface, DWORD index, REFERENCE_TIME latency)
734 FIXME("iface %p, index %lu, latency %s stub!\n", iface, index, wine_dbgstr_longlong(latency));
735 return E_NOTIMPL;
738 static HRESULT WINAPI media_object_Flush(IMediaObject *iface)
740 FIXME("iface %p stub!\n", iface);
741 return E_NOTIMPL;
744 static HRESULT WINAPI media_object_Discontinuity(IMediaObject *iface, DWORD index)
746 FIXME("iface %p, index %lu stub!\n", iface, index);
747 return E_NOTIMPL;
750 static HRESULT WINAPI media_object_AllocateStreamingResources(IMediaObject *iface)
752 FIXME("iface %p stub!\n", iface);
753 return E_NOTIMPL;
756 static HRESULT WINAPI media_object_FreeStreamingResources(IMediaObject *iface)
758 FIXME("iface %p stub!\n", iface);
759 return E_NOTIMPL;
762 static HRESULT WINAPI media_object_GetInputStatus(IMediaObject *iface, DWORD index, DWORD *flags)
764 FIXME("iface %p, index %lu, flags %p stub!\n", iface, index, flags);
765 return E_NOTIMPL;
768 static HRESULT WINAPI media_object_ProcessInput(IMediaObject *iface, DWORD index,
769 IMediaBuffer *buffer, DWORD flags, REFERENCE_TIME timestamp, REFERENCE_TIME timelength)
771 FIXME("iface %p, index %lu, buffer %p, flags %#lx, timestamp %s, timelength %s stub!\n", iface,
772 index, buffer, flags, wine_dbgstr_longlong(timestamp), wine_dbgstr_longlong(timelength));
773 return E_NOTIMPL;
776 static HRESULT WINAPI media_object_ProcessOutput(IMediaObject *iface, DWORD flags, DWORD count,
777 DMO_OUTPUT_DATA_BUFFER *buffers, DWORD *status)
779 FIXME("iface %p, flags %#lx, count %lu, buffers %p, status %p stub!\n", iface, flags, count, buffers, status);
780 return E_NOTIMPL;
783 static HRESULT WINAPI media_object_Lock(IMediaObject *iface, LONG lock)
785 FIXME("iface %p, lock %ld stub!\n", iface, lock);
786 return E_NOTIMPL;
789 static const IMediaObjectVtbl media_object_vtbl =
791 media_object_QueryInterface,
792 media_object_AddRef,
793 media_object_Release,
794 media_object_GetStreamCount,
795 media_object_GetInputStreamInfo,
796 media_object_GetOutputStreamInfo,
797 media_object_GetInputType,
798 media_object_GetOutputType,
799 media_object_SetInputType,
800 media_object_SetOutputType,
801 media_object_GetInputCurrentType,
802 media_object_GetOutputCurrentType,
803 media_object_GetInputSizeInfo,
804 media_object_GetOutputSizeInfo,
805 media_object_GetInputMaxLatency,
806 media_object_SetInputMaxLatency,
807 media_object_Flush,
808 media_object_Discontinuity,
809 media_object_AllocateStreamingResources,
810 media_object_FreeStreamingResources,
811 media_object_GetInputStatus,
812 media_object_ProcessInput,
813 media_object_ProcessOutput,
814 media_object_Lock,
817 static inline struct color_convert *impl_from_IPropertyBag(IPropertyBag *iface)
819 return CONTAINING_RECORD(iface, struct color_convert, IPropertyBag_iface);
822 static HRESULT WINAPI property_bag_QueryInterface(IPropertyBag *iface, REFIID iid, void **out)
824 return IUnknown_QueryInterface(impl_from_IPropertyBag(iface)->outer, iid, out);
827 static ULONG WINAPI property_bag_AddRef(IPropertyBag *iface)
829 return IUnknown_AddRef(impl_from_IPropertyBag(iface)->outer);
832 static ULONG WINAPI property_bag_Release(IPropertyBag *iface)
834 return IUnknown_Release(impl_from_IPropertyBag(iface)->outer);
837 static HRESULT WINAPI property_bag_Read(IPropertyBag *iface, const WCHAR *prop_name, VARIANT *value,
838 IErrorLog *error_log)
840 FIXME("iface %p, prop_name %s, value %p, error_log %p stub!\n", iface, debugstr_w(prop_name), value, error_log);
841 return E_NOTIMPL;
844 static HRESULT WINAPI property_bag_Write(IPropertyBag *iface, const WCHAR *prop_name, VARIANT *value)
846 FIXME("iface %p, prop_name %s, value %p stub!\n", iface, debugstr_w(prop_name), value);
847 return S_OK;
850 static const IPropertyBagVtbl property_bag_vtbl =
852 property_bag_QueryInterface,
853 property_bag_AddRef,
854 property_bag_Release,
855 property_bag_Read,
856 property_bag_Write,
859 static inline struct color_convert *impl_from_IPropertyStore(IPropertyStore *iface)
861 return CONTAINING_RECORD(iface, struct color_convert, IPropertyStore_iface);
864 static HRESULT WINAPI property_store_QueryInterface(IPropertyStore *iface, REFIID iid, void **out)
866 return IUnknown_QueryInterface(impl_from_IPropertyStore(iface)->outer, iid, out);
869 static ULONG WINAPI property_store_AddRef(IPropertyStore *iface)
871 return IUnknown_AddRef(impl_from_IPropertyStore(iface)->outer);
874 static ULONG WINAPI property_store_Release(IPropertyStore *iface)
876 return IUnknown_Release(impl_from_IPropertyStore(iface)->outer);
879 static HRESULT WINAPI property_store_GetCount(IPropertyStore *iface, DWORD *count)
881 FIXME("iface %p, count %p stub!\n", iface, count);
882 return E_NOTIMPL;
885 static HRESULT WINAPI property_store_GetAt(IPropertyStore *iface, DWORD index, PROPERTYKEY *key)
887 FIXME("iface %p, index %lu, key %p stub!\n", iface, index, key);
888 return E_NOTIMPL;
891 static HRESULT WINAPI property_store_GetValue(IPropertyStore *iface, REFPROPERTYKEY key, PROPVARIANT *value)
893 FIXME("iface %p, key %p, value %p stub!\n", iface, key, value);
894 return E_NOTIMPL;
897 static HRESULT WINAPI property_store_SetValue(IPropertyStore *iface, REFPROPERTYKEY key, REFPROPVARIANT value)
899 FIXME("iface %p, key %p, value %p stub!\n", iface, key, value);
900 return E_NOTIMPL;
903 static HRESULT WINAPI property_store_Commit(IPropertyStore *iface)
905 FIXME("iface %p stub!\n", iface);
906 return E_NOTIMPL;
909 static const IPropertyStoreVtbl property_store_vtbl =
911 property_store_QueryInterface,
912 property_store_AddRef,
913 property_store_Release,
914 property_store_GetCount,
915 property_store_GetAt,
916 property_store_GetValue,
917 property_store_SetValue,
918 property_store_Commit,
921 HRESULT color_convert_create(IUnknown *outer, IUnknown **out)
923 static const struct wg_format input_format =
925 .major_type = WG_MAJOR_TYPE_VIDEO,
926 .u.video =
928 .format = WG_VIDEO_FORMAT_I420,
929 .width = 1920,
930 .height = 1080,
933 static const struct wg_format output_format =
935 .major_type = WG_MAJOR_TYPE_VIDEO,
936 .u.video =
938 .format = WG_VIDEO_FORMAT_NV12,
939 .width = 1920,
940 .height = 1080,
943 struct wg_transform *transform;
944 struct color_convert *impl;
945 HRESULT hr;
947 TRACE("outer %p, out %p.\n", outer, out);
949 if (!(transform = wg_transform_create(&input_format, &output_format)))
951 ERR_(winediag)("GStreamer doesn't support video conversion, please install appropriate plugins.\n");
952 return E_FAIL;
954 wg_transform_destroy(transform);
956 if (!(impl = calloc(1, sizeof(*impl))))
957 return E_OUTOFMEMORY;
959 if (FAILED(hr = wg_sample_queue_create(&impl->wg_sample_queue)))
961 free(impl);
962 return hr;
965 impl->IUnknown_inner.lpVtbl = &unknown_vtbl;
966 impl->IMFTransform_iface.lpVtbl = &transform_vtbl;
967 impl->IMediaObject_iface.lpVtbl = &media_object_vtbl;
968 impl->IPropertyBag_iface.lpVtbl = &property_bag_vtbl;
969 impl->IPropertyStore_iface.lpVtbl = &property_store_vtbl;
970 impl->refcount = 1;
971 impl->outer = outer ? outer : &impl->IUnknown_inner;
973 *out = &impl->IUnknown_inner;
974 TRACE("Created %p\n", *out);
975 return S_OK;