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"
32 #include "amstream_private.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(amstream);
38 const IAMMultiMediaStreamVtbl *lpVtbl;
40 IGraphBuilder* pFilterGraph;
42 IGraphBuilder* GraphBuilder;
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);
57 return CLASS_E_NOAGGREGATION;
59 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IAMMultiMediaStreamImpl));
62 ERR("Out of memory\n");
66 object->lpVtbl = &AM_Vtbl;
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_IMultiMediaStream) ||
83 IsEqualGUID(riid, &IID_IAMMultiMediaStream))
85 IUnknown_AddRef(iface);
90 ERR("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
95 static ULONG WINAPI IAMMultiMediaStreamImpl_AddRef(IAMMultiMediaStream* iface)
97 IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
99 TRACE("(%p/%p)\n", iface, This);
101 return InterlockedIncrement(&This->ref);
104 static ULONG WINAPI IAMMultiMediaStreamImpl_Release(IAMMultiMediaStream* iface)
106 IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
107 ULONG ref = InterlockedDecrement(&This->ref);
109 TRACE("(%p/%p)\n", iface, This);
112 HeapFree(GetProcessHeap(), 0, This);
117 /*** IMultiMediaStream methods ***/
118 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetInformation(IAMMultiMediaStream* iface, DWORD* pdwFlags, STREAM_TYPE* pStreamType)
120 IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
122 FIXME("(%p/%p)->(%p,%p) stub!\n", This, iface, pdwFlags, pStreamType);
127 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetMediaStream(IAMMultiMediaStream* iface, REFMSPID idPurpose, IMediaStream** ppMediaStream)
129 IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
133 TRACE("(%p/%p)->(%s,%p)\n", This, iface, debugstr_guid(idPurpose), ppMediaStream);
135 for (i = 0; i < This->nbStreams; i++)
137 IMediaStream_GetInformation(This->pStreams[i], &PurposeId, NULL);
138 if (IsEqualIID(&PurposeId, idPurpose))
140 *ppMediaStream = This->pStreams[i];
141 IMediaStream_AddRef(*ppMediaStream);
146 return MS_E_NOSTREAM;
149 static HRESULT WINAPI IAMMultiMediaStreamImpl_EnumMediaStreams(IAMMultiMediaStream* iface, LONG Index, IMediaStream** ppMediaStream)
151 IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
153 FIXME("(%p/%p)->(%d,%p) stub!\n", This, iface, Index, ppMediaStream);
158 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetState(IAMMultiMediaStream* iface, STREAM_STATE* pCurrentState)
160 IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
162 FIXME("(%p/%p)->(%p) stub!\n", This, iface, pCurrentState);
167 static HRESULT WINAPI IAMMultiMediaStreamImpl_SetState(IAMMultiMediaStream* iface, STREAM_STATE NewState)
169 IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
171 FIXME("(%p/%p)->() stub!\n", This, iface);
176 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetTime(IAMMultiMediaStream* iface, STREAM_TIME* pCurrentTime)
178 IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
180 FIXME("(%p/%p)->(%p) stub!\n", This, iface, pCurrentTime);
185 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetDuration(IAMMultiMediaStream* iface, STREAM_TIME* pDuration)
187 IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
189 FIXME("(%p/%p)->(%p) stub!\n", This, iface, pDuration);
194 static HRESULT WINAPI IAMMultiMediaStreamImpl_Seek(IAMMultiMediaStream* iface, STREAM_TIME SeekTime)
196 IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
198 FIXME("(%p/%p)->() stub!\n", This, iface);
203 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetEndOfStream(IAMMultiMediaStream* iface, HANDLE* phEOS)
205 IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
207 FIXME("(%p/%p)->(%p) stub!\n", This, iface, phEOS);
212 /*** IAMMultiMediaStream methods ***/
213 static HRESULT WINAPI IAMMultiMediaStreamImpl_Initialize(IAMMultiMediaStream* iface, STREAM_TYPE StreamType, DWORD dwFlags, IGraphBuilder* pFilterGraph)
215 IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
218 TRACE("(%p/%p)->(%x,%x,%p)\n", This, iface, (DWORD)StreamType, dwFlags, pFilterGraph);
222 This->pFilterGraph = pFilterGraph;
223 IGraphBuilder_AddRef(This->pFilterGraph);
227 hr = CoCreateInstance(&CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, &IID_IGraphBuilder, (LPVOID*)&This->pFilterGraph);
232 This->StreamType = StreamType;
238 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetFilterGraph(IAMMultiMediaStream* iface, IGraphBuilder** ppGraphBuilder)
240 IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
242 TRACE("(%p/%p)->(%p)\n", This, iface, ppGraphBuilder);
247 if (This->pFilterGraph)
248 return IFilterGraph_QueryInterface(This->pFilterGraph, &IID_IGraphBuilder, (void**)ppGraphBuilder);
250 *ppGraphBuilder = NULL;
255 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetFilter(IAMMultiMediaStream* iface, IMediaStreamFilter** ppFilter)
257 IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
259 FIXME("(%p/%p)->(%p) stub!\n", This, iface, ppFilter);
264 static HRESULT WINAPI IAMMultiMediaStreamImpl_AddMediaStream(IAMMultiMediaStream* iface, IUnknown* pStreamObject, const MSPID* PurposeId,
265 DWORD dwFlags, IMediaStream** ppNewStream)
267 IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
269 IMediaStream* pStream;
270 IMediaStream** pNewStreams;
272 FIXME("(%p/%p)->(%p,%s,%x,%p) partial stub!\n", This, iface, pStreamObject, debugstr_guid(PurposeId), dwFlags, ppNewStream);
274 if (IsEqualGUID(PurposeId, &MSPID_PrimaryVideo))
275 hr = DirectDrawMediaStream_create((IMultiMediaStream*)iface, PurposeId, This->StreamType, &pStream);
277 hr = MediaStream_create((IMultiMediaStream*)iface, PurposeId, This->StreamType, &pStream);
281 pNewStreams = CoTaskMemAlloc((This->nbStreams+1)*sizeof(IMediaStream*));
284 IMediaStream_Release(pStream);
285 return E_OUTOFMEMORY;
288 CopyMemory(pNewStreams, This->pStreams, This->nbStreams*sizeof(IMediaStream*));
289 CoTaskMemFree(This->pStreams);
290 This->pStreams = pNewStreams;
291 This->pStreams[This->nbStreams] = pStream;
295 *ppNewStream = pStream;
301 static HRESULT WINAPI IAMMultiMediaStreamImpl_OpenFile(IAMMultiMediaStream* iface, LPCWSTR pszFileName, DWORD dwFlags)
304 IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
305 IFileSourceFilter *SourceFilter;
306 IBaseFilter *BaseFilter;
309 PIN_DIRECTION pin_direction;
311 TRACE("(%p/%p)->(%s,%x)\n", This, iface, debugstr_w(pszFileName), dwFlags);
313 ret = CoCreateInstance(&CLSID_AsyncReader, NULL, CLSCTX_INPROC_SERVER, &IID_IFileSourceFilter, (void**)&SourceFilter);
317 ret = IFileSourceFilter_Load(SourceFilter, pszFileName, NULL);
320 IFileSourceFilter_Release(SourceFilter);
324 ret = IFileSourceFilter_QueryInterface(SourceFilter, &IID_IBaseFilter, (void**)&BaseFilter);
327 IFileSourceFilter_Release(SourceFilter);
331 ret = IBaseFilter_EnumPins(BaseFilter, &EnumPins);
337 ret = IEnumPins_Next(EnumPins, 1, &ipin, NULL);
340 ret = IPin_QueryDirection(ipin, &pin_direction);
341 IEnumPins_Release(EnumPins);
342 if(ret == S_OK && pin_direction == PINDIR_OUTPUT)
349 IEnumPins_Release(EnumPins);
353 /* If Initialize was not called before, we do it here */
354 if (!This->pFilterGraph)
356 ret = IAMMultiMediaStream_Initialize(iface, STREAMTYPE_READ, 0, NULL);
361 ret = IFilterGraph_QueryInterface(This->pFilterGraph, &IID_IGraphBuilder, (void**)&This->GraphBuilder);
367 ret = IGraphBuilder_AddSourceFilter(This->GraphBuilder, pszFileName, pszFileName, &BaseFilter);
370 IBaseFilter_Release(BaseFilter);
371 IFileSourceFilter_Release(SourceFilter);
375 static HRESULT WINAPI IAMMultiMediaStreamImpl_OpenMoniker(IAMMultiMediaStream* iface, IBindCtx* pCtx, IMoniker* pMoniker, DWORD dwFlags)
377 IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
379 FIXME("(%p/%p)->(%p,%p,%x) stub!\n", This, iface, pCtx, pMoniker, dwFlags);
384 static HRESULT WINAPI IAMMultiMediaStreamImpl_Render(IAMMultiMediaStream* iface, DWORD dwFlags)
386 IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
388 FIXME("(%p/%p)->(%x) partial stub!\n", This, iface, dwFlags);
390 if(dwFlags != AMMSF_NOCLOCK)
393 return IGraphBuilder_Render(This->GraphBuilder, This->ipin);
396 static const IAMMultiMediaStreamVtbl AM_Vtbl =
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