winedbg: Prevent syntax error for setting all debug channels.
[wine/hramrach.git] / dlls / amstream / amstream.c
blob81584d6e8c30f81ee9510be9453a9322a1703d0d
1 /*
2 * Implementation of IAMMultiMediaStream Interface
4 * Copyright 2004 Christian Costa
5 * Copyright 2006 Ivan Leo Puoti
7 * This file contains the (internal) driver registration functions,
8 * driver enumeration APIs and DirectDraw creation functions.
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.
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.
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
25 #include "wine/debug.h"
27 #define COBJMACROS
29 #include "winbase.h"
30 #include "wingdi.h"
32 #include "amstream_private.h"
33 #include "amstream.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(amstream);
37 typedef struct {
38 IAMMultiMediaStream 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;
48 static const struct IAMMultiMediaStreamVtbl AM_Vtbl;
50 HRESULT AM_create(IUnknown *pUnkOuter, LPVOID *ppObj)
52 IAMMultiMediaStreamImpl* object;
54 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
56 if( pUnkOuter )
57 return CLASS_E_NOAGGREGATION;
59 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IAMMultiMediaStreamImpl));
60 if (!object)
62 ERR("Out of memory\n");
63 return E_OUTOFMEMORY;
66 object->lpVtbl.lpVtbl = &AM_Vtbl;
67 object->ref = 1;
69 *ppObj = object;
71 return S_OK;
74 /*** IUnknown methods ***/
75 static HRESULT WINAPI IAMMultiMediaStreamImpl_QueryInterface(IAMMultiMediaStream* iface, REFIID riid, void** ppvObject)
77 IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
79 TRACE("(%p/%p)->(%s,%p)\n", iface, This, debugstr_guid(riid), ppvObject);
81 if (IsEqualGUID(riid, &IID_IUnknown) ||
82 IsEqualGUID(riid, &IID_IAMMultiMediaStream))
84 IClassFactory_AddRef(iface);
85 *ppvObject = This;
86 return S_OK;
89 ERR("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
91 return E_NOINTERFACE;
94 static ULONG WINAPI IAMMultiMediaStreamImpl_AddRef(IAMMultiMediaStream* iface)
96 IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
98 TRACE("(%p/%p)\n", iface, This);
100 return InterlockedIncrement(&This->ref);
103 static ULONG WINAPI IAMMultiMediaStreamImpl_Release(IAMMultiMediaStream* iface)
105 IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
106 ULONG ref = InterlockedDecrement(&This->ref);
108 TRACE("(%p/%p)\n", iface, This);
110 if (!ref)
111 HeapFree(GetProcessHeap(), 0, This);
113 return ref;
116 /*** IMultiMediaStream methods ***/
117 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetInformation(IAMMultiMediaStream* iface, DWORD* pdwFlags, STREAM_TYPE* pStreamType)
119 IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
121 FIXME("(%p/%p)->(%p,%p) stub!\n", This, iface, pdwFlags, pStreamType);
123 return E_NOTIMPL;
126 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetMediaStream(IAMMultiMediaStream* iface, REFMSPID idPurpose, IMediaStream** ppMediaStream)
128 IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
129 MSPID PurposeId;
130 unsigned int i;
132 TRACE("(%p/%p)->(%s,%p)\n", This, iface, debugstr_guid(idPurpose), ppMediaStream);
134 for (i = 0; i < This->nbStreams; i++)
136 IMediaStream_GetInformation(This->pStreams[i], &PurposeId, NULL);
137 if (IsEqualIID(&PurposeId, idPurpose))
139 *ppMediaStream = This->pStreams[i];
140 IMediaStream_AddRef(*ppMediaStream);
141 return S_OK;
145 return MS_E_NOSTREAM;
148 static HRESULT WINAPI IAMMultiMediaStreamImpl_EnumMediaStreams(IAMMultiMediaStream* iface, LONG Index, IMediaStream** ppMediaStream)
150 IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
152 FIXME("(%p/%p)->(%d,%p) stub!\n", This, iface, Index, ppMediaStream);
154 return E_NOTIMPL;
157 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetState(IAMMultiMediaStream* iface, STREAM_STATE* pCurrentState)
159 IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
161 FIXME("(%p/%p)->(%p) stub!\n", This, iface, pCurrentState);
163 return E_NOTIMPL;
166 static HRESULT WINAPI IAMMultiMediaStreamImpl_SetState(IAMMultiMediaStream* iface, STREAM_STATE NewState)
168 IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
170 FIXME("(%p/%p)->() stub!\n", This, iface);
172 return E_NOTIMPL;
175 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetTime(IAMMultiMediaStream* iface, STREAM_TIME* pCurrentTime)
177 IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
179 FIXME("(%p/%p)->(%p) stub!\n", This, iface, pCurrentTime);
181 return E_NOTIMPL;
184 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetDuration(IAMMultiMediaStream* iface, STREAM_TIME* pDuration)
186 IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
188 FIXME("(%p/%p)->(%p) stub!\n", This, iface, pDuration);
190 return E_NOTIMPL;
193 static HRESULT WINAPI IAMMultiMediaStreamImpl_Seek(IAMMultiMediaStream* iface, STREAM_TIME SeekTime)
195 IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
197 FIXME("(%p/%p)->() stub!\n", This, iface);
199 return E_NOTIMPL;
202 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetEndOfStream(IAMMultiMediaStream* iface, HANDLE* phEOS)
204 IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
206 FIXME("(%p/%p)->(%p) stub!\n", This, iface, phEOS);
208 return E_NOTIMPL;
211 /*** IAMMultiMediaStream methods ***/
212 static HRESULT WINAPI IAMMultiMediaStreamImpl_Initialize(IAMMultiMediaStream* iface, STREAM_TYPE StreamType, DWORD dwFlags, IGraphBuilder* pFilterGraph)
214 IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
215 HRESULT hr = S_OK;
217 TRACE("(%p/%p)->(%x,%x,%p)\n", This, iface, (DWORD)StreamType, dwFlags, pFilterGraph);
219 if (pFilterGraph)
221 This->pFilterGraph = pFilterGraph;
222 IGraphBuilder_AddRef(This->pFilterGraph);
224 else
226 hr = CoCreateInstance(&CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, &IID_IGraphBuilder, (LPVOID*)&This->pFilterGraph);
229 if (SUCCEEDED(hr))
231 This->StreamType = StreamType;
234 return hr;
237 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetFilterGraph(IAMMultiMediaStream* iface, IGraphBuilder** ppGraphBuilder)
239 IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
241 TRACE("(%p/%p)->(%p)\n", This, iface, ppGraphBuilder);
243 if (!ppGraphBuilder)
244 return E_POINTER;
246 if (This->pFilterGraph)
247 return IFilterGraph_QueryInterface(This->pFilterGraph, &IID_IGraphBuilder, (void**)ppGraphBuilder);
248 else
249 *ppGraphBuilder = NULL;
251 return S_OK;
254 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetFilter(IAMMultiMediaStream* iface, IMediaStreamFilter** ppFilter)
256 IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
258 FIXME("(%p/%p)->(%p) stub!\n", This, iface, ppFilter);
260 return E_NOTIMPL;
263 static HRESULT WINAPI IAMMultiMediaStreamImpl_AddMediaStream(IAMMultiMediaStream* iface, IUnknown* pStreamObject, const MSPID* PurposeId,
264 DWORD dwFlags, IMediaStream** ppNewStream)
266 IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
267 HRESULT hr;
268 IMediaStream* pStream;
269 IMediaStream** pNewStreams;
271 FIXME("(%p/%p)->(%p,%s,%x,%p) partial stub!\n", This, iface, pStreamObject, debugstr_guid(PurposeId), dwFlags, ppNewStream);
273 if (IsEqualGUID(PurposeId, &MSPID_PrimaryVideo))
274 hr = DirectDrawMediaStream_create((IMultiMediaStream*)iface, PurposeId, This->StreamType, &pStream);
275 else
276 hr = MediaStream_create((IMultiMediaStream*)iface, PurposeId, This->StreamType, &pStream);
278 if (SUCCEEDED(hr))
280 pNewStreams = CoTaskMemAlloc((This->nbStreams+1)*sizeof(IMediaStream*));
281 if (!pNewStreams)
283 IMediaStream_Release(pStream);
284 return E_OUTOFMEMORY;
286 if (This->nbStreams)
287 CopyMemory(pNewStreams, This->pStreams, This->nbStreams*sizeof(IMediaStream*));
288 CoTaskMemFree(This->pStreams);
289 This->pStreams = pNewStreams;
290 This->pStreams[This->nbStreams] = pStream;
291 This->nbStreams++;
293 if (ppNewStream)
294 *ppNewStream = pStream;
297 return hr;
300 static HRESULT WINAPI IAMMultiMediaStreamImpl_OpenFile(IAMMultiMediaStream* iface, LPCWSTR pszFileName, DWORD dwFlags)
302 HRESULT ret;
303 IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
304 IFileSourceFilter *SourceFilter;
305 IBaseFilter *BaseFilter;
306 IEnumPins *EnumPins;
307 IPin *ipin;
308 PIN_DIRECTION pin_direction;
310 TRACE("(%p/%p)->(%s,%x)\n", This, iface, debugstr_w(pszFileName), dwFlags);
312 ret = CoCreateInstance(&CLSID_AsyncReader, NULL, CLSCTX_INPROC_SERVER, &IID_IFileSourceFilter, (void**)&SourceFilter);
313 if(ret != S_OK)
314 return ret;
316 ret = IFileSourceFilter_Load(SourceFilter, pszFileName, NULL);
317 if(ret != S_OK)
319 IFileSourceFilter_Release(SourceFilter);
320 return ret;
323 ret = IFileSourceFilter_QueryInterface(SourceFilter, &IID_IBaseFilter, (void**)&BaseFilter);
324 if(ret != S_OK)
326 IFileSourceFilter_Release(SourceFilter);
327 return ret;
330 ret = IBaseFilter_EnumPins(BaseFilter, &EnumPins);
331 if(ret != S_OK)
333 goto end;
336 ret = IEnumPins_Next(EnumPins, 1, &ipin, NULL);
337 if(ret == S_OK)
339 ret = IPin_QueryDirection(ipin, &pin_direction);
340 IEnumPins_Release(EnumPins);
341 if(ret == S_OK && pin_direction == PINDIR_OUTPUT)
342 This->ipin = ipin;
343 else
344 goto end;
346 else
348 IEnumPins_Release(EnumPins);
349 goto end;
352 /* If Initialize was not called before, we do it here */
353 if (!This->pFilterGraph)
355 ret = IAMMultiMediaStream_Initialize(iface, STREAMTYPE_READ, 0, NULL);
356 if (FAILED(ret))
357 goto end;
360 ret = IFilterGraph_QueryInterface(This->pFilterGraph, &IID_IGraphBuilder, (void**)&This->GraphBuilder);
361 if(ret != S_OK)
363 goto end;
366 ret = IGraphBuilder_AddSourceFilter(This->GraphBuilder, pszFileName, pszFileName, &BaseFilter);
368 end:
369 IBaseFilter_Release(BaseFilter);
370 IFileSourceFilter_Release(SourceFilter);
371 return ret;
374 static HRESULT WINAPI IAMMultiMediaStreamImpl_OpenMoniker(IAMMultiMediaStream* iface, IBindCtx* pCtx, IMoniker* pMoniker, DWORD dwFlags)
376 IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
378 FIXME("(%p/%p)->(%p,%p,%x) stub!\n", This, iface, pCtx, pMoniker, dwFlags);
380 return E_NOTIMPL;
383 static HRESULT WINAPI IAMMultiMediaStreamImpl_Render(IAMMultiMediaStream* iface, DWORD dwFlags)
385 IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
387 FIXME("(%p/%p)->(%x) partial stub!\n", This, iface, dwFlags);
389 if(dwFlags != AMMSF_NOCLOCK)
390 return E_INVALIDARG;
392 return IGraphBuilder_Render(This->GraphBuilder, This->ipin);
395 static const IAMMultiMediaStreamVtbl AM_Vtbl =
397 IAMMultiMediaStreamImpl_QueryInterface,
398 IAMMultiMediaStreamImpl_AddRef,
399 IAMMultiMediaStreamImpl_Release,
400 IAMMultiMediaStreamImpl_GetInformation,
401 IAMMultiMediaStreamImpl_GetMediaStream,
402 IAMMultiMediaStreamImpl_EnumMediaStreams,
403 IAMMultiMediaStreamImpl_GetState,
404 IAMMultiMediaStreamImpl_SetState,
405 IAMMultiMediaStreamImpl_GetTime,
406 IAMMultiMediaStreamImpl_GetDuration,
407 IAMMultiMediaStreamImpl_Seek,
408 IAMMultiMediaStreamImpl_GetEndOfStream,
409 IAMMultiMediaStreamImpl_Initialize,
410 IAMMultiMediaStreamImpl_GetFilterGraph,
411 IAMMultiMediaStreamImpl_GetFilter,
412 IAMMultiMediaStreamImpl_AddMediaStream,
413 IAMMultiMediaStreamImpl_OpenFile,
414 IAMMultiMediaStreamImpl_OpenMoniker,
415 IAMMultiMediaStreamImpl_Render