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 IAMMultiMediaStream IAMMultiMediaStream_iface;
40 IGraphBuilder* pFilterGraph;
42 IGraphBuilder* GraphBuilder;
44 IMediaStream** pStreams;
45 STREAM_TYPE StreamType;
46 } IAMMultiMediaStreamImpl;
48 static inline IAMMultiMediaStreamImpl *impl_from_IAMMultiMediaStream(IAMMultiMediaStream *iface)
50 return CONTAINING_RECORD(iface, IAMMultiMediaStreamImpl, IAMMultiMediaStream_iface);
53 static const struct IAMMultiMediaStreamVtbl AM_Vtbl;
55 HRESULT AM_create(IUnknown *pUnkOuter, LPVOID *ppObj)
57 IAMMultiMediaStreamImpl* object;
59 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
62 return CLASS_E_NOAGGREGATION;
64 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IAMMultiMediaStreamImpl));
67 ERR("Out of memory\n");
71 object->IAMMultiMediaStream_iface.lpVtbl = &AM_Vtbl;
79 /*** IUnknown methods ***/
80 static HRESULT WINAPI IAMMultiMediaStreamImpl_QueryInterface(IAMMultiMediaStream* iface, REFIID riid, void** ppvObject)
82 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
84 TRACE("(%p/%p)->(%s,%p)\n", iface, This, debugstr_guid(riid), ppvObject);
86 if (IsEqualGUID(riid, &IID_IUnknown) ||
87 IsEqualGUID(riid, &IID_IMultiMediaStream) ||
88 IsEqualGUID(riid, &IID_IAMMultiMediaStream))
90 IUnknown_AddRef(iface);
95 ERR("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
100 static ULONG WINAPI IAMMultiMediaStreamImpl_AddRef(IAMMultiMediaStream* iface)
102 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
104 TRACE("(%p/%p)\n", iface, This);
106 return InterlockedIncrement(&This->ref);
109 static ULONG WINAPI IAMMultiMediaStreamImpl_Release(IAMMultiMediaStream* iface)
111 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
112 ULONG ref = InterlockedDecrement(&This->ref);
114 TRACE("(%p/%p)\n", iface, This);
117 HeapFree(GetProcessHeap(), 0, This);
122 /*** IMultiMediaStream methods ***/
123 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetInformation(IAMMultiMediaStream* iface, DWORD* pdwFlags, STREAM_TYPE* pStreamType)
125 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
127 FIXME("(%p/%p)->(%p,%p) stub!\n", This, iface, pdwFlags, pStreamType);
132 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetMediaStream(IAMMultiMediaStream* iface, REFMSPID idPurpose, IMediaStream** ppMediaStream)
134 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
138 TRACE("(%p/%p)->(%s,%p)\n", This, iface, debugstr_guid(idPurpose), ppMediaStream);
140 for (i = 0; i < This->nbStreams; i++)
142 IMediaStream_GetInformation(This->pStreams[i], &PurposeId, NULL);
143 if (IsEqualIID(&PurposeId, idPurpose))
145 *ppMediaStream = This->pStreams[i];
146 IMediaStream_AddRef(*ppMediaStream);
151 return MS_E_NOSTREAM;
154 static HRESULT WINAPI IAMMultiMediaStreamImpl_EnumMediaStreams(IAMMultiMediaStream* iface, LONG Index, IMediaStream** ppMediaStream)
156 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
158 FIXME("(%p/%p)->(%d,%p) stub!\n", This, iface, Index, ppMediaStream);
163 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetState(IAMMultiMediaStream* iface, STREAM_STATE* pCurrentState)
165 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
167 FIXME("(%p/%p)->(%p) stub!\n", This, iface, pCurrentState);
172 static HRESULT WINAPI IAMMultiMediaStreamImpl_SetState(IAMMultiMediaStream* iface, STREAM_STATE NewState)
174 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
176 FIXME("(%p/%p)->() stub!\n", This, iface);
181 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetTime(IAMMultiMediaStream* iface, STREAM_TIME* pCurrentTime)
183 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
185 FIXME("(%p/%p)->(%p) stub!\n", This, iface, pCurrentTime);
190 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetDuration(IAMMultiMediaStream* iface, STREAM_TIME* pDuration)
192 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
194 FIXME("(%p/%p)->(%p) stub!\n", This, iface, pDuration);
199 static HRESULT WINAPI IAMMultiMediaStreamImpl_Seek(IAMMultiMediaStream* iface, STREAM_TIME SeekTime)
201 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
203 FIXME("(%p/%p)->() stub!\n", This, iface);
208 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetEndOfStream(IAMMultiMediaStream* iface, HANDLE* phEOS)
210 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
212 FIXME("(%p/%p)->(%p) stub!\n", This, iface, phEOS);
217 /*** IAMMultiMediaStream methods ***/
218 static HRESULT WINAPI IAMMultiMediaStreamImpl_Initialize(IAMMultiMediaStream* iface, STREAM_TYPE StreamType, DWORD dwFlags, IGraphBuilder* pFilterGraph)
220 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
223 TRACE("(%p/%p)->(%x,%x,%p)\n", This, iface, (DWORD)StreamType, dwFlags, pFilterGraph);
227 This->pFilterGraph = pFilterGraph;
228 IGraphBuilder_AddRef(This->pFilterGraph);
232 hr = CoCreateInstance(&CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, &IID_IGraphBuilder, (LPVOID*)&This->pFilterGraph);
237 This->StreamType = StreamType;
243 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetFilterGraph(IAMMultiMediaStream* iface, IGraphBuilder** ppGraphBuilder)
245 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
247 TRACE("(%p/%p)->(%p)\n", This, iface, ppGraphBuilder);
252 if (This->pFilterGraph)
253 return IFilterGraph_QueryInterface(This->pFilterGraph, &IID_IGraphBuilder, (void**)ppGraphBuilder);
255 *ppGraphBuilder = NULL;
260 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetFilter(IAMMultiMediaStream* iface, IMediaStreamFilter** ppFilter)
262 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
264 FIXME("(%p/%p)->(%p) stub!\n", This, iface, ppFilter);
269 static HRESULT WINAPI IAMMultiMediaStreamImpl_AddMediaStream(IAMMultiMediaStream* iface, IUnknown* pStreamObject, const MSPID* PurposeId,
270 DWORD dwFlags, IMediaStream** ppNewStream)
272 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
274 IMediaStream* pStream;
275 IMediaStream** pNewStreams;
277 FIXME("(%p/%p)->(%p,%s,%x,%p) partial stub!\n", This, iface, pStreamObject, debugstr_guid(PurposeId), dwFlags, ppNewStream);
279 hr = mediastream_create((IMultiMediaStream*)iface, PurposeId, This->StreamType, &pStream);
282 pNewStreams = CoTaskMemRealloc(This->pStreams, (This->nbStreams+1) * sizeof(IMediaStream*));
285 IMediaStream_Release(pStream);
286 return E_OUTOFMEMORY;
288 This->pStreams = pNewStreams;
289 This->pStreams[This->nbStreams] = pStream;
293 *ppNewStream = pStream;
299 static HRESULT WINAPI IAMMultiMediaStreamImpl_OpenFile(IAMMultiMediaStream* iface, LPCWSTR pszFileName, DWORD dwFlags)
302 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
303 IFileSourceFilter *SourceFilter;
304 IBaseFilter *BaseFilter;
307 PIN_DIRECTION pin_direction;
309 TRACE("(%p/%p)->(%s,%x)\n", This, iface, debugstr_w(pszFileName), dwFlags);
311 ret = CoCreateInstance(&CLSID_AsyncReader, NULL, CLSCTX_INPROC_SERVER, &IID_IFileSourceFilter, (void**)&SourceFilter);
315 ret = IFileSourceFilter_Load(SourceFilter, pszFileName, NULL);
318 IFileSourceFilter_Release(SourceFilter);
322 ret = IFileSourceFilter_QueryInterface(SourceFilter, &IID_IBaseFilter, (void**)&BaseFilter);
325 IFileSourceFilter_Release(SourceFilter);
329 ret = IBaseFilter_EnumPins(BaseFilter, &EnumPins);
335 ret = IEnumPins_Next(EnumPins, 1, &ipin, NULL);
338 ret = IPin_QueryDirection(ipin, &pin_direction);
339 IEnumPins_Release(EnumPins);
340 if(ret == S_OK && pin_direction == PINDIR_OUTPUT)
347 IEnumPins_Release(EnumPins);
351 /* If Initialize was not called before, we do it here */
352 if (!This->pFilterGraph)
354 ret = IAMMultiMediaStream_Initialize(iface, STREAMTYPE_READ, 0, NULL);
359 ret = IFilterGraph_QueryInterface(This->pFilterGraph, &IID_IGraphBuilder, (void**)&This->GraphBuilder);
365 ret = IGraphBuilder_AddSourceFilter(This->GraphBuilder, pszFileName, pszFileName, &BaseFilter);
368 IBaseFilter_Release(BaseFilter);
369 IFileSourceFilter_Release(SourceFilter);
373 static HRESULT WINAPI IAMMultiMediaStreamImpl_OpenMoniker(IAMMultiMediaStream* iface, IBindCtx* pCtx, IMoniker* pMoniker, DWORD dwFlags)
375 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
377 FIXME("(%p/%p)->(%p,%p,%x) stub!\n", This, iface, pCtx, pMoniker, dwFlags);
382 static HRESULT WINAPI IAMMultiMediaStreamImpl_Render(IAMMultiMediaStream* iface, DWORD dwFlags)
384 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
386 FIXME("(%p/%p)->(%x) partial stub!\n", This, iface, dwFlags);
388 if(dwFlags != AMMSF_NOCLOCK)
391 return IGraphBuilder_Render(This->GraphBuilder, This->ipin);
394 static const IAMMultiMediaStreamVtbl AM_Vtbl =
396 IAMMultiMediaStreamImpl_QueryInterface,
397 IAMMultiMediaStreamImpl_AddRef,
398 IAMMultiMediaStreamImpl_Release,
399 IAMMultiMediaStreamImpl_GetInformation,
400 IAMMultiMediaStreamImpl_GetMediaStream,
401 IAMMultiMediaStreamImpl_EnumMediaStreams,
402 IAMMultiMediaStreamImpl_GetState,
403 IAMMultiMediaStreamImpl_SetState,
404 IAMMultiMediaStreamImpl_GetTime,
405 IAMMultiMediaStreamImpl_GetDuration,
406 IAMMultiMediaStreamImpl_Seek,
407 IAMMultiMediaStreamImpl_GetEndOfStream,
408 IAMMultiMediaStreamImpl_Initialize,
409 IAMMultiMediaStreamImpl_GetFilterGraph,
410 IAMMultiMediaStreamImpl_GetFilter,
411 IAMMultiMediaStreamImpl_AddMediaStream,
412 IAMMultiMediaStreamImpl_OpenFile,
413 IAMMultiMediaStreamImpl_OpenMoniker,
414 IAMMultiMediaStreamImpl_Render