bf197aadcf7b46b088dddd96ef75d4af5d25da4b
[reactos.git] / reactos / dll / directx / amstream / mediastream.c
1 /*
2 * Implementation of IMediaStream Interface
3 *
4 * Copyright 2005, 2008 Christian Costa
5 *
6 * This file contains the (internal) driver registration functions,
7 * driver enumeration APIs and DirectDraw creation functions.
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24 #include "wine/debug.h"
25
26 #define COBJMACROS
27
28 #include "winbase.h"
29 #include "wingdi.h"
30
31 #include "amstream_private.h"
32 #include "ddstream.h"
33 #include "amstream.h"
34
35 WINE_DEFAULT_DEBUG_CHANNEL(amstream);
36
37 typedef struct {
38 IMediaStream lpVtbl;
39 LONG ref;
40 IMultiMediaStream* Parent;
41 MSPID PurposeId;
42 STREAM_TYPE StreamType;
43 } IMediaStreamImpl;
44
45 typedef struct {
46 IDirectDrawMediaStream lpVtbl;
47 LONG ref;
48 IMultiMediaStream* Parent;
49 MSPID PurposeId;
50 STREAM_TYPE StreamType;
51 } IDirectDrawMediaStreamImpl;
52
53 static const struct IMediaStreamVtbl MediaStream_Vtbl;
54 static const struct IDirectDrawMediaStreamVtbl DirectDrawMediaStream_Vtbl;
55
56 HRESULT MediaStream_create(IMultiMediaStream* Parent, const MSPID* pPurposeId, STREAM_TYPE StreamType, IMediaStream** ppMediaStream)
57 {
58 IMediaStreamImpl* object;
59
60 TRACE("(%p,%p,%p)\n", Parent, pPurposeId, ppMediaStream);
61
62 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IMediaStreamImpl));
63 if (!object)
64 {
65 ERR("Out of memory\n");
66 return E_OUTOFMEMORY;
67 }
68
69 object->lpVtbl.lpVtbl = &MediaStream_Vtbl;
70 object->ref = 1;
71
72 object->Parent = Parent;
73 object->PurposeId = *pPurposeId;
74 object->StreamType = StreamType;
75
76 *ppMediaStream = (IMediaStream*)object;
77
78 return S_OK;
79 }
80
81 /*** IUnknown methods ***/
82 static HRESULT WINAPI IMediaStreamImpl_QueryInterface(IMediaStream* iface, REFIID riid, void** ppvObject)
83 {
84 IMediaStreamImpl *This = (IMediaStreamImpl *)iface;
85
86 TRACE("(%p/%p)->(%s,%p)\n", iface, This, debugstr_guid(riid), ppvObject);
87
88 if (IsEqualGUID(riid, &IID_IUnknown) ||
89 IsEqualGUID(riid, &IID_IMediaStream))
90 {
91 IClassFactory_AddRef(iface);
92 *ppvObject = This;
93 return S_OK;
94 }
95
96 ERR("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
97 return E_NOINTERFACE;
98 }
99
100 static ULONG WINAPI IMediaStreamImpl_AddRef(IMediaStream* iface)
101 {
102 IMediaStreamImpl *This = (IMediaStreamImpl *)iface;
103
104 TRACE("(%p/%p)\n", iface, This);
105
106 return InterlockedIncrement(&This->ref);
107 }
108
109 static ULONG WINAPI IMediaStreamImpl_Release(IMediaStream* iface)
110 {
111 IMediaStreamImpl *This = (IMediaStreamImpl *)iface;
112 ULONG ref = InterlockedDecrement(&This->ref);
113
114 TRACE("(%p/%p)\n", iface, This);
115
116 if (!ref)
117 HeapFree(GetProcessHeap(), 0, This);
118
119 return ref;
120 }
121
122 /*** IMediaStream methods ***/
123 static HRESULT WINAPI IMediaStreamImpl_GetMultiMediaStream(IMediaStream* iface, IMultiMediaStream** ppMultiMediaStream)
124 {
125 IMediaStreamImpl *This = (IMediaStreamImpl *)iface;
126
127 FIXME("(%p/%p)->(%p) stub!\n", This, iface, ppMultiMediaStream);
128
129 return S_FALSE;
130 }
131
132
133 static HRESULT WINAPI IMediaStreamImpl_GetInformation(IMediaStream* iface, MSPID* pPurposeId, STREAM_TYPE* pType)
134 {
135 IMediaStreamImpl *This = (IMediaStreamImpl *)iface;
136
137 TRACE("(%p/%p)->(%p,%p)\n", This, iface, pPurposeId, pType);
138
139 if (pPurposeId)
140 *pPurposeId = This->PurposeId;
141 if (pType)
142 *pType = This->StreamType;
143
144 return S_OK;
145 }
146
147 static HRESULT WINAPI IMediaStreamImpl_SetSameFormat(IMediaStream* iface, IMediaStream* pStreamThatHasDesiredFormat, DWORD dwFlags)
148 {
149 IMediaStreamImpl *This = (IMediaStreamImpl *)iface;
150
151 FIXME("(%p/%p)->(%p,%x) stub!\n", This, iface, pStreamThatHasDesiredFormat, dwFlags);
152
153 return S_FALSE;
154 }
155
156 static HRESULT WINAPI IMediaStreamImpl_AllocateSample(IMediaStream* iface, DWORD dwFlags, IStreamSample** ppSample)
157 {
158 IMediaStreamImpl *This = (IMediaStreamImpl *)iface;
159
160 FIXME("(%p/%p)->(%x,%p) stub!\n", This, iface, dwFlags, ppSample);
161
162 return S_FALSE;
163 }
164
165 static HRESULT WINAPI IMediaStreamImpl_CreateSharedSample(IMediaStream* iface, IStreamSample* pExistingSample, DWORD dwFlags, IStreamSample** ppSample)
166 {
167 IMediaStreamImpl *This = (IMediaStreamImpl *)iface;
168
169 FIXME("(%p/%p)->(%p,%x,%p) stub!\n", This, iface, pExistingSample, dwFlags, ppSample);
170
171 return S_FALSE;
172 }
173
174 static HRESULT WINAPI IMediaStreamImpl_SendEndOfStream(IMediaStream* iface, DWORD dwFlags)
175 {
176 IMediaStreamImpl *This = (IMediaStreamImpl *)iface;
177
178 FIXME("(%p/%p)->(%x) stub!\n", This, iface, dwFlags);
179
180 return S_FALSE;
181 }
182
183 static const struct IMediaStreamVtbl MediaStream_Vtbl =
184 {
185 IMediaStreamImpl_QueryInterface,
186 IMediaStreamImpl_AddRef,
187 IMediaStreamImpl_Release,
188 IMediaStreamImpl_GetMultiMediaStream,
189 IMediaStreamImpl_GetInformation,
190 IMediaStreamImpl_SetSameFormat,
191 IMediaStreamImpl_AllocateSample,
192 IMediaStreamImpl_CreateSharedSample,
193 IMediaStreamImpl_SendEndOfStream
194 };
195
196 HRESULT DirectDrawMediaStream_create(IMultiMediaStream* Parent, const MSPID* pPurposeId, STREAM_TYPE StreamType, IMediaStream** ppMediaStream)
197 {
198 IDirectDrawMediaStreamImpl* object;
199
200 TRACE("(%p,%p,%p)\n", Parent, pPurposeId, ppMediaStream);
201
202 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IMediaStreamImpl));
203 if (!object)
204 {
205 ERR("Out of memory\n");
206 return E_OUTOFMEMORY;
207 }
208
209 object->lpVtbl.lpVtbl = &DirectDrawMediaStream_Vtbl;
210 object->ref = 1;
211
212 object->Parent = Parent;
213 object->PurposeId = *pPurposeId;
214 object->StreamType = StreamType;
215
216 *ppMediaStream = (IMediaStream*)object;
217
218 return S_OK;
219 }
220
221 static HRESULT WINAPI IDirectDrawMediaStreamImpl_QueryInterface(IDirectDrawMediaStream* iface, REFIID riid, void** ppvObject)
222 {
223 IMediaStreamImpl *This = (IMediaStreamImpl *)iface;
224
225 TRACE("(%p/%p)->(%s,%p)\n", iface, This, debugstr_guid(riid), ppvObject);
226
227 if (IsEqualGUID(riid, &IID_IUnknown) ||
228 IsEqualGUID(riid, &IID_IMediaStream) ||
229 IsEqualGUID(riid, &IID_IDirectDrawMediaStream))
230 {
231 IClassFactory_AddRef(iface);
232 *ppvObject = This;
233 return S_OK;
234 }
235
236 ERR("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
237 return E_NOINTERFACE;
238 }
239
240 static HRESULT WINAPI IDirectDrawMediaStreamImpl_GetFormat(IDirectDrawMediaStream* iface, DDSURFACEDESC *pDDSDCurrent,
241 IDirectDrawPalette **ppDirectDrawPalette, DDSURFACEDESC *pDDSDDesired, DWORD *pdwFlags)
242 {
243 FIXME("(%p)->(%p,%p,%p,%p) stub!\n", iface, pDDSDCurrent, ppDirectDrawPalette, pDDSDDesired, pdwFlags);
244
245 return E_NOTIMPL;
246
247 }
248
249 static HRESULT WINAPI IDirectDrawMediaStreamImpl_SetFormat(IDirectDrawMediaStream* iface, const DDSURFACEDESC *pDDSurfaceDesc,
250 IDirectDrawPalette *pDirectDrawPalette)
251 {
252 FIXME("(%p)->(%p,%p) stub!\n", iface, pDDSurfaceDesc, pDirectDrawPalette);
253
254 return E_NOTIMPL;
255 }
256
257 static HRESULT WINAPI IDirectDrawMediaStreamImpl_GetDirectDraw(IDirectDrawMediaStream* iface, IDirectDraw **ppDirectDraw)
258 {
259 FIXME("(%p)->(%p) stub!\n", iface, ppDirectDraw);
260
261 return E_NOTIMPL;
262 }
263
264 static HRESULT WINAPI IDirectDrawMediaStreamImpl_SetDirectDraw(IDirectDrawMediaStream* iface, IDirectDraw *pDirectDraw)
265 {
266 FIXME("(%p)->(%p) stub!\n", iface, pDirectDraw);
267
268 return E_NOTIMPL;
269 }
270
271 static HRESULT WINAPI IDirectDrawMediaStreamImpl_CreateSample(IDirectDrawMediaStream* iface, IDirectDrawSurface *pSurface, const RECT *pRect,
272 DWORD dwFlags, IDirectDrawStreamSample **ppSample)
273 {
274 FIXME("(%p)->(%p,%p,%x,%p) stub!\n", iface, pSurface, pRect, dwFlags, ppSample);
275
276 return E_NOTIMPL;
277 }
278
279 static HRESULT WINAPI IDirectDrawMediaStreamImpl_GetTimePerFrame(IDirectDrawMediaStream* iface, STREAM_TIME *pFrameTime)
280 {
281 FIXME("(%p)->(%p) stub!\n", iface, pFrameTime);
282
283 return E_NOTIMPL;
284 }
285
286 /* Note: Hack so we can reuse the old functions without compiler warnings */
287 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
288 # define XCAST(fun) (typeof(DirectDrawMediaStream_Vtbl.fun))
289 #else
290 # define XCAST(fun) (void*)
291 #endif
292
293 static const struct IDirectDrawMediaStreamVtbl DirectDrawMediaStream_Vtbl =
294 {
295 IDirectDrawMediaStreamImpl_QueryInterface,
296 XCAST(AddRef)IMediaStreamImpl_AddRef,
297 XCAST(Release)IMediaStreamImpl_Release,
298 XCAST(GetMultiMediaStream)IMediaStreamImpl_GetMultiMediaStream,
299 XCAST(GetInformation)IMediaStreamImpl_GetInformation,
300 XCAST(SetSameFormat)IMediaStreamImpl_SetSameFormat,
301 XCAST(AllocateSample)IMediaStreamImpl_AllocateSample,
302 XCAST(CreateSharedSample)IMediaStreamImpl_CreateSharedSample,
303 XCAST(SendEndOfStream)IMediaStreamImpl_SendEndOfStream,
304 IDirectDrawMediaStreamImpl_GetFormat,
305 IDirectDrawMediaStreamImpl_SetFormat,
306 IDirectDrawMediaStreamImpl_GetDirectDraw,
307 IDirectDrawMediaStreamImpl_SetDirectDraw,
308 IDirectDrawMediaStreamImpl_CreateSample,
309 IDirectDrawMediaStreamImpl_GetTimePerFrame
310 };
311 #undef XCAST