gdi32: Move the font cache list out of freetype.c.
[wine.git] / dlls / mf / topology.c
blob8032e438b732d0395023eb78d6c0adbf1f30e9d8
1 /*
2 * Copyright 2017 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
20 #include <stdarg.h>
22 #define COBJMACROS
24 #include "windef.h"
25 #include "winbase.h"
27 #undef INITGUID
28 #include <guiddef.h>
29 #include "mfidl.h"
31 #include "wine/debug.h"
33 #include "mf_private.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(mfplat);
37 static LONG next_node_id;
38 static TOPOID next_topology_id;
40 struct node_stream
42 IMFMediaType *preferred_type;
43 struct topology_node *connection;
44 DWORD connection_stream;
47 struct node_streams
49 struct node_stream *streams;
50 size_t size;
51 size_t count;
54 struct topology_node
56 IMFTopologyNode IMFTopologyNode_iface;
57 LONG refcount;
58 IMFAttributes *attributes;
59 MF_TOPOLOGY_TYPE node_type;
60 TOPOID id;
61 IUnknown *object;
62 IMFMediaType *input_type; /* Only for tee nodes. */
63 struct node_streams inputs;
64 struct node_streams outputs;
65 CRITICAL_SECTION cs;
68 struct topology
70 IMFTopology IMFTopology_iface;
71 LONG refcount;
72 IMFAttributes *attributes;
73 struct
75 struct topology_node **nodes;
76 size_t size;
77 size_t count;
78 } nodes;
79 TOPOID id;
82 struct topology_loader
84 IMFTopoLoader IMFTopoLoader_iface;
85 LONG refcount;
88 struct seq_source
90 IMFSequencerSource IMFSequencerSource_iface;
91 IMFMediaSourceTopologyProvider IMFMediaSourceTopologyProvider_iface;
92 LONG refcount;
95 static inline struct topology *impl_from_IMFTopology(IMFTopology *iface)
97 return CONTAINING_RECORD(iface, struct topology, IMFTopology_iface);
100 static struct topology_node *impl_from_IMFTopologyNode(IMFTopologyNode *iface)
102 return CONTAINING_RECORD(iface, struct topology_node, IMFTopologyNode_iface);
105 static const IMFTopologyNodeVtbl topologynodevtbl;
107 static struct topology_node *unsafe_impl_from_IMFTopologyNode(IMFTopologyNode *iface)
109 if (!iface || iface->lpVtbl != &topologynodevtbl)
110 return NULL;
111 return impl_from_IMFTopologyNode(iface);
114 static HRESULT create_topology_node(MF_TOPOLOGY_TYPE node_type, struct topology_node **node);
115 static HRESULT topology_node_connect_output(struct topology_node *node, DWORD output_index,
116 struct topology_node *connection, DWORD input_index);
118 static struct topology *unsafe_impl_from_IMFTopology(IMFTopology *iface);
120 static struct topology_loader *impl_from_IMFTopoLoader(IMFTopoLoader *iface)
122 return CONTAINING_RECORD(iface, struct topology_loader, IMFTopoLoader_iface);
125 static struct seq_source *impl_from_IMFSequencerSource(IMFSequencerSource *iface)
127 return CONTAINING_RECORD(iface, struct seq_source, IMFSequencerSource_iface);
130 static struct seq_source *impl_from_IMFMediaSourceTopologyProvider(IMFMediaSourceTopologyProvider *iface)
132 return CONTAINING_RECORD(iface, struct seq_source, IMFMediaSourceTopologyProvider_iface);
135 static HRESULT topology_node_reserve_streams(struct node_streams *streams, DWORD index)
137 if (!mf_array_reserve((void **)&streams->streams, &streams->size, index + 1, sizeof(*streams->streams)))
138 return E_OUTOFMEMORY;
140 if (index >= streams->count)
142 memset(&streams->streams[streams->count], 0, (index - streams->count + 1) * sizeof(*streams->streams));
143 streams->count = index + 1;
146 return S_OK;
149 static HRESULT WINAPI topology_QueryInterface(IMFTopology *iface, REFIID riid, void **out)
151 struct topology *topology = impl_from_IMFTopology(iface);
153 TRACE("%p, %s, %p.\n", iface, debugstr_guid(riid), out);
155 if (IsEqualIID(riid, &IID_IMFTopology) ||
156 IsEqualIID(riid, &IID_IMFAttributes) ||
157 IsEqualIID(riid, &IID_IUnknown))
159 *out = &topology->IMFTopology_iface;
161 else
163 FIXME("(%s, %p)\n", debugstr_guid(riid), out);
164 *out = NULL;
165 return E_NOINTERFACE;
168 IUnknown_AddRef((IUnknown*)*out);
169 return S_OK;
172 static ULONG WINAPI topology_AddRef(IMFTopology *iface)
174 struct topology *topology = impl_from_IMFTopology(iface);
175 ULONG refcount = InterlockedIncrement(&topology->refcount);
177 TRACE("%p, refcount %u.\n", iface, refcount);
179 return refcount;
182 static HRESULT topology_node_disconnect_output(struct topology_node *node, DWORD output_index)
184 struct topology_node *connection = NULL;
185 struct node_stream *stream;
186 DWORD connection_stream;
187 HRESULT hr = S_OK;
189 EnterCriticalSection(&node->cs);
191 if (output_index < node->outputs.count)
193 stream = &node->outputs.streams[output_index];
195 if (stream->connection)
197 connection = stream->connection;
198 connection_stream = stream->connection_stream;
199 stream->connection = NULL;
200 stream->connection_stream = 0;
202 else
203 hr = MF_E_NOT_FOUND;
205 else
206 hr = E_INVALIDARG;
208 LeaveCriticalSection(&node->cs);
210 if (connection)
212 EnterCriticalSection(&connection->cs);
214 if (connection_stream < connection->inputs.count)
216 stream = &connection->inputs.streams[connection_stream];
218 if (stream->connection)
220 stream->connection = NULL;
221 stream->connection_stream = 0;
225 LeaveCriticalSection(&connection->cs);
227 IMFTopologyNode_Release(&connection->IMFTopologyNode_iface);
228 IMFTopologyNode_Release(&node->IMFTopologyNode_iface);
231 return hr;
234 static void topology_node_disconnect(struct topology_node *node)
236 struct node_stream *stream;
237 size_t i;
239 for (i = 0; i < node->outputs.count; ++i)
240 topology_node_disconnect_output(node, i);
242 for (i = 0; i < node->inputs.count; ++i)
244 stream = &node->inputs.streams[i];
245 if (stream->connection)
246 topology_node_disconnect_output(stream->connection, stream->connection_stream);
250 static void topology_clear(struct topology *topology)
252 size_t i;
254 for (i = 0; i < topology->nodes.count; ++i)
256 topology_node_disconnect(topology->nodes.nodes[i]);
257 IMFTopologyNode_Release(&topology->nodes.nodes[i]->IMFTopologyNode_iface);
259 heap_free(topology->nodes.nodes);
260 topology->nodes.nodes = NULL;
261 topology->nodes.count = 0;
262 topology->nodes.size = 0;
265 static ULONG WINAPI topology_Release(IMFTopology *iface)
267 struct topology *topology = impl_from_IMFTopology(iface);
268 ULONG refcount = InterlockedDecrement(&topology->refcount);
270 TRACE("%p, refcount %u.\n", iface, refcount);
272 if (!refcount)
274 if (topology->attributes)
275 IMFAttributes_Release(topology->attributes);
276 topology_clear(topology);
277 heap_free(topology);
280 return refcount;
283 static HRESULT WINAPI topology_GetItem(IMFTopology *iface, REFGUID key, PROPVARIANT *value)
285 struct topology *topology = impl_from_IMFTopology(iface);
287 TRACE("%p, %s, %p.\n", iface, debugstr_guid(key), value);
289 return IMFAttributes_GetItem(topology->attributes, key, value);
292 static HRESULT WINAPI topology_GetItemType(IMFTopology *iface, REFGUID key, MF_ATTRIBUTE_TYPE *type)
294 struct topology *topology = impl_from_IMFTopology(iface);
296 TRACE("%p, %s, %p.\n", iface, debugstr_guid(key), type);
298 return IMFAttributes_GetItemType(topology->attributes, key, type);
301 static HRESULT WINAPI topology_CompareItem(IMFTopology *iface, REFGUID key, REFPROPVARIANT value, BOOL *result)
303 struct topology *topology = impl_from_IMFTopology(iface);
305 TRACE("%p, %s, %p, %p.\n", iface, debugstr_guid(key), value, result);
307 return IMFAttributes_CompareItem(topology->attributes, key, value, result);
310 static HRESULT WINAPI topology_Compare(IMFTopology *iface, IMFAttributes *theirs, MF_ATTRIBUTES_MATCH_TYPE type,
311 BOOL *result)
313 struct topology *topology = impl_from_IMFTopology(iface);
315 TRACE("%p, %p, %d, %p.\n", iface, theirs, type, result);
317 return IMFAttributes_Compare(topology->attributes, theirs, type, result);
320 static HRESULT WINAPI topology_GetUINT32(IMFTopology *iface, REFGUID key, UINT32 *value)
322 struct topology *topology = impl_from_IMFTopology(iface);
324 TRACE("%p, %s, %p.\n", iface, debugstr_guid(key), value);
326 return IMFAttributes_GetUINT32(topology->attributes, key, value);
329 static HRESULT WINAPI topology_GetUINT64(IMFTopology *iface, REFGUID key, UINT64 *value)
331 struct topology *topology = impl_from_IMFTopology(iface);
333 TRACE("%p, %s, %p.\n", iface, debugstr_guid(key), value);
335 return IMFAttributes_GetUINT64(topology->attributes, key, value);
338 static HRESULT WINAPI topology_GetDouble(IMFTopology *iface, REFGUID key, double *value)
340 struct topology *topology = impl_from_IMFTopology(iface);
342 TRACE("%p, %s, %p.\n", iface, debugstr_guid(key), value);
344 return IMFAttributes_GetDouble(topology->attributes, key, value);
347 static HRESULT WINAPI topology_GetGUID(IMFTopology *iface, REFGUID key, GUID *value)
349 struct topology *topology = impl_from_IMFTopology(iface);
351 TRACE("%p, %s, %p.\n", iface, debugstr_guid(key), value);
353 return IMFAttributes_GetGUID(topology->attributes, key, value);
356 static HRESULT WINAPI topology_GetStringLength(IMFTopology *iface, REFGUID key, UINT32 *length)
358 struct topology *topology = impl_from_IMFTopology(iface);
360 TRACE("%p, %s, %p.\n", iface, debugstr_guid(key), length);
362 return IMFAttributes_GetStringLength(topology->attributes, key, length);
365 static HRESULT WINAPI topology_GetString(IMFTopology *iface, REFGUID key, WCHAR *value,
366 UINT32 size, UINT32 *length)
368 struct topology *topology = impl_from_IMFTopology(iface);
370 TRACE("%p, %s, %p, %d, %p.\n", iface, debugstr_guid(key), value, size, length);
372 return IMFAttributes_GetString(topology->attributes, key, value, size, length);
375 static HRESULT WINAPI topology_GetAllocatedString(IMFTopology *iface, REFGUID key,
376 WCHAR **value, UINT32 *length)
378 struct topology *topology = impl_from_IMFTopology(iface);
380 TRACE("%p, %s, %p, %p.\n", iface, debugstr_guid(key), value, length);
382 return IMFAttributes_GetAllocatedString(topology->attributes, key, value, length);
385 static HRESULT WINAPI topology_GetBlobSize(IMFTopology *iface, REFGUID key, UINT32 *size)
387 struct topology *topology = impl_from_IMFTopology(iface);
389 TRACE("%p, %s, %p.\n", iface, debugstr_guid(key), size);
391 return IMFAttributes_GetBlobSize(topology->attributes, key, size);
394 static HRESULT WINAPI topology_GetBlob(IMFTopology *iface, REFGUID key, UINT8 *buf,
395 UINT32 bufsize, UINT32 *blobsize)
397 struct topology *topology = impl_from_IMFTopology(iface);
399 TRACE("%p, %s, %p, %d, %p.\n", iface, debugstr_guid(key), buf, bufsize, blobsize);
401 return IMFAttributes_GetBlob(topology->attributes, key, buf, bufsize, blobsize);
404 static HRESULT WINAPI topology_GetAllocatedBlob(IMFTopology *iface, REFGUID key, UINT8 **buf, UINT32 *size)
406 struct topology *topology = impl_from_IMFTopology(iface);
408 TRACE("%p, %s, %p, %p.\n", iface, debugstr_guid(key), buf, size);
410 return IMFAttributes_GetAllocatedBlob(topology->attributes, key, buf, size);
413 static HRESULT WINAPI topology_GetUnknown(IMFTopology *iface, REFGUID key, REFIID riid, void **ppv)
415 struct topology *topology = impl_from_IMFTopology(iface);
417 TRACE("%p, %s, %s, %p.\n", iface, debugstr_guid(key), debugstr_guid(riid), ppv);
419 return IMFAttributes_GetUnknown(topology->attributes, key, riid, ppv);
422 static HRESULT WINAPI topology_SetItem(IMFTopology *iface, REFGUID key, REFPROPVARIANT value)
424 struct topology *topology = impl_from_IMFTopology(iface);
426 TRACE("%p, %s, %p.\n", iface, debugstr_guid(key), value);
428 return IMFAttributes_SetItem(topology->attributes, key, value);
431 static HRESULT WINAPI topology_DeleteItem(IMFTopology *iface, REFGUID key)
433 struct topology *topology = impl_from_IMFTopology(iface);
435 TRACE("%p, %s.\n", topology, debugstr_guid(key));
437 return IMFAttributes_DeleteItem(topology->attributes, key);
440 static HRESULT WINAPI topology_DeleteAllItems(IMFTopology *iface)
442 struct topology *topology = impl_from_IMFTopology(iface);
444 TRACE("%p.\n", iface);
446 return IMFAttributes_DeleteAllItems(topology->attributes);
449 static HRESULT WINAPI topology_SetUINT32(IMFTopology *iface, REFGUID key, UINT32 value)
451 struct topology *topology = impl_from_IMFTopology(iface);
453 TRACE("%p, %s, %d.\n", iface, debugstr_guid(key), value);
455 return IMFAttributes_SetUINT32(topology->attributes, key, value);
458 static HRESULT WINAPI topology_SetUINT64(IMFTopology *iface, REFGUID key, UINT64 value)
460 struct topology *topology = impl_from_IMFTopology(iface);
462 TRACE("%p, %s, %s.\n", iface, debugstr_guid(key), wine_dbgstr_longlong(value));
464 return IMFAttributes_SetUINT64(topology->attributes, key, value);
467 static HRESULT WINAPI topology_SetDouble(IMFTopology *iface, REFGUID key, double value)
469 struct topology *topology = impl_from_IMFTopology(iface);
471 TRACE("%p, %s, %f.\n", iface, debugstr_guid(key), value);
473 return IMFAttributes_SetDouble(topology->attributes, key, value);
476 static HRESULT WINAPI topology_SetGUID(IMFTopology *iface, REFGUID key, REFGUID value)
478 struct topology *topology = impl_from_IMFTopology(iface);
480 TRACE("%p, %s, %s.\n", iface, debugstr_guid(key), debugstr_guid(value));
482 return IMFAttributes_SetGUID(topology->attributes, key, value);
485 static HRESULT WINAPI topology_SetString(IMFTopology *iface, REFGUID key, const WCHAR *value)
487 struct topology *topology = impl_from_IMFTopology(iface);
489 TRACE("%p, %s, %s.\n", iface, debugstr_guid(key), debugstr_w(value));
491 return IMFAttributes_SetString(topology->attributes, key, value);
494 static HRESULT WINAPI topology_SetBlob(IMFTopology *iface, REFGUID key, const UINT8 *buf, UINT32 size)
496 struct topology *topology = impl_from_IMFTopology(iface);
498 TRACE("%p, %s, %p, %d.\n", iface, debugstr_guid(key), buf, size);
500 return IMFAttributes_SetBlob(topology->attributes, key, buf, size);
503 static HRESULT WINAPI topology_SetUnknown(IMFTopology *iface, REFGUID key, IUnknown *unknown)
505 struct topology *topology = impl_from_IMFTopology(iface);
507 TRACE("%p, %s, %p.\n", iface, debugstr_guid(key), unknown);
509 return IMFAttributes_SetUnknown(topology->attributes, key, unknown);
512 static HRESULT WINAPI topology_LockStore(IMFTopology *iface)
514 struct topology *topology = impl_from_IMFTopology(iface);
516 TRACE("%p.\n", iface);
518 return IMFAttributes_LockStore(topology->attributes);
521 static HRESULT WINAPI topology_UnlockStore(IMFTopology *iface)
523 struct topology *topology = impl_from_IMFTopology(iface);
525 TRACE("%p.\n", iface);
527 return IMFAttributes_UnlockStore(topology->attributes);
530 static HRESULT WINAPI topology_GetCount(IMFTopology *iface, UINT32 *count)
532 struct topology *topology = impl_from_IMFTopology(iface);
534 TRACE("%p, %p.\n", iface, count);
536 return IMFAttributes_GetCount(topology->attributes, count);
539 static HRESULT WINAPI topology_GetItemByIndex(IMFTopology *iface, UINT32 index, GUID *key, PROPVARIANT *value)
541 struct topology *topology = impl_from_IMFTopology(iface);
543 TRACE("%p, %u, %p, %p.\n", iface, index, key, value);
545 return IMFAttributes_GetItemByIndex(topology->attributes, index, key, value);
548 static HRESULT WINAPI topology_CopyAllItems(IMFTopology *iface, IMFAttributes *dest)
550 struct topology *topology = impl_from_IMFTopology(iface);
552 TRACE("%p, %p.\n", iface, dest);
554 return IMFAttributes_CopyAllItems(topology->attributes, dest);
557 static HRESULT WINAPI topology_GetTopologyID(IMFTopology *iface, TOPOID *id)
559 struct topology *topology = impl_from_IMFTopology(iface);
561 TRACE("%p, %p.\n", iface, id);
563 if (!id)
564 return E_POINTER;
566 *id = topology->id;
568 return S_OK;
571 static HRESULT topology_get_node_by_id(const struct topology *topology, TOPOID id, struct topology_node **node)
573 size_t i = 0;
575 for (i = 0; i < topology->nodes.count; ++i)
577 if (topology->nodes.nodes[i]->id == id)
579 *node = topology->nodes.nodes[i];
580 return S_OK;
584 return MF_E_NOT_FOUND;
587 static HRESULT topology_add_node(struct topology *topology, struct topology_node *node)
589 struct topology_node *match;
591 if (!node)
592 return E_POINTER;
594 if (SUCCEEDED(topology_get_node_by_id(topology, node->id, &match)))
595 return E_INVALIDARG;
597 if (!mf_array_reserve((void **)&topology->nodes.nodes, &topology->nodes.size, topology->nodes.count + 1,
598 sizeof(*topology->nodes.nodes)))
600 return E_OUTOFMEMORY;
603 topology->nodes.nodes[topology->nodes.count++] = node;
604 IMFTopologyNode_AddRef(&node->IMFTopologyNode_iface);
606 return S_OK;
609 static HRESULT WINAPI topology_AddNode(IMFTopology *iface, IMFTopologyNode *node_iface)
611 struct topology *topology = impl_from_IMFTopology(iface);
612 struct topology_node *node = unsafe_impl_from_IMFTopologyNode(node_iface);
614 TRACE("%p, %p.\n", iface, node_iface);
616 return topology_add_node(topology, node);
619 static HRESULT WINAPI topology_RemoveNode(IMFTopology *iface, IMFTopologyNode *node)
621 struct topology *topology = impl_from_IMFTopology(iface);
622 size_t i, count;
624 TRACE("%p, %p.\n", iface, node);
626 for (i = 0; i < topology->nodes.count; ++i)
628 if (&topology->nodes.nodes[i]->IMFTopologyNode_iface == node)
630 topology_node_disconnect(topology->nodes.nodes[i]);
631 IMFTopologyNode_Release(&topology->nodes.nodes[i]->IMFTopologyNode_iface);
632 count = topology->nodes.count - i - 1;
633 if (count)
635 memmove(&topology->nodes.nodes[i], &topology->nodes.nodes[i + 1],
636 count * sizeof(*topology->nodes.nodes));
638 topology->nodes.count--;
639 return S_OK;
643 return E_INVALIDARG;
646 static HRESULT WINAPI topology_GetNodeCount(IMFTopology *iface, WORD *count)
648 struct topology *topology = impl_from_IMFTopology(iface);
650 TRACE("%p, %p.\n", iface, count);
652 if (!count)
653 return E_POINTER;
655 *count = topology->nodes.count;
657 return S_OK;
660 static HRESULT WINAPI topology_GetNode(IMFTopology *iface, WORD index, IMFTopologyNode **node)
662 struct topology *topology = impl_from_IMFTopology(iface);
664 TRACE("%p, %u, %p.\n", iface, index, node);
666 if (!node)
667 return E_POINTER;
669 if (index >= topology->nodes.count)
670 return MF_E_INVALIDINDEX;
672 *node = &topology->nodes.nodes[index]->IMFTopologyNode_iface;
673 IMFTopologyNode_AddRef(*node);
675 return S_OK;
678 static HRESULT WINAPI topology_Clear(IMFTopology *iface)
680 struct topology *topology = impl_from_IMFTopology(iface);
682 TRACE("%p.\n", iface);
684 topology_clear(topology);
685 return S_OK;
688 static HRESULT WINAPI topology_CloneFrom(IMFTopology *iface, IMFTopology *src)
690 struct topology *topology = impl_from_IMFTopology(iface);
691 struct topology *src_topology = unsafe_impl_from_IMFTopology(src);
692 struct topology_node *node;
693 size_t i, j;
694 HRESULT hr;
696 TRACE("%p, %p.\n", iface, src);
698 topology_clear(topology);
700 /* Clone nodes. */
701 for (i = 0; i < src_topology->nodes.count; ++i)
703 if (FAILED(hr = create_topology_node(src_topology->nodes.nodes[i]->node_type, &node)))
705 WARN("Failed to create a node, hr %#x.\n", hr);
706 break;
709 if (SUCCEEDED(hr = IMFTopologyNode_CloneFrom(&node->IMFTopologyNode_iface,
710 &src_topology->nodes.nodes[i]->IMFTopologyNode_iface)))
712 topology_add_node(topology, node);
715 IMFTopologyNode_Release(&node->IMFTopologyNode_iface);
718 /* Clone connections. */
719 for (i = 0; i < src_topology->nodes.count; ++i)
721 const struct node_streams *outputs = &src_topology->nodes.nodes[i]->outputs;
723 for (j = 0; j < outputs->count; ++j)
725 DWORD input_index = outputs->streams[j].connection_stream;
726 TOPOID id = outputs->streams[j].connection->id;
728 /* Skip node lookup in destination topology, assuming same node order. */
729 if (SUCCEEDED(hr = topology_get_node_by_id(topology, id, &node)))
730 topology_node_connect_output(topology->nodes.nodes[i], j, node, input_index);
734 /* Copy attributes and id. */
735 hr = IMFTopology_CopyAllItems(src, (IMFAttributes *)&topology->IMFTopology_iface);
736 if (SUCCEEDED(hr))
737 topology->id = src_topology->id;
739 return S_OK;
742 static HRESULT WINAPI topology_GetNodeByID(IMFTopology *iface, TOPOID id, IMFTopologyNode **ret)
744 struct topology *topology = impl_from_IMFTopology(iface);
745 struct topology_node *node;
746 HRESULT hr;
748 TRACE("%p, %p.\n", iface, ret);
750 if (SUCCEEDED(hr = topology_get_node_by_id(topology, id, &node)))
752 *ret = &node->IMFTopologyNode_iface;
753 IMFTopologyNode_AddRef(*ret);
755 else
756 *ret = NULL;
758 return hr;
761 static HRESULT topology_get_node_collection(const struct topology *topology, MF_TOPOLOGY_TYPE node_type,
762 IMFCollection **collection)
764 HRESULT hr;
765 size_t i;
767 if (!collection)
768 return E_POINTER;
770 if (FAILED(hr = MFCreateCollection(collection)))
771 return hr;
773 for (i = 0; i < topology->nodes.count; ++i)
775 if (topology->nodes.nodes[i]->node_type == node_type)
777 if (FAILED(hr = IMFCollection_AddElement(*collection,
778 (IUnknown *)&topology->nodes.nodes[i]->IMFTopologyNode_iface)))
780 IMFCollection_Release(*collection);
781 *collection = NULL;
782 break;
787 return hr;
790 static HRESULT WINAPI topology_GetSourceNodeCollection(IMFTopology *iface, IMFCollection **collection)
792 struct topology *topology = impl_from_IMFTopology(iface);
794 TRACE("%p, %p.\n", iface, collection);
796 return topology_get_node_collection(topology, MF_TOPOLOGY_SOURCESTREAM_NODE, collection);
799 static HRESULT WINAPI topology_GetOutputNodeCollection(IMFTopology *iface, IMFCollection **collection)
801 struct topology *topology = impl_from_IMFTopology(iface);
803 TRACE("%p, %p.\n", iface, collection);
805 return topology_get_node_collection(topology, MF_TOPOLOGY_OUTPUT_NODE, collection);
808 static const IMFTopologyVtbl topologyvtbl =
810 topology_QueryInterface,
811 topology_AddRef,
812 topology_Release,
813 topology_GetItem,
814 topology_GetItemType,
815 topology_CompareItem,
816 topology_Compare,
817 topology_GetUINT32,
818 topology_GetUINT64,
819 topology_GetDouble,
820 topology_GetGUID,
821 topology_GetStringLength,
822 topology_GetString,
823 topology_GetAllocatedString,
824 topology_GetBlobSize,
825 topology_GetBlob,
826 topology_GetAllocatedBlob,
827 topology_GetUnknown,
828 topology_SetItem,
829 topology_DeleteItem,
830 topology_DeleteAllItems,
831 topology_SetUINT32,
832 topology_SetUINT64,
833 topology_SetDouble,
834 topology_SetGUID,
835 topology_SetString,
836 topology_SetBlob,
837 topology_SetUnknown,
838 topology_LockStore,
839 topology_UnlockStore,
840 topology_GetCount,
841 topology_GetItemByIndex,
842 topology_CopyAllItems,
843 topology_GetTopologyID,
844 topology_AddNode,
845 topology_RemoveNode,
846 topology_GetNodeCount,
847 topology_GetNode,
848 topology_Clear,
849 topology_CloneFrom,
850 topology_GetNodeByID,
851 topology_GetSourceNodeCollection,
852 topology_GetOutputNodeCollection,
855 static struct topology *unsafe_impl_from_IMFTopology(IMFTopology *iface)
857 if (!iface || iface->lpVtbl != &topologyvtbl)
858 return NULL;
859 return impl_from_IMFTopology(iface);
862 static TOPOID topology_generate_id(void)
864 TOPOID old;
868 old = next_topology_id;
870 while (InterlockedCompareExchange64((LONG64 *)&next_topology_id, old + 1, old) != old);
872 return next_topology_id;
875 /***********************************************************************
876 * MFCreateTopology (mf.@)
878 HRESULT WINAPI MFCreateTopology(IMFTopology **topology)
880 struct topology *object;
881 HRESULT hr;
883 TRACE("%p.\n", topology);
885 if (!topology)
886 return E_POINTER;
888 object = heap_alloc_zero(sizeof(*object));
889 if (!object)
890 return E_OUTOFMEMORY;
892 object->IMFTopology_iface.lpVtbl = &topologyvtbl;
893 object->refcount = 1;
895 hr = MFCreateAttributes(&object->attributes, 0);
896 if (FAILED(hr))
898 IMFTopology_Release(&object->IMFTopology_iface);
899 return hr;
902 object->id = topology_generate_id();
904 *topology = &object->IMFTopology_iface;
906 return S_OK;
909 static HRESULT WINAPI topology_node_QueryInterface(IMFTopologyNode *iface, REFIID riid, void **out)
911 struct topology_node *node = impl_from_IMFTopologyNode(iface);
913 TRACE("%p, %s, %p.\n", iface, debugstr_guid(riid), out);
915 if (IsEqualIID(riid, &IID_IMFTopologyNode) ||
916 IsEqualIID(riid, &IID_IMFAttributes) ||
917 IsEqualIID(riid, &IID_IUnknown))
919 *out = &node->IMFTopologyNode_iface;
920 IMFTopologyNode_AddRef(iface);
921 return S_OK;
924 WARN("Unsupported interface %s.\n", debugstr_guid(riid));
925 *out = NULL;
927 return E_NOINTERFACE;
930 static ULONG WINAPI topology_node_AddRef(IMFTopologyNode *iface)
932 struct topology_node *node = impl_from_IMFTopologyNode(iface);
933 ULONG refcount = InterlockedIncrement(&node->refcount);
935 TRACE("%p, refcount %u.\n", iface, refcount);
937 return refcount;
940 static ULONG WINAPI topology_node_Release(IMFTopologyNode *iface)
942 struct topology_node *node = impl_from_IMFTopologyNode(iface);
943 ULONG refcount = InterlockedDecrement(&node->refcount);
944 unsigned int i;
946 TRACE("%p, refcount %u.\n", iface, refcount);
948 if (!refcount)
950 if (node->object)
951 IUnknown_Release(node->object);
952 if (node->input_type)
953 IMFMediaType_Release(node->input_type);
954 for (i = 0; i < node->inputs.count; ++i)
956 if (node->inputs.streams[i].preferred_type)
957 IMFMediaType_Release(node->inputs.streams[i].preferred_type);
959 for (i = 0; i < node->outputs.count; ++i)
961 if (node->outputs.streams[i].preferred_type)
962 IMFMediaType_Release(node->outputs.streams[i].preferred_type);
964 heap_free(node->inputs.streams);
965 heap_free(node->outputs.streams);
966 IMFAttributes_Release(node->attributes);
967 DeleteCriticalSection(&node->cs);
968 heap_free(node);
971 return refcount;
974 static HRESULT WINAPI topology_node_GetItem(IMFTopologyNode *iface, REFGUID key, PROPVARIANT *value)
976 struct topology_node *node = impl_from_IMFTopologyNode(iface);
978 TRACE("%p, %s, %p.\n", iface, debugstr_guid(key), value);
980 return IMFAttributes_GetItem(node->attributes, key, value);
983 static HRESULT WINAPI topology_node_GetItemType(IMFTopologyNode *iface, REFGUID key, MF_ATTRIBUTE_TYPE *type)
985 struct topology_node *node = impl_from_IMFTopologyNode(iface);
987 TRACE("%p, %s, %p.\n", iface, debugstr_guid(key), type);
989 return IMFAttributes_GetItemType(node->attributes, key, type);
992 static HRESULT WINAPI topology_node_CompareItem(IMFTopologyNode *iface, REFGUID key, REFPROPVARIANT value, BOOL *result)
994 struct topology_node *node = impl_from_IMFTopologyNode(iface);
996 TRACE("%p, %s, %p, %p.\n", iface, debugstr_guid(key), value, result);
998 return IMFAttributes_CompareItem(node->attributes, key, value, result);
1001 static HRESULT WINAPI topology_node_Compare(IMFTopologyNode *iface, IMFAttributes *theirs,
1002 MF_ATTRIBUTES_MATCH_TYPE type, BOOL *result)
1004 struct topology_node *node = impl_from_IMFTopologyNode(iface);
1006 TRACE("%p, %p, %d, %p.\n", iface, theirs, type, result);
1008 return IMFAttributes_Compare(node->attributes, theirs, type, result);
1011 static HRESULT WINAPI topology_node_GetUINT32(IMFTopologyNode *iface, REFGUID key, UINT32 *value)
1013 struct topology_node *node = impl_from_IMFTopologyNode(iface);
1015 TRACE("%p, %s, %p.\n", iface, debugstr_guid(key), value);
1017 return IMFAttributes_GetUINT32(node->attributes, key, value);
1020 static HRESULT WINAPI topology_node_GetUINT64(IMFTopologyNode *iface, REFGUID key, UINT64 *value)
1022 struct topology_node *node = impl_from_IMFTopologyNode(iface);
1024 TRACE("%p, %s, %p.\n", iface, debugstr_guid(key), value);
1026 return IMFAttributes_GetUINT64(node->attributes, key, value);
1029 static HRESULT WINAPI topology_node_GetDouble(IMFTopologyNode *iface, REFGUID key, double *value)
1031 struct topology_node *node = impl_from_IMFTopologyNode(iface);
1033 TRACE("%p, %s, %p.\n", iface, debugstr_guid(key), value);
1035 return IMFAttributes_GetDouble(node->attributes, key, value);
1038 static HRESULT WINAPI topology_node_GetGUID(IMFTopologyNode *iface, REFGUID key, GUID *value)
1040 struct topology_node *node = impl_from_IMFTopologyNode(iface);
1042 TRACE("%p, %s, %p.\n", iface, debugstr_guid(key), value);
1044 return IMFAttributes_GetGUID(node->attributes, key, value);
1047 static HRESULT WINAPI topology_node_GetStringLength(IMFTopologyNode *iface, REFGUID key, UINT32 *length)
1049 struct topology_node *node = impl_from_IMFTopologyNode(iface);
1051 TRACE("%p, %s, %p.\n", iface, debugstr_guid(key), length);
1053 return IMFAttributes_GetStringLength(node->attributes, key, length);
1056 static HRESULT WINAPI topology_node_GetString(IMFTopologyNode *iface, REFGUID key, WCHAR *value,
1057 UINT32 size, UINT32 *length)
1059 struct topology_node *node = impl_from_IMFTopologyNode(iface);
1061 TRACE("%p, %s, %p, %d, %p.\n", iface, debugstr_guid(key), value, size, length);
1063 return IMFAttributes_GetString(node->attributes, key, value, size, length);
1066 static HRESULT WINAPI topology_node_GetAllocatedString(IMFTopologyNode *iface, REFGUID key,
1067 WCHAR **value, UINT32 *length)
1069 struct topology_node *node = impl_from_IMFTopologyNode(iface);
1071 TRACE("%p, %s, %p, %p.\n", iface, debugstr_guid(key), value, length);
1073 return IMFAttributes_GetAllocatedString(node->attributes, key, value, length);
1076 static HRESULT WINAPI topology_node_GetBlobSize(IMFTopologyNode *iface, REFGUID key, UINT32 *size)
1078 struct topology_node *node = impl_from_IMFTopologyNode(iface);
1080 TRACE("%p, %s, %p.\n", iface, debugstr_guid(key), size);
1082 return IMFAttributes_GetBlobSize(node->attributes, key, size);
1085 static HRESULT WINAPI topology_node_GetBlob(IMFTopologyNode *iface, REFGUID key, UINT8 *buf,
1086 UINT32 bufsize, UINT32 *blobsize)
1088 struct topology_node *node = impl_from_IMFTopologyNode(iface);
1090 TRACE("%p, %s, %p, %d, %p.\n", iface, debugstr_guid(key), buf, bufsize, blobsize);
1092 return IMFAttributes_GetBlob(node->attributes, key, buf, bufsize, blobsize);
1095 static HRESULT WINAPI topology_node_GetAllocatedBlob(IMFTopologyNode *iface, REFGUID key, UINT8 **buf, UINT32 *size)
1097 struct topology_node *node = impl_from_IMFTopologyNode(iface);
1099 TRACE("%p, %s, %p, %p.\n", iface, debugstr_guid(key), buf, size);
1101 return IMFAttributes_GetAllocatedBlob(node->attributes, key, buf, size);
1104 static HRESULT WINAPI topology_node_GetUnknown(IMFTopologyNode *iface, REFGUID key, REFIID riid, void **ppv)
1106 struct topology_node *node = impl_from_IMFTopologyNode(iface);
1108 TRACE("%p, %s, %s, %p.\n", iface, debugstr_guid(key), debugstr_guid(riid), ppv);
1110 return IMFAttributes_GetUnknown(node->attributes, key, riid, ppv);
1113 static HRESULT WINAPI topology_node_SetItem(IMFTopologyNode *iface, REFGUID key, REFPROPVARIANT value)
1115 struct topology_node *node = impl_from_IMFTopologyNode(iface);
1117 TRACE("%p, %s, %p.\n", iface, debugstr_guid(key), value);
1119 return IMFAttributes_SetItem(node->attributes, key, value);
1122 static HRESULT WINAPI topology_node_DeleteItem(IMFTopologyNode *iface, REFGUID key)
1124 struct topology_node *node = impl_from_IMFTopologyNode(iface);
1126 TRACE("%p, %s.\n", iface, debugstr_guid(key));
1128 return IMFAttributes_DeleteItem(node->attributes, key);
1131 static HRESULT WINAPI topology_node_DeleteAllItems(IMFTopologyNode *iface)
1133 struct topology_node *node = impl_from_IMFTopologyNode(iface);
1135 TRACE("%p.\n", iface);
1137 return IMFAttributes_DeleteAllItems(node->attributes);
1140 static HRESULT WINAPI topology_node_SetUINT32(IMFTopologyNode *iface, REFGUID key, UINT32 value)
1142 struct topology_node *node = impl_from_IMFTopologyNode(iface);
1144 TRACE("%p, %s, %d.\n", iface, debugstr_guid(key), value);
1146 return IMFAttributes_SetUINT32(node->attributes, key, value);
1149 static HRESULT WINAPI topology_node_SetUINT64(IMFTopologyNode *iface, REFGUID key, UINT64 value)
1151 struct topology_node *node = impl_from_IMFTopologyNode(iface);
1153 TRACE("%p, %s, %s.\n", iface, debugstr_guid(key), wine_dbgstr_longlong(value));
1155 return IMFAttributes_SetUINT64(node->attributes, key, value);
1158 static HRESULT WINAPI topology_node_SetDouble(IMFTopologyNode *iface, REFGUID key, double value)
1160 struct topology_node *node = impl_from_IMFTopologyNode(iface);
1162 TRACE("%p, %s, %f.\n", iface, debugstr_guid(key), value);
1164 return IMFAttributes_SetDouble(node->attributes, key, value);
1167 static HRESULT WINAPI topology_node_SetGUID(IMFTopologyNode *iface, REFGUID key, REFGUID value)
1169 struct topology_node *node = impl_from_IMFTopologyNode(iface);
1171 TRACE("%p, %s, %s.\n", iface, debugstr_guid(key), debugstr_guid(value));
1173 return IMFAttributes_SetGUID(node->attributes, key, value);
1176 static HRESULT WINAPI topology_node_SetString(IMFTopologyNode *iface, REFGUID key, const WCHAR *value)
1178 struct topology_node *node = impl_from_IMFTopologyNode(iface);
1180 TRACE("%p, %s, %s.\n", iface, debugstr_guid(key), debugstr_w(value));
1182 return IMFAttributes_SetString(node->attributes, key, value);
1185 static HRESULT WINAPI topology_node_SetBlob(IMFTopologyNode *iface, REFGUID key, const UINT8 *buf, UINT32 size)
1187 struct topology_node *node = impl_from_IMFTopologyNode(iface);
1189 TRACE("%p, %s, %p, %d.\n", iface, debugstr_guid(key), buf, size);
1191 return IMFAttributes_SetBlob(node->attributes, key, buf, size);
1194 static HRESULT WINAPI topology_node_SetUnknown(IMFTopologyNode *iface, REFGUID key, IUnknown *unknown)
1196 struct topology_node *node = impl_from_IMFTopologyNode(iface);
1198 TRACE("%p, %s, %p.\n", iface, debugstr_guid(key), unknown);
1200 return IMFAttributes_SetUnknown(node->attributes, key, unknown);
1203 static HRESULT WINAPI topology_node_LockStore(IMFTopologyNode *iface)
1205 struct topology_node *node = impl_from_IMFTopologyNode(iface);
1207 TRACE("%p.\n", iface);
1209 return IMFAttributes_LockStore(node->attributes);
1212 static HRESULT WINAPI topology_node_UnlockStore(IMFTopologyNode *iface)
1214 struct topology_node *node = impl_from_IMFTopologyNode(iface);
1216 TRACE("%p.\n", iface);
1218 return IMFAttributes_UnlockStore(node->attributes);
1221 static HRESULT WINAPI topology_node_GetCount(IMFTopologyNode *iface, UINT32 *count)
1223 struct topology_node *node = impl_from_IMFTopologyNode(iface);
1225 TRACE("%p, %p.\n", iface, count);
1227 return IMFAttributes_GetCount(node->attributes, count);
1230 static HRESULT WINAPI topology_node_GetItemByIndex(IMFTopologyNode *iface, UINT32 index, GUID *key, PROPVARIANT *value)
1232 struct topology_node *node = impl_from_IMFTopologyNode(iface);
1234 TRACE("%p, %u, %p, %p.\n", iface, index, key, value);
1236 return IMFAttributes_GetItemByIndex(node->attributes, index, key, value);
1239 static HRESULT WINAPI topology_node_CopyAllItems(IMFTopologyNode *iface, IMFAttributes *dest)
1241 struct topology_node *node = impl_from_IMFTopologyNode(iface);
1243 TRACE("%p, %p.\n", iface, dest);
1245 return IMFAttributes_CopyAllItems(node->attributes, dest);
1248 static HRESULT topology_node_set_object(struct topology_node *node, IUnknown *object)
1250 static const GUID *iids[3] = { &IID_IPersist, &IID_IPersistStorage, &IID_IPersistPropertyBag };
1251 IPersist *persist = NULL;
1252 BOOL has_object_id;
1253 GUID object_id;
1254 unsigned int i;
1255 HRESULT hr;
1257 has_object_id = IMFAttributes_GetGUID(node->attributes, &MF_TOPONODE_TRANSFORM_OBJECTID, &object_id) == S_OK;
1259 if (object && !has_object_id)
1261 for (i = 0; i < ARRAY_SIZE(iids); ++i)
1263 persist = NULL;
1264 if (SUCCEEDED(hr = IUnknown_QueryInterface(object, iids[i], (void **)&persist)))
1265 break;
1268 if (persist)
1270 if (FAILED(hr = IPersist_GetClassID(persist, &object_id)))
1272 IPersist_Release(persist);
1273 persist = NULL;
1278 EnterCriticalSection(&node->cs);
1280 if (node->object)
1281 IUnknown_Release(node->object);
1282 node->object = object;
1283 if (node->object)
1284 IUnknown_AddRef(node->object);
1286 if (persist)
1287 IMFAttributes_SetGUID(node->attributes, &MF_TOPONODE_TRANSFORM_OBJECTID, &object_id);
1289 LeaveCriticalSection(&node->cs);
1291 if (persist)
1292 IPersist_Release(persist);
1294 return S_OK;
1297 static HRESULT WINAPI topology_node_SetObject(IMFTopologyNode *iface, IUnknown *object)
1299 struct topology_node *node = impl_from_IMFTopologyNode(iface);
1301 TRACE("%p, %p.\n", iface, object);
1303 return topology_node_set_object(node, object);
1306 static HRESULT WINAPI topology_node_GetObject(IMFTopologyNode *iface, IUnknown **object)
1308 struct topology_node *node = impl_from_IMFTopologyNode(iface);
1310 TRACE("%p, %p.\n", iface, object);
1312 if (!object)
1313 return E_POINTER;
1315 EnterCriticalSection(&node->cs);
1317 *object = node->object;
1318 if (*object)
1319 IUnknown_AddRef(*object);
1321 LeaveCriticalSection(&node->cs);
1323 return *object ? S_OK : E_FAIL;
1326 static HRESULT WINAPI topology_node_GetNodeType(IMFTopologyNode *iface, MF_TOPOLOGY_TYPE *node_type)
1328 struct topology_node *node = impl_from_IMFTopologyNode(iface);
1330 TRACE("%p, %p.\n", iface, node_type);
1332 *node_type = node->node_type;
1334 return S_OK;
1337 static HRESULT WINAPI topology_node_GetTopoNodeID(IMFTopologyNode *iface, TOPOID *id)
1339 struct topology_node *node = impl_from_IMFTopologyNode(iface);
1341 TRACE("%p, %p.\n", iface, id);
1343 *id = node->id;
1345 return S_OK;
1348 static HRESULT WINAPI topology_node_SetTopoNodeID(IMFTopologyNode *iface, TOPOID id)
1350 struct topology_node *node = impl_from_IMFTopologyNode(iface);
1352 TRACE("%p, %s.\n", iface, wine_dbgstr_longlong(id));
1354 node->id = id;
1356 return S_OK;
1359 static HRESULT WINAPI topology_node_GetInputCount(IMFTopologyNode *iface, DWORD *count)
1361 struct topology_node *node = impl_from_IMFTopologyNode(iface);
1363 TRACE("%p, %p.\n", iface, count);
1365 *count = node->inputs.count;
1367 return S_OK;
1370 static HRESULT WINAPI topology_node_GetOutputCount(IMFTopologyNode *iface, DWORD *count)
1372 struct topology_node *node = impl_from_IMFTopologyNode(iface);
1374 TRACE("%p, %p.\n", iface, count);
1376 *count = node->outputs.count;
1378 return S_OK;
1381 static void topology_node_set_stream_type(struct node_stream *stream, IMFMediaType *mediatype)
1383 if (stream->preferred_type)
1384 IMFMediaType_Release(stream->preferred_type);
1385 stream->preferred_type = mediatype;
1386 if (stream->preferred_type)
1387 IMFMediaType_AddRef(stream->preferred_type);
1390 static HRESULT topology_node_connect_output(struct topology_node *node, DWORD output_index,
1391 struct topology_node *connection, DWORD input_index)
1393 struct node_stream *stream;
1394 HRESULT hr;
1396 if (node->node_type == MF_TOPOLOGY_OUTPUT_NODE || connection->node_type == MF_TOPOLOGY_SOURCESTREAM_NODE)
1397 return E_FAIL;
1399 EnterCriticalSection(&node->cs);
1400 EnterCriticalSection(&connection->cs);
1402 topology_node_disconnect_output(node, output_index);
1403 if (input_index < connection->inputs.count)
1405 stream = &connection->inputs.streams[input_index];
1406 if (stream->connection)
1407 topology_node_disconnect_output(stream->connection, stream->connection_stream);
1410 hr = topology_node_reserve_streams(&node->outputs, output_index);
1411 if (SUCCEEDED(hr))
1413 size_t old_count = connection->inputs.count;
1414 hr = topology_node_reserve_streams(&connection->inputs, input_index);
1415 if (SUCCEEDED(hr) && !old_count && connection->input_type)
1417 topology_node_set_stream_type(connection->inputs.streams, connection->input_type);
1418 IMFMediaType_Release(connection->input_type);
1419 connection->input_type = NULL;
1423 if (SUCCEEDED(hr))
1425 node->outputs.streams[output_index].connection = connection;
1426 IMFTopologyNode_AddRef(&node->outputs.streams[output_index].connection->IMFTopologyNode_iface);
1427 node->outputs.streams[output_index].connection_stream = input_index;
1428 connection->inputs.streams[input_index].connection = node;
1429 IMFTopologyNode_AddRef(&connection->inputs.streams[input_index].connection->IMFTopologyNode_iface);
1430 connection->inputs.streams[input_index].connection_stream = output_index;
1433 LeaveCriticalSection(&connection->cs);
1434 LeaveCriticalSection(&node->cs);
1436 return hr;
1439 static HRESULT WINAPI topology_node_ConnectOutput(IMFTopologyNode *iface, DWORD output_index,
1440 IMFTopologyNode *peer, DWORD input_index)
1442 struct topology_node *node = impl_from_IMFTopologyNode(iface);
1443 struct topology_node *connection = unsafe_impl_from_IMFTopologyNode(peer);
1445 TRACE("%p, %u, %p, %u.\n", iface, output_index, peer, input_index);
1447 if (!connection)
1449 WARN("External node implementations are not supported.\n");
1450 return E_UNEXPECTED;
1453 return topology_node_connect_output(node, output_index, connection, input_index);
1456 static HRESULT WINAPI topology_node_DisconnectOutput(IMFTopologyNode *iface, DWORD output_index)
1458 struct topology_node *node = impl_from_IMFTopologyNode(iface);
1460 TRACE("%p, %u.\n", iface, output_index);
1462 return topology_node_disconnect_output(node, output_index);
1465 static HRESULT WINAPI topology_node_GetInput(IMFTopologyNode *iface, DWORD input_index, IMFTopologyNode **ret,
1466 DWORD *output_index)
1468 struct topology_node *node = impl_from_IMFTopologyNode(iface);
1469 HRESULT hr = S_OK;
1471 TRACE("%p, %u, %p, %p.\n", iface, input_index, ret, output_index);
1473 EnterCriticalSection(&node->cs);
1475 if (input_index < node->inputs.count)
1477 const struct node_stream *stream = &node->inputs.streams[input_index];
1479 if (stream->connection)
1481 *ret = &stream->connection->IMFTopologyNode_iface;
1482 IMFTopologyNode_AddRef(*ret);
1483 *output_index = stream->connection_stream;
1485 else
1486 hr = MF_E_NOT_FOUND;
1488 else
1489 hr = E_INVALIDARG;
1491 LeaveCriticalSection(&node->cs);
1493 return hr;
1496 static HRESULT WINAPI topology_node_GetOutput(IMFTopologyNode *iface, DWORD output_index, IMFTopologyNode **ret,
1497 DWORD *input_index)
1499 struct topology_node *node = impl_from_IMFTopologyNode(iface);
1500 HRESULT hr = S_OK;
1502 TRACE("%p, %u, %p, %p.\n", iface, output_index, ret, input_index);
1504 EnterCriticalSection(&node->cs);
1506 if (output_index < node->outputs.count)
1508 const struct node_stream *stream = &node->outputs.streams[output_index];
1510 if (stream->connection)
1512 *ret = &stream->connection->IMFTopologyNode_iface;
1513 IMFTopologyNode_AddRef(*ret);
1514 *input_index = stream->connection_stream;
1516 else
1517 hr = MF_E_NOT_FOUND;
1519 else
1520 hr = E_INVALIDARG;
1522 LeaveCriticalSection(&node->cs);
1524 return hr;
1527 static HRESULT WINAPI topology_node_SetOutputPrefType(IMFTopologyNode *iface, DWORD index, IMFMediaType *mediatype)
1529 struct topology_node *node = impl_from_IMFTopologyNode(iface);
1530 HRESULT hr = S_OK;
1532 TRACE("%p, %u, %p.\n", iface, index, mediatype);
1534 EnterCriticalSection(&node->cs);
1536 if (node->node_type != MF_TOPOLOGY_OUTPUT_NODE)
1538 if (SUCCEEDED(hr = topology_node_reserve_streams(&node->outputs, index)))
1539 topology_node_set_stream_type(&node->outputs.streams[index], mediatype);
1541 else
1542 hr = E_NOTIMPL;
1544 LeaveCriticalSection(&node->cs);
1546 return hr;
1549 static HRESULT topology_node_get_pref_type(struct node_streams *streams, unsigned int index, IMFMediaType **mediatype)
1551 *mediatype = streams->streams[index].preferred_type;
1552 if (*mediatype)
1554 IMFMediaType_AddRef(*mediatype);
1555 return S_OK;
1558 return E_FAIL;
1561 static HRESULT WINAPI topology_node_GetOutputPrefType(IMFTopologyNode *iface, DWORD index, IMFMediaType **mediatype)
1563 struct topology_node *node = impl_from_IMFTopologyNode(iface);
1564 HRESULT hr = S_OK;
1566 TRACE("%p, %u, %p.\n", iface, index, mediatype);
1568 EnterCriticalSection(&node->cs);
1570 if (index < node->outputs.count)
1571 hr = topology_node_get_pref_type(&node->outputs, index, mediatype);
1572 else
1573 hr = E_INVALIDARG;
1575 LeaveCriticalSection(&node->cs);
1577 return hr;
1580 static HRESULT WINAPI topology_node_SetInputPrefType(IMFTopologyNode *iface, DWORD index, IMFMediaType *mediatype)
1582 struct topology_node *node = impl_from_IMFTopologyNode(iface);
1583 HRESULT hr = S_OK;
1585 TRACE("%p, %u, %p.\n", iface, index, mediatype);
1587 EnterCriticalSection(&node->cs);
1589 switch (node->node_type)
1591 case MF_TOPOLOGY_TEE_NODE:
1592 if (index)
1594 hr = MF_E_INVALIDTYPE;
1595 break;
1597 if (node->inputs.count)
1598 topology_node_set_stream_type(&node->inputs.streams[index], mediatype);
1599 else
1601 if (node->input_type)
1602 IMFMediaType_Release(node->input_type);
1603 node->input_type = mediatype;
1604 if (node->input_type)
1605 IMFMediaType_AddRef(node->input_type);
1607 break;
1608 case MF_TOPOLOGY_SOURCESTREAM_NODE:
1609 hr = E_NOTIMPL;
1610 break;
1611 default:
1612 if (SUCCEEDED(hr = topology_node_reserve_streams(&node->inputs, index)))
1613 topology_node_set_stream_type(&node->inputs.streams[index], mediatype);
1616 LeaveCriticalSection(&node->cs);
1618 return hr;
1621 static HRESULT WINAPI topology_node_GetInputPrefType(IMFTopologyNode *iface, DWORD index, IMFMediaType **mediatype)
1623 struct topology_node *node = impl_from_IMFTopologyNode(iface);
1624 HRESULT hr = S_OK;
1626 TRACE("%p, %u, %p.\n", iface, index, mediatype);
1628 EnterCriticalSection(&node->cs);
1630 if (index < node->inputs.count)
1632 hr = topology_node_get_pref_type(&node->inputs, index, mediatype);
1634 else if (node->node_type == MF_TOPOLOGY_TEE_NODE && node->input_type)
1636 *mediatype = node->input_type;
1637 IMFMediaType_AddRef(*mediatype);
1639 else
1640 hr = E_INVALIDARG;
1642 LeaveCriticalSection(&node->cs);
1644 return hr;
1647 static HRESULT WINAPI topology_node_CloneFrom(IMFTopologyNode *iface, IMFTopologyNode *src_node)
1649 struct topology_node *node = impl_from_IMFTopologyNode(iface);
1650 MF_TOPOLOGY_TYPE node_type;
1651 IMFMediaType *mediatype;
1652 IUnknown *object;
1653 DWORD count, i;
1654 TOPOID topoid;
1655 HRESULT hr;
1657 TRACE("%p, %p.\n", iface, src_node);
1659 if (FAILED(hr = IMFTopologyNode_GetNodeType(src_node, &node_type)))
1660 return hr;
1662 if (node->node_type != node_type)
1663 return MF_E_INVALIDREQUEST;
1665 if (FAILED(hr = IMFTopologyNode_GetTopoNodeID(src_node, &topoid)))
1666 return hr;
1668 object = NULL;
1669 IMFTopologyNode_GetObject(src_node, &object);
1671 EnterCriticalSection(&node->cs);
1673 hr = IMFTopologyNode_CopyAllItems(src_node, node->attributes);
1675 if (SUCCEEDED(hr))
1676 hr = topology_node_set_object(node, object);
1678 if (SUCCEEDED(hr))
1679 node->id = topoid;
1681 if (SUCCEEDED(IMFTopologyNode_GetInputCount(src_node, &count)))
1683 for (i = 0; i < count; ++i)
1685 if (SUCCEEDED(IMFTopologyNode_GetInputPrefType(src_node, i, &mediatype)))
1687 IMFTopologyNode_SetInputPrefType(iface, i, mediatype);
1688 IMFMediaType_Release(mediatype);
1693 if (SUCCEEDED(IMFTopologyNode_GetOutputCount(src_node, &count)))
1695 for (i = 0; i < count; ++i)
1697 if (SUCCEEDED(IMFTopologyNode_GetOutputPrefType(src_node, i, &mediatype)))
1699 IMFTopologyNode_SetOutputPrefType(iface, i, mediatype);
1700 IMFMediaType_Release(mediatype);
1705 LeaveCriticalSection(&node->cs);
1707 if (object)
1708 IUnknown_Release(object);
1710 return hr;
1713 static const IMFTopologyNodeVtbl topologynodevtbl =
1715 topology_node_QueryInterface,
1716 topology_node_AddRef,
1717 topology_node_Release,
1718 topology_node_GetItem,
1719 topology_node_GetItemType,
1720 topology_node_CompareItem,
1721 topology_node_Compare,
1722 topology_node_GetUINT32,
1723 topology_node_GetUINT64,
1724 topology_node_GetDouble,
1725 topology_node_GetGUID,
1726 topology_node_GetStringLength,
1727 topology_node_GetString,
1728 topology_node_GetAllocatedString,
1729 topology_node_GetBlobSize,
1730 topology_node_GetBlob,
1731 topology_node_GetAllocatedBlob,
1732 topology_node_GetUnknown,
1733 topology_node_SetItem,
1734 topology_node_DeleteItem,
1735 topology_node_DeleteAllItems,
1736 topology_node_SetUINT32,
1737 topology_node_SetUINT64,
1738 topology_node_SetDouble,
1739 topology_node_SetGUID,
1740 topology_node_SetString,
1741 topology_node_SetBlob,
1742 topology_node_SetUnknown,
1743 topology_node_LockStore,
1744 topology_node_UnlockStore,
1745 topology_node_GetCount,
1746 topology_node_GetItemByIndex,
1747 topology_node_CopyAllItems,
1748 topology_node_SetObject,
1749 topology_node_GetObject,
1750 topology_node_GetNodeType,
1751 topology_node_GetTopoNodeID,
1752 topology_node_SetTopoNodeID,
1753 topology_node_GetInputCount,
1754 topology_node_GetOutputCount,
1755 topology_node_ConnectOutput,
1756 topology_node_DisconnectOutput,
1757 topology_node_GetInput,
1758 topology_node_GetOutput,
1759 topology_node_SetOutputPrefType,
1760 topology_node_GetOutputPrefType,
1761 topology_node_SetInputPrefType,
1762 topology_node_GetInputPrefType,
1763 topology_node_CloneFrom,
1766 static HRESULT create_topology_node(MF_TOPOLOGY_TYPE node_type, struct topology_node **node)
1768 HRESULT hr;
1770 *node = heap_alloc_zero(sizeof(**node));
1771 if (!*node)
1772 return E_OUTOFMEMORY;
1774 (*node)->IMFTopologyNode_iface.lpVtbl = &topologynodevtbl;
1775 (*node)->refcount = 1;
1776 (*node)->node_type = node_type;
1777 hr = MFCreateAttributes(&(*node)->attributes, 0);
1778 if (FAILED(hr))
1780 heap_free(*node);
1781 return hr;
1783 (*node)->id = ((TOPOID)GetCurrentProcessId() << 32) | InterlockedIncrement(&next_node_id);
1784 InitializeCriticalSection(&(*node)->cs);
1786 return S_OK;
1789 /***********************************************************************
1790 * MFCreateTopologyNode (mf.@)
1792 HRESULT WINAPI MFCreateTopologyNode(MF_TOPOLOGY_TYPE node_type, IMFTopologyNode **node)
1794 struct topology_node *object;
1795 HRESULT hr;
1797 TRACE("%d, %p.\n", node_type, node);
1799 if (!node)
1800 return E_POINTER;
1802 hr = create_topology_node(node_type, &object);
1803 if (SUCCEEDED(hr))
1804 *node = &object->IMFTopologyNode_iface;
1806 return hr;
1809 /***********************************************************************
1810 * MFGetTopoNodeCurrentType (mf.@)
1812 HRESULT WINAPI MFGetTopoNodeCurrentType(IMFTopologyNode *node, DWORD stream, BOOL output, IMFMediaType **type)
1814 IMFMediaTypeHandler *type_handler;
1815 MF_TOPOLOGY_TYPE node_type;
1816 IMFStreamSink *stream_sink;
1817 IMFStreamDescriptor *sd;
1818 IMFTransform *transform;
1819 UINT32 primary_output;
1820 IUnknown *object;
1821 HRESULT hr;
1823 TRACE("%p, %u, %d, %p.\n", node, stream, output, type);
1825 if (FAILED(hr = IMFTopologyNode_GetNodeType(node, &node_type)))
1826 return hr;
1828 switch (node_type)
1830 case MF_TOPOLOGY_OUTPUT_NODE:
1831 if (FAILED(hr = IMFTopologyNode_GetObject(node, &object)))
1832 return hr;
1834 hr = IUnknown_QueryInterface(object, &IID_IMFStreamSink, (void **)&stream_sink);
1835 IUnknown_Release(object);
1836 if (SUCCEEDED(hr))
1838 hr = IMFStreamSink_GetMediaTypeHandler(stream_sink, &type_handler);
1839 IMFStreamSink_Release(stream_sink);
1841 if (SUCCEEDED(hr))
1843 hr = IMFMediaTypeHandler_GetCurrentMediaType(type_handler, type);
1844 IMFMediaTypeHandler_Release(type_handler);
1847 break;
1848 case MF_TOPOLOGY_SOURCESTREAM_NODE:
1849 if (FAILED(hr = IMFTopologyNode_GetUnknown(node, &MF_TOPONODE_STREAM_DESCRIPTOR, &IID_IMFStreamDescriptor,
1850 (void **)&sd)))
1852 return hr;
1855 hr = IMFStreamDescriptor_GetMediaTypeHandler(sd, &type_handler);
1856 IMFStreamDescriptor_Release(sd);
1857 if (SUCCEEDED(hr))
1859 hr = IMFMediaTypeHandler_GetCurrentMediaType(type_handler, type);
1860 IMFMediaTypeHandler_Release(type_handler);
1862 break;
1863 case MF_TOPOLOGY_TRANSFORM_NODE:
1864 if (FAILED(hr = IMFTopologyNode_GetObject(node, &object)))
1865 return hr;
1867 hr = IUnknown_QueryInterface(object, &IID_IMFTransform, (void **)&transform);
1868 IUnknown_Release(object);
1869 if (SUCCEEDED(hr))
1871 if (output)
1872 hr = IMFTransform_GetOutputCurrentType(transform, stream, type);
1873 else
1874 hr = IMFTransform_GetInputCurrentType(transform, stream, type);
1875 IMFTransform_Release(transform);
1877 break;
1878 case MF_TOPOLOGY_TEE_NODE:
1879 if (SUCCEEDED(hr = IMFTopologyNode_GetInputPrefType(node, 0, type)))
1880 break;
1882 if (FAILED(IMFTopologyNode_GetUINT32(node, &MF_TOPONODE_PRIMARYOUTPUT, &primary_output)))
1883 primary_output = 0;
1885 hr = IMFTopologyNode_GetOutputPrefType(node, primary_output, type);
1886 break;
1887 default:
1891 return hr;
1894 static HRESULT WINAPI topology_loader_QueryInterface(IMFTopoLoader *iface, REFIID riid, void **out)
1896 TRACE("%p, %s, %p.\n", iface, debugstr_guid(riid), out);
1898 if (IsEqualIID(riid, &IID_IMFTopoLoader) ||
1899 IsEqualIID(riid, &IID_IUnknown))
1901 *out = iface;
1902 IMFTopoLoader_AddRef(iface);
1903 return S_OK;
1906 WARN("Unsupported %s.\n", debugstr_guid(riid));
1907 *out = NULL;
1908 return E_NOINTERFACE;
1911 static ULONG WINAPI topology_loader_AddRef(IMFTopoLoader *iface)
1913 struct topology_loader *loader = impl_from_IMFTopoLoader(iface);
1914 ULONG refcount = InterlockedIncrement(&loader->refcount);
1916 TRACE("%p, refcount %u.\n", iface, refcount);
1918 return refcount;
1921 static ULONG WINAPI topology_loader_Release(IMFTopoLoader *iface)
1923 struct topology_loader *loader = impl_from_IMFTopoLoader(iface);
1924 ULONG refcount = InterlockedDecrement(&loader->refcount);
1926 TRACE("%p, refcount %u.\n", iface, refcount);
1928 if (!refcount)
1930 heap_free(loader);
1933 return refcount;
1936 struct topoloader_context
1938 IMFTopology *input_topology;
1939 IMFTopology *output_topology;
1940 unsigned int marker;
1941 GUID key;
1944 static IMFTopologyNode *topology_loader_get_node_for_marker(struct topoloader_context *context, TOPOID *id)
1946 IMFTopologyNode *node;
1947 unsigned short i = 0;
1948 unsigned int value;
1950 while (SUCCEEDED(IMFTopology_GetNode(context->output_topology, i++, &node)))
1952 if (SUCCEEDED(IMFTopologyNode_GetUINT32(node, &context->key, &value)) && value == context->marker)
1954 IMFTopologyNode_GetTopoNodeID(node, id);
1955 return node;
1957 IMFTopologyNode_Release(node);
1960 *id = 0;
1961 return NULL;
1964 static HRESULT topology_loader_clone_node(struct topoloader_context *context, IMFTopologyNode *node,
1965 IMFTopologyNode **ret, unsigned int marker)
1967 IMFTopologyNode *cloned_node;
1968 MF_TOPOLOGY_TYPE node_type;
1969 HRESULT hr;
1971 if (ret) *ret = NULL;
1973 IMFTopologyNode_GetNodeType(node, &node_type);
1975 if (FAILED(hr = MFCreateTopologyNode(node_type, &cloned_node)))
1976 return hr;
1978 if (SUCCEEDED(hr = IMFTopologyNode_CloneFrom(cloned_node, node)))
1979 hr = IMFTopologyNode_SetUINT32(cloned_node, &context->key, marker);
1981 if (SUCCEEDED(hr))
1982 hr = IMFTopology_AddNode(context->output_topology, cloned_node);
1984 if (SUCCEEDED(hr) && ret)
1986 *ret = cloned_node;
1987 IMFTopologyNode_AddRef(*ret);
1990 IMFTopologyNode_Release(cloned_node);
1992 return hr;
1995 typedef HRESULT (*p_topology_loader_connect_func)(struct topoloader_context *context, IMFTopologyNode *upstream_node,
1996 unsigned int output_index, IMFTopologyNode *downstream_node, unsigned int input_index);
1998 static HRESULT topology_loader_connect_source_node(struct topoloader_context *context, IMFTopologyNode *upstream_node,
1999 unsigned int output_index, IMFTopologyNode *downstream_node, unsigned int input_index)
2001 FIXME("Unimplemented.\n");
2003 return E_NOTIMPL;
2006 static HRESULT topology_loader_resolve_branch(struct topoloader_context *context, IMFTopologyNode *upstream_node,
2007 unsigned int output_index, IMFTopologyNode *downstream_node, unsigned input_index)
2009 static const p_topology_loader_connect_func connectors[MF_TOPOLOGY_TEE_NODE+1][MF_TOPOLOGY_TEE_NODE+1] =
2011 /* OUTPUT */ { NULL },
2012 /* SOURCESTREAM */ { topology_loader_connect_source_node, NULL, NULL, NULL },
2013 /* TRANSFORM */ { NULL },
2014 /* TEE */ { NULL },
2016 MF_TOPOLOGY_TYPE u_type, d_type;
2017 IMFTopologyNode *node;
2018 TOPOID id;
2020 /* Downstream node might have already been cloned. */
2021 IMFTopologyNode_GetTopoNodeID(downstream_node, &id);
2022 if (FAILED(IMFTopology_GetNodeByID(context->output_topology, id, &node)))
2023 topology_loader_clone_node(context, downstream_node, &node, context->marker + 1);
2025 IMFTopologyNode_ConnectOutput(upstream_node, output_index, node, input_index);
2027 IMFTopologyNode_GetNodeType(upstream_node, &u_type);
2028 IMFTopologyNode_GetNodeType(downstream_node, &d_type);
2030 if (!connectors[u_type][d_type])
2032 WARN("Unsupported branch kind %d -> %d.\n", u_type, d_type);
2033 return E_FAIL;
2036 return connectors[u_type][d_type](context, upstream_node, output_index, downstream_node, input_index);
2039 static HRESULT topology_loader_resolve_nodes(struct topoloader_context *context, unsigned int *layer_size)
2041 IMFTopologyNode *downstream_node, *node, *orig_node;
2042 unsigned int input_index, size = 0;
2043 MF_TOPOLOGY_TYPE node_type;
2044 HRESULT hr = S_OK;
2045 TOPOID id;
2047 while ((node = topology_loader_get_node_for_marker(context, &id)))
2049 ++size;
2051 IMFTopology_GetNodeByID(context->input_topology, id, &orig_node);
2053 IMFTopologyNode_GetNodeType(node, &node_type);
2054 switch (node_type)
2056 case MF_TOPOLOGY_SOURCESTREAM_NODE:
2057 if (FAILED(IMFTopologyNode_GetOutput(orig_node, 0, &downstream_node, &input_index)))
2059 IMFTopology_RemoveNode(context->output_topology, node);
2060 continue;
2063 hr = topology_loader_resolve_branch(context, node, 0, downstream_node, input_index);
2064 break;
2065 case MF_TOPOLOGY_TRANSFORM_NODE:
2066 case MF_TOPOLOGY_TEE_NODE:
2067 FIXME("Unsupported node type %d.\n", node_type);
2068 break;
2069 default:
2070 WARN("Unexpected node type %d.\n", node_type);
2073 IMFTopologyNode_DeleteItem(node, &context->key);
2075 if (FAILED(hr))
2076 break;
2079 *layer_size = size;
2081 return hr;
2084 static HRESULT WINAPI topology_loader_Load(IMFTopoLoader *iface, IMFTopology *input_topology,
2085 IMFTopology **ret_topology, IMFTopology *current_topology)
2087 struct topoloader_context context = { 0 };
2088 IMFTopology *output_topology;
2089 MF_TOPOLOGY_TYPE node_type;
2090 unsigned int layer_size;
2091 IMFTopologyNode *node;
2092 unsigned short i = 0;
2093 IMFStreamSink *sink;
2094 IUnknown *object;
2095 HRESULT hr = E_FAIL;
2097 FIXME("%p, %p, %p, %p.\n", iface, input_topology, ret_topology, current_topology);
2099 if (current_topology)
2100 FIXME("Current topology instance is ignored.\n");
2102 /* Basic sanity checks for input topology:
2104 - source nodes must have stream descriptor set;
2105 - sink nodes must be resolved to stream sink objects;
2107 while (SUCCEEDED(IMFTopology_GetNode(input_topology, i++, &node)))
2109 IMFTopologyNode_GetNodeType(node, &node_type);
2111 switch (node_type)
2113 case MF_TOPOLOGY_OUTPUT_NODE:
2114 if (SUCCEEDED(hr = IMFTopologyNode_GetObject(node, &object)))
2116 /* Sinks must be bound beforehand. */
2117 if (FAILED(IUnknown_QueryInterface(object, &IID_IMFStreamSink, (void **)&sink)))
2118 hr = MF_E_TOPO_SINK_ACTIVATES_UNSUPPORTED;
2119 else if (sink)
2120 IMFStreamSink_Release(sink);
2121 IUnknown_Release(object);
2123 break;
2124 case MF_TOPOLOGY_SOURCESTREAM_NODE:
2125 hr = IMFTopologyNode_GetItem(node, &MF_TOPONODE_STREAM_DESCRIPTOR, NULL);
2126 break;
2127 default:
2131 IMFTopologyNode_Release(node);
2132 if (FAILED(hr))
2133 return hr;
2136 if (FAILED(hr = MFCreateTopology(&output_topology)))
2137 return hr;
2139 context.input_topology = input_topology;
2140 context.output_topology = output_topology;
2141 memset(&context.key, 0xff, sizeof(context.key));
2143 /* Clone source nodes, use initial marker value. */
2144 i = 0;
2145 while (SUCCEEDED(IMFTopology_GetNode(input_topology, i++, &node)))
2147 IMFTopologyNode_GetNodeType(node, &node_type);
2149 if (node_type == MF_TOPOLOGY_SOURCESTREAM_NODE)
2151 if (FAILED(hr = topology_loader_clone_node(&context, node, NULL, 0)))
2152 WARN("Failed to clone source node, hr %#x.\n", hr);
2155 IMFTopologyNode_Release(node);
2158 for (context.marker = 0;; ++context.marker)
2160 if (FAILED(hr = topology_loader_resolve_nodes(&context, &layer_size)))
2162 WARN("Failed to resolve for marker %u, hr %#x.\n", context.marker, hr);
2163 break;
2166 /* Reached last marker value. */
2167 if (!layer_size)
2168 break;
2171 /* For now return original topology. */
2173 *ret_topology = output_topology;
2175 return IMFTopology_CloneFrom(output_topology, input_topology);
2178 static const IMFTopoLoaderVtbl topologyloadervtbl =
2180 topology_loader_QueryInterface,
2181 topology_loader_AddRef,
2182 topology_loader_Release,
2183 topology_loader_Load,
2186 /***********************************************************************
2187 * MFCreateTopoLoader (mf.@)
2189 HRESULT WINAPI MFCreateTopoLoader(IMFTopoLoader **loader)
2191 struct topology_loader *object;
2193 TRACE("%p.\n", loader);
2195 if (!loader)
2196 return E_POINTER;
2198 object = heap_alloc(sizeof(*object));
2199 if (!object)
2200 return E_OUTOFMEMORY;
2202 object->IMFTopoLoader_iface.lpVtbl = &topologyloadervtbl;
2203 object->refcount = 1;
2205 *loader = &object->IMFTopoLoader_iface;
2207 return S_OK;
2210 static HRESULT WINAPI seq_source_QueryInterface(IMFSequencerSource *iface, REFIID riid, void **out)
2212 struct seq_source *seq_source = impl_from_IMFSequencerSource(iface);
2214 TRACE("%p, %s, %p.\n", iface, debugstr_guid(riid), out);
2216 *out = NULL;
2218 if (IsEqualIID(riid, &IID_IMFSequencerSource) ||
2219 IsEqualIID(riid, &IID_IUnknown))
2221 *out = &seq_source->IMFSequencerSource_iface;
2223 else if (IsEqualIID(riid, &IID_IMFMediaSourceTopologyProvider))
2225 *out = &seq_source->IMFMediaSourceTopologyProvider_iface;
2227 else
2229 WARN("Unimplemented %s.\n", debugstr_guid(riid));
2230 return E_NOINTERFACE;
2233 if (*out)
2234 IUnknown_AddRef((IUnknown *)*out);
2236 return S_OK;
2239 static ULONG WINAPI seq_source_AddRef(IMFSequencerSource *iface)
2241 struct seq_source *seq_source = impl_from_IMFSequencerSource(iface);
2242 ULONG refcount = InterlockedIncrement(&seq_source->refcount);
2244 TRACE("%p, refcount %u.\n", iface, refcount);
2246 return refcount;
2249 static ULONG WINAPI seq_source_Release(IMFSequencerSource *iface)
2251 struct seq_source *seq_source = impl_from_IMFSequencerSource(iface);
2252 ULONG refcount = InterlockedDecrement(&seq_source->refcount);
2254 TRACE("%p, refcount %u.\n", iface, refcount);
2256 if (!refcount)
2258 heap_free(seq_source);
2261 return refcount;
2264 static HRESULT WINAPI seq_source_AppendTopology(IMFSequencerSource *iface, IMFTopology *topology,
2265 DWORD flags, MFSequencerElementId *id)
2267 FIXME("%p, %p, %x, %p.\n", iface, topology, flags, id);
2269 return E_NOTIMPL;
2272 static HRESULT WINAPI seq_source_DeleteTopology(IMFSequencerSource *iface, MFSequencerElementId id)
2274 FIXME("%p, %#x.\n", iface, id);
2276 return E_NOTIMPL;
2279 static HRESULT WINAPI seq_source_GetPresentationContext(IMFSequencerSource *iface,
2280 IMFPresentationDescriptor *descriptor, MFSequencerElementId *id, IMFTopology **topology)
2282 FIXME("%p, %p, %p, %p.\n", iface, descriptor, id, topology);
2284 return E_NOTIMPL;
2287 static HRESULT WINAPI seq_source_UpdateTopology(IMFSequencerSource *iface, MFSequencerElementId id,
2288 IMFTopology *topology)
2290 FIXME("%p, %#x, %p.\n", iface, id, topology);
2292 return E_NOTIMPL;
2295 static HRESULT WINAPI seq_source_UpdateTopologyFlags(IMFSequencerSource *iface, MFSequencerElementId id, DWORD flags)
2297 FIXME("%p, %#x, %#x.\n", iface, id, flags);
2299 return E_NOTIMPL;
2302 static HRESULT WINAPI seq_source_topology_provider_QueryInterface(IMFMediaSourceTopologyProvider *iface, REFIID riid,
2303 void **obj)
2305 struct seq_source *seq_source = impl_from_IMFMediaSourceTopologyProvider(iface);
2306 return IMFSequencerSource_QueryInterface(&seq_source->IMFSequencerSource_iface, riid, obj);
2309 static ULONG WINAPI seq_source_topology_provider_AddRef(IMFMediaSourceTopologyProvider *iface)
2311 struct seq_source *seq_source = impl_from_IMFMediaSourceTopologyProvider(iface);
2312 return IMFSequencerSource_AddRef(&seq_source->IMFSequencerSource_iface);
2315 static ULONG WINAPI seq_source_topology_provider_Release(IMFMediaSourceTopologyProvider *iface)
2317 struct seq_source *seq_source = impl_from_IMFMediaSourceTopologyProvider(iface);
2318 return IMFSequencerSource_Release(&seq_source->IMFSequencerSource_iface);
2321 static HRESULT WINAPI seq_source_topology_provider_GetMediaSourceTopology(IMFMediaSourceTopologyProvider *iface,
2322 IMFPresentationDescriptor *pd, IMFTopology **topology)
2324 FIXME("%p, %p, %p.\n", iface, pd, topology);
2326 return E_NOTIMPL;
2329 static const IMFMediaSourceTopologyProviderVtbl seq_source_topology_provider_vtbl =
2331 seq_source_topology_provider_QueryInterface,
2332 seq_source_topology_provider_AddRef,
2333 seq_source_topology_provider_Release,
2334 seq_source_topology_provider_GetMediaSourceTopology,
2337 static const IMFSequencerSourceVtbl seqsourcevtbl =
2339 seq_source_QueryInterface,
2340 seq_source_AddRef,
2341 seq_source_Release,
2342 seq_source_AppendTopology,
2343 seq_source_DeleteTopology,
2344 seq_source_GetPresentationContext,
2345 seq_source_UpdateTopology,
2346 seq_source_UpdateTopologyFlags,
2349 /***********************************************************************
2350 * MFCreateSequencerSource (mf.@)
2352 HRESULT WINAPI MFCreateSequencerSource(IUnknown *reserved, IMFSequencerSource **seq_source)
2354 struct seq_source *object;
2356 TRACE("%p, %p.\n", reserved, seq_source);
2358 if (!seq_source)
2359 return E_POINTER;
2361 object = heap_alloc(sizeof(*object));
2362 if (!object)
2363 return E_OUTOFMEMORY;
2365 object->IMFSequencerSource_iface.lpVtbl = &seqsourcevtbl;
2366 object->IMFMediaSourceTopologyProvider_iface.lpVtbl = &seq_source_topology_provider_vtbl;
2367 object->refcount = 1;
2369 *seq_source = &object->IMFSequencerSource_iface;
2371 return S_OK;