wined3d: Rename the wined3d_adapter "num" field to "ordinal".
[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     IMediaStream lpVtbl;
40     LONG ref;
41     IMultiMediaStream* Parent;
42     MSPID PurposeId;
43     STREAM_TYPE StreamType;
44 } IMediaStreamImpl;
45
46 typedef struct {
47     IDirectDrawMediaStream lpVtbl;
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.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       IClassFactory_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->lpVtbl.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;
218
219     return S_OK;
220 }
221
222 static HRESULT WINAPI IDirectDrawMediaStreamImpl_QueryInterface(IDirectDrawMediaStream* iface, REFIID riid, void** ppvObject)
223 {
224     IMediaStreamImpl *This = (IMediaStreamImpl *)iface;
225
226     TRACE("(%p/%p)->(%s,%p)\n", iface, This, debugstr_guid(riid), ppvObject);
227
228     if (IsEqualGUID(riid, &IID_IUnknown) ||
229         IsEqualGUID(riid, &IID_IMediaStream) ||
230         IsEqualGUID(riid, &IID_IDirectDrawMediaStream))
231     {
232       IClassFactory_AddRef(iface);
233       *ppvObject = This;
234       return S_OK;
235     }
236
237     ERR("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
238     return E_NOINTERFACE;
239 }
240
241 static HRESULT WINAPI IDirectDrawMediaStreamImpl_GetFormat(IDirectDrawMediaStream* iface, DDSURFACEDESC *pDDSDCurrent,
242                                                            IDirectDrawPalette **ppDirectDrawPalette, DDSURFACEDESC *pDDSDDesired, DWORD *pdwFlags)
243 {
244     FIXME("(%p)->(%p,%p,%p,%p) stub!\n", iface, pDDSDCurrent, ppDirectDrawPalette, pDDSDDesired, pdwFlags);
245
246     return E_NOTIMPL;
247
248 }
249
250 static HRESULT WINAPI IDirectDrawMediaStreamImpl_SetFormat(IDirectDrawMediaStream* iface, const DDSURFACEDESC *pDDSurfaceDesc,
251                                                           IDirectDrawPalette *pDirectDrawPalette)
252 {
253     FIXME("(%p)->(%p,%p) stub!\n", iface, pDDSurfaceDesc, pDirectDrawPalette);
254
255     return E_NOTIMPL;
256 }
257
258 static HRESULT WINAPI IDirectDrawMediaStreamImpl_GetDirectDraw(IDirectDrawMediaStream* iface, IDirectDraw **ppDirectDraw)
259 {
260     FIXME("(%p)->(%p) stub!\n", iface, ppDirectDraw);
261
262     return E_NOTIMPL;
263 }
264
265 static HRESULT WINAPI IDirectDrawMediaStreamImpl_SetDirectDraw(IDirectDrawMediaStream* iface, IDirectDraw *pDirectDraw)
266 {
267     FIXME("(%p)->(%p) stub!\n", iface, pDirectDraw);
268
269     return E_NOTIMPL;
270 }
271
272 static HRESULT WINAPI IDirectDrawMediaStreamImpl_CreateSample(IDirectDrawMediaStream* iface, IDirectDrawSurface *pSurface, const RECT *pRect,
273                                                              DWORD dwFlags, IDirectDrawStreamSample **ppSample)
274 {
275     FIXME("(%p)->(%p,%p,%x,%p) stub!\n", iface, pSurface, pRect, dwFlags, ppSample);
276
277     return E_NOTIMPL;
278 }
279
280 static HRESULT WINAPI IDirectDrawMediaStreamImpl_GetTimePerFrame(IDirectDrawMediaStream* iface, STREAM_TIME *pFrameTime)
281 {
282     FIXME("(%p)->(%p) stub!\n", iface, pFrameTime);
283
284     return E_NOTIMPL;
285 }
286
287 /* Note: Hack so we can reuse the old functions without compiler warnings */
288 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
289 # define XCAST(fun)     (typeof(DirectDrawMediaStream_Vtbl.fun))
290 #else
291 # define XCAST(fun)     (void*)
292 #endif
293
294 static const struct IDirectDrawMediaStreamVtbl DirectDrawMediaStream_Vtbl =
295 {
296     IDirectDrawMediaStreamImpl_QueryInterface,
297     XCAST(AddRef)IMediaStreamImpl_AddRef,
298     XCAST(Release)IMediaStreamImpl_Release,
299     XCAST(GetMultiMediaStream)IMediaStreamImpl_GetMultiMediaStream,
300     XCAST(GetInformation)IMediaStreamImpl_GetInformation,
301     XCAST(SetSameFormat)IMediaStreamImpl_SetSameFormat,
302     XCAST(AllocateSample)IMediaStreamImpl_AllocateSample,
303     XCAST(CreateSharedSample)IMediaStreamImpl_CreateSharedSample,
304     XCAST(SendEndOfStream)IMediaStreamImpl_SendEndOfStream,
305     IDirectDrawMediaStreamImpl_GetFormat,
306     IDirectDrawMediaStreamImpl_SetFormat,
307     IDirectDrawMediaStreamImpl_GetDirectDraw,
308     IDirectDrawMediaStreamImpl_SetDirectDraw,
309     IDirectDrawMediaStreamImpl_CreateSample,
310     IDirectDrawMediaStreamImpl_GetTimePerFrame
311 };
312 #undef XCAST