evr/mixer: Preserve frame aspect ratio when rendering.
[wine.git] / dlls / evr / mixer.c
blob4f5837a49a4c4b33512301412ba6d9d3d1a7680e
1 /*
2 * Copyright 2020 Nikolay Sivov
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #define COBJMACROS
21 #include "evr.h"
22 #include "d3d9.h"
23 #include "dxva2api.h"
24 #include "mfapi.h"
25 #include "mferror.h"
27 #include "evr_classes.h"
28 #include "evr_private.h"
30 #include "initguid.h"
31 #include "evr9.h"
32 #include "evcode.h"
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(evr);
38 #define MAX_MIXER_INPUT_SUBSTREAMS (15)
39 #define MAX_MIXER_INPUT_STREAMS (MAX_MIXER_INPUT_SUBSTREAMS + 1)
41 struct input_stream
43 unsigned int id;
44 IMFAttributes *attributes;
45 IMFMediaType *media_type;
46 MFVideoNormalizedRect rect;
47 unsigned int zorder;
48 SIZE frame_size;
49 IMFSample *sample;
50 unsigned int sample_requested : 1;
53 struct rt_format
55 GUID device;
56 D3DFORMAT format;
57 IMFMediaType *media_type;
60 struct output_stream
62 IMFMediaType *media_type;
63 struct rt_format *rt_formats;
64 unsigned int rt_formats_count;
67 struct video_mixer
69 IMFTransform IMFTransform_iface;
70 IMFVideoDeviceID IMFVideoDeviceID_iface;
71 IMFTopologyServiceLookupClient IMFTopologyServiceLookupClient_iface;
72 IMFVideoMixerControl2 IMFVideoMixerControl2_iface;
73 IMFGetService IMFGetService_iface;
74 IMFVideoMixerBitmap IMFVideoMixerBitmap_iface;
75 IMFVideoPositionMapper IMFVideoPositionMapper_iface;
76 IMFVideoProcessor IMFVideoProcessor_iface;
77 IMFAttributes IMFAttributes_iface;
78 IMFQualityAdvise IMFQualityAdvise_iface;
79 IMFClockStateSink IMFClockStateSink_iface;
80 IUnknown IUnknown_inner;
81 IUnknown *outer_unk;
82 LONG refcount;
84 struct input_stream inputs[MAX_MIXER_INPUT_STREAMS];
85 unsigned int input_ids[MAX_MIXER_INPUT_STREAMS];
86 struct input_stream *zorder[MAX_MIXER_INPUT_STREAMS];
87 unsigned int input_count;
88 struct output_stream output;
90 IDirect3DDeviceManager9 *device_manager;
91 IDirectXVideoProcessor *processor;
92 HANDLE device_handle;
94 IMediaEventSink *event_sink;
95 IMFAttributes *attributes;
96 IMFAttributes *internal_attributes;
97 unsigned int mixing_flags;
98 unsigned int is_streaming;
99 struct
101 COLORREF rgba;
102 DXVA2_AYUVSample16 ayuv;
103 } bkgnd_color;
104 MFVideoArea aperture;
105 LONGLONG lower_bound;
106 LONGLONG upper_bound;
107 CRITICAL_SECTION cs;
110 static struct video_mixer *impl_from_IUnknown(IUnknown *iface)
112 return CONTAINING_RECORD(iface, struct video_mixer, IUnknown_inner);
115 static struct video_mixer *impl_from_IMFTransform(IMFTransform *iface)
117 return CONTAINING_RECORD(iface, struct video_mixer, IMFTransform_iface);
120 static struct video_mixer *impl_from_IMFVideoDeviceID(IMFVideoDeviceID *iface)
122 return CONTAINING_RECORD(iface, struct video_mixer, IMFVideoDeviceID_iface);
125 static struct video_mixer *impl_from_IMFTopologyServiceLookupClient(IMFTopologyServiceLookupClient *iface)
127 return CONTAINING_RECORD(iface, struct video_mixer, IMFTopologyServiceLookupClient_iface);
130 static struct video_mixer *impl_from_IMFVideoMixerControl2(IMFVideoMixerControl2 *iface)
132 return CONTAINING_RECORD(iface, struct video_mixer, IMFVideoMixerControl2_iface);
135 static struct video_mixer *impl_from_IMFGetService(IMFGetService *iface)
137 return CONTAINING_RECORD(iface, struct video_mixer, IMFGetService_iface);
140 static struct video_mixer *impl_from_IMFVideoMixerBitmap(IMFVideoMixerBitmap *iface)
142 return CONTAINING_RECORD(iface, struct video_mixer, IMFVideoMixerBitmap_iface);
145 static struct video_mixer *impl_from_IMFVideoPositionMapper(IMFVideoPositionMapper *iface)
147 return CONTAINING_RECORD(iface, struct video_mixer, IMFVideoPositionMapper_iface);
150 static struct video_mixer *impl_from_IMFVideoProcessor(IMFVideoProcessor *iface)
152 return CONTAINING_RECORD(iface, struct video_mixer, IMFVideoProcessor_iface);
155 static struct video_mixer *impl_from_IMFAttributes(IMFAttributes *iface)
157 return CONTAINING_RECORD(iface, struct video_mixer, IMFAttributes_iface);
160 static struct video_mixer *impl_from_IMFQualityAdvise(IMFQualityAdvise *iface)
162 return CONTAINING_RECORD(iface, struct video_mixer, IMFQualityAdvise_iface);
165 static struct video_mixer *impl_from_IMFClockStateSink(IMFClockStateSink *iface)
167 return CONTAINING_RECORD(iface, struct video_mixer, IMFClockStateSink_iface);
170 static int __cdecl video_mixer_compare_input_id(const void *a, const void *b)
172 const unsigned int *key = a;
173 const struct input_stream *input = b;
175 if (*key > input->id) return 1;
176 if (*key < input->id) return -1;
177 return 0;
180 static HRESULT video_mixer_get_input(const struct video_mixer *mixer, unsigned int id, struct input_stream **stream)
182 *stream = bsearch(&id, mixer->inputs, mixer->input_count, sizeof(*mixer->inputs), video_mixer_compare_input_id);
183 return *stream ? S_OK : MF_E_INVALIDSTREAMNUMBER;
186 static void video_mixer_init_input(struct input_stream *stream)
188 if (SUCCEEDED(MFCreateAttributes(&stream->attributes, 1)))
189 IMFAttributes_SetUINT32(stream->attributes, &MF_SA_REQUIRED_SAMPLE_COUNT, 1);
190 stream->rect.left = stream->rect.top = 0.0f;
191 stream->rect.right = stream->rect.bottom = 1.0f;
194 static int __cdecl video_mixer_zorder_sort_compare(const void *a, const void *b)
196 const struct input_stream *left = *(void **)a, *right = *(void **)b;
197 return left->zorder != right->zorder ? (left->zorder < right->zorder ? -1 : 1) : 0;
200 static void video_mixer_update_zorder_map(struct video_mixer *mixer)
202 unsigned int i;
204 for (i = 0; i < mixer->input_count; ++i)
205 mixer->zorder[i] = &mixer->inputs[i];
207 qsort(mixer->zorder, mixer->input_count, sizeof(*mixer->zorder), video_mixer_zorder_sort_compare);
210 static void video_mixer_clear_types(struct video_mixer *mixer)
212 unsigned int i;
214 for (i = 0; i < mixer->input_count; ++i)
216 if (mixer->inputs[i].media_type)
217 IMFMediaType_Release(mixer->inputs[i].media_type);
218 mixer->inputs[i].media_type = NULL;
219 if (mixer->inputs[i].sample)
220 IMFSample_Release(mixer->inputs[i].sample);
221 mixer->inputs[i].sample = NULL;
223 for (i = 0; i < mixer->output.rt_formats_count; ++i)
225 IMFMediaType_Release(mixer->output.rt_formats[i].media_type);
227 free(mixer->output.rt_formats);
228 if (mixer->output.media_type)
229 IMFMediaType_Release(mixer->output.media_type);
230 mixer->output.media_type = NULL;
233 static HRESULT WINAPI video_mixer_inner_QueryInterface(IUnknown *iface, REFIID riid, void **obj)
235 struct video_mixer *mixer = impl_from_IUnknown(iface);
237 TRACE("%p, %s, %p.\n", iface, debugstr_guid(riid), obj);
239 if (IsEqualIID(riid, &IID_IUnknown))
241 *obj = iface;
243 else if (IsEqualIID(riid, &IID_IMFTransform))
245 *obj = &mixer->IMFTransform_iface;
247 else if (IsEqualIID(riid, &IID_IMFVideoDeviceID))
249 *obj = &mixer->IMFVideoDeviceID_iface;
251 else if (IsEqualIID(riid, &IID_IMFTopologyServiceLookupClient))
253 *obj = &mixer->IMFTopologyServiceLookupClient_iface;
255 else if (IsEqualIID(riid, &IID_IMFVideoMixerControl2) ||
256 IsEqualIID(riid, &IID_IMFVideoMixerControl))
258 *obj = &mixer->IMFVideoMixerControl2_iface;
260 else if (IsEqualIID(riid, &IID_IMFGetService))
262 *obj = &mixer->IMFGetService_iface;
264 else if (IsEqualIID(riid, &IID_IMFVideoMixerBitmap))
266 *obj = &mixer->IMFVideoMixerBitmap_iface;
268 else if (IsEqualIID(riid, &IID_IMFVideoPositionMapper))
270 *obj = &mixer->IMFVideoPositionMapper_iface;
272 else if (IsEqualIID(riid, &IID_IMFVideoProcessor))
274 *obj = &mixer->IMFVideoProcessor_iface;
276 else if (IsEqualIID(riid, &IID_IMFAttributes))
278 *obj = &mixer->IMFAttributes_iface;
280 else if (IsEqualIID(riid, &IID_IMFQualityAdvise))
282 *obj = &mixer->IMFQualityAdvise_iface;
284 else if (IsEqualIID(riid, &IID_IMFClockStateSink))
286 *obj = &mixer->IMFClockStateSink_iface;
288 else
290 WARN("Unsupported interface %s.\n", debugstr_guid(riid));
291 *obj = NULL;
292 return E_NOINTERFACE;
295 IUnknown_AddRef((IUnknown *)*obj);
296 return S_OK;
299 static ULONG WINAPI video_mixer_inner_AddRef(IUnknown *iface)
301 struct video_mixer *mixer = impl_from_IUnknown(iface);
302 ULONG refcount = InterlockedIncrement(&mixer->refcount);
304 TRACE("%p, refcount %u.\n", iface, refcount);
306 return refcount;
309 static void video_mixer_release_device_manager(struct video_mixer *mixer)
311 if (mixer->processor)
312 IDirectXVideoProcessor_Release(mixer->processor);
313 if (mixer->device_manager)
315 IDirect3DDeviceManager9_CloseDeviceHandle(mixer->device_manager, mixer->device_handle);
316 IDirect3DDeviceManager9_Release(mixer->device_manager);
318 mixer->device_handle = NULL;
319 mixer->device_manager = NULL;
320 mixer->processor = NULL;
323 static ULONG WINAPI video_mixer_inner_Release(IUnknown *iface)
325 struct video_mixer *mixer = impl_from_IUnknown(iface);
326 ULONG refcount = InterlockedDecrement(&mixer->refcount);
327 unsigned int i;
329 TRACE("%p, refcount %u.\n", iface, refcount);
331 if (!refcount)
333 for (i = 0; i < mixer->input_count; ++i)
335 if (mixer->inputs[i].attributes)
336 IMFAttributes_Release(mixer->inputs[i].attributes);
338 video_mixer_clear_types(mixer);
339 video_mixer_release_device_manager(mixer);
340 if (mixer->attributes)
341 IMFAttributes_Release(mixer->attributes);
342 if (mixer->internal_attributes)
343 IMFAttributes_Release(mixer->internal_attributes);
344 DeleteCriticalSection(&mixer->cs);
345 free(mixer);
348 return refcount;
351 static const IUnknownVtbl video_mixer_inner_vtbl =
353 video_mixer_inner_QueryInterface,
354 video_mixer_inner_AddRef,
355 video_mixer_inner_Release,
358 static HRESULT WINAPI video_mixer_transform_QueryInterface(IMFTransform *iface, REFIID riid, void **obj)
360 struct video_mixer *mixer = impl_from_IMFTransform(iface);
361 return IUnknown_QueryInterface(mixer->outer_unk, riid, obj);
364 static ULONG WINAPI video_mixer_transform_AddRef(IMFTransform *iface)
366 struct video_mixer *mixer = impl_from_IMFTransform(iface);
367 return IUnknown_AddRef(mixer->outer_unk);
370 static ULONG WINAPI video_mixer_transform_Release(IMFTransform *iface)
372 struct video_mixer *mixer = impl_from_IMFTransform(iface);
373 return IUnknown_Release(mixer->outer_unk);
376 static HRESULT WINAPI video_mixer_transform_GetStreamLimits(IMFTransform *iface, DWORD *input_minimum,
377 DWORD *input_maximum, DWORD *output_minimum, DWORD *output_maximum)
379 TRACE("%p, %p, %p, %p, %p.\n", iface, input_minimum, input_maximum, output_minimum, output_maximum);
381 *input_minimum = 1;
382 *input_maximum = MAX_MIXER_INPUT_STREAMS;
383 *output_minimum = 1;
384 *output_maximum = 1;
386 return S_OK;
389 static HRESULT WINAPI video_mixer_transform_GetStreamCount(IMFTransform *iface, DWORD *inputs, DWORD *outputs)
391 struct video_mixer *mixer = impl_from_IMFTransform(iface);
393 TRACE("%p, %p, %p.\n", iface, inputs, outputs);
395 EnterCriticalSection(&mixer->cs);
396 if (inputs) *inputs = mixer->input_count;
397 if (outputs) *outputs = 1;
398 LeaveCriticalSection(&mixer->cs);
400 return S_OK;
403 static HRESULT WINAPI video_mixer_transform_GetStreamIDs(IMFTransform *iface, DWORD input_size, DWORD *inputs,
404 DWORD output_size, DWORD *outputs)
406 struct video_mixer *mixer = impl_from_IMFTransform(iface);
407 HRESULT hr = S_OK;
409 TRACE("%p, %u, %p, %u, %p.\n", iface, input_size, inputs, output_size, outputs);
411 EnterCriticalSection(&mixer->cs);
412 if (mixer->input_count > input_size || !output_size)
413 hr = MF_E_BUFFERTOOSMALL;
414 else if (inputs)
415 memcpy(inputs, mixer->input_ids, mixer->input_count * sizeof(*inputs));
416 if (outputs) *outputs = 0;
417 LeaveCriticalSection(&mixer->cs);
419 return hr;
422 static HRESULT WINAPI video_mixer_transform_GetInputStreamInfo(IMFTransform *iface, DWORD id, MFT_INPUT_STREAM_INFO *info)
424 struct video_mixer *mixer = impl_from_IMFTransform(iface);
425 struct input_stream *input;
426 HRESULT hr;
428 TRACE("%p, %u, %p.\n", iface, id, info);
430 EnterCriticalSection(&mixer->cs);
432 if (SUCCEEDED(hr = video_mixer_get_input(mixer, id, &input)))
434 memset(info, 0, sizeof(*info));
435 if (id)
436 info->dwFlags |= MFT_INPUT_STREAM_REMOVABLE | MFT_INPUT_STREAM_OPTIONAL;
439 LeaveCriticalSection(&mixer->cs);
441 return hr;
444 static HRESULT WINAPI video_mixer_transform_GetOutputStreamInfo(IMFTransform *iface, DWORD id, MFT_OUTPUT_STREAM_INFO *info)
446 TRACE("%p, %u, %p.\n", iface, id, info);
448 if (id)
449 return MF_E_INVALIDSTREAMNUMBER;
451 memset(info, 0, sizeof(*info));
453 return S_OK;
456 static HRESULT WINAPI video_mixer_transform_GetAttributes(IMFTransform *iface, IMFAttributes **attributes)
458 struct video_mixer *mixer = impl_from_IMFTransform(iface);
460 TRACE("%p, %p.\n", iface, attributes);
462 if (!attributes)
463 return E_POINTER;
465 *attributes = mixer->attributes;
466 IMFAttributes_AddRef(*attributes);
468 return S_OK;
471 static HRESULT WINAPI video_mixer_transform_GetInputStreamAttributes(IMFTransform *iface, DWORD id,
472 IMFAttributes **attributes)
474 struct video_mixer *mixer = impl_from_IMFTransform(iface);
475 struct input_stream *input;
476 HRESULT hr;
478 TRACE("%p, %u, %p.\n", iface, id, attributes);
480 EnterCriticalSection(&mixer->cs);
482 if (SUCCEEDED(hr = video_mixer_get_input(mixer, id, &input)))
484 *attributes = input->attributes;
485 if (*attributes)
486 IMFAttributes_AddRef(*attributes);
489 LeaveCriticalSection(&mixer->cs);
491 return hr;
494 static HRESULT WINAPI video_mixer_transform_GetOutputStreamAttributes(IMFTransform *iface, DWORD id,
495 IMFAttributes **attributes)
497 TRACE("%p, %u, %p.\n", iface, id, attributes);
499 return E_NOTIMPL;
502 static HRESULT WINAPI video_mixer_transform_DeleteInputStream(IMFTransform *iface, DWORD id)
504 struct video_mixer *mixer = impl_from_IMFTransform(iface);
505 struct input_stream *input;
506 unsigned int idx;
507 HRESULT hr;
509 TRACE("%p, %u.\n", iface, id);
511 if (!id)
512 return MF_E_INVALIDSTREAMNUMBER;
514 EnterCriticalSection(&mixer->cs);
516 /* Can't delete reference stream. */
517 if (SUCCEEDED(hr = video_mixer_get_input(mixer, id, &input)))
519 mixer->input_count--;
520 idx = input - mixer->inputs;
521 if (idx < mixer->input_count)
523 if (mixer->inputs[idx].attributes)
524 IMFAttributes_Release(mixer->inputs[idx].attributes);
525 memmove(&mixer->inputs[idx], &mixer->inputs[idx + 1], (mixer->input_count - idx) * sizeof(*mixer->inputs));
526 memmove(&mixer->input_ids[idx], &mixer->input_ids[idx + 1], (mixer->input_count - idx) *
527 sizeof(*mixer->input_ids));
528 video_mixer_update_zorder_map(mixer);
532 LeaveCriticalSection(&mixer->cs);
534 return hr;
537 static int __cdecl video_mixer_add_input_sort_compare(const void *a, const void *b)
539 const struct input_stream *left = a, *right = b;
540 return left->id != right->id ? (left->id < right->id ? -1 : 1) : 0;
543 static HRESULT WINAPI video_mixer_transform_AddInputStreams(IMFTransform *iface, DWORD count, DWORD *ids)
545 struct video_mixer *mixer = impl_from_IMFTransform(iface);
546 struct input_stream inputs[MAX_MIXER_INPUT_STREAMS] = { {0} };
547 struct input_stream *input;
548 unsigned int i, len;
549 HRESULT hr = S_OK;
551 TRACE("%p, %u, %p.\n", iface, count, ids);
553 if (!ids)
554 return E_POINTER;
556 EnterCriticalSection(&mixer->cs);
557 if (count > ARRAY_SIZE(mixer->inputs) - mixer->input_count)
558 hr = E_INVALIDARG;
559 else
561 /* Test for collisions. */
562 memcpy(inputs, mixer->inputs, mixer->input_count * sizeof(*inputs));
563 for (i = 0; i < count; ++i)
564 inputs[i + mixer->input_count].id = ids[i];
566 len = mixer->input_count + count;
568 qsort(inputs, len, sizeof(*inputs), video_mixer_add_input_sort_compare);
570 for (i = 1; i < len; ++i)
572 if (inputs[i - 1].id == inputs[i].id)
574 hr = E_INVALIDARG;
575 break;
579 if (SUCCEEDED(hr))
581 unsigned int zorder = mixer->input_count;
583 for (i = 0; i < count; ++i)
585 if ((input = bsearch(&ids[i], inputs, len, sizeof(*inputs), video_mixer_compare_input_id)))
586 video_mixer_init_input(input);
588 memcpy(&mixer->input_ids[mixer->input_count], ids, count * sizeof(*ids));
589 memcpy(mixer->inputs, inputs, len * sizeof(*inputs));
590 mixer->input_count += count;
592 for (i = 0; i < count; ++i)
594 if (SUCCEEDED(video_mixer_get_input(mixer, ids[i], &input)))
595 input->zorder = zorder;
596 zorder++;
599 video_mixer_update_zorder_map(mixer);
602 LeaveCriticalSection(&mixer->cs);
604 return hr;
607 static HRESULT WINAPI video_mixer_transform_GetInputAvailableType(IMFTransform *iface, DWORD id, DWORD index,
608 IMFMediaType **type)
610 TRACE("%p, %u, %u, %p.\n", iface, id, index, type);
612 return E_NOTIMPL;
615 static HRESULT WINAPI video_mixer_transform_GetOutputAvailableType(IMFTransform *iface, DWORD id, DWORD index,
616 IMFMediaType **type)
618 struct video_mixer *mixer = impl_from_IMFTransform(iface);
619 HRESULT hr = S_OK;
621 TRACE("%p, %u, %u, %p.\n", iface, id, index, type);
623 if (id)
624 return MF_E_INVALIDSTREAMNUMBER;
626 EnterCriticalSection(&mixer->cs);
628 if (!mixer->inputs[0].media_type)
629 hr = MF_E_TRANSFORM_TYPE_NOT_SET;
630 else if (index >= mixer->output.rt_formats_count)
631 hr = MF_E_NO_MORE_TYPES;
632 else
634 if (SUCCEEDED(hr = MFCreateMediaType(type)))
635 hr = IMFMediaType_CopyAllItems(mixer->output.rt_formats[index].media_type, (IMFAttributes *)*type);
638 LeaveCriticalSection(&mixer->cs);
640 return hr;
643 static HRESULT video_mixer_init_dxva_videodesc(IMFMediaType *media_type, DXVA2_VideoDesc *video_desc)
645 const MFVIDEOFORMAT *video_format;
646 IMFVideoMediaType *video_type;
647 BOOL is_compressed = TRUE;
648 HRESULT hr = S_OK;
650 if (FAILED(IMFMediaType_QueryInterface(media_type, &IID_IMFVideoMediaType, (void **)&video_type)))
651 return MF_E_INVALIDMEDIATYPE;
653 video_format = IMFVideoMediaType_GetVideoFormat(video_type);
654 IMFVideoMediaType_IsCompressedFormat(video_type, &is_compressed);
656 if (!video_format || !video_format->videoInfo.dwWidth || !video_format->videoInfo.dwHeight || is_compressed)
658 hr = MF_E_INVALIDMEDIATYPE;
659 goto done;
662 memset(video_desc, 0, sizeof(*video_desc));
663 video_desc->SampleWidth = video_format->videoInfo.dwWidth;
664 video_desc->SampleHeight = video_format->videoInfo.dwHeight;
665 video_desc->Format = video_format->surfaceInfo.Format;
667 done:
668 IMFVideoMediaType_Release(video_type);
670 return hr;
673 static void video_mixer_append_rt_format(struct rt_format *rt_formats, unsigned int *count,
674 const GUID *device, D3DFORMAT format)
676 unsigned int i;
678 for (i = 0; i < *count; ++i)
680 if (rt_formats[i].format == format) return;
683 rt_formats[*count].format = format;
684 rt_formats[*count].device = *device;
685 *count += 1;
688 static unsigned int video_mixer_get_interlace_mode_from_video_desc(const DXVA2_VideoDesc *video_desc)
690 switch (video_desc->SampleFormat.SampleFormat)
692 case DXVA2_SampleFieldInterleavedEvenFirst:
693 return MFVideoInterlace_FieldInterleavedUpperFirst;
694 case DXVA2_SampleFieldInterleavedOddFirst:
695 return MFVideoInterlace_FieldInterleavedLowerFirst;
696 case DXVA2_SampleFieldSingleEven:
697 return MFVideoInterlace_FieldSingleUpper;
698 case DXVA2_SampleFieldSingleOdd:
699 return MFVideoInterlace_FieldSingleLower;
700 default:
701 return MFVideoInterlace_Progressive;
705 static void mf_get_attribute_uint32(IMFMediaType *media_type, const GUID *key, UINT32 *value,
706 UINT32 default_value)
708 if (FAILED(IMFMediaType_GetUINT32(media_type, key, value)))
709 *value = default_value;
712 static void mf_get_attribute_uint64(IMFMediaType *media_type, const GUID *key, UINT64 *value,
713 UINT64 default_value)
715 if (FAILED(IMFMediaType_GetUINT64(media_type, key, value)))
716 *value = default_value;
719 static HRESULT video_mixer_collect_output_types(struct video_mixer *mixer, const DXVA2_VideoDesc *video_desc,
720 IMFMediaType *media_type, IDirectXVideoProcessorService *service, unsigned int device_count,
721 const GUID *devices, unsigned int flags)
723 struct rt_format *rt_formats = NULL, *ptr;
724 unsigned int i, j, format_count, count;
725 HRESULT hr = MF_E_INVALIDMEDIATYPE;
726 D3DFORMAT *formats;
727 GUID subtype;
729 count = 0;
730 for (i = 0; i < device_count; ++i)
732 if (SUCCEEDED(IDirectXVideoProcessorService_GetVideoProcessorRenderTargets(service, &devices[i], video_desc,
733 &format_count, &formats)))
735 if (!(ptr = realloc(rt_formats, (count + format_count) * sizeof(*rt_formats))))
737 hr = E_OUTOFMEMORY;
738 count = 0;
739 CoTaskMemFree(formats);
740 break;
742 rt_formats = ptr;
744 for (j = 0; j < format_count; ++j)
745 video_mixer_append_rt_format(rt_formats, &count, &devices[i], formats[j]);
747 CoTaskMemFree(formats);
751 if (count && !(flags & MFT_SET_TYPE_TEST_ONLY))
753 UINT32 fixed_samples, interlace_mode;
754 MFVideoArea aperture;
755 UINT64 par;
757 if (!(mixer->output.rt_formats = calloc(count, sizeof(*mixer->output.rt_formats))))
759 free(rt_formats);
760 return E_OUTOFMEMORY;
763 memcpy(&subtype, &MFVideoFormat_Base, sizeof(subtype));
764 memset(&aperture, 0, sizeof(aperture));
765 if (FAILED(IMFMediaType_GetBlob(media_type, &MF_MT_GEOMETRIC_APERTURE, (UINT8 *)&aperture,
766 sizeof(aperture), NULL)))
768 aperture.Area.cx = video_desc->SampleWidth;
769 aperture.Area.cy = video_desc->SampleHeight;
771 interlace_mode = video_mixer_get_interlace_mode_from_video_desc(video_desc);
772 mf_get_attribute_uint64(media_type, &MF_MT_PIXEL_ASPECT_RATIO, &par, (UINT64)1 << 32 | 1);
773 mf_get_attribute_uint32(media_type, &MF_MT_FIXED_SIZE_SAMPLES, &fixed_samples, 1);
775 for (i = 0; i < count; ++i)
777 IMFMediaType *rt_media_type;
779 subtype.Data1 = rt_formats[i].format;
780 mixer->output.rt_formats[i] = rt_formats[i];
782 MFCreateMediaType(&rt_media_type);
783 IMFMediaType_CopyAllItems(media_type, (IMFAttributes *)rt_media_type);
784 IMFMediaType_SetGUID(rt_media_type, &MF_MT_SUBTYPE, &subtype);
785 IMFMediaType_SetUINT64(rt_media_type, &MF_MT_FRAME_SIZE, (UINT64)aperture.Area.cx << 32 | aperture.Area.cy);
786 IMFMediaType_SetBlob(rt_media_type, &MF_MT_GEOMETRIC_APERTURE, (const UINT8 *)&aperture, sizeof(aperture));
787 IMFMediaType_SetBlob(rt_media_type, &MF_MT_MINIMUM_DISPLAY_APERTURE, (const UINT8 *)&aperture, sizeof(aperture));
788 IMFMediaType_SetUINT32(rt_media_type, &MF_MT_INTERLACE_MODE, interlace_mode);
789 IMFMediaType_SetUINT64(rt_media_type, &MF_MT_PIXEL_ASPECT_RATIO, par);
790 IMFMediaType_SetUINT32(rt_media_type, &MF_MT_FIXED_SIZE_SAMPLES, fixed_samples);
792 mixer->output.rt_formats[i].media_type = rt_media_type;
794 mixer->output.rt_formats_count = count;
797 free(rt_formats);
799 return count ? S_OK : hr;
802 static HRESULT video_mixer_open_device_handle(struct video_mixer *mixer)
804 IDirect3DDeviceManager9_CloseDeviceHandle(mixer->device_manager, mixer->device_handle);
805 mixer->device_handle = NULL;
806 return IDirect3DDeviceManager9_OpenDeviceHandle(mixer->device_manager, &mixer->device_handle);
809 static HRESULT video_mixer_get_processor_service(struct video_mixer *mixer, IDirectXVideoProcessorService **service)
811 HRESULT hr;
813 if (!mixer->device_handle)
815 if (FAILED(hr = IDirect3DDeviceManager9_OpenDeviceHandle(mixer->device_manager, &mixer->device_handle)))
816 return hr;
819 for (;;)
821 hr = IDirect3DDeviceManager9_GetVideoService(mixer->device_manager, mixer->device_handle,
822 &IID_IDirectXVideoProcessorService, (void **)service);
823 if (hr == DXVA2_E_NEW_VIDEO_DEVICE)
825 if (SUCCEEDED(hr = video_mixer_open_device_handle(mixer)))
826 continue;
828 break;
831 return hr;
834 static HRESULT WINAPI video_mixer_transform_SetInputType(IMFTransform *iface, DWORD id, IMFMediaType *media_type, DWORD flags)
836 struct video_mixer *mixer = impl_from_IMFTransform(iface);
837 IDirectXVideoProcessorService *service;
838 DXVA2_VideoDesc video_desc;
839 HRESULT hr = E_NOTIMPL;
840 unsigned int count;
841 GUID *guids;
843 TRACE("%p, %u, %p, %#x.\n", iface, id, media_type, flags);
845 EnterCriticalSection(&mixer->cs);
847 if (!(flags & MFT_SET_TYPE_TEST_ONLY))
848 video_mixer_clear_types(mixer);
850 if (!mixer->device_manager)
851 hr = MF_E_NOT_INITIALIZED;
852 else
854 if (SUCCEEDED(hr = video_mixer_get_processor_service(mixer, &service)))
856 if (SUCCEEDED(hr = video_mixer_init_dxva_videodesc(media_type, &video_desc)))
858 if (!id)
860 if (SUCCEEDED(hr = IDirectXVideoProcessorService_GetVideoProcessorDeviceGuids(service, &video_desc,
861 &count, &guids)))
863 if (SUCCEEDED(hr = video_mixer_collect_output_types(mixer, &video_desc, media_type,
864 service, count, guids, flags)) && !(flags & MFT_SET_TYPE_TEST_ONLY))
866 if (mixer->inputs[0].media_type)
867 IMFMediaType_Release(mixer->inputs[0].media_type);
868 mixer->inputs[0].media_type = media_type;
869 mixer->inputs[0].frame_size.cx = video_desc.SampleWidth;
870 mixer->inputs[0].frame_size.cy = video_desc.SampleHeight;
871 IMFMediaType_AddRef(mixer->inputs[0].media_type);
873 CoTaskMemFree(guids);
876 else
878 FIXME("Unimplemented for substreams.\n");
879 hr = E_NOTIMPL;
882 IDirectXVideoProcessorService_Release(service);
886 LeaveCriticalSection(&mixer->cs);
888 return hr;
891 static HRESULT WINAPI video_mixer_transform_SetOutputType(IMFTransform *iface, DWORD id, IMFMediaType *type, DWORD flags)
893 const unsigned int equality_flags = MF_MEDIATYPE_EQUAL_MAJOR_TYPES | MF_MEDIATYPE_EQUAL_FORMAT_TYPES;
894 struct video_mixer *mixer = impl_from_IMFTransform(iface);
895 HRESULT hr = MF_E_INVALIDMEDIATYPE;
896 unsigned int i, compare_flags;
897 BOOL is_compressed = TRUE;
899 TRACE("%p, %u, %p, %#x.\n", iface, id, type, flags);
901 if (id)
902 return MF_E_INVALIDSTREAMNUMBER;
904 if (!type)
905 return E_INVALIDARG;
907 if (FAILED(IMFMediaType_IsCompressedFormat(type, &is_compressed)) || is_compressed)
908 return MF_E_INVALIDMEDIATYPE;
910 EnterCriticalSection(&mixer->cs);
912 for (i = 0; i < mixer->output.rt_formats_count; ++i)
914 compare_flags = 0;
915 if (FAILED(IMFMediaType_IsEqual(type, mixer->output.rt_formats[i].media_type, &compare_flags)))
916 continue;
918 if ((compare_flags & equality_flags) == equality_flags)
920 hr = S_OK;
921 break;
925 if (SUCCEEDED(hr) && !(flags & MFT_SET_TYPE_TEST_ONLY))
927 IDirectXVideoProcessorService *service;
929 if (SUCCEEDED(hr = video_mixer_get_processor_service(mixer, &service)))
931 DXVA2_VideoDesc video_desc;
932 GUID subtype = { 0 };
933 D3DFORMAT rt_format;
935 if (mixer->processor)
936 IDirectXVideoProcessor_Release(mixer->processor);
937 mixer->processor = NULL;
939 video_mixer_init_dxva_videodesc(mixer->inputs[0].media_type, &video_desc);
940 IMFMediaType_GetGUID(type, &MF_MT_SUBTYPE, &subtype);
941 rt_format = subtype.Data1;
943 if (SUCCEEDED(hr = IDirectXVideoProcessorService_CreateVideoProcessor(service, &mixer->output.rt_formats[i].device,
944 &video_desc, rt_format, MAX_MIXER_INPUT_SUBSTREAMS, &mixer->processor)))
946 if (FAILED(IMFMediaType_GetBlob(type, &MF_MT_GEOMETRIC_APERTURE, (UINT8 *)&mixer->aperture,
947 sizeof(mixer->aperture), NULL)))
949 memset(&mixer->aperture, 0, sizeof(mixer->aperture));
951 if (mixer->output.media_type)
952 IMFMediaType_Release(mixer->output.media_type);
953 mixer->output.media_type = type;
954 IMFMediaType_AddRef(mixer->output.media_type);
957 IDirectXVideoProcessorService_Release(service);
961 LeaveCriticalSection(&mixer->cs);
963 return hr;
966 static HRESULT WINAPI video_mixer_transform_GetInputCurrentType(IMFTransform *iface, DWORD id, IMFMediaType **type)
968 struct video_mixer *mixer = impl_from_IMFTransform(iface);
969 struct input_stream *stream;
970 HRESULT hr;
972 TRACE("%p, %u, %p.\n", iface, id, type);
974 EnterCriticalSection(&mixer->cs);
976 if (SUCCEEDED(hr = video_mixer_get_input(mixer, id, &stream)))
978 if (!stream->media_type)
979 hr = MF_E_TRANSFORM_TYPE_NOT_SET;
980 else
982 *type = stream->media_type;
983 IMFMediaType_AddRef(*type);
987 LeaveCriticalSection(&mixer->cs);
989 return hr;
992 static HRESULT WINAPI video_mixer_transform_GetOutputCurrentType(IMFTransform *iface, DWORD id, IMFMediaType **type)
994 struct video_mixer *mixer = impl_from_IMFTransform(iface);
995 HRESULT hr = S_OK;
997 TRACE("%p, %u, %p.\n", iface, id, type);
999 if (id)
1000 return MF_E_INVALIDSTREAMNUMBER;
1002 EnterCriticalSection(&mixer->cs);
1004 if (!mixer->output.media_type)
1005 hr = MF_E_TRANSFORM_TYPE_NOT_SET;
1006 else
1008 *type = mixer->output.media_type;
1009 IMFMediaType_AddRef(*type);
1012 LeaveCriticalSection(&mixer->cs);
1014 return hr;
1017 static HRESULT WINAPI video_mixer_transform_GetInputStatus(IMFTransform *iface, DWORD id, DWORD *status)
1019 struct video_mixer *mixer = impl_from_IMFTransform(iface);
1020 struct input_stream *stream;
1021 HRESULT hr;
1023 TRACE("%p, %u, %p.\n", iface, id, status);
1025 if (!status)
1026 return E_POINTER;
1028 EnterCriticalSection(&mixer->cs);
1030 if (!mixer->output.media_type)
1031 hr = MF_E_TRANSFORM_TYPE_NOT_SET;
1032 else if (SUCCEEDED(hr = video_mixer_get_input(mixer, id, &stream)))
1034 *status = stream->sample ? 0 : MFT_INPUT_STATUS_ACCEPT_DATA;
1037 LeaveCriticalSection(&mixer->cs);
1039 return hr;
1042 static HRESULT WINAPI video_mixer_transform_GetOutputStatus(IMFTransform *iface, DWORD *status)
1044 struct video_mixer *mixer = impl_from_IMFTransform(iface);
1045 HRESULT hr = S_OK;
1046 unsigned int i;
1048 TRACE("%p, %p.\n", iface, status);
1050 if (!status)
1051 return E_POINTER;
1053 EnterCriticalSection(&mixer->cs);
1055 if (!mixer->output.media_type)
1056 hr = MF_E_TRANSFORM_TYPE_NOT_SET;
1057 else
1059 *status = MFT_OUTPUT_STATUS_SAMPLE_READY;
1060 for (i = 0; i < mixer->input_count; ++i)
1062 if (!mixer->inputs[i].sample)
1064 *status = 0;
1065 break;
1070 LeaveCriticalSection(&mixer->cs);
1072 return hr;
1075 static HRESULT WINAPI video_mixer_transform_SetOutputBounds(IMFTransform *iface, LONGLONG lower, LONGLONG upper)
1077 struct video_mixer *mixer = impl_from_IMFTransform(iface);
1079 TRACE("%p, %s, %s.\n", iface, wine_dbgstr_longlong(lower), wine_dbgstr_longlong(upper));
1081 EnterCriticalSection(&mixer->cs);
1083 mixer->lower_bound = lower;
1084 mixer->upper_bound = upper;
1086 LeaveCriticalSection(&mixer->cs);
1088 return S_OK;
1091 static HRESULT WINAPI video_mixer_transform_ProcessEvent(IMFTransform *iface, DWORD id, IMFMediaEvent *event)
1093 FIXME("%p, %u, %p.\n", iface, id, event);
1095 return E_NOTIMPL;
1098 static void video_mixer_request_sample(struct video_mixer *mixer, unsigned int idx)
1100 if (!mixer->event_sink || mixer->inputs[idx].sample_requested)
1101 return;
1103 IMediaEventSink_Notify(mixer->event_sink, EC_SAMPLE_NEEDED, idx, 0);
1104 mixer->inputs[idx].sample_requested = 1;
1107 static HRESULT WINAPI video_mixer_transform_ProcessMessage(IMFTransform *iface, MFT_MESSAGE_TYPE message, ULONG_PTR param)
1109 struct video_mixer *mixer = impl_from_IMFTransform(iface);
1110 HRESULT hr = S_OK;
1111 unsigned int i;
1113 TRACE("%p, %#x, %#lx.\n", iface, message, param);
1115 switch (message)
1117 case MFT_MESSAGE_SET_D3D_MANAGER:
1119 EnterCriticalSection(&mixer->cs);
1121 video_mixer_release_device_manager(mixer);
1122 if (param)
1123 hr = IUnknown_QueryInterface((IUnknown *)param, &IID_IDirect3DDeviceManager9, (void **)&mixer->device_manager);
1125 LeaveCriticalSection(&mixer->cs);
1127 break;
1129 case MFT_MESSAGE_COMMAND_FLUSH:
1131 EnterCriticalSection(&mixer->cs);
1133 for (i = 0; i < mixer->input_count; ++i)
1135 if (mixer->inputs[i].sample)
1137 IMFSample_Release(mixer->inputs[i].sample);
1138 mixer->inputs[i].sample = NULL;
1139 mixer->inputs[i].sample_requested = 0;
1143 LeaveCriticalSection(&mixer->cs);
1145 break;
1147 case MFT_MESSAGE_NOTIFY_BEGIN_STREAMING:
1148 case MFT_MESSAGE_NOTIFY_END_STREAMING:
1150 EnterCriticalSection(&mixer->cs);
1152 if (!mixer->is_streaming)
1154 for (i = 0; i < mixer->input_count; ++i)
1155 video_mixer_request_sample(mixer, i);
1158 mixer->is_streaming = message == MFT_MESSAGE_NOTIFY_BEGIN_STREAMING;
1160 LeaveCriticalSection(&mixer->cs);
1162 break;
1164 case MFT_MESSAGE_COMMAND_DRAIN:
1165 break;
1167 default:
1168 WARN("Message not handled %d.\n", message);
1169 hr = E_NOTIMPL;
1172 return hr;
1175 static HRESULT WINAPI video_mixer_transform_ProcessInput(IMFTransform *iface, DWORD id, IMFSample *sample, DWORD flags)
1177 struct video_mixer *mixer = impl_from_IMFTransform(iface);
1178 struct input_stream *input;
1179 HRESULT hr;
1181 TRACE("%p, %u, %p, %#x.\n", iface, id, sample, flags);
1183 if (!sample)
1184 return E_POINTER;
1186 EnterCriticalSection(&mixer->cs);
1188 if (SUCCEEDED(hr = video_mixer_get_input(mixer, id, &input)))
1190 if (!input->media_type || !mixer->output.media_type)
1191 hr = MF_E_TRANSFORM_TYPE_NOT_SET;
1192 else if (input->sample)
1193 hr = MF_E_NOTACCEPTING;
1194 else
1196 mixer->is_streaming = 1;
1197 input->sample_requested = 0;
1198 input->sample = sample;
1199 IMFSample_AddRef(input->sample);
1203 LeaveCriticalSection(&mixer->cs);
1205 return hr;
1208 static HRESULT video_mixer_get_sample_surface(IMFSample *sample, IDirect3DSurface9 **surface)
1210 IMFMediaBuffer *buffer;
1211 IMFGetService *gs;
1212 HRESULT hr;
1214 if (FAILED(hr = IMFSample_GetBufferByIndex(sample, 0, &buffer)))
1215 return hr;
1217 hr = IMFMediaBuffer_QueryInterface(buffer, &IID_IMFGetService, (void **)&gs);
1218 IMFMediaBuffer_Release(buffer);
1219 if (FAILED(hr))
1220 return hr;
1222 hr = IMFGetService_GetService(gs, &MR_BUFFER_SERVICE, &IID_IDirect3DSurface9, (void **)surface);
1223 IMFGetService_Release(gs);
1224 return hr;
1227 static HRESULT video_mixer_get_d3d_device(struct video_mixer *mixer, IDirect3DDevice9 **device)
1229 HRESULT hr;
1231 for (;;)
1233 hr = IDirect3DDeviceManager9_LockDevice(mixer->device_manager, mixer->device_handle,
1234 device, TRUE);
1235 if (hr == DXVA2_E_NEW_VIDEO_DEVICE)
1237 if (SUCCEEDED(hr = video_mixer_open_device_handle(mixer)))
1238 continue;
1240 break;
1243 return hr;
1246 static BOOL video_mixer_rect_needs_scaling(const MFVideoNormalizedRect *scale)
1248 return scale->left != 0.0f || scale->top != 0.0f || scale->right != 1.0f || scale->bottom != 1.0f;
1251 static void video_mixer_scale_rect(RECT *rect, unsigned int width, unsigned int height,
1252 const MFVideoNormalizedRect *scale)
1254 if (video_mixer_rect_needs_scaling(scale))
1256 rect->left = width * scale->left;
1257 rect->right = width * scale->right;
1258 rect->top = height * scale->top;
1259 rect->bottom = height * scale->bottom;
1261 else
1262 SetRect(rect, 0, 0, width, height);
1265 static void video_mixer_correct_aspect_ratio(const RECT *src, RECT *dst)
1267 unsigned int src_width = src->right - src->left, src_height = src->bottom - src->top;
1268 unsigned int dst_width = dst->right - dst->left, dst_height = dst->bottom - dst->top;
1270 if (src_width * dst_height > dst_width * src_height)
1272 /* src is "wider" than dst. */
1273 unsigned int dst_center = (dst->top + dst->bottom) / 2;
1274 unsigned int scaled_height = src_height * dst_width / src_width;
1276 dst->top = dst_center - scaled_height / 2;
1277 dst->bottom = dst->top + scaled_height;
1279 else if (src_width * dst_height < dst_width * src_height)
1281 /* src is "taller" than dst. */
1282 unsigned int dst_center = (dst->left + dst->right) / 2;
1283 unsigned int scaled_width = src_width * dst_height / src_height;
1285 dst->left = dst_center - scaled_width / 2;
1286 dst->right = dst->left + scaled_width;
1290 static void video_mixer_render(struct video_mixer *mixer, IDirect3DSurface9 *rt)
1292 DXVA2_VideoSample samples[MAX_MIXER_INPUT_STREAMS] = {{ 0 }};
1293 DXVA2_VideoProcessBltParams params = { 0 };
1294 MFVideoNormalizedRect zoom_rect;
1295 struct input_stream *stream;
1296 HRESULT hr = S_OK;
1297 unsigned int i;
1298 RECT dst;
1300 if (FAILED(IMFAttributes_GetBlob(mixer->attributes, &VIDEO_ZOOM_RECT, (UINT8 *)&zoom_rect,
1301 sizeof(zoom_rect), NULL)))
1303 zoom_rect.left = zoom_rect.top = 0.0f;
1304 zoom_rect.right = zoom_rect.bottom = 1.0f;
1307 SetRect(&dst, 0, 0, mixer->aperture.Area.cx, mixer->aperture.Area.cy);
1308 OffsetRect(&dst, mixer->aperture.OffsetX.value, mixer->aperture.OffsetY.value);
1310 for (i = 0; i < mixer->input_count; ++i)
1312 DXVA2_VideoSample *sample = &samples[i];
1313 IDirect3DSurface9 *surface;
1315 stream = mixer->zorder[i];
1317 if (FAILED(hr = video_mixer_get_sample_surface(stream->sample, &surface)))
1319 WARN("Failed to get source surface for stream %u, hr %#x.\n", i, hr);
1320 break;
1323 /* Full input frame corrected to full destination rectangle. */
1325 video_mixer_scale_rect(&sample->SrcRect, stream->frame_size.cx, stream->frame_size.cy, &zoom_rect);
1326 CopyRect(&sample->DstRect, &dst);
1327 video_mixer_correct_aspect_ratio(&sample->SrcRect, &sample->DstRect);
1329 if (video_mixer_rect_needs_scaling(&stream->rect))
1330 WARN("Ignoring stream %u rectangle %s.\n", stream->id, debugstr_normalized_rect(&stream->rect));
1332 sample->SampleFormat.SampleFormat = stream->id == 0 ? DXVA2_SampleProgressiveFrame : DXVA2_SampleSubStream;
1333 sample->SrcSurface = surface;
1334 sample->PlanarAlpha = DXVA2_Fixed32OpaqueAlpha();
1337 if (SUCCEEDED(hr))
1339 SetRect(&params.TargetRect, 0, 0, mixer->aperture.Area.cx, mixer->aperture.Area.cy);
1340 OffsetRect(&params.TargetRect, mixer->aperture.OffsetX.value, mixer->aperture.OffsetY.value);
1342 params.BackgroundColor = mixer->bkgnd_color.ayuv;
1343 params.Alpha = DXVA2_Fixed32OpaqueAlpha();
1345 if (FAILED(hr = IDirectXVideoProcessor_VideoProcessBlt(mixer->processor, rt, &params, samples,
1346 mixer->input_count, NULL)))
1348 WARN("Failed to process samples, hr %#x.\n", hr);
1352 for (i = 0; i < mixer->input_count; ++i)
1354 if (samples[i].SrcSurface)
1355 IDirect3DSurface9_Release(samples[i].SrcSurface);
1359 static HRESULT video_mixer_get_sample_desired_time(IMFSample *sample, LONGLONG *timestamp, LONGLONG *duration)
1361 IMFDesiredSample *desired;
1362 HRESULT hr;
1364 if (SUCCEEDED(hr = IMFSample_QueryInterface(sample, &IID_IMFDesiredSample, (void **)&desired)))
1366 hr = IMFDesiredSample_GetDesiredSampleTimeAndDuration(desired, timestamp, duration);
1367 IMFDesiredSample_Release(desired);
1370 return hr;
1373 static HRESULT WINAPI video_mixer_transform_ProcessOutput(IMFTransform *iface, DWORD flags, DWORD count,
1374 MFT_OUTPUT_DATA_BUFFER *buffers, DWORD *status)
1376 struct video_mixer *mixer = impl_from_IMFTransform(iface);
1377 LONGLONG timestamp, duration;
1378 IDirect3DSurface9 *surface;
1379 IDirect3DDevice9 *device;
1380 unsigned int i;
1381 HRESULT hr;
1383 TRACE("%p, %#x, %u, %p, %p.\n", iface, flags, count, buffers, status);
1385 if (!buffers || !count || count > 1 || !buffers->pSample)
1386 return E_INVALIDARG;
1388 if (buffers->dwStreamID)
1389 return MF_E_INVALIDSTREAMNUMBER;
1391 *status = 0;
1393 EnterCriticalSection(&mixer->cs);
1395 if (SUCCEEDED(hr = video_mixer_get_sample_surface(buffers->pSample, &surface)))
1397 if (mixer->is_streaming)
1399 for (i = 0; i < mixer->input_count; ++i)
1401 if (!mixer->inputs[i].sample)
1403 hr = MF_E_TRANSFORM_NEED_MORE_INPUT;
1404 break;
1408 if (SUCCEEDED(hr))
1410 video_mixer_render(mixer, surface);
1412 timestamp = duration = 0;
1413 if (SUCCEEDED(IMFSample_GetSampleTime(mixer->inputs[0].sample, &timestamp)))
1415 IMFSample_SetSampleTime(buffers->pSample, timestamp);
1417 IMFSample_GetSampleDuration(mixer->inputs[0].sample, &duration);
1418 IMFSample_SetSampleDuration(buffers->pSample, duration);
1422 if (SUCCEEDED(hr))
1424 for (i = 0; i < mixer->input_count; ++i)
1426 if (mixer->inputs[i].sample)
1427 IMFSample_Release(mixer->inputs[i].sample);
1428 mixer->inputs[i].sample = NULL;
1429 video_mixer_request_sample(mixer, i);
1433 else
1435 if (SUCCEEDED(video_mixer_get_sample_desired_time(buffers->pSample, &timestamp, &duration)))
1437 if (SUCCEEDED(hr = video_mixer_get_d3d_device(mixer, &device)))
1439 IDirect3DDevice9_ColorFill(device, surface, NULL, 0);
1440 IDirect3DDeviceManager9_UnlockDevice(mixer->device_manager, mixer->device_handle, FALSE);
1441 IDirect3DDevice9_Release(device);
1444 else
1445 hr = MF_E_TRANSFORM_NEED_MORE_INPUT;
1447 IDirect3DSurface9_Release(surface);
1450 LeaveCriticalSection(&mixer->cs);
1452 return hr;
1455 static const IMFTransformVtbl video_mixer_transform_vtbl =
1457 video_mixer_transform_QueryInterface,
1458 video_mixer_transform_AddRef,
1459 video_mixer_transform_Release,
1460 video_mixer_transform_GetStreamLimits,
1461 video_mixer_transform_GetStreamCount,
1462 video_mixer_transform_GetStreamIDs,
1463 video_mixer_transform_GetInputStreamInfo,
1464 video_mixer_transform_GetOutputStreamInfo,
1465 video_mixer_transform_GetAttributes,
1466 video_mixer_transform_GetInputStreamAttributes,
1467 video_mixer_transform_GetOutputStreamAttributes,
1468 video_mixer_transform_DeleteInputStream,
1469 video_mixer_transform_AddInputStreams,
1470 video_mixer_transform_GetInputAvailableType,
1471 video_mixer_transform_GetOutputAvailableType,
1472 video_mixer_transform_SetInputType,
1473 video_mixer_transform_SetOutputType,
1474 video_mixer_transform_GetInputCurrentType,
1475 video_mixer_transform_GetOutputCurrentType,
1476 video_mixer_transform_GetInputStatus,
1477 video_mixer_transform_GetOutputStatus,
1478 video_mixer_transform_SetOutputBounds,
1479 video_mixer_transform_ProcessEvent,
1480 video_mixer_transform_ProcessMessage,
1481 video_mixer_transform_ProcessInput,
1482 video_mixer_transform_ProcessOutput,
1485 static HRESULT WINAPI video_mixer_device_id_QueryInterface(IMFVideoDeviceID *iface, REFIID riid, void **obj)
1487 struct video_mixer *mixer = impl_from_IMFVideoDeviceID(iface);
1488 return IMFTransform_QueryInterface(&mixer->IMFTransform_iface, riid, obj);
1491 static ULONG WINAPI video_mixer_device_id_AddRef(IMFVideoDeviceID *iface)
1493 struct video_mixer *mixer = impl_from_IMFVideoDeviceID(iface);
1494 return IMFTransform_AddRef(&mixer->IMFTransform_iface);
1497 static ULONG WINAPI video_mixer_device_id_Release(IMFVideoDeviceID *iface)
1499 struct video_mixer *mixer = impl_from_IMFVideoDeviceID(iface);
1500 return IMFTransform_Release(&mixer->IMFTransform_iface);
1503 static HRESULT WINAPI video_mixer_device_id_GetDeviceID(IMFVideoDeviceID *iface, IID *device_id)
1505 TRACE("%p, %p.\n", iface, device_id);
1507 if (!device_id)
1508 return E_POINTER;
1510 memcpy(device_id, &IID_IDirect3DDevice9, sizeof(*device_id));
1512 return S_OK;
1515 static const IMFVideoDeviceIDVtbl video_mixer_device_id_vtbl =
1517 video_mixer_device_id_QueryInterface,
1518 video_mixer_device_id_AddRef,
1519 video_mixer_device_id_Release,
1520 video_mixer_device_id_GetDeviceID,
1523 static HRESULT WINAPI video_mixer_service_client_QueryInterface(IMFTopologyServiceLookupClient *iface,
1524 REFIID riid, void **obj)
1526 struct video_mixer *mixer = impl_from_IMFTopologyServiceLookupClient(iface);
1527 return IMFTransform_QueryInterface(&mixer->IMFTransform_iface, riid, obj);
1530 static ULONG WINAPI video_mixer_service_client_AddRef(IMFTopologyServiceLookupClient *iface)
1532 struct video_mixer *mixer = impl_from_IMFTopologyServiceLookupClient(iface);
1533 return IMFTransform_AddRef(&mixer->IMFTransform_iface);
1536 static ULONG WINAPI video_mixer_service_client_Release(IMFTopologyServiceLookupClient *iface)
1538 struct video_mixer *mixer = impl_from_IMFTopologyServiceLookupClient(iface);
1539 return IMFTransform_Release(&mixer->IMFTransform_iface);
1542 static HRESULT WINAPI video_mixer_service_client_InitServicePointers(IMFTopologyServiceLookupClient *iface,
1543 IMFTopologyServiceLookup *service_lookup)
1545 struct video_mixer *mixer = impl_from_IMFTopologyServiceLookupClient(iface);
1546 unsigned int count;
1547 HRESULT hr;
1549 TRACE("%p, %p.\n", iface, service_lookup);
1551 if (!service_lookup)
1552 return E_POINTER;
1554 EnterCriticalSection(&mixer->cs);
1556 count = 1;
1557 if (FAILED(hr = IMFTopologyServiceLookup_LookupService(service_lookup, MF_SERVICE_LOOKUP_GLOBAL, 0,
1558 &MR_VIDEO_RENDER_SERVICE, &IID_IMediaEventSink, (void **)&mixer->event_sink, &count)))
1560 WARN("Failed to get renderer event sink, hr %#x.\n", hr);
1563 LeaveCriticalSection(&mixer->cs);
1565 return hr;
1568 static HRESULT WINAPI video_mixer_service_client_ReleaseServicePointers(IMFTopologyServiceLookupClient *iface)
1570 struct video_mixer *mixer = impl_from_IMFTopologyServiceLookupClient(iface);
1572 TRACE("%p.\n", iface);
1574 EnterCriticalSection(&mixer->cs);
1576 if (mixer->event_sink)
1577 IMediaEventSink_Release(mixer->event_sink);
1578 mixer->event_sink = NULL;
1580 LeaveCriticalSection(&mixer->cs);
1582 return S_OK;
1585 static const IMFTopologyServiceLookupClientVtbl video_mixer_service_client_vtbl =
1587 video_mixer_service_client_QueryInterface,
1588 video_mixer_service_client_AddRef,
1589 video_mixer_service_client_Release,
1590 video_mixer_service_client_InitServicePointers,
1591 video_mixer_service_client_ReleaseServicePointers,
1594 static HRESULT WINAPI video_mixer_control_QueryInterface(IMFVideoMixerControl2 *iface, REFIID riid, void **obj)
1596 struct video_mixer *mixer = impl_from_IMFVideoMixerControl2(iface);
1597 return IMFTransform_QueryInterface(&mixer->IMFTransform_iface, riid, obj);
1600 static ULONG WINAPI video_mixer_control_AddRef(IMFVideoMixerControl2 *iface)
1602 struct video_mixer *mixer = impl_from_IMFVideoMixerControl2(iface);
1603 return IMFTransform_AddRef(&mixer->IMFTransform_iface);
1606 static ULONG WINAPI video_mixer_control_Release(IMFVideoMixerControl2 *iface)
1608 struct video_mixer *mixer = impl_from_IMFVideoMixerControl2(iface);
1609 return IMFTransform_Release(&mixer->IMFTransform_iface);
1612 static HRESULT WINAPI video_mixer_control_SetStreamZOrder(IMFVideoMixerControl2 *iface, DWORD id, DWORD zorder)
1614 struct video_mixer *mixer = impl_from_IMFVideoMixerControl2(iface);
1615 struct input_stream *stream;
1616 HRESULT hr;
1618 TRACE("%p, %u, %u.\n", iface, id, zorder);
1620 /* Can't change reference stream. */
1621 if (!id && zorder)
1622 return E_INVALIDARG;
1624 EnterCriticalSection(&mixer->cs);
1626 if (zorder >= mixer->input_count)
1627 hr = E_INVALIDARG;
1628 else if (SUCCEEDED(hr = video_mixer_get_input(mixer, id, &stream)))
1630 /* Lowest zorder only applies to reference stream. */
1631 if (id && !zorder)
1632 hr = MF_E_INVALIDREQUEST;
1633 else if (stream->zorder != zorder)
1635 stream->zorder = zorder;
1636 video_mixer_update_zorder_map(mixer);
1640 LeaveCriticalSection(&mixer->cs);
1642 return hr;
1645 static HRESULT WINAPI video_mixer_control_GetStreamZOrder(IMFVideoMixerControl2 *iface, DWORD id, DWORD *zorder)
1647 struct video_mixer *mixer = impl_from_IMFVideoMixerControl2(iface);
1648 struct input_stream *stream;
1649 HRESULT hr;
1651 TRACE("%p, %u, %p.\n", iface, id, zorder);
1653 if (!zorder)
1654 return E_POINTER;
1656 EnterCriticalSection(&mixer->cs);
1658 if (SUCCEEDED(hr = video_mixer_get_input(mixer, id, &stream)))
1659 *zorder = stream->zorder;
1661 LeaveCriticalSection(&mixer->cs);
1663 return hr;
1666 static HRESULT WINAPI video_mixer_control_SetStreamOutputRect(IMFVideoMixerControl2 *iface, DWORD id,
1667 const MFVideoNormalizedRect *rect)
1669 struct video_mixer *mixer = impl_from_IMFVideoMixerControl2(iface);
1670 struct input_stream *stream;
1671 HRESULT hr;
1673 TRACE("%p, %u, %s.\n", iface, id, debugstr_normalized_rect(rect));
1675 if (!rect)
1676 return E_POINTER;
1678 if (rect->left > rect->right || rect->top > rect->bottom ||
1679 rect->left < 0.0f || rect->top < 0.0f || rect->right > 1.0f || rect->bottom > 1.0f)
1681 return E_INVALIDARG;
1684 EnterCriticalSection(&mixer->cs);
1686 if (SUCCEEDED(hr = video_mixer_get_input(mixer, id, &stream)))
1687 stream->rect = *rect;
1689 LeaveCriticalSection(&mixer->cs);
1691 return hr;
1694 static HRESULT WINAPI video_mixer_control_GetStreamOutputRect(IMFVideoMixerControl2 *iface, DWORD id,
1695 MFVideoNormalizedRect *rect)
1697 struct video_mixer *mixer = impl_from_IMFVideoMixerControl2(iface);
1698 struct input_stream *stream;
1699 HRESULT hr;
1701 TRACE("%p, %u, %p.\n", iface, id, rect);
1703 if (!rect)
1704 return E_POINTER;
1706 EnterCriticalSection(&mixer->cs);
1708 if (SUCCEEDED(hr = video_mixer_get_input(mixer, id, &stream)))
1709 *rect = stream->rect;
1711 LeaveCriticalSection(&mixer->cs);
1713 return hr;
1716 static HRESULT WINAPI video_mixer_control_SetMixingPrefs(IMFVideoMixerControl2 *iface, DWORD flags)
1718 struct video_mixer *mixer = impl_from_IMFVideoMixerControl2(iface);
1720 TRACE("%p, %#x.\n", iface, flags);
1722 EnterCriticalSection(&mixer->cs);
1723 mixer->mixing_flags = flags;
1724 LeaveCriticalSection(&mixer->cs);
1726 return S_OK;
1729 static HRESULT WINAPI video_mixer_control_GetMixingPrefs(IMFVideoMixerControl2 *iface, DWORD *flags)
1731 struct video_mixer *mixer = impl_from_IMFVideoMixerControl2(iface);
1733 TRACE("%p, %p.\n", iface, flags);
1735 if (!flags)
1736 return E_POINTER;
1738 EnterCriticalSection(&mixer->cs);
1739 *flags = mixer->mixing_flags;
1740 LeaveCriticalSection(&mixer->cs);
1742 return S_OK;
1745 static const IMFVideoMixerControl2Vtbl video_mixer_control_vtbl =
1747 video_mixer_control_QueryInterface,
1748 video_mixer_control_AddRef,
1749 video_mixer_control_Release,
1750 video_mixer_control_SetStreamZOrder,
1751 video_mixer_control_GetStreamZOrder,
1752 video_mixer_control_SetStreamOutputRect,
1753 video_mixer_control_GetStreamOutputRect,
1754 video_mixer_control_SetMixingPrefs,
1755 video_mixer_control_GetMixingPrefs,
1758 static HRESULT WINAPI video_mixer_getservice_QueryInterface(IMFGetService *iface, REFIID riid, void **obj)
1760 struct video_mixer *mixer = impl_from_IMFGetService(iface);
1761 return IMFTransform_QueryInterface(&mixer->IMFTransform_iface, riid, obj);
1764 static ULONG WINAPI video_mixer_getservice_AddRef(IMFGetService *iface)
1766 struct video_mixer *mixer = impl_from_IMFGetService(iface);
1767 return IMFTransform_AddRef(&mixer->IMFTransform_iface);
1770 static ULONG WINAPI video_mixer_getservice_Release(IMFGetService *iface)
1772 struct video_mixer *mixer = impl_from_IMFGetService(iface);
1773 return IMFTransform_Release(&mixer->IMFTransform_iface);
1776 static HRESULT WINAPI video_mixer_getservice_GetService(IMFGetService *iface, REFGUID service, REFIID riid, void **obj)
1778 TRACE("%p, %s, %s, %p.\n", iface, debugstr_guid(service), debugstr_guid(riid), obj);
1780 if (IsEqualGUID(service, &MR_VIDEO_MIXER_SERVICE))
1782 if (IsEqualIID(riid, &IID_IMFVideoMixerBitmap) ||
1783 IsEqualIID(riid, &IID_IMFVideoProcessor) ||
1784 IsEqualIID(riid, &IID_IMFVideoPositionMapper) ||
1785 IsEqualIID(riid, &IID_IMFVideoMixerControl) ||
1786 IsEqualIID(riid, &IID_IMFVideoMixerControl2))
1788 return IMFGetService_QueryInterface(iface, riid, obj);
1791 return E_NOINTERFACE;
1794 FIXME("Unsupported service %s, riid %s.\n", debugstr_guid(service), debugstr_guid(riid));
1796 return MF_E_UNSUPPORTED_SERVICE;
1799 static const IMFGetServiceVtbl video_mixer_getservice_vtbl =
1801 video_mixer_getservice_QueryInterface,
1802 video_mixer_getservice_AddRef,
1803 video_mixer_getservice_Release,
1804 video_mixer_getservice_GetService,
1807 static HRESULT WINAPI video_mixer_bitmap_QueryInterface(IMFVideoMixerBitmap *iface, REFIID riid, void **obj)
1809 struct video_mixer *mixer = impl_from_IMFVideoMixerBitmap(iface);
1810 return IMFTransform_QueryInterface(&mixer->IMFTransform_iface, riid, obj);
1813 static ULONG WINAPI video_mixer_bitmap_AddRef(IMFVideoMixerBitmap *iface)
1815 struct video_mixer *mixer = impl_from_IMFVideoMixerBitmap(iface);
1816 return IMFTransform_AddRef(&mixer->IMFTransform_iface);
1819 static ULONG WINAPI video_mixer_bitmap_Release(IMFVideoMixerBitmap *iface)
1821 struct video_mixer *mixer = impl_from_IMFVideoMixerBitmap(iface);
1822 return IMFTransform_Release(&mixer->IMFTransform_iface);
1825 static HRESULT WINAPI video_mixer_bitmap_SetAlphaBitmap(IMFVideoMixerBitmap *iface, const MFVideoAlphaBitmap *bitmap)
1827 FIXME("%p, %p.\n", iface, bitmap);
1829 return E_NOTIMPL;
1832 static HRESULT WINAPI video_mixer_bitmap_ClearAlphaBitmap(IMFVideoMixerBitmap *iface)
1834 FIXME("%p.\n", iface);
1836 return E_NOTIMPL;
1839 static HRESULT WINAPI video_mixer_bitmap_UpdateAlphaBitmapParameters(IMFVideoMixerBitmap *iface,
1840 const MFVideoAlphaBitmapParams *params)
1842 FIXME("%p, %p.\n", iface, params);
1844 return E_NOTIMPL;
1847 static HRESULT WINAPI video_mixer_bitmap_GetAlphaBitmapParameters(IMFVideoMixerBitmap *iface, MFVideoAlphaBitmapParams *params)
1849 FIXME("%p, %p.\n", iface, params);
1851 return E_NOTIMPL;
1854 static const IMFVideoMixerBitmapVtbl video_mixer_bitmap_vtbl =
1856 video_mixer_bitmap_QueryInterface,
1857 video_mixer_bitmap_AddRef,
1858 video_mixer_bitmap_Release,
1859 video_mixer_bitmap_SetAlphaBitmap,
1860 video_mixer_bitmap_ClearAlphaBitmap,
1861 video_mixer_bitmap_UpdateAlphaBitmapParameters,
1862 video_mixer_bitmap_GetAlphaBitmapParameters,
1865 static HRESULT WINAPI video_mixer_position_mapper_QueryInterface(IMFVideoPositionMapper *iface, REFIID riid, void **obj)
1867 struct video_mixer *mixer = impl_from_IMFVideoPositionMapper(iface);
1868 return IMFTransform_QueryInterface(&mixer->IMFTransform_iface, riid, obj);
1871 static ULONG WINAPI video_mixer_position_mapper_AddRef(IMFVideoPositionMapper *iface)
1873 struct video_mixer *mixer = impl_from_IMFVideoPositionMapper(iface);
1874 return IMFTransform_AddRef(&mixer->IMFTransform_iface);
1877 static ULONG WINAPI video_mixer_position_mapper_Release(IMFVideoPositionMapper *iface)
1879 struct video_mixer *mixer = impl_from_IMFVideoPositionMapper(iface);
1880 return IMFTransform_Release(&mixer->IMFTransform_iface);
1883 static HRESULT WINAPI video_mixer_position_mapper_MapOutputCoordinateToInputStream(IMFVideoPositionMapper *iface,
1884 float x_out, float y_out, DWORD output_stream, DWORD input_stream, float *x_in, float *y_in)
1886 FIXME("%p, %f, %f, %u, %u, %p, %p.\n", iface, x_out, y_out, output_stream, input_stream, x_in, y_in);
1888 return E_NOTIMPL;
1891 static const IMFVideoPositionMapperVtbl video_mixer_position_mapper_vtbl =
1893 video_mixer_position_mapper_QueryInterface,
1894 video_mixer_position_mapper_AddRef,
1895 video_mixer_position_mapper_Release,
1896 video_mixer_position_mapper_MapOutputCoordinateToInputStream,
1899 static HRESULT WINAPI video_mixer_processor_QueryInterface(IMFVideoProcessor *iface, REFIID riid, void **obj)
1901 struct video_mixer *mixer = impl_from_IMFVideoProcessor(iface);
1902 return IMFTransform_QueryInterface(&mixer->IMFTransform_iface, riid, obj);
1905 static ULONG WINAPI video_mixer_processor_AddRef(IMFVideoProcessor *iface)
1907 struct video_mixer *mixer = impl_from_IMFVideoProcessor(iface);
1908 return IMFTransform_AddRef(&mixer->IMFTransform_iface);
1911 static ULONG WINAPI video_mixer_processor_Release(IMFVideoProcessor *iface)
1913 struct video_mixer *mixer = impl_from_IMFVideoProcessor(iface);
1914 return IMFTransform_Release(&mixer->IMFTransform_iface);
1917 static HRESULT WINAPI video_mixer_processor_GetAvailableVideoProcessorModes(IMFVideoProcessor *iface, UINT *count,
1918 GUID **modes)
1920 FIXME("%p, %p, %p.\n", iface, count, modes);
1922 return E_NOTIMPL;
1925 static HRESULT WINAPI video_mixer_processor_GetVideoProcessorCaps(IMFVideoProcessor *iface, GUID *mode,
1926 DXVA2_VideoProcessorCaps *caps)
1928 FIXME("%p, %s, %p.\n", iface, debugstr_guid(mode), caps);
1930 return E_NOTIMPL;
1933 static HRESULT WINAPI video_mixer_processor_GetVideoProcessorMode(IMFVideoProcessor *iface, GUID *mode)
1935 FIXME("%p, %p.\n", iface, mode);
1937 return E_NOTIMPL;
1940 static HRESULT WINAPI video_mixer_processor_SetVideoProcessorMode(IMFVideoProcessor *iface, GUID *mode)
1942 FIXME("%p, %s.\n", iface, debugstr_guid(mode));
1944 return E_NOTIMPL;
1947 static HRESULT WINAPI video_mixer_processor_GetProcAmpRange(IMFVideoProcessor *iface, DWORD prop, DXVA2_ValueRange *range)
1949 FIXME("%p, %#x, %p.\n", iface, prop, range);
1951 return E_NOTIMPL;
1954 static HRESULT WINAPI video_mixer_processor_GetProcAmpValues(IMFVideoProcessor *iface, DWORD flags, DXVA2_ProcAmpValues *values)
1956 FIXME("%p, %#x, %p.\n", iface, flags, values);
1958 return E_NOTIMPL;
1961 static HRESULT WINAPI video_mixer_processor_SetProcAmpValues(IMFVideoProcessor *iface, DWORD flags, DXVA2_ProcAmpValues *values)
1963 FIXME("%p, %#x, %p.\n", iface, flags, values);
1965 return E_NOTIMPL;
1968 static HRESULT WINAPI video_mixer_processor_GetFilteringRange(IMFVideoProcessor *iface, DWORD prop, DXVA2_ValueRange *range)
1970 FIXME("%p, %#x, %p.\n", iface, prop, range);
1972 return E_NOTIMPL;
1975 static HRESULT WINAPI video_mixer_processor_GetFilteringValue(IMFVideoProcessor *iface, DWORD prop, DXVA2_Fixed32 *value)
1977 FIXME("%p, %#x, %p.\n", iface, prop, value);
1979 return E_NOTIMPL;
1982 static HRESULT WINAPI video_mixer_processor_SetFilteringValue(IMFVideoProcessor *iface, DWORD prop, DXVA2_Fixed32 *value)
1984 FIXME("%p, %#x, %p.\n", iface, prop, value);
1986 return E_NOTIMPL;
1989 static HRESULT WINAPI video_mixer_processor_GetBackgroundColor(IMFVideoProcessor *iface, COLORREF *color)
1991 struct video_mixer *mixer = impl_from_IMFVideoProcessor(iface);
1993 TRACE("%p, %p.\n", iface, color);
1995 if (!color)
1996 return E_POINTER;
1998 EnterCriticalSection(&mixer->cs);
1999 *color = mixer->bkgnd_color.rgba;
2000 LeaveCriticalSection(&mixer->cs);
2002 return S_OK;
2005 static void video_mixer_rgb_to_ycbcr(COLORREF rgb, DXVA2_AYUVSample16 *ayuv)
2007 int y, cb, cr, r, g, b;
2009 r = GetRValue(rgb); g = GetGValue(rgb); b = GetBValue(rgb);
2010 /* Coefficients according to SDTV ITU-R BT.601 */
2011 y = (77 * r + 150 * g + 29 * b + 128) / 256 + 16;
2012 cb = (-44 * r - 87 * g + 131 * b + 128) / 256 + 128;
2013 cr = (131 * r - 110 * g - 21 * b + 128) / 256 + 128;
2015 ayuv->Y = y * 0x100;
2016 ayuv->Cb = cb * 0x100;
2017 ayuv->Cr = cr * 0x100;
2018 ayuv->Alpha = 0xffff;
2021 static HRESULT WINAPI video_mixer_processor_SetBackgroundColor(IMFVideoProcessor *iface, COLORREF color)
2023 struct video_mixer *mixer = impl_from_IMFVideoProcessor(iface);
2025 TRACE("%p, %#x.\n", iface, color);
2027 EnterCriticalSection(&mixer->cs);
2028 if (mixer->bkgnd_color.rgba != color)
2030 video_mixer_rgb_to_ycbcr(color, &mixer->bkgnd_color.ayuv);
2031 mixer->bkgnd_color.rgba = color;
2033 LeaveCriticalSection(&mixer->cs);
2035 return S_OK;
2038 static const IMFVideoProcessorVtbl video_mixer_processor_vtbl =
2040 video_mixer_processor_QueryInterface,
2041 video_mixer_processor_AddRef,
2042 video_mixer_processor_Release,
2043 video_mixer_processor_GetAvailableVideoProcessorModes,
2044 video_mixer_processor_GetVideoProcessorCaps,
2045 video_mixer_processor_GetVideoProcessorMode,
2046 video_mixer_processor_SetVideoProcessorMode,
2047 video_mixer_processor_GetProcAmpRange,
2048 video_mixer_processor_GetProcAmpValues,
2049 video_mixer_processor_SetProcAmpValues,
2050 video_mixer_processor_GetFilteringRange,
2051 video_mixer_processor_GetFilteringValue,
2052 video_mixer_processor_SetFilteringValue,
2053 video_mixer_processor_GetBackgroundColor,
2054 video_mixer_processor_SetBackgroundColor,
2057 static HRESULT WINAPI video_mixer_attributes_QueryInterface(IMFAttributes *iface, REFIID riid, void **out)
2059 struct video_mixer *mixer = impl_from_IMFAttributes(iface);
2060 return IMFTransform_QueryInterface(&mixer->IMFTransform_iface, riid, out);
2063 static ULONG WINAPI video_mixer_attributes_AddRef(IMFAttributes *iface)
2065 struct video_mixer *mixer = impl_from_IMFAttributes(iface);
2066 return IMFTransform_AddRef(&mixer->IMFTransform_iface);
2069 static ULONG WINAPI video_mixer_attributes_Release(IMFAttributes *iface)
2071 struct video_mixer *mixer = impl_from_IMFAttributes(iface);
2072 return IMFTransform_Release(&mixer->IMFTransform_iface);
2075 static HRESULT WINAPI video_mixer_attributes_GetItem(IMFAttributes *iface, REFGUID key, PROPVARIANT *value)
2077 struct video_mixer *mixer = impl_from_IMFAttributes(iface);
2079 TRACE("%p, %s, %p.\n", iface, debugstr_guid(key), value);
2081 return IMFAttributes_GetItem(mixer->internal_attributes, key, value);
2084 static HRESULT WINAPI video_mixer_attributes_GetItemType(IMFAttributes *iface, REFGUID key, MF_ATTRIBUTE_TYPE *type)
2086 struct video_mixer *mixer = impl_from_IMFAttributes(iface);
2088 TRACE("%p, %s, %p.\n", iface, debugstr_guid(key), type);
2090 return IMFAttributes_GetItemType(mixer->internal_attributes, key, type);
2093 static HRESULT WINAPI video_mixer_attributes_CompareItem(IMFAttributes *iface, REFGUID key,
2094 REFPROPVARIANT value, BOOL *result)
2096 struct video_mixer *mixer = impl_from_IMFAttributes(iface);
2098 TRACE("%p, %s, %p, %p.\n", iface, debugstr_guid(key), value, result);
2100 return IMFAttributes_CompareItem(mixer->internal_attributes, key, value, result);
2103 static HRESULT WINAPI video_mixer_attributes_Compare(IMFAttributes *iface, IMFAttributes *theirs,
2104 MF_ATTRIBUTES_MATCH_TYPE match_type, BOOL *ret)
2106 struct video_mixer *mixer = impl_from_IMFAttributes(iface);
2108 TRACE("%p, %p, %d, %p.\n", iface, theirs, match_type, ret);
2110 return IMFAttributes_Compare(mixer->internal_attributes, theirs, match_type, ret);
2113 static HRESULT WINAPI video_mixer_attributes_GetUINT32(IMFAttributes *iface, REFGUID key, UINT32 *value)
2115 struct video_mixer *mixer = impl_from_IMFAttributes(iface);
2117 TRACE("%p, %s, %p.\n", iface, debugstr_guid(key), value);
2119 return IMFAttributes_GetUINT32(mixer->internal_attributes, key, value);
2122 static HRESULT WINAPI video_mixer_attributes_GetUINT64(IMFAttributes *iface, REFGUID key, UINT64 *value)
2124 struct video_mixer *mixer = impl_from_IMFAttributes(iface);
2126 TRACE("%p, %s, %p.\n", iface, debugstr_guid(key), value);
2128 return IMFAttributes_GetUINT64(mixer->internal_attributes, key, value);
2131 static HRESULT WINAPI video_mixer_attributes_GetDouble(IMFAttributes *iface, REFGUID key, double *value)
2133 struct video_mixer *mixer = impl_from_IMFAttributes(iface);
2135 TRACE("%p, %s, %p.\n", iface, debugstr_guid(key), value);
2137 return IMFAttributes_GetDouble(mixer->internal_attributes, key, value);
2140 static HRESULT WINAPI video_mixer_attributes_GetGUID(IMFAttributes *iface, REFGUID key, GUID *value)
2142 struct video_mixer *mixer = impl_from_IMFAttributes(iface);
2144 TRACE("%p, %s, %p.\n", iface, debugstr_guid(key), value);
2146 return IMFAttributes_GetGUID(mixer->internal_attributes, key, value);
2149 static HRESULT WINAPI video_mixer_attributes_GetStringLength(IMFAttributes *iface, REFGUID key, UINT32 *length)
2151 struct video_mixer *mixer = impl_from_IMFAttributes(iface);
2153 TRACE("%p, %s, %p.\n", iface, debugstr_guid(key), length);
2155 return IMFAttributes_GetStringLength(mixer->internal_attributes, key, length);
2158 static HRESULT WINAPI video_mixer_attributes_GetString(IMFAttributes *iface, REFGUID key, WCHAR *value,
2159 UINT32 size, UINT32 *length)
2161 struct video_mixer *mixer = impl_from_IMFAttributes(iface);
2163 TRACE("%p, %s, %p, %d, %p.\n", iface, debugstr_guid(key), value, size, length);
2165 return IMFAttributes_GetString(mixer->internal_attributes, key, value, size, length);
2168 static HRESULT WINAPI video_mixer_attributes_GetAllocatedString(IMFAttributes *iface, REFGUID key,
2169 WCHAR **value, UINT32 *length)
2171 struct video_mixer *mixer = impl_from_IMFAttributes(iface);
2173 TRACE("%p, %s, %p, %p.\n", iface, debugstr_guid(key), value, length);
2175 return IMFAttributes_GetAllocatedString(mixer->internal_attributes, key, value, length);
2178 static HRESULT WINAPI video_mixer_attributes_GetBlobSize(IMFAttributes *iface, REFGUID key, UINT32 *size)
2180 struct video_mixer *mixer = impl_from_IMFAttributes(iface);
2182 TRACE("%p, %s, %p.\n", iface, debugstr_guid(key), size);
2184 return IMFAttributes_GetBlobSize(mixer->internal_attributes, key, size);
2187 static HRESULT WINAPI video_mixer_attributes_GetBlob(IMFAttributes *iface, REFGUID key, UINT8 *buf,
2188 UINT32 bufsize, UINT32 *blobsize)
2190 struct video_mixer *mixer = impl_from_IMFAttributes(iface);
2192 TRACE("%p, %s, %p, %d, %p.\n", iface, debugstr_guid(key), buf, bufsize, blobsize);
2194 return IMFAttributes_GetBlob(mixer->internal_attributes, key, buf, bufsize, blobsize);
2197 static HRESULT WINAPI video_mixer_attributes_GetAllocatedBlob(IMFAttributes *iface, REFGUID key, UINT8 **buf, UINT32 *size)
2199 struct video_mixer *mixer = impl_from_IMFAttributes(iface);
2201 TRACE("%p, %s, %p, %p.\n", iface, debugstr_guid(key), buf, size);
2203 return IMFAttributes_GetAllocatedBlob(mixer->internal_attributes, key, buf, size);
2206 static HRESULT WINAPI video_mixer_attributes_GetUnknown(IMFAttributes *iface, REFGUID key, REFIID riid, void **out)
2208 struct video_mixer *mixer = impl_from_IMFAttributes(iface);
2210 TRACE("%p, %s, %s, %p.\n", iface, debugstr_guid(key), debugstr_guid(riid), out);
2212 return IMFAttributes_GetUnknown(mixer->internal_attributes, key, riid, out);
2215 static HRESULT WINAPI video_mixer_attributes_SetItem(IMFAttributes *iface, REFGUID key, REFPROPVARIANT value)
2217 struct video_mixer *mixer = impl_from_IMFAttributes(iface);
2219 TRACE("%p, %s, %p.\n", iface, debugstr_guid(key), value);
2221 return IMFAttributes_SetItem(mixer->internal_attributes, key, value);
2224 static HRESULT WINAPI video_mixer_attributes_DeleteItem(IMFAttributes *iface, REFGUID key)
2226 struct video_mixer *mixer = impl_from_IMFAttributes(iface);
2228 TRACE("%p, %s.\n", iface, debugstr_guid(key));
2230 return IMFAttributes_DeleteItem(mixer->internal_attributes, key);
2233 static HRESULT WINAPI video_mixer_attributes_DeleteAllItems(IMFAttributes *iface)
2235 struct video_mixer *mixer = impl_from_IMFAttributes(iface);
2237 TRACE("%p.\n", iface);
2239 return IMFAttributes_DeleteAllItems(mixer->internal_attributes);
2242 static HRESULT WINAPI video_mixer_attributes_SetUINT32(IMFAttributes *iface, REFGUID key, UINT32 value)
2244 struct video_mixer *mixer = impl_from_IMFAttributes(iface);
2246 TRACE("%p, %s, %u.\n", iface, debugstr_guid(key), value);
2248 return IMFAttributes_SetUINT32(mixer->internal_attributes, key, value);
2251 static HRESULT WINAPI video_mixer_attributes_SetUINT64(IMFAttributes *iface, REFGUID key, UINT64 value)
2253 struct video_mixer *mixer = impl_from_IMFAttributes(iface);
2255 TRACE("%p, %s, %s.\n", iface, debugstr_guid(key), wine_dbgstr_longlong(value));
2257 return IMFAttributes_SetUINT64(mixer->internal_attributes, key, value);
2260 static HRESULT WINAPI video_mixer_attributes_SetDouble(IMFAttributes *iface, REFGUID key, double value)
2262 struct video_mixer *mixer = impl_from_IMFAttributes(iface);
2264 TRACE("%p, %s, %f.\n", iface, debugstr_guid(key), value);
2266 return IMFAttributes_SetDouble(mixer->internal_attributes, key, value);
2269 static HRESULT WINAPI video_mixer_attributes_SetGUID(IMFAttributes *iface, REFGUID key, REFGUID value)
2271 struct video_mixer *mixer = impl_from_IMFAttributes(iface);
2273 TRACE("%p, %s, %s.\n", iface, debugstr_guid(key), debugstr_guid(value));
2275 return IMFAttributes_SetGUID(mixer->internal_attributes, key, value);
2278 static HRESULT WINAPI video_mixer_attributes_SetString(IMFAttributes *iface, REFGUID key, const WCHAR *value)
2280 struct video_mixer *mixer = impl_from_IMFAttributes(iface);
2282 TRACE("%p, %s, %s.\n", iface, debugstr_guid(key), debugstr_w(value));
2284 return IMFAttributes_SetString(mixer->internal_attributes, key, value);
2287 static HRESULT WINAPI video_mixer_attributes_SetBlob(IMFAttributes *iface, REFGUID key, const UINT8 *buf, UINT32 size)
2289 struct video_mixer *mixer = impl_from_IMFAttributes(iface);
2291 TRACE("%p, %s, %p, %u.\n", iface, debugstr_guid(key), buf, size);
2293 return IMFAttributes_SetBlob(mixer->internal_attributes, key, buf, size);
2296 static HRESULT WINAPI video_mixer_attributes_SetUnknown(IMFAttributes *iface, REFGUID key, IUnknown *unknown)
2298 struct video_mixer *mixer = impl_from_IMFAttributes(iface);
2300 TRACE("%p, %s, %p.\n", iface, debugstr_guid(key), unknown);
2302 return IMFAttributes_SetUnknown(mixer->internal_attributes, key, unknown);
2305 static HRESULT WINAPI video_mixer_attributes_LockStore(IMFAttributes *iface)
2307 struct video_mixer *mixer = impl_from_IMFAttributes(iface);
2309 TRACE("%p.\n", iface);
2311 return IMFAttributes_LockStore(mixer->internal_attributes);
2314 static HRESULT WINAPI video_mixer_attributes_UnlockStore(IMFAttributes *iface)
2316 struct video_mixer *mixer = impl_from_IMFAttributes(iface);
2318 TRACE("%p.\n", iface);
2320 return IMFAttributes_UnlockStore(mixer->internal_attributes);
2323 static HRESULT WINAPI video_mixer_attributes_GetCount(IMFAttributes *iface, UINT32 *count)
2325 struct video_mixer *mixer = impl_from_IMFAttributes(iface);
2327 TRACE("%p, %p.\n", iface, count);
2329 return IMFAttributes_GetCount(mixer->internal_attributes, count);
2332 static HRESULT WINAPI video_mixer_attributes_GetItemByIndex(IMFAttributes *iface, UINT32 index,
2333 GUID *key, PROPVARIANT *value)
2335 struct video_mixer *mixer = impl_from_IMFAttributes(iface);
2337 TRACE("%p, %u, %p, %p.\n", iface, index, key, value);
2339 return IMFAttributes_GetItemByIndex(mixer->internal_attributes, index, key, value);
2342 static HRESULT WINAPI video_mixer_attributes_CopyAllItems(IMFAttributes *iface, IMFAttributes *dest)
2344 struct video_mixer *mixer = impl_from_IMFAttributes(iface);
2346 TRACE("%p, %p.\n", iface, dest);
2348 return IMFAttributes_CopyAllItems(mixer->internal_attributes, dest);
2351 static const IMFAttributesVtbl video_mixer_attributes_vtbl =
2353 video_mixer_attributes_QueryInterface,
2354 video_mixer_attributes_AddRef,
2355 video_mixer_attributes_Release,
2356 video_mixer_attributes_GetItem,
2357 video_mixer_attributes_GetItemType,
2358 video_mixer_attributes_CompareItem,
2359 video_mixer_attributes_Compare,
2360 video_mixer_attributes_GetUINT32,
2361 video_mixer_attributes_GetUINT64,
2362 video_mixer_attributes_GetDouble,
2363 video_mixer_attributes_GetGUID,
2364 video_mixer_attributes_GetStringLength,
2365 video_mixer_attributes_GetString,
2366 video_mixer_attributes_GetAllocatedString,
2367 video_mixer_attributes_GetBlobSize,
2368 video_mixer_attributes_GetBlob,
2369 video_mixer_attributes_GetAllocatedBlob,
2370 video_mixer_attributes_GetUnknown,
2371 video_mixer_attributes_SetItem,
2372 video_mixer_attributes_DeleteItem,
2373 video_mixer_attributes_DeleteAllItems,
2374 video_mixer_attributes_SetUINT32,
2375 video_mixer_attributes_SetUINT64,
2376 video_mixer_attributes_SetDouble,
2377 video_mixer_attributes_SetGUID,
2378 video_mixer_attributes_SetString,
2379 video_mixer_attributes_SetBlob,
2380 video_mixer_attributes_SetUnknown,
2381 video_mixer_attributes_LockStore,
2382 video_mixer_attributes_UnlockStore,
2383 video_mixer_attributes_GetCount,
2384 video_mixer_attributes_GetItemByIndex,
2385 video_mixer_attributes_CopyAllItems
2388 static HRESULT WINAPI video_mixer_quality_advise_QueryInterface(IMFQualityAdvise *iface, REFIID riid, void **out)
2390 struct video_mixer *mixer = impl_from_IMFQualityAdvise(iface);
2391 return IMFTransform_QueryInterface(&mixer->IMFTransform_iface, riid, out);
2394 static ULONG WINAPI video_mixer_quality_advise_AddRef(IMFQualityAdvise *iface)
2396 struct video_mixer *mixer = impl_from_IMFQualityAdvise(iface);
2397 return IMFTransform_AddRef(&mixer->IMFTransform_iface);
2400 static ULONG WINAPI video_mixer_quality_advise_Release(IMFQualityAdvise *iface)
2402 struct video_mixer *mixer = impl_from_IMFQualityAdvise(iface);
2403 return IMFTransform_Release(&mixer->IMFTransform_iface);
2406 static HRESULT WINAPI video_mixer_quality_advise_SetDropMode(IMFQualityAdvise *iface, MF_QUALITY_DROP_MODE mode)
2408 FIXME("%p, %u.\n", iface, mode);
2410 return E_NOTIMPL;
2413 static HRESULT WINAPI video_mixer_quality_advise_SetQualityLevel(IMFQualityAdvise *iface, MF_QUALITY_LEVEL level)
2415 FIXME("%p, %u.\n", iface, level);
2417 return E_NOTIMPL;
2420 static HRESULT WINAPI video_mixer_quality_advise_GetDropMode(IMFQualityAdvise *iface, MF_QUALITY_DROP_MODE *mode)
2422 FIXME("%p, %p.\n", iface, mode);
2424 return E_NOTIMPL;
2427 static HRESULT WINAPI video_mixer_quality_advise_GetQualityLevel(IMFQualityAdvise *iface, MF_QUALITY_LEVEL *level)
2429 FIXME("%p, %p.\n", iface, level);
2431 return E_NOTIMPL;
2434 static HRESULT WINAPI video_mixer_quality_advise_DropTime(IMFQualityAdvise *iface, LONGLONG interval)
2436 FIXME("%p, %s.\n", iface, wine_dbgstr_longlong(interval));
2438 return E_NOTIMPL;
2441 static const IMFQualityAdviseVtbl video_mixer_quality_advise_vtbl =
2443 video_mixer_quality_advise_QueryInterface,
2444 video_mixer_quality_advise_AddRef,
2445 video_mixer_quality_advise_Release,
2446 video_mixer_quality_advise_SetDropMode,
2447 video_mixer_quality_advise_SetQualityLevel,
2448 video_mixer_quality_advise_GetDropMode,
2449 video_mixer_quality_advise_GetQualityLevel,
2450 video_mixer_quality_advise_DropTime,
2453 static HRESULT WINAPI video_mixer_clock_state_sink_QueryInterface(IMFClockStateSink *iface,
2454 REFIID riid, void **out)
2456 struct video_mixer *mixer = impl_from_IMFClockStateSink(iface);
2457 return IMFTransform_QueryInterface(&mixer->IMFTransform_iface, riid, out);
2460 static ULONG WINAPI video_mixer_clock_state_sink_AddRef(IMFClockStateSink *iface)
2462 struct video_mixer *mixer = impl_from_IMFClockStateSink(iface);
2463 return IMFTransform_AddRef(&mixer->IMFTransform_iface);
2466 static ULONG WINAPI video_mixer_clock_state_sink_Release(IMFClockStateSink *iface)
2468 struct video_mixer *mixer = impl_from_IMFClockStateSink(iface);
2469 return IMFTransform_Release(&mixer->IMFTransform_iface);
2472 static HRESULT WINAPI video_mixer_clock_state_sink_OnClockStart(IMFClockStateSink *iface,
2473 MFTIME systime, LONGLONG offset)
2475 FIXME("%p.\n", iface);
2477 return E_NOTIMPL;
2480 static HRESULT WINAPI video_mixer_clock_state_sink_OnClockStop(IMFClockStateSink *iface,
2481 MFTIME systime)
2483 FIXME("%p.\n", iface);
2485 return E_NOTIMPL;
2488 static HRESULT WINAPI video_mixer_clock_state_sink_OnClockPause(IMFClockStateSink *iface,
2489 MFTIME systime)
2491 FIXME("%p.\n", iface);
2493 return E_NOTIMPL;
2496 static HRESULT WINAPI video_mixer_clock_state_sink_OnClockRestart(IMFClockStateSink *iface,
2497 MFTIME systime)
2499 FIXME("%p.\n", iface);
2501 return E_NOTIMPL;
2504 static HRESULT WINAPI video_mixer_clock_state_sink_OnClockSetRate(IMFClockStateSink *iface,
2505 MFTIME systime, float rate)
2507 FIXME("%p, %f.\n", iface, rate);
2509 return E_NOTIMPL;
2512 static const IMFClockStateSinkVtbl video_mixer_clock_state_sink_vtbl =
2514 video_mixer_clock_state_sink_QueryInterface,
2515 video_mixer_clock_state_sink_AddRef,
2516 video_mixer_clock_state_sink_Release,
2517 video_mixer_clock_state_sink_OnClockStart,
2518 video_mixer_clock_state_sink_OnClockStop,
2519 video_mixer_clock_state_sink_OnClockPause,
2520 video_mixer_clock_state_sink_OnClockRestart,
2521 video_mixer_clock_state_sink_OnClockSetRate,
2524 HRESULT WINAPI MFCreateVideoMixer(IUnknown *owner, REFIID riid_device, REFIID riid, void **obj)
2526 TRACE("%p, %s, %s, %p.\n", owner, debugstr_guid(riid_device), debugstr_guid(riid), obj);
2528 *obj = NULL;
2530 if (!IsEqualIID(riid_device, &IID_IDirect3DDevice9))
2531 return E_INVALIDARG;
2533 return CoCreateInstance(&CLSID_MFVideoMixer9, owner, CLSCTX_INPROC_SERVER, riid, obj);
2536 HRESULT evr_mixer_create(IUnknown *outer, void **out)
2538 struct video_mixer *object;
2539 MFVideoNormalizedRect rect;
2540 HRESULT hr;
2542 if (!(object = calloc(1, sizeof(*object))))
2543 return E_OUTOFMEMORY;
2545 object->IMFTransform_iface.lpVtbl = &video_mixer_transform_vtbl;
2546 object->IMFVideoDeviceID_iface.lpVtbl = &video_mixer_device_id_vtbl;
2547 object->IMFTopologyServiceLookupClient_iface.lpVtbl = &video_mixer_service_client_vtbl;
2548 object->IMFVideoMixerControl2_iface.lpVtbl = &video_mixer_control_vtbl;
2549 object->IMFGetService_iface.lpVtbl = &video_mixer_getservice_vtbl;
2550 object->IMFVideoMixerBitmap_iface.lpVtbl = &video_mixer_bitmap_vtbl;
2551 object->IMFVideoPositionMapper_iface.lpVtbl = &video_mixer_position_mapper_vtbl;
2552 object->IMFVideoProcessor_iface.lpVtbl = &video_mixer_processor_vtbl;
2553 object->IMFAttributes_iface.lpVtbl = &video_mixer_attributes_vtbl;
2554 object->IMFQualityAdvise_iface.lpVtbl = &video_mixer_quality_advise_vtbl;
2555 object->IMFClockStateSink_iface.lpVtbl = &video_mixer_clock_state_sink_vtbl;
2556 object->IUnknown_inner.lpVtbl = &video_mixer_inner_vtbl;
2557 object->outer_unk = outer ? outer : &object->IUnknown_inner;
2558 object->refcount = 1;
2559 object->input_count = 1;
2560 object->lower_bound = MFT_OUTPUT_BOUND_LOWER_UNBOUNDED;
2561 object->upper_bound = MFT_OUTPUT_BOUND_UPPER_UNBOUNDED;
2562 video_mixer_init_input(&object->inputs[0]);
2563 video_mixer_update_zorder_map(object);
2564 video_mixer_rgb_to_ycbcr(object->bkgnd_color.rgba, &object->bkgnd_color.ayuv);
2565 InitializeCriticalSection(&object->cs);
2566 if (FAILED(hr = MFCreateAttributes(&object->attributes, 0)))
2568 IUnknown_Release(&object->IUnknown_inner);
2569 return hr;
2571 if (FAILED(hr = MFCreateAttributes(&object->internal_attributes, 0)))
2573 IUnknown_Release(&object->IUnknown_inner);
2574 return hr;
2577 /* Default attributes configuration. */
2579 rect.left = rect.top = 0.0f;
2580 rect.right = rect.bottom = 1.0f;
2581 IMFAttributes_SetBlob(object->attributes, &VIDEO_ZOOM_RECT, (const UINT8 *)&rect, sizeof(rect));
2583 IMFAttributes_SetUINT32(object->internal_attributes, &MF_SA_D3D_AWARE, 1);
2585 *out = &object->IUnknown_inner;
2587 return S_OK;