Sync to trunk r39350.
[reactos.git] / reactos / dll / directx / ksuser / ksuser.c
1 /*
2 * KSUSER.DLL - ReactOS
3 *
4 * Copyright 2008 Magnus Olsen and Dmitry Chapyshev
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21
22 #include "ksuser.h"
23 #define NDEBUG
24 #include <debug.h>
25
26 NTSTATUS NTAPI KsiCreateObjectType( HANDLE hHandle, PVOID guidstr, PVOID Buffer, ULONG BufferSize, ACCESS_MASK DesiredAccess, PHANDLE phHandle);
27
28 NTSTATUS
29 NTAPI
30 KsiCreateObjectType( HANDLE hHandle,
31 PVOID IID,
32 PVOID Buffer,
33 ULONG BufferSize,
34 ACCESS_MASK DesiredAccess,
35 PHANDLE phHandle)
36 {
37 NTSTATUS Status;
38 ULONG Length;
39 ULONG TotalSize;
40 LPWSTR pStr;
41 UNICODE_STRING ObjectName;
42 OBJECT_ATTRIBUTES ObjectAttributes;
43 IO_STATUS_BLOCK IoStatusBlock;
44
45 Length = wcslen(IID);
46
47 TotalSize = (Length * sizeof(WCHAR)) + BufferSize + 2 * sizeof(WCHAR);
48
49 pStr = HeapAlloc(GetProcessHeap(), 0, TotalSize);
50 if (!pStr)
51 return STATUS_INSUFFICIENT_RESOURCES;
52
53 wcscpy(pStr, (LPWSTR)IID);
54 pStr[Length] = L'\\';
55 memcpy(&pStr[Length+1], Buffer, BufferSize);
56 pStr[Length+1+BufferSize] = L'\0';
57
58 RtlInitUnicodeString(&ObjectName, pStr);
59
60 InitializeObjectAttributes(&ObjectAttributes, &ObjectName, OBJ_CASE_INSENSITIVE, hHandle, NULL);
61
62 Status = NtCreateFile(phHandle, DesiredAccess, &ObjectAttributes, &IoStatusBlock, NULL, FILE_ATTRIBUTE_NORMAL, 0, 1, 0, NULL, 0);
63 HeapFree(GetProcessHeap(), 0, pStr);
64 if (!NT_SUCCESS(Status))
65 {
66 *phHandle = INVALID_HANDLE_VALUE;
67 Status = RtlNtStatusToDosError(Status);
68 }
69 return Status;
70 }
71
72 /*++
73 * @name KsCreateAllocator
74 * @implemented
75 * The function KsCreateAllocator creates a handle to an allocator for the given sink connection handle
76 *
77 * @param HANDLE ConnectionHandle
78 * Handle to the sink connection on which to create the allocator
79 *
80 * @param PKSALLOCATOR_FRAMING AllocatorFraming
81 * the input param we using to alloc our framing
82 *
83 * @param PHANDLE AllocatorHandle
84 * Our new handle that we have alloc
85 *
86 * @return
87 * Return NTSTATUS error code or sussess code.
88 *
89 * @remarks.
90 * none
91 *
92 *--*/
93 KSDDKAPI
94 NTSTATUS
95 NTAPI
96 KsCreateAllocator(HANDLE ConnectionHandle,
97 PKSALLOCATOR_FRAMING AllocatorFraming,
98 PHANDLE AllocatorHandle)
99
100 {
101 return KsiCreateObjectType( ConnectionHandle,
102 KSSTRING_Allocator,
103 (PVOID) AllocatorFraming,
104 sizeof(KSALLOCATOR_FRAMING),
105 GENERIC_READ,
106 AllocatorHandle);
107 }
108
109 /*++
110 * @name KsCreateClock
111 * @implemented
112 *
113 * The function KsCreateClock creates handle to clock instance
114 *
115 * @param HANDLE ConnectionHandle
116 * Handle to use to create the clock
117 *
118 * @param PKSCLOCK_CREATE ClockCreate
119 * paramenter to use to create the clock
120 *
121 * @param PHANDLE ClockHandle
122 * The new handle
123 *
124 * @return
125 * Return NTSTATUS error code or sussess code.
126 *
127 * @remarks.
128 * none
129 *
130 *--*/
131 KSDDKAPI
132 NTSTATUS
133 NTAPI
134 KsCreateClock(HANDLE ConnectionHandle,
135 PKSCLOCK_CREATE ClockCreate,
136 PHANDLE ClockHandle)
137 {
138 return KsiCreateObjectType( ConnectionHandle,
139 KSSTRING_Clock,
140 (PVOID) ClockCreate,
141 sizeof(KSCLOCK_CREATE),
142 GENERIC_READ,
143 ClockHandle);
144 }
145
146 /*++
147 * @name KsCreatePin
148 * @implemented
149 *
150 * The function KsCreatePin passes a connection request to device and create pin instance
151 *
152 * @param HANDLE FilterHandle
153 * handle of the filter initiating the create request
154 *
155 * @param PKSPIN_CONNECT Connect
156 * Pointer to a KSPIN_CONNECT structure that contains parameters for the requested connection.
157 * This should be followed in memory by a KSDATAFORMAT data structure, describing the data format
158 * requested for the connection.
159
160 * @param ACCESS_MASK DesiredAccess
161 * Desrided access
162 *
163 * @param PHANDLE ConnectionHandle
164 * connection handle passed
165 *
166 * @return
167 * Return NTSTATUS error code or sussess code.
168 *
169 * @remarks.
170 * The flag in PKSDATAFORMAT is not really document,
171 * to find it u need api mointor allot api and figout
172 * how it works, only flag I have found is the
173 * KSDATAFORMAT_ATTRIBUTES flag, it doing a Align
174 * of LONLONG size, it also round up it.
175 *
176 *--*/
177
178 KSDDKAPI
179 NTSTATUS
180 NTAPI
181 KsCreatePin(HANDLE FilterHandle,
182 PKSPIN_CONNECT Connect,
183 ACCESS_MASK DesiredAccess,
184 PHANDLE ConnectionHandle)
185 {
186 ULONG BufferSize = sizeof(KSPIN_CONNECT);
187 PKSDATAFORMAT DataFormat = (PKSDATAFORMAT)(Connect + 1);
188
189 if (DataFormat->Flags & KSDATAFORMAT_ATTRIBUTES)
190 {
191 BufferSize += (ROUND_UP(DataFormat->FormatSize,sizeof(LONGLONG)) + DataFormat->FormatSize);
192 }
193
194 return KsiCreateObjectType(FilterHandle,
195 KSSTRING_Pin,
196 Connect,
197 BufferSize,
198 DesiredAccess,
199 ConnectionHandle);
200
201 }
202
203 /*++
204 * @name KsCreateTopologyNode
205 * @implemented
206 *
207 * The function KsCreateTopologyNode creates a handle to a topology node instance
208 *
209 * @param HANDLE ParentHandle
210 * Handle to parent when want to use when we created the node on
211 *
212 *
213 * @param PKSNODE_CREATE NodeCreate
214 * topology node parameters to use when it is create
215 *
216 * @param ACCESS_MASK DesiredAccess
217 * Desrided access
218 *
219 * @param PHANDLE NodeHandle
220 * Location for the topology node handle
221 *
222 * @return
223 * Return NTSTATUS error code or sussess code.
224 *
225 * @remarks.
226 * none
227 *
228 *--*/
229 KSDDKAPI
230 NTSTATUS
231 NTAPI
232 KsCreateTopologyNode(HANDLE ParentHandle,
233 PKSNODE_CREATE NodeCreate,
234 IN ACCESS_MASK DesiredAccess,
235 OUT PHANDLE NodeHandle)
236 {
237 return KsiCreateObjectType( ParentHandle,
238 KSSTRING_TopologyNode,
239 (PVOID) NodeCreate,
240 sizeof(KSNODE_CREATE),
241 DesiredAccess,
242 NodeHandle);
243 }
244
245
246 BOOL
247 APIENTRY
248 DllMain(HANDLE hModule, DWORD ulreason, LPVOID lpReserved)
249 {
250 switch (ulreason)
251 {
252 case DLL_PROCESS_ATTACH:
253 case DLL_THREAD_ATTACH:
254 case DLL_THREAD_DETACH:
255 case DLL_PROCESS_DETACH:
256 break;
257 }
258
259 return TRUE;
260 }