d3d10: Parse semantic in parse_fx10_local_variable().
[wine] / dlls / amstream / amstream.c
1 /*
2  * Implementation of IAMMultiMediaStream Interface
3  *
4  * Copyright 2004 Christian Costa
5  * Copyright 2006 Ivan Leo Puoti
6  *
7  * This file contains the (internal) driver registration functions,
8  * driver enumeration APIs and DirectDraw creation functions.
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 2.1 of the License, or (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with this library; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24
25 #include "wine/debug.h"
26
27 #define COBJMACROS
28
29 #include "winbase.h"
30 #include "wingdi.h"
31
32 #include "amstream_private.h"
33 #include "amstream.h"
34
35 WINE_DEFAULT_DEBUG_CHANNEL(amstream);
36
37 typedef struct {
38     const IAMMultiMediaStreamVtbl *lpVtbl;
39     LONG ref;
40     IGraphBuilder* pFilterGraph;
41     IPin* ipin;
42     IGraphBuilder* GraphBuilder;
43     ULONG nbStreams;
44     IMediaStream** pStreams;
45     STREAM_TYPE StreamType;
46 } IAMMultiMediaStreamImpl;
47
48 static const struct IAMMultiMediaStreamVtbl AM_Vtbl;
49
50 HRESULT AM_create(IUnknown *pUnkOuter, LPVOID *ppObj)
51 {
52     IAMMultiMediaStreamImpl* object; 
53
54     TRACE("(%p,%p)\n", pUnkOuter, ppObj);
55
56     if( pUnkOuter )
57         return CLASS_E_NOAGGREGATION;
58
59     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IAMMultiMediaStreamImpl));
60     if (!object)
61     {
62         ERR("Out of memory\n");
63         return E_OUTOFMEMORY;
64     }
65
66     object->lpVtbl = &AM_Vtbl;
67     object->ref = 1;
68
69     *ppObj = object;
70
71     return S_OK;
72 }
73
74 /*** IUnknown methods ***/
75 static HRESULT WINAPI IAMMultiMediaStreamImpl_QueryInterface(IAMMultiMediaStream* iface, REFIID riid, void** ppvObject)
76 {
77     IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
78
79     TRACE("(%p/%p)->(%s,%p)\n", iface, This, debugstr_guid(riid), ppvObject);
80
81     if (IsEqualGUID(riid, &IID_IUnknown) ||
82         IsEqualGUID(riid, &IID_IMultiMediaStream) ||
83         IsEqualGUID(riid, &IID_IAMMultiMediaStream))
84     {
85         IUnknown_AddRef(iface);
86         *ppvObject = This;
87         return S_OK;
88     }
89
90     ERR("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
91
92     return E_NOINTERFACE;
93 }
94
95 static ULONG WINAPI IAMMultiMediaStreamImpl_AddRef(IAMMultiMediaStream* iface)
96 {
97     IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
98
99     TRACE("(%p/%p)\n", iface, This);
100
101     return InterlockedIncrement(&This->ref);
102 }
103
104 static ULONG WINAPI IAMMultiMediaStreamImpl_Release(IAMMultiMediaStream* iface)
105 {
106     IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
107     ULONG ref = InterlockedDecrement(&This->ref);
108
109     TRACE("(%p/%p)\n", iface, This);
110
111     if (!ref)
112         HeapFree(GetProcessHeap(), 0, This);
113
114     return ref;
115 }
116
117 /*** IMultiMediaStream methods ***/
118 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetInformation(IAMMultiMediaStream* iface, DWORD* pdwFlags, STREAM_TYPE* pStreamType)
119 {
120     IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
121
122     FIXME("(%p/%p)->(%p,%p) stub!\n", This, iface, pdwFlags, pStreamType);
123
124     return E_NOTIMPL;
125 }
126
127 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetMediaStream(IAMMultiMediaStream* iface, REFMSPID idPurpose, IMediaStream** ppMediaStream)
128 {
129     IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
130     MSPID PurposeId;
131     unsigned int i;
132
133     TRACE("(%p/%p)->(%s,%p)\n", This, iface, debugstr_guid(idPurpose), ppMediaStream);
134
135     for (i = 0; i < This->nbStreams; i++)
136     {
137         IMediaStream_GetInformation(This->pStreams[i], &PurposeId, NULL);
138         if (IsEqualIID(&PurposeId, idPurpose))
139         {
140             *ppMediaStream = This->pStreams[i];
141             IMediaStream_AddRef(*ppMediaStream);
142             return S_OK;
143         }
144     }
145
146     return MS_E_NOSTREAM;
147 }
148
149 static HRESULT WINAPI IAMMultiMediaStreamImpl_EnumMediaStreams(IAMMultiMediaStream* iface, LONG Index, IMediaStream** ppMediaStream)
150 {
151     IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
152
153     FIXME("(%p/%p)->(%d,%p) stub!\n", This, iface, Index, ppMediaStream);
154
155     return E_NOTIMPL;
156 }
157
158 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetState(IAMMultiMediaStream* iface, STREAM_STATE* pCurrentState)
159 {
160     IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
161
162     FIXME("(%p/%p)->(%p) stub!\n", This, iface, pCurrentState);
163
164     return E_NOTIMPL;
165 }
166
167 static HRESULT WINAPI IAMMultiMediaStreamImpl_SetState(IAMMultiMediaStream* iface, STREAM_STATE NewState)
168 {
169     IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
170
171     FIXME("(%p/%p)->() stub!\n", This, iface);
172
173     return E_NOTIMPL;
174 }
175
176 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetTime(IAMMultiMediaStream* iface, STREAM_TIME* pCurrentTime)
177 {
178     IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
179
180     FIXME("(%p/%p)->(%p) stub!\n", This, iface, pCurrentTime);
181
182     return E_NOTIMPL;
183 }
184
185 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetDuration(IAMMultiMediaStream* iface, STREAM_TIME* pDuration)
186 {
187     IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
188
189     FIXME("(%p/%p)->(%p) stub!\n", This, iface, pDuration);
190
191     return E_NOTIMPL;
192 }
193
194 static HRESULT WINAPI IAMMultiMediaStreamImpl_Seek(IAMMultiMediaStream* iface, STREAM_TIME SeekTime)
195 {
196     IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
197
198     FIXME("(%p/%p)->() stub!\n", This, iface);
199
200     return E_NOTIMPL;
201 }
202
203 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetEndOfStream(IAMMultiMediaStream* iface, HANDLE* phEOS)
204 {
205     IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
206
207     FIXME("(%p/%p)->(%p) stub!\n", This, iface, phEOS);
208
209     return E_NOTIMPL;
210 }
211
212 /*** IAMMultiMediaStream methods ***/
213 static HRESULT WINAPI IAMMultiMediaStreamImpl_Initialize(IAMMultiMediaStream* iface, STREAM_TYPE StreamType, DWORD dwFlags, IGraphBuilder* pFilterGraph)
214 {
215     IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
216     HRESULT hr = S_OK;
217
218     TRACE("(%p/%p)->(%x,%x,%p)\n", This, iface, (DWORD)StreamType, dwFlags, pFilterGraph);
219
220     if (pFilterGraph)
221     {
222         This->pFilterGraph = pFilterGraph;
223         IGraphBuilder_AddRef(This->pFilterGraph);
224     }
225     else
226     {
227         hr = CoCreateInstance(&CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, &IID_IGraphBuilder, (LPVOID*)&This->pFilterGraph);
228     }
229
230     if (SUCCEEDED(hr))
231     {
232         This->StreamType = StreamType;
233     }
234
235     return hr;
236 }
237
238 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetFilterGraph(IAMMultiMediaStream* iface, IGraphBuilder** ppGraphBuilder)
239 {
240     IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
241
242     TRACE("(%p/%p)->(%p)\n", This, iface, ppGraphBuilder);
243
244     if (!ppGraphBuilder)
245         return E_POINTER;
246
247     if (This->pFilterGraph)
248         return IFilterGraph_QueryInterface(This->pFilterGraph, &IID_IGraphBuilder, (void**)ppGraphBuilder);
249     else
250         *ppGraphBuilder = NULL;
251
252     return S_OK;
253 }
254
255 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetFilter(IAMMultiMediaStream* iface, IMediaStreamFilter** ppFilter)
256 {
257     IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
258
259     FIXME("(%p/%p)->(%p) stub!\n", This, iface, ppFilter); 
260
261     return E_NOTIMPL;
262 }
263
264 static HRESULT WINAPI IAMMultiMediaStreamImpl_AddMediaStream(IAMMultiMediaStream* iface, IUnknown* pStreamObject, const MSPID* PurposeId,
265                                           DWORD dwFlags, IMediaStream** ppNewStream)
266 {
267     IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
268     HRESULT hr;
269     IMediaStream* pStream;
270     IMediaStream** pNewStreams;
271
272     FIXME("(%p/%p)->(%p,%s,%x,%p) partial stub!\n", This, iface, pStreamObject, debugstr_guid(PurposeId), dwFlags, ppNewStream);
273
274     if (IsEqualGUID(PurposeId, &MSPID_PrimaryVideo))
275         hr = DirectDrawMediaStream_create((IMultiMediaStream*)iface, PurposeId, This->StreamType, &pStream);
276     else
277         hr = MediaStream_create((IMultiMediaStream*)iface, PurposeId, This->StreamType, &pStream);
278
279     if (SUCCEEDED(hr))
280     {
281         pNewStreams = CoTaskMemAlloc((This->nbStreams+1)*sizeof(IMediaStream*));
282         if (!pNewStreams)
283         {
284             IMediaStream_Release(pStream);
285             return E_OUTOFMEMORY;
286         }
287         if (This->nbStreams)
288             CopyMemory(pNewStreams, This->pStreams, This->nbStreams*sizeof(IMediaStream*));
289         CoTaskMemFree(This->pStreams);
290         This->pStreams = pNewStreams;
291         This->pStreams[This->nbStreams] = pStream;
292         This->nbStreams++;
293
294         if (ppNewStream)
295             *ppNewStream = pStream;
296     }
297
298     return hr;
299 }
300
301 static HRESULT WINAPI IAMMultiMediaStreamImpl_OpenFile(IAMMultiMediaStream* iface, LPCWSTR pszFileName, DWORD dwFlags)
302 {
303     HRESULT ret;
304     IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
305     IFileSourceFilter *SourceFilter;
306     IBaseFilter *BaseFilter;
307     IEnumPins *EnumPins;
308     IPin *ipin;
309     PIN_DIRECTION pin_direction;
310
311     TRACE("(%p/%p)->(%s,%x)\n", This, iface, debugstr_w(pszFileName), dwFlags);
312
313     ret = CoCreateInstance(&CLSID_AsyncReader, NULL, CLSCTX_INPROC_SERVER, &IID_IFileSourceFilter, (void**)&SourceFilter);
314     if(ret != S_OK)
315         return ret;
316
317     ret = IFileSourceFilter_Load(SourceFilter, pszFileName, NULL);
318     if(ret != S_OK)
319     {
320         IFileSourceFilter_Release(SourceFilter);
321         return ret;
322     }
323
324     ret = IFileSourceFilter_QueryInterface(SourceFilter, &IID_IBaseFilter, (void**)&BaseFilter);
325     if(ret != S_OK)
326     {
327         IFileSourceFilter_Release(SourceFilter);
328         return ret;
329     }
330
331     ret = IBaseFilter_EnumPins(BaseFilter, &EnumPins);
332     if(ret != S_OK)
333     {
334         goto end;
335     }
336
337     ret = IEnumPins_Next(EnumPins, 1, &ipin, NULL);
338     if(ret == S_OK)
339     {
340         ret = IPin_QueryDirection(ipin, &pin_direction);
341         IEnumPins_Release(EnumPins);
342         if(ret == S_OK && pin_direction == PINDIR_OUTPUT)
343             This->ipin = ipin;
344         else
345             goto end;
346     }
347     else
348     {
349         IEnumPins_Release(EnumPins);
350         goto end;
351     }
352
353     /* If Initialize was not called before, we do it here */
354     if (!This->pFilterGraph)
355     {
356         ret = IAMMultiMediaStream_Initialize(iface, STREAMTYPE_READ, 0, NULL);
357         if (FAILED(ret))
358             goto end;
359     }
360
361     ret = IFilterGraph_QueryInterface(This->pFilterGraph, &IID_IGraphBuilder, (void**)&This->GraphBuilder);
362     if(ret != S_OK)
363     {
364         goto end;
365     }
366
367     ret = IGraphBuilder_AddSourceFilter(This->GraphBuilder, pszFileName, pszFileName, &BaseFilter);
368
369 end:
370     IBaseFilter_Release(BaseFilter);
371     IFileSourceFilter_Release(SourceFilter);
372     return ret;
373 }
374
375 static HRESULT WINAPI IAMMultiMediaStreamImpl_OpenMoniker(IAMMultiMediaStream* iface, IBindCtx* pCtx, IMoniker* pMoniker, DWORD dwFlags)
376 {
377     IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
378
379     FIXME("(%p/%p)->(%p,%p,%x) stub!\n", This, iface, pCtx, pMoniker, dwFlags);
380
381     return E_NOTIMPL;
382 }
383
384 static HRESULT WINAPI IAMMultiMediaStreamImpl_Render(IAMMultiMediaStream* iface, DWORD dwFlags)
385 {
386     IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
387
388     FIXME("(%p/%p)->(%x) partial stub!\n", This, iface, dwFlags);
389
390     if(dwFlags != AMMSF_NOCLOCK)
391         return E_INVALIDARG;
392
393     return IGraphBuilder_Render(This->GraphBuilder, This->ipin);
394 }
395
396 static const IAMMultiMediaStreamVtbl AM_Vtbl =
397 {
398     IAMMultiMediaStreamImpl_QueryInterface,
399     IAMMultiMediaStreamImpl_AddRef,
400     IAMMultiMediaStreamImpl_Release,
401     IAMMultiMediaStreamImpl_GetInformation,
402     IAMMultiMediaStreamImpl_GetMediaStream,
403     IAMMultiMediaStreamImpl_EnumMediaStreams,
404     IAMMultiMediaStreamImpl_GetState,
405     IAMMultiMediaStreamImpl_SetState,
406     IAMMultiMediaStreamImpl_GetTime,
407     IAMMultiMediaStreamImpl_GetDuration,
408     IAMMultiMediaStreamImpl_Seek,
409     IAMMultiMediaStreamImpl_GetEndOfStream,
410     IAMMultiMediaStreamImpl_Initialize,
411     IAMMultiMediaStreamImpl_GetFilterGraph,
412     IAMMultiMediaStreamImpl_GetFilter,
413     IAMMultiMediaStreamImpl_AddMediaStream,
414     IAMMultiMediaStreamImpl_OpenFile,
415     IAMMultiMediaStreamImpl_OpenMoniker,
416     IAMMultiMediaStreamImpl_Render
417 };