amstream: Basic COM cleanup for the IDirectDrawMediaStream iface.
[wine] / dlls / 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 "amstream.h"
33
34 #include "ddstream.h"
35
36 WINE_DEFAULT_DEBUG_CHANNEL(amstream);
37
38 typedef struct {
39     const IMediaStreamVtbl *lpVtbl;
40     LONG ref;
41     IMultiMediaStream* Parent;
42     MSPID PurposeId;
43     STREAM_TYPE StreamType;
44 } IMediaStreamImpl;
45
46 typedef struct {
47     IDirectDrawMediaStream IDirectDrawMediaStream_iface;
48     LONG ref;
49     IMultiMediaStream* Parent;
50     MSPID PurposeId;
51     STREAM_TYPE StreamType;
52 } IDirectDrawMediaStreamImpl;
53
54 static const struct IMediaStreamVtbl MediaStream_Vtbl;
55 static const struct IDirectDrawMediaStreamVtbl DirectDrawMediaStream_Vtbl;
56
57 HRESULT MediaStream_create(IMultiMediaStream* Parent, const MSPID* pPurposeId, STREAM_TYPE StreamType, IMediaStream** ppMediaStream)
58 {
59     IMediaStreamImpl* object; 
60
61     TRACE("(%p,%s,%p)\n", Parent, debugstr_guid(pPurposeId), ppMediaStream);
62
63     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IMediaStreamImpl));
64     if (!object)
65     {
66         ERR("Out of memory\n");
67         return E_OUTOFMEMORY;
68     }
69
70     object->lpVtbl = &MediaStream_Vtbl;
71     object->ref = 1;
72
73     object->Parent = Parent;
74     object->PurposeId = *pPurposeId;
75     object->StreamType = StreamType;
76
77     *ppMediaStream = (IMediaStream*)object;
78
79     return S_OK;
80 }
81
82 /*** IUnknown methods ***/
83 static HRESULT WINAPI IMediaStreamImpl_QueryInterface(IMediaStream* iface, REFIID riid, void** ppvObject)
84 {
85     IMediaStreamImpl *This = (IMediaStreamImpl *)iface;
86
87     TRACE("(%p/%p)->(%s,%p)\n", iface, This, debugstr_guid(riid), ppvObject);
88
89     if (IsEqualGUID(riid, &IID_IUnknown) ||
90         IsEqualGUID(riid, &IID_IMediaStream))
91     {
92         IUnknown_AddRef(iface);
93         *ppvObject = This;
94         return S_OK;
95     }
96
97     ERR("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
98     return E_NOINTERFACE;
99 }
100
101 static ULONG WINAPI IMediaStreamImpl_AddRef(IMediaStream* iface)
102 {
103     IMediaStreamImpl *This = (IMediaStreamImpl *)iface;
104
105     TRACE("(%p/%p)\n", iface, This);
106
107     return InterlockedIncrement(&This->ref);
108 }
109
110 static ULONG WINAPI IMediaStreamImpl_Release(IMediaStream* iface)
111 {
112     IMediaStreamImpl *This = (IMediaStreamImpl *)iface;
113     ULONG ref = InterlockedDecrement(&This->ref);
114
115     TRACE("(%p/%p)\n", iface, This);
116
117     if (!ref)
118       HeapFree(GetProcessHeap(), 0, This);
119
120     return ref;
121 }
122
123 /*** IMediaStream methods ***/
124 static HRESULT WINAPI IMediaStreamImpl_GetMultiMediaStream(IMediaStream* iface, IMultiMediaStream** ppMultiMediaStream)
125 {
126     IMediaStreamImpl *This = (IMediaStreamImpl *)iface;
127
128     FIXME("(%p/%p)->(%p) stub!\n", This, iface, ppMultiMediaStream);
129
130     return S_FALSE;
131 }
132
133
134 static HRESULT WINAPI IMediaStreamImpl_GetInformation(IMediaStream* iface, MSPID* pPurposeId, STREAM_TYPE* pType)
135 {
136     IMediaStreamImpl *This = (IMediaStreamImpl *)iface;
137
138     TRACE("(%p/%p)->(%p,%p)\n", This, iface, pPurposeId, pType);
139
140     if (pPurposeId)
141         *pPurposeId = This->PurposeId;
142     if (pType)
143         *pType = This->StreamType;
144
145     return S_OK;
146 }
147
148 static HRESULT WINAPI IMediaStreamImpl_SetSameFormat(IMediaStream* iface, IMediaStream* pStreamThatHasDesiredFormat, DWORD dwFlags)
149 {
150     IMediaStreamImpl *This = (IMediaStreamImpl *)iface;
151
152     FIXME("(%p/%p)->(%p,%x) stub!\n", This, iface, pStreamThatHasDesiredFormat, dwFlags);
153
154     return S_FALSE;
155 }
156
157 static HRESULT WINAPI IMediaStreamImpl_AllocateSample(IMediaStream* iface, DWORD dwFlags, IStreamSample** ppSample)
158 {
159     IMediaStreamImpl *This = (IMediaStreamImpl *)iface;
160
161     FIXME("(%p/%p)->(%x,%p) stub!\n", This, iface, dwFlags, ppSample);
162
163     return S_FALSE;
164 }
165
166 static HRESULT WINAPI IMediaStreamImpl_CreateSharedSample(IMediaStream* iface, IStreamSample* pExistingSample, DWORD dwFlags, IStreamSample** ppSample)
167 {
168     IMediaStreamImpl *This = (IMediaStreamImpl *)iface;
169
170     FIXME("(%p/%p)->(%p,%x,%p) stub!\n", This, iface, pExistingSample, dwFlags, ppSample);
171
172     return S_FALSE;
173 }
174
175 static HRESULT WINAPI IMediaStreamImpl_SendEndOfStream(IMediaStream* iface, DWORD dwFlags)
176 {
177     IMediaStreamImpl *This = (IMediaStreamImpl *)iface;
178
179     FIXME("(%p/%p)->(%x) stub!\n", This, iface, dwFlags);
180
181     return S_FALSE;
182 }
183
184 static const struct IMediaStreamVtbl MediaStream_Vtbl =
185 {
186     IMediaStreamImpl_QueryInterface,
187     IMediaStreamImpl_AddRef,
188     IMediaStreamImpl_Release,
189     IMediaStreamImpl_GetMultiMediaStream,
190     IMediaStreamImpl_GetInformation,
191     IMediaStreamImpl_SetSameFormat,
192     IMediaStreamImpl_AllocateSample,
193     IMediaStreamImpl_CreateSharedSample,
194     IMediaStreamImpl_SendEndOfStream
195 };
196
197 HRESULT DirectDrawMediaStream_create(IMultiMediaStream* Parent, const MSPID* pPurposeId, STREAM_TYPE StreamType, IMediaStream** ppMediaStream)
198 {
199     IDirectDrawMediaStreamImpl* object;
200
201     TRACE("(%p,%s,%p)\n", Parent, debugstr_guid(pPurposeId), ppMediaStream);
202
203     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IMediaStreamImpl));
204     if (!object)
205     {
206         ERR("Out of memory\n");
207         return E_OUTOFMEMORY;
208     }
209
210     object->IDirectDrawMediaStream_iface.lpVtbl = &DirectDrawMediaStream_Vtbl;
211     object->ref = 1;
212
213     object->Parent = Parent;
214     object->PurposeId = *pPurposeId;
215     object->StreamType = StreamType;
216
217     *ppMediaStream = (IMediaStream*)&object->IDirectDrawMediaStream_iface;
218
219     return S_OK;
220 }
221
222 static inline IDirectDrawMediaStreamImpl *impl_from_IDirectDrawMediaStream(IDirectDrawMediaStream *iface)
223 {
224     return CONTAINING_RECORD(iface, IDirectDrawMediaStreamImpl, IDirectDrawMediaStream_iface);
225 }
226
227 static HRESULT WINAPI IDirectDrawMediaStreamImpl_QueryInterface(IDirectDrawMediaStream *iface,
228         REFIID riid, void **ppv)
229 {
230     IDirectDrawMediaStreamImpl *This = impl_from_IDirectDrawMediaStream(iface);
231
232     TRACE("(%p/%p)->(%s,%p)\n", iface, This, debugstr_guid(riid), ppv);
233
234     if (IsEqualGUID(riid, &IID_IUnknown) ||
235         IsEqualGUID(riid, &IID_IMediaStream) ||
236         IsEqualGUID(riid, &IID_IDirectDrawMediaStream))
237     {
238         IUnknown_AddRef(iface);
239         *ppv = This;
240         return S_OK;
241     }
242
243     ERR("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppv);
244     return E_NOINTERFACE;
245 }
246
247 static HRESULT WINAPI IDirectDrawMediaStreamImpl_GetFormat(IDirectDrawMediaStream *iface,
248         DDSURFACEDESC *pDDSDCurrent, IDirectDrawPalette **ppDirectDrawPalette,
249         DDSURFACEDESC *pDDSDDesired, DWORD *pdwFlags)
250 {
251     FIXME("(%p)->(%p,%p,%p,%p) stub!\n", iface, pDDSDCurrent, ppDirectDrawPalette, pDDSDDesired,
252             pdwFlags);
253
254     return E_NOTIMPL;
255
256 }
257
258 static HRESULT WINAPI IDirectDrawMediaStreamImpl_SetFormat(IDirectDrawMediaStream *iface,
259         const DDSURFACEDESC *pDDSurfaceDesc, IDirectDrawPalette *pDirectDrawPalette)
260 {
261     FIXME("(%p)->(%p,%p) stub!\n", iface, pDDSurfaceDesc, pDirectDrawPalette);
262
263     return E_NOTIMPL;
264 }
265
266 static HRESULT WINAPI IDirectDrawMediaStreamImpl_GetDirectDraw(IDirectDrawMediaStream *iface,
267         IDirectDraw **ppDirectDraw)
268 {
269     FIXME("(%p)->(%p) stub!\n", iface, ppDirectDraw);
270
271     return E_NOTIMPL;
272 }
273
274 static HRESULT WINAPI IDirectDrawMediaStreamImpl_SetDirectDraw(IDirectDrawMediaStream *iface,
275         IDirectDraw *pDirectDraw)
276 {
277     FIXME("(%p)->(%p) stub!\n", iface, pDirectDraw);
278
279     return E_NOTIMPL;
280 }
281
282 static HRESULT WINAPI IDirectDrawMediaStreamImpl_CreateSample(IDirectDrawMediaStream *iface,
283         IDirectDrawSurface *pSurface, const RECT *pRect, DWORD dwFlags,
284         IDirectDrawStreamSample **ppSample)
285 {
286     FIXME("(%p)->(%p,%p,%x,%p) stub!\n", iface, pSurface, pRect, dwFlags, ppSample);
287
288     return E_NOTIMPL;
289 }
290
291 static HRESULT WINAPI IDirectDrawMediaStreamImpl_GetTimePerFrame(IDirectDrawMediaStream *iface,
292         STREAM_TIME *pFrameTime)
293 {
294     FIXME("(%p)->(%p) stub!\n", iface, pFrameTime);
295
296     return E_NOTIMPL;
297 }
298
299 /* Note: Hack so we can reuse the old functions without compiler warnings */
300 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
301 # define XCAST(fun)     (typeof(DirectDrawMediaStream_Vtbl.fun))
302 #else
303 # define XCAST(fun)     (void*)
304 #endif
305
306 static const struct IDirectDrawMediaStreamVtbl DirectDrawMediaStream_Vtbl =
307 {
308     IDirectDrawMediaStreamImpl_QueryInterface,
309     XCAST(AddRef)IMediaStreamImpl_AddRef,
310     XCAST(Release)IMediaStreamImpl_Release,
311     XCAST(GetMultiMediaStream)IMediaStreamImpl_GetMultiMediaStream,
312     XCAST(GetInformation)IMediaStreamImpl_GetInformation,
313     XCAST(SetSameFormat)IMediaStreamImpl_SetSameFormat,
314     XCAST(AllocateSample)IMediaStreamImpl_AllocateSample,
315     XCAST(CreateSharedSample)IMediaStreamImpl_CreateSharedSample,
316     XCAST(SendEndOfStream)IMediaStreamImpl_SendEndOfStream,
317     IDirectDrawMediaStreamImpl_GetFormat,
318     IDirectDrawMediaStreamImpl_SetFormat,
319     IDirectDrawMediaStreamImpl_GetDirectDraw,
320     IDirectDrawMediaStreamImpl_SetDirectDraw,
321     IDirectDrawMediaStreamImpl_CreateSample,
322     IDirectDrawMediaStreamImpl_GetTimePerFrame
323 };
324 #undef XCAST