From c1c77f22bc3ccde601134ac1f9375ac3c504bef0 Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Tue, 8 Oct 2019 15:58:55 +0300 Subject: [PATCH] mf: Copy preferred types when cloning nodes. Signed-off-by: Nikolay Sivov Signed-off-by: Alexandre Julliard --- dlls/mf/tests/mf.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++ dlls/mf/topology.c | 26 +++++++++++++++++++ 2 files changed, 91 insertions(+) diff --git a/dlls/mf/tests/mf.c b/dlls/mf/tests/mf.c index 038bfeacd1d..7f9edfe241c 100644 --- a/dlls/mf/tests/mf.c +++ b/dlls/mf/tests/mf.c @@ -656,6 +656,71 @@ static void test_topology(void) IMFTopologyNode_Release(node); IMFTopologyNode_Release(node2); + /* Cloning nodes of different types. */ + hr = MFCreateTopologyNode(MF_TOPOLOGY_SOURCESTREAM_NODE, &node); + ok(hr == S_OK, "Failed to create topology node, hr %#x.\n", hr); + + hr = MFCreateTopologyNode(MF_TOPOLOGY_OUTPUT_NODE, &node2); + ok(hr == S_OK, "Failed to create topology node, hr %#x.\n", hr); + + hr = IMFTopologyNode_CloneFrom(node, node2); + ok(hr == MF_E_INVALIDREQUEST, "Unexpected hr %#x.\n", hr); + + IMFTopologyNode_Release(node2); + + /* Cloning preferred types. */ + hr = MFCreateTopologyNode(MF_TOPOLOGY_SOURCESTREAM_NODE, &node2); + ok(hr == S_OK, "Failed to create topology node, hr %#x.\n", hr); + + hr = MFCreateMediaType(&mediatype); + ok(hr == S_OK, "Failed to create media type, hr %#x.\n", hr); + + hr = IMFTopologyNode_SetOutputPrefType(node2, 0, mediatype); + ok(hr == S_OK, "Failed to set preferred type, hr %#x.\n", hr); + + /* Vista checks for additional attributes. */ + hr = IMFTopologyNode_CloneFrom(node, node2); + ok(hr == S_OK || broken(hr == MF_E_ATTRIBUTENOTFOUND) /* Vista */, "Failed to clone a node, hr %#x.\n", hr); + + hr = IMFTopologyNode_GetOutputPrefType(node, 0, &mediatype2); + ok(hr == S_OK, "Failed to get preferred type, hr %#x.\n", hr); + ok(mediatype == mediatype2, "Unexpected media type.\n"); + + IMFMediaType_Release(mediatype2); + IMFMediaType_Release(mediatype); + + IMFTopologyNode_Release(node2); + + /* Existing preferred types are not cleared. */ + hr = MFCreateTopologyNode(MF_TOPOLOGY_SOURCESTREAM_NODE, &node2); + ok(hr == S_OK, "Failed to create topology node, hr %#x.\n", hr); + + hr = IMFTopologyNode_GetOutputCount(node, &count); + ok(hr == S_OK, "Failed to get output count, hr %#x.\n", hr); + ok(count == 1, "Unexpected output count.\n"); + + hr = IMFTopologyNode_CloneFrom(node, node2); + ok(hr == S_OK || broken(hr == MF_E_ATTRIBUTENOTFOUND) /* Vista */, "Failed to clone a node, hr %#x.\n", hr); + + hr = IMFTopologyNode_GetOutputCount(node, &count); + ok(hr == S_OK, "Failed to get output count, hr %#x.\n", hr); + ok(count == 1, "Unexpected output count.\n"); + + hr = IMFTopologyNode_GetOutputPrefType(node, 0, &mediatype2); + ok(hr == S_OK, "Failed to get preferred type, hr %#x.\n", hr); + ok(!!mediatype2, "Unexpected media type.\n"); + IMFMediaType_Release(mediatype2); + + hr = IMFTopologyNode_CloneFrom(node2, node); + ok(hr == S_OK || broken(hr == MF_E_ATTRIBUTENOTFOUND) /* Vista */, "Failed to clone a node, hr %#x.\n", hr); + + hr = IMFTopologyNode_GetOutputCount(node2, &count); + ok(hr == S_OK, "Failed to get output count, hr %#x.\n", hr); + ok(count == 1, "Unexpected output count.\n"); + + IMFTopologyNode_Release(node2); + IMFTopologyNode_Release(node); + IMFTopology_Release(topology); } diff --git a/dlls/mf/topology.c b/dlls/mf/topology.c index ad89739d4ad..db828163286 100644 --- a/dlls/mf/topology.c +++ b/dlls/mf/topology.c @@ -1628,7 +1628,9 @@ static HRESULT WINAPI topology_node_CloneFrom(IMFTopologyNode *iface, IMFTopolog { struct topology_node *node = impl_from_IMFTopologyNode(iface); MF_TOPOLOGY_TYPE node_type; + IMFMediaType *mediatype; IUnknown *object; + DWORD count, i; TOPOID topoid; HRESULT hr; @@ -1656,6 +1658,30 @@ static HRESULT WINAPI topology_node_CloneFrom(IMFTopologyNode *iface, IMFTopolog if (SUCCEEDED(hr)) node->id = topoid; + if (SUCCEEDED(IMFTopologyNode_GetInputCount(src_node, &count))) + { + for (i = 0; i < count; ++i) + { + if (SUCCEEDED(IMFTopologyNode_GetInputPrefType(src_node, i, &mediatype))) + { + IMFTopologyNode_SetInputPrefType(iface, i, mediatype); + IMFMediaType_Release(mediatype); + } + } + } + + if (SUCCEEDED(IMFTopologyNode_GetOutputCount(src_node, &count))) + { + for (i = 0; i < count; ++i) + { + if (SUCCEEDED(IMFTopologyNode_GetOutputPrefType(src_node, i, &mediatype))) + { + IMFTopologyNode_SetOutputPrefType(iface, i, mediatype); + IMFMediaType_Release(mediatype); + } + } + } + LeaveCriticalSection(&node->cs); if (object)